@waku/rln 0.1.5-bc093d3.0 → 0.1.5-d17562d.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 (119) hide show
  1. package/bundle/index.js +2 -1
  2. package/bundle/packages/rln/dist/contract/constants.js +5 -1
  3. package/bundle/packages/rln/dist/contract/rln_base_contract.js +33 -35
  4. package/bundle/packages/rln/dist/contract/rln_contract.js +1 -1
  5. package/bundle/packages/rln/dist/utils/bytes.js +8 -2
  6. package/bundle/packages/rln/dist/utils/metamask.js +2 -2
  7. package/dist/.tsbuildinfo +1 -1
  8. package/dist/contract/index.d.ts +1 -0
  9. package/dist/contract/index.js +1 -0
  10. package/dist/contract/index.js.map +1 -1
  11. package/dist/contract/rln_base_contract.d.ts +4 -4
  12. package/dist/contract/rln_base_contract.js +31 -33
  13. package/dist/contract/rln_base_contract.js.map +1 -1
  14. package/dist/index.d.ts +2 -1
  15. package/dist/index.js +1 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/keystore/keystore.js.map +1 -1
  18. package/dist/keystore/types.d.ts +2 -2
  19. package/dist/utils/bytes.js +8 -2
  20. package/dist/utils/bytes.js.map +1 -1
  21. package/package.json +1 -1
  22. package/src/contract/index.ts +1 -0
  23. package/src/contract/rln_base_contract.ts +47 -47
  24. package/src/index.ts +3 -1
  25. package/src/keystore/keystore.ts +4 -2
  26. package/src/keystore/types.ts +2 -2
  27. package/src/utils/bytes.ts +10 -2
  28. package/bundle/_virtual/__node-resolve_empty.js +0 -6
  29. package/bundle/_virtual/_node-resolve_empty.js +0 -3
  30. package/bundle/_virtual/bn.js +0 -3
  31. package/bundle/_virtual/common.js +0 -3
  32. package/bundle/_virtual/common2.js +0 -3
  33. package/bundle/_virtual/hash.js +0 -3
  34. package/bundle/_virtual/inherits_browser.js +0 -3
  35. package/bundle/_virtual/ripemd.js +0 -3
  36. package/bundle/_virtual/sha.js +0 -3
  37. package/bundle/_virtual/sha3.js +0 -3
  38. package/bundle/_virtual/utils3.js +0 -3
  39. package/bundle/node_modules/@ethersproject/abi/lib.esm/_version.js +0 -3
  40. package/bundle/node_modules/@ethersproject/abi/lib.esm/abi-coder.js +0 -96
  41. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/abstract-coder.js +0 -148
  42. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/address.js +0 -26
  43. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/anonymous.js +0 -20
  44. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/array.js +0 -210
  45. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/boolean.js +0 -18
  46. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/bytes.js +0 -30
  47. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/fixed-bytes.js +0 -26
  48. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/null.js +0 -22
  49. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/number.js +0 -43
  50. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/string.js +0 -19
  51. package/bundle/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js +0 -58
  52. package/bundle/node_modules/@ethersproject/abi/lib.esm/fragments.js +0 -854
  53. package/bundle/node_modules/@ethersproject/abi/lib.esm/interface.js +0 -609
  54. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/_version.js +0 -3
  55. package/bundle/node_modules/@ethersproject/abstract-provider/lib.esm/index.js +0 -66
  56. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/_version.js +0 -3
  57. package/bundle/node_modules/@ethersproject/abstract-signer/lib.esm/index.js +0 -302
  58. package/bundle/node_modules/@ethersproject/address/lib.esm/_version.js +0 -3
  59. package/bundle/node_modules/@ethersproject/address/lib.esm/index.js +0 -110
  60. package/bundle/node_modules/@ethersproject/base64/lib.esm/base64.js +0 -20
  61. package/bundle/node_modules/@ethersproject/basex/lib.esm/index.js +0 -120
  62. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/_version.js +0 -3
  63. package/bundle/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js +0 -287
  64. package/bundle/node_modules/@ethersproject/bytes/lib.esm/_version.js +0 -3
  65. package/bundle/node_modules/@ethersproject/bytes/lib.esm/index.js +0 -402
  66. package/bundle/node_modules/@ethersproject/constants/lib.esm/addresses.js +0 -3
  67. package/bundle/node_modules/@ethersproject/constants/lib.esm/bignumbers.js +0 -8
  68. package/bundle/node_modules/@ethersproject/constants/lib.esm/hashes.js +0 -3
  69. package/bundle/node_modules/@ethersproject/contracts/lib.esm/_version.js +0 -3
  70. package/bundle/node_modules/@ethersproject/contracts/lib.esm/index.js +0 -893
  71. package/bundle/node_modules/@ethersproject/hash/lib.esm/_version.js +0 -3
  72. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/decoder.js +0 -256
  73. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/include.js +0 -36
  74. package/bundle/node_modules/@ethersproject/hash/lib.esm/ens-normalize/lib.js +0 -135
  75. package/bundle/node_modules/@ethersproject/hash/lib.esm/id.js +0 -8
  76. package/bundle/node_modules/@ethersproject/hash/lib.esm/namehash.js +0 -64
  77. package/bundle/node_modules/@ethersproject/hash/lib.esm/typed-data.js +0 -443
  78. package/bundle/node_modules/@ethersproject/keccak256/lib.esm/index.js +0 -8
  79. package/bundle/node_modules/@ethersproject/keccak256/node_modules/js-sha3/src/sha3.js +0 -660
  80. package/bundle/node_modules/@ethersproject/logger/lib.esm/_version.js +0 -3
  81. package/bundle/node_modules/@ethersproject/logger/lib.esm/index.js +0 -352
  82. package/bundle/node_modules/@ethersproject/networks/lib.esm/_version.js +0 -3
  83. package/bundle/node_modules/@ethersproject/networks/lib.esm/index.js +0 -248
  84. package/bundle/node_modules/@ethersproject/properties/lib.esm/_version.js +0 -3
  85. package/bundle/node_modules/@ethersproject/properties/lib.esm/index.js +0 -127
  86. package/bundle/node_modules/@ethersproject/providers/lib.esm/_version.js +0 -3
  87. package/bundle/node_modules/@ethersproject/providers/lib.esm/base-provider.js +0 -2007
  88. package/bundle/node_modules/@ethersproject/providers/lib.esm/formatter.js +0 -422
  89. package/bundle/node_modules/@ethersproject/providers/lib.esm/json-rpc-provider.js +0 -674
  90. package/bundle/node_modules/@ethersproject/providers/lib.esm/web3-provider.js +0 -132
  91. package/bundle/node_modules/@ethersproject/rlp/lib.esm/_version.js +0 -3
  92. package/bundle/node_modules/@ethersproject/rlp/lib.esm/index.js +0 -120
  93. package/bundle/node_modules/@ethersproject/sha2/lib.esm/sha2.js +0 -8
  94. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/_version.js +0 -3
  95. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/elliptic.js +0 -2430
  96. package/bundle/node_modules/@ethersproject/signing-key/lib.esm/index.js +0 -76
  97. package/bundle/node_modules/@ethersproject/strings/lib.esm/_version.js +0 -3
  98. package/bundle/node_modules/@ethersproject/strings/lib.esm/utf8.js +0 -219
  99. package/bundle/node_modules/@ethersproject/transactions/lib.esm/_version.js +0 -3
  100. package/bundle/node_modules/@ethersproject/transactions/lib.esm/index.js +0 -279
  101. package/bundle/node_modules/@ethersproject/web/lib.esm/_version.js +0 -3
  102. package/bundle/node_modules/@ethersproject/web/lib.esm/geturl.js +0 -69
  103. package/bundle/node_modules/@ethersproject/web/lib.esm/index.js +0 -404
  104. package/bundle/node_modules/bech32/index.js +0 -187
  105. package/bundle/node_modules/bn.js/lib/bn.js +0 -3361
  106. package/bundle/node_modules/hash.js/lib/hash/common.js +0 -97
  107. package/bundle/node_modules/hash.js/lib/hash/hmac.js +0 -51
  108. package/bundle/node_modules/hash.js/lib/hash/ripemd.js +0 -152
  109. package/bundle/node_modules/hash.js/lib/hash/sha/1.js +0 -81
  110. package/bundle/node_modules/hash.js/lib/hash/sha/224.js +0 -33
  111. package/bundle/node_modules/hash.js/lib/hash/sha/256.js +0 -113
  112. package/bundle/node_modules/hash.js/lib/hash/sha/384.js +0 -39
  113. package/bundle/node_modules/hash.js/lib/hash/sha/512.js +0 -336
  114. package/bundle/node_modules/hash.js/lib/hash/sha/common.js +0 -53
  115. package/bundle/node_modules/hash.js/lib/hash/sha.js +0 -14
  116. package/bundle/node_modules/hash.js/lib/hash/utils.js +0 -282
  117. package/bundle/node_modules/hash.js/lib/hash.js +0 -33
  118. package/bundle/node_modules/inherits/inherits_browser.js +0 -33
  119. package/bundle/node_modules/minimalistic-assert/index.js +0 -13
@@ -1,854 +0,0 @@
1
- import { defineReadOnly } from '../../properties/lib.esm/index.js';
2
- import { Logger } from '../../logger/lib.esm/index.js';
3
- import { version } from './_version.js';
4
- import { BigNumber } from '../../bignumber/lib.esm/bignumber.js';
5
-
6
- const logger = new Logger(version);
7
- const _constructorGuard = {};
8
- let ModifiersBytes = { calldata: true, memory: true, storage: true };
9
- let ModifiersNest = { calldata: true, memory: true };
10
- function checkModifier(type, name) {
11
- if (type === "bytes" || type === "string") {
12
- if (ModifiersBytes[name]) {
13
- return true;
14
- }
15
- }
16
- else if (type === "address") {
17
- if (name === "payable") {
18
- return true;
19
- }
20
- }
21
- else if (type.indexOf("[") >= 0 || type === "tuple") {
22
- if (ModifiersNest[name]) {
23
- return true;
24
- }
25
- }
26
- if (ModifiersBytes[name] || name === "payable") {
27
- logger.throwArgumentError("invalid modifier", "name", name);
28
- }
29
- return false;
30
- }
31
- // @TODO: Make sure that children of an indexed tuple are marked with a null indexed
32
- function parseParamType(param, allowIndexed) {
33
- let originalParam = param;
34
- function throwError(i) {
35
- logger.throwArgumentError(`unexpected character at position ${i}`, "param", param);
36
- }
37
- param = param.replace(/\s/g, " ");
38
- function newNode(parent) {
39
- let node = { type: "", name: "", parent: parent, state: { allowType: true } };
40
- if (allowIndexed) {
41
- node.indexed = false;
42
- }
43
- return node;
44
- }
45
- let parent = { type: "", name: "", state: { allowType: true } };
46
- let node = parent;
47
- for (let i = 0; i < param.length; i++) {
48
- let c = param[i];
49
- switch (c) {
50
- case "(":
51
- if (node.state.allowType && node.type === "") {
52
- node.type = "tuple";
53
- }
54
- else if (!node.state.allowParams) {
55
- throwError(i);
56
- }
57
- node.state.allowType = false;
58
- node.type = verifyType(node.type);
59
- node.components = [newNode(node)];
60
- node = node.components[0];
61
- break;
62
- case ")":
63
- delete node.state;
64
- if (node.name === "indexed") {
65
- if (!allowIndexed) {
66
- throwError(i);
67
- }
68
- node.indexed = true;
69
- node.name = "";
70
- }
71
- if (checkModifier(node.type, node.name)) {
72
- node.name = "";
73
- }
74
- node.type = verifyType(node.type);
75
- let child = node;
76
- node = node.parent;
77
- if (!node) {
78
- throwError(i);
79
- }
80
- delete child.parent;
81
- node.state.allowParams = false;
82
- node.state.allowName = true;
83
- node.state.allowArray = true;
84
- break;
85
- case ",":
86
- delete node.state;
87
- if (node.name === "indexed") {
88
- if (!allowIndexed) {
89
- throwError(i);
90
- }
91
- node.indexed = true;
92
- node.name = "";
93
- }
94
- if (checkModifier(node.type, node.name)) {
95
- node.name = "";
96
- }
97
- node.type = verifyType(node.type);
98
- let sibling = newNode(node.parent);
99
- //{ type: "", name: "", parent: node.parent, state: { allowType: true } };
100
- node.parent.components.push(sibling);
101
- delete node.parent;
102
- node = sibling;
103
- break;
104
- // Hit a space...
105
- case " ":
106
- // If reading type, the type is done and may read a param or name
107
- if (node.state.allowType) {
108
- if (node.type !== "") {
109
- node.type = verifyType(node.type);
110
- delete node.state.allowType;
111
- node.state.allowName = true;
112
- node.state.allowParams = true;
113
- }
114
- }
115
- // If reading name, the name is done
116
- if (node.state.allowName) {
117
- if (node.name !== "") {
118
- if (node.name === "indexed") {
119
- if (!allowIndexed) {
120
- throwError(i);
121
- }
122
- if (node.indexed) {
123
- throwError(i);
124
- }
125
- node.indexed = true;
126
- node.name = "";
127
- }
128
- else if (checkModifier(node.type, node.name)) {
129
- node.name = "";
130
- }
131
- else {
132
- node.state.allowName = false;
133
- }
134
- }
135
- }
136
- break;
137
- case "[":
138
- if (!node.state.allowArray) {
139
- throwError(i);
140
- }
141
- node.type += c;
142
- node.state.allowArray = false;
143
- node.state.allowName = false;
144
- node.state.readArray = true;
145
- break;
146
- case "]":
147
- if (!node.state.readArray) {
148
- throwError(i);
149
- }
150
- node.type += c;
151
- node.state.readArray = false;
152
- node.state.allowArray = true;
153
- node.state.allowName = true;
154
- break;
155
- default:
156
- if (node.state.allowType) {
157
- node.type += c;
158
- node.state.allowParams = true;
159
- node.state.allowArray = true;
160
- }
161
- else if (node.state.allowName) {
162
- node.name += c;
163
- delete node.state.allowArray;
164
- }
165
- else if (node.state.readArray) {
166
- node.type += c;
167
- }
168
- else {
169
- throwError(i);
170
- }
171
- }
172
- }
173
- if (node.parent) {
174
- logger.throwArgumentError("unexpected eof", "param", param);
175
- }
176
- delete parent.state;
177
- if (node.name === "indexed") {
178
- if (!allowIndexed) {
179
- throwError(originalParam.length - 7);
180
- }
181
- if (node.indexed) {
182
- throwError(originalParam.length - 7);
183
- }
184
- node.indexed = true;
185
- node.name = "";
186
- }
187
- else if (checkModifier(node.type, node.name)) {
188
- node.name = "";
189
- }
190
- parent.type = verifyType(parent.type);
191
- return parent;
192
- }
193
- function populate(object, params) {
194
- for (let key in params) {
195
- defineReadOnly(object, key, params[key]);
196
- }
197
- }
198
- const FormatTypes = Object.freeze({
199
- // Bare formatting, as is needed for computing a sighash of an event or function
200
- sighash: "sighash",
201
- // Human-Readable with Minimal spacing and without names (compact human-readable)
202
- minimal: "minimal",
203
- // Human-Readable with nice spacing, including all names
204
- full: "full",
205
- // JSON-format a la Solidity
206
- json: "json"
207
- });
208
- const paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
209
- class ParamType {
210
- constructor(constructorGuard, params) {
211
- if (constructorGuard !== _constructorGuard) {
212
- logger.throwError("use fromString", Logger.errors.UNSUPPORTED_OPERATION, {
213
- operation: "new ParamType()"
214
- });
215
- }
216
- populate(this, params);
217
- let match = this.type.match(paramTypeArray);
218
- if (match) {
219
- populate(this, {
220
- arrayLength: parseInt(match[2] || "-1"),
221
- arrayChildren: ParamType.fromObject({
222
- type: match[1],
223
- components: this.components
224
- }),
225
- baseType: "array"
226
- });
227
- }
228
- else {
229
- populate(this, {
230
- arrayLength: null,
231
- arrayChildren: null,
232
- baseType: ((this.components != null) ? "tuple" : this.type)
233
- });
234
- }
235
- this._isParamType = true;
236
- Object.freeze(this);
237
- }
238
- // Format the parameter fragment
239
- // - sighash: "(uint256,address)"
240
- // - minimal: "tuple(uint256,address) indexed"
241
- // - full: "tuple(uint256 foo, address bar) indexed baz"
242
- format(format) {
243
- if (!format) {
244
- format = FormatTypes.sighash;
245
- }
246
- if (!FormatTypes[format]) {
247
- logger.throwArgumentError("invalid format type", "format", format);
248
- }
249
- if (format === FormatTypes.json) {
250
- let result = {
251
- type: ((this.baseType === "tuple") ? "tuple" : this.type),
252
- name: (this.name || undefined)
253
- };
254
- if (typeof (this.indexed) === "boolean") {
255
- result.indexed = this.indexed;
256
- }
257
- if (this.components) {
258
- result.components = this.components.map((comp) => JSON.parse(comp.format(format)));
259
- }
260
- return JSON.stringify(result);
261
- }
262
- let result = "";
263
- // Array
264
- if (this.baseType === "array") {
265
- result += this.arrayChildren.format(format);
266
- result += "[" + (this.arrayLength < 0 ? "" : String(this.arrayLength)) + "]";
267
- }
268
- else {
269
- if (this.baseType === "tuple") {
270
- if (format !== FormatTypes.sighash) {
271
- result += this.type;
272
- }
273
- result += "(" + this.components.map((comp) => comp.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ")";
274
- }
275
- else {
276
- result += this.type;
277
- }
278
- }
279
- if (format !== FormatTypes.sighash) {
280
- if (this.indexed === true) {
281
- result += " indexed";
282
- }
283
- if (format === FormatTypes.full && this.name) {
284
- result += " " + this.name;
285
- }
286
- }
287
- return result;
288
- }
289
- static from(value, allowIndexed) {
290
- if (typeof (value) === "string") {
291
- return ParamType.fromString(value, allowIndexed);
292
- }
293
- return ParamType.fromObject(value);
294
- }
295
- static fromObject(value) {
296
- if (ParamType.isParamType(value)) {
297
- return value;
298
- }
299
- return new ParamType(_constructorGuard, {
300
- name: (value.name || null),
301
- type: verifyType(value.type),
302
- indexed: ((value.indexed == null) ? null : !!value.indexed),
303
- components: (value.components ? value.components.map(ParamType.fromObject) : null)
304
- });
305
- }
306
- static fromString(value, allowIndexed) {
307
- function ParamTypify(node) {
308
- return ParamType.fromObject({
309
- name: node.name,
310
- type: node.type,
311
- indexed: node.indexed,
312
- components: node.components
313
- });
314
- }
315
- return ParamTypify(parseParamType(value, !!allowIndexed));
316
- }
317
- static isParamType(value) {
318
- return !!(value != null && value._isParamType);
319
- }
320
- }
321
- function parseParams(value, allowIndex) {
322
- return splitNesting(value).map((param) => ParamType.fromString(param, allowIndex));
323
- }
324
- class Fragment {
325
- constructor(constructorGuard, params) {
326
- if (constructorGuard !== _constructorGuard) {
327
- logger.throwError("use a static from method", Logger.errors.UNSUPPORTED_OPERATION, {
328
- operation: "new Fragment()"
329
- });
330
- }
331
- populate(this, params);
332
- this._isFragment = true;
333
- Object.freeze(this);
334
- }
335
- static from(value) {
336
- if (Fragment.isFragment(value)) {
337
- return value;
338
- }
339
- if (typeof (value) === "string") {
340
- return Fragment.fromString(value);
341
- }
342
- return Fragment.fromObject(value);
343
- }
344
- static fromObject(value) {
345
- if (Fragment.isFragment(value)) {
346
- return value;
347
- }
348
- switch (value.type) {
349
- case "function":
350
- return FunctionFragment.fromObject(value);
351
- case "event":
352
- return EventFragment.fromObject(value);
353
- case "constructor":
354
- return ConstructorFragment.fromObject(value);
355
- case "error":
356
- return ErrorFragment.fromObject(value);
357
- case "fallback":
358
- case "receive":
359
- // @TODO: Something? Maybe return a FunctionFragment? A custom DefaultFunctionFragment?
360
- return null;
361
- }
362
- return logger.throwArgumentError("invalid fragment object", "value", value);
363
- }
364
- static fromString(value) {
365
- // Make sure the "returns" is surrounded by a space and all whitespace is exactly one space
366
- value = value.replace(/\s/g, " ");
367
- value = value.replace(/\(/g, " (").replace(/\)/g, ") ").replace(/\s+/g, " ");
368
- value = value.trim();
369
- if (value.split(" ")[0] === "event") {
370
- return EventFragment.fromString(value.substring(5).trim());
371
- }
372
- else if (value.split(" ")[0] === "function") {
373
- return FunctionFragment.fromString(value.substring(8).trim());
374
- }
375
- else if (value.split("(")[0].trim() === "constructor") {
376
- return ConstructorFragment.fromString(value.trim());
377
- }
378
- else if (value.split(" ")[0] === "error") {
379
- return ErrorFragment.fromString(value.substring(5).trim());
380
- }
381
- return logger.throwArgumentError("unsupported fragment", "value", value);
382
- }
383
- static isFragment(value) {
384
- return !!(value && value._isFragment);
385
- }
386
- }
387
- class EventFragment extends Fragment {
388
- format(format) {
389
- if (!format) {
390
- format = FormatTypes.sighash;
391
- }
392
- if (!FormatTypes[format]) {
393
- logger.throwArgumentError("invalid format type", "format", format);
394
- }
395
- if (format === FormatTypes.json) {
396
- return JSON.stringify({
397
- type: "event",
398
- anonymous: this.anonymous,
399
- name: this.name,
400
- inputs: this.inputs.map((input) => JSON.parse(input.format(format)))
401
- });
402
- }
403
- let result = "";
404
- if (format !== FormatTypes.sighash) {
405
- result += "event ";
406
- }
407
- result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
408
- if (format !== FormatTypes.sighash) {
409
- if (this.anonymous) {
410
- result += "anonymous ";
411
- }
412
- }
413
- return result.trim();
414
- }
415
- static from(value) {
416
- if (typeof (value) === "string") {
417
- return EventFragment.fromString(value);
418
- }
419
- return EventFragment.fromObject(value);
420
- }
421
- static fromObject(value) {
422
- if (EventFragment.isEventFragment(value)) {
423
- return value;
424
- }
425
- if (value.type !== "event") {
426
- logger.throwArgumentError("invalid event object", "value", value);
427
- }
428
- const params = {
429
- name: verifyIdentifier(value.name),
430
- anonymous: value.anonymous,
431
- inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
432
- type: "event"
433
- };
434
- return new EventFragment(_constructorGuard, params);
435
- }
436
- static fromString(value) {
437
- let match = value.match(regexParen);
438
- if (!match) {
439
- logger.throwArgumentError("invalid event string", "value", value);
440
- }
441
- let anonymous = false;
442
- match[3].split(" ").forEach((modifier) => {
443
- switch (modifier.trim()) {
444
- case "anonymous":
445
- anonymous = true;
446
- break;
447
- case "":
448
- break;
449
- default:
450
- logger.warn("unknown modifier: " + modifier);
451
- }
452
- });
453
- return EventFragment.fromObject({
454
- name: match[1].trim(),
455
- anonymous: anonymous,
456
- inputs: parseParams(match[2], true),
457
- type: "event"
458
- });
459
- }
460
- static isEventFragment(value) {
461
- return (value && value._isFragment && value.type === "event");
462
- }
463
- }
464
- function parseGas(value, params) {
465
- params.gas = null;
466
- let comps = value.split("@");
467
- if (comps.length !== 1) {
468
- if (comps.length > 2) {
469
- logger.throwArgumentError("invalid human-readable ABI signature", "value", value);
470
- }
471
- if (!comps[1].match(/^[0-9]+$/)) {
472
- logger.throwArgumentError("invalid human-readable ABI signature gas", "value", value);
473
- }
474
- params.gas = BigNumber.from(comps[1]);
475
- return comps[0];
476
- }
477
- return value;
478
- }
479
- function parseModifiers(value, params) {
480
- params.constant = false;
481
- params.payable = false;
482
- params.stateMutability = "nonpayable";
483
- value.split(" ").forEach((modifier) => {
484
- switch (modifier.trim()) {
485
- case "constant":
486
- params.constant = true;
487
- break;
488
- case "payable":
489
- params.payable = true;
490
- params.stateMutability = "payable";
491
- break;
492
- case "nonpayable":
493
- params.payable = false;
494
- params.stateMutability = "nonpayable";
495
- break;
496
- case "pure":
497
- params.constant = true;
498
- params.stateMutability = "pure";
499
- break;
500
- case "view":
501
- params.constant = true;
502
- params.stateMutability = "view";
503
- break;
504
- case "external":
505
- case "public":
506
- case "":
507
- break;
508
- default:
509
- console.log("unknown modifier: " + modifier);
510
- }
511
- });
512
- }
513
- function verifyState(value) {
514
- let result = {
515
- constant: false,
516
- payable: true,
517
- stateMutability: "payable"
518
- };
519
- if (value.stateMutability != null) {
520
- result.stateMutability = value.stateMutability;
521
- // Set (and check things are consistent) the constant property
522
- result.constant = (result.stateMutability === "view" || result.stateMutability === "pure");
523
- if (value.constant != null) {
524
- if ((!!value.constant) !== result.constant) {
525
- logger.throwArgumentError("cannot have constant function with mutability " + result.stateMutability, "value", value);
526
- }
527
- }
528
- // Set (and check things are consistent) the payable property
529
- result.payable = (result.stateMutability === "payable");
530
- if (value.payable != null) {
531
- if ((!!value.payable) !== result.payable) {
532
- logger.throwArgumentError("cannot have payable function with mutability " + result.stateMutability, "value", value);
533
- }
534
- }
535
- }
536
- else if (value.payable != null) {
537
- result.payable = !!value.payable;
538
- // If payable we can assume non-constant; otherwise we can't assume
539
- if (value.constant == null && !result.payable && value.type !== "constructor") {
540
- logger.throwArgumentError("unable to determine stateMutability", "value", value);
541
- }
542
- result.constant = !!value.constant;
543
- if (result.constant) {
544
- result.stateMutability = "view";
545
- }
546
- else {
547
- result.stateMutability = (result.payable ? "payable" : "nonpayable");
548
- }
549
- if (result.payable && result.constant) {
550
- logger.throwArgumentError("cannot have constant payable function", "value", value);
551
- }
552
- }
553
- else if (value.constant != null) {
554
- result.constant = !!value.constant;
555
- result.payable = !result.constant;
556
- result.stateMutability = (result.constant ? "view" : "payable");
557
- }
558
- else if (value.type !== "constructor") {
559
- logger.throwArgumentError("unable to determine stateMutability", "value", value);
560
- }
561
- return result;
562
- }
563
- class ConstructorFragment extends Fragment {
564
- format(format) {
565
- if (!format) {
566
- format = FormatTypes.sighash;
567
- }
568
- if (!FormatTypes[format]) {
569
- logger.throwArgumentError("invalid format type", "format", format);
570
- }
571
- if (format === FormatTypes.json) {
572
- return JSON.stringify({
573
- type: "constructor",
574
- stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
575
- payable: this.payable,
576
- gas: (this.gas ? this.gas.toNumber() : undefined),
577
- inputs: this.inputs.map((input) => JSON.parse(input.format(format)))
578
- });
579
- }
580
- if (format === FormatTypes.sighash) {
581
- logger.throwError("cannot format a constructor for sighash", Logger.errors.UNSUPPORTED_OPERATION, {
582
- operation: "format(sighash)"
583
- });
584
- }
585
- let result = "constructor(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
586
- if (this.stateMutability && this.stateMutability !== "nonpayable") {
587
- result += this.stateMutability + " ";
588
- }
589
- return result.trim();
590
- }
591
- static from(value) {
592
- if (typeof (value) === "string") {
593
- return ConstructorFragment.fromString(value);
594
- }
595
- return ConstructorFragment.fromObject(value);
596
- }
597
- static fromObject(value) {
598
- if (ConstructorFragment.isConstructorFragment(value)) {
599
- return value;
600
- }
601
- if (value.type !== "constructor") {
602
- logger.throwArgumentError("invalid constructor object", "value", value);
603
- }
604
- let state = verifyState(value);
605
- if (state.constant) {
606
- logger.throwArgumentError("constructor cannot be constant", "value", value);
607
- }
608
- const params = {
609
- name: null,
610
- type: value.type,
611
- inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
612
- payable: state.payable,
613
- stateMutability: state.stateMutability,
614
- gas: (value.gas ? BigNumber.from(value.gas) : null)
615
- };
616
- return new ConstructorFragment(_constructorGuard, params);
617
- }
618
- static fromString(value) {
619
- let params = { type: "constructor" };
620
- value = parseGas(value, params);
621
- let parens = value.match(regexParen);
622
- if (!parens || parens[1].trim() !== "constructor") {
623
- logger.throwArgumentError("invalid constructor string", "value", value);
624
- }
625
- params.inputs = parseParams(parens[2].trim(), false);
626
- parseModifiers(parens[3].trim(), params);
627
- return ConstructorFragment.fromObject(params);
628
- }
629
- static isConstructorFragment(value) {
630
- return (value && value._isFragment && value.type === "constructor");
631
- }
632
- }
633
- class FunctionFragment extends ConstructorFragment {
634
- format(format) {
635
- if (!format) {
636
- format = FormatTypes.sighash;
637
- }
638
- if (!FormatTypes[format]) {
639
- logger.throwArgumentError("invalid format type", "format", format);
640
- }
641
- if (format === FormatTypes.json) {
642
- return JSON.stringify({
643
- type: "function",
644
- name: this.name,
645
- constant: this.constant,
646
- stateMutability: ((this.stateMutability !== "nonpayable") ? this.stateMutability : undefined),
647
- payable: this.payable,
648
- gas: (this.gas ? this.gas.toNumber() : undefined),
649
- inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
650
- outputs: this.outputs.map((output) => JSON.parse(output.format(format))),
651
- });
652
- }
653
- let result = "";
654
- if (format !== FormatTypes.sighash) {
655
- result += "function ";
656
- }
657
- result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
658
- if (format !== FormatTypes.sighash) {
659
- if (this.stateMutability) {
660
- if (this.stateMutability !== "nonpayable") {
661
- result += (this.stateMutability + " ");
662
- }
663
- }
664
- else if (this.constant) {
665
- result += "view ";
666
- }
667
- if (this.outputs && this.outputs.length) {
668
- result += "returns (" + this.outputs.map((output) => output.format(format)).join(", ") + ") ";
669
- }
670
- if (this.gas != null) {
671
- result += "@" + this.gas.toString() + " ";
672
- }
673
- }
674
- return result.trim();
675
- }
676
- static from(value) {
677
- if (typeof (value) === "string") {
678
- return FunctionFragment.fromString(value);
679
- }
680
- return FunctionFragment.fromObject(value);
681
- }
682
- static fromObject(value) {
683
- if (FunctionFragment.isFunctionFragment(value)) {
684
- return value;
685
- }
686
- if (value.type !== "function") {
687
- logger.throwArgumentError("invalid function object", "value", value);
688
- }
689
- let state = verifyState(value);
690
- const params = {
691
- type: value.type,
692
- name: verifyIdentifier(value.name),
693
- constant: state.constant,
694
- inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : []),
695
- outputs: (value.outputs ? value.outputs.map(ParamType.fromObject) : []),
696
- payable: state.payable,
697
- stateMutability: state.stateMutability,
698
- gas: (value.gas ? BigNumber.from(value.gas) : null)
699
- };
700
- return new FunctionFragment(_constructorGuard, params);
701
- }
702
- static fromString(value) {
703
- let params = { type: "function" };
704
- value = parseGas(value, params);
705
- let comps = value.split(" returns ");
706
- if (comps.length > 2) {
707
- logger.throwArgumentError("invalid function string", "value", value);
708
- }
709
- let parens = comps[0].match(regexParen);
710
- if (!parens) {
711
- logger.throwArgumentError("invalid function signature", "value", value);
712
- }
713
- params.name = parens[1].trim();
714
- if (params.name) {
715
- verifyIdentifier(params.name);
716
- }
717
- params.inputs = parseParams(parens[2], false);
718
- parseModifiers(parens[3].trim(), params);
719
- // We have outputs
720
- if (comps.length > 1) {
721
- let returns = comps[1].match(regexParen);
722
- if (returns[1].trim() != "" || returns[3].trim() != "") {
723
- logger.throwArgumentError("unexpected tokens", "value", value);
724
- }
725
- params.outputs = parseParams(returns[2], false);
726
- }
727
- else {
728
- params.outputs = [];
729
- }
730
- return FunctionFragment.fromObject(params);
731
- }
732
- static isFunctionFragment(value) {
733
- return (value && value._isFragment && value.type === "function");
734
- }
735
- }
736
- //export class StructFragment extends Fragment {
737
- //}
738
- function checkForbidden(fragment) {
739
- const sig = fragment.format();
740
- if (sig === "Error(string)" || sig === "Panic(uint256)") {
741
- logger.throwArgumentError(`cannot specify user defined ${sig} error`, "fragment", fragment);
742
- }
743
- return fragment;
744
- }
745
- class ErrorFragment extends Fragment {
746
- format(format) {
747
- if (!format) {
748
- format = FormatTypes.sighash;
749
- }
750
- if (!FormatTypes[format]) {
751
- logger.throwArgumentError("invalid format type", "format", format);
752
- }
753
- if (format === FormatTypes.json) {
754
- return JSON.stringify({
755
- type: "error",
756
- name: this.name,
757
- inputs: this.inputs.map((input) => JSON.parse(input.format(format))),
758
- });
759
- }
760
- let result = "";
761
- if (format !== FormatTypes.sighash) {
762
- result += "error ";
763
- }
764
- result += this.name + "(" + this.inputs.map((input) => input.format(format)).join((format === FormatTypes.full) ? ", " : ",") + ") ";
765
- return result.trim();
766
- }
767
- static from(value) {
768
- if (typeof (value) === "string") {
769
- return ErrorFragment.fromString(value);
770
- }
771
- return ErrorFragment.fromObject(value);
772
- }
773
- static fromObject(value) {
774
- if (ErrorFragment.isErrorFragment(value)) {
775
- return value;
776
- }
777
- if (value.type !== "error") {
778
- logger.throwArgumentError("invalid error object", "value", value);
779
- }
780
- const params = {
781
- type: value.type,
782
- name: verifyIdentifier(value.name),
783
- inputs: (value.inputs ? value.inputs.map(ParamType.fromObject) : [])
784
- };
785
- return checkForbidden(new ErrorFragment(_constructorGuard, params));
786
- }
787
- static fromString(value) {
788
- let params = { type: "error" };
789
- let parens = value.match(regexParen);
790
- if (!parens) {
791
- logger.throwArgumentError("invalid error signature", "value", value);
792
- }
793
- params.name = parens[1].trim();
794
- if (params.name) {
795
- verifyIdentifier(params.name);
796
- }
797
- params.inputs = parseParams(parens[2], false);
798
- return checkForbidden(ErrorFragment.fromObject(params));
799
- }
800
- static isErrorFragment(value) {
801
- return (value && value._isFragment && value.type === "error");
802
- }
803
- }
804
- function verifyType(type) {
805
- // These need to be transformed to their full description
806
- if (type.match(/^uint($|[^1-9])/)) {
807
- type = "uint256" + type.substring(4);
808
- }
809
- else if (type.match(/^int($|[^1-9])/)) {
810
- type = "int256" + type.substring(3);
811
- }
812
- // @TODO: more verification
813
- return type;
814
- }
815
- // See: https://github.com/ethereum/solidity/blob/1f8f1a3db93a548d0555e3e14cfc55a10e25b60e/docs/grammar/SolidityLexer.g4#L234
816
- const regexIdentifier = new RegExp("^[a-zA-Z$_][a-zA-Z0-9$_]*$");
817
- function verifyIdentifier(value) {
818
- if (!value || !value.match(regexIdentifier)) {
819
- logger.throwArgumentError(`invalid identifier "${value}"`, "value", value);
820
- }
821
- return value;
822
- }
823
- const regexParen = new RegExp("^([^)(]*)\\((.*)\\)([^)(]*)$");
824
- function splitNesting(value) {
825
- value = value.trim();
826
- let result = [];
827
- let accum = "";
828
- let depth = 0;
829
- for (let offset = 0; offset < value.length; offset++) {
830
- let c = value[offset];
831
- if (c === "," && depth === 0) {
832
- result.push(accum);
833
- accum = "";
834
- }
835
- else {
836
- accum += c;
837
- if (c === "(") {
838
- depth++;
839
- }
840
- else if (c === ")") {
841
- depth--;
842
- if (depth === -1) {
843
- logger.throwArgumentError("unbalanced parenthesis", "value", value);
844
- }
845
- }
846
- }
847
- }
848
- if (accum) {
849
- result.push(accum);
850
- }
851
- return result;
852
- }
853
-
854
- export { ConstructorFragment, ErrorFragment, EventFragment, FormatTypes, Fragment, FunctionFragment, ParamType };