@airgap/ethereum 0.13.7-beta.21 → 0.13.7-beta.23

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