@ledgerhq/hw-app-btc 10.16.0-nightly.20260115024415 → 10.16.0-nightly.20260116124336
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/CHANGELOG.md +5 -3
- package/README.md +106 -56
- package/lib/Btc.d.ts +37 -0
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +30 -2
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +84 -0
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +326 -9
- package/lib/BtcNew.js.map +1 -1
- package/lib/createTransaction.d.ts.map +1 -1
- package/lib/createTransaction.js +3 -2
- package/lib/createTransaction.js.map +1 -1
- package/lib/getTrustedInputBIP143.d.ts +1 -2
- package/lib/getTrustedInputBIP143.d.ts.map +1 -1
- package/lib/getTrustedInputBIP143.js +1 -1
- package/lib/getTrustedInputBIP143.js.map +1 -1
- package/lib/newops/accounttype.d.ts +3 -3
- package/lib/newops/accounttype.d.ts.map +1 -1
- package/lib/newops/accounttype.js +15 -14
- package/lib/newops/accounttype.js.map +1 -1
- package/lib/newops/appClient.d.ts +1 -1
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +2 -2
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.d.ts +1 -1
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib/newops/merkelizedPsbt.js +1 -1
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/policy.js +2 -2
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.d.ts +1 -1
- package/lib/newops/psbtExtractor.d.ts.map +1 -1
- package/lib/newops/psbtExtractor.js +3 -3
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtFinalizer.d.ts +1 -1
- package/lib/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib/newops/psbtFinalizer.js +5 -6
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/signP2SHTransaction.d.ts.map +1 -1
- package/lib/signP2SHTransaction.js +3 -2
- package/lib/signP2SHTransaction.js.map +1 -1
- package/lib-es/Btc.d.ts +37 -0
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +30 -2
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +84 -0
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +325 -8
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/createTransaction.d.ts.map +1 -1
- package/lib-es/createTransaction.js +3 -2
- package/lib-es/createTransaction.js.map +1 -1
- package/lib-es/getTrustedInputBIP143.d.ts +1 -2
- package/lib-es/getTrustedInputBIP143.d.ts.map +1 -1
- package/lib-es/getTrustedInputBIP143.js +1 -1
- package/lib-es/getTrustedInputBIP143.js.map +1 -1
- package/lib-es/newops/accounttype.d.ts +3 -3
- package/lib-es/newops/accounttype.d.ts.map +1 -1
- package/lib-es/newops/accounttype.js +11 -10
- package/lib-es/newops/accounttype.js.map +1 -1
- package/lib-es/newops/appClient.d.ts +1 -1
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +1 -1
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +1 -1
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/policy.js +1 -1
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.d.ts +1 -1
- package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
- package/lib-es/newops/psbtExtractor.js +1 -1
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.d.ts +1 -1
- package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib-es/newops/psbtFinalizer.js +1 -2
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/signP2SHTransaction.d.ts.map +1 -1
- package/lib-es/signP2SHTransaction.js +3 -2
- package/lib-es/signP2SHTransaction.js.map +1 -1
- package/package.json +6 -6
- package/src/Btc.ts +41 -2
- package/src/BtcNew.ts +483 -9
- package/src/createTransaction.ts +4 -3
- package/src/getTrustedInputBIP143.ts +0 -2
- package/src/newops/accounttype.ts +11 -12
- package/src/newops/appClient.ts +1 -1
- package/src/newops/clientCommands.ts +1 -1
- package/src/newops/merkelizedPsbt.ts +1 -1
- package/src/newops/policy.ts +1 -1
- package/src/newops/psbtExtractor.ts +1 -2
- package/src/newops/psbtFinalizer.ts +1 -2
- package/src/signP2SHTransaction.ts +3 -2
- package/tests/Btc.test.ts +848 -20
- package/tests/newops/BtcNew.signMessage.test.ts +35 -0
- package/tests/newops/BtcNew.signPsbtBuffer.test.ts +391 -0
- package/tests/newops/BtcNew.test.ts +13 -1
- package/tests/newops/integrationtools.ts +1 -1
- package/lib/buffertools.d.ts +0 -31
- package/lib/buffertools.d.ts.map +0 -1
- package/lib/buffertools.js +0 -129
- package/lib/buffertools.js.map +0 -1
- package/lib/newops/psbtv2.d.ts +0 -150
- package/lib/newops/psbtv2.d.ts.map +0 -1
- package/lib/newops/psbtv2.js +0 -469
- package/lib/newops/psbtv2.js.map +0 -1
- package/lib-es/buffertools.d.ts +0 -31
- package/lib-es/buffertools.d.ts.map +0 -1
- package/lib-es/buffertools.js +0 -119
- package/lib-es/buffertools.js.map +0 -1
- package/lib-es/newops/psbtv2.d.ts +0 -150
- package/lib-es/newops/psbtv2.d.ts.map +0 -1
- package/lib-es/newops/psbtv2.js +0 -464
- package/lib-es/newops/psbtv2.js.map +0 -1
- package/src/buffertools.ts +0 -137
- package/src/newops/psbtv2.ts +0 -525
- package/tests/buffertools.test.ts +0 -25
- package/tests/newops/psbtv2.test.ts +0 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# @ledgerhq/hw-app-btc
|
|
2
2
|
|
|
3
|
-
## 10.16.0-nightly.
|
|
3
|
+
## 10.16.0-nightly.20260116124336
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- [#13340](https://github.com/LedgerHQ/ledger-live/pull/13340) [`85ed675`](https://github.com/LedgerHQ/ledger-live/commit/85ed67593945e396cfe995a13de7454850fa6436) Thanks [@Justkant](https://github.com/Justkant)! - feat(coin-bitcoin): support psbt signature in wallet-api
|
|
8
|
+
|
|
7
9
|
- [#13537](https://github.com/LedgerHQ/ledger-live/pull/13537) [`7e33c7b`](https://github.com/LedgerHQ/ledger-live/commit/7e33c7b3de128e0c076176e98f8065f7cf7ad733) Thanks [@hedi-edelbloute](https://github.com/hedi-edelbloute)! - feat: btc recovery app support
|
|
8
10
|
|
|
9
11
|
- [#13396](https://github.com/LedgerHQ/ledger-live/pull/13396) [`b9a3e43`](https://github.com/LedgerHQ/ledger-live/commit/b9a3e431be33943ab4feb4294d6a7f27b966e61b) Thanks [@gre-ledger](https://github.com/gre-ledger)! - Update Jest to v30
|
|
@@ -11,8 +13,8 @@
|
|
|
11
13
|
### Patch Changes
|
|
12
14
|
|
|
13
15
|
- Updated dependencies [[`b9a3e43`](https://github.com/LedgerHQ/ledger-live/commit/b9a3e431be33943ab4feb4294d6a7f27b966e61b)]:
|
|
14
|
-
- @ledgerhq/hw-transport@6.32.0-nightly.
|
|
15
|
-
- @ledgerhq/logs@6.14.0-nightly.
|
|
16
|
+
- @ledgerhq/hw-transport@6.32.0-nightly.20260116124336
|
|
17
|
+
- @ledgerhq/logs@6.14.0-nightly.20260116124336
|
|
16
18
|
|
|
17
19
|
## 10.15.0
|
|
18
20
|
|
package/README.md
CHANGED
|
@@ -42,81 +42,85 @@ For a smooth and quick integration:
|
|
|
42
42
|
* [createPaymentTransaction](#createpaymenttransaction)
|
|
43
43
|
* [Parameters](#parameters-4)
|
|
44
44
|
* [Examples](#examples-3)
|
|
45
|
-
* [
|
|
45
|
+
* [signPsbtBuffer](#signpsbtbuffer)
|
|
46
46
|
* [Parameters](#parameters-5)
|
|
47
47
|
* [Examples](#examples-4)
|
|
48
|
-
* [
|
|
48
|
+
* [signP2SHTransaction](#signp2shtransaction)
|
|
49
49
|
* [Parameters](#parameters-6)
|
|
50
50
|
* [Examples](#examples-5)
|
|
51
|
-
* [
|
|
51
|
+
* [splitTransaction](#splittransaction)
|
|
52
52
|
* [Parameters](#parameters-7)
|
|
53
53
|
* [Examples](#examples-6)
|
|
54
|
-
* [
|
|
54
|
+
* [serializeTransactionOutputs](#serializetransactionoutputs)
|
|
55
55
|
* [Parameters](#parameters-8)
|
|
56
|
-
|
|
56
|
+
* [Examples](#examples-7)
|
|
57
|
+
* [getTrustedInput](#gettrustedinput)
|
|
57
58
|
* [Parameters](#parameters-9)
|
|
59
|
+
* [getTrustedInputBIP143](#gettrustedinputbip143)
|
|
60
|
+
* [Parameters](#parameters-10)
|
|
58
61
|
* [BtcNew](#btcnew)
|
|
59
62
|
* [getWalletXpub](#getwalletxpub-1)
|
|
60
|
-
* [Parameters](#parameters-10)
|
|
61
|
-
* [getWalletPublicKey](#getwalletpublickey-1)
|
|
62
63
|
* [Parameters](#parameters-11)
|
|
63
|
-
* [
|
|
64
|
+
* [getWalletPublicKey](#getwalletpublickey-1)
|
|
64
65
|
* [Parameters](#parameters-12)
|
|
65
|
-
* [
|
|
66
|
+
* [createPaymentTransaction](#createpaymenttransaction-1)
|
|
66
67
|
* [Parameters](#parameters-13)
|
|
68
|
+
* [signPsbtBuffer](#signpsbtbuffer-1)
|
|
69
|
+
* [Parameters](#parameters-14)
|
|
70
|
+
* [signMessage](#signmessage-1)
|
|
71
|
+
* [Parameters](#parameters-15)
|
|
67
72
|
* [descrTemplFrom](#descrtemplfrom)
|
|
68
|
-
* [Parameters](#parameters-
|
|
73
|
+
* [Parameters](#parameters-16)
|
|
69
74
|
* [BtcOld](#btcold)
|
|
70
75
|
* [getWalletPublicKey](#getwalletpublickey-2)
|
|
71
|
-
* [Parameters](#parameters-
|
|
72
|
-
* [Examples](#examples-7)
|
|
73
|
-
* [createPaymentTransaction](#createpaymenttransaction-2)
|
|
74
|
-
* [Parameters](#parameters-16)
|
|
76
|
+
* [Parameters](#parameters-17)
|
|
75
77
|
* [Examples](#examples-8)
|
|
78
|
+
* [createPaymentTransaction](#createpaymenttransaction-2)
|
|
79
|
+
* [Parameters](#parameters-18)
|
|
80
|
+
* [Examples](#examples-9)
|
|
76
81
|
* [CreateTransactionArg](#createtransactionarg)
|
|
77
82
|
* [Properties](#properties)
|
|
78
83
|
* [AddressFormat](#addressformat)
|
|
79
84
|
* [AccountType](#accounttype)
|
|
80
85
|
* [spendingCondition](#spendingcondition)
|
|
81
|
-
* [Parameters](#parameters-
|
|
86
|
+
* [Parameters](#parameters-19)
|
|
82
87
|
* [setInput](#setinput)
|
|
83
|
-
* [Parameters](#parameters-
|
|
88
|
+
* [Parameters](#parameters-20)
|
|
84
89
|
* [setOwnOutput](#setownoutput)
|
|
85
|
-
* [Parameters](#parameters-
|
|
90
|
+
* [Parameters](#parameters-21)
|
|
86
91
|
* [getDescriptorTemplate](#getdescriptortemplate)
|
|
87
92
|
* [SingleKeyAccount](#singlekeyaccount)
|
|
88
93
|
* [getTaprootOutputKey](#gettaprootoutputkey)
|
|
89
|
-
* [Parameters](#parameters-
|
|
94
|
+
* [Parameters](#parameters-22)
|
|
90
95
|
* [AppClient](#appclient)
|
|
91
|
-
* [Parameters](#parameters-
|
|
96
|
+
* [Parameters](#parameters-23)
|
|
92
97
|
* [ClientCommandInterpreter](#clientcommandinterpreter)
|
|
93
|
-
* [Parameters](#parameters-
|
|
98
|
+
* [Parameters](#parameters-24)
|
|
94
99
|
* [MerkelizedPsbt](#merkelizedpsbt)
|
|
95
|
-
* [Parameters](#parameters-
|
|
100
|
+
* [Parameters](#parameters-25)
|
|
96
101
|
* [Merkle](#merkle)
|
|
97
|
-
* [Parameters](#parameters-
|
|
102
|
+
* [Parameters](#parameters-26)
|
|
98
103
|
* [MerkleMap](#merklemap)
|
|
99
|
-
* [Parameters](#parameters-
|
|
104
|
+
* [Parameters](#parameters-27)
|
|
100
105
|
* [WalletPolicy](#walletpolicy)
|
|
101
|
-
* [Parameters](#parameters-
|
|
106
|
+
* [Parameters](#parameters-28)
|
|
102
107
|
* [extract](#extract)
|
|
103
|
-
* [Parameters](#parameters-
|
|
108
|
+
* [Parameters](#parameters-29)
|
|
104
109
|
* [finalize](#finalize)
|
|
105
|
-
* [Parameters](#parameters-
|
|
110
|
+
* [Parameters](#parameters-30)
|
|
106
111
|
* [clearFinalizedInput](#clearfinalizedinput)
|
|
107
|
-
* [Parameters](#parameters-
|
|
112
|
+
* [Parameters](#parameters-31)
|
|
108
113
|
* [writePush](#writepush)
|
|
109
|
-
* [Parameters](#parameters-
|
|
110
|
-
* [PsbtV2](#psbtv2)
|
|
114
|
+
* [Parameters](#parameters-32)
|
|
111
115
|
* [serializeTransactionOutputs](#serializetransactionoutputs-1)
|
|
112
|
-
* [Parameters](#parameters-
|
|
113
|
-
* [Examples](#examples-
|
|
116
|
+
* [Parameters](#parameters-33)
|
|
117
|
+
* [Examples](#examples-10)
|
|
114
118
|
* [SignP2SHTransactionArg](#signp2shtransactionarg)
|
|
115
119
|
* [Properties](#properties-1)
|
|
116
120
|
* [splitSaplingPart](#splitsaplingpart)
|
|
117
|
-
* [Parameters](#parameters-
|
|
121
|
+
* [Parameters](#parameters-34)
|
|
118
122
|
* [splitOrchardPart](#splitorchardpart)
|
|
119
|
-
* [Parameters](#parameters-
|
|
123
|
+
* [Parameters](#parameters-35)
|
|
120
124
|
* [TransactionInput](#transactioninput)
|
|
121
125
|
* [TransactionOutput](#transactionoutput)
|
|
122
126
|
* [Transaction](#transaction)
|
|
@@ -249,6 +253,35 @@ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d
|
|
|
249
253
|
|
|
250
254
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** the signed transaction ready to be broadcast
|
|
251
255
|
|
|
256
|
+
#### signPsbtBuffer
|
|
257
|
+
|
|
258
|
+
Sign a PSBT Buffer
|
|
259
|
+
|
|
260
|
+
This method can handle PSBTs with or without BIP32 derivation information.
|
|
261
|
+
It processes a PSBT buffer and signs the transaction inputs according to the
|
|
262
|
+
wallet policy and derivation paths.
|
|
263
|
+
|
|
264
|
+
##### Parameters
|
|
265
|
+
|
|
266
|
+
* `psbt` **[Buffer](https://nodejs.org/api/buffer.html)** The PSBT (Partially Signed Bitcoin Transaction) buffer to be signed
|
|
267
|
+
* `opts` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Optional configuration for signing
|
|
268
|
+
|
|
269
|
+
* `opts.finalizePsbt` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Whether to finalize the PSBT after signing (default: true)
|
|
270
|
+
* `opts.accountPath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** BIP32 derivation path for the account (e.g., "m/84'/0'/0'")
|
|
271
|
+
* `opts.addressFormat` **[AddressFormat](#addressformat)?** Address format to use for signing (e.g., 'p2wpkh', 'p2sh-p2wpkh', 'p2pkh')
|
|
272
|
+
|
|
273
|
+
##### Examples
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
const { psbt: signedPsbt, tx } = await btc.signPsbtBuffer(psbtBuffer, {
|
|
277
|
+
finalizePsbt: true,
|
|
278
|
+
accountPath: "m/84'/0'/0'",
|
|
279
|
+
addressFormat: 'p2wpkh'
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{psbt: [Buffer](https://nodejs.org/api/buffer.html), tx: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>** A promise that resolves to an object containing the signed PSBT buffer and the transaction hex string
|
|
284
|
+
|
|
252
285
|
#### signP2SHTransaction
|
|
253
286
|
|
|
254
287
|
To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction\_async with the folowing parameters
|
|
@@ -423,6 +456,42 @@ transaction is returned.
|
|
|
423
456
|
|
|
424
457
|
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** 
|
|
425
458
|
|
|
459
|
+
#### signPsbtBuffer
|
|
460
|
+
|
|
461
|
+
Signs a PSBT buffer using the Bitcoin app (new protocol).
|
|
462
|
+
|
|
463
|
+
* If the PSBT is v2, it is deserialized directly.
|
|
464
|
+
* If the PSBT is v0, it is converted to v2 internally.
|
|
465
|
+
* The account type (legacy, wrapped segwit, native segwit, taproot) is
|
|
466
|
+
inferred from PSBT data when possible, or from the provided options.
|
|
467
|
+
|
|
468
|
+
Note: All internal inputs (inputs that can be signed by the device) must
|
|
469
|
+
belong to the same account and use the same account type. Mixed input types
|
|
470
|
+
or inputs from different accounts are not supported and will throw an error.
|
|
471
|
+
|
|
472
|
+
##### Parameters
|
|
473
|
+
|
|
474
|
+
* `psbtBuffer` **[Buffer](https://nodejs.org/api/buffer.html)** Raw PSBT buffer (v0 or v2) to be signed.
|
|
475
|
+
* `options` **{finalizePsbt: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, accountPath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, addressFormat: [AddressFormat](#addressformat)?, onDeviceSignatureRequested: function (): void?, onDeviceSignatureGranted: function (): void?, onDeviceStreaming: function (arg: {progress: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), total: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), index: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}): void?}?** Optional signing configuration.
|
|
476
|
+
|
|
477
|
+
* `options.finalizePsbt` Whether to finalize the PSBT after signing
|
|
478
|
+
(default: true). If true, the returned `tx` is a fully signed
|
|
479
|
+
transaction ready for broadcast.
|
|
480
|
+
* `options.accountPath` BIP32 account path (for example,
|
|
481
|
+
"m/84'/0'/0'") used when BIP32 derivation information is missing from
|
|
482
|
+
the PSBT. Required if the PSBT does not contain BIP32 derivation data.
|
|
483
|
+
* `options.addressFormat` Explicit address format to use when the
|
|
484
|
+
account type cannot be inferred from the PSBT ("legacy", "p2sh",
|
|
485
|
+
"bech32", or "bech32m").
|
|
486
|
+
* `options.onDeviceSignatureRequested` Callback when signature is about to be requested from device.
|
|
487
|
+
* `options.onDeviceSignatureGranted` Callback when the first signature is granted by device.
|
|
488
|
+
* `options.onDeviceStreaming` Callback to track signing progress with index and total.
|
|
489
|
+
|
|
490
|
+
Returns **any** An object containing:* `psbt`: a non-finalized PSBT buffer including signatures.
|
|
491
|
+
* `tx`: the fully signed transaction hex string (if `finalizePsbt` is
|
|
492
|
+
true), or the hex of the transaction that would be extracted after
|
|
493
|
+
finalization.
|
|
494
|
+
|
|
426
495
|
#### signMessage
|
|
427
496
|
|
|
428
497
|
Signs an arbitrary hex-formatted message with the private key at
|
|
@@ -671,7 +740,7 @@ The signing process is documented at
|
|
|
671
740
|
|
|
672
741
|
#### Parameters
|
|
673
742
|
|
|
674
|
-
* `psbt` **
|
|
743
|
+
* `psbt` **PsbtV2** 
|
|
675
744
|
|
|
676
745
|
### Merkle
|
|
677
746
|
|
|
@@ -723,7 +792,7 @@ the role is partially documented in BIP174 (PSBTv0
|
|
|
723
792
|
|
|
724
793
|
#### Parameters
|
|
725
794
|
|
|
726
|
-
* `psbt` **
|
|
795
|
+
* `psbt` **PsbtV2** 
|
|
727
796
|
|
|
728
797
|
Returns **[Buffer](https://nodejs.org/api/buffer.html)** 
|
|
729
798
|
|
|
@@ -741,7 +810,7 @@ derivation paths.
|
|
|
741
810
|
|
|
742
811
|
#### Parameters
|
|
743
812
|
|
|
744
|
-
* `psbt` **
|
|
813
|
+
* `psbt` **PsbtV2** The psbt with all signatures added as partial sigs, either
|
|
745
814
|
through PSBT\_IN\_PARTIAL\_SIG or PSBT\_IN\_TAP\_KEY\_SIG
|
|
746
815
|
|
|
747
816
|
Returns **void** 
|
|
@@ -756,7 +825,7 @@ without actually knowing why. I think we should remove them too.
|
|
|
756
825
|
|
|
757
826
|
#### Parameters
|
|
758
827
|
|
|
759
|
-
* `psbt` **
|
|
828
|
+
* `psbt` **PsbtV2** 
|
|
760
829
|
* `inputIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** 
|
|
761
830
|
|
|
762
831
|
### writePush
|
|
@@ -770,25 +839,6 @@ depending on the size of the data. See
|
|
|
770
839
|
* `buf` **BufferWriter** the BufferWriter to write to
|
|
771
840
|
* `data` **[Buffer](https://nodejs.org/api/buffer.html)** the Buffer to be pushed.
|
|
772
841
|
|
|
773
|
-
### PsbtV2
|
|
774
|
-
|
|
775
|
-
Implements Partially Signed Bitcoin Transaction version 2, BIP370, as
|
|
776
|
-
documented at <https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki>
|
|
777
|
-
and <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>
|
|
778
|
-
|
|
779
|
-
A psbt is a data structure that can carry all relevant information about a
|
|
780
|
-
transaction through all stages of the signing process. From constructing an
|
|
781
|
-
unsigned transaction to extracting the final serialized transaction ready for
|
|
782
|
-
broadcast.
|
|
783
|
-
|
|
784
|
-
This implementation is limited to what's needed in ledgerjs to carry out its
|
|
785
|
-
duties, which means that support for features like multisig or taproot script
|
|
786
|
-
path spending are not implemented. Specifically, it supports p2pkh,
|
|
787
|
-
p2wpkhWrappedInP2sh, p2wpkh and p2tr key path spending.
|
|
788
|
-
|
|
789
|
-
This class is made purposefully dumb, so it's easy to add support for
|
|
790
|
-
complemantary fields as needed in the future.
|
|
791
|
-
|
|
792
842
|
### serializeTransactionOutputs
|
|
793
843
|
|
|
794
844
|
#### Parameters
|
package/lib/Btc.d.ts
CHANGED
|
@@ -120,6 +120,43 @@ export default class Btc {
|
|
|
120
120
|
}).then(res => ...);
|
|
121
121
|
*/
|
|
122
122
|
createPaymentTransaction(arg: CreateTransactionArg): Promise<string>;
|
|
123
|
+
/**
|
|
124
|
+
* Sign a PSBT Buffer
|
|
125
|
+
*
|
|
126
|
+
* This method can handle PSBTs with or without BIP32 derivation information.
|
|
127
|
+
* It processes a PSBT buffer and signs the transaction inputs according to the
|
|
128
|
+
* wallet policy and derivation paths.
|
|
129
|
+
*
|
|
130
|
+
* @param {Buffer} psbt - The PSBT (Partially Signed Bitcoin Transaction) buffer to be signed
|
|
131
|
+
* @param {Object} [opts] - Optional configuration for signing
|
|
132
|
+
* @param {boolean} [opts.finalizePsbt] - Whether to finalize the PSBT after signing (default: true)
|
|
133
|
+
* @param {string} [opts.accountPath] - BIP32 derivation path for the account (e.g., "m/84'/0'/0'")
|
|
134
|
+
* @param {AddressFormat} [opts.addressFormat] - Address format to use for signing (e.g., 'p2wpkh', 'p2sh-p2wpkh', 'p2pkh')
|
|
135
|
+
*
|
|
136
|
+
* @returns {Promise<{psbt: Buffer, tx: string}>} A promise that resolves to an object containing the signed PSBT buffer and the transaction hex string
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const { psbt: signedPsbt, tx } = await btc.signPsbtBuffer(psbtBuffer, {
|
|
140
|
+
* finalizePsbt: true,
|
|
141
|
+
* accountPath: "m/84'/0'/0'",
|
|
142
|
+
* addressFormat: 'p2wpkh'
|
|
143
|
+
* });
|
|
144
|
+
*/
|
|
145
|
+
signPsbtBuffer(psbt: Buffer, opts?: {
|
|
146
|
+
finalizePsbt?: boolean;
|
|
147
|
+
accountPath?: string;
|
|
148
|
+
addressFormat?: AddressFormat;
|
|
149
|
+
onDeviceSignatureRequested?: () => void;
|
|
150
|
+
onDeviceSignatureGranted?: () => void;
|
|
151
|
+
onDeviceStreaming?: (arg: {
|
|
152
|
+
progress: number;
|
|
153
|
+
total: number;
|
|
154
|
+
index: number;
|
|
155
|
+
}) => void;
|
|
156
|
+
}): Promise<{
|
|
157
|
+
psbt: Buffer;
|
|
158
|
+
tx: string;
|
|
159
|
+
}>;
|
|
123
160
|
/**
|
|
124
161
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
125
162
|
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
package/lib/Btc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Btc.d.ts","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;AACA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AACpD,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,CAAC;AAI9B;;;;;;;;;GASG;AAEH,MAAM,CAAC,OAAO,OAAO,GAAG;IAEtB,OAAO,CAAC,UAAU,CAAY;IAG9B,OAAO,CAAC,KAAK,CAAkB;gBACnB,EACV,SAAS,EACT,WAAmB,EACnB,QAAoB,GACrB,EAAE;QACD,SAAS,EAAE,SAAS,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IA+BD;;;;;;;;OAQG;IACH,aAAa,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,MAA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AAW,GAAE,KAAK,CAAC,MAAM,CAAM,GAC9B,WAAW;IAId;;;;;MAKE;IACF,2BAA2B,CAAC,CAAC,EAAE,WAAW,GAAG,MAAM;IAInD;;;;OAIG;IACH,eAAe,CACb,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,EACxB,WAAW,GAAE,KAAK,CAAC,MAAM,CAAM,GAC9B,OAAO,CAAC,MAAM,CAAC;IAIlB;;OAEG;IACH,qBAAqB,CACnB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,WAAW,EACxB,WAAW,GAAE,KAAK,CAAC,MAAM,CAAM,GAC9B,MAAM;IAIH,qBAAqB,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;CAsCxD"}
|
package/lib/Btc.js
CHANGED
|
@@ -37,8 +37,8 @@ class Btc {
|
|
|
37
37
|
"signP2SHTransaction",
|
|
38
38
|
"signMessage",
|
|
39
39
|
"createPaymentTransaction",
|
|
40
|
+
"signPsbtBuffer",
|
|
40
41
|
"getTrustedInput",
|
|
41
|
-
"getTrustedInputBIP143",
|
|
42
42
|
], scrambleKey);
|
|
43
43
|
this._impl = (() => {
|
|
44
44
|
switch (currency) {
|
|
@@ -168,6 +168,34 @@ class Btc {
|
|
|
168
168
|
return impl.createPaymentTransaction(arg);
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Sign a PSBT Buffer
|
|
173
|
+
*
|
|
174
|
+
* This method can handle PSBTs with or without BIP32 derivation information.
|
|
175
|
+
* It processes a PSBT buffer and signs the transaction inputs according to the
|
|
176
|
+
* wallet policy and derivation paths.
|
|
177
|
+
*
|
|
178
|
+
* @param {Buffer} psbt - The PSBT (Partially Signed Bitcoin Transaction) buffer to be signed
|
|
179
|
+
* @param {Object} [opts] - Optional configuration for signing
|
|
180
|
+
* @param {boolean} [opts.finalizePsbt] - Whether to finalize the PSBT after signing (default: true)
|
|
181
|
+
* @param {string} [opts.accountPath] - BIP32 derivation path for the account (e.g., "m/84'/0'/0'")
|
|
182
|
+
* @param {AddressFormat} [opts.addressFormat] - Address format to use for signing (e.g., 'p2wpkh', 'p2sh-p2wpkh', 'p2pkh')
|
|
183
|
+
*
|
|
184
|
+
* @returns {Promise<{psbt: Buffer, tx: string}>} A promise that resolves to an object containing the signed PSBT buffer and the transaction hex string
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const { psbt: signedPsbt, tx } = await btc.signPsbtBuffer(psbtBuffer, {
|
|
188
|
+
* finalizePsbt: true,
|
|
189
|
+
* accountPath: "m/84'/0'/0'",
|
|
190
|
+
* addressFormat: 'p2wpkh'
|
|
191
|
+
* });
|
|
192
|
+
*/
|
|
193
|
+
async signPsbtBuffer(psbt, opts) {
|
|
194
|
+
if (this._impl instanceof BtcOld_1.default) {
|
|
195
|
+
throw new TypeError("signPsbtBuffer is not supported with the legacy Bitcoin app");
|
|
196
|
+
}
|
|
197
|
+
return this._impl.signPsbtBuffer(psbt, opts);
|
|
198
|
+
}
|
|
171
199
|
/**
|
|
172
200
|
* To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
173
201
|
* @param inputs is an array of [ transaction, output_index, redeem script, optional sequence ] where
|
|
@@ -224,7 +252,7 @@ class Btc {
|
|
|
224
252
|
* Trusted input is the hash of a UTXO that needs to be signed. BIP143 is used for Segwit inputs.
|
|
225
253
|
*/
|
|
226
254
|
getTrustedInputBIP143(indexLookup, transaction, additionals = []) {
|
|
227
|
-
return (0, getTrustedInputBIP143_1.getTrustedInputBIP143)(
|
|
255
|
+
return (0, getTrustedInputBIP143_1.getTrustedInputBIP143)(indexLookup, transaction, additionals);
|
|
228
256
|
}
|
|
229
257
|
async changeImplIfNecessary() {
|
|
230
258
|
// if BtcOld was instantiated, stick with it
|
package/lib/Btc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;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AAK,MAAM;oBACT,uEAAuE;oBACvE,OAAO,gBAAM,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACrC;oBACE,OAAO,IAAI,CAAC;YAChB,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,KAAK,GAAG,IAAI,gBAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAhVD,sBAgVC"}
|
package/lib/BtcNew.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
1
3
|
import type { CreateTransactionArg } from "./createTransaction";
|
|
2
4
|
import type { AddressFormat } from "./getWalletPublicKey";
|
|
3
5
|
import { AppClient as Client } from "./newops/appClient";
|
|
@@ -93,6 +95,88 @@ export default class BtcNew {
|
|
|
93
95
|
* transaction is returned.
|
|
94
96
|
*/
|
|
95
97
|
createPaymentTransaction(arg: CreateTransactionArg): Promise<string>;
|
|
98
|
+
/**
|
|
99
|
+
* Signs a PSBT buffer using the Bitcoin app (new protocol).
|
|
100
|
+
*
|
|
101
|
+
* - If the PSBT is v2, it is deserialized directly.
|
|
102
|
+
* - If the PSBT is v0, it is converted to v2 internally.
|
|
103
|
+
* - The account type (legacy, wrapped segwit, native segwit, taproot) is
|
|
104
|
+
* inferred from PSBT data when possible, or from the provided options.
|
|
105
|
+
*
|
|
106
|
+
* Note: All internal inputs (inputs that can be signed by the device) must
|
|
107
|
+
* belong to the same account and use the same account type. Mixed input types
|
|
108
|
+
* or inputs from different accounts are not supported and will throw an error.
|
|
109
|
+
*
|
|
110
|
+
* @param psbtBuffer - Raw PSBT buffer (v0 or v2) to be signed.
|
|
111
|
+
* @param options - Optional signing configuration.
|
|
112
|
+
* @param options.finalizePsbt - Whether to finalize the PSBT after signing
|
|
113
|
+
* (default: true). If true, the returned `tx` is a fully signed
|
|
114
|
+
* transaction ready for broadcast.
|
|
115
|
+
* @param options.accountPath - BIP32 account path (for example,
|
|
116
|
+
* "m/84'/0'/0'") used when BIP32 derivation information is missing from
|
|
117
|
+
* the PSBT. Required if the PSBT does not contain BIP32 derivation data.
|
|
118
|
+
* @param options.addressFormat - Explicit address format to use when the
|
|
119
|
+
* account type cannot be inferred from the PSBT ("legacy", "p2sh",
|
|
120
|
+
* "bech32", or "bech32m").
|
|
121
|
+
* @param options.onDeviceSignatureRequested - Callback when signature is about to be requested from device.
|
|
122
|
+
* @param options.onDeviceSignatureGranted - Callback when the first signature is granted by device.
|
|
123
|
+
* @param options.onDeviceStreaming - Callback to track signing progress with index and total.
|
|
124
|
+
*
|
|
125
|
+
* @returns An object containing:
|
|
126
|
+
* - `psbt`: a non-finalized PSBT buffer including signatures.
|
|
127
|
+
* - `tx`: the fully signed transaction hex string (if `finalizePsbt` is
|
|
128
|
+
* true), or the hex of the transaction that would be extracted after
|
|
129
|
+
* finalization.
|
|
130
|
+
*/
|
|
131
|
+
signPsbtBuffer(psbtBuffer: Buffer, options?: {
|
|
132
|
+
finalizePsbt?: boolean;
|
|
133
|
+
accountPath?: string;
|
|
134
|
+
addressFormat?: AddressFormat;
|
|
135
|
+
onDeviceSignatureRequested?: () => void;
|
|
136
|
+
onDeviceSignatureGranted?: () => void;
|
|
137
|
+
onDeviceStreaming?: (arg: {
|
|
138
|
+
progress: number;
|
|
139
|
+
total: number;
|
|
140
|
+
index: number;
|
|
141
|
+
}) => void;
|
|
142
|
+
}): Promise<{
|
|
143
|
+
psbt: Buffer;
|
|
144
|
+
tx: string;
|
|
145
|
+
}>;
|
|
146
|
+
private deserializePsbt;
|
|
147
|
+
private analyzeAllInputs;
|
|
148
|
+
private validateAccountPathConsistency;
|
|
149
|
+
private validateScriptTypeConsistency;
|
|
150
|
+
private resolveAccountPathFromOptions;
|
|
151
|
+
private createWalletPolicy;
|
|
152
|
+
private createProgressCallback;
|
|
153
|
+
private finalizePsbtAndExtract;
|
|
154
|
+
/**
|
|
155
|
+
* Analyzes a single input to determine if it's internal (can be signed by the device)
|
|
156
|
+
* and extracts its account path and script type.
|
|
157
|
+
*/
|
|
158
|
+
private analyzeInput;
|
|
159
|
+
private checkBip32Derivation;
|
|
160
|
+
private checkStandardBip32Derivation;
|
|
161
|
+
private checkTaprootBip32Derivation;
|
|
162
|
+
private extractAccountPath;
|
|
163
|
+
private determineInputScriptType;
|
|
164
|
+
/**
|
|
165
|
+
* Detects the script type from a scriptPubKey.
|
|
166
|
+
*/
|
|
167
|
+
private detectScriptType;
|
|
168
|
+
/**
|
|
169
|
+
* Compares two derivation paths for equality.
|
|
170
|
+
*/
|
|
171
|
+
private arePathsEqual;
|
|
172
|
+
/**
|
|
173
|
+
* Determines the account type based on detected script type, account path, or options.
|
|
174
|
+
*/
|
|
175
|
+
private determineAccountType;
|
|
176
|
+
private createAccountTypeFromScriptType;
|
|
177
|
+
private determineAccountTypeFromWitnessUtxo;
|
|
178
|
+
private createAccountTypeFromAddressFormat;
|
|
179
|
+
private determineAccountTypeFromPurpose;
|
|
96
180
|
/**
|
|
97
181
|
* Signs an arbitrary hex-formatted message with the private key at
|
|
98
182
|
* the provided derivation path according to the Bitcoin Signature format
|
package/lib/BtcNew.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":";;AAUA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAS1D,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAazD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CA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