@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.
- package/README.md +66 -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 +280 -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 +191 -0
- package/lib/services/ledger/index.js.map +1 -0
- package/lib/services/ledger/loadConfig.d.ts +3 -0
- package/lib/services/ledger/loadConfig.d.ts.map +1 -0
- package/lib/{loadConfig.js → services/ledger/loadConfig.js} +0 -0
- package/lib/services/ledger/loadConfig.js.map +1 -0
- package/lib/services/ledger/nfts.d.ts +10 -0
- package/lib/services/ledger/nfts.d.ts.map +1 -0
- package/lib/{nfts.js → services/ledger/nfts.js} +10 -10
- package/lib/services/ledger/nfts.js.map +1 -0
- package/lib/services/types.d.ts +27 -0
- package/lib/services/types.d.ts.map +1 -0
- package/lib/services/types.js +3 -0
- package/lib/services/types.js.map +1 -0
- package/lib/utils.d.ts +8 -27
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +68 -68
- package/lib/utils.js.map +1 -1
- package/lib-es/Eth.d.ts +14 -33
- package/lib-es/Eth.d.ts.map +1 -1
- package/lib-es/Eth.js +268 -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 +189 -0
- package/lib-es/services/ledger/index.js.map +1 -0
- package/lib-es/services/ledger/loadConfig.d.ts +3 -0
- package/lib-es/services/ledger/loadConfig.d.ts.map +1 -0
- package/lib-es/services/ledger/loadConfig.js +20 -0
- package/lib-es/services/ledger/loadConfig.js.map +1 -0
- package/{lib → lib-es/services/ledger}/nfts.d.ts +2 -3
- package/lib-es/services/ledger/nfts.d.ts.map +1 -0
- package/lib-es/services/ledger/nfts.js +94 -0
- package/lib-es/services/ledger/nfts.js.map +1 -0
- package/lib-es/services/types.d.ts +27 -0
- package/lib-es/services/types.d.ts.map +1 -0
- package/lib-es/services/types.js +2 -0
- package/lib-es/services/types.js.map +1 -0
- package/lib-es/utils.d.ts +8 -27
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +66 -61
- package/lib-es/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/Eth.ts +133 -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 +125 -0
- package/src/services/ledger/loadConfig.ts +14 -0
- package/src/{nfts.ts → services/ledger/nfts.ts} +11 -12
- package/src/services/types.ts +42 -0
- package/src/utils.ts +72 -94
- package/tests/Eth.test.ts +2 -2
- package/lib/contracts.d.ts.map +0 -1
- package/lib/contracts.js.map +0 -1
- package/lib/erc20.d.ts.map +0 -1
- package/lib/erc20.js.map +0 -1
- package/lib/loadConfig.d.ts +0 -7
- package/lib/loadConfig.d.ts.map +0 -1
- package/lib/loadConfig.js.map +0 -1
- package/lib/nfts.d.ts.map +0 -1
- package/lib/nfts.js.map +0 -1
- package/src/loadConfig.ts +0 -23
package/lib/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,222 @@ 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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
return [4 /*yield*/, setPlugin(this.transport, nftPluginPayload)];
|
|
219
|
+
resolution = _q.sent();
|
|
220
|
+
_q.label = 2;
|
|
330
221
|
case 2:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
case 3:
|
|
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
|
-
|
|
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)];
|
|
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
|
-
|
|
343
|
-
|
|
233
|
+
_q.sent();
|
|
234
|
+
_q.label = 6;
|
|
344
235
|
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;
|
|
236
|
+
_b = _a.next();
|
|
237
|
+
return [3 /*break*/, 4];
|
|
238
|
+
case 7: return [3 /*break*/, 10];
|
|
353
239
|
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)];
|
|
240
|
+
e_1_1 = _q.sent();
|
|
241
|
+
e_1 = { error: e_1_1 };
|
|
242
|
+
return [3 /*break*/, 10];
|
|
363
243
|
case 9:
|
|
364
|
-
|
|
365
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
|
|
372
|
-
|
|
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 (
|
|
270
|
+
if (_d && !_d.done && (_m = _c["return"])) _m.call(_c);
|
|
377
271
|
}
|
|
378
|
-
finally { if (
|
|
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
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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
|
-
|
|
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
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
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;
|