@ledgerhq/hw-app-eth 6.21.3 → 6.22.0

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 +51 -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 +273 -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 +168 -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} +3 -14
  26. package/lib/services/ledger/nfts.js.map +1 -0
  27. package/lib/services/types.d.ts +18 -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 +261 -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 +166 -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 +83 -0
  58. package/lib-es/services/ledger/nfts.js.map +1 -0
  59. package/lib-es/services/types.d.ts +18 -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 +124 -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 +119 -0
  72. package/src/services/ledger/loadConfig.ts +14 -0
  73. package/src/{nfts.ts → services/ledger/nfts.ts} +5 -18
  74. package/src/services/types.ts +28 -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,215 @@ 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)["catch"](function () { return null; })];
326
211
  case 1:
327
- nftPluginPayload = _b.sent();
328
- if (!nftPluginPayload) return [3 /*break*/, 3];
329
- return [4 /*yield*/, setPlugin(this.transport, nftPluginPayload)];
212
+ resolution = _q.sent();
213
+ _q.label = 2;
330
214
  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)];
215
+ if (!resolution) return [3 /*break*/, 31];
216
+ _q.label = 3;
217
+ case 3:
218
+ _q.trys.push([3, 8, 9, 10]);
219
+ _a = __values(resolution.plugin), _b = _a.next();
220
+ _q.label = 4;
334
221
  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)];
222
+ if (!!_b.done) return [3 /*break*/, 7];
223
+ plugin = _b.value;
224
+ return [4 /*yield*/, setPlugin(this.transport, plugin)];
341
225
  case 5:
342
- _b.sent();
343
- _b.label = 6;
226
+ _q.sent();
227
+ _q.label = 6;
344
228
  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;
229
+ _b = _a.next();
230
+ return [3 /*break*/, 4];
231
+ case 7: return [3 /*break*/, 10];
353
232
  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)];
233
+ e_1_1 = _q.sent();
234
+ e_1 = { error: e_1_1 };
235
+ return [3 /*break*/, 10];
363
236
  case 9:
364
- _b.sent();
365
- _b.label = 10;
237
+ try {
238
+ if (_b && !_b.done && (_l = _a["return"])) _l.call(_a);
239
+ }
240
+ finally { if (e_1) throw e_1.error; }
241
+ return [7 /*endfinally*/];
366
242
  case 10:
367
- erc20OfInterest_1_1 = erc20OfInterest_1.next();
368
- return [3 /*break*/, 8];
369
- case 11: return [3 /*break*/, 14];
243
+ _q.trys.push([10, 15, 16, 17]);
244
+ _c = __values(resolution.externalPlugin), _d = _c.next();
245
+ _q.label = 11;
246
+ case 11:
247
+ if (!!_d.done) return [3 /*break*/, 14];
248
+ _e = _d.value, payload = _e.payload, signature = _e.signature;
249
+ return [4 /*yield*/, setExternalPlugin(this.transport, payload, signature)];
370
250
  case 12:
371
- e_1_1 = _b.sent();
372
- e_1 = { error: e_1_1 };
373
- return [3 /*break*/, 14];
251
+ _q.sent();
252
+ _q.label = 13;
374
253
  case 13:
254
+ _d = _c.next();
255
+ return [3 /*break*/, 11];
256
+ case 14: return [3 /*break*/, 17];
257
+ case 15:
258
+ e_2_1 = _q.sent();
259
+ e_2 = { error: e_2_1 };
260
+ return [3 /*break*/, 17];
261
+ case 16:
375
262
  try {
376
- if (erc20OfInterest_1_1 && !erc20OfInterest_1_1.done && (_a = erc20OfInterest_1["return"])) _a.call(erc20OfInterest_1);
263
+ if (_d && !_d.done && (_m = _c["return"])) _m.call(_c);
377
264
  }
378
- finally { if (e_1) throw e_1.error; }
265
+ finally { if (e_2) throw e_2.error; }
379
266
  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
267
  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);
268
+ _q.trys.push([17, 22, 23, 24]);
269
+ _f = __values(resolution.nfts), _g = _f.next();
270
+ _q.label = 18;
271
+ case 18:
272
+ if (!!_g.done) return [3 /*break*/, 21];
273
+ nft = _g.value;
274
+ return [4 /*yield*/, provideNFTInformation(this.transport, Buffer.from(nft, "hex"))];
275
+ case 19:
276
+ _q.sent();
277
+ _q.label = 20;
278
+ case 20:
279
+ _g = _f.next();
280
+ return [3 /*break*/, 18];
281
+ case 21: return [3 /*break*/, 24];
282
+ case 22:
283
+ e_3_1 = _q.sent();
284
+ e_3 = { error: e_3_1 };
285
+ return [3 /*break*/, 24];
286
+ case 23:
287
+ try {
288
+ if (_g && !_g.done && (_o = _f["return"])) _o.call(_f);
289
+ }
290
+ finally { if (e_3) throw e_3.error; }
291
+ return [7 /*endfinally*/];
292
+ case 24:
293
+ _q.trys.push([24, 29, 30, 31]);
294
+ _h = __values(resolution.erc20Tokens), _j = _h.next();
295
+ _q.label = 25;
296
+ case 25:
297
+ if (!!_j.done) return [3 /*break*/, 28];
298
+ data = _j.value;
299
+ return [4 /*yield*/, provideERC20TokenInformation(this.transport, Buffer.from(data, "hex"))];
300
+ case 26:
301
+ _q.sent();
302
+ _q.label = 27;
303
+ case 27:
304
+ _j = _h.next();
305
+ return [3 /*break*/, 25];
306
+ case 28: return [3 /*break*/, 31];
307
+ case 29:
308
+ e_4_1 = _q.sent();
309
+ e_4 = { error: e_4_1 };
310
+ return [3 /*break*/, 31];
311
+ case 30:
312
+ try {
313
+ if (_j && !_j.done && (_p = _h["return"])) _p.call(_h);
314
+ }
315
+ finally { if (e_4) throw e_4.error; }
316
+ return [7 /*endfinally*/];
317
+ case 31:
318
+ rawTx = Buffer.from(rawTxHex, "hex");
319
+ _k = (0, utils_1.decodeTxInfo)(rawTx), vrsOffset = _k.vrsOffset, txType = _k.txType, chainId = _k.chainId, chainIdTruncated = _k.chainIdTruncated;
320
+ paths = splitPath(path);
321
+ offset = 0;
322
+ _loop_1 = function () {
323
+ var first, maxChunkSize, chunkSize, buffer;
324
+ return __generator(this, function (_r) {
325
+ switch (_r.label) {
326
+ case 0:
327
+ first = offset === 0;
328
+ maxChunkSize = first ? 150 - 1 - paths.length * 4 : 150;
329
+ chunkSize = offset + maxChunkSize > rawTx.length
330
+ ? rawTx.length - offset
331
+ : maxChunkSize;
332
+ if (vrsOffset != 0 && offset + chunkSize >= vrsOffset) {
333
+ // Make sure that the chunk doesn't end right on the EIP 155 marker if set
334
+ chunkSize = rawTx.length - offset;
335
+ }
336
+ buffer = Buffer.alloc(first ? 1 + paths.length * 4 + chunkSize : chunkSize);
337
+ if (first) {
338
+ buffer[0] = paths.length;
339
+ paths.forEach(function (element, index) {
340
+ buffer.writeUInt32BE(element, 1 + 4 * index);
341
+ });
342
+ rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
343
+ }
344
+ else {
345
+ rawTx.copy(buffer, 0, offset, offset + chunkSize);
346
+ }
347
+ return [4 /*yield*/, this_1.transport
348
+ .send(0xe0, 0x04, first ? 0x00 : 0x80, 0x00, buffer)["catch"](function (e) {
349
+ throw remapTransactionRelatedErrors(e);
350
+ })];
351
+ case 1:
352
+ response = _r.sent();
353
+ offset += chunkSize;
354
+ return [2 /*return*/];
407
355
  }
356
+ });
357
+ };
358
+ this_1 = this;
359
+ _q.label = 32;
360
+ case 32:
361
+ if (!(offset !== rawTx.length)) return [3 /*break*/, 34];
362
+ return [5 /*yield**/, _loop_1()];
363
+ case 33:
364
+ _q.sent();
365
+ return [3 /*break*/, 32];
366
+ case 34:
367
+ response_byte = response[0];
368
+ v = "";
369
+ if (chainId.times(2).plus(35).plus(1).isGreaterThan(255)) {
370
+ oneByteChainId = (chainIdTruncated * 2 + 35) % 256;
371
+ ecc_parity = Math.abs(response_byte - oneByteChainId);
372
+ if (txType != null) {
373
+ // For EIP2930 and EIP1559 tx, v is simply the parity.
374
+ v = ecc_parity % 2 == 1 ? "00" : "01";
408
375
  }
409
376
  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;
377
+ // Legacy type transaction with a big chain ID
378
+ v = chainId.times(2).plus(35).plus(ecc_parity).toString(16);
415
379
  }
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
- })];
380
+ }
381
+ else {
382
+ v = response_byte.toString(16);
383
+ }
384
+ // Make sure v has is prefixed with a 0 if its length is odd ("1" -> "01").
385
+ if (v.length % 2 == 1) {
386
+ v = "0" + v;
387
+ }
388
+ r = response.slice(1, 1 + 32).toString("hex");
389
+ s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
390
+ return [2 /*return*/, { v: v, r: r, s: s }];
426
391
  }
427
392
  });
428
393
  });
@@ -453,50 +418,58 @@ var Eth = /** @class */ (function () {
453
418
  })
454
419
  */
455
420
  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;
421
+ return __awaiter(this, void 0, void 0, function () {
422
+ var paths, offset, message, response, _loop_2, this_2, v, r, s;
423
+ return __generator(this, function (_a) {
424
+ switch (_a.label) {
425
+ case 0:
426
+ paths = splitPath(path);
427
+ offset = 0;
428
+ message = Buffer.from(messageHex, "hex");
429
+ _loop_2 = function () {
430
+ var maxChunkSize, chunkSize, buffer;
431
+ return __generator(this, function (_b) {
432
+ switch (_b.label) {
433
+ case 0:
434
+ maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150;
435
+ chunkSize = offset + maxChunkSize > message.length
436
+ ? message.length - offset
437
+ : maxChunkSize;
438
+ buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize);
439
+ if (offset === 0) {
440
+ buffer[0] = paths.length;
441
+ paths.forEach(function (element, index) {
442
+ buffer.writeUInt32BE(element, 1 + 4 * index);
443
+ });
444
+ buffer.writeUInt32BE(message.length, 1 + 4 * paths.length);
445
+ message.copy(buffer, 1 + 4 * paths.length + 4, offset, offset + chunkSize);
446
+ }
447
+ else {
448
+ message.copy(buffer, 0, offset, offset + chunkSize);
449
+ }
450
+ return [4 /*yield*/, this_2.transport.send(0xe0, 0x08, offset === 0 ? 0x00 : 0x80, 0x00, buffer)];
451
+ case 1:
452
+ response = _b.sent();
453
+ offset += chunkSize;
454
+ return [2 /*return*/];
455
+ }
456
+ });
457
+ };
458
+ this_2 = this;
459
+ _a.label = 1;
460
+ case 1:
461
+ if (!(offset !== message.length)) return [3 /*break*/, 3];
462
+ return [5 /*yield**/, _loop_2()];
463
+ case 2:
464
+ _a.sent();
465
+ return [3 /*break*/, 1];
466
+ case 3:
467
+ v = response[0];
468
+ r = response.slice(1, 1 + 32).toString("hex");
469
+ s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
470
+ return [2 /*return*/, { v: v, r: r, s: s }];
471
+ }
490
472
  });
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
473
  });
501
474
  };
502
475
  /**
@@ -514,7 +487,7 @@ var Eth = /** @class */ (function () {
514
487
  Eth.prototype.signEIP712HashedMessage = function (path, domainSeparatorHex, hashStructMessageHex) {
515
488
  var domainSeparator = hexBuffer(domainSeparatorHex);
516
489
  var hashStruct = hexBuffer(hashStructMessageHex);
517
- var paths = (0, utils_1.splitPath)(path);
490
+ var paths = splitPath(path);
518
491
  var buffer = Buffer.alloc(1 + paths.length * 4 + 32 + 32, 0);
519
492
  var offset = 0;
520
493
  buffer[0] = paths.length;
@@ -545,7 +518,7 @@ var Eth = /** @class */ (function () {
545
518
  * @return the Stark public key
546
519
  */
547
520
  Eth.prototype.starkGetPublicKey = function (path, boolDisplay) {
548
- var paths = (0, utils_1.splitPath)(path);
521
+ var paths = splitPath(path);
549
522
  var buffer = Buffer.alloc(1 + paths.length * 4);
550
523
  buffer[0] = paths.length;
551
524
  paths.forEach(function (element, index) {
@@ -575,7 +548,7 @@ var Eth = /** @class */ (function () {
575
548
  Eth.prototype.starkSignOrder = function (path, sourceTokenAddress, sourceQuantization, destinationTokenAddress, destinationQuantization, sourceVault, destinationVault, amountSell, amountBuy, nonce, timestamp) {
576
549
  var sourceTokenAddressHex = maybeHexBuffer(sourceTokenAddress);
577
550
  var destinationTokenAddressHex = maybeHexBuffer(destinationTokenAddress);
578
- var paths = (0, utils_1.splitPath)(path);
551
+ var paths = splitPath(path);
579
552
  var buffer = Buffer.alloc(1 + paths.length * 4 + 20 + 32 + 20 + 32 + 4 + 4 + 8 + 8 + 4 + 4, 0);
580
553
  var offset = 0;
581
554
  buffer[0] = paths.length;
@@ -647,7 +620,7 @@ var Eth = /** @class */ (function () {
647
620
  throw new Error("eth.starkSignOrderv2 invalid destination quantization type=" +
648
621
  destinationQuantizationType);
649
622
  }
650
- var paths = (0, utils_1.splitPath)(path);
623
+ var paths = splitPath(path);
651
624
  var buffer = Buffer.alloc(1 +
652
625
  paths.length * 4 +
653
626
  1 +
@@ -736,7 +709,7 @@ var Eth = /** @class */ (function () {
736
709
  Eth.prototype.starkSignTransfer = function (path, transferTokenAddress, transferQuantization, targetPublicKey, sourceVault, destinationVault, amountTransfer, nonce, timestamp) {
737
710
  var transferTokenAddressHex = maybeHexBuffer(transferTokenAddress);
738
711
  var targetPublicKeyHex = hexBuffer(targetPublicKey);
739
- var paths = (0, utils_1.splitPath)(path);
712
+ var paths = splitPath(path);
740
713
  var buffer = Buffer.alloc(1 + paths.length * 4 + 20 + 32 + 32 + 4 + 4 + 8 + 4 + 4, 0);
741
714
  var offset = 0;
742
715
  buffer[0] = paths.length;
@@ -797,7 +770,7 @@ var Eth = /** @class */ (function () {
797
770
  throw new Error("eth.starkSignTransferv2 invalid quantization type=" +
798
771
  transferQuantizationType);
799
772
  }
800
- var paths = (0, utils_1.splitPath)(path);
773
+ var paths = splitPath(path);
801
774
  var buffer = Buffer.alloc(1 +
802
775
  paths.length * 4 +
803
776
  1 +
@@ -930,7 +903,7 @@ var Eth = /** @class */ (function () {
930
903
  */
931
904
  Eth.prototype.starkUnsafeSign = function (path, hash) {
932
905
  var hashHex = hexBuffer(hash);
933
- var paths = (0, utils_1.splitPath)(path);
906
+ var paths = splitPath(path);
934
907
  var buffer = Buffer.alloc(1 + paths.length * 4 + 32);
935
908
  var offset = 0;
936
909
  buffer[0] = paths.length;
@@ -959,7 +932,7 @@ var Eth = /** @class */ (function () {
959
932
  * eth.eth2GetPublicKey("12381/3600/0/0").then(o => o.publicKey)
960
933
  */
961
934
  Eth.prototype.eth2GetPublicKey = function (path, boolDisplay) {
962
- var paths = (0, utils_1.splitPath)(path);
935
+ var paths = splitPath(path);
963
936
  var buffer = Buffer.alloc(1 + paths.length * 4);
964
937
  buffer[0] = paths.length;
965
938
  paths.forEach(function (element, index) {
@@ -992,22 +965,17 @@ var Eth = /** @class */ (function () {
992
965
  throw e;
993
966
  });
994
967
  };
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
- */
968
+ Eth.prototype.provideERC20TokenInformation = function (_a) {
969
+ var data = _a.data;
970
+ console.warn("hw-app-eth: eth.provideERC20TokenInformation is deprecated. signTransaction solves this for you when providing it in `resolution`.");
971
+ return provideERC20TokenInformation(this.transport, data);
972
+ };
1001
973
  Eth.prototype.setExternalPlugin = function (pluginName, contractAddress, selector) {
974
+ console.warn("hw-app-eth: eth.setExternalPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
1002
975
  return setExternalPlugin(this.transport, pluginName, selector);
1003
976
  };
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
977
  Eth.prototype.setPlugin = function (data) {
978
+ console.warn("hw-app-eth: eth.setPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
1011
979
  return setPlugin(this.transport, data);
1012
980
  };
1013
981
  return Eth;