web3ethabii 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +59 -0
  3. package/lib/commonjs/api/errors_api.d.ts +5 -0
  4. package/lib/commonjs/api/errors_api.js +44 -0
  5. package/lib/commonjs/api/errors_api.js.map +1 -0
  6. package/lib/commonjs/api/events_api.d.ts +51 -0
  7. package/lib/commonjs/api/events_api.js +90 -0
  8. package/lib/commonjs/api/events_api.js.map +1 -0
  9. package/lib/commonjs/api/functions_api.d.ts +92 -0
  10. package/lib/commonjs/api/functions_api.js +139 -0
  11. package/lib/commonjs/api/functions_api.js.map +1 -0
  12. package/lib/commonjs/api/logs_api.d.ts +49 -0
  13. package/lib/commonjs/api/logs_api.js +107 -0
  14. package/lib/commonjs/api/logs_api.js.map +1 -0
  15. package/lib/commonjs/api/parameters_api.d.ts +238 -0
  16. package/lib/commonjs/api/parameters_api.js +280 -0
  17. package/lib/commonjs/api/parameters_api.js.map +1 -0
  18. package/lib/commonjs/coders/base/address.d.ts +4 -0
  19. package/lib/commonjs/coders/base/address.js +75 -0
  20. package/lib/commonjs/coders/base/address.js.map +1 -0
  21. package/lib/commonjs/coders/base/array.d.ts +4 -0
  22. package/lib/commonjs/coders/base/array.js +106 -0
  23. package/lib/commonjs/coders/base/array.js.map +1 -0
  24. package/lib/commonjs/coders/base/bool.d.ts +4 -0
  25. package/lib/commonjs/coders/base/bool.js +56 -0
  26. package/lib/commonjs/coders/base/bool.js.map +1 -0
  27. package/lib/commonjs/coders/base/bytes.d.ts +4 -0
  28. package/lib/commonjs/coders/base/bytes.js +101 -0
  29. package/lib/commonjs/coders/base/bytes.js.map +1 -0
  30. package/lib/commonjs/coders/base/index.d.ts +11 -0
  31. package/lib/commonjs/coders/base/index.js +109 -0
  32. package/lib/commonjs/coders/base/index.js.map +1 -0
  33. package/lib/commonjs/coders/base/number.d.ts +4 -0
  34. package/lib/commonjs/coders/base/number.js +116 -0
  35. package/lib/commonjs/coders/base/number.js.map +1 -0
  36. package/lib/commonjs/coders/base/numbersLimits.d.ts +4 -0
  37. package/lib/commonjs/coders/base/numbersLimits.js +40 -0
  38. package/lib/commonjs/coders/base/numbersLimits.js.map +1 -0
  39. package/lib/commonjs/coders/base/string.d.ts +4 -0
  40. package/lib/commonjs/coders/base/string.js +40 -0
  41. package/lib/commonjs/coders/base/string.js.map +1 -0
  42. package/lib/commonjs/coders/base/tuple.d.ts +7 -0
  43. package/lib/commonjs/coders/base/tuple.js +123 -0
  44. package/lib/commonjs/coders/base/tuple.js.map +1 -0
  45. package/lib/commonjs/coders/base/utils.d.ts +2 -0
  46. package/lib/commonjs/coders/base/utils.js +50 -0
  47. package/lib/commonjs/coders/base/utils.js.map +1 -0
  48. package/lib/commonjs/coders/decode.d.ts +5 -0
  49. package/lib/commonjs/coders/decode.js +29 -0
  50. package/lib/commonjs/coders/decode.js.map +1 -0
  51. package/lib/commonjs/coders/encode.d.ts +38 -0
  52. package/lib/commonjs/coders/encode.js +113 -0
  53. package/lib/commonjs/coders/encode.js.map +1 -0
  54. package/lib/commonjs/coders/types.d.ts +16 -0
  55. package/lib/commonjs/coders/types.js +19 -0
  56. package/lib/commonjs/coders/types.js.map +1 -0
  57. package/lib/commonjs/coders/utils.d.ts +23 -0
  58. package/lib/commonjs/coders/utils.js +115 -0
  59. package/lib/commonjs/coders/utils.js.map +1 -0
  60. package/lib/commonjs/decode_contract_error_data.d.ts +3 -0
  61. package/lib/commonjs/decode_contract_error_data.js +73 -0
  62. package/lib/commonjs/decode_contract_error_data.js.map +1 -0
  63. package/lib/commonjs/eip_712.d.ts +50 -0
  64. package/lib/commonjs/eip_712.js +144 -0
  65. package/lib/commonjs/eip_712.js.map +1 -0
  66. package/lib/commonjs/index.d.ts +8 -0
  67. package/lib/commonjs/index.js +43 -0
  68. package/lib/commonjs/index.js.map +1 -0
  69. package/lib/commonjs/package.json +1 -0
  70. package/lib/commonjs/utils.d.ts +43 -0
  71. package/lib/commonjs/utils.js +216 -0
  72. package/lib/commonjs/utils.js.map +1 -0
  73. package/lib/esm/api/errors_api.js +40 -0
  74. package/lib/esm/api/errors_api.js.map +1 -0
  75. package/lib/esm/api/events_api.js +86 -0
  76. package/lib/esm/api/events_api.js.map +1 -0
  77. package/lib/esm/api/functions_api.js +134 -0
  78. package/lib/esm/api/functions_api.js.map +1 -0
  79. package/lib/esm/api/logs_api.js +103 -0
  80. package/lib/esm/api/logs_api.js.map +1 -0
  81. package/lib/esm/api/parameters_api.js +271 -0
  82. package/lib/esm/api/parameters_api.js.map +1 -0
  83. package/lib/esm/coders/base/address.js +70 -0
  84. package/lib/esm/coders/base/address.js.map +1 -0
  85. package/lib/esm/coders/base/array.js +101 -0
  86. package/lib/esm/coders/base/array.js.map +1 -0
  87. package/lib/esm/coders/base/bool.js +51 -0
  88. package/lib/esm/coders/base/bool.js.map +1 -0
  89. package/lib/esm/coders/base/bytes.js +96 -0
  90. package/lib/esm/coders/base/bytes.js.map +1 -0
  91. package/lib/esm/coders/base/index.js +90 -0
  92. package/lib/esm/coders/base/index.js.map +1 -0
  93. package/lib/esm/coders/base/number.js +111 -0
  94. package/lib/esm/coders/base/number.js.map +1 -0
  95. package/lib/esm/coders/base/numbersLimits.js +37 -0
  96. package/lib/esm/coders/base/numbersLimits.js.map +1 -0
  97. package/lib/esm/coders/base/string.js +35 -0
  98. package/lib/esm/coders/base/string.js.map +1 -0
  99. package/lib/esm/coders/base/tuple.js +118 -0
  100. package/lib/esm/coders/base/tuple.js.map +1 -0
  101. package/lib/esm/coders/base/utils.js +46 -0
  102. package/lib/esm/coders/base/utils.js.map +1 -0
  103. package/lib/esm/coders/decode.js +25 -0
  104. package/lib/esm/coders/decode.js.map +1 -0
  105. package/lib/esm/coders/encode.js +108 -0
  106. package/lib/esm/coders/encode.js.map +1 -0
  107. package/lib/esm/coders/types.js +18 -0
  108. package/lib/esm/coders/types.js.map +1 -0
  109. package/lib/esm/coders/utils.js +105 -0
  110. package/lib/esm/coders/utils.js.map +1 -0
  111. package/lib/esm/decode_contract_error_data.js +69 -0
  112. package/lib/esm/decode_contract_error_data.js.map +1 -0
  113. package/lib/esm/eip_712.js +140 -0
  114. package/lib/esm/eip_712.js.map +1 -0
  115. package/lib/esm/index.js +25 -0
  116. package/lib/esm/index.js.map +1 -0
  117. package/lib/esm/package.json +1 -0
  118. package/lib/esm/utils.js +199 -0
  119. package/lib/esm/utils.js.map +1 -0
  120. package/lib/types/api/errors_api.d.ts +6 -0
  121. package/lib/types/api/errors_api.d.ts.map +1 -0
  122. package/lib/types/api/events_api.d.ts +52 -0
  123. package/lib/types/api/events_api.d.ts.map +1 -0
  124. package/lib/types/api/functions_api.d.ts +93 -0
  125. package/lib/types/api/functions_api.d.ts.map +1 -0
  126. package/lib/types/api/logs_api.d.ts +50 -0
  127. package/lib/types/api/logs_api.d.ts.map +1 -0
  128. package/lib/types/api/parameters_api.d.ts +239 -0
  129. package/lib/types/api/parameters_api.d.ts.map +1 -0
  130. package/lib/types/coders/base/address.d.ts +5 -0
  131. package/lib/types/coders/base/address.d.ts.map +1 -0
  132. package/lib/types/coders/base/array.d.ts +5 -0
  133. package/lib/types/coders/base/array.d.ts.map +1 -0
  134. package/lib/types/coders/base/bool.d.ts +5 -0
  135. package/lib/types/coders/base/bool.d.ts.map +1 -0
  136. package/lib/types/coders/base/bytes.d.ts +5 -0
  137. package/lib/types/coders/base/bytes.d.ts.map +1 -0
  138. package/lib/types/coders/base/index.d.ts +12 -0
  139. package/lib/types/coders/base/index.d.ts.map +1 -0
  140. package/lib/types/coders/base/number.d.ts +5 -0
  141. package/lib/types/coders/base/number.d.ts.map +1 -0
  142. package/lib/types/coders/base/numbersLimits.d.ts +5 -0
  143. package/lib/types/coders/base/numbersLimits.d.ts.map +1 -0
  144. package/lib/types/coders/base/string.d.ts +5 -0
  145. package/lib/types/coders/base/string.d.ts.map +1 -0
  146. package/lib/types/coders/base/tuple.d.ts +8 -0
  147. package/lib/types/coders/base/tuple.d.ts.map +1 -0
  148. package/lib/types/coders/base/utils.d.ts +3 -0
  149. package/lib/types/coders/base/utils.d.ts.map +1 -0
  150. package/lib/types/coders/decode.d.ts +6 -0
  151. package/lib/types/coders/decode.d.ts.map +1 -0
  152. package/lib/types/coders/encode.d.ts +39 -0
  153. package/lib/types/coders/encode.d.ts.map +1 -0
  154. package/lib/types/coders/types.d.ts +17 -0
  155. package/lib/types/coders/types.d.ts.map +1 -0
  156. package/lib/types/coders/utils.d.ts +24 -0
  157. package/lib/types/coders/utils.d.ts.map +1 -0
  158. package/lib/types/decode_contract_error_data.d.ts +4 -0
  159. package/lib/types/decode_contract_error_data.d.ts.map +1 -0
  160. package/lib/types/eip_712.d.ts +51 -0
  161. package/lib/types/eip_712.d.ts.map +1 -0
  162. package/lib/types/index.d.ts +9 -0
  163. package/lib/types/index.d.ts.map +1 -0
  164. package/lib/types/utils.d.ts +44 -0
  165. package/lib/types/utils.d.ts.map +1 -0
  166. package/pa8cztln.cjs +1 -0
  167. package/package.json +56 -0
  168. package/src/api/errors_api.ts +45 -0
  169. package/src/api/events_api.ts +91 -0
  170. package/src/api/functions_api.ts +145 -0
  171. package/src/api/logs_api.ts +131 -0
  172. package/src/api/parameters_api.ts +287 -0
  173. package/src/coders/base/address.ts +75 -0
  174. package/src/coders/base/array.ts +120 -0
  175. package/src/coders/base/bool.ts +54 -0
  176. package/src/coders/base/bytes.ts +106 -0
  177. package/src/coders/base/index.ts +95 -0
  178. package/src/coders/base/number.ts +116 -0
  179. package/src/coders/base/numbersLimits.ts +39 -0
  180. package/src/coders/base/string.ts +38 -0
  181. package/src/coders/base/tuple.ts +130 -0
  182. package/src/coders/base/utils.ts +51 -0
  183. package/src/coders/decode.ts +32 -0
  184. package/src/coders/encode.ts +114 -0
  185. package/src/coders/types.ts +39 -0
  186. package/src/coders/utils.ts +128 -0
  187. package/src/decode_contract_error_data.ts +80 -0
  188. package/src/eip_712.ts +252 -0
  189. package/src/index.ts +25 -0
  190. package/src/utils.ts +266 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../../../src/coders/base/string.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,6CAAuC;AAEvC,2CAAoD;AAEpD,yCAAsD;AAEtD,SAAgB,YAAY,CAAC,MAAoB,EAAE,KAAc;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC9B,MAAM,IAAI,sBAAQ,CAAC,iCAAiC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;KACjE;IACD,MAAM,KAAK,GAAG,IAAA,wBAAW,EAAC,KAAK,CAAC,CAAC;IACjC,OAAO,IAAA,sBAAW,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;AACxD,CAAC;AAND,oCAMC;AAED,SAAgB,YAAY,CAAC,MAAoB,EAAE,KAAiB;IACnE,MAAM,CAAC,GAAG,IAAA,sBAAW,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;IAC1D,OAAO;QACN,MAAM,EAAE,IAAA,sBAAS,EAAC,CAAC,CAAC,MAAM,CAAC;QAC3B,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,QAAQ;KACpB,CAAC;AACH,CAAC;AAPD,oCAOC"}
@@ -0,0 +1,7 @@
1
+ import { AbiParameter } from 'web3-types';
2
+ import { DecoderResult, EncoderResult } from '../types.js';
3
+ export declare function encodeTuple(param: AbiParameter, input: unknown): EncoderResult;
4
+ export declare function decodeTuple(param: AbiParameter, bytes: Uint8Array): DecoderResult<{
5
+ [key: string]: unknown;
6
+ __length__: number;
7
+ }>;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeTuple = exports.encodeTuple = 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 utils_js_2 = require("../utils.js");
26
+ const number_js_1 = require("./number.js");
27
+ function encodeTuple(param, input) {
28
+ var _a, _b, _c;
29
+ let dynamic = false;
30
+ if (!Array.isArray(input) && typeof input !== 'object') {
31
+ throw new web3_errors_1.AbiError('param must be either Array or Object', {
32
+ param,
33
+ input,
34
+ });
35
+ }
36
+ const narrowedInput = input;
37
+ const encoded = [];
38
+ for (let i = 0; i < ((_b = (_a = param.components) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0); i += 1) {
39
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40
+ const paramComponent = param.components[i];
41
+ let result;
42
+ if (Array.isArray(narrowedInput)) {
43
+ if (i >= narrowedInput.length) {
44
+ throw new web3_errors_1.AbiError('input param length missmatch', {
45
+ param,
46
+ input,
47
+ });
48
+ }
49
+ result = (0, index_js_1.encodeParamFromAbiParameter)(paramComponent, narrowedInput[i]);
50
+ }
51
+ else {
52
+ const paramInput = narrowedInput[(_c = paramComponent.name) !== null && _c !== void 0 ? _c : ''];
53
+ // eslint-disable-next-line no-null/no-null
54
+ if (paramInput === undefined || paramInput === null) {
55
+ throw new web3_errors_1.AbiError('missing input defined in abi', {
56
+ param,
57
+ input,
58
+ paramName: paramComponent.name,
59
+ });
60
+ }
61
+ result = (0, index_js_1.encodeParamFromAbiParameter)(paramComponent, paramInput);
62
+ }
63
+ if (result.dynamic) {
64
+ dynamic = true;
65
+ }
66
+ encoded.push(result);
67
+ }
68
+ if (dynamic) {
69
+ return {
70
+ dynamic: true,
71
+ encoded: (0, utils_js_1.encodeDynamicParams)(encoded),
72
+ };
73
+ }
74
+ return {
75
+ dynamic: false,
76
+ encoded: (0, web3_utils_1.uint8ArrayConcat)(...encoded.map(e => e.encoded)),
77
+ };
78
+ }
79
+ exports.encodeTuple = encodeTuple;
80
+ function decodeTuple(param, bytes) {
81
+ const result = {
82
+ __length__: 0,
83
+ };
84
+ // tracks how much static params consumed bytes
85
+ let consumed = 0;
86
+ if (!param.components) {
87
+ return {
88
+ result,
89
+ encoded: bytes,
90
+ consumed,
91
+ };
92
+ }
93
+ // track how much dynamic params consumed bytes
94
+ let dynamicConsumed = 0;
95
+ for (const [index, childParam] of param.components.entries()) {
96
+ let decodedResult;
97
+ if ((0, utils_js_2.isDynamic)(childParam)) {
98
+ // if dynamic, we will have offset encoded
99
+ const offsetResult = (0, number_js_1.decodeNumber)({ type: 'uint32', name: '' }, bytes.subarray(consumed));
100
+ // offset counts from start of original byte sequence
101
+ decodedResult = (0, index_js_1.decodeParamFromAbiParameter)(childParam, bytes.subarray(Number(offsetResult.result)));
102
+ consumed += offsetResult.consumed;
103
+ dynamicConsumed += decodedResult.consumed;
104
+ }
105
+ else {
106
+ // static param, just decode
107
+ decodedResult = (0, index_js_1.decodeParamFromAbiParameter)(childParam, bytes.subarray(consumed));
108
+ consumed += decodedResult.consumed;
109
+ }
110
+ result.__length__ += 1;
111
+ result[index] = decodedResult.result;
112
+ if (childParam.name && childParam.name !== '') {
113
+ result[childParam.name] = decodedResult.result;
114
+ }
115
+ }
116
+ return {
117
+ encoded: bytes.subarray(consumed + dynamicConsumed),
118
+ result,
119
+ consumed: consumed + dynamicConsumed,
120
+ };
121
+ }
122
+ exports.decodeTuple = decodeTuple;
123
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../../src/coders/base/tuple.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,6CAAuC;AAEvC,2CAA8C;AAE9C,2CAA2C;AAC3C,yCAAsF;AACtF,yCAAiD;AACjD,0CAAwC;AACxC,2CAA2C;AAE3C,SAAgB,WAAW,CAAC,KAAmB,EAAE,KAAc;;IAC9D,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACvD,MAAM,IAAI,sBAAQ,CAAC,sCAAsC,EAAE;YAC1D,KAAK;YACL,KAAK;SACL,CAAC,CAAC;KACH;IACD,MAAM,aAAa,GAAG,KAAiD,CAAC;IACxE,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAA,MAAA,KAAK,CAAC,UAAU,0CAAE,MAAM,mCAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QAC5D,oEAAoE;QACpE,MAAM,cAAc,GAAG,KAAK,CAAC,UAAW,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,MAAqB,CAAC;QAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;YACjC,IAAI,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE;gBAC9B,MAAM,IAAI,sBAAQ,CAAC,8BAA8B,EAAE;oBAClD,KAAK;oBACL,KAAK;iBACL,CAAC,CAAC;aACH;YACD,MAAM,GAAG,IAAA,sCAA2B,EAAC,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;SACvE;aAAM;YACN,MAAM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IAAI,aAA4B,CAAC;QACjC,IAAI,IAAA,oBAAS,EAAC,UAAU,CAAC,EAAE;YAC1B,0CAA0C;YAC1C,MAAM,YAAY,GAAG,IAAA,wBAAY,EAChC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,EAC5B,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CACxB,CAAC;YACF,qDAAqD;YACrD,aAAa,GAAG,IAAA,sCAA2B,EAC1C,UAAU,EACV,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAC3C,CAAC;YACF,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC;YAClC,eAAe,IAAI,aAAa,CAAC,QAAQ,CAAC;SAC1C;aAAM;YACN,4BAA4B;YAC5B,aAAa,GAAG,IAAA,sCAA2B,EAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;YAClF,QAAQ,IAAI,aAAa,CAAC,QAAQ,CAAC;SACnC;QACD,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;QACvB,MAAM,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC;QACrC,IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,KAAK,EAAE,EAAE;YAC9C,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,MAAM,CAAC;SAC/C;KACD;IACD,OAAO;QACN,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAAC;QACnD,MAAM;QACN,QAAQ,EAAE,QAAQ,GAAG,eAAe;KACpC,CAAC;AACH,CAAC;AAnDD,kCAmDC"}
@@ -0,0 +1,2 @@
1
+ import { EncoderResult } from '../types.js';
2
+ export declare function encodeDynamicParams(encodedParams: ReadonlyArray<EncoderResult>): Uint8Array;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeDynamicParams = 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_utils_1 = require("web3-utils");
21
+ const utils_js_1 = require("../utils.js");
22
+ const number_js_1 = require("./number.js");
23
+ function encodeDynamicParams(encodedParams) {
24
+ let staticSize = 0;
25
+ let dynamicSize = 0;
26
+ const staticParams = [];
27
+ const dynamicParams = [];
28
+ // figure out static size
29
+ for (const encodedParam of encodedParams) {
30
+ if (encodedParam.dynamic) {
31
+ staticSize += utils_js_1.WORD_SIZE;
32
+ }
33
+ else {
34
+ staticSize += encodedParam.encoded.length;
35
+ }
36
+ }
37
+ for (const encodedParam of encodedParams) {
38
+ if (encodedParam.dynamic) {
39
+ staticParams.push((0, number_js_1.encodeNumber)({ type: 'uint256', name: '' }, staticSize + dynamicSize));
40
+ dynamicParams.push(encodedParam);
41
+ dynamicSize += encodedParam.encoded.length;
42
+ }
43
+ else {
44
+ staticParams.push(encodedParam);
45
+ }
46
+ }
47
+ return (0, web3_utils_1.uint8ArrayConcat)(...staticParams.map(p => p.encoded), ...dynamicParams.map(p => p.encoded));
48
+ }
49
+ exports.encodeDynamicParams = encodeDynamicParams;
50
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/coders/base/utils.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,2CAA8C;AAE9C,0CAAwC;AACxC,2CAA2C;AAE3C,SAAgB,mBAAmB,CAAC,aAA2C;IAC9E,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,YAAY,GAAoB,EAAE,CAAC;IACzC,MAAM,aAAa,GAAoB,EAAE,CAAC;IAC1C,yBAAyB;IACzB,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QACzC,IAAI,YAAY,CAAC,OAAO,EAAE;YACzB,UAAU,IAAI,oBAAS,CAAC;SACxB;aAAM;YACN,UAAU,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC;SAC1C;KACD;IAED,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QACzC,IAAI,YAAY,CAAC,OAAO,EAAE;YACzB,YAAY,CAAC,IAAI,CAChB,IAAA,wBAAY,EAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,UAAU,GAAG,WAAW,CAAC,CACrE,CAAC;YACF,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACjC,WAAW,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC;SAC3C;aAAM;YACN,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SAChC;KACD;IACD,OAAO,IAAA,6BAAgB,EACtB,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EACnC,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CACpC,CAAC;AACH,CAAC;AA7BD,kDA6BC"}
@@ -0,0 +1,5 @@
1
+ import { AbiInput, HexString } from 'web3-types';
2
+ export declare function decodeParameters(abis: AbiInput[] | ReadonlyArray<AbiInput>, bytes: HexString, _loose: boolean): {
3
+ [key: string]: unknown;
4
+ __length__: number;
5
+ };
@@ -0,0 +1,29 @@
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.decodeParameters = void 0;
20
+ const web3_validator_1 = require("web3-validator");
21
+ const tuple_js_1 = require("./base/tuple.js");
22
+ const utils_js_1 = require("./utils.js");
23
+ function decodeParameters(abis, bytes, _loose) {
24
+ const abiParams = (0, utils_js_1.toAbiParams)(abis);
25
+ const bytesArray = web3_validator_1.utils.hexToUint8Array(bytes);
26
+ return (0, tuple_js_1.decodeTuple)({ type: 'tuple', name: '', components: abiParams }, bytesArray).result;
27
+ }
28
+ exports.decodeParameters = decodeParameters;
29
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../../src/coders/decode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAGF,mDAAuC;AACvC,8CAA8C;AAC9C,yCAAyC;AAEzC,SAAgB,gBAAgB,CAC/B,IAA0C,EAC1C,KAAgB,EAChB,MAAe;IAEf,MAAM,SAAS,GAAG,IAAA,sBAAW,EAAC,IAAI,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,sBAAK,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEhD,OAAO,IAAA,sBAAW,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC,MAAM,CAAC;AAC3F,CAAC;AATD,4CASC"}
@@ -0,0 +1,38 @@
1
+ import { AbiInput } from 'web3-types';
2
+ /**
3
+ * Encodes a parameter based on its type to its ABI representation.
4
+ * @param abi - An array of {@link AbiInput}. See [Solidity's documentation](https://solidity.readthedocs.io/en/v0.5.3/abi-spec.html#json) for more details.
5
+ * @param params - The actual parameters to encode.
6
+ * @returns - The ABI encoded parameters
7
+ * @example
8
+ * ```ts
9
+ * const res = web3.eth.abi.encodeParameters(
10
+ * ["uint256", "string"],
11
+ * ["2345675643", "Hello!%"]
12
+ * );
13
+ *
14
+ * console.log(res);
15
+ * > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
16
+ * ```
17
+ */
18
+ export declare function encodeParameters(abi: ReadonlyArray<AbiInput>, params: unknown[]): string;
19
+ /**
20
+ * Infer a smart contract method parameter type and then encode this parameter.
21
+ * @param params - The parameters to encode.
22
+ * @returns - The ABI encoded parameters
23
+ *
24
+ * @remarks
25
+ * This method is useful when you don't know the type of the parameters you want to encode. It will infer the type of the parameters and then encode them.
26
+ * However, it is not recommended to use this method when you know the type of the parameters you want to encode. In this case, use the {@link encodeParameters} method instead.
27
+ * The type inference is not perfect and can lead to unexpected results. Especially when you want to encode an array, uint that is not uint256 or bytes....
28
+ * @example
29
+ * ```ts
30
+ * const res = web3.eth.abi.encodeParameters(
31
+ * ["2345675643", "Hello!%"]
32
+ * );
33
+ *
34
+ * console.log(res);
35
+ * > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
36
+ * ```
37
+ */
38
+ export declare function inferTypesAndEncodeParameters(params: unknown[]): string;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.inferTypesAndEncodeParameters = exports.encodeParameters = 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 index_js_1 = require("./base/index.js");
24
+ const utils_js_1 = require("./utils.js");
25
+ /**
26
+ * @param params - The params to infer the ABI from
27
+ * @returns The inferred ABI
28
+ * @example
29
+ * ```
30
+ * inferParamsAbi([1, -1, 'hello', '0x1234', ])
31
+ * ```
32
+ * > [{ type: 'int256' }, { type: 'uint256' }, { type: 'string' }, { type: 'bytes' }]
33
+ * ```
34
+ */
35
+ function inferParamsAbi(params) {
36
+ const abi = [];
37
+ params.forEach(param => {
38
+ if (Array.isArray(param)) {
39
+ const inferredParams = inferParamsAbi(param);
40
+ abi.push({
41
+ type: 'tuple',
42
+ components: inferredParams,
43
+ name: '',
44
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
45
+ });
46
+ }
47
+ else {
48
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
49
+ abi.push({ type: (0, web3_utils_1.toHex)(param, true) });
50
+ }
51
+ });
52
+ return abi;
53
+ }
54
+ /**
55
+ * Encodes a parameter based on its type to its ABI representation.
56
+ * @param abi - An array of {@link AbiInput}. See [Solidity's documentation](https://solidity.readthedocs.io/en/v0.5.3/abi-spec.html#json) for more details.
57
+ * @param params - The actual parameters to encode.
58
+ * @returns - The ABI encoded parameters
59
+ * @example
60
+ * ```ts
61
+ * const res = web3.eth.abi.encodeParameters(
62
+ * ["uint256", "string"],
63
+ * ["2345675643", "Hello!%"]
64
+ * );
65
+ *
66
+ * console.log(res);
67
+ * > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
68
+ * ```
69
+ */
70
+ function encodeParameters(abi, params) {
71
+ if ((abi === null || abi === void 0 ? void 0 : abi.length) !== params.length) {
72
+ throw new web3_errors_1.AbiError('Invalid number of values received for given ABI', {
73
+ expected: abi === null || abi === void 0 ? void 0 : abi.length,
74
+ received: params.length,
75
+ });
76
+ }
77
+ const abiParams = (0, utils_js_1.toAbiParams)(abi);
78
+ return web3_validator_1.utils.uint8ArrayToHexString((0, index_js_1.encodeTuple)({ type: 'tuple', name: '', components: abiParams }, params).encoded);
79
+ }
80
+ exports.encodeParameters = encodeParameters;
81
+ /**
82
+ * Infer a smart contract method parameter type and then encode this parameter.
83
+ * @param params - The parameters to encode.
84
+ * @returns - The ABI encoded parameters
85
+ *
86
+ * @remarks
87
+ * This method is useful when you don't know the type of the parameters you want to encode. It will infer the type of the parameters and then encode them.
88
+ * However, it is not recommended to use this method when you know the type of the parameters you want to encode. In this case, use the {@link encodeParameters} method instead.
89
+ * The type inference is not perfect and can lead to unexpected results. Especially when you want to encode an array, uint that is not uint256 or bytes....
90
+ * @example
91
+ * ```ts
92
+ * const res = web3.eth.abi.encodeParameters(
93
+ * ["2345675643", "Hello!%"]
94
+ * );
95
+ *
96
+ * console.log(res);
97
+ * > 0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000
98
+ * ```
99
+ */
100
+ function inferTypesAndEncodeParameters(params) {
101
+ try {
102
+ const abiParams = inferParamsAbi(params);
103
+ return web3_validator_1.utils.uint8ArrayToHexString((0, index_js_1.encodeTuple)({ type: 'tuple', name: '', components: abiParams }, params).encoded);
104
+ }
105
+ catch (e) {
106
+ // throws If the inferred params type caused an error
107
+ throw new web3_errors_1.AbiError('Could not infer types from given params', {
108
+ params,
109
+ });
110
+ }
111
+ }
112
+ exports.inferTypesAndEncodeParameters = inferTypesAndEncodeParameters;
113
+ //# sourceMappingURL=encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.js","sourceRoot":"","sources":["../../../src/coders/encode.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;EAeE;AACF,6CAAuC;AAEvC,2CAAmC;AACnC,mDAAuC;AACvC,8CAA8C;AAC9C,yCAAyC;AAEzC;;;;;;;;;GASG;AACH,SAAS,cAAc,CAAC,MAAiB;IACxC,MAAM,GAAG,GAAmB,EAAE,CAAC;IAC/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACtB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACzB,MAAM,cAAc,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YAC7C,GAAG,CAAC,IAAI,CAAC;gBACR,IAAI,EAAE,OAAO;gBACb,UAAU,EAAE,cAAc;gBAC1B,IAAI,EAAE,EAAE;gBACR,iEAAiE;aACjD,CAAC,CAAC;SACnB;aAAM;YACN,iEAAiE;YACjE,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAA,kBAAK,EAAC,KAAY,EAAE,IAAI,CAAC,EAAkB,CAAC,CAAC;SAC9D;IACF,CAAC,CAAC,CAAC;IACH,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,gBAAgB,CAAC,GAA4B,EAAE,MAAiB;IAC/E,IAAI,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,MAAK,MAAM,CAAC,MAAM,EAAE;QAClC,MAAM,IAAI,sBAAQ,CAAC,iDAAiD,EAAE;YACrE,QAAQ,EAAE,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,MAAM;SACvB,CAAC,CAAC;KACH;IAED,MAAM,SAAS,GAAG,IAAA,sBAAW,EAAC,GAAG,CAAC,CAAC;IACnC,OAAO,sBAAK,CAAC,qBAAqB,CACjC,IAAA,sBAAW,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,OAAO,CAC/E,CAAC;AACH,CAAC;AAZD,4CAYC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,6BAA6B,CAAC,MAAiB;IAC9D,IAAI;QACH,MAAM,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,sBAAK,CAAC,qBAAqB,CACjC,IAAA,sBAAW,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC,OAAO,CAC/E,CAAC;KACF;IAAC,OAAO,CAAC,EAAE;QACX,qDAAqD;QACrD,MAAM,IAAI,sBAAQ,CAAC,yCAAyC,EAAE;YAC7D,MAAM;SACN,CAAC,CAAC;KACH;AACF,CAAC;AAZD,sEAYC"}
@@ -0,0 +1,16 @@
1
+ export declare type EncoderResult = {
2
+ dynamic: boolean;
3
+ encoded: Uint8Array;
4
+ };
5
+ export declare type DecoderResult<T = unknown> = {
6
+ result: T;
7
+ encoded: Uint8Array;
8
+ consumed: number;
9
+ };
10
+ export declare type NumberType = {
11
+ signed: boolean;
12
+ byteLength: number;
13
+ };
14
+ export declare type BytesType = {
15
+ size?: number;
16
+ };
@@ -0,0 +1,19 @@
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
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/coders/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE"}
@@ -0,0 +1,23 @@
1
+ import { AbiParameter as ExternalAbiParameter } from 'abitype';
2
+ import { AbiInput, AbiParameter } from 'web3-types';
3
+ export declare const WORD_SIZE = 32;
4
+ export declare function alloc(size?: number): Uint8Array;
5
+ /**
6
+ * Where possible returns a Uint8Array of the requested size that references
7
+ * uninitialized memory. Only use if you are certain you will immediately
8
+ * overwrite every value in the returned `Uint8Array`.
9
+ */
10
+ export declare function allocUnsafe(size?: number): Uint8Array;
11
+ export declare function convertExternalAbiParameter(abiParam: ExternalAbiParameter): AbiParameter;
12
+ export declare function isAbiParameter(param: unknown): param is AbiParameter;
13
+ export declare function toAbiParams(abi: ReadonlyArray<AbiInput>): ReadonlyArray<AbiParameter>;
14
+ export declare function extractArrayType(param: AbiParameter): {
15
+ size: number;
16
+ param: AbiParameter;
17
+ };
18
+ /**
19
+ * Param is dynamic if it's dynamic base type or if some of his children (components, array items)
20
+ * is of dynamic type
21
+ * @param param
22
+ */
23
+ export declare function isDynamic(param: AbiParameter): boolean;
@@ -0,0 +1,115 @@
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.isDynamic = exports.extractArrayType = exports.toAbiParams = exports.isAbiParameter = exports.convertExternalAbiParameter = exports.allocUnsafe = exports.alloc = exports.WORD_SIZE = void 0;
20
+ const abitype_1 = require("abitype");
21
+ const web3_errors_1 = require("web3-errors");
22
+ const web3_utils_1 = require("web3-utils");
23
+ const utils_js_1 = require("../utils.js");
24
+ exports.WORD_SIZE = 32;
25
+ function alloc(size = 0) {
26
+ var _a;
27
+ if (((_a = globalThis.Buffer) === null || _a === void 0 ? void 0 : _a.alloc) !== undefined) {
28
+ const buf = globalThis.Buffer.alloc(size);
29
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
30
+ }
31
+ return new Uint8Array(size);
32
+ }
33
+ exports.alloc = alloc;
34
+ /**
35
+ * Where possible returns a Uint8Array of the requested size that references
36
+ * uninitialized memory. Only use if you are certain you will immediately
37
+ * overwrite every value in the returned `Uint8Array`.
38
+ */
39
+ function allocUnsafe(size = 0) {
40
+ var _a;
41
+ if (((_a = globalThis.Buffer) === null || _a === void 0 ? void 0 : _a.allocUnsafe) !== undefined) {
42
+ const buf = globalThis.Buffer.allocUnsafe(size);
43
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
44
+ }
45
+ return new Uint8Array(size);
46
+ }
47
+ exports.allocUnsafe = allocUnsafe;
48
+ function convertExternalAbiParameter(abiParam) {
49
+ var _a, _b;
50
+ return Object.assign(Object.assign({}, abiParam), { name: (_a = abiParam.name) !== null && _a !== void 0 ? _a : '', components: (_b = abiParam.components) === null || _b === void 0 ? void 0 : _b.map(c => convertExternalAbiParameter(c)) });
51
+ }
52
+ exports.convertExternalAbiParameter = convertExternalAbiParameter;
53
+ function isAbiParameter(param) {
54
+ return (!(0, web3_utils_1.isNullish)(param) &&
55
+ typeof param === 'object' &&
56
+ !(0, web3_utils_1.isNullish)(param.type) &&
57
+ typeof param.type === 'string');
58
+ }
59
+ exports.isAbiParameter = isAbiParameter;
60
+ function toAbiParams(abi) {
61
+ return abi.map(input => {
62
+ var _a;
63
+ if (isAbiParameter(input)) {
64
+ return input;
65
+ }
66
+ if (typeof input === 'string') {
67
+ return convertExternalAbiParameter((0, abitype_1.parseAbiParameter)(input.replace(/tuple/, '')));
68
+ }
69
+ if ((0, utils_js_1.isSimplifiedStructFormat)(input)) {
70
+ const structName = Object.keys(input)[0];
71
+ const structInfo = (0, utils_js_1.mapStructNameAndType)(structName);
72
+ structInfo.name = (_a = structInfo.name) !== null && _a !== void 0 ? _a : '';
73
+ return Object.assign(Object.assign({}, structInfo), { components: (0, utils_js_1.mapStructToCoderFormat)(input[structName]) });
74
+ }
75
+ throw new web3_errors_1.AbiError('Invalid abi');
76
+ });
77
+ }
78
+ exports.toAbiParams = toAbiParams;
79
+ function extractArrayType(param) {
80
+ const arrayParenthesisStart = param.type.lastIndexOf('[');
81
+ const arrayParamType = param.type.substring(0, arrayParenthesisStart);
82
+ const sizeString = param.type.substring(arrayParenthesisStart);
83
+ let size = -1;
84
+ if (sizeString !== '[]') {
85
+ size = Number(sizeString.slice(1, -1));
86
+ // eslint-disable-next-line no-restricted-globals
87
+ if (isNaN(size)) {
88
+ throw new web3_errors_1.AbiError('Invalid fixed array size', { size: sizeString });
89
+ }
90
+ }
91
+ return {
92
+ param: { type: arrayParamType, name: '', components: param.components },
93
+ size,
94
+ };
95
+ }
96
+ exports.extractArrayType = extractArrayType;
97
+ /**
98
+ * Param is dynamic if it's dynamic base type or if some of his children (components, array items)
99
+ * is of dynamic type
100
+ * @param param
101
+ */
102
+ function isDynamic(param) {
103
+ var _a, _b;
104
+ if (param.type === 'string' || param.type === 'bytes' || param.type.endsWith('[]'))
105
+ return true;
106
+ if (param.type === 'tuple') {
107
+ return (_b = (_a = param.components) === null || _a === void 0 ? void 0 : _a.some(isDynamic)) !== null && _b !== void 0 ? _b : false;
108
+ }
109
+ if (param.type.endsWith(']')) {
110
+ return isDynamic(extractArrayType(param).param);
111
+ }
112
+ return false;
113
+ }
114
+ exports.isDynamic = isDynamic;
115
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/coders/utils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF,qCAAkF;AAClF,6CAAuC;AAEvC,2CAAuC;AACvC,0CAIqB;AAER,QAAA,SAAS,GAAG,EAAE,CAAC;AAE5B,SAAgB,KAAK,CAAC,IAAI,GAAG,CAAC;;IAC7B,IAAI,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,KAAK,MAAK,SAAS,EAAE;QAC3C,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;KAClE;IAED,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAPD,sBAOC;AAED;;;;GAIG;AACH,SAAgB,WAAW,CAAC,IAAI,GAAG,CAAC;;IACnC,IAAI,CAAA,MAAA,UAAU,CAAC,MAAM,0CAAE,WAAW,MAAK,SAAS,EAAE;QACjD,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAChD,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,UAAU,CAAC,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CAAC,UAAU,0CAAE,IAAI,CAAC,SAAS,CAAC,mCAAI,KAAK,CAAC;KAClD;IACD,IAAI,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC7B,OAAO,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC;KAChD;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AATD,8BASC"}
@@ -0,0 +1,3 @@
1
+ import { Eip838ExecutionError } from 'web3-errors';
2
+ import { AbiErrorFragment } from 'web3-types';
3
+ export declare const decodeContractErrorData: (errorsAbi: AbiErrorFragment[], error: Eip838ExecutionError) => void;