@etherplay/dev-wallet-host 0.0.0 → 0.1.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 (42) hide show
  1. package/README.md +110 -0
  2. package/bin/dev-wallet-host.js +163 -0
  3. package/config.example.json +30 -0
  4. package/lib/server.js +130 -0
  5. package/package.json +52 -2
  6. package/site/Facebook_Logo_Primary.png +0 -0
  7. package/site/README.txt +12 -0
  8. package/site/_etherplay_accounts.html +168 -0
  9. package/site/assets/App-81EXtqUY.css +495 -0
  10. package/site/assets/App-n-xKxOMT.js +21249 -0
  11. package/site/assets/App-n-xKxOMT.js.map +1 -0
  12. package/site/assets/bignumbers-tTSUAFen.js +12 -0
  13. package/site/assets/bignumbers-tTSUAFen.js.map +1 -0
  14. package/site/assets/index-BqqAh48J.js +28 -0
  15. package/site/assets/index-BqqAh48J.js.map +1 -0
  16. package/site/assets/index-CnVGoVpH.js +4020 -0
  17. package/site/assets/index-CnVGoVpH.js.map +1 -0
  18. package/site/assets/index-DqysTtwQ.js +918 -0
  19. package/site/assets/index-DqysTtwQ.js.map +1 -0
  20. package/site/assets/index-Wu-sMuYC.js +5153 -0
  21. package/site/assets/index-Wu-sMuYC.js.map +1 -0
  22. package/site/assets/index-Y5uolvJQ.js +24364 -0
  23. package/site/assets/index-Y5uolvJQ.js.map +1 -0
  24. package/site/assets/index-client-8kPxwRn_.js +1771 -0
  25. package/site/assets/index-client-8kPxwRn_.js.map +1 -0
  26. package/site/assets/index-dhS1shEX.js +6227 -0
  27. package/site/assets/index-dhS1shEX.js.map +1 -0
  28. package/site/assets/index-l0sNRNKZ.js.map +1 -0
  29. package/site/assets/login-CbHgl9FL.js +324 -0
  30. package/site/assets/login-CbHgl9FL.js.map +1 -0
  31. package/site/assets/login-bn0FJsfM.css +30 -0
  32. package/site/assets/typed-data-Xi7g-SpO.js +834 -0
  33. package/site/assets/typed-data-Xi7g-SpO.js.map +1 -0
  34. package/site/assets/utf8-B9sGmk3K.js +172 -0
  35. package/site/assets/utf8-B9sGmk3K.js.map +1 -0
  36. package/site/build-info.json +4 -0
  37. package/site/google_logo.png +0 -0
  38. package/site/index.html +12 -0
  39. package/site/login/index.html +49 -0
  40. package/site/logo.svg +104 -0
  41. package/site/x-logo-black.png +0 -0
  42. package/site/x-logo-white.png +0 -0
@@ -0,0 +1,918 @@
1
+ import { d as defineReadOnly, B as BigNumber, g as getAddress } from "./index-Wu-sMuYC.js";
2
+ import { L as Logger, a as arrayify, h as hexlify, m as hexConcat, c as concat, l as hexZeroPad } from "./App-n-xKxOMT.js";
3
+ import { M as MaxUint256, O as One, N as NegativeOne, Z as Zero } from "./bignumbers-tTSUAFen.js";
4
+ import { t as toUtf8Bytes, a as toUtf8String } from "./utf8-B9sGmk3K.js";
5
+ import "./index-client-8kPxwRn_.js";
6
+ import "./login-CbHgl9FL.js";
7
+ const version = "abi/5.8.0";
8
+ const logger$3 = new Logger(version);
9
+ const _constructorGuard = {};
10
+ let ModifiersBytes = { calldata: true, memory: true, storage: true };
11
+ let ModifiersNest = { calldata: true, memory: true };
12
+ function checkModifier(type, name) {
13
+ if (type === "bytes" || type === "string") {
14
+ if (ModifiersBytes[name]) {
15
+ return true;
16
+ }
17
+ } else if (type === "address") {
18
+ if (name === "payable") {
19
+ return true;
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$3.throwArgumentError("invalid modifier", "name", name);
28
+ }
29
+ return false;
30
+ }
31
+ function parseParamType(param, allowIndexed) {
32
+ let originalParam = param;
33
+ function throwError(i) {
34
+ logger$3.throwArgumentError(`unexpected character at position ${i}`, "param", param);
35
+ }
36
+ param = param.replace(/\s/g, " ");
37
+ function newNode(parent2) {
38
+ let node2 = { type: "", name: "", parent: parent2, state: { allowType: true } };
39
+ if (allowIndexed) {
40
+ node2.indexed = false;
41
+ }
42
+ return node2;
43
+ }
44
+ let parent = { type: "", name: "", state: { allowType: true } };
45
+ let node = parent;
46
+ for (let i = 0; i < param.length; i++) {
47
+ let c = param[i];
48
+ switch (c) {
49
+ case "(":
50
+ if (node.state.allowType && node.type === "") {
51
+ node.type = "tuple";
52
+ } else if (!node.state.allowParams) {
53
+ throwError(i);
54
+ }
55
+ node.state.allowType = false;
56
+ node.type = verifyType(node.type);
57
+ node.components = [newNode(node)];
58
+ node = node.components[0];
59
+ break;
60
+ case ")":
61
+ delete node.state;
62
+ if (node.name === "indexed") {
63
+ if (!allowIndexed) {
64
+ throwError(i);
65
+ }
66
+ node.indexed = true;
67
+ node.name = "";
68
+ }
69
+ if (checkModifier(node.type, node.name)) {
70
+ node.name = "";
71
+ }
72
+ node.type = verifyType(node.type);
73
+ let child = node;
74
+ node = node.parent;
75
+ if (!node) {
76
+ throwError(i);
77
+ }
78
+ delete child.parent;
79
+ node.state.allowParams = false;
80
+ node.state.allowName = true;
81
+ node.state.allowArray = true;
82
+ break;
83
+ case ",":
84
+ delete node.state;
85
+ if (node.name === "indexed") {
86
+ if (!allowIndexed) {
87
+ throwError(i);
88
+ }
89
+ node.indexed = true;
90
+ node.name = "";
91
+ }
92
+ if (checkModifier(node.type, node.name)) {
93
+ node.name = "";
94
+ }
95
+ node.type = verifyType(node.type);
96
+ let sibling = newNode(node.parent);
97
+ node.parent.components.push(sibling);
98
+ delete node.parent;
99
+ node = sibling;
100
+ break;
101
+ // Hit a space...
102
+ case " ":
103
+ if (node.state.allowType) {
104
+ if (node.type !== "") {
105
+ node.type = verifyType(node.type);
106
+ delete node.state.allowType;
107
+ node.state.allowName = true;
108
+ node.state.allowParams = true;
109
+ }
110
+ }
111
+ if (node.state.allowName) {
112
+ if (node.name !== "") {
113
+ if (node.name === "indexed") {
114
+ if (!allowIndexed) {
115
+ throwError(i);
116
+ }
117
+ if (node.indexed) {
118
+ throwError(i);
119
+ }
120
+ node.indexed = true;
121
+ node.name = "";
122
+ } else if (checkModifier(node.type, node.name)) {
123
+ node.name = "";
124
+ } else {
125
+ node.state.allowName = false;
126
+ }
127
+ }
128
+ }
129
+ break;
130
+ case "[":
131
+ if (!node.state.allowArray) {
132
+ throwError(i);
133
+ }
134
+ node.type += c;
135
+ node.state.allowArray = false;
136
+ node.state.allowName = false;
137
+ node.state.readArray = true;
138
+ break;
139
+ case "]":
140
+ if (!node.state.readArray) {
141
+ throwError(i);
142
+ }
143
+ node.type += c;
144
+ node.state.readArray = false;
145
+ node.state.allowArray = true;
146
+ node.state.allowName = true;
147
+ break;
148
+ default:
149
+ if (node.state.allowType) {
150
+ node.type += c;
151
+ node.state.allowParams = true;
152
+ node.state.allowArray = true;
153
+ } else if (node.state.allowName) {
154
+ node.name += c;
155
+ delete node.state.allowArray;
156
+ } else if (node.state.readArray) {
157
+ node.type += c;
158
+ } else {
159
+ throwError(i);
160
+ }
161
+ }
162
+ }
163
+ if (node.parent) {
164
+ logger$3.throwArgumentError("unexpected eof", "param", param);
165
+ }
166
+ delete parent.state;
167
+ if (node.name === "indexed") {
168
+ if (!allowIndexed) {
169
+ throwError(originalParam.length - 7);
170
+ }
171
+ if (node.indexed) {
172
+ throwError(originalParam.length - 7);
173
+ }
174
+ node.indexed = true;
175
+ node.name = "";
176
+ } else if (checkModifier(node.type, node.name)) {
177
+ node.name = "";
178
+ }
179
+ parent.type = verifyType(parent.type);
180
+ return parent;
181
+ }
182
+ function populate(object, params) {
183
+ for (let key in params) {
184
+ defineReadOnly(object, key, params[key]);
185
+ }
186
+ }
187
+ const FormatTypes = Object.freeze({
188
+ // Bare formatting, as is needed for computing a sighash of an event or function
189
+ sighash: "sighash",
190
+ // Human-Readable with Minimal spacing and without names (compact human-readable)
191
+ minimal: "minimal",
192
+ // Human-Readable with nice spacing, including all names
193
+ full: "full",
194
+ // JSON-format a la Solidity
195
+ json: "json"
196
+ });
197
+ const paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
198
+ class ParamType {
199
+ constructor(constructorGuard, params) {
200
+ if (constructorGuard !== _constructorGuard) {
201
+ logger$3.throwError("use fromString", Logger.errors.UNSUPPORTED_OPERATION, {
202
+ operation: "new ParamType()"
203
+ });
204
+ }
205
+ populate(this, params);
206
+ let match = this.type.match(paramTypeArray);
207
+ if (match) {
208
+ populate(this, {
209
+ arrayLength: parseInt(match[2] || "-1"),
210
+ arrayChildren: ParamType.fromObject({
211
+ type: match[1],
212
+ components: this.components
213
+ }),
214
+ baseType: "array"
215
+ });
216
+ } else {
217
+ populate(this, {
218
+ arrayLength: null,
219
+ arrayChildren: null,
220
+ baseType: this.components != null ? "tuple" : this.type
221
+ });
222
+ }
223
+ this._isParamType = true;
224
+ Object.freeze(this);
225
+ }
226
+ // Format the parameter fragment
227
+ // - sighash: "(uint256,address)"
228
+ // - minimal: "tuple(uint256,address) indexed"
229
+ // - full: "tuple(uint256 foo, address bar) indexed baz"
230
+ format(format) {
231
+ if (!format) {
232
+ format = FormatTypes.sighash;
233
+ }
234
+ if (!FormatTypes[format]) {
235
+ logger$3.throwArgumentError("invalid format type", "format", format);
236
+ }
237
+ if (format === FormatTypes.json) {
238
+ let result2 = {
239
+ type: this.baseType === "tuple" ? "tuple" : this.type,
240
+ name: this.name || void 0
241
+ };
242
+ if (typeof this.indexed === "boolean") {
243
+ result2.indexed = this.indexed;
244
+ }
245
+ if (this.components) {
246
+ result2.components = this.components.map((comp) => JSON.parse(comp.format(format)));
247
+ }
248
+ return JSON.stringify(result2);
249
+ }
250
+ let result = "";
251
+ if (this.baseType === "array") {
252
+ result += this.arrayChildren.format(format);
253
+ result += "[" + (this.arrayLength < 0 ? "" : String(this.arrayLength)) + "]";
254
+ } else {
255
+ if (this.baseType === "tuple") {
256
+ if (format !== FormatTypes.sighash) {
257
+ result += this.type;
258
+ }
259
+ result += "(" + this.components.map((comp) => comp.format(format)).join(format === FormatTypes.full ? ", " : ",") + ")";
260
+ } else {
261
+ result += this.type;
262
+ }
263
+ }
264
+ if (format !== FormatTypes.sighash) {
265
+ if (this.indexed === true) {
266
+ result += " indexed";
267
+ }
268
+ if (format === FormatTypes.full && this.name) {
269
+ result += " " + this.name;
270
+ }
271
+ }
272
+ return result;
273
+ }
274
+ static from(value, allowIndexed) {
275
+ if (typeof value === "string") {
276
+ return ParamType.fromString(value, allowIndexed);
277
+ }
278
+ return ParamType.fromObject(value);
279
+ }
280
+ static fromObject(value) {
281
+ if (ParamType.isParamType(value)) {
282
+ return value;
283
+ }
284
+ return new ParamType(_constructorGuard, {
285
+ name: value.name || null,
286
+ type: verifyType(value.type),
287
+ indexed: value.indexed == null ? null : !!value.indexed,
288
+ components: value.components ? value.components.map(ParamType.fromObject) : null
289
+ });
290
+ }
291
+ static fromString(value, allowIndexed) {
292
+ function ParamTypify(node) {
293
+ return ParamType.fromObject({
294
+ name: node.name,
295
+ type: node.type,
296
+ indexed: node.indexed,
297
+ components: node.components
298
+ });
299
+ }
300
+ return ParamTypify(parseParamType(value, !!allowIndexed));
301
+ }
302
+ static isParamType(value) {
303
+ return !!(value != null && value._isParamType);
304
+ }
305
+ }
306
+ function verifyType(type) {
307
+ if (type.match(/^uint($|[^1-9])/)) {
308
+ type = "uint256" + type.substring(4);
309
+ } else if (type.match(/^int($|[^1-9])/)) {
310
+ type = "int256" + type.substring(3);
311
+ }
312
+ return type;
313
+ }
314
+ const logger$2 = new Logger(version);
315
+ class Coder {
316
+ constructor(name, type, localName, dynamic) {
317
+ this.name = name;
318
+ this.type = type;
319
+ this.localName = localName;
320
+ this.dynamic = dynamic;
321
+ }
322
+ _throwError(message, value) {
323
+ logger$2.throwArgumentError(message, this.localName, value);
324
+ }
325
+ }
326
+ class Writer {
327
+ constructor(wordSize) {
328
+ defineReadOnly(this, "wordSize", wordSize || 32);
329
+ this._data = [];
330
+ this._dataLength = 0;
331
+ this._padding = new Uint8Array(wordSize);
332
+ }
333
+ get data() {
334
+ return hexConcat(this._data);
335
+ }
336
+ get length() {
337
+ return this._dataLength;
338
+ }
339
+ _writeData(data) {
340
+ this._data.push(data);
341
+ this._dataLength += data.length;
342
+ return data.length;
343
+ }
344
+ appendWriter(writer) {
345
+ return this._writeData(concat(writer._data));
346
+ }
347
+ // Arrayish items; padded on the right to wordSize
348
+ writeBytes(value) {
349
+ let bytes = arrayify(value);
350
+ const paddingOffset = bytes.length % this.wordSize;
351
+ if (paddingOffset) {
352
+ bytes = concat([bytes, this._padding.slice(paddingOffset)]);
353
+ }
354
+ return this._writeData(bytes);
355
+ }
356
+ _getValue(value) {
357
+ let bytes = arrayify(BigNumber.from(value));
358
+ if (bytes.length > this.wordSize) {
359
+ logger$2.throwError("value out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
360
+ length: this.wordSize,
361
+ offset: bytes.length
362
+ });
363
+ }
364
+ if (bytes.length % this.wordSize) {
365
+ bytes = concat([this._padding.slice(bytes.length % this.wordSize), bytes]);
366
+ }
367
+ return bytes;
368
+ }
369
+ // BigNumberish items; padded on the left to wordSize
370
+ writeValue(value) {
371
+ return this._writeData(this._getValue(value));
372
+ }
373
+ writeUpdatableValue() {
374
+ const offset = this._data.length;
375
+ this._data.push(this._padding);
376
+ this._dataLength += this.wordSize;
377
+ return (value) => {
378
+ this._data[offset] = this._getValue(value);
379
+ };
380
+ }
381
+ }
382
+ class Reader {
383
+ constructor(data, wordSize, coerceFunc, allowLoose) {
384
+ defineReadOnly(this, "_data", arrayify(data));
385
+ defineReadOnly(this, "wordSize", wordSize || 32);
386
+ defineReadOnly(this, "_coerceFunc", coerceFunc);
387
+ defineReadOnly(this, "allowLoose", allowLoose);
388
+ this._offset = 0;
389
+ }
390
+ get data() {
391
+ return hexlify(this._data);
392
+ }
393
+ get consumed() {
394
+ return this._offset;
395
+ }
396
+ // The default Coerce function
397
+ static coerce(name, value) {
398
+ let match = name.match("^u?int([0-9]+)$");
399
+ if (match && parseInt(match[1]) <= 48) {
400
+ value = value.toNumber();
401
+ }
402
+ return value;
403
+ }
404
+ coerce(name, value) {
405
+ if (this._coerceFunc) {
406
+ return this._coerceFunc(name, value);
407
+ }
408
+ return Reader.coerce(name, value);
409
+ }
410
+ _peekBytes(offset, length, loose) {
411
+ let alignedLength = Math.ceil(length / this.wordSize) * this.wordSize;
412
+ if (this._offset + alignedLength > this._data.length) {
413
+ if (this.allowLoose && loose && this._offset + length <= this._data.length) {
414
+ alignedLength = length;
415
+ } else {
416
+ logger$2.throwError("data out-of-bounds", Logger.errors.BUFFER_OVERRUN, {
417
+ length: this._data.length,
418
+ offset: this._offset + alignedLength
419
+ });
420
+ }
421
+ }
422
+ return this._data.slice(this._offset, this._offset + alignedLength);
423
+ }
424
+ subReader(offset) {
425
+ return new Reader(this._data.slice(this._offset + offset), this.wordSize, this._coerceFunc, this.allowLoose);
426
+ }
427
+ readBytes(length, loose) {
428
+ let bytes = this._peekBytes(0, length, !!loose);
429
+ this._offset += bytes.length;
430
+ return bytes.slice(0, length);
431
+ }
432
+ readValue() {
433
+ return BigNumber.from(this.readBytes(this.wordSize));
434
+ }
435
+ }
436
+ class AddressCoder extends Coder {
437
+ constructor(localName) {
438
+ super("address", "address", localName, false);
439
+ }
440
+ defaultValue() {
441
+ return "0x0000000000000000000000000000000000000000";
442
+ }
443
+ encode(writer, value) {
444
+ try {
445
+ value = getAddress(value);
446
+ } catch (error) {
447
+ this._throwError(error.message, value);
448
+ }
449
+ return writer.writeValue(value);
450
+ }
451
+ decode(reader) {
452
+ return getAddress(hexZeroPad(reader.readValue().toHexString(), 20));
453
+ }
454
+ }
455
+ class AnonymousCoder extends Coder {
456
+ constructor(coder) {
457
+ super(coder.name, coder.type, void 0, coder.dynamic);
458
+ this.coder = coder;
459
+ }
460
+ defaultValue() {
461
+ return this.coder.defaultValue();
462
+ }
463
+ encode(writer, value) {
464
+ return this.coder.encode(writer, value);
465
+ }
466
+ decode(reader) {
467
+ return this.coder.decode(reader);
468
+ }
469
+ }
470
+ const logger$1 = new Logger(version);
471
+ function pack(writer, coders, values) {
472
+ let arrayValues = null;
473
+ if (Array.isArray(values)) {
474
+ arrayValues = values;
475
+ } else if (values && typeof values === "object") {
476
+ let unique = {};
477
+ arrayValues = coders.map((coder) => {
478
+ const name = coder.localName;
479
+ if (!name) {
480
+ logger$1.throwError("cannot encode object for signature with missing names", Logger.errors.INVALID_ARGUMENT, {
481
+ argument: "values",
482
+ coder,
483
+ value: values
484
+ });
485
+ }
486
+ if (unique[name]) {
487
+ logger$1.throwError("cannot encode object for signature with duplicate names", Logger.errors.INVALID_ARGUMENT, {
488
+ argument: "values",
489
+ coder,
490
+ value: values
491
+ });
492
+ }
493
+ unique[name] = true;
494
+ return values[name];
495
+ });
496
+ } else {
497
+ logger$1.throwArgumentError("invalid tuple value", "tuple", values);
498
+ }
499
+ if (coders.length !== arrayValues.length) {
500
+ logger$1.throwArgumentError("types/value length mismatch", "tuple", values);
501
+ }
502
+ let staticWriter = new Writer(writer.wordSize);
503
+ let dynamicWriter = new Writer(writer.wordSize);
504
+ let updateFuncs = [];
505
+ coders.forEach((coder, index) => {
506
+ let value = arrayValues[index];
507
+ if (coder.dynamic) {
508
+ let dynamicOffset = dynamicWriter.length;
509
+ coder.encode(dynamicWriter, value);
510
+ let updateFunc = staticWriter.writeUpdatableValue();
511
+ updateFuncs.push((baseOffset) => {
512
+ updateFunc(baseOffset + dynamicOffset);
513
+ });
514
+ } else {
515
+ coder.encode(staticWriter, value);
516
+ }
517
+ });
518
+ updateFuncs.forEach((func) => {
519
+ func(staticWriter.length);
520
+ });
521
+ let length = writer.appendWriter(staticWriter);
522
+ length += writer.appendWriter(dynamicWriter);
523
+ return length;
524
+ }
525
+ function unpack(reader, coders) {
526
+ let values = [];
527
+ let baseReader = reader.subReader(0);
528
+ coders.forEach((coder) => {
529
+ let value = null;
530
+ if (coder.dynamic) {
531
+ let offset = reader.readValue();
532
+ let offsetReader = baseReader.subReader(offset.toNumber());
533
+ try {
534
+ value = coder.decode(offsetReader);
535
+ } catch (error) {
536
+ if (error.code === Logger.errors.BUFFER_OVERRUN) {
537
+ throw error;
538
+ }
539
+ value = error;
540
+ value.baseType = coder.name;
541
+ value.name = coder.localName;
542
+ value.type = coder.type;
543
+ }
544
+ } else {
545
+ try {
546
+ value = coder.decode(reader);
547
+ } catch (error) {
548
+ if (error.code === Logger.errors.BUFFER_OVERRUN) {
549
+ throw error;
550
+ }
551
+ value = error;
552
+ value.baseType = coder.name;
553
+ value.name = coder.localName;
554
+ value.type = coder.type;
555
+ }
556
+ }
557
+ if (value != void 0) {
558
+ values.push(value);
559
+ }
560
+ });
561
+ const uniqueNames = coders.reduce((accum, coder) => {
562
+ const name = coder.localName;
563
+ if (name) {
564
+ if (!accum[name]) {
565
+ accum[name] = 0;
566
+ }
567
+ accum[name]++;
568
+ }
569
+ return accum;
570
+ }, {});
571
+ coders.forEach((coder, index) => {
572
+ let name = coder.localName;
573
+ if (!name || uniqueNames[name] !== 1) {
574
+ return;
575
+ }
576
+ if (name === "length") {
577
+ name = "_length";
578
+ }
579
+ if (values[name] != null) {
580
+ return;
581
+ }
582
+ const value = values[index];
583
+ if (value instanceof Error) {
584
+ Object.defineProperty(values, name, {
585
+ enumerable: true,
586
+ get: () => {
587
+ throw value;
588
+ }
589
+ });
590
+ } else {
591
+ values[name] = value;
592
+ }
593
+ });
594
+ for (let i = 0; i < values.length; i++) {
595
+ const value = values[i];
596
+ if (value instanceof Error) {
597
+ Object.defineProperty(values, i, {
598
+ enumerable: true,
599
+ get: () => {
600
+ throw value;
601
+ }
602
+ });
603
+ }
604
+ }
605
+ return Object.freeze(values);
606
+ }
607
+ class ArrayCoder extends Coder {
608
+ constructor(coder, length, localName) {
609
+ const type = coder.type + "[" + (length >= 0 ? length : "") + "]";
610
+ const dynamic = length === -1 || coder.dynamic;
611
+ super("array", type, localName, dynamic);
612
+ this.coder = coder;
613
+ this.length = length;
614
+ }
615
+ defaultValue() {
616
+ const defaultChild = this.coder.defaultValue();
617
+ const result = [];
618
+ for (let i = 0; i < this.length; i++) {
619
+ result.push(defaultChild);
620
+ }
621
+ return result;
622
+ }
623
+ encode(writer, value) {
624
+ if (!Array.isArray(value)) {
625
+ this._throwError("expected array value", value);
626
+ }
627
+ let count = this.length;
628
+ if (count === -1) {
629
+ count = value.length;
630
+ writer.writeValue(value.length);
631
+ }
632
+ logger$1.checkArgumentCount(value.length, count, "coder array" + (this.localName ? " " + this.localName : ""));
633
+ let coders = [];
634
+ for (let i = 0; i < value.length; i++) {
635
+ coders.push(this.coder);
636
+ }
637
+ return pack(writer, coders, value);
638
+ }
639
+ decode(reader) {
640
+ let count = this.length;
641
+ if (count === -1) {
642
+ count = reader.readValue().toNumber();
643
+ if (count * 32 > reader._data.length) {
644
+ logger$1.throwError("insufficient data length", Logger.errors.BUFFER_OVERRUN, {
645
+ length: reader._data.length,
646
+ count
647
+ });
648
+ }
649
+ }
650
+ let coders = [];
651
+ for (let i = 0; i < count; i++) {
652
+ coders.push(new AnonymousCoder(this.coder));
653
+ }
654
+ return reader.coerce(this.name, unpack(reader, coders));
655
+ }
656
+ }
657
+ class BooleanCoder extends Coder {
658
+ constructor(localName) {
659
+ super("bool", "bool", localName, false);
660
+ }
661
+ defaultValue() {
662
+ return false;
663
+ }
664
+ encode(writer, value) {
665
+ return writer.writeValue(value ? 1 : 0);
666
+ }
667
+ decode(reader) {
668
+ return reader.coerce(this.type, !reader.readValue().isZero());
669
+ }
670
+ }
671
+ class DynamicBytesCoder extends Coder {
672
+ constructor(type, localName) {
673
+ super(type, type, localName, true);
674
+ }
675
+ defaultValue() {
676
+ return "0x";
677
+ }
678
+ encode(writer, value) {
679
+ value = arrayify(value);
680
+ let length = writer.writeValue(value.length);
681
+ length += writer.writeBytes(value);
682
+ return length;
683
+ }
684
+ decode(reader) {
685
+ return reader.readBytes(reader.readValue().toNumber(), true);
686
+ }
687
+ }
688
+ class BytesCoder extends DynamicBytesCoder {
689
+ constructor(localName) {
690
+ super("bytes", localName);
691
+ }
692
+ decode(reader) {
693
+ return reader.coerce(this.name, hexlify(super.decode(reader)));
694
+ }
695
+ }
696
+ class FixedBytesCoder extends Coder {
697
+ constructor(size, localName) {
698
+ let name = "bytes" + String(size);
699
+ super(name, name, localName, false);
700
+ this.size = size;
701
+ }
702
+ defaultValue() {
703
+ return "0x0000000000000000000000000000000000000000000000000000000000000000".substring(0, 2 + this.size * 2);
704
+ }
705
+ encode(writer, value) {
706
+ let data = arrayify(value);
707
+ if (data.length !== this.size) {
708
+ this._throwError("incorrect data length", value);
709
+ }
710
+ return writer.writeBytes(data);
711
+ }
712
+ decode(reader) {
713
+ return reader.coerce(this.name, hexlify(reader.readBytes(this.size)));
714
+ }
715
+ }
716
+ class NullCoder extends Coder {
717
+ constructor(localName) {
718
+ super("null", "", localName, false);
719
+ }
720
+ defaultValue() {
721
+ return null;
722
+ }
723
+ encode(writer, value) {
724
+ if (value != null) {
725
+ this._throwError("not null", value);
726
+ }
727
+ return writer.writeBytes([]);
728
+ }
729
+ decode(reader) {
730
+ reader.readBytes(0);
731
+ return reader.coerce(this.name, null);
732
+ }
733
+ }
734
+ class NumberCoder extends Coder {
735
+ constructor(size, signed, localName) {
736
+ const name = (signed ? "int" : "uint") + size * 8;
737
+ super(name, name, localName, false);
738
+ this.size = size;
739
+ this.signed = signed;
740
+ }
741
+ defaultValue() {
742
+ return 0;
743
+ }
744
+ encode(writer, value) {
745
+ let v = BigNumber.from(value);
746
+ let maxUintValue = MaxUint256.mask(writer.wordSize * 8);
747
+ if (this.signed) {
748
+ let bounds = maxUintValue.mask(this.size * 8 - 1);
749
+ if (v.gt(bounds) || v.lt(bounds.add(One).mul(NegativeOne))) {
750
+ this._throwError("value out-of-bounds", value);
751
+ }
752
+ } else if (v.lt(Zero) || v.gt(maxUintValue.mask(this.size * 8))) {
753
+ this._throwError("value out-of-bounds", value);
754
+ }
755
+ v = v.toTwos(this.size * 8).mask(this.size * 8);
756
+ if (this.signed) {
757
+ v = v.fromTwos(this.size * 8).toTwos(8 * writer.wordSize);
758
+ }
759
+ return writer.writeValue(v);
760
+ }
761
+ decode(reader) {
762
+ let value = reader.readValue().mask(this.size * 8);
763
+ if (this.signed) {
764
+ value = value.fromTwos(this.size * 8);
765
+ }
766
+ return reader.coerce(this.name, value);
767
+ }
768
+ }
769
+ class StringCoder extends DynamicBytesCoder {
770
+ constructor(localName) {
771
+ super("string", localName);
772
+ }
773
+ defaultValue() {
774
+ return "";
775
+ }
776
+ encode(writer, value) {
777
+ return super.encode(writer, toUtf8Bytes(value));
778
+ }
779
+ decode(reader) {
780
+ return toUtf8String(super.decode(reader));
781
+ }
782
+ }
783
+ class TupleCoder extends Coder {
784
+ constructor(coders, localName) {
785
+ let dynamic = false;
786
+ const types = [];
787
+ coders.forEach((coder) => {
788
+ if (coder.dynamic) {
789
+ dynamic = true;
790
+ }
791
+ types.push(coder.type);
792
+ });
793
+ const type = "tuple(" + types.join(",") + ")";
794
+ super("tuple", type, localName, dynamic);
795
+ this.coders = coders;
796
+ }
797
+ defaultValue() {
798
+ const values = [];
799
+ this.coders.forEach((coder) => {
800
+ values.push(coder.defaultValue());
801
+ });
802
+ const uniqueNames = this.coders.reduce((accum, coder) => {
803
+ const name = coder.localName;
804
+ if (name) {
805
+ if (!accum[name]) {
806
+ accum[name] = 0;
807
+ }
808
+ accum[name]++;
809
+ }
810
+ return accum;
811
+ }, {});
812
+ this.coders.forEach((coder, index) => {
813
+ let name = coder.localName;
814
+ if (!name || uniqueNames[name] !== 1) {
815
+ return;
816
+ }
817
+ if (name === "length") {
818
+ name = "_length";
819
+ }
820
+ if (values[name] != null) {
821
+ return;
822
+ }
823
+ values[name] = values[index];
824
+ });
825
+ return Object.freeze(values);
826
+ }
827
+ encode(writer, value) {
828
+ return pack(writer, this.coders, value);
829
+ }
830
+ decode(reader) {
831
+ return reader.coerce(this.name, unpack(reader, this.coders));
832
+ }
833
+ }
834
+ const logger = new Logger(version);
835
+ const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
836
+ const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
837
+ class AbiCoder {
838
+ constructor(coerceFunc) {
839
+ defineReadOnly(this, "coerceFunc", coerceFunc || null);
840
+ }
841
+ _getCoder(param) {
842
+ switch (param.baseType) {
843
+ case "address":
844
+ return new AddressCoder(param.name);
845
+ case "bool":
846
+ return new BooleanCoder(param.name);
847
+ case "string":
848
+ return new StringCoder(param.name);
849
+ case "bytes":
850
+ return new BytesCoder(param.name);
851
+ case "array":
852
+ return new ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
853
+ case "tuple":
854
+ return new TupleCoder((param.components || []).map((component) => {
855
+ return this._getCoder(component);
856
+ }), param.name);
857
+ case "":
858
+ return new NullCoder(param.name);
859
+ }
860
+ let match = param.type.match(paramTypeNumber);
861
+ if (match) {
862
+ let size = parseInt(match[2] || "256");
863
+ if (size === 0 || size > 256 || size % 8 !== 0) {
864
+ logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
865
+ }
866
+ return new NumberCoder(size / 8, match[1] === "int", param.name);
867
+ }
868
+ match = param.type.match(paramTypeBytes);
869
+ if (match) {
870
+ let size = parseInt(match[1]);
871
+ if (size === 0 || size > 32) {
872
+ logger.throwArgumentError("invalid bytes length", "param", param);
873
+ }
874
+ return new FixedBytesCoder(size, param.name);
875
+ }
876
+ return logger.throwArgumentError("invalid type", "type", param.type);
877
+ }
878
+ _getWordSize() {
879
+ return 32;
880
+ }
881
+ _getReader(data, allowLoose) {
882
+ return new Reader(data, this._getWordSize(), this.coerceFunc, allowLoose);
883
+ }
884
+ _getWriter() {
885
+ return new Writer(this._getWordSize());
886
+ }
887
+ getDefaultValue(types) {
888
+ const coders = types.map((type) => this._getCoder(ParamType.from(type)));
889
+ const coder = new TupleCoder(coders, "_");
890
+ return coder.defaultValue();
891
+ }
892
+ encode(types, values) {
893
+ if (types.length !== values.length) {
894
+ logger.throwError("types/values length mismatch", Logger.errors.INVALID_ARGUMENT, {
895
+ count: { types: types.length, values: values.length },
896
+ value: { types, values }
897
+ });
898
+ }
899
+ const coders = types.map((type) => this._getCoder(ParamType.from(type)));
900
+ const coder = new TupleCoder(coders, "_");
901
+ const writer = this._getWriter();
902
+ coder.encode(writer, values);
903
+ return writer.data;
904
+ }
905
+ decode(types, data, loose) {
906
+ const coders = types.map((type) => this._getCoder(ParamType.from(type)));
907
+ const coder = new TupleCoder(coders, "_");
908
+ return coder.decode(this._getReader(arrayify(data), loose));
909
+ }
910
+ }
911
+ const defaultAbiCoder = new AbiCoder();
912
+ export {
913
+ AbiCoder,
914
+ FormatTypes,
915
+ ParamType,
916
+ defaultAbiCoder
917
+ };
918
+ //# sourceMappingURL=index-DqysTtwQ.js.map