@cloak.dev/sdk 0.2.13 → 0.2.14
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/CHANGELOG.md +42 -0
- package/README.md +40 -4
- package/dist/index.cjs +120 -36
- package/dist/index.d.cts +56 -11
- package/dist/index.d.ts +56 -11
- package/dist/index.js +127 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -627,7 +627,7 @@ function messageSignerFromCallback(address2, signMessage) {
|
|
|
627
627
|
}
|
|
628
628
|
|
|
629
629
|
// src/scanning/compliance-keys.ts
|
|
630
|
-
import
|
|
630
|
+
import nacl3 from "tweetnacl";
|
|
631
631
|
import { blake3 as blake32 } from "@noble/hashes/blake3";
|
|
632
632
|
import { sha256 as sha2562 } from "@noble/hashes/sha2";
|
|
633
633
|
|
|
@@ -897,8 +897,14 @@ function connectionRpcEndpoint(connection) {
|
|
|
897
897
|
// src/relay/payload.ts
|
|
898
898
|
import { sha256 } from "@noble/hashes/sha2";
|
|
899
899
|
import { bytesToHex as bytesToHex2 } from "@noble/hashes/utils";
|
|
900
|
-
import {
|
|
900
|
+
import {
|
|
901
|
+
createNoopSigner,
|
|
902
|
+
getBase58Decoder as getBase58Decoder2,
|
|
903
|
+
getCompiledTransactionMessageDecoder,
|
|
904
|
+
getCompiledTransactionMessageEncoder
|
|
905
|
+
} from "@solana/kit";
|
|
901
906
|
import { getTransferSolInstruction } from "@solana-program/system";
|
|
907
|
+
import nacl2 from "tweetnacl";
|
|
902
908
|
|
|
903
909
|
// src/solana/transaction.ts
|
|
904
910
|
import {
|
|
@@ -1369,6 +1375,61 @@ function buildAuthTransactionMessage(sender, digest) {
|
|
|
1369
1375
|
function serializeAuthTransactionMessage(sender, digest) {
|
|
1370
1376
|
return new Uint8Array(compileUnsigned(buildAuthTransactionMessage(sender, digest)).messageBytes);
|
|
1371
1377
|
}
|
|
1378
|
+
var MAX_AUTH_TX_MESSAGE_BYTES = 1232;
|
|
1379
|
+
var TRANSFER_ZERO_LAMPORTS = Uint8Array.from([2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
1380
|
+
var SYSTEM_PROGRAM_ADDRESS2 = "11111111111111111111111111111111";
|
|
1381
|
+
function sameBytes(a, b) {
|
|
1382
|
+
return a.length === b.length && a.every((byte, i) => byte === b[i]);
|
|
1383
|
+
}
|
|
1384
|
+
function walletAuthTransactionMessageBinds(sender, payload, bytes) {
|
|
1385
|
+
if (bytes.length > MAX_AUTH_TX_MESSAGE_BYTES) return false;
|
|
1386
|
+
let compiled;
|
|
1387
|
+
try {
|
|
1388
|
+
compiled = getCompiledTransactionMessageDecoder().decode(bytes);
|
|
1389
|
+
if (compiled.version !== "legacy" && compiled.version !== 0) return false;
|
|
1390
|
+
if (!sameBytes(new Uint8Array(getCompiledTransactionMessageEncoder().encode(compiled)), bytes)) return false;
|
|
1391
|
+
} catch {
|
|
1392
|
+
return false;
|
|
1393
|
+
}
|
|
1394
|
+
if (!sanitizes(compiled)) return false;
|
|
1395
|
+
const accounts = compiled.staticAccounts;
|
|
1396
|
+
if (compiled.header.numSignerAccounts !== 1 || accounts[0] !== sender) return false;
|
|
1397
|
+
const lifetimeToken = compiled.lifetimeToken;
|
|
1398
|
+
if (lifetimeToken !== getBase58Decoder2().decode(sha256(payload))) return false;
|
|
1399
|
+
let ours = false;
|
|
1400
|
+
for (const instruction of compiled.instructions) {
|
|
1401
|
+
const program = accounts[instruction.programAddressIndex];
|
|
1402
|
+
if (program === SYSTEM_PROGRAM_ADDRESS2 && instruction.accountIndices?.length === 2 && instruction.accountIndices[0] === 0 && instruction.accountIndices[1] === 0 && sameBytes(new Uint8Array(instruction.data ?? []), TRANSFER_ZERO_LAMPORTS)) {
|
|
1403
|
+
ours = true;
|
|
1404
|
+
} else if (!WALLET_ADDED_PROGRAMS.includes(program)) {
|
|
1405
|
+
return false;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
return ours;
|
|
1409
|
+
}
|
|
1410
|
+
var WALLET_ADDED_PROGRAMS = [
|
|
1411
|
+
"ComputeBudget111111111111111111111111111111",
|
|
1412
|
+
"L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95"
|
|
1413
|
+
];
|
|
1414
|
+
function sanitizes(compiled) {
|
|
1415
|
+
const { header, staticAccounts, instructions } = compiled;
|
|
1416
|
+
const lookups = compiled.addressTableLookups ?? [];
|
|
1417
|
+
if (header.numReadonlySignerAccounts >= header.numSignerAccounts) return false;
|
|
1418
|
+
if (header.numSignerAccounts + header.numReadonlyNonSignerAccounts > staticAccounts.length) return false;
|
|
1419
|
+
let total = staticAccounts.length;
|
|
1420
|
+
for (const lookup of lookups) {
|
|
1421
|
+
const loaded = lookup.writableIndexes.length + lookup.readonlyIndexes.length;
|
|
1422
|
+
if (loaded === 0) return false;
|
|
1423
|
+
total += loaded;
|
|
1424
|
+
}
|
|
1425
|
+
if (total > 256) return false;
|
|
1426
|
+
return instructions.every(
|
|
1427
|
+
(instruction) => (
|
|
1428
|
+
// Programs come from static keys only and are never the fee payer.
|
|
1429
|
+
instruction.programAddressIndex > 0 && instruction.programAddressIndex < staticAccounts.length && (instruction.accountIndices ?? []).every((index) => index < total)
|
|
1430
|
+
)
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1372
1433
|
async function signRelayAuthPayload(signer, payload) {
|
|
1373
1434
|
if (isMessageSigner(signer)) {
|
|
1374
1435
|
const signature = await signMessageBytes(signer, payload);
|
|
@@ -1392,7 +1453,21 @@ async function signRelayAuthPayload(signer, payload) {
|
|
|
1392
1453
|
}
|
|
1393
1454
|
const signature = new Uint8Array(own);
|
|
1394
1455
|
assertDetachedSignature(signature, "signTransaction");
|
|
1395
|
-
|
|
1456
|
+
const signedMessage = new Uint8Array(signed.messageBytes);
|
|
1457
|
+
if (!nacl2.sign.detached.verify(signedMessage, signature, addressBytes(signer.address))) {
|
|
1458
|
+
throw new Error(
|
|
1459
|
+
"The wallet's signature does not match the Cloak auth transaction it returned. Nothing was submitted."
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
if (sameBytes(signedMessage, new Uint8Array(compileUnsigned(message).messageBytes))) {
|
|
1463
|
+
return { signature, mode: "transaction" };
|
|
1464
|
+
}
|
|
1465
|
+
if (!walletAuthTransactionMessageBinds(signer.address, payload, signedMessage)) {
|
|
1466
|
+
throw new Error(
|
|
1467
|
+
"The wallet changed the Cloak auth transaction into one that no longer authorizes this request (another fee payer or signer, another blockhash, or no 0 SOL self-transfer). Nothing was submitted."
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
return { signature, mode: "transaction", txMessage: signedMessage };
|
|
1396
1471
|
}
|
|
1397
1472
|
throw new Error("Relay auth signer can neither sign messages nor transactions.");
|
|
1398
1473
|
}
|
|
@@ -1454,14 +1529,15 @@ async function buildRelayAuthFields(endpoint, programId, body, signers, fields =
|
|
|
1454
1529
|
fields
|
|
1455
1530
|
);
|
|
1456
1531
|
const approvalStartedMs = Date.now();
|
|
1457
|
-
const { signature, mode } = await signRelayAuthPayload(wallet, preimage.message);
|
|
1532
|
+
const { signature, mode, txMessage } = await signRelayAuthPayload(wallet, preimage.message);
|
|
1458
1533
|
assertApprovalWithinFreshnessWindow(Date.now() - approvalStartedMs);
|
|
1459
1534
|
return {
|
|
1460
1535
|
sender: preimage.sender,
|
|
1461
1536
|
auth_issued_at: preimage.auth_issued_at,
|
|
1462
1537
|
auth_nonce: preimage.auth_nonce,
|
|
1463
1538
|
auth_signature: Buffer.from(signature).toString("base64"),
|
|
1464
|
-
...mode === "transaction" ? { auth_mode: mode } : {}
|
|
1539
|
+
...mode === "transaction" ? { auth_mode: mode } : {},
|
|
1540
|
+
...txMessage ? { auth_tx_message: Buffer.from(txMessage).toString("base64") } : {}
|
|
1465
1541
|
};
|
|
1466
1542
|
}
|
|
1467
1543
|
var REQUEST_AUTH_BATCH_DOMAIN = "CLOAK_RELAY_BATCH_AUTH_V1";
|
|
@@ -1512,7 +1588,7 @@ function deriveViewingKeyFromNk(nk) {
|
|
|
1512
1588
|
preimage.set(nk, CHAIN_NOTE_VK_DOMAIN.length);
|
|
1513
1589
|
const derived = blake32(preimage);
|
|
1514
1590
|
const privateKey = clampX25519Secret(derived);
|
|
1515
|
-
const publicKey =
|
|
1591
|
+
const publicKey = nacl3.scalarMult.base(privateKey);
|
|
1516
1592
|
return { privateKey, publicKey };
|
|
1517
1593
|
}
|
|
1518
1594
|
function deriveDiversifier(nk, commitmentHex, outputIndex) {
|
|
@@ -1547,7 +1623,7 @@ function deriveDiversifiedViewingKey(nk, diversifier) {
|
|
|
1547
1623
|
preimage.set(diversifier, SK_D_DOMAIN.length + nk.length);
|
|
1548
1624
|
const derived = blake32(preimage);
|
|
1549
1625
|
const privateKey = clampX25519Secret(derived);
|
|
1550
|
-
const publicKey =
|
|
1626
|
+
const publicKey = nacl3.scalarMult.base(privateKey);
|
|
1551
1627
|
return { privateKey, publicKey };
|
|
1552
1628
|
}
|
|
1553
1629
|
function deriveViewingKeyFromSpendKey(skSpend) {
|
|
@@ -1610,7 +1686,7 @@ async function deriveUserCompliancePublicKey(masterCompliancePublicKey, userPubl
|
|
|
1610
1686
|
masterCompliancePublicKey,
|
|
1611
1687
|
userPublicKey
|
|
1612
1688
|
);
|
|
1613
|
-
return
|
|
1689
|
+
return nacl3.scalarMult(factor, masterCompliancePublicKey);
|
|
1614
1690
|
}
|
|
1615
1691
|
function bytesToHex3(bytes) {
|
|
1616
1692
|
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
@@ -1657,7 +1733,8 @@ async function registerViewingKey(relayUrl, userPubkey, nk, signMessage) {
|
|
|
1657
1733
|
nonce: challenge.nonce,
|
|
1658
1734
|
identifier: keyId,
|
|
1659
1735
|
signature,
|
|
1660
|
-
...signed.mode === "transaction" ? { auth_mode: signed.mode } : {}
|
|
1736
|
+
...signed.mode === "transaction" ? { auth_mode: signed.mode } : {},
|
|
1737
|
+
...signed.txMessage ? { tx_message: Buffer.from(signed.txMessage).toString("base64") } : {}
|
|
1661
1738
|
})
|
|
1662
1739
|
});
|
|
1663
1740
|
if (!response.ok) {
|
|
@@ -1666,7 +1743,7 @@ async function registerViewingKey(relayUrl, userPubkey, nk, signMessage) {
|
|
|
1666
1743
|
}
|
|
1667
1744
|
|
|
1668
1745
|
// src/scanning/metadata-encryption.ts
|
|
1669
|
-
import
|
|
1746
|
+
import nacl4 from "tweetnacl";
|
|
1670
1747
|
var AES_GCM_NONCE_LENGTH = 12;
|
|
1671
1748
|
var AES_GCM_TAG_LENGTH = 16;
|
|
1672
1749
|
var X25519_KEY_LENGTH2 = 32;
|
|
@@ -1763,8 +1840,8 @@ async function aesGcmDecrypt(ciphertext, keyBytes, nonce) {
|
|
|
1763
1840
|
}
|
|
1764
1841
|
async function encryptForRecipient(plaintext, recipientPublicKey) {
|
|
1765
1842
|
assert32Bytes2(recipientPublicKey, "recipientPublicKey");
|
|
1766
|
-
const ephemeral =
|
|
1767
|
-
const sharedSecret =
|
|
1843
|
+
const ephemeral = nacl4.box.keyPair();
|
|
1844
|
+
const sharedSecret = nacl4.scalarMult(ephemeral.secretKey, recipientPublicKey);
|
|
1768
1845
|
const nonce = randomBytes(AES_GCM_NONCE_LENGTH);
|
|
1769
1846
|
const ciphertext = await aesGcmEncrypt(plaintext, sharedSecret, nonce);
|
|
1770
1847
|
return {
|
|
@@ -1823,7 +1900,7 @@ async function encryptTransactionMetadataBundle(metadata, viewingKeyPrivate, use
|
|
|
1823
1900
|
const plaintext = new TextEncoder().encode(JSON.stringify(metadata));
|
|
1824
1901
|
const basePoint = new Uint8Array(32);
|
|
1825
1902
|
basePoint[0] = 9;
|
|
1826
|
-
const viewingKeyPublic =
|
|
1903
|
+
const viewingKeyPublic = nacl4.scalarMult(viewingKeyPrivate, basePoint);
|
|
1827
1904
|
const [userPayload, compliancePayload] = await Promise.all([
|
|
1828
1905
|
encryptForRecipient(plaintext, viewingKeyPublic),
|
|
1829
1906
|
encryptForRecipient(plaintext, viewingKeyPublic)
|
|
@@ -1842,7 +1919,7 @@ async function decryptTransactionMetadata(encrypted, viewKeySecret) {
|
|
|
1842
1919
|
const payload = decodePayload(encrypted);
|
|
1843
1920
|
const ephemeralPk = hexToBytes(payload.ephemeral_pk);
|
|
1844
1921
|
assert32Bytes2(ephemeralPk, "ephemeral public key");
|
|
1845
|
-
const sharedSecret =
|
|
1922
|
+
const sharedSecret = nacl4.scalarMult(viewKeySecret, ephemeralPk);
|
|
1846
1923
|
return decryptWithSharedSecret(payload, sharedSecret);
|
|
1847
1924
|
}
|
|
1848
1925
|
async function decryptComplianceMetadataWithMasterKey(encrypted, masterCompliancePrivateKey, masterCompliancePublicKey, userPublicKey) {
|
|
@@ -1855,8 +1932,8 @@ async function decryptComplianceMetadataWithMasterKey(encrypted, masterComplianc
|
|
|
1855
1932
|
masterCompliancePublicKey,
|
|
1856
1933
|
userPublicKey
|
|
1857
1934
|
);
|
|
1858
|
-
const scaledEphemeral =
|
|
1859
|
-
const sharedSecret =
|
|
1935
|
+
const scaledEphemeral = nacl4.scalarMult(userFactor, ephemeralPk);
|
|
1936
|
+
const sharedSecret = nacl4.scalarMult(masterCompliancePrivateKey, scaledEphemeral);
|
|
1860
1937
|
return decryptWithSharedSecret(payload, sharedSecret);
|
|
1861
1938
|
}
|
|
1862
1939
|
|
|
@@ -3503,7 +3580,8 @@ var RelayService = class {
|
|
|
3503
3580
|
nonce: challenge.nonce,
|
|
3504
3581
|
identifier,
|
|
3505
3582
|
signature,
|
|
3506
|
-
...signed.mode === "transaction" ? { auth_mode: signed.mode } : {}
|
|
3583
|
+
...signed.mode === "transaction" ? { auth_mode: signed.mode } : {},
|
|
3584
|
+
...signed.txMessage ? { tx_message: this.bytesToBase64(signed.txMessage) } : {}
|
|
3507
3585
|
})
|
|
3508
3586
|
});
|
|
3509
3587
|
if (!response.ok) {
|
|
@@ -4920,7 +4998,7 @@ function chainNoteFromBase64(base64) {
|
|
|
4920
4998
|
}
|
|
4921
4999
|
|
|
4922
5000
|
// src/notes/delivery-note.ts
|
|
4923
|
-
import
|
|
5001
|
+
import nacl5 from "tweetnacl";
|
|
4924
5002
|
var RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN = 32;
|
|
4925
5003
|
var RECIPIENT_DELIVERY_NONCE_LEN = 24;
|
|
4926
5004
|
var RECIPIENT_DELIVERY_PLAINTEXT_LEN = 40;
|
|
@@ -4971,10 +5049,10 @@ function encodeRecipientDeliveryNote(note, recipientViewingPublicKey) {
|
|
|
4971
5049
|
const plaintext = new Uint8Array(RECIPIENT_DELIVERY_PLAINTEXT_LEN);
|
|
4972
5050
|
writeU64LE2(plaintext, 0, note.amount);
|
|
4973
5051
|
writeU256BE2(plaintext, 8, note.blinding);
|
|
4974
|
-
const ephemeral =
|
|
4975
|
-
const shared =
|
|
4976
|
-
const nonce =
|
|
4977
|
-
const ciphertext =
|
|
5052
|
+
const ephemeral = nacl5.box.keyPair();
|
|
5053
|
+
const shared = nacl5.box.before(recipientViewingPublicKey, ephemeral.secretKey);
|
|
5054
|
+
const nonce = nacl5.randomBytes(nacl5.secretbox.nonceLength);
|
|
5055
|
+
const ciphertext = nacl5.secretbox(plaintext, nonce, shared);
|
|
4978
5056
|
if (ciphertext.length !== RECIPIENT_DELIVERY_CIPHERTEXT_LEN) {
|
|
4979
5057
|
throw new Error(
|
|
4980
5058
|
`delivery ciphertext must be ${RECIPIENT_DELIVERY_CIPHERTEXT_LEN} bytes, got ${ciphertext.length}`
|
|
@@ -5000,8 +5078,8 @@ function openRecipientDeliveryNote(envelope, viewingSecretKey) {
|
|
|
5000
5078
|
const ciphertext = envelope.slice(
|
|
5001
5079
|
RECIPIENT_DELIVERY_EPHEMERAL_PK_LEN + RECIPIENT_DELIVERY_NONCE_LEN
|
|
5002
5080
|
);
|
|
5003
|
-
const shared =
|
|
5004
|
-
const plaintext =
|
|
5081
|
+
const shared = nacl5.box.before(ephemeralPk, viewingSecretKey);
|
|
5082
|
+
const plaintext = nacl5.secretbox.open(ciphertext, nonce, shared);
|
|
5005
5083
|
if (!plaintext || plaintext.length !== RECIPIENT_DELIVERY_PLAINTEXT_LEN) return null;
|
|
5006
5084
|
return { amount: readU64LE2(plaintext, 0), blinding: readU256BE2(plaintext, 8) };
|
|
5007
5085
|
} catch {
|
|
@@ -5037,7 +5115,7 @@ async function createRecipientDeliveryOpener(viewingSecretKey) {
|
|
|
5037
5115
|
}
|
|
5038
5116
|
const slow = async (envelope) => openRecipientDeliveryNote(envelope, viewingSecretKey);
|
|
5039
5117
|
const subtle = globalThis.crypto?.subtle;
|
|
5040
|
-
const hsalsa =
|
|
5118
|
+
const hsalsa = nacl5.lowlevel?.crypto_core_hsalsa20;
|
|
5041
5119
|
if (!subtle || typeof hsalsa !== "function") return slow;
|
|
5042
5120
|
let privateKey;
|
|
5043
5121
|
const sharedKey = async (ephemeralPk) => {
|
|
@@ -5054,9 +5132,9 @@ async function createRecipientDeliveryOpener(viewingSecretKey) {
|
|
|
5054
5132
|
pkcs8.set(X25519_PKCS8_PREFIX);
|
|
5055
5133
|
pkcs8.set(viewingSecretKey, X25519_PKCS8_PREFIX.length);
|
|
5056
5134
|
privateKey = await subtle.importKey("pkcs8", pkcs8, { name: "X25519" }, false, ["deriveBits"]);
|
|
5057
|
-
const probe =
|
|
5135
|
+
const probe = nacl5.box.keyPair().publicKey;
|
|
5058
5136
|
const fast = await sharedKey(probe);
|
|
5059
|
-
const reference =
|
|
5137
|
+
const reference = nacl5.box.before(probe, viewingSecretKey);
|
|
5060
5138
|
if (fast.length !== reference.length || fast.some((b, i) => b !== reference[i])) return slow;
|
|
5061
5139
|
} catch {
|
|
5062
5140
|
return slow;
|
|
@@ -5076,7 +5154,7 @@ async function createRecipientDeliveryOpener(viewingSecretKey) {
|
|
|
5076
5154
|
return openRecipientDeliveryNote(envelope, viewingSecretKey);
|
|
5077
5155
|
}
|
|
5078
5156
|
try {
|
|
5079
|
-
return decodeOpened(
|
|
5157
|
+
return decodeOpened(nacl5.secretbox.open(ciphertext, nonce, key));
|
|
5080
5158
|
} catch {
|
|
5081
5159
|
return null;
|
|
5082
5160
|
}
|
|
@@ -5670,7 +5748,7 @@ async function matchChangeNote(params) {
|
|
|
5670
5748
|
|
|
5671
5749
|
// src/flows/transact.ts
|
|
5672
5750
|
import { buildPoseidon as buildPoseidon2 } from "circomlibjs";
|
|
5673
|
-
import
|
|
5751
|
+
import nacl6 from "tweetnacl";
|
|
5674
5752
|
|
|
5675
5753
|
// src/relay/chain-note-time.ts
|
|
5676
5754
|
async function relayChainNoteTimestampMs(relayUrl) {
|
|
@@ -6540,6 +6618,7 @@ async function registerViewingKeyOnce(relayUrl, userPubkey, viewingKeyHex, cache
|
|
|
6540
6618
|
);
|
|
6541
6619
|
let signatureBase64;
|
|
6542
6620
|
let authMode = "message";
|
|
6621
|
+
let txMessageBase64;
|
|
6543
6622
|
const messageBytes = new TextEncoder().encode(challenge.message);
|
|
6544
6623
|
if (options.signMessage) {
|
|
6545
6624
|
const sig = await options.signMessage(messageBytes);
|
|
@@ -6557,6 +6636,7 @@ async function registerViewingKeyOnce(relayUrl, userPubkey, viewingKeyHex, cache
|
|
|
6557
6636
|
const signed = await signRelayAuthPayload(options.signer, messageBytes);
|
|
6558
6637
|
signatureBase64 = Buffer.from(signed.signature).toString("base64");
|
|
6559
6638
|
authMode = signed.mode;
|
|
6639
|
+
if (signed.txMessage) txMessageBase64 = Buffer.from(signed.txMessage).toString("base64");
|
|
6560
6640
|
} else {
|
|
6561
6641
|
throw new Error(
|
|
6562
6642
|
"Viewing key registration is mandatory: signMessage or signer (wallet) or depositorKeypair is required."
|
|
@@ -6571,7 +6651,8 @@ async function registerViewingKeyOnce(relayUrl, userPubkey, viewingKeyHex, cache
|
|
|
6571
6651
|
viewing_key: viewingKeyHex,
|
|
6572
6652
|
nonce: challenge.nonce,
|
|
6573
6653
|
signature: signatureBase64,
|
|
6574
|
-
...authMode === "transaction" ? { auth_mode: authMode } : {}
|
|
6654
|
+
...authMode === "transaction" ? { auth_mode: authMode } : {},
|
|
6655
|
+
...txMessageBase64 ? { tx_message: txMessageBase64 } : {}
|
|
6575
6656
|
})
|
|
6576
6657
|
});
|
|
6577
6658
|
if (!response.ok) {
|
|
@@ -7836,7 +7917,7 @@ async function fetchRiskQuote(riskQuoteUrl, wallet, options) {
|
|
|
7836
7917
|
`Invalid risk quote response: invalid lengths (sig=${signatureBuf.length}, msg=${messageArr.length}, pk=${publicKeyBytes.length}; expected msg 33/41/50/82/146)`
|
|
7837
7918
|
);
|
|
7838
7919
|
}
|
|
7839
|
-
if (!
|
|
7920
|
+
if (!nacl6.sign.detached.verify(messageArr, new Uint8Array(signatureBuf), publicKeyBytes)) {
|
|
7840
7921
|
throw new Error(
|
|
7841
7922
|
"Invalid risk quote response: signature does not verify under signer_pubkey"
|
|
7842
7923
|
);
|
|
@@ -10763,7 +10844,7 @@ var RelayBatchAuthCoordinator = class {
|
|
|
10763
10844
|
);
|
|
10764
10845
|
}
|
|
10765
10846
|
const approvalStartedMs = Date.now();
|
|
10766
|
-
const { signature, mode } = await signRelayAuthPayload(this.signer, message);
|
|
10847
|
+
const { signature, mode, txMessage } = await signRelayAuthPayload(this.signer, message);
|
|
10767
10848
|
if (!isKeyPairSigner2(this.signer)) {
|
|
10768
10849
|
assertApprovalWithinFreshnessWindow(
|
|
10769
10850
|
Date.now() - approvalStartedMs,
|
|
@@ -10781,6 +10862,9 @@ var RelayBatchAuthCoordinator = class {
|
|
|
10781
10862
|
auth_nonce: preimage.auth_nonce,
|
|
10782
10863
|
auth_signature: signatureB64,
|
|
10783
10864
|
...mode === "transaction" ? { auth_mode: mode } : {},
|
|
10865
|
+
// The wallet's own message when it changed the envelope; one approval, so the same
|
|
10866
|
+
// message for every item, exactly like the signature.
|
|
10867
|
+
...txMessage ? { auth_tx_message: Buffer.from(txMessage).toString("base64") } : {},
|
|
10784
10868
|
// A fresh array per item: `Object.assign` puts this on the wire body, and the body is
|
|
10785
10869
|
// serialized again on every network retry.
|
|
10786
10870
|
auth_batch: { digests: [...digests] }
|
|
@@ -12619,7 +12703,7 @@ async function fetchNoteIndexPage(relayUrl, epoch, page, options = {}) {
|
|
|
12619
12703
|
|
|
12620
12704
|
// src/notes/request-keys.ts
|
|
12621
12705
|
import { blake3 as blake36 } from "@noble/hashes/blake3";
|
|
12622
|
-
import
|
|
12706
|
+
import nacl7 from "tweetnacl";
|
|
12623
12707
|
var BN254_ORDER = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
|
12624
12708
|
var ROOT_SEED_DOMAIN = new TextEncoder().encode("cloak_request_root_v1");
|
|
12625
12709
|
var ROOT_NK_DOMAIN = new TextEncoder().encode("cloak_request_root_nk_v1");
|
|
@@ -12669,7 +12753,7 @@ async function deriveRequestKeys(root, counter) {
|
|
|
12669
12753
|
return {
|
|
12670
12754
|
counter,
|
|
12671
12755
|
utxoKeypair: { privateKey, publicKey },
|
|
12672
|
-
viewingKeypair: { privateKey: vk, publicKey:
|
|
12756
|
+
viewingKeypair: { privateKey: vk, publicKey: nacl7.scalarMult.base(vk) }
|
|
12673
12757
|
};
|
|
12674
12758
|
}
|
|
12675
12759
|
async function deriveRequestKeyRange(root, from, count) {
|
|
@@ -14170,7 +14254,7 @@ async function loadWeb3() {
|
|
|
14170
14254
|
}
|
|
14171
14255
|
|
|
14172
14256
|
// src/bridge/rail-verify.ts
|
|
14173
|
-
import
|
|
14257
|
+
import nacl8 from "tweetnacl";
|
|
14174
14258
|
import { sha256 as sha2567 } from "@noble/hashes/sha256";
|
|
14175
14259
|
var ONECLICK_PUBKEY_B58 = "reYaWhvwu8Jzo3WUM3zhn6VrhuMEF4eADL17qtRVifc";
|
|
14176
14260
|
var b58 = /* @__PURE__ */ (() => {
|
|
@@ -14281,7 +14365,7 @@ function verifyQuoteSignature(resp) {
|
|
|
14281
14365
|
const message = new TextEncoder().encode(b58.encode(new Uint8Array(digest)));
|
|
14282
14366
|
const sig = resp.signature.replace(/^ed25519:/, "");
|
|
14283
14367
|
try {
|
|
14284
|
-
return { valid:
|
|
14368
|
+
return { valid: nacl8.sign.detached.verify(message, b58.decode(sig), b58.decode(ONECLICK_PUBKEY_B58)) };
|
|
14285
14369
|
} catch (e) {
|
|
14286
14370
|
return { valid: false, reason: e instanceof Error ? e.message : String(e) };
|
|
14287
14371
|
}
|
|
@@ -14379,11 +14463,11 @@ function cloakBridgeRail(relayUrl) {
|
|
|
14379
14463
|
}
|
|
14380
14464
|
|
|
14381
14465
|
// src/bridge/paymaster-client.ts
|
|
14382
|
-
import { getCompiledTransactionMessageDecoder, getInstructionsFromCompiledTransactionMessage } from "@solana/kit";
|
|
14466
|
+
import { getCompiledTransactionMessageDecoder as getCompiledTransactionMessageDecoder2, getInstructionsFromCompiledTransactionMessage } from "@solana/kit";
|
|
14383
14467
|
import { parseTransferSolInstruction } from "@solana-program/system";
|
|
14384
14468
|
import { TOKEN_PROGRAM_ADDRESS as TOKEN_PROGRAM_ADDRESS3, findAssociatedTokenPda as findAssociatedTokenPda3, parseTransferInstruction } from "@solana-program/token";
|
|
14385
14469
|
async function validatePaymasterTopUpTransaction(tx, expect) {
|
|
14386
|
-
const compiledMessage =
|
|
14470
|
+
const compiledMessage = getCompiledTransactionMessageDecoder2().decode(tx.messageBytes);
|
|
14387
14471
|
const ixs = getInstructionsFromCompiledTransactionMessage(compiledMessage);
|
|
14388
14472
|
if (ixs.length !== 1 && ixs.length !== 2) {
|
|
14389
14473
|
throw new Error(
|
|
@@ -14663,7 +14747,7 @@ async function scanReceivers(rpc, opts, receiverAt, provenance) {
|
|
|
14663
14747
|
|
|
14664
14748
|
// src/bridge/deposit-core.ts
|
|
14665
14749
|
import {
|
|
14666
|
-
getCompiledTransactionMessageDecoder as
|
|
14750
|
+
getCompiledTransactionMessageDecoder as getCompiledTransactionMessageDecoder3,
|
|
14667
14751
|
getInstructionsFromCompiledTransactionMessage as getInstructionsFromCompiledTransactionMessage2
|
|
14668
14752
|
} from "@solana/kit";
|
|
14669
14753
|
import { getTransferSolInstruction as getTransferSolInstruction2 } from "@solana-program/system";
|
|
@@ -14730,7 +14814,7 @@ function makeDepositSigner(params) {
|
|
|
14730
14814
|
const out = [];
|
|
14731
14815
|
for (const tx of transactions) {
|
|
14732
14816
|
state.measuredSize = transactionBytes(tx).length;
|
|
14733
|
-
const compiled =
|
|
14817
|
+
const compiled = getCompiledTransactionMessageDecoder3().decode(tx.messageBytes);
|
|
14734
14818
|
const loadedAddresses = await resolveLoadedAddresses(rpc, compiled);
|
|
14735
14819
|
const instructions = getInstructionsFromCompiledTransactionMessage2(compiled, loadedAddresses);
|
|
14736
14820
|
const transactIx = instructions.find((i) => i.programAddress === programId);
|
|
@@ -15047,7 +15131,7 @@ async function withShieldRetries(attempt, hooks = {}) {
|
|
|
15047
15131
|
}
|
|
15048
15132
|
|
|
15049
15133
|
// src/index.ts
|
|
15050
|
-
var VERSION = "0.2.
|
|
15134
|
+
var VERSION = "0.2.14";
|
|
15051
15135
|
var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
15052
15136
|
export {
|
|
15053
15137
|
AccountRole,
|
|
@@ -15123,6 +15207,7 @@ export {
|
|
|
15123
15207
|
VARIABLE_FEE_NUMERATOR,
|
|
15124
15208
|
VARIABLE_FEE_RATE,
|
|
15125
15209
|
VERSION,
|
|
15210
|
+
WALLET_ADDED_PROGRAMS,
|
|
15126
15211
|
WITHDRAW_FEE_BPS,
|
|
15127
15212
|
WITHDRAW_FIXED_FEE,
|
|
15128
15213
|
accountMeta,
|
|
@@ -15399,6 +15484,7 @@ export {
|
|
|
15399
15484
|
verifyQuoteSignature,
|
|
15400
15485
|
verifyUtxos,
|
|
15401
15486
|
waitForRoot,
|
|
15487
|
+
walletAuthTransactionMessageBinds,
|
|
15402
15488
|
withShieldRetries,
|
|
15403
15489
|
withTiming,
|
|
15404
15490
|
withdrawFeeFor
|
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.
|
|
4
|
+
"version": "0.2.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|