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