@ledgerhq/hw-app-eth 6.21.3 → 6.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -100
- package/erc20.js +1 -1
- package/lib/Eth.d.ts +30 -33
- package/lib/Eth.d.ts.map +1 -1
- package/lib/Eth.js +282 -324
- package/lib/Eth.js.map +1 -1
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +7 -0
- package/lib/errors.js.map +1 -0
- package/lib/services/ledger/contracts.d.ts +14 -0
- package/lib/services/ledger/contracts.d.ts.map +1 -0
- package/lib/{contracts.js → services/ledger/contracts.js} +0 -0
- package/lib/services/ledger/contracts.js.map +1 -0
- package/lib/services/ledger/erc20.d.ts +22 -0
- package/lib/services/ledger/erc20.d.ts.map +1 -0
- package/lib/{erc20.js → services/ledger/erc20.js} +0 -0
- package/lib/services/ledger/erc20.js.map +1 -0
- package/lib/services/ledger/index.d.ts +4 -0
- package/lib/services/ledger/index.d.ts.map +1 -0
- package/lib/services/ledger/index.js +191 -0
- package/lib/services/ledger/index.js.map +1 -0
- package/lib/services/ledger/loadConfig.d.ts +3 -0
- package/lib/services/ledger/loadConfig.d.ts.map +1 -0
- package/lib/{loadConfig.js → services/ledger/loadConfig.js} +0 -0
- package/lib/services/ledger/loadConfig.js.map +1 -0
- package/lib/services/ledger/nfts.d.ts +10 -0
- package/lib/services/ledger/nfts.d.ts.map +1 -0
- package/lib/{nfts.js → services/ledger/nfts.js} +10 -10
- package/lib/services/ledger/nfts.js.map +1 -0
- package/lib/services/types.d.ts +27 -0
- package/lib/services/types.d.ts.map +1 -0
- package/lib/services/types.js +3 -0
- package/lib/services/types.js.map +1 -0
- package/lib/utils.d.ts +8 -27
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +68 -68
- package/lib/utils.js.map +1 -1
- package/lib-es/Eth.d.ts +30 -33
- package/lib-es/Eth.d.ts.map +1 -1
- package/lib-es/Eth.js +271 -316
- package/lib-es/Eth.js.map +1 -1
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +4 -0
- package/lib-es/errors.js.map +1 -0
- package/{lib → lib-es/services/ledger}/contracts.d.ts +1 -1
- package/lib-es/services/ledger/contracts.d.ts.map +1 -0
- package/lib-es/services/ledger/contracts.js +96 -0
- package/lib-es/services/ledger/contracts.js.map +1 -0
- package/{lib → lib-es/services/ledger}/erc20.d.ts +0 -0
- package/lib-es/services/ledger/erc20.d.ts.map +1 -0
- package/lib-es/services/ledger/erc20.js +64 -0
- package/lib-es/services/ledger/erc20.js.map +1 -0
- package/lib-es/services/ledger/index.d.ts +4 -0
- package/lib-es/services/ledger/index.d.ts.map +1 -0
- package/lib-es/services/ledger/index.js +189 -0
- package/lib-es/services/ledger/index.js.map +1 -0
- package/lib-es/services/ledger/loadConfig.d.ts +3 -0
- package/lib-es/services/ledger/loadConfig.d.ts.map +1 -0
- package/lib-es/services/ledger/loadConfig.js +20 -0
- package/lib-es/services/ledger/loadConfig.js.map +1 -0
- package/{lib → lib-es/services/ledger}/nfts.d.ts +2 -3
- package/lib-es/services/ledger/nfts.d.ts.map +1 -0
- package/lib-es/services/ledger/nfts.js +94 -0
- package/lib-es/services/ledger/nfts.js.map +1 -0
- package/lib-es/services/types.d.ts +27 -0
- package/lib-es/services/types.d.ts.map +1 -0
- package/lib-es/services/types.js +2 -0
- package/lib-es/services/types.js.map +1 -0
- package/lib-es/utils.d.ts +8 -27
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +66 -61
- package/lib-es/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/Eth.ts +139 -261
- package/src/errors.ts +8 -0
- package/src/{contracts.ts → services/ledger/contracts.ts} +1 -1
- package/src/{erc20.ts → services/ledger/erc20.ts} +0 -0
- package/src/services/ledger/index.ts +125 -0
- package/src/services/ledger/loadConfig.ts +14 -0
- package/src/{nfts.ts → services/ledger/nfts.ts} +11 -12
- package/src/services/types.ts +42 -0
- package/src/utils.ts +72 -94
- package/tests/Eth.test.ts +2 -2
- package/lib/contracts.d.ts.map +0 -1
- package/lib/contracts.js.map +0 -1
- package/lib/erc20.d.ts.map +0 -1
- package/lib/erc20.js.map +0 -1
- package/lib/loadConfig.d.ts +0 -7
- package/lib/loadConfig.d.ts.map +0 -1
- package/lib/loadConfig.js.map +0 -1
- package/lib/nfts.d.ts.map +0 -1
- package/lib/nfts.js.map +0 -1
- package/src/loadConfig.ts +0 -23
package/lib/Eth.js
CHANGED
|
@@ -46,32 +46,13 @@ 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
|
-
/********************************************************************************
|
|
51
|
-
* Ledger Node JS API
|
|
52
|
-
* (c) 2016-2017 Ledger
|
|
53
|
-
*
|
|
54
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
55
|
-
* you may not use this file except in compliance with the License.
|
|
56
|
-
* You may obtain a copy of the License at
|
|
57
|
-
*
|
|
58
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
59
|
-
*
|
|
60
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
61
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
62
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
63
|
-
* See the License for the specific language governing permissions and
|
|
64
|
-
* limitations under the License.
|
|
65
|
-
********************************************************************************/
|
|
66
|
-
// FIXME drop:
|
|
67
53
|
var utils_1 = require("./utils");
|
|
68
|
-
var
|
|
69
|
-
var errors_1 = require("
|
|
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");
|
|
54
|
+
var ledger_1 = __importDefault(require("./services/ledger"));
|
|
55
|
+
var errors_1 = require("./errors");
|
|
75
56
|
var starkQuantizationTypeMap = {
|
|
76
57
|
eth: 1,
|
|
77
58
|
erc20: 2,
|
|
@@ -79,6 +60,21 @@ var starkQuantizationTypeMap = {
|
|
|
79
60
|
erc20mintable: 4,
|
|
80
61
|
erc721mintable: 5
|
|
81
62
|
};
|
|
63
|
+
function splitPath(path) {
|
|
64
|
+
var result = [];
|
|
65
|
+
var components = path.split("/");
|
|
66
|
+
components.forEach(function (element) {
|
|
67
|
+
var number = parseInt(element, 10);
|
|
68
|
+
if (isNaN(number)) {
|
|
69
|
+
return; // FIXME shouldn't it throws instead?
|
|
70
|
+
}
|
|
71
|
+
if (element.length > 1 && element[element.length - 1] === "'") {
|
|
72
|
+
number += 0x80000000;
|
|
73
|
+
}
|
|
74
|
+
result.push(number);
|
|
75
|
+
});
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
82
78
|
function hexBuffer(str) {
|
|
83
79
|
return Buffer.from(str.startsWith("0x") ? str.slice(2) : str, "hex");
|
|
84
80
|
}
|
|
@@ -140,7 +136,7 @@ var Eth = /** @class */ (function () {
|
|
|
140
136
|
* eth.getAddress("44'/60'/0'/0/0").then(o => o.address)
|
|
141
137
|
*/
|
|
142
138
|
Eth.prototype.getAddress = function (path, boolDisplay, boolChaincode) {
|
|
143
|
-
var paths =
|
|
139
|
+
var paths = splitPath(path);
|
|
144
140
|
var buffer = Buffer.alloc(1 + paths.length * 4);
|
|
145
141
|
buffer[0] = paths.length;
|
|
146
142
|
paths.forEach(function (element, index) {
|
|
@@ -166,263 +162,222 @@ var Eth = /** @class */ (function () {
|
|
|
166
162
|
});
|
|
167
163
|
};
|
|
168
164
|
/**
|
|
169
|
-
*
|
|
170
|
-
* to associate a contract address with a ticker and number of decimals.
|
|
171
|
-
*
|
|
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.
|
|
165
|
+
* You can sign a transaction and retrieve v, r, s given the raw transaction and the BIP 32 path of the account to sign.
|
|
176
166
|
*
|
|
167
|
+
* @param path: the BIP32 path to sign the transaction on
|
|
168
|
+
* @param rawTxHex: the raw ethereum transaction in hexadecimal to sign
|
|
169
|
+
* @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.
|
|
177
170
|
* @example
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
171
|
+
import ledgerService from "@ledgerhq/hw-app-eth/lib/services/ledger"
|
|
172
|
+
const tx = "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080"; // raw tx to sign
|
|
173
|
+
const resolution = await ledgerService.resolveTransaction(tx);
|
|
174
|
+
const result = eth.signTransaction("44'/60'/0'/0/0", tx, resolution);
|
|
175
|
+
console.log(result);
|
|
182
176
|
*/
|
|
183
|
-
Eth.prototype.
|
|
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
|
|
189
|
-
* @example
|
|
190
|
-
eth.signTransaction("44'/60'/0'/0/0", "e8018504e3b292008252089428ee52a8f3d6e5d15f8b131996950d7f296c7952872bd72a2487400080").then(result => ...)
|
|
191
|
-
*/
|
|
192
|
-
Eth.prototype.signTransaction = function (path, rawTxHex) {
|
|
177
|
+
Eth.prototype.signTransaction = function (path, rawTxHex, resolution) {
|
|
193
178
|
return __awaiter(this, void 0, void 0, function () {
|
|
194
|
-
var
|
|
195
|
-
var e_1,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
switch (_b.label) {
|
|
179
|
+
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;
|
|
180
|
+
var e_1, _l, e_2, _m, e_3, _o, e_4, _p;
|
|
181
|
+
return __generator(this, function (_q) {
|
|
182
|
+
switch (_q.label) {
|
|
199
183
|
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)];
|
|
184
|
+
if (!(resolution === undefined)) return [3 /*break*/, 2];
|
|
185
|
+
console.warn("hw-app-eth: signTransaction(path, rawTxHex, resolution): " +
|
|
186
|
+
"please provide the 'resolution' parameter. " +
|
|
187
|
+
"See https://github.com/LedgerHQ/ledgerjs/blob/master/packages/hw-app-eth/README.md " +
|
|
188
|
+
"– 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)." +
|
|
189
|
+
"// Possible solution:\n" +
|
|
190
|
+
" + import ledgerService from '@ledgerhq/hw-app-eth/lib/services/ledger';\n" +
|
|
191
|
+
" + const resolution = await ledgerService.resolveTransaction(rawTxHex);");
|
|
192
|
+
return [4 /*yield*/, ledger_1["default"]
|
|
193
|
+
.resolveTransaction(rawTxHex, this.loadConfig, {
|
|
194
|
+
externalPlugins: true,
|
|
195
|
+
erc20: true
|
|
196
|
+
})["catch"](function (e) {
|
|
197
|
+
console.warn("an error occurred in resolveTransaction => fallback to blind signing: " +
|
|
198
|
+
String(e));
|
|
199
|
+
return null;
|
|
200
|
+
})];
|
|
326
201
|
case 1:
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return [4 /*yield*/, setPlugin(this.transport, nftPluginPayload)];
|
|
202
|
+
resolution = _q.sent();
|
|
203
|
+
_q.label = 2;
|
|
330
204
|
case 2:
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
case 3:
|
|
205
|
+
if (!resolution) return [3 /*break*/, 31];
|
|
206
|
+
_q.label = 3;
|
|
207
|
+
case 3:
|
|
208
|
+
_q.trys.push([3, 8, 9, 10]);
|
|
209
|
+
_a = __values(resolution.plugin), _b = _a.next();
|
|
210
|
+
_q.label = 4;
|
|
334
211
|
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)];
|
|
212
|
+
if (!!_b.done) return [3 /*break*/, 7];
|
|
213
|
+
plugin = _b.value;
|
|
214
|
+
return [4 /*yield*/, setPlugin(this.transport, plugin)];
|
|
341
215
|
case 5:
|
|
342
|
-
|
|
343
|
-
|
|
216
|
+
_q.sent();
|
|
217
|
+
_q.label = 6;
|
|
344
218
|
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;
|
|
219
|
+
_b = _a.next();
|
|
220
|
+
return [3 /*break*/, 4];
|
|
221
|
+
case 7: return [3 /*break*/, 10];
|
|
353
222
|
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)];
|
|
223
|
+
e_1_1 = _q.sent();
|
|
224
|
+
e_1 = { error: e_1_1 };
|
|
225
|
+
return [3 /*break*/, 10];
|
|
363
226
|
case 9:
|
|
364
|
-
|
|
365
|
-
|
|
227
|
+
try {
|
|
228
|
+
if (_b && !_b.done && (_l = _a["return"])) _l.call(_a);
|
|
229
|
+
}
|
|
230
|
+
finally { if (e_1) throw e_1.error; }
|
|
231
|
+
return [7 /*endfinally*/];
|
|
366
232
|
case 10:
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
233
|
+
_q.trys.push([10, 15, 16, 17]);
|
|
234
|
+
_c = __values(resolution.externalPlugin), _d = _c.next();
|
|
235
|
+
_q.label = 11;
|
|
236
|
+
case 11:
|
|
237
|
+
if (!!_d.done) return [3 /*break*/, 14];
|
|
238
|
+
_e = _d.value, payload = _e.payload, signature = _e.signature;
|
|
239
|
+
return [4 /*yield*/, setExternalPlugin(this.transport, payload, signature)];
|
|
370
240
|
case 12:
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return [3 /*break*/, 14];
|
|
241
|
+
_q.sent();
|
|
242
|
+
_q.label = 13;
|
|
374
243
|
case 13:
|
|
244
|
+
_d = _c.next();
|
|
245
|
+
return [3 /*break*/, 11];
|
|
246
|
+
case 14: return [3 /*break*/, 17];
|
|
247
|
+
case 15:
|
|
248
|
+
e_2_1 = _q.sent();
|
|
249
|
+
e_2 = { error: e_2_1 };
|
|
250
|
+
return [3 /*break*/, 17];
|
|
251
|
+
case 16:
|
|
375
252
|
try {
|
|
376
|
-
if (
|
|
253
|
+
if (_d && !_d.done && (_m = _c["return"])) _m.call(_c);
|
|
377
254
|
}
|
|
378
|
-
finally { if (
|
|
255
|
+
finally { if (e_2) throw e_2.error; }
|
|
379
256
|
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
257
|
case 17:
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
258
|
+
_q.trys.push([17, 22, 23, 24]);
|
|
259
|
+
_f = __values(resolution.nfts), _g = _f.next();
|
|
260
|
+
_q.label = 18;
|
|
261
|
+
case 18:
|
|
262
|
+
if (!!_g.done) return [3 /*break*/, 21];
|
|
263
|
+
nft = _g.value;
|
|
264
|
+
return [4 /*yield*/, provideNFTInformation(this.transport, Buffer.from(nft, "hex"))];
|
|
265
|
+
case 19:
|
|
266
|
+
_q.sent();
|
|
267
|
+
_q.label = 20;
|
|
268
|
+
case 20:
|
|
269
|
+
_g = _f.next();
|
|
270
|
+
return [3 /*break*/, 18];
|
|
271
|
+
case 21: return [3 /*break*/, 24];
|
|
272
|
+
case 22:
|
|
273
|
+
e_3_1 = _q.sent();
|
|
274
|
+
e_3 = { error: e_3_1 };
|
|
275
|
+
return [3 /*break*/, 24];
|
|
276
|
+
case 23:
|
|
277
|
+
try {
|
|
278
|
+
if (_g && !_g.done && (_o = _f["return"])) _o.call(_f);
|
|
279
|
+
}
|
|
280
|
+
finally { if (e_3) throw e_3.error; }
|
|
281
|
+
return [7 /*endfinally*/];
|
|
282
|
+
case 24:
|
|
283
|
+
_q.trys.push([24, 29, 30, 31]);
|
|
284
|
+
_h = __values(resolution.erc20Tokens), _j = _h.next();
|
|
285
|
+
_q.label = 25;
|
|
286
|
+
case 25:
|
|
287
|
+
if (!!_j.done) return [3 /*break*/, 28];
|
|
288
|
+
data = _j.value;
|
|
289
|
+
return [4 /*yield*/, provideERC20TokenInformation(this.transport, Buffer.from(data, "hex"))];
|
|
290
|
+
case 26:
|
|
291
|
+
_q.sent();
|
|
292
|
+
_q.label = 27;
|
|
293
|
+
case 27:
|
|
294
|
+
_j = _h.next();
|
|
295
|
+
return [3 /*break*/, 25];
|
|
296
|
+
case 28: return [3 /*break*/, 31];
|
|
297
|
+
case 29:
|
|
298
|
+
e_4_1 = _q.sent();
|
|
299
|
+
e_4 = { error: e_4_1 };
|
|
300
|
+
return [3 /*break*/, 31];
|
|
301
|
+
case 30:
|
|
302
|
+
try {
|
|
303
|
+
if (_j && !_j.done && (_p = _h["return"])) _p.call(_h);
|
|
304
|
+
}
|
|
305
|
+
finally { if (e_4) throw e_4.error; }
|
|
306
|
+
return [7 /*endfinally*/];
|
|
307
|
+
case 31:
|
|
308
|
+
rawTx = Buffer.from(rawTxHex, "hex");
|
|
309
|
+
_k = (0, utils_1.decodeTxInfo)(rawTx), vrsOffset = _k.vrsOffset, txType = _k.txType, chainId = _k.chainId, chainIdTruncated = _k.chainIdTruncated;
|
|
310
|
+
paths = splitPath(path);
|
|
311
|
+
offset = 0;
|
|
312
|
+
_loop_1 = function () {
|
|
313
|
+
var first, maxChunkSize, chunkSize, buffer;
|
|
314
|
+
return __generator(this, function (_r) {
|
|
315
|
+
switch (_r.label) {
|
|
316
|
+
case 0:
|
|
317
|
+
first = offset === 0;
|
|
318
|
+
maxChunkSize = first ? 150 - 1 - paths.length * 4 : 150;
|
|
319
|
+
chunkSize = offset + maxChunkSize > rawTx.length
|
|
320
|
+
? rawTx.length - offset
|
|
321
|
+
: maxChunkSize;
|
|
322
|
+
if (vrsOffset != 0 && offset + chunkSize >= vrsOffset) {
|
|
323
|
+
// Make sure that the chunk doesn't end right on the EIP 155 marker if set
|
|
324
|
+
chunkSize = rawTx.length - offset;
|
|
325
|
+
}
|
|
326
|
+
buffer = Buffer.alloc(first ? 1 + paths.length * 4 + chunkSize : chunkSize);
|
|
327
|
+
if (first) {
|
|
328
|
+
buffer[0] = paths.length;
|
|
329
|
+
paths.forEach(function (element, index) {
|
|
330
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
331
|
+
});
|
|
332
|
+
rawTx.copy(buffer, 1 + 4 * paths.length, offset, offset + chunkSize);
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
rawTx.copy(buffer, 0, offset, offset + chunkSize);
|
|
336
|
+
}
|
|
337
|
+
return [4 /*yield*/, this_1.transport
|
|
338
|
+
.send(0xe0, 0x04, first ? 0x00 : 0x80, 0x00, buffer)["catch"](function (e) {
|
|
339
|
+
throw remapTransactionRelatedErrors(e);
|
|
340
|
+
})];
|
|
341
|
+
case 1:
|
|
342
|
+
response = _r.sent();
|
|
343
|
+
offset += chunkSize;
|
|
344
|
+
return [2 /*return*/];
|
|
407
345
|
}
|
|
346
|
+
});
|
|
347
|
+
};
|
|
348
|
+
this_1 = this;
|
|
349
|
+
_q.label = 32;
|
|
350
|
+
case 32:
|
|
351
|
+
if (!(offset !== rawTx.length)) return [3 /*break*/, 34];
|
|
352
|
+
return [5 /*yield**/, _loop_1()];
|
|
353
|
+
case 33:
|
|
354
|
+
_q.sent();
|
|
355
|
+
return [3 /*break*/, 32];
|
|
356
|
+
case 34:
|
|
357
|
+
response_byte = response[0];
|
|
358
|
+
v = "";
|
|
359
|
+
if (chainId.times(2).plus(35).plus(1).isGreaterThan(255)) {
|
|
360
|
+
oneByteChainId = (chainIdTruncated * 2 + 35) % 256;
|
|
361
|
+
ecc_parity = Math.abs(response_byte - oneByteChainId);
|
|
362
|
+
if (txType != null) {
|
|
363
|
+
// For EIP2930 and EIP1559 tx, v is simply the parity.
|
|
364
|
+
v = ecc_parity % 2 == 1 ? "00" : "01";
|
|
408
365
|
}
|
|
409
366
|
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;
|
|
367
|
+
// Legacy type transaction with a big chain ID
|
|
368
|
+
v = chainId.times(2).plus(35).plus(ecc_parity).toString(16);
|
|
415
369
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
v = response_byte.toString(16);
|
|
373
|
+
}
|
|
374
|
+
// Make sure v has is prefixed with a 0 if its length is odd ("1" -> "01").
|
|
375
|
+
if (v.length % 2 == 1) {
|
|
376
|
+
v = "0" + v;
|
|
377
|
+
}
|
|
378
|
+
r = response.slice(1, 1 + 32).toString("hex");
|
|
379
|
+
s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
|
|
380
|
+
return [2 /*return*/, { v: v, r: r, s: s }];
|
|
426
381
|
}
|
|
427
382
|
});
|
|
428
383
|
});
|
|
@@ -453,50 +408,58 @@ var Eth = /** @class */ (function () {
|
|
|
453
408
|
})
|
|
454
409
|
*/
|
|
455
410
|
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
|
-
|
|
411
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
412
|
+
var paths, offset, message, response, _loop_2, this_2, v, r, s;
|
|
413
|
+
return __generator(this, function (_a) {
|
|
414
|
+
switch (_a.label) {
|
|
415
|
+
case 0:
|
|
416
|
+
paths = splitPath(path);
|
|
417
|
+
offset = 0;
|
|
418
|
+
message = Buffer.from(messageHex, "hex");
|
|
419
|
+
_loop_2 = function () {
|
|
420
|
+
var maxChunkSize, chunkSize, buffer;
|
|
421
|
+
return __generator(this, function (_b) {
|
|
422
|
+
switch (_b.label) {
|
|
423
|
+
case 0:
|
|
424
|
+
maxChunkSize = offset === 0 ? 150 - 1 - paths.length * 4 - 4 : 150;
|
|
425
|
+
chunkSize = offset + maxChunkSize > message.length
|
|
426
|
+
? message.length - offset
|
|
427
|
+
: maxChunkSize;
|
|
428
|
+
buffer = Buffer.alloc(offset === 0 ? 1 + paths.length * 4 + 4 + chunkSize : chunkSize);
|
|
429
|
+
if (offset === 0) {
|
|
430
|
+
buffer[0] = paths.length;
|
|
431
|
+
paths.forEach(function (element, index) {
|
|
432
|
+
buffer.writeUInt32BE(element, 1 + 4 * index);
|
|
433
|
+
});
|
|
434
|
+
buffer.writeUInt32BE(message.length, 1 + 4 * paths.length);
|
|
435
|
+
message.copy(buffer, 1 + 4 * paths.length + 4, offset, offset + chunkSize);
|
|
436
|
+
}
|
|
437
|
+
else {
|
|
438
|
+
message.copy(buffer, 0, offset, offset + chunkSize);
|
|
439
|
+
}
|
|
440
|
+
return [4 /*yield*/, this_2.transport.send(0xe0, 0x08, offset === 0 ? 0x00 : 0x80, 0x00, buffer)];
|
|
441
|
+
case 1:
|
|
442
|
+
response = _b.sent();
|
|
443
|
+
offset += chunkSize;
|
|
444
|
+
return [2 /*return*/];
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
};
|
|
448
|
+
this_2 = this;
|
|
449
|
+
_a.label = 1;
|
|
450
|
+
case 1:
|
|
451
|
+
if (!(offset !== message.length)) return [3 /*break*/, 3];
|
|
452
|
+
return [5 /*yield**/, _loop_2()];
|
|
453
|
+
case 2:
|
|
454
|
+
_a.sent();
|
|
455
|
+
return [3 /*break*/, 1];
|
|
456
|
+
case 3:
|
|
457
|
+
v = response[0];
|
|
458
|
+
r = response.slice(1, 1 + 32).toString("hex");
|
|
459
|
+
s = response.slice(1 + 32, 1 + 32 + 32).toString("hex");
|
|
460
|
+
return [2 /*return*/, { v: v, r: r, s: s }];
|
|
461
|
+
}
|
|
490
462
|
});
|
|
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
463
|
});
|
|
501
464
|
};
|
|
502
465
|
/**
|
|
@@ -514,7 +477,7 @@ var Eth = /** @class */ (function () {
|
|
|
514
477
|
Eth.prototype.signEIP712HashedMessage = function (path, domainSeparatorHex, hashStructMessageHex) {
|
|
515
478
|
var domainSeparator = hexBuffer(domainSeparatorHex);
|
|
516
479
|
var hashStruct = hexBuffer(hashStructMessageHex);
|
|
517
|
-
var paths =
|
|
480
|
+
var paths = splitPath(path);
|
|
518
481
|
var buffer = Buffer.alloc(1 + paths.length * 4 + 32 + 32, 0);
|
|
519
482
|
var offset = 0;
|
|
520
483
|
buffer[0] = paths.length;
|
|
@@ -545,7 +508,7 @@ var Eth = /** @class */ (function () {
|
|
|
545
508
|
* @return the Stark public key
|
|
546
509
|
*/
|
|
547
510
|
Eth.prototype.starkGetPublicKey = function (path, boolDisplay) {
|
|
548
|
-
var paths =
|
|
511
|
+
var paths = splitPath(path);
|
|
549
512
|
var buffer = Buffer.alloc(1 + paths.length * 4);
|
|
550
513
|
buffer[0] = paths.length;
|
|
551
514
|
paths.forEach(function (element, index) {
|
|
@@ -575,7 +538,7 @@ var Eth = /** @class */ (function () {
|
|
|
575
538
|
Eth.prototype.starkSignOrder = function (path, sourceTokenAddress, sourceQuantization, destinationTokenAddress, destinationQuantization, sourceVault, destinationVault, amountSell, amountBuy, nonce, timestamp) {
|
|
576
539
|
var sourceTokenAddressHex = maybeHexBuffer(sourceTokenAddress);
|
|
577
540
|
var destinationTokenAddressHex = maybeHexBuffer(destinationTokenAddress);
|
|
578
|
-
var paths =
|
|
541
|
+
var paths = splitPath(path);
|
|
579
542
|
var buffer = Buffer.alloc(1 + paths.length * 4 + 20 + 32 + 20 + 32 + 4 + 4 + 8 + 8 + 4 + 4, 0);
|
|
580
543
|
var offset = 0;
|
|
581
544
|
buffer[0] = paths.length;
|
|
@@ -647,7 +610,7 @@ var Eth = /** @class */ (function () {
|
|
|
647
610
|
throw new Error("eth.starkSignOrderv2 invalid destination quantization type=" +
|
|
648
611
|
destinationQuantizationType);
|
|
649
612
|
}
|
|
650
|
-
var paths =
|
|
613
|
+
var paths = splitPath(path);
|
|
651
614
|
var buffer = Buffer.alloc(1 +
|
|
652
615
|
paths.length * 4 +
|
|
653
616
|
1 +
|
|
@@ -736,7 +699,7 @@ var Eth = /** @class */ (function () {
|
|
|
736
699
|
Eth.prototype.starkSignTransfer = function (path, transferTokenAddress, transferQuantization, targetPublicKey, sourceVault, destinationVault, amountTransfer, nonce, timestamp) {
|
|
737
700
|
var transferTokenAddressHex = maybeHexBuffer(transferTokenAddress);
|
|
738
701
|
var targetPublicKeyHex = hexBuffer(targetPublicKey);
|
|
739
|
-
var paths =
|
|
702
|
+
var paths = splitPath(path);
|
|
740
703
|
var buffer = Buffer.alloc(1 + paths.length * 4 + 20 + 32 + 32 + 4 + 4 + 8 + 4 + 4, 0);
|
|
741
704
|
var offset = 0;
|
|
742
705
|
buffer[0] = paths.length;
|
|
@@ -797,7 +760,7 @@ var Eth = /** @class */ (function () {
|
|
|
797
760
|
throw new Error("eth.starkSignTransferv2 invalid quantization type=" +
|
|
798
761
|
transferQuantizationType);
|
|
799
762
|
}
|
|
800
|
-
var paths =
|
|
763
|
+
var paths = splitPath(path);
|
|
801
764
|
var buffer = Buffer.alloc(1 +
|
|
802
765
|
paths.length * 4 +
|
|
803
766
|
1 +
|
|
@@ -930,7 +893,7 @@ var Eth = /** @class */ (function () {
|
|
|
930
893
|
*/
|
|
931
894
|
Eth.prototype.starkUnsafeSign = function (path, hash) {
|
|
932
895
|
var hashHex = hexBuffer(hash);
|
|
933
|
-
var paths =
|
|
896
|
+
var paths = splitPath(path);
|
|
934
897
|
var buffer = Buffer.alloc(1 + paths.length * 4 + 32);
|
|
935
898
|
var offset = 0;
|
|
936
899
|
buffer[0] = paths.length;
|
|
@@ -959,7 +922,7 @@ var Eth = /** @class */ (function () {
|
|
|
959
922
|
* eth.eth2GetPublicKey("12381/3600/0/0").then(o => o.publicKey)
|
|
960
923
|
*/
|
|
961
924
|
Eth.prototype.eth2GetPublicKey = function (path, boolDisplay) {
|
|
962
|
-
var paths =
|
|
925
|
+
var paths = splitPath(path);
|
|
963
926
|
var buffer = Buffer.alloc(1 + paths.length * 4);
|
|
964
927
|
buffer[0] = paths.length;
|
|
965
928
|
paths.forEach(function (element, index) {
|
|
@@ -992,22 +955,17 @@ var Eth = /** @class */ (function () {
|
|
|
992
955
|
throw e;
|
|
993
956
|
});
|
|
994
957
|
};
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
*/
|
|
958
|
+
Eth.prototype.provideERC20TokenInformation = function (_a) {
|
|
959
|
+
var data = _a.data;
|
|
960
|
+
console.warn("hw-app-eth: eth.provideERC20TokenInformation is deprecated. signTransaction solves this for you when providing it in `resolution`.");
|
|
961
|
+
return provideERC20TokenInformation(this.transport, data);
|
|
962
|
+
};
|
|
1001
963
|
Eth.prototype.setExternalPlugin = function (pluginName, contractAddress, selector) {
|
|
964
|
+
console.warn("hw-app-eth: eth.setExternalPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
|
|
1002
965
|
return setExternalPlugin(this.transport, pluginName, selector);
|
|
1003
966
|
};
|
|
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
967
|
Eth.prototype.setPlugin = function (data) {
|
|
968
|
+
console.warn("hw-app-eth: eth.setPlugin is deprecated. signTransaction solves this for you when providing it in `resolution`.");
|
|
1011
969
|
return setPlugin(this.transport, data);
|
|
1012
970
|
};
|
|
1013
971
|
return Eth;
|
|
@@ -1031,8 +989,8 @@ function provideNFTInformation(transport, data) {
|
|
|
1031
989
|
return false;
|
|
1032
990
|
}
|
|
1033
991
|
if (e && e.statusCode === 0x6d00) {
|
|
1034
|
-
//
|
|
1035
|
-
|
|
992
|
+
// older version of ETH app => error because we don't allow blind sign when NFT is explicitly requested to be resolved.
|
|
993
|
+
throw new errors_1.EthAppNftNotSupported();
|
|
1036
994
|
}
|
|
1037
995
|
throw e;
|
|
1038
996
|
});
|