@anywalletkit/wallet-zcash 0.3.0 → 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.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SpentOutput, Z as ZcashNetwork, a as ZcashTxDescription, b as ZcashClient, U as Utxo, c as ZcashTxInfo, d as ZcashConfig, e as ZcashSpend, f as ZcashTransferOptions, g as ZcashMaxSpendableResult, h as ZcashReceipt, i as ZcashTransaction } from './history-BpA-R7Tf.cjs';
2
- export { B as BLOCKCHAIR_URL, j as BlockchairClient, k as BlockchairTxDashboard, C as CAIP2, H as HistoryUnavailableError, l as ZcashChainTx, m as ZcashClientConfig, n as ZcashHistoryCursor, o as ZcashHistoryOptions, p as ZcashHistoryPage, q as ZcashHistoryRaw, r as ZcashHistorySource, s as ZcashTxInputDescription, t as ZcashTxOutputDescription, u as ZcashWarning, v as blockchairTime, w as createZcashHistory, x as decodeHistoryCursor, y as encodeHistoryCursor, z as mapDashboardTx, A as zcashExplorerTxUrl } from './history-BpA-R7Tf.cjs';
1
+ import { S as SpentOutput, Z as ZcashNetwork, a as ZcashTxDescription, b as ZcashClient, U as Utxo, c as ZcashTxInfo, d as ZcashConfig, e as ZcashSpend, f as ZcashTransferOptions, g as ZcashMaxSpendableResult, h as ZcashReceipt, i as ZcashTransaction } from './history-CiZ6aFMT.cjs';
2
+ export { B as BLOCKCHAIR_URL, j as BlockchairClient, k as BlockchairInput, l as BlockchairOutput, m as BlockchairTxDashboard, n as BlockchairTxRow, C as CAIP2, H as HistoryUnavailableError, o as ZcashChainTx, p as ZcashClientConfig, q as ZcashHistoryCursor, r as ZcashHistoryOptions, s as ZcashHistoryPage, t as ZcashHistoryRaw, u as ZcashHistorySource, v as ZcashTxInputDescription, w as ZcashTxOutputDescription, x as ZcashWarning, y as blockchairTime, z as createZcashHistory, A as decodeHistoryCursor, D as encodeHistoryCursor, E as mapDashboardTx, F as zcashExplorerTxUrl } from './history-CiZ6aFMT.cjs';
3
3
  import { Signer, IWalletAccountReadOnly, IWalletAccount, WriteOptions, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
4
4
 
5
5
  declare const TX_VERSION_V5 = 2147483653;
@@ -368,6 +368,7 @@ interface Built {
368
368
  * ownership) before signing AND before broadcast — also for caller-supplied raw hex.
369
369
  */
370
370
  declare class WalletAccountZcash extends WalletAccountReadOnlyZcash implements IWalletAccount {
371
+ #private;
371
372
  /** UTXOs and the tip height come from the network before signing. */
372
373
  readonly needsNetwork = true;
373
374
  /** Derivation path, or `external` for an external signer. */
@@ -396,9 +397,6 @@ declare class WalletAccountZcash extends WalletAccountReadOnlyZcash implements I
396
397
  * transaction signed with expiry 0 never expires.
397
398
  */
398
399
  private chainParams;
399
- /** Sign every input through the signer; the scriptSig is `<DER ‖ 0x01> <pubkey>`. */
400
- private signInputs;
401
- protected signSpend(spend: ZcashSpend): Promise<Built>;
402
400
  private checkMax;
403
401
  /** The outputs a raw transaction spends, fetched through the client (the wire format carries no values). */
404
402
  private spentOutputs;
@@ -450,4 +448,4 @@ declare class WalletManagerZcash extends WalletManager<WalletAccountZcash, Zcash
450
448
  getFeeRates(): Promise<FeeRates>;
451
449
  }
452
450
 
453
- export { type BlockbookTxDetails, type BlockbookVin, type BlockbookVout, BroadcastUnknownError, CURRENT_BRANCH_ID, type CoinSelectOptions, type CoinSelection, DEFAULT_EXPIRY_DELTA, DEFAULT_MAX_FEE, DUST_LIMIT, type DecodedAddress, type DescribeContext, FINAL_SEQUENCE, GRACE_ACTIONS, MAINNET_UPGRADES, MARGINAL_FEE, MAX_SEQUENCE, MAX_UTXO_INPUTS, P2PKH_INPUT_SIZE, SIGHASH_ALL, type ScriptKind, type SpendPlan, SpentOutput, TX_VERSION_V5, TooManyInputsError, type TransparentTxV5, type TxInput, type TxOutput, type UnsafeTransactionCode, UnsafeTransactionError, Utxo, VERSION_GROUP_ID_V5, WalletAccountReadOnlyZcash, WalletAccountZcash, WalletManagerZcash, ZcashBlockbookClient, ZcashClient, ZcashConfig, ZcashMaxSpendableResult, ZcashNetwork, ZcashReceipt, ZcashSpend, ZcashTransaction, ZcashTransferOptions, ZcashTxDescription, ZcashTxInfo, addressFor, addressFromPublicKey, addressFromScript, addressPrefix, assertSafe, branchIdForHeight, coinType, conventionalFee, createClient, decodeAddress, WalletManagerZcash as default, describeTransaction, encodeAddress, encodeMessageSignature, estimateSize, hash160, headerDigest, isAnsweredRefusal, logicalActions, magicHash, outputSize, outputsDigest, p2pkhScriptSig, parseP2pkhScriptSig, parseTx, prevoutsDigest, recoverMessagePublicKey, scriptFor, scriptKind, selectAll, selectCoins, sequenceDigest, serializeTx, sighashAll, signMessageWith, spendableUtxos, transparentDigest, txHashPersonalization, txid, txidDigest };
451
+ export { type BlockbookTxDetails, type BlockbookVin, type BlockbookVout, BroadcastUnknownError, type Built, CURRENT_BRANCH_ID, type CoinSelectOptions, type CoinSelection, DEFAULT_EXPIRY_DELTA, DEFAULT_MAX_FEE, DUST_LIMIT, type DecodedAddress, type DescribeContext, FINAL_SEQUENCE, GRACE_ACTIONS, MAINNET_UPGRADES, MARGINAL_FEE, MAX_SEQUENCE, MAX_UTXO_INPUTS, P2PKH_INPUT_SIZE, SIGHASH_ALL, type ScriptKind, type SpendPlan, SpentOutput, TX_VERSION_V5, TooManyInputsError, type TransparentTxV5, type TxInput, type TxOutput, type UnsafeTransactionCode, UnsafeTransactionError, Utxo, VERSION_GROUP_ID_V5, WalletAccountReadOnlyZcash, WalletAccountZcash, WalletManagerZcash, ZcashBlockbookClient, ZcashClient, ZcashConfig, ZcashMaxSpendableResult, ZcashNetwork, ZcashReceipt, ZcashSpend, ZcashTransaction, ZcashTransferOptions, ZcashTxDescription, ZcashTxInfo, addressFor, addressFromPublicKey, addressFromScript, addressPrefix, assertSafe, branchIdForHeight, coinType, conventionalFee, createClient, decodeAddress, WalletManagerZcash as default, describeTransaction, encodeAddress, encodeMessageSignature, estimateSize, hash160, headerDigest, isAnsweredRefusal, logicalActions, magicHash, outputSize, outputsDigest, p2pkhScriptSig, parseP2pkhScriptSig, parseTx, prevoutsDigest, recoverMessagePublicKey, scriptFor, scriptKind, selectAll, selectCoins, sequenceDigest, serializeTx, sighashAll, signMessageWith, spendableUtxos, transparentDigest, txHashPersonalization, txid, txidDigest };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as SpentOutput, Z as ZcashNetwork, a as ZcashTxDescription, b as ZcashClient, U as Utxo, c as ZcashTxInfo, d as ZcashConfig, e as ZcashSpend, f as ZcashTransferOptions, g as ZcashMaxSpendableResult, h as ZcashReceipt, i as ZcashTransaction } from './history-BpA-R7Tf.js';
2
- export { B as BLOCKCHAIR_URL, j as BlockchairClient, k as BlockchairTxDashboard, C as CAIP2, H as HistoryUnavailableError, l as ZcashChainTx, m as ZcashClientConfig, n as ZcashHistoryCursor, o as ZcashHistoryOptions, p as ZcashHistoryPage, q as ZcashHistoryRaw, r as ZcashHistorySource, s as ZcashTxInputDescription, t as ZcashTxOutputDescription, u as ZcashWarning, v as blockchairTime, w as createZcashHistory, x as decodeHistoryCursor, y as encodeHistoryCursor, z as mapDashboardTx, A as zcashExplorerTxUrl } from './history-BpA-R7Tf.js';
1
+ import { S as SpentOutput, Z as ZcashNetwork, a as ZcashTxDescription, b as ZcashClient, U as Utxo, c as ZcashTxInfo, d as ZcashConfig, e as ZcashSpend, f as ZcashTransferOptions, g as ZcashMaxSpendableResult, h as ZcashReceipt, i as ZcashTransaction } from './history-CiZ6aFMT.js';
2
+ export { B as BLOCKCHAIR_URL, j as BlockchairClient, k as BlockchairInput, l as BlockchairOutput, m as BlockchairTxDashboard, n as BlockchairTxRow, C as CAIP2, H as HistoryUnavailableError, o as ZcashChainTx, p as ZcashClientConfig, q as ZcashHistoryCursor, r as ZcashHistoryOptions, s as ZcashHistoryPage, t as ZcashHistoryRaw, u as ZcashHistorySource, v as ZcashTxInputDescription, w as ZcashTxOutputDescription, x as ZcashWarning, y as blockchairTime, z as createZcashHistory, A as decodeHistoryCursor, D as encodeHistoryCursor, E as mapDashboardTx, F as zcashExplorerTxUrl } from './history-CiZ6aFMT.js';
3
3
  import { Signer, IWalletAccountReadOnly, IWalletAccount, WriteOptions, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
4
4
 
5
5
  declare const TX_VERSION_V5 = 2147483653;
@@ -368,6 +368,7 @@ interface Built {
368
368
  * ownership) before signing AND before broadcast — also for caller-supplied raw hex.
369
369
  */
370
370
  declare class WalletAccountZcash extends WalletAccountReadOnlyZcash implements IWalletAccount {
371
+ #private;
371
372
  /** UTXOs and the tip height come from the network before signing. */
372
373
  readonly needsNetwork = true;
373
374
  /** Derivation path, or `external` for an external signer. */
@@ -396,9 +397,6 @@ declare class WalletAccountZcash extends WalletAccountReadOnlyZcash implements I
396
397
  * transaction signed with expiry 0 never expires.
397
398
  */
398
399
  private chainParams;
399
- /** Sign every input through the signer; the scriptSig is `<DER ‖ 0x01> <pubkey>`. */
400
- private signInputs;
401
- protected signSpend(spend: ZcashSpend): Promise<Built>;
402
400
  private checkMax;
403
401
  /** The outputs a raw transaction spends, fetched through the client (the wire format carries no values). */
404
402
  private spentOutputs;
@@ -450,4 +448,4 @@ declare class WalletManagerZcash extends WalletManager<WalletAccountZcash, Zcash
450
448
  getFeeRates(): Promise<FeeRates>;
451
449
  }
452
450
 
453
- export { type BlockbookTxDetails, type BlockbookVin, type BlockbookVout, BroadcastUnknownError, CURRENT_BRANCH_ID, type CoinSelectOptions, type CoinSelection, DEFAULT_EXPIRY_DELTA, DEFAULT_MAX_FEE, DUST_LIMIT, type DecodedAddress, type DescribeContext, FINAL_SEQUENCE, GRACE_ACTIONS, MAINNET_UPGRADES, MARGINAL_FEE, MAX_SEQUENCE, MAX_UTXO_INPUTS, P2PKH_INPUT_SIZE, SIGHASH_ALL, type ScriptKind, type SpendPlan, SpentOutput, TX_VERSION_V5, TooManyInputsError, type TransparentTxV5, type TxInput, type TxOutput, type UnsafeTransactionCode, UnsafeTransactionError, Utxo, VERSION_GROUP_ID_V5, WalletAccountReadOnlyZcash, WalletAccountZcash, WalletManagerZcash, ZcashBlockbookClient, ZcashClient, ZcashConfig, ZcashMaxSpendableResult, ZcashNetwork, ZcashReceipt, ZcashSpend, ZcashTransaction, ZcashTransferOptions, ZcashTxDescription, ZcashTxInfo, addressFor, addressFromPublicKey, addressFromScript, addressPrefix, assertSafe, branchIdForHeight, coinType, conventionalFee, createClient, decodeAddress, WalletManagerZcash as default, describeTransaction, encodeAddress, encodeMessageSignature, estimateSize, hash160, headerDigest, isAnsweredRefusal, logicalActions, magicHash, outputSize, outputsDigest, p2pkhScriptSig, parseP2pkhScriptSig, parseTx, prevoutsDigest, recoverMessagePublicKey, scriptFor, scriptKind, selectAll, selectCoins, sequenceDigest, serializeTx, sighashAll, signMessageWith, spendableUtxos, transparentDigest, txHashPersonalization, txid, txidDigest };
451
+ export { type BlockbookTxDetails, type BlockbookVin, type BlockbookVout, BroadcastUnknownError, type Built, CURRENT_BRANCH_ID, type CoinSelectOptions, type CoinSelection, DEFAULT_EXPIRY_DELTA, DEFAULT_MAX_FEE, DUST_LIMIT, type DecodedAddress, type DescribeContext, FINAL_SEQUENCE, GRACE_ACTIONS, MAINNET_UPGRADES, MARGINAL_FEE, MAX_SEQUENCE, MAX_UTXO_INPUTS, P2PKH_INPUT_SIZE, SIGHASH_ALL, type ScriptKind, type SpendPlan, SpentOutput, TX_VERSION_V5, TooManyInputsError, type TransparentTxV5, type TxInput, type TxOutput, type UnsafeTransactionCode, UnsafeTransactionError, Utxo, VERSION_GROUP_ID_V5, WalletAccountReadOnlyZcash, WalletAccountZcash, WalletManagerZcash, ZcashBlockbookClient, ZcashClient, ZcashConfig, ZcashMaxSpendableResult, ZcashNetwork, ZcashReceipt, ZcashSpend, ZcashTransaction, ZcashTransferOptions, ZcashTxDescription, ZcashTxInfo, addressFor, addressFromPublicKey, addressFromScript, addressPrefix, assertSafe, branchIdForHeight, coinType, conventionalFee, createClient, decodeAddress, WalletManagerZcash as default, describeTransaction, encodeAddress, encodeMessageSignature, estimateSize, hash160, headerDigest, isAnsweredRefusal, logicalActions, magicHash, outputSize, outputsDigest, p2pkhScriptSig, parseP2pkhScriptSig, parseTx, prevoutsDigest, recoverMessagePublicKey, scriptFor, scriptKind, selectAll, selectCoins, sequenceDigest, serializeTx, sighashAll, signMessageWith, spendableUtxos, transparentDigest, txHashPersonalization, txid, txidDigest };
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  u32le,
27
27
  utf8ToBytes,
28
28
  zcashExplorerTxUrl
29
- } from "./chunk-KICTVRL7.js";
29
+ } from "./chunk-JIJF3MGJ.js";
30
30
 
31
31
  // src/address.ts
32
32
  import { sha256 } from "@noble/hashes/sha2.js";
@@ -59,7 +59,8 @@ function encodeAddress(kind, hash, network) {
59
59
  return b58.encode(Uint8Array.of(a, b, ...hash));
60
60
  }
61
61
  function decodeAddress(address, network) {
62
- const a = address.trim();
62
+ if (typeof address !== "string" || /\s/.test(address)) throw new Error(`Invalid Zcash address: it carries whitespace or an invisible character (${JSON.stringify(address)}).`);
63
+ const a = address;
63
64
  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.`);
64
65
  if (/^zs1|^ztestsapling/i.test(a)) throw new Error("Sapling shielded address (zs1\u2026) \u2014 this wallet sends to transparent t-addresses only.");
65
66
  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.");
@@ -788,7 +789,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
788
789
  return { lockTime, expiryHeight, consensusBranchId };
789
790
  }
790
791
  /** Sign every input through the signer; the scriptSig is `<DER ‖ 0x01> <pubkey>`. */
791
- async signInputs(tx, spent) {
792
+ async #signInputs(tx, spent) {
792
793
  for (let i = 0; i < tx.inputs.length; i++) {
793
794
  const digest = sighashAll(tx, i, spent);
794
795
  const rs = await this.signer.sign(digest, { scheme: "ecdsa", context: "zcash-sighash" });
@@ -796,7 +797,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
796
797
  tx.inputs[i].scriptSig = p2pkhScriptSig(der, this.publicKey);
797
798
  }
798
799
  }
799
- async signSpend(spend) {
800
+ async #signSpend(spend) {
800
801
  this.live();
801
802
  const plan = await this.planSpend(spend);
802
803
  const params = await this.chainParams();
@@ -808,7 +809,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
808
809
  const spent = plan.utxos.map((u) => ({ value: u.value, script: this.scriptPubKey }));
809
810
  const have = plan.utxos.reduce((s, u) => s + u.value, 0n);
810
811
  if (have < plan.amount + plan.fee) throw new InsufficientFundsError3(plan.amount + plan.fee, have, "ZEC");
811
- await this.signInputs(tx, spent);
812
+ await this.#signInputs(tx, spent);
812
813
  const ctx = this.ctx({ to: spend.to, value: plan.amount });
813
814
  const desc = describeTransaction(tx, spent, ctx);
814
815
  assertSafe(desc, ctx);
@@ -840,7 +841,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
840
841
  /** "What you sign": the fully resolved spend (signed, NOT broadcast) or a caller's raw hex. */
841
842
  async describeTransaction(tx) {
842
843
  if (typeof tx === "string") return (await this.describeRaw(tx)).desc;
843
- return (await this.signSpend(tx)).desc;
844
+ return (await this.#signSpend(tx)).desc;
844
845
  }
845
846
  /** 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. */
846
847
  async signTransaction(tx, options = {}) {
@@ -850,7 +851,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
850
851
  this.checkMax(desc.fee, feeLimit(this._config.transactionMaxFee, options), "transaction");
851
852
  return tx;
852
853
  }
853
- const built = await this.signSpend(tx);
854
+ const built = await this.#signSpend(tx);
854
855
  this.checkMax(built.fee, feeLimit(this._config.transactionMaxFee, options), "transaction");
855
856
  return built.hex;
856
857
  }
@@ -868,7 +869,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
868
869
  hash = txid(parsed);
869
870
  fee = desc.fee;
870
871
  } else {
871
- const built = await this.signSpend(tx);
872
+ const built = await this.#signSpend(tx);
872
873
  rawHex = built.hex;
873
874
  hash = built.txid;
874
875
  fee = built.fee;
@@ -881,7 +882,7 @@ var WalletAccountZcash = class _WalletAccountZcash extends WalletAccountReadOnly
881
882
  if (o.token) throw new Error("Tokens are not supported on the zcash blockchain.");
882
883
  this.live();
883
884
  const client = this.requireClient("transfer");
884
- const built = await this.signSpend({ to: o.recipient, value: o.amount });
885
+ const built = await this.#signSpend({ to: o.recipient, value: o.amount });
885
886
  this.checkMax(built.fee, feeLimit(this._config.transferMaxFee, writeOptions), "transfer");
886
887
  return { hash: await this.broadcast(client, built.hex, built.txid), fee: built.fee };
887
888
  }