Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 64x 64x 64x 32x 32x 32x 64x 64x 64x 64x 1x 32x 32x 32x 32x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 100x 100x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 200x 77508x 77508x 77508x 77508x 77508x 200x 200x 200x 200x 200x 200x 200x 200x 200x 16643x 200x 200x 200x 16443x 16443x 200x | /** * A Typed object allows a value to have its type explicitly * specified. * * For example, in Solidity, the value ``45`` could represent a * ``uint8`` or a ``uint256``. The value ``0x1234`` could represent * a ``bytes2`` or ``bytes``. * * Since JavaScript has no meaningful way to explicitly inform any * APIs which what the type is, this allows transparent interoperation * with Soldity. * * @_subsection: api/abi:Typed Values */ import { assertPrivate, defineProperties } from "../utils/index.js"; import type { Addressable } from "../address/index.js"; import type { BigNumberish, BytesLike } from "../utils/index.js"; import type { Result } from "./coders/abstract-coder.js"; const _gaurd = { }; function n(value: BigNumberish, width: number): Typed { let signed = false; if (width < 0) { signed = true; width *= -1; } // @TODO: Check range is valid for value return new Typed(_gaurd, `${ signed ? "": "u" }int${ width }`, value, { signed, width }); } function b(value: BytesLike, size?: number): Typed { // @TODO: Check range is valid for value return new Typed(_gaurd, `bytes${ (size) ? size: "" }`, value, { size }); } // @TODO: Remove this in v7, it was replaced by TypedBigInt /** * @_ignore: */ export interface TypedNumber extends Typed { value: number; defaultValue(): number; minValue(): number; maxValue(): number; } /** * A **Typed** that represents a numeric value. */ export interface TypedBigInt extends Typed { /** * The value. */ value: bigint; /** * The default value for all numeric types is ``0``. */ defaultValue(): bigint; /** * The minimum value for this type, accounting for bit-width and signed-ness. */ minValue(): bigint; /** * The minimum value for this type, accounting for bit-width. */ maxValue(): bigint; } /** * A **Typed** that represents a binary sequence of data as bytes. */ export interface TypedData extends Typed { /** * The value. */ value: string; /** * The default value for this type. */ defaultValue(): string; } /** * A **Typed** that represents a UTF-8 sequence of bytes. */ export interface TypedString extends Typed { /** * The value. */ value: string; /** * The default value for the string type is the empty string (i.e. ``""``). */ defaultValue(): string; } const _typedSymbol = Symbol.for("_ethers_typed"); /** * The **Typed** class to wrap values providing explicit type information. */ export class Typed { /** * The type, as a Solidity-compatible type. */ readonly type!: string; /** * The actual value. */ readonly value!: any; readonly #options: any; /** * @_ignore: */ readonly _typedSymbol!: Symbol; /** * @_ignore: */ constructor(gaurd: any, type: string, value: any, options?: any) { if (options == null) { options = null; } assertPrivate(_gaurd, gaurd, "Typed"); defineProperties<Typed>(this, { _typedSymbol, type, value }); this.#options = options; // Check the value is valid this.format(); } /** * Format the type as a Human-Readable type. */ format(): string { if (this.type === "array") { throw new Error(""); } else if (this.type === "dynamicArray") { throw new Error(""); } else if (this.type === "tuple") { return `tuple(${ this.value.map((v: Typed) => v.format()).join(",") })` } return this.type; } /** * The default value returned by this type. */ defaultValue(): string | number | bigint | Result { return 0; } /** * The minimum value for numeric types. */ minValue(): string | number | bigint { return 0; } /** * The maximum value for numeric types. */ maxValue(): string | number | bigint { return 0; } /** * Returns ``true`` and provides a type guard is this is a [[TypedBigInt]]. */ isBigInt(): this is TypedBigInt { return !!(this.type.match(/^u?int[0-9]+$/)); } /** * Returns ``true`` and provides a type guard is this is a [[TypedData]]. */ isData(): this is TypedData { return this.type.startsWith("bytes"); } /** * Returns ``true`` and provides a type guard is this is a [[TypedString]]. */ isString(): this is TypedString { return (this.type === "string"); } /** * Returns the tuple name, if this is a tuple. Throws otherwise. */ get tupleName(): null | string { if (this.type !== "tuple") { throw TypeError("not a tuple"); } return this.#options; } // Returns the length of this type as an array // - `null` indicates the length is unforced, it could be dynamic // - `-1` indicates the length is dynamic // - any other value indicates it is a static array and is its length /** * Returns the length of the array type or ``-1`` if it is dynamic. * * Throws if the type is not an array. */ get arrayLength(): null | number { if (this.type !== "array") { throw TypeError("not an array"); } if (this.#options === true) { return -1; } if (this.#options === false) { return (<Array<any>>(this.value)).length; } return null; } /** * Returns a new **Typed** of %%type%% with the %%value%%. */ static from(type: string, value: any): Typed { return new Typed(_gaurd, type, value); } /** * Return a new ``uint8`` type for %%v%%. */ static uint8(v: BigNumberish): Typed { return n(v, 8); } /** * Return a new ``uint16`` type for %%v%%. */ static uint16(v: BigNumberish): Typed { return n(v, 16); } /** * Return a new ``uint24`` type for %%v%%. */ static uint24(v: BigNumberish): Typed { return n(v, 24); } /** * Return a new ``uint32`` type for %%v%%. */ static uint32(v: BigNumberish): Typed { return n(v, 32); } /** * Return a new ``uint40`` type for %%v%%. */ static uint40(v: BigNumberish): Typed { return n(v, 40); } /** * Return a new ``uint48`` type for %%v%%. */ static uint48(v: BigNumberish): Typed { return n(v, 48); } /** * Return a new ``uint56`` type for %%v%%. */ static uint56(v: BigNumberish): Typed { return n(v, 56); } /** * Return a new ``uint64`` type for %%v%%. */ static uint64(v: BigNumberish): Typed { return n(v, 64); } /** * Return a new ``uint72`` type for %%v%%. */ static uint72(v: BigNumberish): Typed { return n(v, 72); } /** * Return a new ``uint80`` type for %%v%%. */ static uint80(v: BigNumberish): Typed { return n(v, 80); } /** * Return a new ``uint88`` type for %%v%%. */ static uint88(v: BigNumberish): Typed { return n(v, 88); } /** * Return a new ``uint96`` type for %%v%%. */ static uint96(v: BigNumberish): Typed { return n(v, 96); } /** * Return a new ``uint104`` type for %%v%%. */ static uint104(v: BigNumberish): Typed { return n(v, 104); } /** * Return a new ``uint112`` type for %%v%%. */ static uint112(v: BigNumberish): Typed { return n(v, 112); } /** * Return a new ``uint120`` type for %%v%%. */ static uint120(v: BigNumberish): Typed { return n(v, 120); } /** * Return a new ``uint128`` type for %%v%%. */ static uint128(v: BigNumberish): Typed { return n(v, 128); } /** * Return a new ``uint136`` type for %%v%%. */ static uint136(v: BigNumberish): Typed { return n(v, 136); } /** * Return a new ``uint144`` type for %%v%%. */ static uint144(v: BigNumberish): Typed { return n(v, 144); } /** * Return a new ``uint152`` type for %%v%%. */ static uint152(v: BigNumberish): Typed { return n(v, 152); } /** * Return a new ``uint160`` type for %%v%%. */ static uint160(v: BigNumberish): Typed { return n(v, 160); } /** * Return a new ``uint168`` type for %%v%%. */ static uint168(v: BigNumberish): Typed { return n(v, 168); } /** * Return a new ``uint176`` type for %%v%%. */ static uint176(v: BigNumberish): Typed { return n(v, 176); } /** * Return a new ``uint184`` type for %%v%%. */ static uint184(v: BigNumberish): Typed { return n(v, 184); } /** * Return a new ``uint192`` type for %%v%%. */ static uint192(v: BigNumberish): Typed { return n(v, 192); } /** * Return a new ``uint200`` type for %%v%%. */ static uint200(v: BigNumberish): Typed { return n(v, 200); } /** * Return a new ``uint208`` type for %%v%%. */ static uint208(v: BigNumberish): Typed { return n(v, 208); } /** * Return a new ``uint216`` type for %%v%%. */ static uint216(v: BigNumberish): Typed { return n(v, 216); } /** * Return a new ``uint224`` type for %%v%%. */ static uint224(v: BigNumberish): Typed { return n(v, 224); } /** * Return a new ``uint232`` type for %%v%%. */ static uint232(v: BigNumberish): Typed { return n(v, 232); } /** * Return a new ``uint240`` type for %%v%%. */ static uint240(v: BigNumberish): Typed { return n(v, 240); } /** * Return a new ``uint248`` type for %%v%%. */ static uint248(v: BigNumberish): Typed { return n(v, 248); } /** * Return a new ``uint256`` type for %%v%%. */ static uint256(v: BigNumberish): Typed { return n(v, 256); } /** * Return a new ``uint256`` type for %%v%%. */ static uint(v: BigNumberish): Typed { return n(v, 256); } /** * Return a new ``int8`` type for %%v%%. */ static int8(v: BigNumberish): Typed { return n(v, -8); } /** * Return a new ``int16`` type for %%v%%. */ static int16(v: BigNumberish): Typed { return n(v, -16); } /** * Return a new ``int24`` type for %%v%%. */ static int24(v: BigNumberish): Typed { return n(v, -24); } /** * Return a new ``int32`` type for %%v%%. */ static int32(v: BigNumberish): Typed { return n(v, -32); } /** * Return a new ``int40`` type for %%v%%. */ static int40(v: BigNumberish): Typed { return n(v, -40); } /** * Return a new ``int48`` type for %%v%%. */ static int48(v: BigNumberish): Typed { return n(v, -48); } /** * Return a new ``int56`` type for %%v%%. */ static int56(v: BigNumberish): Typed { return n(v, -56); } /** * Return a new ``int64`` type for %%v%%. */ static int64(v: BigNumberish): Typed { return n(v, -64); } /** * Return a new ``int72`` type for %%v%%. */ static int72(v: BigNumberish): Typed { return n(v, -72); } /** * Return a new ``int80`` type for %%v%%. */ static int80(v: BigNumberish): Typed { return n(v, -80); } /** * Return a new ``int88`` type for %%v%%. */ static int88(v: BigNumberish): Typed { return n(v, -88); } /** * Return a new ``int96`` type for %%v%%. */ static int96(v: BigNumberish): Typed { return n(v, -96); } /** * Return a new ``int104`` type for %%v%%. */ static int104(v: BigNumberish): Typed { return n(v, -104); } /** * Return a new ``int112`` type for %%v%%. */ static int112(v: BigNumberish): Typed { return n(v, -112); } /** * Return a new ``int120`` type for %%v%%. */ static int120(v: BigNumberish): Typed { return n(v, -120); } /** * Return a new ``int128`` type for %%v%%. */ static int128(v: BigNumberish): Typed { return n(v, -128); } /** * Return a new ``int136`` type for %%v%%. */ static int136(v: BigNumberish): Typed { return n(v, -136); } /** * Return a new ``int144`` type for %%v%%. */ static int144(v: BigNumberish): Typed { return n(v, -144); } /** * Return a new ``int52`` type for %%v%%. */ static int152(v: BigNumberish): Typed { return n(v, -152); } /** * Return a new ``int160`` type for %%v%%. */ static int160(v: BigNumberish): Typed { return n(v, -160); } /** * Return a new ``int168`` type for %%v%%. */ static int168(v: BigNumberish): Typed { return n(v, -168); } /** * Return a new ``int176`` type for %%v%%. */ static int176(v: BigNumberish): Typed { return n(v, -176); } /** * Return a new ``int184`` type for %%v%%. */ static int184(v: BigNumberish): Typed { return n(v, -184); } /** * Return a new ``int92`` type for %%v%%. */ static int192(v: BigNumberish): Typed { return n(v, -192); } /** * Return a new ``int200`` type for %%v%%. */ static int200(v: BigNumberish): Typed { return n(v, -200); } /** * Return a new ``int208`` type for %%v%%. */ static int208(v: BigNumberish): Typed { return n(v, -208); } /** * Return a new ``int216`` type for %%v%%. */ static int216(v: BigNumberish): Typed { return n(v, -216); } /** * Return a new ``int224`` type for %%v%%. */ static int224(v: BigNumberish): Typed { return n(v, -224); } /** * Return a new ``int232`` type for %%v%%. */ static int232(v: BigNumberish): Typed { return n(v, -232); } /** * Return a new ``int240`` type for %%v%%. */ static int240(v: BigNumberish): Typed { return n(v, -240); } /** * Return a new ``int248`` type for %%v%%. */ static int248(v: BigNumberish): Typed { return n(v, -248); } /** * Return a new ``int256`` type for %%v%%. */ static int256(v: BigNumberish): Typed { return n(v, -256); } /** * Return a new ``int256`` type for %%v%%. */ static int(v: BigNumberish): Typed { return n(v, -256); } /** * Return a new ``bytes1`` type for %%v%%. */ static bytes1(v: BytesLike): Typed { return b(v, 1); } /** * Return a new ``bytes2`` type for %%v%%. */ static bytes2(v: BytesLike): Typed { return b(v, 2); } /** * Return a new ``bytes3`` type for %%v%%. */ static bytes3(v: BytesLike): Typed { return b(v, 3); } /** * Return a new ``bytes4`` type for %%v%%. */ static bytes4(v: BytesLike): Typed { return b(v, 4); } /** * Return a new ``bytes5`` type for %%v%%. */ static bytes5(v: BytesLike): Typed { return b(v, 5); } /** * Return a new ``bytes6`` type for %%v%%. */ static bytes6(v: BytesLike): Typed { return b(v, 6); } /** * Return a new ``bytes7`` type for %%v%%. */ static bytes7(v: BytesLike): Typed { return b(v, 7); } /** * Return a new ``bytes8`` type for %%v%%. */ static bytes8(v: BytesLike): Typed { return b(v, 8); } /** * Return a new ``bytes9`` type for %%v%%. */ static bytes9(v: BytesLike): Typed { return b(v, 9); } /** * Return a new ``bytes10`` type for %%v%%. */ static bytes10(v: BytesLike): Typed { return b(v, 10); } /** * Return a new ``bytes11`` type for %%v%%. */ static bytes11(v: BytesLike): Typed { return b(v, 11); } /** * Return a new ``bytes12`` type for %%v%%. */ static bytes12(v: BytesLike): Typed { return b(v, 12); } /** * Return a new ``bytes13`` type for %%v%%. */ static bytes13(v: BytesLike): Typed { return b(v, 13); } /** * Return a new ``bytes14`` type for %%v%%. */ static bytes14(v: BytesLike): Typed { return b(v, 14); } /** * Return a new ``bytes15`` type for %%v%%. */ static bytes15(v: BytesLike): Typed { return b(v, 15); } /** * Return a new ``bytes16`` type for %%v%%. */ static bytes16(v: BytesLike): Typed { return b(v, 16); } /** * Return a new ``bytes17`` type for %%v%%. */ static bytes17(v: BytesLike): Typed { return b(v, 17); } /** * Return a new ``bytes18`` type for %%v%%. */ static bytes18(v: BytesLike): Typed { return b(v, 18); } /** * Return a new ``bytes19`` type for %%v%%. */ static bytes19(v: BytesLike): Typed { return b(v, 19); } /** * Return a new ``bytes20`` type for %%v%%. */ static bytes20(v: BytesLike): Typed { return b(v, 20); } /** * Return a new ``bytes21`` type for %%v%%. */ static bytes21(v: BytesLike): Typed { return b(v, 21); } /** * Return a new ``bytes22`` type for %%v%%. */ static bytes22(v: BytesLike): Typed { return b(v, 22); } /** * Return a new ``bytes23`` type for %%v%%. */ static bytes23(v: BytesLike): Typed { return b(v, 23); } /** * Return a new ``bytes24`` type for %%v%%. */ static bytes24(v: BytesLike): Typed { return b(v, 24); } /** * Return a new ``bytes25`` type for %%v%%. */ static bytes25(v: BytesLike): Typed { return b(v, 25); } /** * Return a new ``bytes26`` type for %%v%%. */ static bytes26(v: BytesLike): Typed { return b(v, 26); } /** * Return a new ``bytes27`` type for %%v%%. */ static bytes27(v: BytesLike): Typed { return b(v, 27); } /** * Return a new ``bytes28`` type for %%v%%. */ static bytes28(v: BytesLike): Typed { return b(v, 28); } /** * Return a new ``bytes29`` type for %%v%%. */ static bytes29(v: BytesLike): Typed { return b(v, 29); } /** * Return a new ``bytes30`` type for %%v%%. */ static bytes30(v: BytesLike): Typed { return b(v, 30); } /** * Return a new ``bytes31`` type for %%v%%. */ static bytes31(v: BytesLike): Typed { return b(v, 31); } /** * Return a new ``bytes32`` type for %%v%%. */ static bytes32(v: BytesLike): Typed { return b(v, 32); } /** * Return a new ``address`` type for %%v%%. */ static address(v: string | Addressable): Typed { return new Typed(_gaurd, "address", v); } /** * Return a new ``bool`` type for %%v%%. */ static bool(v: any): Typed { return new Typed(_gaurd, "bool", !!v); } /** * Return a new ``bytes`` type for %%v%%. */ static bytes(v: BytesLike): Typed { return new Typed(_gaurd, "bytes", v); } /** * Return a new ``string`` type for %%v%%. */ static string(v: string): Typed { return new Typed(_gaurd, "string", v); } /** * Return a new ``array`` type for %%v%%, allowing %%dynamic%% length. */ static array(v: Array<any | Typed>, dynamic?: null | boolean): Typed { throw new Error("not implemented yet"); return new Typed(_gaurd, "array", v, dynamic); } /** * Return a new ``tuple`` type for %%v%%, with the optional %%name%%. */ static tuple(v: Array<any | Typed> | Record<string, any | Typed>, name?: string): Typed { throw new Error("not implemented yet"); return new Typed(_gaurd, "tuple", v, name); } /** * Return a new ``uint8`` type for %%v%%. */ static overrides(v: Record<string, any>): Typed { return new Typed(_gaurd, "overrides", Object.assign({ }, v)); } /** * Returns true only if %%value%% is a [[Typed]] instance. */ static isTyped(value: any): value is Typed { return (value && typeof(value) === "object" && "_typedSymbol" in value && value._typedSymbol === _typedSymbol); } /** * If the value is a [[Typed]] instance, validates the underlying value * and returns it, otherwise returns value directly. * * This is useful for functions that with to accept either a [[Typed]] * object or values. */ static dereference<T>(value: Typed | T, type: string): T { if (Typed.isTyped(value)) { if (value.type !== type) { throw new Error(`invalid type: expecetd ${ type }, got ${ value.type }`); } return value.value; } return value; } } |