github.com/alexdevranger/node-1.8.27@v0.0.0-20221128213301-aa5841e41d2d/internal/jsre/deps/web3.js (about) 1 require = (function e(t, n, r) { 2 function s(o, u) { 3 if (!n[o]) { 4 if (!t[o]) { 5 var a = typeof require == "function" && require; 6 if (!u && a) return a(o, !0); 7 if (i) return i(o, !0); 8 var f = new Error("Cannot find module '" + o + "'"); 9 throw ((f.code = "MODULE_NOT_FOUND"), f); 10 } 11 var l = (n[o] = { exports: {} }); 12 t[o][0].call( 13 l.exports, 14 function (e) { 15 var n = t[o][1][e]; 16 return s(n ? n : e); 17 }, 18 l, 19 l.exports, 20 e, 21 t, 22 n, 23 r 24 ); 25 } 26 return n[o].exports; 27 } 28 var i = typeof require == "function" && require; 29 for (var o = 0; o < r.length; o++) s(r[o]); 30 return s; 31 })( 32 { 33 1: [ 34 function (require, module, exports) { 35 module.exports = [ 36 { 37 constant: true, 38 inputs: [ 39 { 40 name: "_owner", 41 type: "address", 42 }, 43 ], 44 name: "name", 45 outputs: [ 46 { 47 name: "o_name", 48 type: "bytes32", 49 }, 50 ], 51 type: "function", 52 }, 53 { 54 constant: true, 55 inputs: [ 56 { 57 name: "_name", 58 type: "bytes32", 59 }, 60 ], 61 name: "owner", 62 outputs: [ 63 { 64 name: "", 65 type: "address", 66 }, 67 ], 68 type: "function", 69 }, 70 { 71 constant: true, 72 inputs: [ 73 { 74 name: "_name", 75 type: "bytes32", 76 }, 77 ], 78 name: "content", 79 outputs: [ 80 { 81 name: "", 82 type: "bytes32", 83 }, 84 ], 85 type: "function", 86 }, 87 { 88 constant: true, 89 inputs: [ 90 { 91 name: "_name", 92 type: "bytes32", 93 }, 94 ], 95 name: "addr", 96 outputs: [ 97 { 98 name: "", 99 type: "address", 100 }, 101 ], 102 type: "function", 103 }, 104 { 105 constant: false, 106 inputs: [ 107 { 108 name: "_name", 109 type: "bytes32", 110 }, 111 ], 112 name: "reserve", 113 outputs: [], 114 type: "function", 115 }, 116 { 117 constant: true, 118 inputs: [ 119 { 120 name: "_name", 121 type: "bytes32", 122 }, 123 ], 124 name: "subRegistrar", 125 outputs: [ 126 { 127 name: "", 128 type: "address", 129 }, 130 ], 131 type: "function", 132 }, 133 { 134 constant: false, 135 inputs: [ 136 { 137 name: "_name", 138 type: "bytes32", 139 }, 140 { 141 name: "_newOwner", 142 type: "address", 143 }, 144 ], 145 name: "transfer", 146 outputs: [], 147 type: "function", 148 }, 149 { 150 constant: false, 151 inputs: [ 152 { 153 name: "_name", 154 type: "bytes32", 155 }, 156 { 157 name: "_registrar", 158 type: "address", 159 }, 160 ], 161 name: "setSubRegistrar", 162 outputs: [], 163 type: "function", 164 }, 165 { 166 constant: false, 167 inputs: [], 168 name: "Registrar", 169 outputs: [], 170 type: "function", 171 }, 172 { 173 constant: false, 174 inputs: [ 175 { 176 name: "_name", 177 type: "bytes32", 178 }, 179 { 180 name: "_a", 181 type: "address", 182 }, 183 { 184 name: "_primary", 185 type: "bool", 186 }, 187 ], 188 name: "setAddress", 189 outputs: [], 190 type: "function", 191 }, 192 { 193 constant: false, 194 inputs: [ 195 { 196 name: "_name", 197 type: "bytes32", 198 }, 199 { 200 name: "_content", 201 type: "bytes32", 202 }, 203 ], 204 name: "setContent", 205 outputs: [], 206 type: "function", 207 }, 208 { 209 constant: false, 210 inputs: [ 211 { 212 name: "_name", 213 type: "bytes32", 214 }, 215 ], 216 name: "disown", 217 outputs: [], 218 type: "function", 219 }, 220 { 221 anonymous: false, 222 inputs: [ 223 { 224 indexed: true, 225 name: "_name", 226 type: "bytes32", 227 }, 228 { 229 indexed: false, 230 name: "_winner", 231 type: "address", 232 }, 233 ], 234 name: "AuctionEnded", 235 type: "event", 236 }, 237 { 238 anonymous: false, 239 inputs: [ 240 { 241 indexed: true, 242 name: "_name", 243 type: "bytes32", 244 }, 245 { 246 indexed: false, 247 name: "_bidder", 248 type: "address", 249 }, 250 { 251 indexed: false, 252 name: "_value", 253 type: "uint256", 254 }, 255 ], 256 name: "NewBid", 257 type: "event", 258 }, 259 { 260 anonymous: false, 261 inputs: [ 262 { 263 indexed: true, 264 name: "name", 265 type: "bytes32", 266 }, 267 ], 268 name: "Changed", 269 type: "event", 270 }, 271 { 272 anonymous: false, 273 inputs: [ 274 { 275 indexed: true, 276 name: "name", 277 type: "bytes32", 278 }, 279 { 280 indexed: true, 281 name: "addr", 282 type: "address", 283 }, 284 ], 285 name: "PrimaryChanged", 286 type: "event", 287 }, 288 ]; 289 }, 290 {}, 291 ], 292 2: [ 293 function (require, module, exports) { 294 module.exports = [ 295 { 296 constant: true, 297 inputs: [ 298 { 299 name: "_name", 300 type: "bytes32", 301 }, 302 ], 303 name: "owner", 304 outputs: [ 305 { 306 name: "", 307 type: "address", 308 }, 309 ], 310 type: "function", 311 }, 312 { 313 constant: false, 314 inputs: [ 315 { 316 name: "_name", 317 type: "bytes32", 318 }, 319 { 320 name: "_refund", 321 type: "address", 322 }, 323 ], 324 name: "disown", 325 outputs: [], 326 type: "function", 327 }, 328 { 329 constant: true, 330 inputs: [ 331 { 332 name: "_name", 333 type: "bytes32", 334 }, 335 ], 336 name: "addr", 337 outputs: [ 338 { 339 name: "", 340 type: "address", 341 }, 342 ], 343 type: "function", 344 }, 345 { 346 constant: false, 347 inputs: [ 348 { 349 name: "_name", 350 type: "bytes32", 351 }, 352 ], 353 name: "reserve", 354 outputs: [], 355 type: "function", 356 }, 357 { 358 constant: false, 359 inputs: [ 360 { 361 name: "_name", 362 type: "bytes32", 363 }, 364 { 365 name: "_newOwner", 366 type: "address", 367 }, 368 ], 369 name: "transfer", 370 outputs: [], 371 type: "function", 372 }, 373 { 374 constant: false, 375 inputs: [ 376 { 377 name: "_name", 378 type: "bytes32", 379 }, 380 { 381 name: "_a", 382 type: "address", 383 }, 384 ], 385 name: "setAddr", 386 outputs: [], 387 type: "function", 388 }, 389 { 390 anonymous: false, 391 inputs: [ 392 { 393 indexed: true, 394 name: "name", 395 type: "bytes32", 396 }, 397 ], 398 name: "Changed", 399 type: "event", 400 }, 401 ]; 402 }, 403 {}, 404 ], 405 3: [ 406 function (require, module, exports) { 407 module.exports = [ 408 { 409 constant: false, 410 inputs: [ 411 { 412 name: "from", 413 type: "bytes32", 414 }, 415 { 416 name: "to", 417 type: "address", 418 }, 419 { 420 name: "value", 421 type: "uint256", 422 }, 423 ], 424 name: "transfer", 425 outputs: [], 426 type: "function", 427 }, 428 { 429 constant: false, 430 inputs: [ 431 { 432 name: "from", 433 type: "bytes32", 434 }, 435 { 436 name: "to", 437 type: "address", 438 }, 439 { 440 name: "indirectId", 441 type: "bytes32", 442 }, 443 { 444 name: "value", 445 type: "uint256", 446 }, 447 ], 448 name: "icapTransfer", 449 outputs: [], 450 type: "function", 451 }, 452 { 453 constant: false, 454 inputs: [ 455 { 456 name: "to", 457 type: "bytes32", 458 }, 459 ], 460 name: "deposit", 461 outputs: [], 462 payable: true, 463 type: "function", 464 }, 465 { 466 anonymous: false, 467 inputs: [ 468 { 469 indexed: true, 470 name: "from", 471 type: "address", 472 }, 473 { 474 indexed: false, 475 name: "value", 476 type: "uint256", 477 }, 478 ], 479 name: "AnonymousDeposit", 480 type: "event", 481 }, 482 { 483 anonymous: false, 484 inputs: [ 485 { 486 indexed: true, 487 name: "from", 488 type: "address", 489 }, 490 { 491 indexed: true, 492 name: "to", 493 type: "bytes32", 494 }, 495 { 496 indexed: false, 497 name: "value", 498 type: "uint256", 499 }, 500 ], 501 name: "Deposit", 502 type: "event", 503 }, 504 { 505 anonymous: false, 506 inputs: [ 507 { 508 indexed: true, 509 name: "from", 510 type: "bytes32", 511 }, 512 { 513 indexed: true, 514 name: "to", 515 type: "address", 516 }, 517 { 518 indexed: false, 519 name: "value", 520 type: "uint256", 521 }, 522 ], 523 name: "Transfer", 524 type: "event", 525 }, 526 { 527 anonymous: false, 528 inputs: [ 529 { 530 indexed: true, 531 name: "from", 532 type: "bytes32", 533 }, 534 { 535 indexed: true, 536 name: "to", 537 type: "address", 538 }, 539 { 540 indexed: false, 541 name: "indirectId", 542 type: "bytes32", 543 }, 544 { 545 indexed: false, 546 name: "value", 547 type: "uint256", 548 }, 549 ], 550 name: "IcapTransfer", 551 type: "event", 552 }, 553 ]; 554 }, 555 {}, 556 ], 557 4: [ 558 function (require, module, exports) { 559 var f = require("./formatters"); 560 var SolidityType = require("./type"); 561 562 /** 563 * SolidityTypeAddress is a prootype that represents address type 564 * It matches: 565 * address 566 * address[] 567 * address[4] 568 * address[][] 569 * address[3][] 570 * address[][6][], ... 571 */ 572 var SolidityTypeAddress = function () { 573 this._inputFormatter = f.formatInputInt; 574 this._outputFormatter = f.formatOutputAddress; 575 }; 576 577 SolidityTypeAddress.prototype = new SolidityType({}); 578 SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 579 580 SolidityTypeAddress.prototype.isType = function (name) { 581 return !!name.match(/address(\[([0-9]*)\])?/); 582 }; 583 584 module.exports = SolidityTypeAddress; 585 }, 586 { "./formatters": 9, "./type": 14 }, 587 ], 588 5: [ 589 function (require, module, exports) { 590 var f = require("./formatters"); 591 var SolidityType = require("./type"); 592 593 /** 594 * SolidityTypeBool is a prootype that represents bool type 595 * It matches: 596 * bool 597 * bool[] 598 * bool[4] 599 * bool[][] 600 * bool[3][] 601 * bool[][6][], ... 602 */ 603 var SolidityTypeBool = function () { 604 this._inputFormatter = f.formatInputBool; 605 this._outputFormatter = f.formatOutputBool; 606 }; 607 608 SolidityTypeBool.prototype = new SolidityType({}); 609 SolidityTypeBool.prototype.constructor = SolidityTypeBool; 610 611 SolidityTypeBool.prototype.isType = function (name) { 612 return !!name.match(/^bool(\[([0-9]*)\])*$/); 613 }; 614 615 module.exports = SolidityTypeBool; 616 }, 617 { "./formatters": 9, "./type": 14 }, 618 ], 619 6: [ 620 function (require, module, exports) { 621 var f = require("./formatters"); 622 var SolidityType = require("./type"); 623 624 /** 625 * SolidityTypeBytes is a prototype that represents the bytes type. 626 * It matches: 627 * bytes 628 * bytes[] 629 * bytes[4] 630 * bytes[][] 631 * bytes[3][] 632 * bytes[][6][], ... 633 * bytes32 634 * bytes8[4] 635 * bytes[3][] 636 */ 637 var SolidityTypeBytes = function () { 638 this._inputFormatter = f.formatInputBytes; 639 this._outputFormatter = f.formatOutputBytes; 640 }; 641 642 SolidityTypeBytes.prototype = new SolidityType({}); 643 SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 644 645 SolidityTypeBytes.prototype.isType = function (name) { 646 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 647 }; 648 649 module.exports = SolidityTypeBytes; 650 }, 651 { "./formatters": 9, "./type": 14 }, 652 ], 653 7: [ 654 function (require, module, exports) { 655 /* 656 This file is part of web3.js. 657 658 web3.js is free software: you can redistribute it and/or modify 659 it under the terms of the GNU Lesser General Public License as published by 660 the Free Software Foundation, either version 3 of the License, or 661 (at your option) any later version. 662 663 web3.js is distributed in the hope that it will be useful, 664 but WITHOUT ANY WARRANTY; without even the implied warranty of 665 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 666 GNU Lesser General Public License for more details. 667 668 You should have received a copy of the GNU Lesser General Public License 669 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 670 */ 671 /** 672 * @file coder.js 673 * @author Marek Kotewicz <marek@ethdev.com> 674 * @date 2015 675 */ 676 677 var f = require("./formatters"); 678 679 var SolidityTypeAddress = require("./address"); 680 var SolidityTypeBool = require("./bool"); 681 var SolidityTypeInt = require("./int"); 682 var SolidityTypeUInt = require("./uint"); 683 var SolidityTypeDynamicBytes = require("./dynamicbytes"); 684 var SolidityTypeString = require("./string"); 685 var SolidityTypeReal = require("./real"); 686 var SolidityTypeUReal = require("./ureal"); 687 var SolidityTypeBytes = require("./bytes"); 688 689 var isDynamic = function (solidityType, type) { 690 return ( 691 solidityType.isDynamicType(type) || 692 solidityType.isDynamicArray(type) 693 ); 694 }; 695 696 /** 697 * SolidityCoder prototype should be used to encode/decode solidity params of any type 698 */ 699 var SolidityCoder = function (types) { 700 this._types = types; 701 }; 702 703 /** 704 * This method should be used to transform type to SolidityType 705 * 706 * @method _requireType 707 * @param {String} type 708 * @returns {SolidityType} 709 * @throws {Error} throws if no matching type is found 710 */ 711 SolidityCoder.prototype._requireType = function (type) { 712 var solidityType = this._types.filter(function (t) { 713 return t.isType(type); 714 })[0]; 715 716 if (!solidityType) { 717 throw Error("invalid solidity type!: " + type); 718 } 719 720 return solidityType; 721 }; 722 723 /** 724 * Should be used to encode plain param 725 * 726 * @method encodeParam 727 * @param {String} type 728 * @param {Object} plain param 729 * @return {String} encoded plain param 730 */ 731 SolidityCoder.prototype.encodeParam = function (type, param) { 732 return this.encodeParams([type], [param]); 733 }; 734 735 /** 736 * Should be used to encode list of params 737 * 738 * @method encodeParams 739 * @param {Array} types 740 * @param {Array} params 741 * @return {String} encoded list of params 742 */ 743 SolidityCoder.prototype.encodeParams = function (types, params) { 744 var solidityTypes = this.getSolidityTypes(types); 745 746 var encodeds = solidityTypes.map(function (solidityType, index) { 747 return solidityType.encode(params[index], types[index]); 748 }); 749 750 var dynamicOffset = solidityTypes.reduce(function ( 751 acc, 752 solidityType, 753 index 754 ) { 755 var staticPartLength = solidityType.staticPartLength(types[index]); 756 var roundedStaticPartLength = 757 Math.floor((staticPartLength + 31) / 32) * 32; 758 759 return ( 760 acc + 761 (isDynamic(solidityTypes[index], types[index]) 762 ? 32 763 : roundedStaticPartLength) 764 ); 765 }, 766 0); 767 768 var result = this.encodeMultiWithOffset( 769 types, 770 solidityTypes, 771 encodeds, 772 dynamicOffset 773 ); 774 775 return result; 776 }; 777 778 SolidityCoder.prototype.encodeMultiWithOffset = function ( 779 types, 780 solidityTypes, 781 encodeds, 782 dynamicOffset 783 ) { 784 var result = ""; 785 var self = this; 786 787 types.forEach(function (type, i) { 788 if (isDynamic(solidityTypes[i], types[i])) { 789 result += f.formatInputInt(dynamicOffset).encode(); 790 var e = self.encodeWithOffset( 791 types[i], 792 solidityTypes[i], 793 encodeds[i], 794 dynamicOffset 795 ); 796 dynamicOffset += e.length / 2; 797 } else { 798 // don't add length to dynamicOffset. it's already counted 799 result += self.encodeWithOffset( 800 types[i], 801 solidityTypes[i], 802 encodeds[i], 803 dynamicOffset 804 ); 805 } 806 807 // TODO: figure out nested arrays 808 }); 809 810 types.forEach(function (type, i) { 811 if (isDynamic(solidityTypes[i], types[i])) { 812 var e = self.encodeWithOffset( 813 types[i], 814 solidityTypes[i], 815 encodeds[i], 816 dynamicOffset 817 ); 818 dynamicOffset += e.length / 2; 819 result += e; 820 } 821 }); 822 return result; 823 }; 824 825 // TODO: refactor whole encoding! 826 SolidityCoder.prototype.encodeWithOffset = function ( 827 type, 828 solidityType, 829 encoded, 830 offset 831 ) { 832 var self = this; 833 if (solidityType.isDynamicArray(type)) { 834 return (function () { 835 // offset was already set 836 var nestedName = solidityType.nestedName(type); 837 var nestedStaticPartLength = 838 solidityType.staticPartLength(nestedName); 839 var result = encoded[0]; 840 841 (function () { 842 var previousLength = 2; // in int 843 if (solidityType.isDynamicArray(nestedName)) { 844 for (var i = 1; i < encoded.length; i++) { 845 previousLength += +encoded[i - 1][0] || 0; 846 result += f 847 .formatInputInt( 848 offset + 849 i * nestedStaticPartLength + 850 previousLength * 32 851 ) 852 .encode(); 853 } 854 } 855 })(); 856 857 // first element is length, skip it 858 (function () { 859 for (var i = 0; i < encoded.length - 1; i++) { 860 var additionalOffset = result / 2; 861 result += self.encodeWithOffset( 862 nestedName, 863 solidityType, 864 encoded[i + 1], 865 offset + additionalOffset 866 ); 867 } 868 })(); 869 870 return result; 871 })(); 872 } else if (solidityType.isStaticArray(type)) { 873 return (function () { 874 var nestedName = solidityType.nestedName(type); 875 var nestedStaticPartLength = 876 solidityType.staticPartLength(nestedName); 877 var result = ""; 878 879 if (solidityType.isDynamicArray(nestedName)) { 880 (function () { 881 var previousLength = 0; // in int 882 for (var i = 0; i < encoded.length; i++) { 883 // calculate length of previous item 884 previousLength += +(encoded[i - 1] || [])[0] || 0; 885 result += f 886 .formatInputInt( 887 offset + 888 i * nestedStaticPartLength + 889 previousLength * 32 890 ) 891 .encode(); 892 } 893 })(); 894 } 895 896 (function () { 897 for (var i = 0; i < encoded.length; i++) { 898 var additionalOffset = result / 2; 899 result += self.encodeWithOffset( 900 nestedName, 901 solidityType, 902 encoded[i], 903 offset + additionalOffset 904 ); 905 } 906 })(); 907 908 return result; 909 })(); 910 } 911 912 return encoded; 913 }; 914 915 /** 916 * Should be used to decode bytes to plain param 917 * 918 * @method decodeParam 919 * @param {String} type 920 * @param {String} bytes 921 * @return {Object} plain param 922 */ 923 SolidityCoder.prototype.decodeParam = function (type, bytes) { 924 return this.decodeParams([type], bytes)[0]; 925 }; 926 927 /** 928 * Should be used to decode list of params 929 * 930 * @method decodeParam 931 * @param {Array} types 932 * @param {String} bytes 933 * @return {Array} array of plain params 934 */ 935 SolidityCoder.prototype.decodeParams = function (types, bytes) { 936 var solidityTypes = this.getSolidityTypes(types); 937 var offsets = this.getOffsets(types, solidityTypes); 938 939 return solidityTypes.map(function (solidityType, index) { 940 return solidityType.decode( 941 bytes, 942 offsets[index], 943 types[index], 944 index 945 ); 946 }); 947 }; 948 949 SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { 950 var lengths = solidityTypes.map(function (solidityType, index) { 951 return solidityType.staticPartLength(types[index]); 952 }); 953 954 for (var i = 1; i < lengths.length; i++) { 955 // sum with length of previous element 956 lengths[i] += lengths[i - 1]; 957 } 958 959 return lengths.map(function (length, index) { 960 // remove the current length, so the length is sum of previous elements 961 var staticPartLength = solidityTypes[index].staticPartLength( 962 types[index] 963 ); 964 return length - staticPartLength; 965 }); 966 }; 967 968 SolidityCoder.prototype.getSolidityTypes = function (types) { 969 var self = this; 970 return types.map(function (type) { 971 return self._requireType(type); 972 }); 973 }; 974 975 var coder = new SolidityCoder([ 976 new SolidityTypeAddress(), 977 new SolidityTypeBool(), 978 new SolidityTypeInt(), 979 new SolidityTypeUInt(), 980 new SolidityTypeDynamicBytes(), 981 new SolidityTypeBytes(), 982 new SolidityTypeString(), 983 new SolidityTypeReal(), 984 new SolidityTypeUReal(), 985 ]); 986 987 module.exports = coder; 988 }, 989 { 990 "./address": 4, 991 "./bool": 5, 992 "./bytes": 6, 993 "./dynamicbytes": 8, 994 "./formatters": 9, 995 "./int": 10, 996 "./real": 12, 997 "./string": 13, 998 "./uint": 15, 999 "./ureal": 16, 1000 }, 1001 ], 1002 8: [ 1003 function (require, module, exports) { 1004 var f = require("./formatters"); 1005 var SolidityType = require("./type"); 1006 1007 var SolidityTypeDynamicBytes = function () { 1008 this._inputFormatter = f.formatInputDynamicBytes; 1009 this._outputFormatter = f.formatOutputDynamicBytes; 1010 }; 1011 1012 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 1013 SolidityTypeDynamicBytes.prototype.constructor = 1014 SolidityTypeDynamicBytes; 1015 1016 SolidityTypeDynamicBytes.prototype.isType = function (name) { 1017 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 1018 }; 1019 1020 SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 1021 return true; 1022 }; 1023 1024 module.exports = SolidityTypeDynamicBytes; 1025 }, 1026 { "./formatters": 9, "./type": 14 }, 1027 ], 1028 9: [ 1029 function (require, module, exports) { 1030 /* 1031 This file is part of web3.js. 1032 1033 web3.js is free software: you can redistribute it and/or modify 1034 it under the terms of the GNU Lesser General Public License as published by 1035 the Free Software Foundation, either version 3 of the License, or 1036 (at your option) any later version. 1037 1038 web3.js is distributed in the hope that it will be useful, 1039 but WITHOUT ANY WARRANTY; without even the implied warranty of 1040 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1041 GNU Lesser General Public License for more details. 1042 1043 You should have received a copy of the GNU Lesser General Public License 1044 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1045 */ 1046 /** 1047 * @file formatters.js 1048 * @author Marek Kotewicz <marek@ethdev.com> 1049 * @date 2015 1050 */ 1051 1052 var BigNumber = require("bignumber.js"); 1053 var utils = require("../utils/utils"); 1054 var c = require("../utils/config"); 1055 var SolidityParam = require("./param"); 1056 1057 /** 1058 * Formats input value to byte representation of int 1059 * If value is negative, return it's two's complement 1060 * If the value is floating point, round it down 1061 * 1062 * @method formatInputInt 1063 * @param {String|Number|BigNumber} value that needs to be formatted 1064 * @returns {SolidityParam} 1065 */ 1066 var formatInputInt = function (value) { 1067 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 1068 var result = utils.padLeft( 1069 utils.toTwosComplement(value).toString(16), 1070 64 1071 ); 1072 return new SolidityParam(result); 1073 }; 1074 1075 /** 1076 * Formats input bytes 1077 * 1078 * @method formatInputBytes 1079 * @param {String} 1080 * @returns {SolidityParam} 1081 */ 1082 var formatInputBytes = function (value) { 1083 var result = utils.toHex(value).substr(2); 1084 var l = Math.floor((result.length + 63) / 64); 1085 result = utils.padRight(result, l * 64); 1086 return new SolidityParam(result); 1087 }; 1088 1089 /** 1090 * Formats input bytes 1091 * 1092 * @method formatDynamicInputBytes 1093 * @param {String} 1094 * @returns {SolidityParam} 1095 */ 1096 var formatInputDynamicBytes = function (value) { 1097 var result = utils.toHex(value).substr(2); 1098 var length = result.length / 2; 1099 var l = Math.floor((result.length + 63) / 64); 1100 result = utils.padRight(result, l * 64); 1101 return new SolidityParam(formatInputInt(length).value + result); 1102 }; 1103 1104 /** 1105 * Formats input value to byte representation of string 1106 * 1107 * @method formatInputString 1108 * @param {String} 1109 * @returns {SolidityParam} 1110 */ 1111 var formatInputString = function (value) { 1112 var result = utils.fromUtf8(value).substr(2); 1113 var length = result.length / 2; 1114 var l = Math.floor((result.length + 63) / 64); 1115 result = utils.padRight(result, l * 64); 1116 return new SolidityParam(formatInputInt(length).value + result); 1117 }; 1118 1119 /** 1120 * Formats input value to byte representation of bool 1121 * 1122 * @method formatInputBool 1123 * @param {Boolean} 1124 * @returns {SolidityParam} 1125 */ 1126 var formatInputBool = function (value) { 1127 var result = 1128 "000000000000000000000000000000000000000000000000000000000000000" + 1129 (value ? "1" : "0"); 1130 return new SolidityParam(result); 1131 }; 1132 1133 /** 1134 * Formats input value to byte representation of real 1135 * Values are multiplied by 2^m and encoded as integers 1136 * 1137 * @method formatInputReal 1138 * @param {String|Number|BigNumber} 1139 * @returns {SolidityParam} 1140 */ 1141 var formatInputReal = function (value) { 1142 return formatInputInt( 1143 new BigNumber(value).times(new BigNumber(2).pow(128)) 1144 ); 1145 }; 1146 1147 /** 1148 * Check if input value is negative 1149 * 1150 * @method signedIsNegative 1151 * @param {String} value is hex format 1152 * @returns {Boolean} true if it is negative, otherwise false 1153 */ 1154 var signedIsNegative = function (value) { 1155 return ( 1156 new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1) === 1157 "1" 1158 ); 1159 }; 1160 1161 /** 1162 * Formats right-aligned output bytes to int 1163 * 1164 * @method formatOutputInt 1165 * @param {SolidityParam} param 1166 * @returns {BigNumber} right-aligned output bytes formatted to big number 1167 */ 1168 var formatOutputInt = function (param) { 1169 var value = param.staticPart() || "0"; 1170 1171 // check if it's negative number 1172 // it is, return two's complement 1173 if (signedIsNegative(value)) { 1174 return new BigNumber(value, 16) 1175 .minus( 1176 new BigNumber( 1177 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 1178 16 1179 ) 1180 ) 1181 .minus(1); 1182 } 1183 return new BigNumber(value, 16); 1184 }; 1185 1186 /** 1187 * Formats right-aligned output bytes to uint 1188 * 1189 * @method formatOutputUInt 1190 * @param {SolidityParam} 1191 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1192 */ 1193 var formatOutputUInt = function (param) { 1194 var value = param.staticPart() || "0"; 1195 return new BigNumber(value, 16); 1196 }; 1197 1198 /** 1199 * Formats right-aligned output bytes to real 1200 * 1201 * @method formatOutputReal 1202 * @param {SolidityParam} 1203 * @returns {BigNumber} input bytes formatted to real 1204 */ 1205 var formatOutputReal = function (param) { 1206 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1207 }; 1208 1209 /** 1210 * Formats right-aligned output bytes to ureal 1211 * 1212 * @method formatOutputUReal 1213 * @param {SolidityParam} 1214 * @returns {BigNumber} input bytes formatted to ureal 1215 */ 1216 var formatOutputUReal = function (param) { 1217 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1218 }; 1219 1220 /** 1221 * Should be used to format output bool 1222 * 1223 * @method formatOutputBool 1224 * @param {SolidityParam} 1225 * @returns {Boolean} right-aligned input bytes formatted to bool 1226 */ 1227 var formatOutputBool = function (param) { 1228 return param.staticPart() === 1229 "0000000000000000000000000000000000000000000000000000000000000001" 1230 ? true 1231 : false; 1232 }; 1233 1234 /** 1235 * Should be used to format output bytes 1236 * 1237 * @method formatOutputBytes 1238 * @param {SolidityParam} left-aligned hex representation of string 1239 * @param {String} name type name 1240 * @returns {String} hex string 1241 */ 1242 var formatOutputBytes = function (param, name) { 1243 var matches = name.match(/^bytes([0-9]*)/); 1244 var size = parseInt(matches[1]); 1245 return "0x" + param.staticPart().slice(0, 2 * size); 1246 }; 1247 1248 /** 1249 * Should be used to format output bytes 1250 * 1251 * @method formatOutputDynamicBytes 1252 * @param {SolidityParam} left-aligned hex representation of string 1253 * @returns {String} hex string 1254 */ 1255 var formatOutputDynamicBytes = function (param) { 1256 var length = 1257 new BigNumber(param.dynamicPart().slice(0, 64), 16).toNumber() * 2; 1258 return "0x" + param.dynamicPart().substr(64, length); 1259 }; 1260 1261 /** 1262 * Should be used to format output string 1263 * 1264 * @method formatOutputString 1265 * @param {SolidityParam} left-aligned hex representation of string 1266 * @returns {String} ascii string 1267 */ 1268 var formatOutputString = function (param) { 1269 var length = 1270 new BigNumber(param.dynamicPart().slice(0, 64), 16).toNumber() * 2; 1271 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1272 }; 1273 1274 /** 1275 * Should be used to format output address 1276 * 1277 * @method formatOutputAddress 1278 * @param {SolidityParam} right-aligned input bytes 1279 * @returns {String} address 1280 */ 1281 var formatOutputAddress = function (param) { 1282 var value = param.staticPart(); 1283 return "0x" + value.slice(value.length - 40, value.length); 1284 }; 1285 1286 module.exports = { 1287 formatInputInt: formatInputInt, 1288 formatInputBytes: formatInputBytes, 1289 formatInputDynamicBytes: formatInputDynamicBytes, 1290 formatInputString: formatInputString, 1291 formatInputBool: formatInputBool, 1292 formatInputReal: formatInputReal, 1293 formatOutputInt: formatOutputInt, 1294 formatOutputUInt: formatOutputUInt, 1295 formatOutputReal: formatOutputReal, 1296 formatOutputUReal: formatOutputUReal, 1297 formatOutputBool: formatOutputBool, 1298 formatOutputBytes: formatOutputBytes, 1299 formatOutputDynamicBytes: formatOutputDynamicBytes, 1300 formatOutputString: formatOutputString, 1301 formatOutputAddress: formatOutputAddress, 1302 }; 1303 }, 1304 { 1305 "../utils/config": 18, 1306 "../utils/utils": 20, 1307 "./param": 11, 1308 "bignumber.js": "bignumber.js", 1309 }, 1310 ], 1311 10: [ 1312 function (require, module, exports) { 1313 var f = require("./formatters"); 1314 var SolidityType = require("./type"); 1315 1316 /** 1317 * SolidityTypeInt is a prootype that represents int type 1318 * It matches: 1319 * int 1320 * int[] 1321 * int[4] 1322 * int[][] 1323 * int[3][] 1324 * int[][6][], ... 1325 * int32 1326 * int64[] 1327 * int8[4] 1328 * int256[][] 1329 * int[3][] 1330 * int64[][6][], ... 1331 */ 1332 var SolidityTypeInt = function () { 1333 this._inputFormatter = f.formatInputInt; 1334 this._outputFormatter = f.formatOutputInt; 1335 }; 1336 1337 SolidityTypeInt.prototype = new SolidityType({}); 1338 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1339 1340 SolidityTypeInt.prototype.isType = function (name) { 1341 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1342 }; 1343 1344 module.exports = SolidityTypeInt; 1345 }, 1346 { "./formatters": 9, "./type": 14 }, 1347 ], 1348 11: [ 1349 function (require, module, exports) { 1350 /* 1351 This file is part of web3.js. 1352 1353 web3.js is free software: you can redistribute it and/or modify 1354 it under the terms of the GNU Lesser General Public License as published by 1355 the Free Software Foundation, either version 3 of the License, or 1356 (at your option) any later version. 1357 1358 web3.js is distributed in the hope that it will be useful, 1359 but WITHOUT ANY WARRANTY; without even the implied warranty of 1360 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1361 GNU Lesser General Public License for more details. 1362 1363 You should have received a copy of the GNU Lesser General Public License 1364 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1365 */ 1366 /** 1367 * @file param.js 1368 * @author Marek Kotewicz <marek@ethdev.com> 1369 * @date 2015 1370 */ 1371 1372 var utils = require("../utils/utils"); 1373 1374 /** 1375 * SolidityParam object prototype. 1376 * Should be used when encoding, decoding solidity bytes 1377 */ 1378 var SolidityParam = function (value, offset) { 1379 this.value = value || ""; 1380 this.offset = offset; // offset in bytes 1381 }; 1382 1383 /** 1384 * This method should be used to get length of params's dynamic part 1385 * 1386 * @method dynamicPartLength 1387 * @returns {Number} length of dynamic part (in bytes) 1388 */ 1389 SolidityParam.prototype.dynamicPartLength = function () { 1390 return this.dynamicPart().length / 2; 1391 }; 1392 1393 /** 1394 * This method should be used to create copy of solidity param with different offset 1395 * 1396 * @method withOffset 1397 * @param {Number} offset length in bytes 1398 * @returns {SolidityParam} new solidity param with applied offset 1399 */ 1400 SolidityParam.prototype.withOffset = function (offset) { 1401 return new SolidityParam(this.value, offset); 1402 }; 1403 1404 /** 1405 * This method should be used to combine solidity params together 1406 * eg. when appending an array 1407 * 1408 * @method combine 1409 * @param {SolidityParam} param with which we should combine 1410 * @param {SolidityParam} result of combination 1411 */ 1412 SolidityParam.prototype.combine = function (param) { 1413 return new SolidityParam(this.value + param.value); 1414 }; 1415 1416 /** 1417 * This method should be called to check if param has dynamic size. 1418 * If it has, it returns true, otherwise false 1419 * 1420 * @method isDynamic 1421 * @returns {Boolean} 1422 */ 1423 SolidityParam.prototype.isDynamic = function () { 1424 return this.offset !== undefined; 1425 }; 1426 1427 /** 1428 * This method should be called to transform offset to bytes 1429 * 1430 * @method offsetAsBytes 1431 * @returns {String} bytes representation of offset 1432 */ 1433 SolidityParam.prototype.offsetAsBytes = function () { 1434 return !this.isDynamic() 1435 ? "" 1436 : utils.padLeft( 1437 utils.toTwosComplement(this.offset).toString(16), 1438 64 1439 ); 1440 }; 1441 1442 /** 1443 * This method should be called to get static part of param 1444 * 1445 * @method staticPart 1446 * @returns {String} offset if it is a dynamic param, otherwise value 1447 */ 1448 SolidityParam.prototype.staticPart = function () { 1449 if (!this.isDynamic()) { 1450 return this.value; 1451 } 1452 return this.offsetAsBytes(); 1453 }; 1454 1455 /** 1456 * This method should be called to get dynamic part of param 1457 * 1458 * @method dynamicPart 1459 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1460 */ 1461 SolidityParam.prototype.dynamicPart = function () { 1462 return this.isDynamic() ? this.value : ""; 1463 }; 1464 1465 /** 1466 * This method should be called to encode param 1467 * 1468 * @method encode 1469 * @returns {String} 1470 */ 1471 SolidityParam.prototype.encode = function () { 1472 return this.staticPart() + this.dynamicPart(); 1473 }; 1474 1475 /** 1476 * This method should be called to encode array of params 1477 * 1478 * @method encodeList 1479 * @param {Array[SolidityParam]} params 1480 * @returns {String} 1481 */ 1482 SolidityParam.encodeList = function (params) { 1483 // updating offsets 1484 var totalOffset = params.length * 32; 1485 var offsetParams = params.map(function (param) { 1486 if (!param.isDynamic()) { 1487 return param; 1488 } 1489 var offset = totalOffset; 1490 totalOffset += param.dynamicPartLength(); 1491 return param.withOffset(offset); 1492 }); 1493 1494 // encode everything! 1495 return offsetParams.reduce( 1496 function (result, param) { 1497 return result + param.dynamicPart(); 1498 }, 1499 offsetParams.reduce(function (result, param) { 1500 return result + param.staticPart(); 1501 }, "") 1502 ); 1503 }; 1504 1505 module.exports = SolidityParam; 1506 }, 1507 { "../utils/utils": 20 }, 1508 ], 1509 12: [ 1510 function (require, module, exports) { 1511 var f = require("./formatters"); 1512 var SolidityType = require("./type"); 1513 1514 /** 1515 * SolidityTypeReal is a prootype that represents real type 1516 * It matches: 1517 * real 1518 * real[] 1519 * real[4] 1520 * real[][] 1521 * real[3][] 1522 * real[][6][], ... 1523 * real32 1524 * real64[] 1525 * real8[4] 1526 * real256[][] 1527 * real[3][] 1528 * real64[][6][], ... 1529 */ 1530 var SolidityTypeReal = function () { 1531 this._inputFormatter = f.formatInputReal; 1532 this._outputFormatter = f.formatOutputReal; 1533 }; 1534 1535 SolidityTypeReal.prototype = new SolidityType({}); 1536 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1537 1538 SolidityTypeReal.prototype.isType = function (name) { 1539 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1540 }; 1541 1542 module.exports = SolidityTypeReal; 1543 }, 1544 { "./formatters": 9, "./type": 14 }, 1545 ], 1546 13: [ 1547 function (require, module, exports) { 1548 var f = require("./formatters"); 1549 var SolidityType = require("./type"); 1550 1551 var SolidityTypeString = function () { 1552 this._inputFormatter = f.formatInputString; 1553 this._outputFormatter = f.formatOutputString; 1554 }; 1555 1556 SolidityTypeString.prototype = new SolidityType({}); 1557 SolidityTypeString.prototype.constructor = SolidityTypeString; 1558 1559 SolidityTypeString.prototype.isType = function (name) { 1560 return !!name.match(/^string(\[([0-9]*)\])*$/); 1561 }; 1562 1563 SolidityTypeString.prototype.isDynamicType = function () { 1564 return true; 1565 }; 1566 1567 module.exports = SolidityTypeString; 1568 }, 1569 { "./formatters": 9, "./type": 14 }, 1570 ], 1571 14: [ 1572 function (require, module, exports) { 1573 var f = require("./formatters"); 1574 var SolidityParam = require("./param"); 1575 1576 /** 1577 * SolidityType prototype is used to encode/decode solidity params of certain type 1578 */ 1579 var SolidityType = function (config) { 1580 this._inputFormatter = config.inputFormatter; 1581 this._outputFormatter = config.outputFormatter; 1582 }; 1583 1584 /** 1585 * Should be used to determine if this SolidityType do match given name 1586 * 1587 * @method isType 1588 * @param {String} name 1589 * @return {Bool} true if type match this SolidityType, otherwise false 1590 */ 1591 SolidityType.prototype.isType = function (name) { 1592 throw "this method should be overrwritten for type " + name; 1593 }; 1594 1595 /** 1596 * Should be used to determine what is the length of static part in given type 1597 * 1598 * @method staticPartLength 1599 * @param {String} name 1600 * @return {Number} length of static part in bytes 1601 */ 1602 SolidityType.prototype.staticPartLength = function (name) { 1603 // If name isn't an array then treat it like a single element array. 1604 return (this.nestedTypes(name) || ["[1]"]) 1605 .map(function (type) { 1606 // the length of the nested array 1607 return parseInt(type.slice(1, -1), 10) || 1; 1608 }) 1609 .reduce(function (previous, current) { 1610 return previous * current; 1611 // all basic types are 32 bytes long 1612 }, 32); 1613 }; 1614 1615 /** 1616 * Should be used to determine if type is dynamic array 1617 * eg: 1618 * "type[]" => true 1619 * "type[4]" => false 1620 * 1621 * @method isDynamicArray 1622 * @param {String} name 1623 * @return {Bool} true if the type is dynamic array 1624 */ 1625 SolidityType.prototype.isDynamicArray = function (name) { 1626 var nestedTypes = this.nestedTypes(name); 1627 return ( 1628 !!nestedTypes && 1629 !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) 1630 ); 1631 }; 1632 1633 /** 1634 * Should be used to determine if type is static array 1635 * eg: 1636 * "type[]" => false 1637 * "type[4]" => true 1638 * 1639 * @method isStaticArray 1640 * @param {String} name 1641 * @return {Bool} true if the type is static array 1642 */ 1643 SolidityType.prototype.isStaticArray = function (name) { 1644 var nestedTypes = this.nestedTypes(name); 1645 return ( 1646 !!nestedTypes && 1647 !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) 1648 ); 1649 }; 1650 1651 /** 1652 * Should return length of static array 1653 * eg. 1654 * "int[32]" => 32 1655 * "int256[14]" => 14 1656 * "int[2][3]" => 3 1657 * "int" => 1 1658 * "int[1]" => 1 1659 * "int[]" => 1 1660 * 1661 * @method staticArrayLength 1662 * @param {String} name 1663 * @return {Number} static array length 1664 */ 1665 SolidityType.prototype.staticArrayLength = function (name) { 1666 var nestedTypes = this.nestedTypes(name); 1667 if (nestedTypes) { 1668 return parseInt( 1669 nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1 1670 ); 1671 } 1672 return 1; 1673 }; 1674 1675 /** 1676 * Should return nested type 1677 * eg. 1678 * "int[32]" => "int" 1679 * "int256[14]" => "int256" 1680 * "int[2][3]" => "int[2]" 1681 * "int" => "int" 1682 * "int[]" => "int" 1683 * 1684 * @method nestedName 1685 * @param {String} name 1686 * @return {String} nested name 1687 */ 1688 SolidityType.prototype.nestedName = function (name) { 1689 // remove last [] in name 1690 var nestedTypes = this.nestedTypes(name); 1691 if (!nestedTypes) { 1692 return name; 1693 } 1694 1695 return name.substr( 1696 0, 1697 name.length - nestedTypes[nestedTypes.length - 1].length 1698 ); 1699 }; 1700 1701 /** 1702 * Should return true if type has dynamic size by default 1703 * such types are "string", "bytes" 1704 * 1705 * @method isDynamicType 1706 * @param {String} name 1707 * @return {Bool} true if is dynamic, otherwise false 1708 */ 1709 SolidityType.prototype.isDynamicType = function () { 1710 return false; 1711 }; 1712 1713 /** 1714 * Should return array of nested types 1715 * eg. 1716 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1717 * "int[] => ["[]"] 1718 * "int" => null 1719 * 1720 * @method nestedTypes 1721 * @param {String} name 1722 * @return {Array} array of nested types 1723 */ 1724 SolidityType.prototype.nestedTypes = function (name) { 1725 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1726 return name.match(/(\[[0-9]*\])/g); 1727 }; 1728 1729 /** 1730 * Should be used to encode the value 1731 * 1732 * @method encode 1733 * @param {Object} value 1734 * @param {String} name 1735 * @return {String} encoded value 1736 */ 1737 SolidityType.prototype.encode = function (value, name) { 1738 var self = this; 1739 if (this.isDynamicArray(name)) { 1740 return (function () { 1741 var length = value.length; // in int 1742 var nestedName = self.nestedName(name); 1743 1744 var result = []; 1745 result.push(f.formatInputInt(length).encode()); 1746 1747 value.forEach(function (v) { 1748 result.push(self.encode(v, nestedName)); 1749 }); 1750 1751 return result; 1752 })(); 1753 } else if (this.isStaticArray(name)) { 1754 return (function () { 1755 var length = self.staticArrayLength(name); // in int 1756 var nestedName = self.nestedName(name); 1757 1758 var result = []; 1759 for (var i = 0; i < length; i++) { 1760 result.push(self.encode(value[i], nestedName)); 1761 } 1762 1763 return result; 1764 })(); 1765 } 1766 1767 return this._inputFormatter(value, name).encode(); 1768 }; 1769 1770 /** 1771 * Should be used to decode value from bytes 1772 * 1773 * @method decode 1774 * @param {String} bytes 1775 * @param {Number} offset in bytes 1776 * @param {String} name type name 1777 * @returns {Object} decoded value 1778 */ 1779 SolidityType.prototype.decode = function (bytes, offset, name) { 1780 var self = this; 1781 1782 if (this.isDynamicArray(name)) { 1783 return (function () { 1784 var arrayOffset = parseInt("0x" + bytes.substr(offset * 2, 64)); // in bytes 1785 var length = parseInt("0x" + bytes.substr(arrayOffset * 2, 64)); // in int 1786 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1787 1788 var nestedName = self.nestedName(name); 1789 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1790 var roundedNestedStaticPartLength = 1791 Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1792 var result = []; 1793 1794 for ( 1795 var i = 0; 1796 i < length * roundedNestedStaticPartLength; 1797 i += roundedNestedStaticPartLength 1798 ) { 1799 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1800 } 1801 1802 return result; 1803 })(); 1804 } else if (this.isStaticArray(name)) { 1805 return (function () { 1806 var length = self.staticArrayLength(name); // in int 1807 var arrayStart = offset; // in bytes 1808 1809 var nestedName = self.nestedName(name); 1810 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1811 var roundedNestedStaticPartLength = 1812 Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1813 var result = []; 1814 1815 for ( 1816 var i = 0; 1817 i < length * roundedNestedStaticPartLength; 1818 i += roundedNestedStaticPartLength 1819 ) { 1820 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1821 } 1822 1823 return result; 1824 })(); 1825 } else if (this.isDynamicType(name)) { 1826 return (function () { 1827 var dynamicOffset = parseInt("0x" + bytes.substr(offset * 2, 64)); // in bytes 1828 var length = parseInt("0x" + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1829 var roundedLength = Math.floor((length + 31) / 32); // in int 1830 var param = new SolidityParam( 1831 bytes.substr(dynamicOffset * 2, (1 + roundedLength) * 64), 1832 0 1833 ); 1834 return self._outputFormatter(param, name); 1835 })(); 1836 } 1837 1838 var length = this.staticPartLength(name); 1839 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1840 return this._outputFormatter(param, name); 1841 }; 1842 1843 module.exports = SolidityType; 1844 }, 1845 { "./formatters": 9, "./param": 11 }, 1846 ], 1847 15: [ 1848 function (require, module, exports) { 1849 var f = require("./formatters"); 1850 var SolidityType = require("./type"); 1851 1852 /** 1853 * SolidityTypeUInt is a prootype that represents uint type 1854 * It matches: 1855 * uint 1856 * uint[] 1857 * uint[4] 1858 * uint[][] 1859 * uint[3][] 1860 * uint[][6][], ... 1861 * uint32 1862 * uint64[] 1863 * uint8[4] 1864 * uint256[][] 1865 * uint[3][] 1866 * uint64[][6][], ... 1867 */ 1868 var SolidityTypeUInt = function () { 1869 this._inputFormatter = f.formatInputInt; 1870 this._outputFormatter = f.formatOutputUInt; 1871 }; 1872 1873 SolidityTypeUInt.prototype = new SolidityType({}); 1874 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1875 1876 SolidityTypeUInt.prototype.isType = function (name) { 1877 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1878 }; 1879 1880 module.exports = SolidityTypeUInt; 1881 }, 1882 { "./formatters": 9, "./type": 14 }, 1883 ], 1884 16: [ 1885 function (require, module, exports) { 1886 var f = require("./formatters"); 1887 var SolidityType = require("./type"); 1888 1889 /** 1890 * SolidityTypeUReal is a prootype that represents ureal type 1891 * It matches: 1892 * ureal 1893 * ureal[] 1894 * ureal[4] 1895 * ureal[][] 1896 * ureal[3][] 1897 * ureal[][6][], ... 1898 * ureal32 1899 * ureal64[] 1900 * ureal8[4] 1901 * ureal256[][] 1902 * ureal[3][] 1903 * ureal64[][6][], ... 1904 */ 1905 var SolidityTypeUReal = function () { 1906 this._inputFormatter = f.formatInputReal; 1907 this._outputFormatter = f.formatOutputUReal; 1908 }; 1909 1910 SolidityTypeUReal.prototype = new SolidityType({}); 1911 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1912 1913 SolidityTypeUReal.prototype.isType = function (name) { 1914 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1915 }; 1916 1917 module.exports = SolidityTypeUReal; 1918 }, 1919 { "./formatters": 9, "./type": 14 }, 1920 ], 1921 17: [ 1922 function (require, module, exports) { 1923 "use strict"; 1924 1925 // go env doesn't have and need XMLHttpRequest 1926 if (typeof XMLHttpRequest === "undefined") { 1927 exports.XMLHttpRequest = {}; 1928 } else { 1929 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1930 } 1931 }, 1932 {}, 1933 ], 1934 18: [ 1935 function (require, module, exports) { 1936 /* 1937 This file is part of web3.js. 1938 1939 web3.js is free software: you can redistribute it and/or modify 1940 it under the terms of the GNU Lesser General Public License as published by 1941 the Free Software Foundation, either version 3 of the License, or 1942 (at your option) any later version. 1943 1944 web3.js is distributed in the hope that it will be useful, 1945 but WITHOUT ANY WARRANTY; without even the implied warranty of 1946 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1947 GNU Lesser General Public License for more details. 1948 1949 You should have received a copy of the GNU Lesser General Public License 1950 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1951 */ 1952 /** @file config.js 1953 * @authors: 1954 * Marek Kotewicz <marek@ethdev.com> 1955 * @date 2015 1956 */ 1957 1958 /** 1959 * Utils 1960 * 1961 * @module utils 1962 */ 1963 1964 /** 1965 * Utility functions 1966 * 1967 * @class [utils] config 1968 * @constructor 1969 */ 1970 1971 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1972 var BigNumber = require("bignumber.js"); 1973 1974 var ETH_UNITS = [ 1975 "wei", 1976 "kwei", 1977 "Mwei", 1978 "Gwei", 1979 "szabo", 1980 "finney", 1981 "femtoether", 1982 "picoether", 1983 "nanoether", 1984 "microether", 1985 "milliether", 1986 "nano", 1987 "micro", 1988 "milli", 1989 "ether", 1990 "grand", 1991 "Mether", 1992 "Gether", 1993 "Tether", 1994 "Pether", 1995 "Eether", 1996 "Zether", 1997 "Yether", 1998 "Nether", 1999 "Dether", 2000 "Vether", 2001 "Uether", 2002 ]; 2003 2004 module.exports = { 2005 ETH_PADDING: 32, 2006 ETH_SIGNATURE_LENGTH: 4, 2007 ETH_UNITS: ETH_UNITS, 2008 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 2009 ETH_POLLING_TIMEOUT: 1000 / 2, 2010 defaultBlock: "latest", 2011 defaultAccount: undefined, 2012 }; 2013 }, 2014 { "bignumber.js": "bignumber.js" }, 2015 ], 2016 19: [ 2017 function (require, module, exports) { 2018 /* 2019 This file is part of web3.js. 2020 2021 web3.js is free software: you can redistribute it and/or modify 2022 it under the terms of the GNU Lesser General Public License as published by 2023 the Free Software Foundation, either version 3 of the License, or 2024 (at your option) any later version. 2025 2026 web3.js is distributed in the hope that it will be useful, 2027 but WITHOUT ANY WARRANTY; without even the implied warranty of 2028 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2029 GNU Lesser General Public License for more details. 2030 2031 You should have received a copy of the GNU Lesser General Public License 2032 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2033 */ 2034 /** 2035 * @file sha3.js 2036 * @author Marek Kotewicz <marek@ethdev.com> 2037 * @date 2015 2038 */ 2039 2040 var CryptoJS = require("crypto-js"); 2041 var sha3 = require("crypto-js/sha3"); 2042 2043 module.exports = function (value, options) { 2044 if (options && options.encoding === "hex") { 2045 if (value.length > 2 && value.substr(0, 2) === "0x") { 2046 value = value.substr(2); 2047 } 2048 value = CryptoJS.enc.Hex.parse(value); 2049 } 2050 2051 return sha3(value, { 2052 outputLength: 256, 2053 }).toString(); 2054 }; 2055 }, 2056 { "crypto-js": 59, "crypto-js/sha3": 80 }, 2057 ], 2058 20: [ 2059 function (require, module, exports) { 2060 /* 2061 This file is part of web3.js. 2062 2063 web3.js is free software: you can redistribute it and/or modify 2064 it under the terms of the GNU Lesser General Public License as published by 2065 the Free Software Foundation, either version 3 of the License, or 2066 (at your option) any later version. 2067 2068 web3.js is distributed in the hope that it will be useful, 2069 but WITHOUT ANY WARRANTY; without even the implied warranty of 2070 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2071 GNU Lesser General Public License for more details. 2072 2073 You should have received a copy of the GNU Lesser General Public License 2074 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2075 */ 2076 /** 2077 * @file utils.js 2078 * @author Marek Kotewicz <marek@ethdev.com> 2079 * @date 2015 2080 */ 2081 2082 /** 2083 * Utils 2084 * 2085 * @module utils 2086 */ 2087 2088 /** 2089 * Utility functions 2090 * 2091 * @class [utils] utils 2092 * @constructor 2093 */ 2094 2095 var BigNumber = require("bignumber.js"); 2096 var sha3 = require("./sha3.js"); 2097 var utf8 = require("utf8"); 2098 2099 var unitMap = { 2100 noether: "0", 2101 wei: "1", 2102 kwei: "1000", 2103 Kwei: "1000", 2104 babbage: "1000", 2105 femtoether: "1000", 2106 mwei: "1000000", 2107 Mwei: "1000000", 2108 lovelace: "1000000", 2109 picoether: "1000000", 2110 gwei: "1000000000", 2111 Gwei: "1000000000", 2112 shannon: "1000000000", 2113 nanoether: "1000000000", 2114 nano: "1000000000", 2115 szabo: "1000000000000", 2116 microether: "1000000000000", 2117 micro: "1000000000000", 2118 finney: "1000000000000000", 2119 milliether: "1000000000000000", 2120 milli: "1000000000000000", 2121 ether: "1000000000000000000", 2122 kether: "1000000000000000000000", 2123 grand: "1000000000000000000000", 2124 mether: "1000000000000000000000000", 2125 gether: "1000000000000000000000000000", 2126 tether: "1000000000000000000000000000000", 2127 }; 2128 2129 /** 2130 * Should be called to pad string to expected length 2131 * 2132 * @method padLeft 2133 * @param {String} string to be padded 2134 * @param {Number} characters that result string should have 2135 * @param {String} sign, by default 0 2136 * @returns {String} right aligned string 2137 */ 2138 var padLeft = function (string, chars, sign) { 2139 return ( 2140 new Array(chars - string.length + 1).join(sign ? sign : "0") + 2141 string 2142 ); 2143 }; 2144 2145 /** 2146 * Should be called to pad string to expected length 2147 * 2148 * @method padRight 2149 * @param {String} string to be padded 2150 * @param {Number} characters that result string should have 2151 * @param {String} sign, by default 0 2152 * @returns {String} right aligned string 2153 */ 2154 var padRight = function (string, chars, sign) { 2155 return ( 2156 string + 2157 new Array(chars - string.length + 1).join(sign ? sign : "0") 2158 ); 2159 }; 2160 2161 /** 2162 * Should be called to get utf8 from it's hex representation 2163 * 2164 * @method toUtf8 2165 * @param {String} string in hex 2166 * @returns {String} ascii string representation of hex value 2167 */ 2168 var toUtf8 = function (hex) { 2169 // Find termination 2170 var str = ""; 2171 var i = 0, 2172 l = hex.length; 2173 if (hex.substring(0, 2) === "0x") { 2174 i = 2; 2175 } 2176 for (; i < l; i += 2) { 2177 var code = parseInt(hex.substr(i, 2), 16); 2178 if (code === 0) break; 2179 str += String.fromCharCode(code); 2180 } 2181 2182 return utf8.decode(str); 2183 }; 2184 2185 /** 2186 * Should be called to get ascii from it's hex representation 2187 * 2188 * @method toAscii 2189 * @param {String} string in hex 2190 * @returns {String} ascii string representation of hex value 2191 */ 2192 var toAscii = function (hex) { 2193 // Find termination 2194 var str = ""; 2195 var i = 0, 2196 l = hex.length; 2197 if (hex.substring(0, 2) === "0x") { 2198 i = 2; 2199 } 2200 for (; i < l; i += 2) { 2201 var code = parseInt(hex.substr(i, 2), 16); 2202 str += String.fromCharCode(code); 2203 } 2204 2205 return str; 2206 }; 2207 2208 /** 2209 * Should be called to get hex representation (prefixed by 0x) of utf8 string 2210 * 2211 * @method fromUtf8 2212 * @param {String} string 2213 * @param {Number} optional padding 2214 * @returns {String} hex representation of input string 2215 */ 2216 var fromUtf8 = function (str) { 2217 str = utf8.encode(str); 2218 var hex = ""; 2219 for (var i = 0; i < str.length; i++) { 2220 var code = str.charCodeAt(i); 2221 if (code === 0) break; 2222 var n = code.toString(16); 2223 hex += n.length < 2 ? "0" + n : n; 2224 } 2225 2226 return "0x" + hex; 2227 }; 2228 2229 /** 2230 * Should be called to get hex representation (prefixed by 0x) of ascii string 2231 * 2232 * @method fromAscii 2233 * @param {String} string 2234 * @param {Number} optional padding 2235 * @returns {String} hex representation of input string 2236 */ 2237 var fromAscii = function (str) { 2238 var hex = ""; 2239 for (var i = 0; i < str.length; i++) { 2240 var code = str.charCodeAt(i); 2241 var n = code.toString(16); 2242 hex += n.length < 2 ? "0" + n : n; 2243 } 2244 2245 return "0x" + hex; 2246 }; 2247 2248 /** 2249 * Should be used to create full function/event name from json abi 2250 * 2251 * @method transformToFullName 2252 * @param {Object} json-abi 2253 * @return {String} full fnction/event name 2254 */ 2255 var transformToFullName = function (json) { 2256 if (json.name.indexOf("(") !== -1) { 2257 return json.name; 2258 } 2259 2260 var typeName = json.inputs 2261 .map(function (i) { 2262 return i.type; 2263 }) 2264 .join(); 2265 return json.name + "(" + typeName + ")"; 2266 }; 2267 2268 /** 2269 * Should be called to get display name of contract function 2270 * 2271 * @method extractDisplayName 2272 * @param {String} name of function/event 2273 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2274 */ 2275 var extractDisplayName = function (name) { 2276 var length = name.indexOf("("); 2277 return length !== -1 ? name.substr(0, length) : name; 2278 }; 2279 2280 /// @returns overloaded part of function/event name 2281 var extractTypeName = function (name) { 2282 /// TODO: make it invulnerable 2283 var length = name.indexOf("("); 2284 return length !== -1 2285 ? name 2286 .substr(length + 1, name.length - 1 - (length + 1)) 2287 .replace(" ", "") 2288 : ""; 2289 }; 2290 2291 /** 2292 * Converts value to it's decimal representation in string 2293 * 2294 * @method toDecimal 2295 * @param {String|Number|BigNumber} 2296 * @return {String} 2297 */ 2298 var toDecimal = function (value) { 2299 return toBigNumber(value).toNumber(); 2300 }; 2301 2302 /** 2303 * Converts value to it's hex representation 2304 * 2305 * @method fromDecimal 2306 * @param {String|Number|BigNumber} 2307 * @return {String} 2308 */ 2309 var fromDecimal = function (value) { 2310 var number = toBigNumber(value); 2311 var result = number.toString(16); 2312 2313 return number.lessThan(0) ? "-0x" + result.substr(1) : "0x" + result; 2314 }; 2315 2316 /** 2317 * Auto converts any given value into it's hex representation. 2318 * 2319 * And even stringifys objects before. 2320 * 2321 * @method toHex 2322 * @param {String|Number|BigNumber|Object} 2323 * @return {String} 2324 */ 2325 var toHex = function (val) { 2326 /*jshint maxcomplexity: 8 */ 2327 2328 if (isBoolean(val)) return fromDecimal(+val); 2329 2330 if (isBigNumber(val)) return fromDecimal(val); 2331 2332 if (typeof val === "object") return fromUtf8(JSON.stringify(val)); 2333 2334 // if its a negative number, pass it through fromDecimal 2335 if (isString(val)) { 2336 if (val.indexOf("-0x") === 0) return fromDecimal(val); 2337 else if (val.indexOf("0x") === 0) return val; 2338 else if (!isFinite(val)) return fromAscii(val); 2339 } 2340 2341 return fromDecimal(val); 2342 }; 2343 2344 /** 2345 * Returns value of unit in Wei 2346 * 2347 * @method getValueOfUnit 2348 * @param {String} unit the unit to convert to, default ether 2349 * @returns {BigNumber} value of the unit (in Wei) 2350 * @throws error if the unit is not correct:w 2351 */ 2352 var getValueOfUnit = function (unit) { 2353 unit = unit ? unit.toLowerCase() : "ether"; 2354 var unitValue = unitMap[unit]; 2355 if (unitValue === undefined) { 2356 throw new Error( 2357 "This unit doesn't exists, please use the one of the following units" + 2358 JSON.stringify(unitMap, null, 2) 2359 ); 2360 } 2361 return new BigNumber(unitValue, 10); 2362 }; 2363 2364 /** 2365 * Takes a number of wei and converts it to any other ether unit. 2366 * 2367 * Possible units are: 2368 * SI Short SI Full Effigy Other 2369 * - kwei femtoether babbage 2370 * - mwei picoether lovelace 2371 * - gwei nanoether shannon nano 2372 * - -- microether szabo micro 2373 * - -- milliether finney milli 2374 * - ether -- -- 2375 * - kether -- grand 2376 * - mether 2377 * - gether 2378 * - tether 2379 * 2380 * @method fromWei 2381 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2382 * @param {String} unit the unit to convert to, default ether 2383 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2384 */ 2385 var fromWei = function (number, unit) { 2386 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2387 2388 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2389 }; 2390 2391 /** 2392 * Takes a number of a unit and converts it to wei. 2393 * 2394 * Possible units are: 2395 * SI Short SI Full Effigy Other 2396 * - kwei femtoether babbage 2397 * - mwei picoether lovelace 2398 * - gwei nanoether shannon nano 2399 * - -- microether szabo micro 2400 * - -- microether szabo micro 2401 * - -- milliether finney milli 2402 * - ether -- -- 2403 * - kether -- grand 2404 * - mether 2405 * - gether 2406 * - tether 2407 * 2408 * @method toWei 2409 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2410 * @param {String} unit the unit to convert from, default ether 2411 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2412 */ 2413 var toWei = function (number, unit) { 2414 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2415 2416 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2417 }; 2418 2419 /** 2420 * Takes an input and transforms it into a bignumber 2421 * 2422 * @method toBigNumber 2423 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2424 * @return {BigNumber} BigNumber 2425 */ 2426 var toBigNumber = function (number) { 2427 /*jshint maxcomplexity:5 */ 2428 number = number || 0; 2429 if (isBigNumber(number)) return number; 2430 2431 if ( 2432 isString(number) && 2433 (number.indexOf("0x") === 0 || number.indexOf("-0x") === 0) 2434 ) { 2435 return new BigNumber(number.replace("0x", ""), 16); 2436 } 2437 2438 return new BigNumber(number.toString(10), 10); 2439 }; 2440 2441 /** 2442 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2443 * 2444 * @method toTwosComplement 2445 * @param {Number|String|BigNumber} 2446 * @return {BigNumber} 2447 */ 2448 var toTwosComplement = function (number) { 2449 var bigNumber = toBigNumber(number).round(); 2450 if (bigNumber.lessThan(0)) { 2451 return new BigNumber( 2452 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 2453 16 2454 ) 2455 .plus(bigNumber) 2456 .plus(1); 2457 } 2458 return bigNumber; 2459 }; 2460 2461 /** 2462 * Checks if the given string is strictly an address 2463 * 2464 * @method isStrictAddress 2465 * @param {String} address the given HEX adress 2466 * @return {Boolean} 2467 */ 2468 var isStrictAddress = function (address) { 2469 return /^0x[0-9a-f]{40}$/i.test(address); 2470 }; 2471 2472 /** 2473 * Checks if the given string is an address 2474 * 2475 * @method isAddress 2476 * @param {String} address the given HEX adress 2477 * @return {Boolean} 2478 */ 2479 var isAddress = function (address) { 2480 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2481 // check if it has the basic requirements of an address 2482 return false; 2483 } else if ( 2484 /^(0x)?[0-9a-f]{40}$/.test(address) || 2485 /^(0x)?[0-9A-F]{40}$/.test(address) 2486 ) { 2487 // If it's all small caps or all caps, return true 2488 return true; 2489 } else { 2490 // Otherwise check each case 2491 return isChecksumAddress(address); 2492 } 2493 }; 2494 2495 /** 2496 * Checks if the given string is a checksummed address 2497 * 2498 * @method isChecksumAddress 2499 * @param {String} address the given HEX adress 2500 * @return {Boolean} 2501 */ 2502 var isChecksumAddress = function (address) { 2503 // Check each case 2504 address = address.replace("0x", ""); 2505 var addressHash = sha3(address.toLowerCase()); 2506 2507 for (var i = 0; i < 40; i++) { 2508 // the nth letter should be uppercase if the nth digit of casemap is 1 2509 if ( 2510 (parseInt(addressHash[i], 16) > 7 && 2511 address[i].toUpperCase() !== address[i]) || 2512 (parseInt(addressHash[i], 16) <= 7 && 2513 address[i].toLowerCase() !== address[i]) 2514 ) { 2515 return false; 2516 } 2517 } 2518 return true; 2519 }; 2520 2521 /** 2522 * Makes a checksum address 2523 * 2524 * @method toChecksumAddress 2525 * @param {String} address the given HEX adress 2526 * @return {String} 2527 */ 2528 var toChecksumAddress = function (address) { 2529 if (typeof address === "undefined") return ""; 2530 2531 address = address.toLowerCase().replace("0x", ""); 2532 var addressHash = sha3(address); 2533 var checksumAddress = "0x"; 2534 2535 for (var i = 0; i < address.length; i++) { 2536 // If ith character is 9 to f then make it uppercase 2537 if (parseInt(addressHash[i], 16) > 7) { 2538 checksumAddress += address[i].toUpperCase(); 2539 } else { 2540 checksumAddress += address[i]; 2541 } 2542 } 2543 return checksumAddress; 2544 }; 2545 2546 /** 2547 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2548 * 2549 * @method toAddress 2550 * @param {String} address 2551 * @return {String} formatted address 2552 */ 2553 var toAddress = function (address) { 2554 if (isStrictAddress(address)) { 2555 return address; 2556 } 2557 2558 if (/^[0-9a-f]{40}$/.test(address)) { 2559 return "0x" + address; 2560 } 2561 2562 return "0x" + padLeft(toHex(address).substr(2), 40); 2563 }; 2564 2565 /** 2566 * Returns true if object is BigNumber, otherwise false 2567 * 2568 * @method isBigNumber 2569 * @param {Object} 2570 * @return {Boolean} 2571 */ 2572 var isBigNumber = function (object) { 2573 return ( 2574 object instanceof BigNumber || 2575 (object && 2576 object.constructor && 2577 object.constructor.name === "BigNumber") 2578 ); 2579 }; 2580 2581 /** 2582 * Returns true if object is string, otherwise false 2583 * 2584 * @method isString 2585 * @param {Object} 2586 * @return {Boolean} 2587 */ 2588 var isString = function (object) { 2589 return ( 2590 typeof object === "string" || 2591 (object && 2592 object.constructor && 2593 object.constructor.name === "String") 2594 ); 2595 }; 2596 2597 /** 2598 * Returns true if object is function, otherwise false 2599 * 2600 * @method isFunction 2601 * @param {Object} 2602 * @return {Boolean} 2603 */ 2604 var isFunction = function (object) { 2605 return typeof object === "function"; 2606 }; 2607 2608 /** 2609 * Returns true if object is Objet, otherwise false 2610 * 2611 * @method isObject 2612 * @param {Object} 2613 * @return {Boolean} 2614 */ 2615 var isObject = function (object) { 2616 return ( 2617 object !== null && 2618 !(object instanceof Array) && 2619 typeof object === "object" 2620 ); 2621 }; 2622 2623 /** 2624 * Returns true if object is boolean, otherwise false 2625 * 2626 * @method isBoolean 2627 * @param {Object} 2628 * @return {Boolean} 2629 */ 2630 var isBoolean = function (object) { 2631 return typeof object === "boolean"; 2632 }; 2633 2634 /** 2635 * Returns true if object is array, otherwise false 2636 * 2637 * @method isArray 2638 * @param {Object} 2639 * @return {Boolean} 2640 */ 2641 var isArray = function (object) { 2642 return object instanceof Array; 2643 }; 2644 2645 /** 2646 * Returns true if given string is valid json object 2647 * 2648 * @method isJson 2649 * @param {String} 2650 * @return {Boolean} 2651 */ 2652 var isJson = function (str) { 2653 try { 2654 return !!JSON.parse(str); 2655 } catch (e) { 2656 return false; 2657 } 2658 }; 2659 2660 /** 2661 * Returns true if given string is a valid Ethereum block header bloom. 2662 * 2663 * @method isBloom 2664 * @param {String} hex encoded bloom filter 2665 * @return {Boolean} 2666 */ 2667 var isBloom = function (bloom) { 2668 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2669 return false; 2670 } else if ( 2671 /^(0x)?[0-9a-f]{512}$/.test(bloom) || 2672 /^(0x)?[0-9A-F]{512}$/.test(bloom) 2673 ) { 2674 return true; 2675 } 2676 return false; 2677 }; 2678 2679 /** 2680 * Returns true if given string is a valid log topic. 2681 * 2682 * @method isTopic 2683 * @param {String} hex encoded topic 2684 * @return {Boolean} 2685 */ 2686 var isTopic = function (topic) { 2687 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2688 return false; 2689 } else if ( 2690 /^(0x)?[0-9a-f]{64}$/.test(topic) || 2691 /^(0x)?[0-9A-F]{64}$/.test(topic) 2692 ) { 2693 return true; 2694 } 2695 return false; 2696 }; 2697 2698 module.exports = { 2699 padLeft: padLeft, 2700 padRight: padRight, 2701 toHex: toHex, 2702 toDecimal: toDecimal, 2703 fromDecimal: fromDecimal, 2704 toUtf8: toUtf8, 2705 toAscii: toAscii, 2706 fromUtf8: fromUtf8, 2707 fromAscii: fromAscii, 2708 transformToFullName: transformToFullName, 2709 extractDisplayName: extractDisplayName, 2710 extractTypeName: extractTypeName, 2711 toWei: toWei, 2712 fromWei: fromWei, 2713 toBigNumber: toBigNumber, 2714 toTwosComplement: toTwosComplement, 2715 toAddress: toAddress, 2716 isBigNumber: isBigNumber, 2717 isStrictAddress: isStrictAddress, 2718 isAddress: isAddress, 2719 isChecksumAddress: isChecksumAddress, 2720 toChecksumAddress: toChecksumAddress, 2721 isFunction: isFunction, 2722 isString: isString, 2723 isObject: isObject, 2724 isBoolean: isBoolean, 2725 isArray: isArray, 2726 isJson: isJson, 2727 isBloom: isBloom, 2728 isTopic: isTopic, 2729 }; 2730 }, 2731 { "./sha3.js": 19, "bignumber.js": "bignumber.js", utf8: 85 }, 2732 ], 2733 21: [ 2734 function (require, module, exports) { 2735 module.exports = { 2736 version: "0.20.1", 2737 }; 2738 }, 2739 {}, 2740 ], 2741 22: [ 2742 function (require, module, exports) { 2743 /* 2744 This file is part of web3.js. 2745 2746 web3.js is free software: you can redistribute it and/or modify 2747 it under the terms of the GNU Lesser General Public License as published by 2748 the Free Software Foundation, either version 3 of the License, or 2749 (at your option) any later version. 2750 2751 web3.js is distributed in the hope that it will be useful, 2752 but WITHOUT ANY WARRANTY; without even the implied warranty of 2753 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2754 GNU Lesser General Public License for more details. 2755 2756 You should have received a copy of the GNU Lesser General Public License 2757 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2758 */ 2759 /** 2760 * @file web3.js 2761 * @authors: 2762 * Jeffrey Wilcke <jeff@ethdev.com> 2763 * Marek Kotewicz <marek@ethdev.com> 2764 * Marian Oancea <marian@ethdev.com> 2765 * Fabian Vogelsteller <fabian@ethdev.com> 2766 * Gav Wood <g@ethdev.com> 2767 * @date 2014 2768 */ 2769 2770 var RequestManager = require("./web3/requestmanager"); 2771 var Iban = require("./web3/iban"); 2772 var Eth = require("./web3/methods/eth"); 2773 var DB = require("./web3/methods/db"); 2774 var Shh = require("./web3/methods/shh"); 2775 var Net = require("./web3/methods/net"); 2776 var Personal = require("./web3/methods/personal"); 2777 var Swarm = require("./web3/methods/swarm"); 2778 var Settings = require("./web3/settings"); 2779 var version = require("./version.json"); 2780 var utils = require("./utils/utils"); 2781 var sha3 = require("./utils/sha3"); 2782 var extend = require("./web3/extend"); 2783 var Batch = require("./web3/batch"); 2784 var Property = require("./web3/property"); 2785 var HttpProvider = require("./web3/httpprovider"); 2786 var IpcProvider = require("./web3/ipcprovider"); 2787 var BigNumber = require("bignumber.js"); 2788 2789 function Web3(provider) { 2790 this._requestManager = new RequestManager(provider); 2791 this.currentProvider = provider; 2792 this.eth = new Eth(this); 2793 this.db = new DB(this); 2794 this.shh = new Shh(this); 2795 this.net = new Net(this); 2796 this.personal = new Personal(this); 2797 this.bzz = new Swarm(this); 2798 this.settings = new Settings(); 2799 this.version = { 2800 api: version.version, 2801 }; 2802 this.providers = { 2803 HttpProvider: HttpProvider, 2804 IpcProvider: IpcProvider, 2805 }; 2806 this._extend = extend(this); 2807 this._extend({ 2808 properties: properties(), 2809 }); 2810 } 2811 2812 // expose providers on the class 2813 Web3.providers = { 2814 HttpProvider: HttpProvider, 2815 IpcProvider: IpcProvider, 2816 }; 2817 2818 Web3.prototype.setProvider = function (provider) { 2819 this._requestManager.setProvider(provider); 2820 this.currentProvider = provider; 2821 }; 2822 2823 Web3.prototype.reset = function (keepIsSyncing) { 2824 this._requestManager.reset(keepIsSyncing); 2825 this.settings = new Settings(); 2826 }; 2827 2828 Web3.prototype.BigNumber = BigNumber; 2829 Web3.prototype.toHex = utils.toHex; 2830 Web3.prototype.toAscii = utils.toAscii; 2831 Web3.prototype.toUtf8 = utils.toUtf8; 2832 Web3.prototype.fromAscii = utils.fromAscii; 2833 Web3.prototype.fromUtf8 = utils.fromUtf8; 2834 Web3.prototype.toDecimal = utils.toDecimal; 2835 Web3.prototype.fromDecimal = utils.fromDecimal; 2836 Web3.prototype.toBigNumber = utils.toBigNumber; 2837 Web3.prototype.toWei = utils.toWei; 2838 Web3.prototype.fromWei = utils.fromWei; 2839 Web3.prototype.isAddress = utils.isAddress; 2840 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2841 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2842 Web3.prototype.isIBAN = utils.isIBAN; 2843 Web3.prototype.padLeft = utils.padLeft; 2844 Web3.prototype.padRight = utils.padRight; 2845 2846 Web3.prototype.sha3 = function (string, options) { 2847 return "0x" + sha3(string, options); 2848 }; 2849 2850 /** 2851 * Transforms direct icap to address 2852 */ 2853 Web3.prototype.fromICAP = function (icap) { 2854 var iban = new Iban(icap); 2855 return iban.address(); 2856 }; 2857 2858 var properties = function () { 2859 return [ 2860 new Property({ 2861 name: "version.node", 2862 getter: "web3_clientVersion", 2863 }), 2864 new Property({ 2865 name: "version.network", 2866 getter: "net_version", 2867 inputFormatter: utils.toDecimal, 2868 }), 2869 new Property({ 2870 name: "version.ethereum", 2871 getter: "eth_protocolVersion", 2872 inputFormatter: utils.toDecimal, 2873 }), 2874 new Property({ 2875 name: "version.whisper", 2876 getter: "shh_version", 2877 inputFormatter: utils.toDecimal, 2878 }), 2879 ]; 2880 }; 2881 2882 Web3.prototype.isConnected = function () { 2883 return this.currentProvider && this.currentProvider.isConnected(); 2884 }; 2885 2886 Web3.prototype.createBatch = function () { 2887 return new Batch(this); 2888 }; 2889 2890 module.exports = Web3; 2891 }, 2892 { 2893 "./utils/sha3": 19, 2894 "./utils/utils": 20, 2895 "./version.json": 21, 2896 "./web3/batch": 24, 2897 "./web3/extend": 28, 2898 "./web3/httpprovider": 32, 2899 "./web3/iban": 33, 2900 "./web3/ipcprovider": 34, 2901 "./web3/methods/db": 37, 2902 "./web3/methods/eth": 38, 2903 "./web3/methods/net": 39, 2904 "./web3/methods/personal": 40, 2905 "./web3/methods/shh": 41, 2906 "./web3/methods/swarm": 42, 2907 "./web3/property": 45, 2908 "./web3/requestmanager": 46, 2909 "./web3/settings": 47, 2910 "bignumber.js": "bignumber.js", 2911 }, 2912 ], 2913 23: [ 2914 function (require, module, exports) { 2915 /* 2916 This file is part of web3.js. 2917 2918 web3.js is free software: you can redistribute it and/or modify 2919 it under the terms of the GNU Lesser General Public License as published by 2920 the Free Software Foundation, either version 3 of the License, or 2921 (at your option) any later version. 2922 2923 web3.js is distributed in the hope that it will be useful, 2924 but WITHOUT ANY WARRANTY; without even the implied warranty of 2925 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2926 GNU Lesser General Public License for more details. 2927 2928 You should have received a copy of the GNU Lesser General Public License 2929 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2930 */ 2931 /** 2932 * @file allevents.js 2933 * @author Marek Kotewicz <marek@ethdev.com> 2934 * @date 2014 2935 */ 2936 2937 var sha3 = require("../utils/sha3"); 2938 var SolidityEvent = require("./event"); 2939 var formatters = require("./formatters"); 2940 var utils = require("../utils/utils"); 2941 var Filter = require("./filter"); 2942 var watches = require("./methods/watches"); 2943 2944 var AllSolidityEvents = function (requestManager, json, address) { 2945 this._requestManager = requestManager; 2946 this._json = json; 2947 this._address = address; 2948 }; 2949 2950 AllSolidityEvents.prototype.encode = function (options) { 2951 options = options || {}; 2952 var result = {}; 2953 2954 ["fromBlock", "toBlock"] 2955 .filter(function (f) { 2956 return options[f] !== undefined; 2957 }) 2958 .forEach(function (f) { 2959 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2960 }); 2961 2962 result.address = this._address; 2963 2964 return result; 2965 }; 2966 2967 AllSolidityEvents.prototype.decode = function (data) { 2968 data.data = data.data || ""; 2969 data.topics = data.topics || []; 2970 2971 var eventTopic = data.topics[0].slice(2); 2972 var match = this._json.filter(function (j) { 2973 return eventTopic === sha3(utils.transformToFullName(j)); 2974 })[0]; 2975 2976 if (!match) { 2977 // cannot find matching event? 2978 console.warn("cannot find event for log"); 2979 return data; 2980 } 2981 2982 var event = new SolidityEvent( 2983 this._requestManager, 2984 match, 2985 this._address 2986 ); 2987 return event.decode(data); 2988 }; 2989 2990 AllSolidityEvents.prototype.execute = function (options, callback) { 2991 if (utils.isFunction(arguments[arguments.length - 1])) { 2992 callback = arguments[arguments.length - 1]; 2993 if (arguments.length === 1) options = null; 2994 } 2995 2996 var o = this.encode(options); 2997 var formatter = this.decode.bind(this); 2998 return new Filter( 2999 o, 3000 "eth", 3001 this._requestManager, 3002 watches.eth(), 3003 formatter, 3004 callback 3005 ); 3006 }; 3007 3008 AllSolidityEvents.prototype.attachToContract = function (contract) { 3009 var execute = this.execute.bind(this); 3010 contract.allEvents = execute; 3011 }; 3012 3013 module.exports = AllSolidityEvents; 3014 }, 3015 { 3016 "../utils/sha3": 19, 3017 "../utils/utils": 20, 3018 "./event": 27, 3019 "./filter": 29, 3020 "./formatters": 30, 3021 "./methods/watches": 43, 3022 }, 3023 ], 3024 24: [ 3025 function (require, module, exports) { 3026 /* 3027 This file is part of web3.js. 3028 3029 web3.js is free software: you can redistribute it and/or modify 3030 it under the terms of the GNU Lesser General Public License as published by 3031 the Free Software Foundation, either version 3 of the License, or 3032 (at your option) any later version. 3033 3034 web3.js is distributed in the hope that it will be useful, 3035 but WITHOUT ANY WARRANTY; without even the implied warranty of 3036 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3037 GNU Lesser General Public License for more details. 3038 3039 You should have received a copy of the GNU Lesser General Public License 3040 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3041 */ 3042 /** 3043 * @file batch.js 3044 * @author Marek Kotewicz <marek@ethdev.com> 3045 * @date 2015 3046 */ 3047 3048 var Jsonrpc = require("./jsonrpc"); 3049 var errors = require("./errors"); 3050 3051 var Batch = function (web3) { 3052 this.requestManager = web3._requestManager; 3053 this.requests = []; 3054 }; 3055 3056 /** 3057 * Should be called to add create new request to batch request 3058 * 3059 * @method add 3060 * @param {Object} jsonrpc requet object 3061 */ 3062 Batch.prototype.add = function (request) { 3063 this.requests.push(request); 3064 }; 3065 3066 /** 3067 * Should be called to execute batch request 3068 * 3069 * @method execute 3070 */ 3071 Batch.prototype.execute = function () { 3072 var requests = this.requests; 3073 this.requestManager.sendBatch(requests, function (err, results) { 3074 results = results || []; 3075 requests 3076 .map(function (request, index) { 3077 return results[index] || {}; 3078 }) 3079 .forEach(function (result, index) { 3080 if (requests[index].callback) { 3081 if (!Jsonrpc.isValidResponse(result)) { 3082 return requests[index].callback( 3083 errors.InvalidResponse(result) 3084 ); 3085 } 3086 3087 requests[index].callback( 3088 null, 3089 requests[index].format 3090 ? requests[index].format(result.result) 3091 : result.result 3092 ); 3093 } 3094 }); 3095 }); 3096 }; 3097 3098 module.exports = Batch; 3099 }, 3100 { "./errors": 26, "./jsonrpc": 35 }, 3101 ], 3102 25: [ 3103 function (require, module, exports) { 3104 /* 3105 This file is part of web3.js. 3106 3107 web3.js is free software: you can redistribute it and/or modify 3108 it under the terms of the GNU Lesser General Public License as published by 3109 the Free Software Foundation, either version 3 of the License, or 3110 (at your option) any later version. 3111 3112 web3.js is distributed in the hope that it will be useful, 3113 but WITHOUT ANY WARRANTY; without even the implied warranty of 3114 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3115 GNU Lesser General Public License for more details. 3116 3117 You should have received a copy of the GNU Lesser General Public License 3118 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3119 */ 3120 /** 3121 * @file contract.js 3122 * @author Marek Kotewicz <marek@ethdev.com> 3123 * @date 2014 3124 */ 3125 3126 var utils = require("../utils/utils"); 3127 var coder = require("../solidity/coder"); 3128 var SolidityEvent = require("./event"); 3129 var SolidityFunction = require("./function"); 3130 var AllEvents = require("./allevents"); 3131 3132 /** 3133 * Should be called to encode constructor params 3134 * 3135 * @method encodeConstructorParams 3136 * @param {Array} abi 3137 * @param {Array} constructor params 3138 */ 3139 var encodeConstructorParams = function (abi, params) { 3140 return ( 3141 abi 3142 .filter(function (json) { 3143 return ( 3144 json.type === "constructor" && 3145 json.inputs.length === params.length 3146 ); 3147 }) 3148 .map(function (json) { 3149 return json.inputs.map(function (input) { 3150 return input.type; 3151 }); 3152 }) 3153 .map(function (types) { 3154 return coder.encodeParams(types, params); 3155 })[0] || "" 3156 ); 3157 }; 3158 3159 /** 3160 * Should be called to add functions to contract object 3161 * 3162 * @method addFunctionsToContract 3163 * @param {Contract} contract 3164 * @param {Array} abi 3165 */ 3166 var addFunctionsToContract = function (contract) { 3167 contract.abi 3168 .filter(function (json) { 3169 return json.type === "function"; 3170 }) 3171 .map(function (json) { 3172 return new SolidityFunction( 3173 contract._eth, 3174 json, 3175 contract.address 3176 ); 3177 }) 3178 .forEach(function (f) { 3179 f.attachToContract(contract); 3180 }); 3181 }; 3182 3183 /** 3184 * Should be called to add events to contract object 3185 * 3186 * @method addEventsToContract 3187 * @param {Contract} contract 3188 * @param {Array} abi 3189 */ 3190 var addEventsToContract = function (contract) { 3191 var events = contract.abi.filter(function (json) { 3192 return json.type === "event"; 3193 }); 3194 3195 var All = new AllEvents( 3196 contract._eth._requestManager, 3197 events, 3198 contract.address 3199 ); 3200 All.attachToContract(contract); 3201 3202 events 3203 .map(function (json) { 3204 return new SolidityEvent( 3205 contract._eth._requestManager, 3206 json, 3207 contract.address 3208 ); 3209 }) 3210 .forEach(function (e) { 3211 e.attachToContract(contract); 3212 }); 3213 }; 3214 3215 /** 3216 * Should be called to check if the contract gets properly deployed on the blockchain. 3217 * 3218 * @method checkForContractAddress 3219 * @param {Object} contract 3220 * @param {Function} callback 3221 * @returns {Undefined} 3222 */ 3223 var checkForContractAddress = function (contract, callback) { 3224 var count = 0, 3225 callbackFired = false; 3226 3227 // wait for receipt 3228 var filter = contract._eth.filter("latest", function (e) { 3229 if (!e && !callbackFired) { 3230 count++; 3231 3232 // stop watching after 50 blocks (timeout) 3233 if (count > 50) { 3234 filter.stopWatching(function () {}); 3235 callbackFired = true; 3236 3237 if (callback) 3238 callback( 3239 new Error( 3240 "Contract transaction couldn't be found after 50 blocks" 3241 ) 3242 ); 3243 else 3244 throw new Error( 3245 "Contract transaction couldn't be found after 50 blocks" 3246 ); 3247 } else { 3248 contract._eth.getTransactionReceipt( 3249 contract.transactionHash, 3250 function (e, receipt) { 3251 if (receipt && !callbackFired) { 3252 contract._eth.getCode( 3253 receipt.contractAddress, 3254 function (e, code) { 3255 /*jshint maxcomplexity: 6 */ 3256 3257 if (callbackFired || !code) return; 3258 3259 filter.stopWatching(function () {}); 3260 callbackFired = true; 3261 3262 if (code.length > 3) { 3263 // console.log('Contract code deployed!'); 3264 3265 contract.address = receipt.contractAddress; 3266 3267 // attach events and methods again after we have 3268 addFunctionsToContract(contract); 3269 addEventsToContract(contract); 3270 3271 // call callback for the second time 3272 if (callback) callback(null, contract); 3273 } else { 3274 if (callback) 3275 callback( 3276 new Error( 3277 "The contract code couldn't be stored, please check your gas amount." 3278 ) 3279 ); 3280 else 3281 throw new Error( 3282 "The contract code couldn't be stored, please check your gas amount." 3283 ); 3284 } 3285 } 3286 ); 3287 } 3288 } 3289 ); 3290 } 3291 } 3292 }); 3293 }; 3294 3295 /** 3296 * Should be called to create new ContractFactory instance 3297 * 3298 * @method ContractFactory 3299 * @param {Array} abi 3300 */ 3301 var ContractFactory = function (eth, abi) { 3302 this.eth = eth; 3303 this.abi = abi; 3304 3305 /** 3306 * Should be called to create new contract on a blockchain 3307 * 3308 * @method new 3309 * @param {Any} contract constructor param1 (optional) 3310 * @param {Any} contract constructor param2 (optional) 3311 * @param {Object} contract transaction object (required) 3312 * @param {Function} callback 3313 * @returns {Contract} returns contract instance 3314 */ 3315 this.new = function () { 3316 /*jshint maxcomplexity: 7 */ 3317 3318 var contract = new Contract(this.eth, this.abi); 3319 3320 // parse arguments 3321 var options = {}; // required! 3322 var callback; 3323 3324 var args = Array.prototype.slice.call(arguments); 3325 if (utils.isFunction(args[args.length - 1])) { 3326 callback = args.pop(); 3327 } 3328 3329 var last = args[args.length - 1]; 3330 if (utils.isObject(last) && !utils.isArray(last)) { 3331 options = args.pop(); 3332 } 3333 3334 if (options.value > 0) { 3335 var constructorAbi = 3336 abi.filter(function (json) { 3337 return ( 3338 json.type === "constructor" && 3339 json.inputs.length === args.length 3340 ); 3341 })[0] || {}; 3342 3343 if (!constructorAbi.payable) { 3344 throw new Error("Cannot send value to non-payable constructor"); 3345 } 3346 } 3347 3348 var bytes = encodeConstructorParams(this.abi, args); 3349 options.data += bytes; 3350 3351 if (callback) { 3352 // wait for the contract address adn check if the code was deployed 3353 this.eth.sendTransaction(options, function (err, hash) { 3354 if (err) { 3355 callback(err); 3356 } else { 3357 // add the transaction hash 3358 contract.transactionHash = hash; 3359 3360 // call callback for the first time 3361 callback(null, contract); 3362 3363 checkForContractAddress(contract, callback); 3364 } 3365 }); 3366 } else { 3367 var hash = this.eth.sendTransaction(options); 3368 // add the transaction hash 3369 contract.transactionHash = hash; 3370 checkForContractAddress(contract); 3371 } 3372 3373 return contract; 3374 }; 3375 3376 this.new.getData = this.getData.bind(this); 3377 }; 3378 3379 /** 3380 * Should be called to create new ContractFactory 3381 * 3382 * @method contract 3383 * @param {Array} abi 3384 * @returns {ContractFactory} new contract factory 3385 */ 3386 //var contract = function (abi) { 3387 //return new ContractFactory(abi); 3388 //}; 3389 3390 /** 3391 * Should be called to get access to existing contract on a blockchain 3392 * 3393 * @method at 3394 * @param {Address} contract address (required) 3395 * @param {Function} callback {optional) 3396 * @returns {Contract} returns contract if no callback was passed, 3397 * otherwise calls callback function (err, contract) 3398 */ 3399 ContractFactory.prototype.at = function (address, callback) { 3400 var contract = new Contract(this.eth, this.abi, address); 3401 3402 // this functions are not part of prototype, 3403 // because we dont want to spoil the interface 3404 addFunctionsToContract(contract); 3405 addEventsToContract(contract); 3406 3407 if (callback) { 3408 callback(null, contract); 3409 } 3410 return contract; 3411 }; 3412 3413 /** 3414 * Gets the data, which is data to deploy plus constructor params 3415 * 3416 * @method getData 3417 */ 3418 ContractFactory.prototype.getData = function () { 3419 var options = {}; // required! 3420 var args = Array.prototype.slice.call(arguments); 3421 3422 var last = args[args.length - 1]; 3423 if (utils.isObject(last) && !utils.isArray(last)) { 3424 options = args.pop(); 3425 } 3426 3427 var bytes = encodeConstructorParams(this.abi, args); 3428 options.data += bytes; 3429 3430 return options.data; 3431 }; 3432 3433 /** 3434 * Should be called to create new contract instance 3435 * 3436 * @method Contract 3437 * @param {Array} abi 3438 * @param {Address} contract address 3439 */ 3440 var Contract = function (eth, abi, address) { 3441 this._eth = eth; 3442 this.transactionHash = null; 3443 this.address = address; 3444 this.abi = abi; 3445 }; 3446 3447 module.exports = ContractFactory; 3448 }, 3449 { 3450 "../solidity/coder": 7, 3451 "../utils/utils": 20, 3452 "./allevents": 23, 3453 "./event": 27, 3454 "./function": 31, 3455 }, 3456 ], 3457 26: [ 3458 function (require, module, exports) { 3459 /* 3460 This file is part of web3.js. 3461 3462 web3.js is free software: you can redistribute it and/or modify 3463 it under the terms of the GNU Lesser General Public License as published by 3464 the Free Software Foundation, either version 3 of the License, or 3465 (at your option) any later version. 3466 3467 web3.js is distributed in the hope that it will be useful, 3468 but WITHOUT ANY WARRANTY; without even the implied warranty of 3469 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3470 GNU Lesser General Public License for more details. 3471 3472 You should have received a copy of the GNU Lesser General Public License 3473 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3474 */ 3475 /** 3476 * @file errors.js 3477 * @author Marek Kotewicz <marek@ethdev.com> 3478 * @date 2015 3479 */ 3480 3481 module.exports = { 3482 InvalidNumberOfSolidityArgs: function () { 3483 return new Error( 3484 "Invalid number of arguments to Solidity function" 3485 ); 3486 }, 3487 InvalidNumberOfRPCParams: function () { 3488 return new Error( 3489 "Invalid number of input parameters to RPC method" 3490 ); 3491 }, 3492 InvalidConnection: function (host) { 3493 return new Error( 3494 "CONNECTION ERROR: Couldn't connect to node " + host + "." 3495 ); 3496 }, 3497 InvalidProvider: function () { 3498 return new Error("Provider not set or invalid"); 3499 }, 3500 InvalidResponse: function (result) { 3501 var message = 3502 !!result && !!result.error && !!result.error.message 3503 ? result.error.message 3504 : "Invalid JSON RPC response: " + JSON.stringify(result); 3505 return new Error(message); 3506 }, 3507 ConnectionTimeout: function (ms) { 3508 return new Error( 3509 "CONNECTION TIMEOUT: timeout of " + ms + " ms achived" 3510 ); 3511 }, 3512 }; 3513 }, 3514 {}, 3515 ], 3516 27: [ 3517 function (require, module, exports) { 3518 /* 3519 This file is part of web3.js. 3520 3521 web3.js is free software: you can redistribute it and/or modify 3522 it under the terms of the GNU Lesser General Public License as published by 3523 the Free Software Foundation, either version 3 of the License, or 3524 (at your option) any later version. 3525 3526 web3.js is distributed in the hope that it will be useful, 3527 but WITHOUT ANY WARRANTY; without even the implied warranty of 3528 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3529 GNU Lesser General Public License for more details. 3530 3531 You should have received a copy of the GNU Lesser General Public License 3532 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3533 */ 3534 /** 3535 * @file event.js 3536 * @author Marek Kotewicz <marek@ethdev.com> 3537 * @date 2014 3538 */ 3539 3540 var utils = require("../utils/utils"); 3541 var coder = require("../solidity/coder"); 3542 var formatters = require("./formatters"); 3543 var sha3 = require("../utils/sha3"); 3544 var Filter = require("./filter"); 3545 var watches = require("./methods/watches"); 3546 3547 /** 3548 * This prototype should be used to create event filters 3549 */ 3550 var SolidityEvent = function (requestManager, json, address) { 3551 this._requestManager = requestManager; 3552 this._params = json.inputs; 3553 this._name = utils.transformToFullName(json); 3554 this._address = address; 3555 this._anonymous = json.anonymous; 3556 }; 3557 3558 /** 3559 * Should be used to get filtered param types 3560 * 3561 * @method types 3562 * @param {Bool} decide if returned typed should be indexed 3563 * @return {Array} array of types 3564 */ 3565 SolidityEvent.prototype.types = function (indexed) { 3566 return this._params 3567 .filter(function (i) { 3568 return i.indexed === indexed; 3569 }) 3570 .map(function (i) { 3571 return i.type; 3572 }); 3573 }; 3574 3575 /** 3576 * Should be used to get event display name 3577 * 3578 * @method displayName 3579 * @return {String} event display name 3580 */ 3581 SolidityEvent.prototype.displayName = function () { 3582 return utils.extractDisplayName(this._name); 3583 }; 3584 3585 /** 3586 * Should be used to get event type name 3587 * 3588 * @method typeName 3589 * @return {String} event type name 3590 */ 3591 SolidityEvent.prototype.typeName = function () { 3592 return utils.extractTypeName(this._name); 3593 }; 3594 3595 /** 3596 * Should be used to get event signature 3597 * 3598 * @method signature 3599 * @return {String} event signature 3600 */ 3601 SolidityEvent.prototype.signature = function () { 3602 return sha3(this._name); 3603 }; 3604 3605 /** 3606 * Should be used to encode indexed params and options to one final object 3607 * 3608 * @method encode 3609 * @param {Object} indexed 3610 * @param {Object} options 3611 * @return {Object} everything combined together and encoded 3612 */ 3613 SolidityEvent.prototype.encode = function (indexed, options) { 3614 indexed = indexed || {}; 3615 options = options || {}; 3616 var result = {}; 3617 3618 ["fromBlock", "toBlock"] 3619 .filter(function (f) { 3620 return options[f] !== undefined; 3621 }) 3622 .forEach(function (f) { 3623 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3624 }); 3625 3626 result.topics = []; 3627 3628 result.address = this._address; 3629 if (!this._anonymous) { 3630 result.topics.push("0x" + this.signature()); 3631 } 3632 3633 var indexedTopics = this._params 3634 .filter(function (i) { 3635 return i.indexed === true; 3636 }) 3637 .map(function (i) { 3638 var value = indexed[i.name]; 3639 if (value === undefined || value === null) { 3640 return null; 3641 } 3642 3643 if (utils.isArray(value)) { 3644 return value.map(function (v) { 3645 return "0x" + coder.encodeParam(i.type, v); 3646 }); 3647 } 3648 return "0x" + coder.encodeParam(i.type, value); 3649 }); 3650 3651 result.topics = result.topics.concat(indexedTopics); 3652 3653 return result; 3654 }; 3655 3656 /** 3657 * Should be used to decode indexed params and options 3658 * 3659 * @method decode 3660 * @param {Object} data 3661 * @return {Object} result object with decoded indexed && not indexed params 3662 */ 3663 SolidityEvent.prototype.decode = function (data) { 3664 data.data = data.data || ""; 3665 data.topics = data.topics || []; 3666 3667 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3668 var indexedData = argTopics 3669 .map(function (topics) { 3670 return topics.slice(2); 3671 }) 3672 .join(""); 3673 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3674 3675 var notIndexedData = data.data.slice(2); 3676 var notIndexedParams = coder.decodeParams( 3677 this.types(false), 3678 notIndexedData 3679 ); 3680 3681 var result = formatters.outputLogFormatter(data); 3682 result.event = this.displayName(); 3683 result.address = data.address; 3684 3685 result.args = this._params.reduce(function (acc, current) { 3686 acc[current.name] = current.indexed 3687 ? indexedParams.shift() 3688 : notIndexedParams.shift(); 3689 return acc; 3690 }, {}); 3691 3692 delete result.data; 3693 delete result.topics; 3694 3695 return result; 3696 }; 3697 3698 /** 3699 * Should be used to create new filter object from event 3700 * 3701 * @method execute 3702 * @param {Object} indexed 3703 * @param {Object} options 3704 * @return {Object} filter object 3705 */ 3706 SolidityEvent.prototype.execute = function ( 3707 indexed, 3708 options, 3709 callback 3710 ) { 3711 if (utils.isFunction(arguments[arguments.length - 1])) { 3712 callback = arguments[arguments.length - 1]; 3713 if (arguments.length === 2) options = null; 3714 if (arguments.length === 1) { 3715 options = null; 3716 indexed = {}; 3717 } 3718 } 3719 3720 var o = this.encode(indexed, options); 3721 var formatter = this.decode.bind(this); 3722 return new Filter( 3723 o, 3724 "eth", 3725 this._requestManager, 3726 watches.eth(), 3727 formatter, 3728 callback 3729 ); 3730 }; 3731 3732 /** 3733 * Should be used to attach event to contract object 3734 * 3735 * @method attachToContract 3736 * @param {Contract} 3737 */ 3738 SolidityEvent.prototype.attachToContract = function (contract) { 3739 var execute = this.execute.bind(this); 3740 var displayName = this.displayName(); 3741 if (!contract[displayName]) { 3742 contract[displayName] = execute; 3743 } 3744 contract[displayName][this.typeName()] = this.execute.bind( 3745 this, 3746 contract 3747 ); 3748 }; 3749 3750 module.exports = SolidityEvent; 3751 }, 3752 { 3753 "../solidity/coder": 7, 3754 "../utils/sha3": 19, 3755 "../utils/utils": 20, 3756 "./filter": 29, 3757 "./formatters": 30, 3758 "./methods/watches": 43, 3759 }, 3760 ], 3761 28: [ 3762 function (require, module, exports) { 3763 var formatters = require("./formatters"); 3764 var utils = require("./../utils/utils"); 3765 var Method = require("./method"); 3766 var Property = require("./property"); 3767 3768 // TODO: refactor, so the input params are not altered. 3769 // it's necessary to make same 'extension' work with multiple providers 3770 var extend = function (web3) { 3771 /* jshint maxcomplexity:5 */ 3772 var ex = function (extension) { 3773 var extendedObject; 3774 if (extension.property) { 3775 if (!web3[extension.property]) { 3776 web3[extension.property] = {}; 3777 } 3778 extendedObject = web3[extension.property]; 3779 } else { 3780 extendedObject = web3; 3781 } 3782 3783 if (extension.methods) { 3784 extension.methods.forEach(function (method) { 3785 method.attachToObject(extendedObject); 3786 method.setRequestManager(web3._requestManager); 3787 }); 3788 } 3789 3790 if (extension.properties) { 3791 extension.properties.forEach(function (property) { 3792 property.attachToObject(extendedObject); 3793 property.setRequestManager(web3._requestManager); 3794 }); 3795 } 3796 }; 3797 3798 ex.formatters = formatters; 3799 ex.utils = utils; 3800 ex.Method = Method; 3801 ex.Property = Property; 3802 3803 return ex; 3804 }; 3805 3806 module.exports = extend; 3807 }, 3808 { 3809 "./../utils/utils": 20, 3810 "./formatters": 30, 3811 "./method": 36, 3812 "./property": 45, 3813 }, 3814 ], 3815 29: [ 3816 function (require, module, exports) { 3817 /* 3818 This file is part of web3.js. 3819 3820 web3.js is free software: you can redistribute it and/or modify 3821 it under the terms of the GNU Lesser General Public License as published by 3822 the Free Software Foundation, either version 3 of the License, or 3823 (at your option) any later version. 3824 3825 web3.js is distributed in the hope that it will be useful, 3826 but WITHOUT ANY WARRANTY; without even the implied warranty of 3827 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3828 GNU Lesser General Public License for more details. 3829 3830 You should have received a copy of the GNU Lesser General Public License 3831 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3832 */ 3833 /** @file filter.js 3834 * @authors: 3835 * Jeffrey Wilcke <jeff@ethdev.com> 3836 * Marek Kotewicz <marek@ethdev.com> 3837 * Marian Oancea <marian@ethdev.com> 3838 * Fabian Vogelsteller <fabian@ethdev.com> 3839 * Gav Wood <g@ethdev.com> 3840 * @date 2014 3841 */ 3842 3843 var formatters = require("./formatters"); 3844 var utils = require("../utils/utils"); 3845 3846 /** 3847 * Converts a given topic to a hex string, but also allows null values. 3848 * 3849 * @param {Mixed} value 3850 * @return {String} 3851 */ 3852 var toTopic = function (value) { 3853 if (value === null || typeof value === "undefined") return null; 3854 3855 value = String(value); 3856 3857 if (value.indexOf("0x") === 0) return value; 3858 else return utils.fromUtf8(value); 3859 }; 3860 3861 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3862 /// @param should be string or object 3863 /// @returns options string or object 3864 var getOptions = function (options, type) { 3865 /*jshint maxcomplexity: 6 */ 3866 3867 if (utils.isString(options)) { 3868 return options; 3869 } 3870 3871 options = options || {}; 3872 3873 switch (type) { 3874 case "eth": 3875 // make sure topics, get converted to hex 3876 options.topics = options.topics || []; 3877 options.topics = options.topics.map(function (topic) { 3878 return utils.isArray(topic) 3879 ? topic.map(toTopic) 3880 : toTopic(topic); 3881 }); 3882 3883 return { 3884 topics: options.topics, 3885 from: options.from, 3886 to: options.to, 3887 address: options.address, 3888 fromBlock: formatters.inputBlockNumberFormatter( 3889 options.fromBlock 3890 ), 3891 toBlock: formatters.inputBlockNumberFormatter(options.toBlock), 3892 }; 3893 case "shh": 3894 return options; 3895 } 3896 }; 3897 3898 /** 3899 Adds the callback and sets up the methods, to iterate over the results. 3900 3901 @method getLogsAtStart 3902 @param {Object} self 3903 @param {function} callback 3904 */ 3905 var getLogsAtStart = function (self, callback) { 3906 // call getFilterLogs for the first watch callback start 3907 if (!utils.isString(self.options)) { 3908 self.get(function (err, messages) { 3909 // don't send all the responses to all the watches again... just to self one 3910 if (err) { 3911 callback(err); 3912 } 3913 3914 if (utils.isArray(messages)) { 3915 messages.forEach(function (message) { 3916 callback(null, message); 3917 }); 3918 } 3919 }); 3920 } 3921 }; 3922 3923 /** 3924 Adds the callback and sets up the methods, to iterate over the results. 3925 3926 @method pollFilter 3927 @param {Object} self 3928 */ 3929 var pollFilter = function (self) { 3930 var onMessage = function (error, messages) { 3931 if (error) { 3932 return self.callbacks.forEach(function (callback) { 3933 callback(error); 3934 }); 3935 } 3936 3937 if (utils.isArray(messages)) { 3938 messages.forEach(function (message) { 3939 message = self.formatter ? self.formatter(message) : message; 3940 self.callbacks.forEach(function (callback) { 3941 callback(null, message); 3942 }); 3943 }); 3944 } 3945 }; 3946 3947 self.requestManager.startPolling( 3948 { 3949 method: self.implementation.poll.call, 3950 params: [self.filterId], 3951 }, 3952 self.filterId, 3953 onMessage, 3954 self.stopWatching.bind(self) 3955 ); 3956 }; 3957 3958 var Filter = function ( 3959 options, 3960 type, 3961 requestManager, 3962 methods, 3963 formatter, 3964 callback, 3965 filterCreationErrorCallback 3966 ) { 3967 var self = this; 3968 var implementation = {}; 3969 methods.forEach(function (method) { 3970 method.setRequestManager(requestManager); 3971 method.attachToObject(implementation); 3972 }); 3973 this.requestManager = requestManager; 3974 this.options = getOptions(options, type); 3975 this.implementation = implementation; 3976 this.filterId = null; 3977 this.callbacks = []; 3978 this.getLogsCallbacks = []; 3979 this.pollFilters = []; 3980 this.formatter = formatter; 3981 this.implementation.newFilter(this.options, function (error, id) { 3982 if (error) { 3983 self.callbacks.forEach(function (cb) { 3984 cb(error); 3985 }); 3986 if (typeof filterCreationErrorCallback === "function") { 3987 filterCreationErrorCallback(error); 3988 } 3989 } else { 3990 self.filterId = id; 3991 3992 // check if there are get pending callbacks as a consequence 3993 // of calling get() with filterId unassigned. 3994 self.getLogsCallbacks.forEach(function (cb) { 3995 self.get(cb); 3996 }); 3997 self.getLogsCallbacks = []; 3998 3999 // get filter logs for the already existing watch calls 4000 self.callbacks.forEach(function (cb) { 4001 getLogsAtStart(self, cb); 4002 }); 4003 if (self.callbacks.length > 0) pollFilter(self); 4004 4005 // start to watch immediately 4006 if (typeof callback === "function") { 4007 return self.watch(callback); 4008 } 4009 } 4010 }); 4011 4012 return this; 4013 }; 4014 4015 Filter.prototype.watch = function (callback) { 4016 this.callbacks.push(callback); 4017 4018 if (this.filterId) { 4019 getLogsAtStart(this, callback); 4020 pollFilter(this); 4021 } 4022 4023 return this; 4024 }; 4025 4026 Filter.prototype.stopWatching = function (callback) { 4027 this.requestManager.stopPolling(this.filterId); 4028 this.callbacks = []; 4029 // remove filter async 4030 if (callback) { 4031 this.implementation.uninstallFilter(this.filterId, callback); 4032 } else { 4033 return this.implementation.uninstallFilter(this.filterId); 4034 } 4035 }; 4036 4037 Filter.prototype.get = function (callback) { 4038 var self = this; 4039 if (utils.isFunction(callback)) { 4040 if (this.filterId === null) { 4041 // If filterId is not set yet, call it back 4042 // when newFilter() assigns it. 4043 this.getLogsCallbacks.push(callback); 4044 } else { 4045 this.implementation.getLogs(this.filterId, function (err, res) { 4046 if (err) { 4047 callback(err); 4048 } else { 4049 callback( 4050 null, 4051 res.map(function (log) { 4052 return self.formatter ? self.formatter(log) : log; 4053 }) 4054 ); 4055 } 4056 }); 4057 } 4058 } else { 4059 if (this.filterId === null) { 4060 throw new Error( 4061 "Filter ID Error: filter().get() can't be chained synchronous, please provide a callback for the get() method." 4062 ); 4063 } 4064 var logs = this.implementation.getLogs(this.filterId); 4065 return logs.map(function (log) { 4066 return self.formatter ? self.formatter(log) : log; 4067 }); 4068 } 4069 4070 return this; 4071 }; 4072 4073 module.exports = Filter; 4074 }, 4075 { "../utils/utils": 20, "./formatters": 30 }, 4076 ], 4077 30: [ 4078 function (require, module, exports) { 4079 "use strict"; 4080 4081 /* 4082 This file is part of web3.js. 4083 4084 web3.js is free software: you can redistribute it and/or modify 4085 it under the terms of the GNU Lesser General Public License as published by 4086 the Free Software Foundation, either version 3 of the License, or 4087 (at your option) any later version. 4088 4089 web3.js is distributed in the hope that it will be useful, 4090 but WITHOUT ANY WARRANTY; without even the implied warranty of 4091 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4092 GNU Lesser General Public License for more details. 4093 4094 You should have received a copy of the GNU Lesser General Public License 4095 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4096 */ 4097 /** 4098 * @file formatters.js 4099 * @author Marek Kotewicz <marek@ethdev.com> 4100 * @author Fabian Vogelsteller <fabian@ethdev.com> 4101 * @date 2015 4102 */ 4103 4104 var utils = require("../utils/utils"); 4105 var config = require("../utils/config"); 4106 var Iban = require("./iban"); 4107 4108 /** 4109 * Should the format output to a big number 4110 * 4111 * @method outputBigNumberFormatter 4112 * @param {String|Number|BigNumber} 4113 * @returns {BigNumber} object 4114 */ 4115 var outputBigNumberFormatter = function (number) { 4116 return utils.toBigNumber(number); 4117 }; 4118 4119 var isPredefinedBlockNumber = function (blockNumber) { 4120 return ( 4121 blockNumber === "latest" || 4122 blockNumber === "pending" || 4123 blockNumber === "earliest" 4124 ); 4125 }; 4126 4127 var inputDefaultBlockNumberFormatter = function (blockNumber) { 4128 if (blockNumber === undefined) { 4129 return config.defaultBlock; 4130 } 4131 return inputBlockNumberFormatter(blockNumber); 4132 }; 4133 4134 var inputBlockNumberFormatter = function (blockNumber) { 4135 if (blockNumber === undefined) { 4136 return undefined; 4137 } else if (isPredefinedBlockNumber(blockNumber)) { 4138 return blockNumber; 4139 } 4140 return utils.toHex(blockNumber); 4141 }; 4142 4143 /** 4144 * Formats the input of a transaction and converts all values to HEX 4145 * 4146 * @method inputCallFormatter 4147 * @param {Object} transaction options 4148 * @returns object 4149 */ 4150 var inputCallFormatter = function (options) { 4151 options.from = options.from || config.defaultAccount; 4152 4153 if (options.from) { 4154 options.from = inputAddressFormatter(options.from); 4155 } 4156 4157 if (options.to) { 4158 // it might be contract creation 4159 options.to = inputAddressFormatter(options.to); 4160 } 4161 4162 ["gasPrice", "gas", "value", "nonce"] 4163 .filter(function (key) { 4164 return options[key] !== undefined; 4165 }) 4166 .forEach(function (key) { 4167 options[key] = utils.fromDecimal(options[key]); 4168 }); 4169 4170 return options; 4171 }; 4172 4173 /** 4174 * Formats the input of a transaction and converts all values to HEX 4175 * 4176 * @method inputTransactionFormatter 4177 * @param {Object} transaction options 4178 * @returns object 4179 */ 4180 var inputTransactionFormatter = function (options) { 4181 options.from = options.from || config.defaultAccount; 4182 options.from = inputAddressFormatter(options.from); 4183 4184 if (options.to) { 4185 // it might be contract creation 4186 options.to = inputAddressFormatter(options.to); 4187 } 4188 4189 ["gasPrice", "gas", "value", "nonce"] 4190 .filter(function (key) { 4191 return options[key] !== undefined; 4192 }) 4193 .forEach(function (key) { 4194 options[key] = utils.fromDecimal(options[key]); 4195 }); 4196 4197 return options; 4198 }; 4199 4200 /** 4201 * Formats the output of a transaction to its proper values 4202 * 4203 * @method outputTransactionFormatter 4204 * @param {Object} tx 4205 * @returns {Object} 4206 */ 4207 var outputTransactionFormatter = function (tx) { 4208 if (tx.blockNumber !== null) 4209 tx.blockNumber = utils.toDecimal(tx.blockNumber); 4210 if (tx.transactionIndex !== null) 4211 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 4212 tx.nonce = utils.toDecimal(tx.nonce); 4213 tx.gas = utils.toDecimal(tx.gas); 4214 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 4215 tx.value = utils.toBigNumber(tx.value); 4216 return tx; 4217 }; 4218 4219 /** 4220 * Formats the output of a transaction receipt to its proper values 4221 * 4222 * @method outputTransactionReceiptFormatter 4223 * @param {Object} receipt 4224 * @returns {Object} 4225 */ 4226 var outputTransactionReceiptFormatter = function (receipt) { 4227 if (receipt.blockNumber !== null) 4228 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 4229 if (receipt.transactionIndex !== null) 4230 receipt.transactionIndex = utils.toDecimal( 4231 receipt.transactionIndex 4232 ); 4233 receipt.cumulativeGasUsed = utils.toDecimal( 4234 receipt.cumulativeGasUsed 4235 ); 4236 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 4237 4238 if (utils.isArray(receipt.logs)) { 4239 receipt.logs = receipt.logs.map(function (log) { 4240 return outputLogFormatter(log); 4241 }); 4242 } 4243 4244 return receipt; 4245 }; 4246 4247 /** 4248 * Formats the output of a block to its proper values 4249 * 4250 * @method outputBlockFormatter 4251 * @param {Object} block 4252 * @returns {Object} 4253 */ 4254 var outputBlockFormatter = function (block) { 4255 // transform to number 4256 block.gasLimit = utils.toDecimal(block.gasLimit); 4257 block.gasUsed = utils.toDecimal(block.gasUsed); 4258 block.size = utils.toDecimal(block.size); 4259 block.timestamp = utils.toDecimal(block.timestamp); 4260 if (block.number !== null) 4261 block.number = utils.toDecimal(block.number); 4262 4263 block.difficulty = utils.toBigNumber(block.difficulty); 4264 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 4265 4266 if (utils.isArray(block.transactions)) { 4267 block.transactions.forEach(function (item) { 4268 if (!utils.isString(item)) 4269 return outputTransactionFormatter(item); 4270 }); 4271 } 4272 4273 return block; 4274 }; 4275 4276 /** 4277 * Formats the output of a log 4278 * 4279 * @method outputLogFormatter 4280 * @param {Object} log object 4281 * @returns {Object} log 4282 */ 4283 var outputLogFormatter = function (log) { 4284 if (log.blockNumber) 4285 log.blockNumber = utils.toDecimal(log.blockNumber); 4286 if (log.transactionIndex) 4287 log.transactionIndex = utils.toDecimal(log.transactionIndex); 4288 if (log.logIndex) log.logIndex = utils.toDecimal(log.logIndex); 4289 4290 return log; 4291 }; 4292 4293 /** 4294 * Formats the input of a whisper post and converts all values to HEX 4295 * 4296 * @method inputPostFormatter 4297 * @param {Object} transaction object 4298 * @returns {Object} 4299 */ 4300 var inputPostFormatter = function (post) { 4301 // post.payload = utils.toHex(post.payload); 4302 post.ttl = utils.fromDecimal(post.ttl); 4303 post.workToProve = utils.fromDecimal(post.workToProve); 4304 post.priority = utils.fromDecimal(post.priority); 4305 4306 // fallback 4307 if (!utils.isArray(post.topics)) { 4308 post.topics = post.topics ? [post.topics] : []; 4309 } 4310 4311 // format the following options 4312 post.topics = post.topics.map(function (topic) { 4313 // convert only if not hex 4314 return topic.indexOf("0x") === 0 ? topic : utils.fromUtf8(topic); 4315 }); 4316 4317 return post; 4318 }; 4319 4320 /** 4321 * Formats the output of a received post message 4322 * 4323 * @method outputPostFormatter 4324 * @param {Object} 4325 * @returns {Object} 4326 */ 4327 var outputPostFormatter = function (post) { 4328 post.expiry = utils.toDecimal(post.expiry); 4329 post.sent = utils.toDecimal(post.sent); 4330 post.ttl = utils.toDecimal(post.ttl); 4331 post.workProved = utils.toDecimal(post.workProved); 4332 // post.payloadRaw = post.payload; 4333 // post.payload = utils.toAscii(post.payload); 4334 4335 // if (utils.isJson(post.payload)) { 4336 // post.payload = JSON.parse(post.payload); 4337 // } 4338 4339 // format the following options 4340 if (!post.topics) { 4341 post.topics = []; 4342 } 4343 post.topics = post.topics.map(function (topic) { 4344 return utils.toAscii(topic); 4345 }); 4346 4347 return post; 4348 }; 4349 4350 var inputAddressFormatter = function (address) { 4351 var iban = new Iban(address); 4352 if (iban.isValid() && iban.isDirect()) { 4353 return "0x" + iban.address(); 4354 } else if (utils.isStrictAddress(address)) { 4355 return address; 4356 } else if (utils.isAddress(address)) { 4357 return "0x" + address; 4358 } 4359 throw new Error("invalid address"); 4360 }; 4361 4362 var outputSyncingFormatter = function (result) { 4363 if (!result) { 4364 return result; 4365 } 4366 4367 result.startingBlock = utils.toDecimal(result.startingBlock); 4368 result.currentBlock = utils.toDecimal(result.currentBlock); 4369 result.highestBlock = utils.toDecimal(result.highestBlock); 4370 if (result.knownStates) { 4371 result.knownStates = utils.toDecimal(result.knownStates); 4372 result.pulledStates = utils.toDecimal(result.pulledStates); 4373 } 4374 4375 return result; 4376 }; 4377 4378 module.exports = { 4379 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 4380 inputBlockNumberFormatter: inputBlockNumberFormatter, 4381 inputCallFormatter: inputCallFormatter, 4382 inputTransactionFormatter: inputTransactionFormatter, 4383 inputAddressFormatter: inputAddressFormatter, 4384 inputPostFormatter: inputPostFormatter, 4385 outputBigNumberFormatter: outputBigNumberFormatter, 4386 outputTransactionFormatter: outputTransactionFormatter, 4387 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 4388 outputBlockFormatter: outputBlockFormatter, 4389 outputLogFormatter: outputLogFormatter, 4390 outputPostFormatter: outputPostFormatter, 4391 outputSyncingFormatter: outputSyncingFormatter, 4392 }; 4393 }, 4394 { "../utils/config": 18, "../utils/utils": 20, "./iban": 33 }, 4395 ], 4396 31: [ 4397 function (require, module, exports) { 4398 /* 4399 This file is part of web3.js. 4400 4401 web3.js is free software: you can redistribute it and/or modify 4402 it under the terms of the GNU Lesser General Public License as published by 4403 the Free Software Foundation, either version 3 of the License, or 4404 (at your option) any later version. 4405 4406 web3.js is distributed in the hope that it will be useful, 4407 but WITHOUT ANY WARRANTY; without even the implied warranty of 4408 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4409 GNU Lesser General Public License for more details. 4410 4411 You should have received a copy of the GNU Lesser General Public License 4412 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4413 */ 4414 /** 4415 * @file function.js 4416 * @author Marek Kotewicz <marek@ethdev.com> 4417 * @date 2015 4418 */ 4419 4420 var coder = require("../solidity/coder"); 4421 var utils = require("../utils/utils"); 4422 var errors = require("./errors"); 4423 var formatters = require("./formatters"); 4424 var sha3 = require("../utils/sha3"); 4425 4426 /** 4427 * This prototype should be used to call/sendTransaction to solidity functions 4428 */ 4429 var SolidityFunction = function (eth, json, address) { 4430 this._eth = eth; 4431 this._inputTypes = json.inputs.map(function (i) { 4432 return i.type; 4433 }); 4434 this._outputTypes = json.outputs.map(function (i) { 4435 return i.type; 4436 }); 4437 this._constant = json.constant; 4438 this._payable = json.payable; 4439 this._name = utils.transformToFullName(json); 4440 this._address = address; 4441 }; 4442 4443 SolidityFunction.prototype.extractCallback = function (args) { 4444 if (utils.isFunction(args[args.length - 1])) { 4445 return args.pop(); // modify the args array! 4446 } 4447 }; 4448 4449 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4450 if ( 4451 args.length > this._inputTypes.length && 4452 !utils.isObject(args[args.length - 1]) 4453 ) { 4454 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4455 } 4456 }; 4457 4458 /** 4459 * Should be called to check if the number of arguments is correct 4460 * 4461 * @method validateArgs 4462 * @param {Array} arguments 4463 * @throws {Error} if it is not 4464 */ 4465 SolidityFunction.prototype.validateArgs = function (args) { 4466 var inputArgs = args.filter(function (a) { 4467 // filter the options object but not arguments that are arrays 4468 return !( 4469 utils.isObject(a) === true && 4470 utils.isArray(a) === false && 4471 utils.isBigNumber(a) === false 4472 ); 4473 }); 4474 if (inputArgs.length !== this._inputTypes.length) { 4475 throw errors.InvalidNumberOfSolidityArgs(); 4476 } 4477 }; 4478 4479 /** 4480 * Should be used to create payload from arguments 4481 * 4482 * @method toPayload 4483 * @param {Array} solidity function params 4484 * @param {Object} optional payload options 4485 */ 4486 SolidityFunction.prototype.toPayload = function (args) { 4487 var options = {}; 4488 if ( 4489 args.length > this._inputTypes.length && 4490 utils.isObject(args[args.length - 1]) 4491 ) { 4492 options = args[args.length - 1]; 4493 } 4494 this.validateArgs(args); 4495 options.to = this._address; 4496 options.data = 4497 "0x" + 4498 this.signature() + 4499 coder.encodeParams(this._inputTypes, args); 4500 return options; 4501 }; 4502 4503 /** 4504 * Should be used to get function signature 4505 * 4506 * @method signature 4507 * @return {String} function signature 4508 */ 4509 SolidityFunction.prototype.signature = function () { 4510 return sha3(this._name).slice(0, 8); 4511 }; 4512 4513 SolidityFunction.prototype.unpackOutput = function (output) { 4514 if (!output) { 4515 return; 4516 } 4517 4518 output = output.length >= 2 ? output.slice(2) : output; 4519 var result = coder.decodeParams(this._outputTypes, output); 4520 return result.length === 1 ? result[0] : result; 4521 }; 4522 4523 /** 4524 * Calls a contract function. 4525 * 4526 * @method call 4527 * @param {...Object} Contract function arguments 4528 * @param {function} If the last argument is a function, the contract function 4529 * call will be asynchronous, and the callback will be passed the 4530 * error and result. 4531 * @return {String} output bytes 4532 */ 4533 SolidityFunction.prototype.call = function () { 4534 var args = Array.prototype.slice.call(arguments).filter(function (a) { 4535 return a !== undefined; 4536 }); 4537 var callback = this.extractCallback(args); 4538 var defaultBlock = this.extractDefaultBlock(args); 4539 var payload = this.toPayload(args); 4540 4541 if (!callback) { 4542 var output = this._eth.call(payload, defaultBlock); 4543 return this.unpackOutput(output); 4544 } 4545 4546 var self = this; 4547 this._eth.call(payload, defaultBlock, function (error, output) { 4548 if (error) return callback(error, null); 4549 4550 var unpacked = null; 4551 try { 4552 unpacked = self.unpackOutput(output); 4553 } catch (e) { 4554 error = e; 4555 } 4556 4557 callback(error, unpacked); 4558 }); 4559 }; 4560 4561 /** 4562 * Should be used to sendTransaction to solidity function 4563 * 4564 * @method sendTransaction 4565 */ 4566 SolidityFunction.prototype.sendTransaction = function () { 4567 var args = Array.prototype.slice.call(arguments).filter(function (a) { 4568 return a !== undefined; 4569 }); 4570 var callback = this.extractCallback(args); 4571 var payload = this.toPayload(args); 4572 4573 if (payload.value > 0 && !this._payable) { 4574 throw new Error("Cannot send value to non-payable function"); 4575 } 4576 4577 if (!callback) { 4578 return this._eth.sendTransaction(payload); 4579 } 4580 4581 this._eth.sendTransaction(payload, callback); 4582 }; 4583 4584 /** 4585 * Should be used to estimateGas of solidity function 4586 * 4587 * @method estimateGas 4588 */ 4589 SolidityFunction.prototype.estimateGas = function () { 4590 var args = Array.prototype.slice.call(arguments); 4591 var callback = this.extractCallback(args); 4592 var payload = this.toPayload(args); 4593 4594 if (!callback) { 4595 return this._eth.estimateGas(payload); 4596 } 4597 4598 this._eth.estimateGas(payload, callback); 4599 }; 4600 4601 /** 4602 * Return the encoded data of the call 4603 * 4604 * @method getData 4605 * @return {String} the encoded data 4606 */ 4607 SolidityFunction.prototype.getData = function () { 4608 var args = Array.prototype.slice.call(arguments); 4609 var payload = this.toPayload(args); 4610 4611 return payload.data; 4612 }; 4613 4614 /** 4615 * Should be used to get function display name 4616 * 4617 * @method displayName 4618 * @return {String} display name of the function 4619 */ 4620 SolidityFunction.prototype.displayName = function () { 4621 return utils.extractDisplayName(this._name); 4622 }; 4623 4624 /** 4625 * Should be used to get function type name 4626 * 4627 * @method typeName 4628 * @return {String} type name of the function 4629 */ 4630 SolidityFunction.prototype.typeName = function () { 4631 return utils.extractTypeName(this._name); 4632 }; 4633 4634 /** 4635 * Should be called to get rpc requests from solidity function 4636 * 4637 * @method request 4638 * @returns {Object} 4639 */ 4640 SolidityFunction.prototype.request = function () { 4641 var args = Array.prototype.slice.call(arguments); 4642 var callback = this.extractCallback(args); 4643 var payload = this.toPayload(args); 4644 var format = this.unpackOutput.bind(this); 4645 4646 return { 4647 method: this._constant ? "eth_call" : "eth_sendTransaction", 4648 callback: callback, 4649 params: [payload], 4650 format: format, 4651 }; 4652 }; 4653 4654 /** 4655 * Should be called to execute function 4656 * 4657 * @method execute 4658 */ 4659 SolidityFunction.prototype.execute = function () { 4660 var transaction = !this._constant; 4661 4662 // send transaction 4663 if (transaction) { 4664 return this.sendTransaction.apply( 4665 this, 4666 Array.prototype.slice.call(arguments) 4667 ); 4668 } 4669 4670 // call 4671 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4672 }; 4673 4674 /** 4675 * Should be called to attach function to contract 4676 * 4677 * @method attachToContract 4678 * @param {Contract} 4679 */ 4680 SolidityFunction.prototype.attachToContract = function (contract) { 4681 var execute = this.execute.bind(this); 4682 execute.request = this.request.bind(this); 4683 execute.call = this.call.bind(this); 4684 execute.sendTransaction = this.sendTransaction.bind(this); 4685 execute.estimateGas = this.estimateGas.bind(this); 4686 execute.getData = this.getData.bind(this); 4687 var displayName = this.displayName(); 4688 if (!contract[displayName]) { 4689 contract[displayName] = execute; 4690 } 4691 contract[displayName][this.typeName()] = execute; // circular!!!! 4692 }; 4693 4694 module.exports = SolidityFunction; 4695 }, 4696 { 4697 "../solidity/coder": 7, 4698 "../utils/sha3": 19, 4699 "../utils/utils": 20, 4700 "./errors": 26, 4701 "./formatters": 30, 4702 }, 4703 ], 4704 32: [ 4705 function (require, module, exports) { 4706 /* 4707 This file is part of web3.js. 4708 4709 web3.js is free software: you can redistribute it and/or modify 4710 it under the terms of the GNU Lesser General Public License as published by 4711 the Free Software Foundation, either version 3 of the License, or 4712 (at your option) any later version. 4713 4714 web3.js is distributed in the hope that it will be useful, 4715 but WITHOUT ANY WARRANTY; without even the implied warranty of 4716 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4717 GNU Lesser General Public License for more details. 4718 4719 You should have received a copy of the GNU Lesser General Public License 4720 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4721 */ 4722 /** @file httpprovider.js 4723 * @authors: 4724 * Marek Kotewicz <marek@ethdev.com> 4725 * Marian Oancea <marian@ethdev.com> 4726 * Fabian Vogelsteller <fabian@ethdev.com> 4727 * @date 2015 4728 */ 4729 4730 var errors = require("./errors"); 4731 4732 // workaround to use httpprovider in different envs 4733 4734 // browser 4735 if (typeof window !== "undefined" && window.XMLHttpRequest) { 4736 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4737 // node 4738 } else { 4739 XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; // jshint ignore: line 4740 } 4741 4742 var XHR2 = require("xhr2"); // jshint ignore: line 4743 4744 /** 4745 * HttpProvider should be used to send rpc calls over http 4746 */ 4747 var HttpProvider = function (host, timeout, user, password) { 4748 this.host = host || "http://localhost:8545"; 4749 this.timeout = timeout || 0; 4750 this.user = user; 4751 this.password = password; 4752 }; 4753 4754 /** 4755 * Should be called to prepare new XMLHttpRequest 4756 * 4757 * @method prepareRequest 4758 * @param {Boolean} true if request should be async 4759 * @return {XMLHttpRequest} object 4760 */ 4761 HttpProvider.prototype.prepareRequest = function (async) { 4762 var request; 4763 4764 if (async) { 4765 request = new XHR2(); 4766 request.timeout = this.timeout; 4767 } else { 4768 request = new XMLHttpRequest(); 4769 } 4770 4771 request.open("POST", this.host, async); 4772 if (this.user && this.password) { 4773 var auth = 4774 "Basic " + 4775 new Buffer(this.user + ":" + this.password).toString("base64"); 4776 request.setRequestHeader("Authorization", auth); 4777 } 4778 request.setRequestHeader("Content-Type", "application/json"); 4779 return request; 4780 }; 4781 4782 /** 4783 * Should be called to make sync request 4784 * 4785 * @method send 4786 * @param {Object} payload 4787 * @return {Object} result 4788 */ 4789 HttpProvider.prototype.send = function (payload) { 4790 var request = this.prepareRequest(false); 4791 4792 try { 4793 request.send(JSON.stringify(payload)); 4794 } catch (error) { 4795 throw errors.InvalidConnection(this.host); 4796 } 4797 4798 var result = request.responseText; 4799 4800 try { 4801 result = JSON.parse(result); 4802 } catch (e) { 4803 throw errors.InvalidResponse(request.responseText); 4804 } 4805 4806 return result; 4807 }; 4808 4809 /** 4810 * Should be used to make async request 4811 * 4812 * @method sendAsync 4813 * @param {Object} payload 4814 * @param {Function} callback triggered on end with (err, result) 4815 */ 4816 HttpProvider.prototype.sendAsync = function (payload, callback) { 4817 var request = this.prepareRequest(true); 4818 4819 request.onreadystatechange = function () { 4820 if (request.readyState === 4 && request.timeout !== 1) { 4821 var result = request.responseText; 4822 var error = null; 4823 4824 try { 4825 result = JSON.parse(result); 4826 } catch (e) { 4827 error = errors.InvalidResponse(request.responseText); 4828 } 4829 4830 callback(error, result); 4831 } 4832 }; 4833 4834 request.ontimeout = function () { 4835 callback(errors.ConnectionTimeout(this.timeout)); 4836 }; 4837 4838 try { 4839 request.send(JSON.stringify(payload)); 4840 } catch (error) { 4841 callback(errors.InvalidConnection(this.host)); 4842 } 4843 }; 4844 4845 /** 4846 * Synchronously tries to make Http request 4847 * 4848 * @method isConnected 4849 * @return {Boolean} returns true if request haven't failed. Otherwise false 4850 */ 4851 HttpProvider.prototype.isConnected = function () { 4852 try { 4853 this.send({ 4854 id: 9999999999, 4855 jsonrpc: "2.0", 4856 method: "net_listening", 4857 params: [], 4858 }); 4859 return true; 4860 } catch (e) { 4861 return false; 4862 } 4863 }; 4864 4865 module.exports = HttpProvider; 4866 }, 4867 { "./errors": 26, xhr2: 86, xmlhttprequest: 17 }, 4868 ], 4869 33: [ 4870 function (require, module, exports) { 4871 /* 4872 This file is part of web3.js. 4873 4874 web3.js is free software: you can redistribute it and/or modify 4875 it under the terms of the GNU Lesser General Public License as published by 4876 the Free Software Foundation, either version 3 of the License, or 4877 (at your option) any later version. 4878 4879 web3.js is distributed in the hope that it will be useful, 4880 but WITHOUT ANY WARRANTY; without even the implied warranty of 4881 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4882 GNU Lesser General Public License for more details. 4883 4884 You should have received a copy of the GNU Lesser General Public License 4885 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4886 */ 4887 /** 4888 * @file iban.js 4889 * @author Marek Kotewicz <marek@ethdev.com> 4890 * @date 2015 4891 */ 4892 4893 var BigNumber = require("bignumber.js"); 4894 4895 var padLeft = function (string, bytes) { 4896 var result = string; 4897 while (result.length < bytes * 2) { 4898 result = "0" + result; 4899 } 4900 return result; 4901 }; 4902 4903 /** 4904 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4905 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4906 * 4907 * @method iso13616Prepare 4908 * @param {String} iban the IBAN 4909 * @returns {String} the prepared IBAN 4910 */ 4911 var iso13616Prepare = function (iban) { 4912 var A = "A".charCodeAt(0); 4913 var Z = "Z".charCodeAt(0); 4914 4915 iban = iban.toUpperCase(); 4916 iban = iban.substr(4) + iban.substr(0, 4); 4917 4918 return iban 4919 .split("") 4920 .map(function (n) { 4921 var code = n.charCodeAt(0); 4922 if (code >= A && code <= Z) { 4923 // A = 10, B = 11, ... Z = 35 4924 return code - A + 10; 4925 } else { 4926 return n; 4927 } 4928 }) 4929 .join(""); 4930 }; 4931 4932 /** 4933 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4934 * 4935 * @method mod9710 4936 * @param {String} iban 4937 * @returns {Number} 4938 */ 4939 var mod9710 = function (iban) { 4940 var remainder = iban, 4941 block; 4942 4943 while (remainder.length > 2) { 4944 block = remainder.slice(0, 9); 4945 remainder = 4946 (parseInt(block, 10) % 97) + remainder.slice(block.length); 4947 } 4948 4949 return parseInt(remainder, 10) % 97; 4950 }; 4951 4952 /** 4953 * This prototype should be used to create iban object from iban correct string 4954 * 4955 * @param {String} iban 4956 */ 4957 var Iban = function (iban) { 4958 this._iban = iban; 4959 }; 4960 4961 /** 4962 * This method should be used to create iban object from ethereum address 4963 * 4964 * @method fromAddress 4965 * @param {String} address 4966 * @return {Iban} the IBAN object 4967 */ 4968 Iban.fromAddress = function (address) { 4969 var asBn = new BigNumber(address, 16); 4970 var base36 = asBn.toString(36); 4971 var padded = padLeft(base36, 15); 4972 return Iban.fromBban(padded.toUpperCase()); 4973 }; 4974 4975 /** 4976 * Convert the passed BBAN to an IBAN for this country specification. 4977 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4978 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4979 * 4980 * @method fromBban 4981 * @param {String} bban the BBAN to convert to IBAN 4982 * @returns {Iban} the IBAN object 4983 */ 4984 Iban.fromBban = function (bban) { 4985 var countryCode = "XE"; 4986 4987 var remainder = mod9710(iso13616Prepare(countryCode + "00" + bban)); 4988 var checkDigit = ("0" + (98 - remainder)).slice(-2); 4989 4990 return new Iban(countryCode + checkDigit + bban); 4991 }; 4992 4993 /** 4994 * Should be used to create IBAN object for given institution and identifier 4995 * 4996 * @method createIndirect 4997 * @param {Object} options, required options are "institution" and "identifier" 4998 * @return {Iban} the IBAN object 4999 */ 5000 Iban.createIndirect = function (options) { 5001 return Iban.fromBban( 5002 "ETH" + options.institution + options.identifier 5003 ); 5004 }; 5005 5006 /** 5007 * Thos method should be used to check if given string is valid iban object 5008 * 5009 * @method isValid 5010 * @param {String} iban string 5011 * @return {Boolean} true if it is valid IBAN 5012 */ 5013 Iban.isValid = function (iban) { 5014 var i = new Iban(iban); 5015 return i.isValid(); 5016 }; 5017 5018 /** 5019 * Should be called to check if iban is correct 5020 * 5021 * @method isValid 5022 * @returns {Boolean} true if it is, otherwise false 5023 */ 5024 Iban.prototype.isValid = function () { 5025 return ( 5026 /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 5027 mod9710(iso13616Prepare(this._iban)) === 1 5028 ); 5029 }; 5030 5031 /** 5032 * Should be called to check if iban number is direct 5033 * 5034 * @method isDirect 5035 * @returns {Boolean} true if it is, otherwise false 5036 */ 5037 Iban.prototype.isDirect = function () { 5038 return this._iban.length === 34 || this._iban.length === 35; 5039 }; 5040 5041 /** 5042 * Should be called to check if iban number if indirect 5043 * 5044 * @method isIndirect 5045 * @returns {Boolean} true if it is, otherwise false 5046 */ 5047 Iban.prototype.isIndirect = function () { 5048 return this._iban.length === 20; 5049 }; 5050 5051 /** 5052 * Should be called to get iban checksum 5053 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 5054 * 5055 * @method checksum 5056 * @returns {String} checksum 5057 */ 5058 Iban.prototype.checksum = function () { 5059 return this._iban.substr(2, 2); 5060 }; 5061 5062 /** 5063 * Should be called to get institution identifier 5064 * eg. XREG 5065 * 5066 * @method institution 5067 * @returns {String} institution identifier 5068 */ 5069 Iban.prototype.institution = function () { 5070 return this.isIndirect() ? this._iban.substr(7, 4) : ""; 5071 }; 5072 5073 /** 5074 * Should be called to get client identifier within institution 5075 * eg. GAVOFYORK 5076 * 5077 * @method client 5078 * @returns {String} client identifier 5079 */ 5080 Iban.prototype.client = function () { 5081 return this.isIndirect() ? this._iban.substr(11) : ""; 5082 }; 5083 5084 /** 5085 * Should be called to get client direct address 5086 * 5087 * @method address 5088 * @returns {String} client direct address 5089 */ 5090 Iban.prototype.address = function () { 5091 if (this.isDirect()) { 5092 var base36 = this._iban.substr(4); 5093 var asBn = new BigNumber(base36, 36); 5094 return padLeft(asBn.toString(16), 20); 5095 } 5096 5097 return ""; 5098 }; 5099 5100 Iban.prototype.toString = function () { 5101 return this._iban; 5102 }; 5103 5104 module.exports = Iban; 5105 }, 5106 { "bignumber.js": "bignumber.js" }, 5107 ], 5108 34: [ 5109 function (require, module, exports) { 5110 /* 5111 This file is part of web3.js. 5112 5113 web3.js is free software: you can redistribute it and/or modify 5114 it under the terms of the GNU Lesser General Public License as published by 5115 the Free Software Foundation, either version 3 of the License, or 5116 (at your option) any later version. 5117 5118 web3.js is distributed in the hope that it will be useful, 5119 but WITHOUT ANY WARRANTY; without even the implied warranty of 5120 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5121 GNU Lesser General Public License for more details. 5122 5123 You should have received a copy of the GNU Lesser General Public License 5124 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5125 */ 5126 /** @file ipcprovider.js 5127 * @authors: 5128 * Fabian Vogelsteller <fabian@ethdev.com> 5129 * @date 2015 5130 */ 5131 5132 "use strict"; 5133 5134 var utils = require("../utils/utils"); 5135 var errors = require("./errors"); 5136 5137 var IpcProvider = function (path, net) { 5138 var _this = this; 5139 this.responseCallbacks = {}; 5140 this.path = path; 5141 5142 this.connection = net.connect({ path: this.path }); 5143 5144 this.connection.on("error", function (e) { 5145 console.error("IPC Connection Error", e); 5146 _this._timeout(); 5147 }); 5148 5149 this.connection.on("end", function () { 5150 _this._timeout(); 5151 }); 5152 5153 // LISTEN FOR CONNECTION RESPONSES 5154 this.connection.on("data", function (data) { 5155 /*jshint maxcomplexity: 6 */ 5156 5157 _this._parseResponse(data.toString()).forEach(function (result) { 5158 var id = null; 5159 5160 // get the id which matches the returned id 5161 if (utils.isArray(result)) { 5162 result.forEach(function (load) { 5163 if (_this.responseCallbacks[load.id]) id = load.id; 5164 }); 5165 } else { 5166 id = result.id; 5167 } 5168 5169 // fire the callback 5170 if (_this.responseCallbacks[id]) { 5171 _this.responseCallbacks[id](null, result); 5172 delete _this.responseCallbacks[id]; 5173 } 5174 }); 5175 }); 5176 }; 5177 5178 /** 5179 Will parse the response and make an array out of it. 5180 5181 @method _parseResponse 5182 @param {String} data 5183 */ 5184 IpcProvider.prototype._parseResponse = function (data) { 5185 var _this = this, 5186 returnValues = []; 5187 5188 // DE-CHUNKER 5189 var dechunkedData = data 5190 .replace(/\}[\n\r]?\{/g, "}|--|{") // }{ 5191 .replace(/\}\][\n\r]?\[\{/g, "}]|--|[{") // }][{ 5192 .replace(/\}[\n\r]?\[\{/g, "}|--|[{") // }[{ 5193 .replace(/\}\][\n\r]?\{/g, "}]|--|{") // }]{ 5194 .split("|--|"); 5195 5196 dechunkedData.forEach(function (data) { 5197 // prepend the last chunk 5198 if (_this.lastChunk) data = _this.lastChunk + data; 5199 5200 var result = null; 5201 5202 try { 5203 result = JSON.parse(data); 5204 } catch (e) { 5205 _this.lastChunk = data; 5206 5207 // start timeout to cancel all requests 5208 clearTimeout(_this.lastChunkTimeout); 5209 _this.lastChunkTimeout = setTimeout(function () { 5210 _this._timeout(); 5211 throw errors.InvalidResponse(data); 5212 }, 1000 * 15); 5213 5214 return; 5215 } 5216 5217 // cancel timeout and set chunk to null 5218 clearTimeout(_this.lastChunkTimeout); 5219 _this.lastChunk = null; 5220 5221 if (result) returnValues.push(result); 5222 }); 5223 5224 return returnValues; 5225 }; 5226 5227 /** 5228 Get the adds a callback to the responseCallbacks object, 5229 which will be called if a response matching the response Id will arrive. 5230 5231 @method _addResponseCallback 5232 */ 5233 IpcProvider.prototype._addResponseCallback = function ( 5234 payload, 5235 callback 5236 ) { 5237 var id = payload.id || payload[0].id; 5238 var method = payload.method || payload[0].method; 5239 5240 this.responseCallbacks[id] = callback; 5241 this.responseCallbacks[id].method = method; 5242 }; 5243 5244 /** 5245 Timeout all requests when the end/error event is fired 5246 5247 @method _timeout 5248 */ 5249 IpcProvider.prototype._timeout = function () { 5250 for (var key in this.responseCallbacks) { 5251 if (this.responseCallbacks.hasOwnProperty(key)) { 5252 this.responseCallbacks[key](errors.InvalidConnection("on IPC")); 5253 delete this.responseCallbacks[key]; 5254 } 5255 } 5256 }; 5257 5258 /** 5259 Check if the current connection is still valid. 5260 5261 @method isConnected 5262 */ 5263 IpcProvider.prototype.isConnected = function () { 5264 var _this = this; 5265 5266 // try reconnect, when connection is gone 5267 if (!_this.connection.writable) 5268 _this.connection.connect({ path: _this.path }); 5269 5270 return !!this.connection.writable; 5271 }; 5272 5273 IpcProvider.prototype.send = function (payload) { 5274 if (this.connection.writeSync) { 5275 var result; 5276 5277 // try reconnect, when connection is gone 5278 if (!this.connection.writable) 5279 this.connection.connect({ path: this.path }); 5280 5281 var data = this.connection.writeSync(JSON.stringify(payload)); 5282 5283 try { 5284 result = JSON.parse(data); 5285 } catch (e) { 5286 throw errors.InvalidResponse(data); 5287 } 5288 5289 return result; 5290 } else { 5291 throw new Error( 5292 'You tried to send "' + 5293 payload.method + 5294 '" synchronously. Synchronous requests are not supported by the IPC provider.' 5295 ); 5296 } 5297 }; 5298 5299 IpcProvider.prototype.sendAsync = function (payload, callback) { 5300 // try reconnect, when connection is gone 5301 if (!this.connection.writable) 5302 this.connection.connect({ path: this.path }); 5303 5304 this.connection.write(JSON.stringify(payload)); 5305 this._addResponseCallback(payload, callback); 5306 }; 5307 5308 module.exports = IpcProvider; 5309 }, 5310 { "../utils/utils": 20, "./errors": 26 }, 5311 ], 5312 35: [ 5313 function (require, module, exports) { 5314 /* 5315 This file is part of web3.js. 5316 5317 web3.js is free software: you can redistribute it and/or modify 5318 it under the terms of the GNU Lesser General Public License as published by 5319 the Free Software Foundation, either version 3 of the License, or 5320 (at your option) any later version. 5321 5322 web3.js is distributed in the hope that it will be useful, 5323 but WITHOUT ANY WARRANTY; without even the implied warranty of 5324 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5325 GNU Lesser General Public License for more details. 5326 5327 You should have received a copy of the GNU Lesser General Public License 5328 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5329 */ 5330 /** @file jsonrpc.js 5331 * @authors: 5332 * Marek Kotewicz <marek@ethdev.com> 5333 * Aaron Kumavis <aaron@kumavis.me> 5334 * @date 2015 5335 */ 5336 5337 // Initialize Jsonrpc as a simple object with utility functions. 5338 var Jsonrpc = { 5339 messageId: 0, 5340 }; 5341 5342 /** 5343 * Should be called to valid json create payload object 5344 * 5345 * @method toPayload 5346 * @param {Function} method of jsonrpc call, required 5347 * @param {Array} params, an array of method params, optional 5348 * @returns {Object} valid jsonrpc payload object 5349 */ 5350 Jsonrpc.toPayload = function (method, params) { 5351 if (!method) console.error("jsonrpc method should be specified!"); 5352 5353 // advance message ID 5354 Jsonrpc.messageId++; 5355 5356 return { 5357 jsonrpc: "2.0", 5358 id: Jsonrpc.messageId, 5359 method: method, 5360 params: params || [], 5361 }; 5362 }; 5363 5364 /** 5365 * Should be called to check if jsonrpc response is valid 5366 * 5367 * @method isValidResponse 5368 * @param {Object} 5369 * @returns {Boolean} true if response is valid, otherwise false 5370 */ 5371 Jsonrpc.isValidResponse = function (response) { 5372 return Array.isArray(response) 5373 ? response.every(validateSingleMessage) 5374 : validateSingleMessage(response); 5375 5376 function validateSingleMessage(message) { 5377 return ( 5378 !!message && 5379 !message.error && 5380 message.jsonrpc === "2.0" && 5381 typeof message.id === "number" && 5382 message.result !== undefined 5383 ); // only undefined is not valid json object 5384 } 5385 }; 5386 5387 /** 5388 * Should be called to create batch payload object 5389 * 5390 * @method toBatchPayload 5391 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 5392 * @returns {Array} batch payload 5393 */ 5394 Jsonrpc.toBatchPayload = function (messages) { 5395 return messages.map(function (message) { 5396 return Jsonrpc.toPayload(message.method, message.params); 5397 }); 5398 }; 5399 5400 module.exports = Jsonrpc; 5401 }, 5402 {}, 5403 ], 5404 36: [ 5405 function (require, module, exports) { 5406 /* 5407 This file is part of web3.js. 5408 5409 web3.js is free software: you can redistribute it and/or modify 5410 it under the terms of the GNU Lesser General Public License as published by 5411 the Free Software Foundation, either version 3 of the License, or 5412 (at your option) any later version. 5413 5414 web3.js is distributed in the hope that it will be useful, 5415 but WITHOUT ANY WARRANTY; without even the implied warranty of 5416 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5417 GNU Lesser General Public License for more details. 5418 5419 You should have received a copy of the GNU Lesser General Public License 5420 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5421 */ 5422 /** 5423 * @file method.js 5424 * @author Marek Kotewicz <marek@ethdev.com> 5425 * @date 2015 5426 */ 5427 5428 var utils = require("../utils/utils"); 5429 var errors = require("./errors"); 5430 5431 var Method = function (options) { 5432 this.name = options.name; 5433 this.call = options.call; 5434 this.params = options.params || 0; 5435 this.inputFormatter = options.inputFormatter; 5436 this.outputFormatter = options.outputFormatter; 5437 this.requestManager = null; 5438 }; 5439 5440 Method.prototype.setRequestManager = function (rm) { 5441 this.requestManager = rm; 5442 }; 5443 5444 /** 5445 * Should be used to determine name of the jsonrpc method based on arguments 5446 * 5447 * @method getCall 5448 * @param {Array} arguments 5449 * @return {String} name of jsonrpc method 5450 */ 5451 Method.prototype.getCall = function (args) { 5452 return utils.isFunction(this.call) ? this.call(args) : this.call; 5453 }; 5454 5455 /** 5456 * Should be used to extract callback from array of arguments. Modifies input param 5457 * 5458 * @method extractCallback 5459 * @param {Array} arguments 5460 * @return {Function|Null} callback, if exists 5461 */ 5462 Method.prototype.extractCallback = function (args) { 5463 if (utils.isFunction(args[args.length - 1])) { 5464 return args.pop(); // modify the args array! 5465 } 5466 }; 5467 5468 /** 5469 * Should be called to check if the number of arguments is correct 5470 * 5471 * @method validateArgs 5472 * @param {Array} arguments 5473 * @throws {Error} if it is not 5474 */ 5475 Method.prototype.validateArgs = function (args) { 5476 if (args.length !== this.params) { 5477 throw errors.InvalidNumberOfRPCParams(); 5478 } 5479 }; 5480 5481 /** 5482 * Should be called to format input args of method 5483 * 5484 * @method formatInput 5485 * @param {Array} 5486 * @return {Array} 5487 */ 5488 Method.prototype.formatInput = function (args) { 5489 if (!this.inputFormatter) { 5490 return args; 5491 } 5492 5493 return this.inputFormatter.map(function (formatter, index) { 5494 return formatter ? formatter(args[index]) : args[index]; 5495 }); 5496 }; 5497 5498 /** 5499 * Should be called to format output(result) of method 5500 * 5501 * @method formatOutput 5502 * @param {Object} 5503 * @return {Object} 5504 */ 5505 Method.prototype.formatOutput = function (result) { 5506 return this.outputFormatter && result 5507 ? this.outputFormatter(result) 5508 : result; 5509 }; 5510 5511 /** 5512 * Should create payload from given input args 5513 * 5514 * @method toPayload 5515 * @param {Array} args 5516 * @return {Object} 5517 */ 5518 Method.prototype.toPayload = function (args) { 5519 var call = this.getCall(args); 5520 var callback = this.extractCallback(args); 5521 var params = this.formatInput(args); 5522 this.validateArgs(params); 5523 5524 return { 5525 method: call, 5526 params: params, 5527 callback: callback, 5528 }; 5529 }; 5530 5531 Method.prototype.attachToObject = function (obj) { 5532 var func = this.buildCall(); 5533 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5534 var name = this.name.split("."); 5535 if (name.length > 1) { 5536 obj[name[0]] = obj[name[0]] || {}; 5537 obj[name[0]][name[1]] = func; 5538 } else { 5539 obj[name[0]] = func; 5540 } 5541 }; 5542 5543 Method.prototype.buildCall = function () { 5544 var method = this; 5545 var send = function () { 5546 var payload = method.toPayload( 5547 Array.prototype.slice.call(arguments) 5548 ); 5549 if (payload.callback) { 5550 return method.requestManager.sendAsync( 5551 payload, 5552 function (err, result) { 5553 payload.callback(err, method.formatOutput(result)); 5554 } 5555 ); 5556 } 5557 return method.formatOutput(method.requestManager.send(payload)); 5558 }; 5559 send.request = this.request.bind(this); 5560 return send; 5561 }; 5562 5563 /** 5564 * Should be called to create pure JSONRPC request which can be used in batch request 5565 * 5566 * @method request 5567 * @param {...} params 5568 * @return {Object} jsonrpc request 5569 */ 5570 Method.prototype.request = function () { 5571 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5572 payload.format = this.formatOutput.bind(this); 5573 return payload; 5574 }; 5575 5576 module.exports = Method; 5577 }, 5578 { "../utils/utils": 20, "./errors": 26 }, 5579 ], 5580 37: [ 5581 function (require, module, exports) { 5582 /* 5583 This file is part of web3.js. 5584 5585 web3.js is free software: you can redistribute it and/or modify 5586 it under the terms of the GNU Lesser General Public License as published by 5587 the Free Software Foundation, either version 3 of the License, or 5588 (at your option) any later version. 5589 5590 web3.js is distributed in the hope that it will be useful, 5591 but WITHOUT ANY WARRANTY; without even the implied warranty of 5592 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5593 GNU Lesser General Public License for more details. 5594 5595 You should have received a copy of the GNU Lesser General Public License 5596 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5597 */ 5598 /** @file db.js 5599 * @authors: 5600 * Marek Kotewicz <marek@ethdev.com> 5601 * @date 2015 5602 */ 5603 5604 var Method = require("../method"); 5605 5606 var DB = function (web3) { 5607 this._requestManager = web3._requestManager; 5608 5609 var self = this; 5610 5611 methods().forEach(function (method) { 5612 method.attachToObject(self); 5613 method.setRequestManager(web3._requestManager); 5614 }); 5615 }; 5616 5617 var methods = function () { 5618 var putString = new Method({ 5619 name: "putString", 5620 call: "db_putString", 5621 params: 3, 5622 }); 5623 5624 var getString = new Method({ 5625 name: "getString", 5626 call: "db_getString", 5627 params: 2, 5628 }); 5629 5630 var putHex = new Method({ 5631 name: "putHex", 5632 call: "db_putHex", 5633 params: 3, 5634 }); 5635 5636 var getHex = new Method({ 5637 name: "getHex", 5638 call: "db_getHex", 5639 params: 2, 5640 }); 5641 5642 return [putString, getString, putHex, getHex]; 5643 }; 5644 5645 module.exports = DB; 5646 }, 5647 { "../method": 36 }, 5648 ], 5649 38: [ 5650 function (require, module, exports) { 5651 /* 5652 This file is part of web3.js. 5653 5654 web3.js is free software: you can redistribute it and/or modify 5655 it under the terms of the GNU Lesser General Public License as published by 5656 the Free Software Foundation, either version 3 of the License, or 5657 (at your option) any later version. 5658 5659 web3.js is distributed in the hope that it will be useful, 5660 but WITHOUT ANY WARRANTY; without even the implied warranty of 5661 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5662 GNU Lesser General Public License for more details. 5663 5664 You should have received a copy of the GNU Lesser General Public License 5665 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5666 */ 5667 /** 5668 * @file eth.js 5669 * @author Marek Kotewicz <marek@ethdev.com> 5670 * @author Fabian Vogelsteller <fabian@ethdev.com> 5671 * @date 2015 5672 */ 5673 5674 "use strict"; 5675 5676 var formatters = require("../formatters"); 5677 var utils = require("../../utils/utils"); 5678 var Method = require("../method"); 5679 var Property = require("../property"); 5680 var c = require("../../utils/config"); 5681 var Contract = require("../contract"); 5682 var watches = require("./watches"); 5683 var Filter = require("../filter"); 5684 var IsSyncing = require("../syncing"); 5685 var namereg = require("../namereg"); 5686 var Iban = require("../iban"); 5687 var transfer = require("../transfer"); 5688 5689 var blockCall = function (args) { 5690 return utils.isString(args[0]) && args[0].indexOf("0x") === 0 5691 ? "eth_getBlockByHash" 5692 : "eth_getBlockByNumber"; 5693 }; 5694 5695 var transactionFromBlockCall = function (args) { 5696 return utils.isString(args[0]) && args[0].indexOf("0x") === 0 5697 ? "eth_getTransactionByBlockHashAndIndex" 5698 : "eth_getTransactionByBlockNumberAndIndex"; 5699 }; 5700 5701 var uncleCall = function (args) { 5702 return utils.isString(args[0]) && args[0].indexOf("0x") === 0 5703 ? "eth_getUncleByBlockHashAndIndex" 5704 : "eth_getUncleByBlockNumberAndIndex"; 5705 }; 5706 5707 var getBlockTransactionCountCall = function (args) { 5708 return utils.isString(args[0]) && args[0].indexOf("0x") === 0 5709 ? "eth_getBlockTransactionCountByHash" 5710 : "eth_getBlockTransactionCountByNumber"; 5711 }; 5712 5713 var uncleCountCall = function (args) { 5714 return utils.isString(args[0]) && args[0].indexOf("0x") === 0 5715 ? "eth_getUncleCountByBlockHash" 5716 : "eth_getUncleCountByBlockNumber"; 5717 }; 5718 5719 function Eth(web3) { 5720 this._requestManager = web3._requestManager; 5721 5722 var self = this; 5723 5724 methods().forEach(function (method) { 5725 method.attachToObject(self); 5726 method.setRequestManager(self._requestManager); 5727 }); 5728 5729 properties().forEach(function (p) { 5730 p.attachToObject(self); 5731 p.setRequestManager(self._requestManager); 5732 }); 5733 5734 this.iban = Iban; 5735 this.sendIBANTransaction = transfer.bind(null, this); 5736 } 5737 5738 Object.defineProperty(Eth.prototype, "defaultBlock", { 5739 get: function () { 5740 return c.defaultBlock; 5741 }, 5742 set: function (val) { 5743 c.defaultBlock = val; 5744 return val; 5745 }, 5746 }); 5747 5748 Object.defineProperty(Eth.prototype, "defaultAccount", { 5749 get: function () { 5750 return c.defaultAccount; 5751 }, 5752 set: function (val) { 5753 c.defaultAccount = val; 5754 return val; 5755 }, 5756 }); 5757 5758 var methods = function () { 5759 var getBalance = new Method({ 5760 name: "getBalance", 5761 call: "eth_getBalance", 5762 params: 2, 5763 inputFormatter: [ 5764 formatters.inputAddressFormatter, 5765 formatters.inputDefaultBlockNumberFormatter, 5766 ], 5767 outputFormatter: formatters.outputBigNumberFormatter, 5768 }); 5769 5770 var getStorageAt = new Method({ 5771 name: "getStorageAt", 5772 call: "eth_getStorageAt", 5773 params: 3, 5774 inputFormatter: [ 5775 null, 5776 utils.toHex, 5777 formatters.inputDefaultBlockNumberFormatter, 5778 ], 5779 }); 5780 5781 var getCode = new Method({ 5782 name: "getCode", 5783 call: "eth_getCode", 5784 params: 2, 5785 inputFormatter: [ 5786 formatters.inputAddressFormatter, 5787 formatters.inputDefaultBlockNumberFormatter, 5788 ], 5789 }); 5790 5791 var getBlock = new Method({ 5792 name: "getBlock", 5793 call: blockCall, 5794 params: 2, 5795 inputFormatter: [ 5796 formatters.inputBlockNumberFormatter, 5797 function (val) { 5798 return !!val; 5799 }, 5800 ], 5801 outputFormatter: formatters.outputBlockFormatter, 5802 }); 5803 5804 var getUncle = new Method({ 5805 name: "getUncle", 5806 call: uncleCall, 5807 params: 2, 5808 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5809 outputFormatter: formatters.outputBlockFormatter, 5810 }); 5811 5812 var getCompilers = new Method({ 5813 name: "getCompilers", 5814 call: "eth_getCompilers", 5815 params: 0, 5816 }); 5817 5818 var getBlockTransactionCount = new Method({ 5819 name: "getBlockTransactionCount", 5820 call: getBlockTransactionCountCall, 5821 params: 1, 5822 inputFormatter: [formatters.inputBlockNumberFormatter], 5823 outputFormatter: utils.toDecimal, 5824 }); 5825 5826 var getBlockUncleCount = new Method({ 5827 name: "getBlockUncleCount", 5828 call: uncleCountCall, 5829 params: 1, 5830 inputFormatter: [formatters.inputBlockNumberFormatter], 5831 outputFormatter: utils.toDecimal, 5832 }); 5833 5834 var getTransaction = new Method({ 5835 name: "getTransaction", 5836 call: "eth_getTransactionByHash", 5837 params: 1, 5838 outputFormatter: formatters.outputTransactionFormatter, 5839 }); 5840 5841 var getTransactionFromBlock = new Method({ 5842 name: "getTransactionFromBlock", 5843 call: transactionFromBlockCall, 5844 params: 2, 5845 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5846 outputFormatter: formatters.outputTransactionFormatter, 5847 }); 5848 5849 var getTransactionReceipt = new Method({ 5850 name: "getTransactionReceipt", 5851 call: "eth_getTransactionReceipt", 5852 params: 1, 5853 outputFormatter: formatters.outputTransactionReceiptFormatter, 5854 }); 5855 5856 var getTransactionCount = new Method({ 5857 name: "getTransactionCount", 5858 call: "eth_getTransactionCount", 5859 params: 2, 5860 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5861 outputFormatter: utils.toDecimal, 5862 }); 5863 5864 var sendRawTransaction = new Method({ 5865 name: "sendRawTransaction", 5866 call: "eth_sendRawTransaction", 5867 params: 1, 5868 inputFormatter: [null], 5869 }); 5870 5871 var sendTransaction = new Method({ 5872 name: "sendTransaction", 5873 call: "eth_sendTransaction", 5874 params: 1, 5875 inputFormatter: [formatters.inputTransactionFormatter], 5876 }); 5877 5878 var signTransaction = new Method({ 5879 name: "signTransaction", 5880 call: "eth_signTransaction", 5881 params: 1, 5882 inputFormatter: [formatters.inputTransactionFormatter], 5883 }); 5884 5885 var sign = new Method({ 5886 name: "sign", 5887 call: "eth_sign", 5888 params: 2, 5889 inputFormatter: [formatters.inputAddressFormatter, null], 5890 }); 5891 5892 var call = new Method({ 5893 name: "call", 5894 call: "eth_call", 5895 params: 2, 5896 inputFormatter: [ 5897 formatters.inputCallFormatter, 5898 formatters.inputDefaultBlockNumberFormatter, 5899 ], 5900 }); 5901 5902 var estimateGas = new Method({ 5903 name: "estimateGas", 5904 call: "eth_estimateGas", 5905 params: 1, 5906 inputFormatter: [formatters.inputCallFormatter], 5907 outputFormatter: utils.toDecimal, 5908 }); 5909 5910 var compileSolidity = new Method({ 5911 name: "compile.solidity", 5912 call: "eth_compileSolidity", 5913 params: 1, 5914 }); 5915 5916 var compileLLL = new Method({ 5917 name: "compile.lll", 5918 call: "eth_compileLLL", 5919 params: 1, 5920 }); 5921 5922 var compileSerpent = new Method({ 5923 name: "compile.serpent", 5924 call: "eth_compileSerpent", 5925 params: 1, 5926 }); 5927 5928 var submitWork = new Method({ 5929 name: "submitWork", 5930 call: "eth_submitWork", 5931 params: 3, 5932 }); 5933 5934 var getWork = new Method({ 5935 name: "getWork", 5936 call: "eth_getWork", 5937 params: 0, 5938 }); 5939 5940 return [ 5941 getBalance, 5942 getStorageAt, 5943 getCode, 5944 getBlock, 5945 getUncle, 5946 getCompilers, 5947 getBlockTransactionCount, 5948 getBlockUncleCount, 5949 getTransaction, 5950 getTransactionFromBlock, 5951 getTransactionReceipt, 5952 getTransactionCount, 5953 call, 5954 estimateGas, 5955 sendRawTransaction, 5956 signTransaction, 5957 sendTransaction, 5958 sign, 5959 compileSolidity, 5960 compileLLL, 5961 compileSerpent, 5962 submitWork, 5963 getWork, 5964 ]; 5965 }; 5966 5967 var properties = function () { 5968 return [ 5969 new Property({ 5970 name: "coinbase", 5971 getter: "eth_coinbase", 5972 }), 5973 new Property({ 5974 name: "mining", 5975 getter: "eth_mining", 5976 }), 5977 new Property({ 5978 name: "hashrate", 5979 getter: "eth_hashrate", 5980 outputFormatter: utils.toDecimal, 5981 }), 5982 new Property({ 5983 name: "syncing", 5984 getter: "eth_syncing", 5985 outputFormatter: formatters.outputSyncingFormatter, 5986 }), 5987 new Property({ 5988 name: "gasPrice", 5989 getter: "eth_gasPrice", 5990 outputFormatter: formatters.outputBigNumberFormatter, 5991 }), 5992 new Property({ 5993 name: "accounts", 5994 getter: "eth_accounts", 5995 }), 5996 new Property({ 5997 name: "blockNumber", 5998 getter: "eth_blockNumber", 5999 outputFormatter: utils.toDecimal, 6000 }), 6001 new Property({ 6002 name: "protocolVersion", 6003 getter: "eth_protocolVersion", 6004 }), 6005 ]; 6006 }; 6007 6008 Eth.prototype.contract = function (abi) { 6009 var factory = new Contract(this, abi); 6010 return factory; 6011 }; 6012 6013 Eth.prototype.filter = function ( 6014 options, 6015 callback, 6016 filterCreationErrorCallback 6017 ) { 6018 return new Filter( 6019 options, 6020 "eth", 6021 this._requestManager, 6022 watches.eth(), 6023 formatters.outputLogFormatter, 6024 callback, 6025 filterCreationErrorCallback 6026 ); 6027 }; 6028 6029 Eth.prototype.namereg = function () { 6030 return this.contract(namereg.global.abi).at(namereg.global.address); 6031 }; 6032 6033 Eth.prototype.icapNamereg = function () { 6034 return this.contract(namereg.icap.abi).at(namereg.icap.address); 6035 }; 6036 6037 Eth.prototype.isSyncing = function (callback) { 6038 return new IsSyncing(this._requestManager, callback); 6039 }; 6040 6041 module.exports = Eth; 6042 }, 6043 { 6044 "../../utils/config": 18, 6045 "../../utils/utils": 20, 6046 "../contract": 25, 6047 "../filter": 29, 6048 "../formatters": 30, 6049 "../iban": 33, 6050 "../method": 36, 6051 "../namereg": 44, 6052 "../property": 45, 6053 "../syncing": 48, 6054 "../transfer": 49, 6055 "./watches": 43, 6056 }, 6057 ], 6058 39: [ 6059 function (require, module, exports) { 6060 /* 6061 This file is part of web3.js. 6062 6063 web3.js is free software: you can redistribute it and/or modify 6064 it under the terms of the GNU Lesser General Public License as published by 6065 the Free Software Foundation, either version 3 of the License, or 6066 (at your option) any later version. 6067 6068 web3.js is distributed in the hope that it will be useful, 6069 but WITHOUT ANY WARRANTY; without even the implied warranty of 6070 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6071 GNU Lesser General Public License for more details. 6072 6073 You should have received a copy of the GNU Lesser General Public License 6074 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6075 */ 6076 /** @file eth.js 6077 * @authors: 6078 * Marek Kotewicz <marek@ethdev.com> 6079 * @date 2015 6080 */ 6081 6082 var utils = require("../../utils/utils"); 6083 var Property = require("../property"); 6084 6085 var Net = function (web3) { 6086 this._requestManager = web3._requestManager; 6087 6088 var self = this; 6089 6090 properties().forEach(function (p) { 6091 p.attachToObject(self); 6092 p.setRequestManager(web3._requestManager); 6093 }); 6094 }; 6095 6096 /// @returns an array of objects describing web3.eth api properties 6097 var properties = function () { 6098 return [ 6099 new Property({ 6100 name: "listening", 6101 getter: "net_listening", 6102 }), 6103 new Property({ 6104 name: "peerCount", 6105 getter: "net_peerCount", 6106 outputFormatter: utils.toDecimal, 6107 }), 6108 ]; 6109 }; 6110 6111 module.exports = Net; 6112 }, 6113 { "../../utils/utils": 20, "../property": 45 }, 6114 ], 6115 40: [ 6116 function (require, module, exports) { 6117 /* 6118 This file is part of web3.js. 6119 6120 web3.js is free software: you can redistribute it and/or modify 6121 it under the terms of the GNU Lesser General Public License as published by 6122 the Free Software Foundation, either version 3 of the License, or 6123 (at your option) any later version. 6124 6125 web3.js is distributed in the hope that it will be useful, 6126 but WITHOUT ANY WARRANTY; without even the implied warranty of 6127 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6128 GNU Lesser General Public License for more details. 6129 6130 You should have received a copy of the GNU Lesser General Public License 6131 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6132 */ 6133 /** 6134 * @file eth.js 6135 * @author Marek Kotewicz <marek@ethdev.com> 6136 * @author Fabian Vogelsteller <fabian@ethdev.com> 6137 * @date 2015 6138 */ 6139 6140 "use strict"; 6141 6142 var Method = require("../method"); 6143 var Property = require("../property"); 6144 var formatters = require("../formatters"); 6145 6146 function Personal(web3) { 6147 this._requestManager = web3._requestManager; 6148 6149 var self = this; 6150 6151 methods().forEach(function (method) { 6152 method.attachToObject(self); 6153 method.setRequestManager(self._requestManager); 6154 }); 6155 6156 properties().forEach(function (p) { 6157 p.attachToObject(self); 6158 p.setRequestManager(self._requestManager); 6159 }); 6160 } 6161 6162 var methods = function () { 6163 var newAccount = new Method({ 6164 name: "newAccount", 6165 call: "personal_newAccount", 6166 params: 1, 6167 inputFormatter: [null], 6168 }); 6169 6170 var importRawKey = new Method({ 6171 name: "importRawKey", 6172 call: "personal_importRawKey", 6173 params: 2, 6174 }); 6175 6176 var sign = new Method({ 6177 name: "sign", 6178 call: "personal_sign", 6179 params: 3, 6180 inputFormatter: [null, formatters.inputAddressFormatter, null], 6181 }); 6182 6183 var ecRecover = new Method({ 6184 name: "ecRecover", 6185 call: "personal_ecRecover", 6186 params: 2, 6187 }); 6188 6189 var unlockAccount = new Method({ 6190 name: "unlockAccount", 6191 call: "personal_unlockAccount", 6192 params: 3, 6193 inputFormatter: [formatters.inputAddressFormatter, null, null], 6194 }); 6195 6196 var sendTransaction = new Method({ 6197 name: "sendTransaction", 6198 call: "personal_sendTransaction", 6199 params: 2, 6200 inputFormatter: [formatters.inputTransactionFormatter, null], 6201 }); 6202 6203 var lockAccount = new Method({ 6204 name: "lockAccount", 6205 call: "personal_lockAccount", 6206 params: 1, 6207 inputFormatter: [formatters.inputAddressFormatter], 6208 }); 6209 6210 return [ 6211 newAccount, 6212 importRawKey, 6213 unlockAccount, 6214 ecRecover, 6215 sign, 6216 sendTransaction, 6217 lockAccount, 6218 ]; 6219 }; 6220 6221 var properties = function () { 6222 return [ 6223 new Property({ 6224 name: "listAccounts", 6225 getter: "personal_listAccounts", 6226 }), 6227 ]; 6228 }; 6229 6230 module.exports = Personal; 6231 }, 6232 { "../formatters": 30, "../method": 36, "../property": 45 }, 6233 ], 6234 41: [ 6235 function (require, module, exports) { 6236 /* 6237 This file is part of web3.js. 6238 6239 web3.js is free software: you can redistribute it and/or modify 6240 it under the terms of the GNU Lesser General Public License as published by 6241 the Free Software Foundation, either version 3 of the License, or 6242 (at your option) any later version. 6243 6244 web3.js is distributed in the hope that it will be useful, 6245 but WITHOUT ANY WARRANTY; without even the implied warranty of 6246 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6247 GNU Lesser General Public License for more details. 6248 6249 You should have received a copy of the GNU Lesser General Public License 6250 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6251 */ 6252 /** @file shh.js 6253 * @authors: 6254 * Fabian Vogelsteller <fabian@ethereum.org> 6255 * Marek Kotewicz <marek@ethcore.io> 6256 * @date 2017 6257 */ 6258 6259 var Method = require("../method"); 6260 var Filter = require("../filter"); 6261 var watches = require("./watches"); 6262 6263 var Shh = function (web3) { 6264 this._requestManager = web3._requestManager; 6265 6266 var self = this; 6267 6268 methods().forEach(function (method) { 6269 method.attachToObject(self); 6270 method.setRequestManager(self._requestManager); 6271 }); 6272 }; 6273 6274 Shh.prototype.newMessageFilter = function ( 6275 options, 6276 callback, 6277 filterCreationErrorCallback 6278 ) { 6279 return new Filter( 6280 options, 6281 "shh", 6282 this._requestManager, 6283 watches.shh(), 6284 null, 6285 callback, 6286 filterCreationErrorCallback 6287 ); 6288 }; 6289 6290 var methods = function () { 6291 return [ 6292 new Method({ 6293 name: "version", 6294 call: "shh_version", 6295 params: 0, 6296 }), 6297 new Method({ 6298 name: "info", 6299 call: "shh_info", 6300 params: 0, 6301 }), 6302 new Method({ 6303 name: "setMaxMessageSize", 6304 call: "shh_setMaxMessageSize", 6305 params: 1, 6306 }), 6307 new Method({ 6308 name: "setMinPoW", 6309 call: "shh_setMinPoW", 6310 params: 1, 6311 }), 6312 new Method({ 6313 name: "markTrustedPeer", 6314 call: "shh_markTrustedPeer", 6315 params: 1, 6316 }), 6317 new Method({ 6318 name: "newKeyPair", 6319 call: "shh_newKeyPair", 6320 params: 0, 6321 }), 6322 new Method({ 6323 name: "addPrivateKey", 6324 call: "shh_addPrivateKey", 6325 params: 1, 6326 }), 6327 new Method({ 6328 name: "deleteKeyPair", 6329 call: "shh_deleteKeyPair", 6330 params: 1, 6331 }), 6332 new Method({ 6333 name: "hasKeyPair", 6334 call: "shh_hasKeyPair", 6335 params: 1, 6336 }), 6337 new Method({ 6338 name: "getPublicKey", 6339 call: "shh_getPublicKey", 6340 params: 1, 6341 }), 6342 new Method({ 6343 name: "getPrivateKey", 6344 call: "shh_getPrivateKey", 6345 params: 1, 6346 }), 6347 new Method({ 6348 name: "newSymKey", 6349 call: "shh_newSymKey", 6350 params: 0, 6351 }), 6352 new Method({ 6353 name: "addSymKey", 6354 call: "shh_addSymKey", 6355 params: 1, 6356 }), 6357 new Method({ 6358 name: "generateSymKeyFromPassword", 6359 call: "shh_generateSymKeyFromPassword", 6360 params: 1, 6361 }), 6362 new Method({ 6363 name: "hasSymKey", 6364 call: "shh_hasSymKey", 6365 params: 1, 6366 }), 6367 new Method({ 6368 name: "getSymKey", 6369 call: "shh_getSymKey", 6370 params: 1, 6371 }), 6372 new Method({ 6373 name: "deleteSymKey", 6374 call: "shh_deleteSymKey", 6375 params: 1, 6376 }), 6377 6378 // subscribe and unsubscribe missing 6379 6380 new Method({ 6381 name: "post", 6382 call: "shh_post", 6383 params: 1, 6384 inputFormatter: [null], 6385 }), 6386 ]; 6387 }; 6388 6389 module.exports = Shh; 6390 }, 6391 { "../filter": 29, "../method": 36, "./watches": 43 }, 6392 ], 6393 42: [ 6394 function (require, module, exports) { 6395 /* 6396 This file is part of web3.js. 6397 6398 web3.js is free software: you can redistribute it and/or modify 6399 it under the terms of the GNU Lesser General Public License as published by 6400 the Free Software Foundation, either version 3 of the License, or 6401 (at your option) any later version. 6402 6403 web3.js is distributed in the hope that it will be useful, 6404 but WITHOUT ANY WARRANTY; without even the implied warranty of 6405 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6406 GNU Lesser General Public License for more details. 6407 6408 You should have received a copy of the GNU Lesser General Public License 6409 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6410 */ 6411 /** 6412 * @file bzz.js 6413 * @author Alex Beregszaszi <alex@rtfs.hu> 6414 * @date 2016 6415 * 6416 * Reference: https://github.com/alexdevranger/node-1.8.27/blob/swarm/internal/web3ext/web3ext.go#L33 6417 */ 6418 6419 "use strict"; 6420 6421 var Method = require("../method"); 6422 var Property = require("../property"); 6423 6424 function Swarm(web3) { 6425 this._requestManager = web3._requestManager; 6426 6427 var self = this; 6428 6429 methods().forEach(function (method) { 6430 method.attachToObject(self); 6431 method.setRequestManager(self._requestManager); 6432 }); 6433 6434 properties().forEach(function (p) { 6435 p.attachToObject(self); 6436 p.setRequestManager(self._requestManager); 6437 }); 6438 } 6439 6440 var methods = function () { 6441 var blockNetworkRead = new Method({ 6442 name: "blockNetworkRead", 6443 call: "bzz_blockNetworkRead", 6444 params: 1, 6445 inputFormatter: [null], 6446 }); 6447 6448 var syncEnabled = new Method({ 6449 name: "syncEnabled", 6450 call: "bzz_syncEnabled", 6451 params: 1, 6452 inputFormatter: [null], 6453 }); 6454 6455 var swapEnabled = new Method({ 6456 name: "swapEnabled", 6457 call: "bzz_swapEnabled", 6458 params: 1, 6459 inputFormatter: [null], 6460 }); 6461 6462 var download = new Method({ 6463 name: "download", 6464 call: "bzz_download", 6465 params: 2, 6466 inputFormatter: [null, null], 6467 }); 6468 6469 var upload = new Method({ 6470 name: "upload", 6471 call: "bzz_upload", 6472 params: 2, 6473 inputFormatter: [null, null], 6474 }); 6475 6476 var retrieve = new Method({ 6477 name: "retrieve", 6478 call: "bzz_retrieve", 6479 params: 1, 6480 inputFormatter: [null], 6481 }); 6482 6483 var store = new Method({ 6484 name: "store", 6485 call: "bzz_store", 6486 params: 2, 6487 inputFormatter: [null, null], 6488 }); 6489 6490 var get = new Method({ 6491 name: "get", 6492 call: "bzz_get", 6493 params: 1, 6494 inputFormatter: [null], 6495 }); 6496 6497 var put = new Method({ 6498 name: "put", 6499 call: "bzz_put", 6500 params: 2, 6501 inputFormatter: [null, null], 6502 }); 6503 6504 var modify = new Method({ 6505 name: "modify", 6506 call: "bzz_modify", 6507 params: 4, 6508 inputFormatter: [null, null, null, null], 6509 }); 6510 6511 return [ 6512 blockNetworkRead, 6513 syncEnabled, 6514 swapEnabled, 6515 download, 6516 upload, 6517 retrieve, 6518 store, 6519 get, 6520 put, 6521 modify, 6522 ]; 6523 }; 6524 6525 var properties = function () { 6526 return [ 6527 new Property({ 6528 name: "hive", 6529 getter: "bzz_hive", 6530 }), 6531 new Property({ 6532 name: "info", 6533 getter: "bzz_info", 6534 }), 6535 ]; 6536 }; 6537 6538 module.exports = Swarm; 6539 }, 6540 { "../method": 36, "../property": 45 }, 6541 ], 6542 43: [ 6543 function (require, module, exports) { 6544 /* 6545 This file is part of web3.js. 6546 6547 web3.js is free software: you can redistribute it and/or modify 6548 it under the terms of the GNU Lesser General Public License as published by 6549 the Free Software Foundation, either version 3 of the License, or 6550 (at your option) any later version. 6551 6552 web3.js is distributed in the hope that it will be useful, 6553 but WITHOUT ANY WARRANTY; without even the implied warranty of 6554 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6555 GNU Lesser General Public License for more details. 6556 6557 You should have received a copy of the GNU Lesser General Public License 6558 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6559 */ 6560 /** @file watches.js 6561 * @authors: 6562 * Marek Kotewicz <marek@ethdev.com> 6563 * @date 2015 6564 */ 6565 6566 var Method = require("../method"); 6567 6568 /// @returns an array of objects describing web3.eth.filter api methods 6569 var eth = function () { 6570 var newFilterCall = function (args) { 6571 var type = args[0]; 6572 6573 switch (type) { 6574 case "latest": 6575 args.shift(); 6576 this.params = 0; 6577 return "eth_newBlockFilter"; 6578 case "pending": 6579 args.shift(); 6580 this.params = 0; 6581 return "eth_newPendingTransactionFilter"; 6582 default: 6583 return "eth_newFilter"; 6584 } 6585 }; 6586 6587 var newFilter = new Method({ 6588 name: "newFilter", 6589 call: newFilterCall, 6590 params: 1, 6591 }); 6592 6593 var uninstallFilter = new Method({ 6594 name: "uninstallFilter", 6595 call: "eth_uninstallFilter", 6596 params: 1, 6597 }); 6598 6599 var getLogs = new Method({ 6600 name: "getLogs", 6601 call: "eth_getFilterLogs", 6602 params: 1, 6603 }); 6604 6605 var poll = new Method({ 6606 name: "poll", 6607 call: "eth_getFilterChanges", 6608 params: 1, 6609 }); 6610 6611 return [newFilter, uninstallFilter, getLogs, poll]; 6612 }; 6613 6614 /// @returns an array of objects describing web3.shh.watch api methods 6615 var shh = function () { 6616 return [ 6617 new Method({ 6618 name: "newFilter", 6619 call: "shh_newMessageFilter", 6620 params: 1, 6621 }), 6622 new Method({ 6623 name: "uninstallFilter", 6624 call: "shh_deleteMessageFilter", 6625 params: 1, 6626 }), 6627 new Method({ 6628 name: "getLogs", 6629 call: "shh_getFilterMessages", 6630 params: 1, 6631 }), 6632 new Method({ 6633 name: "poll", 6634 call: "shh_getFilterMessages", 6635 params: 1, 6636 }), 6637 ]; 6638 }; 6639 6640 module.exports = { 6641 eth: eth, 6642 shh: shh, 6643 }; 6644 }, 6645 { "../method": 36 }, 6646 ], 6647 44: [ 6648 function (require, module, exports) { 6649 /* 6650 This file is part of web3.js. 6651 6652 web3.js is free software: you can redistribute it and/or modify 6653 it under the terms of the GNU Lesser General Public License as published by 6654 the Free Software Foundation, either version 3 of the License, or 6655 (at your option) any later version. 6656 6657 web3.js is distributed in the hope that it will be useful, 6658 but WITHOUT ANY WARRANTY; without even the implied warranty of 6659 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6660 GNU Lesser General Public License for more details. 6661 6662 You should have received a copy of the GNU Lesser General Public License 6663 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6664 */ 6665 /** 6666 * @file namereg.js 6667 * @author Marek Kotewicz <marek@ethdev.com> 6668 * @date 2015 6669 */ 6670 6671 var globalRegistrarAbi = require("../contracts/GlobalRegistrar.json"); 6672 var icapRegistrarAbi = require("../contracts/ICAPRegistrar.json"); 6673 6674 var globalNameregAddress = "0xc6d9d2cd449a754c494264e1809c50e34d64562b"; 6675 var icapNameregAddress = "0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00"; 6676 6677 module.exports = { 6678 global: { 6679 abi: globalRegistrarAbi, 6680 address: globalNameregAddress, 6681 }, 6682 icap: { 6683 abi: icapRegistrarAbi, 6684 address: icapNameregAddress, 6685 }, 6686 }; 6687 }, 6688 { 6689 "../contracts/GlobalRegistrar.json": 1, 6690 "../contracts/ICAPRegistrar.json": 2, 6691 }, 6692 ], 6693 45: [ 6694 function (require, module, exports) { 6695 /* 6696 This file is part of web3.js. 6697 6698 web3.js is free software: you can redistribute it and/or modify 6699 it under the terms of the GNU Lesser General Public License as published by 6700 the Free Software Foundation, either version 3 of the License, or 6701 (at your option) any later version. 6702 6703 web3.js is distributed in the hope that it will be useful, 6704 but WITHOUT ANY WARRANTY; without even the implied warranty of 6705 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6706 GNU Lesser General Public License for more details. 6707 6708 You should have received a copy of the GNU Lesser General Public License 6709 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6710 */ 6711 /** 6712 * @file property.js 6713 * @author Fabian Vogelsteller <fabian@frozeman.de> 6714 * @author Marek Kotewicz <marek@ethdev.com> 6715 * @date 2015 6716 */ 6717 6718 var utils = require("../utils/utils"); 6719 6720 var Property = function (options) { 6721 this.name = options.name; 6722 this.getter = options.getter; 6723 this.setter = options.setter; 6724 this.outputFormatter = options.outputFormatter; 6725 this.inputFormatter = options.inputFormatter; 6726 this.requestManager = null; 6727 }; 6728 6729 Property.prototype.setRequestManager = function (rm) { 6730 this.requestManager = rm; 6731 }; 6732 6733 /** 6734 * Should be called to format input args of method 6735 * 6736 * @method formatInput 6737 * @param {Array} 6738 * @return {Array} 6739 */ 6740 Property.prototype.formatInput = function (arg) { 6741 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6742 }; 6743 6744 /** 6745 * Should be called to format output(result) of method 6746 * 6747 * @method formatOutput 6748 * @param {Object} 6749 * @return {Object} 6750 */ 6751 Property.prototype.formatOutput = function (result) { 6752 return this.outputFormatter && result !== null && result !== undefined 6753 ? this.outputFormatter(result) 6754 : result; 6755 }; 6756 6757 /** 6758 * Should be used to extract callback from array of arguments. Modifies input param 6759 * 6760 * @method extractCallback 6761 * @param {Array} arguments 6762 * @return {Function|Null} callback, if exists 6763 */ 6764 Property.prototype.extractCallback = function (args) { 6765 if (utils.isFunction(args[args.length - 1])) { 6766 return args.pop(); // modify the args array! 6767 } 6768 }; 6769 6770 /** 6771 * Should attach function to method 6772 * 6773 * @method attachToObject 6774 * @param {Object} 6775 * @param {Function} 6776 */ 6777 Property.prototype.attachToObject = function (obj) { 6778 var proto = { 6779 get: this.buildGet(), 6780 enumerable: true, 6781 }; 6782 6783 var names = this.name.split("."); 6784 var name = names[0]; 6785 if (names.length > 1) { 6786 obj[names[0]] = obj[names[0]] || {}; 6787 obj = obj[names[0]]; 6788 name = names[1]; 6789 } 6790 6791 Object.defineProperty(obj, name, proto); 6792 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6793 }; 6794 6795 var asyncGetterName = function (name) { 6796 return "get" + name.charAt(0).toUpperCase() + name.slice(1); 6797 }; 6798 6799 Property.prototype.buildGet = function () { 6800 var property = this; 6801 return function get() { 6802 return property.formatOutput( 6803 property.requestManager.send({ 6804 method: property.getter, 6805 }) 6806 ); 6807 }; 6808 }; 6809 6810 Property.prototype.buildAsyncGet = function () { 6811 var property = this; 6812 var get = function (callback) { 6813 property.requestManager.sendAsync( 6814 { 6815 method: property.getter, 6816 }, 6817 function (err, result) { 6818 callback(err, property.formatOutput(result)); 6819 } 6820 ); 6821 }; 6822 get.request = this.request.bind(this); 6823 return get; 6824 }; 6825 6826 /** 6827 * Should be called to create pure JSONRPC request which can be used in batch request 6828 * 6829 * @method request 6830 * @param {...} params 6831 * @return {Object} jsonrpc request 6832 */ 6833 Property.prototype.request = function () { 6834 var payload = { 6835 method: this.getter, 6836 params: [], 6837 callback: this.extractCallback( 6838 Array.prototype.slice.call(arguments) 6839 ), 6840 }; 6841 payload.format = this.formatOutput.bind(this); 6842 return payload; 6843 }; 6844 6845 module.exports = Property; 6846 }, 6847 { "../utils/utils": 20 }, 6848 ], 6849 46: [ 6850 function (require, module, exports) { 6851 /* 6852 This file is part of web3.js. 6853 6854 web3.js is free software: you can redistribute it and/or modify 6855 it under the terms of the GNU Lesser General Public License as published by 6856 the Free Software Foundation, either version 3 of the License, or 6857 (at your option) any later version. 6858 6859 web3.js is distributed in the hope that it will be useful, 6860 but WITHOUT ANY WARRANTY; without even the implied warranty of 6861 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6862 GNU Lesser General Public License for more details. 6863 6864 You should have received a copy of the GNU Lesser General Public License 6865 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6866 */ 6867 /** 6868 * @file requestmanager.js 6869 * @author Jeffrey Wilcke <jeff@ethdev.com> 6870 * @author Marek Kotewicz <marek@ethdev.com> 6871 * @author Marian Oancea <marian@ethdev.com> 6872 * @author Fabian Vogelsteller <fabian@ethdev.com> 6873 * @author Gav Wood <g@ethdev.com> 6874 * @date 2014 6875 */ 6876 6877 var Jsonrpc = require("./jsonrpc"); 6878 var utils = require("../utils/utils"); 6879 var c = require("../utils/config"); 6880 var errors = require("./errors"); 6881 6882 /** 6883 * It's responsible for passing messages to providers 6884 * It's also responsible for polling the ethereum node for incoming messages 6885 * Default poll timeout is 1 second 6886 * Singleton 6887 */ 6888 var RequestManager = function (provider) { 6889 this.provider = provider; 6890 this.polls = {}; 6891 this.timeout = null; 6892 }; 6893 6894 /** 6895 * Should be used to synchronously send request 6896 * 6897 * @method send 6898 * @param {Object} data 6899 * @return {Object} 6900 */ 6901 RequestManager.prototype.send = function (data) { 6902 if (!this.provider) { 6903 console.error(errors.InvalidProvider()); 6904 return null; 6905 } 6906 6907 var payload = Jsonrpc.toPayload(data.method, data.params); 6908 var result = this.provider.send(payload); 6909 6910 if (!Jsonrpc.isValidResponse(result)) { 6911 throw errors.InvalidResponse(result); 6912 } 6913 6914 return result.result; 6915 }; 6916 6917 /** 6918 * Should be used to asynchronously send request 6919 * 6920 * @method sendAsync 6921 * @param {Object} data 6922 * @param {Function} callback 6923 */ 6924 RequestManager.prototype.sendAsync = function (data, callback) { 6925 if (!this.provider) { 6926 return callback(errors.InvalidProvider()); 6927 } 6928 6929 var payload = Jsonrpc.toPayload(data.method, data.params); 6930 this.provider.sendAsync(payload, function (err, result) { 6931 if (err) { 6932 return callback(err); 6933 } 6934 6935 if (!Jsonrpc.isValidResponse(result)) { 6936 return callback(errors.InvalidResponse(result)); 6937 } 6938 6939 callback(null, result.result); 6940 }); 6941 }; 6942 6943 /** 6944 * Should be called to asynchronously send batch request 6945 * 6946 * @method sendBatch 6947 * @param {Array} batch data 6948 * @param {Function} callback 6949 */ 6950 RequestManager.prototype.sendBatch = function (data, callback) { 6951 if (!this.provider) { 6952 return callback(errors.InvalidProvider()); 6953 } 6954 6955 var payload = Jsonrpc.toBatchPayload(data); 6956 6957 this.provider.sendAsync(payload, function (err, results) { 6958 if (err) { 6959 return callback(err); 6960 } 6961 6962 if (!utils.isArray(results)) { 6963 return callback(errors.InvalidResponse(results)); 6964 } 6965 6966 callback(err, results); 6967 }); 6968 }; 6969 6970 /** 6971 * Should be used to set provider of request manager 6972 * 6973 * @method setProvider 6974 * @param {Object} 6975 */ 6976 RequestManager.prototype.setProvider = function (p) { 6977 this.provider = p; 6978 }; 6979 6980 /** 6981 * Should be used to start polling 6982 * 6983 * @method startPolling 6984 * @param {Object} data 6985 * @param {Number} pollId 6986 * @param {Function} callback 6987 * @param {Function} uninstall 6988 * 6989 * @todo cleanup number of params 6990 */ 6991 RequestManager.prototype.startPolling = function ( 6992 data, 6993 pollId, 6994 callback, 6995 uninstall 6996 ) { 6997 this.polls[pollId] = { 6998 data: data, 6999 id: pollId, 7000 callback: callback, 7001 uninstall: uninstall, 7002 }; 7003 7004 // start polling 7005 if (!this.timeout) { 7006 this.poll(); 7007 } 7008 }; 7009 7010 /** 7011 * Should be used to stop polling for filter with given id 7012 * 7013 * @method stopPolling 7014 * @param {Number} pollId 7015 */ 7016 RequestManager.prototype.stopPolling = function (pollId) { 7017 delete this.polls[pollId]; 7018 7019 // stop polling 7020 if (Object.keys(this.polls).length === 0 && this.timeout) { 7021 clearTimeout(this.timeout); 7022 this.timeout = null; 7023 } 7024 }; 7025 7026 /** 7027 * Should be called to reset the polling mechanism of the request manager 7028 * 7029 * @method reset 7030 */ 7031 RequestManager.prototype.reset = function (keepIsSyncing) { 7032 /*jshint maxcomplexity:5 */ 7033 7034 for (var key in this.polls) { 7035 // remove all polls, except sync polls, 7036 // they need to be removed manually by calling syncing.stopWatching() 7037 if (!keepIsSyncing || key.indexOf("syncPoll_") === -1) { 7038 this.polls[key].uninstall(); 7039 delete this.polls[key]; 7040 } 7041 } 7042 7043 // stop polling 7044 if (Object.keys(this.polls).length === 0 && this.timeout) { 7045 clearTimeout(this.timeout); 7046 this.timeout = null; 7047 } 7048 }; 7049 7050 /** 7051 * Should be called to poll for changes on filter with given id 7052 * 7053 * @method poll 7054 */ 7055 RequestManager.prototype.poll = function () { 7056 /*jshint maxcomplexity: 6 */ 7057 this.timeout = setTimeout( 7058 this.poll.bind(this), 7059 c.ETH_POLLING_TIMEOUT 7060 ); 7061 7062 if (Object.keys(this.polls).length === 0) { 7063 return; 7064 } 7065 7066 if (!this.provider) { 7067 console.error(errors.InvalidProvider()); 7068 return; 7069 } 7070 7071 var pollsData = []; 7072 var pollsIds = []; 7073 for (var key in this.polls) { 7074 pollsData.push(this.polls[key].data); 7075 pollsIds.push(key); 7076 } 7077 7078 if (pollsData.length === 0) { 7079 return; 7080 } 7081 7082 var payload = Jsonrpc.toBatchPayload(pollsData); 7083 7084 // map the request id to they poll id 7085 var pollsIdMap = {}; 7086 payload.forEach(function (load, index) { 7087 pollsIdMap[load.id] = pollsIds[index]; 7088 }); 7089 7090 var self = this; 7091 this.provider.sendAsync(payload, function (error, results) { 7092 // TODO: console log? 7093 if (error) { 7094 return; 7095 } 7096 7097 if (!utils.isArray(results)) { 7098 throw errors.InvalidResponse(results); 7099 } 7100 results 7101 .map(function (result) { 7102 var id = pollsIdMap[result.id]; 7103 7104 // make sure the filter is still installed after arrival of the request 7105 if (self.polls[id]) { 7106 result.callback = self.polls[id].callback; 7107 return result; 7108 } else return false; 7109 }) 7110 .filter(function (result) { 7111 return !!result; 7112 }) 7113 .filter(function (result) { 7114 var valid = Jsonrpc.isValidResponse(result); 7115 if (!valid) { 7116 result.callback(errors.InvalidResponse(result)); 7117 } 7118 return valid; 7119 }) 7120 .forEach(function (result) { 7121 result.callback(null, result.result); 7122 }); 7123 }); 7124 }; 7125 7126 module.exports = RequestManager; 7127 }, 7128 { 7129 "../utils/config": 18, 7130 "../utils/utils": 20, 7131 "./errors": 26, 7132 "./jsonrpc": 35, 7133 }, 7134 ], 7135 47: [ 7136 function (require, module, exports) { 7137 var Settings = function () { 7138 this.defaultBlock = "latest"; 7139 this.defaultAccount = undefined; 7140 }; 7141 7142 module.exports = Settings; 7143 }, 7144 {}, 7145 ], 7146 48: [ 7147 function (require, module, exports) { 7148 /* 7149 This file is part of web3.js. 7150 7151 web3.js is free software: you can redistribute it and/or modify 7152 it under the terms of the GNU Lesser General Public License as published by 7153 the Free Software Foundation, either version 3 of the License, or 7154 (at your option) any later version. 7155 7156 web3.js is distributed in the hope that it will be useful, 7157 but WITHOUT ANY WARRANTY; without even the implied warranty of 7158 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7159 GNU Lesser General Public License for more details. 7160 7161 You should have received a copy of the GNU Lesser General Public License 7162 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7163 */ 7164 /** @file syncing.js 7165 * @authors: 7166 * Fabian Vogelsteller <fabian@ethdev.com> 7167 * @date 2015 7168 */ 7169 7170 var formatters = require("./formatters"); 7171 var utils = require("../utils/utils"); 7172 7173 var count = 1; 7174 7175 /** 7176 Adds the callback and sets up the methods, to iterate over the results. 7177 7178 @method pollSyncing 7179 @param {Object} self 7180 */ 7181 var pollSyncing = function (self) { 7182 var onMessage = function (error, sync) { 7183 if (error) { 7184 return self.callbacks.forEach(function (callback) { 7185 callback(error); 7186 }); 7187 } 7188 7189 if (utils.isObject(sync) && sync.startingBlock) 7190 sync = formatters.outputSyncingFormatter(sync); 7191 7192 self.callbacks.forEach(function (callback) { 7193 if (self.lastSyncState !== sync) { 7194 // call the callback with true first so the app can stop anything, before receiving the sync data 7195 if (!self.lastSyncState && utils.isObject(sync)) 7196 callback(null, true); 7197 7198 // call on the next CPU cycle, so the actions of the sync stop can be processes first 7199 setTimeout(function () { 7200 callback(null, sync); 7201 }, 0); 7202 7203 self.lastSyncState = sync; 7204 } 7205 }); 7206 }; 7207 7208 self.requestManager.startPolling( 7209 { 7210 method: "eth_syncing", 7211 params: [], 7212 }, 7213 self.pollId, 7214 onMessage, 7215 self.stopWatching.bind(self) 7216 ); 7217 }; 7218 7219 var IsSyncing = function (requestManager, callback) { 7220 this.requestManager = requestManager; 7221 this.pollId = "syncPoll_" + count++; 7222 this.callbacks = []; 7223 this.addCallback(callback); 7224 this.lastSyncState = false; 7225 pollSyncing(this); 7226 7227 return this; 7228 }; 7229 7230 IsSyncing.prototype.addCallback = function (callback) { 7231 if (callback) this.callbacks.push(callback); 7232 return this; 7233 }; 7234 7235 IsSyncing.prototype.stopWatching = function () { 7236 this.requestManager.stopPolling(this.pollId); 7237 this.callbacks = []; 7238 }; 7239 7240 module.exports = IsSyncing; 7241 }, 7242 { "../utils/utils": 20, "./formatters": 30 }, 7243 ], 7244 49: [ 7245 function (require, module, exports) { 7246 /* 7247 This file is part of web3.js. 7248 7249 web3.js is free software: you can redistribute it and/or modify 7250 it under the terms of the GNU Lesser General Public License as published by 7251 the Free Software Foundation, either version 3 of the License, or 7252 (at your option) any later version. 7253 7254 web3.js is distributed in the hope that it will be useful, 7255 but WITHOUT ANY WARRANTY; without even the implied warranty of 7256 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7257 GNU Lesser General Public License for more details. 7258 7259 You should have received a copy of the GNU Lesser General Public License 7260 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7261 */ 7262 /** 7263 * @file transfer.js 7264 * @author Marek Kotewicz <marek@ethdev.com> 7265 * @date 2015 7266 */ 7267 7268 var Iban = require("./iban"); 7269 var exchangeAbi = require("../contracts/SmartExchange.json"); 7270 7271 /** 7272 * Should be used to make Iban transfer 7273 * 7274 * @method transfer 7275 * @param {String} from 7276 * @param {String} to iban 7277 * @param {Value} value to be tranfered 7278 * @param {Function} callback, callback 7279 */ 7280 var transfer = function (eth, from, to, value, callback) { 7281 var iban = new Iban(to); 7282 if (!iban.isValid()) { 7283 throw new Error("invalid iban address"); 7284 } 7285 7286 if (iban.isDirect()) { 7287 return transferToAddress( 7288 eth, 7289 from, 7290 iban.address(), 7291 value, 7292 callback 7293 ); 7294 } 7295 7296 if (!callback) { 7297 var address = eth.icapNamereg().addr(iban.institution()); 7298 return deposit(eth, from, address, value, iban.client()); 7299 } 7300 7301 eth.icapNamereg().addr(iban.institution(), function (err, address) { 7302 return deposit(eth, from, address, value, iban.client(), callback); 7303 }); 7304 }; 7305 7306 /** 7307 * Should be used to transfer funds to certain address 7308 * 7309 * @method transferToAddress 7310 * @param {String} from 7311 * @param {String} to 7312 * @param {Value} value to be tranfered 7313 * @param {Function} callback, callback 7314 */ 7315 var transferToAddress = function (eth, from, to, value, callback) { 7316 return eth.sendTransaction( 7317 { 7318 address: to, 7319 from: from, 7320 value: value, 7321 }, 7322 callback 7323 ); 7324 }; 7325 7326 /** 7327 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 7328 * 7329 * @method deposit 7330 * @param {String} from 7331 * @param {String} to 7332 * @param {Value} value to be transfered 7333 * @param {String} client unique identifier 7334 * @param {Function} callback, callback 7335 */ 7336 var deposit = function (eth, from, to, value, client, callback) { 7337 var abi = exchangeAbi; 7338 return eth.contract(abi).at(to).deposit( 7339 client, 7340 { 7341 from: from, 7342 value: value, 7343 }, 7344 callback 7345 ); 7346 }; 7347 7348 module.exports = transfer; 7349 }, 7350 { "../contracts/SmartExchange.json": 3, "./iban": 33 }, 7351 ], 7352 50: [function (require, module, exports) {}, {}], 7353 51: [ 7354 function (require, module, exports) { 7355 (function (root, factory, undef) { 7356 if (typeof exports === "object") { 7357 // CommonJS 7358 module.exports = exports = factory( 7359 require("./core"), 7360 require("./enc-base64"), 7361 require("./md5"), 7362 require("./evpkdf"), 7363 require("./cipher-core") 7364 ); 7365 } else if (typeof define === "function" && define.amd) { 7366 // AMD 7367 define([ 7368 "./core", 7369 "./enc-base64", 7370 "./md5", 7371 "./evpkdf", 7372 "./cipher-core", 7373 ], factory); 7374 } else { 7375 // Global (browser) 7376 factory(root.CryptoJS); 7377 } 7378 })(this, function (CryptoJS) { 7379 (function () { 7380 // Shortcuts 7381 var C = CryptoJS; 7382 var C_lib = C.lib; 7383 var BlockCipher = C_lib.BlockCipher; 7384 var C_algo = C.algo; 7385 7386 // Lookup tables 7387 var SBOX = []; 7388 var INV_SBOX = []; 7389 var SUB_MIX_0 = []; 7390 var SUB_MIX_1 = []; 7391 var SUB_MIX_2 = []; 7392 var SUB_MIX_3 = []; 7393 var INV_SUB_MIX_0 = []; 7394 var INV_SUB_MIX_1 = []; 7395 var INV_SUB_MIX_2 = []; 7396 var INV_SUB_MIX_3 = []; 7397 7398 // Compute lookup tables 7399 (function () { 7400 // Compute double table 7401 var d = []; 7402 for (var i = 0; i < 256; i++) { 7403 if (i < 128) { 7404 d[i] = i << 1; 7405 } else { 7406 d[i] = (i << 1) ^ 0x11b; 7407 } 7408 } 7409 7410 // Walk GF(2^8) 7411 var x = 0; 7412 var xi = 0; 7413 for (var i = 0; i < 256; i++) { 7414 // Compute sbox 7415 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 7416 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 7417 SBOX[x] = sx; 7418 INV_SBOX[sx] = x; 7419 7420 // Compute multiplication 7421 var x2 = d[x]; 7422 var x4 = d[x2]; 7423 var x8 = d[x4]; 7424 7425 // Compute sub bytes, mix columns tables 7426 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 7427 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 7428 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 7429 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 7430 SUB_MIX_3[x] = t; 7431 7432 // Compute inv sub bytes, inv mix columns tables 7433 var t = 7434 (x8 * 0x1010101) ^ 7435 (x4 * 0x10001) ^ 7436 (x2 * 0x101) ^ 7437 (x * 0x1010100); 7438 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 7439 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 7440 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 7441 INV_SUB_MIX_3[sx] = t; 7442 7443 // Compute next counter 7444 if (!x) { 7445 x = xi = 1; 7446 } else { 7447 x = x2 ^ d[d[d[x8 ^ x2]]]; 7448 xi ^= d[d[xi]]; 7449 } 7450 } 7451 })(); 7452 7453 // Precomputed Rcon lookup 7454 var RCON = [ 7455 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 7456 ]; 7457 7458 /** 7459 * AES block cipher algorithm. 7460 */ 7461 var AES = (C_algo.AES = BlockCipher.extend({ 7462 _doReset: function () { 7463 // Skip reset of nRounds has been set before and key did not change 7464 if (this._nRounds && this._keyPriorReset === this._key) { 7465 return; 7466 } 7467 7468 // Shortcuts 7469 var key = (this._keyPriorReset = this._key); 7470 var keyWords = key.words; 7471 var keySize = key.sigBytes / 4; 7472 7473 // Compute number of rounds 7474 var nRounds = (this._nRounds = keySize + 6); 7475 7476 // Compute number of key schedule rows 7477 var ksRows = (nRounds + 1) * 4; 7478 7479 // Compute key schedule 7480 var keySchedule = (this._keySchedule = []); 7481 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 7482 if (ksRow < keySize) { 7483 keySchedule[ksRow] = keyWords[ksRow]; 7484 } else { 7485 var t = keySchedule[ksRow - 1]; 7486 7487 if (!(ksRow % keySize)) { 7488 // Rot word 7489 t = (t << 8) | (t >>> 24); 7490 7491 // Sub word 7492 t = 7493 (SBOX[t >>> 24] << 24) | 7494 (SBOX[(t >>> 16) & 0xff] << 16) | 7495 (SBOX[(t >>> 8) & 0xff] << 8) | 7496 SBOX[t & 0xff]; 7497 7498 // Mix Rcon 7499 t ^= RCON[(ksRow / keySize) | 0] << 24; 7500 } else if (keySize > 6 && ksRow % keySize == 4) { 7501 // Sub word 7502 t = 7503 (SBOX[t >>> 24] << 24) | 7504 (SBOX[(t >>> 16) & 0xff] << 16) | 7505 (SBOX[(t >>> 8) & 0xff] << 8) | 7506 SBOX[t & 0xff]; 7507 } 7508 7509 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 7510 } 7511 } 7512 7513 // Compute inv key schedule 7514 var invKeySchedule = (this._invKeySchedule = []); 7515 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 7516 var ksRow = ksRows - invKsRow; 7517 7518 if (invKsRow % 4) { 7519 var t = keySchedule[ksRow]; 7520 } else { 7521 var t = keySchedule[ksRow - 4]; 7522 } 7523 7524 if (invKsRow < 4 || ksRow <= 4) { 7525 invKeySchedule[invKsRow] = t; 7526 } else { 7527 invKeySchedule[invKsRow] = 7528 INV_SUB_MIX_0[SBOX[t >>> 24]] ^ 7529 INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 7530 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ 7531 INV_SUB_MIX_3[SBOX[t & 0xff]]; 7532 } 7533 } 7534 }, 7535 7536 encryptBlock: function (M, offset) { 7537 this._doCryptBlock( 7538 M, 7539 offset, 7540 this._keySchedule, 7541 SUB_MIX_0, 7542 SUB_MIX_1, 7543 SUB_MIX_2, 7544 SUB_MIX_3, 7545 SBOX 7546 ); 7547 }, 7548 7549 decryptBlock: function (M, offset) { 7550 // Swap 2nd and 4th rows 7551 var t = M[offset + 1]; 7552 M[offset + 1] = M[offset + 3]; 7553 M[offset + 3] = t; 7554 7555 this._doCryptBlock( 7556 M, 7557 offset, 7558 this._invKeySchedule, 7559 INV_SUB_MIX_0, 7560 INV_SUB_MIX_1, 7561 INV_SUB_MIX_2, 7562 INV_SUB_MIX_3, 7563 INV_SBOX 7564 ); 7565 7566 // Inv swap 2nd and 4th rows 7567 var t = M[offset + 1]; 7568 M[offset + 1] = M[offset + 3]; 7569 M[offset + 3] = t; 7570 }, 7571 7572 _doCryptBlock: function ( 7573 M, 7574 offset, 7575 keySchedule, 7576 SUB_MIX_0, 7577 SUB_MIX_1, 7578 SUB_MIX_2, 7579 SUB_MIX_3, 7580 SBOX 7581 ) { 7582 // Shortcut 7583 var nRounds = this._nRounds; 7584 7585 // Get input, add round key 7586 var s0 = M[offset] ^ keySchedule[0]; 7587 var s1 = M[offset + 1] ^ keySchedule[1]; 7588 var s2 = M[offset + 2] ^ keySchedule[2]; 7589 var s3 = M[offset + 3] ^ keySchedule[3]; 7590 7591 // Key schedule row counter 7592 var ksRow = 4; 7593 7594 // Rounds 7595 for (var round = 1; round < nRounds; round++) { 7596 // Shift rows, sub bytes, mix columns, add round key 7597 var t0 = 7598 SUB_MIX_0[s0 >>> 24] ^ 7599 SUB_MIX_1[(s1 >>> 16) & 0xff] ^ 7600 SUB_MIX_2[(s2 >>> 8) & 0xff] ^ 7601 SUB_MIX_3[s3 & 0xff] ^ 7602 keySchedule[ksRow++]; 7603 var t1 = 7604 SUB_MIX_0[s1 >>> 24] ^ 7605 SUB_MIX_1[(s2 >>> 16) & 0xff] ^ 7606 SUB_MIX_2[(s3 >>> 8) & 0xff] ^ 7607 SUB_MIX_3[s0 & 0xff] ^ 7608 keySchedule[ksRow++]; 7609 var t2 = 7610 SUB_MIX_0[s2 >>> 24] ^ 7611 SUB_MIX_1[(s3 >>> 16) & 0xff] ^ 7612 SUB_MIX_2[(s0 >>> 8) & 0xff] ^ 7613 SUB_MIX_3[s1 & 0xff] ^ 7614 keySchedule[ksRow++]; 7615 var t3 = 7616 SUB_MIX_0[s3 >>> 24] ^ 7617 SUB_MIX_1[(s0 >>> 16) & 0xff] ^ 7618 SUB_MIX_2[(s1 >>> 8) & 0xff] ^ 7619 SUB_MIX_3[s2 & 0xff] ^ 7620 keySchedule[ksRow++]; 7621 7622 // Update state 7623 s0 = t0; 7624 s1 = t1; 7625 s2 = t2; 7626 s3 = t3; 7627 } 7628 7629 // Shift rows, sub bytes, add round key 7630 var t0 = 7631 ((SBOX[s0 >>> 24] << 24) | 7632 (SBOX[(s1 >>> 16) & 0xff] << 16) | 7633 (SBOX[(s2 >>> 8) & 0xff] << 8) | 7634 SBOX[s3 & 0xff]) ^ 7635 keySchedule[ksRow++]; 7636 var t1 = 7637 ((SBOX[s1 >>> 24] << 24) | 7638 (SBOX[(s2 >>> 16) & 0xff] << 16) | 7639 (SBOX[(s3 >>> 8) & 0xff] << 8) | 7640 SBOX[s0 & 0xff]) ^ 7641 keySchedule[ksRow++]; 7642 var t2 = 7643 ((SBOX[s2 >>> 24] << 24) | 7644 (SBOX[(s3 >>> 16) & 0xff] << 16) | 7645 (SBOX[(s0 >>> 8) & 0xff] << 8) | 7646 SBOX[s1 & 0xff]) ^ 7647 keySchedule[ksRow++]; 7648 var t3 = 7649 ((SBOX[s3 >>> 24] << 24) | 7650 (SBOX[(s0 >>> 16) & 0xff] << 16) | 7651 (SBOX[(s1 >>> 8) & 0xff] << 8) | 7652 SBOX[s2 & 0xff]) ^ 7653 keySchedule[ksRow++]; 7654 7655 // Set output 7656 M[offset] = t0; 7657 M[offset + 1] = t1; 7658 M[offset + 2] = t2; 7659 M[offset + 3] = t3; 7660 }, 7661 7662 keySize: 256 / 32, 7663 })); 7664 7665 /** 7666 * Shortcut functions to the cipher's object interface. 7667 * 7668 * @example 7669 * 7670 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7671 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7672 */ 7673 C.AES = BlockCipher._createHelper(AES); 7674 })(); 7675 7676 return CryptoJS.AES; 7677 }); 7678 }, 7679 { 7680 "./cipher-core": 52, 7681 "./core": 53, 7682 "./enc-base64": 54, 7683 "./evpkdf": 56, 7684 "./md5": 61, 7685 }, 7686 ], 7687 52: [ 7688 function (require, module, exports) { 7689 (function (root, factory) { 7690 if (typeof exports === "object") { 7691 // CommonJS 7692 module.exports = exports = factory(require("./core")); 7693 } else if (typeof define === "function" && define.amd) { 7694 // AMD 7695 define(["./core"], factory); 7696 } else { 7697 // Global (browser) 7698 factory(root.CryptoJS); 7699 } 7700 })(this, function (CryptoJS) { 7701 /** 7702 * Cipher core components. 7703 */ 7704 CryptoJS.lib.Cipher || 7705 (function (undefined) { 7706 // Shortcuts 7707 var C = CryptoJS; 7708 var C_lib = C.lib; 7709 var Base = C_lib.Base; 7710 var WordArray = C_lib.WordArray; 7711 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7712 var C_enc = C.enc; 7713 var Utf8 = C_enc.Utf8; 7714 var Base64 = C_enc.Base64; 7715 var C_algo = C.algo; 7716 var EvpKDF = C_algo.EvpKDF; 7717 7718 /** 7719 * Abstract base cipher template. 7720 * 7721 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7722 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7723 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7724 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7725 */ 7726 var Cipher = (C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7727 /** 7728 * Configuration options. 7729 * 7730 * @property {WordArray} iv The IV to use for this operation. 7731 */ 7732 cfg: Base.extend(), 7733 7734 /** 7735 * Creates this cipher in encryption mode. 7736 * 7737 * @param {WordArray} key The key. 7738 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7739 * 7740 * @return {Cipher} A cipher instance. 7741 * 7742 * @static 7743 * 7744 * @example 7745 * 7746 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7747 */ 7748 createEncryptor: function (key, cfg) { 7749 return this.create(this._ENC_XFORM_MODE, key, cfg); 7750 }, 7751 7752 /** 7753 * Creates this cipher in decryption mode. 7754 * 7755 * @param {WordArray} key The key. 7756 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7757 * 7758 * @return {Cipher} A cipher instance. 7759 * 7760 * @static 7761 * 7762 * @example 7763 * 7764 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7765 */ 7766 createDecryptor: function (key, cfg) { 7767 return this.create(this._DEC_XFORM_MODE, key, cfg); 7768 }, 7769 7770 /** 7771 * Initializes a newly created cipher. 7772 * 7773 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7774 * @param {WordArray} key The key. 7775 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7776 * 7777 * @example 7778 * 7779 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7780 */ 7781 init: function (xformMode, key, cfg) { 7782 // Apply config defaults 7783 this.cfg = this.cfg.extend(cfg); 7784 7785 // Store transform mode and key 7786 this._xformMode = xformMode; 7787 this._key = key; 7788 7789 // Set initial values 7790 this.reset(); 7791 }, 7792 7793 /** 7794 * Resets this cipher to its initial state. 7795 * 7796 * @example 7797 * 7798 * cipher.reset(); 7799 */ 7800 reset: function () { 7801 // Reset data buffer 7802 BufferedBlockAlgorithm.reset.call(this); 7803 7804 // Perform concrete-cipher logic 7805 this._doReset(); 7806 }, 7807 7808 /** 7809 * Adds data to be encrypted or decrypted. 7810 * 7811 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7812 * 7813 * @return {WordArray} The data after processing. 7814 * 7815 * @example 7816 * 7817 * var encrypted = cipher.process('data'); 7818 * var encrypted = cipher.process(wordArray); 7819 */ 7820 process: function (dataUpdate) { 7821 // Append 7822 this._append(dataUpdate); 7823 7824 // Process available blocks 7825 return this._process(); 7826 }, 7827 7828 /** 7829 * Finalizes the encryption or decryption process. 7830 * Note that the finalize operation is effectively a destructive, read-once operation. 7831 * 7832 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7833 * 7834 * @return {WordArray} The data after final processing. 7835 * 7836 * @example 7837 * 7838 * var encrypted = cipher.finalize(); 7839 * var encrypted = cipher.finalize('data'); 7840 * var encrypted = cipher.finalize(wordArray); 7841 */ 7842 finalize: function (dataUpdate) { 7843 // Final data update 7844 if (dataUpdate) { 7845 this._append(dataUpdate); 7846 } 7847 7848 // Perform concrete-cipher logic 7849 var finalProcessedData = this._doFinalize(); 7850 7851 return finalProcessedData; 7852 }, 7853 7854 keySize: 128 / 32, 7855 7856 ivSize: 128 / 32, 7857 7858 _ENC_XFORM_MODE: 1, 7859 7860 _DEC_XFORM_MODE: 2, 7861 7862 /** 7863 * Creates shortcut functions to a cipher's object interface. 7864 * 7865 * @param {Cipher} cipher The cipher to create a helper for. 7866 * 7867 * @return {Object} An object with encrypt and decrypt shortcut functions. 7868 * 7869 * @static 7870 * 7871 * @example 7872 * 7873 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7874 */ 7875 _createHelper: (function () { 7876 function selectCipherStrategy(key) { 7877 if (typeof key == "string") { 7878 return PasswordBasedCipher; 7879 } else { 7880 return SerializableCipher; 7881 } 7882 } 7883 7884 return function (cipher) { 7885 return { 7886 encrypt: function (message, key, cfg) { 7887 return selectCipherStrategy(key).encrypt( 7888 cipher, 7889 message, 7890 key, 7891 cfg 7892 ); 7893 }, 7894 7895 decrypt: function (ciphertext, key, cfg) { 7896 return selectCipherStrategy(key).decrypt( 7897 cipher, 7898 ciphertext, 7899 key, 7900 cfg 7901 ); 7902 }, 7903 }; 7904 }; 7905 })(), 7906 })); 7907 7908 /** 7909 * Abstract base stream cipher template. 7910 * 7911 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7912 */ 7913 var StreamCipher = (C_lib.StreamCipher = Cipher.extend({ 7914 _doFinalize: function () { 7915 // Process partial blocks 7916 var finalProcessedBlocks = this._process(!!"flush"); 7917 7918 return finalProcessedBlocks; 7919 }, 7920 7921 blockSize: 1, 7922 })); 7923 7924 /** 7925 * Mode namespace. 7926 */ 7927 var C_mode = (C.mode = {}); 7928 7929 /** 7930 * Abstract base block cipher mode template. 7931 */ 7932 var BlockCipherMode = (C_lib.BlockCipherMode = Base.extend({ 7933 /** 7934 * Creates this mode for encryption. 7935 * 7936 * @param {Cipher} cipher A block cipher instance. 7937 * @param {Array} iv The IV words. 7938 * 7939 * @static 7940 * 7941 * @example 7942 * 7943 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7944 */ 7945 createEncryptor: function (cipher, iv) { 7946 return this.Encryptor.create(cipher, iv); 7947 }, 7948 7949 /** 7950 * Creates this mode for decryption. 7951 * 7952 * @param {Cipher} cipher A block cipher instance. 7953 * @param {Array} iv The IV words. 7954 * 7955 * @static 7956 * 7957 * @example 7958 * 7959 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7960 */ 7961 createDecryptor: function (cipher, iv) { 7962 return this.Decryptor.create(cipher, iv); 7963 }, 7964 7965 /** 7966 * Initializes a newly created mode. 7967 * 7968 * @param {Cipher} cipher A block cipher instance. 7969 * @param {Array} iv The IV words. 7970 * 7971 * @example 7972 * 7973 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7974 */ 7975 init: function (cipher, iv) { 7976 this._cipher = cipher; 7977 this._iv = iv; 7978 }, 7979 })); 7980 7981 /** 7982 * Cipher Block Chaining mode. 7983 */ 7984 var CBC = (C_mode.CBC = (function () { 7985 /** 7986 * Abstract base CBC mode. 7987 */ 7988 var CBC = BlockCipherMode.extend(); 7989 7990 /** 7991 * CBC encryptor. 7992 */ 7993 CBC.Encryptor = CBC.extend({ 7994 /** 7995 * Processes the data block at offset. 7996 * 7997 * @param {Array} words The data words to operate on. 7998 * @param {number} offset The offset where the block starts. 7999 * 8000 * @example 8001 * 8002 * mode.processBlock(data.words, offset); 8003 */ 8004 processBlock: function (words, offset) { 8005 // Shortcuts 8006 var cipher = this._cipher; 8007 var blockSize = cipher.blockSize; 8008 8009 // XOR and encrypt 8010 xorBlock.call(this, words, offset, blockSize); 8011 cipher.encryptBlock(words, offset); 8012 8013 // Remember this block to use with next block 8014 this._prevBlock = words.slice(offset, offset + blockSize); 8015 }, 8016 }); 8017 8018 /** 8019 * CBC decryptor. 8020 */ 8021 CBC.Decryptor = CBC.extend({ 8022 /** 8023 * Processes the data block at offset. 8024 * 8025 * @param {Array} words The data words to operate on. 8026 * @param {number} offset The offset where the block starts. 8027 * 8028 * @example 8029 * 8030 * mode.processBlock(data.words, offset); 8031 */ 8032 processBlock: function (words, offset) { 8033 // Shortcuts 8034 var cipher = this._cipher; 8035 var blockSize = cipher.blockSize; 8036 8037 // Remember this block to use with next block 8038 var thisBlock = words.slice(offset, offset + blockSize); 8039 8040 // Decrypt and XOR 8041 cipher.decryptBlock(words, offset); 8042 xorBlock.call(this, words, offset, blockSize); 8043 8044 // This block becomes the previous block 8045 this._prevBlock = thisBlock; 8046 }, 8047 }); 8048 8049 function xorBlock(words, offset, blockSize) { 8050 // Shortcut 8051 var iv = this._iv; 8052 8053 // Choose mixing block 8054 if (iv) { 8055 var block = iv; 8056 8057 // Remove IV for subsequent blocks 8058 this._iv = undefined; 8059 } else { 8060 var block = this._prevBlock; 8061 } 8062 8063 // XOR blocks 8064 for (var i = 0; i < blockSize; i++) { 8065 words[offset + i] ^= block[i]; 8066 } 8067 } 8068 8069 return CBC; 8070 })()); 8071 8072 /** 8073 * Padding namespace. 8074 */ 8075 var C_pad = (C.pad = {}); 8076 8077 /** 8078 * PKCS #5/7 padding strategy. 8079 */ 8080 var Pkcs7 = (C_pad.Pkcs7 = { 8081 /** 8082 * Pads data using the algorithm defined in PKCS #5/7. 8083 * 8084 * @param {WordArray} data The data to pad. 8085 * @param {number} blockSize The multiple that the data should be padded to. 8086 * 8087 * @static 8088 * 8089 * @example 8090 * 8091 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 8092 */ 8093 pad: function (data, blockSize) { 8094 // Shortcut 8095 var blockSizeBytes = blockSize * 4; 8096 8097 // Count padding bytes 8098 var nPaddingBytes = 8099 blockSizeBytes - (data.sigBytes % blockSizeBytes); 8100 8101 // Create padding word 8102 var paddingWord = 8103 (nPaddingBytes << 24) | 8104 (nPaddingBytes << 16) | 8105 (nPaddingBytes << 8) | 8106 nPaddingBytes; 8107 8108 // Create padding 8109 var paddingWords = []; 8110 for (var i = 0; i < nPaddingBytes; i += 4) { 8111 paddingWords.push(paddingWord); 8112 } 8113 var padding = WordArray.create(paddingWords, nPaddingBytes); 8114 8115 // Add padding 8116 data.concat(padding); 8117 }, 8118 8119 /** 8120 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 8121 * 8122 * @param {WordArray} data The data to unpad. 8123 * 8124 * @static 8125 * 8126 * @example 8127 * 8128 * CryptoJS.pad.Pkcs7.unpad(wordArray); 8129 */ 8130 unpad: function (data) { 8131 // Get number of padding bytes from last byte 8132 var nPaddingBytes = 8133 data.words[(data.sigBytes - 1) >>> 2] & 0xff; 8134 8135 // Remove padding 8136 data.sigBytes -= nPaddingBytes; 8137 }, 8138 }); 8139 8140 /** 8141 * Abstract base block cipher template. 8142 * 8143 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 8144 */ 8145 var BlockCipher = (C_lib.BlockCipher = Cipher.extend({ 8146 /** 8147 * Configuration options. 8148 * 8149 * @property {Mode} mode The block mode to use. Default: CBC 8150 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 8151 */ 8152 cfg: Cipher.cfg.extend({ 8153 mode: CBC, 8154 padding: Pkcs7, 8155 }), 8156 8157 reset: function () { 8158 // Reset cipher 8159 Cipher.reset.call(this); 8160 8161 // Shortcuts 8162 var cfg = this.cfg; 8163 var iv = cfg.iv; 8164 var mode = cfg.mode; 8165 8166 // Reset block mode 8167 if (this._xformMode == this._ENC_XFORM_MODE) { 8168 var modeCreator = mode.createEncryptor; 8169 } /* if (this._xformMode == this._DEC_XFORM_MODE) */ else { 8170 var modeCreator = mode.createDecryptor; 8171 8172 // Keep at least one block in the buffer for unpadding 8173 this._minBufferSize = 1; 8174 } 8175 this._mode = modeCreator.call(mode, this, iv && iv.words); 8176 }, 8177 8178 _doProcessBlock: function (words, offset) { 8179 this._mode.processBlock(words, offset); 8180 }, 8181 8182 _doFinalize: function () { 8183 // Shortcut 8184 var padding = this.cfg.padding; 8185 8186 // Finalize 8187 if (this._xformMode == this._ENC_XFORM_MODE) { 8188 // Pad data 8189 padding.pad(this._data, this.blockSize); 8190 8191 // Process final blocks 8192 var finalProcessedBlocks = this._process(!!"flush"); 8193 } /* if (this._xformMode == this._DEC_XFORM_MODE) */ else { 8194 // Process final blocks 8195 var finalProcessedBlocks = this._process(!!"flush"); 8196 8197 // Unpad data 8198 padding.unpad(finalProcessedBlocks); 8199 } 8200 8201 return finalProcessedBlocks; 8202 }, 8203 8204 blockSize: 128 / 32, 8205 })); 8206 8207 /** 8208 * A collection of cipher parameters. 8209 * 8210 * @property {WordArray} ciphertext The raw ciphertext. 8211 * @property {WordArray} key The key to this ciphertext. 8212 * @property {WordArray} iv The IV used in the ciphering operation. 8213 * @property {WordArray} salt The salt used with a key derivation function. 8214 * @property {Cipher} algorithm The cipher algorithm. 8215 * @property {Mode} mode The block mode used in the ciphering operation. 8216 * @property {Padding} padding The padding scheme used in the ciphering operation. 8217 * @property {number} blockSize The block size of the cipher. 8218 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 8219 */ 8220 var CipherParams = (C_lib.CipherParams = Base.extend({ 8221 /** 8222 * Initializes a newly created cipher params object. 8223 * 8224 * @param {Object} cipherParams An object with any of the possible cipher parameters. 8225 * 8226 * @example 8227 * 8228 * var cipherParams = CryptoJS.lib.CipherParams.create({ 8229 * ciphertext: ciphertextWordArray, 8230 * key: keyWordArray, 8231 * iv: ivWordArray, 8232 * salt: saltWordArray, 8233 * algorithm: CryptoJS.algo.AES, 8234 * mode: CryptoJS.mode.CBC, 8235 * padding: CryptoJS.pad.PKCS7, 8236 * blockSize: 4, 8237 * formatter: CryptoJS.format.OpenSSL 8238 * }); 8239 */ 8240 init: function (cipherParams) { 8241 this.mixIn(cipherParams); 8242 }, 8243 8244 /** 8245 * Converts this cipher params object to a string. 8246 * 8247 * @param {Format} formatter (Optional) The formatting strategy to use. 8248 * 8249 * @return {string} The stringified cipher params. 8250 * 8251 * @throws Error If neither the formatter nor the default formatter is set. 8252 * 8253 * @example 8254 * 8255 * var string = cipherParams + ''; 8256 * var string = cipherParams.toString(); 8257 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 8258 */ 8259 toString: function (formatter) { 8260 return (formatter || this.formatter).stringify(this); 8261 }, 8262 })); 8263 8264 /** 8265 * Format namespace. 8266 */ 8267 var C_format = (C.format = {}); 8268 8269 /** 8270 * OpenSSL formatting strategy. 8271 */ 8272 var OpenSSLFormatter = (C_format.OpenSSL = { 8273 /** 8274 * Converts a cipher params object to an OpenSSL-compatible string. 8275 * 8276 * @param {CipherParams} cipherParams The cipher params object. 8277 * 8278 * @return {string} The OpenSSL-compatible string. 8279 * 8280 * @static 8281 * 8282 * @example 8283 * 8284 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 8285 */ 8286 stringify: function (cipherParams) { 8287 // Shortcuts 8288 var ciphertext = cipherParams.ciphertext; 8289 var salt = cipherParams.salt; 8290 8291 // Format 8292 if (salt) { 8293 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]) 8294 .concat(salt) 8295 .concat(ciphertext); 8296 } else { 8297 var wordArray = ciphertext; 8298 } 8299 8300 return wordArray.toString(Base64); 8301 }, 8302 8303 /** 8304 * Converts an OpenSSL-compatible string to a cipher params object. 8305 * 8306 * @param {string} openSSLStr The OpenSSL-compatible string. 8307 * 8308 * @return {CipherParams} The cipher params object. 8309 * 8310 * @static 8311 * 8312 * @example 8313 * 8314 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 8315 */ 8316 parse: function (openSSLStr) { 8317 // Parse base64 8318 var ciphertext = Base64.parse(openSSLStr); 8319 8320 // Shortcut 8321 var ciphertextWords = ciphertext.words; 8322 8323 // Test for salt 8324 if ( 8325 ciphertextWords[0] == 0x53616c74 && 8326 ciphertextWords[1] == 0x65645f5f 8327 ) { 8328 // Extract salt 8329 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 8330 8331 // Remove salt from ciphertext 8332 ciphertextWords.splice(0, 4); 8333 ciphertext.sigBytes -= 16; 8334 } 8335 8336 return CipherParams.create({ 8337 ciphertext: ciphertext, 8338 salt: salt, 8339 }); 8340 }, 8341 }); 8342 8343 /** 8344 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 8345 */ 8346 var SerializableCipher = (C_lib.SerializableCipher = Base.extend({ 8347 /** 8348 * Configuration options. 8349 * 8350 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 8351 */ 8352 cfg: Base.extend({ 8353 format: OpenSSLFormatter, 8354 }), 8355 8356 /** 8357 * Encrypts a message. 8358 * 8359 * @param {Cipher} cipher The cipher algorithm to use. 8360 * @param {WordArray|string} message The message to encrypt. 8361 * @param {WordArray} key The key. 8362 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8363 * 8364 * @return {CipherParams} A cipher params object. 8365 * 8366 * @static 8367 * 8368 * @example 8369 * 8370 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 8371 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 8372 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8373 */ 8374 encrypt: function (cipher, message, key, cfg) { 8375 // Apply config defaults 8376 cfg = this.cfg.extend(cfg); 8377 8378 // Encrypt 8379 var encryptor = cipher.createEncryptor(key, cfg); 8380 var ciphertext = encryptor.finalize(message); 8381 8382 // Shortcut 8383 var cipherCfg = encryptor.cfg; 8384 8385 // Create and return serializable cipher params 8386 return CipherParams.create({ 8387 ciphertext: ciphertext, 8388 key: key, 8389 iv: cipherCfg.iv, 8390 algorithm: cipher, 8391 mode: cipherCfg.mode, 8392 padding: cipherCfg.padding, 8393 blockSize: cipher.blockSize, 8394 formatter: cfg.format, 8395 }); 8396 }, 8397 8398 /** 8399 * Decrypts serialized ciphertext. 8400 * 8401 * @param {Cipher} cipher The cipher algorithm to use. 8402 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8403 * @param {WordArray} key The key. 8404 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8405 * 8406 * @return {WordArray} The plaintext. 8407 * 8408 * @static 8409 * 8410 * @example 8411 * 8412 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8413 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8414 */ 8415 decrypt: function (cipher, ciphertext, key, cfg) { 8416 // Apply config defaults 8417 cfg = this.cfg.extend(cfg); 8418 8419 // Convert string to CipherParams 8420 ciphertext = this._parse(ciphertext, cfg.format); 8421 8422 // Decrypt 8423 var plaintext = cipher 8424 .createDecryptor(key, cfg) 8425 .finalize(ciphertext.ciphertext); 8426 8427 return plaintext; 8428 }, 8429 8430 /** 8431 * Converts serialized ciphertext to CipherParams, 8432 * else assumed CipherParams already and returns ciphertext unchanged. 8433 * 8434 * @param {CipherParams|string} ciphertext The ciphertext. 8435 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 8436 * 8437 * @return {CipherParams} The unserialized ciphertext. 8438 * 8439 * @static 8440 * 8441 * @example 8442 * 8443 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 8444 */ 8445 _parse: function (ciphertext, format) { 8446 if (typeof ciphertext == "string") { 8447 return format.parse(ciphertext, this); 8448 } else { 8449 return ciphertext; 8450 } 8451 }, 8452 })); 8453 8454 /** 8455 * Key derivation function namespace. 8456 */ 8457 var C_kdf = (C.kdf = {}); 8458 8459 /** 8460 * OpenSSL key derivation function. 8461 */ 8462 var OpenSSLKdf = (C_kdf.OpenSSL = { 8463 /** 8464 * Derives a key and IV from a password. 8465 * 8466 * @param {string} password The password to derive from. 8467 * @param {number} keySize The size in words of the key to generate. 8468 * @param {number} ivSize The size in words of the IV to generate. 8469 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 8470 * 8471 * @return {CipherParams} A cipher params object with the key, IV, and salt. 8472 * 8473 * @static 8474 * 8475 * @example 8476 * 8477 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 8478 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 8479 */ 8480 execute: function (password, keySize, ivSize, salt) { 8481 // Generate random salt 8482 if (!salt) { 8483 salt = WordArray.random(64 / 8); 8484 } 8485 8486 // Derive key and IV 8487 var key = EvpKDF.create({ 8488 keySize: keySize + ivSize, 8489 }).compute(password, salt); 8490 8491 // Separate key and IV 8492 var iv = WordArray.create( 8493 key.words.slice(keySize), 8494 ivSize * 4 8495 ); 8496 key.sigBytes = keySize * 4; 8497 8498 // Return params 8499 return CipherParams.create({ key: key, iv: iv, salt: salt }); 8500 }, 8501 }); 8502 8503 /** 8504 * A serializable cipher wrapper that derives the key from a password, 8505 * and returns ciphertext as a serializable cipher params object. 8506 */ 8507 var PasswordBasedCipher = (C_lib.PasswordBasedCipher = 8508 SerializableCipher.extend({ 8509 /** 8510 * Configuration options. 8511 * 8512 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 8513 */ 8514 cfg: SerializableCipher.cfg.extend({ 8515 kdf: OpenSSLKdf, 8516 }), 8517 8518 /** 8519 * Encrypts a message using a password. 8520 * 8521 * @param {Cipher} cipher The cipher algorithm to use. 8522 * @param {WordArray|string} message The message to encrypt. 8523 * @param {string} password The password. 8524 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8525 * 8526 * @return {CipherParams} A cipher params object. 8527 * 8528 * @static 8529 * 8530 * @example 8531 * 8532 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 8533 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 8534 */ 8535 encrypt: function (cipher, message, password, cfg) { 8536 // Apply config defaults 8537 cfg = this.cfg.extend(cfg); 8538 8539 // Derive key and other params 8540 var derivedParams = cfg.kdf.execute( 8541 password, 8542 cipher.keySize, 8543 cipher.ivSize 8544 ); 8545 8546 // Add IV to config 8547 cfg.iv = derivedParams.iv; 8548 8549 // Encrypt 8550 var ciphertext = SerializableCipher.encrypt.call( 8551 this, 8552 cipher, 8553 message, 8554 derivedParams.key, 8555 cfg 8556 ); 8557 8558 // Mix in derived params 8559 ciphertext.mixIn(derivedParams); 8560 8561 return ciphertext; 8562 }, 8563 8564 /** 8565 * Decrypts serialized ciphertext using a password. 8566 * 8567 * @param {Cipher} cipher The cipher algorithm to use. 8568 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8569 * @param {string} password The password. 8570 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8571 * 8572 * @return {WordArray} The plaintext. 8573 * 8574 * @static 8575 * 8576 * @example 8577 * 8578 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 8579 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 8580 */ 8581 decrypt: function (cipher, ciphertext, password, cfg) { 8582 // Apply config defaults 8583 cfg = this.cfg.extend(cfg); 8584 8585 // Convert string to CipherParams 8586 ciphertext = this._parse(ciphertext, cfg.format); 8587 8588 // Derive key and other params 8589 var derivedParams = cfg.kdf.execute( 8590 password, 8591 cipher.keySize, 8592 cipher.ivSize, 8593 ciphertext.salt 8594 ); 8595 8596 // Add IV to config 8597 cfg.iv = derivedParams.iv; 8598 8599 // Decrypt 8600 var plaintext = SerializableCipher.decrypt.call( 8601 this, 8602 cipher, 8603 ciphertext, 8604 derivedParams.key, 8605 cfg 8606 ); 8607 8608 return plaintext; 8609 }, 8610 })); 8611 })(); 8612 }); 8613 }, 8614 { "./core": 53 }, 8615 ], 8616 53: [ 8617 function (require, module, exports) { 8618 (function (root, factory) { 8619 if (typeof exports === "object") { 8620 // CommonJS 8621 module.exports = exports = factory(); 8622 } else if (typeof define === "function" && define.amd) { 8623 // AMD 8624 define([], factory); 8625 } else { 8626 // Global (browser) 8627 root.CryptoJS = factory(); 8628 } 8629 })(this, function () { 8630 /** 8631 * CryptoJS core components. 8632 */ 8633 var CryptoJS = 8634 CryptoJS || 8635 (function (Math, undefined) { 8636 /* 8637 * Local polyfil of Object.create 8638 */ 8639 var create = 8640 Object.create || 8641 (function () { 8642 function F() {} 8643 8644 return function (obj) { 8645 var subtype; 8646 8647 F.prototype = obj; 8648 8649 subtype = new F(); 8650 8651 F.prototype = null; 8652 8653 return subtype; 8654 }; 8655 })(); 8656 8657 /** 8658 * CryptoJS namespace. 8659 */ 8660 var C = {}; 8661 8662 /** 8663 * Library namespace. 8664 */ 8665 var C_lib = (C.lib = {}); 8666 8667 /** 8668 * Base object for prototypal inheritance. 8669 */ 8670 var Base = (C_lib.Base = (function () { 8671 return { 8672 /** 8673 * Creates a new object that inherits from this object. 8674 * 8675 * @param {Object} overrides Properties to copy into the new object. 8676 * 8677 * @return {Object} The new object. 8678 * 8679 * @static 8680 * 8681 * @example 8682 * 8683 * var MyType = CryptoJS.lib.Base.extend({ 8684 * field: 'value', 8685 * 8686 * method: function () { 8687 * } 8688 * }); 8689 */ 8690 extend: function (overrides) { 8691 // Spawn 8692 var subtype = create(this); 8693 8694 // Augment 8695 if (overrides) { 8696 subtype.mixIn(overrides); 8697 } 8698 8699 // Create default initializer 8700 if ( 8701 !subtype.hasOwnProperty("init") || 8702 this.init === subtype.init 8703 ) { 8704 subtype.init = function () { 8705 subtype.$super.init.apply(this, arguments); 8706 }; 8707 } 8708 8709 // Initializer's prototype is the subtype object 8710 subtype.init.prototype = subtype; 8711 8712 // Reference supertype 8713 subtype.$super = this; 8714 8715 return subtype; 8716 }, 8717 8718 /** 8719 * Extends this object and runs the init method. 8720 * Arguments to create() will be passed to init(). 8721 * 8722 * @return {Object} The new object. 8723 * 8724 * @static 8725 * 8726 * @example 8727 * 8728 * var instance = MyType.create(); 8729 */ 8730 create: function () { 8731 var instance = this.extend(); 8732 instance.init.apply(instance, arguments); 8733 8734 return instance; 8735 }, 8736 8737 /** 8738 * Initializes a newly created object. 8739 * Override this method to add some logic when your objects are created. 8740 * 8741 * @example 8742 * 8743 * var MyType = CryptoJS.lib.Base.extend({ 8744 * init: function () { 8745 * // ... 8746 * } 8747 * }); 8748 */ 8749 init: function () {}, 8750 8751 /** 8752 * Copies properties into this object. 8753 * 8754 * @param {Object} properties The properties to mix in. 8755 * 8756 * @example 8757 * 8758 * MyType.mixIn({ 8759 * field: 'value' 8760 * }); 8761 */ 8762 mixIn: function (properties) { 8763 for (var propertyName in properties) { 8764 if (properties.hasOwnProperty(propertyName)) { 8765 this[propertyName] = properties[propertyName]; 8766 } 8767 } 8768 8769 // IE won't copy toString using the loop above 8770 if (properties.hasOwnProperty("toString")) { 8771 this.toString = properties.toString; 8772 } 8773 }, 8774 8775 /** 8776 * Creates a copy of this object. 8777 * 8778 * @return {Object} The clone. 8779 * 8780 * @example 8781 * 8782 * var clone = instance.clone(); 8783 */ 8784 clone: function () { 8785 return this.init.prototype.extend(this); 8786 }, 8787 }; 8788 })()); 8789 8790 /** 8791 * An array of 32-bit words. 8792 * 8793 * @property {Array} words The array of 32-bit words. 8794 * @property {number} sigBytes The number of significant bytes in this word array. 8795 */ 8796 var WordArray = (C_lib.WordArray = Base.extend({ 8797 /** 8798 * Initializes a newly created word array. 8799 * 8800 * @param {Array} words (Optional) An array of 32-bit words. 8801 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8802 * 8803 * @example 8804 * 8805 * var wordArray = CryptoJS.lib.WordArray.create(); 8806 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8807 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8808 */ 8809 init: function (words, sigBytes) { 8810 words = this.words = words || []; 8811 8812 if (sigBytes != undefined) { 8813 this.sigBytes = sigBytes; 8814 } else { 8815 this.sigBytes = words.length * 4; 8816 } 8817 }, 8818 8819 /** 8820 * Converts this word array to a string. 8821 * 8822 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8823 * 8824 * @return {string} The stringified word array. 8825 * 8826 * @example 8827 * 8828 * var string = wordArray + ''; 8829 * var string = wordArray.toString(); 8830 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8831 */ 8832 toString: function (encoder) { 8833 return (encoder || Hex).stringify(this); 8834 }, 8835 8836 /** 8837 * Concatenates a word array to this word array. 8838 * 8839 * @param {WordArray} wordArray The word array to append. 8840 * 8841 * @return {WordArray} This word array. 8842 * 8843 * @example 8844 * 8845 * wordArray1.concat(wordArray2); 8846 */ 8847 concat: function (wordArray) { 8848 // Shortcuts 8849 var thisWords = this.words; 8850 var thatWords = wordArray.words; 8851 var thisSigBytes = this.sigBytes; 8852 var thatSigBytes = wordArray.sigBytes; 8853 8854 // Clamp excess bits 8855 this.clamp(); 8856 8857 // Concat 8858 if (thisSigBytes % 4) { 8859 // Copy one byte at a time 8860 for (var i = 0; i < thatSigBytes; i++) { 8861 var thatByte = 8862 (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8863 thisWords[(thisSigBytes + i) >>> 2] |= 8864 thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8865 } 8866 } else { 8867 // Copy one word at a time 8868 for (var i = 0; i < thatSigBytes; i += 4) { 8869 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8870 } 8871 } 8872 this.sigBytes += thatSigBytes; 8873 8874 // Chainable 8875 return this; 8876 }, 8877 8878 /** 8879 * Removes insignificant bits. 8880 * 8881 * @example 8882 * 8883 * wordArray.clamp(); 8884 */ 8885 clamp: function () { 8886 // Shortcuts 8887 var words = this.words; 8888 var sigBytes = this.sigBytes; 8889 8890 // Clamp 8891 words[sigBytes >>> 2] &= 8892 0xffffffff << (32 - (sigBytes % 4) * 8); 8893 words.length = Math.ceil(sigBytes / 4); 8894 }, 8895 8896 /** 8897 * Creates a copy of this word array. 8898 * 8899 * @return {WordArray} The clone. 8900 * 8901 * @example 8902 * 8903 * var clone = wordArray.clone(); 8904 */ 8905 clone: function () { 8906 var clone = Base.clone.call(this); 8907 clone.words = this.words.slice(0); 8908 8909 return clone; 8910 }, 8911 8912 /** 8913 * Creates a word array filled with random bytes. 8914 * 8915 * @param {number} nBytes The number of random bytes to generate. 8916 * 8917 * @return {WordArray} The random word array. 8918 * 8919 * @static 8920 * 8921 * @example 8922 * 8923 * var wordArray = CryptoJS.lib.WordArray.random(16); 8924 */ 8925 random: function (nBytes) { 8926 var words = []; 8927 8928 var r = function (m_w) { 8929 var m_w = m_w; 8930 var m_z = 0x3ade68b1; 8931 var mask = 0xffffffff; 8932 8933 return function () { 8934 m_z = (0x9069 * (m_z & 0xffff) + (m_z >> 0x10)) & mask; 8935 m_w = (0x4650 * (m_w & 0xffff) + (m_w >> 0x10)) & mask; 8936 var result = ((m_z << 0x10) + m_w) & mask; 8937 result /= 0x100000000; 8938 result += 0.5; 8939 return result * (Math.random() > 0.5 ? 1 : -1); 8940 }; 8941 }; 8942 8943 for (var i = 0, rcache; i < nBytes; i += 4) { 8944 var _r = r((rcache || Math.random()) * 0x100000000); 8945 8946 rcache = _r() * 0x3ade67b7; 8947 words.push((_r() * 0x100000000) | 0); 8948 } 8949 8950 return new WordArray.init(words, nBytes); 8951 }, 8952 })); 8953 8954 /** 8955 * Encoder namespace. 8956 */ 8957 var C_enc = (C.enc = {}); 8958 8959 /** 8960 * Hex encoding strategy. 8961 */ 8962 var Hex = (C_enc.Hex = { 8963 /** 8964 * Converts a word array to a hex string. 8965 * 8966 * @param {WordArray} wordArray The word array. 8967 * 8968 * @return {string} The hex string. 8969 * 8970 * @static 8971 * 8972 * @example 8973 * 8974 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8975 */ 8976 stringify: function (wordArray) { 8977 // Shortcuts 8978 var words = wordArray.words; 8979 var sigBytes = wordArray.sigBytes; 8980 8981 // Convert 8982 var hexChars = []; 8983 for (var i = 0; i < sigBytes; i++) { 8984 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8985 hexChars.push((bite >>> 4).toString(16)); 8986 hexChars.push((bite & 0x0f).toString(16)); 8987 } 8988 8989 return hexChars.join(""); 8990 }, 8991 8992 /** 8993 * Converts a hex string to a word array. 8994 * 8995 * @param {string} hexStr The hex string. 8996 * 8997 * @return {WordArray} The word array. 8998 * 8999 * @static 9000 * 9001 * @example 9002 * 9003 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 9004 */ 9005 parse: function (hexStr) { 9006 // Shortcut 9007 var hexStrLength = hexStr.length; 9008 9009 // Convert 9010 var words = []; 9011 for (var i = 0; i < hexStrLength; i += 2) { 9012 words[i >>> 3] |= 9013 parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 9014 } 9015 9016 return new WordArray.init(words, hexStrLength / 2); 9017 }, 9018 }); 9019 9020 /** 9021 * Latin1 encoding strategy. 9022 */ 9023 var Latin1 = (C_enc.Latin1 = { 9024 /** 9025 * Converts a word array to a Latin1 string. 9026 * 9027 * @param {WordArray} wordArray The word array. 9028 * 9029 * @return {string} The Latin1 string. 9030 * 9031 * @static 9032 * 9033 * @example 9034 * 9035 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 9036 */ 9037 stringify: function (wordArray) { 9038 // Shortcuts 9039 var words = wordArray.words; 9040 var sigBytes = wordArray.sigBytes; 9041 9042 // Convert 9043 var latin1Chars = []; 9044 for (var i = 0; i < sigBytes; i++) { 9045 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 9046 latin1Chars.push(String.fromCharCode(bite)); 9047 } 9048 9049 return latin1Chars.join(""); 9050 }, 9051 9052 /** 9053 * Converts a Latin1 string to a word array. 9054 * 9055 * @param {string} latin1Str The Latin1 string. 9056 * 9057 * @return {WordArray} The word array. 9058 * 9059 * @static 9060 * 9061 * @example 9062 * 9063 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 9064 */ 9065 parse: function (latin1Str) { 9066 // Shortcut 9067 var latin1StrLength = latin1Str.length; 9068 9069 // Convert 9070 var words = []; 9071 for (var i = 0; i < latin1StrLength; i++) { 9072 words[i >>> 2] |= 9073 (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 9074 } 9075 9076 return new WordArray.init(words, latin1StrLength); 9077 }, 9078 }); 9079 9080 /** 9081 * UTF-8 encoding strategy. 9082 */ 9083 var Utf8 = (C_enc.Utf8 = { 9084 /** 9085 * Converts a word array to a UTF-8 string. 9086 * 9087 * @param {WordArray} wordArray The word array. 9088 * 9089 * @return {string} The UTF-8 string. 9090 * 9091 * @static 9092 * 9093 * @example 9094 * 9095 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 9096 */ 9097 stringify: function (wordArray) { 9098 try { 9099 return decodeURIComponent( 9100 escape(Latin1.stringify(wordArray)) 9101 ); 9102 } catch (e) { 9103 throw new Error("Malformed UTF-8 data"); 9104 } 9105 }, 9106 9107 /** 9108 * Converts a UTF-8 string to a word array. 9109 * 9110 * @param {string} utf8Str The UTF-8 string. 9111 * 9112 * @return {WordArray} The word array. 9113 * 9114 * @static 9115 * 9116 * @example 9117 * 9118 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 9119 */ 9120 parse: function (utf8Str) { 9121 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 9122 }, 9123 }); 9124 9125 /** 9126 * Abstract buffered block algorithm template. 9127 * 9128 * The property blockSize must be implemented in a concrete subtype. 9129 * 9130 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 9131 */ 9132 var BufferedBlockAlgorithm = (C_lib.BufferedBlockAlgorithm = 9133 Base.extend({ 9134 /** 9135 * Resets this block algorithm's data buffer to its initial state. 9136 * 9137 * @example 9138 * 9139 * bufferedBlockAlgorithm.reset(); 9140 */ 9141 reset: function () { 9142 // Initial values 9143 this._data = new WordArray.init(); 9144 this._nDataBytes = 0; 9145 }, 9146 9147 /** 9148 * Adds new data to this block algorithm's buffer. 9149 * 9150 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 9151 * 9152 * @example 9153 * 9154 * bufferedBlockAlgorithm._append('data'); 9155 * bufferedBlockAlgorithm._append(wordArray); 9156 */ 9157 _append: function (data) { 9158 // Convert string to WordArray, else assume WordArray already 9159 if (typeof data == "string") { 9160 data = Utf8.parse(data); 9161 } 9162 9163 // Append 9164 this._data.concat(data); 9165 this._nDataBytes += data.sigBytes; 9166 }, 9167 9168 /** 9169 * Processes available data blocks. 9170 * 9171 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 9172 * 9173 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 9174 * 9175 * @return {WordArray} The processed data. 9176 * 9177 * @example 9178 * 9179 * var processedData = bufferedBlockAlgorithm._process(); 9180 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 9181 */ 9182 _process: function (doFlush) { 9183 // Shortcuts 9184 var data = this._data; 9185 var dataWords = data.words; 9186 var dataSigBytes = data.sigBytes; 9187 var blockSize = this.blockSize; 9188 var blockSizeBytes = blockSize * 4; 9189 9190 // Count blocks ready 9191 var nBlocksReady = dataSigBytes / blockSizeBytes; 9192 if (doFlush) { 9193 // Round up to include partial blocks 9194 nBlocksReady = Math.ceil(nBlocksReady); 9195 } else { 9196 // Round down to include only full blocks, 9197 // less the number of blocks that must remain in the buffer 9198 nBlocksReady = Math.max( 9199 (nBlocksReady | 0) - this._minBufferSize, 9200 0 9201 ); 9202 } 9203 9204 // Count words ready 9205 var nWordsReady = nBlocksReady * blockSize; 9206 9207 // Count bytes ready 9208 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 9209 9210 // Process blocks 9211 if (nWordsReady) { 9212 for ( 9213 var offset = 0; 9214 offset < nWordsReady; 9215 offset += blockSize 9216 ) { 9217 // Perform concrete-algorithm logic 9218 this._doProcessBlock(dataWords, offset); 9219 } 9220 9221 // Remove processed words 9222 var processedWords = dataWords.splice(0, nWordsReady); 9223 data.sigBytes -= nBytesReady; 9224 } 9225 9226 // Return processed words 9227 return new WordArray.init(processedWords, nBytesReady); 9228 }, 9229 9230 /** 9231 * Creates a copy of this object. 9232 * 9233 * @return {Object} The clone. 9234 * 9235 * @example 9236 * 9237 * var clone = bufferedBlockAlgorithm.clone(); 9238 */ 9239 clone: function () { 9240 var clone = Base.clone.call(this); 9241 clone._data = this._data.clone(); 9242 9243 return clone; 9244 }, 9245 9246 _minBufferSize: 0, 9247 })); 9248 9249 /** 9250 * Abstract hasher template. 9251 * 9252 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 9253 */ 9254 var Hasher = (C_lib.Hasher = BufferedBlockAlgorithm.extend({ 9255 /** 9256 * Configuration options. 9257 */ 9258 cfg: Base.extend(), 9259 9260 /** 9261 * Initializes a newly created hasher. 9262 * 9263 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 9264 * 9265 * @example 9266 * 9267 * var hasher = CryptoJS.algo.SHA256.create(); 9268 */ 9269 init: function (cfg) { 9270 // Apply config defaults 9271 this.cfg = this.cfg.extend(cfg); 9272 9273 // Set initial values 9274 this.reset(); 9275 }, 9276 9277 /** 9278 * Resets this hasher to its initial state. 9279 * 9280 * @example 9281 * 9282 * hasher.reset(); 9283 */ 9284 reset: function () { 9285 // Reset data buffer 9286 BufferedBlockAlgorithm.reset.call(this); 9287 9288 // Perform concrete-hasher logic 9289 this._doReset(); 9290 }, 9291 9292 /** 9293 * Updates this hasher with a message. 9294 * 9295 * @param {WordArray|string} messageUpdate The message to append. 9296 * 9297 * @return {Hasher} This hasher. 9298 * 9299 * @example 9300 * 9301 * hasher.update('message'); 9302 * hasher.update(wordArray); 9303 */ 9304 update: function (messageUpdate) { 9305 // Append 9306 this._append(messageUpdate); 9307 9308 // Update the hash 9309 this._process(); 9310 9311 // Chainable 9312 return this; 9313 }, 9314 9315 /** 9316 * Finalizes the hash computation. 9317 * Note that the finalize operation is effectively a destructive, read-once operation. 9318 * 9319 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9320 * 9321 * @return {WordArray} The hash. 9322 * 9323 * @example 9324 * 9325 * var hash = hasher.finalize(); 9326 * var hash = hasher.finalize('message'); 9327 * var hash = hasher.finalize(wordArray); 9328 */ 9329 finalize: function (messageUpdate) { 9330 // Final message update 9331 if (messageUpdate) { 9332 this._append(messageUpdate); 9333 } 9334 9335 // Perform concrete-hasher logic 9336 var hash = this._doFinalize(); 9337 9338 return hash; 9339 }, 9340 9341 blockSize: 512 / 32, 9342 9343 /** 9344 * Creates a shortcut function to a hasher's object interface. 9345 * 9346 * @param {Hasher} hasher The hasher to create a helper for. 9347 * 9348 * @return {Function} The shortcut function. 9349 * 9350 * @static 9351 * 9352 * @example 9353 * 9354 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 9355 */ 9356 _createHelper: function (hasher) { 9357 return function (message, cfg) { 9358 return new hasher.init(cfg).finalize(message); 9359 }; 9360 }, 9361 9362 /** 9363 * Creates a shortcut function to the HMAC's object interface. 9364 * 9365 * @param {Hasher} hasher The hasher to use in this HMAC helper. 9366 * 9367 * @return {Function} The shortcut function. 9368 * 9369 * @static 9370 * 9371 * @example 9372 * 9373 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 9374 */ 9375 _createHmacHelper: function (hasher) { 9376 return function (message, key) { 9377 return new C_algo.HMAC.init(hasher, key).finalize(message); 9378 }; 9379 }, 9380 })); 9381 9382 /** 9383 * Algorithm namespace. 9384 */ 9385 var C_algo = (C.algo = {}); 9386 9387 return C; 9388 })(Math); 9389 9390 return CryptoJS; 9391 }); 9392 }, 9393 {}, 9394 ], 9395 54: [ 9396 function (require, module, exports) { 9397 (function (root, factory) { 9398 if (typeof exports === "object") { 9399 // CommonJS 9400 module.exports = exports = factory(require("./core")); 9401 } else if (typeof define === "function" && define.amd) { 9402 // AMD 9403 define(["./core"], factory); 9404 } else { 9405 // Global (browser) 9406 factory(root.CryptoJS); 9407 } 9408 })(this, function (CryptoJS) { 9409 (function () { 9410 // Shortcuts 9411 var C = CryptoJS; 9412 var C_lib = C.lib; 9413 var WordArray = C_lib.WordArray; 9414 var C_enc = C.enc; 9415 9416 /** 9417 * Base64 encoding strategy. 9418 */ 9419 var Base64 = (C_enc.Base64 = { 9420 /** 9421 * Converts a word array to a Base64 string. 9422 * 9423 * @param {WordArray} wordArray The word array. 9424 * 9425 * @return {string} The Base64 string. 9426 * 9427 * @static 9428 * 9429 * @example 9430 * 9431 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 9432 */ 9433 stringify: function (wordArray) { 9434 // Shortcuts 9435 var words = wordArray.words; 9436 var sigBytes = wordArray.sigBytes; 9437 var map = this._map; 9438 9439 // Clamp excess bits 9440 wordArray.clamp(); 9441 9442 // Convert 9443 var base64Chars = []; 9444 for (var i = 0; i < sigBytes; i += 3) { 9445 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 9446 var byte2 = 9447 (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 9448 var byte3 = 9449 (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 9450 9451 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 9452 9453 for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) { 9454 base64Chars.push( 9455 map.charAt((triplet >>> (6 * (3 - j))) & 0x3f) 9456 ); 9457 } 9458 } 9459 9460 // Add padding 9461 var paddingChar = map.charAt(64); 9462 if (paddingChar) { 9463 while (base64Chars.length % 4) { 9464 base64Chars.push(paddingChar); 9465 } 9466 } 9467 9468 return base64Chars.join(""); 9469 }, 9470 9471 /** 9472 * Converts a Base64 string to a word array. 9473 * 9474 * @param {string} base64Str The Base64 string. 9475 * 9476 * @return {WordArray} The word array. 9477 * 9478 * @static 9479 * 9480 * @example 9481 * 9482 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 9483 */ 9484 parse: function (base64Str) { 9485 // Shortcuts 9486 var base64StrLength = base64Str.length; 9487 var map = this._map; 9488 var reverseMap = this._reverseMap; 9489 9490 if (!reverseMap) { 9491 reverseMap = this._reverseMap = []; 9492 for (var j = 0; j < map.length; j++) { 9493 reverseMap[map.charCodeAt(j)] = j; 9494 } 9495 } 9496 9497 // Ignore padding 9498 var paddingChar = map.charAt(64); 9499 if (paddingChar) { 9500 var paddingIndex = base64Str.indexOf(paddingChar); 9501 if (paddingIndex !== -1) { 9502 base64StrLength = paddingIndex; 9503 } 9504 } 9505 9506 // Convert 9507 return parseLoop(base64Str, base64StrLength, reverseMap); 9508 }, 9509 9510 _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", 9511 }); 9512 9513 function parseLoop(base64Str, base64StrLength, reverseMap) { 9514 var words = []; 9515 var nBytes = 0; 9516 for (var i = 0; i < base64StrLength; i++) { 9517 if (i % 4) { 9518 var bits1 = 9519 reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 9520 var bits2 = 9521 reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 9522 words[nBytes >>> 2] |= 9523 (bits1 | bits2) << (24 - (nBytes % 4) * 8); 9524 nBytes++; 9525 } 9526 } 9527 return WordArray.create(words, nBytes); 9528 } 9529 })(); 9530 9531 return CryptoJS.enc.Base64; 9532 }); 9533 }, 9534 { "./core": 53 }, 9535 ], 9536 55: [ 9537 function (require, module, exports) { 9538 (function (root, factory) { 9539 if (typeof exports === "object") { 9540 // CommonJS 9541 module.exports = exports = factory(require("./core")); 9542 } else if (typeof define === "function" && define.amd) { 9543 // AMD 9544 define(["./core"], factory); 9545 } else { 9546 // Global (browser) 9547 factory(root.CryptoJS); 9548 } 9549 })(this, function (CryptoJS) { 9550 (function () { 9551 // Shortcuts 9552 var C = CryptoJS; 9553 var C_lib = C.lib; 9554 var WordArray = C_lib.WordArray; 9555 var C_enc = C.enc; 9556 9557 /** 9558 * UTF-16 BE encoding strategy. 9559 */ 9560 var Utf16BE = 9561 (C_enc.Utf16 = 9562 C_enc.Utf16BE = 9563 { 9564 /** 9565 * Converts a word array to a UTF-16 BE string. 9566 * 9567 * @param {WordArray} wordArray The word array. 9568 * 9569 * @return {string} The UTF-16 BE string. 9570 * 9571 * @static 9572 * 9573 * @example 9574 * 9575 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 9576 */ 9577 stringify: function (wordArray) { 9578 // Shortcuts 9579 var words = wordArray.words; 9580 var sigBytes = wordArray.sigBytes; 9581 9582 // Convert 9583 var utf16Chars = []; 9584 for (var i = 0; i < sigBytes; i += 2) { 9585 var codePoint = 9586 (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 9587 utf16Chars.push(String.fromCharCode(codePoint)); 9588 } 9589 9590 return utf16Chars.join(""); 9591 }, 9592 9593 /** 9594 * Converts a UTF-16 BE string to a word array. 9595 * 9596 * @param {string} utf16Str The UTF-16 BE string. 9597 * 9598 * @return {WordArray} The word array. 9599 * 9600 * @static 9601 * 9602 * @example 9603 * 9604 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 9605 */ 9606 parse: function (utf16Str) { 9607 // Shortcut 9608 var utf16StrLength = utf16Str.length; 9609 9610 // Convert 9611 var words = []; 9612 for (var i = 0; i < utf16StrLength; i++) { 9613 words[i >>> 1] |= 9614 utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 9615 } 9616 9617 return WordArray.create(words, utf16StrLength * 2); 9618 }, 9619 }); 9620 9621 /** 9622 * UTF-16 LE encoding strategy. 9623 */ 9624 C_enc.Utf16LE = { 9625 /** 9626 * Converts a word array to a UTF-16 LE string. 9627 * 9628 * @param {WordArray} wordArray The word array. 9629 * 9630 * @return {string} The UTF-16 LE string. 9631 * 9632 * @static 9633 * 9634 * @example 9635 * 9636 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 9637 */ 9638 stringify: function (wordArray) { 9639 // Shortcuts 9640 var words = wordArray.words; 9641 var sigBytes = wordArray.sigBytes; 9642 9643 // Convert 9644 var utf16Chars = []; 9645 for (var i = 0; i < sigBytes; i += 2) { 9646 var codePoint = swapEndian( 9647 (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff 9648 ); 9649 utf16Chars.push(String.fromCharCode(codePoint)); 9650 } 9651 9652 return utf16Chars.join(""); 9653 }, 9654 9655 /** 9656 * Converts a UTF-16 LE string to a word array. 9657 * 9658 * @param {string} utf16Str The UTF-16 LE string. 9659 * 9660 * @return {WordArray} The word array. 9661 * 9662 * @static 9663 * 9664 * @example 9665 * 9666 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 9667 */ 9668 parse: function (utf16Str) { 9669 // Shortcut 9670 var utf16StrLength = utf16Str.length; 9671 9672 // Convert 9673 var words = []; 9674 for (var i = 0; i < utf16StrLength; i++) { 9675 words[i >>> 1] |= swapEndian( 9676 utf16Str.charCodeAt(i) << (16 - (i % 2) * 16) 9677 ); 9678 } 9679 9680 return WordArray.create(words, utf16StrLength * 2); 9681 }, 9682 }; 9683 9684 function swapEndian(word) { 9685 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 9686 } 9687 })(); 9688 9689 return CryptoJS.enc.Utf16; 9690 }); 9691 }, 9692 { "./core": 53 }, 9693 ], 9694 56: [ 9695 function (require, module, exports) { 9696 (function (root, factory, undef) { 9697 if (typeof exports === "object") { 9698 // CommonJS 9699 module.exports = exports = factory( 9700 require("./core"), 9701 require("./sha1"), 9702 require("./hmac") 9703 ); 9704 } else if (typeof define === "function" && define.amd) { 9705 // AMD 9706 define(["./core", "./sha1", "./hmac"], factory); 9707 } else { 9708 // Global (browser) 9709 factory(root.CryptoJS); 9710 } 9711 })(this, function (CryptoJS) { 9712 (function () { 9713 // Shortcuts 9714 var C = CryptoJS; 9715 var C_lib = C.lib; 9716 var Base = C_lib.Base; 9717 var WordArray = C_lib.WordArray; 9718 var C_algo = C.algo; 9719 var MD5 = C_algo.MD5; 9720 9721 /** 9722 * This key derivation function is meant to conform with EVP_BytesToKey. 9723 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 9724 */ 9725 var EvpKDF = (C_algo.EvpKDF = Base.extend({ 9726 /** 9727 * Configuration options. 9728 * 9729 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9730 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 9731 * @property {number} iterations The number of iterations to perform. Default: 1 9732 */ 9733 cfg: Base.extend({ 9734 keySize: 128 / 32, 9735 hasher: MD5, 9736 iterations: 1, 9737 }), 9738 9739 /** 9740 * Initializes a newly created key derivation function. 9741 * 9742 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9743 * 9744 * @example 9745 * 9746 * var kdf = CryptoJS.algo.EvpKDF.create(); 9747 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9748 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9749 */ 9750 init: function (cfg) { 9751 this.cfg = this.cfg.extend(cfg); 9752 }, 9753 9754 /** 9755 * Derives a key from a password. 9756 * 9757 * @param {WordArray|string} password The password. 9758 * @param {WordArray|string} salt A salt. 9759 * 9760 * @return {WordArray} The derived key. 9761 * 9762 * @example 9763 * 9764 * var key = kdf.compute(password, salt); 9765 */ 9766 compute: function (password, salt) { 9767 // Shortcut 9768 var cfg = this.cfg; 9769 9770 // Init hasher 9771 var hasher = cfg.hasher.create(); 9772 9773 // Initial values 9774 var derivedKey = WordArray.create(); 9775 9776 // Shortcuts 9777 var derivedKeyWords = derivedKey.words; 9778 var keySize = cfg.keySize; 9779 var iterations = cfg.iterations; 9780 9781 // Generate key 9782 while (derivedKeyWords.length < keySize) { 9783 if (block) { 9784 hasher.update(block); 9785 } 9786 var block = hasher.update(password).finalize(salt); 9787 hasher.reset(); 9788 9789 // Iterations 9790 for (var i = 1; i < iterations; i++) { 9791 block = hasher.finalize(block); 9792 hasher.reset(); 9793 } 9794 9795 derivedKey.concat(block); 9796 } 9797 derivedKey.sigBytes = keySize * 4; 9798 9799 return derivedKey; 9800 }, 9801 })); 9802 9803 /** 9804 * Derives a key from a password. 9805 * 9806 * @param {WordArray|string} password The password. 9807 * @param {WordArray|string} salt A salt. 9808 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9809 * 9810 * @return {WordArray} The derived key. 9811 * 9812 * @static 9813 * 9814 * @example 9815 * 9816 * var key = CryptoJS.EvpKDF(password, salt); 9817 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9818 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9819 */ 9820 C.EvpKDF = function (password, salt, cfg) { 9821 return EvpKDF.create(cfg).compute(password, salt); 9822 }; 9823 })(); 9824 9825 return CryptoJS.EvpKDF; 9826 }); 9827 }, 9828 { "./core": 53, "./hmac": 58, "./sha1": 77 }, 9829 ], 9830 57: [ 9831 function (require, module, exports) { 9832 (function (root, factory, undef) { 9833 if (typeof exports === "object") { 9834 // CommonJS 9835 module.exports = exports = factory( 9836 require("./core"), 9837 require("./cipher-core") 9838 ); 9839 } else if (typeof define === "function" && define.amd) { 9840 // AMD 9841 define(["./core", "./cipher-core"], factory); 9842 } else { 9843 // Global (browser) 9844 factory(root.CryptoJS); 9845 } 9846 })(this, function (CryptoJS) { 9847 (function (undefined) { 9848 // Shortcuts 9849 var C = CryptoJS; 9850 var C_lib = C.lib; 9851 var CipherParams = C_lib.CipherParams; 9852 var C_enc = C.enc; 9853 var Hex = C_enc.Hex; 9854 var C_format = C.format; 9855 9856 var HexFormatter = (C_format.Hex = { 9857 /** 9858 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9859 * 9860 * @param {CipherParams} cipherParams The cipher params object. 9861 * 9862 * @return {string} The hexadecimally encoded string. 9863 * 9864 * @static 9865 * 9866 * @example 9867 * 9868 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9869 */ 9870 stringify: function (cipherParams) { 9871 return cipherParams.ciphertext.toString(Hex); 9872 }, 9873 9874 /** 9875 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9876 * 9877 * @param {string} input The hexadecimally encoded string. 9878 * 9879 * @return {CipherParams} The cipher params object. 9880 * 9881 * @static 9882 * 9883 * @example 9884 * 9885 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9886 */ 9887 parse: function (input) { 9888 var ciphertext = Hex.parse(input); 9889 return CipherParams.create({ ciphertext: ciphertext }); 9890 }, 9891 }); 9892 })(); 9893 9894 return CryptoJS.format.Hex; 9895 }); 9896 }, 9897 { "./cipher-core": 52, "./core": 53 }, 9898 ], 9899 58: [ 9900 function (require, module, exports) { 9901 (function (root, factory) { 9902 if (typeof exports === "object") { 9903 // CommonJS 9904 module.exports = exports = factory(require("./core")); 9905 } else if (typeof define === "function" && define.amd) { 9906 // AMD 9907 define(["./core"], factory); 9908 } else { 9909 // Global (browser) 9910 factory(root.CryptoJS); 9911 } 9912 })(this, function (CryptoJS) { 9913 (function () { 9914 // Shortcuts 9915 var C = CryptoJS; 9916 var C_lib = C.lib; 9917 var Base = C_lib.Base; 9918 var C_enc = C.enc; 9919 var Utf8 = C_enc.Utf8; 9920 var C_algo = C.algo; 9921 9922 /** 9923 * HMAC algorithm. 9924 */ 9925 var HMAC = (C_algo.HMAC = Base.extend({ 9926 /** 9927 * Initializes a newly created HMAC. 9928 * 9929 * @param {Hasher} hasher The hash algorithm to use. 9930 * @param {WordArray|string} key The secret key. 9931 * 9932 * @example 9933 * 9934 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9935 */ 9936 init: function (hasher, key) { 9937 // Init hasher 9938 hasher = this._hasher = new hasher.init(); 9939 9940 // Convert string to WordArray, else assume WordArray already 9941 if (typeof key == "string") { 9942 key = Utf8.parse(key); 9943 } 9944 9945 // Shortcuts 9946 var hasherBlockSize = hasher.blockSize; 9947 var hasherBlockSizeBytes = hasherBlockSize * 4; 9948 9949 // Allow arbitrary length keys 9950 if (key.sigBytes > hasherBlockSizeBytes) { 9951 key = hasher.finalize(key); 9952 } 9953 9954 // Clamp excess bits 9955 key.clamp(); 9956 9957 // Clone key for inner and outer pads 9958 var oKey = (this._oKey = key.clone()); 9959 var iKey = (this._iKey = key.clone()); 9960 9961 // Shortcuts 9962 var oKeyWords = oKey.words; 9963 var iKeyWords = iKey.words; 9964 9965 // XOR keys with pad constants 9966 for (var i = 0; i < hasherBlockSize; i++) { 9967 oKeyWords[i] ^= 0x5c5c5c5c; 9968 iKeyWords[i] ^= 0x36363636; 9969 } 9970 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9971 9972 // Set initial values 9973 this.reset(); 9974 }, 9975 9976 /** 9977 * Resets this HMAC to its initial state. 9978 * 9979 * @example 9980 * 9981 * hmacHasher.reset(); 9982 */ 9983 reset: function () { 9984 // Shortcut 9985 var hasher = this._hasher; 9986 9987 // Reset 9988 hasher.reset(); 9989 hasher.update(this._iKey); 9990 }, 9991 9992 /** 9993 * Updates this HMAC with a message. 9994 * 9995 * @param {WordArray|string} messageUpdate The message to append. 9996 * 9997 * @return {HMAC} This HMAC instance. 9998 * 9999 * @example 10000 * 10001 * hmacHasher.update('message'); 10002 * hmacHasher.update(wordArray); 10003 */ 10004 update: function (messageUpdate) { 10005 this._hasher.update(messageUpdate); 10006 10007 // Chainable 10008 return this; 10009 }, 10010 10011 /** 10012 * Finalizes the HMAC computation. 10013 * Note that the finalize operation is effectively a destructive, read-once operation. 10014 * 10015 * @param {WordArray|string} messageUpdate (Optional) A final message update. 10016 * 10017 * @return {WordArray} The HMAC. 10018 * 10019 * @example 10020 * 10021 * var hmac = hmacHasher.finalize(); 10022 * var hmac = hmacHasher.finalize('message'); 10023 * var hmac = hmacHasher.finalize(wordArray); 10024 */ 10025 finalize: function (messageUpdate) { 10026 // Shortcut 10027 var hasher = this._hasher; 10028 10029 // Compute HMAC 10030 var innerHash = hasher.finalize(messageUpdate); 10031 hasher.reset(); 10032 var hmac = hasher.finalize( 10033 this._oKey.clone().concat(innerHash) 10034 ); 10035 10036 return hmac; 10037 }, 10038 })); 10039 })(); 10040 }); 10041 }, 10042 { "./core": 53 }, 10043 ], 10044 59: [ 10045 function (require, module, exports) { 10046 (function (root, factory, undef) { 10047 if (typeof exports === "object") { 10048 // CommonJS 10049 module.exports = exports = factory( 10050 require("./core"), 10051 require("./x64-core"), 10052 require("./lib-typedarrays"), 10053 require("./enc-utf16"), 10054 require("./enc-base64"), 10055 require("./md5"), 10056 require("./sha1"), 10057 require("./sha256"), 10058 require("./sha224"), 10059 require("./sha512"), 10060 require("./sha384"), 10061 require("./sha3"), 10062 require("./ripemd160"), 10063 require("./hmac"), 10064 require("./pbkdf2"), 10065 require("./evpkdf"), 10066 require("./cipher-core"), 10067 require("./mode-cfb"), 10068 require("./mode-ctr"), 10069 require("./mode-ctr-gladman"), 10070 require("./mode-ofb"), 10071 require("./mode-ecb"), 10072 require("./pad-ansix923"), 10073 require("./pad-iso10126"), 10074 require("./pad-iso97971"), 10075 require("./pad-zeropadding"), 10076 require("./pad-nopadding"), 10077 require("./format-hex"), 10078 require("./aes"), 10079 require("./tripledes"), 10080 require("./rc4"), 10081 require("./rabbit"), 10082 require("./rabbit-legacy") 10083 ); 10084 } else if (typeof define === "function" && define.amd) { 10085 // AMD 10086 define([ 10087 "./core", 10088 "./x64-core", 10089 "./lib-typedarrays", 10090 "./enc-utf16", 10091 "./enc-base64", 10092 "./md5", 10093 "./sha1", 10094 "./sha256", 10095 "./sha224", 10096 "./sha512", 10097 "./sha384", 10098 "./sha3", 10099 "./ripemd160", 10100 "./hmac", 10101 "./pbkdf2", 10102 "./evpkdf", 10103 "./cipher-core", 10104 "./mode-cfb", 10105 "./mode-ctr", 10106 "./mode-ctr-gladman", 10107 "./mode-ofb", 10108 "./mode-ecb", 10109 "./pad-ansix923", 10110 "./pad-iso10126", 10111 "./pad-iso97971", 10112 "./pad-zeropadding", 10113 "./pad-nopadding", 10114 "./format-hex", 10115 "./aes", 10116 "./tripledes", 10117 "./rc4", 10118 "./rabbit", 10119 "./rabbit-legacy", 10120 ], factory); 10121 } else { 10122 // Global (browser) 10123 root.CryptoJS = factory(root.CryptoJS); 10124 } 10125 })(this, function (CryptoJS) { 10126 return CryptoJS; 10127 }); 10128 }, 10129 { 10130 "./aes": 51, 10131 "./cipher-core": 52, 10132 "./core": 53, 10133 "./enc-base64": 54, 10134 "./enc-utf16": 55, 10135 "./evpkdf": 56, 10136 "./format-hex": 57, 10137 "./hmac": 58, 10138 "./lib-typedarrays": 60, 10139 "./md5": 61, 10140 "./mode-cfb": 62, 10141 "./mode-ctr": 64, 10142 "./mode-ctr-gladman": 63, 10143 "./mode-ecb": 65, 10144 "./mode-ofb": 66, 10145 "./pad-ansix923": 67, 10146 "./pad-iso10126": 68, 10147 "./pad-iso97971": 69, 10148 "./pad-nopadding": 70, 10149 "./pad-zeropadding": 71, 10150 "./pbkdf2": 72, 10151 "./rabbit": 74, 10152 "./rabbit-legacy": 73, 10153 "./rc4": 75, 10154 "./ripemd160": 76, 10155 "./sha1": 77, 10156 "./sha224": 78, 10157 "./sha256": 79, 10158 "./sha3": 80, 10159 "./sha384": 81, 10160 "./sha512": 82, 10161 "./tripledes": 83, 10162 "./x64-core": 84, 10163 }, 10164 ], 10165 60: [ 10166 function (require, module, exports) { 10167 (function (root, factory) { 10168 if (typeof exports === "object") { 10169 // CommonJS 10170 module.exports = exports = factory(require("./core")); 10171 } else if (typeof define === "function" && define.amd) { 10172 // AMD 10173 define(["./core"], factory); 10174 } else { 10175 // Global (browser) 10176 factory(root.CryptoJS); 10177 } 10178 })(this, function (CryptoJS) { 10179 (function () { 10180 // Check if typed arrays are supported 10181 if (typeof ArrayBuffer != "function") { 10182 return; 10183 } 10184 10185 // Shortcuts 10186 var C = CryptoJS; 10187 var C_lib = C.lib; 10188 var WordArray = C_lib.WordArray; 10189 10190 // Reference original init 10191 var superInit = WordArray.init; 10192 10193 // Augment WordArray.init to handle typed arrays 10194 var subInit = (WordArray.init = function (typedArray) { 10195 // Convert buffers to uint8 10196 if (typedArray instanceof ArrayBuffer) { 10197 typedArray = new Uint8Array(typedArray); 10198 } 10199 10200 // Convert other array views to uint8 10201 if ( 10202 typedArray instanceof Int8Array || 10203 (typeof Uint8ClampedArray !== "undefined" && 10204 typedArray instanceof Uint8ClampedArray) || 10205 typedArray instanceof Int16Array || 10206 typedArray instanceof Uint16Array || 10207 typedArray instanceof Int32Array || 10208 typedArray instanceof Uint32Array || 10209 typedArray instanceof Float32Array || 10210 typedArray instanceof Float64Array 10211 ) { 10212 typedArray = new Uint8Array( 10213 typedArray.buffer, 10214 typedArray.byteOffset, 10215 typedArray.byteLength 10216 ); 10217 } 10218 10219 // Handle Uint8Array 10220 if (typedArray instanceof Uint8Array) { 10221 // Shortcut 10222 var typedArrayByteLength = typedArray.byteLength; 10223 10224 // Extract bytes 10225 var words = []; 10226 for (var i = 0; i < typedArrayByteLength; i++) { 10227 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 10228 } 10229 10230 // Initialize this word array 10231 superInit.call(this, words, typedArrayByteLength); 10232 } else { 10233 // Else call normal init 10234 superInit.apply(this, arguments); 10235 } 10236 }); 10237 10238 subInit.prototype = WordArray; 10239 })(); 10240 10241 return CryptoJS.lib.WordArray; 10242 }); 10243 }, 10244 { "./core": 53 }, 10245 ], 10246 61: [ 10247 function (require, module, exports) { 10248 (function (root, factory) { 10249 if (typeof exports === "object") { 10250 // CommonJS 10251 module.exports = exports = factory(require("./core")); 10252 } else if (typeof define === "function" && define.amd) { 10253 // AMD 10254 define(["./core"], factory); 10255 } else { 10256 // Global (browser) 10257 factory(root.CryptoJS); 10258 } 10259 })(this, function (CryptoJS) { 10260 (function (Math) { 10261 // Shortcuts 10262 var C = CryptoJS; 10263 var C_lib = C.lib; 10264 var WordArray = C_lib.WordArray; 10265 var Hasher = C_lib.Hasher; 10266 var C_algo = C.algo; 10267 10268 // Constants table 10269 var T = []; 10270 10271 // Compute constants 10272 (function () { 10273 for (var i = 0; i < 64; i++) { 10274 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 10275 } 10276 })(); 10277 10278 /** 10279 * MD5 hash algorithm. 10280 */ 10281 var MD5 = (C_algo.MD5 = Hasher.extend({ 10282 _doReset: function () { 10283 this._hash = new WordArray.init([ 10284 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 10285 ]); 10286 }, 10287 10288 _doProcessBlock: function (M, offset) { 10289 // Swap endian 10290 for (var i = 0; i < 16; i++) { 10291 // Shortcuts 10292 var offset_i = offset + i; 10293 var M_offset_i = M[offset_i]; 10294 10295 M[offset_i] = 10296 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10297 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00); 10298 } 10299 10300 // Shortcuts 10301 var H = this._hash.words; 10302 10303 var M_offset_0 = M[offset + 0]; 10304 var M_offset_1 = M[offset + 1]; 10305 var M_offset_2 = M[offset + 2]; 10306 var M_offset_3 = M[offset + 3]; 10307 var M_offset_4 = M[offset + 4]; 10308 var M_offset_5 = M[offset + 5]; 10309 var M_offset_6 = M[offset + 6]; 10310 var M_offset_7 = M[offset + 7]; 10311 var M_offset_8 = M[offset + 8]; 10312 var M_offset_9 = M[offset + 9]; 10313 var M_offset_10 = M[offset + 10]; 10314 var M_offset_11 = M[offset + 11]; 10315 var M_offset_12 = M[offset + 12]; 10316 var M_offset_13 = M[offset + 13]; 10317 var M_offset_14 = M[offset + 14]; 10318 var M_offset_15 = M[offset + 15]; 10319 10320 // Working varialbes 10321 var a = H[0]; 10322 var b = H[1]; 10323 var c = H[2]; 10324 var d = H[3]; 10325 10326 // Computation 10327 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 10328 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 10329 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 10330 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 10331 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 10332 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 10333 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 10334 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 10335 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 10336 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 10337 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 10338 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 10339 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 10340 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 10341 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 10342 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 10343 10344 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 10345 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 10346 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 10347 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 10348 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 10349 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 10350 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 10351 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 10352 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 10353 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 10354 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 10355 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 10356 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 10357 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 10358 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 10359 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 10360 10361 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 10362 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 10363 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 10364 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 10365 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 10366 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 10367 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 10368 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 10369 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 10370 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 10371 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 10372 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 10373 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 10374 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 10375 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 10376 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 10377 10378 a = II(a, b, c, d, M_offset_0, 6, T[48]); 10379 d = II(d, a, b, c, M_offset_7, 10, T[49]); 10380 c = II(c, d, a, b, M_offset_14, 15, T[50]); 10381 b = II(b, c, d, a, M_offset_5, 21, T[51]); 10382 a = II(a, b, c, d, M_offset_12, 6, T[52]); 10383 d = II(d, a, b, c, M_offset_3, 10, T[53]); 10384 c = II(c, d, a, b, M_offset_10, 15, T[54]); 10385 b = II(b, c, d, a, M_offset_1, 21, T[55]); 10386 a = II(a, b, c, d, M_offset_8, 6, T[56]); 10387 d = II(d, a, b, c, M_offset_15, 10, T[57]); 10388 c = II(c, d, a, b, M_offset_6, 15, T[58]); 10389 b = II(b, c, d, a, M_offset_13, 21, T[59]); 10390 a = II(a, b, c, d, M_offset_4, 6, T[60]); 10391 d = II(d, a, b, c, M_offset_11, 10, T[61]); 10392 c = II(c, d, a, b, M_offset_2, 15, T[62]); 10393 b = II(b, c, d, a, M_offset_9, 21, T[63]); 10394 10395 // Intermediate hash value 10396 H[0] = (H[0] + a) | 0; 10397 H[1] = (H[1] + b) | 0; 10398 H[2] = (H[2] + c) | 0; 10399 H[3] = (H[3] + d) | 0; 10400 }, 10401 10402 _doFinalize: function () { 10403 // Shortcuts 10404 var data = this._data; 10405 var dataWords = data.words; 10406 10407 var nBitsTotal = this._nDataBytes * 8; 10408 var nBitsLeft = data.sigBytes * 8; 10409 10410 // Add padding 10411 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 10412 10413 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 10414 var nBitsTotalL = nBitsTotal; 10415 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = 10416 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 10417 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00); 10418 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = 10419 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 10420 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00); 10421 10422 data.sigBytes = (dataWords.length + 1) * 4; 10423 10424 // Hash final blocks 10425 this._process(); 10426 10427 // Shortcuts 10428 var hash = this._hash; 10429 var H = hash.words; 10430 10431 // Swap endian 10432 for (var i = 0; i < 4; i++) { 10433 // Shortcut 10434 var H_i = H[i]; 10435 10436 H[i] = 10437 (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 10438 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 10439 } 10440 10441 // Return final computed hash 10442 return hash; 10443 }, 10444 10445 clone: function () { 10446 var clone = Hasher.clone.call(this); 10447 clone._hash = this._hash.clone(); 10448 10449 return clone; 10450 }, 10451 })); 10452 10453 function FF(a, b, c, d, x, s, t) { 10454 var n = a + ((b & c) | (~b & d)) + x + t; 10455 return ((n << s) | (n >>> (32 - s))) + b; 10456 } 10457 10458 function GG(a, b, c, d, x, s, t) { 10459 var n = a + ((b & d) | (c & ~d)) + x + t; 10460 return ((n << s) | (n >>> (32 - s))) + b; 10461 } 10462 10463 function HH(a, b, c, d, x, s, t) { 10464 var n = a + (b ^ c ^ d) + x + t; 10465 return ((n << s) | (n >>> (32 - s))) + b; 10466 } 10467 10468 function II(a, b, c, d, x, s, t) { 10469 var n = a + (c ^ (b | ~d)) + x + t; 10470 return ((n << s) | (n >>> (32 - s))) + b; 10471 } 10472 10473 /** 10474 * Shortcut function to the hasher's object interface. 10475 * 10476 * @param {WordArray|string} message The message to hash. 10477 * 10478 * @return {WordArray} The hash. 10479 * 10480 * @static 10481 * 10482 * @example 10483 * 10484 * var hash = CryptoJS.MD5('message'); 10485 * var hash = CryptoJS.MD5(wordArray); 10486 */ 10487 C.MD5 = Hasher._createHelper(MD5); 10488 10489 /** 10490 * Shortcut function to the HMAC's object interface. 10491 * 10492 * @param {WordArray|string} message The message to hash. 10493 * @param {WordArray|string} key The secret key. 10494 * 10495 * @return {WordArray} The HMAC. 10496 * 10497 * @static 10498 * 10499 * @example 10500 * 10501 * var hmac = CryptoJS.HmacMD5(message, key); 10502 */ 10503 C.HmacMD5 = Hasher._createHmacHelper(MD5); 10504 })(Math); 10505 10506 return CryptoJS.MD5; 10507 }); 10508 }, 10509 { "./core": 53 }, 10510 ], 10511 62: [ 10512 function (require, module, exports) { 10513 (function (root, factory, undef) { 10514 if (typeof exports === "object") { 10515 // CommonJS 10516 module.exports = exports = factory( 10517 require("./core"), 10518 require("./cipher-core") 10519 ); 10520 } else if (typeof define === "function" && define.amd) { 10521 // AMD 10522 define(["./core", "./cipher-core"], factory); 10523 } else { 10524 // Global (browser) 10525 factory(root.CryptoJS); 10526 } 10527 })(this, function (CryptoJS) { 10528 /** 10529 * Cipher Feedback block mode. 10530 */ 10531 CryptoJS.mode.CFB = (function () { 10532 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 10533 10534 CFB.Encryptor = CFB.extend({ 10535 processBlock: function (words, offset) { 10536 // Shortcuts 10537 var cipher = this._cipher; 10538 var blockSize = cipher.blockSize; 10539 10540 generateKeystreamAndEncrypt.call( 10541 this, 10542 words, 10543 offset, 10544 blockSize, 10545 cipher 10546 ); 10547 10548 // Remember this block to use with next block 10549 this._prevBlock = words.slice(offset, offset + blockSize); 10550 }, 10551 }); 10552 10553 CFB.Decryptor = CFB.extend({ 10554 processBlock: function (words, offset) { 10555 // Shortcuts 10556 var cipher = this._cipher; 10557 var blockSize = cipher.blockSize; 10558 10559 // Remember this block to use with next block 10560 var thisBlock = words.slice(offset, offset + blockSize); 10561 10562 generateKeystreamAndEncrypt.call( 10563 this, 10564 words, 10565 offset, 10566 blockSize, 10567 cipher 10568 ); 10569 10570 // This block becomes the previous block 10571 this._prevBlock = thisBlock; 10572 }, 10573 }); 10574 10575 function generateKeystreamAndEncrypt( 10576 words, 10577 offset, 10578 blockSize, 10579 cipher 10580 ) { 10581 // Shortcut 10582 var iv = this._iv; 10583 10584 // Generate keystream 10585 if (iv) { 10586 var keystream = iv.slice(0); 10587 10588 // Remove IV for subsequent blocks 10589 this._iv = undefined; 10590 } else { 10591 var keystream = this._prevBlock; 10592 } 10593 cipher.encryptBlock(keystream, 0); 10594 10595 // Encrypt 10596 for (var i = 0; i < blockSize; i++) { 10597 words[offset + i] ^= keystream[i]; 10598 } 10599 } 10600 10601 return CFB; 10602 })(); 10603 10604 return CryptoJS.mode.CFB; 10605 }); 10606 }, 10607 { "./cipher-core": 52, "./core": 53 }, 10608 ], 10609 63: [ 10610 function (require, module, exports) { 10611 (function (root, factory, undef) { 10612 if (typeof exports === "object") { 10613 // CommonJS 10614 module.exports = exports = factory( 10615 require("./core"), 10616 require("./cipher-core") 10617 ); 10618 } else if (typeof define === "function" && define.amd) { 10619 // AMD 10620 define(["./core", "./cipher-core"], factory); 10621 } else { 10622 // Global (browser) 10623 factory(root.CryptoJS); 10624 } 10625 })(this, function (CryptoJS) { 10626 /** @preserve 10627 * Counter block mode compatible with Dr Brian Gladman fileenc.c 10628 * derived from CryptoJS.mode.CTR 10629 * Jan Hruby jhruby.web@gmail.com 10630 */ 10631 CryptoJS.mode.CTRGladman = (function () { 10632 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 10633 10634 function incWord(word) { 10635 if (((word >> 24) & 0xff) === 0xff) { 10636 //overflow 10637 var b1 = (word >> 16) & 0xff; 10638 var b2 = (word >> 8) & 0xff; 10639 var b3 = word & 0xff; 10640 10641 if (b1 === 0xff) { 10642 // overflow b1 10643 b1 = 0; 10644 if (b2 === 0xff) { 10645 b2 = 0; 10646 if (b3 === 0xff) { 10647 b3 = 0; 10648 } else { 10649 ++b3; 10650 } 10651 } else { 10652 ++b2; 10653 } 10654 } else { 10655 ++b1; 10656 } 10657 10658 word = 0; 10659 word += b1 << 16; 10660 word += b2 << 8; 10661 word += b3; 10662 } else { 10663 word += 0x01 << 24; 10664 } 10665 return word; 10666 } 10667 10668 function incCounter(counter) { 10669 if ((counter[0] = incWord(counter[0])) === 0) { 10670 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 10671 counter[1] = incWord(counter[1]); 10672 } 10673 return counter; 10674 } 10675 10676 var Encryptor = (CTRGladman.Encryptor = CTRGladman.extend({ 10677 processBlock: function (words, offset) { 10678 // Shortcuts 10679 var cipher = this._cipher; 10680 var blockSize = cipher.blockSize; 10681 var iv = this._iv; 10682 var counter = this._counter; 10683 10684 // Generate keystream 10685 if (iv) { 10686 counter = this._counter = iv.slice(0); 10687 10688 // Remove IV for subsequent blocks 10689 this._iv = undefined; 10690 } 10691 10692 incCounter(counter); 10693 10694 var keystream = counter.slice(0); 10695 cipher.encryptBlock(keystream, 0); 10696 10697 // Encrypt 10698 for (var i = 0; i < blockSize; i++) { 10699 words[offset + i] ^= keystream[i]; 10700 } 10701 }, 10702 })); 10703 10704 CTRGladman.Decryptor = Encryptor; 10705 10706 return CTRGladman; 10707 })(); 10708 10709 return CryptoJS.mode.CTRGladman; 10710 }); 10711 }, 10712 { "./cipher-core": 52, "./core": 53 }, 10713 ], 10714 64: [ 10715 function (require, module, exports) { 10716 (function (root, factory, undef) { 10717 if (typeof exports === "object") { 10718 // CommonJS 10719 module.exports = exports = factory( 10720 require("./core"), 10721 require("./cipher-core") 10722 ); 10723 } else if (typeof define === "function" && define.amd) { 10724 // AMD 10725 define(["./core", "./cipher-core"], factory); 10726 } else { 10727 // Global (browser) 10728 factory(root.CryptoJS); 10729 } 10730 })(this, function (CryptoJS) { 10731 /** 10732 * Counter block mode. 10733 */ 10734 CryptoJS.mode.CTR = (function () { 10735 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 10736 10737 var Encryptor = (CTR.Encryptor = CTR.extend({ 10738 processBlock: function (words, offset) { 10739 // Shortcuts 10740 var cipher = this._cipher; 10741 var blockSize = cipher.blockSize; 10742 var iv = this._iv; 10743 var counter = this._counter; 10744 10745 // Generate keystream 10746 if (iv) { 10747 counter = this._counter = iv.slice(0); 10748 10749 // Remove IV for subsequent blocks 10750 this._iv = undefined; 10751 } 10752 var keystream = counter.slice(0); 10753 cipher.encryptBlock(keystream, 0); 10754 10755 // Increment counter 10756 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0; 10757 10758 // Encrypt 10759 for (var i = 0; i < blockSize; i++) { 10760 words[offset + i] ^= keystream[i]; 10761 } 10762 }, 10763 })); 10764 10765 CTR.Decryptor = Encryptor; 10766 10767 return CTR; 10768 })(); 10769 10770 return CryptoJS.mode.CTR; 10771 }); 10772 }, 10773 { "./cipher-core": 52, "./core": 53 }, 10774 ], 10775 65: [ 10776 function (require, module, exports) { 10777 (function (root, factory, undef) { 10778 if (typeof exports === "object") { 10779 // CommonJS 10780 module.exports = exports = factory( 10781 require("./core"), 10782 require("./cipher-core") 10783 ); 10784 } else if (typeof define === "function" && define.amd) { 10785 // AMD 10786 define(["./core", "./cipher-core"], factory); 10787 } else { 10788 // Global (browser) 10789 factory(root.CryptoJS); 10790 } 10791 })(this, function (CryptoJS) { 10792 /** 10793 * Electronic Codebook block mode. 10794 */ 10795 CryptoJS.mode.ECB = (function () { 10796 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 10797 10798 ECB.Encryptor = ECB.extend({ 10799 processBlock: function (words, offset) { 10800 this._cipher.encryptBlock(words, offset); 10801 }, 10802 }); 10803 10804 ECB.Decryptor = ECB.extend({ 10805 processBlock: function (words, offset) { 10806 this._cipher.decryptBlock(words, offset); 10807 }, 10808 }); 10809 10810 return ECB; 10811 })(); 10812 10813 return CryptoJS.mode.ECB; 10814 }); 10815 }, 10816 { "./cipher-core": 52, "./core": 53 }, 10817 ], 10818 66: [ 10819 function (require, module, exports) { 10820 (function (root, factory, undef) { 10821 if (typeof exports === "object") { 10822 // CommonJS 10823 module.exports = exports = factory( 10824 require("./core"), 10825 require("./cipher-core") 10826 ); 10827 } else if (typeof define === "function" && define.amd) { 10828 // AMD 10829 define(["./core", "./cipher-core"], factory); 10830 } else { 10831 // Global (browser) 10832 factory(root.CryptoJS); 10833 } 10834 })(this, function (CryptoJS) { 10835 /** 10836 * Output Feedback block mode. 10837 */ 10838 CryptoJS.mode.OFB = (function () { 10839 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 10840 10841 var Encryptor = (OFB.Encryptor = OFB.extend({ 10842 processBlock: function (words, offset) { 10843 // Shortcuts 10844 var cipher = this._cipher; 10845 var blockSize = cipher.blockSize; 10846 var iv = this._iv; 10847 var keystream = this._keystream; 10848 10849 // Generate keystream 10850 if (iv) { 10851 keystream = this._keystream = iv.slice(0); 10852 10853 // Remove IV for subsequent blocks 10854 this._iv = undefined; 10855 } 10856 cipher.encryptBlock(keystream, 0); 10857 10858 // Encrypt 10859 for (var i = 0; i < blockSize; i++) { 10860 words[offset + i] ^= keystream[i]; 10861 } 10862 }, 10863 })); 10864 10865 OFB.Decryptor = Encryptor; 10866 10867 return OFB; 10868 })(); 10869 10870 return CryptoJS.mode.OFB; 10871 }); 10872 }, 10873 { "./cipher-core": 52, "./core": 53 }, 10874 ], 10875 67: [ 10876 function (require, module, exports) { 10877 (function (root, factory, undef) { 10878 if (typeof exports === "object") { 10879 // CommonJS 10880 module.exports = exports = factory( 10881 require("./core"), 10882 require("./cipher-core") 10883 ); 10884 } else if (typeof define === "function" && define.amd) { 10885 // AMD 10886 define(["./core", "./cipher-core"], factory); 10887 } else { 10888 // Global (browser) 10889 factory(root.CryptoJS); 10890 } 10891 })(this, function (CryptoJS) { 10892 /** 10893 * ANSI X.923 padding strategy. 10894 */ 10895 CryptoJS.pad.AnsiX923 = { 10896 pad: function (data, blockSize) { 10897 // Shortcuts 10898 var dataSigBytes = data.sigBytes; 10899 var blockSizeBytes = blockSize * 4; 10900 10901 // Count padding bytes 10902 var nPaddingBytes = 10903 blockSizeBytes - (dataSigBytes % blockSizeBytes); 10904 10905 // Compute last byte position 10906 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10907 10908 // Pad 10909 data.clamp(); 10910 data.words[lastBytePos >>> 2] |= 10911 nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10912 data.sigBytes += nPaddingBytes; 10913 }, 10914 10915 unpad: function (data) { 10916 // Get number of padding bytes from last byte 10917 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10918 10919 // Remove padding 10920 data.sigBytes -= nPaddingBytes; 10921 }, 10922 }; 10923 10924 return CryptoJS.pad.Ansix923; 10925 }); 10926 }, 10927 { "./cipher-core": 52, "./core": 53 }, 10928 ], 10929 68: [ 10930 function (require, module, exports) { 10931 (function (root, factory, undef) { 10932 if (typeof exports === "object") { 10933 // CommonJS 10934 module.exports = exports = factory( 10935 require("./core"), 10936 require("./cipher-core") 10937 ); 10938 } else if (typeof define === "function" && define.amd) { 10939 // AMD 10940 define(["./core", "./cipher-core"], factory); 10941 } else { 10942 // Global (browser) 10943 factory(root.CryptoJS); 10944 } 10945 })(this, function (CryptoJS) { 10946 /** 10947 * ISO 10126 padding strategy. 10948 */ 10949 CryptoJS.pad.Iso10126 = { 10950 pad: function (data, blockSize) { 10951 // Shortcut 10952 var blockSizeBytes = blockSize * 4; 10953 10954 // Count padding bytes 10955 var nPaddingBytes = 10956 blockSizeBytes - (data.sigBytes % blockSizeBytes); 10957 10958 // Pad 10959 data 10960 .concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)) 10961 .concat( 10962 CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1) 10963 ); 10964 }, 10965 10966 unpad: function (data) { 10967 // Get number of padding bytes from last byte 10968 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10969 10970 // Remove padding 10971 data.sigBytes -= nPaddingBytes; 10972 }, 10973 }; 10974 10975 return CryptoJS.pad.Iso10126; 10976 }); 10977 }, 10978 { "./cipher-core": 52, "./core": 53 }, 10979 ], 10980 69: [ 10981 function (require, module, exports) { 10982 (function (root, factory, undef) { 10983 if (typeof exports === "object") { 10984 // CommonJS 10985 module.exports = exports = factory( 10986 require("./core"), 10987 require("./cipher-core") 10988 ); 10989 } else if (typeof define === "function" && define.amd) { 10990 // AMD 10991 define(["./core", "./cipher-core"], factory); 10992 } else { 10993 // Global (browser) 10994 factory(root.CryptoJS); 10995 } 10996 })(this, function (CryptoJS) { 10997 /** 10998 * ISO/IEC 9797-1 Padding Method 2. 10999 */ 11000 CryptoJS.pad.Iso97971 = { 11001 pad: function (data, blockSize) { 11002 // Add 0x80 byte 11003 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 11004 11005 // Zero pad the rest 11006 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 11007 }, 11008 11009 unpad: function (data) { 11010 // Remove zero padding 11011 CryptoJS.pad.ZeroPadding.unpad(data); 11012 11013 // Remove one more byte -- the 0x80 byte 11014 data.sigBytes--; 11015 }, 11016 }; 11017 11018 return CryptoJS.pad.Iso97971; 11019 }); 11020 }, 11021 { "./cipher-core": 52, "./core": 53 }, 11022 ], 11023 70: [ 11024 function (require, module, exports) { 11025 (function (root, factory, undef) { 11026 if (typeof exports === "object") { 11027 // CommonJS 11028 module.exports = exports = factory( 11029 require("./core"), 11030 require("./cipher-core") 11031 ); 11032 } else if (typeof define === "function" && define.amd) { 11033 // AMD 11034 define(["./core", "./cipher-core"], factory); 11035 } else { 11036 // Global (browser) 11037 factory(root.CryptoJS); 11038 } 11039 })(this, function (CryptoJS) { 11040 /** 11041 * A noop padding strategy. 11042 */ 11043 CryptoJS.pad.NoPadding = { 11044 pad: function () {}, 11045 11046 unpad: function () {}, 11047 }; 11048 11049 return CryptoJS.pad.NoPadding; 11050 }); 11051 }, 11052 { "./cipher-core": 52, "./core": 53 }, 11053 ], 11054 71: [ 11055 function (require, module, exports) { 11056 (function (root, factory, undef) { 11057 if (typeof exports === "object") { 11058 // CommonJS 11059 module.exports = exports = factory( 11060 require("./core"), 11061 require("./cipher-core") 11062 ); 11063 } else if (typeof define === "function" && define.amd) { 11064 // AMD 11065 define(["./core", "./cipher-core"], factory); 11066 } else { 11067 // Global (browser) 11068 factory(root.CryptoJS); 11069 } 11070 })(this, function (CryptoJS) { 11071 /** 11072 * Zero padding strategy. 11073 */ 11074 CryptoJS.pad.ZeroPadding = { 11075 pad: function (data, blockSize) { 11076 // Shortcut 11077 var blockSizeBytes = blockSize * 4; 11078 11079 // Pad 11080 data.clamp(); 11081 data.sigBytes += 11082 blockSizeBytes - 11083 (data.sigBytes % blockSizeBytes || blockSizeBytes); 11084 }, 11085 11086 unpad: function (data) { 11087 // Shortcut 11088 var dataWords = data.words; 11089 11090 // Unpad 11091 var i = data.sigBytes - 1; 11092 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 11093 i--; 11094 } 11095 data.sigBytes = i + 1; 11096 }, 11097 }; 11098 11099 return CryptoJS.pad.ZeroPadding; 11100 }); 11101 }, 11102 { "./cipher-core": 52, "./core": 53 }, 11103 ], 11104 72: [ 11105 function (require, module, exports) { 11106 (function (root, factory, undef) { 11107 if (typeof exports === "object") { 11108 // CommonJS 11109 module.exports = exports = factory( 11110 require("./core"), 11111 require("./sha1"), 11112 require("./hmac") 11113 ); 11114 } else if (typeof define === "function" && define.amd) { 11115 // AMD 11116 define(["./core", "./sha1", "./hmac"], factory); 11117 } else { 11118 // Global (browser) 11119 factory(root.CryptoJS); 11120 } 11121 })(this, function (CryptoJS) { 11122 (function () { 11123 // Shortcuts 11124 var C = CryptoJS; 11125 var C_lib = C.lib; 11126 var Base = C_lib.Base; 11127 var WordArray = C_lib.WordArray; 11128 var C_algo = C.algo; 11129 var SHA1 = C_algo.SHA1; 11130 var HMAC = C_algo.HMAC; 11131 11132 /** 11133 * Password-Based Key Derivation Function 2 algorithm. 11134 */ 11135 var PBKDF2 = (C_algo.PBKDF2 = Base.extend({ 11136 /** 11137 * Configuration options. 11138 * 11139 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 11140 * @property {Hasher} hasher The hasher to use. Default: SHA1 11141 * @property {number} iterations The number of iterations to perform. Default: 1 11142 */ 11143 cfg: Base.extend({ 11144 keySize: 128 / 32, 11145 hasher: SHA1, 11146 iterations: 1, 11147 }), 11148 11149 /** 11150 * Initializes a newly created key derivation function. 11151 * 11152 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 11153 * 11154 * @example 11155 * 11156 * var kdf = CryptoJS.algo.PBKDF2.create(); 11157 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 11158 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 11159 */ 11160 init: function (cfg) { 11161 this.cfg = this.cfg.extend(cfg); 11162 }, 11163 11164 /** 11165 * Computes the Password-Based Key Derivation Function 2. 11166 * 11167 * @param {WordArray|string} password The password. 11168 * @param {WordArray|string} salt A salt. 11169 * 11170 * @return {WordArray} The derived key. 11171 * 11172 * @example 11173 * 11174 * var key = kdf.compute(password, salt); 11175 */ 11176 compute: function (password, salt) { 11177 // Shortcut 11178 var cfg = this.cfg; 11179 11180 // Init HMAC 11181 var hmac = HMAC.create(cfg.hasher, password); 11182 11183 // Initial values 11184 var derivedKey = WordArray.create(); 11185 var blockIndex = WordArray.create([0x00000001]); 11186 11187 // Shortcuts 11188 var derivedKeyWords = derivedKey.words; 11189 var blockIndexWords = blockIndex.words; 11190 var keySize = cfg.keySize; 11191 var iterations = cfg.iterations; 11192 11193 // Generate key 11194 while (derivedKeyWords.length < keySize) { 11195 var block = hmac.update(salt).finalize(blockIndex); 11196 hmac.reset(); 11197 11198 // Shortcuts 11199 var blockWords = block.words; 11200 var blockWordsLength = blockWords.length; 11201 11202 // Iterations 11203 var intermediate = block; 11204 for (var i = 1; i < iterations; i++) { 11205 intermediate = hmac.finalize(intermediate); 11206 hmac.reset(); 11207 11208 // Shortcut 11209 var intermediateWords = intermediate.words; 11210 11211 // XOR intermediate with block 11212 for (var j = 0; j < blockWordsLength; j++) { 11213 blockWords[j] ^= intermediateWords[j]; 11214 } 11215 } 11216 11217 derivedKey.concat(block); 11218 blockIndexWords[0]++; 11219 } 11220 derivedKey.sigBytes = keySize * 4; 11221 11222 return derivedKey; 11223 }, 11224 })); 11225 11226 /** 11227 * Computes the Password-Based Key Derivation Function 2. 11228 * 11229 * @param {WordArray|string} password The password. 11230 * @param {WordArray|string} salt A salt. 11231 * @param {Object} cfg (Optional) The configuration options to use for this computation. 11232 * 11233 * @return {WordArray} The derived key. 11234 * 11235 * @static 11236 * 11237 * @example 11238 * 11239 * var key = CryptoJS.PBKDF2(password, salt); 11240 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 11241 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 11242 */ 11243 C.PBKDF2 = function (password, salt, cfg) { 11244 return PBKDF2.create(cfg).compute(password, salt); 11245 }; 11246 })(); 11247 11248 return CryptoJS.PBKDF2; 11249 }); 11250 }, 11251 { "./core": 53, "./hmac": 58, "./sha1": 77 }, 11252 ], 11253 73: [ 11254 function (require, module, exports) { 11255 (function (root, factory, undef) { 11256 if (typeof exports === "object") { 11257 // CommonJS 11258 module.exports = exports = factory( 11259 require("./core"), 11260 require("./enc-base64"), 11261 require("./md5"), 11262 require("./evpkdf"), 11263 require("./cipher-core") 11264 ); 11265 } else if (typeof define === "function" && define.amd) { 11266 // AMD 11267 define([ 11268 "./core", 11269 "./enc-base64", 11270 "./md5", 11271 "./evpkdf", 11272 "./cipher-core", 11273 ], factory); 11274 } else { 11275 // Global (browser) 11276 factory(root.CryptoJS); 11277 } 11278 })(this, function (CryptoJS) { 11279 (function () { 11280 // Shortcuts 11281 var C = CryptoJS; 11282 var C_lib = C.lib; 11283 var StreamCipher = C_lib.StreamCipher; 11284 var C_algo = C.algo; 11285 11286 // Reusable objects 11287 var S = []; 11288 var C_ = []; 11289 var G = []; 11290 11291 /** 11292 * Rabbit stream cipher algorithm. 11293 * 11294 * This is a legacy version that neglected to convert the key to little-endian. 11295 * This error doesn't affect the cipher's security, 11296 * but it does affect its compatibility with other implementations. 11297 */ 11298 var RabbitLegacy = (C_algo.RabbitLegacy = StreamCipher.extend({ 11299 _doReset: function () { 11300 // Shortcuts 11301 var K = this._key.words; 11302 var iv = this.cfg.iv; 11303 11304 // Generate initial state values 11305 var X = (this._X = [ 11306 K[0], 11307 (K[3] << 16) | (K[2] >>> 16), 11308 K[1], 11309 (K[0] << 16) | (K[3] >>> 16), 11310 K[2], 11311 (K[1] << 16) | (K[0] >>> 16), 11312 K[3], 11313 (K[2] << 16) | (K[1] >>> 16), 11314 ]); 11315 11316 // Generate initial counter values 11317 var C = (this._C = [ 11318 (K[2] << 16) | (K[2] >>> 16), 11319 (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 11320 (K[3] << 16) | (K[3] >>> 16), 11321 (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 11322 (K[0] << 16) | (K[0] >>> 16), 11323 (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 11324 (K[1] << 16) | (K[1] >>> 16), 11325 (K[3] & 0xffff0000) | (K[0] & 0x0000ffff), 11326 ]); 11327 11328 // Carry bit 11329 this._b = 0; 11330 11331 // Iterate the system four times 11332 for (var i = 0; i < 4; i++) { 11333 nextState.call(this); 11334 } 11335 11336 // Modify the counters 11337 for (var i = 0; i < 8; i++) { 11338 C[i] ^= X[(i + 4) & 7]; 11339 } 11340 11341 // IV setup 11342 if (iv) { 11343 // Shortcuts 11344 var IV = iv.words; 11345 var IV_0 = IV[0]; 11346 var IV_1 = IV[1]; 11347 11348 // Generate four subvectors 11349 var i0 = 11350 (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | 11351 (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 11352 var i2 = 11353 (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | 11354 (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 11355 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 11356 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 11357 11358 // Modify counter values 11359 C[0] ^= i0; 11360 C[1] ^= i1; 11361 C[2] ^= i2; 11362 C[3] ^= i3; 11363 C[4] ^= i0; 11364 C[5] ^= i1; 11365 C[6] ^= i2; 11366 C[7] ^= i3; 11367 11368 // Iterate the system four times 11369 for (var i = 0; i < 4; i++) { 11370 nextState.call(this); 11371 } 11372 } 11373 }, 11374 11375 _doProcessBlock: function (M, offset) { 11376 // Shortcut 11377 var X = this._X; 11378 11379 // Iterate the system 11380 nextState.call(this); 11381 11382 // Generate four keystream words 11383 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 11384 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 11385 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 11386 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 11387 11388 for (var i = 0; i < 4; i++) { 11389 // Swap endian 11390 S[i] = 11391 (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 11392 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 11393 11394 // Encrypt 11395 M[offset + i] ^= S[i]; 11396 } 11397 }, 11398 11399 blockSize: 128 / 32, 11400 11401 ivSize: 64 / 32, 11402 })); 11403 11404 function nextState() { 11405 // Shortcuts 11406 var X = this._X; 11407 var C = this._C; 11408 11409 // Save old counter values 11410 for (var i = 0; i < 8; i++) { 11411 C_[i] = C[i]; 11412 } 11413 11414 // Calculate new counter values 11415 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 11416 C[1] = 11417 (C[1] + 0xd34d34d3 + (C[0] >>> 0 < C_[0] >>> 0 ? 1 : 0)) | 0; 11418 C[2] = 11419 (C[2] + 0x34d34d34 + (C[1] >>> 0 < C_[1] >>> 0 ? 1 : 0)) | 0; 11420 C[3] = 11421 (C[3] + 0x4d34d34d + (C[2] >>> 0 < C_[2] >>> 0 ? 1 : 0)) | 0; 11422 C[4] = 11423 (C[4] + 0xd34d34d3 + (C[3] >>> 0 < C_[3] >>> 0 ? 1 : 0)) | 0; 11424 C[5] = 11425 (C[5] + 0x34d34d34 + (C[4] >>> 0 < C_[4] >>> 0 ? 1 : 0)) | 0; 11426 C[6] = 11427 (C[6] + 0x4d34d34d + (C[5] >>> 0 < C_[5] >>> 0 ? 1 : 0)) | 0; 11428 C[7] = 11429 (C[7] + 0xd34d34d3 + (C[6] >>> 0 < C_[6] >>> 0 ? 1 : 0)) | 0; 11430 this._b = C[7] >>> 0 < C_[7] >>> 0 ? 1 : 0; 11431 11432 // Calculate the g-values 11433 for (var i = 0; i < 8; i++) { 11434 var gx = X[i] + C[i]; 11435 11436 // Construct high and low argument for squaring 11437 var ga = gx & 0xffff; 11438 var gb = gx >>> 16; 11439 11440 // Calculate high and low result of squaring 11441 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 11442 var gl = 11443 (((gx & 0xffff0000) * gx) | 0) + 11444 (((gx & 0x0000ffff) * gx) | 0); 11445 11446 // High XOR low 11447 G[i] = gh ^ gl; 11448 } 11449 11450 // Calculate new state values 11451 X[0] = 11452 (G[0] + 11453 ((G[7] << 16) | (G[7] >>> 16)) + 11454 ((G[6] << 16) | (G[6] >>> 16))) | 11455 0; 11456 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 11457 X[2] = 11458 (G[2] + 11459 ((G[1] << 16) | (G[1] >>> 16)) + 11460 ((G[0] << 16) | (G[0] >>> 16))) | 11461 0; 11462 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 11463 X[4] = 11464 (G[4] + 11465 ((G[3] << 16) | (G[3] >>> 16)) + 11466 ((G[2] << 16) | (G[2] >>> 16))) | 11467 0; 11468 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 11469 X[6] = 11470 (G[6] + 11471 ((G[5] << 16) | (G[5] >>> 16)) + 11472 ((G[4] << 16) | (G[4] >>> 16))) | 11473 0; 11474 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 11475 } 11476 11477 /** 11478 * Shortcut functions to the cipher's object interface. 11479 * 11480 * @example 11481 * 11482 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 11483 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 11484 */ 11485 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 11486 })(); 11487 11488 return CryptoJS.RabbitLegacy; 11489 }); 11490 }, 11491 { 11492 "./cipher-core": 52, 11493 "./core": 53, 11494 "./enc-base64": 54, 11495 "./evpkdf": 56, 11496 "./md5": 61, 11497 }, 11498 ], 11499 74: [ 11500 function (require, module, exports) { 11501 (function (root, factory, undef) { 11502 if (typeof exports === "object") { 11503 // CommonJS 11504 module.exports = exports = factory( 11505 require("./core"), 11506 require("./enc-base64"), 11507 require("./md5"), 11508 require("./evpkdf"), 11509 require("./cipher-core") 11510 ); 11511 } else if (typeof define === "function" && define.amd) { 11512 // AMD 11513 define([ 11514 "./core", 11515 "./enc-base64", 11516 "./md5", 11517 "./evpkdf", 11518 "./cipher-core", 11519 ], factory); 11520 } else { 11521 // Global (browser) 11522 factory(root.CryptoJS); 11523 } 11524 })(this, function (CryptoJS) { 11525 (function () { 11526 // Shortcuts 11527 var C = CryptoJS; 11528 var C_lib = C.lib; 11529 var StreamCipher = C_lib.StreamCipher; 11530 var C_algo = C.algo; 11531 11532 // Reusable objects 11533 var S = []; 11534 var C_ = []; 11535 var G = []; 11536 11537 /** 11538 * Rabbit stream cipher algorithm 11539 */ 11540 var Rabbit = (C_algo.Rabbit = StreamCipher.extend({ 11541 _doReset: function () { 11542 // Shortcuts 11543 var K = this._key.words; 11544 var iv = this.cfg.iv; 11545 11546 // Swap endian 11547 for (var i = 0; i < 4; i++) { 11548 K[i] = 11549 (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 11550 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 11551 } 11552 11553 // Generate initial state values 11554 var X = (this._X = [ 11555 K[0], 11556 (K[3] << 16) | (K[2] >>> 16), 11557 K[1], 11558 (K[0] << 16) | (K[3] >>> 16), 11559 K[2], 11560 (K[1] << 16) | (K[0] >>> 16), 11561 K[3], 11562 (K[2] << 16) | (K[1] >>> 16), 11563 ]); 11564 11565 // Generate initial counter values 11566 var C = (this._C = [ 11567 (K[2] << 16) | (K[2] >>> 16), 11568 (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 11569 (K[3] << 16) | (K[3] >>> 16), 11570 (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 11571 (K[0] << 16) | (K[0] >>> 16), 11572 (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 11573 (K[1] << 16) | (K[1] >>> 16), 11574 (K[3] & 0xffff0000) | (K[0] & 0x0000ffff), 11575 ]); 11576 11577 // Carry bit 11578 this._b = 0; 11579 11580 // Iterate the system four times 11581 for (var i = 0; i < 4; i++) { 11582 nextState.call(this); 11583 } 11584 11585 // Modify the counters 11586 for (var i = 0; i < 8; i++) { 11587 C[i] ^= X[(i + 4) & 7]; 11588 } 11589 11590 // IV setup 11591 if (iv) { 11592 // Shortcuts 11593 var IV = iv.words; 11594 var IV_0 = IV[0]; 11595 var IV_1 = IV[1]; 11596 11597 // Generate four subvectors 11598 var i0 = 11599 (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | 11600 (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 11601 var i2 = 11602 (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | 11603 (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 11604 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 11605 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 11606 11607 // Modify counter values 11608 C[0] ^= i0; 11609 C[1] ^= i1; 11610 C[2] ^= i2; 11611 C[3] ^= i3; 11612 C[4] ^= i0; 11613 C[5] ^= i1; 11614 C[6] ^= i2; 11615 C[7] ^= i3; 11616 11617 // Iterate the system four times 11618 for (var i = 0; i < 4; i++) { 11619 nextState.call(this); 11620 } 11621 } 11622 }, 11623 11624 _doProcessBlock: function (M, offset) { 11625 // Shortcut 11626 var X = this._X; 11627 11628 // Iterate the system 11629 nextState.call(this); 11630 11631 // Generate four keystream words 11632 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 11633 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 11634 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 11635 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 11636 11637 for (var i = 0; i < 4; i++) { 11638 // Swap endian 11639 S[i] = 11640 (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 11641 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 11642 11643 // Encrypt 11644 M[offset + i] ^= S[i]; 11645 } 11646 }, 11647 11648 blockSize: 128 / 32, 11649 11650 ivSize: 64 / 32, 11651 })); 11652 11653 function nextState() { 11654 // Shortcuts 11655 var X = this._X; 11656 var C = this._C; 11657 11658 // Save old counter values 11659 for (var i = 0; i < 8; i++) { 11660 C_[i] = C[i]; 11661 } 11662 11663 // Calculate new counter values 11664 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 11665 C[1] = 11666 (C[1] + 0xd34d34d3 + (C[0] >>> 0 < C_[0] >>> 0 ? 1 : 0)) | 0; 11667 C[2] = 11668 (C[2] + 0x34d34d34 + (C[1] >>> 0 < C_[1] >>> 0 ? 1 : 0)) | 0; 11669 C[3] = 11670 (C[3] + 0x4d34d34d + (C[2] >>> 0 < C_[2] >>> 0 ? 1 : 0)) | 0; 11671 C[4] = 11672 (C[4] + 0xd34d34d3 + (C[3] >>> 0 < C_[3] >>> 0 ? 1 : 0)) | 0; 11673 C[5] = 11674 (C[5] + 0x34d34d34 + (C[4] >>> 0 < C_[4] >>> 0 ? 1 : 0)) | 0; 11675 C[6] = 11676 (C[6] + 0x4d34d34d + (C[5] >>> 0 < C_[5] >>> 0 ? 1 : 0)) | 0; 11677 C[7] = 11678 (C[7] + 0xd34d34d3 + (C[6] >>> 0 < C_[6] >>> 0 ? 1 : 0)) | 0; 11679 this._b = C[7] >>> 0 < C_[7] >>> 0 ? 1 : 0; 11680 11681 // Calculate the g-values 11682 for (var i = 0; i < 8; i++) { 11683 var gx = X[i] + C[i]; 11684 11685 // Construct high and low argument for squaring 11686 var ga = gx & 0xffff; 11687 var gb = gx >>> 16; 11688 11689 // Calculate high and low result of squaring 11690 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 11691 var gl = 11692 (((gx & 0xffff0000) * gx) | 0) + 11693 (((gx & 0x0000ffff) * gx) | 0); 11694 11695 // High XOR low 11696 G[i] = gh ^ gl; 11697 } 11698 11699 // Calculate new state values 11700 X[0] = 11701 (G[0] + 11702 ((G[7] << 16) | (G[7] >>> 16)) + 11703 ((G[6] << 16) | (G[6] >>> 16))) | 11704 0; 11705 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 11706 X[2] = 11707 (G[2] + 11708 ((G[1] << 16) | (G[1] >>> 16)) + 11709 ((G[0] << 16) | (G[0] >>> 16))) | 11710 0; 11711 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 11712 X[4] = 11713 (G[4] + 11714 ((G[3] << 16) | (G[3] >>> 16)) + 11715 ((G[2] << 16) | (G[2] >>> 16))) | 11716 0; 11717 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 11718 X[6] = 11719 (G[6] + 11720 ((G[5] << 16) | (G[5] >>> 16)) + 11721 ((G[4] << 16) | (G[4] >>> 16))) | 11722 0; 11723 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 11724 } 11725 11726 /** 11727 * Shortcut functions to the cipher's object interface. 11728 * 11729 * @example 11730 * 11731 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 11732 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 11733 */ 11734 C.Rabbit = StreamCipher._createHelper(Rabbit); 11735 })(); 11736 11737 return CryptoJS.Rabbit; 11738 }); 11739 }, 11740 { 11741 "./cipher-core": 52, 11742 "./core": 53, 11743 "./enc-base64": 54, 11744 "./evpkdf": 56, 11745 "./md5": 61, 11746 }, 11747 ], 11748 75: [ 11749 function (require, module, exports) { 11750 (function (root, factory, undef) { 11751 if (typeof exports === "object") { 11752 // CommonJS 11753 module.exports = exports = factory( 11754 require("./core"), 11755 require("./enc-base64"), 11756 require("./md5"), 11757 require("./evpkdf"), 11758 require("./cipher-core") 11759 ); 11760 } else if (typeof define === "function" && define.amd) { 11761 // AMD 11762 define([ 11763 "./core", 11764 "./enc-base64", 11765 "./md5", 11766 "./evpkdf", 11767 "./cipher-core", 11768 ], factory); 11769 } else { 11770 // Global (browser) 11771 factory(root.CryptoJS); 11772 } 11773 })(this, function (CryptoJS) { 11774 (function () { 11775 // Shortcuts 11776 var C = CryptoJS; 11777 var C_lib = C.lib; 11778 var StreamCipher = C_lib.StreamCipher; 11779 var C_algo = C.algo; 11780 11781 /** 11782 * RC4 stream cipher algorithm. 11783 */ 11784 var RC4 = (C_algo.RC4 = StreamCipher.extend({ 11785 _doReset: function () { 11786 // Shortcuts 11787 var key = this._key; 11788 var keyWords = key.words; 11789 var keySigBytes = key.sigBytes; 11790 11791 // Init sbox 11792 var S = (this._S = []); 11793 for (var i = 0; i < 256; i++) { 11794 S[i] = i; 11795 } 11796 11797 // Key setup 11798 for (var i = 0, j = 0; i < 256; i++) { 11799 var keyByteIndex = i % keySigBytes; 11800 var keyByte = 11801 (keyWords[keyByteIndex >>> 2] >>> 11802 (24 - (keyByteIndex % 4) * 8)) & 11803 0xff; 11804 11805 j = (j + S[i] + keyByte) % 256; 11806 11807 // Swap 11808 var t = S[i]; 11809 S[i] = S[j]; 11810 S[j] = t; 11811 } 11812 11813 // Counters 11814 this._i = this._j = 0; 11815 }, 11816 11817 _doProcessBlock: function (M, offset) { 11818 M[offset] ^= generateKeystreamWord.call(this); 11819 }, 11820 11821 keySize: 256 / 32, 11822 11823 ivSize: 0, 11824 })); 11825 11826 function generateKeystreamWord() { 11827 // Shortcuts 11828 var S = this._S; 11829 var i = this._i; 11830 var j = this._j; 11831 11832 // Generate keystream word 11833 var keystreamWord = 0; 11834 for (var n = 0; n < 4; n++) { 11835 i = (i + 1) % 256; 11836 j = (j + S[i]) % 256; 11837 11838 // Swap 11839 var t = S[i]; 11840 S[i] = S[j]; 11841 S[j] = t; 11842 11843 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 11844 } 11845 11846 // Update counters 11847 this._i = i; 11848 this._j = j; 11849 11850 return keystreamWord; 11851 } 11852 11853 /** 11854 * Shortcut functions to the cipher's object interface. 11855 * 11856 * @example 11857 * 11858 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 11859 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 11860 */ 11861 C.RC4 = StreamCipher._createHelper(RC4); 11862 11863 /** 11864 * Modified RC4 stream cipher algorithm. 11865 */ 11866 var RC4Drop = (C_algo.RC4Drop = RC4.extend({ 11867 /** 11868 * Configuration options. 11869 * 11870 * @property {number} drop The number of keystream words to drop. Default 192 11871 */ 11872 cfg: RC4.cfg.extend({ 11873 drop: 192, 11874 }), 11875 11876 _doReset: function () { 11877 RC4._doReset.call(this); 11878 11879 // Drop 11880 for (var i = this.cfg.drop; i > 0; i--) { 11881 generateKeystreamWord.call(this); 11882 } 11883 }, 11884 })); 11885 11886 /** 11887 * Shortcut functions to the cipher's object interface. 11888 * 11889 * @example 11890 * 11891 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 11892 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 11893 */ 11894 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 11895 })(); 11896 11897 return CryptoJS.RC4; 11898 }); 11899 }, 11900 { 11901 "./cipher-core": 52, 11902 "./core": 53, 11903 "./enc-base64": 54, 11904 "./evpkdf": 56, 11905 "./md5": 61, 11906 }, 11907 ], 11908 76: [ 11909 function (require, module, exports) { 11910 (function (root, factory) { 11911 if (typeof exports === "object") { 11912 // CommonJS 11913 module.exports = exports = factory(require("./core")); 11914 } else if (typeof define === "function" && define.amd) { 11915 // AMD 11916 define(["./core"], factory); 11917 } else { 11918 // Global (browser) 11919 factory(root.CryptoJS); 11920 } 11921 })(this, function (CryptoJS) { 11922 /** @preserve 11923 (c) 2012 by Cédric Mesnil. All rights reserved. 11924 11925 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 11926 11927 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11928 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11929 11930 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11931 */ 11932 11933 (function (Math) { 11934 // Shortcuts 11935 var C = CryptoJS; 11936 var C_lib = C.lib; 11937 var WordArray = C_lib.WordArray; 11938 var Hasher = C_lib.Hasher; 11939 var C_algo = C.algo; 11940 11941 // Constants table 11942 var _zl = WordArray.create([ 11943 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 11944 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 11945 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 11946 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 11947 13, 11948 ]); 11949 var _zr = WordArray.create([ 11950 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 11951 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11952 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 11953 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 11954 9, 11, 11955 ]); 11956 var _sl = WordArray.create([ 11957 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 11958 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 11959 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 11960 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 11961 13, 14, 11, 8, 5, 6, 11962 ]); 11963 var _sr = WordArray.create([ 11964 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 11965 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 11966 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 11967 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 11968 15, 13, 11, 11, 11969 ]); 11970 11971 var _hl = WordArray.create([ 11972 0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e, 11973 ]); 11974 var _hr = WordArray.create([ 11975 0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000, 11976 ]); 11977 11978 /** 11979 * RIPEMD160 hash algorithm. 11980 */ 11981 var RIPEMD160 = (C_algo.RIPEMD160 = Hasher.extend({ 11982 _doReset: function () { 11983 this._hash = WordArray.create([ 11984 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, 11985 ]); 11986 }, 11987 11988 _doProcessBlock: function (M, offset) { 11989 // Swap endian 11990 for (var i = 0; i < 16; i++) { 11991 // Shortcuts 11992 var offset_i = offset + i; 11993 var M_offset_i = M[offset_i]; 11994 11995 // Swap 11996 M[offset_i] = 11997 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 11998 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00); 11999 } 12000 // Shortcut 12001 var H = this._hash.words; 12002 var hl = _hl.words; 12003 var hr = _hr.words; 12004 var zl = _zl.words; 12005 var zr = _zr.words; 12006 var sl = _sl.words; 12007 var sr = _sr.words; 12008 12009 // Working variables 12010 var al, bl, cl, dl, el; 12011 var ar, br, cr, dr, er; 12012 12013 ar = al = H[0]; 12014 br = bl = H[1]; 12015 cr = cl = H[2]; 12016 dr = dl = H[3]; 12017 er = el = H[4]; 12018 // Computation 12019 var t; 12020 for (var i = 0; i < 80; i += 1) { 12021 t = (al + M[offset + zl[i]]) | 0; 12022 if (i < 16) { 12023 t += f1(bl, cl, dl) + hl[0]; 12024 } else if (i < 32) { 12025 t += f2(bl, cl, dl) + hl[1]; 12026 } else if (i < 48) { 12027 t += f3(bl, cl, dl) + hl[2]; 12028 } else if (i < 64) { 12029 t += f4(bl, cl, dl) + hl[3]; 12030 } else { 12031 // if (i<80) { 12032 t += f5(bl, cl, dl) + hl[4]; 12033 } 12034 t = t | 0; 12035 t = rotl(t, sl[i]); 12036 t = (t + el) | 0; 12037 al = el; 12038 el = dl; 12039 dl = rotl(cl, 10); 12040 cl = bl; 12041 bl = t; 12042 12043 t = (ar + M[offset + zr[i]]) | 0; 12044 if (i < 16) { 12045 t += f5(br, cr, dr) + hr[0]; 12046 } else if (i < 32) { 12047 t += f4(br, cr, dr) + hr[1]; 12048 } else if (i < 48) { 12049 t += f3(br, cr, dr) + hr[2]; 12050 } else if (i < 64) { 12051 t += f2(br, cr, dr) + hr[3]; 12052 } else { 12053 // if (i<80) { 12054 t += f1(br, cr, dr) + hr[4]; 12055 } 12056 t = t | 0; 12057 t = rotl(t, sr[i]); 12058 t = (t + er) | 0; 12059 ar = er; 12060 er = dr; 12061 dr = rotl(cr, 10); 12062 cr = br; 12063 br = t; 12064 } 12065 // Intermediate hash value 12066 t = (H[1] + cl + dr) | 0; 12067 H[1] = (H[2] + dl + er) | 0; 12068 H[2] = (H[3] + el + ar) | 0; 12069 H[3] = (H[4] + al + br) | 0; 12070 H[4] = (H[0] + bl + cr) | 0; 12071 H[0] = t; 12072 }, 12073 12074 _doFinalize: function () { 12075 // Shortcuts 12076 var data = this._data; 12077 var dataWords = data.words; 12078 12079 var nBitsTotal = this._nDataBytes * 8; 12080 var nBitsLeft = data.sigBytes * 8; 12081 12082 // Add padding 12083 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 12084 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = 12085 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 12086 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00); 12087 data.sigBytes = (dataWords.length + 1) * 4; 12088 12089 // Hash final blocks 12090 this._process(); 12091 12092 // Shortcuts 12093 var hash = this._hash; 12094 var H = hash.words; 12095 12096 // Swap endian 12097 for (var i = 0; i < 5; i++) { 12098 // Shortcut 12099 var H_i = H[i]; 12100 12101 // Swap 12102 H[i] = 12103 (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 12104 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 12105 } 12106 12107 // Return final computed hash 12108 return hash; 12109 }, 12110 12111 clone: function () { 12112 var clone = Hasher.clone.call(this); 12113 clone._hash = this._hash.clone(); 12114 12115 return clone; 12116 }, 12117 })); 12118 12119 function f1(x, y, z) { 12120 return x ^ y ^ z; 12121 } 12122 12123 function f2(x, y, z) { 12124 return (x & y) | (~x & z); 12125 } 12126 12127 function f3(x, y, z) { 12128 return (x | ~y) ^ z; 12129 } 12130 12131 function f4(x, y, z) { 12132 return (x & z) | (y & ~z); 12133 } 12134 12135 function f5(x, y, z) { 12136 return x ^ (y | ~z); 12137 } 12138 12139 function rotl(x, n) { 12140 return (x << n) | (x >>> (32 - n)); 12141 } 12142 12143 /** 12144 * Shortcut function to the hasher's object interface. 12145 * 12146 * @param {WordArray|string} message The message to hash. 12147 * 12148 * @return {WordArray} The hash. 12149 * 12150 * @static 12151 * 12152 * @example 12153 * 12154 * var hash = CryptoJS.RIPEMD160('message'); 12155 * var hash = CryptoJS.RIPEMD160(wordArray); 12156 */ 12157 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 12158 12159 /** 12160 * Shortcut function to the HMAC's object interface. 12161 * 12162 * @param {WordArray|string} message The message to hash. 12163 * @param {WordArray|string} key The secret key. 12164 * 12165 * @return {WordArray} The HMAC. 12166 * 12167 * @static 12168 * 12169 * @example 12170 * 12171 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 12172 */ 12173 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 12174 })(Math); 12175 12176 return CryptoJS.RIPEMD160; 12177 }); 12178 }, 12179 { "./core": 53 }, 12180 ], 12181 77: [ 12182 function (require, module, exports) { 12183 (function (root, factory) { 12184 if (typeof exports === "object") { 12185 // CommonJS 12186 module.exports = exports = factory(require("./core")); 12187 } else if (typeof define === "function" && define.amd) { 12188 // AMD 12189 define(["./core"], factory); 12190 } else { 12191 // Global (browser) 12192 factory(root.CryptoJS); 12193 } 12194 })(this, function (CryptoJS) { 12195 (function () { 12196 // Shortcuts 12197 var C = CryptoJS; 12198 var C_lib = C.lib; 12199 var WordArray = C_lib.WordArray; 12200 var Hasher = C_lib.Hasher; 12201 var C_algo = C.algo; 12202 12203 // Reusable object 12204 var W = []; 12205 12206 /** 12207 * SHA-1 hash algorithm. 12208 */ 12209 var SHA1 = (C_algo.SHA1 = Hasher.extend({ 12210 _doReset: function () { 12211 this._hash = new WordArray.init([ 12212 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, 12213 ]); 12214 }, 12215 12216 _doProcessBlock: function (M, offset) { 12217 // Shortcut 12218 var H = this._hash.words; 12219 12220 // Working variables 12221 var a = H[0]; 12222 var b = H[1]; 12223 var c = H[2]; 12224 var d = H[3]; 12225 var e = H[4]; 12226 12227 // Computation 12228 for (var i = 0; i < 80; i++) { 12229 if (i < 16) { 12230 W[i] = M[offset + i] | 0; 12231 } else { 12232 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 12233 W[i] = (n << 1) | (n >>> 31); 12234 } 12235 12236 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 12237 if (i < 20) { 12238 t += ((b & c) | (~b & d)) + 0x5a827999; 12239 } else if (i < 40) { 12240 t += (b ^ c ^ d) + 0x6ed9eba1; 12241 } else if (i < 60) { 12242 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 12243 } /* if (i < 80) */ else { 12244 t += (b ^ c ^ d) - 0x359d3e2a; 12245 } 12246 12247 e = d; 12248 d = c; 12249 c = (b << 30) | (b >>> 2); 12250 b = a; 12251 a = t; 12252 } 12253 12254 // Intermediate hash value 12255 H[0] = (H[0] + a) | 0; 12256 H[1] = (H[1] + b) | 0; 12257 H[2] = (H[2] + c) | 0; 12258 H[3] = (H[3] + d) | 0; 12259 H[4] = (H[4] + e) | 0; 12260 }, 12261 12262 _doFinalize: function () { 12263 // Shortcuts 12264 var data = this._data; 12265 var dataWords = data.words; 12266 12267 var nBitsTotal = this._nDataBytes * 8; 12268 var nBitsLeft = data.sigBytes * 8; 12269 12270 // Add padding 12271 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 12272 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor( 12273 nBitsTotal / 0x100000000 12274 ); 12275 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 12276 data.sigBytes = dataWords.length * 4; 12277 12278 // Hash final blocks 12279 this._process(); 12280 12281 // Return final computed hash 12282 return this._hash; 12283 }, 12284 12285 clone: function () { 12286 var clone = Hasher.clone.call(this); 12287 clone._hash = this._hash.clone(); 12288 12289 return clone; 12290 }, 12291 })); 12292 12293 /** 12294 * Shortcut function to the hasher's object interface. 12295 * 12296 * @param {WordArray|string} message The message to hash. 12297 * 12298 * @return {WordArray} The hash. 12299 * 12300 * @static 12301 * 12302 * @example 12303 * 12304 * var hash = CryptoJS.SHA1('message'); 12305 * var hash = CryptoJS.SHA1(wordArray); 12306 */ 12307 C.SHA1 = Hasher._createHelper(SHA1); 12308 12309 /** 12310 * Shortcut function to the HMAC's object interface. 12311 * 12312 * @param {WordArray|string} message The message to hash. 12313 * @param {WordArray|string} key The secret key. 12314 * 12315 * @return {WordArray} The HMAC. 12316 * 12317 * @static 12318 * 12319 * @example 12320 * 12321 * var hmac = CryptoJS.HmacSHA1(message, key); 12322 */ 12323 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 12324 })(); 12325 12326 return CryptoJS.SHA1; 12327 }); 12328 }, 12329 { "./core": 53 }, 12330 ], 12331 78: [ 12332 function (require, module, exports) { 12333 (function (root, factory, undef) { 12334 if (typeof exports === "object") { 12335 // CommonJS 12336 module.exports = exports = factory( 12337 require("./core"), 12338 require("./sha256") 12339 ); 12340 } else if (typeof define === "function" && define.amd) { 12341 // AMD 12342 define(["./core", "./sha256"], factory); 12343 } else { 12344 // Global (browser) 12345 factory(root.CryptoJS); 12346 } 12347 })(this, function (CryptoJS) { 12348 (function () { 12349 // Shortcuts 12350 var C = CryptoJS; 12351 var C_lib = C.lib; 12352 var WordArray = C_lib.WordArray; 12353 var C_algo = C.algo; 12354 var SHA256 = C_algo.SHA256; 12355 12356 /** 12357 * SHA-224 hash algorithm. 12358 */ 12359 var SHA224 = (C_algo.SHA224 = SHA256.extend({ 12360 _doReset: function () { 12361 this._hash = new WordArray.init([ 12362 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 12363 0x68581511, 0x64f98fa7, 0xbefa4fa4, 12364 ]); 12365 }, 12366 12367 _doFinalize: function () { 12368 var hash = SHA256._doFinalize.call(this); 12369 12370 hash.sigBytes -= 4; 12371 12372 return hash; 12373 }, 12374 })); 12375 12376 /** 12377 * Shortcut function to the hasher's object interface. 12378 * 12379 * @param {WordArray|string} message The message to hash. 12380 * 12381 * @return {WordArray} The hash. 12382 * 12383 * @static 12384 * 12385 * @example 12386 * 12387 * var hash = CryptoJS.SHA224('message'); 12388 * var hash = CryptoJS.SHA224(wordArray); 12389 */ 12390 C.SHA224 = SHA256._createHelper(SHA224); 12391 12392 /** 12393 * Shortcut function to the HMAC's object interface. 12394 * 12395 * @param {WordArray|string} message The message to hash. 12396 * @param {WordArray|string} key The secret key. 12397 * 12398 * @return {WordArray} The HMAC. 12399 * 12400 * @static 12401 * 12402 * @example 12403 * 12404 * var hmac = CryptoJS.HmacSHA224(message, key); 12405 */ 12406 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 12407 })(); 12408 12409 return CryptoJS.SHA224; 12410 }); 12411 }, 12412 { "./core": 53, "./sha256": 79 }, 12413 ], 12414 79: [ 12415 function (require, module, exports) { 12416 (function (root, factory) { 12417 if (typeof exports === "object") { 12418 // CommonJS 12419 module.exports = exports = factory(require("./core")); 12420 } else if (typeof define === "function" && define.amd) { 12421 // AMD 12422 define(["./core"], factory); 12423 } else { 12424 // Global (browser) 12425 factory(root.CryptoJS); 12426 } 12427 })(this, function (CryptoJS) { 12428 (function (Math) { 12429 // Shortcuts 12430 var C = CryptoJS; 12431 var C_lib = C.lib; 12432 var WordArray = C_lib.WordArray; 12433 var Hasher = C_lib.Hasher; 12434 var C_algo = C.algo; 12435 12436 // Initialization and round constants tables 12437 var H = []; 12438 var K = []; 12439 12440 // Compute constants 12441 (function () { 12442 function isPrime(n) { 12443 var sqrtN = Math.sqrt(n); 12444 for (var factor = 2; factor <= sqrtN; factor++) { 12445 if (!(n % factor)) { 12446 return false; 12447 } 12448 } 12449 12450 return true; 12451 } 12452 12453 function getFractionalBits(n) { 12454 return ((n - (n | 0)) * 0x100000000) | 0; 12455 } 12456 12457 var n = 2; 12458 var nPrime = 0; 12459 while (nPrime < 64) { 12460 if (isPrime(n)) { 12461 if (nPrime < 8) { 12462 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 12463 } 12464 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 12465 12466 nPrime++; 12467 } 12468 12469 n++; 12470 } 12471 })(); 12472 12473 // Reusable object 12474 var W = []; 12475 12476 /** 12477 * SHA-256 hash algorithm. 12478 */ 12479 var SHA256 = (C_algo.SHA256 = Hasher.extend({ 12480 _doReset: function () { 12481 this._hash = new WordArray.init(H.slice(0)); 12482 }, 12483 12484 _doProcessBlock: function (M, offset) { 12485 // Shortcut 12486 var H = this._hash.words; 12487 12488 // Working variables 12489 var a = H[0]; 12490 var b = H[1]; 12491 var c = H[2]; 12492 var d = H[3]; 12493 var e = H[4]; 12494 var f = H[5]; 12495 var g = H[6]; 12496 var h = H[7]; 12497 12498 // Computation 12499 for (var i = 0; i < 64; i++) { 12500 if (i < 16) { 12501 W[i] = M[offset + i] | 0; 12502 } else { 12503 var gamma0x = W[i - 15]; 12504 var gamma0 = 12505 ((gamma0x << 25) | (gamma0x >>> 7)) ^ 12506 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 12507 (gamma0x >>> 3); 12508 12509 var gamma1x = W[i - 2]; 12510 var gamma1 = 12511 ((gamma1x << 15) | (gamma1x >>> 17)) ^ 12512 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 12513 (gamma1x >>> 10); 12514 12515 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 12516 } 12517 12518 var ch = (e & f) ^ (~e & g); 12519 var maj = (a & b) ^ (a & c) ^ (b & c); 12520 12521 var sigma0 = 12522 ((a << 30) | (a >>> 2)) ^ 12523 ((a << 19) | (a >>> 13)) ^ 12524 ((a << 10) | (a >>> 22)); 12525 var sigma1 = 12526 ((e << 26) | (e >>> 6)) ^ 12527 ((e << 21) | (e >>> 11)) ^ 12528 ((e << 7) | (e >>> 25)); 12529 12530 var t1 = h + sigma1 + ch + K[i] + W[i]; 12531 var t2 = sigma0 + maj; 12532 12533 h = g; 12534 g = f; 12535 f = e; 12536 e = (d + t1) | 0; 12537 d = c; 12538 c = b; 12539 b = a; 12540 a = (t1 + t2) | 0; 12541 } 12542 12543 // Intermediate hash value 12544 H[0] = (H[0] + a) | 0; 12545 H[1] = (H[1] + b) | 0; 12546 H[2] = (H[2] + c) | 0; 12547 H[3] = (H[3] + d) | 0; 12548 H[4] = (H[4] + e) | 0; 12549 H[5] = (H[5] + f) | 0; 12550 H[6] = (H[6] + g) | 0; 12551 H[7] = (H[7] + h) | 0; 12552 }, 12553 12554 _doFinalize: function () { 12555 // Shortcuts 12556 var data = this._data; 12557 var dataWords = data.words; 12558 12559 var nBitsTotal = this._nDataBytes * 8; 12560 var nBitsLeft = data.sigBytes * 8; 12561 12562 // Add padding 12563 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 12564 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor( 12565 nBitsTotal / 0x100000000 12566 ); 12567 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 12568 data.sigBytes = dataWords.length * 4; 12569 12570 // Hash final blocks 12571 this._process(); 12572 12573 // Return final computed hash 12574 return this._hash; 12575 }, 12576 12577 clone: function () { 12578 var clone = Hasher.clone.call(this); 12579 clone._hash = this._hash.clone(); 12580 12581 return clone; 12582 }, 12583 })); 12584 12585 /** 12586 * Shortcut function to the hasher's object interface. 12587 * 12588 * @param {WordArray|string} message The message to hash. 12589 * 12590 * @return {WordArray} The hash. 12591 * 12592 * @static 12593 * 12594 * @example 12595 * 12596 * var hash = CryptoJS.SHA256('message'); 12597 * var hash = CryptoJS.SHA256(wordArray); 12598 */ 12599 C.SHA256 = Hasher._createHelper(SHA256); 12600 12601 /** 12602 * Shortcut function to the HMAC's object interface. 12603 * 12604 * @param {WordArray|string} message The message to hash. 12605 * @param {WordArray|string} key The secret key. 12606 * 12607 * @return {WordArray} The HMAC. 12608 * 12609 * @static 12610 * 12611 * @example 12612 * 12613 * var hmac = CryptoJS.HmacSHA256(message, key); 12614 */ 12615 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 12616 })(Math); 12617 12618 return CryptoJS.SHA256; 12619 }); 12620 }, 12621 { "./core": 53 }, 12622 ], 12623 80: [ 12624 function (require, module, exports) { 12625 (function (root, factory, undef) { 12626 if (typeof exports === "object") { 12627 // CommonJS 12628 module.exports = exports = factory( 12629 require("./core"), 12630 require("./x64-core") 12631 ); 12632 } else if (typeof define === "function" && define.amd) { 12633 // AMD 12634 define(["./core", "./x64-core"], factory); 12635 } else { 12636 // Global (browser) 12637 factory(root.CryptoJS); 12638 } 12639 })(this, function (CryptoJS) { 12640 (function (Math) { 12641 // Shortcuts 12642 var C = CryptoJS; 12643 var C_lib = C.lib; 12644 var WordArray = C_lib.WordArray; 12645 var Hasher = C_lib.Hasher; 12646 var C_x64 = C.x64; 12647 var X64Word = C_x64.Word; 12648 var C_algo = C.algo; 12649 12650 // Constants tables 12651 var RHO_OFFSETS = []; 12652 var PI_INDEXES = []; 12653 var ROUND_CONSTANTS = []; 12654 12655 // Compute Constants 12656 (function () { 12657 // Compute rho offset constants 12658 var x = 1, 12659 y = 0; 12660 for (var t = 0; t < 24; t++) { 12661 RHO_OFFSETS[x + 5 * y] = (((t + 1) * (t + 2)) / 2) % 64; 12662 12663 var newX = y % 5; 12664 var newY = (2 * x + 3 * y) % 5; 12665 x = newX; 12666 y = newY; 12667 } 12668 12669 // Compute pi index constants 12670 for (var x = 0; x < 5; x++) { 12671 for (var y = 0; y < 5; y++) { 12672 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 12673 } 12674 } 12675 12676 // Compute round constants 12677 var LFSR = 0x01; 12678 for (var i = 0; i < 24; i++) { 12679 var roundConstantMsw = 0; 12680 var roundConstantLsw = 0; 12681 12682 for (var j = 0; j < 7; j++) { 12683 if (LFSR & 0x01) { 12684 var bitPosition = (1 << j) - 1; 12685 if (bitPosition < 32) { 12686 roundConstantLsw ^= 1 << bitPosition; 12687 } /* if (bitPosition >= 32) */ else { 12688 roundConstantMsw ^= 1 << (bitPosition - 32); 12689 } 12690 } 12691 12692 // Compute next LFSR 12693 if (LFSR & 0x80) { 12694 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 12695 LFSR = (LFSR << 1) ^ 0x71; 12696 } else { 12697 LFSR <<= 1; 12698 } 12699 } 12700 12701 ROUND_CONSTANTS[i] = X64Word.create( 12702 roundConstantMsw, 12703 roundConstantLsw 12704 ); 12705 } 12706 })(); 12707 12708 // Reusable objects for temporary values 12709 var T = []; 12710 (function () { 12711 for (var i = 0; i < 25; i++) { 12712 T[i] = X64Word.create(); 12713 } 12714 })(); 12715 12716 /** 12717 * SHA-3 hash algorithm. 12718 */ 12719 var SHA3 = (C_algo.SHA3 = Hasher.extend({ 12720 /** 12721 * Configuration options. 12722 * 12723 * @property {number} outputLength 12724 * The desired number of bits in the output hash. 12725 * Only values permitted are: 224, 256, 384, 512. 12726 * Default: 512 12727 */ 12728 cfg: Hasher.cfg.extend({ 12729 outputLength: 512, 12730 }), 12731 12732 _doReset: function () { 12733 var state = (this._state = []); 12734 for (var i = 0; i < 25; i++) { 12735 state[i] = new X64Word.init(); 12736 } 12737 12738 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 12739 }, 12740 12741 _doProcessBlock: function (M, offset) { 12742 // Shortcuts 12743 var state = this._state; 12744 var nBlockSizeLanes = this.blockSize / 2; 12745 12746 // Absorb 12747 for (var i = 0; i < nBlockSizeLanes; i++) { 12748 // Shortcuts 12749 var M2i = M[offset + 2 * i]; 12750 var M2i1 = M[offset + 2 * i + 1]; 12751 12752 // Swap endian 12753 M2i = 12754 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 12755 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00); 12756 M2i1 = 12757 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 12758 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00); 12759 12760 // Absorb message into state 12761 var lane = state[i]; 12762 lane.high ^= M2i1; 12763 lane.low ^= M2i; 12764 } 12765 12766 // Rounds 12767 for (var round = 0; round < 24; round++) { 12768 // Theta 12769 for (var x = 0; x < 5; x++) { 12770 // Mix column lanes 12771 var tMsw = 0, 12772 tLsw = 0; 12773 for (var y = 0; y < 5; y++) { 12774 var lane = state[x + 5 * y]; 12775 tMsw ^= lane.high; 12776 tLsw ^= lane.low; 12777 } 12778 12779 // Temporary values 12780 var Tx = T[x]; 12781 Tx.high = tMsw; 12782 Tx.low = tLsw; 12783 } 12784 for (var x = 0; x < 5; x++) { 12785 // Shortcuts 12786 var Tx4 = T[(x + 4) % 5]; 12787 var Tx1 = T[(x + 1) % 5]; 12788 var Tx1Msw = Tx1.high; 12789 var Tx1Lsw = Tx1.low; 12790 12791 // Mix surrounding columns 12792 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 12793 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 12794 for (var y = 0; y < 5; y++) { 12795 var lane = state[x + 5 * y]; 12796 lane.high ^= tMsw; 12797 lane.low ^= tLsw; 12798 } 12799 } 12800 12801 // Rho Pi 12802 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 12803 // Shortcuts 12804 var lane = state[laneIndex]; 12805 var laneMsw = lane.high; 12806 var laneLsw = lane.low; 12807 var rhoOffset = RHO_OFFSETS[laneIndex]; 12808 12809 // Rotate lanes 12810 if (rhoOffset < 32) { 12811 var tMsw = 12812 (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 12813 var tLsw = 12814 (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 12815 } /* if (rhoOffset >= 32) */ else { 12816 var tMsw = 12817 (laneLsw << (rhoOffset - 32)) | 12818 (laneMsw >>> (64 - rhoOffset)); 12819 var tLsw = 12820 (laneMsw << (rhoOffset - 32)) | 12821 (laneLsw >>> (64 - rhoOffset)); 12822 } 12823 12824 // Transpose lanes 12825 var TPiLane = T[PI_INDEXES[laneIndex]]; 12826 TPiLane.high = tMsw; 12827 TPiLane.low = tLsw; 12828 } 12829 12830 // Rho pi at x = y = 0 12831 var T0 = T[0]; 12832 var state0 = state[0]; 12833 T0.high = state0.high; 12834 T0.low = state0.low; 12835 12836 // Chi 12837 for (var x = 0; x < 5; x++) { 12838 for (var y = 0; y < 5; y++) { 12839 // Shortcuts 12840 var laneIndex = x + 5 * y; 12841 var lane = state[laneIndex]; 12842 var TLane = T[laneIndex]; 12843 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 12844 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 12845 12846 // Mix rows 12847 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 12848 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 12849 } 12850 } 12851 12852 // Iota 12853 var lane = state[0]; 12854 var roundConstant = ROUND_CONSTANTS[round]; 12855 lane.high ^= roundConstant.high; 12856 lane.low ^= roundConstant.low; 12857 } 12858 }, 12859 12860 _doFinalize: function () { 12861 // Shortcuts 12862 var data = this._data; 12863 var dataWords = data.words; 12864 var nBitsTotal = this._nDataBytes * 8; 12865 var nBitsLeft = data.sigBytes * 8; 12866 var blockSizeBits = this.blockSize * 32; 12867 12868 // Add padding 12869 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - (nBitsLeft % 32)); 12870 dataWords[ 12871 ((Math.ceil((nBitsLeft + 1) / blockSizeBits) * 12872 blockSizeBits) >>> 12873 5) - 12874 1 12875 ] |= 0x80; 12876 data.sigBytes = dataWords.length * 4; 12877 12878 // Hash final blocks 12879 this._process(); 12880 12881 // Shortcuts 12882 var state = this._state; 12883 var outputLengthBytes = this.cfg.outputLength / 8; 12884 var outputLengthLanes = outputLengthBytes / 8; 12885 12886 // Squeeze 12887 var hashWords = []; 12888 for (var i = 0; i < outputLengthLanes; i++) { 12889 // Shortcuts 12890 var lane = state[i]; 12891 var laneMsw = lane.high; 12892 var laneLsw = lane.low; 12893 12894 // Swap endian 12895 laneMsw = 12896 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 12897 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00); 12898 laneLsw = 12899 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 12900 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00); 12901 12902 // Squeeze state to retrieve hash 12903 hashWords.push(laneLsw); 12904 hashWords.push(laneMsw); 12905 } 12906 12907 // Return final computed hash 12908 return new WordArray.init(hashWords, outputLengthBytes); 12909 }, 12910 12911 clone: function () { 12912 var clone = Hasher.clone.call(this); 12913 12914 var state = (clone._state = this._state.slice(0)); 12915 for (var i = 0; i < 25; i++) { 12916 state[i] = state[i].clone(); 12917 } 12918 12919 return clone; 12920 }, 12921 })); 12922 12923 /** 12924 * Shortcut function to the hasher's object interface. 12925 * 12926 * @param {WordArray|string} message The message to hash. 12927 * 12928 * @return {WordArray} The hash. 12929 * 12930 * @static 12931 * 12932 * @example 12933 * 12934 * var hash = CryptoJS.SHA3('message'); 12935 * var hash = CryptoJS.SHA3(wordArray); 12936 */ 12937 C.SHA3 = Hasher._createHelper(SHA3); 12938 12939 /** 12940 * Shortcut function to the HMAC's object interface. 12941 * 12942 * @param {WordArray|string} message The message to hash. 12943 * @param {WordArray|string} key The secret key. 12944 * 12945 * @return {WordArray} The HMAC. 12946 * 12947 * @static 12948 * 12949 * @example 12950 * 12951 * var hmac = CryptoJS.HmacSHA3(message, key); 12952 */ 12953 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 12954 })(Math); 12955 12956 return CryptoJS.SHA3; 12957 }); 12958 }, 12959 { "./core": 53, "./x64-core": 84 }, 12960 ], 12961 81: [ 12962 function (require, module, exports) { 12963 (function (root, factory, undef) { 12964 if (typeof exports === "object") { 12965 // CommonJS 12966 module.exports = exports = factory( 12967 require("./core"), 12968 require("./x64-core"), 12969 require("./sha512") 12970 ); 12971 } else if (typeof define === "function" && define.amd) { 12972 // AMD 12973 define(["./core", "./x64-core", "./sha512"], factory); 12974 } else { 12975 // Global (browser) 12976 factory(root.CryptoJS); 12977 } 12978 })(this, function (CryptoJS) { 12979 (function () { 12980 // Shortcuts 12981 var C = CryptoJS; 12982 var C_x64 = C.x64; 12983 var X64Word = C_x64.Word; 12984 var X64WordArray = C_x64.WordArray; 12985 var C_algo = C.algo; 12986 var SHA512 = C_algo.SHA512; 12987 12988 /** 12989 * SHA-384 hash algorithm. 12990 */ 12991 var SHA384 = (C_algo.SHA384 = SHA512.extend({ 12992 _doReset: function () { 12993 this._hash = new X64WordArray.init([ 12994 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), 12995 new X64Word.init(0x629a292a, 0x367cd507), 12996 new X64Word.init(0x9159015a, 0x3070dd17), 12997 new X64Word.init(0x152fecd8, 0xf70e5939), 12998 new X64Word.init(0x67332667, 0xffc00b31), 12999 new X64Word.init(0x8eb44a87, 0x68581511), 13000 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), 13001 new X64Word.init(0x47b5481d, 0xbefa4fa4), 13002 ]); 13003 }, 13004 13005 _doFinalize: function () { 13006 var hash = SHA512._doFinalize.call(this); 13007 13008 hash.sigBytes -= 16; 13009 13010 return hash; 13011 }, 13012 })); 13013 13014 /** 13015 * Shortcut function to the hasher's object interface. 13016 * 13017 * @param {WordArray|string} message The message to hash. 13018 * 13019 * @return {WordArray} The hash. 13020 * 13021 * @static 13022 * 13023 * @example 13024 * 13025 * var hash = CryptoJS.SHA384('message'); 13026 * var hash = CryptoJS.SHA384(wordArray); 13027 */ 13028 C.SHA384 = SHA512._createHelper(SHA384); 13029 13030 /** 13031 * Shortcut function to the HMAC's object interface. 13032 * 13033 * @param {WordArray|string} message The message to hash. 13034 * @param {WordArray|string} key The secret key. 13035 * 13036 * @return {WordArray} The HMAC. 13037 * 13038 * @static 13039 * 13040 * @example 13041 * 13042 * var hmac = CryptoJS.HmacSHA384(message, key); 13043 */ 13044 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 13045 })(); 13046 13047 return CryptoJS.SHA384; 13048 }); 13049 }, 13050 { "./core": 53, "./sha512": 82, "./x64-core": 84 }, 13051 ], 13052 82: [ 13053 function (require, module, exports) { 13054 (function (root, factory, undef) { 13055 if (typeof exports === "object") { 13056 // CommonJS 13057 module.exports = exports = factory( 13058 require("./core"), 13059 require("./x64-core") 13060 ); 13061 } else if (typeof define === "function" && define.amd) { 13062 // AMD 13063 define(["./core", "./x64-core"], factory); 13064 } else { 13065 // Global (browser) 13066 factory(root.CryptoJS); 13067 } 13068 })(this, function (CryptoJS) { 13069 (function () { 13070 // Shortcuts 13071 var C = CryptoJS; 13072 var C_lib = C.lib; 13073 var Hasher = C_lib.Hasher; 13074 var C_x64 = C.x64; 13075 var X64Word = C_x64.Word; 13076 var X64WordArray = C_x64.WordArray; 13077 var C_algo = C.algo; 13078 13079 function X64Word_create() { 13080 return X64Word.create.apply(X64Word, arguments); 13081 } 13082 13083 // Constants 13084 var K = [ 13085 X64Word_create(0x428a2f98, 0xd728ae22), 13086 X64Word_create(0x71374491, 0x23ef65cd), 13087 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), 13088 X64Word_create(0xe9b5dba5, 0x8189dbbc), 13089 X64Word_create(0x3956c25b, 0xf348b538), 13090 X64Word_create(0x59f111f1, 0xb605d019), 13091 X64Word_create(0x923f82a4, 0xaf194f9b), 13092 X64Word_create(0xab1c5ed5, 0xda6d8118), 13093 X64Word_create(0xd807aa98, 0xa3030242), 13094 X64Word_create(0x12835b01, 0x45706fbe), 13095 X64Word_create(0x243185be, 0x4ee4b28c), 13096 X64Word_create(0x550c7dc3, 0xd5ffb4e2), 13097 X64Word_create(0x72be5d74, 0xf27b896f), 13098 X64Word_create(0x80deb1fe, 0x3b1696b1), 13099 X64Word_create(0x9bdc06a7, 0x25c71235), 13100 X64Word_create(0xc19bf174, 0xcf692694), 13101 X64Word_create(0xe49b69c1, 0x9ef14ad2), 13102 X64Word_create(0xefbe4786, 0x384f25e3), 13103 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), 13104 X64Word_create(0x240ca1cc, 0x77ac9c65), 13105 X64Word_create(0x2de92c6f, 0x592b0275), 13106 X64Word_create(0x4a7484aa, 0x6ea6e483), 13107 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), 13108 X64Word_create(0x76f988da, 0x831153b5), 13109 X64Word_create(0x983e5152, 0xee66dfab), 13110 X64Word_create(0xa831c66d, 0x2db43210), 13111 X64Word_create(0xb00327c8, 0x98fb213f), 13112 X64Word_create(0xbf597fc7, 0xbeef0ee4), 13113 X64Word_create(0xc6e00bf3, 0x3da88fc2), 13114 X64Word_create(0xd5a79147, 0x930aa725), 13115 X64Word_create(0x06ca6351, 0xe003826f), 13116 X64Word_create(0x14292967, 0x0a0e6e70), 13117 X64Word_create(0x27b70a85, 0x46d22ffc), 13118 X64Word_create(0x2e1b2138, 0x5c26c926), 13119 X64Word_create(0x4d2c6dfc, 0x5ac42aed), 13120 X64Word_create(0x53380d13, 0x9d95b3df), 13121 X64Word_create(0x650a7354, 0x8baf63de), 13122 X64Word_create(0x766a0abb, 0x3c77b2a8), 13123 X64Word_create(0x81c2c92e, 0x47edaee6), 13124 X64Word_create(0x92722c85, 0x1482353b), 13125 X64Word_create(0xa2bfe8a1, 0x4cf10364), 13126 X64Word_create(0xa81a664b, 0xbc423001), 13127 X64Word_create(0xc24b8b70, 0xd0f89791), 13128 X64Word_create(0xc76c51a3, 0x0654be30), 13129 X64Word_create(0xd192e819, 0xd6ef5218), 13130 X64Word_create(0xd6990624, 0x5565a910), 13131 X64Word_create(0xf40e3585, 0x5771202a), 13132 X64Word_create(0x106aa070, 0x32bbd1b8), 13133 X64Word_create(0x19a4c116, 0xb8d2d0c8), 13134 X64Word_create(0x1e376c08, 0x5141ab53), 13135 X64Word_create(0x2748774c, 0xdf8eeb99), 13136 X64Word_create(0x34b0bcb5, 0xe19b48a8), 13137 X64Word_create(0x391c0cb3, 0xc5c95a63), 13138 X64Word_create(0x4ed8aa4a, 0xe3418acb), 13139 X64Word_create(0x5b9cca4f, 0x7763e373), 13140 X64Word_create(0x682e6ff3, 0xd6b2b8a3), 13141 X64Word_create(0x748f82ee, 0x5defb2fc), 13142 X64Word_create(0x78a5636f, 0x43172f60), 13143 X64Word_create(0x84c87814, 0xa1f0ab72), 13144 X64Word_create(0x8cc70208, 0x1a6439ec), 13145 X64Word_create(0x90befffa, 0x23631e28), 13146 X64Word_create(0xa4506ceb, 0xde82bde9), 13147 X64Word_create(0xbef9a3f7, 0xb2c67915), 13148 X64Word_create(0xc67178f2, 0xe372532b), 13149 X64Word_create(0xca273ece, 0xea26619c), 13150 X64Word_create(0xd186b8c7, 0x21c0c207), 13151 X64Word_create(0xeada7dd6, 0xcde0eb1e), 13152 X64Word_create(0xf57d4f7f, 0xee6ed178), 13153 X64Word_create(0x06f067aa, 0x72176fba), 13154 X64Word_create(0x0a637dc5, 0xa2c898a6), 13155 X64Word_create(0x113f9804, 0xbef90dae), 13156 X64Word_create(0x1b710b35, 0x131c471b), 13157 X64Word_create(0x28db77f5, 0x23047d84), 13158 X64Word_create(0x32caab7b, 0x40c72493), 13159 X64Word_create(0x3c9ebe0a, 0x15c9bebc), 13160 X64Word_create(0x431d67c4, 0x9c100d4c), 13161 X64Word_create(0x4cc5d4be, 0xcb3e42b6), 13162 X64Word_create(0x597f299c, 0xfc657e2a), 13163 X64Word_create(0x5fcb6fab, 0x3ad6faec), 13164 X64Word_create(0x6c44198c, 0x4a475817), 13165 ]; 13166 13167 // Reusable objects 13168 var W = []; 13169 (function () { 13170 for (var i = 0; i < 80; i++) { 13171 W[i] = X64Word_create(); 13172 } 13173 })(); 13174 13175 /** 13176 * SHA-512 hash algorithm. 13177 */ 13178 var SHA512 = (C_algo.SHA512 = Hasher.extend({ 13179 _doReset: function () { 13180 this._hash = new X64WordArray.init([ 13181 new X64Word.init(0x6a09e667, 0xf3bcc908), 13182 new X64Word.init(0xbb67ae85, 0x84caa73b), 13183 new X64Word.init(0x3c6ef372, 0xfe94f82b), 13184 new X64Word.init(0xa54ff53a, 0x5f1d36f1), 13185 new X64Word.init(0x510e527f, 0xade682d1), 13186 new X64Word.init(0x9b05688c, 0x2b3e6c1f), 13187 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), 13188 new X64Word.init(0x5be0cd19, 0x137e2179), 13189 ]); 13190 }, 13191 13192 _doProcessBlock: function (M, offset) { 13193 // Shortcuts 13194 var H = this._hash.words; 13195 13196 var H0 = H[0]; 13197 var H1 = H[1]; 13198 var H2 = H[2]; 13199 var H3 = H[3]; 13200 var H4 = H[4]; 13201 var H5 = H[5]; 13202 var H6 = H[6]; 13203 var H7 = H[7]; 13204 13205 var H0h = H0.high; 13206 var H0l = H0.low; 13207 var H1h = H1.high; 13208 var H1l = H1.low; 13209 var H2h = H2.high; 13210 var H2l = H2.low; 13211 var H3h = H3.high; 13212 var H3l = H3.low; 13213 var H4h = H4.high; 13214 var H4l = H4.low; 13215 var H5h = H5.high; 13216 var H5l = H5.low; 13217 var H6h = H6.high; 13218 var H6l = H6.low; 13219 var H7h = H7.high; 13220 var H7l = H7.low; 13221 13222 // Working variables 13223 var ah = H0h; 13224 var al = H0l; 13225 var bh = H1h; 13226 var bl = H1l; 13227 var ch = H2h; 13228 var cl = H2l; 13229 var dh = H3h; 13230 var dl = H3l; 13231 var eh = H4h; 13232 var el = H4l; 13233 var fh = H5h; 13234 var fl = H5l; 13235 var gh = H6h; 13236 var gl = H6l; 13237 var hh = H7h; 13238 var hl = H7l; 13239 13240 // Rounds 13241 for (var i = 0; i < 80; i++) { 13242 // Shortcut 13243 var Wi = W[i]; 13244 13245 // Extend message 13246 if (i < 16) { 13247 var Wih = (Wi.high = M[offset + i * 2] | 0); 13248 var Wil = (Wi.low = M[offset + i * 2 + 1] | 0); 13249 } else { 13250 // Gamma0 13251 var gamma0x = W[i - 15]; 13252 var gamma0xh = gamma0x.high; 13253 var gamma0xl = gamma0x.low; 13254 var gamma0h = 13255 ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ 13256 ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ 13257 (gamma0xh >>> 7); 13258 var gamma0l = 13259 ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ 13260 ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ 13261 ((gamma0xl >>> 7) | (gamma0xh << 25)); 13262 13263 // Gamma1 13264 var gamma1x = W[i - 2]; 13265 var gamma1xh = gamma1x.high; 13266 var gamma1xl = gamma1x.low; 13267 var gamma1h = 13268 ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ 13269 ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ 13270 (gamma1xh >>> 6); 13271 var gamma1l = 13272 ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ 13273 ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ 13274 ((gamma1xl >>> 6) | (gamma1xh << 26)); 13275 13276 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 13277 var Wi7 = W[i - 7]; 13278 var Wi7h = Wi7.high; 13279 var Wi7l = Wi7.low; 13280 13281 var Wi16 = W[i - 16]; 13282 var Wi16h = Wi16.high; 13283 var Wi16l = Wi16.low; 13284 13285 var Wil = gamma0l + Wi7l; 13286 var Wih = 13287 gamma0h + Wi7h + (Wil >>> 0 < gamma0l >>> 0 ? 1 : 0); 13288 var Wil = Wil + gamma1l; 13289 var Wih = 13290 Wih + gamma1h + (Wil >>> 0 < gamma1l >>> 0 ? 1 : 0); 13291 var Wil = Wil + Wi16l; 13292 var Wih = Wih + Wi16h + (Wil >>> 0 < Wi16l >>> 0 ? 1 : 0); 13293 13294 Wi.high = Wih; 13295 Wi.low = Wil; 13296 } 13297 13298 var chh = (eh & fh) ^ (~eh & gh); 13299 var chl = (el & fl) ^ (~el & gl); 13300 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 13301 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 13302 13303 var sigma0h = 13304 ((ah >>> 28) | (al << 4)) ^ 13305 ((ah << 30) | (al >>> 2)) ^ 13306 ((ah << 25) | (al >>> 7)); 13307 var sigma0l = 13308 ((al >>> 28) | (ah << 4)) ^ 13309 ((al << 30) | (ah >>> 2)) ^ 13310 ((al << 25) | (ah >>> 7)); 13311 var sigma1h = 13312 ((eh >>> 14) | (el << 18)) ^ 13313 ((eh >>> 18) | (el << 14)) ^ 13314 ((eh << 23) | (el >>> 9)); 13315 var sigma1l = 13316 ((el >>> 14) | (eh << 18)) ^ 13317 ((el >>> 18) | (eh << 14)) ^ 13318 ((el << 23) | (eh >>> 9)); 13319 13320 // t1 = h + sigma1 + ch + K[i] + W[i] 13321 var Ki = K[i]; 13322 var Kih = Ki.high; 13323 var Kil = Ki.low; 13324 13325 var t1l = hl + sigma1l; 13326 var t1h = hh + sigma1h + (t1l >>> 0 < hl >>> 0 ? 1 : 0); 13327 var t1l = t1l + chl; 13328 var t1h = t1h + chh + (t1l >>> 0 < chl >>> 0 ? 1 : 0); 13329 var t1l = t1l + Kil; 13330 var t1h = t1h + Kih + (t1l >>> 0 < Kil >>> 0 ? 1 : 0); 13331 var t1l = t1l + Wil; 13332 var t1h = t1h + Wih + (t1l >>> 0 < Wil >>> 0 ? 1 : 0); 13333 13334 // t2 = sigma0 + maj 13335 var t2l = sigma0l + majl; 13336 var t2h = 13337 sigma0h + majh + (t2l >>> 0 < sigma0l >>> 0 ? 1 : 0); 13338 13339 // Update working variables 13340 hh = gh; 13341 hl = gl; 13342 gh = fh; 13343 gl = fl; 13344 fh = eh; 13345 fl = el; 13346 el = (dl + t1l) | 0; 13347 eh = (dh + t1h + (el >>> 0 < dl >>> 0 ? 1 : 0)) | 0; 13348 dh = ch; 13349 dl = cl; 13350 ch = bh; 13351 cl = bl; 13352 bh = ah; 13353 bl = al; 13354 al = (t1l + t2l) | 0; 13355 ah = (t1h + t2h + (al >>> 0 < t1l >>> 0 ? 1 : 0)) | 0; 13356 } 13357 13358 // Intermediate hash value 13359 H0l = H0.low = H0l + al; 13360 H0.high = H0h + ah + (H0l >>> 0 < al >>> 0 ? 1 : 0); 13361 H1l = H1.low = H1l + bl; 13362 H1.high = H1h + bh + (H1l >>> 0 < bl >>> 0 ? 1 : 0); 13363 H2l = H2.low = H2l + cl; 13364 H2.high = H2h + ch + (H2l >>> 0 < cl >>> 0 ? 1 : 0); 13365 H3l = H3.low = H3l + dl; 13366 H3.high = H3h + dh + (H3l >>> 0 < dl >>> 0 ? 1 : 0); 13367 H4l = H4.low = H4l + el; 13368 H4.high = H4h + eh + (H4l >>> 0 < el >>> 0 ? 1 : 0); 13369 H5l = H5.low = H5l + fl; 13370 H5.high = H5h + fh + (H5l >>> 0 < fl >>> 0 ? 1 : 0); 13371 H6l = H6.low = H6l + gl; 13372 H6.high = H6h + gh + (H6l >>> 0 < gl >>> 0 ? 1 : 0); 13373 H7l = H7.low = H7l + hl; 13374 H7.high = H7h + hh + (H7l >>> 0 < hl >>> 0 ? 1 : 0); 13375 }, 13376 13377 _doFinalize: function () { 13378 // Shortcuts 13379 var data = this._data; 13380 var dataWords = data.words; 13381 13382 var nBitsTotal = this._nDataBytes * 8; 13383 var nBitsLeft = data.sigBytes * 8; 13384 13385 // Add padding 13386 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 13387 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor( 13388 nBitsTotal / 0x100000000 13389 ); 13390 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 13391 data.sigBytes = dataWords.length * 4; 13392 13393 // Hash final blocks 13394 this._process(); 13395 13396 // Convert hash to 32-bit word array before returning 13397 var hash = this._hash.toX32(); 13398 13399 // Return final computed hash 13400 return hash; 13401 }, 13402 13403 clone: function () { 13404 var clone = Hasher.clone.call(this); 13405 clone._hash = this._hash.clone(); 13406 13407 return clone; 13408 }, 13409 13410 blockSize: 1024 / 32, 13411 })); 13412 13413 /** 13414 * Shortcut function to the hasher's object interface. 13415 * 13416 * @param {WordArray|string} message The message to hash. 13417 * 13418 * @return {WordArray} The hash. 13419 * 13420 * @static 13421 * 13422 * @example 13423 * 13424 * var hash = CryptoJS.SHA512('message'); 13425 * var hash = CryptoJS.SHA512(wordArray); 13426 */ 13427 C.SHA512 = Hasher._createHelper(SHA512); 13428 13429 /** 13430 * Shortcut function to the HMAC's object interface. 13431 * 13432 * @param {WordArray|string} message The message to hash. 13433 * @param {WordArray|string} key The secret key. 13434 * 13435 * @return {WordArray} The HMAC. 13436 * 13437 * @static 13438 * 13439 * @example 13440 * 13441 * var hmac = CryptoJS.HmacSHA512(message, key); 13442 */ 13443 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 13444 })(); 13445 13446 return CryptoJS.SHA512; 13447 }); 13448 }, 13449 { "./core": 53, "./x64-core": 84 }, 13450 ], 13451 83: [ 13452 function (require, module, exports) { 13453 (function (root, factory, undef) { 13454 if (typeof exports === "object") { 13455 // CommonJS 13456 module.exports = exports = factory( 13457 require("./core"), 13458 require("./enc-base64"), 13459 require("./md5"), 13460 require("./evpkdf"), 13461 require("./cipher-core") 13462 ); 13463 } else if (typeof define === "function" && define.amd) { 13464 // AMD 13465 define([ 13466 "./core", 13467 "./enc-base64", 13468 "./md5", 13469 "./evpkdf", 13470 "./cipher-core", 13471 ], factory); 13472 } else { 13473 // Global (browser) 13474 factory(root.CryptoJS); 13475 } 13476 })(this, function (CryptoJS) { 13477 (function () { 13478 // Shortcuts 13479 var C = CryptoJS; 13480 var C_lib = C.lib; 13481 var WordArray = C_lib.WordArray; 13482 var BlockCipher = C_lib.BlockCipher; 13483 var C_algo = C.algo; 13484 13485 // Permuted Choice 1 constants 13486 var PC1 = [ 13487 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 13488 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36, 63, 55, 47, 39, 31, 23, 13489 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 13490 5, 28, 20, 12, 4, 13491 ]; 13492 13493 // Permuted Choice 2 constants 13494 var PC2 = [ 13495 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 13496 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 13497 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32, 13498 ]; 13499 13500 // Cumulative bit shift constants 13501 var BIT_SHIFTS = [ 13502 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28, 13503 ]; 13504 13505 // SBOXes and round permutation constants 13506 var SBOX_P = [ 13507 { 13508 0x0: 0x808200, 13509 0x10000000: 0x8000, 13510 0x20000000: 0x808002, 13511 0x30000000: 0x2, 13512 0x40000000: 0x200, 13513 0x50000000: 0x808202, 13514 0x60000000: 0x800202, 13515 0x70000000: 0x800000, 13516 0x80000000: 0x202, 13517 0x90000000: 0x800200, 13518 0xa0000000: 0x8200, 13519 0xb0000000: 0x808000, 13520 0xc0000000: 0x8002, 13521 0xd0000000: 0x800002, 13522 0xe0000000: 0x0, 13523 0xf0000000: 0x8202, 13524 0x8000000: 0x0, 13525 0x18000000: 0x808202, 13526 0x28000000: 0x8202, 13527 0x38000000: 0x8000, 13528 0x48000000: 0x808200, 13529 0x58000000: 0x200, 13530 0x68000000: 0x808002, 13531 0x78000000: 0x2, 13532 0x88000000: 0x800200, 13533 0x98000000: 0x8200, 13534 0xa8000000: 0x808000, 13535 0xb8000000: 0x800202, 13536 0xc8000000: 0x800002, 13537 0xd8000000: 0x8002, 13538 0xe8000000: 0x202, 13539 0xf8000000: 0x800000, 13540 0x1: 0x8000, 13541 0x10000001: 0x2, 13542 0x20000001: 0x808200, 13543 0x30000001: 0x800000, 13544 0x40000001: 0x808002, 13545 0x50000001: 0x8200, 13546 0x60000001: 0x200, 13547 0x70000001: 0x800202, 13548 0x80000001: 0x808202, 13549 0x90000001: 0x808000, 13550 0xa0000001: 0x800002, 13551 0xb0000001: 0x8202, 13552 0xc0000001: 0x202, 13553 0xd0000001: 0x800200, 13554 0xe0000001: 0x8002, 13555 0xf0000001: 0x0, 13556 0x8000001: 0x808202, 13557 0x18000001: 0x808000, 13558 0x28000001: 0x800000, 13559 0x38000001: 0x200, 13560 0x48000001: 0x8000, 13561 0x58000001: 0x800002, 13562 0x68000001: 0x2, 13563 0x78000001: 0x8202, 13564 0x88000001: 0x8002, 13565 0x98000001: 0x800202, 13566 0xa8000001: 0x202, 13567 0xb8000001: 0x808200, 13568 0xc8000001: 0x800200, 13569 0xd8000001: 0x0, 13570 0xe8000001: 0x8200, 13571 0xf8000001: 0x808002, 13572 }, 13573 { 13574 0x0: 0x40084010, 13575 0x1000000: 0x4000, 13576 0x2000000: 0x80000, 13577 0x3000000: 0x40080010, 13578 0x4000000: 0x40000010, 13579 0x5000000: 0x40084000, 13580 0x6000000: 0x40004000, 13581 0x7000000: 0x10, 13582 0x8000000: 0x84000, 13583 0x9000000: 0x40004010, 13584 0xa000000: 0x40000000, 13585 0xb000000: 0x84010, 13586 0xc000000: 0x80010, 13587 0xd000000: 0x0, 13588 0xe000000: 0x4010, 13589 0xf000000: 0x40080000, 13590 0x800000: 0x40004000, 13591 0x1800000: 0x84010, 13592 0x2800000: 0x10, 13593 0x3800000: 0x40004010, 13594 0x4800000: 0x40084010, 13595 0x5800000: 0x40000000, 13596 0x6800000: 0x80000, 13597 0x7800000: 0x40080010, 13598 0x8800000: 0x80010, 13599 0x9800000: 0x0, 13600 0xa800000: 0x4000, 13601 0xb800000: 0x40080000, 13602 0xc800000: 0x40000010, 13603 0xd800000: 0x84000, 13604 0xe800000: 0x40084000, 13605 0xf800000: 0x4010, 13606 0x10000000: 0x0, 13607 0x11000000: 0x40080010, 13608 0x12000000: 0x40004010, 13609 0x13000000: 0x40084000, 13610 0x14000000: 0x40080000, 13611 0x15000000: 0x10, 13612 0x16000000: 0x84010, 13613 0x17000000: 0x4000, 13614 0x18000000: 0x4010, 13615 0x19000000: 0x80000, 13616 0x1a000000: 0x80010, 13617 0x1b000000: 0x40000010, 13618 0x1c000000: 0x84000, 13619 0x1d000000: 0x40004000, 13620 0x1e000000: 0x40000000, 13621 0x1f000000: 0x40084010, 13622 0x10800000: 0x84010, 13623 0x11800000: 0x80000, 13624 0x12800000: 0x40080000, 13625 0x13800000: 0x4000, 13626 0x14800000: 0x40004000, 13627 0x15800000: 0x40084010, 13628 0x16800000: 0x10, 13629 0x17800000: 0x40000000, 13630 0x18800000: 0x40084000, 13631 0x19800000: 0x40000010, 13632 0x1a800000: 0x40004010, 13633 0x1b800000: 0x80010, 13634 0x1c800000: 0x0, 13635 0x1d800000: 0x4010, 13636 0x1e800000: 0x40080010, 13637 0x1f800000: 0x84000, 13638 }, 13639 { 13640 0x0: 0x104, 13641 0x100000: 0x0, 13642 0x200000: 0x4000100, 13643 0x300000: 0x10104, 13644 0x400000: 0x10004, 13645 0x500000: 0x4000004, 13646 0x600000: 0x4010104, 13647 0x700000: 0x4010000, 13648 0x800000: 0x4000000, 13649 0x900000: 0x4010100, 13650 0xa00000: 0x10100, 13651 0xb00000: 0x4010004, 13652 0xc00000: 0x4000104, 13653 0xd00000: 0x10000, 13654 0xe00000: 0x4, 13655 0xf00000: 0x100, 13656 0x80000: 0x4010100, 13657 0x180000: 0x4010004, 13658 0x280000: 0x0, 13659 0x380000: 0x4000100, 13660 0x480000: 0x4000004, 13661 0x580000: 0x10000, 13662 0x680000: 0x10004, 13663 0x780000: 0x104, 13664 0x880000: 0x4, 13665 0x980000: 0x100, 13666 0xa80000: 0x4010000, 13667 0xb80000: 0x10104, 13668 0xc80000: 0x10100, 13669 0xd80000: 0x4000104, 13670 0xe80000: 0x4010104, 13671 0xf80000: 0x4000000, 13672 0x1000000: 0x4010100, 13673 0x1100000: 0x10004, 13674 0x1200000: 0x10000, 13675 0x1300000: 0x4000100, 13676 0x1400000: 0x100, 13677 0x1500000: 0x4010104, 13678 0x1600000: 0x4000004, 13679 0x1700000: 0x0, 13680 0x1800000: 0x4000104, 13681 0x1900000: 0x4000000, 13682 0x1a00000: 0x4, 13683 0x1b00000: 0x10100, 13684 0x1c00000: 0x4010000, 13685 0x1d00000: 0x104, 13686 0x1e00000: 0x10104, 13687 0x1f00000: 0x4010004, 13688 0x1080000: 0x4000000, 13689 0x1180000: 0x104, 13690 0x1280000: 0x4010100, 13691 0x1380000: 0x0, 13692 0x1480000: 0x10004, 13693 0x1580000: 0x4000100, 13694 0x1680000: 0x100, 13695 0x1780000: 0x4010004, 13696 0x1880000: 0x10000, 13697 0x1980000: 0x4010104, 13698 0x1a80000: 0x10104, 13699 0x1b80000: 0x4000004, 13700 0x1c80000: 0x4000104, 13701 0x1d80000: 0x4010000, 13702 0x1e80000: 0x4, 13703 0x1f80000: 0x10100, 13704 }, 13705 { 13706 0x0: 0x80401000, 13707 0x10000: 0x80001040, 13708 0x20000: 0x401040, 13709 0x30000: 0x80400000, 13710 0x40000: 0x0, 13711 0x50000: 0x401000, 13712 0x60000: 0x80000040, 13713 0x70000: 0x400040, 13714 0x80000: 0x80000000, 13715 0x90000: 0x400000, 13716 0xa0000: 0x40, 13717 0xb0000: 0x80001000, 13718 0xc0000: 0x80400040, 13719 0xd0000: 0x1040, 13720 0xe0000: 0x1000, 13721 0xf0000: 0x80401040, 13722 0x8000: 0x80001040, 13723 0x18000: 0x40, 13724 0x28000: 0x80400040, 13725 0x38000: 0x80001000, 13726 0x48000: 0x401000, 13727 0x58000: 0x80401040, 13728 0x68000: 0x0, 13729 0x78000: 0x80400000, 13730 0x88000: 0x1000, 13731 0x98000: 0x80401000, 13732 0xa8000: 0x400000, 13733 0xb8000: 0x1040, 13734 0xc8000: 0x80000000, 13735 0xd8000: 0x400040, 13736 0xe8000: 0x401040, 13737 0xf8000: 0x80000040, 13738 0x100000: 0x400040, 13739 0x110000: 0x401000, 13740 0x120000: 0x80000040, 13741 0x130000: 0x0, 13742 0x140000: 0x1040, 13743 0x150000: 0x80400040, 13744 0x160000: 0x80401000, 13745 0x170000: 0x80001040, 13746 0x180000: 0x80401040, 13747 0x190000: 0x80000000, 13748 0x1a0000: 0x80400000, 13749 0x1b0000: 0x401040, 13750 0x1c0000: 0x80001000, 13751 0x1d0000: 0x400000, 13752 0x1e0000: 0x40, 13753 0x1f0000: 0x1000, 13754 0x108000: 0x80400000, 13755 0x118000: 0x80401040, 13756 0x128000: 0x0, 13757 0x138000: 0x401000, 13758 0x148000: 0x400040, 13759 0x158000: 0x80000000, 13760 0x168000: 0x80001040, 13761 0x178000: 0x40, 13762 0x188000: 0x80000040, 13763 0x198000: 0x1000, 13764 0x1a8000: 0x80001000, 13765 0x1b8000: 0x80400040, 13766 0x1c8000: 0x1040, 13767 0x1d8000: 0x80401000, 13768 0x1e8000: 0x400000, 13769 0x1f8000: 0x401040, 13770 }, 13771 { 13772 0x0: 0x80, 13773 0x1000: 0x1040000, 13774 0x2000: 0x40000, 13775 0x3000: 0x20000000, 13776 0x4000: 0x20040080, 13777 0x5000: 0x1000080, 13778 0x6000: 0x21000080, 13779 0x7000: 0x40080, 13780 0x8000: 0x1000000, 13781 0x9000: 0x20040000, 13782 0xa000: 0x20000080, 13783 0xb000: 0x21040080, 13784 0xc000: 0x21040000, 13785 0xd000: 0x0, 13786 0xe000: 0x1040080, 13787 0xf000: 0x21000000, 13788 0x800: 0x1040080, 13789 0x1800: 0x21000080, 13790 0x2800: 0x80, 13791 0x3800: 0x1040000, 13792 0x4800: 0x40000, 13793 0x5800: 0x20040080, 13794 0x6800: 0x21040000, 13795 0x7800: 0x20000000, 13796 0x8800: 0x20040000, 13797 0x9800: 0x0, 13798 0xa800: 0x21040080, 13799 0xb800: 0x1000080, 13800 0xc800: 0x20000080, 13801 0xd800: 0x21000000, 13802 0xe800: 0x1000000, 13803 0xf800: 0x40080, 13804 0x10000: 0x40000, 13805 0x11000: 0x80, 13806 0x12000: 0x20000000, 13807 0x13000: 0x21000080, 13808 0x14000: 0x1000080, 13809 0x15000: 0x21040000, 13810 0x16000: 0x20040080, 13811 0x17000: 0x1000000, 13812 0x18000: 0x21040080, 13813 0x19000: 0x21000000, 13814 0x1a000: 0x1040000, 13815 0x1b000: 0x20040000, 13816 0x1c000: 0x40080, 13817 0x1d000: 0x20000080, 13818 0x1e000: 0x0, 13819 0x1f000: 0x1040080, 13820 0x10800: 0x21000080, 13821 0x11800: 0x1000000, 13822 0x12800: 0x1040000, 13823 0x13800: 0x20040080, 13824 0x14800: 0x20000000, 13825 0x15800: 0x1040080, 13826 0x16800: 0x80, 13827 0x17800: 0x21040000, 13828 0x18800: 0x40080, 13829 0x19800: 0x21040080, 13830 0x1a800: 0x0, 13831 0x1b800: 0x21000000, 13832 0x1c800: 0x1000080, 13833 0x1d800: 0x40000, 13834 0x1e800: 0x20040000, 13835 0x1f800: 0x20000080, 13836 }, 13837 { 13838 0x0: 0x10000008, 13839 0x100: 0x2000, 13840 0x200: 0x10200000, 13841 0x300: 0x10202008, 13842 0x400: 0x10002000, 13843 0x500: 0x200000, 13844 0x600: 0x200008, 13845 0x700: 0x10000000, 13846 0x800: 0x0, 13847 0x900: 0x10002008, 13848 0xa00: 0x202000, 13849 0xb00: 0x8, 13850 0xc00: 0x10200008, 13851 0xd00: 0x202008, 13852 0xe00: 0x2008, 13853 0xf00: 0x10202000, 13854 0x80: 0x10200000, 13855 0x180: 0x10202008, 13856 0x280: 0x8, 13857 0x380: 0x200000, 13858 0x480: 0x202008, 13859 0x580: 0x10000008, 13860 0x680: 0x10002000, 13861 0x780: 0x2008, 13862 0x880: 0x200008, 13863 0x980: 0x2000, 13864 0xa80: 0x10002008, 13865 0xb80: 0x10200008, 13866 0xc80: 0x0, 13867 0xd80: 0x10202000, 13868 0xe80: 0x202000, 13869 0xf80: 0x10000000, 13870 0x1000: 0x10002000, 13871 0x1100: 0x10200008, 13872 0x1200: 0x10202008, 13873 0x1300: 0x2008, 13874 0x1400: 0x200000, 13875 0x1500: 0x10000000, 13876 0x1600: 0x10000008, 13877 0x1700: 0x202000, 13878 0x1800: 0x202008, 13879 0x1900: 0x0, 13880 0x1a00: 0x8, 13881 0x1b00: 0x10200000, 13882 0x1c00: 0x2000, 13883 0x1d00: 0x10002008, 13884 0x1e00: 0x10202000, 13885 0x1f00: 0x200008, 13886 0x1080: 0x8, 13887 0x1180: 0x202000, 13888 0x1280: 0x200000, 13889 0x1380: 0x10000008, 13890 0x1480: 0x10002000, 13891 0x1580: 0x2008, 13892 0x1680: 0x10202008, 13893 0x1780: 0x10200000, 13894 0x1880: 0x10202000, 13895 0x1980: 0x10200008, 13896 0x1a80: 0x2000, 13897 0x1b80: 0x202008, 13898 0x1c80: 0x200008, 13899 0x1d80: 0x0, 13900 0x1e80: 0x10000000, 13901 0x1f80: 0x10002008, 13902 }, 13903 { 13904 0x0: 0x100000, 13905 0x10: 0x2000401, 13906 0x20: 0x400, 13907 0x30: 0x100401, 13908 0x40: 0x2100401, 13909 0x50: 0x0, 13910 0x60: 0x1, 13911 0x70: 0x2100001, 13912 0x80: 0x2000400, 13913 0x90: 0x100001, 13914 0xa0: 0x2000001, 13915 0xb0: 0x2100400, 13916 0xc0: 0x2100000, 13917 0xd0: 0x401, 13918 0xe0: 0x100400, 13919 0xf0: 0x2000000, 13920 0x8: 0x2100001, 13921 0x18: 0x0, 13922 0x28: 0x2000401, 13923 0x38: 0x2100400, 13924 0x48: 0x100000, 13925 0x58: 0x2000001, 13926 0x68: 0x2000000, 13927 0x78: 0x401, 13928 0x88: 0x100401, 13929 0x98: 0x2000400, 13930 0xa8: 0x2100000, 13931 0xb8: 0x100001, 13932 0xc8: 0x400, 13933 0xd8: 0x2100401, 13934 0xe8: 0x1, 13935 0xf8: 0x100400, 13936 0x100: 0x2000000, 13937 0x110: 0x100000, 13938 0x120: 0x2000401, 13939 0x130: 0x2100001, 13940 0x140: 0x100001, 13941 0x150: 0x2000400, 13942 0x160: 0x2100400, 13943 0x170: 0x100401, 13944 0x180: 0x401, 13945 0x190: 0x2100401, 13946 0x1a0: 0x100400, 13947 0x1b0: 0x1, 13948 0x1c0: 0x0, 13949 0x1d0: 0x2100000, 13950 0x1e0: 0x2000001, 13951 0x1f0: 0x400, 13952 0x108: 0x100400, 13953 0x118: 0x2000401, 13954 0x128: 0x2100001, 13955 0x138: 0x1, 13956 0x148: 0x2000000, 13957 0x158: 0x100000, 13958 0x168: 0x401, 13959 0x178: 0x2100400, 13960 0x188: 0x2000001, 13961 0x198: 0x2100000, 13962 0x1a8: 0x0, 13963 0x1b8: 0x2100401, 13964 0x1c8: 0x100401, 13965 0x1d8: 0x400, 13966 0x1e8: 0x2000400, 13967 0x1f8: 0x100001, 13968 }, 13969 { 13970 0x0: 0x8000820, 13971 0x1: 0x20000, 13972 0x2: 0x8000000, 13973 0x3: 0x20, 13974 0x4: 0x20020, 13975 0x5: 0x8020820, 13976 0x6: 0x8020800, 13977 0x7: 0x800, 13978 0x8: 0x8020000, 13979 0x9: 0x8000800, 13980 0xa: 0x20800, 13981 0xb: 0x8020020, 13982 0xc: 0x820, 13983 0xd: 0x0, 13984 0xe: 0x8000020, 13985 0xf: 0x20820, 13986 0x80000000: 0x800, 13987 0x80000001: 0x8020820, 13988 0x80000002: 0x8000820, 13989 0x80000003: 0x8000000, 13990 0x80000004: 0x8020000, 13991 0x80000005: 0x20800, 13992 0x80000006: 0x20820, 13993 0x80000007: 0x20, 13994 0x80000008: 0x8000020, 13995 0x80000009: 0x820, 13996 0x8000000a: 0x20020, 13997 0x8000000b: 0x8020800, 13998 0x8000000c: 0x0, 13999 0x8000000d: 0x8020020, 14000 0x8000000e: 0x8000800, 14001 0x8000000f: 0x20000, 14002 0x10: 0x20820, 14003 0x11: 0x8020800, 14004 0x12: 0x20, 14005 0x13: 0x800, 14006 0x14: 0x8000800, 14007 0x15: 0x8000020, 14008 0x16: 0x8020020, 14009 0x17: 0x20000, 14010 0x18: 0x0, 14011 0x19: 0x20020, 14012 0x1a: 0x8020000, 14013 0x1b: 0x8000820, 14014 0x1c: 0x8020820, 14015 0x1d: 0x20800, 14016 0x1e: 0x820, 14017 0x1f: 0x8000000, 14018 0x80000010: 0x20000, 14019 0x80000011: 0x800, 14020 0x80000012: 0x8020020, 14021 0x80000013: 0x20820, 14022 0x80000014: 0x20, 14023 0x80000015: 0x8020000, 14024 0x80000016: 0x8000000, 14025 0x80000017: 0x8000820, 14026 0x80000018: 0x8020820, 14027 0x80000019: 0x8000020, 14028 0x8000001a: 0x8000800, 14029 0x8000001b: 0x0, 14030 0x8000001c: 0x20800, 14031 0x8000001d: 0x820, 14032 0x8000001e: 0x20020, 14033 0x8000001f: 0x8020800, 14034 }, 14035 ]; 14036 14037 // Masks that select the SBOX input 14038 var SBOX_MASK = [ 14039 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 0x0001f800, 14040 0x00001f80, 0x000001f8, 0x8000001f, 14041 ]; 14042 14043 /** 14044 * DES block cipher algorithm. 14045 */ 14046 var DES = (C_algo.DES = BlockCipher.extend({ 14047 _doReset: function () { 14048 // Shortcuts 14049 var key = this._key; 14050 var keyWords = key.words; 14051 14052 // Select 56 bits according to PC1 14053 var keyBits = []; 14054 for (var i = 0; i < 56; i++) { 14055 var keyBitPos = PC1[i] - 1; 14056 keyBits[i] = 14057 (keyWords[keyBitPos >>> 5] >>> (31 - (keyBitPos % 32))) & 1; 14058 } 14059 14060 // Assemble 16 subkeys 14061 var subKeys = (this._subKeys = []); 14062 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 14063 // Create subkey 14064 var subKey = (subKeys[nSubKey] = []); 14065 14066 // Shortcut 14067 var bitShift = BIT_SHIFTS[nSubKey]; 14068 14069 // Select 48 bits according to PC2 14070 for (var i = 0; i < 24; i++) { 14071 // Select from the left 28 key bits 14072 subKey[(i / 6) | 0] |= 14073 keyBits[(PC2[i] - 1 + bitShift) % 28] << (31 - (i % 6)); 14074 14075 // Select from the right 28 key bits 14076 subKey[4 + ((i / 6) | 0)] |= 14077 keyBits[28 + ((PC2[i + 24] - 1 + bitShift) % 28)] << 14078 (31 - (i % 6)); 14079 } 14080 14081 // Since each subkey is applied to an expanded 32-bit input, 14082 // the subkey can be broken into 8 values scaled to 32-bits, 14083 // which allows the key to be used without expansion 14084 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 14085 for (var i = 1; i < 7; i++) { 14086 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 14087 } 14088 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 14089 } 14090 14091 // Compute inverse subkeys 14092 var invSubKeys = (this._invSubKeys = []); 14093 for (var i = 0; i < 16; i++) { 14094 invSubKeys[i] = subKeys[15 - i]; 14095 } 14096 }, 14097 14098 encryptBlock: function (M, offset) { 14099 this._doCryptBlock(M, offset, this._subKeys); 14100 }, 14101 14102 decryptBlock: function (M, offset) { 14103 this._doCryptBlock(M, offset, this._invSubKeys); 14104 }, 14105 14106 _doCryptBlock: function (M, offset, subKeys) { 14107 // Get input 14108 this._lBlock = M[offset]; 14109 this._rBlock = M[offset + 1]; 14110 14111 // Initial permutation 14112 exchangeLR.call(this, 4, 0x0f0f0f0f); 14113 exchangeLR.call(this, 16, 0x0000ffff); 14114 exchangeRL.call(this, 2, 0x33333333); 14115 exchangeRL.call(this, 8, 0x00ff00ff); 14116 exchangeLR.call(this, 1, 0x55555555); 14117 14118 // Rounds 14119 for (var round = 0; round < 16; round++) { 14120 // Shortcuts 14121 var subKey = subKeys[round]; 14122 var lBlock = this._lBlock; 14123 var rBlock = this._rBlock; 14124 14125 // Feistel function 14126 var f = 0; 14127 for (var i = 0; i < 8; i++) { 14128 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 14129 } 14130 this._lBlock = rBlock; 14131 this._rBlock = lBlock ^ f; 14132 } 14133 14134 // Undo swap from last round 14135 var t = this._lBlock; 14136 this._lBlock = this._rBlock; 14137 this._rBlock = t; 14138 14139 // Final permutation 14140 exchangeLR.call(this, 1, 0x55555555); 14141 exchangeRL.call(this, 8, 0x00ff00ff); 14142 exchangeRL.call(this, 2, 0x33333333); 14143 exchangeLR.call(this, 16, 0x0000ffff); 14144 exchangeLR.call(this, 4, 0x0f0f0f0f); 14145 14146 // Set output 14147 M[offset] = this._lBlock; 14148 M[offset + 1] = this._rBlock; 14149 }, 14150 14151 keySize: 64 / 32, 14152 14153 ivSize: 64 / 32, 14154 14155 blockSize: 64 / 32, 14156 })); 14157 14158 // Swap bits across the left and right words 14159 function exchangeLR(offset, mask) { 14160 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 14161 this._rBlock ^= t; 14162 this._lBlock ^= t << offset; 14163 } 14164 14165 function exchangeRL(offset, mask) { 14166 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 14167 this._lBlock ^= t; 14168 this._rBlock ^= t << offset; 14169 } 14170 14171 /** 14172 * Shortcut functions to the cipher's object interface. 14173 * 14174 * @example 14175 * 14176 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 14177 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 14178 */ 14179 C.DES = BlockCipher._createHelper(DES); 14180 14181 /** 14182 * Triple-DES block cipher algorithm. 14183 */ 14184 var TripleDES = (C_algo.TripleDES = BlockCipher.extend({ 14185 _doReset: function () { 14186 // Shortcuts 14187 var key = this._key; 14188 var keyWords = key.words; 14189 14190 // Create DES instances 14191 this._des1 = DES.createEncryptor( 14192 WordArray.create(keyWords.slice(0, 2)) 14193 ); 14194 this._des2 = DES.createEncryptor( 14195 WordArray.create(keyWords.slice(2, 4)) 14196 ); 14197 this._des3 = DES.createEncryptor( 14198 WordArray.create(keyWords.slice(4, 6)) 14199 ); 14200 }, 14201 14202 encryptBlock: function (M, offset) { 14203 this._des1.encryptBlock(M, offset); 14204 this._des2.decryptBlock(M, offset); 14205 this._des3.encryptBlock(M, offset); 14206 }, 14207 14208 decryptBlock: function (M, offset) { 14209 this._des3.decryptBlock(M, offset); 14210 this._des2.encryptBlock(M, offset); 14211 this._des1.decryptBlock(M, offset); 14212 }, 14213 14214 keySize: 192 / 32, 14215 14216 ivSize: 64 / 32, 14217 14218 blockSize: 64 / 32, 14219 })); 14220 14221 /** 14222 * Shortcut functions to the cipher's object interface. 14223 * 14224 * @example 14225 * 14226 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 14227 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 14228 */ 14229 C.TripleDES = BlockCipher._createHelper(TripleDES); 14230 })(); 14231 14232 return CryptoJS.TripleDES; 14233 }); 14234 }, 14235 { 14236 "./cipher-core": 52, 14237 "./core": 53, 14238 "./enc-base64": 54, 14239 "./evpkdf": 56, 14240 "./md5": 61, 14241 }, 14242 ], 14243 84: [ 14244 function (require, module, exports) { 14245 (function (root, factory) { 14246 if (typeof exports === "object") { 14247 // CommonJS 14248 module.exports = exports = factory(require("./core")); 14249 } else if (typeof define === "function" && define.amd) { 14250 // AMD 14251 define(["./core"], factory); 14252 } else { 14253 // Global (browser) 14254 factory(root.CryptoJS); 14255 } 14256 })(this, function (CryptoJS) { 14257 (function (undefined) { 14258 // Shortcuts 14259 var C = CryptoJS; 14260 var C_lib = C.lib; 14261 var Base = C_lib.Base; 14262 var X32WordArray = C_lib.WordArray; 14263 14264 /** 14265 * x64 namespace. 14266 */ 14267 var C_x64 = (C.x64 = {}); 14268 14269 /** 14270 * A 64-bit word. 14271 */ 14272 var X64Word = (C_x64.Word = Base.extend({ 14273 /** 14274 * Initializes a newly created 64-bit word. 14275 * 14276 * @param {number} high The high 32 bits. 14277 * @param {number} low The low 32 bits. 14278 * 14279 * @example 14280 * 14281 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 14282 */ 14283 init: function (high, low) { 14284 this.high = high; 14285 this.low = low; 14286 }, 14287 14288 /** 14289 * Bitwise NOTs this word. 14290 * 14291 * @return {X64Word} A new x64-Word object after negating. 14292 * 14293 * @example 14294 * 14295 * var negated = x64Word.not(); 14296 */ 14297 // not: function () { 14298 // var high = ~this.high; 14299 // var low = ~this.low; 14300 14301 // return X64Word.create(high, low); 14302 // }, 14303 14304 /** 14305 * Bitwise ANDs this word with the passed word. 14306 * 14307 * @param {X64Word} word The x64-Word to AND with this word. 14308 * 14309 * @return {X64Word} A new x64-Word object after ANDing. 14310 * 14311 * @example 14312 * 14313 * var anded = x64Word.and(anotherX64Word); 14314 */ 14315 // and: function (word) { 14316 // var high = this.high & word.high; 14317 // var low = this.low & word.low; 14318 14319 // return X64Word.create(high, low); 14320 // }, 14321 14322 /** 14323 * Bitwise ORs this word with the passed word. 14324 * 14325 * @param {X64Word} word The x64-Word to OR with this word. 14326 * 14327 * @return {X64Word} A new x64-Word object after ORing. 14328 * 14329 * @example 14330 * 14331 * var ored = x64Word.or(anotherX64Word); 14332 */ 14333 // or: function (word) { 14334 // var high = this.high | word.high; 14335 // var low = this.low | word.low; 14336 14337 // return X64Word.create(high, low); 14338 // }, 14339 14340 /** 14341 * Bitwise XORs this word with the passed word. 14342 * 14343 * @param {X64Word} word The x64-Word to XOR with this word. 14344 * 14345 * @return {X64Word} A new x64-Word object after XORing. 14346 * 14347 * @example 14348 * 14349 * var xored = x64Word.xor(anotherX64Word); 14350 */ 14351 // xor: function (word) { 14352 // var high = this.high ^ word.high; 14353 // var low = this.low ^ word.low; 14354 14355 // return X64Word.create(high, low); 14356 // }, 14357 14358 /** 14359 * Shifts this word n bits to the left. 14360 * 14361 * @param {number} n The number of bits to shift. 14362 * 14363 * @return {X64Word} A new x64-Word object after shifting. 14364 * 14365 * @example 14366 * 14367 * var shifted = x64Word.shiftL(25); 14368 */ 14369 // shiftL: function (n) { 14370 // if (n < 32) { 14371 // var high = (this.high << n) | (this.low >>> (32 - n)); 14372 // var low = this.low << n; 14373 // } else { 14374 // var high = this.low << (n - 32); 14375 // var low = 0; 14376 // } 14377 14378 // return X64Word.create(high, low); 14379 // }, 14380 14381 /** 14382 * Shifts this word n bits to the right. 14383 * 14384 * @param {number} n The number of bits to shift. 14385 * 14386 * @return {X64Word} A new x64-Word object after shifting. 14387 * 14388 * @example 14389 * 14390 * var shifted = x64Word.shiftR(7); 14391 */ 14392 // shiftR: function (n) { 14393 // if (n < 32) { 14394 // var low = (this.low >>> n) | (this.high << (32 - n)); 14395 // var high = this.high >>> n; 14396 // } else { 14397 // var low = this.high >>> (n - 32); 14398 // var high = 0; 14399 // } 14400 14401 // return X64Word.create(high, low); 14402 // }, 14403 14404 /** 14405 * Rotates this word n bits to the left. 14406 * 14407 * @param {number} n The number of bits to rotate. 14408 * 14409 * @return {X64Word} A new x64-Word object after rotating. 14410 * 14411 * @example 14412 * 14413 * var rotated = x64Word.rotL(25); 14414 */ 14415 // rotL: function (n) { 14416 // return this.shiftL(n).or(this.shiftR(64 - n)); 14417 // }, 14418 14419 /** 14420 * Rotates this word n bits to the right. 14421 * 14422 * @param {number} n The number of bits to rotate. 14423 * 14424 * @return {X64Word} A new x64-Word object after rotating. 14425 * 14426 * @example 14427 * 14428 * var rotated = x64Word.rotR(7); 14429 */ 14430 // rotR: function (n) { 14431 // return this.shiftR(n).or(this.shiftL(64 - n)); 14432 // }, 14433 14434 /** 14435 * Adds this word with the passed word. 14436 * 14437 * @param {X64Word} word The x64-Word to add with this word. 14438 * 14439 * @return {X64Word} A new x64-Word object after adding. 14440 * 14441 * @example 14442 * 14443 * var added = x64Word.add(anotherX64Word); 14444 */ 14445 // add: function (word) { 14446 // var low = (this.low + word.low) | 0; 14447 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 14448 // var high = (this.high + word.high + carry) | 0; 14449 14450 // return X64Word.create(high, low); 14451 // } 14452 })); 14453 14454 /** 14455 * An array of 64-bit words. 14456 * 14457 * @property {Array} words The array of CryptoJS.x64.Word objects. 14458 * @property {number} sigBytes The number of significant bytes in this word array. 14459 */ 14460 var X64WordArray = (C_x64.WordArray = Base.extend({ 14461 /** 14462 * Initializes a newly created word array. 14463 * 14464 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 14465 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 14466 * 14467 * @example 14468 * 14469 * var wordArray = CryptoJS.x64.WordArray.create(); 14470 * 14471 * var wordArray = CryptoJS.x64.WordArray.create([ 14472 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 14473 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 14474 * ]); 14475 * 14476 * var wordArray = CryptoJS.x64.WordArray.create([ 14477 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 14478 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 14479 * ], 10); 14480 */ 14481 init: function (words, sigBytes) { 14482 words = this.words = words || []; 14483 14484 if (sigBytes != undefined) { 14485 this.sigBytes = sigBytes; 14486 } else { 14487 this.sigBytes = words.length * 8; 14488 } 14489 }, 14490 14491 /** 14492 * Converts this 64-bit word array to a 32-bit word array. 14493 * 14494 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 14495 * 14496 * @example 14497 * 14498 * var x32WordArray = x64WordArray.toX32(); 14499 */ 14500 toX32: function () { 14501 // Shortcuts 14502 var x64Words = this.words; 14503 var x64WordsLength = x64Words.length; 14504 14505 // Convert 14506 var x32Words = []; 14507 for (var i = 0; i < x64WordsLength; i++) { 14508 var x64Word = x64Words[i]; 14509 x32Words.push(x64Word.high); 14510 x32Words.push(x64Word.low); 14511 } 14512 14513 return X32WordArray.create(x32Words, this.sigBytes); 14514 }, 14515 14516 /** 14517 * Creates a copy of this word array. 14518 * 14519 * @return {X64WordArray} The clone. 14520 * 14521 * @example 14522 * 14523 * var clone = x64WordArray.clone(); 14524 */ 14525 clone: function () { 14526 var clone = Base.clone.call(this); 14527 14528 // Clone "words" array 14529 var words = (clone.words = this.words.slice(0)); 14530 14531 // Clone each X64Word object 14532 var wordsLength = words.length; 14533 for (var i = 0; i < wordsLength; i++) { 14534 words[i] = words[i].clone(); 14535 } 14536 14537 return clone; 14538 }, 14539 })); 14540 })(); 14541 14542 return CryptoJS; 14543 }); 14544 }, 14545 { "./core": 53 }, 14546 ], 14547 85: [ 14548 function (require, module, exports) { 14549 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 14550 (function (root) { 14551 // Detect free variables `exports` 14552 var freeExports = typeof exports == "object" && exports; 14553 14554 // Detect free variable `module` 14555 var freeModule = 14556 typeof module == "object" && 14557 module && 14558 module.exports == freeExports && 14559 module; 14560 14561 // Detect free variable `global`, from Node.js or Browserified code, 14562 // and use it as `root` 14563 var freeGlobal = typeof global == "object" && global; 14564 if ( 14565 freeGlobal.global === freeGlobal || 14566 freeGlobal.window === freeGlobal 14567 ) { 14568 root = freeGlobal; 14569 } 14570 14571 /*--------------------------------------------------------------------------*/ 14572 14573 var stringFromCharCode = String.fromCharCode; 14574 14575 // Taken from https://mths.be/punycode 14576 function ucs2decode(string) { 14577 var output = []; 14578 var counter = 0; 14579 var length = string.length; 14580 var value; 14581 var extra; 14582 while (counter < length) { 14583 value = string.charCodeAt(counter++); 14584 if (value >= 0xd800 && value <= 0xdbff && counter < length) { 14585 // high surrogate, and there is a next character 14586 extra = string.charCodeAt(counter++); 14587 if ((extra & 0xfc00) == 0xdc00) { 14588 // low surrogate 14589 output.push( 14590 ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000 14591 ); 14592 } else { 14593 // unmatched surrogate; only append this code unit, in case the next 14594 // code unit is the high surrogate of a surrogate pair 14595 output.push(value); 14596 counter--; 14597 } 14598 } else { 14599 output.push(value); 14600 } 14601 } 14602 return output; 14603 } 14604 14605 // Taken from https://mths.be/punycode 14606 function ucs2encode(array) { 14607 var length = array.length; 14608 var index = -1; 14609 var value; 14610 var output = ""; 14611 while (++index < length) { 14612 value = array[index]; 14613 if (value > 0xffff) { 14614 value -= 0x10000; 14615 output += stringFromCharCode(((value >>> 10) & 0x3ff) | 0xd800); 14616 value = 0xdc00 | (value & 0x3ff); 14617 } 14618 output += stringFromCharCode(value); 14619 } 14620 return output; 14621 } 14622 14623 function checkScalarValue(codePoint) { 14624 if (codePoint >= 0xd800 && codePoint <= 0xdfff) { 14625 throw Error( 14626 "Lone surrogate U+" + 14627 codePoint.toString(16).toUpperCase() + 14628 " is not a scalar value" 14629 ); 14630 } 14631 } 14632 /*--------------------------------------------------------------------------*/ 14633 14634 function createByte(codePoint, shift) { 14635 return stringFromCharCode(((codePoint >> shift) & 0x3f) | 0x80); 14636 } 14637 14638 function encodeCodePoint(codePoint) { 14639 if ((codePoint & 0xffffff80) == 0) { 14640 // 1-byte sequence 14641 return stringFromCharCode(codePoint); 14642 } 14643 var symbol = ""; 14644 if ((codePoint & 0xfffff800) == 0) { 14645 // 2-byte sequence 14646 symbol = stringFromCharCode(((codePoint >> 6) & 0x1f) | 0xc0); 14647 } else if ((codePoint & 0xffff0000) == 0) { 14648 // 3-byte sequence 14649 checkScalarValue(codePoint); 14650 symbol = stringFromCharCode(((codePoint >> 12) & 0x0f) | 0xe0); 14651 symbol += createByte(codePoint, 6); 14652 } else if ((codePoint & 0xffe00000) == 0) { 14653 // 4-byte sequence 14654 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xf0); 14655 symbol += createByte(codePoint, 12); 14656 symbol += createByte(codePoint, 6); 14657 } 14658 symbol += stringFromCharCode((codePoint & 0x3f) | 0x80); 14659 return symbol; 14660 } 14661 14662 function utf8encode(string) { 14663 var codePoints = ucs2decode(string); 14664 var length = codePoints.length; 14665 var index = -1; 14666 var codePoint; 14667 var byteString = ""; 14668 while (++index < length) { 14669 codePoint = codePoints[index]; 14670 byteString += encodeCodePoint(codePoint); 14671 } 14672 return byteString; 14673 } 14674 14675 /*--------------------------------------------------------------------------*/ 14676 14677 function readContinuationByte() { 14678 if (byteIndex >= byteCount) { 14679 throw Error("Invalid byte index"); 14680 } 14681 14682 var continuationByte = byteArray[byteIndex] & 0xff; 14683 byteIndex++; 14684 14685 if ((continuationByte & 0xc0) == 0x80) { 14686 return continuationByte & 0x3f; 14687 } 14688 14689 // If we end up here, it’s not a continuation byte 14690 throw Error("Invalid continuation byte"); 14691 } 14692 14693 function decodeSymbol() { 14694 var byte1; 14695 var byte2; 14696 var byte3; 14697 var byte4; 14698 var codePoint; 14699 14700 if (byteIndex > byteCount) { 14701 throw Error("Invalid byte index"); 14702 } 14703 14704 if (byteIndex == byteCount) { 14705 return false; 14706 } 14707 14708 // Read first byte 14709 byte1 = byteArray[byteIndex] & 0xff; 14710 byteIndex++; 14711 14712 // 1-byte sequence (no continuation bytes) 14713 if ((byte1 & 0x80) == 0) { 14714 return byte1; 14715 } 14716 14717 // 2-byte sequence 14718 if ((byte1 & 0xe0) == 0xc0) { 14719 byte2 = readContinuationByte(); 14720 codePoint = ((byte1 & 0x1f) << 6) | byte2; 14721 if (codePoint >= 0x80) { 14722 return codePoint; 14723 } else { 14724 throw Error("Invalid continuation byte"); 14725 } 14726 } 14727 14728 // 3-byte sequence (may include unpaired surrogates) 14729 if ((byte1 & 0xf0) == 0xe0) { 14730 byte2 = readContinuationByte(); 14731 byte3 = readContinuationByte(); 14732 codePoint = ((byte1 & 0x0f) << 12) | (byte2 << 6) | byte3; 14733 if (codePoint >= 0x0800) { 14734 checkScalarValue(codePoint); 14735 return codePoint; 14736 } else { 14737 throw Error("Invalid continuation byte"); 14738 } 14739 } 14740 14741 // 4-byte sequence 14742 if ((byte1 & 0xf8) == 0xf0) { 14743 byte2 = readContinuationByte(); 14744 byte3 = readContinuationByte(); 14745 byte4 = readContinuationByte(); 14746 codePoint = 14747 ((byte1 & 0x07) << 0x12) | 14748 (byte2 << 0x0c) | 14749 (byte3 << 0x06) | 14750 byte4; 14751 if (codePoint >= 0x010000 && codePoint <= 0x10ffff) { 14752 return codePoint; 14753 } 14754 } 14755 14756 throw Error("Invalid UTF-8 detected"); 14757 } 14758 14759 var byteArray; 14760 var byteCount; 14761 var byteIndex; 14762 function utf8decode(byteString) { 14763 byteArray = ucs2decode(byteString); 14764 byteCount = byteArray.length; 14765 byteIndex = 0; 14766 var codePoints = []; 14767 var tmp; 14768 while ((tmp = decodeSymbol()) !== false) { 14769 codePoints.push(tmp); 14770 } 14771 return ucs2encode(codePoints); 14772 } 14773 14774 /*--------------------------------------------------------------------------*/ 14775 14776 var utf8 = { 14777 version: "2.1.2", 14778 encode: utf8encode, 14779 decode: utf8decode, 14780 }; 14781 14782 // Some AMD build optimizers, like r.js, check for specific condition patterns 14783 // like the following: 14784 if ( 14785 typeof define == "function" && 14786 typeof define.amd == "object" && 14787 define.amd 14788 ) { 14789 define(function () { 14790 return utf8; 14791 }); 14792 } else if (freeExports && !freeExports.nodeType) { 14793 if (freeModule) { 14794 // in Node.js or RingoJS v0.8.0+ 14795 freeModule.exports = utf8; 14796 } else { 14797 // in Narwhal or RingoJS v0.7.0- 14798 var object = {}; 14799 var hasOwnProperty = object.hasOwnProperty; 14800 for (var key in utf8) { 14801 hasOwnProperty.call(utf8, key) && 14802 (freeExports[key] = utf8[key]); 14803 } 14804 } 14805 } else { 14806 // in Rhino or a web browser 14807 root.utf8 = utf8; 14808 } 14809 })(this); 14810 }, 14811 {}, 14812 ], 14813 86: [ 14814 function (require, module, exports) { 14815 module.exports = XMLHttpRequest; 14816 }, 14817 {}, 14818 ], 14819 "bignumber.js": [ 14820 function (require, module, exports) { 14821 "use strict"; 14822 14823 module.exports = BigNumber; // jshint ignore:line 14824 }, 14825 {}, 14826 ], 14827 web3: [ 14828 function (require, module, exports) { 14829 var Web3 = require("./lib/web3"); 14830 14831 // dont override global variable 14832 if ( 14833 typeof window !== "undefined" && 14834 typeof window.Web3 === "undefined" 14835 ) { 14836 window.Web3 = Web3; 14837 } 14838 14839 module.exports = Web3; 14840 }, 14841 { "./lib/web3": 22 }, 14842 ], 14843 }, 14844 {}, 14845 ["web3"] 14846 ); 14847 //# sourceMappingURL=web3-light.js.map