@zerc20/wallet-sdk 0.4.0 → 0.6.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.
Files changed (73) hide show
  1. package/LICENSE +17 -20
  2. package/README.md +2 -2
  3. package/dist/accountId.d.ts +5 -0
  4. package/dist/accountId.js +19 -0
  5. package/dist/accountId.js.map +1 -0
  6. package/dist/chain.d.ts +86 -9
  7. package/dist/chain.js +61 -33
  8. package/dist/chain.js.map +1 -1
  9. package/dist/context.d.ts +8 -2
  10. package/dist/context.js +15 -2
  11. package/dist/context.js.map +1 -1
  12. package/dist/core.d.ts +35 -5
  13. package/dist/core.js +98 -25
  14. package/dist/core.js.map +1 -1
  15. package/dist/errors.d.ts +20 -3
  16. package/dist/errors.js +7 -1
  17. package/dist/errors.js.map +1 -1
  18. package/dist/index.d.ts +4 -2
  19. package/dist/index.js +4 -2
  20. package/dist/index.js.map +1 -1
  21. package/dist/network.d.ts +4 -2
  22. package/dist/network.js +3 -1
  23. package/dist/network.js.map +1 -1
  24. package/dist/pos.d.ts +10 -1
  25. package/dist/pos.js +219 -55
  26. package/dist/pos.js.map +1 -1
  27. package/dist/prove.d.ts +3 -0
  28. package/dist/prove.js +9 -0
  29. package/dist/prove.js.map +1 -1
  30. package/dist/rageExit.d.ts +27 -4
  31. package/dist/rageExit.js +160 -49
  32. package/dist/rageExit.js.map +1 -1
  33. package/dist/seed.d.ts +4 -0
  34. package/dist/seed.js +13 -1
  35. package/dist/seed.js.map +1 -1
  36. package/dist/servers.d.ts +5 -0
  37. package/dist/servers.js +2 -0
  38. package/dist/servers.js.map +1 -1
  39. package/dist/services.d.ts +14 -6
  40. package/dist/services.js +35 -14
  41. package/dist/services.js.map +1 -1
  42. package/dist/spend.d.ts +53 -11
  43. package/dist/spend.js +171 -65
  44. package/dist/spend.js.map +1 -1
  45. package/dist/state.d.ts +21 -0
  46. package/dist/state.js.map +1 -1
  47. package/dist/sync.d.ts +10 -5
  48. package/dist/sync.js +49 -18
  49. package/dist/sync.js.map +1 -1
  50. package/dist/wallet.d.ts +132 -21
  51. package/dist/wallet.js +342 -91
  52. package/dist/wallet.js.map +1 -1
  53. package/package.json +3 -3
  54. package/src/accountId.ts +22 -0
  55. package/src/chain.ts +101 -49
  56. package/src/context.ts +27 -3
  57. package/src/core.ts +112 -26
  58. package/src/errors.ts +15 -2
  59. package/src/index.ts +15 -2
  60. package/src/network.ts +6 -3
  61. package/src/pos.ts +247 -61
  62. package/src/prove.ts +10 -0
  63. package/src/rageExit.ts +237 -61
  64. package/src/seed.ts +24 -1
  65. package/src/servers.ts +9 -1
  66. package/src/services.ts +36 -22
  67. package/src/spend.ts +188 -75
  68. package/src/state.ts +25 -1
  69. package/src/sync.ts +54 -19
  70. package/src/wallet.ts +437 -109
  71. package/wasm/zerc20_wallet_core.d.ts +1 -1
  72. package/wasm/zerc20_wallet_core.js +1 -1
  73. package/wasm/zerc20_wallet_core_bg.wasm +0 -0
package/LICENSE CHANGED
@@ -1,24 +1,21 @@
1
- This is free and unencumbered software released into the public domain.
1
+ MIT License
2
2
 
3
- Anyone is free to copy, modify, publish, use, compile, sell, or
4
- distribute this software, either in source code form or as a compiled
5
- binary, for any purpose, commercial or non-commercial, and by any
6
- means.
3
+ Copyright (c) 2026 zERC20
7
4
 
8
- In jurisdictions that recognize copyright laws, the author or authors
9
- of this software dedicate any and all copyright interest in the
10
- software to the public domain. We make this dedication for the benefit
11
- of the public at large and to the detriment of our heirs and
12
- successors. We intend this dedication to be an overt act of
13
- relinquishment in perpetuity of all present and future rights to this
14
- software under copyright law.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
15
11
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
- OTHER DEALINGS IN THE SOFTWARE.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
23
14
 
24
- For more information, please refer to <https://unlicense.org/>
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -19,9 +19,9 @@ const wallet = await Wallet.open({ network, walletClient, seed, persist: { load,
19
19
  await wallet.sync();
20
20
  wallet.balances();
21
21
  const q = await wallet.fees({ kind: 'send', token, amount });
22
- await (await wallet.send({ to: '0x…', token, amount, maxFee: q.fee })).wait();
22
+ await (await wallet.send({ to: 'zerc20id1…', token, amount, maxFee: q.fee })).wait();
23
23
  ```
24
24
 
25
25
  ## License
26
26
 
27
- [Unlicense](LICENSE)
27
+ [MIT](LICENSE)
@@ -0,0 +1,5 @@
1
+ import { type Address } from 'viem';
2
+ /** `address` as its zERC20 ID: checksummed text (bech32m, `zerc20id1…`) of its 20 bytes. */
3
+ export declare const accountId: (address: Address) => string;
4
+ /** The account `text` is the zERC20 ID of, or `null` if it is not one. */
5
+ export declare function idAccount(text: string): Address | null;
@@ -0,0 +1,19 @@
1
+ // A zERC20 ID: an account's address as text that no other wallet or exchange takes for an address, so that a payer
2
+ // pays the account privately, as only a zERC20 wallet does, and never by a public transfer to the address, which this
3
+ // wallet does not hold.
4
+ import { bech32m } from '@scure/base';
5
+ import { bytesToHex, getAddress, hexToBytes } from 'viem';
6
+ const PREFIX = 'zerc20id';
7
+ /** `address` as its zERC20 ID: checksummed text (bech32m, `zerc20id1…`) of its 20 bytes. */
8
+ export const accountId = (address) => bech32m.encode(PREFIX, bech32m.toWords(hexToBytes(address)), false);
9
+ /** The account `text` is the zERC20 ID of, or `null` if it is not one. */
10
+ export function idAccount(text) {
11
+ try {
12
+ const { prefix, bytes } = bech32m.decodeToBytes(text.trim());
13
+ return prefix === PREFIX && bytes.length === 20 ? getAddress(bytesToHex(bytes)) : null;
14
+ }
15
+ catch {
16
+ return null;
17
+ }
18
+ }
19
+ //# sourceMappingURL=accountId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountId.js","sourceRoot":"","sources":["../src/accountId.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,sHAAsH;AACtH,wBAAwB;AAExB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAgB,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAExE,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B,4FAA4F;AAC5F,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAU,EAAE,CACpD,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAEtE,0EAA0E;AAC1E,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7D,OAAO,MAAM,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACzF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
package/dist/chain.d.ts CHANGED
@@ -282,6 +282,41 @@ export declare const depositFactoryAbi: readonly [{
282
282
  }, {
283
283
  readonly type: "address";
284
284
  readonly name: "refundAddress";
285
+ }, {
286
+ readonly type: "address";
287
+ readonly name: "refundSigner";
288
+ }, {
289
+ readonly type: "address";
290
+ readonly name: "feeRecipient";
291
+ }, {
292
+ readonly type: "uint256";
293
+ readonly name: "fee";
294
+ }, {
295
+ readonly type: "address";
296
+ readonly name: "referrer";
297
+ }, {
298
+ readonly type: "uint16";
299
+ readonly name: "referralBps";
300
+ }];
301
+ readonly outputs: readonly [{
302
+ readonly type: "address";
303
+ }];
304
+ }, {
305
+ readonly name: "flush";
306
+ readonly type: "function";
307
+ readonly stateMutability: "nonpayable";
308
+ readonly inputs: readonly [{
309
+ readonly type: "address";
310
+ readonly name: "token";
311
+ }, {
312
+ readonly type: "address";
313
+ readonly name: "burnAddress";
314
+ }, {
315
+ readonly type: "address";
316
+ readonly name: "refundAddress";
317
+ }, {
318
+ readonly type: "address";
319
+ readonly name: "refundSigner";
285
320
  }, {
286
321
  readonly type: "address";
287
322
  readonly name: "feeRecipient";
@@ -299,6 +334,18 @@ export declare const depositFactoryAbi: readonly [{
299
334
  readonly type: "address";
300
335
  }];
301
336
  }];
337
+ /** Where a deposit address sends back what it cannot wrap, and a rage exit's refund: a fixed address, which anyone may
338
+ * refund to, or wherever the key at `signer` signs for each refund (`DepositAddress.refundTo`). */
339
+ export type Refund = {
340
+ address: Address;
341
+ } | {
342
+ signer: Address;
343
+ };
344
+ /** What the factory derives a deposit address from, in the order its `predict` and `flush` take it. */
345
+ export type FactoryArgs = readonly [Address, Hex, Address, Address, Address, bigint, Address, number];
346
+ /** `FactoryArgs` for a deposit address of `token` into `burnAddress` whose refunds go as `refund` says, and whose flush
347
+ * pays `fee` to `feeRecipient` and `referralBps` of the rest to `referrer`. */
348
+ export declare const factoryArgs: (token: Address, burnAddress: Hex, refund: Refund, feeRecipient: Address, fee: bigint, referrer: Address, referralBps: number) => FactoryArgs;
302
349
  /** The factory's `MAX_REFERRAL_BPS`: the most of a deposit, after the relayer's fee, that a referrer can take. */
303
350
  export declare const MAX_REFERRAL_BPS = 300;
304
351
  /** An app that hands out deposit addresses and takes `bps` of each payment to them, of what is left after the relayer's
@@ -316,7 +363,30 @@ export declare const depositAddressAbi: readonly [{
316
363
  readonly name: "asset";
317
364
  }];
318
365
  readonly outputs: readonly [];
366
+ }, {
367
+ readonly name: "refundTo";
368
+ readonly type: "function";
369
+ readonly stateMutability: "nonpayable";
370
+ readonly inputs: readonly [{
371
+ readonly type: "address";
372
+ readonly name: "asset";
373
+ }, {
374
+ readonly type: "address";
375
+ readonly name: "to";
376
+ }, {
377
+ readonly type: "uint256";
378
+ readonly name: "deadline";
379
+ }, {
380
+ readonly type: "bytes";
381
+ readonly name: "signature";
382
+ }];
383
+ readonly outputs: readonly [];
319
384
  }];
385
+ /** What a deposit address's refund signer signs to send its balance of `asset` to `to` until `deadline` (Unix seconds),
386
+ * as an EIP-191 message: the chain and the address are in it, so it moves nothing at the same address elsewhere. */
387
+ export declare const refundDigest: (chainId: bigint, depositAddress: Address, asset: Address, to: Address, deadline: bigint) => `0x${string}`;
388
+ /** Multicall3, at the address it has on every chain the deposit relayer serves: it puts calls in one transaction. */
389
+ export declare const MULTICALL3: Address;
320
390
  /** The native asset's stand-in for `underlyingAsset`. */
321
391
  export declare const NATIVE: Address;
322
392
  /** `Protocol.UNWRAP_INTENT`: the `withdrawIntent` that pays a withdrawal out as the underlying asset. The EIP-712 struct
@@ -333,21 +403,26 @@ export interface Token {
333
403
  symbol: string;
334
404
  decimals: number;
335
405
  }
406
+ /** A transport to a chain's RPCs, `urls` in order: a call one fails, or cannot be sent to, goes on to the next, so one
407
+ * that a resolver, a firewall or an outage keeps from a device stops nothing. A public RPC also turns calls away beyond
408
+ * some per second (Tenderly's gateways, about five `eth_call`s), which a sync and a deposit together pass: a call every
409
+ * one turned away is tried again, five times, the first after 0.15 s and each after twice the last, 4.65 s in all,
410
+ * since viem's default three give up within the second the limit counts. */
411
+ export declare const rpcTransport: (urls: readonly string[]) => import("viem").FallbackTransport<import("viem").HttpTransport<undefined, false>[]>;
336
412
  export declare class Chain {
337
413
  #private;
338
414
  readonly config: ChainConfig;
339
415
  readonly client: PublicClient;
340
416
  constructor(config: ChainConfig);
341
417
  get chainId(): bigint;
342
- ledger(): Promise<Address>;
343
- /** The deposit address the factory deploys for `token`, `burnAddress` and `refundAddress`, whose flush pays `fee`
344
- * to `feeRecipient` and `referralBps` of the rest to `referrer`. */
345
- predictDepositAddress(token: Address, burnAddress: Hex, refundAddress: Address, feeRecipient: Address, fee: bigint, referrer: Address, referralBps: number): Promise<Address>;
346
- /** The refund address of `address` if it is a deployed deposit address for `token` and `burnAddress`, whatever its
347
- * refund address, fee and referral; null if it is not one. A clone's code ends with its immutable args,
348
- * `abi.encode(token, burnAddress, refundAddress, feeRecipient, fee, referrer, referralBps)`; the factory's address
349
- * for them confirms it, so code made to look like one does not pass. */
350
- depositAddressRefund(address: Address, token: Address, burnAddress: Hex): Promise<Address | null>;
418
+ readonly ledger: () => Promise<`0x${string}`>;
419
+ /** The deposit address the factory deploys for `args`. */
420
+ predictDepositAddress(args: FactoryArgs): Promise<Address>;
421
+ /** Where `address` refunds to if it is a deployed deposit address for `token` and `burnAddress`, whatever its refund,
422
+ * fee and referral; null if it is not one. A clone's code ends with its immutable args,
423
+ * `abi.encode(token, burnAddress, refundAddress, refundSigner, feeRecipient, fee, referrer, referralBps)`; the
424
+ * factory's address for them confirms it, so code made to look like one does not pass. */
425
+ depositAddressRefund(address: Address, token: Address, burnAddress: Hex): Promise<Refund | null>;
351
426
  /** Whether the ledger accepts `root` as the tree at `size` leaves. */
352
427
  provedRoot(size: number, root: Hex): Promise<boolean>;
353
428
  /** `2^64 - 1`, unless the ledger is in an emergency: then it accepts no root above it, and proves none. */
@@ -356,4 +431,6 @@ export declare class Chain {
356
431
  withdrawFee(tokenId: number, amount: bigint): Promise<bigint>;
357
432
  /** Every token the factory has registered, read once and then only the new ones. */
358
433
  tokens(): Promise<Token[]>;
434
+ /** The tokens as `tokens()` last read them, without reading again. */
435
+ get known(): Token[];
359
436
  }
package/dist/chain.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // What a wallet reads from the chain itself, through its own RPC: roots are taken from here, never from a server.
2
- import { createPublicClient, decodeAbiParameters, http, keccak256, numberToHex, parseAbi, size, slice, toHex, zeroAddress, } from 'viem';
2
+ import { createPublicClient, decodeAbiParameters, encodeAbiParameters, fallback, http, keccak256, numberToHex, parseAbi, parseAbiParameters, size, slice, toHex, zeroAddress, } from 'viem';
3
3
  export const verifierAbi = parseAbi([
4
4
  'function ledger() view returns (address)',
5
5
  'function factory() view returns (address)',
@@ -35,64 +35,92 @@ export const erc20Abi = parseAbi([
35
35
  'function transfer(address to, uint256 amount) returns (bool)',
36
36
  ]);
37
37
  export const depositFactoryAbi = parseAbi([
38
- 'function predict(address token, address burnAddress, address refundAddress, address feeRecipient, uint256 fee, address referrer, uint16 referralBps) view returns (address)',
38
+ 'function predict(address token, address burnAddress, address refundAddress, address refundSigner, address feeRecipient, uint256 fee, address referrer, uint16 referralBps) view returns (address)',
39
+ 'function flush(address token, address burnAddress, address refundAddress, address refundSigner, address feeRecipient, uint256 fee, address referrer, uint16 referralBps) returns (address)',
39
40
  ]);
41
+ const refundArgs = (refund) => 'address' in refund ? [refund.address, zeroAddress] : [zeroAddress, refund.signer];
42
+ /** `FactoryArgs` for a deposit address of `token` into `burnAddress` whose refunds go as `refund` says, and whose flush
43
+ * pays `fee` to `feeRecipient` and `referralBps` of the rest to `referrer`. */
44
+ export const factoryArgs = (token, burnAddress, refund, feeRecipient, fee, referrer, referralBps) => [token, burnAddress, ...refundArgs(refund), feeRecipient, fee, referrer, referralBps];
40
45
  /** The factory's `MAX_REFERRAL_BPS`: the most of a deposit, after the relayer's fee, that a referrer can take. */
41
46
  export const MAX_REFERRAL_BPS = 300;
42
- export const depositAddressAbi = parseAbi(['function refund(address asset)']);
47
+ export const depositAddressAbi = parseAbi([
48
+ 'function refund(address asset)',
49
+ 'function refundTo(address asset, address to, uint256 deadline, bytes signature)',
50
+ ]);
51
+ /** What a deposit address's refund signer signs to send its balance of `asset` to `to` until `deadline` (Unix seconds),
52
+ * as an EIP-191 message: the chain and the address are in it, so it moves nothing at the same address elsewhere. */
53
+ export const refundDigest = (chainId, depositAddress, asset, to, deadline) => keccak256(encodeAbiParameters(parseAbiParameters('uint256, address, address, address, uint256'), [
54
+ chainId,
55
+ depositAddress,
56
+ asset,
57
+ to,
58
+ deadline,
59
+ ]));
60
+ /** Multicall3, at the address it has on every chain the deposit relayer serves: it puts calls in one transaction. */
61
+ export const MULTICALL3 = '0xcA11bde05977b3631167028862bE2a173976CA11';
43
62
  /** The native asset's stand-in for `underlyingAsset`. */
44
63
  export const NATIVE = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
45
64
  /** `Protocol.UNWRAP_INTENT`: the `withdrawIntent` that pays a withdrawal out as the underlying asset. The EIP-712 struct
46
65
  * hash of `Unwrap()`, reduced into the BN254 field. */
47
66
  export const UNWRAP_INTENT = BigInt(keccak256(keccak256(toHex('Unwrap()')))) %
48
67
  21888242871839275222246405745257275088548364400416034343698204186575808495617n;
68
+ /** A transport to a chain's RPCs, `urls` in order: a call one fails, or cannot be sent to, goes on to the next, so one
69
+ * that a resolver, a firewall or an outage keeps from a device stops nothing. A public RPC also turns calls away beyond
70
+ * some per second (Tenderly's gateways, about five `eth_call`s), which a sync and a deposit together pass: a call every
71
+ * one turned away is tried again, five times, the first after 0.15 s and each after twice the last, 4.65 s in all,
72
+ * since viem's default three give up within the second the limit counts. */
73
+ export const rpcTransport = (urls) => fallback(urls.map((url) => http(url, { retryCount: 0 })), { retryCount: 5 });
74
+ /** `read`, made once and then kept. A read that fails is not kept: the next call reads again, rather than failing for
75
+ * as long as the wallet is open. */
76
+ function once(read) {
77
+ let kept;
78
+ return () => (kept ??= read().catch((e) => {
79
+ kept = undefined;
80
+ throw e;
81
+ }));
82
+ }
49
83
  export class Chain {
50
84
  config;
51
85
  client;
52
- #ledger;
53
- #tokens;
86
+ #tokens = [];
54
87
  constructor(config) {
55
88
  this.config = config;
56
- this.client = createPublicClient({ transport: http(config.rpcUrl) });
89
+ this.client = createPublicClient({ transport: rpcTransport(config.rpcUrls) });
57
90
  }
58
91
  get chainId() {
59
92
  return this.config.chainId;
60
93
  }
61
- ledger() {
62
- this.#ledger ??= this.client.readContract({
63
- address: this.config.verifier,
64
- abi: verifierAbi,
65
- functionName: 'ledger',
66
- });
67
- return this.#ledger;
68
- }
69
- /** The deposit address the factory deploys for `token`, `burnAddress` and `refundAddress`, whose flush pays `fee`
70
- * to `feeRecipient` and `referralBps` of the rest to `referrer`. */
71
- predictDepositAddress(token, burnAddress, refundAddress, feeRecipient, fee, referrer, referralBps) {
94
+ // the verifier's ledger and token factory are set once, as it is initialized
95
+ ledger = once(() => this.client.readContract({ address: this.config.verifier, abi: verifierAbi, functionName: 'ledger' }));
96
+ #factory = once(() => this.client.readContract({ address: this.config.verifier, abi: verifierAbi, functionName: 'factory' }));
97
+ /** The deposit address the factory deploys for `args`. */
98
+ predictDepositAddress(args) {
72
99
  return this.client.readContract({
73
100
  address: this.config.depositAddressFactory,
74
101
  abi: depositFactoryAbi,
75
102
  functionName: 'predict',
76
- args: [token, burnAddress, refundAddress, feeRecipient, fee, referrer, referralBps],
103
+ args,
77
104
  });
78
105
  }
79
- /** The refund address of `address` if it is a deployed deposit address for `token` and `burnAddress`, whatever its
80
- * refund address, fee and referral; null if it is not one. A clone's code ends with its immutable args,
81
- * `abi.encode(token, burnAddress, refundAddress, feeRecipient, fee, referrer, referralBps)`; the factory's address
82
- * for them confirms it, so code made to look like one does not pass. */
106
+ /** Where `address` refunds to if it is a deployed deposit address for `token` and `burnAddress`, whatever its refund,
107
+ * fee and referral; null if it is not one. A clone's code ends with its immutable args,
108
+ * `abi.encode(token, burnAddress, refundAddress, refundSigner, feeRecipient, fee, referrer, referralBps)`; the
109
+ * factory's address for them confirms it, so code made to look like one does not pass. */
83
110
  async depositAddressRefund(address, token, burnAddress) {
84
111
  const code = await this.client.getCode({ address });
85
- if (!code || size(code) < 224)
112
+ if (!code || size(code) < 256)
86
113
  return null;
87
114
  // the uint16 read as a whole word, so code made to look like a clone cannot make the decoding throw
88
- const [refundAddress, feeRecipient, fee, referrer, referralBps] = decodeAbiParameters([{ type: 'address' }, { type: 'address' }, { type: 'uint256' }, { type: 'address' }, { type: 'uint256' }], slice(code, size(code) - 160));
115
+ const [refundAddress, refundSigner, feeRecipient, fee, referrer, referralBps] = decodeAbiParameters(parseAbiParameters('address, address, address, uint256, address, uint256'), slice(code, size(code) - 192));
89
116
  // predict would revert
90
- if (refundAddress === zeroAddress || feeRecipient === zeroAddress)
117
+ if ((refundAddress === zeroAddress) === (refundSigner === zeroAddress) || feeRecipient === zeroAddress)
91
118
  return null;
92
119
  if (referralBps > MAX_REFERRAL_BPS || (referrer === zeroAddress && referralBps !== 0n))
93
120
  return null;
94
- const expected = await this.predictDepositAddress(token, burnAddress, refundAddress, feeRecipient, fee, referrer, Number(referralBps));
95
- return expected.toLowerCase() === address.toLowerCase() ? refundAddress : null;
121
+ const refund = refundAddress === zeroAddress ? { signer: refundSigner } : { address: refundAddress };
122
+ const expected = await this.predictDepositAddress(factoryArgs(token, burnAddress, refund, feeRecipient, fee, referrer, Number(referralBps)));
123
+ return expected.toLowerCase() === address.toLowerCase() ? refund : null;
96
124
  }
97
125
  /** Whether the ledger accepts `root` as the tree at `size` leaves. */
98
126
  async provedRoot(size, root) {
@@ -125,13 +153,9 @@ export class Chain {
125
153
  }
126
154
  /** Every token the factory has registered, read once and then only the new ones. */
127
155
  async tokens() {
128
- const factory = await this.client.readContract({
129
- address: this.config.verifier,
130
- abi: verifierAbi,
131
- functionName: 'factory',
132
- });
156
+ const factory = await this.#factory();
133
157
  const count = await this.client.readContract({ address: factory, abi: factoryAbi, functionName: 'tokenCount' });
134
- const known = this.#tokens ?? [];
158
+ const known = this.#tokens;
135
159
  const fresh = await Promise.all(Array.from({ length: count - known.length }, async (_, i) => {
136
160
  const tokenId = known.length + i + 1;
137
161
  const address = await this.client.readContract({
@@ -151,5 +175,9 @@ export class Chain {
151
175
  this.#tokens = [...known, ...fresh];
152
176
  return this.#tokens;
153
177
  }
178
+ /** The tokens as `tokens()` last read them, without reading again. */
179
+ get known() {
180
+ return this.#tokens;
181
+ }
154
182
  }
155
183
  //# sourceMappingURL=chain.js.map
package/dist/chain.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,kHAAkH;AAElH,OAAO,EAIL,kBAAkB,EAClB,mBAAmB,EACnB,IAAI,EACJ,SAAS,EACT,WAAW,EACX,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,KAAK,EACL,WAAW,GACZ,MAAM,MAAM,CAAC;AAGd,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC;IAClC,0CAA0C;IAC1C,2CAA2C;IAC3C,iDAAiD;IACjD,6EAA6E;IAC7E,yEAAyE;IACzE,gQAAgQ;IAChQ,4IAA4I;IAC5I,4CAA4C;CAC7C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,QAAQ,CAAC;IAChC,sEAAsE;IACtE,wCAAwC;IACxC,iEAAiE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GAAG,CAAC,GAAG,CAAC,CAAC;YACrC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;gBAC7C,OAAO,EAAE,OAAO;gBAChB,GAAG,EAAE,UAAU;gBACf,YAAY,EAAE,WAAW;gBACzB,IAAI,EAAE,CAAC,OAAO,CAAC;aAChB,CAAC,CAAC;YACH,MAAM,IAAI,GAAG,CAAsD,YAAe,EAAE,EAAE,CACpF,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;YACrE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBACvD,IAAI,CAAC,QAAQ,CAAC;gBACd,IAAI,CAAC,UAAU,CAAC;gBAChB,IAAI,CAAC,iBAAiB,CAAC;aACxB,CAAC,CAAC;YACH,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QACnF,CAAC,CAAC,CACH,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,sEAAsE;IACtE,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
package/dist/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { CanisterClient, ViewKey } from '@zerc20/storage-sdk';
2
- import { type Account, type Hex, type WalletClient } from 'viem';
3
- import type { Chain } from './chain.js';
2
+ import { type Account, type Address, type Hex, type LocalAccount, type WalletClient } from 'viem';
3
+ import { type Chain } from './chain.js';
4
4
  import type { ChainConfig, Network } from './network.js';
5
5
  import type { Asp, Indexer } from './servers.js';
6
6
  import type { ChainState, WalletState } from './state.js';
@@ -29,6 +29,8 @@ export interface Ctx {
29
29
  /** The owners derived while the seed was held, or given by a view key, by key: the wallet's own (`''`) and each
30
30
  * receive code's. */
31
31
  owners: Map<string, Owner>;
32
+ /** The refund signers' addresses derived while the seed was held, by receive code (`refundSigner`). */
33
+ refundSigners: Map<string, Address>;
32
34
  address: Hex;
33
35
  /** The account that holds the public funds, and signs for them. */
34
36
  account: Account;
@@ -56,6 +58,10 @@ export declare function spendKey(ctx: Ctx, code?: CodeId): SpendKey;
56
58
  /** `spendKey`'s owner: derived before, or now if the seed is held; null if neither. The wallet's own is derived as it
57
59
  * opens. */
58
60
  export declare function owner(ctx: Ctx, code?: CodeId): Owner | null;
61
+ /** The key that signs where the refunds of the deposit address handed out with `code`'s burn address go. */
62
+ export declare function refundAccount(ctx: Ctx, code: CodeId): LocalAccount;
63
+ /** `refundAccount`'s address: derived before, or now if the seed is held; null if neither. */
64
+ export declare function refundSigner(ctx: Ctx, code: CodeId): Address | null;
59
65
  export declare function chainCtx(ctx: Ctx, chainId: bigint): ChainCtx;
60
66
  export declare function chainState(ctx: Ctx, chainId: bigint): ChainState;
61
67
  /** `wc` on `chainId`, switched there first: a browser wallet is on one chain at a time. */
package/dist/context.js CHANGED
@@ -1,7 +1,10 @@
1
1
  // Everything an open wallet works with, shared by sync and the operations.
2
- import { createWalletClient, http, publicActions } from 'viem';
2
+ import { createWalletClient, publicActions, } from 'viem';
3
+ import { privateKeyToAccount } from 'viem/accounts';
4
+ import { rpcTransport } from './chain.js';
3
5
  import { core } from './core.js';
4
6
  import { guard } from './errors.js';
7
+ import { refundKey } from './seed.js';
5
8
  const keys = new WeakMap();
6
9
  const idOf = (code) => (code ? `${code.chainId}:${code.tokenId}:${code.index}` : '');
7
10
  /** The seed, which the wallet holds whenever it does what needs it. */
@@ -33,6 +36,16 @@ export function spendKey(ctx, code) {
33
36
  export function owner(ctx, code) {
34
37
  return ctx.owners.get(idOf(code)) ?? (ctx.seed ? spendKey(ctx, code) : null);
35
38
  }
39
+ /** The key that signs where the refunds of the deposit address handed out with `code`'s burn address go. */
40
+ export function refundAccount(ctx, code) {
41
+ const account = privateKeyToAccount(refundKey(seedOf(ctx), code.chainId, code.tokenId, code.index));
42
+ ctx.refundSigners.set(idOf(code), account.address);
43
+ return account;
44
+ }
45
+ /** `refundAccount`'s address: derived before, or now if the seed is held; null if neither. */
46
+ export function refundSigner(ctx, code) {
47
+ return ctx.refundSigners.get(idOf(code)) ?? (ctx.seed ? refundAccount(ctx, code).address : null);
48
+ }
36
49
  export function chainCtx(ctx, chainId) {
37
50
  const c = ctx.chains.find((c) => c.config.chainId === chainId);
38
51
  if (!c)
@@ -56,7 +69,7 @@ export async function switched(wc, chainId) {
56
69
  export async function walletOn(ctx, chainId) {
57
70
  if (ctx.walletClient)
58
71
  return switched(ctx.walletClient, chainId);
59
- return createWalletClient({ account: ctx.account, transport: http(chainCtx(ctx, chainId).config.rpcUrl) });
72
+ return createWalletClient({ account: ctx.account, transport: rpcTransport(chainCtx(ctx, chainId).config.rpcUrls) });
60
73
  }
61
74
  /** Waits until the wallet's own node has a transaction mined on ours too: the wallet simulates the next one there, and
62
75
  * where blocks are fast that node lags ours now and then, so the next one would show as reverting. A wallet that does
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAG3E,OAAO,EAA6C,kBAAkB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAE1G,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AA+CpC,MAAM,IAAI,GAAG,IAAI,OAAO,EAAqC,CAAC;AAS9D,MAAM,IAAI,GAAG,CAAC,IAAa,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,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AAO,CAAC,EAAE,CAAC,CAAC;AACtH,CAAC;AAED;;kCAEkC;AAClC,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,EAAgB,EAAE,IAAS;IAC1D,MAAM,EAAE;SACL,MAAM,CAAC,aAAa,CAAC;SACrB,yBAAyB,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;SAC5E,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrB,CAAC"}
package/dist/core.d.ts CHANGED
@@ -9,8 +9,12 @@ export interface Burn {
9
9
  }
10
10
  /** The `index`-th burn address of `publicKey` on a chain and token, and its salt, from `burnKey`: the wallet's own burn
11
11
  * key, or a point of sale's (`wallet_keys::derive_burn_address`). About 2^16 hashes, spread over the device's cores
12
- * (Web Workers in a browser, worker threads in Node) so that the app stays responsive; `signal` stops the search. */
13
- export declare const burnAddress: (burnKey: Uint8Array, chainId: bigint, tokenId: number, index: number, publicKey: Hex, signal?: AbortSignal) => Promise<Burn>;
12
+ * (Web Workers in a browser, worker threads in Node) so that the app stays responsive; `signal` stops the search. One
13
+ * that nobody waits for, made ahead, is `urgent: false`: it gives way to those someone waits for. */
14
+ export declare const burnAddress: (burnKey: Uint8Array, chainId: bigint, tokenId: number, index: number, publicKey: Hex, opts?: {
15
+ signal?: AbortSignal;
16
+ urgent?: boolean;
17
+ }) => Promise<Burn>;
14
18
  /** A burn address of someone else's `publicKey` (one they published to be paid), with a random salt that has the proof
15
19
  * of work: about 2^16 hashes too, searched the same way. Only who holds the salt finds it: the payer, and the owner once
16
20
  * told (`planSend` with `burn`). */
@@ -36,9 +40,26 @@ export type BurnAnswer = {
36
40
  } | {
37
41
  error: string;
38
42
  };
39
- /** The address a block holds, if any. Its salts count up from a start: one the burn key derives, or for someone else's
40
- * key a random one below 2^253, so that every salt is a field element. */
41
- export declare function runBlock({ search: s, from, to }: BurnBlock): Burn | null;
43
+ /** What a block asks of the protocol code: `burnBlock`'s arguments, or `burnBlockFor`'s. */
44
+ export type BurnCall = {
45
+ burnKey: Uint8Array;
46
+ chainId: bigint;
47
+ tokenId: number;
48
+ index: number;
49
+ publicKey: Hex;
50
+ from: number;
51
+ to: number;
52
+ } | {
53
+ chainId: bigint;
54
+ publicKey: Hex;
55
+ start: Hex;
56
+ count: number;
57
+ };
58
+ /** A block's call. Its salts count up from a start: one the burn key derives, or for someone else's key a random one
59
+ * below 2^253, so that every salt is a field element. */
60
+ export declare function blockCall({ search: s, from, to }: BurnBlock): BurnCall;
61
+ /** The address a block holds, if any. */
62
+ export declare function runBlock(b: BurnBlock): Burn | null;
42
63
  type Outcome = {
43
64
  burn: Burn;
44
65
  } | {
@@ -55,4 +76,13 @@ export declare class Search {
55
76
  finish(block: number, burn: Burn | null): void;
56
77
  fail(error: unknown): void;
57
78
  }
79
+ /** Runs blocks somewhere other than this module's wasm: a server's native process, say. */
80
+ export interface BurnRunner {
81
+ /** How many blocks it runs at once. */
82
+ slots: number;
83
+ run(call: BurnCall): Promise<Burn | null>;
84
+ }
85
+ /** Runs every block from now on on `r`, or with null in this module's wasm again. The blocks the runner had are handed
86
+ * out again, and what it answers for them later is dropped. */
87
+ export declare function runBurnsOn(r: BurnRunner | null): void;
58
88
  export {};