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