@airgap/ethereum 0.13.11-beta.1 → 0.13.11-beta.10

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 (159) hide show
  1. package/index.d.ts +1 -0
  2. package/index.js +18 -0
  3. package/index.js.map +1 -0
  4. package/package.json +1 -5
  5. package/v0/index.d.ts +12 -0
  6. package/v0/index.js +39 -0
  7. package/v0/index.js.map +1 -0
  8. package/v0/protocol/BaseEthereumProtocol.d.ts +98 -0
  9. package/v0/protocol/BaseEthereumProtocol.js +939 -0
  10. package/v0/protocol/BaseEthereumProtocol.js.map +1 -0
  11. package/v0/protocol/EthereumAddress.d.ts +8 -0
  12. package/v0/protocol/EthereumAddress.js +43 -0
  13. package/v0/protocol/EthereumAddress.js.map +1 -0
  14. package/v0/protocol/EthereumChainIDs.d.ts +1 -0
  15. package/v0/protocol/EthereumChainIDs.js +340 -0
  16. package/v0/protocol/EthereumChainIDs.js.map +1 -0
  17. package/v0/protocol/EthereumClassicProtocol.d.ts +6 -0
  18. package/v0/protocol/EthereumClassicProtocol.js +30 -0
  19. package/v0/protocol/EthereumClassicProtocol.js.map +1 -0
  20. package/v0/protocol/EthereumCryptoClient.d.ts +12 -0
  21. package/v0/protocol/EthereumCryptoClient.js +148 -0
  22. package/v0/protocol/EthereumCryptoClient.js.map +1 -0
  23. package/v0/protocol/EthereumProtocol.d.ts +10 -0
  24. package/v0/protocol/EthereumProtocol.js +34 -0
  25. package/v0/protocol/EthereumProtocol.js.map +1 -0
  26. package/v0/protocol/EthereumProtocolOptions.d.ts +46 -0
  27. package/v0/protocol/EthereumProtocolOptions.js +150 -0
  28. package/v0/protocol/EthereumProtocolOptions.js.map +1 -0
  29. package/v0/protocol/EthereumRopstenProtocol.d.ts +6 -0
  30. package/v0/protocol/EthereumRopstenProtocol.js +30 -0
  31. package/v0/protocol/EthereumRopstenProtocol.js.map +1 -0
  32. package/v0/protocol/EthereumTypes.d.ts +14 -0
  33. package/v0/protocol/EthereumTypes.js +3 -0
  34. package/v0/protocol/EthereumTypes.js.map +1 -0
  35. package/v0/protocol/clients/info-clients/EtherscanInfoClient.d.ts +8 -0
  36. package/v0/protocol/clients/info-clients/EtherscanInfoClient.js +195 -0
  37. package/v0/protocol/clients/info-clients/EtherscanInfoClient.js.map +1 -0
  38. package/v0/protocol/clients/info-clients/InfoClient.d.ts +8 -0
  39. package/v0/protocol/clients/info-clients/InfoClient.js +11 -0
  40. package/v0/protocol/clients/info-clients/InfoClient.js.map +1 -0
  41. package/v0/protocol/clients/node-clients/AirGapNodeClient.d.ts +41 -0
  42. package/v0/protocol/clients/node-clients/AirGapNodeClient.js +353 -0
  43. package/v0/protocol/clients/node-clients/AirGapNodeClient.js.map +1 -0
  44. package/v0/protocol/clients/node-clients/NodeClient.d.ts +17 -0
  45. package/v0/protocol/clients/node-clients/NodeClient.js +11 -0
  46. package/v0/protocol/clients/node-clients/NodeClient.js.map +1 -0
  47. package/v0/protocol/erc20/ERC20.d.ts +3 -0
  48. package/v0/protocol/erc20/ERC20.js +9 -0
  49. package/v0/protocol/erc20/ERC20.js.map +1 -0
  50. package/v0/protocol/erc20/GenericERC20.d.ts +32 -0
  51. package/v0/protocol/erc20/GenericERC20.js +335 -0
  52. package/v0/protocol/erc20/GenericERC20.js.map +1 -0
  53. package/v0/protocol/utils/utils.d.ts +13 -0
  54. package/v0/protocol/utils/utils.js +140 -0
  55. package/v0/protocol/utils/utils.js.map +1 -0
  56. package/v0/serializer/schemas/v2/transaction-sign-request-ethereum.json +50 -0
  57. package/v0/serializer/schemas/v2/transaction-sign-response-ethereum.json +19 -0
  58. package/v0/serializer/schemas/v3/transaction-sign-request-ethereum-typed.json +38 -0
  59. package/v0/serializer/schemas/v3/transaction-sign-request-ethereum.json +50 -0
  60. package/v0/serializer/schemas/v3/transaction-sign-response-ethereum.json +19 -0
  61. package/v0/serializer/validators/transaction-validator.d.ts +15 -0
  62. package/v0/serializer/validators/transaction-validator.js +96 -0
  63. package/v0/serializer/validators/transaction-validator.js.map +1 -0
  64. package/v0/serializer/validators/validators.d.ts +1 -0
  65. package/v0/serializer/validators/validators.js +78 -0
  66. package/v0/serializer/validators/validators.js.map +1 -0
  67. package/v0/types/signed-transaction-ethereum.d.ts +5 -0
  68. package/v0/types/signed-transaction-ethereum.js +3 -0
  69. package/v0/types/signed-transaction-ethereum.js.map +1 -0
  70. package/v0/types/transaction-ethereum.d.ts +14 -0
  71. package/v0/types/transaction-ethereum.js +3 -0
  72. package/v0/types/transaction-ethereum.js.map +1 -0
  73. package/v0/types/unsigned-transaction-ethereum-typed.d.ts +11 -0
  74. package/v0/types/unsigned-transaction-ethereum-typed.js +3 -0
  75. package/v0/types/unsigned-transaction-ethereum-typed.js.map +1 -0
  76. package/v0/types/unsigned-transaction-ethereum.d.ts +15 -0
  77. package/v0/types/unsigned-transaction-ethereum.js +3 -0
  78. package/v0/types/unsigned-transaction-ethereum.js.map +1 -0
  79. package/v1/block-explorer/EtherscanBlockExplorer.d.ts +9 -0
  80. package/v1/block-explorer/EtherscanBlockExplorer.js +74 -0
  81. package/v1/block-explorer/EtherscanBlockExplorer.js.map +1 -0
  82. package/v1/clients/crypto/EthereumCryptoClient.d.ts +7 -0
  83. package/v1/clients/crypto/EthereumCryptoClient.js +147 -0
  84. package/v1/clients/crypto/EthereumCryptoClient.js.map +1 -0
  85. package/v1/clients/info/EthereumInfoClient.d.ts +15 -0
  86. package/v1/clients/info/EthereumInfoClient.js +11 -0
  87. package/v1/clients/info/EthereumInfoClient.js.map +1 -0
  88. package/v1/clients/info/EtherscanInfoClient.d.ts +7 -0
  89. package/v1/clients/info/EtherscanInfoClient.js +165 -0
  90. package/v1/clients/info/EtherscanInfoClient.js.map +1 -0
  91. package/v1/clients/node/AirGapNodeClient.d.ts +41 -0
  92. package/v1/clients/node/AirGapNodeClient.js +351 -0
  93. package/v1/clients/node/AirGapNodeClient.js.map +1 -0
  94. package/v1/clients/node/EthereumNodeClient.d.ts +17 -0
  95. package/v1/clients/node/EthereumNodeClient.js +11 -0
  96. package/v1/clients/node/EthereumNodeClient.js.map +1 -0
  97. package/v1/data/EthereumAddress.d.ts +7 -0
  98. package/v1/data/EthereumAddress.js +46 -0
  99. package/v1/data/EthereumAddress.js.map +1 -0
  100. package/v1/index.d.ts +11 -0
  101. package/v1/index.js +13 -0
  102. package/v1/index.js.map +1 -0
  103. package/v1/module/ERC20Tokens.d.ts +3 -0
  104. package/v1/module/ERC20Tokens.js +815 -0
  105. package/v1/module/ERC20Tokens.js.map +1 -0
  106. package/v1/module/EthereumModule.d.ts +13 -0
  107. package/v1/module/EthereumModule.js +125 -0
  108. package/v1/module/EthereumModule.js.map +1 -0
  109. package/v1/module.d.ts +3 -0
  110. package/v1/module.js +24 -0
  111. package/v1/module.js.map +1 -0
  112. package/v1/protocol/EthereumBaseProtocol.d.ts +84 -0
  113. package/v1/protocol/EthereumBaseProtocol.js +827 -0
  114. package/v1/protocol/EthereumBaseProtocol.js.map +1 -0
  115. package/v1/protocol/EthereumChainIds.d.ts +1 -0
  116. package/v1/protocol/EthereumChainIds.js +340 -0
  117. package/v1/protocol/EthereumChainIds.js.map +1 -0
  118. package/v1/protocol/EthereumProtocol.d.ts +8 -0
  119. package/v1/protocol/EthereumProtocol.js +64 -0
  120. package/v1/protocol/EthereumProtocol.js.map +1 -0
  121. package/v1/protocol/erc20/ERC20Token.d.ts +8 -0
  122. package/v1/protocol/erc20/ERC20Token.js +421 -0
  123. package/v1/protocol/erc20/ERC20Token.js.map +1 -0
  124. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +12 -0
  125. package/v1/serializer/v3/schemas/converter/transaction-converter.js +80 -0
  126. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
  127. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.d.ts +10 -0
  128. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js +3 -0
  129. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js.map +1 -0
  130. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.d.ts +14 -0
  131. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js +3 -0
  132. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js.map +1 -0
  133. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.d.ts +3 -0
  134. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js +3 -0
  135. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js.map +1 -0
  136. package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum-typed.json +41 -0
  137. package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum.json +58 -0
  138. package/v1/serializer/v3/schemas/generated/transaction-sign-response-ethereum.json +19 -0
  139. package/v1/serializer/v3/serializer-companion.d.ts +13 -0
  140. package/v1/serializer/v3/serializer-companion.js +190 -0
  141. package/v1/serializer/v3/serializer-companion.js.map +1 -0
  142. package/v1/serializer/v3/validators/transaction-validator.d.ts +7 -0
  143. package/v1/serializer/v3/validators/transaction-validator.js +71 -0
  144. package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
  145. package/v1/types/crypto.d.ts +2 -0
  146. package/v1/types/crypto.js +3 -0
  147. package/v1/types/crypto.js.map +1 -0
  148. package/v1/types/protocol.d.ts +32 -0
  149. package/v1/types/protocol.js +3 -0
  150. package/v1/types/protocol.js.map +1 -0
  151. package/v1/types/transaction.d.ts +24 -0
  152. package/v1/types/transaction.js +3 -0
  153. package/v1/types/transaction.js.map +1 -0
  154. package/v1/utils/EthereumUtils.d.ts +13 -0
  155. package/v1/utils/EthereumUtils.js +140 -0
  156. package/v1/utils/EthereumUtils.js.map +1 -0
  157. package/v1/utils/key.d.ts +5 -0
  158. package/v1/utils/key.js +101 -0
  159. package/v1/utils/key.js.map +1 -0
@@ -0,0 +1,58 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "definitions": {
4
+ "EthereumTransactionSignRequest": {
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "callbackURL": {
8
+ "type": "string"
9
+ },
10
+ "publicKey": {
11
+ "type": "string"
12
+ },
13
+ "transaction": {
14
+ "$ref": "#/definitions/SerializableEthereumRawUnsignedTransaction"
15
+ }
16
+ },
17
+ "required": ["publicKey", "transaction"],
18
+ "type": "object"
19
+ },
20
+ "HexString": {
21
+ "type": "string"
22
+ },
23
+ "SerializableEthereumRawUnsignedTransaction": {
24
+ "additionalProperties": false,
25
+ "properties": {
26
+ "chainId": {
27
+ "type": "number"
28
+ },
29
+ "data": {
30
+ "$ref": "#/definitions/HexString",
31
+ "type": "string"
32
+ },
33
+ "gasLimit": {
34
+ "$ref": "#/definitions/HexString",
35
+ "type": "string"
36
+ },
37
+ "gasPrice": {
38
+ "$ref": "#/definitions/HexString",
39
+ "type": "string"
40
+ },
41
+ "nonce": {
42
+ "$ref": "#/definitions/HexString",
43
+ "type": "string"
44
+ },
45
+ "to": {
46
+ "$ref": "#/definitions/HexString",
47
+ "type": "string"
48
+ },
49
+ "value": {
50
+ "$ref": "#/definitions/HexString",
51
+ "type": "string"
52
+ }
53
+ },
54
+ "required": ["chainId", "data", "gasLimit", "gasPrice", "nonce", "to", "value"],
55
+ "type": "object"
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$ref": "#/definitions/EthereumTransactionSignResponse",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "definitions": {
5
+ "EthereumTransactionSignResponse": {
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "accountIdentifier": {
9
+ "type": "string"
10
+ },
11
+ "transaction": {
12
+ "type": "string"
13
+ }
14
+ },
15
+ "required": ["accountIdentifier", "transaction"],
16
+ "type": "object"
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,13 @@
1
+ import { AirGapV3SerializerCompanion, SignedTransaction, UnsignedTransaction } from '@airgap/module-kit';
2
+ import { V3SchemaConfiguration } from '@airgap/module-kit/types/serializer';
3
+ import { TransactionSignRequest, TransactionSignResponse } from '@airgap/serializer';
4
+ export declare class EthereumV3SerializerCompanion implements AirGapV3SerializerCompanion {
5
+ readonly schemas: V3SchemaConfiguration[];
6
+ private readonly ethereumTransactionValidator;
7
+ toTransactionSignRequest(identifier: string, unsignedTransaction: UnsignedTransaction, publicKey: string, callbackUrl?: string): Promise<TransactionSignRequest>;
8
+ fromTransactionSignRequest(identifier: string, transactionSignRequest: TransactionSignRequest): Promise<UnsignedTransaction>;
9
+ validateTransactionSignRequest(identifier: string, transactionSignRequest: TransactionSignRequest): Promise<boolean>;
10
+ toTransactionSignResponse(identifier: string, signedTransaction: SignedTransaction, accountIdentifier: string): Promise<TransactionSignResponse>;
11
+ fromTransactionSignResponse(identifier: string, transactionSignResponse: TransactionSignResponse): Promise<SignedTransaction>;
12
+ validateTransactionSignResponse(identifier: string, transactionSignResponse: TransactionSignResponse): Promise<boolean>;
13
+ }
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.EthereumV3SerializerCompanion = void 0;
40
+ var coinlib_core_1 = require("@airgap/coinlib-core");
41
+ var errors_1 = require("@airgap/coinlib-core/errors");
42
+ var serializer_1 = require("@airgap/serializer");
43
+ var transaction_converter_1 = require("./schemas/converter/transaction-converter");
44
+ var transaction_validator_1 = require("./validators/transaction-validator");
45
+ var ethereumTransactionSignRequest = require('./schemas/generated/transaction-sign-request-ethereum.json');
46
+ var ethereumTypedTransactionSignRequest = require('./schemas/generated/transaction-sign-request-ethereum-typed.json');
47
+ var ethereumTransactionSignResponse = require('./schemas/generated/transaction-sign-response-ethereum.json');
48
+ var EthereumV3SerializerCompanion = /** @class */ (function () {
49
+ function EthereumV3SerializerCompanion() {
50
+ this.schemas = [
51
+ {
52
+ type: serializer_1.IACMessageType.TransactionSignRequest,
53
+ schema: { schema: ethereumTransactionSignRequest },
54
+ protocolIdentifier: coinlib_core_1.MainProtocolSymbols.ETH
55
+ },
56
+ {
57
+ type: serializer_1.IACMessageType.TransactionSignRequest,
58
+ schema: { schema: ethereumTypedTransactionSignRequest },
59
+ protocolIdentifier: coinlib_core_1.MainProtocolSymbols.ETH
60
+ },
61
+ {
62
+ type: serializer_1.IACMessageType.TransactionSignResponse,
63
+ schema: { schema: ethereumTransactionSignResponse },
64
+ protocolIdentifier: coinlib_core_1.MainProtocolSymbols.ETH
65
+ },
66
+ {
67
+ type: serializer_1.IACMessageType.TransactionSignRequest,
68
+ schema: { schema: ethereumTransactionSignRequest },
69
+ protocolIdentifier: coinlib_core_1.SubProtocolSymbols.ETH_ERC20
70
+ },
71
+ {
72
+ type: serializer_1.IACMessageType.TransactionSignResponse,
73
+ schema: { schema: ethereumTransactionSignResponse },
74
+ protocolIdentifier: coinlib_core_1.SubProtocolSymbols.ETH_ERC20
75
+ }
76
+ ];
77
+ this.ethereumTransactionValidator = new transaction_validator_1.EthereumTransactionValidator();
78
+ }
79
+ EthereumV3SerializerCompanion.prototype.toTransactionSignRequest = function (identifier, unsignedTransaction, publicKey, callbackUrl) {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ return __generator(this, function (_a) {
82
+ switch (identifier) {
83
+ case coinlib_core_1.MainProtocolSymbols.ETH:
84
+ case coinlib_core_1.SubProtocolSymbols.ETH_ERC20:
85
+ return [2 /*return*/, (0, transaction_converter_1.ethereumUnsignedTransactionToRequest)(unsignedTransaction, publicKey, callbackUrl)];
86
+ default:
87
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
88
+ }
89
+ return [2 /*return*/];
90
+ });
91
+ });
92
+ };
93
+ EthereumV3SerializerCompanion.prototype.fromTransactionSignRequest = function (identifier, transactionSignRequest) {
94
+ return __awaiter(this, void 0, void 0, function () {
95
+ return __generator(this, function (_a) {
96
+ switch (identifier) {
97
+ case coinlib_core_1.MainProtocolSymbols.ETH:
98
+ case coinlib_core_1.SubProtocolSymbols.ETH_ERC20:
99
+ return [2 /*return*/, (0, transaction_converter_1.ethereumTransactionSignRequestToUnsigned)(transactionSignRequest)];
100
+ default:
101
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
102
+ }
103
+ return [2 /*return*/];
104
+ });
105
+ });
106
+ };
107
+ EthereumV3SerializerCompanion.prototype.validateTransactionSignRequest = function (identifier, transactionSignRequest) {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var _a, _b;
110
+ return __generator(this, function (_c) {
111
+ switch (_c.label) {
112
+ case 0:
113
+ _a = identifier;
114
+ switch (_a) {
115
+ case coinlib_core_1.MainProtocolSymbols.ETH: return [3 /*break*/, 1];
116
+ case coinlib_core_1.SubProtocolSymbols.ETH_ERC20: return [3 /*break*/, 1];
117
+ }
118
+ return [3 /*break*/, 4];
119
+ case 1:
120
+ _c.trys.push([1, 3, , 4]);
121
+ return [4 /*yield*/, this.ethereumTransactionValidator.validateUnsignedTransaction(transactionSignRequest)];
122
+ case 2:
123
+ _c.sent();
124
+ return [2 /*return*/, true];
125
+ case 3:
126
+ _b = _c.sent();
127
+ return [2 /*return*/, false];
128
+ case 4: throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
129
+ }
130
+ });
131
+ });
132
+ };
133
+ EthereumV3SerializerCompanion.prototype.toTransactionSignResponse = function (identifier, signedTransaction, accountIdentifier) {
134
+ return __awaiter(this, void 0, void 0, function () {
135
+ return __generator(this, function (_a) {
136
+ switch (identifier) {
137
+ case coinlib_core_1.MainProtocolSymbols.ETH:
138
+ case coinlib_core_1.SubProtocolSymbols.ETH_ERC20:
139
+ return [2 /*return*/, (0, transaction_converter_1.ethereumSignedTransactionToResponse)(signedTransaction, accountIdentifier)];
140
+ default:
141
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
142
+ }
143
+ return [2 /*return*/];
144
+ });
145
+ });
146
+ };
147
+ EthereumV3SerializerCompanion.prototype.fromTransactionSignResponse = function (identifier, transactionSignResponse) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ return __generator(this, function (_a) {
150
+ switch (identifier) {
151
+ case coinlib_core_1.MainProtocolSymbols.ETH:
152
+ case coinlib_core_1.SubProtocolSymbols.ETH_ERC20:
153
+ return [2 /*return*/, (0, transaction_converter_1.ethereumTransactionSignResponseToSigned)(transactionSignResponse)];
154
+ default:
155
+ throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
156
+ }
157
+ return [2 /*return*/];
158
+ });
159
+ });
160
+ };
161
+ EthereumV3SerializerCompanion.prototype.validateTransactionSignResponse = function (identifier, transactionSignResponse) {
162
+ return __awaiter(this, void 0, void 0, function () {
163
+ var _a, _b;
164
+ return __generator(this, function (_c) {
165
+ switch (_c.label) {
166
+ case 0:
167
+ _a = identifier;
168
+ switch (_a) {
169
+ case coinlib_core_1.MainProtocolSymbols.ETH: return [3 /*break*/, 1];
170
+ case coinlib_core_1.SubProtocolSymbols.ETH_ERC20: return [3 /*break*/, 1];
171
+ }
172
+ return [3 /*break*/, 4];
173
+ case 1:
174
+ _c.trys.push([1, 3, , 4]);
175
+ return [4 /*yield*/, this.ethereumTransactionValidator.validateSignedTransaction(transactionSignResponse)];
176
+ case 2:
177
+ _c.sent();
178
+ return [2 /*return*/, true];
179
+ case 3:
180
+ _b = _c.sent();
181
+ return [2 /*return*/, false];
182
+ case 4: throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
183
+ }
184
+ });
185
+ });
186
+ };
187
+ return EthereumV3SerializerCompanion;
188
+ }());
189
+ exports.EthereumV3SerializerCompanion = EthereumV3SerializerCompanion;
190
+ //# sourceMappingURL=serializer-companion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serializer-companion.js","sourceRoot":"","sources":["../../../../src/v1/serializer/v3/serializer-companion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsF;AACtF,sDAA8D;AAG9D,iDAAgH;AAIhH,mFAKkD;AAClD,4EAAiF;AAEjF,IAAM,8BAA8B,GAAe,OAAO,CAAC,4DAA4D,CAAC,CAAA;AACxH,IAAM,mCAAmC,GAAe,OAAO,CAAC,kEAAkE,CAAC,CAAA;AACnI,IAAM,+BAA+B,GAAe,OAAO,CAAC,6DAA6D,CAAC,CAAA;AAE1H;IAAA;QACkB,YAAO,GAA4B;YACjD;gBACE,IAAI,EAAE,2BAAc,CAAC,sBAAsB;gBAC3C,MAAM,EAAE,EAAE,MAAM,EAAE,8BAA8B,EAAE;gBAClD,kBAAkB,EAAE,kCAAmB,CAAC,GAAG;aAC5C;YACD;gBACE,IAAI,EAAE,2BAAc,CAAC,sBAAsB;gBAC3C,MAAM,EAAE,EAAE,MAAM,EAAE,mCAAmC,EAAE;gBACvD,kBAAkB,EAAE,kCAAmB,CAAC,GAAG;aAC5C;YACD;gBACE,IAAI,EAAE,2BAAc,CAAC,uBAAuB;gBAC5C,MAAM,EAAE,EAAE,MAAM,EAAE,+BAA+B,EAAE;gBACnD,kBAAkB,EAAE,kCAAmB,CAAC,GAAG;aAC5C;YACD;gBACE,IAAI,EAAE,2BAAc,CAAC,sBAAsB;gBAC3C,MAAM,EAAE,EAAE,MAAM,EAAE,8BAA8B,EAAE;gBAClD,kBAAkB,EAAE,iCAAkB,CAAC,SAAS;aACjD;YACD;gBACE,IAAI,EAAE,2BAAc,CAAC,uBAAuB;gBAC5C,MAAM,EAAE,EAAE,MAAM,EAAE,+BAA+B,EAAE;gBACnD,kBAAkB,EAAE,iCAAkB,CAAC,SAAS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/serializer';
2
+ import { EthereumTransactionSignRequest } from '../schemas/definitions/transaction-sign-request-ethereum';
3
+ import { EthereumTransactionSignResponse } from '../schemas/definitions/transaction-sign-response-ethereum';
4
+ export declare class EthereumTransactionValidator implements TransactionValidator, TransactionValidatorV2 {
5
+ validateUnsignedTransaction(request: EthereumTransactionSignRequest): Promise<any>;
6
+ validateSignedTransaction(signedTx: EthereumTransactionSignResponse): any;
7
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EthereumTransactionValidator = void 0;
4
+ // tslint:disable: max-classes-per-file
5
+ var validate_1 = require("@airgap/coinlib-core/dependencies/src/validate.js-0.13.1/validate");
6
+ var serializer_1 = require("@airgap/serializer");
7
+ var unsignedTransactionConstraints = {
8
+ nonce: {
9
+ presence: { allowEmpty: false },
10
+ type: 'String',
11
+ isHexStringWithPrefix: true
12
+ },
13
+ gasPrice: {
14
+ presence: { allowEmpty: false },
15
+ type: 'String',
16
+ isHexStringWithPrefix: true
17
+ },
18
+ gasLimit: {
19
+ presence: { allowEmpty: false },
20
+ type: 'String',
21
+ isHexStringWithPrefix: true
22
+ },
23
+ to: {
24
+ presence: { allowEmpty: false },
25
+ type: 'String',
26
+ isHexStringWithPrefix: true,
27
+ format: {
28
+ pattern: '^0x[a-fA-F0-9]{40}$',
29
+ flags: 'i',
30
+ message: 'is not a valid ethereum address'
31
+ }
32
+ },
33
+ value: {
34
+ presence: { allowEmpty: false },
35
+ type: 'String',
36
+ isHexStringWithPrefix: true
37
+ },
38
+ chainId: {
39
+ presence: { allowEmpty: false },
40
+ numericality: { noStrings: true, onlyInteger: true, greaterThanOrEqualTo: 0 }
41
+ },
42
+ data: {
43
+ presence: { allowEmpty: false },
44
+ type: 'String',
45
+ isHexStringWithPrefix: true
46
+ }
47
+ };
48
+ var signedTransactionConstraints = {
49
+ transaction: {
50
+ presence: { allowEmpty: false },
51
+ type: 'String',
52
+ isValidEthereumTransactionString: true
53
+ }
54
+ };
55
+ var success = function () { return undefined; };
56
+ var error = function (errors) { return errors; };
57
+ var EthereumTransactionValidator = /** @class */ (function () {
58
+ function EthereumTransactionValidator() {
59
+ }
60
+ EthereumTransactionValidator.prototype.validateUnsignedTransaction = function (request) {
61
+ var transaction = request.transaction;
62
+ (0, serializer_1.validateSyncScheme)({});
63
+ return (0, validate_1.async)(transaction, unsignedTransactionConstraints).then(success, error);
64
+ };
65
+ EthereumTransactionValidator.prototype.validateSignedTransaction = function (signedTx) {
66
+ return (0, validate_1.async)(signedTx, signedTransactionConstraints).then(success, error);
67
+ };
68
+ return EthereumTransactionValidator;
69
+ }());
70
+ exports.EthereumTransactionValidator = EthereumTransactionValidator;
71
+ //# sourceMappingURL=transaction-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-validator.js","sourceRoot":"","sources":["../../../../../src/v1/serializer/v3/validators/transaction-validator.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,8FAAyF;AACzF,iDAAqG;AAKrG,IAAM,8BAA8B,GAAG;IACrC,KAAK,EAAE;QACL,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,qBAAqB,EAAE,IAAI;KAC5B;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,qBAAqB,EAAE,IAAI;KAC5B;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,qBAAqB,EAAE,IAAI;KAC5B;IACD,EAAE,EAAE;QACF,QAAQ,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE;QAC/B,IAAI,EAAE,QAAQ;QACd,qBAAqB,EAAE,IAAI;QAC3B,MAAM,EAAE;YACN,OAAO,EAAE,qBAAqB;YAC9B,KAAK,EAAE,GAAG;YACV,OAAO,EAA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0,0 +1,2 @@
1
+ import { Secp256K1CryptoConfiguration } from '@airgap/module-kit';
2
+ export declare type EthereumCryptoConfiguration = Secp256K1CryptoConfiguration;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/v1/types/crypto.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import { FeeDefaults, ProtocolNetwork, ProtocolUnitsMetadata } from '@airgap/module-kit';
2
+ export declare type EthereumUnits = 'ETH' | 'GWEI' | 'WEI';
3
+ export interface EthereumProtocolNetwork extends ProtocolNetwork {
4
+ chainId: number;
5
+ blockExplorerApi: string;
6
+ }
7
+ export interface EthereumProtocolOptions {
8
+ network: EthereumProtocolNetwork;
9
+ }
10
+ export interface EthereumBaseProtocolOptions<_Units extends string = EthereumUnits> extends EthereumProtocolOptions {
11
+ identifier: string;
12
+ name: string;
13
+ units: ProtocolUnitsMetadata<_Units>;
14
+ mainUnit: _Units;
15
+ feeDefaults?: FeeDefaults<EthereumUnits>;
16
+ standardDerivationPath?: string;
17
+ }
18
+ export interface ERC20TokenOptions extends EthereumProtocolOptions {
19
+ name: string;
20
+ identifier: string;
21
+ contractAddress: string;
22
+ units: ProtocolUnitsMetadata<string>;
23
+ mainUnit: string;
24
+ }
25
+ export interface ERC20TokenMetadata {
26
+ name: string;
27
+ identifier: string;
28
+ symbol: string;
29
+ marketSymbol: string;
30
+ contractAddress: string;
31
+ decimals: number;
32
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/v1/types/protocol.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ import { SignedTransaction, TransactionCursor, UnsignedTransaction } from '@airgap/module-kit';
2
+ export interface EthereumRawUnsignedTransaction extends UnsignedTransaction {
3
+ ethereumType: 'raw';
4
+ nonce: string;
5
+ gasPrice: string;
6
+ gasLimit: string;
7
+ to: string;
8
+ value: string;
9
+ chainId: number;
10
+ data: string;
11
+ }
12
+ export interface EthereumTypedUnsignedTransaction extends UnsignedTransaction {
13
+ ethereumType: 'typed';
14
+ serialized: string;
15
+ derivationPath: string;
16
+ masterFingerprint: string;
17
+ }
18
+ export declare type EthereumUnsignedTransaction = EthereumRawUnsignedTransaction | EthereumTypedUnsignedTransaction;
19
+ export interface EthereumSignedTransaction extends SignedTransaction {
20
+ serialized: string;
21
+ }
22
+ export interface EthereumTransactionCursor extends TransactionCursor {
23
+ page?: number;
24
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/v1/types/transaction.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ export declare class EthereumUtils {
2
+ static toHex(value: any): string;
3
+ private static readonly SHA3_NULL_S;
4
+ static sha3(value: any): string | null;
5
+ private static numberToHex;
6
+ private static hexToBytes;
7
+ private static isHexStrict;
8
+ private static checkAddressChecksum;
9
+ private static isAddress;
10
+ private static isBigNumber;
11
+ private static utf8ToHex;
12
+ private static isObject;
13
+ }
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EthereumUtils = void 0;
4
+ var bignumber_1 = require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber");
5
+ var errors_1 = require("@airgap/coinlib-core/errors");
6
+ var coinlib_error_1 = require("@airgap/coinlib-core/errors/coinlib-error");
7
+ // var _ = require('underscore')
8
+ // var BN = require('@airgap/coinlib-core/dependencies/src/bn.js-4.11.8/bn')
9
+ // var numberToBN = require('number-to-bn')
10
+ var utf8 = require('@airgap/coinlib-core/dependencies/src/utf8-3.0.0/utf8');
11
+ var createKeccakHash = require('@airgap/coinlib-core/dependencies/src/keccak-1.0.2/js');
12
+ // this code was adapted from web3.js (https://github.com/ethereum/web3.js/blob/2.x/packages/web3-utils/src/Utils.js)
13
+ var EthereumUtils = /** @class */ (function () {
14
+ function EthereumUtils() {
15
+ }
16
+ EthereumUtils.toHex = function (value) {
17
+ if (EthereumUtils.isAddress(value)) {
18
+ return "0x".concat(value.toLowerCase().replace(/^0x/i, ''));
19
+ }
20
+ if (typeof value === 'boolean') {
21
+ return value ? '0x01' : '0x00';
22
+ }
23
+ if (EthereumUtils.isObject(value) && !EthereumUtils.isBigNumber(value) /* && !EthereumUtils.isBN(value)*/) {
24
+ return EthereumUtils.utf8ToHex(JSON.stringify(value));
25
+ }
26
+ // if its a negative number, pass it through numberToHex
27
+ if (typeof value === 'string') {
28
+ if (value.indexOf('-0x') === 0 || value.indexOf('-0X') === 0) {
29
+ return EthereumUtils.numberToHex(value);
30
+ }
31
+ else if (value.indexOf('0x') === 0 || value.indexOf('0X') === 0) {
32
+ return value;
33
+ }
34
+ else if (!isFinite(Number(value))) {
35
+ return EthereumUtils.utf8ToHex(value);
36
+ }
37
+ }
38
+ return EthereumUtils.numberToHex(value);
39
+ };
40
+ EthereumUtils.sha3 = function (value) {
41
+ var valueInBytes = value;
42
+ if (EthereumUtils.isHexStrict(value) && /^0x/i.test(value.toString())) {
43
+ valueInBytes = EthereumUtils.hexToBytes(value);
44
+ }
45
+ var hash = createKeccakHash('keccak256').update(valueInBytes).digest('hex');
46
+ var returnValue = "0x".concat(hash);
47
+ if (returnValue === EthereumUtils.SHA3_NULL_S) {
48
+ return null;
49
+ }
50
+ else {
51
+ return returnValue;
52
+ }
53
+ };
54
+ EthereumUtils.numberToHex = function (value) {
55
+ if (value === null || value === undefined) {
56
+ return value;
57
+ }
58
+ if (!isFinite(Number(value)) && !EthereumUtils.isHexStrict(value)) {
59
+ throw new errors_1.InvalidValueError(coinlib_error_1.Domain.UTILS, "Given input \"".concat(JSON.stringify(value), "\" is not a number."));
60
+ }
61
+ // var number = EthereumUtils.toBN(value)
62
+ var myNumber = new bignumber_1.BigNumber(value);
63
+ var result = myNumber.toString(16);
64
+ return myNumber.lt(new bignumber_1.BigNumber(0)) ? "-0x".concat(result.substr(1)) : "0x".concat(result);
65
+ };
66
+ EthereumUtils.hexToBytes = function (value) {
67
+ var hex = typeof value === 'number' ? value.toString(16) : value;
68
+ if (!EthereumUtils.isHexStrict(hex)) {
69
+ throw new errors_1.InvalidValueError(coinlib_error_1.Domain.UTILS, "Given value \"".concat(JSON.stringify(hex), "\" is not a valid hex string."));
70
+ }
71
+ hex = hex.replace(/^0x/i, '');
72
+ var bytes = [];
73
+ for (var c = 0; c < hex.length; c += 2) {
74
+ bytes.push(parseInt(hex.substr(c, 2), 16));
75
+ }
76
+ return bytes;
77
+ };
78
+ EthereumUtils.isHexStrict = function (hex) {
79
+ return (typeof hex === 'string' || typeof hex === 'number') && /^(-)?0x[0-9a-f]*$/i.test(hex.toString());
80
+ };
81
+ EthereumUtils.checkAddressChecksum = function (value) {
82
+ var address = value.replace(/^0x/i, '');
83
+ var addressHash = EthereumUtils.sha3(address.toLowerCase());
84
+ if (addressHash === null) {
85
+ return false;
86
+ }
87
+ addressHash = addressHash.replace(/^0x/i, '');
88
+ for (var i = 0; i < 40; i++) {
89
+ if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) ||
90
+ (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
91
+ return false;
92
+ }
93
+ }
94
+ return true;
95
+ };
96
+ EthereumUtils.isAddress = function (value) {
97
+ if (!/^(0x)?[0-9a-f]{40}$/i.test(value)) {
98
+ return false;
99
+ // If it's ALL lowercase or ALL upppercase
100
+ }
101
+ else if (/^(0x|0X)?[0-9a-f]{40}$/.test(value) || /^(0x|0X)?[0-9A-F]{40}$/.test(value)) {
102
+ return true;
103
+ // Otherwise check each case
104
+ }
105
+ else {
106
+ return EthereumUtils.checkAddressChecksum(value);
107
+ }
108
+ };
109
+ EthereumUtils.isBigNumber = function (value) {
110
+ if (!value) {
111
+ return false;
112
+ }
113
+ else {
114
+ return bignumber_1.BigNumber.isBigNumber(value);
115
+ }
116
+ };
117
+ EthereumUtils.utf8ToHex = function (value) {
118
+ var str = utf8.encode(value);
119
+ var hex = '';
120
+ // remove \u0000 padding from either side
121
+ str = str.replace(/^(?:\u0000)*/, '');
122
+ str = str.split('').reverse().join('');
123
+ str = str.replace(/^(?:\u0000)*/, '');
124
+ str = str.split('').reverse().join('');
125
+ for (var i = 0; i < str.length; i++) {
126
+ var code = str.charCodeAt(i);
127
+ var n = code.toString(16);
128
+ hex += n.length < 2 ? "0".concat(n) : n;
129
+ }
130
+ return "0x".concat(hex);
131
+ };
132
+ EthereumUtils.isObject = function (value) {
133
+ var type = typeof value;
134
+ return type === 'function' || (type === 'object' && !!value);
135
+ };
136
+ EthereumUtils.SHA3_NULL_S = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
137
+ return EthereumUtils;
138
+ }());
139
+ exports.EthereumUtils = EthereumUtils;
140
+ //# sourceMappingURL=EthereumUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthereumUtils.js","sourceRoot":"","sources":["../../../src/v1/utils/EthereumUtils.ts"],"names":[],"mappings":";;;AAAA,gGAA8F;AAC9F,sDAA+D;AAC/D,2EAAkE;AAClE,gCAAgC;AAChC,4EAA4E;AAC5E,2CAA2C;AAC3C,IAAM,IAAI,GAAG,OAAO,CAAC,uDAAuD,CAAC,CAAA;AAC7E,IAAM,gBAAgB,GAAG,OAAO,CAAC,uDAAuD,CAAC,CAAA;AAEzF,qHAAqH;AACrH;IAAA;IAqJA,CAAC;IApJe,mBAAK,GAAnB,UAAoB,KAAU;QAC5B,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAClC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AAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAA;QACrC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAEtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,IAAM,IAAI,GAAW,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;YACtC,IAAM,CAAC,GAAW,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;YACnC,GAAG,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,WAAI,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,CAAA;SAClC;QAED,OAAO,YAAK,GAAG,CAAE,CAAA;IACnB,CAAC;IAEc,sBAAQ,GAAvB,UAAwB,KAAc;QACpC,IAAM,IAAI,GAAW,OAAO,KAAK,CAAA;QAEjC,OAAO,IAAI,KAAK,UAAU,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,CAAA;IAC9D,CAAC;IAxHuB,yBAAW,GAAW,oEAAoE,CAAA;IAyHpH,oBAAC;CAAA,AArJD,IAqJC;AArJY,sCAAa"}
@@ -0,0 +1,5 @@
1
+ import { ExtendedPublicKey, ExtendedSecretKey, PublicKey, SecretKey } from '@airgap/module-kit';
2
+ export declare function convertSecretKey(secretKey: SecretKey, targetFormat: SecretKey['format']): SecretKey;
3
+ export declare function convertExtendedSecretKey(extendedSecretKey: ExtendedSecretKey, targetFormat: ExtendedSecretKey['format']): ExtendedSecretKey;
4
+ export declare function convertPublicKey(publicKey: PublicKey, targetFormat: PublicKey['format']): PublicKey;
5
+ export declare function convertExtendedPublicKey(extendedPublicKey: ExtendedPublicKey, targetFormat: ExtendedPublicKey['format']): ExtendedPublicKey;