@leather.io/bitcoin 0.17.0 → 0.18.1

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @leather.io/bitcoin@0.17.0 build /home/runner/work/mono/mono/packages/bitcoin
2
+ > @leather.io/bitcoin@0.18.1 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 25.37 KB
12
- ESM dist/index.js.map 49.31 KB
13
- ESM ⚡️ Build success in 39ms
11
+ ESM dist/index.js 43.72 KB
12
+ ESM dist/index.js.map 84.58 KB
13
+ ESM ⚡️ Build success in 52ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 4101ms
16
- DTS dist/index.d.ts 16.04 KB
15
+ DTS ⚡️ Build success in 4068ms
16
+ DTS dist/index.d.ts 20.41 KB
package/CHANGELOG.md CHANGED
@@ -310,6 +310,36 @@
310
310
  * devDependencies
311
311
  * @leather.io/rpc bumped to 2.1.20
312
312
 
313
+ ### Dependencies
314
+
315
+ * The following workspace dependencies were updated
316
+ * dependencies
317
+ * @leather.io/constants bumped to 0.13.7
318
+ * @leather.io/crypto bumped to 1.6.16
319
+ * @leather.io/models bumped to 0.24.0
320
+ * @leather.io/utils bumped to 0.21.0
321
+ * devDependencies
322
+ * @leather.io/rpc bumped to 2.1.22
323
+
324
+ ## [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)
325
+
326
+
327
+ ### Features
328
+
329
+ * migrate bitcoin generate txs, closes LEA-1735 ([44fd6cf](https://github.com/leather-io/mono/commit/44fd6cfd29a2016b38d96b4e80e377ae7eae81df))
330
+
331
+
332
+ ### Dependencies
333
+
334
+ * The following workspace dependencies were updated
335
+ * dependencies
336
+ * @leather.io/constants bumped to 0.13.6
337
+ * @leather.io/crypto bumped to 1.6.15
338
+ * @leather.io/models bumped to 0.23.0
339
+ * @leather.io/utils bumped to 0.20.1
340
+ * devDependencies
341
+ * @leather.io/rpc bumped to 2.1.21
342
+
313
343
  ## [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)
314
344
 
315
345
 
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 { BitcoinNetworkModes, NetworkModes } from '@leather.io/models';
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 };