@cloak.dev/sdk 0.2.6-staging.abb3ae6 → 0.2.6-staging.d98da76
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 +100 -11
- package/dist/index.d.cts +66 -29
- package/dist/index.d.ts +66 -29
- package/dist/index.js +99 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -723,6 +723,7 @@ __export(index_exports, {
|
|
|
723
723
|
deriveSpendKey: () => deriveSpendKey,
|
|
724
724
|
deriveSwapRefundAuthorization: () => deriveSwapRefundAuthorization,
|
|
725
725
|
deriveSwapRefundBlinding: () => deriveSwapRefundBlinding,
|
|
726
|
+
deriveSwapRefundKeypair: () => deriveSwapRefundKeypair,
|
|
726
727
|
deriveUserCompliancePublicKey: () => deriveUserCompliancePublicKey,
|
|
727
728
|
deriveUserComplianceScalar: () => deriveUserComplianceScalar,
|
|
728
729
|
deriveUtxoKeypairFromSpendKey: () => deriveUtxoKeypairFromSpendKey,
|
|
@@ -6053,6 +6054,8 @@ function normalizeOwnerPublicKey(publicKey, label) {
|
|
|
6053
6054
|
init_inputs();
|
|
6054
6055
|
var bs582 = import_bs582.default.default || import_bs582.default;
|
|
6055
6056
|
var REFUND_SEED_DOMAIN = new TextEncoder().encode("cloak_swap_refund_v1");
|
|
6057
|
+
var REFUND_KEY_DOMAIN_V2 = new TextEncoder().encode("cloak_swap_refund_v2");
|
|
6058
|
+
var REFUND_PRIVATE_KEY_INFO_V2 = new TextEncoder().encode("sk_v2");
|
|
6056
6059
|
var LEGACY_REFUND_PRIVATE_KEY_INFO = new TextEncoder().encode("sk");
|
|
6057
6060
|
var REFUND_BLINDING_INFO = new TextEncoder().encode("blinding");
|
|
6058
6061
|
function normalizeNullifier(inputNullifier) {
|
|
@@ -6097,13 +6100,35 @@ function deriveSwapRefundBlinding(viewingKeyNk, inputNullifier) {
|
|
|
6097
6100
|
const nk = assertNk(viewingKeyNk);
|
|
6098
6101
|
return toFieldSecret(derive(nk, normalizeNullifier(inputNullifier), REFUND_BLINDING_INFO));
|
|
6099
6102
|
}
|
|
6100
|
-
|
|
6103
|
+
function privateKeyBytes(privateKey) {
|
|
6104
|
+
return Uint8Array.from(Buffer.from(privateKey.toString(16).padStart(64, "0"), "hex"));
|
|
6105
|
+
}
|
|
6106
|
+
async function deriveSwapRefundKeypair(ownerUtxoKeypair, inputNullifier) {
|
|
6101
6107
|
const owner = await assertOwnerUtxoKeypair(ownerUtxoKeypair);
|
|
6108
|
+
const nullifier = normalizeNullifier(inputNullifier);
|
|
6109
|
+
const preimage = new Uint8Array(
|
|
6110
|
+
REFUND_KEY_DOMAIN_V2.length + 32 + nullifier.length + REFUND_PRIVATE_KEY_INFO_V2.length
|
|
6111
|
+
);
|
|
6112
|
+
let off = 0;
|
|
6113
|
+
preimage.set(REFUND_KEY_DOMAIN_V2, off);
|
|
6114
|
+
off += REFUND_KEY_DOMAIN_V2.length;
|
|
6115
|
+
preimage.set(privateKeyBytes(owner.privateKey), off);
|
|
6116
|
+
off += 32;
|
|
6117
|
+
preimage.set(nullifier, off);
|
|
6118
|
+
off += nullifier.length;
|
|
6119
|
+
preimage.set(REFUND_PRIVATE_KEY_INFO_V2, off);
|
|
6120
|
+
const privateKey = toFieldSecret((0, import_blake34.blake3)(preimage));
|
|
6121
|
+
const publicKey = await derivePublicKey(privateKey);
|
|
6122
|
+
if (publicKey === 0n) throw new Error("refund authorization is degenerate");
|
|
6123
|
+
return { privateKey, publicKey };
|
|
6124
|
+
}
|
|
6125
|
+
async function deriveSwapRefundAuthorization(viewingKeyNk, inputNullifier, ownerUtxoKeypair) {
|
|
6102
6126
|
const blinding = deriveSwapRefundBlinding(viewingKeyNk, inputNullifier);
|
|
6103
|
-
|
|
6127
|
+
const keypair = await deriveSwapRefundKeypair(ownerUtxoKeypair, inputNullifier);
|
|
6128
|
+
if (keypair.publicKey === 0n || blinding === 0n) {
|
|
6104
6129
|
throw new Error("refund authorization is degenerate");
|
|
6105
6130
|
}
|
|
6106
|
-
return { privateKey:
|
|
6131
|
+
return { privateKey: keypair.privateKey, publicKey: keypair.publicKey, blinding };
|
|
6107
6132
|
}
|
|
6108
6133
|
async function deriveLegacySwapRefundAuthorization(viewingKeyNk, inputNullifier) {
|
|
6109
6134
|
const nk = assertNk(viewingKeyNk);
|
|
@@ -6124,9 +6149,12 @@ async function computeSwapRefundCommitment(amountAfterFee, refundPublicKey, refu
|
|
|
6124
6149
|
mintAddress: NATIVE_SOL_MINT
|
|
6125
6150
|
});
|
|
6126
6151
|
}
|
|
6152
|
+
function toField(value) {
|
|
6153
|
+
return value instanceof Uint8Array ? BigInt("0x" + Buffer.from(value).toString("hex")) : value;
|
|
6154
|
+
}
|
|
6127
6155
|
async function matchSwapRefundLeaf(params) {
|
|
6128
6156
|
const { viewingKeyNk, inputNullifier, amountAfterFee } = params;
|
|
6129
|
-
const expected =
|
|
6157
|
+
const expected = toField(params.commitment);
|
|
6130
6158
|
let blinding;
|
|
6131
6159
|
try {
|
|
6132
6160
|
blinding = deriveSwapRefundBlinding(viewingKeyNk, inputNullifier);
|
|
@@ -6134,11 +6162,55 @@ async function matchSwapRefundLeaf(params) {
|
|
|
6134
6162
|
return null;
|
|
6135
6163
|
}
|
|
6136
6164
|
const ownerPub = normalizeOwnerPublicKey(params.ownerUtxoKeypair?.publicKey, "ownerUtxoKeypair.publicKey");
|
|
6165
|
+
const ownerPriv = params.ownerUtxoKeypair?.privateKey ?? 0n;
|
|
6166
|
+
let perSwapPub;
|
|
6167
|
+
let perSwapPriv = 0n;
|
|
6168
|
+
if (ownerPriv > 0n && ownerPub !== void 0) {
|
|
6169
|
+
try {
|
|
6170
|
+
const kp = await deriveSwapRefundKeypair({ privateKey: ownerPriv, publicKey: ownerPub }, inputNullifier);
|
|
6171
|
+
perSwapPub = kp.publicKey;
|
|
6172
|
+
perSwapPriv = kp.privateKey;
|
|
6173
|
+
} catch {
|
|
6174
|
+
return null;
|
|
6175
|
+
}
|
|
6176
|
+
}
|
|
6177
|
+
if (params.publishedRefundPubkey !== void 0 && params.publishedRefundBlinding !== void 0) {
|
|
6178
|
+
const published = toField(params.publishedRefundPubkey);
|
|
6179
|
+
const publishedBlinding = toField(params.publishedRefundBlinding);
|
|
6180
|
+
if (published !== 0n && publishedBlinding === blinding) {
|
|
6181
|
+
if (perSwapPub === void 0 || perSwapPub === published) {
|
|
6182
|
+
const candidate = await computeSwapRefundCommitment(amountAfterFee, published, blinding);
|
|
6183
|
+
if (candidate === expected && published !== ownerPub) {
|
|
6184
|
+
return {
|
|
6185
|
+
keypair: { privateKey: perSwapPub === published ? perSwapPriv : 0n, publicKey: published },
|
|
6186
|
+
shape: "per-swap",
|
|
6187
|
+
blinding,
|
|
6188
|
+
amount: amountAfterFee,
|
|
6189
|
+
commitment: candidate,
|
|
6190
|
+
legacyExposed: false
|
|
6191
|
+
};
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
}
|
|
6195
|
+
} else if (perSwapPub !== void 0) {
|
|
6196
|
+
const candidate = await computeSwapRefundCommitment(amountAfterFee, perSwapPub, blinding);
|
|
6197
|
+
if (candidate === expected) {
|
|
6198
|
+
return {
|
|
6199
|
+
keypair: { privateKey: perSwapPriv, publicKey: perSwapPub },
|
|
6200
|
+
shape: "per-swap",
|
|
6201
|
+
blinding,
|
|
6202
|
+
amount: amountAfterFee,
|
|
6203
|
+
commitment: candidate,
|
|
6204
|
+
legacyExposed: false
|
|
6205
|
+
};
|
|
6206
|
+
}
|
|
6207
|
+
}
|
|
6137
6208
|
if (ownerPub !== void 0) {
|
|
6138
6209
|
const candidate = await computeSwapRefundCommitment(amountAfterFee, ownerPub, blinding);
|
|
6139
6210
|
if (candidate === expected) {
|
|
6140
6211
|
return {
|
|
6141
|
-
keypair: { privateKey:
|
|
6212
|
+
keypair: { privateKey: ownerPriv, publicKey: ownerPub },
|
|
6213
|
+
shape: "owner",
|
|
6142
6214
|
blinding,
|
|
6143
6215
|
amount: amountAfterFee,
|
|
6144
6216
|
commitment: candidate,
|
|
@@ -6156,6 +6228,7 @@ async function matchSwapRefundLeaf(params) {
|
|
|
6156
6228
|
if (legacyCandidate !== expected) return null;
|
|
6157
6229
|
return {
|
|
6158
6230
|
keypair: { privateKey: legacy.privateKey, publicKey: legacy.publicKey },
|
|
6231
|
+
shape: "legacy-nk",
|
|
6159
6232
|
blinding: legacy.blinding,
|
|
6160
6233
|
amount: amountAfterFee,
|
|
6161
6234
|
commitment: legacyCandidate,
|
|
@@ -6167,6 +6240,9 @@ var PROOF_LEN2 = 256;
|
|
|
6167
6240
|
var NULLIFIER_0_OFFSET = 1 + PROOF_LEN2 + 104;
|
|
6168
6241
|
var PUBLIC_INPUTS_LEN2 = 264;
|
|
6169
6242
|
var MIN_TRANSACT_SWAP_LEN = 1 + PROOF_LEN2 + PUBLIC_INPUTS_LEN2;
|
|
6243
|
+
var REFUND_PUBKEY_OFFSET = 1 + PROOF_LEN2 + PUBLIC_INPUTS_LEN2 + 72;
|
|
6244
|
+
var REFUND_BLINDING_OFFSET = REFUND_PUBKEY_OFFSET + 32;
|
|
6245
|
+
var MIN_TRANSACT_SWAP_WITH_PARAMS_LEN = REFUND_BLINDING_OFFSET + 32;
|
|
6170
6246
|
function toBase58(key) {
|
|
6171
6247
|
if (!key) return void 0;
|
|
6172
6248
|
if (typeof key === "string") return key;
|
|
@@ -6229,7 +6305,7 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options)
|
|
|
6229
6305
|
}
|
|
6230
6306
|
if (!options || normalizeOwnerPublicKey(options.ownerUtxoKeypair?.publicKey, "options.ownerUtxoKeypair.publicKey") === void 0) {
|
|
6231
6307
|
throw new Error(
|
|
6232
|
-
"discoverSwapRefunds requires options.ownerUtxoKeypair (the wallet's long-lived UTXO keypair): refund leaves are
|
|
6308
|
+
"discoverSwapRefunds requires options.ownerUtxoKeypair (the wallet's long-lived UTXO keypair): per-swap and owner-key refund leaves are matched against it, and nk alone can only find legacy refunds."
|
|
6233
6309
|
);
|
|
6234
6310
|
}
|
|
6235
6311
|
const ownerUtxoKeypair = options.ownerUtxoKeypair;
|
|
@@ -6289,7 +6365,15 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options)
|
|
|
6289
6365
|
programId
|
|
6290
6366
|
);
|
|
6291
6367
|
const key = swapState;
|
|
6292
|
-
|
|
6368
|
+
const hasParams = data.length >= MIN_TRANSACT_SWAP_WITH_PARAMS_LEN;
|
|
6369
|
+
if (!nullifierBySwapState.has(key)) {
|
|
6370
|
+
nullifierBySwapState.set(key, {
|
|
6371
|
+
nullifier,
|
|
6372
|
+
signature,
|
|
6373
|
+
refundPubkey: hasParams ? data.slice(REFUND_PUBKEY_OFFSET, REFUND_PUBKEY_OFFSET + 32) : void 0,
|
|
6374
|
+
refundBlinding: hasParams ? data.slice(REFUND_BLINDING_OFFSET, REFUND_BLINDING_OFFSET + 32) : void 0
|
|
6375
|
+
});
|
|
6376
|
+
}
|
|
6293
6377
|
}
|
|
6294
6378
|
const logs = tx.meta?.logMessages;
|
|
6295
6379
|
const scan = scanRefundLeafEvents(logs, programIdBase58);
|
|
@@ -6308,7 +6392,9 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options)
|
|
|
6308
6392
|
inputNullifier: candidate.nullifier,
|
|
6309
6393
|
amountAfterFee: event.amountAfterFee,
|
|
6310
6394
|
commitment: event.commitmentField,
|
|
6311
|
-
ownerUtxoKeypair
|
|
6395
|
+
ownerUtxoKeypair,
|
|
6396
|
+
publishedRefundPubkey: candidate.refundPubkey,
|
|
6397
|
+
publishedRefundBlinding: candidate.refundBlinding
|
|
6312
6398
|
});
|
|
6313
6399
|
if (!recovered) continue;
|
|
6314
6400
|
const dedupe = `${close.signature}:${event.leafIndex}`;
|
|
@@ -13641,7 +13727,8 @@ async function matchOwnItems(own, owner, onReject, onSkip) {
|
|
|
13641
13727
|
atRisk: o.refund.legacyExposed,
|
|
13642
13728
|
amount: o.refund.amount,
|
|
13643
13729
|
blinding: o.refund.blinding,
|
|
13644
|
-
|
|
13730
|
+
// per-swap refunds carry their derived keypair; owner-shape ones carry the owner
|
|
13731
|
+
keypair: o.refund.keypair,
|
|
13645
13732
|
mint: NATIVE_SOL_MINT,
|
|
13646
13733
|
commitment: o.refund.commitment,
|
|
13647
13734
|
leaf: Number(item.leaf)
|
|
@@ -14307,7 +14394,8 @@ async function runOnce(ctx, cursor) {
|
|
|
14307
14394
|
for (const c of byLeaf.values()) {
|
|
14308
14395
|
const pubOk = keyChecked.get(c.keypair.privateKey) ?? (c.keypair.privateKey !== 0n && await derivePublicKey(c.keypair.privateKey) === c.keypair.publicKey);
|
|
14309
14396
|
keyChecked.set(c.keypair.privateKey, pubOk);
|
|
14310
|
-
|
|
14397
|
+
const ownerOk = c.keypair.publicKey === owner.publicKey || c.kind === "swap_refund";
|
|
14398
|
+
if (!pubOk || !c.atRisk && !ownerOk) {
|
|
14311
14399
|
stats.dropped++;
|
|
14312
14400
|
tally(c, "rejected");
|
|
14313
14401
|
continue;
|
|
@@ -14316,7 +14404,7 @@ async function runOnce(ctx, cursor) {
|
|
|
14316
14404
|
verifiedOut.add(verifiedKey(c.mint, c.leaf, c.commitment));
|
|
14317
14405
|
const utxo = {
|
|
14318
14406
|
amount: c.amount,
|
|
14319
|
-
keypair: c.atRisk ? { ...c.keypair } : owner,
|
|
14407
|
+
keypair: c.atRisk || c.kind === "swap_refund" ? { ...c.keypair } : owner,
|
|
14320
14408
|
blinding: c.blinding,
|
|
14321
14409
|
mintAddress: c.mint,
|
|
14322
14410
|
index: c.leaf,
|
|
@@ -15800,6 +15888,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15800
15888
|
deriveSpendKey,
|
|
15801
15889
|
deriveSwapRefundAuthorization,
|
|
15802
15890
|
deriveSwapRefundBlinding,
|
|
15891
|
+
deriveSwapRefundKeypair,
|
|
15803
15892
|
deriveUserCompliancePublicKey,
|
|
15804
15893
|
deriveUserComplianceScalar,
|
|
15805
15894
|
deriveUtxoKeypairFromSpendKey,
|
package/dist/index.d.cts
CHANGED
|
@@ -3872,8 +3872,10 @@ interface UtxoSwapResult extends TransactResult {
|
|
|
3872
3872
|
* `SwapState.sol_amount`, = gross swap amount minus the on-chain swap fee). R_fb is an ordinary
|
|
3873
3873
|
* leaf of the main pool tree, spent with the ordinary `transact()` path. All values are hex.
|
|
3874
3874
|
*
|
|
3875
|
-
* `publicKey` is
|
|
3876
|
-
*
|
|
3875
|
+
* `publicKey` is a PER-SWAP public key, derived from `options.ownerUtxoKeypair`'s private key and
|
|
3876
|
+
* the swap's first input nullifier, so no two swaps from one wallet share it and it is not the
|
|
3877
|
+
* wallet's UTXO public key. Spend R_fb with `deriveSwapRefundKeypair(owner, nullifier)`; the
|
|
3878
|
+
* private key is deliberately not repeated here and `nk` cannot produce it. The
|
|
3877
3879
|
* blinding is derived from the wallet's `nk` and the swap's public first input nullifier
|
|
3878
3880
|
* (`derivedFromNk` is always true), so `discoverSwapRefunds` finds the leaf again from key
|
|
3879
3881
|
* material if this object is lost.
|
|
@@ -4658,26 +4660,34 @@ declare function matchChangeNote(params: MatchChangeNoteParams): Promise<Recover
|
|
|
4658
4660
|
* viewing key and the swap creator's, and found nothing under either.
|
|
4659
4661
|
*
|
|
4660
4662
|
* ── The fix, and why it is SDK-only ───────────────────────────────────────────────────────────
|
|
4661
|
-
* The refund leaf is
|
|
4662
|
-
* its
|
|
4663
|
+
* The refund leaf's BLINDING is derived as a PRF of the owner's `nk` and the swap's own first input
|
|
4664
|
+
* nullifier, and its OWNER KEY is derived per swap from the wallet's UTXO private key:
|
|
4663
4665
|
*
|
|
4664
|
-
* blinding = BLAKE3("cloak_swap_refund_v1" || nk || nullifier0 || "blinding")
|
|
4665
|
-
*
|
|
4666
|
+
* blinding = BLAKE3("cloak_swap_refund_v1" || nk || nullifier0 || "blinding") -> field
|
|
4667
|
+
* priv = BLAKE3("cloak_swap_refund_v2" || ownerPrivateKey || nullifier0 || "sk_v2") -> field
|
|
4668
|
+
* pub = derivePublicKey(priv)
|
|
4666
4669
|
*
|
|
4667
|
-
* `nullifier0` is published in the TransactSwap public inputs, so a scanner holding `nk`
|
|
4668
|
-
*
|
|
4669
|
-
*
|
|
4670
|
-
*
|
|
4671
|
-
* blinding
|
|
4670
|
+
* `nullifier0` is published in the TransactSwap public inputs, so a scanner holding `nk` can replay
|
|
4671
|
+
* the blinding for every swap it sees. `refund_pubkey` and `refund_blinding` are ALSO published, in
|
|
4672
|
+
* plain text, in the TransactSwap instruction data (and in SwapState), so a view-only scanner (nk
|
|
4673
|
+
* plus the owner PUBLIC key) reads the per-swap pubkey from there, checks that the published
|
|
4674
|
+
* blinding equals the nk-derived one, and checks that the commitment matches. Spending R_fb needs
|
|
4675
|
+
* `priv`, which needs the owner's private key: `nk` cannot produce it, so the viewing key stays
|
|
4676
|
+
* view-only, and the owner re-derives the spend key from its own private key plus the nullifier.
|
|
4677
|
+
*
|
|
4678
|
+
* Why not the owner key itself (0.2.6 - 0.2.8)? That shape published the wallet's permanent UTXO
|
|
4679
|
+
* public key as `refund_pubkey` on every swap, so anyone holding a user's receiving key could list
|
|
4680
|
+
* all of that wallet's swaps. A different public key per swap removes the link.
|
|
4672
4681
|
*
|
|
4673
4682
|
* This changes NOTHING on chain or in the relay. `refund_pubkey` / `refund_blinding` remain
|
|
4674
4683
|
* caller-supplied values bound into `computeSwapExtDataHash`; only their provenance changes.
|
|
4675
4684
|
*
|
|
4676
|
-
* ──
|
|
4677
|
-
*
|
|
4678
|
-
*
|
|
4679
|
-
*
|
|
4680
|
-
*
|
|
4685
|
+
* ── Three refund shapes, all still recognised ─────────────────────────────────────────────────
|
|
4686
|
+
* "per-swap" (0.2.9+) owner = per-swap key from the owner private key (above)
|
|
4687
|
+
* "owner" (0.2.6 - 0.2.8) owner = the wallet's permanent UTXO keypair; linkable across swaps
|
|
4688
|
+
* "legacy-nk" (< 0.2.6) owner key AND blinding from nk; `legacyExposed: true`, because anyone
|
|
4689
|
+
* holding `nk` can spend it. An app should migrate those refunds.
|
|
4690
|
+
* No API builds a refund in the last two shapes any more.
|
|
4681
4691
|
*
|
|
4682
4692
|
* ── Guardrails preserved ──────────────────────────────────────────────────────────────────────
|
|
4683
4693
|
* [H-04 / DD-01] the authorization is rejected unless publicKey and blinding are both non-zero.
|
|
@@ -4698,14 +4708,20 @@ interface SwapRefundAuthorization {
|
|
|
4698
4708
|
publicKey: bigint;
|
|
4699
4709
|
blinding: bigint;
|
|
4700
4710
|
}
|
|
4711
|
+
/** Which key shape owns a refund leaf; see the file header. */
|
|
4712
|
+
type SwapRefundShape = "per-swap" | "owner" | "legacy-nk";
|
|
4701
4713
|
/** A refund leaf matched back to its owner. */
|
|
4702
4714
|
interface RecoveredSwapRefund {
|
|
4703
4715
|
/**
|
|
4704
|
-
* The
|
|
4705
|
-
* (`privateKey` is `0n`
|
|
4706
|
-
*
|
|
4716
|
+
* The key that owns the leaf. `per-swap`: the key derived from the owner private key and the
|
|
4717
|
+
* swap nullifier (`privateKey` is `0n` for a view-only match: the public key is real, but the
|
|
4718
|
+
* spend key needs the owner private key, see {@link deriveSwapRefundKeypair}). `owner`: the
|
|
4719
|
+
* `ownerUtxoKeypair` the matcher was given (`privateKey` `0n` if only the public key was
|
|
4720
|
+
* supplied). `legacy-nk`: the nk-derived keypair, complete and spendable.
|
|
4707
4721
|
*/
|
|
4708
4722
|
keypair: UtxoKeypair;
|
|
4723
|
+
/** Which of the three shapes matched. */
|
|
4724
|
+
shape: SwapRefundShape;
|
|
4709
4725
|
blinding: bigint;
|
|
4710
4726
|
amount: bigint;
|
|
4711
4727
|
/** R_fb as a field element, identical to the commitment `CloseSwapState` appended. */
|
|
@@ -4724,8 +4740,15 @@ interface RecoveredSwapRefund {
|
|
|
4724
4740
|
*/
|
|
4725
4741
|
declare function deriveSwapRefundBlinding(viewingKeyNk: Uint8Array, inputNullifier: Uint8Array | bigint): bigint;
|
|
4726
4742
|
/**
|
|
4727
|
-
* The refund
|
|
4728
|
-
*
|
|
4743
|
+
* The per-swap refund KEYPAIR: a different key for every swap, derived from the owner's private key
|
|
4744
|
+
* and the swap's first input nullifier. `nk` cannot reproduce it. Use this to spend a refund the
|
|
4745
|
+
* swap result reported, or any `per-swap` refund a view-only scan found.
|
|
4746
|
+
*/
|
|
4747
|
+
declare function deriveSwapRefundKeypair(ownerUtxoKeypair: UtxoKeypair, inputNullifier: Uint8Array | bigint): Promise<UtxoKeypair>;
|
|
4748
|
+
/**
|
|
4749
|
+
* The refund authorization `swapUtxo` binds into the swap ext-data hash: a per-swap keypair derived
|
|
4750
|
+
* from the wallet's UTXO private key and the swap's first input nullifier, plus the nk-derived
|
|
4751
|
+
* blinding. The public key differs for every swap and differs from the wallet's UTXO public key.
|
|
4729
4752
|
*
|
|
4730
4753
|
* `ownerUtxoKeypair` is required and validated. The refund key is never derived from `nk`.
|
|
4731
4754
|
*/
|
|
@@ -4752,16 +4775,28 @@ interface MatchSwapRefundLeafParams {
|
|
|
4752
4775
|
commitment: bigint | Uint8Array;
|
|
4753
4776
|
/**
|
|
4754
4777
|
* The wallet's long-lived UTXO keypair (`privateKey: 0n` is fine for a view-only match). Without
|
|
4755
|
-
* it only legacy refunds can be matched.
|
|
4778
|
+
* it only legacy-nk refunds can be matched.
|
|
4756
4779
|
*/
|
|
4757
4780
|
ownerUtxoKeypair?: UtxoKeypair;
|
|
4781
|
+
/**
|
|
4782
|
+
* `refund_pubkey` as published in the swap's TransactSwap instruction data (bytes 593-624) or its
|
|
4783
|
+
* SwapState. A view-only scanner needs it to match a `per-swap` refund, because it cannot derive
|
|
4784
|
+
* the key. Pass it together with {@link publishedRefundBlinding}.
|
|
4785
|
+
*/
|
|
4786
|
+
publishedRefundPubkey?: bigint | Uint8Array;
|
|
4787
|
+
/** `refund_blinding` as published in the same place (bytes 625-656). */
|
|
4788
|
+
publishedRefundBlinding?: bigint | Uint8Array;
|
|
4758
4789
|
}
|
|
4759
4790
|
/**
|
|
4760
4791
|
* Decide whether a public refund leaf belongs to this wallet, and if so return it. Returns `null`
|
|
4761
4792
|
* for every leaf that is not ours; a scanner runs this against every close it can see.
|
|
4762
4793
|
*
|
|
4763
|
-
* Tries the
|
|
4764
|
-
*
|
|
4794
|
+
* Tries, in order: the per-swap shape (published pubkey, or re-derived when the owner private key
|
|
4795
|
+
* is present), the 0.2.6 - 0.2.8 owner-key shape, then the legacy nk shape (`legacyExposed`).
|
|
4796
|
+
* `shape` on the result says which one matched.
|
|
4797
|
+
*
|
|
4798
|
+
* A per-swap match from a view-only scan returns `keypair.privateKey === 0n`; the caller spends it
|
|
4799
|
+
* with {@link deriveSwapRefundKeypair} once it holds the owner private key.
|
|
4765
4800
|
*/
|
|
4766
4801
|
declare function matchSwapRefundLeaf(params: MatchSwapRefundLeafParams): Promise<RecoveredSwapRefund | null>;
|
|
4767
4802
|
/** One recovered refund leaf, with the chain coordinates that produced it. */
|
|
@@ -4777,9 +4812,11 @@ interface DiscoveredSwapRefund extends RecoveredSwapRefund {
|
|
|
4777
4812
|
}
|
|
4778
4813
|
interface DiscoverSwapRefundsOptions {
|
|
4779
4814
|
/**
|
|
4780
|
-
* The wallet's long-lived UTXO keypair
|
|
4781
|
-
*
|
|
4782
|
-
* for a view-only scan
|
|
4815
|
+
* The wallet's long-lived UTXO keypair. Required. Pass the real keypair to get spendable
|
|
4816
|
+
* results (per-swap refunds come back with their derived keypair), or `{ privateKey: 0n,
|
|
4817
|
+
* publicKey }` for a view-only scan: per-swap refunds are then matched from the `refund_pubkey`
|
|
4818
|
+
* published in the swap instruction and come back with `privateKey: 0n` (re-derive it with
|
|
4819
|
+
* `deriveSwapRefundKeypair`). Legacy (nk-owned) refunds are found either way and flagged
|
|
4783
4820
|
* `legacyExposed`.
|
|
4784
4821
|
*/
|
|
4785
4822
|
ownerUtxoKeypair: UtxoKeypair;
|
|
@@ -4807,7 +4844,7 @@ interface DiscoverSwapRefundsOptions {
|
|
|
4807
4844
|
* its owner could not see it under any key they held.
|
|
4808
4845
|
*
|
|
4809
4846
|
* FORWARD-LOOKING ONLY. This finds refunds whose blinding was DERIVED from (nk, nullifier0), owned
|
|
4810
|
-
*
|
|
4847
|
+
* by a per-swap key (0.2.9+), the wallet UTXO key (0.2.6-0.2.8) or an nk-derived key (legacy, flagged).
|
|
4811
4848
|
* A swap whose refund keypair and blinding were drawn from raw randomness (every swap submitted
|
|
4812
4849
|
* before that derivation shipped) has no derivation to replay,
|
|
4813
4850
|
* and no key-only scan can ever recover it. Those secrets existed solely in the caller's in-memory
|
|
@@ -6421,4 +6458,4 @@ declare const VERSION = "0.2.6";
|
|
|
6421
6458
|
/** True when scanner supports TransactSwap (tag 1). Check this to verify the correct SDK bundle is loaded. */
|
|
6422
6459
|
declare const SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
6423
6460
|
|
|
6424
|
-
export { BRIDGE_ESCROW_LABEL, BRIDGE_ESCROW_LABEL_V2, BUILD_ALLOWS_LOCAL_ENDPOINTS, type BridgeDeliveryState, type BridgeDeposit, type BridgeDepositState, type BridgeQuoteAssessment, type BridgeQuoteInput, type BridgeRail, type BridgeRailAttestation, type BridgeRailProblem, type BridgeRailQuoteOption, type BridgeRailQuoteRequest, type BridgeRailQuoteResponse, type BridgeRailStatusResult, type BuildRecipientDeliveryNotesParams, CHAIN_NOTE_SALT_BITS, CLEANUP_FEE_BUDGET, CLOAK_PRODUCTION_RELAY_URL, CLOAK_PROGRAM_ID, type ChainNoteTxType, type CircuitVerificationResult, type CleanupResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, type CloakRpc, type CommitmentEntry, type CommitmentsResponse, type CompactChainNote, type ComplianceReport, type ComplianceTxType, type ConfirmSettlementParams, type CreateRecoverableDepositUtxoParams, DEFAULT_CIRCUITS_URL, DEFAULT_TRANSACTION_CIRCUITS_URL, DELIVERY_MEMO_TAG, DELIVERY_REGISTRY_SEED, type DeliveredNote, DepositError, type DepositInstructionParams, type DepositNoteSecrets, type DepositOptions, type DepositOutcome, type DepositRef, type DepositResult, type DepositStatus, type DiscoverOptions, type DiscoverSwapRefundsOptions, type DiscoveredSwapRefund, DoNotRetry, ECONOMIC_MINIMUM, EXPECTED_CIRCUIT_HASHES, type EncodeNoteIndexPageParams, type EncryptedMetadataBundle, type EncryptedNote$1 as EncryptedNote, type ErrorCategory, type ExpandedSpendKey, type ExternalFeePayerAdapter, FEE_BUDGET, FIXED_FEE_LAMPORTS, type FundingPlan, type Groth16Proof, type IndexedRecoveredNote, type IndexedRecoveredNoteKind, InsecureRandomnessError, LAMPORTS_PER_SOL, type LegacyWalletAdapter, type WalletSigner as LegacyWalletSigner, LocalStorageAdapter, type LogLevel, type Logger, type LookupTable, MAINNET_RENT_0, MAINNET_RENT_1, MAX_RECEIVER_INDEX, MERKLE_TREE_HEIGHT, MIN_DEPOSIT_LAMPORTS, MIN_DEPOSIT_SPL_BASE_UNITS, type MasterKey, type MatchChangeNoteParams, type MatchDepositNoteParams, type MatchSwapRefundLeafParams, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, MerkleTree, type MessageSigner, NATIVE_SOL_MINT, NOTE_INDEX_NO_LEAF, NOTE_INDEX_PAGE_SIZE, type Network, type NoteData, type NoteIndexCursor, type NoteIndexDeliveryItem, type NoteIndexFetchOptions, NoteIndexFormatError, type NoteIndexHead, NoteIndexHeadBehindError, type NoteIndexItem, type NoteIndexPage, type NoteIndexRecoveryStats, type NoteIndexSwapRefundItem, type NoteIndexTxItem, ONECLICK_PUBKEY_B58, type OnchainMerkleProof, type ParseNoteIndexPageOptions, type ParsedDeliveryCarrier, type PaymasterTopUpExpectation, type PaymasterTopUpResult, type PendingDeposit, type PendingWithdrawal, type PostFailureVerdict, RECIPIENT_DELIVERY_CIPHERTEXT_LEN, RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN, RECIPIENT_DELIVERY_NONCE_LEN, RECIPIENT_DELIVERY_NOTE_BYTES, RECIPIENT_DELIVERY_PLAINTEXT_LEN, RECIPIENT_DELIVERY_TAG_LEN, RELAY_BATCH_AUTH_MAX_ITEMS, RELAY_ORIGIN_ALLOWLIST, REQUEST_AUTH_BATCH_DOMAIN, REQUEST_AUTH_BATCH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS, type RecipientDeliveryNote, type RecoverNotesFromIndexParams, type RecoverNotesFromIndexResult, type RecoveredChangeNote, type RecoveredChangeNoteRecord, type RecoveredDepositNote, type RecoveredDepositNoteRecord, type RecoveredSwapRefund, type RelayAuthMode, type RelayAuthPreimage, type RelayAuthSigner, RelayBatchAuthCoordinator, type RelayBatchAuthCoordinatorOptions, type RelayBatchAuthEnvelope, type RelayBatchAuthFields, type RelayBatchAuthItemHandle, RelayInternalError, RelayService, type RelaySubmissionResult, type RentRates, type RetryHooks, type RiskQuoteInstructionResponse, RootNotFoundError, SCANNER_SUPPORTS_TRANSACT_SWAP, SIGN_IN_MESSAGE, SanctionsQuoteError, type ScanOptions, type ScanRecipientDeliveryOptions, type ScanResult, type ScanSummary, type ScannedTransaction, type SettlementConnection, type SettlementContext, type SettlementStatus, type SettlementVerdict, SettlementVerificationError, ShieldPoolErrors, type ShieldPoolPDAs, SimpleWallet, type SpendKey, type SpendOptions, type StorageAdapter, type SubmitTransactToRelayArgs, type SwapOptions, type SwapParams, type SwapRefundAuthorization, type SwapResult, TERMINAL_FAILURE, TRANSACTION_CIRCUITS_VERSION, TRANSACT_AUTH_FIELDS, TRANSACT_SWAP_AUTH_FIELDS, type TransactBatchItem, type TransactBatchItemOutcome, type TransactBatchOptions, type TransactBatchResult, type TransactOptions, type TransactParams, type TransactRequestBodyParams, type TransactResult, TransactionConfirmationError, type TransactionMetadata, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, type Utxo, UtxoAlreadySpentError, type EncryptedNote as UtxoEncryptedNote, type UtxoKeypair, type UtxoSwapParams, type UtxoSwapResult, UtxoWallet, VARIABLE_FEE_DENOMINATOR, VARIABLE_FEE_NUMERATOR, VARIABLE_FEE_RATE, VERSION, type VerifyUtxosResult, type ViewKey, type ViewingKeyPair, WITHDRAW_FEE_BPS, WITHDRAW_FIXED_FEE, type WalletAdapterBridgeOptions, type WalletSigner$1 as WalletSigner, type WalletUtxo, type Web3Module, type WithdrawOptions, type WithdrawSubmissionResult, accountMeta, addressBytes, addressFromBytes, addressFromPublicKey, assertDirectSubmissionLanded, assertInputMints, assertTransactionCircuitIntegrity, assessBridgeQuote, bigintToBytes32$1 as bigintToBytes32, bigintToHex, buildAuthTransactionMessage, buildMerkleTree, buildMerkleTreeFromChain, buildMerkleTreeFromRelay, buildRecipientDeliveryNotes, buildRelayAuthPreimage, buildRelayBatchAuthMessage, buildTransactRequestBody, buildTransactionMessage, bytesToHex, calculateFee, calculateFeeBigint, calculateRelayFee, canRebuildMerkleTreeFromChain, canonicalJson, canonicalPayloadString, chainNoteFromBase64, chainNoteToBase64, classifyPostFailure, classifyRelayError, cleanupReceivingAddress, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, cloakBridgeRail, computeChainNoteHash, computeExtDataHash, computeMerkleRoot, computeNoteIndexChain, computeProofForLatestDeposit, computeProofFromChain, computeSignature, computeSwapRefundCommitment, computeCommitment as computeUtxoCommitment, computeNullifier as computeUtxoNullifier, confirmSignature, confirmTransactSettlement, copyNoteToClipboard, createCloakError, createCloakRpc, createDepositInstruction, createLogger, createRecoverableChangeUtxo, createRecoverableDepositUtxo, createRelayBatchAuthCoordinator, createUtxo, createZeroUtxo, decryptCompactChainNote, decryptComplianceMetadataWithMasterKey, decryptTransactionMetadata, depositFromDerivedKey, deriveBridgeReceiver, deriveChangeNoteBlinding, deriveDepositNoteBlinding, deriveDiversifiedViewingKey, deriveDiversifier, deriveFundingTargets, deriveInputNullifierPdas, deriveLegacyBridgeReceiver, deriveLegacyDepositNoteSecrets, deriveLegacySwapRefundAuthorization, derivePublicKey, deriveSpendKey, deriveSwapRefundAuthorization, deriveSwapRefundBlinding, deriveUserCompliancePublicKey, deriveUserComplianceScalar, deriveUtxoKeypairFromSpendKey, deriveViewKey, deriveViewingKeyFromNk, deriveViewingKeyFromSpendKey, deriveViewingKeyFromUtxoPrivateKey, deserializeUtxo, detectNetworkFromRpcUrl, discoverSwapRefunds, downloadNote, encodeDeliveryCarrierMemo, encodeNoteIndexItem, encodeNoteIndexPage, encodeNoteSimple, encodeRecipientDeliveryNote, encryptCompactChainNote, encryptNoteForRecipient, encryptTransactionMetadata, encryptTransactionMetadataBundle, expandSpendKey, explainRelayAuthRejection, exportKeys, exportNote, exportWalletKeys, fetchAccountBytes, fetchCommitments, fetchLatestBlockhash, fetchLookupTables, fetchNoteIndexHead, fetchNoteIndexPage, fetchRiskQuoteInstruction, fetchRiskQuoteIx, fetchSignaturesForAddress, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, findProgramAddress, formatAmount, formatComplianceCsv, formatErrorForLogging, formatSol, fullWithdraw, fundReceiverViaPaymaster, generateCloakKeys, generateCommitmentAsync, generateMasterSeed, generateNoteFromWallet, generateUtxoKeypair, generateViewingKeyPair, getAddressExplorerUrl, getChainNoteRegistryPDA, getCircuitsPath, getDeliveryRegistryPDA, getDistributableAmount, getExplorerUrl, getNkFromUtxoPrivateKey, getNullifierPDA, getPendingOperationsSummary, getPoolAuthorityConfigPDA, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getSwapStatePDA, getViewKey, hasPendingOperations, hexToBigint$1 as hexToBigint, hexToBytes, importKeys, importWalletKeys, isBrowser, isBrowserLike, isDebugEnabled, isMessageSigner, isPlausibleSignature, isReactNative, isRootNotFoundError, isSubmissionOutcomeUnknownResponse, isTerminalFailure, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawAmountSufficient, isWithdrawable, listBridgeDeposits, loadPendingDeposits, loadPendingWithdrawals, loadVerifiedCircuitArtifacts, matchChangeNote, matchDepositNote, matchSwapRefundLeaf, mayRetry, messageSignerFromCallback, openRecipientDeliveryNote, parseAmount, parseDeliveryCarrierMemo, parseError, parseNote, parseNoteIndexItem, parseNoteIndexPage, parseRelayErrorResponse, parseRelayErrorSignature, parseTransactionError, partialWithdraw, partiallySignTransaction, poseidonHash, preflightCheck, preflightNullifiers, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, programInstruction, proofToBytes, pubkeyToFieldElement, pubkeyToLimbs, randomBytes, randomChangeNoteSalt, randomDepositNoteSalt, randomFieldElement, readMerkleTreeState, readRent, recipientDeliveryNoteToBase64, recoverNotesFromIndex, registerViewingKey, relayRequestDigestHex, removePendingDeposit, removePendingWithdrawal, renderAssessment, resolveCircuitsBase, retryDelayMs, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, scanRecipientDeliveryNotes, scanTransactions, sdkLogger, selectUtxos, sendInstructions, sendRawTransaction, sendTransaction, serializeAuthTransactionMessage, serializeNote, serializeUtxo, setCircuitsPath, setDebugMode, signCompiledTransaction, signMessageBytes, signRelayAuthPayload, signTransaction, signerFromKeypair, signerFromSecretKey, signerFromWalletAdapter, splitTo2Limbs, submitTransactToRelay, sumUtxoAmounts, swapUtxo, swapWithChange, toAddress, toComplianceReport, transact, transactBatch, transactionBase64, transactionBytes, transactionFromBytes, transactionWireSize, transfer, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, bigintToBytes32 as utxoBigintToBytes32, utxoEquals, hexToBigint as utxoHexToBigint, validateDepositParams, validateNote, validateOutputsSum, validatePaymasterTopUpTransaction, validateRoot, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, verifyQuoteSignature, verifyUtxos, waitForRoot, withShieldRetries, withTiming, withdrawFeeFor };
|
|
6461
|
+
export { BRIDGE_ESCROW_LABEL, BRIDGE_ESCROW_LABEL_V2, BUILD_ALLOWS_LOCAL_ENDPOINTS, type BridgeDeliveryState, type BridgeDeposit, type BridgeDepositState, type BridgeQuoteAssessment, type BridgeQuoteInput, type BridgeRail, type BridgeRailAttestation, type BridgeRailProblem, type BridgeRailQuoteOption, type BridgeRailQuoteRequest, type BridgeRailQuoteResponse, type BridgeRailStatusResult, type BuildRecipientDeliveryNotesParams, CHAIN_NOTE_SALT_BITS, CLEANUP_FEE_BUDGET, CLOAK_PRODUCTION_RELAY_URL, CLOAK_PROGRAM_ID, type ChainNoteTxType, type CircuitVerificationResult, type CleanupResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, type CloakRpc, type CommitmentEntry, type CommitmentsResponse, type CompactChainNote, type ComplianceReport, type ComplianceTxType, type ConfirmSettlementParams, type CreateRecoverableDepositUtxoParams, DEFAULT_CIRCUITS_URL, DEFAULT_TRANSACTION_CIRCUITS_URL, DELIVERY_MEMO_TAG, DELIVERY_REGISTRY_SEED, type DeliveredNote, DepositError, type DepositInstructionParams, type DepositNoteSecrets, type DepositOptions, type DepositOutcome, type DepositRef, type DepositResult, type DepositStatus, type DiscoverOptions, type DiscoverSwapRefundsOptions, type DiscoveredSwapRefund, DoNotRetry, ECONOMIC_MINIMUM, EXPECTED_CIRCUIT_HASHES, type EncodeNoteIndexPageParams, type EncryptedMetadataBundle, type EncryptedNote$1 as EncryptedNote, type ErrorCategory, type ExpandedSpendKey, type ExternalFeePayerAdapter, FEE_BUDGET, FIXED_FEE_LAMPORTS, type FundingPlan, type Groth16Proof, type IndexedRecoveredNote, type IndexedRecoveredNoteKind, InsecureRandomnessError, LAMPORTS_PER_SOL, type LegacyWalletAdapter, type WalletSigner as LegacyWalletSigner, LocalStorageAdapter, type LogLevel, type Logger, type LookupTable, MAINNET_RENT_0, MAINNET_RENT_1, MAX_RECEIVER_INDEX, MERKLE_TREE_HEIGHT, MIN_DEPOSIT_LAMPORTS, MIN_DEPOSIT_SPL_BASE_UNITS, type MasterKey, type MatchChangeNoteParams, type MatchDepositNoteParams, type MatchSwapRefundLeafParams, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, MerkleTree, type MessageSigner, NATIVE_SOL_MINT, NOTE_INDEX_NO_LEAF, NOTE_INDEX_PAGE_SIZE, type Network, type NoteData, type NoteIndexCursor, type NoteIndexDeliveryItem, type NoteIndexFetchOptions, NoteIndexFormatError, type NoteIndexHead, NoteIndexHeadBehindError, type NoteIndexItem, type NoteIndexPage, type NoteIndexRecoveryStats, type NoteIndexSwapRefundItem, type NoteIndexTxItem, ONECLICK_PUBKEY_B58, type OnchainMerkleProof, type ParseNoteIndexPageOptions, type ParsedDeliveryCarrier, type PaymasterTopUpExpectation, type PaymasterTopUpResult, type PendingDeposit, type PendingWithdrawal, type PostFailureVerdict, RECIPIENT_DELIVERY_CIPHERTEXT_LEN, RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN, RECIPIENT_DELIVERY_NONCE_LEN, RECIPIENT_DELIVERY_NOTE_BYTES, RECIPIENT_DELIVERY_PLAINTEXT_LEN, RECIPIENT_DELIVERY_TAG_LEN, RELAY_BATCH_AUTH_MAX_ITEMS, RELAY_ORIGIN_ALLOWLIST, REQUEST_AUTH_BATCH_DOMAIN, REQUEST_AUTH_BATCH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS, type RecipientDeliveryNote, type RecoverNotesFromIndexParams, type RecoverNotesFromIndexResult, type RecoveredChangeNote, type RecoveredChangeNoteRecord, type RecoveredDepositNote, type RecoveredDepositNoteRecord, type RecoveredSwapRefund, type RelayAuthMode, type RelayAuthPreimage, type RelayAuthSigner, RelayBatchAuthCoordinator, type RelayBatchAuthCoordinatorOptions, type RelayBatchAuthEnvelope, type RelayBatchAuthFields, type RelayBatchAuthItemHandle, RelayInternalError, RelayService, type RelaySubmissionResult, type RentRates, type RetryHooks, type RiskQuoteInstructionResponse, RootNotFoundError, SCANNER_SUPPORTS_TRANSACT_SWAP, SIGN_IN_MESSAGE, SanctionsQuoteError, type ScanOptions, type ScanRecipientDeliveryOptions, type ScanResult, type ScanSummary, type ScannedTransaction, type SettlementConnection, type SettlementContext, type SettlementStatus, type SettlementVerdict, SettlementVerificationError, ShieldPoolErrors, type ShieldPoolPDAs, SimpleWallet, type SpendKey, type SpendOptions, type StorageAdapter, type SubmitTransactToRelayArgs, type SwapOptions, type SwapParams, type SwapRefundAuthorization, type SwapRefundShape, type SwapResult, TERMINAL_FAILURE, TRANSACTION_CIRCUITS_VERSION, TRANSACT_AUTH_FIELDS, TRANSACT_SWAP_AUTH_FIELDS, type TransactBatchItem, type TransactBatchItemOutcome, type TransactBatchOptions, type TransactBatchResult, type TransactOptions, type TransactParams, type TransactRequestBodyParams, type TransactResult, TransactionConfirmationError, type TransactionMetadata, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, type Utxo, UtxoAlreadySpentError, type EncryptedNote as UtxoEncryptedNote, type UtxoKeypair, type UtxoSwapParams, type UtxoSwapResult, UtxoWallet, VARIABLE_FEE_DENOMINATOR, VARIABLE_FEE_NUMERATOR, VARIABLE_FEE_RATE, VERSION, type VerifyUtxosResult, type ViewKey, type ViewingKeyPair, WITHDRAW_FEE_BPS, WITHDRAW_FIXED_FEE, type WalletAdapterBridgeOptions, type WalletSigner$1 as WalletSigner, type WalletUtxo, type Web3Module, type WithdrawOptions, type WithdrawSubmissionResult, accountMeta, addressBytes, addressFromBytes, addressFromPublicKey, assertDirectSubmissionLanded, assertInputMints, assertTransactionCircuitIntegrity, assessBridgeQuote, bigintToBytes32$1 as bigintToBytes32, bigintToHex, buildAuthTransactionMessage, buildMerkleTree, buildMerkleTreeFromChain, buildMerkleTreeFromRelay, buildRecipientDeliveryNotes, buildRelayAuthPreimage, buildRelayBatchAuthMessage, buildTransactRequestBody, buildTransactionMessage, bytesToHex, calculateFee, calculateFeeBigint, calculateRelayFee, canRebuildMerkleTreeFromChain, canonicalJson, canonicalPayloadString, chainNoteFromBase64, chainNoteToBase64, classifyPostFailure, classifyRelayError, cleanupReceivingAddress, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, cloakBridgeRail, computeChainNoteHash, computeExtDataHash, computeMerkleRoot, computeNoteIndexChain, computeProofForLatestDeposit, computeProofFromChain, computeSignature, computeSwapRefundCommitment, computeCommitment as computeUtxoCommitment, computeNullifier as computeUtxoNullifier, confirmSignature, confirmTransactSettlement, copyNoteToClipboard, createCloakError, createCloakRpc, createDepositInstruction, createLogger, createRecoverableChangeUtxo, createRecoverableDepositUtxo, createRelayBatchAuthCoordinator, createUtxo, createZeroUtxo, decryptCompactChainNote, decryptComplianceMetadataWithMasterKey, decryptTransactionMetadata, depositFromDerivedKey, deriveBridgeReceiver, deriveChangeNoteBlinding, deriveDepositNoteBlinding, deriveDiversifiedViewingKey, deriveDiversifier, deriveFundingTargets, deriveInputNullifierPdas, deriveLegacyBridgeReceiver, deriveLegacyDepositNoteSecrets, deriveLegacySwapRefundAuthorization, derivePublicKey, deriveSpendKey, deriveSwapRefundAuthorization, deriveSwapRefundBlinding, deriveSwapRefundKeypair, deriveUserCompliancePublicKey, deriveUserComplianceScalar, deriveUtxoKeypairFromSpendKey, deriveViewKey, deriveViewingKeyFromNk, deriveViewingKeyFromSpendKey, deriveViewingKeyFromUtxoPrivateKey, deserializeUtxo, detectNetworkFromRpcUrl, discoverSwapRefunds, downloadNote, encodeDeliveryCarrierMemo, encodeNoteIndexItem, encodeNoteIndexPage, encodeNoteSimple, encodeRecipientDeliveryNote, encryptCompactChainNote, encryptNoteForRecipient, encryptTransactionMetadata, encryptTransactionMetadataBundle, expandSpendKey, explainRelayAuthRejection, exportKeys, exportNote, exportWalletKeys, fetchAccountBytes, fetchCommitments, fetchLatestBlockhash, fetchLookupTables, fetchNoteIndexHead, fetchNoteIndexPage, fetchRiskQuoteInstruction, fetchRiskQuoteIx, fetchSignaturesForAddress, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, findProgramAddress, formatAmount, formatComplianceCsv, formatErrorForLogging, formatSol, fullWithdraw, fundReceiverViaPaymaster, generateCloakKeys, generateCommitmentAsync, generateMasterSeed, generateNoteFromWallet, generateUtxoKeypair, generateViewingKeyPair, getAddressExplorerUrl, getChainNoteRegistryPDA, getCircuitsPath, getDeliveryRegistryPDA, getDistributableAmount, getExplorerUrl, getNkFromUtxoPrivateKey, getNullifierPDA, getPendingOperationsSummary, getPoolAuthorityConfigPDA, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getSwapStatePDA, getViewKey, hasPendingOperations, hexToBigint$1 as hexToBigint, hexToBytes, importKeys, importWalletKeys, isBrowser, isBrowserLike, isDebugEnabled, isMessageSigner, isPlausibleSignature, isReactNative, isRootNotFoundError, isSubmissionOutcomeUnknownResponse, isTerminalFailure, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawAmountSufficient, isWithdrawable, listBridgeDeposits, loadPendingDeposits, loadPendingWithdrawals, loadVerifiedCircuitArtifacts, matchChangeNote, matchDepositNote, matchSwapRefundLeaf, mayRetry, messageSignerFromCallback, openRecipientDeliveryNote, parseAmount, parseDeliveryCarrierMemo, parseError, parseNote, parseNoteIndexItem, parseNoteIndexPage, parseRelayErrorResponse, parseRelayErrorSignature, parseTransactionError, partialWithdraw, partiallySignTransaction, poseidonHash, preflightCheck, preflightNullifiers, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, programInstruction, proofToBytes, pubkeyToFieldElement, pubkeyToLimbs, randomBytes, randomChangeNoteSalt, randomDepositNoteSalt, randomFieldElement, readMerkleTreeState, readRent, recipientDeliveryNoteToBase64, recoverNotesFromIndex, registerViewingKey, relayRequestDigestHex, removePendingDeposit, removePendingWithdrawal, renderAssessment, resolveCircuitsBase, retryDelayMs, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, scanRecipientDeliveryNotes, scanTransactions, sdkLogger, selectUtxos, sendInstructions, sendRawTransaction, sendTransaction, serializeAuthTransactionMessage, serializeNote, serializeUtxo, setCircuitsPath, setDebugMode, signCompiledTransaction, signMessageBytes, signRelayAuthPayload, signTransaction, signerFromKeypair, signerFromSecretKey, signerFromWalletAdapter, splitTo2Limbs, submitTransactToRelay, sumUtxoAmounts, swapUtxo, swapWithChange, toAddress, toComplianceReport, transact, transactBatch, transactionBase64, transactionBytes, transactionFromBytes, transactionWireSize, transfer, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, bigintToBytes32 as utxoBigintToBytes32, utxoEquals, hexToBigint as utxoHexToBigint, validateDepositParams, validateNote, validateOutputsSum, validatePaymasterTopUpTransaction, validateRoot, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, verifyQuoteSignature, verifyUtxos, waitForRoot, withShieldRetries, withTiming, withdrawFeeFor };
|
package/dist/index.d.ts
CHANGED
|
@@ -3872,8 +3872,10 @@ interface UtxoSwapResult extends TransactResult {
|
|
|
3872
3872
|
* `SwapState.sol_amount`, = gross swap amount minus the on-chain swap fee). R_fb is an ordinary
|
|
3873
3873
|
* leaf of the main pool tree, spent with the ordinary `transact()` path. All values are hex.
|
|
3874
3874
|
*
|
|
3875
|
-
* `publicKey` is
|
|
3876
|
-
*
|
|
3875
|
+
* `publicKey` is a PER-SWAP public key, derived from `options.ownerUtxoKeypair`'s private key and
|
|
3876
|
+
* the swap's first input nullifier, so no two swaps from one wallet share it and it is not the
|
|
3877
|
+
* wallet's UTXO public key. Spend R_fb with `deriveSwapRefundKeypair(owner, nullifier)`; the
|
|
3878
|
+
* private key is deliberately not repeated here and `nk` cannot produce it. The
|
|
3877
3879
|
* blinding is derived from the wallet's `nk` and the swap's public first input nullifier
|
|
3878
3880
|
* (`derivedFromNk` is always true), so `discoverSwapRefunds` finds the leaf again from key
|
|
3879
3881
|
* material if this object is lost.
|
|
@@ -4658,26 +4660,34 @@ declare function matchChangeNote(params: MatchChangeNoteParams): Promise<Recover
|
|
|
4658
4660
|
* viewing key and the swap creator's, and found nothing under either.
|
|
4659
4661
|
*
|
|
4660
4662
|
* ── The fix, and why it is SDK-only ───────────────────────────────────────────────────────────
|
|
4661
|
-
* The refund leaf is
|
|
4662
|
-
* its
|
|
4663
|
+
* The refund leaf's BLINDING is derived as a PRF of the owner's `nk` and the swap's own first input
|
|
4664
|
+
* nullifier, and its OWNER KEY is derived per swap from the wallet's UTXO private key:
|
|
4663
4665
|
*
|
|
4664
|
-
* blinding = BLAKE3("cloak_swap_refund_v1" || nk || nullifier0 || "blinding")
|
|
4665
|
-
*
|
|
4666
|
+
* blinding = BLAKE3("cloak_swap_refund_v1" || nk || nullifier0 || "blinding") -> field
|
|
4667
|
+
* priv = BLAKE3("cloak_swap_refund_v2" || ownerPrivateKey || nullifier0 || "sk_v2") -> field
|
|
4668
|
+
* pub = derivePublicKey(priv)
|
|
4666
4669
|
*
|
|
4667
|
-
* `nullifier0` is published in the TransactSwap public inputs, so a scanner holding `nk`
|
|
4668
|
-
*
|
|
4669
|
-
*
|
|
4670
|
-
*
|
|
4671
|
-
* blinding
|
|
4670
|
+
* `nullifier0` is published in the TransactSwap public inputs, so a scanner holding `nk` can replay
|
|
4671
|
+
* the blinding for every swap it sees. `refund_pubkey` and `refund_blinding` are ALSO published, in
|
|
4672
|
+
* plain text, in the TransactSwap instruction data (and in SwapState), so a view-only scanner (nk
|
|
4673
|
+
* plus the owner PUBLIC key) reads the per-swap pubkey from there, checks that the published
|
|
4674
|
+
* blinding equals the nk-derived one, and checks that the commitment matches. Spending R_fb needs
|
|
4675
|
+
* `priv`, which needs the owner's private key: `nk` cannot produce it, so the viewing key stays
|
|
4676
|
+
* view-only, and the owner re-derives the spend key from its own private key plus the nullifier.
|
|
4677
|
+
*
|
|
4678
|
+
* Why not the owner key itself (0.2.6 - 0.2.8)? That shape published the wallet's permanent UTXO
|
|
4679
|
+
* public key as `refund_pubkey` on every swap, so anyone holding a user's receiving key could list
|
|
4680
|
+
* all of that wallet's swaps. A different public key per swap removes the link.
|
|
4672
4681
|
*
|
|
4673
4682
|
* This changes NOTHING on chain or in the relay. `refund_pubkey` / `refund_blinding` remain
|
|
4674
4683
|
* caller-supplied values bound into `computeSwapExtDataHash`; only their provenance changes.
|
|
4675
4684
|
*
|
|
4676
|
-
* ──
|
|
4677
|
-
*
|
|
4678
|
-
*
|
|
4679
|
-
*
|
|
4680
|
-
*
|
|
4685
|
+
* ── Three refund shapes, all still recognised ─────────────────────────────────────────────────
|
|
4686
|
+
* "per-swap" (0.2.9+) owner = per-swap key from the owner private key (above)
|
|
4687
|
+
* "owner" (0.2.6 - 0.2.8) owner = the wallet's permanent UTXO keypair; linkable across swaps
|
|
4688
|
+
* "legacy-nk" (< 0.2.6) owner key AND blinding from nk; `legacyExposed: true`, because anyone
|
|
4689
|
+
* holding `nk` can spend it. An app should migrate those refunds.
|
|
4690
|
+
* No API builds a refund in the last two shapes any more.
|
|
4681
4691
|
*
|
|
4682
4692
|
* ── Guardrails preserved ──────────────────────────────────────────────────────────────────────
|
|
4683
4693
|
* [H-04 / DD-01] the authorization is rejected unless publicKey and blinding are both non-zero.
|
|
@@ -4698,14 +4708,20 @@ interface SwapRefundAuthorization {
|
|
|
4698
4708
|
publicKey: bigint;
|
|
4699
4709
|
blinding: bigint;
|
|
4700
4710
|
}
|
|
4711
|
+
/** Which key shape owns a refund leaf; see the file header. */
|
|
4712
|
+
type SwapRefundShape = "per-swap" | "owner" | "legacy-nk";
|
|
4701
4713
|
/** A refund leaf matched back to its owner. */
|
|
4702
4714
|
interface RecoveredSwapRefund {
|
|
4703
4715
|
/**
|
|
4704
|
-
* The
|
|
4705
|
-
* (`privateKey` is `0n`
|
|
4706
|
-
*
|
|
4716
|
+
* The key that owns the leaf. `per-swap`: the key derived from the owner private key and the
|
|
4717
|
+
* swap nullifier (`privateKey` is `0n` for a view-only match: the public key is real, but the
|
|
4718
|
+
* spend key needs the owner private key, see {@link deriveSwapRefundKeypair}). `owner`: the
|
|
4719
|
+
* `ownerUtxoKeypair` the matcher was given (`privateKey` `0n` if only the public key was
|
|
4720
|
+
* supplied). `legacy-nk`: the nk-derived keypair, complete and spendable.
|
|
4707
4721
|
*/
|
|
4708
4722
|
keypair: UtxoKeypair;
|
|
4723
|
+
/** Which of the three shapes matched. */
|
|
4724
|
+
shape: SwapRefundShape;
|
|
4709
4725
|
blinding: bigint;
|
|
4710
4726
|
amount: bigint;
|
|
4711
4727
|
/** R_fb as a field element, identical to the commitment `CloseSwapState` appended. */
|
|
@@ -4724,8 +4740,15 @@ interface RecoveredSwapRefund {
|
|
|
4724
4740
|
*/
|
|
4725
4741
|
declare function deriveSwapRefundBlinding(viewingKeyNk: Uint8Array, inputNullifier: Uint8Array | bigint): bigint;
|
|
4726
4742
|
/**
|
|
4727
|
-
* The refund
|
|
4728
|
-
*
|
|
4743
|
+
* The per-swap refund KEYPAIR: a different key for every swap, derived from the owner's private key
|
|
4744
|
+
* and the swap's first input nullifier. `nk` cannot reproduce it. Use this to spend a refund the
|
|
4745
|
+
* swap result reported, or any `per-swap` refund a view-only scan found.
|
|
4746
|
+
*/
|
|
4747
|
+
declare function deriveSwapRefundKeypair(ownerUtxoKeypair: UtxoKeypair, inputNullifier: Uint8Array | bigint): Promise<UtxoKeypair>;
|
|
4748
|
+
/**
|
|
4749
|
+
* The refund authorization `swapUtxo` binds into the swap ext-data hash: a per-swap keypair derived
|
|
4750
|
+
* from the wallet's UTXO private key and the swap's first input nullifier, plus the nk-derived
|
|
4751
|
+
* blinding. The public key differs for every swap and differs from the wallet's UTXO public key.
|
|
4729
4752
|
*
|
|
4730
4753
|
* `ownerUtxoKeypair` is required and validated. The refund key is never derived from `nk`.
|
|
4731
4754
|
*/
|
|
@@ -4752,16 +4775,28 @@ interface MatchSwapRefundLeafParams {
|
|
|
4752
4775
|
commitment: bigint | Uint8Array;
|
|
4753
4776
|
/**
|
|
4754
4777
|
* The wallet's long-lived UTXO keypair (`privateKey: 0n` is fine for a view-only match). Without
|
|
4755
|
-
* it only legacy refunds can be matched.
|
|
4778
|
+
* it only legacy-nk refunds can be matched.
|
|
4756
4779
|
*/
|
|
4757
4780
|
ownerUtxoKeypair?: UtxoKeypair;
|
|
4781
|
+
/**
|
|
4782
|
+
* `refund_pubkey` as published in the swap's TransactSwap instruction data (bytes 593-624) or its
|
|
4783
|
+
* SwapState. A view-only scanner needs it to match a `per-swap` refund, because it cannot derive
|
|
4784
|
+
* the key. Pass it together with {@link publishedRefundBlinding}.
|
|
4785
|
+
*/
|
|
4786
|
+
publishedRefundPubkey?: bigint | Uint8Array;
|
|
4787
|
+
/** `refund_blinding` as published in the same place (bytes 625-656). */
|
|
4788
|
+
publishedRefundBlinding?: bigint | Uint8Array;
|
|
4758
4789
|
}
|
|
4759
4790
|
/**
|
|
4760
4791
|
* Decide whether a public refund leaf belongs to this wallet, and if so return it. Returns `null`
|
|
4761
4792
|
* for every leaf that is not ours; a scanner runs this against every close it can see.
|
|
4762
4793
|
*
|
|
4763
|
-
* Tries the
|
|
4764
|
-
*
|
|
4794
|
+
* Tries, in order: the per-swap shape (published pubkey, or re-derived when the owner private key
|
|
4795
|
+
* is present), the 0.2.6 - 0.2.8 owner-key shape, then the legacy nk shape (`legacyExposed`).
|
|
4796
|
+
* `shape` on the result says which one matched.
|
|
4797
|
+
*
|
|
4798
|
+
* A per-swap match from a view-only scan returns `keypair.privateKey === 0n`; the caller spends it
|
|
4799
|
+
* with {@link deriveSwapRefundKeypair} once it holds the owner private key.
|
|
4765
4800
|
*/
|
|
4766
4801
|
declare function matchSwapRefundLeaf(params: MatchSwapRefundLeafParams): Promise<RecoveredSwapRefund | null>;
|
|
4767
4802
|
/** One recovered refund leaf, with the chain coordinates that produced it. */
|
|
@@ -4777,9 +4812,11 @@ interface DiscoveredSwapRefund extends RecoveredSwapRefund {
|
|
|
4777
4812
|
}
|
|
4778
4813
|
interface DiscoverSwapRefundsOptions {
|
|
4779
4814
|
/**
|
|
4780
|
-
* The wallet's long-lived UTXO keypair
|
|
4781
|
-
*
|
|
4782
|
-
* for a view-only scan
|
|
4815
|
+
* The wallet's long-lived UTXO keypair. Required. Pass the real keypair to get spendable
|
|
4816
|
+
* results (per-swap refunds come back with their derived keypair), or `{ privateKey: 0n,
|
|
4817
|
+
* publicKey }` for a view-only scan: per-swap refunds are then matched from the `refund_pubkey`
|
|
4818
|
+
* published in the swap instruction and come back with `privateKey: 0n` (re-derive it with
|
|
4819
|
+
* `deriveSwapRefundKeypair`). Legacy (nk-owned) refunds are found either way and flagged
|
|
4783
4820
|
* `legacyExposed`.
|
|
4784
4821
|
*/
|
|
4785
4822
|
ownerUtxoKeypair: UtxoKeypair;
|
|
@@ -4807,7 +4844,7 @@ interface DiscoverSwapRefundsOptions {
|
|
|
4807
4844
|
* its owner could not see it under any key they held.
|
|
4808
4845
|
*
|
|
4809
4846
|
* FORWARD-LOOKING ONLY. This finds refunds whose blinding was DERIVED from (nk, nullifier0), owned
|
|
4810
|
-
*
|
|
4847
|
+
* by a per-swap key (0.2.9+), the wallet UTXO key (0.2.6-0.2.8) or an nk-derived key (legacy, flagged).
|
|
4811
4848
|
* A swap whose refund keypair and blinding were drawn from raw randomness (every swap submitted
|
|
4812
4849
|
* before that derivation shipped) has no derivation to replay,
|
|
4813
4850
|
* and no key-only scan can ever recover it. Those secrets existed solely in the caller's in-memory
|
|
@@ -6421,4 +6458,4 @@ declare const VERSION = "0.2.6";
|
|
|
6421
6458
|
/** True when scanner supports TransactSwap (tag 1). Check this to verify the correct SDK bundle is loaded. */
|
|
6422
6459
|
declare const SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
6423
6460
|
|
|
6424
|
-
export { BRIDGE_ESCROW_LABEL, BRIDGE_ESCROW_LABEL_V2, BUILD_ALLOWS_LOCAL_ENDPOINTS, type BridgeDeliveryState, type BridgeDeposit, type BridgeDepositState, type BridgeQuoteAssessment, type BridgeQuoteInput, type BridgeRail, type BridgeRailAttestation, type BridgeRailProblem, type BridgeRailQuoteOption, type BridgeRailQuoteRequest, type BridgeRailQuoteResponse, type BridgeRailStatusResult, type BuildRecipientDeliveryNotesParams, CHAIN_NOTE_SALT_BITS, CLEANUP_FEE_BUDGET, CLOAK_PRODUCTION_RELAY_URL, CLOAK_PROGRAM_ID, type ChainNoteTxType, type CircuitVerificationResult, type CleanupResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, type CloakRpc, type CommitmentEntry, type CommitmentsResponse, type CompactChainNote, type ComplianceReport, type ComplianceTxType, type ConfirmSettlementParams, type CreateRecoverableDepositUtxoParams, DEFAULT_CIRCUITS_URL, DEFAULT_TRANSACTION_CIRCUITS_URL, DELIVERY_MEMO_TAG, DELIVERY_REGISTRY_SEED, type DeliveredNote, DepositError, type DepositInstructionParams, type DepositNoteSecrets, type DepositOptions, type DepositOutcome, type DepositRef, type DepositResult, type DepositStatus, type DiscoverOptions, type DiscoverSwapRefundsOptions, type DiscoveredSwapRefund, DoNotRetry, ECONOMIC_MINIMUM, EXPECTED_CIRCUIT_HASHES, type EncodeNoteIndexPageParams, type EncryptedMetadataBundle, type EncryptedNote$1 as EncryptedNote, type ErrorCategory, type ExpandedSpendKey, type ExternalFeePayerAdapter, FEE_BUDGET, FIXED_FEE_LAMPORTS, type FundingPlan, type Groth16Proof, type IndexedRecoveredNote, type IndexedRecoveredNoteKind, InsecureRandomnessError, LAMPORTS_PER_SOL, type LegacyWalletAdapter, type WalletSigner as LegacyWalletSigner, LocalStorageAdapter, type LogLevel, type Logger, type LookupTable, MAINNET_RENT_0, MAINNET_RENT_1, MAX_RECEIVER_INDEX, MERKLE_TREE_HEIGHT, MIN_DEPOSIT_LAMPORTS, MIN_DEPOSIT_SPL_BASE_UNITS, type MasterKey, type MatchChangeNoteParams, type MatchDepositNoteParams, type MatchSwapRefundLeafParams, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, MerkleTree, type MessageSigner, NATIVE_SOL_MINT, NOTE_INDEX_NO_LEAF, NOTE_INDEX_PAGE_SIZE, type Network, type NoteData, type NoteIndexCursor, type NoteIndexDeliveryItem, type NoteIndexFetchOptions, NoteIndexFormatError, type NoteIndexHead, NoteIndexHeadBehindError, type NoteIndexItem, type NoteIndexPage, type NoteIndexRecoveryStats, type NoteIndexSwapRefundItem, type NoteIndexTxItem, ONECLICK_PUBKEY_B58, type OnchainMerkleProof, type ParseNoteIndexPageOptions, type ParsedDeliveryCarrier, type PaymasterTopUpExpectation, type PaymasterTopUpResult, type PendingDeposit, type PendingWithdrawal, type PostFailureVerdict, RECIPIENT_DELIVERY_CIPHERTEXT_LEN, RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN, RECIPIENT_DELIVERY_NONCE_LEN, RECIPIENT_DELIVERY_NOTE_BYTES, RECIPIENT_DELIVERY_PLAINTEXT_LEN, RECIPIENT_DELIVERY_TAG_LEN, RELAY_BATCH_AUTH_MAX_ITEMS, RELAY_ORIGIN_ALLOWLIST, REQUEST_AUTH_BATCH_DOMAIN, REQUEST_AUTH_BATCH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS, type RecipientDeliveryNote, type RecoverNotesFromIndexParams, type RecoverNotesFromIndexResult, type RecoveredChangeNote, type RecoveredChangeNoteRecord, type RecoveredDepositNote, type RecoveredDepositNoteRecord, type RecoveredSwapRefund, type RelayAuthMode, type RelayAuthPreimage, type RelayAuthSigner, RelayBatchAuthCoordinator, type RelayBatchAuthCoordinatorOptions, type RelayBatchAuthEnvelope, type RelayBatchAuthFields, type RelayBatchAuthItemHandle, RelayInternalError, RelayService, type RelaySubmissionResult, type RentRates, type RetryHooks, type RiskQuoteInstructionResponse, RootNotFoundError, SCANNER_SUPPORTS_TRANSACT_SWAP, SIGN_IN_MESSAGE, SanctionsQuoteError, type ScanOptions, type ScanRecipientDeliveryOptions, type ScanResult, type ScanSummary, type ScannedTransaction, type SettlementConnection, type SettlementContext, type SettlementStatus, type SettlementVerdict, SettlementVerificationError, ShieldPoolErrors, type ShieldPoolPDAs, SimpleWallet, type SpendKey, type SpendOptions, type StorageAdapter, type SubmitTransactToRelayArgs, type SwapOptions, type SwapParams, type SwapRefundAuthorization, type SwapResult, TERMINAL_FAILURE, TRANSACTION_CIRCUITS_VERSION, TRANSACT_AUTH_FIELDS, TRANSACT_SWAP_AUTH_FIELDS, type TransactBatchItem, type TransactBatchItemOutcome, type TransactBatchOptions, type TransactBatchResult, type TransactOptions, type TransactParams, type TransactRequestBodyParams, type TransactResult, TransactionConfirmationError, type TransactionMetadata, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, type Utxo, UtxoAlreadySpentError, type EncryptedNote as UtxoEncryptedNote, type UtxoKeypair, type UtxoSwapParams, type UtxoSwapResult, UtxoWallet, VARIABLE_FEE_DENOMINATOR, VARIABLE_FEE_NUMERATOR, VARIABLE_FEE_RATE, VERSION, type VerifyUtxosResult, type ViewKey, type ViewingKeyPair, WITHDRAW_FEE_BPS, WITHDRAW_FIXED_FEE, type WalletAdapterBridgeOptions, type WalletSigner$1 as WalletSigner, type WalletUtxo, type Web3Module, type WithdrawOptions, type WithdrawSubmissionResult, accountMeta, addressBytes, addressFromBytes, addressFromPublicKey, assertDirectSubmissionLanded, assertInputMints, assertTransactionCircuitIntegrity, assessBridgeQuote, bigintToBytes32$1 as bigintToBytes32, bigintToHex, buildAuthTransactionMessage, buildMerkleTree, buildMerkleTreeFromChain, buildMerkleTreeFromRelay, buildRecipientDeliveryNotes, buildRelayAuthPreimage, buildRelayBatchAuthMessage, buildTransactRequestBody, buildTransactionMessage, bytesToHex, calculateFee, calculateFeeBigint, calculateRelayFee, canRebuildMerkleTreeFromChain, canonicalJson, canonicalPayloadString, chainNoteFromBase64, chainNoteToBase64, classifyPostFailure, classifyRelayError, cleanupReceivingAddress, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, cloakBridgeRail, computeChainNoteHash, computeExtDataHash, computeMerkleRoot, computeNoteIndexChain, computeProofForLatestDeposit, computeProofFromChain, computeSignature, computeSwapRefundCommitment, computeCommitment as computeUtxoCommitment, computeNullifier as computeUtxoNullifier, confirmSignature, confirmTransactSettlement, copyNoteToClipboard, createCloakError, createCloakRpc, createDepositInstruction, createLogger, createRecoverableChangeUtxo, createRecoverableDepositUtxo, createRelayBatchAuthCoordinator, createUtxo, createZeroUtxo, decryptCompactChainNote, decryptComplianceMetadataWithMasterKey, decryptTransactionMetadata, depositFromDerivedKey, deriveBridgeReceiver, deriveChangeNoteBlinding, deriveDepositNoteBlinding, deriveDiversifiedViewingKey, deriveDiversifier, deriveFundingTargets, deriveInputNullifierPdas, deriveLegacyBridgeReceiver, deriveLegacyDepositNoteSecrets, deriveLegacySwapRefundAuthorization, derivePublicKey, deriveSpendKey, deriveSwapRefundAuthorization, deriveSwapRefundBlinding, deriveUserCompliancePublicKey, deriveUserComplianceScalar, deriveUtxoKeypairFromSpendKey, deriveViewKey, deriveViewingKeyFromNk, deriveViewingKeyFromSpendKey, deriveViewingKeyFromUtxoPrivateKey, deserializeUtxo, detectNetworkFromRpcUrl, discoverSwapRefunds, downloadNote, encodeDeliveryCarrierMemo, encodeNoteIndexItem, encodeNoteIndexPage, encodeNoteSimple, encodeRecipientDeliveryNote, encryptCompactChainNote, encryptNoteForRecipient, encryptTransactionMetadata, encryptTransactionMetadataBundle, expandSpendKey, explainRelayAuthRejection, exportKeys, exportNote, exportWalletKeys, fetchAccountBytes, fetchCommitments, fetchLatestBlockhash, fetchLookupTables, fetchNoteIndexHead, fetchNoteIndexPage, fetchRiskQuoteInstruction, fetchRiskQuoteIx, fetchSignaturesForAddress, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, findProgramAddress, formatAmount, formatComplianceCsv, formatErrorForLogging, formatSol, fullWithdraw, fundReceiverViaPaymaster, generateCloakKeys, generateCommitmentAsync, generateMasterSeed, generateNoteFromWallet, generateUtxoKeypair, generateViewingKeyPair, getAddressExplorerUrl, getChainNoteRegistryPDA, getCircuitsPath, getDeliveryRegistryPDA, getDistributableAmount, getExplorerUrl, getNkFromUtxoPrivateKey, getNullifierPDA, getPendingOperationsSummary, getPoolAuthorityConfigPDA, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getSwapStatePDA, getViewKey, hasPendingOperations, hexToBigint$1 as hexToBigint, hexToBytes, importKeys, importWalletKeys, isBrowser, isBrowserLike, isDebugEnabled, isMessageSigner, isPlausibleSignature, isReactNative, isRootNotFoundError, isSubmissionOutcomeUnknownResponse, isTerminalFailure, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawAmountSufficient, isWithdrawable, listBridgeDeposits, loadPendingDeposits, loadPendingWithdrawals, loadVerifiedCircuitArtifacts, matchChangeNote, matchDepositNote, matchSwapRefundLeaf, mayRetry, messageSignerFromCallback, openRecipientDeliveryNote, parseAmount, parseDeliveryCarrierMemo, parseError, parseNote, parseNoteIndexItem, parseNoteIndexPage, parseRelayErrorResponse, parseRelayErrorSignature, parseTransactionError, partialWithdraw, partiallySignTransaction, poseidonHash, preflightCheck, preflightNullifiers, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, programInstruction, proofToBytes, pubkeyToFieldElement, pubkeyToLimbs, randomBytes, randomChangeNoteSalt, randomDepositNoteSalt, randomFieldElement, readMerkleTreeState, readRent, recipientDeliveryNoteToBase64, recoverNotesFromIndex, registerViewingKey, relayRequestDigestHex, removePendingDeposit, removePendingWithdrawal, renderAssessment, resolveCircuitsBase, retryDelayMs, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, scanRecipientDeliveryNotes, scanTransactions, sdkLogger, selectUtxos, sendInstructions, sendRawTransaction, sendTransaction, serializeAuthTransactionMessage, serializeNote, serializeUtxo, setCircuitsPath, setDebugMode, signCompiledTransaction, signMessageBytes, signRelayAuthPayload, signTransaction, signerFromKeypair, signerFromSecretKey, signerFromWalletAdapter, splitTo2Limbs, submitTransactToRelay, sumUtxoAmounts, swapUtxo, swapWithChange, toAddress, toComplianceReport, transact, transactBatch, transactionBase64, transactionBytes, transactionFromBytes, transactionWireSize, transfer, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, bigintToBytes32 as utxoBigintToBytes32, utxoEquals, hexToBigint as utxoHexToBigint, validateDepositParams, validateNote, validateOutputsSum, validatePaymasterTopUpTransaction, validateRoot, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, verifyQuoteSignature, verifyUtxos, waitForRoot, withShieldRetries, withTiming, withdrawFeeFor };
|
|
6461
|
+
export { BRIDGE_ESCROW_LABEL, BRIDGE_ESCROW_LABEL_V2, BUILD_ALLOWS_LOCAL_ENDPOINTS, type BridgeDeliveryState, type BridgeDeposit, type BridgeDepositState, type BridgeQuoteAssessment, type BridgeQuoteInput, type BridgeRail, type BridgeRailAttestation, type BridgeRailProblem, type BridgeRailQuoteOption, type BridgeRailQuoteRequest, type BridgeRailQuoteResponse, type BridgeRailStatusResult, type BuildRecipientDeliveryNotesParams, CHAIN_NOTE_SALT_BITS, CLEANUP_FEE_BUDGET, CLOAK_PRODUCTION_RELAY_URL, CLOAK_PROGRAM_ID, type ChainNoteTxType, type CircuitVerificationResult, type CleanupResult, type CloakConfig, CloakError, type CloakKeyPair, type CloakNote, type CloakRpc, type CommitmentEntry, type CommitmentsResponse, type CompactChainNote, type ComplianceReport, type ComplianceTxType, type ConfirmSettlementParams, type CreateRecoverableDepositUtxoParams, DEFAULT_CIRCUITS_URL, DEFAULT_TRANSACTION_CIRCUITS_URL, DELIVERY_MEMO_TAG, DELIVERY_REGISTRY_SEED, type DeliveredNote, DepositError, type DepositInstructionParams, type DepositNoteSecrets, type DepositOptions, type DepositOutcome, type DepositRef, type DepositResult, type DepositStatus, type DiscoverOptions, type DiscoverSwapRefundsOptions, type DiscoveredSwapRefund, DoNotRetry, ECONOMIC_MINIMUM, EXPECTED_CIRCUIT_HASHES, type EncodeNoteIndexPageParams, type EncryptedMetadataBundle, type EncryptedNote$1 as EncryptedNote, type ErrorCategory, type ExpandedSpendKey, type ExternalFeePayerAdapter, FEE_BUDGET, FIXED_FEE_LAMPORTS, type FundingPlan, type Groth16Proof, type IndexedRecoveredNote, type IndexedRecoveredNoteKind, InsecureRandomnessError, LAMPORTS_PER_SOL, type LegacyWalletAdapter, type WalletSigner as LegacyWalletSigner, LocalStorageAdapter, type LogLevel, type Logger, type LookupTable, MAINNET_RENT_0, MAINNET_RENT_1, MAX_RECEIVER_INDEX, MERKLE_TREE_HEIGHT, MIN_DEPOSIT_LAMPORTS, MIN_DEPOSIT_SPL_BASE_UNITS, type MasterKey, type MatchChangeNoteParams, type MatchDepositNoteParams, type MatchSwapRefundLeafParams, type MaxLengthArray, MemoryStorageAdapter, type MerkleProof, type MerkleRootResponse, MerkleTree, type MessageSigner, NATIVE_SOL_MINT, NOTE_INDEX_NO_LEAF, NOTE_INDEX_PAGE_SIZE, type Network, type NoteData, type NoteIndexCursor, type NoteIndexDeliveryItem, type NoteIndexFetchOptions, NoteIndexFormatError, type NoteIndexHead, NoteIndexHeadBehindError, type NoteIndexItem, type NoteIndexPage, type NoteIndexRecoveryStats, type NoteIndexSwapRefundItem, type NoteIndexTxItem, ONECLICK_PUBKEY_B58, type OnchainMerkleProof, type ParseNoteIndexPageOptions, type ParsedDeliveryCarrier, type PaymasterTopUpExpectation, type PaymasterTopUpResult, type PendingDeposit, type PendingWithdrawal, type PostFailureVerdict, RECIPIENT_DELIVERY_CIPHERTEXT_LEN, RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN, RECIPIENT_DELIVERY_NONCE_LEN, RECIPIENT_DELIVERY_NOTE_BYTES, RECIPIENT_DELIVERY_PLAINTEXT_LEN, RECIPIENT_DELIVERY_TAG_LEN, RELAY_BATCH_AUTH_MAX_ITEMS, RELAY_ORIGIN_ALLOWLIST, REQUEST_AUTH_BATCH_DOMAIN, REQUEST_AUTH_BATCH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_AGE_SECONDS, REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS, type RecipientDeliveryNote, type RecoverNotesFromIndexParams, type RecoverNotesFromIndexResult, type RecoveredChangeNote, type RecoveredChangeNoteRecord, type RecoveredDepositNote, type RecoveredDepositNoteRecord, type RecoveredSwapRefund, type RelayAuthMode, type RelayAuthPreimage, type RelayAuthSigner, RelayBatchAuthCoordinator, type RelayBatchAuthCoordinatorOptions, type RelayBatchAuthEnvelope, type RelayBatchAuthFields, type RelayBatchAuthItemHandle, RelayInternalError, RelayService, type RelaySubmissionResult, type RentRates, type RetryHooks, type RiskQuoteInstructionResponse, RootNotFoundError, SCANNER_SUPPORTS_TRANSACT_SWAP, SIGN_IN_MESSAGE, SanctionsQuoteError, type ScanOptions, type ScanRecipientDeliveryOptions, type ScanResult, type ScanSummary, type ScannedTransaction, type SettlementConnection, type SettlementContext, type SettlementStatus, type SettlementVerdict, SettlementVerificationError, ShieldPoolErrors, type ShieldPoolPDAs, SimpleWallet, type SpendKey, type SpendOptions, type StorageAdapter, type SubmitTransactToRelayArgs, type SwapOptions, type SwapParams, type SwapRefundAuthorization, type SwapRefundShape, type SwapResult, TERMINAL_FAILURE, TRANSACTION_CIRCUITS_VERSION, TRANSACT_AUTH_FIELDS, TRANSACT_SWAP_AUTH_FIELDS, type TransactBatchItem, type TransactBatchItemOutcome, type TransactBatchOptions, type TransactBatchResult, type TransactOptions, type TransactParams, type TransactRequestBodyParams, type TransactResult, TransactionConfirmationError, type TransactionMetadata, type Transfer, type TransferOptions, type TransferResult, type TxStatus, type UserFriendlyError, type Utxo, UtxoAlreadySpentError, type EncryptedNote as UtxoEncryptedNote, type UtxoKeypair, type UtxoSwapParams, type UtxoSwapResult, UtxoWallet, VARIABLE_FEE_DENOMINATOR, VARIABLE_FEE_NUMERATOR, VARIABLE_FEE_RATE, VERSION, type VerifyUtxosResult, type ViewKey, type ViewingKeyPair, WITHDRAW_FEE_BPS, WITHDRAW_FIXED_FEE, type WalletAdapterBridgeOptions, type WalletSigner$1 as WalletSigner, type WalletUtxo, type Web3Module, type WithdrawOptions, type WithdrawSubmissionResult, accountMeta, addressBytes, addressFromBytes, addressFromPublicKey, assertDirectSubmissionLanded, assertInputMints, assertTransactionCircuitIntegrity, assessBridgeQuote, bigintToBytes32$1 as bigintToBytes32, bigintToHex, buildAuthTransactionMessage, buildMerkleTree, buildMerkleTreeFromChain, buildMerkleTreeFromRelay, buildRecipientDeliveryNotes, buildRelayAuthPreimage, buildRelayBatchAuthMessage, buildTransactRequestBody, buildTransactionMessage, bytesToHex, calculateFee, calculateFeeBigint, calculateRelayFee, canRebuildMerkleTreeFromChain, canonicalJson, canonicalPayloadString, chainNoteFromBase64, chainNoteToBase64, classifyPostFailure, classifyRelayError, cleanupReceivingAddress, cleanupStalePendingOperations, clearPendingDeposits, clearPendingWithdrawals, cloakBridgeRail, computeChainNoteHash, computeExtDataHash, computeMerkleRoot, computeNoteIndexChain, computeProofForLatestDeposit, computeProofFromChain, computeSignature, computeSwapRefundCommitment, computeCommitment as computeUtxoCommitment, computeNullifier as computeUtxoNullifier, confirmSignature, confirmTransactSettlement, copyNoteToClipboard, createCloakError, createCloakRpc, createDepositInstruction, createLogger, createRecoverableChangeUtxo, createRecoverableDepositUtxo, createRelayBatchAuthCoordinator, createUtxo, createZeroUtxo, decryptCompactChainNote, decryptComplianceMetadataWithMasterKey, decryptTransactionMetadata, depositFromDerivedKey, deriveBridgeReceiver, deriveChangeNoteBlinding, deriveDepositNoteBlinding, deriveDiversifiedViewingKey, deriveDiversifier, deriveFundingTargets, deriveInputNullifierPdas, deriveLegacyBridgeReceiver, deriveLegacyDepositNoteSecrets, deriveLegacySwapRefundAuthorization, derivePublicKey, deriveSpendKey, deriveSwapRefundAuthorization, deriveSwapRefundBlinding, deriveSwapRefundKeypair, deriveUserCompliancePublicKey, deriveUserComplianceScalar, deriveUtxoKeypairFromSpendKey, deriveViewKey, deriveViewingKeyFromNk, deriveViewingKeyFromSpendKey, deriveViewingKeyFromUtxoPrivateKey, deserializeUtxo, detectNetworkFromRpcUrl, discoverSwapRefunds, downloadNote, encodeDeliveryCarrierMemo, encodeNoteIndexItem, encodeNoteIndexPage, encodeNoteSimple, encodeRecipientDeliveryNote, encryptCompactChainNote, encryptNoteForRecipient, encryptTransactionMetadata, encryptTransactionMetadataBundle, expandSpendKey, explainRelayAuthRejection, exportKeys, exportNote, exportWalletKeys, fetchAccountBytes, fetchCommitments, fetchLatestBlockhash, fetchLookupTables, fetchNoteIndexHead, fetchNoteIndexPage, fetchRiskQuoteInstruction, fetchRiskQuoteIx, fetchSignaturesForAddress, filterNotesByNetwork, filterWithdrawableNotes, findNoteByCommitment, findProgramAddress, formatAmount, formatComplianceCsv, formatErrorForLogging, formatSol, fullWithdraw, fundReceiverViaPaymaster, generateCloakKeys, generateCommitmentAsync, generateMasterSeed, generateNoteFromWallet, generateUtxoKeypair, generateViewingKeyPair, getAddressExplorerUrl, getChainNoteRegistryPDA, getCircuitsPath, getDeliveryRegistryPDA, getDistributableAmount, getExplorerUrl, getNkFromUtxoPrivateKey, getNullifierPDA, getPendingOperationsSummary, getPoolAuthorityConfigPDA, getPublicKey, getPublicViewKey, getRecipientAmount, getRpcUrlForNetwork, getShieldPoolPDAs, getSwapStatePDA, getViewKey, hasPendingOperations, hexToBigint$1 as hexToBigint, hexToBytes, importKeys, importWalletKeys, isBrowser, isBrowserLike, isDebugEnabled, isMessageSigner, isPlausibleSignature, isReactNative, isRootNotFoundError, isSubmissionOutcomeUnknownResponse, isTerminalFailure, isValidHex, isValidRpcUrl, isValidSolanaAddress, isWithdrawAmountSufficient, isWithdrawable, listBridgeDeposits, loadPendingDeposits, loadPendingWithdrawals, loadVerifiedCircuitArtifacts, matchChangeNote, matchDepositNote, matchSwapRefundLeaf, mayRetry, messageSignerFromCallback, openRecipientDeliveryNote, parseAmount, parseDeliveryCarrierMemo, parseError, parseNote, parseNoteIndexItem, parseNoteIndexPage, parseRelayErrorResponse, parseRelayErrorSignature, parseTransactionError, partialWithdraw, partiallySignTransaction, poseidonHash, preflightCheck, preflightNullifiers, prepareEncryptedOutput, prepareEncryptedOutputForRecipient, programInstruction, proofToBytes, pubkeyToFieldElement, pubkeyToLimbs, randomBytes, randomChangeNoteSalt, randomDepositNoteSalt, randomFieldElement, readMerkleTreeState, readRent, recipientDeliveryNoteToBase64, recoverNotesFromIndex, registerViewingKey, relayRequestDigestHex, removePendingDeposit, removePendingWithdrawal, renderAssessment, resolveCircuitsBase, retryDelayMs, savePendingDeposit, savePendingWithdrawal, scanNotesForWallet, scanRecipientDeliveryNotes, scanTransactions, sdkLogger, selectUtxos, sendInstructions, sendRawTransaction, sendTransaction, serializeAuthTransactionMessage, serializeNote, serializeUtxo, setCircuitsPath, setDebugMode, signCompiledTransaction, signMessageBytes, signRelayAuthPayload, signTransaction, signerFromKeypair, signerFromSecretKey, signerFromWalletAdapter, splitTo2Limbs, submitTransactToRelay, sumUtxoAmounts, swapUtxo, swapWithChange, toAddress, toComplianceReport, transact, transactBatch, transactionBase64, transactionBytes, transactionFromBytes, transactionWireSize, transfer, truncate, tryDecryptNote, updateNoteWithDeposit, updatePendingDeposit, updatePendingWithdrawal, bigintToBytes32 as utxoBigintToBytes32, utxoEquals, hexToBigint as utxoHexToBigint, validateDepositParams, validateNote, validateOutputsSum, validatePaymasterTopUpTransaction, validateRoot, validateTransfers, validateWalletConnected, validateWithdrawableNote, verifyAllCircuits, verifyCircuitIntegrity, verifyQuoteSignature, verifyUtxos, waitForRoot, withShieldRetries, withTiming, withdrawFeeFor };
|
package/dist/index.js
CHANGED
|
@@ -5172,6 +5172,8 @@ function normalizeOwnerPublicKey(publicKey, label) {
|
|
|
5172
5172
|
// src/notes/swap-refund.ts
|
|
5173
5173
|
var bs582 = _bs582.default || _bs582;
|
|
5174
5174
|
var REFUND_SEED_DOMAIN = new TextEncoder().encode("cloak_swap_refund_v1");
|
|
5175
|
+
var REFUND_KEY_DOMAIN_V2 = new TextEncoder().encode("cloak_swap_refund_v2");
|
|
5176
|
+
var REFUND_PRIVATE_KEY_INFO_V2 = new TextEncoder().encode("sk_v2");
|
|
5175
5177
|
var LEGACY_REFUND_PRIVATE_KEY_INFO = new TextEncoder().encode("sk");
|
|
5176
5178
|
var REFUND_BLINDING_INFO = new TextEncoder().encode("blinding");
|
|
5177
5179
|
function normalizeNullifier(inputNullifier) {
|
|
@@ -5216,13 +5218,35 @@ function deriveSwapRefundBlinding(viewingKeyNk, inputNullifier) {
|
|
|
5216
5218
|
const nk = assertNk(viewingKeyNk);
|
|
5217
5219
|
return toFieldSecret(derive(nk, normalizeNullifier(inputNullifier), REFUND_BLINDING_INFO));
|
|
5218
5220
|
}
|
|
5219
|
-
|
|
5221
|
+
function privateKeyBytes(privateKey) {
|
|
5222
|
+
return Uint8Array.from(Buffer.from(privateKey.toString(16).padStart(64, "0"), "hex"));
|
|
5223
|
+
}
|
|
5224
|
+
async function deriveSwapRefundKeypair(ownerUtxoKeypair, inputNullifier) {
|
|
5220
5225
|
const owner = await assertOwnerUtxoKeypair(ownerUtxoKeypair);
|
|
5226
|
+
const nullifier = normalizeNullifier(inputNullifier);
|
|
5227
|
+
const preimage = new Uint8Array(
|
|
5228
|
+
REFUND_KEY_DOMAIN_V2.length + 32 + nullifier.length + REFUND_PRIVATE_KEY_INFO_V2.length
|
|
5229
|
+
);
|
|
5230
|
+
let off = 0;
|
|
5231
|
+
preimage.set(REFUND_KEY_DOMAIN_V2, off);
|
|
5232
|
+
off += REFUND_KEY_DOMAIN_V2.length;
|
|
5233
|
+
preimage.set(privateKeyBytes(owner.privateKey), off);
|
|
5234
|
+
off += 32;
|
|
5235
|
+
preimage.set(nullifier, off);
|
|
5236
|
+
off += nullifier.length;
|
|
5237
|
+
preimage.set(REFUND_PRIVATE_KEY_INFO_V2, off);
|
|
5238
|
+
const privateKey = toFieldSecret(blake33(preimage));
|
|
5239
|
+
const publicKey = await derivePublicKey(privateKey);
|
|
5240
|
+
if (publicKey === 0n) throw new Error("refund authorization is degenerate");
|
|
5241
|
+
return { privateKey, publicKey };
|
|
5242
|
+
}
|
|
5243
|
+
async function deriveSwapRefundAuthorization(viewingKeyNk, inputNullifier, ownerUtxoKeypair) {
|
|
5221
5244
|
const blinding = deriveSwapRefundBlinding(viewingKeyNk, inputNullifier);
|
|
5222
|
-
|
|
5245
|
+
const keypair = await deriveSwapRefundKeypair(ownerUtxoKeypair, inputNullifier);
|
|
5246
|
+
if (keypair.publicKey === 0n || blinding === 0n) {
|
|
5223
5247
|
throw new Error("refund authorization is degenerate");
|
|
5224
5248
|
}
|
|
5225
|
-
return { privateKey:
|
|
5249
|
+
return { privateKey: keypair.privateKey, publicKey: keypair.publicKey, blinding };
|
|
5226
5250
|
}
|
|
5227
5251
|
async function deriveLegacySwapRefundAuthorization(viewingKeyNk, inputNullifier) {
|
|
5228
5252
|
const nk = assertNk(viewingKeyNk);
|
|
@@ -5243,9 +5267,12 @@ async function computeSwapRefundCommitment(amountAfterFee, refundPublicKey, refu
|
|
|
5243
5267
|
mintAddress: NATIVE_SOL_MINT
|
|
5244
5268
|
});
|
|
5245
5269
|
}
|
|
5270
|
+
function toField(value) {
|
|
5271
|
+
return value instanceof Uint8Array ? BigInt("0x" + Buffer.from(value).toString("hex")) : value;
|
|
5272
|
+
}
|
|
5246
5273
|
async function matchSwapRefundLeaf(params) {
|
|
5247
5274
|
const { viewingKeyNk, inputNullifier, amountAfterFee } = params;
|
|
5248
|
-
const expected =
|
|
5275
|
+
const expected = toField(params.commitment);
|
|
5249
5276
|
let blinding;
|
|
5250
5277
|
try {
|
|
5251
5278
|
blinding = deriveSwapRefundBlinding(viewingKeyNk, inputNullifier);
|
|
@@ -5253,11 +5280,55 @@ async function matchSwapRefundLeaf(params) {
|
|
|
5253
5280
|
return null;
|
|
5254
5281
|
}
|
|
5255
5282
|
const ownerPub = normalizeOwnerPublicKey(params.ownerUtxoKeypair?.publicKey, "ownerUtxoKeypair.publicKey");
|
|
5283
|
+
const ownerPriv = params.ownerUtxoKeypair?.privateKey ?? 0n;
|
|
5284
|
+
let perSwapPub;
|
|
5285
|
+
let perSwapPriv = 0n;
|
|
5286
|
+
if (ownerPriv > 0n && ownerPub !== void 0) {
|
|
5287
|
+
try {
|
|
5288
|
+
const kp = await deriveSwapRefundKeypair({ privateKey: ownerPriv, publicKey: ownerPub }, inputNullifier);
|
|
5289
|
+
perSwapPub = kp.publicKey;
|
|
5290
|
+
perSwapPriv = kp.privateKey;
|
|
5291
|
+
} catch {
|
|
5292
|
+
return null;
|
|
5293
|
+
}
|
|
5294
|
+
}
|
|
5295
|
+
if (params.publishedRefundPubkey !== void 0 && params.publishedRefundBlinding !== void 0) {
|
|
5296
|
+
const published = toField(params.publishedRefundPubkey);
|
|
5297
|
+
const publishedBlinding = toField(params.publishedRefundBlinding);
|
|
5298
|
+
if (published !== 0n && publishedBlinding === blinding) {
|
|
5299
|
+
if (perSwapPub === void 0 || perSwapPub === published) {
|
|
5300
|
+
const candidate = await computeSwapRefundCommitment(amountAfterFee, published, blinding);
|
|
5301
|
+
if (candidate === expected && published !== ownerPub) {
|
|
5302
|
+
return {
|
|
5303
|
+
keypair: { privateKey: perSwapPub === published ? perSwapPriv : 0n, publicKey: published },
|
|
5304
|
+
shape: "per-swap",
|
|
5305
|
+
blinding,
|
|
5306
|
+
amount: amountAfterFee,
|
|
5307
|
+
commitment: candidate,
|
|
5308
|
+
legacyExposed: false
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5311
|
+
}
|
|
5312
|
+
}
|
|
5313
|
+
} else if (perSwapPub !== void 0) {
|
|
5314
|
+
const candidate = await computeSwapRefundCommitment(amountAfterFee, perSwapPub, blinding);
|
|
5315
|
+
if (candidate === expected) {
|
|
5316
|
+
return {
|
|
5317
|
+
keypair: { privateKey: perSwapPriv, publicKey: perSwapPub },
|
|
5318
|
+
shape: "per-swap",
|
|
5319
|
+
blinding,
|
|
5320
|
+
amount: amountAfterFee,
|
|
5321
|
+
commitment: candidate,
|
|
5322
|
+
legacyExposed: false
|
|
5323
|
+
};
|
|
5324
|
+
}
|
|
5325
|
+
}
|
|
5256
5326
|
if (ownerPub !== void 0) {
|
|
5257
5327
|
const candidate = await computeSwapRefundCommitment(amountAfterFee, ownerPub, blinding);
|
|
5258
5328
|
if (candidate === expected) {
|
|
5259
5329
|
return {
|
|
5260
|
-
keypair: { privateKey:
|
|
5330
|
+
keypair: { privateKey: ownerPriv, publicKey: ownerPub },
|
|
5331
|
+
shape: "owner",
|
|
5261
5332
|
blinding,
|
|
5262
5333
|
amount: amountAfterFee,
|
|
5263
5334
|
commitment: candidate,
|
|
@@ -5275,6 +5346,7 @@ async function matchSwapRefundLeaf(params) {
|
|
|
5275
5346
|
if (legacyCandidate !== expected) return null;
|
|
5276
5347
|
return {
|
|
5277
5348
|
keypair: { privateKey: legacy.privateKey, publicKey: legacy.publicKey },
|
|
5349
|
+
shape: "legacy-nk",
|
|
5278
5350
|
blinding: legacy.blinding,
|
|
5279
5351
|
amount: amountAfterFee,
|
|
5280
5352
|
commitment: legacyCandidate,
|
|
@@ -5286,6 +5358,9 @@ var PROOF_LEN2 = 256;
|
|
|
5286
5358
|
var NULLIFIER_0_OFFSET = 1 + PROOF_LEN2 + 104;
|
|
5287
5359
|
var PUBLIC_INPUTS_LEN2 = 264;
|
|
5288
5360
|
var MIN_TRANSACT_SWAP_LEN = 1 + PROOF_LEN2 + PUBLIC_INPUTS_LEN2;
|
|
5361
|
+
var REFUND_PUBKEY_OFFSET = 1 + PROOF_LEN2 + PUBLIC_INPUTS_LEN2 + 72;
|
|
5362
|
+
var REFUND_BLINDING_OFFSET = REFUND_PUBKEY_OFFSET + 32;
|
|
5363
|
+
var MIN_TRANSACT_SWAP_WITH_PARAMS_LEN = REFUND_BLINDING_OFFSET + 32;
|
|
5289
5364
|
function toBase58(key) {
|
|
5290
5365
|
if (!key) return void 0;
|
|
5291
5366
|
if (typeof key === "string") return key;
|
|
@@ -5348,7 +5423,7 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options)
|
|
|
5348
5423
|
}
|
|
5349
5424
|
if (!options || normalizeOwnerPublicKey(options.ownerUtxoKeypair?.publicKey, "options.ownerUtxoKeypair.publicKey") === void 0) {
|
|
5350
5425
|
throw new Error(
|
|
5351
|
-
"discoverSwapRefunds requires options.ownerUtxoKeypair (the wallet's long-lived UTXO keypair): refund leaves are
|
|
5426
|
+
"discoverSwapRefunds requires options.ownerUtxoKeypair (the wallet's long-lived UTXO keypair): per-swap and owner-key refund leaves are matched against it, and nk alone can only find legacy refunds."
|
|
5352
5427
|
);
|
|
5353
5428
|
}
|
|
5354
5429
|
const ownerUtxoKeypair = options.ownerUtxoKeypair;
|
|
@@ -5408,7 +5483,15 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options)
|
|
|
5408
5483
|
programId
|
|
5409
5484
|
);
|
|
5410
5485
|
const key = swapState;
|
|
5411
|
-
|
|
5486
|
+
const hasParams = data.length >= MIN_TRANSACT_SWAP_WITH_PARAMS_LEN;
|
|
5487
|
+
if (!nullifierBySwapState.has(key)) {
|
|
5488
|
+
nullifierBySwapState.set(key, {
|
|
5489
|
+
nullifier,
|
|
5490
|
+
signature,
|
|
5491
|
+
refundPubkey: hasParams ? data.slice(REFUND_PUBKEY_OFFSET, REFUND_PUBKEY_OFFSET + 32) : void 0,
|
|
5492
|
+
refundBlinding: hasParams ? data.slice(REFUND_BLINDING_OFFSET, REFUND_BLINDING_OFFSET + 32) : void 0
|
|
5493
|
+
});
|
|
5494
|
+
}
|
|
5412
5495
|
}
|
|
5413
5496
|
const logs = tx.meta?.logMessages;
|
|
5414
5497
|
const scan = scanRefundLeafEvents(logs, programIdBase58);
|
|
@@ -5427,7 +5510,9 @@ async function discoverSwapRefunds(connection, programId, viewingKeyNk, options)
|
|
|
5427
5510
|
inputNullifier: candidate.nullifier,
|
|
5428
5511
|
amountAfterFee: event.amountAfterFee,
|
|
5429
5512
|
commitment: event.commitmentField,
|
|
5430
|
-
ownerUtxoKeypair
|
|
5513
|
+
ownerUtxoKeypair,
|
|
5514
|
+
publishedRefundPubkey: candidate.refundPubkey,
|
|
5515
|
+
publishedRefundBlinding: candidate.refundBlinding
|
|
5431
5516
|
});
|
|
5432
5517
|
if (!recovered) continue;
|
|
5433
5518
|
const dedupe = `${close.signature}:${event.leafIndex}`;
|
|
@@ -12743,7 +12828,8 @@ async function matchOwnItems(own, owner, onReject, onSkip) {
|
|
|
12743
12828
|
atRisk: o.refund.legacyExposed,
|
|
12744
12829
|
amount: o.refund.amount,
|
|
12745
12830
|
blinding: o.refund.blinding,
|
|
12746
|
-
|
|
12831
|
+
// per-swap refunds carry their derived keypair; owner-shape ones carry the owner
|
|
12832
|
+
keypair: o.refund.keypair,
|
|
12747
12833
|
mint: NATIVE_SOL_MINT,
|
|
12748
12834
|
commitment: o.refund.commitment,
|
|
12749
12835
|
leaf: Number(item.leaf)
|
|
@@ -13409,7 +13495,8 @@ async function runOnce(ctx, cursor) {
|
|
|
13409
13495
|
for (const c of byLeaf.values()) {
|
|
13410
13496
|
const pubOk = keyChecked.get(c.keypair.privateKey) ?? (c.keypair.privateKey !== 0n && await derivePublicKey(c.keypair.privateKey) === c.keypair.publicKey);
|
|
13411
13497
|
keyChecked.set(c.keypair.privateKey, pubOk);
|
|
13412
|
-
|
|
13498
|
+
const ownerOk = c.keypair.publicKey === owner.publicKey || c.kind === "swap_refund";
|
|
13499
|
+
if (!pubOk || !c.atRisk && !ownerOk) {
|
|
13413
13500
|
stats.dropped++;
|
|
13414
13501
|
tally(c, "rejected");
|
|
13415
13502
|
continue;
|
|
@@ -13418,7 +13505,7 @@ async function runOnce(ctx, cursor) {
|
|
|
13418
13505
|
verifiedOut.add(verifiedKey(c.mint, c.leaf, c.commitment));
|
|
13419
13506
|
const utxo = {
|
|
13420
13507
|
amount: c.amount,
|
|
13421
|
-
keypair: c.atRisk ? { ...c.keypair } : owner,
|
|
13508
|
+
keypair: c.atRisk || c.kind === "swap_refund" ? { ...c.keypair } : owner,
|
|
13422
13509
|
blinding: c.blinding,
|
|
13423
13510
|
mintAddress: c.mint,
|
|
13424
13511
|
index: c.leaf,
|
|
@@ -14903,6 +14990,7 @@ export {
|
|
|
14903
14990
|
deriveSpendKey,
|
|
14904
14991
|
deriveSwapRefundAuthorization,
|
|
14905
14992
|
deriveSwapRefundBlinding,
|
|
14993
|
+
deriveSwapRefundKeypair,
|
|
14906
14994
|
deriveUserCompliancePublicKey,
|
|
14907
14995
|
deriveUserComplianceScalar,
|
|
14908
14996
|
deriveUtxoKeypairFromSpendKey,
|
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.6-staging.
|
|
4
|
+
"version": "0.2.6-staging.d98da76",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|