@auditable/privacy-pool-zk-sdk 0.7.0 → 0.8.0

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.
@@ -36,35 +36,69 @@ export function buildWithdrawMerkleWitness(coin_json, state_json) {
36
36
  }
37
37
 
38
38
  /**
39
- * Calculate nullifier hash from nullifier decimal string.
39
+ * Calculate owner-bound nullifier hash from nullifier and spend-scalar decimal strings.
40
40
  * Returns hex string (0x...)
41
41
  * @param {string} nullifier_decimal
42
+ * @param {string} priv_key_scalar_decimal
42
43
  * @returns {string}
43
44
  */
44
- export function calculateNullifierHash(nullifier_decimal) {
45
- let deferred3_0;
46
- let deferred3_1;
45
+ export function calculateNullifierHash(nullifier_decimal, priv_key_scalar_decimal) {
46
+ let deferred4_0;
47
+ let deferred4_1;
47
48
  try {
48
49
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
49
50
  const ptr0 = passStringToWasm0(nullifier_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
50
51
  const len0 = WASM_VECTOR_LEN;
51
- wasm.calculateNullifierHash(retptr, ptr0, len0);
52
+ const ptr1 = passStringToWasm0(priv_key_scalar_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
53
+ const len1 = WASM_VECTOR_LEN;
54
+ wasm.calculateNullifierHash(retptr, ptr0, len0, ptr1, len1);
52
55
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
53
56
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
54
57
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
55
58
  var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
56
- var ptr2 = r0;
57
- var len2 = r1;
59
+ var ptr3 = r0;
60
+ var len3 = r1;
58
61
  if (r3) {
59
- ptr2 = 0; len2 = 0;
62
+ ptr3 = 0; len3 = 0;
60
63
  throw takeObject(r2);
61
64
  }
62
- deferred3_0 = ptr2;
63
- deferred3_1 = len2;
64
- return getStringFromWasm0(ptr2, len2);
65
+ deferred4_0 = ptr3;
66
+ deferred4_1 = len3;
67
+ return getStringFromWasm0(ptr3, len3);
68
+ } finally {
69
+ wasm.__wbindgen_add_to_stack_pointer(16);
70
+ wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
71
+ }
72
+ }
73
+
74
+ /**
75
+ * `R = Poseidon255(2)(hi, lo)`; `scalar` is the raw Poseidon hash when it is
76
+ * already in `(0, BabyJub subgroup order)`. Out-of-range hashes fail so the
77
+ * caller can rejection-sample a new nonce.
78
+ * @param {string} nonce_decimal
79
+ * @param {string} recipient_hi_decimal
80
+ * @param {string} recipient_lo_decimal
81
+ * @returns {any}
82
+ */
83
+ export function derivedEscrowKey(nonce_decimal, recipient_hi_decimal, recipient_lo_decimal) {
84
+ try {
85
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
86
+ const ptr0 = passStringToWasm0(nonce_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
87
+ const len0 = WASM_VECTOR_LEN;
88
+ const ptr1 = passStringToWasm0(recipient_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
89
+ const len1 = WASM_VECTOR_LEN;
90
+ const ptr2 = passStringToWasm0(recipient_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
91
+ const len2 = WASM_VECTOR_LEN;
92
+ wasm.derivedEscrowKey(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
93
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
94
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
95
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
96
+ if (r2) {
97
+ throw takeObject(r1);
98
+ }
99
+ return takeObject(r0);
65
100
  } finally {
66
101
  wasm.__wbindgen_add_to_stack_pointer(16);
67
- wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
68
102
  }
69
103
  }
70
104
 
@@ -145,26 +179,28 @@ export function ecdhSharedKey(priv_hex, pub_x_hex, pub_y_hex) {
145
179
  }
146
180
 
147
181
  /**
148
- * Generate a new coin with random nullifier, secret, and shared-secret field elements.
149
- * `amount` is stroops (u64); JS passes `bigint`.
182
+ * Generate a new coin with random nullifier, secret, and owner public-key field elements.
183
+ * `amount_decimal` is an arbitrary-precision decimal field element (never JS `number`).
150
184
  * `asset_hi_decimal` / `asset_lo_decimal` are decimal Fr strings for the Stellar asset contract id (two limbs).
151
185
  * Returns JSON: { coin: { value, nullifier, secret, commitment, asset_hi, asset_lo }, commitment_hex, precommitement_hex }
152
- * @param {bigint} amount
186
+ * @param {string} amount_decimal
153
187
  * @param {string} asset_hi_decimal
154
188
  * @param {string} asset_lo_decimal
155
189
  * @param {string} application_id_decimal
156
190
  * @returns {any}
157
191
  */
158
- export function generateCoin(amount, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
192
+ export function generateCoin(amount_decimal, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
159
193
  try {
160
194
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
161
- const ptr0 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
195
+ const ptr0 = passStringToWasm0(amount_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
162
196
  const len0 = WASM_VECTOR_LEN;
163
- const ptr1 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
197
+ const ptr1 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
164
198
  const len1 = WASM_VECTOR_LEN;
165
- const ptr2 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
199
+ const ptr2 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
166
200
  const len2 = WASM_VECTOR_LEN;
167
- wasm.generateCoin(retptr, amount, ptr0, len0, ptr1, len1, ptr2, len2);
201
+ const ptr3 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
202
+ const len3 = WASM_VECTOR_LEN;
203
+ wasm.generateCoin(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
168
204
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
169
205
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
170
206
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -178,32 +214,34 @@ export function generateCoin(amount, asset_hi_decimal, asset_lo_decimal, applica
178
214
  }
179
215
 
180
216
  /**
181
- * `Poseidon₁(scalar)` secret + fixed ECDH shared coords (hex), matching an aligned deposit witness.
217
+ * `Poseidon₁(scalar)` secret + recipient owner public key (hex), matching an aligned deposit witness.
182
218
  * @param {string} scalar_hex
183
- * @param {string} shared_x_hex
184
- * @param {string} shared_y_hex
185
- * @param {bigint} amount
219
+ * @param {string} owner_x_hex
220
+ * @param {string} owner_y_hex
221
+ * @param {string} amount_decimal
186
222
  * @param {string} asset_hi_decimal
187
223
  * @param {string} asset_lo_decimal
188
224
  * @param {string} application_id_decimal
189
225
  * @returns {any}
190
226
  */
191
- export function generateCoinForDepositWithSharedHex(scalar_hex, shared_x_hex, shared_y_hex, amount, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
227
+ export function generateCoinForDepositWithOwnerPubHex(scalar_hex, owner_x_hex, owner_y_hex, amount_decimal, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
192
228
  try {
193
229
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
194
230
  const ptr0 = passStringToWasm0(scalar_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
195
231
  const len0 = WASM_VECTOR_LEN;
196
- const ptr1 = passStringToWasm0(shared_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
232
+ const ptr1 = passStringToWasm0(owner_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
197
233
  const len1 = WASM_VECTOR_LEN;
198
- const ptr2 = passStringToWasm0(shared_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
234
+ const ptr2 = passStringToWasm0(owner_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
199
235
  const len2 = WASM_VECTOR_LEN;
200
- const ptr3 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
236
+ const ptr3 = passStringToWasm0(amount_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
201
237
  const len3 = WASM_VECTOR_LEN;
202
- const ptr4 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
238
+ const ptr4 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
203
239
  const len4 = WASM_VECTOR_LEN;
204
- const ptr5 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
240
+ const ptr5 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
205
241
  const len5 = WASM_VECTOR_LEN;
206
- wasm.generateCoinForDepositWithSharedHex(retptr, ptr0, len0, ptr1, len1, ptr2, len2, amount, ptr3, len3, ptr4, len4, ptr5, len5);
242
+ const ptr6 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
243
+ const len6 = WASM_VECTOR_LEN;
244
+ wasm.generateCoinForDepositWithOwnerPubHex(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6);
207
245
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
208
246
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
209
247
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -219,24 +257,26 @@ export function generateCoinForDepositWithSharedHex(scalar_hex, shared_x_hex, sh
219
257
  /**
220
258
  * `secret` in coin = `Poseidon255(1)(scalar)` per `deposit.circom`; scalar is 32-byte hex (64 chars, optional `0x`).
221
259
  * @param {string} scalar_hex
222
- * @param {bigint} amount
260
+ * @param {string} amount_decimal
223
261
  * @param {string} asset_hi_decimal
224
262
  * @param {string} asset_lo_decimal
225
263
  * @param {string} application_id_decimal
226
264
  * @returns {any}
227
265
  */
228
- export function generateCoinFromDepositEphemeralScalarHex(scalar_hex, amount, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
266
+ export function generateCoinFromDepositEphemeralScalarHex(scalar_hex, amount_decimal, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
229
267
  try {
230
268
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
231
269
  const ptr0 = passStringToWasm0(scalar_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
232
270
  const len0 = WASM_VECTOR_LEN;
233
- const ptr1 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
271
+ const ptr1 = passStringToWasm0(amount_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
234
272
  const len1 = WASM_VECTOR_LEN;
235
- const ptr2 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
273
+ const ptr2 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
236
274
  const len2 = WASM_VECTOR_LEN;
237
- const ptr3 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
275
+ const ptr3 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
238
276
  const len3 = WASM_VECTOR_LEN;
239
- wasm.generateCoinFromDepositEphemeralScalarHex(retptr, ptr0, len0, amount, ptr1, len1, ptr2, len2, ptr3, len3);
277
+ const ptr4 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
278
+ const len4 = WASM_VECTOR_LEN;
279
+ wasm.generateCoinFromDepositEphemeralScalarHex(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
240
280
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
241
281
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
242
282
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -250,29 +290,31 @@ export function generateCoinFromDepositEphemeralScalarHex(scalar_hex, amount, as
250
290
  }
251
291
 
252
292
  /**
253
- * Same as `generateCoin`, but commitment uses the given ECDH shared key (64-char hex coords from `ecdhSharedKey`); shared coords are not stored in `coin` JSON.
254
- * @param {string} shared_x_hex
255
- * @param {string} shared_y_hex
256
- * @param {bigint} amount
293
+ * Same as `generateCoin`, but commitment uses the given owner public key (64-char hex coords).
294
+ * @param {string} owner_x_hex
295
+ * @param {string} owner_y_hex
296
+ * @param {string} amount_decimal
257
297
  * @param {string} asset_hi_decimal
258
298
  * @param {string} asset_lo_decimal
259
299
  * @param {string} application_id_decimal
260
300
  * @returns {any}
261
301
  */
262
- export function generateCoinWithSharedSecretHex(shared_x_hex, shared_y_hex, amount, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
302
+ export function generateCoinWithOwnerPubHex(owner_x_hex, owner_y_hex, amount_decimal, asset_hi_decimal, asset_lo_decimal, application_id_decimal) {
263
303
  try {
264
304
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
265
- const ptr0 = passStringToWasm0(shared_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
305
+ const ptr0 = passStringToWasm0(owner_x_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
266
306
  const len0 = WASM_VECTOR_LEN;
267
- const ptr1 = passStringToWasm0(shared_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
307
+ const ptr1 = passStringToWasm0(owner_y_hex, wasm.__wbindgen_export, wasm.__wbindgen_export2);
268
308
  const len1 = WASM_VECTOR_LEN;
269
- const ptr2 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
309
+ const ptr2 = passStringToWasm0(amount_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
270
310
  const len2 = WASM_VECTOR_LEN;
271
- const ptr3 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
311
+ const ptr3 = passStringToWasm0(asset_hi_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
272
312
  const len3 = WASM_VECTOR_LEN;
273
- const ptr4 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
313
+ const ptr4 = passStringToWasm0(asset_lo_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
274
314
  const len4 = WASM_VECTOR_LEN;
275
- wasm.generateCoinWithSharedSecretHex(retptr, ptr0, len0, ptr1, len1, amount, ptr2, len2, ptr3, len3, ptr4, len4);
315
+ const ptr5 = passStringToWasm0(application_id_decimal, wasm.__wbindgen_export, wasm.__wbindgen_export2);
316
+ const len5 = WASM_VECTOR_LEN;
317
+ wasm.generateCoinWithOwnerPubHex(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5);
276
318
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
277
319
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
278
320
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
Binary file
@@ -2,14 +2,15 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const buildWithdrawMerkleWitness: (a: number, b: number, c: number, d: number, e: number) => void;
5
- export const calculateNullifierHash: (a: number, b: number, c: number) => void;
5
+ export const calculateNullifierHash: (a: number, b: number, c: number, d: number, e: number) => void;
6
+ export const derivedEscrowKey: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
6
7
  export const ecdhEphemeralPublicKey: (a: number, b: number, c: number) => void;
7
8
  export const ecdhEphemeralPublicKeyFromScalarHex: (a: number, b: number, c: number) => void;
8
9
  export const ecdhSharedKey: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
9
- export const generateCoin: (a: number, b: bigint, c: number, d: number, e: number, f: number, g: number, h: number) => void;
10
- export const generateCoinForDepositWithSharedHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: bigint, i: number, j: number, k: number, l: number, m: number, n: number) => void;
11
- export const generateCoinFromDepositEphemeralScalarHex: (a: number, b: number, c: number, d: bigint, e: number, f: number, g: number, h: number, i: number, j: number) => void;
12
- export const generateCoinWithSharedSecretHex: (a: number, b: number, c: number, d: number, e: number, f: bigint, g: number, h: number, i: number, j: number, k: number, l: number) => void;
10
+ export const generateCoin: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
11
+ export const generateCoinForDepositWithOwnerPubHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number) => void;
12
+ export const generateCoinFromDepositEphemeralScalarHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => void;
13
+ export const generateCoinWithOwnerPubHex: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number) => void;
13
14
  export const proofToHex: (a: number, b: number, c: number) => void;
14
15
  export const publicToHex: (a: number, b: number, c: number) => void;
15
16
  export const __wbindgen_export: (a: number, b: number) => number;
@@ -1,36 +0,0 @@
1
- import { xdr } from '@stellar/stellar-sdk';
2
- export interface PlaintextNotePayload {
3
- value: bigint;
4
- asset_hi: Buffer;
5
- asset_lo: Buffer;
6
- nullifier: Buffer;
7
- secret: Buffer;
8
- deposited_ephemeral_scalar?: Buffer;
9
- }
10
- export type OptionalPrivateAddressRegistrationPayload = {
11
- tag: 'None';
12
- } | {
13
- tag: 'Some';
14
- values: readonly [
15
- {
16
- owner: string;
17
- public_key_x: Buffer;
18
- public_key_y: Buffer;
19
- }
20
- ];
21
- };
22
- export interface OnboardingPayloadInput {
23
- owner: string;
24
- temp_public_key_x: Buffer;
25
- temp_public_key_y: Buffer;
26
- encrypted_private_key: Buffer;
27
- notes: PlaintextNotePayload[];
28
- private_address_registration: OptionalPrivateAddressRegistrationPayload;
29
- }
30
- declare const ONBOARDING_ZERO_DOMAIN = "privacy-pool-onboarding-zero-v1";
31
- /** Canonical `onboardingHash` matching `libs/kyt-passage/src/lib.rs::hash_onboarding`. */
32
- export declare function hashOnboardingCanonical(onboarding: OnboardingPayloadInput | null | undefined): string;
33
- export declare function onboardingToScVal(onboarding: OnboardingPayloadInput): xdr.ScVal;
34
- export declare function onboardingOptionToScVal(onboarding: OnboardingPayloadInput | null | undefined): xdr.ScVal;
35
- export declare function addressToScVal(address: string): xdr.ScVal;
36
- export { ONBOARDING_ZERO_DOMAIN };