Skip to content

Commit

Permalink
Bump ts, prettier. Fix cjs-esm modules
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jun 21, 2024
1 parent ce727bb commit 8f036f9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 55 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 @@
Minimal library for Ethereum transactions, addresses and smart contracts.

- 🔓 Secure: 3 deps, audited [noble](https://paulmillr.com/noble/) cryptography, no network code
- 🔻 Tree-shaking-friendly: use only what's necessary, other code won't be included
- 🔻 Tree-shakeable: unused code is excluded from your builds
- 🔍 Reliable: 150MB of test vectors from EIPs, ethers and viem
- ✍️ Create, sign and decode transactions using human-readable hints
- 🌍 Fetch balances and history from an archive node
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 10 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
],
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"types": "esm/index.d.ts",
"dependencies": {
"@noble/curves": "~1.4.0",
"@noble/hashes": "~1.4.0",
Expand All @@ -25,9 +25,9 @@
"micro-bmark": "0.3.1",
"micro-ftch": "0.4.0",
"micro-should": "0.4.0",
"prettier": "3.1.1",
"prettier": "3.3.2",
"snappyjs": "0.7.0",
"typescript": "5.3.2",
"typescript": "5.5.2",
"yaml": "2.4.1"
},
"author": "Paul Miller (https://paulmillr.com)",
Expand All @@ -38,39 +38,32 @@
"license": "MIT",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./esm/index.js",
"default": "./index.js"
"require": "./index.js"
},
"./abi": {
"types": "./abi/index.d.ts",
"import": "./esm/abi/index.js",
"default": "./abi/index.js"
"require": "./abi/index.js"
},
"./net": {
"types": "./net/index.d.ts",
"import": "./esm/net/index.js",
"default": "./net/index.js"
"require": "./net/index.js"
},
"./rlp": {
"types": "./rlp.d.ts",
"import": "./esm/rlp.js",
"default": "./rlp.js"
"require": "./rlp.js"
},
"./ssz": {
"types": "./ssz.d.ts",
"import": "./esm/ssz.js",
"default": "./net/ssz.js"
"require": "./ssz.js"
},
"./tx": {
"types": "./tx.d.ts",
"import": "./esm/tx.js",
"default": "./tx.js"
"require": "./tx.js"
},
"./utils": {
"types": "./utils.d.ts",
"import": "./esm/utils.js",
"default": "./utils.js"
"require": "./utils.js"
}
},
"keywords": [
Expand Down
50 changes: 24 additions & 26 deletions src/abi/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,17 @@ type ArrType<T extends string> = `${T}[${'' | ThreeDigits}]`;
type Arr2dType<T extends string> = `${T}[${'' | ThrityDigits}][${'' | ThrityDigits}]`;

// [{name: 'a', type: 'string'}, {name: 'b', type: 'uint'}] -> {a: string, b: bigint};
export type MapTuple<T> = T extends ArrLike<Component<string> & { name: string }>
? {
[K in T[number] as K['name']]: MapType<K>;
}
: T extends ArrLike<Component<string>>
? // [{name: 'a', type: 'string'}, {type: 'uint'}] -> [string, bigint];
{
[K in keyof T]: T[K] extends BaseComponent ? MapType<T[K]> : unknown;
export type MapTuple<T> =
T extends ArrLike<Component<string> & { name: string }>
? {
[K in T[number] as K['name']]: MapType<K>;
}
: unknown;
: T extends ArrLike<Component<string>>
? // [{name: 'a', type: 'string'}, {type: 'uint'}] -> [string, bigint];
{
[K in keyof T]: T[K] extends BaseComponent ? MapType<T[K]> : unknown;
}
: unknown;

// prettier-ignore
export type MapType<T extends BaseComponent> =
Expand Down Expand Up @@ -315,15 +316,14 @@ export type ContractTypeFilter<T> = {
[K in keyof T]: T[K] extends FunctionType & { name: string } ? T[K] : never;
};

export type ContractType<T extends Array<FnArg>, N, F = ContractTypeFilter<T>> = F extends ArrLike<
FunctionType & { name: string }
>
? {
[K in F[number] as K['name']]: N extends Web3Provider
? ContractMethodNet<K>
: ContractMethod<K>;
}
: never;
export type ContractType<T extends Array<FnArg>, N, F = ContractTypeFilter<T>> =
F extends ArrLike<FunctionType & { name: string }>
? {
[K in F[number] as K['name']]: N extends Web3Provider
? ContractMethodNet<K>
: ContractMethod<K>;
}
: never;

function fnSignature(o: FnArg): string {
if (!o.type) throw new Error('ABI.fnSignature wrong argument');
Expand Down Expand Up @@ -418,14 +418,12 @@ export type EventMethod<T extends EventType> = {
topics: (values: TopicsValue<ArgsType<T['inputs']>>) => (string | null)[];
};

export type ContractEventType<
T extends Array<FnArg>,
F = ContractEventTypeFilter<T>,
> = F extends ArrLike<EventType>
? {
[K in F[number] as K['name']]: EventMethod<K>;
}
: never;
export type ContractEventType<T extends Array<FnArg>, F = ContractEventTypeFilter<T>> =
F extends ArrLike<EventType>
? {
[K in F[number] as K['name']]: EventMethod<K>;
}
: never;

// TODO: try to simplify further
export function events<T extends ArrLike<FnArg>>(abi: T): ContractEventType<Writable<T>> {
Expand Down
4 changes: 3 additions & 1 deletion tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"extends": "@paulmillr/jsbt/tsconfigs/esm.json",
"compilerOptions": {
"outDir": "esm"
"outDir": "esm",
"declaration": true,
"declarationMap": true
},
"include": ["src"],
"exclude": ["node_modules", "lib"]
Expand Down
9 changes: 7 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"compilerOptions": {
"outDir": "."
},
"include": ["src"],
"exclude": ["node_modules", "lib"]
"include": [
"src"
],
"exclude": [
"node_modules",
"lib"
]
}

0 comments on commit 8f036f9

Please sign in to comment.