npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@resolverworks/ezccip

v0.0.15

Published

Turnkey CCIP-Read Handler

Downloads

568

Readme

ezccip.js

Turnkey EIP-3668: CCIP-Read Handler for ENS and arbitrary functions.

$ npm i @resolverworks/ezccip

Demo

  1. npm run start — starts a CCIP-Read server for TOR protocol using serve()
  2. setText("ccip.context", "0xd00d726b2aD6C81E894DC6B87BE6Ce9c5572D2cd http://localhost:8016")

Examples

  • DNS: ezccip.raffy.xyz (Mainnet)
    • Context: 0xd00d726b2aD6C81E894DC6B87BE6Ce9c5572D2cd https://raffy.xyz/ezccip/
  • ENS: ezccip.eth (Sepolia)
    • Context: 0xd00d726b2aD6C81E894DC6B87BE6Ce9c5572D2cd https://raffy.xyz/ezccip/s

Usage

Create an instance and register some handlers.

import {EZCCIP} from '@resolverworks/ezccip';

let ezccip = new EZCCIP();

// implement an arbitrary function
ezccip.register('add(uint256, uint256) returns (uint256)', ([a, b]) => [a + b]);

// implement a wildcard ENSIP-10 resolver
// which handles resolve() automatically
ezccip.enableENSIP10(async (name, context) => {
    return {
        async text(key) {
            switch (key) {
                case 'name': return 'Raffy';
                case 'avatar': return 'https://raffy.antistupid.com/ens.jpg';
            }
        },
    };
});

// more complicated example
let abi = new ethers.Interface([
    'function f(bytes32 x) return (string)',
    'function g(uint256 a, uint256 b) return (uint256)',
]);
ezccip.register(abi, { // register multiple functions at once using existing ABI
    async ['f()']([x], context, history) { // match function by signature
        history.show = [context.sender]; // replace arguments of f(...) in logger 
        history.name = 'Chonk'; // rename f() to Chonk() in logger
        return [context.calldata]; // echo incoming calldata
    },
    async ['0xe2179b8e']([a, b], context) {  // match by selector
        context.protocol = "tor"; // override signing protocol
        return ethers.toBeHex(1337n, 32); // return raw encoded result
    }
});

When your server has a request for CCIP-Read, use EZCCIP to produce a response.

let {sender, data: calldata} = JSON.parse(req.body); // ABI-encoded request in JSON from EIP-3668
let {data, history} = await ezccip.handleRead(sender, calldata, {
    protocol: 'tor', // default, tor requires signingKey + resolver
    signingKey, // your private key
    resolver, // address of the TOR
});
reply.json({data}); // ABI-encoded response in JSON for EIP-3668
console.log(history.toString()); // description of response
  • implement via GET, POST, or query directly
  • context carries useful information about the incoming request
  • history collects information as the response is generated

serve()

Start a simple server for an EZCCIP instance or a function representing the enableENSIP10() handler.

let {http} = await serve(ezccip); // see types for more configuration
// ...
http.close();

// minimal example:
// return fixed text() for any name
await serve(() => { text: () => 'Raffy' });
  • serve() will bind requests to the sender if the protocol needs a target and no resolver was provided.
  • Provide a resolvers mapping to pair endpoint suffixes to specific contract deployments.
    • The demo uses s to correspond to the Sepolia deployment, which makes requests to the modified endpoint http://localhost:8016/s target that contract, regardless of sender.
  • An endpointcontract pairing is required to support wrapped CCIP calls!

processENSIP10()

Apply ENSIP-10 calldata to a Record-object and generate the corresponding ABI-encoded response. This is a free-function.

let record = {
    text(key) { if (key == 'name') return 'raffy'; }
    addr(type) { if (type == 60) return '0x1234'; }
};
let calldata = '0x...'; // encodeFunctionData('text', ['name']);
let res = await processENSIP10(record, calldata); // encodeFunctionResult('text', ['raffy']);