@airgap/ethereum 0.13.20 → 0.13.21-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/package.json +7 -7
  2. package/v1/clients/info/EthereumInfoClient.d.ts +7 -9
  3. package/v1/clients/info/EthereumInfoClient.js.map +1 -1
  4. package/v1/clients/info/EtherscanInfoClient.d.ts +1 -2
  5. package/v1/clients/info/EtherscanInfoClient.js +2 -0
  6. package/v1/clients/info/EtherscanInfoClient.js.map +1 -1
  7. package/v1/index.d.ts +6 -19
  8. package/v1/index.js +1 -16
  9. package/v1/index.js.map +1 -1
  10. package/v1/module/ERC20Tokens.d.ts +1 -1
  11. package/v1/module/EthereumModule.d.ts +4 -4
  12. package/v1/module/EthereumModule.js.map +1 -1
  13. package/v1/protocol/EthereumBaseProtocol.d.ts +8 -84
  14. package/v1/protocol/EthereumBaseProtocol.js +7 -777
  15. package/v1/protocol/EthereumBaseProtocol.js.map +1 -1
  16. package/v1/protocol/EthereumProtocol.d.ts +7 -6
  17. package/v1/protocol/EthereumProtocol.js +3 -3
  18. package/v1/protocol/EthereumProtocol.js.map +1 -1
  19. package/v1/protocol/erc20/ERC20Token.d.ts +10 -15
  20. package/v1/protocol/erc20/ERC20Token.js +35 -26
  21. package/v1/protocol/erc20/ERC20Token.js.map +1 -1
  22. package/v1/serializer/v3/serializer-companion.js +9 -10
  23. package/v1/serializer/v3/serializer-companion.js.map +1 -1
  24. package/v1/utils/protocol.d.ts +5 -4
  25. package/v1/utils/protocol.js.map +1 -1
  26. package/v1/clients/crypto/EthereumCryptoClient.d.ts +0 -7
  27. package/v1/clients/crypto/EthereumCryptoClient.js +0 -147
  28. package/v1/clients/crypto/EthereumCryptoClient.js.map +0 -1
  29. package/v1/clients/node/EthereumNodeClient.d.ts +0 -18
  30. package/v1/clients/node/EthereumNodeClient.js +0 -3
  31. package/v1/clients/node/EthereumNodeClient.js.map +0 -1
  32. package/v1/clients/node/HttpEthereumNodeClient.d.ts +0 -66
  33. package/v1/clients/node/HttpEthereumNodeClient.js +0 -443
  34. package/v1/clients/node/HttpEthereumNodeClient.js.map +0 -1
  35. package/v1/data/EthereumAddress.d.ts +0 -7
  36. package/v1/data/EthereumAddress.js +0 -46
  37. package/v1/data/EthereumAddress.js.map +0 -1
  38. package/v1/protocol/EthereumChainIds.d.ts +0 -1
  39. package/v1/protocol/EthereumChainIds.js +0 -340
  40. package/v1/protocol/EthereumChainIds.js.map +0 -1
  41. package/v1/protocol/erc20/ERC20Protocol.d.ts +0 -32
  42. package/v1/protocol/erc20/ERC20Protocol.js +0 -397
  43. package/v1/protocol/erc20/ERC20Protocol.js.map +0 -1
  44. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +0 -8
  45. package/v1/serializer/v3/schemas/converter/transaction-converter.js +0 -76
  46. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +0 -1
  47. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.d.ts +0 -10
  48. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js +0 -3
  49. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js.map +0 -1
  50. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.d.ts +0 -14
  51. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js +0 -3
  52. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js.map +0 -1
  53. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.d.ts +0 -3
  54. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js +0 -3
  55. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js.map +0 -1
  56. package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum-typed.json +0 -41
  57. package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum.json +0 -58
  58. package/v1/serializer/v3/schemas/generated/transaction-sign-response-ethereum.json +0 -19
  59. package/v1/serializer/v3/validators/transaction-validator.d.ts +0 -7
  60. package/v1/serializer/v3/validators/transaction-validator.js +0 -71
  61. package/v1/serializer/v3/validators/transaction-validator.js.map +0 -1
  62. package/v1/types/crypto.d.ts +0 -2
  63. package/v1/types/crypto.js +0 -3
  64. package/v1/types/crypto.js.map +0 -1
  65. package/v1/types/protocol.d.ts +0 -35
  66. package/v1/types/protocol.js +0 -3
  67. package/v1/types/protocol.js.map +0 -1
  68. package/v1/types/transaction.d.ts +0 -24
  69. package/v1/types/transaction.js +0 -3
  70. package/v1/types/transaction.js.map +0 -1
  71. package/v1/utils/EthereumUtils.d.ts +0 -16
  72. package/v1/utils/EthereumUtils.js +0 -155
  73. package/v1/utils/EthereumUtils.js.map +0 -1
  74. package/v1/utils/key.d.ts +0 -5
  75. package/v1/utils/key.js +0 -101
  76. package/v1/utils/key.js.map +0 -1
@@ -25,29 +25,6 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
- if (k2 === undefined) k2 = k;
30
- var desc = Object.getOwnPropertyDescriptor(m, k);
31
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
- desc = { enumerable: true, get: function() { return m[k]; } };
33
- }
34
- Object.defineProperty(o, k2, desc);
35
- }) : (function(o, m, k, k2) {
36
- if (k2 === undefined) k2 = k;
37
- o[k2] = m[k];
38
- }));
39
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
- Object.defineProperty(o, "default", { enumerable: true, value: v });
41
- }) : function(o, v) {
42
- o["default"] = v;
43
- });
44
- var __importStar = (this && this.__importStar) || function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
- __setModuleDefault(result, mod);
49
- return result;
50
- };
51
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -84,29 +61,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
84
61
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
62
  }
86
63
  };
87
- var __importDefault = (this && this.__importDefault) || function (mod) {
88
- return (mod && mod.__esModule) ? mod : { "default": mod };
89
- };
90
64
  Object.defineProperty(exports, "__esModule", { value: true });
91
- exports.DefaultEthereumBaseProtocolImpl = exports.EthereumBaseProtocolImpl = exports.DEFAULT_ETHEREUM_UNITS_METADATA = void 0;
65
+ exports.EthereumBaseProtocolImpl = exports.DEFAULT_ETHEREUM_UNITS_METADATA = void 0;
92
66
  // tslint:disable: max-classes-per-file
93
67
  var coinlib_core_1 = require("@airgap/coinlib-core");
94
- var bignumber_1 = require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber");
95
- // @ts-ignore
96
- var BitGo = __importStar(require("@airgap/coinlib-core/dependencies/src/bitgo-utxo-lib-5d91049fd7a988382df81c8260e244ee56d57aac/src"));
97
- var errors_1 = require("@airgap/coinlib-core/errors");
98
- var hex_1 = require("@airgap/coinlib-core/utils/hex");
99
- var crypto_1 = require("@airgap/crypto");
100
68
  var module_kit_1 = require("@airgap/module-kit");
101
- var common_1 = __importDefault(require("@ethereumjs/common"));
102
- // TODO: ETH TX and ethereumjs-util-5.2.0 removed
103
- var tx_1 = require("@ethereumjs/tx");
104
- var EthereumCryptoClient_1 = require("../clients/crypto/EthereumCryptoClient");
105
- var EthereumAddress_1 = require("../data/EthereumAddress");
106
- var EthereumUtils_1 = require("../utils/EthereumUtils");
107
- var key_1 = require("../utils/key");
108
- var EthereumChainIds_1 = require("./EthereumChainIds");
109
- // Implementation
69
+ var evm_1 = require("@airgap/evm");
110
70
  exports.DEFAULT_ETHEREUM_UNITS_METADATA = {
111
71
  ETH: {
112
72
  symbol: { value: 'ETH', market: 'eth' },
@@ -121,436 +81,11 @@ exports.DEFAULT_ETHEREUM_UNITS_METADATA = {
121
81
  decimals: 0
122
82
  }
123
83
  };
124
- var MAX_GAS_ESTIMATE = 300000;
125
- var WALLET_CONNECT_NAMESPACE = 'eip155';
126
- var EthereumBaseProtocolImpl = /** @class */ (function () {
84
+ var EthereumBaseProtocolImpl = /** @class */ (function (_super) {
85
+ __extends(EthereumBaseProtocolImpl, _super);
127
86
  function EthereumBaseProtocolImpl(nodeClient, infoClient, options) {
128
- var _a, _b;
129
- this.bitcoinJS = {
130
- lib: BitGo,
131
- config: { network: BitGo.networks.bitcoin }
132
- };
133
- this.feeUnits = exports.DEFAULT_ETHEREUM_UNITS_METADATA;
134
- // Offline
135
- this.cryptoConfiguration = {
136
- algorithm: 'secp256k1'
137
- };
138
- this.options = options;
139
- this.nodeClient = nodeClient;
140
- this.infoClient = infoClient;
141
- this.cryptoClient = new EthereumCryptoClient_1.EthereumCryptoClient();
142
- this.units = options.units;
143
- this.feeDefaults = (_a = options.feeDefaults) !== null && _a !== void 0 ? _a : {
144
- low: (0, module_kit_1.newAmount)(0.00021 /* 21000 GAS * 10 GWEI */, 'ETH').blockchain(this.feeUnits),
145
- medium: (0, module_kit_1.newAmount)(0.000315 /* 21000 GAS * 15 GWEI */, 'ETH').blockchain(this.feeUnits),
146
- high: (0, module_kit_1.newAmount)(0.00084 /* 21000 GAS * 40 GWEI */, 'ETH').blockchain(this.feeUnits)
147
- };
148
- this.metadata = {
149
- identifier: options.identifier,
150
- name: options.name,
151
- units: options.units,
152
- mainUnit: options.mainUnit,
153
- fee: {
154
- defaults: this.feeDefaults,
155
- units: this.feeUnits,
156
- mainUnit: 'ETH'
157
- },
158
- account: {
159
- standardDerivationPath: (_b = options.standardDerivationPath) !== null && _b !== void 0 ? _b : "m/44'/60'/0'",
160
- address: {
161
- isCaseSensitive: false,
162
- placeholder: '0xabc...',
163
- regex: '^0x[a-fA-F0-9]{40}$'
164
- }
165
- },
166
- transaction: {
167
- arbitraryData: {
168
- inner: { name: 'data' }
169
- }
170
- }
171
- };
87
+ return _super.call(this, nodeClient, infoClient, __assign(__assign({}, options), { identifier: coinlib_core_1.MainProtocolSymbols.ETH, name: 'Ethereum', units: exports.DEFAULT_ETHEREUM_UNITS_METADATA, mainUnit: 'ETH', feeUnits: exports.DEFAULT_ETHEREUM_UNITS_METADATA, mainFeeUnit: 'ETH' })) || this;
172
88
  }
173
- EthereumBaseProtocolImpl.prototype.getMetadata = function () {
174
- return __awaiter(this, void 0, void 0, function () {
175
- return __generator(this, function (_a) {
176
- return [2 /*return*/, this.metadata];
177
- });
178
- });
179
- };
180
- EthereumBaseProtocolImpl.prototype.getAddressFromPublicKey = function (publicKey) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- return __generator(this, function (_a) {
183
- return [2 /*return*/, EthereumAddress_1.EthereumAddress.from(this.nonExtendedPublicKey(publicKey)).asString()];
184
- });
185
- });
186
- };
187
- EthereumBaseProtocolImpl.prototype.deriveFromExtendedPublicKey = function (extendedPublicKey, visibilityIndex, addressIndex) {
188
- return __awaiter(this, void 0, void 0, function () {
189
- return __generator(this, function (_a) {
190
- return [2 /*return*/, this.getPublicKeyFromExtendedPublicKey(extendedPublicKey, visibilityIndex, addressIndex)];
191
- });
192
- });
193
- };
194
- EthereumBaseProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
195
- return __awaiter(this, void 0, void 0, function () {
196
- return __generator(this, function (_a) {
197
- return [2 /*return*/, publicKey.type === 'pub'
198
- ? this.getDetailsFromTransactionWithPublicKey(transaction, publicKey)
199
- : this.getDetailsFromTransactionWithExtendedPublicKey(transaction, publicKey)];
200
- });
201
- });
202
- };
203
- EthereumBaseProtocolImpl.prototype.getDetailsFromTransactionWithPublicKey = function (transaction, publicKey) {
204
- return __awaiter(this, void 0, void 0, function () {
205
- var _a, ownAddress;
206
- return __generator(this, function (_b) {
207
- switch (_b.label) {
208
- case 0:
209
- _a = transaction.type;
210
- switch (_a) {
211
- case 'signed': return [3 /*break*/, 1];
212
- case 'unsigned': return [3 /*break*/, 2];
213
- }
214
- return [3 /*break*/, 4];
215
- case 1: return [2 /*return*/, this.getDetailsFromSignedTransaction(transaction)];
216
- case 2: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
217
- case 3:
218
- ownAddress = _b.sent();
219
- if (transaction.ethereumType === 'typed') {
220
- return [2 /*return*/, this.getDetailsFromTypedUnsignedTransaction(transaction, ownAddress)];
221
- }
222
- else {
223
- return [2 /*return*/, this.getDetailsFromRawUnsignedTransaction(transaction, ownAddress)];
224
- }
225
- _b.label = 4;
226
- case 4:
227
- (0, coinlib_core_1.assertNever)(transaction);
228
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unsupported transaction type.');
229
- }
230
- });
231
- });
232
- };
233
- EthereumBaseProtocolImpl.prototype.getDetailsFromTransactionWithExtendedPublicKey = function (transaction, extendedPublicKey) {
234
- return __awaiter(this, void 0, void 0, function () {
235
- var _a, dps, derivedPublicKey, ownAddress, derivedPublicKey, ownAddress;
236
- return __generator(this, function (_b) {
237
- switch (_b.label) {
238
- case 0:
239
- _a = transaction.type;
240
- switch (_a) {
241
- case 'signed': return [3 /*break*/, 1];
242
- case 'unsigned': return [3 /*break*/, 2];
243
- }
244
- return [3 /*break*/, 6];
245
- case 1: return [2 /*return*/, this.getDetailsFromSignedTransaction(transaction)];
246
- case 2:
247
- if (!(transaction.ethereumType === 'typed')) return [3 /*break*/, 4];
248
- dps = transaction.derivationPath.split('/');
249
- derivedPublicKey = this.getPublicKeyFromExtendedPublicKey(extendedPublicKey, Number(dps[dps.length - 2]), Number(dps[dps.length - 1]));
250
- return [4 /*yield*/, this.getAddressFromPublicKey(derivedPublicKey)];
251
- case 3:
252
- ownAddress = _b.sent();
253
- return [2 /*return*/, this.getDetailsFromTypedUnsignedTransaction(transaction, ownAddress)];
254
- case 4:
255
- derivedPublicKey = this.getPublicKeyFromExtendedPublicKey(extendedPublicKey, 0, 0);
256
- return [4 /*yield*/, this.getAddressFromPublicKey(derivedPublicKey)];
257
- case 5:
258
- ownAddress = _b.sent();
259
- return [2 /*return*/, this.getDetailsFromRawUnsignedTransaction(transaction, ownAddress)];
260
- case 6:
261
- (0, coinlib_core_1.assertNever)(transaction);
262
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unsupported transaction type.');
263
- }
264
- });
265
- });
266
- };
267
- EthereumBaseProtocolImpl.prototype.getDetailsFromSignedTransaction = function (transaction) {
268
- var _a, _b;
269
- return __awaiter(this, void 0, void 0, function () {
270
- var ethTx, tx, hexValue, hexGasPrice, hexGasLimit, hexNonce, chainId, to, feeTx;
271
- return __generator(this, function (_c) {
272
- ethTx = tx_1.TransactionFactory.fromSerializedData(Buffer.from(transaction.serialized, 'hex'));
273
- if (ethTx.type === 0) {
274
- tx = ethTx;
275
- hexValue = tx.value.toString('hex') || '0x0';
276
- hexGasPrice = tx.gasPrice.toString('hex') || '0x0';
277
- hexGasLimit = tx.gasLimit.toString('hex') || '0x0';
278
- hexNonce = tx.nonce.toString('hex') || '0x0';
279
- chainId = tx.common.chainIdBN().toString(10);
280
- to = tx.to;
281
- if (!to) {
282
- throw new Error('No "TO" address');
283
- }
284
- return [2 /*return*/, [
285
- {
286
- from: [tx.getSenderAddress().toString()],
287
- to: [to.toString()],
288
- isInbound: tx.toCreationAddress(),
289
- amount: (0, module_kit_1.newAmount)(parseInt(hexValue, 16), 'blockchain'),
290
- fee: (0, module_kit_1.newAmount)(new bignumber_1.BigNumber(parseInt(hexGasLimit, 16)).multipliedBy(parseInt(hexGasPrice, 16)), 'blockchain'),
291
- network: this.options.network,
292
- status: {
293
- type: 'unknown',
294
- hash: "0x".concat(tx.hash().toString('hex'))
295
- },
296
- arbitraryData: "0x".concat(tx.data.toString('hex')),
297
- extra: {
298
- chainId: chainId,
299
- nonce: parseInt(hexNonce, 16)
300
- }
301
- }
302
- ]];
303
- }
304
- try {
305
- feeTx = ethTx;
306
- return [2 /*return*/, [
307
- {
308
- from: [feeTx.getSenderAddress().toString()],
309
- to: [(_b = (_a = feeTx.to) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''],
310
- isInbound: false,
311
- amount: (0, module_kit_1.newAmount)(feeTx.value.toString(10), 'blockchain'),
312
- fee: (0, module_kit_1.newAmount)(new bignumber_1.BigNumber(feeTx.gasLimit.toString(10)).multipliedBy(feeTx.maxFeePerGas.toString(10)), 'blockchain'),
313
- network: this.options.network,
314
- arbitraryData: feeTx.data.toString('hex'),
315
- extra: {
316
- chainId: feeTx.chainId.toNumber(),
317
- nonce: feeTx.nonce.toNumber()
318
- }
319
- }
320
- ]];
321
- }
322
- catch (e) {
323
- throw new Error("Transaction type \"".concat(ethTx.type, "\" not supported"));
324
- }
325
- return [2 /*return*/];
326
- });
327
- });
328
- };
329
- EthereumBaseProtocolImpl.prototype.getDetailsFromTypedUnsignedTransaction = function (transaction, ownAddress) {
330
- var _a, _b, _c;
331
- return __awaiter(this, void 0, void 0, function () {
332
- var typedTransaction, airGapTransaction;
333
- return __generator(this, function (_d) {
334
- typedTransaction = tx_1.TransactionFactory.fromSerializedData(Buffer.from(transaction.serialized, 'hex'));
335
- airGapTransaction = {
336
- from: [ownAddress],
337
- to: [(_b = (_a = typedTransaction.to) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''],
338
- isInbound: false,
339
- amount: (0, module_kit_1.newAmount)(typedTransaction.value.toString(10), 'blockchain'),
340
- fee: (0, module_kit_1.newAmount)(new bignumber_1.BigNumber(typedTransaction.gasLimit.toString(10)).multipliedBy(typedTransaction.maxFeePerGas.toString(10)), 'blockchain'),
341
- network: this.options.network,
342
- arbitraryData: typedTransaction.data.toString('hex'),
343
- uiAlerts: typedTransaction.chainId.toNumber() !== 1
344
- ? [
345
- (0, module_kit_1.newWarningUIAlert)({
346
- title: (0, module_kit_1.newPlainUIText)('Chain ID'),
347
- description: (0, module_kit_1.newPlainUIText)("Please note that this is not an Ethereum Mainnet transaction, it is from ".concat((_c = EthereumChainIds_1.ETHEREUM_CHAIN_IDS[typedTransaction.chainId.toNumber()]) !== null && _c !== void 0 ? _c : "Chain ID ".concat(typedTransaction.chainId.toNumber())))
348
- })
349
- ]
350
- : undefined
351
- };
352
- return [2 /*return*/, [airGapTransaction]];
353
- });
354
- });
355
- };
356
- EthereumBaseProtocolImpl.prototype.getDetailsFromRawUnsignedTransaction = function (transaction, ownAddress) {
357
- return __awaiter(this, void 0, void 0, function () {
358
- return __generator(this, function (_a) {
359
- return [2 /*return*/, [
360
- {
361
- from: [ownAddress],
362
- to: [transaction.to],
363
- isInbound: false,
364
- amount: (0, module_kit_1.newAmount)(transaction.value, 'blockchain'),
365
- fee: (0, module_kit_1.newAmount)(new bignumber_1.BigNumber(transaction.gasLimit).multipliedBy(transaction.gasPrice), 'blockchain'),
366
- network: this.options.network,
367
- arbitraryData: transaction.data
368
- }
369
- ]];
370
- });
371
- });
372
- };
373
- EthereumBaseProtocolImpl.prototype.verifyMessageWithPublicKey = function (message, signature, publicKey) {
374
- return __awaiter(this, void 0, void 0, function () {
375
- var hexSignature, hexPublicKey;
376
- return __generator(this, function (_a) {
377
- hexSignature = signature;
378
- hexPublicKey = (0, key_1.convertPublicKey)(this.nonExtendedPublicKey(publicKey), 'hex');
379
- return [2 /*return*/, this.cryptoClient.verifyMessage(message, hexSignature.value, hexPublicKey.value)];
380
- });
381
- });
382
- };
383
- EthereumBaseProtocolImpl.prototype.encryptAsymmetricWithPublicKey = function (payload, publicKey) {
384
- return __awaiter(this, void 0, void 0, function () {
385
- var hexPublicKey;
386
- return __generator(this, function (_a) {
387
- hexPublicKey = (0, key_1.convertPublicKey)(this.nonExtendedPublicKey(publicKey), 'hex');
388
- return [2 /*return*/, this.cryptoClient.encryptAsymmetric(payload, hexPublicKey.value)];
389
- });
390
- });
391
- };
392
- EthereumBaseProtocolImpl.prototype.getCryptoConfiguration = function () {
393
- return __awaiter(this, void 0, void 0, function () {
394
- return __generator(this, function (_a) {
395
- return [2 /*return*/, this.cryptoConfiguration];
396
- });
397
- });
398
- };
399
- EthereumBaseProtocolImpl.prototype.getKeyPairFromDerivative = function (derivative) {
400
- return __awaiter(this, void 0, void 0, function () {
401
- var node;
402
- return __generator(this, function (_a) {
403
- node = this.derivativeToBip32Node(derivative);
404
- return [2 /*return*/, {
405
- secretKey: (0, module_kit_1.newSecretKey)(node.keyPair.getPrivateKeyBuffer().toString('hex'), 'hex'),
406
- publicKey: (0, module_kit_1.newPublicKey)(node.neutered().keyPair.getPublicKeyBuffer().toString('hex'), 'hex')
407
- }];
408
- });
409
- });
410
- };
411
- EthereumBaseProtocolImpl.prototype.getExtendedKeyPairFromDerivative = function (derivative) {
412
- return __awaiter(this, void 0, void 0, function () {
413
- var node;
414
- return __generator(this, function (_a) {
415
- node = this.derivativeToBip32Node(derivative);
416
- return [2 /*return*/, {
417
- secretKey: (0, module_kit_1.newExtendedSecretKey)(node.toBase58(), 'encoded'),
418
- publicKey: (0, module_kit_1.newExtendedPublicKey)(node.neutered().toBase58(), 'encoded')
419
- }];
420
- });
421
- });
422
- };
423
- EthereumBaseProtocolImpl.prototype.deriveFromExtendedSecretKey = function (extendedSecretKey, visibilityIndex, addressIndex) {
424
- return __awaiter(this, void 0, void 0, function () {
425
- return __generator(this, function (_a) {
426
- return [2 /*return*/, this.getSecretKeyFromExtendedSecretKey(extendedSecretKey, visibilityIndex, addressIndex)];
427
- });
428
- });
429
- };
430
- EthereumBaseProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
431
- return __awaiter(this, void 0, void 0, function () {
432
- return __generator(this, function (_a) {
433
- return [2 /*return*/, transaction.ethereumType === 'typed'
434
- ? this.signTypedUnsignedTransactionWithSecretKey(transaction, this.nonExtendedSecretKey(secretKey))
435
- : this.signRawUnsignedTransactionWithSecretKey(transaction, this.nonExtendedSecretKey(secretKey))];
436
- });
437
- });
438
- };
439
- EthereumBaseProtocolImpl.prototype.signTypedUnsignedTransactionWithSecretKey = function (transaction, secretKey) {
440
- return __awaiter(this, void 0, void 0, function () {
441
- var typedTransaction;
442
- return __generator(this, function (_a) {
443
- typedTransaction = tx_1.TransactionFactory.fromSerializedData(Buffer.from(transaction.serialized, 'hex'));
444
- return [2 /*return*/, this.signTypedTransactionWithSecretKey(typedTransaction, secretKey)];
445
- });
446
- });
447
- };
448
- EthereumBaseProtocolImpl.prototype.signRawUnsignedTransactionWithSecretKey = function (transaction, secretKey) {
449
- return __awaiter(this, void 0, void 0, function () {
450
- var txData, common, typedTransaction;
451
- return __generator(this, function (_a) {
452
- txData = {
453
- nonce: transaction.nonce,
454
- gasPrice: transaction.gasPrice,
455
- gasLimit: transaction.gasLimit,
456
- to: transaction.to,
457
- value: transaction.value.startsWith('0x') ? transaction.value : EthereumUtils_1.EthereumUtils.toHex(parseInt(transaction.value, 10)),
458
- data: transaction.data
459
- };
460
- try {
461
- common = new common_1.default({ chain: transaction.chainId });
462
- }
463
- catch (_b) {
464
- common = common_1.default.custom({ chainId: transaction.chainId });
465
- }
466
- typedTransaction = tx_1.TransactionFactory.fromTxData(txData, { common: common });
467
- return [2 /*return*/, this.signTypedTransactionWithSecretKey(typedTransaction, secretKey)];
468
- });
469
- });
470
- };
471
- EthereumBaseProtocolImpl.prototype.signTypedTransactionWithSecretKey = function (transaction, secretKey) {
472
- return __awaiter(this, void 0, void 0, function () {
473
- var hexSecretKey, signedTransaction;
474
- return __generator(this, function (_a) {
475
- hexSecretKey = (0, key_1.convertSecretKey)(secretKey, 'hex');
476
- signedTransaction = transaction.sign(Buffer.from(hexSecretKey.value, 'hex'));
477
- return [2 /*return*/, (0, module_kit_1.newSignedTransaction)({
478
- serialized: signedTransaction.serialize().toString('hex')
479
- })];
480
- });
481
- });
482
- };
483
- EthereumBaseProtocolImpl.prototype.signMessageWithKeyPair = function (message, keyPair) {
484
- return __awaiter(this, void 0, void 0, function () {
485
- var hexSecretKey, signature;
486
- return __generator(this, function (_a) {
487
- switch (_a.label) {
488
- case 0:
489
- hexSecretKey = (0, key_1.convertSecretKey)(this.nonExtendedSecretKey(keyPair.secretKey), 'hex');
490
- return [4 /*yield*/, this.cryptoClient.signMessage(message, { privateKey: hexSecretKey.value })];
491
- case 1:
492
- signature = _a.sent();
493
- return [2 /*return*/, (0, module_kit_1.newSignature)(signature, 'hex')];
494
- }
495
- });
496
- });
497
- };
498
- EthereumBaseProtocolImpl.prototype.decryptAsymmetricWithKeyPair = function (payload, keyPair) {
499
- return __awaiter(this, void 0, void 0, function () {
500
- var hexSecretKey, hexPublicKey;
501
- return __generator(this, function (_a) {
502
- hexSecretKey = (0, key_1.convertSecretKey)(this.nonExtendedSecretKey(keyPair.secretKey), 'hex');
503
- hexPublicKey = (0, key_1.convertPublicKey)(this.nonExtendedPublicKey(keyPair.publicKey), 'hex');
504
- return [2 /*return*/, this.cryptoClient.decryptAsymmetric(payload, { privateKey: hexSecretKey.value, publicKey: hexPublicKey.value })];
505
- });
506
- });
507
- };
508
- EthereumBaseProtocolImpl.prototype.encryptAESWithSecretKey = function (payload, secretKey) {
509
- return __awaiter(this, void 0, void 0, function () {
510
- var hexSecretKey;
511
- return __generator(this, function (_a) {
512
- hexSecretKey = (0, key_1.convertSecretKey)(this.nonExtendedSecretKey(secretKey), 'hex');
513
- return [2 /*return*/, this.cryptoClient.encryptAES(payload, hexSecretKey.value)];
514
- });
515
- });
516
- };
517
- EthereumBaseProtocolImpl.prototype.decryptAESWithSecretKey = function (payload, secretKey) {
518
- return __awaiter(this, void 0, void 0, function () {
519
- var hexSecretKey;
520
- return __generator(this, function (_a) {
521
- hexSecretKey = (0, key_1.convertSecretKey)(this.nonExtendedSecretKey(secretKey), 'hex');
522
- return [2 /*return*/, this.cryptoClient.decryptAES(payload, hexSecretKey.value)];
523
- });
524
- });
525
- };
526
- // Online
527
- EthereumBaseProtocolImpl.prototype.getNetwork = function () {
528
- return __awaiter(this, void 0, void 0, function () {
529
- return __generator(this, function (_a) {
530
- return [2 /*return*/, this.options.network];
531
- });
532
- });
533
- };
534
- EthereumBaseProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
535
- return __awaiter(this, void 0, void 0, function () {
536
- var address;
537
- return __generator(this, function (_a) {
538
- switch (_a.label) {
539
- case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
540
- case 1:
541
- address = _a.sent();
542
- return [2 /*return*/, this.getTransactionsForAddress(address, limit, cursor)];
543
- }
544
- });
545
- });
546
- };
547
- EthereumBaseProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
548
- return __awaiter(this, void 0, void 0, function () {
549
- return __generator(this, function (_a) {
550
- return [2 /*return*/, this.getTransactionsForAddresses([address], limit, cursor)];
551
- });
552
- });
553
- };
554
89
  EthereumBaseProtocolImpl.prototype.getTransactionsForAddresses = function (addresses, limit, cursor) {
555
90
  return __awaiter(this, void 0, void 0, function () {
556
91
  var _this = this;
@@ -563,7 +98,7 @@ var EthereumBaseProtocolImpl = /** @class */ (function () {
563
98
  }
564
99
  Promise.all(promises)
565
100
  .then(function (values) {
566
- var page = Math.max.apply(Math, values.map(function (txResult) { return txResult.cursor.page; }));
101
+ var page = Math.max.apply(Math, values.map(function (txResult) { var _a; return (_a = txResult.cursor.page) !== null && _a !== void 0 ? _a : 0; }));
567
102
  var transactions = values.reduce(function (acc, current) {
568
103
  return acc.concat(current.transactions.map(function (tx) { return (__assign(__assign({}, tx), { amount: (0, module_kit_1.newAmount)(tx.amount.value, 'blockchain'), fee: (0, module_kit_1.newAmount)(tx.fee.value, 'blockchain'), network: _this.options.network })); }));
569
104
  }, []);
@@ -581,312 +116,7 @@ var EthereumBaseProtocolImpl = /** @class */ (function () {
581
116
  });
582
117
  });
583
118
  };
584
- EthereumBaseProtocolImpl.prototype.getTransactionStatus = function (transactionIds) {
585
- return __awaiter(this, void 0, void 0, function () {
586
- var statuses;
587
- var _this = this;
588
- return __generator(this, function (_a) {
589
- switch (_a.label) {
590
- case 0: return [4 /*yield*/, Promise.all(transactionIds.map(function (txHash) { return __awaiter(_this, void 0, void 0, function () {
591
- var _a;
592
- return __generator(this, function (_b) {
593
- switch (_b.label) {
594
- case 0:
595
- _a = [txHash];
596
- return [4 /*yield*/, this.nodeClient.getTransactionStatus(txHash)];
597
- case 1: return [2 /*return*/, _a.concat([_b.sent()])];
598
- }
599
- });
600
- }); }))];
601
- case 1:
602
- statuses = _a.sent();
603
- return [2 /*return*/, statuses.reduce(function (obj, next) {
604
- var _a;
605
- return Object.assign(obj, (_a = {}, _a[next[0]] = next[1], _a));
606
- }, {})];
607
- }
608
- });
609
- });
610
- };
611
- EthereumBaseProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
612
- return __awaiter(this, void 0, void 0, function () {
613
- var address;
614
- return __generator(this, function (_a) {
615
- switch (_a.label) {
616
- case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
617
- case 1:
618
- address = _a.sent();
619
- return [2 /*return*/, this.getBalanceOfAddress(address)];
620
- }
621
- });
622
- });
623
- };
624
- EthereumBaseProtocolImpl.prototype.getBalanceOfAddress = function (address) {
625
- return __awaiter(this, void 0, void 0, function () {
626
- return __generator(this, function (_a) {
627
- return [2 /*return*/, this.getBalanceOfAddresses([address])];
628
- });
629
- });
630
- };
631
- EthereumBaseProtocolImpl.prototype.getBalanceOfAddresses = function (addresses) {
632
- return __awaiter(this, void 0, void 0, function () {
633
- var balances;
634
- var _this = this;
635
- return __generator(this, function (_a) {
636
- switch (_a.label) {
637
- case 0: return [4 /*yield*/, Promise.all(addresses.map(function (address) {
638
- return _this.nodeClient.fetchBalance(address);
639
- }))];
640
- case 1:
641
- balances = _a.sent();
642
- return [2 /*return*/, {
643
- total: (0, module_kit_1.newAmount)(balances.reduce(function (a, b) { return a.plus(b); }), 'blockchain')
644
- }];
645
- }
646
- });
647
- });
648
- };
649
- EthereumBaseProtocolImpl.prototype.getTokenBalancesOfPublicKey = function (publicKey, tokens) {
650
- return __awaiter(this, void 0, void 0, function () {
651
- var address, contractAddresses, balances;
652
- return __generator(this, function (_a) {
653
- switch (_a.label) {
654
- case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
655
- case 1:
656
- address = _a.sent();
657
- contractAddresses = tokens.map(function (token) { return token.contractAddress; });
658
- return [4 /*yield*/, this.nodeClient.callBalanceOfOnContracts(contractAddresses, address)];
659
- case 2:
660
- balances = _a.sent();
661
- return [2 /*return*/, tokens.reduce(function (obj, next) {
662
- var _a;
663
- var balance = balances[next.contractAddress];
664
- if (balance === undefined) {
665
- return obj;
666
- }
667
- return Object.assign(obj, (_a = {}, _a[next.identifier] = (0, module_kit_1.newAmount)(balance, 'blockchain'), _a));
668
- }, {})];
669
- }
670
- });
671
- });
672
- };
673
- EthereumBaseProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
674
- return __awaiter(this, void 0, void 0, function () {
675
- var _a, total, transferable, balance, fee, estimatedFee, amountWithoutFees;
676
- return __generator(this, function (_b) {
677
- switch (_b.label) {
678
- case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
679
- case 1:
680
- _a = _b.sent(), total = _a.total, transferable = _a.transferable;
681
- balance = new bignumber_1.BigNumber((0, module_kit_1.newAmount)(transferable !== null && transferable !== void 0 ? transferable : total).blockchain(this.units).value);
682
- if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 2];
683
- fee = configuration.fee;
684
- return [3 /*break*/, 4];
685
- case 2: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, to.map(function (recipient) { return ({
686
- to: recipient,
687
- amount: (0, module_kit_1.newAmount)(balance.div(to.length).decimalPlaces(0, bignumber_1.BigNumber.ROUND_CEIL), 'blockchain')
688
- }); }))];
689
- case 3:
690
- estimatedFee = _b.sent();
691
- fee = (0, module_kit_1.newAmount)(estimatedFee.medium).blockchain(this.feeUnits);
692
- if (balance.lte(fee.value)) {
693
- fee = (0, module_kit_1.newAmount)(0, 'blockchain');
694
- }
695
- _b.label = 4;
696
- case 4:
697
- amountWithoutFees = balance.minus(fee.value);
698
- if (amountWithoutFees.isNegative()) {
699
- amountWithoutFees = new bignumber_1.BigNumber(0);
700
- }
701
- return [2 /*return*/, (0, module_kit_1.newAmount)(amountWithoutFees, 'blockchain')];
702
- }
703
- });
704
- });
705
- };
706
- EthereumBaseProtocolImpl.prototype.getTransactionFeeWithPublicKey = function (publicKey, details, configuration) {
707
- return __awaiter(this, void 0, void 0, function () {
708
- var address, estimatedGas, gasPrice, feeStepFactor, estimatedFee, lowFee, mediumFee, highFee;
709
- return __generator(this, function (_a) {
710
- switch (_a.label) {
711
- case 0:
712
- if (details.length !== 1) {
713
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ETHEREUM, 'you cannot have 0 transaction details');
714
- }
715
- return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
716
- case 1:
717
- address = _a.sent();
718
- return [4 /*yield*/, this.estimateGas(address, details[0].to, (0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units))];
719
- case 2:
720
- estimatedGas = _a.sent();
721
- return [4 /*yield*/, this.nodeClient.getGasPrice()];
722
- case 3:
723
- gasPrice = _a.sent();
724
- feeStepFactor = new bignumber_1.BigNumber(0.5);
725
- estimatedFee = estimatedGas.times(gasPrice);
726
- lowFee = estimatedFee.minus(estimatedFee.times(feeStepFactor).integerValue(bignumber_1.BigNumber.ROUND_FLOOR));
727
- mediumFee = estimatedFee;
728
- highFee = mediumFee.plus(mediumFee.times(feeStepFactor).integerValue(bignumber_1.BigNumber.ROUND_FLOOR));
729
- return [2 /*return*/, {
730
- low: (0, module_kit_1.newAmount)(lowFee, 'blockchain'),
731
- medium: (0, module_kit_1.newAmount)(mediumFee, 'blockchain'),
732
- high: (0, module_kit_1.newAmount)(highFee, 'blockchain')
733
- }];
734
- }
735
- });
736
- });
737
- };
738
- EthereumBaseProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
739
- var _a;
740
- return __awaiter(this, void 0, void 0, function () {
741
- var fee, estimatedFee, wrappedFee, wrappedAmount, address, hexAmount, balance, availableBalance, gasLimit, gasPrice, txCount, transaction;
742
- return __generator(this, function (_b) {
743
- switch (_b.label) {
744
- case 0:
745
- if (details.length !== 1) {
746
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ETHEREUM, 'you cannot have 0 transaction details');
747
- }
748
- if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 1];
749
- fee = configuration.fee;
750
- return [3 /*break*/, 3];
751
- case 1: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, details)];
752
- case 2:
753
- estimatedFee = _b.sent();
754
- fee = estimatedFee.medium;
755
- _b.label = 3;
756
- case 3:
757
- wrappedFee = new bignumber_1.BigNumber((0, module_kit_1.newAmount)(fee).blockchain(this.feeUnits).value);
758
- wrappedAmount = new bignumber_1.BigNumber((0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units).value);
759
- return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
760
- case 4:
761
- address = _b.sent();
762
- hexAmount = EthereumUtils_1.EthereumUtils.toHex(wrappedAmount.toFixed());
763
- return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
764
- case 5:
765
- balance = _b.sent();
766
- availableBalance = (0, module_kit_1.newAmount)((_a = balance.transferable) !== null && _a !== void 0 ? _a : balance.total).blockchain(this.units);
767
- return [4 /*yield*/, this.estimateGas(address, details[0].to, hexAmount)];
768
- case 6:
769
- gasLimit = _b.sent();
770
- gasPrice = wrappedFee.div(gasLimit).integerValue(bignumber_1.BigNumber.ROUND_CEIL);
771
- if (!new bignumber_1.BigNumber(availableBalance.value).gte(wrappedAmount.plus(wrappedFee))) return [3 /*break*/, 8];
772
- return [4 /*yield*/, this.nodeClient.fetchTransactionCount(address)];
773
- case 7:
774
- txCount = _b.sent();
775
- transaction = (0, module_kit_1.newUnsignedTransaction)({
776
- ethereumType: 'raw',
777
- nonce: EthereumUtils_1.EthereumUtils.toHex(txCount),
778
- gasLimit: EthereumUtils_1.EthereumUtils.toHex(gasLimit.toFixed()),
779
- gasPrice: EthereumUtils_1.EthereumUtils.toHex(gasPrice.toFixed()),
780
- to: details[0].to,
781
- value: hexAmount,
782
- chainId: this.options.network.chainId,
783
- data: '0x'
784
- });
785
- return [2 /*return*/, transaction];
786
- case 8: throw new errors_1.BalanceError(coinlib_core_1.Domain.ETHEREUM, 'not enough balance');
787
- }
788
- });
789
- });
790
- };
791
- EthereumBaseProtocolImpl.prototype.getWalletConnectChain = function () {
792
- return __awaiter(this, void 0, void 0, function () {
793
- return __generator(this, function (_a) {
794
- return [2 /*return*/, "".concat(WALLET_CONNECT_NAMESPACE, ":").concat(this.options.network.chainId)];
795
- });
796
- });
797
- };
798
- EthereumBaseProtocolImpl.prototype.prepareWalletConnectTransactionWithPublicKey = function (publicKey, request) {
799
- var _a, _b, _c;
800
- return __awaiter(this, void 0, void 0, function () {
801
- var gasPricePromise, noncePromise, _d, gasPrice, nonce;
802
- var _this = this;
803
- return __generator(this, function (_e) {
804
- switch (_e.label) {
805
- case 0:
806
- gasPricePromise = request.gasPrice
807
- ? Promise.resolve(request.gasPrice)
808
- : this.nodeClient.getGasPrice().then(function (gasPrice) { return "0x".concat(gasPrice.toString(16)); });
809
- noncePromise = request.nonce
810
- ? Promise.resolve(request.nonce)
811
- : this.getAddressFromPublicKey(publicKey)
812
- .then(function (address) { return _this.nodeClient.fetchTransactionCount(address); })
813
- .then(function (transactionCount) { return "0x".concat(new bignumber_1.BigNumber(transactionCount).toString(16)); });
814
- return [4 /*yield*/, Promise.all([gasPricePromise, noncePromise])];
815
- case 1:
816
- _d = _e.sent(), gasPrice = _d[0], nonce = _d[1];
817
- return [2 /*return*/, (0, module_kit_1.newUnsignedTransaction)({
818
- ethereumType: 'raw',
819
- nonce: nonce,
820
- gasLimit: "0x".concat((300000).toString(16)),
821
- gasPrice: gasPrice,
822
- to: (_a = request.to) !== null && _a !== void 0 ? _a : '',
823
- value: (_b = request.value) !== null && _b !== void 0 ? _b : '0x00',
824
- chainId: this.options.network.chainId,
825
- data: (_c = request.data) !== null && _c !== void 0 ? _c : '0x'
826
- })];
827
- }
828
- });
829
- });
830
- };
831
- EthereumBaseProtocolImpl.prototype.broadcastTransaction = function (transaction) {
832
- return __awaiter(this, void 0, void 0, function () {
833
- return __generator(this, function (_a) {
834
- return [2 /*return*/, this.nodeClient.sendSignedTransaction("0x".concat(transaction.serialized.replace(/^0x/, '')))];
835
- });
836
- });
837
- };
838
- // Custom
839
- EthereumBaseProtocolImpl.prototype.nonExtendedPublicKey = function (publicKey) {
840
- return publicKey.type === 'pub' ? publicKey : this.getPublicKeyFromExtendedPublicKey(publicKey);
841
- };
842
- EthereumBaseProtocolImpl.prototype.nonExtendedSecretKey = function (secretKey) {
843
- return secretKey.type === 'priv' ? secretKey : this.getSecretKeyFromExtendedSecretKey(secretKey);
844
- };
845
- EthereumBaseProtocolImpl.prototype.getPublicKeyFromExtendedPublicKey = function (extendedPublicKey, visibilityIndex, addressIndex) {
846
- if (visibilityIndex === void 0) { visibilityIndex = 0; }
847
- if (addressIndex === void 0) { addressIndex = 0; }
848
- var encodedExtendedPublicKey = (0, key_1.convertExtendedPublicKey)(extendedPublicKey, 'encoded');
849
- var derivedNode = this.deriveNode(encodedExtendedPublicKey.value, visibilityIndex, addressIndex);
850
- return (0, module_kit_1.newPublicKey)(derivedNode.neutered().keyPair.getPublicKeyBuffer().toString('hex'), 'hex');
851
- };
852
- EthereumBaseProtocolImpl.prototype.getSecretKeyFromExtendedSecretKey = function (extendedSecretKey, visibilityIndex, addressIndex) {
853
- if (visibilityIndex === void 0) { visibilityIndex = 0; }
854
- if (addressIndex === void 0) { addressIndex = 0; }
855
- var encodedExtendedSecretKey = (0, key_1.convertExtendedSecretKey)(extendedSecretKey, 'encoded');
856
- var derivedNode = this.deriveNode(encodedExtendedSecretKey.value, visibilityIndex, addressIndex);
857
- return (0, module_kit_1.newSecretKey)(derivedNode.keyPair.getPrivateKeyBuffer().toString('hex'), 'hex');
858
- };
859
- EthereumBaseProtocolImpl.prototype.deriveNode = function (base58, visibilityIndex, addressIndex) {
860
- return [visibilityIndex, addressIndex].reduce(function (node, index) { return node.derive(index); }, this.bitcoinJS.lib.HDNode.fromBase58(base58, this.bitcoinJS.config.network));
861
- };
862
- EthereumBaseProtocolImpl.prototype.estimateGas = function (fromAddress, toAddress, amount, data) {
863
- return __awaiter(this, void 0, void 0, function () {
864
- var hexAmount, blockchainAmount;
865
- return __generator(this, function (_a) {
866
- if (typeof amount === 'string' && (0, hex_1.isHex)(amount)) {
867
- hexAmount = amount;
868
- }
869
- else {
870
- blockchainAmount = (0, module_kit_1.isAmount)(amount) ? (0, module_kit_1.newAmount)(amount).blockchain(this.units) : (0, module_kit_1.newAmount)(amount, 'blockchain');
871
- hexAmount = EthereumUtils_1.EthereumUtils.toHex(blockchainAmount.value);
872
- }
873
- return [2 /*return*/, this.nodeClient.estimateTransactionGas(fromAddress, toAddress, hexAmount, data, EthereumUtils_1.EthereumUtils.toHex(MAX_GAS_ESTIMATE))];
874
- });
875
- });
876
- };
877
- EthereumBaseProtocolImpl.prototype.derivativeToBip32Node = function (derivative) {
878
- var bip32Node = (0, crypto_1.encodeDerivative)('bip32', derivative);
879
- return this.bitcoinJS.lib.HDNode.fromBase58(bip32Node.secretKey, this.bitcoinJS.config.network);
880
- };
881
119
  return EthereumBaseProtocolImpl;
882
- }());
120
+ }(evm_1.EvmBaseProtocolImpl));
883
121
  exports.EthereumBaseProtocolImpl = EthereumBaseProtocolImpl;
884
- var DefaultEthereumBaseProtocolImpl = /** @class */ (function (_super) {
885
- __extends(DefaultEthereumBaseProtocolImpl, _super);
886
- function DefaultEthereumBaseProtocolImpl(nodeClient, infoClient, options) {
887
- return _super.call(this, nodeClient, infoClient, __assign(__assign({}, options), { identifier: coinlib_core_1.MainProtocolSymbols.ETH, name: 'Ethereum', units: exports.DEFAULT_ETHEREUM_UNITS_METADATA, mainUnit: 'ETH' })) || this;
888
- }
889
- return DefaultEthereumBaseProtocolImpl;
890
- }(EthereumBaseProtocolImpl));
891
- exports.DefaultEthereumBaseProtocolImpl = DefaultEthereumBaseProtocolImpl;
892
122
  //# sourceMappingURL=EthereumBaseProtocol.js.map