@ledgerhq/hw-app-eth 6.21.3 → 6.22.3
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 +66 -100
- package/erc20.js +1 -1
- package/lib/Eth.d.ts +30 -33
- package/lib/Eth.d.ts.map +1 -1
- package/lib/Eth.js +282 -324
- package/lib/Eth.js.map +1 -1
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +7 -0
- package/lib/errors.js.map +1 -0
- package/lib/services/ledger/contracts.d.ts +14 -0
- package/lib/services/ledger/contracts.d.ts.map +1 -0
- package/lib/{contracts.js → services/ledger/contracts.js} +0 -0
- package/lib/services/ledger/contracts.js.map +1 -0
- package/lib/services/ledger/erc20.d.ts +22 -0
- package/lib/services/ledger/erc20.d.ts.map +1 -0
- package/lib/{erc20.js → services/ledger/erc20.js} +0 -0
- package/lib/services/ledger/erc20.js.map +1 -0
- package/lib/services/ledger/index.d.ts +4 -0
- package/lib/services/ledger/index.d.ts.map +1 -0
- package/lib/services/ledger/index.js +191 -0
- package/lib/services/ledger/index.js.map +1 -0
- package/lib/services/ledger/loadConfig.d.ts +3 -0
- package/lib/services/ledger/loadConfig.d.ts.map +1 -0
- package/lib/{loadConfig.js → services/ledger/loadConfig.js} +0 -0
- package/lib/services/ledger/loadConfig.js.map +1 -0
- package/lib/services/ledger/nfts.d.ts +10 -0
- package/lib/services/ledger/nfts.d.ts.map +1 -0
- package/lib/{nfts.js → services/ledger/nfts.js} +10 -10
- package/lib/services/ledger/nfts.js.map +1 -0
- package/lib/services/types.d.ts +27 -0
- package/lib/services/types.d.ts.map +1 -0
- package/lib/services/types.js +3 -0
- package/lib/services/types.js.map +1 -0
- package/lib/utils.d.ts +8 -27
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +68 -68
- package/lib/utils.js.map +1 -1
- package/lib-es/Eth.d.ts +30 -33
- package/lib-es/Eth.d.ts.map +1 -1
- package/lib-es/Eth.js +271 -316
- package/lib-es/Eth.js.map +1 -1
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +4 -0
- package/lib-es/errors.js.map +1 -0
- package/{lib → lib-es/services/ledger}/contracts.d.ts +1 -1
- package/lib-es/services/ledger/contracts.d.ts.map +1 -0
- package/lib-es/services/ledger/contracts.js +96 -0
- package/lib-es/services/ledger/contracts.js.map +1 -0
- package/{lib → lib-es/services/ledger}/erc20.d.ts +0 -0
- package/lib-es/services/ledger/erc20.d.ts.map +1 -0
- package/lib-es/services/ledger/erc20.js +64 -0
- package/lib-es/services/ledger/erc20.js.map +1 -0
- package/lib-es/services/ledger/index.d.ts +4 -0
- package/lib-es/services/ledger/index.d.ts.map +1 -0
- package/lib-es/services/ledger/index.js +189 -0
- package/lib-es/services/ledger/index.js.map +1 -0
- package/lib-es/services/ledger/loadConfig.d.ts +3 -0
- package/lib-es/services/ledger/loadConfig.d.ts.map +1 -0
- package/lib-es/services/ledger/loadConfig.js +20 -0
- package/lib-es/services/ledger/loadConfig.js.map +1 -0
- package/{lib → lib-es/services/ledger}/nfts.d.ts +2 -3
- package/lib-es/services/ledger/nfts.d.ts.map +1 -0
- package/lib-es/services/ledger/nfts.js +94 -0
- package/lib-es/services/ledger/nfts.js.map +1 -0
- package/lib-es/services/types.d.ts +27 -0
- package/lib-es/services/types.d.ts.map +1 -0
- package/lib-es/services/types.js +2 -0
- package/lib-es/services/types.js.map +1 -0
- package/lib-es/utils.d.ts +8 -27
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +66 -61
- package/lib-es/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/Eth.ts +139 -261
- package/src/errors.ts +8 -0
- package/src/{contracts.ts → services/ledger/contracts.ts} +1 -1
- package/src/{erc20.ts → services/ledger/erc20.ts} +0 -0
- package/src/services/ledger/index.ts +125 -0
- package/src/services/ledger/loadConfig.ts +14 -0
- package/src/{nfts.ts → services/ledger/nfts.ts} +11 -12
- package/src/services/types.ts +42 -0
- package/src/utils.ts +72 -94
- package/tests/Eth.test.ts +2 -2
- package/lib/contracts.d.ts.map +0 -1
- package/lib/contracts.js.map +0 -1
- package/lib/erc20.d.ts.map +0 -1
- package/lib/erc20.js.map +0 -1
- package/lib/loadConfig.d.ts +0 -7
- package/lib/loadConfig.d.ts.map +0 -1
- package/lib/loadConfig.js.map +0 -1
- package/lib/nfts.d.ts.map +0 -1
- package/lib/nfts.js.map +0 -1
- package/src/loadConfig.ts +0 -23
package/lib-es/Eth.js
CHANGED
|
@@ -45,31 +45,9 @@ var __values = (this && this.__values) || function(o) {
|
|
|
45
45
|
};
|
|
46
46
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
47
47
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*
|
|
52
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
53
|
-
* you may not use this file except in compliance with the License.
|
|
54
|
-
* You may obtain a copy of the License at
|
|
55
|
-
*
|
|
56
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
57
|
-
*
|
|
58
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
59
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
60
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
61
|
-
* See the License for the specific language governing permissions and
|
|
62
|
-
* limitations under the License.
|
|
63
|
-
********************************************************************************/
|
|
64
|
-
// FIXME drop:
|
|
65
|
-
import { splitPath, foreach } from "./utils";
|
|
66
|
-
import { log } from "@ledgerhq/logs";
|
|
67
|
-
import { EthAppPleaseEnableContractData } from "@ledgerhq/errors";
|
|
68
|
-
import { BigNumber } from "bignumber.js";
|
|
69
|
-
import { ethers } from "ethers";
|
|
70
|
-
import { byContractAddressAndChainId } from "./erc20";
|
|
71
|
-
import { loadInfosForContractMethod } from "./contracts";
|
|
72
|
-
import { getNFTInfo, loadNftPlugin } from "./nfts";
|
|
48
|
+
import { decodeTxInfo } from "./utils";
|
|
49
|
+
import ledgerService from "./services/ledger";
|
|
50
|
+
import { EthAppNftNotSupported, EthAppPleaseEnableContractData, } from "./errors";
|
|
73
51
|
var starkQuantizationTypeMap = {
|
|
74
52
|
eth: 1,
|
|
75
53
|
erc20: 2,
|
|
@@ -77,6 +55,21 @@ var starkQuantizationTypeMap = {
|
|
|
77
55
|
erc20mintable: 4,
|
|
78
56
|
erc721mintable: 5
|
|
79
57
|
};
|
|
58
|
+
function splitPath(path) {
|
|
59
|
+
var result = [];
|
|
60
|
+
var components = path.split("/");
|
|
61
|
+
components.forEach(function (element) {
|
|
62
|
+
var number = parseInt(element, 10);
|
|
63
|
+
if (isNaN(number)) {
|
|
64
|
+
return; // FIXME shouldn't it throws instead?
|
|
65
|
+
}
|
|
66
|
+
if (element.length > 1 && element[element.length - 1] === "'") {
|
|
67
|
+
number += 0x80000000;
|
|
68
|
+
}
|
|
69
|
+
result.push(number);
|
|
70
|
+
});
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
80
73
|
function hexBuffer(str) {
|
|
81
74
|
return Buffer.from(str.startsWith("0x") ? str.slice(2) : str, "hex");
|
|
82
75
|
}
|
|
@@ -164,263 +157,222 @@ var Eth = /** @class */ (function () {
|
|
|
164
157
|
});
|
|
165
158
|
};
|
|
166
159
|
/**
|
|
167
|
-
*
|
|
168
|
-
* to associate a contract address with a ticker and number of decimals.
|
|
169
|
-
*
|
|
170
|
-
* It shall be run immediately before performing a transaction involving a contract
|
|
171
|
-
* calling this contract address to display the proper token information to the user if necessary.
|
|
172
|
-
*
|
|
173
|
-
* @param {*} info: a blob from "erc20.js" utilities that contains all token information.
|
|
160
|
+
* You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign.
|
|
174
161
|
*
|
|
162
|
+
* @param path: the BIP32 path to sign the transaction on
|
|
163
|
+
* @param rawTxHex: the raw ethereum transaction in hexadecimal to sign
|
|
164
|
+
* @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.
|
|
175
165
|
* @example
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
166
|
+
import ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger"
|
|
167
|
+
const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
|
|
168
|
+
const resolution = await ledgerService.resolveTransaction(tx);
|
|
169
|
+
const result = eth.signTransaction("44'/60'/0'/0/0", tx, resolution);
|
|
170
|
+
console.log(result);
|
|
180
171
|
*/
|
|
181
|
-
Eth.prototype.
|
|
182
|
-
var data = _a.data;
|
|
183
|
-
return provideERC20TokenInformation(this.transport, data);
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign
|
|
187
|
-
* @example
|
|
188
|
-
eth.signTransaction("44'/60'/0'/0/0", "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080").then(result => ...)
|
|
189
|
-
*/
|
|
190
|
-
Eth.prototype.signTransaction = function (path, rawTxHex) {
|
|
172
|
+
Eth.prototype.signTransaction = function (path, rawTxHex, resolution) {
|
|
191
173
|
return __awaiter(this, void 0, void 0, function () {
|
|
192
|
-
var
|
|
193
|
-
var e_1,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
switch (_b.label) {
|
|
174
|
+
var _a, _b, plugin, e_1_1, _c, _d, _e, payload, signature, e_2_1, _f, _g, nft, e_3_1, _h, _j, data, e_4_1, rawTx, _k, vrsOffset, txType, chainId, chainIdTruncated, paths, response, offset, _loop_1, this_1, response_byte, v, oneByteChainId, ecc_parity, r, s;
|
|
175
|
+
var e_1, _l, e_2, _m, e_3, _o, e_4, _p;
|
|
176
|
+
return __generator(this, function (_q) {
|
|
177
|
+
switch (_q.label) {
|
|
197
178
|
case 0:
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
data: rlpDecoded[7],
|
|
216
|
-
to: rlpDecoded[5],
|
|
217
|
-
chainId: rlpTx[0]
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
else if (txType === 1) {
|
|
221
|
-
// EIP2930
|
|
222
|
-
decodedTx = {
|
|
223
|
-
data: rlpDecoded[6],
|
|
224
|
-
to: rlpDecoded[4],
|
|
225
|
-
chainId: rlpTx[0]
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
// Legacy tx
|
|
230
|
-
decodedTx = {
|
|
231
|
-
data: rlpDecoded[5],
|
|
232
|
-
to: rlpDecoded[3],
|
|
233
|
-
// Default to 1 for non EIP 155 txs
|
|
234
|
-
chainId: rlpTx.length > 6 ? rlpTx[6] : Buffer.from("0x01", "hex")
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
if (txType === null && rlpTx.length > 6) {
|
|
238
|
-
rlpVrs = Buffer.from(ethers.utils.RLP.encode(rlpTx.slice(-3)).slice(2), "hex");
|
|
239
|
-
vrsOffset = rawTx.length - (rlpVrs.length - 1);
|
|
240
|
-
// First byte > 0xf7 means the length of the list length doesn't fit in a single byte.
|
|
241
|
-
if (rlpVrs[0] > 0xf7) {
|
|
242
|
-
// Increment vrsOffset to account for that extra byte.
|
|
243
|
-
vrsOffset++;
|
|
244
|
-
sizeOfListLen = rlpVrs[0] - 0xf7;
|
|
245
|
-
// Increase rlpOffset by the size of the list length.
|
|
246
|
-
vrsOffset += sizeOfListLen - 1;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
chainIdSrc = decodedTx.chainId;
|
|
250
|
-
if (chainIdSrc) {
|
|
251
|
-
// Using BigNumber because chainID could be any uint256.
|
|
252
|
-
chainId = new BigNumber(chainIdSrc.toString("hex"), 16);
|
|
253
|
-
chainIdTruncatedBuf = Buffer.alloc(4);
|
|
254
|
-
if (chainIdSrc.length > 4) {
|
|
255
|
-
chainIdSrc.copy(chainIdTruncatedBuf);
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
chainIdSrc.copy(chainIdTruncatedBuf, 4 - chainIdSrc.length);
|
|
259
|
-
}
|
|
260
|
-
chainIdTruncated = chainIdTruncatedBuf.readUInt32BE(0);
|
|
261
|
-
}
|
|
262
|
-
_loop_1 = function () {
|
|
263
|
-
var maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 : 150;
|
|
264
|
-
var chunkSize = offset + maxChunkSize > rawTx.length
|
|
265
|
-
? rawTx.length - offset
|
|
266
|
-
: maxChunkSize;
|
|
267
|
-
if (vrsOffset != 0 && offset + chunkSize >= vrsOffset) {
|
|
268
|
-
// Make sure that the chunk doesn't end right on the EIP 155 marker if set
|
|
269
|
-
chunkSize = rawTx.length - offset;
|
|
270
|
-
}
|
|
271
|
-
var buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + chunkSize : chunkSize);
|
|
272
|
-
if (offset === 0) {
|
|
273
|
-
buffer[0] = paths.length;
|
|
274
|
-
paths.forEach(function (element, index) {
|
|
275
|
-
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
276
|
-
});
|
|
277
|
-
rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
rawTx.copy(buffer, 0, offset, offset + chunkSize);
|
|
281
|
-
}
|
|
282
|
-
toSend.push(buffer);
|
|
283
|
-
offset += chunkSize;
|
|
284
|
-
};
|
|
285
|
-
while (offset !== rawTx.length) {
|
|
286
|
-
_loop_1();
|
|
287
|
-
}
|
|
288
|
-
provideForContract = function (address) { return __awaiter(_this, void 0, void 0, function () {
|
|
289
|
-
var nftInfo, erc20Info;
|
|
290
|
-
return __generator(this, function (_a) {
|
|
291
|
-
switch (_a.label) {
|
|
292
|
-
case 0: return [4 /*yield*/, getNFTInfo(address, chainIdTruncated, this.loadConfig)];
|
|
293
|
-
case 1:
|
|
294
|
-
nftInfo = _a.sent();
|
|
295
|
-
if (!nftInfo) return [3 /*break*/, 3];
|
|
296
|
-
log("ethereum", "loading nft info for " +
|
|
297
|
-
nftInfo.contractAddress +
|
|
298
|
-
" (" +
|
|
299
|
-
nftInfo.collectionName +
|
|
300
|
-
")");
|
|
301
|
-
return [4 /*yield*/, provideNFTInformation(this.transport, nftInfo.data)];
|
|
302
|
-
case 2:
|
|
303
|
-
_a.sent();
|
|
304
|
-
return [3 /*break*/, 5];
|
|
305
|
-
case 3:
|
|
306
|
-
erc20Info = byContractAddressAndChainId(address, chainIdTruncated);
|
|
307
|
-
if (!erc20Info) return [3 /*break*/, 5];
|
|
308
|
-
log("ethereum", "loading erc20token info for " +
|
|
309
|
-
erc20Info.contractAddress +
|
|
310
|
-
" (" +
|
|
311
|
-
erc20Info.ticker +
|
|
312
|
-
")");
|
|
313
|
-
return [4 /*yield*/, provideERC20TokenInformation(this.transport, erc20Info.data)];
|
|
314
|
-
case 4:
|
|
315
|
-
_a.sent();
|
|
316
|
-
_a.label = 5;
|
|
317
|
-
case 5: return [2 /*return*/];
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}); };
|
|
321
|
-
if (!(decodedTx.data.length >= 10)) return [3 /*break*/, 18];
|
|
322
|
-
selector = decodedTx.data.substring(0, 10);
|
|
323
|
-
return [4 /*yield*/, loadNftPlugin(decodedTx.to, selector, chainIdTruncated, this.loadConfig)];
|
|
179
|
+
if (!(resolution === undefined)) return [3 /*break*/, 2];
|
|
180
|
+
console.warn("hw-app-eth: signTransaction(path, rawTxHex, resolution): " +
|
|
181
|
+
"please provide the 'resolution' parameter. " +
|
|
182
|
+
"See https://github.com/LedgerHQ/ledgerjs/blob/master/packages/hw-app-eth/README.md " +
|
|
183
|
+
"– the previous signature is deprecated and providing the 3rd 'resolution' parameter explicitly will become mandatory so you have the control on the resolution and the fallback mecanism (e.g. fallback to blind signing or not)." +
|
|
184
|
+
"// Possible solution:\n" +
|
|
185
|
+
" + import ledgerService from '@ledgerhq/hw-app-eth/lib/services/ledger';\n" +
|
|
186
|
+
" + const resolution = await ledgerService.resolveTransaction(rawTxHex);");
|
|
187
|
+
return [4 /*yield*/, ledgerService
|
|
188
|
+
.resolveTransaction(rawTxHex, this.loadConfig, {
|
|
189
|
+
externalPlugins: true,
|
|
190
|
+
erc20: true
|
|
191
|
+
})["catch"](function (e) {
|
|
192
|
+
console.warn("an error occurred in resolveTransaction => fallback to blind signing: " +
|
|
193
|
+
String(e));
|
|
194
|
+
return null;
|
|
195
|
+
})];
|
|
324
196
|
case 1:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
return [4 /*yield*/, setPlugin(this.transport, nftPluginPayload)];
|
|
197
|
+
resolution = _q.sent();
|
|
198
|
+
_q.label = 2;
|
|
328
199
|
case 2:
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
case 3:
|
|
200
|
+
if (!resolution) return [3 /*break*/, 31];
|
|
201
|
+
_q.label = 3;
|
|
202
|
+
case 3:
|
|
203
|
+
_q.trys.push([3, 8, 9, 10]);
|
|
204
|
+
_a = __values(resolution.plugin), _b = _a.next();
|
|
205
|
+
_q.label = 4;
|
|
332
206
|
case 4:
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (!plugin) return [3 /*break*/, 6];
|
|
337
|
-
log("ethereum", "loading plugin for " + selector);
|
|
338
|
-
return [4 /*yield*/, setExternalPlugin(this.transport, payload, signature)];
|
|
207
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
208
|
+
plugin = _b.value;
|
|
209
|
+
return [4 /*yield*/, setPlugin(this.transport, plugin)];
|
|
339
210
|
case 5:
|
|
340
|
-
|
|
341
|
-
|
|
211
|
+
_q.sent();
|
|
212
|
+
_q.label = 6;
|
|
342
213
|
case 6:
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
_b.label = 7;
|
|
347
|
-
case 7:
|
|
348
|
-
_b.trys.push([7, 12, 13, 14]);
|
|
349
|
-
erc20OfInterest_1 = __values(erc20OfInterest), erc20OfInterest_1_1 = erc20OfInterest_1.next();
|
|
350
|
-
_b.label = 8;
|
|
214
|
+
_b = _a.next();
|
|
215
|
+
return [3 /*break*/, 4];
|
|
216
|
+
case 7: return [3 /*break*/, 10];
|
|
351
217
|
case 8:
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (seg === "-1" && Array.isArray(value)) {
|
|
356
|
-
return value[value.length - 1];
|
|
357
|
-
}
|
|
358
|
-
return value[seg];
|
|
359
|
-
}, args);
|
|
360
|
-
return [4 /*yield*/, provideForContract(address)];
|
|
218
|
+
e_1_1 = _q.sent();
|
|
219
|
+
e_1 = { error: e_1_1 };
|
|
220
|
+
return [3 /*break*/, 10];
|
|
361
221
|
case 9:
|
|
362
|
-
|
|
363
|
-
|
|
222
|
+
try {
|
|
223
|
+
if (_b && !_b.done && (_l = _a["return"])) _l.call(_a);
|
|
224
|
+
}
|
|
225
|
+
finally { if (e_1) throw e_1.error; }
|
|
226
|
+
return [7 /*endfinally*/];
|
|
364
227
|
case 10:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
228
|
+
_q.trys.push([10, 15, 16, 17]);
|
|
229
|
+
_c = __values(resolution.externalPlugin), _d = _c.next();
|
|
230
|
+
_q.label = 11;
|
|
231
|
+
case 11:
|
|
232
|
+
if (!!_d.done) return [3 /*break*/, 14];
|
|
233
|
+
_e = _d.value, payload = _e.payload, signature = _e.signature;
|
|
234
|
+
return [4 /*yield*/, setExternalPlugin(this.transport, payload, signature)];
|
|
368
235
|
case 12:
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return [3 /*break*/, 14];
|
|
236
|
+
_q.sent();
|
|
237
|
+
_q.label = 13;
|
|
372
238
|
case 13:
|
|
239
|
+
_d = _c.next();
|
|
240
|
+
return [3 /*break*/, 11];
|
|
241
|
+
case 14: return [3 /*break*/, 17];
|
|
242
|
+
case 15:
|
|
243
|
+
e_2_1 = _q.sent();
|
|
244
|
+
e_2 = { error: e_2_1 };
|
|
245
|
+
return [3 /*break*/, 17];
|
|
246
|
+
case 16:
|
|
373
247
|
try {
|
|
374
|
-
if (
|
|
248
|
+
if (_d && !_d.done && (_m = _c["return"])) _m.call(_c);
|
|
375
249
|
}
|
|
376
|
-
finally { if (
|
|
250
|
+
finally { if (e_2) throw e_2.error; }
|
|
377
251
|
return [7 /*endfinally*/];
|
|
378
|
-
case 14: return [3 /*break*/, 16];
|
|
379
|
-
case 15:
|
|
380
|
-
log("ethereum", "no infos for selector " + selector);
|
|
381
|
-
_b.label = 16;
|
|
382
|
-
case 16: return [4 /*yield*/, provideForContract(decodedTx.to)];
|
|
383
252
|
case 17:
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
253
|
+
_q.trys.push([17, 22, 23, 24]);
|
|
254
|
+
_f = __values(resolution.nfts), _g = _f.next();
|
|
255
|
+
_q.label = 18;
|
|
256
|
+
case 18:
|
|
257
|
+
if (!!_g.done) return [3 /*break*/, 21];
|
|
258
|
+
nft = _g.value;
|
|
259
|
+
return [4 /*yield*/, provideNFTInformation(this.transport, Buffer.from(nft, "hex"))];
|
|
260
|
+
case 19:
|
|
261
|
+
_q.sent();
|
|
262
|
+
_q.label = 20;
|
|
263
|
+
case 20:
|
|
264
|
+
_g = _f.next();
|
|
265
|
+
return [3 /*break*/, 18];
|
|
266
|
+
case 21: return [3 /*break*/, 24];
|
|
267
|
+
case 22:
|
|
268
|
+
e_3_1 = _q.sent();
|
|
269
|
+
e_3 = { error: e_3_1 };
|
|
270
|
+
return [3 /*break*/, 24];
|
|
271
|
+
case 23:
|
|
272
|
+
try {
|
|
273
|
+
if (_g && !_g.done && (_o = _f["return"])) _o.call(_f);
|
|
274
|
+
}
|
|
275
|
+
finally { if (e_3) throw e_3.error; }
|
|
276
|
+
return [7 /*endfinally*/];
|
|
277
|
+
case 24:
|
|
278
|
+
_q.trys.push([24, 29, 30, 31]);
|
|
279
|
+
_h = __values(resolution.erc20Tokens), _j = _h.next();
|
|
280
|
+
_q.label = 25;
|
|
281
|
+
case 25:
|
|
282
|
+
if (!!_j.done) return [3 /*break*/, 28];
|
|
283
|
+
data = _j.value;
|
|
284
|
+
return [4 /*yield*/, provideERC20TokenInformation(this.transport, Buffer.from(data, "hex"))];
|
|
285
|
+
case 26:
|
|
286
|
+
_q.sent();
|
|
287
|
+
_q.label = 27;
|
|
288
|
+
case 27:
|
|
289
|
+
_j = _h.next();
|
|
290
|
+
return [3 /*break*/, 25];
|
|
291
|
+
case 28: return [3 /*break*/, 31];
|
|
292
|
+
case 29:
|
|
293
|
+
e_4_1 = _q.sent();
|
|
294
|
+
e_4 = { error: e_4_1 };
|
|
295
|
+
return [3 /*break*/, 31];
|
|
296
|
+
case 30:
|
|
297
|
+
try {
|
|
298
|
+
if (_j && !_j.done && (_p = _h["return"])) _p.call(_h);
|
|
299
|
+
}
|
|
300
|
+
finally { if (e_4) throw e_4.error; }
|
|
301
|
+
return [7 /*endfinally*/];
|
|
302
|
+
case 31:
|
|
303
|
+
rawTx = Buffer.from(rawTxHex, "hex");
|
|
304
|
+
_k = decodeTxInfo(rawTx), vrsOffset = _k.vrsOffset, txType = _k.txType, chainId = _k.chainId, chainIdTruncated = _k.chainIdTruncated;
|
|
305
|
+
paths = splitPath(path);
|
|
306
|
+
offset = 0;
|
|
307
|
+
_loop_1 = function () {
|
|
308
|
+
var first, maxChunkSize, chunkSize, buffer;
|
|
309
|
+
return __generator(this, function (_r) {
|
|
310
|
+
switch (_r.label) {
|
|
311
|
+
case 0:
|
|
312
|
+
first = offset === 0;
|
|
313
|
+
maxChunkSize = first ? 150 - 1 - paths.length * 4 : 150;
|
|
314
|
+
chunkSize = offset + maxChunkSize > rawTx.length
|
|
315
|
+
? rawTx.length - offset
|
|
316
|
+
: maxChunkSize;
|
|
317
|
+
if (vrsOffset != 0 && offset + chunkSize >= vrsOffset) {
|
|
318
|
+
// Make sure that the chunk doesn't end right on the EIP 155 marker if set
|
|
319
|
+
chunkSize = rawTx.length - offset;
|
|
320
|
+
}
|
|
321
|
+
buffer = Buffer.alloc(first ? 1 + paths.length * 4 + chunkSize : chunkSize);
|
|
322
|
+
if (first) {
|
|
323
|
+
buffer[0] = paths.length;
|
|
324
|
+
paths.forEach(function (element, index) {
|
|
325
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
326
|
+
});
|
|
327
|
+
rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
rawTx.copy(buffer, 0, offset, offset + chunkSize);
|
|
331
|
+
}
|
|
332
|
+
return [4 /*yield*/, this_1.transport
|
|
333
|
+
.send(0xe0, 0x04, first ? 0x00 : 0x80, 0x00, buffer)["catch"](function (e) {
|
|
334
|
+
throw remapTransactionRelatedErrors(e);
|
|
335
|
+
})];
|
|
336
|
+
case 1:
|
|
337
|
+
response = _r.sent();
|
|
338
|
+
offset += chunkSize;
|
|
339
|
+
return [2 /*return*/];
|
|
405
340
|
}
|
|
341
|
+
});
|
|
342
|
+
};
|
|
343
|
+
this_1 = this;
|
|
344
|
+
_q.label = 32;
|
|
345
|
+
case 32:
|
|
346
|
+
if (!(offset !== rawTx.length)) return [3 /*break*/, 34];
|
|
347
|
+
return [5 /*yield**/, _loop_1()];
|
|
348
|
+
case 33:
|
|
349
|
+
_q.sent();
|
|
350
|
+
return [3 /*break*/, 32];
|
|
351
|
+
case 34:
|
|
352
|
+
response_byte = response[0];
|
|
353
|
+
v = "";
|
|
354
|
+
if (chainId.times(2).plus(35).plus(1).isGreaterThan(255)) {
|
|
355
|
+
oneByteChainId = (chainIdTruncated * 2 + 35) % 256;
|
|
356
|
+
ecc_parity = Math.abs(response_byte - oneByteChainId);
|
|
357
|
+
if (txType != null) {
|
|
358
|
+
// For EIP2930 and EIP1559 tx, v is simply the parity.
|
|
359
|
+
v = ecc_parity % 2 == 1 ? "00" : "01";
|
|
406
360
|
}
|
|
407
361
|
else {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
// Make sure v has is prefixed with a 0 if its length is odd ("1" -> "01").
|
|
411
|
-
if (v.length % 2 == 1) {
|
|
412
|
-
v = "0" + v;
|
|
362
|
+
// Legacy type transaction with a big chain ID
|
|
363
|
+
v = chainId.times(2).plus(35).plus(ecc_parity).toString(16);
|
|
413
364
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
v = response_byte.toString(16);
|
|
368
|
+
}
|
|
369
|
+
// Make sure v has is prefixed with a 0 if its length is odd ("1" -> "01").
|
|
370
|
+
if (v.length % 2 == 1) {
|
|
371
|
+
v = "0" + v;
|
|
372
|
+
}
|
|
373
|
+
r = response.slice(1, 1 + 32).toString("hex");
|
|
374
|
+
s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
|
|
375
|
+
return [2 /*return*/, { v: v, r: r, s: s }];
|
|
424
376
|
}
|
|
425
377
|
});
|
|
426
378
|
});
|
|
@@ -451,50 +403,58 @@ var Eth = /** @class */ (function () {
|
|
|
451
403
|
})
|
|
452
404
|
*/
|
|
453
405
|
Eth.prototype.signPersonalMessage = function (path, messageHex) {
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
406
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
407
|
+
var paths, offset, message, response, _loop_2, this_2, v, r, s;
|
|
408
|
+
return __generator(this, function (_a) {
|
|
409
|
+
switch (_a.label) {
|
|
410
|
+
case 0:
|
|
411
|
+
paths = splitPath(path);
|
|
412
|
+
offset = 0;
|
|
413
|
+
message = Buffer.from(messageHex, "hex");
|
|
414
|
+
_loop_2 = function () {
|
|
415
|
+
var maxChunkSize, chunkSize, buffer;
|
|
416
|
+
return __generator(this, function (_b) {
|
|
417
|
+
switch (_b.label) {
|
|
418
|
+
case 0:
|
|
419
|
+
maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150;
|
|
420
|
+
chunkSize = offset + maxChunkSize > message.length
|
|
421
|
+
? message.length - offset
|
|
422
|
+
: maxChunkSize;
|
|
423
|
+
buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize);
|
|
424
|
+
if (offset === 0) {
|
|
425
|
+
buffer[0] = paths.length;
|
|
426
|
+
paths.forEach(function (element, index) {
|
|
427
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
428
|
+
});
|
|
429
|
+
buffer.writeUInt32BE(message.length, 1 + 4 * paths.length);
|
|
430
|
+
message.copy(buffer, 1 + 4 * paths.length + 4, offset, offset + chunkSize);
|
|
431
|
+
}
|
|
432
|
+
else {
|
|
433
|
+
message.copy(buffer, 0, offset, offset + chunkSize);
|
|
434
|
+
}
|
|
435
|
+
return [4 /*yield*/, this_2.transport.send(0xe0, 0x08, offset === 0 ? 0x00 : 0x80, 0x00, buffer)];
|
|
436
|
+
case 1:
|
|
437
|
+
response = _b.sent();
|
|
438
|
+
offset += chunkSize;
|
|
439
|
+
return [2 /*return*/];
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
};
|
|
443
|
+
this_2 = this;
|
|
444
|
+
_a.label = 1;
|
|
445
|
+
case 1:
|
|
446
|
+
if (!(offset !== message.length)) return [3 /*break*/, 3];
|
|
447
|
+
return [5 /*yield**/, _loop_2()];
|
|
448
|
+
case 2:
|
|
449
|
+
_a.sent();
|
|
450
|
+
return [3 /*break*/, 1];
|
|
451
|
+
case 3:
|
|
452
|
+
v = response[0];
|
|
453
|
+
r = response.slice(1, 1 + 32).toString("hex");
|
|
454
|
+
s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
|
|
455
|
+
return [2 /*return*/, { v: v, r: r, s: s }];
|
|
456
|
+
}
|
|
488
457
|
});
|
|
489
|
-
}).then(function () {
|
|
490
|
-
var v = response[0];
|
|
491
|
-
var r = response.slice(1, 1 + 32).toString("hex");
|
|
492
|
-
var s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
|
|
493
|
-
return {
|
|
494
|
-
v: v,
|
|
495
|
-
r: r,
|
|
496
|
-
s: s
|
|
497
|
-
};
|
|
498
458
|
});
|
|
499
459
|
};
|
|
500
460
|
/**
|
|
@@ -990,22 +950,17 @@ var Eth = /** @class */ (function () {
|
|
|
990
950
|
throw e;
|
|
991
951
|
});
|
|
992
952
|
};
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
*/
|
|
953
|
+
Eth.prototype.provideERC20TokenInformation = function (_a) {
|
|
954
|
+
var data = _a.data;
|
|
955
|
+
console.warn("hw-app-eth: eth.provideERC20TokenInformation is deprecated. signTransaction solves this for you when providing it in `resolution`.");
|
|
956
|
+
return provideERC20TokenInformation(this.transport, data);
|
|
957
|
+
};
|
|
999
958
|
Eth.prototype.setExternalPlugin = function (pluginName, contractAddress, selector) {
|
|
959
|
+
console.warn("hw-app-eth: eth.setExternalPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
|
|
1000
960
|
return setExternalPlugin(this.transport, pluginName, selector);
|
|
1001
961
|
};
|
|
1002
|
-
/**
|
|
1003
|
-
* Set the plugin (internal or external) that should be used to parse the next transaction
|
|
1004
|
-
*
|
|
1005
|
-
* @param data string containing the payload and signature that will be parsed and verified by the device.
|
|
1006
|
-
* @return True if the method was executed successfully
|
|
1007
|
-
*/
|
|
1008
962
|
Eth.prototype.setPlugin = function (data) {
|
|
963
|
+
console.warn("hw-app-eth: eth.setPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
|
|
1009
964
|
return setPlugin(this.transport, data);
|
|
1010
965
|
};
|
|
1011
966
|
return Eth;
|
|
@@ -1029,8 +984,8 @@ function provideNFTInformation(transport, data) {
|
|
|
1029
984
|
return false;
|
|
1030
985
|
}
|
|
1031
986
|
if (e && e.statusCode === 0x6d00) {
|
|
1032
|
-
//
|
|
1033
|
-
|
|
987
|
+
// older version of ETH app => error because we don't allow blind sign when NFT is explicitly requested to be resolved.
|
|
988
|
+
throw new EthAppNftNotSupported();
|
|
1034
989
|
}
|
|
1035
990
|
throw e;
|
|
1036
991
|
});
|