@ledgerhq/hw-app-btc 6.10.0 → 6.12.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.
Files changed (114) hide show
  1. package/README.md +384 -60
  2. package/lib/Btc.d.ts +9 -6
  3. package/lib/Btc.d.ts.map +1 -1
  4. package/lib/Btc.js +73 -8
  5. package/lib/Btc.js.map +1 -1
  6. package/lib/BtcNew.d.ts +79 -32
  7. package/lib/BtcNew.d.ts.map +1 -1
  8. package/lib/BtcNew.js +168 -207
  9. package/lib/BtcNew.js.map +1 -1
  10. package/lib/newops/accounttype.d.ts +110 -0
  11. package/lib/newops/accounttype.d.ts.map +1 -0
  12. package/lib/newops/accounttype.js +233 -0
  13. package/lib/newops/accounttype.js.map +1 -0
  14. package/lib/newops/appClient.d.ts +6 -2
  15. package/lib/newops/appClient.d.ts.map +1 -1
  16. package/lib/newops/appClient.js +8 -4
  17. package/lib/newops/appClient.js.map +1 -1
  18. package/lib/newops/clientCommands.d.ts +18 -2
  19. package/lib/newops/clientCommands.d.ts.map +1 -1
  20. package/lib/newops/clientCommands.js +34 -12
  21. package/lib/newops/clientCommands.js.map +1 -1
  22. package/lib/newops/merkelizedPsbt.d.ts +11 -0
  23. package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
  24. package/lib/newops/merkelizedPsbt.js +11 -0
  25. package/lib/newops/merkelizedPsbt.js.map +1 -1
  26. package/lib/newops/merkle.d.ts +5 -0
  27. package/lib/newops/merkle.d.ts.map +1 -1
  28. package/lib/newops/merkle.js +5 -0
  29. package/lib/newops/merkle.js.map +1 -1
  30. package/lib/newops/merkleMap.d.ts +10 -0
  31. package/lib/newops/merkleMap.d.ts.map +1 -1
  32. package/lib/newops/merkleMap.js +10 -0
  33. package/lib/newops/merkleMap.js.map +1 -1
  34. package/lib/newops/policy.d.ts +8 -0
  35. package/lib/newops/policy.d.ts.map +1 -1
  36. package/lib/newops/policy.js +9 -1
  37. package/lib/newops/policy.js.map +1 -1
  38. package/lib/newops/psbtExtractor.d.ts +6 -0
  39. package/lib/newops/psbtExtractor.d.ts.map +1 -1
  40. package/lib/newops/psbtExtractor.js +6 -0
  41. package/lib/newops/psbtExtractor.js.map +1 -1
  42. package/lib/newops/psbtFinalizer.d.ts +11 -1
  43. package/lib/newops/psbtFinalizer.d.ts.map +1 -1
  44. package/lib/newops/psbtFinalizer.js +26 -1
  45. package/lib/newops/psbtFinalizer.js.map +1 -1
  46. package/lib/newops/psbtv2.d.ts +22 -2
  47. package/lib/newops/psbtv2.d.ts.map +1 -1
  48. package/lib/newops/psbtv2.js +33 -8
  49. package/lib/newops/psbtv2.js.map +1 -1
  50. package/lib-es/Btc.d.ts +9 -6
  51. package/lib-es/Btc.d.ts.map +1 -1
  52. package/lib-es/Btc.js +73 -8
  53. package/lib-es/Btc.js.map +1 -1
  54. package/lib-es/BtcNew.d.ts +79 -32
  55. package/lib-es/BtcNew.d.ts.map +1 -1
  56. package/lib-es/BtcNew.js +170 -209
  57. package/lib-es/BtcNew.js.map +1 -1
  58. package/lib-es/newops/accounttype.d.ts +110 -0
  59. package/lib-es/newops/accounttype.d.ts.map +1 -0
  60. package/lib-es/newops/accounttype.js +230 -0
  61. package/lib-es/newops/accounttype.js.map +1 -0
  62. package/lib-es/newops/appClient.d.ts +6 -2
  63. package/lib-es/newops/appClient.d.ts.map +1 -1
  64. package/lib-es/newops/appClient.js +8 -4
  65. package/lib-es/newops/appClient.js.map +1 -1
  66. package/lib-es/newops/clientCommands.d.ts +18 -2
  67. package/lib-es/newops/clientCommands.d.ts.map +1 -1
  68. package/lib-es/newops/clientCommands.js +34 -12
  69. package/lib-es/newops/clientCommands.js.map +1 -1
  70. package/lib-es/newops/merkelizedPsbt.d.ts +11 -0
  71. package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
  72. package/lib-es/newops/merkelizedPsbt.js +11 -0
  73. package/lib-es/newops/merkelizedPsbt.js.map +1 -1
  74. package/lib-es/newops/merkle.d.ts +5 -0
  75. package/lib-es/newops/merkle.d.ts.map +1 -1
  76. package/lib-es/newops/merkle.js +5 -0
  77. package/lib-es/newops/merkle.js.map +1 -1
  78. package/lib-es/newops/merkleMap.d.ts +10 -0
  79. package/lib-es/newops/merkleMap.d.ts.map +1 -1
  80. package/lib-es/newops/merkleMap.js +10 -0
  81. package/lib-es/newops/merkleMap.js.map +1 -1
  82. package/lib-es/newops/policy.d.ts +8 -0
  83. package/lib-es/newops/policy.d.ts.map +1 -1
  84. package/lib-es/newops/policy.js +10 -2
  85. package/lib-es/newops/policy.js.map +1 -1
  86. package/lib-es/newops/psbtExtractor.d.ts +6 -0
  87. package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
  88. package/lib-es/newops/psbtExtractor.js +6 -0
  89. package/lib-es/newops/psbtExtractor.js.map +1 -1
  90. package/lib-es/newops/psbtFinalizer.d.ts +11 -1
  91. package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
  92. package/lib-es/newops/psbtFinalizer.js +26 -1
  93. package/lib-es/newops/psbtFinalizer.js.map +1 -1
  94. package/lib-es/newops/psbtv2.d.ts +22 -2
  95. package/lib-es/newops/psbtv2.d.ts.map +1 -1
  96. package/lib-es/newops/psbtv2.js +33 -8
  97. package/lib-es/newops/psbtv2.js.map +1 -1
  98. package/package.json +3 -3
  99. package/src/Btc.ts +111 -9
  100. package/src/BtcNew.ts +204 -209
  101. package/src/newops/accounttype.ts +370 -0
  102. package/src/newops/appClient.ts +12 -4
  103. package/src/newops/clientCommands.ts +34 -12
  104. package/src/newops/merkelizedPsbt.ts +11 -0
  105. package/src/newops/merkle.ts +5 -0
  106. package/src/newops/merkleMap.ts +10 -0
  107. package/src/newops/policy.ts +10 -2
  108. package/src/newops/psbtExtractor.ts +6 -0
  109. package/src/newops/psbtFinalizer.ts +26 -1
  110. package/src/newops/psbtv2.ts +34 -14
  111. package/tests/Btc.test.ts +89 -0
  112. package/tests/newops/BtcNew.test.ts +48 -21
  113. package/tests/newops/integrationtools.ts +47 -36
  114. package/tests/newops/testtx.ts +0 -55
package/README.md CHANGED
@@ -36,36 +36,68 @@ Ledger Hardware Wallet BTC JavaScript bindings. Also supports many altcoins.
36
36
  * [serializeTransactionOutputs](#serializetransactionoutputs)
37
37
  * [Parameters](#parameters-7)
38
38
  * [Examples](#examples-6)
39
- * [createPaymentTransactionNew](#createpaymenttransactionnew-1)
39
+ * [getWalletPublicKey](#getwalletpublickey-1)
40
+ * [BtcNew](#btcnew)
40
41
  * [Parameters](#parameters-8)
41
- * [Examples](#examples-7)
42
- * [BtcOld](#btcold)
43
- * [Parameters](#parameters-9)
44
- * [Examples](#examples-8)
45
- * [getWalletPublicKey](#getwalletpublickey-1)
42
+ * [getWalletXpub](#getwalletxpub-1)
43
+ * [Parameters](#parameters-9)
44
+ * [getWalletPublicKey](#getwalletpublickey-2)
46
45
  * [Parameters](#parameters-10)
47
- * [Examples](#examples-9)
48
- * [signMessageNew](#signmessagenew-1)
46
+ * [createPaymentTransactionNew](#createpaymenttransactionnew-1)
49
47
  * [Parameters](#parameters-11)
50
- * [Examples](#examples-10)
48
+ * [BtcOld](#btcold)
49
+ * [Parameters](#parameters-12)
50
+ * [Examples](#examples-7)
51
+ * [getWalletPublicKey](#getwalletpublickey-3)
52
+ * [Parameters](#parameters-13)
53
+ * [Examples](#examples-8)
54
+ * [signMessageNew](#signmessagenew-1)
55
+ * [Parameters](#parameters-14)
56
+ * [Examples](#examples-9)
51
57
  * [createPaymentTransactionNew](#createpaymenttransactionnew-2)
52
- * [Parameters](#parameters-12)
53
- * [Examples](#examples-11)
58
+ * [Parameters](#parameters-15)
59
+ * [Examples](#examples-10)
54
60
  * [signP2SHTransaction](#signp2shtransaction-1)
55
- * [Parameters](#parameters-13)
56
- * [Examples](#examples-12)
61
+ * [Parameters](#parameters-16)
62
+ * [Examples](#examples-11)
57
63
  * [CreateTransactionArg](#createtransactionarg)
58
64
  * [Properties](#properties)
59
65
  * [AddressFormat](#addressformat)
60
- * [constructor](#constructor)
61
- * [Parameters](#parameters-14)
62
- * [constructor](#constructor-1)
63
- * [Parameters](#parameters-15)
66
+ * [AccountType](#accounttype)
67
+ * [spendingCondition](#spendingcondition)
68
+ * [Parameters](#parameters-17)
69
+ * [setInput](#setinput)
70
+ * [Parameters](#parameters-18)
71
+ * [setOwnOutput](#setownoutput)
72
+ * [Parameters](#parameters-19)
73
+ * [getDescriptorTemplate](#getdescriptortemplate)
74
+ * [SingleKeyAccount](#singlekeyaccount)
75
+ * [getTaprootOutputKey](#gettaprootoutputkey)
76
+ * [Parameters](#parameters-20)
77
+ * [AppClient](#appclient)
78
+ * [Parameters](#parameters-21)
79
+ * [ClientCommandInterpreter](#clientcommandinterpreter)
80
+ * [Parameters](#parameters-22)
81
+ * [MerkelizedPsbt](#merkelizedpsbt)
82
+ * [Parameters](#parameters-23)
83
+ * [Merkle](#merkle)
84
+ * [Parameters](#parameters-24)
85
+ * [MerkleMap](#merklemap)
86
+ * [Parameters](#parameters-25)
87
+ * [WalletPolicy](#walletpolicy)
88
+ * [Parameters](#parameters-26)
89
+ * [extract](#extract)
90
+ * [Parameters](#parameters-27)
64
91
  * [finalize](#finalize)
65
- * [Parameters](#parameters-16)
92
+ * [Parameters](#parameters-28)
93
+ * [clearFinalizedInput](#clearfinalizedinput)
94
+ * [Parameters](#parameters-29)
95
+ * [writePush](#writepush)
96
+ * [Parameters](#parameters-30)
97
+ * [PsbtV2](#psbtv2)
66
98
  * [serializeTransactionOutputs](#serializetransactionoutputs-1)
67
- * [Parameters](#parameters-17)
68
- * [Examples](#examples-13)
99
+ * [Parameters](#parameters-31)
100
+ * [Examples](#examples-12)
69
101
  * [SignP2SHTransactionArg](#signp2shtransactionarg)
70
102
  * [Properties](#properties-1)
71
103
  * [TransactionInput](#transactioninput)
@@ -111,7 +143,7 @@ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/
111
143
 
112
144
  * p2sh format with 49' paths
113
145
 
114
- * bech32 format with 173' paths
146
+ * bech32 format with 84' paths
115
147
 
116
148
  * cashaddr in case of Bitcoin Cash
117
149
 
@@ -158,19 +190,19 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction
158
190
  * sequence is the sequence number to use for this input (when using RBF), or non present
159
191
  * `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
160
192
  * `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
161
- * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
193
+ * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
162
194
  * `lockTime` is the optional lockTime of the transaction to sign, or default (0)
163
195
  * `sigHashType` is the hash type of the transaction to sign, or default (all)
164
- * `segwit` is an optional boolean indicating wether to use segwit or not
196
+ * `segwit` is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
165
197
  * `initialTimestamp` is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
166
198
  * `additionals` list of additionnal options* "bech32" for spending native segwit outputs
167
- * "bech32m" for spending native segwit outputs
199
+ * "bech32m" for spending segwit v1+ outputs
168
200
  * "abc" for bch
169
201
  * "gold" for btg
170
202
  * "bipxxx" for using BIPxxx
171
203
  * "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
172
204
  * `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
173
- * `useTrustedInputForSegwit` trust inputs for segwit transactions
205
+ * `useTrustedInputForSegwit` trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
174
206
 
175
207
  ##### Examples
176
208
 
@@ -247,44 +279,118 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
247
279
 
248
280
  Returns **[Buffer](https://nodejs.org/api/buffer.html)**
249
281
 
250
- ### createPaymentTransactionNew
282
+ ### getWalletPublicKey
251
283
 
252
- To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
284
+ Definition: A "normal path" is a prefix of a standard path where all
285
+ the hardened steps of the standard path are included. For example, the
286
+ paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
287
+ is not. m/'199/1'/17'/0/1 is not a normal path either.
288
+
289
+ There's a compatiblity issue between old and new app: When exporting
290
+ the key of a non-normal path with verify=false, the new app would
291
+ return an error, whereas the old app would return the key.
292
+
293
+ See
294
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey>
295
+
296
+ If format bech32m is used, we'll not use old, because it doesn't
297
+ support it.
298
+
299
+ When to use new (given the app supports it)
300
+
301
+ * format is bech32m or
302
+ * path is normal or
303
+ * verify is true
304
+
305
+ Otherwise use old.
306
+
307
+ ### BtcNew
308
+
309
+ This class implements the same interface as BtcOld (formerly
310
+ named Btc), but interacts with Bitcoin hardware app version 2+
311
+ which uses a totally new APDU protocol. This new
312
+ protocol is documented at
313
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md>
314
+
315
+ Since the interface must remain compatible with BtcOld, the methods
316
+ of this class are quite clunky, because it needs to adapt legacy
317
+ input data into the PSBT process. In the future, a new interface should
318
+ be developed that exposes PSBT to the outer world, which would render
319
+ a much cleaner implementation.
253
320
 
254
321
  #### Parameters
255
322
 
256
- * `arg` **[CreateTransactionArg](#createtransactionarg)**
257
- * `inputs` is an array of \[ transaction, output_index, optional redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
258
- * output_index is the output in the transaction used as input for this UTXO (counting from 0)
259
- * redeem script is the optional redeem script to use when consuming a Segregated Witness input
260
- * sequence is the sequence number to use for this input (when using RBF), or non present
261
- * `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
262
- * `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
263
- * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
264
- * `lockTime` is the optional lockTime of the transaction to sign, or default (0)
265
- * `sigHashType` is the hash type of the transaction to sign, or default (all)
266
- * `segwit` is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
267
- * `initialTimestamp` is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
268
- * `additionals` list of additionnal options* "bech32" for spending native segwit outputs
269
- * "bech32m" for spending segwit v1+ outptus
270
- * "abc" for bch
271
- * "gold" for btg
272
- * "bipxxx" for using BIPxxx
273
- * "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
274
- * `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
275
- * `useTrustedInputForSegwit` trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
323
+ * ``
276
324
 
277
- #### Examples
325
+ #### getWalletXpub
278
326
 
279
- ```javascript
280
- btc.createTransaction({
281
- inputs: [ [tx1, 1] ],
282
- associatedKeysets: ["0'/0/0"],
283
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
284
- }).then(res => ...);
285
- ```
327
+ This is a new method that allow users to get an xpub at a standard path.
328
+ Standard paths are described at
329
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description>
286
330
 
287
- 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
331
+ This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
332
+ M/44'/N'/x'/\*\*
333
+ M/48'/N'/x'/y'/\*\*
334
+ M/49'/N'/x'/\*\*
335
+ M/84'/N'/x'/\*\*
336
+ M/86'/N'/x'/\*\*
337
+
338
+ The method was added because of added security in the hardware app v2+. The
339
+ new hardware app will allow export of any xpub up to and including the
340
+ deepest hardened key of standard derivation paths, whereas the old app
341
+ would allow export of any key.
342
+
343
+ This caused an issue for callers of this class, who only had
344
+ getWalletPublicKey() to call which means they have to constuct xpub
345
+ themselves:
346
+
347
+ Suppose a user of this class wants to create an account xpub on a standard
348
+ path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
349
+ by requesting the parent key M/44'/0'. The new app won't allow that, because
350
+ it only allows exporting deepest level hardened path. So the options are to
351
+ allow requesting M/44'/0' from the app, or to add a new function
352
+ "getWalletXpub".
353
+
354
+ We opted for adding a new function, which can greatly simplify client code.
355
+
356
+ ##### Parameters
357
+
358
+ * `$0` **{path: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), xpubVersion: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}**
359
+
360
+ * `$0.path`
361
+ * `$0.xpubVersion`
362
+
363
+ 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)>**
364
+
365
+ #### getWalletPublicKey
366
+
367
+ This method returns a public key, a bitcoin address, and and a chaincode
368
+ for a specific derivation path.
369
+
370
+ Limitation: If the path is not a leaf node of a standard path, the address
371
+ will be the empty string "", see this.getWalletAddress() for details.
372
+
373
+ ##### Parameters
374
+
375
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
376
+ * `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
377
+
378
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{publicKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), bitcoinAddress: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), chainCode: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
379
+
380
+ #### createPaymentTransactionNew
381
+
382
+ Build and sign a transaction. See Btc.createPaymentTransactionNew for
383
+ details on how to use this method.
384
+
385
+ This method will convert the legacy arguments, CreateTransactionArg, into
386
+ a psbt which is finally signed and finalized, and the extracted fully signed
387
+ transaction is returned.
388
+
389
+ ##### Parameters
390
+
391
+ * `arg` **[CreateTransactionArg](#createtransactionarg)**
392
+
393
+ 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)>**
288
394
 
289
395
  ### BtcOld
290
396
 
@@ -440,30 +546,248 @@ address format is one of legacy | p2sh | bech32 | cashaddr
440
546
 
441
547
  Type: (`"legacy"` | `"p2sh"` | `"bech32"` | `"bech32m"` | `"cashaddr"`)
442
548
 
443
- ### constructor
549
+ ### AccountType
550
+
551
+ Encapsulates differences between account types, for example p2wpkh,
552
+ p2wpkhWrapped, p2tr.
553
+
554
+ #### spendingCondition
555
+
556
+ Generates a scriptPubKey (output script) from a list of public keys. If a
557
+ p2sh redeemScript or a p2wsh witnessScript is needed it will also be set on
558
+ the returned SpendingCondition.
559
+
560
+ The pubkeys are expected to be 33 byte ecdsa compressed pubkeys.
561
+
562
+ ##### Parameters
563
+
564
+ * `pubkeys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>**
565
+
566
+ Returns **SpendingCondition**
567
+
568
+ #### setInput
569
+
570
+ Populates the psbt with account type-specific data for an input.
571
+
572
+ ##### Parameters
573
+
574
+ * `i` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the input map to populate
575
+ * `inputTx` **([Buffer](https://nodejs.org/api/buffer.html) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** The full transaction containing the spent output. This may
576
+ be omitted for taproot.
577
+ * `spentOutput` **SpentOutput** The amount and spending condition of the spent output
578
+ * `pubkeys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** The 33 byte ecdsa compressed public keys involved in the input
579
+ * `pathElems` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** The paths corresponding to the pubkeys, in same order.
580
+
581
+ Returns **void**
582
+
583
+ #### setOwnOutput
584
+
585
+ Populates the psbt with account type-specific data for an output. This is typically
586
+ done for change outputs and other outputs that goes to the same account as
587
+ being spent from.
588
+
589
+ ##### Parameters
590
+
591
+ * `i` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The index of the output map to populate
592
+ * `cond` **SpendingCondition** The spending condition for this output
593
+ * `pubkeys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** The 33 byte ecdsa compressed public keys involved in this output
594
+ * `paths` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)>>** The paths corresponding to the pubkeys, in same order.
595
+
596
+ Returns **void**
597
+
598
+ #### getDescriptorTemplate
599
+
600
+ Returns the descriptor template for this account type. Currently only
601
+ DefaultDescriptorTemplates are allowed, but that might be changed in the
602
+ future. See class WalletPolicy for more information on descriptor
603
+ templates.
604
+
605
+ Returns **DefaultDescriptorTemplate**
606
+
607
+ ### SingleKeyAccount
608
+
609
+ **Extends BaseAccount**
610
+
611
+ Superclass for single signature accounts. This will make sure that the pubkey
612
+ arrays and path arrays in the method arguments contains exactly one element
613
+ and calls an abstract method to do the actual work.
614
+
615
+ ### getTaprootOutputKey
616
+
617
+ Calculates a taproot output key from an internal key. This output key will be
618
+ used as witness program in a taproot output. The internal key is tweaked
619
+ according to recommendation in BIP341:
620
+ <https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0>
621
+
622
+ #### Parameters
623
+
624
+ * `internalPubkey` **[Buffer](https://nodejs.org/api/buffer.html)** A 32 byte x-only taproot internal key
625
+
626
+ Returns **[Buffer](https://nodejs.org/api/buffer.html)** The output key
627
+
628
+ ### AppClient
629
+
630
+ This class encapsulates the APDU protocol documented at
631
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md>
632
+
633
+ #### Parameters
634
+
635
+ * `transport` **Transport**
636
+
637
+ ### ClientCommandInterpreter
638
+
639
+ This class will dispatch a client command coming from the hardware device to
640
+ the appropriate client command implementation. Those client commands
641
+ typically requests data from a merkle tree or merkelized maps.
642
+
643
+ A ClientCommandInterpreter is prepared by adding the merkle trees and
644
+ merkelized maps it should be able to serve to the hardware device. This class
645
+ doesn't know anything about the semantics of the data it holds, it just
646
+ serves merkle data. It doesn't even know in what context it is being
647
+ executed, ie SignPsbt, getWalletAddress, etc.
648
+
649
+ If the command yelds results to the client, as signPsbt does, the yielded
650
+ data will be accessible after the command completed by calling getYielded(),
651
+ which will return the yields in the same order as they came in.
652
+
653
+ #### Parameters
654
+
655
+ * `progressCallback` **function (): void**
656
+
657
+ ### MerkelizedPsbt
658
+
659
+ **Extends PsbtV2**
660
+
661
+ This class merkelizes a PSBTv2, by merkelizing the different
662
+ maps of the psbt. This is used during the transaction signing process,
663
+ where the hardware app can request specific parts of the psbt from the
664
+ client code and be sure that the response data actually belong to the psbt.
665
+ The reason for this is the limited amount of memory available to the app,
666
+ so it can't always store the full psbt in memory.
667
+
668
+ The signing process is documented at
669
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#sign_psbt>
670
+
671
+ #### Parameters
672
+
673
+ * `psbt` **[PsbtV2](#psbtv2)**
674
+
675
+ ### Merkle
676
+
677
+ This class implements the merkle tree used by Ledger Bitcoin app v2+,
678
+ which is documented at
679
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md>
680
+
681
+ #### Parameters
682
+
683
+ * `leaves` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>**
684
+ * `hasher` **function (buf: [Buffer](https://nodejs.org/api/buffer.html)): [Buffer](https://nodejs.org/api/buffer.html)** (optional, default `crypto.sha256`)
685
+
686
+ ### MerkleMap
687
+
688
+ This implements "Merkelized Maps", documented at
689
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md#merkleized-maps>
690
+
691
+ A merkelized map consist of two merkle trees, one for the keys of
692
+ a map and one for the values of the same map, thus the two merkle
693
+ trees have the same shape. The commitment is the number elements
694
+ in the map followed by the keys' merkle root followed by the
695
+ values' merkle root.
444
696
 
445
697
  #### Parameters
446
698
 
447
699
  * `keys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** Sorted list of (unhashed) keys
448
700
  * `values` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>** values, in corresponding order as the keys, and of equal length
449
701
 
450
- ### constructor
702
+ ### WalletPolicy
451
703
 
452
- For now, we only support default descriptor templates.
704
+ The Bitcon hardware app uses a descriptors-like thing to describe
705
+ how to construct output scripts from keys. A "Wallet Policy" consists
706
+ of a "Descriptor Template" and a list of "keys". A key is basically
707
+ a serialized BIP32 extended public key with some added derivation path
708
+ information. This is documented at
709
+ <https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/wallet.md>
453
710
 
454
711
  #### Parameters
455
712
 
456
713
  * `descriptorTemplate` **DefaultDescriptorTemplate**
457
714
  * `key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
458
715
 
716
+ ### extract
717
+
718
+ This implements the "Transaction Extractor" role of BIP370 (PSBTv2
719
+ <https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#transaction-extractor>). However
720
+ the role is partially documented in BIP174 (PSBTv0
721
+ <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#transaction-extractor>).
722
+
723
+ #### Parameters
724
+
725
+ * `psbt` **[PsbtV2](#psbtv2)**
726
+
727
+ Returns **[Buffer](https://nodejs.org/api/buffer.html)**
728
+
459
729
  ### finalize
460
730
 
731
+ This roughly implements the "input finalizer" role of BIP370 (PSBTv2
732
+ <https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki>). However
733
+ the role is documented in BIP174 (PSBTv0
734
+ <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>).
735
+
736
+ Verify that all inputs have a signature, and set inputFinalScriptwitness
737
+ and/or inputFinalScriptSig depending on the type of the spent outputs. Clean
738
+ fields that aren't useful anymore, partial signatures, redeem script and
739
+ derivation paths.
740
+
461
741
  #### Parameters
462
742
 
463
- * `psbt` **PsbtV2** The psbt with all signatures added as partial sigs, either through PSBT_IN_PARTIAL_SIG or PSBT_IN_TAP_KEY_SIG
743
+ * `psbt` **[PsbtV2](#psbtv2)** The psbt with all signatures added as partial sigs, either
744
+ through PSBT_IN_PARTIAL_SIG or PSBT_IN_TAP_KEY_SIG
464
745
 
465
746
  Returns **void**
466
747
 
748
+ ### clearFinalizedInput
749
+
750
+ Deletes fields that are no longer neccesary from the psbt.
751
+
752
+ Note, the spec doesn't say anything about removing ouput fields
753
+ like PSBT_OUT_BIP32\_DERIVATION_PATH and others, so we keep them
754
+ without actually knowing why. I think we should remove them too.
755
+
756
+ #### Parameters
757
+
758
+ * `psbt` **[PsbtV2](#psbtv2)**
759
+ * `inputIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
760
+
761
+ ### writePush
762
+
763
+ Writes a script push operation to buf, which looks different
764
+ depending on the size of the data. See
765
+ <https://en.bitcoin.it/wiki/Script#Constants>
766
+
767
+ #### Parameters
768
+
769
+ * `buf` **BufferWriter** the BufferWriter to write to
770
+ * `data` **[Buffer](https://nodejs.org/api/buffer.html)** the Buffer to be pushed.
771
+
772
+ ### PsbtV2
773
+
774
+ Implements Partially Signed Bitcoin Transaction version 2, BIP370, as
775
+ documented at <https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki>
776
+ and <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>
777
+
778
+ A psbt is a data structure that can carry all relevant information about a
779
+ transaction through all stages of the signing process. From constructing an
780
+ unsigned transaction to extracting the final serialized transaction ready for
781
+ broadcast.
782
+
783
+ This implementation is limited to what's needed in ledgerjs to carry out its
784
+ duties, which means that support for features like multisig or taproot script
785
+ path spending are not implemented. Specifically, it supports p2pkh,
786
+ p2wpkhWrappedInP2sh, p2wpkh and p2tr key path spending.
787
+
788
+ This class is made purposefully dumb, so it's easy to add support for
789
+ complemantary fields as needed in the future.
790
+
467
791
  ### serializeTransactionOutputs
468
792
 
469
793
  #### Parameters
package/lib/Btc.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type Transport from "@ledgerhq/hw-transport";
3
+ import BtcNew from "./BtcNew";
4
+ import BtcOld from "./BtcOld";
3
5
  import type { CreateTransactionArg } from "./createTransaction";
4
6
  import type { AddressFormat } from "./getWalletPublicKey";
5
7
  import type { SignP2SHTransactionArg } from "./signP2SHTransaction";
@@ -40,7 +42,7 @@ export default class Btc {
40
42
  *
41
43
  * - p2sh format with 49' paths
42
44
  *
43
- * - bech32 format with 173' paths
45
+ * - bech32 format with 84' paths
44
46
  *
45
47
  * - cashaddr in case of Bitcoin Cash
46
48
  *
@@ -80,21 +82,21 @@ export default class Btc {
80
82
  * * sequence is the sequence number to use for this input (when using RBF), or non present
81
83
  * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
82
84
  * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
83
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
85
+ * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
84
86
  * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
85
87
  * @param sigHashType is the hash type of the transaction to sign, or default (all)
86
- * @param segwit is an optional boolean indicating wether to use segwit or not
88
+ * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
87
89
  * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
88
90
  * @param additionals list of additionnal options
89
91
  *
90
92
  * - "bech32" for spending native segwit outputs
91
- * - "bech32m" for spending native segwit outputs
93
+ * - "bech32m" for spending segwit v1+ outputs
92
94
  * - "abc" for bch
93
95
  * - "gold" for btg
94
96
  * - "bipxxx" for using BIPxxx
95
97
  * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
96
98
  * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
97
- * @param useTrustedInputForSegwit trust inputs for segwit transactions
99
+ * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
98
100
  * @return the signed transaction ready to be broadcast
99
101
  * @example
100
102
  btc.createTransaction({
@@ -141,6 +143,7 @@ export default class Btc {
141
143
  private _lazyImpl;
142
144
  private getCorrectImpl;
143
145
  private inferCorrectImpl;
144
- private old;
146
+ protected old(): BtcOld;
147
+ protected new(): BtcNew;
145
148
  }
146
149
  //# sourceMappingURL=Btc.d.ts.map
package/lib/Btc.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Btc.d.ts","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAGpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,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;AAC9B;;;;;;GAMG;AAEH,MAAM,CAA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