github.com/tirogen/go-ethereum@v1.10.12-0.20221226051715-250cfede41b6/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 solidityType.isDynamicType(type) || solidityType.isDynamicArray(type); 691 }; 692 693 /** 694 * SolidityCoder prototype should be used to encode/decode solidity params of any type 695 */ 696 var SolidityCoder = function (types) { 697 this._types = types; 698 }; 699 700 /** 701 * This method should be used to transform type to SolidityType 702 * 703 * @method _requireType 704 * @param {String} type 705 * @returns {SolidityType} 706 * @throws {Error} throws if no matching type is found 707 */ 708 SolidityCoder.prototype._requireType = function (type) { 709 var solidityType = this._types.filter(function (t) { 710 return t.isType(type); 711 })[0]; 712 713 if (!solidityType) { 714 throw Error('invalid solidity type!: ' + type); 715 } 716 717 return solidityType; 718 }; 719 720 /** 721 * Should be used to encode plain param 722 * 723 * @method encodeParam 724 * @param {String} type 725 * @param {Object} plain param 726 * @return {String} encoded plain param 727 */ 728 SolidityCoder.prototype.encodeParam = function (type, param) { 729 return this.encodeParams([type], [param]); 730 }; 731 732 /** 733 * Should be used to encode list of params 734 * 735 * @method encodeParams 736 * @param {Array} types 737 * @param {Array} params 738 * @return {String} encoded list of params 739 */ 740 SolidityCoder.prototype.encodeParams = function (types, params) { 741 var solidityTypes = this.getSolidityTypes(types); 742 743 var encodeds = solidityTypes.map(function (solidityType, index) { 744 return solidityType.encode(params[index], types[index]); 745 }); 746 747 var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) { 748 var staticPartLength = solidityType.staticPartLength(types[index]); 749 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 750 751 return acc + (isDynamic(solidityTypes[index], types[index]) ? 32 : roundedStaticPartLength); 752 }, 0); 753 754 var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset); 755 756 return result; 757 }; 758 759 SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) { 760 var result = ''; 761 var self = this; 762 763 types.forEach(function (type, i) { 764 if (isDynamic(solidityTypes[i], types[i])) { 765 result += f.formatInputInt(dynamicOffset).encode(); 766 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 767 dynamicOffset += e.length / 2; 768 } else { 769 // don't add length to dynamicOffset. it's already counted 770 result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 771 } 772 773 // TODO: figure out nested arrays 774 }); 775 776 types.forEach(function (type, i) { 777 if (isDynamic(solidityTypes[i], types[i])) { 778 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 779 dynamicOffset += e.length / 2; 780 result += e; 781 } 782 }); 783 return result; 784 }; 785 786 // TODO: refactor whole encoding! 787 SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) { 788 var self = this; 789 if (solidityType.isDynamicArray(type)) { 790 return (function () { 791 // offset was already set 792 var nestedName = solidityType.nestedName(type); 793 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 794 var result = encoded[0]; 795 796 (function () { 797 var previousLength = 2; // in int 798 if (solidityType.isDynamicArray(nestedName)) { 799 for (var i = 1; i < encoded.length; i++) { 800 previousLength += +encoded[i - 1][0] || 0; 801 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 802 } 803 } 804 })(); 805 806 // first element is length, skip it 807 (function () { 808 for (var i = 0; i < encoded.length - 1; i++) { 809 var additionalOffset = result / 2; 810 result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset); 811 } 812 })(); 813 814 return result; 815 })(); 816 } else if (solidityType.isStaticArray(type)) { 817 return (function () { 818 var nestedName = solidityType.nestedName(type); 819 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 820 var result = ''; 821 822 if (solidityType.isDynamicArray(nestedName)) { 823 (function () { 824 var previousLength = 0; // in int 825 for (var i = 0; i < encoded.length; i++) { 826 // calculate length of previous item 827 previousLength += +(encoded[i - 1] || [])[0] || 0; 828 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 829 } 830 })(); 831 } 832 833 (function () { 834 for (var i = 0; i < encoded.length; i++) { 835 var additionalOffset = result / 2; 836 result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset); 837 } 838 })(); 839 840 return result; 841 })(); 842 } 843 844 return encoded; 845 }; 846 847 /** 848 * Should be used to decode bytes to plain param 849 * 850 * @method decodeParam 851 * @param {String} type 852 * @param {String} bytes 853 * @return {Object} plain param 854 */ 855 SolidityCoder.prototype.decodeParam = function (type, bytes) { 856 return this.decodeParams([type], bytes)[0]; 857 }; 858 859 /** 860 * Should be used to decode list of params 861 * 862 * @method decodeParam 863 * @param {Array} types 864 * @param {String} bytes 865 * @return {Array} array of plain params 866 */ 867 SolidityCoder.prototype.decodeParams = function (types, bytes) { 868 var solidityTypes = this.getSolidityTypes(types); 869 var offsets = this.getOffsets(types, solidityTypes); 870 871 return solidityTypes.map(function (solidityType, index) { 872 return solidityType.decode(bytes, offsets[index], types[index], index); 873 }); 874 }; 875 876 SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { 877 var lengths = solidityTypes.map(function (solidityType, index) { 878 return solidityType.staticPartLength(types[index]); 879 }); 880 881 for (var i = 1; i < lengths.length; i++) { 882 // sum with length of previous element 883 lengths[i] += lengths[i - 1]; 884 } 885 886 return lengths.map(function (length, index) { 887 // remove the current length, so the length is sum of previous elements 888 var staticPartLength = solidityTypes[index].staticPartLength(types[index]); 889 return length - staticPartLength; 890 }); 891 }; 892 893 SolidityCoder.prototype.getSolidityTypes = function (types) { 894 var self = this; 895 return types.map(function (type) { 896 return self._requireType(type); 897 }); 898 }; 899 900 var coder = new SolidityCoder([ 901 new SolidityTypeAddress(), 902 new SolidityTypeBool(), 903 new SolidityTypeInt(), 904 new SolidityTypeUInt(), 905 new SolidityTypeDynamicBytes(), 906 new SolidityTypeBytes(), 907 new SolidityTypeString(), 908 new SolidityTypeReal(), 909 new SolidityTypeUReal(), 910 ]); 911 912 module.exports = coder; 913 }, 914 { 915 './address': 4, 916 './bool': 5, 917 './bytes': 6, 918 './dynamicbytes': 8, 919 './formatters': 9, 920 './int': 10, 921 './real': 12, 922 './string': 13, 923 './uint': 15, 924 './ureal': 16, 925 }, 926 ], 927 8: [ 928 function (require, module, exports) { 929 var f = require('./formatters'); 930 var SolidityType = require('./type'); 931 932 var SolidityTypeDynamicBytes = function () { 933 this._inputFormatter = f.formatInputDynamicBytes; 934 this._outputFormatter = f.formatOutputDynamicBytes; 935 }; 936 937 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 938 SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 939 940 SolidityTypeDynamicBytes.prototype.isType = function (name) { 941 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 942 }; 943 944 SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 945 return true; 946 }; 947 948 module.exports = SolidityTypeDynamicBytes; 949 }, 950 { './formatters': 9, './type': 14 }, 951 ], 952 9: [ 953 function (require, module, exports) { 954 /* 955 This file is part of web3.js. 956 957 web3.js is free software: you can redistribute it and/or modify 958 it under the terms of the GNU Lesser General Public License as published by 959 the Free Software Foundation, either version 3 of the License, or 960 (at your option) any later version. 961 962 web3.js is distributed in the hope that it will be useful, 963 but WITHOUT ANY WARRANTY; without even the implied warranty of 964 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 965 GNU Lesser General Public License for more details. 966 967 You should have received a copy of the GNU Lesser General Public License 968 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 969 */ 970 /** 971 * @file formatters.js 972 * @author Marek Kotewicz <marek@ethdev.com> 973 * @date 2015 974 */ 975 976 var BigNumber = require('bignumber.js'); 977 var utils = require('../utils/utils'); 978 var c = require('../utils/config'); 979 var SolidityParam = require('./param'); 980 981 /** 982 * Formats input value to byte representation of int 983 * If value is negative, return it's two's complement 984 * If the value is floating point, round it down 985 * 986 * @method formatInputInt 987 * @param {String|Number|BigNumber} value that needs to be formatted 988 * @returns {SolidityParam} 989 */ 990 var formatInputInt = function (value) { 991 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 992 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 993 return new SolidityParam(result); 994 }; 995 996 /** 997 * Formats input bytes 998 * 999 * @method formatInputBytes 1000 * @param {String} 1001 * @returns {SolidityParam} 1002 */ 1003 var formatInputBytes = function (value) { 1004 var result = utils.toHex(value).substr(2); 1005 var l = Math.floor((result.length + 63) / 64); 1006 result = utils.padRight(result, l * 64); 1007 return new SolidityParam(result); 1008 }; 1009 1010 /** 1011 * Formats input bytes 1012 * 1013 * @method formatDynamicInputBytes 1014 * @param {String} 1015 * @returns {SolidityParam} 1016 */ 1017 var formatInputDynamicBytes = function (value) { 1018 var result = utils.toHex(value).substr(2); 1019 var length = result.length / 2; 1020 var l = Math.floor((result.length + 63) / 64); 1021 result = utils.padRight(result, l * 64); 1022 return new SolidityParam(formatInputInt(length).value + result); 1023 }; 1024 1025 /** 1026 * Formats input value to byte representation of string 1027 * 1028 * @method formatInputString 1029 * @param {String} 1030 * @returns {SolidityParam} 1031 */ 1032 var formatInputString = function (value) { 1033 var result = utils.fromUtf8(value).substr(2); 1034 var length = result.length / 2; 1035 var l = Math.floor((result.length + 63) / 64); 1036 result = utils.padRight(result, l * 64); 1037 return new SolidityParam(formatInputInt(length).value + result); 1038 }; 1039 1040 /** 1041 * Formats input value to byte representation of bool 1042 * 1043 * @method formatInputBool 1044 * @param {Boolean} 1045 * @returns {SolidityParam} 1046 */ 1047 var formatInputBool = function (value) { 1048 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 1049 return new SolidityParam(result); 1050 }; 1051 1052 /** 1053 * Formats input value to byte representation of real 1054 * Values are multiplied by 2^m and encoded as integers 1055 * 1056 * @method formatInputReal 1057 * @param {String|Number|BigNumber} 1058 * @returns {SolidityParam} 1059 */ 1060 var formatInputReal = function (value) { 1061 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1062 }; 1063 1064 /** 1065 * Check if input value is negative 1066 * 1067 * @method signedIsNegative 1068 * @param {String} value is hex format 1069 * @returns {Boolean} true if it is negative, otherwise false 1070 */ 1071 var signedIsNegative = function (value) { 1072 return new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1) === '1'; 1073 }; 1074 1075 /** 1076 * Formats right-aligned output bytes to int 1077 * 1078 * @method formatOutputInt 1079 * @param {SolidityParam} param 1080 * @returns {BigNumber} right-aligned output bytes formatted to big number 1081 */ 1082 var formatOutputInt = function (param) { 1083 var value = param.staticPart() || '0'; 1084 1085 // check if it's negative number 1086 // it is, return two's complement 1087 if (signedIsNegative(value)) { 1088 return new BigNumber(value, 16) 1089 .minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)) 1090 .minus(1); 1091 } 1092 return new BigNumber(value, 16); 1093 }; 1094 1095 /** 1096 * Formats right-aligned output bytes to uint 1097 * 1098 * @method formatOutputUInt 1099 * @param {SolidityParam} 1100 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1101 */ 1102 var formatOutputUInt = function (param) { 1103 var value = param.staticPart() || '0'; 1104 return new BigNumber(value, 16); 1105 }; 1106 1107 /** 1108 * Formats right-aligned output bytes to real 1109 * 1110 * @method formatOutputReal 1111 * @param {SolidityParam} 1112 * @returns {BigNumber} input bytes formatted to real 1113 */ 1114 var formatOutputReal = function (param) { 1115 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1116 }; 1117 1118 /** 1119 * Formats right-aligned output bytes to ureal 1120 * 1121 * @method formatOutputUReal 1122 * @param {SolidityParam} 1123 * @returns {BigNumber} input bytes formatted to ureal 1124 */ 1125 var formatOutputUReal = function (param) { 1126 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1127 }; 1128 1129 /** 1130 * Should be used to format output bool 1131 * 1132 * @method formatOutputBool 1133 * @param {SolidityParam} 1134 * @returns {Boolean} right-aligned input bytes formatted to bool 1135 */ 1136 var formatOutputBool = function (param) { 1137 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' 1138 ? true 1139 : false; 1140 }; 1141 1142 /** 1143 * Should be used to format output bytes 1144 * 1145 * @method formatOutputBytes 1146 * @param {SolidityParam} left-aligned hex representation of string 1147 * @param {String} name type name 1148 * @returns {String} hex string 1149 */ 1150 var formatOutputBytes = function (param, name) { 1151 var matches = name.match(/^bytes([0-9]*)/); 1152 var size = parseInt(matches[1]); 1153 return '0x' + param.staticPart().slice(0, 2 * size); 1154 }; 1155 1156 /** 1157 * Should be used to format output bytes 1158 * 1159 * @method formatOutputDynamicBytes 1160 * @param {SolidityParam} left-aligned hex representation of string 1161 * @returns {String} hex string 1162 */ 1163 var formatOutputDynamicBytes = function (param) { 1164 var length = new BigNumber(param.dynamicPart().slice(0, 64), 16).toNumber() * 2; 1165 return '0x' + param.dynamicPart().substr(64, length); 1166 }; 1167 1168 /** 1169 * Should be used to format output string 1170 * 1171 * @method formatOutputString 1172 * @param {SolidityParam} left-aligned hex representation of string 1173 * @returns {String} ascii string 1174 */ 1175 var formatOutputString = function (param) { 1176 var length = new BigNumber(param.dynamicPart().slice(0, 64), 16).toNumber() * 2; 1177 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1178 }; 1179 1180 /** 1181 * Should be used to format output address 1182 * 1183 * @method formatOutputAddress 1184 * @param {SolidityParam} right-aligned input bytes 1185 * @returns {String} address 1186 */ 1187 var formatOutputAddress = function (param) { 1188 var value = param.staticPart(); 1189 return '0x' + value.slice(value.length - 40, value.length); 1190 }; 1191 1192 module.exports = { 1193 formatInputInt: formatInputInt, 1194 formatInputBytes: formatInputBytes, 1195 formatInputDynamicBytes: formatInputDynamicBytes, 1196 formatInputString: formatInputString, 1197 formatInputBool: formatInputBool, 1198 formatInputReal: formatInputReal, 1199 formatOutputInt: formatOutputInt, 1200 formatOutputUInt: formatOutputUInt, 1201 formatOutputReal: formatOutputReal, 1202 formatOutputUReal: formatOutputUReal, 1203 formatOutputBool: formatOutputBool, 1204 formatOutputBytes: formatOutputBytes, 1205 formatOutputDynamicBytes: formatOutputDynamicBytes, 1206 formatOutputString: formatOutputString, 1207 formatOutputAddress: formatOutputAddress, 1208 }; 1209 }, 1210 { '../utils/config': 18, '../utils/utils': 20, './param': 11, 'bignumber.js': 'bignumber.js' }, 1211 ], 1212 10: [ 1213 function (require, module, exports) { 1214 var f = require('./formatters'); 1215 var SolidityType = require('./type'); 1216 1217 /** 1218 * SolidityTypeInt is a prootype that represents int type 1219 * It matches: 1220 * int 1221 * int[] 1222 * int[4] 1223 * int[][] 1224 * int[3][] 1225 * int[][6][], ... 1226 * int32 1227 * int64[] 1228 * int8[4] 1229 * int256[][] 1230 * int[3][] 1231 * int64[][6][], ... 1232 */ 1233 var SolidityTypeInt = function () { 1234 this._inputFormatter = f.formatInputInt; 1235 this._outputFormatter = f.formatOutputInt; 1236 }; 1237 1238 SolidityTypeInt.prototype = new SolidityType({}); 1239 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1240 1241 SolidityTypeInt.prototype.isType = function (name) { 1242 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1243 }; 1244 1245 module.exports = SolidityTypeInt; 1246 }, 1247 { './formatters': 9, './type': 14 }, 1248 ], 1249 11: [ 1250 function (require, module, exports) { 1251 /* 1252 This file is part of web3.js. 1253 1254 web3.js is free software: you can redistribute it and/or modify 1255 it under the terms of the GNU Lesser General Public License as published by 1256 the Free Software Foundation, either version 3 of the License, or 1257 (at your option) any later version. 1258 1259 web3.js is distributed in the hope that it will be useful, 1260 but WITHOUT ANY WARRANTY; without even the implied warranty of 1261 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1262 GNU Lesser General Public License for more details. 1263 1264 You should have received a copy of the GNU Lesser General Public License 1265 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1266 */ 1267 /** 1268 * @file param.js 1269 * @author Marek Kotewicz <marek@ethdev.com> 1270 * @date 2015 1271 */ 1272 1273 var utils = require('../utils/utils'); 1274 1275 /** 1276 * SolidityParam object prototype. 1277 * Should be used when encoding, decoding solidity bytes 1278 */ 1279 var SolidityParam = function (value, offset) { 1280 this.value = value || ''; 1281 this.offset = offset; // offset in bytes 1282 }; 1283 1284 /** 1285 * This method should be used to get length of params's dynamic part 1286 * 1287 * @method dynamicPartLength 1288 * @returns {Number} length of dynamic part (in bytes) 1289 */ 1290 SolidityParam.prototype.dynamicPartLength = function () { 1291 return this.dynamicPart().length / 2; 1292 }; 1293 1294 /** 1295 * This method should be used to create copy of solidity param with different offset 1296 * 1297 * @method withOffset 1298 * @param {Number} offset length in bytes 1299 * @returns {SolidityParam} new solidity param with applied offset 1300 */ 1301 SolidityParam.prototype.withOffset = function (offset) { 1302 return new SolidityParam(this.value, offset); 1303 }; 1304 1305 /** 1306 * This method should be used to combine solidity params together 1307 * eg. when appending an array 1308 * 1309 * @method combine 1310 * @param {SolidityParam} param with which we should combine 1311 * @param {SolidityParam} result of combination 1312 */ 1313 SolidityParam.prototype.combine = function (param) { 1314 return new SolidityParam(this.value + param.value); 1315 }; 1316 1317 /** 1318 * This method should be called to check if param has dynamic size. 1319 * If it has, it returns true, otherwise false 1320 * 1321 * @method isDynamic 1322 * @returns {Boolean} 1323 */ 1324 SolidityParam.prototype.isDynamic = function () { 1325 return this.offset !== undefined; 1326 }; 1327 1328 /** 1329 * This method should be called to transform offset to bytes 1330 * 1331 * @method offsetAsBytes 1332 * @returns {String} bytes representation of offset 1333 */ 1334 SolidityParam.prototype.offsetAsBytes = function () { 1335 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1336 }; 1337 1338 /** 1339 * This method should be called to get static part of param 1340 * 1341 * @method staticPart 1342 * @returns {String} offset if it is a dynamic param, otherwise value 1343 */ 1344 SolidityParam.prototype.staticPart = function () { 1345 if (!this.isDynamic()) { 1346 return this.value; 1347 } 1348 return this.offsetAsBytes(); 1349 }; 1350 1351 /** 1352 * This method should be called to get dynamic part of param 1353 * 1354 * @method dynamicPart 1355 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1356 */ 1357 SolidityParam.prototype.dynamicPart = function () { 1358 return this.isDynamic() ? this.value : ''; 1359 }; 1360 1361 /** 1362 * This method should be called to encode param 1363 * 1364 * @method encode 1365 * @returns {String} 1366 */ 1367 SolidityParam.prototype.encode = function () { 1368 return this.staticPart() + this.dynamicPart(); 1369 }; 1370 1371 /** 1372 * This method should be called to encode array of params 1373 * 1374 * @method encodeList 1375 * @param {Array[SolidityParam]} params 1376 * @returns {String} 1377 */ 1378 SolidityParam.encodeList = function (params) { 1379 // updating offsets 1380 var totalOffset = params.length * 32; 1381 var offsetParams = params.map(function (param) { 1382 if (!param.isDynamic()) { 1383 return param; 1384 } 1385 var offset = totalOffset; 1386 totalOffset += param.dynamicPartLength(); 1387 return param.withOffset(offset); 1388 }); 1389 1390 // encode everything! 1391 return offsetParams.reduce( 1392 function (result, param) { 1393 return result + param.dynamicPart(); 1394 }, 1395 offsetParams.reduce(function (result, param) { 1396 return result + param.staticPart(); 1397 }, '') 1398 ); 1399 }; 1400 1401 module.exports = SolidityParam; 1402 }, 1403 { '../utils/utils': 20 }, 1404 ], 1405 12: [ 1406 function (require, module, exports) { 1407 var f = require('./formatters'); 1408 var SolidityType = require('./type'); 1409 1410 /** 1411 * SolidityTypeReal is a prootype that represents real type 1412 * It matches: 1413 * real 1414 * real[] 1415 * real[4] 1416 * real[][] 1417 * real[3][] 1418 * real[][6][], ... 1419 * real32 1420 * real64[] 1421 * real8[4] 1422 * real256[][] 1423 * real[3][] 1424 * real64[][6][], ... 1425 */ 1426 var SolidityTypeReal = function () { 1427 this._inputFormatter = f.formatInputReal; 1428 this._outputFormatter = f.formatOutputReal; 1429 }; 1430 1431 SolidityTypeReal.prototype = new SolidityType({}); 1432 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1433 1434 SolidityTypeReal.prototype.isType = function (name) { 1435 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1436 }; 1437 1438 module.exports = SolidityTypeReal; 1439 }, 1440 { './formatters': 9, './type': 14 }, 1441 ], 1442 13: [ 1443 function (require, module, exports) { 1444 var f = require('./formatters'); 1445 var SolidityType = require('./type'); 1446 1447 var SolidityTypeString = function () { 1448 this._inputFormatter = f.formatInputString; 1449 this._outputFormatter = f.formatOutputString; 1450 }; 1451 1452 SolidityTypeString.prototype = new SolidityType({}); 1453 SolidityTypeString.prototype.constructor = SolidityTypeString; 1454 1455 SolidityTypeString.prototype.isType = function (name) { 1456 return !!name.match(/^string(\[([0-9]*)\])*$/); 1457 }; 1458 1459 SolidityTypeString.prototype.isDynamicType = function () { 1460 return true; 1461 }; 1462 1463 module.exports = SolidityTypeString; 1464 }, 1465 { './formatters': 9, './type': 14 }, 1466 ], 1467 14: [ 1468 function (require, module, exports) { 1469 var f = require('./formatters'); 1470 var SolidityParam = require('./param'); 1471 1472 /** 1473 * SolidityType prototype is used to encode/decode solidity params of certain type 1474 */ 1475 var SolidityType = function (config) { 1476 this._inputFormatter = config.inputFormatter; 1477 this._outputFormatter = config.outputFormatter; 1478 }; 1479 1480 /** 1481 * Should be used to determine if this SolidityType do match given name 1482 * 1483 * @method isType 1484 * @param {String} name 1485 * @return {Bool} true if type match this SolidityType, otherwise false 1486 */ 1487 SolidityType.prototype.isType = function (name) { 1488 throw 'this method should be overrwritten for type ' + name; 1489 }; 1490 1491 /** 1492 * Should be used to determine what is the length of static part in given type 1493 * 1494 * @method staticPartLength 1495 * @param {String} name 1496 * @return {Number} length of static part in bytes 1497 */ 1498 SolidityType.prototype.staticPartLength = function (name) { 1499 // If name isn't an array then treat it like a single element array. 1500 return (this.nestedTypes(name) || ['[1]']) 1501 .map(function (type) { 1502 // the length of the nested array 1503 return parseInt(type.slice(1, -1), 10) || 1; 1504 }) 1505 .reduce(function (previous, current) { 1506 return previous * current; 1507 // all basic types are 32 bytes long 1508 }, 32); 1509 }; 1510 1511 /** 1512 * Should be used to determine if type is dynamic array 1513 * eg: 1514 * "type[]" => true 1515 * "type[4]" => false 1516 * 1517 * @method isDynamicArray 1518 * @param {String} name 1519 * @return {Bool} true if the type is dynamic array 1520 */ 1521 SolidityType.prototype.isDynamicArray = function (name) { 1522 var nestedTypes = this.nestedTypes(name); 1523 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1524 }; 1525 1526 /** 1527 * Should be used to determine if type is static array 1528 * eg: 1529 * "type[]" => false 1530 * "type[4]" => true 1531 * 1532 * @method isStaticArray 1533 * @param {String} name 1534 * @return {Bool} true if the type is static array 1535 */ 1536 SolidityType.prototype.isStaticArray = function (name) { 1537 var nestedTypes = this.nestedTypes(name); 1538 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1539 }; 1540 1541 /** 1542 * Should return length of static array 1543 * eg. 1544 * "int[32]" => 32 1545 * "int256[14]" => 14 1546 * "int[2][3]" => 3 1547 * "int" => 1 1548 * "int[1]" => 1 1549 * "int[]" => 1 1550 * 1551 * @method staticArrayLength 1552 * @param {String} name 1553 * @return {Number} static array length 1554 */ 1555 SolidityType.prototype.staticArrayLength = function (name) { 1556 var nestedTypes = this.nestedTypes(name); 1557 if (nestedTypes) { 1558 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1559 } 1560 return 1; 1561 }; 1562 1563 /** 1564 * Should return nested type 1565 * eg. 1566 * "int[32]" => "int" 1567 * "int256[14]" => "int256" 1568 * "int[2][3]" => "int[2]" 1569 * "int" => "int" 1570 * "int[]" => "int" 1571 * 1572 * @method nestedName 1573 * @param {String} name 1574 * @return {String} nested name 1575 */ 1576 SolidityType.prototype.nestedName = function (name) { 1577 // remove last [] in name 1578 var nestedTypes = this.nestedTypes(name); 1579 if (!nestedTypes) { 1580 return name; 1581 } 1582 1583 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1584 }; 1585 1586 /** 1587 * Should return true if type has dynamic size by default 1588 * such types are "string", "bytes" 1589 * 1590 * @method isDynamicType 1591 * @param {String} name 1592 * @return {Bool} true if is dynamic, otherwise false 1593 */ 1594 SolidityType.prototype.isDynamicType = function () { 1595 return false; 1596 }; 1597 1598 /** 1599 * Should return array of nested types 1600 * eg. 1601 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1602 * "int[] => ["[]"] 1603 * "int" => null 1604 * 1605 * @method nestedTypes 1606 * @param {String} name 1607 * @return {Array} array of nested types 1608 */ 1609 SolidityType.prototype.nestedTypes = function (name) { 1610 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1611 return name.match(/(\[[0-9]*\])/g); 1612 }; 1613 1614 /** 1615 * Should be used to encode the value 1616 * 1617 * @method encode 1618 * @param {Object} value 1619 * @param {String} name 1620 * @return {String} encoded value 1621 */ 1622 SolidityType.prototype.encode = function (value, name) { 1623 var self = this; 1624 if (this.isDynamicArray(name)) { 1625 return (function () { 1626 var length = value.length; // in int 1627 var nestedName = self.nestedName(name); 1628 1629 var result = []; 1630 result.push(f.formatInputInt(length).encode()); 1631 1632 value.forEach(function (v) { 1633 result.push(self.encode(v, nestedName)); 1634 }); 1635 1636 return result; 1637 })(); 1638 } else if (this.isStaticArray(name)) { 1639 return (function () { 1640 var length = self.staticArrayLength(name); // in int 1641 var nestedName = self.nestedName(name); 1642 1643 var result = []; 1644 for (var i = 0; i < length; i++) { 1645 result.push(self.encode(value[i], nestedName)); 1646 } 1647 1648 return result; 1649 })(); 1650 } 1651 1652 return this._inputFormatter(value, name).encode(); 1653 }; 1654 1655 /** 1656 * Should be used to decode value from bytes 1657 * 1658 * @method decode 1659 * @param {String} bytes 1660 * @param {Number} offset in bytes 1661 * @param {String} name type name 1662 * @returns {Object} decoded value 1663 */ 1664 SolidityType.prototype.decode = function (bytes, offset, name) { 1665 var self = this; 1666 1667 if (this.isDynamicArray(name)) { 1668 return (function () { 1669 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1670 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1671 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1672 1673 var nestedName = self.nestedName(name); 1674 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1675 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1676 var result = []; 1677 1678 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1679 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1680 } 1681 1682 return result; 1683 })(); 1684 } else if (this.isStaticArray(name)) { 1685 return (function () { 1686 var length = self.staticArrayLength(name); // in int 1687 var arrayStart = offset; // in bytes 1688 1689 var nestedName = self.nestedName(name); 1690 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1691 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1692 var result = []; 1693 1694 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1695 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1696 } 1697 1698 return result; 1699 })(); 1700 } else if (this.isDynamicType(name)) { 1701 return (function () { 1702 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1703 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1704 var roundedLength = Math.floor((length + 31) / 32); // in int 1705 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, (1 + roundedLength) * 64), 0); 1706 return self._outputFormatter(param, name); 1707 })(); 1708 } 1709 1710 var length = this.staticPartLength(name); 1711 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1712 return this._outputFormatter(param, name); 1713 }; 1714 1715 module.exports = SolidityType; 1716 }, 1717 { './formatters': 9, './param': 11 }, 1718 ], 1719 15: [ 1720 function (require, module, exports) { 1721 var f = require('./formatters'); 1722 var SolidityType = require('./type'); 1723 1724 /** 1725 * SolidityTypeUInt is a prootype that represents uint type 1726 * It matches: 1727 * uint 1728 * uint[] 1729 * uint[4] 1730 * uint[][] 1731 * uint[3][] 1732 * uint[][6][], ... 1733 * uint32 1734 * uint64[] 1735 * uint8[4] 1736 * uint256[][] 1737 * uint[3][] 1738 * uint64[][6][], ... 1739 */ 1740 var SolidityTypeUInt = function () { 1741 this._inputFormatter = f.formatInputInt; 1742 this._outputFormatter = f.formatOutputUInt; 1743 }; 1744 1745 SolidityTypeUInt.prototype = new SolidityType({}); 1746 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1747 1748 SolidityTypeUInt.prototype.isType = function (name) { 1749 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1750 }; 1751 1752 module.exports = SolidityTypeUInt; 1753 }, 1754 { './formatters': 9, './type': 14 }, 1755 ], 1756 16: [ 1757 function (require, module, exports) { 1758 var f = require('./formatters'); 1759 var SolidityType = require('./type'); 1760 1761 /** 1762 * SolidityTypeUReal is a prootype that represents ureal type 1763 * It matches: 1764 * ureal 1765 * ureal[] 1766 * ureal[4] 1767 * ureal[][] 1768 * ureal[3][] 1769 * ureal[][6][], ... 1770 * ureal32 1771 * ureal64[] 1772 * ureal8[4] 1773 * ureal256[][] 1774 * ureal[3][] 1775 * ureal64[][6][], ... 1776 */ 1777 var SolidityTypeUReal = function () { 1778 this._inputFormatter = f.formatInputReal; 1779 this._outputFormatter = f.formatOutputUReal; 1780 }; 1781 1782 SolidityTypeUReal.prototype = new SolidityType({}); 1783 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1784 1785 SolidityTypeUReal.prototype.isType = function (name) { 1786 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1787 }; 1788 1789 module.exports = SolidityTypeUReal; 1790 }, 1791 { './formatters': 9, './type': 14 }, 1792 ], 1793 17: [ 1794 function (require, module, exports) { 1795 'use strict'; 1796 1797 // go env doesn't have and need XMLHttpRequest 1798 if (typeof XMLHttpRequest === 'undefined') { 1799 exports.XMLHttpRequest = {}; 1800 } else { 1801 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1802 } 1803 }, 1804 {}, 1805 ], 1806 18: [ 1807 function (require, module, exports) { 1808 /* 1809 This file is part of web3.js. 1810 1811 web3.js is free software: you can redistribute it and/or modify 1812 it under the terms of the GNU Lesser General Public License as published by 1813 the Free Software Foundation, either version 3 of the License, or 1814 (at your option) any later version. 1815 1816 web3.js is distributed in the hope that it will be useful, 1817 but WITHOUT ANY WARRANTY; without even the implied warranty of 1818 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1819 GNU Lesser General Public License for more details. 1820 1821 You should have received a copy of the GNU Lesser General Public License 1822 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1823 */ 1824 /** @file config.js 1825 * @authors: 1826 * Marek Kotewicz <marek@ethdev.com> 1827 * @date 2015 1828 */ 1829 1830 /** 1831 * Utils 1832 * 1833 * @module utils 1834 */ 1835 1836 /** 1837 * Utility functions 1838 * 1839 * @class [utils] config 1840 * @constructor 1841 */ 1842 1843 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1844 var BigNumber = require('bignumber.js'); 1845 1846 var ETH_UNITS = [ 1847 'wei', 1848 'kwei', 1849 'Mwei', 1850 'Gwei', 1851 'szabo', 1852 'finney', 1853 'femtoether', 1854 'picoether', 1855 'nanoether', 1856 'microether', 1857 'milliether', 1858 'nano', 1859 'micro', 1860 'milli', 1861 'ether', 1862 'grand', 1863 'Mether', 1864 'Gether', 1865 'Tether', 1866 'Pether', 1867 'Eether', 1868 'Zether', 1869 'Yether', 1870 'Nether', 1871 'Dether', 1872 'Vether', 1873 'Uether', 1874 ]; 1875 1876 module.exports = { 1877 ETH_PADDING: 32, 1878 ETH_SIGNATURE_LENGTH: 4, 1879 ETH_UNITS: ETH_UNITS, 1880 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1881 ETH_POLLING_TIMEOUT: 1000 / 2, 1882 defaultBlock: 'latest', 1883 defaultAccount: undefined, 1884 }; 1885 }, 1886 { 'bignumber.js': 'bignumber.js' }, 1887 ], 1888 19: [ 1889 function (require, module, exports) { 1890 /* 1891 This file is part of web3.js. 1892 1893 web3.js is free software: you can redistribute it and/or modify 1894 it under the terms of the GNU Lesser General Public License as published by 1895 the Free Software Foundation, either version 3 of the License, or 1896 (at your option) any later version. 1897 1898 web3.js is distributed in the hope that it will be useful, 1899 but WITHOUT ANY WARRANTY; without even the implied warranty of 1900 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1901 GNU Lesser General Public License for more details. 1902 1903 You should have received a copy of the GNU Lesser General Public License 1904 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1905 */ 1906 /** 1907 * @file sha3.js 1908 * @author Marek Kotewicz <marek@ethdev.com> 1909 * @date 2015 1910 */ 1911 1912 var CryptoJS = require('crypto-js'); 1913 var sha3 = require('crypto-js/sha3'); 1914 1915 module.exports = function (value, options) { 1916 if (options && options.encoding === 'hex') { 1917 if (value.length > 2 && value.substr(0, 2) === '0x') { 1918 value = value.substr(2); 1919 } 1920 value = CryptoJS.enc.Hex.parse(value); 1921 } 1922 1923 return sha3(value, { 1924 outputLength: 256, 1925 }).toString(); 1926 }; 1927 }, 1928 { 'crypto-js': 59, 'crypto-js/sha3': 80 }, 1929 ], 1930 20: [ 1931 function (require, module, exports) { 1932 /* 1933 This file is part of web3.js. 1934 1935 web3.js is free software: you can redistribute it and/or modify 1936 it under the terms of the GNU Lesser General Public License as published by 1937 the Free Software Foundation, either version 3 of the License, or 1938 (at your option) any later version. 1939 1940 web3.js is distributed in the hope that it will be useful, 1941 but WITHOUT ANY WARRANTY; without even the implied warranty of 1942 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1943 GNU Lesser General Public License for more details. 1944 1945 You should have received a copy of the GNU Lesser General Public License 1946 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1947 */ 1948 /** 1949 * @file utils.js 1950 * @author Marek Kotewicz <marek@ethdev.com> 1951 * @date 2015 1952 */ 1953 1954 /** 1955 * Utils 1956 * 1957 * @module utils 1958 */ 1959 1960 /** 1961 * Utility functions 1962 * 1963 * @class [utils] utils 1964 * @constructor 1965 */ 1966 1967 var BigNumber = require('bignumber.js'); 1968 var sha3 = require('./sha3.js'); 1969 var utf8 = require('utf8'); 1970 1971 var unitMap = { 1972 noether: '0', 1973 wei: '1', 1974 kwei: '1000', 1975 Kwei: '1000', 1976 babbage: '1000', 1977 femtoether: '1000', 1978 mwei: '1000000', 1979 Mwei: '1000000', 1980 lovelace: '1000000', 1981 picoether: '1000000', 1982 gwei: '1000000000', 1983 Gwei: '1000000000', 1984 shannon: '1000000000', 1985 nanoether: '1000000000', 1986 nano: '1000000000', 1987 szabo: '1000000000000', 1988 microether: '1000000000000', 1989 micro: '1000000000000', 1990 finney: '1000000000000000', 1991 milliether: '1000000000000000', 1992 milli: '1000000000000000', 1993 ether: '1000000000000000000', 1994 kether: '1000000000000000000000', 1995 grand: '1000000000000000000000', 1996 mether: '1000000000000000000000000', 1997 gether: '1000000000000000000000000000', 1998 tether: '1000000000000000000000000000000', 1999 }; 2000 2001 /** 2002 * Should be called to pad string to expected length 2003 * 2004 * @method padLeft 2005 * @param {String} string to be padded 2006 * @param {Number} characters that result string should have 2007 * @param {String} sign, by default 0 2008 * @returns {String} right aligned string 2009 */ 2010 var padLeft = function (string, chars, sign) { 2011 return new Array(chars - string.length + 1).join(sign ? sign : '0') + string; 2012 }; 2013 2014 /** 2015 * Should be called to pad string to expected length 2016 * 2017 * @method padRight 2018 * @param {String} string to be padded 2019 * @param {Number} characters that result string should have 2020 * @param {String} sign, by default 0 2021 * @returns {String} right aligned string 2022 */ 2023 var padRight = function (string, chars, sign) { 2024 return string + new Array(chars - string.length + 1).join(sign ? sign : '0'); 2025 }; 2026 2027 /** 2028 * Should be called to get utf8 from it's hex representation 2029 * 2030 * @method toUtf8 2031 * @param {String} string in hex 2032 * @returns {String} ascii string representation of hex value 2033 */ 2034 var toUtf8 = function (hex) { 2035 // Find termination 2036 var str = ''; 2037 var i = 0, 2038 l = hex.length; 2039 if (hex.substring(0, 2) === '0x') { 2040 i = 2; 2041 } 2042 for (; i < l; i += 2) { 2043 var code = parseInt(hex.substr(i, 2), 16); 2044 if (code === 0) break; 2045 str += String.fromCharCode(code); 2046 } 2047 2048 return utf8.decode(str); 2049 }; 2050 2051 /** 2052 * Should be called to get ascii from it's hex representation 2053 * 2054 * @method toAscii 2055 * @param {String} string in hex 2056 * @returns {String} ascii string representation of hex value 2057 */ 2058 var toAscii = function (hex) { 2059 // Find termination 2060 var str = ''; 2061 var i = 0, 2062 l = hex.length; 2063 if (hex.substring(0, 2) === '0x') { 2064 i = 2; 2065 } 2066 for (; i < l; i += 2) { 2067 var code = parseInt(hex.substr(i, 2), 16); 2068 str += String.fromCharCode(code); 2069 } 2070 2071 return str; 2072 }; 2073 2074 /** 2075 * Should be called to get hex representation (prefixed by 0x) of utf8 string 2076 * 2077 * @method fromUtf8 2078 * @param {String} string 2079 * @param {Number} optional padding 2080 * @returns {String} hex representation of input string 2081 */ 2082 var fromUtf8 = function (str) { 2083 str = utf8.encode(str); 2084 var hex = ''; 2085 for (var i = 0; i < str.length; i++) { 2086 var code = str.charCodeAt(i); 2087 if (code === 0) break; 2088 var n = code.toString(16); 2089 hex += n.length < 2 ? '0' + n : n; 2090 } 2091 2092 return '0x' + hex; 2093 }; 2094 2095 /** 2096 * Should be called to get hex representation (prefixed by 0x) of ascii string 2097 * 2098 * @method fromAscii 2099 * @param {String} string 2100 * @param {Number} optional padding 2101 * @returns {String} hex representation of input string 2102 */ 2103 var fromAscii = function (str) { 2104 var hex = ''; 2105 for (var i = 0; i < str.length; i++) { 2106 var code = str.charCodeAt(i); 2107 var n = code.toString(16); 2108 hex += n.length < 2 ? '0' + n : n; 2109 } 2110 2111 return '0x' + hex; 2112 }; 2113 2114 /** 2115 * Should be used to create full function/event name from json abi 2116 * 2117 * @method transformToFullName 2118 * @param {Object} json-abi 2119 * @return {String} full fnction/event name 2120 */ 2121 var transformToFullName = function (json) { 2122 if (json.name.indexOf('(') !== -1) { 2123 return json.name; 2124 } 2125 2126 var typeName = json.inputs 2127 .map(function (i) { 2128 return i.type; 2129 }) 2130 .join(); 2131 return json.name + '(' + typeName + ')'; 2132 }; 2133 2134 /** 2135 * Should be called to get display name of contract function 2136 * 2137 * @method extractDisplayName 2138 * @param {String} name of function/event 2139 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2140 */ 2141 var extractDisplayName = function (name) { 2142 var length = name.indexOf('('); 2143 return length !== -1 ? name.substr(0, length) : name; 2144 }; 2145 2146 /// @returns overloaded part of function/event name 2147 var extractTypeName = function (name) { 2148 /// TODO: make it invulnerable 2149 var length = name.indexOf('('); 2150 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ''; 2151 }; 2152 2153 /** 2154 * Converts value to it's decimal representation in string 2155 * 2156 * @method toDecimal 2157 * @param {String|Number|BigNumber} 2158 * @return {String} 2159 */ 2160 var toDecimal = function (value) { 2161 return toBigNumber(value).toNumber(); 2162 }; 2163 2164 /** 2165 * Converts value to it's hex representation 2166 * 2167 * @method fromDecimal 2168 * @param {String|Number|BigNumber} 2169 * @return {String} 2170 */ 2171 var fromDecimal = function (value) { 2172 var number = toBigNumber(value); 2173 var result = number.toString(16); 2174 2175 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2176 }; 2177 2178 /** 2179 * Auto converts any given value into it's hex representation. 2180 * 2181 * And even stringifys objects before. 2182 * 2183 * @method toHex 2184 * @param {String|Number|BigNumber|Object} 2185 * @return {String} 2186 */ 2187 var toHex = function (val) { 2188 /*jshint maxcomplexity: 8 */ 2189 2190 if (isBoolean(val)) return fromDecimal(+val); 2191 2192 if (isBigNumber(val)) return fromDecimal(val); 2193 2194 if (typeof val === 'object') return fromUtf8(JSON.stringify(val)); 2195 2196 // if its a negative number, pass it through fromDecimal 2197 if (isString(val)) { 2198 if (val.indexOf('-0x') === 0) return fromDecimal(val); 2199 else if (val.indexOf('0x') === 0) return val; 2200 else if (!isFinite(val)) return fromAscii(val); 2201 } 2202 2203 return fromDecimal(val); 2204 }; 2205 2206 /** 2207 * Returns value of unit in Wei 2208 * 2209 * @method getValueOfUnit 2210 * @param {String} unit the unit to convert to, default ether 2211 * @returns {BigNumber} value of the unit (in Wei) 2212 * @throws error if the unit is not correct:w 2213 */ 2214 var getValueOfUnit = function (unit) { 2215 unit = unit ? unit.toLowerCase() : 'ether'; 2216 var unitValue = unitMap[unit]; 2217 if (unitValue === undefined) { 2218 throw new Error( 2219 "This unit doesn't exists, please use the one of the following units" + JSON.stringify(unitMap, null, 2) 2220 ); 2221 } 2222 return new BigNumber(unitValue, 10); 2223 }; 2224 2225 /** 2226 * Takes a number of wei and converts it to any other ether unit. 2227 * 2228 * Possible units are: 2229 * SI Short SI Full Effigy Other 2230 * - kwei femtoether babbage 2231 * - mwei picoether lovelace 2232 * - gwei nanoether shannon nano 2233 * - -- microether szabo micro 2234 * - -- milliether finney milli 2235 * - ether -- -- 2236 * - kether -- grand 2237 * - mether 2238 * - gether 2239 * - tether 2240 * 2241 * @method fromWei 2242 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2243 * @param {String} unit the unit to convert to, default ether 2244 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2245 */ 2246 var fromWei = function (number, unit) { 2247 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2248 2249 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2250 }; 2251 2252 /** 2253 * Takes a number of a unit and converts it to wei. 2254 * 2255 * Possible units are: 2256 * SI Short SI Full Effigy Other 2257 * - kwei femtoether babbage 2258 * - mwei picoether lovelace 2259 * - gwei nanoether shannon nano 2260 * - -- microether szabo micro 2261 * - -- microether szabo micro 2262 * - -- milliether finney milli 2263 * - ether -- -- 2264 * - kether -- grand 2265 * - mether 2266 * - gether 2267 * - tether 2268 * 2269 * @method toWei 2270 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2271 * @param {String} unit the unit to convert from, default ether 2272 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2273 */ 2274 var toWei = function (number, unit) { 2275 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2276 2277 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2278 }; 2279 2280 /** 2281 * Takes an input and transforms it into a bignumber 2282 * 2283 * @method toBigNumber 2284 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2285 * @return {BigNumber} BigNumber 2286 */ 2287 var toBigNumber = function (number) { 2288 /*jshint maxcomplexity:5 */ 2289 number = number || 0; 2290 if (isBigNumber(number)) return number; 2291 2292 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2293 return new BigNumber(number.replace('0x', ''), 16); 2294 } 2295 2296 return new BigNumber(number.toString(10), 10); 2297 }; 2298 2299 /** 2300 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2301 * 2302 * @method toTwosComplement 2303 * @param {Number|String|BigNumber} 2304 * @return {BigNumber} 2305 */ 2306 var toTwosComplement = function (number) { 2307 var bigNumber = toBigNumber(number).round(); 2308 if (bigNumber.lessThan(0)) { 2309 return new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16) 2310 .plus(bigNumber) 2311 .plus(1); 2312 } 2313 return bigNumber; 2314 }; 2315 2316 /** 2317 * Checks if the given string is strictly an address 2318 * 2319 * @method isStrictAddress 2320 * @param {String} address the given HEX address 2321 * @return {Boolean} 2322 */ 2323 var isStrictAddress = function (address) { 2324 return /^0x[0-9a-f]{40}$/i.test(address); 2325 }; 2326 2327 /** 2328 * Checks if the given string is an address 2329 * 2330 * @method isAddress 2331 * @param {String} address the given HEX address 2332 * @return {Boolean} 2333 */ 2334 var isAddress = function (address) { 2335 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2336 // check if it has the basic requirements of an address 2337 return false; 2338 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2339 // If it's all small caps or all caps, return true 2340 return true; 2341 } else { 2342 // Otherwise check each case 2343 return isChecksumAddress(address); 2344 } 2345 }; 2346 2347 /** 2348 * Checks if the given string is a checksummed address 2349 * 2350 * @method isChecksumAddress 2351 * @param {String} address the given HEX address 2352 * @return {Boolean} 2353 */ 2354 var isChecksumAddress = function (address) { 2355 // Check each case 2356 address = address.replace('0x', ''); 2357 var addressHash = sha3(address.toLowerCase()); 2358 2359 for (var i = 0; i < 40; i++) { 2360 // the nth letter should be uppercase if the nth digit of casemap is 1 2361 if ( 2362 (parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || 2363 (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i]) 2364 ) { 2365 return false; 2366 } 2367 } 2368 return true; 2369 }; 2370 2371 /** 2372 * Makes a checksum address 2373 * 2374 * @method toChecksumAddress 2375 * @param {String} address the given HEX address 2376 * @return {String} 2377 */ 2378 var toChecksumAddress = function (address) { 2379 if (typeof address === 'undefined') return ''; 2380 2381 address = address.toLowerCase().replace('0x', ''); 2382 var addressHash = sha3(address); 2383 var checksumAddress = '0x'; 2384 2385 for (var i = 0; i < address.length; i++) { 2386 // If ith character is 9 to f then make it uppercase 2387 if (parseInt(addressHash[i], 16) > 7) { 2388 checksumAddress += address[i].toUpperCase(); 2389 } else { 2390 checksumAddress += address[i]; 2391 } 2392 } 2393 return checksumAddress; 2394 }; 2395 2396 /** 2397 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2398 * 2399 * @method toAddress 2400 * @param {String} address 2401 * @return {String} formatted address 2402 */ 2403 var toAddress = function (address) { 2404 if (isStrictAddress(address)) { 2405 return address; 2406 } 2407 2408 if (/^[0-9a-f]{40}$/.test(address)) { 2409 return '0x' + address; 2410 } 2411 2412 return '0x' + padLeft(toHex(address).substr(2), 40); 2413 }; 2414 2415 /** 2416 * Returns true if object is BigNumber, otherwise false 2417 * 2418 * @method isBigNumber 2419 * @param {Object} 2420 * @return {Boolean} 2421 */ 2422 var isBigNumber = function (object) { 2423 return ( 2424 object instanceof BigNumber || (object && object.constructor && object.constructor.name === 'BigNumber') 2425 ); 2426 }; 2427 2428 /** 2429 * Returns true if object is string, otherwise false 2430 * 2431 * @method isString 2432 * @param {Object} 2433 * @return {Boolean} 2434 */ 2435 var isString = function (object) { 2436 return typeof object === 'string' || (object && object.constructor && object.constructor.name === 'String'); 2437 }; 2438 2439 /** 2440 * Returns true if object is function, otherwise false 2441 * 2442 * @method isFunction 2443 * @param {Object} 2444 * @return {Boolean} 2445 */ 2446 var isFunction = function (object) { 2447 return typeof object === 'function'; 2448 }; 2449 2450 /** 2451 * Returns true if object is Objet, otherwise false 2452 * 2453 * @method isObject 2454 * @param {Object} 2455 * @return {Boolean} 2456 */ 2457 var isObject = function (object) { 2458 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2459 }; 2460 2461 /** 2462 * Returns true if object is boolean, otherwise false 2463 * 2464 * @method isBoolean 2465 * @param {Object} 2466 * @return {Boolean} 2467 */ 2468 var isBoolean = function (object) { 2469 return typeof object === 'boolean'; 2470 }; 2471 2472 /** 2473 * Returns true if object is array, otherwise false 2474 * 2475 * @method isArray 2476 * @param {Object} 2477 * @return {Boolean} 2478 */ 2479 var isArray = function (object) { 2480 return object instanceof Array; 2481 }; 2482 2483 /** 2484 * Returns true if given string is valid json object 2485 * 2486 * @method isJson 2487 * @param {String} 2488 * @return {Boolean} 2489 */ 2490 var isJson = function (str) { 2491 try { 2492 return !!JSON.parse(str); 2493 } catch (e) { 2494 return false; 2495 } 2496 }; 2497 2498 /** 2499 * Returns true if given string is a valid Ethereum block header bloom. 2500 * 2501 * @method isBloom 2502 * @param {String} hex encoded bloom filter 2503 * @return {Boolean} 2504 */ 2505 var isBloom = function (bloom) { 2506 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2507 return false; 2508 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2509 return true; 2510 } 2511 return false; 2512 }; 2513 2514 /** 2515 * Returns true if given string is a valid log topic. 2516 * 2517 * @method isTopic 2518 * @param {String} hex encoded topic 2519 * @return {Boolean} 2520 */ 2521 var isTopic = function (topic) { 2522 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2523 return false; 2524 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2525 return true; 2526 } 2527 return false; 2528 }; 2529 2530 module.exports = { 2531 padLeft: padLeft, 2532 padRight: padRight, 2533 toHex: toHex, 2534 toDecimal: toDecimal, 2535 fromDecimal: fromDecimal, 2536 toUtf8: toUtf8, 2537 toAscii: toAscii, 2538 fromUtf8: fromUtf8, 2539 fromAscii: fromAscii, 2540 transformToFullName: transformToFullName, 2541 extractDisplayName: extractDisplayName, 2542 extractTypeName: extractTypeName, 2543 toWei: toWei, 2544 fromWei: fromWei, 2545 toBigNumber: toBigNumber, 2546 toTwosComplement: toTwosComplement, 2547 toAddress: toAddress, 2548 isBigNumber: isBigNumber, 2549 isStrictAddress: isStrictAddress, 2550 isAddress: isAddress, 2551 isChecksumAddress: isChecksumAddress, 2552 toChecksumAddress: toChecksumAddress, 2553 isFunction: isFunction, 2554 isString: isString, 2555 isObject: isObject, 2556 isBoolean: isBoolean, 2557 isArray: isArray, 2558 isJson: isJson, 2559 isBloom: isBloom, 2560 isTopic: isTopic, 2561 }; 2562 }, 2563 { './sha3.js': 19, 'bignumber.js': 'bignumber.js', utf8: 85 }, 2564 ], 2565 21: [ 2566 function (require, module, exports) { 2567 module.exports = { 2568 version: '0.20.1', 2569 }; 2570 }, 2571 {}, 2572 ], 2573 22: [ 2574 function (require, module, exports) { 2575 /* 2576 This file is part of web3.js. 2577 2578 web3.js is free software: you can redistribute it and/or modify 2579 it under the terms of the GNU Lesser General Public License as published by 2580 the Free Software Foundation, either version 3 of the License, or 2581 (at your option) any later version. 2582 2583 web3.js is distributed in the hope that it will be useful, 2584 but WITHOUT ANY WARRANTY; without even the implied warranty of 2585 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2586 GNU Lesser General Public License for more details. 2587 2588 You should have received a copy of the GNU Lesser General Public License 2589 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2590 */ 2591 /** 2592 * @file web3.js 2593 * @authors: 2594 * Jeffrey Wilcke <jeff@ethdev.com> 2595 * Marek Kotewicz <marek@ethdev.com> 2596 * Marian Oancea <marian@ethdev.com> 2597 * Fabian Vogelsteller <fabian@ethdev.com> 2598 * Gav Wood <g@ethdev.com> 2599 * @date 2014 2600 */ 2601 2602 var RequestManager = require('./web3/requestmanager'); 2603 var Iban = require('./web3/iban'); 2604 var Eth = require('./web3/methods/eth'); 2605 var DB = require('./web3/methods/db'); 2606 var Shh = require('./web3/methods/shh'); 2607 var Net = require('./web3/methods/net'); 2608 var Personal = require('./web3/methods/personal'); 2609 var Swarm = require('./web3/methods/swarm'); 2610 var Settings = require('./web3/settings'); 2611 var version = require('./version.json'); 2612 var utils = require('./utils/utils'); 2613 var sha3 = require('./utils/sha3'); 2614 var extend = require('./web3/extend'); 2615 var Batch = require('./web3/batch'); 2616 var Property = require('./web3/property'); 2617 var HttpProvider = require('./web3/httpprovider'); 2618 var IpcProvider = require('./web3/ipcprovider'); 2619 var BigNumber = require('bignumber.js'); 2620 2621 function Web3(provider) { 2622 this._requestManager = new RequestManager(provider); 2623 this.currentProvider = provider; 2624 this.eth = new Eth(this); 2625 this.db = new DB(this); 2626 this.shh = new Shh(this); 2627 this.net = new Net(this); 2628 this.personal = new Personal(this); 2629 this.bzz = new Swarm(this); 2630 this.settings = new Settings(); 2631 this.version = { 2632 api: version.version, 2633 }; 2634 this.providers = { 2635 HttpProvider: HttpProvider, 2636 IpcProvider: IpcProvider, 2637 }; 2638 this._extend = extend(this); 2639 this._extend({ 2640 properties: properties(), 2641 }); 2642 } 2643 2644 // expose providers on the class 2645 Web3.providers = { 2646 HttpProvider: HttpProvider, 2647 IpcProvider: IpcProvider, 2648 }; 2649 2650 Web3.prototype.setProvider = function (provider) { 2651 this._requestManager.setProvider(provider); 2652 this.currentProvider = provider; 2653 }; 2654 2655 Web3.prototype.reset = function (keepIsSyncing) { 2656 this._requestManager.reset(keepIsSyncing); 2657 this.settings = new Settings(); 2658 }; 2659 2660 Web3.prototype.BigNumber = BigNumber; 2661 Web3.prototype.toHex = utils.toHex; 2662 Web3.prototype.toAscii = utils.toAscii; 2663 Web3.prototype.toUtf8 = utils.toUtf8; 2664 Web3.prototype.fromAscii = utils.fromAscii; 2665 Web3.prototype.fromUtf8 = utils.fromUtf8; 2666 Web3.prototype.toDecimal = utils.toDecimal; 2667 Web3.prototype.fromDecimal = utils.fromDecimal; 2668 Web3.prototype.toBigNumber = utils.toBigNumber; 2669 Web3.prototype.toWei = utils.toWei; 2670 Web3.prototype.fromWei = utils.fromWei; 2671 Web3.prototype.isAddress = utils.isAddress; 2672 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2673 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2674 Web3.prototype.isIBAN = utils.isIBAN; 2675 Web3.prototype.padLeft = utils.padLeft; 2676 Web3.prototype.padRight = utils.padRight; 2677 2678 Web3.prototype.sha3 = function (string, options) { 2679 return '0x' + sha3(string, options); 2680 }; 2681 2682 /** 2683 * Transforms direct icap to address 2684 */ 2685 Web3.prototype.fromICAP = function (icap) { 2686 var iban = new Iban(icap); 2687 return iban.address(); 2688 }; 2689 2690 var properties = function () { 2691 return [ 2692 new Property({ 2693 name: 'version.node', 2694 getter: 'web3_clientVersion', 2695 }), 2696 new Property({ 2697 name: 'version.network', 2698 getter: 'net_version', 2699 inputFormatter: utils.toDecimal, 2700 }), 2701 new Property({ 2702 name: 'version.ethereum', 2703 getter: 'eth_protocolVersion', 2704 inputFormatter: utils.toDecimal, 2705 }), 2706 new Property({ 2707 name: 'version.whisper', 2708 getter: 'shh_version', 2709 inputFormatter: utils.toDecimal, 2710 }), 2711 ]; 2712 }; 2713 2714 Web3.prototype.isConnected = function () { 2715 return this.currentProvider && this.currentProvider.isConnected(); 2716 }; 2717 2718 Web3.prototype.createBatch = function () { 2719 return new Batch(this); 2720 }; 2721 2722 module.exports = Web3; 2723 }, 2724 { 2725 './utils/sha3': 19, 2726 './utils/utils': 20, 2727 './version.json': 21, 2728 './web3/batch': 24, 2729 './web3/extend': 28, 2730 './web3/httpprovider': 32, 2731 './web3/iban': 33, 2732 './web3/ipcprovider': 34, 2733 './web3/methods/db': 37, 2734 './web3/methods/eth': 38, 2735 './web3/methods/net': 39, 2736 './web3/methods/personal': 40, 2737 './web3/methods/shh': 41, 2738 './web3/methods/swarm': 42, 2739 './web3/property': 45, 2740 './web3/requestmanager': 46, 2741 './web3/settings': 47, 2742 'bignumber.js': 'bignumber.js', 2743 }, 2744 ], 2745 23: [ 2746 function (require, module, exports) { 2747 /* 2748 This file is part of web3.js. 2749 2750 web3.js is free software: you can redistribute it and/or modify 2751 it under the terms of the GNU Lesser General Public License as published by 2752 the Free Software Foundation, either version 3 of the License, or 2753 (at your option) any later version. 2754 2755 web3.js is distributed in the hope that it will be useful, 2756 but WITHOUT ANY WARRANTY; without even the implied warranty of 2757 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2758 GNU Lesser General Public License for more details. 2759 2760 You should have received a copy of the GNU Lesser General Public License 2761 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2762 */ 2763 /** 2764 * @file allevents.js 2765 * @author Marek Kotewicz <marek@ethdev.com> 2766 * @date 2014 2767 */ 2768 2769 var sha3 = require('../utils/sha3'); 2770 var SolidityEvent = require('./event'); 2771 var formatters = require('./formatters'); 2772 var utils = require('../utils/utils'); 2773 var Filter = require('./filter'); 2774 var watches = require('./methods/watches'); 2775 2776 var AllSolidityEvents = function (requestManager, json, address) { 2777 this._requestManager = requestManager; 2778 this._json = json; 2779 this._address = address; 2780 }; 2781 2782 AllSolidityEvents.prototype.encode = function (options) { 2783 options = options || {}; 2784 var result = {}; 2785 2786 ['fromBlock', 'toBlock'] 2787 .filter(function (f) { 2788 return options[f] !== undefined; 2789 }) 2790 .forEach(function (f) { 2791 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2792 }); 2793 2794 result.address = this._address; 2795 2796 return result; 2797 }; 2798 2799 AllSolidityEvents.prototype.decode = function (data) { 2800 data.data = data.data || ''; 2801 data.topics = data.topics || []; 2802 2803 var eventTopic = data.topics[0].slice(2); 2804 var match = this._json.filter(function (j) { 2805 return eventTopic === sha3(utils.transformToFullName(j)); 2806 })[0]; 2807 2808 if (!match) { 2809 // cannot find matching event? 2810 console.warn('cannot find event for log'); 2811 return data; 2812 } 2813 2814 var event = new SolidityEvent(this._requestManager, match, this._address); 2815 return event.decode(data); 2816 }; 2817 2818 AllSolidityEvents.prototype.execute = function (options, callback) { 2819 if (utils.isFunction(arguments[arguments.length - 1])) { 2820 callback = arguments[arguments.length - 1]; 2821 if (arguments.length === 1) options = null; 2822 } 2823 2824 var o = this.encode(options); 2825 var formatter = this.decode.bind(this); 2826 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 2827 }; 2828 2829 AllSolidityEvents.prototype.attachToContract = function (contract) { 2830 var execute = this.execute.bind(this); 2831 contract.allEvents = execute; 2832 }; 2833 2834 module.exports = AllSolidityEvents; 2835 }, 2836 { 2837 '../utils/sha3': 19, 2838 '../utils/utils': 20, 2839 './event': 27, 2840 './filter': 29, 2841 './formatters': 30, 2842 './methods/watches': 43, 2843 }, 2844 ], 2845 24: [ 2846 function (require, module, exports) { 2847 /* 2848 This file is part of web3.js. 2849 2850 web3.js is free software: you can redistribute it and/or modify 2851 it under the terms of the GNU Lesser General Public License as published by 2852 the Free Software Foundation, either version 3 of the License, or 2853 (at your option) any later version. 2854 2855 web3.js is distributed in the hope that it will be useful, 2856 but WITHOUT ANY WARRANTY; without even the implied warranty of 2857 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2858 GNU Lesser General Public License for more details. 2859 2860 You should have received a copy of the GNU Lesser General Public License 2861 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2862 */ 2863 /** 2864 * @file batch.js 2865 * @author Marek Kotewicz <marek@ethdev.com> 2866 * @date 2015 2867 */ 2868 2869 var Jsonrpc = require('./jsonrpc'); 2870 var errors = require('./errors'); 2871 2872 var Batch = function (web3) { 2873 this.requestManager = web3._requestManager; 2874 this.requests = []; 2875 }; 2876 2877 /** 2878 * Should be called to add create new request to batch request 2879 * 2880 * @method add 2881 * @param {Object} jsonrpc requet object 2882 */ 2883 Batch.prototype.add = function (request) { 2884 this.requests.push(request); 2885 }; 2886 2887 /** 2888 * Should be called to execute batch request 2889 * 2890 * @method execute 2891 */ 2892 Batch.prototype.execute = function () { 2893 var requests = this.requests; 2894 this.requestManager.sendBatch(requests, function (err, results) { 2895 results = results || []; 2896 requests 2897 .map(function (request, index) { 2898 return results[index] || {}; 2899 }) 2900 .forEach(function (result, index) { 2901 if (requests[index].callback) { 2902 if (!Jsonrpc.isValidResponse(result)) { 2903 return requests[index].callback(errors.InvalidResponse(result)); 2904 } 2905 2906 requests[index].callback( 2907 null, 2908 requests[index].format ? requests[index].format(result.result) : result.result 2909 ); 2910 } 2911 }); 2912 }); 2913 }; 2914 2915 module.exports = Batch; 2916 }, 2917 { './errors': 26, './jsonrpc': 35 }, 2918 ], 2919 25: [ 2920 function (require, module, exports) { 2921 /* 2922 This file is part of web3.js. 2923 2924 web3.js is free software: you can redistribute it and/or modify 2925 it under the terms of the GNU Lesser General Public License as published by 2926 the Free Software Foundation, either version 3 of the License, or 2927 (at your option) any later version. 2928 2929 web3.js is distributed in the hope that it will be useful, 2930 but WITHOUT ANY WARRANTY; without even the implied warranty of 2931 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2932 GNU Lesser General Public License for more details. 2933 2934 You should have received a copy of the GNU Lesser General Public License 2935 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2936 */ 2937 /** 2938 * @file contract.js 2939 * @author Marek Kotewicz <marek@ethdev.com> 2940 * @date 2014 2941 */ 2942 2943 var utils = require('../utils/utils'); 2944 var coder = require('../solidity/coder'); 2945 var SolidityEvent = require('./event'); 2946 var SolidityFunction = require('./function'); 2947 var AllEvents = require('./allevents'); 2948 2949 /** 2950 * Should be called to encode constructor params 2951 * 2952 * @method encodeConstructorParams 2953 * @param {Array} abi 2954 * @param {Array} constructor params 2955 */ 2956 var encodeConstructorParams = function (abi, params) { 2957 return ( 2958 abi 2959 .filter(function (json) { 2960 return json.type === 'constructor' && json.inputs.length === params.length; 2961 }) 2962 .map(function (json) { 2963 return json.inputs.map(function (input) { 2964 return input.type; 2965 }); 2966 }) 2967 .map(function (types) { 2968 return coder.encodeParams(types, params); 2969 })[0] || '' 2970 ); 2971 }; 2972 2973 /** 2974 * Should be called to add functions to contract object 2975 * 2976 * @method addFunctionsToContract 2977 * @param {Contract} contract 2978 * @param {Array} abi 2979 */ 2980 var addFunctionsToContract = function (contract) { 2981 contract.abi 2982 .filter(function (json) { 2983 return json.type === 'function'; 2984 }) 2985 .map(function (json) { 2986 return new SolidityFunction(contract._eth, json, contract.address); 2987 }) 2988 .forEach(function (f) { 2989 f.attachToContract(contract); 2990 }); 2991 }; 2992 2993 /** 2994 * Should be called to add events to contract object 2995 * 2996 * @method addEventsToContract 2997 * @param {Contract} contract 2998 * @param {Array} abi 2999 */ 3000 var addEventsToContract = function (contract) { 3001 var events = contract.abi.filter(function (json) { 3002 return json.type === 'event'; 3003 }); 3004 3005 var All = new AllEvents(contract._eth._requestManager, events, contract.address); 3006 All.attachToContract(contract); 3007 3008 events 3009 .map(function (json) { 3010 return new SolidityEvent(contract._eth._requestManager, json, contract.address); 3011 }) 3012 .forEach(function (e) { 3013 e.attachToContract(contract); 3014 }); 3015 }; 3016 3017 /** 3018 * Should be called to check if the contract gets properly deployed on the blockchain. 3019 * 3020 * @method checkForContractAddress 3021 * @param {Object} contract 3022 * @param {Function} callback 3023 * @returns {Undefined} 3024 */ 3025 var checkForContractAddress = function (contract, callback) { 3026 var count = 0, 3027 callbackFired = false; 3028 3029 // wait for receipt 3030 var filter = contract._eth.filter('latest', function (e) { 3031 if (!e && !callbackFired) { 3032 count++; 3033 3034 // stop watching after 50 blocks (timeout) 3035 if (count > 50) { 3036 filter.stopWatching(function () {}); 3037 callbackFired = true; 3038 3039 if (callback) callback(new Error("Contract transaction couldn't be found after 50 blocks")); 3040 else throw new Error("Contract transaction couldn't be found after 50 blocks"); 3041 } else { 3042 contract._eth.getTransactionReceipt(contract.transactionHash, function (e, receipt) { 3043 if (receipt && !callbackFired) { 3044 contract._eth.getCode(receipt.contractAddress, function (e, code) { 3045 /*jshint maxcomplexity: 6 */ 3046 3047 if (callbackFired || !code) return; 3048 3049 filter.stopWatching(function () {}); 3050 callbackFired = true; 3051 3052 if (code.length > 3) { 3053 // console.log('Contract code deployed!'); 3054 3055 contract.address = receipt.contractAddress; 3056 3057 // attach events and methods again after we have 3058 addFunctionsToContract(contract); 3059 addEventsToContract(contract); 3060 3061 // call callback for the second time 3062 if (callback) callback(null, contract); 3063 } else { 3064 if (callback) 3065 callback(new Error("The contract code couldn't be stored, please check your gas amount.")); 3066 else throw new Error("The contract code couldn't be stored, please check your gas amount."); 3067 } 3068 }); 3069 } 3070 }); 3071 } 3072 } 3073 }); 3074 }; 3075 3076 /** 3077 * Should be called to create new ContractFactory instance 3078 * 3079 * @method ContractFactory 3080 * @param {Array} abi 3081 */ 3082 var ContractFactory = function (eth, abi) { 3083 this.eth = eth; 3084 this.abi = abi; 3085 3086 /** 3087 * Should be called to create new contract on a blockchain 3088 * 3089 * @method new 3090 * @param {Any} contract constructor param1 (optional) 3091 * @param {Any} contract constructor param2 (optional) 3092 * @param {Object} contract transaction object (required) 3093 * @param {Function} callback 3094 * @returns {Contract} returns contract instance 3095 */ 3096 this.new = function () { 3097 /*jshint maxcomplexity: 7 */ 3098 3099 var contract = new Contract(this.eth, this.abi); 3100 3101 // parse arguments 3102 var options = {}; // required! 3103 var callback; 3104 3105 var args = Array.prototype.slice.call(arguments); 3106 if (utils.isFunction(args[args.length - 1])) { 3107 callback = args.pop(); 3108 } 3109 3110 var last = args[args.length - 1]; 3111 if (utils.isObject(last) && !utils.isArray(last)) { 3112 options = args.pop(); 3113 } 3114 3115 if (options.value > 0) { 3116 var constructorAbi = 3117 abi.filter(function (json) { 3118 return json.type === 'constructor' && json.inputs.length === args.length; 3119 })[0] || {}; 3120 3121 if (!constructorAbi.payable) { 3122 throw new Error('Cannot send value to non-payable constructor'); 3123 } 3124 } 3125 3126 var bytes = encodeConstructorParams(this.abi, args); 3127 options.data += bytes; 3128 3129 if (callback) { 3130 // wait for the contract address and check if the code was deployed 3131 this.eth.sendTransaction(options, function (err, hash) { 3132 if (err) { 3133 callback(err); 3134 } else { 3135 // add the transaction hash 3136 contract.transactionHash = hash; 3137 3138 // call callback for the first time 3139 callback(null, contract); 3140 3141 checkForContractAddress(contract, callback); 3142 } 3143 }); 3144 } else { 3145 var hash = this.eth.sendTransaction(options); 3146 // add the transaction hash 3147 contract.transactionHash = hash; 3148 checkForContractAddress(contract); 3149 } 3150 3151 return contract; 3152 }; 3153 3154 this.new.getData = this.getData.bind(this); 3155 }; 3156 3157 /** 3158 * Should be called to create new ContractFactory 3159 * 3160 * @method contract 3161 * @param {Array} abi 3162 * @returns {ContractFactory} new contract factory 3163 */ 3164 //var contract = function (abi) { 3165 //return new ContractFactory(abi); 3166 //}; 3167 3168 /** 3169 * Should be called to get access to existing contract on a blockchain 3170 * 3171 * @method at 3172 * @param {Address} contract address (required) 3173 * @param {Function} callback {optional) 3174 * @returns {Contract} returns contract if no callback was passed, 3175 * otherwise calls callback function (err, contract) 3176 */ 3177 ContractFactory.prototype.at = function (address, callback) { 3178 var contract = new Contract(this.eth, this.abi, address); 3179 3180 // this functions are not part of prototype, 3181 // because we don't want to spoil the interface 3182 addFunctionsToContract(contract); 3183 addEventsToContract(contract); 3184 3185 if (callback) { 3186 callback(null, contract); 3187 } 3188 return contract; 3189 }; 3190 3191 /** 3192 * Gets the data, which is data to deploy plus constructor params 3193 * 3194 * @method getData 3195 */ 3196 ContractFactory.prototype.getData = function () { 3197 var options = {}; // required! 3198 var args = Array.prototype.slice.call(arguments); 3199 3200 var last = args[args.length - 1]; 3201 if (utils.isObject(last) && !utils.isArray(last)) { 3202 options = args.pop(); 3203 } 3204 3205 var bytes = encodeConstructorParams(this.abi, args); 3206 options.data += bytes; 3207 3208 return options.data; 3209 }; 3210 3211 /** 3212 * Should be called to create new contract instance 3213 * 3214 * @method Contract 3215 * @param {Array} abi 3216 * @param {Address} contract address 3217 */ 3218 var Contract = function (eth, abi, address) { 3219 this._eth = eth; 3220 this.transactionHash = null; 3221 this.address = address; 3222 this.abi = abi; 3223 }; 3224 3225 module.exports = ContractFactory; 3226 }, 3227 { '../solidity/coder': 7, '../utils/utils': 20, './allevents': 23, './event': 27, './function': 31 }, 3228 ], 3229 26: [ 3230 function (require, module, exports) { 3231 /* 3232 This file is part of web3.js. 3233 3234 web3.js is free software: you can redistribute it and/or modify 3235 it under the terms of the GNU Lesser General Public License as published by 3236 the Free Software Foundation, either version 3 of the License, or 3237 (at your option) any later version. 3238 3239 web3.js is distributed in the hope that it will be useful, 3240 but WITHOUT ANY WARRANTY; without even the implied warranty of 3241 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3242 GNU Lesser General Public License for more details. 3243 3244 You should have received a copy of the GNU Lesser General Public License 3245 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3246 */ 3247 /** 3248 * @file errors.js 3249 * @author Marek Kotewicz <marek@ethdev.com> 3250 * @date 2015 3251 */ 3252 3253 module.exports = { 3254 InvalidNumberOfSolidityArgs: function () { 3255 return new Error('Invalid number of arguments to Solidity function'); 3256 }, 3257 InvalidNumberOfRPCParams: function () { 3258 return new Error('Invalid number of input parameters to RPC method'); 3259 }, 3260 InvalidConnection: function (host) { 3261 return new Error("CONNECTION ERROR: Couldn't connect to node " + host + '.'); 3262 }, 3263 InvalidProvider: function () { 3264 return new Error('Provider not set or invalid'); 3265 }, 3266 InvalidResponse: function (result) { 3267 var message = 3268 !!result && !!result.error && !!result.error.message 3269 ? result.error.message 3270 : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3271 return new Error(message); 3272 }, 3273 ConnectionTimeout: function (ms) { 3274 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3275 }, 3276 }; 3277 }, 3278 {}, 3279 ], 3280 27: [ 3281 function (require, module, exports) { 3282 /* 3283 This file is part of web3.js. 3284 3285 web3.js is free software: you can redistribute it and/or modify 3286 it under the terms of the GNU Lesser General Public License as published by 3287 the Free Software Foundation, either version 3 of the License, or 3288 (at your option) any later version. 3289 3290 web3.js is distributed in the hope that it will be useful, 3291 but WITHOUT ANY WARRANTY; without even the implied warranty of 3292 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3293 GNU Lesser General Public License for more details. 3294 3295 You should have received a copy of the GNU Lesser General Public License 3296 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3297 */ 3298 /** 3299 * @file event.js 3300 * @author Marek Kotewicz <marek@ethdev.com> 3301 * @date 2014 3302 */ 3303 3304 var utils = require('../utils/utils'); 3305 var coder = require('../solidity/coder'); 3306 var formatters = require('./formatters'); 3307 var sha3 = require('../utils/sha3'); 3308 var Filter = require('./filter'); 3309 var watches = require('./methods/watches'); 3310 3311 /** 3312 * This prototype should be used to create event filters 3313 */ 3314 var SolidityEvent = function (requestManager, json, address) { 3315 this._requestManager = requestManager; 3316 this._params = json.inputs; 3317 this._name = utils.transformToFullName(json); 3318 this._address = address; 3319 this._anonymous = json.anonymous; 3320 }; 3321 3322 /** 3323 * Should be used to get filtered param types 3324 * 3325 * @method types 3326 * @param {Bool} decide if returned typed should be indexed 3327 * @return {Array} array of types 3328 */ 3329 SolidityEvent.prototype.types = function (indexed) { 3330 return this._params 3331 .filter(function (i) { 3332 return i.indexed === indexed; 3333 }) 3334 .map(function (i) { 3335 return i.type; 3336 }); 3337 }; 3338 3339 /** 3340 * Should be used to get event display name 3341 * 3342 * @method displayName 3343 * @return {String} event display name 3344 */ 3345 SolidityEvent.prototype.displayName = function () { 3346 return utils.extractDisplayName(this._name); 3347 }; 3348 3349 /** 3350 * Should be used to get event type name 3351 * 3352 * @method typeName 3353 * @return {String} event type name 3354 */ 3355 SolidityEvent.prototype.typeName = function () { 3356 return utils.extractTypeName(this._name); 3357 }; 3358 3359 /** 3360 * Should be used to get event signature 3361 * 3362 * @method signature 3363 * @return {String} event signature 3364 */ 3365 SolidityEvent.prototype.signature = function () { 3366 return sha3(this._name); 3367 }; 3368 3369 /** 3370 * Should be used to encode indexed params and options to one final object 3371 * 3372 * @method encode 3373 * @param {Object} indexed 3374 * @param {Object} options 3375 * @return {Object} everything combined together and encoded 3376 */ 3377 SolidityEvent.prototype.encode = function (indexed, options) { 3378 indexed = indexed || {}; 3379 options = options || {}; 3380 var result = {}; 3381 3382 ['fromBlock', 'toBlock'] 3383 .filter(function (f) { 3384 return options[f] !== undefined; 3385 }) 3386 .forEach(function (f) { 3387 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3388 }); 3389 3390 result.topics = []; 3391 3392 result.address = this._address; 3393 if (!this._anonymous) { 3394 result.topics.push('0x' + this.signature()); 3395 } 3396 3397 var indexedTopics = this._params 3398 .filter(function (i) { 3399 return i.indexed === true; 3400 }) 3401 .map(function (i) { 3402 var value = indexed[i.name]; 3403 if (value === undefined || value === null) { 3404 return null; 3405 } 3406 3407 if (utils.isArray(value)) { 3408 return value.map(function (v) { 3409 return '0x' + coder.encodeParam(i.type, v); 3410 }); 3411 } 3412 return '0x' + coder.encodeParam(i.type, value); 3413 }); 3414 3415 result.topics = result.topics.concat(indexedTopics); 3416 3417 return result; 3418 }; 3419 3420 /** 3421 * Should be used to decode indexed params and options 3422 * 3423 * @method decode 3424 * @param {Object} data 3425 * @return {Object} result object with decoded indexed && not indexed params 3426 */ 3427 SolidityEvent.prototype.decode = function (data) { 3428 data.data = data.data || ''; 3429 data.topics = data.topics || []; 3430 3431 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3432 var indexedData = argTopics 3433 .map(function (topics) { 3434 return topics.slice(2); 3435 }) 3436 .join(''); 3437 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3438 3439 var notIndexedData = data.data.slice(2); 3440 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3441 3442 var result = formatters.outputLogFormatter(data); 3443 result.event = this.displayName(); 3444 result.address = data.address; 3445 3446 result.args = this._params.reduce(function (acc, current) { 3447 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3448 return acc; 3449 }, {}); 3450 3451 delete result.data; 3452 delete result.topics; 3453 3454 return result; 3455 }; 3456 3457 /** 3458 * Should be used to create new filter object from event 3459 * 3460 * @method execute 3461 * @param {Object} indexed 3462 * @param {Object} options 3463 * @return {Object} filter object 3464 */ 3465 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3466 if (utils.isFunction(arguments[arguments.length - 1])) { 3467 callback = arguments[arguments.length - 1]; 3468 if (arguments.length === 2) options = null; 3469 if (arguments.length === 1) { 3470 options = null; 3471 indexed = {}; 3472 } 3473 } 3474 3475 var o = this.encode(indexed, options); 3476 var formatter = this.decode.bind(this); 3477 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 3478 }; 3479 3480 /** 3481 * Should be used to attach event to contract object 3482 * 3483 * @method attachToContract 3484 * @param {Contract} 3485 */ 3486 SolidityEvent.prototype.attachToContract = function (contract) { 3487 var execute = this.execute.bind(this); 3488 var displayName = this.displayName(); 3489 if (!contract[displayName]) { 3490 contract[displayName] = execute; 3491 } 3492 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3493 }; 3494 3495 module.exports = SolidityEvent; 3496 }, 3497 { 3498 '../solidity/coder': 7, 3499 '../utils/sha3': 19, 3500 '../utils/utils': 20, 3501 './filter': 29, 3502 './formatters': 30, 3503 './methods/watches': 43, 3504 }, 3505 ], 3506 28: [ 3507 function (require, module, exports) { 3508 var formatters = require('./formatters'); 3509 var utils = require('./../utils/utils'); 3510 var Method = require('./method'); 3511 var Property = require('./property'); 3512 3513 // TODO: refactor, so the input params are not altered. 3514 // it's necessary to make same 'extension' work with multiple providers 3515 var extend = function (web3) { 3516 /* jshint maxcomplexity:5 */ 3517 var ex = function (extension) { 3518 var extendedObject; 3519 if (extension.property) { 3520 if (!web3[extension.property]) { 3521 web3[extension.property] = {}; 3522 } 3523 extendedObject = web3[extension.property]; 3524 } else { 3525 extendedObject = web3; 3526 } 3527 3528 if (extension.methods) { 3529 extension.methods.forEach(function (method) { 3530 method.attachToObject(extendedObject); 3531 method.setRequestManager(web3._requestManager); 3532 }); 3533 } 3534 3535 if (extension.properties) { 3536 extension.properties.forEach(function (property) { 3537 property.attachToObject(extendedObject); 3538 property.setRequestManager(web3._requestManager); 3539 }); 3540 } 3541 }; 3542 3543 ex.formatters = formatters; 3544 ex.utils = utils; 3545 ex.Method = Method; 3546 ex.Property = Property; 3547 3548 return ex; 3549 }; 3550 3551 module.exports = extend; 3552 }, 3553 { './../utils/utils': 20, './formatters': 30, './method': 36, './property': 45 }, 3554 ], 3555 29: [ 3556 function (require, module, exports) { 3557 /* 3558 This file is part of web3.js. 3559 3560 web3.js is free software: you can redistribute it and/or modify 3561 it under the terms of the GNU Lesser General Public License as published by 3562 the Free Software Foundation, either version 3 of the License, or 3563 (at your option) any later version. 3564 3565 web3.js is distributed in the hope that it will be useful, 3566 but WITHOUT ANY WARRANTY; without even the implied warranty of 3567 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3568 GNU Lesser General Public License for more details. 3569 3570 You should have received a copy of the GNU Lesser General Public License 3571 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3572 */ 3573 /** @file filter.js 3574 * @authors: 3575 * Jeffrey Wilcke <jeff@ethdev.com> 3576 * Marek Kotewicz <marek@ethdev.com> 3577 * Marian Oancea <marian@ethdev.com> 3578 * Fabian Vogelsteller <fabian@ethdev.com> 3579 * Gav Wood <g@ethdev.com> 3580 * @date 2014 3581 */ 3582 3583 var formatters = require('./formatters'); 3584 var utils = require('../utils/utils'); 3585 3586 /** 3587 * Converts a given topic to a hex string, but also allows null values. 3588 * 3589 * @param {Mixed} value 3590 * @return {String} 3591 */ 3592 var toTopic = function (value) { 3593 if (value === null || typeof value === 'undefined') return null; 3594 3595 value = String(value); 3596 3597 if (value.indexOf('0x') === 0) return value; 3598 else return utils.fromUtf8(value); 3599 }; 3600 3601 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3602 /// @param should be string or object 3603 /// @returns options string or object 3604 var getOptions = function (options, type) { 3605 /*jshint maxcomplexity: 6 */ 3606 3607 if (utils.isString(options)) { 3608 return options; 3609 } 3610 3611 options = options || {}; 3612 3613 switch (type) { 3614 case 'eth': 3615 // make sure topics, get converted to hex 3616 options.topics = options.topics || []; 3617 options.topics = options.topics.map(function (topic) { 3618 return utils.isArray(topic) ? topic.map(toTopic) : toTopic(topic); 3619 }); 3620 3621 return { 3622 topics: options.topics, 3623 from: options.from, 3624 to: options.to, 3625 address: options.address, 3626 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3627 toBlock: formatters.inputBlockNumberFormatter(options.toBlock), 3628 }; 3629 case 'shh': 3630 return options; 3631 } 3632 }; 3633 3634 /** 3635 Adds the callback and sets up the methods, to iterate over the results. 3636 3637 @method getLogsAtStart 3638 @param {Object} self 3639 @param {function} callback 3640 */ 3641 var getLogsAtStart = function (self, callback) { 3642 // call getFilterLogs for the first watch callback start 3643 if (!utils.isString(self.options)) { 3644 self.get(function (err, messages) { 3645 // don't send all the responses to all the watches again... just to self one 3646 if (err) { 3647 callback(err); 3648 } 3649 3650 if (utils.isArray(messages)) { 3651 messages.forEach(function (message) { 3652 callback(null, message); 3653 }); 3654 } 3655 }); 3656 } 3657 }; 3658 3659 /** 3660 Adds the callback and sets up the methods, to iterate over the results. 3661 3662 @method pollFilter 3663 @param {Object} self 3664 */ 3665 var pollFilter = function (self) { 3666 var onMessage = function (error, messages) { 3667 if (error) { 3668 return self.callbacks.forEach(function (callback) { 3669 callback(error); 3670 }); 3671 } 3672 3673 if (utils.isArray(messages)) { 3674 messages.forEach(function (message) { 3675 message = self.formatter ? self.formatter(message) : message; 3676 self.callbacks.forEach(function (callback) { 3677 callback(null, message); 3678 }); 3679 }); 3680 } 3681 }; 3682 3683 self.requestManager.startPolling( 3684 { 3685 method: self.implementation.poll.call, 3686 params: [self.filterId], 3687 }, 3688 self.filterId, 3689 onMessage, 3690 self.stopWatching.bind(self) 3691 ); 3692 }; 3693 3694 var Filter = function ( 3695 options, 3696 type, 3697 requestManager, 3698 methods, 3699 formatter, 3700 callback, 3701 filterCreationErrorCallback 3702 ) { 3703 var self = this; 3704 var implementation = {}; 3705 methods.forEach(function (method) { 3706 method.setRequestManager(requestManager); 3707 method.attachToObject(implementation); 3708 }); 3709 this.requestManager = requestManager; 3710 this.options = getOptions(options, type); 3711 this.implementation = implementation; 3712 this.filterId = null; 3713 this.callbacks = []; 3714 this.getLogsCallbacks = []; 3715 this.pollFilters = []; 3716 this.formatter = formatter; 3717 this.implementation.newFilter(this.options, function (error, id) { 3718 if (error) { 3719 self.callbacks.forEach(function (cb) { 3720 cb(error); 3721 }); 3722 if (typeof filterCreationErrorCallback === 'function') { 3723 filterCreationErrorCallback(error); 3724 } 3725 } else { 3726 self.filterId = id; 3727 3728 // check if there are get pending callbacks as a consequence 3729 // of calling get() with filterId unassigned. 3730 self.getLogsCallbacks.forEach(function (cb) { 3731 self.get(cb); 3732 }); 3733 self.getLogsCallbacks = []; 3734 3735 // get filter logs for the already existing watch calls 3736 self.callbacks.forEach(function (cb) { 3737 getLogsAtStart(self, cb); 3738 }); 3739 if (self.callbacks.length > 0) pollFilter(self); 3740 3741 // start to watch immediately 3742 if (typeof callback === 'function') { 3743 return self.watch(callback); 3744 } 3745 } 3746 }); 3747 3748 return this; 3749 }; 3750 3751 Filter.prototype.watch = function (callback) { 3752 this.callbacks.push(callback); 3753 3754 if (this.filterId) { 3755 getLogsAtStart(this, callback); 3756 pollFilter(this); 3757 } 3758 3759 return this; 3760 }; 3761 3762 Filter.prototype.stopWatching = function (callback) { 3763 this.requestManager.stopPolling(this.filterId); 3764 this.callbacks = []; 3765 // remove filter async 3766 if (callback) { 3767 this.implementation.uninstallFilter(this.filterId, callback); 3768 } else { 3769 return this.implementation.uninstallFilter(this.filterId); 3770 } 3771 }; 3772 3773 Filter.prototype.get = function (callback) { 3774 var self = this; 3775 if (utils.isFunction(callback)) { 3776 if (this.filterId === null) { 3777 // If filterId is not set yet, call it back 3778 // when newFilter() assigns it. 3779 this.getLogsCallbacks.push(callback); 3780 } else { 3781 this.implementation.getLogs(this.filterId, function (err, res) { 3782 if (err) { 3783 callback(err); 3784 } else { 3785 callback( 3786 null, 3787 res.map(function (log) { 3788 return self.formatter ? self.formatter(log) : log; 3789 }) 3790 ); 3791 } 3792 }); 3793 } 3794 } else { 3795 if (this.filterId === null) { 3796 throw new Error( 3797 "Filter ID Error: filter().get() can't be chained synchronous, please provide a callback for the get() method." 3798 ); 3799 } 3800 var logs = this.implementation.getLogs(this.filterId); 3801 return logs.map(function (log) { 3802 return self.formatter ? self.formatter(log) : log; 3803 }); 3804 } 3805 3806 return this; 3807 }; 3808 3809 module.exports = Filter; 3810 }, 3811 { '../utils/utils': 20, './formatters': 30 }, 3812 ], 3813 30: [ 3814 function (require, module, exports) { 3815 'use strict'; 3816 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 /** 3834 * @file formatters.js 3835 * @author Marek Kotewicz <marek@ethdev.com> 3836 * @author Fabian Vogelsteller <fabian@ethdev.com> 3837 * @date 2015 3838 */ 3839 3840 var utils = require('../utils/utils'); 3841 var config = require('../utils/config'); 3842 var Iban = require('./iban'); 3843 3844 /** 3845 * Should the format output to a big number 3846 * 3847 * @method outputBigNumberFormatter 3848 * @param {String|Number|BigNumber} 3849 * @returns {BigNumber} object 3850 */ 3851 var outputBigNumberFormatter = function (number) { 3852 return utils.toBigNumber(number); 3853 }; 3854 3855 var isPredefinedBlockNumber = function (blockNumber) { 3856 return ( 3857 blockNumber === 'latest' || 3858 blockNumber === 'pending' || 3859 blockNumber === 'earliest' || 3860 blockNumber === 'finalized' || 3861 blockNumber === 'safe' 3862 ); 3863 }; 3864 3865 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3866 if (blockNumber === undefined) { 3867 return config.defaultBlock; 3868 } 3869 return inputBlockNumberFormatter(blockNumber); 3870 }; 3871 3872 var inputBlockNumberFormatter = function (blockNumber) { 3873 if (blockNumber === undefined) { 3874 return undefined; 3875 } else if (isPredefinedBlockNumber(blockNumber)) { 3876 return blockNumber; 3877 } 3878 return utils.toHex(blockNumber); 3879 }; 3880 3881 /** 3882 * Formats the input of a transaction and converts all values to HEX 3883 * 3884 * @method inputCallFormatter 3885 * @param {Object} transaction options 3886 * @returns object 3887 */ 3888 var inputCallFormatter = function (options) { 3889 options.from = options.from || config.defaultAccount; 3890 3891 if (options.from) { 3892 options.from = inputAddressFormatter(options.from); 3893 } 3894 3895 if (options.to) { 3896 // it might be contract creation 3897 options.to = inputAddressFormatter(options.to); 3898 } 3899 3900 ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'] 3901 .filter(function (key) { 3902 return options[key] !== undefined; 3903 }) 3904 .forEach(function (key) { 3905 options[key] = utils.fromDecimal(options[key]); 3906 }); 3907 3908 return options; 3909 }; 3910 3911 /** 3912 * Formats the input of a transaction and converts all values to HEX 3913 * 3914 * @method inputTransactionFormatter 3915 * @param {Object} transaction options 3916 * @returns object 3917 */ 3918 var inputTransactionFormatter = function (options) { 3919 options.from = options.from || config.defaultAccount; 3920 options.from = inputAddressFormatter(options.from); 3921 3922 if (options.to) { 3923 // it might be contract creation 3924 options.to = inputAddressFormatter(options.to); 3925 } 3926 3927 ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'] 3928 .filter(function (key) { 3929 return options[key] !== undefined; 3930 }) 3931 .forEach(function (key) { 3932 options[key] = utils.fromDecimal(options[key]); 3933 }); 3934 3935 return options; 3936 }; 3937 3938 /** 3939 * Formats the output of a transaction to its proper values 3940 * 3941 * @method outputTransactionFormatter 3942 * @param {Object} tx 3943 * @returns {Object} 3944 */ 3945 var outputTransactionFormatter = function (tx) { 3946 if (tx.blockNumber !== null) tx.blockNumber = utils.toDecimal(tx.blockNumber); 3947 if (tx.transactionIndex !== null) tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3948 tx.nonce = utils.toDecimal(tx.nonce); 3949 tx.gas = utils.toDecimal(tx.gas); 3950 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3951 if (tx.maxFeePerGas !== undefined) { 3952 tx.maxFeePerGas = utils.toBigNumber(tx.maxFeePerGas); 3953 } 3954 if (tx.maxPriorityFeePerGas !== undefined) { 3955 tx.maxPriorityFeePerGas = utils.toBigNumber(tx.maxPriorityFeePerGas); 3956 } 3957 tx.value = utils.toBigNumber(tx.value); 3958 return tx; 3959 }; 3960 3961 /** 3962 * Formats the output of a transaction receipt to its proper values 3963 * 3964 * @method outputTransactionReceiptFormatter 3965 * @param {Object} receipt 3966 * @returns {Object} 3967 */ 3968 var outputTransactionReceiptFormatter = function (receipt) { 3969 if (receipt.blockNumber !== null) receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3970 if (receipt.transactionIndex !== null) receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3971 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3972 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3973 if (receipt.effectiveGasPrice !== undefined) { 3974 receipt.effectiveGasPrice = utils.toBigNumber(receipt.effectiveGasPrice); 3975 } 3976 if (utils.isArray(receipt.logs)) { 3977 receipt.logs = receipt.logs.map(function (log) { 3978 return outputLogFormatter(log); 3979 }); 3980 } 3981 3982 return receipt; 3983 }; 3984 3985 /** 3986 * Formats the output of a block to its proper values 3987 * 3988 * @method outputBlockFormatter 3989 * @param {Object} block 3990 * @returns {Object} 3991 */ 3992 var outputBlockFormatter = function (block) { 3993 // transform to number 3994 if (block.baseFeePerGas !== undefined) { 3995 block.baseFeePerGas = utils.toBigNumber(block.baseFeePerGas); 3996 } 3997 block.gasLimit = utils.toDecimal(block.gasLimit); 3998 block.gasUsed = utils.toDecimal(block.gasUsed); 3999 block.size = utils.toDecimal(block.size); 4000 block.timestamp = utils.toDecimal(block.timestamp); 4001 if (block.number !== null) block.number = utils.toDecimal(block.number); 4002 4003 block.difficulty = utils.toBigNumber(block.difficulty); 4004 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 4005 4006 if (utils.isArray(block.transactions)) { 4007 block.transactions.forEach(function (item) { 4008 if (!utils.isString(item)) return outputTransactionFormatter(item); 4009 }); 4010 } 4011 4012 return block; 4013 }; 4014 4015 /** 4016 * Formats the output of a log 4017 * 4018 * @method outputLogFormatter 4019 * @param {Object} log object 4020 * @returns {Object} log 4021 */ 4022 var outputLogFormatter = function (log) { 4023 if (log.blockNumber) log.blockNumber = utils.toDecimal(log.blockNumber); 4024 if (log.transactionIndex) log.transactionIndex = utils.toDecimal(log.transactionIndex); 4025 if (log.logIndex) log.logIndex = utils.toDecimal(log.logIndex); 4026 4027 return log; 4028 }; 4029 4030 /** 4031 * Formats the input of a whisper post and converts all values to HEX 4032 * 4033 * @method inputPostFormatter 4034 * @param {Object} transaction object 4035 * @returns {Object} 4036 */ 4037 var inputPostFormatter = function (post) { 4038 // post.payload = utils.toHex(post.payload); 4039 post.ttl = utils.fromDecimal(post.ttl); 4040 post.workToProve = utils.fromDecimal(post.workToProve); 4041 post.priority = utils.fromDecimal(post.priority); 4042 4043 // fallback 4044 if (!utils.isArray(post.topics)) { 4045 post.topics = post.topics ? [post.topics] : []; 4046 } 4047 4048 // format the following options 4049 post.topics = post.topics.map(function (topic) { 4050 // convert only if not hex 4051 return topic.indexOf('0x') === 0 ? topic : utils.fromUtf8(topic); 4052 }); 4053 4054 return post; 4055 }; 4056 4057 /** 4058 * Formats the output of a received post message 4059 * 4060 * @method outputPostFormatter 4061 * @param {Object} 4062 * @returns {Object} 4063 */ 4064 var outputPostFormatter = function (post) { 4065 post.expiry = utils.toDecimal(post.expiry); 4066 post.sent = utils.toDecimal(post.sent); 4067 post.ttl = utils.toDecimal(post.ttl); 4068 post.workProved = utils.toDecimal(post.workProved); 4069 // post.payloadRaw = post.payload; 4070 // post.payload = utils.toAscii(post.payload); 4071 4072 // if (utils.isJson(post.payload)) { 4073 // post.payload = JSON.parse(post.payload); 4074 // } 4075 4076 // format the following options 4077 if (!post.topics) { 4078 post.topics = []; 4079 } 4080 post.topics = post.topics.map(function (topic) { 4081 return utils.toAscii(topic); 4082 }); 4083 4084 return post; 4085 }; 4086 4087 var inputAddressFormatter = function (address) { 4088 var iban = new Iban(address); 4089 if (iban.isValid() && iban.isDirect()) { 4090 return '0x' + iban.address(); 4091 } else if (utils.isStrictAddress(address)) { 4092 return address; 4093 } else if (utils.isAddress(address)) { 4094 return '0x' + address; 4095 } 4096 throw new Error('invalid address'); 4097 }; 4098 4099 var outputSyncingFormatter = function (result) { 4100 if (!result) { 4101 return result; 4102 } 4103 4104 result.startingBlock = utils.toDecimal(result.startingBlock); 4105 result.currentBlock = utils.toDecimal(result.currentBlock); 4106 result.highestBlock = utils.toDecimal(result.highestBlock); 4107 result.syncedAccounts = utils.toDecimal(result.syncedAccounts); 4108 result.syncedAccountBytes = utils.toDecimal(result.syncedAccountBytes); 4109 result.syncedBytecodes = utils.toDecimal(result.syncedBytecodes); 4110 result.syncedBytecodeBytes = utils.toDecimal(result.syncedBytecodeBytes); 4111 result.syncedStorage = utils.toDecimal(result.syncedStorage); 4112 result.syncedStorageBytes = utils.toDecimal(result.syncedStorageBytes); 4113 result.healedTrienodes = utils.toDecimal(result.healedTrienodes); 4114 result.healedTrienodeBytes = utils.toDecimal(result.healedTrienodeBytes); 4115 result.healedBytecodes = utils.toDecimal(result.healedBytecodes); 4116 result.healedBytecodeBytes = utils.toDecimal(result.healedBytecodeBytes); 4117 result.healingTrienodes = utils.toDecimal(result.healingTrienodes); 4118 result.healingBytecode = utils.toDecimal(result.healingBytecode); 4119 4120 return result; 4121 }; 4122 4123 module.exports = { 4124 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 4125 inputBlockNumberFormatter: inputBlockNumberFormatter, 4126 inputCallFormatter: inputCallFormatter, 4127 inputTransactionFormatter: inputTransactionFormatter, 4128 inputAddressFormatter: inputAddressFormatter, 4129 inputPostFormatter: inputPostFormatter, 4130 outputBigNumberFormatter: outputBigNumberFormatter, 4131 outputTransactionFormatter: outputTransactionFormatter, 4132 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 4133 outputBlockFormatter: outputBlockFormatter, 4134 outputLogFormatter: outputLogFormatter, 4135 outputPostFormatter: outputPostFormatter, 4136 outputSyncingFormatter: outputSyncingFormatter, 4137 }; 4138 }, 4139 { '../utils/config': 18, '../utils/utils': 20, './iban': 33 }, 4140 ], 4141 31: [ 4142 function (require, module, exports) { 4143 /* 4144 This file is part of web3.js. 4145 4146 web3.js is free software: you can redistribute it and/or modify 4147 it under the terms of the GNU Lesser General Public License as published by 4148 the Free Software Foundation, either version 3 of the License, or 4149 (at your option) any later version. 4150 4151 web3.js is distributed in the hope that it will be useful, 4152 but WITHOUT ANY WARRANTY; without even the implied warranty of 4153 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4154 GNU Lesser General Public License for more details. 4155 4156 You should have received a copy of the GNU Lesser General Public License 4157 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4158 */ 4159 /** 4160 * @file function.js 4161 * @author Marek Kotewicz <marek@ethdev.com> 4162 * @date 2015 4163 */ 4164 4165 var coder = require('../solidity/coder'); 4166 var utils = require('../utils/utils'); 4167 var errors = require('./errors'); 4168 var formatters = require('./formatters'); 4169 var sha3 = require('../utils/sha3'); 4170 4171 /** 4172 * This prototype should be used to call/sendTransaction to solidity functions 4173 */ 4174 var SolidityFunction = function (eth, json, address) { 4175 this._eth = eth; 4176 this._inputTypes = json.inputs.map(function (i) { 4177 return i.type; 4178 }); 4179 this._outputTypes = json.outputs.map(function (i) { 4180 return i.type; 4181 }); 4182 this._constant = json.constant; 4183 this._payable = json.payable; 4184 this._name = utils.transformToFullName(json); 4185 this._address = address; 4186 }; 4187 4188 SolidityFunction.prototype.extractCallback = function (args) { 4189 if (utils.isFunction(args[args.length - 1])) { 4190 return args.pop(); // modify the args array! 4191 } 4192 }; 4193 4194 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4195 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length - 1])) { 4196 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4197 } 4198 }; 4199 4200 /** 4201 * Should be called to check if the number of arguments is correct 4202 * 4203 * @method validateArgs 4204 * @param {Array} arguments 4205 * @throws {Error} if it is not 4206 */ 4207 SolidityFunction.prototype.validateArgs = function (args) { 4208 var inputArgs = args.filter(function (a) { 4209 // filter the options object but not arguments that are arrays 4210 return !(utils.isObject(a) === true && utils.isArray(a) === false && utils.isBigNumber(a) === false); 4211 }); 4212 if (inputArgs.length !== this._inputTypes.length) { 4213 throw errors.InvalidNumberOfSolidityArgs(); 4214 } 4215 }; 4216 4217 /** 4218 * Should be used to create payload from arguments 4219 * 4220 * @method toPayload 4221 * @param {Array} solidity function params 4222 * @param {Object} optional payload options 4223 */ 4224 SolidityFunction.prototype.toPayload = function (args) { 4225 var options = {}; 4226 if (args.length > this._inputTypes.length && utils.isObject(args[args.length - 1])) { 4227 options = args[args.length - 1]; 4228 } 4229 this.validateArgs(args); 4230 options.to = this._address; 4231 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4232 return options; 4233 }; 4234 4235 /** 4236 * Should be used to get function signature 4237 * 4238 * @method signature 4239 * @return {String} function signature 4240 */ 4241 SolidityFunction.prototype.signature = function () { 4242 return sha3(this._name).slice(0, 8); 4243 }; 4244 4245 SolidityFunction.prototype.unpackOutput = function (output) { 4246 if (!output) { 4247 return; 4248 } 4249 4250 output = output.length >= 2 ? output.slice(2) : output; 4251 var result = coder.decodeParams(this._outputTypes, output); 4252 return result.length === 1 ? result[0] : result; 4253 }; 4254 4255 /** 4256 * Calls a contract function. 4257 * 4258 * @method call 4259 * @param {...Object} Contract function arguments 4260 * @param {function} If the last argument is a function, the contract function 4261 * call will be asynchronous, and the callback will be passed the 4262 * error and result. 4263 * @return {String} output bytes 4264 */ 4265 SolidityFunction.prototype.call = function () { 4266 var args = Array.prototype.slice.call(arguments).filter(function (a) { 4267 return a !== undefined; 4268 }); 4269 var callback = this.extractCallback(args); 4270 var defaultBlock = this.extractDefaultBlock(args); 4271 var payload = this.toPayload(args); 4272 4273 if (!callback) { 4274 var output = this._eth.call(payload, defaultBlock); 4275 return this.unpackOutput(output); 4276 } 4277 4278 var self = this; 4279 this._eth.call(payload, defaultBlock, function (error, output) { 4280 if (error) return callback(error, null); 4281 4282 var unpacked = null; 4283 try { 4284 unpacked = self.unpackOutput(output); 4285 } catch (e) { 4286 error = e; 4287 } 4288 4289 callback(error, unpacked); 4290 }); 4291 }; 4292 4293 /** 4294 * Should be used to sendTransaction to solidity function 4295 * 4296 * @method sendTransaction 4297 */ 4298 SolidityFunction.prototype.sendTransaction = function () { 4299 var args = Array.prototype.slice.call(arguments).filter(function (a) { 4300 return a !== undefined; 4301 }); 4302 var callback = this.extractCallback(args); 4303 var payload = this.toPayload(args); 4304 4305 if (payload.value > 0 && !this._payable) { 4306 throw new Error('Cannot send value to non-payable function'); 4307 } 4308 4309 if (!callback) { 4310 return this._eth.sendTransaction(payload); 4311 } 4312 4313 this._eth.sendTransaction(payload, callback); 4314 }; 4315 4316 /** 4317 * Should be used to estimateGas of solidity function 4318 * 4319 * @method estimateGas 4320 */ 4321 SolidityFunction.prototype.estimateGas = function () { 4322 var args = Array.prototype.slice.call(arguments); 4323 var callback = this.extractCallback(args); 4324 var payload = this.toPayload(args); 4325 4326 if (!callback) { 4327 return this._eth.estimateGas(payload); 4328 } 4329 4330 this._eth.estimateGas(payload, callback); 4331 }; 4332 4333 /** 4334 * Return the encoded data of the call 4335 * 4336 * @method getData 4337 * @return {String} the encoded data 4338 */ 4339 SolidityFunction.prototype.getData = function () { 4340 var args = Array.prototype.slice.call(arguments); 4341 var payload = this.toPayload(args); 4342 4343 return payload.data; 4344 }; 4345 4346 /** 4347 * Should be used to get function display name 4348 * 4349 * @method displayName 4350 * @return {String} display name of the function 4351 */ 4352 SolidityFunction.prototype.displayName = function () { 4353 return utils.extractDisplayName(this._name); 4354 }; 4355 4356 /** 4357 * Should be used to get function type name 4358 * 4359 * @method typeName 4360 * @return {String} type name of the function 4361 */ 4362 SolidityFunction.prototype.typeName = function () { 4363 return utils.extractTypeName(this._name); 4364 }; 4365 4366 /** 4367 * Should be called to get rpc requests from solidity function 4368 * 4369 * @method request 4370 * @returns {Object} 4371 */ 4372 SolidityFunction.prototype.request = function () { 4373 var args = Array.prototype.slice.call(arguments); 4374 var callback = this.extractCallback(args); 4375 var payload = this.toPayload(args); 4376 var format = this.unpackOutput.bind(this); 4377 4378 return { 4379 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4380 callback: callback, 4381 params: [payload], 4382 format: format, 4383 }; 4384 }; 4385 4386 /** 4387 * Should be called to execute function 4388 * 4389 * @method execute 4390 */ 4391 SolidityFunction.prototype.execute = function () { 4392 var transaction = !this._constant; 4393 4394 // send transaction 4395 if (transaction) { 4396 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4397 } 4398 4399 // call 4400 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4401 }; 4402 4403 /** 4404 * Should be called to attach function to contract 4405 * 4406 * @method attachToContract 4407 * @param {Contract} 4408 */ 4409 SolidityFunction.prototype.attachToContract = function (contract) { 4410 var execute = this.execute.bind(this); 4411 execute.request = this.request.bind(this); 4412 execute.call = this.call.bind(this); 4413 execute.sendTransaction = this.sendTransaction.bind(this); 4414 execute.estimateGas = this.estimateGas.bind(this); 4415 execute.getData = this.getData.bind(this); 4416 var displayName = this.displayName(); 4417 if (!contract[displayName]) { 4418 contract[displayName] = execute; 4419 } 4420 contract[displayName][this.typeName()] = execute; // circular!!!! 4421 }; 4422 4423 module.exports = SolidityFunction; 4424 }, 4425 { '../solidity/coder': 7, '../utils/sha3': 19, '../utils/utils': 20, './errors': 26, './formatters': 30 }, 4426 ], 4427 32: [ 4428 function (require, module, exports) { 4429 /* 4430 This file is part of web3.js. 4431 4432 web3.js is free software: you can redistribute it and/or modify 4433 it under the terms of the GNU Lesser General Public License as published by 4434 the Free Software Foundation, either version 3 of the License, or 4435 (at your option) any later version. 4436 4437 web3.js is distributed in the hope that it will be useful, 4438 but WITHOUT ANY WARRANTY; without even the implied warranty of 4439 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4440 GNU Lesser General Public License for more details. 4441 4442 You should have received a copy of the GNU Lesser General Public License 4443 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4444 */ 4445 /** @file httpprovider.js 4446 * @authors: 4447 * Marek Kotewicz <marek@ethdev.com> 4448 * Marian Oancea <marian@ethdev.com> 4449 * Fabian Vogelsteller <fabian@ethdev.com> 4450 * @date 2015 4451 */ 4452 4453 var errors = require('./errors'); 4454 4455 // workaround to use httpprovider in different envs 4456 4457 // browser 4458 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4459 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4460 // node 4461 } else { 4462 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4463 } 4464 4465 var XHR2 = require('xhr2'); // jshint ignore: line 4466 4467 /** 4468 * HttpProvider should be used to send rpc calls over http 4469 */ 4470 var HttpProvider = function (host, timeout, user, password) { 4471 this.host = host || 'http://localhost:8545'; 4472 this.timeout = timeout || 0; 4473 this.user = user; 4474 this.password = password; 4475 }; 4476 4477 /** 4478 * Should be called to prepare new XMLHttpRequest 4479 * 4480 * @method prepareRequest 4481 * @param {Boolean} true if request should be async 4482 * @return {XMLHttpRequest} object 4483 */ 4484 HttpProvider.prototype.prepareRequest = function (async) { 4485 var request; 4486 4487 if (async) { 4488 request = new XHR2(); 4489 request.timeout = this.timeout; 4490 } else { 4491 request = new XMLHttpRequest(); 4492 } 4493 4494 request.open('POST', this.host, async); 4495 if (this.user && this.password) { 4496 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4497 request.setRequestHeader('Authorization', auth); 4498 } 4499 request.setRequestHeader('Content-Type', 'application/json'); 4500 return request; 4501 }; 4502 4503 /** 4504 * Should be called to make sync request 4505 * 4506 * @method send 4507 * @param {Object} payload 4508 * @return {Object} result 4509 */ 4510 HttpProvider.prototype.send = function (payload) { 4511 var request = this.prepareRequest(false); 4512 4513 try { 4514 request.send(JSON.stringify(payload)); 4515 } catch (error) { 4516 throw errors.InvalidConnection(this.host); 4517 } 4518 4519 var result = request.responseText; 4520 4521 try { 4522 result = JSON.parse(result); 4523 } catch (e) { 4524 throw errors.InvalidResponse(request.responseText); 4525 } 4526 4527 return result; 4528 }; 4529 4530 /** 4531 * Should be used to make async request 4532 * 4533 * @method sendAsync 4534 * @param {Object} payload 4535 * @param {Function} callback triggered on end with (err, result) 4536 */ 4537 HttpProvider.prototype.sendAsync = function (payload, callback) { 4538 var request = this.prepareRequest(true); 4539 4540 request.onreadystatechange = function () { 4541 if (request.readyState === 4 && request.timeout !== 1) { 4542 var result = request.responseText; 4543 var error = null; 4544 4545 try { 4546 result = JSON.parse(result); 4547 } catch (e) { 4548 error = errors.InvalidResponse(request.responseText); 4549 } 4550 4551 callback(error, result); 4552 } 4553 }; 4554 4555 request.ontimeout = function () { 4556 callback(errors.ConnectionTimeout(this.timeout)); 4557 }; 4558 4559 try { 4560 request.send(JSON.stringify(payload)); 4561 } catch (error) { 4562 callback(errors.InvalidConnection(this.host)); 4563 } 4564 }; 4565 4566 /** 4567 * Synchronously tries to make Http request 4568 * 4569 * @method isConnected 4570 * @return {Boolean} returns true if request haven't failed. Otherwise false 4571 */ 4572 HttpProvider.prototype.isConnected = function () { 4573 try { 4574 this.send({ 4575 id: 9999999999, 4576 jsonrpc: '2.0', 4577 method: 'net_listening', 4578 params: [], 4579 }); 4580 return true; 4581 } catch (e) { 4582 return false; 4583 } 4584 }; 4585 4586 module.exports = HttpProvider; 4587 }, 4588 { './errors': 26, xhr2: 86, xmlhttprequest: 17 }, 4589 ], 4590 33: [ 4591 function (require, module, exports) { 4592 /* 4593 This file is part of web3.js. 4594 4595 web3.js is free software: you can redistribute it and/or modify 4596 it under the terms of the GNU Lesser General Public License as published by 4597 the Free Software Foundation, either version 3 of the License, or 4598 (at your option) any later version. 4599 4600 web3.js is distributed in the hope that it will be useful, 4601 but WITHOUT ANY WARRANTY; without even the implied warranty of 4602 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4603 GNU Lesser General Public License for more details. 4604 4605 You should have received a copy of the GNU Lesser General Public License 4606 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4607 */ 4608 /** 4609 * @file iban.js 4610 * @author Marek Kotewicz <marek@ethdev.com> 4611 * @date 2015 4612 */ 4613 4614 var BigNumber = require('bignumber.js'); 4615 4616 var padLeft = function (string, bytes) { 4617 var result = string; 4618 while (result.length < bytes * 2) { 4619 result = '0' + result; 4620 } 4621 return result; 4622 }; 4623 4624 /** 4625 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4626 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4627 * 4628 * @method iso13616Prepare 4629 * @param {String} iban the IBAN 4630 * @returns {String} the prepared IBAN 4631 */ 4632 var iso13616Prepare = function (iban) { 4633 var A = 'A'.charCodeAt(0); 4634 var Z = 'Z'.charCodeAt(0); 4635 4636 iban = iban.toUpperCase(); 4637 iban = iban.substr(4) + iban.substr(0, 4); 4638 4639 return iban 4640 .split('') 4641 .map(function (n) { 4642 var code = n.charCodeAt(0); 4643 if (code >= A && code <= Z) { 4644 // A = 10, B = 11, ... Z = 35 4645 return code - A + 10; 4646 } else { 4647 return n; 4648 } 4649 }) 4650 .join(''); 4651 }; 4652 4653 /** 4654 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4655 * 4656 * @method mod9710 4657 * @param {String} iban 4658 * @returns {Number} 4659 */ 4660 var mod9710 = function (iban) { 4661 var remainder = iban, 4662 block; 4663 4664 while (remainder.length > 2) { 4665 block = remainder.slice(0, 9); 4666 remainder = (parseInt(block, 10) % 97) + remainder.slice(block.length); 4667 } 4668 4669 return parseInt(remainder, 10) % 97; 4670 }; 4671 4672 /** 4673 * This prototype should be used to create iban object from iban correct string 4674 * 4675 * @param {String} iban 4676 */ 4677 var Iban = function (iban) { 4678 this._iban = iban; 4679 }; 4680 4681 /** 4682 * This method should be used to create iban object from ethereum address 4683 * 4684 * @method fromAddress 4685 * @param {String} address 4686 * @return {Iban} the IBAN object 4687 */ 4688 Iban.fromAddress = function (address) { 4689 var asBn = new BigNumber(address, 16); 4690 var base36 = asBn.toString(36); 4691 var padded = padLeft(base36, 15); 4692 return Iban.fromBban(padded.toUpperCase()); 4693 }; 4694 4695 /** 4696 * Convert the passed BBAN to an IBAN for this country specification. 4697 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4698 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4699 * 4700 * @method fromBban 4701 * @param {String} bban the BBAN to convert to IBAN 4702 * @returns {Iban} the IBAN object 4703 */ 4704 Iban.fromBban = function (bban) { 4705 var countryCode = 'XE'; 4706 4707 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4708 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4709 4710 return new Iban(countryCode + checkDigit + bban); 4711 }; 4712 4713 /** 4714 * Should be used to create IBAN object for given institution and identifier 4715 * 4716 * @method createIndirect 4717 * @param {Object} options, required options are "institution" and "identifier" 4718 * @return {Iban} the IBAN object 4719 */ 4720 Iban.createIndirect = function (options) { 4721 return Iban.fromBban('ETH' + options.institution + options.identifier); 4722 }; 4723 4724 /** 4725 * Thos method should be used to check if given string is valid iban object 4726 * 4727 * @method isValid 4728 * @param {String} iban string 4729 * @return {Boolean} true if it is valid IBAN 4730 */ 4731 Iban.isValid = function (iban) { 4732 var i = new Iban(iban); 4733 return i.isValid(); 4734 }; 4735 4736 /** 4737 * Should be called to check if iban is correct 4738 * 4739 * @method isValid 4740 * @returns {Boolean} true if it is, otherwise false 4741 */ 4742 Iban.prototype.isValid = function () { 4743 return ( 4744 /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4745 mod9710(iso13616Prepare(this._iban)) === 1 4746 ); 4747 }; 4748 4749 /** 4750 * Should be called to check if iban number is direct 4751 * 4752 * @method isDirect 4753 * @returns {Boolean} true if it is, otherwise false 4754 */ 4755 Iban.prototype.isDirect = function () { 4756 return this._iban.length === 34 || this._iban.length === 35; 4757 }; 4758 4759 /** 4760 * Should be called to check if iban number if indirect 4761 * 4762 * @method isIndirect 4763 * @returns {Boolean} true if it is, otherwise false 4764 */ 4765 Iban.prototype.isIndirect = function () { 4766 return this._iban.length === 20; 4767 }; 4768 4769 /** 4770 * Should be called to get iban checksum 4771 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4772 * 4773 * @method checksum 4774 * @returns {String} checksum 4775 */ 4776 Iban.prototype.checksum = function () { 4777 return this._iban.substr(2, 2); 4778 }; 4779 4780 /** 4781 * Should be called to get institution identifier 4782 * eg. XREG 4783 * 4784 * @method institution 4785 * @returns {String} institution identifier 4786 */ 4787 Iban.prototype.institution = function () { 4788 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4789 }; 4790 4791 /** 4792 * Should be called to get client identifier within institution 4793 * eg. GAVOFYORK 4794 * 4795 * @method client 4796 * @returns {String} client identifier 4797 */ 4798 Iban.prototype.client = function () { 4799 return this.isIndirect() ? this._iban.substr(11) : ''; 4800 }; 4801 4802 /** 4803 * Should be called to get client direct address 4804 * 4805 * @method address 4806 * @returns {String} client direct address 4807 */ 4808 Iban.prototype.address = function () { 4809 if (this.isDirect()) { 4810 var base36 = this._iban.substr(4); 4811 var asBn = new BigNumber(base36, 36); 4812 return padLeft(asBn.toString(16), 20); 4813 } 4814 4815 return ''; 4816 }; 4817 4818 Iban.prototype.toString = function () { 4819 return this._iban; 4820 }; 4821 4822 module.exports = Iban; 4823 }, 4824 { 'bignumber.js': 'bignumber.js' }, 4825 ], 4826 34: [ 4827 function (require, module, exports) { 4828 /* 4829 This file is part of web3.js. 4830 4831 web3.js is free software: you can redistribute it and/or modify 4832 it under the terms of the GNU Lesser General Public License as published by 4833 the Free Software Foundation, either version 3 of the License, or 4834 (at your option) any later version. 4835 4836 web3.js is distributed in the hope that it will be useful, 4837 but WITHOUT ANY WARRANTY; without even the implied warranty of 4838 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4839 GNU Lesser General Public License for more details. 4840 4841 You should have received a copy of the GNU Lesser General Public License 4842 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4843 */ 4844 /** @file ipcprovider.js 4845 * @authors: 4846 * Fabian Vogelsteller <fabian@ethdev.com> 4847 * @date 2015 4848 */ 4849 4850 'use strict'; 4851 4852 var utils = require('../utils/utils'); 4853 var errors = require('./errors'); 4854 4855 var IpcProvider = function (path, net) { 4856 var _this = this; 4857 this.responseCallbacks = {}; 4858 this.path = path; 4859 4860 this.connection = net.connect({ path: this.path }); 4861 4862 this.connection.on('error', function (e) { 4863 console.error('IPC Connection Error', e); 4864 _this._timeout(); 4865 }); 4866 4867 this.connection.on('end', function () { 4868 _this._timeout(); 4869 }); 4870 4871 // LISTEN FOR CONNECTION RESPONSES 4872 this.connection.on('data', function (data) { 4873 /*jshint maxcomplexity: 6 */ 4874 4875 _this._parseResponse(data.toString()).forEach(function (result) { 4876 var id = null; 4877 4878 // get the id which matches the returned id 4879 if (utils.isArray(result)) { 4880 result.forEach(function (load) { 4881 if (_this.responseCallbacks[load.id]) id = load.id; 4882 }); 4883 } else { 4884 id = result.id; 4885 } 4886 4887 // fire the callback 4888 if (_this.responseCallbacks[id]) { 4889 _this.responseCallbacks[id](null, result); 4890 delete _this.responseCallbacks[id]; 4891 } 4892 }); 4893 }); 4894 }; 4895 4896 /** 4897 Will parse the response and make an array out of it. 4898 4899 @method _parseResponse 4900 @param {String} data 4901 */ 4902 IpcProvider.prototype._parseResponse = function (data) { 4903 var _this = this, 4904 returnValues = []; 4905 4906 // DE-CHUNKER 4907 var dechunkedData = data 4908 .replace(/\}[\n\r]?\{/g, '}|--|{') // }{ 4909 .replace(/\}\][\n\r]?\[\{/g, '}]|--|[{') // }][{ 4910 .replace(/\}[\n\r]?\[\{/g, '}|--|[{') // }[{ 4911 .replace(/\}\][\n\r]?\{/g, '}]|--|{') // }]{ 4912 .split('|--|'); 4913 4914 dechunkedData.forEach(function (data) { 4915 // prepend the last chunk 4916 if (_this.lastChunk) data = _this.lastChunk + data; 4917 4918 var result = null; 4919 4920 try { 4921 result = JSON.parse(data); 4922 } catch (e) { 4923 _this.lastChunk = data; 4924 4925 // start timeout to cancel all requests 4926 clearTimeout(_this.lastChunkTimeout); 4927 _this.lastChunkTimeout = setTimeout(function () { 4928 _this._timeout(); 4929 throw errors.InvalidResponse(data); 4930 }, 1000 * 15); 4931 4932 return; 4933 } 4934 4935 // cancel timeout and set chunk to null 4936 clearTimeout(_this.lastChunkTimeout); 4937 _this.lastChunk = null; 4938 4939 if (result) returnValues.push(result); 4940 }); 4941 4942 return returnValues; 4943 }; 4944 4945 /** 4946 Get the adds a callback to the responseCallbacks object, 4947 which will be called if a response matching the response Id will arrive. 4948 4949 @method _addResponseCallback 4950 */ 4951 IpcProvider.prototype._addResponseCallback = function (payload, callback) { 4952 var id = payload.id || payload[0].id; 4953 var method = payload.method || payload[0].method; 4954 4955 this.responseCallbacks[id] = callback; 4956 this.responseCallbacks[id].method = method; 4957 }; 4958 4959 /** 4960 Timeout all requests when the end/error event is fired 4961 4962 @method _timeout 4963 */ 4964 IpcProvider.prototype._timeout = function () { 4965 for (var key in this.responseCallbacks) { 4966 if (this.responseCallbacks.hasOwnProperty(key)) { 4967 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4968 delete this.responseCallbacks[key]; 4969 } 4970 } 4971 }; 4972 4973 /** 4974 Check if the current connection is still valid. 4975 4976 @method isConnected 4977 */ 4978 IpcProvider.prototype.isConnected = function () { 4979 var _this = this; 4980 4981 // try reconnect, when connection is gone 4982 if (!_this.connection.writable) _this.connection.connect({ path: _this.path }); 4983 4984 return !!this.connection.writable; 4985 }; 4986 4987 IpcProvider.prototype.send = function (payload) { 4988 if (this.connection.writeSync) { 4989 var result; 4990 4991 // try reconnect, when connection is gone 4992 if (!this.connection.writable) this.connection.connect({ path: this.path }); 4993 4994 var data = this.connection.writeSync(JSON.stringify(payload)); 4995 4996 try { 4997 result = JSON.parse(data); 4998 } catch (e) { 4999 throw errors.InvalidResponse(data); 5000 } 5001 5002 return result; 5003 } else { 5004 throw new Error( 5005 'You tried to send "' + 5006 payload.method + 5007 '" synchronously. Synchronous requests are not supported by the IPC provider.' 5008 ); 5009 } 5010 }; 5011 5012 IpcProvider.prototype.sendAsync = function (payload, callback) { 5013 // try reconnect, when connection is gone 5014 if (!this.connection.writable) this.connection.connect({ path: this.path }); 5015 5016 this.connection.write(JSON.stringify(payload)); 5017 this._addResponseCallback(payload, callback); 5018 }; 5019 5020 module.exports = IpcProvider; 5021 }, 5022 { '../utils/utils': 20, './errors': 26 }, 5023 ], 5024 35: [ 5025 function (require, module, exports) { 5026 /* 5027 This file is part of web3.js. 5028 5029 web3.js is free software: you can redistribute it and/or modify 5030 it under the terms of the GNU Lesser General Public License as published by 5031 the Free Software Foundation, either version 3 of the License, or 5032 (at your option) any later version. 5033 5034 web3.js is distributed in the hope that it will be useful, 5035 but WITHOUT ANY WARRANTY; without even the implied warranty of 5036 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5037 GNU Lesser General Public License for more details. 5038 5039 You should have received a copy of the GNU Lesser General Public License 5040 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5041 */ 5042 /** @file jsonrpc.js 5043 * @authors: 5044 * Marek Kotewicz <marek@ethdev.com> 5045 * Aaron Kumavis <aaron@kumavis.me> 5046 * @date 2015 5047 */ 5048 5049 // Initialize Jsonrpc as a simple object with utility functions. 5050 var Jsonrpc = { 5051 messageId: 0, 5052 }; 5053 5054 /** 5055 * Should be called to valid json create payload object 5056 * 5057 * @method toPayload 5058 * @param {Function} method of jsonrpc call, required 5059 * @param {Array} params, an array of method params, optional 5060 * @returns {Object} valid jsonrpc payload object 5061 */ 5062 Jsonrpc.toPayload = function (method, params) { 5063 if (!method) console.error('jsonrpc method should be specified!'); 5064 5065 // advance message ID 5066 Jsonrpc.messageId++; 5067 5068 return { 5069 jsonrpc: '2.0', 5070 id: Jsonrpc.messageId, 5071 method: method, 5072 params: params || [], 5073 }; 5074 }; 5075 5076 /** 5077 * Should be called to check if jsonrpc response is valid 5078 * 5079 * @method isValidResponse 5080 * @param {Object} 5081 * @returns {Boolean} true if response is valid, otherwise false 5082 */ 5083 Jsonrpc.isValidResponse = function (response) { 5084 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 5085 5086 function validateSingleMessage(message) { 5087 return ( 5088 !!message && 5089 !message.error && 5090 message.jsonrpc === '2.0' && 5091 typeof message.id === 'number' && 5092 message.result !== undefined 5093 ); // only undefined is not valid json object 5094 } 5095 }; 5096 5097 /** 5098 * Should be called to create batch payload object 5099 * 5100 * @method toBatchPayload 5101 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 5102 * @returns {Array} batch payload 5103 */ 5104 Jsonrpc.toBatchPayload = function (messages) { 5105 return messages.map(function (message) { 5106 return Jsonrpc.toPayload(message.method, message.params); 5107 }); 5108 }; 5109 5110 module.exports = Jsonrpc; 5111 }, 5112 {}, 5113 ], 5114 36: [ 5115 function (require, module, exports) { 5116 /* 5117 This file is part of web3.js. 5118 5119 web3.js is free software: you can redistribute it and/or modify 5120 it under the terms of the GNU Lesser General Public License as published by 5121 the Free Software Foundation, either version 3 of the License, or 5122 (at your option) any later version. 5123 5124 web3.js is distributed in the hope that it will be useful, 5125 but WITHOUT ANY WARRANTY; without even the implied warranty of 5126 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5127 GNU Lesser General Public License for more details. 5128 5129 You should have received a copy of the GNU Lesser General Public License 5130 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5131 */ 5132 /** 5133 * @file method.js 5134 * @author Marek Kotewicz <marek@ethdev.com> 5135 * @date 2015 5136 */ 5137 5138 var utils = require('../utils/utils'); 5139 var errors = require('./errors'); 5140 5141 var Method = function (options) { 5142 this.name = options.name; 5143 this.call = options.call; 5144 this.params = options.params || 0; 5145 this.inputFormatter = options.inputFormatter; 5146 this.outputFormatter = options.outputFormatter; 5147 this.requestManager = null; 5148 }; 5149 5150 Method.prototype.setRequestManager = function (rm) { 5151 this.requestManager = rm; 5152 }; 5153 5154 /** 5155 * Should be used to determine name of the jsonrpc method based on arguments 5156 * 5157 * @method getCall 5158 * @param {Array} arguments 5159 * @return {String} name of jsonrpc method 5160 */ 5161 Method.prototype.getCall = function (args) { 5162 return utils.isFunction(this.call) ? this.call(args) : this.call; 5163 }; 5164 5165 /** 5166 * Should be used to extract callback from array of arguments. Modifies input param 5167 * 5168 * @method extractCallback 5169 * @param {Array} arguments 5170 * @return {Function|Null} callback, if exists 5171 */ 5172 Method.prototype.extractCallback = function (args) { 5173 if (utils.isFunction(args[args.length - 1])) { 5174 return args.pop(); // modify the args array! 5175 } 5176 }; 5177 5178 /** 5179 * Should be called to check if the number of arguments is correct 5180 * 5181 * @method validateArgs 5182 * @param {Array} arguments 5183 * @throws {Error} if it is not 5184 */ 5185 Method.prototype.validateArgs = function (args) { 5186 if (args.length !== this.params) { 5187 throw errors.InvalidNumberOfRPCParams(); 5188 } 5189 }; 5190 5191 /** 5192 * Should be called to format input args of method 5193 * 5194 * @method formatInput 5195 * @param {Array} 5196 * @return {Array} 5197 */ 5198 Method.prototype.formatInput = function (args) { 5199 if (!this.inputFormatter) { 5200 return args; 5201 } 5202 5203 return this.inputFormatter.map(function (formatter, index) { 5204 return formatter ? formatter(args[index]) : args[index]; 5205 }); 5206 }; 5207 5208 /** 5209 * Should be called to format output(result) of method 5210 * 5211 * @method formatOutput 5212 * @param {Object} 5213 * @return {Object} 5214 */ 5215 Method.prototype.formatOutput = function (result) { 5216 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5217 }; 5218 5219 /** 5220 * Should create payload from given input args 5221 * 5222 * @method toPayload 5223 * @param {Array} args 5224 * @return {Object} 5225 */ 5226 Method.prototype.toPayload = function (args) { 5227 var call = this.getCall(args); 5228 var callback = this.extractCallback(args); 5229 var params = this.formatInput(args); 5230 this.validateArgs(params); 5231 5232 return { 5233 method: call, 5234 params: params, 5235 callback: callback, 5236 }; 5237 }; 5238 5239 Method.prototype.attachToObject = function (obj) { 5240 var func = this.buildCall(); 5241 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5242 var name = this.name.split('.'); 5243 if (name.length > 1) { 5244 obj[name[0]] = obj[name[0]] || {}; 5245 obj[name[0]][name[1]] = func; 5246 } else { 5247 obj[name[0]] = func; 5248 } 5249 }; 5250 5251 Method.prototype.buildCall = function () { 5252 var method = this; 5253 var send = function () { 5254 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5255 if (payload.callback) { 5256 return method.requestManager.sendAsync(payload, function (err, result) { 5257 payload.callback(err, method.formatOutput(result)); 5258 }); 5259 } 5260 return method.formatOutput(method.requestManager.send(payload)); 5261 }; 5262 send.request = this.request.bind(this); 5263 return send; 5264 }; 5265 5266 /** 5267 * Should be called to create pure JSONRPC request which can be used in batch request 5268 * 5269 * @method request 5270 * @param {...} params 5271 * @return {Object} jsonrpc request 5272 */ 5273 Method.prototype.request = function () { 5274 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5275 payload.format = this.formatOutput.bind(this); 5276 return payload; 5277 }; 5278 5279 module.exports = Method; 5280 }, 5281 { '../utils/utils': 20, './errors': 26 }, 5282 ], 5283 37: [ 5284 function (require, module, exports) { 5285 /* 5286 This file is part of web3.js. 5287 5288 web3.js is free software: you can redistribute it and/or modify 5289 it under the terms of the GNU Lesser General Public License as published by 5290 the Free Software Foundation, either version 3 of the License, or 5291 (at your option) any later version. 5292 5293 web3.js is distributed in the hope that it will be useful, 5294 but WITHOUT ANY WARRANTY; without even the implied warranty of 5295 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5296 GNU Lesser General Public License for more details. 5297 5298 You should have received a copy of the GNU Lesser General Public License 5299 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5300 */ 5301 /** @file db.js 5302 * @authors: 5303 * Marek Kotewicz <marek@ethdev.com> 5304 * @date 2015 5305 */ 5306 5307 var Method = require('../method'); 5308 5309 var DB = function (web3) { 5310 this._requestManager = web3._requestManager; 5311 5312 var self = this; 5313 5314 methods().forEach(function (method) { 5315 method.attachToObject(self); 5316 method.setRequestManager(web3._requestManager); 5317 }); 5318 }; 5319 5320 var methods = function () { 5321 var putString = new Method({ 5322 name: 'putString', 5323 call: 'db_putString', 5324 params: 3, 5325 }); 5326 5327 var getString = new Method({ 5328 name: 'getString', 5329 call: 'db_getString', 5330 params: 2, 5331 }); 5332 5333 var putHex = new Method({ 5334 name: 'putHex', 5335 call: 'db_putHex', 5336 params: 3, 5337 }); 5338 5339 var getHex = new Method({ 5340 name: 'getHex', 5341 call: 'db_getHex', 5342 params: 2, 5343 }); 5344 5345 return [putString, getString, putHex, getHex]; 5346 }; 5347 5348 module.exports = DB; 5349 }, 5350 { '../method': 36 }, 5351 ], 5352 38: [ 5353 function (require, module, exports) { 5354 /* 5355 This file is part of web3.js. 5356 5357 web3.js is free software: you can redistribute it and/or modify 5358 it under the terms of the GNU Lesser General Public License as published by 5359 the Free Software Foundation, either version 3 of the License, or 5360 (at your option) any later version. 5361 5362 web3.js is distributed in the hope that it will be useful, 5363 but WITHOUT ANY WARRANTY; without even the implied warranty of 5364 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5365 GNU Lesser General Public License for more details. 5366 5367 You should have received a copy of the GNU Lesser General Public License 5368 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5369 */ 5370 /** 5371 * @file eth.js 5372 * @author Marek Kotewicz <marek@ethdev.com> 5373 * @author Fabian Vogelsteller <fabian@ethdev.com> 5374 * @date 2015 5375 */ 5376 5377 'use strict'; 5378 5379 var formatters = require('../formatters'); 5380 var utils = require('../../utils/utils'); 5381 var Method = require('../method'); 5382 var Property = require('../property'); 5383 var c = require('../../utils/config'); 5384 var Contract = require('../contract'); 5385 var watches = require('./watches'); 5386 var Filter = require('../filter'); 5387 var IsSyncing = require('../syncing'); 5388 var namereg = require('../namereg'); 5389 var Iban = require('../iban'); 5390 var transfer = require('../transfer'); 5391 5392 var blockCall = function (args) { 5393 return utils.isString(args[0]) && args[0].indexOf('0x') === 0 ? 'eth_getBlockByHash' : 'eth_getBlockByNumber'; 5394 }; 5395 5396 var transactionFromBlockCall = function (args) { 5397 return utils.isString(args[0]) && args[0].indexOf('0x') === 0 5398 ? 'eth_getTransactionByBlockHashAndIndex' 5399 : 'eth_getTransactionByBlockNumberAndIndex'; 5400 }; 5401 5402 var uncleCall = function (args) { 5403 return utils.isString(args[0]) && args[0].indexOf('0x') === 0 5404 ? 'eth_getUncleByBlockHashAndIndex' 5405 : 'eth_getUncleByBlockNumberAndIndex'; 5406 }; 5407 5408 var getBlockTransactionCountCall = function (args) { 5409 return utils.isString(args[0]) && args[0].indexOf('0x') === 0 5410 ? 'eth_getBlockTransactionCountByHash' 5411 : 'eth_getBlockTransactionCountByNumber'; 5412 }; 5413 5414 var uncleCountCall = function (args) { 5415 return utils.isString(args[0]) && args[0].indexOf('0x') === 0 5416 ? 'eth_getUncleCountByBlockHash' 5417 : 'eth_getUncleCountByBlockNumber'; 5418 }; 5419 5420 function Eth(web3) { 5421 this._requestManager = web3._requestManager; 5422 5423 var self = this; 5424 5425 methods().forEach(function (method) { 5426 method.attachToObject(self); 5427 method.setRequestManager(self._requestManager); 5428 }); 5429 5430 properties().forEach(function (p) { 5431 p.attachToObject(self); 5432 p.setRequestManager(self._requestManager); 5433 }); 5434 5435 this.iban = Iban; 5436 this.sendIBANTransaction = transfer.bind(null, this); 5437 } 5438 5439 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5440 get: function () { 5441 return c.defaultBlock; 5442 }, 5443 set: function (val) { 5444 c.defaultBlock = val; 5445 return val; 5446 }, 5447 }); 5448 5449 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5450 get: function () { 5451 return c.defaultAccount; 5452 }, 5453 set: function (val) { 5454 c.defaultAccount = val; 5455 return val; 5456 }, 5457 }); 5458 5459 var methods = function () { 5460 var getBalance = new Method({ 5461 name: 'getBalance', 5462 call: 'eth_getBalance', 5463 params: 2, 5464 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5465 outputFormatter: formatters.outputBigNumberFormatter, 5466 }); 5467 5468 var getStorageAt = new Method({ 5469 name: 'getStorageAt', 5470 call: 'eth_getStorageAt', 5471 params: 3, 5472 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter], 5473 }); 5474 5475 var getCode = new Method({ 5476 name: 'getCode', 5477 call: 'eth_getCode', 5478 params: 2, 5479 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5480 }); 5481 5482 var getBlock = new Method({ 5483 name: 'getBlock', 5484 call: blockCall, 5485 params: 2, 5486 inputFormatter: [ 5487 formatters.inputBlockNumberFormatter, 5488 function (val) { 5489 return !!val; 5490 }, 5491 ], 5492 outputFormatter: formatters.outputBlockFormatter, 5493 }); 5494 5495 var getUncle = new Method({ 5496 name: 'getUncle', 5497 call: uncleCall, 5498 params: 2, 5499 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5500 outputFormatter: formatters.outputBlockFormatter, 5501 }); 5502 5503 var getCompilers = new Method({ 5504 name: 'getCompilers', 5505 call: 'eth_getCompilers', 5506 params: 0, 5507 }); 5508 5509 var getBlockTransactionCount = new Method({ 5510 name: 'getBlockTransactionCount', 5511 call: getBlockTransactionCountCall, 5512 params: 1, 5513 inputFormatter: [formatters.inputBlockNumberFormatter], 5514 outputFormatter: utils.toDecimal, 5515 }); 5516 5517 var getBlockUncleCount = new Method({ 5518 name: 'getBlockUncleCount', 5519 call: uncleCountCall, 5520 params: 1, 5521 inputFormatter: [formatters.inputBlockNumberFormatter], 5522 outputFormatter: utils.toDecimal, 5523 }); 5524 5525 var getTransaction = new Method({ 5526 name: 'getTransaction', 5527 call: 'eth_getTransactionByHash', 5528 params: 1, 5529 outputFormatter: formatters.outputTransactionFormatter, 5530 }); 5531 5532 var getTransactionFromBlock = new Method({ 5533 name: 'getTransactionFromBlock', 5534 call: transactionFromBlockCall, 5535 params: 2, 5536 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5537 outputFormatter: formatters.outputTransactionFormatter, 5538 }); 5539 5540 var getTransactionReceipt = new Method({ 5541 name: 'getTransactionReceipt', 5542 call: 'eth_getTransactionReceipt', 5543 params: 1, 5544 outputFormatter: formatters.outputTransactionReceiptFormatter, 5545 }); 5546 5547 var getTransactionCount = new Method({ 5548 name: 'getTransactionCount', 5549 call: 'eth_getTransactionCount', 5550 params: 2, 5551 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5552 outputFormatter: utils.toDecimal, 5553 }); 5554 5555 var sendRawTransaction = new Method({ 5556 name: 'sendRawTransaction', 5557 call: 'eth_sendRawTransaction', 5558 params: 1, 5559 inputFormatter: [null], 5560 }); 5561 5562 var sendTransaction = new Method({ 5563 name: 'sendTransaction', 5564 call: 'eth_sendTransaction', 5565 params: 1, 5566 inputFormatter: [formatters.inputTransactionFormatter], 5567 }); 5568 5569 var signTransaction = new Method({ 5570 name: 'signTransaction', 5571 call: 'eth_signTransaction', 5572 params: 1, 5573 inputFormatter: [formatters.inputTransactionFormatter], 5574 }); 5575 5576 var sign = new Method({ 5577 name: 'sign', 5578 call: 'eth_sign', 5579 params: 2, 5580 inputFormatter: [formatters.inputAddressFormatter, null], 5581 }); 5582 5583 var call = new Method({ 5584 name: 'call', 5585 call: 'eth_call', 5586 params: 2, 5587 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter], 5588 }); 5589 5590 var estimateGas = new Method({ 5591 name: 'estimateGas', 5592 call: 'eth_estimateGas', 5593 params: 1, 5594 inputFormatter: [formatters.inputCallFormatter], 5595 outputFormatter: utils.toDecimal, 5596 }); 5597 5598 var compileSolidity = new Method({ 5599 name: 'compile.solidity', 5600 call: 'eth_compileSolidity', 5601 params: 1, 5602 }); 5603 5604 var compileLLL = new Method({ 5605 name: 'compile.lll', 5606 call: 'eth_compileLLL', 5607 params: 1, 5608 }); 5609 5610 var compileSerpent = new Method({ 5611 name: 'compile.serpent', 5612 call: 'eth_compileSerpent', 5613 params: 1, 5614 }); 5615 5616 var submitWork = new Method({ 5617 name: 'submitWork', 5618 call: 'eth_submitWork', 5619 params: 3, 5620 }); 5621 5622 var getWork = new Method({ 5623 name: 'getWork', 5624 call: 'eth_getWork', 5625 params: 0, 5626 }); 5627 5628 return [ 5629 getBalance, 5630 getStorageAt, 5631 getCode, 5632 getBlock, 5633 getUncle, 5634 getCompilers, 5635 getBlockTransactionCount, 5636 getBlockUncleCount, 5637 getTransaction, 5638 getTransactionFromBlock, 5639 getTransactionReceipt, 5640 getTransactionCount, 5641 call, 5642 estimateGas, 5643 sendRawTransaction, 5644 signTransaction, 5645 sendTransaction, 5646 sign, 5647 compileSolidity, 5648 compileLLL, 5649 compileSerpent, 5650 submitWork, 5651 getWork, 5652 ]; 5653 }; 5654 5655 var properties = function () { 5656 return [ 5657 new Property({ 5658 name: 'coinbase', 5659 getter: 'eth_coinbase', 5660 }), 5661 new Property({ 5662 name: 'mining', 5663 getter: 'eth_mining', 5664 }), 5665 new Property({ 5666 name: 'hashrate', 5667 getter: 'eth_hashrate', 5668 outputFormatter: utils.toDecimal, 5669 }), 5670 new Property({ 5671 name: 'syncing', 5672 getter: 'eth_syncing', 5673 outputFormatter: formatters.outputSyncingFormatter, 5674 }), 5675 new Property({ 5676 name: 'gasPrice', 5677 getter: 'eth_gasPrice', 5678 outputFormatter: formatters.outputBigNumberFormatter, 5679 }), 5680 new Property({ 5681 name: 'accounts', 5682 getter: 'eth_accounts', 5683 }), 5684 new Property({ 5685 name: 'blockNumber', 5686 getter: 'eth_blockNumber', 5687 outputFormatter: utils.toDecimal, 5688 }), 5689 new Property({ 5690 name: 'protocolVersion', 5691 getter: 'eth_protocolVersion', 5692 }), 5693 ]; 5694 }; 5695 5696 Eth.prototype.contract = function (abi) { 5697 var factory = new Contract(this, abi); 5698 return factory; 5699 }; 5700 5701 Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5702 return new Filter( 5703 options, 5704 'eth', 5705 this._requestManager, 5706 watches.eth(), 5707 formatters.outputLogFormatter, 5708 callback, 5709 filterCreationErrorCallback 5710 ); 5711 }; 5712 5713 Eth.prototype.namereg = function () { 5714 return this.contract(namereg.global.abi).at(namereg.global.address); 5715 }; 5716 5717 Eth.prototype.icapNamereg = function () { 5718 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5719 }; 5720 5721 Eth.prototype.isSyncing = function (callback) { 5722 return new IsSyncing(this._requestManager, callback); 5723 }; 5724 5725 module.exports = Eth; 5726 }, 5727 { 5728 '../../utils/config': 18, 5729 '../../utils/utils': 20, 5730 '../contract': 25, 5731 '../filter': 29, 5732 '../formatters': 30, 5733 '../iban': 33, 5734 '../method': 36, 5735 '../namereg': 44, 5736 '../property': 45, 5737 '../syncing': 48, 5738 '../transfer': 49, 5739 './watches': 43, 5740 }, 5741 ], 5742 39: [ 5743 function (require, module, exports) { 5744 /* 5745 This file is part of web3.js. 5746 5747 web3.js is free software: you can redistribute it and/or modify 5748 it under the terms of the GNU Lesser General Public License as published by 5749 the Free Software Foundation, either version 3 of the License, or 5750 (at your option) any later version. 5751 5752 web3.js is distributed in the hope that it will be useful, 5753 but WITHOUT ANY WARRANTY; without even the implied warranty of 5754 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5755 GNU Lesser General Public License for more details. 5756 5757 You should have received a copy of the GNU Lesser General Public License 5758 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5759 */ 5760 /** @file eth.js 5761 * @authors: 5762 * Marek Kotewicz <marek@ethdev.com> 5763 * @date 2015 5764 */ 5765 5766 var utils = require('../../utils/utils'); 5767 var Property = require('../property'); 5768 5769 var Net = function (web3) { 5770 this._requestManager = web3._requestManager; 5771 5772 var self = this; 5773 5774 properties().forEach(function (p) { 5775 p.attachToObject(self); 5776 p.setRequestManager(web3._requestManager); 5777 }); 5778 }; 5779 5780 /// @returns an array of objects describing web3.eth api properties 5781 var properties = function () { 5782 return [ 5783 new Property({ 5784 name: 'listening', 5785 getter: 'net_listening', 5786 }), 5787 new Property({ 5788 name: 'peerCount', 5789 getter: 'net_peerCount', 5790 outputFormatter: utils.toDecimal, 5791 }), 5792 ]; 5793 }; 5794 5795 module.exports = Net; 5796 }, 5797 { '../../utils/utils': 20, '../property': 45 }, 5798 ], 5799 40: [ 5800 function (require, module, exports) { 5801 /* 5802 This file is part of web3.js. 5803 5804 web3.js is free software: you can redistribute it and/or modify 5805 it under the terms of the GNU Lesser General Public License as published by 5806 the Free Software Foundation, either version 3 of the License, or 5807 (at your option) any later version. 5808 5809 web3.js is distributed in the hope that it will be useful, 5810 but WITHOUT ANY WARRANTY; without even the implied warranty of 5811 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5812 GNU Lesser General Public License for more details. 5813 5814 You should have received a copy of the GNU Lesser General Public License 5815 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5816 */ 5817 /** 5818 * @file eth.js 5819 * @author Marek Kotewicz <marek@ethdev.com> 5820 * @author Fabian Vogelsteller <fabian@ethdev.com> 5821 * @date 2015 5822 */ 5823 5824 'use strict'; 5825 5826 var Method = require('../method'); 5827 var Property = require('../property'); 5828 var formatters = require('../formatters'); 5829 5830 function Personal(web3) { 5831 this._requestManager = web3._requestManager; 5832 5833 var self = this; 5834 5835 methods().forEach(function (method) { 5836 method.attachToObject(self); 5837 method.setRequestManager(self._requestManager); 5838 }); 5839 5840 properties().forEach(function (p) { 5841 p.attachToObject(self); 5842 p.setRequestManager(self._requestManager); 5843 }); 5844 } 5845 5846 var methods = function () { 5847 var newAccount = new Method({ 5848 name: 'newAccount', 5849 call: 'personal_newAccount', 5850 params: 1, 5851 inputFormatter: [null], 5852 }); 5853 5854 var importRawKey = new Method({ 5855 name: 'importRawKey', 5856 call: 'personal_importRawKey', 5857 params: 2, 5858 }); 5859 5860 var sign = new Method({ 5861 name: 'sign', 5862 call: 'personal_sign', 5863 params: 3, 5864 inputFormatter: [null, formatters.inputAddressFormatter, null], 5865 }); 5866 5867 var ecRecover = new Method({ 5868 name: 'ecRecover', 5869 call: 'personal_ecRecover', 5870 params: 2, 5871 }); 5872 5873 var unlockAccount = new Method({ 5874 name: 'unlockAccount', 5875 call: 'personal_unlockAccount', 5876 params: 3, 5877 inputFormatter: [formatters.inputAddressFormatter, null, null], 5878 }); 5879 5880 var sendTransaction = new Method({ 5881 name: 'sendTransaction', 5882 call: 'personal_sendTransaction', 5883 params: 2, 5884 inputFormatter: [formatters.inputTransactionFormatter, null], 5885 }); 5886 5887 var lockAccount = new Method({ 5888 name: 'lockAccount', 5889 call: 'personal_lockAccount', 5890 params: 1, 5891 inputFormatter: [formatters.inputAddressFormatter], 5892 }); 5893 5894 return [newAccount, importRawKey, unlockAccount, ecRecover, sign, sendTransaction, lockAccount]; 5895 }; 5896 5897 var properties = function () { 5898 return [ 5899 new Property({ 5900 name: 'listAccounts', 5901 getter: 'personal_listAccounts', 5902 }), 5903 ]; 5904 }; 5905 5906 module.exports = Personal; 5907 }, 5908 { '../formatters': 30, '../method': 36, '../property': 45 }, 5909 ], 5910 41: [ 5911 function (require, module, exports) { 5912 /* 5913 This file is part of web3.js. 5914 5915 web3.js is free software: you can redistribute it and/or modify 5916 it under the terms of the GNU Lesser General Public License as published by 5917 the Free Software Foundation, either version 3 of the License, or 5918 (at your option) any later version. 5919 5920 web3.js is distributed in the hope that it will be useful, 5921 but WITHOUT ANY WARRANTY; without even the implied warranty of 5922 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5923 GNU Lesser General Public License for more details. 5924 5925 You should have received a copy of the GNU Lesser General Public License 5926 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5927 */ 5928 /** @file shh.js 5929 * @authors: 5930 * Fabian Vogelsteller <fabian@ethereum.org> 5931 * Marek Kotewicz <marek@ethcore.io> 5932 * @date 2017 5933 */ 5934 5935 var Method = require('../method'); 5936 var Filter = require('../filter'); 5937 var watches = require('./watches'); 5938 5939 var Shh = function (web3) { 5940 this._requestManager = web3._requestManager; 5941 5942 var self = this; 5943 5944 methods().forEach(function (method) { 5945 method.attachToObject(self); 5946 method.setRequestManager(self._requestManager); 5947 }); 5948 }; 5949 5950 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 5951 return new Filter( 5952 options, 5953 'shh', 5954 this._requestManager, 5955 watches.shh(), 5956 null, 5957 callback, 5958 filterCreationErrorCallback 5959 ); 5960 }; 5961 5962 var methods = function () { 5963 return [ 5964 new Method({ 5965 name: 'version', 5966 call: 'shh_version', 5967 params: 0, 5968 }), 5969 new Method({ 5970 name: 'info', 5971 call: 'shh_info', 5972 params: 0, 5973 }), 5974 new Method({ 5975 name: 'setMaxMessageSize', 5976 call: 'shh_setMaxMessageSize', 5977 params: 1, 5978 }), 5979 new Method({ 5980 name: 'setMinPoW', 5981 call: 'shh_setMinPoW', 5982 params: 1, 5983 }), 5984 new Method({ 5985 name: 'markTrustedPeer', 5986 call: 'shh_markTrustedPeer', 5987 params: 1, 5988 }), 5989 new Method({ 5990 name: 'newKeyPair', 5991 call: 'shh_newKeyPair', 5992 params: 0, 5993 }), 5994 new Method({ 5995 name: 'addPrivateKey', 5996 call: 'shh_addPrivateKey', 5997 params: 1, 5998 }), 5999 new Method({ 6000 name: 'deleteKeyPair', 6001 call: 'shh_deleteKeyPair', 6002 params: 1, 6003 }), 6004 new Method({ 6005 name: 'hasKeyPair', 6006 call: 'shh_hasKeyPair', 6007 params: 1, 6008 }), 6009 new Method({ 6010 name: 'getPublicKey', 6011 call: 'shh_getPublicKey', 6012 params: 1, 6013 }), 6014 new Method({ 6015 name: 'getPrivateKey', 6016 call: 'shh_getPrivateKey', 6017 params: 1, 6018 }), 6019 new Method({ 6020 name: 'newSymKey', 6021 call: 'shh_newSymKey', 6022 params: 0, 6023 }), 6024 new Method({ 6025 name: 'addSymKey', 6026 call: 'shh_addSymKey', 6027 params: 1, 6028 }), 6029 new Method({ 6030 name: 'generateSymKeyFromPassword', 6031 call: 'shh_generateSymKeyFromPassword', 6032 params: 1, 6033 }), 6034 new Method({ 6035 name: 'hasSymKey', 6036 call: 'shh_hasSymKey', 6037 params: 1, 6038 }), 6039 new Method({ 6040 name: 'getSymKey', 6041 call: 'shh_getSymKey', 6042 params: 1, 6043 }), 6044 new Method({ 6045 name: 'deleteSymKey', 6046 call: 'shh_deleteSymKey', 6047 params: 1, 6048 }), 6049 6050 // subscribe and unsubscribe missing 6051 6052 new Method({ 6053 name: 'post', 6054 call: 'shh_post', 6055 params: 1, 6056 inputFormatter: [null], 6057 }), 6058 ]; 6059 }; 6060 6061 module.exports = Shh; 6062 }, 6063 { '../filter': 29, '../method': 36, './watches': 43 }, 6064 ], 6065 42: [ 6066 function (require, module, exports) { 6067 /* 6068 This file is part of web3.js. 6069 6070 web3.js is free software: you can redistribute it and/or modify 6071 it under the terms of the GNU Lesser General Public License as published by 6072 the Free Software Foundation, either version 3 of the License, or 6073 (at your option) any later version. 6074 6075 web3.js is distributed in the hope that it will be useful, 6076 but WITHOUT ANY WARRANTY; without even the implied warranty of 6077 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6078 GNU Lesser General Public License for more details. 6079 6080 You should have received a copy of the GNU Lesser General Public License 6081 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6082 */ 6083 /** 6084 * @file bzz.js 6085 * @author Alex Beregszaszi <alex@rtfs.hu> 6086 * @date 2016 6087 * 6088 * Reference: https://github.com/tirogen/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33 6089 */ 6090 6091 'use strict'; 6092 6093 var Method = require('../method'); 6094 var Property = require('../property'); 6095 6096 function Swarm(web3) { 6097 this._requestManager = web3._requestManager; 6098 6099 var self = this; 6100 6101 methods().forEach(function (method) { 6102 method.attachToObject(self); 6103 method.setRequestManager(self._requestManager); 6104 }); 6105 6106 properties().forEach(function (p) { 6107 p.attachToObject(self); 6108 p.setRequestManager(self._requestManager); 6109 }); 6110 } 6111 6112 var methods = function () { 6113 var blockNetworkRead = new Method({ 6114 name: 'blockNetworkRead', 6115 call: 'bzz_blockNetworkRead', 6116 params: 1, 6117 inputFormatter: [null], 6118 }); 6119 6120 var syncEnabled = new Method({ 6121 name: 'syncEnabled', 6122 call: 'bzz_syncEnabled', 6123 params: 1, 6124 inputFormatter: [null], 6125 }); 6126 6127 var swapEnabled = new Method({ 6128 name: 'swapEnabled', 6129 call: 'bzz_swapEnabled', 6130 params: 1, 6131 inputFormatter: [null], 6132 }); 6133 6134 var download = new Method({ 6135 name: 'download', 6136 call: 'bzz_download', 6137 params: 2, 6138 inputFormatter: [null, null], 6139 }); 6140 6141 var upload = new Method({ 6142 name: 'upload', 6143 call: 'bzz_upload', 6144 params: 2, 6145 inputFormatter: [null, null], 6146 }); 6147 6148 var retrieve = new Method({ 6149 name: 'retrieve', 6150 call: 'bzz_retrieve', 6151 params: 1, 6152 inputFormatter: [null], 6153 }); 6154 6155 var store = new Method({ 6156 name: 'store', 6157 call: 'bzz_store', 6158 params: 2, 6159 inputFormatter: [null, null], 6160 }); 6161 6162 var get = new Method({ 6163 name: 'get', 6164 call: 'bzz_get', 6165 params: 1, 6166 inputFormatter: [null], 6167 }); 6168 6169 var put = new Method({ 6170 name: 'put', 6171 call: 'bzz_put', 6172 params: 2, 6173 inputFormatter: [null, null], 6174 }); 6175 6176 var modify = new Method({ 6177 name: 'modify', 6178 call: 'bzz_modify', 6179 params: 4, 6180 inputFormatter: [null, null, null, null], 6181 }); 6182 6183 return [blockNetworkRead, syncEnabled, swapEnabled, download, upload, retrieve, store, get, put, modify]; 6184 }; 6185 6186 var properties = function () { 6187 return [ 6188 new Property({ 6189 name: 'hive', 6190 getter: 'bzz_hive', 6191 }), 6192 new Property({ 6193 name: 'info', 6194 getter: 'bzz_info', 6195 }), 6196 ]; 6197 }; 6198 6199 module.exports = Swarm; 6200 }, 6201 { '../method': 36, '../property': 45 }, 6202 ], 6203 43: [ 6204 function (require, module, exports) { 6205 /* 6206 This file is part of web3.js. 6207 6208 web3.js is free software: you can redistribute it and/or modify 6209 it under the terms of the GNU Lesser General Public License as published by 6210 the Free Software Foundation, either version 3 of the License, or 6211 (at your option) any later version. 6212 6213 web3.js is distributed in the hope that it will be useful, 6214 but WITHOUT ANY WARRANTY; without even the implied warranty of 6215 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6216 GNU Lesser General Public License for more details. 6217 6218 You should have received a copy of the GNU Lesser General Public License 6219 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6220 */ 6221 /** @file watches.js 6222 * @authors: 6223 * Marek Kotewicz <marek@ethdev.com> 6224 * @date 2015 6225 */ 6226 6227 var Method = require('../method'); 6228 6229 /// @returns an array of objects describing web3.eth.filter api methods 6230 var eth = function () { 6231 var newFilterCall = function (args) { 6232 var type = args[0]; 6233 6234 switch (type) { 6235 case 'latest': 6236 args.shift(); 6237 this.params = 0; 6238 return 'eth_newBlockFilter'; 6239 case 'pending': 6240 args.shift(); 6241 this.params = 0; 6242 return 'eth_newPendingTransactionFilter'; 6243 default: 6244 return 'eth_newFilter'; 6245 } 6246 }; 6247 6248 var newFilter = new Method({ 6249 name: 'newFilter', 6250 call: newFilterCall, 6251 params: 1, 6252 }); 6253 6254 var uninstallFilter = new Method({ 6255 name: 'uninstallFilter', 6256 call: 'eth_uninstallFilter', 6257 params: 1, 6258 }); 6259 6260 var getLogs = new Method({ 6261 name: 'getLogs', 6262 call: 'eth_getFilterLogs', 6263 params: 1, 6264 }); 6265 6266 var poll = new Method({ 6267 name: 'poll', 6268 call: 'eth_getFilterChanges', 6269 params: 1, 6270 }); 6271 6272 return [newFilter, uninstallFilter, getLogs, poll]; 6273 }; 6274 6275 /// @returns an array of objects describing web3.shh.watch api methods 6276 var shh = function () { 6277 return [ 6278 new Method({ 6279 name: 'newFilter', 6280 call: 'shh_newMessageFilter', 6281 params: 1, 6282 }), 6283 new Method({ 6284 name: 'uninstallFilter', 6285 call: 'shh_deleteMessageFilter', 6286 params: 1, 6287 }), 6288 new Method({ 6289 name: 'getLogs', 6290 call: 'shh_getFilterMessages', 6291 params: 1, 6292 }), 6293 new Method({ 6294 name: 'poll', 6295 call: 'shh_getFilterMessages', 6296 params: 1, 6297 }), 6298 ]; 6299 }; 6300 6301 module.exports = { 6302 eth: eth, 6303 shh: shh, 6304 }; 6305 }, 6306 { '../method': 36 }, 6307 ], 6308 44: [ 6309 function (require, module, exports) { 6310 /* 6311 This file is part of web3.js. 6312 6313 web3.js is free software: you can redistribute it and/or modify 6314 it under the terms of the GNU Lesser General Public License as published by 6315 the Free Software Foundation, either version 3 of the License, or 6316 (at your option) any later version. 6317 6318 web3.js is distributed in the hope that it will be useful, 6319 but WITHOUT ANY WARRANTY; without even the implied warranty of 6320 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6321 GNU Lesser General Public License for more details. 6322 6323 You should have received a copy of the GNU Lesser General Public License 6324 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6325 */ 6326 /** 6327 * @file namereg.js 6328 * @author Marek Kotewicz <marek@ethdev.com> 6329 * @date 2015 6330 */ 6331 6332 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6333 var icapRegistrarAbi = require('../contracts/ICAPRegistrar.json'); 6334 6335 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6336 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6337 6338 module.exports = { 6339 global: { 6340 abi: globalRegistrarAbi, 6341 address: globalNameregAddress, 6342 }, 6343 icap: { 6344 abi: icapRegistrarAbi, 6345 address: icapNameregAddress, 6346 }, 6347 }; 6348 }, 6349 { '../contracts/GlobalRegistrar.json': 1, '../contracts/ICAPRegistrar.json': 2 }, 6350 ], 6351 45: [ 6352 function (require, module, exports) { 6353 /* 6354 This file is part of web3.js. 6355 6356 web3.js is free software: you can redistribute it and/or modify 6357 it under the terms of the GNU Lesser General Public License as published by 6358 the Free Software Foundation, either version 3 of the License, or 6359 (at your option) any later version. 6360 6361 web3.js is distributed in the hope that it will be useful, 6362 but WITHOUT ANY WARRANTY; without even the implied warranty of 6363 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6364 GNU Lesser General Public License for more details. 6365 6366 You should have received a copy of the GNU Lesser General Public License 6367 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6368 */ 6369 /** 6370 * @file property.js 6371 * @author Fabian Vogelsteller <fabian@frozeman.de> 6372 * @author Marek Kotewicz <marek@ethdev.com> 6373 * @date 2015 6374 */ 6375 6376 var utils = require('../utils/utils'); 6377 6378 var Property = function (options) { 6379 this.name = options.name; 6380 this.getter = options.getter; 6381 this.setter = options.setter; 6382 this.outputFormatter = options.outputFormatter; 6383 this.inputFormatter = options.inputFormatter; 6384 this.requestManager = null; 6385 }; 6386 6387 Property.prototype.setRequestManager = function (rm) { 6388 this.requestManager = rm; 6389 }; 6390 6391 /** 6392 * Should be called to format input args of method 6393 * 6394 * @method formatInput 6395 * @param {Array} 6396 * @return {Array} 6397 */ 6398 Property.prototype.formatInput = function (arg) { 6399 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6400 }; 6401 6402 /** 6403 * Should be called to format output(result) of method 6404 * 6405 * @method formatOutput 6406 * @param {Object} 6407 * @return {Object} 6408 */ 6409 Property.prototype.formatOutput = function (result) { 6410 return this.outputFormatter && result !== null && result !== undefined 6411 ? this.outputFormatter(result) 6412 : result; 6413 }; 6414 6415 /** 6416 * Should be used to extract callback from array of arguments. Modifies input param 6417 * 6418 * @method extractCallback 6419 * @param {Array} arguments 6420 * @return {Function|Null} callback, if exists 6421 */ 6422 Property.prototype.extractCallback = function (args) { 6423 if (utils.isFunction(args[args.length - 1])) { 6424 return args.pop(); // modify the args array! 6425 } 6426 }; 6427 6428 /** 6429 * Should attach function to method 6430 * 6431 * @method attachToObject 6432 * @param {Object} 6433 * @param {Function} 6434 */ 6435 Property.prototype.attachToObject = function (obj) { 6436 var proto = { 6437 get: this.buildGet(), 6438 enumerable: true, 6439 }; 6440 6441 var names = this.name.split('.'); 6442 var name = names[0]; 6443 if (names.length > 1) { 6444 obj[names[0]] = obj[names[0]] || {}; 6445 obj = obj[names[0]]; 6446 name = names[1]; 6447 } 6448 6449 Object.defineProperty(obj, name, proto); 6450 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6451 }; 6452 6453 var asyncGetterName = function (name) { 6454 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6455 }; 6456 6457 Property.prototype.buildGet = function () { 6458 var property = this; 6459 return function get() { 6460 return property.formatOutput( 6461 property.requestManager.send({ 6462 method: property.getter, 6463 }) 6464 ); 6465 }; 6466 }; 6467 6468 Property.prototype.buildAsyncGet = function () { 6469 var property = this; 6470 var get = function (callback) { 6471 property.requestManager.sendAsync( 6472 { 6473 method: property.getter, 6474 }, 6475 function (err, result) { 6476 callback(err, property.formatOutput(result)); 6477 } 6478 ); 6479 }; 6480 get.request = this.request.bind(this); 6481 return get; 6482 }; 6483 6484 /** 6485 * Should be called to create pure JSONRPC request which can be used in batch request 6486 * 6487 * @method request 6488 * @param {...} params 6489 * @return {Object} jsonrpc request 6490 */ 6491 Property.prototype.request = function () { 6492 var payload = { 6493 method: this.getter, 6494 params: [], 6495 callback: this.extractCallback(Array.prototype.slice.call(arguments)), 6496 }; 6497 payload.format = this.formatOutput.bind(this); 6498 return payload; 6499 }; 6500 6501 module.exports = Property; 6502 }, 6503 { '../utils/utils': 20 }, 6504 ], 6505 46: [ 6506 function (require, module, exports) { 6507 /* 6508 This file is part of web3.js. 6509 6510 web3.js is free software: you can redistribute it and/or modify 6511 it under the terms of the GNU Lesser General Public License as published by 6512 the Free Software Foundation, either version 3 of the License, or 6513 (at your option) any later version. 6514 6515 web3.js is distributed in the hope that it will be useful, 6516 but WITHOUT ANY WARRANTY; without even the implied warranty of 6517 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6518 GNU Lesser General Public License for more details. 6519 6520 You should have received a copy of the GNU Lesser General Public License 6521 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6522 */ 6523 /** 6524 * @file requestmanager.js 6525 * @author Jeffrey Wilcke <jeff@ethdev.com> 6526 * @author Marek Kotewicz <marek@ethdev.com> 6527 * @author Marian Oancea <marian@ethdev.com> 6528 * @author Fabian Vogelsteller <fabian@ethdev.com> 6529 * @author Gav Wood <g@ethdev.com> 6530 * @date 2014 6531 */ 6532 6533 var Jsonrpc = require('./jsonrpc'); 6534 var utils = require('../utils/utils'); 6535 var c = require('../utils/config'); 6536 var errors = require('./errors'); 6537 6538 /** 6539 * It's responsible for passing messages to providers 6540 * It's also responsible for polling the ethereum node for incoming messages 6541 * Default poll timeout is 1 second 6542 * Singleton 6543 */ 6544 var RequestManager = function (provider) { 6545 this.provider = provider; 6546 this.polls = {}; 6547 this.timeout = null; 6548 }; 6549 6550 /** 6551 * Should be used to synchronously send request 6552 * 6553 * @method send 6554 * @param {Object} data 6555 * @return {Object} 6556 */ 6557 RequestManager.prototype.send = function (data) { 6558 if (!this.provider) { 6559 console.error(errors.InvalidProvider()); 6560 return null; 6561 } 6562 6563 var payload = Jsonrpc.toPayload(data.method, data.params); 6564 var result = this.provider.send(payload); 6565 6566 if (!Jsonrpc.isValidResponse(result)) { 6567 throw errors.InvalidResponse(result); 6568 } 6569 6570 return result.result; 6571 }; 6572 6573 /** 6574 * Should be used to asynchronously send request 6575 * 6576 * @method sendAsync 6577 * @param {Object} data 6578 * @param {Function} callback 6579 */ 6580 RequestManager.prototype.sendAsync = function (data, callback) { 6581 if (!this.provider) { 6582 return callback(errors.InvalidProvider()); 6583 } 6584 6585 var payload = Jsonrpc.toPayload(data.method, data.params); 6586 this.provider.sendAsync(payload, function (err, result) { 6587 if (err) { 6588 return callback(err); 6589 } 6590 6591 if (!Jsonrpc.isValidResponse(result)) { 6592 return callback(errors.InvalidResponse(result)); 6593 } 6594 6595 callback(null, result.result); 6596 }); 6597 }; 6598 6599 /** 6600 * Should be called to asynchronously send batch request 6601 * 6602 * @method sendBatch 6603 * @param {Array} batch data 6604 * @param {Function} callback 6605 */ 6606 RequestManager.prototype.sendBatch = function (data, callback) { 6607 if (!this.provider) { 6608 return callback(errors.InvalidProvider()); 6609 } 6610 6611 var payload = Jsonrpc.toBatchPayload(data); 6612 6613 this.provider.sendAsync(payload, function (err, results) { 6614 if (err) { 6615 return callback(err); 6616 } 6617 6618 if (!utils.isArray(results)) { 6619 return callback(errors.InvalidResponse(results)); 6620 } 6621 6622 callback(err, results); 6623 }); 6624 }; 6625 6626 /** 6627 * Should be used to set provider of request manager 6628 * 6629 * @method setProvider 6630 * @param {Object} 6631 */ 6632 RequestManager.prototype.setProvider = function (p) { 6633 this.provider = p; 6634 }; 6635 6636 /** 6637 * Should be used to start polling 6638 * 6639 * @method startPolling 6640 * @param {Object} data 6641 * @param {Number} pollId 6642 * @param {Function} callback 6643 * @param {Function} uninstall 6644 * 6645 * @todo cleanup number of params 6646 */ 6647 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6648 this.polls[pollId] = { data: data, id: pollId, callback: callback, uninstall: uninstall }; 6649 6650 // start polling 6651 if (!this.timeout) { 6652 this.poll(); 6653 } 6654 }; 6655 6656 /** 6657 * Should be used to stop polling for filter with given id 6658 * 6659 * @method stopPolling 6660 * @param {Number} pollId 6661 */ 6662 RequestManager.prototype.stopPolling = function (pollId) { 6663 delete this.polls[pollId]; 6664 6665 // stop polling 6666 if (Object.keys(this.polls).length === 0 && this.timeout) { 6667 clearTimeout(this.timeout); 6668 this.timeout = null; 6669 } 6670 }; 6671 6672 /** 6673 * Should be called to reset the polling mechanism of the request manager 6674 * 6675 * @method reset 6676 */ 6677 RequestManager.prototype.reset = function (keepIsSyncing) { 6678 /*jshint maxcomplexity:5 */ 6679 6680 for (var key in this.polls) { 6681 // remove all polls, except sync polls, 6682 // they need to be removed manually by calling syncing.stopWatching() 6683 if (!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6684 this.polls[key].uninstall(); 6685 delete this.polls[key]; 6686 } 6687 } 6688 6689 // stop polling 6690 if (Object.keys(this.polls).length === 0 && this.timeout) { 6691 clearTimeout(this.timeout); 6692 this.timeout = null; 6693 } 6694 }; 6695 6696 /** 6697 * Should be called to poll for changes on filter with given id 6698 * 6699 * @method poll 6700 */ 6701 RequestManager.prototype.poll = function () { 6702 /*jshint maxcomplexity: 6 */ 6703 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6704 6705 if (Object.keys(this.polls).length === 0) { 6706 return; 6707 } 6708 6709 if (!this.provider) { 6710 console.error(errors.InvalidProvider()); 6711 return; 6712 } 6713 6714 var pollsData = []; 6715 var pollsIds = []; 6716 for (var key in this.polls) { 6717 pollsData.push(this.polls[key].data); 6718 pollsIds.push(key); 6719 } 6720 6721 if (pollsData.length === 0) { 6722 return; 6723 } 6724 6725 var payload = Jsonrpc.toBatchPayload(pollsData); 6726 6727 // map the request id to they poll id 6728 var pollsIdMap = {}; 6729 payload.forEach(function (load, index) { 6730 pollsIdMap[load.id] = pollsIds[index]; 6731 }); 6732 6733 var self = this; 6734 this.provider.sendAsync(payload, function (error, results) { 6735 // TODO: console log? 6736 if (error) { 6737 return; 6738 } 6739 6740 if (!utils.isArray(results)) { 6741 throw errors.InvalidResponse(results); 6742 } 6743 results 6744 .map(function (result) { 6745 var id = pollsIdMap[result.id]; 6746 6747 // make sure the filter is still installed after arrival of the request 6748 if (self.polls[id]) { 6749 result.callback = self.polls[id].callback; 6750 return result; 6751 } else return false; 6752 }) 6753 .filter(function (result) { 6754 return !!result; 6755 }) 6756 .filter(function (result) { 6757 var valid = Jsonrpc.isValidResponse(result); 6758 if (!valid) { 6759 result.callback(errors.InvalidResponse(result)); 6760 } 6761 return valid; 6762 }) 6763 .forEach(function (result) { 6764 result.callback(null, result.result); 6765 }); 6766 }); 6767 }; 6768 6769 module.exports = RequestManager; 6770 }, 6771 { '../utils/config': 18, '../utils/utils': 20, './errors': 26, './jsonrpc': 35 }, 6772 ], 6773 47: [ 6774 function (require, module, exports) { 6775 var Settings = function () { 6776 this.defaultBlock = 'latest'; 6777 this.defaultAccount = undefined; 6778 }; 6779 6780 module.exports = Settings; 6781 }, 6782 {}, 6783 ], 6784 48: [ 6785 function (require, module, exports) { 6786 /* 6787 This file is part of web3.js. 6788 6789 web3.js is free software: you can redistribute it and/or modify 6790 it under the terms of the GNU Lesser General Public License as published by 6791 the Free Software Foundation, either version 3 of the License, or 6792 (at your option) any later version. 6793 6794 web3.js is distributed in the hope that it will be useful, 6795 but WITHOUT ANY WARRANTY; without even the implied warranty of 6796 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6797 GNU Lesser General Public License for more details. 6798 6799 You should have received a copy of the GNU Lesser General Public License 6800 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6801 */ 6802 /** @file syncing.js 6803 * @authors: 6804 * Fabian Vogelsteller <fabian@ethdev.com> 6805 * @date 2015 6806 */ 6807 6808 var formatters = require('./formatters'); 6809 var utils = require('../utils/utils'); 6810 6811 var count = 1; 6812 6813 /** 6814 Adds the callback and sets up the methods, to iterate over the results. 6815 6816 @method pollSyncing 6817 @param {Object} self 6818 */ 6819 var pollSyncing = function (self) { 6820 var onMessage = function (error, sync) { 6821 if (error) { 6822 return self.callbacks.forEach(function (callback) { 6823 callback(error); 6824 }); 6825 } 6826 6827 if (utils.isObject(sync) && sync.startingBlock) sync = formatters.outputSyncingFormatter(sync); 6828 6829 self.callbacks.forEach(function (callback) { 6830 if (self.lastSyncState !== sync) { 6831 // call the callback with true first so the app can stop anything, before receiving the sync data 6832 if (!self.lastSyncState && utils.isObject(sync)) callback(null, true); 6833 6834 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6835 setTimeout(function () { 6836 callback(null, sync); 6837 }, 0); 6838 6839 self.lastSyncState = sync; 6840 } 6841 }); 6842 }; 6843 6844 self.requestManager.startPolling( 6845 { 6846 method: 'eth_syncing', 6847 params: [], 6848 }, 6849 self.pollId, 6850 onMessage, 6851 self.stopWatching.bind(self) 6852 ); 6853 }; 6854 6855 var IsSyncing = function (requestManager, callback) { 6856 this.requestManager = requestManager; 6857 this.pollId = 'syncPoll_' + count++; 6858 this.callbacks = []; 6859 this.addCallback(callback); 6860 this.lastSyncState = false; 6861 pollSyncing(this); 6862 6863 return this; 6864 }; 6865 6866 IsSyncing.prototype.addCallback = function (callback) { 6867 if (callback) this.callbacks.push(callback); 6868 return this; 6869 }; 6870 6871 IsSyncing.prototype.stopWatching = function () { 6872 this.requestManager.stopPolling(this.pollId); 6873 this.callbacks = []; 6874 }; 6875 6876 module.exports = IsSyncing; 6877 }, 6878 { '../utils/utils': 20, './formatters': 30 }, 6879 ], 6880 49: [ 6881 function (require, module, exports) { 6882 /* 6883 This file is part of web3.js. 6884 6885 web3.js is free software: you can redistribute it and/or modify 6886 it under the terms of the GNU Lesser General Public License as published by 6887 the Free Software Foundation, either version 3 of the License, or 6888 (at your option) any later version. 6889 6890 web3.js is distributed in the hope that it will be useful, 6891 but WITHOUT ANY WARRANTY; without even the implied warranty of 6892 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6893 GNU Lesser General Public License for more details. 6894 6895 You should have received a copy of the GNU Lesser General Public License 6896 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6897 */ 6898 /** 6899 * @file transfer.js 6900 * @author Marek Kotewicz <marek@ethdev.com> 6901 * @date 2015 6902 */ 6903 6904 var Iban = require('./iban'); 6905 var exchangeAbi = require('../contracts/SmartExchange.json'); 6906 6907 /** 6908 * Should be used to make Iban transfer 6909 * 6910 * @method transfer 6911 * @param {String} from 6912 * @param {String} to iban 6913 * @param {Value} value to be tranfered 6914 * @param {Function} callback, callback 6915 */ 6916 var transfer = function (eth, from, to, value, callback) { 6917 var iban = new Iban(to); 6918 if (!iban.isValid()) { 6919 throw new Error('invalid iban address'); 6920 } 6921 6922 if (iban.isDirect()) { 6923 return transferToAddress(eth, from, iban.address(), value, callback); 6924 } 6925 6926 if (!callback) { 6927 var address = eth.icapNamereg().addr(iban.institution()); 6928 return deposit(eth, from, address, value, iban.client()); 6929 } 6930 6931 eth.icapNamereg().addr(iban.institution(), function (err, address) { 6932 return deposit(eth, from, address, value, iban.client(), callback); 6933 }); 6934 }; 6935 6936 /** 6937 * Should be used to transfer funds to certain address 6938 * 6939 * @method transferToAddress 6940 * @param {String} from 6941 * @param {String} to 6942 * @param {Value} value to be tranfered 6943 * @param {Function} callback, callback 6944 */ 6945 var transferToAddress = function (eth, from, to, value, callback) { 6946 return eth.sendTransaction( 6947 { 6948 address: to, 6949 from: from, 6950 value: value, 6951 }, 6952 callback 6953 ); 6954 }; 6955 6956 /** 6957 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6958 * 6959 * @method deposit 6960 * @param {String} from 6961 * @param {String} to 6962 * @param {Value} value to be transferred 6963 * @param {String} client unique identifier 6964 * @param {Function} callback, callback 6965 */ 6966 var deposit = function (eth, from, to, value, client, callback) { 6967 var abi = exchangeAbi; 6968 return eth.contract(abi).at(to).deposit( 6969 client, 6970 { 6971 from: from, 6972 value: value, 6973 }, 6974 callback 6975 ); 6976 }; 6977 6978 module.exports = transfer; 6979 }, 6980 { '../contracts/SmartExchange.json': 3, './iban': 33 }, 6981 ], 6982 50: [function (require, module, exports) {}, {}], 6983 51: [ 6984 function (require, module, exports) { 6985 (function (root, factory, undef) { 6986 if (typeof exports === 'object') { 6987 // CommonJS 6988 module.exports = exports = factory( 6989 require('./core'), 6990 require('./enc-base64'), 6991 require('./md5'), 6992 require('./evpkdf'), 6993 require('./cipher-core') 6994 ); 6995 } else if (typeof define === 'function' && define.amd) { 6996 // AMD 6997 define(['./core', './enc-base64', './md5', './evpkdf', './cipher-core'], factory); 6998 } else { 6999 // Global (browser) 7000 factory(root.CryptoJS); 7001 } 7002 })(this, function (CryptoJS) { 7003 (function () { 7004 // Shortcuts 7005 var C = CryptoJS; 7006 var C_lib = C.lib; 7007 var BlockCipher = C_lib.BlockCipher; 7008 var C_algo = C.algo; 7009 7010 // Lookup tables 7011 var SBOX = []; 7012 var INV_SBOX = []; 7013 var SUB_MIX_0 = []; 7014 var SUB_MIX_1 = []; 7015 var SUB_MIX_2 = []; 7016 var SUB_MIX_3 = []; 7017 var INV_SUB_MIX_0 = []; 7018 var INV_SUB_MIX_1 = []; 7019 var INV_SUB_MIX_2 = []; 7020 var INV_SUB_MIX_3 = []; 7021 7022 // Compute lookup tables 7023 (function () { 7024 // Compute double table 7025 var d = []; 7026 for (var i = 0; i < 256; i++) { 7027 if (i < 128) { 7028 d[i] = i << 1; 7029 } else { 7030 d[i] = (i << 1) ^ 0x11b; 7031 } 7032 } 7033 7034 // Walk GF(2^8) 7035 var x = 0; 7036 var xi = 0; 7037 for (var i = 0; i < 256; i++) { 7038 // Compute sbox 7039 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 7040 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 7041 SBOX[x] = sx; 7042 INV_SBOX[sx] = x; 7043 7044 // Compute multiplication 7045 var x2 = d[x]; 7046 var x4 = d[x2]; 7047 var x8 = d[x4]; 7048 7049 // Compute sub bytes, mix columns tables 7050 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 7051 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 7052 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 7053 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 7054 SUB_MIX_3[x] = t; 7055 7056 // Compute inv sub bytes, inv mix columns tables 7057 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 7058 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 7059 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 7060 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 7061 INV_SUB_MIX_3[sx] = t; 7062 7063 // Compute next counter 7064 if (!x) { 7065 x = xi = 1; 7066 } else { 7067 x = x2 ^ d[d[d[x8 ^ x2]]]; 7068 xi ^= d[d[xi]]; 7069 } 7070 } 7071 })(); 7072 7073 // Precomputed Rcon lookup 7074 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 7075 7076 /** 7077 * AES block cipher algorithm. 7078 */ 7079 var AES = (C_algo.AES = BlockCipher.extend({ 7080 _doReset: function () { 7081 // Skip reset of nRounds has been set before and key did not change 7082 if (this._nRounds && this._keyPriorReset === this._key) { 7083 return; 7084 } 7085 7086 // Shortcuts 7087 var key = (this._keyPriorReset = this._key); 7088 var keyWords = key.words; 7089 var keySize = key.sigBytes / 4; 7090 7091 // Compute number of rounds 7092 var nRounds = (this._nRounds = keySize + 6); 7093 7094 // Compute number of key schedule rows 7095 var ksRows = (nRounds + 1) * 4; 7096 7097 // Compute key schedule 7098 var keySchedule = (this._keySchedule = []); 7099 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 7100 if (ksRow < keySize) { 7101 keySchedule[ksRow] = keyWords[ksRow]; 7102 } else { 7103 var t = keySchedule[ksRow - 1]; 7104 7105 if (!(ksRow % keySize)) { 7106 // Rot word 7107 t = (t << 8) | (t >>> 24); 7108 7109 // Sub word 7110 t = 7111 (SBOX[t >>> 24] << 24) | 7112 (SBOX[(t >>> 16) & 0xff] << 16) | 7113 (SBOX[(t >>> 8) & 0xff] << 8) | 7114 SBOX[t & 0xff]; 7115 7116 // Mix Rcon 7117 t ^= RCON[(ksRow / keySize) | 0] << 24; 7118 } else if (keySize > 6 && ksRow % keySize == 4) { 7119 // Sub word 7120 t = 7121 (SBOX[t >>> 24] << 24) | 7122 (SBOX[(t >>> 16) & 0xff] << 16) | 7123 (SBOX[(t >>> 8) & 0xff] << 8) | 7124 SBOX[t & 0xff]; 7125 } 7126 7127 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 7128 } 7129 } 7130 7131 // Compute inv key schedule 7132 var invKeySchedule = (this._invKeySchedule = []); 7133 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 7134 var ksRow = ksRows - invKsRow; 7135 7136 if (invKsRow % 4) { 7137 var t = keySchedule[ksRow]; 7138 } else { 7139 var t = keySchedule[ksRow - 4]; 7140 } 7141 7142 if (invKsRow < 4 || ksRow <= 4) { 7143 invKeySchedule[invKsRow] = t; 7144 } else { 7145 invKeySchedule[invKsRow] = 7146 INV_SUB_MIX_0[SBOX[t >>> 24]] ^ 7147 INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 7148 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ 7149 INV_SUB_MIX_3[SBOX[t & 0xff]]; 7150 } 7151 } 7152 }, 7153 7154 encryptBlock: function (M, offset) { 7155 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 7156 }, 7157 7158 decryptBlock: function (M, offset) { 7159 // Swap 2nd and 4th rows 7160 var t = M[offset + 1]; 7161 M[offset + 1] = M[offset + 3]; 7162 M[offset + 3] = t; 7163 7164 this._doCryptBlock( 7165 M, 7166 offset, 7167 this._invKeySchedule, 7168 INV_SUB_MIX_0, 7169 INV_SUB_MIX_1, 7170 INV_SUB_MIX_2, 7171 INV_SUB_MIX_3, 7172 INV_SBOX 7173 ); 7174 7175 // Inv swap 2nd and 4th rows 7176 var t = M[offset + 1]; 7177 M[offset + 1] = M[offset + 3]; 7178 M[offset + 3] = t; 7179 }, 7180 7181 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 7182 // Shortcut 7183 var nRounds = this._nRounds; 7184 7185 // Get input, add round key 7186 var s0 = M[offset] ^ keySchedule[0]; 7187 var s1 = M[offset + 1] ^ keySchedule[1]; 7188 var s2 = M[offset + 2] ^ keySchedule[2]; 7189 var s3 = M[offset + 3] ^ keySchedule[3]; 7190 7191 // Key schedule row counter 7192 var ksRow = 4; 7193 7194 // Rounds 7195 for (var round = 1; round < nRounds; round++) { 7196 // Shift rows, sub bytes, mix columns, add round key 7197 var t0 = 7198 SUB_MIX_0[s0 >>> 24] ^ 7199 SUB_MIX_1[(s1 >>> 16) & 0xff] ^ 7200 SUB_MIX_2[(s2 >>> 8) & 0xff] ^ 7201 SUB_MIX_3[s3 & 0xff] ^ 7202 keySchedule[ksRow++]; 7203 var t1 = 7204 SUB_MIX_0[s1 >>> 24] ^ 7205 SUB_MIX_1[(s2 >>> 16) & 0xff] ^ 7206 SUB_MIX_2[(s3 >>> 8) & 0xff] ^ 7207 SUB_MIX_3[s0 & 0xff] ^ 7208 keySchedule[ksRow++]; 7209 var t2 = 7210 SUB_MIX_0[s2 >>> 24] ^ 7211 SUB_MIX_1[(s3 >>> 16) & 0xff] ^ 7212 SUB_MIX_2[(s0 >>> 8) & 0xff] ^ 7213 SUB_MIX_3[s1 & 0xff] ^ 7214 keySchedule[ksRow++]; 7215 var t3 = 7216 SUB_MIX_0[s3 >>> 24] ^ 7217 SUB_MIX_1[(s0 >>> 16) & 0xff] ^ 7218 SUB_MIX_2[(s1 >>> 8) & 0xff] ^ 7219 SUB_MIX_3[s2 & 0xff] ^ 7220 keySchedule[ksRow++]; 7221 7222 // Update state 7223 s0 = t0; 7224 s1 = t1; 7225 s2 = t2; 7226 s3 = t3; 7227 } 7228 7229 // Shift rows, sub bytes, add round key 7230 var t0 = 7231 ((SBOX[s0 >>> 24] << 24) | 7232 (SBOX[(s1 >>> 16) & 0xff] << 16) | 7233 (SBOX[(s2 >>> 8) & 0xff] << 8) | 7234 SBOX[s3 & 0xff]) ^ 7235 keySchedule[ksRow++]; 7236 var t1 = 7237 ((SBOX[s1 >>> 24] << 24) | 7238 (SBOX[(s2 >>> 16) & 0xff] << 16) | 7239 (SBOX[(s3 >>> 8) & 0xff] << 8) | 7240 SBOX[s0 & 0xff]) ^ 7241 keySchedule[ksRow++]; 7242 var t2 = 7243 ((SBOX[s2 >>> 24] << 24) | 7244 (SBOX[(s3 >>> 16) & 0xff] << 16) | 7245 (SBOX[(s0 >>> 8) & 0xff] << 8) | 7246 SBOX[s1 & 0xff]) ^ 7247 keySchedule[ksRow++]; 7248 var t3 = 7249 ((SBOX[s3 >>> 24] << 24) | 7250 (SBOX[(s0 >>> 16) & 0xff] << 16) | 7251 (SBOX[(s1 >>> 8) & 0xff] << 8) | 7252 SBOX[s2 & 0xff]) ^ 7253 keySchedule[ksRow++]; 7254 7255 // Set output 7256 M[offset] = t0; 7257 M[offset + 1] = t1; 7258 M[offset + 2] = t2; 7259 M[offset + 3] = t3; 7260 }, 7261 7262 keySize: 256 / 32, 7263 })); 7264 7265 /** 7266 * Shortcut functions to the cipher's object interface. 7267 * 7268 * @example 7269 * 7270 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7271 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7272 */ 7273 C.AES = BlockCipher._createHelper(AES); 7274 })(); 7275 7276 return CryptoJS.AES; 7277 }); 7278 }, 7279 { './cipher-core': 52, './core': 53, './enc-base64': 54, './evpkdf': 56, './md5': 61 }, 7280 ], 7281 52: [ 7282 function (require, module, exports) { 7283 (function (root, factory) { 7284 if (typeof exports === 'object') { 7285 // CommonJS 7286 module.exports = exports = factory(require('./core')); 7287 } else if (typeof define === 'function' && define.amd) { 7288 // AMD 7289 define(['./core'], factory); 7290 } else { 7291 // Global (browser) 7292 factory(root.CryptoJS); 7293 } 7294 })(this, function (CryptoJS) { 7295 /** 7296 * Cipher core components. 7297 */ 7298 CryptoJS.lib.Cipher || 7299 (function (undefined) { 7300 // Shortcuts 7301 var C = CryptoJS; 7302 var C_lib = C.lib; 7303 var Base = C_lib.Base; 7304 var WordArray = C_lib.WordArray; 7305 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7306 var C_enc = C.enc; 7307 var Utf8 = C_enc.Utf8; 7308 var Base64 = C_enc.Base64; 7309 var C_algo = C.algo; 7310 var EvpKDF = C_algo.EvpKDF; 7311 7312 /** 7313 * Abstract base cipher template. 7314 * 7315 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7316 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7317 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7318 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7319 */ 7320 var Cipher = (C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7321 /** 7322 * Configuration options. 7323 * 7324 * @property {WordArray} iv The IV to use for this operation. 7325 */ 7326 cfg: Base.extend(), 7327 7328 /** 7329 * Creates this cipher in encryption mode. 7330 * 7331 * @param {WordArray} key The key. 7332 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7333 * 7334 * @return {Cipher} A cipher instance. 7335 * 7336 * @static 7337 * 7338 * @example 7339 * 7340 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7341 */ 7342 createEncryptor: function (key, cfg) { 7343 return this.create(this._ENC_XFORM_MODE, key, cfg); 7344 }, 7345 7346 /** 7347 * Creates this cipher in decryption mode. 7348 * 7349 * @param {WordArray} key The key. 7350 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7351 * 7352 * @return {Cipher} A cipher instance. 7353 * 7354 * @static 7355 * 7356 * @example 7357 * 7358 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7359 */ 7360 createDecryptor: function (key, cfg) { 7361 return this.create(this._DEC_XFORM_MODE, key, cfg); 7362 }, 7363 7364 /** 7365 * Initializes a newly created cipher. 7366 * 7367 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7368 * @param {WordArray} key The key. 7369 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7370 * 7371 * @example 7372 * 7373 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7374 */ 7375 init: function (xformMode, key, cfg) { 7376 // Apply config defaults 7377 this.cfg = this.cfg.extend(cfg); 7378 7379 // Store transform mode and key 7380 this._xformMode = xformMode; 7381 this._key = key; 7382 7383 // Set initial values 7384 this.reset(); 7385 }, 7386 7387 /** 7388 * Resets this cipher to its initial state. 7389 * 7390 * @example 7391 * 7392 * cipher.reset(); 7393 */ 7394 reset: function () { 7395 // Reset data buffer 7396 BufferedBlockAlgorithm.reset.call(this); 7397 7398 // Perform concrete-cipher logic 7399 this._doReset(); 7400 }, 7401 7402 /** 7403 * Adds data to be encrypted or decrypted. 7404 * 7405 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7406 * 7407 * @return {WordArray} The data after processing. 7408 * 7409 * @example 7410 * 7411 * var encrypted = cipher.process('data'); 7412 * var encrypted = cipher.process(wordArray); 7413 */ 7414 process: function (dataUpdate) { 7415 // Append 7416 this._append(dataUpdate); 7417 7418 // Process available blocks 7419 return this._process(); 7420 }, 7421 7422 /** 7423 * Finalizes the encryption or decryption process. 7424 * Note that the finalize operation is effectively a destructive, read-once operation. 7425 * 7426 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7427 * 7428 * @return {WordArray} The data after final processing. 7429 * 7430 * @example 7431 * 7432 * var encrypted = cipher.finalize(); 7433 * var encrypted = cipher.finalize('data'); 7434 * var encrypted = cipher.finalize(wordArray); 7435 */ 7436 finalize: function (dataUpdate) { 7437 // Final data update 7438 if (dataUpdate) { 7439 this._append(dataUpdate); 7440 } 7441 7442 // Perform concrete-cipher logic 7443 var finalProcessedData = this._doFinalize(); 7444 7445 return finalProcessedData; 7446 }, 7447 7448 keySize: 128 / 32, 7449 7450 ivSize: 128 / 32, 7451 7452 _ENC_XFORM_MODE: 1, 7453 7454 _DEC_XFORM_MODE: 2, 7455 7456 /** 7457 * Creates shortcut functions to a cipher's object interface. 7458 * 7459 * @param {Cipher} cipher The cipher to create a helper for. 7460 * 7461 * @return {Object} An object with encrypt and decrypt shortcut functions. 7462 * 7463 * @static 7464 * 7465 * @example 7466 * 7467 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7468 */ 7469 _createHelper: (function () { 7470 function selectCipherStrategy(key) { 7471 if (typeof key == 'string') { 7472 return PasswordBasedCipher; 7473 } else { 7474 return SerializableCipher; 7475 } 7476 } 7477 7478 return function (cipher) { 7479 return { 7480 encrypt: function (message, key, cfg) { 7481 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7482 }, 7483 7484 decrypt: function (ciphertext, key, cfg) { 7485 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7486 }, 7487 }; 7488 }; 7489 })(), 7490 })); 7491 7492 /** 7493 * Abstract base stream cipher template. 7494 * 7495 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7496 */ 7497 var StreamCipher = (C_lib.StreamCipher = Cipher.extend({ 7498 _doFinalize: function () { 7499 // Process partial blocks 7500 var finalProcessedBlocks = this._process(!!'flush'); 7501 7502 return finalProcessedBlocks; 7503 }, 7504 7505 blockSize: 1, 7506 })); 7507 7508 /** 7509 * Mode namespace. 7510 */ 7511 var C_mode = (C.mode = {}); 7512 7513 /** 7514 * Abstract base block cipher mode template. 7515 */ 7516 var BlockCipherMode = (C_lib.BlockCipherMode = Base.extend({ 7517 /** 7518 * Creates this mode for encryption. 7519 * 7520 * @param {Cipher} cipher A block cipher instance. 7521 * @param {Array} iv The IV words. 7522 * 7523 * @static 7524 * 7525 * @example 7526 * 7527 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7528 */ 7529 createEncryptor: function (cipher, iv) { 7530 return this.Encryptor.create(cipher, iv); 7531 }, 7532 7533 /** 7534 * Creates this mode for decryption. 7535 * 7536 * @param {Cipher} cipher A block cipher instance. 7537 * @param {Array} iv The IV words. 7538 * 7539 * @static 7540 * 7541 * @example 7542 * 7543 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7544 */ 7545 createDecryptor: function (cipher, iv) { 7546 return this.Decryptor.create(cipher, iv); 7547 }, 7548 7549 /** 7550 * Initializes a newly created mode. 7551 * 7552 * @param {Cipher} cipher A block cipher instance. 7553 * @param {Array} iv The IV words. 7554 * 7555 * @example 7556 * 7557 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7558 */ 7559 init: function (cipher, iv) { 7560 this._cipher = cipher; 7561 this._iv = iv; 7562 }, 7563 })); 7564 7565 /** 7566 * Cipher Block Chaining mode. 7567 */ 7568 var CBC = (C_mode.CBC = (function () { 7569 /** 7570 * Abstract base CBC mode. 7571 */ 7572 var CBC = BlockCipherMode.extend(); 7573 7574 /** 7575 * CBC encryptor. 7576 */ 7577 CBC.Encryptor = CBC.extend({ 7578 /** 7579 * Processes the data block at offset. 7580 * 7581 * @param {Array} words The data words to operate on. 7582 * @param {number} offset The offset where the block starts. 7583 * 7584 * @example 7585 * 7586 * mode.processBlock(data.words, offset); 7587 */ 7588 processBlock: function (words, offset) { 7589 // Shortcuts 7590 var cipher = this._cipher; 7591 var blockSize = cipher.blockSize; 7592 7593 // XOR and encrypt 7594 xorBlock.call(this, words, offset, blockSize); 7595 cipher.encryptBlock(words, offset); 7596 7597 // Remember this block to use with next block 7598 this._prevBlock = words.slice(offset, offset + blockSize); 7599 }, 7600 }); 7601 7602 /** 7603 * CBC decryptor. 7604 */ 7605 CBC.Decryptor = CBC.extend({ 7606 /** 7607 * Processes the data block at offset. 7608 * 7609 * @param {Array} words The data words to operate on. 7610 * @param {number} offset The offset where the block starts. 7611 * 7612 * @example 7613 * 7614 * mode.processBlock(data.words, offset); 7615 */ 7616 processBlock: function (words, offset) { 7617 // Shortcuts 7618 var cipher = this._cipher; 7619 var blockSize = cipher.blockSize; 7620 7621 // Remember this block to use with next block 7622 var thisBlock = words.slice(offset, offset + blockSize); 7623 7624 // Decrypt and XOR 7625 cipher.decryptBlock(words, offset); 7626 xorBlock.call(this, words, offset, blockSize); 7627 7628 // This block becomes the previous block 7629 this._prevBlock = thisBlock; 7630 }, 7631 }); 7632 7633 function xorBlock(words, offset, blockSize) { 7634 // Shortcut 7635 var iv = this._iv; 7636 7637 // Choose mixing block 7638 if (iv) { 7639 var block = iv; 7640 7641 // Remove IV for subsequent blocks 7642 this._iv = undefined; 7643 } else { 7644 var block = this._prevBlock; 7645 } 7646 7647 // XOR blocks 7648 for (var i = 0; i < blockSize; i++) { 7649 words[offset + i] ^= block[i]; 7650 } 7651 } 7652 7653 return CBC; 7654 })()); 7655 7656 /** 7657 * Padding namespace. 7658 */ 7659 var C_pad = (C.pad = {}); 7660 7661 /** 7662 * PKCS #5/7 padding strategy. 7663 */ 7664 var Pkcs7 = (C_pad.Pkcs7 = { 7665 /** 7666 * Pads data using the algorithm defined in PKCS #5/7. 7667 * 7668 * @param {WordArray} data The data to pad. 7669 * @param {number} blockSize The multiple that the data should be padded to. 7670 * 7671 * @static 7672 * 7673 * @example 7674 * 7675 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7676 */ 7677 pad: function (data, blockSize) { 7678 // Shortcut 7679 var blockSizeBytes = blockSize * 4; 7680 7681 // Count padding bytes 7682 var nPaddingBytes = blockSizeBytes - (data.sigBytes % blockSizeBytes); 7683 7684 // Create padding word 7685 var paddingWord = 7686 (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7687 7688 // Create padding 7689 var paddingWords = []; 7690 for (var i = 0; i < nPaddingBytes; i += 4) { 7691 paddingWords.push(paddingWord); 7692 } 7693 var padding = WordArray.create(paddingWords, nPaddingBytes); 7694 7695 // Add padding 7696 data.concat(padding); 7697 }, 7698 7699 /** 7700 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7701 * 7702 * @param {WordArray} data The data to unpad. 7703 * 7704 * @static 7705 * 7706 * @example 7707 * 7708 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7709 */ 7710 unpad: function (data) { 7711 // Get number of padding bytes from last byte 7712 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7713 7714 // Remove padding 7715 data.sigBytes -= nPaddingBytes; 7716 }, 7717 }); 7718 7719 /** 7720 * Abstract base block cipher template. 7721 * 7722 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7723 */ 7724 var BlockCipher = (C_lib.BlockCipher = Cipher.extend({ 7725 /** 7726 * Configuration options. 7727 * 7728 * @property {Mode} mode The block mode to use. Default: CBC 7729 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7730 */ 7731 cfg: Cipher.cfg.extend({ 7732 mode: CBC, 7733 padding: Pkcs7, 7734 }), 7735 7736 reset: function () { 7737 // Reset cipher 7738 Cipher.reset.call(this); 7739 7740 // Shortcuts 7741 var cfg = this.cfg; 7742 var iv = cfg.iv; 7743 var mode = cfg.mode; 7744 7745 // Reset block mode 7746 if (this._xformMode == this._ENC_XFORM_MODE) { 7747 var modeCreator = mode.createEncryptor; 7748 } /* if (this._xformMode == this._DEC_XFORM_MODE) */ else { 7749 var modeCreator = mode.createDecryptor; 7750 7751 // Keep at least one block in the buffer for unpadding 7752 this._minBufferSize = 1; 7753 } 7754 this._mode = modeCreator.call(mode, this, iv && iv.words); 7755 }, 7756 7757 _doProcessBlock: function (words, offset) { 7758 this._mode.processBlock(words, offset); 7759 }, 7760 7761 _doFinalize: function () { 7762 // Shortcut 7763 var padding = this.cfg.padding; 7764 7765 // Finalize 7766 if (this._xformMode == this._ENC_XFORM_MODE) { 7767 // Pad data 7768 padding.pad(this._data, this.blockSize); 7769 7770 // Process final blocks 7771 var finalProcessedBlocks = this._process(!!'flush'); 7772 } /* if (this._xformMode == this._DEC_XFORM_MODE) */ else { 7773 // Process final blocks 7774 var finalProcessedBlocks = this._process(!!'flush'); 7775 7776 // Unpad data 7777 padding.unpad(finalProcessedBlocks); 7778 } 7779 7780 return finalProcessedBlocks; 7781 }, 7782 7783 blockSize: 128 / 32, 7784 })); 7785 7786 /** 7787 * A collection of cipher parameters. 7788 * 7789 * @property {WordArray} ciphertext The raw ciphertext. 7790 * @property {WordArray} key The key to this ciphertext. 7791 * @property {WordArray} iv The IV used in the ciphering operation. 7792 * @property {WordArray} salt The salt used with a key derivation function. 7793 * @property {Cipher} algorithm The cipher algorithm. 7794 * @property {Mode} mode The block mode used in the ciphering operation. 7795 * @property {Padding} padding The padding scheme used in the ciphering operation. 7796 * @property {number} blockSize The block size of the cipher. 7797 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7798 */ 7799 var CipherParams = (C_lib.CipherParams = Base.extend({ 7800 /** 7801 * Initializes a newly created cipher params object. 7802 * 7803 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7804 * 7805 * @example 7806 * 7807 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7808 * ciphertext: ciphertextWordArray, 7809 * key: keyWordArray, 7810 * iv: ivWordArray, 7811 * salt: saltWordArray, 7812 * algorithm: CryptoJS.algo.AES, 7813 * mode: CryptoJS.mode.CBC, 7814 * padding: CryptoJS.pad.PKCS7, 7815 * blockSize: 4, 7816 * formatter: CryptoJS.format.OpenSSL 7817 * }); 7818 */ 7819 init: function (cipherParams) { 7820 this.mixIn(cipherParams); 7821 }, 7822 7823 /** 7824 * Converts this cipher params object to a string. 7825 * 7826 * @param {Format} formatter (Optional) The formatting strategy to use. 7827 * 7828 * @return {string} The stringified cipher params. 7829 * 7830 * @throws Error If neither the formatter nor the default formatter is set. 7831 * 7832 * @example 7833 * 7834 * var string = cipherParams + ''; 7835 * var string = cipherParams.toString(); 7836 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7837 */ 7838 toString: function (formatter) { 7839 return (formatter || this.formatter).stringify(this); 7840 }, 7841 })); 7842 7843 /** 7844 * Format namespace. 7845 */ 7846 var C_format = (C.format = {}); 7847 7848 /** 7849 * OpenSSL formatting strategy. 7850 */ 7851 var OpenSSLFormatter = (C_format.OpenSSL = { 7852 /** 7853 * Converts a cipher params object to an OpenSSL-compatible string. 7854 * 7855 * @param {CipherParams} cipherParams The cipher params object. 7856 * 7857 * @return {string} The OpenSSL-compatible string. 7858 * 7859 * @static 7860 * 7861 * @example 7862 * 7863 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7864 */ 7865 stringify: function (cipherParams) { 7866 // Shortcuts 7867 var ciphertext = cipherParams.ciphertext; 7868 var salt = cipherParams.salt; 7869 7870 // Format 7871 if (salt) { 7872 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7873 } else { 7874 var wordArray = ciphertext; 7875 } 7876 7877 return wordArray.toString(Base64); 7878 }, 7879 7880 /** 7881 * Converts an OpenSSL-compatible string to a cipher params object. 7882 * 7883 * @param {string} openSSLStr The OpenSSL-compatible string. 7884 * 7885 * @return {CipherParams} The cipher params object. 7886 * 7887 * @static 7888 * 7889 * @example 7890 * 7891 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7892 */ 7893 parse: function (openSSLStr) { 7894 // Parse base64 7895 var ciphertext = Base64.parse(openSSLStr); 7896 7897 // Shortcut 7898 var ciphertextWords = ciphertext.words; 7899 7900 // Test for salt 7901 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7902 // Extract salt 7903 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7904 7905 // Remove salt from ciphertext 7906 ciphertextWords.splice(0, 4); 7907 ciphertext.sigBytes -= 16; 7908 } 7909 7910 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7911 }, 7912 }); 7913 7914 /** 7915 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7916 */ 7917 var SerializableCipher = (C_lib.SerializableCipher = Base.extend({ 7918 /** 7919 * Configuration options. 7920 * 7921 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7922 */ 7923 cfg: Base.extend({ 7924 format: OpenSSLFormatter, 7925 }), 7926 7927 /** 7928 * Encrypts a message. 7929 * 7930 * @param {Cipher} cipher The cipher algorithm to use. 7931 * @param {WordArray|string} message The message to encrypt. 7932 * @param {WordArray} key The key. 7933 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7934 * 7935 * @return {CipherParams} A cipher params object. 7936 * 7937 * @static 7938 * 7939 * @example 7940 * 7941 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7942 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7943 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7944 */ 7945 encrypt: function (cipher, message, key, cfg) { 7946 // Apply config defaults 7947 cfg = this.cfg.extend(cfg); 7948 7949 // Encrypt 7950 var encryptor = cipher.createEncryptor(key, cfg); 7951 var ciphertext = encryptor.finalize(message); 7952 7953 // Shortcut 7954 var cipherCfg = encryptor.cfg; 7955 7956 // Create and return serializable cipher params 7957 return CipherParams.create({ 7958 ciphertext: ciphertext, 7959 key: key, 7960 iv: cipherCfg.iv, 7961 algorithm: cipher, 7962 mode: cipherCfg.mode, 7963 padding: cipherCfg.padding, 7964 blockSize: cipher.blockSize, 7965 formatter: cfg.format, 7966 }); 7967 }, 7968 7969 /** 7970 * Decrypts serialized ciphertext. 7971 * 7972 * @param {Cipher} cipher The cipher algorithm to use. 7973 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7974 * @param {WordArray} key The key. 7975 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7976 * 7977 * @return {WordArray} The plaintext. 7978 * 7979 * @static 7980 * 7981 * @example 7982 * 7983 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7984 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7985 */ 7986 decrypt: function (cipher, ciphertext, key, cfg) { 7987 // Apply config defaults 7988 cfg = this.cfg.extend(cfg); 7989 7990 // Convert string to CipherParams 7991 ciphertext = this._parse(ciphertext, cfg.format); 7992 7993 // Decrypt 7994 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7995 7996 return plaintext; 7997 }, 7998 7999 /** 8000 * Converts serialized ciphertext to CipherParams, 8001 * else assumed CipherParams already and returns ciphertext unchanged. 8002 * 8003 * @param {CipherParams|string} ciphertext The ciphertext. 8004 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 8005 * 8006 * @return {CipherParams} The unserialized ciphertext. 8007 * 8008 * @static 8009 * 8010 * @example 8011 * 8012 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 8013 */ 8014 _parse: function (ciphertext, format) { 8015 if (typeof ciphertext == 'string') { 8016 return format.parse(ciphertext, this); 8017 } else { 8018 return ciphertext; 8019 } 8020 }, 8021 })); 8022 8023 /** 8024 * Key derivation function namespace. 8025 */ 8026 var C_kdf = (C.kdf = {}); 8027 8028 /** 8029 * OpenSSL key derivation function. 8030 */ 8031 var OpenSSLKdf = (C_kdf.OpenSSL = { 8032 /** 8033 * Derives a key and IV from a password. 8034 * 8035 * @param {string} password The password to derive from. 8036 * @param {number} keySize The size in words of the key to generate. 8037 * @param {number} ivSize The size in words of the IV to generate. 8038 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 8039 * 8040 * @return {CipherParams} A cipher params object with the key, IV, and salt. 8041 * 8042 * @static 8043 * 8044 * @example 8045 * 8046 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 8047 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 8048 */ 8049 execute: function (password, keySize, ivSize, salt) { 8050 // Generate random salt 8051 if (!salt) { 8052 salt = WordArray.random(64 / 8); 8053 } 8054 8055 // Derive key and IV 8056 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 8057 8058 // Separate key and IV 8059 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 8060 key.sigBytes = keySize * 4; 8061 8062 // Return params 8063 return CipherParams.create({ key: key, iv: iv, salt: salt }); 8064 }, 8065 }); 8066 8067 /** 8068 * A serializable cipher wrapper that derives the key from a password, 8069 * and returns ciphertext as a serializable cipher params object. 8070 */ 8071 var PasswordBasedCipher = (C_lib.PasswordBasedCipher = SerializableCipher.extend({ 8072 /** 8073 * Configuration options. 8074 * 8075 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 8076 */ 8077 cfg: SerializableCipher.cfg.extend({ 8078 kdf: OpenSSLKdf, 8079 }), 8080 8081 /** 8082 * Encrypts a message using a password. 8083 * 8084 * @param {Cipher} cipher The cipher algorithm to use. 8085 * @param {WordArray|string} message The message to encrypt. 8086 * @param {string} password The password. 8087 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8088 * 8089 * @return {CipherParams} A cipher params object. 8090 * 8091 * @static 8092 * 8093 * @example 8094 * 8095 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 8096 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 8097 */ 8098 encrypt: function (cipher, message, password, cfg) { 8099 // Apply config defaults 8100 cfg = this.cfg.extend(cfg); 8101 8102 // Derive key and other params 8103 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 8104 8105 // Add IV to config 8106 cfg.iv = derivedParams.iv; 8107 8108 // Encrypt 8109 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 8110 8111 // Mix in derived params 8112 ciphertext.mixIn(derivedParams); 8113 8114 return ciphertext; 8115 }, 8116 8117 /** 8118 * Decrypts serialized ciphertext using a password. 8119 * 8120 * @param {Cipher} cipher The cipher algorithm to use. 8121 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8122 * @param {string} password The password. 8123 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8124 * 8125 * @return {WordArray} The plaintext. 8126 * 8127 * @static 8128 * 8129 * @example 8130 * 8131 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 8132 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 8133 */ 8134 decrypt: function (cipher, ciphertext, password, cfg) { 8135 // Apply config defaults 8136 cfg = this.cfg.extend(cfg); 8137 8138 // Convert string to CipherParams 8139 ciphertext = this._parse(ciphertext, cfg.format); 8140 8141 // Derive key and other params 8142 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 8143 8144 // Add IV to config 8145 cfg.iv = derivedParams.iv; 8146 8147 // Decrypt 8148 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 8149 8150 return plaintext; 8151 }, 8152 })); 8153 })(); 8154 }); 8155 }, 8156 { './core': 53 }, 8157 ], 8158 53: [ 8159 function (require, module, exports) { 8160 (function (root, factory) { 8161 if (typeof exports === 'object') { 8162 // CommonJS 8163 module.exports = exports = factory(); 8164 } else if (typeof define === 'function' && define.amd) { 8165 // AMD 8166 define([], factory); 8167 } else { 8168 // Global (browser) 8169 root.CryptoJS = factory(); 8170 } 8171 })(this, function () { 8172 /** 8173 * CryptoJS core components. 8174 */ 8175 var CryptoJS = 8176 CryptoJS || 8177 (function (Math, undefined) { 8178 /* 8179 * Local polyfil of Object.create 8180 */ 8181 var create = 8182 Object.create || 8183 (function () { 8184 function F() {} 8185 8186 return function (obj) { 8187 var subtype; 8188 8189 F.prototype = obj; 8190 8191 subtype = new F(); 8192 8193 F.prototype = null; 8194 8195 return subtype; 8196 }; 8197 })(); 8198 8199 /** 8200 * CryptoJS namespace. 8201 */ 8202 var C = {}; 8203 8204 /** 8205 * Library namespace. 8206 */ 8207 var C_lib = (C.lib = {}); 8208 8209 /** 8210 * Base object for prototypal inheritance. 8211 */ 8212 var Base = (C_lib.Base = (function () { 8213 return { 8214 /** 8215 * Creates a new object that inherits from this object. 8216 * 8217 * @param {Object} overrides Properties to copy into the new object. 8218 * 8219 * @return {Object} The new object. 8220 * 8221 * @static 8222 * 8223 * @example 8224 * 8225 * var MyType = CryptoJS.lib.Base.extend({ 8226 * field: 'value', 8227 * 8228 * method: function () { 8229 * } 8230 * }); 8231 */ 8232 extend: function (overrides) { 8233 // Spawn 8234 var subtype = create(this); 8235 8236 // Augment 8237 if (overrides) { 8238 subtype.mixIn(overrides); 8239 } 8240 8241 // Create default initializer 8242 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 8243 subtype.init = function () { 8244 subtype.$super.init.apply(this, arguments); 8245 }; 8246 } 8247 8248 // Initializer's prototype is the subtype object 8249 subtype.init.prototype = subtype; 8250 8251 // Reference supertype 8252 subtype.$super = this; 8253 8254 return subtype; 8255 }, 8256 8257 /** 8258 * Extends this object and runs the init method. 8259 * Arguments to create() will be passed to init(). 8260 * 8261 * @return {Object} The new object. 8262 * 8263 * @static 8264 * 8265 * @example 8266 * 8267 * var instance = MyType.create(); 8268 */ 8269 create: function () { 8270 var instance = this.extend(); 8271 instance.init.apply(instance, arguments); 8272 8273 return instance; 8274 }, 8275 8276 /** 8277 * Initializes a newly created object. 8278 * Override this method to add some logic when your objects are created. 8279 * 8280 * @example 8281 * 8282 * var MyType = CryptoJS.lib.Base.extend({ 8283 * init: function () { 8284 * // ... 8285 * } 8286 * }); 8287 */ 8288 init: function () {}, 8289 8290 /** 8291 * Copies properties into this object. 8292 * 8293 * @param {Object} properties The properties to mix in. 8294 * 8295 * @example 8296 * 8297 * MyType.mixIn({ 8298 * field: 'value' 8299 * }); 8300 */ 8301 mixIn: function (properties) { 8302 for (var propertyName in properties) { 8303 if (properties.hasOwnProperty(propertyName)) { 8304 this[propertyName] = properties[propertyName]; 8305 } 8306 } 8307 8308 // IE won't copy toString using the loop above 8309 if (properties.hasOwnProperty('toString')) { 8310 this.toString = properties.toString; 8311 } 8312 }, 8313 8314 /** 8315 * Creates a copy of this object. 8316 * 8317 * @return {Object} The clone. 8318 * 8319 * @example 8320 * 8321 * var clone = instance.clone(); 8322 */ 8323 clone: function () { 8324 return this.init.prototype.extend(this); 8325 }, 8326 }; 8327 })()); 8328 8329 /** 8330 * An array of 32-bit words. 8331 * 8332 * @property {Array} words The array of 32-bit words. 8333 * @property {number} sigBytes The number of significant bytes in this word array. 8334 */ 8335 var WordArray = (C_lib.WordArray = Base.extend({ 8336 /** 8337 * Initializes a newly created word array. 8338 * 8339 * @param {Array} words (Optional) An array of 32-bit words. 8340 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8341 * 8342 * @example 8343 * 8344 * var wordArray = CryptoJS.lib.WordArray.create(); 8345 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8346 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8347 */ 8348 init: function (words, sigBytes) { 8349 words = this.words = words || []; 8350 8351 if (sigBytes != undefined) { 8352 this.sigBytes = sigBytes; 8353 } else { 8354 this.sigBytes = words.length * 4; 8355 } 8356 }, 8357 8358 /** 8359 * Converts this word array to a string. 8360 * 8361 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8362 * 8363 * @return {string} The stringified word array. 8364 * 8365 * @example 8366 * 8367 * var string = wordArray + ''; 8368 * var string = wordArray.toString(); 8369 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8370 */ 8371 toString: function (encoder) { 8372 return (encoder || Hex).stringify(this); 8373 }, 8374 8375 /** 8376 * Concatenates a word array to this word array. 8377 * 8378 * @param {WordArray} wordArray The word array to append. 8379 * 8380 * @return {WordArray} This word array. 8381 * 8382 * @example 8383 * 8384 * wordArray1.concat(wordArray2); 8385 */ 8386 concat: function (wordArray) { 8387 // Shortcuts 8388 var thisWords = this.words; 8389 var thatWords = wordArray.words; 8390 var thisSigBytes = this.sigBytes; 8391 var thatSigBytes = wordArray.sigBytes; 8392 8393 // Clamp excess bits 8394 this.clamp(); 8395 8396 // Concat 8397 if (thisSigBytes % 4) { 8398 // Copy one byte at a time 8399 for (var i = 0; i < thatSigBytes; i++) { 8400 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8401 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8402 } 8403 } else { 8404 // Copy one word at a time 8405 for (var i = 0; i < thatSigBytes; i += 4) { 8406 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8407 } 8408 } 8409 this.sigBytes += thatSigBytes; 8410 8411 // Chainable 8412 return this; 8413 }, 8414 8415 /** 8416 * Removes insignificant bits. 8417 * 8418 * @example 8419 * 8420 * wordArray.clamp(); 8421 */ 8422 clamp: function () { 8423 // Shortcuts 8424 var words = this.words; 8425 var sigBytes = this.sigBytes; 8426 8427 // Clamp 8428 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8429 words.length = Math.ceil(sigBytes / 4); 8430 }, 8431 8432 /** 8433 * Creates a copy of this word array. 8434 * 8435 * @return {WordArray} The clone. 8436 * 8437 * @example 8438 * 8439 * var clone = wordArray.clone(); 8440 */ 8441 clone: function () { 8442 var clone = Base.clone.call(this); 8443 clone.words = this.words.slice(0); 8444 8445 return clone; 8446 }, 8447 8448 /** 8449 * Creates a word array filled with random bytes. 8450 * 8451 * @param {number} nBytes The number of random bytes to generate. 8452 * 8453 * @return {WordArray} The random word array. 8454 * 8455 * @static 8456 * 8457 * @example 8458 * 8459 * var wordArray = CryptoJS.lib.WordArray.random(16); 8460 */ 8461 random: function (nBytes) { 8462 var words = []; 8463 8464 var r = function (m_w) { 8465 var m_w = m_w; 8466 var m_z = 0x3ade68b1; 8467 var mask = 0xffffffff; 8468 8469 return function () { 8470 m_z = (0x9069 * (m_z & 0xffff) + (m_z >> 0x10)) & mask; 8471 m_w = (0x4650 * (m_w & 0xffff) + (m_w >> 0x10)) & mask; 8472 var result = ((m_z << 0x10) + m_w) & mask; 8473 result /= 0x100000000; 8474 result += 0.5; 8475 return result * (Math.random() > 0.5 ? 1 : -1); 8476 }; 8477 }; 8478 8479 for (var i = 0, rcache; i < nBytes; i += 4) { 8480 var _r = r((rcache || Math.random()) * 0x100000000); 8481 8482 rcache = _r() * 0x3ade67b7; 8483 words.push((_r() * 0x100000000) | 0); 8484 } 8485 8486 return new WordArray.init(words, nBytes); 8487 }, 8488 })); 8489 8490 /** 8491 * Encoder namespace. 8492 */ 8493 var C_enc = (C.enc = {}); 8494 8495 /** 8496 * Hex encoding strategy. 8497 */ 8498 var Hex = (C_enc.Hex = { 8499 /** 8500 * Converts a word array to a hex string. 8501 * 8502 * @param {WordArray} wordArray The word array. 8503 * 8504 * @return {string} The hex string. 8505 * 8506 * @static 8507 * 8508 * @example 8509 * 8510 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8511 */ 8512 stringify: function (wordArray) { 8513 // Shortcuts 8514 var words = wordArray.words; 8515 var sigBytes = wordArray.sigBytes; 8516 8517 // Convert 8518 var hexChars = []; 8519 for (var i = 0; i < sigBytes; i++) { 8520 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8521 hexChars.push((bite >>> 4).toString(16)); 8522 hexChars.push((bite & 0x0f).toString(16)); 8523 } 8524 8525 return hexChars.join(''); 8526 }, 8527 8528 /** 8529 * Converts a hex string to a word array. 8530 * 8531 * @param {string} hexStr The hex string. 8532 * 8533 * @return {WordArray} The word array. 8534 * 8535 * @static 8536 * 8537 * @example 8538 * 8539 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8540 */ 8541 parse: function (hexStr) { 8542 // Shortcut 8543 var hexStrLength = hexStr.length; 8544 8545 // Convert 8546 var words = []; 8547 for (var i = 0; i < hexStrLength; i += 2) { 8548 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8549 } 8550 8551 return new WordArray.init(words, hexStrLength / 2); 8552 }, 8553 }); 8554 8555 /** 8556 * Latin1 encoding strategy. 8557 */ 8558 var Latin1 = (C_enc.Latin1 = { 8559 /** 8560 * Converts a word array to a Latin1 string. 8561 * 8562 * @param {WordArray} wordArray The word array. 8563 * 8564 * @return {string} The Latin1 string. 8565 * 8566 * @static 8567 * 8568 * @example 8569 * 8570 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8571 */ 8572 stringify: function (wordArray) { 8573 // Shortcuts 8574 var words = wordArray.words; 8575 var sigBytes = wordArray.sigBytes; 8576 8577 // Convert 8578 var latin1Chars = []; 8579 for (var i = 0; i < sigBytes; i++) { 8580 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8581 latin1Chars.push(String.fromCharCode(bite)); 8582 } 8583 8584 return latin1Chars.join(''); 8585 }, 8586 8587 /** 8588 * Converts a Latin1 string to a word array. 8589 * 8590 * @param {string} latin1Str The Latin1 string. 8591 * 8592 * @return {WordArray} The word array. 8593 * 8594 * @static 8595 * 8596 * @example 8597 * 8598 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8599 */ 8600 parse: function (latin1Str) { 8601 // Shortcut 8602 var latin1StrLength = latin1Str.length; 8603 8604 // Convert 8605 var words = []; 8606 for (var i = 0; i < latin1StrLength; i++) { 8607 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8608 } 8609 8610 return new WordArray.init(words, latin1StrLength); 8611 }, 8612 }); 8613 8614 /** 8615 * UTF-8 encoding strategy. 8616 */ 8617 var Utf8 = (C_enc.Utf8 = { 8618 /** 8619 * Converts a word array to a UTF-8 string. 8620 * 8621 * @param {WordArray} wordArray The word array. 8622 * 8623 * @return {string} The UTF-8 string. 8624 * 8625 * @static 8626 * 8627 * @example 8628 * 8629 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8630 */ 8631 stringify: function (wordArray) { 8632 try { 8633 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8634 } catch (e) { 8635 throw new Error('Malformed UTF-8 data'); 8636 } 8637 }, 8638 8639 /** 8640 * Converts a UTF-8 string to a word array. 8641 * 8642 * @param {string} utf8Str The UTF-8 string. 8643 * 8644 * @return {WordArray} The word array. 8645 * 8646 * @static 8647 * 8648 * @example 8649 * 8650 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8651 */ 8652 parse: function (utf8Str) { 8653 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8654 }, 8655 }); 8656 8657 /** 8658 * Abstract buffered block algorithm template. 8659 * 8660 * The property blockSize must be implemented in a concrete subtype. 8661 * 8662 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8663 */ 8664 var BufferedBlockAlgorithm = (C_lib.BufferedBlockAlgorithm = Base.extend({ 8665 /** 8666 * Resets this block algorithm's data buffer to its initial state. 8667 * 8668 * @example 8669 * 8670 * bufferedBlockAlgorithm.reset(); 8671 */ 8672 reset: function () { 8673 // Initial values 8674 this._data = new WordArray.init(); 8675 this._nDataBytes = 0; 8676 }, 8677 8678 /** 8679 * Adds new data to this block algorithm's buffer. 8680 * 8681 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8682 * 8683 * @example 8684 * 8685 * bufferedBlockAlgorithm._append('data'); 8686 * bufferedBlockAlgorithm._append(wordArray); 8687 */ 8688 _append: function (data) { 8689 // Convert string to WordArray, else assume WordArray already 8690 if (typeof data == 'string') { 8691 data = Utf8.parse(data); 8692 } 8693 8694 // Append 8695 this._data.concat(data); 8696 this._nDataBytes += data.sigBytes; 8697 }, 8698 8699 /** 8700 * Processes available data blocks. 8701 * 8702 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8703 * 8704 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8705 * 8706 * @return {WordArray} The processed data. 8707 * 8708 * @example 8709 * 8710 * var processedData = bufferedBlockAlgorithm._process(); 8711 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8712 */ 8713 _process: function (doFlush) { 8714 // Shortcuts 8715 var data = this._data; 8716 var dataWords = data.words; 8717 var dataSigBytes = data.sigBytes; 8718 var blockSize = this.blockSize; 8719 var blockSizeBytes = blockSize * 4; 8720 8721 // Count blocks ready 8722 var nBlocksReady = dataSigBytes / blockSizeBytes; 8723 if (doFlush) { 8724 // Round up to include partial blocks 8725 nBlocksReady = Math.ceil(nBlocksReady); 8726 } else { 8727 // Round down to include only full blocks, 8728 // less the number of blocks that must remain in the buffer 8729 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8730 } 8731 8732 // Count words ready 8733 var nWordsReady = nBlocksReady * blockSize; 8734 8735 // Count bytes ready 8736 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8737 8738 // Process blocks 8739 if (nWordsReady) { 8740 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8741 // Perform concrete-algorithm logic 8742 this._doProcessBlock(dataWords, offset); 8743 } 8744 8745 // Remove processed words 8746 var processedWords = dataWords.splice(0, nWordsReady); 8747 data.sigBytes -= nBytesReady; 8748 } 8749 8750 // Return processed words 8751 return new WordArray.init(processedWords, nBytesReady); 8752 }, 8753 8754 /** 8755 * Creates a copy of this object. 8756 * 8757 * @return {Object} The clone. 8758 * 8759 * @example 8760 * 8761 * var clone = bufferedBlockAlgorithm.clone(); 8762 */ 8763 clone: function () { 8764 var clone = Base.clone.call(this); 8765 clone._data = this._data.clone(); 8766 8767 return clone; 8768 }, 8769 8770 _minBufferSize: 0, 8771 })); 8772 8773 /** 8774 * Abstract hasher template. 8775 * 8776 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8777 */ 8778 var Hasher = (C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8779 /** 8780 * Configuration options. 8781 */ 8782 cfg: Base.extend(), 8783 8784 /** 8785 * Initializes a newly created hasher. 8786 * 8787 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8788 * 8789 * @example 8790 * 8791 * var hasher = CryptoJS.algo.SHA256.create(); 8792 */ 8793 init: function (cfg) { 8794 // Apply config defaults 8795 this.cfg = this.cfg.extend(cfg); 8796 8797 // Set initial values 8798 this.reset(); 8799 }, 8800 8801 /** 8802 * Resets this hasher to its initial state. 8803 * 8804 * @example 8805 * 8806 * hasher.reset(); 8807 */ 8808 reset: function () { 8809 // Reset data buffer 8810 BufferedBlockAlgorithm.reset.call(this); 8811 8812 // Perform concrete-hasher logic 8813 this._doReset(); 8814 }, 8815 8816 /** 8817 * Updates this hasher with a message. 8818 * 8819 * @param {WordArray|string} messageUpdate The message to append. 8820 * 8821 * @return {Hasher} This hasher. 8822 * 8823 * @example 8824 * 8825 * hasher.update('message'); 8826 * hasher.update(wordArray); 8827 */ 8828 update: function (messageUpdate) { 8829 // Append 8830 this._append(messageUpdate); 8831 8832 // Update the hash 8833 this._process(); 8834 8835 // Chainable 8836 return this; 8837 }, 8838 8839 /** 8840 * Finalizes the hash computation. 8841 * Note that the finalize operation is effectively a destructive, read-once operation. 8842 * 8843 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8844 * 8845 * @return {WordArray} The hash. 8846 * 8847 * @example 8848 * 8849 * var hash = hasher.finalize(); 8850 * var hash = hasher.finalize('message'); 8851 * var hash = hasher.finalize(wordArray); 8852 */ 8853 finalize: function (messageUpdate) { 8854 // Final message update 8855 if (messageUpdate) { 8856 this._append(messageUpdate); 8857 } 8858 8859 // Perform concrete-hasher logic 8860 var hash = this._doFinalize(); 8861 8862 return hash; 8863 }, 8864 8865 blockSize: 512 / 32, 8866 8867 /** 8868 * Creates a shortcut function to a hasher's object interface. 8869 * 8870 * @param {Hasher} hasher The hasher to create a helper for. 8871 * 8872 * @return {Function} The shortcut function. 8873 * 8874 * @static 8875 * 8876 * @example 8877 * 8878 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8879 */ 8880 _createHelper: function (hasher) { 8881 return function (message, cfg) { 8882 return new hasher.init(cfg).finalize(message); 8883 }; 8884 }, 8885 8886 /** 8887 * Creates a shortcut function to the HMAC's object interface. 8888 * 8889 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8890 * 8891 * @return {Function} The shortcut function. 8892 * 8893 * @static 8894 * 8895 * @example 8896 * 8897 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8898 */ 8899 _createHmacHelper: function (hasher) { 8900 return function (message, key) { 8901 return new C_algo.HMAC.init(hasher, key).finalize(message); 8902 }; 8903 }, 8904 })); 8905 8906 /** 8907 * Algorithm namespace. 8908 */ 8909 var C_algo = (C.algo = {}); 8910 8911 return C; 8912 })(Math); 8913 8914 return CryptoJS; 8915 }); 8916 }, 8917 {}, 8918 ], 8919 54: [ 8920 function (require, module, exports) { 8921 (function (root, factory) { 8922 if (typeof exports === 'object') { 8923 // CommonJS 8924 module.exports = exports = factory(require('./core')); 8925 } else if (typeof define === 'function' && define.amd) { 8926 // AMD 8927 define(['./core'], factory); 8928 } else { 8929 // Global (browser) 8930 factory(root.CryptoJS); 8931 } 8932 })(this, function (CryptoJS) { 8933 (function () { 8934 // Shortcuts 8935 var C = CryptoJS; 8936 var C_lib = C.lib; 8937 var WordArray = C_lib.WordArray; 8938 var C_enc = C.enc; 8939 8940 /** 8941 * Base64 encoding strategy. 8942 */ 8943 var Base64 = (C_enc.Base64 = { 8944 /** 8945 * Converts a word array to a Base64 string. 8946 * 8947 * @param {WordArray} wordArray The word array. 8948 * 8949 * @return {string} The Base64 string. 8950 * 8951 * @static 8952 * 8953 * @example 8954 * 8955 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8956 */ 8957 stringify: function (wordArray) { 8958 // Shortcuts 8959 var words = wordArray.words; 8960 var sigBytes = wordArray.sigBytes; 8961 var map = this._map; 8962 8963 // Clamp excess bits 8964 wordArray.clamp(); 8965 8966 // Convert 8967 var base64Chars = []; 8968 for (var i = 0; i < sigBytes; i += 3) { 8969 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8970 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8971 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8972 8973 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8974 8975 for (var j = 0; j < 4 && i + j * 0.75 < sigBytes; j++) { 8976 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8977 } 8978 } 8979 8980 // Add padding 8981 var paddingChar = map.charAt(64); 8982 if (paddingChar) { 8983 while (base64Chars.length % 4) { 8984 base64Chars.push(paddingChar); 8985 } 8986 } 8987 8988 return base64Chars.join(''); 8989 }, 8990 8991 /** 8992 * Converts a Base64 string to a word array. 8993 * 8994 * @param {string} base64Str The Base64 string. 8995 * 8996 * @return {WordArray} The word array. 8997 * 8998 * @static 8999 * 9000 * @example 9001 * 9002 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 9003 */ 9004 parse: function (base64Str) { 9005 // Shortcuts 9006 var base64StrLength = base64Str.length; 9007 var map = this._map; 9008 var reverseMap = this._reverseMap; 9009 9010 if (!reverseMap) { 9011 reverseMap = this._reverseMap = []; 9012 for (var j = 0; j < map.length; j++) { 9013 reverseMap[map.charCodeAt(j)] = j; 9014 } 9015 } 9016 9017 // Ignore padding 9018 var paddingChar = map.charAt(64); 9019 if (paddingChar) { 9020 var paddingIndex = base64Str.indexOf(paddingChar); 9021 if (paddingIndex !== -1) { 9022 base64StrLength = paddingIndex; 9023 } 9024 } 9025 9026 // Convert 9027 return parseLoop(base64Str, base64StrLength, reverseMap); 9028 }, 9029 9030 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', 9031 }); 9032 9033 function parseLoop(base64Str, base64StrLength, reverseMap) { 9034 var words = []; 9035 var nBytes = 0; 9036 for (var i = 0; i < base64StrLength; i++) { 9037 if (i % 4) { 9038 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 9039 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 9040 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 9041 nBytes++; 9042 } 9043 } 9044 return WordArray.create(words, nBytes); 9045 } 9046 })(); 9047 9048 return CryptoJS.enc.Base64; 9049 }); 9050 }, 9051 { './core': 53 }, 9052 ], 9053 55: [ 9054 function (require, module, exports) { 9055 (function (root, factory) { 9056 if (typeof exports === 'object') { 9057 // CommonJS 9058 module.exports = exports = factory(require('./core')); 9059 } else if (typeof define === 'function' && define.amd) { 9060 // AMD 9061 define(['./core'], factory); 9062 } else { 9063 // Global (browser) 9064 factory(root.CryptoJS); 9065 } 9066 })(this, function (CryptoJS) { 9067 (function () { 9068 // Shortcuts 9069 var C = CryptoJS; 9070 var C_lib = C.lib; 9071 var WordArray = C_lib.WordArray; 9072 var C_enc = C.enc; 9073 9074 /** 9075 * UTF-16 BE encoding strategy. 9076 */ 9077 var Utf16BE = 9078 (C_enc.Utf16 = 9079 C_enc.Utf16BE = 9080 { 9081 /** 9082 * Converts a word array to a UTF-16 BE string. 9083 * 9084 * @param {WordArray} wordArray The word array. 9085 * 9086 * @return {string} The UTF-16 BE string. 9087 * 9088 * @static 9089 * 9090 * @example 9091 * 9092 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 9093 */ 9094 stringify: function (wordArray) { 9095 // Shortcuts 9096 var words = wordArray.words; 9097 var sigBytes = wordArray.sigBytes; 9098 9099 // Convert 9100 var utf16Chars = []; 9101 for (var i = 0; i < sigBytes; i += 2) { 9102 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 9103 utf16Chars.push(String.fromCharCode(codePoint)); 9104 } 9105 9106 return utf16Chars.join(''); 9107 }, 9108 9109 /** 9110 * Converts a UTF-16 BE string to a word array. 9111 * 9112 * @param {string} utf16Str The UTF-16 BE string. 9113 * 9114 * @return {WordArray} The word array. 9115 * 9116 * @static 9117 * 9118 * @example 9119 * 9120 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 9121 */ 9122 parse: function (utf16Str) { 9123 // Shortcut 9124 var utf16StrLength = utf16Str.length; 9125 9126 // Convert 9127 var words = []; 9128 for (var i = 0; i < utf16StrLength; i++) { 9129 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 9130 } 9131 9132 return WordArray.create(words, utf16StrLength * 2); 9133 }, 9134 }); 9135 9136 /** 9137 * UTF-16 LE encoding strategy. 9138 */ 9139 C_enc.Utf16LE = { 9140 /** 9141 * Converts a word array to a UTF-16 LE string. 9142 * 9143 * @param {WordArray} wordArray The word array. 9144 * 9145 * @return {string} The UTF-16 LE string. 9146 * 9147 * @static 9148 * 9149 * @example 9150 * 9151 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 9152 */ 9153 stringify: function (wordArray) { 9154 // Shortcuts 9155 var words = wordArray.words; 9156 var sigBytes = wordArray.sigBytes; 9157 9158 // Convert 9159 var utf16Chars = []; 9160 for (var i = 0; i < sigBytes; i += 2) { 9161 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 9162 utf16Chars.push(String.fromCharCode(codePoint)); 9163 } 9164 9165 return utf16Chars.join(''); 9166 }, 9167 9168 /** 9169 * Converts a UTF-16 LE string to a word array. 9170 * 9171 * @param {string} utf16Str The UTF-16 LE string. 9172 * 9173 * @return {WordArray} The word array. 9174 * 9175 * @static 9176 * 9177 * @example 9178 * 9179 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 9180 */ 9181 parse: function (utf16Str) { 9182 // Shortcut 9183 var utf16StrLength = utf16Str.length; 9184 9185 // Convert 9186 var words = []; 9187 for (var i = 0; i < utf16StrLength; i++) { 9188 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 9189 } 9190 9191 return WordArray.create(words, utf16StrLength * 2); 9192 }, 9193 }; 9194 9195 function swapEndian(word) { 9196 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 9197 } 9198 })(); 9199 9200 return CryptoJS.enc.Utf16; 9201 }); 9202 }, 9203 { './core': 53 }, 9204 ], 9205 56: [ 9206 function (require, module, exports) { 9207 (function (root, factory, undef) { 9208 if (typeof exports === 'object') { 9209 // CommonJS 9210 module.exports = exports = factory(require('./core'), require('./sha1'), require('./hmac')); 9211 } else if (typeof define === 'function' && define.amd) { 9212 // AMD 9213 define(['./core', './sha1', './hmac'], factory); 9214 } else { 9215 // Global (browser) 9216 factory(root.CryptoJS); 9217 } 9218 })(this, function (CryptoJS) { 9219 (function () { 9220 // Shortcuts 9221 var C = CryptoJS; 9222 var C_lib = C.lib; 9223 var Base = C_lib.Base; 9224 var WordArray = C_lib.WordArray; 9225 var C_algo = C.algo; 9226 var MD5 = C_algo.MD5; 9227 9228 /** 9229 * This key derivation function is meant to conform with EVP_BytesToKey. 9230 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 9231 */ 9232 var EvpKDF = (C_algo.EvpKDF = Base.extend({ 9233 /** 9234 * Configuration options. 9235 * 9236 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9237 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 9238 * @property {number} iterations The number of iterations to perform. Default: 1 9239 */ 9240 cfg: Base.extend({ 9241 keySize: 128 / 32, 9242 hasher: MD5, 9243 iterations: 1, 9244 }), 9245 9246 /** 9247 * Initializes a newly created key derivation function. 9248 * 9249 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9250 * 9251 * @example 9252 * 9253 * var kdf = CryptoJS.algo.EvpKDF.create(); 9254 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9255 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9256 */ 9257 init: function (cfg) { 9258 this.cfg = this.cfg.extend(cfg); 9259 }, 9260 9261 /** 9262 * Derives a key from a password. 9263 * 9264 * @param {WordArray|string} password The password. 9265 * @param {WordArray|string} salt A salt. 9266 * 9267 * @return {WordArray} The derived key. 9268 * 9269 * @example 9270 * 9271 * var key = kdf.compute(password, salt); 9272 */ 9273 compute: function (password, salt) { 9274 // Shortcut 9275 var cfg = this.cfg; 9276 9277 // Init hasher 9278 var hasher = cfg.hasher.create(); 9279 9280 // Initial values 9281 var derivedKey = WordArray.create(); 9282 9283 // Shortcuts 9284 var derivedKeyWords = derivedKey.words; 9285 var keySize = cfg.keySize; 9286 var iterations = cfg.iterations; 9287 9288 // Generate key 9289 while (derivedKeyWords.length < keySize) { 9290 if (block) { 9291 hasher.update(block); 9292 } 9293 var block = hasher.update(password).finalize(salt); 9294 hasher.reset(); 9295 9296 // Iterations 9297 for (var i = 1; i < iterations; i++) { 9298 block = hasher.finalize(block); 9299 hasher.reset(); 9300 } 9301 9302 derivedKey.concat(block); 9303 } 9304 derivedKey.sigBytes = keySize * 4; 9305 9306 return derivedKey; 9307 }, 9308 })); 9309 9310 /** 9311 * Derives a key from a password. 9312 * 9313 * @param {WordArray|string} password The password. 9314 * @param {WordArray|string} salt A salt. 9315 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9316 * 9317 * @return {WordArray} The derived key. 9318 * 9319 * @static 9320 * 9321 * @example 9322 * 9323 * var key = CryptoJS.EvpKDF(password, salt); 9324 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9325 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9326 */ 9327 C.EvpKDF = function (password, salt, cfg) { 9328 return EvpKDF.create(cfg).compute(password, salt); 9329 }; 9330 })(); 9331 9332 return CryptoJS.EvpKDF; 9333 }); 9334 }, 9335 { './core': 53, './hmac': 58, './sha1': 77 }, 9336 ], 9337 57: [ 9338 function (require, module, exports) { 9339 (function (root, factory, undef) { 9340 if (typeof exports === 'object') { 9341 // CommonJS 9342 module.exports = exports = factory(require('./core'), require('./cipher-core')); 9343 } else if (typeof define === 'function' && define.amd) { 9344 // AMD 9345 define(['./core', './cipher-core'], factory); 9346 } else { 9347 // Global (browser) 9348 factory(root.CryptoJS); 9349 } 9350 })(this, function (CryptoJS) { 9351 (function (undefined) { 9352 // Shortcuts 9353 var C = CryptoJS; 9354 var C_lib = C.lib; 9355 var CipherParams = C_lib.CipherParams; 9356 var C_enc = C.enc; 9357 var Hex = C_enc.Hex; 9358 var C_format = C.format; 9359 9360 var HexFormatter = (C_format.Hex = { 9361 /** 9362 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9363 * 9364 * @param {CipherParams} cipherParams The cipher params object. 9365 * 9366 * @return {string} The hexadecimally encoded string. 9367 * 9368 * @static 9369 * 9370 * @example 9371 * 9372 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9373 */ 9374 stringify: function (cipherParams) { 9375 return cipherParams.ciphertext.toString(Hex); 9376 }, 9377 9378 /** 9379 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9380 * 9381 * @param {string} input The hexadecimally encoded string. 9382 * 9383 * @return {CipherParams} The cipher params object. 9384 * 9385 * @static 9386 * 9387 * @example 9388 * 9389 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9390 */ 9391 parse: function (input) { 9392 var ciphertext = Hex.parse(input); 9393 return CipherParams.create({ ciphertext: ciphertext }); 9394 }, 9395 }); 9396 })(); 9397 9398 return CryptoJS.format.Hex; 9399 }); 9400 }, 9401 { './cipher-core': 52, './core': 53 }, 9402 ], 9403 58: [ 9404 function (require, module, exports) { 9405 (function (root, factory) { 9406 if (typeof exports === 'object') { 9407 // CommonJS 9408 module.exports = exports = factory(require('./core')); 9409 } else if (typeof define === 'function' && define.amd) { 9410 // AMD 9411 define(['./core'], factory); 9412 } else { 9413 // Global (browser) 9414 factory(root.CryptoJS); 9415 } 9416 })(this, function (CryptoJS) { 9417 (function () { 9418 // Shortcuts 9419 var C = CryptoJS; 9420 var C_lib = C.lib; 9421 var Base = C_lib.Base; 9422 var C_enc = C.enc; 9423 var Utf8 = C_enc.Utf8; 9424 var C_algo = C.algo; 9425 9426 /** 9427 * HMAC algorithm. 9428 */ 9429 var HMAC = (C_algo.HMAC = Base.extend({ 9430 /** 9431 * Initializes a newly created HMAC. 9432 * 9433 * @param {Hasher} hasher The hash algorithm to use. 9434 * @param {WordArray|string} key The secret key. 9435 * 9436 * @example 9437 * 9438 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9439 */ 9440 init: function (hasher, key) { 9441 // Init hasher 9442 hasher = this._hasher = new hasher.init(); 9443 9444 // Convert string to WordArray, else assume WordArray already 9445 if (typeof key == 'string') { 9446 key = Utf8.parse(key); 9447 } 9448 9449 // Shortcuts 9450 var hasherBlockSize = hasher.blockSize; 9451 var hasherBlockSizeBytes = hasherBlockSize * 4; 9452 9453 // Allow arbitrary length keys 9454 if (key.sigBytes > hasherBlockSizeBytes) { 9455 key = hasher.finalize(key); 9456 } 9457 9458 // Clamp excess bits 9459 key.clamp(); 9460 9461 // Clone key for inner and outer pads 9462 var oKey = (this._oKey = key.clone()); 9463 var iKey = (this._iKey = key.clone()); 9464 9465 // Shortcuts 9466 var oKeyWords = oKey.words; 9467 var iKeyWords = iKey.words; 9468 9469 // XOR keys with pad constants 9470 for (var i = 0; i < hasherBlockSize; i++) { 9471 oKeyWords[i] ^= 0x5c5c5c5c; 9472 iKeyWords[i] ^= 0x36363636; 9473 } 9474 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9475 9476 // Set initial values 9477 this.reset(); 9478 }, 9479 9480 /** 9481 * Resets this HMAC to its initial state. 9482 * 9483 * @example 9484 * 9485 * hmacHasher.reset(); 9486 */ 9487 reset: function () { 9488 // Shortcut 9489 var hasher = this._hasher; 9490 9491 // Reset 9492 hasher.reset(); 9493 hasher.update(this._iKey); 9494 }, 9495 9496 /** 9497 * Updates this HMAC with a message. 9498 * 9499 * @param {WordArray|string} messageUpdate The message to append. 9500 * 9501 * @return {HMAC} This HMAC instance. 9502 * 9503 * @example 9504 * 9505 * hmacHasher.update('message'); 9506 * hmacHasher.update(wordArray); 9507 */ 9508 update: function (messageUpdate) { 9509 this._hasher.update(messageUpdate); 9510 9511 // Chainable 9512 return this; 9513 }, 9514 9515 /** 9516 * Finalizes the HMAC computation. 9517 * Note that the finalize operation is effectively a destructive, read-once operation. 9518 * 9519 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9520 * 9521 * @return {WordArray} The HMAC. 9522 * 9523 * @example 9524 * 9525 * var hmac = hmacHasher.finalize(); 9526 * var hmac = hmacHasher.finalize('message'); 9527 * var hmac = hmacHasher.finalize(wordArray); 9528 */ 9529 finalize: function (messageUpdate) { 9530 // Shortcut 9531 var hasher = this._hasher; 9532 9533 // Compute HMAC 9534 var innerHash = hasher.finalize(messageUpdate); 9535 hasher.reset(); 9536 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9537 9538 return hmac; 9539 }, 9540 })); 9541 })(); 9542 }); 9543 }, 9544 { './core': 53 }, 9545 ], 9546 59: [ 9547 function (require, module, exports) { 9548 (function (root, factory, undef) { 9549 if (typeof exports === 'object') { 9550 // CommonJS 9551 module.exports = exports = factory( 9552 require('./core'), 9553 require('./x64-core'), 9554 require('./lib-typedarrays'), 9555 require('./enc-utf16'), 9556 require('./enc-base64'), 9557 require('./md5'), 9558 require('./sha1'), 9559 require('./sha256'), 9560 require('./sha224'), 9561 require('./sha512'), 9562 require('./sha384'), 9563 require('./sha3'), 9564 require('./ripemd160'), 9565 require('./hmac'), 9566 require('./pbkdf2'), 9567 require('./evpkdf'), 9568 require('./cipher-core'), 9569 require('./mode-cfb'), 9570 require('./mode-ctr'), 9571 require('./mode-ctr-gladman'), 9572 require('./mode-ofb'), 9573 require('./mode-ecb'), 9574 require('./pad-ansix923'), 9575 require('./pad-iso10126'), 9576 require('./pad-iso97971'), 9577 require('./pad-zeropadding'), 9578 require('./pad-nopadding'), 9579 require('./format-hex'), 9580 require('./aes'), 9581 require('./tripledes'), 9582 require('./rc4'), 9583 require('./rabbit'), 9584 require('./rabbit-legacy') 9585 ); 9586 } else if (typeof define === 'function' && define.amd) { 9587 // AMD 9588 define([ 9589 './core', 9590 './x64-core', 9591 './lib-typedarrays', 9592 './enc-utf16', 9593 './enc-base64', 9594 './md5', 9595 './sha1', 9596 './sha256', 9597 './sha224', 9598 './sha512', 9599 './sha384', 9600 './sha3', 9601 './ripemd160', 9602 './hmac', 9603 './pbkdf2', 9604 './evpkdf', 9605 './cipher-core', 9606 './mode-cfb', 9607 './mode-ctr', 9608 './mode-ctr-gladman', 9609 './mode-ofb', 9610 './mode-ecb', 9611 './pad-ansix923', 9612 './pad-iso10126', 9613 './pad-iso97971', 9614 './pad-zeropadding', 9615 './pad-nopadding', 9616 './format-hex', 9617 './aes', 9618 './tripledes', 9619 './rc4', 9620 './rabbit', 9621 './rabbit-legacy', 9622 ], factory); 9623 } else { 9624 // Global (browser) 9625 root.CryptoJS = factory(root.CryptoJS); 9626 } 9627 })(this, function (CryptoJS) { 9628 return CryptoJS; 9629 }); 9630 }, 9631 { 9632 './aes': 51, 9633 './cipher-core': 52, 9634 './core': 53, 9635 './enc-base64': 54, 9636 './enc-utf16': 55, 9637 './evpkdf': 56, 9638 './format-hex': 57, 9639 './hmac': 58, 9640 './lib-typedarrays': 60, 9641 './md5': 61, 9642 './mode-cfb': 62, 9643 './mode-ctr': 64, 9644 './mode-ctr-gladman': 63, 9645 './mode-ecb': 65, 9646 './mode-ofb': 66, 9647 './pad-ansix923': 67, 9648 './pad-iso10126': 68, 9649 './pad-iso97971': 69, 9650 './pad-nopadding': 70, 9651 './pad-zeropadding': 71, 9652 './pbkdf2': 72, 9653 './rabbit': 74, 9654 './rabbit-legacy': 73, 9655 './rc4': 75, 9656 './ripemd160': 76, 9657 './sha1': 77, 9658 './sha224': 78, 9659 './sha256': 79, 9660 './sha3': 80, 9661 './sha384': 81, 9662 './sha512': 82, 9663 './tripledes': 83, 9664 './x64-core': 84, 9665 }, 9666 ], 9667 60: [ 9668 function (require, module, exports) { 9669 (function (root, factory) { 9670 if (typeof exports === 'object') { 9671 // CommonJS 9672 module.exports = exports = factory(require('./core')); 9673 } else if (typeof define === 'function' && define.amd) { 9674 // AMD 9675 define(['./core'], factory); 9676 } else { 9677 // Global (browser) 9678 factory(root.CryptoJS); 9679 } 9680 })(this, function (CryptoJS) { 9681 (function () { 9682 // Check if typed arrays are supported 9683 if (typeof ArrayBuffer != 'function') { 9684 return; 9685 } 9686 9687 // Shortcuts 9688 var C = CryptoJS; 9689 var C_lib = C.lib; 9690 var WordArray = C_lib.WordArray; 9691 9692 // Reference original init 9693 var superInit = WordArray.init; 9694 9695 // Augment WordArray.init to handle typed arrays 9696 var subInit = (WordArray.init = function (typedArray) { 9697 // Convert buffers to uint8 9698 if (typedArray instanceof ArrayBuffer) { 9699 typedArray = new Uint8Array(typedArray); 9700 } 9701 9702 // Convert other array views to uint8 9703 if ( 9704 typedArray instanceof Int8Array || 9705 (typeof Uint8ClampedArray !== 'undefined' && typedArray instanceof Uint8ClampedArray) || 9706 typedArray instanceof Int16Array || 9707 typedArray instanceof Uint16Array || 9708 typedArray instanceof Int32Array || 9709 typedArray instanceof Uint32Array || 9710 typedArray instanceof Float32Array || 9711 typedArray instanceof Float64Array 9712 ) { 9713 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9714 } 9715 9716 // Handle Uint8Array 9717 if (typedArray instanceof Uint8Array) { 9718 // Shortcut 9719 var typedArrayByteLength = typedArray.byteLength; 9720 9721 // Extract bytes 9722 var words = []; 9723 for (var i = 0; i < typedArrayByteLength; i++) { 9724 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9725 } 9726 9727 // Initialize this word array 9728 superInit.call(this, words, typedArrayByteLength); 9729 } else { 9730 // Else call normal init 9731 superInit.apply(this, arguments); 9732 } 9733 }); 9734 9735 subInit.prototype = WordArray; 9736 })(); 9737 9738 return CryptoJS.lib.WordArray; 9739 }); 9740 }, 9741 { './core': 53 }, 9742 ], 9743 61: [ 9744 function (require, module, exports) { 9745 (function (root, factory) { 9746 if (typeof exports === 'object') { 9747 // CommonJS 9748 module.exports = exports = factory(require('./core')); 9749 } else if (typeof define === 'function' && define.amd) { 9750 // AMD 9751 define(['./core'], factory); 9752 } else { 9753 // Global (browser) 9754 factory(root.CryptoJS); 9755 } 9756 })(this, function (CryptoJS) { 9757 (function (Math) { 9758 // Shortcuts 9759 var C = CryptoJS; 9760 var C_lib = C.lib; 9761 var WordArray = C_lib.WordArray; 9762 var Hasher = C_lib.Hasher; 9763 var C_algo = C.algo; 9764 9765 // Constants table 9766 var T = []; 9767 9768 // Compute constants 9769 (function () { 9770 for (var i = 0; i < 64; i++) { 9771 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9772 } 9773 })(); 9774 9775 /** 9776 * MD5 hash algorithm. 9777 */ 9778 var MD5 = (C_algo.MD5 = Hasher.extend({ 9779 _doReset: function () { 9780 this._hash = new WordArray.init([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]); 9781 }, 9782 9783 _doProcessBlock: function (M, offset) { 9784 // Swap endian 9785 for (var i = 0; i < 16; i++) { 9786 // Shortcuts 9787 var offset_i = offset + i; 9788 var M_offset_i = M[offset_i]; 9789 9790 M[offset_i] = 9791 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9792 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00); 9793 } 9794 9795 // Shortcuts 9796 var H = this._hash.words; 9797 9798 var M_offset_0 = M[offset + 0]; 9799 var M_offset_1 = M[offset + 1]; 9800 var M_offset_2 = M[offset + 2]; 9801 var M_offset_3 = M[offset + 3]; 9802 var M_offset_4 = M[offset + 4]; 9803 var M_offset_5 = M[offset + 5]; 9804 var M_offset_6 = M[offset + 6]; 9805 var M_offset_7 = M[offset + 7]; 9806 var M_offset_8 = M[offset + 8]; 9807 var M_offset_9 = M[offset + 9]; 9808 var M_offset_10 = M[offset + 10]; 9809 var M_offset_11 = M[offset + 11]; 9810 var M_offset_12 = M[offset + 12]; 9811 var M_offset_13 = M[offset + 13]; 9812 var M_offset_14 = M[offset + 14]; 9813 var M_offset_15 = M[offset + 15]; 9814 9815 // Working varialbes 9816 var a = H[0]; 9817 var b = H[1]; 9818 var c = H[2]; 9819 var d = H[3]; 9820 9821 // Computation 9822 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9823 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9824 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9825 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9826 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9827 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9828 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9829 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9830 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9831 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9832 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9833 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9834 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9835 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9836 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9837 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9838 9839 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9840 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9841 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9842 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9843 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9844 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9845 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9846 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9847 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9848 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9849 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9850 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9851 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9852 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9853 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9854 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9855 9856 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9857 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9858 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9859 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9860 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9861 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9862 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9863 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9864 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9865 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9866 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9867 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9868 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9869 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9870 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9871 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9872 9873 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9874 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9875 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9876 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9877 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9878 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9879 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9880 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9881 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9882 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9883 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9884 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9885 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9886 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9887 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9888 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9889 9890 // Intermediate hash value 9891 H[0] = (H[0] + a) | 0; 9892 H[1] = (H[1] + b) | 0; 9893 H[2] = (H[2] + c) | 0; 9894 H[3] = (H[3] + d) | 0; 9895 }, 9896 9897 _doFinalize: function () { 9898 // Shortcuts 9899 var data = this._data; 9900 var dataWords = data.words; 9901 9902 var nBitsTotal = this._nDataBytes * 8; 9903 var nBitsLeft = data.sigBytes * 8; 9904 9905 // Add padding 9906 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 9907 9908 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9909 var nBitsTotalL = nBitsTotal; 9910 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = 9911 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9912 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00); 9913 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = 9914 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9915 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00); 9916 9917 data.sigBytes = (dataWords.length + 1) * 4; 9918 9919 // Hash final blocks 9920 this._process(); 9921 9922 // Shortcuts 9923 var hash = this._hash; 9924 var H = hash.words; 9925 9926 // Swap endian 9927 for (var i = 0; i < 4; i++) { 9928 // Shortcut 9929 var H_i = H[i]; 9930 9931 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9932 } 9933 9934 // Return final computed hash 9935 return hash; 9936 }, 9937 9938 clone: function () { 9939 var clone = Hasher.clone.call(this); 9940 clone._hash = this._hash.clone(); 9941 9942 return clone; 9943 }, 9944 })); 9945 9946 function FF(a, b, c, d, x, s, t) { 9947 var n = a + ((b & c) | (~b & d)) + x + t; 9948 return ((n << s) | (n >>> (32 - s))) + b; 9949 } 9950 9951 function GG(a, b, c, d, x, s, t) { 9952 var n = a + ((b & d) | (c & ~d)) + x + t; 9953 return ((n << s) | (n >>> (32 - s))) + b; 9954 } 9955 9956 function HH(a, b, c, d, x, s, t) { 9957 var n = a + (b ^ c ^ d) + x + t; 9958 return ((n << s) | (n >>> (32 - s))) + b; 9959 } 9960 9961 function II(a, b, c, d, x, s, t) { 9962 var n = a + (c ^ (b | ~d)) + x + t; 9963 return ((n << s) | (n >>> (32 - s))) + b; 9964 } 9965 9966 /** 9967 * Shortcut function to the hasher's object interface. 9968 * 9969 * @param {WordArray|string} message The message to hash. 9970 * 9971 * @return {WordArray} The hash. 9972 * 9973 * @static 9974 * 9975 * @example 9976 * 9977 * var hash = CryptoJS.MD5('message'); 9978 * var hash = CryptoJS.MD5(wordArray); 9979 */ 9980 C.MD5 = Hasher._createHelper(MD5); 9981 9982 /** 9983 * Shortcut function to the HMAC's object interface. 9984 * 9985 * @param {WordArray|string} message The message to hash. 9986 * @param {WordArray|string} key The secret key. 9987 * 9988 * @return {WordArray} The HMAC. 9989 * 9990 * @static 9991 * 9992 * @example 9993 * 9994 * var hmac = CryptoJS.HmacMD5(message, key); 9995 */ 9996 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9997 })(Math); 9998 9999 return CryptoJS.MD5; 10000 }); 10001 }, 10002 { './core': 53 }, 10003 ], 10004 62: [ 10005 function (require, module, exports) { 10006 (function (root, factory, undef) { 10007 if (typeof exports === 'object') { 10008 // CommonJS 10009 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10010 } else if (typeof define === 'function' && define.amd) { 10011 // AMD 10012 define(['./core', './cipher-core'], factory); 10013 } else { 10014 // Global (browser) 10015 factory(root.CryptoJS); 10016 } 10017 })(this, function (CryptoJS) { 10018 /** 10019 * Cipher Feedback block mode. 10020 */ 10021 CryptoJS.mode.CFB = (function () { 10022 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 10023 10024 CFB.Encryptor = CFB.extend({ 10025 processBlock: function (words, offset) { 10026 // Shortcuts 10027 var cipher = this._cipher; 10028 var blockSize = cipher.blockSize; 10029 10030 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 10031 10032 // Remember this block to use with next block 10033 this._prevBlock = words.slice(offset, offset + blockSize); 10034 }, 10035 }); 10036 10037 CFB.Decryptor = CFB.extend({ 10038 processBlock: function (words, offset) { 10039 // Shortcuts 10040 var cipher = this._cipher; 10041 var blockSize = cipher.blockSize; 10042 10043 // Remember this block to use with next block 10044 var thisBlock = words.slice(offset, offset + blockSize); 10045 10046 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 10047 10048 // This block becomes the previous block 10049 this._prevBlock = thisBlock; 10050 }, 10051 }); 10052 10053 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 10054 // Shortcut 10055 var iv = this._iv; 10056 10057 // Generate keystream 10058 if (iv) { 10059 var keystream = iv.slice(0); 10060 10061 // Remove IV for subsequent blocks 10062 this._iv = undefined; 10063 } else { 10064 var keystream = this._prevBlock; 10065 } 10066 cipher.encryptBlock(keystream, 0); 10067 10068 // Encrypt 10069 for (var i = 0; i < blockSize; i++) { 10070 words[offset + i] ^= keystream[i]; 10071 } 10072 } 10073 10074 return CFB; 10075 })(); 10076 10077 return CryptoJS.mode.CFB; 10078 }); 10079 }, 10080 { './cipher-core': 52, './core': 53 }, 10081 ], 10082 63: [ 10083 function (require, module, exports) { 10084 (function (root, factory, undef) { 10085 if (typeof exports === 'object') { 10086 // CommonJS 10087 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10088 } else if (typeof define === 'function' && define.amd) { 10089 // AMD 10090 define(['./core', './cipher-core'], factory); 10091 } else { 10092 // Global (browser) 10093 factory(root.CryptoJS); 10094 } 10095 })(this, function (CryptoJS) { 10096 /** @preserve 10097 * Counter block mode compatible with Dr Brian Gladman fileenc.c 10098 * derived from CryptoJS.mode.CTR 10099 * Jan Hruby jhruby.web@gmail.com 10100 */ 10101 CryptoJS.mode.CTRGladman = (function () { 10102 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 10103 10104 function incWord(word) { 10105 if (((word >> 24) & 0xff) === 0xff) { 10106 //overflow 10107 var b1 = (word >> 16) & 0xff; 10108 var b2 = (word >> 8) & 0xff; 10109 var b3 = word & 0xff; 10110 10111 if (b1 === 0xff) { 10112 // overflow b1 10113 b1 = 0; 10114 if (b2 === 0xff) { 10115 b2 = 0; 10116 if (b3 === 0xff) { 10117 b3 = 0; 10118 } else { 10119 ++b3; 10120 } 10121 } else { 10122 ++b2; 10123 } 10124 } else { 10125 ++b1; 10126 } 10127 10128 word = 0; 10129 word += b1 << 16; 10130 word += b2 << 8; 10131 word += b3; 10132 } else { 10133 word += 0x01 << 24; 10134 } 10135 return word; 10136 } 10137 10138 function incCounter(counter) { 10139 if ((counter[0] = incWord(counter[0])) === 0) { 10140 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 10141 counter[1] = incWord(counter[1]); 10142 } 10143 return counter; 10144 } 10145 10146 var Encryptor = (CTRGladman.Encryptor = CTRGladman.extend({ 10147 processBlock: function (words, offset) { 10148 // Shortcuts 10149 var cipher = this._cipher; 10150 var blockSize = cipher.blockSize; 10151 var iv = this._iv; 10152 var counter = this._counter; 10153 10154 // Generate keystream 10155 if (iv) { 10156 counter = this._counter = iv.slice(0); 10157 10158 // Remove IV for subsequent blocks 10159 this._iv = undefined; 10160 } 10161 10162 incCounter(counter); 10163 10164 var keystream = counter.slice(0); 10165 cipher.encryptBlock(keystream, 0); 10166 10167 // Encrypt 10168 for (var i = 0; i < blockSize; i++) { 10169 words[offset + i] ^= keystream[i]; 10170 } 10171 }, 10172 })); 10173 10174 CTRGladman.Decryptor = Encryptor; 10175 10176 return CTRGladman; 10177 })(); 10178 10179 return CryptoJS.mode.CTRGladman; 10180 }); 10181 }, 10182 { './cipher-core': 52, './core': 53 }, 10183 ], 10184 64: [ 10185 function (require, module, exports) { 10186 (function (root, factory, undef) { 10187 if (typeof exports === 'object') { 10188 // CommonJS 10189 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10190 } else if (typeof define === 'function' && define.amd) { 10191 // AMD 10192 define(['./core', './cipher-core'], factory); 10193 } else { 10194 // Global (browser) 10195 factory(root.CryptoJS); 10196 } 10197 })(this, function (CryptoJS) { 10198 /** 10199 * Counter block mode. 10200 */ 10201 CryptoJS.mode.CTR = (function () { 10202 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 10203 10204 var Encryptor = (CTR.Encryptor = CTR.extend({ 10205 processBlock: function (words, offset) { 10206 // Shortcuts 10207 var cipher = this._cipher; 10208 var blockSize = cipher.blockSize; 10209 var iv = this._iv; 10210 var counter = this._counter; 10211 10212 // Generate keystream 10213 if (iv) { 10214 counter = this._counter = iv.slice(0); 10215 10216 // Remove IV for subsequent blocks 10217 this._iv = undefined; 10218 } 10219 var keystream = counter.slice(0); 10220 cipher.encryptBlock(keystream, 0); 10221 10222 // Increment counter 10223 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0; 10224 10225 // Encrypt 10226 for (var i = 0; i < blockSize; i++) { 10227 words[offset + i] ^= keystream[i]; 10228 } 10229 }, 10230 })); 10231 10232 CTR.Decryptor = Encryptor; 10233 10234 return CTR; 10235 })(); 10236 10237 return CryptoJS.mode.CTR; 10238 }); 10239 }, 10240 { './cipher-core': 52, './core': 53 }, 10241 ], 10242 65: [ 10243 function (require, module, exports) { 10244 (function (root, factory, undef) { 10245 if (typeof exports === 'object') { 10246 // CommonJS 10247 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10248 } else if (typeof define === 'function' && define.amd) { 10249 // AMD 10250 define(['./core', './cipher-core'], factory); 10251 } else { 10252 // Global (browser) 10253 factory(root.CryptoJS); 10254 } 10255 })(this, function (CryptoJS) { 10256 /** 10257 * Electronic Codebook block mode. 10258 */ 10259 CryptoJS.mode.ECB = (function () { 10260 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 10261 10262 ECB.Encryptor = ECB.extend({ 10263 processBlock: function (words, offset) { 10264 this._cipher.encryptBlock(words, offset); 10265 }, 10266 }); 10267 10268 ECB.Decryptor = ECB.extend({ 10269 processBlock: function (words, offset) { 10270 this._cipher.decryptBlock(words, offset); 10271 }, 10272 }); 10273 10274 return ECB; 10275 })(); 10276 10277 return CryptoJS.mode.ECB; 10278 }); 10279 }, 10280 { './cipher-core': 52, './core': 53 }, 10281 ], 10282 66: [ 10283 function (require, module, exports) { 10284 (function (root, factory, undef) { 10285 if (typeof exports === 'object') { 10286 // CommonJS 10287 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10288 } else if (typeof define === 'function' && define.amd) { 10289 // AMD 10290 define(['./core', './cipher-core'], factory); 10291 } else { 10292 // Global (browser) 10293 factory(root.CryptoJS); 10294 } 10295 })(this, function (CryptoJS) { 10296 /** 10297 * Output Feedback block mode. 10298 */ 10299 CryptoJS.mode.OFB = (function () { 10300 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 10301 10302 var Encryptor = (OFB.Encryptor = OFB.extend({ 10303 processBlock: function (words, offset) { 10304 // Shortcuts 10305 var cipher = this._cipher; 10306 var blockSize = cipher.blockSize; 10307 var iv = this._iv; 10308 var keystream = this._keystream; 10309 10310 // Generate keystream 10311 if (iv) { 10312 keystream = this._keystream = iv.slice(0); 10313 10314 // Remove IV for subsequent blocks 10315 this._iv = undefined; 10316 } 10317 cipher.encryptBlock(keystream, 0); 10318 10319 // Encrypt 10320 for (var i = 0; i < blockSize; i++) { 10321 words[offset + i] ^= keystream[i]; 10322 } 10323 }, 10324 })); 10325 10326 OFB.Decryptor = Encryptor; 10327 10328 return OFB; 10329 })(); 10330 10331 return CryptoJS.mode.OFB; 10332 }); 10333 }, 10334 { './cipher-core': 52, './core': 53 }, 10335 ], 10336 67: [ 10337 function (require, module, exports) { 10338 (function (root, factory, undef) { 10339 if (typeof exports === 'object') { 10340 // CommonJS 10341 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10342 } else if (typeof define === 'function' && define.amd) { 10343 // AMD 10344 define(['./core', './cipher-core'], factory); 10345 } else { 10346 // Global (browser) 10347 factory(root.CryptoJS); 10348 } 10349 })(this, function (CryptoJS) { 10350 /** 10351 * ANSI X.923 padding strategy. 10352 */ 10353 CryptoJS.pad.AnsiX923 = { 10354 pad: function (data, blockSize) { 10355 // Shortcuts 10356 var dataSigBytes = data.sigBytes; 10357 var blockSizeBytes = blockSize * 4; 10358 10359 // Count padding bytes 10360 var nPaddingBytes = blockSizeBytes - (dataSigBytes % blockSizeBytes); 10361 10362 // Compute last byte position 10363 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10364 10365 // Pad 10366 data.clamp(); 10367 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10368 data.sigBytes += nPaddingBytes; 10369 }, 10370 10371 unpad: function (data) { 10372 // Get number of padding bytes from last byte 10373 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10374 10375 // Remove padding 10376 data.sigBytes -= nPaddingBytes; 10377 }, 10378 }; 10379 10380 return CryptoJS.pad.Ansix923; 10381 }); 10382 }, 10383 { './cipher-core': 52, './core': 53 }, 10384 ], 10385 68: [ 10386 function (require, module, exports) { 10387 (function (root, factory, undef) { 10388 if (typeof exports === 'object') { 10389 // CommonJS 10390 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10391 } else if (typeof define === 'function' && define.amd) { 10392 // AMD 10393 define(['./core', './cipher-core'], factory); 10394 } else { 10395 // Global (browser) 10396 factory(root.CryptoJS); 10397 } 10398 })(this, function (CryptoJS) { 10399 /** 10400 * ISO 10126 padding strategy. 10401 */ 10402 CryptoJS.pad.Iso10126 = { 10403 pad: function (data, blockSize) { 10404 // Shortcut 10405 var blockSizeBytes = blockSize * 4; 10406 10407 // Count padding bytes 10408 var nPaddingBytes = blockSizeBytes - (data.sigBytes % blockSizeBytes); 10409 10410 // Pad 10411 data 10412 .concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)) 10413 .concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10414 }, 10415 10416 unpad: function (data) { 10417 // Get number of padding bytes from last byte 10418 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10419 10420 // Remove padding 10421 data.sigBytes -= nPaddingBytes; 10422 }, 10423 }; 10424 10425 return CryptoJS.pad.Iso10126; 10426 }); 10427 }, 10428 { './cipher-core': 52, './core': 53 }, 10429 ], 10430 69: [ 10431 function (require, module, exports) { 10432 (function (root, factory, undef) { 10433 if (typeof exports === 'object') { 10434 // CommonJS 10435 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10436 } else if (typeof define === 'function' && define.amd) { 10437 // AMD 10438 define(['./core', './cipher-core'], factory); 10439 } else { 10440 // Global (browser) 10441 factory(root.CryptoJS); 10442 } 10443 })(this, function (CryptoJS) { 10444 /** 10445 * ISO/IEC 9797-1 Padding Method 2. 10446 */ 10447 CryptoJS.pad.Iso97971 = { 10448 pad: function (data, blockSize) { 10449 // Add 0x80 byte 10450 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10451 10452 // Zero pad the rest 10453 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10454 }, 10455 10456 unpad: function (data) { 10457 // Remove zero padding 10458 CryptoJS.pad.ZeroPadding.unpad(data); 10459 10460 // Remove one more byte -- the 0x80 byte 10461 data.sigBytes--; 10462 }, 10463 }; 10464 10465 return CryptoJS.pad.Iso97971; 10466 }); 10467 }, 10468 { './cipher-core': 52, './core': 53 }, 10469 ], 10470 70: [ 10471 function (require, module, exports) { 10472 (function (root, factory, undef) { 10473 if (typeof exports === 'object') { 10474 // CommonJS 10475 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10476 } else if (typeof define === 'function' && define.amd) { 10477 // AMD 10478 define(['./core', './cipher-core'], factory); 10479 } else { 10480 // Global (browser) 10481 factory(root.CryptoJS); 10482 } 10483 })(this, function (CryptoJS) { 10484 /** 10485 * A noop padding strategy. 10486 */ 10487 CryptoJS.pad.NoPadding = { 10488 pad: function () {}, 10489 10490 unpad: function () {}, 10491 }; 10492 10493 return CryptoJS.pad.NoPadding; 10494 }); 10495 }, 10496 { './cipher-core': 52, './core': 53 }, 10497 ], 10498 71: [ 10499 function (require, module, exports) { 10500 (function (root, factory, undef) { 10501 if (typeof exports === 'object') { 10502 // CommonJS 10503 module.exports = exports = factory(require('./core'), require('./cipher-core')); 10504 } else if (typeof define === 'function' && define.amd) { 10505 // AMD 10506 define(['./core', './cipher-core'], factory); 10507 } else { 10508 // Global (browser) 10509 factory(root.CryptoJS); 10510 } 10511 })(this, function (CryptoJS) { 10512 /** 10513 * Zero padding strategy. 10514 */ 10515 CryptoJS.pad.ZeroPadding = { 10516 pad: function (data, blockSize) { 10517 // Shortcut 10518 var blockSizeBytes = blockSize * 4; 10519 10520 // Pad 10521 data.clamp(); 10522 data.sigBytes += blockSizeBytes - (data.sigBytes % blockSizeBytes || blockSizeBytes); 10523 }, 10524 10525 unpad: function (data) { 10526 // Shortcut 10527 var dataWords = data.words; 10528 10529 // Unpad 10530 var i = data.sigBytes - 1; 10531 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10532 i--; 10533 } 10534 data.sigBytes = i + 1; 10535 }, 10536 }; 10537 10538 return CryptoJS.pad.ZeroPadding; 10539 }); 10540 }, 10541 { './cipher-core': 52, './core': 53 }, 10542 ], 10543 72: [ 10544 function (require, module, exports) { 10545 (function (root, factory, undef) { 10546 if (typeof exports === 'object') { 10547 // CommonJS 10548 module.exports = exports = factory(require('./core'), require('./sha1'), require('./hmac')); 10549 } else if (typeof define === 'function' && define.amd) { 10550 // AMD 10551 define(['./core', './sha1', './hmac'], factory); 10552 } else { 10553 // Global (browser) 10554 factory(root.CryptoJS); 10555 } 10556 })(this, function (CryptoJS) { 10557 (function () { 10558 // Shortcuts 10559 var C = CryptoJS; 10560 var C_lib = C.lib; 10561 var Base = C_lib.Base; 10562 var WordArray = C_lib.WordArray; 10563 var C_algo = C.algo; 10564 var SHA1 = C_algo.SHA1; 10565 var HMAC = C_algo.HMAC; 10566 10567 /** 10568 * Password-Based Key Derivation Function 2 algorithm. 10569 */ 10570 var PBKDF2 = (C_algo.PBKDF2 = Base.extend({ 10571 /** 10572 * Configuration options. 10573 * 10574 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10575 * @property {Hasher} hasher The hasher to use. Default: SHA1 10576 * @property {number} iterations The number of iterations to perform. Default: 1 10577 */ 10578 cfg: Base.extend({ 10579 keySize: 128 / 32, 10580 hasher: SHA1, 10581 iterations: 1, 10582 }), 10583 10584 /** 10585 * Initializes a newly created key derivation function. 10586 * 10587 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10588 * 10589 * @example 10590 * 10591 * var kdf = CryptoJS.algo.PBKDF2.create(); 10592 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10593 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10594 */ 10595 init: function (cfg) { 10596 this.cfg = this.cfg.extend(cfg); 10597 }, 10598 10599 /** 10600 * Computes the Password-Based Key Derivation Function 2. 10601 * 10602 * @param {WordArray|string} password The password. 10603 * @param {WordArray|string} salt A salt. 10604 * 10605 * @return {WordArray} The derived key. 10606 * 10607 * @example 10608 * 10609 * var key = kdf.compute(password, salt); 10610 */ 10611 compute: function (password, salt) { 10612 // Shortcut 10613 var cfg = this.cfg; 10614 10615 // Init HMAC 10616 var hmac = HMAC.create(cfg.hasher, password); 10617 10618 // Initial values 10619 var derivedKey = WordArray.create(); 10620 var blockIndex = WordArray.create([0x00000001]); 10621 10622 // Shortcuts 10623 var derivedKeyWords = derivedKey.words; 10624 var blockIndexWords = blockIndex.words; 10625 var keySize = cfg.keySize; 10626 var iterations = cfg.iterations; 10627 10628 // Generate key 10629 while (derivedKeyWords.length < keySize) { 10630 var block = hmac.update(salt).finalize(blockIndex); 10631 hmac.reset(); 10632 10633 // Shortcuts 10634 var blockWords = block.words; 10635 var blockWordsLength = blockWords.length; 10636 10637 // Iterations 10638 var intermediate = block; 10639 for (var i = 1; i < iterations; i++) { 10640 intermediate = hmac.finalize(intermediate); 10641 hmac.reset(); 10642 10643 // Shortcut 10644 var intermediateWords = intermediate.words; 10645 10646 // XOR intermediate with block 10647 for (var j = 0; j < blockWordsLength; j++) { 10648 blockWords[j] ^= intermediateWords[j]; 10649 } 10650 } 10651 10652 derivedKey.concat(block); 10653 blockIndexWords[0]++; 10654 } 10655 derivedKey.sigBytes = keySize * 4; 10656 10657 return derivedKey; 10658 }, 10659 })); 10660 10661 /** 10662 * Computes the Password-Based Key Derivation Function 2. 10663 * 10664 * @param {WordArray|string} password The password. 10665 * @param {WordArray|string} salt A salt. 10666 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10667 * 10668 * @return {WordArray} The derived key. 10669 * 10670 * @static 10671 * 10672 * @example 10673 * 10674 * var key = CryptoJS.PBKDF2(password, salt); 10675 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10676 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10677 */ 10678 C.PBKDF2 = function (password, salt, cfg) { 10679 return PBKDF2.create(cfg).compute(password, salt); 10680 }; 10681 })(); 10682 10683 return CryptoJS.PBKDF2; 10684 }); 10685 }, 10686 { './core': 53, './hmac': 58, './sha1': 77 }, 10687 ], 10688 73: [ 10689 function (require, module, exports) { 10690 (function (root, factory, undef) { 10691 if (typeof exports === 'object') { 10692 // CommonJS 10693 module.exports = exports = factory( 10694 require('./core'), 10695 require('./enc-base64'), 10696 require('./md5'), 10697 require('./evpkdf'), 10698 require('./cipher-core') 10699 ); 10700 } else if (typeof define === 'function' && define.amd) { 10701 // AMD 10702 define(['./core', './enc-base64', './md5', './evpkdf', './cipher-core'], factory); 10703 } else { 10704 // Global (browser) 10705 factory(root.CryptoJS); 10706 } 10707 })(this, function (CryptoJS) { 10708 (function () { 10709 // Shortcuts 10710 var C = CryptoJS; 10711 var C_lib = C.lib; 10712 var StreamCipher = C_lib.StreamCipher; 10713 var C_algo = C.algo; 10714 10715 // Reusable objects 10716 var S = []; 10717 var C_ = []; 10718 var G = []; 10719 10720 /** 10721 * Rabbit stream cipher algorithm. 10722 * 10723 * This is a legacy version that neglected to convert the key to little-endian. 10724 * This error doesn't affect the cipher's security, 10725 * but it does affect its compatibility with other implementations. 10726 */ 10727 var RabbitLegacy = (C_algo.RabbitLegacy = StreamCipher.extend({ 10728 _doReset: function () { 10729 // Shortcuts 10730 var K = this._key.words; 10731 var iv = this.cfg.iv; 10732 10733 // Generate initial state values 10734 var X = (this._X = [ 10735 K[0], 10736 (K[3] << 16) | (K[2] >>> 16), 10737 K[1], 10738 (K[0] << 16) | (K[3] >>> 16), 10739 K[2], 10740 (K[1] << 16) | (K[0] >>> 16), 10741 K[3], 10742 (K[2] << 16) | (K[1] >>> 16), 10743 ]); 10744 10745 // Generate initial counter values 10746 var C = (this._C = [ 10747 (K[2] << 16) | (K[2] >>> 16), 10748 (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10749 (K[3] << 16) | (K[3] >>> 16), 10750 (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10751 (K[0] << 16) | (K[0] >>> 16), 10752 (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10753 (K[1] << 16) | (K[1] >>> 16), 10754 (K[3] & 0xffff0000) | (K[0] & 0x0000ffff), 10755 ]); 10756 10757 // Carry bit 10758 this._b = 0; 10759 10760 // Iterate the system four times 10761 for (var i = 0; i < 4; i++) { 10762 nextState.call(this); 10763 } 10764 10765 // Modify the counters 10766 for (var i = 0; i < 8; i++) { 10767 C[i] ^= X[(i + 4) & 7]; 10768 } 10769 10770 // IV setup 10771 if (iv) { 10772 // Shortcuts 10773 var IV = iv.words; 10774 var IV_0 = IV[0]; 10775 var IV_1 = IV[1]; 10776 10777 // Generate four subvectors 10778 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10779 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10780 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10781 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10782 10783 // Modify counter values 10784 C[0] ^= i0; 10785 C[1] ^= i1; 10786 C[2] ^= i2; 10787 C[3] ^= i3; 10788 C[4] ^= i0; 10789 C[5] ^= i1; 10790 C[6] ^= i2; 10791 C[7] ^= i3; 10792 10793 // Iterate the system four times 10794 for (var i = 0; i < 4; i++) { 10795 nextState.call(this); 10796 } 10797 } 10798 }, 10799 10800 _doProcessBlock: function (M, offset) { 10801 // Shortcut 10802 var X = this._X; 10803 10804 // Iterate the system 10805 nextState.call(this); 10806 10807 // Generate four keystream words 10808 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10809 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10810 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10811 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10812 10813 for (var i = 0; i < 4; i++) { 10814 // Swap endian 10815 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10816 10817 // Encrypt 10818 M[offset + i] ^= S[i]; 10819 } 10820 }, 10821 10822 blockSize: 128 / 32, 10823 10824 ivSize: 64 / 32, 10825 })); 10826 10827 function nextState() { 10828 // Shortcuts 10829 var X = this._X; 10830 var C = this._C; 10831 10832 // Save old counter values 10833 for (var i = 0; i < 8; i++) { 10834 C_[i] = C[i]; 10835 } 10836 10837 // Calculate new counter values 10838 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10839 C[1] = (C[1] + 0xd34d34d3 + (C[0] >>> 0 < C_[0] >>> 0 ? 1 : 0)) | 0; 10840 C[2] = (C[2] + 0x34d34d34 + (C[1] >>> 0 < C_[1] >>> 0 ? 1 : 0)) | 0; 10841 C[3] = (C[3] + 0x4d34d34d + (C[2] >>> 0 < C_[2] >>> 0 ? 1 : 0)) | 0; 10842 C[4] = (C[4] + 0xd34d34d3 + (C[3] >>> 0 < C_[3] >>> 0 ? 1 : 0)) | 0; 10843 C[5] = (C[5] + 0x34d34d34 + (C[4] >>> 0 < C_[4] >>> 0 ? 1 : 0)) | 0; 10844 C[6] = (C[6] + 0x4d34d34d + (C[5] >>> 0 < C_[5] >>> 0 ? 1 : 0)) | 0; 10845 C[7] = (C[7] + 0xd34d34d3 + (C[6] >>> 0 < C_[6] >>> 0 ? 1 : 0)) | 0; 10846 this._b = C[7] >>> 0 < C_[7] >>> 0 ? 1 : 0; 10847 10848 // Calculate the g-values 10849 for (var i = 0; i < 8; i++) { 10850 var gx = X[i] + C[i]; 10851 10852 // Construct high and low argument for squaring 10853 var ga = gx & 0xffff; 10854 var gb = gx >>> 16; 10855 10856 // Calculate high and low result of squaring 10857 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10858 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10859 10860 // High XOR low 10861 G[i] = gh ^ gl; 10862 } 10863 10864 // Calculate new state values 10865 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10866 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10867 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10868 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10869 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10870 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10871 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10872 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10873 } 10874 10875 /** 10876 * Shortcut functions to the cipher's object interface. 10877 * 10878 * @example 10879 * 10880 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10881 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10882 */ 10883 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10884 })(); 10885 10886 return CryptoJS.RabbitLegacy; 10887 }); 10888 }, 10889 { './cipher-core': 52, './core': 53, './enc-base64': 54, './evpkdf': 56, './md5': 61 }, 10890 ], 10891 74: [ 10892 function (require, module, exports) { 10893 (function (root, factory, undef) { 10894 if (typeof exports === 'object') { 10895 // CommonJS 10896 module.exports = exports = factory( 10897 require('./core'), 10898 require('./enc-base64'), 10899 require('./md5'), 10900 require('./evpkdf'), 10901 require('./cipher-core') 10902 ); 10903 } else if (typeof define === 'function' && define.amd) { 10904 // AMD 10905 define(['./core', './enc-base64', './md5', './evpkdf', './cipher-core'], factory); 10906 } else { 10907 // Global (browser) 10908 factory(root.CryptoJS); 10909 } 10910 })(this, function (CryptoJS) { 10911 (function () { 10912 // Shortcuts 10913 var C = CryptoJS; 10914 var C_lib = C.lib; 10915 var StreamCipher = C_lib.StreamCipher; 10916 var C_algo = C.algo; 10917 10918 // Reusable objects 10919 var S = []; 10920 var C_ = []; 10921 var G = []; 10922 10923 /** 10924 * Rabbit stream cipher algorithm 10925 */ 10926 var Rabbit = (C_algo.Rabbit = StreamCipher.extend({ 10927 _doReset: function () { 10928 // Shortcuts 10929 var K = this._key.words; 10930 var iv = this.cfg.iv; 10931 10932 // Swap endian 10933 for (var i = 0; i < 4; i++) { 10934 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10935 } 10936 10937 // Generate initial state values 10938 var X = (this._X = [ 10939 K[0], 10940 (K[3] << 16) | (K[2] >>> 16), 10941 K[1], 10942 (K[0] << 16) | (K[3] >>> 16), 10943 K[2], 10944 (K[1] << 16) | (K[0] >>> 16), 10945 K[3], 10946 (K[2] << 16) | (K[1] >>> 16), 10947 ]); 10948 10949 // Generate initial counter values 10950 var C = (this._C = [ 10951 (K[2] << 16) | (K[2] >>> 16), 10952 (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10953 (K[3] << 16) | (K[3] >>> 16), 10954 (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10955 (K[0] << 16) | (K[0] >>> 16), 10956 (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10957 (K[1] << 16) | (K[1] >>> 16), 10958 (K[3] & 0xffff0000) | (K[0] & 0x0000ffff), 10959 ]); 10960 10961 // Carry bit 10962 this._b = 0; 10963 10964 // Iterate the system four times 10965 for (var i = 0; i < 4; i++) { 10966 nextState.call(this); 10967 } 10968 10969 // Modify the counters 10970 for (var i = 0; i < 8; i++) { 10971 C[i] ^= X[(i + 4) & 7]; 10972 } 10973 10974 // IV setup 10975 if (iv) { 10976 // Shortcuts 10977 var IV = iv.words; 10978 var IV_0 = IV[0]; 10979 var IV_1 = IV[1]; 10980 10981 // Generate four subvectors 10982 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10983 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10984 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10985 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10986 10987 // Modify counter values 10988 C[0] ^= i0; 10989 C[1] ^= i1; 10990 C[2] ^= i2; 10991 C[3] ^= i3; 10992 C[4] ^= i0; 10993 C[5] ^= i1; 10994 C[6] ^= i2; 10995 C[7] ^= i3; 10996 10997 // Iterate the system four times 10998 for (var i = 0; i < 4; i++) { 10999 nextState.call(this); 11000 } 11001 } 11002 }, 11003 11004 _doProcessBlock: function (M, offset) { 11005 // Shortcut 11006 var X = this._X; 11007 11008 // Iterate the system 11009 nextState.call(this); 11010 11011 // Generate four keystream words 11012 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 11013 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 11014 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 11015 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 11016 11017 for (var i = 0; i < 4; i++) { 11018 // Swap endian 11019 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 11020 11021 // Encrypt 11022 M[offset + i] ^= S[i]; 11023 } 11024 }, 11025 11026 blockSize: 128 / 32, 11027 11028 ivSize: 64 / 32, 11029 })); 11030 11031 function nextState() { 11032 // Shortcuts 11033 var X = this._X; 11034 var C = this._C; 11035 11036 // Save old counter values 11037 for (var i = 0; i < 8; i++) { 11038 C_[i] = C[i]; 11039 } 11040 11041 // Calculate new counter values 11042 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 11043 C[1] = (C[1] + 0xd34d34d3 + (C[0] >>> 0 < C_[0] >>> 0 ? 1 : 0)) | 0; 11044 C[2] = (C[2] + 0x34d34d34 + (C[1] >>> 0 < C_[1] >>> 0 ? 1 : 0)) | 0; 11045 C[3] = (C[3] + 0x4d34d34d + (C[2] >>> 0 < C_[2] >>> 0 ? 1 : 0)) | 0; 11046 C[4] = (C[4] + 0xd34d34d3 + (C[3] >>> 0 < C_[3] >>> 0 ? 1 : 0)) | 0; 11047 C[5] = (C[5] + 0x34d34d34 + (C[4] >>> 0 < C_[4] >>> 0 ? 1 : 0)) | 0; 11048 C[6] = (C[6] + 0x4d34d34d + (C[5] >>> 0 < C_[5] >>> 0 ? 1 : 0)) | 0; 11049 C[7] = (C[7] + 0xd34d34d3 + (C[6] >>> 0 < C_[6] >>> 0 ? 1 : 0)) | 0; 11050 this._b = C[7] >>> 0 < C_[7] >>> 0 ? 1 : 0; 11051 11052 // Calculate the g-values 11053 for (var i = 0; i < 8; i++) { 11054 var gx = X[i] + C[i]; 11055 11056 // Construct high and low argument for squaring 11057 var ga = gx & 0xffff; 11058 var gb = gx >>> 16; 11059 11060 // Calculate high and low result of squaring 11061 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 11062 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 11063 11064 // High XOR low 11065 G[i] = gh ^ gl; 11066 } 11067 11068 // Calculate new state values 11069 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 11070 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 11071 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 11072 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 11073 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 11074 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 11075 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 11076 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 11077 } 11078 11079 /** 11080 * Shortcut functions to the cipher's object interface. 11081 * 11082 * @example 11083 * 11084 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 11085 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 11086 */ 11087 C.Rabbit = StreamCipher._createHelper(Rabbit); 11088 })(); 11089 11090 return CryptoJS.Rabbit; 11091 }); 11092 }, 11093 { './cipher-core': 52, './core': 53, './enc-base64': 54, './evpkdf': 56, './md5': 61 }, 11094 ], 11095 75: [ 11096 function (require, module, exports) { 11097 (function (root, factory, undef) { 11098 if (typeof exports === 'object') { 11099 // CommonJS 11100 module.exports = exports = factory( 11101 require('./core'), 11102 require('./enc-base64'), 11103 require('./md5'), 11104 require('./evpkdf'), 11105 require('./cipher-core') 11106 ); 11107 } else if (typeof define === 'function' && define.amd) { 11108 // AMD 11109 define(['./core', './enc-base64', './md5', './evpkdf', './cipher-core'], factory); 11110 } else { 11111 // Global (browser) 11112 factory(root.CryptoJS); 11113 } 11114 })(this, function (CryptoJS) { 11115 (function () { 11116 // Shortcuts 11117 var C = CryptoJS; 11118 var C_lib = C.lib; 11119 var StreamCipher = C_lib.StreamCipher; 11120 var C_algo = C.algo; 11121 11122 /** 11123 * RC4 stream cipher algorithm. 11124 */ 11125 var RC4 = (C_algo.RC4 = StreamCipher.extend({ 11126 _doReset: function () { 11127 // Shortcuts 11128 var key = this._key; 11129 var keyWords = key.words; 11130 var keySigBytes = key.sigBytes; 11131 11132 // Init sbox 11133 var S = (this._S = []); 11134 for (var i = 0; i < 256; i++) { 11135 S[i] = i; 11136 } 11137 11138 // Key setup 11139 for (var i = 0, j = 0; i < 256; i++) { 11140 var keyByteIndex = i % keySigBytes; 11141 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 11142 11143 j = (j + S[i] + keyByte) % 256; 11144 11145 // Swap 11146 var t = S[i]; 11147 S[i] = S[j]; 11148 S[j] = t; 11149 } 11150 11151 // Counters 11152 this._i = this._j = 0; 11153 }, 11154 11155 _doProcessBlock: function (M, offset) { 11156 M[offset] ^= generateKeystreamWord.call(this); 11157 }, 11158 11159 keySize: 256 / 32, 11160 11161 ivSize: 0, 11162 })); 11163 11164 function generateKeystreamWord() { 11165 // Shortcuts 11166 var S = this._S; 11167 var i = this._i; 11168 var j = this._j; 11169 11170 // Generate keystream word 11171 var keystreamWord = 0; 11172 for (var n = 0; n < 4; n++) { 11173 i = (i + 1) % 256; 11174 j = (j + S[i]) % 256; 11175 11176 // Swap 11177 var t = S[i]; 11178 S[i] = S[j]; 11179 S[j] = t; 11180 11181 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 11182 } 11183 11184 // Update counters 11185 this._i = i; 11186 this._j = j; 11187 11188 return keystreamWord; 11189 } 11190 11191 /** 11192 * Shortcut functions to the cipher's object interface. 11193 * 11194 * @example 11195 * 11196 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 11197 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 11198 */ 11199 C.RC4 = StreamCipher._createHelper(RC4); 11200 11201 /** 11202 * Modified RC4 stream cipher algorithm. 11203 */ 11204 var RC4Drop = (C_algo.RC4Drop = RC4.extend({ 11205 /** 11206 * Configuration options. 11207 * 11208 * @property {number} drop The number of keystream words to drop. Default 192 11209 */ 11210 cfg: RC4.cfg.extend({ 11211 drop: 192, 11212 }), 11213 11214 _doReset: function () { 11215 RC4._doReset.call(this); 11216 11217 // Drop 11218 for (var i = this.cfg.drop; i > 0; i--) { 11219 generateKeystreamWord.call(this); 11220 } 11221 }, 11222 })); 11223 11224 /** 11225 * Shortcut functions to the cipher's object interface. 11226 * 11227 * @example 11228 * 11229 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 11230 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 11231 */ 11232 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 11233 })(); 11234 11235 return CryptoJS.RC4; 11236 }); 11237 }, 11238 { './cipher-core': 52, './core': 53, './enc-base64': 54, './evpkdf': 56, './md5': 61 }, 11239 ], 11240 76: [ 11241 function (require, module, exports) { 11242 (function (root, factory) { 11243 if (typeof exports === 'object') { 11244 // CommonJS 11245 module.exports = exports = factory(require('./core')); 11246 } else if (typeof define === 'function' && define.amd) { 11247 // AMD 11248 define(['./core'], factory); 11249 } else { 11250 // Global (browser) 11251 factory(root.CryptoJS); 11252 } 11253 })(this, function (CryptoJS) { 11254 /** @preserve 11255 (c) 2012 by Cédric Mesnil. All rights reserved. 11256 11257 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 11258 11259 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11260 - 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. 11261 11262 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. 11263 */ 11264 11265 (function (Math) { 11266 // Shortcuts 11267 var C = CryptoJS; 11268 var C_lib = C.lib; 11269 var WordArray = C_lib.WordArray; 11270 var Hasher = C_lib.Hasher; 11271 var C_algo = C.algo; 11272 11273 // Constants table 11274 var _zl = WordArray.create([ 11275 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 11276 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 11277 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13, 11278 ]); 11279 var _zr = WordArray.create([ 11280 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 11281 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 11282 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11, 11283 ]); 11284 var _sl = WordArray.create([ 11285 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 11286 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 11287 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6, 11288 ]); 11289 var _sr = WordArray.create([ 11290 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 11291 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 11292 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11, 11293 ]); 11294 11295 var _hl = WordArray.create([0x00000000, 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xa953fd4e]); 11296 var _hr = WordArray.create([0x50a28be6, 0x5c4dd124, 0x6d703ef3, 0x7a6d76e9, 0x00000000]); 11297 11298 /** 11299 * RIPEMD160 hash algorithm. 11300 */ 11301 var RIPEMD160 = (C_algo.RIPEMD160 = Hasher.extend({ 11302 _doReset: function () { 11303 this._hash = WordArray.create([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]); 11304 }, 11305 11306 _doProcessBlock: function (M, offset) { 11307 // Swap endian 11308 for (var i = 0; i < 16; i++) { 11309 // Shortcuts 11310 var offset_i = offset + i; 11311 var M_offset_i = M[offset_i]; 11312 11313 // Swap 11314 M[offset_i] = 11315 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 11316 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00); 11317 } 11318 // Shortcut 11319 var H = this._hash.words; 11320 var hl = _hl.words; 11321 var hr = _hr.words; 11322 var zl = _zl.words; 11323 var zr = _zr.words; 11324 var sl = _sl.words; 11325 var sr = _sr.words; 11326 11327 // Working variables 11328 var al, bl, cl, dl, el; 11329 var ar, br, cr, dr, er; 11330 11331 ar = al = H[0]; 11332 br = bl = H[1]; 11333 cr = cl = H[2]; 11334 dr = dl = H[3]; 11335 er = el = H[4]; 11336 // Computation 11337 var t; 11338 for (var i = 0; i < 80; i += 1) { 11339 t = (al + M[offset + zl[i]]) | 0; 11340 if (i < 16) { 11341 t += f1(bl, cl, dl) + hl[0]; 11342 } else if (i < 32) { 11343 t += f2(bl, cl, dl) + hl[1]; 11344 } else if (i < 48) { 11345 t += f3(bl, cl, dl) + hl[2]; 11346 } else if (i < 64) { 11347 t += f4(bl, cl, dl) + hl[3]; 11348 } else { 11349 // if (i<80) { 11350 t += f5(bl, cl, dl) + hl[4]; 11351 } 11352 t = t | 0; 11353 t = rotl(t, sl[i]); 11354 t = (t + el) | 0; 11355 al = el; 11356 el = dl; 11357 dl = rotl(cl, 10); 11358 cl = bl; 11359 bl = t; 11360 11361 t = (ar + M[offset + zr[i]]) | 0; 11362 if (i < 16) { 11363 t += f5(br, cr, dr) + hr[0]; 11364 } else if (i < 32) { 11365 t += f4(br, cr, dr) + hr[1]; 11366 } else if (i < 48) { 11367 t += f3(br, cr, dr) + hr[2]; 11368 } else if (i < 64) { 11369 t += f2(br, cr, dr) + hr[3]; 11370 } else { 11371 // if (i<80) { 11372 t += f1(br, cr, dr) + hr[4]; 11373 } 11374 t = t | 0; 11375 t = rotl(t, sr[i]); 11376 t = (t + er) | 0; 11377 ar = er; 11378 er = dr; 11379 dr = rotl(cr, 10); 11380 cr = br; 11381 br = t; 11382 } 11383 // Intermediate hash value 11384 t = (H[1] + cl + dr) | 0; 11385 H[1] = (H[2] + dl + er) | 0; 11386 H[2] = (H[3] + el + ar) | 0; 11387 H[3] = (H[4] + al + br) | 0; 11388 H[4] = (H[0] + bl + cr) | 0; 11389 H[0] = t; 11390 }, 11391 11392 _doFinalize: function () { 11393 // Shortcuts 11394 var data = this._data; 11395 var dataWords = data.words; 11396 11397 var nBitsTotal = this._nDataBytes * 8; 11398 var nBitsLeft = data.sigBytes * 8; 11399 11400 // Add padding 11401 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 11402 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = 11403 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11404 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00); 11405 data.sigBytes = (dataWords.length + 1) * 4; 11406 11407 // Hash final blocks 11408 this._process(); 11409 11410 // Shortcuts 11411 var hash = this._hash; 11412 var H = hash.words; 11413 11414 // Swap endian 11415 for (var i = 0; i < 5; i++) { 11416 // Shortcut 11417 var H_i = H[i]; 11418 11419 // Swap 11420 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11421 } 11422 11423 // Return final computed hash 11424 return hash; 11425 }, 11426 11427 clone: function () { 11428 var clone = Hasher.clone.call(this); 11429 clone._hash = this._hash.clone(); 11430 11431 return clone; 11432 }, 11433 })); 11434 11435 function f1(x, y, z) { 11436 return x ^ y ^ z; 11437 } 11438 11439 function f2(x, y, z) { 11440 return (x & y) | (~x & z); 11441 } 11442 11443 function f3(x, y, z) { 11444 return (x | ~y) ^ z; 11445 } 11446 11447 function f4(x, y, z) { 11448 return (x & z) | (y & ~z); 11449 } 11450 11451 function f5(x, y, z) { 11452 return x ^ (y | ~z); 11453 } 11454 11455 function rotl(x, n) { 11456 return (x << n) | (x >>> (32 - n)); 11457 } 11458 11459 /** 11460 * Shortcut function to the hasher's object interface. 11461 * 11462 * @param {WordArray|string} message The message to hash. 11463 * 11464 * @return {WordArray} The hash. 11465 * 11466 * @static 11467 * 11468 * @example 11469 * 11470 * var hash = CryptoJS.RIPEMD160('message'); 11471 * var hash = CryptoJS.RIPEMD160(wordArray); 11472 */ 11473 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11474 11475 /** 11476 * Shortcut function to the HMAC's object interface. 11477 * 11478 * @param {WordArray|string} message The message to hash. 11479 * @param {WordArray|string} key The secret key. 11480 * 11481 * @return {WordArray} The HMAC. 11482 * 11483 * @static 11484 * 11485 * @example 11486 * 11487 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11488 */ 11489 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11490 })(Math); 11491 11492 return CryptoJS.RIPEMD160; 11493 }); 11494 }, 11495 { './core': 53 }, 11496 ], 11497 77: [ 11498 function (require, module, exports) { 11499 (function (root, factory) { 11500 if (typeof exports === 'object') { 11501 // CommonJS 11502 module.exports = exports = factory(require('./core')); 11503 } else if (typeof define === 'function' && define.amd) { 11504 // AMD 11505 define(['./core'], factory); 11506 } else { 11507 // Global (browser) 11508 factory(root.CryptoJS); 11509 } 11510 })(this, function (CryptoJS) { 11511 (function () { 11512 // Shortcuts 11513 var C = CryptoJS; 11514 var C_lib = C.lib; 11515 var WordArray = C_lib.WordArray; 11516 var Hasher = C_lib.Hasher; 11517 var C_algo = C.algo; 11518 11519 // Reusable object 11520 var W = []; 11521 11522 /** 11523 * SHA-1 hash algorithm. 11524 */ 11525 var SHA1 = (C_algo.SHA1 = Hasher.extend({ 11526 _doReset: function () { 11527 this._hash = new WordArray.init([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]); 11528 }, 11529 11530 _doProcessBlock: function (M, offset) { 11531 // Shortcut 11532 var H = this._hash.words; 11533 11534 // Working variables 11535 var a = H[0]; 11536 var b = H[1]; 11537 var c = H[2]; 11538 var d = H[3]; 11539 var e = H[4]; 11540 11541 // Computation 11542 for (var i = 0; i < 80; i++) { 11543 if (i < 16) { 11544 W[i] = M[offset + i] | 0; 11545 } else { 11546 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11547 W[i] = (n << 1) | (n >>> 31); 11548 } 11549 11550 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11551 if (i < 20) { 11552 t += ((b & c) | (~b & d)) + 0x5a827999; 11553 } else if (i < 40) { 11554 t += (b ^ c ^ d) + 0x6ed9eba1; 11555 } else if (i < 60) { 11556 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11557 } /* if (i < 80) */ else { 11558 t += (b ^ c ^ d) - 0x359d3e2a; 11559 } 11560 11561 e = d; 11562 d = c; 11563 c = (b << 30) | (b >>> 2); 11564 b = a; 11565 a = t; 11566 } 11567 11568 // Intermediate hash value 11569 H[0] = (H[0] + a) | 0; 11570 H[1] = (H[1] + b) | 0; 11571 H[2] = (H[2] + c) | 0; 11572 H[3] = (H[3] + d) | 0; 11573 H[4] = (H[4] + e) | 0; 11574 }, 11575 11576 _doFinalize: function () { 11577 // Shortcuts 11578 var data = this._data; 11579 var dataWords = data.words; 11580 11581 var nBitsTotal = this._nDataBytes * 8; 11582 var nBitsLeft = data.sigBytes * 8; 11583 11584 // Add padding 11585 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 11586 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11587 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11588 data.sigBytes = dataWords.length * 4; 11589 11590 // Hash final blocks 11591 this._process(); 11592 11593 // Return final computed hash 11594 return this._hash; 11595 }, 11596 11597 clone: function () { 11598 var clone = Hasher.clone.call(this); 11599 clone._hash = this._hash.clone(); 11600 11601 return clone; 11602 }, 11603 })); 11604 11605 /** 11606 * Shortcut function to the hasher's object interface. 11607 * 11608 * @param {WordArray|string} message The message to hash. 11609 * 11610 * @return {WordArray} The hash. 11611 * 11612 * @static 11613 * 11614 * @example 11615 * 11616 * var hash = CryptoJS.SHA1('message'); 11617 * var hash = CryptoJS.SHA1(wordArray); 11618 */ 11619 C.SHA1 = Hasher._createHelper(SHA1); 11620 11621 /** 11622 * Shortcut function to the HMAC's object interface. 11623 * 11624 * @param {WordArray|string} message The message to hash. 11625 * @param {WordArray|string} key The secret key. 11626 * 11627 * @return {WordArray} The HMAC. 11628 * 11629 * @static 11630 * 11631 * @example 11632 * 11633 * var hmac = CryptoJS.HmacSHA1(message, key); 11634 */ 11635 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11636 })(); 11637 11638 return CryptoJS.SHA1; 11639 }); 11640 }, 11641 { './core': 53 }, 11642 ], 11643 78: [ 11644 function (require, module, exports) { 11645 (function (root, factory, undef) { 11646 if (typeof exports === 'object') { 11647 // CommonJS 11648 module.exports = exports = factory(require('./core'), require('./sha256')); 11649 } else if (typeof define === 'function' && define.amd) { 11650 // AMD 11651 define(['./core', './sha256'], factory); 11652 } else { 11653 // Global (browser) 11654 factory(root.CryptoJS); 11655 } 11656 })(this, function (CryptoJS) { 11657 (function () { 11658 // Shortcuts 11659 var C = CryptoJS; 11660 var C_lib = C.lib; 11661 var WordArray = C_lib.WordArray; 11662 var C_algo = C.algo; 11663 var SHA256 = C_algo.SHA256; 11664 11665 /** 11666 * SHA-224 hash algorithm. 11667 */ 11668 var SHA224 = (C_algo.SHA224 = SHA256.extend({ 11669 _doReset: function () { 11670 this._hash = new WordArray.init([ 11671 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, 11672 ]); 11673 }, 11674 11675 _doFinalize: function () { 11676 var hash = SHA256._doFinalize.call(this); 11677 11678 hash.sigBytes -= 4; 11679 11680 return hash; 11681 }, 11682 })); 11683 11684 /** 11685 * Shortcut function to the hasher's object interface. 11686 * 11687 * @param {WordArray|string} message The message to hash. 11688 * 11689 * @return {WordArray} The hash. 11690 * 11691 * @static 11692 * 11693 * @example 11694 * 11695 * var hash = CryptoJS.SHA224('message'); 11696 * var hash = CryptoJS.SHA224(wordArray); 11697 */ 11698 C.SHA224 = SHA256._createHelper(SHA224); 11699 11700 /** 11701 * Shortcut function to the HMAC's object interface. 11702 * 11703 * @param {WordArray|string} message The message to hash. 11704 * @param {WordArray|string} key The secret key. 11705 * 11706 * @return {WordArray} The HMAC. 11707 * 11708 * @static 11709 * 11710 * @example 11711 * 11712 * var hmac = CryptoJS.HmacSHA224(message, key); 11713 */ 11714 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11715 })(); 11716 11717 return CryptoJS.SHA224; 11718 }); 11719 }, 11720 { './core': 53, './sha256': 79 }, 11721 ], 11722 79: [ 11723 function (require, module, exports) { 11724 (function (root, factory) { 11725 if (typeof exports === 'object') { 11726 // CommonJS 11727 module.exports = exports = factory(require('./core')); 11728 } else if (typeof define === 'function' && define.amd) { 11729 // AMD 11730 define(['./core'], factory); 11731 } else { 11732 // Global (browser) 11733 factory(root.CryptoJS); 11734 } 11735 })(this, function (CryptoJS) { 11736 (function (Math) { 11737 // Shortcuts 11738 var C = CryptoJS; 11739 var C_lib = C.lib; 11740 var WordArray = C_lib.WordArray; 11741 var Hasher = C_lib.Hasher; 11742 var C_algo = C.algo; 11743 11744 // Initialization and round constants tables 11745 var H = []; 11746 var K = []; 11747 11748 // Compute constants 11749 (function () { 11750 function isPrime(n) { 11751 var sqrtN = Math.sqrt(n); 11752 for (var factor = 2; factor <= sqrtN; factor++) { 11753 if (!(n % factor)) { 11754 return false; 11755 } 11756 } 11757 11758 return true; 11759 } 11760 11761 function getFractionalBits(n) { 11762 return ((n - (n | 0)) * 0x100000000) | 0; 11763 } 11764 11765 var n = 2; 11766 var nPrime = 0; 11767 while (nPrime < 64) { 11768 if (isPrime(n)) { 11769 if (nPrime < 8) { 11770 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11771 } 11772 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11773 11774 nPrime++; 11775 } 11776 11777 n++; 11778 } 11779 })(); 11780 11781 // Reusable object 11782 var W = []; 11783 11784 /** 11785 * SHA-256 hash algorithm. 11786 */ 11787 var SHA256 = (C_algo.SHA256 = Hasher.extend({ 11788 _doReset: function () { 11789 this._hash = new WordArray.init(H.slice(0)); 11790 }, 11791 11792 _doProcessBlock: function (M, offset) { 11793 // Shortcut 11794 var H = this._hash.words; 11795 11796 // Working variables 11797 var a = H[0]; 11798 var b = H[1]; 11799 var c = H[2]; 11800 var d = H[3]; 11801 var e = H[4]; 11802 var f = H[5]; 11803 var g = H[6]; 11804 var h = H[7]; 11805 11806 // Computation 11807 for (var i = 0; i < 64; i++) { 11808 if (i < 16) { 11809 W[i] = M[offset + i] | 0; 11810 } else { 11811 var gamma0x = W[i - 15]; 11812 var gamma0 = 11813 ((gamma0x << 25) | (gamma0x >>> 7)) ^ ((gamma0x << 14) | (gamma0x >>> 18)) ^ (gamma0x >>> 3); 11814 11815 var gamma1x = W[i - 2]; 11816 var gamma1 = 11817 ((gamma1x << 15) | (gamma1x >>> 17)) ^ ((gamma1x << 13) | (gamma1x >>> 19)) ^ (gamma1x >>> 10); 11818 11819 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11820 } 11821 11822 var ch = (e & f) ^ (~e & g); 11823 var maj = (a & b) ^ (a & c) ^ (b & c); 11824 11825 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11826 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11827 11828 var t1 = h + sigma1 + ch + K[i] + W[i]; 11829 var t2 = sigma0 + maj; 11830 11831 h = g; 11832 g = f; 11833 f = e; 11834 e = (d + t1) | 0; 11835 d = c; 11836 c = b; 11837 b = a; 11838 a = (t1 + t2) | 0; 11839 } 11840 11841 // Intermediate hash value 11842 H[0] = (H[0] + a) | 0; 11843 H[1] = (H[1] + b) | 0; 11844 H[2] = (H[2] + c) | 0; 11845 H[3] = (H[3] + d) | 0; 11846 H[4] = (H[4] + e) | 0; 11847 H[5] = (H[5] + f) | 0; 11848 H[6] = (H[6] + g) | 0; 11849 H[7] = (H[7] + h) | 0; 11850 }, 11851 11852 _doFinalize: function () { 11853 // Shortcuts 11854 var data = this._data; 11855 var dataWords = data.words; 11856 11857 var nBitsTotal = this._nDataBytes * 8; 11858 var nBitsLeft = data.sigBytes * 8; 11859 11860 // Add padding 11861 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 11862 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11863 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11864 data.sigBytes = dataWords.length * 4; 11865 11866 // Hash final blocks 11867 this._process(); 11868 11869 // Return final computed hash 11870 return this._hash; 11871 }, 11872 11873 clone: function () { 11874 var clone = Hasher.clone.call(this); 11875 clone._hash = this._hash.clone(); 11876 11877 return clone; 11878 }, 11879 })); 11880 11881 /** 11882 * Shortcut function to the hasher's object interface. 11883 * 11884 * @param {WordArray|string} message The message to hash. 11885 * 11886 * @return {WordArray} The hash. 11887 * 11888 * @static 11889 * 11890 * @example 11891 * 11892 * var hash = CryptoJS.SHA256('message'); 11893 * var hash = CryptoJS.SHA256(wordArray); 11894 */ 11895 C.SHA256 = Hasher._createHelper(SHA256); 11896 11897 /** 11898 * Shortcut function to the HMAC's object interface. 11899 * 11900 * @param {WordArray|string} message The message to hash. 11901 * @param {WordArray|string} key The secret key. 11902 * 11903 * @return {WordArray} The HMAC. 11904 * 11905 * @static 11906 * 11907 * @example 11908 * 11909 * var hmac = CryptoJS.HmacSHA256(message, key); 11910 */ 11911 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11912 })(Math); 11913 11914 return CryptoJS.SHA256; 11915 }); 11916 }, 11917 { './core': 53 }, 11918 ], 11919 80: [ 11920 function (require, module, exports) { 11921 (function (root, factory, undef) { 11922 if (typeof exports === 'object') { 11923 // CommonJS 11924 module.exports = exports = factory(require('./core'), require('./x64-core')); 11925 } else if (typeof define === 'function' && define.amd) { 11926 // AMD 11927 define(['./core', './x64-core'], factory); 11928 } else { 11929 // Global (browser) 11930 factory(root.CryptoJS); 11931 } 11932 })(this, function (CryptoJS) { 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_x64 = C.x64; 11940 var X64Word = C_x64.Word; 11941 var C_algo = C.algo; 11942 11943 // Constants tables 11944 var RHO_OFFSETS = []; 11945 var PI_INDEXES = []; 11946 var ROUND_CONSTANTS = []; 11947 11948 // Compute Constants 11949 (function () { 11950 // Compute rho offset constants 11951 var x = 1, 11952 y = 0; 11953 for (var t = 0; t < 24; t++) { 11954 RHO_OFFSETS[x + 5 * y] = (((t + 1) * (t + 2)) / 2) % 64; 11955 11956 var newX = y % 5; 11957 var newY = (2 * x + 3 * y) % 5; 11958 x = newX; 11959 y = newY; 11960 } 11961 11962 // Compute pi index constants 11963 for (var x = 0; x < 5; x++) { 11964 for (var y = 0; y < 5; y++) { 11965 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11966 } 11967 } 11968 11969 // Compute round constants 11970 var LFSR = 0x01; 11971 for (var i = 0; i < 24; i++) { 11972 var roundConstantMsw = 0; 11973 var roundConstantLsw = 0; 11974 11975 for (var j = 0; j < 7; j++) { 11976 if (LFSR & 0x01) { 11977 var bitPosition = (1 << j) - 1; 11978 if (bitPosition < 32) { 11979 roundConstantLsw ^= 1 << bitPosition; 11980 } /* if (bitPosition >= 32) */ else { 11981 roundConstantMsw ^= 1 << (bitPosition - 32); 11982 } 11983 } 11984 11985 // Compute next LFSR 11986 if (LFSR & 0x80) { 11987 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11988 LFSR = (LFSR << 1) ^ 0x71; 11989 } else { 11990 LFSR <<= 1; 11991 } 11992 } 11993 11994 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11995 } 11996 })(); 11997 11998 // Reusable objects for temporary values 11999 var T = []; 12000 (function () { 12001 for (var i = 0; i < 25; i++) { 12002 T[i] = X64Word.create(); 12003 } 12004 })(); 12005 12006 /** 12007 * SHA-3 hash algorithm. 12008 */ 12009 var SHA3 = (C_algo.SHA3 = Hasher.extend({ 12010 /** 12011 * Configuration options. 12012 * 12013 * @property {number} outputLength 12014 * The desired number of bits in the output hash. 12015 * Only values permitted are: 224, 256, 384, 512. 12016 * Default: 512 12017 */ 12018 cfg: Hasher.cfg.extend({ 12019 outputLength: 512, 12020 }), 12021 12022 _doReset: function () { 12023 var state = (this._state = []); 12024 for (var i = 0; i < 25; i++) { 12025 state[i] = new X64Word.init(); 12026 } 12027 12028 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 12029 }, 12030 12031 _doProcessBlock: function (M, offset) { 12032 // Shortcuts 12033 var state = this._state; 12034 var nBlockSizeLanes = this.blockSize / 2; 12035 12036 // Absorb 12037 for (var i = 0; i < nBlockSizeLanes; i++) { 12038 // Shortcuts 12039 var M2i = M[offset + 2 * i]; 12040 var M2i1 = M[offset + 2 * i + 1]; 12041 12042 // Swap endian 12043 M2i = (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00); 12044 M2i1 = (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00); 12045 12046 // Absorb message into state 12047 var lane = state[i]; 12048 lane.high ^= M2i1; 12049 lane.low ^= M2i; 12050 } 12051 12052 // Rounds 12053 for (var round = 0; round < 24; round++) { 12054 // Theta 12055 for (var x = 0; x < 5; x++) { 12056 // Mix column lanes 12057 var tMsw = 0, 12058 tLsw = 0; 12059 for (var y = 0; y < 5; y++) { 12060 var lane = state[x + 5 * y]; 12061 tMsw ^= lane.high; 12062 tLsw ^= lane.low; 12063 } 12064 12065 // Temporary values 12066 var Tx = T[x]; 12067 Tx.high = tMsw; 12068 Tx.low = tLsw; 12069 } 12070 for (var x = 0; x < 5; x++) { 12071 // Shortcuts 12072 var Tx4 = T[(x + 4) % 5]; 12073 var Tx1 = T[(x + 1) % 5]; 12074 var Tx1Msw = Tx1.high; 12075 var Tx1Lsw = Tx1.low; 12076 12077 // Mix surrounding columns 12078 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 12079 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 12080 for (var y = 0; y < 5; y++) { 12081 var lane = state[x + 5 * y]; 12082 lane.high ^= tMsw; 12083 lane.low ^= tLsw; 12084 } 12085 } 12086 12087 // Rho Pi 12088 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 12089 // Shortcuts 12090 var lane = state[laneIndex]; 12091 var laneMsw = lane.high; 12092 var laneLsw = lane.low; 12093 var rhoOffset = RHO_OFFSETS[laneIndex]; 12094 12095 // Rotate lanes 12096 if (rhoOffset < 32) { 12097 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 12098 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 12099 } /* if (rhoOffset >= 32) */ else { 12100 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 12101 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 12102 } 12103 12104 // Transpose lanes 12105 var TPiLane = T[PI_INDEXES[laneIndex]]; 12106 TPiLane.high = tMsw; 12107 TPiLane.low = tLsw; 12108 } 12109 12110 // Rho pi at x = y = 0 12111 var T0 = T[0]; 12112 var state0 = state[0]; 12113 T0.high = state0.high; 12114 T0.low = state0.low; 12115 12116 // Chi 12117 for (var x = 0; x < 5; x++) { 12118 for (var y = 0; y < 5; y++) { 12119 // Shortcuts 12120 var laneIndex = x + 5 * y; 12121 var lane = state[laneIndex]; 12122 var TLane = T[laneIndex]; 12123 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 12124 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 12125 12126 // Mix rows 12127 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 12128 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 12129 } 12130 } 12131 12132 // Iota 12133 var lane = state[0]; 12134 var roundConstant = ROUND_CONSTANTS[round]; 12135 lane.high ^= roundConstant.high; 12136 lane.low ^= roundConstant.low; 12137 } 12138 }, 12139 12140 _doFinalize: function () { 12141 // Shortcuts 12142 var data = this._data; 12143 var dataWords = data.words; 12144 var nBitsTotal = this._nDataBytes * 8; 12145 var nBitsLeft = data.sigBytes * 8; 12146 var blockSizeBits = this.blockSize * 32; 12147 12148 // Add padding 12149 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - (nBitsLeft % 32)); 12150 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 12151 data.sigBytes = dataWords.length * 4; 12152 12153 // Hash final blocks 12154 this._process(); 12155 12156 // Shortcuts 12157 var state = this._state; 12158 var outputLengthBytes = this.cfg.outputLength / 8; 12159 var outputLengthLanes = outputLengthBytes / 8; 12160 12161 // Squeeze 12162 var hashWords = []; 12163 for (var i = 0; i < outputLengthLanes; i++) { 12164 // Shortcuts 12165 var lane = state[i]; 12166 var laneMsw = lane.high; 12167 var laneLsw = lane.low; 12168 12169 // Swap endian 12170 laneMsw = 12171 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 12172 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00); 12173 laneLsw = 12174 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 12175 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00); 12176 12177 // Squeeze state to retrieve hash 12178 hashWords.push(laneLsw); 12179 hashWords.push(laneMsw); 12180 } 12181 12182 // Return final computed hash 12183 return new WordArray.init(hashWords, outputLengthBytes); 12184 }, 12185 12186 clone: function () { 12187 var clone = Hasher.clone.call(this); 12188 12189 var state = (clone._state = this._state.slice(0)); 12190 for (var i = 0; i < 25; i++) { 12191 state[i] = state[i].clone(); 12192 } 12193 12194 return clone; 12195 }, 12196 })); 12197 12198 /** 12199 * Shortcut function to the hasher's object interface. 12200 * 12201 * @param {WordArray|string} message The message to hash. 12202 * 12203 * @return {WordArray} The hash. 12204 * 12205 * @static 12206 * 12207 * @example 12208 * 12209 * var hash = CryptoJS.SHA3('message'); 12210 * var hash = CryptoJS.SHA3(wordArray); 12211 */ 12212 C.SHA3 = Hasher._createHelper(SHA3); 12213 12214 /** 12215 * Shortcut function to the HMAC's object interface. 12216 * 12217 * @param {WordArray|string} message The message to hash. 12218 * @param {WordArray|string} key The secret key. 12219 * 12220 * @return {WordArray} The HMAC. 12221 * 12222 * @static 12223 * 12224 * @example 12225 * 12226 * var hmac = CryptoJS.HmacSHA3(message, key); 12227 */ 12228 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 12229 })(Math); 12230 12231 return CryptoJS.SHA3; 12232 }); 12233 }, 12234 { './core': 53, './x64-core': 84 }, 12235 ], 12236 81: [ 12237 function (require, module, exports) { 12238 (function (root, factory, undef) { 12239 if (typeof exports === 'object') { 12240 // CommonJS 12241 module.exports = exports = factory(require('./core'), require('./x64-core'), require('./sha512')); 12242 } else if (typeof define === 'function' && define.amd) { 12243 // AMD 12244 define(['./core', './x64-core', './sha512'], factory); 12245 } else { 12246 // Global (browser) 12247 factory(root.CryptoJS); 12248 } 12249 })(this, function (CryptoJS) { 12250 (function () { 12251 // Shortcuts 12252 var C = CryptoJS; 12253 var C_x64 = C.x64; 12254 var X64Word = C_x64.Word; 12255 var X64WordArray = C_x64.WordArray; 12256 var C_algo = C.algo; 12257 var SHA512 = C_algo.SHA512; 12258 12259 /** 12260 * SHA-384 hash algorithm. 12261 */ 12262 var SHA384 = (C_algo.SHA384 = SHA512.extend({ 12263 _doReset: function () { 12264 this._hash = new X64WordArray.init([ 12265 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), 12266 new X64Word.init(0x629a292a, 0x367cd507), 12267 new X64Word.init(0x9159015a, 0x3070dd17), 12268 new X64Word.init(0x152fecd8, 0xf70e5939), 12269 new X64Word.init(0x67332667, 0xffc00b31), 12270 new X64Word.init(0x8eb44a87, 0x68581511), 12271 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), 12272 new X64Word.init(0x47b5481d, 0xbefa4fa4), 12273 ]); 12274 }, 12275 12276 _doFinalize: function () { 12277 var hash = SHA512._doFinalize.call(this); 12278 12279 hash.sigBytes -= 16; 12280 12281 return hash; 12282 }, 12283 })); 12284 12285 /** 12286 * Shortcut function to the hasher's object interface. 12287 * 12288 * @param {WordArray|string} message The message to hash. 12289 * 12290 * @return {WordArray} The hash. 12291 * 12292 * @static 12293 * 12294 * @example 12295 * 12296 * var hash = CryptoJS.SHA384('message'); 12297 * var hash = CryptoJS.SHA384(wordArray); 12298 */ 12299 C.SHA384 = SHA512._createHelper(SHA384); 12300 12301 /** 12302 * Shortcut function to the HMAC's object interface. 12303 * 12304 * @param {WordArray|string} message The message to hash. 12305 * @param {WordArray|string} key The secret key. 12306 * 12307 * @return {WordArray} The HMAC. 12308 * 12309 * @static 12310 * 12311 * @example 12312 * 12313 * var hmac = CryptoJS.HmacSHA384(message, key); 12314 */ 12315 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 12316 })(); 12317 12318 return CryptoJS.SHA384; 12319 }); 12320 }, 12321 { './core': 53, './sha512': 82, './x64-core': 84 }, 12322 ], 12323 82: [ 12324 function (require, module, exports) { 12325 (function (root, factory, undef) { 12326 if (typeof exports === 'object') { 12327 // CommonJS 12328 module.exports = exports = factory(require('./core'), require('./x64-core')); 12329 } else if (typeof define === 'function' && define.amd) { 12330 // AMD 12331 define(['./core', './x64-core'], factory); 12332 } else { 12333 // Global (browser) 12334 factory(root.CryptoJS); 12335 } 12336 })(this, function (CryptoJS) { 12337 (function () { 12338 // Shortcuts 12339 var C = CryptoJS; 12340 var C_lib = C.lib; 12341 var Hasher = C_lib.Hasher; 12342 var C_x64 = C.x64; 12343 var X64Word = C_x64.Word; 12344 var X64WordArray = C_x64.WordArray; 12345 var C_algo = C.algo; 12346 12347 function X64Word_create() { 12348 return X64Word.create.apply(X64Word, arguments); 12349 } 12350 12351 // Constants 12352 var K = [ 12353 X64Word_create(0x428a2f98, 0xd728ae22), 12354 X64Word_create(0x71374491, 0x23ef65cd), 12355 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), 12356 X64Word_create(0xe9b5dba5, 0x8189dbbc), 12357 X64Word_create(0x3956c25b, 0xf348b538), 12358 X64Word_create(0x59f111f1, 0xb605d019), 12359 X64Word_create(0x923f82a4, 0xaf194f9b), 12360 X64Word_create(0xab1c5ed5, 0xda6d8118), 12361 X64Word_create(0xd807aa98, 0xa3030242), 12362 X64Word_create(0x12835b01, 0x45706fbe), 12363 X64Word_create(0x243185be, 0x4ee4b28c), 12364 X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12365 X64Word_create(0x72be5d74, 0xf27b896f), 12366 X64Word_create(0x80deb1fe, 0x3b1696b1), 12367 X64Word_create(0x9bdc06a7, 0x25c71235), 12368 X64Word_create(0xc19bf174, 0xcf692694), 12369 X64Word_create(0xe49b69c1, 0x9ef14ad2), 12370 X64Word_create(0xefbe4786, 0x384f25e3), 12371 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), 12372 X64Word_create(0x240ca1cc, 0x77ac9c65), 12373 X64Word_create(0x2de92c6f, 0x592b0275), 12374 X64Word_create(0x4a7484aa, 0x6ea6e483), 12375 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), 12376 X64Word_create(0x76f988da, 0x831153b5), 12377 X64Word_create(0x983e5152, 0xee66dfab), 12378 X64Word_create(0xa831c66d, 0x2db43210), 12379 X64Word_create(0xb00327c8, 0x98fb213f), 12380 X64Word_create(0xbf597fc7, 0xbeef0ee4), 12381 X64Word_create(0xc6e00bf3, 0x3da88fc2), 12382 X64Word_create(0xd5a79147, 0x930aa725), 12383 X64Word_create(0x06ca6351, 0xe003826f), 12384 X64Word_create(0x14292967, 0x0a0e6e70), 12385 X64Word_create(0x27b70a85, 0x46d22ffc), 12386 X64Word_create(0x2e1b2138, 0x5c26c926), 12387 X64Word_create(0x4d2c6dfc, 0x5ac42aed), 12388 X64Word_create(0x53380d13, 0x9d95b3df), 12389 X64Word_create(0x650a7354, 0x8baf63de), 12390 X64Word_create(0x766a0abb, 0x3c77b2a8), 12391 X64Word_create(0x81c2c92e, 0x47edaee6), 12392 X64Word_create(0x92722c85, 0x1482353b), 12393 X64Word_create(0xa2bfe8a1, 0x4cf10364), 12394 X64Word_create(0xa81a664b, 0xbc423001), 12395 X64Word_create(0xc24b8b70, 0xd0f89791), 12396 X64Word_create(0xc76c51a3, 0x0654be30), 12397 X64Word_create(0xd192e819, 0xd6ef5218), 12398 X64Word_create(0xd6990624, 0x5565a910), 12399 X64Word_create(0xf40e3585, 0x5771202a), 12400 X64Word_create(0x106aa070, 0x32bbd1b8), 12401 X64Word_create(0x19a4c116, 0xb8d2d0c8), 12402 X64Word_create(0x1e376c08, 0x5141ab53), 12403 X64Word_create(0x2748774c, 0xdf8eeb99), 12404 X64Word_create(0x34b0bcb5, 0xe19b48a8), 12405 X64Word_create(0x391c0cb3, 0xc5c95a63), 12406 X64Word_create(0x4ed8aa4a, 0xe3418acb), 12407 X64Word_create(0x5b9cca4f, 0x7763e373), 12408 X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12409 X64Word_create(0x748f82ee, 0x5defb2fc), 12410 X64Word_create(0x78a5636f, 0x43172f60), 12411 X64Word_create(0x84c87814, 0xa1f0ab72), 12412 X64Word_create(0x8cc70208, 0x1a6439ec), 12413 X64Word_create(0x90befffa, 0x23631e28), 12414 X64Word_create(0xa4506ceb, 0xde82bde9), 12415 X64Word_create(0xbef9a3f7, 0xb2c67915), 12416 X64Word_create(0xc67178f2, 0xe372532b), 12417 X64Word_create(0xca273ece, 0xea26619c), 12418 X64Word_create(0xd186b8c7, 0x21c0c207), 12419 X64Word_create(0xeada7dd6, 0xcde0eb1e), 12420 X64Word_create(0xf57d4f7f, 0xee6ed178), 12421 X64Word_create(0x06f067aa, 0x72176fba), 12422 X64Word_create(0x0a637dc5, 0xa2c898a6), 12423 X64Word_create(0x113f9804, 0xbef90dae), 12424 X64Word_create(0x1b710b35, 0x131c471b), 12425 X64Word_create(0x28db77f5, 0x23047d84), 12426 X64Word_create(0x32caab7b, 0x40c72493), 12427 X64Word_create(0x3c9ebe0a, 0x15c9bebc), 12428 X64Word_create(0x431d67c4, 0x9c100d4c), 12429 X64Word_create(0x4cc5d4be, 0xcb3e42b6), 12430 X64Word_create(0x597f299c, 0xfc657e2a), 12431 X64Word_create(0x5fcb6fab, 0x3ad6faec), 12432 X64Word_create(0x6c44198c, 0x4a475817), 12433 ]; 12434 12435 // Reusable objects 12436 var W = []; 12437 (function () { 12438 for (var i = 0; i < 80; i++) { 12439 W[i] = X64Word_create(); 12440 } 12441 })(); 12442 12443 /** 12444 * SHA-512 hash algorithm. 12445 */ 12446 var SHA512 = (C_algo.SHA512 = Hasher.extend({ 12447 _doReset: function () { 12448 this._hash = new X64WordArray.init([ 12449 new X64Word.init(0x6a09e667, 0xf3bcc908), 12450 new X64Word.init(0xbb67ae85, 0x84caa73b), 12451 new X64Word.init(0x3c6ef372, 0xfe94f82b), 12452 new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12453 new X64Word.init(0x510e527f, 0xade682d1), 12454 new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12455 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), 12456 new X64Word.init(0x5be0cd19, 0x137e2179), 12457 ]); 12458 }, 12459 12460 _doProcessBlock: function (M, offset) { 12461 // Shortcuts 12462 var H = this._hash.words; 12463 12464 var H0 = H[0]; 12465 var H1 = H[1]; 12466 var H2 = H[2]; 12467 var H3 = H[3]; 12468 var H4 = H[4]; 12469 var H5 = H[5]; 12470 var H6 = H[6]; 12471 var H7 = H[7]; 12472 12473 var H0h = H0.high; 12474 var H0l = H0.low; 12475 var H1h = H1.high; 12476 var H1l = H1.low; 12477 var H2h = H2.high; 12478 var H2l = H2.low; 12479 var H3h = H3.high; 12480 var H3l = H3.low; 12481 var H4h = H4.high; 12482 var H4l = H4.low; 12483 var H5h = H5.high; 12484 var H5l = H5.low; 12485 var H6h = H6.high; 12486 var H6l = H6.low; 12487 var H7h = H7.high; 12488 var H7l = H7.low; 12489 12490 // Working variables 12491 var ah = H0h; 12492 var al = H0l; 12493 var bh = H1h; 12494 var bl = H1l; 12495 var ch = H2h; 12496 var cl = H2l; 12497 var dh = H3h; 12498 var dl = H3l; 12499 var eh = H4h; 12500 var el = H4l; 12501 var fh = H5h; 12502 var fl = H5l; 12503 var gh = H6h; 12504 var gl = H6l; 12505 var hh = H7h; 12506 var hl = H7l; 12507 12508 // Rounds 12509 for (var i = 0; i < 80; i++) { 12510 // Shortcut 12511 var Wi = W[i]; 12512 12513 // Extend message 12514 if (i < 16) { 12515 var Wih = (Wi.high = M[offset + i * 2] | 0); 12516 var Wil = (Wi.low = M[offset + i * 2 + 1] | 0); 12517 } else { 12518 // Gamma0 12519 var gamma0x = W[i - 15]; 12520 var gamma0xh = gamma0x.high; 12521 var gamma0xl = gamma0x.low; 12522 var gamma0h = 12523 ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12524 var gamma0l = 12525 ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ 12526 ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ 12527 ((gamma0xl >>> 7) | (gamma0xh << 25)); 12528 12529 // Gamma1 12530 var gamma1x = W[i - 2]; 12531 var gamma1xh = gamma1x.high; 12532 var gamma1xl = gamma1x.low; 12533 var gamma1h = 12534 ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12535 var gamma1l = 12536 ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ 12537 ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ 12538 ((gamma1xl >>> 6) | (gamma1xh << 26)); 12539 12540 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12541 var Wi7 = W[i - 7]; 12542 var Wi7h = Wi7.high; 12543 var Wi7l = Wi7.low; 12544 12545 var Wi16 = W[i - 16]; 12546 var Wi16h = Wi16.high; 12547 var Wi16l = Wi16.low; 12548 12549 var Wil = gamma0l + Wi7l; 12550 var Wih = gamma0h + Wi7h + (Wil >>> 0 < gamma0l >>> 0 ? 1 : 0); 12551 var Wil = Wil + gamma1l; 12552 var Wih = Wih + gamma1h + (Wil >>> 0 < gamma1l >>> 0 ? 1 : 0); 12553 var Wil = Wil + Wi16l; 12554 var Wih = Wih + Wi16h + (Wil >>> 0 < Wi16l >>> 0 ? 1 : 0); 12555 12556 Wi.high = Wih; 12557 Wi.low = Wil; 12558 } 12559 12560 var chh = (eh & fh) ^ (~eh & gh); 12561 var chl = (el & fl) ^ (~el & gl); 12562 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12563 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12564 12565 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12566 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12567 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12568 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12569 12570 // t1 = h + sigma1 + ch + K[i] + W[i] 12571 var Ki = K[i]; 12572 var Kih = Ki.high; 12573 var Kil = Ki.low; 12574 12575 var t1l = hl + sigma1l; 12576 var t1h = hh + sigma1h + (t1l >>> 0 < hl >>> 0 ? 1 : 0); 12577 var t1l = t1l + chl; 12578 var t1h = t1h + chh + (t1l >>> 0 < chl >>> 0 ? 1 : 0); 12579 var t1l = t1l + Kil; 12580 var t1h = t1h + Kih + (t1l >>> 0 < Kil >>> 0 ? 1 : 0); 12581 var t1l = t1l + Wil; 12582 var t1h = t1h + Wih + (t1l >>> 0 < Wil >>> 0 ? 1 : 0); 12583 12584 // t2 = sigma0 + maj 12585 var t2l = sigma0l + majl; 12586 var t2h = sigma0h + majh + (t2l >>> 0 < sigma0l >>> 0 ? 1 : 0); 12587 12588 // Update working variables 12589 hh = gh; 12590 hl = gl; 12591 gh = fh; 12592 gl = fl; 12593 fh = eh; 12594 fl = el; 12595 el = (dl + t1l) | 0; 12596 eh = (dh + t1h + (el >>> 0 < dl >>> 0 ? 1 : 0)) | 0; 12597 dh = ch; 12598 dl = cl; 12599 ch = bh; 12600 cl = bl; 12601 bh = ah; 12602 bl = al; 12603 al = (t1l + t2l) | 0; 12604 ah = (t1h + t2h + (al >>> 0 < t1l >>> 0 ? 1 : 0)) | 0; 12605 } 12606 12607 // Intermediate hash value 12608 H0l = H0.low = H0l + al; 12609 H0.high = H0h + ah + (H0l >>> 0 < al >>> 0 ? 1 : 0); 12610 H1l = H1.low = H1l + bl; 12611 H1.high = H1h + bh + (H1l >>> 0 < bl >>> 0 ? 1 : 0); 12612 H2l = H2.low = H2l + cl; 12613 H2.high = H2h + ch + (H2l >>> 0 < cl >>> 0 ? 1 : 0); 12614 H3l = H3.low = H3l + dl; 12615 H3.high = H3h + dh + (H3l >>> 0 < dl >>> 0 ? 1 : 0); 12616 H4l = H4.low = H4l + el; 12617 H4.high = H4h + eh + (H4l >>> 0 < el >>> 0 ? 1 : 0); 12618 H5l = H5.low = H5l + fl; 12619 H5.high = H5h + fh + (H5l >>> 0 < fl >>> 0 ? 1 : 0); 12620 H6l = H6.low = H6l + gl; 12621 H6.high = H6h + gh + (H6l >>> 0 < gl >>> 0 ? 1 : 0); 12622 H7l = H7.low = H7l + hl; 12623 H7.high = H7h + hh + (H7l >>> 0 < hl >>> 0 ? 1 : 0); 12624 }, 12625 12626 _doFinalize: function () { 12627 // Shortcuts 12628 var data = this._data; 12629 var dataWords = data.words; 12630 12631 var nBitsTotal = this._nDataBytes * 8; 12632 var nBitsLeft = data.sigBytes * 8; 12633 12634 // Add padding 12635 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - (nBitsLeft % 32)); 12636 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12637 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12638 data.sigBytes = dataWords.length * 4; 12639 12640 // Hash final blocks 12641 this._process(); 12642 12643 // Convert hash to 32-bit word array before returning 12644 var hash = this._hash.toX32(); 12645 12646 // Return final computed hash 12647 return hash; 12648 }, 12649 12650 clone: function () { 12651 var clone = Hasher.clone.call(this); 12652 clone._hash = this._hash.clone(); 12653 12654 return clone; 12655 }, 12656 12657 blockSize: 1024 / 32, 12658 })); 12659 12660 /** 12661 * Shortcut function to the hasher's object interface. 12662 * 12663 * @param {WordArray|string} message The message to hash. 12664 * 12665 * @return {WordArray} The hash. 12666 * 12667 * @static 12668 * 12669 * @example 12670 * 12671 * var hash = CryptoJS.SHA512('message'); 12672 * var hash = CryptoJS.SHA512(wordArray); 12673 */ 12674 C.SHA512 = Hasher._createHelper(SHA512); 12675 12676 /** 12677 * Shortcut function to the HMAC's object interface. 12678 * 12679 * @param {WordArray|string} message The message to hash. 12680 * @param {WordArray|string} key The secret key. 12681 * 12682 * @return {WordArray} The HMAC. 12683 * 12684 * @static 12685 * 12686 * @example 12687 * 12688 * var hmac = CryptoJS.HmacSHA512(message, key); 12689 */ 12690 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12691 })(); 12692 12693 return CryptoJS.SHA512; 12694 }); 12695 }, 12696 { './core': 53, './x64-core': 84 }, 12697 ], 12698 83: [ 12699 function (require, module, exports) { 12700 (function (root, factory, undef) { 12701 if (typeof exports === 'object') { 12702 // CommonJS 12703 module.exports = exports = factory( 12704 require('./core'), 12705 require('./enc-base64'), 12706 require('./md5'), 12707 require('./evpkdf'), 12708 require('./cipher-core') 12709 ); 12710 } else if (typeof define === 'function' && define.amd) { 12711 // AMD 12712 define(['./core', './enc-base64', './md5', './evpkdf', './cipher-core'], factory); 12713 } else { 12714 // Global (browser) 12715 factory(root.CryptoJS); 12716 } 12717 })(this, function (CryptoJS) { 12718 (function () { 12719 // Shortcuts 12720 var C = CryptoJS; 12721 var C_lib = C.lib; 12722 var WordArray = C_lib.WordArray; 12723 var BlockCipher = C_lib.BlockCipher; 12724 var C_algo = C.algo; 12725 12726 // Permuted Choice 1 constants 12727 var PC1 = [ 12728 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 12729 36, 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12730 12, 4, 12731 ]; 12732 12733 // Permuted Choice 2 constants 12734 var PC2 = [ 12735 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10, 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2, 41, 52, 31, 37, 12736 47, 55, 30, 40, 51, 45, 33, 48, 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32, 12737 ]; 12738 12739 // Cumulative bit shift constants 12740 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12741 12742 // SBOXes and round permutation constants 12743 var SBOX_P = [ 12744 { 12745 0x0: 0x808200, 12746 0x10000000: 0x8000, 12747 0x20000000: 0x808002, 12748 0x30000000: 0x2, 12749 0x40000000: 0x200, 12750 0x50000000: 0x808202, 12751 0x60000000: 0x800202, 12752 0x70000000: 0x800000, 12753 0x80000000: 0x202, 12754 0x90000000: 0x800200, 12755 0xa0000000: 0x8200, 12756 0xb0000000: 0x808000, 12757 0xc0000000: 0x8002, 12758 0xd0000000: 0x800002, 12759 0xe0000000: 0x0, 12760 0xf0000000: 0x8202, 12761 0x8000000: 0x0, 12762 0x18000000: 0x808202, 12763 0x28000000: 0x8202, 12764 0x38000000: 0x8000, 12765 0x48000000: 0x808200, 12766 0x58000000: 0x200, 12767 0x68000000: 0x808002, 12768 0x78000000: 0x2, 12769 0x88000000: 0x800200, 12770 0x98000000: 0x8200, 12771 0xa8000000: 0x808000, 12772 0xb8000000: 0x800202, 12773 0xc8000000: 0x800002, 12774 0xd8000000: 0x8002, 12775 0xe8000000: 0x202, 12776 0xf8000000: 0x800000, 12777 0x1: 0x8000, 12778 0x10000001: 0x2, 12779 0x20000001: 0x808200, 12780 0x30000001: 0x800000, 12781 0x40000001: 0x808002, 12782 0x50000001: 0x8200, 12783 0x60000001: 0x200, 12784 0x70000001: 0x800202, 12785 0x80000001: 0x808202, 12786 0x90000001: 0x808000, 12787 0xa0000001: 0x800002, 12788 0xb0000001: 0x8202, 12789 0xc0000001: 0x202, 12790 0xd0000001: 0x800200, 12791 0xe0000001: 0x8002, 12792 0xf0000001: 0x0, 12793 0x8000001: 0x808202, 12794 0x18000001: 0x808000, 12795 0x28000001: 0x800000, 12796 0x38000001: 0x200, 12797 0x48000001: 0x8000, 12798 0x58000001: 0x800002, 12799 0x68000001: 0x2, 12800 0x78000001: 0x8202, 12801 0x88000001: 0x8002, 12802 0x98000001: 0x800202, 12803 0xa8000001: 0x202, 12804 0xb8000001: 0x808200, 12805 0xc8000001: 0x800200, 12806 0xd8000001: 0x0, 12807 0xe8000001: 0x8200, 12808 0xf8000001: 0x808002, 12809 }, 12810 { 12811 0x0: 0x40084010, 12812 0x1000000: 0x4000, 12813 0x2000000: 0x80000, 12814 0x3000000: 0x40080010, 12815 0x4000000: 0x40000010, 12816 0x5000000: 0x40084000, 12817 0x6000000: 0x40004000, 12818 0x7000000: 0x10, 12819 0x8000000: 0x84000, 12820 0x9000000: 0x40004010, 12821 0xa000000: 0x40000000, 12822 0xb000000: 0x84010, 12823 0xc000000: 0x80010, 12824 0xd000000: 0x0, 12825 0xe000000: 0x4010, 12826 0xf000000: 0x40080000, 12827 0x800000: 0x40004000, 12828 0x1800000: 0x84010, 12829 0x2800000: 0x10, 12830 0x3800000: 0x40004010, 12831 0x4800000: 0x40084010, 12832 0x5800000: 0x40000000, 12833 0x6800000: 0x80000, 12834 0x7800000: 0x40080010, 12835 0x8800000: 0x80010, 12836 0x9800000: 0x0, 12837 0xa800000: 0x4000, 12838 0xb800000: 0x40080000, 12839 0xc800000: 0x40000010, 12840 0xd800000: 0x84000, 12841 0xe800000: 0x40084000, 12842 0xf800000: 0x4010, 12843 0x10000000: 0x0, 12844 0x11000000: 0x40080010, 12845 0x12000000: 0x40004010, 12846 0x13000000: 0x40084000, 12847 0x14000000: 0x40080000, 12848 0x15000000: 0x10, 12849 0x16000000: 0x84010, 12850 0x17000000: 0x4000, 12851 0x18000000: 0x4010, 12852 0x19000000: 0x80000, 12853 0x1a000000: 0x80010, 12854 0x1b000000: 0x40000010, 12855 0x1c000000: 0x84000, 12856 0x1d000000: 0x40004000, 12857 0x1e000000: 0x40000000, 12858 0x1f000000: 0x40084010, 12859 0x10800000: 0x84010, 12860 0x11800000: 0x80000, 12861 0x12800000: 0x40080000, 12862 0x13800000: 0x4000, 12863 0x14800000: 0x40004000, 12864 0x15800000: 0x40084010, 12865 0x16800000: 0x10, 12866 0x17800000: 0x40000000, 12867 0x18800000: 0x40084000, 12868 0x19800000: 0x40000010, 12869 0x1a800000: 0x40004010, 12870 0x1b800000: 0x80010, 12871 0x1c800000: 0x0, 12872 0x1d800000: 0x4010, 12873 0x1e800000: 0x40080010, 12874 0x1f800000: 0x84000, 12875 }, 12876 { 12877 0x0: 0x104, 12878 0x100000: 0x0, 12879 0x200000: 0x4000100, 12880 0x300000: 0x10104, 12881 0x400000: 0x10004, 12882 0x500000: 0x4000004, 12883 0x600000: 0x4010104, 12884 0x700000: 0x4010000, 12885 0x800000: 0x4000000, 12886 0x900000: 0x4010100, 12887 0xa00000: 0x10100, 12888 0xb00000: 0x4010004, 12889 0xc00000: 0x4000104, 12890 0xd00000: 0x10000, 12891 0xe00000: 0x4, 12892 0xf00000: 0x100, 12893 0x80000: 0x4010100, 12894 0x180000: 0x4010004, 12895 0x280000: 0x0, 12896 0x380000: 0x4000100, 12897 0x480000: 0x4000004, 12898 0x580000: 0x10000, 12899 0x680000: 0x10004, 12900 0x780000: 0x104, 12901 0x880000: 0x4, 12902 0x980000: 0x100, 12903 0xa80000: 0x4010000, 12904 0xb80000: 0x10104, 12905 0xc80000: 0x10100, 12906 0xd80000: 0x4000104, 12907 0xe80000: 0x4010104, 12908 0xf80000: 0x4000000, 12909 0x1000000: 0x4010100, 12910 0x1100000: 0x10004, 12911 0x1200000: 0x10000, 12912 0x1300000: 0x4000100, 12913 0x1400000: 0x100, 12914 0x1500000: 0x4010104, 12915 0x1600000: 0x4000004, 12916 0x1700000: 0x0, 12917 0x1800000: 0x4000104, 12918 0x1900000: 0x4000000, 12919 0x1a00000: 0x4, 12920 0x1b00000: 0x10100, 12921 0x1c00000: 0x4010000, 12922 0x1d00000: 0x104, 12923 0x1e00000: 0x10104, 12924 0x1f00000: 0x4010004, 12925 0x1080000: 0x4000000, 12926 0x1180000: 0x104, 12927 0x1280000: 0x4010100, 12928 0x1380000: 0x0, 12929 0x1480000: 0x10004, 12930 0x1580000: 0x4000100, 12931 0x1680000: 0x100, 12932 0x1780000: 0x4010004, 12933 0x1880000: 0x10000, 12934 0x1980000: 0x4010104, 12935 0x1a80000: 0x10104, 12936 0x1b80000: 0x4000004, 12937 0x1c80000: 0x4000104, 12938 0x1d80000: 0x4010000, 12939 0x1e80000: 0x4, 12940 0x1f80000: 0x10100, 12941 }, 12942 { 12943 0x0: 0x80401000, 12944 0x10000: 0x80001040, 12945 0x20000: 0x401040, 12946 0x30000: 0x80400000, 12947 0x40000: 0x0, 12948 0x50000: 0x401000, 12949 0x60000: 0x80000040, 12950 0x70000: 0x400040, 12951 0x80000: 0x80000000, 12952 0x90000: 0x400000, 12953 0xa0000: 0x40, 12954 0xb0000: 0x80001000, 12955 0xc0000: 0x80400040, 12956 0xd0000: 0x1040, 12957 0xe0000: 0x1000, 12958 0xf0000: 0x80401040, 12959 0x8000: 0x80001040, 12960 0x18000: 0x40, 12961 0x28000: 0x80400040, 12962 0x38000: 0x80001000, 12963 0x48000: 0x401000, 12964 0x58000: 0x80401040, 12965 0x68000: 0x0, 12966 0x78000: 0x80400000, 12967 0x88000: 0x1000, 12968 0x98000: 0x80401000, 12969 0xa8000: 0x400000, 12970 0xb8000: 0x1040, 12971 0xc8000: 0x80000000, 12972 0xd8000: 0x400040, 12973 0xe8000: 0x401040, 12974 0xf8000: 0x80000040, 12975 0x100000: 0x400040, 12976 0x110000: 0x401000, 12977 0x120000: 0x80000040, 12978 0x130000: 0x0, 12979 0x140000: 0x1040, 12980 0x150000: 0x80400040, 12981 0x160000: 0x80401000, 12982 0x170000: 0x80001040, 12983 0x180000: 0x80401040, 12984 0x190000: 0x80000000, 12985 0x1a0000: 0x80400000, 12986 0x1b0000: 0x401040, 12987 0x1c0000: 0x80001000, 12988 0x1d0000: 0x400000, 12989 0x1e0000: 0x40, 12990 0x1f0000: 0x1000, 12991 0x108000: 0x80400000, 12992 0x118000: 0x80401040, 12993 0x128000: 0x0, 12994 0x138000: 0x401000, 12995 0x148000: 0x400040, 12996 0x158000: 0x80000000, 12997 0x168000: 0x80001040, 12998 0x178000: 0x40, 12999 0x188000: 0x80000040, 13000 0x198000: 0x1000, 13001 0x1a8000: 0x80001000, 13002 0x1b8000: 0x80400040, 13003 0x1c8000: 0x1040, 13004 0x1d8000: 0x80401000, 13005 0x1e8000: 0x400000, 13006 0x1f8000: 0x401040, 13007 }, 13008 { 13009 0x0: 0x80, 13010 0x1000: 0x1040000, 13011 0x2000: 0x40000, 13012 0x3000: 0x20000000, 13013 0x4000: 0x20040080, 13014 0x5000: 0x1000080, 13015 0x6000: 0x21000080, 13016 0x7000: 0x40080, 13017 0x8000: 0x1000000, 13018 0x9000: 0x20040000, 13019 0xa000: 0x20000080, 13020 0xb000: 0x21040080, 13021 0xc000: 0x21040000, 13022 0xd000: 0x0, 13023 0xe000: 0x1040080, 13024 0xf000: 0x21000000, 13025 0x800: 0x1040080, 13026 0x1800: 0x21000080, 13027 0x2800: 0x80, 13028 0x3800: 0x1040000, 13029 0x4800: 0x40000, 13030 0x5800: 0x20040080, 13031 0x6800: 0x21040000, 13032 0x7800: 0x20000000, 13033 0x8800: 0x20040000, 13034 0x9800: 0x0, 13035 0xa800: 0x21040080, 13036 0xb800: 0x1000080, 13037 0xc800: 0x20000080, 13038 0xd800: 0x21000000, 13039 0xe800: 0x1000000, 13040 0xf800: 0x40080, 13041 0x10000: 0x40000, 13042 0x11000: 0x80, 13043 0x12000: 0x20000000, 13044 0x13000: 0x21000080, 13045 0x14000: 0x1000080, 13046 0x15000: 0x21040000, 13047 0x16000: 0x20040080, 13048 0x17000: 0x1000000, 13049 0x18000: 0x21040080, 13050 0x19000: 0x21000000, 13051 0x1a000: 0x1040000, 13052 0x1b000: 0x20040000, 13053 0x1c000: 0x40080, 13054 0x1d000: 0x20000080, 13055 0x1e000: 0x0, 13056 0x1f000: 0x1040080, 13057 0x10800: 0x21000080, 13058 0x11800: 0x1000000, 13059 0x12800: 0x1040000, 13060 0x13800: 0x20040080, 13061 0x14800: 0x20000000, 13062 0x15800: 0x1040080, 13063 0x16800: 0x80, 13064 0x17800: 0x21040000, 13065 0x18800: 0x40080, 13066 0x19800: 0x21040080, 13067 0x1a800: 0x0, 13068 0x1b800: 0x21000000, 13069 0x1c800: 0x1000080, 13070 0x1d800: 0x40000, 13071 0x1e800: 0x20040000, 13072 0x1f800: 0x20000080, 13073 }, 13074 { 13075 0x0: 0x10000008, 13076 0x100: 0x2000, 13077 0x200: 0x10200000, 13078 0x300: 0x10202008, 13079 0x400: 0x10002000, 13080 0x500: 0x200000, 13081 0x600: 0x200008, 13082 0x700: 0x10000000, 13083 0x800: 0x0, 13084 0x900: 0x10002008, 13085 0xa00: 0x202000, 13086 0xb00: 0x8, 13087 0xc00: 0x10200008, 13088 0xd00: 0x202008, 13089 0xe00: 0x2008, 13090 0xf00: 0x10202000, 13091 0x80: 0x10200000, 13092 0x180: 0x10202008, 13093 0x280: 0x8, 13094 0x380: 0x200000, 13095 0x480: 0x202008, 13096 0x580: 0x10000008, 13097 0x680: 0x10002000, 13098 0x780: 0x2008, 13099 0x880: 0x200008, 13100 0x980: 0x2000, 13101 0xa80: 0x10002008, 13102 0xb80: 0x10200008, 13103 0xc80: 0x0, 13104 0xd80: 0x10202000, 13105 0xe80: 0x202000, 13106 0xf80: 0x10000000, 13107 0x1000: 0x10002000, 13108 0x1100: 0x10200008, 13109 0x1200: 0x10202008, 13110 0x1300: 0x2008, 13111 0x1400: 0x200000, 13112 0x1500: 0x10000000, 13113 0x1600: 0x10000008, 13114 0x1700: 0x202000, 13115 0x1800: 0x202008, 13116 0x1900: 0x0, 13117 0x1a00: 0x8, 13118 0x1b00: 0x10200000, 13119 0x1c00: 0x2000, 13120 0x1d00: 0x10002008, 13121 0x1e00: 0x10202000, 13122 0x1f00: 0x200008, 13123 0x1080: 0x8, 13124 0x1180: 0x202000, 13125 0x1280: 0x200000, 13126 0x1380: 0x10000008, 13127 0x1480: 0x10002000, 13128 0x1580: 0x2008, 13129 0x1680: 0x10202008, 13130 0x1780: 0x10200000, 13131 0x1880: 0x10202000, 13132 0x1980: 0x10200008, 13133 0x1a80: 0x2000, 13134 0x1b80: 0x202008, 13135 0x1c80: 0x200008, 13136 0x1d80: 0x0, 13137 0x1e80: 0x10000000, 13138 0x1f80: 0x10002008, 13139 }, 13140 { 13141 0x0: 0x100000, 13142 0x10: 0x2000401, 13143 0x20: 0x400, 13144 0x30: 0x100401, 13145 0x40: 0x2100401, 13146 0x50: 0x0, 13147 0x60: 0x1, 13148 0x70: 0x2100001, 13149 0x80: 0x2000400, 13150 0x90: 0x100001, 13151 0xa0: 0x2000001, 13152 0xb0: 0x2100400, 13153 0xc0: 0x2100000, 13154 0xd0: 0x401, 13155 0xe0: 0x100400, 13156 0xf0: 0x2000000, 13157 0x8: 0x2100001, 13158 0x18: 0x0, 13159 0x28: 0x2000401, 13160 0x38: 0x2100400, 13161 0x48: 0x100000, 13162 0x58: 0x2000001, 13163 0x68: 0x2000000, 13164 0x78: 0x401, 13165 0x88: 0x100401, 13166 0x98: 0x2000400, 13167 0xa8: 0x2100000, 13168 0xb8: 0x100001, 13169 0xc8: 0x400, 13170 0xd8: 0x2100401, 13171 0xe8: 0x1, 13172 0xf8: 0x100400, 13173 0x100: 0x2000000, 13174 0x110: 0x100000, 13175 0x120: 0x2000401, 13176 0x130: 0x2100001, 13177 0x140: 0x100001, 13178 0x150: 0x2000400, 13179 0x160: 0x2100400, 13180 0x170: 0x100401, 13181 0x180: 0x401, 13182 0x190: 0x2100401, 13183 0x1a0: 0x100400, 13184 0x1b0: 0x1, 13185 0x1c0: 0x0, 13186 0x1d0: 0x2100000, 13187 0x1e0: 0x2000001, 13188 0x1f0: 0x400, 13189 0x108: 0x100400, 13190 0x118: 0x2000401, 13191 0x128: 0x2100001, 13192 0x138: 0x1, 13193 0x148: 0x2000000, 13194 0x158: 0x100000, 13195 0x168: 0x401, 13196 0x178: 0x2100400, 13197 0x188: 0x2000001, 13198 0x198: 0x2100000, 13199 0x1a8: 0x0, 13200 0x1b8: 0x2100401, 13201 0x1c8: 0x100401, 13202 0x1d8: 0x400, 13203 0x1e8: 0x2000400, 13204 0x1f8: 0x100001, 13205 }, 13206 { 13207 0x0: 0x8000820, 13208 0x1: 0x20000, 13209 0x2: 0x8000000, 13210 0x3: 0x20, 13211 0x4: 0x20020, 13212 0x5: 0x8020820, 13213 0x6: 0x8020800, 13214 0x7: 0x800, 13215 0x8: 0x8020000, 13216 0x9: 0x8000800, 13217 0xa: 0x20800, 13218 0xb: 0x8020020, 13219 0xc: 0x820, 13220 0xd: 0x0, 13221 0xe: 0x8000020, 13222 0xf: 0x20820, 13223 0x80000000: 0x800, 13224 0x80000001: 0x8020820, 13225 0x80000002: 0x8000820, 13226 0x80000003: 0x8000000, 13227 0x80000004: 0x8020000, 13228 0x80000005: 0x20800, 13229 0x80000006: 0x20820, 13230 0x80000007: 0x20, 13231 0x80000008: 0x8000020, 13232 0x80000009: 0x820, 13233 0x8000000a: 0x20020, 13234 0x8000000b: 0x8020800, 13235 0x8000000c: 0x0, 13236 0x8000000d: 0x8020020, 13237 0x8000000e: 0x8000800, 13238 0x8000000f: 0x20000, 13239 0x10: 0x20820, 13240 0x11: 0x8020800, 13241 0x12: 0x20, 13242 0x13: 0x800, 13243 0x14: 0x8000800, 13244 0x15: 0x8000020, 13245 0x16: 0x8020020, 13246 0x17: 0x20000, 13247 0x18: 0x0, 13248 0x19: 0x20020, 13249 0x1a: 0x8020000, 13250 0x1b: 0x8000820, 13251 0x1c: 0x8020820, 13252 0x1d: 0x20800, 13253 0x1e: 0x820, 13254 0x1f: 0x8000000, 13255 0x80000010: 0x20000, 13256 0x80000011: 0x800, 13257 0x80000012: 0x8020020, 13258 0x80000013: 0x20820, 13259 0x80000014: 0x20, 13260 0x80000015: 0x8020000, 13261 0x80000016: 0x8000000, 13262 0x80000017: 0x8000820, 13263 0x80000018: 0x8020820, 13264 0x80000019: 0x8000020, 13265 0x8000001a: 0x8000800, 13266 0x8000001b: 0x0, 13267 0x8000001c: 0x20800, 13268 0x8000001d: 0x820, 13269 0x8000001e: 0x20020, 13270 0x8000001f: 0x8020800, 13271 }, 13272 ]; 13273 13274 // Masks that select the SBOX input 13275 var SBOX_MASK = [ 13276 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f, 13277 ]; 13278 13279 /** 13280 * DES block cipher algorithm. 13281 */ 13282 var DES = (C_algo.DES = BlockCipher.extend({ 13283 _doReset: function () { 13284 // Shortcuts 13285 var key = this._key; 13286 var keyWords = key.words; 13287 13288 // Select 56 bits according to PC1 13289 var keyBits = []; 13290 for (var i = 0; i < 56; i++) { 13291 var keyBitPos = PC1[i] - 1; 13292 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - (keyBitPos % 32))) & 1; 13293 } 13294 13295 // Assemble 16 subkeys 13296 var subKeys = (this._subKeys = []); 13297 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 13298 // Create subkey 13299 var subKey = (subKeys[nSubKey] = []); 13300 13301 // Shortcut 13302 var bitShift = BIT_SHIFTS[nSubKey]; 13303 13304 // Select 48 bits according to PC2 13305 for (var i = 0; i < 24; i++) { 13306 // Select from the left 28 key bits 13307 subKey[(i / 6) | 0] |= keyBits[(PC2[i] - 1 + bitShift) % 28] << (31 - (i % 6)); 13308 13309 // Select from the right 28 key bits 13310 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + ((PC2[i + 24] - 1 + bitShift) % 28)] << (31 - (i % 6)); 13311 } 13312 13313 // Since each subkey is applied to an expanded 32-bit input, 13314 // the subkey can be broken into 8 values scaled to 32-bits, 13315 // which allows the key to be used without expansion 13316 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 13317 for (var i = 1; i < 7; i++) { 13318 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 13319 } 13320 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 13321 } 13322 13323 // Compute inverse subkeys 13324 var invSubKeys = (this._invSubKeys = []); 13325 for (var i = 0; i < 16; i++) { 13326 invSubKeys[i] = subKeys[15 - i]; 13327 } 13328 }, 13329 13330 encryptBlock: function (M, offset) { 13331 this._doCryptBlock(M, offset, this._subKeys); 13332 }, 13333 13334 decryptBlock: function (M, offset) { 13335 this._doCryptBlock(M, offset, this._invSubKeys); 13336 }, 13337 13338 _doCryptBlock: function (M, offset, subKeys) { 13339 // Get input 13340 this._lBlock = M[offset]; 13341 this._rBlock = M[offset + 1]; 13342 13343 // Initial permutation 13344 exchangeLR.call(this, 4, 0x0f0f0f0f); 13345 exchangeLR.call(this, 16, 0x0000ffff); 13346 exchangeRL.call(this, 2, 0x33333333); 13347 exchangeRL.call(this, 8, 0x00ff00ff); 13348 exchangeLR.call(this, 1, 0x55555555); 13349 13350 // Rounds 13351 for (var round = 0; round < 16; round++) { 13352 // Shortcuts 13353 var subKey = subKeys[round]; 13354 var lBlock = this._lBlock; 13355 var rBlock = this._rBlock; 13356 13357 // Feistel function 13358 var f = 0; 13359 for (var i = 0; i < 8; i++) { 13360 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 13361 } 13362 this._lBlock = rBlock; 13363 this._rBlock = lBlock ^ f; 13364 } 13365 13366 // Undo swap from last round 13367 var t = this._lBlock; 13368 this._lBlock = this._rBlock; 13369 this._rBlock = t; 13370 13371 // Final permutation 13372 exchangeLR.call(this, 1, 0x55555555); 13373 exchangeRL.call(this, 8, 0x00ff00ff); 13374 exchangeRL.call(this, 2, 0x33333333); 13375 exchangeLR.call(this, 16, 0x0000ffff); 13376 exchangeLR.call(this, 4, 0x0f0f0f0f); 13377 13378 // Set output 13379 M[offset] = this._lBlock; 13380 M[offset + 1] = this._rBlock; 13381 }, 13382 13383 keySize: 64 / 32, 13384 13385 ivSize: 64 / 32, 13386 13387 blockSize: 64 / 32, 13388 })); 13389 13390 // Swap bits across the left and right words 13391 function exchangeLR(offset, mask) { 13392 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13393 this._rBlock ^= t; 13394 this._lBlock ^= t << offset; 13395 } 13396 13397 function exchangeRL(offset, mask) { 13398 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13399 this._lBlock ^= t; 13400 this._rBlock ^= t << offset; 13401 } 13402 13403 /** 13404 * Shortcut functions to the cipher's object interface. 13405 * 13406 * @example 13407 * 13408 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13409 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13410 */ 13411 C.DES = BlockCipher._createHelper(DES); 13412 13413 /** 13414 * Triple-DES block cipher algorithm. 13415 */ 13416 var TripleDES = (C_algo.TripleDES = BlockCipher.extend({ 13417 _doReset: function () { 13418 // Shortcuts 13419 var key = this._key; 13420 var keyWords = key.words; 13421 13422 // Create DES instances 13423 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13424 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13425 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13426 }, 13427 13428 encryptBlock: function (M, offset) { 13429 this._des1.encryptBlock(M, offset); 13430 this._des2.decryptBlock(M, offset); 13431 this._des3.encryptBlock(M, offset); 13432 }, 13433 13434 decryptBlock: function (M, offset) { 13435 this._des3.decryptBlock(M, offset); 13436 this._des2.encryptBlock(M, offset); 13437 this._des1.decryptBlock(M, offset); 13438 }, 13439 13440 keySize: 192 / 32, 13441 13442 ivSize: 64 / 32, 13443 13444 blockSize: 64 / 32, 13445 })); 13446 13447 /** 13448 * Shortcut functions to the cipher's object interface. 13449 * 13450 * @example 13451 * 13452 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13453 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13454 */ 13455 C.TripleDES = BlockCipher._createHelper(TripleDES); 13456 })(); 13457 13458 return CryptoJS.TripleDES; 13459 }); 13460 }, 13461 { './cipher-core': 52, './core': 53, './enc-base64': 54, './evpkdf': 56, './md5': 61 }, 13462 ], 13463 84: [ 13464 function (require, module, exports) { 13465 (function (root, factory) { 13466 if (typeof exports === 'object') { 13467 // CommonJS 13468 module.exports = exports = factory(require('./core')); 13469 } else if (typeof define === 'function' && define.amd) { 13470 // AMD 13471 define(['./core'], factory); 13472 } else { 13473 // Global (browser) 13474 factory(root.CryptoJS); 13475 } 13476 })(this, function (CryptoJS) { 13477 (function (undefined) { 13478 // Shortcuts 13479 var C = CryptoJS; 13480 var C_lib = C.lib; 13481 var Base = C_lib.Base; 13482 var X32WordArray = C_lib.WordArray; 13483 13484 /** 13485 * x64 namespace. 13486 */ 13487 var C_x64 = (C.x64 = {}); 13488 13489 /** 13490 * A 64-bit word. 13491 */ 13492 var X64Word = (C_x64.Word = Base.extend({ 13493 /** 13494 * Initializes a newly created 64-bit word. 13495 * 13496 * @param {number} high The high 32 bits. 13497 * @param {number} low The low 32 bits. 13498 * 13499 * @example 13500 * 13501 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13502 */ 13503 init: function (high, low) { 13504 this.high = high; 13505 this.low = low; 13506 }, 13507 13508 /** 13509 * Bitwise NOTs this word. 13510 * 13511 * @return {X64Word} A new x64-Word object after negating. 13512 * 13513 * @example 13514 * 13515 * var negated = x64Word.not(); 13516 */ 13517 // not: function () { 13518 // var high = ~this.high; 13519 // var low = ~this.low; 13520 13521 // return X64Word.create(high, low); 13522 // }, 13523 13524 /** 13525 * Bitwise ANDs this word with the passed word. 13526 * 13527 * @param {X64Word} word The x64-Word to AND with this word. 13528 * 13529 * @return {X64Word} A new x64-Word object after ANDing. 13530 * 13531 * @example 13532 * 13533 * var anded = x64Word.and(anotherX64Word); 13534 */ 13535 // and: function (word) { 13536 // var high = this.high & word.high; 13537 // var low = this.low & word.low; 13538 13539 // return X64Word.create(high, low); 13540 // }, 13541 13542 /** 13543 * Bitwise ORs this word with the passed word. 13544 * 13545 * @param {X64Word} word The x64-Word to OR with this word. 13546 * 13547 * @return {X64Word} A new x64-Word object after ORing. 13548 * 13549 * @example 13550 * 13551 * var ored = x64Word.or(anotherX64Word); 13552 */ 13553 // or: function (word) { 13554 // var high = this.high | word.high; 13555 // var low = this.low | word.low; 13556 13557 // return X64Word.create(high, low); 13558 // }, 13559 13560 /** 13561 * Bitwise XORs this word with the passed word. 13562 * 13563 * @param {X64Word} word The x64-Word to XOR with this word. 13564 * 13565 * @return {X64Word} A new x64-Word object after XORing. 13566 * 13567 * @example 13568 * 13569 * var xored = x64Word.xor(anotherX64Word); 13570 */ 13571 // xor: function (word) { 13572 // var high = this.high ^ word.high; 13573 // var low = this.low ^ word.low; 13574 13575 // return X64Word.create(high, low); 13576 // }, 13577 13578 /** 13579 * Shifts this word n bits to the left. 13580 * 13581 * @param {number} n The number of bits to shift. 13582 * 13583 * @return {X64Word} A new x64-Word object after shifting. 13584 * 13585 * @example 13586 * 13587 * var shifted = x64Word.shiftL(25); 13588 */ 13589 // shiftL: function (n) { 13590 // if (n < 32) { 13591 // var high = (this.high << n) | (this.low >>> (32 - n)); 13592 // var low = this.low << n; 13593 // } else { 13594 // var high = this.low << (n - 32); 13595 // var low = 0; 13596 // } 13597 13598 // return X64Word.create(high, low); 13599 // }, 13600 13601 /** 13602 * Shifts this word n bits to the right. 13603 * 13604 * @param {number} n The number of bits to shift. 13605 * 13606 * @return {X64Word} A new x64-Word object after shifting. 13607 * 13608 * @example 13609 * 13610 * var shifted = x64Word.shiftR(7); 13611 */ 13612 // shiftR: function (n) { 13613 // if (n < 32) { 13614 // var low = (this.low >>> n) | (this.high << (32 - n)); 13615 // var high = this.high >>> n; 13616 // } else { 13617 // var low = this.high >>> (n - 32); 13618 // var high = 0; 13619 // } 13620 13621 // return X64Word.create(high, low); 13622 // }, 13623 13624 /** 13625 * Rotates this word n bits to the left. 13626 * 13627 * @param {number} n The number of bits to rotate. 13628 * 13629 * @return {X64Word} A new x64-Word object after rotating. 13630 * 13631 * @example 13632 * 13633 * var rotated = x64Word.rotL(25); 13634 */ 13635 // rotL: function (n) { 13636 // return this.shiftL(n).or(this.shiftR(64 - n)); 13637 // }, 13638 13639 /** 13640 * Rotates this word n bits to the right. 13641 * 13642 * @param {number} n The number of bits to rotate. 13643 * 13644 * @return {X64Word} A new x64-Word object after rotating. 13645 * 13646 * @example 13647 * 13648 * var rotated = x64Word.rotR(7); 13649 */ 13650 // rotR: function (n) { 13651 // return this.shiftR(n).or(this.shiftL(64 - n)); 13652 // }, 13653 13654 /** 13655 * Adds this word with the passed word. 13656 * 13657 * @param {X64Word} word The x64-Word to add with this word. 13658 * 13659 * @return {X64Word} A new x64-Word object after adding. 13660 * 13661 * @example 13662 * 13663 * var added = x64Word.add(anotherX64Word); 13664 */ 13665 // add: function (word) { 13666 // var low = (this.low + word.low) | 0; 13667 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13668 // var high = (this.high + word.high + carry) | 0; 13669 13670 // return X64Word.create(high, low); 13671 // } 13672 })); 13673 13674 /** 13675 * An array of 64-bit words. 13676 * 13677 * @property {Array} words The array of CryptoJS.x64.Word objects. 13678 * @property {number} sigBytes The number of significant bytes in this word array. 13679 */ 13680 var X64WordArray = (C_x64.WordArray = Base.extend({ 13681 /** 13682 * Initializes a newly created word array. 13683 * 13684 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13685 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13686 * 13687 * @example 13688 * 13689 * var wordArray = CryptoJS.x64.WordArray.create(); 13690 * 13691 * var wordArray = CryptoJS.x64.WordArray.create([ 13692 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13693 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13694 * ]); 13695 * 13696 * var wordArray = CryptoJS.x64.WordArray.create([ 13697 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13698 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13699 * ], 10); 13700 */ 13701 init: function (words, sigBytes) { 13702 words = this.words = words || []; 13703 13704 if (sigBytes != undefined) { 13705 this.sigBytes = sigBytes; 13706 } else { 13707 this.sigBytes = words.length * 8; 13708 } 13709 }, 13710 13711 /** 13712 * Converts this 64-bit word array to a 32-bit word array. 13713 * 13714 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13715 * 13716 * @example 13717 * 13718 * var x32WordArray = x64WordArray.toX32(); 13719 */ 13720 toX32: function () { 13721 // Shortcuts 13722 var x64Words = this.words; 13723 var x64WordsLength = x64Words.length; 13724 13725 // Convert 13726 var x32Words = []; 13727 for (var i = 0; i < x64WordsLength; i++) { 13728 var x64Word = x64Words[i]; 13729 x32Words.push(x64Word.high); 13730 x32Words.push(x64Word.low); 13731 } 13732 13733 return X32WordArray.create(x32Words, this.sigBytes); 13734 }, 13735 13736 /** 13737 * Creates a copy of this word array. 13738 * 13739 * @return {X64WordArray} The clone. 13740 * 13741 * @example 13742 * 13743 * var clone = x64WordArray.clone(); 13744 */ 13745 clone: function () { 13746 var clone = Base.clone.call(this); 13747 13748 // Clone "words" array 13749 var words = (clone.words = this.words.slice(0)); 13750 13751 // Clone each X64Word object 13752 var wordsLength = words.length; 13753 for (var i = 0; i < wordsLength; i++) { 13754 words[i] = words[i].clone(); 13755 } 13756 13757 return clone; 13758 }, 13759 })); 13760 })(); 13761 13762 return CryptoJS; 13763 }); 13764 }, 13765 { './core': 53 }, 13766 ], 13767 85: [ 13768 function (require, module, exports) { 13769 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13770 (function (root) { 13771 // Detect free variables `exports` 13772 var freeExports = typeof exports == 'object' && exports; 13773 13774 // Detect free variable `module` 13775 var freeModule = typeof module == 'object' && module && module.exports == freeExports && module; 13776 13777 // Detect free variable `global`, from Node.js or Browserified code, 13778 // and use it as `root` 13779 var freeGlobal = typeof global == 'object' && global; 13780 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13781 root = freeGlobal; 13782 } 13783 13784 /*--------------------------------------------------------------------------*/ 13785 13786 var stringFromCharCode = String.fromCharCode; 13787 13788 // Taken from https://mths.be/punycode 13789 function ucs2decode(string) { 13790 var output = []; 13791 var counter = 0; 13792 var length = string.length; 13793 var value; 13794 var extra; 13795 while (counter < length) { 13796 value = string.charCodeAt(counter++); 13797 if (value >= 0xd800 && value <= 0xdbff && counter < length) { 13798 // high surrogate, and there is a next character 13799 extra = string.charCodeAt(counter++); 13800 if ((extra & 0xfc00) == 0xdc00) { 13801 // low surrogate 13802 output.push(((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000); 13803 } else { 13804 // unmatched surrogate; only append this code unit, in case the next 13805 // code unit is the high surrogate of a surrogate pair 13806 output.push(value); 13807 counter--; 13808 } 13809 } else { 13810 output.push(value); 13811 } 13812 } 13813 return output; 13814 } 13815 13816 // Taken from https://mths.be/punycode 13817 function ucs2encode(array) { 13818 var length = array.length; 13819 var index = -1; 13820 var value; 13821 var output = ''; 13822 while (++index < length) { 13823 value = array[index]; 13824 if (value > 0xffff) { 13825 value -= 0x10000; 13826 output += stringFromCharCode(((value >>> 10) & 0x3ff) | 0xd800); 13827 value = 0xdc00 | (value & 0x3ff); 13828 } 13829 output += stringFromCharCode(value); 13830 } 13831 return output; 13832 } 13833 13834 function checkScalarValue(codePoint) { 13835 if (codePoint >= 0xd800 && codePoint <= 0xdfff) { 13836 throw Error('Lone surrogate U+' + codePoint.toString(16).toUpperCase() + ' is not a scalar value'); 13837 } 13838 } 13839 /*--------------------------------------------------------------------------*/ 13840 13841 function createByte(codePoint, shift) { 13842 return stringFromCharCode(((codePoint >> shift) & 0x3f) | 0x80); 13843 } 13844 13845 function encodeCodePoint(codePoint) { 13846 if ((codePoint & 0xffffff80) == 0) { 13847 // 1-byte sequence 13848 return stringFromCharCode(codePoint); 13849 } 13850 var symbol = ''; 13851 if ((codePoint & 0xfffff800) == 0) { 13852 // 2-byte sequence 13853 symbol = stringFromCharCode(((codePoint >> 6) & 0x1f) | 0xc0); 13854 } else if ((codePoint & 0xffff0000) == 0) { 13855 // 3-byte sequence 13856 checkScalarValue(codePoint); 13857 symbol = stringFromCharCode(((codePoint >> 12) & 0x0f) | 0xe0); 13858 symbol += createByte(codePoint, 6); 13859 } else if ((codePoint & 0xffe00000) == 0) { 13860 // 4-byte sequence 13861 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xf0); 13862 symbol += createByte(codePoint, 12); 13863 symbol += createByte(codePoint, 6); 13864 } 13865 symbol += stringFromCharCode((codePoint & 0x3f) | 0x80); 13866 return symbol; 13867 } 13868 13869 function utf8encode(string) { 13870 var codePoints = ucs2decode(string); 13871 var length = codePoints.length; 13872 var index = -1; 13873 var codePoint; 13874 var byteString = ''; 13875 while (++index < length) { 13876 codePoint = codePoints[index]; 13877 byteString += encodeCodePoint(codePoint); 13878 } 13879 return byteString; 13880 } 13881 13882 /*--------------------------------------------------------------------------*/ 13883 13884 function readContinuationByte() { 13885 if (byteIndex >= byteCount) { 13886 throw Error('Invalid byte index'); 13887 } 13888 13889 var continuationByte = byteArray[byteIndex] & 0xff; 13890 byteIndex++; 13891 13892 if ((continuationByte & 0xc0) == 0x80) { 13893 return continuationByte & 0x3f; 13894 } 13895 13896 // If we end up here, it’s not a continuation byte 13897 throw Error('Invalid continuation byte'); 13898 } 13899 13900 function decodeSymbol() { 13901 var byte1; 13902 var byte2; 13903 var byte3; 13904 var byte4; 13905 var codePoint; 13906 13907 if (byteIndex > byteCount) { 13908 throw Error('Invalid byte index'); 13909 } 13910 13911 if (byteIndex == byteCount) { 13912 return false; 13913 } 13914 13915 // Read first byte 13916 byte1 = byteArray[byteIndex] & 0xff; 13917 byteIndex++; 13918 13919 // 1-byte sequence (no continuation bytes) 13920 if ((byte1 & 0x80) == 0) { 13921 return byte1; 13922 } 13923 13924 // 2-byte sequence 13925 if ((byte1 & 0xe0) == 0xc0) { 13926 byte2 = readContinuationByte(); 13927 codePoint = ((byte1 & 0x1f) << 6) | byte2; 13928 if (codePoint >= 0x80) { 13929 return codePoint; 13930 } else { 13931 throw Error('Invalid continuation byte'); 13932 } 13933 } 13934 13935 // 3-byte sequence (may include unpaired surrogates) 13936 if ((byte1 & 0xf0) == 0xe0) { 13937 byte2 = readContinuationByte(); 13938 byte3 = readContinuationByte(); 13939 codePoint = ((byte1 & 0x0f) << 12) | (byte2 << 6) | byte3; 13940 if (codePoint >= 0x0800) { 13941 checkScalarValue(codePoint); 13942 return codePoint; 13943 } else { 13944 throw Error('Invalid continuation byte'); 13945 } 13946 } 13947 13948 // 4-byte sequence 13949 if ((byte1 & 0xf8) == 0xf0) { 13950 byte2 = readContinuationByte(); 13951 byte3 = readContinuationByte(); 13952 byte4 = readContinuationByte(); 13953 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0c) | (byte3 << 0x06) | byte4; 13954 if (codePoint >= 0x010000 && codePoint <= 0x10ffff) { 13955 return codePoint; 13956 } 13957 } 13958 13959 throw Error('Invalid UTF-8 detected'); 13960 } 13961 13962 var byteArray; 13963 var byteCount; 13964 var byteIndex; 13965 function utf8decode(byteString) { 13966 byteArray = ucs2decode(byteString); 13967 byteCount = byteArray.length; 13968 byteIndex = 0; 13969 var codePoints = []; 13970 var tmp; 13971 while ((tmp = decodeSymbol()) !== false) { 13972 codePoints.push(tmp); 13973 } 13974 return ucs2encode(codePoints); 13975 } 13976 13977 /*--------------------------------------------------------------------------*/ 13978 13979 var utf8 = { 13980 version: '2.1.2', 13981 encode: utf8encode, 13982 decode: utf8decode, 13983 }; 13984 13985 // Some AMD build optimizers, like r.js, check for specific condition patterns 13986 // like the following: 13987 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { 13988 define(function () { 13989 return utf8; 13990 }); 13991 } else if (freeExports && !freeExports.nodeType) { 13992 if (freeModule) { 13993 // in Node.js or RingoJS v0.8.0+ 13994 freeModule.exports = utf8; 13995 } else { 13996 // in Narwhal or RingoJS v0.7.0- 13997 var object = {}; 13998 var hasOwnProperty = object.hasOwnProperty; 13999 for (var key in utf8) { 14000 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 14001 } 14002 } 14003 } else { 14004 // in Rhino or a web browser 14005 root.utf8 = utf8; 14006 } 14007 })(this); 14008 }, 14009 {}, 14010 ], 14011 86: [ 14012 function (require, module, exports) { 14013 module.exports = XMLHttpRequest; 14014 }, 14015 {}, 14016 ], 14017 'bignumber.js': [ 14018 function (require, module, exports) { 14019 'use strict'; 14020 14021 module.exports = BigNumber; // jshint ignore:line 14022 }, 14023 {}, 14024 ], 14025 web3: [ 14026 function (require, module, exports) { 14027 var Web3 = require('./lib/web3'); 14028 14029 // don't override global variable 14030 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 14031 window.Web3 = Web3; 14032 } 14033 14034 module.exports = Web3; 14035 }, 14036 { './lib/web3': 22 }, 14037 ], 14038 }, 14039 {}, 14040 ['web3'] 14041 );