@onrail-xyz/evm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,416 @@
1
+ import type { Address } from "viem";
2
+ import type { RoUint8Array, OptionalArg } from "@onrail-xyz/utils";
3
+ import type { KindWithAtomic } from "@onrail-xyz/amount";
4
+ import { type AmountOrAtomic } from "@onrail-xyz/common";
5
+ import { type Deadline } from "./layouting.js";
6
+ import { type ContractMethods } from "./client.js";
7
+ import type { Eip712Domain, Eip712Message } from "./eip712.js";
8
+ declare const erc3009Spec: <const K extends KindWithAtomic | undefined = undefined>(...kind: OptionalArg<K>) => readonly [import("./client.js").FuncSpec<"authorizationState", readonly [import("./layouting.js").AbiParam<"authorizer", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"nonce", "bytes32", {
9
+ readonly binary: "bytes";
10
+ readonly size: 32;
11
+ }, RoUint8Array>], (authorizer: `0x${string}`, nonce: RoUint8Array) => {
12
+ authorizer: `0x${string}`;
13
+ nonce: RoUint8Array;
14
+ }, Readonly<{
15
+ binary: "bytes";
16
+ layout: {
17
+ readonly _padding: {
18
+ readonly binary: "bytes";
19
+ readonly fixed: Uint8Array<ArrayBuffer>;
20
+ };
21
+ readonly item: {
22
+ readonly binary: "uint";
23
+ readonly size: 1;
24
+ readonly custom: {
25
+ readonly to: (encoded: number) => boolean;
26
+ readonly from: (value: boolean) => number;
27
+ };
28
+ };
29
+ };
30
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
31
+ readonly item: boolean;
32
+ }, boolean>;
33
+ }>>, import("./client.js").FuncSpec<"transferWithAuthorization", readonly [import("./layouting.js").AbiParam<"from", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"to", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"value", "uint256", import("@onrail-xyz/common").AmountItem<32, K>, import("@onrail-xyz/common").AmountOr<K, bigint>>, import("./layouting.js").AbiParam<"validAfter", "uint256", import("@onrail-xyz/binary-layout").TimestampItem<{
34
+ readonly size: 32;
35
+ }>, Date>, import("./layouting.js").AbiParam<"validBefore", "uint256", import("@onrail-xyz/binary-layout").TimestampItem<{
36
+ readonly size: 32;
37
+ readonly saturateAs: "infinity";
38
+ }>, "infinity" | Date>, import("./layouting.js").AbiParam<"nonce", "bytes32", {
39
+ readonly binary: "bytes";
40
+ readonly size: 32;
41
+ }, RoUint8Array>, import("./layouting.js").AbiParam<"signature", "uint8,bytes32,bytes32", Readonly<{
42
+ binary: "bytes";
43
+ layout: {
44
+ readonly v: Readonly<{
45
+ binary: "bytes";
46
+ layout: {
47
+ readonly _padding: {
48
+ readonly binary: "bytes";
49
+ readonly fixed: Uint8Array<ArrayBuffer>;
50
+ };
51
+ readonly item: {
52
+ readonly binary: "uint";
53
+ readonly size: 1;
54
+ };
55
+ };
56
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
57
+ readonly item: number;
58
+ }, number>;
59
+ }>;
60
+ readonly r: {
61
+ readonly binary: "bytes";
62
+ readonly size: 32;
63
+ };
64
+ readonly s: {
65
+ readonly binary: "bytes";
66
+ readonly size: 32;
67
+ };
68
+ };
69
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
70
+ readonly v: number;
71
+ readonly r: RoUint8Array;
72
+ readonly s: RoUint8Array;
73
+ }, RoUint8Array>;
74
+ }>, RoUint8Array>], (from: `0x${string}`, to: `0x${string}`, value: import("@onrail-xyz/common").AmountOr<K, bigint>, validAfter: Date, validBefore: "infinity" | Date, nonce: RoUint8Array, signature: RoUint8Array) => {
75
+ from: `0x${string}`;
76
+ to: `0x${string}`;
77
+ value: import("@onrail-xyz/common").AmountOr<K, bigint>;
78
+ validAfter: Date;
79
+ validBefore: "infinity" | Date;
80
+ nonce: RoUint8Array;
81
+ signature: RoUint8Array;
82
+ }, undefined>, import("./client.js").FuncSpec<"receiveWithAuthorization", readonly [import("./layouting.js").AbiParam<"from", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"to", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"value", "uint256", import("@onrail-xyz/common").AmountItem<32, K>, import("@onrail-xyz/common").AmountOr<K, bigint>>, import("./layouting.js").AbiParam<"validAfter", "uint256", import("@onrail-xyz/binary-layout").TimestampItem<{
83
+ readonly size: 32;
84
+ }>, Date>, import("./layouting.js").AbiParam<"validBefore", "uint256", import("@onrail-xyz/binary-layout").TimestampItem<{
85
+ readonly size: 32;
86
+ readonly saturateAs: "infinity";
87
+ }>, "infinity" | Date>, import("./layouting.js").AbiParam<"nonce", "bytes32", {
88
+ readonly binary: "bytes";
89
+ readonly size: 32;
90
+ }, RoUint8Array>, import("./layouting.js").AbiParam<"signature", "uint8,bytes32,bytes32", Readonly<{
91
+ binary: "bytes";
92
+ layout: {
93
+ readonly v: Readonly<{
94
+ binary: "bytes";
95
+ layout: {
96
+ readonly _padding: {
97
+ readonly binary: "bytes";
98
+ readonly fixed: Uint8Array<ArrayBuffer>;
99
+ };
100
+ readonly item: {
101
+ readonly binary: "uint";
102
+ readonly size: 1;
103
+ };
104
+ };
105
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
106
+ readonly item: number;
107
+ }, number>;
108
+ }>;
109
+ readonly r: {
110
+ readonly binary: "bytes";
111
+ readonly size: 32;
112
+ };
113
+ readonly s: {
114
+ readonly binary: "bytes";
115
+ readonly size: 32;
116
+ };
117
+ };
118
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
119
+ readonly v: number;
120
+ readonly r: RoUint8Array;
121
+ readonly s: RoUint8Array;
122
+ }, RoUint8Array>;
123
+ }>, RoUint8Array>], (from: `0x${string}`, to: `0x${string}`, value: import("@onrail-xyz/common").AmountOr<K, bigint>, validAfter: Date, validBefore: "infinity" | Date, nonce: RoUint8Array, signature: RoUint8Array) => {
124
+ from: `0x${string}`;
125
+ to: `0x${string}`;
126
+ value: import("@onrail-xyz/common").AmountOr<K, bigint>;
127
+ validAfter: Date;
128
+ validBefore: "infinity" | Date;
129
+ nonce: RoUint8Array;
130
+ signature: RoUint8Array;
131
+ }, undefined>, import("./client.js").FuncSpec<"cancelAuthorization", readonly [import("./layouting.js").AbiParam<"authorizer", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"nonce", "bytes32", {
132
+ readonly binary: "bytes";
133
+ readonly size: 32;
134
+ }, RoUint8Array>, import("./layouting.js").AbiParam<"signature", "uint8,bytes32,bytes32", Readonly<{
135
+ binary: "bytes";
136
+ layout: {
137
+ readonly v: Readonly<{
138
+ binary: "bytes";
139
+ layout: {
140
+ readonly _padding: {
141
+ readonly binary: "bytes";
142
+ readonly fixed: Uint8Array<ArrayBuffer>;
143
+ };
144
+ readonly item: {
145
+ readonly binary: "uint";
146
+ readonly size: 1;
147
+ };
148
+ };
149
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
150
+ readonly item: number;
151
+ }, number>;
152
+ }>;
153
+ readonly r: {
154
+ readonly binary: "bytes";
155
+ readonly size: 32;
156
+ };
157
+ readonly s: {
158
+ readonly binary: "bytes";
159
+ readonly size: 32;
160
+ };
161
+ };
162
+ custom: import("@onrail-xyz/binary-layout").Conversion<{
163
+ readonly v: number;
164
+ readonly r: RoUint8Array;
165
+ readonly s: RoUint8Array;
166
+ }, RoUint8Array>;
167
+ }>, RoUint8Array>], (authorizer: `0x${string}`, nonce: RoUint8Array, signature: RoUint8Array) => {
168
+ authorizer: `0x${string}`;
169
+ nonce: RoUint8Array;
170
+ signature: RoUint8Array;
171
+ }, undefined>];
172
+ export declare const erc3009: <const K extends KindWithAtomic | undefined = undefined>(contract: Address, ...kind: OptionalArg<K>) => ContractMethods<ReturnType<typeof erc3009Spec<K>>>;
173
+ export declare const erc3009Events: readonly [import("./layouting.js").SigVariantOf<"AuthorizationUsed", readonly [import("./layouting.js").AbiParam<"authorizer", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"nonce", "bytes32", {
174
+ readonly binary: "bytes";
175
+ readonly size: 32;
176
+ }, RoUint8Array>]>, import("./layouting.js").SigVariantOf<"AuthorizationCanceled", readonly [import("./layouting.js").AbiParam<"authorizer", "address", import("./layouting.js").AddressItem, `0x${string}`>, import("./layouting.js").AbiParam<"nonce", "bytes32", {
177
+ readonly binary: "bytes";
178
+ readonly size: 32;
179
+ }, RoUint8Array>]>];
180
+ declare const authorizationType: readonly [{
181
+ readonly name: "from";
182
+ readonly type: "address";
183
+ }, {
184
+ readonly name: "to";
185
+ readonly type: "address";
186
+ }, {
187
+ readonly name: "value";
188
+ readonly type: "uint256";
189
+ }, {
190
+ readonly name: "validAfter";
191
+ readonly type: "uint256";
192
+ }, {
193
+ readonly name: "validBefore";
194
+ readonly type: "uint256";
195
+ }, {
196
+ readonly name: "nonce";
197
+ readonly type: "bytes32";
198
+ }];
199
+ declare const cancelAuthorizationType: readonly [{
200
+ readonly name: "authorizer";
201
+ readonly type: "address";
202
+ }, {
203
+ readonly name: "nonce";
204
+ readonly type: "bytes32";
205
+ }];
206
+ export type Eip3009AuthorizationMessage = Eip712Message<typeof authorizationType>;
207
+ export type Eip3009CancelMessage = Eip712Message<typeof cancelAuthorizationType>;
208
+ export declare const randomAuthorizationNonce: () => Uint8Array;
209
+ export declare const composeTransferWithAuthorizationMsg: (from: Address, to: Address, value: AmountOrAtomic, domain: Eip712Domain, nonce: RoUint8Array, validBefore?: Deadline, validAfter?: Date) => {
210
+ readonly types: {
211
+ readonly [x: string]: ({
212
+ readonly name: "name";
213
+ readonly type: "string";
214
+ } | {
215
+ readonly name: "version";
216
+ readonly type: "string";
217
+ } | {
218
+ readonly name: "chainId";
219
+ readonly type: "uint256";
220
+ } | {
221
+ readonly name: "verifyingContract";
222
+ readonly type: "address";
223
+ } | {
224
+ readonly name: "salt";
225
+ readonly type: "bytes32";
226
+ })[] | readonly [{
227
+ readonly name: "from";
228
+ readonly type: "address";
229
+ }, {
230
+ readonly name: "to";
231
+ readonly type: "address";
232
+ }, {
233
+ readonly name: "value";
234
+ readonly type: "uint256";
235
+ }, {
236
+ readonly name: "validAfter";
237
+ readonly type: "uint256";
238
+ }, {
239
+ readonly name: "validBefore";
240
+ readonly type: "uint256";
241
+ }, {
242
+ readonly name: "nonce";
243
+ readonly type: "bytes32";
244
+ }];
245
+ readonly EIP712Domain: ({
246
+ readonly name: "name";
247
+ readonly type: "string";
248
+ } | {
249
+ readonly name: "version";
250
+ readonly type: "string";
251
+ } | {
252
+ readonly name: "chainId";
253
+ readonly type: "uint256";
254
+ } | {
255
+ readonly name: "verifyingContract";
256
+ readonly type: "address";
257
+ } | {
258
+ readonly name: "salt";
259
+ readonly type: "bytes32";
260
+ })[];
261
+ };
262
+ readonly primaryType: "ReceiveWithAuthorization" | "TransferWithAuthorization";
263
+ readonly domain: Partial<Eip712Message<readonly [{
264
+ readonly name: "name";
265
+ readonly type: "string";
266
+ }, {
267
+ readonly name: "version";
268
+ readonly type: "string";
269
+ }, {
270
+ readonly name: "chainId";
271
+ readonly type: "uint256";
272
+ }, {
273
+ readonly name: "verifyingContract";
274
+ readonly type: "address";
275
+ }, {
276
+ readonly name: "salt";
277
+ readonly type: "bytes32";
278
+ }]>>;
279
+ readonly message: {
280
+ readonly from: `0x${string}`;
281
+ readonly to: `0x${string}`;
282
+ readonly value: bigint;
283
+ readonly validAfter: bigint;
284
+ readonly validBefore: bigint;
285
+ readonly nonce: RoUint8Array;
286
+ };
287
+ };
288
+ export declare const composeReceiveWithAuthorizationMsg: (from: Address, to: Address, value: AmountOrAtomic, domain: Eip712Domain, nonce: RoUint8Array, validBefore?: Deadline, validAfter?: Date) => {
289
+ readonly types: {
290
+ readonly [x: string]: ({
291
+ readonly name: "name";
292
+ readonly type: "string";
293
+ } | {
294
+ readonly name: "version";
295
+ readonly type: "string";
296
+ } | {
297
+ readonly name: "chainId";
298
+ readonly type: "uint256";
299
+ } | {
300
+ readonly name: "verifyingContract";
301
+ readonly type: "address";
302
+ } | {
303
+ readonly name: "salt";
304
+ readonly type: "bytes32";
305
+ })[] | readonly [{
306
+ readonly name: "from";
307
+ readonly type: "address";
308
+ }, {
309
+ readonly name: "to";
310
+ readonly type: "address";
311
+ }, {
312
+ readonly name: "value";
313
+ readonly type: "uint256";
314
+ }, {
315
+ readonly name: "validAfter";
316
+ readonly type: "uint256";
317
+ }, {
318
+ readonly name: "validBefore";
319
+ readonly type: "uint256";
320
+ }, {
321
+ readonly name: "nonce";
322
+ readonly type: "bytes32";
323
+ }];
324
+ readonly EIP712Domain: ({
325
+ readonly name: "name";
326
+ readonly type: "string";
327
+ } | {
328
+ readonly name: "version";
329
+ readonly type: "string";
330
+ } | {
331
+ readonly name: "chainId";
332
+ readonly type: "uint256";
333
+ } | {
334
+ readonly name: "verifyingContract";
335
+ readonly type: "address";
336
+ } | {
337
+ readonly name: "salt";
338
+ readonly type: "bytes32";
339
+ })[];
340
+ };
341
+ readonly primaryType: "ReceiveWithAuthorization" | "TransferWithAuthorization";
342
+ readonly domain: Partial<Eip712Message<readonly [{
343
+ readonly name: "name";
344
+ readonly type: "string";
345
+ }, {
346
+ readonly name: "version";
347
+ readonly type: "string";
348
+ }, {
349
+ readonly name: "chainId";
350
+ readonly type: "uint256";
351
+ }, {
352
+ readonly name: "verifyingContract";
353
+ readonly type: "address";
354
+ }, {
355
+ readonly name: "salt";
356
+ readonly type: "bytes32";
357
+ }]>>;
358
+ readonly message: {
359
+ readonly from: `0x${string}`;
360
+ readonly to: `0x${string}`;
361
+ readonly value: bigint;
362
+ readonly validAfter: bigint;
363
+ readonly validBefore: bigint;
364
+ readonly nonce: RoUint8Array;
365
+ };
366
+ };
367
+ export declare const composeCancelAuthorizationMsg: (authorizer: Address, domain: Eip712Domain, nonce: RoUint8Array) => {
368
+ readonly types: {
369
+ readonly EIP712Domain: ({
370
+ readonly name: "name";
371
+ readonly type: "string";
372
+ } | {
373
+ readonly name: "version";
374
+ readonly type: "string";
375
+ } | {
376
+ readonly name: "chainId";
377
+ readonly type: "uint256";
378
+ } | {
379
+ readonly name: "verifyingContract";
380
+ readonly type: "address";
381
+ } | {
382
+ readonly name: "salt";
383
+ readonly type: "bytes32";
384
+ })[];
385
+ readonly CancelAuthorization: readonly [{
386
+ readonly name: "authorizer";
387
+ readonly type: "address";
388
+ }, {
389
+ readonly name: "nonce";
390
+ readonly type: "bytes32";
391
+ }];
392
+ };
393
+ readonly primaryType: "CancelAuthorization";
394
+ readonly domain: Partial<Eip712Message<readonly [{
395
+ readonly name: "name";
396
+ readonly type: "string";
397
+ }, {
398
+ readonly name: "version";
399
+ readonly type: "string";
400
+ }, {
401
+ readonly name: "chainId";
402
+ readonly type: "uint256";
403
+ }, {
404
+ readonly name: "verifyingContract";
405
+ readonly type: "address";
406
+ }, {
407
+ readonly name: "salt";
408
+ readonly type: "bytes32";
409
+ }]>>;
410
+ readonly message: {
411
+ readonly authorizer: `0x${string}`;
412
+ readonly nonce: RoUint8Array;
413
+ };
414
+ };
415
+ export {};
416
+ //# sourceMappingURL=erc3009.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"erc3009.d.ts","sourceRoot":"","sources":["../src/erc3009.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,72 @@
1
+ import { toAtomicIfAmount, hashItem } from "@onrail-xyz/common";
2
+ import { deadlineItem, evmTimestampItem, abiBoolItem, abiSignatureItem, sigVariant, abiParam, amountParam, addressParam } from "./layouting.js";
3
+ import { abiFunction, contractFromSpec } from "./client.js";
4
+ import { eip712DomainType } from "./eip712.js";
5
+ const from = addressParam("from");
6
+ const to = addressParam("to");
7
+ const authorizer = addressParam("authorizer");
8
+ //the standard's nonce is a caller-chosen bytes32, unrelated to EIP-2612's sequential uint256
9
+ const nonce = abiParam("nonce", "bytes32", hashItem);
10
+ const validAfter = abiParam("validAfter", "uint256", evmTimestampItem);
11
+ const validBefore = abiParam("validBefore", "uint256", deadlineItem);
12
+ const signature = abiParam("signature", "uint8,bytes32,bytes32", abiSignatureItem);
13
+ const erc3009Spec = (...kind) => {
14
+ const value = amountParam("value", "uint256", ...kind);
15
+ //one parameter list under two names: the receiving variant binds the submitter to be `to`
16
+ const withAuthorization = (name) => abiFunction(name, [from, to, value, validAfter, validBefore, nonce, signature], (from, to, value, validAfter, validBefore, nonce, signature) => ({ from, to, value, validAfter, validBefore, nonce, signature }));
17
+ return [
18
+ abiFunction("authorizationState", [authorizer, nonce], (authorizer, nonce) => ({ authorizer, nonce }), abiBoolItem),
19
+ withAuthorization("transferWithAuthorization"),
20
+ withAuthorization("receiveWithAuthorization"),
21
+ abiFunction("cancelAuthorization", [authorizer, nonce, signature], (authorizer, nonce, signature) => ({ authorizer, nonce, signature })),
22
+ ];
23
+ };
24
+ export const erc3009 = (contract, ...kind) => contractFromSpec(contract, erc3009Spec(...kind));
25
+ //the standard's events as `buildParseEvent` variants; its reverts are left to implementations
26
+ export const erc3009Events = [
27
+ sigVariant("AuthorizationUsed", authorizer, nonce),
28
+ sigVariant("AuthorizationCanceled", authorizer, nonce),
29
+ ];
30
+ // ---- EIP-3009 Authorization Messages ----
31
+ const authorizationType = [
32
+ { name: "from", type: "address" },
33
+ { name: "to", type: "address" },
34
+ { name: "value", type: "uint256" },
35
+ { name: "validAfter", type: "uint256" },
36
+ { name: "validBefore", type: "uint256" },
37
+ { name: "nonce", type: "bytes32" },
38
+ ];
39
+ const cancelAuthorizationType = [
40
+ { name: "authorizer", type: "address" },
41
+ { name: "nonce", type: "bytes32" },
42
+ ];
43
+ export const randomAuthorizationNonce = () => crypto.getRandomValues(new Uint8Array(32));
44
+ //one struct under two names: the receiving variant additionally binds the submitter to be `to`
45
+ const composeAuthorization = (primaryType) => (from, to, value, domain, nonce, validBefore = "infinity", validAfter = new Date(0)) => {
46
+ const atomic = toAtomicIfAmount(value);
47
+ if (atomic < 0n)
48
+ throw new Error("Value must not be negative");
49
+ return {
50
+ types: { EIP712Domain: eip712DomainType(domain), [primaryType]: authorizationType },
51
+ primaryType,
52
+ domain,
53
+ message: { from,
54
+ to,
55
+ value: atomic,
56
+ validAfter: evmTimestampItem.custom.from(validAfter),
57
+ validBefore: deadlineItem.custom.from(validBefore),
58
+ nonce,
59
+ },
60
+ };
61
+ };
62
+ //compose an EIP-3009 authorization; `toViemTypedData` bridges it to viem's signing calls
63
+ export const composeTransferWithAuthorizationMsg = composeAuthorization("TransferWithAuthorization");
64
+ export const composeReceiveWithAuthorizationMsg = composeAuthorization("ReceiveWithAuthorization");
65
+ export const composeCancelAuthorizationMsg = (authorizer, domain, nonce) => ({
66
+ types: { EIP712Domain: eip712DomainType(domain),
67
+ CancelAuthorization: cancelAuthorizationType,
68
+ },
69
+ primaryType: "CancelAuthorization",
70
+ domain,
71
+ message: { authorizer, nonce },
72
+ });
@@ -0,0 +1,2 @@
1
+ export { keccak_256 as keccak256, sha3_256 } from "@noble/hashes/sha3.js";
2
+ //# sourceMappingURL=hashing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashing.d.ts","sourceRoot":"","sources":["../src/hashing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1 @@
1
+ export { keccak_256 as keccak256, sha3_256 } from "@noble/hashes/sha3.js";
@@ -0,0 +1,10 @@
1
+ export * from "./client.js";
2
+ export * from "./eip712.js";
3
+ export * from "./erc20.js";
4
+ export * from "./erc3009.js";
5
+ export * from "./hashing.js";
6
+ export * from "./layouting.js";
7
+ export * from "./parsing.js";
8
+ export * from "./permit.js";
9
+ export * from "./query.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./client.js";
2
+ export * from "./eip712.js";
3
+ export * from "./erc20.js";
4
+ export * from "./erc3009.js";
5
+ export * from "./hashing.js";
6
+ export * from "./layouting.js";
7
+ export * from "./parsing.js";
8
+ export * from "./permit.js";
9
+ export * from "./query.js";