@cloak.dev/sdk 0.2.4-staging.d6e0e6c → 0.2.5-staging.4b3a899
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/README.md +82 -31
- package/dist/{chunk-KNM6K5NG.js → chunk-GM3WEXYP.js} +48 -7
- package/dist/index.cjs +1318 -855
- package/dist/index.d.cts +500 -383
- package/dist/index.d.ts +500 -383
- package/dist/index.js +1281 -890
- package/dist/{utxo-XPEGGWZ6.js → utxo-TM7UCHTN.js} +1 -1
- package/package.json +10 -5
package/README.md
CHANGED
|
@@ -5,19 +5,24 @@ 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.5 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.
|
|
15
|
-
# swaps and SPL pools also need:
|
|
16
|
-
npm install @solana/spl-token
|
|
14
|
+
npm install @cloak.dev/sdk@^0.2.5
|
|
17
15
|
```
|
|
18
16
|
|
|
17
|
+
The SDK is built on [`@solana/kit`](https://github.com/anza-xyz/kit) and re-exports the pieces an
|
|
18
|
+
integrator needs (`address`, `createCloakRpc`, `generateKeyPairSigner`, `signerFromSecretKey`,
|
|
19
|
+
`sendInstructions`, …), so `@solana/web3.js` is not required. Token-account derivation for SPL
|
|
20
|
+
pools and swaps uses `@solana-program/token`, which the SDK depends on; import
|
|
21
|
+
`findAssociatedTokenPda` from it directly. Coming from 0.2.4 or earlier (web3.js): see
|
|
22
|
+
[Migrating from @solana/web3.js](#migrating-from-solanaweb3js).
|
|
23
|
+
|
|
19
24
|
Node >= 18. Ships ESM and CJS builds with type declarations. Runs in Node and in the browser
|
|
20
|
-
(wallet
|
|
25
|
+
(wallet signing); the on-chain Merkle-tree rebuild fallback is not available in browsers.
|
|
21
26
|
|
|
22
27
|
## Networks
|
|
23
28
|
|
|
@@ -29,7 +34,7 @@ Node >= 18. Ships ESM and CJS builds with type declarations. Runs in Node and in
|
|
|
29
34
|
| Cloak endpoint | `https://api.cloak.ag` — pinned into the build, not configurable (see below) |
|
|
30
35
|
| Circuits | `https://storage.googleapis.com/cloak-circuits/circuits/0.2.0` (the SDK default) |
|
|
31
36
|
| Pools | WSOL (`NATIVE_SOL_MINT`), USDC `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v`, USDT `Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB` |
|
|
32
|
-
| RPC | any mainnet RPC; use `
|
|
37
|
+
| RPC | any mainnet RPC; use `createCloakRpc(url)` (a `@solana/kit` `Rpc` that remembers its endpoint) |
|
|
33
38
|
|
|
34
39
|
The endpoint is fixed when the SDK is built and cannot be changed by a consumer. A published build
|
|
35
40
|
carries `RELAY_ORIGIN_ALLOWLIST` as a compiled-in constant, every request is checked against it
|
|
@@ -100,8 +105,10 @@ import {
|
|
|
100
105
|
generateUtxoKeypair,
|
|
101
106
|
getNkFromUtxoPrivateKey,
|
|
102
107
|
transact,
|
|
108
|
+
address,
|
|
109
|
+
createCloakRpc,
|
|
110
|
+
signerFromSecretKey,
|
|
103
111
|
} from "@cloak.dev/sdk";
|
|
104
|
-
import { Connection, Keypair, PublicKey } from "@solana/web3.js";
|
|
105
112
|
|
|
106
113
|
async function main() {
|
|
107
114
|
const [recipientArg, lamportsArg] = process.argv.slice(2);
|
|
@@ -116,11 +123,11 @@ async function main() {
|
|
|
116
123
|
throw new Error("Set SOLANA_RPC_URL, CLOAK_RELAY_URL and KEYPAIR_PATH");
|
|
117
124
|
}
|
|
118
125
|
|
|
119
|
-
const connection =
|
|
120
|
-
const signer =
|
|
126
|
+
const connection = createCloakRpc(rpcUrl);
|
|
127
|
+
const signer = await signerFromSecretKey(
|
|
121
128
|
Uint8Array.from(JSON.parse(readFileSync(keypairPath, "utf8"))),
|
|
122
129
|
);
|
|
123
|
-
const recipient =
|
|
130
|
+
const recipient = address(recipientArg);
|
|
124
131
|
const amount = BigInt(lamportsArg);
|
|
125
132
|
|
|
126
133
|
// The wallet's viewing base (nk). A real wallet derives it from its seed; a throwaway
|
|
@@ -136,7 +143,7 @@ async function main() {
|
|
|
136
143
|
inputUtxos: [await createZeroUtxo(NATIVE_SOL_MINT)],
|
|
137
144
|
outputUtxos: [utxo],
|
|
138
145
|
externalAmount: amount,
|
|
139
|
-
depositor: signer.
|
|
146
|
+
depositor: signer.address,
|
|
140
147
|
},
|
|
141
148
|
{
|
|
142
149
|
connection,
|
|
@@ -155,7 +162,7 @@ async function main() {
|
|
|
155
162
|
programId: CLOAK_PROGRAM_ID,
|
|
156
163
|
relayUrl,
|
|
157
164
|
depositorKeypair: signer,
|
|
158
|
-
walletPublicKey: signer.
|
|
165
|
+
walletPublicKey: signer.address,
|
|
159
166
|
chainNoteViewingKeyNk: nk,
|
|
160
167
|
cachedMerkleTree: deposited.merkleTree,
|
|
161
168
|
});
|
|
@@ -188,27 +195,35 @@ Rules for minimal scripts:
|
|
|
188
195
|
- `transact`, `partialWithdraw` and `fullWithdraw` already retry on a stale Merkle root; do not
|
|
189
196
|
wrap them in your own retry loop.
|
|
190
197
|
|
|
191
|
-
### Browser (wallet
|
|
198
|
+
### Browser (wallet)
|
|
192
199
|
|
|
193
|
-
Replace `depositorKeypair` with the
|
|
200
|
+
Replace `depositorKeypair` with a `@solana/kit` `TransactionSigner` for the user's wallet. A
|
|
201
|
+
Wallet Standard app gets one from `@solana/react` (`useWalletAccountTransactionSigner`); an app on
|
|
202
|
+
`@solana/wallet-adapter-*` wraps the adapter with `signerFromWalletAdapter`:
|
|
194
203
|
|
|
195
204
|
```ts
|
|
205
|
+
import { signerFromWalletAdapter } from "@cloak.dev/sdk";
|
|
206
|
+
|
|
207
|
+
const signer = signerFromWalletAdapter(wallet); // wallet: the connected adapter (publicKey + signTransaction [+ signMessage])
|
|
208
|
+
|
|
196
209
|
await transact(params, {
|
|
197
210
|
connection,
|
|
198
211
|
programId: CLOAK_PROGRAM_ID,
|
|
199
212
|
relayUrl,
|
|
200
|
-
|
|
213
|
+
signer, // signs the deposit transaction
|
|
201
214
|
signMessage: (message) => wallet.signMessage(message), // signs the viewing-key registration challenge
|
|
202
|
-
depositorPublicKey:
|
|
203
|
-
walletPublicKey:
|
|
215
|
+
depositorPublicKey: signer.address,
|
|
216
|
+
walletPublicKey: signer.address,
|
|
204
217
|
chainNoteViewingKeyNk: nk,
|
|
205
218
|
chainNoteSalt: noteSalt,
|
|
206
219
|
});
|
|
207
220
|
```
|
|
208
221
|
|
|
209
|
-
`
|
|
210
|
-
|
|
211
|
-
|
|
222
|
+
`signer` is asked to sign legacy and v0 (address-lookup-table) transactions alike; deposits use
|
|
223
|
+
either depending on the path taken. `signerFromWalletAdapter` hands the adapter a web3.js
|
|
224
|
+
`VersionedTransaction`, so an app that uses it must have `@solana/web3.js` installed (it is an
|
|
225
|
+
optional peer dependency of the SDK). `signMessage` is required unless
|
|
226
|
+
`enforceViewingKeyRegistration: false` is set; without it the call fails with
|
|
212
227
|
"Viewing key registration is mandatory: signMessage (wallet) or depositorKeypair is required."
|
|
213
228
|
|
|
214
229
|
A deposit is signed by the wallet and goes straight to chain. A private send, a withdrawal and a
|
|
@@ -225,12 +240,17 @@ await transact(
|
|
|
225
240
|
programId: CLOAK_PROGRAM_ID,
|
|
226
241
|
relayUrl,
|
|
227
242
|
signMessage: (message) => wallet.signMessage(message),
|
|
228
|
-
walletPublicKey:
|
|
243
|
+
walletPublicKey: signer.address, // becomes the authenticated sender
|
|
229
244
|
chainNoteViewingKeyNk: nk,
|
|
230
245
|
},
|
|
231
246
|
);
|
|
232
247
|
```
|
|
233
248
|
|
|
249
|
+
A wallet that cannot sign messages (Ledger, Trezor) passes `signer` instead of `signMessage`: the
|
|
250
|
+
sender then authenticates by signing a 0-lamport no-op self-transfer that carries the request
|
|
251
|
+
digest (`auth_mode: "transaction"`). Give a wallet one of the two; when both are present
|
|
252
|
+
`signMessage` is used.
|
|
253
|
+
|
|
234
254
|
`signMessage` must return the raw 64-byte ed25519 detached signature over the bytes it is given;
|
|
235
255
|
adapters that re-encode or wrap the result are rejected by name. `walletPublicKey` must be the end
|
|
236
256
|
user's own wallet — it is the identity the transaction is authenticated as. Passing neither a
|
|
@@ -335,7 +355,7 @@ const result = await transfer(
|
|
|
335
355
|
programId: CLOAK_PROGRAM_ID,
|
|
336
356
|
relayUrl,
|
|
337
357
|
depositorKeypair: signer,
|
|
338
|
-
walletPublicKey: signer.
|
|
358
|
+
walletPublicKey: signer.address,
|
|
339
359
|
chainNoteViewingKeyNk: myNk,
|
|
340
360
|
// The recipient's X25519 viewing public key. With it the recipient can discover the note
|
|
341
361
|
// from chain with their own key (scanRecipientDeliveryNotes). Without it the note is still
|
|
@@ -367,10 +387,10 @@ its fee on the withdrawn amount ([Fees and limits](#fees-and-limits)).
|
|
|
367
387
|
Same API with the pool mint on every note:
|
|
368
388
|
|
|
369
389
|
```ts
|
|
370
|
-
const usdc =
|
|
390
|
+
const usdc = address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
|
|
371
391
|
const { utxo, noteSalt } = await createRecoverableDepositUtxo(2_000_000n, nk, usdc); // 2.00 USDC
|
|
372
392
|
await transact(
|
|
373
|
-
{ inputUtxos: [await createZeroUtxo(usdc)], outputUtxos: [utxo], externalAmount: 2_000_000n, depositor: signer.
|
|
393
|
+
{ inputUtxos: [await createZeroUtxo(usdc)], outputUtxos: [utxo], externalAmount: 2_000_000n, depositor: signer.address },
|
|
374
394
|
{ connection, programId: CLOAK_PROGRAM_ID, relayUrl, depositorKeypair: signer, chainNoteViewingKeyNk: nk, chainNoteSalt: noteSalt },
|
|
375
395
|
);
|
|
376
396
|
```
|
|
@@ -389,9 +409,9 @@ through Jupiter. Swap input is SOL only (the pool is wSOL-locked).
|
|
|
389
409
|
|
|
390
410
|
```ts
|
|
391
411
|
import { swapWithChange } from "@cloak.dev/sdk";
|
|
392
|
-
import {
|
|
412
|
+
import { findAssociatedTokenPda, TOKEN_PROGRAM_ADDRESS } from "@solana-program/token";
|
|
393
413
|
|
|
394
|
-
const recipientAta =
|
|
414
|
+
const [recipientAta] = await findAssociatedTokenPda({ mint: usdc, owner: recipientWallet, tokenProgram: TOKEN_PROGRAM_ADDRESS });
|
|
395
415
|
|
|
396
416
|
const swap = await swapWithChange(
|
|
397
417
|
[solNote],
|
|
@@ -404,7 +424,7 @@ const swap = await swapWithChange(
|
|
|
404
424
|
programId: CLOAK_PROGRAM_ID,
|
|
405
425
|
relayUrl,
|
|
406
426
|
depositorKeypair: signer,
|
|
407
|
-
walletPublicKey: signer.
|
|
427
|
+
walletPublicKey: signer.address,
|
|
408
428
|
chainNoteViewingKeyNk: nk,
|
|
409
429
|
swapSlippageBps: 100,
|
|
410
430
|
},
|
|
@@ -491,12 +511,12 @@ instead of a full scan result. Deposit recovery applies to deposits built with
|
|
|
491
511
|
|
|
492
512
|
A recovered or delivered note needs its leaf index before it can be spent. Look it up by commitment.
|
|
493
513
|
The two record types differ: `RecoveredDepositNoteRecord` carries the note's own `keypair`, a
|
|
494
|
-
`bigint` `commitment` and
|
|
514
|
+
`bigint` `commitment` and an `Address` `mintAddress`; `DeliveredNote` carries a hex `commitment`,
|
|
495
515
|
a base58 `mint` (set only when the scan was given `ownerUtxoPublicKey`) and no keypair, because the
|
|
496
516
|
keypair is yours.
|
|
497
517
|
|
|
498
518
|
```ts
|
|
499
|
-
import {
|
|
519
|
+
import { address } from "@cloak.dev/sdk";
|
|
500
520
|
|
|
501
521
|
const entries = await fetchCommitments(relayUrl, { mint: NATIVE_SOL_MINT });
|
|
502
522
|
const indexOf = (commitment: bigint) =>
|
|
@@ -523,7 +543,7 @@ const deliveredNote: Utxo = {
|
|
|
523
543
|
amount: delivered.amount,
|
|
524
544
|
keypair: owner, // the UtxoKeypair whose publicKey the sender used
|
|
525
545
|
blinding: delivered.blinding,
|
|
526
|
-
mintAddress:
|
|
546
|
+
mintAddress: address(delivered.mint),
|
|
527
547
|
commitment: deliveredCommitment,
|
|
528
548
|
index: indexOf(deliveredCommitment),
|
|
529
549
|
};
|
|
@@ -627,19 +647,50 @@ relay endpoint and the localhost-RPC check.
|
|
|
627
647
|
|
|
628
648
|
## Version and compatibility
|
|
629
649
|
|
|
630
|
-
- SDK 0.2.
|
|
650
|
+
- SDK 0.2.5 pairs with the mainnet program at `zh1eLd6rSphLejbFfJEneUwzHRfMKxgzrgkfwA6qRkW`
|
|
631
651
|
(deployed 2026-08-24) and the 0.2.0 circuit bundle — the program and circuit bundle are unchanged
|
|
632
652
|
since 0.2.0; only the SDK package version has moved. All flows in this README were exercised on
|
|
633
653
|
mainnet on 2026-08-25: deposit, private send and withdraw on SOL, USDC and USDT; swaps SOL to
|
|
634
654
|
USDC and USDT; viewing-key discovery followed by a spend; keypair-only deposit recovery.
|
|
635
655
|
- 0.2.2 adds the opt-in `TransactOptions.relaySupplementalAlt` (see [SPL pools](#spl-pools-usdc-usdt)):
|
|
636
656
|
off by default, and existing behavior is unchanged when it is left unset.
|
|
657
|
+
- 0.2.5 moves the SDK from `@solana/web3.js` to `@solana/kit`. The program, the circuit bundle,
|
|
658
|
+
the relay protocol and every hash the SDK computes are unchanged; what changes is the shape of
|
|
659
|
+
the Solana values at the API boundary, listed under
|
|
660
|
+
[Migrating from @solana/web3.js](#migrating-from-solanaweb3js).
|
|
637
661
|
- Proofs generated with the 0.1.x circuits are rejected by the mainnet program. SDK 0.1.x builds
|
|
638
662
|
(which ship the 0.1.0 bundle) are not usable against it; upgrade to 0.2.x.
|
|
639
663
|
- The note-based `CloakSDK` class is removed in 0.2.0. It targeted the pre-0.2.0 instruction layout
|
|
640
664
|
and the unpublished 0.1.0 `withdraw_*` circuits, so it could not work against the current program.
|
|
641
665
|
Use the UTXO API above: `transact`, `transfer`, `partialWithdraw`, `fullWithdraw`, `swapUtxo`.
|
|
642
666
|
|
|
667
|
+
## Migrating from @solana/web3.js
|
|
668
|
+
|
|
669
|
+
0.2.5 is built on `@solana/kit`. The flows, options and hashes are the same; the Solana values
|
|
670
|
+
that cross the API boundary change type:
|
|
671
|
+
|
|
672
|
+
| 0.2.4 and earlier (web3.js) | 0.2.5 (kit) |
|
|
673
|
+
| --- | --- |
|
|
674
|
+
| `new Connection(url, "confirmed")` | `createCloakRpc(url)` (`CloakRpc`; commitment is per call, default `confirmed`) |
|
|
675
|
+
| `PublicKey` everywhere (`programId`, `mintAddress`, `recipient`, `depositor`, `walletPublicKey`, `relayer`, `expectedMint`, `riskOracleQueue`) | `Address` (a branded base58 string): `address("...")`; compare with `===`, bytes with `addressBytes(a)` |
|
|
676
|
+
| `Keypair` as `depositorKeypair` | `KeyPairSigner`: `await signerFromSecretKey(secretKey)` or `await generateKeyPairSigner()`; `signer.address` replaces `.publicKey` |
|
|
677
|
+
| `signTransaction: (tx) => wallet.signTransaction(tx)` | `signer: TransactionSigner` (Wallet Standard signer, or `signerFromWalletAdapter(adapter)`) |
|
|
678
|
+
| `signAuthTransaction` (message-less wallets) | gone; the same `signer` authenticates relay requests when `signMessage` is absent |
|
|
679
|
+
| `getShieldPoolPDAs(...)` and the other PDA helpers (sync) | `await getShieldPoolPDAs(...)` (all PDA helpers are async) |
|
|
680
|
+
| `addressLookupTableAccounts: AddressLookupTableAccount[]` | `LookupTable[]` (`{ address, addresses }`), or `fetchLookupTables(rpc, addresses)` |
|
|
681
|
+
| `getRiskQuoteInstruction: (wallet: PublicKey) => Promise<TransactionInstruction>` | `(wallet: Address) => Promise<Instruction>` (kit instruction: `programAddress`, `accounts`, `data`) |
|
|
682
|
+
| `getAssociatedTokenAddressSync(mint, owner)` from `@solana/spl-token` | `findAssociatedTokenPda({ mint, owner, tokenProgram: TOKEN_PROGRAM_ADDRESS })` from `@solana-program/token` |
|
|
683
|
+
| `RelayAuthSigner = { walletPublicKey, signMessage } \| { walletPublicKey, signAuthTransaction }` | `MessageSigner \| TransactionSigner`; build a message signer with `messageSignerFromCallback(address, signMessage)` |
|
|
684
|
+
| `WalletAdapter`, `keypairToAdapter`, `signTransaction` exports | removed; `WalletSigner` is `TransactionSigner`, `sendTransaction(signedTx, rpc)` sends a kit transaction |
|
|
685
|
+
|
|
686
|
+
Everything else (`transact`, `transfer`, `partialWithdraw`, `fullWithdraw`, `swapUtxo`,
|
|
687
|
+
`swapWithChange`, `transactBatch`, the scanners, notes, viewing keys, fees, errors) keeps its
|
|
688
|
+
signature. The SDK re-exports the kit helpers it uses (`address`, `addressBytes`,
|
|
689
|
+
`findProgramAddress`, `createCloakRpc`, `fetchAccountBytes`, `signerFromSecretKey`,
|
|
690
|
+
`generateKeyPairSigner`, `signMessageBytes`, `buildTransactionMessage`, `signTransaction`,
|
|
691
|
+
`sendInstructions`, …) so a script needs no other Solana dependency; anything beyond that comes from
|
|
692
|
+
`@solana/kit` and the `@solana-program/*` packages directly.
|
|
693
|
+
|
|
643
694
|
## Examples
|
|
644
695
|
|
|
645
696
|
```bash
|
|
@@ -1,5 +1,34 @@
|
|
|
1
|
+
// src/solana/address.ts
|
|
2
|
+
import {
|
|
3
|
+
address,
|
|
4
|
+
assertIsAddress,
|
|
5
|
+
getAddressDecoder,
|
|
6
|
+
getAddressEncoder,
|
|
7
|
+
isAddress
|
|
8
|
+
} from "@solana/kit";
|
|
9
|
+
import { SYSTEM_PROGRAM_ADDRESS } from "@solana-program/system";
|
|
10
|
+
var ADDRESS_ENCODER = getAddressEncoder();
|
|
11
|
+
var ADDRESS_DECODER = getAddressDecoder();
|
|
12
|
+
function addressBytes(value) {
|
|
13
|
+
return new Uint8Array(ADDRESS_ENCODER.encode(address(value)));
|
|
14
|
+
}
|
|
15
|
+
function addressFromBytes(bytes) {
|
|
16
|
+
const u8 = bytes instanceof Uint8Array ? bytes : Uint8Array.from(bytes);
|
|
17
|
+
if (u8.length !== 32) throw new Error(`An address is 32 bytes, got ${u8.length}`);
|
|
18
|
+
return ADDRESS_DECODER.decode(u8);
|
|
19
|
+
}
|
|
20
|
+
function toAddress(value) {
|
|
21
|
+
if (typeof value === "string") return address(value);
|
|
22
|
+
return address(value.toBase58());
|
|
23
|
+
}
|
|
24
|
+
var DEFAULT_ADDRESS = address("11111111111111111111111111111111");
|
|
25
|
+
var SYSVAR_INSTRUCTIONS_ADDRESS = address("Sysvar1nstructions1111111111111111111111111");
|
|
26
|
+
var SYSVAR_SLOT_HASHES_ADDRESS = address("SysvarS1otHashes111111111111111111111111111");
|
|
27
|
+
var SYSVAR_RENT_ADDRESS = address("SysvarRent111111111111111111111111111111111");
|
|
28
|
+
var SYSVAR_CLOCK_ADDRESS = address("SysvarC1ock11111111111111111111111111111111");
|
|
29
|
+
var ED25519_PROGRAM_ADDRESS = address("Ed25519SigVerify111111111111111111111111111");
|
|
30
|
+
|
|
1
31
|
// src/notes/utxo.ts
|
|
2
|
-
import { PublicKey } from "@solana/web3.js";
|
|
3
32
|
import { buildPoseidon as buildPoseidon2 } from "circomlibjs";
|
|
4
33
|
import { blake3 } from "@noble/hashes/blake3";
|
|
5
34
|
|
|
@@ -37,7 +66,9 @@ function splitTo2Limbs(value) {
|
|
|
37
66
|
return [lo, hi];
|
|
38
67
|
}
|
|
39
68
|
function pubkeyToLimbs(pubkey) {
|
|
40
|
-
const bytes = typeof pubkey
|
|
69
|
+
const bytes = typeof pubkey === "string" ? isAddress(pubkey) ? addressBytes(pubkey) : (() => {
|
|
70
|
+
throw new Error(`Invalid address: ${pubkey}`);
|
|
71
|
+
})() : typeof pubkey.toBytes === "function" ? pubkey.toBytes() : pubkey;
|
|
41
72
|
const value = BigInt("0x" + Buffer.from(bytes).toString("hex"));
|
|
42
73
|
return splitTo2Limbs(value);
|
|
43
74
|
}
|
|
@@ -245,7 +276,7 @@ function convertEndianness64(bytes) {
|
|
|
245
276
|
var FIELD_MODULUS = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
|
246
277
|
var KEYPAIR_DOMAIN_TAG = BigInt("5423839527465210463");
|
|
247
278
|
var UTXO_KEY_DOMAIN = new TextEncoder().encode("cloak_utxo_priv_v1");
|
|
248
|
-
var NATIVE_SOL_MINT =
|
|
279
|
+
var NATIVE_SOL_MINT = address("So11111111111111111111111111111111111111112");
|
|
249
280
|
var poseidonInstance = null;
|
|
250
281
|
async function getPoseidon2() {
|
|
251
282
|
if (!poseidonInstance) {
|
|
@@ -317,7 +348,7 @@ async function createZeroUtxo(mintAddress = NATIVE_SOL_MINT, salt) {
|
|
|
317
348
|
return utxo;
|
|
318
349
|
}
|
|
319
350
|
function pubkeyToFieldElement(pubkey) {
|
|
320
|
-
const bytes = pubkey
|
|
351
|
+
const bytes = addressBytes(pubkey);
|
|
321
352
|
let value = BigInt(0);
|
|
322
353
|
for (let i = 0; i < 32; i++) {
|
|
323
354
|
value = value << BigInt(8) | BigInt(bytes[i]);
|
|
@@ -325,7 +356,7 @@ function pubkeyToFieldElement(pubkey) {
|
|
|
325
356
|
return value % FIELD_MODULUS;
|
|
326
357
|
}
|
|
327
358
|
function pubkeyToFieldLimbs(pubkey) {
|
|
328
|
-
const bytes = pubkey
|
|
359
|
+
const bytes = addressBytes(pubkey);
|
|
329
360
|
let hi = BigInt(0);
|
|
330
361
|
let lo = BigInt(0);
|
|
331
362
|
for (let i = 0; i < 16; i++) {
|
|
@@ -382,7 +413,7 @@ function serializeUtxo(utxo) {
|
|
|
382
413
|
for (let i = 0; i < 32; i++) {
|
|
383
414
|
view.setUint8(40 + i, blindingBytes[i]);
|
|
384
415
|
}
|
|
385
|
-
const mintBytes = utxo.mintAddress
|
|
416
|
+
const mintBytes = addressBytes(utxo.mintAddress);
|
|
386
417
|
for (let i = 0; i < 32; i++) {
|
|
387
418
|
view.setUint8(72 + i, mintBytes[i]);
|
|
388
419
|
}
|
|
@@ -399,7 +430,7 @@ async function deserializeUtxo(bytes) {
|
|
|
399
430
|
const blindingBytes = bytes.slice(40, 72);
|
|
400
431
|
const blinding = bytesToBigint(blindingBytes);
|
|
401
432
|
const mintBytes = bytes.slice(72, 104);
|
|
402
|
-
const mintAddress =
|
|
433
|
+
const mintAddress = addressFromBytes(mintBytes);
|
|
403
434
|
const index = view.getUint32(104, true);
|
|
404
435
|
const utxo = {
|
|
405
436
|
amount,
|
|
@@ -469,6 +500,16 @@ function selectUtxos(available, targetAmount) {
|
|
|
469
500
|
}
|
|
470
501
|
|
|
471
502
|
export {
|
|
503
|
+
address,
|
|
504
|
+
isAddress,
|
|
505
|
+
SYSTEM_PROGRAM_ADDRESS,
|
|
506
|
+
addressBytes,
|
|
507
|
+
addressFromBytes,
|
|
508
|
+
toAddress,
|
|
509
|
+
DEFAULT_ADDRESS,
|
|
510
|
+
SYSVAR_INSTRUCTIONS_ADDRESS,
|
|
511
|
+
SYSVAR_SLOT_HASHES_ADDRESS,
|
|
512
|
+
ED25519_PROGRAM_ADDRESS,
|
|
472
513
|
CloakError,
|
|
473
514
|
poseidonHash,
|
|
474
515
|
splitTo2Limbs,
|