@cloak.ag/sdk 1.0.5 → 1.0.7
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/chunk-QDMAIFO4.js +389 -0
- package/dist/index.cjs +2879 -3071
- package/dist/index.d.cts +198 -284
- package/dist/index.d.ts +198 -284
- package/dist/index.js +2520 -3089
- package/dist/onchain-proof-CY7AWF43.js +10 -0
- package/package.json +12 -3
package/dist/index.d.ts
CHANGED
|
@@ -130,12 +130,6 @@ interface CloakConfig {
|
|
|
130
130
|
* Optional but recommended for full functionality
|
|
131
131
|
*/
|
|
132
132
|
cloakKeys?: any;
|
|
133
|
-
/**
|
|
134
|
-
* Single API base URL for both Indexer and Relay services.
|
|
135
|
-
* If provided, it will be used for both services and overrides
|
|
136
|
-
* any `indexerUrl` or `relayUrl` values.
|
|
137
|
-
*/
|
|
138
|
-
apiUrl?: string;
|
|
139
133
|
/** Optional: Proof generation timeout in milliseconds (default: 5 minutes) */
|
|
140
134
|
proofTimeout?: number;
|
|
141
135
|
/** Optional: Program ID (defaults to Cloak mainnet program) */
|
|
@@ -152,6 +146,23 @@ interface CloakConfig {
|
|
|
152
146
|
nullifierShardAddress?: PublicKey;
|
|
153
147
|
/** Optional: Treasury account address (auto-derived if not provided) */
|
|
154
148
|
treasuryAddress?: PublicKey;
|
|
149
|
+
/**
|
|
150
|
+
* Enable debug logging with structured output similar to Rust tracing.
|
|
151
|
+
*
|
|
152
|
+
* When enabled, logs SDK operations with timestamps, module paths,
|
|
153
|
+
* and key-value pairs for context:
|
|
154
|
+
*
|
|
155
|
+
* ```
|
|
156
|
+
* 2026-01-23T00:51:46.489000Z INFO cloak::sdk: 📥 Deposit completed signature=42XB... leaf_index=757
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* Can also be enabled via environment variable:
|
|
160
|
+
* - `CLOAK_DEBUG=1`
|
|
161
|
+
* - `DEBUG=cloak:*`
|
|
162
|
+
*
|
|
163
|
+
* Default: false
|
|
164
|
+
*/
|
|
165
|
+
debug?: boolean;
|
|
155
166
|
}
|
|
156
167
|
/**
|
|
157
168
|
* Deposit progress status
|
|
@@ -199,10 +210,46 @@ interface DepositOptions {
|
|
|
199
210
|
requireNoteAcknowledgment?: boolean;
|
|
200
211
|
/** Skip simulation (default: false) */
|
|
201
212
|
skipPreflight?: boolean;
|
|
202
|
-
/**
|
|
213
|
+
/**
|
|
214
|
+
* Compute units to request.
|
|
215
|
+
* - If `optimizeCU` is true, this is ignored and CU is determined via simulation
|
|
216
|
+
* - Otherwise defaults to 40,000 (suitable for typical deposits)
|
|
217
|
+
*/
|
|
203
218
|
computeUnits?: number;
|
|
204
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Enable simulation-based CU optimization.
|
|
221
|
+
* When true, simulates the transaction first to determine actual CU usage,
|
|
222
|
+
* then sets an optimal limit (simulated + 20% buffer).
|
|
223
|
+
*
|
|
224
|
+
* **Note: Only works in keypair mode (Node.js/scripts).**
|
|
225
|
+
* In wallet/browser mode, this is ignored because simulation would require
|
|
226
|
+
* the user to sign twice (simulation + actual tx) which is bad UX.
|
|
227
|
+
*
|
|
228
|
+
* Trade-offs:
|
|
229
|
+
* - ✅ Optimal block scheduling priority
|
|
230
|
+
* - ❌ Adds ~200-500ms latency (extra RPC call)
|
|
231
|
+
* - ❌ Only available in keypair mode
|
|
232
|
+
*
|
|
233
|
+
* Default: false (uses fixed 40K CU which is ~75% efficient for typical deposits)
|
|
234
|
+
*/
|
|
235
|
+
optimizeCU?: boolean;
|
|
236
|
+
/** Priority fee in micro-lamports (default: 10,000) */
|
|
205
237
|
priorityFee?: number;
|
|
238
|
+
/**
|
|
239
|
+
* Loaded accounts data size limit in bytes.
|
|
240
|
+
*
|
|
241
|
+
* Without this, Solana defaults to 64MB which incurs CU overhead
|
|
242
|
+
* (charged at 8 CU per 32KB). Setting a lower limit improves priority.
|
|
243
|
+
*
|
|
244
|
+
* **Note for Cloak deposits:**
|
|
245
|
+
* The Shield Pool program is ~104KB, so the minimum practical limit is ~128KB.
|
|
246
|
+
*
|
|
247
|
+
* Default: 256 * 1024 (256KB) - provides safety margin above program size.
|
|
248
|
+
* Set to 0 to disable (use Solana 64MB default).
|
|
249
|
+
*
|
|
250
|
+
* @see https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
|
|
251
|
+
*/
|
|
252
|
+
loadedAccountsDataSizeLimit?: number;
|
|
206
253
|
/**
|
|
207
254
|
* Optional: Encrypt output for specific recipient's view key
|
|
208
255
|
* If not provided, encrypts for the wallet's own view key (for self-scanning)
|
|
@@ -250,28 +297,6 @@ interface TxStatus {
|
|
|
250
297
|
txId?: string;
|
|
251
298
|
error?: string;
|
|
252
299
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Note scanning options
|
|
255
|
-
*/
|
|
256
|
-
interface ScanNotesOptions {
|
|
257
|
-
/** Start index for scanning (default: 0) */
|
|
258
|
-
startIndex?: number;
|
|
259
|
-
/** End index for scanning (default: latest) */
|
|
260
|
-
endIndex?: number;
|
|
261
|
-
/** Batch size for fetching notes (default: 100) */
|
|
262
|
-
batchSize?: number;
|
|
263
|
-
/** Progress callback */
|
|
264
|
-
onProgress?: (current: number, total: number) => void;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Scanned note result with metadata
|
|
268
|
-
*/
|
|
269
|
-
interface ScannedNote extends CloakNote {
|
|
270
|
-
/** When this note was discovered */
|
|
271
|
-
scannedAt: number;
|
|
272
|
-
/** Whether this note has been spent (nullifier check) */
|
|
273
|
-
isSpent?: boolean;
|
|
274
|
-
}
|
|
275
300
|
/**
|
|
276
301
|
* Swap parameters for token swaps
|
|
277
302
|
*/
|
|
@@ -503,9 +528,7 @@ declare class CloakSDK {
|
|
|
503
528
|
private keypair?;
|
|
504
529
|
private wallet?;
|
|
505
530
|
private cloakKeys?;
|
|
506
|
-
private indexer;
|
|
507
531
|
private relay;
|
|
508
|
-
private depositRecovery;
|
|
509
532
|
private storage;
|
|
510
533
|
/**
|
|
511
534
|
* Create a new Cloak SDK client
|
|
@@ -537,8 +560,9 @@ declare class CloakSDK {
|
|
|
537
560
|
cloakKeys?: CloakKeyPair;
|
|
538
561
|
storage?: StorageAdapter;
|
|
539
562
|
programId?: PublicKey;
|
|
540
|
-
indexerUrl?: string;
|
|
541
563
|
relayUrl?: string;
|
|
564
|
+
/** Enable debug logging with structured output */
|
|
565
|
+
debug?: boolean;
|
|
542
566
|
});
|
|
543
567
|
/**
|
|
544
568
|
* Get the public key for deposits (from keypair or wallet)
|
|
@@ -737,18 +761,20 @@ declare class CloakSDK {
|
|
|
737
761
|
*/
|
|
738
762
|
isWithdrawable(note: CloakNote): boolean;
|
|
739
763
|
/**
|
|
740
|
-
* Get Merkle proof for a leaf index
|
|
764
|
+
* Get Merkle proof for a leaf index directly from on-chain state
|
|
741
765
|
*
|
|
766
|
+
* @param connection - Solana connection
|
|
742
767
|
* @param leafIndex - Leaf index in tree
|
|
743
|
-
* @returns Merkle proof
|
|
768
|
+
* @returns Merkle proof computed from on-chain data
|
|
744
769
|
*/
|
|
745
|
-
getMerkleProof(leafIndex: number): Promise<MerkleProof>;
|
|
770
|
+
getMerkleProof(connection: Connection, leafIndex: number): Promise<MerkleProof>;
|
|
746
771
|
/**
|
|
747
|
-
* Get current Merkle root
|
|
772
|
+
* Get current Merkle root directly from on-chain state
|
|
748
773
|
*
|
|
749
|
-
* @
|
|
774
|
+
* @param connection - Solana connection
|
|
775
|
+
* @returns Current root hash from on-chain tree
|
|
750
776
|
*/
|
|
751
|
-
getCurrentRoot(): Promise<string>;
|
|
777
|
+
getCurrentRoot(connection: Connection): Promise<string>;
|
|
752
778
|
/**
|
|
753
779
|
* Get transaction status from relay service
|
|
754
780
|
*
|
|
@@ -756,47 +782,6 @@ declare class CloakSDK {
|
|
|
756
782
|
* @returns Current status
|
|
757
783
|
*/
|
|
758
784
|
getTransactionStatus(requestId: string): Promise<TxStatus>;
|
|
759
|
-
/**
|
|
760
|
-
* Recover a deposit that completed on-chain but failed to register
|
|
761
|
-
*
|
|
762
|
-
* Use this when a deposit transaction succeeded but the browser crashed
|
|
763
|
-
* or lost connection before the indexer registration completed.
|
|
764
|
-
*
|
|
765
|
-
* @param signature - Transaction signature
|
|
766
|
-
* @param commitment - Note commitment hash
|
|
767
|
-
* @param note - Optional: The full note if available
|
|
768
|
-
* @returns Recovery result with updated note
|
|
769
|
-
*
|
|
770
|
-
* @example
|
|
771
|
-
* ```typescript
|
|
772
|
-
* const result = await sdk.recoverDeposit({
|
|
773
|
-
* signature: "5Kn4...",
|
|
774
|
-
* commitment: "abc123...",
|
|
775
|
-
* note: myNote // optional if you have it
|
|
776
|
-
* });
|
|
777
|
-
*
|
|
778
|
-
* if (result.success) {
|
|
779
|
-
* console.log(`Recovered! Leaf index: ${result.leafIndex}`);
|
|
780
|
-
* }
|
|
781
|
-
* ```
|
|
782
|
-
*/
|
|
783
|
-
recoverDeposit(options: {
|
|
784
|
-
signature: string;
|
|
785
|
-
commitment: string;
|
|
786
|
-
note?: CloakNote;
|
|
787
|
-
onProgress?: (status: string) => void;
|
|
788
|
-
}): Promise<{
|
|
789
|
-
success: boolean;
|
|
790
|
-
leafIndex?: number;
|
|
791
|
-
root?: string;
|
|
792
|
-
slot?: number;
|
|
793
|
-
merkleProof?: {
|
|
794
|
-
pathElements: string[];
|
|
795
|
-
pathIndices: number[];
|
|
796
|
-
};
|
|
797
|
-
note?: CloakNote;
|
|
798
|
-
error?: string;
|
|
799
|
-
}>;
|
|
800
785
|
/**
|
|
801
786
|
* Load all notes from storage
|
|
802
787
|
*
|
|
@@ -834,29 +819,6 @@ declare class CloakSDK {
|
|
|
834
819
|
* Get the configuration
|
|
835
820
|
*/
|
|
836
821
|
getConfig(): CloakConfig;
|
|
837
|
-
/**
|
|
838
|
-
* Scan blockchain for notes belonging to this wallet (v2.0 feature)
|
|
839
|
-
*
|
|
840
|
-
* Requires Cloak keys to be configured in the SDK.
|
|
841
|
-
* Fetches encrypted outputs from the indexer and decrypts notes
|
|
842
|
-
* that belong to this wallet.
|
|
843
|
-
*
|
|
844
|
-
* @param options - Scanning options
|
|
845
|
-
* @returns Array of discovered notes with metadata
|
|
846
|
-
*
|
|
847
|
-
* @example
|
|
848
|
-
* ```typescript
|
|
849
|
-
* const notes = await sdk.scanNotes({
|
|
850
|
-
* onProgress: (current, total) => {
|
|
851
|
-
* console.log(`Scanning: ${current}/${total}`);
|
|
852
|
-
* }
|
|
853
|
-
* });
|
|
854
|
-
*
|
|
855
|
-
* console.log(`Found ${notes.length} notes!`);
|
|
856
|
-
* const totalBalance = notes.reduce((sum, n) => sum + n.amount, 0);
|
|
857
|
-
* ```
|
|
858
|
-
*/
|
|
859
|
-
scanNotes(options?: ScanNotesOptions): Promise<ScannedNote[]>;
|
|
860
822
|
/**
|
|
861
823
|
* Wrap errors with better categorization and user-friendly messages
|
|
862
824
|
*
|
|
@@ -929,6 +891,7 @@ declare function parseNote(jsonString: string): CloakNote;
|
|
|
929
891
|
declare function exportNote(note: CloakNote, pretty?: boolean): string;
|
|
930
892
|
/**
|
|
931
893
|
* Check if a note is withdrawable (has been deposited)
|
|
894
|
+
* Note: merkleProof is optional - it may be fetched lazily at withdrawal time
|
|
932
895
|
*/
|
|
933
896
|
declare function isWithdrawable(note: CloakNote): boolean;
|
|
934
897
|
/**
|
|
@@ -940,7 +903,7 @@ declare function updateNoteWithDeposit(note: CloakNote, depositInfo: {
|
|
|
940
903
|
slot: number;
|
|
941
904
|
leafIndex: number;
|
|
942
905
|
root: string;
|
|
943
|
-
merkleProof
|
|
906
|
+
merkleProof?: {
|
|
944
907
|
pathElements: string[];
|
|
945
908
|
pathIndices: number[];
|
|
946
909
|
};
|
|
@@ -1368,6 +1331,22 @@ declare function getAddressExplorerUrl(address: string, network?: Network): stri
|
|
|
1368
1331
|
* This is the single source of truth for error codes and messages.
|
|
1369
1332
|
*/
|
|
1370
1333
|
|
|
1334
|
+
/**
|
|
1335
|
+
* Error thrown when the Merkle root used in a proof is no longer
|
|
1336
|
+
* in the on-chain root history (stale root).
|
|
1337
|
+
*
|
|
1338
|
+
* This happens when many deposits occur between proof generation and
|
|
1339
|
+
* transaction submission, pushing the proof's root out of history.
|
|
1340
|
+
*
|
|
1341
|
+
* The fix is to regenerate the proof with a fresh Merkle root.
|
|
1342
|
+
*/
|
|
1343
|
+
declare class RootNotFoundError extends Error {
|
|
1344
|
+
constructor(message?: string);
|
|
1345
|
+
}
|
|
1346
|
+
/**
|
|
1347
|
+
* Check if an error message indicates a RootNotFound (0x1001) error
|
|
1348
|
+
*/
|
|
1349
|
+
declare function isRootNotFoundError(error: unknown): boolean;
|
|
1371
1350
|
/**
|
|
1372
1351
|
* Shield Pool Program Error Codes
|
|
1373
1352
|
*
|
|
@@ -1417,125 +1396,71 @@ declare function createCloakError(error: unknown, _context: string): CloakError;
|
|
|
1417
1396
|
declare function formatErrorForLogging(error: unknown): string;
|
|
1418
1397
|
|
|
1419
1398
|
/**
|
|
1420
|
-
*
|
|
1399
|
+
* Structured Logger for Cloak SDK
|
|
1400
|
+
*
|
|
1401
|
+
* Provides structured logging similar to Rust tracing format:
|
|
1402
|
+
* 2026-01-23T00:51:46.489317Z INFO cloak::module: 📥 Message key=value
|
|
1403
|
+
*
|
|
1404
|
+
* Enable via:
|
|
1405
|
+
* - SDK config: new CloakSDK({ debug: true })
|
|
1406
|
+
* - Environment: CLOAK_DEBUG=1 or DEBUG=cloak:*
|
|
1407
|
+
*/
|
|
1408
|
+
type LogLevel = "DEBUG" | "INFO" | "WARN" | "ERROR";
|
|
1409
|
+
/**
|
|
1410
|
+
* Enable or disable debug logging globally
|
|
1411
|
+
*/
|
|
1412
|
+
declare function setDebugMode(enabled: boolean): void;
|
|
1413
|
+
/**
|
|
1414
|
+
* Check if debug mode is enabled
|
|
1421
1415
|
*/
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1416
|
+
declare function isDebugEnabled(): boolean;
|
|
1417
|
+
/**
|
|
1418
|
+
* Logger interface
|
|
1419
|
+
*/
|
|
1420
|
+
interface Logger {
|
|
1421
|
+
debug: (message: string, kvPairs?: Record<string, unknown>) => void;
|
|
1422
|
+
info: (message: string, kvPairs?: Record<string, unknown>) => void;
|
|
1423
|
+
warn: (message: string, kvPairs?: Record<string, unknown>) => void;
|
|
1424
|
+
error: (message: string, kvPairs?: Record<string, unknown>) => void;
|
|
1428
1425
|
}
|
|
1429
1426
|
/**
|
|
1430
|
-
*
|
|
1427
|
+
* Create a logger for a specific module
|
|
1428
|
+
*
|
|
1429
|
+
* @param module - Module name (e.g., "cloak::sdk", "cloak::indexer")
|
|
1430
|
+
* @returns Logger instance with debug, info, warn, error methods
|
|
1431
1431
|
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1432
|
+
* @example
|
|
1433
|
+
* ```typescript
|
|
1434
|
+
* const log = createLogger("cloak::deposit");
|
|
1435
|
+
* log.info("Depositing", { amount: 100000000 });
|
|
1436
|
+
* // Output: 2026-01-23T00:51:46.489000Z INFO cloak::deposit: Depositing amount=100000000
|
|
1437
|
+
* ```
|
|
1434
1438
|
*/
|
|
1435
|
-
declare
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
*
|
|
1461
|
-
* @example
|
|
1462
|
-
* ```typescript
|
|
1463
|
-
* const proof = await indexer.getMerkleProof(42);
|
|
1464
|
-
* console.log(`Proof has ${proof.pathElements.length} siblings`);
|
|
1465
|
-
* ```
|
|
1466
|
-
*/
|
|
1467
|
-
getMerkleProof(leafIndex: number): Promise<MerkleProof>;
|
|
1468
|
-
/**
|
|
1469
|
-
* Get notes in a specific range
|
|
1470
|
-
*
|
|
1471
|
-
* Useful for scanning the tree or fetching notes in batches.
|
|
1472
|
-
*
|
|
1473
|
-
* @param start - Start index (inclusive)
|
|
1474
|
-
* @param end - End index (inclusive)
|
|
1475
|
-
* @param limit - Maximum number of notes to return (default: 100)
|
|
1476
|
-
* @returns Notes in the range
|
|
1477
|
-
*
|
|
1478
|
-
* @example
|
|
1479
|
-
* ```typescript
|
|
1480
|
-
* const { notes, has_more } = await indexer.getNotesRange(0, 99, 100);
|
|
1481
|
-
* console.log(`Fetched ${notes.length} notes`);
|
|
1482
|
-
* ```
|
|
1483
|
-
*/
|
|
1484
|
-
getNotesRange(start: number, end: number, limit?: number): Promise<NotesRangeResponse>;
|
|
1485
|
-
/**
|
|
1486
|
-
* Get all notes from the tree
|
|
1487
|
-
*
|
|
1488
|
-
* Fetches all notes in batches. Use with caution for large trees.
|
|
1489
|
-
*
|
|
1490
|
-
* @param batchSize - Size of each batch (default: 100)
|
|
1491
|
-
* @returns All encrypted notes
|
|
1492
|
-
*
|
|
1493
|
-
* @example
|
|
1494
|
-
* ```typescript
|
|
1495
|
-
* const allNotes = await indexer.getAllNotes();
|
|
1496
|
-
* console.log(`Total notes: ${allNotes.length}`);
|
|
1497
|
-
* ```
|
|
1498
|
-
*/
|
|
1499
|
-
getAllNotes(batchSize?: number): Promise<string[]>;
|
|
1500
|
-
/**
|
|
1501
|
-
* Submit a deposit to the indexer
|
|
1502
|
-
*
|
|
1503
|
-
* Registers a new deposit transaction with the indexer, which will
|
|
1504
|
-
* return the leaf index and current root.
|
|
1505
|
-
*
|
|
1506
|
-
* @param params - Deposit parameters
|
|
1507
|
-
* @returns Success response with leaf index and root
|
|
1508
|
-
*
|
|
1509
|
-
* @example
|
|
1510
|
-
* ```typescript
|
|
1511
|
-
* const result = await indexer.submitDeposit({
|
|
1512
|
-
* leafCommit: note.commitment,
|
|
1513
|
-
* encryptedOutput: btoa(JSON.stringify(noteData)),
|
|
1514
|
-
* txSignature: signature,
|
|
1515
|
-
* slot: txSlot
|
|
1516
|
-
* });
|
|
1517
|
-
* console.log(`Leaf index: ${result.leafIndex}`);
|
|
1518
|
-
* ```
|
|
1519
|
-
*/
|
|
1520
|
-
submitDeposit(params: {
|
|
1521
|
-
leafCommit: string;
|
|
1522
|
-
encryptedOutput: string;
|
|
1523
|
-
txSignature: string;
|
|
1524
|
-
slot: number;
|
|
1525
|
-
}): Promise<{
|
|
1526
|
-
success: boolean;
|
|
1527
|
-
leafIndex?: number;
|
|
1528
|
-
root?: string;
|
|
1529
|
-
}>;
|
|
1530
|
-
/**
|
|
1531
|
-
* Check indexer health
|
|
1532
|
-
*
|
|
1533
|
-
* @returns Health status
|
|
1534
|
-
*/
|
|
1535
|
-
healthCheck(): Promise<{
|
|
1536
|
-
status: string;
|
|
1537
|
-
}>;
|
|
1538
|
-
}
|
|
1439
|
+
declare function createLogger(module: string): Logger;
|
|
1440
|
+
/**
|
|
1441
|
+
* Measure and return duration of an async operation
|
|
1442
|
+
*
|
|
1443
|
+
* @param _logger - Logger instance (reserved for future debug logging)
|
|
1444
|
+
* @param _operation - Operation name (reserved for future debug logging)
|
|
1445
|
+
* @param fn - Async function to measure
|
|
1446
|
+
* @returns Result and duration in milliseconds
|
|
1447
|
+
*/
|
|
1448
|
+
declare function withTiming<T>(_logger: Logger, _operation: string, fn: () => Promise<T>): Promise<{
|
|
1449
|
+
result: T;
|
|
1450
|
+
durationMs: number;
|
|
1451
|
+
}>;
|
|
1452
|
+
/**
|
|
1453
|
+
* Format lamports as SOL with proper decimals
|
|
1454
|
+
*/
|
|
1455
|
+
declare function formatSol(lamports: number | bigint): string;
|
|
1456
|
+
/**
|
|
1457
|
+
* Truncate a string (useful for signatures, hashes)
|
|
1458
|
+
*/
|
|
1459
|
+
declare function truncate(str: string, len?: number): string;
|
|
1460
|
+
/**
|
|
1461
|
+
* Default SDK logger instance
|
|
1462
|
+
*/
|
|
1463
|
+
declare const sdkLogger: Logger;
|
|
1539
1464
|
|
|
1540
1465
|
/**
|
|
1541
1466
|
* Result from submitting a withdrawal that includes the request ID
|
|
@@ -1707,70 +1632,6 @@ declare class RelayService {
|
|
|
1707
1632
|
private sleep;
|
|
1708
1633
|
}
|
|
1709
1634
|
|
|
1710
|
-
/**
|
|
1711
|
-
* Deposit Recovery Service
|
|
1712
|
-
*
|
|
1713
|
-
* Handles recovery of deposits that completed on-chain but failed
|
|
1714
|
-
* to finalize with the indexer (e.g., browser crash, network failure)
|
|
1715
|
-
*/
|
|
1716
|
-
|
|
1717
|
-
interface RecoveryOptions {
|
|
1718
|
-
/** Transaction signature to recover */
|
|
1719
|
-
signature: string;
|
|
1720
|
-
/** Note commitment hash */
|
|
1721
|
-
commitment: string;
|
|
1722
|
-
/** Optional: The full note if available */
|
|
1723
|
-
note?: CloakNote;
|
|
1724
|
-
/** Callback for progress updates */
|
|
1725
|
-
onProgress?: (status: string) => void;
|
|
1726
|
-
}
|
|
1727
|
-
interface RecoveryResult {
|
|
1728
|
-
success: boolean;
|
|
1729
|
-
leafIndex?: number;
|
|
1730
|
-
root?: string;
|
|
1731
|
-
slot?: number;
|
|
1732
|
-
merkleProof?: {
|
|
1733
|
-
pathElements: string[];
|
|
1734
|
-
pathIndices: number[];
|
|
1735
|
-
};
|
|
1736
|
-
note?: CloakNote;
|
|
1737
|
-
error?: string;
|
|
1738
|
-
}
|
|
1739
|
-
/**
|
|
1740
|
-
* Service for recovering incomplete deposits
|
|
1741
|
-
*/
|
|
1742
|
-
declare class DepositRecoveryService {
|
|
1743
|
-
private indexer;
|
|
1744
|
-
private apiUrl;
|
|
1745
|
-
constructor(indexer: IndexerService, apiUrl: string);
|
|
1746
|
-
/**
|
|
1747
|
-
* Recover a deposit that completed on-chain but failed to register
|
|
1748
|
-
*
|
|
1749
|
-
* @param options Recovery options
|
|
1750
|
-
* @returns Recovery result with updated note
|
|
1751
|
-
*/
|
|
1752
|
-
recoverDeposit(options: RecoveryOptions): Promise<RecoveryResult>;
|
|
1753
|
-
/**
|
|
1754
|
-
* Check if a deposit already exists in the indexer
|
|
1755
|
-
* Uses the enhanced deposit lookup endpoint with include_proof=true
|
|
1756
|
-
*
|
|
1757
|
-
* @private
|
|
1758
|
-
*/
|
|
1759
|
-
private checkExistingDeposit;
|
|
1760
|
-
/**
|
|
1761
|
-
* Recover deposit by transaction signature
|
|
1762
|
-
* Uses the indexer's signature lookup endpoint
|
|
1763
|
-
*/
|
|
1764
|
-
recoverBySignature(signature: string): Promise<RecoveryResult>;
|
|
1765
|
-
/**
|
|
1766
|
-
* Finalize a deposit via server API (alternative recovery method)
|
|
1767
|
-
*
|
|
1768
|
-
* This method calls a server-side endpoint that can handle
|
|
1769
|
-
* the recovery process with elevated permissions.
|
|
1770
|
-
*/
|
|
1771
|
-
finalizeDepositViaServer(signature: string, commitment: string, encryptedOutput?: string): Promise<RecoveryResult>;
|
|
1772
|
-
}
|
|
1773
|
-
|
|
1774
1635
|
/**
|
|
1775
1636
|
* Encrypted Output Helpers
|
|
1776
1637
|
*
|
|
@@ -1834,7 +1695,7 @@ declare function keypairToAdapter(keypair: Keypair): WalletAdapter;
|
|
|
1834
1695
|
* Deposits SOL into the Cloak protocol by creating a commitment.
|
|
1835
1696
|
*
|
|
1836
1697
|
* Instruction format:
|
|
1837
|
-
* - Byte 0: Discriminant (
|
|
1698
|
+
* - Byte 0: Discriminant (0x01 for Deposit, per ShieldPoolInstruction enum)
|
|
1838
1699
|
* - Bytes 1-8: Amount (u64, little-endian)
|
|
1839
1700
|
* - Bytes 9-40: Commitment (32 bytes)
|
|
1840
1701
|
*
|
|
@@ -1914,6 +1775,59 @@ interface ShieldPoolPDAs {
|
|
|
1914
1775
|
*/
|
|
1915
1776
|
declare function getShieldPoolPDAs(programId?: PublicKey, mint?: PublicKey): ShieldPoolPDAs;
|
|
1916
1777
|
|
|
1778
|
+
/**
|
|
1779
|
+
* On-chain Merkle proof computation
|
|
1780
|
+
*
|
|
1781
|
+
* Computes Merkle proofs directly from on-chain tree state,
|
|
1782
|
+
* eliminating the need for an indexer for proof generation.
|
|
1783
|
+
*/
|
|
1784
|
+
|
|
1785
|
+
/**
|
|
1786
|
+
* Merkle proof result
|
|
1787
|
+
*/
|
|
1788
|
+
interface OnchainMerkleProof {
|
|
1789
|
+
pathElements: string[];
|
|
1790
|
+
pathIndices: number[];
|
|
1791
|
+
root: string;
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Read the Merkle tree state from on-chain account
|
|
1795
|
+
*/
|
|
1796
|
+
declare function readMerkleTreeState(connection: Connection, merkleTreePDA: PublicKey): Promise<{
|
|
1797
|
+
nextIndex: number;
|
|
1798
|
+
root: string;
|
|
1799
|
+
subtrees: string[];
|
|
1800
|
+
}>;
|
|
1801
|
+
/**
|
|
1802
|
+
* Compute Merkle proof for a leaf at a given index using on-chain state
|
|
1803
|
+
*
|
|
1804
|
+
* This works by:
|
|
1805
|
+
* 1. Reading the subtrees (frontier) from the on-chain account
|
|
1806
|
+
* 2. For each level, determining the sibling:
|
|
1807
|
+
* - If index is odd: sibling is the stored subtree (left sibling)
|
|
1808
|
+
* - If index is even: sibling is either a subsequent subtree or zero value
|
|
1809
|
+
*
|
|
1810
|
+
* Note: This works best for recent leaves where siblings are zero values.
|
|
1811
|
+
* For older leaves with non-zero siblings that aren't stored in subtrees,
|
|
1812
|
+
* an indexer may still be needed.
|
|
1813
|
+
*
|
|
1814
|
+
* @param connection - Solana connection
|
|
1815
|
+
* @param merkleTreePDA - PDA of the merkle tree account
|
|
1816
|
+
* @param leafIndex - Index of the leaf to compute proof for
|
|
1817
|
+
* @returns Merkle proof with path elements and indices
|
|
1818
|
+
*/
|
|
1819
|
+
declare function computeProofFromChain(connection: Connection, merkleTreePDA: PublicKey, leafIndex: number): Promise<OnchainMerkleProof>;
|
|
1820
|
+
/**
|
|
1821
|
+
* Compute proof for the most recently inserted leaf
|
|
1822
|
+
*
|
|
1823
|
+
* This is the most reliable case - immediately after your deposit,
|
|
1824
|
+
* all siblings to the right are zero values, and siblings to the left
|
|
1825
|
+
* are stored in the subtrees.
|
|
1826
|
+
*/
|
|
1827
|
+
declare function computeProofForLatestDeposit(connection: Connection, merkleTreePDA: PublicKey): Promise<OnchainMerkleProof & {
|
|
1828
|
+
leafIndex: number;
|
|
1829
|
+
}>;
|
|
1830
|
+
|
|
1917
1831
|
/**
|
|
1918
1832
|
* Direct Circom WASM Proof Generation
|
|
1919
1833
|
*
|
|
@@ -2162,4 +2076,4 @@ declare function cleanupStalePendingOperations(maxAgeMs?: number): {
|
|
|
2162
2076
|
|
|
2163
2077
|
declare const VERSION = "1.0.0";
|
|
2164
2078
|
|
|
2165
|
-
export { CLOAK_PROGRAM_ID, type CircuitVerificationResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, CloakSDK, type DepositInstructionParams, type DepositOptions,
|
|
2079
|
+
export { CLOAK_PROGRAM_ID, type CircuitVerificationResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, CloakSDK, type DepositInstructionParams, type DepositOptions, type DepositResult, type DepositStatus, EXPECTED_CIRCUIT_HASHES, type EncryptedNote, type ErrorCategory, FIXED_FEE_LAMPORTS, type Groth16Proof, LAMPORTS_PER_SOL, LocalStorageAdapter, type LogLevel, type Logger, type MasterKey, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, type Network, type NoteData, type OnchainMerkleProof, type PendingDeposit, type PendingWithdrawal, type ProofResult, RelayService, RootNotFoundError, ShieldPoolErrors, type ShieldPoolPDAs, type SpendKey, type StorageAdapter, type SwapOptions, type SwapParams, type SwapResult, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, VARIABLE_FEE_RATE, VERSION, type ViewKey, type WalletAdapter, type WithdrawOptions, type WithdrawRegularInputs, type WithdrawSubmissionResult, type WithdrawSwapInputs, bigintToBytes32, buildPublicInputsBytes, bytesToHex, calculateFee, calculateRelayFee, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, computeCommitment, computeMerkleRoot, computeNullifier, computeNullifierAsync, computeNullifierSync, computeOutputsHash, computeOutputsHashAsync, computeOutputsHashSync, computeProofForLatestDeposit, computeProofFromChain, computeSwapOutputsHash, computeSwapOutputsHashAsync, computeSwapOutputsHashSync, copyNoteToClipboard, createCloakError, createDepositInstruction, createLogger, deriveSpendKey, deriveViewKey, detectNetworkFromRpcUrl, downloadNote, encodeNoteSimple, encryptNoteForRecipient, exportKeys, exportNote, exportWalletKeys, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, formatAmount, formatErrorForLogging, formatSol, generateCloakKeys, generateCommitment, generateCommitmentAsync, generateMasterSeed, generateNote, generateNoteFromWallet, generateWithdrawRegularProof, generateWithdrawSwapProof, getAddressExplorerUrl, getDistributableAmount, getExplorerUrl, getPendingOperationsSummary, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getViewKey, hasPendingOperations, hexToBigint, hexToBytes, importKeys, importWalletKeys, isDebugEnabled, isRootNotFoundError, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawable, keypairToAdapter, loadPendingDeposits, loadPendingWithdrawals, parseAmount, parseError, parseNote, parseTransactionError, poseidonHash, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, proofToBytes, pubkeyToLimbs, randomBytes, readMerkleTreeState, removePendingDeposit, removePendingWithdrawal, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, sdkLogger, sendTransaction, serializeNote, setDebugMode, signTransaction, splitTo2Limbs, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, validateDepositParams, validateNote, validateOutputsSum, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, withTiming };
|