@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.
- package/README.md +51 -100
- package/erc20.js +1 -1
- package/lib/Eth.d.ts +14 -33
- package/lib/Eth.d.ts.map +1 -1
- package/lib/Eth.js +273 -305
- package/lib/Eth.js.map +1 -1
- 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 +168 -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} +3 -14
- package/lib/services/ledger/nfts.js.map +1 -0
- package/lib/services/types.d.ts +18 -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 +14 -33
- package/lib-es/Eth.d.ts.map +1 -1
- package/lib-es/Eth.js +261 -296
- package/lib-es/Eth.js.map +1 -1
- 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 +166 -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 +83 -0
- package/lib-es/services/ledger/nfts.js.map +1 -0
- package/lib-es/services/types.d.ts +18 -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 +124 -258
- 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 +119 -0
- package/src/services/ledger/loadConfig.ts +14 -0
- package/src/{nfts.ts → services/ledger/nfts.ts} +5 -18
- package/src/services/types.ts +28 -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/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
|
|
71
|
-
var
|
|
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 =
|
|
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
|
-
*
|
|
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
|
-
*
|
|
173
|
-
*
|
|
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
|
-
|
|
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
|
|
195
|
-
var e_1,
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
return [4 /*yield*/, setPlugin(this.transport, nftPluginPayload)];
|
|
212
|
+
resolution = _q.sent();
|
|
213
|
+
_q.label = 2;
|
|
330
214
|
case 2:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
case 3:
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
343
|
-
|
|
226
|
+
_q.sent();
|
|
227
|
+
_q.label = 6;
|
|
344
228
|
case 6:
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
365
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
372
|
-
|
|
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 (
|
|
263
|
+
if (_d && !_d.done && (_m = _c["return"])) _m.call(_c);
|
|
377
264
|
}
|
|
378
|
-
finally { if (
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
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
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
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
|
-
|
|
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
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
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;
|