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 @@
|
|
1
|
+
{"version":3,"file":"errors_api.js","sourceRoot":"","sources":["../../../src/api/errors_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9E;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAuC,EAAU,EAAE;IACvF,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE;QAC1E,MAAM,IAAI,QAAQ,CAAC,iDAAiD,CAAC,CAAC;KACtE;IAED,IAAI,IAAY,CAAC;IAEjB,IAAI,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,UAAU,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE;QAC7F,IAAI,GAAG,2BAA2B,CAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACN,IAAI,GAAG,YAAY,CAAC;KACpB;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC,CAAC"}
|
@@ -0,0 +1,86 @@
|
|
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
|
+
/**
|
18
|
+
*
|
19
|
+
* @module ABI
|
20
|
+
*/
|
21
|
+
import { sha3Raw } from 'web3-utils';
|
22
|
+
import { AbiError } from 'web3-errors';
|
23
|
+
import { jsonInterfaceMethodToString, isAbiEventFragment } from '../utils.js';
|
24
|
+
/**
|
25
|
+
* Encodes the event name to its ABI signature, which are the sha3 hash of the event name including input types.
|
26
|
+
* @param functionName - The event name to encode, or the {@link AbiEventFragment} object of the event. If string, it has to be in the form of `eventName(param1Type,param2Type,...)`. eg: myEvent(uint256,bytes32).
|
27
|
+
* @returns - The ABI signature of the event.
|
28
|
+
*
|
29
|
+
* @example
|
30
|
+
* ```ts
|
31
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
32
|
+
* name: "myEvent",
|
33
|
+
* type: "event",
|
34
|
+
* inputs: [
|
35
|
+
* {
|
36
|
+
* type: "uint256",
|
37
|
+
* name: "myNumber",
|
38
|
+
* },
|
39
|
+
* {
|
40
|
+
* type: "bytes32",
|
41
|
+
* name: "myBytes",
|
42
|
+
* },
|
43
|
+
* ],
|
44
|
+
* });
|
45
|
+
* console.log(event);
|
46
|
+
* > 0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97
|
47
|
+
*
|
48
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
49
|
+
* inputs: [
|
50
|
+
* {
|
51
|
+
* indexed: true,
|
52
|
+
* name: "from",
|
53
|
+
* type: "address",
|
54
|
+
* },
|
55
|
+
* {
|
56
|
+
* indexed: true,
|
57
|
+
* name: "to",
|
58
|
+
* type: "address",
|
59
|
+
* },
|
60
|
+
* {
|
61
|
+
* indexed: false,
|
62
|
+
* name: "value",
|
63
|
+
* type: "uint256",
|
64
|
+
* },
|
65
|
+
* ],
|
66
|
+
* name: "Transfer",
|
67
|
+
* type: "event",
|
68
|
+
* });
|
69
|
+
* console.log(event);
|
70
|
+
* > 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
|
71
|
+
* ```
|
72
|
+
*/
|
73
|
+
export const encodeEventSignature = (functionName) => {
|
74
|
+
if (typeof functionName !== 'string' && !isAbiEventFragment(functionName)) {
|
75
|
+
throw new AbiError('Invalid parameter value in encodeEventSignature');
|
76
|
+
}
|
77
|
+
let name;
|
78
|
+
if (functionName && (typeof functionName === 'function' || typeof functionName === 'object')) {
|
79
|
+
name = jsonInterfaceMethodToString(functionName);
|
80
|
+
}
|
81
|
+
else {
|
82
|
+
name = functionName;
|
83
|
+
}
|
84
|
+
return sha3Raw(name);
|
85
|
+
};
|
86
|
+
//# sourceMappingURL=events_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"events_api.js","sourceRoot":"","sources":["../../../src/api/events_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,YAAuC,EAAU,EAAE;IACvF,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE;QAC1E,MAAM,IAAI,QAAQ,CAAC,iDAAiD,CAAC,CAAC;KACtE;IAED,IAAI,IAAY,CAAC;IAEjB,IAAI,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,UAAU,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE;QAC7F,IAAI,GAAG,2BAA2B,CAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACN,IAAI,GAAG,YAAY,CAAC;KACpB;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC,CAAC"}
|
@@ -0,0 +1,134 @@
|
|
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
|
+
/**
|
18
|
+
*
|
19
|
+
* @module ABI
|
20
|
+
*/
|
21
|
+
import { AbiError } from 'web3-errors';
|
22
|
+
import { sha3Raw } from 'web3-utils';
|
23
|
+
import { isAbiFunctionFragment, jsonInterfaceMethodToString } from '../utils.js';
|
24
|
+
import { encodeParameters } from './parameters_api.js';
|
25
|
+
/**
|
26
|
+
* Encodes the function name to its ABI representation, which are the first 4 bytes of the sha3 of the function name including types.
|
27
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
28
|
+
* @param functionName - The function name to encode or the `JSON interface` object of the function.
|
29
|
+
* If the passed parameter is a string, it has to be in the form of `functionName(param1Type,param2Type,...)`. eg: myFunction(uint256,uint32[],bytes10,bytes)
|
30
|
+
* @returns - The ABI signature of the function.
|
31
|
+
* @example
|
32
|
+
* ```ts
|
33
|
+
* const signature = web3.eth.abi.encodeFunctionSignature({
|
34
|
+
* name: "myMethod",
|
35
|
+
* type: "function",
|
36
|
+
* inputs: [
|
37
|
+
* {
|
38
|
+
* type: "uint256",
|
39
|
+
* name: "myNumber",
|
40
|
+
* },
|
41
|
+
* {
|
42
|
+
* type: "string",
|
43
|
+
* name: "myString",
|
44
|
+
* },
|
45
|
+
* ],
|
46
|
+
* });
|
47
|
+
* console.log(signature);
|
48
|
+
* > 0x24ee0097
|
49
|
+
*
|
50
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
|
51
|
+
* console.log(signature);
|
52
|
+
* > 0x24ee0097
|
53
|
+
*
|
54
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('safeTransferFrom(address,address,uint256,bytes)');
|
55
|
+
* console.log(signature);
|
56
|
+
* > 0xb88d4fde
|
57
|
+
* ```
|
58
|
+
*/
|
59
|
+
export const encodeFunctionSignature = (functionName) => {
|
60
|
+
if (typeof functionName !== 'string' && !isAbiFunctionFragment(functionName)) {
|
61
|
+
throw new AbiError('Invalid parameter value in encodeFunctionSignature');
|
62
|
+
}
|
63
|
+
let name;
|
64
|
+
if (functionName && (typeof functionName === 'function' || typeof functionName === 'object')) {
|
65
|
+
name = jsonInterfaceMethodToString(functionName);
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
name = functionName;
|
69
|
+
}
|
70
|
+
return sha3Raw(name).slice(0, 10);
|
71
|
+
};
|
72
|
+
/**
|
73
|
+
* Encodes a function call using its `JSON interface` object and given parameters.
|
74
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
75
|
+
* @param jsonInterface - The `JSON interface` object of the function.
|
76
|
+
* @param params - The parameters to encode
|
77
|
+
* @returns - The ABI encoded function call, which, means the function signature and the parameters passed.
|
78
|
+
* @example
|
79
|
+
* ```ts
|
80
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
81
|
+
* {
|
82
|
+
* name: "myMethod",
|
83
|
+
* type: "function",
|
84
|
+
* inputs: [
|
85
|
+
* {
|
86
|
+
* type: "uint256",
|
87
|
+
* name: "myNumber",
|
88
|
+
* },
|
89
|
+
* {
|
90
|
+
* type: "string",
|
91
|
+
* name: "myString",
|
92
|
+
* },
|
93
|
+
* ],
|
94
|
+
* },
|
95
|
+
* ["2345675643", "Hello!%"]
|
96
|
+
* );
|
97
|
+
* console.log(sig);
|
98
|
+
* > 0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
|
99
|
+
*
|
100
|
+
*
|
101
|
+
*
|
102
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
103
|
+
* {
|
104
|
+
* inputs: [
|
105
|
+
* {
|
106
|
+
* name: "account",
|
107
|
+
* type: "address",
|
108
|
+
* },
|
109
|
+
* ],
|
110
|
+
* name: "balanceOf",
|
111
|
+
* outputs: [
|
112
|
+
* {
|
113
|
+
* name: "",
|
114
|
+
* type: "uint256",
|
115
|
+
* },
|
116
|
+
* ],
|
117
|
+
* stateMutability: "view",
|
118
|
+
* type: "function",
|
119
|
+
* },
|
120
|
+
* ["0x1234567890123456789012345678901234567890"]
|
121
|
+
* );
|
122
|
+
*
|
123
|
+
* console.log(sig);
|
124
|
+
* > 0x70a082310000000000000000000000001234567890123456789012345678901234567890
|
125
|
+
* ```
|
126
|
+
*/
|
127
|
+
export const encodeFunctionCall = (jsonInterface, params) => {
|
128
|
+
var _a;
|
129
|
+
if (!isAbiFunctionFragment(jsonInterface)) {
|
130
|
+
throw new AbiError('Invalid parameter value in encodeFunctionCall');
|
131
|
+
}
|
132
|
+
return `${encodeFunctionSignature(jsonInterface)}${encodeParameters((_a = jsonInterface.inputs) !== null && _a !== void 0 ? _a : [], params !== null && params !== void 0 ? params : []).replace('0x', '')}`;
|
133
|
+
};
|
134
|
+
//# sourceMappingURL=functions_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"functions_api.js","sourceRoot":"","sources":["../../../src/api/functions_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,YAA0C,EAAU,EAAE;IAC7F,IAAI,OAAO,YAAY,KAAK,QAAQ,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE;QAC7E,MAAM,IAAI,QAAQ,CAAC,oDAAoD,CAAC,CAAC;KACzE;IAED,IAAI,IAAY,CAAC;IAEjB,IAAI,YAAY,IAAI,CAAC,OAAO,YAAY,KAAK,UAAU,IAAI,OAAO,YAAY,KAAK,QAAQ,CAAC,EAAE;QAC7F,IAAI,GAAG,2BAA2B,CAAC,YAAY,CAAC,CAAC;KACjD;SAAM;QACN,IAAI,GAAG,YAAY,CAAC;KACpB;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CACjC,aAAkC,EAClC,MAAiB,EACR,EAAE;;IACX,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,EAAE;QAC1C,MAAM,IAAI,QAAQ,CAAC,+CAA+C,CAAC,CAAC;KACpE;IAED,OAAO,GAAG,uBAAuB,CAAC,aAAa,CAAC,GAAG,gBAAgB,CAClE,MAAA,aAAa,CAAC,MAAM,mCAAI,EAAE,EAC1B,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CACZ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;AACvB,CAAC,CAAC"}
|
@@ -0,0 +1,103 @@
|
|
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 { decodeParameter, decodeParametersWith } from './parameters_api.js';
|
18
|
+
const STATIC_TYPES = ['bool', 'string', 'int', 'uint', 'address', 'fixed', 'ufixed'];
|
19
|
+
const _decodeParameter = (inputType, clonedTopic) => inputType === 'string' ? clonedTopic : decodeParameter(inputType, clonedTopic);
|
20
|
+
/**
|
21
|
+
* Decodes ABI-encoded log data and indexed topic data.
|
22
|
+
* @param inputs - A {@link AbiParameter} input array. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
23
|
+
* @param data - The ABI byte code in the `data` field of a log.
|
24
|
+
* @param topics - An array with the index parameter topics of the log, without the topic[0] if its a non-anonymous event, otherwise with topic[0]
|
25
|
+
* @returns - The result object containing the decoded parameters.
|
26
|
+
*
|
27
|
+
* @example
|
28
|
+
* ```ts
|
29
|
+
* let res = web3.eth.abi.decodeLog(
|
30
|
+
* [
|
31
|
+
* {
|
32
|
+
* type: "string",
|
33
|
+
* name: "myString",
|
34
|
+
* },
|
35
|
+
* {
|
36
|
+
* type: "uint256",
|
37
|
+
* name: "myNumber",
|
38
|
+
* indexed: true,
|
39
|
+
* },
|
40
|
+
* {
|
41
|
+
* type: "uint8",
|
42
|
+
* name: "mySmallNumber",
|
43
|
+
* indexed: true,
|
44
|
+
* },
|
45
|
+
* ],
|
46
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000748656c6c6f252100000000000000000000000000000000000000000000000000",
|
47
|
+
* [
|
48
|
+
* "0x000000000000000000000000000000000000000000000000000000000000f310",
|
49
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000010",
|
50
|
+
* ]
|
51
|
+
* );
|
52
|
+
* > {
|
53
|
+
* '0': 'Hello%!',
|
54
|
+
* '1': 62224n,
|
55
|
+
* '2': 16n,
|
56
|
+
* __length__: 3,
|
57
|
+
* myString: 'Hello%!',
|
58
|
+
* myNumber: 62224n,
|
59
|
+
* mySmallNumber: 16n
|
60
|
+
* }
|
61
|
+
* ```
|
62
|
+
*/
|
63
|
+
export const decodeLog = (inputs, data, topics) => {
|
64
|
+
const clonedTopics = Array.isArray(topics) ? topics : [topics];
|
65
|
+
const indexedInputs = {};
|
66
|
+
const nonIndexedInputs = {};
|
67
|
+
for (const [i, input] of inputs.entries()) {
|
68
|
+
if (input.indexed) {
|
69
|
+
indexedInputs[i] = input;
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
nonIndexedInputs[i] = input;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
const decodedNonIndexedInputs = data
|
76
|
+
? decodeParametersWith(Object.values(nonIndexedInputs), data, true)
|
77
|
+
: { __length__: 0 };
|
78
|
+
// If topics are more than indexed inputs, that means first topic is the event signature
|
79
|
+
const offset = clonedTopics.length - Object.keys(indexedInputs).length;
|
80
|
+
const decodedIndexedInputs = Object.values(indexedInputs).map((input, index) => STATIC_TYPES.some(s => input.type.startsWith(s))
|
81
|
+
? _decodeParameter(input.type, clonedTopics[index + offset])
|
82
|
+
: clonedTopics[index + offset]);
|
83
|
+
const returnValues = { __length__: 0 };
|
84
|
+
let indexedCounter = 0;
|
85
|
+
let nonIndexedCounter = 0;
|
86
|
+
for (const [i, res] of inputs.entries()) {
|
87
|
+
returnValues[i] = res.type === 'string' ? '' : undefined;
|
88
|
+
if (indexedInputs[i]) {
|
89
|
+
returnValues[i] = decodedIndexedInputs[indexedCounter];
|
90
|
+
indexedCounter += 1;
|
91
|
+
}
|
92
|
+
if (nonIndexedInputs[i]) {
|
93
|
+
returnValues[i] = decodedNonIndexedInputs[String(nonIndexedCounter)];
|
94
|
+
nonIndexedCounter += 1;
|
95
|
+
}
|
96
|
+
if (res.name) {
|
97
|
+
returnValues[res.name] = returnValues[i];
|
98
|
+
}
|
99
|
+
returnValues.__length__ += 1;
|
100
|
+
}
|
101
|
+
return returnValues;
|
102
|
+
};
|
103
|
+
//# sourceMappingURL=logs_api.js.map
|
@@ -0,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IAAI,EAAE;YACb,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;SACzC;QAED,YAAY,CAAC,UAAU,IAAI,CAAC,CAAC;KAC7B;IAED,OAAO,YAA0B,CAAC;AACnC,CAAC,CAAC"}
|
@@ -0,0 +1,271 @@
|
|
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
|
+
/**
|
18
|
+
*
|
19
|
+
* @module ABI
|
20
|
+
*/
|
21
|
+
import { AbiError } from 'web3-errors';
|
22
|
+
import { decodeParameters as decodeParametersInternal } from '../coders/decode.js';
|
23
|
+
import { encodeParameters } from '../coders/encode.js';
|
24
|
+
export { encodeParameters, inferTypesAndEncodeParameters } from '../coders/encode.js';
|
25
|
+
/**
|
26
|
+
* Encodes a parameter based on its type to its ABI representation.
|
27
|
+
* @param abi - The type of the parameter. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
28
|
+
* @param param - The actual parameter to encode.
|
29
|
+
* @returns - The ABI encoded parameter
|
30
|
+
* @example
|
31
|
+
* ```ts
|
32
|
+
* const res = web3.eth.abi.encodeParameter("uint256", "2345675643");
|
33
|
+
* console.log(res);
|
34
|
+
* 0x000000000000000000000000000000000000000000000000000000008bd02b7b
|
35
|
+
*
|
36
|
+
* const res = web3.eth.abi.encodeParameter("uint", "2345675643");
|
37
|
+
*
|
38
|
+
* console.log(res);
|
39
|
+
* >0x000000000000000000000000000000000000000000000000000000008bd02b7b
|
40
|
+
*
|
41
|
+
* const res = web3.eth.abi.encodeParameter("bytes32", "0xdf3234");
|
42
|
+
*
|
43
|
+
* console.log(res);
|
44
|
+
* >0xdf32340000000000000000000000000000000000000000000000000000000000
|
45
|
+
*
|
46
|
+
* const res = web3.eth.abi.encodeParameter("bytes", "0xdf3234");
|
47
|
+
*
|
48
|
+
* console.log(res);
|
49
|
+
* > 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003df32340000000000000000000000000000000000000000000000000000000000
|
50
|
+
*
|
51
|
+
* const res = web3.eth.abi.encodeParameter("bytes32[]", ["0xdf3234", "0xfdfd"]);
|
52
|
+
*
|
53
|
+
* console.log(res);
|
54
|
+
* > 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000
|
55
|
+
*
|
56
|
+
* const res = web3.eth.abi.encodeParameter(
|
57
|
+
* {
|
58
|
+
* ParentStruct: {
|
59
|
+
* propertyOne: "uint256",
|
60
|
+
* propertyTwo: "uint256",
|
61
|
+
* childStruct: {
|
62
|
+
* propertyOne: "uint256",
|
63
|
+
* propertyTwo: "uint256",
|
64
|
+
* },
|
65
|
+
* },
|
66
|
+
* },
|
67
|
+
* {
|
68
|
+
* propertyOne: 42,
|
69
|
+
* propertyTwo: 56,
|
70
|
+
* childStruct: {
|
71
|
+
* propertyOne: 45,
|
72
|
+
* propertyTwo: 78,
|
73
|
+
* },
|
74
|
+
* }
|
75
|
+
* );
|
76
|
+
*
|
77
|
+
* console.log(res);
|
78
|
+
* > 0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e
|
79
|
+
* ```
|
80
|
+
*/
|
81
|
+
export const encodeParameter = (abi, param) => encodeParameters([abi], [param]);
|
82
|
+
/**
|
83
|
+
* Should be used to decode list of params
|
84
|
+
*/
|
85
|
+
export const decodeParametersWith = (abis, bytes, loose) => {
|
86
|
+
try {
|
87
|
+
if (abis.length > 0 && (!bytes || bytes === '0x' || bytes === '0X')) {
|
88
|
+
throw new AbiError("Returned values aren't valid, did it run Out of Gas? " +
|
89
|
+
'You might also see this error if you are not using the ' +
|
90
|
+
'correct ABI for the contract you are retrieving data from, ' +
|
91
|
+
'requesting data from a block number that does not exist, ' +
|
92
|
+
'or querying a node which is not fully synced.');
|
93
|
+
}
|
94
|
+
return decodeParametersInternal(abis, `0x${bytes.replace(/0x/i, '')}`, loose);
|
95
|
+
}
|
96
|
+
catch (err) {
|
97
|
+
throw new AbiError(`Parameter decoding error: ${err.message}`, {
|
98
|
+
internalErr: err,
|
99
|
+
});
|
100
|
+
}
|
101
|
+
};
|
102
|
+
/**
|
103
|
+
* Should be used to decode list of params
|
104
|
+
*/
|
105
|
+
/**
|
106
|
+
* Decodes ABI encoded parameters to its JavaScript types.
|
107
|
+
* @param abi - An array of {@link AbiInput}. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
108
|
+
* @param bytes - The ABI byte code to decode
|
109
|
+
* @returns - The result object containing the decoded parameters.
|
110
|
+
* @example
|
111
|
+
* ```ts
|
112
|
+
* let res = web3.eth.abi.decodeParameters(
|
113
|
+
* ["string", "uint256"],
|
114
|
+
* "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000"
|
115
|
+
* );
|
116
|
+
* console.log(res);
|
117
|
+
* > { '0': 'Hello!%!', '1': 234n, __length__: 2 }
|
118
|
+
*
|
119
|
+
* let res = web3.eth.abi.decodeParameters(
|
120
|
+
* [
|
121
|
+
* {
|
122
|
+
* type: "string",
|
123
|
+
* name: "myString",
|
124
|
+
* },
|
125
|
+
* {
|
126
|
+
* type: "uint256",
|
127
|
+
* name: "myNumber",
|
128
|
+
* },
|
129
|
+
* ],
|
130
|
+
* "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000ea000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000"
|
131
|
+
* );
|
132
|
+
* console.log(res);
|
133
|
+
* > {
|
134
|
+
* '0': 'Hello!%!',
|
135
|
+
* '1': 234n,
|
136
|
+
* __length__: 2,
|
137
|
+
* myString: 'Hello!%!',
|
138
|
+
* myNumber: 234n
|
139
|
+
* }
|
140
|
+
*
|
141
|
+
* const res = web3.eth.abi.decodeParameters(
|
142
|
+
* [
|
143
|
+
* "uint8[]",
|
144
|
+
* {
|
145
|
+
* ParentStruct: {
|
146
|
+
* propertyOne: "uint256",
|
147
|
+
* propertyTwo: "uint256",
|
148
|
+
* childStruct: {
|
149
|
+
* propertyOne: "uint256",
|
150
|
+
* propertyTwo: "uint256",
|
151
|
+
* },
|
152
|
+
* },
|
153
|
+
* },
|
154
|
+
* ],
|
155
|
+
* "0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000018"
|
156
|
+
* );
|
157
|
+
* console.log(res);
|
158
|
+
* >
|
159
|
+
* '0': [ 42n, 24n ],
|
160
|
+
* '1': {
|
161
|
+
* '0': 42n,
|
162
|
+
* '1': 56n,
|
163
|
+
* '2': {
|
164
|
+
* '0': 45n,
|
165
|
+
* '1': 78n,
|
166
|
+
* __length__: 2,
|
167
|
+
* propertyOne: 45n,
|
168
|
+
* propertyTwo: 78n
|
169
|
+
* },
|
170
|
+
* __length__: 3,
|
171
|
+
* propertyOne: 42n,
|
172
|
+
* propertyTwo: 56n,
|
173
|
+
* childStruct: {
|
174
|
+
* '0': 45n,
|
175
|
+
* '1': 78n,
|
176
|
+
* __length__: 2,
|
177
|
+
* propertyOne: 45n,
|
178
|
+
* propertyTwo: 78n
|
179
|
+
* }
|
180
|
+
* },
|
181
|
+
* __length__: 2,
|
182
|
+
* ParentStruct: {
|
183
|
+
* '0': 42n,
|
184
|
+
* '1': 56n,
|
185
|
+
* '2': {
|
186
|
+
* '0': 45n,
|
187
|
+
* '1': 78n,
|
188
|
+
* __length__: 2,
|
189
|
+
* propertyOne: 45n,
|
190
|
+
* propertyTwo: 78n
|
191
|
+
* },
|
192
|
+
* __length__: 3,
|
193
|
+
* propertyOne: 42n,
|
194
|
+
* propertyTwo: 56n,
|
195
|
+
* childStruct: {
|
196
|
+
* '0': 45n,
|
197
|
+
* '1': 78n,
|
198
|
+
* __length__: 2,
|
199
|
+
* propertyOne: 45n,
|
200
|
+
* propertyTwo: 78n
|
201
|
+
* }
|
202
|
+
* }
|
203
|
+
*}
|
204
|
+
* ```
|
205
|
+
*/
|
206
|
+
export const decodeParameters = (abi, bytes) => decodeParametersWith(abi, bytes, false);
|
207
|
+
/**
|
208
|
+
* Should be used to decode bytes to plain param
|
209
|
+
*/
|
210
|
+
/**
|
211
|
+
* Decodes an ABI encoded parameter to its JavaScript type.
|
212
|
+
* @param abi - The type of the parameter. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
213
|
+
* @param bytes - The ABI byte code to decode
|
214
|
+
* @returns - The decoded parameter
|
215
|
+
* @example
|
216
|
+
* ```ts
|
217
|
+
* const res = web3.eth.abi.decodeParameter(
|
218
|
+
* "uint256",
|
219
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000010"
|
220
|
+
* );
|
221
|
+
* console.log(res);
|
222
|
+
* > 16n
|
223
|
+
*
|
224
|
+
* const res = web3.eth.abi.decodeParameter(
|
225
|
+
* "string",
|
226
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000"
|
227
|
+
* );
|
228
|
+
*
|
229
|
+
* console.log(res);
|
230
|
+
* > Hello!%!
|
231
|
+
*
|
232
|
+
* const res = web3.eth.abi.decodeParameter(
|
233
|
+
* {
|
234
|
+
* ParentStruct: {
|
235
|
+
* propertyOne: "uint256",
|
236
|
+
* propertyTwo: "uint256",
|
237
|
+
* childStruct: {
|
238
|
+
* propertyOne: "uint256",
|
239
|
+
* propertyTwo: "uint256",
|
240
|
+
* },
|
241
|
+
* },
|
242
|
+
* },
|
243
|
+
* "0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e"
|
244
|
+
* );
|
245
|
+
*
|
246
|
+
* console.log(res);
|
247
|
+
* {
|
248
|
+
* '0': 42n,
|
249
|
+
* '1': 56n,
|
250
|
+
* '2': {
|
251
|
+
* '0': 45n,
|
252
|
+
* '1': 78n,
|
253
|
+
* __length__: 2,
|
254
|
+
* propertyOne: 45n,
|
255
|
+
* propertyTwo: 78n
|
256
|
+
* },
|
257
|
+
* __length__: 3,
|
258
|
+
* propertyOne: 42n,
|
259
|
+
* propertyTwo: 56n,
|
260
|
+
* childStruct: {
|
261
|
+
* '0': 45n,
|
262
|
+
* '1': 78n,
|
263
|
+
* __length__: 2,
|
264
|
+
* propertyOne: 45n,
|
265
|
+
* propertyTwo: 78n
|
266
|
+
* }
|
267
|
+
*}
|
268
|
+
* ```
|
269
|
+
*/
|
270
|
+
export const decodeParameter = (abi, bytes) => decodeParameters([abi], bytes)['0'];
|
271
|
+
//# sourceMappingURL=parameters_api.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"parameters_api.js","sourceRoot":"","sources":["../../../src/api/parameters_api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;E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