@bsv/wallet-toolbox-client 2.10.0 → 2.10.2

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.
@@ -231,7 +231,7 @@ var WERR_UTXO_REVIEW_INCONCLUSIVE = class extends WalletError {
231
231
  obj.checked = this.checked;
232
232
  obj.confirmedSpent = this.confirmedSpent;
233
233
  obj.unknown = this.unknown;
234
- return JSON.stringify(obj);
234
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
235
235
  }
236
236
  };
237
237
  /**
@@ -249,7 +249,7 @@ var WERRActionBatchState = class extends WalletError {
249
249
  const obj = JSON.parse(super.toJson());
250
250
  obj.state = this.state;
251
251
  obj.batchId = this.batchId;
252
- return JSON.stringify(obj);
252
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
253
253
  }
254
254
  };
255
255
  /**
@@ -275,7 +275,7 @@ var WERR_INVALID_PARAMETER = class extends WalletError {
275
275
  const obj = JSON.parse(super.toJson());
276
276
  obj.code = 6;
277
277
  obj.parameter = this.parameter;
278
- return JSON.stringify(obj);
278
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
279
279
  }
280
280
  };
281
281
  /**
@@ -302,7 +302,7 @@ var WERR_INVALID_MERKLE_ROOT = class extends WalletError {
302
302
  obj.blockHeight = this.blockHeight;
303
303
  obj.merkleRoot = this.merkleRoot;
304
304
  obj.txid = this.txid;
305
- return JSON.stringify(obj);
305
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
306
306
  }
307
307
  };
308
308
  /**
@@ -319,7 +319,7 @@ var WERR_MISSING_PARAMETER = class extends WalletError {
319
319
  toJson() {
320
320
  const obj = JSON.parse(super.toJson());
321
321
  obj.parameter = this.parameter;
322
- return JSON.stringify(obj);
322
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
323
323
  }
324
324
  };
325
325
  /**
@@ -377,7 +377,7 @@ var WERR_INSUFFICIENT_FUNDS = class extends WalletError {
377
377
  obj.code = 7;
378
378
  obj.totalSatoshisNeeded = this.totalSatoshisNeeded;
379
379
  obj.moreSatoshisNeeded = this.moreSatoshisNeeded;
380
- return JSON.stringify(obj);
380
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
381
381
  }
382
382
  };
383
383
  var WERR_INVALID_PUBLIC_KEY = class extends WalletError {
@@ -394,7 +394,7 @@ var WERR_INVALID_PUBLIC_KEY = class extends WalletError {
394
394
  toJson() {
395
395
  const obj = JSON.parse(super.toJson());
396
396
  obj.key = this.key;
397
- return JSON.stringify(obj);
397
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
398
398
  }
399
399
  };
400
400
  /**
@@ -429,7 +429,7 @@ var WERR_REVIEW_ACTIONS = class extends WalletError {
429
429
  obj.txid = this.txid;
430
430
  obj.tx = this.tx;
431
431
  obj.noSendChange = this.noSendChange;
432
- return JSON.stringify(obj);
432
+ return (0, _bsv_sdk.stringifyBRC100)(obj);
433
433
  }
434
434
  };
435
435
  /**
@@ -7845,6 +7845,23 @@ function mergePriorOptions(caVargs, saArgs) {
7845
7845
  return _bsv_sdk.Validation.validateSignActionArgs(saArgs);
7846
7846
  }
7847
7847
  //#endregion
7848
+ //#region ../src/utility/canonicalizeAtomicBeef.ts
7849
+ /**
7850
+ * Restricts an AtomicBEEF envelope to the transaction named by its BRC-95
7851
+ * prefix and that transaction's recursive dependency closure.
7852
+ *
7853
+ * Older senders could serialize unrelated, otherwise valid BEEF branches into
7854
+ * an AtomicBEEF envelope. Those branches are not part of the payment proof and
7855
+ * must not influence internalization. Proof and transaction validation still
7856
+ * run against the returned closure at each wallet trust boundary.
7857
+ */
7858
+ function canonicalizeAtomicBeef(bytes) {
7859
+ const received = bytes instanceof Uint8Array ? _bsv_sdk.Beef.fromBinaryView(bytes) : _bsv_sdk.Beef.fromBinary(bytes);
7860
+ const txid = received.atomicTxid;
7861
+ if (txid == null || received.findTxid(txid) == null || received.isAtomic(txid)) return received;
7862
+ return _bsv_sdk.Beef.fromBinary(received.toBinaryAtomic(txid));
7863
+ }
7864
+ //#endregion
7848
7865
  //#region ../src/signer/methods/internalizeAction.ts
7849
7866
  /**
7850
7867
  * Internalize Action allows a wallet to take ownership of outputs in a pre-existing transaction.
@@ -7886,7 +7903,7 @@ function mergePriorOptions(caVargs, saArgs) {
7886
7903
  */
7887
7904
  async function internalizeAction$1(wallet, auth, args) {
7888
7905
  const vargs = _bsv_sdk.Validation.validateInternalizeActionArgs(args);
7889
- const { tx } = await validateAtomicBeef();
7906
+ const { ab, tx, txid } = await validateAtomicBeef();
7890
7907
  const brc29ProtocolID = [2, "3241645161d8"];
7891
7908
  for (const o of vargs.outputs) {
7892
7909
  if (o.outputIndex < 0 || o.outputIndex >= tx.outputs.length) throw new WERR_INVALID_PARAMETER("outputIndex", `a valid output index in range 0 to ${tx.outputs.length - 1}`);
@@ -7900,7 +7917,10 @@ async function internalizeAction$1(wallet, auth, args) {
7900
7917
  default: throw new WERR_INTERNAL(`unexpected protocol ${o.protocol}`);
7901
7918
  }
7902
7919
  }
7903
- return await wallet.storage.internalizeAction(args);
7920
+ return await wallet.storage.internalizeAction({
7921
+ ...args,
7922
+ tx: ab.toBinaryAtomic(txid)
7923
+ });
7904
7924
  function setupWalletPaymentForOutput(o, _dargs) {
7905
7925
  const p = o.paymentRemittance;
7906
7926
  const output = tx.outputs[o.outputIndex];
@@ -7923,7 +7943,7 @@ async function internalizeAction$1(wallet, auth, args) {
7923
7943
  * 2. That the proofs are for the same block as recorded in the wallet's configured storage in the event of a reorg.
7924
7944
  */
7925
7945
  async function validateAtomicBeef() {
7926
- const ab = _bsv_sdk.Beef.fromBinary(vargs.tx);
7946
+ const ab = canonicalizeAtomicBeef(vargs.tx);
7927
7947
  if (!await ab.verify(await wallet.getServices().getChainTracker(), false) || !ab.atomicTxid) {
7928
7948
  console.log(`internalizeAction beef is invalid: ${ab.toLogString()}`);
7929
7949
  throw new WERR_INVALID_PARAMETER("tx", "valid AtomicBEEF");
@@ -12456,7 +12476,7 @@ var InternalizeActionContext = class {
12456
12476
  * @returns
12457
12477
  */
12458
12478
  async validateAtomicBeef(atomicBeef) {
12459
- const ab = atomicBeef instanceof Uint8Array ? _bsv_sdk.Beef.fromBinaryView(atomicBeef) : _bsv_sdk.Beef.fromBinary(atomicBeef);
12479
+ const ab = canonicalizeAtomicBeef(atomicBeef);
12460
12480
  if (!await ab.verify(await this.storage.getServices().getChainTracker(), false) || !ab.atomicTxid) throw new WERR_INVALID_PARAMETER("tx", "valid AtomicBEEF");
12461
12481
  const txid = ab.atomicTxid;
12462
12482
  const btx = ab.findTxid(txid);
@@ -33209,7 +33229,7 @@ var WABTransport = class {
33209
33229
  bodyFor(options, metadata) {
33210
33230
  let body;
33211
33231
  try {
33212
- body = options.body === void 0 ? void 0 : JSON.stringify(options.body);
33232
+ body = options.body === void 0 ? void 0 : (0, _bsv_sdk.stringifyBRC100)(options.body);
33213
33233
  } catch (cause) {
33214
33234
  const error = new WABClientError("WAB_INVALID_REQUEST", "WAB request encoding failed.", false, void 0, {
33215
33235
  ...metadata.errorContext,