@bsv/wallet-toolbox-client 2.6.0 → 2.6.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.
@@ -7296,7 +7296,7 @@ async function createActionCore$1(wallet, auth, vargs, parent) {
7296
7296
  r.noSendChange = prior.dcr.noSendChangeOutputVouts?.map((vout) => `${r.txid}.${vout}`);
7297
7297
  beef.atomicTxid = r.txid;
7298
7298
  setResultBeef(r, beef);
7299
- if (!vargs.options.returnTXIDOnly) r.tx = await traceActionStep(wallet, "wallet.create_action.serialize_result_beef", parent, () => beef.toUint8ArrayAtomic(r.txid));
7299
+ if (!vargs.options.returnTXIDOnly) r.tx = await traceActionStep(wallet, "wallet.create_action.serialize_result_beef", parent, () => beef.toBinaryAtomic(r.txid));
7300
7300
  }
7301
7301
  const { sendWithResults, notDelayedResults } = await traceActionStep(wallet, "wallet.create_action.process", parent, async () => await processAction(prior, wallet, auth, vargs));
7302
7302
  logger?.log("processed transaction");
@@ -7412,7 +7412,7 @@ async function signActionCore(wallet, auth, args, parent) {
7412
7412
  await traceSignActionStep(wallet, "wallet.sign_action.verify_unlock_scripts", parent, async () => await verifyUnlockScripts(txid, beef, wallet.scriptVerifier));
7413
7413
  const r = {
7414
7414
  txid: prior.tx.id("hex"),
7415
- tx: vargs.options.returnTXIDOnly ? void 0 : beef.toUint8ArrayAtomic(txid),
7415
+ tx: vargs.options.returnTXIDOnly ? void 0 : beef.toBinaryAtomic(txid),
7416
7416
  sendWithResults,
7417
7417
  notDelayedResults
7418
7418
  };
@@ -20784,9 +20784,11 @@ var BulkFileDataManager = class BulkFileDataManager {
20784
20784
  const nextHeight = lbf != null ? lbf.firstHeight + lbf.count : 0;
20785
20785
  ({headers: newBulkHeaders, incrementalChainWork} = trimAlreadyStoredHeaders(newBulkHeaders, nextHeight, incrementalChainWork));
20786
20786
  if (newBulkHeaders.length === 0) return;
20787
- if (lbf == null || nextHeight !== newBulkHeaders[0].height) throw new WERR_INVALID_PARAMETER("newBulkHeaders", "an extension of existing bulk headers");
20788
- if (!lbf.lastHash) throw new WERR_INTERNAL(`lastHash is not defined for the last bulk file ${lbf.fileName}`);
20789
- const lastChainWork = incrementalChainWork ? addWork(incrementalChainWork, lbf.lastChainWork) : computeChainWorkFromHeaders(newBulkHeaders, lbf);
20787
+ if (nextHeight !== newBulkHeaders[0].height) throw new WERR_INVALID_PARAMETER("newBulkHeaders", "an extension of existing bulk headers");
20788
+ if (lbf != null && !lbf.lastHash) throw new WERR_INTERNAL(`lastHash is not defined for the last bulk file ${lbf.fileName}`);
20789
+ const prevChainWork = lbf?.lastChainWork ?? "00".repeat(32);
20790
+ const prevHash = lbf?.lastHash ?? "00".repeat(32);
20791
+ const lastChainWork = incrementalChainWork ? addWork(incrementalChainWork, prevChainWork) : computeChainWorkFromHeaders(newBulkHeaders, lbf);
20790
20792
  const data = serializeBaseBlockHeaders(newBulkHeaders);
20791
20793
  const fileHash = asString(_bsv_sdk.Hash.sha256(asArray(data)), "base64");
20792
20794
  const bf = {
@@ -20796,9 +20798,9 @@ var BulkFileDataManager = class BulkFileDataManager {
20796
20798
  fileName: "incremental",
20797
20799
  firstHeight: newBulkHeaders[0].height,
20798
20800
  count: newBulkHeaders.length,
20799
- prevChainWork: lbf.lastChainWork,
20801
+ prevChainWork,
20800
20802
  lastChainWork,
20801
- prevHash: lbf.lastHash,
20803
+ prevHash,
20802
20804
  lastHash: newBulkHeaders.at(-1).hash,
20803
20805
  fileHash,
20804
20806
  data
@@ -21228,12 +21230,13 @@ function trimAlreadyStoredHeaders(headers, nextHeight, incrementalChainWork) {
21228
21230
  }
21229
21231
  /**
21230
21232
  * Computes `lastChainWork` for a sequence of new bulk headers extending `lbf`,
21231
- * validating that the sequence is contiguous.
21233
+ * or beginning at genesis when bulk storage is empty, validating that the
21234
+ * sequence is contiguous.
21232
21235
  */
21233
21236
  function computeChainWorkFromHeaders(headers, lbf) {
21234
- let lastHeight = lbf.firstHeight + lbf.count - 1;
21235
- let lastHash = lbf.lastHash;
21236
- let lastChainWork = lbf.lastChainWork;
21237
+ let lastHeight = lbf != null ? lbf.firstHeight + lbf.count - 1 : -1;
21238
+ let lastHash = lbf?.lastHash ?? "00".repeat(32);
21239
+ let lastChainWork = lbf?.lastChainWork ?? "00".repeat(32);
21237
21240
  for (const h of headers) {
21238
21241
  if (h.height !== lastHeight + 1 || h.previousHash !== lastHash) throw new WERR_INVALID_PARAMETER("headers", `an extension of existing bulk headers, header with height ${h.height} is non-sequential`);
21239
21242
  lastChainWork = addWork(lastChainWork, convertBitsToWork(h.bits));