@anywalletkit/wallet-btc 0.3.0 → 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/{chunk-TZNOUBSP.js → chunk-SIR2SRK2.js} +1 -1
- package/dist/chunk-SIR2SRK2.js.map +1 -0
- package/dist/{history-B5fmsCjZ.d.cts → history-CasPAf7l.d.cts} +1 -1
- package/dist/{history-B5fmsCjZ.d.ts → history-CasPAf7l.d.ts} +1 -1
- package/dist/history.cjs.map +1 -1
- package/dist/history.d.cts +1 -1
- package/dist/history.d.ts +1 -1
- package/dist/history.js +1 -1
- package/dist/index.cjs +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -16
- package/dist/index.d.ts +4 -16
- package/dist/index.js +11 -11
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/dist/chunk-TZNOUBSP.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BtcClient, U as Utxo, a as BlockbookTx, b as BtcConfig, c as BtcTxDescription, d as BtcAddressType, e as BtcNetwork, f as BtcSpend, g as BtcTransferOptions, h as BtcMaxSpendableResult, i as BtcReceipt, j as BtcTransaction } from './history-
|
|
2
|
-
export { k as BlockbookAddressPage, l as
|
|
1
|
+
import { B as BtcClient, U as Utxo, a as BlockbookTx, b as BtcConfig, c as BtcTxDescription, d as BtcAddressType, e as BtcNetwork, f as BtcSpend, g as BtcTransferOptions, h as BtcMaxSpendableResult, i as BtcReceipt, j as BtcTransaction } from './history-CasPAf7l.cjs';
|
|
2
|
+
export { k as BlockbookAddressPage, l as BlockbookAddressTx, m as BlockbookClient, n as BlockbookTxDetails, o as BlockbookVin, p as BlockbookVout, q as BtcChainTx, r as BtcClientConfig, s as BtcHistoryCursor, t as BtcHistoryOptions, u as BtcHistoryPage, v as BtcHistoryRaw, w as BtcHistorySource, x as BtcTxInputDescription, y as BtcTxOutputDescription, z as BtcWarning, C as CAIP2_GENESIS, H as HistoryUnavailableError, A as btcExplorerTxUrl, D as createBtcHistory, E as decodeHistoryCursor, F as encodeHistoryCursor, G as mapBlockbookTx, I as unconfirmedOutgoing } from './history-CasPAf7l.cjs';
|
|
3
3
|
import { Signer, IWalletAccountReadOnly, IWalletAccount, WriteOptions, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
4
4
|
import { Transaction } from '@scure/btc-signer';
|
|
5
5
|
import { BTC_NETWORK } from '@scure/btc-signer/utils.js';
|
|
@@ -324,6 +324,7 @@ interface Built {
|
|
|
324
324
|
* ownership) before signing AND before broadcast — also for caller-supplied raw hex.
|
|
325
325
|
*/
|
|
326
326
|
declare class WalletAccountBtc extends WalletAccountReadOnlyBtc implements IWalletAccount {
|
|
327
|
+
#private;
|
|
327
328
|
/** UTXOs, fee rate and tip height come from the network before signing. */
|
|
328
329
|
readonly needsNetwork = true;
|
|
329
330
|
/** Derivation path, or `external` for an external signer. */
|
|
@@ -346,20 +347,7 @@ declare class WalletAccountBtc extends WalletAccountReadOnlyBtc implements IWall
|
|
|
346
347
|
sign(message: string | Uint8Array): Promise<string>;
|
|
347
348
|
/** The x-only internal key and its BIP-86 tweak (no script tree) for taproot key-path spends. */
|
|
348
349
|
private taprootKeys;
|
|
349
|
-
/**
|
|
350
|
-
* Sign every input through the signer and attach the witness-ready signature:
|
|
351
|
-
* p2wpkh → `partialSig` (DER + SIGHASH_ALL), p2tr → `tapKeySig` (64 bytes, DEFAULT).
|
|
352
|
-
* btc-signer only computes the sighash and assembles the witness; it never sees a key.
|
|
353
|
-
*/
|
|
354
|
-
private signInputs;
|
|
355
350
|
private ctx;
|
|
356
|
-
private signPlan;
|
|
357
|
-
/**
|
|
358
|
-
* Plan → sign → measure. The plan's fee assumes 72-byte DER signatures; if the
|
|
359
|
-
* signed vsize somehow needs more, the difference comes out of change (never the
|
|
360
|
-
* recipient) and the tx is re-signed once.
|
|
361
|
-
*/
|
|
362
|
-
protected signSpend(spend: BtcSpend): Promise<Built>;
|
|
363
351
|
private checkMax;
|
|
364
352
|
/**
|
|
365
353
|
* BIP-143 (p2wpkh) commits each input's signature to that input's CLAIMED amount
|
|
@@ -426,4 +414,4 @@ declare class WalletManagerBtc extends WalletManager<WalletAccountBtc, BtcConfig
|
|
|
426
414
|
getFeeRates(): Promise<FeeRates>;
|
|
427
415
|
}
|
|
428
416
|
|
|
429
|
-
export { BlockbookTx, BroadcastUnknownError, BtcAddressType, BtcClient, BtcConfig, BtcMaxSpendableResult, BtcNetwork, BtcReceipt, BtcSpend, BtcTransaction, BtcTransferOptions, BtcTxDescription, type CoinSelectOptions, type CoinSelection, DEFAULT_MAX_FEE_RATE, DUST_LIMIT_P2TR, DUST_LIMIT_P2WPKH, type DecodedAddress, type DescribeContext, EsploraClient, FINAL_SEQUENCE, INPUT_WEIGHT, MAX_UTXO_INPUTS, RBF_SEQUENCE, REGTEST_NETWORK, type ScriptKind, type SegwitType, type SelectionTarget, type SpendPlan, TooManyInputsError, type UnsafeTransactionCode, UnsafeTransactionError, UnsupportedAddressTypeError, Utxo, WalletAccountBtc, WalletAccountReadOnlyBtc, WalletManagerBtc, addressFor, addressFromPublicKey, addressFromScript, assertSafe, coinType, createClient, decodeAddress, WalletManagerBtc as default, describeTransaction, dustLimit, encodeMessageSignature, estimateVsize, isAnsweredRefusal, magicHash, networkParams, outputVBytes, parseRawTransaction, purposeFor, recoverMessagePublicKey, scriptKind, selectAll, selectCoins, signMessage, signMessageWith, spendableUtxos };
|
|
417
|
+
export { BlockbookTx, BroadcastUnknownError, BtcAddressType, BtcClient, BtcConfig, BtcMaxSpendableResult, BtcNetwork, BtcReceipt, BtcSpend, BtcTransaction, BtcTransferOptions, BtcTxDescription, type Built, type CoinSelectOptions, type CoinSelection, DEFAULT_MAX_FEE_RATE, DUST_LIMIT_P2TR, DUST_LIMIT_P2WPKH, type DecodedAddress, type DescribeContext, EsploraClient, FINAL_SEQUENCE, INPUT_WEIGHT, MAX_UTXO_INPUTS, RBF_SEQUENCE, REGTEST_NETWORK, type ScriptKind, type SegwitType, type SelectionTarget, type SpendPlan, TooManyInputsError, type UnsafeTransactionCode, UnsafeTransactionError, UnsupportedAddressTypeError, Utxo, WalletAccountBtc, WalletAccountReadOnlyBtc, WalletManagerBtc, addressFor, addressFromPublicKey, addressFromScript, assertSafe, coinType, createClient, decodeAddress, WalletManagerBtc as default, describeTransaction, dustLimit, encodeMessageSignature, estimateVsize, isAnsweredRefusal, magicHash, networkParams, outputVBytes, parseRawTransaction, purposeFor, recoverMessagePublicKey, scriptKind, selectAll, selectCoins, signMessage, signMessageWith, spendableUtxos };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BtcClient, U as Utxo, a as BlockbookTx, b as BtcConfig, c as BtcTxDescription, d as BtcAddressType, e as BtcNetwork, f as BtcSpend, g as BtcTransferOptions, h as BtcMaxSpendableResult, i as BtcReceipt, j as BtcTransaction } from './history-
|
|
2
|
-
export { k as BlockbookAddressPage, l as
|
|
1
|
+
import { B as BtcClient, U as Utxo, a as BlockbookTx, b as BtcConfig, c as BtcTxDescription, d as BtcAddressType, e as BtcNetwork, f as BtcSpend, g as BtcTransferOptions, h as BtcMaxSpendableResult, i as BtcReceipt, j as BtcTransaction } from './history-CasPAf7l.js';
|
|
2
|
+
export { k as BlockbookAddressPage, l as BlockbookAddressTx, m as BlockbookClient, n as BlockbookTxDetails, o as BlockbookVin, p as BlockbookVout, q as BtcChainTx, r as BtcClientConfig, s as BtcHistoryCursor, t as BtcHistoryOptions, u as BtcHistoryPage, v as BtcHistoryRaw, w as BtcHistorySource, x as BtcTxInputDescription, y as BtcTxOutputDescription, z as BtcWarning, C as CAIP2_GENESIS, H as HistoryUnavailableError, A as btcExplorerTxUrl, D as createBtcHistory, E as decodeHistoryCursor, F as encodeHistoryCursor, G as mapBlockbookTx, I as unconfirmedOutgoing } from './history-CasPAf7l.js';
|
|
3
3
|
import { Signer, IWalletAccountReadOnly, IWalletAccount, WriteOptions, TransferResult, WalletManager, FeeRates } from '@anywalletkit/core';
|
|
4
4
|
import { Transaction } from '@scure/btc-signer';
|
|
5
5
|
import { BTC_NETWORK } from '@scure/btc-signer/utils.js';
|
|
@@ -324,6 +324,7 @@ interface Built {
|
|
|
324
324
|
* ownership) before signing AND before broadcast — also for caller-supplied raw hex.
|
|
325
325
|
*/
|
|
326
326
|
declare class WalletAccountBtc extends WalletAccountReadOnlyBtc implements IWalletAccount {
|
|
327
|
+
#private;
|
|
327
328
|
/** UTXOs, fee rate and tip height come from the network before signing. */
|
|
328
329
|
readonly needsNetwork = true;
|
|
329
330
|
/** Derivation path, or `external` for an external signer. */
|
|
@@ -346,20 +347,7 @@ declare class WalletAccountBtc extends WalletAccountReadOnlyBtc implements IWall
|
|
|
346
347
|
sign(message: string | Uint8Array): Promise<string>;
|
|
347
348
|
/** The x-only internal key and its BIP-86 tweak (no script tree) for taproot key-path spends. */
|
|
348
349
|
private taprootKeys;
|
|
349
|
-
/**
|
|
350
|
-
* Sign every input through the signer and attach the witness-ready signature:
|
|
351
|
-
* p2wpkh → `partialSig` (DER + SIGHASH_ALL), p2tr → `tapKeySig` (64 bytes, DEFAULT).
|
|
352
|
-
* btc-signer only computes the sighash and assembles the witness; it never sees a key.
|
|
353
|
-
*/
|
|
354
|
-
private signInputs;
|
|
355
350
|
private ctx;
|
|
356
|
-
private signPlan;
|
|
357
|
-
/**
|
|
358
|
-
* Plan → sign → measure. The plan's fee assumes 72-byte DER signatures; if the
|
|
359
|
-
* signed vsize somehow needs more, the difference comes out of change (never the
|
|
360
|
-
* recipient) and the tx is re-signed once.
|
|
361
|
-
*/
|
|
362
|
-
protected signSpend(spend: BtcSpend): Promise<Built>;
|
|
363
351
|
private checkMax;
|
|
364
352
|
/**
|
|
365
353
|
* BIP-143 (p2wpkh) commits each input's signature to that input's CLAIMED amount
|
|
@@ -426,4 +414,4 @@ declare class WalletManagerBtc extends WalletManager<WalletAccountBtc, BtcConfig
|
|
|
426
414
|
getFeeRates(): Promise<FeeRates>;
|
|
427
415
|
}
|
|
428
416
|
|
|
429
|
-
export { BlockbookTx, BroadcastUnknownError, BtcAddressType, BtcClient, BtcConfig, BtcMaxSpendableResult, BtcNetwork, BtcReceipt, BtcSpend, BtcTransaction, BtcTransferOptions, BtcTxDescription, type CoinSelectOptions, type CoinSelection, DEFAULT_MAX_FEE_RATE, DUST_LIMIT_P2TR, DUST_LIMIT_P2WPKH, type DecodedAddress, type DescribeContext, EsploraClient, FINAL_SEQUENCE, INPUT_WEIGHT, MAX_UTXO_INPUTS, RBF_SEQUENCE, REGTEST_NETWORK, type ScriptKind, type SegwitType, type SelectionTarget, type SpendPlan, TooManyInputsError, type UnsafeTransactionCode, UnsafeTransactionError, UnsupportedAddressTypeError, Utxo, WalletAccountBtc, WalletAccountReadOnlyBtc, WalletManagerBtc, addressFor, addressFromPublicKey, addressFromScript, assertSafe, coinType, createClient, decodeAddress, WalletManagerBtc as default, describeTransaction, dustLimit, encodeMessageSignature, estimateVsize, isAnsweredRefusal, magicHash, networkParams, outputVBytes, parseRawTransaction, purposeFor, recoverMessagePublicKey, scriptKind, selectAll, selectCoins, signMessage, signMessageWith, spendableUtxos };
|
|
417
|
+
export { BlockbookTx, BroadcastUnknownError, BtcAddressType, BtcClient, BtcConfig, BtcMaxSpendableResult, BtcNetwork, BtcReceipt, BtcSpend, BtcTransaction, BtcTransferOptions, BtcTxDescription, type Built, type CoinSelectOptions, type CoinSelection, DEFAULT_MAX_FEE_RATE, DUST_LIMIT_P2TR, DUST_LIMIT_P2WPKH, type DecodedAddress, type DescribeContext, EsploraClient, FINAL_SEQUENCE, INPUT_WEIGHT, MAX_UTXO_INPUTS, RBF_SEQUENCE, REGTEST_NETWORK, type ScriptKind, type SegwitType, type SelectionTarget, type SpendPlan, TooManyInputsError, type UnsafeTransactionCode, UnsafeTransactionError, UnsupportedAddressTypeError, Utxo, WalletAccountBtc, WalletAccountReadOnlyBtc, WalletManagerBtc, addressFor, addressFromPublicKey, addressFromScript, assertSafe, coinType, createClient, decodeAddress, WalletManagerBtc as default, describeTransaction, dustLimit, encodeMessageSignature, estimateVsize, isAnsweredRefusal, magicHash, networkParams, outputVBytes, parseRawTransaction, purposeFor, recoverMessagePublicKey, scriptKind, selectAll, selectCoins, signMessage, signMessageWith, spendableUtxos };
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
refusal,
|
|
17
17
|
refusedStatus,
|
|
18
18
|
unconfirmedOutgoing
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-SIR2SRK2.js";
|
|
20
20
|
|
|
21
21
|
// src/errors.ts
|
|
22
22
|
import { InsufficientFundsError, NetworkError, SignerError } from "@anywalletkit/core";
|
|
@@ -701,7 +701,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
701
701
|
* p2wpkh → `partialSig` (DER + SIGHASH_ALL), p2tr → `tapKeySig` (64 bytes, DEFAULT).
|
|
702
702
|
* btc-signer only computes the sighash and assembles the witness; it never sees a key.
|
|
703
703
|
*/
|
|
704
|
-
async signInputs(tx, values) {
|
|
704
|
+
async #signInputs(tx, values) {
|
|
705
705
|
if (this.addressType === "p2tr") {
|
|
706
706
|
const { tweak } = this.taprootKeys();
|
|
707
707
|
const scripts = Array.from({ length: tx.inputsLength }, () => this.scriptPubKey);
|
|
@@ -726,7 +726,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
726
726
|
ctx(intended) {
|
|
727
727
|
return { network: this._network, ownAddress: this.address, intended, maxFeeRate: this.maxFeeRate };
|
|
728
728
|
}
|
|
729
|
-
async signPlan(plan, to, recipientValue, change, lockTime, rbf) {
|
|
729
|
+
async #signPlan(plan, to, recipientValue, change, lockTime, rbf) {
|
|
730
730
|
const spend = spendInfo(this.publicKey, this._network, this.addressType);
|
|
731
731
|
const tx = new Transaction2({ lockTime });
|
|
732
732
|
const sequence = rbf ? RBF_SEQUENCE : FINAL_SEQUENCE;
|
|
@@ -735,7 +735,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
735
735
|
}
|
|
736
736
|
tx.addOutputAddress(to, recipientValue, this._network);
|
|
737
737
|
if (change > 0n) tx.addOutputAddress(this.address, change, this._network);
|
|
738
|
-
await this
|
|
738
|
+
await this.#signInputs(tx, plan.utxos.map((u) => u.value));
|
|
739
739
|
tx.finalize();
|
|
740
740
|
return tx;
|
|
741
741
|
}
|
|
@@ -744,7 +744,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
744
744
|
* signed vsize somehow needs more, the difference comes out of change (never the
|
|
745
745
|
* recipient) and the tx is re-signed once.
|
|
746
746
|
*/
|
|
747
|
-
async signSpend(spend) {
|
|
747
|
+
async #signSpend(spend) {
|
|
748
748
|
this.live();
|
|
749
749
|
const plan = await this.planSpend(spend);
|
|
750
750
|
await this.verifyPrevouts(plan.utxos);
|
|
@@ -752,7 +752,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
752
752
|
const rbf = spend.rbf ?? this._config.rbf ?? true;
|
|
753
753
|
let change = plan.change;
|
|
754
754
|
let fee = plan.fee;
|
|
755
|
-
let tx = await this
|
|
755
|
+
let tx = await this.#signPlan(plan, spend.to, plan.amount, change, lockTime, rbf);
|
|
756
756
|
const required = BigInt(tx.vsize) * plan.feeRate;
|
|
757
757
|
if (required > fee) {
|
|
758
758
|
const delta = required - fee;
|
|
@@ -765,7 +765,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
765
765
|
fee = plan.fee + plan.change;
|
|
766
766
|
change = 0n;
|
|
767
767
|
} else fee = required;
|
|
768
|
-
tx = await this
|
|
768
|
+
tx = await this.#signPlan(plan, spend.to, plan.amount, change, lockTime, rbf);
|
|
769
769
|
if (BigInt(tx.vsize) * plan.feeRate > fee) throw new Error("Fee shortfall after output rebalance.");
|
|
770
770
|
}
|
|
771
771
|
const ctx = this.ctx({ to: spend.to, value: plan.amount });
|
|
@@ -836,7 +836,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
836
836
|
/** "What you sign": the fully resolved spend (signed, NOT broadcast) or a caller's raw hex. */
|
|
837
837
|
async describeTransaction(tx) {
|
|
838
838
|
if (typeof tx === "string") return (await this.describeRaw(tx)).desc;
|
|
839
|
-
return (await this
|
|
839
|
+
return (await this.#signSpend(tx)).desc;
|
|
840
840
|
}
|
|
841
841
|
/** 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. */
|
|
842
842
|
async signTransaction(tx, options = {}) {
|
|
@@ -846,7 +846,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
846
846
|
this.checkMax(desc.fee, feeLimit(this._config.transactionMaxFee, options), "transaction");
|
|
847
847
|
return tx;
|
|
848
848
|
}
|
|
849
|
-
const { tx: built, fee } = await this
|
|
849
|
+
const { tx: built, fee } = await this.#signSpend(tx);
|
|
850
850
|
this.checkMax(fee, feeLimit(this._config.transactionMaxFee, options), "transaction");
|
|
851
851
|
return built.hex;
|
|
852
852
|
}
|
|
@@ -864,7 +864,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
864
864
|
hash = parsed.id;
|
|
865
865
|
fee = desc.fee;
|
|
866
866
|
} else {
|
|
867
|
-
const built = await this
|
|
867
|
+
const built = await this.#signSpend(tx);
|
|
868
868
|
rawHex = built.tx.hex;
|
|
869
869
|
hash = built.tx.id;
|
|
870
870
|
fee = built.fee;
|
|
@@ -877,7 +877,7 @@ var WalletAccountBtc = class _WalletAccountBtc extends WalletAccountReadOnlyBtc
|
|
|
877
877
|
if (o.token) throw new Error("Tokens are not supported on the bitcoin blockchain.");
|
|
878
878
|
this.live();
|
|
879
879
|
const client = this.requireClient("transfer");
|
|
880
|
-
const built = await this
|
|
880
|
+
const built = await this.#signSpend({ to: o.recipient, value: o.amount });
|
|
881
881
|
this.checkMax(built.fee, feeLimit(this._config.transferMaxFee, writeOptions), "transfer");
|
|
882
882
|
return { hash: await this.broadcast(client, built.tx.hex, built.tx.id), fee: built.fee };
|
|
883
883
|
}
|