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,140 @@
|
|
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 { isNullish, keccak256 } from 'web3-utils';
|
18
|
+
import { AbiError } from 'web3-errors';
|
19
|
+
import { encodeParameters } from './coders/encode.js';
|
20
|
+
const TYPE_REGEX = /^\w+/;
|
21
|
+
const ARRAY_REGEX = /^(.*)\[([0-9]*?)]$/;
|
22
|
+
/**
|
23
|
+
* Get the dependencies of a struct type. If a struct has the same dependency multiple times, it's only included once
|
24
|
+
* in the resulting array.
|
25
|
+
*/
|
26
|
+
const getDependencies = (typedData, type, dependencies = []) => {
|
27
|
+
const match = type.match(TYPE_REGEX);
|
28
|
+
const actualType = match[0];
|
29
|
+
if (dependencies.includes(actualType)) {
|
30
|
+
return dependencies;
|
31
|
+
}
|
32
|
+
if (!typedData.types[actualType]) {
|
33
|
+
return dependencies;
|
34
|
+
}
|
35
|
+
return [
|
36
|
+
actualType,
|
37
|
+
...typedData.types[actualType].reduce((previous, _type) => [
|
38
|
+
...previous,
|
39
|
+
...getDependencies(typedData, _type.type, previous).filter(dependency => !previous.includes(dependency)),
|
40
|
+
], []),
|
41
|
+
];
|
42
|
+
};
|
43
|
+
/**
|
44
|
+
* Encode a type to a string. All dependant types are alphabetically sorted.
|
45
|
+
*
|
46
|
+
* @param {TypedData} typedData
|
47
|
+
* @param {string} type
|
48
|
+
* @param {Options} [options]
|
49
|
+
* @return {string}
|
50
|
+
*/
|
51
|
+
const encodeType = (typedData, type) => {
|
52
|
+
const [primary, ...dependencies] = getDependencies(typedData, type);
|
53
|
+
// eslint-disable-next-line @typescript-eslint/require-array-sort-compare
|
54
|
+
const types = [primary, ...dependencies.sort()];
|
55
|
+
return types
|
56
|
+
.map(dependency =>
|
57
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
58
|
+
`${dependency}(${typedData.types[dependency].map(_type => `${_type.type} ${_type.name}`)})`)
|
59
|
+
.join('');
|
60
|
+
};
|
61
|
+
/**
|
62
|
+
* Get a type string as hash.
|
63
|
+
*/
|
64
|
+
const getTypeHash = (typedData, type) => keccak256(encodeType(typedData, type));
|
65
|
+
/**
|
66
|
+
* Get encoded data as a hash. The data should be a key -> value object with all the required values. All dependant
|
67
|
+
* types are automatically encoded.
|
68
|
+
*/
|
69
|
+
const getStructHash = (typedData, type, data) => keccak256(encodeData(typedData, type, data));
|
70
|
+
/**
|
71
|
+
* Get the EIP-191 encoded message to sign, from the typedData object. If `hash` is enabled, the message will be hashed
|
72
|
+
* with Keccak256.
|
73
|
+
*/
|
74
|
+
export const getMessage = (typedData, hash) => {
|
75
|
+
const EIP_191_PREFIX = '1901';
|
76
|
+
const message = `0x${EIP_191_PREFIX}${getStructHash(typedData, 'EIP712Domain', typedData.domain).substring(2)}${getStructHash(typedData, typedData.primaryType, typedData.message).substring(2)}`;
|
77
|
+
if (hash) {
|
78
|
+
return keccak256(message);
|
79
|
+
}
|
80
|
+
return message;
|
81
|
+
};
|
82
|
+
/**
|
83
|
+
* Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as tuple, which consists of
|
84
|
+
* an array of ABI compatible types, and an array of corresponding values.
|
85
|
+
*/
|
86
|
+
const encodeValue = (typedData, type, data) => {
|
87
|
+
const match = type.match(ARRAY_REGEX);
|
88
|
+
// Checks for array types
|
89
|
+
if (match) {
|
90
|
+
const arrayType = match[1];
|
91
|
+
const length = Number(match[2]) || undefined;
|
92
|
+
if (!Array.isArray(data)) {
|
93
|
+
throw new AbiError('Cannot encode data: value is not of array type', {
|
94
|
+
data,
|
95
|
+
});
|
96
|
+
}
|
97
|
+
if (length && data.length !== length) {
|
98
|
+
throw new AbiError(`Cannot encode data: expected length of ${length}, but got ${data.length}`, {
|
99
|
+
data,
|
100
|
+
});
|
101
|
+
}
|
102
|
+
const encodedData = data.map(item => encodeValue(typedData, arrayType, item));
|
103
|
+
const types = encodedData.map(item => item[0]);
|
104
|
+
const values = encodedData.map(item => item[1]);
|
105
|
+
return ['bytes32', keccak256(encodeParameters(types, values))];
|
106
|
+
}
|
107
|
+
if (typedData.types[type]) {
|
108
|
+
return ['bytes32', getStructHash(typedData, type, data)];
|
109
|
+
}
|
110
|
+
// Strings and arbitrary byte arrays are hashed to bytes32
|
111
|
+
if (type === 'string') {
|
112
|
+
return ['bytes32', keccak256(data)];
|
113
|
+
}
|
114
|
+
if (type === 'bytes') {
|
115
|
+
return ['bytes32', keccak256(data)];
|
116
|
+
}
|
117
|
+
return [type, data];
|
118
|
+
};
|
119
|
+
/**
|
120
|
+
* Encode the data to an ABI encoded Buffer. The data should be a key -> value object with all the required values. All
|
121
|
+
* dependant types are automatically encoded.
|
122
|
+
*/
|
123
|
+
const encodeData = (typedData, type, data) => {
|
124
|
+
const [types, values] = typedData.types[type].reduce(([_types, _values], field) => {
|
125
|
+
if (isNullish(data[field.name]) || isNullish(field.type)) {
|
126
|
+
throw new AbiError(`Cannot encode data: missing data for '${field.name}'`, {
|
127
|
+
data,
|
128
|
+
field,
|
129
|
+
});
|
130
|
+
}
|
131
|
+
const value = data[field.name];
|
132
|
+
const [_type, encodedValue] = encodeValue(typedData, field.type, value);
|
133
|
+
return [
|
134
|
+
[..._types, _type],
|
135
|
+
[..._values, encodedValue],
|
136
|
+
];
|
137
|
+
}, [['bytes32'], [getTypeHash(typedData, type)]]);
|
138
|
+
return encodeParameters(types, values);
|
139
|
+
};
|
140
|
+
//# 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,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,WAAW,GAAG,oBAAoB,CAAC;AAEzC;;;GAGG;AACH,MAAM,eAAe,GAAG,CACvB,SAA0B,EAC1B,IAAY,EACZ,eAA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AAE;IACX,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CACnD,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE;QAC5B,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;YACzD,MAAM,IAAI,QAAQ,CAAC,yCAAyC,KAAK,CAAC,IAAI,GAAG,EAAE;gBAC1E,IAAI;gBACJ,KAAK;aACL,CAAC,CAAC;SACH;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,GAAG,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAExE,OAAO;YACN,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC;YAClB,CAAC,GAAG,OAAO,EAAE,YAAY,CAAC;SAC1B,CAAC;IACH,CAAC,EACD,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC,WAAW,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAC7C,CAAC;IAEF,OAAO,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC,CAAC"}
|
package/lib/esm/index.js
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
export * from './api/errors_api.js';
|
18
|
+
export * from './api/events_api.js';
|
19
|
+
export * from './api/functions_api.js';
|
20
|
+
export * from './api/logs_api.js';
|
21
|
+
export * from './api/parameters_api.js';
|
22
|
+
export * from './utils.js';
|
23
|
+
export * from './decode_contract_error_data.js';
|
24
|
+
export { getMessage as getEncodedEip712Data } from './eip_712.js';
|
25
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,YAAY,CAAC;AAC3B,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,cAAc,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"type": "module"}
|
package/lib/esm/utils.js
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
/*
|
2
|
+
This file is part of web3.js.
|
3
|
+
|
4
|
+
web3.js is free software: you can redistribute it and/or modify
|
5
|
+
it under the terms of the GNU Lesser General Public License as published by
|
6
|
+
the Free Software Foundation, either version 3 of the License, or
|
7
|
+
(at your option) any later version.
|
8
|
+
|
9
|
+
web3.js is distributed in the hope that it will be useful,
|
10
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
GNU Lesser General Public License for more details.
|
13
|
+
|
14
|
+
You should have received a copy of the GNU Lesser General Public License
|
15
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { AbiError } from 'web3-errors';
|
18
|
+
import { isNullish, isUint8Array, leftPad, rightPad, toHex } from 'web3-utils';
|
19
|
+
export const isAbiFragment = (item) => !isNullish(item) &&
|
20
|
+
typeof item === 'object' &&
|
21
|
+
!isNullish(item.type) &&
|
22
|
+
['function', 'event', 'constructor', 'error'].includes(item.type);
|
23
|
+
export const isAbiErrorFragment = (item) => !isNullish(item) &&
|
24
|
+
typeof item === 'object' &&
|
25
|
+
!isNullish(item.type) &&
|
26
|
+
item.type === 'error';
|
27
|
+
export const isAbiEventFragment = (item) => !isNullish(item) &&
|
28
|
+
typeof item === 'object' &&
|
29
|
+
!isNullish(item.type) &&
|
30
|
+
item.type === 'event';
|
31
|
+
export const isAbiFunctionFragment = (item) => !isNullish(item) &&
|
32
|
+
typeof item === 'object' &&
|
33
|
+
!isNullish(item.type) &&
|
34
|
+
item.type === 'function';
|
35
|
+
export const isAbiConstructorFragment = (item) => !isNullish(item) &&
|
36
|
+
typeof item === 'object' &&
|
37
|
+
!isNullish(item.type) &&
|
38
|
+
item.type === 'constructor';
|
39
|
+
/**
|
40
|
+
* Check if type is simplified struct format
|
41
|
+
*/
|
42
|
+
export const isSimplifiedStructFormat = (type) => typeof type === 'object' &&
|
43
|
+
typeof type.components === 'undefined' &&
|
44
|
+
typeof type.name === 'undefined';
|
45
|
+
/**
|
46
|
+
* Maps the correct tuple type and name when the simplified format in encode/decodeParameter is used
|
47
|
+
*/
|
48
|
+
export const mapStructNameAndType = (structName) => structName.includes('[]')
|
49
|
+
? { type: 'tuple[]', name: structName.slice(0, -2) }
|
50
|
+
: { type: 'tuple', name: structName };
|
51
|
+
/**
|
52
|
+
* Maps the simplified format in to the expected format of the ABICoder
|
53
|
+
*/
|
54
|
+
export const mapStructToCoderFormat = (struct) => {
|
55
|
+
const components = [];
|
56
|
+
for (const key of Object.keys(struct)) {
|
57
|
+
const item = struct[key];
|
58
|
+
if (typeof item === 'object') {
|
59
|
+
components.push(Object.assign(Object.assign({}, mapStructNameAndType(key)), { components: mapStructToCoderFormat(item) }));
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
components.push({
|
63
|
+
name: key,
|
64
|
+
type: struct[key],
|
65
|
+
});
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return components;
|
69
|
+
};
|
70
|
+
/**
|
71
|
+
* Map types if simplified format is used
|
72
|
+
*/
|
73
|
+
export const mapTypes = (types) => {
|
74
|
+
const mappedTypes = [];
|
75
|
+
for (const type of types) {
|
76
|
+
let modifiedType = type;
|
77
|
+
// Clone object
|
78
|
+
if (typeof type === 'object') {
|
79
|
+
modifiedType = Object.assign({}, type);
|
80
|
+
}
|
81
|
+
// Remap `function` type params to bytes24 since Ethers does not
|
82
|
+
// recognize former type. Solidity docs say `Function` is a bytes24
|
83
|
+
// encoding the contract address followed by the function selector hash.
|
84
|
+
if (typeof type === 'object' && type.type === 'function') {
|
85
|
+
modifiedType = Object.assign(Object.assign({}, type), { type: 'bytes24' });
|
86
|
+
}
|
87
|
+
if (isSimplifiedStructFormat(modifiedType)) {
|
88
|
+
const structName = Object.keys(modifiedType)[0];
|
89
|
+
mappedTypes.push(Object.assign(Object.assign({}, mapStructNameAndType(structName)), { components: mapStructToCoderFormat(modifiedType[structName]) }));
|
90
|
+
}
|
91
|
+
else {
|
92
|
+
mappedTypes.push(modifiedType);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
return mappedTypes;
|
96
|
+
};
|
97
|
+
/**
|
98
|
+
* returns true if input is a hexstring and is odd-lengthed
|
99
|
+
*/
|
100
|
+
export const isOddHexstring = (param) => typeof param === 'string' && /^(-)?0x[0-9a-f]*$/i.test(param) && param.length % 2 === 1;
|
101
|
+
/**
|
102
|
+
* format odd-length bytes to even-length
|
103
|
+
*/
|
104
|
+
export const formatOddHexstrings = (param) => isOddHexstring(param) ? `0x0${param.substring(2)}` : param;
|
105
|
+
const paramTypeBytes = /^bytes([0-9]*)$/;
|
106
|
+
const paramTypeBytesArray = /^bytes([0-9]*)\[\]$/;
|
107
|
+
const paramTypeNumber = /^(u?int)([0-9]*)$/;
|
108
|
+
const paramTypeNumberArray = /^(u?int)([0-9]*)\[\]$/;
|
109
|
+
/**
|
110
|
+
* Handle some formatting of params for backwards compatibility with Ethers V4
|
111
|
+
*/
|
112
|
+
export const formatParam = (type, _param) => {
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
114
|
+
// clone if _param is an object
|
115
|
+
const param = typeof _param === 'object' && !Array.isArray(_param) ? Object.assign({}, _param) : _param;
|
116
|
+
// Format BN to string
|
117
|
+
if (param instanceof BigInt || typeof param === 'bigint') {
|
118
|
+
return param.toString(10);
|
119
|
+
}
|
120
|
+
if (paramTypeBytesArray.exec(type) || paramTypeNumberArray.exec(type)) {
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
122
|
+
const paramClone = [...param];
|
123
|
+
return paramClone.map(p => formatParam(type.replace('[]', ''), p));
|
124
|
+
}
|
125
|
+
// Format correct width for u?int[0-9]*
|
126
|
+
let match = paramTypeNumber.exec(type);
|
127
|
+
if (match) {
|
128
|
+
const size = parseInt(match[2] ? match[2] : '256', 10);
|
129
|
+
if (size / 8 < param.length) {
|
130
|
+
// pad to correct bit width
|
131
|
+
return leftPad(param, size);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
// Format correct length for bytes[0-9]+
|
135
|
+
match = paramTypeBytes.exec(type);
|
136
|
+
if (match) {
|
137
|
+
const hexParam = isUint8Array(param) ? toHex(param) : param;
|
138
|
+
// format to correct length
|
139
|
+
const size = parseInt(match[1], 10);
|
140
|
+
if (size) {
|
141
|
+
let maxSize = size * 2;
|
142
|
+
if (param.startsWith('0x')) {
|
143
|
+
maxSize += 2;
|
144
|
+
}
|
145
|
+
// pad to correct length
|
146
|
+
const paddedParam = hexParam.length < maxSize
|
147
|
+
? rightPad(param, size * 2)
|
148
|
+
: hexParam;
|
149
|
+
return formatOddHexstrings(paddedParam);
|
150
|
+
}
|
151
|
+
return formatOddHexstrings(hexParam);
|
152
|
+
}
|
153
|
+
return param;
|
154
|
+
};
|
155
|
+
/**
|
156
|
+
* used to flatten json abi inputs/outputs into an array of type-representing-strings
|
157
|
+
*/
|
158
|
+
export const flattenTypes = (includeTuple, puts) => {
|
159
|
+
const types = [];
|
160
|
+
puts.forEach(param => {
|
161
|
+
if (typeof param.components === 'object') {
|
162
|
+
if (!param.type.startsWith('tuple')) {
|
163
|
+
throw new AbiError(`Invalid value given "${param.type}". Error: components found but type is not tuple.`);
|
164
|
+
}
|
165
|
+
const arrayBracket = param.type.indexOf('[');
|
166
|
+
const suffix = arrayBracket >= 0 ? param.type.substring(arrayBracket) : '';
|
167
|
+
const result = flattenTypes(includeTuple, param.components);
|
168
|
+
if (Array.isArray(result) && includeTuple) {
|
169
|
+
types.push(`tuple(${result.join(',')})${suffix}`);
|
170
|
+
}
|
171
|
+
else if (!includeTuple) {
|
172
|
+
types.push(`(${result.join(',')})${suffix}`);
|
173
|
+
}
|
174
|
+
else {
|
175
|
+
types.push(`(${result.join()})`);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
else {
|
179
|
+
types.push(param.type);
|
180
|
+
}
|
181
|
+
});
|
182
|
+
return types;
|
183
|
+
};
|
184
|
+
/**
|
185
|
+
* Should be used to create full function/event name from json abi
|
186
|
+
* returns a string
|
187
|
+
*/
|
188
|
+
export const jsonInterfaceMethodToString = (json) => {
|
189
|
+
var _a, _b, _c, _d;
|
190
|
+
if (isAbiErrorFragment(json) || isAbiEventFragment(json) || isAbiFunctionFragment(json)) {
|
191
|
+
if ((_a = json.name) === null || _a === void 0 ? void 0 : _a.includes('(')) {
|
192
|
+
return json.name;
|
193
|
+
}
|
194
|
+
return `${(_b = json.name) !== null && _b !== void 0 ? _b : ''}(${flattenTypes(false, (_c = json.inputs) !== null && _c !== void 0 ? _c : []).join(',')})`;
|
195
|
+
}
|
196
|
+
// Constructor fragment
|
197
|
+
return `(${flattenTypes(false, (_d = json.inputs) !== null && _d !== void 0 ? _d : []).join(',')})`;
|
198
|
+
};
|
199
|
+
//# sourceMappingURL=utils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAY/E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAa,EAAuB,EAAE,CACnE,CAAC,SAAS,CAAC,IAAI,CAAC;IAChB,OAAO,IAAI,KAAK,QAAQ;IACxB,CAAC,SAAS,CAAE,IAAyB,CAAC,IAAI,CAAC;IAC3C,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAE,IAAyB,CAAC,IAAI,CAAC,CAAC;AAEzF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAA4B,EAAE,CAC7E,CAAC,SAAS,CAAC,IAAI,CAAC;IAChB,OAAO,IAAI,KAAK,QAAQ;IACxB,CAAC,SAAS,CAAE,IAAyB,CAAC,IAAI,CAAC;IAC1C,IAAyB,CAAC,IAAI,KAAK,OAAO,CAAC;AAE7C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAA4B,EAAE,CAC7E,CAAC,SAAS,CAAC,IAAI,CAAC;IAChB,OAAO,IAAI,KAAK,QAAQ;IACxB,CAAC,SAAS,CAAE,IAAyB,CAAC,IAAI,CAAC;IAC1C,IAAyB,CAAC,IAAI,KAAK,OAAO,CAAC;AAE7C,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAa,EAA+B,EAAE,CACnF,CAAC,SAAS,CAAC,IAAI,CA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AC,IAAI,kBAAkB,CAAC,IAAI,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,EAAE;QACxF,IAAI,MAAA,IAAI,CAAC,IAAI,0CAAE,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC7B,OAAO,IAAI,CAAC,IAAI,CAAC;SACjB;QAED,OAAO,GAAG,MAAA,IAAI,CAAC,IAAI,mCAAI,EAAE,IAAI,YAAY,CAAC,KAAK,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;KACjF;IAED,uBAAuB;IACvB,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,MAAA,IAAI,CAAC,MAAM,mCAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AAChE,CAAC,CAAC"}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { AbiErrorFragment } from 'web3-types';
|
2
|
+
/**
|
3
|
+
* Encodes the error name to its ABI signature, which are the sha3 hash of the error name including input types.
|
4
|
+
*/
|
5
|
+
export declare const encodeErrorSignature: (functionName: string | AbiErrorFragment) => string;
|
6
|
+
//# sourceMappingURL=errors_api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors_api.d.ts","sourceRoot":"","sources":["../../../src/api/errors_api.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C;;GAEG;AACH,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,GAAG,gBAAgB,KAAG,MAc9E,CAAC"}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { AbiEventFragment } from 'web3-types';
|
2
|
+
/**
|
3
|
+
* Encodes the event name to its ABI signature, which are the sha3 hash of the event name including input types.
|
4
|
+
* @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).
|
5
|
+
* @returns - The ABI signature of the event.
|
6
|
+
*
|
7
|
+
* @example
|
8
|
+
* ```ts
|
9
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
10
|
+
* name: "myEvent",
|
11
|
+
* type: "event",
|
12
|
+
* inputs: [
|
13
|
+
* {
|
14
|
+
* type: "uint256",
|
15
|
+
* name: "myNumber",
|
16
|
+
* },
|
17
|
+
* {
|
18
|
+
* type: "bytes32",
|
19
|
+
* name: "myBytes",
|
20
|
+
* },
|
21
|
+
* ],
|
22
|
+
* });
|
23
|
+
* console.log(event);
|
24
|
+
* > 0xf2eeb729e636a8cb783be044acf6b7b1e2c5863735b60d6daae84c366ee87d97
|
25
|
+
*
|
26
|
+
* const event = web3.eth.abi.encodeEventSignature({
|
27
|
+
* inputs: [
|
28
|
+
* {
|
29
|
+
* indexed: true,
|
30
|
+
* name: "from",
|
31
|
+
* type: "address",
|
32
|
+
* },
|
33
|
+
* {
|
34
|
+
* indexed: true,
|
35
|
+
* name: "to",
|
36
|
+
* type: "address",
|
37
|
+
* },
|
38
|
+
* {
|
39
|
+
* indexed: false,
|
40
|
+
* name: "value",
|
41
|
+
* type: "uint256",
|
42
|
+
* },
|
43
|
+
* ],
|
44
|
+
* name: "Transfer",
|
45
|
+
* type: "event",
|
46
|
+
* });
|
47
|
+
* console.log(event);
|
48
|
+
* > 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
|
49
|
+
* ```
|
50
|
+
*/
|
51
|
+
export declare const encodeEventSignature: (functionName: string | AbiEventFragment) => string;
|
52
|
+
//# sourceMappingURL=events_api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"events_api.d.ts","sourceRoot":"","sources":["../../../src/api/events_api.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,oBAAoB,iBAAkB,MAAM,GAAG,gBAAgB,KAAG,MAc9E,CAAC"}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
import { AbiFunctionFragment } from 'web3-types';
|
2
|
+
/**
|
3
|
+
* Encodes the function name to its ABI representation, which are the first 4 bytes of the sha3 of the function name including types.
|
4
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
5
|
+
* @param functionName - The function name to encode or the `JSON interface` object of the function.
|
6
|
+
* If the passed parameter is a string, it has to be in the form of `functionName(param1Type,param2Type,...)`. eg: myFunction(uint256,uint32[],bytes10,bytes)
|
7
|
+
* @returns - The ABI signature of the function.
|
8
|
+
* @example
|
9
|
+
* ```ts
|
10
|
+
* const signature = web3.eth.abi.encodeFunctionSignature({
|
11
|
+
* name: "myMethod",
|
12
|
+
* type: "function",
|
13
|
+
* inputs: [
|
14
|
+
* {
|
15
|
+
* type: "uint256",
|
16
|
+
* name: "myNumber",
|
17
|
+
* },
|
18
|
+
* {
|
19
|
+
* type: "string",
|
20
|
+
* name: "myString",
|
21
|
+
* },
|
22
|
+
* ],
|
23
|
+
* });
|
24
|
+
* console.log(signature);
|
25
|
+
* > 0x24ee0097
|
26
|
+
*
|
27
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('myMethod(uint256,string)')
|
28
|
+
* console.log(signature);
|
29
|
+
* > 0x24ee0097
|
30
|
+
*
|
31
|
+
* const signature = web3.eth.abi.encodeFunctionSignature('safeTransferFrom(address,address,uint256,bytes)');
|
32
|
+
* console.log(signature);
|
33
|
+
* > 0xb88d4fde
|
34
|
+
* ```
|
35
|
+
*/
|
36
|
+
export declare const encodeFunctionSignature: (functionName: string | AbiFunctionFragment) => string;
|
37
|
+
/**
|
38
|
+
* Encodes a function call using its `JSON interface` object and given parameters.
|
39
|
+
* The JSON interface spec documentation https://docs.soliditylang.org/en/latest/abi-spec.html#json
|
40
|
+
* @param jsonInterface - The `JSON interface` object of the function.
|
41
|
+
* @param params - The parameters to encode
|
42
|
+
* @returns - The ABI encoded function call, which, means the function signature and the parameters passed.
|
43
|
+
* @example
|
44
|
+
* ```ts
|
45
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
46
|
+
* {
|
47
|
+
* name: "myMethod",
|
48
|
+
* type: "function",
|
49
|
+
* inputs: [
|
50
|
+
* {
|
51
|
+
* type: "uint256",
|
52
|
+
* name: "myNumber",
|
53
|
+
* },
|
54
|
+
* {
|
55
|
+
* type: "string",
|
56
|
+
* name: "myString",
|
57
|
+
* },
|
58
|
+
* ],
|
59
|
+
* },
|
60
|
+
* ["2345675643", "Hello!%"]
|
61
|
+
* );
|
62
|
+
* console.log(sig);
|
63
|
+
* > 0x24ee0097000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
|
64
|
+
*
|
65
|
+
*
|
66
|
+
*
|
67
|
+
* const sig = web3.eth.abi.encodeFunctionCall(
|
68
|
+
* {
|
69
|
+
* inputs: [
|
70
|
+
* {
|
71
|
+
* name: "account",
|
72
|
+
* type: "address",
|
73
|
+
* },
|
74
|
+
* ],
|
75
|
+
* name: "balanceOf",
|
76
|
+
* outputs: [
|
77
|
+
* {
|
78
|
+
* name: "",
|
79
|
+
* type: "uint256",
|
80
|
+
* },
|
81
|
+
* ],
|
82
|
+
* stateMutability: "view",
|
83
|
+
* type: "function",
|
84
|
+
* },
|
85
|
+
* ["0x1234567890123456789012345678901234567890"]
|
86
|
+
* );
|
87
|
+
*
|
88
|
+
* console.log(sig);
|
89
|
+
* > 0x70a082310000000000000000000000001234567890123456789012345678901234567890
|
90
|
+
* ```
|
91
|
+
*/
|
92
|
+
export declare const encodeFunctionCall: (jsonInterface: AbiFunctionFragment, params: unknown[]) => string;
|
93
|
+
//# sourceMappingURL=functions_api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"functions_api.d.ts","sourceRoot":"","sources":["../../../src/api/functions_api.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAIjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,uBAAuB,iBAAkB,MAAM,GAAG,mBAAmB,KAAG,MAcpF,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,eAAO,MAAM,kBAAkB,kBACf,mBAAmB,UAC1B,OAAO,EAAE,KACf,MASF,CAAC"}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/**
|
2
|
+
*
|
3
|
+
* @module ABI
|
4
|
+
*/
|
5
|
+
import { HexString, AbiParameter, DecodedParams } from 'web3-types';
|
6
|
+
/**
|
7
|
+
* Decodes ABI-encoded log data and indexed topic data.
|
8
|
+
* @param inputs - A {@link AbiParameter} input array. See the [Solidity documentation](https://docs.soliditylang.org/en/develop/types.html) for a list of types.
|
9
|
+
* @param data - The ABI byte code in the `data` field of a log.
|
10
|
+
* @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]
|
11
|
+
* @returns - The result object containing the decoded parameters.
|
12
|
+
*
|
13
|
+
* @example
|
14
|
+
* ```ts
|
15
|
+
* let res = web3.eth.abi.decodeLog(
|
16
|
+
* [
|
17
|
+
* {
|
18
|
+
* type: "string",
|
19
|
+
* name: "myString",
|
20
|
+
* },
|
21
|
+
* {
|
22
|
+
* type: "uint256",
|
23
|
+
* name: "myNumber",
|
24
|
+
* indexed: true,
|
25
|
+
* },
|
26
|
+
* {
|
27
|
+
* type: "uint8",
|
28
|
+
* name: "mySmallNumber",
|
29
|
+
* indexed: true,
|
30
|
+
* },
|
31
|
+
* ],
|
32
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000748656c6c6f252100000000000000000000000000000000000000000000000000",
|
33
|
+
* [
|
34
|
+
* "0x000000000000000000000000000000000000000000000000000000000000f310",
|
35
|
+
* "0x0000000000000000000000000000000000000000000000000000000000000010",
|
36
|
+
* ]
|
37
|
+
* );
|
38
|
+
* > {
|
39
|
+
* '0': 'Hello%!',
|
40
|
+
* '1': 62224n,
|
41
|
+
* '2': 16n,
|
42
|
+
* __length__: 3,
|
43
|
+
* myString: 'Hello%!',
|
44
|
+
* myNumber: 62224n,
|
45
|
+
* mySmallNumber: 16n
|
46
|
+
* }
|
47
|
+
* ```
|
48
|
+
*/
|
49
|
+
export declare const decodeLog: <ReturnType_1 extends DecodedParams>(inputs: Array<AbiParameter> | ReadonlyArray<AbiParameter>, data: HexString, topics: string | string[]) => ReturnType_1;
|
50
|
+
//# sourceMappingURL=logs_api.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logs_api.d.ts","sourceRoot":"","sources":["../../../src/api/logs_api.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAQpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,SAAS,+CACb,MAAM,YAAY,CAAC,GAAG,cAAc,YAAY,CAAC,QACnD,SAAS,UACP,MAAM,GAAG,MAAM,EAAE,iBAsDzB,CAAC"}
|