@dynamic-labs-wallet/aleo 0.0.0 → 0.0.331

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,85 @@
1
+ /**
2
+ * IndexedDB-backed persistence for Aleo per-wallet record-scanner state.
3
+ *
4
+ * We cache the scanner's UUID, the owned-records list, and the spent-record
5
+ * nonces per accountAddress so subsequent queries resume from the last known
6
+ * state instead of re-registering with Provable's scanner on every page load.
7
+ *
8
+ * Storage shape (object store "state", keyed by `${accountAddress}:${network}`):
9
+ * { accountAddress, network, scannerUuid, records, spentNonces, lastScannedBlock,
10
+ * sealanceProofs, updatedAt }
11
+ *
12
+ * The keyPath value is the composite `${accountAddress}:${network}` so testnet
13
+ * and mainnet entries for the same wallet don't collide. Pre-network-aware
14
+ * entries (raw `accountAddress` keys) are functionally orphaned by the new
15
+ * composite lookups and will simply be re-registered on first call. Acceptable
16
+ * one-time cost; avoids a DB schema migration / version bump.
17
+ *
18
+ * `records` is a JSON-stringified array of `OwnedRecord` — keeping it as a
19
+ * string lets us cache decrypted plaintexts without imposing a Provable SDK
20
+ * type dependency on this persistence module.
21
+ *
22
+ * Security: blobs are stored plaintext, matching Dynamic's existing policy
23
+ * for locally-cached key material. Protection comes from the iframe's origin
24
+ * isolation, not at-rest encryption. Cloned from Midnight's
25
+ * walletStateStorage.ts; a future refactor may extract a generic kv store.
26
+ */
27
+ /** A cached Sealance Merkle exclusion proof for one stablecoin's freezelist.
28
+ * Recomputing the proof requires walking the freeze-list tree (16-deep
29
+ * Poseidon4 BHP256), so we cache by `root` and reuse until the freezelist
30
+ * changes on chain. */
31
+ export type SealanceProofCacheEntry = {
32
+ /** Last element of the BigInt-converted freeze-list tree, decimal string. */
33
+ root: string;
34
+ /** Output of `SealanceMerkleTree.formatMerkleProof([proofLeft, proofRight])`
35
+ * — ready to pass directly as a `[MerkleProof; 2u32].private` input. */
36
+ formattedProof: string;
37
+ computedAt: number;
38
+ };
39
+ export type AleoNetwork = 'mainnet' | 'testnet';
40
+ /** Composes the IndexedDB key from a wallet address + network. Exported so
41
+ * callers can build the same string when they need to look up a record
42
+ * outside the standard `getWalletState` path. */
43
+ export declare const buildStorageKey: (accountAddress: string, network: AleoNetwork) => string;
44
+ export type PersistedWalletState = {
45
+ /** Composite `${accountAddress}:${network}` — the IndexedDB keyPath value.
46
+ * We keep the field name `accountAddress` for keyPath compatibility with
47
+ * the existing object store; the actual wallet address lives in
48
+ * `walletAddress` below. */
49
+ accountAddress: string;
50
+ /** Real `aleo1...` address (sans network suffix). Useful for diagnostics. */
51
+ walletAddress?: string;
52
+ /** Network this entry's scanner UUID + records belong to. Pre-network-aware
53
+ * entries don't have this field; we treat absence as "stale, re-register". */
54
+ network?: AleoNetwork;
55
+ /** UUID returned by Provable's scanner /register flow. Required to query
56
+ * that wallet's records on subsequent calls. */
57
+ scannerUuid?: string;
58
+ /** JSON-stringified OwnedRecord[] — decrypted plaintexts cached between
59
+ * sessions. Stored as string to avoid a Provable type dep here. */
60
+ records: string;
61
+ /** Record nonces we've consumed as inputs in our own proveTransaction
62
+ * calls. Used to filter out spent records when the server-side spent-
63
+ * check isn't authoritative (e.g., between a broadcast and the scanner
64
+ * re-indexing the chain). */
65
+ spentNonces: string[];
66
+ /** Height through which `records` is known complete. Next scan picks up
67
+ * from `lastScannedBlock + 1`. */
68
+ lastScannedBlock: number;
69
+ /** Cached Sealance exclusion proofs keyed by freezelist program id
70
+ * (e.g. `test_usad_freezelist.aleo`). Re-validated against the current
71
+ * on-chain root before each spend; rebuilt only when the root changes. */
72
+ sealanceProofs?: Record<string, SealanceProofCacheEntry>;
73
+ updatedAt: number;
74
+ };
75
+ export declare function toError(err: unknown, fallbackMessage: string): Error;
76
+ export declare function getWalletState(accountAddress: string, network: AleoNetwork): Promise<PersistedWalletState | null>;
77
+ export declare function putWalletState(accountAddress: string, network: AleoNetwork, state: {
78
+ scannerUuid?: string;
79
+ records: string;
80
+ spentNonces: string[];
81
+ lastScannedBlock: number;
82
+ sealanceProofs?: Record<string, SealanceProofCacheEntry>;
83
+ }): Promise<void>;
84
+ export declare function deleteWalletState(accountAddress: string, network: AleoNetwork): Promise<void>;
85
+ //# sourceMappingURL=walletStateStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"walletStateStorage.d.ts","sourceRoot":"","sources":["../../src/client/walletStateStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAMH;;;wBAGwB;AACxB,MAAM,MAAM,uBAAuB,GAAG;IACpC,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb;6EACyE;IACzE,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AAEhD;;kDAEkD;AAClD,eAAO,MAAM,eAAe,mBAAoB,MAAM,WAAW,WAAW,KAAG,MAAwC,CAAC;AAExH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;iCAG6B;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;mFAC+E;IAC/E,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB;qDACiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;wEACoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB;;;kCAG8B;IAC9B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB;uCACmC;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB;;+EAE2E;IAC3E,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;IACzD,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,KAAK,CAcpE;AAqCD,wBAAsB,cAAc,CAClC,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,WAAW,GACnB,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAStC;AAED,wBAAsB,cAAc,CAClC,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE;IACL,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CAC1D,GACA,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED,wBAAsB,iBAAiB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAOnG"}
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './client/index.js';
2
+ export { ALEO_NETWORKS, type AleoNetwork } from './client/constants.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../packages/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC"}