UNPKG

16.6 kBTypeScriptView Raw
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 ********************************************************************************/
18import type Transport from "@ledgerhq/hw-transport";
19import { BigNumber } from "bignumber.js";
20import { LedgerEthTransactionResolution, LoadConfig } from "./services/types";
21import ledgerService from "./services/ledger";
22import { EIP712Message, isEIP712Message, getFiltersForMessage } from "./modules/EIP712";
23export { ledgerService, isEIP712Message, getFiltersForMessage };
24export declare type StarkQuantizationType = "eth" | "erc20" | "erc721" | "erc20mintable" | "erc721mintable";
25/**
26 * Ethereum API
27 *
28 * @example
29 * import Eth from "@ledgerhq/hw-app-eth";
30 * const eth = new Eth(transport)
31 */
32export default class Eth {
33 transport: Transport;
34 loadConfig: LoadConfig;
35 setLoadConfig(loadConfig: LoadConfig): void;
36 constructor(transport: Transport, scrambleKey?: string, loadConfig?: LoadConfig);
37 /**
38 * get Ethereum address for a given BIP 32 path.
39 * @param path a path in BIP 32 format
40 * @option boolDisplay optionally enable or not the display
41 * @option boolChaincode optionally enable or not the chaincode request
42 * @return an object with a publicKey, address and (optionally) chainCode
43 * @example
44 * eth.getAddress("44'/60'/0'/0/0").then(o => o.address)
45 */
46 getAddress(path: string, boolDisplay?: boolean, boolChaincode?: boolean): Promise<{
47 publicKey: string;
48 address: string;
49 chainCode?: string;
50 }>;
51 /**
52 * You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign.
53 *
54 * @param path: the BIP32 path to sign the transaction on
55 * @param rawTxHex: the raw ethereum transaction in hexadecimal to sign
56 * @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.
57 * @example
58 import { ledgerService } from "@ledgerhq/hw-app-eth"
59 const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
60 const resolution = await ledgerService.resolveTransaction(tx);
61 const result = eth.signTransaction("44'/60'/0'/0/0", tx, resolution);
62 console.log(result);
63 */
64 signTransaction(path: string, rawTxHex: string, resolution?: LedgerEthTransactionResolution | null): Promise<{
65 s: string;
66 v: string;
67 r: string;
68 }>;
69 /**
70 */
71 getAppConfiguration(): Promise<{
72 arbitraryDataEnabled: number;
73 erc20ProvisioningNecessary: number;
74 starkEnabled: number;
75 starkv2Supported: number;
76 version: string;
77 }>;
78 /**
79 * 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.
80 * @example
81 eth.signPersonalMessage("44'/60'/0'/0/0", Buffer.from("test").toString("hex")).then(result => {
82 var v = result['v'] - 27;
83 v = v.toString(16);
84 if (v.length < 2) {
85 v = "0" + v;
86 }
87 console.log("Signature 0x" + result['r'] + result['s'] + v);
88 })
89 */
90 signPersonalMessage(path: string, messageHex: string): Promise<{
91 v: number;
92 s: string;
93 r: string;
94 }>;
95 /**
96 * Sign a prepared message following web3.eth.signTypedData specification. The host computes the domain separator and hashStruct(message)
97 * @example
98 eth.signEIP712HashedMessage("44'/60'/0'/0/0", Buffer.from("0101010101010101010101010101010101010101010101010101010101010101").toString("hex"), Buffer.from("0202020202020202020202020202020202020202020202020202020202020202").toString("hex")).then(result => {
99 var v = result['v'] - 27;
100 v = v.toString(16);
101 if (v.length < 2) {
102 v = "0" + v;
103 }
104 console.log("Signature 0x" + result['r'] + result['s'] + v);
105 })
106 */
107 signEIP712HashedMessage(path: string, domainSeparatorHex: string, hashStructMessageHex: string): Promise<{
108 v: number;
109 s: string;
110 r: string;
111 }>;
112 /**
113 * Sign an EIP-721 formatted message following the specification here:
114 * https://github.com/LedgerHQ/app-ethereum/blob/develop/doc/ethapp.asc#sign-eth-eip-712
115 * ⚠️ This method is not compatible with nano S (LNS). Make sure to use a try/catch to fallback on the signEIP712HashedMessage method ⚠️
116 @example
117 eth.signEIP721Message("44'/60'/0'/0/0", {
118 domain: {
119 chainId: 69,
120 name: "Da Domain",
121 verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
122 version: "1"
123 },
124 types: {
125 "EIP712Domain": [
126 { name: "name", type: "string" },
127 { name: "version", type: "string" },
128 { name: "chainId", type: "uint256" },
129 { name: "verifyingContract", type: "address" }
130 ],
131 "Test": [
132 { name: "contents", type: "string" }
133 ]
134 },
135 primaryType: "Test",
136 message: {contents: "Hello, Bob!"},
137 })
138 *
139 * @param {String} path derivationPath
140 * @param {Object} jsonMessage message to sign
141 * @param {Boolean} fullImplem use the legacy implementation
142 * @returns {Promise}
143 */
144 signEIP712Message(path: string, jsonMessage: EIP712Message, fullImplem?: boolean): Promise<{
145 v: number;
146 s: string;
147 r: string;
148 }>;
149 /**
150 * get Stark public key for a given BIP 32 path.
151 * @param path a path in BIP 32 format
152 * @option boolDisplay optionally enable or not the display
153 * @return the Stark public key
154 */
155 starkGetPublicKey(path: string, boolDisplay?: boolean): Promise<Buffer>;
156 /**
157 * sign a Stark order
158 * @param path a path in BIP 32 format
159 * @option sourceTokenAddress contract address of the source token (not present for ETH)
160 * @param sourceQuantization quantization used for the source token
161 * @option destinationTokenAddress contract address of the destination token (not present for ETH)
162 * @param destinationQuantization quantization used for the destination token
163 * @param sourceVault ID of the source vault
164 * @param destinationVault ID of the destination vault
165 * @param amountSell amount to sell
166 * @param amountBuy amount to buy
167 * @param nonce transaction nonce
168 * @param timestamp transaction validity timestamp
169 * @return the signature
170 */
171 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 | {
172 r: string;
173 s: string;
174 }>;
175 /**
176 * sign a Stark order using the Starkex V2 protocol
177 * @param path a path in BIP 32 format
178 * @option sourceTokenAddress contract address of the source token (not present for ETH)
179 * @param sourceQuantizationType quantization type used for the source token
180 * @option sourceQuantization quantization used for the source token (not present for erc 721 or mintable erc 721)
181 * @option sourceMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) associated to the source token
182 * @option destinationTokenAddress contract address of the destination token (not present for ETH)
183 * @param destinationQuantizationType quantization type used for the destination token
184 * @option destinationQuantization quantization used for the destination token (not present for erc 721 or mintable erc 721)
185 * @option destinationMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) associated to the destination token
186 * @param sourceVault ID of the source vault
187 * @param destinationVault ID of the destination vault
188 * @param amountSell amount to sell
189 * @param amountBuy amount to buy
190 * @param nonce transaction nonce
191 * @param timestamp transaction validity timestamp
192 * @return the signature
193 */
194 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 | {
195 r: string;
196 s: string;
197 }>;
198 /**
199 * sign a Stark transfer
200 * @param path a path in BIP 32 format
201 * @option transferTokenAddress contract address of the token to be transferred (not present for ETH)
202 * @param transferQuantization quantization used for the token to be transferred
203 * @param targetPublicKey target Stark public key
204 * @param sourceVault ID of the source vault
205 * @param destinationVault ID of the destination vault
206 * @param amountTransfer amount to transfer
207 * @param nonce transaction nonce
208 * @param timestamp transaction validity timestamp
209 * @return the signature
210 */
211 starkSignTransfer(path: string, transferTokenAddress: string | undefined, transferQuantization: BigNumber, targetPublicKey: string, sourceVault: number, destinationVault: number, amountTransfer: BigNumber, nonce: number, timestamp: number): Promise<Buffer | {
212 r: string;
213 s: string;
214 }>;
215 /**
216 * sign a Stark transfer or conditional transfer using the Starkex V2 protocol
217 * @param path a path in BIP 32 format
218 * @option transferTokenAddress contract address of the token to be transferred (not present for ETH)
219 * @param transferQuantizationType quantization type used for the token to be transferred
220 * @option transferQuantization quantization used for the token to be transferred (not present for erc 721 or mintable erc 721)
221 * @option transferMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) associated to the token to be transferred
222 * @param targetPublicKey target Stark public key
223 * @param sourceVault ID of the source vault
224 * @param destinationVault ID of the destination vault
225 * @param amountTransfer amount to transfer
226 * @param nonce transaction nonce
227 * @param timestamp transaction validity timestamp
228 * @option conditionalTransferAddress onchain address of the condition for a conditional transfer
229 * @option conditionalTransferFact fact associated to the condition for a conditional transfer
230 * @return the signature
231 */
232 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 | {
233 r: string;
234 s: string;
235 }>;
236 /**
237 * provide quantization information before singing a deposit or withdrawal Stark powered contract call
238 *
239 * It shall be run following a provideERC20TokenInformation call for the given contract
240 *
241 * @param operationContract contract address of the token to be transferred (not present for ETH)
242 * @param operationQuantization quantization used for the token to be transferred
243 */
244 starkProvideQuantum(operationContract: string | undefined, operationQuantization: BigNumber): Promise<boolean>;
245 /**
246 * provide quantization information before singing a deposit or withdrawal Stark powered contract call using the Starkex V2 protocol
247 *
248 * It shall be run following a provideERC20TokenInformation call for the given contract
249 *
250 * @param operationContract contract address of the token to be transferred (not present for ETH)
251 * @param operationQuantizationType quantization type of the token to be transferred
252 * @option operationQuantization quantization used for the token to be transferred (not present for erc 721 or mintable erc 721)
253 * @option operationMintableBlobOrTokenId mintable blob (mintable erc 20 / mintable erc 721) or token id (erc 721) of the token to be transferred
254 */
255 starkProvideQuantum_v2(operationContract: string | undefined, operationQuantizationType: StarkQuantizationType, operationQuantization?: BigNumber, operationMintableBlobOrTokenId?: BigNumber): Promise<boolean>;
256 /**
257 * sign the given hash over the Stark curve
258 * It is intended for speed of execution in case an unknown Stark model is pushed and should be avoided as much as possible.
259 * @param path a path in BIP 32 format
260 * @param hash hexadecimal hash to sign
261 * @return the signature
262 */
263 starkUnsafeSign(path: string, hash: string): Promise<Buffer | {
264 r: string;
265 s: string;
266 }>;
267 /**
268 * get an Ethereum 2 BLS-12 381 public key for a given BIP 32 path.
269 * @param path a path in BIP 32 format
270 * @option boolDisplay optionally enable or not the display
271 * @return an object with a publicKey
272 * @example
273 * eth.eth2GetPublicKey("12381/3600/0/0").then(o => o.publicKey)
274 */
275 eth2GetPublicKey(path: string, boolDisplay?: boolean): Promise<{
276 publicKey: string;
277 }>;
278 /**
279 * Set the index of a Withdrawal key used as withdrawal credentials in an ETH 2 deposit contract call signature
280 *
281 * It shall be run before the ETH 2 deposit transaction is signed. If not called, the index is set to 0
282 *
283 * @param withdrawalIndex index path in the EIP 2334 path m/12381/3600/withdrawalIndex/0
284 * @return True if the method was executed successfully
285 */
286 eth2SetWithdrawalIndex(withdrawalIndex: number): Promise<boolean>;
287 /**
288 * get a public encryption key on Curve25519 according to EIP 1024
289 * @param path a path in BIP 32 format
290 * @option boolDisplay optionally enable or not the display
291 * @return an object with a publicKey
292 * @example
293 * eth.getEIP1024PublicEncryptionKey("44'/60'/0'/0/0").then(o => o.publicKey)
294 */
295 getEIP1024PublicEncryptionKey(path: string, boolDisplay?: boolean): Promise<{
296 publicKey: string;
297 }>;
298 /**
299 * get a shared secret on Curve25519 according to EIP 1024
300 * @param path a path in BIP 32 format
301 * @param remotePublicKeyHex remote Curve25519 public key
302 * @option boolDisplay optionally enable or not the display
303 * @return an object with a shared secret
304 * @example
305 * eth.getEIP1024SharedSecret("44'/60'/0'/0/0", "87020e80af6e07a6e4697f091eacadb9e7e6629cb7e5a8a371689a3ed53b3d64").then(o => o.sharedSecret)
306 */
307 getEIP1024SharedSecret(path: string, remotePublicKeyHex: string, boolDisplay?: boolean): Promise<{
308 sharedSecret: string;
309 }>;
310 provideERC20TokenInformation({ data }: {
311 data: Buffer;
312 }): Promise<boolean>;
313 setExternalPlugin(pluginName: string, contractAddress: string, selector: string): Promise<boolean>;
314 setPlugin(data: string): Promise<boolean>;
315}
316//# sourceMappingURL=Eth.d.ts.map
\No newline at end of file