@cloak.ag/sdk 1.0.6 → 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 +2867 -3126
- package/dist/index.d.cts +160 -282
- package/dist/index.d.ts +160 -282
- package/dist/index.js +2509 -3147
- package/dist/onchain-proof-CY7AWF43.js +10 -0
- package/package.json +11 -2
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
|
|
@@ -286,28 +297,6 @@ interface TxStatus {
|
|
|
286
297
|
txId?: string;
|
|
287
298
|
error?: string;
|
|
288
299
|
}
|
|
289
|
-
/**
|
|
290
|
-
* Note scanning options
|
|
291
|
-
*/
|
|
292
|
-
interface ScanNotesOptions {
|
|
293
|
-
/** Start index for scanning (default: 0) */
|
|
294
|
-
startIndex?: number;
|
|
295
|
-
/** End index for scanning (default: latest) */
|
|
296
|
-
endIndex?: number;
|
|
297
|
-
/** Batch size for fetching notes (default: 100) */
|
|
298
|
-
batchSize?: number;
|
|
299
|
-
/** Progress callback */
|
|
300
|
-
onProgress?: (current: number, total: number) => void;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Scanned note result with metadata
|
|
304
|
-
*/
|
|
305
|
-
interface ScannedNote extends CloakNote {
|
|
306
|
-
/** When this note was discovered */
|
|
307
|
-
scannedAt: number;
|
|
308
|
-
/** Whether this note has been spent (nullifier check) */
|
|
309
|
-
isSpent?: boolean;
|
|
310
|
-
}
|
|
311
300
|
/**
|
|
312
301
|
* Swap parameters for token swaps
|
|
313
302
|
*/
|
|
@@ -539,9 +528,7 @@ declare class CloakSDK {
|
|
|
539
528
|
private keypair?;
|
|
540
529
|
private wallet?;
|
|
541
530
|
private cloakKeys?;
|
|
542
|
-
private indexer;
|
|
543
531
|
private relay;
|
|
544
|
-
private depositRecovery;
|
|
545
532
|
private storage;
|
|
546
533
|
/**
|
|
547
534
|
* Create a new Cloak SDK client
|
|
@@ -573,8 +560,9 @@ declare class CloakSDK {
|
|
|
573
560
|
cloakKeys?: CloakKeyPair;
|
|
574
561
|
storage?: StorageAdapter;
|
|
575
562
|
programId?: PublicKey;
|
|
576
|
-
indexerUrl?: string;
|
|
577
563
|
relayUrl?: string;
|
|
564
|
+
/** Enable debug logging with structured output */
|
|
565
|
+
debug?: boolean;
|
|
578
566
|
});
|
|
579
567
|
/**
|
|
580
568
|
* Get the public key for deposits (from keypair or wallet)
|
|
@@ -773,18 +761,20 @@ declare class CloakSDK {
|
|
|
773
761
|
*/
|
|
774
762
|
isWithdrawable(note: CloakNote): boolean;
|
|
775
763
|
/**
|
|
776
|
-
* Get Merkle proof for a leaf index
|
|
764
|
+
* Get Merkle proof for a leaf index directly from on-chain state
|
|
777
765
|
*
|
|
766
|
+
* @param connection - Solana connection
|
|
778
767
|
* @param leafIndex - Leaf index in tree
|
|
779
|
-
* @returns Merkle proof
|
|
768
|
+
* @returns Merkle proof computed from on-chain data
|
|
780
769
|
*/
|
|
781
|
-
getMerkleProof(leafIndex: number): Promise<MerkleProof>;
|
|
770
|
+
getMerkleProof(connection: Connection, leafIndex: number): Promise<MerkleProof>;
|
|
782
771
|
/**
|
|
783
|
-
* Get current Merkle root
|
|
772
|
+
* Get current Merkle root directly from on-chain state
|
|
784
773
|
*
|
|
785
|
-
* @
|
|
774
|
+
* @param connection - Solana connection
|
|
775
|
+
* @returns Current root hash from on-chain tree
|
|
786
776
|
*/
|
|
787
|
-
getCurrentRoot(): Promise<string>;
|
|
777
|
+
getCurrentRoot(connection: Connection): Promise<string>;
|
|
788
778
|
/**
|
|
789
779
|
* Get transaction status from relay service
|
|
790
780
|
*
|
|
@@ -792,47 +782,6 @@ declare class CloakSDK {
|
|
|
792
782
|
* @returns Current status
|
|
793
783
|
*/
|
|
794
784
|
getTransactionStatus(requestId: string): Promise<TxStatus>;
|
|
795
|
-
/**
|
|
796
|
-
* Recover a deposit that completed on-chain but failed to register
|
|
797
|
-
*
|
|
798
|
-
* Use this when a deposit transaction succeeded but the browser crashed
|
|
799
|
-
* or lost connection before the indexer registration completed.
|
|
800
|
-
*
|
|
801
|
-
* @param signature - Transaction signature
|
|
802
|
-
* @param commitment - Note commitment hash
|
|
803
|
-
* @param note - Optional: The full note if available
|
|
804
|
-
* @returns Recovery result with updated note
|
|
805
|
-
*
|
|
806
|
-
* @example
|
|
807
|
-
* ```typescript
|
|
808
|
-
* const result = await sdk.recoverDeposit({
|
|
809
|
-
* signature: "5Kn4...",
|
|
810
|
-
* commitment: "abc123...",
|
|
811
|
-
* note: myNote // optional if you have it
|
|
812
|
-
* });
|
|
813
|
-
*
|
|
814
|
-
* if (result.success) {
|
|
815
|
-
* console.log(`Recovered! Leaf index: ${result.leafIndex}`);
|
|
816
|
-
* }
|
|
817
|
-
* ```
|
|
818
|
-
*/
|
|
819
|
-
recoverDeposit(options: {
|
|
820
|
-
signature: string;
|
|
821
|
-
commitment: string;
|
|
822
|
-
note?: CloakNote;
|
|
823
|
-
onProgress?: (status: string) => void;
|
|
824
|
-
}): Promise<{
|
|
825
|
-
success: boolean;
|
|
826
|
-
leafIndex?: number;
|
|
827
|
-
root?: string;
|
|
828
|
-
slot?: number;
|
|
829
|
-
merkleProof?: {
|
|
830
|
-
pathElements: string[];
|
|
831
|
-
pathIndices: number[];
|
|
832
|
-
};
|
|
833
|
-
note?: CloakNote;
|
|
834
|
-
error?: string;
|
|
835
|
-
}>;
|
|
836
785
|
/**
|
|
837
786
|
* Load all notes from storage
|
|
838
787
|
*
|
|
@@ -870,29 +819,6 @@ declare class CloakSDK {
|
|
|
870
819
|
* Get the configuration
|
|
871
820
|
*/
|
|
872
821
|
getConfig(): CloakConfig;
|
|
873
|
-
/**
|
|
874
|
-
* Scan blockchain for notes belonging to this wallet (v2.0 feature)
|
|
875
|
-
*
|
|
876
|
-
* Requires Cloak keys to be configured in the SDK.
|
|
877
|
-
* Fetches encrypted outputs from the indexer and decrypts notes
|
|
878
|
-
* that belong to this wallet.
|
|
879
|
-
*
|
|
880
|
-
* @param options - Scanning options
|
|
881
|
-
* @returns Array of discovered notes with metadata
|
|
882
|
-
*
|
|
883
|
-
* @example
|
|
884
|
-
* ```typescript
|
|
885
|
-
* const notes = await sdk.scanNotes({
|
|
886
|
-
* onProgress: (current, total) => {
|
|
887
|
-
* console.log(`Scanning: ${current}/${total}`);
|
|
888
|
-
* }
|
|
889
|
-
* });
|
|
890
|
-
*
|
|
891
|
-
* console.log(`Found ${notes.length} notes!`);
|
|
892
|
-
* const totalBalance = notes.reduce((sum, n) => sum + n.amount, 0);
|
|
893
|
-
* ```
|
|
894
|
-
*/
|
|
895
|
-
scanNotes(options?: ScanNotesOptions): Promise<ScannedNote[]>;
|
|
896
822
|
/**
|
|
897
823
|
* Wrap errors with better categorization and user-friendly messages
|
|
898
824
|
*
|
|
@@ -965,6 +891,7 @@ declare function parseNote(jsonString: string): CloakNote;
|
|
|
965
891
|
declare function exportNote(note: CloakNote, pretty?: boolean): string;
|
|
966
892
|
/**
|
|
967
893
|
* Check if a note is withdrawable (has been deposited)
|
|
894
|
+
* Note: merkleProof is optional - it may be fetched lazily at withdrawal time
|
|
968
895
|
*/
|
|
969
896
|
declare function isWithdrawable(note: CloakNote): boolean;
|
|
970
897
|
/**
|
|
@@ -976,7 +903,7 @@ declare function updateNoteWithDeposit(note: CloakNote, depositInfo: {
|
|
|
976
903
|
slot: number;
|
|
977
904
|
leafIndex: number;
|
|
978
905
|
root: string;
|
|
979
|
-
merkleProof
|
|
906
|
+
merkleProof?: {
|
|
980
907
|
pathElements: string[];
|
|
981
908
|
pathIndices: number[];
|
|
982
909
|
};
|
|
@@ -1404,6 +1331,22 @@ declare function getAddressExplorerUrl(address: string, network?: Network): stri
|
|
|
1404
1331
|
* This is the single source of truth for error codes and messages.
|
|
1405
1332
|
*/
|
|
1406
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;
|
|
1407
1350
|
/**
|
|
1408
1351
|
* Shield Pool Program Error Codes
|
|
1409
1352
|
*
|
|
@@ -1453,125 +1396,71 @@ declare function createCloakError(error: unknown, _context: string): CloakError;
|
|
|
1453
1396
|
declare function formatErrorForLogging(error: unknown): string;
|
|
1454
1397
|
|
|
1455
1398
|
/**
|
|
1456
|
-
*
|
|
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
|
|
1415
|
+
*/
|
|
1416
|
+
declare function isDebugEnabled(): boolean;
|
|
1417
|
+
/**
|
|
1418
|
+
* Logger interface
|
|
1457
1419
|
*/
|
|
1458
|
-
interface
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
end: number;
|
|
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;
|
|
1464
1425
|
}
|
|
1465
1426
|
/**
|
|
1466
|
-
*
|
|
1427
|
+
* Create a logger for a specific module
|
|
1467
1428
|
*
|
|
1468
|
-
*
|
|
1469
|
-
*
|
|
1429
|
+
* @param module - Module name (e.g., "cloak::sdk", "cloak::indexer")
|
|
1430
|
+
* @returns Logger instance with debug, info, warn, error methods
|
|
1431
|
+
*
|
|
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
|
+
* ```
|
|
1470
1438
|
*/
|
|
1471
|
-
declare
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
*
|
|
1497
|
-
* @example
|
|
1498
|
-
* ```typescript
|
|
1499
|
-
* const proof = await indexer.getMerkleProof(42);
|
|
1500
|
-
* console.log(`Proof has ${proof.pathElements.length} siblings`);
|
|
1501
|
-
* ```
|
|
1502
|
-
*/
|
|
1503
|
-
getMerkleProof(leafIndex: number): Promise<MerkleProof>;
|
|
1504
|
-
/**
|
|
1505
|
-
* Get notes in a specific range
|
|
1506
|
-
*
|
|
1507
|
-
* Useful for scanning the tree or fetching notes in batches.
|
|
1508
|
-
*
|
|
1509
|
-
* @param start - Start index (inclusive)
|
|
1510
|
-
* @param end - End index (inclusive)
|
|
1511
|
-
* @param limit - Maximum number of notes to return (default: 100)
|
|
1512
|
-
* @returns Notes in the range
|
|
1513
|
-
*
|
|
1514
|
-
* @example
|
|
1515
|
-
* ```typescript
|
|
1516
|
-
* const { notes, has_more } = await indexer.getNotesRange(0, 99, 100);
|
|
1517
|
-
* console.log(`Fetched ${notes.length} notes`);
|
|
1518
|
-
* ```
|
|
1519
|
-
*/
|
|
1520
|
-
getNotesRange(start: number, end: number, limit?: number): Promise<NotesRangeResponse>;
|
|
1521
|
-
/**
|
|
1522
|
-
* Get all notes from the tree
|
|
1523
|
-
*
|
|
1524
|
-
* Fetches all notes in batches. Use with caution for large trees.
|
|
1525
|
-
*
|
|
1526
|
-
* @param batchSize - Size of each batch (default: 100)
|
|
1527
|
-
* @returns All encrypted notes
|
|
1528
|
-
*
|
|
1529
|
-
* @example
|
|
1530
|
-
* ```typescript
|
|
1531
|
-
* const allNotes = await indexer.getAllNotes();
|
|
1532
|
-
* console.log(`Total notes: ${allNotes.length}`);
|
|
1533
|
-
* ```
|
|
1534
|
-
*/
|
|
1535
|
-
getAllNotes(batchSize?: number): Promise<string[]>;
|
|
1536
|
-
/**
|
|
1537
|
-
* Submit a deposit to the indexer
|
|
1538
|
-
*
|
|
1539
|
-
* Registers a new deposit transaction with the indexer, which will
|
|
1540
|
-
* return the leaf index and current root.
|
|
1541
|
-
*
|
|
1542
|
-
* @param params - Deposit parameters
|
|
1543
|
-
* @returns Success response with leaf index and root
|
|
1544
|
-
*
|
|
1545
|
-
* @example
|
|
1546
|
-
* ```typescript
|
|
1547
|
-
* const result = await indexer.submitDeposit({
|
|
1548
|
-
* leafCommit: note.commitment,
|
|
1549
|
-
* encryptedOutput: btoa(JSON.stringify(noteData)),
|
|
1550
|
-
* txSignature: signature,
|
|
1551
|
-
* slot: txSlot
|
|
1552
|
-
* });
|
|
1553
|
-
* console.log(`Leaf index: ${result.leafIndex}`);
|
|
1554
|
-
* ```
|
|
1555
|
-
*/
|
|
1556
|
-
submitDeposit(params: {
|
|
1557
|
-
leafCommit: string;
|
|
1558
|
-
encryptedOutput: string;
|
|
1559
|
-
txSignature: string;
|
|
1560
|
-
slot: number;
|
|
1561
|
-
}): Promise<{
|
|
1562
|
-
success: boolean;
|
|
1563
|
-
leafIndex?: number;
|
|
1564
|
-
root?: string;
|
|
1565
|
-
}>;
|
|
1566
|
-
/**
|
|
1567
|
-
* Check indexer health
|
|
1568
|
-
*
|
|
1569
|
-
* @returns Health status
|
|
1570
|
-
*/
|
|
1571
|
-
healthCheck(): Promise<{
|
|
1572
|
-
status: string;
|
|
1573
|
-
}>;
|
|
1574
|
-
}
|
|
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;
|
|
1575
1464
|
|
|
1576
1465
|
/**
|
|
1577
1466
|
* Result from submitting a withdrawal that includes the request ID
|
|
@@ -1743,70 +1632,6 @@ declare class RelayService {
|
|
|
1743
1632
|
private sleep;
|
|
1744
1633
|
}
|
|
1745
1634
|
|
|
1746
|
-
/**
|
|
1747
|
-
* Deposit Recovery Service
|
|
1748
|
-
*
|
|
1749
|
-
* Handles recovery of deposits that completed on-chain but failed
|
|
1750
|
-
* to finalize with the indexer (e.g., browser crash, network failure)
|
|
1751
|
-
*/
|
|
1752
|
-
|
|
1753
|
-
interface RecoveryOptions {
|
|
1754
|
-
/** Transaction signature to recover */
|
|
1755
|
-
signature: string;
|
|
1756
|
-
/** Note commitment hash */
|
|
1757
|
-
commitment: string;
|
|
1758
|
-
/** Optional: The full note if available */
|
|
1759
|
-
note?: CloakNote;
|
|
1760
|
-
/** Callback for progress updates */
|
|
1761
|
-
onProgress?: (status: string) => void;
|
|
1762
|
-
}
|
|
1763
|
-
interface RecoveryResult {
|
|
1764
|
-
success: boolean;
|
|
1765
|
-
leafIndex?: number;
|
|
1766
|
-
root?: string;
|
|
1767
|
-
slot?: number;
|
|
1768
|
-
merkleProof?: {
|
|
1769
|
-
pathElements: string[];
|
|
1770
|
-
pathIndices: number[];
|
|
1771
|
-
};
|
|
1772
|
-
note?: CloakNote;
|
|
1773
|
-
error?: string;
|
|
1774
|
-
}
|
|
1775
|
-
/**
|
|
1776
|
-
* Service for recovering incomplete deposits
|
|
1777
|
-
*/
|
|
1778
|
-
declare class DepositRecoveryService {
|
|
1779
|
-
private indexer;
|
|
1780
|
-
private apiUrl;
|
|
1781
|
-
constructor(indexer: IndexerService, apiUrl: string);
|
|
1782
|
-
/**
|
|
1783
|
-
* Recover a deposit that completed on-chain but failed to register
|
|
1784
|
-
*
|
|
1785
|
-
* @param options Recovery options
|
|
1786
|
-
* @returns Recovery result with updated note
|
|
1787
|
-
*/
|
|
1788
|
-
recoverDeposit(options: RecoveryOptions): Promise<RecoveryResult>;
|
|
1789
|
-
/**
|
|
1790
|
-
* Check if a deposit already exists in the indexer
|
|
1791
|
-
* Uses the enhanced deposit lookup endpoint with include_proof=true
|
|
1792
|
-
*
|
|
1793
|
-
* @private
|
|
1794
|
-
*/
|
|
1795
|
-
private checkExistingDeposit;
|
|
1796
|
-
/**
|
|
1797
|
-
* Recover deposit by transaction signature
|
|
1798
|
-
* Uses the indexer's signature lookup endpoint
|
|
1799
|
-
*/
|
|
1800
|
-
recoverBySignature(signature: string): Promise<RecoveryResult>;
|
|
1801
|
-
/**
|
|
1802
|
-
* Finalize a deposit via server API (alternative recovery method)
|
|
1803
|
-
*
|
|
1804
|
-
* This method calls a server-side endpoint that can handle
|
|
1805
|
-
* the recovery process with elevated permissions.
|
|
1806
|
-
*/
|
|
1807
|
-
finalizeDepositViaServer(signature: string, commitment: string, encryptedOutput?: string): Promise<RecoveryResult>;
|
|
1808
|
-
}
|
|
1809
|
-
|
|
1810
1635
|
/**
|
|
1811
1636
|
* Encrypted Output Helpers
|
|
1812
1637
|
*
|
|
@@ -1870,7 +1695,7 @@ declare function keypairToAdapter(keypair: Keypair): WalletAdapter;
|
|
|
1870
1695
|
* Deposits SOL into the Cloak protocol by creating a commitment.
|
|
1871
1696
|
*
|
|
1872
1697
|
* Instruction format:
|
|
1873
|
-
* - Byte 0: Discriminant (
|
|
1698
|
+
* - Byte 0: Discriminant (0x01 for Deposit, per ShieldPoolInstruction enum)
|
|
1874
1699
|
* - Bytes 1-8: Amount (u64, little-endian)
|
|
1875
1700
|
* - Bytes 9-40: Commitment (32 bytes)
|
|
1876
1701
|
*
|
|
@@ -1950,6 +1775,59 @@ interface ShieldPoolPDAs {
|
|
|
1950
1775
|
*/
|
|
1951
1776
|
declare function getShieldPoolPDAs(programId?: PublicKey, mint?: PublicKey): ShieldPoolPDAs;
|
|
1952
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
|
+
|
|
1953
1831
|
/**
|
|
1954
1832
|
* Direct Circom WASM Proof Generation
|
|
1955
1833
|
*
|
|
@@ -2198,4 +2076,4 @@ declare function cleanupStalePendingOperations(maxAgeMs?: number): {
|
|
|
2198
2076
|
|
|
2199
2077
|
declare const VERSION = "1.0.0";
|
|
2200
2078
|
|
|
2201
|
-
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 };
|