@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
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { HistoryEntry } from "../../history/types.js";
|
|
2
|
+
import type { Storage } from "../../types.js";
|
|
3
|
+
type HistoryEntryRecord = HistoryEntry;
|
|
4
|
+
export declare function createHistoryStore(storage: Storage): {
|
|
5
|
+
putHistoryEntry(entry: HistoryEntryRecord): Promise<void>;
|
|
6
|
+
hasHistorySnapshot(options: {
|
|
7
|
+
chainId: number;
|
|
8
|
+
mpk: string;
|
|
9
|
+
}): Promise<boolean>;
|
|
10
|
+
listHistoryEntries(options: {
|
|
11
|
+
chainId: number;
|
|
12
|
+
mpk: string;
|
|
13
|
+
}): Promise<HistoryEntry[]>;
|
|
14
|
+
clearHistoryEntries(options: {
|
|
15
|
+
chainId: number;
|
|
16
|
+
mpk: string;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
commitHistorySnapshot(options: {
|
|
19
|
+
chainId: number;
|
|
20
|
+
mpk: string;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=history-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-store.d.ts","sourceRoot":"","sources":["../../../state/store/history-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAQ9C,KAAK,kBAAkB,GAAG,YAAY,CAAC;AAGvC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO;2BASlB,kBAAkB;gCAOb;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;gCAShC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;iCAiB/B;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;mCAS9B;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE;EAMxE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { keys } from "../../keys.js";
|
|
2
|
+
import { decodeJson, encodeJson, } from "../../utils/json-codec.js";
|
|
3
|
+
import { ensureChainId, ensureMpk } from "../../utils/validators.js";
|
|
4
|
+
export function createHistoryStore(storage) {
|
|
5
|
+
async function putMeta(options) {
|
|
6
|
+
await storage.put(keys.historyMeta(options.chainId, options.mpk), encodeJson({ v: 1, updatedAtMs: Date.now() }));
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
async putHistoryEntry(entry) {
|
|
10
|
+
ensureChainId(entry.chainId);
|
|
11
|
+
ensureMpk(entry.mpk);
|
|
12
|
+
const key = keys.historyEntry(entry.id);
|
|
13
|
+
await storage.put(key, encodeJson(entry));
|
|
14
|
+
},
|
|
15
|
+
async hasHistorySnapshot(options) {
|
|
16
|
+
ensureChainId(options.chainId);
|
|
17
|
+
ensureMpk(options.mpk);
|
|
18
|
+
const meta = await storage.get(keys.historyMeta(options.chainId, options.mpk));
|
|
19
|
+
return meta !== null;
|
|
20
|
+
},
|
|
21
|
+
async listHistoryEntries(options) {
|
|
22
|
+
ensureChainId(options.chainId);
|
|
23
|
+
ensureMpk(options.mpk);
|
|
24
|
+
const prefix = keys.historyPrefix(options.chainId, options.mpk);
|
|
25
|
+
const entries = await storage.iter({ prefix });
|
|
26
|
+
const decoded = entries
|
|
27
|
+
.filter(({ key }) => !key.endsWith(":__meta__"))
|
|
28
|
+
.map(({ value }) => decodeJson(value));
|
|
29
|
+
decoded.sort((a, b) => {
|
|
30
|
+
const at = a.timestamp ?? 0;
|
|
31
|
+
const bt = b.timestamp ?? 0;
|
|
32
|
+
if (at !== bt)
|
|
33
|
+
return bt - at;
|
|
34
|
+
return b.txHash.localeCompare(a.txHash);
|
|
35
|
+
});
|
|
36
|
+
return decoded;
|
|
37
|
+
},
|
|
38
|
+
async clearHistoryEntries(options) {
|
|
39
|
+
ensureChainId(options.chainId);
|
|
40
|
+
ensureMpk(options.mpk);
|
|
41
|
+
const prefix = keys.historyPrefix(options.chainId, options.mpk);
|
|
42
|
+
const existing = await storage.iter({ prefix });
|
|
43
|
+
if (existing.length === 0)
|
|
44
|
+
return;
|
|
45
|
+
await storage.batch(existing.map(({ key }) => ({ del: key })));
|
|
46
|
+
},
|
|
47
|
+
async commitHistorySnapshot(options) {
|
|
48
|
+
ensureChainId(options.chainId);
|
|
49
|
+
ensureMpk(options.mpk);
|
|
50
|
+
await putMeta(options);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export { createStateStore } from "./store.js";
|
|
1
|
+
export { createStateStore, type StateStore } from "./store.js";
|
|
2
2
|
export { createLeafStore } from "./leaf-store.js";
|
|
3
3
|
export { createNoteStore } from "./note-store.js";
|
|
4
4
|
export { createNullifierStore } from "./nullifier-store.js";
|
|
5
5
|
export { createRootStore } from "./root-store.js";
|
|
6
6
|
export { createCiphertextStore } from "./ciphertext-store.js";
|
|
7
|
+
export { createHistoryStore } from "./history-store.js";
|
|
7
8
|
export { createJobStore } from "./job-store.js";
|
|
8
|
-
export { DEFAULT_JOB_TIMEOUT_MS, type JobStatus, type
|
|
9
|
+
export { DEFAULT_JOB_TIMEOUT_MS, type JobStatus, type JobKind, type JobRecord, type DepositRecord, type TransferRecord, type WithdrawRecord, type PoolTransactionRecord, type TransactContext, type TransactOutput, } from "./jobs.js";
|
|
9
10
|
export type { LeafRecord, NoteInsert, NoteRecord, NullifierRecord, RootRecord, } from "./records.js";
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../state/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../state/store/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACL,sBAAsB,EACtB,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,cAAc,GACpB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,GACX,MAAM,cAAc,CAAC"}
|
|
@@ -4,5 +4,6 @@ export { createNoteStore } from "./note-store.js";
|
|
|
4
4
|
export { createNullifierStore } from "./nullifier-store.js";
|
|
5
5
|
export { createRootStore } from "./root-store.js";
|
|
6
6
|
export { createCiphertextStore } from "./ciphertext-store.js";
|
|
7
|
+
export { createHistoryStore } from "./history-store.js";
|
|
7
8
|
export { createJobStore } from "./job-store.js";
|
|
8
9
|
export { DEFAULT_JOB_TIMEOUT_MS, } from "./jobs.js";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Storage } from "../../types.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { JobKind, JobRecord, JobStatus } from "../store/jobs.js";
|
|
3
3
|
export declare function createJobStore(storage: Storage): {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
kind?:
|
|
4
|
+
putJob(job: JobRecord): Promise<void>;
|
|
5
|
+
getJob(relayId: string): Promise<JobRecord | null>;
|
|
6
|
+
listJobs(filter?: {
|
|
7
|
+
kind?: JobKind;
|
|
8
8
|
statuses?: JobStatus[];
|
|
9
|
-
}): Promise<
|
|
10
|
-
|
|
9
|
+
}): Promise<JobRecord[]>;
|
|
10
|
+
deleteJob(relayId: string): Promise<void>;
|
|
11
11
|
};
|
|
12
12
|
//# sourceMappingURL=job-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-store.d.ts","sourceRoot":"","sources":["../../../state/store/job-store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"job-store.d.ts","sourceRoot":"","sources":["../../../state/store/job-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAQ9C,OAAO,KAAK,EAEV,OAAO,EACP,SAAS,EACT,SAAS,EAEV,MAAM,kBAAkB,CAAC;AAwI1B,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO;gBAEzB,SAAS;oBASL,MAAM;sBAKlB;QACN,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;KACxB;uBAesB,MAAM;EAIlC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { CoreError } from "../../errors.js";
|
|
1
2
|
import { keys } from "../../keys.js";
|
|
2
3
|
import { decodeJson, encodeJson, getJson } from "../../utils/json-codec.js";
|
|
3
|
-
import { ensureAddress, ensureChainId, ensurePositiveInt, } from "../../utils/validators.js";
|
|
4
|
+
import { ensureAddress, ensureChainId, ensureMpk, ensurePositiveInt, } from "../../utils/validators.js";
|
|
4
5
|
import { DEFAULT_JOB_TIMEOUT_MS } from "../store/jobs.js";
|
|
5
6
|
const VALID_STATUSES = [
|
|
6
7
|
"pending",
|
|
@@ -10,14 +11,15 @@ const VALID_STATUSES = [
|
|
|
10
11
|
"failed",
|
|
11
12
|
"dead",
|
|
12
13
|
];
|
|
14
|
+
const VALID_KINDS = ["deposit", "transfer", "withdraw"];
|
|
13
15
|
function assertStatus(status) {
|
|
14
16
|
if (!VALID_STATUSES.includes(status)) {
|
|
15
|
-
throw new
|
|
17
|
+
throw new CoreError(`invalid job status: ${status}`);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
function assertKind(kind) {
|
|
19
|
-
if (kind
|
|
20
|
-
throw new
|
|
21
|
+
if (!VALID_KINDS.includes(kind)) {
|
|
22
|
+
throw new CoreError(`invalid job kind: ${kind}`);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
function normalizeTimestamps(job) {
|
|
@@ -33,47 +35,71 @@ function normalizeTimestamps(job) {
|
|
|
33
35
|
timeoutMs,
|
|
34
36
|
};
|
|
35
37
|
}
|
|
36
|
-
function
|
|
37
|
-
ensurePositiveInt("context index", context.index);
|
|
38
|
-
if (!context.nullifier) {
|
|
39
|
-
throw new Error("context nullifier is required");
|
|
40
|
-
}
|
|
41
|
-
const { witness } = context;
|
|
42
|
-
if (!witness) {
|
|
43
|
-
throw new Error("context witness is required");
|
|
44
|
-
}
|
|
45
|
-
ensurePositiveInt("witness leafIndex", witness.leafIndex);
|
|
46
|
-
if (!Array.isArray(witness.pathElements) ||
|
|
47
|
-
!Array.isArray(witness.pathIndices)) {
|
|
48
|
-
throw new Error("witness pathElements and pathIndices are required");
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function validateTransactJob(job) {
|
|
38
|
+
function validatePoolTransactionRecord(job) {
|
|
52
39
|
ensureAddress("pool address", job.poolAddress);
|
|
53
40
|
if (!job.calldata) {
|
|
54
|
-
throw new
|
|
41
|
+
throw new CoreError("calldata is required for pool transaction record");
|
|
55
42
|
}
|
|
56
|
-
job.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
if (!Array.isArray(job.transactions) || !job.transactions.length) {
|
|
44
|
+
throw new CoreError("transactions array is required");
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < job.transactions.length; i++) {
|
|
47
|
+
const tx = job.transactions[i];
|
|
48
|
+
ensureAddress(`transaction token at ${i}`, tx.token);
|
|
49
|
+
if (!Array.isArray(tx.nullifiers) || !tx.nullifiers.length) {
|
|
50
|
+
throw new CoreError(`nullifiers array is required at index ${i}`);
|
|
51
|
+
}
|
|
52
|
+
// predictedCommitments can be empty for withdrawals with no change
|
|
53
|
+
if (!Array.isArray(tx.predictedCommitments)) {
|
|
54
|
+
throw new CoreError(`predicted commitments array is required at index ${i}`);
|
|
55
|
+
}
|
|
56
|
+
// Only require non-empty commitments if there's no withdrawal
|
|
57
|
+
if (!tx.predictedCommitments.length && !tx.withdrawal) {
|
|
58
|
+
throw new CoreError(`predicted commitments are required at index ${i}`);
|
|
60
59
|
}
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
for (let j = 0; j < tx.predictedCommitments.length; j++) {
|
|
61
|
+
const c = tx.predictedCommitments[j];
|
|
62
|
+
if (!c.hex) {
|
|
63
|
+
throw new CoreError(`predicted commitment hex is required at index ${i}.${j}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (tx.withdrawal) {
|
|
67
|
+
if (!tx.withdrawal.amount) {
|
|
68
|
+
throw new CoreError(`withdrawal amount is required at index ${i}`);
|
|
69
|
+
}
|
|
70
|
+
if (!tx.withdrawal.recipient) {
|
|
71
|
+
throw new CoreError(`withdrawal recipient is required at index ${i}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
}
|
|
64
|
-
function
|
|
65
|
-
if (!job.
|
|
66
|
-
|
|
76
|
+
function validateDepositRecord(job) {
|
|
77
|
+
if (!Array.isArray(job.predictedCommitments) ||
|
|
78
|
+
!job.predictedCommitments.length) {
|
|
79
|
+
throw new CoreError("predicted commitments array is required for deposit");
|
|
67
80
|
}
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
for (let i = 0; i < job.predictedCommitments.length; i++) {
|
|
82
|
+
const c = job.predictedCommitments[i];
|
|
83
|
+
if (!c.hex) {
|
|
84
|
+
throw new CoreError(`predicted commitment hex is required at index ${i}`);
|
|
85
|
+
}
|
|
86
|
+
ensureAddress(`predicted commitment token at ${i}`, c.token);
|
|
87
|
+
if (!c.amount) {
|
|
88
|
+
throw new CoreError(`predicted commitment amount is required at index ${i}`);
|
|
89
|
+
}
|
|
90
|
+
if (c.index !== undefined) {
|
|
91
|
+
ensurePositiveInt(`predicted commitment index at ${i}`, c.index);
|
|
92
|
+
}
|
|
70
93
|
}
|
|
71
94
|
}
|
|
72
95
|
function validateJob(job) {
|
|
73
96
|
if (!job.relayId) {
|
|
74
|
-
throw new
|
|
97
|
+
throw new CoreError("relayId is required");
|
|
75
98
|
}
|
|
76
99
|
ensureChainId(job.chainId);
|
|
100
|
+
if (job.mpk !== undefined) {
|
|
101
|
+
ensureMpk(job.mpk);
|
|
102
|
+
}
|
|
77
103
|
assertStatus(job.status);
|
|
78
104
|
assertKind(job.kind);
|
|
79
105
|
ensurePositiveInt("job createdAt", job.createdAt);
|
|
@@ -82,10 +108,10 @@ function validateJob(job) {
|
|
|
82
108
|
ensurePositiveInt("job lastCheckedAt", job.lastCheckedAt);
|
|
83
109
|
}
|
|
84
110
|
if (job.kind === "deposit") {
|
|
85
|
-
|
|
111
|
+
validateDepositRecord(job);
|
|
86
112
|
}
|
|
87
113
|
else {
|
|
88
|
-
|
|
114
|
+
validatePoolTransactionRecord(job);
|
|
89
115
|
}
|
|
90
116
|
}
|
|
91
117
|
function buildJobKey(relayId) {
|
|
@@ -93,15 +119,15 @@ function buildJobKey(relayId) {
|
|
|
93
119
|
}
|
|
94
120
|
export function createJobStore(storage) {
|
|
95
121
|
return {
|
|
96
|
-
async
|
|
122
|
+
async putJob(job) {
|
|
97
123
|
const normalized = normalizeTimestamps(job);
|
|
98
124
|
validateJob(normalized);
|
|
99
125
|
await storage.put(buildJobKey(normalized.relayId), encodeJson(normalized));
|
|
100
126
|
},
|
|
101
|
-
async
|
|
127
|
+
async getJob(relayId) {
|
|
102
128
|
return getJson(storage, buildJobKey(relayId));
|
|
103
129
|
},
|
|
104
|
-
async
|
|
130
|
+
async listJobs(filter = {}) {
|
|
105
131
|
const entries = await storage.iter({ prefix: "jobs:" });
|
|
106
132
|
const statuses = filter.statuses ?? VALID_STATUSES;
|
|
107
133
|
const filtered = entries
|
|
@@ -111,7 +137,7 @@ export function createJobStore(storage) {
|
|
|
111
137
|
filtered.sort((a, b) => a.createdAt - b.createdAt);
|
|
112
138
|
return filtered;
|
|
113
139
|
},
|
|
114
|
-
async
|
|
140
|
+
async deleteJob(relayId) {
|
|
115
141
|
await storage.delete(buildJobKey(relayId));
|
|
116
142
|
},
|
|
117
143
|
};
|
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
export type JobStatus = "pending" | "submitted" | "broadcasting" | "succeeded" | "failed" | "dead";
|
|
2
|
-
export type
|
|
3
|
-
export type
|
|
2
|
+
export type JobKind = "deposit" | "transfer" | "withdraw";
|
|
3
|
+
export type JobRecordBase = {
|
|
4
4
|
relayId: string;
|
|
5
|
-
kind:
|
|
5
|
+
kind: JobKind;
|
|
6
6
|
chainId: number;
|
|
7
|
+
/** Master public key (hex string) for correlating jobs with history/account views. */
|
|
8
|
+
mpk?: string;
|
|
7
9
|
status: JobStatus;
|
|
8
|
-
broadcasterRelayId?: string | null;
|
|
9
10
|
txHash?: string | null;
|
|
10
11
|
createdAt: number;
|
|
11
12
|
lastCheckedAt?: number;
|
|
12
13
|
timeoutMs: number;
|
|
13
14
|
error?: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* Optional history preview so UIs can show pending/failed history rows before notes are indexed.
|
|
17
|
+
* Amount deltas follow HistoryAmount semantics (positive receive, negative send).
|
|
18
|
+
*/
|
|
19
|
+
historyPreview?: {
|
|
20
|
+
kind: "Deposit" | "Receive" | "Send" | "SelfSend" | "Withdraw";
|
|
21
|
+
amounts: Array<{
|
|
22
|
+
token: string;
|
|
23
|
+
delta: string;
|
|
24
|
+
}>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Predicted commitment info for deposits.
|
|
29
|
+
*/
|
|
30
|
+
export type PredictedCommitment = {
|
|
31
|
+
hex: string;
|
|
32
|
+
token: string;
|
|
33
|
+
amount: string;
|
|
34
|
+
index?: number;
|
|
35
|
+
root?: string;
|
|
14
36
|
};
|
|
15
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Record for tracking deposits
|
|
39
|
+
*/
|
|
40
|
+
export type DepositRecord = JobRecordBase & {
|
|
16
41
|
kind: "deposit";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
index?: number;
|
|
20
|
-
root?: string;
|
|
21
|
-
};
|
|
42
|
+
/** Predicted commitments for each note */
|
|
43
|
+
predictedCommitments: PredictedCommitment[];
|
|
22
44
|
};
|
|
23
|
-
export type
|
|
45
|
+
export type TransactContext = {
|
|
24
46
|
index: number;
|
|
25
47
|
nullifier: string;
|
|
26
48
|
witness: {
|
|
@@ -32,19 +54,44 @@ export type PendingTransactContext = {
|
|
|
32
54
|
};
|
|
33
55
|
root: string;
|
|
34
56
|
};
|
|
35
|
-
export type
|
|
57
|
+
export type TransactOutput = {
|
|
36
58
|
hex: string;
|
|
37
59
|
index: number;
|
|
38
60
|
root?: string;
|
|
39
61
|
};
|
|
40
|
-
|
|
41
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Individual transaction info within a transact job.
|
|
64
|
+
*/
|
|
65
|
+
export type TransactJobTransaction = {
|
|
66
|
+
token: string;
|
|
67
|
+
nullifiers: string[];
|
|
68
|
+
predictedCommitments: Array<{
|
|
69
|
+
hex: string;
|
|
70
|
+
index?: number;
|
|
71
|
+
}>;
|
|
72
|
+
/** For withdrawals: amount and recipient */
|
|
73
|
+
withdrawal?: {
|
|
74
|
+
amount: string;
|
|
75
|
+
recipient: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/** Fields shared by transfer and withdraw records */
|
|
79
|
+
type PoolTransactionFields = {
|
|
42
80
|
poolAddress: string;
|
|
43
81
|
calldata: string;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
82
|
+
/** Individual transactions in the batch */
|
|
83
|
+
transactions: TransactJobTransaction[];
|
|
84
|
+
};
|
|
85
|
+
export type TransferRecord = JobRecordBase & PoolTransactionFields & {
|
|
86
|
+
kind: "transfer";
|
|
87
|
+
};
|
|
88
|
+
export type WithdrawRecord = JobRecordBase & PoolTransactionFields & {
|
|
89
|
+
kind: "withdraw";
|
|
47
90
|
};
|
|
48
|
-
|
|
91
|
+
/** Union of all pool transaction records (transfer or withdraw) */
|
|
92
|
+
export type PoolTransactionRecord = TransferRecord | WithdrawRecord;
|
|
93
|
+
/** Union of all job records */
|
|
94
|
+
export type JobRecord = DepositRecord | TransferRecord | WithdrawRecord;
|
|
49
95
|
export declare const DEFAULT_JOB_TIMEOUT_MS: number;
|
|
96
|
+
export {};
|
|
50
97
|
//# sourceMappingURL=jobs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../../../state/store/jobs.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,SAAS,GACT,WAAW,GACX,cAAc,GACd,WAAW,GACX,QAAQ,GACR,MAAM,CAAC;AAEX,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"jobs.d.ts","sourceRoot":"","sources":["../../../state/store/jobs.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"leaf-store.d.ts","sourceRoot":"","sources":["../../../state/store/leaf-store.ts"],"names":[],"mappings":"AACA,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;IAM9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;
|
|
1
|
+
{"version":3,"file":"leaf-store.d.ts","sourceRoot":"","sources":["../../../state/store/leaf-store.ts"],"names":[],"mappings":"AACA,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;IAM9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;IAI5C;;OAEG;yBACwB,MAAM;EAQpC"}
|
|
@@ -15,15 +15,12 @@ export function createLeafStore(storage) {
|
|
|
15
15
|
* Load a leaf commitment by tree index.
|
|
16
16
|
*/
|
|
17
17
|
async getLeaf(chainId, index) {
|
|
18
|
-
ensureChainId(chainId);
|
|
19
|
-
ensurePositiveInt("leaf index", index);
|
|
20
18
|
return getJson(storage, keys.leaf(chainId, index));
|
|
21
19
|
},
|
|
22
20
|
/**
|
|
23
21
|
* Remove all cached leaves for a chain.
|
|
24
22
|
*/
|
|
25
23
|
async clearLeaves(chainId) {
|
|
26
|
-
ensureChainId(chainId);
|
|
27
24
|
const prefix = `leaves:${chainId}:`;
|
|
28
25
|
const entries = await storage.iter({ prefix });
|
|
29
26
|
if (entries.length === 0)
|
|
@@ -4,7 +4,9 @@ export declare const emptyBytes: () => Uint8Array<ArrayBuffer>;
|
|
|
4
4
|
export declare function createNoteStore(storage: Storage): {
|
|
5
5
|
/**
|
|
6
6
|
* Upsert a note record and maintain the unspent-note index for fast balance queries.
|
|
7
|
-
* If the note already exists and is marked as spent, preserve the
|
|
7
|
+
* If the note already exists and is marked as spent, preserve spentAt unless the caller
|
|
8
|
+
* provides an explicit spentAt value (eg. upgrading from a local observation time to an
|
|
9
|
+
* on-chain timestamp from the indexer).
|
|
8
10
|
*/
|
|
9
11
|
putNote(note: NoteInsert): Promise<void>;
|
|
10
12
|
/**
|
|
@@ -21,18 +23,16 @@ export declare function createNoteStore(storage: Storage): {
|
|
|
21
23
|
includeSpent?: boolean;
|
|
22
24
|
}): Promise<NoteRecord[]>;
|
|
23
25
|
/**
|
|
24
|
-
* Mark a cached note as spent by setting its timestamp and
|
|
26
|
+
* Mark a cached note as spent by setting its timestamp and transaction hash.
|
|
25
27
|
*/
|
|
26
|
-
markNoteSpent(chainId: number, index: number, spentAt?: number): Promise<NoteRecord>;
|
|
28
|
+
markNoteSpent(chainId: number, index: number, spentAt?: number, spentTxHash?: string): Promise<NoteRecord>;
|
|
27
29
|
/**
|
|
28
30
|
* Drop the spent marker from a cached note, returning it to the unspent index.
|
|
29
31
|
*/
|
|
30
32
|
markNoteUnspent(chainId: number, index: number): Promise<NoteRecord>;
|
|
31
33
|
/**
|
|
32
|
-
*
|
|
34
|
+
* Remove all cached notes and their unspent indices for a chain.
|
|
33
35
|
*/
|
|
34
|
-
|
|
35
|
-
chainId?: number;
|
|
36
|
-
}): Promise<Record<string, bigint>>;
|
|
36
|
+
clearNotes(chainId: number): Promise<void>;
|
|
37
37
|
};
|
|
38
38
|
//# sourceMappingURL=note-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"note-store.d.ts","sourceRoot":"","sources":["../../../state/store/note-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"note-store.d.ts","sourceRoot":"","sources":["../../../state/store/note-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAW,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAevD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAElE,eAAO,MAAM,UAAU,+BAA0B,CAAC;AAElD,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO;IA2D5C;;;;;OAKG;kBACiB,UAAU;IAW9B;;OAEG;qBACoB,MAAM,SAAS,MAAM;IAI5C;;OAEG;wBAEQ;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB;IAkBH;;OAEG;2BAEQ,MAAM,SACR,MAAM,kCAEC,MAAM;IAiBtB;;OAEG;6BAC4B,MAAM,SAAS,MAAM;IAcpD;;OAEG;wBACuB,MAAM;EAmBnC"}
|
|
@@ -9,9 +9,23 @@ export function createNoteStore(storage) {
|
|
|
9
9
|
ensurePositiveInt("note index", record.index);
|
|
10
10
|
ensureMpk(record.mpk);
|
|
11
11
|
ensureBigIntString("note value", record.value);
|
|
12
|
+
if (record.createdAt !== undefined) {
|
|
13
|
+
ensurePositiveInt("note createdAt", record.createdAt);
|
|
14
|
+
}
|
|
12
15
|
if (record.spentAt !== undefined) {
|
|
13
16
|
ensurePositiveInt("note spentAt", record.spentAt);
|
|
14
17
|
}
|
|
18
|
+
if (record.createdTxHash !== undefined &&
|
|
19
|
+
record.createdTxHash.length === 0) {
|
|
20
|
+
throw new CoreError("note createdTxHash must be a non-empty string");
|
|
21
|
+
}
|
|
22
|
+
if (record.createdEventType !== undefined &&
|
|
23
|
+
record.createdEventType.length === 0) {
|
|
24
|
+
throw new CoreError("note createdEventType must be a non-empty string");
|
|
25
|
+
}
|
|
26
|
+
if (record.spentTxHash !== undefined && record.spentTxHash.length === 0) {
|
|
27
|
+
throw new CoreError("note spentTxHash must be a non-empty string");
|
|
28
|
+
}
|
|
15
29
|
const noteKey = keys.note(record.chainId, record.index);
|
|
16
30
|
const previous = await getJson(storage, noteKey);
|
|
17
31
|
const ops = [
|
|
@@ -41,13 +55,15 @@ export function createNoteStore(storage) {
|
|
|
41
55
|
const store = {
|
|
42
56
|
/**
|
|
43
57
|
* Upsert a note record and maintain the unspent-note index for fast balance queries.
|
|
44
|
-
* If the note already exists and is marked as spent, preserve the
|
|
58
|
+
* If the note already exists and is marked as spent, preserve spentAt unless the caller
|
|
59
|
+
* provides an explicit spentAt value (eg. upgrading from a local observation time to an
|
|
60
|
+
* on-chain timestamp from the indexer).
|
|
45
61
|
*/
|
|
46
62
|
async putNote(note) {
|
|
47
63
|
const noteKey = keys.note(note.chainId, note.index);
|
|
48
64
|
const existing = await getJson(storage, noteKey);
|
|
49
|
-
if (existing?.spentAt !== undefined) {
|
|
50
|
-
// Preserve spentAt if
|
|
65
|
+
if (existing?.spentAt !== undefined && note.spentAt === undefined) {
|
|
66
|
+
// Preserve spentAt if caller doesn't provide a value.
|
|
51
67
|
await persistNote({ ...note, spentAt: existing.spentAt });
|
|
52
68
|
}
|
|
53
69
|
else {
|
|
@@ -58,8 +74,6 @@ export function createNoteStore(storage) {
|
|
|
58
74
|
* Fetch a note by (chainId, index) if it exists in local storage.
|
|
59
75
|
*/
|
|
60
76
|
async getNote(chainId, index) {
|
|
61
|
-
ensureChainId(chainId);
|
|
62
|
-
ensurePositiveInt("note index", index);
|
|
63
77
|
return getJson(storage, keys.note(chainId, index));
|
|
64
78
|
},
|
|
65
79
|
/**
|
|
@@ -67,12 +81,6 @@ export function createNoteStore(storage) {
|
|
|
67
81
|
*/
|
|
68
82
|
async listNotes(options = {}) {
|
|
69
83
|
const { chainId, mpk, token, includeSpent = true } = options;
|
|
70
|
-
if (chainId !== undefined) {
|
|
71
|
-
ensureChainId(chainId);
|
|
72
|
-
}
|
|
73
|
-
if (mpk !== undefined) {
|
|
74
|
-
ensureMpk(mpk);
|
|
75
|
-
}
|
|
76
84
|
const prefix = chainId !== undefined ? `notes:${chainId}:` : "notes:";
|
|
77
85
|
const entries = await storage.iter({ prefix });
|
|
78
86
|
const filtered = entries
|
|
@@ -85,20 +93,18 @@ export function createNoteStore(storage) {
|
|
|
85
93
|
return filtered;
|
|
86
94
|
},
|
|
87
95
|
/**
|
|
88
|
-
* Mark a cached note as spent by setting its timestamp and
|
|
96
|
+
* Mark a cached note as spent by setting its timestamp and transaction hash.
|
|
89
97
|
*/
|
|
90
|
-
async markNoteSpent(chainId, index, spentAt = Date.now()) {
|
|
91
|
-
ensureChainId(chainId);
|
|
92
|
-
ensurePositiveInt("note index", index);
|
|
93
|
-
ensurePositiveInt("note spentAt", spentAt);
|
|
98
|
+
async markNoteSpent(chainId, index, spentAt = Date.now(), spentTxHash) {
|
|
94
99
|
const existing = await store.getNote(chainId, index);
|
|
95
100
|
if (!existing) {
|
|
96
101
|
throw new CoreError("note not found");
|
|
97
102
|
}
|
|
98
|
-
if (existing.spentAt === spentAt
|
|
103
|
+
if (existing.spentAt === spentAt &&
|
|
104
|
+
existing.spentTxHash === spentTxHash) {
|
|
99
105
|
return existing;
|
|
100
106
|
}
|
|
101
|
-
const updated = { ...existing, spentAt };
|
|
107
|
+
const updated = { ...existing, spentAt, spentTxHash };
|
|
102
108
|
await persistNote(updated);
|
|
103
109
|
return updated;
|
|
104
110
|
},
|
|
@@ -106,8 +112,6 @@ export function createNoteStore(storage) {
|
|
|
106
112
|
* Drop the spent marker from a cached note, returning it to the unspent index.
|
|
107
113
|
*/
|
|
108
114
|
async markNoteUnspent(chainId, index) {
|
|
109
|
-
ensureChainId(chainId);
|
|
110
|
-
ensurePositiveInt("note index", index);
|
|
111
115
|
const existing = await store.getNote(chainId, index);
|
|
112
116
|
if (!existing) {
|
|
113
117
|
throw new CoreError("note not found");
|
|
@@ -121,21 +125,21 @@ export function createNoteStore(storage) {
|
|
|
121
125
|
return updated;
|
|
122
126
|
},
|
|
123
127
|
/**
|
|
124
|
-
*
|
|
128
|
+
* Remove all cached notes and their unspent indices for a chain.
|
|
125
129
|
*/
|
|
126
|
-
async
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
130
|
+
async clearNotes(chainId) {
|
|
131
|
+
const notePrefix = `notes:${chainId}:`;
|
|
132
|
+
const noteEntries = await storage.iter({ prefix: notePrefix });
|
|
133
|
+
// Also clear unspent indices for this chain (all mpks)
|
|
134
|
+
const unspentPrefix = `idx:notes:unspent:${chainId}:`;
|
|
135
|
+
const unspentEntries = await storage.iter({ prefix: unspentPrefix });
|
|
136
|
+
if (noteEntries.length === 0 && unspentEntries.length === 0)
|
|
137
|
+
return;
|
|
138
|
+
const deletions = [
|
|
139
|
+
...noteEntries.map(({ key }) => ({ del: key })),
|
|
140
|
+
...unspentEntries.map(({ key }) => ({ del: key })),
|
|
141
|
+
];
|
|
142
|
+
await storage.batch(deletions);
|
|
139
143
|
},
|
|
140
144
|
};
|
|
141
145
|
return store;
|
|
@@ -13,5 +13,14 @@ export declare function createNullifierStore(storage: Storage): {
|
|
|
13
13
|
* Count all nullifiers stored locally for a given chain.
|
|
14
14
|
*/
|
|
15
15
|
countNullifiers(chainId: number): Promise<number>;
|
|
16
|
+
/**
|
|
17
|
+
* Remove all cached nullifiers for a chain.
|
|
18
|
+
*/
|
|
19
|
+
clearNullifiers(chainId: number): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Remove cached nullifiers whose noteIndex >= fromIndex.
|
|
22
|
+
* Used by partial resync to keep the count-based optimization accurate.
|
|
23
|
+
*/
|
|
24
|
+
clearNullifiersFromIndex(chainId: number, fromIndex: number): Promise<void>;
|
|
16
25
|
};
|
|
17
26
|
//# sourceMappingURL=nullifier-store.d.ts.map
|