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,73 @@
|
|
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.decodeContractErrorData = void 0;
|
20
|
+
const errors_api_js_1 = require("./api/errors_api.js");
|
21
|
+
const parameters_api_js_1 = require("./api/parameters_api.js");
|
22
|
+
const utils_js_1 = require("./utils.js");
|
23
|
+
const decodeContractErrorData = (errorsAbi, error) => {
|
24
|
+
if (error === null || error === void 0 ? void 0 : error.data) {
|
25
|
+
let errorName;
|
26
|
+
let errorSignature;
|
27
|
+
let errorArgs;
|
28
|
+
try {
|
29
|
+
const errorSha = error.data.slice(0, 10);
|
30
|
+
const errorAbi = errorsAbi.find(abi => (0, errors_api_js_1.encodeErrorSignature)(abi).startsWith(errorSha));
|
31
|
+
if (errorAbi === null || errorAbi === void 0 ? void 0 : errorAbi.inputs) {
|
32
|
+
errorName = errorAbi.name;
|
33
|
+
errorSignature = (0, utils_js_1.jsonInterfaceMethodToString)(errorAbi);
|
34
|
+
// decode abi.inputs according to EIP-838
|
35
|
+
errorArgs = (0, parameters_api_js_1.decodeParameters)([...errorAbi.inputs], error.data.substring(10));
|
36
|
+
}
|
37
|
+
else if (error.data.startsWith('0x08c379a0')) {
|
38
|
+
// If ABI was not provided, check for the 2 famous errors: 'Error(string)' or 'Panic(uint256)'
|
39
|
+
errorName = 'Error';
|
40
|
+
errorSignature = 'Error(string)';
|
41
|
+
// decode abi.inputs according to EIP-838
|
42
|
+
errorArgs = (0, parameters_api_js_1.decodeParameters)([
|
43
|
+
{
|
44
|
+
name: 'message',
|
45
|
+
type: 'string',
|
46
|
+
},
|
47
|
+
], error.data.substring(10));
|
48
|
+
}
|
49
|
+
else if (error.data.startsWith('0x4e487b71')) {
|
50
|
+
errorName = 'Panic';
|
51
|
+
errorSignature = 'Panic(uint256)';
|
52
|
+
// decode abi.inputs according to EIP-838
|
53
|
+
errorArgs = (0, parameters_api_js_1.decodeParameters)([
|
54
|
+
{
|
55
|
+
name: 'code',
|
56
|
+
type: 'uint256',
|
57
|
+
},
|
58
|
+
], error.data.substring(10));
|
59
|
+
}
|
60
|
+
else {
|
61
|
+
console.error('No matching error abi found for error data', error.data);
|
62
|
+
}
|
63
|
+
}
|
64
|
+
catch (err) {
|
65
|
+
console.error(err);
|
66
|
+
}
|
67
|
+
if (errorName) {
|
68
|
+
error.setDecodedProperties(errorName, errorSignature, errorArgs);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
};
|
72
|
+
exports.decodeContractErrorData = decodeContractErrorData;
|
73
|
+
//# 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,uDAA2D;AAC3D,+DAA2D;AAC3D,yCAAyD;AAElD,MAAM,uBAAuB,GAAG,CACtC,SAA6B,EAC7B,KAA2B,EAC1B,EAAE;IACH,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,EAAE;QAChB,IAAI,SAA6B,CAAC;QAClC,IAAI,cAAkC,CAAC;QACvC,IAAI,SAAiD,CAAC;QACtD,IAAI;YACH,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACzC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAA,oCAAoB,EAAC,GAAG,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;YAEvF,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAAE;gBACrB,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC;gBAC1B,cAAc,GAAG,IAAA,sCAA2B,EAAC,QAAQ,CAAC,CAAC;gBACvD,yCAAyC;gBACzC,SAAS,GAAG,IAAA,oCAAgB,EAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;aAC7E;iBAAM,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;gBAC/C,8FAA8F;gBAE9F,SAAS,GAAG,OAAO,CAAC;gBACpB,cAAc,GAAG,eAAe,CAAC;gBACjC,yCAAyC;gBACzC,SAAS,GAAG,IAAA,oCAAgB,EAC3B;oBACC;wBACC,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,QAAQ;qBACd;iBACD,EACD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CACxB,CAAC;aACF;iBAAM,IAAI,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE;gBAC/C,SAAS,GAAG,OAAO,CAAC;gBACpB,cAAc,GAAG,gBAAgB,CAAC;gBAClC,yCAAyC;gBACzC,SAAS,GAAG,IAAA,oCAAgB,EAC3B;oBACC;wBACC,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,SAAS;qBACf;iBACD,EACD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CACxB,CAAC;aACF;iBAAM;gBACN,OAAO,CAAC,KAAK,CAAC,4CAA4C,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;aACxE;SACD;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;QACD,IAAI,SAAS,EAAE;YACd,KAAK,CAAC,oBAAoB,CAAC,SAAS,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;SACjE;KACD;AACF,CAAC,CAAC;AAvDW,QAAA,uBAAuB,2BAuDlC"}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/**
|
2
|
+
* The web3.eth.abi functions let you encode and decode parameters to ABI (Application Binary Interface) for function calls to the EVM (Ethereum Virtual Machine).
|
3
|
+
*
|
4
|
+
* For using Web3 ABI functions, first install Web3 package using `npm i web3` or `yarn add web3`.
|
5
|
+
* After that, Web3 ABI functions will be available.
|
6
|
+
* ```ts
|
7
|
+
* import { Web3 } from 'web3';
|
8
|
+
*
|
9
|
+
* const web3 = new Web3();
|
10
|
+
* const encoded = web3.eth.abi.encodeFunctionSignature({
|
11
|
+
* name: 'myMethod',
|
12
|
+
* type: 'function',
|
13
|
+
* inputs: [{
|
14
|
+
* type: 'uint256',
|
15
|
+
* name: 'myNumber'
|
16
|
+
* },{
|
17
|
+
* type: 'string',
|
18
|
+
* name: 'myString'
|
19
|
+
* }]
|
20
|
+
* });
|
21
|
+
*
|
22
|
+
* ```
|
23
|
+
*
|
24
|
+
* For using individual package install `web3-eth-abi` package using `npm i web3-eth-abi` or `yarn add web3-eth-abi` and only import required functions.
|
25
|
+
* This is more efficient approach for building lightweight applications.
|
26
|
+
* ```ts
|
27
|
+
* import { encodeFunctionSignature } from 'web3-eth-abi';
|
28
|
+
*
|
29
|
+
* const encoded = encodeFunctionSignature({
|
30
|
+
* name: 'myMethod',
|
31
|
+
* type: 'function',
|
32
|
+
* inputs: [{
|
33
|
+
* type: 'uint256',
|
34
|
+
* name: 'myNumber'
|
35
|
+
* },{
|
36
|
+
* type: 'string',
|
37
|
+
* name: 'myString'
|
38
|
+
* }]
|
39
|
+
* });
|
40
|
+
*
|
41
|
+
* ```
|
42
|
+
*
|
43
|
+
* @module ABI
|
44
|
+
*/
|
45
|
+
import { Eip712TypedData } from 'web3-types';
|
46
|
+
/**
|
47
|
+
* Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
|
48
|
+
* with Keccak256.
|
49
|
+
*/
|
50
|
+
export declare const getMessage: (typedData: Eip712TypedData, hash?: boolean) => string;
|
@@ -0,0 +1,144 @@
|
|
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.getMessage = void 0;
|
20
|
+
const web3_utils_1 = require("web3-utils");
|
21
|
+
const web3_errors_1 = require("web3-errors");
|
22
|
+
const encode_js_1 = require("./coders/encode.js");
|
23
|
+
const TYPE_REGEX = /^\w+/;
|
24
|
+
const ARRAY_REGEX = /^(.*)\[([0-9]*?)]$/;
|
25
|
+
/**
|
26
|
+
* Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
|
27
|
+
* in the resulting array.
|
28
|
+
*/
|
29
|
+
const getDependencies = (typedData, type, dependencies = []) => {
|
30
|
+
const match = type.match(TYPE_REGEX);
|
31
|
+
const actualType = match[0];
|
32
|
+
if (dependencies.includes(actualType)) {
|
33
|
+
return dependencies;
|
34
|
+
}
|
35
|
+
if (!typedData.types[actualType]) {
|
36
|
+
return dependencies;
|
37
|
+
}
|
38
|
+
return [
|
39
|
+
actualType,
|
40
|
+
...typedData.types[actualType].reduce((previous, _type) => [
|
41
|
+
...previous,
|
42
|
+
...getDependencies(typedData, _type.type, previous).filter(dependency => !previous.includes(dependency)),
|
43
|
+
], []),
|
44
|
+
];
|
45
|
+
};
|
46
|
+
/**
|
47
|
+
* Encode a type to a string. All dependant types are alphabetically sorted.
|
48
|
+
*
|
49
|
+
* @param {TypedData} typedData
|
50
|
+
* @param {string} type
|
51
|
+
* @param {Options} [options]
|
52
|
+
* @return {string}
|
53
|
+
*/
|
54
|
+
const encodeType = (typedData, type) => {
|
55
|
+
const [primary, ...dependencies] = getDependencies(typedData, type);
|
56
|
+
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
57
|
+
const types = [primary, ...dependencies.sort()];
|
58
|
+
return types
|
59
|
+
.map(dependency =>
|
60
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
61
|
+
`${dependency}(${typedData.types[dependency].map(_type => `${_type.type} ${_type.name}`)})`)
|
62
|
+
.join('');
|
63
|
+
};
|
64
|
+
/**
|
65
|
+
* Get a type string as hash.
|
66
|
+
*/
|
67
|
+
const getTypeHash = (typedData, type) => (0, web3_utils_1.keccak256)(encodeType(typedData, type));
|
68
|
+
/**
|
69
|
+
* Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
|
70
|
+
* types are automatically encoded.
|
71
|
+
*/
|
72
|
+
const getStructHash = (typedData, type, data) => (0, web3_utils_1.keccak256)(encodeData(typedData, type, data));
|
73
|
+
/**
|
74
|
+
* Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
|
75
|
+
* with Keccak256.
|
76
|
+
*/
|
77
|
+
const getMessage = (typedData, hash) => {
|
78
|
+
const EIP_191_PREFIX = '1901';
|
79
|
+
const message = `0x${EIP_191_PREFIX}${getStructHash(typedData, 'EIP712Domain', typedData.domain).substring(2)}${getStructHash(typedData, typedData.primaryType, typedData.message).substring(2)}`;
|
80
|
+
if (hash) {
|
81
|
+
return (0, web3_utils_1.keccak256)(message);
|
82
|
+
}
|
83
|
+
return message;
|
84
|
+
};
|
85
|
+
exports.getMessage = getMessage;
|
86
|
+
/**
|
87
|
+
* Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
|
88
|
+
* an array of ABI compatible types, and an array of corresponding values.
|
89
|
+
*/
|
90
|
+
const encodeValue = (typedData, type, data) => {
|
91
|
+
const match = type.match(ARRAY_REGEX);
|
92
|
+
// Checks for array types
|
93
|
+
if (match) {
|
94
|
+
const arrayType = match[1];
|
95
|
+
const length = Number(match[2]) || undefined;
|
96
|
+
if (!Array.isArray(data)) {
|
97
|
+
throw new web3_errors_1.AbiError('Cannot encode data: value is not of array type', {
|
98
|
+
data,
|
99
|
+
});
|
100
|
+
}
|
101
|
+
if (length && data.length !== length) {
|
102
|
+
throw new web3_errors_1.AbiError(`Cannot encode data: expected length of ${length}, but got ${data.length}`, {
|
103
|
+
data,
|
104
|
+
});
|
105
|
+
}
|
106
|
+
const encodedData = data.map(item => encodeValue(typedData, arrayType, item));
|
107
|
+
const types = encodedData.map(item => item[0]);
|
108
|
+
const values = encodedData.map(item => item[1]);
|
109
|
+
return ['bytes32', (0, web3_utils_1.keccak256)((0, encode_js_1.encodeParameters)(types, values))];
|
110
|
+
}
|
111
|
+
if (typedData.types[type]) {
|
112
|
+
return ['bytes32', getStructHash(typedData, type, data)];
|
113
|
+
}
|
114
|
+
// Strings and arbitrary byte arrays are hashed to bytes32
|
115
|
+
if (type === 'string') {
|
116
|
+
return ['bytes32', (0, web3_utils_1.keccak256)(data)];
|
117
|
+
}
|
118
|
+
if (type === 'bytes') {
|
119
|
+
return ['bytes32', (0, web3_utils_1.keccak256)(data)];
|
120
|
+
}
|
121
|
+
return [type, data];
|
122
|
+
};
|
123
|
+
/**
|
124
|
+
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
|
125
|
+
* dependant types are automatically encoded.
|
126
|
+
*/
|
127
|
+
const encodeData = (typedData, type, data) => {
|
128
|
+
const [types, values] = typedData.types[type].reduce(([_types, _values], field) => {
|
129
|
+
if ((0, web3_utils_1.isNullish)(data[field.name]) || (0, web3_utils_1.isNullish)(field.type)) {
|
130
|
+
throw new web3_errors_1.AbiError(`Cannot encode data: missing data for '${field.name}'`, {
|
131
|
+
data,
|
132
|
+
field,
|
133
|
+
});
|
134
|
+
}
|
135
|
+
const value = data[field.name];
|
136
|
+
const [_type, encodedValue] = encodeValue(typedData, field.type, value);
|
137
|
+
return [
|
138
|
+
[..._types, _type],
|
139
|
+
[..._values, encodedValue],
|
140
|
+
];
|
141
|
+
}, [['bytes32'], [getTypeHash(typedData, type)]]);
|
142
|
+
return (0, encode_js_1.encodeParameters)(types, values);
|
143
|
+
};
|
144
|
+
//# sourceMappingURL=eip_712.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"eip_712.js","sourceRoot":"","sources":["../../src/eip_712.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAkDF,2CAAkD;AAClD,6CAAuC;AACvC,kDAAsD;AAEtD,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEzC;;;GAGG;AACH,MAAM,eAAe,GAAG,CACvB,SAA0B,EAC1B,IAAY,EACZ,eAAyB,EAAE,EAChB,EAAE;IACb,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAE,CAAC;IACtC,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAC5B,IAAI,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;QACtC,OAAO,YAAY,CAAC;KACpB;IAED,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;QACjC,OAAO,YAAY,CAAC;KACpB;IAED,OAAO;QACN,UAAU;QACV,GAAG,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,MAAM,CACpC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC;YACpB,GAAG,QAAQ;YACX,GAAG,eAAe,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,MAAM,CACzD,UAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,CAC5C;SACD,EACD,EAAE,CACF;KACD,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CAAC,SAA0B,EAAE,IAAY,EAAU,EAAE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C1B,CAAC;IACH,CAAC,EACD,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAC7C,CAAC;IAEF,OAAO,IAAA,4BAAgB,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC,CAAC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export * from './api/errors_api.js';
|
2
|
+
export * from './api/events_api.js';
|
3
|
+
export * from './api/functions_api.js';
|
4
|
+
export * from './api/logs_api.js';
|
5
|
+
export * from './api/parameters_api.js';
|
6
|
+
export * from './utils.js';
|
7
|
+
export * from './decode_contract_error_data.js';
|
8
|
+
export { getMessage as getEncodedEip712Data } from './eip_712.js';
|
@@ -0,0 +1,43 @@
|
|
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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
19
|
+
if (k2 === undefined) k2 = k;
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
23
|
+
}
|
24
|
+
Object.defineProperty(o, k2, desc);
|
25
|
+
}) : (function(o, m, k, k2) {
|
26
|
+
if (k2 === undefined) k2 = k;
|
27
|
+
o[k2] = m[k];
|
28
|
+
}));
|
29
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
30
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
31
|
+
};
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
33
|
+
exports.getEncodedEip712Data = void 0;
|
34
|
+
__exportStar(require("./api/errors_api.js"), exports);
|
35
|
+
__exportStar(require("./api/events_api.js"), exports);
|
36
|
+
__exportStar(require("./api/functions_api.js"), exports);
|
37
|
+
__exportStar(require("./api/logs_api.js"), exports);
|
38
|
+
__exportStar(require("./api/parameters_api.js"), exports);
|
39
|
+
__exportStar(require("./utils.js"), exports);
|
40
|
+
__exportStar(require("./decode_contract_error_data.js"), exports);
|
41
|
+
var eip_712_js_1 = require("./eip_712.js");
|
42
|
+
Object.defineProperty(exports, "getEncodedEip712Data", { enumerable: true, get: function () { return eip_712_js_1.getMessage; } });
|
43
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;;;;;;AAEF,sDAAoC;AACpC,sDAAoC;AACpC,yDAAuC;AACvC,oDAAkC;AAClC,0DAAwC;AACxC,6CAA2B;AAC3B,kEAAgD;AAChD,2CAAkE;AAAzD,kHAAA,UAAU,OAAwB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type": "commonjs"}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { AbiInput, AbiCoderStruct, AbiFragment, AbiParameter, AbiStruct, AbiEventFragment, AbiFunctionFragment, AbiConstructorFragment } from 'web3-types';
|
2
|
+
export declare const isAbiFragment: (item: unknown) => item is AbiFragment;
|
3
|
+
export declare const isAbiErrorFragment: (item: unknown) => item is AbiEventFragment;
|
4
|
+
export declare const isAbiEventFragment: (item: unknown) => item is AbiEventFragment;
|
5
|
+
export declare const isAbiFunctionFragment: (item: unknown) => item is AbiFunctionFragment;
|
6
|
+
export declare const isAbiConstructorFragment: (item: unknown) => item is AbiConstructorFragment;
|
7
|
+
/**
|
8
|
+
* Check if type is simplified struct format
|
9
|
+
*/
|
10
|
+
export declare const isSimplifiedStructFormat: (type: string | Partial<AbiParameter> | Partial<AbiInput>) => type is Omit<AbiParameter, "components" | "name">;
|
11
|
+
/**
|
12
|
+
* Maps the correct tuple type and name when the simplified format in encode/decodeParameter is used
|
13
|
+
*/
|
14
|
+
export declare const mapStructNameAndType: (structName: string) => AbiStruct;
|
15
|
+
/**
|
16
|
+
* Maps the simplified format in to the expected format of the ABICoder
|
17
|
+
*/
|
18
|
+
export declare const mapStructToCoderFormat: (struct: AbiStruct) => Array<AbiCoderStruct>;
|
19
|
+
/**
|
20
|
+
* Map types if simplified format is used
|
21
|
+
*/
|
22
|
+
export declare const mapTypes: (types: AbiInput[]) => Array<string | AbiParameter | Record<string, unknown>>;
|
23
|
+
/**
|
24
|
+
* returns true if input is a hexstring and is odd-lengthed
|
25
|
+
*/
|
26
|
+
export declare const isOddHexstring: (param: unknown) => boolean;
|
27
|
+
/**
|
28
|
+
* format odd-length bytes to even-length
|
29
|
+
*/
|
30
|
+
export declare const formatOddHexstrings: (param: string) => string;
|
31
|
+
/**
|
32
|
+
* Handle some formatting of params for backwards compatibility with Ethers V4
|
33
|
+
*/
|
34
|
+
export declare const formatParam: (type: string, _param: unknown) => unknown;
|
35
|
+
/**
|
36
|
+
* used to flatten json abi inputs/outputs into an array of type-representing-strings
|
37
|
+
*/
|
38
|
+
export declare const flattenTypes: (includeTuple: boolean, puts: ReadonlyArray<AbiParameter>) => string[];
|
39
|
+
/**
|
40
|
+
* Should be used to create full function/event name from json abi
|
41
|
+
* returns a string
|
42
|
+
*/
|
43
|
+
export declare const jsonInterfaceMethodToString: (json: AbiFragment) => string;
|
@@ -0,0 +1,216 @@
|
|
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.jsonInterfaceMethodToString = exports.flattenTypes = exports.formatParam = exports.formatOddHexstrings = exports.isOddHexstring = exports.mapTypes = exports.mapStructToCoderFormat = exports.mapStructNameAndType = exports.isSimplifiedStructFormat = exports.isAbiConstructorFragment = exports.isAbiFunctionFragment = exports.isAbiEventFragment = exports.isAbiErrorFragment = exports.isAbiFragment = void 0;
|
20
|
+
const web3_errors_1 = require("web3-errors");
|
21
|
+
const web3_utils_1 = require("web3-utils");
|
22
|
+
const isAbiFragment = (item) => !(0, web3_utils_1.isNullish)(item) &&
|
23
|
+
typeof item === 'object' &&
|
24
|
+
!(0, web3_utils_1.isNullish)(item.type) &&
|
25
|
+
['function', 'event', 'constructor', 'error'].includes(item.type);
|
26
|
+
exports.isAbiFragment = isAbiFragment;
|
27
|
+
const isAbiErrorFragment = (item) => !(0, web3_utils_1.isNullish)(item) &&
|
28
|
+
typeof item === 'object' &&
|
29
|
+
!(0, web3_utils_1.isNullish)(item.type) &&
|
30
|
+
item.type === 'error';
|
31
|
+
exports.isAbiErrorFragment = isAbiErrorFragment;
|
32
|
+
const isAbiEventFragment = (item) => !(0, web3_utils_1.isNullish)(item) &&
|
33
|
+
typeof item === 'object' &&
|
34
|
+
!(0, web3_utils_1.isNullish)(item.type) &&
|
35
|
+
item.type === 'event';
|
36
|
+
exports.isAbiEventFragment = isAbiEventFragment;
|
37
|
+
const isAbiFunctionFragment = (item) => !(0, web3_utils_1.isNullish)(item) &&
|
38
|
+
typeof item === 'object' &&
|
39
|
+
!(0, web3_utils_1.isNullish)(item.type) &&
|
40
|
+
item.type === 'function';
|
41
|
+
exports.isAbiFunctionFragment = isAbiFunctionFragment;
|
42
|
+
const isAbiConstructorFragment = (item) => !(0, web3_utils_1.isNullish)(item) &&
|
43
|
+
typeof item === 'object' &&
|
44
|
+
!(0, web3_utils_1.isNullish)(item.type) &&
|
45
|
+
item.type === 'constructor';
|
46
|
+
exports.isAbiConstructorFragment = isAbiConstructorFragment;
|
47
|
+
/**
|
48
|
+
* Check if type is simplified struct format
|
49
|
+
*/
|
50
|
+
const isSimplifiedStructFormat = (type) => typeof type === 'object' &&
|
51
|
+
typeof type.components === 'undefined' &&
|
52
|
+
typeof type.name === 'undefined';
|
53
|
+
exports.isSimplifiedStructFormat = isSimplifiedStructFormat;
|
54
|
+
/**
|
55
|
+
* Maps the correct tuple type and name when the simplified format in encode/decodeParameter is used
|
56
|
+
*/
|
57
|
+
const mapStructNameAndType = (structName) => structName.includes('[]')
|
58
|
+
? { type: 'tuple[]', name: structName.slice(0, -2) }
|
59
|
+
: { type: 'tuple', name: structName };
|
60
|
+
exports.mapStructNameAndType = mapStructNameAndType;
|
61
|
+
/**
|
62
|
+
* Maps the simplified format in to the expected format of the ABICoder
|
63
|
+
*/
|
64
|
+
const mapStructToCoderFormat = (struct) => {
|
65
|
+
const components = [];
|
66
|
+
for (const key of Object.keys(struct)) {
|
67
|
+
const item = struct[key];
|
68
|
+
if (typeof item === 'object') {
|
69
|
+
components.push(Object.assign(Object.assign({}, (0, exports.mapStructNameAndType)(key)), { components: (0, exports.mapStructToCoderFormat)(item) }));
|
70
|
+
}
|
71
|
+
else {
|
72
|
+
components.push({
|
73
|
+
name: key,
|
74
|
+
type: struct[key],
|
75
|
+
});
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return components;
|
79
|
+
};
|
80
|
+
exports.mapStructToCoderFormat = mapStructToCoderFormat;
|
81
|
+
/**
|
82
|
+
* Map types if simplified format is used
|
83
|
+
*/
|
84
|
+
const mapTypes = (types) => {
|
85
|
+
const mappedTypes = [];
|
86
|
+
for (const type of types) {
|
87
|
+
let modifiedType = type;
|
88
|
+
// Clone object
|
89
|
+
if (typeof type === 'object') {
|
90
|
+
modifiedType = Object.assign({}, type);
|
91
|
+
}
|
92
|
+
// Remap `function` type params to bytes24 since Ethers does not
|
93
|
+
// recognize former type. Solidity docs say `Function` is a bytes24
|
94
|
+
// encoding the contract address followed by the function selector hash.
|
95
|
+
if (typeof type === 'object' && type.type === 'function') {
|
96
|
+
modifiedType = Object.assign(Object.assign({}, type), { type: 'bytes24' });
|
97
|
+
}
|
98
|
+
if ((0, exports.isSimplifiedStructFormat)(modifiedType)) {
|
99
|
+
const structName = Object.keys(modifiedType)[0];
|
100
|
+
mappedTypes.push(Object.assign(Object.assign({}, (0, exports.mapStructNameAndType)(structName)), { components: (0, exports.mapStructToCoderFormat)(modifiedType[structName]) }));
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
mappedTypes.push(modifiedType);
|
104
|
+
}
|
105
|
+
}
|
106
|
+
return mappedTypes;
|
107
|
+
};
|
108
|
+
exports.mapTypes = mapTypes;
|
109
|
+
/**
|
110
|
+
* returns true if input is a hexstring and is odd-lengthed
|
111
|
+
*/
|
112
|
+
const isOddHexstring = (param) => typeof param === 'string' && /^(-)?0x[0-9a-f]*$/i.test(param) && param.length % 2 === 1;
|
113
|
+
exports.isOddHexstring = isOddHexstring;
|
114
|
+
/**
|
115
|
+
* format odd-length bytes to even-length
|
116
|
+
*/
|
117
|
+
const formatOddHexstrings = (param) => (0, exports.isOddHexstring)(param) ? `0x0${param.substring(2)}` : param;
|
118
|
+
exports.formatOddHexstrings = formatOddHexstrings;
|
119
|
+
const paramTypeBytes = /^bytes([0-9]*)$/;
|
120
|
+
const paramTypeBytesArray = /^bytes([0-9]*)\[\]$/;
|
121
|
+
const paramTypeNumber = /^(u?int)([0-9]*)$/;
|
122
|
+
const paramTypeNumberArray = /^(u?int)([0-9]*)\[\]$/;
|
123
|
+
/**
|
124
|
+
* Handle some formatting of params for backwards compatibility with Ethers V4
|
125
|
+
*/
|
126
|
+
const formatParam = (type, _param) => {
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
128
|
+
// clone if _param is an object
|
129
|
+
const param = typeof _param === 'object' && !Array.isArray(_param) ? Object.assign({}, _param) : _param;
|
130
|
+
// Format BN to string
|
131
|
+
if (param instanceof BigInt || typeof param === 'bigint') {
|
132
|
+
return param.toString(10);
|
133
|
+
}
|
134
|
+
if (paramTypeBytesArray.exec(type) || paramTypeNumberArray.exec(type)) {
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
136
|
+
const paramClone = [...param];
|
137
|
+
return paramClone.map(p => (0, exports.formatParam)(type.replace('[]', ''), p));
|
138
|
+
}
|
139
|
+
// Format correct width for u?int[0-9]*
|
140
|
+
let match = paramTypeNumber.exec(type);
|
141
|
+
if (match) {
|
142
|
+
const size = parseInt(match[2] ? match[2] : '256', 10);
|
143
|
+
if (size / 8 < param.length) {
|
144
|
+
// pad to correct bit width
|
145
|
+
return (0, web3_utils_1.leftPad)(param, size);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
// Format correct length for bytes[0-9]+
|
149
|
+
match = paramTypeBytes.exec(type);
|
150
|
+
if (match) {
|
151
|
+
const hexParam = (0, web3_utils_1.isUint8Array)(param) ? (0, web3_utils_1.toHex)(param) : param;
|
152
|
+
// format to correct length
|
153
|
+
const size = parseInt(match[1], 10);
|
154
|
+
if (size) {
|
155
|
+
let maxSize = size * 2;
|
156
|
+
if (param.startsWith('0x')) {
|
157
|
+
maxSize += 2;
|
158
|
+
}
|
159
|
+
// pad to correct length
|
160
|
+
const paddedParam = hexParam.length < maxSize
|
161
|
+
? (0, web3_utils_1.rightPad)(param, size * 2)
|
162
|
+
: hexParam;
|
163
|
+
return (0, exports.formatOddHexstrings)(paddedParam);
|
164
|
+
}
|
165
|
+
return (0, exports.formatOddHexstrings)(hexParam);
|
166
|
+
}
|
167
|
+
return param;
|
168
|
+
};
|
169
|
+
exports.formatParam = formatParam;
|
170
|
+
/**
|
171
|
+
* used to flatten json abi inputs/outputs into an array of type-representing-strings
|
172
|
+
*/
|
173
|
+
const flattenTypes = (includeTuple, puts) => {
|
174
|
+
const types = [];
|
175
|
+
puts.forEach(param => {
|
176
|
+
if (typeof param.components === 'object') {
|
177
|
+
if (!param.type.startsWith('tuple')) {
|
178
|
+
throw new web3_errors_1.AbiError(`Invalid value given "${param.type}". Error: components found but type is not tuple.`);
|
179
|
+
}
|
180
|
+
const arrayBracket = param.type.indexOf('[');
|
181
|
+
const suffix = arrayBracket >= 0 ? param.type.substring(arrayBracket) : '';
|
182
|
+
const result = (0, exports.flattenTypes)(includeTuple, param.components);
|
183
|
+
if (Array.isArray(result) && includeTuple) {
|
184
|
+
types.push(`tuple(${result.join(',')})${suffix}`);
|
185
|
+
}
|
186
|
+
else if (!includeTuple) {
|
187
|
+
types.push(`(${result.join(',')})${suffix}`);
|
188
|
+
}
|
189
|
+
else {
|
190
|
+
types.push(`(${result.join()})`);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
else {
|
194
|
+
types.push(param.type);
|
195
|
+
}
|
196
|
+
});
|
197
|
+
return types;
|
198
|
+
};
|
199
|
+
exports.flattenTypes = flattenTypes;
|
200
|
+
/**
|
201
|
+
* Should be used to create full function/event name from json abi
|
202
|
+
* returns a string
|
203
|
+
*/
|
204
|
+
const jsonInterfaceMethodToString = (json) => {
|
205
|
+
var _a, _b, _c, _d;
|
206
|
+
if ((0, exports.isAbiErrorFragment)(json) || (0, exports.isAbiEventFragment)(json) || (0, exports.isAbiFunctionFragment)(json)) {
|
207
|
+
if ((_a = json.name) === null || _a === void 0 ? void 0 : _a.includes('(')) {
|
208
|
+
return json.name;
|
209
|
+
}
|
210
|
+
return `${(_b = json.name) !== null && _b !== void 0 ? _b : ''}(${(0, exports.flattenTypes)(false, (_c = json.inputs) !== null && _c !== void 0 ? _c : []).join(',')})`;
|
211
|
+
}
|
212
|
+
// Constructor fragment
|
213
|
+
return `(${(0, exports.flattenTypes)(false, (_d = json.inputs) !== null && _d !== void 0 ? _d : []).join(',')})`;
|
214
|
+
};
|
215
|
+
exports.jsonInterfaceMethodToString = jsonInterfaceMethodToString;
|
216
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF,6CAAuC;AACvC,2CAA+E;AAYxE,MAAM,aAAa,GAAG,CAAC,IAAa,EAAuB,EAAE,CACnE,CAAC,IAAA,sBAAS,EAAC,IAAI,CAAC;IAChB,OAAO,IAAI,KAAK,QAAQ;IACxB,CAAC,IAAA,sBAAS,EAAE,IAAyB,CAAC,IAAI,CAAC;IAC3C,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAE,IAAyB,CAAC,IAAI,CAAC,CAAC;AAJ5E,QAAA,aAAa,iBAI+D;AAElF,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAA4B,EAAE,CAC7E,CAAC,IAAA,sBAAS,EAAC,IAAI,CAAC;IAChB,OAAO,IAAI,KAAK,QAAQ;IACxB,CAAC,IAAA,sBAAS,EAAE,IAAyB,CAAC,IAAI,CAAC;IAC1C,IAAyB,CAAC,IAAI,KAAK,OAAO,CAAC;AAJhC,QAAA,kBAAkB,sBAIc;AAEtC,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAA4B,EAAE,CAC7E,CAAC,IAAA,sBAAS,EAAC,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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, isAbiErrorFragment } from '../utils.js';
|
24
|
+
/**
|
25
|
+
* Encodes the error name to its ABI signature, which are the sha3 hash of the error name including input types.
|
26
|
+
*/
|
27
|
+
export const encodeErrorSignature = (functionName) => {
|
28
|
+
if (typeof functionName !== 'string' && !isAbiErrorFragment(functionName)) {
|
29
|
+
throw new AbiError('Invalid parameter value in encodeErrorSignature');
|
30
|
+
}
|
31
|
+
let name;
|
32
|
+
if (functionName && (typeof functionName === 'function' || typeof functionName === 'object')) {
|
33
|
+
name = jsonInterfaceMethodToString(functionName);
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
name = functionName;
|
37
|
+
}
|
38
|
+
return sha3Raw(name);
|
39
|
+
};
|
40
|
+
//# sourceMappingURL=errors_api.js.map
|