@arcanetech/privacy-sdk-stellar 0.3.0 → 0.5.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.
@@ -1,9 +1,10 @@
1
1
  // src/transact/pool/service.ts
2
2
  import {
3
+ PrivacyPoolSDK as PrivacyPoolSDK2,
3
4
  decodeDecodedEphemeralKey,
4
5
  randomFrDecimal253,
5
6
  scalarHexToFrDecimal as scalarHexToFrDecimal2
6
- } from "@auditable/privacy-pool-zk-sdk";
7
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
7
8
 
8
9
  // src/transact/merkle/field-decimal.ts
9
10
  import { Buffer as Buffer2 } from "buffer";
@@ -26,11 +27,18 @@ import {
26
27
  decodeStealthAddress,
27
28
  encodeStealthAddress,
28
29
  recipientPublicKeysDecimalFromStealthAddress
29
- } from "@auditable/privacy-pool-zk-sdk";
30
- import { DEFAULT_STEALTH_SIGN_NONCE } from "@auditable/privacy-pool-zk-sdk";
31
- function buildPrivateAddressSignMessage(publicKey, nonce) {
30
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
31
+ import { DEFAULT_STEALTH_SIGN_NONCE } from "@arcanetech/stellar-privacy-pool-zk-sdk";
32
+ import {
33
+ OWNER_BOUND_NOTE_SCHEMA_VERSION,
34
+ spendScalarHexFromStellarSignature
35
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
36
+ function buildPrivateAddressSignMessage(publicKey, domain, nonce) {
32
37
  const buildMessage = buildStealthAddressSignMessage;
33
- return buildMessage(publicKey, nonce);
38
+ if (nonce === void 0) {
39
+ return buildMessage(publicKey, domain);
40
+ }
41
+ return buildMessage(publicKey, domain, nonce);
34
42
  }
35
43
  function decodePrivateAddress(value) {
36
44
  const decodeAddress = decodeStealthAddress;
@@ -60,12 +68,12 @@ function privateAddressSdk(sdk) {
60
68
  );
61
69
  }
62
70
  return {
63
- generatePrivateAddressFromStellarSignature: (signature) => generator.call(sdk, signature)
71
+ generatePrivateAddressFromStellarSignature: (signature, domain) => generator.call(sdk, signature, domain)
64
72
  };
65
73
  }
66
74
 
67
75
  // src/transact/proofs/withdraw/transact-proof.ts
68
- import { withdrawObjectFromMerkleWitness as withdrawObjectFromMerkleWitness2 } from "@auditable/privacy-pool-zk-sdk";
76
+ import { withdrawObjectFromMerkleWitness as withdrawObjectFromMerkleWitness2 } from "@arcanetech/stellar-privacy-pool-zk-sdk";
69
77
 
70
78
  // src/transact/proofs/transaction-input.ts
71
79
  import { Buffer as Buffer4 } from "buffer";
@@ -105,6 +113,10 @@ function resolveTokenContractId(tokenContractRaw) {
105
113
  }
106
114
 
107
115
  // src/transact/proofs/transaction-input.ts
116
+ var ZERO_PUBLIC_WITHDRAW_ADDRESS = {
117
+ withdrawAddressHi: "0",
118
+ withdrawAddressLo: "0"
119
+ };
108
120
  var CONTRACT_ADDRESS_HALF_BYTES = 16;
109
121
  var CONTRACT_ADDRESS_BYTES = 32;
110
122
  function bytes16ToDecimal(bytes) {
@@ -131,7 +143,25 @@ function withTokenAddressPublicInputs(base, tokenAddress) {
131
143
  return {
132
144
  ...base,
133
145
  tokenAddressHi: hi,
134
- tokenAddressLo: lo
146
+ tokenAddressLo: lo,
147
+ withdrawAddressHi: base.withdrawAddressHi ?? ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressHi,
148
+ withdrawAddressLo: base.withdrawAddressLo ?? ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressLo,
149
+ escrowRecipientHi: base.escrowRecipientHi ?? "0",
150
+ escrowRecipientLo: base.escrowRecipientLo ?? "0",
151
+ sweepOutputOwnerPubX: base.sweepOutputOwnerPubX ?? "0",
152
+ sweepOutputOwnerPubY: base.sweepOutputOwnerPubY ?? "0"
153
+ };
154
+ }
155
+ function publicWithdrawAddressLimbs(parameters) {
156
+ if (parameters.publicWithdrawalAmount === "0") {
157
+ return {
158
+ withdrawAddressHi: ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressHi,
159
+ withdrawAddressLo: ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressLo
160
+ };
161
+ }
162
+ return {
163
+ withdrawAddressHi: parameters.destinationHi,
164
+ withdrawAddressLo: parameters.destinationLo
135
165
  };
136
166
  }
137
167
  function tokenAddressToAssetLeg(tokenAddress) {
@@ -142,91 +172,91 @@ function assetLegToTokenAddress(assetHi, assetLo) {
142
172
  const payload = Buffer4.concat([decimalToBytes16(assetHi), decimalToBytes16(assetLo)]);
143
173
  return StrKey2.encodeContract(payload);
144
174
  }
145
- function buildZeroPublicLegs() {
175
+ function buildZeroPublicLegs(publicNInputs = 1, publicNOutputs = 1) {
146
176
  return {
147
- publicWithdrawnAssets: [["0", "0"]],
148
- publicDepositedAssets: [["0", "0"]],
149
- publicDeposits: ["0"],
150
- publicWithdrawals: ["0"]
177
+ publicWithdrawnAssets: Array.from(
178
+ { length: publicNOutputs },
179
+ () => ["0", "0"]
180
+ ),
181
+ publicDepositedAssets: Array.from(
182
+ { length: publicNInputs },
183
+ () => ["0", "0"]
184
+ ),
185
+ publicDeposits: Array.from({ length: publicNInputs }, () => "0"),
186
+ publicWithdrawals: Array.from({ length: publicNOutputs }, () => "0")
151
187
  };
152
188
  }
153
- function buildPublicDepositLegs(tokenAddress, amount) {
154
- const legs = buildZeroPublicLegs();
189
+ function buildPublicDepositLegs(tokenAddress, amount, publicNInputs = 1, publicNOutputs = 1) {
190
+ const legs = buildZeroPublicLegs(publicNInputs, publicNOutputs);
155
191
  return {
156
192
  ...legs,
157
- publicDepositedAssets: [tokenAddressToAssetLeg(tokenAddress)],
158
- publicDeposits: [amount]
193
+ publicDepositedAssets: [
194
+ tokenAddressToAssetLeg(tokenAddress),
195
+ ...legs.publicDepositedAssets.slice(1)
196
+ ],
197
+ publicDeposits: [amount, ...legs.publicDeposits.slice(1)]
159
198
  };
160
199
  }
161
- function buildPublicWithdrawLegs(tokenAddress, amount) {
162
- const legs = buildZeroPublicLegs();
200
+ function buildPublicWithdrawLegs(tokenAddress, amount, publicNInputs = 1, publicNOutputs = 1) {
201
+ const legs = buildZeroPublicLegs(publicNInputs, publicNOutputs);
163
202
  return {
164
203
  ...legs,
165
- publicWithdrawnAssets: [tokenAddressToAssetLeg(tokenAddress)],
166
- publicWithdrawals: [amount]
204
+ publicWithdrawnAssets: [
205
+ tokenAddressToAssetLeg(tokenAddress),
206
+ ...legs.publicWithdrawnAssets.slice(1)
207
+ ],
208
+ publicWithdrawals: [amount, ...legs.publicWithdrawals.slice(1)]
167
209
  };
168
210
  }
169
211
 
170
- // src/transact/proofs/confidential/helpers.ts
212
+ // src/transact/zk/slots.ts
171
213
  import {
172
- ed25519PubkeyPayloadHexToWithdrawFrDecimals,
173
- withdrawObjectFromMerkleWitness
174
- } from "@auditable/privacy-pool-zk-sdk";
175
- import { StrKey as StrKey3 } from "@stellar/stellar-sdk";
176
- import { Buffer as Buffer5 } from "buffer";
177
-
178
- // src/transact/encoding/priv-key-scalar-from-recipient-hex.ts
179
- import { BN254_BABYJUB_SCALAR_MAX_EXCLUSIVE } from "@auditable/privacy-pool-zk-sdk";
180
- var SCALAR_HEX_CHAR_LENGTH = 64;
181
- var DECIMAL_RADIX = 10;
182
- var BIGINT_ONE = 1n;
183
- function normalizeRecipientScalarHex(hexInput) {
184
- const trimmed = hexInput.trim().replace(/^0x/iu, "");
185
- if (!/^[0-9a-f]*$/iu.test(trimmed)) {
186
- throw new Error("recipient scalar hex must be hexadecimal");
187
- }
188
- const withLeadingNibble = trimmed.length % 2 === 0 ? trimmed : `0${trimmed}`;
189
- const lower = withLeadingNibble.toLowerCase();
190
- const padded = lower.padStart(SCALAR_HEX_CHAR_LENGTH, "0").slice(-SCALAR_HEX_CHAR_LENGTH);
191
- if (padded.length !== SCALAR_HEX_CHAR_LENGTH) {
214
+ padDepositSlots,
215
+ padPublicLegs,
216
+ padWithdrawSlots
217
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
218
+ function padWithdrawSlotsToLayout(sdk, slots) {
219
+ return padWithdrawSlots(slots, sdk.getLayout().nIns);
220
+ }
221
+ function padDepositSlotsToLayout(sdk, slots) {
222
+ return padDepositSlots(slots, sdk.getLayout().nOuts);
223
+ }
224
+ function padPublicLegsToLayout(sdk, legs) {
225
+ const { publicNInputs, publicNOutputs } = sdk.getLayout();
226
+ return padPublicLegs(legs, publicNInputs, publicNOutputs);
227
+ }
228
+ function padStrings(values, length, fill) {
229
+ if (values.length > length) {
192
230
  throw new Error(
193
- `recipient scalar hex must fit 32 bytes (${SCALAR_HEX_CHAR_LENGTH} hex chars)`
231
+ `expected at most ${String(length)} application-id slots, got ${String(values.length)}`
194
232
  );
195
233
  }
196
- return padded;
234
+ return [...values, ...Array.from({ length: length - values.length }, () => fill)];
197
235
  }
198
- function privKeyScalarDecimalFromRecipientScalarHex(hexInput) {
199
- const hex = normalizeRecipientScalarHex(hexInput);
200
- const value = BigInt(`0x${hex}`);
201
- const mask = BN254_BABYJUB_SCALAR_MAX_EXCLUSIVE - BIGINT_ONE;
202
- return (value & mask).toString(DECIMAL_RADIX);
236
+ function buildApplicationIdHints(input) {
237
+ const { nIns, nOuts } = input.sdk.getLayout();
238
+ return [
239
+ ...padStrings(input.inputIds, nIns, "0"),
240
+ ...padStrings(input.outputIds, nOuts, "0")
241
+ ];
242
+ }
243
+ function uniformApplicationIdHints(applicationId, nAuditSlots) {
244
+ return Array.from({ length: nAuditSlots }, () => applicationId);
203
245
  }
204
246
 
205
247
  // src/transact/proofs/confidential/helpers.ts
248
+ import { withdrawObjectFromMerkleWitness } from "@arcanetech/stellar-privacy-pool-zk-sdk";
206
249
  var MIN_CONFIDENTIAL_TRANSFER_STROOPS = 1n;
207
250
  var ZERO_STROOPS = 0n;
208
- function leafEphemeralCoords(xHex, yHex) {
209
- const coords = {};
210
- Object.defineProperty(coords, "x", {
211
- value: xHex,
212
- enumerable: true,
213
- writable: true
214
- });
215
- Object.defineProperty(coords, "y", {
216
- value: yHex,
217
- enumerable: true,
218
- writable: true
219
- });
220
- return coords;
221
- }
222
251
  function withdrawWitnessForCoin(parameters) {
223
- const { sdk, coin, state, xHex, yHex } = parameters;
252
+ const { sdk, coin, state } = parameters;
224
253
  const witness = sdk.buildWithdrawMerkleWitness(coin, state);
225
254
  const withdrawApplicationId = coin.application_id ?? parameters.applicationId;
226
255
  const withdrawObject = withdrawObjectFromMerkleWitness(
227
256
  witness,
228
- leafEphemeralCoords(xHex, yHex),
229
- withdrawApplicationId
257
+ parameters.ownerPubHex,
258
+ withdrawApplicationId,
259
+ parameters.privKeyScalar
230
260
  );
231
261
  return { witness, withdrawObject };
232
262
  }
@@ -235,16 +265,16 @@ function dualWithdrawLegsWithSharedRoot(parameters) {
235
265
  sdk: parameters.sdk,
236
266
  coin: parameters.coinA,
237
267
  state: parameters.state,
238
- xHex: parameters.ephemeralA.xHex,
239
- yHex: parameters.ephemeralA.yHex,
268
+ ownerPubHex: parameters.ownerPubHex,
269
+ privKeyScalar: parameters.privKeyScalar,
240
270
  applicationId: parameters.applicationId
241
271
  });
242
272
  const legB = withdrawWitnessForCoin({
243
273
  sdk: parameters.sdk,
244
274
  coin: parameters.coinB,
245
275
  state: parameters.state,
246
- xHex: parameters.ephemeralB.xHex,
247
- yHex: parameters.ephemeralB.yHex,
276
+ ownerPubHex: parameters.ownerPubHex,
277
+ privKeyScalar: parameters.privKeyScalar,
248
278
  applicationId: parameters.applicationId
249
279
  });
250
280
  if (legA.witness.stateRoot !== legB.witness.stateRoot) {
@@ -252,15 +282,6 @@ function dualWithdrawLegsWithSharedRoot(parameters) {
252
282
  }
253
283
  return { legA, legB };
254
284
  }
255
- function senderWithdrawFrAndScalar(parameters) {
256
- const pkRaw = StrKey3.decodeEd25519PublicKey(parameters.senderGAddress);
257
- const pkHex = Buffer5.from(pkRaw).toString("hex");
258
- const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals(pkHex);
259
- const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
260
- parameters.senderPrivKeyScalarHex
261
- );
262
- return { hi, lo, privKeyScalar };
263
- }
264
285
  function requireChangeRecipientWhenPartial(changeStroops, selfPrivateAddressStpl1ForChange) {
265
286
  if (changeStroops > ZERO_STROOPS) {
266
287
  const stpl1 = selfPrivateAddressStpl1ForChange?.trim() ?? "";
@@ -285,15 +306,15 @@ function changeStroopsAfterDualTransfer(transferStroops, totalNotes) {
285
306
  import {
286
307
  DEMO_AUDIT_PUBLIC_KEY,
287
308
  resolveTransactionAuditParams
288
- } from "@auditable/privacy-pool-zk-sdk";
289
- import { Buffer as Buffer6 } from "buffer";
309
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
310
+ import { Buffer as Buffer5 } from "buffer";
290
311
  var UNCOMPRESSED_PREFIX = "04";
291
312
  var UNCOMPRESSED_HEX_LENGTH = 130;
292
313
  var XY_HEX_LENGTH = 128;
293
314
  var X_OFFSET_END = 32;
294
315
  var Y_OFFSET_START = 32;
295
316
  var Y_OFFSET_END = 64;
296
- var DECIMAL_RADIX2 = 10;
317
+ var DECIMAL_RADIX = 10;
297
318
  var BN254_FR_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
298
319
  var BABYJUBJUB_A = 168700n;
299
320
  var BABYJUBJUB_D = 168696n;
@@ -313,13 +334,13 @@ function parseAuditPublicKeyFromEnvHex(raw) {
313
334
  "Audit public key must be uncompressed 65-byte hex (04 + X + Y) or 64-byte X+Y hex"
314
335
  );
315
336
  }
316
- const bytes = Buffer6.from(payload, "hex");
337
+ const bytes = Buffer5.from(payload, "hex");
317
338
  const auditPublicKeyXDecimal = BigInt(
318
339
  `0x${bytes.subarray(0, X_OFFSET_END).toString("hex")}`
319
- ).toString(DECIMAL_RADIX2);
340
+ ).toString(DECIMAL_RADIX);
320
341
  const auditPublicKeyYDecimal = BigInt(
321
342
  `0x${bytes.subarray(Y_OFFSET_START, Y_OFFSET_END).toString("hex")}`
322
- ).toString(DECIMAL_RADIX2);
343
+ ).toString(DECIMAL_RADIX);
323
344
  if (!passesBabyJubCurveCheck(
324
345
  BigInt(auditPublicKeyXDecimal),
325
346
  BigInt(auditPublicKeyYDecimal)
@@ -331,7 +352,8 @@ function parseAuditPublicKeyFromEnvHex(raw) {
331
352
  function buildPoolTransactionAuditParameters(input) {
332
353
  return resolveTransactionAuditParams(
333
354
  input.applicationId,
334
- input.auditPublicKey ?? DEMO_AUDIT_PUBLIC_KEY
355
+ input.auditPublicKey ?? DEMO_AUDIT_PUBLIC_KEY,
356
+ input.nAuditSlots
335
357
  );
336
358
  }
337
359
  function resolvePoolApplicationId(applicationId) {
@@ -345,24 +367,24 @@ function resolvePoolApplicationId(applicationId) {
345
367
  }
346
368
 
347
369
  // src/transact/proofs/withdraw/helpers.ts
348
- import { ed25519PubkeyPayloadHexToWithdrawFrDecimals as ed25519PubkeyPayloadHexToWithdrawFrDecimals2 } from "@auditable/privacy-pool-zk-sdk";
370
+ import { ed25519PubkeyPayloadHexToWithdrawFrDecimals } from "@arcanetech/stellar-privacy-pool-zk-sdk";
349
371
 
350
372
  // src/transact/stellar/account.ts
351
- import { StrKey as StrKey4 } from "@stellar/stellar-sdk";
352
- import { Buffer as Buffer7 } from "buffer";
373
+ import { StrKey as StrKey3 } from "@stellar/stellar-sdk";
374
+ import { Buffer as Buffer6 } from "buffer";
353
375
  var MUXED_ACCOUNT_ID_BYTE_LENGTH = 8;
354
376
  var ED25519_PUBLIC_KEY_BYTE_LENGTH = 32;
355
377
  function ed25519HexFromGAddress(trimmed) {
356
378
  try {
357
- const raw = StrKey4.decodeEd25519PublicKey(trimmed);
358
- return Buffer7.from(raw).toString("hex");
379
+ const raw = StrKey3.decodeEd25519PublicKey(trimmed);
380
+ return Buffer6.from(raw).toString("hex");
359
381
  } catch {
360
382
  return void 0;
361
383
  }
362
384
  }
363
385
  function ed25519HexFromMuxedAddress(trimmed) {
364
386
  try {
365
- const raw = StrKey4.decodeMed25519PublicKey(trimmed);
387
+ const raw = StrKey3.decodeMed25519PublicKey(trimmed);
366
388
  if (raw.length === MUXED_ACCOUNT_ID_BYTE_LENGTH + ED25519_PUBLIC_KEY_BYTE_LENGTH) {
367
389
  return raw.subarray(MUXED_ACCOUNT_ID_BYTE_LENGTH).toString("hex");
368
390
  }
@@ -387,26 +409,29 @@ function ed25519PublicKeyHexFromStellarAccount(address) {
387
409
  throw new Error("Invalid destination Stellar address");
388
410
  }
389
411
 
390
- // src/transact/encoding/ephemeral-key.ts
391
- var HEX_64_RE = /^[\da-f]{64}$/iu;
392
- function normalizeCoordinate(value) {
393
- const hex = value.trim().replace(/^0x/iu, "").toLowerCase();
394
- if (!HEX_64_RE.test(hex)) {
395
- throw new Error("Ephemeral key coordinate must be a 32-byte hex string.");
412
+ // src/transact/encoding/priv-key-scalar-from-recipient-hex.ts
413
+ import { canonicalBabyJubScalarFromInteger } from "@arcanetech/stellar-privacy-pool-zk-sdk";
414
+ var SCALAR_HEX_CHAR_LENGTH = 64;
415
+ var DECIMAL_RADIX2 = 10;
416
+ function normalizeRecipientScalarHex(hexInput) {
417
+ const trimmed = hexInput.trim().replace(/^0x/iu, "");
418
+ if (!/^[0-9a-f]*$/iu.test(trimmed)) {
419
+ throw new Error("recipient scalar hex must be hexadecimal");
396
420
  }
397
- return hex;
398
- }
399
- function parseEphemeralKeyString(input) {
400
- const [xRaw, yRaw, extra] = input.split(":");
401
- if (!xRaw || !yRaw || extra !== void 0) {
421
+ const withLeadingNibble = trimmed.length % 2 === 0 ? trimmed : `0${trimmed}`;
422
+ const lower = withLeadingNibble.toLowerCase();
423
+ const padded = lower.padStart(SCALAR_HEX_CHAR_LENGTH, "0").slice(-SCALAR_HEX_CHAR_LENGTH);
424
+ if (padded.length !== SCALAR_HEX_CHAR_LENGTH) {
402
425
  throw new Error(
403
- 'Ephemeral key must be a string in "xHex:yHex" format (32-byte hex each).'
426
+ `recipient scalar hex must fit 32 bytes (${SCALAR_HEX_CHAR_LENGTH} hex chars)`
404
427
  );
405
428
  }
406
- return {
407
- xHex: normalizeCoordinate(xRaw),
408
- yHex: normalizeCoordinate(yRaw)
409
- };
429
+ return padded;
430
+ }
431
+ function privKeyScalarDecimalFromRecipientScalarHex(hexInput) {
432
+ const hex = normalizeRecipientScalarHex(hexInput);
433
+ const value = BigInt(`0x${hex}`);
434
+ return canonicalBabyJubScalarFromInteger(value).toString(DECIMAL_RADIX2);
410
435
  }
411
436
 
412
437
  // src/transact/proofs/withdraw/helpers.ts
@@ -414,7 +439,7 @@ function destinationWithdrawFrAndScalar(parameters) {
414
439
  const pkHex = ed25519PublicKeyHexFromStellarAccount(
415
440
  parameters.destinationStellarAddress
416
441
  );
417
- const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals2(pkHex);
442
+ const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals(pkHex);
418
443
  const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
419
444
  parameters.privKeyScalarHex
420
445
  );
@@ -428,8 +453,11 @@ function buildWithdrawPublicInput(parameters) {
428
453
  return withTokenAddressPublicInputs(
429
454
  {
430
455
  stateRoot: parameters.stateRoot,
431
- withdrawAddressHi: hi,
432
- withdrawAddressLo: lo,
456
+ ...publicWithdrawAddressLimbs({
457
+ publicWithdrawalAmount: parameters.publicWithdrawalAmount,
458
+ destinationHi: hi,
459
+ destinationLo: lo
460
+ }),
433
461
  privKeyScalar
434
462
  },
435
463
  parameters.tokenAddress
@@ -437,7 +465,7 @@ function buildWithdrawPublicInput(parameters) {
437
465
  }
438
466
  async function resolveWithdrawChangeDeposits(parameters) {
439
467
  if (parameters.changeStroops <= ZERO_STROOPS) {
440
- return { deposits: ["dummy", "dummy"] };
468
+ return { deposits: [] };
441
469
  }
442
470
  const stpl1 = parameters.changePrivateAddressStpl1?.trim() ?? "";
443
471
  if (!stpl1) {
@@ -451,7 +479,7 @@ async function resolveWithdrawChangeDeposits(parameters) {
451
479
  tokenAddress: parameters.tokenAddress
452
480
  });
453
481
  return {
454
- deposits: [slot.deposit, "dummy"],
482
+ deposits: [slot.deposit],
455
483
  changeCoin: {
456
484
  commitment_hex: slot.commitment_hex,
457
485
  coin: slot.coin,
@@ -476,14 +504,14 @@ function buildDualWithdrawPublicInput(parameters) {
476
504
  stateRoot: parameters.stateRoot,
477
505
  destinationStellarAddress: parameters.destinationStellarAddress,
478
506
  privKeyScalarHex: parameters.privKeyScalarHex,
479
- tokenAddress: parameters.tokenAddress
507
+ tokenAddress: parameters.tokenAddress,
508
+ publicWithdrawalAmount: parameters.publicWithdrawalAmount
480
509
  });
481
510
  }
482
511
  async function prepareDualWithdrawProofInputs(parameters) {
483
- const totalNotes = BigInt(parameters.coinA.value) + BigInt(parameters.coinB.value);
484
512
  const changeStroops = validateDualWithdrawAmounts(
485
513
  parameters.withdrawAmountStroops,
486
- totalNotes,
514
+ BigInt(parameters.coinA.value) + BigInt(parameters.coinB.value),
487
515
  parameters.changePrivateAddressStpl1
488
516
  );
489
517
  const { legA, legB } = dualWithdrawLegsWithSharedRoot({
@@ -491,8 +519,12 @@ async function prepareDualWithdrawProofInputs(parameters) {
491
519
  coinA: parameters.coinA,
492
520
  coinB: parameters.coinB,
493
521
  state: parameters.state,
494
- ephemeralA: parseEphemeralKeyString(parameters.ephemeralAKey),
495
- ephemeralB: parseEphemeralKeyString(parameters.ephemeralBKey),
522
+ ownerPubHex: parameters.sdk.ecdhEphemeralPublicKeyFromScalarHex(
523
+ parameters.privKeyScalarHex
524
+ ),
525
+ privKeyScalar: privKeyScalarDecimalFromRecipientScalarHex(
526
+ parameters.privKeyScalarHex
527
+ ),
496
528
  applicationId: parameters.applicationId
497
529
  });
498
530
  const { deposits, changeCoin } = await resolveWithdrawChangeDeposits({
@@ -505,17 +537,19 @@ async function prepareDualWithdrawProofInputs(parameters) {
505
537
  destinationStellarAddress: parameters.destinationStellarAddress,
506
538
  privKeyScalarHex: parameters.privKeyScalarHex,
507
539
  tokenAddress: parameters.tokenAddress,
508
- stateRoot: legA.witness.stateRoot
540
+ stateRoot: legA.witness.stateRoot,
541
+ publicWithdrawalAmount: parameters.withdrawAmountStroops.toString()
509
542
  });
510
543
  const audit = buildPoolTransactionAuditParameters({
511
544
  applicationId: parameters.applicationId,
545
+ nAuditSlots: parameters.sdk.getLayout().nAuditSlots,
512
546
  ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
513
547
  });
514
548
  return {
515
549
  publicInput,
516
550
  audit,
517
- withdrawLegs: [legA.withdrawObject, legB.withdrawObject],
518
551
  deposits,
552
+ withdrawLegs: [legA.withdrawObject, legB.withdrawObject],
519
553
  ...changeCoin ? { changeCoin } : {}
520
554
  };
521
555
  }
@@ -533,35 +567,49 @@ function validateSingleWithdrawAmounts(withdrawAmountStroops, noteStroops) {
533
567
  async function proveSingleWithdrawTransaction(parameters) {
534
568
  return parameters.sdk.proveTransaction(
535
569
  parameters.publicInput,
536
- buildPublicWithdrawLegs(
537
- parameters.tokenAddress,
538
- parameters.withdrawAmountStroops.toString()
570
+ padPublicLegsToLayout(
571
+ parameters.sdk,
572
+ buildPublicWithdrawLegs(
573
+ parameters.tokenAddress,
574
+ parameters.withdrawAmountStroops.toString()
575
+ )
539
576
  ),
540
- [parameters.primaryWithdraw, "dummy"],
541
- parameters.deposits,
577
+ padWithdrawSlotsToLayout(parameters.sdk, [parameters.primaryWithdraw]),
578
+ padDepositSlotsToLayout(parameters.sdk, parameters.deposits),
542
579
  parameters.audit
543
580
  );
544
581
  }
545
582
  function buildPrimaryWithdrawForCoin(parameters) {
546
- const ephemeralPoint = parseEphemeralKeyString(parameters.depositorEphemeralKey);
547
583
  const witness = parameters.sdk.buildWithdrawMerkleWitness(
548
584
  parameters.coin,
549
585
  parameters.state
550
586
  );
587
+ const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
588
+ parameters.privKeyScalarHex
589
+ );
590
+ const ownerPubHex = parameters.sdk.ecdhEphemeralPublicKeyFromScalarHex(
591
+ parameters.privKeyScalarHex
592
+ );
551
593
  const primaryWithdraw = withdrawObjectFromMerkleWitness2(
552
594
  witness,
553
- leafEphemeralCoords(ephemeralPoint.xHex, ephemeralPoint.yHex),
554
- parameters.applicationId
595
+ ownerPubHex,
596
+ parameters.applicationId,
597
+ privKeyScalar
555
598
  );
556
599
  return { witness, primaryWithdraw };
557
600
  }
558
601
  async function prepareSingleWithdrawProofInputs(parameters) {
559
- const noteStroops = BigInt(parameters.coin.value);
560
602
  const changeStroops = validateSingleWithdrawAmounts(
561
603
  parameters.withdrawAmountStroops,
562
- noteStroops
604
+ BigInt(parameters.coin.value)
563
605
  );
564
- const { witness, primaryWithdraw } = buildPrimaryWithdrawForCoin(parameters);
606
+ const { witness, primaryWithdraw } = buildPrimaryWithdrawForCoin({
607
+ sdk: parameters.sdk,
608
+ applicationId: parameters.applicationId,
609
+ coin: parameters.coin,
610
+ state: parameters.state,
611
+ privKeyScalarHex: parameters.privKeyScalarHex
612
+ });
565
613
  const { deposits, changeCoin } = await resolveWithdrawChangeDeposits({
566
614
  changeStroops,
567
615
  changePrivateAddressStpl1: parameters.changePrivateAddressStpl1,
@@ -572,18 +620,19 @@ async function prepareSingleWithdrawProofInputs(parameters) {
572
620
  stateRoot: witness.stateRoot,
573
621
  destinationStellarAddress: parameters.destinationStellarAddress,
574
622
  privKeyScalarHex: parameters.privKeyScalarHex,
575
- tokenAddress: parameters.tokenAddress
576
- });
577
- const audit = buildPoolTransactionAuditParameters({
578
- applicationId: parameters.applicationId,
579
- ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
623
+ tokenAddress: parameters.tokenAddress,
624
+ publicWithdrawalAmount: parameters.withdrawAmountStroops.toString()
580
625
  });
581
626
  return {
582
627
  primaryWithdraw,
583
628
  deposits,
584
629
  changeCoin,
585
630
  publicInput,
586
- audit
631
+ audit: buildPoolTransactionAuditParameters({
632
+ applicationId: parameters.applicationId,
633
+ nAuditSlots: parameters.sdk.getLayout().nAuditSlots,
634
+ ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
635
+ })
587
636
  };
588
637
  }
589
638
  async function proveWithdrawTransact(parameters) {
@@ -599,12 +648,11 @@ async function proveWithdrawTransact(parameters) {
599
648
  });
600
649
  return {
601
650
  ...proof,
602
- applicationIdsPlaintext: [
603
- parameters.applicationId,
604
- "0",
605
- changeCoin ? parameters.applicationId : "0",
606
- "0"
607
- ],
651
+ applicationIdsPlaintext: buildApplicationIdHints({
652
+ sdk: parameters.sdk,
653
+ inputIds: [parameters.applicationId],
654
+ outputIds: [changeCoin ? parameters.applicationId : "0"]
655
+ }),
608
656
  ...changeCoin ? { changeCoin } : {}
609
657
  };
610
658
  }
@@ -612,33 +660,251 @@ async function proveWithdrawTransactDual(parameters) {
612
660
  const { publicInput, audit, withdrawLegs, deposits, changeCoin } = await prepareDualWithdrawProofInputs(parameters);
613
661
  const proof = await parameters.sdk.proveTransaction(
614
662
  publicInput,
615
- buildPublicWithdrawLegs(
616
- parameters.tokenAddress,
617
- parameters.withdrawAmountStroops.toString()
663
+ padPublicLegsToLayout(
664
+ parameters.sdk,
665
+ buildPublicWithdrawLegs(
666
+ parameters.tokenAddress,
667
+ parameters.withdrawAmountStroops.toString()
668
+ )
618
669
  ),
619
- withdrawLegs,
620
- deposits,
670
+ padWithdrawSlotsToLayout(parameters.sdk, withdrawLegs),
671
+ padDepositSlotsToLayout(parameters.sdk, deposits),
621
672
  audit
622
673
  );
623
674
  return {
624
675
  ...proof,
625
- applicationIdsPlaintext: [
626
- audit.applicationId,
627
- audit.applicationId,
628
- changeCoin ? audit.applicationId : "0",
629
- "0"
630
- ],
676
+ applicationIdsPlaintext: buildApplicationIdHints({
677
+ sdk: parameters.sdk,
678
+ inputIds: [audit.applicationId, audit.applicationId],
679
+ outputIds: [changeCoin ? audit.applicationId : "0"]
680
+ }),
631
681
  ...changeCoin ? { changeCoin } : {}
632
682
  };
633
683
  }
634
684
 
635
685
  // src/transact/pool/service.ts
636
686
  import "buffer";
637
- import { PrivacyPoolSDK as PrivacyPoolSdkClass } from "@auditable/privacy-pool-zk-sdk";
687
+
688
+ // src/transact/zk/circuit-config.ts
689
+ import {
690
+ BundledZkCircuit
691
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
692
+
693
+ // src/transact/environment/zk-config-nonce.ts
694
+ var STANDARD_ZK_CONFIG_NONCE = 0n;
695
+ var COMMITMENT_V2_ZK_NONCE = 2n;
696
+ var BINDING_ZK_NONCE = 3n;
697
+ var SIX_BY_SIX_ZK_NONCE = 6n;
698
+ var SIX_BY_SIX_BINDING_ZK_NONCE = 7n;
699
+ var DEFAULT_ZK_CONFIG_NONCE = BINDING_ZK_NONCE;
700
+ function resolveZkConfigNonce(transactEnvironment) {
701
+ return transactEnvironment.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
702
+ }
703
+
704
+ // src/transact/zk/browser-artifact-cache.ts
705
+ import { ZK_SDK_PACKAGE_VERSION } from "@arcanetech/stellar-privacy-pool-zk-sdk";
706
+ var ZK_ARTIFACT_CACHE_NAME = `privacy-sdk-stellar-zk-artifacts:${ZK_SDK_PACKAGE_VERSION}`;
707
+ function isBrowserCacheApiAvailable() {
708
+ return browserCacheStorage() !== void 0;
709
+ }
710
+ function readCaches() {
711
+ return globalThis.caches;
712
+ }
713
+ function browserCacheStorage() {
714
+ const cachesValue = readCaches();
715
+ if (cachesValue === void 0 || cachesValue === null) {
716
+ return void 0;
717
+ }
718
+ return cachesValue;
719
+ }
720
+ function absoluteArtifactUrl(url) {
721
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url)) {
722
+ return url;
723
+ }
724
+ const href = globalThis.location?.href;
725
+ if (href === void 0) {
726
+ return url;
727
+ }
728
+ return new URL(url, href).href;
729
+ }
730
+ async function rememberResponse(url, response) {
731
+ const storage = browserCacheStorage();
732
+ if (storage === void 0) {
733
+ return;
734
+ }
735
+ try {
736
+ const cache = await storage.open(ZK_ARTIFACT_CACHE_NAME);
737
+ await cache.put(url, response.clone());
738
+ } catch {
739
+ return;
740
+ }
741
+ }
742
+ async function fetchNetworkArrayBuffer(url) {
743
+ const response = await fetch(url);
744
+ if (!response.ok) {
745
+ throw new Error(`Failed to fetch ZK artifact ${url}: ${String(response.status)}`);
746
+ }
747
+ await rememberResponse(url, response);
748
+ return response.arrayBuffer();
749
+ }
750
+ async function fetchArrayBufferWithBrowserCache(url) {
751
+ const requestUrl = absoluteArtifactUrl(url);
752
+ const storage = browserCacheStorage();
753
+ if (storage !== void 0) {
754
+ const cache = await storage.open(ZK_ARTIFACT_CACHE_NAME);
755
+ const cached = await cache.match(requestUrl);
756
+ if (cached?.ok === true) {
757
+ return cached.arrayBuffer();
758
+ }
759
+ }
760
+ return fetchNetworkArrayBuffer(requestUrl);
761
+ }
762
+
763
+ // src/transact/zk/prefetch-bundled-circuit.ts
764
+ import {
765
+ bundledCircuitFileNames,
766
+ defaultZkArtifactBaseUrl
767
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
768
+ function resolveArtifactBaseUrl(explicit) {
769
+ const trimmed = explicit?.trim();
770
+ if (trimmed === void 0 || trimmed === "") {
771
+ return defaultZkArtifactBaseUrl();
772
+ }
773
+ let withoutSlash = trimmed;
774
+ while (withoutSlash.endsWith("/")) {
775
+ withoutSlash = withoutSlash.slice(0, -1);
776
+ }
777
+ return withoutSlash;
778
+ }
779
+ function artifactHref(base, fileName) {
780
+ const withSlash = `${base}/`;
781
+ if (/^https?:\/\//i.test(withSlash) || withSlash.startsWith("file:")) {
782
+ return new URL(fileName, withSlash).href;
783
+ }
784
+ const href = globalThis.location?.href;
785
+ if (href !== void 0) {
786
+ return new URL(fileName, new URL(withSlash, href)).href;
787
+ }
788
+ return `${withSlash}${fileName}`;
789
+ }
790
+ async function materializeBundledCircuitWithBrowserCache(definition, zkArtifactBaseUrl) {
791
+ const base = resolveArtifactBaseUrl(zkArtifactBaseUrl);
792
+ const names = bundledCircuitFileNames(definition.circuit);
793
+ const [circuitGraph, r1cs, provingKey] = await Promise.all([
794
+ fetchArrayBufferWithBrowserCache(artifactHref(base, names.graphFileName)),
795
+ fetchArrayBufferWithBrowserCache(artifactHref(base, names.r1csFileName)),
796
+ fetchArrayBufferWithBrowserCache(artifactHref(base, names.provingKeyFileName))
797
+ ]);
798
+ return {
799
+ nIns: definition.nIns,
800
+ nOuts: definition.nOuts,
801
+ publicNInputs: definition.publicNInputs,
802
+ publicNOutputs: definition.publicNOutputs,
803
+ circuitGraph,
804
+ r1cs,
805
+ provingKey
806
+ };
807
+ }
808
+
809
+ // src/transact/zk/circuit-config.ts
810
+ import { BundledZkCircuit as BundledZkCircuit2 } from "@arcanetech/stellar-privacy-pool-zk-sdk";
811
+ var DEFAULT_STELLAR_ZK_CIRCUITS = {
812
+ [BINDING_ZK_NONCE.toString()]: {
813
+ nIns: 2,
814
+ nOuts: 2,
815
+ publicNInputs: 1,
816
+ publicNOutputs: 1,
817
+ circuit: BundledZkCircuit.TwoByTwo
818
+ },
819
+ [SIX_BY_SIX_BINDING_ZK_NONCE.toString()]: {
820
+ nIns: 6,
821
+ nOuts: 6,
822
+ publicNInputs: 1,
823
+ publicNOutputs: 1,
824
+ circuit: BundledZkCircuit.SixBySix
825
+ }
826
+ };
827
+ function isBundledDefinition(definition) {
828
+ return "circuit" in definition;
829
+ }
830
+ function bundledConfig(definition) {
831
+ return {
832
+ nIns: definition.nIns,
833
+ nOuts: definition.nOuts,
834
+ publicNInputs: definition.publicNInputs,
835
+ publicNOutputs: definition.publicNOutputs,
836
+ circuit: definition.circuit
837
+ };
838
+ }
839
+ async function materializeCustomDefinition(definition) {
840
+ const [zkey, circuitGraph, r1cs, provingKey] = await Promise.all([
841
+ fetchArrayBufferWithBrowserCache(definition.zkeyUrl),
842
+ fetchArrayBufferWithBrowserCache(definition.circuitGraphUrl),
843
+ fetchArrayBufferWithBrowserCache(definition.r1csUrl),
844
+ fetchArrayBufferWithBrowserCache(definition.provingKeyUrl)
845
+ ]);
846
+ return {
847
+ nIns: definition.nIns,
848
+ nOuts: definition.nOuts,
849
+ publicNInputs: definition.publicNInputs,
850
+ publicNOutputs: definition.publicNOutputs,
851
+ zkey,
852
+ circuitGraph,
853
+ r1cs,
854
+ provingKey
855
+ };
856
+ }
857
+ async function materializeDefinition(definition, zkArtifactBaseUrl) {
858
+ if (!isBundledDefinition(definition)) {
859
+ return materializeCustomDefinition(definition);
860
+ }
861
+ if (isBrowserCacheApiAvailable()) {
862
+ return materializeBundledCircuitWithBrowserCache(definition, zkArtifactBaseUrl);
863
+ }
864
+ return bundledConfig(definition);
865
+ }
866
+ async function materializeSelectedZkCircuit(circuits, nonce, zkArtifactBaseUrl) {
867
+ const map = stellarCircuitsOrDefault(circuits);
868
+ const key = nonce.toString();
869
+ const definition = Object.entries(map).find(([nonceKey]) => nonceKey === key)?.[1];
870
+ if (!definition) {
871
+ throw new Error(`no zk circuit configured for nonce ${key}`);
872
+ }
873
+ return { [key]: await materializeDefinition(definition, zkArtifactBaseUrl) };
874
+ }
875
+ function stellarCircuitsOrDefault(circuits) {
876
+ return circuits ?? DEFAULT_STELLAR_ZK_CIRCUITS;
877
+ }
878
+ function optionalZkArtifactBaseUrl(value) {
879
+ if (value === void 0) {
880
+ return {};
881
+ }
882
+ const trimmed = value.trim();
883
+ if (trimmed === "") {
884
+ return {};
885
+ }
886
+ let withoutSlash = trimmed;
887
+ while (withoutSlash.endsWith("/")) {
888
+ withoutSlash = withoutSlash.slice(0, -1);
889
+ }
890
+ return { zkArtifactBaseUrl: withoutSlash };
891
+ }
638
892
 
639
893
  // src/transact/pool/aligned-deposit.ts
640
- import { PrivacyPoolSDK, scalarHexToFrDecimal } from "@auditable/privacy-pool-zk-sdk";
894
+ import {
895
+ PrivacyPoolSDK,
896
+ scalarHexToFrDecimal
897
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
641
898
  var SAMPLE_SCALAR_ATTEMPTS = 10;
899
+ function escrowDepositFields(parameters) {
900
+ if (!parameters.recipientHi || !parameters.recipientLo) {
901
+ return {};
902
+ }
903
+ return {
904
+ ...parameters.escrowNonce ? { escrowNonce: parameters.escrowNonce } : {},
905
+ recipientStellar: [parameters.recipientHi, parameters.recipientLo]
906
+ };
907
+ }
642
908
  function sampleValidDepositScalarHex() {
643
909
  for (let index = 0; index < SAMPLE_SCALAR_ATTEMPTS; index++) {
644
910
  const candidate = PrivacyPoolSDK.generateRandomScalarHex32();
@@ -654,17 +920,12 @@ function sampleValidDepositScalarHex() {
654
920
  async function buildAlignedDepositSlotForSdk(sdk, applicationId, parameters) {
655
921
  const privateAddressPoint = decodePrivateAddress(parameters.privateAddressStpl1);
656
922
  const scalarHex = sampleValidDepositScalarHex();
657
- const shared = sdk.ecdhSharedKey(
658
- scalarHex,
659
- privateAddressPoint.x,
660
- privateAddressPoint.y
661
- );
662
923
  const [assetHi, assetLo] = tokenAddressToAssetLeg(parameters.tokenAddress);
663
924
  const resolvedApplicationId = resolvePoolApplicationId(applicationId);
664
- const generated = sdk.generateCoinForDepositWithSharedHex(
925
+ const generated = sdk.generateCoinForDepositWithOwnerPubHex(
665
926
  scalarHex,
666
- shared.x,
667
- shared.y,
927
+ privateAddressPoint.x,
928
+ privateAddressPoint.y,
668
929
  parameters.amountStroops,
669
930
  assetHi,
670
931
  assetLo,
@@ -679,27 +940,34 @@ async function buildAlignedDepositSlotForSdk(sdk, applicationId, parameters) {
679
940
  ephemeralKeyScalar: scalarHexToFrDecimal(scalarHex),
680
941
  asset: [generated.coin.asset_hi, generated.coin.asset_lo],
681
942
  applicationId: resolvedApplicationId,
682
- recipientPublicKeys
943
+ recipientPublicKeys,
944
+ ...escrowDepositFields(parameters)
683
945
  };
684
946
  return {
685
947
  deposit,
686
948
  commitment_hex: generated.commitment_hex,
687
949
  coin: generated.coin,
688
950
  depositScalarHex: scalarHex,
689
- precommitementHex: generated.precommitement_hex
951
+ precommitementHex: generated.precommitementHex
690
952
  };
691
953
  }
692
954
 
693
955
  // src/transact/pool/service.ts
694
956
  var PrivacyPoolService = class {
695
- constructor(assets, applicationId, auditPublicKey) {
957
+ constructor(assets, applicationId, auditPublicKey, zkCircuits, zkConfigNonce, zkArtifactBaseUrl) {
696
958
  this.assets = assets;
697
959
  this.applicationId = applicationId;
698
960
  this.auditPublicKey = auditPublicKey;
961
+ this.zkCircuits = zkCircuits;
962
+ this.zkConfigNonce = zkConfigNonce;
963
+ this.zkArtifactBaseUrl = zkArtifactBaseUrl;
699
964
  }
700
965
  assets;
701
966
  applicationId;
702
967
  auditPublicKey;
968
+ zkCircuits;
969
+ zkConfigNonce;
970
+ zkArtifactBaseUrl;
703
971
  sdk = void 0;
704
972
  initPromise = void 0;
705
973
  async ensureInit() {
@@ -715,10 +983,17 @@ var PrivacyPoolService = class {
715
983
  "PrivacyPoolService requires browser ZK assets before initialization."
716
984
  );
717
985
  }
718
- this.sdk = await PrivacyPoolSdkClass.init({
986
+ const zkConfigNonce = this.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
987
+ const zkCircuits = await materializeSelectedZkCircuit(
988
+ this.zkCircuits,
989
+ zkConfigNonce,
990
+ this.zkArtifactBaseUrl
991
+ );
992
+ this.sdk = await PrivacyPoolSDK2.init({
719
993
  wasmBinary: this.assets.sdkWasm,
720
- circuitWasm: this.assets.circuitWasm,
721
- zkey: this.assets.provingKey
994
+ zkCircuits,
995
+ zkConfigNonce,
996
+ ...optionalZkArtifactBaseUrl(this.zkArtifactBaseUrl)
722
997
  });
723
998
  })();
724
999
  return this.initPromise;
@@ -736,22 +1011,17 @@ var PrivacyPoolService = class {
736
1011
  getApplicationId() {
737
1012
  return resolvePoolApplicationId(this.applicationId);
738
1013
  }
739
- async generatePrivateAddressFromStellarSignature(signature) {
740
- await this.ensureInit();
741
- if (!this.sdk) {
742
- throw new Error("SDK not initialized");
743
- }
744
- return privateAddressSdk(this.sdk).generatePrivateAddressFromStellarSignature(
745
- signature
1014
+ async generatePrivateAddressFromStellarSignature(signature, domain) {
1015
+ const sdk = await this.getInitializedSdk();
1016
+ return privateAddressSdk(sdk).generatePrivateAddressFromStellarSignature(
1017
+ signature,
1018
+ domain
746
1019
  );
747
1020
  }
748
1021
  async sharedSecretX(recipientScalarHex, ephemeralKeyEncoded) {
749
- await this.ensureInit();
750
- if (!this.sdk) {
751
- throw new Error("SDK not initialized");
752
- }
1022
+ const sdk = await this.getInitializedSdk();
753
1023
  const ephemeralKey = decodeDecodedEphemeralKey(ephemeralKeyEncoded);
754
- const shared = this.sdk.sharedSecretFromRecipientPreimage({
1024
+ const shared = sdk.sharedSecretFromRecipientPreimage({
755
1025
  recipientScalar: recipientScalarHex,
756
1026
  ephemeralKey
757
1027
  });
@@ -774,6 +1044,7 @@ var PrivacyPoolService = class {
774
1044
  const applicationId = this.getApplicationId();
775
1045
  const audit = buildPoolTransactionAuditParameters({
776
1046
  applicationId,
1047
+ nAuditSlots: sdk.getLayout().nAuditSlots,
777
1048
  ...this.auditPublicKey ? { auditPublicKey: this.auditPublicKey } : {}
778
1049
  });
779
1050
  const deposit = {
@@ -787,38 +1058,35 @@ var PrivacyPoolService = class {
787
1058
  const publicInput = withTokenAddressPublicInputs(
788
1059
  {
789
1060
  stateRoot,
790
- withdrawAddressHi: "0",
791
- withdrawAddressLo: "0",
792
1061
  privKeyScalar: randomFrDecimal253()
793
1062
  },
794
1063
  parameters.tokenAddress
795
1064
  );
796
1065
  const proof = await sdk.proveTransaction(
797
1066
  publicInput,
798
- buildPublicDepositLegs(parameters.tokenAddress, parameters.coin.value),
799
- ["dummy", "dummy"],
800
- [deposit, "dummy"],
1067
+ padPublicLegsToLayout(
1068
+ sdk,
1069
+ buildPublicDepositLegs(parameters.tokenAddress, parameters.coin.value)
1070
+ ),
1071
+ padWithdrawSlotsToLayout(sdk, []),
1072
+ padDepositSlotsToLayout(sdk, [deposit]),
801
1073
  audit
802
1074
  );
803
- const applicationIdsPlaintext = [
804
- "0",
805
- "0",
806
- applicationId,
807
- "0"
808
- ];
1075
+ const applicationIdsPlaintext = buildApplicationIdHints({
1076
+ sdk,
1077
+ inputIds: [],
1078
+ outputIds: [applicationId]
1079
+ });
809
1080
  return { ...proof, applicationIdsPlaintext };
810
1081
  }
811
- async calculateNullifierHash(nullifier) {
1082
+ async calculateNullifierHash(nullifier, privKeyScalar) {
812
1083
  const sdk = await this.getInitializedSdk();
813
- return sdk.calculateNullifierHash(nullifier);
1084
+ return sdk.calculateNullifierHash(nullifier, privKeyScalar);
814
1085
  }
815
1086
  async prepareWithdrawTransactProof(parameters) {
816
- await this.ensureInit();
817
- if (!this.sdk) {
818
- throw new Error("SDK not initialized");
819
- }
1087
+ const sdk = await this.getInitializedSdk();
820
1088
  return proveWithdrawTransact({
821
- sdk: this.sdk,
1089
+ sdk,
822
1090
  applicationId: this.getApplicationId(),
823
1091
  buildAlignedDepositSlot: (input) => this.buildAlignedDepositSlot(input),
824
1092
  ...this.auditPublicKey ? { auditPublicKey: this.auditPublicKey } : {},
@@ -826,12 +1094,9 @@ var PrivacyPoolService = class {
826
1094
  });
827
1095
  }
828
1096
  async prepareWithdrawTransactProofDual(parameters) {
829
- await this.ensureInit();
830
- if (!this.sdk) {
831
- throw new Error("SDK not initialized");
832
- }
1097
+ const sdk = await this.getInitializedSdk();
833
1098
  return proveWithdrawTransactDual({
834
- sdk: this.sdk,
1099
+ sdk,
835
1100
  applicationId: this.getApplicationId(),
836
1101
  buildAlignedDepositSlot: (input) => this.buildAlignedDepositSlot(input),
837
1102
  ...this.auditPublicKey ? { auditPublicKey: this.auditPublicKey } : {},
@@ -854,7 +1119,10 @@ function createPrivacyPoolService(input) {
854
1119
  return new PrivacyPoolService(
855
1120
  input?.assets,
856
1121
  input?.applicationId,
857
- input?.auditPublicKey
1122
+ input?.auditPublicKey,
1123
+ input?.zkCircuits,
1124
+ input?.zkConfigNonce,
1125
+ input?.zkArtifactBaseUrl
858
1126
  );
859
1127
  }
860
1128
  var configuredPrivacyPoolService;
@@ -870,140 +1138,470 @@ function getPrivacyPoolService() {
870
1138
  return configuredPrivacyPoolService;
871
1139
  }
872
1140
 
873
- // src/transact/assets/load-browser.ts
874
- async function loadStellarBrowserAssets(input) {
875
- const cacheKey = input.cacheBust ? `?v=${Date.now()}` : "";
876
- const [sdkWasm, circuitWasm, provingKey] = await Promise.all([
877
- fetch(`${input.sdkWasmUrl}${cacheKey}`).then((response) => response.arrayBuffer()),
878
- fetch(input.circuitWasmUrl).then((response) => response.arrayBuffer()),
879
- fetch(input.provingKeyUrl).then((response) => response.arrayBuffer())
880
- ]);
881
- return { sdkWasm, circuitWasm, provingKey };
882
- }
883
- async function loadDefaultStellarBrowserAssets(options) {
884
- await import("@auditable/privacy-pool-zk-sdk");
885
- const sdkWasmUrl = new URL("@auditable/privacy-pool-zk-sdk/sdk.wasm", import.meta.url).href;
886
- const circuitWasmUrl = new URL(
887
- "@auditable/privacy-pool-zk-sdk/witness.wasm",
888
- import.meta.url
889
- ).href;
890
- const provingKeyUrl = new URL(
891
- "@auditable/privacy-pool-zk-sdk/main.zkey",
892
- import.meta.url
893
- ).href;
894
- return loadStellarBrowserAssets({
895
- sdkWasmUrl,
896
- circuitWasmUrl,
897
- provingKeyUrl,
898
- ...options?.cacheBust ? { cacheBust: true } : {}
899
- });
900
- }
901
-
902
- // src/transact/onboarding/build-payload.ts
903
- import { Buffer as Buffer9 } from "buffer";
904
- import { PrivacyPoolSDK as PrivacyPoolSDK4 } from "@auditable/privacy-pool-zk-sdk";
905
-
906
- // src/transact/encoding/fr-decimal-to-bytes.ts
907
- var BN254_SCALAR_MOD = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
908
- var FIELD_BYTE_LENGTH = 32;
909
- var BYTE_MASK = 0xffn;
910
- var BITS_PER_BYTE = 8n;
911
- function frDecimalToPaddedBytes32(decimal) {
912
- let value = BigInt(decimal.trim());
913
- value = (value % BN254_SCALAR_MOD + BN254_SCALAR_MOD) % BN254_SCALAR_MOD;
914
- const bytes = Buffer.alloc(FIELD_BYTE_LENGTH);
915
- for (let index = FIELD_BYTE_LENGTH - 1; index >= 0; index -= 1) {
916
- bytes[index] = Number(value & BYTE_MASK);
917
- value >>= BITS_PER_BYTE;
918
- }
919
- return bytes;
1141
+ // src/transact/escrow/tag-challenge-message.ts
1142
+ function buildBlindedRecipientTagChallengeMessage(fields) {
1143
+ return [
1144
+ "Arcane privacy layer: issue your blinded recipient tags.",
1145
+ "",
1146
+ `Wallet: ${fields.stellarAddress}`,
1147
+ `Network: ${fields.networkPassphrase}`,
1148
+ `Issued: ${fields.issuedAt}`,
1149
+ `Expires: ${fields.expiresAt}`,
1150
+ `Nonce: ${fields.nonce}`,
1151
+ "",
1152
+ "This signature proves you control the wallet. It is the same kind of signed challenge used to derive your private-note spend key."
1153
+ ].join("\n");
920
1154
  }
921
1155
 
922
- // src/transact/onboarding/recipient.ts
923
- import { PrivacyPoolSDK as PrivacyPoolSDK3 } from "@auditable/privacy-pool-zk-sdk";
1156
+ // src/transact/escrow/derived-escrow-recipient.ts
1157
+ import { Buffer as Buffer8 } from "buffer";
1158
+ import { StrKey as StrKey4 } from "@stellar/stellar-sdk";
1159
+ import {
1160
+ derivedEscrowKey,
1161
+ ed25519PubkeyPayloadHexToWithdrawFrDecimals as ed25519PubkeyPayloadHexToWithdrawFrDecimals2,
1162
+ sampleDerivedEscrowKey
1163
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
924
1164
  var COORDINATE_HEX_LENGTH = 64;
925
- async function generateTemporaryRecipientPrivateAddress() {
926
- await getPrivacyPoolService().getInitializedSdk();
927
- const temporaryScalarHex = PrivacyPoolSDK3.generateRandomScalarHex32();
928
- const sdk = await getPrivacyPoolService().getInitializedSdk();
929
- const point = sdk.ecdhEphemeralPublicKeyFromScalarHex(temporaryScalarHex);
930
- const publicKeyXHex = point.x.padStart(COORDINATE_HEX_LENGTH, "0");
931
- const publicKeyYHex = point.y.padStart(COORDINATE_HEX_LENGTH, "0");
1165
+ function stellarAccountToFieldLimbs(stellarAddress) {
1166
+ const pkRaw = StrKey4.decodeEd25519PublicKey(stellarAddress.trim());
1167
+ const pkHex = Buffer8.from(pkRaw).toString("hex");
1168
+ const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals2(pkHex);
1169
+ return { recipientHi: hi, recipientLo: lo };
1170
+ }
1171
+ function padCoordinateHex(value) {
1172
+ return value.replace(/^0x/iu, "").padStart(COORDINATE_HEX_LENGTH, "0");
1173
+ }
1174
+ async function deriveEscrowRecipientFromStellarAddress(input) {
1175
+ const recipientStellarAddress = input.recipientStellarAddress.trim();
1176
+ if (!StrKey4.isValidEd25519PublicKey(recipientStellarAddress)) {
1177
+ throw new Error("Escrow recipient must be a Stellar G-address.");
1178
+ }
1179
+ const { recipientHi, recipientLo } = stellarAccountToFieldLimbs(
1180
+ recipientStellarAddress
1181
+ );
1182
+ const deriveKey = input.deriveKey ?? derivedEscrowKey;
1183
+ let nonceDecimal;
1184
+ let key;
1185
+ if (input.nonceDecimal) {
1186
+ nonceDecimal = input.nonceDecimal;
1187
+ key = await deriveKey(
1188
+ BigInt(nonceDecimal),
1189
+ BigInt(recipientHi),
1190
+ BigInt(recipientLo)
1191
+ );
1192
+ } else {
1193
+ const sampled = await sampleDerivedEscrowKey(
1194
+ BigInt(recipientHi),
1195
+ BigInt(recipientLo)
1196
+ );
1197
+ nonceDecimal = sampled.nonce.toString();
1198
+ key = sampled.key;
1199
+ }
932
1200
  return {
933
- temporaryScalarHex,
934
- temporaryPrivateAddressStpl1: encodePrivateAddressFromHexCoordinates(
935
- publicKeyXHex,
936
- publicKeyYHex
937
- )
1201
+ nonceDecimal,
1202
+ recipientHi,
1203
+ recipientLo,
1204
+ recipientStellarAddress,
1205
+ privateAddressStpl1: encodePrivateAddressFromHexCoordinates(
1206
+ padCoordinateHex(key.pointXHex),
1207
+ padCoordinateHex(key.pointYHex)
1208
+ ),
1209
+ scalarHex: padCoordinateHex(key.scalarHex)
938
1210
  };
939
1211
  }
940
1212
 
941
- // src/transact/onboarding/build-payload.ts
942
- var COORDINATE_HEX_LENGTH2 = 64;
943
- function noneOptionalRegistration() {
944
- return { tag: "None", values: void 0 };
1213
+ // src/transact/escrow/assert-escrow-sweep-claimant.ts
1214
+ import { insufficientStateError } from "@arcanetech/privacy-sdk-core";
1215
+ function assertEscrowSweepClaimant(input) {
1216
+ const walletPublicKey = input.walletPublicKey.trim();
1217
+ const claimantAddress = input.claimantAddress.trim();
1218
+ if (!walletPublicKey || walletPublicKey !== claimantAddress) {
1219
+ const error = insufficientStateError(
1220
+ "escrow_sweep_claimant_mismatch",
1221
+ "Escrow sweep requires the connected account that owns the note.",
1222
+ { walletPublicKey, claimantAddress }
1223
+ );
1224
+ throw new Error(error.message, { cause: error });
1225
+ }
945
1226
  }
946
- function coinToPlaintextNote(coin) {
947
- const [assetHi, assetLo] = tokenAddressToAssetLeg(coin.tokenAddress);
1227
+
1228
+ // src/transact/escrow/reconstruct-escrow-note.ts
1229
+ var FIELD_HEX_LENGTH = 64;
1230
+ function hexToDecimal(hex) {
1231
+ const clean = hex.trim().replace(/^0x/u, "");
1232
+ return BigInt(`0x${clean || "0"}`).toString();
1233
+ }
1234
+ function padFieldHex(value) {
1235
+ return value.replace(/^0x/iu, "").padStart(FIELD_HEX_LENGTH, "0");
1236
+ }
1237
+ async function defaultDecryptOutputNote(input) {
1238
+ const module = await import("@arcanetech/stellar-privacy-pool-zk-sdk");
1239
+ if (typeof module.decryptOutputNoteEvent !== "function") {
1240
+ throw new TypeError("Output note decryption is not available.");
1241
+ }
1242
+ return module.decryptOutputNoteEvent(input);
1243
+ }
1244
+ async function reconstructEscrowNote(input) {
1245
+ const derived = await deriveEscrowRecipientFromStellarAddress({
1246
+ recipientStellarAddress: input.claimantAddress,
1247
+ nonceDecimal: input.nonceDecimal,
1248
+ ...input.deriveKey ? { deriveKey: input.deriveKey } : {}
1249
+ });
1250
+ const event = input.events.find((entry) => entry.outputIndex === input.seq);
1251
+ if (!event) {
1252
+ throw new Error("Escrow output note event was not found for this sequence.");
1253
+ }
1254
+ const decrypt = input.decrypt ?? defaultDecryptOutputNote;
1255
+ const decrypted = await decrypt({
1256
+ recipientScalarHex: derived.scalarHex,
1257
+ commitmentHashHex: event.commitmentHashHex,
1258
+ createdEphemeralKey: event.createdEphemeralKey,
1259
+ ciphertext: event.ciphertext,
1260
+ tag: event.tag,
1261
+ ownerMode: 1n
1262
+ });
948
1263
  return {
949
- asset_hi: frDecimalToPaddedBytes32(assetHi),
950
- asset_lo: frDecimalToPaddedBytes32(assetLo),
951
- deposited_ephemeral_scalar: void 0,
952
- nullifier: frDecimalToPaddedBytes32(coin.nullifier),
953
- secret: frDecimalToPaddedBytes32(coin.secret),
954
- value: BigInt(coin.value)
1264
+ coin: {
1265
+ value: decrypted.value,
1266
+ nullifier: decrypted.nullifier,
1267
+ secret: decrypted.secret,
1268
+ commitment: hexToDecimal(decrypted.commitmentHex),
1269
+ asset_hi: decrypted.assetHi,
1270
+ asset_lo: decrypted.assetLo,
1271
+ application_id: decrypted.applicationId
1272
+ },
1273
+ scalarHex: derived.scalarHex,
1274
+ privateAddressStpl1: derived.privateAddressStpl1,
1275
+ recipientHi: derived.recipientHi,
1276
+ recipientLo: derived.recipientLo,
1277
+ nonceDecimal: derived.nonceDecimal,
1278
+ tokenAddress: assetLegToTokenAddress(decrypted.assetHi, decrypted.assetLo),
1279
+ commitmentHex: padFieldHex(decrypted.commitmentHex)
955
1280
  };
956
1281
  }
957
- async function generateRandomDepositScalarHex() {
958
- await getPrivacyPoolService().getInitializedSdk();
959
- return PrivacyPoolSDK4.generateRandomScalarHex32();
1282
+
1283
+ // src/transact/escrow/prepare-escrow-sweep.ts
1284
+ import { StrKey as StrKey5 } from "@stellar/stellar-sdk";
1285
+ var PRIVATE_DISCLOSURE = {
1286
+ senderAddress: "private",
1287
+ recipientAddress: "private",
1288
+ assetAddress: "private",
1289
+ amount: "private"
1290
+ };
1291
+ function requireRegisteredPrivateAddress(value) {
1292
+ const trimmed = value.trim();
1293
+ if (!trimmed || StrKey5.isValidEd25519PublicKey(trimmed)) {
1294
+ throw new Error("Escrow sweep recipient must be a registered private address.");
1295
+ }
1296
+ return trimmed;
960
1297
  }
961
- function buildOnboardingPayload(parameters) {
962
- const notes = parameters.recipientNotes.map((coin) => coinToPlaintextNote(coin));
963
- const temporaryDecoded = decodePrivateAddress(
964
- parameters.temporaryKey.temporaryPrivateAddressStpl1.trim()
965
- );
966
- let privateAddressRegistration = noneOptionalRegistration();
967
- if (parameters.permanentPrivateAddressStpl1?.trim()) {
968
- const decoded = decodePrivateAddress(
969
- parameters.permanentPrivateAddressStpl1.trim()
970
- );
971
- const registration = {
972
- owner: parameters.ownerStellarAddress.trim(),
973
- public_key_x: Buffer9.from(decoded.x.padStart(COORDINATE_HEX_LENGTH2, "0"), "hex"),
974
- public_key_y: Buffer9.from(decoded.y.padStart(COORDINATE_HEX_LENGTH2, "0"), "hex")
975
- };
976
- privateAddressRegistration = { tag: "Some", values: [registration] };
1298
+ function consumedEscrowRecord(input) {
1299
+ return {
1300
+ id: input.reconstructed.commitmentHex,
1301
+ owner: input.walletPublicKey,
1302
+ asset: input.asset,
1303
+ amount: BigInt(input.reconstructed.coin.value),
1304
+ consumed: false,
1305
+ status: "finalized",
1306
+ poolContract: input.poolContract,
1307
+ coinNote: input.reconstructed.coin,
1308
+ privateAddress: input.reconstructed.privateAddressStpl1,
1309
+ commitmentHex: input.reconstructed.commitmentHex
1310
+ };
1311
+ }
1312
+ function attachEscrowAuthorization(prepared, escrowAuthorization) {
1313
+ const credential = escrowAuthorization.trim();
1314
+ if (!credential) {
1315
+ throw new Error("Escrow sweep requires a signed authorization entry.");
977
1316
  }
978
1317
  return {
979
- owner: parameters.ownerStellarAddress.trim(),
980
- temp_public_key_x: Buffer9.from(
981
- temporaryDecoded.x.padStart(COORDINATE_HEX_LENGTH2, "0"),
982
- "hex"
983
- ),
984
- temp_public_key_y: Buffer9.from(
985
- temporaryDecoded.y.padStart(COORDINATE_HEX_LENGTH2, "0"),
986
- "hex"
987
- ),
988
- encrypted_private_key: Buffer9.from(
989
- parameters.temporaryKey.temporaryScalarHex,
990
- "utf8"
991
- ),
992
- notes: { notes },
993
- private_address_registration: privateAddressRegistration
1318
+ ...prepared,
1319
+ transactArtifacts: {
1320
+ ...prepared.transactArtifacts,
1321
+ escrowAuthorization: credential
1322
+ }
994
1323
  };
995
1324
  }
996
- async function buildTransferOnboardingAtExecute(input) {
997
- return buildOnboardingPayload({
998
- ownerStellarAddress: input.ownerStellarAddress,
999
- temporaryKey: {
1000
- temporaryScalarHex: input.temporaryRecipientKey.temporaryScalarHex,
1001
- temporaryPrivateAddressStpl1: input.temporaryRecipientKey.temporaryPrivateAddressStpl1
1325
+ function sweepTransactArtifacts(input) {
1326
+ return {
1327
+ spendSource: "escrow",
1328
+ escrowRecipient: input.claimantAddress.trim(),
1329
+ escrowSpendScalarHex: input.reconstructed.scalarHex,
1330
+ escrowClaimantLimbs: {
1331
+ recipientHi: input.reconstructed.recipientHi,
1332
+ recipientLo: input.reconstructed.recipientLo,
1333
+ nonceDecimal: input.reconstructed.nonceDecimal
1002
1334
  },
1003
- recipientNotes: [input.recipientNote]
1335
+ executeFinalizeRequired: true,
1336
+ walletPublicKey: input.walletPublicKey
1337
+ };
1338
+ }
1339
+ function prepareEscrowSweepOperation(input) {
1340
+ assertEscrowSweepClaimant({
1341
+ walletPublicKey: input.walletPublicKey,
1342
+ claimantAddress: input.claimantAddress
1004
1343
  });
1344
+ const walletPublicKey = input.walletPublicKey.trim();
1345
+ const registeredPrivateAddress = requireRegisteredPrivateAddress(
1346
+ input.registeredPrivateAddress
1347
+ );
1348
+ const amount = BigInt(input.reconstructed.coin.value);
1349
+ return {
1350
+ kind: "transfer",
1351
+ intent: {
1352
+ from: input.reconstructed.privateAddressStpl1,
1353
+ to: registeredPrivateAddress,
1354
+ asset: input.asset,
1355
+ amount,
1356
+ disclosure: PRIVATE_DISCLOSURE
1357
+ },
1358
+ consumedRecords: [
1359
+ consumedEscrowRecord({
1360
+ reconstructed: input.reconstructed,
1361
+ walletPublicKey,
1362
+ poolContract: input.poolContract,
1363
+ asset: input.asset
1364
+ })
1365
+ ],
1366
+ outputRecords: [],
1367
+ submissionPayload: { operationId: crypto.randomUUID(), signed: false },
1368
+ transactArtifacts: sweepTransactArtifacts({
1369
+ claimantAddress: input.claimantAddress,
1370
+ reconstructed: input.reconstructed,
1371
+ walletPublicKey
1372
+ })
1373
+ };
1374
+ }
1375
+
1376
+ // src/transact/escrow/fetch-output-note-events.ts
1377
+ import { Api } from "@stellar/stellar-sdk/rpc";
1378
+
1379
+ // src/rpc/soroban-transaction-meta.ts
1380
+ import { Address, StrKey as StrKey6 } from "@stellar/stellar-sdk";
1381
+ var TRANSACTION_META_SWITCH_SOROBAN_V3 = 3;
1382
+ var TRANSACTION_META_SWITCH_SOROBAN_V4 = 4;
1383
+ function pushSorobanV3ContractEvents(out, meta) {
1384
+ const soroban = meta.v3().sorobanMeta();
1385
+ if (!soroban) {
1386
+ return;
1387
+ }
1388
+ for (const event of soroban.events()) {
1389
+ out.push(event);
1390
+ }
1391
+ }
1392
+ function pushSorobanV4ContractEvents(out, meta) {
1393
+ const v4 = meta.v4();
1394
+ for (const txEvent of v4.events()) {
1395
+ out.push(txEvent.event());
1396
+ }
1397
+ for (const op of v4.operations()) {
1398
+ for (const event of op.events()) {
1399
+ out.push(event);
1400
+ }
1401
+ }
1402
+ }
1403
+ function collectContractEventsFromMeta(meta) {
1404
+ const out = [];
1405
+ const code = meta.switch();
1406
+ if (code === TRANSACTION_META_SWITCH_SOROBAN_V3) {
1407
+ pushSorobanV3ContractEvents(out, meta);
1408
+ }
1409
+ if (code === TRANSACTION_META_SWITCH_SOROBAN_V4) {
1410
+ pushSorobanV4ContractEvents(out, meta);
1411
+ }
1412
+ return out;
1413
+ }
1414
+
1415
+ // src/rpc/server.ts
1416
+ import { rpc } from "@stellar/stellar-sdk";
1417
+ function createStellarRpcServer(rpcUrl) {
1418
+ return new rpc.Server(rpcUrl.trim(), { allowHttp: true });
1419
+ }
1420
+
1421
+ // src/transact/escrow/parse-output-note-events.ts
1422
+ import { StrKey as StrKey7 } from "@stellar/stellar-sdk";
1423
+ var FIELD_BYTE_LENGTH = 32;
1424
+ var FIELD_HEX_LENGTH2 = 64;
1425
+ var CONTRACT_EVENT_BODY_V0 = 0;
1426
+ var OUTPUT_NOTE_TOPIC_COUNT = 3;
1427
+ function extractSymbol(value) {
1428
+ try {
1429
+ if (value.switch().name === "scvSymbol") {
1430
+ return value.sym().toString();
1431
+ }
1432
+ if (value.switch().name === "scvString") {
1433
+ return value.str().toString();
1434
+ }
1435
+ } catch {
1436
+ return void 0;
1437
+ }
1438
+ return void 0;
1439
+ }
1440
+ function readBytes(value) {
1441
+ if (!value) {
1442
+ return void 0;
1443
+ }
1444
+ try {
1445
+ if (value.switch().name !== "scvBytes") {
1446
+ return void 0;
1447
+ }
1448
+ return Buffer.from(value.bytes());
1449
+ } catch {
1450
+ return void 0;
1451
+ }
1452
+ }
1453
+ function readU32(value) {
1454
+ if (!value) {
1455
+ return void 0;
1456
+ }
1457
+ try {
1458
+ if (value.switch().name !== "scvU32") {
1459
+ return void 0;
1460
+ }
1461
+ return value.u32();
1462
+ } catch {
1463
+ return void 0;
1464
+ }
1465
+ }
1466
+ function fieldHex(bytes) {
1467
+ return bytes.toString("hex").padStart(FIELD_HEX_LENGTH2, "0");
1468
+ }
1469
+ function ciphertextLimbs(bytes) {
1470
+ if (bytes.length === 0 || bytes.length % FIELD_BYTE_LENGTH !== 0) {
1471
+ return [];
1472
+ }
1473
+ const limbs = [];
1474
+ for (let offset = 0; offset < bytes.length; offset += FIELD_BYTE_LENGTH) {
1475
+ limbs.push(fieldHex(bytes.subarray(offset, offset + FIELD_BYTE_LENGTH)));
1476
+ }
1477
+ return limbs;
1478
+ }
1479
+ function payloadMap(data) {
1480
+ const entries = /* @__PURE__ */ new Map();
1481
+ try {
1482
+ if (data.switch().name !== "scvMap") {
1483
+ return entries;
1484
+ }
1485
+ const mapped = data.map();
1486
+ if (!mapped) {
1487
+ return entries;
1488
+ }
1489
+ for (const entry of mapped) {
1490
+ const key = extractSymbol(entry.key());
1491
+ if (key) {
1492
+ entries.set(key, entry.val());
1493
+ }
1494
+ }
1495
+ } catch {
1496
+ return entries;
1497
+ }
1498
+ return entries;
1499
+ }
1500
+ function hashToBuffer(value) {
1501
+ return Buffer.isBuffer(value) ? value : void 0;
1502
+ }
1503
+ function eventContractId(event) {
1504
+ try {
1505
+ const contractId = hashToBuffer(event.contractId());
1506
+ if (!contractId) {
1507
+ return void 0;
1508
+ }
1509
+ return StrKey7.encodeContract(contractId);
1510
+ } catch {
1511
+ return void 0;
1512
+ }
1513
+ }
1514
+ function eventMatchesPool(event, poolAddress) {
1515
+ const contractId = eventContractId(event);
1516
+ return contractId === void 0 || contractId === poolAddress.trim();
1517
+ }
1518
+ function outputNoteEventBody(event) {
1519
+ if (event.type().name !== "contract") {
1520
+ return void 0;
1521
+ }
1522
+ const body = event.body();
1523
+ if (body.switch() !== CONTRACT_EVENT_BODY_V0) {
1524
+ return void 0;
1525
+ }
1526
+ return body.v0();
1527
+ }
1528
+ function outputNoteFromPayload(topics, payload) {
1529
+ const commitment = readBytes(topics[2]);
1530
+ const outputIndex = readU32(payload.get("output_index"));
1531
+ const ephemeralX = readBytes(payload.get("ephemeral_x"));
1532
+ const ephemeralY = readBytes(payload.get("ephemeral_y"));
1533
+ const ciphertextBytes = readBytes(payload.get("ciphertext"));
1534
+ const tag = readBytes(payload.get("tag"));
1535
+ const ciphertext = ciphertextBytes ? ciphertextLimbs(ciphertextBytes) : [];
1536
+ if (!commitment || outputIndex === void 0 || !ephemeralX || !ephemeralY || ciphertext.length === 0 || !tag) {
1537
+ return void 0;
1538
+ }
1539
+ return {
1540
+ outputIndex,
1541
+ commitmentHashHex: fieldHex(commitment),
1542
+ createdEphemeralKey: [fieldHex(ephemeralX), fieldHex(ephemeralY)],
1543
+ ciphertext,
1544
+ tag: fieldHex(tag)
1545
+ };
1546
+ }
1547
+ function parseEscrowOutputNoteEvent(event, poolAddress) {
1548
+ if (!eventMatchesPool(event, poolAddress)) {
1549
+ return void 0;
1550
+ }
1551
+ const v0 = outputNoteEventBody(event);
1552
+ const topics = v0?.topics();
1553
+ if (!v0 || !Array.isArray(topics) || topics.length < OUTPUT_NOTE_TOPIC_COUNT) {
1554
+ return void 0;
1555
+ }
1556
+ if (extractSymbol(topics[0]) !== "audit" || extractSymbol(topics[1]) !== "output_note") {
1557
+ return void 0;
1558
+ }
1559
+ return outputNoteFromPayload(topics, payloadMap(v0.data()));
1560
+ }
1561
+
1562
+ // src/transact/escrow/fetch-output-note-events.ts
1563
+ async function fetchEscrowOutputNoteEvents(input) {
1564
+ const txId = input.txId.trim();
1565
+ if (!txId) {
1566
+ throw new Error("Escrow output-note transaction id is missing.");
1567
+ }
1568
+ const response = await createStellarRpcServer(
1569
+ input.transactEnvironment.network.rpcUrl
1570
+ ).getTransaction(txId);
1571
+ if (response.status !== Api.GetTransactionStatus.SUCCESS) {
1572
+ throw new Error("Escrow output-note transaction was not found.");
1573
+ }
1574
+ const meta = response.resultMetaXdr;
1575
+ if (!meta) {
1576
+ return [];
1577
+ }
1578
+ const events = [];
1579
+ for (const event of collectContractEventsFromMeta(meta)) {
1580
+ const parsed = parseEscrowOutputNoteEvent(event, input.poolAddress);
1581
+ if (parsed) {
1582
+ events.push(parsed);
1583
+ }
1584
+ }
1585
+ return events;
1005
1586
  }
1006
1587
 
1588
+ // src/transact/escrow/simulate-escrow-authorization.ts
1589
+ import {
1590
+ Account,
1591
+ Address as Address3,
1592
+ Contract,
1593
+ nativeToScVal as nativeToScVal2,
1594
+ TransactionBuilder as TransactionBuilder2,
1595
+ rpc as rpc4
1596
+ } from "@stellar/stellar-sdk";
1597
+ import { Buffer as Buffer10 } from "buffer";
1598
+
1599
+ // src/transact/kyt/passage/inspect.ts
1600
+ import {
1601
+ layoutForKnownNonce,
1602
+ zeroBindingTagsInPublicSignals
1603
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
1604
+
1007
1605
  // src/transact/kyt/inspect-error.ts
1008
1606
  var KytInspectError = class extends Error {
1009
1607
  reasonCode;
@@ -1032,18 +1630,6 @@ function parseKytReasonCode(reasonCode) {
1032
1630
  };
1033
1631
  }
1034
1632
 
1035
- // src/contracts/contract-context.ts
1036
- function requireContractContext(environment) {
1037
- if (!environment || !("contractContext" in environment)) {
1038
- throw new Error("Contract context is not configured on the transact environment.");
1039
- }
1040
- const resolved = environment;
1041
- return resolved.contractContext;
1042
- }
1043
- function readPoolClientFactory(environment) {
1044
- return requireContractContext(environment).createPoolClient;
1045
- }
1046
-
1047
1633
  // src/transact/kyt/passage/poll.ts
1048
1634
  import "@stellar/stellar-sdk";
1049
1635
  var KYT_REGISTER_MAX_POLLS = 60;
@@ -1098,20 +1684,20 @@ async function waitForKytRegistration(parameters) {
1098
1684
  }
1099
1685
 
1100
1686
  // src/transact/kyt/passage/submit.ts
1101
- import { Buffer as Buffer10 } from "buffer";
1102
- import { Operation, TransactionBuilder, rpc as rpc2, xdr } from "@stellar/stellar-sdk";
1687
+ import { Buffer as Buffer9 } from "buffer";
1688
+ import { Operation, TransactionBuilder, rpc as rpc3, xdr as xdr3 } from "@stellar/stellar-sdk";
1103
1689
  var KYT_REGISTER_FEE_STROOPS = "1000000";
1104
1690
  var KYT_REGISTER_TIMEOUT_SECONDS = 300;
1105
1691
  function passageIdToScValue(passageId) {
1106
- return xdr.ScVal.scvBytes(Buffer10.from(passageId.replace(/^0x/, ""), "hex"));
1692
+ return xdr3.ScVal.scvBytes(Buffer9.from(passageId.replace(/^0x/, ""), "hex"));
1107
1693
  }
1108
1694
  function approvalSignatureToBytes(signature) {
1109
1695
  const clean = signature.trim();
1110
- return /^(0x)?[0-9a-fA-F]{128}$/.test(clean) ? Buffer10.from(clean.replace(/^0x/i, ""), "hex") : Buffer10.from(clean, "base64");
1696
+ return /^(0x)?[0-9a-fA-F]{128}$/.test(clean) ? Buffer9.from(clean.replace(/^0x/i, ""), "hex") : Buffer9.from(clean, "base64");
1111
1697
  }
1112
1698
  function signatureToScValue(signature) {
1113
1699
  const bytes = approvalSignatureToBytes(signature);
1114
- return xdr.ScVal.scvBytes(bytes);
1700
+ return xdr3.ScVal.scvBytes(bytes);
1115
1701
  }
1116
1702
  async function registerKytPassage(parameters) {
1117
1703
  const signTransaction = parameters.transactEnvironment.signTransaction;
@@ -1121,7 +1707,7 @@ async function registerKytPassage(parameters) {
1121
1707
  );
1122
1708
  }
1123
1709
  const kytRegistry = parameters.transactEnvironment.kyt.kytPassageRegistryContract;
1124
- const server = new rpc2.Server(parameters.sorobanRpcUrl, { allowHttp: true });
1710
+ const server = new rpc3.Server(parameters.sorobanRpcUrl, { allowHttp: true });
1125
1711
  const sourceAccount = await server.getAccount(parameters.owner);
1126
1712
  const transaction = new TransactionBuilder(sourceAccount, {
1127
1713
  fee: KYT_REGISTER_FEE_STROOPS,
@@ -1132,7 +1718,7 @@ async function registerKytPassage(parameters) {
1132
1718
  function: "register_passage",
1133
1719
  args: [
1134
1720
  passageIdToScValue(parameters.approval.passageId),
1135
- xdr.ScVal.scvU32(parameters.approval.expiresAtLedger),
1721
+ xdr3.ScVal.scvU32(parameters.approval.expiresAtLedger),
1136
1722
  signatureToScValue(parameters.approval.signature)
1137
1723
  ]
1138
1724
  })
@@ -1155,15 +1741,9 @@ async function registerKytPassage(parameters) {
1155
1741
  await waitForKytRegistration({ server, hash: result.hash });
1156
1742
  }
1157
1743
 
1158
- // src/transact/environment/zk-config-nonce.ts
1159
- var DEFAULT_ZK_CONFIG_NONCE = 0n;
1160
- function resolveZkConfigNonce(transactEnvironment) {
1161
- return transactEnvironment.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
1162
- }
1163
-
1164
1744
  // src/transact/kyt/passage/inspect.ts
1165
- function buildApplicationIdHints(applicationId) {
1166
- return [applicationId, applicationId, applicationId, applicationId];
1745
+ function buildApplicationIdHints2(applicationId, nAuditSlots) {
1746
+ return uniformApplicationIdHints(applicationId, nAuditSlots);
1167
1747
  }
1168
1748
  function buildNonce() {
1169
1749
  return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}`;
@@ -1191,37 +1771,61 @@ function throwKytInspectRejected(body) {
1191
1771
  ...parsed.address ? { detailAddress: parsed.address } : {}
1192
1772
  });
1193
1773
  }
1194
- async function requestKytPassageForPoolInteraction(input) {
1195
- const applicationId = resolvePoolApplicationId(
1196
- input.transactEnvironment.network.applicationId
1197
- );
1198
- const applicationIdsPlaintext = input.applicationIdsPlaintext ?? buildApplicationIdHints(applicationId);
1199
- const kytRegistry = input.transactEnvironment.kyt.kytPassageRegistryContract;
1200
- const currentLedger = await fetchCurrentLedger(input.sorobanRpcUrl);
1774
+ function inspectRequestHeaders(inspectAuthorization) {
1775
+ const token = inspectAuthorization?.trim();
1776
+ return {
1777
+ "content-type": "application/json",
1778
+ ...token ? { authorization: `Bearer ${token}` } : {}
1779
+ };
1780
+ }
1781
+ async function postKytInspect(input, applicationIdsPlaintext, zkConfigNonce, currentLedger) {
1201
1782
  const response = await fetch(
1202
1783
  `${input.transactEnvironment.kyt.apiBaseUrl}/kyt/passages/inspect`,
1203
1784
  {
1204
1785
  method: "POST",
1205
- headers: { "content-type": "application/json" },
1786
+ headers: inspectRequestHeaders(
1787
+ input.transactEnvironment.kyt.inspectAuthorization
1788
+ ),
1206
1789
  body: JSON.stringify(
1207
1790
  {
1208
1791
  owner: input.owner,
1209
1792
  poolContract: input.poolContract,
1210
- kytRegistry,
1793
+ kytRegistry: input.transactEnvironment.kyt.kytPassageRegistryContract,
1211
1794
  proofBytes: input.proofHex,
1212
- publicSignalsBytes: input.publicHex,
1795
+ publicSignalsBytes: zeroBindingTagsInPublicSignals(
1796
+ input.publicHex,
1797
+ zkConfigNonce
1798
+ ).toString("hex"),
1213
1799
  applicationIdsPlaintext,
1214
1800
  decryptedAuditSlots: input.decryptedAuditSlots,
1215
- onboarding: input.onboarding,
1216
1801
  nonce: buildNonce(),
1217
- zkConfigNonce: resolveZkConfigNonce(input.transactEnvironment),
1218
- currentLedger
1802
+ zkConfigNonce,
1803
+ currentLedger,
1804
+ ...input.ciphertextHex ? { ciphertextBytes: input.ciphertextHex } : {},
1805
+ ...input.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: input.outputNoteEphemeralScalars } : {}
1219
1806
  },
1220
1807
  kytJsonReplacer
1221
1808
  )
1222
1809
  }
1223
1810
  );
1224
- const body = await parseInspectResponse(response);
1811
+ return parseInspectResponse(response);
1812
+ }
1813
+ async function requestKytPassageForPoolInteraction(input) {
1814
+ const applicationId = resolvePoolApplicationId(
1815
+ input.transactEnvironment.network.applicationId
1816
+ );
1817
+ const zkConfigNonce = resolveZkConfigNonce(input.transactEnvironment);
1818
+ const applicationIdsPlaintext = input.applicationIdsPlaintext ?? buildApplicationIdHints2(
1819
+ applicationId,
1820
+ layoutForKnownNonce(zkConfigNonce).nAuditSlots
1821
+ );
1822
+ const currentLedger = await fetchCurrentLedger(input.sorobanRpcUrl);
1823
+ const body = await postKytInspect(
1824
+ input,
1825
+ applicationIdsPlaintext,
1826
+ zkConfigNonce,
1827
+ currentLedger
1828
+ );
1225
1829
  if (body.status !== "approved") {
1226
1830
  throwKytInspectRejected(body);
1227
1831
  }
@@ -1237,6 +1841,216 @@ async function requestKytPassageForPoolInteraction(input) {
1237
1841
  return body;
1238
1842
  }
1239
1843
 
1844
+ // src/transact/escrow/kyt-authorization-sc-value.ts
1845
+ import { nativeToScVal } from "@stellar/stellar-sdk";
1846
+ function kytAuthorizationScValue(parameters) {
1847
+ return nativeToScVal(
1848
+ {
1849
+ expiration_ledger: parameters.expirationLedger,
1850
+ signature: parameters.signature
1851
+ },
1852
+ {
1853
+ type: {
1854
+ expiration_ledger: ["symbol", "u32"],
1855
+ signature: ["symbol", "bytes"]
1856
+ }
1857
+ }
1858
+ );
1859
+ }
1860
+
1861
+ // src/transact/escrow/pick-escrow-authorization.ts
1862
+ import { Address as Address2 } from "@stellar/stellar-sdk";
1863
+ function credentialAddress(entry) {
1864
+ try {
1865
+ const credentials = entry.credentials();
1866
+ if (credentials.switch().name !== "sorobanCredentialsAddress") {
1867
+ return void 0;
1868
+ }
1869
+ return Address2.fromScAddress(credentials.address().address()).toString();
1870
+ } catch {
1871
+ return void 0;
1872
+ }
1873
+ }
1874
+ function pickUnsignedEscrowAuthorization(input) {
1875
+ const claimant = input.claimantAddress.trim();
1876
+ const match = input.auth.find((entry) => credentialAddress(entry) === claimant);
1877
+ if (!match) {
1878
+ throw new Error("Simulation did not return a claimant authorization entry.");
1879
+ }
1880
+ return match.toXDR("base64");
1881
+ }
1882
+
1883
+ // src/transact/escrow/simulate-escrow-authorization.ts
1884
+ var SIMULATE_FEE = "100";
1885
+ var SIMULATE_TIMEOUT_SECONDS = 30;
1886
+ var RECORD_NONROOT_AUTH = "record_allow_nonroot";
1887
+ function hexToBytes(hex) {
1888
+ return Buffer10.from(hex.replace(/^0x/iu, ""), "hex");
1889
+ }
1890
+ function optionalSweepCiphertext(artifacts) {
1891
+ return {
1892
+ ...artifacts?.ciphertextHex ? { ciphertextHex: artifacts.ciphertextHex } : {},
1893
+ ...artifacts?.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: artifacts.outputNoteEphemeralScalars } : {}
1894
+ };
1895
+ }
1896
+ function requireSweepArtifacts(prepared) {
1897
+ const artifacts = prepared.transactArtifacts;
1898
+ const proofHex = artifacts?.proofHex?.trim();
1899
+ const publicHex = artifacts?.publicHex?.trim();
1900
+ const escrowRecipient = artifacts?.escrowRecipient?.trim();
1901
+ if (!proofHex || !publicHex || !escrowRecipient) {
1902
+ throw new Error("Prepared sweep is missing proof, public signals, or claimant.");
1903
+ }
1904
+ return {
1905
+ proofHex,
1906
+ publicHex,
1907
+ escrowRecipient,
1908
+ ...optionalSweepCiphertext(artifacts)
1909
+ };
1910
+ }
1911
+ function requireRelayerPublicKey(value) {
1912
+ const relayerPublicKey = value.trim();
1913
+ if (!relayerPublicKey) {
1914
+ throw new Error("Escrow sweep simulation requires the relayer public key.");
1915
+ }
1916
+ return relayerPublicKey;
1917
+ }
1918
+ async function inspectRelayerSweepKyt(input) {
1919
+ const environment = input.transactEnvironment;
1920
+ return requestKytPassageForPoolInteraction({
1921
+ owner: input.relayerPublicKey,
1922
+ poolContract: environment.network.poolContract,
1923
+ proofHex: input.artifacts.proofHex,
1924
+ publicHex: input.artifacts.publicHex,
1925
+ ...input.artifacts.ciphertextHex ? { ciphertextHex: input.artifacts.ciphertextHex } : {},
1926
+ ...input.artifacts.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: input.artifacts.outputNoteEphemeralScalars } : {},
1927
+ ...input.prepared.transactArtifacts?.applicationIdsPlaintext ? {
1928
+ applicationIdsPlaintext: input.prepared.transactArtifacts.applicationIdsPlaintext
1929
+ } : {},
1930
+ networkPassphrase: environment.network.networkPassphrase,
1931
+ sorobanRpcUrl: environment.network.rpcUrl,
1932
+ transactEnvironment: environment
1933
+ });
1934
+ }
1935
+ async function simulateSweepAuthEntries(input) {
1936
+ const environment = input.transactEnvironment;
1937
+ const server = createStellarRpcServer(environment.network.rpcUrl);
1938
+ const account = await server.getAccount(input.relayerPublicKey);
1939
+ const operation = new Contract(environment.network.poolContract).call(
1940
+ "transact",
1941
+ new Address3(input.relayerPublicKey).toScVal(),
1942
+ nativeToScVal2(resolveZkConfigNonce(environment), { type: "u64" }),
1943
+ nativeToScVal2(hexToBytes(input.artifacts.proofHex), { type: "bytes" }),
1944
+ nativeToScVal2(hexToBytes(input.artifacts.publicHex), { type: "bytes" }),
1945
+ nativeToScVal2(hexToBytes(input.artifacts.ciphertextHex ?? ""), { type: "bytes" }),
1946
+ kytAuthorizationScValue({
1947
+ expirationLedger: input.approval.expiresAtLedger,
1948
+ signature: approvalSignatureToBytes(input.approval.signature)
1949
+ })
1950
+ );
1951
+ const built = new TransactionBuilder2(
1952
+ new Account(account.accountId(), account.sequenceNumber()),
1953
+ {
1954
+ fee: SIMULATE_FEE,
1955
+ networkPassphrase: environment.network.networkPassphrase
1956
+ }
1957
+ ).addOperation(operation).setTimeout(SIMULATE_TIMEOUT_SECONDS).build();
1958
+ const simulated = await server.simulateTransaction(
1959
+ built,
1960
+ { cpuInstructions: 0 },
1961
+ RECORD_NONROOT_AUTH
1962
+ );
1963
+ if (rpc4.Api.isSimulationError(simulated)) {
1964
+ throw new Error(`Escrow sweep authorization simulation failed: ${simulated.error}`);
1965
+ }
1966
+ return simulated.result?.auth ?? [];
1967
+ }
1968
+ async function unsignedEscrowAuthorizationForSweep(input) {
1969
+ const relayerPublicKey = requireRelayerPublicKey(input.relayerPublicKey);
1970
+ const artifacts = requireSweepArtifacts(input.prepared);
1971
+ const approval = await inspectRelayerSweepKyt({
1972
+ artifacts,
1973
+ prepared: input.prepared,
1974
+ transactEnvironment: input.transactEnvironment,
1975
+ relayerPublicKey
1976
+ });
1977
+ const auth = await simulateSweepAuthEntries({
1978
+ artifacts,
1979
+ transactEnvironment: input.transactEnvironment,
1980
+ relayerPublicKey,
1981
+ approval
1982
+ });
1983
+ return pickUnsignedEscrowAuthorization({
1984
+ auth,
1985
+ claimantAddress: artifacts.escrowRecipient
1986
+ });
1987
+ }
1988
+
1989
+ // src/transact/assets/load-browser.ts
1990
+ async function loadStellarBrowserAssets(input) {
1991
+ const cacheKey = input.cacheBust ? `?v=${Date.now()}` : "";
1992
+ const sdkWasm = await fetch(`${input.sdkWasmUrl}${cacheKey}`).then(
1993
+ (response) => response.arrayBuffer()
1994
+ );
1995
+ return { sdkWasm };
1996
+ }
1997
+ async function loadDefaultStellarBrowserAssets(options) {
1998
+ await import("@arcanetech/stellar-privacy-pool-zk-sdk");
1999
+ const sdkWasmUrl = new URL(
2000
+ "@arcanetech/stellar-privacy-pool-zk-sdk/sdk.wasm",
2001
+ import.meta.url
2002
+ ).href;
2003
+ return loadStellarBrowserAssets({
2004
+ sdkWasmUrl,
2005
+ ...options?.cacheBust ? { cacheBust: true } : {}
2006
+ });
2007
+ }
2008
+
2009
+ // src/transact/private-address/temporary-recipient.ts
2010
+ import { PrivacyPoolSDK as PrivacyPoolSDK3 } from "@arcanetech/stellar-privacy-pool-zk-sdk";
2011
+ var COORDINATE_HEX_LENGTH2 = 64;
2012
+ async function generateRandomDepositScalarHex() {
2013
+ await getPrivacyPoolService().getInitializedSdk();
2014
+ return PrivacyPoolSDK3.generateRandomScalarHex32();
2015
+ }
2016
+ async function generateTemporaryRecipientPrivateAddress() {
2017
+ await getPrivacyPoolService().getInitializedSdk();
2018
+ const temporaryScalarHex = PrivacyPoolSDK3.generateRandomScalarHex32();
2019
+ const sdk = await getPrivacyPoolService().getInitializedSdk();
2020
+ const point = sdk.ecdhEphemeralPublicKeyFromScalarHex(temporaryScalarHex);
2021
+ const publicKeyXHex = point.x.padStart(COORDINATE_HEX_LENGTH2, "0");
2022
+ const publicKeyYHex = point.y.padStart(COORDINATE_HEX_LENGTH2, "0");
2023
+ return {
2024
+ temporaryScalarHex,
2025
+ temporaryPrivateAddressStpl1: encodePrivateAddressFromHexCoordinates(
2026
+ publicKeyXHex,
2027
+ publicKeyYHex
2028
+ )
2029
+ };
2030
+ }
2031
+
2032
+ // src/contracts/contract-context.ts
2033
+ function requireContractContext(environment) {
2034
+ if (!environment || !("contractContext" in environment)) {
2035
+ throw new Error("Contract context is not configured on the transact environment.");
2036
+ }
2037
+ const resolved = environment;
2038
+ return resolved.contractContext;
2039
+ }
2040
+ function readPoolClientFactory(environment) {
2041
+ return requireContractContext(environment).createPoolClient;
2042
+ }
2043
+
2044
+ // src/transact/pool/proof-types.ts
2045
+ function ciphertextArtifactsFromProof(proof) {
2046
+ return {
2047
+ ...proof.ciphertext_hex === void 0 ? {} : { ciphertextHex: proof.ciphertext_hex },
2048
+ ...proof.output_note_ephemeral_scalars === void 0 ? {} : {
2049
+ outputNoteEphemeralScalars: [...proof.output_note_ephemeral_scalars]
2050
+ }
2051
+ };
2052
+ }
2053
+
1240
2054
  // src/transact/submit/ttl-preflight.ts
1241
2055
  function getNested(source, path) {
1242
2056
  let cursor = source;
@@ -1283,12 +2097,12 @@ async function runTtlPreflight(assembledTransaction) {
1283
2097
 
1284
2098
  // src/transact/submit/zk-config-ttl.ts
1285
2099
  import {
1286
- Address,
2100
+ Address as Address4,
1287
2101
  Operation as Operation2,
1288
2102
  SorobanDataBuilder,
1289
- TransactionBuilder as TransactionBuilder2,
1290
- rpc as rpc3,
1291
- xdr as xdr2
2103
+ TransactionBuilder as TransactionBuilder3,
2104
+ rpc as rpc5,
2105
+ xdr as xdr5
1292
2106
  } from "@stellar/stellar-sdk";
1293
2107
  var ZK_CONFIG_TTL_THRESHOLD_LEDGERS = 1e5;
1294
2108
  var ZK_CONFIG_TTL_EXTEND_TO_LEDGERS = 5e5;
@@ -1312,15 +2126,15 @@ async function waitForExtendFootprintTtlConfirmation(parameters) {
1312
2126
  throw new Error("ZK config TTL extension was not confirmed in time");
1313
2127
  }
1314
2128
  function zkConfigLedgerKey(contractId, nonce) {
1315
- const configKeyScValue = xdr2.ScVal.scvVec([
1316
- xdr2.ScVal.scvSymbol("Config"),
1317
- xdr2.ScVal.scvU64(xdr2.Uint64.fromString(nonce.toString()))
2129
+ const configKeyScValue = xdr5.ScVal.scvVec([
2130
+ xdr5.ScVal.scvSymbol("Config"),
2131
+ xdr5.ScVal.scvU64(xdr5.Uint64.fromString(nonce.toString()))
1318
2132
  ]);
1319
- return xdr2.LedgerKey.contractData(
1320
- new xdr2.LedgerKeyContractData({
1321
- contract: new Address(contractId).toScAddress(),
2133
+ return xdr5.LedgerKey.contractData(
2134
+ new xdr5.LedgerKeyContractData({
2135
+ contract: new Address4(contractId).toScAddress(),
1322
2136
  key: configKeyScValue,
1323
- durability: xdr2.ContractDataDurability.persistent()
2137
+ durability: xdr5.ContractDataDurability.persistent()
1324
2138
  })
1325
2139
  );
1326
2140
  }
@@ -1338,7 +2152,7 @@ async function needsTtlExtension(parameters) {
1338
2152
  }
1339
2153
  async function submitExtendFootprintTtlTransaction(parameters) {
1340
2154
  const sourceAccount = await parameters.server.getAccount(parameters.sourcePublicKey);
1341
- const transaction = new TransactionBuilder2(sourceAccount, {
2155
+ const transaction = new TransactionBuilder3(sourceAccount, {
1342
2156
  fee: EXTEND_TTL_FEE_STROOPS,
1343
2157
  networkPassphrase: parameters.networkPassphrase
1344
2158
  }).addOperation(
@@ -1352,7 +2166,7 @@ async function submitExtendFootprintTtlTransaction(parameters) {
1352
2166
  networkPassphrase: parameters.networkPassphrase,
1353
2167
  address: parameters.sourcePublicKey
1354
2168
  });
1355
- const signedTransaction = TransactionBuilder2.fromXDR(
2169
+ const signedTransaction = TransactionBuilder3.fromXDR(
1356
2170
  signedTxXdr,
1357
2171
  parameters.networkPassphrase
1358
2172
  );
@@ -1370,7 +2184,7 @@ async function extendZkConfigTtlIfNeeded(parameters) {
1370
2184
  if (!parameters.signTransaction) {
1371
2185
  return;
1372
2186
  }
1373
- const server = new rpc3.Server(parameters.sorobanRpcUrl, { allowHttp: true });
2187
+ const server = new rpc5.Server(parameters.sorobanRpcUrl, { allowHttp: true });
1374
2188
  const ledgerKey = zkConfigLedgerKey(parameters.contractId, parameters.nonce);
1375
2189
  if (!await needsTtlExtension({ server, ledgerKey })) {
1376
2190
  return;
@@ -1400,7 +2214,10 @@ async function submitPoolTransact(parameters) {
1400
2214
  nonce: parameters.nonce,
1401
2215
  proof_bytes: Buffer11.from(parameters.proofHex.replace(/^0x/iu, ""), "hex"),
1402
2216
  pub_signals_bytes: Buffer11.from(parameters.publicHex.replace(/^0x/iu, ""), "hex"),
1403
- onboarding: parameters.onboarding,
2217
+ ciphertext_bytes: Buffer11.from(
2218
+ (parameters.ciphertextHex ?? "").replace(/^0x/iu, ""),
2219
+ "hex"
2220
+ ),
1404
2221
  kyt_authorization: {
1405
2222
  expiration_ledger: parameters.approval.expiresAtLedger,
1406
2223
  signature: approvalSignatureToBytes(parameters.approval.signature)
@@ -1425,19 +2242,21 @@ async function submitSorobanDeposit(input) {
1425
2242
  });
1426
2243
  const merkleTx = await poolClient.get_merkle_root();
1427
2244
  const merkleRootBuffer = merkleTx.result;
1428
- const { applicationIdsPlaintext, proof_hex, public_hex } = await input.privacyPoolService.prepareDepositTransactProof({
2245
+ const proof = await input.privacyPoolService.prepareDepositTransactProof({
1429
2246
  privateAddressStpl1: input.privateAddressStpl1,
1430
2247
  coin: input.coin,
1431
2248
  depositScalarHex: input.depositScalarHex,
1432
2249
  merkleRootBytes: merkleRootBuffer,
1433
2250
  tokenAddress: input.tokenAddress
1434
2251
  });
2252
+ const ciphertext = ciphertextArtifactsFromProof(proof);
1435
2253
  const approval = await requestKytPassageForPoolInteraction({
1436
2254
  owner: input.walletPublicKey,
1437
2255
  poolContract: input.contractId,
1438
- proofHex: proof_hex,
1439
- publicHex: public_hex,
1440
- applicationIdsPlaintext,
2256
+ proofHex: proof.proof_hex,
2257
+ publicHex: proof.public_hex,
2258
+ applicationIdsPlaintext: proof.applicationIdsPlaintext,
2259
+ ...ciphertext,
1441
2260
  networkPassphrase: input.networkPassphrase,
1442
2261
  sorobanRpcUrl: input.sorobanRpcUrl,
1443
2262
  transactEnvironment: input.transactEnvironment
@@ -1447,8 +2266,9 @@ async function submitSorobanDeposit(input) {
1447
2266
  contractId: input.contractId,
1448
2267
  from: input.walletPublicKey,
1449
2268
  nonce: resolveZkConfigNonce(input.transactEnvironment),
1450
- proofHex: proof_hex,
1451
- publicHex: public_hex,
2269
+ proofHex: proof.proof_hex,
2270
+ publicHex: proof.public_hex,
2271
+ ...ciphertext,
1452
2272
  approval,
1453
2273
  networkPassphrase: input.networkPassphrase,
1454
2274
  sorobanRpcUrl: input.sorobanRpcUrl,
@@ -1469,7 +2289,8 @@ async function submitSorobanConfidentialTransfer(input) {
1469
2289
  poolContract: input.contractId,
1470
2290
  proofHex: input.proofHex,
1471
2291
  publicHex: input.publicHex,
1472
- ...input.onboarding ? { onboarding: input.onboarding } : {},
2292
+ ...input.ciphertextHex ? { ciphertextHex: input.ciphertextHex } : {},
2293
+ ...input.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: input.outputNoteEphemeralScalars } : {},
1473
2294
  ...input.applicationIdsPlaintext ? { applicationIdsPlaintext: input.applicationIdsPlaintext } : {},
1474
2295
  networkPassphrase: input.networkPassphrase,
1475
2296
  sorobanRpcUrl: input.sorobanRpcUrl,
@@ -1482,7 +2303,7 @@ async function submitSorobanConfidentialTransfer(input) {
1482
2303
  nonce: resolveZkConfigNonce(input.transactEnvironment),
1483
2304
  proofHex: input.proofHex,
1484
2305
  publicHex: input.publicHex,
1485
- ...input.onboarding ? { onboarding: input.onboarding } : {},
2306
+ ...input.ciphertextHex ? { ciphertextHex: input.ciphertextHex } : {},
1486
2307
  approval,
1487
2308
  networkPassphrase: input.networkPassphrase,
1488
2309
  sorobanRpcUrl: input.sorobanRpcUrl,
@@ -1490,14 +2311,19 @@ async function submitSorobanConfidentialTransfer(input) {
1490
2311
  });
1491
2312
  }
1492
2313
 
1493
- // src/transact/onboarding/recipient-change-deposits.ts
1494
- async function buildPaddingDepositPair(recipientPrivateAddressStpl1, tokenAddress, recipientDeposit) {
1495
- const paddingSlot = await getPrivacyPoolService().buildAlignedDepositSlot({
1496
- privateAddressStpl1: recipientPrivateAddressStpl1,
1497
- amountStroops: ZERO_STROOPS,
1498
- tokenAddress
1499
- });
1500
- return [recipientDeposit, paddingSlot.deposit];
2314
+ // src/transact/proofs/confidential/recipient-change-deposits.ts
2315
+ function escrowOutputFields(input) {
2316
+ if (!input.escrowSend) {
2317
+ return {};
2318
+ }
2319
+ return {
2320
+ escrowNonce: input.escrowSend.nonceDecimal,
2321
+ recipientHi: input.escrowSend.recipientHi,
2322
+ recipientLo: input.escrowSend.recipientLo
2323
+ };
2324
+ }
2325
+ function paddingDepositPair(recipientDeposit) {
2326
+ return [recipientDeposit, "dummy"];
1501
2327
  }
1502
2328
  async function buildChangeDepositPair(parameters) {
1503
2329
  const changeSlot = await getPrivacyPoolService().buildAlignedDepositSlot({
@@ -1516,24 +2342,24 @@ async function buildChangeDepositPair(parameters) {
1516
2342
  };
1517
2343
  }
1518
2344
  async function buildRecipientAndOptionalChangeDeposits(parameters) {
2345
+ const escrow = {
2346
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
2347
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
2348
+ };
1519
2349
  const recipientPrivateAddress = parameters.recipientPrivateAddressStpl1.trim();
1520
2350
  const recipientSlot = await getPrivacyPoolService().buildAlignedDepositSlot({
1521
2351
  privateAddressStpl1: recipientPrivateAddress,
1522
2352
  amountStroops: parameters.transferStroops,
1523
- tokenAddress: parameters.tokenAddress
2353
+ tokenAddress: parameters.tokenAddress,
2354
+ ...escrowOutputFields(escrow)
1524
2355
  });
1525
2356
  if (parameters.changeStroops <= ZERO_STROOPS) {
1526
2357
  return {
1527
2358
  recipientSlot,
1528
- deposits: await buildPaddingDepositPair(
1529
- recipientPrivateAddress,
1530
- parameters.tokenAddress,
1531
- recipientSlot.deposit
1532
- )
2359
+ deposits: paddingDepositPair(recipientSlot.deposit)
1533
2360
  };
1534
2361
  }
1535
2362
  const changeResult = await buildChangeDepositPair({
1536
- recipientPrivateAddressStpl1: recipientPrivateAddress,
1537
2363
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
1538
2364
  changeStroops: parameters.changeStroops,
1539
2365
  tokenAddress: parameters.tokenAddress,
@@ -1555,20 +2381,61 @@ function generatedOutputCoinFromSlot(slot) {
1555
2381
  precommitementHex: slot.precommitementHex
1556
2382
  };
1557
2383
  }
2384
+ function publicEscrowRecipientLimbs(parameters) {
2385
+ const limbs = parameters.escrowClaimantLimbs;
2386
+ if (!limbs) {
2387
+ return void 0;
2388
+ }
2389
+ return {
2390
+ escrowRecipientHi: limbs.recipientHi,
2391
+ escrowRecipientLo: limbs.recipientLo
2392
+ };
2393
+ }
2394
+ function sweepWithdrawStamp(parameters) {
2395
+ const publicLimbs = publicEscrowRecipientLimbs(parameters);
2396
+ if (!publicLimbs) {
2397
+ return void 0;
2398
+ }
2399
+ return {
2400
+ ...publicLimbs,
2401
+ ...parameters.escrowClaimantLimbs?.nonceDecimal ? { escrowNonce: parameters.escrowClaimantLimbs.nonceDecimal } : {}
2402
+ };
2403
+ }
2404
+ function stampWithdrawEscrowLimbs(withdrawObject, limbs) {
2405
+ if (!limbs) {
2406
+ return withdrawObject;
2407
+ }
2408
+ return {
2409
+ ...withdrawObject,
2410
+ recipientStellar: [limbs.escrowRecipientHi, limbs.escrowRecipientLo],
2411
+ ...limbs.escrowNonce ? { escrowNonce: limbs.escrowNonce } : {}
2412
+ };
2413
+ }
2414
+ function sweepOutputOwnerFields(parameters) {
2415
+ if (!parameters.escrowClaimantLimbs) {
2416
+ return void 0;
2417
+ }
2418
+ const [sweepOutputOwnerPubX, sweepOutputOwnerPubY] = recipientPublicKeysDecimalFromPrivateAddress(
2419
+ parameters.recipientPrivateAddressStpl1
2420
+ );
2421
+ return { sweepOutputOwnerPubX, sweepOutputOwnerPubY };
2422
+ }
1558
2423
  async function buildTransferDepositsAndPublicInput(parameters) {
1559
2424
  const { recipientSlot, deposits, changeCoin } = await buildRecipientAndOptionalChangeDeposits({
1560
2425
  recipientPrivateAddressStpl1: parameters.recipientPrivateAddressStpl1,
1561
2426
  transferStroops: parameters.transferStroops,
1562
2427
  changeStroops: parameters.changeStroops,
1563
2428
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
1564
- tokenAddress: parameters.tokenAddress
2429
+ tokenAddress: parameters.tokenAddress,
2430
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
2431
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
1565
2432
  });
1566
2433
  const publicInput = withTokenAddressPublicInputs(
1567
2434
  {
1568
2435
  stateRoot: parameters.stateRoot,
1569
- withdrawAddressHi: parameters.withdrawAddressHi,
1570
- withdrawAddressLo: parameters.withdrawAddressLo,
1571
- privKeyScalar: parameters.privKeyScalar
2436
+ privKeyScalar: parameters.privKeyScalar,
2437
+ ...publicEscrowRecipientLimbs(parameters),
2438
+ ...sweepOutputOwnerFields(parameters)
1572
2439
  },
1573
2440
  parameters.tokenAddress
1574
2441
  );
@@ -1580,10 +2447,6 @@ async function buildTransferDepositsAndPublicInput(parameters) {
1580
2447
  };
1581
2448
  }
1582
2449
  async function buildSenderTransferDepositsAndPublicInput(parameters) {
1583
- const { hi, lo, privKeyScalar } = senderWithdrawFrAndScalar({
1584
- senderGAddress: parameters.senderGAddress,
1585
- senderPrivKeyScalarHex: parameters.senderPrivKeyScalarHex
1586
- });
1587
2450
  return buildTransferDepositsAndPublicInput({
1588
2451
  recipientPrivateAddressStpl1: parameters.recipientPrivateAddressStpl1,
1589
2452
  transferStroops: parameters.transferStroops,
@@ -1591,31 +2454,55 @@ async function buildSenderTransferDepositsAndPublicInput(parameters) {
1591
2454
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
1592
2455
  tokenAddress: parameters.tokenAddress,
1593
2456
  stateRoot: parameters.stateRoot,
1594
- withdrawAddressHi: hi,
1595
- withdrawAddressLo: lo,
1596
- privKeyScalar
2457
+ privKeyScalar: privKeyScalarDecimalFromRecipientScalarHex(
2458
+ parameters.senderPrivKeyScalarHex
2459
+ ),
2460
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
2461
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
1597
2462
  });
1598
2463
  }
1599
2464
 
1600
2465
  // src/transact/proofs/confidential/dual.ts
1601
- function buildDualTransferApplicationIds(applicationId, changeCoin) {
1602
- return [
1603
- applicationId,
1604
- applicationId,
1605
- applicationId,
1606
- changeCoin ? applicationId : "0"
1607
- ];
2466
+ function confidentialEscrowFields(parameters) {
2467
+ return {
2468
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
2469
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
2470
+ };
2471
+ }
2472
+ function stampDualWithdrawLegs(legs, parameters) {
2473
+ const escrowLimbs = sweepWithdrawStamp(confidentialEscrowFields(parameters));
2474
+ return {
2475
+ legA: {
2476
+ ...legs.legA,
2477
+ withdrawObject: stampWithdrawEscrowLimbs(legs.legA.withdrawObject, escrowLimbs)
2478
+ },
2479
+ legB: {
2480
+ ...legs.legB,
2481
+ withdrawObject: stampWithdrawEscrowLimbs(legs.legB.withdrawObject, escrowLimbs)
2482
+ }
2483
+ };
2484
+ }
2485
+ function buildDualTransferApplicationIds(sdk, applicationId, changeCoin) {
2486
+ return buildApplicationIdHints({
2487
+ sdk,
2488
+ inputIds: [applicationId, applicationId],
2489
+ outputIds: [applicationId, changeCoin ? applicationId : "0"]
2490
+ });
1608
2491
  }
1609
2492
  async function proveDualConfidentialTransfer(parameters) {
1610
2493
  const audit = buildPoolTransactionAuditParameters({
1611
2494
  applicationId: parameters.applicationId,
2495
+ nAuditSlots: parameters.sdk.getLayout().nAuditSlots,
1612
2496
  ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
1613
2497
  });
1614
2498
  return parameters.sdk.proveTransaction(
1615
2499
  parameters.publicInput,
1616
- buildZeroPublicLegs(),
1617
- [parameters.legA.withdrawObject, parameters.legB.withdrawObject],
1618
- parameters.deposits,
2500
+ padPublicLegsToLayout(parameters.sdk, buildZeroPublicLegs()),
2501
+ padWithdrawSlotsToLayout(parameters.sdk, [
2502
+ parameters.legA.withdrawObject,
2503
+ parameters.legB.withdrawObject
2504
+ ]),
2505
+ padDepositSlotsToLayout(parameters.sdk, parameters.deposits),
1619
2506
  audit
1620
2507
  );
1621
2508
  }
@@ -1629,24 +2516,33 @@ async function buildDualTransferProofContext(parameters, applicationId, sdk) {
1629
2516
  changeStroops,
1630
2517
  parameters.selfPrivateAddressStpl1ForChange
1631
2518
  );
1632
- const { legA, legB } = dualWithdrawLegsWithSharedRoot({
1633
- sdk,
1634
- coinA: parameters.coinA,
1635
- coinB: parameters.coinB,
1636
- state: parameters.state,
1637
- ephemeralA: parseEphemeralKeyString(parameters.ephemeralAKey),
1638
- ephemeralB: parseEphemeralKeyString(parameters.ephemeralBKey),
1639
- applicationId
1640
- });
2519
+ const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
2520
+ parameters.senderPrivKeyScalarHex
2521
+ );
2522
+ const ownerPubHex = sdk.ecdhEphemeralPublicKeyFromScalarHex(
2523
+ parameters.senderPrivKeyScalarHex
2524
+ );
2525
+ const { legA, legB } = stampDualWithdrawLegs(
2526
+ dualWithdrawLegsWithSharedRoot({
2527
+ sdk,
2528
+ coinA: parameters.coinA,
2529
+ coinB: parameters.coinB,
2530
+ state: parameters.state,
2531
+ ownerPubHex,
2532
+ privKeyScalar,
2533
+ applicationId
2534
+ }),
2535
+ parameters
2536
+ );
1641
2537
  const transferInputs = await buildSenderTransferDepositsAndPublicInput({
1642
- senderGAddress: parameters.senderGAddress,
1643
2538
  senderPrivKeyScalarHex: parameters.senderPrivKeyScalarHex,
1644
2539
  recipientPrivateAddressStpl1: parameters.recipientPrivateAddressStpl1,
1645
2540
  transferStroops: parameters.transferStroops,
1646
2541
  changeStroops,
1647
2542
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
1648
2543
  tokenAddress: parameters.tokenAddress,
1649
- stateRoot: legA.witness.stateRoot
2544
+ stateRoot: legA.witness.stateRoot,
2545
+ ...confidentialEscrowFields(parameters)
1650
2546
  });
1651
2547
  return { legA, legB, applicationId, ...transferInputs };
1652
2548
  }
@@ -1674,7 +2570,11 @@ async function prepareConfidentialTransferProofDual(parameters) {
1674
2570
  }));
1675
2571
  return {
1676
2572
  ...proof,
1677
- applicationIdsPlaintext: buildDualTransferApplicationIds(applicationId, changeCoin),
2573
+ applicationIdsPlaintext: buildDualTransferApplicationIds(
2574
+ sdk,
2575
+ applicationId,
2576
+ changeCoin
2577
+ ),
1678
2578
  recipientCoin: generatedOutputCoinFromSlot(recipientSlot),
1679
2579
  ...changeCoin ? { changeCoin } : {}
1680
2580
  };
@@ -1692,51 +2592,72 @@ function validateSingleCoinTransferAmounts(transferStroops, noteStroops, selfPri
1692
2592
  requireChangeRecipientWhenPartial(changeStroops, selfPrivateAddressStpl1ForChange);
1693
2593
  return changeStroops;
1694
2594
  }
1695
- function buildSingleTransferApplicationIds(applicationId, changeCoin) {
1696
- return [applicationId, "0", applicationId, changeCoin ? applicationId : "0"];
2595
+ function buildSingleTransferApplicationIds(sdk, applicationId, changeCoin) {
2596
+ return buildApplicationIdHints({
2597
+ sdk,
2598
+ inputIds: [applicationId],
2599
+ outputIds: [applicationId, changeCoin ? applicationId : "0"]
2600
+ });
1697
2601
  }
1698
2602
  function buildTransferAuditParameters(parameters) {
1699
2603
  const auditPublicKey = parameters.poolService.getAuditPublicKey();
1700
2604
  return buildPoolTransactionAuditParameters({
1701
2605
  applicationId: parameters.applicationId,
2606
+ nAuditSlots: parameters.nAuditSlots,
1702
2607
  ...auditPublicKey ? { auditPublicKey } : {}
1703
2608
  });
1704
2609
  }
1705
2610
  async function proveTransaction(parameters) {
1706
2611
  return parameters.sdk.proveTransaction(
1707
2612
  parameters.publicInput,
1708
- buildZeroPublicLegs(),
1709
- [parameters.withdrawObject, "dummy"],
1710
- parameters.deposits,
2613
+ padPublicLegsToLayout(parameters.sdk, buildZeroPublicLegs()),
2614
+ padWithdrawSlotsToLayout(parameters.sdk, [parameters.withdrawObject]),
2615
+ padDepositSlotsToLayout(parameters.sdk, parameters.deposits),
1711
2616
  parameters.audit
1712
2617
  );
1713
2618
  }
2619
+ function confidentialEscrowFields2(input) {
2620
+ return {
2621
+ ...input.escrowSend ? { escrowSend: input.escrowSend } : {},
2622
+ ...input.escrowClaimantLimbs ? { escrowClaimantLimbs: input.escrowClaimantLimbs } : {}
2623
+ };
2624
+ }
1714
2625
  async function buildTransferProofInputs(parameters) {
1715
2626
  const changeStroops = validateSingleCoinTransferAmounts(
1716
2627
  parameters.input.transferStroops,
1717
2628
  parameters.noteStroops,
1718
2629
  parameters.input.selfPrivateAddressStpl1ForChange
1719
2630
  );
2631
+ const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
2632
+ parameters.input.senderPrivKeyScalarHex
2633
+ );
1720
2634
  const { witness, withdrawObject } = withdrawWitnessForCoin({
1721
2635
  sdk: parameters.sdk,
1722
2636
  coin: parameters.input.coin,
1723
2637
  state: parameters.input.state,
1724
- ...parseEphemeralKeyString(parameters.input.depositorEphemeralKey),
2638
+ ownerPubHex: parameters.sdk.ecdhEphemeralPublicKeyFromScalarHex(
2639
+ parameters.input.senderPrivKeyScalarHex
2640
+ ),
2641
+ privKeyScalar,
1725
2642
  applicationId: parameters.applicationId
1726
2643
  });
2644
+ const stampedWithdraw = stampWithdrawEscrowLimbs(
2645
+ withdrawObject,
2646
+ sweepWithdrawStamp(confidentialEscrowFields2(parameters.input))
2647
+ );
1727
2648
  const { recipientSlot, deposits, changeCoin, publicInput } = await buildSenderTransferDepositsAndPublicInput({
1728
- senderGAddress: parameters.input.senderGAddress,
1729
2649
  senderPrivKeyScalarHex: parameters.input.senderPrivKeyScalarHex,
1730
2650
  recipientPrivateAddressStpl1: parameters.input.recipientPrivateAddressStpl1,
1731
2651
  transferStroops: parameters.input.transferStroops,
1732
2652
  changeStroops,
1733
2653
  selfPrivateAddressStpl1ForChange: parameters.input.selfPrivateAddressStpl1ForChange,
1734
2654
  tokenAddress: parameters.input.tokenAddress,
1735
- stateRoot: witness.stateRoot
2655
+ stateRoot: witness.stateRoot,
2656
+ ...confidentialEscrowFields2(parameters.input)
1736
2657
  });
1737
2658
  return {
1738
2659
  witness,
1739
- withdrawObject,
2660
+ withdrawObject: stampedWithdraw,
1740
2661
  recipientSlot,
1741
2662
  deposits,
1742
2663
  changeCoin,
@@ -1754,7 +2675,11 @@ async function prepareConfidentialTransferProof(parameters) {
1754
2675
  input: parameters,
1755
2676
  noteStroops
1756
2677
  });
1757
- const audit = buildTransferAuditParameters({ poolService, applicationId });
2678
+ const audit = buildTransferAuditParameters({
2679
+ poolService,
2680
+ applicationId,
2681
+ nAuditSlots: sdk.getLayout().nAuditSlots
2682
+ });
1758
2683
  const proof = await proveTransaction({
1759
2684
  sdk,
1760
2685
  publicInput,
@@ -1765,6 +2690,7 @@ async function prepareConfidentialTransferProof(parameters) {
1765
2690
  return {
1766
2691
  ...proof,
1767
2692
  applicationIdsPlaintext: buildSingleTransferApplicationIds(
2693
+ sdk,
1768
2694
  applicationId,
1769
2695
  changeCoin
1770
2696
  ),
@@ -1896,12 +2822,25 @@ async function readLeafEphemeralHex(parameters) {
1896
2822
  return { xHex, yHex };
1897
2823
  }
1898
2824
 
2825
+ // src/transact/encoding/fr-decimal-to-bytes.ts
2826
+ var BN254_SCALAR_MOD = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
2827
+ var FIELD_BYTE_LENGTH2 = 32;
2828
+ var BYTE_MASK = 0xffn;
2829
+ var BITS_PER_BYTE = 8n;
2830
+ function frDecimalToPaddedBytes32(decimal) {
2831
+ let value = BigInt(decimal.trim());
2832
+ value = (value % BN254_SCALAR_MOD + BN254_SCALAR_MOD) % BN254_SCALAR_MOD;
2833
+ const bytes = Buffer.alloc(FIELD_BYTE_LENGTH2);
2834
+ for (let index = FIELD_BYTE_LENGTH2 - 1; index >= 0; index -= 1) {
2835
+ bytes[index] = Number(value & BYTE_MASK);
2836
+ value >>= BITS_PER_BYTE;
2837
+ }
2838
+ return bytes;
2839
+ }
2840
+
1899
2841
  // src/state/foundation/paths.ts
1900
2842
  var STELLAR_STATE_PATHS = {
1901
2843
  privateRecords: "$.privateRecords",
1902
- pendingClaimsItems: "$.pendingClaims.items",
1903
- pendingClaimsPagination: "$.pendingClaims.pagination",
1904
- pendingClaimsCountByOwner: "$.pendingClaims.countByOwner",
1905
2844
  registryPrivateAddresses: "$.registry.privateAddresses",
1906
2845
  registryRegisteredAddresses: "$.registry.registeredAddresses",
1907
2846
  registryLookups: "$.registry.lookups",
@@ -1921,25 +2860,6 @@ var STELLAR_STATE_PATHS = {
1921
2860
 
1922
2861
  // src/state/schemas/shared.ts
1923
2862
  import { z } from "zod";
1924
- var pendingClaimSchema = z.object({
1925
- id: z.string().min(1),
1926
- owner: z.string().min(1),
1927
- asset: z.string().min(1),
1928
- amount: z.coerce.bigint(),
1929
- createdAt: z.string().min(1),
1930
- poolTxId: z.string().optional(),
1931
- commitmentHex: z.string().optional(),
1932
- nullifierHex: z.string().optional(),
1933
- futureNullifierHashHex: z.string().optional(),
1934
- assetHiHex: z.string().optional(),
1935
- assetLoHex: z.string().optional(),
1936
- nullifierFieldHex: z.string().optional(),
1937
- secretHex: z.string().optional(),
1938
- tempPublicKeyXHex: z.string().optional(),
1939
- tempPublicKeyYHex: z.string().optional(),
1940
- encryptedRecoveryBase64: z.string().optional(),
1941
- createdAtLedger: z.number().int().optional()
1942
- });
1943
2863
  var paginationSchema = z.object({
1944
2864
  total: z.number().int().nonnegative(),
1945
2865
  page: z.number().int().positive(),
@@ -2109,26 +3029,6 @@ function normalizePublicBalancesFromEntries(value, owner) {
2109
3029
  }).filter((balance) => balance !== void 0);
2110
3030
  }
2111
3031
 
2112
- // src/state/read/normalize/claims.ts
2113
- function normalizePendingClaimsState(value) {
2114
- if (typeof value !== "object" || value === null) {
2115
- return { items: [] };
2116
- }
2117
- const record = value;
2118
- const items = Array.isArray(record.items) ? record.items.flatMap((item) => {
2119
- const parsed = pendingClaimSchema.safeParse(item);
2120
- return parsed.success ? [withoutUndefinedFields(parsed.data)] : [];
2121
- }) : [];
2122
- const paginationResult = paginationSchema.safeParse(record.pagination);
2123
- if (paginationResult.success) {
2124
- return { items, pagination: paginationResult.data };
2125
- }
2126
- return { items };
2127
- }
2128
- function normalizePendingClaimsCount(value) {
2129
- return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
2130
- }
2131
-
2132
3032
  // src/state/read/normalize/deliveries.ts
2133
3033
  function normalizeIncomingDeliveries(value) {
2134
3034
  const entries = typeof value === "object" && value !== null && !Array.isArray(value) ? Object.values(value) : value;
@@ -2251,8 +3151,7 @@ import { registerArrayFilterItemSchema } from "@arcanetech/privacy-sdk-core/stat
2251
3151
 
2252
3152
  // src/state/filters/ops.ts
2253
3153
  var stellarArrayFilterSchemaKeys = {
2254
- privateRecord: "privateRecord",
2255
- pendingClaim: "pendingClaim"
3154
+ privateRecord: "privateRecord"
2256
3155
  };
2257
3156
  function rejectPrivateRecordsByIds(ids) {
2258
3157
  return {
@@ -2278,56 +3177,6 @@ function rejectConsumedPrivateRecords() {
2278
3177
  }
2279
3178
  };
2280
3179
  }
2281
- function rejectPendingClaimsByOwner(owner) {
2282
- return {
2283
- opType: "arrayFilter",
2284
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2285
- itemSchemaKey: stellarArrayFilterSchemaKeys.pendingClaim,
2286
- rejectWhen: {
2287
- op: "fieldEquals",
2288
- field: "owner",
2289
- value: owner
2290
- }
2291
- };
2292
- }
2293
- function rejectPendingClaimsByIds(ids) {
2294
- return {
2295
- opType: "arrayFilter",
2296
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2297
- itemSchemaKey: stellarArrayFilterSchemaKeys.pendingClaim,
2298
- rejectWhen: {
2299
- op: "fieldIn",
2300
- field: "id",
2301
- values: ids
2302
- }
2303
- };
2304
- }
2305
- function rejectPendingClaimsByOwnerAndAsset(input) {
2306
- const matches = [];
2307
- if (input.owner !== void 0) {
2308
- matches.push({
2309
- op: "fieldEquals",
2310
- field: "owner",
2311
- value: input.owner
2312
- });
2313
- }
2314
- if (input.asset !== void 0) {
2315
- matches.push({
2316
- op: "fieldEquals",
2317
- field: "asset",
2318
- value: input.asset
2319
- });
2320
- }
2321
- return {
2322
- opType: "arrayFilter",
2323
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2324
- itemSchemaKey: stellarArrayFilterSchemaKeys.pendingClaim,
2325
- rejectWhen: {
2326
- op: "and",
2327
- matches
2328
- }
2329
- };
2330
- }
2331
3180
 
2332
3181
  // src/state/filters/register-schemas.ts
2333
3182
  var registered = false;
@@ -2339,24 +3188,12 @@ function registerStellarArrayFilterSchemas() {
2339
3188
  stellarArrayFilterSchemaKeys.privateRecord,
2340
3189
  privateRecordSchema
2341
3190
  );
2342
- registerArrayFilterItemSchema(
2343
- stellarArrayFilterSchemaKeys.pendingClaim,
2344
- pendingClaimSchema
2345
- );
2346
3191
  registered = true;
2347
3192
  }
2348
3193
 
2349
3194
  // src/state/bridge/call-types.ts
2350
3195
  import "@arcanetech/privacy-sdk-core/state";
2351
3196
  var stellarStateCallTypes = {
2352
- pendingClaims: "pendingClaims",
2353
- clearPendingClaims: "clearPendingClaims",
2354
- readPendingClaims: "readPendingClaims",
2355
- replacePendingClaimsPage: "replacePendingClaimsPage",
2356
- upsertPendingClaims: "upsertPendingClaims",
2357
- removePendingClaims: "removePendingClaims",
2358
- setPendingClaimsCount: "setPendingClaimsCount",
2359
- readPendingClaimsCount: "readPendingClaimsCount",
2360
3197
  readStellarAddressRegistered: "readStellarAddressRegistered",
2361
3198
  readCachedPrivateAddress: "readCachedPrivateAddress",
2362
3199
  readRegistryLookup: "readRegistryLookup",
@@ -2583,194 +3420,10 @@ var stellarBalancesStateDefinitions = [
2583
3420
  }
2584
3421
  ];
2585
3422
 
2586
- // src/state/schemas/claims/write.ts
2587
- import { z as z5 } from "zod";
2588
- var pendingClaimsWriteSchema = z5.object({
2589
- type: z5.literal(stellarStateCallTypes.pendingClaims),
2590
- claims: z5.array(pendingClaimSchema),
2591
- paginationInfo: paginationSchema
2592
- }).transform(({ type, claims, paginationInfo }) => ({
2593
- type,
2594
- operations: [
2595
- {
2596
- opType: "arrayPush",
2597
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2598
- items: claims
2599
- },
2600
- {
2601
- opType: "primitiveSet",
2602
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsPagination,
2603
- value: paginationInfo
2604
- }
2605
- ]
2606
- }));
2607
- var clearPendingClaimsSchema = z5.object({
2608
- type: z5.literal(stellarStateCallTypes.clearPendingClaims),
2609
- owner: z5.string().optional(),
2610
- asset: z5.string().optional()
2611
- }).transform(({ type, owner, asset }) => {
2612
- if (owner === void 0 && asset === void 0) {
2613
- return {
2614
- type,
2615
- operations: [
2616
- {
2617
- opType: "arrayClean",
2618
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems
2619
- }
2620
- ]
2621
- };
2622
- }
2623
- return {
2624
- type,
2625
- operations: [rejectPendingClaimsByOwnerAndAsset({ owner, asset })]
2626
- };
2627
- });
2628
- var readPendingClaimsSchema = z5.object({
2629
- type: z5.literal(stellarStateCallTypes.readPendingClaims)
2630
- }).transform(({ type }) => ({
2631
- type,
2632
- operations: [
2633
- {
2634
- opType: "primitiveGet",
2635
- jsonPath: "$.pendingClaims"
2636
- }
2637
- ]
2638
- }));
2639
-
2640
- // src/state/schemas/claims/page.ts
2641
- import { z as z6 } from "zod";
2642
- var pendingClaimBridgeItemSchema = pendingClaimSchema;
2643
- var replacePendingClaimsPageSchema = z6.object({
2644
- type: z6.literal(stellarStateCallTypes.replacePendingClaimsPage),
2645
- owner: z6.string().min(1),
2646
- claims: z6.array(pendingClaimBridgeItemSchema),
2647
- paginationInfo: z6.object({
2648
- total: z6.number().int().nonnegative(),
2649
- page: z6.number().int().positive(),
2650
- pageSize: z6.number().int().positive(),
2651
- hasMore: z6.boolean()
2652
- }),
2653
- count: z6.number().int().nonnegative().optional()
2654
- }).transform(({ type, owner, claims, paginationInfo, count }) => ({
2655
- type,
2656
- operations: [
2657
- rejectPendingClaimsByOwner(owner),
2658
- {
2659
- opType: "arrayPush",
2660
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2661
- items: claims
2662
- },
2663
- {
2664
- opType: "primitiveSet",
2665
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsPagination,
2666
- value: paginationInfo
2667
- },
2668
- {
2669
- opType: "recordSet",
2670
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsCountByOwner,
2671
- key: owner,
2672
- value: count ?? paginationInfo.total
2673
- }
2674
- ]
2675
- }));
2676
- var upsertPendingClaimsSchema = z6.object({
2677
- type: z6.literal(stellarStateCallTypes.upsertPendingClaims),
2678
- claims: z6.array(pendingClaimBridgeItemSchema)
2679
- }).transform(({ type, claims }) => ({
2680
- type,
2681
- operations: [
2682
- rejectPendingClaimsByIds(claims.map((claim) => claim.id)),
2683
- {
2684
- opType: "arrayPush",
2685
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2686
- items: claims
2687
- }
2688
- ]
2689
- }));
2690
- var removePendingClaimsSchema = z6.object({
2691
- type: z6.literal(stellarStateCallTypes.removePendingClaims),
2692
- ids: z6.array(z6.string().min(1))
2693
- }).transform(({ type, ids }) => ({
2694
- type,
2695
- operations: [rejectPendingClaimsByIds(ids)]
2696
- }));
2697
- var readPendingClaimsCountSchema = z6.object({
2698
- type: z6.literal(stellarStateCallTypes.readPendingClaimsCount),
2699
- owner: z6.string().min(1)
2700
- }).transform(({ type, owner }) => ({
2701
- type,
2702
- operations: [
2703
- {
2704
- opType: "recordGet",
2705
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsCountByOwner,
2706
- key: owner
2707
- }
2708
- ]
2709
- }));
2710
- var setPendingClaimsCountSchema = z6.object({
2711
- type: z6.literal(stellarStateCallTypes.setPendingClaimsCount),
2712
- owner: z6.string().min(1),
2713
- count: z6.number().int().nonnegative()
2714
- }).transform(({ type, owner, count }) => ({
2715
- type,
2716
- operations: [
2717
- {
2718
- opType: "recordSet",
2719
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsCountByOwner,
2720
- key: owner,
2721
- value: count
2722
- }
2723
- ]
2724
- }));
2725
-
2726
- // src/state/definitions/claims.ts
2727
- var stellarClaimsStateDefinitions = [
2728
- {
2729
- type: stellarStateCallTypes.pendingClaims,
2730
- mode: "write",
2731
- schema: pendingClaimsWriteSchema
2732
- },
2733
- {
2734
- type: stellarStateCallTypes.clearPendingClaims,
2735
- mode: "write",
2736
- schema: clearPendingClaimsSchema
2737
- },
2738
- {
2739
- type: stellarStateCallTypes.readPendingClaims,
2740
- mode: "read",
2741
- schema: readPendingClaimsSchema
2742
- },
2743
- {
2744
- type: stellarStateCallTypes.replacePendingClaimsPage,
2745
- mode: "write",
2746
- schema: replacePendingClaimsPageSchema
2747
- },
2748
- {
2749
- type: stellarStateCallTypes.upsertPendingClaims,
2750
- mode: "write",
2751
- schema: upsertPendingClaimsSchema
2752
- },
2753
- {
2754
- type: stellarStateCallTypes.removePendingClaims,
2755
- mode: "write",
2756
- schema: removePendingClaimsSchema
2757
- },
2758
- {
2759
- type: stellarStateCallTypes.readPendingClaimsCount,
2760
- mode: "read",
2761
- schema: readPendingClaimsCountSchema
2762
- },
2763
- {
2764
- type: stellarStateCallTypes.setPendingClaimsCount,
2765
- mode: "write",
2766
- schema: setPendingClaimsCountSchema
2767
- }
2768
- ];
2769
-
2770
3423
  // src/state/schemas/claims/deliveries.ts
2771
- import { z as z7 } from "zod";
2772
- var readIncomingDeliveriesSchema = z7.object({
2773
- type: z7.literal(stellarStateCallTypes.readIncomingDeliveries)
3424
+ import { z as z5 } from "zod";
3425
+ var readIncomingDeliveriesSchema = z5.object({
3426
+ type: z5.literal(stellarStateCallTypes.readIncomingDeliveries)
2774
3427
  }).transform(({ type }) => ({
2775
3428
  type,
2776
3429
  operations: [
@@ -2780,9 +3433,9 @@ var readIncomingDeliveriesSchema = z7.object({
2780
3433
  }
2781
3434
  ]
2782
3435
  }));
2783
- var upsertIncomingDeliveriesSchema = z7.object({
2784
- type: z7.literal(stellarStateCallTypes.upsertIncomingDeliveries),
2785
- deliveries: z7.array(incomingDeliverySchema)
3436
+ var upsertIncomingDeliveriesSchema = z5.object({
3437
+ type: z5.literal(stellarStateCallTypes.upsertIncomingDeliveries),
3438
+ deliveries: z5.array(incomingDeliverySchema)
2786
3439
  }).transform(({ type, deliveries }) => ({
2787
3440
  type,
2788
3441
  operations: deliveries.map((delivery) => ({
@@ -2792,10 +3445,10 @@ var upsertIncomingDeliveriesSchema = z7.object({
2792
3445
  value: delivery
2793
3446
  }))
2794
3447
  }));
2795
- var readDeliverySyncStateSchema = z7.object({
2796
- type: z7.literal(stellarStateCallTypes.readDeliverySyncState),
2797
- privateAddress: z7.string().min(1),
2798
- asset: z7.string().min(1)
3448
+ var readDeliverySyncStateSchema = z5.object({
3449
+ type: z5.literal(stellarStateCallTypes.readDeliverySyncState),
3450
+ privateAddress: z5.string().min(1),
3451
+ asset: z5.string().min(1)
2799
3452
  }).transform(({ type, privateAddress, asset }) => ({
2800
3453
  type,
2801
3454
  operations: [
@@ -2806,8 +3459,8 @@ var readDeliverySyncStateSchema = z7.object({
2806
3459
  }
2807
3460
  ]
2808
3461
  }));
2809
- var setDeliverySyncStateSchema = z7.object({
2810
- type: z7.literal(stellarStateCallTypes.setDeliverySyncState),
3462
+ var setDeliverySyncStateSchema = z5.object({
3463
+ type: z5.literal(stellarStateCallTypes.setDeliverySyncState),
2811
3464
  syncState: deliverySyncStateSchema
2812
3465
  }).transform(({ type, syncState }) => ({
2813
3466
  type,
@@ -2846,10 +3499,10 @@ var stellarDeliveriesStateDefinitions = [
2846
3499
  ];
2847
3500
 
2848
3501
  // src/state/schemas/pool/merkle.ts
2849
- import { z as z8 } from "zod";
2850
- var readPoolMerkleStateSchema = z8.object({
2851
- type: z8.literal(stellarStateCallTypes.readPoolMerkleState),
2852
- poolContract: z8.string().min(1)
3502
+ import { z as z6 } from "zod";
3503
+ var readPoolMerkleStateSchema = z6.object({
3504
+ type: z6.literal(stellarStateCallTypes.readPoolMerkleState),
3505
+ poolContract: z6.string().min(1)
2853
3506
  }).transform(({ type, poolContract }) => ({
2854
3507
  type,
2855
3508
  operations: [
@@ -2860,8 +3513,8 @@ var readPoolMerkleStateSchema = z8.object({
2860
3513
  }
2861
3514
  ]
2862
3515
  }));
2863
- var setPoolMerkleStateSchema = z8.object({
2864
- type: z8.literal(stellarStateCallTypes.setPoolMerkleState),
3516
+ var setPoolMerkleStateSchema = z6.object({
3517
+ type: z6.literal(stellarStateCallTypes.setPoolMerkleState),
2865
3518
  state: poolMerkleStateSchema
2866
3519
  }).transform(({ type, state }) => ({
2867
3520
  type,
@@ -2874,10 +3527,10 @@ var setPoolMerkleStateSchema = z8.object({
2874
3527
  }
2875
3528
  ]
2876
3529
  }));
2877
- var readLeafEphemeralSchema = z8.object({
2878
- type: z8.literal(stellarStateCallTypes.readLeafEphemeral),
2879
- poolContract: z8.string().min(1),
2880
- leafIndex: z8.number().int().nonnegative()
3530
+ var readLeafEphemeralSchema = z6.object({
3531
+ type: z6.literal(stellarStateCallTypes.readLeafEphemeral),
3532
+ poolContract: z6.string().min(1),
3533
+ leafIndex: z6.number().int().nonnegative()
2881
3534
  }).transform(({ type, poolContract, leafIndex }) => ({
2882
3535
  type,
2883
3536
  operations: [
@@ -2888,8 +3541,8 @@ var readLeafEphemeralSchema = z8.object({
2888
3541
  }
2889
3542
  ]
2890
3543
  }));
2891
- var setLeafEphemeralSchema = z8.object({
2892
- type: z8.literal(stellarStateCallTypes.setLeafEphemeral),
3544
+ var setLeafEphemeralSchema = z6.object({
3545
+ type: z6.literal(stellarStateCallTypes.setLeafEphemeral),
2893
3546
  ephemeral: leafEphemeralSchema
2894
3547
  }).transform(({ type, ephemeral }) => ({
2895
3548
  type,
@@ -2928,9 +3581,9 @@ var stellarPoolStateDefinitions = [
2928
3581
  ];
2929
3582
 
2930
3583
  // src/state/schemas/records/private.ts
2931
- import { z as z9 } from "zod";
2932
- var listPrivateRecordsSchema = z9.object({
2933
- type: z9.literal(stellarStateCallTypes.listPrivateRecords)
3584
+ import { z as z7 } from "zod";
3585
+ var listPrivateRecordsSchema = z7.object({
3586
+ type: z7.literal(stellarStateCallTypes.listPrivateRecords)
2934
3587
  }).transform(({ type }) => ({
2935
3588
  type,
2936
3589
  operations: [
@@ -2940,9 +3593,9 @@ var listPrivateRecordsSchema = z9.object({
2940
3593
  }
2941
3594
  ]
2942
3595
  }));
2943
- var savePrivateRecordsSchema = z9.object({
2944
- type: z9.literal(stellarStateCallTypes.savePrivateRecords),
2945
- records: z9.array(privateRecordSchema)
3596
+ var savePrivateRecordsSchema = z7.object({
3597
+ type: z7.literal(stellarStateCallTypes.savePrivateRecords),
3598
+ records: z7.array(privateRecordSchema)
2946
3599
  }).transform(({ type, records }) => ({
2947
3600
  type,
2948
3601
  operations: [
@@ -2953,9 +3606,9 @@ var savePrivateRecordsSchema = z9.object({
2953
3606
  }
2954
3607
  ]
2955
3608
  }));
2956
- var replacePrivateRecordsSchema = z9.object({
2957
- type: z9.literal(stellarStateCallTypes.replacePrivateRecords),
2958
- records: z9.array(privateRecordSchema)
3609
+ var replacePrivateRecordsSchema = z7.object({
3610
+ type: z7.literal(stellarStateCallTypes.replacePrivateRecords),
3611
+ records: z7.array(privateRecordSchema)
2959
3612
  }).transform(({ type, records }) => ({
2960
3613
  type,
2961
3614
  operations: [
@@ -2970,18 +3623,18 @@ var replacePrivateRecordsSchema = z9.object({
2970
3623
  }
2971
3624
  ]
2972
3625
  }));
2973
- var pruneConsumedPrivateRecordsSchema = z9.object({
2974
- type: z9.literal(stellarStateCallTypes.pruneConsumedPrivateRecords)
3626
+ var pruneConsumedPrivateRecordsSchema = z7.object({
3627
+ type: z7.literal(stellarStateCallTypes.pruneConsumedPrivateRecords)
2975
3628
  }).transform(({ type }) => ({
2976
3629
  type,
2977
3630
  operations: [rejectConsumedPrivateRecords()]
2978
3631
  }));
2979
3632
 
2980
3633
  // src/state/schemas/records/transactions.ts
2981
- import { z as z10 } from "zod";
2982
- var upsertPrivateRecordsSchema = z10.object({
2983
- type: z10.literal(stellarStateCallTypes.upsertPrivateRecords),
2984
- records: z10.array(privateRecordSchema)
3634
+ import { z as z8 } from "zod";
3635
+ var upsertPrivateRecordsSchema = z8.object({
3636
+ type: z8.literal(stellarStateCallTypes.upsertPrivateRecords),
3637
+ records: z8.array(privateRecordSchema)
2985
3638
  }).transform(({ type, records }) => ({
2986
3639
  type,
2987
3640
  operations: [
@@ -2993,9 +3646,9 @@ var upsertPrivateRecordsSchema = z10.object({
2993
3646
  }
2994
3647
  ]
2995
3648
  }));
2996
- var readTransactionStatusSchema = z10.object({
2997
- type: z10.literal(stellarStateCallTypes.readTransactionStatus),
2998
- txHash: z10.string().min(1)
3649
+ var readTransactionStatusSchema = z8.object({
3650
+ type: z8.literal(stellarStateCallTypes.readTransactionStatus),
3651
+ txHash: z8.string().min(1)
2999
3652
  }).transform(({ type, txHash }) => ({
3000
3653
  type,
3001
3654
  operations: [
@@ -3006,8 +3659,8 @@ var readTransactionStatusSchema = z10.object({
3006
3659
  }
3007
3660
  ]
3008
3661
  }));
3009
- var setTransactionStatusSchema = z10.object({
3010
- type: z10.literal(stellarStateCallTypes.setTransactionStatus),
3662
+ var setTransactionStatusSchema = z8.object({
3663
+ type: z8.literal(stellarStateCallTypes.setTransactionStatus),
3011
3664
  status: transactionStatusSchema
3012
3665
  }).transform(({ type, status }) => ({
3013
3666
  type,
@@ -3020,9 +3673,9 @@ var setTransactionStatusSchema = z10.object({
3020
3673
  }
3021
3674
  ]
3022
3675
  }));
3023
- var clearTransactionStatusSchema = z10.object({
3024
- type: z10.literal(stellarStateCallTypes.clearTransactionStatus),
3025
- txHash: z10.string().min(1)
3676
+ var clearTransactionStatusSchema = z8.object({
3677
+ type: z8.literal(stellarStateCallTypes.clearTransactionStatus),
3678
+ txHash: z8.string().min(1)
3026
3679
  }).transform(({ type, txHash }) => ({
3027
3680
  type,
3028
3681
  operations: [
@@ -3064,10 +3717,10 @@ var stellarRecordsStateDefinitions = [
3064
3717
  ];
3065
3718
 
3066
3719
  // src/state/schemas/registry/lookup.ts
3067
- import { z as z11 } from "zod";
3068
- var readStellarAddressRegisteredSchema = z11.object({
3069
- type: z11.literal(stellarStateCallTypes.readStellarAddressRegistered),
3070
- address: z11.string().min(1)
3720
+ import { z as z9 } from "zod";
3721
+ var readStellarAddressRegisteredSchema = z9.object({
3722
+ type: z9.literal(stellarStateCallTypes.readStellarAddressRegistered),
3723
+ address: z9.string().min(1)
3071
3724
  }).transform(({ type, address }) => ({
3072
3725
  type,
3073
3726
  operations: [
@@ -3078,9 +3731,9 @@ var readStellarAddressRegisteredSchema = z11.object({
3078
3731
  }
3079
3732
  ]
3080
3733
  }));
3081
- var readCachedPrivateAddressSchema = z11.object({
3082
- type: z11.literal(stellarStateCallTypes.readCachedPrivateAddress),
3083
- address: z11.string().min(1)
3734
+ var readCachedPrivateAddressSchema = z9.object({
3735
+ type: z9.literal(stellarStateCallTypes.readCachedPrivateAddress),
3736
+ address: z9.string().min(1)
3084
3737
  }).transform(({ type, address }) => ({
3085
3738
  type,
3086
3739
  operations: [
@@ -3091,11 +3744,11 @@ var readCachedPrivateAddressSchema = z11.object({
3091
3744
  }
3092
3745
  ]
3093
3746
  }));
3094
- var saveRegisteredPrivateAddressSchema = z11.object({
3095
- type: z11.literal(stellarStateCallTypes.saveRegisteredPrivateAddress),
3096
- address: z11.string().min(1),
3097
- privateAddress: z11.string().min(1),
3098
- registered: z11.boolean()
3747
+ var saveRegisteredPrivateAddressSchema = z9.object({
3748
+ type: z9.literal(stellarStateCallTypes.saveRegisteredPrivateAddress),
3749
+ address: z9.string().min(1),
3750
+ privateAddress: z9.string().min(1),
3751
+ registered: z9.boolean()
3099
3752
  }).transform(({ type, address, privateAddress, registered: registered2 }) => {
3100
3753
  const lookup = registryLookupSchema.parse({
3101
3754
  owner: address,
@@ -3127,9 +3780,9 @@ var saveRegisteredPrivateAddressSchema = z11.object({
3127
3780
  ]
3128
3781
  };
3129
3782
  });
3130
- var invalidateRegisteredAddressSchema = z11.object({
3131
- type: z11.literal(stellarStateCallTypes.invalidateRegisteredAddress),
3132
- address: z11.string().min(1)
3783
+ var invalidateRegisteredAddressSchema = z9.object({
3784
+ type: z9.literal(stellarStateCallTypes.invalidateRegisteredAddress),
3785
+ address: z9.string().min(1)
3133
3786
  }).transform(({ type, address }) => ({
3134
3787
  type,
3135
3788
  operations: [
@@ -3150,9 +3803,9 @@ var invalidateRegisteredAddressSchema = z11.object({
3150
3803
  }
3151
3804
  ]
3152
3805
  }));
3153
- var readRegistryLookupSchema = z11.object({
3154
- type: z11.literal(stellarStateCallTypes.readRegistryLookup),
3155
- address: z11.string().min(1)
3806
+ var readRegistryLookupSchema = z9.object({
3807
+ type: z9.literal(stellarStateCallTypes.readRegistryLookup),
3808
+ address: z9.string().min(1)
3156
3809
  }).transform(({ type, address }) => ({
3157
3810
  type,
3158
3811
  operations: [
@@ -3163,8 +3816,8 @@ var readRegistryLookupSchema = z11.object({
3163
3816
  }
3164
3817
  ]
3165
3818
  }));
3166
- var saveRegistryLookupSchema = z11.object({
3167
- type: z11.literal(stellarStateCallTypes.saveRegistryLookup),
3819
+ var saveRegistryLookupSchema = z9.object({
3820
+ type: z9.literal(stellarStateCallTypes.saveRegistryLookup),
3168
3821
  lookup: registryLookupSchema
3169
3822
  }).transform(({ type, lookup }) => {
3170
3823
  const operations = [
@@ -3200,9 +3853,9 @@ var saveRegistryLookupSchema = z11.object({
3200
3853
  }
3201
3854
  return { type, operations };
3202
3855
  });
3203
- var invalidateRegistryLookupSchema = z11.object({
3204
- type: z11.literal(stellarStateCallTypes.invalidateRegistryLookup),
3205
- address: z11.string().min(1)
3856
+ var invalidateRegistryLookupSchema = z9.object({
3857
+ type: z9.literal(stellarStateCallTypes.invalidateRegistryLookup),
3858
+ address: z9.string().min(1)
3206
3859
  }).transform(({ type, address }) => ({
3207
3860
  type,
3208
3861
  operations: [
@@ -3283,9 +3936,9 @@ var stellarTransactionStateDefinitions = [
3283
3936
  ];
3284
3937
 
3285
3938
  // src/state/schemas/wallet/scalar.ts
3286
- import { z as z12 } from "zod";
3287
- var saveWalletPrivateAddressScalarSchema = z12.object({
3288
- type: z12.literal(stellarStateCallTypes.saveWalletPrivateAddressScalar),
3939
+ import { z as z10 } from "zod";
3940
+ var saveWalletPrivateAddressScalarSchema = z10.object({
3941
+ type: z10.literal(stellarStateCallTypes.saveWalletPrivateAddressScalar),
3289
3942
  scalar: walletPrivateAddressScalarSchema
3290
3943
  }).transform(({ type, scalar }) => ({
3291
3944
  type,
@@ -3298,10 +3951,10 @@ var saveWalletPrivateAddressScalarSchema = z12.object({
3298
3951
  }
3299
3952
  ]
3300
3953
  }));
3301
- var readWalletPrivateAddressScalarSchema = z12.object({
3302
- type: z12.literal(stellarStateCallTypes.readWalletPrivateAddressScalar),
3303
- owner: z12.string().min(1),
3304
- nonce: z12.string().min(1)
3954
+ var readWalletPrivateAddressScalarSchema = z10.object({
3955
+ type: z10.literal(stellarStateCallTypes.readWalletPrivateAddressScalar),
3956
+ owner: z10.string().min(1),
3957
+ nonce: z10.string().min(1)
3305
3958
  }).transform(({ type, owner, nonce }) => ({
3306
3959
  type,
3307
3960
  operations: [
@@ -3314,9 +3967,9 @@ var readWalletPrivateAddressScalarSchema = z12.object({
3314
3967
  }));
3315
3968
 
3316
3969
  // src/state/schemas/wallet/private-address.ts
3317
- import { z as z13 } from "zod";
3318
- var saveWalletPrivateAddressRecordSchema = z13.object({
3319
- type: z13.literal(stellarStateCallTypes.saveWalletPrivateAddressRecord),
3970
+ import { z as z11 } from "zod";
3971
+ var saveWalletPrivateAddressRecordSchema = z11.object({
3972
+ type: z11.literal(stellarStateCallTypes.saveWalletPrivateAddressRecord),
3320
3973
  record: walletPrivateAddressRecordSchema
3321
3974
  }).transform(({ type, record }) => ({
3322
3975
  type,
@@ -3329,10 +3982,10 @@ var saveWalletPrivateAddressRecordSchema = z13.object({
3329
3982
  }
3330
3983
  ]
3331
3984
  }));
3332
- var readWalletPrivateAddressRecordSchema = z13.object({
3333
- type: z13.literal(stellarStateCallTypes.readWalletPrivateAddressRecord),
3334
- owner: z13.string().min(1),
3335
- nonce: z13.string().min(1)
3985
+ var readWalletPrivateAddressRecordSchema = z11.object({
3986
+ type: z11.literal(stellarStateCallTypes.readWalletPrivateAddressRecord),
3987
+ owner: z11.string().min(1),
3988
+ nonce: z11.string().min(1)
3336
3989
  }).transform(({ type, owner, nonce }) => ({
3337
3990
  type,
3338
3991
  operations: [
@@ -3343,10 +3996,10 @@ var readWalletPrivateAddressRecordSchema = z13.object({
3343
3996
  }
3344
3997
  ]
3345
3998
  }));
3346
- var setWalletDefaultPrivateAddressNonceSchema = z13.object({
3347
- type: z13.literal(stellarStateCallTypes.setWalletDefaultPrivateAddressNonce),
3348
- owner: z13.string().min(1),
3349
- nonce: z13.string().min(1)
3999
+ var setWalletDefaultPrivateAddressNonceSchema = z11.object({
4000
+ type: z11.literal(stellarStateCallTypes.setWalletDefaultPrivateAddressNonce),
4001
+ owner: z11.string().min(1),
4002
+ nonce: z11.string().min(1)
3350
4003
  }).transform(({ type, owner, nonce }) => ({
3351
4004
  type,
3352
4005
  operations: [
@@ -3358,9 +4011,9 @@ var setWalletDefaultPrivateAddressNonceSchema = z13.object({
3358
4011
  }
3359
4012
  ]
3360
4013
  }));
3361
- var readWalletDefaultPrivateAddressNonceSchema = z13.object({
3362
- type: z13.literal(stellarStateCallTypes.readWalletDefaultPrivateAddressNonce),
3363
- owner: z13.string().min(1)
4014
+ var readWalletDefaultPrivateAddressNonceSchema = z11.object({
4015
+ type: z11.literal(stellarStateCallTypes.readWalletDefaultPrivateAddressNonce),
4016
+ owner: z11.string().min(1)
3364
4017
  }).transform(({ type, owner }) => ({
3365
4018
  type,
3366
4019
  operations: [
@@ -3371,10 +4024,10 @@ var readWalletDefaultPrivateAddressNonceSchema = z13.object({
3371
4024
  }
3372
4025
  ]
3373
4026
  }));
3374
- var deleteWalletPrivateAddressScalarSchema = z13.object({
3375
- type: z13.literal(stellarStateCallTypes.deleteWalletPrivateAddressScalar),
3376
- owner: z13.string().min(1),
3377
- nonce: z13.string().min(1)
4027
+ var deleteWalletPrivateAddressScalarSchema = z11.object({
4028
+ type: z11.literal(stellarStateCallTypes.deleteWalletPrivateAddressScalar),
4029
+ owner: z11.string().min(1),
4030
+ nonce: z11.string().min(1)
3378
4031
  }).transform(({ type, owner, nonce }) => ({
3379
4032
  type,
3380
4033
  operations: [
@@ -3428,7 +4081,6 @@ var stellarWalletStateDefinitions = [
3428
4081
  // src/state/definitions/index.ts
3429
4082
  registerStellarArrayFilterSchemas();
3430
4083
  var stellarStateDefinitions = [
3431
- ...stellarClaimsStateDefinitions,
3432
4084
  ...stellarRegistryStateDefinitions,
3433
4085
  ...stellarAssetsStateDefinitions,
3434
4086
  ...stellarBalancesStateDefinitions,
@@ -3552,112 +4204,10 @@ function createAssetsCatalogMethods(context) {
3552
4204
  }
3553
4205
 
3554
4206
  // src/state/service/assets/index.ts
3555
- function createAssetsService(context) {
3556
- return {
3557
- ...createAssetsCatalogMethods(context),
3558
- ...createPublicBalanceMethods(context)
3559
- };
3560
- }
3561
-
3562
- // src/state/service/claims/read-methods.ts
3563
- function createClaimsReadMethods(context) {
3564
- const { bridge } = context;
3565
- async function getPendingClaims(filter = {}) {
3566
- const value = await bridge.read({
3567
- type: stellarStateCallTypes.readPendingClaims
3568
- });
3569
- const state = normalizePendingClaimsState(value);
3570
- const items = state.items.filter((claim) => {
3571
- if (filter.owner !== void 0 && claim.owner !== filter.owner) {
3572
- return false;
3573
- }
3574
- if (filter.asset !== void 0 && claim.asset !== filter.asset) {
3575
- return false;
3576
- }
3577
- return true;
3578
- });
3579
- if (state.pagination !== void 0) {
3580
- return { items, pagination: state.pagination };
3581
- }
3582
- return { items };
3583
- }
3584
- return {
3585
- getPendingClaims,
3586
- async getPendingClaimsCount(owner) {
3587
- const value = await bridge.read({
3588
- type: stellarStateCallTypes.readPendingClaimsCount,
3589
- owner
3590
- });
3591
- const count = normalizePendingClaimsCount(value);
3592
- if (count !== void 0) {
3593
- return count;
3594
- }
3595
- const claims = await getPendingClaims({ owner });
3596
- return claims.items.length;
3597
- }
3598
- };
3599
- }
3600
-
3601
- // src/state/service/claims/write-methods.ts
3602
- function appendPendingClaims(bridge, claims, paginationInfo) {
3603
- return bridge.write({
3604
- type: stellarStateCallTypes.pendingClaims,
3605
- claims,
3606
- paginationInfo
3607
- });
3608
- }
3609
- function replacePendingClaimsPage(bridge, input) {
3610
- return bridge.write({
3611
- type: stellarStateCallTypes.replacePendingClaimsPage,
3612
- owner: input.owner,
3613
- claims: input.claims,
3614
- paginationInfo: input.paginationInfo,
3615
- ...input.count === void 0 ? {} : { count: input.count }
3616
- });
3617
- }
3618
- function upsertPendingClaims(bridge, claims) {
3619
- return bridge.write({
3620
- type: stellarStateCallTypes.upsertPendingClaims,
3621
- claims
3622
- });
3623
- }
3624
- function removePendingClaims(bridge, ids) {
3625
- return bridge.write({
3626
- type: stellarStateCallTypes.removePendingClaims,
3627
- ids
3628
- });
3629
- }
3630
- function clearPendingClaims(bridge, input = {}) {
3631
- return bridge.write({
3632
- type: stellarStateCallTypes.clearPendingClaims,
3633
- ...input.owner === void 0 ? {} : { owner: input.owner },
3634
- ...input.asset === void 0 ? {} : { asset: input.asset }
3635
- });
3636
- }
3637
- function setPendingClaimsCount(bridge, owner, count) {
3638
- return bridge.write({
3639
- type: stellarStateCallTypes.setPendingClaimsCount,
3640
- owner,
3641
- count
3642
- });
3643
- }
3644
- function createClaimsWriteMethods(context) {
3645
- const { bridge } = context;
3646
- return {
3647
- appendPendingClaims: (claims, paginationInfo) => appendPendingClaims(bridge, claims, paginationInfo),
3648
- replacePendingClaimsPage: (input) => replacePendingClaimsPage(bridge, input),
3649
- upsertPendingClaims: (claims) => upsertPendingClaims(bridge, claims),
3650
- removePendingClaims: (ids) => removePendingClaims(bridge, ids),
3651
- clearPendingClaims: (input = {}) => clearPendingClaims(bridge, input),
3652
- setPendingClaimsCount: (owner, count) => setPendingClaimsCount(bridge, owner, count)
3653
- };
3654
- }
3655
-
3656
- // src/state/service/claims/index.ts
3657
- function createClaimsService(context) {
4207
+ function createAssetsService(context) {
3658
4208
  return {
3659
- ...createClaimsWriteMethods(context),
3660
- ...createClaimsReadMethods(context)
4209
+ ...createAssetsCatalogMethods(context),
4210
+ ...createPublicBalanceMethods(context)
3661
4211
  };
3662
4212
  }
3663
4213
 
@@ -4186,7 +4736,6 @@ function composeStellarStateService(adapter) {
4186
4736
  ...createWalletAddressService(base),
4187
4737
  ...createPoolMerkleService(base),
4188
4738
  ...createPoolEphemeralService(base),
4189
- ...createClaimsService(base),
4190
4739
  ...createDeliveriesService(base),
4191
4740
  ...createRecordsService(base)
4192
4741
  };
@@ -4251,42 +4800,1030 @@ function attachPoolStatePorts(transactEnvironment, state) {
4251
4800
  resolveSenderPrivKeyScalarFromState: createSenderScalarStateResolver(state)
4252
4801
  };
4253
4802
  }
4803
+
4804
+ // src/transact/encoding/ephemeral-key.ts
4805
+ var HEX_64_RE = /^[\da-f]{64}$/iu;
4806
+ function normalizeCoordinate(value) {
4807
+ const hex = value.trim().replace(/^0x/iu, "").toLowerCase();
4808
+ if (!HEX_64_RE.test(hex)) {
4809
+ throw new Error("Ephemeral key coordinate must be a 32-byte hex string.");
4810
+ }
4811
+ return hex;
4812
+ }
4813
+ function serializeEphemeralKeyString(point) {
4814
+ return `${normalizeCoordinate(point.xHex)}:${normalizeCoordinate(point.yHex)}`;
4815
+ }
4816
+
4817
+ // src/transact/private-address/record-coin.ts
4818
+ function requireCoinNoteFromRecord(record) {
4819
+ if (!record.coinNote) {
4820
+ throw new Error(`Private record ${record.id} is missing coin note data.`);
4821
+ }
4822
+ return record.coinNote;
4823
+ }
4824
+ function findCommitmentLeafIndex(commitments, commitment) {
4825
+ return commitments.indexOf(commitment);
4826
+ }
4827
+
4828
+ // src/transact/engine/prepare/shared.ts
4829
+ async function resolveTokenContractId2(environment, assetId) {
4830
+ if (environment.resolveTokenContractId) {
4831
+ return environment.resolveTokenContractId(assetId);
4832
+ }
4833
+ throw new Error(`Token contract is not configured for asset ${assetId}.`);
4834
+ }
4835
+ async function resolveSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
4836
+ const cached = await readSenderPrivKeyScalarHex(
4837
+ environment,
4838
+ privateAddressStpl1,
4839
+ owner
4840
+ );
4841
+ if (cached) {
4842
+ return cached;
4843
+ }
4844
+ if (environment.ensureSenderPrivKeyScalarHex) {
4845
+ return environment.ensureSenderPrivKeyScalarHex(privateAddressStpl1);
4846
+ }
4847
+ if (!environment.resolveSenderPrivKeyScalarHex) {
4848
+ throw new Error("Sender private key scalar resolver is not configured.");
4849
+ }
4850
+ return environment.resolveSenderPrivKeyScalarHex(privateAddressStpl1);
4851
+ }
4852
+ async function readSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
4853
+ if (owner && environment.resolveSenderPrivKeyScalarFromState) {
4854
+ const fromState = await environment.resolveSenderPrivKeyScalarFromState({
4855
+ owner,
4856
+ privateAddressStpl1
4857
+ });
4858
+ if (fromState?.trim()) {
4859
+ return fromState.trim();
4860
+ }
4861
+ }
4862
+ if (environment.readSenderPrivKeyScalarHex) {
4863
+ const cached = await environment.readSenderPrivKeyScalarHex(privateAddressStpl1);
4864
+ if (cached?.trim()) {
4865
+ return cached.trim();
4866
+ }
4867
+ }
4868
+ return void 0;
4869
+ }
4870
+ async function ensureSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
4871
+ const cached = await readSenderPrivKeyScalarHex(
4872
+ environment,
4873
+ privateAddressStpl1,
4874
+ owner
4875
+ );
4876
+ if (cached) {
4877
+ return cached;
4878
+ }
4879
+ if (environment.ensureSenderPrivKeyScalarHex) {
4880
+ return environment.ensureSenderPrivKeyScalarHex(privateAddressStpl1);
4881
+ }
4882
+ return resolveSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner);
4883
+ }
4884
+ async function loadMerkleState(environment, walletPublicKey) {
4885
+ const merged = await fetchAndMergeMerkleState({
4886
+ poolContractId: environment.network.poolContract,
4887
+ walletPublicKey,
4888
+ transactEnvironment: environment,
4889
+ ...environment.poolMerkleState ? { poolMerkleState: environment.poolMerkleState } : {}
4890
+ });
4891
+ return { commitments: merged.commitments };
4892
+ }
4893
+
4894
+ // src/transact/escrow/require-escrow-spend-scalar.ts
4895
+ function isEscrowSweepSpend(artifacts) {
4896
+ return artifacts?.spendSource === "escrow" && artifacts.escrowSend !== true;
4897
+ }
4898
+ function requireEscrowSpendScalarHex(artifacts) {
4899
+ if (!isEscrowSweepSpend(artifacts)) {
4900
+ throw new Error("Escrow sweep requires spendSource escrow.");
4901
+ }
4902
+ const hex = artifacts?.escrowSpendScalarHex?.trim();
4903
+ if (!hex) {
4904
+ throw new Error("Escrow sweep requires the reconstructed note owner scalar.");
4905
+ }
4906
+ return hex;
4907
+ }
4908
+ function nullifierCheckSpendScalarHex(artifacts) {
4909
+ if (!isEscrowSweepSpend(artifacts)) {
4910
+ return void 0;
4911
+ }
4912
+ return requireEscrowSpendScalarHex(artifacts);
4913
+ }
4914
+
4915
+ // src/transact/transfer-source/resolve.ts
4916
+ function readTransferFromPrivateAddress(from) {
4917
+ return from.trim();
4918
+ }
4919
+
4920
+ // src/transact/transfer-source/verify-private-records.ts
4921
+ import { executionError, insufficientStateError as insufficientStateError2 } from "@arcanetech/privacy-sdk-core";
4922
+
4923
+ // src/contracts/pool/pool-domain-service.ts
4924
+ import { Buffer as Buffer14 } from "buffer";
4925
+ function hexToBuffer(hex) {
4926
+ const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
4927
+ return Buffer14.from(clean, "hex");
4928
+ }
4929
+ async function readNullifierConsumedOnChain(input) {
4930
+ const client = input.contractContext.createPoolClient({
4931
+ contractId: input.poolContractId,
4932
+ walletPublicKey: input.walletPublicKey,
4933
+ networkPassphrase: input.contractContext.network.networkPassphrase,
4934
+ sorobanRpcUrl: input.contractContext.network.rpcUrl
4935
+ });
4936
+ const read = await client.is_nulifier_hash_consumed({
4937
+ hash: hexToBuffer(input.nullifierHashHex)
4938
+ });
4939
+ return read.result;
4940
+ }
4941
+
4942
+ // src/transact/transfer-source/verify-private-records.ts
4943
+ async function resolveNullifierSpendScalarHex(input) {
4944
+ const stamped = input.spendScalarHex?.trim();
4945
+ if (stamped) {
4946
+ return stamped;
4947
+ }
4948
+ const privateAddress = input.record.privateAddress?.trim();
4949
+ if (!privateAddress) {
4950
+ throw executionError(
4951
+ "Private record is missing a private address; cannot derive the owner-bound spend scalar.",
4952
+ "validation",
4953
+ {
4954
+ reason: "private_record_missing_private_address",
4955
+ recordId: input.record.id
4956
+ }
4957
+ );
4958
+ }
4959
+ return ensureSenderPrivKeyScalarHex(
4960
+ input.environment,
4961
+ privateAddress,
4962
+ input.walletPublicKey
4963
+ );
4964
+ }
4965
+ async function readPrivateRecordNullifierSpendStatus(input) {
4966
+ const coin = requireCoinNoteFromRecord(input.record);
4967
+ const scalarHex = await resolveNullifierSpendScalarHex(input);
4968
+ const nullifierHashHex = await getPrivacyPoolService().calculateNullifierHash(
4969
+ coin.nullifier,
4970
+ privKeyScalarDecimalFromRecipientScalarHex(scalarHex)
4971
+ );
4972
+ const contractContext = requireContractContext(input.environment);
4973
+ const poolContractId = input.poolContractId?.trim() || contractContext.network.poolContract;
4974
+ const spent = await readNullifierConsumedOnChain({
4975
+ contractContext,
4976
+ poolContractId,
4977
+ walletPublicKey: input.walletPublicKey.trim(),
4978
+ nullifierHashHex
4979
+ });
4980
+ return { spent, nullifierHashHex };
4981
+ }
4982
+ async function verifyPrivateRecordsNullifiersBeforeExecute(input) {
4983
+ for (const record of input.records) {
4984
+ const status = await readPrivateRecordNullifierSpendStatus({
4985
+ record,
4986
+ environment: input.environment,
4987
+ walletPublicKey: input.walletPublicKey,
4988
+ ...input.poolContractId ? { poolContractId: input.poolContractId } : {},
4989
+ ...input.spendScalarHex ? { spendScalarHex: input.spendScalarHex } : {}
4990
+ });
4991
+ if (status.spent) {
4992
+ throw executionError(
4993
+ "Private input note nullifier was already spent on-chain.",
4994
+ "validation",
4995
+ {
4996
+ reason: "private_record_nullifier_spent",
4997
+ recordId: record.id,
4998
+ nullifierHashHex: status.nullifierHashHex
4999
+ }
5000
+ );
5001
+ }
5002
+ }
5003
+ }
5004
+
5005
+ // src/transact/engine/spend-proof-context.ts
5006
+ async function resolveSenderPrivKeyScalarHex2(input) {
5007
+ if (isEscrowSweepSpend(input.prepared.transactArtifacts)) {
5008
+ return requireEscrowSpendScalarHex(input.prepared.transactArtifacts);
5009
+ }
5010
+ if (input.prepared.kind !== "transfer" && input.prepared.kind !== "withdraw") {
5011
+ throw new Error("Spend execution requires a transfer or withdraw intent.");
5012
+ }
5013
+ return ensureSenderPrivKeyScalarHex(
5014
+ input.environment,
5015
+ readTransferFromPrivateAddress(input.prepared.intent.from),
5016
+ input.walletPublicKey
5017
+ );
5018
+ }
5019
+ async function buildSpendProofContextAtExecute(input) {
5020
+ const [primaryRecord] = input.prepared.consumedRecords;
5021
+ if (!primaryRecord) {
5022
+ throw new Error("Spend execution requires at least one private record.");
5023
+ }
5024
+ const walletPublicKey = primaryRecord.owner.trim();
5025
+ if (!walletPublicKey) {
5026
+ throw new Error("Spend execution record owner is missing.");
5027
+ }
5028
+ const senderPrivKeyScalarHex = await resolveSenderPrivKeyScalarHex2({
5029
+ prepared: input.prepared,
5030
+ environment: input.environment,
5031
+ walletPublicKey
5032
+ });
5033
+ const tokenAddress = await resolveTokenContractId2(
5034
+ input.environment,
5035
+ input.prepared.intent.asset
5036
+ );
5037
+ const coin = requireCoinNoteFromRecord(primaryRecord);
5038
+ const { commitments } = await loadMerkleState(input.environment, walletPublicKey);
5039
+ const leafIndex = findCommitmentLeafIndex(commitments, coin.commitment);
5040
+ if (leafIndex < 0) {
5041
+ throw new Error("Coin commitment not found in on-chain Merkle state.");
5042
+ }
5043
+ const ephemeral = await readLeafEphemeralHex({
5044
+ poolContractId: input.environment.network.poolContract,
5045
+ walletPublicKey,
5046
+ leafIndex,
5047
+ transactEnvironment: input.environment,
5048
+ ...input.environment.leafEphemeral ? { leafEphemeral: input.environment.leafEphemeral } : {}
5049
+ });
5050
+ return {
5051
+ walletPublicKey,
5052
+ tokenAddress,
5053
+ coin,
5054
+ commitments,
5055
+ ephemeral,
5056
+ senderPrivKeyScalarHex,
5057
+ recipientPrivateAddressStpl1: input.recipientPrivateAddressStpl1
5058
+ };
5059
+ }
5060
+ async function readCoinEphemeralForRecord(input) {
5061
+ const coin = requireCoinNoteFromRecord(input.record);
5062
+ const leafIndex = findCommitmentLeafIndex(input.commitments, coin.commitment);
5063
+ if (leafIndex < 0) {
5064
+ throw new Error("Coin commitment not found in on-chain Merkle state.");
5065
+ }
5066
+ const ephemeral = await readLeafEphemeralHex({
5067
+ poolContractId: input.environment.network.poolContract,
5068
+ walletPublicKey: input.walletPublicKey,
5069
+ leafIndex,
5070
+ transactEnvironment: input.environment,
5071
+ ...input.environment.leafEphemeral ? { leafEphemeral: input.environment.leafEphemeral } : {}
5072
+ });
5073
+ return { coin, ephemeral };
5074
+ }
5075
+
5076
+ // src/transact/engine/prepare/transfer-helpers.ts
5077
+ import { StrKey as StrKey8 } from "@stellar/stellar-sdk";
5078
+ function isStellarAccountRecipient(prepared) {
5079
+ return prepared.kind === "transfer" && StrKey8.isValidEd25519PublicKey(prepared.intent.to.trim());
5080
+ }
5081
+ async function resolveTransferRecipientForExecute(prepared, environment, walletPublicKey) {
5082
+ if (!isStellarAccountRecipient(prepared)) {
5083
+ return {
5084
+ recipientPrivateAddressStpl1: prepared.intent.to.trim()
5085
+ };
5086
+ }
5087
+ if (!environment.resolveTransferRecipientAtExecute) {
5088
+ throw new Error("Transfer recipient resolver is not configured.");
5089
+ }
5090
+ return environment.resolveTransferRecipientAtExecute({
5091
+ recipientStellarAddress: prepared.intent.to.trim(),
5092
+ walletPublicKey
5093
+ });
5094
+ }
5095
+
5096
+ // src/transact/engine/transfer-proof-at-execute.ts
5097
+ function readChangeRecipient(input, changeStroops) {
5098
+ if (changeStroops <= 0n || input.prepared.kind !== "transfer") {
5099
+ return void 0;
5100
+ }
5101
+ const from = input.prepared.intent.from;
5102
+ return readTransferFromPrivateAddress(from);
5103
+ }
5104
+ function proofEscrowFields(input) {
5105
+ return {
5106
+ ...input.escrowSend ? { escrowSend: input.escrowSend } : {},
5107
+ ...input.escrowClaimantLimbs ? { escrowClaimantLimbs: input.escrowClaimantLimbs } : {}
5108
+ };
5109
+ }
5110
+ async function buildSingleTransferProofAtExecute(input) {
5111
+ const context = await buildSpendProofContextAtExecute(input);
5112
+ const changeStroops = BigInt(context.coin.value) - input.prepared.intent.amount;
5113
+ const proof = await prepareConfidentialTransferProof({
5114
+ coin: context.coin,
5115
+ state: { commitments: context.commitments },
5116
+ senderPrivKeyScalarHex: context.senderPrivKeyScalarHex,
5117
+ depositorEphemeralKey: serializeEphemeralKeyString({
5118
+ xHex: context.ephemeral.xHex,
5119
+ yHex: context.ephemeral.yHex
5120
+ }),
5121
+ transferStroops: input.prepared.intent.amount,
5122
+ recipientPrivateAddressStpl1: context.recipientPrivateAddressStpl1,
5123
+ selfPrivateAddressStpl1ForChange: readChangeRecipient(input, changeStroops),
5124
+ tokenAddress: context.tokenAddress,
5125
+ ...proofEscrowFields(input)
5126
+ });
5127
+ return { context, proof };
5128
+ }
5129
+ async function buildDualTransferProofAtExecute(input) {
5130
+ const [primaryRecord, secondaryRecord] = input.prepared.consumedRecords;
5131
+ if (!primaryRecord || !secondaryRecord) {
5132
+ throw new Error("Dual transfer execution requires two private input records.");
5133
+ }
5134
+ const context = await buildSpendProofContextAtExecute(input);
5135
+ const secondary = await readCoinEphemeralForRecord({
5136
+ record: secondaryRecord,
5137
+ environment: input.environment,
5138
+ walletPublicKey: context.walletPublicKey,
5139
+ commitments: context.commitments
5140
+ });
5141
+ const totalNotes = BigInt(context.coin.value) + BigInt(secondary.coin.value);
5142
+ const changeStroops = totalNotes - input.prepared.intent.amount;
5143
+ const proof = await prepareConfidentialTransferProofDual({
5144
+ coinA: context.coin,
5145
+ coinB: secondary.coin,
5146
+ state: { commitments: context.commitments },
5147
+ senderPrivKeyScalarHex: context.senderPrivKeyScalarHex,
5148
+ ephemeralAKey: serializeEphemeralKeyString({
5149
+ xHex: context.ephemeral.xHex,
5150
+ yHex: context.ephemeral.yHex
5151
+ }),
5152
+ ephemeralBKey: serializeEphemeralKeyString({
5153
+ xHex: secondary.ephemeral.xHex,
5154
+ yHex: secondary.ephemeral.yHex
5155
+ }),
5156
+ transferStroops: input.prepared.intent.amount,
5157
+ recipientPrivateAddressStpl1: context.recipientPrivateAddressStpl1,
5158
+ selfPrivateAddressStpl1ForChange: readChangeRecipient(input, changeStroops),
5159
+ tokenAddress: context.tokenAddress,
5160
+ ...proofEscrowFields(input)
5161
+ });
5162
+ return { context, proof };
5163
+ }
5164
+ async function buildTransferProofAtExecute(input) {
5165
+ const recordCount = input.prepared.consumedRecords.length;
5166
+ if (recordCount === 1) {
5167
+ return buildSingleTransferProofAtExecute(input);
5168
+ }
5169
+ if (recordCount === 2) {
5170
+ return buildDualTransferProofAtExecute(input);
5171
+ }
5172
+ throw new Error("Confidential transfer execution supports at most two input notes.");
5173
+ }
5174
+
5175
+ // src/transact/engine/transfer-finalize.ts
5176
+ function stampEscrowOutputRecords(input) {
5177
+ if (input.escrowSendPrivateAddress) {
5178
+ const [recipientRecord, ...rest] = input.prepared.outputRecords;
5179
+ if (recipientRecord) {
5180
+ input.prepared.outputRecords = [
5181
+ {
5182
+ ...recipientRecord,
5183
+ privateAddress: input.escrowSendPrivateAddress
5184
+ },
5185
+ ...rest
5186
+ ];
5187
+ }
5188
+ }
5189
+ seedEscrowSweepOutputsFromProof({
5190
+ prepared: input.prepared,
5191
+ proof: input.proof,
5192
+ walletPublicKey: input.walletPublicKey
5193
+ });
5194
+ enrichTransferOutputRecords(input.prepared, input.proof);
5195
+ }
5196
+ function seedEscrowSweepOutputsFromProof(input) {
5197
+ if (input.prepared.transactArtifacts?.spendSource !== "escrow" || input.prepared.outputRecords.length > 0) {
5198
+ return;
5199
+ }
5200
+ input.prepared.outputRecords = [
5201
+ {
5202
+ id: input.proof.recipientCoin.commitment_hex,
5203
+ owner: input.walletPublicKey,
5204
+ privateAddress: input.prepared.intent.to,
5205
+ asset: input.prepared.intent.asset,
5206
+ amount: input.prepared.intent.amount,
5207
+ consumed: false
5208
+ }
5209
+ ];
5210
+ }
5211
+ function enrichTransferOutputRecords(prepared, proof) {
5212
+ if (prepared.outputRecords.length === 0) {
5213
+ return;
5214
+ }
5215
+ const generatedOutputCoins = [
5216
+ proof.recipientCoin,
5217
+ ...proof.changeCoin ? [proof.changeCoin] : []
5218
+ ];
5219
+ prepared.outputRecords = prepared.outputRecords.map((record, index) => {
5220
+ const generatedCoin = generatedOutputCoins.at(index);
5221
+ if (!generatedCoin) {
5222
+ return record;
5223
+ }
5224
+ return {
5225
+ ...record,
5226
+ id: generatedCoin.commitment_hex,
5227
+ commitmentHex: generatedCoin.commitment_hex,
5228
+ coinNote: generatedCoin.coin,
5229
+ depositScalarHex: generatedCoin.depositScalarHex,
5230
+ precommitementHex: generatedCoin.precommitementHex
5231
+ };
5232
+ });
5233
+ }
5234
+ function escrowSpendArtifacts(input) {
5235
+ if (input.escrowSend) {
5236
+ return {
5237
+ escrowSend: true,
5238
+ spendSource: "escrow",
5239
+ ...input.escrowRecipient ? { escrowRecipient: input.escrowRecipient } : {}
5240
+ };
5241
+ }
5242
+ if (input.preparedSpendSource === "escrow") {
5243
+ return {
5244
+ spendSource: "escrow",
5245
+ ...input.escrowRecipient ? { escrowRecipient: input.escrowRecipient } : {},
5246
+ ...input.escrowSpendScalarHex ? { escrowSpendScalarHex: input.escrowSpendScalarHex } : {},
5247
+ ...input.escrowClaimantLimbs ? { escrowClaimantLimbs: input.escrowClaimantLimbs } : {}
5248
+ };
5249
+ }
5250
+ return {};
5251
+ }
5252
+ function buildTransferFinalizeArtifacts(input) {
5253
+ return {
5254
+ proofHex: input.proof.proof_hex,
5255
+ publicHex: input.proof.public_hex,
5256
+ ...ciphertextArtifactsFromProof(input.proof),
5257
+ applicationIdsPlaintext: input.proof.applicationIdsPlaintext,
5258
+ tokenAddress: input.context.tokenAddress,
5259
+ walletPublicKey: input.context.walletPublicKey,
5260
+ executeFinalizeRequired: false,
5261
+ ...escrowSpendArtifacts(input)
5262
+ };
5263
+ }
5264
+ async function runTransferFinalizeSteps(input) {
5265
+ const recipient = await resolveTransferRecipientForExecute(
5266
+ input.prepared,
5267
+ input.environment,
5268
+ input.walletPublicKey
5269
+ );
5270
+ const spendScalarHex = nullifierCheckSpendScalarHex(input.prepared.transactArtifacts);
5271
+ await verifyPrivateRecordsNullifiersBeforeExecute({
5272
+ records: input.prepared.consumedRecords,
5273
+ environment: input.environment,
5274
+ walletPublicKey: input.walletPublicKey,
5275
+ ...spendScalarHex ? { spendScalarHex } : {}
5276
+ });
5277
+ const { context, proof } = await buildTransferProofAtExecute({
5278
+ prepared: input.prepared,
5279
+ environment: input.environment,
5280
+ recipientPrivateAddressStpl1: recipient.recipientPrivateAddressStpl1,
5281
+ ...recipient.escrowSend ? { escrowSend: recipient.escrowSend } : {},
5282
+ ...input.prepared.transactArtifacts?.escrowClaimantLimbs ? {
5283
+ escrowClaimantLimbs: input.prepared.transactArtifacts.escrowClaimantLimbs
5284
+ } : {}
5285
+ });
5286
+ stampEscrowOutputRecords({
5287
+ prepared: input.prepared,
5288
+ proof,
5289
+ walletPublicKey: input.walletPublicKey,
5290
+ ...recipient.escrowSend ? { escrowSendPrivateAddress: recipient.recipientPrivateAddressStpl1 } : {}
5291
+ });
5292
+ return buildTransferFinalizeArtifacts({
5293
+ proof,
5294
+ context,
5295
+ ...sweepFinalizeStamp(input.prepared, recipient)
5296
+ });
5297
+ }
5298
+ function sweepArtifactStamp(artifacts) {
5299
+ return {
5300
+ ...artifacts?.escrowSpendScalarHex ? { escrowSpendScalarHex: artifacts.escrowSpendScalarHex } : {},
5301
+ ...artifacts?.spendSource ? { preparedSpendSource: artifacts.spendSource } : {},
5302
+ ...artifacts?.escrowClaimantLimbs ? { escrowClaimantLimbs: artifacts.escrowClaimantLimbs } : {}
5303
+ };
5304
+ }
5305
+ function sweepFinalizeStamp(prepared, recipient) {
5306
+ const artifacts = prepared.transactArtifacts;
5307
+ const fromSend = recipient.escrowSend?.recipientStellarAddress?.trim();
5308
+ const escrowRecipient = fromSend || artifacts?.escrowRecipient?.trim();
5309
+ return {
5310
+ ...recipient.escrowSend ? { escrowSend: true } : {},
5311
+ ...escrowRecipient ? { escrowRecipient } : {},
5312
+ ...sweepArtifactStamp(artifacts)
5313
+ };
5314
+ }
5315
+ async function finalizeTransferAtExecute(prepared, environment) {
5316
+ const [primaryRecord] = prepared.consumedRecords;
5317
+ if (!primaryRecord?.owner.trim()) {
5318
+ throw new Error("Transfer execution record owner is missing.");
5319
+ }
5320
+ const walletPublicKey = primaryRecord.owner.trim();
5321
+ return runTransferFinalizeSteps({ prepared, environment, walletPublicKey });
5322
+ }
5323
+
5324
+ // src/transact/engine/execute.ts
5325
+ function enrichWithdrawOutputRecords(prepared, proof) {
5326
+ if (!proof.changeCoin || prepared.outputRecords.length === 0) {
5327
+ return;
5328
+ }
5329
+ const changeCoin = proof.changeCoin;
5330
+ prepared.outputRecords = prepared.outputRecords.map((record) => ({
5331
+ ...record,
5332
+ id: changeCoin.commitment_hex,
5333
+ commitmentHex: changeCoin.commitment_hex,
5334
+ coinNote: changeCoin.coin,
5335
+ depositScalarHex: changeCoin.depositScalarHex,
5336
+ precommitementHex: changeCoin.precommitementHex
5337
+ }));
5338
+ }
5339
+ function buildWithdrawFinalizeArtifacts(proof, context) {
5340
+ return {
5341
+ proofHex: proof.proof_hex,
5342
+ publicHex: proof.public_hex,
5343
+ ...ciphertextArtifactsFromProof(proof),
5344
+ applicationIdsPlaintext: proof.applicationIdsPlaintext,
5345
+ tokenAddress: context.tokenAddress,
5346
+ walletPublicKey: context.walletPublicKey,
5347
+ executeFinalizeRequired: false
5348
+ };
5349
+ }
5350
+ async function finalizeSingleWithdrawAtExecute(prepared, environment, poolService, withdrawFrom) {
5351
+ const context = await buildSpendProofContextAtExecute({
5352
+ prepared,
5353
+ environment,
5354
+ recipientPrivateAddressStpl1: withdrawFrom
5355
+ });
5356
+ const changeStroops = BigInt(context.coin.value) - prepared.intent.amount;
5357
+ const proof = await poolService.prepareWithdrawTransactProof({
5358
+ coin: context.coin,
5359
+ state: { commitments: context.commitments },
5360
+ destinationStellarAddress: prepared.intent.to,
5361
+ privKeyScalarHex: context.senderPrivKeyScalarHex,
5362
+ depositorEphemeralKey: serializeEphemeralKeyString({
5363
+ xHex: context.ephemeral.xHex,
5364
+ yHex: context.ephemeral.yHex
5365
+ }),
5366
+ withdrawAmountStroops: prepared.intent.amount,
5367
+ changePrivateAddressStpl1: changeStroops > 0n ? withdrawFrom : void 0,
5368
+ tokenAddress: context.tokenAddress
5369
+ });
5370
+ enrichWithdrawOutputRecords(prepared, proof);
5371
+ return buildWithdrawFinalizeArtifacts(proof, context);
5372
+ }
5373
+ async function finalizeDualWithdrawAtExecute(prepared, environment, poolService, withdrawFrom) {
5374
+ const [, secondaryRecord] = prepared.consumedRecords;
5375
+ if (!secondaryRecord) {
5376
+ throw new Error("Dual withdraw execution requires two private input records.");
5377
+ }
5378
+ const context = await buildSpendProofContextAtExecute({
5379
+ prepared,
5380
+ environment,
5381
+ recipientPrivateAddressStpl1: withdrawFrom
5382
+ });
5383
+ const secondary = await readCoinEphemeralForRecord({
5384
+ record: secondaryRecord,
5385
+ environment,
5386
+ walletPublicKey: context.walletPublicKey,
5387
+ commitments: context.commitments
5388
+ });
5389
+ const totalNotes = BigInt(context.coin.value) + BigInt(secondary.coin.value);
5390
+ const changeStroops = totalNotes - prepared.intent.amount;
5391
+ const proof = await poolService.prepareWithdrawTransactProofDual({
5392
+ coinA: context.coin,
5393
+ coinB: secondary.coin,
5394
+ state: { commitments: context.commitments },
5395
+ destinationStellarAddress: prepared.intent.to,
5396
+ privKeyScalarHex: context.senderPrivKeyScalarHex,
5397
+ depositorEphemeralAKey: serializeEphemeralKeyString({
5398
+ xHex: context.ephemeral.xHex,
5399
+ yHex: context.ephemeral.yHex
5400
+ }),
5401
+ depositorEphemeralBKey: serializeEphemeralKeyString({
5402
+ xHex: secondary.ephemeral.xHex,
5403
+ yHex: secondary.ephemeral.yHex
5404
+ }),
5405
+ withdrawAmountStroops: prepared.intent.amount,
5406
+ changePrivateAddressStpl1: changeStroops > 0n ? withdrawFrom : void 0,
5407
+ tokenAddress: context.tokenAddress
5408
+ });
5409
+ enrichWithdrawOutputRecords(prepared, proof);
5410
+ return buildWithdrawFinalizeArtifacts(proof, context);
5411
+ }
5412
+ async function finalizeWithdrawAtExecute(prepared, environment, poolService) {
5413
+ if (prepared.kind !== "withdraw") {
5414
+ throw new Error("Withdraw finalize requires a withdraw operation.");
5415
+ }
5416
+ const withdrawIntent = prepared.intent;
5417
+ const withdrawFrom = withdrawIntent.from;
5418
+ const recordCount = prepared.consumedRecords.length;
5419
+ if (recordCount === 1) {
5420
+ return finalizeSingleWithdrawAtExecute(
5421
+ prepared,
5422
+ environment,
5423
+ poolService,
5424
+ withdrawFrom
5425
+ );
5426
+ }
5427
+ if (recordCount === 2) {
5428
+ return finalizeDualWithdrawAtExecute(
5429
+ prepared,
5430
+ environment,
5431
+ poolService,
5432
+ withdrawFrom
5433
+ );
5434
+ }
5435
+ throw new Error("Confidential withdraw execution supports at most two input notes.");
5436
+ }
5437
+ async function finalizeSpendOperationAtExecute(prepared, environment, poolService) {
5438
+ if (prepared.kind !== "transfer" && prepared.kind !== "withdraw") {
5439
+ return prepared;
5440
+ }
5441
+ if (prepared.transactArtifacts?.proofHex) {
5442
+ return prepared;
5443
+ }
5444
+ const artifacts = prepared.kind === "transfer" ? await finalizeTransferAtExecute(prepared, environment) : await finalizeWithdrawAtExecute(prepared, environment, poolService);
5445
+ return {
5446
+ ...prepared,
5447
+ transactArtifacts: {
5448
+ ...prepared.transactArtifacts,
5449
+ ...artifacts
5450
+ }
5451
+ };
5452
+ }
5453
+
5454
+ // src/transact/relay/constants.ts
5455
+ var RELAY_TRANSACT_PACKAGE_VERSION_V1 = 1;
5456
+ var RELAY_TRANSACT_SUPPORTED_SIGNAL_COUNT = 93;
5457
+ var RELAY_TRANSACT_FIELD_BYTES = 32;
5458
+ var RELAY_TRANSACT_SIGNAL_PREFIX_BYTES = 4;
5459
+ var RELAY_SIGNAL_INDEX_NULLIFIER_0 = 0;
5460
+ var RELAY_SIGNAL_INDEX_NULLIFIER_1 = 1;
5461
+ var RELAY_SIGNAL_INDEX_STATE_ROOT = 82;
5462
+ var RELAY_SIGNAL_INDEX_WITHDRAW_ADDRESS_HI = 83;
5463
+ var RELAY_SIGNAL_INDEX_WITHDRAW_ADDRESS_LO = 84;
5464
+ var RELAY_SIGNAL_INDEX_ESCROW_RECIPIENT_HI = 85;
5465
+ var RELAY_SIGNAL_INDEX_ESCROW_RECIPIENT_LO = 86;
5466
+ var RELAY_SIGNAL_INDEX_PUBLIC_WITHDRAWAL_ASSET_HI = 87;
5467
+ var RELAY_SIGNAL_INDEX_PUBLIC_WITHDRAWAL_ASSET_LO = 88;
5468
+ var RELAY_SIGNAL_INDEX_PUBLIC_DEPOSIT_ASSET_HI = 89;
5469
+ var RELAY_SIGNAL_INDEX_PUBLIC_DEPOSIT_ASSET_LO = 90;
5470
+ var RELAY_SIGNAL_INDEX_PUBLIC_DEPOSIT = 91;
5471
+ var RELAY_SIGNAL_INDEX_PUBLIC_WITHDRAWAL = 92;
5472
+
5473
+ // src/transact/relay/signals.ts
5474
+ import { Buffer as Buffer15 } from "buffer";
5475
+
5476
+ // src/transact/relay/layout-profile.ts
5477
+ var FIELD_BYTES = 32;
5478
+ var PREFIX_BYTES = 4;
5479
+ var LEGACY_PUBLIC_INPUT_PREFIX_LEN = 5;
5480
+ var V2_PUBLIC_INPUT_PREFIX_LEN = 7;
5481
+ var EPHEMERAL_COORDINATE_COUNT = 2;
5482
+ var STANDARD_SHAPE = {
5483
+ nIns: 2,
5484
+ nOuts: 2,
5485
+ publicNInputs: 1,
5486
+ publicNOutputs: 1,
5487
+ nAuditSlots: 4,
5488
+ noteAuditLen: 12,
5489
+ noteOutputLen: 6
5490
+ };
5491
+ var SIX_BY_SIX_SHAPE = {
5492
+ nIns: 6,
5493
+ nOuts: 6,
5494
+ publicNInputs: 1,
5495
+ publicNOutputs: 1,
5496
+ nAuditSlots: 12,
5497
+ noteAuditLen: 12,
5498
+ noteOutputLen: 6
5499
+ };
5500
+ function profileFromShape(nonce, shape, publicInputPrefixLength, ciphertextsInPublicSignals) {
5501
+ const auditOffset = shape.nIns + shape.nOuts + shape.nOuts * EPHEMERAL_COORDINATE_COUNT;
5502
+ const outputNoteOffset = ciphertextsInPublicSignals ? auditOffset + shape.nAuditSlots * EPHEMERAL_COORDINATE_COUNT + shape.nAuditSlots * shape.noteAuditLen + shape.nAuditSlots : auditOffset + EPHEMERAL_COORDINATE_COUNT + shape.nAuditSlots;
5503
+ const publicOutputsLength = ciphertextsInPublicSignals ? outputNoteOffset + shape.nOuts * shape.noteOutputLen + shape.nOuts : outputNoteOffset + shape.nOuts;
5504
+ const signalCount = publicOutputsLength + publicInputPrefixLength + EPHEMERAL_COORDINATE_COUNT * shape.publicNInputs + EPHEMERAL_COORDINATE_COUNT * shape.publicNOutputs + shape.publicNInputs + shape.publicNOutputs;
5505
+ const stateRoot = publicOutputsLength;
5506
+ return {
5507
+ nonce,
5508
+ signalCount,
5509
+ fieldBytes: FIELD_BYTES,
5510
+ prefixBytes: PREFIX_BYTES,
5511
+ indices: {
5512
+ nullifier0: 0,
5513
+ nullifier1: 1,
5514
+ stateRoot,
5515
+ withdrawAddressHi: stateRoot + 1,
5516
+ withdrawAddressLo: stateRoot + 2,
5517
+ escrowRecipientHi: stateRoot + 3,
5518
+ escrowRecipientLo: stateRoot + 4,
5519
+ publicWithdrawalAssetHi: stateRoot + publicInputPrefixLength,
5520
+ publicWithdrawalAssetLo: stateRoot + publicInputPrefixLength + 1,
5521
+ publicDepositAssetHi: stateRoot + publicInputPrefixLength + 2,
5522
+ publicDepositAssetLo: stateRoot + publicInputPrefixLength + 3,
5523
+ publicDeposit: stateRoot + publicInputPrefixLength + 4,
5524
+ publicWithdrawal: stateRoot + publicInputPrefixLength + 5
5525
+ }
5526
+ };
5527
+ }
5528
+ function relayLayoutProfileForNonce(nonce) {
5529
+ if (nonce === STANDARD_ZK_CONFIG_NONCE) {
5530
+ return profileFromShape(
5531
+ nonce,
5532
+ STANDARD_SHAPE,
5533
+ LEGACY_PUBLIC_INPUT_PREFIX_LEN,
5534
+ true
5535
+ );
5536
+ }
5537
+ if (nonce === COMMITMENT_V2_ZK_NONCE) {
5538
+ return profileFromShape(nonce, STANDARD_SHAPE, V2_PUBLIC_INPUT_PREFIX_LEN, true);
5539
+ }
5540
+ if (nonce === BINDING_ZK_NONCE) {
5541
+ return profileFromShape(nonce, STANDARD_SHAPE, V2_PUBLIC_INPUT_PREFIX_LEN, false);
5542
+ }
5543
+ if (nonce === SIX_BY_SIX_ZK_NONCE) {
5544
+ return profileFromShape(nonce, SIX_BY_SIX_SHAPE, V2_PUBLIC_INPUT_PREFIX_LEN, true);
5545
+ }
5546
+ if (nonce === SIX_BY_SIX_BINDING_ZK_NONCE) {
5547
+ return profileFromShape(nonce, SIX_BY_SIX_SHAPE, V2_PUBLIC_INPUT_PREFIX_LEN, false);
5548
+ }
5549
+ throw new Error(`Unknown ZK config nonce ${nonce.toString()}`);
5550
+ }
5551
+
5552
+ // src/transact/relay/signals.ts
5553
+ function decodePublicSignalBytes(publicSignals) {
5554
+ return Buffer15.from(publicSignals.replace(/^0x/iu, ""), "hex");
5555
+ }
5556
+ function hasSupportedLengthPrefix(bytes, signalCount) {
5557
+ const expected = RELAY_TRANSACT_SIGNAL_PREFIX_BYTES + signalCount * RELAY_TRANSACT_FIELD_BYTES;
5558
+ if (bytes.length !== expected) {
5559
+ return false;
5560
+ }
5561
+ return bytes.readUInt32BE(0) === signalCount;
5562
+ }
5563
+ function assertSupportedPublicSignals(publicSignals, zkConfigNonce = DEFAULT_ZK_CONFIG_NONCE) {
5564
+ const profile = relayLayoutProfileForNonce(zkConfigNonce);
5565
+ const bytes = decodePublicSignalBytes(publicSignals);
5566
+ const supportedBytes = profile.signalCount * RELAY_TRANSACT_FIELD_BYTES;
5567
+ if (bytes.length === supportedBytes || hasSupportedLengthPrefix(bytes, profile.signalCount)) {
5568
+ return;
5569
+ }
5570
+ throw new Error(
5571
+ `Relay Transact Package V1 requires exactly ${String(profile.signalCount)} packed public signals.`
5572
+ );
5573
+ }
5574
+ function sliceSupportedPublicSignalFields(publicSignals, zkConfigNonce = DEFAULT_ZK_CONFIG_NONCE) {
5575
+ assertSupportedPublicSignals(publicSignals, zkConfigNonce);
5576
+ const profile = relayLayoutProfileForNonce(zkConfigNonce);
5577
+ const bytes = decodePublicSignalBytes(publicSignals);
5578
+ const body = hasSupportedLengthPrefix(bytes, profile.signalCount) ? bytes.subarray(RELAY_TRANSACT_SIGNAL_PREFIX_BYTES) : bytes;
5579
+ return Array.from(
5580
+ { length: profile.signalCount },
5581
+ (_unused, index) => Buffer15.from(
5582
+ body.subarray(
5583
+ index * RELAY_TRANSACT_FIELD_BYTES,
5584
+ (index + 1) * RELAY_TRANSACT_FIELD_BYTES
5585
+ )
5586
+ )
5587
+ );
5588
+ }
5589
+
5590
+ // src/transact/relay/prepare.ts
5591
+ function normalizeHex(value) {
5592
+ return value.replace(/^0x/iu, "").toLowerCase();
5593
+ }
5594
+ function prepareRelayTransactPackage(input) {
5595
+ const zkConfigNonce = input.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
5596
+ assertSupportedPublicSignals(input.publicSignals, zkConfigNonce);
5597
+ const prepared = {
5598
+ version: RELAY_TRANSACT_PACKAGE_VERSION_V1,
5599
+ poolSelector: input.poolSelector,
5600
+ zkConfigNonce,
5601
+ proofBytes: normalizeHex(input.proofBytes),
5602
+ publicSignals: normalizeHex(input.publicSignals),
5603
+ applicationIdHints: input.applicationIdHints
5604
+ };
5605
+ if (input.ciphertextBytes) {
5606
+ prepared.ciphertextBytes = normalizeHex(input.ciphertextBytes);
5607
+ }
5608
+ if (input.outputNoteEphemeralScalars) {
5609
+ prepared.outputNoteEphemeralScalars = [...input.outputNoteEphemeralScalars];
5610
+ }
5611
+ if (input.escrowAuthorization) {
5612
+ prepared.escrowAuthorization = input.escrowAuthorization;
5613
+ }
5614
+ if (input.keyVersionHints) {
5615
+ prepared.keyVersionHints = input.keyVersionHints;
5616
+ }
5617
+ return prepared;
5618
+ }
5619
+
5620
+ // src/transact/relay/from-prepared.ts
5621
+ function requirePreparedArtifacts(prepared) {
5622
+ const artifacts = prepared.transactArtifacts;
5623
+ if (!artifacts?.proofHex || !artifacts.publicHex || !artifacts.applicationIdsPlaintext) {
5624
+ throw new Error("Prepared operation is missing transact artifacts.");
5625
+ }
5626
+ return {
5627
+ proofBytes: artifacts.proofHex,
5628
+ publicSignals: artifacts.publicHex,
5629
+ applicationIdHints: artifacts.applicationIdsPlaintext,
5630
+ ...artifacts.ciphertextHex ? { ciphertextBytes: artifacts.ciphertextHex } : {},
5631
+ ...artifacts.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: artifacts.outputNoteEphemeralScalars } : {},
5632
+ ...artifacts.escrowAuthorization ? { escrowAuthorization: artifacts.escrowAuthorization } : {}
5633
+ };
5634
+ }
5635
+ function prepareRelayTransactPackageFromPrepared(input) {
5636
+ return prepareRelayTransactPackage({
5637
+ poolSelector: input.poolSelector,
5638
+ ...requirePreparedArtifacts(input.prepared),
5639
+ ...input.zkConfigNonce === void 0 ? {} : { zkConfigNonce: input.zkConfigNonce },
5640
+ ...input.keyVersionHints ? { keyVersionHints: input.keyVersionHints } : {}
5641
+ });
5642
+ }
5643
+
5644
+ // src/transact/relay/profile.ts
5645
+ function fieldAt(fields, index) {
5646
+ const field = fields.find((_unused, offset) => offset === index);
5647
+ if (!field) {
5648
+ throw new Error(`Missing packed public signal at index ${String(index)}.`);
5649
+ }
5650
+ return field;
5651
+ }
5652
+ function fieldHex2(fields, index) {
5653
+ return fieldAt(fields, index).toString("hex");
5654
+ }
5655
+ function fieldAmount(fields, index) {
5656
+ return BigInt(`0x${fieldAt(fields, index).toString("hex")}`).toString();
5657
+ }
5658
+ function readRelayTransactSupportedProfile(prepared) {
5659
+ const layout = relayLayoutProfileForNonce(prepared.zkConfigNonce);
5660
+ const fields = sliceSupportedPublicSignalFields(
5661
+ prepared.publicSignals,
5662
+ prepared.zkConfigNonce
5663
+ );
5664
+ const { indices } = layout;
5665
+ return {
5666
+ orderedNullifiers: [
5667
+ fieldHex2(fields, indices.nullifier0),
5668
+ fieldHex2(fields, indices.nullifier1)
5669
+ ],
5670
+ publicLegContext: {
5671
+ stateRoot: fieldHex2(fields, indices.stateRoot),
5672
+ withdrawAddressHi: fieldHex2(fields, indices.withdrawAddressHi),
5673
+ withdrawAddressLo: fieldHex2(fields, indices.withdrawAddressLo),
5674
+ escrowRecipientHi: fieldHex2(fields, indices.escrowRecipientHi),
5675
+ escrowRecipientLo: fieldHex2(fields, indices.escrowRecipientLo),
5676
+ publicWithdrawalAssetHi: fieldHex2(fields, indices.publicWithdrawalAssetHi),
5677
+ publicWithdrawalAssetLo: fieldHex2(fields, indices.publicWithdrawalAssetLo),
5678
+ publicDepositAssetHi: fieldHex2(fields, indices.publicDepositAssetHi),
5679
+ publicDepositAssetLo: fieldHex2(fields, indices.publicDepositAssetLo),
5680
+ publicDepositAmount: fieldAmount(fields, indices.publicDeposit),
5681
+ publicWithdrawalAmount: fieldAmount(fields, indices.publicWithdrawal)
5682
+ }
5683
+ };
5684
+ }
5685
+
5686
+ // src/transact/relay/required-submission-method.ts
5687
+ var ZERO_PUBLIC_DEPOSIT = 0n;
5688
+ var SUBMISSION_METHOD = {
5689
+ direct: "direct",
5690
+ relay: "relay"
5691
+ };
5692
+ var ESCROW_SUBMISSION_REFUSAL = {
5693
+ positivePublicDeposit: "escrow_positive_public_deposit"
5694
+ };
5695
+ var EscrowSubmissionRefusedError = class extends Error {
5696
+ reason;
5697
+ constructor(reason) {
5698
+ super(reason);
5699
+ this.name = "EscrowSubmissionRefusedError";
5700
+ this.reason = reason;
5701
+ }
5702
+ };
5703
+ function isEscrowPreparedOperation(prepared) {
5704
+ return prepared.transactArtifacts?.escrowSend === true || prepared.transactArtifacts?.spendSource === "escrow";
5705
+ }
5706
+ function publicDepositAmountFromPrepared(prepared, zkConfigNonce) {
5707
+ const publicHex = prepared.transactArtifacts?.publicHex;
5708
+ if (!publicHex) {
5709
+ return void 0;
5710
+ }
5711
+ const layout = relayLayoutProfileForNonce(zkConfigNonce);
5712
+ const fields = sliceSupportedPublicSignalFields(publicHex, zkConfigNonce);
5713
+ const field = fields.find(
5714
+ (_unused, offset) => offset === layout.indices.publicDeposit
5715
+ );
5716
+ if (!field) {
5717
+ throw new Error(
5718
+ `Missing packed public signal at index ${String(layout.indices.publicDeposit)}.`
5719
+ );
5720
+ }
5721
+ return BigInt(`0x${field.toString("hex")}`);
5722
+ }
5723
+ function evaluateRequiredSubmissionMethod(prepared, zkConfigNonce = DEFAULT_ZK_CONFIG_NONCE) {
5724
+ const publicDepositAmount = publicDepositAmountFromPrepared(prepared, zkConfigNonce);
5725
+ if (isEscrowPreparedOperation(prepared)) {
5726
+ if (publicDepositAmount !== void 0 && publicDepositAmount > ZERO_PUBLIC_DEPOSIT) {
5727
+ return { refused: ESCROW_SUBMISSION_REFUSAL.positivePublicDeposit };
5728
+ }
5729
+ if (prepared.transactArtifacts?.escrowSend === true) {
5730
+ return { method: SUBMISSION_METHOD.relay };
5731
+ }
5732
+ return { method: SUBMISSION_METHOD.direct };
5733
+ }
5734
+ if (publicDepositAmount === void 0) {
5735
+ throw new Error("Prepared operation is missing transact artifacts.");
5736
+ }
5737
+ return {
5738
+ method: publicDepositAmount > ZERO_PUBLIC_DEPOSIT ? SUBMISSION_METHOD.direct : SUBMISSION_METHOD.relay
5739
+ };
5740
+ }
5741
+ function requiredSubmissionMethod(prepared, zkConfigNonce = DEFAULT_ZK_CONFIG_NONCE) {
5742
+ const result = evaluateRequiredSubmissionMethod(prepared, zkConfigNonce);
5743
+ if ("refused" in result) {
5744
+ throw new EscrowSubmissionRefusedError(result.refused);
5745
+ }
5746
+ return result.method;
5747
+ }
4254
5748
  export {
5749
+ BundledZkCircuit2 as BundledZkCircuit,
5750
+ COMMITMENT_V2_ZK_NONCE,
4255
5751
  DEFAULT_STEALTH_SIGN_NONCE as DEFAULT_PRIVATE_ADDRESS_SIGN_NONCE,
5752
+ DEFAULT_STELLAR_ZK_CIRCUITS,
5753
+ DEFAULT_ZK_CONFIG_NONCE,
5754
+ ESCROW_SUBMISSION_REFUSAL,
5755
+ EscrowSubmissionRefusedError,
4256
5756
  KytInspectError,
4257
5757
  MIN_CONFIDENTIAL_TRANSFER_STROOPS,
5758
+ OWNER_BOUND_NOTE_SCHEMA_VERSION,
4258
5759
  PrivacyPoolService,
5760
+ RELAY_SIGNAL_INDEX_ESCROW_RECIPIENT_HI,
5761
+ RELAY_SIGNAL_INDEX_ESCROW_RECIPIENT_LO,
5762
+ RELAY_SIGNAL_INDEX_NULLIFIER_0,
5763
+ RELAY_SIGNAL_INDEX_NULLIFIER_1,
5764
+ RELAY_SIGNAL_INDEX_PUBLIC_DEPOSIT,
5765
+ RELAY_SIGNAL_INDEX_PUBLIC_DEPOSIT_ASSET_HI,
5766
+ RELAY_SIGNAL_INDEX_PUBLIC_DEPOSIT_ASSET_LO,
5767
+ RELAY_SIGNAL_INDEX_PUBLIC_WITHDRAWAL,
5768
+ RELAY_SIGNAL_INDEX_PUBLIC_WITHDRAWAL_ASSET_HI,
5769
+ RELAY_SIGNAL_INDEX_PUBLIC_WITHDRAWAL_ASSET_LO,
5770
+ RELAY_SIGNAL_INDEX_STATE_ROOT,
5771
+ RELAY_SIGNAL_INDEX_WITHDRAW_ADDRESS_HI,
5772
+ RELAY_SIGNAL_INDEX_WITHDRAW_ADDRESS_LO,
5773
+ RELAY_TRANSACT_FIELD_BYTES,
5774
+ RELAY_TRANSACT_PACKAGE_VERSION_V1,
5775
+ RELAY_TRANSACT_SIGNAL_PREFIX_BYTES,
5776
+ RELAY_TRANSACT_SUPPORTED_SIGNAL_COUNT,
5777
+ SIX_BY_SIX_ZK_NONCE,
5778
+ STANDARD_ZK_CONFIG_NONCE,
5779
+ SUBMISSION_METHOD,
4259
5780
  ZERO_STROOPS,
5781
+ assertEscrowSweepClaimant,
4260
5782
  assetLegToTokenAddress,
5783
+ attachEscrowAuthorization,
4261
5784
  attachPoolStatePorts,
4262
- buildOnboardingPayload,
5785
+ buildBlindedRecipientTagChallengeMessage,
4263
5786
  buildPoolTransactionAuditParameters,
4264
5787
  buildPrivateAddressSignMessage,
4265
- buildTransferOnboardingAtExecute,
4266
5788
  configurePrivacyPoolService,
4267
5789
  createPrivacyPoolService,
4268
5790
  decodePrivateAddress,
5791
+ deriveEscrowRecipientFromStellarAddress,
4269
5792
  encodePrivateAddress,
4270
5793
  encodePrivateAddressFromHexCoordinates,
5794
+ evaluateRequiredSubmissionMethod,
4271
5795
  fetchAndMergeMerkleState,
5796
+ fetchEscrowOutputNoteEvents,
5797
+ finalizeSpendOperationAtExecute,
4272
5798
  frDecimalToPaddedBytes32,
4273
5799
  generateRandomDepositScalarHex,
4274
5800
  generateTemporaryRecipientPrivateAddress,
4275
5801
  getPrivacyPoolService,
5802
+ isEscrowPreparedOperation,
4276
5803
  loadDefaultStellarBrowserAssets,
4277
5804
  loadStellarBrowserAssets,
5805
+ optionalZkArtifactBaseUrl,
4278
5806
  parseAuditPublicKeyFromEnvHex,
4279
5807
  parseKytReasonCode,
4280
5808
  prepareConfidentialTransferProof,
4281
5809
  prepareConfidentialTransferProofDual,
5810
+ prepareEscrowSweepOperation,
5811
+ prepareRelayTransactPackage,
5812
+ prepareRelayTransactPackageFromPrepared,
4282
5813
  privateAddressSdk,
4283
5814
  readLeafEphemeralHex,
5815
+ readRelayTransactSupportedProfile,
4284
5816
  recipientPublicKeysDecimalFromPrivateAddress,
5817
+ reconstructEscrowNote,
4285
5818
  requestKytPassageForPoolInteraction,
5819
+ requiredSubmissionMethod,
4286
5820
  resolvePoolApplicationId,
5821
+ resolveZkConfigNonce,
4287
5822
  runTtlPreflight,
5823
+ spendScalarHexFromStellarSignature,
4288
5824
  submitSorobanConfidentialTransfer,
4289
5825
  submitSorobanDeposit,
4290
- tokenAddressToAssetLeg
5826
+ tokenAddressToAssetLeg,
5827
+ unsignedEscrowAuthorizationForSweep
4291
5828
  };
4292
5829
  //# sourceMappingURL=index.js.map