@ledgerhq/hw-app-btc 6.9.1-taproot.0 → 6.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +602 -107
- package/lib/Btc.d.ts +11 -7
- package/lib/Btc.d.ts.map +1 -1
- package/lib/Btc.js +113 -31
- package/lib/Btc.js.map +1 -1
- package/lib/BtcNew.d.ts +81 -32
- package/lib/BtcNew.d.ts.map +1 -1
- package/lib/BtcNew.js +296 -99
- package/lib/BtcNew.js.map +1 -1
- package/lib/BtcOld.d.ts +3 -1
- package/lib/BtcOld.d.ts.map +1 -1
- package/lib/BtcOld.js +22 -6
- package/lib/BtcOld.js.map +1 -1
- package/lib/constants.d.ts +1 -0
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +2 -1
- package/lib/constants.js.map +1 -1
- package/lib/getAppAndVersion.d.ts +3 -2
- package/lib/getAppAndVersion.d.ts.map +1 -1
- package/lib/getAppAndVersion.js.map +1 -1
- package/lib/newops/appClient.d.ts +6 -2
- package/lib/newops/appClient.d.ts.map +1 -1
- package/lib/newops/appClient.js +9 -5
- package/lib/newops/appClient.js.map +1 -1
- package/lib/newops/clientCommands.d.ts +18 -2
- package/lib/newops/clientCommands.d.ts.map +1 -1
- package/lib/newops/clientCommands.js +20 -3
- package/lib/newops/clientCommands.js.map +1 -1
- package/lib/newops/merkelizedPsbt.d.ts +11 -0
- package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib/newops/merkelizedPsbt.js +11 -0
- package/lib/newops/merkelizedPsbt.js.map +1 -1
- package/lib/newops/merkle.d.ts +5 -0
- package/lib/newops/merkle.d.ts.map +1 -1
- package/lib/newops/merkle.js +5 -0
- package/lib/newops/merkle.js.map +1 -1
- package/lib/newops/merkleMap.d.ts +10 -0
- package/lib/newops/merkleMap.d.ts.map +1 -1
- package/lib/newops/merkleMap.js +10 -0
- package/lib/newops/merkleMap.js.map +1 -1
- package/lib/newops/policy.d.ts +8 -0
- package/lib/newops/policy.d.ts.map +1 -1
- package/lib/newops/policy.js +9 -1
- package/lib/newops/policy.js.map +1 -1
- package/lib/newops/psbtExtractor.d.ts +6 -0
- package/lib/newops/psbtExtractor.d.ts.map +1 -1
- package/lib/newops/psbtExtractor.js +6 -0
- package/lib/newops/psbtExtractor.js.map +1 -1
- package/lib/newops/psbtFinalizer.d.ts +11 -1
- package/lib/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib/newops/psbtFinalizer.js +28 -4
- package/lib/newops/psbtFinalizer.js.map +1 -1
- package/lib/newops/psbtv2.d.ts +22 -2
- package/lib/newops/psbtv2.d.ts.map +1 -1
- package/lib/newops/psbtv2.js +37 -8
- package/lib/newops/psbtv2.js.map +1 -1
- package/lib-es/Btc.d.ts +11 -7
- package/lib-es/Btc.d.ts.map +1 -1
- package/lib-es/Btc.js +94 -31
- package/lib-es/Btc.js.map +1 -1
- package/lib-es/BtcNew.d.ts +81 -32
- package/lib-es/BtcNew.d.ts.map +1 -1
- package/lib-es/BtcNew.js +293 -101
- package/lib-es/BtcNew.js.map +1 -1
- package/lib-es/BtcOld.d.ts +3 -1
- package/lib-es/BtcOld.d.ts.map +1 -1
- package/lib-es/BtcOld.js +22 -6
- package/lib-es/BtcOld.js.map +1 -1
- package/lib-es/constants.d.ts +1 -0
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +1 -0
- package/lib-es/constants.js.map +1 -1
- package/lib-es/getAppAndVersion.d.ts +3 -2
- package/lib-es/getAppAndVersion.d.ts.map +1 -1
- package/lib-es/getAppAndVersion.js.map +1 -1
- package/lib-es/newops/appClient.d.ts +6 -2
- package/lib-es/newops/appClient.d.ts.map +1 -1
- package/lib-es/newops/appClient.js +9 -5
- package/lib-es/newops/appClient.js.map +1 -1
- package/lib-es/newops/clientCommands.d.ts +18 -2
- package/lib-es/newops/clientCommands.d.ts.map +1 -1
- package/lib-es/newops/clientCommands.js +20 -3
- package/lib-es/newops/clientCommands.js.map +1 -1
- package/lib-es/newops/merkelizedPsbt.d.ts +11 -0
- package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
- package/lib-es/newops/merkelizedPsbt.js +11 -0
- package/lib-es/newops/merkelizedPsbt.js.map +1 -1
- package/lib-es/newops/merkle.d.ts +5 -0
- package/lib-es/newops/merkle.d.ts.map +1 -1
- package/lib-es/newops/merkle.js +5 -0
- package/lib-es/newops/merkle.js.map +1 -1
- package/lib-es/newops/merkleMap.d.ts +10 -0
- package/lib-es/newops/merkleMap.d.ts.map +1 -1
- package/lib-es/newops/merkleMap.js +10 -0
- package/lib-es/newops/merkleMap.js.map +1 -1
- package/lib-es/newops/policy.d.ts +8 -0
- package/lib-es/newops/policy.d.ts.map +1 -1
- package/lib-es/newops/policy.js +10 -2
- package/lib-es/newops/policy.js.map +1 -1
- package/lib-es/newops/psbtExtractor.d.ts +6 -0
- package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
- package/lib-es/newops/psbtExtractor.js +6 -0
- package/lib-es/newops/psbtExtractor.js.map +1 -1
- package/lib-es/newops/psbtFinalizer.d.ts +11 -1
- package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
- package/lib-es/newops/psbtFinalizer.js +28 -4
- package/lib-es/newops/psbtFinalizer.js.map +1 -1
- package/lib-es/newops/psbtv2.d.ts +22 -2
- package/lib-es/newops/psbtv2.d.ts.map +1 -1
- package/lib-es/newops/psbtv2.js +37 -8
- package/lib-es/newops/psbtv2.js.map +1 -1
- package/package.json +4 -4
- package/src/Btc.ts +92 -21
- package/src/BtcNew.ts +295 -77
- package/src/BtcOld.ts +13 -9
- package/src/bip32.ts +1 -1
- package/src/constants.ts +1 -0
- package/src/getAppAndVersion.ts +7 -4
- package/src/newops/appClient.ts +13 -5
- package/src/newops/clientCommands.ts +19 -3
- package/src/newops/merkelizedPsbt.ts +11 -0
- package/src/newops/merkle.ts +5 -0
- package/src/newops/merkleMap.ts +10 -0
- package/src/newops/policy.ts +10 -2
- package/src/newops/psbtExtractor.ts +6 -0
- package/src/newops/psbtFinalizer.ts +28 -4
- package/src/newops/psbtv2.ts +38 -14
- package/tests/Btc.integration.test.ts +125 -15
- package/tests/Btc.test.ts +83 -0
- package/tests/newops/BtcNew.test.ts +75 -508
- package/tests/newops/integrationtools.ts +174 -0
- package/tests/newops/testtx.ts +676 -0
- package/tests/speculosclient.ts +47 -0
package/README.md
CHANGED
|
@@ -13,38 +13,89 @@ Ledger Hardware Wallet BTC JavaScript bindings. Also supports many altcoins.
|
|
|
13
13
|
|
|
14
14
|
#### Table of Contents
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
* [outputScriptOf](#outputscriptof)
|
|
49
|
+
* [Parameters](#parameters-12)
|
|
50
|
+
* [getTaprootOutputKey](#gettaprootoutputkey)
|
|
51
|
+
* [Parameters](#parameters-13)
|
|
52
|
+
* [BtcOld](#btcold)
|
|
53
|
+
* [Parameters](#parameters-14)
|
|
54
|
+
* [Examples](#examples-7)
|
|
55
|
+
* [getWalletPublicKey](#getwalletpublickey-3)
|
|
56
|
+
* [Parameters](#parameters-15)
|
|
57
|
+
* [Examples](#examples-8)
|
|
58
|
+
* [signMessageNew](#signmessagenew-1)
|
|
59
|
+
* [Parameters](#parameters-16)
|
|
60
|
+
* [Examples](#examples-9)
|
|
61
|
+
* [createPaymentTransactionNew](#createpaymenttransactionnew-2)
|
|
62
|
+
* [Parameters](#parameters-17)
|
|
63
|
+
* [Examples](#examples-10)
|
|
64
|
+
* [signP2SHTransaction](#signp2shtransaction-1)
|
|
65
|
+
* [Parameters](#parameters-18)
|
|
66
|
+
* [Examples](#examples-11)
|
|
67
|
+
* [CreateTransactionArg](#createtransactionarg)
|
|
68
|
+
* [Properties](#properties)
|
|
69
|
+
* [AddressFormat](#addressformat)
|
|
70
|
+
* [AppClient](#appclient)
|
|
71
|
+
* [Parameters](#parameters-19)
|
|
72
|
+
* [ClientCommandInterpreter](#clientcommandinterpreter)
|
|
73
|
+
* [Parameters](#parameters-20)
|
|
74
|
+
* [MerkelizedPsbt](#merkelizedpsbt)
|
|
75
|
+
* [Parameters](#parameters-21)
|
|
76
|
+
* [Merkle](#merkle)
|
|
77
|
+
* [Parameters](#parameters-22)
|
|
78
|
+
* [MerkleMap](#merklemap)
|
|
79
|
+
* [Parameters](#parameters-23)
|
|
80
|
+
* [WalletPolicy](#walletpolicy)
|
|
81
|
+
* [Parameters](#parameters-24)
|
|
82
|
+
* [extract](#extract)
|
|
83
|
+
* [Parameters](#parameters-25)
|
|
84
|
+
* [finalize](#finalize)
|
|
85
|
+
* [Parameters](#parameters-26)
|
|
86
|
+
* [clearFinalizedInput](#clearfinalizedinput)
|
|
87
|
+
* [Parameters](#parameters-27)
|
|
88
|
+
* [writePush](#writepush)
|
|
89
|
+
* [Parameters](#parameters-28)
|
|
90
|
+
* [PsbtV2](#psbtv2)
|
|
91
|
+
* [serializeTransactionOutputs](#serializetransactionoutputs-1)
|
|
92
|
+
* [Parameters](#parameters-29)
|
|
93
|
+
* [Examples](#examples-12)
|
|
94
|
+
* [SignP2SHTransactionArg](#signp2shtransactionarg)
|
|
95
|
+
* [Properties](#properties-1)
|
|
96
|
+
* [TransactionInput](#transactioninput)
|
|
97
|
+
* [TransactionOutput](#transactionoutput)
|
|
98
|
+
* [Transaction](#transaction)
|
|
48
99
|
|
|
49
100
|
### Btc
|
|
50
101
|
|
|
@@ -52,8 +103,8 @@ Bitcoin API.
|
|
|
52
103
|
|
|
53
104
|
#### Parameters
|
|
54
105
|
|
|
55
|
-
|
|
56
|
-
|
|
106
|
+
* `transport` **Transport**
|
|
107
|
+
* `scrambleKey` (optional, default `"BTC"`)
|
|
57
108
|
|
|
58
109
|
#### Examples
|
|
59
110
|
|
|
@@ -62,21 +113,32 @@ import Btc from "@ledgerhq/hw-app-btc";
|
|
|
62
113
|
const btc = new Btc(transport)
|
|
63
114
|
```
|
|
64
115
|
|
|
116
|
+
#### getWalletXpub
|
|
117
|
+
|
|
118
|
+
Get an XPUB with a ledger device
|
|
119
|
+
|
|
120
|
+
##### Parameters
|
|
121
|
+
|
|
122
|
+
* `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'`
|
|
123
|
+
* xpubVersion: the XPUBVersion of the coin used. (use @ledgerhq/currencies if needed)
|
|
124
|
+
|
|
125
|
+
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
|
|
126
|
+
|
|
65
127
|
#### getWalletPublicKey
|
|
66
128
|
|
|
67
129
|
##### Parameters
|
|
68
130
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
131
|
+
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path
|
|
132
|
+
* `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
|
|
133
|
+
* `options` an object with optional these fields:* verify (boolean) will ask user to confirm the address on the device
|
|
72
134
|
|
|
73
|
-
|
|
135
|
+
* 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
136
|
|
|
75
|
-
|
|
137
|
+
* p2sh format with 49' paths
|
|
76
138
|
|
|
77
|
-
|
|
139
|
+
* bech32 format with 84' paths
|
|
78
140
|
|
|
79
|
-
|
|
141
|
+
* cashaddr in case of Bitcoin Cash
|
|
80
142
|
|
|
81
143
|
##### Examples
|
|
82
144
|
|
|
@@ -85,7 +147,7 @@ btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
|
|
|
85
147
|
btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
86
148
|
```
|
|
87
149
|
|
|
88
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
150
|
+
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
151
|
|
|
90
152
|
#### signMessageNew
|
|
91
153
|
|
|
@@ -93,8 +155,8 @@ You can sign a message according to the Bitcoin Signature format and retrieve v,
|
|
|
93
155
|
|
|
94
156
|
##### Parameters
|
|
95
157
|
|
|
96
|
-
|
|
97
|
-
|
|
158
|
+
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
159
|
+
* `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
98
160
|
|
|
99
161
|
##### Examples
|
|
100
162
|
|
|
@@ -106,7 +168,7 @@ console.log("Signature : " + signature);
|
|
|
106
168
|
}).catch(function(ex) {console.log(ex);});
|
|
107
169
|
```
|
|
108
170
|
|
|
109
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
171
|
+
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
172
|
|
|
111
173
|
#### createPaymentTransactionNew
|
|
112
174
|
|
|
@@ -114,25 +176,26 @@ To sign a transaction involving standard (P2PKH) inputs, call createTransaction
|
|
|
114
176
|
|
|
115
177
|
##### Parameters
|
|
116
178
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
179
|
+
* `arg` **[CreateTransactionArg](#createtransactionarg)**
|
|
180
|
+
* `inputs` is an array of \[ transaction, output_index, optional redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
|
|
181
|
+
* output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
182
|
+
* redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
183
|
+
* sequence is the sequence number to use for this input (when using RBF), or non present
|
|
184
|
+
* `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
185
|
+
* `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
186
|
+
* `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
|
|
187
|
+
* `lockTime` is the optional lockTime of the transaction to sign, or default (0)
|
|
188
|
+
* `sigHashType` is the hash type of the transaction to sign, or default (all)
|
|
189
|
+
* `segwit` is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
|
|
190
|
+
* `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)
|
|
191
|
+
* `additionals` list of additionnal options* "bech32" for spending native segwit outputs
|
|
192
|
+
* "bech32m" for spending segwit v1+ outputs
|
|
193
|
+
* "abc" for bch
|
|
194
|
+
* "gold" for btg
|
|
195
|
+
* "bipxxx" for using BIPxxx
|
|
196
|
+
* "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
197
|
+
* `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
|
|
198
|
+
* `useTrustedInputForSegwit` trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
|
|
136
199
|
|
|
137
200
|
##### Examples
|
|
138
201
|
|
|
@@ -144,7 +207,7 @@ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d
|
|
|
144
207
|
}).then(res => ...);
|
|
145
208
|
```
|
|
146
209
|
|
|
147
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
210
|
+
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
211
|
|
|
149
212
|
#### signP2SHTransaction
|
|
150
213
|
|
|
@@ -152,15 +215,15 @@ To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransactio
|
|
|
152
215
|
|
|
153
216
|
##### Parameters
|
|
154
217
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
218
|
+
* `arg` **[SignP2SHTransactionArg](#signp2shtransactionarg)**
|
|
219
|
+
* `inputs` is an array of \[ transaction, output_index, redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
|
|
220
|
+
* output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
221
|
+
* redeem script is the mandatory redeem script associated to the current P2SH input
|
|
222
|
+
* sequence is the sequence number to use for this input (when using RBF), or non present
|
|
223
|
+
* `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
224
|
+
* `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
|
|
225
|
+
* `lockTime` is the optional lockTime of the transaction to sign, or default (0)
|
|
226
|
+
* `sigHashType` is the hash type of the transaction to sign, or default (all)
|
|
164
227
|
|
|
165
228
|
##### Examples
|
|
166
229
|
|
|
@@ -172,7 +235,7 @@ outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d
|
|
|
172
235
|
}).then(result => ...);
|
|
173
236
|
```
|
|
174
237
|
|
|
175
|
-
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)
|
|
238
|
+
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
239
|
|
|
177
240
|
#### splitTransaction
|
|
178
241
|
|
|
@@ -180,11 +243,11 @@ For each UTXO included in your transaction, create a transaction object from the
|
|
|
180
243
|
|
|
181
244
|
##### Parameters
|
|
182
245
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
246
|
+
* `transactionHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
247
|
+
* `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`)
|
|
248
|
+
* `hasTimestamp` (optional, default `false`)
|
|
249
|
+
* `hasExtraData` (optional, default `false`)
|
|
250
|
+
* `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
251
|
|
|
189
252
|
##### Examples
|
|
190
253
|
|
|
@@ -198,7 +261,7 @@ Returns **[Transaction](#transaction)**
|
|
|
198
261
|
|
|
199
262
|
##### Parameters
|
|
200
263
|
|
|
201
|
-
|
|
264
|
+
* `t` **[Transaction](#transaction)**
|
|
202
265
|
|
|
203
266
|
##### Examples
|
|
204
267
|
|
|
@@ -209,39 +272,471 @@ const outputScript = btc.serializeTransactionOutputs(tx1).toString('hex');
|
|
|
209
272
|
|
|
210
273
|
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
|
|
211
274
|
|
|
275
|
+
### getWalletPublicKey
|
|
276
|
+
|
|
277
|
+
Definition: A "normal path" is a prefix of a standard path where all
|
|
278
|
+
the hardened steps of the standard path are included. For example, the
|
|
279
|
+
paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
|
|
280
|
+
is not. m/'199/1'/17'/0/1 is not a normal path either.
|
|
281
|
+
|
|
282
|
+
There's a compatiblity issue between old and new app: When exporting
|
|
283
|
+
the key of a non-normal path with verify=false, the new app would
|
|
284
|
+
return an error, whereas the old app would return the key.
|
|
285
|
+
|
|
286
|
+
See
|
|
287
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey>
|
|
288
|
+
|
|
289
|
+
If format bech32m is used, we'll not use old, because it doesn't
|
|
290
|
+
support it.
|
|
291
|
+
|
|
292
|
+
When to use new (given the app supports it)
|
|
293
|
+
|
|
294
|
+
* format is bech32m or
|
|
295
|
+
* path is normal or
|
|
296
|
+
* verify is true
|
|
297
|
+
|
|
298
|
+
Otherwise use old.
|
|
299
|
+
|
|
300
|
+
### BtcNew
|
|
301
|
+
|
|
302
|
+
This class implements the same interface as BtcOld (formerly
|
|
303
|
+
named Btc), but interacts with Bitcoin hardware app version 2+
|
|
304
|
+
which uses a totally new APDU protocol. This new
|
|
305
|
+
protocol is documented at
|
|
306
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md>
|
|
307
|
+
|
|
308
|
+
Since the interface must remain compatible with BtcOld, the methods
|
|
309
|
+
of this class are quite clunky, because it needs to adapt legacy
|
|
310
|
+
input data into the PSBT process. In the future, a new interface should
|
|
311
|
+
be developed that exposes PSBT to the outer world, which would render
|
|
312
|
+
a much cleaner implementation.
|
|
313
|
+
|
|
314
|
+
#### Parameters
|
|
315
|
+
|
|
316
|
+
* ``
|
|
317
|
+
|
|
318
|
+
#### getWalletXpub
|
|
319
|
+
|
|
320
|
+
This is a new method that allow users to get an xpub at a standard path.
|
|
321
|
+
Standard paths are described at
|
|
322
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description>
|
|
323
|
+
|
|
324
|
+
This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
|
|
325
|
+
M/44'/N'/x'/\*\*
|
|
326
|
+
M/48'/N'/x'/y'/\*\*
|
|
327
|
+
M/49'/N'/x'/\*\*
|
|
328
|
+
M/84'/N'/x'/\*\*
|
|
329
|
+
M/86'/N'/x'/\*\*
|
|
330
|
+
|
|
331
|
+
The method was added because of added security in the hardware app v2+. The
|
|
332
|
+
new hardware app will allow export of any xpub up to and including the
|
|
333
|
+
deepest hardened key of standard derivation paths, whereas the old app
|
|
334
|
+
would allow export of any key.
|
|
335
|
+
|
|
336
|
+
This caused an issue for callers of this class, who only had
|
|
337
|
+
getWalletPublicKey() to call which means they have to constuct xpub
|
|
338
|
+
themselves:
|
|
339
|
+
|
|
340
|
+
Suppose a user of this class wants to create an account xpub on a standard
|
|
341
|
+
path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
|
|
342
|
+
by requesting the parent key M/44'/0'. The new app won't allow that, because
|
|
343
|
+
it only allows exporting deepest level hardened path. So the options are to
|
|
344
|
+
allow requesting M/44'/0' from the app, or to add a new function
|
|
345
|
+
"getWalletXpub".
|
|
346
|
+
|
|
347
|
+
We opted for adding a new function, which can greatly simplify client code.
|
|
348
|
+
|
|
349
|
+
##### Parameters
|
|
350
|
+
|
|
351
|
+
* `$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)}**
|
|
352
|
+
|
|
353
|
+
* `$0.path`
|
|
354
|
+
* `$0.xpubVersion`
|
|
355
|
+
|
|
356
|
+
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)>**
|
|
357
|
+
|
|
358
|
+
#### getWalletPublicKey
|
|
359
|
+
|
|
360
|
+
This method returns a public key, a bitcoin address, and and a chaincode
|
|
361
|
+
for a specific derivation path.
|
|
362
|
+
|
|
363
|
+
Limitation: If the path is not a leaf node of a standard path, the address
|
|
364
|
+
will be the empty string "", see this.getWalletAddress() for details.
|
|
365
|
+
|
|
366
|
+
##### Parameters
|
|
367
|
+
|
|
368
|
+
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
369
|
+
* `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
|
|
370
|
+
|
|
371
|
+
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)}>**
|
|
372
|
+
|
|
373
|
+
#### createPaymentTransactionNew
|
|
374
|
+
|
|
375
|
+
Build and sign a transaction. See Btc.createPaymentTransactionNew for
|
|
376
|
+
details on how to use this method.
|
|
377
|
+
|
|
378
|
+
This method will convert the legacy arguments, CreateTransactionArg, into
|
|
379
|
+
a psbt which is finally signed and finalized, and the extracted fully signed
|
|
380
|
+
transaction is returned.
|
|
381
|
+
|
|
382
|
+
##### Parameters
|
|
383
|
+
|
|
384
|
+
* `arg` **[CreateTransactionArg](#createtransactionarg)**
|
|
385
|
+
|
|
386
|
+
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)>**
|
|
387
|
+
|
|
388
|
+
### outputScriptOf
|
|
389
|
+
|
|
390
|
+
Generates a single signature scriptPubKey (output script) from a public key.
|
|
391
|
+
This is done differently depending on account type.
|
|
392
|
+
|
|
393
|
+
If accountType is p2tr, the public key must be a 32 byte x-only taproot
|
|
394
|
+
pubkey, otherwise it's expected to be a 33 byte ecdsa compressed pubkey.
|
|
395
|
+
|
|
396
|
+
#### Parameters
|
|
397
|
+
|
|
398
|
+
* `pubkey` **[Buffer](https://nodejs.org/api/buffer.html)**
|
|
399
|
+
* `accountType` **AccountType**
|
|
400
|
+
|
|
401
|
+
Returns **{script: [Buffer](https://nodejs.org/api/buffer.html), redeemScript: [Buffer](https://nodejs.org/api/buffer.html)?}**
|
|
402
|
+
|
|
403
|
+
### getTaprootOutputKey
|
|
404
|
+
|
|
405
|
+
Calculates a taproot output key from an internal key. This output key will be
|
|
406
|
+
used as witness program in a taproot output. The internal key is tweaked
|
|
407
|
+
according to recommendation in BIP341:
|
|
408
|
+
<https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#cite_ref-22-0>
|
|
409
|
+
|
|
410
|
+
#### Parameters
|
|
411
|
+
|
|
412
|
+
* `internalPubkey` **[Buffer](https://nodejs.org/api/buffer.html)** A 32 byte x-only taproot internal key
|
|
413
|
+
|
|
414
|
+
Returns **[Buffer](https://nodejs.org/api/buffer.html)** The output key
|
|
415
|
+
|
|
416
|
+
### BtcOld
|
|
417
|
+
|
|
418
|
+
Bitcoin API.
|
|
419
|
+
|
|
420
|
+
#### Parameters
|
|
421
|
+
|
|
422
|
+
* ``
|
|
423
|
+
|
|
424
|
+
#### Examples
|
|
425
|
+
|
|
426
|
+
```javascript
|
|
427
|
+
import Btc from "@ledgerhq/hw-app-btc";
|
|
428
|
+
const btc = new Btc(transport)
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
#### getWalletPublicKey
|
|
432
|
+
|
|
433
|
+
##### Parameters
|
|
434
|
+
|
|
435
|
+
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a BIP 32 path
|
|
436
|
+
* `opts` **{verify: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?, format: [AddressFormat](#addressformat)?}?**
|
|
437
|
+
* `options` an object with optional these fields:* verify (boolean) will ask user to confirm the address on the device
|
|
438
|
+
|
|
439
|
+
* format ("legacy" | "p2sh" | "bech32" | "cashaddr") to use different bitcoin address formatter.NB The normal usage is to use:* legacy format with 44' paths
|
|
440
|
+
|
|
441
|
+
* p2sh format with 49' paths
|
|
442
|
+
|
|
443
|
+
* bech32 format with 173' paths
|
|
444
|
+
|
|
445
|
+
* cashaddr in case of Bitcoin Cash
|
|
446
|
+
|
|
447
|
+
##### Examples
|
|
448
|
+
|
|
449
|
+
```javascript
|
|
450
|
+
btc.getWalletPublicKey("44'/0'/0'/0/0").then(o => o.bitcoinAddress)
|
|
451
|
+
btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
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)}>**
|
|
455
|
+
|
|
456
|
+
#### signMessageNew
|
|
457
|
+
|
|
458
|
+
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.
|
|
459
|
+
|
|
460
|
+
##### Parameters
|
|
461
|
+
|
|
462
|
+
* `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
463
|
+
* `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
464
|
+
|
|
465
|
+
##### Examples
|
|
466
|
+
|
|
467
|
+
```javascript
|
|
468
|
+
btc.signMessageNew_async("44'/60'/0'/0'/0", Buffer.from("test").toString("hex")).then(function(result) {
|
|
469
|
+
var v = result['v'] + 27 + 4;
|
|
470
|
+
var signature = Buffer.from(v.toString(16) + result['r'] + result['s'], 'hex').toString('base64');
|
|
471
|
+
console.log("Signature : " + signature);
|
|
472
|
+
}).catch(function(ex) {console.log(ex);});
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
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)}>**
|
|
476
|
+
|
|
477
|
+
#### createPaymentTransactionNew
|
|
478
|
+
|
|
479
|
+
To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
|
|
480
|
+
|
|
481
|
+
##### Parameters
|
|
482
|
+
|
|
483
|
+
* `arg` **[CreateTransactionArg](#createtransactionarg)**
|
|
484
|
+
* `inputs` is an array of \[ transaction, output_index, optional redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
|
|
485
|
+
* output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
486
|
+
* redeem script is the optional redeem script to use when consuming a Segregated Witness input
|
|
487
|
+
* sequence is the sequence number to use for this input (when using RBF), or non present
|
|
488
|
+
* `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
489
|
+
* `changePath` is an optional BIP 32 path pointing to the path to the public key used to compute the change address
|
|
490
|
+
* `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
|
|
491
|
+
* `lockTime` is the optional lockTime of the transaction to sign, or default (0)
|
|
492
|
+
* `sigHashType` is the hash type of the transaction to sign, or default (all)
|
|
493
|
+
* `segwit` is an optional boolean indicating wether to use segwit or not
|
|
494
|
+
* `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)
|
|
495
|
+
* `additionals` list of additionnal options* "bech32" for spending native segwit outputs
|
|
496
|
+
* "abc" for bch
|
|
497
|
+
* "gold" for btg
|
|
498
|
+
* "bipxxx" for using BIPxxx
|
|
499
|
+
* "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
|
|
500
|
+
* `expiryHeight` is an optional Buffer for zec overwinter / sapling Txs
|
|
501
|
+
* `useTrustedInputForSegwit` trust inputs for segwit transactions
|
|
502
|
+
|
|
503
|
+
##### Examples
|
|
504
|
+
|
|
505
|
+
```javascript
|
|
506
|
+
btc.createTransaction({
|
|
507
|
+
inputs: [ [tx1, 1] ],
|
|
508
|
+
associatedKeysets: ["0'/0/0"],
|
|
509
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
510
|
+
}).then(res => ...);
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
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
|
|
514
|
+
|
|
515
|
+
#### signP2SHTransaction
|
|
516
|
+
|
|
517
|
+
To obtain the signature of multisignature (P2SH) inputs, call signP2SHTransaction_async with the folowing parameters
|
|
518
|
+
|
|
519
|
+
##### Parameters
|
|
520
|
+
|
|
521
|
+
* `arg` **[SignP2SHTransactionArg](#signp2shtransactionarg)**
|
|
522
|
+
* `inputs` is an array of \[ transaction, output_index, redeem script, optional sequence ] where* transaction is the previously computed transaction object for this UTXO
|
|
523
|
+
* output_index is the output in the transaction used as input for this UTXO (counting from 0)
|
|
524
|
+
* redeem script is the mandatory redeem script associated to the current P2SH input
|
|
525
|
+
* sequence is the sequence number to use for this input (when using RBF), or non present
|
|
526
|
+
* `associatedKeysets` is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
|
|
527
|
+
* `outputScriptHex` is the hexadecimal serialized outputs of the transaction to sign
|
|
528
|
+
* `lockTime` is the optional lockTime of the transaction to sign, or default (0)
|
|
529
|
+
* `sigHashType` is the hash type of the transaction to sign, or default (all)
|
|
530
|
+
|
|
531
|
+
##### Examples
|
|
532
|
+
|
|
533
|
+
```javascript
|
|
534
|
+
btc.signP2SHTransaction({
|
|
535
|
+
inputs: [ [tx, 1, "52210289b4a3ad52a919abd2bdd6920d8a6879b1e788c38aa76f0440a6f32a9f1996d02103a3393b1439d1693b063482c04bd40142db97bdf139eedd1b51ffb7070a37eac321030b9a409a1e476b0d5d17b804fcdb81cf30f9b99c6f3ae1178206e08bc500639853ae"] ],
|
|
536
|
+
associatedKeysets: ["0'/0/0"],
|
|
537
|
+
outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
|
|
538
|
+
}).then(result => ...);
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
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
|
|
542
|
+
|
|
212
543
|
### CreateTransactionArg
|
|
213
544
|
|
|
214
|
-
Type: {inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
|
|
545
|
+
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
546
|
|
|
216
547
|
#### Properties
|
|
217
548
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
549
|
+
* `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))]>**
|
|
550
|
+
* `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)>**
|
|
551
|
+
* `changePath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
|
552
|
+
* `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
553
|
+
* `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
|
554
|
+
* `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
|
555
|
+
* `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
|
556
|
+
* `initialTimestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
|
557
|
+
* `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)>**
|
|
558
|
+
* `expiryHeight` **[Buffer](https://nodejs.org/api/buffer.html)?**
|
|
559
|
+
* `useTrustedInputForSegwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
|
560
|
+
* `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?**
|
|
561
|
+
* `onDeviceSignatureRequested` **function (): void?**
|
|
562
|
+
* `onDeviceSignatureGranted` **function (): void?**
|
|
232
563
|
|
|
233
564
|
### AddressFormat
|
|
234
565
|
|
|
235
566
|
address format is one of legacy | p2sh | bech32 | cashaddr
|
|
236
567
|
|
|
237
|
-
Type: (`"legacy"`
|
|
568
|
+
Type: (`"legacy"` | `"p2sh"` | `"bech32"` | `"bech32m"` | `"cashaddr"`)
|
|
569
|
+
|
|
570
|
+
### AppClient
|
|
571
|
+
|
|
572
|
+
This class encapsulates the APDU protocol documented at
|
|
573
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md>
|
|
574
|
+
|
|
575
|
+
#### Parameters
|
|
576
|
+
|
|
577
|
+
* `transport` **Transport**
|
|
578
|
+
|
|
579
|
+
### ClientCommandInterpreter
|
|
580
|
+
|
|
581
|
+
This class will dispatch a client command coming from the hardware device to
|
|
582
|
+
the appropriate client command implementation. Those client commands
|
|
583
|
+
typically requests data from a merkle tree or merkelized maps.
|
|
584
|
+
|
|
585
|
+
A ClientCommandInterpreter is prepared by adding the merkle trees and
|
|
586
|
+
merkelized maps it should be able to serve to the hardware device. This class
|
|
587
|
+
doesn't know anything about the semantics of the data it holds, it just
|
|
588
|
+
serves merkle data. It doesn't even know in what context it is being
|
|
589
|
+
executed, ie SignPsbt, getWalletAddress, etc.
|
|
590
|
+
|
|
591
|
+
If the command yelds results to the client, as signPsbt does, the yielded
|
|
592
|
+
data will be accessible after the command completed by calling getYielded(),
|
|
593
|
+
which will return the yields in the same order as they came in.
|
|
594
|
+
|
|
595
|
+
#### Parameters
|
|
596
|
+
|
|
597
|
+
* `progressCallback` **function (): void**
|
|
598
|
+
|
|
599
|
+
### MerkelizedPsbt
|
|
600
|
+
|
|
601
|
+
**Extends PsbtV2**
|
|
602
|
+
|
|
603
|
+
This class merkelizes a PSBTv2, by merkelizing the different
|
|
604
|
+
maps of the psbt. This is used during the transaction signing process,
|
|
605
|
+
where the hardware app can request specific parts of the psbt from the
|
|
606
|
+
client code and be sure that the response data actually belong to the psbt.
|
|
607
|
+
The reason for this is the limited amount of memory available to the app,
|
|
608
|
+
so it can't always store the full psbt in memory.
|
|
609
|
+
|
|
610
|
+
The signing process is documented at
|
|
611
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#sign_psbt>
|
|
612
|
+
|
|
613
|
+
#### Parameters
|
|
614
|
+
|
|
615
|
+
* `psbt` **[PsbtV2](#psbtv2)**
|
|
616
|
+
|
|
617
|
+
### Merkle
|
|
618
|
+
|
|
619
|
+
This class implements the merkle tree used by Ledger Bitcoin app v2+,
|
|
620
|
+
which is documented at
|
|
621
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md>
|
|
622
|
+
|
|
623
|
+
#### Parameters
|
|
624
|
+
|
|
625
|
+
* `leaves` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Buffer](https://nodejs.org/api/buffer.html)>**
|
|
626
|
+
* `hasher` **function (buf: [Buffer](https://nodejs.org/api/buffer.html)): [Buffer](https://nodejs.org/api/buffer.html)** (optional, default `crypto.sha256`)
|
|
627
|
+
|
|
628
|
+
### MerkleMap
|
|
629
|
+
|
|
630
|
+
This implements "Merkelized Maps", documented at
|
|
631
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/merkle.md#merkleized-maps>
|
|
632
|
+
|
|
633
|
+
A merkelized map consist of two merkle trees, one for the keys of
|
|
634
|
+
a map and one for the values of the same map, thus the two merkle
|
|
635
|
+
trees have the same shape. The commitment is the number elements
|
|
636
|
+
in the map followed by the keys' merkle root followed by the
|
|
637
|
+
values' merkle root.
|
|
638
|
+
|
|
639
|
+
#### Parameters
|
|
640
|
+
|
|
641
|
+
* `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
|
|
642
|
+
* `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
|
|
643
|
+
|
|
644
|
+
### WalletPolicy
|
|
645
|
+
|
|
646
|
+
The Bitcon hardware app uses a descriptors-like thing to describe
|
|
647
|
+
how to construct output scripts from keys. A "Wallet Policy" consists
|
|
648
|
+
of a "Descriptor Template" and a list of "keys". A key is basically
|
|
649
|
+
a serialized BIP32 extended public key with some added derivation path
|
|
650
|
+
information. This is documented at
|
|
651
|
+
<https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/wallet.md>
|
|
652
|
+
|
|
653
|
+
#### Parameters
|
|
654
|
+
|
|
655
|
+
* `descriptorTemplate` **DefaultDescriptorTemplate**
|
|
656
|
+
* `key` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
657
|
+
|
|
658
|
+
### extract
|
|
659
|
+
|
|
660
|
+
This implements the "Transaction Extractor" role of BIP370 (PSBTv2
|
|
661
|
+
<https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#transaction-extractor>). However
|
|
662
|
+
the role is partially documented in BIP174 (PSBTv0
|
|
663
|
+
<https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#transaction-extractor>).
|
|
664
|
+
|
|
665
|
+
#### Parameters
|
|
666
|
+
|
|
667
|
+
* `psbt` **[PsbtV2](#psbtv2)**
|
|
668
|
+
|
|
669
|
+
Returns **[Buffer](https://nodejs.org/api/buffer.html)**
|
|
670
|
+
|
|
671
|
+
### finalize
|
|
672
|
+
|
|
673
|
+
This roughly implements the "input finalizer" role of BIP370 (PSBTv2
|
|
674
|
+
<https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki>). However
|
|
675
|
+
the role is documented in BIP174 (PSBTv0
|
|
676
|
+
<https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>).
|
|
677
|
+
|
|
678
|
+
Verify that all inputs have a signature, and set inputFinalScriptwitness
|
|
679
|
+
and/or inputFinalScriptSig depending on the type of the spent outputs. Clean
|
|
680
|
+
fields that aren't useful anymore, partial signatures, redeem script and
|
|
681
|
+
derivation paths.
|
|
682
|
+
|
|
683
|
+
#### Parameters
|
|
684
|
+
|
|
685
|
+
* `psbt` **[PsbtV2](#psbtv2)** The psbt with all signatures added as partial sigs, either
|
|
686
|
+
through PSBT_IN_PARTIAL_SIG or PSBT_IN_TAP_KEY_SIG
|
|
687
|
+
|
|
688
|
+
Returns **void**
|
|
689
|
+
|
|
690
|
+
### clearFinalizedInput
|
|
691
|
+
|
|
692
|
+
Deletes fields that are no longer neccesary from the psbt.
|
|
693
|
+
|
|
694
|
+
Note, the spec doesn't say anything about removing ouput fields
|
|
695
|
+
like PSBT_OUT_BIP32\_DERIVATION_PATH and others, so we keep them
|
|
696
|
+
without actually knowing why. I think we should remove them too.
|
|
697
|
+
|
|
698
|
+
#### Parameters
|
|
699
|
+
|
|
700
|
+
* `psbt` **[PsbtV2](#psbtv2)**
|
|
701
|
+
* `inputIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
|
|
702
|
+
|
|
703
|
+
### writePush
|
|
704
|
+
|
|
705
|
+
Writes a script push operation to buf, which looks different
|
|
706
|
+
depending on the size of the data. See
|
|
707
|
+
<https://en.bitcoin.it/wiki/Script#Constants>
|
|
708
|
+
|
|
709
|
+
#### Parameters
|
|
710
|
+
|
|
711
|
+
* `buf` **BufferWriter** the BufferWriter to write to
|
|
712
|
+
* `data` **[Buffer](https://nodejs.org/api/buffer.html)** the Buffer to be pushed.
|
|
713
|
+
|
|
714
|
+
### PsbtV2
|
|
715
|
+
|
|
716
|
+
Implements Partially Signed Bitcoin Transaction version 2, BIP370, as
|
|
717
|
+
documented at <https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki>
|
|
718
|
+
and <https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki>
|
|
719
|
+
|
|
720
|
+
A psbt is a data structure that can carry all relevant information about a
|
|
721
|
+
transaction through all stages of the signing process. From constructing an
|
|
722
|
+
unsigned transaction to extracting the final serialized transaction ready for
|
|
723
|
+
broadcast.
|
|
724
|
+
|
|
725
|
+
This implementation is limited to what's needed in ledgerjs to carry out its
|
|
726
|
+
duties, which means that support for features like multisig or taproot script
|
|
727
|
+
path spending are not implemented. Specifically, it supports p2pkh,
|
|
728
|
+
p2wpkhWrappedInP2sh, p2wpkh and p2tr key path spending.
|
|
729
|
+
|
|
730
|
+
This class is made purposefully dumb, so it's easy to add support for
|
|
731
|
+
complemantary fields as needed in the future.
|
|
238
732
|
|
|
239
733
|
### serializeTransactionOutputs
|
|
240
734
|
|
|
241
735
|
#### Parameters
|
|
242
736
|
|
|
243
|
-
|
|
244
|
-
|
|
737
|
+
* `$0` **[Transaction](#transaction)**
|
|
738
|
+
|
|
739
|
+
* `$0.outputs`
|
|
245
740
|
|
|
246
741
|
#### Examples
|
|
247
742
|
|
|
@@ -254,17 +749,17 @@ Returns **[Buffer](https://nodejs.org/api/buffer.html)**
|
|
|
254
749
|
|
|
255
750
|
### SignP2SHTransactionArg
|
|
256
751
|
|
|
257
|
-
Type: {inputs: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)
|
|
752
|
+
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
753
|
|
|
259
754
|
#### Properties
|
|
260
755
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
756
|
+
* `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))]>**
|
|
757
|
+
* `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)>**
|
|
758
|
+
* `outputScriptHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
|
759
|
+
* `lockTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
|
760
|
+
* `sigHashType` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
|
761
|
+
* `segwit` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
|
762
|
+
* `transactionVersion` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?**
|
|
268
763
|
|
|
269
764
|
### TransactionInput
|
|
270
765
|
|