web3ethabii 4.3.0
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/LICENSE +14 -0
- package/README.md +59 -0
- package/lib/commonjs/api/errors_api.d.ts +5 -0
- package/lib/commonjs/api/errors_api.js +44 -0
- package/lib/commonjs/api/errors_api.js.map +1 -0
- package/lib/commonjs/api/events_api.d.ts +51 -0
- package/lib/commonjs/api/events_api.js +90 -0
- package/lib/commonjs/api/events_api.js.map +1 -0
- package/lib/commonjs/api/functions_api.d.ts +92 -0
- package/lib/commonjs/api/functions_api.js +139 -0
- package/lib/commonjs/api/functions_api.js.map +1 -0
- package/lib/commonjs/api/logs_api.d.ts +49 -0
- package/lib/commonjs/api/logs_api.js +107 -0
- package/lib/commonjs/api/logs_api.js.map +1 -0
- package/lib/commonjs/api/parameters_api.d.ts +238 -0
- package/lib/commonjs/api/parameters_api.js +280 -0
- package/lib/commonjs/api/parameters_api.js.map +1 -0
- package/lib/commonjs/coders/base/address.d.ts +4 -0
- package/lib/commonjs/coders/base/address.js +75 -0
- package/lib/commonjs/coders/base/address.js.map +1 -0
- package/lib/commonjs/coders/base/array.d.ts +4 -0
- package/lib/commonjs/coders/base/array.js +106 -0
- package/lib/commonjs/coders/base/array.js.map +1 -0
- package/lib/commonjs/coders/base/bool.d.ts +4 -0
- package/lib/commonjs/coders/base/bool.js +56 -0
- package/lib/commonjs/coders/base/bool.js.map +1 -0
- package/lib/commonjs/coders/base/bytes.d.ts +4 -0
- package/lib/commonjs/coders/base/bytes.js +101 -0
- package/lib/commonjs/coders/base/bytes.js.map +1 -0
- package/lib/commonjs/coders/base/index.d.ts +11 -0
- package/lib/commonjs/coders/base/index.js +109 -0
- package/lib/commonjs/coders/base/index.js.map +1 -0
- package/lib/commonjs/coders/base/number.d.ts +4 -0
- package/lib/commonjs/coders/base/number.js +116 -0
- package/lib/commonjs/coders/base/number.js.map +1 -0
- package/lib/commonjs/coders/base/numbersLimits.d.ts +4 -0
- package/lib/commonjs/coders/base/numbersLimits.js +40 -0
- package/lib/commonjs/coders/base/numbersLimits.js.map +1 -0
- package/lib/commonjs/coders/base/string.d.ts +4 -0
- package/lib/commonjs/coders/base/string.js +40 -0
- package/lib/commonjs/coders/base/string.js.map +1 -0
- package/lib/commonjs/coders/base/tuple.d.ts +7 -0
- package/lib/commonjs/coders/base/tuple.js +123 -0
- package/lib/commonjs/coders/base/tuple.js.map +1 -0
- package/lib/commonjs/coders/base/utils.d.ts +2 -0
- package/lib/commonjs/coders/base/utils.js +50 -0
- package/lib/commonjs/coders/base/utils.js.map +1 -0
- package/lib/commonjs/coders/decode.d.ts +5 -0
- package/lib/commonjs/coders/decode.js +29 -0
- package/lib/commonjs/coders/decode.js.map +1 -0
- package/lib/commonjs/coders/encode.d.ts +38 -0
- package/lib/commonjs/coders/encode.js +113 -0
- package/lib/commonjs/coders/encode.js.map +1 -0
- package/lib/commonjs/coders/types.d.ts +16 -0
- package/lib/commonjs/coders/types.js +19 -0
- package/lib/commonjs/coders/types.js.map +1 -0
- package/lib/commonjs/coders/utils.d.ts +23 -0
- package/lib/commonjs/coders/utils.js +115 -0
- package/lib/commonjs/coders/utils.js.map +1 -0
- package/lib/commonjs/decode_contract_error_data.d.ts +3 -0
- package/lib/commonjs/decode_contract_error_data.js +73 -0
- package/lib/commonjs/decode_contract_error_data.js.map +1 -0
- package/lib/commonjs/eip_712.d.ts +50 -0
- package/lib/commonjs/eip_712.js +144 -0
- package/lib/commonjs/eip_712.js.map +1 -0
- package/lib/commonjs/index.d.ts +8 -0
- package/lib/commonjs/index.js +43 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils.d.ts +43 -0
- package/lib/commonjs/utils.js +216 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/esm/api/errors_api.js +40 -0
- package/lib/esm/api/errors_api.js.map +1 -0
- package/lib/esm/api/events_api.js +86 -0
- package/lib/esm/api/events_api.js.map +1 -0
- package/lib/esm/api/functions_api.js +134 -0
- package/lib/esm/api/functions_api.js.map +1 -0
- package/lib/esm/api/logs_api.js +103 -0
- package/lib/esm/api/logs_api.js.map +1 -0
- package/lib/esm/api/parameters_api.js +271 -0
- package/lib/esm/api/parameters_api.js.map +1 -0
- package/lib/esm/coders/base/address.js +70 -0
- package/lib/esm/coders/base/address.js.map +1 -0
- package/lib/esm/coders/base/array.js +101 -0
- package/lib/esm/coders/base/array.js.map +1 -0
- package/lib/esm/coders/base/bool.js +51 -0
- package/lib/esm/coders/base/bool.js.map +1 -0
- package/lib/esm/coders/base/bytes.js +96 -0
- package/lib/esm/coders/base/bytes.js.map +1 -0
- package/lib/esm/coders/base/index.js +90 -0
- package/lib/esm/coders/base/index.js.map +1 -0
- package/lib/esm/coders/base/number.js +111 -0
- package/lib/esm/coders/base/number.js.map +1 -0
- package/lib/esm/coders/base/numbersLimits.js +37 -0
- package/lib/esm/coders/base/numbersLimits.js.map +1 -0
- package/lib/esm/coders/base/string.js +35 -0
- package/lib/esm/coders/base/string.js.map +1 -0
- package/lib/esm/coders/base/tuple.js +118 -0
- package/lib/esm/coders/base/tuple.js.map +1 -0
- package/lib/esm/coders/base/utils.js +46 -0
- package/lib/esm/coders/base/utils.js.map +1 -0
- package/lib/esm/coders/decode.js +25 -0
- package/lib/esm/coders/decode.js.map +1 -0
- package/lib/esm/coders/encode.js +108 -0
- package/lib/esm/coders/encode.js.map +1 -0
- package/lib/esm/coders/types.js +18 -0
- package/lib/esm/coders/types.js.map +1 -0
- package/lib/esm/coders/utils.js +105 -0
- package/lib/esm/coders/utils.js.map +1 -0
- package/lib/esm/decode_contract_error_data.js +69 -0
- package/lib/esm/decode_contract_error_data.js.map +1 -0
- package/lib/esm/eip_712.js +140 -0
- package/lib/esm/eip_712.js.map +1 -0
- package/lib/esm/index.js +25 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/utils.js +199 -0
- package/lib/esm/utils.js.map +1 -0
- package/lib/types/api/errors_api.d.ts +6 -0
- package/lib/types/api/errors_api.d.ts.map +1 -0
- package/lib/types/api/events_api.d.ts +52 -0
- package/lib/types/api/events_api.d.ts.map +1 -0
- package/lib/types/api/functions_api.d.ts +93 -0
- package/lib/types/api/functions_api.d.ts.map +1 -0
- package/lib/types/api/logs_api.d.ts +50 -0
- package/lib/types/api/logs_api.d.ts.map +1 -0
- package/lib/types/api/parameters_api.d.ts +239 -0
- package/lib/types/api/parameters_api.d.ts.map +1 -0
- package/lib/types/coders/base/address.d.ts +5 -0
- package/lib/types/coders/base/address.d.ts.map +1 -0
- package/lib/types/coders/base/array.d.ts +5 -0
- package/lib/types/coders/base/array.d.ts.map +1 -0
- package/lib/types/coders/base/bool.d.ts +5 -0
- package/lib/types/coders/base/bool.d.ts.map +1 -0
- package/lib/types/coders/base/bytes.d.ts +5 -0
- package/lib/types/coders/base/bytes.d.ts.map +1 -0
- package/lib/types/coders/base/index.d.ts +12 -0
- package/lib/types/coders/base/index.d.ts.map +1 -0
- package/lib/types/coders/base/number.d.ts +5 -0
- package/lib/types/coders/base/number.d.ts.map +1 -0
- package/lib/types/coders/base/numbersLimits.d.ts +5 -0
- package/lib/types/coders/base/numbersLimits.d.ts.map +1 -0
- package/lib/types/coders/base/string.d.ts +5 -0
- package/lib/types/coders/base/string.d.ts.map +1 -0
- package/lib/types/coders/base/tuple.d.ts +8 -0
- package/lib/types/coders/base/tuple.d.ts.map +1 -0
- package/lib/types/coders/base/utils.d.ts +3 -0
- package/lib/types/coders/base/utils.d.ts.map +1 -0
- package/lib/types/coders/decode.d.ts +6 -0
- package/lib/types/coders/decode.d.ts.map +1 -0
- package/lib/types/coders/encode.d.ts +39 -0
- package/lib/types/coders/encode.d.ts.map +1 -0
- package/lib/types/coders/types.d.ts +17 -0
- package/lib/types/coders/types.d.ts.map +1 -0
- package/lib/types/coders/utils.d.ts +24 -0
- package/lib/types/coders/utils.d.ts.map +1 -0
- package/lib/types/decode_contract_error_data.d.ts +4 -0
- package/lib/types/decode_contract_error_data.d.ts.map +1 -0
- package/lib/types/eip_712.d.ts +51 -0
- package/lib/types/eip_712.d.ts.map +1 -0
- package/lib/types/index.d.ts +9 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/utils.d.ts +44 -0
- package/lib/types/utils.d.ts.map +1 -0
- package/pa8cztln.cjs +1 -0
- package/package.json +56 -0
- package/src/api/errors_api.ts +45 -0
- package/src/api/events_api.ts +91 -0
- package/src/api/functions_api.ts +145 -0
- package/src/api/logs_api.ts +131 -0
- package/src/api/parameters_api.ts +287 -0
- package/src/coders/base/address.ts +75 -0
- package/src/coders/base/array.ts +120 -0
- package/src/coders/base/bool.ts +54 -0
- package/src/coders/base/bytes.ts +106 -0
- package/src/coders/base/index.ts +95 -0
- package/src/coders/base/number.ts +116 -0
- package/src/coders/base/numbersLimits.ts +39 -0
- package/src/coders/base/string.ts +38 -0
- package/src/coders/base/tuple.ts +130 -0
- package/src/coders/base/utils.ts +51 -0
- package/src/coders/decode.ts +32 -0
- package/src/coders/encode.ts +114 -0
- package/src/coders/types.ts +39 -0
- package/src/coders/utils.ts +128 -0
- package/src/decode_contract_error_data.ts +80 -0
- package/src/eip_712.ts +252 -0
- package/src/index.ts +25 -0
- package/src/utils.ts +266 -0
@@ -0,0 +1,118 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { AbiError } from 'web3-errors';
|
18
|
+
import { uint8ArrayConcat } from 'web3-utils';
|
19
|
+
// eslint-disable-next-line import/no-cycle
|
20
|
+
import { decodeParamFromAbiParameter, encodeParamFromAbiParameter } from './index.js';
|
21
|
+
import { encodeDynamicParams } from './utils.js';
|
22
|
+
import { isDynamic } from '../utils.js';
|
23
|
+
import { decodeNumber } from './number.js';
|
24
|
+
export function encodeTuple(param, input) {
|
25
|
+
var _a, _b, _c;
|
26
|
+
let dynamic = false;
|
27
|
+
if (!Array.isArray(input) && typeof input !== 'object') {
|
28
|
+
throw new AbiError('param must be either Array or Object', {
|
29
|
+
param,
|
30
|
+
input,
|
31
|
+
});
|
32
|
+
}
|
33
|
+
const narrowedInput = input;
|
34
|
+
const encoded = [];
|
35
|
+
for (let i = 0; i < ((_b = (_a = param.components) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); i += 1) {
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
37
|
+
const paramComponent = param.components[i];
|
38
|
+
let result;
|
39
|
+
if (Array.isArray(narrowedInput)) {
|
40
|
+
if (i >= narrowedInput.length) {
|
41
|
+
throw new AbiError('input param length missmatch', {
|
42
|
+
param,
|
43
|
+
input,
|
44
|
+
});
|
45
|
+
}
|
46
|
+
result = encodeParamFromAbiParameter(paramComponent, narrowedInput[i]);
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
const paramInput = narrowedInput[(_c = paramComponent.name) !== null && _c !== void 0 ? _c : ''];
|
50
|
+
// eslint-disable-next-line no-null/no-null
|
51
|
+
if (paramInput === undefined || paramInput === null) {
|
52
|
+
throw new AbiError('missing input defined in abi', {
|
53
|
+
param,
|
54
|
+
input,
|
55
|
+
paramName: paramComponent.name,
|
56
|
+
});
|
57
|
+
}
|
58
|
+
result = encodeParamFromAbiParameter(paramComponent, paramInput);
|
59
|
+
}
|
60
|
+
if (result.dynamic) {
|
61
|
+
dynamic = true;
|
62
|
+
}
|
63
|
+
encoded.push(result);
|
64
|
+
}
|
65
|
+
if (dynamic) {
|
66
|
+
return {
|
67
|
+
dynamic: true,
|
68
|
+
encoded: encodeDynamicParams(encoded),
|
69
|
+
};
|
70
|
+
}
|
71
|
+
return {
|
72
|
+
dynamic: false,
|
73
|
+
encoded: uint8ArrayConcat(...encoded.map(e => e.encoded)),
|
74
|
+
};
|
75
|
+
}
|
76
|
+
export function decodeTuple(param, bytes) {
|
77
|
+
const result = {
|
78
|
+
__length__: 0,
|
79
|
+
};
|
80
|
+
// tracks how much static params consumed bytes
|
81
|
+
let consumed = 0;
|
82
|
+
if (!param.components) {
|
83
|
+
return {
|
84
|
+
result,
|
85
|
+
encoded: bytes,
|
86
|
+
consumed,
|
87
|
+
};
|
88
|
+
}
|
89
|
+
// track how much dynamic params consumed bytes
|
90
|
+
let dynamicConsumed = 0;
|
91
|
+
for (const [index, childParam] of param.components.entries()) {
|
92
|
+
let decodedResult;
|
93
|
+
if (isDynamic(childParam)) {
|
94
|
+
// if dynamic, we will have offset encoded
|
95
|
+
const offsetResult = decodeNumber({ type: 'uint32', name: '' }, bytes.subarray(consumed));
|
96
|
+
// offset counts from start of original byte sequence
|
97
|
+
decodedResult = decodeParamFromAbiParameter(childParam, bytes.subarray(Number(offsetResult.result)));
|
98
|
+
consumed += offsetResult.consumed;
|
99
|
+
dynamicConsumed += decodedResult.consumed;
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
// static param, just decode
|
103
|
+
decodedResult = decodeParamFromAbiParameter(childParam, bytes.subarray(consumed));
|
104
|
+
consumed += decodedResult.consumed;
|
105
|
+
}
|
106
|
+
result.__length__ += 1;
|
107
|
+
result[index] = decodedResult.result;
|
108
|
+
if (childParam.name && childParam.name !== '') {
|
109
|
+
result[childParam.name] = decodedResult.result;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
return {
|
113
|
+
encoded: bytes.subarray(consumed + dynamicConsumed),
|
114
|
+
result,
|
115
|
+
consumed: consumed + dynamicConsumed,
|
116
|
+
};
|
117
|
+
}
|
118
|
+
//# sourceMappingURL=tuple.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../../src/coders/base/tuple.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AACF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,2CAA2C;AAC3C,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,UAAU,WAAW,CAAC,KAAmB,EAAE,KAAc;;IAC9D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACvD,MAAM,IAAI,QAAQ,CAAC,sCAAsC,EAAE;YAC1D,KAAK;YACL,KAAK;SACL,CAAC,CAAC;KACH;IACD,MAAM,aAAa,GAAG,KAAiD,CAAC;IACxE,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,UAAU,0CAAE,MAAM,mCAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QAC5D,oEAAoE;QACpE,MAAM,cAAc,GAAG,KAAK,CAAC,UAAW,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,MAAqB,CAAC;QAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACjC,IAAI,CAAC,I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
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { uint8ArrayConcat } from 'web3-utils';
|
18
|
+
import { WORD_SIZE } from '../utils.js';
|
19
|
+
import { encodeNumber } from './number.js';
|
20
|
+
export function encodeDynamicParams(encodedParams) {
|
21
|
+
let staticSize = 0;
|
22
|
+
let dynamicSize = 0;
|
23
|
+
const staticParams = [];
|
24
|
+
const dynamicParams = [];
|
25
|
+
// figure out static size
|
26
|
+
for (const encodedParam of encodedParams) {
|
27
|
+
if (encodedParam.dynamic) {
|
28
|
+
staticSize += WORD_SIZE;
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
staticSize += encodedParam.encoded.length;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
for (const encodedParam of encodedParams) {
|
35
|
+
if (encodedParam.dynamic) {
|
36
|
+
staticParams.push(encodeNumber({ type: 'uint256', name: '' }, staticSize + dynamicSize));
|
37
|
+
dynamicParams.push(encodedParam);
|
38
|
+
dynamicSize += encodedParam.encoded.length;
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
staticParams.push(encodedParam);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return uint8ArrayConcat(...staticParams.map(p => p.encoded), ...dynamicParams.map(p => p.encoded));
|
45
|
+
}
|
46
|
+
//# sourceMappingUR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,CAAC,OAAO,CAAC,CACpC,CAAC;AACH,CAAC"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { utils } from 'web3-validator';
|
18
|
+
import { decodeTuple } from './base/tuple.js';
|
19
|
+
import { toAbiParams } from './utils.js';
|
20
|
+
export function decodeParameters(abis, bytes, _loose) {
|
21
|
+
const abiParams = toAbiParams(abis);
|
22
|
+
const bytesArray = utils.hexToUint8Array(bytes);
|
23
|
+
return decodeTuple({ type: 'tuple', name: '', components: abiParams }, bytesArray).result;
|
24
|
+
}
|
25
|
+
//# sourceMappingURL=decode.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../../src/coders/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAGF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,UAAU,gBAAgB,CAC/B,IAA0C,EAC1C,KAAgB,EAChB,MAAe;IAEf,MAAM,SAAS,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEhD,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC;AAC3F,CAAC"}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { AbiError } from 'web3-errors';
|
18
|
+
import { toHex } from 'web3-utils';
|
19
|
+
import { utils } from 'web3-validator';
|
20
|
+
import { encodeTuple } from './base/index.js';
|
21
|
+
import { toAbiParams } from './utils.js';
|
22
|
+
/**
|
23
|
+
* @param params - The params to infer the ABI from
|
24
|
+
* @returns The inferred ABI
|
25
|
+
* @example
|
26
|
+
* ```
|
27
|
+
* inferParamsAbi([1, -1, 'hello', '0x1234', ])
|
28
|
+
* ```
|
29
|
+
* > [{ type: 'int256' }, { type: 'uint256' }, { type: 'string' }, { type: 'bytes' }]
|
30
|
+
* ```
|
31
|
+
*/
|
32
|
+
function inferParamsAbi(params) {
|
33
|
+
const abi = [];
|
34
|
+
params.forEach(param => {
|
35
|
+
if (Array.isArray(param)) {
|
36
|
+
const inferredParams = inferParamsAbi(param);
|
37
|
+
abi.push({
|
38
|
+
type: 'tuple',
|
39
|
+
components: inferredParams,
|
40
|
+
name: '',
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
42
|
+
});
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
46
|
+
abi.push({ type: toHex(param, true) });
|
47
|
+
}
|
48
|
+
});
|
49
|
+
return abi;
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Encodes a parameter based on its type to its ABI representation.
|
53
|
+
* @param abi - An array of {@link AbiInput}. See [Solidity's documentation](https://solidity.readthedocs.io/en/v0.5.3/abi-spec.html#json) for more details.
|
54
|
+
* @param params - The actual parameters to encode.
|
55
|
+
* @returns - The ABI encoded parameters
|
56
|
+
* @example
|
57
|
+
* ```ts
|
58
|
+
* const res = web3.eth.abi.encodeParameters(
|
59
|
+
* ["uint256", "string"],
|
60
|
+
* ["2345675643", "Hello!%"]
|
61
|
+
* );
|
62
|
+
*
|
63
|
+
* console.log(res);
|
64
|
+
* > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
|
65
|
+
* ```
|
66
|
+
*/
|
67
|
+
export function encodeParameters(abi, params) {
|
68
|
+
if ((abi === null || abi === void 0 ? void 0 : abi.length) !== params.length) {
|
69
|
+
throw new AbiError('Invalid number of values received for given ABI', {
|
70
|
+
expected: abi === null || abi === void 0 ? void 0 : abi.length,
|
71
|
+
received: params.length,
|
72
|
+
});
|
73
|
+
}
|
74
|
+
const abiParams = toAbiParams(abi);
|
75
|
+
return utils.uint8ArrayToHexString(encodeTuple({ type: 'tuple', name: '', components: abiParams }, params).encoded);
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
* Infer a smart contract method parameter type and then encode this parameter.
|
79
|
+
* @param params - The parameters to encode.
|
80
|
+
* @returns - The ABI encoded parameters
|
81
|
+
*
|
82
|
+
* @remarks
|
83
|
+
* This method is useful when you don't know the type of the parameters you want to encode. It will infer the type of the parameters and then encode them.
|
84
|
+
* However, it is not recommended to use this method when you know the type of the parameters you want to encode. In this case, use the {@link encodeParameters} method instead.
|
85
|
+
* The type inference is not perfect and can lead to unexpected results. Especially when you want to encode an array, uint that is not uint256 or bytes....
|
86
|
+
* @example
|
87
|
+
* ```ts
|
88
|
+
* const res = web3.eth.abi.encodeParameters(
|
89
|
+
* ["2345675643", "Hello!%"]
|
90
|
+
* );
|
91
|
+
*
|
92
|
+
* console.log(res);
|
93
|
+
* > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
|
94
|
+
* ```
|
95
|
+
*/
|
96
|
+
export function inferTypesAndEncodeParameters(params) {
|
97
|
+
try {
|
98
|
+
const abiParams = inferParamsAbi(params);
|
99
|
+
return utils.uint8ArrayToHexString(encodeTuple({ type: 'tuple', name: '', components: abiParams }, params).encoded);
|
100
|
+
}
|
101
|
+
catch (e) {
|
102
|
+
// throws If the inferred params type caused an error
|
103
|
+
throw new AbiError('Could not infer types from given params', {
|
104
|
+
params,
|
105
|
+
});
|
106
|
+
}
|
107
|
+
}
|
108
|
+
//# sourceMappingURL=encode.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/coders/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AACF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;;;GASG;AACH,SAAS,cAAc,CAAC,MAAiB;IACxC,MAAM,G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,OAAO,KAAK,CAAC,qBAAqB,CACjC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,OAAO,CAC/E,CAAC;KACF;IAAC,OAAO,CAAC,EAAE;QACX,qDAAqD;QACrD,MAAM,IAAI,QAAQ,CAAC,yCAAyC,EAAE;YAC7D,MAAM;SACN,CAAC,CAAC;KACH;AACF,CAAC"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
export {};
|
18
|
+
//# sourceMappingURL=types.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/coders/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE"}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { parseAbiParameter } from 'abitype';
|
18
|
+
import { AbiError } from 'web3-errors';
|
19
|
+
import { isNullish } from 'web3-utils';
|
20
|
+
import { isSimplifiedStructFormat, mapStructNameAndType, mapStructToCoderFormat, } from '../utils.js';
|
21
|
+
export const WORD_SIZE = 32;
|
22
|
+
export function alloc(size = 0) {
|
23
|
+
var _a;
|
24
|
+
if (((_a = globalThis.Buffer) === null || _a === void 0 ? void 0 : _a.alloc) !== undefined) {
|
25
|
+
const buf = globalThis.Buffer.alloc(size);
|
26
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
27
|
+
}
|
28
|
+
return new Uint8Array(size);
|
29
|
+
}
|
30
|
+
/**
|
31
|
+
* Where possible returns a Uint8Array of the requested size that references
|
32
|
+
* uninitialized memory. Only use if you are certain you will immediately
|
33
|
+
* overwrite every value in the returned `Uint8Array`.
|
34
|
+
*/
|
35
|
+
export function allocUnsafe(size = 0) {
|
36
|
+
var _a;
|
37
|
+
if (((_a = globalThis.Buffer) === null || _a === void 0 ? void 0 : _a.allocUnsafe) !== undefined) {
|
38
|
+
const buf = globalThis.Buffer.allocUnsafe(size);
|
39
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
40
|
+
}
|
41
|
+
return new Uint8Array(size);
|
42
|
+
}
|
43
|
+
export function convertExternalAbiParameter(abiParam) {
|
44
|
+
var _a, _b;
|
45
|
+
return Object.assign(Object.assign({}, abiParam), { name: (_a = abiParam.name) !== null && _a !== void 0 ? _a : '', components: (_b = abiParam.components) === null || _b === void 0 ? void 0 : _b.map(c => convertExternalAbiParameter(c)) });
|
46
|
+
}
|
47
|
+
export function isAbiParameter(param) {
|
48
|
+
return (!isNullish(param) &&
|
49
|
+
typeof param === 'object' &&
|
50
|
+
!isNullish(param.type) &&
|
51
|
+
typeof param.type === 'string');
|
52
|
+
}
|
53
|
+
export function toAbiParams(abi) {
|
54
|
+
return abi.map(input => {
|
55
|
+
var _a;
|
56
|
+
if (isAbiParameter(input)) {
|
57
|
+
return input;
|
58
|
+
}
|
59
|
+
if (typeof input === 'string') {
|
60
|
+
return convertExternalAbiParameter(parseAbiParameter(input.replace(/tuple/, '')));
|
61
|
+
}
|
62
|
+
if (isSimplifiedStructFormat(input)) {
|
63
|
+
const structName = Object.keys(input)[0];
|
64
|
+
const structInfo = mapStructNameAndType(structName);
|
65
|
+
structInfo.name = (_a = structInfo.name) !== null && _a !== void 0 ? _a : '';
|
66
|
+
return Object.assign(Object.assign({}, structInfo), { components: mapStructToCoderFormat(input[structName]) });
|
67
|
+
}
|
68
|
+
throw new AbiError('Invalid abi');
|
69
|
+
});
|
70
|
+
}
|
71
|
+
export function extractArrayType(param) {
|
72
|
+
const arrayParenthesisStart = param.type.lastIndexOf('[');
|
73
|
+
const arrayParamType = param.type.substring(0, arrayParenthesisStart);
|
74
|
+
const sizeString = param.type.substring(arrayParenthesisStart);
|
75
|
+
let size = -1;
|
76
|
+
if (sizeString !== '[]') {
|
77
|
+
size = Number(sizeString.slice(1, -1));
|
78
|
+
// eslint-disable-next-line no-restricted-globals
|
79
|
+
if (isNaN(size)) {
|
80
|
+
throw new AbiError('Invalid fixed array size', { size: sizeString });
|
81
|
+
}
|
82
|
+
}
|
83
|
+
return {
|
84
|
+
param: { type: arrayParamType, name: '', components: param.components },
|
85
|
+
size,
|
86
|
+
};
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Param is dynamic if it's dynamic base type or if some of his children (components, array items)
|
90
|
+
* is of dynamic type
|
91
|
+
* @param param
|
92
|
+
*/
|
93
|
+
export function isDynamic(param) {
|
94
|
+
var _a, _b;
|
95
|
+
if (param.type === 'string' || param.type === 'bytes' || param.type.endsWith('[]'))
|
96
|
+
return true;
|
97
|
+
if (param.type === 'tuple') {
|
98
|
+
return (_b = (_a = param.components) === null || _a === void 0 ? void 0 : _a.some(isDynamic)) !== null && _b !== void 0 ? _b : false;
|
99
|
+
}
|
100
|
+
if (param.type.endsWith(']')) {
|
101
|
+
return isDynamic(extractArrayType(param).param);
|
102
|
+
}
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/coders/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF,OAAO,EAAwC,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,GACtB,MAAM,aAAa,CAAC;AAErB,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC;AAE5B,MAAM,UAAU,KAAK,CAAC,IAAI,GAAG,CAAC;;IAC7B,IAAI,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,KAAK,MAAK,SAAS,EAAE;QAC3C,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;KAClE;IAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAI,GAAG,CAAC;;IACnC,IAAI,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,WAAW,MAAK,SAAS,EAAE;QACjD,MAAM,GAAG,GAAG,UAAU,CAAC,MAA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AAI,KAAK,OAAO,EAAE;QAC3B,OAAO,MAAA,MAAA,KAAK,CAAC,UAAU,0CAAE,IAAI,CAAC,SAAS,CAAC,mCAAI,KAAK,CAAC;KAClD;IACD,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC7B,OAAO,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;KAChD;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { encodeErrorSignature } from './api/errors_api.js';
|
18
|
+
import { decodeParameters } from './api/parameters_api.js';
|
19
|
+
import { jsonInterfaceMethodToString } from './utils.js';
|
20
|
+
export const decodeContractErrorData = (errorsAbi, error) => {
|
21
|
+
if (error === null || error === void 0 ? void 0 : error.data) {
|
22
|
+
let errorName;
|
23
|
+
let errorSignature;
|
24
|
+
let errorArgs;
|
25
|
+
try {
|
26
|
+
const errorSha = error.data.slice(0, 10);
|
27
|
+
const errorAbi = errorsAbi.find(abi => encodeErrorSignature(abi).startsWith(errorSha));
|
28
|
+
if (errorAbi === null || errorAbi === void 0 ? void 0 : errorAbi.inputs) {
|
29
|
+
errorName = errorAbi.name;
|
30
|
+
errorSignature = jsonInterfaceMethodToString(errorAbi);
|
31
|
+
// decode abi.inputs according to EIP-838
|
32
|
+
errorArgs = decodeParameters([...errorAbi.inputs], error.data.substring(10));
|
33
|
+
}
|
34
|
+
else if (error.data.startsWith('0x08c379a0')) {
|
35
|
+
// If ABI was not provided, check for the 2 famous errors: 'Error(string)' or 'Panic(uint256)'
|
36
|
+
errorName = 'Error';
|
37
|
+
errorSignature = 'Error(string)';
|
38
|
+
// decode abi.inputs according to EIP-838
|
39
|
+
errorArgs = decodeParameters([
|
40
|
+
{
|
41
|
+
name: 'message',
|
42
|
+
type: 'string',
|
43
|
+
},
|
44
|
+
], error.data.substring(10));
|
45
|
+
}
|
46
|
+
else if (error.data.startsWith('0x4e487b71')) {
|
47
|
+
errorName = 'Panic';
|
48
|
+
errorSignature = 'Panic(uint256)';
|
49
|
+
// decode abi.inputs according to EIP-838
|
50
|
+
errorArgs = decodeParameters([
|
51
|
+
{
|
52
|
+
name: 'code',
|
53
|
+
type: 'uint256',
|
54
|
+
},
|
55
|
+
], error.data.substring(10));
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
console.error('No matching error abi found for error data', error.data);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
catch (err) {
|
62
|
+
console.error(err);
|
63
|
+
}
|
64
|
+
if (errorName) {
|
65
|
+
error.setDecodedProperties(errorName, errorSignature, errorArgs);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
};
|
69
|
+
//# sourceMappingURL=decode_contract_error_data.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"decode_contract_error_data.js","sourceRoot":"","sources":["../../src/decode_contract_error_data.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAKF,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAEzD,MAAM,CAAC,M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