@ledgerhq/hw-app-btc 6.10.0-taproot.0 → 6.11.2

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 (115) hide show
  1. package/README.md +660 -107
  2. package/lib/Btc.d.ts +9 -6
  3. package/lib/Btc.d.ts.map +1 -1
  4. package/lib/Btc.js +74 -11
  5. package/lib/Btc.js.map +1 -1
  6. package/lib/BtcNew.d.ts +80 -32
  7. package/lib/BtcNew.d.ts.map +1 -1
  8. package/lib/BtcNew.js +179 -209
  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 +75 -12
  53. package/lib-es/Btc.js.map +1 -1
  54. package/lib-es/BtcNew.d.ts +80 -32
  55. package/lib-es/BtcNew.d.ts.map +1 -1
  56. package/lib-es/BtcNew.js +176 -210
  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 +4 -4
  99. package/src/Btc.ts +113 -15
  100. package/src/BtcNew.ts +213 -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.integration.test.ts +7 -1
  112. package/tests/Btc.test.ts +88 -0
  113. package/tests/newops/BtcNew.test.ts +54 -20
  114. package/tests/newops/integrationtools.ts +49 -39
  115. package/tests/newops/testtx.ts +0 -55
package/README.md CHANGED
@@ -13,38 +13,96 @@ Ledger Hardware Wallet BTC JavaScript bindings. Also supports many altcoins.
13
13
 
14
14
  #### Table of Contents
15
15
 
16
- - [Btc](#btc)
17
- - [Parameters](#parameters)
18
- - [Examples](#examples)
19
- - [getWalletPublicKey](#getwalletpublickey)
20
- - [Parameters](#parameters-1)
21
- - [Examples](#examples-1)
22
- - [signMessageNew](#signmessagenew)
23
- - [Parameters](#parameters-2)
24
- - [Examples](#examples-2)
25
- - [createPaymentTransactionNew](#createpaymenttransactionnew)
26
- - [Parameters](#parameters-3)
27
- - [Examples](#examples-3)
28
- - [signP2SHTransaction](#signp2shtransaction)
29
- - [Parameters](#parameters-4)
30
- - [Examples](#examples-4)
31
- - [splitTransaction](#splittransaction)
32
- - [Parameters](#parameters-5)
33
- - [Examples](#examples-5)
34
- - [serializeTransactionOutputs](#serializetransactionoutputs)
35
- - [Parameters](#parameters-6)
36
- - [Examples](#examples-6)
37
- - [CreateTransactionArg](#createtransactionarg)
38
- - [Properties](#properties)
39
- - [AddressFormat](#addressformat)
40
- - [serializeTransactionOutputs](#serializetransactionoutputs-1)
41
- - [Parameters](#parameters-7)
42
- - [Examples](#examples-7)
43
- - [SignP2SHTransactionArg](#signp2shtransactionarg)
44
- - [Properties](#properties-1)
45
- - [TransactionInput](#transactioninput)
46
- - [TransactionOutput](#transactionoutput)
47
- - [Transaction](#transaction)
16
+ * [Btc](#btc)
17
+ * [Parameters](#parameters)
18
+ * [Examples](#examples)
19
+ * [getWalletXpub](#getwalletxpub)
20
+ * [Parameters](#parameters-1)
21
+ * [getWalletPublicKey](#getwalletpublickey)
22
+ * [Parameters](#parameters-2)
23
+ * [Examples](#examples-1)
24
+ * [signMessageNew](#signmessagenew)
25
+ * [Parameters](#parameters-3)
26
+ * [Examples](#examples-2)
27
+ * [createPaymentTransactionNew](#createpaymenttransactionnew)
28
+ * [Parameters](#parameters-4)
29
+ * [Examples](#examples-3)
30
+ * [signP2SHTransaction](#signp2shtransaction)
31
+ * [Parameters](#parameters-5)
32
+ * [Examples](#examples-4)
33
+ * [splitTransaction](#splittransaction)
34
+ * [Parameters](#parameters-6)
35
+ * [Examples](#examples-5)
36
+ * [serializeTransactionOutputs](#serializetransactionoutputs)
37
+ * [Parameters](#parameters-7)
38
+ * [Examples](#examples-6)
39
+ * [getWalletPublicKey](#getwalletpublickey-1)
40
+ * [BtcNew](#btcnew)
41
+ * [Parameters](#parameters-8)
42
+ * [getWalletXpub](#getwalletxpub-1)
43
+ * [Parameters](#parameters-9)
44
+ * [getWalletPublicKey](#getwalletpublickey-2)
45
+ * [Parameters](#parameters-10)
46
+ * [createPaymentTransactionNew](#createpaymenttransactionnew-1)
47
+ * [Parameters](#parameters-11)
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)
57
+ * [createPaymentTransactionNew](#createpaymenttransactionnew-2)
58
+ * [Parameters](#parameters-15)
59
+ * [Examples](#examples-10)
60
+ * [signP2SHTransaction](#signp2shtransaction-1)
61
+ * [Parameters](#parameters-16)
62
+ * [Examples](#examples-11)
63
+ * [CreateTransactionArg](#createtransactionarg)
64
+ * [Properties](#properties)
65
+ * [AddressFormat](#addressformat)
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)
91
+ * [finalize](#finalize)
92
+ * [Parameters](#parameters-28)
93
+ * [clearFinalizedInput](#clearfinalizedinput)
94
+ * [Parameters](#parameters-29)
95
+ * [writePush](#writepush)
96
+ * [Parameters](#parameters-30)
97
+ * [PsbtV2](#psbtv2)
98
+ * [serializeTransactionOutputs](#serializetransactionoutputs-1)
99
+ * [Parameters](#parameters-31)
100
+ * [Examples](#examples-12)
101
+ * [SignP2SHTransactionArg](#signp2shtransactionarg)
102
+ * [Properties](#properties-1)
103
+ * [TransactionInput](#transactioninput)
104
+ * [TransactionOutput](#transactionoutput)
105
+ * [Transaction](#transaction)
48
106
 
49
107
  ### Btc
50
108
 
@@ -52,8 +110,8 @@ Bitcoin API.
52
110
 
53
111
  #### Parameters
54
112
 
55
- - `transport` **Transport**
56
- - `scrambleKey` (optional, default `"BTC"`)
113
+ * `transport` **Transport**
114
+ * `scrambleKey` (optional, default `"BTC"`)
57
115
 
58
116
  #### Examples
59
117
 
@@ -62,21 +120,32 @@ import Btc from "@ledgerhq/hw-app-btc";
62
120
  const btc = new Btc(transport)
63
121
  ```
64
122
 
123
+ #### getWalletXpub
124
+
125
+ Get an XPUB with a ledger device
126
+
127
+ ##### Parameters
128
+
129
+ * `arg` **{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)}** derivation parameter* path: a BIP 32 path of the account level. e.g. `84'/0'/0'`
130
+ * xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed)
131
+
132
+ 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)>** XPUB of the account
133
+
65
134
  #### getWalletPublicKey
66
135
 
67
136
  ##### Parameters
68
137
 
69
- - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path
70
- - `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
71
- - `options` an object with optional these fields:- verify (boolean) will ask user to confirm the address on the device
138
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path
139
+ * `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
140
+ * `options` an object with optional these fields:* verify (boolean) will ask user to confirm the address on the device
72
141
 
73
- - format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:- legacy format with 44' paths
142
+ * format ("legacy" | "p2sh" | "bech32" | "bech32m" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:* legacy format with 44' paths
74
143
 
75
- - p2sh format with 49' paths
144
+ * p2sh format with 49' paths
76
145
 
77
- - bech32 format with 173' paths
146
+ * bech32 format with 84' paths
78
147
 
79
- - cashaddr in case of Bitcoin Cash
148
+ * cashaddr in case of Bitcoin Cash
80
149
 
81
150
  ##### Examples
82
151
 
@@ -85,7 +154,7 @@ btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
85
154
  btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
86
155
  ```
87
156
 
88
- Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;{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)}>**
157
+ 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)}>**
89
158
 
90
159
  #### signMessageNew
91
160
 
@@ -93,8 +162,8 @@ You can sign a message according to the Bitcoin Signature format and retrieve v,
93
162
 
94
163
  ##### Parameters
95
164
 
96
- - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
97
- - `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
165
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
166
+ * `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
98
167
 
99
168
  ##### Examples
100
169
 
@@ -106,7 +175,7 @@ console.log("Signature : " + signature);
106
175
  }).catch(function(ex) {console.log(ex);});
107
176
  ```
108
177
 
109
- Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;{v: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
178
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{v: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
110
179
 
111
180
  #### createPaymentTransactionNew
112
181
 
@@ -114,25 +183,26 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction
114
183
 
115
184
  ##### Parameters
116
185
 
117
- - `arg` **[CreateTransactionArg](#createtransactionarg)**
118
- - `inputs` is an array of [ transaction, output_index, optional redeem script, optional sequence ] where- transaction is the previously computed transaction object for this UTXO
119
- - output_index is the output in the transaction used as input for this UTXO (counting from 0)
120
- - redeem script is the optional redeem script to use when consuming a Segregated Witness input
121
- - sequence is the sequence number to use for this input (when using RBF), or non present
122
- - `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
123
- - `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
124
- - `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
125
- - `lockTime` is the optional lockTime of the transaction to sign, or default (0)
126
- - `sigHashType` is the hash type of the transaction to sign, or default (all)
127
- - `segwit` is an optional boolean indicating wether to use segwit or not
128
- - `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)
129
- - `additionals` list of additionnal options- "bech32" for spending native segwit outputs
130
- - "abc" for bch
131
- - "gold" for btg
132
- - "bipxxx" for using BIPxxx
133
- - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
134
- - `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
135
- - `useTrustedInputForSegwit` trust inputs for segwit transactions
186
+ * `arg` **[CreateTransactionArg](#createtransactionarg)**
187
+ * `inputs` is an array of \[ transaction, output_index, optional redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
188
+ * output_index is the output in the transaction used as input for this UTXO (counting from 0)
189
+ * redeem script is the optional redeem script to use when consuming a Segregated Witness input
190
+ * sequence is the sequence number to use for this input (when using RBF), or non present
191
+ * `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
192
+ * `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
193
+ * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
194
+ * `lockTime` is the optional lockTime of the transaction to sign, or default (0)
195
+ * `sigHashType` is the hash type of the transaction to sign, or default (all)
196
+ * `segwit` is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
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)
198
+ * `additionals` list of additionnal options* "bech32" for spending native segwit outputs
199
+ * "bech32m" for spending segwit v1+ outputs
200
+ * "abc" for bch
201
+ * "gold" for btg
202
+ * "bipxxx" for using BIPxxx
203
+ * "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
204
+ * `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
205
+ * `useTrustedInputForSegwit` trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
136
206
 
137
207
  ##### Examples
138
208
 
@@ -144,7 +214,7 @@ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d
144
214
  }).then(res => ...);
145
215
  ```
146
216
 
147
- Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** the signed transaction ready to be broadcast
217
+ 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
148
218
 
149
219
  #### signP2SHTransaction
150
220
 
@@ -152,15 +222,15 @@ To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransactio
152
222
 
153
223
  ##### Parameters
154
224
 
155
- - `arg` **[SignP2SHTransactionArg](#signp2shtransactionarg)**
156
- - `inputs` is an array of [ transaction, output_index, redeem script, optional sequence ] where- transaction is the previously computed transaction object for this UTXO
157
- - output_index is the output in the transaction used as input for this UTXO (counting from 0)
158
- - redeem script is the mandatory redeem script associated to the current P2SH input
159
- - sequence is the sequence number to use for this input (when using RBF), or non present
160
- - `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
161
- - `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
162
- - `lockTime` is the optional lockTime of the transaction to sign, or default (0)
163
- - `sigHashType` is the hash type of the transaction to sign, or default (all)
225
+ * `arg` **[SignP2SHTransactionArg](#signp2shtransactionarg)**
226
+ * `inputs` is an array of \[ transaction, output_index, redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
227
+ * output_index is the output in the transaction used as input for this UTXO (counting from 0)
228
+ * redeem script is the mandatory redeem script associated to the current P2SH input
229
+ * sequence is the sequence number to use for this input (when using RBF), or non present
230
+ * `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
231
+ * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
232
+ * `lockTime` is the optional lockTime of the transaction to sign, or default (0)
233
+ * `sigHashType` is the hash type of the transaction to sign, or default (all)
164
234
 
165
235
  ##### Examples
166
236
 
@@ -172,7 +242,7 @@ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d
172
242
  }).then(result => ...);
173
243
  ```
174
244
 
175
- Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>>** the signed transaction ready to be broadcast
245
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>>** the signed transaction ready to be broadcast
176
246
 
177
247
  #### splitTransaction
178
248
 
@@ -180,11 +250,11 @@ For each UTXO included in your transaction, create a transaction object from the
180
250
 
181
251
  ##### Parameters
182
252
 
183
- - `transactionHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
184
- - `isSegwitSupported` **([boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** (optional, default `false`)
185
- - `hasTimestamp` (optional, default `false`)
186
- - `hasExtraData` (optional, default `false`)
187
- - `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`)
253
+ * `transactionHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
254
+ * `isSegwitSupported` **([boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** (optional, default `false`)
255
+ * `hasTimestamp` (optional, default `false`)
256
+ * `hasExtraData` (optional, default `false`)
257
+ * `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** (optional, default `[]`)
188
258
 
189
259
  ##### Examples
190
260
 
@@ -198,7 +268,7 @@ Returns **[Transaction](#transaction)**
198
268
 
199
269
  ##### Parameters
200
270
 
201
- - `t` **[Transaction](#transaction)**
271
+ * `t` **[Transaction](#transaction)**
202
272
 
203
273
  ##### Examples
204
274
 
@@ -209,39 +279,522 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
209
279
 
210
280
  Returns **[Buffer](https://nodejs.org/api/buffer.html)**
211
281
 
282
+ ### getWalletPublicKey
283
+
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.
320
+
321
+ #### Parameters
322
+
323
+ * ``
324
+
325
+ #### getWalletXpub
326
+
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>
330
+
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)>**
394
+
395
+ ### BtcOld
396
+
397
+ Bitcoin API.
398
+
399
+ #### Parameters
400
+
401
+ * ``
402
+
403
+ #### Examples
404
+
405
+ ```javascript
406
+ import Btc from "@ledgerhq/hw-app-btc";
407
+ const btc = new Btc(transport)
408
+ ```
409
+
410
+ #### getWalletPublicKey
411
+
412
+ ##### Parameters
413
+
414
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path
415
+ * `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
416
+ * `options` an object with optional these fields:* verify (boolean) will ask user to confirm the address on the device
417
+
418
+ * format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:* legacy format with 44' paths
419
+
420
+ * p2sh format with 49' paths
421
+
422
+ * bech32 format with 173' paths
423
+
424
+ * cashaddr in case of Bitcoin Cash
425
+
426
+ ##### Examples
427
+
428
+ ```javascript
429
+ btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
430
+ btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
431
+ ```
432
+
433
+ 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)}>**
434
+
435
+ #### signMessageNew
436
+
437
+ You can sign a message according to the Bitcoin Signature format and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
438
+
439
+ ##### Parameters
440
+
441
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
442
+ * `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
443
+
444
+ ##### Examples
445
+
446
+ ```javascript
447
+ btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
448
+ var v = result['v'] + 27 + 4;
449
+ var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
450
+ console.log("Signature : " + signature);
451
+ }).catch(function(ex) {console.log(ex);});
452
+ ```
453
+
454
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{v: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
455
+
456
+ #### createPaymentTransactionNew
457
+
458
+ To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
459
+
460
+ ##### Parameters
461
+
462
+ * `arg` **[CreateTransactionArg](#createtransactionarg)**
463
+ * `inputs` is an array of \[ transaction, output_index, optional redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
464
+ * output_index is the output in the transaction used as input for this UTXO (counting from 0)
465
+ * redeem script is the optional redeem script to use when consuming a Segregated Witness input
466
+ * sequence is the sequence number to use for this input (when using RBF), or non present
467
+ * `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
468
+ * `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
469
+ * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
470
+ * `lockTime` is the optional lockTime of the transaction to sign, or default (0)
471
+ * `sigHashType` is the hash type of the transaction to sign, or default (all)
472
+ * `segwit` is an optional boolean indicating wether to use segwit or not
473
+ * `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)
474
+ * `additionals` list of additionnal options* "bech32" for spending native segwit outputs
475
+ * "abc" for bch
476
+ * "gold" for btg
477
+ * "bipxxx" for using BIPxxx
478
+ * "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
479
+ * `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
480
+ * `useTrustedInputForSegwit` trust inputs for segwit transactions
481
+
482
+ ##### Examples
483
+
484
+ ```javascript
485
+ btc.createTransaction({
486
+ inputs: [ [tx1, 1] ],
487
+ associatedKeysets: ["0'/0/0"],
488
+ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
489
+ }).then(res => ...);
490
+ ```
491
+
492
+ 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
493
+
494
+ #### signP2SHTransaction
495
+
496
+ To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
497
+
498
+ ##### Parameters
499
+
500
+ * `arg` **[SignP2SHTransactionArg](#signp2shtransactionarg)**
501
+ * `inputs` is an array of \[ transaction, output_index, redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
502
+ * output_index is the output in the transaction used as input for this UTXO (counting from 0)
503
+ * redeem script is the mandatory redeem script associated to the current P2SH input
504
+ * sequence is the sequence number to use for this input (when using RBF), or non present
505
+ * `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
506
+ * `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
507
+ * `lockTime` is the optional lockTime of the transaction to sign, or default (0)
508
+ * `sigHashType` is the hash type of the transaction to sign, or default (all)
509
+
510
+ ##### Examples
511
+
512
+ ```javascript
513
+ btc.signP2SHTransaction({
514
+ inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
515
+ associatedKeysets: ["0'/0/0"],
516
+ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
517
+ }).then(result => ...);
518
+ ```
519
+
520
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>>** the signed transaction ready to be broadcast
521
+
212
522
  ### CreateTransactionArg
213
523
 
214
- Type: {inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>, associatedKeysets: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, changePath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, outputScriptHex: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), lockTime: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, sigHashType: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, segwit: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, initialTimestamp: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, additionals: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, expiryHeight: [Buffer](https://nodejs.org/api/buffer.html)?, useTrustedInputForSegwit: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, onDeviceStreaming: function (arg0: {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?, onDeviceSignatureRequested: function (): void?, onDeviceSignatureGranted: function (): void?}
524
+ Type: {inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>, associatedKeysets: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, changePath: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?, outputScriptHex: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), lockTime: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, sigHashType: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, segwit: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, initialTimestamp: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, additionals: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, expiryHeight: [Buffer](https://nodejs.org/api/buffer.html)?, useTrustedInputForSegwit: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, onDeviceStreaming: function (arg0: {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?, onDeviceSignatureRequested: function (): void?, onDeviceSignatureGranted: function (): void?}
215
525
 
216
526
  #### Properties
217
527
 
218
- - `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>**
219
- - `associatedKeysets` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
220
- - `changePath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
221
- - `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
222
- - `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
223
- - `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
224
- - `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
225
- - `initialTimestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
226
- - `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
227
- - `expiryHeight` **[Buffer](https://nodejs.org/api/buffer.html)?**
228
- - `useTrustedInputForSegwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
229
- - `onDeviceStreaming` **function (arg0: {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?**
230
- - `onDeviceSignatureRequested` **function (): void?**
231
- - `onDeviceSignatureGranted` **function (): void?**
528
+ * `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>**
529
+ * `associatedKeysets` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
530
+ * `changePath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
531
+ * `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
532
+ * `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
533
+ * `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
534
+ * `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
535
+ * `initialTimestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
536
+ * `additionals` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
537
+ * `expiryHeight` **[Buffer](https://nodejs.org/api/buffer.html)?**
538
+ * `useTrustedInputForSegwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
539
+ * `onDeviceStreaming` **function (arg0: {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?**
540
+ * `onDeviceSignatureRequested` **function (): void?**
541
+ * `onDeviceSignatureGranted` **function (): void?**
232
542
 
233
543
  ### AddressFormat
234
544
 
235
545
  address format is one of legacy | p2sh | bech32 | cashaddr
236
546
 
237
- Type: (`"legacy"` \| `"p2sh"` \| `"bech32"` \| `"cashaddr"`)
547
+ Type: (`"legacy"` | `"p2sh"` | `"bech32"` | `"bech32m"` | `"cashaddr"`)
548
+
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.
696
+
697
+ #### Parameters
698
+
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
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
701
+
702
+ ### WalletPolicy
703
+
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>
710
+
711
+ #### Parameters
712
+
713
+ * `descriptorTemplate` **DefaultDescriptorTemplate**
714
+ * `key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
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
+
729
+ ### finalize
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
+
741
+ #### Parameters
742
+
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
745
+
746
+ Returns **void**
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.
238
790
 
239
791
  ### serializeTransactionOutputs
240
792
 
241
793
  #### Parameters
242
794
 
243
- - `$0` **[Transaction](#transaction)**
244
- - `$0.outputs`
795
+ * `$0` **[Transaction](#transaction)**
796
+
797
+ * `$0.outputs`
245
798
 
246
799
  #### Examples
247
800
 
@@ -254,17 +807,17 @@ Returns **[Buffer](https://nodejs.org/api/buffer.html)**
254
807
 
255
808
  ### SignP2SHTransactionArg
256
809
 
257
- Type: {inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>, associatedKeysets: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, outputScriptHex: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), lockTime: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, sigHashType: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, segwit: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, transactionVersion: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?}
810
+ Type: {inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>, associatedKeysets: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>, outputScriptHex: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), lockTime: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, sigHashType: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?, segwit: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, transactionVersion: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?}
258
811
 
259
812
  #### Properties
260
813
 
261
- - `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>**
262
- - `associatedKeysets` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
263
- - `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
264
- - `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
265
- - `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
266
- - `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
267
- - `transactionVersion` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
814
+ * `inputs` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<\[[Transaction](#transaction), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), ([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined)), ([number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))]>**
815
+ * `associatedKeysets` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
816
+ * `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
817
+ * `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
818
+ * `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
819
+ * `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
820
+ * `transactionVersion` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
268
821
 
269
822
  ### TransactionInput
270
823