essential-eth 0.5.11-next.1 → 0.5.13-next.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/dist/{classes → cjs/classes}/Contract.d.ts +0 -0
- package/dist/cjs/classes/Contract.js +140 -0
- package/dist/{classes → cjs/classes}/test/Contract/crv-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/crv-abi.js +488 -0
- package/dist/{classes → cjs/classes}/test/Contract/ens-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/ens-abi.js +453 -0
- package/dist/{classes → cjs/classes}/test/Contract/fei-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/fei-abi.js +526 -0
- package/dist/{classes → cjs/classes}/test/Contract/foo-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/foo-abi.js +42 -0
- package/dist/{classes → cjs/classes}/test/Contract/uniswap-abi.d.ts +0 -0
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +121 -0
- package/dist/{classes → cjs/classes}/utils/clean-block.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-block.js +160 -0
- package/dist/{classes → cjs/classes}/utils/clean-log.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-log.js +37 -0
- package/dist/{classes → cjs/classes}/utils/clean-transaction-receipt.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +50 -0
- package/dist/{classes → cjs/classes}/utils/clean-transaction.d.ts +0 -0
- package/dist/cjs/classes/utils/clean-transaction.js +51 -0
- package/dist/{classes → cjs/classes}/utils/encode-decode-transaction.d.ts +0 -0
- package/dist/cjs/classes/utils/encode-decode-transaction.js +137 -0
- package/dist/{classes → cjs/classes}/utils/fetchers.d.ts +0 -0
- package/dist/cjs/classes/utils/fetchers.js +81 -0
- package/dist/{classes → cjs/classes}/utils/hex-to-decimal.d.ts +0 -0
- package/dist/cjs/classes/utils/hex-to-decimal.js +24 -0
- package/dist/{classes → cjs/classes}/utils/prepare-transaction.d.ts +0 -0
- package/dist/cjs/classes/utils/prepare-transaction.js +45 -0
- package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- package/dist/cjs/index.js +54 -0
- package/dist/cjs/index.umd.js +2 -0
- package/dist/cjs/index.umd.js.map +1 -0
- package/dist/{logger → cjs/logger}/logger.d.ts +0 -0
- package/dist/cjs/logger/logger.js +36 -0
- package/dist/cjs/logger/package-version.d.ts +1 -0
- package/dist/cjs/logger/package-version.js +5 -0
- package/dist/{providers → cjs/providers}/BaseProvider.d.ts +0 -0
- package/dist/cjs/providers/BaseProvider.js +512 -0
- package/dist/{providers → cjs/providers}/FallthroughProvider.d.ts +0 -0
- package/dist/cjs/providers/FallthroughProvider.js +65 -0
- package/dist/{providers → cjs/providers}/JsonRpcProvider.d.ts +0 -0
- package/dist/cjs/providers/JsonRpcProvider.js +46 -0
- package/dist/{providers → cjs/providers}/test/rpc-urls.d.ts +0 -0
- package/dist/cjs/providers/test/rpc-urls.js +14 -0
- package/dist/{providers → cjs/providers}/utils/chains-info.d.ts +0 -0
- package/dist/cjs/providers/utils/chains-info.js +1402 -0
- package/dist/{shared → cjs/shared}/tiny-big/helpers.d.ts +0 -0
- package/dist/cjs/shared/tiny-big/helpers.js +97 -0
- package/dist/{shared → cjs/shared}/tiny-big/tiny-big.d.ts +0 -0
- package/dist/cjs/shared/tiny-big/tiny-big.js +101 -0
- package/dist/{shared → cjs/shared}/validate-type.d.ts +0 -0
- package/dist/cjs/shared/validate-type.js +9 -0
- package/dist/{types → cjs/types}/Block.types.d.ts +0 -0
- package/dist/cjs/types/Block.types.js +2 -0
- package/dist/{types → cjs/types}/Contract.types.d.ts +0 -0
- package/dist/cjs/types/Contract.types.js +2 -0
- package/dist/{types → cjs/types}/Filter.types.d.ts +0 -0
- package/dist/cjs/types/Filter.types.js +2 -0
- package/dist/{types → cjs/types}/Network.types.d.ts +0 -0
- package/dist/cjs/types/Network.types.js +2 -0
- package/dist/{types → cjs/types}/Transaction.types.d.ts +0 -0
- package/dist/cjs/types/Transaction.types.js +2 -0
- package/dist/{utils → cjs/utils}/bytes.d.ts +0 -0
- package/dist/cjs/utils/bytes.js +711 -0
- package/dist/{utils → cjs/utils}/compute-address.d.ts +0 -0
- package/dist/cjs/utils/compute-address.js +33 -0
- package/dist/{utils → cjs/utils}/compute-public-key.d.ts +0 -0
- package/dist/cjs/utils/compute-public-key.js +26 -0
- package/dist/{utils → cjs/utils}/ether-to-gwei.d.ts +0 -0
- package/dist/cjs/utils/ether-to-gwei.js +35 -0
- package/dist/{utils → cjs/utils}/ether-to-wei.d.ts +0 -0
- package/dist/cjs/utils/ether-to-wei.js +35 -0
- package/dist/{utils → cjs/utils}/gwei-to-ether.d.ts +0 -0
- package/dist/cjs/utils/gwei-to-ether.js +35 -0
- package/dist/{utils → cjs/utils}/hash-message.d.ts +0 -0
- package/dist/cjs/utils/hash-message.js +28 -0
- package/dist/{utils → cjs/utils}/is-address.d.ts +0 -0
- package/dist/cjs/utils/is-address.js +39 -0
- package/dist/{utils → cjs/utils}/keccak256.d.ts +0 -0
- package/dist/cjs/utils/keccak256.js +31 -0
- package/dist/{utils → cjs/utils}/solidity-keccak256.d.ts +0 -0
- package/dist/cjs/utils/solidity-keccak256.js +138 -0
- package/dist/{utils → cjs/utils}/split-signature.d.ts +0 -0
- package/dist/cjs/utils/split-signature.js +163 -0
- package/dist/{utils → cjs/utils}/to-checksum-address.d.ts +0 -0
- package/dist/cjs/utils/to-checksum-address.js +46 -0
- package/dist/{utils → cjs/utils}/to-utf8-bytes.d.ts +0 -0
- package/dist/cjs/utils/to-utf8-bytes.js +21 -0
- package/dist/{utils → cjs/utils}/wei-to-ether.d.ts +0 -0
- package/dist/cjs/utils/wei-to-ether.js +45 -0
- package/dist/esm/classes/Contract.d.ts +11 -0
- package/dist/esm/classes/Contract.js +65 -0
- package/dist/esm/classes/test/Contract/crv-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/crv-abi.js +470 -0
- package/dist/esm/classes/test/Contract/ens-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/ens-abi.js +435 -0
- package/dist/esm/classes/test/Contract/fei-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/fei-abi.js +521 -0
- package/dist/esm/classes/test/Contract/foo-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/foo-abi.js +33 -0
- package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/dist/esm/classes/test/Contract/uniswap-abi.js +116 -0
- package/dist/esm/classes/utils/clean-block.d.ts +3 -0
- package/dist/esm/classes/utils/clean-block.js +35 -0
- package/dist/esm/classes/utils/clean-log.d.ts +2 -0
- package/dist/esm/classes/utils/clean-log.js +26 -0
- package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
- package/dist/esm/classes/utils/clean-transaction-receipt.js +34 -0
- package/dist/esm/classes/utils/clean-transaction.d.ts +2 -0
- package/dist/esm/classes/utils/clean-transaction.js +33 -0
- package/dist/esm/classes/utils/encode-decode-transaction.d.ts +4 -0
- package/dist/esm/classes/utils/encode-decode-transaction.js +98 -0
- package/dist/esm/classes/utils/fetchers.d.ts +9 -0
- package/dist/esm/classes/utils/fetchers.js +43 -0
- package/dist/esm/classes/utils/hex-to-decimal.d.ts +1 -0
- package/dist/esm/classes/utils/hex-to-decimal.js +3 -0
- package/dist/esm/classes/utils/prepare-transaction.d.ts +2 -0
- package/dist/esm/classes/utils/prepare-transaction.js +34 -0
- package/dist/esm/index.d.ts +25 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/logger/logger.d.ts +11 -0
- package/dist/esm/logger/logger.js +33 -0
- package/dist/esm/logger/package-version.d.ts +1 -0
- package/dist/esm/logger/package-version.js +1 -0
- package/dist/esm/providers/BaseProvider.d.ts +24 -0
- package/dist/esm/providers/BaseProvider.js +157 -0
- package/dist/esm/providers/FallthroughProvider.d.ts +11 -0
- package/dist/esm/providers/FallthroughProvider.js +41 -0
- package/dist/esm/providers/JsonRpcProvider.d.ts +7 -0
- package/dist/esm/providers/JsonRpcProvider.js +15 -0
- package/dist/esm/providers/test/rpc-urls.d.ts +11 -0
- package/dist/esm/providers/test/rpc-urls.js +11 -0
- package/dist/esm/providers/utils/chains-info.d.ts +467 -0
- package/dist/esm/providers/utils/chains-info.js +1398 -0
- package/dist/esm/shared/tiny-big/helpers.d.ts +1 -0
- package/dist/esm/shared/tiny-big/helpers.js +58 -0
- package/dist/esm/shared/tiny-big/tiny-big.d.ts +10 -0
- package/dist/esm/shared/tiny-big/tiny-big.js +45 -0
- package/dist/esm/shared/validate-type.d.ts +3 -0
- package/dist/esm/shared/validate-type.js +5 -0
- package/dist/esm/types/Block.types.d.ts +40 -0
- package/dist/esm/types/Block.types.js +1 -0
- package/dist/esm/types/Contract.types.d.ts +24 -0
- package/dist/esm/types/Contract.types.js +1 -0
- package/dist/esm/types/Filter.types.d.ts +12 -0
- package/dist/esm/types/Filter.types.js +1 -0
- package/dist/esm/types/Network.types.d.ts +5 -0
- package/dist/esm/types/Network.types.js +1 -0
- package/dist/esm/types/Transaction.types.d.ts +113 -0
- package/dist/esm/types/Transaction.types.js +1 -0
- package/dist/esm/utils/bytes.d.ts +40 -0
- package/dist/esm/utils/bytes.js +245 -0
- package/dist/esm/utils/compute-address.d.ts +1 -0
- package/dist/esm/utils/compute-address.js +11 -0
- package/dist/esm/utils/compute-public-key.d.ts +2 -0
- package/dist/esm/utils/compute-public-key.js +6 -0
- package/dist/esm/utils/ether-to-gwei.d.ts +3 -0
- package/dist/esm/utils/ether-to-gwei.js +7 -0
- package/dist/esm/utils/ether-to-wei.d.ts +3 -0
- package/dist/esm/utils/ether-to-wei.js +7 -0
- package/dist/esm/utils/gwei-to-ether.d.ts +3 -0
- package/dist/esm/utils/gwei-to-ether.js +7 -0
- package/dist/esm/utils/hash-message.d.ts +2 -0
- package/dist/esm/utils/hash-message.js +12 -0
- package/dist/esm/utils/is-address.d.ts +1 -0
- package/dist/esm/utils/is-address.js +12 -0
- package/dist/esm/utils/keccak256.d.ts +2 -0
- package/dist/esm/utils/keccak256.js +13 -0
- package/dist/esm/utils/solidity-keccak256.d.ts +2 -0
- package/dist/esm/utils/solidity-keccak256.js +85 -0
- package/dist/esm/utils/split-signature.d.ts +2 -0
- package/dist/esm/utils/split-signature.js +126 -0
- package/dist/esm/utils/to-checksum-address.d.ts +1 -0
- package/dist/esm/utils/to-checksum-address.js +25 -0
- package/dist/esm/utils/to-utf8-bytes.d.ts +1 -0
- package/dist/esm/utils/to-utf8-bytes.js +3 -0
- package/dist/esm/utils/wei-to-ether.d.ts +3 -0
- package/dist/esm/utils/wei-to-ether.js +16 -0
- package/package.json +10 -10
- package/readme.md +5 -1
- package/dist/index.js +0 -1904
- package/dist/index.js.map +0 -1
- package/dist/index.module.js +0 -1865
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.js +0 -2
- package/dist/index.umd.js.map +0 -1
- package/dist/logger/package-version.d.ts +0 -1
package/dist/index.module.js
DELETED
|
@@ -1,1865 +0,0 @@
|
|
|
1
|
-
import { Keccak } from 'sha3';
|
|
2
|
-
import unfetch from 'isomorphic-unfetch';
|
|
3
|
-
import Big from 'big.js';
|
|
4
|
-
import { Point } from '@noble/secp256k1';
|
|
5
|
-
import { Buffer as Buffer$1 } from 'buffer';
|
|
6
|
-
|
|
7
|
-
function _extends() {
|
|
8
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
9
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
10
|
-
var source = arguments[i];
|
|
11
|
-
|
|
12
|
-
for (var key in source) {
|
|
13
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
14
|
-
target[key] = source[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return target;
|
|
20
|
-
};
|
|
21
|
-
return _extends.apply(this, arguments);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function hexToDecimal(hex) {
|
|
25
|
-
return BigInt(hex).toString();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const hexFalse = '0'.repeat(64);
|
|
29
|
-
const hexTrue = '0'.repeat(63) + '1';
|
|
30
|
-
|
|
31
|
-
function expandType(type) {
|
|
32
|
-
if (type === 'uint[]') {
|
|
33
|
-
return 'uint256[]';
|
|
34
|
-
} else if (type === 'int[]') {
|
|
35
|
-
return 'int256[]';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return type;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function encodeData(jsonABIArgument, args) {
|
|
42
|
-
const hash = new Keccak(256);
|
|
43
|
-
const functionString = `${jsonABIArgument.name}(${jsonABIArgument.inputs.map(input => expandType(input.type))})`;
|
|
44
|
-
const functionHash = hash.update(functionString).digest('hex');
|
|
45
|
-
const jsonABIInputsLength = jsonABIArgument.inputs.length;
|
|
46
|
-
let shouldValidateInputLength = true;
|
|
47
|
-
|
|
48
|
-
if (jsonABIArgument.inputs.find(input => input.type.includes('['))) {
|
|
49
|
-
shouldValidateInputLength = false;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (shouldValidateInputLength && args.length !== jsonABIInputsLength) {
|
|
53
|
-
throw new Error(`args inputs of "${args.length}" does not match expected length of "${jsonABIArgument.inputs.length}"`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const argsWithTypes = (jsonABIArgument.inputs || []).reduce((acc, input, i) => {
|
|
57
|
-
if (input.type.includes('[')) {
|
|
58
|
-
var _exec;
|
|
59
|
-
|
|
60
|
-
const basicType = (_exec = /([^[]*)\[.*$/g.exec(input.type)) == null ? void 0 : _exec[1];
|
|
61
|
-
args.forEach(arg => {
|
|
62
|
-
acc = acc.concat([[arg, basicType]]);
|
|
63
|
-
});
|
|
64
|
-
return acc;
|
|
65
|
-
} else {
|
|
66
|
-
return acc.concat([[args[i], input.type]]);
|
|
67
|
-
}
|
|
68
|
-
}, []);
|
|
69
|
-
const encodedArgs = argsWithTypes.map(([arg, inputType]) => {
|
|
70
|
-
let rawArg = arg;
|
|
71
|
-
|
|
72
|
-
switch (inputType) {
|
|
73
|
-
case 'bool':
|
|
74
|
-
return arg ? hexTrue : hexFalse;
|
|
75
|
-
|
|
76
|
-
case 'address':
|
|
77
|
-
rawArg = arg.replace(/^0x/g, '').toLowerCase();
|
|
78
|
-
break;
|
|
79
|
-
|
|
80
|
-
default:
|
|
81
|
-
if (inputType.startsWith('bytes')) {
|
|
82
|
-
const argEncoded = rawArg.split('').map(character => character.charCodeAt(0).toString(16)).join('');
|
|
83
|
-
const paddedEncodedArg = argEncoded.padEnd(64, '0');
|
|
84
|
-
return paddedEncodedArg;
|
|
85
|
-
} else if (inputType === 'uint256') {
|
|
86
|
-
const argEncoded = BigInt(arg).toString(16);
|
|
87
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
88
|
-
return paddedEncodedArg;
|
|
89
|
-
} else if (inputType.startsWith('uint')) {
|
|
90
|
-
break;
|
|
91
|
-
} else {
|
|
92
|
-
throw new Error(`essential-eth does not yet support "${inputType}" inputs. Make a PR today!"`);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const argEncoded = rawArg.toString(16);
|
|
98
|
-
const paddedEncodedArg = argEncoded.padStart(64, '0');
|
|
99
|
-
return paddedEncodedArg;
|
|
100
|
-
});
|
|
101
|
-
const functionEncoded = functionHash.slice(0, 8);
|
|
102
|
-
const data = `0x${functionEncoded}${encodedArgs.join('')}`;
|
|
103
|
-
return data;
|
|
104
|
-
}
|
|
105
|
-
function decodeRPCResponse(jsonABIArgument, nodeResponse) {
|
|
106
|
-
const rawOutputs = jsonABIArgument.outputs;
|
|
107
|
-
const encodedOutputs = nodeResponse.slice(2).match(/.{1,64}/g);
|
|
108
|
-
const outputs = (encodedOutputs || []).map((output, i) => {
|
|
109
|
-
const outputType = (rawOutputs || [])[i].type;
|
|
110
|
-
|
|
111
|
-
switch (outputType) {
|
|
112
|
-
case 'bool':
|
|
113
|
-
return output === hexTrue;
|
|
114
|
-
|
|
115
|
-
case 'address':
|
|
116
|
-
return toChecksumAddress(`0x${output.slice(24)}`);
|
|
117
|
-
|
|
118
|
-
case 'uint256':
|
|
119
|
-
return tinyBig(hexToDecimal(`0x${output}`));
|
|
120
|
-
|
|
121
|
-
case 'bytes32':
|
|
122
|
-
return `0x${output}`;
|
|
123
|
-
|
|
124
|
-
case 'uint8':
|
|
125
|
-
return Number(hexToDecimal(`0x${output}`));
|
|
126
|
-
|
|
127
|
-
default:
|
|
128
|
-
throw new Error(`essential-eth does not yet support "${outputType}" outputs. Make a PR today!"`);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
return outputs.length === 1 ? outputs[0] : outputs;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function post(url, body) {
|
|
135
|
-
return unfetch(url, {
|
|
136
|
-
method: 'POST',
|
|
137
|
-
headers: {
|
|
138
|
-
'Content-Type': 'application/json'
|
|
139
|
-
},
|
|
140
|
-
body: JSON.stringify(body)
|
|
141
|
-
}).then(async r => {
|
|
142
|
-
const t = await r.text();
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
return JSON.parse(t);
|
|
146
|
-
} catch (_unused) {
|
|
147
|
-
throw new Error(`Invalid JSON RPC response: "${t}"`);
|
|
148
|
-
}
|
|
149
|
-
}).then(response => {
|
|
150
|
-
const result = response == null ? void 0 : response.result;
|
|
151
|
-
|
|
152
|
-
if (!result) {
|
|
153
|
-
throw new Error(`Invalid JSON RPC response: ${JSON.stringify(response)}`);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return response.result;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function buildRPCPostBody(method, params) {
|
|
160
|
-
return {
|
|
161
|
-
jsonrpc: '2.0',
|
|
162
|
-
id: 1,
|
|
163
|
-
method,
|
|
164
|
-
params
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function estimateGas(txnData) {
|
|
169
|
-
txnData.split('').reduce((previousValue, currentValue) => {
|
|
170
|
-
const characterCost = currentValue === '0' ? 4 : 68;
|
|
171
|
-
return previousValue + characterCost;
|
|
172
|
-
}, 0);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
class BaseContract {
|
|
176
|
-
constructor(addressOrName, contractInterface, signerOrProvider) {
|
|
177
|
-
this._address = void 0;
|
|
178
|
-
this._provider = void 0;
|
|
179
|
-
this._address = addressOrName;
|
|
180
|
-
this._provider = signerOrProvider;
|
|
181
|
-
contractInterface.filter(jsonABIArgument => jsonABIArgument.type === 'function').forEach(jsonABIArgument => {
|
|
182
|
-
if ('name' in jsonABIArgument && typeof jsonABIArgument.name === 'string') {
|
|
183
|
-
defineReadOnly(this, jsonABIArgument.name, async (..._args) => {
|
|
184
|
-
let functionArguments = _args;
|
|
185
|
-
let options = {};
|
|
186
|
-
const lastArg = _args[_args.length - 1];
|
|
187
|
-
|
|
188
|
-
if (!Array.isArray(lastArg) && typeof lastArg === 'object') {
|
|
189
|
-
options = lastArg;
|
|
190
|
-
functionArguments = _args.slice(0, _args.length - 1);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const data = encodeData(jsonABIArgument, functionArguments);
|
|
194
|
-
const decimalGas = typeof options.gasLimit === 'number' ? options.gasLimit : typeof (jsonABIArgument == null ? void 0 : jsonABIArgument.gas) === 'number' ? estimateGas(data) : null;
|
|
195
|
-
|
|
196
|
-
const req = async () => {
|
|
197
|
-
return await post(this._provider.selectRpcUrl(), buildRPCPostBody('eth_call', [_extends({
|
|
198
|
-
to: this._address.toLowerCase(),
|
|
199
|
-
data
|
|
200
|
-
}, decimalGas ? {
|
|
201
|
-
gas: `0x${decimalGas.toString(16)}`
|
|
202
|
-
} : {}), 'latest']));
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
const nodeResponse = await req();
|
|
206
|
-
return decodeRPCResponse(jsonABIArgument, nodeResponse);
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
function defineReadOnly(object, name, value) {
|
|
214
|
-
Object.defineProperty(object, name, {
|
|
215
|
-
enumerable: true,
|
|
216
|
-
value: value,
|
|
217
|
-
writable: false
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
class Contract extends BaseContract {}
|
|
221
|
-
|
|
222
|
-
const version = '0.5.11-next.1';
|
|
223
|
-
|
|
224
|
-
class Logger {
|
|
225
|
-
constructor() {
|
|
226
|
-
this.packageVersion = void 0;
|
|
227
|
-
this.packageVersion = version;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
throwError(message, args) {
|
|
231
|
-
const argsLength = Object.keys(args).length;
|
|
232
|
-
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
throwArgumentError(message, arg, value) {
|
|
236
|
-
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
checkSafeUint53(value, message = 'value not safe') {
|
|
240
|
-
if (typeof value !== 'number') {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
245
|
-
this.throwError(message, {
|
|
246
|
-
operation: 'checkSafeInteger',
|
|
247
|
-
fault: 'out-of-safe-range',
|
|
248
|
-
value: value
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (value % 1) {
|
|
253
|
-
this.throwError(message, {
|
|
254
|
-
operation: 'checkSafeInteger',
|
|
255
|
-
fault: 'non-integer',
|
|
256
|
-
value: value
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const logger = new Logger();
|
|
264
|
-
|
|
265
|
-
function stripTrailingZeroes(numberString) {
|
|
266
|
-
const isNegative = numberString.startsWith('-');
|
|
267
|
-
numberString = numberString.replace('-', '');
|
|
268
|
-
numberString = numberString.replace(/\.0*$/g, '');
|
|
269
|
-
numberString = numberString.replace(/^0+/, '');
|
|
270
|
-
|
|
271
|
-
if (numberString.includes('.')) {
|
|
272
|
-
numberString = numberString.replace(/0+$/, '');
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (numberString.startsWith('.')) {
|
|
276
|
-
numberString = `0${numberString}`;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
return `${isNegative ? '-' : ''}${numberString}`;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function scientificStrToDecimalStr(scientificString) {
|
|
283
|
-
if (!scientificString.match(/e/i)) {
|
|
284
|
-
return stripTrailingZeroes(scientificString);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
let [base, power] = scientificString.split(/e/i);
|
|
288
|
-
const isNegative = Number(base) < 0;
|
|
289
|
-
base = base.replace('-', '');
|
|
290
|
-
base = stripTrailingZeroes(base);
|
|
291
|
-
const [wholeNumber, fraction = ''] = base.split('.');
|
|
292
|
-
|
|
293
|
-
if (Number(power) === 0) {
|
|
294
|
-
return `${isNegative ? '-' : ''}${stripTrailingZeroes(base)}`;
|
|
295
|
-
} else {
|
|
296
|
-
const includesDecimal = base.includes('.');
|
|
297
|
-
|
|
298
|
-
if (!includesDecimal) {
|
|
299
|
-
base = `${base}.`;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
base = base.replace('.', '');
|
|
303
|
-
const baseLength = base.length;
|
|
304
|
-
let splitPaddedNumber;
|
|
305
|
-
|
|
306
|
-
if (Number(power) < 0) {
|
|
307
|
-
if (wholeNumber.length < Math.abs(Number(power))) {
|
|
308
|
-
base = base.padStart(baseLength + Math.abs(Number(power)) - wholeNumber.length, '0');
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
splitPaddedNumber = base.split('');
|
|
312
|
-
|
|
313
|
-
if (wholeNumber.length < Math.abs(Number(power))) {
|
|
314
|
-
splitPaddedNumber = ['.', ...splitPaddedNumber];
|
|
315
|
-
} else {
|
|
316
|
-
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
|
|
317
|
-
}
|
|
318
|
-
} else {
|
|
319
|
-
if (fraction.length < Math.abs(Number(power))) {
|
|
320
|
-
base = base.padEnd(baseLength + Math.abs(Number(power)) - fraction.length, '0');
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
splitPaddedNumber = base.split('');
|
|
324
|
-
|
|
325
|
-
if (fraction.length > Math.abs(Number(power))) {
|
|
326
|
-
splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const toReturn = stripTrailingZeroes(splitPaddedNumber.join(''));
|
|
331
|
-
return `${isNegative ? '-' : ''}${toReturn}`;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
class TinyBig extends Big {
|
|
336
|
-
constructor(value) {
|
|
337
|
-
if (typeof value === 'string' && value.startsWith('0x')) {
|
|
338
|
-
value = hexToDecimal(value);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
super(value);
|
|
342
|
-
|
|
343
|
-
this.padAndChop = (str, padChar, length) => {
|
|
344
|
-
return (Array(length).fill(padChar).join('') + str).slice(length * -1);
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
toHexString() {
|
|
349
|
-
return `0x${BigInt(this.toString()).toString(16)}`;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
toNumber() {
|
|
353
|
-
return Number(scientificStrToDecimalStr(super.toString()));
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
toString() {
|
|
357
|
-
if (this.toNumber() === 0) {
|
|
358
|
-
return '0';
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return scientificStrToDecimalStr(super.toString());
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
toTwos(bitCount) {
|
|
365
|
-
let binaryStr;
|
|
366
|
-
|
|
367
|
-
if (this.gte(0)) {
|
|
368
|
-
const twosComp = this.toNumber().toString(2);
|
|
369
|
-
binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
|
|
370
|
-
} else {
|
|
371
|
-
binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
|
|
372
|
-
|
|
373
|
-
if (Number(binaryStr) < 0) {
|
|
374
|
-
throw new Error('Cannot calculate twos complement');
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const binary = `0b${binaryStr}`;
|
|
379
|
-
const decimal = Number(binary);
|
|
380
|
-
return tinyBig(decimal);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
}
|
|
384
|
-
function tinyBig(value) {
|
|
385
|
-
return new TinyBig(value);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function cleanTransaction(transaction) {
|
|
389
|
-
const cleanedTransaction = _extends({}, transaction);
|
|
390
|
-
|
|
391
|
-
Object.keys(transaction).forEach(key => {
|
|
392
|
-
if (!transaction[key]) return;
|
|
393
|
-
|
|
394
|
-
switch (key) {
|
|
395
|
-
case 'blockNumber':
|
|
396
|
-
case 'chainId':
|
|
397
|
-
case 'transactionIndex':
|
|
398
|
-
case 'type':
|
|
399
|
-
case 'v':
|
|
400
|
-
cleanedTransaction[key] = Number(hexToDecimal(transaction[key]));
|
|
401
|
-
break;
|
|
402
|
-
|
|
403
|
-
case 'from':
|
|
404
|
-
case 'to':
|
|
405
|
-
if (transaction[key]) {
|
|
406
|
-
cleanedTransaction[key] = toChecksumAddress(transaction[key]);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
break;
|
|
410
|
-
|
|
411
|
-
case 'value':
|
|
412
|
-
case 'gas':
|
|
413
|
-
case 'gasPrice':
|
|
414
|
-
case 'maxFeePerGas':
|
|
415
|
-
case 'maxPriorityFeePerGas':
|
|
416
|
-
case 'nonce':
|
|
417
|
-
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
418
|
-
break;
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
return cleanedTransaction;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
function cleanBlock(block, returnTransactionObjects) {
|
|
425
|
-
const cleanedBlock = _extends({}, block);
|
|
426
|
-
|
|
427
|
-
Object.keys(block).forEach(key => {
|
|
428
|
-
if (!block[key]) return;
|
|
429
|
-
|
|
430
|
-
switch (key) {
|
|
431
|
-
case 'difficulty':
|
|
432
|
-
case 'totalDifficulty':
|
|
433
|
-
case 'gasLimit':
|
|
434
|
-
case 'gasUsed':
|
|
435
|
-
case 'size':
|
|
436
|
-
case 'timestamp':
|
|
437
|
-
case 'baseFeePerGas':
|
|
438
|
-
cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
|
|
439
|
-
break;
|
|
440
|
-
|
|
441
|
-
case 'number':
|
|
442
|
-
cleanedBlock[key] = Number(hexToDecimal(block[key]));
|
|
443
|
-
break;
|
|
444
|
-
|
|
445
|
-
case 'miner':
|
|
446
|
-
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
if (returnTransactionObjects) {
|
|
452
|
-
const txns = block.transactions;
|
|
453
|
-
txns.forEach((transaction, index) => {
|
|
454
|
-
cleanedBlock.transactions[index] = cleanTransaction(transaction);
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return cleanedBlock;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
const validateType = (value, allowedTypes) => {
|
|
462
|
-
if (!allowedTypes.includes(typeof value)) {
|
|
463
|
-
throw new Error(`${allowedTypes.join(' or ')} required. Received ${typeof value}`);
|
|
464
|
-
}
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
function toChecksumAddress(address) {
|
|
468
|
-
validateType(address, ['string']);
|
|
469
|
-
|
|
470
|
-
if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
|
|
471
|
-
throw new Error(`Invalid Ethereum address "${address}"`);
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
const _address = address.toLowerCase().replace(/^0x/i, '');
|
|
475
|
-
|
|
476
|
-
const keccak = new Keccak(256);
|
|
477
|
-
const addressHash = keccak.update(_address).digest('hex').replace(/^0x/i, '');
|
|
478
|
-
let checksumAddress = '0x';
|
|
479
|
-
|
|
480
|
-
for (let i = 0; i < _address.length; i++) {
|
|
481
|
-
if (parseInt(addressHash[i], 16) > 7) {
|
|
482
|
-
checksumAddress += _address[i].toUpperCase();
|
|
483
|
-
} else {
|
|
484
|
-
checksumAddress += _address[i];
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && checksumAddress !== address) {
|
|
489
|
-
throw new Error(`Invalid Checksum address for "${address}"`);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return checksumAddress;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
function cleanLog(log, receiptLog) {
|
|
496
|
-
const cleanedLog = _extends({}, log);
|
|
497
|
-
|
|
498
|
-
Object.keys(log).forEach(key => {
|
|
499
|
-
switch (key) {
|
|
500
|
-
case 'address':
|
|
501
|
-
cleanedLog[key] = toChecksumAddress(log[key]);
|
|
502
|
-
break;
|
|
503
|
-
|
|
504
|
-
case 'blockNumber':
|
|
505
|
-
case 'logIndex':
|
|
506
|
-
case 'transactionIndex':
|
|
507
|
-
cleanedLog[key] = Number(hexToDecimal(log[key]));
|
|
508
|
-
break;
|
|
509
|
-
|
|
510
|
-
case 'removed':
|
|
511
|
-
if (receiptLog) {
|
|
512
|
-
delete cleanedLog[key];
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
});
|
|
518
|
-
return cleanedLog;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
function cleanTransactionReceipt(transactionReceipt) {
|
|
522
|
-
const cleanedTransaction = cleanTransaction(transactionReceipt);
|
|
523
|
-
|
|
524
|
-
const cleanedTransactionReceipt = _extends({}, cleanedTransaction);
|
|
525
|
-
|
|
526
|
-
Object.keys(transactionReceipt).forEach(key => {
|
|
527
|
-
if (!transactionReceipt[key]) return;
|
|
528
|
-
|
|
529
|
-
switch (key) {
|
|
530
|
-
case 'status':
|
|
531
|
-
cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
|
|
532
|
-
break;
|
|
533
|
-
|
|
534
|
-
case 'contractAddress':
|
|
535
|
-
if (transactionReceipt[key]) {
|
|
536
|
-
cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
break;
|
|
540
|
-
|
|
541
|
-
case 'cumulativeGasUsed':
|
|
542
|
-
case 'effectiveGasPrice':
|
|
543
|
-
case 'gasUsed':
|
|
544
|
-
cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
|
|
545
|
-
break;
|
|
546
|
-
|
|
547
|
-
case 'logs':
|
|
548
|
-
transactionReceipt[key].forEach((log, index) => {
|
|
549
|
-
cleanedTransactionReceipt[key][index] = cleanLog(log, true);
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
cleanedTransactionReceipt.byzantium = cleanedTransactionReceipt.blockNumber >= 4370000;
|
|
554
|
-
return cleanedTransactionReceipt;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
function isHexable(value) {
|
|
558
|
-
return !!value.toHexString;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
function isBytesLike(value) {
|
|
562
|
-
return isHexString(value) && !(value.length % 2) || isBytes(value);
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
function isInteger(value) {
|
|
566
|
-
return typeof value === 'number' && value == value && value % 1 === 0;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function isBytes(value) {
|
|
570
|
-
if (value == null) {
|
|
571
|
-
return false;
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
if (value.constructor === Uint8Array) {
|
|
575
|
-
return true;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
if (typeof value === 'string') {
|
|
579
|
-
return false;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
583
|
-
return false;
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
for (let i = 0; i < value.length; i++) {
|
|
587
|
-
const v = value[i];
|
|
588
|
-
|
|
589
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
590
|
-
return false;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
return true;
|
|
595
|
-
}
|
|
596
|
-
function arrayify(value, options) {
|
|
597
|
-
if (!options) {
|
|
598
|
-
options = {};
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
if (typeof value === 'number') {
|
|
602
|
-
logger.checkSafeUint53(value, 'invalid arrayify value');
|
|
603
|
-
const result = [];
|
|
604
|
-
|
|
605
|
-
while (value) {
|
|
606
|
-
result.unshift(value & 0xff);
|
|
607
|
-
value = parseInt(String(value / 256));
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
if (result.length === 0) {
|
|
611
|
-
result.push(0);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
return new Uint8Array(result);
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
if (options.allowMissingPrefix && typeof value === 'string' && value.substring(0, 2) !== '0x') {
|
|
618
|
-
value = '0x' + value;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
if (isHexable(value)) {
|
|
622
|
-
value = value.toHexString();
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
if (isHexString(value)) {
|
|
626
|
-
let hex = value.substring(2);
|
|
627
|
-
|
|
628
|
-
if (hex.length % 2) {
|
|
629
|
-
if (options.hexPad === 'left') {
|
|
630
|
-
hex = '0' + hex;
|
|
631
|
-
} else if (options.hexPad === 'right') {
|
|
632
|
-
hex += '0';
|
|
633
|
-
} else {
|
|
634
|
-
logger.throwArgumentError('hex data is odd-length', 'value', value);
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
const result = [];
|
|
639
|
-
|
|
640
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
641
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
return new Uint8Array(result);
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
if (isBytes(value)) {
|
|
648
|
-
return new Uint8Array(value);
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
return logger.throwArgumentError('invalid arrayify value', 'value', value);
|
|
652
|
-
}
|
|
653
|
-
function concat(arrayOfBytesLike) {
|
|
654
|
-
const objects = arrayOfBytesLike.map(item => arrayify(item));
|
|
655
|
-
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
|
656
|
-
const result = new Uint8Array(length);
|
|
657
|
-
objects.reduce((offset, object) => {
|
|
658
|
-
result.set(object, offset);
|
|
659
|
-
return offset + object.length;
|
|
660
|
-
}, 0);
|
|
661
|
-
return result;
|
|
662
|
-
}
|
|
663
|
-
function stripZeros(value) {
|
|
664
|
-
let result = arrayify(value);
|
|
665
|
-
|
|
666
|
-
if (result.length === 0) {
|
|
667
|
-
return result;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
let start = 0;
|
|
671
|
-
|
|
672
|
-
while (start < result.length && result[start] === 0) {
|
|
673
|
-
start++;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
if (start) {
|
|
677
|
-
result = result.slice(start);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
return result;
|
|
681
|
-
}
|
|
682
|
-
function zeroPad(value, length) {
|
|
683
|
-
value = arrayify(value);
|
|
684
|
-
|
|
685
|
-
if (value.length > length) {
|
|
686
|
-
logger.throwArgumentError('value out of range', 'value', value);
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
const result = new Uint8Array(length);
|
|
690
|
-
result.set(value, length - value.length);
|
|
691
|
-
return result;
|
|
692
|
-
}
|
|
693
|
-
function isHexString(value, length) {
|
|
694
|
-
if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
695
|
-
return false;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
return true;
|
|
703
|
-
}
|
|
704
|
-
const HexCharacters = '0123456789abcdef';
|
|
705
|
-
function hexlify(value, options) {
|
|
706
|
-
if (!options) {
|
|
707
|
-
options = {};
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
if (typeof value === 'number') {
|
|
711
|
-
logger.checkSafeUint53(value, 'invalid hexlify value');
|
|
712
|
-
let hex = '';
|
|
713
|
-
|
|
714
|
-
while (value) {
|
|
715
|
-
hex = HexCharacters[value & 0xf] + hex;
|
|
716
|
-
value = Math.floor(value / 16);
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
if (hex.length) {
|
|
720
|
-
if (hex.length % 2) {
|
|
721
|
-
hex = '0' + hex;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
return '0x' + hex;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
return '0x00';
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
if (typeof value === 'bigint') {
|
|
731
|
-
value = value.toString(16);
|
|
732
|
-
|
|
733
|
-
if (value.length % 2) {
|
|
734
|
-
return '0x0' + value;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
return '0x' + value;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
if (options.allowMissingPrefix && typeof value === 'string' && value.substring(0, 2) !== '0x') {
|
|
741
|
-
value = '0x' + value;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
if (isHexable(value)) {
|
|
745
|
-
return value.toHexString();
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
if (isHexString(value)) {
|
|
749
|
-
if (value.length % 2) {
|
|
750
|
-
if (options.hexPad === 'left') {
|
|
751
|
-
value = '0x0' + value.substring(2);
|
|
752
|
-
} else if (options.hexPad === 'right') {
|
|
753
|
-
value += '0';
|
|
754
|
-
} else {
|
|
755
|
-
logger.throwArgumentError('hex data is odd-length', 'value', value);
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
return value.toLowerCase();
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
if (isBytes(value)) {
|
|
763
|
-
let result = '0x';
|
|
764
|
-
|
|
765
|
-
for (let i = 0; i < value.length; i++) {
|
|
766
|
-
const v = value[i];
|
|
767
|
-
result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
return result;
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
return logger.throwArgumentError('invalid hexlify value', 'value', value);
|
|
774
|
-
}
|
|
775
|
-
function hexDataLength(data) {
|
|
776
|
-
if (typeof data !== 'string') {
|
|
777
|
-
data = hexlify(data);
|
|
778
|
-
} else if (!isHexString(data) || data.length % 2) {
|
|
779
|
-
return null;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
return (data.length - 2) / 2;
|
|
783
|
-
}
|
|
784
|
-
function hexDataSlice(data, offset, endOffset) {
|
|
785
|
-
if (typeof data !== 'string') {
|
|
786
|
-
data = hexlify(data);
|
|
787
|
-
} else if (!isHexString(data) || data.length % 2) {
|
|
788
|
-
logger.throwArgumentError('invalid hexData', 'value', data);
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
offset = 2 + 2 * offset;
|
|
792
|
-
|
|
793
|
-
if (endOffset != null) {
|
|
794
|
-
return '0x' + data.substring(offset, 2 + 2 * endOffset);
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
return '0x' + data.substring(offset);
|
|
798
|
-
}
|
|
799
|
-
function hexConcat(items) {
|
|
800
|
-
let result = '0x';
|
|
801
|
-
items.forEach(item => {
|
|
802
|
-
result += hexlify(item).substring(2);
|
|
803
|
-
});
|
|
804
|
-
return result;
|
|
805
|
-
}
|
|
806
|
-
function hexValue(value) {
|
|
807
|
-
const trimmed = hexStripZeros(hexlify(value, {
|
|
808
|
-
hexPad: 'left'
|
|
809
|
-
}));
|
|
810
|
-
|
|
811
|
-
if (trimmed === '0x') {
|
|
812
|
-
return '0x0';
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
return trimmed;
|
|
816
|
-
}
|
|
817
|
-
function hexStripZeros(value) {
|
|
818
|
-
if (typeof value !== 'string') {
|
|
819
|
-
value = hexlify(value);
|
|
820
|
-
}
|
|
821
|
-
|
|
822
|
-
if (!isHexString(value)) {
|
|
823
|
-
logger.throwArgumentError('invalid hex string', 'value', value);
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
value = value.substring(2);
|
|
827
|
-
let offset = 0;
|
|
828
|
-
|
|
829
|
-
while (offset < value.length && value[offset] === '0') {
|
|
830
|
-
offset++;
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
return '0x' + value.substring(offset);
|
|
834
|
-
}
|
|
835
|
-
function hexZeroPad(value, length) {
|
|
836
|
-
if (typeof value !== 'string') {
|
|
837
|
-
value = hexlify(value);
|
|
838
|
-
} else if (!isHexString(value)) {
|
|
839
|
-
logger.throwArgumentError('invalid hex string', 'value', value);
|
|
840
|
-
}
|
|
841
|
-
|
|
842
|
-
if (value.length > 2 * length + 2) {
|
|
843
|
-
logger.throwError('value out of range', {
|
|
844
|
-
value,
|
|
845
|
-
length
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
while (value.length < 2 * length + 2) {
|
|
850
|
-
value = '0x0' + value.substring(2);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
return value;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
function prepareTransaction(transaction) {
|
|
857
|
-
const preparedTransaction = _extends({}, transaction);
|
|
858
|
-
|
|
859
|
-
Object.keys(transaction).forEach(key => {
|
|
860
|
-
switch (key) {
|
|
861
|
-
case 'gas':
|
|
862
|
-
case 'gasPrice':
|
|
863
|
-
case 'nonce':
|
|
864
|
-
case 'maxFeePerGas':
|
|
865
|
-
case 'maxPriorityFeePerGas':
|
|
866
|
-
case 'value':
|
|
867
|
-
{
|
|
868
|
-
const value = transaction[key];
|
|
869
|
-
|
|
870
|
-
if (value instanceof TinyBig) {
|
|
871
|
-
preparedTransaction[key] = value.toHexString();
|
|
872
|
-
} else if (value instanceof Big) {
|
|
873
|
-
preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
|
|
874
|
-
} else if (typeof transaction[key] === 'number') preparedTransaction[key] = '0x' + transaction[key].toString(16);else preparedTransaction[key] = transaction[key].toString();
|
|
875
|
-
|
|
876
|
-
break;
|
|
877
|
-
}
|
|
878
|
-
|
|
879
|
-
case 'data':
|
|
880
|
-
preparedTransaction[key] = hexlify(transaction[key]);
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
return preparedTransaction;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
var chainsInfo = {
|
|
888
|
-
"1": ["eth", "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e"],
|
|
889
|
-
"2": ["exp"],
|
|
890
|
-
"3": ["rop", "0x112234455c3a32fd11230c42e7bccd4a84e02010"],
|
|
891
|
-
"4": ["rin", "0xe7410170f87102df0055eb195163a03b7f2bff4a"],
|
|
892
|
-
"5": ["gor", "0x112234455c3a32fd11230c42e7bccd4a84e02010"],
|
|
893
|
-
"6": ["kot"],
|
|
894
|
-
"7": ["tch"],
|
|
895
|
-
"8": ["ubq"],
|
|
896
|
-
"9": ["tubq"],
|
|
897
|
-
"10": ["oeth"],
|
|
898
|
-
"11": ["meta"],
|
|
899
|
-
"12": ["kal"],
|
|
900
|
-
"13": ["dstg"],
|
|
901
|
-
"14": ["flr"],
|
|
902
|
-
"15": ["diode"],
|
|
903
|
-
"16": ["cflr"],
|
|
904
|
-
"17": ["tfi"],
|
|
905
|
-
"18": ["TST"],
|
|
906
|
-
"19": ["sgb"],
|
|
907
|
-
"20": ["elaeth"],
|
|
908
|
-
"21": ["elaetht"],
|
|
909
|
-
"22": ["eladid"],
|
|
910
|
-
"23": ["eladidt"],
|
|
911
|
-
"24": ["dthmainnet"],
|
|
912
|
-
"25": ["cro"],
|
|
913
|
-
"26": ["L1test"],
|
|
914
|
-
"27": ["shib"],
|
|
915
|
-
"28": ["Boba Rinkeby"],
|
|
916
|
-
"29": ["L1"],
|
|
917
|
-
"30": ["rsk"],
|
|
918
|
-
"31": ["trsk"],
|
|
919
|
-
"32": ["GooDT"],
|
|
920
|
-
"33": ["GooD"],
|
|
921
|
-
"34": ["dth"],
|
|
922
|
-
"35": ["tbwg"],
|
|
923
|
-
"36": ["dx"],
|
|
924
|
-
"38": ["val"],
|
|
925
|
-
"40": ["Telos EVM"],
|
|
926
|
-
"41": ["Telos EVM Testnet"],
|
|
927
|
-
"42": ["kov"],
|
|
928
|
-
"43": ["pangolin"],
|
|
929
|
-
"44": ["crab"],
|
|
930
|
-
"45": ["pangoro"],
|
|
931
|
-
"46": ["darwinia"],
|
|
932
|
-
"50": ["xdc"],
|
|
933
|
-
"51": ["TXDC"],
|
|
934
|
-
"52": ["cet"],
|
|
935
|
-
"53": ["tcet"],
|
|
936
|
-
"54": ["OP"],
|
|
937
|
-
"55": ["ZYX"],
|
|
938
|
-
"56": ["bnb"],
|
|
939
|
-
"57": ["sys"],
|
|
940
|
-
"58": ["Ontology Mainnet"],
|
|
941
|
-
"59": ["EOS Mainnet"],
|
|
942
|
-
"60": ["go"],
|
|
943
|
-
"61": ["etc"],
|
|
944
|
-
"62": ["tetc"],
|
|
945
|
-
"63": ["metc"],
|
|
946
|
-
"64": ["ellaism"],
|
|
947
|
-
"65": ["tokt"],
|
|
948
|
-
"66": ["okt"],
|
|
949
|
-
"67": ["dbm"],
|
|
950
|
-
"68": ["SO1"],
|
|
951
|
-
"69": ["okov"],
|
|
952
|
-
"70": ["hsc"],
|
|
953
|
-
"71": ["cfxtest"],
|
|
954
|
-
"72": ["dxc"],
|
|
955
|
-
"74": ["idchain"],
|
|
956
|
-
"76": ["mix"],
|
|
957
|
-
"77": ["spoa"],
|
|
958
|
-
"78": ["primuschain"],
|
|
959
|
-
"79": ["zenith"],
|
|
960
|
-
"80": ["GeneChain"],
|
|
961
|
-
"81": ["VIL"],
|
|
962
|
-
"82": ["Meter"],
|
|
963
|
-
"83": ["MeterTest"],
|
|
964
|
-
"85": ["gttest"],
|
|
965
|
-
"86": ["gt"],
|
|
966
|
-
"87": ["nnw"],
|
|
967
|
-
"88": ["tomo"],
|
|
968
|
-
"89": ["tomot"],
|
|
969
|
-
"90": ["gar-s0"],
|
|
970
|
-
"91": ["gar-s1"],
|
|
971
|
-
"92": ["gar-s2"],
|
|
972
|
-
"93": ["gar-s3"],
|
|
973
|
-
"95": ["Kylin Testnet"],
|
|
974
|
-
"96": ["nsc"],
|
|
975
|
-
"97": ["bnbt"],
|
|
976
|
-
"99": ["poa"],
|
|
977
|
-
"100": ["gno"],
|
|
978
|
-
"101": ["eti"],
|
|
979
|
-
"102": ["tw3g"],
|
|
980
|
-
"104": ["tklc"],
|
|
981
|
-
"105": ["dw3g"],
|
|
982
|
-
"106": ["vlx"],
|
|
983
|
-
"107": ["ntn"],
|
|
984
|
-
"108": ["TT"],
|
|
985
|
-
"110": ["xpr"],
|
|
986
|
-
"111": ["ETL"],
|
|
987
|
-
"122": ["fuse"],
|
|
988
|
-
"123": ["spark"],
|
|
989
|
-
"124": ["dwu"],
|
|
990
|
-
"125": ["oychain testnet"],
|
|
991
|
-
"126": ["oychain mainnet"],
|
|
992
|
-
"127": ["feth"],
|
|
993
|
-
"128": ["heco"],
|
|
994
|
-
"137": ["MATIC"],
|
|
995
|
-
"141": ["OPtest"],
|
|
996
|
-
"142": ["dax"],
|
|
997
|
-
"162": ["tpht"],
|
|
998
|
-
"163": ["pht"],
|
|
999
|
-
"168": ["aioz"],
|
|
1000
|
-
"170": ["hoosmartchain"],
|
|
1001
|
-
"172": ["resil"],
|
|
1002
|
-
"180": ["ame"],
|
|
1003
|
-
"186": ["Seele"],
|
|
1004
|
-
"188": ["BMC"],
|
|
1005
|
-
"189": ["BMCT"],
|
|
1006
|
-
"193": ["cem"],
|
|
1007
|
-
"199": ["BTT"],
|
|
1008
|
-
"200": ["aox"],
|
|
1009
|
-
"211": ["EDI"],
|
|
1010
|
-
"218": ["SO1-old"],
|
|
1011
|
-
"222": ["ASK"],
|
|
1012
|
-
"225": ["LA"],
|
|
1013
|
-
"226": ["TLA"],
|
|
1014
|
-
"246": ["ewt"],
|
|
1015
|
-
"250": ["ftm"],
|
|
1016
|
-
"256": ["hecot"],
|
|
1017
|
-
"258": ["setm"],
|
|
1018
|
-
"262": ["SUR"],
|
|
1019
|
-
"269": ["hpb"],
|
|
1020
|
-
"280": ["zksync-goerli"],
|
|
1021
|
-
"288": ["Boba"],
|
|
1022
|
-
"300": ["ogc"],
|
|
1023
|
-
"321": ["kcs"],
|
|
1024
|
-
"322": ["kcst"],
|
|
1025
|
-
"333": ["w3q"],
|
|
1026
|
-
"335": ["DFKTEST"],
|
|
1027
|
-
"336": ["sdn"],
|
|
1028
|
-
"338": ["tcro"],
|
|
1029
|
-
"361": ["theta-mainnet"],
|
|
1030
|
-
"363": ["theta-sapphire"],
|
|
1031
|
-
"364": ["theta-amber"],
|
|
1032
|
-
"365": ["theta-testnet"],
|
|
1033
|
-
"369": ["pls"],
|
|
1034
|
-
"385": ["lisinski"],
|
|
1035
|
-
"416": ["SX"],
|
|
1036
|
-
"420": ["ogor"],
|
|
1037
|
-
"499": ["rupx"],
|
|
1038
|
-
"512": ["aac"],
|
|
1039
|
-
"513": ["aact"],
|
|
1040
|
-
"520": ["xt"],
|
|
1041
|
-
"530": ["f(x)Core"],
|
|
1042
|
-
"534": ["CNDL"],
|
|
1043
|
-
"555": ["CLASS"],
|
|
1044
|
-
"558": ["tao"],
|
|
1045
|
-
"588": ["metis-stardust"],
|
|
1046
|
-
"592": ["astr"],
|
|
1047
|
-
"595": ["maca"],
|
|
1048
|
-
"596": ["tkar"],
|
|
1049
|
-
"597": ["taca"],
|
|
1050
|
-
"600": ["mesh-chain-testnet"],
|
|
1051
|
-
"647": ["SX-Testnet"],
|
|
1052
|
-
"666": ["pixie-chain-testnet"],
|
|
1053
|
-
"686": ["kar"],
|
|
1054
|
-
"700": ["SNS"],
|
|
1055
|
-
"707": ["bcs"],
|
|
1056
|
-
"708": ["tbcs"],
|
|
1057
|
-
"721": ["tfeth"],
|
|
1058
|
-
"776": ["opc"],
|
|
1059
|
-
"777": ["cth"],
|
|
1060
|
-
"787": ["aca"],
|
|
1061
|
-
"788": ["taero"],
|
|
1062
|
-
"803": ["haic"],
|
|
1063
|
-
"808": ["PFTEST"],
|
|
1064
|
-
"820": ["clo"],
|
|
1065
|
-
"821": ["tclo"],
|
|
1066
|
-
"880": ["ambros"],
|
|
1067
|
-
"888": ["wan"],
|
|
1068
|
-
"900": ["gar-test-s0"],
|
|
1069
|
-
"901": ["gar-test-s1"],
|
|
1070
|
-
"902": ["gar-test-s2"],
|
|
1071
|
-
"903": ["gar-test-s3"],
|
|
1072
|
-
"909": ["PF"],
|
|
1073
|
-
"940": ["tpls"],
|
|
1074
|
-
"941": ["t2bpls"],
|
|
1075
|
-
"942": ["t3pls"],
|
|
1076
|
-
"977": ["yeti"],
|
|
1077
|
-
"980": ["top_evm"],
|
|
1078
|
-
"989": ["top"],
|
|
1079
|
-
"998": ["ln"],
|
|
1080
|
-
"999": ["twan"],
|
|
1081
|
-
"1000": ["gton"],
|
|
1082
|
-
"1001": ["Baobab"],
|
|
1083
|
-
"1007": ["tnew"],
|
|
1084
|
-
"1008": ["eun"],
|
|
1085
|
-
"1010": ["EVC"],
|
|
1086
|
-
"1012": ["new"],
|
|
1087
|
-
"1022": ["sku"],
|
|
1088
|
-
"1023": ["tclv"],
|
|
1089
|
-
"1024": ["clv"],
|
|
1090
|
-
"1028": ["tbtt"],
|
|
1091
|
-
"1030": ["cfx"],
|
|
1092
|
-
"1088": ["metis-andromeda"],
|
|
1093
|
-
"1139": ["MATH"],
|
|
1094
|
-
"1140": ["tMATH"],
|
|
1095
|
-
"1197": ["iora"],
|
|
1096
|
-
"1201": ["avis"],
|
|
1097
|
-
"1202": ["wtt"],
|
|
1098
|
-
"1213": ["popcat"],
|
|
1099
|
-
"1214": ["enter"],
|
|
1100
|
-
"1246": ["om"],
|
|
1101
|
-
"1280": ["HO"],
|
|
1102
|
-
"1284": ["mbeam"],
|
|
1103
|
-
"1285": ["mriver"],
|
|
1104
|
-
"1286": ["mrock-old"],
|
|
1105
|
-
"1287": ["mbase"],
|
|
1106
|
-
"1288": ["mrock"],
|
|
1107
|
-
"1297": ["Bobabase"],
|
|
1108
|
-
"1319": ["aitd"],
|
|
1109
|
-
"1320": ["aitdtestnet"],
|
|
1110
|
-
"1337": ["cennz-old"],
|
|
1111
|
-
"1506": ["Sherpax"],
|
|
1112
|
-
"1507": ["Sherpax Testnet"],
|
|
1113
|
-
"1618": ["cate"],
|
|
1114
|
-
"1620": ["ath"],
|
|
1115
|
-
"1657": ["bta"],
|
|
1116
|
-
"1688": ["LUDAN"],
|
|
1117
|
-
"1818": ["cube"],
|
|
1118
|
-
"1819": ["cubet"],
|
|
1119
|
-
"1856": ["tsf"],
|
|
1120
|
-
"1898": ["boya"],
|
|
1121
|
-
"1984": ["euntest"],
|
|
1122
|
-
"1987": ["egem"],
|
|
1123
|
-
"2001": ["milkAda"],
|
|
1124
|
-
"2008": ["cloudwalk_testnet"],
|
|
1125
|
-
"2009": ["cloudwalk_mainnet"],
|
|
1126
|
-
"2020": ["420"],
|
|
1127
|
-
"2021": ["edg"],
|
|
1128
|
-
"2022": ["edgt"],
|
|
1129
|
-
"2023": ["taycan-testnet"],
|
|
1130
|
-
"2025": ["rpg"],
|
|
1131
|
-
"2100": ["eco"],
|
|
1132
|
-
"2101": ["esp"],
|
|
1133
|
-
"2152": ["fra"],
|
|
1134
|
-
"2153": ["findora-testnet"],
|
|
1135
|
-
"2213": ["evanesco"],
|
|
1136
|
-
"2221": ["tkava"],
|
|
1137
|
-
"2222": ["kava"],
|
|
1138
|
-
"2223": ["VChain"],
|
|
1139
|
-
"2559": ["ktoc"],
|
|
1140
|
-
"2569": ["tpc"],
|
|
1141
|
-
"2612": ["EZChain"],
|
|
1142
|
-
"2613": ["Fuji-EZChain"],
|
|
1143
|
-
"3000": ["cennz-r"],
|
|
1144
|
-
"3001": ["cennz-n"],
|
|
1145
|
-
"3331": ["zcrbeach"],
|
|
1146
|
-
"3333": ["w3q-t"],
|
|
1147
|
-
"3334": ["w3q-g"],
|
|
1148
|
-
"3400": ["prb"],
|
|
1149
|
-
"3500": ["prbtestnet"],
|
|
1150
|
-
"3501": ["jfin"],
|
|
1151
|
-
"3690": ["btx"],
|
|
1152
|
-
"3737": ["csb"],
|
|
1153
|
-
"3966": ["dyno"],
|
|
1154
|
-
"3967": ["tdyno"],
|
|
1155
|
-
"3999": ["ycc"],
|
|
1156
|
-
"4002": ["tftm"],
|
|
1157
|
-
"4051": ["Bobaopera Testnet"],
|
|
1158
|
-
"4102": ["aioz-testnet"],
|
|
1159
|
-
"4181": ["PHI"],
|
|
1160
|
-
"4689": ["iotex-mainnet"],
|
|
1161
|
-
"4690": ["iotex-testnet"],
|
|
1162
|
-
"4918": ["txvm"],
|
|
1163
|
-
"4919": ["xvm"],
|
|
1164
|
-
"5177": ["tlc"],
|
|
1165
|
-
"5197": ["es"],
|
|
1166
|
-
"5315": ["UZMI"],
|
|
1167
|
-
"5551": ["Nahmii"],
|
|
1168
|
-
"5553": ["Nahmii testnet"],
|
|
1169
|
-
"5700": ["tsys"],
|
|
1170
|
-
"5777": ["dgcc"],
|
|
1171
|
-
"5851": ["Ontology Testnet"],
|
|
1172
|
-
"5869": ["rbd"],
|
|
1173
|
-
"6626": ["pixie-chain"],
|
|
1174
|
-
"6969": ["tombchain"],
|
|
1175
|
-
"7027": ["ELLA"],
|
|
1176
|
-
"7341": ["shyft"],
|
|
1177
|
-
"7777": ["Rise of the Warbots Testnet"],
|
|
1178
|
-
"7878": ["tscas"],
|
|
1179
|
-
"8000": ["teleport"],
|
|
1180
|
-
"8001": ["teleport-testnet"],
|
|
1181
|
-
"8029": ["mdgl"],
|
|
1182
|
-
"8080": ["GeneChainAdn"],
|
|
1183
|
-
"8217": ["Cypress"],
|
|
1184
|
-
"8285": ["Kortho"],
|
|
1185
|
-
"8723": ["olo"],
|
|
1186
|
-
"8724": ["tolo"],
|
|
1187
|
-
"8888": ["ambrostestnet"],
|
|
1188
|
-
"8898": ["mmt"],
|
|
1189
|
-
"8995": ["berg"],
|
|
1190
|
-
"9000": ["evmos-testnet"],
|
|
1191
|
-
"9001": ["evmos"],
|
|
1192
|
-
"9012": ["brb"],
|
|
1193
|
-
"9100": ["GENEC"],
|
|
1194
|
-
"9527": ["trpg"],
|
|
1195
|
-
"9999": ["myn"],
|
|
1196
|
-
"10000": ["smartbch"],
|
|
1197
|
-
"10001": ["smartbchtest"],
|
|
1198
|
-
"10101": ["GEN"],
|
|
1199
|
-
"10823": ["CCP"],
|
|
1200
|
-
"10946": ["quadrans"],
|
|
1201
|
-
"10947": ["quadranstestnet"],
|
|
1202
|
-
"11111": ["WAGMI"],
|
|
1203
|
-
"11437": ["shyftt"],
|
|
1204
|
-
"12051": ["tZERO"],
|
|
1205
|
-
"12052": ["ZERO"],
|
|
1206
|
-
"13381": ["Phoenix"],
|
|
1207
|
-
"16000": ["mtt"],
|
|
1208
|
-
"16001": ["mtttest"],
|
|
1209
|
-
"16888": ["tivar"],
|
|
1210
|
-
"19845": ["btcix"],
|
|
1211
|
-
"21337": ["cennz-a"],
|
|
1212
|
-
"21816": ["omc"],
|
|
1213
|
-
"22023": ["SFL"],
|
|
1214
|
-
"24484": ["web"],
|
|
1215
|
-
"24734": ["mintme"],
|
|
1216
|
-
"26863": ["OAC"],
|
|
1217
|
-
"30067": ["Piece"],
|
|
1218
|
-
"31102": ["esn"],
|
|
1219
|
-
"31337": ["got"],
|
|
1220
|
-
"32520": ["Brise"],
|
|
1221
|
-
"32659": ["fsn"],
|
|
1222
|
-
"35441": ["q"],
|
|
1223
|
-
"35443": ["q-testnet"],
|
|
1224
|
-
"39797": ["nrg"],
|
|
1225
|
-
"42069": ["PC"],
|
|
1226
|
-
"42161": ["arb1"],
|
|
1227
|
-
"42170": ["arb-nova"],
|
|
1228
|
-
"42220": ["CELO"],
|
|
1229
|
-
"42261": ["emerald"],
|
|
1230
|
-
"42262": ["oasis"],
|
|
1231
|
-
"43110": ["avaeth"],
|
|
1232
|
-
"43113": ["Fuji"],
|
|
1233
|
-
"43114": ["avax"],
|
|
1234
|
-
"44787": ["ALFA"],
|
|
1235
|
-
"45000": ["Autobahn Network"],
|
|
1236
|
-
"47805": ["REI"],
|
|
1237
|
-
"49797": ["tnrg"],
|
|
1238
|
-
"50021": ["tgton"],
|
|
1239
|
-
"53935": ["DFK"],
|
|
1240
|
-
"55555": ["reichain"],
|
|
1241
|
-
"55556": ["trei"],
|
|
1242
|
-
"60000": ["TKM-test0"],
|
|
1243
|
-
"60001": ["TKM-test1"],
|
|
1244
|
-
"60002": ["TKM-test2"],
|
|
1245
|
-
"60103": ["TKM-test103"],
|
|
1246
|
-
"62320": ["BKLV"],
|
|
1247
|
-
"62621": ["mtv"],
|
|
1248
|
-
"63000": ["ecs"],
|
|
1249
|
-
"63001": ["ecs-testnet"],
|
|
1250
|
-
"69420": ["cndr"],
|
|
1251
|
-
"70000": ["TKM0"],
|
|
1252
|
-
"70001": ["TKM1"],
|
|
1253
|
-
"70002": ["TKM2"],
|
|
1254
|
-
"70103": ["TKM103"],
|
|
1255
|
-
"71393": ["ckb"],
|
|
1256
|
-
"71401": ["gw-testnet-v1"],
|
|
1257
|
-
"71402": ["gw-mainnet-v1"],
|
|
1258
|
-
"73799": ["vt"],
|
|
1259
|
-
"73927": ["mvm"],
|
|
1260
|
-
"75000": ["resin"],
|
|
1261
|
-
"78110": ["firenze"],
|
|
1262
|
-
"80001": ["maticmum"],
|
|
1263
|
-
"88888": ["ivar"],
|
|
1264
|
-
"99998": ["usctest"],
|
|
1265
|
-
"99999": ["usc"],
|
|
1266
|
-
"100000": ["qkc-r"],
|
|
1267
|
-
"100001": ["qkc-s0"],
|
|
1268
|
-
"100002": ["qkc-s1"],
|
|
1269
|
-
"100003": ["qkc-s2"],
|
|
1270
|
-
"100004": ["qkc-s3"],
|
|
1271
|
-
"100005": ["qkc-s4"],
|
|
1272
|
-
"100006": ["qkc-s5"],
|
|
1273
|
-
"100007": ["qkc-s6"],
|
|
1274
|
-
"100008": ["qkc-s7"],
|
|
1275
|
-
"103090": ["CRFI"],
|
|
1276
|
-
"108801": ["bro"],
|
|
1277
|
-
"110000": ["qkc-d-r"],
|
|
1278
|
-
"110001": ["qkc-d-s0"],
|
|
1279
|
-
"110002": ["qkc-d-s1"],
|
|
1280
|
-
"110003": ["qkc-d-s2"],
|
|
1281
|
-
"110004": ["qkc-d-s3"],
|
|
1282
|
-
"110005": ["qkc-d-s4"],
|
|
1283
|
-
"110006": ["qkc-d-s5"],
|
|
1284
|
-
"110007": ["qkc-d-s6"],
|
|
1285
|
-
"110008": ["qkc-d-s7"],
|
|
1286
|
-
"131419": ["ETND"],
|
|
1287
|
-
"200101": ["milkTAda"],
|
|
1288
|
-
"200625": ["aka"],
|
|
1289
|
-
"201018": ["alaya"],
|
|
1290
|
-
"201030": ["alayadev"],
|
|
1291
|
-
"210425": ["platon"],
|
|
1292
|
-
"234666": ["hym"],
|
|
1293
|
-
"246529": ["ats"],
|
|
1294
|
-
"246785": ["atstau"],
|
|
1295
|
-
"281121": ["SoChain"],
|
|
1296
|
-
"333888": ["sparta"],
|
|
1297
|
-
"333999": ["olympus"],
|
|
1298
|
-
"421611": ["arb-rinkeby"],
|
|
1299
|
-
"421613": ["arb-goerli"],
|
|
1300
|
-
"432201": ["Dexalot"],
|
|
1301
|
-
"444900": ["wlkt"],
|
|
1302
|
-
"474142": ["oc"],
|
|
1303
|
-
"512512": ["cmp"],
|
|
1304
|
-
"666666": ["vpioneer"],
|
|
1305
|
-
"846000": ["bloqs4good"],
|
|
1306
|
-
"888888": ["vision"],
|
|
1307
|
-
"955305": ["elv"],
|
|
1308
|
-
"1313114": ["etho"],
|
|
1309
|
-
"1313500": ["xero"],
|
|
1310
|
-
"1337702": ["kintsugi"],
|
|
1311
|
-
"1337802": ["kiln"],
|
|
1312
|
-
"2203181": ["platondev"],
|
|
1313
|
-
"2206132": ["platondev2"],
|
|
1314
|
-
"7762959": ["music"],
|
|
1315
|
-
"11155111": ["sep"],
|
|
1316
|
-
"13371337": ["tpep"],
|
|
1317
|
-
"18289463": ["ilt"],
|
|
1318
|
-
"20180430": ["spectrum"],
|
|
1319
|
-
"20181205": ["qki"],
|
|
1320
|
-
"28945486": ["auxi"],
|
|
1321
|
-
"35855456": ["JOYS"],
|
|
1322
|
-
"61717561": ["aqua"],
|
|
1323
|
-
"99415706": ["TOYS"],
|
|
1324
|
-
"192837465": ["GTH"],
|
|
1325
|
-
"245022926": ["neonevm-devnet"],
|
|
1326
|
-
"245022934": ["neonevm-mainnet"],
|
|
1327
|
-
"245022940": ["neonevm-testnet"],
|
|
1328
|
-
"311752642": ["oneledger"],
|
|
1329
|
-
"356256156": ["tGTH"],
|
|
1330
|
-
"486217935": ["dGTH"],
|
|
1331
|
-
"1122334455": ["ipos"],
|
|
1332
|
-
"1313161554": ["aurora"],
|
|
1333
|
-
"1313161555": ["aurora-testnet"],
|
|
1334
|
-
"1313161556": ["aurora-betanet"],
|
|
1335
|
-
"1666600000": ["hmy-s0"],
|
|
1336
|
-
"1666600001": ["hmy-s1"],
|
|
1337
|
-
"1666600002": ["hmy-s2"],
|
|
1338
|
-
"1666600003": ["hmy-s3"],
|
|
1339
|
-
"1666700000": ["hmy-b-s0"],
|
|
1340
|
-
"1666700001": ["hmy-b-s1"],
|
|
1341
|
-
"1666700002": ["hmy-b-s2"],
|
|
1342
|
-
"1666700003": ["hmy-b-s3"],
|
|
1343
|
-
"2021121117": ["hop"],
|
|
1344
|
-
"3125659152": ["pirl"],
|
|
1345
|
-
"4216137055": ["frankenstein"],
|
|
1346
|
-
"11297108099": ["tpalm"],
|
|
1347
|
-
"11297108109": ["palm"],
|
|
1348
|
-
"197710212030": ["ntt"],
|
|
1349
|
-
"197710212031": ["ntt-haradev"],
|
|
1350
|
-
"6022140761023": ["mole"],
|
|
1351
|
-
"868455272153094": ["gw-testnet-v1-deprecated"]
|
|
1352
|
-
};
|
|
1353
|
-
|
|
1354
|
-
function prepBlockTag(blockTag) {
|
|
1355
|
-
return typeof blockTag === 'number' ? tinyBig(blockTag).toHexString() : blockTag;
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
class BaseProvider {
|
|
1359
|
-
constructor(rpcUrls) {
|
|
1360
|
-
this._rpcUrls = [];
|
|
1361
|
-
|
|
1362
|
-
this._post = body => post(this.selectRpcUrl(), body);
|
|
1363
|
-
|
|
1364
|
-
this._rpcUrls = rpcUrls;
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
async getNetwork() {
|
|
1368
|
-
const hexChainId = await this.post(buildRPCPostBody('eth_chainId', []));
|
|
1369
|
-
const chainId = hexToDecimal(hexChainId);
|
|
1370
|
-
const info = chainsInfo[chainId];
|
|
1371
|
-
return {
|
|
1372
|
-
chainId: Number(chainId),
|
|
1373
|
-
name: info[0] || 'unknown',
|
|
1374
|
-
ensAddress: info[1] || null
|
|
1375
|
-
};
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
async getBlockNumber() {
|
|
1379
|
-
const currentBlockNumber = await this.post(buildRPCPostBody('eth_blockNumber', []));
|
|
1380
|
-
return Number(hexToDecimal(currentBlockNumber));
|
|
1381
|
-
}
|
|
1382
|
-
|
|
1383
|
-
async getTransaction(transactionHash) {
|
|
1384
|
-
const [rpcTransaction, blockNumber] = await Promise.all([this.post(buildRPCPostBody('eth_getTransactionByHash', [transactionHash])), this.getBlock('latest')]);
|
|
1385
|
-
const cleanedTransaction = cleanTransaction(rpcTransaction);
|
|
1386
|
-
cleanedTransaction.confirmations = blockNumber.number - cleanedTransaction.blockNumber + 1;
|
|
1387
|
-
return cleanedTransaction;
|
|
1388
|
-
}
|
|
1389
|
-
|
|
1390
|
-
async getTransactionReceipt(transactionHash) {
|
|
1391
|
-
const [rpcTransaction, blockNumber] = await Promise.all([this.post(buildRPCPostBody('eth_getTransactionReceipt', [transactionHash])), this.getBlock('latest')]);
|
|
1392
|
-
const cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
|
|
1393
|
-
cleanedTransactionReceipt.confirmations = blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
|
|
1394
|
-
return cleanedTransactionReceipt;
|
|
1395
|
-
}
|
|
1396
|
-
|
|
1397
|
-
async getTransactionCount(address, blockTag = 'latest') {
|
|
1398
|
-
blockTag = prepBlockTag(blockTag);
|
|
1399
|
-
const transactionCount = await this.post(buildRPCPostBody('eth_getTransactionCount', [address, blockTag]));
|
|
1400
|
-
return Number(hexToDecimal(transactionCount));
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
async getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
|
|
1404
|
-
let type = 'Number';
|
|
1405
|
-
|
|
1406
|
-
if (typeof timeFrame === 'string' && timeFrame.length === 66) {
|
|
1407
|
-
type = 'Hash';
|
|
1408
|
-
} else {
|
|
1409
|
-
timeFrame = prepBlockTag(timeFrame);
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1412
|
-
const rpcBlock = await this.post(buildRPCPostBody(`eth_getBlockBy${type}`, [timeFrame, returnTransactionObjects]));
|
|
1413
|
-
return cleanBlock(rpcBlock, returnTransactionObjects);
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
async getGasPrice() {
|
|
1417
|
-
const hexGasPrice = await this.post(buildRPCPostBody('eth_gasPrice', []));
|
|
1418
|
-
return tinyBig(hexToDecimal(hexGasPrice));
|
|
1419
|
-
}
|
|
1420
|
-
|
|
1421
|
-
async getBalance(address, blockTag = 'latest') {
|
|
1422
|
-
blockTag = prepBlockTag(blockTag);
|
|
1423
|
-
const hexBalance = await this.post(buildRPCPostBody('eth_getBalance', [address, blockTag]));
|
|
1424
|
-
return tinyBig(hexToDecimal(hexBalance));
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
async getCode(address, blockTag = 'latest') {
|
|
1428
|
-
blockTag = prepBlockTag(blockTag);
|
|
1429
|
-
const contractCode = await this.post(buildRPCPostBody('eth_getCode', [address, blockTag]));
|
|
1430
|
-
return contractCode;
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
async estimateGas(transaction) {
|
|
1434
|
-
const rpcTransaction = prepareTransaction(transaction);
|
|
1435
|
-
const gasUsed = await this.post(buildRPCPostBody('eth_estimateGas', [rpcTransaction]));
|
|
1436
|
-
return tinyBig(hexToDecimal(gasUsed));
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
async getLogs(filter) {
|
|
1440
|
-
const filterByRange = filter;
|
|
1441
|
-
if (filterByRange.fromBlock) filterByRange.fromBlock = prepBlockTag(filterByRange.fromBlock);
|
|
1442
|
-
if (filterByRange.toBlock) filterByRange.toBlock = prepBlockTag(filterByRange.toBlock);
|
|
1443
|
-
const rpcLogs = await this.post(buildRPCPostBody('eth_getLogs', [filter]));
|
|
1444
|
-
const logs = rpcLogs.map(log => cleanLog(log, false));
|
|
1445
|
-
return logs;
|
|
1446
|
-
}
|
|
1447
|
-
|
|
1448
|
-
async call(transaction, blockTag = 'latest') {
|
|
1449
|
-
if (transaction.gasPrice && (transaction.maxPriorityFeePerGas || transaction.maxFeePerGas)) {
|
|
1450
|
-
logger.throwError('Cannot specify both "gasPrice" and ("maxPriorityFeePerGas" or "maxFeePerGas")', {
|
|
1451
|
-
gasPrice: transaction.gasPrice,
|
|
1452
|
-
maxFeePerGas: transaction.maxFeePerGas,
|
|
1453
|
-
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
|
|
1454
|
-
});
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
if (transaction.maxFeePerGas && transaction.maxPriorityFeePerGas) {
|
|
1458
|
-
logger.throwError('Cannot specify both "maxFeePerGas" and "maxPriorityFeePerGas"', {
|
|
1459
|
-
maxFeePerGas: transaction.maxFeePerGas,
|
|
1460
|
-
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
blockTag = prepBlockTag(blockTag);
|
|
1465
|
-
const rpcTransaction = prepareTransaction(transaction);
|
|
1466
|
-
const transactionRes = await this.post(buildRPCPostBody('eth_call', [rpcTransaction, blockTag]));
|
|
1467
|
-
return transactionRes;
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
const promiseTimeout = (prom, time) => Promise.race([prom, new Promise((_r, reject) => setTimeout(() => reject('Promise timed out'), time))]);
|
|
1473
|
-
|
|
1474
|
-
const DEFAULT_TIMEOUT_DURATION = 8000;
|
|
1475
|
-
class FallthroughProvider extends BaseProvider {
|
|
1476
|
-
selectRpcUrl() {
|
|
1477
|
-
return this._rpcUrls[this.rpcUrlCounter];
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
constructor(rpcUrls, options = {}) {
|
|
1481
|
-
if (!Array.isArray(rpcUrls)) {
|
|
1482
|
-
logger.throwError('Array required', {
|
|
1483
|
-
rpcUrls
|
|
1484
|
-
});
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
if (rpcUrls.length <= 1) {
|
|
1488
|
-
logger.throwError('More than one rpcUrl is required', {
|
|
1489
|
-
rpcUrls
|
|
1490
|
-
});
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
super(rpcUrls);
|
|
1494
|
-
this.rpcUrlCounter = 0;
|
|
1495
|
-
this.timeoutDuration = void 0;
|
|
1496
|
-
|
|
1497
|
-
this.post = body => {
|
|
1498
|
-
const genesisCount = this.rpcUrlCounter;
|
|
1499
|
-
|
|
1500
|
-
const recursivePostRetry = () => {
|
|
1501
|
-
const genesisRpcUrl = this.selectRpcUrl();
|
|
1502
|
-
const res = promiseTimeout(this._post(body), this.timeoutDuration).catch(e => {
|
|
1503
|
-
if (genesisRpcUrl === this.selectRpcUrl()) {
|
|
1504
|
-
this.rpcUrlCounter = (this.rpcUrlCounter + 1) % this._rpcUrls.length;
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
if (this.rpcUrlCounter === genesisCount) {
|
|
1508
|
-
throw e;
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
return recursivePostRetry();
|
|
1512
|
-
});
|
|
1513
|
-
return res;
|
|
1514
|
-
};
|
|
1515
|
-
|
|
1516
|
-
return recursivePostRetry();
|
|
1517
|
-
};
|
|
1518
|
-
|
|
1519
|
-
this.timeoutDuration = options.timeoutDuration || DEFAULT_TIMEOUT_DURATION;
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
class JsonRpcProvider extends BaseProvider {
|
|
1525
|
-
selectRpcUrl() {
|
|
1526
|
-
return this._rpcUrls[0];
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
post(body) {
|
|
1530
|
-
return this._post(body);
|
|
1531
|
-
}
|
|
1532
|
-
|
|
1533
|
-
constructor(rpcUrl = 'https://free-eth-node.com/api/eth') {
|
|
1534
|
-
super([rpcUrl]);
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
}
|
|
1538
|
-
function jsonRpcProvider(rpcUrl) {
|
|
1539
|
-
return new JsonRpcProvider(rpcUrl);
|
|
1540
|
-
}
|
|
1541
|
-
|
|
1542
|
-
function keccak256(data) {
|
|
1543
|
-
let bufferableData;
|
|
1544
|
-
|
|
1545
|
-
if (typeof data === 'string') {
|
|
1546
|
-
bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
|
|
1547
|
-
} else {
|
|
1548
|
-
bufferableData = Buffer.from(data);
|
|
1549
|
-
}
|
|
1550
|
-
|
|
1551
|
-
const keccak = new Keccak(256);
|
|
1552
|
-
const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
|
|
1553
|
-
return addressHash;
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
function computeAddress(key) {
|
|
1557
|
-
if (!key.startsWith('0x04') && !key.startsWith('0x03') && !key.startsWith('0x02')) {
|
|
1558
|
-
key = computePublicKey(key);
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
|
|
1562
|
-
}
|
|
1563
|
-
|
|
1564
|
-
function computePublicKey(privKey) {
|
|
1565
|
-
privKey = hexlify(privKey).slice(2);
|
|
1566
|
-
return '0x' + Point.fromPrivateKey(privKey).toHex();
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
function etherToGwei(etherQuantity) {
|
|
1570
|
-
validateType(etherQuantity, ['string', 'number', 'object']);
|
|
1571
|
-
const result = tinyBig(etherQuantity).times('1000000000');
|
|
1572
|
-
return tinyBig(result);
|
|
1573
|
-
}
|
|
1574
|
-
|
|
1575
|
-
function etherToWei(etherQuantity) {
|
|
1576
|
-
validateType(etherQuantity, ['string', 'number', 'object']);
|
|
1577
|
-
const result = tinyBig(etherQuantity).times('1000000000000000000');
|
|
1578
|
-
return tinyBig(result);
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
function gweiToEther(gweiQuantity) {
|
|
1582
|
-
validateType(gweiQuantity, ['string', 'number', 'object']);
|
|
1583
|
-
const result = tinyBig(gweiQuantity).div('1000000000');
|
|
1584
|
-
return tinyBig(result);
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
const messagePrefix = '\x19Ethereum Signed Message:\n';
|
|
1588
|
-
function hashMessage(message) {
|
|
1589
|
-
if (typeof message === 'string') {
|
|
1590
|
-
message = toUtf8Bytes(message);
|
|
1591
|
-
}
|
|
1592
|
-
|
|
1593
|
-
return keccak256(concat([toUtf8Bytes(messagePrefix), toUtf8Bytes(String(message.length)), message]));
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1596
|
-
function isAddress(address) {
|
|
1597
|
-
validateType(address, ['string']);
|
|
1598
|
-
|
|
1599
|
-
try {
|
|
1600
|
-
toChecksumAddress(address);
|
|
1601
|
-
return true;
|
|
1602
|
-
} catch (error) {
|
|
1603
|
-
return false;
|
|
1604
|
-
}
|
|
1605
|
-
}
|
|
1606
|
-
|
|
1607
|
-
function splitSignature(signature) {
|
|
1608
|
-
const result = {
|
|
1609
|
-
r: '0x',
|
|
1610
|
-
s: '0x',
|
|
1611
|
-
_vs: '0x',
|
|
1612
|
-
recoveryParam: 0,
|
|
1613
|
-
v: 0,
|
|
1614
|
-
yParityAndS: '0x',
|
|
1615
|
-
compact: '0x'
|
|
1616
|
-
};
|
|
1617
|
-
|
|
1618
|
-
if (isBytesLike(signature)) {
|
|
1619
|
-
const bytes = arrayify(signature);
|
|
1620
|
-
|
|
1621
|
-
if (bytes.length === 64) {
|
|
1622
|
-
result.v = 27 + (bytes[32] >> 7);
|
|
1623
|
-
bytes[32] &= 0x7f;
|
|
1624
|
-
result.r = hexlify(bytes.slice(0, 32));
|
|
1625
|
-
result.s = hexlify(bytes.slice(32, 64));
|
|
1626
|
-
} else if (bytes.length === 65) {
|
|
1627
|
-
result.r = hexlify(bytes.slice(0, 32));
|
|
1628
|
-
result.s = hexlify(bytes.slice(32, 64));
|
|
1629
|
-
result.v = bytes[64];
|
|
1630
|
-
} else {
|
|
1631
|
-
logger.throwArgumentError('invalid signature string', 'signature', signature);
|
|
1632
|
-
}
|
|
1633
|
-
|
|
1634
|
-
if (result.v < 27) {
|
|
1635
|
-
if (result.v === 0 || result.v === 1) {
|
|
1636
|
-
result.v += 27;
|
|
1637
|
-
} else {
|
|
1638
|
-
logger.throwArgumentError('signature invalid v byte', 'signature', signature);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
result.recoveryParam = 1 - result.v % 2;
|
|
1643
|
-
|
|
1644
|
-
if (result.recoveryParam) {
|
|
1645
|
-
bytes[32] |= 0x80;
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
result._vs = hexlify(bytes.slice(32, 64));
|
|
1649
|
-
} else {
|
|
1650
|
-
result.r = signature.r;
|
|
1651
|
-
result.s = signature.s;
|
|
1652
|
-
result.v = signature.v;
|
|
1653
|
-
result.recoveryParam = signature.recoveryParam;
|
|
1654
|
-
result._vs = signature._vs;
|
|
1655
|
-
|
|
1656
|
-
if (result._vs != null) {
|
|
1657
|
-
const vs_1 = zeroPad(arrayify(result._vs), 32);
|
|
1658
|
-
result._vs = hexlify(vs_1);
|
|
1659
|
-
const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
1660
|
-
|
|
1661
|
-
if (result.recoveryParam == null) {
|
|
1662
|
-
result.recoveryParam = recoveryParam;
|
|
1663
|
-
} else if (result.recoveryParam !== recoveryParam) {
|
|
1664
|
-
logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
vs_1[0] &= 0x7f;
|
|
1668
|
-
const s = hexlify(vs_1);
|
|
1669
|
-
|
|
1670
|
-
if (result.s == null) {
|
|
1671
|
-
result.s = s;
|
|
1672
|
-
} else if (result.s !== s) {
|
|
1673
|
-
logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
if (result.recoveryParam == null) {
|
|
1678
|
-
if (result.v == null) {
|
|
1679
|
-
logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
|
|
1680
|
-
} else if (result.v === 0 || result.v === 1) {
|
|
1681
|
-
result.recoveryParam = result.v;
|
|
1682
|
-
} else {
|
|
1683
|
-
result.recoveryParam = 1 - result.v % 2;
|
|
1684
|
-
}
|
|
1685
|
-
} else {
|
|
1686
|
-
if (result.v == null) {
|
|
1687
|
-
result.v = 27 + result.recoveryParam;
|
|
1688
|
-
} else {
|
|
1689
|
-
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - result.v % 2;
|
|
1690
|
-
|
|
1691
|
-
if (result.recoveryParam !== recId) {
|
|
1692
|
-
logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
if (result.r == null || !isHexString(result.r)) {
|
|
1698
|
-
logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
|
|
1699
|
-
} else {
|
|
1700
|
-
result.r = hexZeroPad(result.r, 32);
|
|
1701
|
-
}
|
|
1702
|
-
|
|
1703
|
-
if (result.s == null || !isHexString(result.s)) {
|
|
1704
|
-
logger.throwArgumentError('signature missing or invalid s', 'signature', signature);
|
|
1705
|
-
} else {
|
|
1706
|
-
result.s = hexZeroPad(result.s, 32);
|
|
1707
|
-
}
|
|
1708
|
-
|
|
1709
|
-
const vs = arrayify(result.s);
|
|
1710
|
-
|
|
1711
|
-
if (vs[0] >= 128) {
|
|
1712
|
-
logger.throwArgumentError('signature s out of range', 'signature', signature);
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
|
-
if (result.recoveryParam) {
|
|
1716
|
-
vs[0] |= 0x80;
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
|
-
const _vs = hexlify(vs);
|
|
1720
|
-
|
|
1721
|
-
if (result._vs) {
|
|
1722
|
-
if (!isHexString(result._vs)) {
|
|
1723
|
-
logger.throwArgumentError('signature invalid _vs', 'signature', signature);
|
|
1724
|
-
}
|
|
1725
|
-
|
|
1726
|
-
result._vs = hexZeroPad(result._vs, 32);
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
if (result._vs == null) {
|
|
1730
|
-
result._vs = _vs;
|
|
1731
|
-
} else if (result._vs !== _vs) {
|
|
1732
|
-
logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
|
|
1733
|
-
}
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
result.yParityAndS = result._vs;
|
|
1737
|
-
result.compact = result.r + result.yParityAndS.substring(2);
|
|
1738
|
-
return result;
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
function toUtf8Bytes(data) {
|
|
1742
|
-
return new Uint8Array(Buffer.from(data));
|
|
1743
|
-
}
|
|
1744
|
-
|
|
1745
|
-
function weiToEther(weiQuantity) {
|
|
1746
|
-
validateType(weiQuantity, ['string', 'number', 'object']);
|
|
1747
|
-
|
|
1748
|
-
try {
|
|
1749
|
-
let _weiQuantity = weiQuantity;
|
|
1750
|
-
|
|
1751
|
-
if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
|
|
1752
|
-
_weiQuantity = BigInt(weiQuantity).toString();
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
const result = tinyBig(_weiQuantity).div('1000000000000000000');
|
|
1756
|
-
return tinyBig(result);
|
|
1757
|
-
} catch (error) {
|
|
1758
|
-
throw error;
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1762
|
-
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
1763
|
-
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
1764
|
-
const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
|
|
1765
|
-
|
|
1766
|
-
function _pack(type, value, isArray) {
|
|
1767
|
-
switch (type) {
|
|
1768
|
-
case 'address':
|
|
1769
|
-
if (isArray) {
|
|
1770
|
-
return zeroPad(value, 32);
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
return arrayify(value);
|
|
1774
|
-
|
|
1775
|
-
case 'string':
|
|
1776
|
-
return Buffer$1.from(value);
|
|
1777
|
-
|
|
1778
|
-
case 'bytes':
|
|
1779
|
-
return arrayify(value);
|
|
1780
|
-
|
|
1781
|
-
case 'bool':
|
|
1782
|
-
value = value ? '0x01' : '0x00';
|
|
1783
|
-
|
|
1784
|
-
if (isArray) {
|
|
1785
|
-
return zeroPad(value, 32);
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
return arrayify(value);
|
|
1789
|
-
}
|
|
1790
|
-
|
|
1791
|
-
let match = type.match(regexNumber);
|
|
1792
|
-
|
|
1793
|
-
if (match) {
|
|
1794
|
-
let size = parseInt(match[2] || '256');
|
|
1795
|
-
|
|
1796
|
-
if (match[2] && String(size) !== match[2] || size % 8 !== 0 || size === 0 || size > 256) {
|
|
1797
|
-
logger.throwArgumentError('invalid number type', 'type', type);
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
if (isArray) {
|
|
1801
|
-
size = 256;
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
|
-
value = tinyBig(value).toTwos(size).toNumber();
|
|
1805
|
-
const hexValue = hexlify(value);
|
|
1806
|
-
return zeroPad(hexValue, size / 8);
|
|
1807
|
-
}
|
|
1808
|
-
|
|
1809
|
-
match = type.match(regexBytes);
|
|
1810
|
-
|
|
1811
|
-
if (match) {
|
|
1812
|
-
const size = parseInt(match[1]);
|
|
1813
|
-
|
|
1814
|
-
if (String(size) !== match[1] || size === 0 || size > 32) {
|
|
1815
|
-
logger.throwArgumentError('invalid bytes type', 'type', type);
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
if (arrayify(value).byteLength !== size) {
|
|
1819
|
-
logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
if (isArray) {
|
|
1823
|
-
return arrayify((value + hexFalse).substring(0, 66));
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
return value;
|
|
1827
|
-
}
|
|
1828
|
-
|
|
1829
|
-
match = type.match(regexArray);
|
|
1830
|
-
|
|
1831
|
-
if (match && Array.isArray(value)) {
|
|
1832
|
-
const baseType = match[1];
|
|
1833
|
-
const count = parseInt(match[2] || String(value.length));
|
|
1834
|
-
|
|
1835
|
-
if (count != value.length) {
|
|
1836
|
-
logger.throwArgumentError(`invalid array length for ${type}`, 'value', value);
|
|
1837
|
-
}
|
|
1838
|
-
|
|
1839
|
-
const result = [];
|
|
1840
|
-
value.forEach(function (value) {
|
|
1841
|
-
result.push(_pack(baseType, value, true));
|
|
1842
|
-
});
|
|
1843
|
-
return concat(result);
|
|
1844
|
-
}
|
|
1845
|
-
|
|
1846
|
-
return logger.throwArgumentError('invalid type', 'type', type);
|
|
1847
|
-
}
|
|
1848
|
-
|
|
1849
|
-
function pack(types, values) {
|
|
1850
|
-
if (types.length != values.length) {
|
|
1851
|
-
logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
const tight = [];
|
|
1855
|
-
types.forEach(function (type, index) {
|
|
1856
|
-
tight.push(_pack(type, values[index]));
|
|
1857
|
-
});
|
|
1858
|
-
return hexlify(concat(tight));
|
|
1859
|
-
}
|
|
1860
|
-
function solidityKeccak256(types, values) {
|
|
1861
|
-
return keccak256(pack(types, values));
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
export { BaseContract, Contract, FallthroughProvider, JsonRpcProvider, TinyBig, arrayify, computeAddress, computePublicKey, concat, etherToGwei, etherToWei, gweiToEther, hashMessage, hexConcat, hexDataLength, hexDataSlice, hexStripZeros, hexValue, hexZeroPad, hexlify, isAddress, isBytes, isBytesLike, isHexString, jsonRpcProvider, keccak256, pack, solidityKeccak256, splitSignature, stripZeros, tinyBig, toChecksumAddress, toUtf8Bytes, weiToEther, zeroPad };
|
|
1865
|
-
//# sourceMappingURL=index.module.js.map
|