@unlink-xyz/core 0.1.2 → 0.1.3-canary.0877bfe
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.
- package/dist/account/{zkAccount.d.ts → account.d.ts} +7 -5
- package/dist/account/account.d.ts.map +1 -0
- package/dist/account/{zkAccount.js → account.js} +57 -43
- package/dist/browser/index.js +108202 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/circuits.json +74 -0
- package/dist/clients/broadcaster.d.ts +7 -2
- package/dist/clients/broadcaster.d.ts.map +1 -1
- package/dist/clients/broadcaster.js +9 -1
- package/dist/clients/http.d.ts +6 -0
- package/dist/clients/http.d.ts.map +1 -1
- package/dist/clients/http.js +24 -9
- package/dist/clients/indexer.d.ts +11 -0
- package/dist/clients/indexer.d.ts.map +1 -1
- package/dist/clients/indexer.js +40 -11
- package/dist/config.d.ts +28 -9
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +33 -26
- package/dist/constants.d.ts +6 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +5 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +5 -2
- package/dist/crypto-adapters/auto-init.d.ts +2 -0
- package/dist/crypto-adapters/auto-init.d.ts.map +1 -0
- package/dist/crypto-adapters/auto-init.js +7 -0
- package/dist/crypto-adapters/index.d.ts +22 -0
- package/dist/crypto-adapters/index.d.ts.map +1 -0
- package/dist/crypto-adapters/index.js +47 -0
- package/dist/crypto-adapters/polyfills.d.ts +5 -0
- package/dist/crypto-adapters/polyfills.d.ts.map +1 -0
- package/dist/crypto-adapters/polyfills.js +8 -0
- package/dist/errors.d.ts +9 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +18 -0
- package/dist/history/index.d.ts +3 -0
- package/dist/history/index.d.ts.map +1 -0
- package/dist/history/index.js +2 -0
- package/dist/history/service.d.ts +46 -0
- package/dist/history/service.d.ts.map +1 -0
- package/dist/history/service.js +354 -0
- package/dist/history/types.d.ts +21 -0
- package/dist/history/types.d.ts.map +1 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/keys/address.d.ts +13 -0
- package/dist/keys/address.d.ts.map +1 -0
- package/dist/keys/address.js +55 -0
- package/dist/keys/derive.d.ts +37 -0
- package/dist/keys/derive.d.ts.map +1 -0
- package/dist/keys/derive.js +112 -0
- package/dist/keys/hex.d.ts +17 -0
- package/dist/keys/hex.d.ts.map +1 -0
- package/dist/keys/hex.js +66 -0
- package/dist/keys/index.d.ts +5 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +4 -0
- package/dist/keys/mnemonic.d.ts +8 -0
- package/dist/keys/mnemonic.d.ts.map +1 -0
- package/dist/keys/mnemonic.js +23 -0
- package/dist/keys.d.ts +4 -1
- package/dist/keys.d.ts.map +1 -1
- package/dist/keys.js +4 -0
- package/dist/prover/config.d.ts +1 -15
- package/dist/prover/config.d.ts.map +1 -1
- package/dist/prover/config.js +1 -11
- package/dist/prover/prover.d.ts +15 -4
- package/dist/prover/prover.d.ts.map +1 -1
- package/dist/prover/prover.js +115 -98
- package/dist/prover/registry.d.ts +3 -30
- package/dist/prover/registry.d.ts.map +1 -1
- package/dist/prover/registry.js +12 -51
- package/dist/state/merkle/hydrator.d.ts.map +1 -1
- package/dist/state/merkle/hydrator.js +3 -2
- package/dist/state/merkle/index.d.ts +1 -1
- package/dist/state/merkle/index.d.ts.map +1 -1
- package/dist/state/merkle/index.js +1 -1
- package/dist/state/merkle/merkle-tree.d.ts +8 -0
- package/dist/state/merkle/merkle-tree.d.ts.map +1 -1
- package/dist/state/merkle/merkle-tree.js +16 -7
- package/dist/state/store/ciphertext-store.d.ts +4 -0
- package/dist/state/store/ciphertext-store.d.ts.map +1 -1
- package/dist/state/store/ciphertext-store.js +12 -0
- package/dist/state/store/history-store.d.ts +24 -0
- package/dist/state/store/history-store.d.ts.map +1 -0
- package/dist/state/store/history-store.js +53 -0
- package/dist/state/store/index.d.ts +3 -2
- package/dist/state/store/index.d.ts.map +1 -1
- package/dist/state/store/index.js +1 -0
- package/dist/state/store/job-store.d.ts +7 -7
- package/dist/state/store/job-store.d.ts.map +1 -1
- package/dist/state/store/job-store.js +65 -39
- package/dist/state/store/jobs.d.ts +65 -18
- package/dist/state/store/jobs.d.ts.map +1 -1
- package/dist/state/store/leaf-store.d.ts.map +1 -1
- package/dist/state/store/leaf-store.js +0 -3
- package/dist/state/store/note-store.d.ts +7 -7
- package/dist/state/store/note-store.d.ts.map +1 -1
- package/dist/state/store/note-store.js +38 -34
- package/dist/state/store/nullifier-store.d.ts +9 -0
- package/dist/state/store/nullifier-store.d.ts.map +1 -1
- package/dist/state/store/nullifier-store.js +32 -2
- package/dist/state/store/records.d.ts +31 -2
- package/dist/state/store/records.d.ts.map +1 -1
- package/dist/state/store/root-store.d.ts.map +1 -1
- package/dist/state/store/root-store.js +0 -4
- package/dist/state/store/store.d.ts +61 -27
- package/dist/state/store/store.d.ts.map +1 -1
- package/dist/state/store/store.js +92 -1
- package/dist/storage/indexeddb.js +1 -1
- package/dist/storage/memory.d.ts.map +1 -1
- package/dist/storage/memory.js +5 -1
- package/dist/transactions/deposit.d.ts +12 -15
- package/dist/transactions/deposit.d.ts.map +1 -1
- package/dist/transactions/deposit.js +203 -152
- package/dist/transactions/index.d.ts +7 -4
- package/dist/transactions/index.d.ts.map +1 -1
- package/dist/transactions/index.js +7 -2
- package/dist/transactions/note-selection.d.ts +17 -0
- package/dist/transactions/note-selection.d.ts.map +1 -0
- package/dist/transactions/note-selection.js +201 -0
- package/dist/transactions/note-sync.d.ts +5 -33
- package/dist/transactions/note-sync.d.ts.map +1 -1
- package/dist/transactions/note-sync.js +320 -155
- package/dist/transactions/reconcile.d.ts +10 -12
- package/dist/transactions/reconcile.d.ts.map +1 -1
- package/dist/transactions/reconcile.js +53 -7
- package/dist/transactions/transact.d.ts +13 -24
- package/dist/transactions/transact.d.ts.map +1 -1
- package/dist/transactions/transact.js +393 -507
- package/dist/transactions/transaction-planner.d.ts +34 -0
- package/dist/transactions/transaction-planner.d.ts.map +1 -0
- package/dist/transactions/transaction-planner.js +116 -0
- package/dist/transactions/transfer-planner.d.ts +36 -0
- package/dist/transactions/transfer-planner.d.ts.map +1 -0
- package/dist/transactions/transfer-planner.js +85 -0
- package/dist/transactions/types/deposit.d.ts +67 -0
- package/dist/transactions/types/deposit.d.ts.map +1 -0
- package/dist/transactions/types/domain.d.ts +67 -0
- package/dist/transactions/types/domain.d.ts.map +1 -0
- package/dist/transactions/types/domain.js +4 -0
- package/dist/transactions/types/index.d.ts +18 -0
- package/dist/transactions/types/index.d.ts.map +1 -0
- package/dist/transactions/types/index.js +17 -0
- package/dist/transactions/types/options.d.ts +45 -0
- package/dist/transactions/types/options.d.ts.map +1 -0
- package/dist/transactions/types/options.js +1 -0
- package/dist/transactions/types/planning.d.ts +80 -0
- package/dist/transactions/types/planning.d.ts.map +1 -0
- package/dist/transactions/types/planning.js +1 -0
- package/dist/transactions/types/state-stores.d.ts +103 -0
- package/dist/transactions/types/state-stores.d.ts.map +1 -0
- package/dist/transactions/types/state-stores.js +1 -0
- package/dist/transactions/types/transact.d.ts +76 -0
- package/dist/transactions/types/transact.d.ts.map +1 -0
- package/dist/transactions/types/transact.js +1 -0
- package/dist/transactions/withdrawal-planner.d.ts +58 -0
- package/dist/transactions/withdrawal-planner.d.ts.map +1 -0
- package/dist/transactions/withdrawal-planner.js +128 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsup.browser.config.d.ts +7 -0
- package/dist/tsup.browser.config.d.ts.map +1 -0
- package/dist/tsup.browser.config.js +34 -0
- package/dist/utils/amounts.d.ts +39 -0
- package/dist/utils/amounts.d.ts.map +1 -0
- package/dist/utils/amounts.js +89 -0
- package/dist/utils/async.d.ts +9 -0
- package/dist/utils/async.d.ts.map +1 -1
- package/dist/utils/async.js +24 -0
- package/dist/utils/bigint.js +7 -7
- package/dist/utils/crypto.d.ts +11 -5
- package/dist/utils/crypto.d.ts.map +1 -1
- package/dist/utils/crypto.js +12 -6
- package/dist/utils/format.d.ts +25 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +33 -0
- package/dist/utils/json-codec.js +1 -1
- package/dist/utils/notes.d.ts +15 -0
- package/dist/utils/notes.d.ts.map +1 -0
- package/dist/utils/notes.js +14 -0
- package/dist/utils/polling.d.ts +5 -0
- package/dist/utils/polling.d.ts.map +1 -1
- package/dist/utils/polling.js +5 -0
- package/dist/utils/random.d.ts +13 -0
- package/dist/utils/random.d.ts.map +1 -0
- package/dist/utils/random.js +27 -0
- package/dist/utils/secure-memory.d.ts +25 -0
- package/dist/utils/secure-memory.d.ts.map +1 -0
- package/dist/utils/secure-memory.js +28 -0
- package/dist/utils/signature.d.ts +6 -0
- package/dist/utils/signature.d.ts.map +1 -1
- package/dist/utils/signature.js +8 -6
- package/dist/utils/validators.d.ts +21 -10
- package/dist/utils/validators.d.ts.map +1 -1
- package/dist/utils/validators.js +37 -11
- package/dist/vitest.config.d.ts +3 -0
- package/dist/vitest.config.d.ts.map +1 -0
- package/dist/vitest.config.js +13 -0
- package/package.json +28 -11
- package/.eslintrc.json +0 -4
- package/account/zkAccount.test.ts +0 -316
- package/account/zkAccount.ts +0 -222
- package/clients/broadcaster.ts +0 -67
- package/clients/http.ts +0 -94
- package/clients/indexer.ts +0 -150
- package/config.ts +0 -39
- package/core.ts +0 -17
- package/dist/account/railgun-imports-prototype.d.ts +0 -12
- package/dist/account/railgun-imports-prototype.d.ts.map +0 -1
- package/dist/account/railgun-imports-prototype.js +0 -30
- package/dist/account/zkAccount.d.ts.map +0 -1
- package/dist/key-derivation/babyjubjub.d.ts +0 -9
- package/dist/key-derivation/babyjubjub.d.ts.map +0 -1
- package/dist/key-derivation/babyjubjub.js +0 -9
- package/dist/key-derivation/bech32.d.ts +0 -22
- package/dist/key-derivation/bech32.d.ts.map +0 -1
- package/dist/key-derivation/bech32.js +0 -86
- package/dist/key-derivation/bip32.d.ts +0 -17
- package/dist/key-derivation/bip32.d.ts.map +0 -1
- package/dist/key-derivation/bip32.js +0 -41
- package/dist/key-derivation/bip39.d.ts +0 -22
- package/dist/key-derivation/bip39.d.ts.map +0 -1
- package/dist/key-derivation/bip39.js +0 -56
- package/dist/key-derivation/bytes.d.ts +0 -19
- package/dist/key-derivation/bytes.d.ts.map +0 -1
- package/dist/key-derivation/bytes.js +0 -92
- package/dist/key-derivation/hash.d.ts +0 -3
- package/dist/key-derivation/hash.d.ts.map +0 -1
- package/dist/key-derivation/hash.js +0 -10
- package/dist/key-derivation/index.d.ts +0 -8
- package/dist/key-derivation/index.d.ts.map +0 -1
- package/dist/key-derivation/index.js +0 -7
- package/dist/key-derivation/wallet-node.d.ts +0 -45
- package/dist/key-derivation/wallet-node.d.ts.map +0 -1
- package/dist/key-derivation/wallet-node.js +0 -109
- package/dist/state/ciphertext-store.d.ts +0 -12
- package/dist/state/ciphertext-store.d.ts.map +0 -1
- package/dist/state/ciphertext-store.js +0 -25
- package/dist/state/hydrator.d.ts +0 -16
- package/dist/state/hydrator.d.ts.map +0 -1
- package/dist/state/hydrator.js +0 -18
- package/dist/state/job-store.d.ts +0 -12
- package/dist/state/job-store.d.ts.map +0 -1
- package/dist/state/job-store.js +0 -118
- package/dist/state/jobs.d.ts +0 -50
- package/dist/state/jobs.d.ts.map +0 -1
- package/dist/state/jobs.js +0 -1
- package/dist/state/leaf-store.d.ts +0 -17
- package/dist/state/leaf-store.d.ts.map +0 -1
- package/dist/state/leaf-store.js +0 -35
- package/dist/state/merkle-tree.d.ts +0 -34
- package/dist/state/merkle-tree.d.ts.map +0 -1
- package/dist/state/merkle-tree.js +0 -104
- package/dist/state/note-store.d.ts +0 -37
- package/dist/state/note-store.d.ts.map +0 -1
- package/dist/state/note-store.js +0 -133
- package/dist/state/nullifier-store.d.ts +0 -13
- package/dist/state/nullifier-store.d.ts.map +0 -1
- package/dist/state/nullifier-store.js +0 -21
- package/dist/state/records.d.ts +0 -57
- package/dist/state/records.d.ts.map +0 -1
- package/dist/state/root-store.d.ts +0 -13
- package/dist/state/root-store.d.ts.map +0 -1
- package/dist/state/root-store.js +0 -30
- package/dist/state/store.d.ts +0 -26
- package/dist/state/store.d.ts.map +0 -1
- package/dist/state/store.js +0 -19
- package/dist/state.d.ts +0 -83
- package/dist/state.d.ts.map +0 -1
- package/dist/state.js +0 -171
- package/dist/transactions/shield.d.ts +0 -5
- package/dist/transactions/shield.d.ts.map +0 -1
- package/dist/transactions/shield.js +0 -93
- package/dist/transactions/types.d.ts +0 -114
- package/dist/transactions/types.d.ts.map +0 -1
- package/dist/transactions/utils.d.ts +0 -10
- package/dist/transactions/utils.d.ts.map +0 -1
- package/dist/transactions/utils.js +0 -17
- package/dist/utils/time.d.ts +0 -2
- package/dist/utils/time.d.ts.map +0 -1
- package/dist/utils/time.js +0 -3
- package/dist/utils/witness.d.ts +0 -11
- package/dist/utils/witness.d.ts.map +0 -1
- package/dist/utils/witness.js +0 -19
- package/errors.ts +0 -20
- package/index.ts +0 -17
- package/key-derivation/babyjubjub.ts +0 -11
- package/key-derivation/bech32.test.ts +0 -90
- package/key-derivation/bech32.ts +0 -124
- package/key-derivation/bip32.ts +0 -56
- package/key-derivation/bip39.ts +0 -76
- package/key-derivation/bytes.ts +0 -118
- package/key-derivation/hash.ts +0 -13
- package/key-derivation/index.ts +0 -7
- package/key-derivation/wallet-node.ts +0 -155
- package/keys.ts +0 -47
- package/prover/config.ts +0 -104
- package/prover/index.ts +0 -1
- package/prover/prover.integration.test.ts +0 -162
- package/prover/prover.test.ts +0 -309
- package/prover/prover.ts +0 -405
- package/prover/registry.test.ts +0 -90
- package/prover/registry.ts +0 -82
- package/schema.ts +0 -17
- package/setup-artifacts.sh +0 -57
- package/state/index.ts +0 -2
- package/state/merkle/hydrator.ts +0 -69
- package/state/merkle/index.ts +0 -12
- package/state/merkle/merkle-tree.test.ts +0 -50
- package/state/merkle/merkle-tree.ts +0 -163
- package/state/store/ciphertext-store.ts +0 -28
- package/state/store/index.ts +0 -24
- package/state/store/job-store.ts +0 -162
- package/state/store/jobs.ts +0 -64
- package/state/store/leaf-store.ts +0 -39
- package/state/store/note-store.ts +0 -177
- package/state/store/nullifier-store.ts +0 -39
- package/state/store/records.ts +0 -61
- package/state/store/root-store.ts +0 -34
- package/state/store/store.ts +0 -25
- package/state.test.ts +0 -235
- package/storage/index.ts +0 -3
- package/storage/indexeddb.test.ts +0 -99
- package/storage/indexeddb.ts +0 -235
- package/storage/memory.test.ts +0 -59
- package/storage/memory.ts +0 -93
- package/transactions/deposit.test.ts +0 -160
- package/transactions/deposit.ts +0 -227
- package/transactions/index.ts +0 -20
- package/transactions/note-sync.test.ts +0 -155
- package/transactions/note-sync.ts +0 -452
- package/transactions/reconcile.ts +0 -73
- package/transactions/transact.test.ts +0 -451
- package/transactions/transact.ts +0 -811
- package/transactions/types.ts +0 -141
- package/tsconfig.json +0 -14
- package/types/global.d.ts +0 -15
- package/types.ts +0 -24
- package/utils/async.ts +0 -15
- package/utils/bigint.ts +0 -34
- package/utils/crypto.test.ts +0 -69
- package/utils/crypto.ts +0 -58
- package/utils/json-codec.ts +0 -38
- package/utils/polling.ts +0 -6
- package/utils/signature.ts +0 -16
- package/utils/validators.test.ts +0 -64
- package/utils/validators.ts +0 -86
- /package/dist/{transactions → history}/types.js +0 -0
- /package/dist/{state/records.js → transactions/types/deposit.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nullifier-store.d.ts","sourceRoot":"","sources":["../../../state/store/nullifier-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAEjD;;OAEG;4BAC2B,eAAe;IAS7C;;OAEG;0BACyB,MAAM,SAAS,MAAM;
|
|
1
|
+
{"version":3,"file":"nullifier-store.d.ts","sourceRoot":"","sources":["../../../state/store/nullifier-store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO;IAEjD;;OAEG;4BAC2B,eAAe;IAS7C;;OAEG;0BACyB,MAAM,SAAS,MAAM;IAIjD;;OAEG;6BAC4B,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMvD;;OAEG;6BAC4B,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOrD;;;OAGG;sCAEQ,MAAM,aACJ,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC;EAmBnB"}
|
|
@@ -14,17 +14,47 @@ export function createNullifierStore(storage) {
|
|
|
14
14
|
* Lookup a previously observed nullifier by value.
|
|
15
15
|
*/
|
|
16
16
|
async getNullifier(chainId, value) {
|
|
17
|
-
ensureChainId(chainId);
|
|
18
17
|
return getJson(storage, keys.nullifier(chainId, value));
|
|
19
18
|
},
|
|
20
19
|
/**
|
|
21
20
|
* Count all nullifiers stored locally for a given chain.
|
|
22
21
|
*/
|
|
23
22
|
async countNullifiers(chainId) {
|
|
24
|
-
ensureChainId(chainId);
|
|
25
23
|
const prefix = `nullifiers:${chainId}:`;
|
|
26
24
|
const entries = await storage.iter({ prefix });
|
|
27
25
|
return entries.length;
|
|
28
26
|
},
|
|
27
|
+
/**
|
|
28
|
+
* Remove all cached nullifiers for a chain.
|
|
29
|
+
*/
|
|
30
|
+
async clearNullifiers(chainId) {
|
|
31
|
+
const prefix = `nullifiers:${chainId}:`;
|
|
32
|
+
const entries = await storage.iter({ prefix });
|
|
33
|
+
if (entries.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
await storage.batch(entries.map(({ key }) => ({ del: key })));
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Remove cached nullifiers whose noteIndex >= fromIndex.
|
|
39
|
+
* Used by partial resync to keep the count-based optimization accurate.
|
|
40
|
+
*/
|
|
41
|
+
async clearNullifiersFromIndex(chainId, fromIndex) {
|
|
42
|
+
const prefix = `nullifiers:${chainId}:`;
|
|
43
|
+
const entries = await storage.iter({ prefix });
|
|
44
|
+
const ops = [];
|
|
45
|
+
for (const { key, value } of entries) {
|
|
46
|
+
try {
|
|
47
|
+
const record = JSON.parse(new TextDecoder().decode(value));
|
|
48
|
+
if (record.noteIndex === undefined || record.noteIndex >= fromIndex) {
|
|
49
|
+
ops.push({ del: key });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Malformed entry — skip
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (ops.length > 0)
|
|
57
|
+
await storage.batch(ops);
|
|
58
|
+
},
|
|
29
59
|
};
|
|
30
60
|
}
|
|
@@ -22,10 +22,33 @@ export type NoteRecord = {
|
|
|
22
22
|
random: string;
|
|
23
23
|
/** Nullifier that will be revealed when the note is spent. */
|
|
24
24
|
nullifier: string;
|
|
25
|
-
/**
|
|
25
|
+
/**
|
|
26
|
+
* Transaction hash that inserted this note commitment on-chain.
|
|
27
|
+
* Derived from the indexer commitment record.
|
|
28
|
+
*/
|
|
29
|
+
createdTxHash?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Indexer event type associated with the commitment insertion.
|
|
32
|
+
* Typically "deposit" or "transact" once supported by the indexer.
|
|
33
|
+
*/
|
|
34
|
+
createdEventType?: string;
|
|
35
|
+
/** Optional timestamp (ms) when this note was created/observed by the indexer. */
|
|
36
|
+
createdAt?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Optional timestamp (ms) when the note was marked as spent.
|
|
39
|
+
* Prefer an on-chain/indexer-derived time when available; otherwise it may be a local observation time.
|
|
40
|
+
*/
|
|
41
|
+
spentAt?: number;
|
|
42
|
+
/** Transaction hash that spent this note (via its nullifier), when known. */
|
|
43
|
+
spentTxHash?: string;
|
|
44
|
+
};
|
|
45
|
+
export type NoteInsert = Omit<NoteRecord, "spentAt"> & {
|
|
46
|
+
/**
|
|
47
|
+
* Optional timestamp (ms) when the note was marked as spent.
|
|
48
|
+
* When omitted, existing spentAt (if any) is preserved by the note store.
|
|
49
|
+
*/
|
|
26
50
|
spentAt?: number;
|
|
27
51
|
};
|
|
28
|
-
export type NoteInsert = Omit<NoteRecord, 'spentAt'>;
|
|
29
52
|
/**
|
|
30
53
|
* Details about a nullifier observed on-chain, whether or not we own the note.
|
|
31
54
|
*/
|
|
@@ -45,6 +68,12 @@ export type LeafRecord = {
|
|
|
45
68
|
index: number;
|
|
46
69
|
/** Commitment value stored in the tree. */
|
|
47
70
|
commitment: string;
|
|
71
|
+
/** Transaction hash that created this commitment. */
|
|
72
|
+
txHash?: string;
|
|
73
|
+
/** Event type: "deposit" or "transact". */
|
|
74
|
+
eventType?: string;
|
|
75
|
+
/** Unix timestamp (seconds) when indexed. */
|
|
76
|
+
insertedAt?: number;
|
|
48
77
|
};
|
|
49
78
|
/**
|
|
50
79
|
* Historical merkle root snapshot used for proof construction.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records.d.ts","sourceRoot":"","sources":["../../../state/store/records.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,KAAK,EAAE,MAAM,CAAC;IACd,mDAAmD;IACnD,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,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AE,MAAM,CAAC;IACnB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"root-store.d.ts","sourceRoot":"","sources":["../../../state/store/root-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO;IAE5C;;OAEG;kBACiB,UAAU;IAU9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;
|
|
1
|
+
{"version":3,"file":"root-store.d.ts","sourceRoot":"","sources":["../../../state/store/root-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO;IAE5C;;OAEG;kBACiB,UAAU;IAU9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;EAI/C"}
|
|
@@ -20,10 +20,6 @@ export function createRootStore(storage) {
|
|
|
20
20
|
* Retrieve a root snapshot by Merkle root value.
|
|
21
21
|
*/
|
|
22
22
|
async getRoot(chainId, value) {
|
|
23
|
-
ensureChainId(chainId);
|
|
24
|
-
if (typeof value !== "string" || value.length === 0) {
|
|
25
|
-
throw new CoreError("root value must be a non-empty string");
|
|
26
|
-
}
|
|
27
23
|
return getJson(storage, keys.root(chainId, value));
|
|
28
24
|
},
|
|
29
25
|
};
|
|
@@ -1,34 +1,68 @@
|
|
|
1
|
+
import type { HistoryEntry } from "../../history/types.js";
|
|
1
2
|
import type { Storage } from "../../types.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
statuses?: import("./jobs.js").JobStatus[];
|
|
8
|
-
}): Promise<import("./jobs.js").PendingJobRecord[]>;
|
|
9
|
-
deletePendingJob(relayId: string): Promise<void>;
|
|
10
|
-
putCiphertext(chainId: number, index: number, payload: Uint8Array): Promise<void>;
|
|
11
|
-
getCiphertext(chainId: number, index: number): Promise<Uint8Array<ArrayBuffer> | null>;
|
|
12
|
-
putRoot(root: import("./records.js").RootRecord): Promise<void>;
|
|
13
|
-
getRoot(chainId: number, value: string): Promise<import("./records.js").RootRecord | null>;
|
|
14
|
-
putLeaf(leaf: import("./records.js").LeafRecord): Promise<void>;
|
|
15
|
-
getLeaf(chainId: number, index: number): Promise<import("./records.js").LeafRecord | null>;
|
|
16
|
-
clearLeaves(chainId: number): Promise<void>;
|
|
17
|
-
putNullifier(nullifier: import("./records.js").NullifierRecord): Promise<void>;
|
|
18
|
-
getNullifier(chainId: number, value: string): Promise<import("./records.js").NullifierRecord | null>;
|
|
19
|
-
countNullifiers(chainId: number): Promise<number>;
|
|
20
|
-
putNote(note: import("./records.js").NoteInsert): Promise<void>;
|
|
21
|
-
getNote(chainId: number, index: number): Promise<import("./records.js").NoteRecord | null>;
|
|
3
|
+
import type { JobKind, JobRecord, JobStatus } from "./jobs.js";
|
|
4
|
+
import type { LeafRecord, NoteInsert, NoteRecord, NullifierRecord, RootRecord } from "./records.js";
|
|
5
|
+
export interface StateStore {
|
|
6
|
+
putNote(note: NoteInsert): Promise<void>;
|
|
7
|
+
getNote(chainId: number, index: number): Promise<NoteRecord | null>;
|
|
22
8
|
listNotes(options?: {
|
|
23
9
|
chainId?: number;
|
|
24
10
|
mpk?: string;
|
|
25
11
|
token?: string;
|
|
26
12
|
includeSpent?: boolean;
|
|
27
|
-
}): Promise<
|
|
28
|
-
markNoteSpent(chainId: number, index: number, spentAt?: number): Promise<
|
|
29
|
-
markNoteUnspent(chainId: number, index: number): Promise<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
}): Promise<NoteRecord[]>;
|
|
14
|
+
markNoteSpent(chainId: number, index: number, spentAt?: number, spentTxHash?: string): Promise<NoteRecord>;
|
|
15
|
+
markNoteUnspent(chainId: number, index: number): Promise<NoteRecord>;
|
|
16
|
+
clearNotes(chainId: number): Promise<void>;
|
|
17
|
+
putNullifier(nullifier: NullifierRecord): Promise<void>;
|
|
18
|
+
getNullifier(chainId: number, value: string): Promise<NullifierRecord | null>;
|
|
19
|
+
countNullifiers(chainId: number): Promise<number>;
|
|
20
|
+
clearNullifiers(chainId: number): Promise<void>;
|
|
21
|
+
clearNullifiersFromIndex(chainId: number, fromIndex: number): Promise<void>;
|
|
22
|
+
putLeaf(leaf: LeafRecord): Promise<void>;
|
|
23
|
+
getLeaf(chainId: number, index: number): Promise<LeafRecord | null>;
|
|
24
|
+
clearLeaves(chainId: number): Promise<void>;
|
|
25
|
+
putRoot(root: RootRecord): Promise<void>;
|
|
26
|
+
getRoot(chainId: number, value: string): Promise<RootRecord | null>;
|
|
27
|
+
putCiphertext(chainId: number, index: number, payload: Uint8Array): Promise<void>;
|
|
28
|
+
getCiphertext(chainId: number, index: number): Promise<Uint8Array | null>;
|
|
29
|
+
clearCiphertexts(chainId: number): Promise<void>;
|
|
30
|
+
putJob(job: JobRecord): Promise<void>;
|
|
31
|
+
getJob(relayId: string): Promise<JobRecord | null>;
|
|
32
|
+
listJobs(filter?: {
|
|
33
|
+
kind?: JobKind;
|
|
34
|
+
statuses?: JobStatus[];
|
|
35
|
+
}): Promise<JobRecord[]>;
|
|
36
|
+
deleteJob(relayId: string): Promise<void>;
|
|
37
|
+
putHistoryEntry(entry: HistoryEntry): Promise<void>;
|
|
38
|
+
hasHistorySnapshot(options: {
|
|
39
|
+
chainId: number;
|
|
40
|
+
mpk: string;
|
|
41
|
+
}): Promise<boolean>;
|
|
42
|
+
listHistoryEntries(options: {
|
|
43
|
+
chainId: number;
|
|
44
|
+
mpk: string;
|
|
45
|
+
}): Promise<HistoryEntry[]>;
|
|
46
|
+
clearHistoryEntries(options: {
|
|
47
|
+
chainId: number;
|
|
48
|
+
mpk: string;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
commitHistorySnapshot(options: {
|
|
51
|
+
chainId: number;
|
|
52
|
+
mpk: string;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
syncCommitment(params: {
|
|
55
|
+
leaf: LeafRecord;
|
|
56
|
+
ciphertext: {
|
|
57
|
+
chainId: number;
|
|
58
|
+
index: number;
|
|
59
|
+
payload: Uint8Array;
|
|
60
|
+
};
|
|
61
|
+
root: RootRecord;
|
|
62
|
+
note?: NoteRecord;
|
|
63
|
+
}): Promise<void>;
|
|
64
|
+
/** Clear notes, leaves, ciphertexts, and unspent indices for indices >= fromIndex. */
|
|
65
|
+
clearChainDataFromIndex(chainId: number, fromIndex: number): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
export declare function createStateStore(storage: Storage): StateStore;
|
|
34
68
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../state/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../state/store/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAKvD,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,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CAAC,IAAI,CAAC,CAAC;IACpD,kBAAkB,CAAC,OAAO,EAAE;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;KACb,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB,kBAAkB,CAAC,OAAO,EAAE;QAC1B,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;KACb,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5B,mBAAmB,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9E,qBAAqB,CAAC,OAAO,EAAE;QAC7B,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,EAAE,MAAM,CAAC;KACb,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAGlB,cAAc,CAAC,MAAM,EAAE;QACrB,IAAI,EAAE,UAAU,CAAC;QACjB,UAAU,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,UAAU,CAAA;SAAE,CAAC;QACpE,IAAI,EAAE,UAAU,CAAC;QACjB,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElB,sFAAsF;IACtF,uBAAuB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5E;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAuH7D"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { keys } from "../../keys.js";
|
|
2
|
+
import { encodeJson } from "../../utils/json-codec.js";
|
|
1
3
|
import { createCiphertextStore } from "./ciphertext-store.js";
|
|
4
|
+
import { createHistoryStore } from "./history-store.js";
|
|
2
5
|
import { createJobStore } from "./job-store.js";
|
|
3
6
|
import { createLeafStore } from "./leaf-store.js";
|
|
4
|
-
import { createNoteStore } from "./note-store.js";
|
|
7
|
+
import { createNoteStore, emptyBytes } from "./note-store.js";
|
|
5
8
|
import { createNullifierStore } from "./nullifier-store.js";
|
|
6
9
|
import { createRootStore } from "./root-store.js";
|
|
7
10
|
export function createStateStore(storage) {
|
|
@@ -11,6 +14,91 @@ export function createStateStore(storage) {
|
|
|
11
14
|
const roots = createRootStore(storage);
|
|
12
15
|
const ciphertexts = createCiphertextStore(storage);
|
|
13
16
|
const jobs = createJobStore(storage);
|
|
17
|
+
const history = createHistoryStore(storage);
|
|
18
|
+
/**
|
|
19
|
+
* Atomically store a commitment's leaf, ciphertext, root, and optionally note.
|
|
20
|
+
* Uses storage.batch() for all-or-nothing semantics.
|
|
21
|
+
*/
|
|
22
|
+
async function syncCommitment(params) {
|
|
23
|
+
const { leaf, ciphertext, root, note } = params;
|
|
24
|
+
const ops = [
|
|
25
|
+
// Leaf
|
|
26
|
+
{
|
|
27
|
+
put: [
|
|
28
|
+
keys.leaf(leaf.chainId, leaf.index),
|
|
29
|
+
encodeJson(leaf),
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
// Ciphertext (raw bytes, not JSON)
|
|
33
|
+
{
|
|
34
|
+
put: [
|
|
35
|
+
keys.ciphertext(ciphertext.chainId, ciphertext.index),
|
|
36
|
+
ciphertext.payload,
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
// Root
|
|
40
|
+
{
|
|
41
|
+
put: [
|
|
42
|
+
keys.root(root.chainId, root.root),
|
|
43
|
+
encodeJson(root),
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
// Note (if decryption succeeded)
|
|
48
|
+
if (note) {
|
|
49
|
+
ops.push({
|
|
50
|
+
put: [
|
|
51
|
+
keys.note(note.chainId, note.index),
|
|
52
|
+
encodeJson(note),
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
// Maintain unspent index
|
|
56
|
+
if (note.spentAt === undefined) {
|
|
57
|
+
ops.push({
|
|
58
|
+
put: [keys.unspent(note.chainId, note.mpk, note.index), emptyBytes()],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await storage.batch(ops);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Clear notes, leaves, ciphertexts, and unspent indices for indices >= fromIndex.
|
|
66
|
+
* Used by partial resync to remove stale tail data while preserving the valid prefix.
|
|
67
|
+
*
|
|
68
|
+
* Key formats (see keys.ts): notes:${c}:${i}, leaves:${c}:${i},
|
|
69
|
+
* ciphertexts:${c}:${i}, idx:notes:unspent:${c}:${mpk}:${i}.
|
|
70
|
+
* The index is always the last colon-separated segment.
|
|
71
|
+
*/
|
|
72
|
+
async function clearChainDataFromIndex(chainId, fromIndex) {
|
|
73
|
+
const prefixes = [
|
|
74
|
+
`notes:${chainId}:`,
|
|
75
|
+
`leaves:${chainId}:`,
|
|
76
|
+
`ciphertexts:${chainId}:`,
|
|
77
|
+
];
|
|
78
|
+
const ops = [];
|
|
79
|
+
for (const prefix of prefixes) {
|
|
80
|
+
const entries = await storage.iter({ prefix });
|
|
81
|
+
for (const { key } of entries) {
|
|
82
|
+
// Index is always the last colon-segment (see keys.ts key builders)
|
|
83
|
+
const idx = parseInt(key.slice(key.lastIndexOf(":") + 1), 10);
|
|
84
|
+
if (!isNaN(idx) && idx >= fromIndex) {
|
|
85
|
+
ops.push({ del: key });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Clear unspent index entries (key: idx:notes:unspent:${c}:${mpk}:${index})
|
|
90
|
+
const unspentPrefix = `idx:notes:unspent:${chainId}:`;
|
|
91
|
+
const unspentEntries = await storage.iter({ prefix: unspentPrefix });
|
|
92
|
+
for (const { key } of unspentEntries) {
|
|
93
|
+
// Index is always the last colon-segment (see keys.ts key builders)
|
|
94
|
+
const idx = parseInt(key.slice(key.lastIndexOf(":") + 1), 10);
|
|
95
|
+
if (!isNaN(idx) && idx >= fromIndex) {
|
|
96
|
+
ops.push({ del: key });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (ops.length > 0)
|
|
100
|
+
await storage.batch(ops);
|
|
101
|
+
}
|
|
14
102
|
return {
|
|
15
103
|
...notes,
|
|
16
104
|
...nullifiers,
|
|
@@ -18,5 +106,8 @@ export function createStateStore(storage) {
|
|
|
18
106
|
...roots,
|
|
19
107
|
...ciphertexts,
|
|
20
108
|
...jobs,
|
|
109
|
+
...history,
|
|
110
|
+
syncCommitment,
|
|
111
|
+
clearChainDataFromIndex,
|
|
21
112
|
};
|
|
22
113
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAAuC,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3E,wBAAgB,mBAAmB,IAAI,OAAO,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../storage/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAIH,OAAO,EAAuC,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3E,wBAAgB,mBAAmB,IAAI,OAAO,CAmE7C"}
|
package/dist/storage/memory.js
CHANGED
|
@@ -38,7 +38,11 @@ export function createMemoryStorage() {
|
|
|
38
38
|
},
|
|
39
39
|
async delete(k) {
|
|
40
40
|
validateKey(k);
|
|
41
|
-
data.
|
|
41
|
+
const value = data.get(k);
|
|
42
|
+
if (value) {
|
|
43
|
+
// We don't zeroize here by default since we don't know if this is sensitive data.
|
|
44
|
+
data.delete(k);
|
|
45
|
+
}
|
|
42
46
|
},
|
|
43
47
|
async batch(ops) {
|
|
44
48
|
const draft = new Map(data);
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
syncPendingDeposit(relayId: string): Promise<DepositSyncResult>;
|
|
14
|
-
};
|
|
15
|
-
export {};
|
|
1
|
+
import type { BaseStateStore, DepositParams, DepositRelayResult, DepositSyncResult, ServiceOptions } from "./types/index.js";
|
|
2
|
+
export declare const DEPOSIT_ABI: readonly ["function deposit(address _depositor, (uint256 npk, uint256 amount, address token)[] notes, (uint256[3] data)[] ciphertexts) payable"];
|
|
3
|
+
/**
|
|
4
|
+
* Prepare a deposit: compute commitments, build calldata, and persist pending job.
|
|
5
|
+
* Accepts 1 or more notes in a single transaction.
|
|
6
|
+
*/
|
|
7
|
+
export declare function deposit(store: BaseStateStore, req: DepositParams): Promise<DepositRelayResult>;
|
|
8
|
+
/**
|
|
9
|
+
* Wait for all commitments in a deposit to be indexed and update local state.
|
|
10
|
+
* Works for both single and multi-note deposits.
|
|
11
|
+
*/
|
|
12
|
+
export declare function syncDeposit(store: BaseStateStore, relayId: string, opts: ServiceOptions): Promise<DepositSyncResult>;
|
|
16
13
|
//# sourceMappingURL=deposit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../transactions/deposit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deposit.d.ts","sourceRoot":"","sources":["../../transactions/deposit.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EAEjB,cAAc,EACf,MAAM,kBAAkB,CAAC;AAE1B,eAAO,MAAM,WAAW,kJAEd,CAAC;AAyEX;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,KAAK,EAAE,cAAc,EACrB,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC,kBAAkB,CAAC,CAgD7B;AAkHD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,cAAc,EACrB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,iBAAiB,CAAC,CAiD5B"}
|