@anywalletkit/wallet-btc 0.3.2 → 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
@@ -885,8 +885,14 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
885
885
  /** Compressed secp256k1 public key. */
886
886
  publicKey;
887
887
  addressType;
888
- /** The signer that holds the key. */
889
- signer;
888
+ /**
889
+ * The signer that holds the key, in a private field: not a property of the account, so no code
890
+ * the account is handed to (a protocol module, a logger) can reach it and sign around the
891
+ * account's checks (audit 2026-10-29 A1).
892
+ */
893
+ #signer;
894
+ /** What holds the key: `seed`, `key` (one imported key) or `external`. */
895
+ signerKind;
890
896
  _disposed = false;
891
897
  _readOnly;
892
898
  /** `publicKey` is the signer's compressed secp256k1 key (33 bytes); it is needed synchronously for the address. */
@@ -894,9 +900,10 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
894
900
  const type = config.addressType ?? "p2wpkh";
895
901
  super(addressFromPublicKey(publicKey, networkParams(config.network ?? "bitcoin"), type), config);
896
902
  this.addressType = type;
897
- this.signer = (0, import_core9.requireCurve)(signer, "secp256k1");
903
+ this.#signer = (0, import_core9.requireCurve)(signer, "secp256k1");
904
+ this.signerKind = this.#signer.kind;
898
905
  const needed = type === "p2tr" ? "schnorr" : "ecdsa";
899
- if (!this.signer.schemes.includes(needed)) throw new import_core9.SignerError(`A ${type} account needs a signer with the '${needed}' scheme (has: ${this.signer.schemes.join(", ")}).`);
906
+ if (!this.#signer.schemes.includes(needed)) throw new import_core9.SignerError(`A ${type} account needs a signer with the '${needed}' scheme (has: ${this.#signer.schemes.join(", ")}).`);
900
907
  this.publicKey = publicKey;
901
908
  this.path = path;
902
909
  }
@@ -916,7 +923,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
916
923
  async sign(message) {
917
924
  this.live();
918
925
  if (this.addressType === "p2tr") throw new UnsupportedAddressTypeError("BIP-137 message signatures do not exist for taproot accounts (BIP-322 is not implemented).");
919
- return signMessageWith(message, this.signer, "p2wpkh");
926
+ return signMessageWith(message, this.#signer, "p2wpkh");
920
927
  }
921
928
  /** The x-only internal key and its BIP-86 tweak (no script tree) for taproot key-path spends. */
922
929
  taprootKeys() {
@@ -934,7 +941,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
934
941
  const scripts = Array.from({ length: tx.inputsLength }, () => this.scriptPubKey);
935
942
  for (let i = 0; i < tx.inputsLength; i++) {
936
943
  const sighash = tx.preimageWitnessV1(i, scripts, import_btc_signer4.SigHash.DEFAULT, values);
937
- const sig = await this.signer.sign(sighash, { scheme: "schnorr", context: "btc-taproot-keypath", tweak });
944
+ const sig = await this.#signer.sign(sighash, { scheme: "schnorr", context: "btc-taproot-keypath", tweak });
938
945
  tx.updateInput(i, { tapKeySig: sig }, true);
939
946
  }
940
947
  return;
@@ -942,7 +949,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
942
949
  const scriptCode = (0, import_btc_signer4.p2pkh)(this.publicKey).script;
943
950
  for (let i = 0; i < tx.inputsLength; i++) {
944
951
  const sighash = tx.preimageWitnessV0(i, scriptCode, import_btc_signer4.SigHash.ALL, values[i]);
945
- const rs = await this.signer.sign(sighash, { scheme: "ecdsa", context: "btc-sighash" });
952
+ const rs = await this.#signer.sign(sighash, { scheme: "ecdsa", context: "btc-sighash" });
946
953
  const der = import_secp256k12.secp256k1.Signature.fromBytes(rs, "compact").toBytes("der");
947
954
  const sig = new Uint8Array(der.length + 1);
948
955
  sig.set(der, 0);
@@ -1129,7 +1136,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
1129
1136
  }
1130
1137
  dispose() {
1131
1138
  this._disposed = true;
1132
- this.signer.dispose();
1139
+ this.#signer.dispose();
1133
1140
  }
1134
1141
  };
1135
1142