@cloak.dev/sdk 0.2.6 → 0.2.8
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 +56 -0
- package/README.md +9 -4
- package/dist/index.cjs +201 -31
- package/dist/index.d.cts +147 -15
- package/dist/index.d.ts +147 -15
- package/dist/index.js +191 -31
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,62 @@ All notable changes to `@cloak.dev/sdk` are documented here. The format follows
|
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Releases before 0.2.6 are described in
|
|
6
6
|
the README's "Version and compatibility" section and in the git history.
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.8]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
* Per-request receive keys, so two request links from one wallet share no key. `deriveRequestKeyRoot`,
|
|
15
|
+
`deriveRequestKeys` and `deriveRequestKeyRange` derive a fresh UTXO keypair and X25519 viewing
|
|
16
|
+
keypair per request counter from a root. The default root derives from `nk`, so compliance keeps
|
|
17
|
+
visibility of a wallet's requests while nothing public links two links to one requester;
|
|
18
|
+
`REQUEST_KEY_ROOT_SOURCE` can switch it to a spend-key ("seed") root the relay cannot recompute. `recoverNotesFromIndex` takes
|
|
19
|
+
`requestKeys` (at most `MAX_REQUEST_KEYS` = 64) and returns notes paid to them with
|
|
20
|
+
`requestIndex` set; a restore derives `REQUEST_KEY_GAP_LIMIT` (20) counters past the last known
|
|
21
|
+
one. `sweepToWalletKey` moves up to two such notes under the wallet key (one extra transaction);
|
|
22
|
+
`transfer` already did this implicitly, and withdrawals need no sweep.
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
|
|
26
|
+
* `engines.node` is now `>=22.0.0` (was `>=18.0.0`). Node 18 and 20 are end-of-life and received
|
|
27
|
+
no fix in the October 2026 Node security release (Brotli out-of-bounds write in `node:zlib`,
|
|
28
|
+
TLS identity bypasses); use Node 22.23.4 / 24.22.1 or later. npm only warns on an engines
|
|
29
|
+
mismatch unless `engine-strict` is set; no code changed.
|
|
30
|
+
* The publish pipeline builds and publishes on Node 24 (was 20).
|
|
31
|
+
|
|
32
|
+
## [0.2.7]
|
|
33
|
+
|
|
34
|
+
Pairs with the same mainnet program (`zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`) and the same
|
|
35
|
+
0.2.0 circuit bundle as 0.2.6. Note format, hashing and the relay wire format are unchanged; no
|
|
36
|
+
public signature changes. Works with the relay from the partner-program release (services#208).
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
* Internal partner (affiliate) code, used by Cloak's own web and mobile apps (#61):
|
|
41
|
+
`TransactOptions.affiliateCode` is trimmed and lower-cased once at the flow boundary, before it
|
|
42
|
+
enters the request body and the signed relay digest, because the relay only counts
|
|
43
|
+
`^[a-z0-9_]{3,24}$` and silently ignores anything else. A code that is still invalid is left out
|
|
44
|
+
of the request and reported through the new optional `TransactOptions.onWarning(message)`; it
|
|
45
|
+
never fails the request. A code that was already valid is sent exactly as before, so its digest
|
|
46
|
+
is unchanged. `transact`, `transfer`, `partialWithdraw`, `fullWithdraw`, `swapUtxo`,
|
|
47
|
+
`swapWithChange` and `transactBatch` all prepare the option once; which requests carry it is
|
|
48
|
+
unchanged (a withdrawal with a recipient, and a swap intake; never a deposit, a
|
|
49
|
+
shield-to-shield send or a `partialWithdraw` merge step). In `transactBatch` the batch's code
|
|
50
|
+
applies to every fee-bearing item and an item's own `options.affiliateCode` overrides it.
|
|
51
|
+
* Internal `TransactOptions.relayClientId` (for Cloak's mobile app, e.g. `"cloak-mobile/ios/1.4.0"`)
|
|
52
|
+
sends `X-Cloak-Client` with `POST /transact` and `POST /transact_swap`, replacing a same-named
|
|
53
|
+
`relayHeaders` entry. A value that does not match `cloak-mobile/(ios|android)/MAJOR.MINOR.PATCH`
|
|
54
|
+
is left out and reported through `onWarning`; it never fails the request. Browser callers leave
|
|
55
|
+
it unset.
|
|
56
|
+
* Internal helpers `normalizeAffiliateCode(raw): string | null` and
|
|
57
|
+
`isValidRelayClientId(value)` are exported for the apps.
|
|
58
|
+
|
|
59
|
+
### Fixed
|
|
60
|
+
|
|
61
|
+
* Scan results label BRS (`BRSxQRUaGswjLs7ewcH7uXj3r7SgmfKSSLLXyCKHZtUo`) notes as `BRS` instead
|
|
62
|
+
of a truncated mint (#58). Label only; amounts and decimals are unchanged.
|
|
63
|
+
|
|
8
64
|
## [0.2.6]
|
|
9
65
|
|
|
10
66
|
Pairs with the same mainnet program (`zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`) and the same
|
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@ per-mint pool, send privately inside the pool, withdraw to any address, or swap
|
|
|
5
5
|
USDC/USDT with the output landing in a public token account. Groth16 proofs are generated
|
|
6
6
|
client-side (snarkjs) and verified on-chain by the Cloak program.
|
|
7
7
|
|
|
8
|
-
Version 0.2.
|
|
8
|
+
Version 0.2.8 targets the mainnet program deployed on 2026-08-24 and the ceremony-frozen
|
|
9
9
|
`cloak-transaction-0.2.0` circuit bundle. See [Version and compatibility](#version-and-compatibility).
|
|
10
10
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install @cloak.dev/sdk@^0.2.
|
|
14
|
+
npm install @cloak.dev/sdk@^0.2.8
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
The SDK is built on [`@solana/kit`](https://github.com/anza-xyz/kit) and re-exports the pieces an
|
|
@@ -21,7 +21,7 @@ pools and swaps uses `@solana-program/token`, which the SDK depends on; import
|
|
|
21
21
|
`findAssociatedTokenPda` from it directly. Coming from 0.2.4 or earlier (web3.js): see
|
|
22
22
|
[Migrating from @solana/web3.js](#migrating-from-solanaweb3js).
|
|
23
23
|
|
|
24
|
-
Node >=
|
|
24
|
+
Node >= 22. Ships ESM and CJS builds with type declarations. Runs in Node and in the browser
|
|
25
25
|
(wallet signing); the on-chain Merkle-tree rebuild fallback is not available in browsers.
|
|
26
26
|
|
|
27
27
|
## Networks
|
|
@@ -790,7 +790,7 @@ relay endpoint and the localhost-RPC check.
|
|
|
790
790
|
|
|
791
791
|
## Version and compatibility
|
|
792
792
|
|
|
793
|
-
- SDK 0.2.
|
|
793
|
+
- SDK 0.2.8 pairs with the mainnet program at `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`
|
|
794
794
|
(deployed 2026-08-24) and the 0.2.0 circuit bundle — the program and circuit bundle are unchanged
|
|
795
795
|
since 0.2.0; only the SDK package version has moved. The 0.2.5 flows were exercised on mainnet on
|
|
796
796
|
2026-08-25: deposit, private send and withdraw on SOL, USDC and USDT; swaps SOL to USDC and USDT;
|
|
@@ -810,6 +810,11 @@ relay endpoint and the localhost-RPC check.
|
|
|
810
810
|
relay answers them with 401. 0.2.6 also makes nk view-only for notes created from 0.2.6 on, which
|
|
811
811
|
changes several public signatures (`ownerUtxoKeypair` is now required by every spend flow); the
|
|
812
812
|
full list is in [CHANGELOG.md](CHANGELOG.md).
|
|
813
|
+
- 0.2.7 changes no wire format, hash or public signature. Scan results label BRS notes as `BRS`,
|
|
814
|
+
and Cloak's own apps get stricter handling of the internal partner code (see
|
|
815
|
+
[CHANGELOG.md](CHANGELOG.md)).
|
|
816
|
+
- 0.2.8 adds per-request receive keys for request links (`deriveRequestKeys`, `recoverNotesFromIndex({ requestKeys })`, `sweepToWalletKey`) and changes no wire format, hash or existing signature (see
|
|
817
|
+
[CHANGELOG.md](CHANGELOG.md)).
|
|
813
818
|
- Proofs generated with the 0.1.x circuits are rejected by the mainnet program. SDK 0.1.x builds
|
|
814
819
|
(which ship the 0.1.0 bundle) are not usable against it; upgrade to 0.2.x.
|
|
815
820
|
- The note-based `CloakSDK` class is removed in 0.2.0. It targeted the pre-0.2.0 instruction layout
|
package/dist/index.cjs
CHANGED
|
@@ -600,6 +600,7 @@ __export(index_exports, {
|
|
|
600
600
|
MAINNET_RENT_0: () => MAINNET_RENT_0,
|
|
601
601
|
MAINNET_RENT_1: () => MAINNET_RENT_1,
|
|
602
602
|
MAX_RECEIVER_INDEX: () => MAX_RECEIVER_INDEX,
|
|
603
|
+
MAX_REQUEST_KEYS: () => MAX_REQUEST_KEYS,
|
|
603
604
|
MERKLE_TREE_HEIGHT: () => MERKLE_TREE_HEIGHT2,
|
|
604
605
|
MIN_DEPOSIT_LAMPORTS: () => MIN_DEPOSIT_LAMPORTS,
|
|
605
606
|
MIN_DEPOSIT_SPL_BASE_UNITS: () => MIN_DEPOSIT_SPL_BASE_UNITS,
|
|
@@ -623,6 +624,8 @@ __export(index_exports, {
|
|
|
623
624
|
REQUEST_AUTH_BATCH_MAX_AGE_SECONDS: () => REQUEST_AUTH_BATCH_MAX_AGE_SECONDS,
|
|
624
625
|
REQUEST_AUTH_MAX_AGE_SECONDS: () => REQUEST_AUTH_MAX_AGE_SECONDS,
|
|
625
626
|
REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS: () => REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS,
|
|
627
|
+
REQUEST_KEY_GAP_LIMIT: () => REQUEST_KEY_GAP_LIMIT,
|
|
628
|
+
REQUEST_KEY_ROOT_SOURCE: () => REQUEST_KEY_ROOT_SOURCE,
|
|
626
629
|
RelayBatchAuthCoordinator: () => RelayBatchAuthCoordinator,
|
|
627
630
|
RelayInternalError: () => RelayInternalError,
|
|
628
631
|
RelayService: () => RelayService,
|
|
@@ -720,6 +723,9 @@ __export(index_exports, {
|
|
|
720
723
|
deriveLegacyDepositNoteSecrets: () => deriveLegacyDepositNoteSecrets,
|
|
721
724
|
deriveLegacySwapRefundAuthorization: () => deriveLegacySwapRefundAuthorization,
|
|
722
725
|
derivePublicKey: () => derivePublicKey,
|
|
726
|
+
deriveRequestKeyRange: () => deriveRequestKeyRange,
|
|
727
|
+
deriveRequestKeyRoot: () => deriveRequestKeyRoot,
|
|
728
|
+
deriveRequestKeys: () => deriveRequestKeys,
|
|
723
729
|
deriveSpendKey: () => deriveSpendKey,
|
|
724
730
|
deriveSwapRefundAuthorization: () => deriveSwapRefundAuthorization,
|
|
725
731
|
deriveSwapRefundBlinding: () => deriveSwapRefundBlinding,
|
|
@@ -808,6 +814,7 @@ __export(index_exports, {
|
|
|
808
814
|
isTerminalFailure: () => isTerminalFailure,
|
|
809
815
|
isTransactionSigner: () => import_kit2.isTransactionSigner,
|
|
810
816
|
isValidHex: () => isValidHex,
|
|
817
|
+
isValidRelayClientId: () => isValidRelayClientId,
|
|
811
818
|
isValidRpcUrl: () => isValidRpcUrl,
|
|
812
819
|
isValidSolanaAddress: () => isValidSolanaAddress,
|
|
813
820
|
isWithdrawAmountSufficient: () => isWithdrawAmountSufficient,
|
|
@@ -821,6 +828,7 @@ __export(index_exports, {
|
|
|
821
828
|
matchSwapRefundLeaf: () => matchSwapRefundLeaf,
|
|
822
829
|
mayRetry: () => mayRetry,
|
|
823
830
|
messageSignerFromCallback: () => messageSignerFromCallback,
|
|
831
|
+
normalizeAffiliateCode: () => normalizeAffiliateCode,
|
|
824
832
|
openRecipientDeliveryNote: () => openRecipientDeliveryNote,
|
|
825
833
|
parseAmount: () => parseAmount,
|
|
826
834
|
parseDeliveryCarrierMemo: () => parseDeliveryCarrierMemo,
|
|
@@ -884,6 +892,7 @@ __export(index_exports, {
|
|
|
884
892
|
sumUtxoAmounts: () => sumUtxoAmounts,
|
|
885
893
|
swapUtxo: () => swapUtxo,
|
|
886
894
|
swapWithChange: () => swapWithChange,
|
|
895
|
+
sweepToWalletKey: () => sweepToWalletKey,
|
|
887
896
|
toAddress: () => toAddress,
|
|
888
897
|
toComplianceReport: () => toComplianceReport,
|
|
889
898
|
transact: () => transact,
|
|
@@ -5531,6 +5540,19 @@ async function preflightCheck(relayUrl, rootHex) {
|
|
|
5531
5540
|
};
|
|
5532
5541
|
}
|
|
5533
5542
|
|
|
5543
|
+
// src/relay/affiliate.ts
|
|
5544
|
+
var AFFILIATE_CODE_PATTERN = /^[a-z0-9_]{3,24}$/;
|
|
5545
|
+
var RELAY_CLIENT_HEADER_NAME = "X-Cloak-Client";
|
|
5546
|
+
var RELAY_CLIENT_HEADER_PATTERN = /^cloak-mobile\/(ios|android)\/\d+\.\d+\.\d+$/;
|
|
5547
|
+
function normalizeAffiliateCode(raw) {
|
|
5548
|
+
if (typeof raw !== "string") return null;
|
|
5549
|
+
const code = raw.trim().toLowerCase();
|
|
5550
|
+
return AFFILIATE_CODE_PATTERN.test(code) ? code : null;
|
|
5551
|
+
}
|
|
5552
|
+
function isValidRelayClientId(value) {
|
|
5553
|
+
return typeof value === "string" && RELAY_CLIENT_HEADER_PATTERN.test(value);
|
|
5554
|
+
}
|
|
5555
|
+
|
|
5534
5556
|
// src/flows/transact.ts
|
|
5535
5557
|
var import_kit8 = require("@solana/kit");
|
|
5536
5558
|
var import_compute_budget = require("@solana-program/compute-budget");
|
|
@@ -7189,7 +7211,41 @@ function assertInputMints(inputUtxos, expectedMint) {
|
|
|
7189
7211
|
}
|
|
7190
7212
|
}
|
|
7191
7213
|
function affiliateCodeOrUndefined(code) {
|
|
7192
|
-
return
|
|
7214
|
+
return normalizeAffiliateCode(code) ?? void 0;
|
|
7215
|
+
}
|
|
7216
|
+
function prepareAffiliateAndClient(options) {
|
|
7217
|
+
let next = options;
|
|
7218
|
+
const raw = options.affiliateCode;
|
|
7219
|
+
if (raw !== void 0 && raw !== null) {
|
|
7220
|
+
const normalized = normalizeAffiliateCode(raw);
|
|
7221
|
+
if (normalized === null) {
|
|
7222
|
+
if (typeof raw === "string" && raw.trim() !== "") {
|
|
7223
|
+
options.onWarning?.(
|
|
7224
|
+
`affiliateCode ${JSON.stringify(raw)} is not a valid partner code (3-24 characters of a-z, 0-9 or _, after trimming and lower-casing); it was left out of the request.`
|
|
7225
|
+
);
|
|
7226
|
+
}
|
|
7227
|
+
next = { ...next, affiliateCode: void 0 };
|
|
7228
|
+
} else if (normalized !== raw) {
|
|
7229
|
+
next = { ...next, affiliateCode: normalized };
|
|
7230
|
+
}
|
|
7231
|
+
}
|
|
7232
|
+
const clientId = options.relayClientId;
|
|
7233
|
+
if (clientId !== void 0 && clientId !== null && !isValidRelayClientId(clientId)) {
|
|
7234
|
+
if (typeof clientId !== "string" || clientId.trim() !== "") {
|
|
7235
|
+
options.onWarning?.(
|
|
7236
|
+
`relayClientId ${JSON.stringify(clientId)} does not match cloak-mobile/(ios|android)/MAJOR.MINOR.PATCH; no X-Cloak-Client header was sent.`
|
|
7237
|
+
);
|
|
7238
|
+
}
|
|
7239
|
+
next = { ...next, relayClientId: void 0 };
|
|
7240
|
+
} else if (isValidRelayClientId(clientId)) {
|
|
7241
|
+
const headers = {};
|
|
7242
|
+
for (const [name, value] of Object.entries(options.relayHeaders ?? {})) {
|
|
7243
|
+
if (name.toLowerCase() !== RELAY_CLIENT_HEADER_NAME.toLowerCase()) headers[name] = value;
|
|
7244
|
+
}
|
|
7245
|
+
headers[RELAY_CLIENT_HEADER_NAME] = clientId;
|
|
7246
|
+
next = { ...next, relayHeaders: headers };
|
|
7247
|
+
}
|
|
7248
|
+
return next;
|
|
7193
7249
|
}
|
|
7194
7250
|
function parseNkInput(input) {
|
|
7195
7251
|
if (typeof input !== "string") {
|
|
@@ -8844,7 +8900,8 @@ async function submitTransactToRelay(args) {
|
|
|
8844
8900
|
new Error(`Relay submission exhausted ${maxNetworkRetries + 1} attempts without an outcome`)
|
|
8845
8901
|
);
|
|
8846
8902
|
}
|
|
8847
|
-
async function transact(params,
|
|
8903
|
+
async function transact(params, rawOptions) {
|
|
8904
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
8848
8905
|
const {
|
|
8849
8906
|
connection,
|
|
8850
8907
|
programId,
|
|
@@ -9965,7 +10022,8 @@ async function transact(params, options) {
|
|
|
9965
10022
|
addressLookupTableAccounts: resultAddressLookupTableAccounts
|
|
9966
10023
|
};
|
|
9967
10024
|
}
|
|
9968
|
-
async function transfer(inputUtxos, recipientPubkey, amount,
|
|
10025
|
+
async function transfer(inputUtxos, recipientPubkey, amount, rawOptions) {
|
|
10026
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
9969
10027
|
const owner = await requireOwnerUtxoKeypair(options, "transfer");
|
|
9970
10028
|
const transferNk = await requireWalletNk(options, "transfer");
|
|
9971
10029
|
const inputSum = sumUtxoAmounts(inputUtxos);
|
|
@@ -9991,20 +10049,10 @@ async function transfer(inputUtxos, recipientPubkey, amount, options) {
|
|
|
9991
10049
|
);
|
|
9992
10050
|
}
|
|
9993
10051
|
options.onProgress?.("Moving notes under the wallet key before the transfer...");
|
|
9994
|
-
const
|
|
9995
|
-
const
|
|
9996
|
-
const { recipientViewingPublicKey: _recipientViewingPublicKey, ...migrationOptions } = options;
|
|
9997
|
-
void _recipientViewingPublicKey;
|
|
9998
|
-
const migration = await transact(
|
|
9999
|
-
{ inputUtxos: spendInputs, outputUtxos: [migrated], externalAmount: BigInt(0) },
|
|
10000
|
-
{ ...migrationOptions, chainNoteSalt: migrationSalt }
|
|
10001
|
-
);
|
|
10002
|
-
const migratedNote = migration.outputUtxos?.[0] ?? migrated;
|
|
10003
|
-
if (migration.commitmentIndices?.[0] >= 0) {
|
|
10004
|
-
migratedNote.index = migration.commitmentIndices[0];
|
|
10005
|
-
}
|
|
10052
|
+
const migration = await sweepToWalletKey(spendInputs, options);
|
|
10053
|
+
const migratedNote = migration.note;
|
|
10006
10054
|
spendInputs = [migratedNote];
|
|
10007
|
-
spendOptions = { ...options, cachedMerkleTree: migration.merkleTree };
|
|
10055
|
+
spendOptions = { ...options, cachedMerkleTree: migration.result.merkleTree };
|
|
10008
10056
|
}
|
|
10009
10057
|
const changeNoteSalt = randomChangeNoteSalt();
|
|
10010
10058
|
const isSendToSelf = recipientPubkey === owner.publicKey || inputUtxos.some((u) => u.keypair.publicKey === recipientPubkey);
|
|
@@ -10036,7 +10084,29 @@ async function transfer(inputUtxos, recipientPubkey, amount, options) {
|
|
|
10036
10084
|
{ ...spendOptions, chainNoteSalt: changeNoteSalt }
|
|
10037
10085
|
);
|
|
10038
10086
|
}
|
|
10039
|
-
async function
|
|
10087
|
+
async function sweepToWalletKey(inputUtxos, rawOptions) {
|
|
10088
|
+
if (inputUtxos.length === 0 || inputUtxos.length > 2) {
|
|
10089
|
+
throw new Error("sweepToWalletKey: one transaction moves 1 or 2 notes");
|
|
10090
|
+
}
|
|
10091
|
+
assertInputMints(inputUtxos, rawOptions.expectedMint);
|
|
10092
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
10093
|
+
const owner = await requireOwnerUtxoKeypair(options, "sweepToWalletKey");
|
|
10094
|
+
const walletNk = await requireWalletNk(options, "sweepToWalletKey");
|
|
10095
|
+
const mint = inputUtxos[0].mintAddress;
|
|
10096
|
+
const salt = randomChangeNoteSalt();
|
|
10097
|
+
const migrated = (await createRecoverableChangeUtxo(sumUtxoAmounts(inputUtxos), owner, walletNk, mint, salt, 0)).utxo;
|
|
10098
|
+
const { recipientViewingPublicKey: _recipientViewingPublicKey, ...sweepOptions } = options;
|
|
10099
|
+
void _recipientViewingPublicKey;
|
|
10100
|
+
const result = await transact(
|
|
10101
|
+
{ inputUtxos, outputUtxos: [migrated], externalAmount: BigInt(0) },
|
|
10102
|
+
{ ...sweepOptions, chainNoteSalt: salt }
|
|
10103
|
+
);
|
|
10104
|
+
const note = result.outputUtxos?.[0] ?? migrated;
|
|
10105
|
+
if (result.commitmentIndices?.[0] >= 0) note.index = result.commitmentIndices[0];
|
|
10106
|
+
return { note, result };
|
|
10107
|
+
}
|
|
10108
|
+
async function partialWithdraw(inputUtxos, recipient, withdrawAmount, rawOptions) {
|
|
10109
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
10040
10110
|
const owner = await requireOwnerUtxoKeypair(options, "partialWithdraw");
|
|
10041
10111
|
const walletNk = await requireWalletNk(options, "partialWithdraw");
|
|
10042
10112
|
const inputSum = sumUtxoAmounts(inputUtxos);
|
|
@@ -10178,7 +10248,8 @@ async function waitForSwapCompletion(relayUrl, requestId, onProgress, maxAttempt
|
|
|
10178
10248
|
}
|
|
10179
10249
|
return null;
|
|
10180
10250
|
}
|
|
10181
|
-
async function swapUtxo(params,
|
|
10251
|
+
async function swapUtxo(params, rawOptions) {
|
|
10252
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
10182
10253
|
const {
|
|
10183
10254
|
inputUtxos,
|
|
10184
10255
|
changeUtxo,
|
|
@@ -11061,7 +11132,8 @@ async function swapUtxo(params, options) {
|
|
|
11061
11132
|
}
|
|
11062
11133
|
};
|
|
11063
11134
|
}
|
|
11064
|
-
async function swapWithChange(inputUtxos, swapAmount, outputMint, recipientAta, minOutputAmount,
|
|
11135
|
+
async function swapWithChange(inputUtxos, swapAmount, outputMint, recipientAta, minOutputAmount, rawOptions, recipientWallet) {
|
|
11136
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
11065
11137
|
const owner = await requireOwnerUtxoKeypair(options, "swapWithChange");
|
|
11066
11138
|
const totalInput = sumUtxoAmounts(inputUtxos);
|
|
11067
11139
|
const change = totalInput - swapAmount;
|
|
@@ -11469,7 +11541,8 @@ function createRelayBatchAuthCoordinator(options) {
|
|
|
11469
11541
|
}
|
|
11470
11542
|
|
|
11471
11543
|
// src/flows/transact-batch.ts
|
|
11472
|
-
async function transactBatch(items,
|
|
11544
|
+
async function transactBatch(items, rawOptions) {
|
|
11545
|
+
const options = prepareAffiliateAndClient(rawOptions);
|
|
11473
11546
|
if (items.length === 0) {
|
|
11474
11547
|
return { results: [], approvals: 0 };
|
|
11475
11548
|
}
|
|
@@ -11544,6 +11617,7 @@ var TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
|
11544
11617
|
var SOL_MINT = "So11111111111111111111111111111111111111112";
|
|
11545
11618
|
var USDC_MINT = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
11546
11619
|
var USDT_MINT = "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB";
|
|
11620
|
+
var BRS_MINT = "BRSxQRUaGswjLs7ewcH7uXj3r7SgmfKSSLLXyCKHZtUo";
|
|
11547
11621
|
var PUBLIC_AMOUNT_OFFSET = 32;
|
|
11548
11622
|
var EXT_DATA_HASH_OFFSET = 40;
|
|
11549
11623
|
var OUTPUT_COMMITMENT_0_OFFSET = 168;
|
|
@@ -11600,6 +11674,7 @@ function symbolForMint(mint) {
|
|
|
11600
11674
|
if (mint === SOL_MINT) return "SOL";
|
|
11601
11675
|
if (mint === USDC_MINT) return "USDC";
|
|
11602
11676
|
if (mint === USDT_MINT) return "USDT";
|
|
11677
|
+
if (mint === BRS_MINT) return "BRS";
|
|
11603
11678
|
if (!mint || mint.length < 8) return "TOKEN";
|
|
11604
11679
|
return `${mint.slice(0, 4)}...${mint.slice(-4)}`;
|
|
11605
11680
|
}
|
|
@@ -13272,6 +13347,69 @@ async function fetchNoteIndexPage(relayUrl, epoch, page, options = {}) {
|
|
|
13272
13347
|
});
|
|
13273
13348
|
}
|
|
13274
13349
|
|
|
13350
|
+
// src/notes/request-keys.ts
|
|
13351
|
+
var import_blake37 = require("@noble/hashes/blake3");
|
|
13352
|
+
var import_tweetnacl6 = __toESM(require("tweetnacl"), 1);
|
|
13353
|
+
init_utxo();
|
|
13354
|
+
var BN254_ORDER = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
|
13355
|
+
var ROOT_SEED_DOMAIN = new TextEncoder().encode("cloak_request_root_v1");
|
|
13356
|
+
var ROOT_NK_DOMAIN = new TextEncoder().encode("cloak_request_root_nk_v1");
|
|
13357
|
+
var UTXO_DOMAIN = new TextEncoder().encode("cloak_request_utxo_v1");
|
|
13358
|
+
var VIEWING_DOMAIN = new TextEncoder().encode("cloak_request_vk_v1");
|
|
13359
|
+
var REQUEST_KEY_ROOT_SOURCE = "nk";
|
|
13360
|
+
var REQUEST_KEY_GAP_LIMIT = 20;
|
|
13361
|
+
var MAX_REQUEST_KEYS = 64;
|
|
13362
|
+
function check32(value, label) {
|
|
13363
|
+
if (!(value instanceof Uint8Array) || value.length !== 32) throw new Error(`${label} must be 32 bytes`);
|
|
13364
|
+
return value;
|
|
13365
|
+
}
|
|
13366
|
+
function counterBytes(counter) {
|
|
13367
|
+
if (!Number.isInteger(counter) || counter < 0 || counter > 4294967295) throw new Error("request counter must be a u32");
|
|
13368
|
+
const out = new Uint8Array(4);
|
|
13369
|
+
new DataView(out.buffer).setUint32(0, counter, false);
|
|
13370
|
+
return out;
|
|
13371
|
+
}
|
|
13372
|
+
function hashWith(domain, root, counter) {
|
|
13373
|
+
const c = counterBytes(counter);
|
|
13374
|
+
const pre = new Uint8Array(domain.length + root.length + c.length);
|
|
13375
|
+
pre.set(domain, 0);
|
|
13376
|
+
pre.set(root, domain.length);
|
|
13377
|
+
pre.set(c, domain.length + root.length);
|
|
13378
|
+
return (0, import_blake37.blake3)(pre);
|
|
13379
|
+
}
|
|
13380
|
+
function deriveRequestKeyRoot(input, source = REQUEST_KEY_ROOT_SOURCE) {
|
|
13381
|
+
const secret = source === "seed" ? check32(input.skSpend, "skSpend") : check32(input.nk, "nk");
|
|
13382
|
+
const domain = source === "seed" ? ROOT_SEED_DOMAIN : ROOT_NK_DOMAIN;
|
|
13383
|
+
const pre = new Uint8Array(domain.length + 32);
|
|
13384
|
+
pre.set(domain, 0);
|
|
13385
|
+
pre.set(secret, domain.length);
|
|
13386
|
+
return (0, import_blake37.blake3)(pre);
|
|
13387
|
+
}
|
|
13388
|
+
async function deriveRequestKeys(root, counter) {
|
|
13389
|
+
check32(root, "request root");
|
|
13390
|
+
const h = hashWith(UTXO_DOMAIN, root, counter);
|
|
13391
|
+
let value = 0n;
|
|
13392
|
+
for (let i = 0; i < 32; i++) value = value << 8n | BigInt(h[i]);
|
|
13393
|
+
const privateKey = value % (BN254_ORDER >> 4n);
|
|
13394
|
+
if (privateKey === 0n) throw new Error("request key derivation produced a zero key");
|
|
13395
|
+
const publicKey = await derivePublicKey(privateKey);
|
|
13396
|
+
const vk = hashWith(VIEWING_DOMAIN, root, counter);
|
|
13397
|
+
vk[0] &= 248;
|
|
13398
|
+
vk[31] &= 127;
|
|
13399
|
+
vk[31] |= 64;
|
|
13400
|
+
return {
|
|
13401
|
+
counter,
|
|
13402
|
+
utxoKeypair: { privateKey, publicKey },
|
|
13403
|
+
viewingKeypair: { privateKey: vk, publicKey: import_tweetnacl6.default.scalarMult.base(vk) }
|
|
13404
|
+
};
|
|
13405
|
+
}
|
|
13406
|
+
async function deriveRequestKeyRange(root, from, count) {
|
|
13407
|
+
if (!Number.isInteger(count) || count < 0 || count > MAX_REQUEST_KEYS) throw new Error(`count must be in 0..${MAX_REQUEST_KEYS}`);
|
|
13408
|
+
const out = [];
|
|
13409
|
+
for (let i = 0; i < count; i++) out.push(await deriveRequestKeys(root, from + i));
|
|
13410
|
+
return out;
|
|
13411
|
+
}
|
|
13412
|
+
|
|
13275
13413
|
// src/scanning/note-index.ts
|
|
13276
13414
|
var import_bs584 = __toESM(require("bs58"), 1);
|
|
13277
13415
|
var import_sha26 = require("@noble/hashes/sha2");
|
|
@@ -13383,6 +13521,7 @@ var LeafBuffer = class {
|
|
|
13383
13521
|
async function trialItem(item, trials) {
|
|
13384
13522
|
for (const trial of trials) {
|
|
13385
13523
|
if (trial.legacy && item.kind === 2) continue;
|
|
13524
|
+
if (trial.requestIndex !== void 0 && item.kind !== 2) continue;
|
|
13386
13525
|
const opened = await trialItemWith(item, trial);
|
|
13387
13526
|
if (opened) return { ...opened, trial };
|
|
13388
13527
|
}
|
|
@@ -13462,7 +13601,7 @@ async function matchOwnItems(own, owner, onReject, onSkip) {
|
|
|
13462
13601
|
const nullifier = hex32(
|
|
13463
13602
|
await computeNullifier({ amount: c.amount, keypair: c.keypair, blinding: c.blinding, mintAddress: c.mint, index: c.leaf, commitment: c.commitment })
|
|
13464
13603
|
);
|
|
13465
|
-
const full = { ...c, atRisk: c.atRisk || o.trial.legacy, signature: o.item.signature, page: o.page, seq: o.seq, nullifier };
|
|
13604
|
+
const full = { ...c, requestIndex: o.trial.requestIndex, atRisk: c.atRisk || o.trial.legacy, signature: o.item.signature, page: o.page, seq: o.seq, nullifier };
|
|
13466
13605
|
candidates.push(full);
|
|
13467
13606
|
if (!byNullifier.has(nullifier)) {
|
|
13468
13607
|
byNullifier.set(nullifier, full);
|
|
@@ -13540,9 +13679,10 @@ async function matchOwnItems(own, owner, onReject, onSkip) {
|
|
|
13540
13679
|
onReject(o);
|
|
13541
13680
|
return;
|
|
13542
13681
|
}
|
|
13682
|
+
const deliveryOwner = o.trial.requestIndex !== void 0 ? o.trial.owner : owner;
|
|
13543
13683
|
const commitment = await computeCommitment2({
|
|
13544
13684
|
amount: o.delivery.amount,
|
|
13545
|
-
keypair: { privateKey: 0n, publicKey:
|
|
13685
|
+
keypair: { privateKey: 0n, publicKey: deliveryOwner.publicKey },
|
|
13546
13686
|
blinding: o.delivery.blinding,
|
|
13547
13687
|
mintAddress: mint
|
|
13548
13688
|
});
|
|
@@ -13555,7 +13695,7 @@ async function matchOwnItems(own, owner, onReject, onSkip) {
|
|
|
13555
13695
|
atRisk: false,
|
|
13556
13696
|
amount: o.delivery.amount,
|
|
13557
13697
|
blinding: o.delivery.blinding,
|
|
13558
|
-
keypair:
|
|
13698
|
+
keypair: deliveryOwner,
|
|
13559
13699
|
mint,
|
|
13560
13700
|
commitment,
|
|
13561
13701
|
leaf: Number(item.leaf)
|
|
@@ -13909,6 +14049,24 @@ async function recoverNotesFromIndex(params) {
|
|
|
13909
14049
|
seenNks.add(key);
|
|
13910
14050
|
trials.push(await makeTrial(Uint8Array.from(nk), true));
|
|
13911
14051
|
}
|
|
14052
|
+
const requestKeys = params.requestKeys ?? [];
|
|
14053
|
+
if (!Array.isArray(requestKeys)) throw new Error("requestKeys must be an array");
|
|
14054
|
+
if (requestKeys.length > MAX_REQUEST_KEYS) throw new Error(`requestKeys takes at most ${MAX_REQUEST_KEYS} keys`);
|
|
14055
|
+
const seenRequestIdx = /* @__PURE__ */ new Set();
|
|
14056
|
+
for (const rk of requestKeys) {
|
|
14057
|
+
if (!Number.isInteger(rk.index) || rk.index < 0 || seenRequestIdx.has(rk.index)) throw new Error("requestKeys entries need distinct non-negative integer indexes");
|
|
14058
|
+
seenRequestIdx.add(rk.index);
|
|
14059
|
+
if (!(rk.viewingSecretKey instanceof Uint8Array) || rk.viewingSecretKey.length !== 32) throw new Error("requestKeys viewingSecretKey must be 32 bytes");
|
|
14060
|
+
const ownerKp = await assertOwnerUtxoKeypair(rk.ownerKeypair, "requestKeys.ownerKeypair");
|
|
14061
|
+
trials.push({
|
|
14062
|
+
nk: new Uint8Array(32),
|
|
14063
|
+
legacy: false,
|
|
14064
|
+
owner: ownerKp,
|
|
14065
|
+
requestIndex: rk.index,
|
|
14066
|
+
decrypt: async () => null,
|
|
14067
|
+
open: await createRecipientDeliveryOpener(rk.viewingSecretKey)
|
|
14068
|
+
});
|
|
14069
|
+
}
|
|
13912
14070
|
const poolMints = Array.from(new Set(params.poolMints));
|
|
13913
14071
|
const warnings = [];
|
|
13914
14072
|
const head = await fetchNoteIndexHead(relayUrl, { signal: params.signal });
|
|
@@ -13945,6 +14103,7 @@ async function recoverNotesFromIndex(params) {
|
|
|
13945
14103
|
}
|
|
13946
14104
|
async function runOnce(ctx, cursor) {
|
|
13947
14105
|
const { params, head, trials, owner, stats, poolMints } = ctx;
|
|
14106
|
+
const requestOwners = new Set(trials.filter((t) => t.requestIndex !== void 0).map((t) => t.owner.publicKey));
|
|
13948
14107
|
const { relayUrl, onProgress } = params;
|
|
13949
14108
|
const poolSet = new Set(poolMints);
|
|
13950
14109
|
const startPage = cursor?.raw.page ?? 0;
|
|
@@ -14232,7 +14391,8 @@ async function runOnce(ctx, cursor) {
|
|
|
14232
14391
|
for (const c of byLeaf.values()) {
|
|
14233
14392
|
const pubOk = keyChecked.get(c.keypair.privateKey) ?? (c.keypair.privateKey !== 0n && await derivePublicKey(c.keypair.privateKey) === c.keypair.publicKey);
|
|
14234
14393
|
keyChecked.set(c.keypair.privateKey, pubOk);
|
|
14235
|
-
|
|
14394
|
+
const ownerOk = c.requestIndex !== void 0 ? requestOwners.has(c.keypair.publicKey) : c.keypair.publicKey === owner.publicKey;
|
|
14395
|
+
if (!pubOk || !c.atRisk && !ownerOk) {
|
|
14236
14396
|
stats.dropped++;
|
|
14237
14397
|
tally(c, "rejected");
|
|
14238
14398
|
continue;
|
|
@@ -14241,7 +14401,7 @@ async function runOnce(ctx, cursor) {
|
|
|
14241
14401
|
verifiedOut.add(verifiedKey(c.mint, c.leaf, c.commitment));
|
|
14242
14402
|
const utxo = {
|
|
14243
14403
|
amount: c.amount,
|
|
14244
|
-
keypair: c.atRisk ? { ...c.keypair } : owner,
|
|
14404
|
+
keypair: c.atRisk ? { ...c.keypair } : c.requestIndex !== void 0 ? c.keypair : owner,
|
|
14245
14405
|
blinding: c.blinding,
|
|
14246
14406
|
mintAddress: c.mint,
|
|
14247
14407
|
index: c.leaf,
|
|
@@ -14256,7 +14416,8 @@ async function runOnce(ctx, cursor) {
|
|
|
14256
14416
|
kind: c.kind,
|
|
14257
14417
|
utxo,
|
|
14258
14418
|
signature: bs584.encode(c.signature),
|
|
14259
|
-
legacyExposed: c.atRisk
|
|
14419
|
+
legacyExposed: c.atRisk,
|
|
14420
|
+
...c.requestIndex !== void 0 ? { requestIndex: c.requestIndex } : {}
|
|
14260
14421
|
};
|
|
14261
14422
|
(c.atRisk ? atRisk : notes).push(note);
|
|
14262
14423
|
}
|
|
@@ -14701,7 +14862,7 @@ async function loadWeb3() {
|
|
|
14701
14862
|
}
|
|
14702
14863
|
|
|
14703
14864
|
// src/bridge/rail-verify.ts
|
|
14704
|
-
var
|
|
14865
|
+
var import_tweetnacl7 = __toESM(require("tweetnacl"), 1);
|
|
14705
14866
|
var import_sha256 = require("@noble/hashes/sha256");
|
|
14706
14867
|
var ONECLICK_PUBKEY_B58 = "reYaWhvwu8Jzo3WUM3zhn6VrhuMEF4eADL17qtRVifc";
|
|
14707
14868
|
var b58 = /* @__PURE__ */ (() => {
|
|
@@ -14812,7 +14973,7 @@ function verifyQuoteSignature(resp) {
|
|
|
14812
14973
|
const message = new TextEncoder().encode(b58.encode(new Uint8Array(digest)));
|
|
14813
14974
|
const sig = resp.signature.replace(/^ed25519:/, "");
|
|
14814
14975
|
try {
|
|
14815
|
-
return { valid:
|
|
14976
|
+
return { valid: import_tweetnacl7.default.sign.detached.verify(message, b58.decode(sig), b58.decode(ONECLICK_PUBKEY_B58)) };
|
|
14816
14977
|
} catch (e) {
|
|
14817
14978
|
return { valid: false, reason: e instanceof Error ? e.message : String(e) };
|
|
14818
14979
|
}
|
|
@@ -15041,7 +15202,7 @@ async function fundReceiverViaPaymaster(relayUrl, receiver, grantLamports) {
|
|
|
15041
15202
|
// src/bridge/derive.ts
|
|
15042
15203
|
var import_hmac = require("@noble/hashes/hmac");
|
|
15043
15204
|
var import_sha512 = require("@noble/hashes/sha512");
|
|
15044
|
-
var
|
|
15205
|
+
var import_blake38 = require("@noble/hashes/blake3");
|
|
15045
15206
|
init_utxo();
|
|
15046
15207
|
var BRIDGE_ESCROW_LABEL = "cloak_bridge_escrow";
|
|
15047
15208
|
var BRIDGE_ESCROW_LABEL_V2 = "cloak_bridge_escrow_v2";
|
|
@@ -15069,7 +15230,7 @@ async function deriveBridgeReceiver(ownerUtxoKeypair, index) {
|
|
|
15069
15230
|
const preimage = new Uint8Array(BRIDGE_RECEIVER_KEY_DOMAIN.length + priv.length);
|
|
15070
15231
|
preimage.set(BRIDGE_RECEIVER_KEY_DOMAIN, 0);
|
|
15071
15232
|
preimage.set(priv, BRIDGE_RECEIVER_KEY_DOMAIN.length);
|
|
15072
|
-
const key = (0,
|
|
15233
|
+
const key = (0, import_blake38.blake3)(preimage);
|
|
15073
15234
|
const h = (0, import_hmac.hmac)(import_sha512.sha512, key, new TextEncoder().encode(`${BRIDGE_ESCROW_LABEL_V2}:${index}`));
|
|
15074
15235
|
return signerFromSecretKey(h.slice(0, 32));
|
|
15075
15236
|
}
|
|
@@ -15573,7 +15734,7 @@ async function withShieldRetries(attempt, hooks = {}) {
|
|
|
15573
15734
|
}
|
|
15574
15735
|
|
|
15575
15736
|
// src/index.ts
|
|
15576
|
-
var VERSION = "0.2.
|
|
15737
|
+
var VERSION = "0.2.8";
|
|
15577
15738
|
var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
15578
15739
|
// Annotate the CommonJS export names for ESM import in node:
|
|
15579
15740
|
0 && (module.exports = {
|
|
@@ -15602,6 +15763,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15602
15763
|
MAINNET_RENT_0,
|
|
15603
15764
|
MAINNET_RENT_1,
|
|
15604
15765
|
MAX_RECEIVER_INDEX,
|
|
15766
|
+
MAX_REQUEST_KEYS,
|
|
15605
15767
|
MERKLE_TREE_HEIGHT,
|
|
15606
15768
|
MIN_DEPOSIT_LAMPORTS,
|
|
15607
15769
|
MIN_DEPOSIT_SPL_BASE_UNITS,
|
|
@@ -15625,6 +15787,8 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15625
15787
|
REQUEST_AUTH_BATCH_MAX_AGE_SECONDS,
|
|
15626
15788
|
REQUEST_AUTH_MAX_AGE_SECONDS,
|
|
15627
15789
|
REQUEST_AUTH_MAX_FUTURE_SKEW_SECONDS,
|
|
15790
|
+
REQUEST_KEY_GAP_LIMIT,
|
|
15791
|
+
REQUEST_KEY_ROOT_SOURCE,
|
|
15628
15792
|
RelayBatchAuthCoordinator,
|
|
15629
15793
|
RelayInternalError,
|
|
15630
15794
|
RelayService,
|
|
@@ -15722,6 +15886,9 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15722
15886
|
deriveLegacyDepositNoteSecrets,
|
|
15723
15887
|
deriveLegacySwapRefundAuthorization,
|
|
15724
15888
|
derivePublicKey,
|
|
15889
|
+
deriveRequestKeyRange,
|
|
15890
|
+
deriveRequestKeyRoot,
|
|
15891
|
+
deriveRequestKeys,
|
|
15725
15892
|
deriveSpendKey,
|
|
15726
15893
|
deriveSwapRefundAuthorization,
|
|
15727
15894
|
deriveSwapRefundBlinding,
|
|
@@ -15810,6 +15977,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15810
15977
|
isTerminalFailure,
|
|
15811
15978
|
isTransactionSigner,
|
|
15812
15979
|
isValidHex,
|
|
15980
|
+
isValidRelayClientId,
|
|
15813
15981
|
isValidRpcUrl,
|
|
15814
15982
|
isValidSolanaAddress,
|
|
15815
15983
|
isWithdrawAmountSufficient,
|
|
@@ -15823,6 +15991,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15823
15991
|
matchSwapRefundLeaf,
|
|
15824
15992
|
mayRetry,
|
|
15825
15993
|
messageSignerFromCallback,
|
|
15994
|
+
normalizeAffiliateCode,
|
|
15826
15995
|
openRecipientDeliveryNote,
|
|
15827
15996
|
parseAmount,
|
|
15828
15997
|
parseDeliveryCarrierMemo,
|
|
@@ -15886,6 +16055,7 @@ var SCANNER_SUPPORTS_TRANSACT_SWAP = true;
|
|
|
15886
16055
|
sumUtxoAmounts,
|
|
15887
16056
|
swapUtxo,
|
|
15888
16057
|
swapWithChange,
|
|
16058
|
+
sweepToWalletKey,
|
|
15889
16059
|
toAddress,
|
|
15890
16060
|
toComplianceReport,
|
|
15891
16061
|
transact,
|