@airgap/ethereum 0.13.20 → 0.13.21-beta.1
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/info/EthereumInfoClient.d.ts +7 -9
- package/v1/clients/info/EthereumInfoClient.js.map +1 -1
- package/v1/clients/info/EtherscanInfoClient.d.ts +1 -2
- package/v1/clients/info/EtherscanInfoClient.js +2 -0
- package/v1/clients/info/EtherscanInfoClient.js.map +1 -1
- package/v1/index.d.ts +6 -19
- package/v1/index.js +1 -16
- 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 +8 -84
- package/v1/protocol/EthereumBaseProtocol.js +7 -777
- package/v1/protocol/EthereumBaseProtocol.js.map +1 -1
- package/v1/protocol/EthereumProtocol.d.ts +7 -6
- package/v1/protocol/EthereumProtocol.js +3 -3
- package/v1/protocol/EthereumProtocol.js.map +1 -1
- package/v1/protocol/erc20/ERC20Token.d.ts +10 -15
- package/v1/protocol/erc20/ERC20Token.js +35 -26
- package/v1/protocol/erc20/ERC20Token.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +9 -10
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/utils/protocol.d.ts +5 -4
- package/v1/utils/protocol.js.map +1 -1
- package/v1/clients/crypto/EthereumCryptoClient.d.ts +0 -7
- package/v1/clients/crypto/EthereumCryptoClient.js +0 -147
- package/v1/clients/crypto/EthereumCryptoClient.js.map +0 -1
- package/v1/clients/node/EthereumNodeClient.d.ts +0 -18
- package/v1/clients/node/EthereumNodeClient.js +0 -3
- package/v1/clients/node/EthereumNodeClient.js.map +0 -1
- package/v1/clients/node/HttpEthereumNodeClient.d.ts +0 -66
- package/v1/clients/node/HttpEthereumNodeClient.js +0 -443
- package/v1/clients/node/HttpEthereumNodeClient.js.map +0 -1
- package/v1/data/EthereumAddress.d.ts +0 -7
- package/v1/data/EthereumAddress.js +0 -46
- package/v1/data/EthereumAddress.js.map +0 -1
- package/v1/protocol/EthereumChainIds.d.ts +0 -1
- package/v1/protocol/EthereumChainIds.js +0 -340
- package/v1/protocol/EthereumChainIds.js.map +0 -1
- package/v1/protocol/erc20/ERC20Protocol.d.ts +0 -32
- package/v1/protocol/erc20/ERC20Protocol.js +0 -397
- package/v1/protocol/erc20/ERC20Protocol.js.map +0 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +0 -8
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +0 -76
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +0 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.d.ts +0 -10
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum-typed.js.map +0 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.d.ts +0 -14
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-ethereum.js.map +0 -1
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.d.ts +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js +0 -3
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-ethereum.js.map +0 -1
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum-typed.json +0 -41
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-ethereum.json +0 -58
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-ethereum.json +0 -19
- package/v1/serializer/v3/validators/transaction-validator.d.ts +0 -7
- package/v1/serializer/v3/validators/transaction-validator.js +0 -71
- package/v1/serializer/v3/validators/transaction-validator.js.map +0 -1
- package/v1/types/crypto.d.ts +0 -2
- package/v1/types/crypto.js +0 -3
- package/v1/types/crypto.js.map +0 -1
- package/v1/types/protocol.d.ts +0 -35
- package/v1/types/protocol.js +0 -3
- package/v1/types/protocol.js.map +0 -1
- package/v1/types/transaction.d.ts +0 -24
- package/v1/types/transaction.js +0 -3
- package/v1/types/transaction.js.map +0 -1
- package/v1/utils/EthereumUtils.d.ts +0 -16
- package/v1/utils/EthereumUtils.js +0 -155
- package/v1/utils/EthereumUtils.js.map +0 -1
- package/v1/utils/key.d.ts +0 -5
- package/v1/utils/key.js +0 -101
- package/v1/utils/key.js.map +0 -1
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,E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gBAAK,EAAC,WAAW,EAAE,8BAA8B,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAChF,CAAC;IACM,gEAAyB,GAAhC,UAAiC,QAAyC;QACxE,OAAO,IAAA,gBAAK,EAAC,QAAQ,EAAE,4BAA4B,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC3E,CAAC;IACH,mCAAC;AAAD,CAAC,AAVD,IAUC;AAVY,oEAA4B"}
|
package/v1/types/crypto.d.ts
DELETED
package/v1/types/crypto.js
DELETED
package/v1/types/crypto.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/v1/types/crypto.ts"],"names":[],"mappings":""}
|
package/v1/types/protocol.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
package/v1/types/protocol.js
DELETED
package/v1/types/protocol.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/v1/types/protocol.ts"],"names":[],"mappings":""}
|
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
}
|
package/v1/types/transaction.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../../src/v1/types/transaction.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,155 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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AAK,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"}
|
package/v1/utils/key.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
package/v1/utils/key.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.convertExtendedPublicKey = exports.convertPublicKey = exports.convertExtendedSecretKey = exports.convertSecretKey = void 0;
|
|
27
|
-
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
var bs58check = __importStar(require("@airgap/coinlib-core/dependencies/src/bs58check-2.1.2"));
|
|
30
|
-
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
31
|
-
var module_kit_1 = require("@airgap/module-kit");
|
|
32
|
-
var EXT_SK_PREFIX = '0488b21e'; // xpriv
|
|
33
|
-
var EXT_PK_PREFIX = '0488b21e'; // xpub
|
|
34
|
-
function convertSecretKey(secretKey, targetFormat) {
|
|
35
|
-
if (secretKey.format === targetFormat) {
|
|
36
|
-
return secretKey;
|
|
37
|
-
}
|
|
38
|
-
// 'encoded' -> 'hex'
|
|
39
|
-
// 'hex' -> 'encoded'
|
|
40
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unsupported secret key format.');
|
|
41
|
-
}
|
|
42
|
-
exports.convertSecretKey = convertSecretKey;
|
|
43
|
-
function convertExtendedSecretKey(extendedSecretKey, targetFormat) {
|
|
44
|
-
if (extendedSecretKey.format === targetFormat) {
|
|
45
|
-
return extendedSecretKey;
|
|
46
|
-
}
|
|
47
|
-
switch (extendedSecretKey.format) {
|
|
48
|
-
case 'encoded':
|
|
49
|
-
if (targetFormat === 'encoded') {
|
|
50
|
-
return extendedSecretKey;
|
|
51
|
-
}
|
|
52
|
-
return (0, module_kit_1.newExtendedSecretKey)(decodeEncodedKey(EXT_SK_PREFIX, extendedSecretKey.value));
|
|
53
|
-
case 'hex':
|
|
54
|
-
if (targetFormat === 'hex') {
|
|
55
|
-
return extendedSecretKey;
|
|
56
|
-
}
|
|
57
|
-
return (0, module_kit_1.newExtendedSecretKey)(encodeHexKey(EXT_SK_PREFIX, extendedSecretKey.value));
|
|
58
|
-
default:
|
|
59
|
-
(0, coinlib_core_1.assertNever)(extendedSecretKey.format);
|
|
60
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unuspported extended secret key format.');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.convertExtendedSecretKey = convertExtendedSecretKey;
|
|
64
|
-
function convertPublicKey(publicKey, targetFormat) {
|
|
65
|
-
if (publicKey.format === targetFormat) {
|
|
66
|
-
return publicKey;
|
|
67
|
-
}
|
|
68
|
-
// 'encoded' -> 'hex'
|
|
69
|
-
// 'hex' -> 'encoded'
|
|
70
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unsupported public key format.');
|
|
71
|
-
}
|
|
72
|
-
exports.convertPublicKey = convertPublicKey;
|
|
73
|
-
function convertExtendedPublicKey(extendedPublicKey, targetFormat) {
|
|
74
|
-
if (extendedPublicKey.format === targetFormat) {
|
|
75
|
-
return extendedPublicKey;
|
|
76
|
-
}
|
|
77
|
-
switch (extendedPublicKey.format) {
|
|
78
|
-
case 'encoded':
|
|
79
|
-
if (targetFormat === 'encoded') {
|
|
80
|
-
return extendedPublicKey;
|
|
81
|
-
}
|
|
82
|
-
return (0, module_kit_1.newExtendedPublicKey)(decodeEncodedKey(EXT_PK_PREFIX, extendedPublicKey.value));
|
|
83
|
-
case 'hex':
|
|
84
|
-
if (targetFormat === 'hex') {
|
|
85
|
-
return extendedPublicKey;
|
|
86
|
-
}
|
|
87
|
-
return (0, module_kit_1.newExtendedPublicKey)(encodeHexKey(EXT_PK_PREFIX, extendedPublicKey.value));
|
|
88
|
-
default:
|
|
89
|
-
(0, coinlib_core_1.assertNever)(extendedPublicKey.format);
|
|
90
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.ETHEREUM, 'Unuspported extended public key format.');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
exports.convertExtendedPublicKey = convertExtendedPublicKey;
|
|
94
|
-
function decodeEncodedKey(prefix, key) {
|
|
95
|
-
var prefixBytes = Buffer.from(prefix, 'hex').length;
|
|
96
|
-
return bs58check.decode(key).slice(prefixBytes).toString('hex');
|
|
97
|
-
}
|
|
98
|
-
function encodeHexKey(prefix, key) {
|
|
99
|
-
return bs58check.encode(Buffer.concat([Buffer.from(prefix, 'hex'), Buffer.from(key, 'hex')]));
|
|
100
|
-
}
|
|
101
|
-
//# sourceMappingURL=key.js.map
|
package/v1/utils/key.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/v1/utils/key.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA0D;AAC1D,aAAa;AACb,+FAAkF;AAClF,sDAA8D;AAC9D,iDAA2I;AAE3I,IAAM,aAAa,GAAW,UAAU,CAAA,CAAC,QAAQ;AACjD,IAAM,aAAa,GAAW,UAAU,CAAA,CAAC,OAAO;AAEhD,SAAgB,gBAAgB,CAAC,SAAoB,EAAE,YAAiC;IACtF,IAAI,SAAS,CAAC,MAAM,KAAK,YAAY,EAAE;QACrC,OAAO,SAAS,CAAA;KACjB;IAED,qBAAqB;IACrB,yBAAyB;IACzB,MAAM,IAAI,yBAAgB,CAAC,qBAAM,CAAC,QAAQ,EAAE,gCAAgC,CAAC,CAAA;AAC/E,CAAC;AARD,4CAQ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