1 | /// <reference types="node" />
|
2 | /********************************************************************************
|
3 | * Ledger Node JS API
|
4 | * (c) 2016-2017 Ledger
|
5 | *
|
6 | * Licensed under the Apache License, Version 2.0 (the "License");
|
7 | * you may not use this file except in compliance with the License.
|
8 | * You may obtain a copy of the License at
|
9 | *
|
10 | * http://www.apache.org/licenses/LICENSE-2.0
|
11 | *
|
12 | * Unless required by applicable law or agreed to in writing, software
|
13 | * distributed under the License is distributed on an "AS IS" BASIS,
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15 | * See the License for the specific language governing permissions and
|
16 | * limitations under the License.
|
17 | ********************************************************************************/
|
18 | import type Transport from "@ledgerhq/hw-transport";
|
19 | import { BigNumber } from "bignumber.js";
|
20 | import { LedgerEthTransactionResolution, LoadConfig, ResolutionConfig } from "./services/types";
|
21 | import ledgerService from "./services/ledger";
|
22 | import { EIP712Message } from "@ledgerhq/types-live";
|
23 | export { ledgerService };
|
24 | export * from "./utils";
|
25 | export type StarkQuantizationType = "eth" | "erc20" | "erc721" | "erc20mintable" | "erc721mintable";
|
26 | /**
|
27 | * Ethereum API
|
28 | *
|
29 | * @example
|
30 | * import Eth from "@ledgerhq/hw-app-eth";
|
31 | * const eth = new Eth(transport)
|
32 | */
|
33 | export default class Eth {
|
34 | transport: Transport;
|
35 | loadConfig: LoadConfig;
|
36 | setLoadConfig(loadConfig: LoadConfig): void;
|
37 | constructor(transport: Transport, scrambleKey?: string, loadConfig?: LoadConfig);
|
38 | /**
|
39 | * get Ethereum address for a given BIP 32 path.
|
40 | * @param path a path in BIP 32 format
|
41 | * @option boolDisplay optionally enable or not the display
|
42 | * @option boolChaincode optionally enable or not the chaincode request
|
43 | * @return an object with a publicKey, address and (optionally) chainCode
|
44 | * @example
|
45 | * eth.getAddress("44'/60'/0'/0/0").then(o => o.address)
|
46 | */
|
47 | getAddress(path: string, boolDisplay?: boolean, boolChaincode?: boolean): Promise<{
|
48 | publicKey: string;
|
49 | address: string;
|
50 | chainCode?: string;
|
51 | }>;
|
52 | /**
|
53 | * You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign.
|
54 | *
|
55 | * @param path: the BIP32 path to sign the transaction on
|
56 | * @param rawTxHex: the raw ethereum transaction in hexadecimal to sign
|
57 | * @param resolution: resolution is an object with all "resolved" metadata necessary to allow the device to clear sign information. This includes: ERC20 token information, plugins, contracts, NFT signatures,... You must explicitly provide something to avoid having a warning. By default, you can use Ledger's service or your own resolution service. See services/types.js for the contract. Setting the value to "null" will fallback everything to blind signing but will still allow the device to sign the transaction.
|
58 | * @example
|
59 | import { ledgerService } from "@ledgerhq/hw-app-eth"
|
60 | const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
|
61 | const resolution = await ledgerService.resolveTransaction(tx);
|
62 | const result = eth.signTransaction("44'/60'/0'/0/0", tx, resolution);
|
63 | console.log(result);
|
64 | */
|
65 | signTransaction(path: string, rawTxHex: string, resolution?: LedgerEthTransactionResolution | null): Promise<{
|
66 | s: string;
|
67 | v: string;
|
68 | r: string;
|
69 | }>;
|
70 | /**
|
71 | * Helper to get resolution and signature of a transaction in a single method
|
72 | *
|
73 | * @param path: the BIP32 path to sign the transaction on
|
74 | * @param rawTxHex: the raw ethereum transaction in hexadecimal to sign
|
75 | * @param resolutionConfig: configuration about what should be clear signed in the transaction
|
76 | * @param throwOnError: optional parameter to determine if a failing resolution of the transaction should throw an error or not
|
77 | * @example
|
78 | const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
|
79 | const result = eth.clearSignTransaction("44'/60'/0'/0/0", tx, { erc20: true, externalPlugins: true, nft: true});
|
80 | console.log(result);
|
81 | */
|
82 | clearSignTransaction(path: string, rawTxHex: string, resolutionConfig: ResolutionConfig, throwOnError?: boolean): Promise<{
|
83 | r: string;
|
84 | s: string;
|
85 | v: string;
|
86 | }>;
|
87 | /**
|
88 | */
|
89 | getAppConfiguration(): Promise<{
|
90 | arbitraryDataEnabled: number;
|
91 | erc20ProvisioningNecessary: number;
|
92 | starkEnabled: number;
|
93 | starkv2Supported: number;
|
94 | version: string;
|
95 | }>;
|
96 | /**
|
97 | * 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.
|
98 | * @example
|
99 | eth.signPersonalMessage("44'/60'/0'/0/0", Buffer.from("test").toString("hex")).then(result => {
|
100 | var v = result['v'] - 27;
|
101 | v = v.toString(16);
|
102 | if (v.length < 2) {
|
103 | v = "0" + v;
|
104 | }
|
105 | console.log("Signature 0x" + result['r'] + result['s'] + v);
|
106 | })
|
107 | */
|
108 | signPersonalMessage(path: string, messageHex: string): Promise<{
|
109 | v: number;
|
110 | s: string;
|
111 | r: string;
|
112 | }>;
|
113 | /**
|
114 | * Sign a prepared message following web3.eth.signTypedData specification. The host computes the domain separator and hashStruct(message)
|
115 | * @example
|
116 | eth.signEIP712HashedMessage("44'/60'/0'/0/0", Buffer.from("0101010101010101010101010101010101010101010101010101010101010101").toString("hex"), Buffer.from("0202020202020202020202020202020202020202020202020202020202020202").toString("hex")).then(result => {
|
117 | var v = result['v'] - 27;
|
118 | v = v.toString(16);
|
119 | if (v.length < 2) {
|
120 | v = "0" + v;
|
121 | }
|
122 | console.log("Signature 0x" + result['r'] + result['s'] + v);
|
123 | })
|
124 | */
|
125 | signEIP712HashedMessage(path: string, domainSeparatorHex: string, hashStructMessageHex: string): Promise<{
|
126 | v: number;
|
127 | s: string;
|
128 | r: string;
|
129 | }>;
|
130 | /**
|
131 | * Sign an EIP-721 formatted message following the specification here:
|
132 | * https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.asc#sign-eth-eip-712
|
133 | * ⚠️ This method is not compatible with nano S (LNS). Make sure to use a try/catch to fallback on the signEIP712HashedMessage method ⚠️
|
134 | @example
|
135 | eth.signEIP721Message("44'/60'/0'/0/0", {
|
136 | domain: {
|
137 | chainId: 69,
|
138 | name: "Da Domain",
|
139 | verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
|
140 | version: "1"
|
141 | },
|
142 | types: {
|
143 | "EIP712Domain": [
|
144 | { name: "name", type: "string" },
|
145 | { name: "version", type: "string" },
|
146 | { name: "chainId", type: "uint256" },
|
147 | { name: "verifyingContract", type: "address" }
|
148 | ],
|
149 | "Test": [
|
150 | { name: "contents", type: "string" }
|
151 | ]
|
152 | },
|
153 | primaryType: "Test",
|
154 | message: {contents: "Hello, Bob!"},
|
155 | })
|
156 | *
|
157 | * @param {String} path derivationPath
|
158 | * @param {Object} jsonMessage message to sign
|
159 | * @param {Boolean} fullImplem use the legacy implementation
|
160 | * @returns {Promise}
|
161 | */
|
162 | signEIP712Message(path: string, jsonMessage: EIP712Message, fullImplem?: boolean): Promise<{
|
163 | v: number;
|
164 | s: string;
|
165 | r: string;
|
166 | }>;
|
167 | /**
|
168 | * Method returning a 4 bytes TLV challenge as an hexa string
|
169 | *
|
170 | * @returns {Promise<string>}
|
171 | */
|
172 | getChallenge(): Promise<string>;
|
173 | /**
|
174 | * get Stark public key for a given BIP 32 path.
|
175 | * @param path a path in BIP 32 format
|
176 | * @option boolDisplay optionally enable or not the display
|
177 | * @return the Stark public key
|
178 | */
|
179 | starkGetPublicKey(path: string, boolDisplay?: boolean): Promise<Buffer>;
|
180 | /**
|
181 | * sign a Stark order
|
182 | * @param path a path in BIP 32 format
|
183 | * @option sourceTokenAddress contract address of the source token (not present for ETH)
|
184 | * @param sourceQuantization quantization used for the source token
|
185 | * @option destinationTokenAddress contract address of the destination token (not present for ETH)
|
186 | * @param destinationQuantization quantization used for the destination token
|
187 | * @param sourceVault ID of the source vault
|
188 | * @param destinationVault ID of the destination vault
|
189 | * @param amountSell amount to sell
|
190 | * @param amountBuy amount to buy
|
191 | * @param nonce transaction nonce
|
192 | * @param timestamp transaction validity timestamp
|
193 | * @return the signature
|
194 | */
|
195 | starkSignOrder(path: string, sourceTokenAddress: string | undefined, sourceQuantization: BigNumber, destinationTokenAddress: string | undefined, destinationQuantization: BigNumber, sourceVault: number, destinationVault: number, amountSell: BigNumber, amountBuy: BigNumber, nonce: number, timestamp: number): Promise<Buffer | {
|
196 | r: string;
|
197 | s: string;
|
198 | }>;
|
199 | /**
|
200 | * sign a Stark order using the Starkex V2 protocol
|
201 | * @param path a path in BIP 32 format
|
202 | * @option sourceTokenAddress contract address of the source token (not present for ETH)
|
203 | * @param sourceQuantizationType quantization type used for the source token
|
204 | * @option sourceQuantization quantization used for the source token (not present for erc 721 or mintable erc 721)
|
205 | * @option sourceMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) associated to the source token
|
206 | * @option destinationTokenAddress contract address of the destination token (not present for ETH)
|
207 | * @param destinationQuantizationType quantization type used for the destination token
|
208 | * @option destinationQuantization quantization used for the destination token (not present for erc 721 or mintable erc 721)
|
209 | * @option destinationMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) associated to the destination token
|
210 | * @param sourceVault ID of the source vault
|
211 | * @param destinationVault ID of the destination vault
|
212 | * @param amountSell amount to sell
|
213 | * @param amountBuy amount to buy
|
214 | * @param nonce transaction nonce
|
215 | * @param timestamp transaction validity timestamp
|
216 | * @return the signature
|
217 | */
|
218 | starkSignOrder_v2(path: string, sourceTokenAddress: string | undefined, sourceQuantizationType: StarkQuantizationType, sourceQuantization: BigNumber | undefined, sourceMintableBlobOrTokenId: BigNumber | undefined, destinationTokenAddress: string | undefined, destinationQuantizationType: StarkQuantizationType, destinationQuantization: BigNumber | undefined, destinationMintableBlobOrTokenId: BigNumber | undefined, sourceVault: number, destinationVault: number, amountSell: BigNumber, amountBuy: BigNumber, nonce: number, timestamp: number): Promise<Buffer | {
|
219 | r: string;
|
220 | s: string;
|
221 | }>;
|
222 | /**
|
223 | * sign a Stark transfer
|
224 | * @param path a path in BIP 32 format
|
225 | * @option transferTokenAddress contract address of the token to be transferred (not present for ETH)
|
226 | * @param transferQuantization quantization used for the token to be transferred
|
227 | * @param targetPublicKey target Stark public key
|
228 | * @param sourceVault ID of the source vault
|
229 | * @param destinationVault ID of the destination vault
|
230 | * @param amountTransfer amount to transfer
|
231 | * @param nonce transaction nonce
|
232 | * @param timestamp transaction validity timestamp
|
233 | * @return the signature
|
234 | */
|
235 | starkSignTransfer(path: string, transferTokenAddress: string | undefined, transferQuantization: BigNumber, targetPublicKey: string, sourceVault: number, destinationVault: number, amountTransfer: BigNumber, nonce: number, timestamp: number): Promise<Buffer | {
|
236 | r: string;
|
237 | s: string;
|
238 | }>;
|
239 | /**
|
240 | * sign a Stark transfer or conditional transfer using the Starkex V2 protocol
|
241 | * @param path a path in BIP 32 format
|
242 | * @option transferTokenAddress contract address of the token to be transferred (not present for ETH)
|
243 | * @param transferQuantizationType quantization type used for the token to be transferred
|
244 | * @option transferQuantization quantization used for the token to be transferred (not present for erc 721 or mintable erc 721)
|
245 | * @option transferMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) associated to the token to be transferred
|
246 | * @param targetPublicKey target Stark public key
|
247 | * @param sourceVault ID of the source vault
|
248 | * @param destinationVault ID of the destination vault
|
249 | * @param amountTransfer amount to transfer
|
250 | * @param nonce transaction nonce
|
251 | * @param timestamp transaction validity timestamp
|
252 | * @option conditionalTransferAddress onchain address of the condition for a conditional transfer
|
253 | * @option conditionalTransferFact fact associated to the condition for a conditional transfer
|
254 | * @return the signature
|
255 | */
|
256 | starkSignTransfer_v2(path: string, transferTokenAddress: string | undefined, transferQuantizationType: StarkQuantizationType, transferQuantization: BigNumber | undefined, transferMintableBlobOrTokenId: BigNumber | undefined, targetPublicKey: string, sourceVault: number, destinationVault: number, amountTransfer: BigNumber, nonce: number, timestamp: number, conditionalTransferAddress?: string, conditionalTransferFact?: BigNumber): Promise<Buffer | {
|
257 | r: string;
|
258 | s: string;
|
259 | }>;
|
260 | /**
|
261 | * provide quantization information before singing a deposit or withdrawal Stark powered contract call
|
262 | *
|
263 | * It shall be run following a provideERC20TokenInformation call for the given contract
|
264 | *
|
265 | * @param operationContract contract address of the token to be transferred (not present for ETH)
|
266 | * @param operationQuantization quantization used for the token to be transferred
|
267 | */
|
268 | starkProvideQuantum(operationContract: string | undefined, operationQuantization: BigNumber): Promise<boolean>;
|
269 | /**
|
270 | * provide quantization information before singing a deposit or withdrawal Stark powered contract call using the Starkex V2 protocol
|
271 | *
|
272 | * It shall be run following a provideERC20TokenInformation call for the given contract
|
273 | *
|
274 | * @param operationContract contract address of the token to be transferred (not present for ETH)
|
275 | * @param operationQuantizationType quantization type of the token to be transferred
|
276 | * @option operationQuantization quantization used for the token to be transferred (not present for erc 721 or mintable erc 721)
|
277 | * @option operationMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) of the token to be transferred
|
278 | */
|
279 | starkProvideQuantum_v2(operationContract: string | undefined, operationQuantizationType: StarkQuantizationType, operationQuantization?: BigNumber, operationMintableBlobOrTokenId?: BigNumber): Promise<boolean>;
|
280 | /**
|
281 | * sign the given hash over the Stark curve
|
282 | * It is intended for speed of execution in case an unknown Stark model is pushed and should be avoided as much as possible.
|
283 | * @param path a path in BIP 32 format
|
284 | * @param hash hexadecimal hash to sign
|
285 | * @return the signature
|
286 | */
|
287 | starkUnsafeSign(path: string, hash: string): Promise<Buffer | {
|
288 | r: string;
|
289 | s: string;
|
290 | }>;
|
291 | /**
|
292 | * get an Ethereum 2 BLS-12 381 public key for a given BIP 32 path.
|
293 | * @param path a path in BIP 32 format
|
294 | * @option boolDisplay optionally enable or not the display
|
295 | * @return an object with a publicKey
|
296 | * @example
|
297 | * eth.eth2GetPublicKey("12381/3600/0/0").then(o => o.publicKey)
|
298 | */
|
299 | eth2GetPublicKey(path: string, boolDisplay?: boolean): Promise<{
|
300 | publicKey: string;
|
301 | }>;
|
302 | /**
|
303 | * Set the index of a Withdrawal key used as withdrawal credentials in an ETH 2 deposit contract call signature
|
304 | *
|
305 | * It shall be run before the ETH 2 deposit transaction is signed. If not called, the index is set to 0
|
306 | *
|
307 | * @param withdrawalIndex index path in the EIP 2334 path m/12381/3600/withdrawalIndex/0
|
308 | * @return True if the method was executed successfully
|
309 | */
|
310 | eth2SetWithdrawalIndex(withdrawalIndex: number): Promise<boolean>;
|
311 | /**
|
312 | * get a public encryption key on Curve25519 according to EIP 1024
|
313 | * @param path a path in BIP 32 format
|
314 | * @option boolDisplay optionally enable or not the display
|
315 | * @return an object with a publicKey
|
316 | * @example
|
317 | * eth.getEIP1024PublicEncryptionKey("44'/60'/0'/0/0").then(o => o.publicKey)
|
318 | */
|
319 | getEIP1024PublicEncryptionKey(path: string, boolDisplay?: boolean): Promise<{
|
320 | publicKey: string;
|
321 | }>;
|
322 | /**
|
323 | * get a shared secret on Curve25519 according to EIP 1024
|
324 | * @param path a path in BIP 32 format
|
325 | * @param remotePublicKeyHex remote Curve25519 public key
|
326 | * @option boolDisplay optionally enable or not the display
|
327 | * @return an object with a shared secret
|
328 | * @example
|
329 | * eth.getEIP1024SharedSecret("44'/60'/0'/0/0", "87020e80af6e07a6e4697f091eacadb9e7e6629cb7e5a8a371689a3ed53b3d64").then(o => o.sharedSecret)
|
330 | */
|
331 | getEIP1024SharedSecret(path: string, remotePublicKeyHex: string, boolDisplay?: boolean): Promise<{
|
332 | sharedSecret: string;
|
333 | }>;
|
334 | /**
|
335 | * provides a trusted description of an ERC 20 token to associate a contract address with a ticker and number of decimals.
|
336 | *
|
337 | * @param data stringified buffer of ERC20 signature
|
338 | * @returns a boolean
|
339 | */
|
340 | provideERC20TokenInformation(data: string): Promise<boolean>;
|
341 | /**
|
342 | * provides the name of a trusted binding of a plugin with a contract address and a supported method selector. This plugin will be called to interpret contract data in the following transaction signing command.
|
343 | *
|
344 | * @param payload external plugin data
|
345 | * @param signature signature for the plugin
|
346 | * @returns a boolean
|
347 | */
|
348 | setExternalPlugin(payload: string, signature: string): Promise<boolean>;
|
349 | /**
|
350 | * provides the name of a trusted binding of a plugin with a contract address and a supported method selector. This plugin will be called to interpret contract data in the following transaction signing command.
|
351 | *
|
352 | * @param data stringified buffer of plugin signature
|
353 | * @returns a boolean
|
354 | */
|
355 | setPlugin(data: string): Promise<boolean>;
|
356 | /**
|
357 | * provides a trusted description of an NFT to associate a contract address with a collectionName.
|
358 | *
|
359 | * @param data stringified buffer of the NFT description
|
360 | * @returns a boolean
|
361 | */
|
362 | provideNFTInformation(data: string): Promise<boolean>;
|
363 | /**
|
364 | * provides a domain name (like ENS) to be displayed during transactions in place of the address it is associated to. It shall be run just before a transaction involving the associated address that would be displayed on the device.
|
365 | *
|
366 | * @param data an stringied buffer of some TLV encoded data to represent the domain
|
367 | * @returns a boolean
|
368 | */
|
369 | provideDomainName(data: string): Promise<boolean>;
|
370 | }
|
371 | //# sourceMappingURL=Eth.d.ts.map |
\ | No newline at end of file |