@leather.io/bitcoin 0.19.28 → 0.19.30

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.
Files changed (47) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/CHANGELOG.md +29 -0
  3. package/dist/index.d.ts +197 -148
  4. package/dist/index.js +341 -205
  5. package/dist/index.js.map +1 -1
  6. package/package.json +8 -8
  7. package/src/bip322/bip322-utils.ts +1 -1
  8. package/src/bip322/sign-message-bip322-bitcoinjs.ts +8 -3
  9. package/src/bip322/sign-message-bip322.spec.ts +13 -13
  10. package/src/coin-selection/calculate-max-spend.spec.ts +19 -17
  11. package/src/coin-selection/calculate-max-spend.ts +26 -16
  12. package/src/coin-selection/coin-selection.spec.ts +29 -26
  13. package/src/coin-selection/coin-selection.ts +1 -1
  14. package/src/coin-selection/coin-selection.utils.spec.ts +2 -1
  15. package/src/coin-selection/coin-selection.utils.ts +5 -8
  16. package/src/fees/bitcoin-fees.spec.ts +7 -10
  17. package/src/index.ts +21 -9
  18. package/src/mocks/mocks.ts +39 -0
  19. package/src/{p2tr-address-gen.spec.ts → payments/p2tr-address-gen.spec.ts} +1 -1
  20. package/src/{p2tr-address-gen.ts → payments/p2tr-address-gen.ts} +2 -2
  21. package/src/{p2wpkh-address-gen.ts → payments/p2wpkh-address-gen.ts} +2 -2
  22. package/src/psbt/psbt-details.ts +3 -3
  23. package/src/psbt/psbt-inputs.ts +9 -6
  24. package/src/psbt/psbt-outputs.ts +10 -7
  25. package/src/psbt/psbt-totals.ts +3 -3
  26. package/src/{bitcoin-signer.ts → signer/bitcoin-signer.ts} +6 -5
  27. package/src/transactions/generate-unsigned-transaction.spec.ts +1 -1
  28. package/src/transactions/generate-unsigned-transaction.ts +3 -3
  29. package/src/{bitcoin.network.ts → utils/bitcoin.network.ts} +2 -0
  30. package/src/{bitcoin.utils.spec.ts → utils/bitcoin.utils.spec.ts} +19 -14
  31. package/src/{bitcoin.utils.ts → utils/bitcoin.utils.ts} +19 -13
  32. package/src/{lookup-derivation-by-address.spec.ts → utils/lookup-derivation-by-address.spec.ts} +11 -6
  33. package/src/{lookup-derivation-by-address.ts → utils/lookup-derivation-by-address.ts} +4 -3
  34. package/src/validation/address-validation.spec.ts +396 -0
  35. package/src/validation/address-validation.ts +28 -0
  36. package/src/validation/amount-validation.spec.ts +39 -0
  37. package/src/validation/amount-validation.ts +31 -0
  38. package/src/validation/bitcoin-address.ts +23 -0
  39. package/src/{bitcoin-error.ts → validation/bitcoin-error.ts} +4 -2
  40. package/src/validation/transaction-validation.spec.ts +60 -0
  41. package/src/validation/transaction-validation.ts +46 -0
  42. /package/src/{btc-size-fee-estimator.spec.ts → fees/btc-size-fee-estimator.spec.ts} +0 -0
  43. /package/src/{btc-size-fee-estimator.ts → fees/btc-size-fee-estimator.ts} +0 -0
  44. /package/src/{p2wpkh-address-gen.spec.ts → payments/p2wpkh-address-gen.spec.ts} +0 -0
  45. /package/src/{p2wsh-p2sh-address-gen.spec.ts → payments/p2wsh-p2sh-address-gen.spec.ts} +0 -0
  46. /package/src/{p2wsh-p2sh-address-gen.ts → payments/p2wsh-p2sh-address-gen.ts} +0 -0
  47. /package/src/{bitcoin-signer.spec.ts → signer/bitcoin-signer.spec.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
 
2
- > @leather.io/bitcoin@0.19.28 build /home/runner/work/mono/mono/packages/bitcoin
2
+ > @leather.io/bitcoin@0.19.30 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 49.51 KB
12
- ESM dist/index.js.map 97.47 KB
13
- ESM ⚡️ Build success in 78ms
11
+ ESM dist/index.js 53.95 KB
12
+ ESM dist/index.js.map 106.90 KB
13
+ ESM ⚡️ Build success in 72ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 4901ms
16
- DTS dist/index.d.ts 23.09 KB
15
+ DTS ⚡️ Build success in 5548ms
16
+ DTS dist/index.d.ts 26.02 KB
package/CHANGELOG.md CHANGED
@@ -537,6 +537,35 @@
537
537
  * devDependencies
538
538
  * @leather.io/rpc bumped to 2.6.0
539
539
 
540
+ ### Dependencies
541
+
542
+ * The following workspace dependencies were updated
543
+ * dependencies
544
+ * @leather.io/constants bumped to 0.17.0
545
+ * @leather.io/crypto bumped to 1.6.42
546
+ * @leather.io/utils bumped to 0.27.2
547
+ * devDependencies
548
+ * @leather.io/rpc bumped to 2.6.1
549
+
550
+ ## [0.19.30](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.19.29...@leather.io/bitcoin-v0.19.30) (2025-02-21)
551
+
552
+
553
+ ### Bug Fixes
554
+
555
+ * block vitest remote code execution ([c00abaf](https://github.com/leather-io/mono/commit/c00abaf33668b3274825dad886feb6dfadb1d9b1))
556
+
557
+
558
+ ### Dependencies
559
+
560
+ * The following workspace dependencies were updated
561
+ * dependencies
562
+ * @leather.io/constants bumped to 0.17.1
563
+ * @leather.io/crypto bumped to 1.6.43
564
+ * @leather.io/models bumped to 0.26.1
565
+ * @leather.io/utils bumped to 0.27.3
566
+ * devDependencies
567
+ * @leather.io/rpc bumped to 2.6.2
568
+
540
569
  ## [0.19.10](https://github.com/leather-io/mono/compare/@leather.io/bitcoin-v0.19.9...@leather.io/bitcoin-v0.19.10) (2025-01-07)
541
570
 
542
571
 
package/dist/index.d.ts CHANGED
@@ -2,15 +2,16 @@ import * as ecpair from 'ecpair';
2
2
  import * as bitcoin from 'bitcoinjs-lib';
3
3
  import * as btc from '@scure/btc-signer';
4
4
  import * as _leather_io_models from '@leather.io/models';
5
- import { BitcoinNetworkModes, Money, AverageBitcoinFeeRates, NetworkModes, ValueOf, Inscription } from '@leather.io/models';
5
+ import { BitcoinNetworkModes, Money, AverageBitcoinFeeRates, NetworkModes, Inscription, ValueOf } from '@leather.io/models';
6
6
  import BigNumber from 'bignumber.js';
7
- import { HDKey, Versions } from '@scure/bip32';
8
7
  import * as _scure_btc_signer_payment from '@scure/btc-signer/payment';
9
8
  import { P2Ret, P2TROut } from '@scure/btc-signer/payment';
10
- import { SigHash } from '@scure/btc-signer/transaction';
11
- import { PaymentTypes, signatureHash } from '@leather.io/rpc';
9
+ import { HDKey, Versions } from '@scure/bip32';
12
10
  import { TransactionInput, TransactionOutput, RawPSBTV0 } from '@scure/btc-signer/psbt';
11
+ import { BitcoinPaymentTypes, signatureHash, PaymentTypes } from '@leather.io/rpc';
13
12
  import { deriveBip39SeedFromMnemonic, deriveRootBip32Keychain } from '@leather.io/crypto';
13
+ import { SigHash } from '@scure/btc-signer/transaction';
14
+ import { Network } from 'bitcoin-address-validation';
14
15
 
15
16
  declare function ecPairFromPrivateKey(key: Uint8Array): ecpair.ECPairInterface;
16
17
  declare function hashBip322Message(message: Uint8Array | string): Uint8Array;
@@ -27,14 +28,20 @@ declare function isSupportedMessageSigningPaymentType(paymentType: string): bool
27
28
  declare function encodeMessageWitnessData(witnessArray: Buffer[]): Buffer;
28
29
  declare function tweakSigner(signer: bitcoin.Signer, opts?: any): bitcoin.Signer;
29
30
 
31
+ type BitcoinAddress = string & {
32
+ readonly __brand: unique symbol;
33
+ };
34
+ declare function isBitcoinAddress(value: string): value is BitcoinAddress;
35
+ declare function createBitcoinAddress(value: string): BitcoinAddress;
36
+
30
37
  declare function createNativeSegwitBitcoinJsSigner(privateKey: Buffer): ecpair.ECPairInterface;
31
38
  declare function createTaprootBitcoinJsSigner(privateKey: Buffer): bitcoin.Signer;
32
- declare function createToSpendTx(address: string, message: string, network: BitcoinNetworkModes): {
39
+ declare function createToSpendTx(address: BitcoinAddress, message: string, network: BitcoinNetworkModes): {
33
40
  virtualToSpend: bitcoin.Transaction;
34
41
  script: Buffer;
35
42
  };
36
43
  interface SignBip322MessageSimple {
37
- address: string;
44
+ address: BitcoinAddress;
38
45
  message: string;
39
46
  network: BitcoinNetworkModes;
40
47
  signPsbt(psbt: bitcoin.Psbt): Promise<btc.Transaction>;
@@ -85,17 +92,18 @@ declare function determineUtxosForSpend({ feeRate, recipients, utxos }: Determin
85
92
  fee: Money;
86
93
  };
87
94
 
88
- interface CalculateMaxBitcoinSpend {
89
- address: string;
95
+ interface CalculateMaxSpendArgs {
96
+ recipient: BitcoinAddress;
90
97
  utxos: CoinSelectionUtxo[];
91
- fetchedFeeRates?: AverageBitcoinFeeRates;
98
+ feeRates?: AverageBitcoinFeeRates;
92
99
  feeRate?: number;
93
100
  }
94
- declare function calculateMaxBitcoinSpend({ address, utxos, feeRate, fetchedFeeRates, }: CalculateMaxBitcoinSpend): {
101
+ interface CalculateMaxSpendResponse {
95
102
  spendAllFee: number;
96
- amount: _leather_io_models.Money;
97
- spendableBitcoin: BigNumber;
98
- };
103
+ amount: Money;
104
+ spendableBtc: BigNumber;
105
+ }
106
+ declare function calculateMaxSpend({ recipient, utxos, feeRate, feeRates, }: CalculateMaxSpendArgs): CalculateMaxSpendResponse;
99
107
 
100
108
  declare function getUtxoTotal(utxos: CoinSelectionUtxo[]): BigNumber;
101
109
  declare function getSizeInfo(payload: {
@@ -107,11 +115,13 @@ declare function getSizeInfo(payload: {
107
115
  txBytes: number;
108
116
  txWeight: number;
109
117
  };
110
- declare function getSpendableAmount({ utxos, feeRate, recipients, }: {
118
+ interface GetSpendableAmountArgs {
111
119
  utxos: CoinSelectionUtxo[];
112
120
  feeRate: number;
113
121
  recipients: CoinSelectionRecipient[];
114
- }): {
122
+ isSendMax?: boolean;
123
+ }
124
+ declare function getSpendableAmount({ utxos, feeRate, recipients }: GetSpendableAmountArgs): {
115
125
  spendableAmount: BigNumber;
116
126
  fee: number;
117
127
  };
@@ -161,6 +171,20 @@ declare function getBitcoinFees({ feeRates, isSendingMax, recipients, utxos }: G
161
171
  };
162
172
  };
163
173
 
174
+ declare const TEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS: BitcoinAddress;
175
+ declare const TEST_ACCOUNT_1_TAPROOT_ADDRESS: BitcoinAddress;
176
+ declare const TEST_ACCOUNT_2_TAPROOT_ADDRESS: BitcoinAddress;
177
+ declare const TEST_TESNET_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS: BitcoinAddress;
178
+ declare const TEST_TESTNET_ACCOUNT_2_BTC_ADDRESS: BitcoinAddress;
179
+ declare const TEST_TESTNET_ACCOUNT_2_TAPROOT_ADDRESS: BitcoinAddress;
180
+ declare const recipientAddress: BitcoinAddress;
181
+ declare const legacyAddress: BitcoinAddress;
182
+ declare const segwitAddress: BitcoinAddress;
183
+ declare const taprootAddress: BitcoinAddress;
184
+ declare const invalidAddress = "whoop-de-da-boop-da-de-not-a-bitcoin-address";
185
+ declare const inValidCharactersAddress: BitcoinAddress;
186
+ declare const inValidLengthAddress: BitcoinAddress;
187
+
164
188
  interface BtcSignerNetwork {
165
189
  bech32: string;
166
190
  pubKeyHash: number;
@@ -171,7 +195,7 @@ declare function getBtcSignerLibNetworkConfigByMode(network: BitcoinNetworkModes
171
195
  declare function getBitcoinJsLibNetworkConfigByMode(network: BitcoinNetworkModes): bitcoin.networks.Network;
172
196
 
173
197
  interface BitcoinAccount {
174
- type: PaymentTypes;
198
+ type: BitcoinPaymentTypes;
175
199
  derivationPath: string;
176
200
  keychain: HDKey;
177
201
  accountIndex: number;
@@ -206,12 +230,12 @@ declare function getAddressFromOutScript(script: Uint8Array, bitcoinNetwork: Btc
206
230
  * Payment type identifiers, as described by `@scure/btc-signer` library
207
231
  */
208
232
  type BtcSignerLibPaymentTypeIdentifers = 'wpkh' | 'wsh' | 'tr' | 'pkh' | 'sh';
209
- declare const paymentTypeMap: Record<BtcSignerLibPaymentTypeIdentifers, PaymentTypes>;
233
+ declare const paymentTypeMap: Record<BtcSignerLibPaymentTypeIdentifers, BitcoinPaymentTypes>;
210
234
  declare function btcSignerLibPaymentTypeToPaymentTypeMap(payment: BtcSignerLibPaymentTypeIdentifers): "p2tr" | "p2pkh" | "p2sh" | "p2wpkh-p2sh" | "p2wpkh";
211
235
  declare function isBtcSignerLibPaymentType(payment: string): payment is BtcSignerLibPaymentTypeIdentifers;
212
- declare function parseKnownPaymentType(payment: BtcSignerLibPaymentTypeIdentifers | PaymentTypes): "p2tr" | "p2pkh" | "p2sh" | "p2wpkh-p2sh" | "p2wpkh";
213
- type PaymentTypeMap<T> = Record<PaymentTypes, T>;
214
- declare function whenPaymentType(mode: PaymentTypes | BtcSignerLibPaymentTypeIdentifers): <T>(paymentMap: PaymentTypeMap<T>) => T;
236
+ declare function parseKnownPaymentType(payment: BtcSignerLibPaymentTypeIdentifers | BitcoinPaymentTypes): "p2tr" | "p2pkh" | "p2sh" | "p2wpkh-p2sh" | "p2wpkh";
237
+ type PaymentTypeMap<T> = Record<BitcoinPaymentTypes, T>;
238
+ declare function whenPaymentType(mode: BitcoinPaymentTypes | BtcSignerLibPaymentTypeIdentifers): <T>(paymentMap: PaymentTypeMap<T>) => T;
215
239
  type SupportedPaymentType = 'p2wpkh' | 'p2tr';
216
240
  type SupportedPaymentTypeMap<T> = Record<SupportedPaymentType, T>;
217
241
  declare function whenSupportedPaymentType(mode: SupportedPaymentType): <T>(paymentMap: SupportedPaymentTypeMap<T>) => T;
@@ -221,13 +245,13 @@ declare function whenSupportedPaymentType(mode: SupportedPaymentType): <T>(payme
221
245
  * @example
222
246
  * `m/86'/1'/0'/0/0`
223
247
  */
224
- declare function inferPaymentTypeFromPath(path: string): PaymentTypes;
248
+ declare function inferPaymentTypeFromPath(path: string): BitcoinPaymentTypes;
225
249
  declare function inferNetworkFromPath(path: string): NetworkModes;
226
250
  declare function extractExtendedPublicKeyFromPolicy(policy: string): string;
227
251
  declare function createWalletIdDecoratedPath(policy: string, walletId: string): string;
228
252
  declare function getHdKeyVersionsFromNetwork(network: NetworkModes): Versions | undefined;
229
253
  declare function getBitcoinInputAddress(input: TransactionInput, bitcoinNetwork: BtcSignerNetwork): string;
230
- declare function getInputPaymentType(input: TransactionInput, network: BitcoinNetworkModes): PaymentTypes;
254
+ declare function getInputPaymentType(input: TransactionInput, network: BitcoinNetworkModes): BitcoinPaymentTypes;
231
255
  declare function lookUpLedgerKeysByPath(getDerivationPath: (network: BitcoinNetworkModes, accountIndex: number) => string): (ledgerKeyMap: Record<string, {
232
256
  policy: string;
233
257
  } | undefined>, network: BitcoinNetworkModes) => (accountIndex: number) => BitcoinAccount | undefined;
@@ -245,10 +269,132 @@ declare function getNativeSegwitAddress({ index, keychain, network }: GetAddress
245
269
  declare function mnemonicToRootNode(secretKey: string): HDKey;
246
270
  declare function getPsbtTxInputs(psbtTx: btc.Transaction): TransactionInput[];
247
271
  declare function getPsbtTxOutputs(psbtTx: btc.Transaction): TransactionOutput[];
248
- declare function inferNetworkFromAddress(address: string): BitcoinNetworkModes;
249
- declare function inferPaymentTypeFromAddress(address: string): SupportedPaymentType;
272
+ declare function inferNetworkFromAddress(address: BitcoinAddress): BitcoinNetworkModes;
273
+ declare function inferPaymentTypeFromAddress(address: BitcoinAddress): SupportedPaymentType;
250
274
  declare function getBitcoinInputValue(input: TransactionInput): number;
251
275
 
276
+ declare function makeTaprootAccountDerivationPath(network: BitcoinNetworkModes, accountIndex: number): string;
277
+ /** @deprecated Use makeTaprootAccountDerivationPath */
278
+ declare const getTaprootAccountDerivationPath: typeof makeTaprootAccountDerivationPath;
279
+ declare function makeTaprootAddressIndexDerivationPath(network: BitcoinNetworkModes, accountIndex: number, addressIndex: number): string;
280
+ /** @deprecated Use makeTaprootAddressIndexDerivationPath */
281
+ declare const getTaprootAddressIndexDerivationPath: typeof makeTaprootAddressIndexDerivationPath;
282
+ declare function deriveTaprootAccount(keychain: HDKey, network: BitcoinNetworkModes): (accountIndex: number) => BitcoinAccount;
283
+ declare function getTaprootPayment(publicKey: Uint8Array, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2TROut;
284
+ declare function getTaprootPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2TROut;
285
+ interface DeriveTaprootReceiveAddressIndexArgs {
286
+ keychain: HDKey;
287
+ network: BitcoinNetworkModes;
288
+ }
289
+ declare function deriveTaprootReceiveAddressIndexZero({ keychain, network, }: DeriveTaprootReceiveAddressIndexArgs): {
290
+ keychain: HDKey;
291
+ payment: _scure_btc_signer_payment.P2TROut;
292
+ };
293
+
294
+ declare function makeNativeSegwitAccountDerivationPath(network: BitcoinNetworkModes, accountIndex: number): string;
295
+ /** @deprecated Use makeNativeSegwitAccountDerivationPath */
296
+ declare const getNativeSegwitAccountDerivationPath: typeof makeNativeSegwitAccountDerivationPath;
297
+ declare function makeNativeSegwitAddressIndexDerivationPath(network: BitcoinNetworkModes, accountIndex: number, addressIndex: number): string;
298
+ /** @deprecated Use makeNativeSegwitAddressIndexDerivationPath */
299
+ declare const getNativeSegwitAddressIndexDerivationPath: typeof makeNativeSegwitAddressIndexDerivationPath;
300
+ declare function deriveNativeSegwitAccountFromRootKeychain(keychain: HDKey, network: BitcoinNetworkModes): (accountIndex: number) => BitcoinAccount;
301
+ declare function getNativeSegwitPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2Ret;
302
+ interface DeriveNativeSegwitReceiveAddressIndexArgs {
303
+ keychain: HDKey;
304
+ network: BitcoinNetworkModes;
305
+ }
306
+ declare function deriveNativeSegwitReceiveAddressIndexZero({ keychain, network, }: DeriveNativeSegwitReceiveAddressIndexArgs): {
307
+ keychain: HDKey;
308
+ payment: _scure_btc_signer_payment.P2Ret;
309
+ };
310
+
311
+ /**
312
+ * @deprecated
313
+ * Use `deriveBip39MnemonicFromSeed` from `@leather.io/crypto`
314
+ */
315
+ declare const deriveBtcBip49SeedFromMnemonic: typeof deriveBip39SeedFromMnemonic;
316
+ /**
317
+ * @deprecated
318
+ * Use `deriveRootBip32Keychain` from `@leather.io/crypto`
319
+ */
320
+ declare const deriveRootBtcKeychain: typeof deriveRootBip32Keychain;
321
+ declare function decodeCompressedWifPrivateKey(key: string): Uint8Array;
322
+ declare const payToScriptHashTestnetPrefix = 196;
323
+ declare function makePayToScriptHashKeyHash(publicKey: Uint8Array): Uint8Array;
324
+ declare function makePayToScriptHashAddressBytes(keyHash: Uint8Array): Uint8Array;
325
+ declare function makePayToScriptHashAddress(addressBytes: Uint8Array, network: NetworkModes): string;
326
+ declare function publicKeyToPayToScriptHashAddress(publicKey: Uint8Array, network: NetworkModes): string;
327
+
328
+ interface PsbtInput {
329
+ address: BitcoinAddress;
330
+ index?: number;
331
+ inscription?: Inscription;
332
+ isMutable: boolean;
333
+ toSign: boolean;
334
+ txid: string;
335
+ value: number;
336
+ bip32Derivation: TransactionInput['bip32Derivation'];
337
+ tapBip32Derivation: TransactionInput['tapBip32Derivation'];
338
+ }
339
+ interface GetParsedInputsArgs {
340
+ inputs: TransactionInput[];
341
+ indexesToSign?: number[];
342
+ networkMode: BitcoinNetworkModes;
343
+ psbtAddresses: BitcoinAddress[];
344
+ }
345
+ interface GetParsedInputsResponse {
346
+ isPsbtMutable: boolean;
347
+ parsedInputs: PsbtInput[];
348
+ }
349
+ declare function getParsedInputs({ inputs, indexesToSign, networkMode, psbtAddresses, }: GetParsedInputsArgs): GetParsedInputsResponse;
350
+
351
+ interface PsbtOutput {
352
+ address: BitcoinAddress;
353
+ isMutable: boolean;
354
+ toSign: boolean;
355
+ value: number;
356
+ }
357
+ interface GetParsedOutputsArgs {
358
+ isPsbtMutable: boolean;
359
+ outputs: TransactionOutput[];
360
+ networkMode: BitcoinNetworkModes;
361
+ psbtAddresses: BitcoinAddress[];
362
+ }
363
+ declare function getParsedOutputs({ isPsbtMutable, outputs, networkMode, psbtAddresses, }: GetParsedOutputsArgs): PsbtOutput[];
364
+
365
+ interface GetPsbtTotalsProps {
366
+ psbtAddresses: BitcoinAddress[];
367
+ parsedInputs: PsbtInput[];
368
+ parsedOutputs: PsbtOutput[];
369
+ }
370
+ declare function getPsbtTotals({ psbtAddresses, parsedInputs, parsedOutputs }: GetPsbtTotalsProps): {
371
+ inputsTotalNativeSegwit: _leather_io_models.Money;
372
+ inputsTotalTaproot: _leather_io_models.Money;
373
+ outputsTotalNativeSegwit: _leather_io_models.Money;
374
+ outputsTotalTaproot: _leather_io_models.Money;
375
+ psbtInputsTotal: _leather_io_models.Money;
376
+ psbtOutputsTotal: _leather_io_models.Money;
377
+ };
378
+
379
+ interface GetPsbtDetailsArgs {
380
+ psbtHex: string;
381
+ psbtAddresses: BitcoinAddress[];
382
+ networkMode: BitcoinNetworkModes;
383
+ indexesToSign?: number[];
384
+ }
385
+ declare function getPsbtDetails({ psbtHex, networkMode, indexesToSign, psbtAddresses, }: GetPsbtDetailsArgs): {
386
+ addressNativeSegwitTotal: _leather_io_models.Money;
387
+ addressTaprootTotal: _leather_io_models.Money;
388
+ fee: _leather_io_models.Money;
389
+ isPsbtMutable: boolean;
390
+ psbtInputs: PsbtInput[];
391
+ psbtOutputs: PsbtOutput[];
392
+ };
393
+
394
+ type RawPsbt = ReturnType<typeof RawPSBTV0.decode>;
395
+ declare function getPsbtAsTransaction(psbt: string | Uint8Array): btc.Transaction;
396
+ declare function getRawPsbt(psbt: string | Uint8Array): ReturnType<typeof RawPSBTV0.decode>;
397
+
252
398
  type AllowedSighashTypes = ValueOf<typeof signatureHash> | SigHash;
253
399
  interface BitcoinAccountKeychain {
254
400
  descriptor: string;
@@ -265,7 +411,7 @@ interface BitcoinSigner<Payment> {
265
411
  payment: Payment;
266
412
  keychain: HDKey;
267
413
  derivationPath: string;
268
- address: string;
414
+ address: BitcoinAddress;
269
415
  publicKey: Uint8Array;
270
416
  sign(tx: btc.Transaction): void;
271
417
  signIndex(tx: btc.Transaction, index: number, allowedSighash?: AllowedSighashTypes[]): void;
@@ -273,7 +419,7 @@ interface BitcoinSigner<Payment> {
273
419
  interface BitcoinPayerBase {
274
420
  paymentType: PaymentTypes;
275
421
  network: BitcoinNetworkModes;
276
- address: string;
422
+ address: BitcoinAddress;
277
423
  keyOrigin: string;
278
424
  masterKeyFingerprint: string;
279
425
  publicKey: Uint8Array;
@@ -371,70 +517,43 @@ declare function generateBitcoinUnsignedTransactionNativeSegwit({ feeRate, isSen
371
517
  fee: _leather_io_models.Money;
372
518
  };
373
519
 
520
+ declare function getBitcoinAddressNetworkType(network: BitcoinNetworkModes): Network;
521
+ declare function isValidBitcoinAddress(address: string): boolean;
522
+ declare function isValidBitcoinNetworkAddress(address: string, network: BitcoinNetworkModes): boolean;
523
+
524
+ declare const minSpendAmountInSats = 546;
525
+ interface isBtcBalanceSufficientArgs {
526
+ amount: Money;
527
+ spendableBtc: BigNumber;
528
+ }
529
+ declare function isBtcBalanceSufficient({ amount: { amount }, spendableBtc, }: isBtcBalanceSufficientArgs): boolean;
530
+ interface IsBtcMinimumSpendArgs {
531
+ amount: Money;
532
+ }
533
+ declare function isBtcMinimumSpend({ amount: { amount } }: IsBtcMinimumSpendArgs): boolean;
534
+
535
+ type TransactionErrorKey = 'InvalidAddress' | 'InsufficientFunds' | 'InvalidNetworkAddress';
374
536
  declare class BitcoinError extends Error {
375
537
  message: BitcoinErrorKey;
376
538
  constructor(message: BitcoinErrorKey);
377
539
  }
378
- type BitcoinErrorKey = 'InvalidAddress' | 'InsufficientFunds' | 'NoInputsToSign' | 'NoOutputsToSign';
379
-
380
- declare function makeTaprootAccountDerivationPath(network: BitcoinNetworkModes, accountIndex: number): string;
381
- /** @deprecated Use makeTaprootAccountDerivationPath */
382
- declare const getTaprootAccountDerivationPath: typeof makeTaprootAccountDerivationPath;
383
- declare function makeTaprootAddressIndexDerivationPath(network: BitcoinNetworkModes, accountIndex: number, addressIndex: number): string;
384
- /** @deprecated Use makeTaprootAddressIndexDerivationPath */
385
- declare const getTaprootAddressIndexDerivationPath: typeof makeTaprootAddressIndexDerivationPath;
386
- declare function deriveTaprootAccount(keychain: HDKey, network: BitcoinNetworkModes): (accountIndex: number) => BitcoinAccount;
387
- declare function getTaprootPayment(publicKey: Uint8Array, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2TROut;
388
- declare function getTaprootPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2TROut;
389
- interface DeriveTaprootReceiveAddressIndexArgs {
390
- keychain: HDKey;
391
- network: BitcoinNetworkModes;
392
- }
393
- declare function deriveTaprootReceiveAddressIndexZero({ keychain, network, }: DeriveTaprootReceiveAddressIndexArgs): {
394
- keychain: HDKey;
395
- payment: _scure_btc_signer_payment.P2TROut;
396
- };
540
+ type BitcoinErrorKey = TransactionErrorKey | 'InsufficientAmount' | 'NoInputsToSign' | 'NoOutputsToSign';
397
541
 
398
- declare function makeNativeSegwitAccountDerivationPath(network: BitcoinNetworkModes, accountIndex: number): string;
399
- /** @deprecated Use makeNativeSegwitAccountDerivationPath */
400
- declare const getNativeSegwitAccountDerivationPath: typeof makeNativeSegwitAccountDerivationPath;
401
- declare function makeNativeSegwitAddressIndexDerivationPath(network: BitcoinNetworkModes, accountIndex: number, addressIndex: number): string;
402
- /** @deprecated Use makeNativeSegwitAddressIndexDerivationPath */
403
- declare const getNativeSegwitAddressIndexDerivationPath: typeof makeNativeSegwitAddressIndexDerivationPath;
404
- declare function deriveNativeSegwitAccountFromRootKeychain(keychain: HDKey, network: BitcoinNetworkModes): (accountIndex: number) => BitcoinAccount;
405
- declare function getNativeSegwitPaymentFromAddressIndex(keychain: HDKey, network: BitcoinNetworkModes): _scure_btc_signer_payment.P2Ret;
406
- interface DeriveNativeSegwitReceiveAddressIndexArgs {
407
- keychain: HDKey;
542
+ interface BitcoinTransaction extends Omit<GetBitcoinFeesArgs, 'recipients'> {
543
+ amount: Money;
544
+ payer: BitcoinAddress;
545
+ recipient: BitcoinAddress;
408
546
  network: BitcoinNetworkModes;
547
+ feeRate: number;
409
548
  }
410
- declare function deriveNativeSegwitReceiveAddressIndexZero({ keychain, network, }: DeriveNativeSegwitReceiveAddressIndexArgs): {
411
- keychain: HDKey;
412
- payment: _scure_btc_signer_payment.P2Ret;
413
- };
414
-
415
- /**
416
- * @deprecated
417
- * Use `deriveBip39MnemonicFromSeed` from `@leather.io/crypto`
418
- */
419
- declare const deriveBtcBip49SeedFromMnemonic: typeof deriveBip39SeedFromMnemonic;
420
- /**
421
- * @deprecated
422
- * Use `deriveRootBip32Keychain` from `@leather.io/crypto`
423
- */
424
- declare const deriveRootBtcKeychain: typeof deriveRootBip32Keychain;
425
- declare function decodeCompressedWifPrivateKey(key: string): Uint8Array;
426
- declare const payToScriptHashTestnetPrefix = 196;
427
- declare function makePayToScriptHashKeyHash(publicKey: Uint8Array): Uint8Array;
428
- declare function makePayToScriptHashAddressBytes(keyHash: Uint8Array): Uint8Array;
429
- declare function makePayToScriptHashAddress(addressBytes: Uint8Array, network: NetworkModes): string;
430
- declare function publicKeyToPayToScriptHashAddress(publicKey: Uint8Array, network: NetworkModes): string;
549
+ declare function isValidBitcoinTransaction({ amount, payer, recipient, network, utxos, feeRate, feeRates, }: BitcoinTransaction): void;
431
550
 
432
551
  interface LookUpDerivationByAddressArgs {
433
552
  taprootXpub: string;
434
553
  nativeSegwitXpub: string;
435
554
  iterationLimit: number;
436
555
  }
437
- declare function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs): (address: string) => {
556
+ declare function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs): (address: BitcoinAddress) => {
438
557
  readonly status: "success";
439
558
  readonly duration: number;
440
559
  readonly path: string;
@@ -444,74 +563,4 @@ declare function lookupDerivationByAddress(args: LookUpDerivationByAddressArgs):
444
563
  readonly path?: undefined;
445
564
  };
446
565
 
447
- interface PsbtInput {
448
- address: string;
449
- index?: number;
450
- inscription?: Inscription;
451
- isMutable: boolean;
452
- toSign: boolean;
453
- txid: string;
454
- value: number;
455
- bip32Derivation: TransactionInput['bip32Derivation'];
456
- tapBip32Derivation: TransactionInput['tapBip32Derivation'];
457
- }
458
- interface GetParsedInputsArgs {
459
- inputs: TransactionInput[];
460
- indexesToSign?: number[];
461
- networkMode: BitcoinNetworkModes;
462
- psbtAddresses: string[];
463
- }
464
- interface GetParsedInputsResponse {
465
- isPsbtMutable: boolean;
466
- parsedInputs: PsbtInput[];
467
- }
468
- declare function getParsedInputs({ inputs, indexesToSign, networkMode, psbtAddresses, }: GetParsedInputsArgs): GetParsedInputsResponse;
469
-
470
- interface PsbtOutput {
471
- address: string;
472
- isMutable: boolean;
473
- toSign: boolean;
474
- value: number;
475
- }
476
- interface GetParsedOutputsArgs {
477
- isPsbtMutable: boolean;
478
- outputs: TransactionOutput[];
479
- networkMode: BitcoinNetworkModes;
480
- psbtAddresses: string[];
481
- }
482
- declare function getParsedOutputs({ isPsbtMutable, outputs, networkMode, psbtAddresses, }: GetParsedOutputsArgs): PsbtOutput[];
483
-
484
- interface GetPsbtTotalsProps {
485
- psbtAddresses: string[];
486
- parsedInputs: PsbtInput[];
487
- parsedOutputs: PsbtOutput[];
488
- }
489
- declare function getPsbtTotals({ psbtAddresses, parsedInputs, parsedOutputs }: GetPsbtTotalsProps): {
490
- inputsTotalNativeSegwit: _leather_io_models.Money;
491
- inputsTotalTaproot: _leather_io_models.Money;
492
- outputsTotalNativeSegwit: _leather_io_models.Money;
493
- outputsTotalTaproot: _leather_io_models.Money;
494
- psbtInputsTotal: _leather_io_models.Money;
495
- psbtOutputsTotal: _leather_io_models.Money;
496
- };
497
-
498
- interface GetPsbtDetailsArgs {
499
- psbtHex: string;
500
- psbtAddresses: string[];
501
- networkMode: BitcoinNetworkModes;
502
- indexesToSign?: number[];
503
- }
504
- declare function getPsbtDetails({ psbtHex, networkMode, indexesToSign, psbtAddresses, }: GetPsbtDetailsArgs): {
505
- addressNativeSegwitTotal: _leather_io_models.Money;
506
- addressTaprootTotal: _leather_io_models.Money;
507
- fee: _leather_io_models.Money;
508
- isPsbtMutable: boolean;
509
- psbtInputs: PsbtInput[];
510
- psbtOutputs: PsbtOutput[];
511
- };
512
-
513
- type RawPsbt = ReturnType<typeof RawPSBTV0.decode>;
514
- declare function getPsbtAsTransaction(psbt: string | Uint8Array): btc.Transaction;
515
- declare function getRawPsbt(psbt: string | Uint8Array): ReturnType<typeof RawPSBTV0.decode>;
516
-
517
- export { type AllowedSighashTypes, type BitcoinAccount, type BitcoinAccountKeychain, BitcoinError, type BitcoinErrorKey, 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 PsbtInput, type PsbtOutput, type RawPsbt, 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, getBitcoinInputValue, getBitcoinJsLibNetworkConfigByMode, getBitcoinTransactionFee, getBtcSignerLibNetworkConfigByMode, getHdKeyVersionsFromNetwork, getInputPaymentType, getNativeSegwitAccountDerivationPath, getNativeSegwitAddress, getNativeSegwitAddressIndexDerivationPath, getNativeSegwitPaymentFromAddressIndex, getParsedInputs, getParsedOutputs, getPsbtAsTransaction, getPsbtDetails, getPsbtTotals, getPsbtTxInputs, getPsbtTxOutputs, getRawPsbt, 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 };
566
+ export { type AllowedSighashTypes, type BitcoinAccount, type BitcoinAccountKeychain, type BitcoinAddress, BitcoinError, type BitcoinErrorKey, 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 PsbtInput, type PsbtOutput, type RawPsbt, type SupportedPaymentType, type SupportedPaymentTypeMap, TEST_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS, TEST_ACCOUNT_1_TAPROOT_ADDRESS, TEST_ACCOUNT_2_TAPROOT_ADDRESS, TEST_TESNET_ACCOUNT_1_NATIVE_SEGWIT_ADDRESS, TEST_TESTNET_ACCOUNT_2_BTC_ADDRESS, TEST_TESTNET_ACCOUNT_2_TAPROOT_ADDRESS, type WithDerivePayer, bip322TransactionToSignValues, bitcoinNetworkModeToCoreNetworkMode, bitcoinNetworkToCoreNetworkMap, btcSignerLibPaymentTypeToPaymentTypeMap, calculateMaxSpend, coinTypeMap, createBitcoinAddress, 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, getBitcoinAddressNetworkType, getBitcoinCoinTypeIndexByNetwork, getBitcoinFees, getBitcoinInputAddress, getBitcoinInputValue, getBitcoinJsLibNetworkConfigByMode, getBitcoinTransactionFee, getBtcSignerLibNetworkConfigByMode, getHdKeyVersionsFromNetwork, getInputPaymentType, getNativeSegwitAccountDerivationPath, getNativeSegwitAddress, getNativeSegwitAddressIndexDerivationPath, getNativeSegwitPaymentFromAddressIndex, getParsedInputs, getParsedOutputs, getPsbtAsTransaction, getPsbtDetails, getPsbtTotals, getPsbtTxInputs, getPsbtTxOutputs, getRawPsbt, getSizeInfo, getSpendableAmount, getTaprootAccountDerivationPath, getTaprootAddress, getTaprootAddressIndexDerivationPath, getTaprootPayment, getTaprootPaymentFromAddressIndex, getUtxoTotal, hashBip322Message, inValidCharactersAddress, inValidLengthAddress, inferNetworkFromAddress, inferNetworkFromPath, inferPaymentTypeFromAddress, inferPaymentTypeFromPath, initBitcoinAccount, initializeBitcoinAccountKeychainFromDescriptor, invalidAddress, isBitcoinAddress, isBtcBalanceSufficient, isBtcMinimumSpend, isBtcSignerLibPaymentType, isSupportedMessageSigningPaymentType, isValidBitcoinAddress, isValidBitcoinNetworkAddress, isValidBitcoinTransaction, legacyAddress, lookUpLedgerKeysByPath, lookupDerivationByAddress, makeNativeSegwitAccountDerivationPath, makeNativeSegwitAddressIndexDerivationPath, makePayToScriptHashAddress, makePayToScriptHashAddressBytes, makePayToScriptHashKeyHash, makeTaprootAccountDerivationPath, makeTaprootAddressIndexDerivationPath, minSpendAmountInSats, mnemonicToRootNode, parseKnownPaymentType, payToScriptHashTestnetPrefix, payerToBip32Derivation, payerToTapBip32Derivation, paymentTypeMap, publicKeyToPayToScriptHashAddress, recipientAddress, segwitAddress, serializeKeyOrigin, signBip322MessageSimple, taprootAddress, toXOnly, tweakSigner, whenBitcoinNetwork, whenPaymentType, whenSupportedPaymentType };