@anywalletkit/wallet-btc 0.4.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/index.cjs +19 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -722,7 +722,24 @@ var purposeFor = (type) => type === "p2tr" ? 86 : 84;
|
|
|
722
722
|
|
|
723
723
|
// src/read-only-account.ts
|
|
724
724
|
var import_core8 = require("@anywalletkit/core");
|
|
725
|
+
function assertSpendShape(spend) {
|
|
726
|
+
const proto = typeof spend === "object" && spend !== null && !Array.isArray(spend) ? Object.getPrototypeOf(spend) : void 0;
|
|
727
|
+
if (proto === void 0 || proto !== null && Object.getPrototypeOf(proto) !== null) {
|
|
728
|
+
throw new UnsafeTransactionError("malformed-spend", "A spend must be one plain object ({ to, value, \u2026 }); a list or another kind of object is not signed.");
|
|
729
|
+
}
|
|
730
|
+
}
|
|
725
731
|
var toBig = (v) => typeof v === "bigint" ? v : BigInt(Math.round(Number(v)));
|
|
732
|
+
function spendValue(v) {
|
|
733
|
+
if (typeof v === "bigint") return v;
|
|
734
|
+
if (typeof v === "number" && Number.isInteger(v)) return BigInt(v);
|
|
735
|
+
if (typeof v === "string" && v.length <= 300 && !/\s/.test(v)) {
|
|
736
|
+
try {
|
|
737
|
+
return BigInt(v);
|
|
738
|
+
} catch {
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
throw new UnsafeTransactionError("malformed-spend", "A spend value must be a bigint, a whole number or an integer string of at most 300 characters (sats).");
|
|
742
|
+
}
|
|
726
743
|
var WalletAccountReadOnlyBtc = class {
|
|
727
744
|
/** The address. */
|
|
728
745
|
address;
|
|
@@ -788,7 +805,8 @@ var WalletAccountReadOnlyBtc = class {
|
|
|
788
805
|
}
|
|
789
806
|
/** Coin selection for a spend (see coinselect.ts). Validates the recipient and the dust floor first. */
|
|
790
807
|
async planSpend(spend) {
|
|
791
|
-
|
|
808
|
+
assertSpendShape(spend);
|
|
809
|
+
const amount = spendValue(spend.value);
|
|
792
810
|
const recipient = decodeAddress(spend.to, this._network);
|
|
793
811
|
const floor = dustLimit(recipient.kind);
|
|
794
812
|
if (amount < floor) throw new Error(`The amount must be at least the dust limit of the recipient's address type (${floor} sat).`);
|