@ledgerhq/hw-app-eth 6.21.2 → 6.22.2

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.
Files changed (86) hide show
  1. package/README.md +66 -100
  2. package/erc20.js +1 -1
  3. package/lib/Eth.d.ts +14 -33
  4. package/lib/Eth.d.ts.map +1 -1
  5. package/lib/Eth.js +280 -305
  6. package/lib/Eth.js.map +1 -1
  7. package/lib/services/ledger/contracts.d.ts +14 -0
  8. package/lib/services/ledger/contracts.d.ts.map +1 -0
  9. package/lib/{contracts.js → services/ledger/contracts.js} +0 -0
  10. package/lib/services/ledger/contracts.js.map +1 -0
  11. package/lib/services/ledger/erc20.d.ts +22 -0
  12. package/lib/services/ledger/erc20.d.ts.map +1 -0
  13. package/lib/{erc20.js → services/ledger/erc20.js} +0 -0
  14. package/lib/services/ledger/erc20.js.map +1 -0
  15. package/lib/services/ledger/index.d.ts +4 -0
  16. package/lib/services/ledger/index.d.ts.map +1 -0
  17. package/lib/services/ledger/index.js +191 -0
  18. package/lib/services/ledger/index.js.map +1 -0
  19. package/lib/services/ledger/loadConfig.d.ts +3 -0
  20. package/lib/services/ledger/loadConfig.d.ts.map +1 -0
  21. package/lib/{loadConfig.js → services/ledger/loadConfig.js} +0 -0
  22. package/lib/services/ledger/loadConfig.js.map +1 -0
  23. package/lib/services/ledger/nfts.d.ts +10 -0
  24. package/lib/services/ledger/nfts.d.ts.map +1 -0
  25. package/lib/{nfts.js → services/ledger/nfts.js} +10 -10
  26. package/lib/services/ledger/nfts.js.map +1 -0
  27. package/lib/services/types.d.ts +27 -0
  28. package/lib/services/types.d.ts.map +1 -0
  29. package/lib/services/types.js +3 -0
  30. package/lib/services/types.js.map +1 -0
  31. package/lib/utils.d.ts +8 -27
  32. package/lib/utils.d.ts.map +1 -1
  33. package/lib/utils.js +68 -68
  34. package/lib/utils.js.map +1 -1
  35. package/lib-es/Eth.d.ts +14 -33
  36. package/lib-es/Eth.d.ts.map +1 -1
  37. package/lib-es/Eth.js +268 -296
  38. package/lib-es/Eth.js.map +1 -1
  39. package/{lib → lib-es/services/ledger}/contracts.d.ts +1 -1
  40. package/lib-es/services/ledger/contracts.d.ts.map +1 -0
  41. package/lib-es/services/ledger/contracts.js +96 -0
  42. package/lib-es/services/ledger/contracts.js.map +1 -0
  43. package/{lib → lib-es/services/ledger}/erc20.d.ts +0 -0
  44. package/lib-es/services/ledger/erc20.d.ts.map +1 -0
  45. package/lib-es/services/ledger/erc20.js +64 -0
  46. package/lib-es/services/ledger/erc20.js.map +1 -0
  47. package/lib-es/services/ledger/index.d.ts +4 -0
  48. package/lib-es/services/ledger/index.d.ts.map +1 -0
  49. package/lib-es/services/ledger/index.js +189 -0
  50. package/lib-es/services/ledger/index.js.map +1 -0
  51. package/lib-es/services/ledger/loadConfig.d.ts +3 -0
  52. package/lib-es/services/ledger/loadConfig.d.ts.map +1 -0
  53. package/lib-es/services/ledger/loadConfig.js +20 -0
  54. package/lib-es/services/ledger/loadConfig.js.map +1 -0
  55. package/{lib → lib-es/services/ledger}/nfts.d.ts +2 -3
  56. package/lib-es/services/ledger/nfts.d.ts.map +1 -0
  57. package/lib-es/services/ledger/nfts.js +94 -0
  58. package/lib-es/services/ledger/nfts.js.map +1 -0
  59. package/lib-es/services/types.d.ts +27 -0
  60. package/lib-es/services/types.d.ts.map +1 -0
  61. package/lib-es/services/types.js +2 -0
  62. package/lib-es/services/types.js.map +1 -0
  63. package/lib-es/utils.d.ts +8 -27
  64. package/lib-es/utils.d.ts.map +1 -1
  65. package/lib-es/utils.js +66 -61
  66. package/lib-es/utils.js.map +1 -1
  67. package/package.json +3 -3
  68. package/src/Eth.ts +133 -258
  69. package/src/{contracts.ts → services/ledger/contracts.ts} +1 -1
  70. package/src/{erc20.ts → services/ledger/erc20.ts} +0 -0
  71. package/src/services/ledger/index.ts +125 -0
  72. package/src/services/ledger/loadConfig.ts +14 -0
  73. package/src/{nfts.ts → services/ledger/nfts.ts} +11 -12
  74. package/src/services/types.ts +42 -0
  75. package/src/utils.ts +72 -94
  76. package/tests/Eth.test.ts +2 -2
  77. package/lib/contracts.d.ts.map +0 -1
  78. package/lib/contracts.js.map +0 -1
  79. package/lib/erc20.d.ts.map +0 -1
  80. package/lib/erc20.js.map +0 -1
  81. package/lib/loadConfig.d.ts +0 -7
  82. package/lib/loadConfig.d.ts.map +0 -1
  83. package/lib/loadConfig.js.map +0 -1
  84. package/lib/nfts.d.ts.map +0 -1
  85. package/lib/nfts.js.map +0 -1
  86. package/src/loadConfig.ts +0 -23
package/lib/Eth.js CHANGED
@@ -46,6 +46,9 @@ var __values = (this && this.__values) || function(o) {
46
46
  };
47
47
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
48
48
  };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
49
52
  exports.__esModule = true;
50
53
  /********************************************************************************
51
54
  * Ledger Node JS API
@@ -64,14 +67,9 @@ exports.__esModule = true;
64
67
  * limitations under the License.
65
68
  ********************************************************************************/
66
69
  // FIXME drop:
67
- var utils_1 = require("./utils");
68
- var logs_1 = require("@ledgerhq/logs");
69
70
  var errors_1 = require("@ledgerhq/errors");
70
- var bignumber_js_1 = require("bignumber.js");
71
- var ethers_1 = require("ethers");
72
- var erc20_1 = require("./erc20");
73
- var contracts_1 = require("./contracts");
74
- var nfts_1 = require("./nfts");
71
+ var utils_1 = require("./utils");
72
+ var ledger_1 = __importDefault(require("./services/ledger"));
75
73
  var starkQuantizationTypeMap = {
76
74
  eth: 1,
77
75
  erc20: 2,
@@ -79,6 +77,21 @@ var starkQuantizationTypeMap = {
79
77
  erc20mintable: 4,
80
78
  erc721mintable: 5
81
79
  };
80
+ function splitPath(path) {
81
+ var result = [];
82
+ var components = path.split("/");
83
+ components.forEach(function (element) {
84
+ var number = parseInt(element, 10);
85
+ if (isNaN(number)) {
86
+ return; // FIXME shouldn't it throws instead?
87
+ }
88
+ if (element.length > 1 && element[element.length - 1] === "'") {
89
+ number += 0x80000000;
90
+ }
91
+ result.push(number);
92
+ });
93
+ return result;
94
+ }
82
95
  function hexBuffer(str) {
83
96
  return Buffer.from(str.startsWith("0x") ? str.slice(2) : str, "hex");
84
97
  }
@@ -140,7 +153,7 @@ var Eth = /** @class */ (function () {
140
153
  * eth.getAddress("44'/60'/0'/0/0").then(o => o.address)
141
154
  */
142
155
  Eth.prototype.getAddress = function (path, boolDisplay, boolChaincode) {
143
- var paths = (0, utils_1.splitPath)(path);
156
+ var paths = splitPath(path);
144
157
  var buffer = Buffer.alloc(1 + paths.length * 4);
145
158
  buffer[0] = paths.length;
146
159
  paths.forEach(function (element, index) {
@@ -166,263 +179,222 @@ var Eth = /** @class */ (function () {
166
179
  });
167
180
  };
168
181
  /**
169
- * This commands provides a trusted description of an ERC 20 token
170
- * to associate a contract address with a ticker and number of decimals.
182
+ * You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign.
171
183
  *
172
- * It shall be run immediately before performing a transaction involving a contract
173
- * calling this contract address to display the proper token information to the user if necessary.
174
- *
175
- * @param {*} info: a blob from "erc20.js" utilities that contains all token information.
176
- *
177
- * @example
178
- * import { byContractAddressAndChainId } from "@ledgerhq/hw-app-eth/erc20"
179
- * const zrxInfo = byContractAddressAndChainId("0xe41d2489571d322189246dafa5ebde1f4699f498", chainId)
180
- * if (zrxInfo) await appEth.provideERC20TokenInformation(zrxInfo)
181
- * const signed = await appEth.signTransaction(path, rawTxHex)
182
- */
183
- Eth.prototype.provideERC20TokenInformation = function (_a) {
184
- var data = _a.data;
185
- return provideERC20TokenInformation(this.transport, data);
186
- };
187
- /**
188
- * You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign
184
+ * @param path: the BIP32 path to sign the transaction on
185
+ * @param rawTxHex: the raw ethereum transaction in hexadecimal to sign
186
+ * @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.
189
187
  * @example
190
- eth.signTransaction("44'/60'/0'/0/0", "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080").then(result => ...)
188
+ import ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger"
189
+ const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
190
+ const resolution = await ledgerService.resolveTransaction(tx);
191
+ const result = eth.signTransaction("44'/60'/0'/0/0", tx, resolution);
192
+ console.log(result);
191
193
  */
192
- Eth.prototype.signTransaction = function (path, rawTxHex) {
194
+ Eth.prototype.signTransaction = function (path, rawTxHex, resolution) {
193
195
  return __awaiter(this, void 0, void 0, function () {
194
- var paths, offset, rawTx, VALID_TYPES, txType, rlpData, toSend, response, rlpTx, vrsOffset, chainId, chainIdTruncated, rlpDecoded, decodedTx, rlpVrs, sizeOfListLen, chainIdSrc, chainIdTruncatedBuf, _loop_1, provideForContract, selector, nftPluginPayload, infos, plugin, payload, signature, erc20OfInterest, abi, contract, args, erc20OfInterest_1, erc20OfInterest_1_1, address, e_1_1;
195
- var e_1, _a;
196
- var _this = this;
197
- return __generator(this, function (_b) {
198
- switch (_b.label) {
196
+ 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;
197
+ var e_1, _l, e_2, _m, e_3, _o, e_4, _p;
198
+ return __generator(this, function (_q) {
199
+ switch (_q.label) {
199
200
  case 0:
200
- paths = (0, utils_1.splitPath)(path);
201
- offset = 0;
202
- rawTx = Buffer.from(rawTxHex, "hex");
203
- VALID_TYPES = [1, 2];
204
- txType = VALID_TYPES.includes(rawTx[0]) ? rawTx[0] : null;
205
- rlpData = txType === null ? rawTx : rawTx.slice(1, rawTxHex.length);
206
- toSend = [];
207
- rlpTx = ethers_1.ethers.utils.RLP.decode(rlpData).map(function (hex) {
208
- return Buffer.from(hex.slice(2), "hex");
209
- });
210
- vrsOffset = 0;
211
- chainId = new bignumber_js_1.BigNumber(0);
212
- chainIdTruncated = 0;
213
- rlpDecoded = ethers_1.ethers.utils.RLP.decode(rlpData);
214
- if (txType === 2) {
215
- // EIP1559
216
- decodedTx = {
217
- data: rlpDecoded[7],
218
- to: rlpDecoded[5],
219
- chainId: rlpTx[0]
220
- };
221
- }
222
- else if (txType === 1) {
223
- // EIP2930
224
- decodedTx = {
225
- data: rlpDecoded[6],
226
- to: rlpDecoded[4],
227
- chainId: rlpTx[0]
228
- };
229
- }
230
- else {
231
- // Legacy tx
232
- decodedTx = {
233
- data: rlpDecoded[5],
234
- to: rlpDecoded[3],
235
- // Default to 1 for non EIP 155 txs
236
- chainId: rlpTx.length > 6 ? rlpTx[6] : Buffer.from("0x01", "hex")
237
- };
238
- }
239
- if (txType === null && rlpTx.length > 6) {
240
- rlpVrs = Buffer.from(ethers_1.ethers.utils.RLP.encode(rlpTx.slice(-3)).slice(2), "hex");
241
- vrsOffset = rawTx.length - (rlpVrs.length - 1);
242
- // First byte > 0xf7 means the length of the list length doesn't fit in a single byte.
243
- if (rlpVrs[0] > 0xf7) {
244
- // Increment vrsOffset to account for that extra byte.
245
- vrsOffset++;
246
- sizeOfListLen = rlpVrs[0] - 0xf7;
247
- // Increase rlpOffset by the size of the list length.
248
- vrsOffset += sizeOfListLen - 1;
249
- }
250
- }
251
- chainIdSrc = decodedTx.chainId;
252
- if (chainIdSrc) {
253
- // Using BigNumber because chainID could be any uint256.
254
- chainId = new bignumber_js_1.BigNumber(chainIdSrc.toString("hex"), 16);
255
- chainIdTruncatedBuf = Buffer.alloc(4);
256
- if (chainIdSrc.length > 4) {
257
- chainIdSrc.copy(chainIdTruncatedBuf);
258
- }
259
- else {
260
- chainIdSrc.copy(chainIdTruncatedBuf, 4 - chainIdSrc.length);
261
- }
262
- chainIdTruncated = chainIdTruncatedBuf.readUInt32BE(0);
263
- }
264
- _loop_1 = function () {
265
- var maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 : 150;
266
- var chunkSize = offset + maxChunkSize > rawTx.length
267
- ? rawTx.length - offset
268
- : maxChunkSize;
269
- if (vrsOffset != 0 && offset + chunkSize >= vrsOffset) {
270
- // Make sure that the chunk doesn't end right on the EIP 155 marker if set
271
- chunkSize = rawTx.length - offset;
272
- }
273
- var buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + chunkSize : chunkSize);
274
- if (offset === 0) {
275
- buffer[0] = paths.length;
276
- paths.forEach(function (element, index) {
277
- buffer.writeUInt32BE(element, 1 + 4 * index);
278
- });
279
- rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
280
- }
281
- else {
282
- rawTx.copy(buffer, 0, offset, offset + chunkSize);
283
- }
284
- toSend.push(buffer);
285
- offset += chunkSize;
286
- };
287
- while (offset !== rawTx.length) {
288
- _loop_1();
289
- }
290
- provideForContract = function (address) { return __awaiter(_this, void 0, void 0, function () {
291
- var nftInfo, erc20Info;
292
- return __generator(this, function (_a) {
293
- switch (_a.label) {
294
- case 0: return [4 /*yield*/, (0, nfts_1.getNFTInfo)(address, chainIdTruncated, this.loadConfig)];
295
- case 1:
296
- nftInfo = _a.sent();
297
- if (!nftInfo) return [3 /*break*/, 3];
298
- (0, logs_1.log)("ethereum", "loading nft info for " +
299
- nftInfo.contractAddress +
300
- " (" +
301
- nftInfo.collectionName +
302
- ")");
303
- return [4 /*yield*/, provideNFTInformation(this.transport, nftInfo.data)];
304
- case 2:
305
- _a.sent();
306
- return [3 /*break*/, 5];
307
- case 3:
308
- erc20Info = (0, erc20_1.byContractAddressAndChainId)(address, chainIdTruncated);
309
- if (!erc20Info) return [3 /*break*/, 5];
310
- (0, logs_1.log)("ethereum", "loading erc20token info for " +
311
- erc20Info.contractAddress +
312
- " (" +
313
- erc20Info.ticker +
314
- ")");
315
- return [4 /*yield*/, provideERC20TokenInformation(this.transport, erc20Info.data)];
316
- case 4:
317
- _a.sent();
318
- _a.label = 5;
319
- case 5: return [2 /*return*/];
320
- }
321
- });
322
- }); };
323
- if (!(decodedTx.data.length >= 10)) return [3 /*break*/, 18];
324
- selector = decodedTx.data.substring(0, 10);
325
- return [4 /*yield*/, (0, nfts_1.loadNftPlugin)(decodedTx.to, selector, chainIdTruncated, this.loadConfig)];
201
+ if (!(resolution === undefined)) return [3 /*break*/, 2];
202
+ console.warn("hw-app-eth: signTransaction(path, rawTxHex, resolution): " +
203
+ "please provide the 'resolution' parameter. " +
204
+ "See https://github.com/LedgerHQ/ledgerjs/blob/master/packages/hw-app-eth/README.md " +
205
+ "– 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)." +
206
+ "// Possible solution:\n" +
207
+ " + import ledgerService from '@ledgerhq/hw-app-eth/lib/services/ledger';\n" +
208
+ " + const resolution = await ledgerService.resolveTransaction(rawTxHex);");
209
+ return [4 /*yield*/, ledger_1["default"]
210
+ .resolveTransaction(rawTxHex, this.loadConfig, {
211
+ externalPlugins: true,
212
+ erc20: true
213
+ })["catch"](function (e) {
214
+ console.warn("an error occurred in resolveTransaction => fallback to blind signing: " +
215
+ String(e));
216
+ return null;
217
+ })];
326
218
  case 1:
327
- nftPluginPayload = _b.sent();
328
- if (!nftPluginPayload) return [3 /*break*/, 3];
329
- return [4 /*yield*/, setPlugin(this.transport, nftPluginPayload)];
219
+ resolution = _q.sent();
220
+ _q.label = 2;
330
221
  case 2:
331
- _b.sent();
332
- return [3 /*break*/, 16];
333
- case 3: return [4 /*yield*/, (0, contracts_1.loadInfosForContractMethod)(decodedTx.to, selector, chainIdTruncated, this.loadConfig)];
222
+ if (!resolution) return [3 /*break*/, 31];
223
+ _q.label = 3;
224
+ case 3:
225
+ _q.trys.push([3, 8, 9, 10]);
226
+ _a = __values(resolution.plugin), _b = _a.next();
227
+ _q.label = 4;
334
228
  case 4:
335
- infos = _b.sent();
336
- if (!infos) return [3 /*break*/, 15];
337
- plugin = infos.plugin, payload = infos.payload, signature = infos.signature, erc20OfInterest = infos.erc20OfInterest, abi = infos.abi;
338
- if (!plugin) return [3 /*break*/, 6];
339
- (0, logs_1.log)("ethereum", "loading plugin for " + selector);
340
- return [4 /*yield*/, setExternalPlugin(this.transport, payload, signature)];
229
+ if (!!_b.done) return [3 /*break*/, 7];
230
+ plugin = _b.value;
231
+ return [4 /*yield*/, setPlugin(this.transport, plugin)];
341
232
  case 5:
342
- _b.sent();
343
- _b.label = 6;
233
+ _q.sent();
234
+ _q.label = 6;
344
235
  case 6:
345
- if (!(erc20OfInterest && erc20OfInterest.length && abi)) return [3 /*break*/, 14];
346
- contract = new ethers_1.ethers.utils.Interface(abi);
347
- args = contract.parseTransaction(decodedTx).args;
348
- _b.label = 7;
349
- case 7:
350
- _b.trys.push([7, 12, 13, 14]);
351
- erc20OfInterest_1 = __values(erc20OfInterest), erc20OfInterest_1_1 = erc20OfInterest_1.next();
352
- _b.label = 8;
236
+ _b = _a.next();
237
+ return [3 /*break*/, 4];
238
+ case 7: return [3 /*break*/, 10];
353
239
  case 8:
354
- if (!!erc20OfInterest_1_1.done) return [3 /*break*/, 11];
355
- path = erc20OfInterest_1_1.value;
356
- address = path.split(".").reduce(function (value, seg) {
357
- if (seg === "-1" && Array.isArray(value)) {
358
- return value[value.length - 1];
359
- }
360
- return value[seg];
361
- }, args);
362
- return [4 /*yield*/, provideForContract(address)];
240
+ e_1_1 = _q.sent();
241
+ e_1 = { error: e_1_1 };
242
+ return [3 /*break*/, 10];
363
243
  case 9:
364
- _b.sent();
365
- _b.label = 10;
244
+ try {
245
+ if (_b && !_b.done && (_l = _a["return"])) _l.call(_a);
246
+ }
247
+ finally { if (e_1) throw e_1.error; }
248
+ return [7 /*endfinally*/];
366
249
  case 10:
367
- erc20OfInterest_1_1 = erc20OfInterest_1.next();
368
- return [3 /*break*/, 8];
369
- case 11: return [3 /*break*/, 14];
250
+ _q.trys.push([10, 15, 16, 17]);
251
+ _c = __values(resolution.externalPlugin), _d = _c.next();
252
+ _q.label = 11;
253
+ case 11:
254
+ if (!!_d.done) return [3 /*break*/, 14];
255
+ _e = _d.value, payload = _e.payload, signature = _e.signature;
256
+ return [4 /*yield*/, setExternalPlugin(this.transport, payload, signature)];
370
257
  case 12:
371
- e_1_1 = _b.sent();
372
- e_1 = { error: e_1_1 };
373
- return [3 /*break*/, 14];
258
+ _q.sent();
259
+ _q.label = 13;
374
260
  case 13:
261
+ _d = _c.next();
262
+ return [3 /*break*/, 11];
263
+ case 14: return [3 /*break*/, 17];
264
+ case 15:
265
+ e_2_1 = _q.sent();
266
+ e_2 = { error: e_2_1 };
267
+ return [3 /*break*/, 17];
268
+ case 16:
375
269
  try {
376
- if (erc20OfInterest_1_1 && !erc20OfInterest_1_1.done && (_a = erc20OfInterest_1["return"])) _a.call(erc20OfInterest_1);
270
+ if (_d && !_d.done && (_m = _c["return"])) _m.call(_c);
377
271
  }
378
- finally { if (e_1) throw e_1.error; }
272
+ finally { if (e_2) throw e_2.error; }
379
273
  return [7 /*endfinally*/];
380
- case 14: return [3 /*break*/, 16];
381
- case 15:
382
- (0, logs_1.log)("ethereum", "no infos for selector " + selector);
383
- _b.label = 16;
384
- case 16: return [4 /*yield*/, provideForContract(decodedTx.to)];
385
274
  case 17:
386
- _b.sent();
387
- _b.label = 18;
388
- case 18: return [2 /*return*/, (0, utils_1.foreach)(toSend, function (data, i) {
389
- return _this.transport
390
- .send(0xe0, 0x04, i === 0 ? 0x00 : 0x80, 0x00, data)
391
- .then(function (apduResponse) {
392
- response = apduResponse;
393
- });
394
- }).then(function () {
395
- var response_byte = response.slice(0, 1)[0];
396
- var v = "";
397
- if (chainId.times(2).plus(35).plus(1).isGreaterThan(255)) {
398
- var oneByteChainId = (chainIdTruncated * 2 + 35) % 256;
399
- var ecc_parity = Math.abs(response_byte - oneByteChainId);
400
- if (txType != null) {
401
- // For EIP2930 and EIP1559 tx, v is simply the parity.
402
- v = ecc_parity % 2 == 1 ? "00" : "01";
403
- }
404
- else {
405
- // Legacy type transaction with a big chain ID
406
- v = chainId.times(2).plus(35).plus(ecc_parity).toString(16);
275
+ _q.trys.push([17, 22, 23, 24]);
276
+ _f = __values(resolution.nfts), _g = _f.next();
277
+ _q.label = 18;
278
+ case 18:
279
+ if (!!_g.done) return [3 /*break*/, 21];
280
+ nft = _g.value;
281
+ return [4 /*yield*/, provideNFTInformation(this.transport, Buffer.from(nft, "hex"))];
282
+ case 19:
283
+ _q.sent();
284
+ _q.label = 20;
285
+ case 20:
286
+ _g = _f.next();
287
+ return [3 /*break*/, 18];
288
+ case 21: return [3 /*break*/, 24];
289
+ case 22:
290
+ e_3_1 = _q.sent();
291
+ e_3 = { error: e_3_1 };
292
+ return [3 /*break*/, 24];
293
+ case 23:
294
+ try {
295
+ if (_g && !_g.done && (_o = _f["return"])) _o.call(_f);
296
+ }
297
+ finally { if (e_3) throw e_3.error; }
298
+ return [7 /*endfinally*/];
299
+ case 24:
300
+ _q.trys.push([24, 29, 30, 31]);
301
+ _h = __values(resolution.erc20Tokens), _j = _h.next();
302
+ _q.label = 25;
303
+ case 25:
304
+ if (!!_j.done) return [3 /*break*/, 28];
305
+ data = _j.value;
306
+ return [4 /*yield*/, provideERC20TokenInformation(this.transport, Buffer.from(data, "hex"))];
307
+ case 26:
308
+ _q.sent();
309
+ _q.label = 27;
310
+ case 27:
311
+ _j = _h.next();
312
+ return [3 /*break*/, 25];
313
+ case 28: return [3 /*break*/, 31];
314
+ case 29:
315
+ e_4_1 = _q.sent();
316
+ e_4 = { error: e_4_1 };
317
+ return [3 /*break*/, 31];
318
+ case 30:
319
+ try {
320
+ if (_j && !_j.done && (_p = _h["return"])) _p.call(_h);
321
+ }
322
+ finally { if (e_4) throw e_4.error; }
323
+ return [7 /*endfinally*/];
324
+ case 31:
325
+ rawTx = Buffer.from(rawTxHex, "hex");
326
+ _k = (0, utils_1.decodeTxInfo)(rawTx), vrsOffset = _k.vrsOffset, txType = _k.txType, chainId = _k.chainId, chainIdTruncated = _k.chainIdTruncated;
327
+ paths = splitPath(path);
328
+ offset = 0;
329
+ _loop_1 = function () {
330
+ var first, maxChunkSize, chunkSize, buffer;
331
+ return __generator(this, function (_r) {
332
+ switch (_r.label) {
333
+ case 0:
334
+ first = offset === 0;
335
+ maxChunkSize = first ? 150 - 1 - paths.length * 4 : 150;
336
+ chunkSize = offset + maxChunkSize > rawTx.length
337
+ ? rawTx.length - offset
338
+ : maxChunkSize;
339
+ if (vrsOffset != 0 && offset + chunkSize >= vrsOffset) {
340
+ // Make sure that the chunk doesn't end right on the EIP 155 marker if set
341
+ chunkSize = rawTx.length - offset;
342
+ }
343
+ buffer = Buffer.alloc(first ? 1 + paths.length * 4 + chunkSize : chunkSize);
344
+ if (first) {
345
+ buffer[0] = paths.length;
346
+ paths.forEach(function (element, index) {
347
+ buffer.writeUInt32BE(element, 1 + 4 * index);
348
+ });
349
+ rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
350
+ }
351
+ else {
352
+ rawTx.copy(buffer, 0, offset, offset + chunkSize);
353
+ }
354
+ return [4 /*yield*/, this_1.transport
355
+ .send(0xe0, 0x04, first ? 0x00 : 0x80, 0x00, buffer)["catch"](function (e) {
356
+ throw remapTransactionRelatedErrors(e);
357
+ })];
358
+ case 1:
359
+ response = _r.sent();
360
+ offset += chunkSize;
361
+ return [2 /*return*/];
407
362
  }
363
+ });
364
+ };
365
+ this_1 = this;
366
+ _q.label = 32;
367
+ case 32:
368
+ if (!(offset !== rawTx.length)) return [3 /*break*/, 34];
369
+ return [5 /*yield**/, _loop_1()];
370
+ case 33:
371
+ _q.sent();
372
+ return [3 /*break*/, 32];
373
+ case 34:
374
+ response_byte = response[0];
375
+ v = "";
376
+ if (chainId.times(2).plus(35).plus(1).isGreaterThan(255)) {
377
+ oneByteChainId = (chainIdTruncated * 2 + 35) % 256;
378
+ ecc_parity = Math.abs(response_byte - oneByteChainId);
379
+ if (txType != null) {
380
+ // For EIP2930 and EIP1559 tx, v is simply the parity.
381
+ v = ecc_parity % 2 == 1 ? "00" : "01";
408
382
  }
409
383
  else {
410
- v = response_byte.toString(16);
411
- }
412
- // Make sure v has is prefixed with a 0 if its length is odd ("1" -> "01").
413
- if (v.length % 2 == 1) {
414
- v = "0" + v;
384
+ // Legacy type transaction with a big chain ID
385
+ v = chainId.times(2).plus(35).plus(ecc_parity).toString(16);
415
386
  }
416
- var r = response.slice(1, 1 + 32).toString("hex");
417
- var s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
418
- return {
419
- v: v,
420
- r: r,
421
- s: s
422
- };
423
- }, function (e) {
424
- throw remapTransactionRelatedErrors(e);
425
- })];
387
+ }
388
+ else {
389
+ v = response_byte.toString(16);
390
+ }
391
+ // Make sure v has is prefixed with a 0 if its length is odd ("1" -> "01").
392
+ if (v.length % 2 == 1) {
393
+ v = "0" + v;
394
+ }
395
+ r = response.slice(1, 1 + 32).toString("hex");
396
+ s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
397
+ return [2 /*return*/, { v: v, r: r, s: s }];
426
398
  }
427
399
  });
428
400
  });
@@ -453,50 +425,58 @@ var Eth = /** @class */ (function () {
453
425
  })
454
426
  */
455
427
  Eth.prototype.signPersonalMessage = function (path, messageHex) {
456
- var _this = this;
457
- var paths = (0, utils_1.splitPath)(path);
458
- var offset = 0;
459
- var message = Buffer.from(messageHex, "hex");
460
- var toSend = [];
461
- var response;
462
- var _loop_2 = function () {
463
- var maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150;
464
- var chunkSize = offset + maxChunkSize > message.length
465
- ? message.length - offset
466
- : maxChunkSize;
467
- var buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize);
468
- if (offset === 0) {
469
- buffer[0] = paths.length;
470
- paths.forEach(function (element, index) {
471
- buffer.writeUInt32BE(element, 1 + 4 * index);
472
- });
473
- buffer.writeUInt32BE(message.length, 1 + 4 * paths.length);
474
- message.copy(buffer, 1 + 4 * paths.length + 4, offset, offset + chunkSize);
475
- }
476
- else {
477
- message.copy(buffer, 0, offset, offset + chunkSize);
478
- }
479
- toSend.push(buffer);
480
- offset += chunkSize;
481
- };
482
- while (offset !== message.length) {
483
- _loop_2();
484
- }
485
- return (0, utils_1.foreach)(toSend, function (data, i) {
486
- return _this.transport
487
- .send(0xe0, 0x08, i === 0 ? 0x00 : 0x80, 0x00, data)
488
- .then(function (apduResponse) {
489
- response = apduResponse;
428
+ return __awaiter(this, void 0, void 0, function () {
429
+ var paths, offset, message, response, _loop_2, this_2, v, r, s;
430
+ return __generator(this, function (_a) {
431
+ switch (_a.label) {
432
+ case 0:
433
+ paths = splitPath(path);
434
+ offset = 0;
435
+ message = Buffer.from(messageHex, "hex");
436
+ _loop_2 = function () {
437
+ var maxChunkSize, chunkSize, buffer;
438
+ return __generator(this, function (_b) {
439
+ switch (_b.label) {
440
+ case 0:
441
+ maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150;
442
+ chunkSize = offset + maxChunkSize > message.length
443
+ ? message.length - offset
444
+ : maxChunkSize;
445
+ buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize);
446
+ if (offset === 0) {
447
+ buffer[0] = paths.length;
448
+ paths.forEach(function (element, index) {
449
+ buffer.writeUInt32BE(element, 1 + 4 * index);
450
+ });
451
+ buffer.writeUInt32BE(message.length, 1 + 4 * paths.length);
452
+ message.copy(buffer, 1 + 4 * paths.length + 4, offset, offset + chunkSize);
453
+ }
454
+ else {
455
+ message.copy(buffer, 0, offset, offset + chunkSize);
456
+ }
457
+ return [4 /*yield*/, this_2.transport.send(0xe0, 0x08, offset === 0 ? 0x00 : 0x80, 0x00, buffer)];
458
+ case 1:
459
+ response = _b.sent();
460
+ offset += chunkSize;
461
+ return [2 /*return*/];
462
+ }
463
+ });
464
+ };
465
+ this_2 = this;
466
+ _a.label = 1;
467
+ case 1:
468
+ if (!(offset !== message.length)) return [3 /*break*/, 3];
469
+ return [5 /*yield**/, _loop_2()];
470
+ case 2:
471
+ _a.sent();
472
+ return [3 /*break*/, 1];
473
+ case 3:
474
+ v = response[0];
475
+ r = response.slice(1, 1 + 32).toString("hex");
476
+ s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
477
+ return [2 /*return*/, { v: v, r: r, s: s }];
478
+ }
490
479
  });
491
- }).then(function () {
492
- var v = response[0];
493
- var r = response.slice(1, 1 + 32).toString("hex");
494
- var s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
495
- return {
496
- v: v,
497
- r: r,
498
- s: s
499
- };
500
480
  });
501
481
  };
502
482
  /**
@@ -514,7 +494,7 @@ var Eth = /** @class */ (function () {
514
494
  Eth.prototype.signEIP712HashedMessage = function (path, domainSeparatorHex, hashStructMessageHex) {
515
495
  var domainSeparator = hexBuffer(domainSeparatorHex);
516
496
  var hashStruct = hexBuffer(hashStructMessageHex);
517
- var paths = (0, utils_1.splitPath)(path);
497
+ var paths = splitPath(path);
518
498
  var buffer = Buffer.alloc(1 + paths.length * 4 + 32 + 32, 0);
519
499
  var offset = 0;
520
500
  buffer[0] = paths.length;
@@ -545,7 +525,7 @@ var Eth = /** @class */ (function () {
545
525
  * @return the Stark public key
546
526
  */
547
527
  Eth.prototype.starkGetPublicKey = function (path, boolDisplay) {
548
- var paths = (0, utils_1.splitPath)(path);
528
+ var paths = splitPath(path);
549
529
  var buffer = Buffer.alloc(1 + paths.length * 4);
550
530
  buffer[0] = paths.length;
551
531
  paths.forEach(function (element, index) {
@@ -575,7 +555,7 @@ var Eth = /** @class */ (function () {
575
555
  Eth.prototype.starkSignOrder = function (path, sourceTokenAddress, sourceQuantization, destinationTokenAddress, destinationQuantization, sourceVault, destinationVault, amountSell, amountBuy, nonce, timestamp) {
576
556
  var sourceTokenAddressHex = maybeHexBuffer(sourceTokenAddress);
577
557
  var destinationTokenAddressHex = maybeHexBuffer(destinationTokenAddress);
578
- var paths = (0, utils_1.splitPath)(path);
558
+ var paths = splitPath(path);
579
559
  var buffer = Buffer.alloc(1 + paths.length * 4 + 20 + 32 + 20 + 32 + 4 + 4 + 8 + 8 + 4 + 4, 0);
580
560
  var offset = 0;
581
561
  buffer[0] = paths.length;
@@ -647,7 +627,7 @@ var Eth = /** @class */ (function () {
647
627
  throw new Error("eth.starkSignOrderv2 invalid destination quantization type=" +
648
628
  destinationQuantizationType);
649
629
  }
650
- var paths = (0, utils_1.splitPath)(path);
630
+ var paths = splitPath(path);
651
631
  var buffer = Buffer.alloc(1 +
652
632
  paths.length * 4 +
653
633
  1 +
@@ -736,7 +716,7 @@ var Eth = /** @class */ (function () {
736
716
  Eth.prototype.starkSignTransfer = function (path, transferTokenAddress, transferQuantization, targetPublicKey, sourceVault, destinationVault, amountTransfer, nonce, timestamp) {
737
717
  var transferTokenAddressHex = maybeHexBuffer(transferTokenAddress);
738
718
  var targetPublicKeyHex = hexBuffer(targetPublicKey);
739
- var paths = (0, utils_1.splitPath)(path);
719
+ var paths = splitPath(path);
740
720
  var buffer = Buffer.alloc(1 + paths.length * 4 + 20 + 32 + 32 + 4 + 4 + 8 + 4 + 4, 0);
741
721
  var offset = 0;
742
722
  buffer[0] = paths.length;
@@ -797,7 +777,7 @@ var Eth = /** @class */ (function () {
797
777
  throw new Error("eth.starkSignTransferv2 invalid quantization type=" +
798
778
  transferQuantizationType);
799
779
  }
800
- var paths = (0, utils_1.splitPath)(path);
780
+ var paths = splitPath(path);
801
781
  var buffer = Buffer.alloc(1 +
802
782
  paths.length * 4 +
803
783
  1 +
@@ -930,7 +910,7 @@ var Eth = /** @class */ (function () {
930
910
  */
931
911
  Eth.prototype.starkUnsafeSign = function (path, hash) {
932
912
  var hashHex = hexBuffer(hash);
933
- var paths = (0, utils_1.splitPath)(path);
913
+ var paths = splitPath(path);
934
914
  var buffer = Buffer.alloc(1 + paths.length * 4 + 32);
935
915
  var offset = 0;
936
916
  buffer[0] = paths.length;
@@ -959,7 +939,7 @@ var Eth = /** @class */ (function () {
959
939
  * eth.eth2GetPublicKey("12381/3600/0/0").then(o => o.publicKey)
960
940
  */
961
941
  Eth.prototype.eth2GetPublicKey = function (path, boolDisplay) {
962
- var paths = (0, utils_1.splitPath)(path);
942
+ var paths = splitPath(path);
963
943
  var buffer = Buffer.alloc(1 + paths.length * 4);
964
944
  buffer[0] = paths.length;
965
945
  paths.forEach(function (element, index) {
@@ -992,22 +972,17 @@ var Eth = /** @class */ (function () {
992
972
  throw e;
993
973
  });
994
974
  };
995
- /**
996
- * Set the name of the external plugin that should be used to parse the next transaction
997
- *
998
- * @param pluginName string containing the name of the plugin, must have length between 1 and 30 bytes
999
- * @return True if the method was executed successfully
1000
- */
975
+ Eth.prototype.provideERC20TokenInformation = function (_a) {
976
+ var data = _a.data;
977
+ console.warn("hw-app-eth: eth.provideERC20TokenInformation is deprecated. signTransaction solves this for you when providing it in `resolution`.");
978
+ return provideERC20TokenInformation(this.transport, data);
979
+ };
1001
980
  Eth.prototype.setExternalPlugin = function (pluginName, contractAddress, selector) {
981
+ console.warn("hw-app-eth: eth.setExternalPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
1002
982
  return setExternalPlugin(this.transport, pluginName, selector);
1003
983
  };
1004
- /**
1005
- * Set the plugin (internal or external) that should be used to parse the next transaction
1006
- *
1007
- * @param data string containing the payload and signature that will be parsed and verified by the device.
1008
- * @return True if the method was executed successfully
1009
- */
1010
984
  Eth.prototype.setPlugin = function (data) {
985
+ console.warn("hw-app-eth: eth.setPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
1011
986
  return setPlugin(this.transport, data);
1012
987
  };
1013
988
  return Eth;