1 | <img src="https://user-images.githubusercontent.com/211411/34776833-6f1ef4da-f618-11e7-8b13-f0697901d6a8.png" height="100" />
|
2 |
|
3 | [Github](https://github.com/LedgerHQ/ledgerjs/),
|
4 | [Ledger Devs Slack](https://ledger-dev.slack.com/)
|
5 |
|
6 | ## @ledgerhq/hw-app-eth
|
7 |
|
8 | Ledger Hardware Wallet ETH JavaScript bindings.
|
9 |
|
10 | ## API
|
11 |
|
12 |
|
13 |
|
14 | #### Table of Contents
|
15 |
|
16 | - [byContractAddress](#bycontractaddress)
|
17 | - [Parameters](#parameters)
|
18 | - [list](#list)
|
19 | - [Eth](#eth)
|
20 | - [Parameters](#parameters-1)
|
21 | - [Examples](#examples)
|
22 | - [getAddress](#getaddress)
|
23 | - [Parameters](#parameters-2)
|
24 | - [Examples](#examples-1)
|
25 | - [provideERC20TokenInformation](#provideerc20tokeninformation)
|
26 | - [Parameters](#parameters-3)
|
27 | - [Examples](#examples-2)
|
28 | - [signTransaction](#signtransaction)
|
29 | - [Parameters](#parameters-4)
|
30 | - [Examples](#examples-3)
|
31 | - [getAppConfiguration](#getappconfiguration)
|
32 | - [signPersonalMessage](#signpersonalmessage)
|
33 | - [Parameters](#parameters-5)
|
34 | - [Examples](#examples-4)
|
35 | - [signEIP712HashedMessage](#signeip712hashedmessage)
|
36 | - [Parameters](#parameters-6)
|
37 | - [Examples](#examples-5)
|
38 | - [starkGetPublicKey](#starkgetpublickey)
|
39 | - [Parameters](#parameters-7)
|
40 | - [starkSignOrder](#starksignorder)
|
41 | - [Parameters](#parameters-8)
|
42 | - [starkSignOrder_v2](#starksignorder_v2)
|
43 | - [Parameters](#parameters-9)
|
44 | - [starkSignTransfer](#starksigntransfer)
|
45 | - [Parameters](#parameters-10)
|
46 | - [starkSignTransfer_v2](#starksigntransfer_v2)
|
47 | - [Parameters](#parameters-11)
|
48 | - [starkProvideQuantum](#starkprovidequantum)
|
49 | - [Parameters](#parameters-12)
|
50 | - [starkProvideQuantum_v2](#starkprovidequantum_v2)
|
51 | - [Parameters](#parameters-13)
|
52 | - [starkUnsafeSign](#starkunsafesign)
|
53 | - [Parameters](#parameters-14)
|
54 | - [eth2GetPublicKey](#eth2getpublickey)
|
55 | - [Parameters](#parameters-15)
|
56 | - [Examples](#examples-6)
|
57 | - [eth2SetWithdrawalIndex](#eth2setwithdrawalindex)
|
58 | - [Parameters](#parameters-16)
|
59 |
|
60 | ### byContractAddress
|
61 |
|
62 | Retrieve the token information by a given contract address if any
|
63 |
|
64 | #### Parameters
|
65 |
|
66 | - `contract` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
67 |
|
68 | Returns **TokenInfo?**
|
69 |
|
70 | ### list
|
71 |
|
72 | list all the ERC20 tokens informations
|
73 |
|
74 | Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<TokenInfo>**
|
75 |
|
76 | ### Eth
|
77 |
|
78 | Ethereum API
|
79 |
|
80 | #### Parameters
|
81 |
|
82 | - `transport` **Transport<any>**
|
83 | - `scrambleKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** (optional, default `"w0w"`)
|
84 |
|
85 | #### Examples
|
86 |
|
87 | ```javascript
|
88 | import Eth from "@ledgerhq/hw-app-eth";
|
89 | const eth = new Eth(transport)
|
90 | ```
|
91 |
|
92 | #### getAddress
|
93 |
|
94 | get Ethereum address for a given BIP 32 path.
|
95 |
|
96 | ##### Parameters
|
97 |
|
98 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
99 | - `boolDisplay` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
100 | - `boolChaincode` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
101 |
|
102 | ##### Examples
|
103 |
|
104 | ```javascript
|
105 | eth.getAddress("44'/60'/0'/0/0").then(o => o.address)
|
106 | ```
|
107 |
|
108 | 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), address: [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)?}>** an object with a publicKey, address and (optionally) chainCode
|
109 |
|
110 | #### provideERC20TokenInformation
|
111 |
|
112 | This commands provides a trusted description of an ERC 20 token
|
113 | to associate a contract address with a ticker and number of decimals.
|
114 |
|
115 | It shall be run immediately before performing a transaction involving a contract
|
116 | calling this contract address to display the proper token information to the user if necessary.
|
117 |
|
118 | ##### Parameters
|
119 |
|
120 | - `info` **any** : a blob from "erc20.js" utilities that contains all token information.
|
121 | - `info.data`
|
122 |
|
123 | ##### Examples
|
124 |
|
125 | ```javascript
|
126 | import { byContractAddress } from "@ledgerhq/hw-app-eth/erc20"
|
127 | const zrxInfo = byContractAddress("0xe41d2489571d322189246dafa5ebde1f4699f498")
|
128 | if (zrxInfo) await appEth.provideERC20TokenInformation(zrxInfo)
|
129 | const signed = await appEth.signTransaction(path, rawTxHex)
|
130 | ```
|
131 |
|
132 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>**
|
133 |
|
134 | #### signTransaction
|
135 |
|
136 | You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign
|
137 |
|
138 | ##### Parameters
|
139 |
|
140 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
141 | - `rawTxHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
142 |
|
143 | ##### Examples
|
144 |
|
145 | ```javascript
|
146 | eth.signTransaction("44'/60'/0'/0/0", "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080").then(result => ...)
|
147 | ```
|
148 |
|
149 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), v: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
|
150 |
|
151 | #### getAppConfiguration
|
152 |
|
153 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<{arbitraryDataEnabled: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), erc20ProvisioningNecessary: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), starkEnabled: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), starkv2Supported: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), version: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
|
154 |
|
155 | #### signPersonalMessage
|
156 |
|
157 | You can sign a message according to eth_sign RPC call and retrieve v, r, s given the message and the BIP 32 path of the account to sign.
|
158 |
|
159 | ##### Parameters
|
160 |
|
161 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
162 | - `messageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
163 |
|
164 | ##### Examples
|
165 |
|
166 | ```javascript
|
167 | eth.signPersonalMessage("44'/60'/0'/0/0", Buffer.from("test").toString("hex")).then(result => {
|
168 | var v = result['v'] - 27;
|
169 | v = v.toString(16);
|
170 | if (v.length < 2) {
|
171 | v = "0" + v;
|
172 | }
|
173 | console.log("Signature 0x" + result['r'] + result['s'] + v);
|
174 | })
|
175 | ```
|
176 |
|
177 | 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), s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
|
178 |
|
179 | #### signEIP712HashedMessage
|
180 |
|
181 | Sign a prepared message following web3.eth.signTypedData specification. The host computes the domain separator and hashStruct(message)
|
182 |
|
183 | ##### Parameters
|
184 |
|
185 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
186 | - `domainSeparatorHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
187 | - `hashStructMessageHex` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
|
188 |
|
189 | ##### Examples
|
190 |
|
191 | ```javascript
|
192 | eth.signEIP712HashedMessage("44'/60'/0'/0/0", Buffer.from("0101010101010101010101010101010101010101010101010101010101010101").toString("hex"), Buffer.from("0202020202020202020202020202020202020202020202020202020202020202").toString("hex")).then(result => {
|
193 | var v = result['v'] - 27;
|
194 | v = v.toString(16);
|
195 | if (v.length < 2) {
|
196 | v = "0" + v;
|
197 | }
|
198 | console.log("Signature 0x" + result['r'] + result['s'] + v);
|
199 | })
|
200 | ```
|
201 |
|
202 | 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), s: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), r: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)}>**
|
203 |
|
204 | #### starkGetPublicKey
|
205 |
|
206 | get Stark public key for a given BIP 32 path.
|
207 |
|
208 | ##### Parameters
|
209 |
|
210 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
211 | - `boolDisplay` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
212 |
|
213 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the Stark public key
|
214 |
|
215 | #### starkSignOrder
|
216 |
|
217 | sign a Stark order
|
218 |
|
219 | ##### Parameters
|
220 |
|
221 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
222 | - `sourceTokenAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
223 | - `sourceQuantization` **BigNumber** quantization used for the source token
|
224 | - `destinationTokenAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
225 | - `destinationQuantization` **BigNumber** quantization used for the destination token
|
226 | - `sourceVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the source vault
|
227 | - `destinationVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the destination vault
|
228 | - `amountSell` **BigNumber** amount to sell
|
229 | - `amountBuy` **BigNumber** amount to buy
|
230 | - `nonce` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction nonce
|
231 | - `timestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction validity timestamp
|
232 |
|
233 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the signature
|
234 |
|
235 | #### starkSignOrder_v2
|
236 |
|
237 | sign a Stark order using the Starkex V2 protocol
|
238 |
|
239 | ##### Parameters
|
240 |
|
241 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
242 | - `sourceTokenAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
243 | - `sourceQuantizationType` **StarkQuantizationType** quantization type used for the source token
|
244 | - `sourceQuantization` **BigNumber?**
|
245 | - `sourceMintableBlobOrTokenId` **BigNumber?**
|
246 | - `destinationTokenAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
247 | - `destinationQuantizationType` **StarkQuantizationType** quantization type used for the destination token
|
248 | - `destinationQuantization` **BigNumber?**
|
249 | - `destinationMintableBlobOrTokenId` **BigNumber?**
|
250 | - `sourceVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the source vault
|
251 | - `destinationVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the destination vault
|
252 | - `amountSell` **BigNumber** amount to sell
|
253 | - `amountBuy` **BigNumber** amount to buy
|
254 | - `nonce` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction nonce
|
255 | - `timestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction validity timestamp
|
256 |
|
257 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the signature
|
258 |
|
259 | #### starkSignTransfer
|
260 |
|
261 | sign a Stark transfer
|
262 |
|
263 | ##### Parameters
|
264 |
|
265 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
266 | - `transferTokenAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
267 | - `transferQuantization` **BigNumber** quantization used for the token to be transferred
|
268 | - `targetPublicKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** target Stark public key
|
269 | - `sourceVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the source vault
|
270 | - `destinationVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the destination vault
|
271 | - `amountTransfer` **BigNumber** amount to transfer
|
272 | - `nonce` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction nonce
|
273 | - `timestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction validity timestamp
|
274 |
|
275 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the signature
|
276 |
|
277 | #### starkSignTransfer_v2
|
278 |
|
279 | sign a Stark transfer or conditional transfer using the Starkex V2 protocol
|
280 |
|
281 | ##### Parameters
|
282 |
|
283 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
284 | - `transferTokenAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
285 | - `transferQuantizationType` **StarkQuantizationType** quantization type used for the token to be transferred
|
286 | - `transferQuantization` **BigNumber?**
|
287 | - `transferMintableBlobOrTokenId` **BigNumber?**
|
288 | - `targetPublicKey` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** target Stark public key
|
289 | - `sourceVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the source vault
|
290 | - `destinationVault` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ID of the destination vault
|
291 | - `amountTransfer` **BigNumber** amount to transfer
|
292 | - `nonce` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction nonce
|
293 | - `timestamp` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** transaction validity timestamp
|
294 | - `conditionalTransferAddress` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?**
|
295 | - `conditionalTransferFact` **BigNumber?**
|
296 |
|
297 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the signature
|
298 |
|
299 | #### starkProvideQuantum
|
300 |
|
301 | provide quantization information before singing a deposit or withdrawal Stark powered contract call
|
302 |
|
303 | It shall be run following a provideERC20TokenInformation call for the given contract
|
304 |
|
305 | ##### Parameters
|
306 |
|
307 | - `operationContract` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** contract address of the token to be transferred (not present for ETH)
|
308 | - `operationQuantization` **BigNumber** quantization used for the token to be transferred
|
309 |
|
310 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>**
|
311 |
|
312 | #### starkProvideQuantum_v2
|
313 |
|
314 | provide quantization information before singing a deposit or withdrawal Stark powered contract call using the Starkex V2 protocol
|
315 |
|
316 | It shall be run following a provideERC20TokenInformation call for the given contract
|
317 |
|
318 | ##### Parameters
|
319 |
|
320 | - `operationContract` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** contract address of the token to be transferred (not present for ETH)
|
321 | - `operationQuantizationType` **StarkQuantizationType** quantization type of the token to be transferred
|
322 | - `operationQuantization` **BigNumber?**
|
323 | - `operationMintableBlobOrTokenId` **BigNumber?**
|
324 |
|
325 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>**
|
326 |
|
327 | #### starkUnsafeSign
|
328 |
|
329 | sign the given hash over the Stark curve
|
330 | It is intended for speed of execution in case an unknown Stark model is pushed and should be avoided as much as possible.
|
331 |
|
332 | ##### Parameters
|
333 |
|
334 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
335 | - `hash` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** hexadecimal hash to sign
|
336 |
|
337 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** the signature
|
338 |
|
339 | #### eth2GetPublicKey
|
340 |
|
341 | get an Ethereum 2 BLS-12 381 public key for a given BIP 32 path.
|
342 |
|
343 | ##### Parameters
|
344 |
|
345 | - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** a path in BIP 32 format
|
346 | - `boolDisplay` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?**
|
347 |
|
348 | ##### Examples
|
349 |
|
350 | ```javascript
|
351 | eth.eth2GetPublicKey("12381/3600/0/0").then(o => o.publicKey)
|
352 | ```
|
353 |
|
354 | 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)}>** an object with a publicKey
|
355 |
|
356 | #### eth2SetWithdrawalIndex
|
357 |
|
358 | Set the index of a Withdrawal key used as withdrawal credentials in an ETH 2 deposit contract call signature
|
359 |
|
360 | It shall be run before the ETH 2 deposit transaction is signed. If not called, the index is set to 0
|
361 |
|
362 | ##### Parameters
|
363 |
|
364 | - `withdrawalIndex` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** index path in the EIP 2334 path m/12381/3600/withdrawalIndex/0
|
365 |
|
366 | Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** True if the method was executed successfully
|