@airgap/ethereum 0.13.21-beta.6 → 0.13.21
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 +7 -7
- package/v1/clients/crypto/EthereumCryptoClient.d.ts +7 -0
- package/v1/clients/crypto/EthereumCryptoClient.js +147 -0
- package/v1/clients/crypto/EthereumCryptoClient.js.map +1 -0
- package/v1/clients/info/EthereumInfoClient.d.ts +9 -7
- package/v1/clients/info/EthereumInfoClient.js.map +1 -1
- package/v1/clients/info/EtherscanInfoClient.d.ts +2 -1
- package/v1/clients/info/EtherscanInfoClient.js +0 -2
- package/v1/clients/info/EtherscanInfoClient.js.map +1 -1
- package/v1/clients/node/EthereumNodeClient.d.ts +18 -0
- package/v1/clients/node/EthereumNodeClient.js +3 -0
- package/v1/clients/node/EthereumNodeClient.js.map +1 -0
- package/v1/clients/node/HttpEthereumNodeClient.d.ts +66 -0
- package/v1/clients/node/HttpEthereumNodeClient.js +443 -0
- package/v1/clients/node/HttpEthereumNodeClient.js.map +1 -0
- package/v1/data/EthereumAddress.d.ts +7 -0
- package/v1/data/EthereumAddress.js +46 -0
- package/v1/data/EthereumAddress.js.map +1 -0
- package/v1/index.d.ts +19 -6
- package/v1/index.js +16 -1
- package/v1/index.js.map +1 -1
- package/v1/module/ERC20Tokens.d.ts +1 -1
- package/v1/module/EthereumModule.d.ts +4 -4
- package/v1/module/EthereumModule.js.map +1 -1
- package/v1/protocol/EthereumBaseProtocol.d.ts +84 -7
- package/v1/protocol/EthereumBaseProtocol.js +779 -8
- package/v1/protocol/EthereumBaseProtocol.js.map +1 -1
- package/v1/protocol/EthereumChainIds.d.ts +1 -0
- package/v1/protocol/EthereumChainIds.js +340 -0
- package/v1/protocol/EthereumChainIds.js.map +1 -0
- package/v1/protocol/EthereumProtocol.d.ts +6 -7
- package/v1/protocol/EthereumProtocol.js +3 -4
- package/v1/protocol/EthereumProtocol.js.map +1 -1
- package/v1/protocol/erc20/ERC20Protocol.d.ts +32 -0
- package/v1/protocol/erc20/ERC20Protocol.js +397 -0
- package/v1/protocol/erc20/ERC20Protocol.js.map +1 -0
- package/v1/protocol/erc20/ERC20Token.d.ts +15 -10
- package/v1/protocol/erc20/ERC20Token.js +26 -35
- package/v1/protocol/erc20/ERC20Token.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +8 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +76 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.d.ts +10 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.d.ts +14 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum-typed.json +41 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum.json +58 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-ethereum.json +19 -0
- package/v1/serializer/v3/serializer-companion.js +10 -9
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.d.ts +7 -0
- package/v1/serializer/v3/validators/transaction-validator.js +71 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/protocol.d.ts +35 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
- package/v1/types/transaction.d.ts +24 -0
- package/v1/types/transaction.js +3 -0
- package/v1/types/transaction.js.map +1 -0
- package/v1/utils/EthereumUtils.d.ts +16 -0
- package/v1/utils/EthereumUtils.js +155 -0
- package/v1/utils/EthereumUtils.js.map +1 -0
- package/v1/utils/key.d.ts +5 -0
- package/v1/utils/key.js +101 -0
- package/v1/utils/key.js.map +1 -0
- package/v1/utils/protocol.d.ts +4 -5
- package/v1/utils/protocol.js.map +1 -1
|
@@ -0,0 +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,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,EAAK,IAAI,UAAK,QAAQ,EAA/B,QAAoB,CAAF,CAAa;IAErC,OAAO;QACL,WAAW,EAAE,IAAI;QACjB,SAAS,WAAA;QACT,WAAW,EAAE,WAAW;KACzB,CAAA;AACH,CAAC;AAED,SAAS,yCAAyC,CAChD,QAA0C,EAC1C,SAAiB,EACjB,WAAoB;IAEZ,IAAM,CAAC,GAAc,QAAQ,KAAtB,EAAK,IAAI,UAAK,QAAQ,EAA/B,QAAoB,CAAF,CAAa;IAErC,OAAO;QACL,WAAW,EAAE,IAAI;QACjB,SAAS,WAAA;QACT,WAAW,EAAE,WAAW;KACzB,CAAA;AACH,CAAC;AAED,SAAgB,mCAAmC,CACjD,MAAiC,EACjC,iBAAyB;IAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,iBAAiB,mBAAA,EAAE,CAAA;AAC9D,CAAC;AALD,kFAKC;AAED,SAAgB,wCAAwC,CACtD,OAA6E;IAE7E,OAAO,qCAAqC,CAAC,OAAO,CAAC;QACnD,CAAC,CAAC,6CAA6C,CAAC,OAAO,CAAC;QACxD,CAAC,CAAC,2CAA2C,CAAC,OAAO,CAAC,CAAA;AAC1D,CAAC;AAND,4FAMC;AAED,SAAS,2CAA2C,CAAC,OAAuC;IAC1F,OAAO,IAAA,mCAAsB,aAAmC,YAAY,EAAE,KAAK,IAAK,OAAO,CAAC,WAAW,EAAG,CAAA;AAChH,CAAC;AAED,SAAS,6CAA6C,CAAC,OAA4C;IACjG,OAAO,IAAA,mCAAsB,aAAqC,YAAY,EAAE,OAAO,IAAK,OAAO,CAAC,WAAW,EAAG,CAAA;AACpH,CAAC;AAED,SAAgB,uCAAuC,CAAC,QAAyC;IAC/F,OAAO,IAAA,iCAAoB,EAA4B,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;AAC9F,CAAC;AAFD,0FAEC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TransactionSignRequest } from '@airgap/serializer';
|
|
2
|
+
import { HexString } from '@airgap/serializer/v3/schemas/definitions/hex-string';
|
|
3
|
+
import { EthereumTypedUnsignedTransaction } from '../../../../types/transaction';
|
|
4
|
+
export interface SerializableEthereumTypedUnsignedTransaction extends Omit<EthereumTypedUnsignedTransaction, 'type' | 'ethereumType'> {
|
|
5
|
+
serialized: HexString;
|
|
6
|
+
derivationPath: string;
|
|
7
|
+
masterFingerprint: string;
|
|
8
|
+
}
|
|
9
|
+
export interface EthereumTypedTransactionSignRequest extends TransactionSignRequest<SerializableEthereumTypedUnsignedTransaction> {
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sign-request-ethereum-typed.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TransactionSignRequest } from '@airgap/serializer';
|
|
2
|
+
import { HexString } from '@airgap/serializer/v3/schemas/definitions/hex-string';
|
|
3
|
+
import { EthereumRawUnsignedTransaction } from '../../../../types/transaction';
|
|
4
|
+
export interface SerializableEthereumRawUnsignedTransaction extends Omit<EthereumRawUnsignedTransaction, 'type' | 'ethereumType'> {
|
|
5
|
+
nonce: HexString;
|
|
6
|
+
gasPrice: HexString;
|
|
7
|
+
gasLimit: HexString;
|
|
8
|
+
to: HexString;
|
|
9
|
+
value: HexString;
|
|
10
|
+
chainId: number;
|
|
11
|
+
data: HexString;
|
|
12
|
+
}
|
|
13
|
+
export interface EthereumTransactionSignRequest extends TransactionSignRequest<SerializableEthereumRawUnsignedTransaction> {
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sign-request-ethereum.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-sign-response-ethereum.js","sourceRoot":"","sources":["../../../../../../src/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"definitions": {
|
|
4
|
+
"EthereumTypedTransactionSignRequest": {
|
|
5
|
+
"additionalProperties": false,
|
|
6
|
+
"properties": {
|
|
7
|
+
"callbackURL": {
|
|
8
|
+
"type": "string"
|
|
9
|
+
},
|
|
10
|
+
"publicKey": {
|
|
11
|
+
"type": "string"
|
|
12
|
+
},
|
|
13
|
+
"transaction": {
|
|
14
|
+
"$ref": "#/definitions/SerializableEthereumTypedUnsignedTransaction"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"required": ["publicKey", "transaction"],
|
|
18
|
+
"type": "object"
|
|
19
|
+
},
|
|
20
|
+
"HexString": {
|
|
21
|
+
"type": "string"
|
|
22
|
+
},
|
|
23
|
+
"SerializableEthereumTypedUnsignedTransaction": {
|
|
24
|
+
"additionalProperties": false,
|
|
25
|
+
"properties": {
|
|
26
|
+
"derivationPath": {
|
|
27
|
+
"type": "string"
|
|
28
|
+
},
|
|
29
|
+
"masterFingerprint": {
|
|
30
|
+
"type": "string"
|
|
31
|
+
},
|
|
32
|
+
"serialized": {
|
|
33
|
+
"$ref": "#/definitions/HexString",
|
|
34
|
+
"type": "string"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"required": ["derivationPath", "masterFingerprint", "serialized"],
|
|
38
|
+
"type": "object"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -40,10 +40,11 @@ exports.EthereumV3SerializerCompanion = void 0;
|
|
|
40
40
|
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
41
41
|
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
42
42
|
var serializer_1 = require("@airgap/serializer");
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
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');
|
|
47
48
|
var EthereumV3SerializerCompanion = /** @class */ (function () {
|
|
48
49
|
function EthereumV3SerializerCompanion() {
|
|
49
50
|
this.schemas = [
|
|
@@ -73,13 +74,13 @@ var EthereumV3SerializerCompanion = /** @class */ (function () {
|
|
|
73
74
|
protocolIdentifier: coinlib_core_1.SubProtocolSymbols.ETH_ERC20
|
|
74
75
|
}
|
|
75
76
|
];
|
|
76
|
-
this.ethereumTransactionValidator = new
|
|
77
|
+
this.ethereumTransactionValidator = new transaction_validator_1.EthereumTransactionValidator();
|
|
77
78
|
}
|
|
78
79
|
EthereumV3SerializerCompanion.prototype.toTransactionSignRequest = function (identifier, unsignedTransaction, publicKey, callbackUrl) {
|
|
79
80
|
return __awaiter(this, void 0, void 0, function () {
|
|
80
81
|
return __generator(this, function (_a) {
|
|
81
82
|
if (identifier === coinlib_core_1.MainProtocolSymbols.ETH || identifier.startsWith(coinlib_core_1.SubProtocolSymbols.ETH_ERC20)) {
|
|
82
|
-
return [2 /*return*/, (0,
|
|
83
|
+
return [2 /*return*/, (0, transaction_converter_1.ethereumUnsignedTransactionToRequest)(unsignedTransaction, publicKey, callbackUrl)];
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
86
|
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
|
|
@@ -92,7 +93,7 @@ var EthereumV3SerializerCompanion = /** @class */ (function () {
|
|
|
92
93
|
return __awaiter(this, void 0, void 0, function () {
|
|
93
94
|
return __generator(this, function (_a) {
|
|
94
95
|
if (identifier === coinlib_core_1.MainProtocolSymbols.ETH || identifier.startsWith(coinlib_core_1.SubProtocolSymbols.ETH_ERC20)) {
|
|
95
|
-
return [2 /*return*/, (0,
|
|
96
|
+
return [2 /*return*/, (0, transaction_converter_1.ethereumTransactionSignRequestToUnsigned)(transactionSignRequest)];
|
|
96
97
|
}
|
|
97
98
|
else {
|
|
98
99
|
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
|
|
@@ -129,7 +130,7 @@ var EthereumV3SerializerCompanion = /** @class */ (function () {
|
|
|
129
130
|
return __awaiter(this, void 0, void 0, function () {
|
|
130
131
|
return __generator(this, function (_a) {
|
|
131
132
|
if (identifier === coinlib_core_1.MainProtocolSymbols.ETH || identifier.startsWith(coinlib_core_1.SubProtocolSymbols.ETH_ERC20)) {
|
|
132
|
-
return [2 /*return*/, (0,
|
|
133
|
+
return [2 /*return*/, (0, transaction_converter_1.ethereumSignedTransactionToResponse)(signedTransaction, accountIdentifier)];
|
|
133
134
|
}
|
|
134
135
|
else {
|
|
135
136
|
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
|
|
@@ -142,7 +143,7 @@ var EthereumV3SerializerCompanion = /** @class */ (function () {
|
|
|
142
143
|
return __awaiter(this, void 0, void 0, function () {
|
|
143
144
|
return __generator(this, function (_a) {
|
|
144
145
|
if (identifier === coinlib_core_1.MainProtocolSymbols.ETH || identifier.startsWith(coinlib_core_1.SubProtocolSymbols.ETH_ERC20)) {
|
|
145
|
-
return [2 /*return*/, (0,
|
|
146
|
+
return [2 /*return*/, (0, transaction_converter_1.ethereumTransactionSignResponseToSigned)(transactionSignResponse)];
|
|
146
147
|
}
|
|
147
148
|
else {
|
|
148
149
|
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, "Protocol ".concat(identifier, " not supported"));
|
|
@@ -1 +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;
|
|
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,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AQ,EAAE,mBAAY,UAAU,mBAAgB,CAAC,CAAA;iBACpF;;;;KACF;IAEY,uEAA+B,GAA5C,UAA6C,UAAkB,EAAE,uBAAgD;;;;;;6BAC3G,CAAA,UAAU,KAAK,kCAAmB,CAAC,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,iCAAkB,CAAC,SAAS,CAAC,CAAA,EAA7F,wBAA6F;;;;wBAE7F,qBAAM,IAAI,CAAC,4BAA4B,CAAC,yBAAyB,CAAC,uBAAuB,CAAC,EAAA;;wBAA1F,SAA0F,CAAA;wBAE1F,sBAAO,IAAI,EAAA;;;wBAEX,sBAAO,KAAK,EAAA;;4BAGd,MAAM,IAAI,yBAAgB,CAAC,qBAAM,CAAC,QAAQ,EAAE,mBAAY,UAAU,mBAAgB,CAAC,CAAA;;;;;KAEtF;IACH,oCAAC;AAAD,CAAC,AAzGD,IAyGC;AAzGY,sEAA6B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TransactionValidator, TransactionValidatorV2 } from '@airgap/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,EAAE,iCAAiC;SAC3C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|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/v1/types/crypto.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
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<_ProtocolNetwork extends EthereumProtocolNetwork = EthereumProtocolNetwork> {
|
|
8
|
+
network: _ProtocolNetwork;
|
|
9
|
+
}
|
|
10
|
+
export interface EthereumBaseProtocolOptions<_Units extends string = EthereumUnits, _ProtocolNetwork extends EthereumProtocolNetwork = EthereumProtocolNetwork> extends EthereumProtocolOptions<_ProtocolNetwork> {
|
|
11
|
+
identifier: string;
|
|
12
|
+
name: string;
|
|
13
|
+
units: ProtocolUnitsMetadata<_Units>;
|
|
14
|
+
mainUnit: _Units;
|
|
15
|
+
feeDefaults?: FeeDefaults<EthereumUnits>;
|
|
16
|
+
standardDerivationPath?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ERC20ProtocolOptions<_Units extends string, _ProtocolNetwork extends EthereumProtocolNetwork = EthereumProtocolNetwork> extends EthereumProtocolOptions<_ProtocolNetwork> {
|
|
19
|
+
name: string;
|
|
20
|
+
identifier: string;
|
|
21
|
+
contractAddress: string;
|
|
22
|
+
units: ProtocolUnitsMetadata<_Units>;
|
|
23
|
+
mainUnit: _Units;
|
|
24
|
+
}
|
|
25
|
+
export interface ERC20TokenOptions<_ProtocolNetwork extends EthereumProtocolNetwork = EthereumProtocolNetwork> extends ERC20ProtocolOptions<string, _ProtocolNetwork> {
|
|
26
|
+
mainIdentifier: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ERC20TokenMetadata {
|
|
29
|
+
name: string;
|
|
30
|
+
identifier: string;
|
|
31
|
+
symbol: string;
|
|
32
|
+
marketSymbol: string;
|
|
33
|
+
contractAddress: string;
|
|
34
|
+
decimals: number;
|
|
35
|
+
}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/v1/types/transaction.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BigNumber } from '@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber';
|
|
2
|
+
export declare class EthereumUtils {
|
|
3
|
+
static toHex(value: any): string;
|
|
4
|
+
private static readonly SHA3_NULL_S;
|
|
5
|
+
static sha3(value: any): string | null;
|
|
6
|
+
static hexToNumber(value: string): BigNumber;
|
|
7
|
+
private static numberToHex;
|
|
8
|
+
private static hexToBytes;
|
|
9
|
+
private static isHexStrict;
|
|
10
|
+
private static checkAddressChecksum;
|
|
11
|
+
private static isAddress;
|
|
12
|
+
private static isBigNumber;
|
|
13
|
+
static hexToUtf8(value: string): string;
|
|
14
|
+
private static utf8ToHex;
|
|
15
|
+
private static isObject;
|
|
16
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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.hexToNumber = function (value) {
|
|
55
|
+
if (value.startsWith('0x')) {
|
|
56
|
+
value = value.slice(2);
|
|
57
|
+
}
|
|
58
|
+
if (value.startsWith('-0x')) {
|
|
59
|
+
value = "-".concat(value.slice(3));
|
|
60
|
+
}
|
|
61
|
+
return new bignumber_1.BigNumber(value, 16);
|
|
62
|
+
};
|
|
63
|
+
EthereumUtils.numberToHex = function (value) {
|
|
64
|
+
if (value === null || value === undefined) {
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
if (!isFinite(Number(value)) && !EthereumUtils.isHexStrict(value)) {
|
|
68
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.UTILS, "Given input \"".concat(JSON.stringify(value), "\" is not a number."));
|
|
69
|
+
}
|
|
70
|
+
// var number = EthereumUtils.toBN(value)
|
|
71
|
+
var myNumber = new bignumber_1.BigNumber(value);
|
|
72
|
+
var result = myNumber.toString(16);
|
|
73
|
+
return myNumber.lt(new bignumber_1.BigNumber(0)) ? "-0x".concat(result.substr(1)) : "0x".concat(result);
|
|
74
|
+
};
|
|
75
|
+
EthereumUtils.hexToBytes = function (value) {
|
|
76
|
+
var hex = typeof value === 'number' ? value.toString(16) : value;
|
|
77
|
+
if (!EthereumUtils.isHexStrict(hex)) {
|
|
78
|
+
throw new errors_1.InvalidValueError(coinlib_error_1.Domain.UTILS, "Given value \"".concat(JSON.stringify(hex), "\" is not a valid hex string."));
|
|
79
|
+
}
|
|
80
|
+
hex = hex.replace(/^0x/i, '');
|
|
81
|
+
var bytes = [];
|
|
82
|
+
for (var c = 0; c < hex.length; c += 2) {
|
|
83
|
+
bytes.push(parseInt(hex.substr(c, 2), 16));
|
|
84
|
+
}
|
|
85
|
+
return bytes;
|
|
86
|
+
};
|
|
87
|
+
EthereumUtils.isHexStrict = function (hex) {
|
|
88
|
+
return (typeof hex === 'string' || typeof hex === 'number') && /^(-)?0x[0-9a-f]*$/i.test(hex.toString());
|
|
89
|
+
};
|
|
90
|
+
EthereumUtils.checkAddressChecksum = function (value) {
|
|
91
|
+
var address = value.replace(/^0x/i, '');
|
|
92
|
+
var addressHash = EthereumUtils.sha3(address.toLowerCase());
|
|
93
|
+
if (addressHash === null) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
addressHash = addressHash.replace(/^0x/i, '');
|
|
97
|
+
for (var i = 0; i < 40; i++) {
|
|
98
|
+
if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) ||
|
|
99
|
+
(parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
};
|
|
105
|
+
EthereumUtils.isAddress = function (value) {
|
|
106
|
+
if (!/^(0x)?[0-9a-f]{40}$/i.test(value)) {
|
|
107
|
+
return false;
|
|
108
|
+
// If it's ALL lowercase or ALL upppercase
|
|
109
|
+
}
|
|
110
|
+
else if (/^(0x|0X)?[0-9a-f]{40}$/.test(value) || /^(0x|0X)?[0-9A-F]{40}$/.test(value)) {
|
|
111
|
+
return true;
|
|
112
|
+
// Otherwise check each case
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return EthereumUtils.checkAddressChecksum(value);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
EthereumUtils.isBigNumber = function (value) {
|
|
119
|
+
if (!value) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return bignumber_1.BigNumber.isBigNumber(value);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
EthereumUtils.hexToUtf8 = function (value) {
|
|
127
|
+
if (value.startsWith('0x')) {
|
|
128
|
+
value = value.slice(2);
|
|
129
|
+
}
|
|
130
|
+
return Buffer.from(value, 'hex').toString('utf-8');
|
|
131
|
+
};
|
|
132
|
+
EthereumUtils.utf8ToHex = function (value) {
|
|
133
|
+
var str = utf8.encode(value);
|
|
134
|
+
var hex = '';
|
|
135
|
+
// remove \u0000 padding from either side
|
|
136
|
+
str = str.replace(/^(?:\u0000)*/, '');
|
|
137
|
+
str = str.split('').reverse().join('');
|
|
138
|
+
str = str.replace(/^(?:\u0000)*/, '');
|
|
139
|
+
str = str.split('').reverse().join('');
|
|
140
|
+
for (var i = 0; i < str.length; i++) {
|
|
141
|
+
var code = str.charCodeAt(i);
|
|
142
|
+
var n = code.toString(16);
|
|
143
|
+
hex += n.length < 2 ? "0".concat(n) : n;
|
|
144
|
+
}
|
|
145
|
+
return "0x".concat(hex);
|
|
146
|
+
};
|
|
147
|
+
EthereumUtils.isObject = function (value) {
|
|
148
|
+
var type = typeof value;
|
|
149
|
+
return type === 'function' || (type === 'object' && !!value);
|
|
150
|
+
};
|
|
151
|
+
EthereumUtils.SHA3_NULL_S = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
|
|
152
|
+
return EthereumUtils;
|
|
153
|
+
}());
|
|
154
|
+
exports.EthereumUtils = EthereumUtils;
|
|
155
|
+
//# 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;IAyKA,CAAC;IAxKe,mBAAK,GAAnB,UAAoB,KAAU;QAC5B,IAAI,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YAClC,OAAO,YAAK,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAE,CAAA;SACtD;QAED,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE;YAC9B,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAA;SAC/B;QAED,IAAI,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,kCAAkC,EAAE;YACzG,OAAO,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CA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AEpB,yCAAyC;QACzC,GAAG,GAAG,GAAG,CAAC,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;QACtC,GAAG,GAAG,GAAG,CAAC,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;IA5IuB,yBAAW,GAAW,oEAAoE,CAAA;IA6IpH,oBAAC;CAAA,AAzKD,IAyKC;AAzKY,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;
|