Skip to content

Commit

Permalink
resolve typescript issue
Browse files Browse the repository at this point in the history
  • Loading branch information
adraffy committed Aug 23, 2024
1 parent 0cb934b commit 2b37196
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Turnkey [EIP-3668: CCIP-Read](https://eips.ethereum.org/EIPS/eip-3668) Handler f

`$ npm i @resolverworks/ezccip` [✓](https://www.npmjs.com/package/@resolverworks/ezccip)

* see [**types**](./dist/index.d.ts) / uses [ethers@6](https://github.com/ethers-io/ethers.js/)
* see [**types**](./dist/index.d.mts) / uses [ethers](https://github.com/ethers-io/ethers.js/)
* works with any server infrastructure
* uses minimal imports for serverless
* implements multiple protocols:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class EZCCIP {
history.args = history.show = args;
let res = await fn(args, context, history);
if (!res) {
// falsy implies return ()
// falsy implies return ()
res = '0x';
} else if (Array.isArray(res)) {
// an array implies we need to encode the arguments
Expand Down
7 changes: 1 addition & 6 deletions dist/index.d.ts → dist/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ export type History = {
then(): History;
}

type ResolverMap = {
[resolverKey: string]: HexString;
};
type SigningProtocol = 'tor' | 'ens' | 'raw';
type CallContextExtra = {[key: string]: any};
type CallContext = {
sender: HexString;
calldata: HexString;
protocol: SigningProtocol;
resolver: HexString;
resolvers: ResolverMap
resolverKey: string;
history: History;
} & CallContextExtra;
type CCIPReadFunction = (args: Result, context: CallContext, history: History) => Promise<BytesLike | any[] | undefined>;
Expand All @@ -55,7 +50,7 @@ export function processENSIP10(record: Record | undefined, calldata: HexString,
export function serve(handler: ENSIP10Function | EZCCIP, options?: {
log?: boolean | ((...a: any) => any); // default console.log w/date, falsy to disable
port?: number; // default random open
resolvers?: ResolverMap; // default: uses sender
resolvers?: { [tag: string]: HexString }; // default: uses sender
} & EZCCIPConfig): Promise<Readonly<{
http: { close(): void };
port: number;
Expand Down
66 changes: 66 additions & 0 deletions dist/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import type {SigningKey, BytesLike, BigNumberish, Interface, Result, FunctionFragment} from 'ethers';

type HexString = string;

export interface Record {
addr?(type: bigint) : Promise<BytesLike | undefined>;
text?(key: string) : Promise<string | undefined>;
contenthash?(): Promise<BytesLike | undefined>;
pubkey?(): Promise<{x: BigNumberish, y: BigNumberish} | BytesLike | undefined>;
name?(): Promise<string | undefined>;
ABI?(types: number): Promise<{type: number, data: BytesLike} | BytesLike | undefined>;
}

export type History = {
level: number;
next?: History;
children: History[];
name?: string;
error?: any;
show?: any[];
enter(): History;
then(): History;
}

type SigningProtocol = 'tor' | 'ens' | 'raw';
type CallContextExtra = {[key: string]: any};
type CallContext = {
sender: HexString;
calldata: HexString;
protocol: SigningProtocol;
resolver: HexString;
history: History;
} & CallContextExtra;
type CCIPReadFunction = (args: Result, context: CallContext, history: History) => Promise<BytesLike | any[] | undefined>;
type CCIPReadHandler = {abi: Interface, frag: FunctionFragment, fn: CCIPReadFunction};
type ENSIP10Function = (name: string, context: CallContext) => Promise<Record | undefined>;
type EZCCIPConfig = {
protocol?: SigningProtocol;
signingKey?: SigningKey | HexString;
ttlSec?: number;
recursionLimit?: number;
} & CallContextExtra;
export class EZCCIP {
enableENSIP10(get: ENSIP10Function, options?: {multicall?: boolean}): void;
register(abi: string | string[] | Interface, impl: CCIPReadFunction | {[name: string]: CCIPReadFunction}): CCIPReadHandler[];
handleRead(sender: HexString, calldata: HexString, config: EZCCIPConfig & {resolver?: HexString}): Promise<{data: HexString, history: History}>;
}
export function processENSIP10(record: Record | undefined, calldata: HexString, multicall?: boolean, history?: History): HexString;

export function serve(handler: ENSIP10Function | EZCCIP, options?: {
log?: boolean | ((...a: any) => any); // default console.log w/date, falsy to disable
port?: number; // default random open
resolvers?: { [tag: string]: HexString }; // default: uses sender
} & EZCCIPConfig): Promise<Readonly<{
http: { close(): void };
port: number;
endpoint: string;
signer: HexString;
context: string;
}>>;

export function asciiize(s: string): string;
export function labels_from_dns_encoded(v: Uint8Array): string[];
export function error_with(message: string, options: Object, cause?: any): Error;

export const RESOLVE_ABI: Interface;
2 changes: 1 addition & 1 deletion dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class EZCCIP {
history.args = history.show = args;
let res = await fn(args, context, history);
if (!res) {
// falsy implies return ()
// falsy implies return ()
res = '0x';
} else if (Array.isArray(res)) {
// an array implies we need to encode the arguments
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@resolverworks/ezccip",
"version": "0.0.13",
"version": "0.0.14",
"type": "module",
"scripts": {
"test": "node test/all.js",
"start": "node test/demo.js",
"build": "rollup -c"
"build": "cp dist/index.d.mts dist/index.d.cts && rollup -c"
},
"dependencies": {
"ethers": "^6.13.1"
Expand All @@ -14,7 +14,6 @@
"rollup": "^4.11.0"
},
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ezccip.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class EZCCIP {
history.args = history.show = args;
let res = await fn(args, context, history);
if (!res) {
// falsy implies return ()
// falsy implies return ()
res = '0x';
} else if (Array.isArray(res)) {
// an array implies we need to encode the arguments
Expand Down

0 comments on commit 2b37196

Please sign in to comment.