@anywalletkit/wallet-btc 0.3.1 → 0.3.2
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 +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -13
- package/dist/index.d.ts +1 -13
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -928,7 +928,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
928
928
|
* p2wpkh → `partialSig` (DER + SIGHASH_ALL), p2tr → `tapKeySig` (64 bytes, DEFAULT).
|
|
929
929
|
* btc-signer only computes the sighash and assembles the witness; it never sees a key.
|
|
930
930
|
*/
|
|
931
|
-
async signInputs(tx, values) {
|
|
931
|
+
async #signInputs(tx, values) {
|
|
932
932
|
if (this.addressType === "p2tr") {
|
|
933
933
|
const { tweak } = this.taprootKeys();
|
|
934
934
|
const scripts = Array.from({ length: tx.inputsLength }, () => this.scriptPubKey);
|
|
@@ -953,7 +953,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
953
953
|
ctx(intended) {
|
|
954
954
|
return { network: this._network, ownAddress: this.address, intended, maxFeeRate: this.maxFeeRate };
|
|
955
955
|
}
|
|
956
|
-
async signPlan(plan, to, recipientValue, change, lockTime, rbf) {
|
|
956
|
+
async #signPlan(plan, to, recipientValue, change, lockTime, rbf) {
|
|
957
957
|
const spend = spendInfo(this.publicKey, this._network, this.addressType);
|
|
958
958
|
const tx = new import_btc_signer4.Transaction({ lockTime });
|
|
959
959
|
const sequence = rbf ? RBF_SEQUENCE : FINAL_SEQUENCE;
|
|
@@ -962,7 +962,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
962
962
|
}
|
|
963
963
|
tx.addOutputAddress(to, recipientValue, this._network);
|
|
964
964
|
if (change > 0n) tx.addOutputAddress(this.address, change, this._network);
|
|
965
|
-
await this
|
|
965
|
+
await this.#signInputs(tx, plan.utxos.map((u) => u.value));
|
|
966
966
|
tx.finalize();
|
|
967
967
|
return tx;
|
|
968
968
|
}
|
|
@@ -971,7 +971,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
971
971
|
* signed vsize somehow needs more, the difference comes out of change (never the
|
|
972
972
|
* recipient) and the tx is re-signed once.
|
|
973
973
|
*/
|
|
974
|
-
async signSpend(spend) {
|
|
974
|
+
async #signSpend(spend) {
|
|
975
975
|
this.live();
|
|
976
976
|
const plan = await this.planSpend(spend);
|
|
977
977
|
await this.verifyPrevouts(plan.utxos);
|
|
@@ -979,7 +979,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
979
979
|
const rbf = spend.rbf ?? this._config.rbf ?? true;
|
|
980
980
|
let change = plan.change;
|
|
981
981
|
let fee = plan.fee;
|
|
982
|
-
let tx = await this
|
|
982
|
+
let tx = await this.#signPlan(plan, spend.to, plan.amount, change, lockTime, rbf);
|
|
983
983
|
const required = BigInt(tx.vsize) * plan.feeRate;
|
|
984
984
|
if (required > fee) {
|
|
985
985
|
const delta = required - fee;
|
|
@@ -992,7 +992,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
992
992
|
fee = plan.fee + plan.change;
|
|
993
993
|
change = 0n;
|
|
994
994
|
} else fee = required;
|
|
995
|
-
tx = await this
|
|
995
|
+
tx = await this.#signPlan(plan, spend.to, plan.amount, change, lockTime, rbf);
|
|
996
996
|
if (BigInt(tx.vsize) * plan.feeRate > fee) throw new Error("Fee shortfall after output rebalance.");
|
|
997
997
|
}
|
|
998
998
|
const ctx = this.ctx({ to: spend.to, value: plan.amount });
|
|
@@ -1063,7 +1063,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1063
1063
|
/** "What you sign": the fully resolved spend (signed, NOT broadcast) or a caller's raw hex. */
|
|
1064
1064
|
async describeTransaction(tx) {
|
|
1065
1065
|
if (typeof tx === "string") return (await this.describeRaw(tx)).desc;
|
|
1066
|
-
return (await this
|
|
1066
|
+
return (await this.#signSpend(tx)).desc;
|
|
1067
1067
|
}
|
|
1068
1068
|
/** 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. */
|
|
1069
1069
|
async signTransaction(tx, options = {}) {
|
|
@@ -1073,7 +1073,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1073
1073
|
this.checkMax(desc.fee, (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
|
|
1074
1074
|
return tx;
|
|
1075
1075
|
}
|
|
1076
|
-
const { tx: built, fee } = await this
|
|
1076
|
+
const { tx: built, fee } = await this.#signSpend(tx);
|
|
1077
1077
|
this.checkMax(fee, (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
|
|
1078
1078
|
return built.hex;
|
|
1079
1079
|
}
|
|
@@ -1091,7 +1091,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1091
1091
|
hash = parsed.id;
|
|
1092
1092
|
fee = desc.fee;
|
|
1093
1093
|
} else {
|
|
1094
|
-
const built = await this
|
|
1094
|
+
const built = await this.#signSpend(tx);
|
|
1095
1095
|
rawHex = built.tx.hex;
|
|
1096
1096
|
hash = built.tx.id;
|
|
1097
1097
|
fee = built.fee;
|
|
@@ -1104,7 +1104,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1104
1104
|
if (o.token) throw new Error("Tokens are not supported on the bitcoin blockchain.");
|
|
1105
1105
|
this.live();
|
|
1106
1106
|
const client = this.requireClient("transfer");
|
|
1107
|
-
const built = await this
|
|
1107
|
+
const built = await this.#signSpend({ to: o.recipient, value: o.amount });
|
|
1108
1108
|
this.checkMax(built.fee, (0, import_core9.feeLimit)(this._config.transferMaxFee, writeOptions), "transfer");
|
|
1109
1109
|
return { hash: await this.broadcast(client, built.tx.hex, built.tx.id), fee: built.fee };
|
|
1110
1110
|
}
|