@anywalletkit/wallet-btc 0.2.3 → 0.2.5
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 +14 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +14 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -901,7 +901,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
901
901
|
ctx(intended) {
|
|
902
902
|
return { network: this._network, ownAddress: this.address, intended, maxFeeRate: this.maxFeeRate };
|
|
903
903
|
}
|
|
904
|
-
async
|
|
904
|
+
async signPlan(plan, to, recipientValue, change, lockTime, rbf) {
|
|
905
905
|
const spend = spendInfo(this.publicKey, this._network, this.addressType);
|
|
906
906
|
const tx = new import_btc_signer4.Transaction({ lockTime });
|
|
907
907
|
const sequence = rbf ? RBF_SEQUENCE : FINAL_SEQUENCE;
|
|
@@ -919,7 +919,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
919
919
|
* signed vsize somehow needs more, the difference comes out of change (never the
|
|
920
920
|
* recipient) and the tx is re-signed once.
|
|
921
921
|
*/
|
|
922
|
-
async
|
|
922
|
+
async signSpend(spend) {
|
|
923
923
|
this.live();
|
|
924
924
|
const plan = await this.planSpend(spend);
|
|
925
925
|
await this.verifyPrevouts(plan.utxos);
|
|
@@ -927,7 +927,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
927
927
|
const rbf = spend.rbf ?? this._config.rbf ?? true;
|
|
928
928
|
let change = plan.change;
|
|
929
929
|
let fee = plan.fee;
|
|
930
|
-
let tx = await this.
|
|
930
|
+
let tx = await this.signPlan(plan, spend.to, plan.amount, change, lockTime, rbf);
|
|
931
931
|
const required = BigInt(tx.vsize) * plan.feeRate;
|
|
932
932
|
if (required > fee) {
|
|
933
933
|
const delta = required - fee;
|
|
@@ -940,7 +940,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
940
940
|
fee = plan.fee + plan.change;
|
|
941
941
|
change = 0n;
|
|
942
942
|
} else fee = required;
|
|
943
|
-
tx = await this.
|
|
943
|
+
tx = await this.signPlan(plan, spend.to, plan.amount, change, lockTime, rbf);
|
|
944
944
|
if (BigInt(tx.vsize) * plan.feeRate > fee) throw new Error("Fee shortfall after output rebalance.");
|
|
945
945
|
}
|
|
946
946
|
const ctx = this.ctx({ to: spend.to, value: plan.amount });
|
|
@@ -1011,13 +1011,17 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1011
1011
|
/** "What you sign": the fully resolved spend (signed, NOT broadcast) or a caller's raw hex. */
|
|
1012
1012
|
async describeTransaction(tx) {
|
|
1013
1013
|
if (typeof tx === "string") return (await this.describeRaw(tx)).desc;
|
|
1014
|
-
return (await this.
|
|
1014
|
+
return (await this.signSpend(tx)).desc;
|
|
1015
1015
|
}
|
|
1016
|
-
/** Sign without broadcasting. Returns the raw transaction hex. Raw hex input is returned unchanged. */
|
|
1016
|
+
/** 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. */
|
|
1017
1017
|
async signTransaction(tx, options = {}) {
|
|
1018
1018
|
this.live();
|
|
1019
|
-
if (typeof tx === "string")
|
|
1020
|
-
|
|
1019
|
+
if (typeof tx === "string") {
|
|
1020
|
+
const { desc } = await this.describeRaw(tx);
|
|
1021
|
+
this.checkMax(desc.fee, (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
|
|
1022
|
+
return tx;
|
|
1023
|
+
}
|
|
1024
|
+
const { tx: built, fee } = await this.signSpend(tx);
|
|
1021
1025
|
this.checkMax(fee, (0, import_core9.feeLimit)(this._config.transactionMaxFee, options), "transaction");
|
|
1022
1026
|
return built.hex;
|
|
1023
1027
|
}
|
|
@@ -1035,7 +1039,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1035
1039
|
hash = parsed.id;
|
|
1036
1040
|
fee = desc.fee;
|
|
1037
1041
|
} else {
|
|
1038
|
-
const built = await this.
|
|
1042
|
+
const built = await this.signSpend(tx);
|
|
1039
1043
|
rawHex = built.tx.hex;
|
|
1040
1044
|
hash = built.tx.id;
|
|
1041
1045
|
fee = built.fee;
|
|
@@ -1049,7 +1053,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
1049
1053
|
if (o.token) throw new Error("Tokens are not supported on the bitcoin blockchain.");
|
|
1050
1054
|
this.live();
|
|
1051
1055
|
const client = this.requireClient("transfer");
|
|
1052
|
-
const built = await this.
|
|
1056
|
+
const built = await this.signSpend({ to: o.recipient, value: o.amount });
|
|
1053
1057
|
this.checkMax(built.fee, (0, import_core9.feeLimit)(this._config.transferMaxFee, writeOptions), "transfer");
|
|
1054
1058
|
const txid = await client.broadcast(built.tx.hex);
|
|
1055
1059
|
return { hash: txid || built.tx.id, fee: built.fee };
|