@cloak.dev/sdk 0.2.0 → 0.2.2-staging.0f03668
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/LICENSE +202 -0
- package/README.md +201 -57
- package/dist/{chunk-YX5SCAMR.js → chunk-KNM6K5NG.js} +8 -95
- package/dist/index.cjs +3565 -4351
- package/dist/index.d.cts +732 -807
- package/dist/index.d.ts +732 -807
- package/dist/index.js +3452 -4182
- package/dist/{utxo-PFJT3ETR.js → utxo-XPEGGWZ6.js} +3 -3
- package/package.json +50 -20
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/notes/utxo.ts
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
3
|
import { buildPoseidon as buildPoseidon2 } from "circomlibjs";
|
|
4
4
|
import { blake3 } from "@noble/hashes/blake3";
|
|
5
5
|
|
|
6
|
-
// src/
|
|
6
|
+
// src/proving/inputs.ts
|
|
7
7
|
import { buildPoseidon } from "circomlibjs";
|
|
8
8
|
|
|
9
|
-
// src/
|
|
9
|
+
// src/shared/types.ts
|
|
10
10
|
var CloakError = class extends Error {
|
|
11
11
|
constructor(message, category, retryable = false, originalError) {
|
|
12
12
|
super(message);
|
|
@@ -17,7 +17,7 @@ var CloakError = class extends Error {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
// src/
|
|
20
|
+
// src/proving/inputs.ts
|
|
21
21
|
var poseidon = null;
|
|
22
22
|
async function getPoseidon() {
|
|
23
23
|
if (!poseidon) {
|
|
@@ -68,67 +68,6 @@ async function generateCommitmentAsync(amountLamports, r, skSpend) {
|
|
|
68
68
|
const skValue = hexToBigint(bytesToHex(skSpend));
|
|
69
69
|
return await computeCommitment(amount, rValue, skValue);
|
|
70
70
|
}
|
|
71
|
-
function generateCommitment(_amountLamports, _r, _skSpend) {
|
|
72
|
-
throw new Error("generateCommitment is deprecated. Use generateCommitmentAsync instead.");
|
|
73
|
-
}
|
|
74
|
-
async function computeNullifier(sk_spend, leafIndex) {
|
|
75
|
-
const [sk0, sk1] = splitTo2Limbs(sk_spend);
|
|
76
|
-
return await poseidonHash([sk0, sk1, leafIndex]);
|
|
77
|
-
}
|
|
78
|
-
async function computeNullifierAsync(skSpend, leafIndex) {
|
|
79
|
-
const skValue = typeof skSpend === "string" ? hexToBigint(skSpend) : hexToBigint(bytesToHex(skSpend));
|
|
80
|
-
return await computeNullifier(skValue, BigInt(leafIndex));
|
|
81
|
-
}
|
|
82
|
-
function computeNullifierSync(_skSpend, _leafIndex) {
|
|
83
|
-
throw new Error("computeNullifierSync is deprecated. Use computeNullifierAsync instead.");
|
|
84
|
-
}
|
|
85
|
-
async function computeOutputsHashAsync(outputs) {
|
|
86
|
-
let hash = 0n;
|
|
87
|
-
for (const output of outputs) {
|
|
88
|
-
const [lo, hi] = pubkeyToLimbs(output.recipient);
|
|
89
|
-
hash = await poseidonHash([hash, lo, hi, BigInt(output.amount)]);
|
|
90
|
-
}
|
|
91
|
-
return hash;
|
|
92
|
-
}
|
|
93
|
-
async function computeOutputsHash(outAddr, outAmount, outFlags) {
|
|
94
|
-
let hash = 0n;
|
|
95
|
-
for (let i = 0; i < 5; i++) {
|
|
96
|
-
if (outFlags[i] === 1) {
|
|
97
|
-
hash = await poseidonHash([hash, outAddr[i][0], outAddr[i][1], outAmount[i]]);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return hash;
|
|
101
|
-
}
|
|
102
|
-
function computeOutputsHashSync(_outputs) {
|
|
103
|
-
throw new Error("computeOutputsHashSync is deprecated. Use computeOutputsHashAsync instead.");
|
|
104
|
-
}
|
|
105
|
-
async function computeSwapOutputsHash(inputMintLimbs, outputMintLimbs, recipientAtaLimbs, minOutputAmount, publicAmount) {
|
|
106
|
-
return await poseidonHash([
|
|
107
|
-
inputMintLimbs[0],
|
|
108
|
-
inputMintLimbs[1],
|
|
109
|
-
outputMintLimbs[0],
|
|
110
|
-
outputMintLimbs[1],
|
|
111
|
-
recipientAtaLimbs[0],
|
|
112
|
-
recipientAtaLimbs[1],
|
|
113
|
-
minOutputAmount,
|
|
114
|
-
publicAmount
|
|
115
|
-
]);
|
|
116
|
-
}
|
|
117
|
-
async function computeSwapOutputsHashAsync(inputMint, outputMint, recipientAta, minOutputAmount, amount) {
|
|
118
|
-
const inputMintLimbs = pubkeyToLimbs(inputMint);
|
|
119
|
-
const outputMintLimbs = pubkeyToLimbs(outputMint);
|
|
120
|
-
const recipientAtaLimbs = pubkeyToLimbs(recipientAta);
|
|
121
|
-
return await computeSwapOutputsHash(
|
|
122
|
-
inputMintLimbs,
|
|
123
|
-
outputMintLimbs,
|
|
124
|
-
recipientAtaLimbs,
|
|
125
|
-
BigInt(minOutputAmount),
|
|
126
|
-
BigInt(amount)
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
function computeSwapOutputsHashSync(_outputMint, _recipientAta, _minOutputAmount, _amount) {
|
|
130
|
-
throw new Error("computeSwapOutputsHashSync is deprecated. Use computeSwapOutputsHashAsync instead.");
|
|
131
|
-
}
|
|
132
71
|
function bigintToBytes32(n) {
|
|
133
72
|
const hex = n.toString(16).padStart(64, "0");
|
|
134
73
|
const bytes = new Uint8Array(32);
|
|
@@ -301,22 +240,8 @@ function convertEndianness64(bytes) {
|
|
|
301
240
|
}
|
|
302
241
|
return result;
|
|
303
242
|
}
|
|
304
|
-
function buildPublicInputsBytes(root, nullifier, outputsHash, publicAmount) {
|
|
305
|
-
const result = new Uint8Array(104);
|
|
306
|
-
result.set(bigintToBytes32(root), 0);
|
|
307
|
-
result.set(bigintToBytes32(nullifier), 32);
|
|
308
|
-
result.set(bigintToBytes32(outputsHash), 64);
|
|
309
|
-
const amountBytes = new Uint8Array(8);
|
|
310
|
-
let amt = publicAmount;
|
|
311
|
-
for (let i = 7; i >= 0; i--) {
|
|
312
|
-
amountBytes[i] = Number(amt & 0xffn);
|
|
313
|
-
amt = amt >> 8n;
|
|
314
|
-
}
|
|
315
|
-
result.set(amountBytes, 96);
|
|
316
|
-
return result;
|
|
317
|
-
}
|
|
318
243
|
|
|
319
|
-
// src/
|
|
244
|
+
// src/notes/utxo.ts
|
|
320
245
|
var FIELD_MODULUS = BigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
|
|
321
246
|
var KEYPAIR_DOMAIN_TAG = BigInt("5423839527465210463");
|
|
322
247
|
var UTXO_KEY_DOMAIN = new TextEncoder().encode("cloak_utxo_priv_v1");
|
|
@@ -427,7 +352,7 @@ async function computeSignature(privateKey, commitment, pathIndex) {
|
|
|
427
352
|
const hash = poseidon2([privateKey, commitment, pathIndex]);
|
|
428
353
|
return poseidon2.F.toObject(hash);
|
|
429
354
|
}
|
|
430
|
-
async function
|
|
355
|
+
async function computeNullifier(utxo) {
|
|
431
356
|
if (utxo.index === void 0) {
|
|
432
357
|
throw new Error("UTXO must have an index to compute nullifier");
|
|
433
358
|
}
|
|
@@ -550,18 +475,7 @@ export {
|
|
|
550
475
|
pubkeyToLimbs,
|
|
551
476
|
computeMerkleRoot,
|
|
552
477
|
hexToBigint,
|
|
553
|
-
computeCommitment,
|
|
554
478
|
generateCommitmentAsync,
|
|
555
|
-
generateCommitment,
|
|
556
|
-
computeNullifier,
|
|
557
|
-
computeNullifierAsync,
|
|
558
|
-
computeNullifierSync,
|
|
559
|
-
computeOutputsHashAsync,
|
|
560
|
-
computeOutputsHash,
|
|
561
|
-
computeOutputsHashSync,
|
|
562
|
-
computeSwapOutputsHash,
|
|
563
|
-
computeSwapOutputsHashAsync,
|
|
564
|
-
computeSwapOutputsHashSync,
|
|
565
479
|
bigintToBytes32,
|
|
566
480
|
hexToBytes,
|
|
567
481
|
bytesToHex,
|
|
@@ -570,7 +484,6 @@ export {
|
|
|
570
484
|
isValidHex,
|
|
571
485
|
BN254_MODULUS,
|
|
572
486
|
proofToBytes,
|
|
573
|
-
buildPublicInputsBytes,
|
|
574
487
|
NATIVE_SOL_MINT,
|
|
575
488
|
randomFieldElement,
|
|
576
489
|
generateUtxoKeypair,
|
|
@@ -580,9 +493,9 @@ export {
|
|
|
580
493
|
createZeroUtxo,
|
|
581
494
|
pubkeyToFieldElement,
|
|
582
495
|
pubkeyToFieldLimbs,
|
|
583
|
-
computeCommitment2,
|
|
496
|
+
computeCommitment2 as computeCommitment,
|
|
584
497
|
computeSignature,
|
|
585
|
-
|
|
498
|
+
computeNullifier,
|
|
586
499
|
serializeUtxo,
|
|
587
500
|
deserializeUtxo,
|
|
588
501
|
bigintToHex,
|