@wallfree-dev/ethereum 0.13.42

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 (167) hide show
  1. package/LICENSE.md +7 -0
  2. package/index.d.ts +1 -0
  3. package/index.js +18 -0
  4. package/index.js.map +1 -0
  5. package/package.json +67 -0
  6. package/readme.md +121 -0
  7. package/v0/index.d.ts +12 -0
  8. package/v0/index.js +39 -0
  9. package/v0/index.js.map +1 -0
  10. package/v0/protocol/BaseEthereumProtocol.d.ts +99 -0
  11. package/v0/protocol/BaseEthereumProtocol.js +946 -0
  12. package/v0/protocol/BaseEthereumProtocol.js.map +1 -0
  13. package/v0/protocol/EthereumAddress.d.ts +8 -0
  14. package/v0/protocol/EthereumAddress.js +43 -0
  15. package/v0/protocol/EthereumAddress.js.map +1 -0
  16. package/v0/protocol/EthereumChainIDs.d.ts +1 -0
  17. package/v0/protocol/EthereumChainIDs.js +340 -0
  18. package/v0/protocol/EthereumChainIDs.js.map +1 -0
  19. package/v0/protocol/EthereumClassicProtocol.d.ts +6 -0
  20. package/v0/protocol/EthereumClassicProtocol.js +30 -0
  21. package/v0/protocol/EthereumClassicProtocol.js.map +1 -0
  22. package/v0/protocol/EthereumCryptoClient.d.ts +12 -0
  23. package/v0/protocol/EthereumCryptoClient.js +148 -0
  24. package/v0/protocol/EthereumCryptoClient.js.map +1 -0
  25. package/v0/protocol/EthereumProtocol.d.ts +10 -0
  26. package/v0/protocol/EthereumProtocol.js +34 -0
  27. package/v0/protocol/EthereumProtocol.js.map +1 -0
  28. package/v0/protocol/EthereumProtocolOptions.d.ts +46 -0
  29. package/v0/protocol/EthereumProtocolOptions.js +150 -0
  30. package/v0/protocol/EthereumProtocolOptions.js.map +1 -0
  31. package/v0/protocol/EthereumRopstenProtocol.d.ts +6 -0
  32. package/v0/protocol/EthereumRopstenProtocol.js +30 -0
  33. package/v0/protocol/EthereumRopstenProtocol.js.map +1 -0
  34. package/v0/protocol/EthereumTypes.d.ts +14 -0
  35. package/v0/protocol/EthereumTypes.js +3 -0
  36. package/v0/protocol/EthereumTypes.js.map +1 -0
  37. package/v0/protocol/clients/info-clients/EtherscanInfoClient.d.ts +8 -0
  38. package/v0/protocol/clients/info-clients/EtherscanInfoClient.js +195 -0
  39. package/v0/protocol/clients/info-clients/EtherscanInfoClient.js.map +1 -0
  40. package/v0/protocol/clients/info-clients/InfoClient.d.ts +8 -0
  41. package/v0/protocol/clients/info-clients/InfoClient.js +11 -0
  42. package/v0/protocol/clients/info-clients/InfoClient.js.map +1 -0
  43. package/v0/protocol/clients/node-clients/AirGapNodeClient.d.ts +41 -0
  44. package/v0/protocol/clients/node-clients/AirGapNodeClient.js +353 -0
  45. package/v0/protocol/clients/node-clients/AirGapNodeClient.js.map +1 -0
  46. package/v0/protocol/clients/node-clients/NodeClient.d.ts +17 -0
  47. package/v0/protocol/clients/node-clients/NodeClient.js +11 -0
  48. package/v0/protocol/clients/node-clients/NodeClient.js.map +1 -0
  49. package/v0/protocol/erc20/ERC20.d.ts +3 -0
  50. package/v0/protocol/erc20/ERC20.js +9 -0
  51. package/v0/protocol/erc20/ERC20.js.map +1 -0
  52. package/v0/protocol/erc20/GenericERC20.d.ts +32 -0
  53. package/v0/protocol/erc20/GenericERC20.js +335 -0
  54. package/v0/protocol/erc20/GenericERC20.js.map +1 -0
  55. package/v0/protocol/utils/utils.d.ts +13 -0
  56. package/v0/protocol/utils/utils.js +140 -0
  57. package/v0/protocol/utils/utils.js.map +1 -0
  58. package/v0/serializer/schemas/v2/transaction-sign-request-ethereum.json +50 -0
  59. package/v0/serializer/schemas/v2/transaction-sign-response-ethereum.json +19 -0
  60. package/v0/serializer/schemas/v3/transaction-sign-request-ethereum-typed.json +38 -0
  61. package/v0/serializer/schemas/v3/transaction-sign-request-ethereum.json +50 -0
  62. package/v0/serializer/schemas/v3/transaction-sign-response-ethereum.json +19 -0
  63. package/v0/serializer/validators/transaction-validator.d.ts +15 -0
  64. package/v0/serializer/validators/transaction-validator.js +96 -0
  65. package/v0/serializer/validators/transaction-validator.js.map +1 -0
  66. package/v0/serializer/validators/validators.d.ts +1 -0
  67. package/v0/serializer/validators/validators.js +78 -0
  68. package/v0/serializer/validators/validators.js.map +1 -0
  69. package/v0/types/signed-transaction-ethereum.d.ts +5 -0
  70. package/v0/types/signed-transaction-ethereum.js +3 -0
  71. package/v0/types/signed-transaction-ethereum.js.map +1 -0
  72. package/v0/types/transaction-ethereum.d.ts +14 -0
  73. package/v0/types/transaction-ethereum.js +3 -0
  74. package/v0/types/transaction-ethereum.js.map +1 -0
  75. package/v0/types/unsigned-transaction-ethereum-typed.d.ts +11 -0
  76. package/v0/types/unsigned-transaction-ethereum-typed.js +3 -0
  77. package/v0/types/unsigned-transaction-ethereum-typed.js.map +1 -0
  78. package/v0/types/unsigned-transaction-ethereum.d.ts +15 -0
  79. package/v0/types/unsigned-transaction-ethereum.js +3 -0
  80. package/v0/types/unsigned-transaction-ethereum.js.map +1 -0
  81. package/v1/block-explorer/EtherscanBlockExplorer.d.ts +9 -0
  82. package/v1/block-explorer/EtherscanBlockExplorer.js +72 -0
  83. package/v1/block-explorer/EtherscanBlockExplorer.js.map +1 -0
  84. package/v1/clients/crypto/EthereumCryptoClient.d.ts +7 -0
  85. package/v1/clients/crypto/EthereumCryptoClient.js +147 -0
  86. package/v1/clients/crypto/EthereumCryptoClient.js.map +1 -0
  87. package/v1/clients/info/EthereumInfoClient.d.ts +15 -0
  88. package/v1/clients/info/EthereumInfoClient.js +11 -0
  89. package/v1/clients/info/EthereumInfoClient.js.map +1 -0
  90. package/v1/clients/info/EtherscanInfoClient.d.ts +8 -0
  91. package/v1/clients/info/EtherscanInfoClient.js +173 -0
  92. package/v1/clients/info/EtherscanInfoClient.js.map +1 -0
  93. package/v1/clients/node/EthereumNodeClient.d.ts +18 -0
  94. package/v1/clients/node/EthereumNodeClient.js +3 -0
  95. package/v1/clients/node/EthereumNodeClient.js.map +1 -0
  96. package/v1/clients/node/HttpEthereumNodeClient.d.ts +66 -0
  97. package/v1/clients/node/HttpEthereumNodeClient.js +451 -0
  98. package/v1/clients/node/HttpEthereumNodeClient.js.map +1 -0
  99. package/v1/data/EthereumAddress.d.ts +7 -0
  100. package/v1/data/EthereumAddress.js +46 -0
  101. package/v1/data/EthereumAddress.js.map +1 -0
  102. package/v1/index.d.ts +30 -0
  103. package/v1/index.js +43 -0
  104. package/v1/index.js.map +1 -0
  105. package/v1/module/ERC20Tokens.d.ts +3 -0
  106. package/v1/module/ERC20Tokens.js +847 -0
  107. package/v1/module/ERC20Tokens.js.map +1 -0
  108. package/v1/module/EthereumModule.d.ts +16 -0
  109. package/v1/module/EthereumModule.js +127 -0
  110. package/v1/module/EthereumModule.js.map +1 -0
  111. package/v1/module.d.ts +3 -0
  112. package/v1/module.js +24 -0
  113. package/v1/module.js.map +1 -0
  114. package/v1/protocol/EthereumBaseProtocol.d.ts +87 -0
  115. package/v1/protocol/EthereumBaseProtocol.js +892 -0
  116. package/v1/protocol/EthereumBaseProtocol.js.map +1 -0
  117. package/v1/protocol/EthereumChainIds.d.ts +1 -0
  118. package/v1/protocol/EthereumChainIds.js +340 -0
  119. package/v1/protocol/EthereumChainIds.js.map +1 -0
  120. package/v1/protocol/EthereumProtocol.d.ts +8 -0
  121. package/v1/protocol/EthereumProtocol.js +65 -0
  122. package/v1/protocol/EthereumProtocol.js.map +1 -0
  123. package/v1/protocol/erc20/ERC20Protocol.d.ts +32 -0
  124. package/v1/protocol/erc20/ERC20Protocol.js +397 -0
  125. package/v1/protocol/erc20/ERC20Protocol.js.map +1 -0
  126. package/v1/protocol/erc20/ERC20Token.d.ts +19 -0
  127. package/v1/protocol/erc20/ERC20Token.js +131 -0
  128. package/v1/protocol/erc20/ERC20Token.js.map +1 -0
  129. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +8 -0
  130. package/v1/serializer/v3/schemas/converter/transaction-converter.js +82 -0
  131. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
  132. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.d.ts +10 -0
  133. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js +3 -0
  134. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js.map +1 -0
  135. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.d.ts +14 -0
  136. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js +3 -0
  137. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js.map +1 -0
  138. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.d.ts +3 -0
  139. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js +3 -0
  140. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js.map +1 -0
  141. package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum-typed.json +41 -0
  142. package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum.json +58 -0
  143. package/v1/serializer/v3/schemas/generated/transaction-sign-response-ethereum.json +19 -0
  144. package/v1/serializer/v3/serializer-companion.d.ts +13 -0
  145. package/v1/serializer/v3/serializer-companion.js +182 -0
  146. package/v1/serializer/v3/serializer-companion.js.map +1 -0
  147. package/v1/serializer/v3/validators/transaction-validator.d.ts +7 -0
  148. package/v1/serializer/v3/validators/transaction-validator.js +71 -0
  149. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
  150. package/v1/types/crypto.d.ts +2 -0
  151. package/v1/types/crypto.js +3 -0
  152. package/v1/types/crypto.js.map +1 -0
  153. package/v1/types/protocol.d.ts +35 -0
  154. package/v1/types/protocol.js +3 -0
  155. package/v1/types/protocol.js.map +1 -0
  156. package/v1/types/transaction.d.ts +24 -0
  157. package/v1/types/transaction.js +3 -0
  158. package/v1/types/transaction.js.map +1 -0
  159. package/v1/utils/EthereumUtils.d.ts +16 -0
  160. package/v1/utils/EthereumUtils.js +155 -0
  161. package/v1/utils/EthereumUtils.js.map +1 -0
  162. package/v1/utils/key.d.ts +5 -0
  163. package/v1/utils/key.js +101 -0
  164. package/v1/utils/key.js.map +1 -0
  165. package/v1/utils/protocol.d.ts +13 -0
  166. package/v1/utils/protocol.js +38 -0
  167. package/v1/utils/protocol.js.map +1 -0
@@ -0,0 +1,397 @@
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.ERC20ProtocolImpl = void 0;
92
+ var coinlib_core_1 = require("@wallfree-dev/coinlib-core");
93
+ var bignumber_1 = __importDefault(require("@wallfree-dev/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
94
+ // @ts-ignore
95
+ var ethUtil = __importStar(require("@wallfree-dev/coinlib-core/dependencies/src/ethereumjs-util-5.2.0"));
96
+ var errors_1 = require("@wallfree-dev/coinlib-core/errors");
97
+ var hex_1 = require("@wallfree-dev/coinlib-core/utils/hex");
98
+ var module_kit_1 = require("@wallfree-dev/module-kit");
99
+ var tx_1 = require("@ethereumjs/tx");
100
+ var HttpEthereumNodeClient_1 = require("../../clients/node/HttpEthereumNodeClient");
101
+ var EthereumUtils_1 = require("../../utils/EthereumUtils");
102
+ var EthereumBaseProtocol_1 = require("../EthereumBaseProtocol");
103
+ var EthereumTransaction = require('@wallfree-dev/coinlib-core/dependencies/src/ethereumjs-tx-1.3.7/index');
104
+ // Implementation
105
+ var ERC20ProtocolImpl = /** @class */ (function (_super) {
106
+ __extends(ERC20ProtocolImpl, _super);
107
+ function ERC20ProtocolImpl(nodeClient, infoClient, options) {
108
+ var _this = _super.call(this, nodeClient, infoClient, {
109
+ network: options.network,
110
+ name: options.name,
111
+ identifier: options.identifier,
112
+ units: options.units,
113
+ mainUnit: options.mainUnit
114
+ }) || this;
115
+ _this.contractAddress = options.contractAddress;
116
+ return _this;
117
+ }
118
+ // Common
119
+ ERC20ProtocolImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
120
+ return __awaiter(this, void 0, void 0, function () {
121
+ var ethTransactionDetails;
122
+ return __generator(this, function (_a) {
123
+ switch (_a.label) {
124
+ case 0: return [4 /*yield*/, _super.prototype.getDetailsFromTransaction.call(this, transaction, publicKey)];
125
+ case 1:
126
+ ethTransactionDetails = _a.sent();
127
+ switch (transaction.type) {
128
+ case 'signed':
129
+ return [2 /*return*/, this.getDetailsFromSignedContractTransaction(transaction, ethTransactionDetails)];
130
+ case 'unsigned':
131
+ return [2 /*return*/, this.getDetailsFromUnsignedContractTransaction(transaction, ethTransactionDetails)];
132
+ default:
133
+ (0, coinlib_core_1.assertNever)(transaction);
134
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unsupported transaction type.');
135
+ }
136
+ return [2 /*return*/];
137
+ }
138
+ });
139
+ });
140
+ };
141
+ ERC20ProtocolImpl.prototype.getDetailsFromSignedContractTransaction = function (transaction, ethTransactionDetails) {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ var extractedTx, tokenTransferDetails;
144
+ return __generator(this, function (_a) {
145
+ if (ethTransactionDetails.length !== 1) {
146
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ERC20, 'More than one ETH transaction detected.');
147
+ }
148
+ extractedTx = new EthereumTransaction(transaction.serialized);
149
+ tokenTransferDetails = new HttpEthereumNodeClient_1.EthereumRPCDataTransfer("0x".concat(extractedTx.data.toString('hex')));
150
+ return [2 /*return*/, [
151
+ __assign(__assign({}, ethTransactionDetails[0]), { to: [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)], amount: (0, module_kit_1.newAmount)(tokenTransferDetails.amount, 'blockchain') })
152
+ ]];
153
+ });
154
+ });
155
+ };
156
+ ERC20ProtocolImpl.prototype.getDetailsFromUnsignedContractTransaction = function (transaction, ethTransactionDetails) {
157
+ return __awaiter(this, void 0, void 0, function () {
158
+ var data, typedTransaction, tokenTransferDetails;
159
+ return __generator(this, function (_a) {
160
+ if (ethTransactionDetails.length !== 1) {
161
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ERC20, 'More than one ETH transaction detected.');
162
+ }
163
+ if (transaction.ethereumType === 'raw') {
164
+ data = transaction.data;
165
+ }
166
+ else {
167
+ typedTransaction = tx_1.TransactionFactory.fromSerializedData(Buffer.from(transaction.serialized, 'hex'));
168
+ data = typedTransaction.data.toString('hex');
169
+ }
170
+ tokenTransferDetails = new HttpEthereumNodeClient_1.EthereumRPCDataTransfer(data);
171
+ return [2 /*return*/, [
172
+ __assign(__assign({}, ethTransactionDetails[0]), { to: [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)], amount: (0, module_kit_1.newAmount)(tokenTransferDetails.amount, 'blockchain') })
173
+ ]];
174
+ });
175
+ });
176
+ };
177
+ // Offline
178
+ ERC20ProtocolImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
179
+ return __awaiter(this, void 0, void 0, function () {
180
+ var rawTransaction;
181
+ return __generator(this, function (_a) {
182
+ if (transaction.ethereumType !== 'raw') {
183
+ // no v0 implementation
184
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ERC20, 'Unsupported unsigned transaction type.');
185
+ }
186
+ rawTransaction = __assign(__assign({}, transaction), { data: !transaction.data || transaction.data === '0x'
187
+ ? new HttpEthereumNodeClient_1.EthereumRPCDataTransfer(transaction.to, transaction.value).abiEncoded()
188
+ : transaction.data });
189
+ return [2 /*return*/, _super.prototype.signTransactionWithSecretKey.call(this, rawTransaction, secretKey)];
190
+ });
191
+ });
192
+ };
193
+ // Online
194
+ ERC20ProtocolImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
195
+ return __awaiter(this, void 0, void 0, function () {
196
+ var address;
197
+ return __generator(this, function (_a) {
198
+ switch (_a.label) {
199
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
200
+ case 1:
201
+ address = _a.sent();
202
+ return [2 /*return*/, this.getTransactionsForAddress(address, limit, cursor)];
203
+ }
204
+ });
205
+ });
206
+ };
207
+ ERC20ProtocolImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
208
+ return __awaiter(this, void 0, void 0, function () {
209
+ return __generator(this, function (_a) {
210
+ return [2 /*return*/, this.getTransactionsForAddresses([address], limit, cursor)];
211
+ });
212
+ });
213
+ };
214
+ ERC20ProtocolImpl.prototype.getTransactionsForAddresses = function (addresses, limit, cursor) {
215
+ return __awaiter(this, void 0, void 0, function () {
216
+ var _this = this;
217
+ return __generator(this, function (_a) {
218
+ return [2 /*return*/, new Promise(function (overallResolve, overallReject) {
219
+ var promises = [];
220
+ for (var _i = 0, addresses_1 = addresses; _i < addresses_1.length; _i++) {
221
+ var address = addresses_1[_i];
222
+ promises.push(_this.infoClient.fetchContractTransactions(_this.contractAddress, address, limit, cursor));
223
+ }
224
+ Promise.all(promises)
225
+ .then(function (values) {
226
+ var page = Math.max.apply(Math, values.map(function (txResult) { return txResult.cursor.page; }));
227
+ var transactions = values.reduce(function (acc, current) {
228
+ 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 })); }));
229
+ }, []);
230
+ var hasNext = transactions.length >= limit;
231
+ overallResolve({
232
+ transactions: transactions,
233
+ cursor: {
234
+ hasNext: hasNext,
235
+ page: hasNext ? page : undefined
236
+ }
237
+ });
238
+ })
239
+ .catch(overallReject);
240
+ })];
241
+ });
242
+ });
243
+ };
244
+ ERC20ProtocolImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
245
+ return __awaiter(this, void 0, void 0, function () {
246
+ var address;
247
+ return __generator(this, function (_a) {
248
+ switch (_a.label) {
249
+ case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
250
+ case 1:
251
+ address = _a.sent();
252
+ return [2 /*return*/, this.getBalanceOfAddress(address)];
253
+ }
254
+ });
255
+ });
256
+ };
257
+ ERC20ProtocolImpl.prototype.getBalanceOfAddress = function (address) {
258
+ return __awaiter(this, void 0, void 0, function () {
259
+ return __generator(this, function (_a) {
260
+ return [2 /*return*/, this.getBalanceOfAddresses([address])];
261
+ });
262
+ });
263
+ };
264
+ ERC20ProtocolImpl.prototype.getBalanceOfAddresses = function (addresses) {
265
+ return __awaiter(this, void 0, void 0, function () {
266
+ var balances, totalBalance;
267
+ var _this = this;
268
+ return __generator(this, function (_a) {
269
+ switch (_a.label) {
270
+ case 0: return [4 /*yield*/, Promise.all(addresses.map(function (address) {
271
+ return _this.nodeClient.callBalanceOf(_this.contractAddress, address);
272
+ }))];
273
+ case 1:
274
+ balances = _a.sent();
275
+ totalBalance = balances.reduce(function (a, b) { return a.plus(b); });
276
+ return [2 /*return*/, { total: (0, module_kit_1.newAmount)(totalBalance, 'blockchain') }];
277
+ }
278
+ });
279
+ });
280
+ };
281
+ ERC20ProtocolImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
282
+ var _a;
283
+ return __awaiter(this, void 0, void 0, function () {
284
+ var balance;
285
+ return __generator(this, function (_b) {
286
+ switch (_b.label) {
287
+ case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
288
+ case 1:
289
+ balance = _b.sent();
290
+ return [2 /*return*/, (_a = balance.transferable) !== null && _a !== void 0 ? _a : balance.total];
291
+ }
292
+ });
293
+ });
294
+ };
295
+ ERC20ProtocolImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
296
+ var _a;
297
+ return __awaiter(this, void 0, void 0, function () {
298
+ var fee, estimatedFee, wrappedFee, wrappedAmount, balance, wrappedBalance, address, ethBalance, wrappedEthBalance, estimatedGas, txCount, gasPrice, transaction;
299
+ return __generator(this, function (_b) {
300
+ switch (_b.label) {
301
+ case 0:
302
+ if (details.length !== 1) {
303
+ throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ETHEREUM, 'you cannot have 0 transaction details');
304
+ }
305
+ if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 1];
306
+ fee = configuration.fee;
307
+ return [3 /*break*/, 3];
308
+ case 1: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, details)];
309
+ case 2:
310
+ estimatedFee = _b.sent();
311
+ fee = estimatedFee.medium;
312
+ _b.label = 3;
313
+ case 3:
314
+ wrappedFee = new bignumber_1.default((0, module_kit_1.newAmount)(fee).blockchain(this.feeUnits).value);
315
+ wrappedAmount = new bignumber_1.default((0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units).value);
316
+ return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
317
+ case 4:
318
+ balance = _b.sent();
319
+ wrappedBalance = new bignumber_1.default((0, module_kit_1.newAmount)((_a = balance.transferable) !== null && _a !== void 0 ? _a : balance.total).blockchain(this.units).value);
320
+ if (!wrappedBalance.isGreaterThanOrEqualTo(wrappedAmount)) return [3 /*break*/, 11];
321
+ return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
322
+ case 5:
323
+ address = _b.sent();
324
+ return [4 /*yield*/, _super.prototype.getBalanceOfAddresses.call(this, [address])];
325
+ case 6:
326
+ ethBalance = _b.sent();
327
+ wrappedEthBalance = new bignumber_1.default((0, module_kit_1.newAmount)(ethBalance.total).blockchain(this.units).value);
328
+ return [4 /*yield*/, this.estimateGas(address, details[0].to, wrappedAmount)];
329
+ case 7:
330
+ estimatedGas = _b.sent();
331
+ if (!wrappedEthBalance.isGreaterThanOrEqualTo(wrappedFee)) return [3 /*break*/, 9];
332
+ return [4 /*yield*/, this.nodeClient.fetchTransactionCount(address)];
333
+ case 8:
334
+ txCount = _b.sent();
335
+ gasPrice = wrappedFee.isEqualTo(0)
336
+ ? new bignumber_1.default(0)
337
+ : wrappedFee.div(estimatedGas).integerValue(bignumber_1.default.ROUND_CEIL);
338
+ transaction = (0, module_kit_1.newUnsignedTransaction)({
339
+ ethereumType: 'raw',
340
+ nonce: EthereumUtils_1.EthereumUtils.toHex(txCount),
341
+ gasLimit: EthereumUtils_1.EthereumUtils.toHex(estimatedGas.toFixed()),
342
+ gasPrice: EthereumUtils_1.EthereumUtils.toHex(gasPrice.toFixed()),
343
+ to: this.contractAddress,
344
+ value: EthereumUtils_1.EthereumUtils.toHex(new bignumber_1.default(0).toFixed()),
345
+ chainId: this.options.network.chainId,
346
+ data: new HttpEthereumNodeClient_1.EthereumRPCDataTransfer(details[0].to, EthereumUtils_1.EthereumUtils.toHex(wrappedAmount.toFixed())).abiEncoded()
347
+ });
348
+ return [2 /*return*/, transaction];
349
+ case 9: throw new errors_1.BalanceError(coinlib_core_1.Domain.ERC20, 'not enough ETH balance');
350
+ case 10: return [3 /*break*/, 12];
351
+ case 11: throw new errors_1.BalanceError(coinlib_core_1.Domain.ERC20, 'not enough token balance');
352
+ case 12: return [2 /*return*/];
353
+ }
354
+ });
355
+ });
356
+ };
357
+ // Custom
358
+ ERC20ProtocolImpl.prototype.name = function () {
359
+ return __awaiter(this, void 0, void 0, function () {
360
+ return __generator(this, function (_a) {
361
+ return [2 /*return*/, this.nodeClient.getContractName(this.contractAddress)];
362
+ });
363
+ });
364
+ };
365
+ ERC20ProtocolImpl.prototype.symbol = function () {
366
+ return __awaiter(this, void 0, void 0, function () {
367
+ return __generator(this, function (_a) {
368
+ return [2 /*return*/, this.nodeClient.getContractSymbol(this.contractAddress)];
369
+ });
370
+ });
371
+ };
372
+ ERC20ProtocolImpl.prototype.decimals = function () {
373
+ return __awaiter(this, void 0, void 0, function () {
374
+ return __generator(this, function (_a) {
375
+ return [2 /*return*/, this.nodeClient.getContractDecimals(this.contractAddress)];
376
+ });
377
+ });
378
+ };
379
+ ERC20ProtocolImpl.prototype.estimateGas = function (fromAddress, toAddress, amount, _data) {
380
+ return __awaiter(this, void 0, void 0, function () {
381
+ var hexAmount, blockchainAmount;
382
+ return __generator(this, function (_a) {
383
+ if (typeof amount === 'string' && (0, hex_1.isHex)(amount)) {
384
+ hexAmount = amount;
385
+ }
386
+ else {
387
+ blockchainAmount = (0, module_kit_1.isAmount)(amount) ? (0, module_kit_1.newAmount)(amount).blockchain(this.units) : (0, module_kit_1.newAmount)(amount, 'blockchain');
388
+ hexAmount = EthereumUtils_1.EthereumUtils.toHex(blockchainAmount.value);
389
+ }
390
+ return [2 /*return*/, this.nodeClient.estimateTransferGas(this.contractAddress, fromAddress, toAddress, hexAmount)];
391
+ });
392
+ });
393
+ };
394
+ return ERC20ProtocolImpl;
395
+ }(EthereumBaseProtocol_1.EthereumBaseProtocolImpl));
396
+ exports.ERC20ProtocolImpl = ERC20ProtocolImpl;
397
+ //# sourceMappingURL=ERC20Protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ERC20Protocol.js","sourceRoot":"","sources":["../../../../src/v1/protocol/erc20/ERC20Protocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAAgE;AAChE,uHAAgG;AAChG,aAAa;AACb,yGAA4F;AAC5F,4DAA2G;AAC3G,4DAA4D;AAC5D,uDAciC;AACjC,qCAAgF;AAGhF,oFAAmF;AASnF,2DAAyD;AACzD,gEAAwF;AAExF,IAAM,mBAAmB,GAAG,OAAO,CAAC,uEAAuE,CAAC,CAAA;AAW5G,iBAAiB;AAEjB;IACU,qCAAkD;IAK1D,2BACE,UAA8B,EAC9B,UAA8B,EAC9B,OAAuD;QAHzD,YAKE,kBAAM,UAAU,EAAE,UAAU,EAAE;YAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;YAExB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,U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AAC,UAAU,CAAC,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,EAAA;;;KAC/D;IAEY,oCAAQ,GAArB;;;gBACE,sBAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,CAAC,EAAA;;;KACjE;IAEe,uCAAW,GAA3B,UACE,WAAmB,EACnB,SAAiB,EACjB,MAA4C,EAC5C,KAAc;;;;gBAGd,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,IAAA,WAAK,EAAC,MAAM,CAAC,EAAE;oBAC/C,SAAS,GAAG,MAAM,CAAA;iBACnB;qBAAM;oBACC,gBAAgB,GAAW,IAAA,qBAAQ,EAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAA,sBAAS,EAAC,MAAM,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,sBAAS,EAAC,MAAM,EAAE,YAAY,CAAC,CAAA;oBAE9H,SAAS,GAAG,6BAAa,CAAC,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;iBACxD;gBAED,sBAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,CAAC,EAAA;;;KACpG;IACH,wBAAC;AAAD,CAAC,AAnSD,CACU,+CAAwB,GAkSjC;AAnSqB,8CAAiB"}
@@ -0,0 +1,19 @@
1
+ import { AirGapInterface, RecursivePartial } from '@wallfree-dev/module-kit';
2
+ import { EthereumInfoClient } from '../../clients/info/EthereumInfoClient';
3
+ import { EthereumNodeClient } from '../../clients/node/EthereumNodeClient';
4
+ import { ERC20TokenMetadata, ERC20TokenOptions, EthereumProtocolNetwork } from '../../types/protocol';
5
+ import { ERC20Protocol, ERC20ProtocolImpl } from './ERC20Protocol';
6
+ export interface ERC20Token<_ProtocolNetwork extends EthereumProtocolNetwork = EthereumProtocolNetwork> extends AirGapInterface<ERC20Protocol<string, _ProtocolNetwork>, 'SingleTokenSubProtocol'> {
7
+ }
8
+ export declare class ERC20TokenImpl<_ProtocolNetwork extends EthereumProtocolNetwork = EthereumProtocolNetwork> extends ERC20ProtocolImpl<string, _ProtocolNetwork> implements ERC20Token<_ProtocolNetwork> {
9
+ constructor(nodeClient: EthereumNodeClient, infoClient: EthereumInfoClient, options: ERC20TokenOptions<_ProtocolNetwork>);
10
+ getType(): Promise<'token'>;
11
+ private readonly _mainProtocol;
12
+ mainProtocol(): Promise<string>;
13
+ getContractAddress(): Promise<string>;
14
+ }
15
+ declare type ERC20TokenOptionsWithoutMetadata = Omit<ERC20TokenOptions, 'name' | 'identifier' | 'contractAddress' | 'symbol' | 'marketSymbol' | 'decimals'>;
16
+ export declare function createERC20Token(metadata: ERC20TokenMetadata, options?: RecursivePartial<ERC20TokenOptionsWithoutMetadata>): ERC20Token;
17
+ export declare const ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK: EthereumProtocolNetwork;
18
+ export declare function createERC20TokenOptions(metadata: ERC20TokenMetadata, network?: Partial<EthereumProtocolNetwork>, mainIdentifier?: string): ERC20TokenOptions;
19
+ export {};
@@ -0,0 +1,131 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ 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;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.createERC20TokenOptions = exports.ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK = exports.createERC20Token = exports.ERC20TokenImpl = void 0;
66
+ var coinlib_core_1 = require("@wallfree-dev/coinlib-core");
67
+ var EtherscanInfoClient_1 = require("../../clients/info/EtherscanInfoClient");
68
+ var HttpEthereumNodeClient_1 = require("../../clients/node/HttpEthereumNodeClient");
69
+ var EthereumProtocol_1 = require("../EthereumProtocol");
70
+ var ERC20Protocol_1 = require("./ERC20Protocol");
71
+ // Implementation
72
+ var ERC20TokenImpl = /** @class */ (function (_super) {
73
+ __extends(ERC20TokenImpl, _super);
74
+ function ERC20TokenImpl(nodeClient, infoClient, options) {
75
+ var _this = _super.call(this, nodeClient, infoClient, options) || this;
76
+ _this._mainProtocol = options.mainIdentifier;
77
+ return _this;
78
+ }
79
+ // SubProtocol
80
+ ERC20TokenImpl.prototype.getType = function () {
81
+ return __awaiter(this, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ return [2 /*return*/, 'token'];
84
+ });
85
+ });
86
+ };
87
+ ERC20TokenImpl.prototype.mainProtocol = function () {
88
+ return __awaiter(this, void 0, void 0, function () {
89
+ return __generator(this, function (_a) {
90
+ return [2 /*return*/, this._mainProtocol];
91
+ });
92
+ });
93
+ };
94
+ ERC20TokenImpl.prototype.getContractAddress = function () {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ return __generator(this, function (_a) {
97
+ return [2 /*return*/, this.contractAddress];
98
+ });
99
+ });
100
+ };
101
+ return ERC20TokenImpl;
102
+ }(ERC20Protocol_1.ERC20ProtocolImpl));
103
+ exports.ERC20TokenImpl = ERC20TokenImpl;
104
+ function createERC20Token(metadata, options) {
105
+ if (options === void 0) { options = {}; }
106
+ var completeOptions = createERC20TokenOptions(metadata, options.network, options.mainIdentifier);
107
+ return new ERC20TokenImpl(new HttpEthereumNodeClient_1.HttpEthereumNodeClient(completeOptions.network.rpcUrl), new EtherscanInfoClient_1.EtherscanInfoClient(completeOptions.network.blockExplorerApi), completeOptions);
108
+ }
109
+ exports.createERC20Token = createERC20Token;
110
+ exports.ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK = __assign({}, EthereumProtocol_1.ETHEREUM_MAINNET_PROTOCOL_NETWORK);
111
+ var DEFAULT_ERC20_PROTOCOL_NETWORK = exports.ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK;
112
+ function createERC20TokenOptions(metadata, network, mainIdentifier) {
113
+ var _a;
114
+ if (network === void 0) { network = {}; }
115
+ return {
116
+ network: __assign(__assign({}, DEFAULT_ERC20_PROTOCOL_NETWORK), network),
117
+ name: metadata.name,
118
+ identifier: metadata.identifier,
119
+ mainIdentifier: mainIdentifier !== null && mainIdentifier !== void 0 ? mainIdentifier : coinlib_core_1.MainProtocolSymbols.ETH,
120
+ contractAddress: metadata.contractAddress,
121
+ units: (_a = {},
122
+ _a[metadata.symbol] = {
123
+ symbol: { value: metadata.symbol, market: metadata.marketSymbol },
124
+ decimals: metadata.decimals
125
+ },
126
+ _a),
127
+ mainUnit: metadata.symbol
128
+ };
129
+ }
130
+ exports.createERC20TokenOptions = createERC20TokenOptions;
131
+ //# sourceMappingURL=ERC20Token.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ERC20Token.js","sourceRoot":"","sources":["../../../../src/v1/protocol/erc20/ERC20Token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AI;QACnB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,cAAc,EAAE,cAAc,aAAd,cAAc,cAAd,cAAc,GAAI,kCAAmB,CAAC,GAAG;QAEzD,eAAe,EAAE,QAAQ,CAAC,eAAe;QAEzC,KAAK;YACH,GAAC,QAAQ,CAAC,MAAM,IAAG;gBACjB,MAAM,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,YAAY,EAAE;gBACjE,QAAQ,EAAE,QAAQ,CAAC,QAAQ;aAC5B;eACF;QACD,QAAQ,EAAE,QAAQ,CAAC,MAAM;KAC1B,CAAA;AACH,CAAC;AArBD,0DAqBC"}
@@ -0,0 +1,8 @@
1
+ import { EthereumSignedTransaction, EthereumUnsignedTransaction } from '../../../../types/transaction';
2
+ import { EthereumTransactionSignRequest } from '../definitions/transaction-sign-request-ethereum';
3
+ import { EthereumTypedTransactionSignRequest } from '../definitions/transaction-sign-request-ethereum-typed';
4
+ import { EthereumTransactionSignResponse } from '../definitions/transaction-sign-response-ethereum';
5
+ export declare function ethereumUnsignedTransactionToRequest(unsigned: EthereumUnsignedTransaction, publicKey: string, callbackUrl?: string): EthereumTransactionSignRequest | EthereumTypedTransactionSignRequest;
6
+ export declare function ethereumSignedTransactionToResponse(signed: EthereumSignedTransaction, accountIdentifier: string): EthereumTransactionSignResponse;
7
+ export declare function ethereumTransactionSignRequestToUnsigned(request: EthereumTransactionSignRequest | EthereumTypedTransactionSignRequest): EthereumUnsignedTransaction;
8
+ export declare function ethereumTransactionSignResponseToSigned(response: EthereumTransactionSignResponse): EthereumSignedTransaction;