chore: refactored js-sha3 and added biome.json
ddde0216
2 file(s) · +806 −408
| 1 | + | { |
|
| 2 | + | "$schema": "https://biomejs.dev/schemas/2.2.4/schema.json", |
|
| 3 | + | "vcs": { |
|
| 4 | + | "enabled": false, |
|
| 5 | + | "clientKind": "git", |
|
| 6 | + | "useIgnoreFile": false |
|
| 7 | + | }, |
|
| 8 | + | "files": { |
|
| 9 | + | "ignoreUnknown": false |
|
| 10 | + | }, |
|
| 11 | + | "formatter": { |
|
| 12 | + | "enabled": true, |
|
| 13 | + | "indentStyle": "tab" |
|
| 14 | + | }, |
|
| 15 | + | "linter": { |
|
| 16 | + | "enabled": true, |
|
| 17 | + | "rules": { |
|
| 18 | + | "recommended": true, |
|
| 19 | + | "complexity": { |
|
| 20 | + | "useArrowFunction": "off" |
|
| 21 | + | } |
|
| 22 | + | } |
|
| 23 | + | }, |
|
| 24 | + | "javascript": { |
|
| 25 | + | "formatter": { |
|
| 26 | + | "quoteStyle": "double" |
|
| 27 | + | } |
|
| 28 | + | }, |
|
| 29 | + | "assist": { |
|
| 30 | + | "enabled": true, |
|
| 31 | + | "actions": { |
|
| 32 | + | "source": { |
|
| 33 | + | "organizeImports": "on" |
|
| 34 | + | } |
|
| 35 | + | } |
|
| 36 | + | } |
|
| 37 | + | } |
| 299 | 299 | ||
| 300 | 300 | // Use proper keccak256 hash - for production use a crypto library |
|
| 301 | 301 | const hash = this.keccak256(signature); |
|
| 302 | - | return hash.slice(0, 10); // First 4 bytes (function selector) |
|
| 302 | + | return "0x" + hash.slice(0, 8); // First 4 bytes (function selector) |
|
| 303 | 303 | } |
|
| 304 | 304 | ||
| 305 | 305 | encodeArguments() { |
|
| 359 | 359 | data.match(/.{2}/g)?.map((byte) => parseInt(byte, 16)) || []; |
|
| 360 | 360 | return new TextDecoder().decode(new Uint8Array(bytes)); |
|
| 361 | 361 | } catch (e) { |
|
| 362 | + | console.log(e); |
|
| 362 | 363 | return data; |
|
| 363 | 364 | } |
|
| 364 | 365 | } |
|
| 366 | 367 | return result; |
|
| 367 | 368 | } |
|
| 368 | 369 | ||
| 369 | - | keccak256(input) { |
|
| 370 | - | // Use the keccak256 function defined at the bottom of this file |
|
| 371 | - | return keccak256(input); |
|
| 372 | - | } |
|
| 370 | + | keccak256 = (input) => { |
|
| 371 | + | // Use the global keccak256 function from the sha3 library |
|
| 372 | + | if (typeof window.keccak256 === "function") { |
|
| 373 | + | return window.keccak256(input); |
|
| 374 | + | } else { |
|
| 375 | + | throw new Error( |
|
| 376 | + | "keccak256 function not available. Make sure the sha3 library is loaded.", |
|
| 377 | + | ); |
|
| 378 | + | } |
|
| 379 | + | }; |
|
| 373 | 380 | ||
| 374 | 381 | // UI helper methods |
|
| 375 | 382 | getCSSVariable(name, defaultValue) { |
|
| 600 | 607 | customElements.define("contract-call", ContractCall); |
|
| 601 | 608 | ||
| 602 | 609 | /** |
|
| 603 | - | * Minimal Keccak256 implementation for browser use |
|
| 604 | - | * Based on js-sha3 by emn178 |
|
| 605 | - | * https://github.com/emn178/js-sha3 |
|
| 610 | + | * [js-sha3]{@link https://github.com/emn178/js-sha3} |
|
| 611 | + | * |
|
| 612 | + | * @version 0.9.3 |
|
| 613 | + | * @author Chen, Yi-Cyuan [emn178@gmail.com] |
|
| 614 | + | * @copyright Chen, Yi-Cyuan 2015-2023 |
|
| 615 | + | * @license MIT |
|
| 606 | 616 | */ |
|
| 617 | + | /*jslint bitwise: true */ |
|
| 618 | + | (function () { |
|
| 619 | + | var INPUT_ERROR = "input is invalid type"; |
|
| 620 | + | var FINALIZE_ERROR = "finalize already called"; |
|
| 621 | + | var WINDOW = typeof window === "object"; |
|
| 622 | + | var root = WINDOW ? window : {}; |
|
| 623 | + | if (root.JS_SHA3_NO_WINDOW) { |
|
| 624 | + | WINDOW = false; |
|
| 625 | + | } |
|
| 626 | + | var WEB_WORKER = !WINDOW && typeof self === "object"; |
|
| 627 | + | var NODE_JS = |
|
| 628 | + | !root.JS_SHA3_NO_NODE_JS && |
|
| 629 | + | typeof process === "object" && |
|
| 630 | + | process.versions && |
|
| 631 | + | process.versions.node; |
|
| 632 | + | if (NODE_JS) { |
|
| 633 | + | root = global; |
|
| 634 | + | } else if (WEB_WORKER) { |
|
| 635 | + | root = self; |
|
| 636 | + | } |
|
| 637 | + | var COMMON_JS = |
|
| 638 | + | !root.JS_SHA3_NO_COMMON_JS && typeof module === "object" && module.exports; |
|
| 639 | + | var AMD = typeof define === "function" && define.amd; |
|
| 640 | + | var ARRAY_BUFFER = |
|
| 641 | + | !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== "undefined"; |
|
| 642 | + | var HEX_CHARS = "0123456789abcdef".split(""); |
|
| 643 | + | var SHAKE_PADDING = [31, 7936, 2031616, 520093696]; |
|
| 644 | + | var CSHAKE_PADDING = [4, 1024, 262144, 67108864]; |
|
| 645 | + | var KECCAK_PADDING = [1, 256, 65536, 16777216]; |
|
| 646 | + | var PADDING = [6, 1536, 393216, 100663296]; |
|
| 647 | + | var SHIFT = [0, 8, 16, 24]; |
|
| 648 | + | var RC = [ |
|
| 649 | + | 1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, |
|
| 650 | + | 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, |
|
| 651 | + | 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, |
|
| 652 | + | 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, |
|
| 653 | + | 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, |
|
| 654 | + | 2147483649, 0, 2147516424, 2147483648, |
|
| 655 | + | ]; |
|
| 656 | + | var BITS = [224, 256, 384, 512]; |
|
| 657 | + | var SHAKE_BITS = [128, 256]; |
|
| 658 | + | var OUTPUT_TYPES = ["hex", "buffer", "arrayBuffer", "array", "digest"]; |
|
| 659 | + | var CSHAKE_BYTEPAD = { |
|
| 660 | + | 128: 168, |
|
| 661 | + | 256: 136, |
|
| 662 | + | }; |
|
| 607 | 663 | ||
| 608 | - | // Keccak constants |
|
| 609 | - | const KECCAK_PADDING = [1, 256, 65536, 16777216]; |
|
| 610 | - | const SHIFT = [0, 8, 16, 24]; |
|
| 611 | - | const RC = [ |
|
| 612 | - | 1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, |
|
| 613 | - | 2147483649, 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, |
|
| 614 | - | 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, |
|
| 615 | - | 2147483648, 32771, 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, |
|
| 616 | - | 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649, |
|
| 617 | - | 0, 2147516424, 2147483648, |
|
| 618 | - | ]; |
|
| 664 | + | var isArray = |
|
| 665 | + | root.JS_SHA3_NO_NODE_JS || !Array.isArray |
|
| 666 | + | ? function (obj) { |
|
| 667 | + | return Object.prototype.toString.call(obj) === "[object Array]"; |
|
| 668 | + | } |
|
| 669 | + | : Array.isArray; |
|
| 670 | + | ||
| 671 | + | var isView = |
|
| 672 | + | ARRAY_BUFFER && |
|
| 673 | + | (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) |
|
| 674 | + | ? function (obj) { |
|
| 675 | + | return ( |
|
| 676 | + | typeof obj === "object" && |
|
| 677 | + | obj.buffer && |
|
| 678 | + | obj.buffer.constructor === ArrayBuffer |
|
| 679 | + | ); |
|
| 680 | + | } |
|
| 681 | + | : ArrayBuffer.isView; |
|
| 682 | + | ||
| 683 | + | // [message: string, isString: bool] |
|
| 684 | + | var formatMessage = function (message) { |
|
| 685 | + | var type = typeof message; |
|
| 686 | + | if (type === "string") { |
|
| 687 | + | return [message, true]; |
|
| 688 | + | } |
|
| 689 | + | if (type !== "object" || message === null) { |
|
| 690 | + | throw new Error(INPUT_ERROR); |
|
| 691 | + | } |
|
| 692 | + | if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { |
|
| 693 | + | return [new Uint8Array(message), false]; |
|
| 694 | + | } |
|
| 695 | + | if (!isArray(message) && !isView(message)) { |
|
| 696 | + | throw new Error(INPUT_ERROR); |
|
| 697 | + | } |
|
| 698 | + | return [message, false]; |
|
| 699 | + | }; |
|
| 700 | + | ||
| 701 | + | var empty = function (message) { |
|
| 702 | + | return formatMessage(message)[0].length === 0; |
|
| 703 | + | }; |
|
| 704 | + | ||
| 705 | + | var cloneArray = function (array) { |
|
| 706 | + | var newArray = []; |
|
| 707 | + | for (let i = 0; i < array.length; ++i) { |
|
| 708 | + | newArray[i] = array[i]; |
|
| 709 | + | } |
|
| 710 | + | return newArray; |
|
| 711 | + | }; |
|
| 712 | + | ||
| 713 | + | var createOutputMethod = function (bits, padding, outputType) { |
|
| 714 | + | return function (message) { |
|
| 715 | + | return new Keccak(bits, padding, bits).update(message)[outputType](); |
|
| 716 | + | }; |
|
| 717 | + | }; |
|
| 718 | + | ||
| 719 | + | var createShakeOutputMethod = function (bits, padding, outputType) { |
|
| 720 | + | return function (message, outputBits) { |
|
| 721 | + | return new Keccak(bits, padding, outputBits) |
|
| 722 | + | .update(message) |
|
| 723 | + | [outputType](); |
|
| 724 | + | }; |
|
| 725 | + | }; |
|
| 726 | + | ||
| 727 | + | var createCshakeOutputMethod = function (bits, padding, outputType) { |
|
| 728 | + | return function (message, outputBits, n, s) { |
|
| 729 | + | return methods["cshake" + bits] |
|
| 730 | + | .update(message, outputBits, n, s) |
|
| 731 | + | [outputType](); |
|
| 732 | + | }; |
|
| 733 | + | }; |
|
| 734 | + | ||
| 735 | + | var createKmacOutputMethod = function (bits, padding, outputType) { |
|
| 736 | + | return function (key, message, outputBits, s) { |
|
| 737 | + | return methods["kmac" + bits] |
|
| 738 | + | .update(key, message, outputBits, s) |
|
| 739 | + | [outputType](); |
|
| 740 | + | }; |
|
| 741 | + | }; |
|
| 742 | + | ||
| 743 | + | var createOutputMethods = function (method, createMethod, bits, padding) { |
|
| 744 | + | for (let i = 0; i < OUTPUT_TYPES.length; ++i) { |
|
| 745 | + | const type = OUTPUT_TYPES[i]; |
|
| 746 | + | method[type] = createMethod(bits, padding, type); |
|
| 747 | + | } |
|
| 748 | + | return method; |
|
| 749 | + | }; |
|
| 750 | + | ||
| 751 | + | var createMethod = function (bits, padding) { |
|
| 752 | + | var method = createOutputMethod(bits, padding, "hex"); |
|
| 753 | + | method.create = function () { |
|
| 754 | + | return new Keccak(bits, padding, bits); |
|
| 755 | + | }; |
|
| 756 | + | method.update = function (message) { |
|
| 757 | + | return method.create().update(message); |
|
| 758 | + | }; |
|
| 759 | + | return createOutputMethods(method, createOutputMethod, bits, padding); |
|
| 760 | + | }; |
|
| 761 | + | ||
| 762 | + | var createShakeMethod = function (bits, padding) { |
|
| 763 | + | var method = createShakeOutputMethod(bits, padding, "hex"); |
|
| 764 | + | method.create = function (outputBits) { |
|
| 765 | + | return new Keccak(bits, padding, outputBits); |
|
| 766 | + | }; |
|
| 767 | + | method.update = function (message, outputBits) { |
|
| 768 | + | return method.create(outputBits).update(message); |
|
| 769 | + | }; |
|
| 770 | + | return createOutputMethods(method, createShakeOutputMethod, bits, padding); |
|
| 771 | + | }; |
|
| 772 | + | ||
| 773 | + | var createCshakeMethod = function (bits, padding) { |
|
| 774 | + | var w = CSHAKE_BYTEPAD[bits]; |
|
| 775 | + | var method = createCshakeOutputMethod(bits, padding, "hex"); |
|
| 776 | + | method.create = function (outputBits, n, s) { |
|
| 777 | + | if (empty(n) && empty(s)) { |
|
| 778 | + | return methods["shake" + bits].create(outputBits); |
|
| 779 | + | } else { |
|
| 780 | + | return new Keccak(bits, padding, outputBits).bytepad([n, s], w); |
|
| 781 | + | } |
|
| 782 | + | }; |
|
| 783 | + | method.update = function (message, outputBits, n, s) { |
|
| 784 | + | return method.create(outputBits, n, s).update(message); |
|
| 785 | + | }; |
|
| 786 | + | return createOutputMethods(method, createCshakeOutputMethod, bits, padding); |
|
| 787 | + | }; |
|
| 788 | + | ||
| 789 | + | var createKmacMethod = function (bits, padding) { |
|
| 790 | + | var w = CSHAKE_BYTEPAD[bits]; |
|
| 791 | + | var method = createKmacOutputMethod(bits, padding, "hex"); |
|
| 792 | + | method.create = function (key, outputBits, s) { |
|
| 793 | + | return new Kmac(bits, padding, outputBits) |
|
| 794 | + | .bytepad(["KMAC", s], w) |
|
| 795 | + | .bytepad([key], w); |
|
| 796 | + | }; |
|
| 797 | + | method.update = function (key, message, outputBits, s) { |
|
| 798 | + | return method.create(key, outputBits, s).update(message); |
|
| 799 | + | }; |
|
| 800 | + | return createOutputMethods(method, createKmacOutputMethod, bits, padding); |
|
| 801 | + | }; |
|
| 802 | + | ||
| 803 | + | var algorithms = [ |
|
| 804 | + | { |
|
| 805 | + | name: "keccak", |
|
| 806 | + | padding: KECCAK_PADDING, |
|
| 807 | + | bits: BITS, |
|
| 808 | + | createMethod: createMethod, |
|
| 809 | + | }, |
|
| 810 | + | { name: "sha3", padding: PADDING, bits: BITS, createMethod: createMethod }, |
|
| 811 | + | { |
|
| 812 | + | name: "shake", |
|
| 813 | + | padding: SHAKE_PADDING, |
|
| 814 | + | bits: SHAKE_BITS, |
|
| 815 | + | createMethod: createShakeMethod, |
|
| 816 | + | }, |
|
| 817 | + | { |
|
| 818 | + | name: "cshake", |
|
| 819 | + | padding: CSHAKE_PADDING, |
|
| 820 | + | bits: SHAKE_BITS, |
|
| 821 | + | createMethod: createCshakeMethod, |
|
| 822 | + | }, |
|
| 823 | + | { |
|
| 824 | + | name: "kmac", |
|
| 825 | + | padding: CSHAKE_PADDING, |
|
| 826 | + | bits: SHAKE_BITS, |
|
| 827 | + | createMethod: createKmacMethod, |
|
| 828 | + | }, |
|
| 829 | + | ]; |
|
| 619 | 830 | ||
| 620 | - | function Keccak(bits) { |
|
| 621 | - | this.blocks = []; |
|
| 622 | - | this.s = []; |
|
| 623 | - | this.padding = KECCAK_PADDING; |
|
| 624 | - | this.outputBits = bits; |
|
| 625 | - | this.reset = true; |
|
| 626 | - | this.finalized = false; |
|
| 627 | - | this.block = 0; |
|
| 628 | - | this.start = 0; |
|
| 629 | - | this.blockCount = (1600 - (bits << 1)) >> 5; |
|
| 630 | - | this.byteCount = this.blockCount << 2; |
|
| 631 | - | this.outputBlocks = bits >> 5; |
|
| 632 | - | this.extraBytes = (bits & 31) >> 3; |
|
| 831 | + | var methods = {}, |
|
| 832 | + | methodNames = []; |
|
| 633 | 833 | ||
| 634 | - | for (var i = 0; i < 50; ++i) { |
|
| 635 | - | this.s[i] = 0; |
|
| 834 | + | for (let i = 0; i < algorithms.length; ++i) { |
|
| 835 | + | const algorithm = algorithms[i]; |
|
| 836 | + | const bits = algorithm.bits; |
|
| 837 | + | for (let j = 0; j < bits.length; ++j) { |
|
| 838 | + | const methodName = algorithm.name + "_" + bits[j]; |
|
| 839 | + | methodNames.push(methodName); |
|
| 840 | + | methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding); |
|
| 841 | + | if (algorithm.name !== "sha3") { |
|
| 842 | + | const newMethodName = algorithm.name + bits[j]; |
|
| 843 | + | methodNames.push(newMethodName); |
|
| 844 | + | methods[newMethodName] = methods[methodName]; |
|
| 845 | + | } |
|
| 846 | + | } |
|
| 636 | 847 | } |
|
| 637 | - | } |
|
| 638 | 848 | ||
| 639 | - | Keccak.prototype.update = function (message) { |
|
| 640 | - | if (this.finalized) { |
|
| 641 | - | throw new Error("finalized"); |
|
| 849 | + | function Keccak(bits, padding, outputBits) { |
|
| 850 | + | this.blocks = []; |
|
| 851 | + | this.s = []; |
|
| 852 | + | this.padding = padding; |
|
| 853 | + | this.outputBits = outputBits; |
|
| 854 | + | this.reset = true; |
|
| 855 | + | this.finalized = false; |
|
| 856 | + | this.block = 0; |
|
| 857 | + | this.start = 0; |
|
| 858 | + | this.blockCount = (1600 - (bits << 1)) >> 5; |
|
| 859 | + | this.byteCount = this.blockCount << 2; |
|
| 860 | + | this.outputBlocks = outputBits >> 5; |
|
| 861 | + | this.extraBytes = (outputBits & 31) >> 3; |
|
| 862 | + | ||
| 863 | + | for (let i = 0; i < 50; ++i) { |
|
| 864 | + | this.s[i] = 0; |
|
| 865 | + | } |
|
| 642 | 866 | } |
|
| 643 | - | var notString, |
|
| 644 | - | type = typeof message; |
|
| 645 | - | if (type !== "string") { |
|
| 646 | - | if (type === "object") { |
|
| 647 | - | if (message === null) { |
|
| 648 | - | throw new Error("message is null"); |
|
| 649 | - | } else if ( |
|
| 650 | - | Array.isArray(message) || |
|
| 651 | - | (typeof ArrayBuffer !== "undefined" && |
|
| 652 | - | message.constructor === ArrayBuffer) |
|
| 653 | - | ) { |
|
| 654 | - | message = new Uint8Array(message); |
|
| 655 | - | } else if (!ArrayBuffer.isView(message)) { |
|
| 656 | - | throw new Error("invalid message type"); |
|
| 867 | + | ||
| 868 | + | Keccak.prototype.update = function (message) { |
|
| 869 | + | if (this.finalized) { |
|
| 870 | + | throw new Error(FINALIZE_ERROR); |
|
| 871 | + | } |
|
| 872 | + | var result = formatMessage(message); |
|
| 873 | + | message = result[0]; |
|
| 874 | + | var isString = result[1]; |
|
| 875 | + | var blocks = this.blocks, |
|
| 876 | + | byteCount = this.byteCount, |
|
| 877 | + | length = message.length, |
|
| 878 | + | blockCount = this.blockCount, |
|
| 879 | + | index = 0, |
|
| 880 | + | s = this.s, |
|
| 881 | + | i, |
|
| 882 | + | code; |
|
| 883 | + | ||
| 884 | + | while (index < length) { |
|
| 885 | + | if (this.reset) { |
|
| 886 | + | this.reset = false; |
|
| 887 | + | blocks[0] = this.block; |
|
| 888 | + | for (i = 1; i < blockCount + 1; ++i) { |
|
| 889 | + | blocks[i] = 0; |
|
| 890 | + | } |
|
| 891 | + | } |
|
| 892 | + | if (isString) { |
|
| 893 | + | for (i = this.start; index < length && i < byteCount; ++index) { |
|
| 894 | + | code = message.charCodeAt(index); |
|
| 895 | + | if (code < 0x80) { |
|
| 896 | + | blocks[i >> 2] |= code << SHIFT[i++ & 3]; |
|
| 897 | + | } else if (code < 0x800) { |
|
| 898 | + | blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; |
|
| 899 | + | blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
|
| 900 | + | } else if (code < 0xd800 || code >= 0xe000) { |
|
| 901 | + | blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; |
|
| 902 | + | blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; |
|
| 903 | + | blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
|
| 904 | + | } else { |
|
| 905 | + | code = |
|
| 906 | + | 0x10000 + |
|
| 907 | + | (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); |
|
| 908 | + | blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; |
|
| 909 | + | blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; |
|
| 910 | + | blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; |
|
| 911 | + | blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
|
| 912 | + | } |
|
| 913 | + | } |
|
| 914 | + | } else { |
|
| 915 | + | for (i = this.start; index < length && i < byteCount; ++index) { |
|
| 916 | + | blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; |
|
| 917 | + | } |
|
| 918 | + | } |
|
| 919 | + | this.lastByteIndex = i; |
|
| 920 | + | if (i >= byteCount) { |
|
| 921 | + | this.start = i - byteCount; |
|
| 922 | + | this.block = blocks[blockCount]; |
|
| 923 | + | for (i = 0; i < blockCount; ++i) { |
|
| 924 | + | s[i] ^= blocks[i]; |
|
| 925 | + | } |
|
| 926 | + | f(s); |
|
| 927 | + | this.reset = true; |
|
| 928 | + | } else { |
|
| 929 | + | this.start = i; |
|
| 657 | 930 | } |
|
| 658 | - | } else { |
|
| 659 | - | throw new Error("invalid message type"); |
|
| 660 | 931 | } |
|
| 661 | - | notString = true; |
|
| 662 | - | } |
|
| 663 | - | var blocks = this.blocks, |
|
| 664 | - | byteCount = this.byteCount, |
|
| 665 | - | length = message.length, |
|
| 666 | - | blockCount = this.blockCount, |
|
| 667 | - | index = 0, |
|
| 668 | - | s = this.s, |
|
| 669 | - | i, |
|
| 670 | - | code; |
|
| 932 | + | return this; |
|
| 933 | + | }; |
|
| 671 | 934 | ||
| 672 | - | while (index < length) { |
|
| 673 | - | if (this.reset) { |
|
| 674 | - | this.reset = false; |
|
| 675 | - | blocks[0] = this.block; |
|
| 676 | - | for (i = 1; i < blockCount + 1; ++i) { |
|
| 677 | - | blocks[i] = 0; |
|
| 678 | - | } |
|
| 935 | + | Keccak.prototype.encode = function (x, right) { |
|
| 936 | + | var o = x & 255, |
|
| 937 | + | n = 1; |
|
| 938 | + | var bytes = [o]; |
|
| 939 | + | x = x >> 8; |
|
| 940 | + | o = x & 255; |
|
| 941 | + | while (o > 0) { |
|
| 942 | + | bytes.unshift(o); |
|
| 943 | + | x = x >> 8; |
|
| 944 | + | o = x & 255; |
|
| 945 | + | ++n; |
|
| 679 | 946 | } |
|
| 680 | - | if (notString) { |
|
| 681 | - | for (i = this.start; index < length && i < byteCount; ++index) { |
|
| 682 | - | blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; |
|
| 683 | - | } |
|
| 947 | + | if (right) { |
|
| 948 | + | bytes.push(n); |
|
| 684 | 949 | } else { |
|
| 685 | - | for (i = this.start; index < length && i < byteCount; ++index) { |
|
| 686 | - | code = message.charCodeAt(index); |
|
| 950 | + | bytes.unshift(n); |
|
| 951 | + | } |
|
| 952 | + | this.update(bytes); |
|
| 953 | + | return bytes.length; |
|
| 954 | + | }; |
|
| 955 | + | ||
| 956 | + | Keccak.prototype.encodeString = function (str) { |
|
| 957 | + | var result = formatMessage(str); |
|
| 958 | + | str = result[0]; |
|
| 959 | + | var isString = result[1]; |
|
| 960 | + | var bytes = 0, |
|
| 961 | + | length = str.length; |
|
| 962 | + | if (isString) { |
|
| 963 | + | for (let i = 0; i < str.length; ++i) { |
|
| 964 | + | let code = str.charCodeAt(i); |
|
| 687 | 965 | if (code < 0x80) { |
|
| 688 | - | blocks[i >> 2] |= code << SHIFT[i++ & 3]; |
|
| 966 | + | bytes += 1; |
|
| 689 | 967 | } else if (code < 0x800) { |
|
| 690 | - | blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; |
|
| 691 | - | blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
|
| 968 | + | bytes += 2; |
|
| 692 | 969 | } else if (code < 0xd800 || code >= 0xe000) { |
|
| 693 | - | blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; |
|
| 694 | - | blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; |
|
| 695 | - | blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
|
| 970 | + | bytes += 3; |
|
| 696 | 971 | } else { |
|
| 697 | 972 | code = |
|
| 698 | - | 0x10000 + |
|
| 699 | - | (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); |
|
| 700 | - | blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; |
|
| 701 | - | blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; |
|
| 702 | - | blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; |
|
| 703 | - | blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; |
|
| 973 | + | 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff)); |
|
| 974 | + | bytes += 4; |
|
| 704 | 975 | } |
|
| 705 | 976 | } |
|
| 977 | + | } else { |
|
| 978 | + | bytes = length; |
|
| 706 | 979 | } |
|
| 980 | + | bytes += this.encode(bytes * 8); |
|
| 981 | + | this.update(str); |
|
| 982 | + | return bytes; |
|
| 983 | + | }; |
|
| 707 | 984 | ||
| 708 | - | this.lastByteIndex = i; |
|
| 709 | - | if (i >= byteCount) { |
|
| 710 | - | this.start = i - byteCount; |
|
| 711 | - | this.block = blocks[blockCount]; |
|
| 712 | - | for (i = 0; i < blockCount; ++i) { |
|
| 713 | - | s[i] ^= blocks[i]; |
|
| 985 | + | Keccak.prototype.bytepad = function (strs, w) { |
|
| 986 | + | var bytes = this.encode(w); |
|
| 987 | + | for (let i = 0; i < strs.length; ++i) { |
|
| 988 | + | bytes += this.encodeString(strs[i]); |
|
| 989 | + | } |
|
| 990 | + | var paddingBytes = (w - (bytes % w)) % w; |
|
| 991 | + | var zeros = []; |
|
| 992 | + | zeros.length = paddingBytes; |
|
| 993 | + | this.update(zeros); |
|
| 994 | + | return this; |
|
| 995 | + | }; |
|
| 996 | + | ||
| 997 | + | Keccak.prototype.finalize = function () { |
|
| 998 | + | if (this.finalized) { |
|
| 999 | + | return; |
|
| 1000 | + | } |
|
| 1001 | + | this.finalized = true; |
|
| 1002 | + | var blocks = this.blocks, |
|
| 1003 | + | i = this.lastByteIndex, |
|
| 1004 | + | blockCount = this.blockCount, |
|
| 1005 | + | s = this.s; |
|
| 1006 | + | blocks[i >> 2] |= this.padding[i & 3]; |
|
| 1007 | + | if (this.lastByteIndex === this.byteCount) { |
|
| 1008 | + | blocks[0] = blocks[blockCount]; |
|
| 1009 | + | for (i = 1; i < blockCount + 1; ++i) { |
|
| 1010 | + | blocks[i] = 0; |
|
| 714 | 1011 | } |
|
| 715 | - | f(s); |
|
| 716 | - | this.reset = true; |
|
| 717 | - | } else { |
|
| 718 | - | this.start = i; |
|
| 1012 | + | } |
|
| 1013 | + | blocks[blockCount - 1] |= 0x80000000; |
|
| 1014 | + | for (i = 0; i < blockCount; ++i) { |
|
| 1015 | + | s[i] ^= blocks[i]; |
|
| 719 | 1016 | } |
|
| 720 | - | } |
|
| 721 | - | return this; |
|
| 722 | - | }; |
|
| 1017 | + | f(s); |
|
| 1018 | + | }; |
|
| 1019 | + | ||
| 1020 | + | Keccak.prototype.toString = Keccak.prototype.hex = function () { |
|
| 1021 | + | this.finalize(); |
|
| 723 | 1022 | ||
| 724 | - | Keccak.prototype.finalize = function () { |
|
| 725 | - | if (this.finalized) { |
|
| 726 | - | return; |
|
| 727 | - | } |
|
| 728 | - | this.finalized = true; |
|
| 729 | - | var blocks = this.blocks, |
|
| 730 | - | i = this.lastByteIndex, |
|
| 731 | - | blockCount = this.blockCount, |
|
| 732 | - | s = this.s; |
|
| 733 | - | blocks[i >> 2] |= this.padding[i & 3]; |
|
| 734 | - | if (this.lastByteIndex === this.byteCount) { |
|
| 735 | - | blocks[0] = blocks[blockCount]; |
|
| 736 | - | for (i = 1; i < blockCount + 1; ++i) { |
|
| 737 | - | blocks[i] = 0; |
|
| 1023 | + | var blockCount = this.blockCount, |
|
| 1024 | + | s = this.s, |
|
| 1025 | + | outputBlocks = this.outputBlocks, |
|
| 1026 | + | extraBytes = this.extraBytes, |
|
| 1027 | + | i = 0, |
|
| 1028 | + | j = 0; |
|
| 1029 | + | var hex = "", |
|
| 1030 | + | block; |
|
| 1031 | + | while (j < outputBlocks) { |
|
| 1032 | + | for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
|
| 1033 | + | block = s[i]; |
|
| 1034 | + | hex += |
|
| 1035 | + | HEX_CHARS[(block >> 4) & 0x0f] + |
|
| 1036 | + | HEX_CHARS[block & 0x0f] + |
|
| 1037 | + | HEX_CHARS[(block >> 12) & 0x0f] + |
|
| 1038 | + | HEX_CHARS[(block >> 8) & 0x0f] + |
|
| 1039 | + | HEX_CHARS[(block >> 20) & 0x0f] + |
|
| 1040 | + | HEX_CHARS[(block >> 16) & 0x0f] + |
|
| 1041 | + | HEX_CHARS[(block >> 28) & 0x0f] + |
|
| 1042 | + | HEX_CHARS[(block >> 24) & 0x0f]; |
|
| 1043 | + | } |
|
| 1044 | + | if (j % blockCount === 0) { |
|
| 1045 | + | s = cloneArray(s); |
|
| 1046 | + | f(s); |
|
| 1047 | + | i = 0; |
|
| 1048 | + | } |
|
| 1049 | + | } |
|
| 1050 | + | if (extraBytes) { |
|
| 1051 | + | block = s[i]; |
|
| 1052 | + | hex += HEX_CHARS[(block >> 4) & 0x0f] + HEX_CHARS[block & 0x0f]; |
|
| 1053 | + | if (extraBytes > 1) { |
|
| 1054 | + | hex += HEX_CHARS[(block >> 12) & 0x0f] + HEX_CHARS[(block >> 8) & 0x0f]; |
|
| 1055 | + | } |
|
| 1056 | + | if (extraBytes > 2) { |
|
| 1057 | + | hex += |
|
| 1058 | + | HEX_CHARS[(block >> 20) & 0x0f] + HEX_CHARS[(block >> 16) & 0x0f]; |
|
| 1059 | + | } |
|
| 738 | 1060 | } |
|
| 739 | - | } |
|
| 740 | - | blocks[blockCount - 1] |= 0x80000000; |
|
| 741 | - | for (i = 0; i < blockCount; ++i) { |
|
| 742 | - | s[i] ^= blocks[i]; |
|
| 743 | - | } |
|
| 744 | - | f(s); |
|
| 745 | - | }; |
|
| 1061 | + | return hex; |
|
| 1062 | + | }; |
|
| 746 | 1063 | ||
| 747 | - | Keccak.prototype.toString = Keccak.prototype.hex = function () { |
|
| 748 | - | this.finalize(); |
|
| 1064 | + | Keccak.prototype.arrayBuffer = function () { |
|
| 1065 | + | this.finalize(); |
|
| 749 | 1066 | ||
| 750 | - | var blockCount = this.blockCount, |
|
| 751 | - | s = this.s, |
|
| 752 | - | outputBlocks = this.outputBlocks, |
|
| 753 | - | extraBytes = this.extraBytes, |
|
| 754 | - | i = 0, |
|
| 755 | - | j = 0; |
|
| 756 | - | var hex = "", |
|
| 757 | - | block; |
|
| 758 | - | while (j < outputBlocks) { |
|
| 759 | - | for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
|
| 760 | - | block = s[i]; |
|
| 761 | - | hex += |
|
| 762 | - | HEX_CHARS[(block >> 4) & 0x0f] + |
|
| 763 | - | HEX_CHARS[block & 0x0f] + |
|
| 764 | - | HEX_CHARS[(block >> 12) & 0x0f] + |
|
| 765 | - | HEX_CHARS[(block >> 8) & 0x0f] + |
|
| 766 | - | HEX_CHARS[(block >> 20) & 0x0f] + |
|
| 767 | - | HEX_CHARS[(block >> 16) & 0x0f] + |
|
| 768 | - | HEX_CHARS[(block >> 28) & 0x0f] + |
|
| 769 | - | HEX_CHARS[(block >> 24) & 0x0f]; |
|
| 1067 | + | var blockCount = this.blockCount, |
|
| 1068 | + | s = this.s, |
|
| 1069 | + | outputBlocks = this.outputBlocks, |
|
| 1070 | + | extraBytes = this.extraBytes, |
|
| 1071 | + | i = 0, |
|
| 1072 | + | j = 0; |
|
| 1073 | + | var bytes = this.outputBits >> 3; |
|
| 1074 | + | var buffer; |
|
| 1075 | + | if (extraBytes) { |
|
| 1076 | + | buffer = new ArrayBuffer((outputBlocks + 1) << 2); |
|
| 1077 | + | } else { |
|
| 1078 | + | buffer = new ArrayBuffer(bytes); |
|
| 1079 | + | } |
|
| 1080 | + | var array = new Uint32Array(buffer); |
|
| 1081 | + | while (j < outputBlocks) { |
|
| 1082 | + | for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
|
| 1083 | + | array[j] = s[i]; |
|
| 1084 | + | } |
|
| 1085 | + | if (j % blockCount === 0) { |
|
| 1086 | + | s = cloneArray(s); |
|
| 1087 | + | f(s); |
|
| 1088 | + | } |
|
| 770 | 1089 | } |
|
| 771 | - | if (j % blockCount === 0) { |
|
| 772 | - | f(s); |
|
| 773 | - | i = 0; |
|
| 1090 | + | if (extraBytes) { |
|
| 1091 | + | array[j] = s[i]; |
|
| 1092 | + | buffer = buffer.slice(0, bytes); |
|
| 774 | 1093 | } |
|
| 775 | - | } |
|
| 776 | - | if (extraBytes) { |
|
| 777 | - | block = s[i]; |
|
| 778 | - | hex += HEX_CHARS[(block >> 4) & 0x0f] + HEX_CHARS[block & 0x0f]; |
|
| 779 | - | if (extraBytes > 1) { |
|
| 780 | - | hex += HEX_CHARS[(block >> 12) & 0x0f] + HEX_CHARS[(block >> 8) & 0x0f]; |
|
| 1094 | + | return buffer; |
|
| 1095 | + | }; |
|
| 1096 | + | ||
| 1097 | + | Keccak.prototype.buffer = Keccak.prototype.arrayBuffer; |
|
| 1098 | + | ||
| 1099 | + | Keccak.prototype.digest = Keccak.prototype.array = function () { |
|
| 1100 | + | this.finalize(); |
|
| 1101 | + | ||
| 1102 | + | var blockCount = this.blockCount, |
|
| 1103 | + | s = this.s, |
|
| 1104 | + | outputBlocks = this.outputBlocks, |
|
| 1105 | + | extraBytes = this.extraBytes, |
|
| 1106 | + | i = 0, |
|
| 1107 | + | j = 0; |
|
| 1108 | + | var array = [], |
|
| 1109 | + | offset, |
|
| 1110 | + | block; |
|
| 1111 | + | while (j < outputBlocks) { |
|
| 1112 | + | for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { |
|
| 1113 | + | offset = j << 2; |
|
| 1114 | + | block = s[i]; |
|
| 1115 | + | array[offset] = block & 0xff; |
|
| 1116 | + | array[offset + 1] = (block >> 8) & 0xff; |
|
| 1117 | + | array[offset + 2] = (block >> 16) & 0xff; |
|
| 1118 | + | array[offset + 3] = (block >> 24) & 0xff; |
|
| 1119 | + | } |
|
| 1120 | + | if (j % blockCount === 0) { |
|
| 1121 | + | s = cloneArray(s); |
|
| 1122 | + | f(s); |
|
| 1123 | + | } |
|
| 781 | 1124 | } |
|
| 782 | - | if (extraBytes > 2) { |
|
| 783 | - | hex += HEX_CHARS[(block >> 20) & 0x0f] + HEX_CHARS[(block >> 16) & 0x0f]; |
|
| 1125 | + | if (extraBytes) { |
|
| 1126 | + | offset = j << 2; |
|
| 1127 | + | block = s[i]; |
|
| 1128 | + | array[offset] = block & 0xff; |
|
| 1129 | + | if (extraBytes > 1) { |
|
| 1130 | + | array[offset + 1] = (block >> 8) & 0xff; |
|
| 1131 | + | } |
|
| 1132 | + | if (extraBytes > 2) { |
|
| 1133 | + | array[offset + 2] = (block >> 16) & 0xff; |
|
| 1134 | + | } |
|
| 784 | 1135 | } |
|
| 1136 | + | return array; |
|
| 1137 | + | }; |
|
| 1138 | + | ||
| 1139 | + | function Kmac(bits, padding, outputBits) { |
|
| 1140 | + | Keccak.call(this, bits, padding, outputBits); |
|
| 785 | 1141 | } |
|
| 786 | - | return hex; |
|
| 787 | - | }; |
|
| 788 | 1142 | ||
| 789 | - | const HEX_CHARS = "0123456789abcdef".split(""); |
|
| 1143 | + | Kmac.prototype = new Keccak(); |
|
| 790 | 1144 | ||
| 791 | - | var f = function (s) { |
|
| 792 | - | var h, |
|
| 793 | - | l, |
|
| 794 | - | n, |
|
| 795 | - | c0, |
|
| 796 | - | c1, |
|
| 797 | - | c2, |
|
| 798 | - | c3, |
|
| 799 | - | c4, |
|
| 800 | - | c5, |
|
| 801 | - | c6, |
|
| 802 | - | c7, |
|
| 803 | - | c8, |
|
| 804 | - | c9, |
|
| 805 | - | b0, |
|
| 806 | - | b1, |
|
| 807 | - | b2, |
|
| 808 | - | b3, |
|
| 809 | - | b4, |
|
| 810 | - | b5, |
|
| 811 | - | b6, |
|
| 812 | - | b7, |
|
| 813 | - | b8, |
|
| 814 | - | b9, |
|
| 815 | - | b10, |
|
| 816 | - | b11, |
|
| 817 | - | b12, |
|
| 818 | - | b13, |
|
| 819 | - | b14, |
|
| 820 | - | b15, |
|
| 821 | - | b16, |
|
| 822 | - | b17, |
|
| 823 | - | b18, |
|
| 824 | - | b19, |
|
| 825 | - | b20, |
|
| 826 | - | b21, |
|
| 827 | - | b22, |
|
| 828 | - | b23, |
|
| 829 | - | b24, |
|
| 830 | - | b25, |
|
| 831 | - | b26, |
|
| 832 | - | b27, |
|
| 833 | - | b28, |
|
| 834 | - | b29, |
|
| 835 | - | b30, |
|
| 836 | - | b31, |
|
| 837 | - | b32, |
|
| 838 | - | b33, |
|
| 839 | - | b34, |
|
| 840 | - | b35, |
|
| 841 | - | b36, |
|
| 842 | - | b37, |
|
| 843 | - | b38, |
|
| 844 | - | b39, |
|
| 845 | - | b40, |
|
| 846 | - | b41, |
|
| 847 | - | b42, |
|
| 848 | - | b43, |
|
| 849 | - | b44, |
|
| 850 | - | b45, |
|
| 851 | - | b46, |
|
| 852 | - | b47, |
|
| 853 | - | b48, |
|
| 854 | - | b49; |
|
| 855 | - | for (n = 0; n < 48; n += 2) { |
|
| 856 | - | c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; |
|
| 857 | - | c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; |
|
| 858 | - | c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; |
|
| 859 | - | c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]; |
|
| 860 | - | c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]; |
|
| 861 | - | c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]; |
|
| 862 | - | c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]; |
|
| 863 | - | c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]; |
|
| 864 | - | c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]; |
|
| 865 | - | c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]; |
|
| 1145 | + | Kmac.prototype.finalize = function () { |
|
| 1146 | + | this.encode(this.outputBits, true); |
|
| 1147 | + | return Keccak.prototype.finalize.call(this); |
|
| 1148 | + | }; |
|
| 866 | 1149 | ||
| 867 | - | h = c8 ^ ((c2 << 1) | (c3 >>> 31)); |
|
| 868 | - | l = c9 ^ ((c3 << 1) | (c2 >>> 31)); |
|
| 869 | - | s[0] ^= h; |
|
| 870 | - | s[1] ^= l; |
|
| 871 | - | s[10] ^= h; |
|
| 872 | - | s[11] ^= l; |
|
| 873 | - | s[20] ^= h; |
|
| 874 | - | s[21] ^= l; |
|
| 875 | - | s[30] ^= h; |
|
| 876 | - | s[31] ^= l; |
|
| 877 | - | s[40] ^= h; |
|
| 878 | - | s[41] ^= l; |
|
| 879 | - | h = c0 ^ ((c4 << 1) | (c5 >>> 31)); |
|
| 880 | - | l = c1 ^ ((c5 << 1) | (c4 >>> 31)); |
|
| 881 | - | s[2] ^= h; |
|
| 882 | - | s[3] ^= l; |
|
| 883 | - | s[12] ^= h; |
|
| 884 | - | s[13] ^= l; |
|
| 885 | - | s[22] ^= h; |
|
| 886 | - | s[23] ^= l; |
|
| 887 | - | s[32] ^= h; |
|
| 888 | - | s[33] ^= l; |
|
| 889 | - | s[42] ^= h; |
|
| 890 | - | s[43] ^= l; |
|
| 891 | - | h = c2 ^ ((c6 << 1) | (c7 >>> 31)); |
|
| 892 | - | l = c3 ^ ((c7 << 1) | (c6 >>> 31)); |
|
| 893 | - | s[4] ^= h; |
|
| 894 | - | s[5] ^= l; |
|
| 895 | - | s[14] ^= h; |
|
| 896 | - | s[15] ^= l; |
|
| 897 | - | s[24] ^= h; |
|
| 898 | - | s[25] ^= l; |
|
| 899 | - | s[34] ^= h; |
|
| 900 | - | s[35] ^= l; |
|
| 901 | - | s[44] ^= h; |
|
| 902 | - | s[45] ^= l; |
|
| 903 | - | h = c4 ^ ((c8 << 1) | (c9 >>> 31)); |
|
| 904 | - | l = c5 ^ ((c9 << 1) | (c8 >>> 31)); |
|
| 905 | - | s[6] ^= h; |
|
| 906 | - | s[7] ^= l; |
|
| 907 | - | s[16] ^= h; |
|
| 908 | - | s[17] ^= l; |
|
| 909 | - | s[26] ^= h; |
|
| 910 | - | s[27] ^= l; |
|
| 911 | - | s[36] ^= h; |
|
| 912 | - | s[37] ^= l; |
|
| 913 | - | s[46] ^= h; |
|
| 914 | - | s[47] ^= l; |
|
| 915 | - | h = c6 ^ ((c0 << 1) | (c1 >>> 31)); |
|
| 916 | - | l = c7 ^ ((c1 << 1) | (c0 >>> 31)); |
|
| 917 | - | s[8] ^= h; |
|
| 918 | - | s[9] ^= l; |
|
| 919 | - | s[18] ^= h; |
|
| 920 | - | s[19] ^= l; |
|
| 921 | - | s[28] ^= h; |
|
| 922 | - | s[29] ^= l; |
|
| 923 | - | s[38] ^= h; |
|
| 924 | - | s[39] ^= l; |
|
| 925 | - | s[48] ^= h; |
|
| 926 | - | s[49] ^= l; |
|
| 1150 | + | var f = function (s) { |
|
| 1151 | + | var h, |
|
| 1152 | + | l, |
|
| 1153 | + | n, |
|
| 1154 | + | c0, |
|
| 1155 | + | c1, |
|
| 1156 | + | c2, |
|
| 1157 | + | c3, |
|
| 1158 | + | c4, |
|
| 1159 | + | c5, |
|
| 1160 | + | c6, |
|
| 1161 | + | c7, |
|
| 1162 | + | c8, |
|
| 1163 | + | c9, |
|
| 1164 | + | b0, |
|
| 1165 | + | b1, |
|
| 1166 | + | b2, |
|
| 1167 | + | b3, |
|
| 1168 | + | b4, |
|
| 1169 | + | b5, |
|
| 1170 | + | b6, |
|
| 1171 | + | b7, |
|
| 1172 | + | b8, |
|
| 1173 | + | b9, |
|
| 1174 | + | b10, |
|
| 1175 | + | b11, |
|
| 1176 | + | b12, |
|
| 1177 | + | b13, |
|
| 1178 | + | b14, |
|
| 1179 | + | b15, |
|
| 1180 | + | b16, |
|
| 1181 | + | b17, |
|
| 1182 | + | b18, |
|
| 1183 | + | b19, |
|
| 1184 | + | b20, |
|
| 1185 | + | b21, |
|
| 1186 | + | b22, |
|
| 1187 | + | b23, |
|
| 1188 | + | b24, |
|
| 1189 | + | b25, |
|
| 1190 | + | b26, |
|
| 1191 | + | b27, |
|
| 1192 | + | b28, |
|
| 1193 | + | b29, |
|
| 1194 | + | b30, |
|
| 1195 | + | b31, |
|
| 1196 | + | b32, |
|
| 1197 | + | b33, |
|
| 1198 | + | b34, |
|
| 1199 | + | b35, |
|
| 1200 | + | b36, |
|
| 1201 | + | b37, |
|
| 1202 | + | b38, |
|
| 1203 | + | b39, |
|
| 1204 | + | b40, |
|
| 1205 | + | b41, |
|
| 1206 | + | b42, |
|
| 1207 | + | b43, |
|
| 1208 | + | b44, |
|
| 1209 | + | b45, |
|
| 1210 | + | b46, |
|
| 1211 | + | b47, |
|
| 1212 | + | b48, |
|
| 1213 | + | b49; |
|
| 1214 | + | for (n = 0; n < 48; n += 2) { |
|
| 1215 | + | c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; |
|
| 1216 | + | c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; |
|
| 1217 | + | c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; |
|
| 1218 | + | c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]; |
|
| 1219 | + | c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]; |
|
| 1220 | + | c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]; |
|
| 1221 | + | c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]; |
|
| 1222 | + | c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]; |
|
| 1223 | + | c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]; |
|
| 1224 | + | c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]; |
|
| 927 | 1225 | ||
| 928 | - | b0 = s[0]; |
|
| 929 | - | b1 = s[1]; |
|
| 930 | - | b32 = (s[11] << 4) | (s[10] >>> 28); |
|
| 931 | - | b33 = (s[10] << 4) | (s[11] >>> 28); |
|
| 932 | - | b14 = (s[20] << 3) | (s[21] >>> 29); |
|
| 933 | - | b15 = (s[21] << 3) | (s[20] >>> 29); |
|
| 934 | - | b46 = (s[31] << 9) | (s[30] >>> 23); |
|
| 935 | - | b47 = (s[30] << 9) | (s[31] >>> 23); |
|
| 936 | - | b28 = (s[40] << 18) | (s[41] >>> 14); |
|
| 937 | - | b29 = (s[41] << 18) | (s[40] >>> 14); |
|
| 938 | - | b20 = (s[2] << 1) | (s[3] >>> 31); |
|
| 939 | - | b21 = (s[3] << 1) | (s[2] >>> 31); |
|
| 940 | - | b2 = (s[13] << 12) | (s[12] >>> 20); |
|
| 941 | - | b3 = (s[12] << 12) | (s[13] >>> 20); |
|
| 942 | - | b34 = (s[22] << 10) | (s[23] >>> 22); |
|
| 943 | - | b35 = (s[23] << 10) | (s[22] >>> 22); |
|
| 944 | - | b16 = (s[33] << 13) | (s[32] >>> 19); |
|
| 945 | - | b17 = (s[32] << 13) | (s[33] >>> 19); |
|
| 946 | - | b48 = (s[42] << 2) | (s[43] >>> 30); |
|
| 947 | - | b49 = (s[43] << 2) | (s[42] >>> 30); |
|
| 948 | - | b40 = (s[5] << 30) | (s[4] >>> 2); |
|
| 949 | - | b41 = (s[4] << 30) | (s[5] >>> 2); |
|
| 950 | - | b22 = (s[14] << 6) | (s[15] >>> 26); |
|
| 951 | - | b23 = (s[15] << 6) | (s[14] >>> 26); |
|
| 952 | - | b4 = (s[25] << 11) | (s[24] >>> 21); |
|
| 953 | - | b5 = (s[24] << 11) | (s[25] >>> 21); |
|
| 954 | - | b36 = (s[34] << 15) | (s[35] >>> 17); |
|
| 955 | - | b37 = (s[35] << 15) | (s[34] >>> 17); |
|
| 956 | - | b18 = (s[45] << 29) | (s[44] >>> 3); |
|
| 957 | - | b19 = (s[44] << 29) | (s[45] >>> 3); |
|
| 958 | - | b10 = (s[6] << 28) | (s[7] >>> 4); |
|
| 959 | - | b11 = (s[7] << 28) | (s[6] >>> 4); |
|
| 960 | - | b42 = (s[17] << 23) | (s[16] >>> 9); |
|
| 961 | - | b43 = (s[16] << 23) | (s[17] >>> 9); |
|
| 962 | - | b24 = (s[26] << 25) | (s[27] >>> 7); |
|
| 963 | - | b25 = (s[27] << 25) | (s[26] >>> 7); |
|
| 964 | - | b6 = (s[36] << 21) | (s[37] >>> 11); |
|
| 965 | - | b7 = (s[37] << 21) | (s[36] >>> 11); |
|
| 966 | - | b38 = (s[47] << 24) | (s[46] >>> 8); |
|
| 967 | - | b39 = (s[46] << 24) | (s[47] >>> 8); |
|
| 968 | - | b30 = (s[8] << 27) | (s[9] >>> 5); |
|
| 969 | - | b31 = (s[9] << 27) | (s[8] >>> 5); |
|
| 970 | - | b12 = (s[18] << 20) | (s[19] >>> 12); |
|
| 971 | - | b13 = (s[19] << 20) | (s[18] >>> 12); |
|
| 972 | - | b44 = (s[29] << 7) | (s[28] >>> 25); |
|
| 973 | - | b45 = (s[28] << 7) | (s[29] >>> 25); |
|
| 974 | - | b26 = (s[38] << 8) | (s[39] >>> 24); |
|
| 975 | - | b27 = (s[39] << 8) | (s[38] >>> 24); |
|
| 976 | - | b8 = (s[48] << 14) | (s[49] >>> 18); |
|
| 977 | - | b9 = (s[49] << 14) | (s[48] >>> 18); |
|
| 1226 | + | h = c8 ^ ((c2 << 1) | (c3 >>> 31)); |
|
| 1227 | + | l = c9 ^ ((c3 << 1) | (c2 >>> 31)); |
|
| 1228 | + | s[0] ^= h; |
|
| 1229 | + | s[1] ^= l; |
|
| 1230 | + | s[10] ^= h; |
|
| 1231 | + | s[11] ^= l; |
|
| 1232 | + | s[20] ^= h; |
|
| 1233 | + | s[21] ^= l; |
|
| 1234 | + | s[30] ^= h; |
|
| 1235 | + | s[31] ^= l; |
|
| 1236 | + | s[40] ^= h; |
|
| 1237 | + | s[41] ^= l; |
|
| 1238 | + | h = c0 ^ ((c4 << 1) | (c5 >>> 31)); |
|
| 1239 | + | l = c1 ^ ((c5 << 1) | (c4 >>> 31)); |
|
| 1240 | + | s[2] ^= h; |
|
| 1241 | + | s[3] ^= l; |
|
| 1242 | + | s[12] ^= h; |
|
| 1243 | + | s[13] ^= l; |
|
| 1244 | + | s[22] ^= h; |
|
| 1245 | + | s[23] ^= l; |
|
| 1246 | + | s[32] ^= h; |
|
| 1247 | + | s[33] ^= l; |
|
| 1248 | + | s[42] ^= h; |
|
| 1249 | + | s[43] ^= l; |
|
| 1250 | + | h = c2 ^ ((c6 << 1) | (c7 >>> 31)); |
|
| 1251 | + | l = c3 ^ ((c7 << 1) | (c6 >>> 31)); |
|
| 1252 | + | s[4] ^= h; |
|
| 1253 | + | s[5] ^= l; |
|
| 1254 | + | s[14] ^= h; |
|
| 1255 | + | s[15] ^= l; |
|
| 1256 | + | s[24] ^= h; |
|
| 1257 | + | s[25] ^= l; |
|
| 1258 | + | s[34] ^= h; |
|
| 1259 | + | s[35] ^= l; |
|
| 1260 | + | s[44] ^= h; |
|
| 1261 | + | s[45] ^= l; |
|
| 1262 | + | h = c4 ^ ((c8 << 1) | (c9 >>> 31)); |
|
| 1263 | + | l = c5 ^ ((c9 << 1) | (c8 >>> 31)); |
|
| 1264 | + | s[6] ^= h; |
|
| 1265 | + | s[7] ^= l; |
|
| 1266 | + | s[16] ^= h; |
|
| 1267 | + | s[17] ^= l; |
|
| 1268 | + | s[26] ^= h; |
|
| 1269 | + | s[27] ^= l; |
|
| 1270 | + | s[36] ^= h; |
|
| 1271 | + | s[37] ^= l; |
|
| 1272 | + | s[46] ^= h; |
|
| 1273 | + | s[47] ^= l; |
|
| 1274 | + | h = c6 ^ ((c0 << 1) | (c1 >>> 31)); |
|
| 1275 | + | l = c7 ^ ((c1 << 1) | (c0 >>> 31)); |
|
| 1276 | + | s[8] ^= h; |
|
| 1277 | + | s[9] ^= l; |
|
| 1278 | + | s[18] ^= h; |
|
| 1279 | + | s[19] ^= l; |
|
| 1280 | + | s[28] ^= h; |
|
| 1281 | + | s[29] ^= l; |
|
| 1282 | + | s[38] ^= h; |
|
| 1283 | + | s[39] ^= l; |
|
| 1284 | + | s[48] ^= h; |
|
| 1285 | + | s[49] ^= l; |
|
| 978 | 1286 | ||
| 979 | - | s[0] = b0 ^ (~b2 & b4); |
|
| 980 | - | s[1] = b1 ^ (~b3 & b5); |
|
| 981 | - | s[10] = b10 ^ (~b12 & b14); |
|
| 982 | - | s[11] = b11 ^ (~b13 & b15); |
|
| 983 | - | s[20] = b20 ^ (~b22 & b24); |
|
| 984 | - | s[21] = b21 ^ (~b23 & b25); |
|
| 985 | - | s[30] = b30 ^ (~b32 & b34); |
|
| 986 | - | s[31] = b31 ^ (~b33 & b35); |
|
| 987 | - | s[40] = b40 ^ (~b42 & b44); |
|
| 988 | - | s[41] = b41 ^ (~b43 & b45); |
|
| 989 | - | s[2] = b2 ^ (~b4 & b6); |
|
| 990 | - | s[3] = b3 ^ (~b5 & b7); |
|
| 991 | - | s[12] = b12 ^ (~b14 & b16); |
|
| 992 | - | s[13] = b13 ^ (~b15 & b17); |
|
| 993 | - | s[22] = b22 ^ (~b24 & b26); |
|
| 994 | - | s[23] = b23 ^ (~b25 & b27); |
|
| 995 | - | s[32] = b32 ^ (~b34 & b36); |
|
| 996 | - | s[33] = b33 ^ (~b35 & b37); |
|
| 997 | - | s[42] = b42 ^ (~b44 & b46); |
|
| 998 | - | s[43] = b43 ^ (~b45 & b47); |
|
| 999 | - | s[4] = b4 ^ (~b6 & b8); |
|
| 1000 | - | s[5] = b5 ^ (~b7 & b9); |
|
| 1001 | - | s[14] = b14 ^ (~b16 & b18); |
|
| 1002 | - | s[15] = b15 ^ (~b17 & b19); |
|
| 1003 | - | s[24] = b24 ^ (~b26 & b28); |
|
| 1004 | - | s[25] = b25 ^ (~b27 & b29); |
|
| 1005 | - | s[34] = b34 ^ (~b36 & b38); |
|
| 1006 | - | s[35] = b35 ^ (~b37 & b39); |
|
| 1007 | - | s[44] = b44 ^ (~b46 & b48); |
|
| 1008 | - | s[45] = b45 ^ (~b47 & b49); |
|
| 1009 | - | s[6] = b6 ^ (~b8 & b0); |
|
| 1010 | - | s[7] = b7 ^ (~b9 & b1); |
|
| 1011 | - | s[16] = b16 ^ (~b18 & b10); |
|
| 1012 | - | s[17] = b17 ^ (~b19 & b11); |
|
| 1013 | - | s[26] = b26 ^ (~b28 & b20); |
|
| 1014 | - | s[27] = b27 ^ (~b29 & b21); |
|
| 1015 | - | s[36] = b36 ^ (~b38 & b30); |
|
| 1016 | - | s[37] = b37 ^ (~b39 & b31); |
|
| 1017 | - | s[46] = b46 ^ (~b48 & b40); |
|
| 1018 | - | s[47] = b47 ^ (~b49 & b41); |
|
| 1019 | - | s[8] = b8 ^ (~b0 & b2); |
|
| 1020 | - | s[9] = b9 ^ (~b1 & b3); |
|
| 1021 | - | s[18] = b18 ^ (~b10 & b12); |
|
| 1022 | - | s[19] = b19 ^ (~b11 & b13); |
|
| 1023 | - | s[28] = b28 ^ (~b20 & b22); |
|
| 1024 | - | s[29] = b29 ^ (~b21 & b23); |
|
| 1025 | - | s[38] = b38 ^ (~b30 & b32); |
|
| 1026 | - | s[39] = b39 ^ (~b31 & b33); |
|
| 1027 | - | s[48] = b48 ^ (~b40 & b42); |
|
| 1028 | - | s[49] = b49 ^ (~b41 & b43); |
|
| 1287 | + | b0 = s[0]; |
|
| 1288 | + | b1 = s[1]; |
|
| 1289 | + | b32 = (s[11] << 4) | (s[10] >>> 28); |
|
| 1290 | + | b33 = (s[10] << 4) | (s[11] >>> 28); |
|
| 1291 | + | b14 = (s[20] << 3) | (s[21] >>> 29); |
|
| 1292 | + | b15 = (s[21] << 3) | (s[20] >>> 29); |
|
| 1293 | + | b46 = (s[31] << 9) | (s[30] >>> 23); |
|
| 1294 | + | b47 = (s[30] << 9) | (s[31] >>> 23); |
|
| 1295 | + | b28 = (s[40] << 18) | (s[41] >>> 14); |
|
| 1296 | + | b29 = (s[41] << 18) | (s[40] >>> 14); |
|
| 1297 | + | b20 = (s[2] << 1) | (s[3] >>> 31); |
|
| 1298 | + | b21 = (s[3] << 1) | (s[2] >>> 31); |
|
| 1299 | + | b2 = (s[13] << 12) | (s[12] >>> 20); |
|
| 1300 | + | b3 = (s[12] << 12) | (s[13] >>> 20); |
|
| 1301 | + | b34 = (s[22] << 10) | (s[23] >>> 22); |
|
| 1302 | + | b35 = (s[23] << 10) | (s[22] >>> 22); |
|
| 1303 | + | b16 = (s[33] << 13) | (s[32] >>> 19); |
|
| 1304 | + | b17 = (s[32] << 13) | (s[33] >>> 19); |
|
| 1305 | + | b48 = (s[42] << 2) | (s[43] >>> 30); |
|
| 1306 | + | b49 = (s[43] << 2) | (s[42] >>> 30); |
|
| 1307 | + | b40 = (s[5] << 30) | (s[4] >>> 2); |
|
| 1308 | + | b41 = (s[4] << 30) | (s[5] >>> 2); |
|
| 1309 | + | b22 = (s[14] << 6) | (s[15] >>> 26); |
|
| 1310 | + | b23 = (s[15] << 6) | (s[14] >>> 26); |
|
| 1311 | + | b4 = (s[25] << 11) | (s[24] >>> 21); |
|
| 1312 | + | b5 = (s[24] << 11) | (s[25] >>> 21); |
|
| 1313 | + | b36 = (s[34] << 15) | (s[35] >>> 17); |
|
| 1314 | + | b37 = (s[35] << 15) | (s[34] >>> 17); |
|
| 1315 | + | b18 = (s[45] << 29) | (s[44] >>> 3); |
|
| 1316 | + | b19 = (s[44] << 29) | (s[45] >>> 3); |
|
| 1317 | + | b10 = (s[6] << 28) | (s[7] >>> 4); |
|
| 1318 | + | b11 = (s[7] << 28) | (s[6] >>> 4); |
|
| 1319 | + | b42 = (s[17] << 23) | (s[16] >>> 9); |
|
| 1320 | + | b43 = (s[16] << 23) | (s[17] >>> 9); |
|
| 1321 | + | b24 = (s[26] << 25) | (s[27] >>> 7); |
|
| 1322 | + | b25 = (s[27] << 25) | (s[26] >>> 7); |
|
| 1323 | + | b6 = (s[36] << 21) | (s[37] >>> 11); |
|
| 1324 | + | b7 = (s[37] << 21) | (s[36] >>> 11); |
|
| 1325 | + | b38 = (s[47] << 24) | (s[46] >>> 8); |
|
| 1326 | + | b39 = (s[46] << 24) | (s[47] >>> 8); |
|
| 1327 | + | b30 = (s[8] << 27) | (s[9] >>> 5); |
|
| 1328 | + | b31 = (s[9] << 27) | (s[8] >>> 5); |
|
| 1329 | + | b12 = (s[18] << 20) | (s[19] >>> 12); |
|
| 1330 | + | b13 = (s[19] << 20) | (s[18] >>> 12); |
|
| 1331 | + | b44 = (s[29] << 7) | (s[28] >>> 25); |
|
| 1332 | + | b45 = (s[28] << 7) | (s[29] >>> 25); |
|
| 1333 | + | b26 = (s[38] << 8) | (s[39] >>> 24); |
|
| 1334 | + | b27 = (s[39] << 8) | (s[38] >>> 24); |
|
| 1335 | + | b8 = (s[48] << 14) | (s[49] >>> 18); |
|
| 1336 | + | b9 = (s[49] << 14) | (s[48] >>> 18); |
|
| 1029 | 1337 | ||
| 1030 | - | s[0] ^= RC[n]; |
|
| 1031 | - | s[1] ^= RC[n + 1]; |
|
| 1032 | - | } |
|
| 1033 | - | }; |
|
| 1338 | + | s[0] = b0 ^ (~b2 & b4); |
|
| 1339 | + | s[1] = b1 ^ (~b3 & b5); |
|
| 1340 | + | s[10] = b10 ^ (~b12 & b14); |
|
| 1341 | + | s[11] = b11 ^ (~b13 & b15); |
|
| 1342 | + | s[20] = b20 ^ (~b22 & b24); |
|
| 1343 | + | s[21] = b21 ^ (~b23 & b25); |
|
| 1344 | + | s[30] = b30 ^ (~b32 & b34); |
|
| 1345 | + | s[31] = b31 ^ (~b33 & b35); |
|
| 1346 | + | s[40] = b40 ^ (~b42 & b44); |
|
| 1347 | + | s[41] = b41 ^ (~b43 & b45); |
|
| 1348 | + | s[2] = b2 ^ (~b4 & b6); |
|
| 1349 | + | s[3] = b3 ^ (~b5 & b7); |
|
| 1350 | + | s[12] = b12 ^ (~b14 & b16); |
|
| 1351 | + | s[13] = b13 ^ (~b15 & b17); |
|
| 1352 | + | s[22] = b22 ^ (~b24 & b26); |
|
| 1353 | + | s[23] = b23 ^ (~b25 & b27); |
|
| 1354 | + | s[32] = b32 ^ (~b34 & b36); |
|
| 1355 | + | s[33] = b33 ^ (~b35 & b37); |
|
| 1356 | + | s[42] = b42 ^ (~b44 & b46); |
|
| 1357 | + | s[43] = b43 ^ (~b45 & b47); |
|
| 1358 | + | s[4] = b4 ^ (~b6 & b8); |
|
| 1359 | + | s[5] = b5 ^ (~b7 & b9); |
|
| 1360 | + | s[14] = b14 ^ (~b16 & b18); |
|
| 1361 | + | s[15] = b15 ^ (~b17 & b19); |
|
| 1362 | + | s[24] = b24 ^ (~b26 & b28); |
|
| 1363 | + | s[25] = b25 ^ (~b27 & b29); |
|
| 1364 | + | s[34] = b34 ^ (~b36 & b38); |
|
| 1365 | + | s[35] = b35 ^ (~b37 & b39); |
|
| 1366 | + | s[44] = b44 ^ (~b46 & b48); |
|
| 1367 | + | s[45] = b45 ^ (~b47 & b49); |
|
| 1368 | + | s[6] = b6 ^ (~b8 & b0); |
|
| 1369 | + | s[7] = b7 ^ (~b9 & b1); |
|
| 1370 | + | s[16] = b16 ^ (~b18 & b10); |
|
| 1371 | + | s[17] = b17 ^ (~b19 & b11); |
|
| 1372 | + | s[26] = b26 ^ (~b28 & b20); |
|
| 1373 | + | s[27] = b27 ^ (~b29 & b21); |
|
| 1374 | + | s[36] = b36 ^ (~b38 & b30); |
|
| 1375 | + | s[37] = b37 ^ (~b39 & b31); |
|
| 1376 | + | s[46] = b46 ^ (~b48 & b40); |
|
| 1377 | + | s[47] = b47 ^ (~b49 & b41); |
|
| 1378 | + | s[8] = b8 ^ (~b0 & b2); |
|
| 1379 | + | s[9] = b9 ^ (~b1 & b3); |
|
| 1380 | + | s[18] = b18 ^ (~b10 & b12); |
|
| 1381 | + | s[19] = b19 ^ (~b11 & b13); |
|
| 1382 | + | s[28] = b28 ^ (~b20 & b22); |
|
| 1383 | + | s[29] = b29 ^ (~b21 & b23); |
|
| 1384 | + | s[38] = b38 ^ (~b30 & b32); |
|
| 1385 | + | s[39] = b39 ^ (~b31 & b33); |
|
| 1386 | + | s[48] = b48 ^ (~b40 & b42); |
|
| 1387 | + | s[49] = b49 ^ (~b41 & b43); |
|
| 1034 | 1388 | ||
| 1035 | - | // Export keccak256 function |
|
| 1036 | - | export function keccak256(message) { |
|
| 1037 | - | const keccak = new Keccak(256); |
|
| 1038 | - | keccak.update(message); |
|
| 1039 | - | return "0x" + keccak.hex(); |
|
| 1040 | - | } |
|
| 1389 | + | s[0] ^= RC[n]; |
|
| 1390 | + | s[1] ^= RC[n + 1]; |
|
| 1391 | + | } |
|
| 1392 | + | }; |
|
| 1041 | 1393 | ||
| 1042 | - | // For CommonJS compatibility |
|
| 1043 | - | if (typeof module !== "undefined" && module.exports) { |
|
| 1044 | - | module.exports = { keccak256 }; |
|
| 1045 | - | } |
|
| 1394 | + | if (COMMON_JS) { |
|
| 1395 | + | module.exports = methods; |
|
| 1396 | + | } else { |
|
| 1397 | + | for (i = 0; i < methodNames.length; ++i) { |
|
| 1398 | + | root[methodNames[i]] = methods[methodNames[i]]; |
|
| 1399 | + | } |
|
| 1400 | + | if (AMD) { |
|
| 1401 | + | define(function () { |
|
| 1402 | + | return methods; |
|
| 1403 | + | }); |
|
| 1404 | + | } |
|
| 1405 | + | } |
|
| 1406 | + | })(); |
|