moneysurfer 0.1.0 → 0.1.2

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 (3) hide show
  1. package/README.md +5 -4
  2. package/dist/cli.js +50 -18
  3. package/package.json +11 -9
package/README.md CHANGED
@@ -10,16 +10,17 @@ moneysurfer [v1|v2] <command> ...
10
10
 
11
11
  - Full V1 and V2 support: V1 on Ethereum, Optimism and Arbitrum; V2 on mainnet
12
12
  - One seed per protocol
13
- - Nothing is sent to the ASP
14
- - Withdraw via a relayer, yourself, or a Safe; ragequit if unapproved
13
+ - Nothing is sent to the ASP; its set is read from the chain
14
+ - Withdraw via a relayer (V1), yourself, or a Safe; ragequit if unapproved
15
15
  - Local prover in pure JS, everything simulated before sending
16
16
  - Sign with Frame, a private key or a keystore
17
- - No build step, minimal and security audited dependencies
17
+ - Minimal and security audited dependencies, bundled in: an install adds one package
18
+ - Node runs the sources as they are; only the published bundle is built
18
19
 
19
20
  ## Install
20
21
 
21
22
  ```sh
22
- pnpm i jsr:@microprivacy/moneysurfer
23
+ pnpm i -g moneysurfer
23
24
  ```
24
25
 
25
26
  Then fetch the circuits and make a seed:
package/dist/cli.js CHANGED
@@ -4389,9 +4389,13 @@ async function chain_getLogs(net, address, topics, from, to, progress) {
4389
4389
  }
4390
4390
  return address.length > 1 && !batched ? out.sort((a, b)=>Number(a.blockNumber) - Number(b.blockNumber) || Number(a.logIndex) - Number(b.logIndex)) : out;
4391
4391
  }
4392
+ function chain_writeCache(file, json) {
4393
+ mkdirSync(join(config_HOME, 'cache'), {
4394
+ recursive: !0
4395
+ }), writeFileSync(`${file}.tmp`, json), renameSync(`${file}.tmp`, file);
4396
+ }
4392
4397
  async function sync(net, log) {
4393
- var file, json;
4394
- let file1, head = Number(await net.call('eth_blockNumber')), ev = existsSync(file1 = chain_cacheFile()) ? JSON.parse(readFileSync(file1, 'utf8'), revive) : chain_empty(), from = Math.max(DEPLOYED_BLOCK, ev.block - chain_REORG_BLOCKS + 1), keep = (xs)=>xs.filter((x)=>x.block < from);
4398
+ let file, head = Number(await net.call('eth_blockNumber')), ev = existsSync(file = chain_cacheFile()) ? JSON.parse(readFileSync(file, 'utf8'), revive) : chain_empty(), from = Math.max(DEPLOYED_BLOCK, ev.block - chain_REORG_BLOCKS + 1), keep = (xs)=>xs.filter((x)=>x.block < from);
4395
4399
  ev.deposits = keep(ev.deposits), ev.ragequits = keep(ev.ragequits), ev.transacts = keep(ev.transacts), ev.notes = keep(ev.notes);
4396
4400
  let addresses = [
4397
4401
  POOL_ADDR,
@@ -4445,9 +4449,7 @@ async function sync(net, log) {
4445
4449
  ].sort((a, b)=>a[0] - b[0]);
4446
4450
  return ev.leaves = ordered(leaves), ev.keystoreLeaves = ordered(keystoreLeaves), ev.aspRoots = [
4447
4451
  ...aspRoots
4448
- ], ev.block = head, file = chain_cacheFile(), json = JSON.stringify(ev, replace), mkdirSync(join(config_HOME, 'cache'), {
4449
- recursive: !0
4450
- }), writeFileSync(`${file}.tmp`, json), renameSync(`${file}.tmp`, file), log?.(`${ev.deposits.length} deposits, ${ev.transacts.length} transacts, ${ev.ragequits.length} ragequits, ${ev.leaves.length} leaves, ${ev.keystoreLeaves.length} accounts`), ev;
4452
+ ], ev.block = head, chain_writeCache(chain_cacheFile(), JSON.stringify(ev, replace)), log?.(`${ev.deposits.length} deposits, ${ev.transacts.length} transacts, ${ev.ragequits.length} ragequits, ${ev.leaves.length} leaves, ${ev.keystoreLeaves.length} accounts`), ev;
4451
4453
  }
4452
4454
  async function chain_stateTree(net, ev) {
4453
4455
  return checked(net, POOL_ADDR, chain_POOL.isKnownRoot, ev.leaves, 'state');
@@ -4461,18 +4463,48 @@ async function checked(net, to, method, entries, what) {
4461
4463
  if (!await rpc_read(net, to, method, tree.root)) throw Error(`the ${what} tree we built has root 0x${tree.root.toString(16)}, which the contract does not know`);
4462
4464
  return tree;
4463
4465
  }
4464
- async function chain_aspSet(net) {
4465
- let root = await rpc_read(net, ASP_REGISTRY, ASP.latestASPRoot, void 0), url = `${aspApi()}/association-set/leaves?chainId=1&entrypoint=${ENTRYPOINT_ADDR}`, res = await fetch(url, {
4466
+ function chain_matching(leaves, root) {
4467
+ let tree = new crypto_LeanIMT(leaves);
4468
+ if (tree.root === root) return tree;
4469
+ let sorted = new crypto_LeanIMT([
4470
+ ...leaves
4471
+ ].sort((a, b)=>a < b ? -1 : +(a > b)));
4472
+ return sorted.root === root ? sorted : void 0;
4473
+ }
4474
+ async function chain_aspSet(net, log) {
4475
+ let [root, cid] = await Promise.all([
4476
+ rpc_read(net, ASP_REGISTRY, ASP.latestASPRoot, void 0),
4477
+ rpc_read(net, ASP_REGISTRY, ASP.latestIPFSCID, void 0)
4478
+ ]), done = (tree, source)=>({
4479
+ root,
4480
+ tree,
4481
+ source
4482
+ }), file = chain_aspCache(root);
4483
+ if (existsSync(file)) {
4484
+ let tree = chain_matching(JSON.parse(readFileSync(file, 'utf8')).map(BigInt), root);
4485
+ if (tree) return done(tree, 'cache');
4486
+ }
4487
+ let save = (tree)=>chain_writeCache(file, JSON.stringify(tree.levels[0].map(String)));
4488
+ for (let gw of config_IPFS_GATEWAYS)try {
4489
+ let res = await fetch(`${gw}/ipfs/${cid}`, {
4490
+ signal: AbortSignal.timeout(60000)
4491
+ });
4492
+ if (!res.ok) continue;
4493
+ let levels = await res.json(), tree = chain_matching(levels[0].map(BigInt), root);
4494
+ if (!tree) {
4495
+ log?.(`${gw} served ${cid}, but it does not hash to the ASP root -- ignored`);
4496
+ continue;
4497
+ }
4498
+ return save(tree), done(tree, `IPFS ${cid} via ${gw}`);
4499
+ } catch {}
4500
+ log?.(`no IPFS gateway served ${cid}; asking the ASP's API instead (it sees your IP, not your notes)`);
4501
+ let url = `${aspApi()}/association-set/leaves?chainId=1&entrypoint=${ENTRYPOINT_ADDR}`, res = await fetch(url, {
4466
4502
  signal: AbortSignal.timeout(60000)
4467
4503
  });
4468
4504
  if (!res.ok) throw Error(`${url}: HTTP ${res.status}`);
4469
- let { leaves } = await res.json(), tree = new crypto_LeanIMT(leaves.map(BigInt));
4470
- if (tree.root !== root) throw Error(`the ASP's ${tree.size} leaves hash to 0x${tree.root.toString(16)}, but the registry published 0x${root.toString(16)} -- the set is stale or is not this pool's`);
4471
- return {
4472
- root,
4473
- tree,
4474
- source: url
4475
- };
4505
+ let { leaves } = await res.json(), tree = chain_matching(leaves.map(BigInt), root);
4506
+ if (!tree) throw Error(`the ASP's ${leaves.length} leaves do not hash to the root the registry published (0x${root.toString(16)}) -- the set is stale or is not this pool's`);
4507
+ return save(tree), done(tree, url);
4476
4508
  }
4477
4509
  async function tokenMeta(net, token) {
4478
4510
  if (isNative(token)) return ETH_TOKEN;
@@ -4770,7 +4802,7 @@ async function v2_commands_balance(c) {
4770
4802
  ...new Set(all.map((a)=>a.tokenId))
4771
4803
  ], ev);
4772
4804
  if (!accounts.length) return v2_commands_log(`no notes found for this seed at ${owner}`);
4773
- let asp = await chain_aspSet(net), registered = await rpc_read(net, KEYSTORE_ADDR, KEYSTORE.nullifyingKeys, owner) !== 0n;
4805
+ let asp = await chain_aspSet(net, v2_commands_log), registered = await rpc_read(net, KEYSTORE_ADDR, KEYSTORE.nullifyingKeys, owner) !== 0n;
4774
4806
  v2_commands_out(`${owner}${registered ? '' : ' NOT REGISTERED -- `moneysurfer v2 register` before spending'}`);
4775
4807
  let byToken = new Map();
4776
4808
  for (let a of accounts){
@@ -5068,7 +5100,7 @@ async function commands_withdraw(key, amountArg, to, v, c) {
5068
5100
  let [state, ks, asp] = await Promise.all([
5069
5101
  chain_stateTree(net, ev),
5070
5102
  keystoreTree(net, ev),
5071
- chain_aspSet(net)
5103
+ chain_aspSet(net, v2_commands_log)
5072
5104
  ]), timestamp = await rpc_read(net, POOL_ADDR, chain_POOL.commitments, a.note.commitment);
5073
5105
  if (0n === timestamp) throw Error('the pool does not hold this note -- re-sync, or it was never mined');
5074
5106
  let note = {
@@ -5272,7 +5304,7 @@ async function commands_trees() {
5272
5304
  v2_commands_out(`state tree ${state.size} leaves, depth ${state.depth}, root ${hex32(state.root)} (the pool knows it)`);
5273
5305
  let ks = await keystoreTree(net, ev);
5274
5306
  v2_commands_out(`keystore tree ${ks.size} leaves, depth ${ks.depth}, root ${hex32(ks.root)} (the keystore knows it)`);
5275
- let asp = await chain_aspSet(net);
5307
+ let asp = await chain_aspSet(net, v2_commands_log);
5276
5308
  v2_commands_out(`association ${asp.tree.size} leaves, root ${hex32(asp.root)} (the registry published it)`);
5277
5309
  }
5278
5310
  async function commands_run(cmd, rest, v, c) {
@@ -14817,7 +14849,7 @@ let config_ASSETS = join(ASSETS_ROOT, 'v2'), config_HOME = join(HOME_ROOT, 'v2')
14817
14849
  leaves: [],
14818
14850
  keystoreLeaves: [],
14819
14851
  aspRoots: []
14820
- }), chain_cacheFile = ()=>join(config_HOME, 'cache', `1-${POOL_ADDR.toLowerCase()}.json`), revive = (_k, v)=>'string' == typeof v && /^\d+n$/.test(v) ? BigInt(v.slice(0, -1)) : v, replace = (_k, v)=>'bigint' == typeof v ? `${v}n` : v, ETH_TOKEN = {
14852
+ }), chain_cacheFile = ()=>join(config_HOME, 'cache', `1-${POOL_ADDR.toLowerCase()}.json`), revive = (_k, v)=>'string' == typeof v && /^\d+n$/.test(v) ? BigInt(v.slice(0, -1)) : v, replace = (_k, v)=>'bigint' == typeof v ? `${v}n` : v, chain_aspCache = (root)=>join(config_HOME, 'cache', `asp-1-${root}.json`), ETH_TOKEN = {
14821
14853
  symbol: 'ETH',
14822
14854
  decimals: 18
14823
14855
  }, underlyingKey = (a)=>a.router ? symbolKey(a.router.underlyingSymbol, a.router.underlying) : void 0, encodeStr = (str)=>Uint8Array.from(str.split(''), (c)=>c.charCodeAt(0)), sigma16_32 = ciphers_utils_swap32IfBE(ciphers_utils_u32(encodeStr('expand 16-byte k'))), sigma32_32 = ciphers_utils_swap32IfBE(ciphers_utils_u32(encodeStr('expand 32-byte k'))), U32_EMPTY = Uint32Array.of();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moneysurfer",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Lightweight CLI for Privacy Pools V1 and V2",
5
5
  "license": "MPL-2.0",
6
6
  "repository": {
@@ -8,12 +8,21 @@
8
8
  "url": "git+https://github.com/microprivacy/moneysurfer.git"
9
9
  },
10
10
  "type": "module",
11
+ "packageManager": "pnpm@12.3.4+sha512.961aa41fb077da3a04a441d9f8e15ebc0c96da8ef710b2eb67bf9ee7cb0610eabd48f1fd85f51cffe73846785fa0f87c56a3a872a1d893f8446741b5cce45457",
11
12
  "bin": {
12
13
  "moneysurfer": "./dist/cli.js"
13
14
  },
14
15
  "files": [
15
16
  "dist"
16
17
  ],
18
+ "scripts": {
19
+ "build": "rslib build",
20
+ "prepublishOnly": "pnpm build",
21
+ "typecheck": "tsc --noEmit",
22
+ "lint": "biome check",
23
+ "format": "biome check --write",
24
+ "test": "node --test test/*.test.ts"
25
+ },
17
26
  "engines": {
18
27
  "node": ">=22.18"
19
28
  },
@@ -29,12 +38,5 @@
29
38
  "micro-eth-signer": "^0.20.1",
30
39
  "micro-zk-proofs": "^0.3.1",
31
40
  "typescript": "^7.0.2"
32
- },
33
- "scripts": {
34
- "build": "rslib build",
35
- "typecheck": "tsc --noEmit",
36
- "lint": "biome check",
37
- "format": "biome check --write",
38
- "test": "node --test test/*.test.ts"
39
41
  }
40
- }
42
+ }