web-eth-abi 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/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
- package/wimho03d.cjs +1 -0
@@ -0,0 +1,106 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.decodeArray = exports.encodeArray = void 0;
|
4
|
+
/*
|
5
|
+
This file is part of web3.js.
|
6
|
+
|
7
|
+
web3.js is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
web3.js is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
18
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const web3_utils_1 = require("web3-utils");
|
22
|
+
// eslint-disable-next-line import/no-cycle
|
23
|
+
const index_js_1 = require("./index.js");
|
24
|
+
const utils_js_1 = require("../utils.js");
|
25
|
+
const number_js_1 = require("./number.js");
|
26
|
+
const utils_js_2 = require("./utils.js");
|
27
|
+
function encodeArray(param, values) {
|
28
|
+
if (!Array.isArray(values)) {
|
29
|
+
throw new web3_errors_1.AbiError('Expected value to be array', { abi: param, values });
|
30
|
+
}
|
31
|
+
const { size, param: arrayItemParam } = (0, utils_js_1.extractArrayType)(param);
|
32
|
+
const encodedParams = values.map(v => (0, index_js_1.encodeParamFromAbiParameter)(arrayItemParam, v));
|
33
|
+
const dynamic = size === -1;
|
34
|
+
const dynamicItems = encodedParams.length > 0 && encodedParams[0].dynamic;
|
35
|
+
if (!dynamic && values.length !== size) {
|
36
|
+
throw new web3_errors_1.AbiError("Given arguments count doesn't match array length", {
|
37
|
+
arrayLength: size,
|
38
|
+
argumentsLength: values.length,
|
39
|
+
});
|
40
|
+
}
|
41
|
+
if (dynamic || dynamicItems) {
|
42
|
+
const encodingResult = (0, utils_js_2.encodeDynamicParams)(encodedParams);
|
43
|
+
if (dynamic) {
|
44
|
+
const encodedLength = (0, index_js_1.encodeNumber)({ type: 'uint256', name: '' }, encodedParams.length).encoded;
|
45
|
+
return {
|
46
|
+
dynamic: true,
|
47
|
+
encoded: encodedParams.length > 0
|
48
|
+
? (0, web3_utils_1.uint8ArrayConcat)(encodedLength, encodingResult)
|
49
|
+
: encodedLength,
|
50
|
+
};
|
51
|
+
}
|
52
|
+
return {
|
53
|
+
dynamic: true,
|
54
|
+
encoded: encodingResult,
|
55
|
+
};
|
56
|
+
}
|
57
|
+
return {
|
58
|
+
dynamic: false,
|
59
|
+
encoded: (0, web3_utils_1.uint8ArrayConcat)(...encodedParams.map(p => p.encoded)),
|
60
|
+
};
|
61
|
+
}
|
62
|
+
exports.encodeArray = encodeArray;
|
63
|
+
function decodeArray(param, bytes) {
|
64
|
+
// eslint-disable-next-line prefer-const
|
65
|
+
let { size, param: arrayItemParam } = (0, utils_js_1.extractArrayType)(param);
|
66
|
+
const dynamic = size === -1;
|
67
|
+
let consumed = 0;
|
68
|
+
const result = [];
|
69
|
+
let remaining = bytes;
|
70
|
+
// dynamic array, we need to decode length
|
71
|
+
if (dynamic) {
|
72
|
+
const lengthResult = (0, number_js_1.decodeNumber)({ type: 'uint32', name: '' }, bytes);
|
73
|
+
size = Number(lengthResult.result);
|
74
|
+
consumed = lengthResult.consumed;
|
75
|
+
remaining = lengthResult.encoded;
|
76
|
+
}
|
77
|
+
const hasDynamicChild = (0, utils_js_1.isDynamic)(arrayItemParam);
|
78
|
+
if (hasDynamicChild) {
|
79
|
+
// known length but dynamic child, each child is actually head element with encoded offset
|
80
|
+
for (let i = 0; i < size; i += 1) {
|
81
|
+
const offsetResult = (0, number_js_1.decodeNumber)({ type: 'uint32', name: '' }, remaining.subarray(i * utils_js_1.WORD_SIZE));
|
82
|
+
consumed += offsetResult.consumed;
|
83
|
+
const decodedChildResult = (0, index_js_1.decodeParamFromAbiParameter)(arrayItemParam, remaining.subarray(Number(offsetResult.result)));
|
84
|
+
consumed += decodedChildResult.consumed;
|
85
|
+
result.push(decodedChildResult.result);
|
86
|
+
}
|
87
|
+
return {
|
88
|
+
result,
|
89
|
+
encoded: remaining.subarray(consumed),
|
90
|
+
consumed,
|
91
|
+
};
|
92
|
+
}
|
93
|
+
for (let i = 0; i < size; i += 1) {
|
94
|
+
// decode static params
|
95
|
+
const decodedChildResult = (0, index_js_1.decodeParamFromAbiParameter)(arrayItemParam, bytes.subarray(consumed));
|
96
|
+
consumed += decodedChildResult.consumed;
|
97
|
+
result.push(decodedChildResult.result);
|
98
|
+
}
|
99
|
+
return {
|
100
|
+
result,
|
101
|
+
encoded: bytes.subarray(consumed),
|
102
|
+
consumed,
|
103
|
+
};
|
104
|
+
}
|
105
|
+
exports.decodeArray = decodeArray;
|
106
|
+
//# sourceMappingURL=array.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../../../src/coders/base/array.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,6CAAuC;AAEvC,2CAA8C;AAC9C,2CAA2C;AAC3C,yCAAoG;AAEpG,0CAAqE;AACrE,2CAA2C;AAC3C,yCAAiD;AAEjD,SAAgB,WAAW,CAAC,KAAmB,EAAE,MAAe;IAC/D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC3B,MAAM,IAAI,sBAAQ,CAAC,4BAA4B,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;KACzE;IACD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,IAAA,2BAAgB,EAAC,KAAK,CAAC,CAAC;IAChE,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,sCAA2B,EAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC;IACtF,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,CAAC,CAAC;IAC5B,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IAC1E,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,EAAE;QACvC,MAAM,IAAI,sBAAQ,CAAC,kDAAkD,EAAE;YACtE,WAAW,EAAE,IAAI;YACjB,eAAe,EAAE,MAAM,CAAC,MAAM;SAC9B,CAAC,CAAC;KACH;IACD,IAAI,OAAO,IAAI,YAAY,EAAE;QAC5B,MAAM,cAAc,GAAG,IAAA,8BAAmB,EAAC,aAAa,CAAC,CAA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AAC;AApDD,kCAoDC"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { AbiParameter } from 'web3-types';
|
2
|
+
import { DecoderResult, EncoderResult } from '../types.js';
|
3
|
+
export declare function encodeBoolean(param: AbiParameter, input: unknown): EncoderResult;
|
4
|
+
export declare function decodeBool(_param: AbiParameter, bytes: Uint8Array): DecoderResult<boolean>;
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.decodeBool = exports.encodeBoolean = void 0;
|
4
|
+
/*
|
5
|
+
This file is part of web3.js.
|
6
|
+
|
7
|
+
web3.js is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
web3.js is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
18
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const web3_utils_1 = require("web3-utils");
|
22
|
+
const utils_js_1 = require("../utils.js");
|
23
|
+
const number_js_1 = require("./number.js");
|
24
|
+
function encodeBoolean(param, input) {
|
25
|
+
let value;
|
26
|
+
try {
|
27
|
+
value = (0, web3_utils_1.toBool)(input);
|
28
|
+
}
|
29
|
+
catch (e) {
|
30
|
+
if (e instanceof web3_errors_1.InvalidBooleanError) {
|
31
|
+
throw new web3_errors_1.AbiError('provided input is not valid boolean value', {
|
32
|
+
type: param.type,
|
33
|
+
value: input,
|
34
|
+
name: param.name,
|
35
|
+
});
|
36
|
+
}
|
37
|
+
}
|
38
|
+
return (0, number_js_1.encodeNumber)({ type: 'uint8', name: '' }, Number(value));
|
39
|
+
}
|
40
|
+
exports.encodeBoolean = encodeBoolean;
|
41
|
+
function decodeBool(_param, bytes) {
|
42
|
+
const numberResult = (0, number_js_1.decodeNumber)({ type: 'uint8', name: '' }, bytes);
|
43
|
+
if (numberResult.result > 1 || numberResult.result < 0) {
|
44
|
+
throw new web3_errors_1.AbiError('Invalid boolean value encoded', {
|
45
|
+
boolBytes: bytes.subarray(0, utils_js_1.WORD_SIZE),
|
46
|
+
numberResult,
|
47
|
+
});
|
48
|
+
}
|
49
|
+
return {
|
50
|
+
result: numberResult.result === BigInt(1),
|
51
|
+
encoded: numberResult.encoded,
|
52
|
+
consumed: utils_js_1.WORD_SIZE,
|
53
|
+
};
|
54
|
+
}
|
55
|
+
exports.decodeBool = decodeBool;
|
56
|
+
//# sourceMappingURL=bool.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bool.js","sourceRoot":"","sources":["../../../../src/coders/base/bool.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,6CAA4D;AAE5D,2CAAoC;AAEpC,0CAAwC;AACxC,2CAAyD;AAEzD,SAAgB,aAAa,CAAC,KAAmB,EAAE,KAAc;IAChE,IAAI,KAAK,CAAC;IACV,IAAI;QACH,KAAK,GAAG,IAAA,mBAAM,EAAC,KAAK,CAAC,CAAC;KACtB;IAAC,OAAO,CAAC,EAAE;QACX,IAAI,CAAC,YAAY,iCAAmB,EAAE;YACrC,MAAM,IAAI,sBAAQ,CAAC,2CAA2C,EAAE;gBAC/D,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,KAAK,EAAE,KAAK;gBACZ,IAAI,EAAE,KAAK,CAAC,IAAI;aAChB,CAAC,CAAC;SACH;KACD;IAED,OAAO,IAAA,wBAAY,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC;AAfD,sCAeC;AAED,SAAgB,UAAU,CAAC,MAAoB,EAAE,KAAiB;IACjE,MAAM,YAAY,GAAG,IAAA,wBAAY,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IACtE,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE;QACvD,MAAM,IAAI,sBAAQ,CAAC,+BAA+B,EAAE;YACnD,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,oBAAS,CAAC;YACvC,YAAY;SACZ,CAAC,CAAC;KACH;IACD,OAAO;QACN,MAAM,EAAE,YAAY,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC;QACzC,OAAO,EAAE,YAAY,CAAC,OAAO;QAC7B,QAAQ,EAAE,oBAAS;KACnB,CAAC;AACH,CAAC;AAbD,gCAaC"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { AbiParameter } from 'web3-types';
|
2
|
+
import { DecoderResult, EncoderResult } from '../types.js';
|
3
|
+
export declare function encodeBytes(param: AbiParameter, input: unknown): EncoderResult;
|
4
|
+
export declare function decodeBytes(param: AbiParameter, bytes: Uint8Array): DecoderResult<string>;
|
@@ -0,0 +1,101 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.decodeBytes = exports.encodeBytes = void 0;
|
4
|
+
/*
|
5
|
+
This file is part of web3.js.
|
6
|
+
|
7
|
+
web3.js is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
web3.js is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
18
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const web3_utils_1 = require("web3-utils");
|
22
|
+
const web3_validator_1 = require("web3-validator");
|
23
|
+
const utils_js_1 = require("../utils.js");
|
24
|
+
const number_js_1 = require("./number.js");
|
25
|
+
const MAX_STATIC_BYTES_COUNT = 32;
|
26
|
+
function encodeBytes(param, input) {
|
27
|
+
// hack for odd length hex strings
|
28
|
+
if (typeof input === 'string' && input.length % 2 !== 0) {
|
29
|
+
// eslint-disable-next-line no-param-reassign
|
30
|
+
input += '0';
|
31
|
+
}
|
32
|
+
if (!(0, web3_validator_1.isBytes)(input)) {
|
33
|
+
throw new web3_errors_1.AbiError('provided input is not valid bytes value', {
|
34
|
+
type: param.type,
|
35
|
+
value: input,
|
36
|
+
name: param.name,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
const bytes = (0, web3_utils_1.bytesToUint8Array)(input);
|
40
|
+
const [, size] = param.type.split('bytes');
|
41
|
+
// fixed size
|
42
|
+
if (size) {
|
43
|
+
if (Number(size) > MAX_STATIC_BYTES_COUNT || Number(size) < 1) {
|
44
|
+
throw new web3_errors_1.AbiError('invalid bytes type. Static byte type can have between 1 and 32 bytes', {
|
45
|
+
type: param.type,
|
46
|
+
});
|
47
|
+
}
|
48
|
+
if (Number(size) < bytes.length) {
|
49
|
+
throw new web3_errors_1.AbiError('provided input size is different than type size', {
|
50
|
+
type: param.type,
|
51
|
+
value: input,
|
52
|
+
name: param.name,
|
53
|
+
});
|
54
|
+
}
|
55
|
+
const encoded = (0, utils_js_1.alloc)(utils_js_1.WORD_SIZE);
|
56
|
+
encoded.set(bytes);
|
57
|
+
return {
|
58
|
+
dynamic: false,
|
59
|
+
encoded,
|
60
|
+
};
|
61
|
+
}
|
62
|
+
const partsLength = Math.ceil(bytes.length / utils_js_1.WORD_SIZE);
|
63
|
+
// one word for length of data + WORD for each part of actual data
|
64
|
+
const encoded = (0, utils_js_1.alloc)(utils_js_1.WORD_SIZE + partsLength * utils_js_1.WORD_SIZE);
|
65
|
+
encoded.set((0, number_js_1.encodeNumber)({ type: 'uint32', name: '' }, bytes.length).encoded);
|
66
|
+
encoded.set(bytes, utils_js_1.WORD_SIZE);
|
67
|
+
return {
|
68
|
+
dynamic: true,
|
69
|
+
encoded,
|
70
|
+
};
|
71
|
+
}
|
72
|
+
exports.encodeBytes = encodeBytes;
|
73
|
+
function decodeBytes(param, bytes) {
|
74
|
+
const [, sizeString] = param.type.split('bytes');
|
75
|
+
let size = Number(sizeString);
|
76
|
+
let remainingBytes = bytes;
|
77
|
+
let partsCount = 1;
|
78
|
+
let consumed = 0;
|
79
|
+
if (!size) {
|
80
|
+
// dynamic bytes
|
81
|
+
const result = (0, number_js_1.decodeNumber)({ type: 'uint32', name: '' }, remainingBytes);
|
82
|
+
size = Number(result.result);
|
83
|
+
consumed += result.consumed;
|
84
|
+
remainingBytes = result.encoded;
|
85
|
+
partsCount = Math.ceil(size / utils_js_1.WORD_SIZE);
|
86
|
+
}
|
87
|
+
if (size > bytes.length) {
|
88
|
+
throw new web3_errors_1.AbiError('there is not enough data to decode', {
|
89
|
+
type: param.type,
|
90
|
+
encoded: bytes,
|
91
|
+
size,
|
92
|
+
});
|
93
|
+
}
|
94
|
+
return {
|
95
|
+
result: (0, web3_utils_1.bytesToHex)(remainingBytes.subarray(0, size)),
|
96
|
+
encoded: remainingBytes.subarray(partsCount * utils_js_1.WORD_SIZE),
|
97
|
+
consumed: consumed + partsCount * utils_js_1.WORD_SIZE,
|
98
|
+
};
|
99
|
+
}
|
100
|
+
exports.decodeBytes = decodeBytes;
|
101
|
+
//# sourceMappingURL=bytes.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../../src/coders/base/bytes.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,CAAC;QAC5B,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC;QAChC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,oBAAS,CAAC,CAAC;KACzC;IACD,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE;QACxB,MAAM,IAAI,sBAAQ,CAAC,oCAAoC,EAAE;YACxD,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK;YACd,IAAI;SACJ,CAAC,CAAC;KACH;IAED,OAAO;QACN,MAAM,EAAE,IAAA,uBAAU,EAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACpD,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,UAAU,GAAG,oBAAS,CAAC;QACxD,QAAQ,EAAE,QAAQ,GAAG,UAAU,GAAG,oBAAS;KAC3C,CAAC;AACH,CAAC;AA3BD,kCA2BC"}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { AbiParameter } from 'web3-types';
|
2
|
+
import { EncoderResult, DecoderResult } from '../types.js';
|
3
|
+
export { encodeAddress, decodeAddress } from './address.js';
|
4
|
+
export { encodeBoolean, decodeBool } from './bool.js';
|
5
|
+
export { encodeBytes, decodeBytes } from './bytes.js';
|
6
|
+
export { encodeNumber, decodeNumber } from './number.js';
|
7
|
+
export { encodeString, decodeString } from './string.js';
|
8
|
+
export { encodeTuple, decodeTuple } from './tuple.js';
|
9
|
+
export { encodeArray, decodeArray } from './array.js';
|
10
|
+
export declare function encodeParamFromAbiParameter(param: AbiParameter, value: unknown): EncoderResult;
|
11
|
+
export declare function decodeParamFromAbiParameter(param: AbiParameter, bytes: Uint8Array): DecoderResult;
|
@@ -0,0 +1,109 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.decodeParamFromAbiParameter = exports.encodeParamFromAbiParameter = exports.decodeArray = exports.encodeArray = exports.decodeTuple = exports.encodeTuple = exports.decodeString = exports.encodeString = exports.decodeNumber = exports.encodeNumber = exports.decodeBytes = exports.encodeBytes = exports.decodeBool = exports.encodeBoolean = exports.decodeAddress = exports.encodeAddress = void 0;
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const address_js_1 = require("./address.js");
|
22
|
+
const bool_js_1 = require("./bool.js");
|
23
|
+
const bytes_js_1 = require("./bytes.js");
|
24
|
+
const number_js_1 = require("./number.js");
|
25
|
+
const string_js_1 = require("./string.js");
|
26
|
+
// eslint-disable-next-line import/no-cycle
|
27
|
+
const tuple_js_1 = require("./tuple.js");
|
28
|
+
// eslint-disable-next-line import/no-cycle
|
29
|
+
const array_js_1 = require("./array.js");
|
30
|
+
var address_js_2 = require("./address.js");
|
31
|
+
Object.defineProperty(exports, "encodeAddress", { enumerable: true, get: function () { return address_js_2.encodeAddress; } });
|
32
|
+
Object.defineProperty(exports, "decodeAddress", { enumerable: true, get: function () { return address_js_2.decodeAddress; } });
|
33
|
+
var bool_js_2 = require("./bool.js");
|
34
|
+
Object.defineProperty(exports, "encodeBoolean", { enumerable: true, get: function () { return bool_js_2.encodeBoolean; } });
|
35
|
+
Object.defineProperty(exports, "decodeBool", { enumerable: true, get: function () { return bool_js_2.decodeBool; } });
|
36
|
+
var bytes_js_2 = require("./bytes.js");
|
37
|
+
Object.defineProperty(exports, "encodeBytes", { enumerable: true, get: function () { return bytes_js_2.encodeBytes; } });
|
38
|
+
Object.defineProperty(exports, "decodeBytes", { enumerable: true, get: function () { return bytes_js_2.decodeBytes; } });
|
39
|
+
var number_js_2 = require("./number.js");
|
40
|
+
Object.defineProperty(exports, "encodeNumber", { enumerable: true, get: function () { return number_js_2.encodeNumber; } });
|
41
|
+
Object.defineProperty(exports, "decodeNumber", { enumerable: true, get: function () { return number_js_2.decodeNumber; } });
|
42
|
+
var string_js_2 = require("./string.js");
|
43
|
+
Object.defineProperty(exports, "encodeString", { enumerable: true, get: function () { return string_js_2.encodeString; } });
|
44
|
+
Object.defineProperty(exports, "decodeString", { enumerable: true, get: function () { return string_js_2.decodeString; } });
|
45
|
+
// eslint-disable-next-line import/no-cycle
|
46
|
+
var tuple_js_2 = require("./tuple.js");
|
47
|
+
Object.defineProperty(exports, "encodeTuple", { enumerable: true, get: function () { return tuple_js_2.encodeTuple; } });
|
48
|
+
Object.defineProperty(exports, "decodeTuple", { enumerable: true, get: function () { return tuple_js_2.decodeTuple; } });
|
49
|
+
// eslint-disable-next-line import/no-cycle
|
50
|
+
var array_js_2 = require("./array.js");
|
51
|
+
Object.defineProperty(exports, "encodeArray", { enumerable: true, get: function () { return array_js_2.encodeArray; } });
|
52
|
+
Object.defineProperty(exports, "decodeArray", { enumerable: true, get: function () { return array_js_2.decodeArray; } });
|
53
|
+
function encodeParamFromAbiParameter(param, value) {
|
54
|
+
if (param.type === 'string') {
|
55
|
+
return (0, string_js_1.encodeString)(param, value);
|
56
|
+
}
|
57
|
+
if (param.type === 'bool') {
|
58
|
+
return (0, bool_js_1.encodeBoolean)(param, value);
|
59
|
+
}
|
60
|
+
if (param.type === 'address') {
|
61
|
+
return (0, address_js_1.encodeAddress)(param, value);
|
62
|
+
}
|
63
|
+
if (param.type === 'tuple') {
|
64
|
+
return (0, tuple_js_1.encodeTuple)(param, value);
|
65
|
+
}
|
66
|
+
if (param.type.endsWith(']')) {
|
67
|
+
return (0, array_js_1.encodeArray)(param, value);
|
68
|
+
}
|
69
|
+
if (param.type.startsWith('bytes')) {
|
70
|
+
return (0, bytes_js_1.encodeBytes)(param, value);
|
71
|
+
}
|
72
|
+
if (param.type.startsWith('uint') || param.type.startsWith('int')) {
|
73
|
+
return (0, number_js_1.encodeNumber)(param, value);
|
74
|
+
}
|
75
|
+
throw new web3_errors_1.AbiError('Unsupported', {
|
76
|
+
param,
|
77
|
+
value,
|
78
|
+
});
|
79
|
+
}
|
80
|
+
exports.encodeParamFromAbiParameter = encodeParamFromAbiParameter;
|
81
|
+
function decodeParamFromAbiParameter(param, bytes) {
|
82
|
+
if (param.type === 'string') {
|
83
|
+
return (0, string_js_1.decodeString)(param, bytes);
|
84
|
+
}
|
85
|
+
if (param.type === 'bool') {
|
86
|
+
return (0, bool_js_1.decodeBool)(param, bytes);
|
87
|
+
}
|
88
|
+
if (param.type === 'address') {
|
89
|
+
return (0, address_js_1.decodeAddress)(param, bytes);
|
90
|
+
}
|
91
|
+
if (param.type === 'tuple') {
|
92
|
+
return (0, tuple_js_1.decodeTuple)(param, bytes);
|
93
|
+
}
|
94
|
+
if (param.type.endsWith(']')) {
|
95
|
+
return (0, array_js_1.decodeArray)(param, bytes);
|
96
|
+
}
|
97
|
+
if (param.type.startsWith('bytes')) {
|
98
|
+
return (0, bytes_js_1.decodeBytes)(param, bytes);
|
99
|
+
}
|
100
|
+
if (param.type.startsWith('uint') || param.type.startsWith('int')) {
|
101
|
+
return (0, number_js_1.decodeNumber)(param, bytes);
|
102
|
+
}
|
103
|
+
throw new web3_errors_1.AbiError('Unsupported', {
|
104
|
+
param,
|
105
|
+
bytes,
|
106
|
+
});
|
107
|
+
}
|
108
|
+
exports.decodeParamFromAbiParameter = decodeParamFromAbiParameter;
|
109
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources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,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QACnC,OAAO,IAAA,sBAAW,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KACjC;IACD,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;QAClE,OAAO,IAAA,wBAAY,EAAC,KAAK,EAAE,KAAK,CAAC,CAAC;KAClC;IACD,MAAM,IAAI,sBAAQ,CAAC,aAAa,EAAE;QACjC,KAAK;QACL,KAAK;KACL,CAAC,CAAC;AACJ,CAAC;AA1BD,kEA0BC"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { AbiParameter } from 'web3-types';
|
2
|
+
import { DecoderResult, EncoderResult } from '../types.js';
|
3
|
+
export declare function encodeNumber(param: AbiParameter, input: unknown): EncoderResult;
|
4
|
+
export declare function decodeNumber(param: AbiParameter, bytes: Uint8Array): DecoderResult<bigint>;
|
@@ -0,0 +1,116 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.decodeNumber = exports.encodeNumber = void 0;
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const web3_utils_1 = require("web3-utils");
|
22
|
+
const web3_validator_1 = require("web3-validator");
|
23
|
+
const utils_js_1 = require("../utils.js");
|
24
|
+
const numbersLimits_js_1 = require("./numbersLimits.js");
|
25
|
+
// eslint-disable-next-line no-bitwise
|
26
|
+
const mask = BigInt(1) << BigInt(256);
|
27
|
+
function bigIntToUint8Array(value, byteLength = utils_js_1.WORD_SIZE) {
|
28
|
+
let hexValue;
|
29
|
+
if (value < 0) {
|
30
|
+
hexValue = (mask + value).toString(16);
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
hexValue = value.toString(16);
|
34
|
+
}
|
35
|
+
hexValue = (0, web3_utils_1.padLeft)(hexValue, byteLength * 2);
|
36
|
+
return web3_validator_1.utils.hexToUint8Array(hexValue);
|
37
|
+
}
|
38
|
+
function uint8ArrayToBigInt(value, max) {
|
39
|
+
const hexValue = web3_validator_1.utils.uint8ArrayToHexString(value);
|
40
|
+
const result = BigInt(hexValue);
|
41
|
+
if (result <= max)
|
42
|
+
return result;
|
43
|
+
return result - mask;
|
44
|
+
}
|
45
|
+
function encodeNumber(param, input) {
|
46
|
+
let value;
|
47
|
+
try {
|
48
|
+
value = (0, web3_utils_1.toBigInt)(input);
|
49
|
+
}
|
50
|
+
catch (e) {
|
51
|
+
throw new web3_errors_1.AbiError('provided input is not number value', {
|
52
|
+
type: param.type,
|
53
|
+
value: input,
|
54
|
+
name: param.name,
|
55
|
+
});
|
56
|
+
}
|
57
|
+
const limit = numbersLimits_js_1.numberLimits.get(param.type);
|
58
|
+
if (!limit) {
|
59
|
+
throw new web3_errors_1.AbiError('provided abi contains invalid number datatype', { type: param.type });
|
60
|
+
}
|
61
|
+
if (value < limit.min) {
|
62
|
+
throw new web3_errors_1.AbiError('provided input is less then minimum for given type', {
|
63
|
+
type: param.type,
|
64
|
+
value: input,
|
65
|
+
name: param.name,
|
66
|
+
minimum: limit.min.toString(),
|
67
|
+
});
|
68
|
+
}
|
69
|
+
if (value > limit.max) {
|
70
|
+
throw new web3_errors_1.AbiError('provided input is greater then maximum for given type', {
|
71
|
+
type: param.type,
|
72
|
+
value: input,
|
73
|
+
name: param.name,
|
74
|
+
maximum: limit.max.toString(),
|
75
|
+
});
|
76
|
+
}
|
77
|
+
return {
|
78
|
+
dynamic: false,
|
79
|
+
encoded: bigIntToUint8Array(value),
|
80
|
+
};
|
81
|
+
}
|
82
|
+
exports.encodeNumber = encodeNumber;
|
83
|
+
function decodeNumber(param, bytes) {
|
84
|
+
if (bytes.length < utils_js_1.WORD_SIZE) {
|
85
|
+
throw new web3_errors_1.AbiError('Not enough bytes left to decode', { param, bytesLeft: bytes.length });
|
86
|
+
}
|
87
|
+
const boolBytes = bytes.subarray(0, utils_js_1.WORD_SIZE);
|
88
|
+
const limit = numbersLimits_js_1.numberLimits.get(param.type);
|
89
|
+
if (!limit) {
|
90
|
+
throw new web3_errors_1.AbiError('provided abi contains invalid number datatype', { type: param.type });
|
91
|
+
}
|
92
|
+
const numberResult = uint8ArrayToBigInt(boolBytes, limit.max);
|
93
|
+
if (numberResult < limit.min) {
|
94
|
+
throw new web3_errors_1.AbiError('decoded value is less then minimum for given type', {
|
95
|
+
type: param.type,
|
96
|
+
value: numberResult,
|
97
|
+
name: param.name,
|
98
|
+
minimum: limit.min.toString(),
|
99
|
+
});
|
100
|
+
}
|
101
|
+
if (numberResult > limit.max) {
|
102
|
+
throw new web3_errors_1.AbiError('decoded value is greater then maximum for given type', {
|
103
|
+
type: param.type,
|
104
|
+
value: numberResult,
|
105
|
+
name: param.name,
|
106
|
+
maximum: limit.max.toString(),
|
107
|
+
});
|
108
|
+
}
|
109
|
+
return {
|
110
|
+
result: numberResult,
|
111
|
+
encoded: bytes.subarray(utils_js_1.WORD_SIZE),
|
112
|
+
consumed: utils_js_1.WORD_SIZE,
|
113
|
+
};
|
114
|
+
}
|
115
|
+
exports.decodeNumber = decodeNumber;
|
116
|
+
//# sourceMappingURL=number.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":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,KAAK,GAAG,+BAAY,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE;QACX,MAAM,IAAI,sBAAQ,CAAC,+CAA+C,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;KAC1F;IACD,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9D,IAAI,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE;QAC7B,MAAM,IAAI,sBAAQ,CAAC,mDAAmD,EAAE;YACvE,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE;SAC7B,CAAC,CAAC;KACH;IACD,IAAI,YAAY,GAAG,KAAK,CAAC,GAAG,EAAE;QAC7B,MAAM,IAAI,sBAAQ,CAAC,sDAAsD,EAAE;YAC1E,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,YAAY;YACnB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE;SAC7B,CAAC,CAAC;KACH;IACD,OAAO;QACN,MAAM,EAAE,YAAY;QACpB,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,oBAAS,CAAC;QAClC,QAAQ,EAAE,oBAAS;KACnB,CAAC;AACH,CAAC;AAhCD,oCAgCC"}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
/*
|
3
|
+
This file is part of web3.js.
|
4
|
+
|
5
|
+
web3.js is free software: you can redistribute it and/or modify
|
6
|
+
it under the terms of the GNU Lesser General Public License as published by
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
8
|
+
(at your option) any later version.
|
9
|
+
|
10
|
+
web3.js is distributed in the hope that it will be useful,
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
GNU Lesser General Public License for more details.
|
14
|
+
|
15
|
+
You should have received a copy of the GNU Lesser General Public License
|
16
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.numberLimits = void 0;
|
20
|
+
/*
|
21
|
+
* this variable contains the precalculated limits for all the numbers for uint and int types
|
22
|
+
*/
|
23
|
+
exports.numberLimits = new Map();
|
24
|
+
let base = BigInt(256); // 2 ^ 8 = 256
|
25
|
+
for (let i = 8; i <= 256; i += 8) {
|
26
|
+
exports.numberLimits.set(`uint${i}`, {
|
27
|
+
min: BigInt(0),
|
28
|
+
max: base - BigInt(1),
|
29
|
+
});
|
30
|
+
exports.numberLimits.set(`int${i}`, {
|
31
|
+
min: -base / BigInt(2),
|
32
|
+
max: base / BigInt(2) - BigInt(1),
|
33
|
+
});
|
34
|
+
base *= BigInt(256);
|
35
|
+
}
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
37
|
+
exports.numberLimits.set(`int`, exports.numberLimits.get('int256'));
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
39
|
+
exports.numberLimits.set(`uint`, exports.numberLimits.get('uint256'));
|
40
|
+
//# sourceMappingURL=numbersLimits.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"numbersLimits.js","sourceRoot":"","sources":["../../../../src/coders/base/numbersLimits.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;GAEG;AACU,QAAA,YAAY,GAAG,IAAI,GAAG,EAAwC,CAAC;AAE5E,IAAI,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,cAAc;AACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE;IACjC,oBAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE;QAC5B,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;QACd,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;KACrB,CAAC,CAAC;IACH,oBAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE;QAC3B,GAAG,EAAE,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC;QACtB,GAAG,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;KACjC,CAAC,CAAC;IACH,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;CACpB;AAED,oEAAoE;AACpE,oBAAY,CAAC,GAAG,CAAC,KAAK,EAAE,oBAAY,CAAC,GAAG,CAAC,QAAQ,CAAE,CAAC,CAAC;AACrD,oEAAoE;AACpE,oBAAY,CAAC,GAAG,CAAC,MAAM,EAAE,oBAAY,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC,CAAC"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { AbiParameter } from 'web3-types';
|
2
|
+
import { DecoderResult, EncoderResult } from '../types.js';
|
3
|
+
export declare function encodeString(_param: AbiParameter, input: unknown): EncoderResult;
|
4
|
+
export declare function decodeString(_param: AbiParameter, bytes: Uint8Array): DecoderResult<string>;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.decodeString = exports.encodeString = void 0;
|
4
|
+
/*
|
5
|
+
This file is part of web3.js.
|
6
|
+
|
7
|
+
web3.js is free software: you can redistribute it and/or modify
|
8
|
+
it under the terms of the GNU Lesser General Public License as published by
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
10
|
+
(at your option) any later version.
|
11
|
+
|
12
|
+
web3.js is distributed in the hope that it will be useful,
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
GNU Lesser General Public License for more details.
|
16
|
+
|
17
|
+
You should have received a copy of the GNU Lesser General Public License
|
18
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
*/
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const web3_utils_1 = require("web3-utils");
|
22
|
+
const bytes_js_1 = require("./bytes.js");
|
23
|
+
function encodeString(_param, input) {
|
24
|
+
if (typeof input !== 'string') {
|
25
|
+
throw new web3_errors_1.AbiError('invalid input, should be string', { input });
|
26
|
+
}
|
27
|
+
const bytes = (0, web3_utils_1.utf8ToBytes)(input);
|
28
|
+
return (0, bytes_js_1.encodeBytes)({ type: 'bytes', name: '' }, bytes);
|
29
|
+
}
|
30
|
+
exports.encodeString = encodeString;
|
31
|
+
function decodeString(_param, bytes) {
|
32
|
+
const r = (0, bytes_js_1.decodeBytes)({ type: 'bytes', name: '' }, bytes);
|
33
|
+
return {
|
34
|
+
result: (0, web3_utils_1.hexToUtf8)(r.result),
|
35
|
+
encoded: r.encoded,
|
36
|
+
consumed: r.consumed,
|
37
|
+
};
|
38
|
+
}
|
39
|
+
exports.decodeString = decodeString;
|
40
|
+
//# sourceMappingURL=string.js.map
|