@cloak.dev/sdk 0.2.3-staging.c0accd1 → 0.2.3-staging.fdea6cd
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/index.cjs +81 -8
- package/dist/index.d.cts +8 -19
- package/dist/index.d.ts +8 -19
- package/dist/index.js +81 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -4269,6 +4269,23 @@ async function readMerkleTreeState(connection, merkleTreePDA, forceConfirmed = f
|
|
|
4269
4269
|
const finalRoot = root || rpcRoot;
|
|
4270
4270
|
return { nextIndex, root: finalRoot, subtrees };
|
|
4271
4271
|
}
|
|
4272
|
+
function nearTipProofUndecidableLevels(leafIndex, nextIndex, height = MERKLE_TREE_HEIGHT) {
|
|
4273
|
+
if (!Number.isInteger(leafIndex) || !Number.isInteger(nextIndex) || !Number.isInteger(height)) {
|
|
4274
|
+
throw new Error(`nearTipProofUndecidableLevels: integers required (leafIndex=${leafIndex}, nextIndex=${nextIndex}, height=${height})`);
|
|
4275
|
+
}
|
|
4276
|
+
if (leafIndex < 0 || leafIndex >= nextIndex) {
|
|
4277
|
+
throw new Error(`Leaf index ${leafIndex} is not below next_index ${nextIndex}`);
|
|
4278
|
+
}
|
|
4279
|
+
const levels = [];
|
|
4280
|
+
for (let level = 0; level < height; level++) {
|
|
4281
|
+
const width = 2 ** level;
|
|
4282
|
+
const ancestor = Math.floor(leafIndex / width);
|
|
4283
|
+
if (ancestor % 2 === 1 && (ancestor + 1) * width < nextIndex) {
|
|
4284
|
+
levels.push(level);
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4287
|
+
return levels;
|
|
4288
|
+
}
|
|
4272
4289
|
async function computeProofFromChain(connection, merkleTreePDA, leafIndex, forceConfirmed = false) {
|
|
4273
4290
|
assertAllowedRpcConnection(connection);
|
|
4274
4291
|
await ensureZeroValues();
|
|
@@ -4301,7 +4318,12 @@ async function computeProofFromChain(connection, merkleTreePDA, leafIndex, force
|
|
|
4301
4318
|
}
|
|
4302
4319
|
index = Math.floor(index / 2);
|
|
4303
4320
|
}
|
|
4304
|
-
return {
|
|
4321
|
+
return {
|
|
4322
|
+
pathElements,
|
|
4323
|
+
pathIndices,
|
|
4324
|
+
root,
|
|
4325
|
+
undecidableLevels: nearTipProofUndecidableLevels(leafIndex, nextIndex)
|
|
4326
|
+
};
|
|
4305
4327
|
}
|
|
4306
4328
|
async function computeProofForLatestDeposit(connection, merkleTreePDA) {
|
|
4307
4329
|
assertAllowedRpcConnection(connection);
|
|
@@ -4312,7 +4334,7 @@ async function computeProofForLatestDeposit(connection, merkleTreePDA) {
|
|
|
4312
4334
|
}
|
|
4313
4335
|
const leafIndex = nextIndex - 1;
|
|
4314
4336
|
const proof = await computeProofInternal(leafIndex, nextIndex, subtrees);
|
|
4315
|
-
return { ...proof, root, leafIndex };
|
|
4337
|
+
return { ...proof, root, leafIndex, undecidableLevels: [] };
|
|
4316
4338
|
}
|
|
4317
4339
|
async function computeProofInternal(leafIndex, _nextIndex, subtrees) {
|
|
4318
4340
|
const pathElements = [];
|
|
@@ -4620,6 +4642,9 @@ function isBrowserLike() {
|
|
|
4620
4642
|
return typeof globalThis !== "undefined" && (typeof globalThis.window !== "undefined" || typeof globalThis.document !== "undefined");
|
|
4621
4643
|
}
|
|
4622
4644
|
|
|
4645
|
+
// src/config/transaction-version.ts
|
|
4646
|
+
var MAX_SUPPORTED_TRANSACTION_VERSION = 1;
|
|
4647
|
+
|
|
4623
4648
|
// src/relay/client.ts
|
|
4624
4649
|
var bs58 = import_bs58.default.default || import_bs58.default;
|
|
4625
4650
|
var TRANSACT_TAG = 0;
|
|
@@ -4831,7 +4856,7 @@ async function buildMerkleTreeFromChain(connection, programId, merkleTree, onPro
|
|
|
4831
4856
|
}
|
|
4832
4857
|
const signature = signatures[i];
|
|
4833
4858
|
const tx = await connection.getParsedTransaction(signature, {
|
|
4834
|
-
maxSupportedTransactionVersion:
|
|
4859
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION,
|
|
4835
4860
|
commitment: "confirmed"
|
|
4836
4861
|
});
|
|
4837
4862
|
if (!tx || tx.meta?.err) continue;
|
|
@@ -5465,7 +5490,7 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options
|
|
|
5465
5490
|
try {
|
|
5466
5491
|
return await connection.getTransaction(signature, {
|
|
5467
5492
|
commitment: "confirmed",
|
|
5468
|
-
maxSupportedTransactionVersion:
|
|
5493
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
5469
5494
|
});
|
|
5470
5495
|
} catch {
|
|
5471
5496
|
return null;
|
|
@@ -8242,6 +8267,29 @@ async function transact(params, options) {
|
|
|
8242
8267
|
"Merkle tree unavailable from relay/indexer; using on-chain proof fallback (may require retries under high churn)"
|
|
8243
8268
|
);
|
|
8244
8269
|
}
|
|
8270
|
+
if (needsTreeForProof && treeState) {
|
|
8271
|
+
const tip = treeState.nextIndex;
|
|
8272
|
+
const unprovable = paddedInputs.filter((utxo) => {
|
|
8273
|
+
if (utxo.amount === BigInt(0) || utxo.index === void 0 || utxo.index < 0) return false;
|
|
8274
|
+
if (merkleTree && utxo.index < merkleTree.length) return false;
|
|
8275
|
+
if (utxo.index >= tip) return false;
|
|
8276
|
+
const canFillLevel0 = useSiblingInfo && (!!utxo.siblingCommitment || !!utxo.leftSiblingCommitment);
|
|
8277
|
+
return nearTipProofUndecidableLevels(utxo.index, tip).some((level) => level !== 0 || !canFillLevel0);
|
|
8278
|
+
});
|
|
8279
|
+
if (unprovable.length > 0) {
|
|
8280
|
+
onProgress?.(
|
|
8281
|
+
`On-chain frontier can no longer prove leaf ${unprovable.map((u) => u.index).join(", ")} (a later leaf overwrote a frontier level on its path); rebuilding the full tree from chain...`
|
|
8282
|
+
);
|
|
8283
|
+
forceChainIndexing = true;
|
|
8284
|
+
try {
|
|
8285
|
+
merkleTree = await buildMerkleTreeFromChain(connection, programId, pdas.merkleTree, onProgress, mint);
|
|
8286
|
+
} catch (e) {
|
|
8287
|
+
onProgress?.(
|
|
8288
|
+
`Failed to rebuild the tree from chain (${e instanceof Error ? e.message : String(e)}); continuing with the on-chain proof fallback.`
|
|
8289
|
+
);
|
|
8290
|
+
}
|
|
8291
|
+
}
|
|
8292
|
+
}
|
|
8245
8293
|
const merkleProofs = [];
|
|
8246
8294
|
let resolvedRootHex = treeState?.root ?? "0";
|
|
8247
8295
|
let proofRootHex = null;
|
|
@@ -9526,6 +9574,29 @@ async function swapUtxo(params, options) {
|
|
|
9526
9574
|
"Merkle tree unavailable from relay/indexer; using on-chain proof fallback (may require retries under high churn)"
|
|
9527
9575
|
);
|
|
9528
9576
|
}
|
|
9577
|
+
if (needsTreeForProof && merkleState) {
|
|
9578
|
+
const tip = merkleState.nextIndex;
|
|
9579
|
+
const unprovable = paddedInputs.filter((utxo) => {
|
|
9580
|
+
if (utxo.amount === BigInt(0) || utxo.index === void 0 || utxo.index < 0) return false;
|
|
9581
|
+
if (merkleTree && utxo.index < merkleTree.length) return false;
|
|
9582
|
+
if (utxo.index >= tip) return false;
|
|
9583
|
+
const canFillLevel0 = useSiblingInfo && (!!utxo.siblingCommitment || !!utxo.leftSiblingCommitment);
|
|
9584
|
+
return nearTipProofUndecidableLevels(utxo.index, tip).some((level) => level !== 0 || !canFillLevel0);
|
|
9585
|
+
});
|
|
9586
|
+
if (unprovable.length > 0) {
|
|
9587
|
+
onProgress?.(
|
|
9588
|
+
`On-chain frontier can no longer prove leaf ${unprovable.map((u) => u.index).join(", ")} (a later leaf overwrote a frontier level on its path); rebuilding the full tree from chain...`
|
|
9589
|
+
);
|
|
9590
|
+
forceChainIndexing = true;
|
|
9591
|
+
try {
|
|
9592
|
+
merkleTree = await buildMerkleTreeFromChain(connection, programId, pdas.merkleTree, onProgress, NATIVE_SOL_MINT);
|
|
9593
|
+
} catch (e) {
|
|
9594
|
+
onProgress?.(
|
|
9595
|
+
`Failed to rebuild the tree from chain (${e instanceof Error ? e.message : String(e)}); continuing with the on-chain proof fallback.`
|
|
9596
|
+
);
|
|
9597
|
+
}
|
|
9598
|
+
}
|
|
9599
|
+
}
|
|
9529
9600
|
const merkleProofs = [];
|
|
9530
9601
|
let resolvedRootHex = merkleState?.root ?? "0";
|
|
9531
9602
|
let proofRootHex = null;
|
|
@@ -10962,7 +11033,7 @@ async function scanSwapNoteCarriers(connection, programId, viewingKeyNk, swapCtx
|
|
|
10962
11033
|
tx = await withRpcRetry(
|
|
10963
11034
|
() => connection.getTransaction(si.signature, {
|
|
10964
11035
|
commitment: "confirmed",
|
|
10965
|
-
maxSupportedTransactionVersion:
|
|
11036
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
10966
11037
|
})
|
|
10967
11038
|
);
|
|
10968
11039
|
} catch {
|
|
@@ -11063,7 +11134,7 @@ async function scanRecipientDeliveryNotes(opts) {
|
|
|
11063
11134
|
tx = await withRpcRetry(
|
|
11064
11135
|
() => connection.getTransaction(si.signature, {
|
|
11065
11136
|
commitment: "confirmed",
|
|
11066
|
-
maxSupportedTransactionVersion:
|
|
11137
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
11067
11138
|
})
|
|
11068
11139
|
);
|
|
11069
11140
|
} catch {
|
|
@@ -11234,7 +11305,7 @@ async function scanTransactions(opts) {
|
|
|
11234
11305
|
return await withRpcRetry(
|
|
11235
11306
|
() => connection.getTransaction(sigInfo.signature, {
|
|
11236
11307
|
commitment: "confirmed",
|
|
11237
|
-
maxSupportedTransactionVersion:
|
|
11308
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
11238
11309
|
})
|
|
11239
11310
|
);
|
|
11240
11311
|
} catch {
|
|
@@ -12453,7 +12524,9 @@ async function listBridgeDeposits(conn, nk, opts) {
|
|
|
12453
12524
|
const sigs = await conn.getSignaturesForAddress(receiver, { limit: 20 });
|
|
12454
12525
|
for (const s of sigs) {
|
|
12455
12526
|
if (s.err) continue;
|
|
12456
|
-
const tx = await conn.getTransaction(s.signature, {
|
|
12527
|
+
const tx = await conn.getTransaction(s.signature, {
|
|
12528
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
12529
|
+
});
|
|
12457
12530
|
const keys = tx?.transaction.message.getAccountKeys({
|
|
12458
12531
|
accountKeysFromLookups: tx.meta?.loadedAddresses
|
|
12459
12532
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -2522,6 +2522,14 @@ interface OnchainMerkleProof {
|
|
|
2522
2522
|
pathElements: string[];
|
|
2523
2523
|
pathIndices: number[];
|
|
2524
2524
|
root: string;
|
|
2525
|
+
/**
|
|
2526
|
+
* Levels whose sibling could NOT be taken from the current frontier; see
|
|
2527
|
+
* {@link nearTipProofUndecidableLevels}. Empty means the path reproduces the root the program
|
|
2528
|
+
* stored when this leaf was appended. Level 0 alone is recoverable by a caller that knows the
|
|
2529
|
+
* left neighbour's commitment (`leftSiblingCommitment` / `siblingCommitment`); any other level
|
|
2530
|
+
* is not, and the caller must rebuild the full tree instead of submitting the path.
|
|
2531
|
+
*/
|
|
2532
|
+
undecidableLevels: number[];
|
|
2525
2533
|
}
|
|
2526
2534
|
interface MerkleTreeState {
|
|
2527
2535
|
nextIndex: number;
|
|
@@ -2537,25 +2545,6 @@ interface MerkleTreeState {
|
|
|
2537
2545
|
declare function readMerkleTreeState(connection: Connection, merkleTreePDA: PublicKey, forceConfirmed?: boolean, relayUrl?: string,
|
|
2538
2546
|
/** When true, skip relay root and use chain directly (avoids stale relay root causing ProofInvalid) */
|
|
2539
2547
|
skipRelayRoot?: boolean, mint?: PublicKey): Promise<MerkleTreeState>;
|
|
2540
|
-
/**
|
|
2541
|
-
* Compute Merkle proof for a leaf at a given index using on-chain state
|
|
2542
|
-
*
|
|
2543
|
-
* This works by:
|
|
2544
|
-
* 1. Reading the subtrees (frontier) from the on-chain account
|
|
2545
|
-
* 2. For each level, determining the sibling:
|
|
2546
|
-
* - If index is odd: sibling is the stored subtree (left sibling)
|
|
2547
|
-
* - If index is even: sibling is either a subsequent subtree or zero value
|
|
2548
|
-
*
|
|
2549
|
-
* Note: This works best for recent leaves where siblings are zero values.
|
|
2550
|
-
* For older leaves with non-zero siblings that aren't stored in subtrees,
|
|
2551
|
-
* an indexer may still be needed.
|
|
2552
|
-
*
|
|
2553
|
-
* @param connection - Solana connection
|
|
2554
|
-
* @param merkleTreePDA - PDA of the merkle tree account
|
|
2555
|
-
* @param leafIndex - Index of the leaf to compute proof for
|
|
2556
|
-
* @param forceConfirmed - If true, forces "confirmed" commitment level for fresh data
|
|
2557
|
-
* @returns Merkle proof with path elements and indices
|
|
2558
|
-
*/
|
|
2559
2548
|
declare function computeProofFromChain(connection: Connection, merkleTreePDA: PublicKey, leafIndex: number, forceConfirmed?: boolean): Promise<OnchainMerkleProof>;
|
|
2560
2549
|
/**
|
|
2561
2550
|
* Compute proof for the most recently inserted leaf
|
package/dist/index.d.ts
CHANGED
|
@@ -2522,6 +2522,14 @@ interface OnchainMerkleProof {
|
|
|
2522
2522
|
pathElements: string[];
|
|
2523
2523
|
pathIndices: number[];
|
|
2524
2524
|
root: string;
|
|
2525
|
+
/**
|
|
2526
|
+
* Levels whose sibling could NOT be taken from the current frontier; see
|
|
2527
|
+
* {@link nearTipProofUndecidableLevels}. Empty means the path reproduces the root the program
|
|
2528
|
+
* stored when this leaf was appended. Level 0 alone is recoverable by a caller that knows the
|
|
2529
|
+
* left neighbour's commitment (`leftSiblingCommitment` / `siblingCommitment`); any other level
|
|
2530
|
+
* is not, and the caller must rebuild the full tree instead of submitting the path.
|
|
2531
|
+
*/
|
|
2532
|
+
undecidableLevels: number[];
|
|
2525
2533
|
}
|
|
2526
2534
|
interface MerkleTreeState {
|
|
2527
2535
|
nextIndex: number;
|
|
@@ -2537,25 +2545,6 @@ interface MerkleTreeState {
|
|
|
2537
2545
|
declare function readMerkleTreeState(connection: Connection, merkleTreePDA: PublicKey, forceConfirmed?: boolean, relayUrl?: string,
|
|
2538
2546
|
/** When true, skip relay root and use chain directly (avoids stale relay root causing ProofInvalid) */
|
|
2539
2547
|
skipRelayRoot?: boolean, mint?: PublicKey): Promise<MerkleTreeState>;
|
|
2540
|
-
/**
|
|
2541
|
-
* Compute Merkle proof for a leaf at a given index using on-chain state
|
|
2542
|
-
*
|
|
2543
|
-
* This works by:
|
|
2544
|
-
* 1. Reading the subtrees (frontier) from the on-chain account
|
|
2545
|
-
* 2. For each level, determining the sibling:
|
|
2546
|
-
* - If index is odd: sibling is the stored subtree (left sibling)
|
|
2547
|
-
* - If index is even: sibling is either a subsequent subtree or zero value
|
|
2548
|
-
*
|
|
2549
|
-
* Note: This works best for recent leaves where siblings are zero values.
|
|
2550
|
-
* For older leaves with non-zero siblings that aren't stored in subtrees,
|
|
2551
|
-
* an indexer may still be needed.
|
|
2552
|
-
*
|
|
2553
|
-
* @param connection - Solana connection
|
|
2554
|
-
* @param merkleTreePDA - PDA of the merkle tree account
|
|
2555
|
-
* @param leafIndex - Index of the leaf to compute proof for
|
|
2556
|
-
* @param forceConfirmed - If true, forces "confirmed" commitment level for fresh data
|
|
2557
|
-
* @returns Merkle proof with path elements and indices
|
|
2558
|
-
*/
|
|
2559
2548
|
declare function computeProofFromChain(connection: Connection, merkleTreePDA: PublicKey, leafIndex: number, forceConfirmed?: boolean): Promise<OnchainMerkleProof>;
|
|
2560
2549
|
/**
|
|
2561
2550
|
* Compute proof for the most recently inserted leaf
|
package/dist/index.js
CHANGED
|
@@ -3446,6 +3446,23 @@ async function readMerkleTreeState(connection, merkleTreePDA, forceConfirmed = f
|
|
|
3446
3446
|
const finalRoot = root || rpcRoot;
|
|
3447
3447
|
return { nextIndex, root: finalRoot, subtrees };
|
|
3448
3448
|
}
|
|
3449
|
+
function nearTipProofUndecidableLevels(leafIndex, nextIndex, height = MERKLE_TREE_HEIGHT) {
|
|
3450
|
+
if (!Number.isInteger(leafIndex) || !Number.isInteger(nextIndex) || !Number.isInteger(height)) {
|
|
3451
|
+
throw new Error(`nearTipProofUndecidableLevels: integers required (leafIndex=${leafIndex}, nextIndex=${nextIndex}, height=${height})`);
|
|
3452
|
+
}
|
|
3453
|
+
if (leafIndex < 0 || leafIndex >= nextIndex) {
|
|
3454
|
+
throw new Error(`Leaf index ${leafIndex} is not below next_index ${nextIndex}`);
|
|
3455
|
+
}
|
|
3456
|
+
const levels = [];
|
|
3457
|
+
for (let level = 0; level < height; level++) {
|
|
3458
|
+
const width = 2 ** level;
|
|
3459
|
+
const ancestor = Math.floor(leafIndex / width);
|
|
3460
|
+
if (ancestor % 2 === 1 && (ancestor + 1) * width < nextIndex) {
|
|
3461
|
+
levels.push(level);
|
|
3462
|
+
}
|
|
3463
|
+
}
|
|
3464
|
+
return levels;
|
|
3465
|
+
}
|
|
3449
3466
|
async function computeProofFromChain(connection, merkleTreePDA, leafIndex, forceConfirmed = false) {
|
|
3450
3467
|
assertAllowedRpcConnection(connection);
|
|
3451
3468
|
await ensureZeroValues();
|
|
@@ -3478,7 +3495,12 @@ async function computeProofFromChain(connection, merkleTreePDA, leafIndex, force
|
|
|
3478
3495
|
}
|
|
3479
3496
|
index = Math.floor(index / 2);
|
|
3480
3497
|
}
|
|
3481
|
-
return {
|
|
3498
|
+
return {
|
|
3499
|
+
pathElements,
|
|
3500
|
+
pathIndices,
|
|
3501
|
+
root,
|
|
3502
|
+
undecidableLevels: nearTipProofUndecidableLevels(leafIndex, nextIndex)
|
|
3503
|
+
};
|
|
3482
3504
|
}
|
|
3483
3505
|
async function computeProofForLatestDeposit(connection, merkleTreePDA) {
|
|
3484
3506
|
assertAllowedRpcConnection(connection);
|
|
@@ -3489,7 +3511,7 @@ async function computeProofForLatestDeposit(connection, merkleTreePDA) {
|
|
|
3489
3511
|
}
|
|
3490
3512
|
const leafIndex = nextIndex - 1;
|
|
3491
3513
|
const proof = await computeProofInternal(leafIndex, nextIndex, subtrees);
|
|
3492
|
-
return { ...proof, root, leafIndex };
|
|
3514
|
+
return { ...proof, root, leafIndex, undecidableLevels: [] };
|
|
3493
3515
|
}
|
|
3494
3516
|
async function computeProofInternal(leafIndex, _nextIndex, subtrees) {
|
|
3495
3517
|
const pathElements = [];
|
|
@@ -3797,6 +3819,9 @@ function isBrowserLike() {
|
|
|
3797
3819
|
return typeof globalThis !== "undefined" && (typeof globalThis.window !== "undefined" || typeof globalThis.document !== "undefined");
|
|
3798
3820
|
}
|
|
3799
3821
|
|
|
3822
|
+
// src/config/transaction-version.ts
|
|
3823
|
+
var MAX_SUPPORTED_TRANSACTION_VERSION = 1;
|
|
3824
|
+
|
|
3800
3825
|
// src/relay/client.ts
|
|
3801
3826
|
var bs58 = _bs58.default || _bs58;
|
|
3802
3827
|
var TRANSACT_TAG = 0;
|
|
@@ -4008,7 +4033,7 @@ async function buildMerkleTreeFromChain(connection, programId, merkleTree, onPro
|
|
|
4008
4033
|
}
|
|
4009
4034
|
const signature = signatures[i];
|
|
4010
4035
|
const tx = await connection.getParsedTransaction(signature, {
|
|
4011
|
-
maxSupportedTransactionVersion:
|
|
4036
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION,
|
|
4012
4037
|
commitment: "confirmed"
|
|
4013
4038
|
});
|
|
4014
4039
|
if (!tx || tx.meta?.err) continue;
|
|
@@ -4656,7 +4681,7 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options
|
|
|
4656
4681
|
try {
|
|
4657
4682
|
return await connection.getTransaction(signature, {
|
|
4658
4683
|
commitment: "confirmed",
|
|
4659
|
-
maxSupportedTransactionVersion:
|
|
4684
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
4660
4685
|
});
|
|
4661
4686
|
} catch {
|
|
4662
4687
|
return null;
|
|
@@ -7428,6 +7453,29 @@ async function transact(params, options) {
|
|
|
7428
7453
|
"Merkle tree unavailable from relay/indexer; using on-chain proof fallback (may require retries under high churn)"
|
|
7429
7454
|
);
|
|
7430
7455
|
}
|
|
7456
|
+
if (needsTreeForProof && treeState) {
|
|
7457
|
+
const tip = treeState.nextIndex;
|
|
7458
|
+
const unprovable = paddedInputs.filter((utxo) => {
|
|
7459
|
+
if (utxo.amount === BigInt(0) || utxo.index === void 0 || utxo.index < 0) return false;
|
|
7460
|
+
if (merkleTree && utxo.index < merkleTree.length) return false;
|
|
7461
|
+
if (utxo.index >= tip) return false;
|
|
7462
|
+
const canFillLevel0 = useSiblingInfo && (!!utxo.siblingCommitment || !!utxo.leftSiblingCommitment);
|
|
7463
|
+
return nearTipProofUndecidableLevels(utxo.index, tip).some((level) => level !== 0 || !canFillLevel0);
|
|
7464
|
+
});
|
|
7465
|
+
if (unprovable.length > 0) {
|
|
7466
|
+
onProgress?.(
|
|
7467
|
+
`On-chain frontier can no longer prove leaf ${unprovable.map((u) => u.index).join(", ")} (a later leaf overwrote a frontier level on its path); rebuilding the full tree from chain...`
|
|
7468
|
+
);
|
|
7469
|
+
forceChainIndexing = true;
|
|
7470
|
+
try {
|
|
7471
|
+
merkleTree = await buildMerkleTreeFromChain(connection, programId, pdas.merkleTree, onProgress, mint);
|
|
7472
|
+
} catch (e) {
|
|
7473
|
+
onProgress?.(
|
|
7474
|
+
`Failed to rebuild the tree from chain (${e instanceof Error ? e.message : String(e)}); continuing with the on-chain proof fallback.`
|
|
7475
|
+
);
|
|
7476
|
+
}
|
|
7477
|
+
}
|
|
7478
|
+
}
|
|
7431
7479
|
const merkleProofs = [];
|
|
7432
7480
|
let resolvedRootHex = treeState?.root ?? "0";
|
|
7433
7481
|
let proofRootHex = null;
|
|
@@ -8712,6 +8760,29 @@ async function swapUtxo(params, options) {
|
|
|
8712
8760
|
"Merkle tree unavailable from relay/indexer; using on-chain proof fallback (may require retries under high churn)"
|
|
8713
8761
|
);
|
|
8714
8762
|
}
|
|
8763
|
+
if (needsTreeForProof && merkleState) {
|
|
8764
|
+
const tip = merkleState.nextIndex;
|
|
8765
|
+
const unprovable = paddedInputs.filter((utxo) => {
|
|
8766
|
+
if (utxo.amount === BigInt(0) || utxo.index === void 0 || utxo.index < 0) return false;
|
|
8767
|
+
if (merkleTree && utxo.index < merkleTree.length) return false;
|
|
8768
|
+
if (utxo.index >= tip) return false;
|
|
8769
|
+
const canFillLevel0 = useSiblingInfo && (!!utxo.siblingCommitment || !!utxo.leftSiblingCommitment);
|
|
8770
|
+
return nearTipProofUndecidableLevels(utxo.index, tip).some((level) => level !== 0 || !canFillLevel0);
|
|
8771
|
+
});
|
|
8772
|
+
if (unprovable.length > 0) {
|
|
8773
|
+
onProgress?.(
|
|
8774
|
+
`On-chain frontier can no longer prove leaf ${unprovable.map((u) => u.index).join(", ")} (a later leaf overwrote a frontier level on its path); rebuilding the full tree from chain...`
|
|
8775
|
+
);
|
|
8776
|
+
forceChainIndexing = true;
|
|
8777
|
+
try {
|
|
8778
|
+
merkleTree = await buildMerkleTreeFromChain(connection, programId, pdas.merkleTree, onProgress, NATIVE_SOL_MINT);
|
|
8779
|
+
} catch (e) {
|
|
8780
|
+
onProgress?.(
|
|
8781
|
+
`Failed to rebuild the tree from chain (${e instanceof Error ? e.message : String(e)}); continuing with the on-chain proof fallback.`
|
|
8782
|
+
);
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
}
|
|
8715
8786
|
const merkleProofs = [];
|
|
8716
8787
|
let resolvedRootHex = merkleState?.root ?? "0";
|
|
8717
8788
|
let proofRootHex = null;
|
|
@@ -10145,7 +10216,7 @@ async function scanSwapNoteCarriers(connection, programId, viewingKeyNk, swapCtx
|
|
|
10145
10216
|
tx = await withRpcRetry(
|
|
10146
10217
|
() => connection.getTransaction(si.signature, {
|
|
10147
10218
|
commitment: "confirmed",
|
|
10148
|
-
maxSupportedTransactionVersion:
|
|
10219
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
10149
10220
|
})
|
|
10150
10221
|
);
|
|
10151
10222
|
} catch {
|
|
@@ -10246,7 +10317,7 @@ async function scanRecipientDeliveryNotes(opts) {
|
|
|
10246
10317
|
tx = await withRpcRetry(
|
|
10247
10318
|
() => connection.getTransaction(si.signature, {
|
|
10248
10319
|
commitment: "confirmed",
|
|
10249
|
-
maxSupportedTransactionVersion:
|
|
10320
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
10250
10321
|
})
|
|
10251
10322
|
);
|
|
10252
10323
|
} catch {
|
|
@@ -10417,7 +10488,7 @@ async function scanTransactions(opts) {
|
|
|
10417
10488
|
return await withRpcRetry(
|
|
10418
10489
|
() => connection.getTransaction(sigInfo.signature, {
|
|
10419
10490
|
commitment: "confirmed",
|
|
10420
|
-
maxSupportedTransactionVersion:
|
|
10491
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
10421
10492
|
})
|
|
10422
10493
|
);
|
|
10423
10494
|
} catch {
|
|
@@ -11640,7 +11711,9 @@ async function listBridgeDeposits(conn, nk, opts) {
|
|
|
11640
11711
|
const sigs = await conn.getSignaturesForAddress(receiver, { limit: 20 });
|
|
11641
11712
|
for (const s of sigs) {
|
|
11642
11713
|
if (s.err) continue;
|
|
11643
|
-
const tx = await conn.getTransaction(s.signature, {
|
|
11714
|
+
const tx = await conn.getTransaction(s.signature, {
|
|
11715
|
+
maxSupportedTransactionVersion: MAX_SUPPORTED_TRANSACTION_VERSION
|
|
11716
|
+
});
|
|
11644
11717
|
const keys = tx?.transaction.message.getAccountKeys({
|
|
11645
11718
|
accountKeysFromLookups: tx.meta?.loadedAddresses
|
|
11646
11719
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloak.dev/sdk",
|
|
3
3
|
"description": "Shield, send, and swap on Solana privately — TypeScript SDK with UTXO-based zero-knowledge transactions",
|
|
4
|
-
"version": "0.2.3-staging.
|
|
4
|
+
"version": "0.2.3-staging.fdea6cd",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"@lightprotocol/hasher.rs": "^0.2.1",
|
|
66
66
|
"@noble/hashes": "^1.8.0",
|
|
67
67
|
"@solana/spl-token": "0.4.14",
|
|
68
|
-
"@solana/web3.js": "
|
|
68
|
+
"@solana/web3.js": "1.99.0",
|
|
69
69
|
"bs58": "^6.0.0",
|
|
70
70
|
"circomlibjs": "0.1.7",
|
|
71
71
|
"ffjavascript": "^0.3.0",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@switchboard-xyz/common": "^5.6.1",
|
|
90
90
|
"@switchboard-xyz/on-demand": "^3.8.2",
|
|
91
91
|
"@solana/spl-token": ">=0.4.9",
|
|
92
|
-
"@solana/web3.js": ">=1.
|
|
92
|
+
"@solana/web3.js": ">=1.99.0"
|
|
93
93
|
},
|
|
94
94
|
"peerDependenciesMeta": {
|
|
95
95
|
"@switchboard-xyz/common": {
|