@anywalletkit/wallet-zcash 0.3.1 → 0.4.0

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
@@ -128,7 +128,8 @@ function encodeAddress(kind, hash, network) {
128
128
  return b58.encode(Uint8Array.of(a, b, ...hash));
129
129
  }
130
130
  function decodeAddress(address, network) {
131
- const a = address.trim();
131
+ if (typeof address !== "string" || /\s/.test(address)) throw new Error(`Invalid Zcash address: it carries whitespace or an invisible character (${JSON.stringify(address)}).`);
132
+ const a = address;
132
133
  if (/^u1|^utest/i.test(a)) throw new Error(`Unified address (${a.slice(0, 6)}\u2026) \u2014 shielded receivers are not supported; use a transparent t-address.`);
133
134
  if (/^zs1|^ztestsapling/i.test(a)) throw new Error("Sapling shielded address (zs1\u2026) \u2014 this wallet sends to transparent t-addresses only.");
134
135
  if (/^zc/i.test(a) && a.length > 90) throw new Error("Sprout address (zc\u2026) \u2014 the Sprout pool is deprecated; use a transparent t-address.");
@@ -1159,7 +1160,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1159
1160
  return { lockTime, expiryHeight, consensusBranchId };
1160
1161
  }
1161
1162
  /** Sign every input through the signer; the scriptSig is `<DER ‖ 0x01> <pubkey>`. */
1162
- async signInputs(tx, spent) {
1163
+ async #signInputs(tx, spent) {
1163
1164
  for (let i = 0; i < tx.inputs.length; i++) {
1164
1165
  const digest = sighashAll(tx, i, spent);
1165
1166
  const rs = await this.signer.sign(digest, { scheme: "ecdsa", context: "zcash-sighash" });
@@ -1167,7 +1168,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1167
1168
  tx.inputs[i].scriptSig = p2pkhScriptSig(der, this.publicKey);
1168
1169
  }
1169
1170
  }
1170
- async signSpend(spend) {
1171
+ async #signSpend(spend) {
1171
1172
  this.live();
1172
1173
  const plan = await this.planSpend(spend);
1173
1174
  const params = await this.chainParams();
@@ -1179,7 +1180,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1179
1180
  const spent = plan.utxos.map((u) => ({ value: u.value, script: this.scriptPubKey }));
1180
1181
  const have = plan.utxos.reduce((s, u) => s + u.value, 0n);
1181
1182
  if (have < plan.amount + plan.fee) throw new import_core7.InsufficientFundsError(plan.amount + plan.fee, have, "ZEC");
1182
- await this.signInputs(tx, spent);
1183
+ await this.#signInputs(tx, spent);
1183
1184
  const ctx = this.ctx({ to: spend.to, value: plan.amount });
1184
1185
  const desc = describeTransaction(tx, spent, ctx);
1185
1186
  assertSafe(desc, ctx);
@@ -1211,7 +1212,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1211
1212
  /** "What you sign": the fully resolved spend (signed, NOT broadcast) or a caller's raw hex. */
1212
1213
  async describeTransaction(tx) {
1213
1214
  if (typeof tx === "string") return (await this.describeRaw(tx)).desc;
1214
- return (await this.signSpend(tx)).desc;
1215
+ return (await this.#signSpend(tx)).desc;
1215
1216
  }
1216
1217
  /** Sign without broadcasting. Returns the raw transaction hex. Raw hex input gets the checks `sendTransaction` runs (prevouts through the client) and is returned unchanged, never re-signed. */
1217
1218
  async signTransaction(tx, options = {}) {
@@ -1221,7 +1222,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1221
1222
  this.checkMax(desc.fee, (0, import_core7.feeLimit)(this._config.transactionMaxFee, options), "transaction");
1222
1223
  return tx;
1223
1224
  }
1224
- const built = await this.signSpend(tx);
1225
+ const built = await this.#signSpend(tx);
1225
1226
  this.checkMax(built.fee, (0, import_core7.feeLimit)(this._config.transactionMaxFee, options), "transaction");
1226
1227
  return built.hex;
1227
1228
  }
@@ -1239,7 +1240,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1239
1240
  hash = txid(parsed);
1240
1241
  fee = desc.fee;
1241
1242
  } else {
1242
- const built = await this.signSpend(tx);
1243
+ const built = await this.#signSpend(tx);
1243
1244
  rawHex = built.hex;
1244
1245
  hash = built.txid;
1245
1246
  fee = built.fee;
@@ -1252,7 +1253,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
1252
1253
  if (o.token) throw new Error("Tokens are not supported on the zcash blockchain.");
1253
1254
  this.live();
1254
1255
  const client = this.requireClient("transfer");
1255
- const built = await this.signSpend({ to: o.recipient, value: o.amount });
1256
+ const built = await this.#signSpend({ to: o.recipient, value: o.amount });
1256
1257
  this.checkMax(built.fee, (0, import_core7.feeLimit)(this._config.transferMaxFee, writeOptions), "transfer");
1257
1258
  return { hash: await this.broadcast(client, built.hex, built.txid), fee: built.fee };
1258
1259
  }