@leather.io/bitcoin 0.16.7 → 0.18.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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +26 -0
- package/dist/index.d.ts +145 -2
- package/dist/index.js +550 -3
- package/dist/index.js.map +1 -1
- package/package.json +10 -8
- package/src/bitcoin-error.ts +15 -0
- package/src/btc-size-fee-estimator.spec.ts +113 -0
- package/src/btc-size-fee-estimator.ts +327 -0
- package/src/coin-selection/calculate-max-spend.spec.ts +54 -0
- package/src/coin-selection/calculate-max-spend.ts +48 -0
- package/src/coin-selection/coin-selection.mocks.ts +38 -0
- package/src/coin-selection/coin-selection.spec.ts +230 -0
- package/src/coin-selection/coin-selection.ts +139 -0
- package/src/coin-selection/coin-selection.utils.spec.ts +64 -0
- package/src/coin-selection/coin-selection.utils.ts +115 -0
- package/src/fees/bitcoin-fees.spec.ts +90 -0
- package/src/fees/bitcoin-fees.ts +68 -0
- package/src/index.ts +10 -0
- package/src/transactions/generate-unsigned-transaction.spec.ts +83 -0
- package/src/transactions/generate-unsigned-transaction.ts +71 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @leather.io/bitcoin@0.
|
|
2
|
+
> @leather.io/bitcoin@0.18.0 build /home/runner/work/mono/mono/packages/bitcoin
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
CLI Building entry: src/index.ts
|
|
@@ -8,9 +8,9 @@ CLI tsup v8.1.0
|
|
|
8
8
|
CLI Using tsup config: /home/runner/work/mono/mono/packages/bitcoin/tsup.config.ts
|
|
9
9
|
CLI Target: es2022
|
|
10
10
|
ESM Build start
|
|
11
|
-
ESM dist/index.js
|
|
12
|
-
ESM dist/index.js.map
|
|
13
|
-
ESM ⚡️ Build success in
|
|
11
|
+
ESM dist/index.js 43.72 KB
|
|
12
|
+
ESM dist/index.js.map 84.58 KB
|
|
13
|
+
ESM ⚡️ Build success in 58ms
|
|
14
14
|
DTS Build start
|
|
15
|
-
DTS ⚡️ Build success in
|
|
16
|
-
DTS dist/index.d.ts
|
|
15
|
+
DTS ⚡️ Build success in 4435ms
|
|
16
|
+
DTS dist/index.d.ts 20.41 KB
|
package/CHANGELOG.md
CHANGED
|
@@ -310,6 +310,32 @@
|
|
|
310
310
|
* devDependencies
|
|
311
311
|
* @leather.io/rpc bumped to 2.1.20
|
|
312
312
|
|
|
313
|
+
## [0.18.0](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.17.0...@leather.io/bitcoin-v0.18.0) (2024-11-29)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
### Features
|
|
317
|
+
|
|
318
|
+
* migrate bitcoin generate txs, closes LEA-1735 ([44fd6cf](https://github.com/leather-io/mono/commit/44fd6cfd29a2016b38d96b4e80e377ae7eae81df))
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
### Dependencies
|
|
322
|
+
|
|
323
|
+
* The following workspace dependencies were updated
|
|
324
|
+
* dependencies
|
|
325
|
+
* @leather.io/constants bumped to 0.13.6
|
|
326
|
+
* @leather.io/crypto bumped to 1.6.15
|
|
327
|
+
* @leather.io/models bumped to 0.23.0
|
|
328
|
+
* @leather.io/utils bumped to 0.20.1
|
|
329
|
+
* devDependencies
|
|
330
|
+
* @leather.io/rpc bumped to 2.1.21
|
|
331
|
+
|
|
332
|
+
## [0.17.0](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.16.7...@leather.io/bitcoin-v0.17.0) (2024-11-26)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
### Features
|
|
336
|
+
|
|
337
|
+
* migrate btc coin selection, closes LEA-1734 ([0cad7aa](https://github.com/leather-io/mono/commit/0cad7aaa35fbc8704d959a16d12965502757fe89))
|
|
338
|
+
|
|
313
339
|
## [0.16.4](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.16.3...@leather.io/bitcoin-v0.16.4) (2024-11-19)
|
|
314
340
|
|
|
315
341
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as ecpair from 'ecpair';
|
|
2
2
|
import * as bitcoin from 'bitcoinjs-lib';
|
|
3
3
|
import * as btc from '@scure/btc-signer';
|
|
4
|
-
import
|
|
4
|
+
import * as _leather_io_models from '@leather.io/models';
|
|
5
|
+
import { BitcoinNetworkModes, Money, AverageBitcoinFeeRates, NetworkModes } from '@leather.io/models';
|
|
6
|
+
import BigNumber from 'bignumber.js';
|
|
5
7
|
import { HDKey, Versions } from '@scure/bip32';
|
|
6
8
|
import * as _scure_btc_signer_payment from '@scure/btc-signer/payment';
|
|
7
9
|
import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
|
|
@@ -44,6 +46,121 @@ declare function signBip322MessageSimple(args: SignBip322MessageSimple): Promise
|
|
|
44
46
|
signature: string;
|
|
45
47
|
}>;
|
|
46
48
|
|
|
49
|
+
interface CoinSelectionOutput {
|
|
50
|
+
value: bigint;
|
|
51
|
+
address?: string;
|
|
52
|
+
}
|
|
53
|
+
interface CoinSelectionUtxo {
|
|
54
|
+
address: string;
|
|
55
|
+
txid: string;
|
|
56
|
+
value: number;
|
|
57
|
+
vout: number;
|
|
58
|
+
}
|
|
59
|
+
interface CoinSelectionRecipient {
|
|
60
|
+
address: string;
|
|
61
|
+
amount: Money;
|
|
62
|
+
}
|
|
63
|
+
interface DetermineUtxosForSpendArgs {
|
|
64
|
+
feeRate: number;
|
|
65
|
+
recipients: CoinSelectionRecipient[];
|
|
66
|
+
utxos: CoinSelectionUtxo[];
|
|
67
|
+
}
|
|
68
|
+
declare function determineUtxosForSpendAll({ feeRate, recipients, utxos, }: DetermineUtxosForSpendArgs): {
|
|
69
|
+
inputs: CoinSelectionUtxo[];
|
|
70
|
+
outputs: {
|
|
71
|
+
value: bigint;
|
|
72
|
+
address: string;
|
|
73
|
+
}[];
|
|
74
|
+
size: number;
|
|
75
|
+
fee: Money;
|
|
76
|
+
};
|
|
77
|
+
declare function determineUtxosForSpend({ feeRate, recipients, utxos }: DetermineUtxosForSpendArgs): {
|
|
78
|
+
txVBytes: number;
|
|
79
|
+
txBytes: number;
|
|
80
|
+
txWeight: number;
|
|
81
|
+
filteredUtxos: CoinSelectionUtxo[];
|
|
82
|
+
inputs: CoinSelectionUtxo[];
|
|
83
|
+
outputs: CoinSelectionOutput[];
|
|
84
|
+
size: number;
|
|
85
|
+
fee: Money;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
interface CalculateMaxBitcoinSpend {
|
|
89
|
+
address: string;
|
|
90
|
+
utxos: CoinSelectionUtxo[];
|
|
91
|
+
fetchedFeeRates?: AverageBitcoinFeeRates;
|
|
92
|
+
feeRate?: number;
|
|
93
|
+
}
|
|
94
|
+
declare function calculateMaxBitcoinSpend({ address, utxos, feeRate, fetchedFeeRates, }: CalculateMaxBitcoinSpend): {
|
|
95
|
+
spendAllFee: number;
|
|
96
|
+
amount: _leather_io_models.Money;
|
|
97
|
+
spendableBitcoin: BigNumber;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
declare function getUtxoTotal(utxos: CoinSelectionUtxo[]): BigNumber;
|
|
101
|
+
declare function getSizeInfo(payload: {
|
|
102
|
+
inputLength: number;
|
|
103
|
+
recipients: CoinSelectionRecipient[];
|
|
104
|
+
isSendMax?: boolean;
|
|
105
|
+
}): {
|
|
106
|
+
txVBytes: number;
|
|
107
|
+
txBytes: number;
|
|
108
|
+
txWeight: number;
|
|
109
|
+
};
|
|
110
|
+
declare function getSpendableAmount({ utxos, feeRate, recipients, }: {
|
|
111
|
+
utxos: CoinSelectionUtxo[];
|
|
112
|
+
feeRate: number;
|
|
113
|
+
recipients: CoinSelectionRecipient[];
|
|
114
|
+
}): {
|
|
115
|
+
spendableAmount: BigNumber;
|
|
116
|
+
fee: number;
|
|
117
|
+
};
|
|
118
|
+
declare function filterUneconomicalUtxos({ utxos, feeRate, recipients, }: {
|
|
119
|
+
utxos: CoinSelectionUtxo[];
|
|
120
|
+
feeRate: number;
|
|
121
|
+
recipients: CoinSelectionRecipient[];
|
|
122
|
+
}): CoinSelectionUtxo[];
|
|
123
|
+
|
|
124
|
+
type GetBitcoinTransactionFeeArgs = DetermineUtxosForSpendArgs & {
|
|
125
|
+
isSendingMax?: boolean;
|
|
126
|
+
};
|
|
127
|
+
declare function getBitcoinTransactionFee({ isSendingMax, ...props }: GetBitcoinTransactionFeeArgs): Money | null;
|
|
128
|
+
interface BitcoinFees {
|
|
129
|
+
blockchain: 'bitcoin';
|
|
130
|
+
high: {
|
|
131
|
+
fee: Money | null;
|
|
132
|
+
feeRate: number;
|
|
133
|
+
};
|
|
134
|
+
standard: {
|
|
135
|
+
fee: Money | null;
|
|
136
|
+
feeRate: number;
|
|
137
|
+
};
|
|
138
|
+
low: {
|
|
139
|
+
fee: Money | null;
|
|
140
|
+
feeRate: number;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
interface GetBitcoinFeesArgs {
|
|
144
|
+
feeRates: AverageBitcoinFeeRates;
|
|
145
|
+
isSendingMax?: boolean;
|
|
146
|
+
recipients: CoinSelectionRecipient[];
|
|
147
|
+
utxos: CoinSelectionUtxo[];
|
|
148
|
+
}
|
|
149
|
+
declare function getBitcoinFees({ feeRates, isSendingMax, recipients, utxos }: GetBitcoinFeesArgs): {
|
|
150
|
+
high: {
|
|
151
|
+
feeRate: number;
|
|
152
|
+
fee: Money | null;
|
|
153
|
+
};
|
|
154
|
+
standard: {
|
|
155
|
+
feeRate: number;
|
|
156
|
+
fee: Money | null;
|
|
157
|
+
};
|
|
158
|
+
low: {
|
|
159
|
+
feeRate: number;
|
|
160
|
+
fee: Money | null;
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
|
|
47
164
|
interface BtcSignerNetwork {
|
|
48
165
|
bech32: string;
|
|
49
166
|
pubKeyHash: number;
|
|
@@ -53,6 +170,32 @@ interface BtcSignerNetwork {
|
|
|
53
170
|
declare function getBtcSignerLibNetworkConfigByMode(network: BitcoinNetworkModes): BtcSignerNetwork;
|
|
54
171
|
declare function getBitcoinJsLibNetworkConfigByMode(network: BitcoinNetworkModes): bitcoin.networks.Network;
|
|
55
172
|
|
|
173
|
+
interface GenerateBitcoinUnsignedTransactionArgs {
|
|
174
|
+
feeRate: number;
|
|
175
|
+
isSendingMax?: boolean;
|
|
176
|
+
payerAddress: string;
|
|
177
|
+
payerPublicKey: string;
|
|
178
|
+
network: BtcSignerNetwork;
|
|
179
|
+
recipients: CoinSelectionRecipient[];
|
|
180
|
+
utxos: CoinSelectionUtxo[];
|
|
181
|
+
}
|
|
182
|
+
declare function generateBitcoinUnsignedTransactionNativeSegwit({ feeRate, isSendingMax, payerAddress, payerPublicKey, network, recipients, utxos, }: GenerateBitcoinUnsignedTransactionArgs): Promise<{
|
|
183
|
+
tx: btc.Transaction;
|
|
184
|
+
hex: string;
|
|
185
|
+
psbt: Uint8Array;
|
|
186
|
+
inputs: CoinSelectionUtxo[];
|
|
187
|
+
fee: _leather_io_models.Money;
|
|
188
|
+
} | null>;
|
|
189
|
+
|
|
190
|
+
declare enum BitcoinErrorMessage {
|
|
191
|
+
InsufficientFunds = "Insufficient funds",
|
|
192
|
+
NoInputsToSign = "No inputs to sign",
|
|
193
|
+
NoOutputsToSign = "No outputs to sign"
|
|
194
|
+
}
|
|
195
|
+
declare class BitcoinError extends Error {
|
|
196
|
+
constructor(message: string);
|
|
197
|
+
}
|
|
198
|
+
|
|
56
199
|
interface BitcoinAccount {
|
|
57
200
|
type: PaymentTypes;
|
|
58
201
|
derivationPath: string;
|
|
@@ -302,4 +445,4 @@ declare function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs):
|
|
|
302
445
|
readonly path?: undefined;
|
|
303
446
|
};
|
|
304
447
|
|
|
305
|
-
export { type AllowedSighashTypes, type BitcoinAccount, type BitcoinAccountKeychain, type BitcoinNativeSegwitPayer, type BitcoinPayer, type BitcoinPayerBase, type BitcoinPayerInfo, type BitcoinSigner, type BitcoinTaprootPayer, type BtcSignerDefaultBip32Derivation, type BtcSignerLibPaymentTypeIdentifers, type BtcSignerNetwork, type BtcSignerTapBip32Derivation, type PaymentTypeMap, type SupportedPaymentType, type SupportedPaymentTypeMap, type WithDerivePayer, bip322TransactionToSignValues, bitcoinNetworkModeToCoreNetworkMode, bitcoinNetworkToCoreNetworkMap, btcSignerLibPaymentTypeToPaymentTypeMap, coinTypeMap, createNativeSegwitBitcoinJsSigner, createTaprootBitcoinJsSigner, createToSpendTx, createWalletIdDecoratedPath, decodeBitcoinTx, decodeCompressedWifPrivateKey, deriveAddressIndexKeychainFromAccount, deriveAddressIndexZeroFromAccount, deriveBitcoinPayerFromAccount, deriveBtcBip49SeedFromMnemonic, deriveNativeSegwitAccountFromRootKeychain, deriveNativeSegwitReceiveAddressIndexZero, deriveRootBtcKeychain, deriveTaprootAccount, deriveTaprootReceiveAddressIndexZero, ecPairFromPrivateKey, ecdsaPublicKeyLength, ecdsaPublicKeyToSchnorr, encodeMessageWitnessData, extractExtendedPublicKeyFromPolicy, extractRequiredKeyOrigins, getAddressFromOutScript, getBitcoinCoinTypeIndexByNetwork, getBitcoinInputAddress, getBitcoinJsLibNetworkConfigByMode, getBtcSignerLibNetworkConfigByMode, getHdKeyVersionsFromNetwork, getInputPaymentType, getNativeSegwitAccountDerivationPath, getNativeSegwitAddress, getNativeSegwitAddressIndexDerivationPath, getNativeSegwitPaymentFromAddressIndex, getPsbtTxInputs, getPsbtTxOutputs, getTaprootAccountDerivationPath, getTaprootAddress, getTaprootAddressIndexDerivationPath, getTaprootPayment, getTaprootPaymentFromAddressIndex, hashBip322Message, inferNetworkFromAddress, inferNetworkFromPath, inferPaymentTypeFromAddress, inferPaymentTypeFromPath, initBitcoinAccount, initializeBitcoinAccountKeychainFromDescriptor, isBtcSignerLibPaymentType, isSupportedMessageSigningPaymentType, lookUpLedgerKeysByPath, lookupDerivationByAddress, makeNativeSegwitAccountDerivationPath, makeNativeSegwitAddressIndexDerivationPath, makePayToScriptHashAddress, makePayToScriptHashAddressBytes, makePayToScriptHashKeyHash, makeTaprootAccountDerivationPath, makeTaprootAddressIndexDerivationPath, mnemonicToRootNode, parseKnownPaymentType, payToScriptHashTestnetPrefix, payerToBip32Derivation, payerToTapBip32Derivation, paymentTypeMap, publicKeyToPayToScriptHashAddress, serializeKeyOrigin, signBip322MessageSimple, toXOnly, tweakSigner, whenBitcoinNetwork, whenPaymentType, whenSupportedPaymentType };
|
|
448
|
+
export { type AllowedSighashTypes, type BitcoinAccount, type BitcoinAccountKeychain, BitcoinError, BitcoinErrorMessage, type BitcoinFees, type BitcoinNativeSegwitPayer, type BitcoinPayer, type BitcoinPayerBase, type BitcoinPayerInfo, type BitcoinSigner, type BitcoinTaprootPayer, type BtcSignerDefaultBip32Derivation, type BtcSignerLibPaymentTypeIdentifers, type BtcSignerNetwork, type BtcSignerTapBip32Derivation, type CoinSelectionOutput, type CoinSelectionRecipient, type CoinSelectionUtxo, type DetermineUtxosForSpendArgs, type GenerateBitcoinUnsignedTransactionArgs, type GetBitcoinFeesArgs, type PaymentTypeMap, type SupportedPaymentType, type SupportedPaymentTypeMap, type WithDerivePayer, bip322TransactionToSignValues, bitcoinNetworkModeToCoreNetworkMode, bitcoinNetworkToCoreNetworkMap, btcSignerLibPaymentTypeToPaymentTypeMap, calculateMaxBitcoinSpend, coinTypeMap, createNativeSegwitBitcoinJsSigner, createTaprootBitcoinJsSigner, createToSpendTx, createWalletIdDecoratedPath, decodeBitcoinTx, decodeCompressedWifPrivateKey, deriveAddressIndexKeychainFromAccount, deriveAddressIndexZeroFromAccount, deriveBitcoinPayerFromAccount, deriveBtcBip49SeedFromMnemonic, deriveNativeSegwitAccountFromRootKeychain, deriveNativeSegwitReceiveAddressIndexZero, deriveRootBtcKeychain, deriveTaprootAccount, deriveTaprootReceiveAddressIndexZero, determineUtxosForSpend, determineUtxosForSpendAll, ecPairFromPrivateKey, ecdsaPublicKeyLength, ecdsaPublicKeyToSchnorr, encodeMessageWitnessData, extractExtendedPublicKeyFromPolicy, extractRequiredKeyOrigins, filterUneconomicalUtxos, generateBitcoinUnsignedTransactionNativeSegwit, getAddressFromOutScript, getBitcoinCoinTypeIndexByNetwork, getBitcoinFees, getBitcoinInputAddress, getBitcoinJsLibNetworkConfigByMode, getBitcoinTransactionFee, getBtcSignerLibNetworkConfigByMode, getHdKeyVersionsFromNetwork, getInputPaymentType, getNativeSegwitAccountDerivationPath, getNativeSegwitAddress, getNativeSegwitAddressIndexDerivationPath, getNativeSegwitPaymentFromAddressIndex, getPsbtTxInputs, getPsbtTxOutputs, getSizeInfo, getSpendableAmount, getTaprootAccountDerivationPath, getTaprootAddress, getTaprootAddressIndexDerivationPath, getTaprootPayment, getTaprootPaymentFromAddressIndex, getUtxoTotal, hashBip322Message, inferNetworkFromAddress, inferNetworkFromPath, inferPaymentTypeFromAddress, inferPaymentTypeFromPath, initBitcoinAccount, initializeBitcoinAccountKeychainFromDescriptor, isBtcSignerLibPaymentType, isSupportedMessageSigningPaymentType, lookUpLedgerKeysByPath, lookupDerivationByAddress, makeNativeSegwitAccountDerivationPath, makeNativeSegwitAddressIndexDerivationPath, makePayToScriptHashAddress, makePayToScriptHashAddressBytes, makePayToScriptHashKeyHash, makeTaprootAccountDerivationPath, makeTaprootAddressIndexDerivationPath, mnemonicToRootNode, parseKnownPaymentType, payToScriptHashTestnetPrefix, payerToBip32Derivation, payerToTapBip32Derivation, paymentTypeMap, publicKeyToPayToScriptHashAddress, serializeKeyOrigin, signBip322MessageSimple, toXOnly, tweakSigner, whenBitcoinNetwork, whenPaymentType, whenSupportedPaymentType };
|