@airgap/ethereum 0.13.15-beta.10 → 0.13.15-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@airgap/ethereum",
3
- "version": "0.13.15-beta.10",
3
+ "version": "0.13.15-beta.12",
4
4
  "description": "The @airgap/ethereum is an Ethereum implementation of the ICoinProtocol interface from @airgap/coinlib-core.",
5
5
  "keywords": [
6
6
  "airgap",
@@ -1,7 +1,8 @@
1
1
  import { EthereumTransactionCursor } from '../../types/transaction';
2
2
  import { EthereumInfoClient, EthereumInfoClientTransactionsResult } from './EthereumInfoClient';
3
3
  export declare class EtherscanInfoClient extends EthereumInfoClient {
4
- constructor(baseURL: string);
4
+ private readonly apiKey;
5
+ constructor(baseURL: string, apiKey: string);
5
6
  fetchTransactions(address: string, limit: any, cursor?: EthereumTransactionCursor): Promise<EthereumInfoClientTransactionsResult>;
6
7
  fetchContractTransactions(contractAddress: string, address: string, limit: number, cursor?: EthereumTransactionCursor): Promise<EthereumInfoClientTransactionsResult>;
7
8
  }
@@ -64,8 +64,10 @@ var module_kit_1 = require("@airgap/module-kit");
64
64
  var EthereumInfoClient_1 = require("./EthereumInfoClient");
65
65
  var EtherscanInfoClient = /** @class */ (function (_super) {
66
66
  __extends(EtherscanInfoClient, _super);
67
- function EtherscanInfoClient(baseURL) {
68
- return _super.call(this, baseURL) || this;
67
+ function EtherscanInfoClient(baseURL, apiKey) {
68
+ var _this = _super.call(this, baseURL) || this;
69
+ _this.apiKey = apiKey;
70
+ return _this;
69
71
  }
70
72
  EtherscanInfoClient.prototype.fetchTransactions = function (address, limit, cursor) {
71
73
  var _a;
@@ -76,7 +78,7 @@ var EtherscanInfoClient = /** @class */ (function (_super) {
76
78
  case 0:
77
79
  airGapTransactions = [];
78
80
  page = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.page) !== null && _a !== void 0 ? _a : 1;
79
- url = "".concat(this.baseURL, "/api?module=account&action=txlist&address=").concat(address, "&page=").concat(page, "&offset=").concat(limit, "&sort=desc&apiKey=P63MEHEYBM5BGEG5WFN76VPNCET8B2MAP7");
81
+ url = "".concat(this.baseURL, "/api?module=account&action=txlist&address=").concat(address, "&page=").concat(page, "&offset=").concat(limit, "&sort=desc&apiKey=").concat(this.apiKey);
80
82
  return [4 /*yield*/, axios_0_19_0_1.default.get(url)];
81
83
  case 1:
82
84
  response = _b.sent();
@@ -122,7 +124,7 @@ var EtherscanInfoClient = /** @class */ (function (_super) {
122
124
  case 0:
123
125
  airGapTransactions = [];
124
126
  page = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.page) !== null && _a !== void 0 ? _a : 1;
125
- url = "".concat(this.baseURL, "/api?module=account&action=tokentx&address=").concat(address, "&contractAddress=").concat(contractAddress, "&page=").concat(page, "&offset=").concat(limit, "&sort=desc&apiKey=P63MEHEYBM5BGEG5WFN76VPNCET8B2MAP7");
127
+ url = "".concat(this.baseURL, "/api?module=account&action=tokentx&address=").concat(address, "&contractAddress=").concat(contractAddress, "&page=").concat(page, "&offset=").concat(limit, "&sort=desc&apiKey=").concat(this.apiKey);
126
128
  return [4 /*yield*/, axios_0_19_0_1.default.get(url)];
127
129
  case 1:
128
130
  response = _b.sent();
@@ -1 +1 @@
1
- {"version":3,"file":"EtherscanInfoClient.js","sourceRoot":"","sources":["../../../../src/v1/clients/info/EtherscanInfoClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oGAAsE;AACtE,gGAA8F;AAC9F,8FAA2F;AAC3F,sDAA0D;AAC1D,2EAAkE;AAClE,iDAA8C;AAI9C,2DAA8H;AAE9H;IAAyC,uCAAkB;IACzD,6BAAY,OAAe;eACzB,kBAAM,OAAO,CAAC;IAChB,CAAC;IAEY,+CAAiB,GAA9B,UACE,OAAe,EACf,KAAU,EACV,MAAkC;;;;;;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AAC,GAAG,EAAE,YAAY,CAAC;gCAEjC,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,CAAC;gCAC9C,MAAM,EAAE;oCACN,IAAI,EAAE,WAAW,CAAC,gBAAgB,KAAK,SAAS,IAAI,WAAW,CAAC,gBAAgB,KAAK,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ;oCAC/G,IAAI,EAAE,WAAW,CAAC,IAAI;oCACtB,KAAK,EAAE,WAAW,CAAC,WAAW;iCAC/B;6BACF,CAAA;4BAED,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAA;yBAC3C;wBAED,sBAAO;gCACL,YAAY,EAAE,kBAAkB;gCAChC,MAAM,EAAE;oCACN,IAAI,EAAE,IAAI,GAAG,CAAC;iCACf;6BACF,EAAA;;;;KACF;IACH,0BAAC;AAAD,CAAC,AA/FD,CAAyC,uCAAkB,GA+F1D;AA/FY,kDAAmB"}
package/v1/index.d.ts CHANGED
@@ -1,11 +1,23 @@
1
1
  import { EtherscanBlockExplorer } from './block-explorer/EtherscanBlockExplorer';
2
+ import { EthereumInfoClient } from './clients/info/EthereumInfoClient';
3
+ import { EtherscanInfoClient } from './clients/info/EtherscanInfoClient';
4
+ import { AirGapNodeClient } from './clients/node/AirGapNodeClient';
5
+ import { EthereumNodeClient } from './clients/node/EthereumNodeClient';
2
6
  import { EthereumModule } from './module/EthereumModule';
7
+ import { ERC20Protocol, ERC20ProtocolImpl } from './protocol/erc20/ERC20Protocol';
3
8
  import { createERC20Token, ERC20Token } from './protocol/erc20/ERC20Token';
4
9
  import { createEthereumProtocol, createEthereumProtocolOptions, EthereumProtocol } from './protocol/EthereumProtocol';
10
+ import { ethereumSignedTransactionToResponse, ethereumTransactionSignRequestToUnsigned, ethereumTransactionSignResponseToSigned, ethereumUnsignedTransactionToRequest } from './serializer/v3/schemas/converter/transaction-converter';
11
+ import { EthereumTransactionSignRequest } from './serializer/v3/schemas/definitions/transaction-sign-request-ethereum';
12
+ import { EthereumTypedTransactionSignRequest } from './serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed';
13
+ import { EthereumTransactionSignResponse } from './serializer/v3/schemas/definitions/transaction-sign-response-ethereum';
14
+ import { EthereumTransactionValidator } from './serializer/v3/validators/transaction-validator';
5
15
  import { EthereumCryptoConfiguration } from './types/crypto';
6
16
  import { ERC20TokenMetadata, EthereumProtocolNetwork, EthereumProtocolOptions, EthereumUnits } from './types/protocol';
7
17
  import { EthereumRawUnsignedTransaction, EthereumSignedTransaction, EthereumTransactionCursor, EthereumTypedUnsignedTransaction, EthereumUnsignedTransaction } from './types/transaction';
8
18
  export { EthereumModule };
9
- export { EthereumProtocol, createEthereumProtocol, createEthereumProtocolOptions, ERC20Token, createERC20Token };
19
+ export { EthereumProtocol, createEthereumProtocol, createEthereumProtocolOptions, ERC20Protocol, ERC20ProtocolImpl, ERC20Token, createERC20Token };
10
20
  export { EtherscanBlockExplorer };
21
+ export { EthereumNodeClient, AirGapNodeClient, EthereumInfoClient, EtherscanInfoClient };
11
22
  export { EthereumCryptoConfiguration, EthereumUnits, EthereumProtocolNetwork, EthereumProtocolOptions, ERC20TokenMetadata, EthereumUnsignedTransaction, EthereumTypedUnsignedTransaction, EthereumRawUnsignedTransaction, EthereumSignedTransaction, EthereumTransactionCursor };
23
+ export { EthereumTransactionSignRequest, EthereumTypedTransactionSignRequest, EthereumTransactionSignResponse, ethereumUnsignedTransactionToRequest, ethereumSignedTransactionToResponse, ethereumTransactionSignRequestToUnsigned, ethereumTransactionSignResponseToSigned, EthereumTransactionValidator };
package/v1/index.js CHANGED
@@ -1,13 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EtherscanBlockExplorer = exports.createERC20Token = exports.createEthereumProtocolOptions = exports.createEthereumProtocol = exports.EthereumModule = void 0;
3
+ exports.EthereumTransactionValidator = exports.ethereumTransactionSignResponseToSigned = exports.ethereumTransactionSignRequestToUnsigned = exports.ethereumSignedTransactionToResponse = exports.ethereumUnsignedTransactionToRequest = exports.EtherscanInfoClient = exports.EthereumInfoClient = exports.AirGapNodeClient = exports.EthereumNodeClient = exports.EtherscanBlockExplorer = exports.createERC20Token = exports.ERC20ProtocolImpl = exports.createEthereumProtocolOptions = exports.createEthereumProtocol = exports.EthereumModule = void 0;
4
4
  var EtherscanBlockExplorer_1 = require("./block-explorer/EtherscanBlockExplorer");
5
5
  Object.defineProperty(exports, "EtherscanBlockExplorer", { enumerable: true, get: function () { return EtherscanBlockExplorer_1.EtherscanBlockExplorer; } });
6
+ var EthereumInfoClient_1 = require("./clients/info/EthereumInfoClient");
7
+ Object.defineProperty(exports, "EthereumInfoClient", { enumerable: true, get: function () { return EthereumInfoClient_1.EthereumInfoClient; } });
8
+ var EtherscanInfoClient_1 = require("./clients/info/EtherscanInfoClient");
9
+ Object.defineProperty(exports, "EtherscanInfoClient", { enumerable: true, get: function () { return EtherscanInfoClient_1.EtherscanInfoClient; } });
10
+ var AirGapNodeClient_1 = require("./clients/node/AirGapNodeClient");
11
+ Object.defineProperty(exports, "AirGapNodeClient", { enumerable: true, get: function () { return AirGapNodeClient_1.AirGapNodeClient; } });
12
+ var EthereumNodeClient_1 = require("./clients/node/EthereumNodeClient");
13
+ Object.defineProperty(exports, "EthereumNodeClient", { enumerable: true, get: function () { return EthereumNodeClient_1.EthereumNodeClient; } });
6
14
  var EthereumModule_1 = require("./module/EthereumModule");
7
15
  Object.defineProperty(exports, "EthereumModule", { enumerable: true, get: function () { return EthereumModule_1.EthereumModule; } });
16
+ var ERC20Protocol_1 = require("./protocol/erc20/ERC20Protocol");
17
+ Object.defineProperty(exports, "ERC20ProtocolImpl", { enumerable: true, get: function () { return ERC20Protocol_1.ERC20ProtocolImpl; } });
8
18
  var ERC20Token_1 = require("./protocol/erc20/ERC20Token");
9
19
  Object.defineProperty(exports, "createERC20Token", { enumerable: true, get: function () { return ERC20Token_1.createERC20Token; } });
10
20
  var EthereumProtocol_1 = require("./protocol/EthereumProtocol");
11
21
  Object.defineProperty(exports, "createEthereumProtocol", { enumerable: true, get: function () { return EthereumProtocol_1.createEthereumProtocol; } });
12
22
  Object.defineProperty(exports, "createEthereumProtocolOptions", { enumerable: true, get: function () { return EthereumProtocol_1.createEthereumProtocolOptions; } });
23
+ var transaction_converter_1 = require("./serializer/v3/schemas/converter/transaction-converter");
24
+ Object.defineProperty(exports, "ethereumSignedTransactionToResponse", { enumerable: true, get: function () { return transaction_converter_1.ethereumSignedTransactionToResponse; } });
25
+ Object.defineProperty(exports, "ethereumTransactionSignRequestToUnsigned", { enumerable: true, get: function () { return transaction_converter_1.ethereumTransactionSignRequestToUnsigned; } });
26
+ Object.defineProperty(exports, "ethereumTransactionSignResponseToSigned", { enumerable: true, get: function () { return transaction_converter_1.ethereumTransactionSignResponseToSigned; } });
27
+ Object.defineProperty(exports, "ethereumUnsignedTransactionToRequest", { enumerable: true, get: function () { return transaction_converter_1.ethereumUnsignedTransactionToRequest; } });
28
+ var transaction_validator_1 = require("./serializer/v3/validators/transaction-validator");
29
+ Object.defineProperty(exports, "EthereumTransactionValidator", { enumerable: true, get: function () { return transaction_validator_1.EthereumTransactionValidator; } });
13
30
  //# sourceMappingURL=index.js.map
package/v1/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,kFAAgF;AAwBvE,uGAxBA,+CAAsB,OAwBA;AAvB/B,0DAAwD;AAe/C,+FAfA,+BAAc,OAeA;AAdvB,0DAA0E;AAkBoB,iGAlBrF,6BAAgB,OAkBqF;AAjB9G,gEAAqH;AAiB1F,uGAjBlB,yCAAsB,OAiBkB;AAAE,8GAjBlB,gDAA6B,OAiBkB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/v1/index.ts"],"names":[],"mappings":";;;AAAA,kFAAgF;AA+CvE,uGA/CA,+CAAsB,OA+CA;AA9C/B,wEAAsE;AAkDvB,mGAlDtC,uCAAkB,OAkDsC;AAjDjE,0EAAwE;AAiDL,oGAjD1D,yCAAmB,OAiD0D;AAhDtF,oEAAkE;AAgDrC,iGAhDpB,mCAAgB,OAgDoB;AA/C7C,wEAAsE;AA+C7D,mGA/CA,uCAAkB,OA+CA;AA9C3B,0DAAwD;AA0B/C,+FA1BA,+BAAc,OA0BA;AAzBvB,gEAAiF;AAkC/E,kGAlCsB,iCAAiB,OAkCtB;AAjCnB,0DAA0E;AAmCxE,iGAnCO,6BAAgB,OAmCP;AAlClB,gEAAqH;AA6BnH,uGA7BO,yCAAsB,OA6BP;AACtB,8GA9B+B,gDAA6B,OA8B/B;AA7B/B,iGAKgE;AA6D9D,oHAjEA,2DAAmC,OAiEA;AACnC,yHAjEA,gEAAwC,OAiEA;AACxC,wHAjEA,+DAAuC,OAiEA;AAHvC,qHA7DA,4DAAoC,OA6DA;AAxDtC,0FAA+F;AA4D7F,6GA5DO,oDAA4B,OA4DP"}
@@ -36,7 +36,7 @@ var EthereumProtocolImpl = /** @class */ (function (_super) {
36
36
  function EthereumProtocolImpl(options) {
37
37
  if (options === void 0) { options = {}; }
38
38
  var completeOptions = createEthereumProtocolOptions(options.network);
39
- return _super.call(this, new AirGapNodeClient_1.AirGapNodeClient(completeOptions.network.rpcUrl), new EtherscanInfoClient_1.EtherscanInfoClient(completeOptions.network.blockExplorerApi), completeOptions) || this;
39
+ return _super.call(this, new AirGapNodeClient_1.AirGapNodeClient(completeOptions.network.rpcUrl), new EtherscanInfoClient_1.EtherscanInfoClient(completeOptions.network.blockExplorerApi, completeOptions.network.blockExplorerApiKey), completeOptions) || this;
40
40
  }
41
41
  return EthereumProtocolImpl;
42
42
  }(EthereumBaseProtocol_1.DefaultEthereumBaseProtocolImpl));
@@ -51,7 +51,8 @@ exports.ETHEREUM_MAINNET_PROTOCOL_NETWORK = {
51
51
  type: 'mainnet',
52
52
  rpcUrl: 'https://eth-rpc-proxy.airgap.prod.gke.papers.tech',
53
53
  chainId: 1,
54
- blockExplorerApi: 'https://api.etherscan.io'
54
+ blockExplorerApi: 'https://api.etherscan.io',
55
+ blockExplorerApiKey: 'P63MEHEYBM5BGEG5WFN76VPNCET8B2MAP7'
55
56
  };
56
57
  var DEFAULT_ETHEREUM_PROTOCOL_NETWORK = exports.ETHEREUM_MAINNET_PROTOCOL_NETWORK;
57
58
  function createEthereumProtocolOptions(network) {
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumProtocol.js","sourceRoot":"","sources":["../../../src/v1/protocol/EthereumProtocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,2EAAyE;AACzE,qEAAmE;AAGnE,+DAA8F;AAO9F,iBAAiB;AAEjB;IAAmC,wCAA+B;IAChE,8BAAmB,OAAuD;QAAvD,wBAAA,EAAA,YAAuD;QACxE,IAAM,eAAe,GAA4B,6BAA6B,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;eAE/F,kBACE,IAAI,mCAAgB,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EACpD,IAAI,yCAAmB,CAAC,eAAe,CAAC,OAAO,CAAC,gBAAgB,CAAC,EACjE,eAAe,CAChB;IACH,CAAC;IACH,2BAAC;AAAD,CAAC,AAVD,CAAmC,sDAA+B,GAUjE;AAED,UAAU;AAEV,SAAgB,sBAAsB,CAAC,OAAuD;IAAvD,wBAAA,EAAA,YAAuD;IAC5F,OAAO,IAAI,oBAAoB,CAAC,OAAO,CAAC,CAAA;AAC1C,CAAC;AAFD,wDAEC;AAEY,QAAA,iCAAiC,GAA4B;IACxE,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,mDAAmD;IAC3D,OAAO,EAAE,CAAC;IACV,gBAAgB,EAAE,0BAA0B;CAC7C,CAAA;AAED,IAAM,iCAAiC,GAA4B,yCAAiC,CAAA;AAEpG,SAAgB,6BAA6B,CAAC,OAA8C;IAA9C,wBAAA,EAAA,YAA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@@ -0,0 +1,26 @@
1
+ import BigNumber from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
2
+ import { AirGapTransaction, AirGapTransactionsWithCursor, Amount, Balance, PublicKey, SecretKey, TransactionConfiguration, TransactionDetails } from '@airgap/module-kit';
3
+ import { EthereumInfoClient } from '../../clients/info/EthereumInfoClient';
4
+ import { EthereumNodeClient } from '../../clients/node/EthereumNodeClient';
5
+ import { ERC20ProtocolOptions, EthereumUnits } from '../../types/protocol';
6
+ import { EthereumSignedTransaction, EthereumTransactionCursor, EthereumUnsignedTransaction } from '../../types/transaction';
7
+ import { EthereumBaseProtocol, EthereumBaseProtocolImpl } from '../EthereumBaseProtocol';
8
+ export interface ERC20Protocol<_Units extends string> extends EthereumBaseProtocol<_Units> {
9
+ }
10
+ export declare abstract class ERC20ProtocolImpl<_Units extends string> extends EthereumBaseProtocolImpl<_Units> implements ERC20Protocol<_Units> {
11
+ protected readonly contractAddress: string;
12
+ constructor(nodeClient: EthereumNodeClient, infoClient: EthereumInfoClient, options: ERC20ProtocolOptions<_Units>);
13
+ getDetailsFromTransaction(transaction: EthereumSignedTransaction | EthereumUnsignedTransaction, publicKey: PublicKey): Promise<AirGapTransaction<_Units, EthereumUnits>[]>;
14
+ private getDetailsFromSignedContractTransaction;
15
+ private getDetailsFromUnsignedContractTransaction;
16
+ signTransactionWithSecretKey(transaction: EthereumUnsignedTransaction, secretKey: SecretKey): Promise<EthereumSignedTransaction>;
17
+ getTransactionsForPublicKey(publicKey: PublicKey, limit: number, cursor?: EthereumTransactionCursor): Promise<AirGapTransactionsWithCursor<EthereumTransactionCursor, _Units, EthereumUnits>>;
18
+ getTransactionsForAddress(address: string, limit: number, cursor?: EthereumTransactionCursor): Promise<AirGapTransactionsWithCursor<EthereumTransactionCursor, _Units, EthereumUnits>>;
19
+ getTransactionsForAddresses(addresses: string[], limit: number, cursor?: EthereumTransactionCursor): Promise<AirGapTransactionsWithCursor<EthereumTransactionCursor, _Units, EthereumUnits>>;
20
+ getBalanceOfPublicKey(publicKey: PublicKey): Promise<Balance<_Units>>;
21
+ getBalanceOfAddress(address: string): Promise<Balance<_Units>>;
22
+ getBalanceOfAddresses(addresses: string[]): Promise<Balance<_Units>>;
23
+ getTransactionMaxAmountWithPublicKey(publicKey: PublicKey, to: string[], configuration?: TransactionConfiguration<EthereumUnits>): Promise<Amount<_Units>>;
24
+ prepareTransactionWithPublicKey(publicKey: PublicKey, details: TransactionDetails<_Units>[], configuration?: TransactionConfiguration<EthereumUnits>): Promise<EthereumUnsignedTransaction>;
25
+ protected estimateGas(fromAddress: string, toAddress: string, amount: string | number | BigNumber | Amount, _data?: string): Promise<BigNumber>;
26
+ }
@@ -0,0 +1,376 @@
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("@airgap/coinlib-core");
93
+ var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
94
+ // @ts-ignore
95
+ var ethUtil = __importStar(require("@airgap/coinlib-core/dependencies/src/ethereumjs-util-5.2.0"));
96
+ var errors_1 = require("@airgap/coinlib-core/errors");
97
+ var hex_1 = require("@airgap/coinlib-core/utils/hex");
98
+ var module_kit_1 = require("@airgap/module-kit");
99
+ var tx_1 = require("@ethereumjs/tx");
100
+ var AirGapNodeClient_1 = require("../../clients/node/AirGapNodeClient");
101
+ var EthereumUtils_1 = require("../../utils/EthereumUtils");
102
+ var EthereumBaseProtocol_1 = require("../EthereumBaseProtocol");
103
+ var EthereumTransaction = require('@airgap/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 AirGapNodeClient_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 AirGapNodeClient_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 AirGapNodeClient_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.getBalanceOfAddress.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 AirGapNodeClient_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.estimateGas = function (fromAddress, toAddress, amount, _data) {
359
+ return __awaiter(this, void 0, void 0, function () {
360
+ var hexAmount, blockchainAmount;
361
+ return __generator(this, function (_a) {
362
+ if (typeof amount === 'string' && (0, hex_1.isHex)(amount)) {
363
+ hexAmount = amount;
364
+ }
365
+ else {
366
+ blockchainAmount = (0, module_kit_1.isAmount)(amount) ? (0, module_kit_1.newAmount)(amount).blockchain(this.units) : (0, module_kit_1.newAmount)(amount, 'blockchain');
367
+ hexAmount = EthereumUtils_1.EthereumUtils.toHex(blockchainAmount.value);
368
+ }
369
+ return [2 /*return*/, this.nodeClient.estimateTransferGas(this.contractAddress, fromAddress, toAddress, hexAmount)];
370
+ });
371
+ });
372
+ };
373
+ return ERC20ProtocolImpl;
374
+ }(EthereumBaseProtocol_1.EthereumBaseProtocolImpl));
375
+ exports.ERC20ProtocolImpl = ERC20ProtocolImpl;
376
+ //# sourceMappingURL=ERC20Protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ERC20Protocol.js","sourceRoot":"","sources":["../../../../src/v1/protocol/erc20/ERC20Protocol.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA0D;AAC1D,iHAA0F;AAC1F,aAAa;AACb,mGAAsF;AACtF,sDAAqG;AACrG,sDAAsD;AACtD,iDAa2B;AAC3B,qCAAgF;AAGhF,wEAA6E;AAS7E,2DAAyD;AACzD,gEAAwF;AAExF,IAAM,mBAAmB,GAAG,OAAO,CAAC,iEAAiE,CAAC,CAAA;AAMtG,iBAAiB;AAEjB;IAAuE,qCAAgC;IAGrG,2BAAmB,UAA8B,EAAE,UAA8B,EAAE,OAAqC;QAAxH,YACE,kBAAM,UAAU,EAAE,UAAU,EAAE;YAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;YAExB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,UAAU,EAAE,OAAO,CAAC,UAAU;YAE9B,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC,SAEH;QADC,KAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,CAAA;;IAChD,CAAC;IAED,SAAS;IAEI,qDAAyB,GAAtC,UACE,WAAoE,EACpE,SAAoB;;;;;4BAEs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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,AAhRD,CAAuE,+CAAwB,GAgR9F;AAhRqB,8CAAiB"}
@@ -1,7 +1,7 @@
1
1
  import { AirGapInterface } from '@airgap/module-kit';
2
2
  import { ERC20TokenMetadata, EthereumProtocolNetwork, EthereumProtocolOptions } from '../../types/protocol';
3
- import { EthereumBaseProtocol } from '../EthereumBaseProtocol';
4
- export interface ERC20Token extends AirGapInterface<EthereumBaseProtocol<string>, 'SingleTokenSubProtocol'> {
3
+ import { ERC20Protocol } from './ERC20Protocol';
4
+ export interface ERC20Token extends AirGapInterface<ERC20Protocol<string>, 'SingleTokenSubProtocol'> {
5
5
  }
6
6
  export declare function createERC20Token(metadata: ERC20TokenMetadata): ERC20Token;
7
7
  export declare const ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK: EthereumProtocolNetwork;
@@ -25,29 +25,6 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
- if (k2 === undefined) k2 = k;
30
- var desc = Object.getOwnPropertyDescriptor(m, k);
31
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
- desc = { enumerable: true, get: function() { return m[k]; } };
33
- }
34
- Object.defineProperty(o, k2, desc);
35
- }) : (function(o, m, k, k2) {
36
- if (k2 === undefined) k2 = k;
37
- o[k2] = m[k];
38
- }));
39
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
- Object.defineProperty(o, "default", { enumerable: true, value: v });
41
- }) : function(o, v) {
42
- o["default"] = v;
43
- });
44
- var __importStar = (this && this.__importStar) || function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
- __setModuleDefault(result, mod);
49
- return result;
50
- };
51
28
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
52
29
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
53
30
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -84,38 +61,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
84
61
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
85
62
  }
86
63
  };
87
- var __importDefault = (this && this.__importDefault) || function (mod) {
88
- return (mod && mod.__esModule) ? mod : { "default": mod };
89
- };
90
64
  Object.defineProperty(exports, "__esModule", { value: true });
91
65
  exports.createERC20TokenOptions = exports.ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK = exports.createERC20Token = void 0;
92
66
  var coinlib_core_1 = require("@airgap/coinlib-core");
93
- var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
94
- // @ts-ignore
95
- var ethUtil = __importStar(require("@airgap/coinlib-core/dependencies/src/ethereumjs-util-5.2.0"));
96
- var errors_1 = require("@airgap/coinlib-core/errors");
97
- var hex_1 = require("@airgap/coinlib-core/utils/hex");
98
- var module_kit_1 = require("@airgap/module-kit");
99
- var tx_1 = require("@ethereumjs/tx");
100
67
  var EtherscanInfoClient_1 = require("../../clients/info/EtherscanInfoClient");
101
68
  var AirGapNodeClient_1 = require("../../clients/node/AirGapNodeClient");
102
- var EthereumUtils_1 = require("../../utils/EthereumUtils");
103
- var EthereumBaseProtocol_1 = require("../EthereumBaseProtocol");
104
69
  var EthereumProtocol_1 = require("../EthereumProtocol");
105
- var EthereumTransaction = require('@airgap/coinlib-core/dependencies/src/ethereumjs-tx-1.3.7/index');
70
+ var ERC20Protocol_1 = require("./ERC20Protocol");
106
71
  // Implementation
107
72
  var ERC20TokenImpl = /** @class */ (function (_super) {
108
73
  __extends(ERC20TokenImpl, _super);
109
- function ERC20TokenImpl(nodeClient, infoClient, options) {
110
- var _this = _super.call(this, nodeClient, infoClient, {
111
- network: options.network,
112
- name: options.name,
113
- identifier: options.identifier,
114
- units: options.units,
115
- mainUnit: options.mainUnit
116
- }) || this;
117
- _this.contractAddress = options.contractAddress;
118
- return _this;
74
+ function ERC20TokenImpl() {
75
+ return _super !== null && _super.apply(this, arguments) || this;
119
76
  }
120
77
  // SubProtocol
121
78
  ERC20TokenImpl.prototype.getType = function () {
@@ -139,263 +96,8 @@ var ERC20TokenImpl = /** @class */ (function (_super) {
139
96
  });
140
97
  });
141
98
  };
142
- // Common
143
- ERC20TokenImpl.prototype.getDetailsFromTransaction = function (transaction, publicKey) {
144
- return __awaiter(this, void 0, void 0, function () {
145
- var ethTransactionDetails;
146
- return __generator(this, function (_a) {
147
- switch (_a.label) {
148
- case 0: return [4 /*yield*/, _super.prototype.getDetailsFromTransaction.call(this, transaction, publicKey)];
149
- case 1:
150
- ethTransactionDetails = _a.sent();
151
- switch (transaction.type) {
152
- case 'signed':
153
- return [2 /*return*/, this.getDetailsFromSignedContractTransaction(transaction, ethTransactionDetails)];
154
- case 'unsigned':
155
- return [2 /*return*/, this.getDetailsFromUnsignedContractTransaction(transaction, ethTransactionDetails)];
156
- default:
157
- (0, coinlib_core_1.assertNever)(transaction);
158
- throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unsupported transaction type.');
159
- }
160
- return [2 /*return*/];
161
- }
162
- });
163
- });
164
- };
165
- ERC20TokenImpl.prototype.getDetailsFromSignedContractTransaction = function (transaction, ethTransactionDetails) {
166
- return __awaiter(this, void 0, void 0, function () {
167
- var extractedTx, tokenTransferDetails;
168
- return __generator(this, function (_a) {
169
- if (ethTransactionDetails.length !== 1) {
170
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ERC20, 'More than one ETH transaction detected.');
171
- }
172
- extractedTx = new EthereumTransaction(transaction.serialized);
173
- tokenTransferDetails = new AirGapNodeClient_1.EthereumRPCDataTransfer("0x".concat(extractedTx.data.toString('hex')));
174
- return [2 /*return*/, [
175
- __assign(__assign({}, ethTransactionDetails[0]), { to: [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)], amount: (0, module_kit_1.newAmount)(tokenTransferDetails.amount, 'blockchain') })
176
- ]];
177
- });
178
- });
179
- };
180
- ERC20TokenImpl.prototype.getDetailsFromUnsignedContractTransaction = function (transaction, ethTransactionDetails) {
181
- return __awaiter(this, void 0, void 0, function () {
182
- var data, typedTransaction, tokenTransferDetails;
183
- return __generator(this, function (_a) {
184
- if (ethTransactionDetails.length !== 1) {
185
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ERC20, 'More than one ETH transaction detected.');
186
- }
187
- if (transaction.ethereumType === 'raw') {
188
- data = transaction.data;
189
- }
190
- else {
191
- typedTransaction = tx_1.TransactionFactory.fromSerializedData(Buffer.from(transaction.serialized, 'hex'));
192
- data = typedTransaction.data.toString('hex');
193
- }
194
- tokenTransferDetails = new AirGapNodeClient_1.EthereumRPCDataTransfer(data);
195
- return [2 /*return*/, [
196
- __assign(__assign({}, ethTransactionDetails[0]), { to: [ethUtil.toChecksumAddress(tokenTransferDetails.recipient)], amount: (0, module_kit_1.newAmount)(tokenTransferDetails.amount, 'blockchain') })
197
- ]];
198
- });
199
- });
200
- };
201
- // Offline
202
- ERC20TokenImpl.prototype.signTransactionWithSecretKey = function (transaction, secretKey) {
203
- return __awaiter(this, void 0, void 0, function () {
204
- var rawTransaction;
205
- return __generator(this, function (_a) {
206
- if (transaction.ethereumType !== 'raw') {
207
- // no v0 implementation
208
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ERC20, 'Unsupported unsigned transaction type.');
209
- }
210
- rawTransaction = __assign(__assign({}, transaction), { data: !transaction.data || transaction.data === '0x'
211
- ? new AirGapNodeClient_1.EthereumRPCDataTransfer(transaction.to, transaction.value).abiEncoded()
212
- : transaction.data });
213
- return [2 /*return*/, _super.prototype.signTransactionWithSecretKey.call(this, rawTransaction, secretKey)];
214
- });
215
- });
216
- };
217
- // Online
218
- ERC20TokenImpl.prototype.getTransactionsForPublicKey = function (publicKey, limit, cursor) {
219
- return __awaiter(this, void 0, void 0, function () {
220
- var address;
221
- return __generator(this, function (_a) {
222
- switch (_a.label) {
223
- case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
224
- case 1:
225
- address = _a.sent();
226
- return [2 /*return*/, this.getTransactionsForAddress(address, limit, cursor)];
227
- }
228
- });
229
- });
230
- };
231
- ERC20TokenImpl.prototype.getTransactionsForAddress = function (address, limit, cursor) {
232
- return __awaiter(this, void 0, void 0, function () {
233
- return __generator(this, function (_a) {
234
- return [2 /*return*/, this.getTransactionsForAddresses([address], limit, cursor)];
235
- });
236
- });
237
- };
238
- ERC20TokenImpl.prototype.getTransactionsForAddresses = function (addresses, limit, cursor) {
239
- return __awaiter(this, void 0, void 0, function () {
240
- var _this = this;
241
- return __generator(this, function (_a) {
242
- return [2 /*return*/, new Promise(function (overallResolve, overallReject) {
243
- var promises = [];
244
- for (var _i = 0, addresses_1 = addresses; _i < addresses_1.length; _i++) {
245
- var address = addresses_1[_i];
246
- promises.push(_this.infoClient.fetchContractTransactions(_this.contractAddress, address, limit, cursor));
247
- }
248
- Promise.all(promises)
249
- .then(function (values) {
250
- var page = Math.max.apply(Math, values.map(function (txResult) { return txResult.cursor.page; }));
251
- var transactions = values.reduce(function (acc, current) {
252
- 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 })); }));
253
- }, []);
254
- var hasNext = transactions.length >= limit;
255
- overallResolve({
256
- transactions: transactions,
257
- cursor: {
258
- hasNext: hasNext,
259
- page: hasNext ? page : undefined
260
- }
261
- });
262
- })
263
- .catch(overallReject);
264
- })];
265
- });
266
- });
267
- };
268
- ERC20TokenImpl.prototype.getBalanceOfPublicKey = function (publicKey) {
269
- return __awaiter(this, void 0, void 0, function () {
270
- var address;
271
- return __generator(this, function (_a) {
272
- switch (_a.label) {
273
- case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
274
- case 1:
275
- address = _a.sent();
276
- return [2 /*return*/, this.getBalanceOfAddress(address)];
277
- }
278
- });
279
- });
280
- };
281
- ERC20TokenImpl.prototype.getBalanceOfAddress = function (address) {
282
- return __awaiter(this, void 0, void 0, function () {
283
- return __generator(this, function (_a) {
284
- return [2 /*return*/, this.getBalanceOfAddresses([address])];
285
- });
286
- });
287
- };
288
- ERC20TokenImpl.prototype.getBalanceOfAddresses = function (addresses) {
289
- return __awaiter(this, void 0, void 0, function () {
290
- var balances, totalBalance;
291
- var _this = this;
292
- return __generator(this, function (_a) {
293
- switch (_a.label) {
294
- case 0: return [4 /*yield*/, Promise.all(addresses.map(function (address) {
295
- return _this.nodeClient.callBalanceOf(_this.contractAddress, address);
296
- }))];
297
- case 1:
298
- balances = _a.sent();
299
- totalBalance = balances.reduce(function (a, b) { return a.plus(b); });
300
- return [2 /*return*/, { total: (0, module_kit_1.newAmount)(totalBalance, 'blockchain') }];
301
- }
302
- });
303
- });
304
- };
305
- ERC20TokenImpl.prototype.getTransactionMaxAmountWithPublicKey = function (publicKey, to, configuration) {
306
- var _a;
307
- return __awaiter(this, void 0, void 0, function () {
308
- var balance;
309
- return __generator(this, function (_b) {
310
- switch (_b.label) {
311
- case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
312
- case 1:
313
- balance = _b.sent();
314
- return [2 /*return*/, (_a = balance.transferable) !== null && _a !== void 0 ? _a : balance.total];
315
- }
316
- });
317
- });
318
- };
319
- ERC20TokenImpl.prototype.prepareTransactionWithPublicKey = function (publicKey, details, configuration) {
320
- var _a;
321
- return __awaiter(this, void 0, void 0, function () {
322
- var fee, estimatedFee, wrappedFee, wrappedAmount, balance, wrappedBalance, address, ethBalance, wrappedEthBalance, estimatedGas, txCount, gasPrice, transaction;
323
- return __generator(this, function (_b) {
324
- switch (_b.label) {
325
- case 0:
326
- if (details.length !== 1) {
327
- throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.ETHEREUM, 'you cannot have 0 transaction details');
328
- }
329
- if (!((configuration === null || configuration === void 0 ? void 0 : configuration.fee) !== undefined)) return [3 /*break*/, 1];
330
- fee = configuration.fee;
331
- return [3 /*break*/, 3];
332
- case 1: return [4 /*yield*/, this.getTransactionFeeWithPublicKey(publicKey, details)];
333
- case 2:
334
- estimatedFee = _b.sent();
335
- fee = estimatedFee.medium;
336
- _b.label = 3;
337
- case 3:
338
- wrappedFee = new bignumber_1.default((0, module_kit_1.newAmount)(fee).blockchain(this.feeUnits).value);
339
- wrappedAmount = new bignumber_1.default((0, module_kit_1.newAmount)(details[0].amount).blockchain(this.units).value);
340
- return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
341
- case 4:
342
- balance = _b.sent();
343
- wrappedBalance = new bignumber_1.default((0, module_kit_1.newAmount)((_a = balance.transferable) !== null && _a !== void 0 ? _a : balance.total).blockchain(this.units).value);
344
- if (!wrappedBalance.isGreaterThanOrEqualTo(wrappedAmount)) return [3 /*break*/, 11];
345
- return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
346
- case 5:
347
- address = _b.sent();
348
- return [4 /*yield*/, _super.prototype.getBalanceOfAddress.call(this, address)];
349
- case 6:
350
- ethBalance = _b.sent();
351
- wrappedEthBalance = new bignumber_1.default((0, module_kit_1.newAmount)(ethBalance.total).blockchain(this.units).value);
352
- return [4 /*yield*/, this.estimateGas(address, details[0].to, wrappedAmount)];
353
- case 7:
354
- estimatedGas = _b.sent();
355
- if (!wrappedEthBalance.isGreaterThanOrEqualTo(wrappedFee)) return [3 /*break*/, 9];
356
- return [4 /*yield*/, this.nodeClient.fetchTransactionCount(address)];
357
- case 8:
358
- txCount = _b.sent();
359
- gasPrice = wrappedFee.isEqualTo(0)
360
- ? new bignumber_1.default(0)
361
- : wrappedFee.div(estimatedGas).integerValue(bignumber_1.default.ROUND_CEIL);
362
- transaction = (0, module_kit_1.newUnsignedTransaction)({
363
- ethereumType: 'raw',
364
- nonce: EthereumUtils_1.EthereumUtils.toHex(txCount),
365
- gasLimit: EthereumUtils_1.EthereumUtils.toHex(estimatedGas.toFixed()),
366
- gasPrice: EthereumUtils_1.EthereumUtils.toHex(gasPrice.toFixed()),
367
- to: this.contractAddress,
368
- value: EthereumUtils_1.EthereumUtils.toHex(new bignumber_1.default(0).toFixed()),
369
- chainId: this.options.network.chainId,
370
- data: new AirGapNodeClient_1.EthereumRPCDataTransfer(details[0].to, EthereumUtils_1.EthereumUtils.toHex(wrappedAmount.toFixed())).abiEncoded()
371
- });
372
- return [2 /*return*/, transaction];
373
- case 9: throw new errors_1.BalanceError(coinlib_core_1.Domain.ERC20, 'not enough ETH balance');
374
- case 10: return [3 /*break*/, 12];
375
- case 11: throw new errors_1.BalanceError(coinlib_core_1.Domain.ERC20, 'not enough token balance');
376
- case 12: return [2 /*return*/];
377
- }
378
- });
379
- });
380
- };
381
- // Custom
382
- ERC20TokenImpl.prototype.estimateGas = function (fromAddress, toAddress, amount, _data) {
383
- return __awaiter(this, void 0, void 0, function () {
384
- var hexAmount, blockchainAmount;
385
- return __generator(this, function (_a) {
386
- if (typeof amount === 'string' && (0, hex_1.isHex)(amount)) {
387
- hexAmount = amount;
388
- }
389
- else {
390
- blockchainAmount = (0, module_kit_1.isAmount)(amount) ? (0, module_kit_1.newAmount)(amount).blockchain(this.units) : (0, module_kit_1.newAmount)(amount, 'blockchain');
391
- hexAmount = EthereumUtils_1.EthereumUtils.toHex(blockchainAmount.value);
392
- }
393
- return [2 /*return*/, this.nodeClient.estimateTransferGas(this.contractAddress, fromAddress, toAddress, hexAmount)];
394
- });
395
- });
396
- };
397
99
  return ERC20TokenImpl;
398
- }(EthereumBaseProtocol_1.EthereumBaseProtocolImpl));
100
+ }(ERC20Protocol_1.ERC20ProtocolImpl));
399
101
  // Factory
400
102
  function createERC20Token(metadata) {
401
103
  var _a;
@@ -406,7 +108,7 @@ function createERC20Token(metadata) {
406
108
  decimals: metadata.decimals
407
109
  },
408
110
  _a), mainUnit: metadata.symbol });
409
- return new ERC20TokenImpl(new AirGapNodeClient_1.AirGapNodeClient(protocolOptions.network.rpcUrl), new EtherscanInfoClient_1.EtherscanInfoClient(protocolOptions.network.blockExplorerApi), tokenOptions);
111
+ return new ERC20TokenImpl(new AirGapNodeClient_1.AirGapNodeClient(protocolOptions.network.rpcUrl), new EtherscanInfoClient_1.EtherscanInfoClient(protocolOptions.network.blockExplorerApi, protocolOptions.network.blockExplorerApiKey), tokenOptions);
410
112
  }
411
113
  exports.createERC20Token = createERC20Token;
412
114
  exports.ETHEREUM_ERC20_MAINNET_PROTOCOL_NETWORK = __assign(__assign({}, EthereumProtocol_1.ETHEREUM_MAINNET_PROTOCOL_NETWORK), { chainId: 3 });
@@ -1 +1 @@
1
- {"version":3,"file":"ERC20Token.js","sourceRoot":"","sources":["../../../../src/v1/protocol/erc20/ERC20Token.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA+E;AAC/E,iHAA0F;AAC1F,aAAa;AACb,mGAAsF;AACtF,sDAAqG;AACrG,sDAAsD;AACtD,iDAc2B;AAC3B,qCAAgF;AAGhF,8EAA4E;AAC5E,wEAA+F;AAe/F,2DAAyD;AACzD,gEAAwF;AACxF,wDAAuE;AAEvE,IAAM,mBAAmB,GAAG,OAAO,CAAC,iEAAiE,CAAC,CAAA;AAMtG,iBAAiB;AAEjB;IAA6B,kCAAgC;IAG3D,wBAAmB,UAA8B,EAAE,UAA8B,EAAE,OAA0B;QAA7G,YACE,kBAAM,U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b,eAAe,KAClB,IAAI,EAAE,QAAQ,CAAC,IAAI,EACnB,UAAU,EAAE,QAAQ,CAAC,UAAU,EAE/B,eAAe,EAAE,QAAQ,CAAC,eAAe,EAEzC,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;iBAEH,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAC1B,CAAA;IAED,OAAO,IAAI,cAAc,CACvB,IAAI,mCAAgB,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EACpD,IAAI,yCAAmB,CAAC,eAAe,CAAC,OAAO,CAAC,gBAAgB,EAAE,eAAe,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAC9G,YAAY,CACb,CAAA;AACH,CAAC;AAvBD,4CAuBC;AAEY,QAAA,uCAAuC,yBAC/C,oDAAiC,KACpC,OAAO,EAAE,CAAC,IACX;AAED,IAAM,8BAA8B,GAA4B,+CAAuC,CAAA;AAEvG,SAAgB,uBAAuB,CAAC,OAA8C;IAA9C,wBAAA,EAAA,YAA8C;IACpF,OAAO;QACL,OAAO,wBAAO,8BAA8B,GAAK,OAAO,CAAE;KAC3D,CAAA;AACH,CAAC;AAJD,0DAIC"}
@@ -1,12 +1,8 @@
1
- import { EthereumRawUnsignedTransaction, EthereumSignedTransaction, EthereumTypedUnsignedTransaction, EthereumUnsignedTransaction } from '../../../../types/transaction';
1
+ import { EthereumSignedTransaction, EthereumUnsignedTransaction } from '../../../../types/transaction';
2
2
  import { EthereumTransactionSignRequest } from '../definitions/transaction-sign-request-ethereum';
3
3
  import { EthereumTypedTransactionSignRequest } from '../definitions/transaction-sign-request-ethereum-typed';
4
4
  import { EthereumTransactionSignResponse } from '../definitions/transaction-sign-response-ethereum';
5
5
  export declare function ethereumUnsignedTransactionToRequest(unsigned: EthereumUnsignedTransaction, publicKey: string, callbackUrl?: string): EthereumTransactionSignRequest | EthereumTypedTransactionSignRequest;
6
- export declare function ethereumRawUnsignedTransactionToRequest(unsigned: EthereumRawUnsignedTransaction, publicKey: string, callbackUrl?: string): EthereumTransactionSignRequest;
7
- export declare function ethereumTypedUnsignedTransactionToRequest(unsigned: EthereumTypedUnsignedTransaction, publicKey: string, callbackUrl?: string): EthereumTypedTransactionSignRequest;
8
6
  export declare function ethereumSignedTransactionToResponse(signed: EthereumSignedTransaction, accountIdentifier: string): EthereumTransactionSignResponse;
9
7
  export declare function ethereumTransactionSignRequestToUnsigned(request: EthereumTransactionSignRequest | EthereumTypedTransactionSignRequest): EthereumUnsignedTransaction;
10
- export declare function ethereumTransactionSignRequestToRawUnsigned(request: EthereumTransactionSignRequest): EthereumRawUnsignedTransaction;
11
- export declare function ethereumTransactionSignRequestToTypedUnsigned(request: EthereumTypedTransactionSignRequest): EthereumTypedUnsignedTransaction;
12
8
  export declare function ethereumTransactionSignResponseToSigned(response: EthereumTransactionSignResponse): EthereumSignedTransaction;
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  return t;
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.ethereumTransactionSignResponseToSigned = exports.ethereumTransactionSignRequestToTypedUnsigned = exports.ethereumTransactionSignRequestToRawUnsigned = exports.ethereumTransactionSignRequestToUnsigned = exports.ethereumSignedTransactionToResponse = exports.ethereumTypedUnsignedTransactionToRequest = exports.ethereumRawUnsignedTransactionToRequest = exports.ethereumUnsignedTransactionToRequest = void 0;
25
+ exports.ethereumTransactionSignResponseToSigned = exports.ethereumTransactionSignRequestToUnsigned = exports.ethereumSignedTransactionToResponse = exports.ethereumUnsignedTransactionToRequest = void 0;
26
26
  var module_kit_1 = require("@airgap/module-kit");
27
27
  function isEthereumTypedTransactionSignRequest(request) {
28
28
  return (0, module_kit_1.implementsInterface)(request.transaction, {
@@ -45,7 +45,6 @@ function ethereumRawUnsignedTransactionToRequest(unsigned, publicKey, callbackUr
45
45
  callbackURL: callbackUrl
46
46
  };
47
47
  }
48
- exports.ethereumRawUnsignedTransactionToRequest = ethereumRawUnsignedTransactionToRequest;
49
48
  function ethereumTypedUnsignedTransactionToRequest(unsigned, publicKey, callbackUrl) {
50
49
  var _ = unsigned.type, rest = __rest(unsigned, ["type"]);
51
50
  return {
@@ -54,7 +53,6 @@ function ethereumTypedUnsignedTransactionToRequest(unsigned, publicKey, callback
54
53
  callbackURL: callbackUrl
55
54
  };
56
55
  }
57
- exports.ethereumTypedUnsignedTransactionToRequest = ethereumTypedUnsignedTransactionToRequest;
58
56
  function ethereumSignedTransactionToResponse(signed, accountIdentifier) {
59
57
  return { transaction: signed.serialized, accountIdentifier: accountIdentifier };
60
58
  }
@@ -68,11 +66,9 @@ exports.ethereumTransactionSignRequestToUnsigned = ethereumTransactionSignReques
68
66
  function ethereumTransactionSignRequestToRawUnsigned(request) {
69
67
  return (0, module_kit_1.newUnsignedTransaction)(__assign({ ethereumType: 'raw' }, request.transaction));
70
68
  }
71
- exports.ethereumTransactionSignRequestToRawUnsigned = ethereumTransactionSignRequestToRawUnsigned;
72
69
  function ethereumTransactionSignRequestToTypedUnsigned(request) {
73
70
  return (0, module_kit_1.newUnsignedTransaction)(__assign({ ethereumType: 'typed' }, request.transaction));
74
71
  }
75
- exports.ethereumTransactionSignRequestToTypedUnsigned = ethereumTransactionSignRequestToTypedUnsigned;
76
72
  function ethereumTransactionSignResponseToSigned(response) {
77
73
  return (0, module_kit_1.newSignedTransaction)({ serialized: response.transaction });
78
74
  }
@@ -1 +1 @@
1
- {"version":3,"file":"transaction-converter.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/converter/transaction-converter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAsG;AAetG,SAAS,qCAAqC,CAC5C,OAA6E;IAE7E,OAAO,IAAA,gCAAmB,EA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,2CAA2C,CAAC,OAAO,CAAC,CAAA;AAC1D,CAAC;AAND,4FAMC;AAED,SAAgB,2CAA2C,CAAC,OAAuC;IACjG,OAAO,IAAA,mCAAsB,aAAmC,YAAY,EAAE,KAAK,IAAK,OAAO,CAAC,WAAW,EAAG,CAAA;AAChH,CAAC;AAFD,kGAEC;AAED,SAAgB,6CAA6C,CAC3D,OAA4C;IAE5C,OAAO,IAAA,mCAAsB,aAAqC,YAAY,EAAE,OAAO,IAAK,OAAO,CAAC,WAAW,EAAG,CAAA;AACpH,CAAC;AAJD,sGAIC;AAED,SAAgB,uCAAuC,CAAC,QAAyC;IAC/F,OAAO,IAAA,iCAAoB,EAA4B,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;AAC9F,CAAC;AAFD,0FAEC"}
1
+ {"version":3,"file":"transaction-converter.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/converter/transaction-converter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAsG;AAetG,SAAS,qCAAqC,CAC5C,OAA6E;IAE7E,OAAO,IAAA,gCAAmB,EAA+C,OAAO,CAAC,WAAW,EAAE;QAC5F,cAAc,EAAE,UAAU;QAC1B,iBAAiB,EAAE,UAAU;QAC7B,UAAU,EAAE,UAAU;KACvB,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,oCAAoC,CAClD,QAAqC,EACrC,SAAiB,EACjB,WAAoB;IAEpB,OAAO,QAAQ,CAAC,YAAY,KAAK,KAAK;QACpC,CAAC,CAAC,uCAAuC,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC;QAC3E,CAAC,CAAC,yCAAyC,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;AACjF,CAAC;AARD,oFAQC;AAED,SAAS,uCAAuC,CAC9C,QAAwC,EACxC,SAAiB,EACjB,WAAoB;IAEZ,IAAM,CAAC,GAAc,QAAQ,KAAtB,EAA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export interface EthereumProtocolNetwork extends ProtocolNetwork {
4
4
  chainId: number;
5
5
  blockExplorerApi: string;
6
+ blockExplorerApiKey: string;
6
7
  }
7
8
  export interface EthereumProtocolOptions {
8
9
  network: EthereumProtocolNetwork;
@@ -15,13 +16,14 @@ export interface EthereumBaseProtocolOptions<_Units extends string = EthereumUni
15
16
  feeDefaults?: FeeDefaults<EthereumUnits>;
16
17
  standardDerivationPath?: string;
17
18
  }
18
- export interface ERC20TokenOptions extends EthereumProtocolOptions {
19
+ export interface ERC20ProtocolOptions<_Units extends string> extends EthereumProtocolOptions {
19
20
  name: string;
20
21
  identifier: string;
21
22
  contractAddress: string;
22
- units: ProtocolUnitsMetadata<string>;
23
- mainUnit: string;
23
+ units: ProtocolUnitsMetadata<_Units>;
24
+ mainUnit: _Units;
24
25
  }
26
+ export declare type ERC20TokenOptions = ERC20ProtocolOptions<string>;
25
27
  export interface ERC20TokenMetadata {
26
28
  name: string;
27
29
  identifier: string;