@arcanetech/privacy-sdk-stellar 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/node.js CHANGED
@@ -3,12 +3,8 @@ import "@arcanetech/privacy-sdk-core";
3
3
 
4
4
  // src/assets/load-node.ts
5
5
  async function loadNodeAssets(assets) {
6
- const [sdkWasm, circuitWasm, provingKey] = await Promise.all([
7
- readAssetFile(assets.sdkWasmPath),
8
- readAssetFile(assets.circuitWasmPath),
9
- readAssetFile(assets.provingKeyPath)
10
- ]);
11
- return { sdkWasm, circuitWasm, provingKey };
6
+ const sdkWasm = await readAssetFile(assets.sdkWasmPath);
7
+ return { sdkWasm };
12
8
  }
13
9
  async function readAssetFile(path) {
14
10
  const { readFile } = await import("fs/promises");
@@ -62,16 +58,6 @@ import {
62
58
  import {
63
59
  unsupportedDisclosureError
64
60
  } from "@arcanetech/privacy-sdk-core";
65
-
66
- // src/transact/transfer-source/types.ts
67
- function isPendingClaimSource(from) {
68
- return typeof from === "object" && "kind" in from && from.kind === "pendingClaim";
69
- }
70
- function isPrivateAddressTransferFrom(from) {
71
- return typeof from === "string";
72
- }
73
-
74
- // src/policy/disclosure-routes.ts
75
61
  function validatePublicRecipientTransferDisclosure(disclosure) {
76
62
  const errors = [];
77
63
  const fields = [
@@ -98,38 +84,9 @@ function validatePublicRecipientTransferDisclosure(disclosure) {
98
84
  }
99
85
  return errors;
100
86
  }
101
- function validatePendingClaimTransferDisclosure(disclosure) {
102
- const errors = [];
103
- const fields = [
104
- "senderAddress",
105
- "assetAddress",
106
- "amount"
107
- ];
108
- const messages = {
109
- senderAddress: "Pending claim transfers must publish the sender address.",
110
- assetAddress: "Pending claim transfers must publish the asset identifier.",
111
- amount: "Pending claim transfers must publish the transfer amount."
112
- };
113
- for (const field of fields) {
114
- if (disclosure[field] === "private") {
115
- errors.push(
116
- unsupportedDisclosureError(
117
- field,
118
- "private",
119
- ["public"],
120
- messages[field] ?? "This transfer route requires public disclosure."
121
- )
122
- );
123
- }
124
- }
125
- return errors;
126
- }
127
87
  function isPublicStellarRecipientTransfer(intent) {
128
88
  return intent.disclosure.recipientAddress === "public";
129
89
  }
130
- function isPendingClaimTransfer(intent) {
131
- return isPendingClaimSource(intent.from);
132
- }
133
90
 
134
91
  // src/policy/disclosure.ts
135
92
  function isPublicWithdrawRoute(intent) {
@@ -152,9 +109,6 @@ function validateStellarDisclosure(kind, intent) {
152
109
  if (kind === "transfer" && isPublicStellarRecipientTransfer(intent)) {
153
110
  errors.push(...validatePublicRecipientTransferDisclosure(intent.disclosure));
154
111
  }
155
- if (kind === "transfer" && isPendingClaimTransfer(intent)) {
156
- errors.push(...validatePendingClaimTransferDisclosure(intent.disclosure));
157
- }
158
112
  if (kind === "withdraw" && isPublicWithdrawRoute(intent)) {
159
113
  rejectPrivatePublicRouteFields(
160
114
  intent,
@@ -350,118 +304,26 @@ function handleSubmissionFailure(error, options, eventId) {
350
304
  }
351
305
 
352
306
  // src/adapters/record-selection.ts
353
- import { insufficientStateError as insufficientStateError3 } from "@arcanetech/privacy-sdk-core";
307
+ import { insufficientStateError as insufficientStateError2 } from "@arcanetech/privacy-sdk-core";
354
308
 
355
- // src/transact/transfer-source/resolve.ts
356
- import { Buffer as Buffer2 } from "buffer";
357
- import {
358
- insufficientStateError,
359
- invalidIntentError
360
- } from "@arcanetech/privacy-sdk-core";
361
- var FIELD_HEX_LENGTH = 64;
362
- var SCALAR_HEX_PATTERN = new RegExp(`^(0x)?[0-9a-f]{${FIELD_HEX_LENGTH}}$`, "iu");
363
- function hexToDecimal(hex) {
364
- const clean = (hex ?? "").trim().replace(/^0x/u, "");
365
- return BigInt(`0x${clean || "0"}`).toString();
366
- }
367
- function recoveryScalarHexFromClaim(claim) {
368
- const encoded = claim.encryptedRecoveryBase64?.trim();
369
- if (!encoded) {
370
- throw invalidIntentError(
371
- "from",
372
- "Pending claim is missing encrypted recovery data."
373
- );
374
- }
375
- const scalar = Buffer2.from(encoded, "base64").toString("utf8").trim();
376
- if (!SCALAR_HEX_PATTERN.test(scalar)) {
377
- throw invalidIntentError("from", "Pending claim recovery payload is not a scalar.");
378
- }
379
- return scalar.replace(/^0x/iu, "");
380
- }
381
- function pendingClaimToCoin(claim) {
382
- return {
383
- value: claim.amount.toString(),
384
- nullifier: hexToDecimal(claim.nullifierFieldHex),
385
- secret: hexToDecimal(claim.secretHex),
386
- commitment: hexToDecimal(claim.commitmentHex),
387
- asset_hi: hexToDecimal(claim.assetHiHex),
388
- asset_lo: hexToDecimal(claim.assetLoHex)
389
- };
390
- }
391
- function pendingClaimToConsumedRecord(input) {
392
- const coin = pendingClaimToCoin(input.claim);
393
- const nullifierHex = input.claim.nullifierHex ?? input.claim.futureNullifierHashHex;
394
- return {
395
- id: `pending-claim-${input.claim.id}`,
396
- owner: input.walletPublicKey.trim(),
397
- asset: input.claim.asset,
398
- amount: input.claim.amount,
399
- consumed: false,
400
- status: "finalized",
401
- poolContract: input.poolContract,
402
- coinNote: coin,
403
- ...input.claim.commitmentHex ? { commitmentHex: input.claim.commitmentHex } : {},
404
- ...nullifierHex ? { nullifierHex } : {}
405
- };
406
- }
407
- function readPendingClaimFromSource(source) {
408
- if ("claim" in source) {
409
- return source.claim;
410
- }
411
- return void 0;
412
- }
413
- async function resolvePendingClaimSource(input) {
414
- const embedded = readPendingClaimFromSource(input.from);
415
- if (embedded) {
416
- return embedded;
417
- }
418
- if (!("claimId" in input.from)) {
419
- throw invalidIntentError("from", "Pending claim id is required.");
420
- }
421
- const claimId = input.from.claimId.trim();
422
- if (!claimId) {
423
- throw invalidIntentError("from", "Pending claim id is required.");
424
- }
425
- const claims = await input.getPendingClaims();
426
- const claim = claims.items.find((entry) => entry.id === claimId);
427
- if (!claim) {
428
- throw insufficientStateError(
429
- "pending_claim_not_found",
430
- "Pending claim was not found in local state.",
431
- { claimId }
432
- );
433
- }
434
- return claim;
435
- }
436
- function assertPendingClaimOwner(input) {
437
- const owner = input.claim.owner.trim();
438
- const wallet = input.walletPublicKey.trim();
439
- if (owner !== wallet) {
440
- throw insufficientStateError(
441
- "pending_claim_owner_mismatch",
442
- "Pending claim owner does not match the connected wallet.",
443
- { claimOwner: owner, walletPublicKey: wallet }
444
- );
445
- }
309
+ // src/transact/transfer-source/types.ts
310
+ function isPrivateAddressTransferFrom(from) {
311
+ return typeof from === "string";
446
312
  }
313
+
314
+ // src/transact/transfer-source/resolve.ts
447
315
  function readTransferFromPrivateAddress(from) {
448
- if (isPendingClaimSource(from)) {
449
- throw invalidIntentError(
450
- "from",
451
- "Private address is unavailable for a pending claim transfer source."
452
- );
453
- }
454
316
  return from.trim();
455
317
  }
456
318
 
457
- // src/transact/transfer-source/verify.ts
458
- import { executionError as executionError3 } from "@arcanetech/privacy-sdk-core";
319
+ // src/transact/transfer-source/verify-private-records.ts
320
+ import { executionError as executionError3, insufficientStateError } from "@arcanetech/privacy-sdk-core";
459
321
 
460
322
  // src/contracts/pool/pool-domain-service.ts
461
- import { Buffer as Buffer3 } from "buffer";
323
+ import { Buffer as Buffer2 } from "buffer";
462
324
  function hexToBuffer(hex) {
463
325
  const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
464
- return Buffer3.from(clean, "hex");
326
+ return Buffer2.from(clean, "hex");
465
327
  }
466
328
  async function readNullifierConsumedOnChain(input) {
467
329
  const client = input.contractContext.createPoolClient({
@@ -575,15 +437,45 @@ function readPoolClientFactory(environment) {
575
437
  return requireContractContext(environment).createPoolClient;
576
438
  }
577
439
 
440
+ // src/transact/private-address/record-coin.ts
441
+ function requireCoinNoteFromRecord(record) {
442
+ if (!record.coinNote) {
443
+ throw new Error(`Private record ${record.id} is missing coin note data.`);
444
+ }
445
+ return record.coinNote;
446
+ }
447
+ function findCommitmentLeafIndex(commitments, commitment) {
448
+ return commitments.indexOf(commitment);
449
+ }
450
+ function buildPrivateRecordFromDeposit(input) {
451
+ return {
452
+ id: input.commitmentHex,
453
+ owner: input.owner,
454
+ asset: input.assetId,
455
+ amount: input.amount,
456
+ consumed: false,
457
+ status: input.status ?? "pending",
458
+ poolContract: input.poolContract,
459
+ commitmentHex: input.commitmentHex,
460
+ privateAddress: input.privateAddress,
461
+ amountDisplay: input.amountDisplay,
462
+ coinNote: input.coin,
463
+ depositScalarHex: input.depositScalarHex,
464
+ precommitementHex: input.precommitementHex,
465
+ ...input.txHash ? { txHash: input.txHash } : {}
466
+ };
467
+ }
468
+
578
469
  // src/transact/pool/service.ts
579
470
  import {
471
+ PrivacyPoolSDK as PrivacyPoolSDK2,
580
472
  decodeDecodedEphemeralKey,
581
473
  randomFrDecimal253,
582
474
  scalarHexToFrDecimal as scalarHexToFrDecimal2
583
- } from "@auditable/privacy-pool-zk-sdk";
475
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
584
476
 
585
477
  // src/transact/merkle/field-decimal.ts
586
- import { Buffer as Buffer5 } from "buffer";
478
+ import { Buffer as Buffer4 } from "buffer";
587
479
  var BN254 = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
588
480
  var MERKLE_ROOT_BYTE_LENGTH = 32;
589
481
  var DECIMAL_STRING_RADIX = 10;
@@ -593,7 +485,7 @@ function merkleRootBufferToFrDecimal(root) {
593
485
  `expected ${MERKLE_ROOT_BYTE_LENGTH}-byte merkle root, got ${root.length}`
594
486
  );
595
487
  }
596
- const hex = Buffer5.from(root).toString("hex");
488
+ const hex = Buffer4.from(root).toString("hex");
597
489
  return (BigInt(`0x${hex}`) % BN254).toString(DECIMAL_STRING_RADIX);
598
490
  }
599
491
 
@@ -603,8 +495,12 @@ import {
603
495
  decodeStealthAddress,
604
496
  encodeStealthAddress,
605
497
  recipientPublicKeysDecimalFromStealthAddress
606
- } from "@auditable/privacy-pool-zk-sdk";
607
- import { DEFAULT_STEALTH_SIGN_NONCE } from "@auditable/privacy-pool-zk-sdk";
498
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
499
+ import { DEFAULT_STEALTH_SIGN_NONCE } from "@arcanetech/stellar-privacy-pool-zk-sdk";
500
+ import {
501
+ OWNER_BOUND_NOTE_SCHEMA_VERSION,
502
+ spendScalarHexFromStellarSignature
503
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
608
504
  function decodePrivateAddress(value) {
609
505
  const decodeAddress = decodeStealthAddress;
610
506
  return decodeAddress(value);
@@ -633,26 +529,26 @@ function privateAddressSdk(sdk) {
633
529
  );
634
530
  }
635
531
  return {
636
- generatePrivateAddressFromStellarSignature: (signature) => generator.call(sdk, signature)
532
+ generatePrivateAddressFromStellarSignature: (signature, domain) => generator.call(sdk, signature, domain)
637
533
  };
638
534
  }
639
535
 
640
536
  // src/transact/proofs/withdraw/transact-proof.ts
641
- import { withdrawObjectFromMerkleWitness as withdrawObjectFromMerkleWitness2 } from "@auditable/privacy-pool-zk-sdk";
537
+ import { withdrawObjectFromMerkleWitness as withdrawObjectFromMerkleWitness2 } from "@arcanetech/stellar-privacy-pool-zk-sdk";
642
538
 
643
539
  // src/transact/proofs/transaction-input.ts
644
- import { Buffer as Buffer7 } from "buffer";
540
+ import { Buffer as Buffer6 } from "buffer";
645
541
  import { StrKey as StrKey2 } from "@stellar/stellar-sdk";
646
542
 
647
543
  // src/transact/stellar/token-contract.ts
648
- import { Buffer as Buffer6 } from "buffer";
544
+ import { Buffer as Buffer5 } from "buffer";
649
545
  import { StrKey } from "@stellar/stellar-sdk";
650
546
  var CONTRACT_ID_BYTE_LENGTH = 32;
651
547
  var HEX_CHARS_PER_BYTE = 2;
652
548
  var CONTRACT_ID_HEX_CHAR_LENGTH = CONTRACT_ID_BYTE_LENGTH * HEX_CHARS_PER_BYTE;
653
549
  var CONTRACT_ID_HEX = /^(?:0x)?([0-9a-f]{64})$/i;
654
550
  function encodeContractFromHex(hexPayload) {
655
- return StrKey.encodeContract(Buffer6.from(hexPayload, "hex"));
551
+ return StrKey.encodeContract(Buffer5.from(hexPayload, "hex"));
656
552
  }
657
553
  function normalizeSorobanContractId(raw) {
658
554
  const trimmed = raw.trim();
@@ -678,10 +574,14 @@ function resolveTokenContractId(tokenContractRaw) {
678
574
  }
679
575
 
680
576
  // src/transact/proofs/transaction-input.ts
577
+ var ZERO_PUBLIC_WITHDRAW_ADDRESS = {
578
+ withdrawAddressHi: "0",
579
+ withdrawAddressLo: "0"
580
+ };
681
581
  var CONTRACT_ADDRESS_HALF_BYTES = 16;
682
582
  var CONTRACT_ADDRESS_BYTES = 32;
683
583
  function bytes16ToDecimal(bytes) {
684
- return BigInt(`0x${Buffer7.from(bytes).toString("hex")}`).toString();
584
+ return BigInt(`0x${Buffer6.from(bytes).toString("hex")}`).toString();
685
585
  }
686
586
  function tokenAddressFrParts(tokenAddress) {
687
587
  const normalized = resolveTokenContractId(tokenAddress);
@@ -697,98 +597,116 @@ function withTokenAddressPublicInputs(base, tokenAddress) {
697
597
  return {
698
598
  ...base,
699
599
  tokenAddressHi: hi,
700
- tokenAddressLo: lo
600
+ tokenAddressLo: lo,
601
+ withdrawAddressHi: base.withdrawAddressHi ?? ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressHi,
602
+ withdrawAddressLo: base.withdrawAddressLo ?? ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressLo,
603
+ escrowRecipientHi: base.escrowRecipientHi ?? "0",
604
+ escrowRecipientLo: base.escrowRecipientLo ?? "0",
605
+ sweepOutputOwnerPubX: base.sweepOutputOwnerPubX ?? "0",
606
+ sweepOutputOwnerPubY: base.sweepOutputOwnerPubY ?? "0"
607
+ };
608
+ }
609
+ function publicWithdrawAddressLimbs(parameters) {
610
+ if (parameters.publicWithdrawalAmount === "0") {
611
+ return {
612
+ withdrawAddressHi: ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressHi,
613
+ withdrawAddressLo: ZERO_PUBLIC_WITHDRAW_ADDRESS.withdrawAddressLo
614
+ };
615
+ }
616
+ return {
617
+ withdrawAddressHi: parameters.destinationHi,
618
+ withdrawAddressLo: parameters.destinationLo
701
619
  };
702
620
  }
703
621
  function tokenAddressToAssetLeg(tokenAddress) {
704
622
  const { hi, lo } = tokenAddressFrParts(tokenAddress);
705
623
  return [hi, lo];
706
624
  }
707
- function buildZeroPublicLegs() {
625
+ function buildZeroPublicLegs(publicNInputs = 1, publicNOutputs = 1) {
708
626
  return {
709
- publicWithdrawnAssets: [["0", "0"]],
710
- publicDepositedAssets: [["0", "0"]],
711
- publicDeposits: ["0"],
712
- publicWithdrawals: ["0"]
627
+ publicWithdrawnAssets: Array.from(
628
+ { length: publicNOutputs },
629
+ () => ["0", "0"]
630
+ ),
631
+ publicDepositedAssets: Array.from(
632
+ { length: publicNInputs },
633
+ () => ["0", "0"]
634
+ ),
635
+ publicDeposits: Array.from({ length: publicNInputs }, () => "0"),
636
+ publicWithdrawals: Array.from({ length: publicNOutputs }, () => "0")
713
637
  };
714
638
  }
715
- function buildPublicDepositLegs(tokenAddress, amount) {
716
- const legs = buildZeroPublicLegs();
639
+ function buildPublicDepositLegs(tokenAddress, amount, publicNInputs = 1, publicNOutputs = 1) {
640
+ const legs = buildZeroPublicLegs(publicNInputs, publicNOutputs);
717
641
  return {
718
642
  ...legs,
719
- publicDepositedAssets: [tokenAddressToAssetLeg(tokenAddress)],
720
- publicDeposits: [amount]
643
+ publicDepositedAssets: [
644
+ tokenAddressToAssetLeg(tokenAddress),
645
+ ...legs.publicDepositedAssets.slice(1)
646
+ ],
647
+ publicDeposits: [amount, ...legs.publicDeposits.slice(1)]
721
648
  };
722
649
  }
723
- function buildPublicWithdrawLegs(tokenAddress, amount) {
724
- const legs = buildZeroPublicLegs();
650
+ function buildPublicWithdrawLegs(tokenAddress, amount, publicNInputs = 1, publicNOutputs = 1) {
651
+ const legs = buildZeroPublicLegs(publicNInputs, publicNOutputs);
725
652
  return {
726
653
  ...legs,
727
- publicWithdrawnAssets: [tokenAddressToAssetLeg(tokenAddress)],
728
- publicWithdrawals: [amount]
654
+ publicWithdrawnAssets: [
655
+ tokenAddressToAssetLeg(tokenAddress),
656
+ ...legs.publicWithdrawnAssets.slice(1)
657
+ ],
658
+ publicWithdrawals: [amount, ...legs.publicWithdrawals.slice(1)]
729
659
  };
730
660
  }
731
661
 
732
- // src/transact/proofs/confidential/helpers.ts
662
+ // src/transact/zk/slots.ts
733
663
  import {
734
- ed25519PubkeyPayloadHexToWithdrawFrDecimals,
735
- withdrawObjectFromMerkleWitness
736
- } from "@auditable/privacy-pool-zk-sdk";
737
- import { StrKey as StrKey3 } from "@stellar/stellar-sdk";
738
- import { Buffer as Buffer8 } from "buffer";
739
-
740
- // src/transact/encoding/priv-key-scalar-from-recipient-hex.ts
741
- import { BN254_BABYJUB_SCALAR_MAX_EXCLUSIVE } from "@auditable/privacy-pool-zk-sdk";
742
- var SCALAR_HEX_CHAR_LENGTH = 64;
743
- var DECIMAL_RADIX = 10;
744
- var BIGINT_ONE = 1n;
745
- function normalizeRecipientScalarHex(hexInput) {
746
- const trimmed = hexInput.trim().replace(/^0x/iu, "");
747
- if (!/^[0-9a-f]*$/iu.test(trimmed)) {
748
- throw new Error("recipient scalar hex must be hexadecimal");
749
- }
750
- const withLeadingNibble = trimmed.length % 2 === 0 ? trimmed : `0${trimmed}`;
751
- const lower = withLeadingNibble.toLowerCase();
752
- const padded = lower.padStart(SCALAR_HEX_CHAR_LENGTH, "0").slice(-SCALAR_HEX_CHAR_LENGTH);
753
- if (padded.length !== SCALAR_HEX_CHAR_LENGTH) {
664
+ padDepositSlots,
665
+ padPublicLegs,
666
+ padWithdrawSlots
667
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
668
+ function padWithdrawSlotsToLayout(sdk, slots) {
669
+ return padWithdrawSlots(slots, sdk.getLayout().nIns);
670
+ }
671
+ function padDepositSlotsToLayout(sdk, slots) {
672
+ return padDepositSlots(slots, sdk.getLayout().nOuts);
673
+ }
674
+ function padPublicLegsToLayout(sdk, legs) {
675
+ const { publicNInputs, publicNOutputs } = sdk.getLayout();
676
+ return padPublicLegs(legs, publicNInputs, publicNOutputs);
677
+ }
678
+ function padStrings(values, length, fill) {
679
+ if (values.length > length) {
754
680
  throw new Error(
755
- `recipient scalar hex must fit 32 bytes (${SCALAR_HEX_CHAR_LENGTH} hex chars)`
681
+ `expected at most ${String(length)} application-id slots, got ${String(values.length)}`
756
682
  );
757
683
  }
758
- return padded;
684
+ return [...values, ...Array.from({ length: length - values.length }, () => fill)];
759
685
  }
760
- function privKeyScalarDecimalFromRecipientScalarHex(hexInput) {
761
- const hex = normalizeRecipientScalarHex(hexInput);
762
- const value = BigInt(`0x${hex}`);
763
- const mask = BN254_BABYJUB_SCALAR_MAX_EXCLUSIVE - BIGINT_ONE;
764
- return (value & mask).toString(DECIMAL_RADIX);
686
+ function buildApplicationIdHints(input) {
687
+ const { nIns, nOuts } = input.sdk.getLayout();
688
+ return [
689
+ ...padStrings(input.inputIds, nIns, "0"),
690
+ ...padStrings(input.outputIds, nOuts, "0")
691
+ ];
692
+ }
693
+ function uniformApplicationIdHints(applicationId, nAuditSlots) {
694
+ return Array.from({ length: nAuditSlots }, () => applicationId);
765
695
  }
766
696
 
767
697
  // src/transact/proofs/confidential/helpers.ts
698
+ import { withdrawObjectFromMerkleWitness } from "@arcanetech/stellar-privacy-pool-zk-sdk";
768
699
  var MIN_CONFIDENTIAL_TRANSFER_STROOPS = 1n;
769
700
  var ZERO_STROOPS = 0n;
770
- function leafEphemeralCoords(xHex, yHex) {
771
- const coords = {};
772
- Object.defineProperty(coords, "x", {
773
- value: xHex,
774
- enumerable: true,
775
- writable: true
776
- });
777
- Object.defineProperty(coords, "y", {
778
- value: yHex,
779
- enumerable: true,
780
- writable: true
781
- });
782
- return coords;
783
- }
784
701
  function withdrawWitnessForCoin(parameters) {
785
- const { sdk, coin, state, xHex, yHex } = parameters;
702
+ const { sdk, coin, state } = parameters;
786
703
  const witness = sdk.buildWithdrawMerkleWitness(coin, state);
787
704
  const withdrawApplicationId = coin.application_id ?? parameters.applicationId;
788
705
  const withdrawObject = withdrawObjectFromMerkleWitness(
789
706
  witness,
790
- leafEphemeralCoords(xHex, yHex),
791
- withdrawApplicationId
707
+ parameters.ownerPubHex,
708
+ withdrawApplicationId,
709
+ parameters.privKeyScalar
792
710
  );
793
711
  return { witness, withdrawObject };
794
712
  }
@@ -797,16 +715,16 @@ function dualWithdrawLegsWithSharedRoot(parameters) {
797
715
  sdk: parameters.sdk,
798
716
  coin: parameters.coinA,
799
717
  state: parameters.state,
800
- xHex: parameters.ephemeralA.xHex,
801
- yHex: parameters.ephemeralA.yHex,
718
+ ownerPubHex: parameters.ownerPubHex,
719
+ privKeyScalar: parameters.privKeyScalar,
802
720
  applicationId: parameters.applicationId
803
721
  });
804
722
  const legB = withdrawWitnessForCoin({
805
723
  sdk: parameters.sdk,
806
724
  coin: parameters.coinB,
807
725
  state: parameters.state,
808
- xHex: parameters.ephemeralB.xHex,
809
- yHex: parameters.ephemeralB.yHex,
726
+ ownerPubHex: parameters.ownerPubHex,
727
+ privKeyScalar: parameters.privKeyScalar,
810
728
  applicationId: parameters.applicationId
811
729
  });
812
730
  if (legA.witness.stateRoot !== legB.witness.stateRoot) {
@@ -814,15 +732,6 @@ function dualWithdrawLegsWithSharedRoot(parameters) {
814
732
  }
815
733
  return { legA, legB };
816
734
  }
817
- function senderWithdrawFrAndScalar(parameters) {
818
- const pkRaw = StrKey3.decodeEd25519PublicKey(parameters.senderGAddress);
819
- const pkHex = Buffer8.from(pkRaw).toString("hex");
820
- const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals(pkHex);
821
- const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
822
- parameters.senderPrivKeyScalarHex
823
- );
824
- return { hi, lo, privKeyScalar };
825
- }
826
735
  function requireChangeRecipientWhenPartial(changeStroops, selfPrivateAddressStpl1ForChange) {
827
736
  if (changeStroops > ZERO_STROOPS) {
828
737
  const stpl1 = selfPrivateAddressStpl1ForChange?.trim() ?? "";
@@ -847,15 +756,15 @@ function changeStroopsAfterDualTransfer(transferStroops, totalNotes) {
847
756
  import {
848
757
  DEMO_AUDIT_PUBLIC_KEY,
849
758
  resolveTransactionAuditParams
850
- } from "@auditable/privacy-pool-zk-sdk";
851
- import { Buffer as Buffer9 } from "buffer";
759
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
760
+ import { Buffer as Buffer7 } from "buffer";
852
761
  var UNCOMPRESSED_PREFIX = "04";
853
762
  var UNCOMPRESSED_HEX_LENGTH = 130;
854
763
  var XY_HEX_LENGTH = 128;
855
764
  var X_OFFSET_END = 32;
856
765
  var Y_OFFSET_START = 32;
857
766
  var Y_OFFSET_END = 64;
858
- var DECIMAL_RADIX2 = 10;
767
+ var DECIMAL_RADIX = 10;
859
768
  var BN254_FR_MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
860
769
  var BABYJUBJUB_A = 168700n;
861
770
  var BABYJUBJUB_D = 168696n;
@@ -875,13 +784,13 @@ function parseAuditPublicKeyFromEnvHex(raw) {
875
784
  "Audit public key must be uncompressed 65-byte hex (04 + X + Y) or 64-byte X+Y hex"
876
785
  );
877
786
  }
878
- const bytes = Buffer9.from(payload, "hex");
787
+ const bytes = Buffer7.from(payload, "hex");
879
788
  const auditPublicKeyXDecimal = BigInt(
880
789
  `0x${bytes.subarray(0, X_OFFSET_END).toString("hex")}`
881
- ).toString(DECIMAL_RADIX2);
790
+ ).toString(DECIMAL_RADIX);
882
791
  const auditPublicKeyYDecimal = BigInt(
883
792
  `0x${bytes.subarray(Y_OFFSET_START, Y_OFFSET_END).toString("hex")}`
884
- ).toString(DECIMAL_RADIX2);
793
+ ).toString(DECIMAL_RADIX);
885
794
  if (!passesBabyJubCurveCheck(
886
795
  BigInt(auditPublicKeyXDecimal),
887
796
  BigInt(auditPublicKeyYDecimal)
@@ -893,7 +802,8 @@ function parseAuditPublicKeyFromEnvHex(raw) {
893
802
  function buildPoolTransactionAuditParameters(input) {
894
803
  return resolveTransactionAuditParams(
895
804
  input.applicationId,
896
- input.auditPublicKey ?? DEMO_AUDIT_PUBLIC_KEY
805
+ input.auditPublicKey ?? DEMO_AUDIT_PUBLIC_KEY,
806
+ input.nAuditSlots
897
807
  );
898
808
  }
899
809
  function resolvePoolApplicationId(applicationId) {
@@ -907,24 +817,24 @@ function resolvePoolApplicationId(applicationId) {
907
817
  }
908
818
 
909
819
  // src/transact/proofs/withdraw/helpers.ts
910
- import { ed25519PubkeyPayloadHexToWithdrawFrDecimals as ed25519PubkeyPayloadHexToWithdrawFrDecimals2 } from "@auditable/privacy-pool-zk-sdk";
820
+ import { ed25519PubkeyPayloadHexToWithdrawFrDecimals } from "@arcanetech/stellar-privacy-pool-zk-sdk";
911
821
 
912
822
  // src/transact/stellar/account.ts
913
- import { StrKey as StrKey4 } from "@stellar/stellar-sdk";
914
- import { Buffer as Buffer10 } from "buffer";
823
+ import { StrKey as StrKey3 } from "@stellar/stellar-sdk";
824
+ import { Buffer as Buffer8 } from "buffer";
915
825
  var MUXED_ACCOUNT_ID_BYTE_LENGTH = 8;
916
826
  var ED25519_PUBLIC_KEY_BYTE_LENGTH = 32;
917
827
  function ed25519HexFromGAddress(trimmed) {
918
828
  try {
919
- const raw = StrKey4.decodeEd25519PublicKey(trimmed);
920
- return Buffer10.from(raw).toString("hex");
829
+ const raw = StrKey3.decodeEd25519PublicKey(trimmed);
830
+ return Buffer8.from(raw).toString("hex");
921
831
  } catch {
922
832
  return void 0;
923
833
  }
924
834
  }
925
835
  function ed25519HexFromMuxedAddress(trimmed) {
926
836
  try {
927
- const raw = StrKey4.decodeMed25519PublicKey(trimmed);
837
+ const raw = StrKey3.decodeMed25519PublicKey(trimmed);
928
838
  if (raw.length === MUXED_ACCOUNT_ID_BYTE_LENGTH + ED25519_PUBLIC_KEY_BYTE_LENGTH) {
929
839
  return raw.subarray(MUXED_ACCOUNT_ID_BYTE_LENGTH).toString("hex");
930
840
  }
@@ -949,29 +859,29 @@ function ed25519PublicKeyHexFromStellarAccount(address) {
949
859
  throw new Error("Invalid destination Stellar address");
950
860
  }
951
861
 
952
- // src/transact/encoding/ephemeral-key.ts
953
- var HEX_64_RE = /^[\da-f]{64}$/iu;
954
- function normalizeCoordinate(value) {
955
- const hex = value.trim().replace(/^0x/iu, "").toLowerCase();
956
- if (!HEX_64_RE.test(hex)) {
957
- throw new Error("Ephemeral key coordinate must be a 32-byte hex string.");
862
+ // src/transact/encoding/priv-key-scalar-from-recipient-hex.ts
863
+ import { canonicalBabyJubScalarFromInteger } from "@arcanetech/stellar-privacy-pool-zk-sdk";
864
+ var SCALAR_HEX_CHAR_LENGTH = 64;
865
+ var DECIMAL_RADIX2 = 10;
866
+ function normalizeRecipientScalarHex(hexInput) {
867
+ const trimmed = hexInput.trim().replace(/^0x/iu, "");
868
+ if (!/^[0-9a-f]*$/iu.test(trimmed)) {
869
+ throw new Error("recipient scalar hex must be hexadecimal");
958
870
  }
959
- return hex;
960
- }
961
- function parseEphemeralKeyString(input) {
962
- const [xRaw, yRaw, extra] = input.split(":");
963
- if (!xRaw || !yRaw || extra !== void 0) {
871
+ const withLeadingNibble = trimmed.length % 2 === 0 ? trimmed : `0${trimmed}`;
872
+ const lower = withLeadingNibble.toLowerCase();
873
+ const padded = lower.padStart(SCALAR_HEX_CHAR_LENGTH, "0").slice(-SCALAR_HEX_CHAR_LENGTH);
874
+ if (padded.length !== SCALAR_HEX_CHAR_LENGTH) {
964
875
  throw new Error(
965
- 'Ephemeral key must be a string in "xHex:yHex" format (32-byte hex each).'
876
+ `recipient scalar hex must fit 32 bytes (${SCALAR_HEX_CHAR_LENGTH} hex chars)`
966
877
  );
967
878
  }
968
- return {
969
- xHex: normalizeCoordinate(xRaw),
970
- yHex: normalizeCoordinate(yRaw)
971
- };
879
+ return padded;
972
880
  }
973
- function serializeEphemeralKeyString(point) {
974
- return `${normalizeCoordinate(point.xHex)}:${normalizeCoordinate(point.yHex)}`;
881
+ function privKeyScalarDecimalFromRecipientScalarHex(hexInput) {
882
+ const hex = normalizeRecipientScalarHex(hexInput);
883
+ const value = BigInt(`0x${hex}`);
884
+ return canonicalBabyJubScalarFromInteger(value).toString(DECIMAL_RADIX2);
975
885
  }
976
886
 
977
887
  // src/transact/proofs/withdraw/helpers.ts
@@ -979,7 +889,7 @@ function destinationWithdrawFrAndScalar(parameters) {
979
889
  const pkHex = ed25519PublicKeyHexFromStellarAccount(
980
890
  parameters.destinationStellarAddress
981
891
  );
982
- const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals2(pkHex);
892
+ const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals(pkHex);
983
893
  const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
984
894
  parameters.privKeyScalarHex
985
895
  );
@@ -993,8 +903,11 @@ function buildWithdrawPublicInput(parameters) {
993
903
  return withTokenAddressPublicInputs(
994
904
  {
995
905
  stateRoot: parameters.stateRoot,
996
- withdrawAddressHi: hi,
997
- withdrawAddressLo: lo,
906
+ ...publicWithdrawAddressLimbs({
907
+ publicWithdrawalAmount: parameters.publicWithdrawalAmount,
908
+ destinationHi: hi,
909
+ destinationLo: lo
910
+ }),
998
911
  privKeyScalar
999
912
  },
1000
913
  parameters.tokenAddress
@@ -1002,7 +915,7 @@ function buildWithdrawPublicInput(parameters) {
1002
915
  }
1003
916
  async function resolveWithdrawChangeDeposits(parameters) {
1004
917
  if (parameters.changeStroops <= ZERO_STROOPS) {
1005
- return { deposits: ["dummy", "dummy"] };
918
+ return { deposits: [] };
1006
919
  }
1007
920
  const stpl1 = parameters.changePrivateAddressStpl1?.trim() ?? "";
1008
921
  if (!stpl1) {
@@ -1016,7 +929,7 @@ async function resolveWithdrawChangeDeposits(parameters) {
1016
929
  tokenAddress: parameters.tokenAddress
1017
930
  });
1018
931
  return {
1019
- deposits: [slot.deposit, "dummy"],
932
+ deposits: [slot.deposit],
1020
933
  changeCoin: {
1021
934
  commitment_hex: slot.commitment_hex,
1022
935
  coin: slot.coin,
@@ -1041,14 +954,14 @@ function buildDualWithdrawPublicInput(parameters) {
1041
954
  stateRoot: parameters.stateRoot,
1042
955
  destinationStellarAddress: parameters.destinationStellarAddress,
1043
956
  privKeyScalarHex: parameters.privKeyScalarHex,
1044
- tokenAddress: parameters.tokenAddress
957
+ tokenAddress: parameters.tokenAddress,
958
+ publicWithdrawalAmount: parameters.publicWithdrawalAmount
1045
959
  });
1046
960
  }
1047
961
  async function prepareDualWithdrawProofInputs(parameters) {
1048
- const totalNotes = BigInt(parameters.coinA.value) + BigInt(parameters.coinB.value);
1049
962
  const changeStroops = validateDualWithdrawAmounts(
1050
963
  parameters.withdrawAmountStroops,
1051
- totalNotes,
964
+ BigInt(parameters.coinA.value) + BigInt(parameters.coinB.value),
1052
965
  parameters.changePrivateAddressStpl1
1053
966
  );
1054
967
  const { legA, legB } = dualWithdrawLegsWithSharedRoot({
@@ -1056,8 +969,12 @@ async function prepareDualWithdrawProofInputs(parameters) {
1056
969
  coinA: parameters.coinA,
1057
970
  coinB: parameters.coinB,
1058
971
  state: parameters.state,
1059
- ephemeralA: parseEphemeralKeyString(parameters.ephemeralAKey),
1060
- ephemeralB: parseEphemeralKeyString(parameters.ephemeralBKey),
972
+ ownerPubHex: parameters.sdk.ecdhEphemeralPublicKeyFromScalarHex(
973
+ parameters.privKeyScalarHex
974
+ ),
975
+ privKeyScalar: privKeyScalarDecimalFromRecipientScalarHex(
976
+ parameters.privKeyScalarHex
977
+ ),
1061
978
  applicationId: parameters.applicationId
1062
979
  });
1063
980
  const { deposits, changeCoin } = await resolveWithdrawChangeDeposits({
@@ -1070,17 +987,19 @@ async function prepareDualWithdrawProofInputs(parameters) {
1070
987
  destinationStellarAddress: parameters.destinationStellarAddress,
1071
988
  privKeyScalarHex: parameters.privKeyScalarHex,
1072
989
  tokenAddress: parameters.tokenAddress,
1073
- stateRoot: legA.witness.stateRoot
990
+ stateRoot: legA.witness.stateRoot,
991
+ publicWithdrawalAmount: parameters.withdrawAmountStroops.toString()
1074
992
  });
1075
993
  const audit = buildPoolTransactionAuditParameters({
1076
994
  applicationId: parameters.applicationId,
995
+ nAuditSlots: parameters.sdk.getLayout().nAuditSlots,
1077
996
  ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
1078
997
  });
1079
998
  return {
1080
999
  publicInput,
1081
1000
  audit,
1082
- withdrawLegs: [legA.withdrawObject, legB.withdrawObject],
1083
1001
  deposits,
1002
+ withdrawLegs: [legA.withdrawObject, legB.withdrawObject],
1084
1003
  ...changeCoin ? { changeCoin } : {}
1085
1004
  };
1086
1005
  }
@@ -1098,35 +1017,49 @@ function validateSingleWithdrawAmounts(withdrawAmountStroops, noteStroops) {
1098
1017
  async function proveSingleWithdrawTransaction(parameters) {
1099
1018
  return parameters.sdk.proveTransaction(
1100
1019
  parameters.publicInput,
1101
- buildPublicWithdrawLegs(
1102
- parameters.tokenAddress,
1103
- parameters.withdrawAmountStroops.toString()
1020
+ padPublicLegsToLayout(
1021
+ parameters.sdk,
1022
+ buildPublicWithdrawLegs(
1023
+ parameters.tokenAddress,
1024
+ parameters.withdrawAmountStroops.toString()
1025
+ )
1104
1026
  ),
1105
- [parameters.primaryWithdraw, "dummy"],
1106
- parameters.deposits,
1027
+ padWithdrawSlotsToLayout(parameters.sdk, [parameters.primaryWithdraw]),
1028
+ padDepositSlotsToLayout(parameters.sdk, parameters.deposits),
1107
1029
  parameters.audit
1108
1030
  );
1109
1031
  }
1110
1032
  function buildPrimaryWithdrawForCoin(parameters) {
1111
- const ephemeralPoint = parseEphemeralKeyString(parameters.depositorEphemeralKey);
1112
1033
  const witness = parameters.sdk.buildWithdrawMerkleWitness(
1113
1034
  parameters.coin,
1114
1035
  parameters.state
1115
1036
  );
1037
+ const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
1038
+ parameters.privKeyScalarHex
1039
+ );
1040
+ const ownerPubHex = parameters.sdk.ecdhEphemeralPublicKeyFromScalarHex(
1041
+ parameters.privKeyScalarHex
1042
+ );
1116
1043
  const primaryWithdraw = withdrawObjectFromMerkleWitness2(
1117
1044
  witness,
1118
- leafEphemeralCoords(ephemeralPoint.xHex, ephemeralPoint.yHex),
1119
- parameters.applicationId
1045
+ ownerPubHex,
1046
+ parameters.applicationId,
1047
+ privKeyScalar
1120
1048
  );
1121
1049
  return { witness, primaryWithdraw };
1122
1050
  }
1123
1051
  async function prepareSingleWithdrawProofInputs(parameters) {
1124
- const noteStroops = BigInt(parameters.coin.value);
1125
1052
  const changeStroops = validateSingleWithdrawAmounts(
1126
1053
  parameters.withdrawAmountStroops,
1127
- noteStroops
1054
+ BigInt(parameters.coin.value)
1128
1055
  );
1129
- const { witness, primaryWithdraw } = buildPrimaryWithdrawForCoin(parameters);
1056
+ const { witness, primaryWithdraw } = buildPrimaryWithdrawForCoin({
1057
+ sdk: parameters.sdk,
1058
+ applicationId: parameters.applicationId,
1059
+ coin: parameters.coin,
1060
+ state: parameters.state,
1061
+ privKeyScalarHex: parameters.privKeyScalarHex
1062
+ });
1130
1063
  const { deposits, changeCoin } = await resolveWithdrawChangeDeposits({
1131
1064
  changeStroops,
1132
1065
  changePrivateAddressStpl1: parameters.changePrivateAddressStpl1,
@@ -1137,18 +1070,19 @@ async function prepareSingleWithdrawProofInputs(parameters) {
1137
1070
  stateRoot: witness.stateRoot,
1138
1071
  destinationStellarAddress: parameters.destinationStellarAddress,
1139
1072
  privKeyScalarHex: parameters.privKeyScalarHex,
1140
- tokenAddress: parameters.tokenAddress
1141
- });
1142
- const audit = buildPoolTransactionAuditParameters({
1143
- applicationId: parameters.applicationId,
1144
- ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
1073
+ tokenAddress: parameters.tokenAddress,
1074
+ publicWithdrawalAmount: parameters.withdrawAmountStroops.toString()
1145
1075
  });
1146
1076
  return {
1147
1077
  primaryWithdraw,
1148
1078
  deposits,
1149
1079
  changeCoin,
1150
1080
  publicInput,
1151
- audit
1081
+ audit: buildPoolTransactionAuditParameters({
1082
+ applicationId: parameters.applicationId,
1083
+ nAuditSlots: parameters.sdk.getLayout().nAuditSlots,
1084
+ ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
1085
+ })
1152
1086
  };
1153
1087
  }
1154
1088
  async function proveWithdrawTransact(parameters) {
@@ -1164,12 +1098,11 @@ async function proveWithdrawTransact(parameters) {
1164
1098
  });
1165
1099
  return {
1166
1100
  ...proof,
1167
- applicationIdsPlaintext: [
1168
- parameters.applicationId,
1169
- "0",
1170
- changeCoin ? parameters.applicationId : "0",
1171
- "0"
1172
- ],
1101
+ applicationIdsPlaintext: buildApplicationIdHints({
1102
+ sdk: parameters.sdk,
1103
+ inputIds: [parameters.applicationId],
1104
+ outputIds: [changeCoin ? parameters.applicationId : "0"]
1105
+ }),
1173
1106
  ...changeCoin ? { changeCoin } : {}
1174
1107
  };
1175
1108
  }
@@ -1177,33 +1110,143 @@ async function proveWithdrawTransactDual(parameters) {
1177
1110
  const { publicInput, audit, withdrawLegs, deposits, changeCoin } = await prepareDualWithdrawProofInputs(parameters);
1178
1111
  const proof = await parameters.sdk.proveTransaction(
1179
1112
  publicInput,
1180
- buildPublicWithdrawLegs(
1181
- parameters.tokenAddress,
1182
- parameters.withdrawAmountStroops.toString()
1113
+ padPublicLegsToLayout(
1114
+ parameters.sdk,
1115
+ buildPublicWithdrawLegs(
1116
+ parameters.tokenAddress,
1117
+ parameters.withdrawAmountStroops.toString()
1118
+ )
1183
1119
  ),
1184
- withdrawLegs,
1185
- deposits,
1120
+ padWithdrawSlotsToLayout(parameters.sdk, withdrawLegs),
1121
+ padDepositSlotsToLayout(parameters.sdk, deposits),
1186
1122
  audit
1187
1123
  );
1188
1124
  return {
1189
1125
  ...proof,
1190
- applicationIdsPlaintext: [
1191
- audit.applicationId,
1192
- audit.applicationId,
1193
- changeCoin ? audit.applicationId : "0",
1194
- "0"
1195
- ],
1126
+ applicationIdsPlaintext: buildApplicationIdHints({
1127
+ sdk: parameters.sdk,
1128
+ inputIds: [audit.applicationId, audit.applicationId],
1129
+ outputIds: [changeCoin ? audit.applicationId : "0"]
1130
+ }),
1196
1131
  ...changeCoin ? { changeCoin } : {}
1197
1132
  };
1198
1133
  }
1199
1134
 
1200
1135
  // src/transact/pool/service.ts
1201
1136
  import "buffer";
1202
- import { PrivacyPoolSDK as PrivacyPoolSdkClass } from "@auditable/privacy-pool-zk-sdk";
1137
+
1138
+ // src/transact/zk/circuit-config.ts
1139
+ import {
1140
+ BundledZkCircuit
1141
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
1142
+
1143
+ // src/transact/environment/zk-config-nonce.ts
1144
+ var BINDING_ZK_NONCE = 3n;
1145
+ var SIX_BY_SIX_BINDING_ZK_NONCE = 7n;
1146
+ var DEFAULT_ZK_CONFIG_NONCE = BINDING_ZK_NONCE;
1147
+ function resolveZkConfigNonce(transactEnvironment) {
1148
+ return transactEnvironment.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
1149
+ }
1150
+
1151
+ // src/transact/zk/circuit-config.ts
1152
+ import { BundledZkCircuit as BundledZkCircuit2 } from "@arcanetech/stellar-privacy-pool-zk-sdk";
1153
+ var DEFAULT_STELLAR_ZK_CIRCUITS = {
1154
+ [BINDING_ZK_NONCE.toString()]: {
1155
+ nIns: 2,
1156
+ nOuts: 2,
1157
+ publicNInputs: 1,
1158
+ publicNOutputs: 1,
1159
+ circuit: BundledZkCircuit.TwoByTwo
1160
+ },
1161
+ [SIX_BY_SIX_BINDING_ZK_NONCE.toString()]: {
1162
+ nIns: 6,
1163
+ nOuts: 6,
1164
+ publicNInputs: 1,
1165
+ publicNOutputs: 1,
1166
+ circuit: BundledZkCircuit.SixBySix
1167
+ }
1168
+ };
1169
+ function isBundledDefinition(definition) {
1170
+ return "circuit" in definition;
1171
+ }
1172
+ async function fetchBuffer(url) {
1173
+ const response = await fetch(url);
1174
+ if (!response.ok) {
1175
+ throw new Error(`Failed to fetch ZK artifact ${url}: ${String(response.status)}`);
1176
+ }
1177
+ return response.arrayBuffer();
1178
+ }
1179
+ async function materializeDefinition(definition) {
1180
+ if (isBundledDefinition(definition)) {
1181
+ const bundled = {
1182
+ nIns: definition.nIns,
1183
+ nOuts: definition.nOuts,
1184
+ publicNInputs: definition.publicNInputs,
1185
+ publicNOutputs: definition.publicNOutputs,
1186
+ circuit: definition.circuit
1187
+ };
1188
+ return bundled;
1189
+ }
1190
+ const [zkey, circuitGraph, r1cs, provingKey] = await Promise.all([
1191
+ fetchBuffer(definition.zkeyUrl),
1192
+ fetchBuffer(definition.circuitGraphUrl),
1193
+ fetchBuffer(definition.r1csUrl),
1194
+ fetchBuffer(definition.provingKeyUrl)
1195
+ ]);
1196
+ const custom = {
1197
+ nIns: definition.nIns,
1198
+ nOuts: definition.nOuts,
1199
+ publicNInputs: definition.publicNInputs,
1200
+ publicNOutputs: definition.publicNOutputs,
1201
+ zkey,
1202
+ circuitGraph,
1203
+ r1cs,
1204
+ provingKey
1205
+ };
1206
+ return custom;
1207
+ }
1208
+ async function materializeSelectedZkCircuit(circuits, nonce) {
1209
+ const map = stellarCircuitsOrDefault(circuits);
1210
+ const key = nonce.toString();
1211
+ const definition = Object.entries(map).find(([nonceKey]) => nonceKey === key)?.[1];
1212
+ if (!definition) {
1213
+ throw new Error(`no zk circuit configured for nonce ${key}`);
1214
+ }
1215
+ return { [key]: await materializeDefinition(definition) };
1216
+ }
1217
+ function stellarCircuitsOrDefault(circuits) {
1218
+ return circuits ?? DEFAULT_STELLAR_ZK_CIRCUITS;
1219
+ }
1220
+ function optionalZkArtifactBaseUrl(value) {
1221
+ if (value === void 0) {
1222
+ return {};
1223
+ }
1224
+ const trimmed = value.trim();
1225
+ if (trimmed === "") {
1226
+ return {};
1227
+ }
1228
+ let withoutSlash = trimmed;
1229
+ while (withoutSlash.endsWith("/")) {
1230
+ withoutSlash = withoutSlash.slice(0, -1);
1231
+ }
1232
+ return { zkArtifactBaseUrl: withoutSlash };
1233
+ }
1203
1234
 
1204
1235
  // src/transact/pool/aligned-deposit.ts
1205
- import { PrivacyPoolSDK, scalarHexToFrDecimal } from "@auditable/privacy-pool-zk-sdk";
1236
+ import {
1237
+ PrivacyPoolSDK,
1238
+ scalarHexToFrDecimal
1239
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
1206
1240
  var SAMPLE_SCALAR_ATTEMPTS = 10;
1241
+ function escrowDepositFields(parameters) {
1242
+ if (!parameters.recipientHi || !parameters.recipientLo) {
1243
+ return {};
1244
+ }
1245
+ return {
1246
+ ...parameters.escrowNonce ? { escrowNonce: parameters.escrowNonce } : {},
1247
+ recipientStellar: [parameters.recipientHi, parameters.recipientLo]
1248
+ };
1249
+ }
1207
1250
  function sampleValidDepositScalarHex() {
1208
1251
  for (let index = 0; index < SAMPLE_SCALAR_ATTEMPTS; index++) {
1209
1252
  const candidate = PrivacyPoolSDK.generateRandomScalarHex32();
@@ -1219,17 +1262,12 @@ function sampleValidDepositScalarHex() {
1219
1262
  async function buildAlignedDepositSlotForSdk(sdk, applicationId, parameters) {
1220
1263
  const privateAddressPoint = decodePrivateAddress(parameters.privateAddressStpl1);
1221
1264
  const scalarHex = sampleValidDepositScalarHex();
1222
- const shared = sdk.ecdhSharedKey(
1223
- scalarHex,
1224
- privateAddressPoint.x,
1225
- privateAddressPoint.y
1226
- );
1227
1265
  const [assetHi, assetLo] = tokenAddressToAssetLeg(parameters.tokenAddress);
1228
1266
  const resolvedApplicationId = resolvePoolApplicationId(applicationId);
1229
- const generated = sdk.generateCoinForDepositWithSharedHex(
1267
+ const generated = sdk.generateCoinForDepositWithOwnerPubHex(
1230
1268
  scalarHex,
1231
- shared.x,
1232
- shared.y,
1269
+ privateAddressPoint.x,
1270
+ privateAddressPoint.y,
1233
1271
  parameters.amountStroops,
1234
1272
  assetHi,
1235
1273
  assetLo,
@@ -1244,27 +1282,34 @@ async function buildAlignedDepositSlotForSdk(sdk, applicationId, parameters) {
1244
1282
  ephemeralKeyScalar: scalarHexToFrDecimal(scalarHex),
1245
1283
  asset: [generated.coin.asset_hi, generated.coin.asset_lo],
1246
1284
  applicationId: resolvedApplicationId,
1247
- recipientPublicKeys
1285
+ recipientPublicKeys,
1286
+ ...escrowDepositFields(parameters)
1248
1287
  };
1249
1288
  return {
1250
1289
  deposit,
1251
1290
  commitment_hex: generated.commitment_hex,
1252
1291
  coin: generated.coin,
1253
1292
  depositScalarHex: scalarHex,
1254
- precommitementHex: generated.precommitement_hex
1293
+ precommitementHex: generated.precommitementHex
1255
1294
  };
1256
1295
  }
1257
1296
 
1258
1297
  // src/transact/pool/service.ts
1259
1298
  var PrivacyPoolService = class {
1260
- constructor(assets, applicationId, auditPublicKey) {
1299
+ constructor(assets, applicationId, auditPublicKey, zkCircuits, zkConfigNonce, zkArtifactBaseUrl) {
1261
1300
  this.assets = assets;
1262
1301
  this.applicationId = applicationId;
1263
1302
  this.auditPublicKey = auditPublicKey;
1303
+ this.zkCircuits = zkCircuits;
1304
+ this.zkConfigNonce = zkConfigNonce;
1305
+ this.zkArtifactBaseUrl = zkArtifactBaseUrl;
1264
1306
  }
1265
1307
  assets;
1266
1308
  applicationId;
1267
1309
  auditPublicKey;
1310
+ zkCircuits;
1311
+ zkConfigNonce;
1312
+ zkArtifactBaseUrl;
1268
1313
  sdk = void 0;
1269
1314
  initPromise = void 0;
1270
1315
  async ensureInit() {
@@ -1280,10 +1325,16 @@ var PrivacyPoolService = class {
1280
1325
  "PrivacyPoolService requires browser ZK assets before initialization."
1281
1326
  );
1282
1327
  }
1283
- this.sdk = await PrivacyPoolSdkClass.init({
1328
+ const zkConfigNonce = this.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
1329
+ const zkCircuits = await materializeSelectedZkCircuit(
1330
+ this.zkCircuits,
1331
+ zkConfigNonce
1332
+ );
1333
+ this.sdk = await PrivacyPoolSDK2.init({
1284
1334
  wasmBinary: this.assets.sdkWasm,
1285
- circuitWasm: this.assets.circuitWasm,
1286
- zkey: this.assets.provingKey
1335
+ zkCircuits,
1336
+ zkConfigNonce,
1337
+ ...optionalZkArtifactBaseUrl(this.zkArtifactBaseUrl)
1287
1338
  });
1288
1339
  })();
1289
1340
  return this.initPromise;
@@ -1301,22 +1352,17 @@ var PrivacyPoolService = class {
1301
1352
  getApplicationId() {
1302
1353
  return resolvePoolApplicationId(this.applicationId);
1303
1354
  }
1304
- async generatePrivateAddressFromStellarSignature(signature) {
1305
- await this.ensureInit();
1306
- if (!this.sdk) {
1307
- throw new Error("SDK not initialized");
1308
- }
1309
- return privateAddressSdk(this.sdk).generatePrivateAddressFromStellarSignature(
1310
- signature
1355
+ async generatePrivateAddressFromStellarSignature(signature, domain) {
1356
+ const sdk = await this.getInitializedSdk();
1357
+ return privateAddressSdk(sdk).generatePrivateAddressFromStellarSignature(
1358
+ signature,
1359
+ domain
1311
1360
  );
1312
1361
  }
1313
1362
  async sharedSecretX(recipientScalarHex, ephemeralKeyEncoded) {
1314
- await this.ensureInit();
1315
- if (!this.sdk) {
1316
- throw new Error("SDK not initialized");
1317
- }
1363
+ const sdk = await this.getInitializedSdk();
1318
1364
  const ephemeralKey = decodeDecodedEphemeralKey(ephemeralKeyEncoded);
1319
- const shared = this.sdk.sharedSecretFromRecipientPreimage({
1365
+ const shared = sdk.sharedSecretFromRecipientPreimage({
1320
1366
  recipientScalar: recipientScalarHex,
1321
1367
  ephemeralKey
1322
1368
  });
@@ -1339,6 +1385,7 @@ var PrivacyPoolService = class {
1339
1385
  const applicationId = this.getApplicationId();
1340
1386
  const audit = buildPoolTransactionAuditParameters({
1341
1387
  applicationId,
1388
+ nAuditSlots: sdk.getLayout().nAuditSlots,
1342
1389
  ...this.auditPublicKey ? { auditPublicKey: this.auditPublicKey } : {}
1343
1390
  });
1344
1391
  const deposit = {
@@ -1352,38 +1399,35 @@ var PrivacyPoolService = class {
1352
1399
  const publicInput = withTokenAddressPublicInputs(
1353
1400
  {
1354
1401
  stateRoot,
1355
- withdrawAddressHi: "0",
1356
- withdrawAddressLo: "0",
1357
1402
  privKeyScalar: randomFrDecimal253()
1358
1403
  },
1359
1404
  parameters.tokenAddress
1360
1405
  );
1361
1406
  const proof = await sdk.proveTransaction(
1362
1407
  publicInput,
1363
- buildPublicDepositLegs(parameters.tokenAddress, parameters.coin.value),
1364
- ["dummy", "dummy"],
1365
- [deposit, "dummy"],
1408
+ padPublicLegsToLayout(
1409
+ sdk,
1410
+ buildPublicDepositLegs(parameters.tokenAddress, parameters.coin.value)
1411
+ ),
1412
+ padWithdrawSlotsToLayout(sdk, []),
1413
+ padDepositSlotsToLayout(sdk, [deposit]),
1366
1414
  audit
1367
1415
  );
1368
- const applicationIdsPlaintext = [
1369
- "0",
1370
- "0",
1371
- applicationId,
1372
- "0"
1373
- ];
1416
+ const applicationIdsPlaintext = buildApplicationIdHints({
1417
+ sdk,
1418
+ inputIds: [],
1419
+ outputIds: [applicationId]
1420
+ });
1374
1421
  return { ...proof, applicationIdsPlaintext };
1375
1422
  }
1376
- async calculateNullifierHash(nullifier) {
1423
+ async calculateNullifierHash(nullifier, privKeyScalar) {
1377
1424
  const sdk = await this.getInitializedSdk();
1378
- return sdk.calculateNullifierHash(nullifier);
1425
+ return sdk.calculateNullifierHash(nullifier, privKeyScalar);
1379
1426
  }
1380
1427
  async prepareWithdrawTransactProof(parameters) {
1381
- await this.ensureInit();
1382
- if (!this.sdk) {
1383
- throw new Error("SDK not initialized");
1384
- }
1428
+ const sdk = await this.getInitializedSdk();
1385
1429
  return proveWithdrawTransact({
1386
- sdk: this.sdk,
1430
+ sdk,
1387
1431
  applicationId: this.getApplicationId(),
1388
1432
  buildAlignedDepositSlot: (input) => this.buildAlignedDepositSlot(input),
1389
1433
  ...this.auditPublicKey ? { auditPublicKey: this.auditPublicKey } : {},
@@ -1391,12 +1435,9 @@ var PrivacyPoolService = class {
1391
1435
  });
1392
1436
  }
1393
1437
  async prepareWithdrawTransactProofDual(parameters) {
1394
- await this.ensureInit();
1395
- if (!this.sdk) {
1396
- throw new Error("SDK not initialized");
1397
- }
1438
+ const sdk = await this.getInitializedSdk();
1398
1439
  return proveWithdrawTransactDual({
1399
- sdk: this.sdk,
1440
+ sdk,
1400
1441
  applicationId: this.getApplicationId(),
1401
1442
  buildAlignedDepositSlot: (input) => this.buildAlignedDepositSlot(input),
1402
1443
  ...this.auditPublicKey ? { auditPublicKey: this.auditPublicKey } : {},
@@ -1419,7 +1460,10 @@ function createPrivacyPoolService(input) {
1419
1460
  return new PrivacyPoolService(
1420
1461
  input?.assets,
1421
1462
  input?.applicationId,
1422
- input?.auditPublicKey
1463
+ input?.auditPublicKey,
1464
+ input?.zkCircuits,
1465
+ input?.zkConfigNonce,
1466
+ input?.zkArtifactBaseUrl
1423
1467
  );
1424
1468
  }
1425
1469
  var configuredPrivacyPoolService;
@@ -1435,81 +1479,245 @@ function getPrivacyPoolService() {
1435
1479
  return configuredPrivacyPoolService;
1436
1480
  }
1437
1481
 
1438
- // src/transact/transfer-source/verify.ts
1439
- async function verifyPendingClaimBeforeExecute(input) {
1440
- try {
1441
- assertPendingClaimOwner({
1442
- claim: input.claim,
1443
- walletPublicKey: input.walletPublicKey
1482
+ // src/transact/merkle/fetch-contract.ts
1483
+ import { Buffer as Buffer11 } from "buffer";
1484
+
1485
+ // src/transact/merkle/encoding.ts
1486
+ import "buffer";
1487
+ var FR_ORDER = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n;
1488
+ function bufferToDecimal(buf) {
1489
+ const hex = buf.toString("hex");
1490
+ const bigintFromHex = BigInt(`0x${hex}`);
1491
+ const reduced = bigintFromHex % FR_ORDER;
1492
+ return reduced.toString();
1493
+ }
1494
+ function commitmentsBuffersToDecimal(buffers) {
1495
+ return buffers.map((bufferRow) => bufferToDecimal(bufferRow));
1496
+ }
1497
+
1498
+ // src/transact/merkle/state-port.ts
1499
+ function poolMerkleStateToCachedView(state) {
1500
+ return {
1501
+ commitments: state.commitments,
1502
+ updatedAt: state.updatedAt,
1503
+ merkleRootHex: state.merkleRootHex
1504
+ };
1505
+ }
1506
+
1507
+ // src/transact/merkle/fetch-contract.ts
1508
+ function normalizeCommitmentBuffers(rawBuffers) {
1509
+ return rawBuffers.map(
1510
+ (bufferRow) => Buffer11.isBuffer(bufferRow) ? bufferRow : Buffer11.from(bufferRow)
1511
+ );
1512
+ }
1513
+ function mergeContractMerkleWithCache(parameters) {
1514
+ const cachedCount = parameters.cachedState?.commitments.length ?? 0;
1515
+ const shouldPreferContract = parameters.contractCount > cachedCount || !parameters.cachedState || cachedCount === 0;
1516
+ if (shouldPreferContract) {
1517
+ const updatedAt = Date.now();
1518
+ void parameters.poolMerkleState?.set({
1519
+ poolContract: parameters.poolContractId,
1520
+ commitments: parameters.contractCommitments,
1521
+ commitmentCount: parameters.contractCount,
1522
+ merkleRootHex: parameters.merkleRootHex,
1523
+ updatedAt
1444
1524
  });
1445
- const coin = pendingClaimToCoin(input.claim);
1446
- const nullifierHashHex = await getPrivacyPoolService().calculateNullifierHash(
1447
- coin.nullifier
1448
- );
1449
- const contractContext = requireContractContext(input.environment);
1450
- const poolContractId = input.poolContractId?.trim() || contractContext.network.poolContract;
1451
- const spent = await readNullifierConsumedOnChain({
1452
- contractContext,
1453
- poolContractId,
1454
- walletPublicKey: input.walletPublicKey.trim(),
1455
- nullifierHashHex
1525
+ return {
1526
+ commitments: parameters.contractCommitments,
1527
+ updatedAt,
1528
+ merkleRootHex: parameters.merkleRootHex,
1529
+ commitmentCount: parameters.contractCount
1530
+ };
1531
+ }
1532
+ return {
1533
+ commitments: parameters.cachedState.commitments,
1534
+ updatedAt: parameters.cachedState.updatedAt,
1535
+ merkleRootHex: parameters.cachedState.merkleRootHex ?? parameters.merkleRootHex,
1536
+ commitmentCount: parameters.cachedState.commitments.length
1537
+ };
1538
+ }
1539
+ async function readCachedPoolMerkleView(poolMerkleState, poolContractId) {
1540
+ if (!poolMerkleState) {
1541
+ return void 0;
1542
+ }
1543
+ const cached = await poolMerkleState.get(poolContractId);
1544
+ return cached ? poolMerkleStateToCachedView(cached) : void 0;
1545
+ }
1546
+ async function fetchAndMergeMerkleState(parameters) {
1547
+ const client = readPoolClientFactory(parameters.transactEnvironment)({
1548
+ contractId: parameters.poolContractId,
1549
+ walletPublicKey: parameters.walletPublicKey,
1550
+ networkPassphrase: parameters.transactEnvironment.network.networkPassphrase,
1551
+ sorobanRpcUrl: parameters.transactEnvironment.network.rpcUrl
1552
+ });
1553
+ const commitmentsRead = await client.get_commitments();
1554
+ const rawBuffers = commitmentsRead.result;
1555
+ const buffers = normalizeCommitmentBuffers(rawBuffers);
1556
+ const contractCommitments = commitmentsBuffersToDecimal(buffers);
1557
+ const contractCount = contractCommitments.length;
1558
+ const rootRead = await client.get_merkle_root();
1559
+ const merkleRootBuffer = rootRead.result;
1560
+ const merkleRootHex = Buffer11.from(merkleRootBuffer).toString("hex");
1561
+ const cachedState = await readCachedPoolMerkleView(
1562
+ parameters.poolMerkleState,
1563
+ parameters.poolContractId
1564
+ );
1565
+ return mergeContractMerkleWithCache({
1566
+ poolContractId: parameters.poolContractId,
1567
+ contractCommitments,
1568
+ contractCount,
1569
+ merkleRootHex,
1570
+ cachedState,
1571
+ ...parameters.poolMerkleState ? { poolMerkleState: parameters.poolMerkleState } : {}
1572
+ });
1573
+ }
1574
+ async function readLeafEphemeralHex(parameters) {
1575
+ const cached = await parameters.leafEphemeral?.get({
1576
+ poolContract: parameters.poolContractId,
1577
+ leafIndex: parameters.leafIndex
1578
+ });
1579
+ if (cached?.xHex && cached.yHex) {
1580
+ return { xHex: cached.xHex, yHex: cached.yHex };
1581
+ }
1582
+ const client = readPoolClientFactory(parameters.transactEnvironment)({
1583
+ contractId: parameters.poolContractId,
1584
+ walletPublicKey: parameters.walletPublicKey,
1585
+ networkPassphrase: parameters.transactEnvironment.network.networkPassphrase,
1586
+ sorobanRpcUrl: parameters.transactEnvironment.network.rpcUrl
1587
+ });
1588
+ const read = await client.get_leaf_ephemeral({ leaf_index: parameters.leafIndex });
1589
+ const coords = read.result;
1590
+ if (!coords?.x || !coords?.y) {
1591
+ throw new Error("Missing leaf ephemeral key on contract");
1592
+ }
1593
+ const xHex = Buffer11.from(coords.x).toString("hex");
1594
+ const yHex = Buffer11.from(coords.y).toString("hex");
1595
+ await parameters.leafEphemeral?.set({
1596
+ poolContract: parameters.poolContractId,
1597
+ leafIndex: parameters.leafIndex,
1598
+ xHex,
1599
+ yHex,
1600
+ cachedAt: (/* @__PURE__ */ new Date()).toISOString()
1601
+ });
1602
+ return { xHex, yHex };
1603
+ }
1604
+
1605
+ // src/transact/engine/prepare/shared.ts
1606
+ async function resolveTokenContractId2(environment, assetId) {
1607
+ if (environment.resolveTokenContractId) {
1608
+ return environment.resolveTokenContractId(assetId);
1609
+ }
1610
+ throw new Error(`Token contract is not configured for asset ${assetId}.`);
1611
+ }
1612
+ async function resolveWalletPublicKey(environment, prepared) {
1613
+ if (environment.resolveWalletPublicKey) {
1614
+ return environment.resolveWalletPublicKey();
1615
+ }
1616
+ if (prepared.kind === "deposit") {
1617
+ const depositIntent = prepared.intent;
1618
+ return depositIntent.from;
1619
+ }
1620
+ throw new Error("Wallet public key resolver is not configured.");
1621
+ }
1622
+ async function resolveSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
1623
+ const cached = await readSenderPrivKeyScalarHex(
1624
+ environment,
1625
+ privateAddressStpl1,
1626
+ owner
1627
+ );
1628
+ if (cached) {
1629
+ return cached;
1630
+ }
1631
+ if (environment.ensureSenderPrivKeyScalarHex) {
1632
+ return environment.ensureSenderPrivKeyScalarHex(privateAddressStpl1);
1633
+ }
1634
+ if (!environment.resolveSenderPrivKeyScalarHex) {
1635
+ throw new Error("Sender private key scalar resolver is not configured.");
1636
+ }
1637
+ return environment.resolveSenderPrivKeyScalarHex(privateAddressStpl1);
1638
+ }
1639
+ async function readSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
1640
+ if (owner && environment.resolveSenderPrivKeyScalarFromState) {
1641
+ const fromState = await environment.resolveSenderPrivKeyScalarFromState({
1642
+ owner,
1643
+ privateAddressStpl1
1456
1644
  });
1457
- if (spent) {
1458
- throw executionError3(
1459
- "Pending claim nullifier was already spent on-chain.",
1460
- "validation",
1461
- { reason: "pending_claim_nullifier_spent" }
1462
- );
1645
+ if (fromState?.trim()) {
1646
+ return fromState.trim();
1463
1647
  }
1464
- } catch (error) {
1465
- if (typeof error === "object" && error !== null && "code" in error && error.code === "insufficient_state") {
1466
- throw executionError3(
1467
- error instanceof Error ? error.message : "Pending claim owner mismatch.",
1468
- "validation",
1469
- { reason: "pending_claim_owner_mismatch" }
1470
- );
1648
+ }
1649
+ if (environment.readSenderPrivKeyScalarHex) {
1650
+ const cached = await environment.readSenderPrivKeyScalarHex(privateAddressStpl1);
1651
+ if (cached?.trim()) {
1652
+ return cached.trim();
1471
1653
  }
1472
- throw error;
1473
1654
  }
1655
+ return void 0;
1474
1656
  }
1475
-
1476
- // src/transact/transfer-source/verify-private-records.ts
1477
- import { executionError as executionError4, insufficientStateError as insufficientStateError2 } from "@arcanetech/privacy-sdk-core";
1478
-
1479
- // src/transact/private-address/record-coin.ts
1480
- function requireCoinNoteFromRecord(record) {
1481
- if (!record.coinNote) {
1482
- throw new Error(`Private record ${record.id} is missing coin note data.`);
1657
+ async function ensureSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
1658
+ const cached = await readSenderPrivKeyScalarHex(
1659
+ environment,
1660
+ privateAddressStpl1,
1661
+ owner
1662
+ );
1663
+ if (cached) {
1664
+ return cached;
1483
1665
  }
1484
- return record.coinNote;
1666
+ if (environment.ensureSenderPrivKeyScalarHex) {
1667
+ return environment.ensureSenderPrivKeyScalarHex(privateAddressStpl1);
1668
+ }
1669
+ return resolveSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner);
1485
1670
  }
1486
- function findCommitmentLeafIndex(commitments, commitment) {
1487
- return commitments.indexOf(commitment);
1671
+ async function loadMerkleState(environment, walletPublicKey) {
1672
+ const merged = await fetchAndMergeMerkleState({
1673
+ poolContractId: environment.network.poolContract,
1674
+ walletPublicKey,
1675
+ transactEnvironment: environment,
1676
+ ...environment.poolMerkleState ? { poolMerkleState: environment.poolMerkleState } : {}
1677
+ });
1678
+ return { commitments: merged.commitments };
1488
1679
  }
1489
- function buildPrivateRecordFromDeposit(input) {
1680
+ function enrichPreparedOperation(prepared, outputRecords, artifacts) {
1490
1681
  return {
1491
- id: input.commitmentHex,
1492
- owner: input.owner,
1493
- asset: input.assetId,
1494
- amount: input.amount,
1495
- consumed: false,
1496
- status: input.status ?? "pending",
1497
- poolContract: input.poolContract,
1498
- commitmentHex: input.commitmentHex,
1499
- privateAddress: input.privateAddress,
1500
- amountDisplay: input.amountDisplay,
1501
- coinNote: input.coin,
1502
- depositScalarHex: input.depositScalarHex,
1503
- precommitementHex: input.precommitementHex,
1504
- ...input.txHash ? { txHash: input.txHash } : {}
1682
+ ...prepared,
1683
+ outputRecords,
1684
+ transactArtifacts: artifacts,
1685
+ submissionPayload: {
1686
+ operationId: crypto.randomUUID(),
1687
+ signed: false
1688
+ }
1505
1689
  };
1506
1690
  }
1507
1691
 
1508
1692
  // src/transact/transfer-source/verify-private-records.ts
1693
+ async function resolveNullifierSpendScalarHex(input) {
1694
+ const stamped = input.spendScalarHex?.trim();
1695
+ if (stamped) {
1696
+ return stamped;
1697
+ }
1698
+ const privateAddress = input.record.privateAddress?.trim();
1699
+ if (!privateAddress) {
1700
+ throw executionError3(
1701
+ "Private record is missing a private address; cannot derive the owner-bound spend scalar.",
1702
+ "validation",
1703
+ {
1704
+ reason: "private_record_missing_private_address",
1705
+ recordId: input.record.id
1706
+ }
1707
+ );
1708
+ }
1709
+ return ensureSenderPrivKeyScalarHex(
1710
+ input.environment,
1711
+ privateAddress,
1712
+ input.walletPublicKey
1713
+ );
1714
+ }
1509
1715
  async function readPrivateRecordNullifierSpendStatus(input) {
1510
1716
  const coin = requireCoinNoteFromRecord(input.record);
1717
+ const scalarHex = await resolveNullifierSpendScalarHex(input);
1511
1718
  const nullifierHashHex = await getPrivacyPoolService().calculateNullifierHash(
1512
- coin.nullifier
1719
+ coin.nullifier,
1720
+ privKeyScalarDecimalFromRecipientScalarHex(scalarHex)
1513
1721
  );
1514
1722
  const contractContext = requireContractContext(input.environment);
1515
1723
  const poolContractId = input.poolContractId?.trim() || contractContext.network.poolContract;
@@ -1527,10 +1735,11 @@ async function verifyPrivateRecordsNullifiersBeforeExecute(input) {
1527
1735
  record,
1528
1736
  environment: input.environment,
1529
1737
  walletPublicKey: input.walletPublicKey,
1530
- ...input.poolContractId ? { poolContractId: input.poolContractId } : {}
1738
+ ...input.poolContractId ? { poolContractId: input.poolContractId } : {},
1739
+ ...input.spendScalarHex ? { spendScalarHex: input.spendScalarHex } : {}
1531
1740
  });
1532
1741
  if (status.spent) {
1533
- throw executionError4(
1742
+ throw executionError3(
1534
1743
  "Private input note nullifier was already spent on-chain.",
1535
1744
  "validation",
1536
1745
  {
@@ -1550,10 +1759,11 @@ async function assertPrivateRecordsNullifiersAvailable(input) {
1550
1759
  const coin = requireCoinNoteFromRecord(record);
1551
1760
  const spent = await input.checkNullifierSpent({
1552
1761
  nullifier: coin.nullifier,
1553
- walletPublicKey: input.walletPublicKey
1762
+ walletPublicKey: input.walletPublicKey,
1763
+ ...record.privateAddress ? { privateAddressStpl1: record.privateAddress } : {}
1554
1764
  });
1555
1765
  if (spent) {
1556
- throw insufficientStateError2(
1766
+ throw insufficientStateError(
1557
1767
  "private_record_nullifier_spent",
1558
1768
  "Private input note nullifier was already spent on-chain.",
1559
1769
  { recordId: record.id }
@@ -1565,15 +1775,6 @@ async function assertPrivateRecordsNullifiersAvailable(input) {
1565
1775
  // src/adapters/transfer-output-records.ts
1566
1776
  function buildTransferOutputRecords(intent, consumedTotal, walletPublicKey) {
1567
1777
  const recipientOwner = recipientOutputOwner(intent, walletPublicKey);
1568
- if (isPendingClaimSource(intent.from)) {
1569
- return [
1570
- createOutputRecord({
1571
- ...recipientOwner,
1572
- asset: intent.asset,
1573
- amount: intent.amount
1574
- })
1575
- ];
1576
- }
1577
1778
  const changeAmount = consumedTotal - intent.amount;
1578
1779
  const outputs = [
1579
1780
  createOutputRecord({
@@ -1680,7 +1881,8 @@ async function filterUnspentPrivateRecords(input) {
1680
1881
  const coin = requireCoinNoteFromRecord(record);
1681
1882
  const spent = await input.checkNullifierSpent({
1682
1883
  nullifier: coin.nullifier,
1683
- walletPublicKey: input.walletPublicKey
1884
+ walletPublicKey: input.walletPublicKey,
1885
+ ...record.privateAddress ? { privateAddressStpl1: record.privateAddress } : {}
1684
1886
  });
1685
1887
  if (!spent) {
1686
1888
  unspent.push(record);
@@ -1698,14 +1900,14 @@ function pickRecordsForSpendAmount(input) {
1698
1900
  return selected;
1699
1901
  }
1700
1902
  if ((input.kind === "transfer" || input.kind === "withdraw") && selected.length >= 2) {
1701
- throw insufficientStateError3(
1903
+ throw insufficientStateError2(
1702
1904
  "missing_private_records",
1703
1905
  "Storage does not contain enough private records for this operation.",
1704
1906
  { requestedAmount: input.amount, availableAmount: selectedTotal }
1705
1907
  );
1706
1908
  }
1707
1909
  }
1708
- throw insufficientStateError3(
1910
+ throw insufficientStateError2(
1709
1911
  "missing_private_records",
1710
1912
  "Storage does not contain enough private records for this operation.",
1711
1913
  { requestedAmount: input.amount, availableAmount: selectedTotal }
@@ -1714,7 +1916,7 @@ function pickRecordsForSpendAmount(input) {
1714
1916
  async function selectPrivateRecords(input) {
1715
1917
  const from = input.intent.from;
1716
1918
  if (!isPrivateAddressTransferFrom(from)) {
1717
- throw insufficientStateError3(
1919
+ throw insufficientStateError2(
1718
1920
  "invalid_transfer_source",
1719
1921
  "Private record selection requires a private address transfer source."
1720
1922
  );
@@ -1732,7 +1934,7 @@ async function selectPrivateRecords(input) {
1732
1934
  checkNullifierSpent: input.checkNullifierSpent
1733
1935
  }) : locallyAvailable;
1734
1936
  if (available.length === 0) {
1735
- throw insufficientStateError3(
1937
+ throw insufficientStateError2(
1736
1938
  "missing_private_records",
1737
1939
  "Storage does not contain enough private records for this operation.",
1738
1940
  { requestedAmount: input.intent.amount, availableAmount: 0n }
@@ -1760,11 +1962,10 @@ function buildSpendOutputRecords(input) {
1760
1962
  }
1761
1963
 
1762
1964
  // src/adapters/transfer-prepare.ts
1763
- import { insufficientStateError as insufficientStateError4 } from "@arcanetech/privacy-sdk-core";
1764
1965
  async function prepareTransferOperation(intent, deps) {
1966
+ const spend = await resolvePrivateAddressSpend(intent, deps);
1765
1967
  const walletAddress = await deps.wallet.getAddress();
1766
1968
  const walletPublicKey = walletAddress.trim();
1767
- const spend = isPendingClaimSource(intent.from) ? await resolvePendingClaimSpend(intent, deps, walletPublicKey) : await resolvePrivateAddressSpend(intent, deps);
1768
1969
  const consumedTotal = sumRecordAmounts(spend.consumedRecords);
1769
1970
  const prepared = {
1770
1971
  kind: "transfer",
@@ -1779,40 +1980,6 @@ async function prepareTransferOperation(intent, deps) {
1779
1980
  };
1780
1981
  return deps.engine.prepare(prepared);
1781
1982
  }
1782
- async function resolvePendingClaimSpend(intent, deps, walletPublicKey) {
1783
- if (!deps.getPendingClaims) {
1784
- throw insufficientStateError4(
1785
- "pending_claim_state_unavailable",
1786
- "Pending claim state is not available for this transfer."
1787
- );
1788
- }
1789
- const claim = await resolvePendingClaimSource({
1790
- from: intent.from,
1791
- walletPublicKey,
1792
- getPendingClaims: deps.getPendingClaims
1793
- });
1794
- assertPendingClaimOwner({ claim, walletPublicKey });
1795
- await assertPendingClaimNullifierAvailable({
1796
- claim,
1797
- walletPublicKey,
1798
- ...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
1799
- });
1800
- validatePendingClaimIntentMatches(claim, intent);
1801
- return {
1802
- consumedRecords: [
1803
- pendingClaimToConsumedRecord({
1804
- claim,
1805
- walletPublicKey,
1806
- poolContract: deps.poolContract
1807
- })
1808
- ],
1809
- transactArtifacts: {
1810
- pendingClaim: claim,
1811
- spendSource: "pendingClaim",
1812
- executeFinalizeRequired: true
1813
- }
1814
- };
1815
- }
1816
1983
  async function resolvePrivateAddressSpend(intent, deps) {
1817
1984
  const walletAddress = await deps.wallet.getAddress();
1818
1985
  const walletPublicKey = walletAddress.trim();
@@ -1835,37 +2002,6 @@ async function resolvePrivateAddressSpend(intent, deps) {
1835
2002
  }
1836
2003
  };
1837
2004
  }
1838
- function validatePendingClaimIntentMatches(claim, intent) {
1839
- if (claim.amount !== intent.amount) {
1840
- throw insufficientStateError4(
1841
- "pending_claim_amount_mismatch",
1842
- "Transfer amount must match the pending claim amount.",
1843
- { claimAmount: claim.amount, requestedAmount: intent.amount }
1844
- );
1845
- }
1846
- if (claim.asset !== intent.asset) {
1847
- throw insufficientStateError4(
1848
- "pending_claim_asset_mismatch",
1849
- "Transfer asset must match the pending claim asset."
1850
- );
1851
- }
1852
- }
1853
- async function assertPendingClaimNullifierAvailable(input) {
1854
- if (!input.checkNullifierSpent) {
1855
- return;
1856
- }
1857
- const nullifier = pendingClaimToCoin(input.claim).nullifier;
1858
- const spent = await input.checkNullifierSpent({
1859
- nullifier,
1860
- walletPublicKey: input.walletPublicKey
1861
- });
1862
- if (spent) {
1863
- throw insufficientStateError4(
1864
- "pending_claim_nullifier_spent",
1865
- "Pending claim nullifier was already spent on-chain."
1866
- );
1867
- }
1868
- }
1869
2005
 
1870
2006
  // src/adapters/network.ts
1871
2007
  function createStellarNetworkAdapter(deps) {
@@ -1949,9 +2085,6 @@ async function prepareOperation(input) {
1949
2085
  // src/state/foundation/paths.ts
1950
2086
  var STELLAR_STATE_PATHS = {
1951
2087
  privateRecords: "$.privateRecords",
1952
- pendingClaimsItems: "$.pendingClaims.items",
1953
- pendingClaimsPagination: "$.pendingClaims.pagination",
1954
- pendingClaimsCountByOwner: "$.pendingClaims.countByOwner",
1955
2088
  registryPrivateAddresses: "$.registry.privateAddresses",
1956
2089
  registryRegisteredAddresses: "$.registry.registeredAddresses",
1957
2090
  registryLookups: "$.registry.lookups",
@@ -1971,25 +2104,6 @@ var STELLAR_STATE_PATHS = {
1971
2104
 
1972
2105
  // src/state/schemas/shared.ts
1973
2106
  import { z } from "zod";
1974
- var pendingClaimSchema = z.object({
1975
- id: z.string().min(1),
1976
- owner: z.string().min(1),
1977
- asset: z.string().min(1),
1978
- amount: z.coerce.bigint(),
1979
- createdAt: z.string().min(1),
1980
- poolTxId: z.string().optional(),
1981
- commitmentHex: z.string().optional(),
1982
- nullifierHex: z.string().optional(),
1983
- futureNullifierHashHex: z.string().optional(),
1984
- assetHiHex: z.string().optional(),
1985
- assetLoHex: z.string().optional(),
1986
- nullifierFieldHex: z.string().optional(),
1987
- secretHex: z.string().optional(),
1988
- tempPublicKeyXHex: z.string().optional(),
1989
- tempPublicKeyYHex: z.string().optional(),
1990
- encryptedRecoveryBase64: z.string().optional(),
1991
- createdAtLedger: z.number().int().optional()
1992
- });
1993
2107
  var paginationSchema = z.object({
1994
2108
  total: z.number().int().nonnegative(),
1995
2109
  page: z.number().int().positive(),
@@ -2159,26 +2273,6 @@ function normalizePublicBalancesFromEntries(value, owner) {
2159
2273
  }).filter((balance) => balance !== void 0);
2160
2274
  }
2161
2275
 
2162
- // src/state/read/normalize/claims.ts
2163
- function normalizePendingClaimsState(value) {
2164
- if (typeof value !== "object" || value === null) {
2165
- return { items: [] };
2166
- }
2167
- const record = value;
2168
- const items = Array.isArray(record.items) ? record.items.flatMap((item) => {
2169
- const parsed = pendingClaimSchema.safeParse(item);
2170
- return parsed.success ? [withoutUndefinedFields(parsed.data)] : [];
2171
- }) : [];
2172
- const paginationResult = paginationSchema.safeParse(record.pagination);
2173
- if (paginationResult.success) {
2174
- return { items, pagination: paginationResult.data };
2175
- }
2176
- return { items };
2177
- }
2178
- function normalizePendingClaimsCount(value) {
2179
- return typeof value === "number" && Number.isInteger(value) && value >= 0 ? value : void 0;
2180
- }
2181
-
2182
2276
  // src/state/read/normalize/deliveries.ts
2183
2277
  function normalizeIncomingDeliveries(value) {
2184
2278
  const entries = typeof value === "object" && value !== null && !Array.isArray(value) ? Object.values(value) : value;
@@ -2301,8 +2395,7 @@ import { registerArrayFilterItemSchema } from "@arcanetech/privacy-sdk-core/stat
2301
2395
 
2302
2396
  // src/state/filters/ops.ts
2303
2397
  var stellarArrayFilterSchemaKeys = {
2304
- privateRecord: "privateRecord",
2305
- pendingClaim: "pendingClaim"
2398
+ privateRecord: "privateRecord"
2306
2399
  };
2307
2400
  function rejectPrivateRecordsByIds(ids) {
2308
2401
  return {
@@ -2328,56 +2421,6 @@ function rejectConsumedPrivateRecords() {
2328
2421
  }
2329
2422
  };
2330
2423
  }
2331
- function rejectPendingClaimsByOwner(owner) {
2332
- return {
2333
- opType: "arrayFilter",
2334
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2335
- itemSchemaKey: stellarArrayFilterSchemaKeys.pendingClaim,
2336
- rejectWhen: {
2337
- op: "fieldEquals",
2338
- field: "owner",
2339
- value: owner
2340
- }
2341
- };
2342
- }
2343
- function rejectPendingClaimsByIds(ids) {
2344
- return {
2345
- opType: "arrayFilter",
2346
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2347
- itemSchemaKey: stellarArrayFilterSchemaKeys.pendingClaim,
2348
- rejectWhen: {
2349
- op: "fieldIn",
2350
- field: "id",
2351
- values: ids
2352
- }
2353
- };
2354
- }
2355
- function rejectPendingClaimsByOwnerAndAsset(input) {
2356
- const matches = [];
2357
- if (input.owner !== void 0) {
2358
- matches.push({
2359
- op: "fieldEquals",
2360
- field: "owner",
2361
- value: input.owner
2362
- });
2363
- }
2364
- if (input.asset !== void 0) {
2365
- matches.push({
2366
- op: "fieldEquals",
2367
- field: "asset",
2368
- value: input.asset
2369
- });
2370
- }
2371
- return {
2372
- opType: "arrayFilter",
2373
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2374
- itemSchemaKey: stellarArrayFilterSchemaKeys.pendingClaim,
2375
- rejectWhen: {
2376
- op: "and",
2377
- matches
2378
- }
2379
- };
2380
- }
2381
2424
 
2382
2425
  // src/state/filters/register-schemas.ts
2383
2426
  var registered = false;
@@ -2389,24 +2432,12 @@ function registerStellarArrayFilterSchemas() {
2389
2432
  stellarArrayFilterSchemaKeys.privateRecord,
2390
2433
  privateRecordSchema
2391
2434
  );
2392
- registerArrayFilterItemSchema(
2393
- stellarArrayFilterSchemaKeys.pendingClaim,
2394
- pendingClaimSchema
2395
- );
2396
2435
  registered = true;
2397
2436
  }
2398
2437
 
2399
2438
  // src/state/bridge/call-types.ts
2400
2439
  import "@arcanetech/privacy-sdk-core/state";
2401
2440
  var stellarStateCallTypes = {
2402
- pendingClaims: "pendingClaims",
2403
- clearPendingClaims: "clearPendingClaims",
2404
- readPendingClaims: "readPendingClaims",
2405
- replacePendingClaimsPage: "replacePendingClaimsPage",
2406
- upsertPendingClaims: "upsertPendingClaims",
2407
- removePendingClaims: "removePendingClaims",
2408
- setPendingClaimsCount: "setPendingClaimsCount",
2409
- readPendingClaimsCount: "readPendingClaimsCount",
2410
2441
  readStellarAddressRegistered: "readStellarAddressRegistered",
2411
2442
  readCachedPrivateAddress: "readCachedPrivateAddress",
2412
2443
  readRegistryLookup: "readRegistryLookup",
@@ -2633,194 +2664,10 @@ var stellarBalancesStateDefinitions = [
2633
2664
  }
2634
2665
  ];
2635
2666
 
2636
- // src/state/schemas/claims/write.ts
2637
- import { z as z5 } from "zod";
2638
- var pendingClaimsWriteSchema = z5.object({
2639
- type: z5.literal(stellarStateCallTypes.pendingClaims),
2640
- claims: z5.array(pendingClaimSchema),
2641
- paginationInfo: paginationSchema
2642
- }).transform(({ type, claims, paginationInfo }) => ({
2643
- type,
2644
- operations: [
2645
- {
2646
- opType: "arrayPush",
2647
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2648
- items: claims
2649
- },
2650
- {
2651
- opType: "primitiveSet",
2652
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsPagination,
2653
- value: paginationInfo
2654
- }
2655
- ]
2656
- }));
2657
- var clearPendingClaimsSchema = z5.object({
2658
- type: z5.literal(stellarStateCallTypes.clearPendingClaims),
2659
- owner: z5.string().optional(),
2660
- asset: z5.string().optional()
2661
- }).transform(({ type, owner, asset }) => {
2662
- if (owner === void 0 && asset === void 0) {
2663
- return {
2664
- type,
2665
- operations: [
2666
- {
2667
- opType: "arrayClean",
2668
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems
2669
- }
2670
- ]
2671
- };
2672
- }
2673
- return {
2674
- type,
2675
- operations: [rejectPendingClaimsByOwnerAndAsset({ owner, asset })]
2676
- };
2677
- });
2678
- var readPendingClaimsSchema = z5.object({
2679
- type: z5.literal(stellarStateCallTypes.readPendingClaims)
2680
- }).transform(({ type }) => ({
2681
- type,
2682
- operations: [
2683
- {
2684
- opType: "primitiveGet",
2685
- jsonPath: "$.pendingClaims"
2686
- }
2687
- ]
2688
- }));
2689
-
2690
- // src/state/schemas/claims/page.ts
2691
- import { z as z6 } from "zod";
2692
- var pendingClaimBridgeItemSchema = pendingClaimSchema;
2693
- var replacePendingClaimsPageSchema = z6.object({
2694
- type: z6.literal(stellarStateCallTypes.replacePendingClaimsPage),
2695
- owner: z6.string().min(1),
2696
- claims: z6.array(pendingClaimBridgeItemSchema),
2697
- paginationInfo: z6.object({
2698
- total: z6.number().int().nonnegative(),
2699
- page: z6.number().int().positive(),
2700
- pageSize: z6.number().int().positive(),
2701
- hasMore: z6.boolean()
2702
- }),
2703
- count: z6.number().int().nonnegative().optional()
2704
- }).transform(({ type, owner, claims, paginationInfo, count }) => ({
2705
- type,
2706
- operations: [
2707
- rejectPendingClaimsByOwner(owner),
2708
- {
2709
- opType: "arrayPush",
2710
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2711
- items: claims
2712
- },
2713
- {
2714
- opType: "primitiveSet",
2715
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsPagination,
2716
- value: paginationInfo
2717
- },
2718
- {
2719
- opType: "recordSet",
2720
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsCountByOwner,
2721
- key: owner,
2722
- value: count ?? paginationInfo.total
2723
- }
2724
- ]
2725
- }));
2726
- var upsertPendingClaimsSchema = z6.object({
2727
- type: z6.literal(stellarStateCallTypes.upsertPendingClaims),
2728
- claims: z6.array(pendingClaimBridgeItemSchema)
2729
- }).transform(({ type, claims }) => ({
2730
- type,
2731
- operations: [
2732
- rejectPendingClaimsByIds(claims.map((claim) => claim.id)),
2733
- {
2734
- opType: "arrayPush",
2735
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsItems,
2736
- items: claims
2737
- }
2738
- ]
2739
- }));
2740
- var removePendingClaimsSchema = z6.object({
2741
- type: z6.literal(stellarStateCallTypes.removePendingClaims),
2742
- ids: z6.array(z6.string().min(1))
2743
- }).transform(({ type, ids }) => ({
2744
- type,
2745
- operations: [rejectPendingClaimsByIds(ids)]
2746
- }));
2747
- var readPendingClaimsCountSchema = z6.object({
2748
- type: z6.literal(stellarStateCallTypes.readPendingClaimsCount),
2749
- owner: z6.string().min(1)
2750
- }).transform(({ type, owner }) => ({
2751
- type,
2752
- operations: [
2753
- {
2754
- opType: "recordGet",
2755
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsCountByOwner,
2756
- key: owner
2757
- }
2758
- ]
2759
- }));
2760
- var setPendingClaimsCountSchema = z6.object({
2761
- type: z6.literal(stellarStateCallTypes.setPendingClaimsCount),
2762
- owner: z6.string().min(1),
2763
- count: z6.number().int().nonnegative()
2764
- }).transform(({ type, owner, count }) => ({
2765
- type,
2766
- operations: [
2767
- {
2768
- opType: "recordSet",
2769
- jsonPath: STELLAR_STATE_PATHS.pendingClaimsCountByOwner,
2770
- key: owner,
2771
- value: count
2772
- }
2773
- ]
2774
- }));
2775
-
2776
- // src/state/definitions/claims.ts
2777
- var stellarClaimsStateDefinitions = [
2778
- {
2779
- type: stellarStateCallTypes.pendingClaims,
2780
- mode: "write",
2781
- schema: pendingClaimsWriteSchema
2782
- },
2783
- {
2784
- type: stellarStateCallTypes.clearPendingClaims,
2785
- mode: "write",
2786
- schema: clearPendingClaimsSchema
2787
- },
2788
- {
2789
- type: stellarStateCallTypes.readPendingClaims,
2790
- mode: "read",
2791
- schema: readPendingClaimsSchema
2792
- },
2793
- {
2794
- type: stellarStateCallTypes.replacePendingClaimsPage,
2795
- mode: "write",
2796
- schema: replacePendingClaimsPageSchema
2797
- },
2798
- {
2799
- type: stellarStateCallTypes.upsertPendingClaims,
2800
- mode: "write",
2801
- schema: upsertPendingClaimsSchema
2802
- },
2803
- {
2804
- type: stellarStateCallTypes.removePendingClaims,
2805
- mode: "write",
2806
- schema: removePendingClaimsSchema
2807
- },
2808
- {
2809
- type: stellarStateCallTypes.readPendingClaimsCount,
2810
- mode: "read",
2811
- schema: readPendingClaimsCountSchema
2812
- },
2813
- {
2814
- type: stellarStateCallTypes.setPendingClaimsCount,
2815
- mode: "write",
2816
- schema: setPendingClaimsCountSchema
2817
- }
2818
- ];
2819
-
2820
2667
  // src/state/schemas/claims/deliveries.ts
2821
- import { z as z7 } from "zod";
2822
- var readIncomingDeliveriesSchema = z7.object({
2823
- type: z7.literal(stellarStateCallTypes.readIncomingDeliveries)
2668
+ import { z as z5 } from "zod";
2669
+ var readIncomingDeliveriesSchema = z5.object({
2670
+ type: z5.literal(stellarStateCallTypes.readIncomingDeliveries)
2824
2671
  }).transform(({ type }) => ({
2825
2672
  type,
2826
2673
  operations: [
@@ -2830,9 +2677,9 @@ var readIncomingDeliveriesSchema = z7.object({
2830
2677
  }
2831
2678
  ]
2832
2679
  }));
2833
- var upsertIncomingDeliveriesSchema = z7.object({
2834
- type: z7.literal(stellarStateCallTypes.upsertIncomingDeliveries),
2835
- deliveries: z7.array(incomingDeliverySchema)
2680
+ var upsertIncomingDeliveriesSchema = z5.object({
2681
+ type: z5.literal(stellarStateCallTypes.upsertIncomingDeliveries),
2682
+ deliveries: z5.array(incomingDeliverySchema)
2836
2683
  }).transform(({ type, deliveries }) => ({
2837
2684
  type,
2838
2685
  operations: deliveries.map((delivery) => ({
@@ -2842,10 +2689,10 @@ var upsertIncomingDeliveriesSchema = z7.object({
2842
2689
  value: delivery
2843
2690
  }))
2844
2691
  }));
2845
- var readDeliverySyncStateSchema = z7.object({
2846
- type: z7.literal(stellarStateCallTypes.readDeliverySyncState),
2847
- privateAddress: z7.string().min(1),
2848
- asset: z7.string().min(1)
2692
+ var readDeliverySyncStateSchema = z5.object({
2693
+ type: z5.literal(stellarStateCallTypes.readDeliverySyncState),
2694
+ privateAddress: z5.string().min(1),
2695
+ asset: z5.string().min(1)
2849
2696
  }).transform(({ type, privateAddress, asset }) => ({
2850
2697
  type,
2851
2698
  operations: [
@@ -2856,8 +2703,8 @@ var readDeliverySyncStateSchema = z7.object({
2856
2703
  }
2857
2704
  ]
2858
2705
  }));
2859
- var setDeliverySyncStateSchema = z7.object({
2860
- type: z7.literal(stellarStateCallTypes.setDeliverySyncState),
2706
+ var setDeliverySyncStateSchema = z5.object({
2707
+ type: z5.literal(stellarStateCallTypes.setDeliverySyncState),
2861
2708
  syncState: deliverySyncStateSchema
2862
2709
  }).transform(({ type, syncState }) => ({
2863
2710
  type,
@@ -2896,10 +2743,10 @@ var stellarDeliveriesStateDefinitions = [
2896
2743
  ];
2897
2744
 
2898
2745
  // src/state/schemas/pool/merkle.ts
2899
- import { z as z8 } from "zod";
2900
- var readPoolMerkleStateSchema = z8.object({
2901
- type: z8.literal(stellarStateCallTypes.readPoolMerkleState),
2902
- poolContract: z8.string().min(1)
2746
+ import { z as z6 } from "zod";
2747
+ var readPoolMerkleStateSchema = z6.object({
2748
+ type: z6.literal(stellarStateCallTypes.readPoolMerkleState),
2749
+ poolContract: z6.string().min(1)
2903
2750
  }).transform(({ type, poolContract }) => ({
2904
2751
  type,
2905
2752
  operations: [
@@ -2910,8 +2757,8 @@ var readPoolMerkleStateSchema = z8.object({
2910
2757
  }
2911
2758
  ]
2912
2759
  }));
2913
- var setPoolMerkleStateSchema = z8.object({
2914
- type: z8.literal(stellarStateCallTypes.setPoolMerkleState),
2760
+ var setPoolMerkleStateSchema = z6.object({
2761
+ type: z6.literal(stellarStateCallTypes.setPoolMerkleState),
2915
2762
  state: poolMerkleStateSchema
2916
2763
  }).transform(({ type, state }) => ({
2917
2764
  type,
@@ -2924,10 +2771,10 @@ var setPoolMerkleStateSchema = z8.object({
2924
2771
  }
2925
2772
  ]
2926
2773
  }));
2927
- var readLeafEphemeralSchema = z8.object({
2928
- type: z8.literal(stellarStateCallTypes.readLeafEphemeral),
2929
- poolContract: z8.string().min(1),
2930
- leafIndex: z8.number().int().nonnegative()
2774
+ var readLeafEphemeralSchema = z6.object({
2775
+ type: z6.literal(stellarStateCallTypes.readLeafEphemeral),
2776
+ poolContract: z6.string().min(1),
2777
+ leafIndex: z6.number().int().nonnegative()
2931
2778
  }).transform(({ type, poolContract, leafIndex }) => ({
2932
2779
  type,
2933
2780
  operations: [
@@ -2938,8 +2785,8 @@ var readLeafEphemeralSchema = z8.object({
2938
2785
  }
2939
2786
  ]
2940
2787
  }));
2941
- var setLeafEphemeralSchema = z8.object({
2942
- type: z8.literal(stellarStateCallTypes.setLeafEphemeral),
2788
+ var setLeafEphemeralSchema = z6.object({
2789
+ type: z6.literal(stellarStateCallTypes.setLeafEphemeral),
2943
2790
  ephemeral: leafEphemeralSchema
2944
2791
  }).transform(({ type, ephemeral }) => ({
2945
2792
  type,
@@ -2978,9 +2825,9 @@ var stellarPoolStateDefinitions = [
2978
2825
  ];
2979
2826
 
2980
2827
  // src/state/schemas/records/private.ts
2981
- import { z as z9 } from "zod";
2982
- var listPrivateRecordsSchema = z9.object({
2983
- type: z9.literal(stellarStateCallTypes.listPrivateRecords)
2828
+ import { z as z7 } from "zod";
2829
+ var listPrivateRecordsSchema = z7.object({
2830
+ type: z7.literal(stellarStateCallTypes.listPrivateRecords)
2984
2831
  }).transform(({ type }) => ({
2985
2832
  type,
2986
2833
  operations: [
@@ -2990,9 +2837,9 @@ var listPrivateRecordsSchema = z9.object({
2990
2837
  }
2991
2838
  ]
2992
2839
  }));
2993
- var savePrivateRecordsSchema = z9.object({
2994
- type: z9.literal(stellarStateCallTypes.savePrivateRecords),
2995
- records: z9.array(privateRecordSchema)
2840
+ var savePrivateRecordsSchema = z7.object({
2841
+ type: z7.literal(stellarStateCallTypes.savePrivateRecords),
2842
+ records: z7.array(privateRecordSchema)
2996
2843
  }).transform(({ type, records }) => ({
2997
2844
  type,
2998
2845
  operations: [
@@ -3003,9 +2850,9 @@ var savePrivateRecordsSchema = z9.object({
3003
2850
  }
3004
2851
  ]
3005
2852
  }));
3006
- var replacePrivateRecordsSchema = z9.object({
3007
- type: z9.literal(stellarStateCallTypes.replacePrivateRecords),
3008
- records: z9.array(privateRecordSchema)
2853
+ var replacePrivateRecordsSchema = z7.object({
2854
+ type: z7.literal(stellarStateCallTypes.replacePrivateRecords),
2855
+ records: z7.array(privateRecordSchema)
3009
2856
  }).transform(({ type, records }) => ({
3010
2857
  type,
3011
2858
  operations: [
@@ -3020,18 +2867,18 @@ var replacePrivateRecordsSchema = z9.object({
3020
2867
  }
3021
2868
  ]
3022
2869
  }));
3023
- var pruneConsumedPrivateRecordsSchema = z9.object({
3024
- type: z9.literal(stellarStateCallTypes.pruneConsumedPrivateRecords)
2870
+ var pruneConsumedPrivateRecordsSchema = z7.object({
2871
+ type: z7.literal(stellarStateCallTypes.pruneConsumedPrivateRecords)
3025
2872
  }).transform(({ type }) => ({
3026
2873
  type,
3027
2874
  operations: [rejectConsumedPrivateRecords()]
3028
2875
  }));
3029
2876
 
3030
2877
  // src/state/schemas/records/transactions.ts
3031
- import { z as z10 } from "zod";
3032
- var upsertPrivateRecordsSchema = z10.object({
3033
- type: z10.literal(stellarStateCallTypes.upsertPrivateRecords),
3034
- records: z10.array(privateRecordSchema)
2878
+ import { z as z8 } from "zod";
2879
+ var upsertPrivateRecordsSchema = z8.object({
2880
+ type: z8.literal(stellarStateCallTypes.upsertPrivateRecords),
2881
+ records: z8.array(privateRecordSchema)
3035
2882
  }).transform(({ type, records }) => ({
3036
2883
  type,
3037
2884
  operations: [
@@ -3043,9 +2890,9 @@ var upsertPrivateRecordsSchema = z10.object({
3043
2890
  }
3044
2891
  ]
3045
2892
  }));
3046
- var readTransactionStatusSchema = z10.object({
3047
- type: z10.literal(stellarStateCallTypes.readTransactionStatus),
3048
- txHash: z10.string().min(1)
2893
+ var readTransactionStatusSchema = z8.object({
2894
+ type: z8.literal(stellarStateCallTypes.readTransactionStatus),
2895
+ txHash: z8.string().min(1)
3049
2896
  }).transform(({ type, txHash }) => ({
3050
2897
  type,
3051
2898
  operations: [
@@ -3056,8 +2903,8 @@ var readTransactionStatusSchema = z10.object({
3056
2903
  }
3057
2904
  ]
3058
2905
  }));
3059
- var setTransactionStatusSchema = z10.object({
3060
- type: z10.literal(stellarStateCallTypes.setTransactionStatus),
2906
+ var setTransactionStatusSchema = z8.object({
2907
+ type: z8.literal(stellarStateCallTypes.setTransactionStatus),
3061
2908
  status: transactionStatusSchema
3062
2909
  }).transform(({ type, status }) => ({
3063
2910
  type,
@@ -3070,9 +2917,9 @@ var setTransactionStatusSchema = z10.object({
3070
2917
  }
3071
2918
  ]
3072
2919
  }));
3073
- var clearTransactionStatusSchema = z10.object({
3074
- type: z10.literal(stellarStateCallTypes.clearTransactionStatus),
3075
- txHash: z10.string().min(1)
2920
+ var clearTransactionStatusSchema = z8.object({
2921
+ type: z8.literal(stellarStateCallTypes.clearTransactionStatus),
2922
+ txHash: z8.string().min(1)
3076
2923
  }).transform(({ type, txHash }) => ({
3077
2924
  type,
3078
2925
  operations: [
@@ -3114,10 +2961,10 @@ var stellarRecordsStateDefinitions = [
3114
2961
  ];
3115
2962
 
3116
2963
  // src/state/schemas/registry/lookup.ts
3117
- import { z as z11 } from "zod";
3118
- var readStellarAddressRegisteredSchema = z11.object({
3119
- type: z11.literal(stellarStateCallTypes.readStellarAddressRegistered),
3120
- address: z11.string().min(1)
2964
+ import { z as z9 } from "zod";
2965
+ var readStellarAddressRegisteredSchema = z9.object({
2966
+ type: z9.literal(stellarStateCallTypes.readStellarAddressRegistered),
2967
+ address: z9.string().min(1)
3121
2968
  }).transform(({ type, address }) => ({
3122
2969
  type,
3123
2970
  operations: [
@@ -3128,9 +2975,9 @@ var readStellarAddressRegisteredSchema = z11.object({
3128
2975
  }
3129
2976
  ]
3130
2977
  }));
3131
- var readCachedPrivateAddressSchema = z11.object({
3132
- type: z11.literal(stellarStateCallTypes.readCachedPrivateAddress),
3133
- address: z11.string().min(1)
2978
+ var readCachedPrivateAddressSchema = z9.object({
2979
+ type: z9.literal(stellarStateCallTypes.readCachedPrivateAddress),
2980
+ address: z9.string().min(1)
3134
2981
  }).transform(({ type, address }) => ({
3135
2982
  type,
3136
2983
  operations: [
@@ -3141,11 +2988,11 @@ var readCachedPrivateAddressSchema = z11.object({
3141
2988
  }
3142
2989
  ]
3143
2990
  }));
3144
- var saveRegisteredPrivateAddressSchema = z11.object({
3145
- type: z11.literal(stellarStateCallTypes.saveRegisteredPrivateAddress),
3146
- address: z11.string().min(1),
3147
- privateAddress: z11.string().min(1),
3148
- registered: z11.boolean()
2991
+ var saveRegisteredPrivateAddressSchema = z9.object({
2992
+ type: z9.literal(stellarStateCallTypes.saveRegisteredPrivateAddress),
2993
+ address: z9.string().min(1),
2994
+ privateAddress: z9.string().min(1),
2995
+ registered: z9.boolean()
3149
2996
  }).transform(({ type, address, privateAddress, registered: registered2 }) => {
3150
2997
  const lookup = registryLookupSchema.parse({
3151
2998
  owner: address,
@@ -3177,9 +3024,9 @@ var saveRegisteredPrivateAddressSchema = z11.object({
3177
3024
  ]
3178
3025
  };
3179
3026
  });
3180
- var invalidateRegisteredAddressSchema = z11.object({
3181
- type: z11.literal(stellarStateCallTypes.invalidateRegisteredAddress),
3182
- address: z11.string().min(1)
3027
+ var invalidateRegisteredAddressSchema = z9.object({
3028
+ type: z9.literal(stellarStateCallTypes.invalidateRegisteredAddress),
3029
+ address: z9.string().min(1)
3183
3030
  }).transform(({ type, address }) => ({
3184
3031
  type,
3185
3032
  operations: [
@@ -3200,9 +3047,9 @@ var invalidateRegisteredAddressSchema = z11.object({
3200
3047
  }
3201
3048
  ]
3202
3049
  }));
3203
- var readRegistryLookupSchema = z11.object({
3204
- type: z11.literal(stellarStateCallTypes.readRegistryLookup),
3205
- address: z11.string().min(1)
3050
+ var readRegistryLookupSchema = z9.object({
3051
+ type: z9.literal(stellarStateCallTypes.readRegistryLookup),
3052
+ address: z9.string().min(1)
3206
3053
  }).transform(({ type, address }) => ({
3207
3054
  type,
3208
3055
  operations: [
@@ -3213,8 +3060,8 @@ var readRegistryLookupSchema = z11.object({
3213
3060
  }
3214
3061
  ]
3215
3062
  }));
3216
- var saveRegistryLookupSchema = z11.object({
3217
- type: z11.literal(stellarStateCallTypes.saveRegistryLookup),
3063
+ var saveRegistryLookupSchema = z9.object({
3064
+ type: z9.literal(stellarStateCallTypes.saveRegistryLookup),
3218
3065
  lookup: registryLookupSchema
3219
3066
  }).transform(({ type, lookup }) => {
3220
3067
  const operations = [
@@ -3250,9 +3097,9 @@ var saveRegistryLookupSchema = z11.object({
3250
3097
  }
3251
3098
  return { type, operations };
3252
3099
  });
3253
- var invalidateRegistryLookupSchema = z11.object({
3254
- type: z11.literal(stellarStateCallTypes.invalidateRegistryLookup),
3255
- address: z11.string().min(1)
3100
+ var invalidateRegistryLookupSchema = z9.object({
3101
+ type: z9.literal(stellarStateCallTypes.invalidateRegistryLookup),
3102
+ address: z9.string().min(1)
3256
3103
  }).transform(({ type, address }) => ({
3257
3104
  type,
3258
3105
  operations: [
@@ -3333,9 +3180,9 @@ var stellarTransactionStateDefinitions = [
3333
3180
  ];
3334
3181
 
3335
3182
  // src/state/schemas/wallet/scalar.ts
3336
- import { z as z12 } from "zod";
3337
- var saveWalletPrivateAddressScalarSchema = z12.object({
3338
- type: z12.literal(stellarStateCallTypes.saveWalletPrivateAddressScalar),
3183
+ import { z as z10 } from "zod";
3184
+ var saveWalletPrivateAddressScalarSchema = z10.object({
3185
+ type: z10.literal(stellarStateCallTypes.saveWalletPrivateAddressScalar),
3339
3186
  scalar: walletPrivateAddressScalarSchema
3340
3187
  }).transform(({ type, scalar }) => ({
3341
3188
  type,
@@ -3348,10 +3195,10 @@ var saveWalletPrivateAddressScalarSchema = z12.object({
3348
3195
  }
3349
3196
  ]
3350
3197
  }));
3351
- var readWalletPrivateAddressScalarSchema = z12.object({
3352
- type: z12.literal(stellarStateCallTypes.readWalletPrivateAddressScalar),
3353
- owner: z12.string().min(1),
3354
- nonce: z12.string().min(1)
3198
+ var readWalletPrivateAddressScalarSchema = z10.object({
3199
+ type: z10.literal(stellarStateCallTypes.readWalletPrivateAddressScalar),
3200
+ owner: z10.string().min(1),
3201
+ nonce: z10.string().min(1)
3355
3202
  }).transform(({ type, owner, nonce }) => ({
3356
3203
  type,
3357
3204
  operations: [
@@ -3364,9 +3211,9 @@ var readWalletPrivateAddressScalarSchema = z12.object({
3364
3211
  }));
3365
3212
 
3366
3213
  // src/state/schemas/wallet/private-address.ts
3367
- import { z as z13 } from "zod";
3368
- var saveWalletPrivateAddressRecordSchema = z13.object({
3369
- type: z13.literal(stellarStateCallTypes.saveWalletPrivateAddressRecord),
3214
+ import { z as z11 } from "zod";
3215
+ var saveWalletPrivateAddressRecordSchema = z11.object({
3216
+ type: z11.literal(stellarStateCallTypes.saveWalletPrivateAddressRecord),
3370
3217
  record: walletPrivateAddressRecordSchema
3371
3218
  }).transform(({ type, record }) => ({
3372
3219
  type,
@@ -3379,10 +3226,10 @@ var saveWalletPrivateAddressRecordSchema = z13.object({
3379
3226
  }
3380
3227
  ]
3381
3228
  }));
3382
- var readWalletPrivateAddressRecordSchema = z13.object({
3383
- type: z13.literal(stellarStateCallTypes.readWalletPrivateAddressRecord),
3384
- owner: z13.string().min(1),
3385
- nonce: z13.string().min(1)
3229
+ var readWalletPrivateAddressRecordSchema = z11.object({
3230
+ type: z11.literal(stellarStateCallTypes.readWalletPrivateAddressRecord),
3231
+ owner: z11.string().min(1),
3232
+ nonce: z11.string().min(1)
3386
3233
  }).transform(({ type, owner, nonce }) => ({
3387
3234
  type,
3388
3235
  operations: [
@@ -3393,10 +3240,10 @@ var readWalletPrivateAddressRecordSchema = z13.object({
3393
3240
  }
3394
3241
  ]
3395
3242
  }));
3396
- var setWalletDefaultPrivateAddressNonceSchema = z13.object({
3397
- type: z13.literal(stellarStateCallTypes.setWalletDefaultPrivateAddressNonce),
3398
- owner: z13.string().min(1),
3399
- nonce: z13.string().min(1)
3243
+ var setWalletDefaultPrivateAddressNonceSchema = z11.object({
3244
+ type: z11.literal(stellarStateCallTypes.setWalletDefaultPrivateAddressNonce),
3245
+ owner: z11.string().min(1),
3246
+ nonce: z11.string().min(1)
3400
3247
  }).transform(({ type, owner, nonce }) => ({
3401
3248
  type,
3402
3249
  operations: [
@@ -3408,9 +3255,9 @@ var setWalletDefaultPrivateAddressNonceSchema = z13.object({
3408
3255
  }
3409
3256
  ]
3410
3257
  }));
3411
- var readWalletDefaultPrivateAddressNonceSchema = z13.object({
3412
- type: z13.literal(stellarStateCallTypes.readWalletDefaultPrivateAddressNonce),
3413
- owner: z13.string().min(1)
3258
+ var readWalletDefaultPrivateAddressNonceSchema = z11.object({
3259
+ type: z11.literal(stellarStateCallTypes.readWalletDefaultPrivateAddressNonce),
3260
+ owner: z11.string().min(1)
3414
3261
  }).transform(({ type, owner }) => ({
3415
3262
  type,
3416
3263
  operations: [
@@ -3421,10 +3268,10 @@ var readWalletDefaultPrivateAddressNonceSchema = z13.object({
3421
3268
  }
3422
3269
  ]
3423
3270
  }));
3424
- var deleteWalletPrivateAddressScalarSchema = z13.object({
3425
- type: z13.literal(stellarStateCallTypes.deleteWalletPrivateAddressScalar),
3426
- owner: z13.string().min(1),
3427
- nonce: z13.string().min(1)
3271
+ var deleteWalletPrivateAddressScalarSchema = z11.object({
3272
+ type: z11.literal(stellarStateCallTypes.deleteWalletPrivateAddressScalar),
3273
+ owner: z11.string().min(1),
3274
+ nonce: z11.string().min(1)
3428
3275
  }).transform(({ type, owner, nonce }) => ({
3429
3276
  type,
3430
3277
  operations: [
@@ -3478,7 +3325,6 @@ var stellarWalletStateDefinitions = [
3478
3325
  // src/state/definitions/index.ts
3479
3326
  registerStellarArrayFilterSchemas();
3480
3327
  var stellarStateDefinitions = [
3481
- ...stellarClaimsStateDefinitions,
3482
3328
  ...stellarRegistryStateDefinitions,
3483
3329
  ...stellarAssetsStateDefinitions,
3484
3330
  ...stellarBalancesStateDefinitions,
@@ -3609,108 +3455,6 @@ function createAssetsService(context) {
3609
3455
  };
3610
3456
  }
3611
3457
 
3612
- // src/state/service/claims/read-methods.ts
3613
- function createClaimsReadMethods(context) {
3614
- const { bridge } = context;
3615
- async function getPendingClaims(filter = {}) {
3616
- const value = await bridge.read({
3617
- type: stellarStateCallTypes.readPendingClaims
3618
- });
3619
- const state = normalizePendingClaimsState(value);
3620
- const items = state.items.filter((claim) => {
3621
- if (filter.owner !== void 0 && claim.owner !== filter.owner) {
3622
- return false;
3623
- }
3624
- if (filter.asset !== void 0 && claim.asset !== filter.asset) {
3625
- return false;
3626
- }
3627
- return true;
3628
- });
3629
- if (state.pagination !== void 0) {
3630
- return { items, pagination: state.pagination };
3631
- }
3632
- return { items };
3633
- }
3634
- return {
3635
- getPendingClaims,
3636
- async getPendingClaimsCount(owner) {
3637
- const value = await bridge.read({
3638
- type: stellarStateCallTypes.readPendingClaimsCount,
3639
- owner
3640
- });
3641
- const count = normalizePendingClaimsCount(value);
3642
- if (count !== void 0) {
3643
- return count;
3644
- }
3645
- const claims = await getPendingClaims({ owner });
3646
- return claims.items.length;
3647
- }
3648
- };
3649
- }
3650
-
3651
- // src/state/service/claims/write-methods.ts
3652
- function appendPendingClaims(bridge, claims, paginationInfo) {
3653
- return bridge.write({
3654
- type: stellarStateCallTypes.pendingClaims,
3655
- claims,
3656
- paginationInfo
3657
- });
3658
- }
3659
- function replacePendingClaimsPage(bridge, input) {
3660
- return bridge.write({
3661
- type: stellarStateCallTypes.replacePendingClaimsPage,
3662
- owner: input.owner,
3663
- claims: input.claims,
3664
- paginationInfo: input.paginationInfo,
3665
- ...input.count === void 0 ? {} : { count: input.count }
3666
- });
3667
- }
3668
- function upsertPendingClaims(bridge, claims) {
3669
- return bridge.write({
3670
- type: stellarStateCallTypes.upsertPendingClaims,
3671
- claims
3672
- });
3673
- }
3674
- function removePendingClaims(bridge, ids) {
3675
- return bridge.write({
3676
- type: stellarStateCallTypes.removePendingClaims,
3677
- ids
3678
- });
3679
- }
3680
- function clearPendingClaims(bridge, input = {}) {
3681
- return bridge.write({
3682
- type: stellarStateCallTypes.clearPendingClaims,
3683
- ...input.owner === void 0 ? {} : { owner: input.owner },
3684
- ...input.asset === void 0 ? {} : { asset: input.asset }
3685
- });
3686
- }
3687
- function setPendingClaimsCount(bridge, owner, count) {
3688
- return bridge.write({
3689
- type: stellarStateCallTypes.setPendingClaimsCount,
3690
- owner,
3691
- count
3692
- });
3693
- }
3694
- function createClaimsWriteMethods(context) {
3695
- const { bridge } = context;
3696
- return {
3697
- appendPendingClaims: (claims, paginationInfo) => appendPendingClaims(bridge, claims, paginationInfo),
3698
- replacePendingClaimsPage: (input) => replacePendingClaimsPage(bridge, input),
3699
- upsertPendingClaims: (claims) => upsertPendingClaims(bridge, claims),
3700
- removePendingClaims: (ids) => removePendingClaims(bridge, ids),
3701
- clearPendingClaims: (input = {}) => clearPendingClaims(bridge, input),
3702
- setPendingClaimsCount: (owner, count) => setPendingClaimsCount(bridge, owner, count)
3703
- };
3704
- }
3705
-
3706
- // src/state/service/claims/index.ts
3707
- function createClaimsService(context) {
3708
- return {
3709
- ...createClaimsWriteMethods(context),
3710
- ...createClaimsReadMethods(context)
3711
- };
3712
- }
3713
-
3714
3458
  // src/state/service/deliveries/incoming-methods.ts
3715
3459
  function createIncomingDeliveryMethods(context) {
3716
3460
  const { bridge } = context;
@@ -4236,7 +3980,6 @@ function composeStellarStateService(adapter) {
4236
3980
  ...createWalletAddressService(base),
4237
3981
  ...createPoolMerkleService(base),
4238
3982
  ...createPoolEphemeralService(base),
4239
- ...createClaimsService(base),
4240
3983
  ...createDeliveriesService(base),
4241
3984
  ...createRecordsService(base)
4242
3985
  };
@@ -4403,22 +4146,63 @@ async function registerPrivateAddressOnChain(input) {
4403
4146
  return transactionHash;
4404
4147
  }
4405
4148
 
4406
- // src/transact/onboarding/recipient.ts
4407
- import { PrivacyPoolSDK as PrivacyPoolSDK3 } from "@auditable/privacy-pool-zk-sdk";
4149
+ // src/contracts/registry/resolve-transfer-recipient.ts
4150
+ import { StrKey as StrKey5 } from "@stellar/stellar-sdk";
4151
+
4152
+ // src/transact/escrow/derived-escrow-recipient.ts
4153
+ import { Buffer as Buffer13 } from "buffer";
4154
+ import { StrKey as StrKey4 } from "@stellar/stellar-sdk";
4155
+ import {
4156
+ derivedEscrowKey,
4157
+ ed25519PubkeyPayloadHexToWithdrawFrDecimals as ed25519PubkeyPayloadHexToWithdrawFrDecimals2,
4158
+ sampleDerivedEscrowKey
4159
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
4408
4160
  var COORDINATE_HEX_LENGTH2 = 64;
4409
- async function generateTemporaryRecipientPrivateAddress() {
4410
- await getPrivacyPoolService().getInitializedSdk();
4411
- const temporaryScalarHex = PrivacyPoolSDK3.generateRandomScalarHex32();
4412
- const sdk = await getPrivacyPoolService().getInitializedSdk();
4413
- const point = sdk.ecdhEphemeralPublicKeyFromScalarHex(temporaryScalarHex);
4414
- const publicKeyXHex = point.x.padStart(COORDINATE_HEX_LENGTH2, "0");
4415
- const publicKeyYHex = point.y.padStart(COORDINATE_HEX_LENGTH2, "0");
4161
+ function stellarAccountToFieldLimbs(stellarAddress) {
4162
+ const pkRaw = StrKey4.decodeEd25519PublicKey(stellarAddress.trim());
4163
+ const pkHex = Buffer13.from(pkRaw).toString("hex");
4164
+ const { hi, lo } = ed25519PubkeyPayloadHexToWithdrawFrDecimals2(pkHex);
4165
+ return { recipientHi: hi, recipientLo: lo };
4166
+ }
4167
+ function padCoordinateHex(value) {
4168
+ return value.replace(/^0x/iu, "").padStart(COORDINATE_HEX_LENGTH2, "0");
4169
+ }
4170
+ async function deriveEscrowRecipientFromStellarAddress(input) {
4171
+ const recipientStellarAddress = input.recipientStellarAddress.trim();
4172
+ if (!StrKey4.isValidEd25519PublicKey(recipientStellarAddress)) {
4173
+ throw new Error("Escrow recipient must be a Stellar G-address.");
4174
+ }
4175
+ const { recipientHi, recipientLo } = stellarAccountToFieldLimbs(
4176
+ recipientStellarAddress
4177
+ );
4178
+ const deriveKey = input.deriveKey ?? derivedEscrowKey;
4179
+ let nonceDecimal;
4180
+ let key;
4181
+ if (input.nonceDecimal) {
4182
+ nonceDecimal = input.nonceDecimal;
4183
+ key = await deriveKey(
4184
+ BigInt(nonceDecimal),
4185
+ BigInt(recipientHi),
4186
+ BigInt(recipientLo)
4187
+ );
4188
+ } else {
4189
+ const sampled = await sampleDerivedEscrowKey(
4190
+ BigInt(recipientHi),
4191
+ BigInt(recipientLo)
4192
+ );
4193
+ nonceDecimal = sampled.nonce.toString();
4194
+ key = sampled.key;
4195
+ }
4416
4196
  return {
4417
- temporaryScalarHex,
4418
- temporaryPrivateAddressStpl1: encodePrivateAddressFromHexCoordinates(
4419
- publicKeyXHex,
4420
- publicKeyYHex
4421
- )
4197
+ nonceDecimal,
4198
+ recipientHi,
4199
+ recipientLo,
4200
+ recipientStellarAddress,
4201
+ privateAddressStpl1: encodePrivateAddressFromHexCoordinates(
4202
+ padCoordinateHex(key.pointXHex),
4203
+ padCoordinateHex(key.pointYHex)
4204
+ ),
4205
+ scalarHex: padCoordinateHex(key.scalarHex)
4422
4206
  };
4423
4207
  }
4424
4208
 
@@ -4437,11 +4221,23 @@ async function resolveTransferRecipientFromChain(input) {
4437
4221
  recipientStellarAddress
4438
4222
  };
4439
4223
  }
4440
- const temporaryKey = await generateTemporaryRecipientPrivateAddress();
4224
+ if (!StrKey5.isValidEd25519PublicKey(recipientStellarAddress)) {
4225
+ throw new Error(
4226
+ "Transfers to unregistered recipients require a Stellar G-address."
4227
+ );
4228
+ }
4229
+ const escrow = await deriveEscrowRecipientFromStellarAddress({
4230
+ recipientStellarAddress
4231
+ });
4441
4232
  return {
4442
- recipientPrivateAddressStpl1: temporaryKey.temporaryPrivateAddressStpl1,
4233
+ recipientPrivateAddressStpl1: escrow.privateAddressStpl1,
4443
4234
  recipientStellarAddress,
4444
- temporaryRecipientKey: temporaryKey
4235
+ escrowSend: {
4236
+ nonceDecimal: escrow.nonceDecimal,
4237
+ recipientHi: escrow.recipientHi,
4238
+ recipientLo: escrow.recipientLo,
4239
+ recipientStellarAddress
4240
+ }
4445
4241
  };
4446
4242
  }
4447
4243
 
@@ -4449,7 +4245,7 @@ async function resolveTransferRecipientFromChain(input) {
4449
4245
  import { Api } from "@stellar/stellar-sdk/rpc";
4450
4246
 
4451
4247
  // src/rpc/soroban-transaction-meta.ts
4452
- import { Address, StrKey as StrKey5 } from "@stellar/stellar-sdk";
4248
+ import { Address, StrKey as StrKey6 } from "@stellar/stellar-sdk";
4453
4249
  var BIGINT_SHIFT_64 = 64n;
4454
4250
  var TRANSACTION_META_SWITCH_SOROBAN_V3 = 3;
4455
4251
  var TRANSACTION_META_SWITCH_SOROBAN_V4 = 4;
@@ -4493,7 +4289,7 @@ function extractAmountFromScValue(value) {
4493
4289
  return void 0;
4494
4290
  }
4495
4291
  function contractIdToString(contractId) {
4496
- return StrKey5.encodeContract(Buffer.from(contractId));
4292
+ return StrKey6.encodeContract(Buffer.from(contractId));
4497
4293
  }
4498
4294
  function scAddressToContractString(address) {
4499
4295
  if (address.switch().name !== "scAddressTypeContract") {
@@ -4817,7 +4613,8 @@ async function checkPrivateRecordSpendStatusWithEnvironment(input) {
4817
4613
  const environment = requireNetworkEnvironment(input.transactEnvironment);
4818
4614
  const contractContext = requireContractContext(environment);
4819
4615
  const nullifierHashHex = await getPrivacyPoolService().calculateNullifierHash(
4820
- input.nullifier
4616
+ input.nullifier,
4617
+ privKeyScalarDecimalFromRecipientScalarHex(input.privKeyScalarHex)
4821
4618
  );
4822
4619
  const poolContractId = input.poolContractId?.trim() || contractContext.network.poolContract;
4823
4620
  const spent = await readNullifierConsumedOnChain({
@@ -4876,140 +4673,30 @@ function createNullifierSpentChecker(transactEnvironment) {
4876
4673
  }
4877
4674
  return async ({
4878
4675
  nullifier,
4879
- walletPublicKey
4676
+ walletPublicKey,
4677
+ privKeyScalarHex,
4678
+ privateAddressStpl1
4880
4679
  }) => {
4680
+ const addressHint = privateAddressStpl1?.trim() ?? "";
4681
+ const resolvedFromEnsure = transactEnvironment.ensureSenderPrivKeyScalarHex ? await transactEnvironment.ensureSenderPrivKeyScalarHex(addressHint) : void 0;
4682
+ const resolvedFromState = addressHint && transactEnvironment.resolveSenderPrivKeyScalarFromState ? await transactEnvironment.resolveSenderPrivKeyScalarFromState({
4683
+ owner: walletPublicKey,
4684
+ privateAddressStpl1: addressHint
4685
+ }) : void 0;
4686
+ const resolvedScalarHex = privKeyScalarHex?.trim() || resolvedFromEnsure?.trim() || resolvedFromState?.trim();
4687
+ if (!resolvedScalarHex) {
4688
+ throw new Error("Spend scalar is required to check owner-bound nullifiers.");
4689
+ }
4881
4690
  const status = await checkPrivateRecordSpendStatusWithEnvironment({
4882
4691
  transactEnvironment,
4883
4692
  nullifier,
4884
- walletPublicKey
4693
+ walletPublicKey,
4694
+ privKeyScalarHex: resolvedScalarHex
4885
4695
  });
4886
4696
  return status.spent;
4887
4697
  };
4888
4698
  }
4889
4699
 
4890
- // src/transact/merkle/fetch-contract.ts
4891
- import { Buffer as Buffer14 } from "buffer";
4892
-
4893
- // src/transact/merkle/encoding.ts
4894
- import "buffer";
4895
- var FR_ORDER = 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n;
4896
- function bufferToDecimal(buf) {
4897
- const hex = buf.toString("hex");
4898
- const bigintFromHex = BigInt(`0x${hex}`);
4899
- const reduced = bigintFromHex % FR_ORDER;
4900
- return reduced.toString();
4901
- }
4902
- function commitmentsBuffersToDecimal(buffers) {
4903
- return buffers.map((bufferRow) => bufferToDecimal(bufferRow));
4904
- }
4905
-
4906
- // src/transact/merkle/state-port.ts
4907
- function poolMerkleStateToCachedView(state) {
4908
- return {
4909
- commitments: state.commitments,
4910
- updatedAt: state.updatedAt,
4911
- merkleRootHex: state.merkleRootHex
4912
- };
4913
- }
4914
-
4915
- // src/transact/merkle/fetch-contract.ts
4916
- function normalizeCommitmentBuffers(rawBuffers) {
4917
- return rawBuffers.map(
4918
- (bufferRow) => Buffer14.isBuffer(bufferRow) ? bufferRow : Buffer14.from(bufferRow)
4919
- );
4920
- }
4921
- function mergeContractMerkleWithCache(parameters) {
4922
- const cachedCount = parameters.cachedState?.commitments.length ?? 0;
4923
- const shouldPreferContract = parameters.contractCount > cachedCount || !parameters.cachedState || cachedCount === 0;
4924
- if (shouldPreferContract) {
4925
- const updatedAt = Date.now();
4926
- void parameters.poolMerkleState?.set({
4927
- poolContract: parameters.poolContractId,
4928
- commitments: parameters.contractCommitments,
4929
- commitmentCount: parameters.contractCount,
4930
- merkleRootHex: parameters.merkleRootHex,
4931
- updatedAt
4932
- });
4933
- return {
4934
- commitments: parameters.contractCommitments,
4935
- updatedAt,
4936
- merkleRootHex: parameters.merkleRootHex,
4937
- commitmentCount: parameters.contractCount
4938
- };
4939
- }
4940
- return {
4941
- commitments: parameters.cachedState.commitments,
4942
- updatedAt: parameters.cachedState.updatedAt,
4943
- merkleRootHex: parameters.cachedState.merkleRootHex ?? parameters.merkleRootHex,
4944
- commitmentCount: parameters.cachedState.commitments.length
4945
- };
4946
- }
4947
- async function readCachedPoolMerkleView(poolMerkleState, poolContractId) {
4948
- if (!poolMerkleState) {
4949
- return void 0;
4950
- }
4951
- const cached = await poolMerkleState.get(poolContractId);
4952
- return cached ? poolMerkleStateToCachedView(cached) : void 0;
4953
- }
4954
- async function fetchAndMergeMerkleState(parameters) {
4955
- const client = readPoolClientFactory(parameters.transactEnvironment)({
4956
- contractId: parameters.poolContractId,
4957
- walletPublicKey: parameters.walletPublicKey,
4958
- networkPassphrase: parameters.transactEnvironment.network.networkPassphrase,
4959
- sorobanRpcUrl: parameters.transactEnvironment.network.rpcUrl
4960
- });
4961
- const commitmentsRead = await client.get_commitments();
4962
- const rawBuffers = commitmentsRead.result;
4963
- const buffers = normalizeCommitmentBuffers(rawBuffers);
4964
- const contractCommitments = commitmentsBuffersToDecimal(buffers);
4965
- const contractCount = contractCommitments.length;
4966
- const rootRead = await client.get_merkle_root();
4967
- const merkleRootBuffer = rootRead.result;
4968
- const merkleRootHex = Buffer14.from(merkleRootBuffer).toString("hex");
4969
- const cachedState = await readCachedPoolMerkleView(
4970
- parameters.poolMerkleState,
4971
- parameters.poolContractId
4972
- );
4973
- return mergeContractMerkleWithCache({
4974
- poolContractId: parameters.poolContractId,
4975
- contractCommitments,
4976
- contractCount,
4977
- merkleRootHex,
4978
- cachedState,
4979
- ...parameters.poolMerkleState ? { poolMerkleState: parameters.poolMerkleState } : {}
4980
- });
4981
- }
4982
- async function readLeafEphemeralHex(parameters) {
4983
- const cached = await parameters.leafEphemeral?.get({
4984
- poolContract: parameters.poolContractId,
4985
- leafIndex: parameters.leafIndex
4986
- });
4987
- if (cached?.xHex && cached.yHex) {
4988
- return { xHex: cached.xHex, yHex: cached.yHex };
4989
- }
4990
- const client = readPoolClientFactory(parameters.transactEnvironment)({
4991
- contractId: parameters.poolContractId,
4992
- walletPublicKey: parameters.walletPublicKey,
4993
- networkPassphrase: parameters.transactEnvironment.network.networkPassphrase,
4994
- sorobanRpcUrl: parameters.transactEnvironment.network.rpcUrl
4995
- });
4996
- const read = await client.get_leaf_ephemeral({ leaf_index: parameters.leafIndex });
4997
- const coords = read.result;
4998
- if (!coords?.x || !coords?.y) {
4999
- throw new Error("Missing leaf ephemeral key on contract");
5000
- }
5001
- const xHex = Buffer14.from(coords.x).toString("hex");
5002
- const yHex = Buffer14.from(coords.y).toString("hex");
5003
- await parameters.leafEphemeral?.set({
5004
- poolContract: parameters.poolContractId,
5005
- leafIndex: parameters.leafIndex,
5006
- xHex,
5007
- yHex,
5008
- cachedAt: (/* @__PURE__ */ new Date()).toISOString()
5009
- });
5010
- return { xHex, yHex };
5011
- }
5012
-
5013
4700
  // src/client/pool-sync.ts
5014
4701
  function requireTransactEnvironment(transactEnvironment) {
5015
4702
  if (!transactEnvironment) {
@@ -5132,7 +4819,6 @@ function createOperationsFacet(config, state) {
5132
4819
  wallet: config.wallet,
5133
4820
  engine: config.transactEngine,
5134
4821
  poolContract: config.network.poolContract,
5135
- getPendingClaims: () => state.getPendingClaims(),
5136
4822
  ...checkNullifierSpent ? { checkNullifierSpent } : {}
5137
4823
  }),
5138
4824
  policy: createStellarPolicyAdapter(config.policy)
@@ -5176,103 +4862,6 @@ function createAssetsStateDelegates(state) {
5176
4862
  };
5177
4863
  }
5178
4864
 
5179
- // src/state/claims/backend.ts
5180
- var DEFAULT_PENDING_CLAIMS_PAGE_SIZE = 20;
5181
- async function fetchPendingClaimsBackendPage(input) {
5182
- const page = input.page ?? 1;
5183
- const limit = input.pageSize ?? DEFAULT_PENDING_CLAIMS_PAGE_SIZE;
5184
- const params = new URLSearchParams({
5185
- ownerAddress: input.ownerAddress,
5186
- page: String(page),
5187
- limit: String(limit)
5188
- });
5189
- const baseUrl = input.backendBaseUrl.replace(/\/$/, "");
5190
- const response = await fetch(`${baseUrl}/pending-claims?${params.toString()}`);
5191
- if (!response.ok) {
5192
- throw new Error(`Pending claims request failed: ${response.status}`);
5193
- }
5194
- return response.json();
5195
- }
5196
- async function fetchPendingClaimsBackendCount(input) {
5197
- const params = new URLSearchParams({
5198
- ownerAddress: input.ownerAddress
5199
- });
5200
- const baseUrl = input.backendBaseUrl.replace(/\/$/, "");
5201
- const response = await fetch(`${baseUrl}/pending-claims/count?${params.toString()}`);
5202
- if (!response.ok) {
5203
- throw new Error(`Pending claims count request failed: ${response.status}`);
5204
- }
5205
- const payload = await response.json();
5206
- return payload.count;
5207
- }
5208
- function mapBackendPendingClaimItem(item, asset = "") {
5209
- return {
5210
- id: String(item.id),
5211
- owner: item.ownerAddress,
5212
- asset,
5213
- amount: BigInt(item.noteValue),
5214
- createdAt: item.createdAt,
5215
- poolTxId: item.poolTxId,
5216
- commitmentHex: item.commitmentHex,
5217
- nullifierHex: item.nullifierHex,
5218
- futureNullifierHashHex: item.futureNullifierHashHex,
5219
- assetHiHex: item.assetHiHex,
5220
- assetLoHex: item.assetLoHex,
5221
- nullifierFieldHex: item.nullifierFieldHex,
5222
- secretHex: item.secretHex,
5223
- tempPublicKeyXHex: item.tempPublicKeyXHex,
5224
- tempPublicKeyYHex: item.tempPublicKeyYHex,
5225
- encryptedRecoveryBase64: item.encryptedRecoveryBase64,
5226
- createdAtLedger: item.createdAtLedger
5227
- };
5228
- }
5229
- function mapBackendPendingClaimsPage(response, asset = "") {
5230
- return {
5231
- claims: response.data.map((item) => mapBackendPendingClaimItem(item, asset)),
5232
- paginationInfo: {
5233
- total: response.meta.total,
5234
- page: response.meta.page,
5235
- pageSize: response.meta.limit,
5236
- hasMore: response.meta.page < response.meta.totalPages
5237
- }
5238
- };
5239
- }
5240
-
5241
- // src/state/claims/sync-from-backend.ts
5242
- async function syncPendingClaimsFromBackend(stateService, input) {
5243
- const response = await fetchPendingClaimsBackendPage(input);
5244
- const { claims, paginationInfo } = mapBackendPendingClaimsPage(
5245
- response,
5246
- input.asset ?? ""
5247
- );
5248
- await stateService.replacePendingClaimsPage({
5249
- owner: input.ownerAddress,
5250
- claims,
5251
- paginationInfo,
5252
- count: paginationInfo.total
5253
- });
5254
- }
5255
- async function syncPendingClaimsCountFromBackend(stateService, ownerAddress, input) {
5256
- const count = await fetchPendingClaimsBackendCount(input);
5257
- await stateService.setPendingClaimsCount(ownerAddress, count);
5258
- }
5259
-
5260
- // src/client/state-delegates/claims.ts
5261
- function createClaimsStateDelegates(state) {
5262
- return {
5263
- appendPendingClaims: (claims, paginationInfo) => state.appendPendingClaims(claims, paginationInfo),
5264
- loadPendingClaimsFromBackend: (input) => syncPendingClaimsFromBackend(state, input),
5265
- loadPendingClaimsCountFromBackend: (input) => syncPendingClaimsCountFromBackend(state, input.ownerAddress, input),
5266
- replacePendingClaimsPage: (input) => state.replacePendingClaimsPage(input),
5267
- upsertPendingClaims: (claims) => state.upsertPendingClaims(claims),
5268
- removePendingClaims: (ids) => state.removePendingClaims(ids),
5269
- clearPendingClaims: (input = {}) => state.clearPendingClaims(input),
5270
- getPendingClaims: (filter = {}) => state.getPendingClaims(filter),
5271
- getPendingClaimsCount: (owner) => state.getPendingClaimsCount(owner),
5272
- setPendingClaimsCount: (owner, count) => state.setPendingClaimsCount(owner, count)
5273
- };
5274
- }
5275
-
5276
4865
  // src/client/state-delegates/deliveries.ts
5277
4866
  function createDeliveriesStateDelegates(state) {
5278
4867
  return {
@@ -5337,7 +4926,6 @@ function createStateDelegates(state) {
5337
4926
  ...createAssetsStateDelegates(state),
5338
4927
  ...createRegistryStateDelegates(state),
5339
4928
  ...createPoolStateDelegates(state),
5340
- ...createClaimsStateDelegates(state),
5341
4929
  ...createDeliveriesStateDelegates(state),
5342
4930
  ...createRecordsStateDelegates(state)
5343
4931
  };
@@ -5464,91 +5052,14 @@ function createStellarPrivacyClientFromResolvedConfig(config) {
5464
5052
  }
5465
5053
 
5466
5054
  // src/transact/engine/default-factory.ts
5467
- import { PrivacyPoolSDK as PrivacyPoolSDK4 } from "@auditable/privacy-pool-zk-sdk";
5055
+ import { PrivacyPoolSDK as PrivacyPoolSDK3 } from "@arcanetech/stellar-privacy-pool-zk-sdk";
5468
5056
 
5469
- // src/transact/engine/prepare/shared.ts
5470
- async function resolveTokenContractId2(environment, assetId) {
5471
- if (environment.resolveTokenContractId) {
5472
- return environment.resolveTokenContractId(assetId);
5473
- }
5474
- throw new Error(`Token contract is not configured for asset ${assetId}.`);
5475
- }
5476
- async function resolveWalletPublicKey(environment, prepared) {
5477
- if (environment.resolveWalletPublicKey) {
5478
- return environment.resolveWalletPublicKey();
5479
- }
5480
- if (prepared.kind === "deposit") {
5481
- const depositIntent = prepared.intent;
5482
- return depositIntent.from;
5483
- }
5484
- throw new Error("Wallet public key resolver is not configured.");
5485
- }
5486
- async function resolveSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
5487
- const cached = await readSenderPrivKeyScalarHex(
5488
- environment,
5489
- privateAddressStpl1,
5490
- owner
5491
- );
5492
- if (cached) {
5493
- return cached;
5494
- }
5495
- if (environment.ensureSenderPrivKeyScalarHex) {
5496
- return environment.ensureSenderPrivKeyScalarHex(privateAddressStpl1);
5497
- }
5498
- if (!environment.resolveSenderPrivKeyScalarHex) {
5499
- throw new Error("Sender private key scalar resolver is not configured.");
5500
- }
5501
- return environment.resolveSenderPrivKeyScalarHex(privateAddressStpl1);
5502
- }
5503
- async function readSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
5504
- if (owner && environment.resolveSenderPrivKeyScalarFromState) {
5505
- const fromState = await environment.resolveSenderPrivKeyScalarFromState({
5506
- owner,
5507
- privateAddressStpl1
5508
- });
5509
- if (fromState?.trim()) {
5510
- return fromState.trim();
5511
- }
5512
- }
5513
- if (environment.readSenderPrivKeyScalarHex) {
5514
- const cached = await environment.readSenderPrivKeyScalarHex(privateAddressStpl1);
5515
- if (cached?.trim()) {
5516
- return cached.trim();
5517
- }
5518
- }
5519
- return void 0;
5520
- }
5521
- async function ensureSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner) {
5522
- const cached = await readSenderPrivKeyScalarHex(
5523
- environment,
5524
- privateAddressStpl1,
5525
- owner
5526
- );
5527
- if (cached) {
5528
- return cached;
5529
- }
5530
- if (environment.ensureSenderPrivKeyScalarHex) {
5531
- return environment.ensureSenderPrivKeyScalarHex(privateAddressStpl1);
5532
- }
5533
- return resolveSenderPrivKeyScalarHex(environment, privateAddressStpl1, owner);
5534
- }
5535
- async function loadMerkleState(environment, walletPublicKey) {
5536
- const merged = await fetchAndMergeMerkleState({
5537
- poolContractId: environment.network.poolContract,
5538
- walletPublicKey,
5539
- transactEnvironment: environment,
5540
- ...environment.poolMerkleState ? { poolMerkleState: environment.poolMerkleState } : {}
5541
- });
5542
- return { commitments: merged.commitments };
5543
- }
5544
- function enrichPreparedOperation(prepared, outputRecords, artifacts) {
5057
+ // src/transact/pool/proof-types.ts
5058
+ function ciphertextArtifactsFromProof(proof) {
5545
5059
  return {
5546
- ...prepared,
5547
- outputRecords,
5548
- transactArtifacts: artifacts,
5549
- submissionPayload: {
5550
- operationId: crypto.randomUUID(),
5551
- signed: false
5060
+ ...proof.ciphertext_hex === void 0 ? {} : { ciphertextHex: proof.ciphertext_hex },
5061
+ ...proof.output_note_ephemeral_scalars === void 0 ? {} : {
5062
+ outputNoteEphemeralScalars: [...proof.output_note_ephemeral_scalars]
5552
5063
  }
5553
5064
  };
5554
5065
  }
@@ -5603,6 +5114,7 @@ async function prepareDepositOperation(prepared, environment, poolService) {
5603
5114
  return enrichPreparedOperation(prepared, [outputRecord], {
5604
5115
  proofHex: depositProof.proof.proof_hex,
5605
5116
  publicHex: depositProof.proof.public_hex,
5117
+ ...ciphertextArtifactsFromProof(depositProof.proof),
5606
5118
  applicationIdsPlaintext: depositProof.proof.applicationIdsPlaintext,
5607
5119
  tokenAddress,
5608
5120
  depositScalarHex: depositProof.depositScalarHex,
@@ -5612,6 +5124,42 @@ async function prepareDepositOperation(prepared, environment, poolService) {
5612
5124
  });
5613
5125
  }
5614
5126
 
5127
+ // src/transact/engine/prepare/transfer-helpers.ts
5128
+ import { StrKey as StrKey7 } from "@stellar/stellar-sdk";
5129
+ function isStellarAccountRecipient(prepared) {
5130
+ return prepared.kind === "transfer" && StrKey7.isValidEd25519PublicKey(prepared.intent.to.trim());
5131
+ }
5132
+ async function stampEscrowSendArtifacts(prepared, environment, walletPublicKey) {
5133
+ if (!isStellarAccountRecipient(prepared)) {
5134
+ return {};
5135
+ }
5136
+ if (!environment.resolveTransferRecipientAtExecute) {
5137
+ return {};
5138
+ }
5139
+ const recipient = await environment.resolveTransferRecipientAtExecute({
5140
+ recipientStellarAddress: prepared.intent.to.trim(),
5141
+ walletPublicKey
5142
+ });
5143
+ if (!recipient.escrowSend) {
5144
+ return {};
5145
+ }
5146
+ return { escrowSend: true, spendSource: "escrow" };
5147
+ }
5148
+ async function resolveTransferRecipientForExecute(prepared, environment, walletPublicKey) {
5149
+ if (!isStellarAccountRecipient(prepared)) {
5150
+ return {
5151
+ recipientPrivateAddressStpl1: prepared.intent.to.trim()
5152
+ };
5153
+ }
5154
+ if (!environment.resolveTransferRecipientAtExecute) {
5155
+ throw new Error("Transfer recipient resolver is not configured.");
5156
+ }
5157
+ return environment.resolveTransferRecipientAtExecute({
5158
+ recipientStellarAddress: prepared.intent.to.trim(),
5159
+ walletPublicKey
5160
+ });
5161
+ }
5162
+
5615
5163
  // src/transact/engine/prepare/spend.ts
5616
5164
  async function prepareSpendOperation(prepared, environment) {
5617
5165
  const walletPublicKey = await resolveWalletPublicKey(environment, prepared);
@@ -5622,18 +5170,52 @@ async function prepareSpendOperation(prepared, environment) {
5622
5170
  ...prepared.transactArtifacts,
5623
5171
  tokenAddress,
5624
5172
  walletPublicKey,
5625
- executeFinalizeRequired: true
5173
+ executeFinalizeRequired: true,
5174
+ ...await stampEscrowSendArtifacts(prepared, environment, walletPublicKey)
5626
5175
  }
5627
5176
  };
5628
5177
  }
5629
5178
  var prepareTransferOperation2 = prepareSpendOperation;
5630
5179
  var prepareWithdrawOperation = prepareSpendOperation;
5631
5180
 
5181
+ // src/transact/encoding/ephemeral-key.ts
5182
+ var HEX_64_RE = /^[\da-f]{64}$/iu;
5183
+ function normalizeCoordinate(value) {
5184
+ const hex = value.trim().replace(/^0x/iu, "").toLowerCase();
5185
+ if (!HEX_64_RE.test(hex)) {
5186
+ throw new Error("Ephemeral key coordinate must be a 32-byte hex string.");
5187
+ }
5188
+ return hex;
5189
+ }
5190
+ function serializeEphemeralKeyString(point) {
5191
+ return `${normalizeCoordinate(point.xHex)}:${normalizeCoordinate(point.yHex)}`;
5192
+ }
5193
+
5194
+ // src/transact/escrow/require-escrow-spend-scalar.ts
5195
+ function isEscrowSweepSpend(artifacts) {
5196
+ return artifacts?.spendSource === "escrow" && artifacts.escrowSend !== true;
5197
+ }
5198
+ function requireEscrowSpendScalarHex(artifacts) {
5199
+ if (!isEscrowSweepSpend(artifacts)) {
5200
+ throw new Error("Escrow sweep requires spendSource escrow.");
5201
+ }
5202
+ const hex = artifacts?.escrowSpendScalarHex?.trim();
5203
+ if (!hex) {
5204
+ throw new Error("Escrow sweep requires the reconstructed note owner scalar.");
5205
+ }
5206
+ return hex;
5207
+ }
5208
+ function nullifierCheckSpendScalarHex(artifacts) {
5209
+ if (!isEscrowSweepSpend(artifacts)) {
5210
+ return void 0;
5211
+ }
5212
+ return requireEscrowSpendScalarHex(artifacts);
5213
+ }
5214
+
5632
5215
  // src/transact/engine/spend-proof-context.ts
5633
5216
  async function resolveSenderPrivKeyScalarHex2(input) {
5634
- const pendingClaim = input.prepared.transactArtifacts?.pendingClaim;
5635
- if (pendingClaim) {
5636
- return recoveryScalarHexFromClaim(pendingClaim);
5217
+ if (isEscrowSweepSpend(input.prepared.transactArtifacts)) {
5218
+ return requireEscrowSpendScalarHex(input.prepared.transactArtifacts);
5637
5219
  }
5638
5220
  if (input.prepared.kind !== "transfer" && input.prepared.kind !== "withdraw") {
5639
5221
  throw new Error("Spend execution requires a transfer or withdraw intent.");
@@ -5682,8 +5264,7 @@ async function buildSpendProofContextAtExecute(input) {
5682
5264
  commitments,
5683
5265
  ephemeral,
5684
5266
  senderPrivKeyScalarHex,
5685
- recipientPrivateAddressStpl1: input.recipientPrivateAddressStpl1,
5686
- pendingClaim: input.prepared.transactArtifacts?.pendingClaim
5267
+ recipientPrivateAddressStpl1: input.recipientPrivateAddressStpl1
5687
5268
  };
5688
5269
  }
5689
5270
  async function readCoinEphemeralForRecord(input) {
@@ -5702,14 +5283,19 @@ async function readCoinEphemeralForRecord(input) {
5702
5283
  return { coin, ephemeral };
5703
5284
  }
5704
5285
 
5705
- // src/transact/onboarding/recipient-change-deposits.ts
5706
- async function buildPaddingDepositPair(recipientPrivateAddressStpl1, tokenAddress, recipientDeposit) {
5707
- const paddingSlot = await getPrivacyPoolService().buildAlignedDepositSlot({
5708
- privateAddressStpl1: recipientPrivateAddressStpl1,
5709
- amountStroops: ZERO_STROOPS,
5710
- tokenAddress
5711
- });
5712
- return [recipientDeposit, paddingSlot.deposit];
5286
+ // src/transact/proofs/confidential/recipient-change-deposits.ts
5287
+ function escrowOutputFields(input) {
5288
+ if (!input.escrowSend) {
5289
+ return {};
5290
+ }
5291
+ return {
5292
+ escrowNonce: input.escrowSend.nonceDecimal,
5293
+ recipientHi: input.escrowSend.recipientHi,
5294
+ recipientLo: input.escrowSend.recipientLo
5295
+ };
5296
+ }
5297
+ function paddingDepositPair(recipientDeposit) {
5298
+ return [recipientDeposit, "dummy"];
5713
5299
  }
5714
5300
  async function buildChangeDepositPair(parameters) {
5715
5301
  const changeSlot = await getPrivacyPoolService().buildAlignedDepositSlot({
@@ -5728,24 +5314,24 @@ async function buildChangeDepositPair(parameters) {
5728
5314
  };
5729
5315
  }
5730
5316
  async function buildRecipientAndOptionalChangeDeposits(parameters) {
5317
+ const escrow = {
5318
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
5319
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
5320
+ };
5731
5321
  const recipientPrivateAddress = parameters.recipientPrivateAddressStpl1.trim();
5732
5322
  const recipientSlot = await getPrivacyPoolService().buildAlignedDepositSlot({
5733
5323
  privateAddressStpl1: recipientPrivateAddress,
5734
5324
  amountStroops: parameters.transferStroops,
5735
- tokenAddress: parameters.tokenAddress
5325
+ tokenAddress: parameters.tokenAddress,
5326
+ ...escrowOutputFields(escrow)
5736
5327
  });
5737
5328
  if (parameters.changeStroops <= ZERO_STROOPS) {
5738
5329
  return {
5739
5330
  recipientSlot,
5740
- deposits: await buildPaddingDepositPair(
5741
- recipientPrivateAddress,
5742
- parameters.tokenAddress,
5743
- recipientSlot.deposit
5744
- )
5331
+ deposits: paddingDepositPair(recipientSlot.deposit)
5745
5332
  };
5746
5333
  }
5747
5334
  const changeResult = await buildChangeDepositPair({
5748
- recipientPrivateAddressStpl1: recipientPrivateAddress,
5749
5335
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
5750
5336
  changeStroops: parameters.changeStroops,
5751
5337
  tokenAddress: parameters.tokenAddress,
@@ -5767,20 +5353,61 @@ function generatedOutputCoinFromSlot(slot) {
5767
5353
  precommitementHex: slot.precommitementHex
5768
5354
  };
5769
5355
  }
5356
+ function publicEscrowRecipientLimbs(parameters) {
5357
+ const limbs = parameters.escrowClaimantLimbs;
5358
+ if (!limbs) {
5359
+ return void 0;
5360
+ }
5361
+ return {
5362
+ escrowRecipientHi: limbs.recipientHi,
5363
+ escrowRecipientLo: limbs.recipientLo
5364
+ };
5365
+ }
5366
+ function sweepWithdrawStamp(parameters) {
5367
+ const publicLimbs = publicEscrowRecipientLimbs(parameters);
5368
+ if (!publicLimbs) {
5369
+ return void 0;
5370
+ }
5371
+ return {
5372
+ ...publicLimbs,
5373
+ ...parameters.escrowClaimantLimbs?.nonceDecimal ? { escrowNonce: parameters.escrowClaimantLimbs.nonceDecimal } : {}
5374
+ };
5375
+ }
5376
+ function stampWithdrawEscrowLimbs(withdrawObject, limbs) {
5377
+ if (!limbs) {
5378
+ return withdrawObject;
5379
+ }
5380
+ return {
5381
+ ...withdrawObject,
5382
+ recipientStellar: [limbs.escrowRecipientHi, limbs.escrowRecipientLo],
5383
+ ...limbs.escrowNonce ? { escrowNonce: limbs.escrowNonce } : {}
5384
+ };
5385
+ }
5386
+ function sweepOutputOwnerFields(parameters) {
5387
+ if (!parameters.escrowClaimantLimbs) {
5388
+ return void 0;
5389
+ }
5390
+ const [sweepOutputOwnerPubX, sweepOutputOwnerPubY] = recipientPublicKeysDecimalFromPrivateAddress(
5391
+ parameters.recipientPrivateAddressStpl1
5392
+ );
5393
+ return { sweepOutputOwnerPubX, sweepOutputOwnerPubY };
5394
+ }
5770
5395
  async function buildTransferDepositsAndPublicInput(parameters) {
5771
5396
  const { recipientSlot, deposits, changeCoin } = await buildRecipientAndOptionalChangeDeposits({
5772
5397
  recipientPrivateAddressStpl1: parameters.recipientPrivateAddressStpl1,
5773
5398
  transferStroops: parameters.transferStroops,
5774
5399
  changeStroops: parameters.changeStroops,
5775
5400
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
5776
- tokenAddress: parameters.tokenAddress
5401
+ tokenAddress: parameters.tokenAddress,
5402
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
5403
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
5777
5404
  });
5778
5405
  const publicInput = withTokenAddressPublicInputs(
5779
5406
  {
5780
5407
  stateRoot: parameters.stateRoot,
5781
- withdrawAddressHi: parameters.withdrawAddressHi,
5782
- withdrawAddressLo: parameters.withdrawAddressLo,
5783
- privKeyScalar: parameters.privKeyScalar
5408
+ privKeyScalar: parameters.privKeyScalar,
5409
+ ...publicEscrowRecipientLimbs(parameters),
5410
+ ...sweepOutputOwnerFields(parameters)
5784
5411
  },
5785
5412
  parameters.tokenAddress
5786
5413
  );
@@ -5792,10 +5419,6 @@ async function buildTransferDepositsAndPublicInput(parameters) {
5792
5419
  };
5793
5420
  }
5794
5421
  async function buildSenderTransferDepositsAndPublicInput(parameters) {
5795
- const { hi, lo, privKeyScalar } = senderWithdrawFrAndScalar({
5796
- senderGAddress: parameters.senderGAddress,
5797
- senderPrivKeyScalarHex: parameters.senderPrivKeyScalarHex
5798
- });
5799
5422
  return buildTransferDepositsAndPublicInput({
5800
5423
  recipientPrivateAddressStpl1: parameters.recipientPrivateAddressStpl1,
5801
5424
  transferStroops: parameters.transferStroops,
@@ -5803,31 +5426,55 @@ async function buildSenderTransferDepositsAndPublicInput(parameters) {
5803
5426
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
5804
5427
  tokenAddress: parameters.tokenAddress,
5805
5428
  stateRoot: parameters.stateRoot,
5806
- withdrawAddressHi: hi,
5807
- withdrawAddressLo: lo,
5808
- privKeyScalar
5429
+ privKeyScalar: privKeyScalarDecimalFromRecipientScalarHex(
5430
+ parameters.senderPrivKeyScalarHex
5431
+ ),
5432
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
5433
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
5809
5434
  });
5810
5435
  }
5811
5436
 
5812
5437
  // src/transact/proofs/confidential/dual.ts
5813
- function buildDualTransferApplicationIds(applicationId, changeCoin) {
5814
- return [
5815
- applicationId,
5816
- applicationId,
5817
- applicationId,
5818
- changeCoin ? applicationId : "0"
5819
- ];
5438
+ function confidentialEscrowFields(parameters) {
5439
+ return {
5440
+ ...parameters.escrowSend ? { escrowSend: parameters.escrowSend } : {},
5441
+ ...parameters.escrowClaimantLimbs ? { escrowClaimantLimbs: parameters.escrowClaimantLimbs } : {}
5442
+ };
5443
+ }
5444
+ function stampDualWithdrawLegs(legs, parameters) {
5445
+ const escrowLimbs = sweepWithdrawStamp(confidentialEscrowFields(parameters));
5446
+ return {
5447
+ legA: {
5448
+ ...legs.legA,
5449
+ withdrawObject: stampWithdrawEscrowLimbs(legs.legA.withdrawObject, escrowLimbs)
5450
+ },
5451
+ legB: {
5452
+ ...legs.legB,
5453
+ withdrawObject: stampWithdrawEscrowLimbs(legs.legB.withdrawObject, escrowLimbs)
5454
+ }
5455
+ };
5456
+ }
5457
+ function buildDualTransferApplicationIds(sdk, applicationId, changeCoin) {
5458
+ return buildApplicationIdHints({
5459
+ sdk,
5460
+ inputIds: [applicationId, applicationId],
5461
+ outputIds: [applicationId, changeCoin ? applicationId : "0"]
5462
+ });
5820
5463
  }
5821
5464
  async function proveDualConfidentialTransfer(parameters) {
5822
5465
  const audit = buildPoolTransactionAuditParameters({
5823
5466
  applicationId: parameters.applicationId,
5467
+ nAuditSlots: parameters.sdk.getLayout().nAuditSlots,
5824
5468
  ...parameters.auditPublicKey ? { auditPublicKey: parameters.auditPublicKey } : {}
5825
5469
  });
5826
5470
  return parameters.sdk.proveTransaction(
5827
5471
  parameters.publicInput,
5828
- buildZeroPublicLegs(),
5829
- [parameters.legA.withdrawObject, parameters.legB.withdrawObject],
5830
- parameters.deposits,
5472
+ padPublicLegsToLayout(parameters.sdk, buildZeroPublicLegs()),
5473
+ padWithdrawSlotsToLayout(parameters.sdk, [
5474
+ parameters.legA.withdrawObject,
5475
+ parameters.legB.withdrawObject
5476
+ ]),
5477
+ padDepositSlotsToLayout(parameters.sdk, parameters.deposits),
5831
5478
  audit
5832
5479
  );
5833
5480
  }
@@ -5841,24 +5488,33 @@ async function buildDualTransferProofContext(parameters, applicationId, sdk) {
5841
5488
  changeStroops,
5842
5489
  parameters.selfPrivateAddressStpl1ForChange
5843
5490
  );
5844
- const { legA, legB } = dualWithdrawLegsWithSharedRoot({
5845
- sdk,
5846
- coinA: parameters.coinA,
5847
- coinB: parameters.coinB,
5848
- state: parameters.state,
5849
- ephemeralA: parseEphemeralKeyString(parameters.ephemeralAKey),
5850
- ephemeralB: parseEphemeralKeyString(parameters.ephemeralBKey),
5851
- applicationId
5852
- });
5491
+ const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
5492
+ parameters.senderPrivKeyScalarHex
5493
+ );
5494
+ const ownerPubHex = sdk.ecdhEphemeralPublicKeyFromScalarHex(
5495
+ parameters.senderPrivKeyScalarHex
5496
+ );
5497
+ const { legA, legB } = stampDualWithdrawLegs(
5498
+ dualWithdrawLegsWithSharedRoot({
5499
+ sdk,
5500
+ coinA: parameters.coinA,
5501
+ coinB: parameters.coinB,
5502
+ state: parameters.state,
5503
+ ownerPubHex,
5504
+ privKeyScalar,
5505
+ applicationId
5506
+ }),
5507
+ parameters
5508
+ );
5853
5509
  const transferInputs = await buildSenderTransferDepositsAndPublicInput({
5854
- senderGAddress: parameters.senderGAddress,
5855
5510
  senderPrivKeyScalarHex: parameters.senderPrivKeyScalarHex,
5856
5511
  recipientPrivateAddressStpl1: parameters.recipientPrivateAddressStpl1,
5857
5512
  transferStroops: parameters.transferStroops,
5858
5513
  changeStroops,
5859
5514
  selfPrivateAddressStpl1ForChange: parameters.selfPrivateAddressStpl1ForChange,
5860
5515
  tokenAddress: parameters.tokenAddress,
5861
- stateRoot: legA.witness.stateRoot
5516
+ stateRoot: legA.witness.stateRoot,
5517
+ ...confidentialEscrowFields(parameters)
5862
5518
  });
5863
5519
  return { legA, legB, applicationId, ...transferInputs };
5864
5520
  }
@@ -5886,7 +5542,11 @@ async function prepareConfidentialTransferProofDual(parameters) {
5886
5542
  }));
5887
5543
  return {
5888
5544
  ...proof,
5889
- applicationIdsPlaintext: buildDualTransferApplicationIds(applicationId, changeCoin),
5545
+ applicationIdsPlaintext: buildDualTransferApplicationIds(
5546
+ sdk,
5547
+ applicationId,
5548
+ changeCoin
5549
+ ),
5890
5550
  recipientCoin: generatedOutputCoinFromSlot(recipientSlot),
5891
5551
  ...changeCoin ? { changeCoin } : {}
5892
5552
  };
@@ -5904,51 +5564,72 @@ function validateSingleCoinTransferAmounts(transferStroops, noteStroops, selfPri
5904
5564
  requireChangeRecipientWhenPartial(changeStroops, selfPrivateAddressStpl1ForChange);
5905
5565
  return changeStroops;
5906
5566
  }
5907
- function buildSingleTransferApplicationIds(applicationId, changeCoin) {
5908
- return [applicationId, "0", applicationId, changeCoin ? applicationId : "0"];
5567
+ function buildSingleTransferApplicationIds(sdk, applicationId, changeCoin) {
5568
+ return buildApplicationIdHints({
5569
+ sdk,
5570
+ inputIds: [applicationId],
5571
+ outputIds: [applicationId, changeCoin ? applicationId : "0"]
5572
+ });
5909
5573
  }
5910
5574
  function buildTransferAuditParameters(parameters) {
5911
5575
  const auditPublicKey = parameters.poolService.getAuditPublicKey();
5912
5576
  return buildPoolTransactionAuditParameters({
5913
5577
  applicationId: parameters.applicationId,
5578
+ nAuditSlots: parameters.nAuditSlots,
5914
5579
  ...auditPublicKey ? { auditPublicKey } : {}
5915
5580
  });
5916
5581
  }
5917
5582
  async function proveTransaction(parameters) {
5918
5583
  return parameters.sdk.proveTransaction(
5919
5584
  parameters.publicInput,
5920
- buildZeroPublicLegs(),
5921
- [parameters.withdrawObject, "dummy"],
5922
- parameters.deposits,
5585
+ padPublicLegsToLayout(parameters.sdk, buildZeroPublicLegs()),
5586
+ padWithdrawSlotsToLayout(parameters.sdk, [parameters.withdrawObject]),
5587
+ padDepositSlotsToLayout(parameters.sdk, parameters.deposits),
5923
5588
  parameters.audit
5924
5589
  );
5925
5590
  }
5591
+ function confidentialEscrowFields2(input) {
5592
+ return {
5593
+ ...input.escrowSend ? { escrowSend: input.escrowSend } : {},
5594
+ ...input.escrowClaimantLimbs ? { escrowClaimantLimbs: input.escrowClaimantLimbs } : {}
5595
+ };
5596
+ }
5926
5597
  async function buildTransferProofInputs(parameters) {
5927
5598
  const changeStroops = validateSingleCoinTransferAmounts(
5928
5599
  parameters.input.transferStroops,
5929
5600
  parameters.noteStroops,
5930
5601
  parameters.input.selfPrivateAddressStpl1ForChange
5931
5602
  );
5603
+ const privKeyScalar = privKeyScalarDecimalFromRecipientScalarHex(
5604
+ parameters.input.senderPrivKeyScalarHex
5605
+ );
5932
5606
  const { witness, withdrawObject } = withdrawWitnessForCoin({
5933
5607
  sdk: parameters.sdk,
5934
5608
  coin: parameters.input.coin,
5935
5609
  state: parameters.input.state,
5936
- ...parseEphemeralKeyString(parameters.input.depositorEphemeralKey),
5610
+ ownerPubHex: parameters.sdk.ecdhEphemeralPublicKeyFromScalarHex(
5611
+ parameters.input.senderPrivKeyScalarHex
5612
+ ),
5613
+ privKeyScalar,
5937
5614
  applicationId: parameters.applicationId
5938
5615
  });
5616
+ const stampedWithdraw = stampWithdrawEscrowLimbs(
5617
+ withdrawObject,
5618
+ sweepWithdrawStamp(confidentialEscrowFields2(parameters.input))
5619
+ );
5939
5620
  const { recipientSlot, deposits, changeCoin, publicInput } = await buildSenderTransferDepositsAndPublicInput({
5940
- senderGAddress: parameters.input.senderGAddress,
5941
5621
  senderPrivKeyScalarHex: parameters.input.senderPrivKeyScalarHex,
5942
5622
  recipientPrivateAddressStpl1: parameters.input.recipientPrivateAddressStpl1,
5943
5623
  transferStroops: parameters.input.transferStroops,
5944
5624
  changeStroops,
5945
5625
  selfPrivateAddressStpl1ForChange: parameters.input.selfPrivateAddressStpl1ForChange,
5946
5626
  tokenAddress: parameters.input.tokenAddress,
5947
- stateRoot: witness.stateRoot
5627
+ stateRoot: witness.stateRoot,
5628
+ ...confidentialEscrowFields2(parameters.input)
5948
5629
  });
5949
5630
  return {
5950
5631
  witness,
5951
- withdrawObject,
5632
+ withdrawObject: stampedWithdraw,
5952
5633
  recipientSlot,
5953
5634
  deposits,
5954
5635
  changeCoin,
@@ -5966,7 +5647,11 @@ async function prepareConfidentialTransferProof(parameters) {
5966
5647
  input: parameters,
5967
5648
  noteStroops
5968
5649
  });
5969
- const audit = buildTransferAuditParameters({ poolService, applicationId });
5650
+ const audit = buildTransferAuditParameters({
5651
+ poolService,
5652
+ applicationId,
5653
+ nAuditSlots: sdk.getLayout().nAuditSlots
5654
+ });
5970
5655
  const proof = await proveTransaction({
5971
5656
  sdk,
5972
5657
  publicInput,
@@ -5977,6 +5662,7 @@ async function prepareConfidentialTransferProof(parameters) {
5977
5662
  return {
5978
5663
  ...proof,
5979
5664
  applicationIdsPlaintext: buildSingleTransferApplicationIds(
5665
+ sdk,
5980
5666
  applicationId,
5981
5667
  changeCoin
5982
5668
  ),
@@ -5985,95 +5671,26 @@ async function prepareConfidentialTransferProof(parameters) {
5985
5671
  };
5986
5672
  }
5987
5673
 
5988
- // src/transact/engine/prepare/transfer-helpers.ts
5989
- function isPublicRecipientTransfer(prepared) {
5990
- return prepared.kind === "transfer" && prepared.intent.disclosure.recipientAddress === "public";
5991
- }
5992
- async function resolveTransferRecipientForExecute(prepared, environment, walletPublicKey) {
5993
- if (!isPublicRecipientTransfer(prepared)) {
5994
- return {
5995
- recipientPrivateAddressStpl1: prepared.intent.to.trim()
5996
- };
5997
- }
5998
- if (!environment.resolveTransferRecipientAtExecute) {
5999
- throw new Error("Transfer recipient resolver is not configured.");
6000
- }
6001
- return environment.resolveTransferRecipientAtExecute({
6002
- recipientStellarAddress: prepared.intent.to.trim(),
6003
- walletPublicKey
6004
- });
6005
- }
6006
- async function resolveTransferOnboardingAtExecute(input) {
6007
- if (input.prepared.transactArtifacts?.onboarding) {
6008
- return input.prepared.transactArtifacts.onboarding;
6009
- }
6010
- if (!input.recipient.temporaryRecipientKey || !input.environment.buildTransferOnboardingAtExecute) {
6011
- return;
6012
- }
6013
- return input.environment.buildTransferOnboardingAtExecute({
6014
- ownerStellarAddress: input.recipient.recipientStellarAddress ?? input.prepared.intent.to.trim(),
6015
- temporaryRecipientKey: input.recipient.temporaryRecipientKey,
6016
- recipientNote: {
6017
- tokenAddress: input.tokenAddress,
6018
- nullifier: input.recipientCoin.nullifier,
6019
- secret: input.recipientCoin.secret,
6020
- value: input.recipientCoin.value
6021
- }
6022
- });
6023
- }
6024
-
6025
- // src/transact/onboarding/build-pending-claim-payload.ts
6026
- import { Buffer as Buffer15 } from "buffer";
6027
- var FIELD_HEX_LENGTH2 = 64;
6028
- function hexToBuffer2(hex) {
6029
- const clean = hex.trim().replace(/^0x/u, "");
6030
- return Buffer15.from(clean.padStart(FIELD_HEX_LENGTH2, "0"), "hex");
6031
- }
6032
- function buildPendingClaimOnboardingPayload(input) {
6033
- const ownerAddress = input.claim.owner.trim();
6034
- const permanentPrivateAddress = input.permanentPrivateAddressStpl1.trim();
6035
- const decoded = decodePrivateAddress(permanentPrivateAddress);
6036
- const encryptedRecovery = input.claim.encryptedRecoveryBase64?.trim();
6037
- if (!encryptedRecovery) {
6038
- throw new Error("Pending claim is missing encrypted recovery data.");
6039
- }
6040
- return {
6041
- owner: ownerAddress,
6042
- temp_public_key_x: hexToBuffer2(input.claim.tempPublicKeyXHex ?? ""),
6043
- temp_public_key_y: hexToBuffer2(input.claim.tempPublicKeyYHex ?? ""),
6044
- encrypted_private_key: Buffer15.from(encryptedRecovery, "base64"),
6045
- notes: { notes: [] },
6046
- private_address_registration: {
6047
- tag: "Some",
6048
- values: [
6049
- {
6050
- owner: ownerAddress,
6051
- public_key_x: hexToBuffer2(decoded.x),
6052
- public_key_y: hexToBuffer2(decoded.y)
6053
- }
6054
- ]
6055
- }
6056
- };
6057
- }
6058
-
6059
5674
  // src/transact/engine/transfer-proof-at-execute.ts
6060
5675
  function readChangeRecipient(input, changeStroops) {
6061
5676
  if (changeStroops <= 0n || input.prepared.kind !== "transfer") {
6062
5677
  return void 0;
6063
5678
  }
6064
5679
  const from = input.prepared.intent.from;
6065
- if (isPendingClaimSource(from)) {
6066
- return void 0;
6067
- }
6068
5680
  return readTransferFromPrivateAddress(from);
6069
5681
  }
5682
+ function proofEscrowFields(input) {
5683
+ return {
5684
+ ...input.escrowSend ? { escrowSend: input.escrowSend } : {},
5685
+ ...input.escrowClaimantLimbs ? { escrowClaimantLimbs: input.escrowClaimantLimbs } : {}
5686
+ };
5687
+ }
6070
5688
  async function buildSingleTransferProofAtExecute(input) {
6071
5689
  const context = await buildSpendProofContextAtExecute(input);
6072
- const changeStroops = context.pendingClaim ? 0n : BigInt(context.coin.value) - input.prepared.intent.amount;
5690
+ const changeStroops = BigInt(context.coin.value) - input.prepared.intent.amount;
6073
5691
  const proof = await prepareConfidentialTransferProof({
6074
5692
  coin: context.coin,
6075
5693
  state: { commitments: context.commitments },
6076
- senderGAddress: context.walletPublicKey,
6077
5694
  senderPrivKeyScalarHex: context.senderPrivKeyScalarHex,
6078
5695
  depositorEphemeralKey: serializeEphemeralKeyString({
6079
5696
  xHex: context.ephemeral.xHex,
@@ -6082,7 +5699,8 @@ async function buildSingleTransferProofAtExecute(input) {
6082
5699
  transferStroops: input.prepared.intent.amount,
6083
5700
  recipientPrivateAddressStpl1: context.recipientPrivateAddressStpl1,
6084
5701
  selfPrivateAddressStpl1ForChange: readChangeRecipient(input, changeStroops),
6085
- tokenAddress: context.tokenAddress
5702
+ tokenAddress: context.tokenAddress,
5703
+ ...proofEscrowFields(input)
6086
5704
  });
6087
5705
  return { context, proof };
6088
5706
  }
@@ -6104,7 +5722,6 @@ async function buildDualTransferProofAtExecute(input) {
6104
5722
  coinA: context.coin,
6105
5723
  coinB: secondary.coin,
6106
5724
  state: { commitments: context.commitments },
6107
- senderGAddress: context.walletPublicKey,
6108
5725
  senderPrivKeyScalarHex: context.senderPrivKeyScalarHex,
6109
5726
  ephemeralAKey: serializeEphemeralKeyString({
6110
5727
  xHex: context.ephemeral.xHex,
@@ -6117,7 +5734,8 @@ async function buildDualTransferProofAtExecute(input) {
6117
5734
  transferStroops: input.prepared.intent.amount,
6118
5735
  recipientPrivateAddressStpl1: context.recipientPrivateAddressStpl1,
6119
5736
  selfPrivateAddressStpl1ForChange: readChangeRecipient(input, changeStroops),
6120
- tokenAddress: context.tokenAddress
5737
+ tokenAddress: context.tokenAddress,
5738
+ ...proofEscrowFields(input)
6121
5739
  });
6122
5740
  return { context, proof };
6123
5741
  }
@@ -6133,6 +5751,41 @@ async function buildTransferProofAtExecute(input) {
6133
5751
  }
6134
5752
 
6135
5753
  // src/transact/engine/transfer-finalize.ts
5754
+ function stampEscrowOutputRecords(input) {
5755
+ if (input.escrowSendPrivateAddress) {
5756
+ const [recipientRecord, ...rest] = input.prepared.outputRecords;
5757
+ if (recipientRecord) {
5758
+ input.prepared.outputRecords = [
5759
+ {
5760
+ ...recipientRecord,
5761
+ privateAddress: input.escrowSendPrivateAddress
5762
+ },
5763
+ ...rest
5764
+ ];
5765
+ }
5766
+ }
5767
+ seedEscrowSweepOutputsFromProof({
5768
+ prepared: input.prepared,
5769
+ proof: input.proof,
5770
+ walletPublicKey: input.walletPublicKey
5771
+ });
5772
+ enrichTransferOutputRecords(input.prepared, input.proof);
5773
+ }
5774
+ function seedEscrowSweepOutputsFromProof(input) {
5775
+ if (input.prepared.transactArtifacts?.spendSource !== "escrow" || input.prepared.outputRecords.length > 0) {
5776
+ return;
5777
+ }
5778
+ input.prepared.outputRecords = [
5779
+ {
5780
+ id: input.proof.recipientCoin.commitment_hex,
5781
+ owner: input.walletPublicKey,
5782
+ privateAddress: input.prepared.intent.to,
5783
+ asset: input.prepared.intent.asset,
5784
+ amount: input.prepared.intent.amount,
5785
+ consumed: false
5786
+ }
5787
+ ];
5788
+ }
6136
5789
  function enrichTransferOutputRecords(prepared, proof) {
6137
5790
  if (prepared.outputRecords.length === 0) {
6138
5791
  return;
@@ -6156,65 +5809,34 @@ function enrichTransferOutputRecords(prepared, proof) {
6156
5809
  };
6157
5810
  });
6158
5811
  }
6159
- async function resolvePendingClaimOnboardingAtExecute(input) {
6160
- const claim = input.prepared.transactArtifacts?.pendingClaim;
6161
- if (!claim || input.prepared.kind !== "transfer") {
6162
- return;
6163
- }
6164
- const contractContext = requireContractContext(input.environment);
6165
- const lookup = await readRegistryLookupFromChain({
6166
- contractContext,
6167
- owner: input.walletPublicKey.trim(),
6168
- walletPublicKey: input.walletPublicKey.trim()
6169
- });
6170
- if (lookup.status === "registered") {
6171
- return;
6172
- }
6173
- return buildPendingClaimOnboardingPayload({
6174
- claim,
6175
- permanentPrivateAddressStpl1: input.prepared.intent.to.trim()
6176
- });
6177
- }
6178
- async function ensurePendingClaimReadyForExecute(input) {
6179
- const pendingClaim = input.prepared.transactArtifacts?.pendingClaim;
6180
- if (!pendingClaim) {
6181
- return;
5812
+ function escrowSpendArtifacts(input) {
5813
+ if (input.escrowSend) {
5814
+ return {
5815
+ escrowSend: true,
5816
+ spendSource: "escrow",
5817
+ ...input.escrowRecipient ? { escrowRecipient: input.escrowRecipient } : {}
5818
+ };
6182
5819
  }
6183
- await verifyPendingClaimBeforeExecute({
6184
- claim: pendingClaim,
6185
- environment: input.environment,
6186
- walletPublicKey: input.walletPublicKey
6187
- });
6188
- }
6189
- async function resolveTransferOnboardingBundle(input) {
6190
- const pendingClaim = input.prepared.transactArtifacts?.pendingClaim;
6191
- if (pendingClaim) {
6192
- const pendingOnboarding = await resolvePendingClaimOnboardingAtExecute({
6193
- prepared: input.prepared,
6194
- environment: input.environment,
6195
- walletPublicKey: input.walletPublicKey
6196
- });
6197
- if (pendingOnboarding) {
6198
- return pendingOnboarding;
6199
- }
5820
+ if (input.preparedSpendSource === "escrow") {
5821
+ return {
5822
+ spendSource: "escrow",
5823
+ ...input.escrowRecipient ? { escrowRecipient: input.escrowRecipient } : {},
5824
+ ...input.escrowSpendScalarHex ? { escrowSpendScalarHex: input.escrowSpendScalarHex } : {},
5825
+ ...input.escrowClaimantLimbs ? { escrowClaimantLimbs: input.escrowClaimantLimbs } : {}
5826
+ };
6200
5827
  }
6201
- return resolveTransferOnboardingAtExecute({
6202
- prepared: input.prepared,
6203
- environment: input.environment,
6204
- recipient: input.recipient,
6205
- recipientCoin: input.recipientCoin,
6206
- tokenAddress: input.tokenAddress
6207
- });
5828
+ return {};
6208
5829
  }
6209
5830
  function buildTransferFinalizeArtifacts(input) {
6210
5831
  return {
6211
5832
  proofHex: input.proof.proof_hex,
6212
5833
  publicHex: input.proof.public_hex,
5834
+ ...ciphertextArtifactsFromProof(input.proof),
6213
5835
  applicationIdsPlaintext: input.proof.applicationIdsPlaintext,
6214
5836
  tokenAddress: input.context.tokenAddress,
6215
5837
  walletPublicKey: input.context.walletPublicKey,
6216
- onboarding: input.onboarding,
6217
- executeFinalizeRequired: false
5838
+ executeFinalizeRequired: false,
5839
+ ...escrowSpendArtifacts(input)
6218
5840
  };
6219
5841
  }
6220
5842
  async function runTransferFinalizeSteps(input) {
@@ -6223,26 +5845,50 @@ async function runTransferFinalizeSteps(input) {
6223
5845
  input.environment,
6224
5846
  input.walletPublicKey
6225
5847
  );
5848
+ const spendScalarHex = nullifierCheckSpendScalarHex(input.prepared.transactArtifacts);
6226
5849
  await verifyPrivateRecordsNullifiersBeforeExecute({
6227
5850
  records: input.prepared.consumedRecords,
6228
5851
  environment: input.environment,
6229
- walletPublicKey: input.walletPublicKey
5852
+ walletPublicKey: input.walletPublicKey,
5853
+ ...spendScalarHex ? { spendScalarHex } : {}
6230
5854
  });
6231
5855
  const { context, proof } = await buildTransferProofAtExecute({
6232
5856
  prepared: input.prepared,
6233
5857
  environment: input.environment,
6234
- recipientPrivateAddressStpl1: recipient.recipientPrivateAddressStpl1
5858
+ recipientPrivateAddressStpl1: recipient.recipientPrivateAddressStpl1,
5859
+ ...recipient.escrowSend ? { escrowSend: recipient.escrowSend } : {},
5860
+ ...input.prepared.transactArtifacts?.escrowClaimantLimbs ? {
5861
+ escrowClaimantLimbs: input.prepared.transactArtifacts.escrowClaimantLimbs
5862
+ } : {}
6235
5863
  });
6236
- const onboarding = await resolveTransferOnboardingBundle({
5864
+ stampEscrowOutputRecords({
6237
5865
  prepared: input.prepared,
6238
- environment: input.environment,
5866
+ proof,
6239
5867
  walletPublicKey: input.walletPublicKey,
6240
- recipient,
6241
- recipientCoin: proof.recipientCoin.coin,
6242
- tokenAddress: context.tokenAddress
5868
+ ...recipient.escrowSend ? { escrowSendPrivateAddress: recipient.recipientPrivateAddressStpl1 } : {}
6243
5869
  });
6244
- enrichTransferOutputRecords(input.prepared, proof);
6245
- return buildTransferFinalizeArtifacts({ proof, context, onboarding });
5870
+ return buildTransferFinalizeArtifacts({
5871
+ proof,
5872
+ context,
5873
+ ...sweepFinalizeStamp(input.prepared, recipient)
5874
+ });
5875
+ }
5876
+ function sweepArtifactStamp(artifacts) {
5877
+ return {
5878
+ ...artifacts?.escrowSpendScalarHex ? { escrowSpendScalarHex: artifacts.escrowSpendScalarHex } : {},
5879
+ ...artifacts?.spendSource ? { preparedSpendSource: artifacts.spendSource } : {},
5880
+ ...artifacts?.escrowClaimantLimbs ? { escrowClaimantLimbs: artifacts.escrowClaimantLimbs } : {}
5881
+ };
5882
+ }
5883
+ function sweepFinalizeStamp(prepared, recipient) {
5884
+ const artifacts = prepared.transactArtifacts;
5885
+ const fromSend = recipient.escrowSend?.recipientStellarAddress?.trim();
5886
+ const escrowRecipient = fromSend || artifacts?.escrowRecipient?.trim();
5887
+ return {
5888
+ ...recipient.escrowSend ? { escrowSend: true } : {},
5889
+ ...escrowRecipient ? { escrowRecipient } : {},
5890
+ ...sweepArtifactStamp(artifacts)
5891
+ };
6246
5892
  }
6247
5893
  async function finalizeTransferAtExecute(prepared, environment) {
6248
5894
  const [primaryRecord] = prepared.consumedRecords;
@@ -6250,11 +5896,6 @@ async function finalizeTransferAtExecute(prepared, environment) {
6250
5896
  throw new Error("Transfer execution record owner is missing.");
6251
5897
  }
6252
5898
  const walletPublicKey = primaryRecord.owner.trim();
6253
- await ensurePendingClaimReadyForExecute({
6254
- prepared,
6255
- environment,
6256
- walletPublicKey
6257
- });
6258
5899
  return runTransferFinalizeSteps({ prepared, environment, walletPublicKey });
6259
5900
  }
6260
5901
 
@@ -6277,6 +5918,7 @@ function buildWithdrawFinalizeArtifacts(proof, context) {
6277
5918
  return {
6278
5919
  proofHex: proof.proof_hex,
6279
5920
  publicHex: proof.public_hex,
5921
+ ...ciphertextArtifactsFromProof(proof),
6280
5922
  applicationIdsPlaintext: proof.applicationIdsPlaintext,
6281
5923
  tokenAddress: context.tokenAddress,
6282
5924
  walletPublicKey: context.walletPublicKey,
@@ -6387,6 +6029,12 @@ async function finalizeSpendOperationAtExecute(prepared, environment, poolServic
6387
6029
  };
6388
6030
  }
6389
6031
 
6032
+ // src/transact/kyt/passage/inspect.ts
6033
+ import {
6034
+ layoutForKnownNonce,
6035
+ zeroBindingTagsInPublicSignals
6036
+ } from "@arcanetech/stellar-privacy-pool-zk-sdk";
6037
+
6390
6038
  // src/transact/kyt/inspect-error.ts
6391
6039
  var KytInspectError = class extends Error {
6392
6040
  reasonCode;
@@ -6469,16 +6117,16 @@ async function waitForKytRegistration(parameters) {
6469
6117
  }
6470
6118
 
6471
6119
  // src/transact/kyt/passage/submit.ts
6472
- import { Buffer as Buffer16 } from "buffer";
6120
+ import { Buffer as Buffer14 } from "buffer";
6473
6121
  import { Operation, TransactionBuilder, rpc as rpc3, xdr as xdr2 } from "@stellar/stellar-sdk";
6474
6122
  var KYT_REGISTER_FEE_STROOPS = "1000000";
6475
6123
  var KYT_REGISTER_TIMEOUT_SECONDS = 300;
6476
6124
  function passageIdToScValue(passageId) {
6477
- return xdr2.ScVal.scvBytes(Buffer16.from(passageId.replace(/^0x/, ""), "hex"));
6125
+ return xdr2.ScVal.scvBytes(Buffer14.from(passageId.replace(/^0x/, ""), "hex"));
6478
6126
  }
6479
6127
  function approvalSignatureToBytes(signature) {
6480
6128
  const clean = signature.trim();
6481
- return /^(0x)?[0-9a-fA-F]{128}$/.test(clean) ? Buffer16.from(clean.replace(/^0x/i, ""), "hex") : Buffer16.from(clean, "base64");
6129
+ return /^(0x)?[0-9a-fA-F]{128}$/.test(clean) ? Buffer14.from(clean.replace(/^0x/i, ""), "hex") : Buffer14.from(clean, "base64");
6482
6130
  }
6483
6131
  function signatureToScValue(signature) {
6484
6132
  const bytes = approvalSignatureToBytes(signature);
@@ -6526,15 +6174,9 @@ async function registerKytPassage(parameters) {
6526
6174
  await waitForKytRegistration({ server, hash: result.hash });
6527
6175
  }
6528
6176
 
6529
- // src/transact/environment/zk-config-nonce.ts
6530
- var DEFAULT_ZK_CONFIG_NONCE = 0n;
6531
- function resolveZkConfigNonce(transactEnvironment) {
6532
- return transactEnvironment.zkConfigNonce ?? DEFAULT_ZK_CONFIG_NONCE;
6533
- }
6534
-
6535
6177
  // src/transact/kyt/passage/inspect.ts
6536
- function buildApplicationIdHints(applicationId) {
6537
- return [applicationId, applicationId, applicationId, applicationId];
6178
+ function buildApplicationIdHints2(applicationId, nAuditSlots) {
6179
+ return uniformApplicationIdHints(applicationId, nAuditSlots);
6538
6180
  }
6539
6181
  function buildNonce() {
6540
6182
  return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}`;
@@ -6562,37 +6204,61 @@ function throwKytInspectRejected(body) {
6562
6204
  ...parsed.address ? { detailAddress: parsed.address } : {}
6563
6205
  });
6564
6206
  }
6565
- async function requestKytPassageForPoolInteraction(input) {
6566
- const applicationId = resolvePoolApplicationId(
6567
- input.transactEnvironment.network.applicationId
6568
- );
6569
- const applicationIdsPlaintext = input.applicationIdsPlaintext ?? buildApplicationIdHints(applicationId);
6570
- const kytRegistry = input.transactEnvironment.kyt.kytPassageRegistryContract;
6571
- const currentLedger = await fetchCurrentLedger(input.sorobanRpcUrl);
6207
+ function inspectRequestHeaders(inspectAuthorization) {
6208
+ const token = inspectAuthorization?.trim();
6209
+ return {
6210
+ "content-type": "application/json",
6211
+ ...token ? { authorization: `Bearer ${token}` } : {}
6212
+ };
6213
+ }
6214
+ async function postKytInspect(input, applicationIdsPlaintext, zkConfigNonce, currentLedger) {
6572
6215
  const response = await fetch(
6573
6216
  `${input.transactEnvironment.kyt.apiBaseUrl}/kyt/passages/inspect`,
6574
6217
  {
6575
6218
  method: "POST",
6576
- headers: { "content-type": "application/json" },
6219
+ headers: inspectRequestHeaders(
6220
+ input.transactEnvironment.kyt.inspectAuthorization
6221
+ ),
6577
6222
  body: JSON.stringify(
6578
6223
  {
6579
6224
  owner: input.owner,
6580
6225
  poolContract: input.poolContract,
6581
- kytRegistry,
6226
+ kytRegistry: input.transactEnvironment.kyt.kytPassageRegistryContract,
6582
6227
  proofBytes: input.proofHex,
6583
- publicSignalsBytes: input.publicHex,
6228
+ publicSignalsBytes: zeroBindingTagsInPublicSignals(
6229
+ input.publicHex,
6230
+ zkConfigNonce
6231
+ ).toString("hex"),
6584
6232
  applicationIdsPlaintext,
6585
6233
  decryptedAuditSlots: input.decryptedAuditSlots,
6586
- onboarding: input.onboarding,
6587
6234
  nonce: buildNonce(),
6588
- zkConfigNonce: resolveZkConfigNonce(input.transactEnvironment),
6589
- currentLedger
6235
+ zkConfigNonce,
6236
+ currentLedger,
6237
+ ...input.ciphertextHex ? { ciphertextBytes: input.ciphertextHex } : {},
6238
+ ...input.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: input.outputNoteEphemeralScalars } : {}
6590
6239
  },
6591
6240
  kytJsonReplacer
6592
6241
  )
6593
6242
  }
6594
6243
  );
6595
- const body = await parseInspectResponse(response);
6244
+ return parseInspectResponse(response);
6245
+ }
6246
+ async function requestKytPassageForPoolInteraction(input) {
6247
+ const applicationId = resolvePoolApplicationId(
6248
+ input.transactEnvironment.network.applicationId
6249
+ );
6250
+ const zkConfigNonce = resolveZkConfigNonce(input.transactEnvironment);
6251
+ const applicationIdsPlaintext = input.applicationIdsPlaintext ?? buildApplicationIdHints2(
6252
+ applicationId,
6253
+ layoutForKnownNonce(zkConfigNonce).nAuditSlots
6254
+ );
6255
+ const currentLedger = await fetchCurrentLedger(input.sorobanRpcUrl);
6256
+ const body = await postKytInspect(
6257
+ input,
6258
+ applicationIdsPlaintext,
6259
+ zkConfigNonce,
6260
+ currentLedger
6261
+ );
6596
6262
  if (body.status !== "approved") {
6597
6263
  throwKytInspectRejected(body);
6598
6264
  }
@@ -6712,7 +6378,7 @@ async function extendZkConfigTtlIfNeeded(parameters) {
6712
6378
  }
6713
6379
 
6714
6380
  // src/transact/submit/pool-transact.ts
6715
- import { Buffer as Buffer17 } from "buffer";
6381
+ import { Buffer as Buffer15 } from "buffer";
6716
6382
  async function submitPoolTransact(parameters) {
6717
6383
  await extendZkConfigTtlIfNeeded({
6718
6384
  sorobanRpcUrl: parameters.sorobanRpcUrl,
@@ -6725,9 +6391,12 @@ async function submitPoolTransact(parameters) {
6725
6391
  const assembledTransaction = await parameters.contractClient.transact({
6726
6392
  from: parameters.from,
6727
6393
  nonce: parameters.nonce,
6728
- proof_bytes: Buffer17.from(parameters.proofHex.replace(/^0x/iu, ""), "hex"),
6729
- pub_signals_bytes: Buffer17.from(parameters.publicHex.replace(/^0x/iu, ""), "hex"),
6730
- onboarding: parameters.onboarding,
6394
+ proof_bytes: Buffer15.from(parameters.proofHex.replace(/^0x/iu, ""), "hex"),
6395
+ pub_signals_bytes: Buffer15.from(parameters.publicHex.replace(/^0x/iu, ""), "hex"),
6396
+ ciphertext_bytes: Buffer15.from(
6397
+ (parameters.ciphertextHex ?? "").replace(/^0x/iu, ""),
6398
+ "hex"
6399
+ ),
6731
6400
  kyt_authorization: {
6732
6401
  expiration_ledger: parameters.approval.expiresAtLedger,
6733
6402
  signature: approvalSignatureToBytes(parameters.approval.signature)
@@ -6755,7 +6424,8 @@ async function submitSorobanConfidentialTransfer(input) {
6755
6424
  poolContract: input.contractId,
6756
6425
  proofHex: input.proofHex,
6757
6426
  publicHex: input.publicHex,
6758
- ...input.onboarding ? { onboarding: input.onboarding } : {},
6427
+ ...input.ciphertextHex ? { ciphertextHex: input.ciphertextHex } : {},
6428
+ ...input.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: input.outputNoteEphemeralScalars } : {},
6759
6429
  ...input.applicationIdsPlaintext ? { applicationIdsPlaintext: input.applicationIdsPlaintext } : {},
6760
6430
  networkPassphrase: input.networkPassphrase,
6761
6431
  sorobanRpcUrl: input.sorobanRpcUrl,
@@ -6768,7 +6438,7 @@ async function submitSorobanConfidentialTransfer(input) {
6768
6438
  nonce: resolveZkConfigNonce(input.transactEnvironment),
6769
6439
  proofHex: input.proofHex,
6770
6440
  publicHex: input.publicHex,
6771
- ...input.onboarding ? { onboarding: input.onboarding } : {},
6441
+ ...input.ciphertextHex ? { ciphertextHex: input.ciphertextHex } : {},
6772
6442
  approval,
6773
6443
  networkPassphrase: input.networkPassphrase,
6774
6444
  sorobanRpcUrl: input.sorobanRpcUrl,
@@ -6777,6 +6447,13 @@ async function submitSorobanConfidentialTransfer(input) {
6777
6447
  }
6778
6448
 
6779
6449
  // src/transact/engine/submit.ts
6450
+ function optionalInspectCiphertext(artifacts) {
6451
+ return {
6452
+ ...artifacts.ciphertextHex ? { ciphertextHex: artifacts.ciphertextHex } : {},
6453
+ ...artifacts.outputNoteEphemeralScalars ? { outputNoteEphemeralScalars: artifacts.outputNoteEphemeralScalars } : {},
6454
+ ...artifacts.applicationIdsPlaintext ? { applicationIdsPlaintext: artifacts.applicationIdsPlaintext } : {}
6455
+ };
6456
+ }
6780
6457
  async function submitPreparedDeposit(prepared, environment) {
6781
6458
  const artifacts = prepared.transactArtifacts;
6782
6459
  const outputRecord = prepared.outputRecords[0];
@@ -6794,7 +6471,7 @@ async function submitPreparedDeposit(prepared, environment) {
6794
6471
  poolContract: environment.network.poolContract,
6795
6472
  proofHex: artifacts.proofHex,
6796
6473
  publicHex: artifacts.publicHex,
6797
- ...artifacts.applicationIdsPlaintext ? { applicationIdsPlaintext: artifacts.applicationIdsPlaintext } : {},
6474
+ ...optionalInspectCiphertext(artifacts),
6798
6475
  networkPassphrase: environment.network.networkPassphrase,
6799
6476
  sorobanRpcUrl: environment.network.rpcUrl,
6800
6477
  transactEnvironment: environment
@@ -6806,6 +6483,7 @@ async function submitPreparedDeposit(prepared, environment) {
6806
6483
  nonce: resolveZkConfigNonce(environment),
6807
6484
  proofHex: artifacts.proofHex,
6808
6485
  publicHex: artifacts.publicHex,
6486
+ ...artifacts.ciphertextHex ? { ciphertextHex: artifacts.ciphertextHex } : {},
6809
6487
  approval,
6810
6488
  networkPassphrase: environment.network.networkPassphrase,
6811
6489
  sorobanRpcUrl: environment.network.rpcUrl,
@@ -6822,8 +6500,7 @@ async function submitPreparedPoolTransact(prepared, environment) {
6822
6500
  walletPublicKey: artifacts.walletPublicKey,
6823
6501
  proofHex: artifacts.proofHex,
6824
6502
  publicHex: artifacts.publicHex,
6825
- ...artifacts.onboarding ? { onboarding: artifacts.onboarding } : {},
6826
- ...artifacts.applicationIdsPlaintext ? { applicationIdsPlaintext: artifacts.applicationIdsPlaintext } : {},
6503
+ ...optionalInspectCiphertext(artifacts),
6827
6504
  networkPassphrase: environment.network.networkPassphrase,
6828
6505
  sorobanRpcUrl: environment.network.rpcUrl,
6829
6506
  transactEnvironment: environment
@@ -6861,18 +6538,33 @@ function createBrowserStellarTransactEngine(input) {
6861
6538
  }
6862
6539
 
6863
6540
  // src/transact/engine/default-factory.ts
6864
- async function createDefaultTransactEngine(assets, transactEnvironment) {
6865
- await PrivacyPoolSDK4.init({
6541
+ async function privacyPoolInitOptions(assets, transactEnvironment) {
6542
+ if (!transactEnvironment) {
6543
+ return { wasmBinary: assets.sdkWasm };
6544
+ }
6545
+ const zkConfigNonce = resolveZkConfigNonce(transactEnvironment);
6546
+ const zkCircuits = await materializeSelectedZkCircuit(
6547
+ transactEnvironment.zkCircuits,
6548
+ zkConfigNonce
6549
+ );
6550
+ return {
6866
6551
  wasmBinary: assets.sdkWasm,
6867
- circuitWasm: assets.circuitWasm,
6868
- zkey: assets.provingKey
6869
- });
6552
+ zkCircuits,
6553
+ zkConfigNonce,
6554
+ ...optionalZkArtifactBaseUrl(transactEnvironment.zkArtifactBaseUrl)
6555
+ };
6556
+ }
6557
+ async function createDefaultTransactEngine(assets, transactEnvironment) {
6558
+ await PrivacyPoolSDK3.init(await privacyPoolInitOptions(assets, transactEnvironment));
6870
6559
  if (transactEnvironment) {
6871
6560
  configurePrivacyPoolService(
6872
6561
  createPrivacyPoolService({
6873
6562
  assets,
6874
6563
  applicationId: transactEnvironment.network.applicationId,
6875
- ...transactEnvironment.auditPublicKey ? { auditPublicKey: transactEnvironment.auditPublicKey } : {}
6564
+ ...transactEnvironment.auditPublicKey ? { auditPublicKey: transactEnvironment.auditPublicKey } : {},
6565
+ ...transactEnvironment.zkCircuits ? { zkCircuits: transactEnvironment.zkCircuits } : {},
6566
+ ...transactEnvironment.zkConfigNonce === void 0 ? {} : { zkConfigNonce: transactEnvironment.zkConfigNonce },
6567
+ ...optionalZkArtifactBaseUrl(transactEnvironment.zkArtifactBaseUrl)
6876
6568
  })
6877
6569
  );
6878
6570
  return createBrowserStellarTransactEngine({
@@ -6915,7 +6607,7 @@ async function createStellarPrivacyClientFromNodeConfig(config) {
6915
6607
  return input.transactEngine;
6916
6608
  }
6917
6609
  const browserAssets = await loadNodeAssets(input.assets);
6918
- return createDefaultTransactEngine(browserAssets);
6610
+ return createDefaultTransactEngine(browserAssets, input.transactEnvironment);
6919
6611
  });
6920
6612
  if (!resolved.ok) {
6921
6613
  return resolved.result;