@ocash/sdk 0.1.0 → 0.1.1

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/node.d.cts CHANGED
@@ -1,11 +1,15 @@
1
- import { S as StorageAdapter, a as MerkleTreeState, M as MerkleNodeRecord, E as EntryMemoRecord, L as ListEntryMemosQuery, b as EntryNullifierRecord, c as ListEntryNullifiersQuery, d as SyncCursor, U as UtxoRecord, e as ListUtxosQuery, H as Hex, O as OperationType, f as StoredOperation, g as OperationDetailFor, h as ListOperationsQuery } from './index-DgLBElAG.cjs';
2
- export { A as App_ABI, i as AssetOverrideEntry, j as AssetsOverride, B as BABYJUBJUB_SCALAR_FIELD, C as ChainConfigInput, k as CommitmentData, l as CryptoToolkit, D as DepositOperation, m as DepositOperationDetail, n as DummyFactory, o as ERC20_ABI, K as KeyManager, p as KeyValueClient, q as KeyValueStore, r as KeyValueStoreOptions, s as LedgerInfo, t as MemoKit, u as MemoryStore, v as MerkleLeafRecord, w as OCashSdk, x as OCashSdkConfig, y as OperationCreateInput, z as OperationStatus, F as OpsApi, P as PlannerEstimateTransferResult, G as PlannerEstimateWithdrawResult, I as ProofResult, R as RedisStore, J as RedisStoreOptions, N as RelayerRequest, Q as SdkEvent, T as SqliteStore, V as SqliteStoreOptions, W as SyncChainStatus, X as TokenMetadata, Y as TransactionReceipt, Z as TransferOperation, _ as TransferOperationDetail, $ as TransferWitnessInput, a0 as Utils, a1 as WalletSessionInput, a2 as WithdrawOperation, a3 as WithdrawOperationDetail, a4 as WithdrawWitnessInput, a5 as WitnessBuildResult, a6 as WitnessContext, a7 as assertChainConfigInput, a8 as assertTokenList, a9 as assertTokenMetadata, aa as calcTransferProofBinding, ab as calcWithdrawProofBinding, ac as createSdk, ad as default, ae as defaultAssetsOverride, af as fetchPoolTokensFromContract, ag as normalizeTokenMetadata } from './index-DgLBElAG.cjs';
1
+ import { S as StorageAdapter, a as MerkleTreeState, M as MerkleNodeRecord, E as EntryMemoRecord, L as ListEntryMemosQuery, b as EntryNullifierRecord, c as ListEntryNullifiersQuery, d as SyncCursor, U as UtxoRecord, e as ListUtxosQuery, H as Hex, O as OperationType, f as StoredOperation, g as OperationDetailFor, h as OperationStatus, i as ListOperationsQuery, J as MerkleLeafRecord } from './index-CI7UllxU.cjs';
2
+ export { A as App_ABI, j as AssetOverrideEntry, k as AssetsOverride, B as BABYJUBJUB_SCALAR_FIELD, l as BASE_DEV, m as BASE_MAINNET, n as BSC_DEV, o as BSC_MAINNET, p as BSC_TESTNET, q as BSC_TESTNET_DEV, C as ChainConfigInput, r as CommitmentData, s as CryptoToolkit, D as DepositOperation, t as DepositOperationDetail, u as DummyFactory, v as ETH_DEV, w as ETH_MAINNET, K as KeyManager, x as KeyValueClient, y as KeyValueStore, z as KeyValueStoreOptions, F as LedgerInfo, G as MemoKit, I as MemoryStore, N as OCashSdk, P as OCashSdkConfig, Q as OperationCreateInput, R as OpsApi, T as PlannerEstimateTransferResult, V as PlannerEstimateWithdrawResult, W as ProofResult, X as RedisStore, Y as RedisStoreOptions, Z as RelayerRequest, _ as SEPOLIA_DEV, $ as SEPOLIA_TESTNET, a0 as SdkEvent, a1 as SyncChainStatus, a2 as TokenMetadata, a3 as TransactionReceipt, a4 as TransferOperation, a5 as TransferOperationDetail, a6 as TransferWitnessInput, a7 as Utils, a8 as WalletSessionInput, a9 as WithdrawOperation, aa as WithdrawOperationDetail, ab as WithdrawWitnessInput, ac as WitnessBuildResult, ad as WitnessContext, ae as assertChainConfigInput, af as assertTokenList, ag as assertTokenMetadata, ah as calcTransferProofBinding, ai as calcWithdrawProofBinding, aj as createSdk, ak as default, al as defaultAssetsOverrideMainnet, am as defaultAssetsOverrideTestnet, an as fetchPoolTokensFromContract, ao as normalizeTokenMetadata } from './index-CI7UllxU.cjs';
3
3
  import 'viem';
4
4
 
5
5
  type FileStoreOptions = {
6
6
  baseDir: string;
7
7
  maxOperations?: number;
8
8
  };
9
+ /**
10
+ * JSON-file backed StorageAdapter for Node environments.
11
+ * Persists wallet state and shared merkle/entry cache to disk.
12
+ */
9
13
  declare class FileStore implements StorageAdapter {
10
14
  private readonly options;
11
15
  private walletId;
@@ -19,59 +23,283 @@ declare class FileStore implements StorageAdapter {
19
23
  private saveChain;
20
24
  private readonly maxOperations;
21
25
  private readonly merkleNextCid;
26
+ /**
27
+ * Create a FileStore with a base directory and optional limits.
28
+ */
22
29
  constructor(options: FileStoreOptions);
30
+ private samePlainRecord;
31
+ /**
32
+ * Initialize store for a wallet id and load from disk.
33
+ */
23
34
  init(options?: {
24
35
  walletId?: string;
25
36
  }): Promise<void>;
37
+ /**
38
+ * Flush pending state to disk.
39
+ */
26
40
  close(): Promise<void>;
41
+ /**
42
+ * Compute the primary JSON state file path for the current wallet id.
43
+ */
27
44
  private filePath;
45
+ /**
46
+ * Compute the shared JSON state file path for chain-level caches.
47
+ */
48
+ private sharedFilePath;
49
+ /**
50
+ * Compute the shared merkle leaves jsonl file path for a chain.
51
+ */
28
52
  private merkleFilePath;
53
+ private readMerkleFile;
54
+ /**
55
+ * Infer the next merkle cid from the tail of the jsonl file.
56
+ */
29
57
  private getMerkleNextCid;
58
+ /**
59
+ * Load persisted state from disk into memory.
60
+ */
30
61
  private load;
31
- private save;
62
+ /**
63
+ * Persist wallet-scoped state to disk using a temp file swap.
64
+ */
65
+ private saveWallet;
66
+ /**
67
+ * Persist shared chain-scoped state to disk using a temp file swap.
68
+ */
69
+ private saveShared;
70
+ /**
71
+ * Get persisted merkle tree metadata for a chain.
72
+ */
32
73
  getMerkleTree(chainId: number): Promise<MerkleTreeState | undefined>;
74
+ /**
75
+ * Persist merkle tree metadata for a chain.
76
+ */
33
77
  setMerkleTree(chainId: number, tree: MerkleTreeState): Promise<void>;
78
+ /**
79
+ * Clear merkle tree metadata for a chain.
80
+ */
34
81
  clearMerkleTree(chainId: number): Promise<void>;
82
+ /**
83
+ * Get a merkle node by id.
84
+ */
35
85
  getMerkleNode(chainId: number, id: string): Promise<MerkleNodeRecord | undefined>;
86
+ /**
87
+ * Upsert merkle nodes for a chain and persist.
88
+ */
36
89
  upsertMerkleNodes(chainId: number, nodes: MerkleNodeRecord[]): Promise<void>;
90
+ /**
91
+ * Clear merkle nodes for a chain.
92
+ */
37
93
  clearMerkleNodes(chainId: number): Promise<void>;
38
- upsertEntryMemos(memos: EntryMemoRecord[]): Promise<number>;
94
+ /**
95
+ * Upsert entry memos (raw EntryService cache) and persist.
96
+ */
97
+ upsertEntryMemos(memos: EntryMemoRecord[]): Promise<void>;
98
+ /**
99
+ * List entry memos with query filtering and pagination.
100
+ */
39
101
  listEntryMemos(query: ListEntryMemosQuery): Promise<{
40
102
  total: number;
41
103
  rows: EntryMemoRecord[];
42
104
  }>;
105
+ /**
106
+ * Clear entry memo cache for a chain.
107
+ */
43
108
  clearEntryMemos(chainId: number): Promise<void>;
44
- upsertEntryNullifiers(nullifiers: EntryNullifierRecord[]): Promise<number>;
109
+ /**
110
+ * Upsert entry nullifiers (raw EntryService cache) and persist.
111
+ */
112
+ upsertEntryNullifiers(nullifiers: EntryNullifierRecord[]): Promise<void>;
113
+ /**
114
+ * List entry nullifiers with query filtering and pagination.
115
+ */
45
116
  listEntryNullifiers(query: ListEntryNullifiersQuery): Promise<{
46
117
  total: number;
47
118
  rows: EntryNullifierRecord[];
48
119
  }>;
120
+ /**
121
+ * Clear entry nullifier cache for a chain.
122
+ */
49
123
  clearEntryNullifiers(chainId: number): Promise<void>;
124
+ /**
125
+ * Get persisted sync cursor for a chain.
126
+ */
50
127
  getSyncCursor(chainId: number): Promise<SyncCursor | undefined>;
128
+ /**
129
+ * Set persisted sync cursor for a chain.
130
+ */
51
131
  setSyncCursor(chainId: number, cursor: SyncCursor): Promise<void>;
132
+ /**
133
+ * Upsert UTXOs and persist.
134
+ */
52
135
  upsertUtxos(utxos: UtxoRecord[]): Promise<void>;
136
+ /**
137
+ * List UTXOs with query filtering and pagination.
138
+ */
53
139
  listUtxos(query?: ListUtxosQuery): Promise<{
54
140
  total: number;
55
141
  rows: UtxoRecord[];
56
142
  }>;
143
+ /**
144
+ * Mark UTXOs as spent by nullifier and persist.
145
+ */
57
146
  markSpent(input: {
58
147
  chainId: number;
59
148
  nullifiers: Hex[];
60
149
  }): Promise<number>;
150
+ /**
151
+ * Load merkle leaves from jsonl file.
152
+ */
61
153
  getMerkleLeaves(chainId: number): Promise<Array<{
62
154
  cid: number;
63
155
  commitment: Hex;
64
156
  }> | undefined>;
157
+ /**
158
+ * Get a merkle leaf by cid (loads full list then indexes).
159
+ */
65
160
  getMerkleLeaf(chainId: number, cid: number): Promise<{
66
161
  chainId: number;
67
162
  cid: number;
68
163
  commitment: `0x${string}`;
69
164
  } | undefined>;
165
+ /**
166
+ * Append contiguous merkle leaves to jsonl file.
167
+ */
70
168
  appendMerkleLeaves(chainId: number, leaves: Array<{
71
169
  cid: number;
72
170
  commitment: Hex;
73
171
  }>): Promise<void>;
172
+ /**
173
+ * Delete merkle leaves jsonl file for a chain.
174
+ */
74
175
  clearMerkleLeaves(chainId: number): Promise<void>;
176
+ /**
177
+ * Create and persist an operation record.
178
+ */
179
+ createOperation<TType extends OperationType>(input: Omit<StoredOperation<OperationDetailFor<TType>>, 'id' | 'createdAt' | 'status'> & Partial<Pick<StoredOperation<OperationDetailFor<TType>>, 'createdAt' | 'id' | 'status'>> & {
180
+ type: TType;
181
+ }): {
182
+ id: string;
183
+ createdAt: number;
184
+ status: OperationStatus;
185
+ type: OperationType & TType;
186
+ chainId?: number | undefined;
187
+ tokenId?: string | undefined;
188
+ requestUrl?: string | undefined;
189
+ relayerTxHash?: `0x${string}` | undefined;
190
+ txHash?: `0x${string}` | undefined;
191
+ detail?: OperationDetailFor<TType> | undefined;
192
+ error?: string | undefined;
193
+ };
194
+ /**
195
+ * Update an operation record and persist.
196
+ */
197
+ updateOperation(id: string, patch: Partial<StoredOperation>): void;
198
+ /**
199
+ * Delete an operation record and persist.
200
+ */
201
+ deleteOperation(id: string): boolean;
202
+ /**
203
+ * Clear all operations and persist.
204
+ */
205
+ clearOperations(): void;
206
+ /**
207
+ * Prune operations to a maximum count and persist.
208
+ */
209
+ pruneOperations(options?: {
210
+ max?: number;
211
+ }): number;
212
+ /**
213
+ * List operations with filtering/pagination.
214
+ */
215
+ listOperations(input?: number | ListOperationsQuery): StoredOperation[];
216
+ }
217
+
218
+ type SqliteBindValue = string | number | bigint | Uint8Array | null;
219
+ interface SqliteStatement {
220
+ run(...params: SqliteBindValue[]): unknown;
221
+ get(...params: SqliteBindValue[]): unknown;
222
+ all(...params: SqliteBindValue[]): unknown[];
223
+ }
224
+ interface SqliteDatabase {
225
+ exec(sql: string): void;
226
+ prepare(sql: string): SqliteStatement;
227
+ close?: () => void;
228
+ pragma?: (pragma: string) => unknown;
229
+ }
230
+ type SqliteStoreOptions = {
231
+ filename: string;
232
+ walletId?: string;
233
+ maxOperations?: number;
234
+ readonly?: boolean;
235
+ createIfMissing?: boolean;
236
+ busyTimeoutMs?: number;
237
+ pragmas?: string[];
238
+ database?: SqliteDatabase;
239
+ };
240
+ declare class SqliteStore implements StorageAdapter {
241
+ private readonly options;
242
+ private walletId;
243
+ private readonly maxOperations;
244
+ private db;
245
+ constructor(options: SqliteStoreOptions);
246
+ init(options?: {
247
+ walletId?: string;
248
+ }): Promise<void>;
249
+ close(): Promise<void>;
250
+ private walletKey;
251
+ private ensureDb;
252
+ private openDatabase;
253
+ private tryOpenWithNodeSqlite;
254
+ private tryOpenWithBetterSqlite;
255
+ private applyPragmas;
256
+ private initSchema;
257
+ private row;
258
+ private rows;
259
+ private run;
260
+ private inClause;
261
+ getSyncCursor(chainId: number): Promise<SyncCursor | undefined>;
262
+ setSyncCursor(chainId: number, cursor: SyncCursor): Promise<void>;
263
+ upsertUtxos(utxos: UtxoRecord[]): Promise<void>;
264
+ listUtxos(query?: ListUtxosQuery): Promise<{
265
+ total: number;
266
+ rows: UtxoRecord[];
267
+ }>;
268
+ markSpent(input: {
269
+ chainId: number;
270
+ nullifiers: Hex[];
271
+ }): Promise<number>;
272
+ getMerkleLeaves(chainId: number): Promise<Array<{
273
+ cid: number;
274
+ commitment: Hex;
275
+ }> | undefined>;
276
+ getMerkleLeaf(chainId: number, cid: number): Promise<MerkleLeafRecord | undefined>;
277
+ appendMerkleLeaves(chainId: number, leaves: Array<{
278
+ cid: number;
279
+ commitment: Hex;
280
+ }>): Promise<void>;
281
+ clearMerkleLeaves(chainId: number): Promise<void>;
282
+ getMerkleNode(chainId: number, id: string): Promise<MerkleNodeRecord | undefined>;
283
+ upsertMerkleNodes(chainId: number, nodes: MerkleNodeRecord[]): Promise<void>;
284
+ clearMerkleNodes(chainId: number): Promise<void>;
285
+ getMerkleTree(chainId: number): Promise<MerkleTreeState | undefined>;
286
+ setMerkleTree(chainId: number, tree: MerkleTreeState): Promise<void>;
287
+ clearMerkleTree(chainId: number): Promise<void>;
288
+ upsertEntryMemos(memos: EntryMemoRecord[]): Promise<void>;
289
+ listEntryMemos(query: ListEntryMemosQuery): Promise<{
290
+ total: number;
291
+ rows: EntryMemoRecord[];
292
+ }>;
293
+ clearEntryMemos(chainId: number): Promise<void>;
294
+ upsertEntryNullifiers(nullifiers: EntryNullifierRecord[]): Promise<void>;
295
+ listEntryNullifiers(query: ListEntryNullifiersQuery): Promise<{
296
+ total: number;
297
+ rows: EntryNullifierRecord[];
298
+ }>;
299
+ clearEntryNullifiers(chainId: number): Promise<void>;
300
+ private getOperationById;
301
+ private operationFromRow;
302
+ private upsertOperationRow;
75
303
  createOperation<TType extends OperationType>(input: Omit<StoredOperation<OperationDetailFor<TType>>, 'id' | 'createdAt' | 'status'> & Partial<Pick<StoredOperation<OperationDetailFor<TType>>, 'createdAt' | 'id' | 'status'>> & {
76
304
  type: TType;
77
305
  }): StoredOperation<OperationDetailFor<TType>> & {
@@ -86,4 +314,4 @@ declare class FileStore implements StorageAdapter {
86
314
  listOperations(input?: number | ListOperationsQuery): StoredOperation[];
87
315
  }
88
316
 
89
- export { EntryMemoRecord, EntryNullifierRecord, FileStore, type FileStoreOptions, Hex, ListEntryMemosQuery, ListEntryNullifiersQuery, ListOperationsQuery, ListUtxosQuery, MerkleNodeRecord, MerkleTreeState, OperationType, StorageAdapter, StoredOperation, SyncCursor, UtxoRecord };
317
+ export { EntryMemoRecord, EntryNullifierRecord, FileStore, type FileStoreOptions, Hex, ListEntryMemosQuery, ListEntryNullifiersQuery, ListOperationsQuery, ListUtxosQuery, MerkleLeafRecord, MerkleNodeRecord, MerkleTreeState, OperationStatus, OperationType, SqliteStore, type SqliteStoreOptions, StorageAdapter, StoredOperation, SyncCursor, UtxoRecord };
package/dist/node.d.ts CHANGED
@@ -1,11 +1,15 @@
1
- import { S as StorageAdapter, a as MerkleTreeState, M as MerkleNodeRecord, E as EntryMemoRecord, L as ListEntryMemosQuery, b as EntryNullifierRecord, c as ListEntryNullifiersQuery, d as SyncCursor, U as UtxoRecord, e as ListUtxosQuery, H as Hex, O as OperationType, f as StoredOperation, g as OperationDetailFor, h as ListOperationsQuery } from './index-DgLBElAG.js';
2
- export { A as App_ABI, i as AssetOverrideEntry, j as AssetsOverride, B as BABYJUBJUB_SCALAR_FIELD, C as ChainConfigInput, k as CommitmentData, l as CryptoToolkit, D as DepositOperation, m as DepositOperationDetail, n as DummyFactory, o as ERC20_ABI, K as KeyManager, p as KeyValueClient, q as KeyValueStore, r as KeyValueStoreOptions, s as LedgerInfo, t as MemoKit, u as MemoryStore, v as MerkleLeafRecord, w as OCashSdk, x as OCashSdkConfig, y as OperationCreateInput, z as OperationStatus, F as OpsApi, P as PlannerEstimateTransferResult, G as PlannerEstimateWithdrawResult, I as ProofResult, R as RedisStore, J as RedisStoreOptions, N as RelayerRequest, Q as SdkEvent, T as SqliteStore, V as SqliteStoreOptions, W as SyncChainStatus, X as TokenMetadata, Y as TransactionReceipt, Z as TransferOperation, _ as TransferOperationDetail, $ as TransferWitnessInput, a0 as Utils, a1 as WalletSessionInput, a2 as WithdrawOperation, a3 as WithdrawOperationDetail, a4 as WithdrawWitnessInput, a5 as WitnessBuildResult, a6 as WitnessContext, a7 as assertChainConfigInput, a8 as assertTokenList, a9 as assertTokenMetadata, aa as calcTransferProofBinding, ab as calcWithdrawProofBinding, ac as createSdk, ad as default, ae as defaultAssetsOverride, af as fetchPoolTokensFromContract, ag as normalizeTokenMetadata } from './index-DgLBElAG.js';
1
+ import { S as StorageAdapter, a as MerkleTreeState, M as MerkleNodeRecord, E as EntryMemoRecord, L as ListEntryMemosQuery, b as EntryNullifierRecord, c as ListEntryNullifiersQuery, d as SyncCursor, U as UtxoRecord, e as ListUtxosQuery, H as Hex, O as OperationType, f as StoredOperation, g as OperationDetailFor, h as OperationStatus, i as ListOperationsQuery, J as MerkleLeafRecord } from './index-CI7UllxU.js';
2
+ export { A as App_ABI, j as AssetOverrideEntry, k as AssetsOverride, B as BABYJUBJUB_SCALAR_FIELD, l as BASE_DEV, m as BASE_MAINNET, n as BSC_DEV, o as BSC_MAINNET, p as BSC_TESTNET, q as BSC_TESTNET_DEV, C as ChainConfigInput, r as CommitmentData, s as CryptoToolkit, D as DepositOperation, t as DepositOperationDetail, u as DummyFactory, v as ETH_DEV, w as ETH_MAINNET, K as KeyManager, x as KeyValueClient, y as KeyValueStore, z as KeyValueStoreOptions, F as LedgerInfo, G as MemoKit, I as MemoryStore, N as OCashSdk, P as OCashSdkConfig, Q as OperationCreateInput, R as OpsApi, T as PlannerEstimateTransferResult, V as PlannerEstimateWithdrawResult, W as ProofResult, X as RedisStore, Y as RedisStoreOptions, Z as RelayerRequest, _ as SEPOLIA_DEV, $ as SEPOLIA_TESTNET, a0 as SdkEvent, a1 as SyncChainStatus, a2 as TokenMetadata, a3 as TransactionReceipt, a4 as TransferOperation, a5 as TransferOperationDetail, a6 as TransferWitnessInput, a7 as Utils, a8 as WalletSessionInput, a9 as WithdrawOperation, aa as WithdrawOperationDetail, ab as WithdrawWitnessInput, ac as WitnessBuildResult, ad as WitnessContext, ae as assertChainConfigInput, af as assertTokenList, ag as assertTokenMetadata, ah as calcTransferProofBinding, ai as calcWithdrawProofBinding, aj as createSdk, ak as default, al as defaultAssetsOverrideMainnet, am as defaultAssetsOverrideTestnet, an as fetchPoolTokensFromContract, ao as normalizeTokenMetadata } from './index-CI7UllxU.js';
3
3
  import 'viem';
4
4
 
5
5
  type FileStoreOptions = {
6
6
  baseDir: string;
7
7
  maxOperations?: number;
8
8
  };
9
+ /**
10
+ * JSON-file backed StorageAdapter for Node environments.
11
+ * Persists wallet state and shared merkle/entry cache to disk.
12
+ */
9
13
  declare class FileStore implements StorageAdapter {
10
14
  private readonly options;
11
15
  private walletId;
@@ -19,59 +23,283 @@ declare class FileStore implements StorageAdapter {
19
23
  private saveChain;
20
24
  private readonly maxOperations;
21
25
  private readonly merkleNextCid;
26
+ /**
27
+ * Create a FileStore with a base directory and optional limits.
28
+ */
22
29
  constructor(options: FileStoreOptions);
30
+ private samePlainRecord;
31
+ /**
32
+ * Initialize store for a wallet id and load from disk.
33
+ */
23
34
  init(options?: {
24
35
  walletId?: string;
25
36
  }): Promise<void>;
37
+ /**
38
+ * Flush pending state to disk.
39
+ */
26
40
  close(): Promise<void>;
41
+ /**
42
+ * Compute the primary JSON state file path for the current wallet id.
43
+ */
27
44
  private filePath;
45
+ /**
46
+ * Compute the shared JSON state file path for chain-level caches.
47
+ */
48
+ private sharedFilePath;
49
+ /**
50
+ * Compute the shared merkle leaves jsonl file path for a chain.
51
+ */
28
52
  private merkleFilePath;
53
+ private readMerkleFile;
54
+ /**
55
+ * Infer the next merkle cid from the tail of the jsonl file.
56
+ */
29
57
  private getMerkleNextCid;
58
+ /**
59
+ * Load persisted state from disk into memory.
60
+ */
30
61
  private load;
31
- private save;
62
+ /**
63
+ * Persist wallet-scoped state to disk using a temp file swap.
64
+ */
65
+ private saveWallet;
66
+ /**
67
+ * Persist shared chain-scoped state to disk using a temp file swap.
68
+ */
69
+ private saveShared;
70
+ /**
71
+ * Get persisted merkle tree metadata for a chain.
72
+ */
32
73
  getMerkleTree(chainId: number): Promise<MerkleTreeState | undefined>;
74
+ /**
75
+ * Persist merkle tree metadata for a chain.
76
+ */
33
77
  setMerkleTree(chainId: number, tree: MerkleTreeState): Promise<void>;
78
+ /**
79
+ * Clear merkle tree metadata for a chain.
80
+ */
34
81
  clearMerkleTree(chainId: number): Promise<void>;
82
+ /**
83
+ * Get a merkle node by id.
84
+ */
35
85
  getMerkleNode(chainId: number, id: string): Promise<MerkleNodeRecord | undefined>;
86
+ /**
87
+ * Upsert merkle nodes for a chain and persist.
88
+ */
36
89
  upsertMerkleNodes(chainId: number, nodes: MerkleNodeRecord[]): Promise<void>;
90
+ /**
91
+ * Clear merkle nodes for a chain.
92
+ */
37
93
  clearMerkleNodes(chainId: number): Promise<void>;
38
- upsertEntryMemos(memos: EntryMemoRecord[]): Promise<number>;
94
+ /**
95
+ * Upsert entry memos (raw EntryService cache) and persist.
96
+ */
97
+ upsertEntryMemos(memos: EntryMemoRecord[]): Promise<void>;
98
+ /**
99
+ * List entry memos with query filtering and pagination.
100
+ */
39
101
  listEntryMemos(query: ListEntryMemosQuery): Promise<{
40
102
  total: number;
41
103
  rows: EntryMemoRecord[];
42
104
  }>;
105
+ /**
106
+ * Clear entry memo cache for a chain.
107
+ */
43
108
  clearEntryMemos(chainId: number): Promise<void>;
44
- upsertEntryNullifiers(nullifiers: EntryNullifierRecord[]): Promise<number>;
109
+ /**
110
+ * Upsert entry nullifiers (raw EntryService cache) and persist.
111
+ */
112
+ upsertEntryNullifiers(nullifiers: EntryNullifierRecord[]): Promise<void>;
113
+ /**
114
+ * List entry nullifiers with query filtering and pagination.
115
+ */
45
116
  listEntryNullifiers(query: ListEntryNullifiersQuery): Promise<{
46
117
  total: number;
47
118
  rows: EntryNullifierRecord[];
48
119
  }>;
120
+ /**
121
+ * Clear entry nullifier cache for a chain.
122
+ */
49
123
  clearEntryNullifiers(chainId: number): Promise<void>;
124
+ /**
125
+ * Get persisted sync cursor for a chain.
126
+ */
50
127
  getSyncCursor(chainId: number): Promise<SyncCursor | undefined>;
128
+ /**
129
+ * Set persisted sync cursor for a chain.
130
+ */
51
131
  setSyncCursor(chainId: number, cursor: SyncCursor): Promise<void>;
132
+ /**
133
+ * Upsert UTXOs and persist.
134
+ */
52
135
  upsertUtxos(utxos: UtxoRecord[]): Promise<void>;
136
+ /**
137
+ * List UTXOs with query filtering and pagination.
138
+ */
53
139
  listUtxos(query?: ListUtxosQuery): Promise<{
54
140
  total: number;
55
141
  rows: UtxoRecord[];
56
142
  }>;
143
+ /**
144
+ * Mark UTXOs as spent by nullifier and persist.
145
+ */
57
146
  markSpent(input: {
58
147
  chainId: number;
59
148
  nullifiers: Hex[];
60
149
  }): Promise<number>;
150
+ /**
151
+ * Load merkle leaves from jsonl file.
152
+ */
61
153
  getMerkleLeaves(chainId: number): Promise<Array<{
62
154
  cid: number;
63
155
  commitment: Hex;
64
156
  }> | undefined>;
157
+ /**
158
+ * Get a merkle leaf by cid (loads full list then indexes).
159
+ */
65
160
  getMerkleLeaf(chainId: number, cid: number): Promise<{
66
161
  chainId: number;
67
162
  cid: number;
68
163
  commitment: `0x${string}`;
69
164
  } | undefined>;
165
+ /**
166
+ * Append contiguous merkle leaves to jsonl file.
167
+ */
70
168
  appendMerkleLeaves(chainId: number, leaves: Array<{
71
169
  cid: number;
72
170
  commitment: Hex;
73
171
  }>): Promise<void>;
172
+ /**
173
+ * Delete merkle leaves jsonl file for a chain.
174
+ */
74
175
  clearMerkleLeaves(chainId: number): Promise<void>;
176
+ /**
177
+ * Create and persist an operation record.
178
+ */
179
+ createOperation<TType extends OperationType>(input: Omit<StoredOperation<OperationDetailFor<TType>>, 'id' | 'createdAt' | 'status'> & Partial<Pick<StoredOperation<OperationDetailFor<TType>>, 'createdAt' | 'id' | 'status'>> & {
180
+ type: TType;
181
+ }): {
182
+ id: string;
183
+ createdAt: number;
184
+ status: OperationStatus;
185
+ type: OperationType & TType;
186
+ chainId?: number | undefined;
187
+ tokenId?: string | undefined;
188
+ requestUrl?: string | undefined;
189
+ relayerTxHash?: `0x${string}` | undefined;
190
+ txHash?: `0x${string}` | undefined;
191
+ detail?: OperationDetailFor<TType> | undefined;
192
+ error?: string | undefined;
193
+ };
194
+ /**
195
+ * Update an operation record and persist.
196
+ */
197
+ updateOperation(id: string, patch: Partial<StoredOperation>): void;
198
+ /**
199
+ * Delete an operation record and persist.
200
+ */
201
+ deleteOperation(id: string): boolean;
202
+ /**
203
+ * Clear all operations and persist.
204
+ */
205
+ clearOperations(): void;
206
+ /**
207
+ * Prune operations to a maximum count and persist.
208
+ */
209
+ pruneOperations(options?: {
210
+ max?: number;
211
+ }): number;
212
+ /**
213
+ * List operations with filtering/pagination.
214
+ */
215
+ listOperations(input?: number | ListOperationsQuery): StoredOperation[];
216
+ }
217
+
218
+ type SqliteBindValue = string | number | bigint | Uint8Array | null;
219
+ interface SqliteStatement {
220
+ run(...params: SqliteBindValue[]): unknown;
221
+ get(...params: SqliteBindValue[]): unknown;
222
+ all(...params: SqliteBindValue[]): unknown[];
223
+ }
224
+ interface SqliteDatabase {
225
+ exec(sql: string): void;
226
+ prepare(sql: string): SqliteStatement;
227
+ close?: () => void;
228
+ pragma?: (pragma: string) => unknown;
229
+ }
230
+ type SqliteStoreOptions = {
231
+ filename: string;
232
+ walletId?: string;
233
+ maxOperations?: number;
234
+ readonly?: boolean;
235
+ createIfMissing?: boolean;
236
+ busyTimeoutMs?: number;
237
+ pragmas?: string[];
238
+ database?: SqliteDatabase;
239
+ };
240
+ declare class SqliteStore implements StorageAdapter {
241
+ private readonly options;
242
+ private walletId;
243
+ private readonly maxOperations;
244
+ private db;
245
+ constructor(options: SqliteStoreOptions);
246
+ init(options?: {
247
+ walletId?: string;
248
+ }): Promise<void>;
249
+ close(): Promise<void>;
250
+ private walletKey;
251
+ private ensureDb;
252
+ private openDatabase;
253
+ private tryOpenWithNodeSqlite;
254
+ private tryOpenWithBetterSqlite;
255
+ private applyPragmas;
256
+ private initSchema;
257
+ private row;
258
+ private rows;
259
+ private run;
260
+ private inClause;
261
+ getSyncCursor(chainId: number): Promise<SyncCursor | undefined>;
262
+ setSyncCursor(chainId: number, cursor: SyncCursor): Promise<void>;
263
+ upsertUtxos(utxos: UtxoRecord[]): Promise<void>;
264
+ listUtxos(query?: ListUtxosQuery): Promise<{
265
+ total: number;
266
+ rows: UtxoRecord[];
267
+ }>;
268
+ markSpent(input: {
269
+ chainId: number;
270
+ nullifiers: Hex[];
271
+ }): Promise<number>;
272
+ getMerkleLeaves(chainId: number): Promise<Array<{
273
+ cid: number;
274
+ commitment: Hex;
275
+ }> | undefined>;
276
+ getMerkleLeaf(chainId: number, cid: number): Promise<MerkleLeafRecord | undefined>;
277
+ appendMerkleLeaves(chainId: number, leaves: Array<{
278
+ cid: number;
279
+ commitment: Hex;
280
+ }>): Promise<void>;
281
+ clearMerkleLeaves(chainId: number): Promise<void>;
282
+ getMerkleNode(chainId: number, id: string): Promise<MerkleNodeRecord | undefined>;
283
+ upsertMerkleNodes(chainId: number, nodes: MerkleNodeRecord[]): Promise<void>;
284
+ clearMerkleNodes(chainId: number): Promise<void>;
285
+ getMerkleTree(chainId: number): Promise<MerkleTreeState | undefined>;
286
+ setMerkleTree(chainId: number, tree: MerkleTreeState): Promise<void>;
287
+ clearMerkleTree(chainId: number): Promise<void>;
288
+ upsertEntryMemos(memos: EntryMemoRecord[]): Promise<void>;
289
+ listEntryMemos(query: ListEntryMemosQuery): Promise<{
290
+ total: number;
291
+ rows: EntryMemoRecord[];
292
+ }>;
293
+ clearEntryMemos(chainId: number): Promise<void>;
294
+ upsertEntryNullifiers(nullifiers: EntryNullifierRecord[]): Promise<void>;
295
+ listEntryNullifiers(query: ListEntryNullifiersQuery): Promise<{
296
+ total: number;
297
+ rows: EntryNullifierRecord[];
298
+ }>;
299
+ clearEntryNullifiers(chainId: number): Promise<void>;
300
+ private getOperationById;
301
+ private operationFromRow;
302
+ private upsertOperationRow;
75
303
  createOperation<TType extends OperationType>(input: Omit<StoredOperation<OperationDetailFor<TType>>, 'id' | 'createdAt' | 'status'> & Partial<Pick<StoredOperation<OperationDetailFor<TType>>, 'createdAt' | 'id' | 'status'>> & {
76
304
  type: TType;
77
305
  }): StoredOperation<OperationDetailFor<TType>> & {
@@ -86,4 +314,4 @@ declare class FileStore implements StorageAdapter {
86
314
  listOperations(input?: number | ListOperationsQuery): StoredOperation[];
87
315
  }
88
316
 
89
- export { EntryMemoRecord, EntryNullifierRecord, FileStore, type FileStoreOptions, Hex, ListEntryMemosQuery, ListEntryNullifiersQuery, ListOperationsQuery, ListUtxosQuery, MerkleNodeRecord, MerkleTreeState, OperationType, StorageAdapter, StoredOperation, SyncCursor, UtxoRecord };
317
+ export { EntryMemoRecord, EntryNullifierRecord, FileStore, type FileStoreOptions, Hex, ListEntryMemosQuery, ListEntryNullifiersQuery, ListOperationsQuery, ListUtxosQuery, MerkleLeafRecord, MerkleNodeRecord, MerkleTreeState, OperationStatus, OperationType, SqliteStore, type SqliteStoreOptions, StorageAdapter, StoredOperation, SyncCursor, UtxoRecord };