@anywalletkit/wallet-zcash 0.5.0 → 0.5.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 CHANGED
@@ -985,7 +985,24 @@ var import_secp256k12 = require("@noble/curves/secp256k1.js");
985
985
 
986
986
  // src/read-only-account.ts
987
987
  var import_core6 = require("@anywalletkit/core");
988
+ function assertSpendShape(spend) {
989
+ const proto = typeof spend === "object" && spend !== null && !Array.isArray(spend) ? Object.getPrototypeOf(spend) : void 0;
990
+ if (proto === void 0 || proto !== null && Object.getPrototypeOf(proto) !== null) {
991
+ 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.");
992
+ }
993
+ }
988
994
  var toBig = (v) => typeof v === "bigint" ? v : BigInt(typeof v === "string" ? v.trim() : Math.round(v));
995
+ function spendValue(v) {
996
+ if (typeof v === "bigint") return v;
997
+ if (typeof v === "number" && Number.isInteger(v)) return BigInt(v);
998
+ if (typeof v === "string" && v.length <= 300 && !/\s/.test(v)) {
999
+ try {
1000
+ return BigInt(v);
1001
+ } catch {
1002
+ }
1003
+ }
1004
+ throw new UnsafeTransactionError("malformed-spend", "A spend value must be a bigint, a whole number or an integer string of at most 300 characters (zatoshis).");
1005
+ }
989
1006
  var WalletAccountReadOnlyZcash = class {
990
1007
  /** The transparent address. */
991
1008
  address;
@@ -1030,8 +1047,9 @@ var WalletAccountReadOnlyZcash = class {
1030
1047
  }
1031
1048
  /** Coin selection for a spend (ZIP-317 fee). Validates the recipient and the dust floor first. */
1032
1049
  async planSpend(spend) {
1050
+ assertSpendShape(spend);
1033
1051
  if (this.scriptKind !== "p2pkh") throw new Error(`Cannot build spends from a ${this.scriptKind} address; only P2PKH (t1\u2026) accounts spend.`);
1034
- const amount = toBig(spend.value);
1052
+ const amount = spendValue(spend.value);
1035
1053
  const recipient = decodeAddress(spend.to, this._network);
1036
1054
  if (amount < DUST_LIMIT) throw new Error(`The amount must be at least the dust limit (${DUST_LIMIT} zatoshis).`);
1037
1055
  const utxos = await this.requireClient("plan a spend").listUnspent(this.address);