@cloak.dev/sdk 0.2.6-staging.6c85601 → 0.2.6-staging.af2dfc0
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 +101 -0
- package/README.md +88 -39
- package/dist/index.cjs +465 -155
- package/dist/index.d.cts +317 -154
- package/dist/index.d.ts +317 -154
- package/dist/index.js +455 -154
- package/package.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@cloak.dev/sdk` are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Releases before 0.2.6 are described in
|
|
6
|
+
the README's "Version and compatibility" section and in the git history.
|
|
7
|
+
|
|
8
|
+
## [0.2.6]
|
|
9
|
+
|
|
10
|
+
Pairs with the same mainnet program (`zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`) and the same
|
|
11
|
+
0.2.0 circuit bundle as 0.2.5. Note format and hashing are unchanged.
|
|
12
|
+
|
|
13
|
+
### nk view-only (for notes created from 0.2.6 on)
|
|
14
|
+
|
|
15
|
+
The viewing base `nk` is registered with the relay and may be shared with an auditor, so nothing
|
|
16
|
+
that spends or moves funds may be derivable from it. Every note the SDK creates for the wallet
|
|
17
|
+
(deposits, withdraw and swap change, `partialWithdraw` merges, the full-withdraw refund slot, swap
|
|
18
|
+
refunds, bridge receivers and sends to self) is now owned by the wallet's long-lived UTXO keypair,
|
|
19
|
+
passed explicitly as `ownerUtxoKeypair` (`deriveUtxoKeypairFromSpendKey(skSpend)`). `nk` only
|
|
20
|
+
derives blindings, so a scan still finds the notes, and encrypts chain notes.
|
|
21
|
+
|
|
22
|
+
**Older notes.** "nk view-only" holds for notes created from 0.2.6 on. A note created before 0.2.6
|
|
23
|
+
may have an owner key derived from `nk`; such a note moves under the wallet key only when it is
|
|
24
|
+
spent, and nothing in this release moves an idle balance. Until it is spent, `nk` can still spend
|
|
25
|
+
it. These notes are still found by `matchDepositNote`, `matchSwapRefundLeaf`, `matchChangeNote`,
|
|
26
|
+
`scanTransactions` and `discoverSwapRefunds`, come back spendable, and are flagged
|
|
27
|
+
`legacyExposed: true`.
|
|
28
|
+
|
|
29
|
+
#### Changed (BREAKING)
|
|
30
|
+
|
|
31
|
+
* **`SpendOptions.ownerUtxoKeypair` is required.** `transfer`, `partialWithdraw`, `fullWithdraw`,
|
|
32
|
+
`swapUtxo` and `swapWithChange` take `SpendOptions` (`TransactOptions & { ownerUtxoKeypair }`)
|
|
33
|
+
and refuse without it. Change, merges, send-to-self outputs and swap refund leaves are owned by
|
|
34
|
+
it, never by `inputUtxos[0]`'s key. When no input is owned by it, `transfer` first moves the
|
|
35
|
+
inputs into one wallet-owned note (the circuit pins a non-zero output 1 to input 0's key), which
|
|
36
|
+
a `relayAuthBatch` item cannot carry, and which takes at most 2 inputs: with more, `transfer`
|
|
37
|
+
throws and asks the caller to consolidate (send to self, 2 at a time) or withdraw the older
|
|
38
|
+
notes first.
|
|
39
|
+
* **`createRecoverableDepositUtxo` takes one options object**:
|
|
40
|
+
`createRecoverableDepositUtxo({ amount, viewingKeyNk, ownerUtxoKeypair, mintAddress?, noteSalt? })`
|
|
41
|
+
instead of `(amount, viewingKeyNk, mintAddress?, noteSalt?)`. The note is owned by
|
|
42
|
+
`ownerUtxoKeypair`; only its blinding comes from `(nk, noteSalt)`.
|
|
43
|
+
* **`deriveSwapRefundAuthorization(viewingKeyNk, inputNullifier, ownerUtxoKeypair)`** gains the
|
|
44
|
+
third argument. The refund owner is the wallet keypair; the blinding stays
|
|
45
|
+
`PRF(nk, nullifier0)`. `UtxoSwapResult.refund` no longer carries a private key.
|
|
46
|
+
* **`discoverSwapRefunds` requires `options.ownerUtxoKeypair`**: refund leaves are owned by it, and
|
|
47
|
+
`nk` alone only finds legacy refunds.
|
|
48
|
+
* **`deriveBridgeReceiver(ownerUtxoKeypair, index)`** replaces `deriveBridgeReceiver(nk, index)`:
|
|
49
|
+
receivers are derived from the UTXO private key under the v2 label `cloak_bridge_escrow_v2`
|
|
50
|
+
(`BRIDGE_ESCROW_LABEL_V2`), no longer from `nk` under `cloak_bridge_escrow`.
|
|
51
|
+
`listBridgeDeposits(rpc, ownerUtxoKeypair, opts)` takes the keypair too, and also scans the
|
|
52
|
+
legacy `nk` receivers (`opts.includeLegacy`, default on; `opts.legacyViewingKeyNks` for other
|
|
53
|
+
viewing keys the wallet used), flagging them `legacyExposed`.
|
|
54
|
+
* **`transact` needs `chainNoteViewingKeyNk` / `getChainNoteViewingKeyNk` or `ownerUtxoKeypair`**
|
|
55
|
+
(whose canonical nk it then uses). It no longer infers `nk` from an input or output note's key,
|
|
56
|
+
and fails before touching the network when none is given.
|
|
57
|
+
* **`deriveDepositNoteSecrets` is removed.** Use `deriveDepositNoteBlinding` for current deposit
|
|
58
|
+
notes (blinding only; the owner is `ownerUtxoKeypair`) and the recovery-only
|
|
59
|
+
`deriveLegacyDepositNoteSecrets` for notes built by an earlier SDK.
|
|
60
|
+
|
|
61
|
+
#### Added
|
|
62
|
+
|
|
63
|
+
* `deriveDepositNoteBlinding`, `deriveLegacyDepositNoteSecrets`, `deriveSwapRefundBlinding`,
|
|
64
|
+
`deriveLegacySwapRefundAuthorization`, `deriveLegacyBridgeReceiver` and `BRIDGE_ESCROW_LABEL_V2`.
|
|
65
|
+
* `legacyExposed` on recovered deposit, change, swap refund and bridge records: `true` marks a note
|
|
66
|
+
or receiver from before 0.2.6 whose owner key is derivable from `nk`.
|
|
67
|
+
* `scanTransactions` takes `ownerUtxoPublicKey` to match the wallet's own deposits and to
|
|
68
|
+
authenticate delivered notes.
|
|
69
|
+
|
|
70
|
+
### Affiliate code and extra relay headers
|
|
71
|
+
|
|
72
|
+
* `TransactOptions.affiliateCode` (internal, used by Cloak's own apps). `transact`, `swapUtxo` and
|
|
73
|
+
every flow built on them pass it to the request body builders: `/transact` carries
|
|
74
|
+
`affiliate_code` only for a withdrawal with a recipient, `/transact_swap` for any non-empty code;
|
|
75
|
+
deposits and shield-to-shield sends never carry it. It is signed only when present, so a request
|
|
76
|
+
without it is byte-identical to 0.2.5. A request that carries it needs a relay from the affiliate
|
|
77
|
+
release; an older relay answers 401, and the SDK's error then hints at upgrading the relay.
|
|
78
|
+
* `TransactOptions.relayHeaders` (internal) adds headers to `POST /transact` and
|
|
79
|
+
`POST /transact_swap`, for example the mobile client id `X-Cloak-Client`. A name that collides
|
|
80
|
+
with the call's own headers is ignored; names or values with CR, LF or NUL are dropped.
|
|
81
|
+
|
|
82
|
+
### Relay clock
|
|
83
|
+
|
|
84
|
+
* Relay request signatures are stamped with the relay's clock, not the machine's. The relay stamps
|
|
85
|
+
every response with `x-cloak-server-time`; the SDK records the offset from every relay response
|
|
86
|
+
and `auth_issued_at` (single requests and batches) uses it. A machine clock more than 30 seconds
|
|
87
|
+
fast no longer fails with "signature was issued too far in the future".
|
|
88
|
+
* Chain-note timestamps use the relay clock too. Without a usable sample the SDK learns it with one
|
|
89
|
+
`GET /health` through the relay allowlist. A machine more than five minutes off no longer fails
|
|
90
|
+
withdraws, sends and swaps with "chain note is not decryptable".
|
|
91
|
+
* The paymaster client judges the relay-issued voucher expiry on the relay clock.
|
|
92
|
+
* With no sample (a relay that predates the header, or no relay reachable) every stamp falls back to
|
|
93
|
+
`Date.now()`, the 0.2.5 behaviour.
|
|
94
|
+
|
|
95
|
+
### Fixed
|
|
96
|
+
|
|
97
|
+
* A failed deposit no longer rebuilds the Merkle tree from chain (98a818b). A deposit spends no
|
|
98
|
+
inputs, so the replay could not change its outcome; on React Native it cost one
|
|
99
|
+
`getTransaction` per pool transaction (about 2.5k, 7+ minutes) and turned any deposit failure
|
|
100
|
+
(wallet rejection, rent or balance shortfall) into an apparently endless "Generating proof". The
|
|
101
|
+
real error now surfaces at once.
|
package/README.md
CHANGED
|
@@ -130,14 +130,21 @@ async function main() {
|
|
|
130
130
|
const recipient = address(recipientArg);
|
|
131
131
|
const amount = BigInt(lamportsArg);
|
|
132
132
|
|
|
133
|
-
// The wallet's viewing base (nk). A real wallet derives
|
|
134
|
-
// keypair keeps this script
|
|
133
|
+
// The wallet's long-lived UTXO keypair and its viewing base (nk). A real wallet derives the
|
|
134
|
+
// keypair from its seed (deriveUtxoKeypairFromSpendKey); a throwaway keypair keeps this script
|
|
135
|
+
// self-contained.
|
|
135
136
|
const owner = await generateUtxoKeypair();
|
|
136
137
|
const nk = getNkFromUtxoPrivateKey(owner.privateKey);
|
|
137
138
|
|
|
138
|
-
// Shield. The note
|
|
139
|
-
// published inside the nk-encrypted chain note, so a scan holding
|
|
140
|
-
|
|
139
|
+
// Shield. The note is owned by `owner`; only its blinding is derived from (nk, noteSalt), and the
|
|
140
|
+
// salt is published inside the nk-encrypted chain note, so a scan holding nk plus the owner's
|
|
141
|
+
// public key can find it again. nk is view-only: it can never spend the note.
|
|
142
|
+
const { utxo, noteSalt } = await createRecoverableDepositUtxo({
|
|
143
|
+
amount,
|
|
144
|
+
viewingKeyNk: nk,
|
|
145
|
+
ownerUtxoKeypair: owner,
|
|
146
|
+
mintAddress: NATIVE_SOL_MINT,
|
|
147
|
+
});
|
|
141
148
|
const deposited = await transact(
|
|
142
149
|
{
|
|
143
150
|
inputUtxos: [await createZeroUtxo(NATIVE_SOL_MINT)],
|
|
@@ -152,6 +159,7 @@ async function main() {
|
|
|
152
159
|
depositorKeypair: signer,
|
|
153
160
|
chainNoteViewingKeyNk: nk,
|
|
154
161
|
chainNoteSalt: noteSalt,
|
|
162
|
+
ownerUtxoKeypair: owner,
|
|
155
163
|
},
|
|
156
164
|
);
|
|
157
165
|
|
|
@@ -164,6 +172,7 @@ async function main() {
|
|
|
164
172
|
depositorKeypair: signer,
|
|
165
173
|
walletPublicKey: signer.address,
|
|
166
174
|
chainNoteViewingKeyNk: nk,
|
|
175
|
+
ownerUtxoKeypair: owner, // mandatory on every spend flow: it owns any change
|
|
167
176
|
cachedMerkleTree: deposited.merkleTree,
|
|
168
177
|
});
|
|
169
178
|
|
|
@@ -357,6 +366,7 @@ const result = await transfer(
|
|
|
357
366
|
depositorKeypair: signer,
|
|
358
367
|
walletPublicKey: signer.address,
|
|
359
368
|
chainNoteViewingKeyNk: myNk,
|
|
369
|
+
ownerUtxoKeypair: myUtxoKeypair, // owns the change; never inherited from the inputs
|
|
360
370
|
// The recipient's X25519 viewing public key. With it the recipient can discover the note
|
|
361
371
|
// from chain with their own key (scanRecipientDeliveryNotes). Without it the note is still
|
|
362
372
|
// valid but must be handed over out of band.
|
|
@@ -366,9 +376,13 @@ const result = await transfer(
|
|
|
366
376
|
);
|
|
367
377
|
```
|
|
368
378
|
|
|
369
|
-
`transfer` builds the recipient note as output 0 and returns the change (owned by
|
|
370
|
-
|
|
371
|
-
|
|
379
|
+
`transfer` builds the recipient note as output 0 and returns the change (owned by
|
|
380
|
+
`ownerUtxoKeypair`) as output 1. The circuit requires a private spend's output 1 to be owned by
|
|
381
|
+
input 0's key, so `transfer` puts a note owned by `ownerUtxoKeypair` first; when none of the inputs
|
|
382
|
+
is (notes built by an older SDK), it first moves them into one note owned by `ownerUtxoKeypair` with
|
|
383
|
+
a separate self-spend, then sends from that note. Calling `transact` directly with
|
|
384
|
+
`externalAmount: 0n` is the low-level form; keep the recipient note at `outputUtxos[0]`, which is
|
|
385
|
+
the one the delivery carrier is built for.
|
|
372
386
|
The recipient shares two values with the sender: their UTXO public key (`UtxoKeypair.publicKey`)
|
|
373
387
|
and their viewing public key (`deriveViewingKeyFromNk(nk).publicKey`).
|
|
374
388
|
|
|
@@ -377,6 +391,7 @@ and their viewing public key (`deriveViewingKeyFromNk(nk).publicKey`).
|
|
|
377
391
|
```ts
|
|
378
392
|
await fullWithdraw([note], recipientWallet, options); // whole note
|
|
379
393
|
await partialWithdraw([note], recipientWallet, amount, options); // amount out, change stays shielded
|
|
394
|
+
// options: SpendOptions, i.e. TransactOptions with the mandatory `ownerUtxoKeypair`
|
|
380
395
|
```
|
|
381
396
|
|
|
382
397
|
For SPL pools the recipient receives tokens in their associated token account. The program charges
|
|
@@ -388,10 +403,15 @@ Same API with the pool mint on every note:
|
|
|
388
403
|
|
|
389
404
|
```ts
|
|
390
405
|
const usdc = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
391
|
-
const { utxo, noteSalt } = await createRecoverableDepositUtxo(
|
|
406
|
+
const { utxo, noteSalt } = await createRecoverableDepositUtxo({
|
|
407
|
+
amount: 2_000_000n, // 2.00 USDC
|
|
408
|
+
viewingKeyNk: nk,
|
|
409
|
+
ownerUtxoKeypair: owner,
|
|
410
|
+
mintAddress: usdc,
|
|
411
|
+
});
|
|
392
412
|
await transact(
|
|
393
413
|
{ inputUtxos: [await createZeroUtxo(usdc)], outputUtxos: [utxo], externalAmount: 2_000_000n, depositor: signer.address },
|
|
394
|
-
{ connection, programId: CLOAK_PROGRAM_ID, relayUrl, depositorKeypair: signer, chainNoteViewingKeyNk: nk, chainNoteSalt: noteSalt },
|
|
414
|
+
{ connection, programId: CLOAK_PROGRAM_ID, relayUrl, depositorKeypair: signer, chainNoteViewingKeyNk: nk, chainNoteSalt: noteSalt, ownerUtxoKeypair: owner },
|
|
395
415
|
);
|
|
396
416
|
```
|
|
397
417
|
|
|
@@ -426,13 +446,14 @@ const swap = await swapWithChange(
|
|
|
426
446
|
depositorKeypair: signer,
|
|
427
447
|
walletPublicKey: signer.address,
|
|
428
448
|
chainNoteViewingKeyNk: nk,
|
|
449
|
+
ownerUtxoKeypair: owner, // owns the change and the timeout-refund note
|
|
429
450
|
swapSlippageBps: 100,
|
|
430
451
|
},
|
|
431
452
|
recipientWallet, // required on mainnet: the wallet the swap's risk quote is issued for
|
|
432
453
|
);
|
|
433
454
|
|
|
434
455
|
swap.signature; // the executed swap; swapWithChange resolves only once execution has completed
|
|
435
|
-
swap.refund; //
|
|
456
|
+
swap.refund; // the refund-fallback authorization: { publicKey, blinding, derivedFromNk } (see below)
|
|
436
457
|
```
|
|
437
458
|
|
|
438
459
|
`swapUtxo` is the lower-level form taking `UtxoSwapParams` and an explicit change note. Quote the
|
|
@@ -445,18 +466,20 @@ the proof and cannot be changed after it is generated.
|
|
|
445
466
|
`swapWithChange` polls the swap status and throws if the swap is refunded, cancelled or fails, or if
|
|
446
467
|
polling runs out (`swapStatusMaxAttempts` x `swapStatusDelayMs`, default 60 x 2 s); the result above
|
|
447
468
|
exists only for a completed swap. On a timeout the program returns the principal, net of the swap
|
|
448
|
-
fee, to the SOL pool as a refund note, which is spent through the normal withdraw path.
|
|
449
|
-
|
|
450
|
-
discoverable from the
|
|
469
|
+
fee, to the SOL pool as a refund note, which is spent through the normal withdraw path. The refund
|
|
470
|
+
note is owned by `ownerUtxoKeypair` and its blinding is derived from `nk` and the swap's first
|
|
471
|
+
input nullifier, so it is discoverable from the wallet's keys:
|
|
451
472
|
|
|
452
473
|
```ts
|
|
453
474
|
import { discoverSwapRefunds, fullWithdraw, NATIVE_SOL_MINT, type Utxo } from "@cloak.dev/sdk";
|
|
454
475
|
|
|
455
|
-
const refunds = await discoverSwapRefunds(connection, CLOAK_PROGRAM_ID, nk
|
|
476
|
+
const refunds = await discoverSwapRefunds(connection, CLOAK_PROGRAM_ID, nk, {
|
|
477
|
+
ownerUtxoKeypair: owner, // required; pass { privateKey: 0n, publicKey } for a view-only scan
|
|
478
|
+
}); // DiscoveredSwapRefund[]
|
|
456
479
|
for (const refund of refunds) {
|
|
457
480
|
const note: Utxo = {
|
|
458
481
|
amount: refund.amount, // principal net of the swap fee
|
|
459
|
-
keypair: refund.keypair,
|
|
482
|
+
keypair: refund.keypair, // `owner` (or, for a legacyExposed refund, its own key)
|
|
460
483
|
blinding: refund.blinding,
|
|
461
484
|
mintAddress: NATIVE_SOL_MINT,
|
|
462
485
|
commitment: refund.commitment,
|
|
@@ -467,19 +490,31 @@ for (const refund of refunds) {
|
|
|
467
490
|
```
|
|
468
491
|
|
|
469
492
|
Swaps that executed leave no refund note, and an empty result only says that none of the scanned
|
|
470
|
-
leaves derive from
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
493
|
+
leaves derive from these keys. `swap.refund` (hex `publicKey` and `blinding`) is the fast path:
|
|
494
|
+
rebuild the note with the on-chain `SwapState.sol_amount` as the amount,
|
|
495
|
+
`computeSwapRefundCommitment(amount, publicKey, blinding)` as the commitment and `owner` as the
|
|
496
|
+
keypair, then look up the leaf index as in
|
|
497
|
+
[Recovery and discovery](#recovery-and-discovery-viewing-key). `swap.refund` no longer carries a
|
|
498
|
+
private key: the refund is spent with the wallet's own `ownerUtxoKeypair`.
|
|
475
499
|
|
|
476
500
|
## Recovery and discovery (viewing key)
|
|
477
501
|
|
|
478
|
-
The viewing base `nk` is derived from the wallet's
|
|
479
|
-
|
|
480
|
-
opens notes delivered by other people's private sends
|
|
481
|
-
|
|
482
|
-
|
|
502
|
+
The viewing base `nk` is derived from the wallet's long-lived UTXO private key
|
|
503
|
+
(`getNkFromUtxoPrivateKey(privateKey)`). It decrypts the chain notes the SDK attaches to
|
|
504
|
+
transactions, opens notes delivered by other people's private sends, and derives the blindings of
|
|
505
|
+
the wallet's own deposit, change and swap-refund notes so a scan can find them again.
|
|
506
|
+
|
|
507
|
+
**nk is view-only for notes created from 0.2.6 on.** For those it can find and read the wallet's
|
|
508
|
+
notes; it can never spend them or sign for funds. Every note the 0.2.6 SDK creates for the wallet
|
|
509
|
+
is owned by its long-lived UTXO keypair (`ownerUtxoKeypair` /
|
|
510
|
+
`createRecoverableDepositUtxo({ ownerUtxoKeypair })`), and the nullifier needs that keypair's
|
|
511
|
+
private key. Bridge receiving addresses are derived from the UTXO private key, not from nk. Keep the
|
|
512
|
+
spend key and the UTXO private key secret; nk may be shared with an auditor.
|
|
513
|
+
|
|
514
|
+
Notes created before 0.2.6 are different: some have an owner key derived from nk, so nk can spend
|
|
515
|
+
them (they are reported as `legacyExposed`). A pre-0.2.6 note moves under the wallet key only when
|
|
516
|
+
it is spent; nothing in 0.2.6 moves an idle balance. Until such a note is spent, sharing nk also
|
|
517
|
+
shares the ability to spend it.
|
|
483
518
|
|
|
484
519
|
Before a wallet's first transaction the SDK registers `nk` with the relay for compliance scanning:
|
|
485
520
|
it signs a one-time challenge with `signMessage` (wallet) or `depositorKeypair` and submits `nk`
|
|
@@ -494,12 +529,13 @@ const scan = await scanTransactions({
|
|
|
494
529
|
connection,
|
|
495
530
|
programId: CLOAK_PROGRAM_ID,
|
|
496
531
|
viewingKeyNk: nk,
|
|
497
|
-
ownerUtxoPublicKey: owner.publicKey, // authenticates delivered notes
|
|
532
|
+
ownerUtxoPublicKey: owner.publicKey, // matches your own deposits and authenticates delivered notes
|
|
498
533
|
deliveryMints: [NATIVE_SOL_MINT],
|
|
499
534
|
untilSignature: lastScan?.lastSignature, // incremental scans
|
|
500
535
|
});
|
|
501
536
|
|
|
502
|
-
scan.recoveredDepositNotes; // own deposits built with createRecoverableDepositUtxo
|
|
537
|
+
scan.recoveredDepositNotes; // own deposits built with createRecoverableDepositUtxo (keypair.privateKey 0n: use `owner`)
|
|
538
|
+
scan.recoveredChangeNotes; // own withdrawal/swap change (keypair.privateKey 0n: use `owner`)
|
|
503
539
|
scan.deliveredNotes; // notes sent to this wallet (amount + blinding; the keypair is your own)
|
|
504
540
|
scan.transactions; // history rows for compliance reporting
|
|
505
541
|
```
|
|
@@ -507,11 +543,22 @@ scan.transactions; // history rows for compliance reporting
|
|
|
507
543
|
`scanRecipientDeliveryNotes` does the delivery sweep alone, returning `{ notes, rpcCalls }`
|
|
508
544
|
instead of a full scan result. Deposit recovery applies to deposits built with
|
|
509
545
|
`createRecoverableDepositUtxo` (the default in the examples); a deposit built with
|
|
510
|
-
`createUtxo` has a random blinding that is written nowhere and appears as history only.
|
|
546
|
+
`createUtxo` has a random blinding that is written nowhere and appears as history only. Without
|
|
547
|
+
`ownerUtxoPublicKey` the scan can only match notes from an older SDK whose owner key came from nk.
|
|
548
|
+
|
|
549
|
+
Recovered records carry `legacyExposed`. `false` means the note is owned by the wallet's UTXO
|
|
550
|
+
keypair: substitute `owner` for the returned `keypair` (its `privateKey` is `0n`) before spending.
|
|
551
|
+
`true` marks a note built by an SDK before 0.2.6 whose owner key was derived from nk; it comes back
|
|
552
|
+
with a complete keypair and is spendable as is. Such a note moves under the wallet key only when it
|
|
553
|
+
is spent (to yourself, to someone else, or in a withdrawal): with 0.2.6 the change of any spend is
|
|
554
|
+
owned by `ownerUtxoKeypair`. Nothing in 0.2.6 moves an idle balance, so an unspent `legacyExposed`
|
|
555
|
+
note stays spendable by nk until the app spends it. `transfer` spends at most two such notes at a
|
|
556
|
+
time; with more, consolidate them first (send them to yourself two at a time) or withdraw them.
|
|
511
557
|
|
|
512
558
|
A recovered or delivered note needs its leaf index before it can be spent. Look it up by commitment.
|
|
513
|
-
The two record types differ: `RecoveredDepositNoteRecord` carries the
|
|
514
|
-
`
|
|
559
|
+
The two record types differ: `RecoveredDepositNoteRecord` carries a `keypair` (the owner public key
|
|
560
|
+
with `privateKey: 0n` for a current note, so substitute `owner`; complete for a `legacyExposed`
|
|
561
|
+
one), a `bigint` `commitment` and an `Address` `mintAddress`; `DeliveredNote` carries a hex `commitment`,
|
|
515
562
|
a base58 `mint` (set only when the scan was given `ownerUtxoPublicKey`) and no keypair, because the
|
|
516
563
|
keypair is yours.
|
|
517
564
|
|
|
@@ -522,11 +569,11 @@ const entries = await fetchCommitments(relayUrl, { mint: NATIVE_SOL_MINT });
|
|
|
522
569
|
const indexOf = (commitment: bigint) =>
|
|
523
570
|
entries.find((e) => BigInt("0x" + e.commitment.replace(/^0x/, "")) === commitment)?.index;
|
|
524
571
|
|
|
525
|
-
// Own deposit recovered
|
|
572
|
+
// Own deposit recovered by the scan
|
|
526
573
|
const recovered = scan.recoveredDepositNotes[0];
|
|
527
574
|
const ownNote: Utxo = {
|
|
528
575
|
amount: recovered.amount,
|
|
529
|
-
keypair: recovered.keypair,
|
|
576
|
+
keypair: recovered.legacyExposed ? recovered.keypair : owner,
|
|
530
577
|
blinding: recovered.blinding,
|
|
531
578
|
mintAddress: recovered.mintAddress,
|
|
532
579
|
commitment: recovered.commitment,
|
|
@@ -549,9 +596,9 @@ const deliveredNote: Utxo = {
|
|
|
549
596
|
};
|
|
550
597
|
```
|
|
551
598
|
|
|
552
|
-
`discoverSwapRefunds(connection, programId, nk)` returns `DiscoveredSwapRefund`
|
|
553
|
-
`blinding`, `amount`, `commitment`, `leafIndex: bigint`); build
|
|
554
|
-
[Timed-out swaps](#timed-out-swaps).
|
|
599
|
+
`discoverSwapRefunds(connection, programId, nk, { ownerUtxoKeypair })` returns `DiscoveredSwapRefund`
|
|
600
|
+
records (`keypair`, `blinding`, `amount`, `commitment`, `leafIndex: bigint`, `legacyExposed`); build
|
|
601
|
+
the `Utxo` from one as shown under [Timed-out swaps](#timed-out-swaps).
|
|
555
602
|
|
|
556
603
|
`toComplianceReport(scan)` and `formatComplianceCsv(report)` turn a scan into a report.
|
|
557
604
|
|
|
@@ -660,9 +707,11 @@ relay endpoint and the localhost-RPC check.
|
|
|
660
707
|
[Migrating from @solana/web3.js](#migrating-from-solanaweb3js).
|
|
661
708
|
- 0.2.6 adds one optional field, `affiliate_code`, to the relay request schema, used only by
|
|
662
709
|
Cloak's own apps. It is signed only when present, so a request without it is byte-identical to
|
|
663
|
-
0.2.5
|
|
664
|
-
|
|
665
|
-
|
|
710
|
+
0.2.5 on the wire. Requests that carry it require a relay version that accepts `affiliate_code`
|
|
711
|
+
in the signed request view (the relay's affiliate-program release, REL-010/REL-011); an older
|
|
712
|
+
relay answers them with 401. 0.2.6 also makes nk view-only for notes created from 0.2.6 on, which
|
|
713
|
+
changes several public signatures (`ownerUtxoKeypair` is now required by every spend flow); the
|
|
714
|
+
full list is in [CHANGELOG.md](CHANGELOG.md).
|
|
666
715
|
- Proofs generated with the 0.1.x circuits are rejected by the mainnet program. SDK 0.1.x builds
|
|
667
716
|
(which ship the 0.1.0 bundle) are not usable against it; upgrade to 0.2.x.
|
|
668
717
|
- The note-based `CloakSDK` class is removed in 0.2.0. It targeted the pre-0.2.0 instruction layout
|