@arcanetech/privacy-sdk-stellar 0.2.0 → 0.2.3

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
@@ -291,11 +291,14 @@ async function commitStorageChanges(input, eventId, receipt) {
291
291
  });
292
292
  if (input.prepared.outputRecords.length > 0) {
293
293
  await input.storage.savePrivateRecords(
294
- input.prepared.outputRecords.map((record) => ({
295
- ...record,
296
- txHash: receipt.operationId,
297
- status: receipt.confirmed ? "finalized" : record.status
298
- }))
294
+ input.prepared.outputRecords.map((record) => {
295
+ const nextStatus = receipt.confirmed ? "finalized" : record.status;
296
+ return {
297
+ ...record,
298
+ txHash: receipt.operationId,
299
+ ...nextStatus === void 0 ? {} : { status: nextStatus }
300
+ };
301
+ })
299
302
  );
300
303
  }
301
304
  if (input.prepared.consumedRecords.length > 0) {
@@ -351,7 +354,10 @@ import { insufficientStateError as insufficientStateError3 } from "@arcanetech/p
351
354
 
352
355
  // src/transact/transfer-source/resolve.ts
353
356
  import { Buffer as Buffer2 } from "buffer";
354
- import { insufficientStateError, invalidIntentError } from "@arcanetech/privacy-sdk-core";
357
+ import {
358
+ insufficientStateError,
359
+ invalidIntentError
360
+ } from "@arcanetech/privacy-sdk-core";
355
361
  var FIELD_HEX_LENGTH = 64;
356
362
  var SCALAR_HEX_PATTERN = new RegExp(`^(0x)?[0-9a-f]{${FIELD_HEX_LENGTH}}$`, "iu");
357
363
  function hexToDecimal(hex) {
@@ -384,6 +390,7 @@ function pendingClaimToCoin(claim) {
384
390
  }
385
391
  function pendingClaimToConsumedRecord(input) {
386
392
  const coin = pendingClaimToCoin(input.claim);
393
+ const nullifierHex = input.claim.nullifierHex ?? input.claim.futureNullifierHashHex;
387
394
  return {
388
395
  id: `pending-claim-${input.claim.id}`,
389
396
  owner: input.walletPublicKey.trim(),
@@ -392,9 +399,9 @@ function pendingClaimToConsumedRecord(input) {
392
399
  consumed: false,
393
400
  status: "finalized",
394
401
  poolContract: input.poolContract,
395
- commitmentHex: input.claim.commitmentHex,
396
- nullifierHex: input.claim.nullifierHex ?? input.claim.futureNullifierHashHex,
397
- coinNote: coin
402
+ coinNote: coin,
403
+ ...input.claim.commitmentHex ? { commitmentHex: input.claim.commitmentHex } : {},
404
+ ...nullifierHex ? { nullifierHex } : {}
398
405
  };
399
406
  }
400
407
  function readPendingClaimFromSource(source) {
@@ -1787,7 +1794,7 @@ async function resolvePendingClaimSpend(intent, deps, walletPublicKey) {
1787
1794
  await assertPendingClaimNullifierAvailable({
1788
1795
  claim,
1789
1796
  walletPublicKey,
1790
- checkNullifierSpent: deps.checkNullifierSpent
1797
+ ...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
1791
1798
  });
1792
1799
  validatePendingClaimIntentMatches(claim, intent);
1793
1800
  return {
@@ -1813,12 +1820,12 @@ async function resolvePrivateAddressSpend(intent, deps) {
1813
1820
  kind: "transfer",
1814
1821
  intent,
1815
1822
  walletPublicKey,
1816
- checkNullifierSpent: deps.checkNullifierSpent
1823
+ ...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
1817
1824
  });
1818
1825
  await assertPrivateRecordsNullifiersAvailable({
1819
1826
  records: consumedRecords,
1820
1827
  walletPublicKey: walletAddress.trim(),
1821
- checkNullifierSpent: deps.checkNullifierSpent
1828
+ ...deps.checkNullifierSpent ? { checkNullifierSpent: deps.checkNullifierSpent } : {}
1822
1829
  });
1823
1830
  return {
1824
1831
  consumedRecords,
@@ -1900,7 +1907,7 @@ async function resolvePrepareConsumedRecords(input) {
1900
1907
  storage: input.storage,
1901
1908
  intent: input.intent,
1902
1909
  walletPublicKey: await loadSpendSelectionWalletPublicKey(input.wallet),
1903
- checkNullifierSpent: input.checkNullifierSpent
1910
+ ...input.checkNullifierSpent ? { checkNullifierSpent: input.checkNullifierSpent } : {}
1904
1911
  });
1905
1912
  }
1906
1913
  function buildDepositOrWithdrawPrepared(input) {
@@ -5470,7 +5477,8 @@ async function resolveWalletPublicKey(environment, prepared) {
5470
5477
  return environment.resolveWalletPublicKey();
5471
5478
  }
5472
5479
  if (prepared.kind === "deposit") {
5473
- return prepared.intent.from;
5480
+ const depositIntent = prepared.intent;
5481
+ return depositIntent.from;
5474
5482
  }
5475
5483
  throw new Error("Wallet public key resolver is not configured.");
5476
5484
  }
@@ -6265,10 +6273,15 @@ function enrichWithdrawOutputRecords(prepared, proof) {
6265
6273
  }));
6266
6274
  }
6267
6275
  async function finalizeWithdrawAtExecute(prepared, environment, poolService) {
6276
+ if (prepared.kind !== "withdraw") {
6277
+ throw new Error("Withdraw finalize requires a withdraw operation.");
6278
+ }
6279
+ const withdrawIntent = prepared.intent;
6280
+ const withdrawFrom = withdrawIntent.from;
6268
6281
  const context = await buildSpendProofContextAtExecute({
6269
6282
  prepared,
6270
6283
  environment,
6271
- recipientPrivateAddressStpl1: prepared.intent.from
6284
+ recipientPrivateAddressStpl1: withdrawFrom
6272
6285
  });
6273
6286
  const changeStroops = BigInt(context.coin.value) - prepared.intent.amount;
6274
6287
  const proof = await poolService.prepareWithdrawTransactProof({
@@ -6281,7 +6294,7 @@ async function finalizeWithdrawAtExecute(prepared, environment, poolService) {
6281
6294
  yHex: context.ephemeral.yHex
6282
6295
  }),
6283
6296
  withdrawAmountStroops: prepared.intent.amount,
6284
- changePrivateAddressStpl1: changeStroops > 0n ? prepared.intent.from : void 0,
6297
+ changePrivateAddressStpl1: changeStroops > 0n ? withdrawFrom : void 0,
6285
6298
  tokenAddress: context.tokenAddress
6286
6299
  });
6287
6300
  enrichWithdrawOutputRecords(prepared, proof);