github.com/ethereum/go-ethereum@v1.16.1/internal/jsre/deps/web3.js (about) 1 require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 2 module.exports=[ 3 { 4 "constant": true, 5 "inputs": [ 6 { 7 "name": "_owner", 8 "type": "address" 9 } 10 ], 11 "name": "name", 12 "outputs": [ 13 { 14 "name": "o_name", 15 "type": "bytes32" 16 } 17 ], 18 "type": "function" 19 }, 20 { 21 "constant": true, 22 "inputs": [ 23 { 24 "name": "_name", 25 "type": "bytes32" 26 } 27 ], 28 "name": "owner", 29 "outputs": [ 30 { 31 "name": "", 32 "type": "address" 33 } 34 ], 35 "type": "function" 36 }, 37 { 38 "constant": true, 39 "inputs": [ 40 { 41 "name": "_name", 42 "type": "bytes32" 43 } 44 ], 45 "name": "content", 46 "outputs": [ 47 { 48 "name": "", 49 "type": "bytes32" 50 } 51 ], 52 "type": "function" 53 }, 54 { 55 "constant": true, 56 "inputs": [ 57 { 58 "name": "_name", 59 "type": "bytes32" 60 } 61 ], 62 "name": "addr", 63 "outputs": [ 64 { 65 "name": "", 66 "type": "address" 67 } 68 ], 69 "type": "function" 70 }, 71 { 72 "constant": false, 73 "inputs": [ 74 { 75 "name": "_name", 76 "type": "bytes32" 77 } 78 ], 79 "name": "reserve", 80 "outputs": [], 81 "type": "function" 82 }, 83 { 84 "constant": true, 85 "inputs": [ 86 { 87 "name": "_name", 88 "type": "bytes32" 89 } 90 ], 91 "name": "subRegistrar", 92 "outputs": [ 93 { 94 "name": "", 95 "type": "address" 96 } 97 ], 98 "type": "function" 99 }, 100 { 101 "constant": false, 102 "inputs": [ 103 { 104 "name": "_name", 105 "type": "bytes32" 106 }, 107 { 108 "name": "_newOwner", 109 "type": "address" 110 } 111 ], 112 "name": "transfer", 113 "outputs": [], 114 "type": "function" 115 }, 116 { 117 "constant": false, 118 "inputs": [ 119 { 120 "name": "_name", 121 "type": "bytes32" 122 }, 123 { 124 "name": "_registrar", 125 "type": "address" 126 } 127 ], 128 "name": "setSubRegistrar", 129 "outputs": [], 130 "type": "function" 131 }, 132 { 133 "constant": false, 134 "inputs": [], 135 "name": "Registrar", 136 "outputs": [], 137 "type": "function" 138 }, 139 { 140 "constant": false, 141 "inputs": [ 142 { 143 "name": "_name", 144 "type": "bytes32" 145 }, 146 { 147 "name": "_a", 148 "type": "address" 149 }, 150 { 151 "name": "_primary", 152 "type": "bool" 153 } 154 ], 155 "name": "setAddress", 156 "outputs": [], 157 "type": "function" 158 }, 159 { 160 "constant": false, 161 "inputs": [ 162 { 163 "name": "_name", 164 "type": "bytes32" 165 }, 166 { 167 "name": "_content", 168 "type": "bytes32" 169 } 170 ], 171 "name": "setContent", 172 "outputs": [], 173 "type": "function" 174 }, 175 { 176 "constant": false, 177 "inputs": [ 178 { 179 "name": "_name", 180 "type": "bytes32" 181 } 182 ], 183 "name": "disown", 184 "outputs": [], 185 "type": "function" 186 }, 187 { 188 "anonymous": false, 189 "inputs": [ 190 { 191 "indexed": true, 192 "name": "_name", 193 "type": "bytes32" 194 }, 195 { 196 "indexed": false, 197 "name": "_winner", 198 "type": "address" 199 } 200 ], 201 "name": "AuctionEnded", 202 "type": "event" 203 }, 204 { 205 "anonymous": false, 206 "inputs": [ 207 { 208 "indexed": true, 209 "name": "_name", 210 "type": "bytes32" 211 }, 212 { 213 "indexed": false, 214 "name": "_bidder", 215 "type": "address" 216 }, 217 { 218 "indexed": false, 219 "name": "_value", 220 "type": "uint256" 221 } 222 ], 223 "name": "NewBid", 224 "type": "event" 225 }, 226 { 227 "anonymous": false, 228 "inputs": [ 229 { 230 "indexed": true, 231 "name": "name", 232 "type": "bytes32" 233 } 234 ], 235 "name": "Changed", 236 "type": "event" 237 }, 238 { 239 "anonymous": false, 240 "inputs": [ 241 { 242 "indexed": true, 243 "name": "name", 244 "type": "bytes32" 245 }, 246 { 247 "indexed": true, 248 "name": "addr", 249 "type": "address" 250 } 251 ], 252 "name": "PrimaryChanged", 253 "type": "event" 254 } 255 ] 256 257 },{}],2:[function(require,module,exports){ 258 module.exports=[ 259 { 260 "constant": true, 261 "inputs": [ 262 { 263 "name": "_name", 264 "type": "bytes32" 265 } 266 ], 267 "name": "owner", 268 "outputs": [ 269 { 270 "name": "", 271 "type": "address" 272 } 273 ], 274 "type": "function" 275 }, 276 { 277 "constant": false, 278 "inputs": [ 279 { 280 "name": "_name", 281 "type": "bytes32" 282 }, 283 { 284 "name": "_refund", 285 "type": "address" 286 } 287 ], 288 "name": "disown", 289 "outputs": [], 290 "type": "function" 291 }, 292 { 293 "constant": true, 294 "inputs": [ 295 { 296 "name": "_name", 297 "type": "bytes32" 298 } 299 ], 300 "name": "addr", 301 "outputs": [ 302 { 303 "name": "", 304 "type": "address" 305 } 306 ], 307 "type": "function" 308 }, 309 { 310 "constant": false, 311 "inputs": [ 312 { 313 "name": "_name", 314 "type": "bytes32" 315 } 316 ], 317 "name": "reserve", 318 "outputs": [], 319 "type": "function" 320 }, 321 { 322 "constant": false, 323 "inputs": [ 324 { 325 "name": "_name", 326 "type": "bytes32" 327 }, 328 { 329 "name": "_newOwner", 330 "type": "address" 331 } 332 ], 333 "name": "transfer", 334 "outputs": [], 335 "type": "function" 336 }, 337 { 338 "constant": false, 339 "inputs": [ 340 { 341 "name": "_name", 342 "type": "bytes32" 343 }, 344 { 345 "name": "_a", 346 "type": "address" 347 } 348 ], 349 "name": "setAddr", 350 "outputs": [], 351 "type": "function" 352 }, 353 { 354 "anonymous": false, 355 "inputs": [ 356 { 357 "indexed": true, 358 "name": "name", 359 "type": "bytes32" 360 } 361 ], 362 "name": "Changed", 363 "type": "event" 364 } 365 ] 366 367 },{}],3:[function(require,module,exports){ 368 module.exports=[ 369 { 370 "constant": false, 371 "inputs": [ 372 { 373 "name": "from", 374 "type": "bytes32" 375 }, 376 { 377 "name": "to", 378 "type": "address" 379 }, 380 { 381 "name": "value", 382 "type": "uint256" 383 } 384 ], 385 "name": "transfer", 386 "outputs": [], 387 "type": "function" 388 }, 389 { 390 "constant": false, 391 "inputs": [ 392 { 393 "name": "from", 394 "type": "bytes32" 395 }, 396 { 397 "name": "to", 398 "type": "address" 399 }, 400 { 401 "name": "indirectId", 402 "type": "bytes32" 403 }, 404 { 405 "name": "value", 406 "type": "uint256" 407 } 408 ], 409 "name": "icapTransfer", 410 "outputs": [], 411 "type": "function" 412 }, 413 { 414 "constant": false, 415 "inputs": [ 416 { 417 "name": "to", 418 "type": "bytes32" 419 } 420 ], 421 "name": "deposit", 422 "outputs": [], 423 "payable": true, 424 "type": "function" 425 }, 426 { 427 "anonymous": false, 428 "inputs": [ 429 { 430 "indexed": true, 431 "name": "from", 432 "type": "address" 433 }, 434 { 435 "indexed": false, 436 "name": "value", 437 "type": "uint256" 438 } 439 ], 440 "name": "AnonymousDeposit", 441 "type": "event" 442 }, 443 { 444 "anonymous": false, 445 "inputs": [ 446 { 447 "indexed": true, 448 "name": "from", 449 "type": "address" 450 }, 451 { 452 "indexed": true, 453 "name": "to", 454 "type": "bytes32" 455 }, 456 { 457 "indexed": false, 458 "name": "value", 459 "type": "uint256" 460 } 461 ], 462 "name": "Deposit", 463 "type": "event" 464 }, 465 { 466 "anonymous": false, 467 "inputs": [ 468 { 469 "indexed": true, 470 "name": "from", 471 "type": "bytes32" 472 }, 473 { 474 "indexed": true, 475 "name": "to", 476 "type": "address" 477 }, 478 { 479 "indexed": false, 480 "name": "value", 481 "type": "uint256" 482 } 483 ], 484 "name": "Transfer", 485 "type": "event" 486 }, 487 { 488 "anonymous": false, 489 "inputs": [ 490 { 491 "indexed": true, 492 "name": "from", 493 "type": "bytes32" 494 }, 495 { 496 "indexed": true, 497 "name": "to", 498 "type": "address" 499 }, 500 { 501 "indexed": false, 502 "name": "indirectId", 503 "type": "bytes32" 504 }, 505 { 506 "indexed": false, 507 "name": "value", 508 "type": "uint256" 509 } 510 ], 511 "name": "IcapTransfer", 512 "type": "event" 513 } 514 ] 515 516 },{}],4:[function(require,module,exports){ 517 var f = require('./formatters'); 518 var SolidityType = require('./type'); 519 520 /** 521 * SolidityTypeAddress is a prototype that represents address type 522 * It matches: 523 * address 524 * address[] 525 * address[4] 526 * address[][] 527 * address[3][] 528 * address[][6][], ... 529 */ 530 var SolidityTypeAddress = function () { 531 this._inputFormatter = f.formatInputInt; 532 this._outputFormatter = f.formatOutputAddress; 533 }; 534 535 SolidityTypeAddress.prototype = new SolidityType({}); 536 SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 537 538 SolidityTypeAddress.prototype.isType = function (name) { 539 return !!name.match(/address(\[([0-9]*)\])?/); 540 }; 541 542 module.exports = SolidityTypeAddress; 543 544 },{"./formatters":9,"./type":14}],5:[function(require,module,exports){ 545 var f = require('./formatters'); 546 var SolidityType = require('./type'); 547 548 /** 549 * SolidityTypeBool is a prototype that represents bool type 550 * It matches: 551 * bool 552 * bool[] 553 * bool[4] 554 * bool[][] 555 * bool[3][] 556 * bool[][6][], ... 557 */ 558 var SolidityTypeBool = function () { 559 this._inputFormatter = f.formatInputBool; 560 this._outputFormatter = f.formatOutputBool; 561 }; 562 563 SolidityTypeBool.prototype = new SolidityType({}); 564 SolidityTypeBool.prototype.constructor = SolidityTypeBool; 565 566 SolidityTypeBool.prototype.isType = function (name) { 567 return !!name.match(/^bool(\[([0-9]*)\])*$/); 568 }; 569 570 module.exports = SolidityTypeBool; 571 572 },{"./formatters":9,"./type":14}],6:[function(require,module,exports){ 573 var f = require('./formatters'); 574 var SolidityType = require('./type'); 575 576 /** 577 * SolidityTypeBytes is a prototype that represents the bytes type. 578 * It matches: 579 * bytes 580 * bytes[] 581 * bytes[4] 582 * bytes[][] 583 * bytes[3][] 584 * bytes[][6][], ... 585 * bytes32 586 * bytes8[4] 587 * bytes[3][] 588 */ 589 var SolidityTypeBytes = function () { 590 this._inputFormatter = f.formatInputBytes; 591 this._outputFormatter = f.formatOutputBytes; 592 }; 593 594 SolidityTypeBytes.prototype = new SolidityType({}); 595 SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 596 597 SolidityTypeBytes.prototype.isType = function (name) { 598 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 599 }; 600 601 module.exports = SolidityTypeBytes; 602 603 },{"./formatters":9,"./type":14}],7:[function(require,module,exports){ 604 /* 605 This file is part of web3.js. 606 607 web3.js is free software: you can redistribute it and/or modify 608 it under the terms of the GNU Lesser General Public License as published by 609 the Free Software Foundation, either version 3 of the License, or 610 (at your option) any later version. 611 612 web3.js is distributed in the hope that it will be useful, 613 but WITHOUT ANY WARRANTY; without even the implied warranty of 614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 615 GNU Lesser General Public License for more details. 616 617 You should have received a copy of the GNU Lesser General Public License 618 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 619 */ 620 /** 621 * @file coder.js 622 * @author Marek Kotewicz <marek@ethdev.com> 623 * @date 2015 624 */ 625 626 var f = require('./formatters'); 627 628 var SolidityTypeAddress = require('./address'); 629 var SolidityTypeBool = require('./bool'); 630 var SolidityTypeInt = require('./int'); 631 var SolidityTypeUInt = require('./uint'); 632 var SolidityTypeDynamicBytes = require('./dynamicbytes'); 633 var SolidityTypeString = require('./string'); 634 var SolidityTypeReal = require('./real'); 635 var SolidityTypeUReal = require('./ureal'); 636 var SolidityTypeBytes = require('./bytes'); 637 638 var isDynamic = function (solidityType, type) { 639 return solidityType.isDynamicType(type) || 640 solidityType.isDynamicArray(type); 641 }; 642 643 /** 644 * SolidityCoder prototype should be used to encode/decode solidity params of any type 645 */ 646 var SolidityCoder = function (types) { 647 this._types = types; 648 }; 649 650 /** 651 * This method should be used to transform type to SolidityType 652 * 653 * @method _requireType 654 * @param {String} type 655 * @returns {SolidityType} 656 * @throws {Error} throws if no matching type is found 657 */ 658 SolidityCoder.prototype._requireType = function (type) { 659 var solidityType = this._types.filter(function (t) { 660 return t.isType(type); 661 })[0]; 662 663 if (!solidityType) { 664 throw Error('invalid solidity type!: ' + type); 665 } 666 667 return solidityType; 668 }; 669 670 /** 671 * Should be used to encode plain param 672 * 673 * @method encodeParam 674 * @param {String} type 675 * @param {Object} plain param 676 * @return {String} encoded plain param 677 */ 678 SolidityCoder.prototype.encodeParam = function (type, param) { 679 return this.encodeParams([type], [param]); 680 }; 681 682 /** 683 * Should be used to encode list of params 684 * 685 * @method encodeParams 686 * @param {Array} types 687 * @param {Array} params 688 * @return {String} encoded list of params 689 */ 690 SolidityCoder.prototype.encodeParams = function (types, params) { 691 var solidityTypes = this.getSolidityTypes(types); 692 693 var encodeds = solidityTypes.map(function (solidityType, index) { 694 return solidityType.encode(params[index], types[index]); 695 }); 696 697 var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) { 698 var staticPartLength = solidityType.staticPartLength(types[index]); 699 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 700 701 return acc + (isDynamic(solidityTypes[index], types[index]) ? 702 32 : 703 roundedStaticPartLength); 704 }, 0); 705 706 var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset); 707 708 return result; 709 }; 710 711 SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) { 712 var result = ""; 713 var self = this; 714 715 types.forEach(function (type, i) { 716 if (isDynamic(solidityTypes[i], types[i])) { 717 result += f.formatInputInt(dynamicOffset).encode(); 718 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 719 dynamicOffset += e.length / 2; 720 } else { 721 // don't add length to dynamicOffset. it's already counted 722 result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 723 } 724 725 // TODO: figure out nested arrays 726 }); 727 728 types.forEach(function (type, i) { 729 if (isDynamic(solidityTypes[i], types[i])) { 730 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 731 dynamicOffset += e.length / 2; 732 result += e; 733 } 734 }); 735 return result; 736 }; 737 738 // TODO: refactor whole encoding! 739 SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) { 740 var self = this; 741 if (solidityType.isDynamicArray(type)) { 742 return (function () { 743 // offset was already set 744 var nestedName = solidityType.nestedName(type); 745 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 746 var result = encoded[0]; 747 748 (function () { 749 var previousLength = 2; // in int 750 if (solidityType.isDynamicArray(nestedName)) { 751 for (var i = 1; i < encoded.length; i++) { 752 previousLength += +(encoded[i - 1])[0] || 0; 753 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 754 } 755 } 756 })(); 757 758 // first element is length, skip it 759 (function () { 760 for (var i = 0; i < encoded.length - 1; i++) { 761 var additionalOffset = result / 2; 762 result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset); 763 } 764 })(); 765 766 return result; 767 })(); 768 769 } else if (solidityType.isStaticArray(type)) { 770 return (function () { 771 var nestedName = solidityType.nestedName(type); 772 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 773 var result = ""; 774 775 776 if (solidityType.isDynamicArray(nestedName)) { 777 (function () { 778 var previousLength = 0; // in int 779 for (var i = 0; i < encoded.length; i++) { 780 // calculate length of previous item 781 previousLength += +(encoded[i - 1] || [])[0] || 0; 782 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 783 } 784 })(); 785 } 786 787 (function () { 788 for (var i = 0; i < encoded.length; i++) { 789 var additionalOffset = result / 2; 790 result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset); 791 } 792 })(); 793 794 return result; 795 })(); 796 } 797 798 return encoded; 799 }; 800 801 /** 802 * Should be used to decode bytes to plain param 803 * 804 * @method decodeParam 805 * @param {String} type 806 * @param {String} bytes 807 * @return {Object} plain param 808 */ 809 SolidityCoder.prototype.decodeParam = function (type, bytes) { 810 return this.decodeParams([type], bytes)[0]; 811 }; 812 813 /** 814 * Should be used to decode list of params 815 * 816 * @method decodeParam 817 * @param {Array} types 818 * @param {String} bytes 819 * @return {Array} array of plain params 820 */ 821 SolidityCoder.prototype.decodeParams = function (types, bytes) { 822 var solidityTypes = this.getSolidityTypes(types); 823 var offsets = this.getOffsets(types, solidityTypes); 824 825 return solidityTypes.map(function (solidityType, index) { 826 return solidityType.decode(bytes, offsets[index], types[index], index); 827 }); 828 }; 829 830 SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { 831 var lengths = solidityTypes.map(function (solidityType, index) { 832 return solidityType.staticPartLength(types[index]); 833 }); 834 835 for (var i = 1; i < lengths.length; i++) { 836 // sum with length of previous element 837 lengths[i] += lengths[i - 1]; 838 } 839 840 return lengths.map(function (length, index) { 841 // remove the current length, so the length is sum of previous elements 842 var staticPartLength = solidityTypes[index].staticPartLength(types[index]); 843 return length - staticPartLength; 844 }); 845 }; 846 847 SolidityCoder.prototype.getSolidityTypes = function (types) { 848 var self = this; 849 return types.map(function (type) { 850 return self._requireType(type); 851 }); 852 }; 853 854 var coder = new SolidityCoder([ 855 new SolidityTypeAddress(), 856 new SolidityTypeBool(), 857 new SolidityTypeInt(), 858 new SolidityTypeUInt(), 859 new SolidityTypeDynamicBytes(), 860 new SolidityTypeBytes(), 861 new SolidityTypeString(), 862 new SolidityTypeReal(), 863 new SolidityTypeUReal() 864 ]); 865 866 module.exports = coder; 867 868 },{"./address":4,"./bool":5,"./bytes":6,"./dynamicbytes":8,"./formatters":9,"./int":10,"./real":12,"./string":13,"./uint":15,"./ureal":16}],8:[function(require,module,exports){ 869 var f = require('./formatters'); 870 var SolidityType = require('./type'); 871 872 var SolidityTypeDynamicBytes = function () { 873 this._inputFormatter = f.formatInputDynamicBytes; 874 this._outputFormatter = f.formatOutputDynamicBytes; 875 }; 876 877 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 878 SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 879 880 SolidityTypeDynamicBytes.prototype.isType = function (name) { 881 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 882 }; 883 884 SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 885 return true; 886 }; 887 888 module.exports = SolidityTypeDynamicBytes; 889 890 },{"./formatters":9,"./type":14}],9:[function(require,module,exports){ 891 /* 892 This file is part of web3.js. 893 894 web3.js is free software: you can redistribute it and/or modify 895 it under the terms of the GNU Lesser General Public License as published by 896 the Free Software Foundation, either version 3 of the License, or 897 (at your option) any later version. 898 899 web3.js is distributed in the hope that it will be useful, 900 but WITHOUT ANY WARRANTY; without even the implied warranty of 901 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 902 GNU Lesser General Public License for more details. 903 904 You should have received a copy of the GNU Lesser General Public License 905 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 906 */ 907 /** 908 * @file formatters.js 909 * @author Marek Kotewicz <marek@ethdev.com> 910 * @date 2015 911 */ 912 913 var BigNumber = require('bignumber.js'); 914 var utils = require('../utils/utils'); 915 var c = require('../utils/config'); 916 var SolidityParam = require('./param'); 917 918 919 /** 920 * Formats input value to byte representation of int 921 * If value is negative, return it's two's complement 922 * If the value is floating point, round it down 923 * 924 * @method formatInputInt 925 * @param {String|Number|BigNumber} value that needs to be formatted 926 * @returns {SolidityParam} 927 */ 928 var formatInputInt = function (value) { 929 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 930 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 931 return new SolidityParam(result); 932 }; 933 934 /** 935 * Formats input bytes 936 * 937 * @method formatInputBytes 938 * @param {String} 939 * @returns {SolidityParam} 940 */ 941 var formatInputBytes = function (value) { 942 var result = utils.toHex(value).substr(2); 943 var l = Math.floor((result.length + 63) / 64); 944 result = utils.padRight(result, l * 64); 945 return new SolidityParam(result); 946 }; 947 948 /** 949 * Formats input bytes 950 * 951 * @method formatDynamicInputBytes 952 * @param {String} 953 * @returns {SolidityParam} 954 */ 955 var formatInputDynamicBytes = function (value) { 956 var result = utils.toHex(value).substr(2); 957 var length = result.length / 2; 958 var l = Math.floor((result.length + 63) / 64); 959 result = utils.padRight(result, l * 64); 960 return new SolidityParam(formatInputInt(length).value + result); 961 }; 962 963 /** 964 * Formats input value to byte representation of string 965 * 966 * @method formatInputString 967 * @param {String} 968 * @returns {SolidityParam} 969 */ 970 var formatInputString = function (value) { 971 var result = utils.fromUtf8(value).substr(2); 972 var length = result.length / 2; 973 var l = Math.floor((result.length + 63) / 64); 974 result = utils.padRight(result, l * 64); 975 return new SolidityParam(formatInputInt(length).value + result); 976 }; 977 978 /** 979 * Formats input value to byte representation of bool 980 * 981 * @method formatInputBool 982 * @param {Boolean} 983 * @returns {SolidityParam} 984 */ 985 var formatInputBool = function (value) { 986 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 987 return new SolidityParam(result); 988 }; 989 990 /** 991 * Formats input value to byte representation of real 992 * Values are multiplied by 2^m and encoded as integers 993 * 994 * @method formatInputReal 995 * @param {String|Number|BigNumber} 996 * @returns {SolidityParam} 997 */ 998 var formatInputReal = function (value) { 999 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1000 }; 1001 1002 /** 1003 * Check if input value is negative 1004 * 1005 * @method signedIsNegative 1006 * @param {String} value is hex format 1007 * @returns {Boolean} true if it is negative, otherwise false 1008 */ 1009 var signedIsNegative = function (value) { 1010 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1011 }; 1012 1013 /** 1014 * Formats right-aligned output bytes to int 1015 * 1016 * @method formatOutputInt 1017 * @param {SolidityParam} param 1018 * @returns {BigNumber} right-aligned output bytes formatted to big number 1019 */ 1020 var formatOutputInt = function (param) { 1021 var value = param.staticPart() || "0"; 1022 1023 // check if it's negative number 1024 // it is, return two's complement 1025 if (signedIsNegative(value)) { 1026 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1027 } 1028 return new BigNumber(value, 16); 1029 }; 1030 1031 /** 1032 * Formats right-aligned output bytes to uint 1033 * 1034 * @method formatOutputUInt 1035 * @param {SolidityParam} 1036 * @returns {BigNumber} right-aligned output bytes formatted to uint 1037 */ 1038 var formatOutputUInt = function (param) { 1039 var value = param.staticPart() || "0"; 1040 return new BigNumber(value, 16); 1041 }; 1042 1043 /** 1044 * Formats right-aligned output bytes to real 1045 * 1046 * @method formatOutputReal 1047 * @param {SolidityParam} 1048 * @returns {BigNumber} input bytes formatted to real 1049 */ 1050 var formatOutputReal = function (param) { 1051 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1052 }; 1053 1054 /** 1055 * Formats right-aligned output bytes to ureal 1056 * 1057 * @method formatOutputUReal 1058 * @param {SolidityParam} 1059 * @returns {BigNumber} input bytes formatted to ureal 1060 */ 1061 var formatOutputUReal = function (param) { 1062 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1063 }; 1064 1065 /** 1066 * Should be used to format output bool 1067 * 1068 * @method formatOutputBool 1069 * @param {SolidityParam} 1070 * @returns {Boolean} right-aligned input bytes formatted to bool 1071 */ 1072 var formatOutputBool = function (param) { 1073 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1074 }; 1075 1076 /** 1077 * Should be used to format output bytes 1078 * 1079 * @method formatOutputBytes 1080 * @param {SolidityParam} left-aligned hex representation of string 1081 * @param {String} name type name 1082 * @returns {String} hex string 1083 */ 1084 var formatOutputBytes = function (param, name) { 1085 var matches = name.match(/^bytes([0-9]*)/); 1086 var size = parseInt(matches[1]); 1087 return '0x' + param.staticPart().slice(0, 2 * size); 1088 }; 1089 1090 /** 1091 * Should be used to format output bytes 1092 * 1093 * @method formatOutputDynamicBytes 1094 * @param {SolidityParam} left-aligned hex representation of string 1095 * @returns {String} hex string 1096 */ 1097 var formatOutputDynamicBytes = function (param) { 1098 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1099 return '0x' + param.dynamicPart().substr(64, length); 1100 }; 1101 1102 /** 1103 * Should be used to format output string 1104 * 1105 * @method formatOutputString 1106 * @param {SolidityParam} left-aligned hex representation of string 1107 * @returns {String} ascii string 1108 */ 1109 var formatOutputString = function (param) { 1110 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1111 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1112 }; 1113 1114 /** 1115 * Should be used to format output address 1116 * 1117 * @method formatOutputAddress 1118 * @param {SolidityParam} right-aligned input bytes 1119 * @returns {String} address 1120 */ 1121 var formatOutputAddress = function (param) { 1122 var value = param.staticPart(); 1123 return "0x" + value.slice(value.length - 40, value.length); 1124 }; 1125 1126 module.exports = { 1127 formatInputInt: formatInputInt, 1128 formatInputBytes: formatInputBytes, 1129 formatInputDynamicBytes: formatInputDynamicBytes, 1130 formatInputString: formatInputString, 1131 formatInputBool: formatInputBool, 1132 formatInputReal: formatInputReal, 1133 formatOutputInt: formatOutputInt, 1134 formatOutputUInt: formatOutputUInt, 1135 formatOutputReal: formatOutputReal, 1136 formatOutputUReal: formatOutputUReal, 1137 formatOutputBool: formatOutputBool, 1138 formatOutputBytes: formatOutputBytes, 1139 formatOutputDynamicBytes: formatOutputDynamicBytes, 1140 formatOutputString: formatOutputString, 1141 formatOutputAddress: formatOutputAddress 1142 }; 1143 1144 },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){ 1145 var f = require('./formatters'); 1146 var SolidityType = require('./type'); 1147 1148 /** 1149 * SolidityTypeInt is a prototype that represents int type 1150 * It matches: 1151 * int 1152 * int[] 1153 * int[4] 1154 * int[][] 1155 * int[3][] 1156 * int[][6][], ... 1157 * int32 1158 * int64[] 1159 * int8[4] 1160 * int256[][] 1161 * int[3][] 1162 * int64[][6][], ... 1163 */ 1164 var SolidityTypeInt = function () { 1165 this._inputFormatter = f.formatInputInt; 1166 this._outputFormatter = f.formatOutputInt; 1167 }; 1168 1169 SolidityTypeInt.prototype = new SolidityType({}); 1170 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1171 1172 SolidityTypeInt.prototype.isType = function (name) { 1173 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1174 }; 1175 1176 module.exports = SolidityTypeInt; 1177 1178 },{"./formatters":9,"./type":14}],11:[function(require,module,exports){ 1179 /* 1180 This file is part of web3.js. 1181 1182 web3.js is free software: you can redistribute it and/or modify 1183 it under the terms of the GNU Lesser General Public License as published by 1184 the Free Software Foundation, either version 3 of the License, or 1185 (at your option) any later version. 1186 1187 web3.js is distributed in the hope that it will be useful, 1188 but WITHOUT ANY WARRANTY; without even the implied warranty of 1189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1190 GNU Lesser General Public License for more details. 1191 1192 You should have received a copy of the GNU Lesser General Public License 1193 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1194 */ 1195 /** 1196 * @file param.js 1197 * @author Marek Kotewicz <marek@ethdev.com> 1198 * @date 2015 1199 */ 1200 1201 var utils = require('../utils/utils'); 1202 1203 /** 1204 * SolidityParam object prototype. 1205 * Should be used when encoding, decoding solidity bytes 1206 */ 1207 var SolidityParam = function (value, offset) { 1208 this.value = value || ''; 1209 this.offset = offset; // offset in bytes 1210 }; 1211 1212 /** 1213 * This method should be used to get length of params's dynamic part 1214 * 1215 * @method dynamicPartLength 1216 * @returns {Number} length of dynamic part (in bytes) 1217 */ 1218 SolidityParam.prototype.dynamicPartLength = function () { 1219 return this.dynamicPart().length / 2; 1220 }; 1221 1222 /** 1223 * This method should be used to create copy of solidity param with different offset 1224 * 1225 * @method withOffset 1226 * @param {Number} offset length in bytes 1227 * @returns {SolidityParam} new solidity param with applied offset 1228 */ 1229 SolidityParam.prototype.withOffset = function (offset) { 1230 return new SolidityParam(this.value, offset); 1231 }; 1232 1233 /** 1234 * This method should be used to combine solidity params together 1235 * eg. when appending an array 1236 * 1237 * @method combine 1238 * @param {SolidityParam} param with which we should combine 1239 * @param {SolidityParam} result of combination 1240 */ 1241 SolidityParam.prototype.combine = function (param) { 1242 return new SolidityParam(this.value + param.value); 1243 }; 1244 1245 /** 1246 * This method should be called to check if param has dynamic size. 1247 * If it has, it returns true, otherwise false 1248 * 1249 * @method isDynamic 1250 * @returns {Boolean} 1251 */ 1252 SolidityParam.prototype.isDynamic = function () { 1253 return this.offset !== undefined; 1254 }; 1255 1256 /** 1257 * This method should be called to transform offset to bytes 1258 * 1259 * @method offsetAsBytes 1260 * @returns {String} bytes representation of offset 1261 */ 1262 SolidityParam.prototype.offsetAsBytes = function () { 1263 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1264 }; 1265 1266 /** 1267 * This method should be called to get static part of param 1268 * 1269 * @method staticPart 1270 * @returns {String} offset if it is a dynamic param, otherwise value 1271 */ 1272 SolidityParam.prototype.staticPart = function () { 1273 if (!this.isDynamic()) { 1274 return this.value; 1275 } 1276 return this.offsetAsBytes(); 1277 }; 1278 1279 /** 1280 * This method should be called to get dynamic part of param 1281 * 1282 * @method dynamicPart 1283 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1284 */ 1285 SolidityParam.prototype.dynamicPart = function () { 1286 return this.isDynamic() ? this.value : ''; 1287 }; 1288 1289 /** 1290 * This method should be called to encode param 1291 * 1292 * @method encode 1293 * @returns {String} 1294 */ 1295 SolidityParam.prototype.encode = function () { 1296 return this.staticPart() + this.dynamicPart(); 1297 }; 1298 1299 /** 1300 * This method should be called to encode array of params 1301 * 1302 * @method encodeList 1303 * @param {Array[SolidityParam]} params 1304 * @returns {String} 1305 */ 1306 SolidityParam.encodeList = function (params) { 1307 1308 // updating offsets 1309 var totalOffset = params.length * 32; 1310 var offsetParams = params.map(function (param) { 1311 if (!param.isDynamic()) { 1312 return param; 1313 } 1314 var offset = totalOffset; 1315 totalOffset += param.dynamicPartLength(); 1316 return param.withOffset(offset); 1317 }); 1318 1319 // encode everything! 1320 return offsetParams.reduce(function (result, param) { 1321 return result + param.dynamicPart(); 1322 }, offsetParams.reduce(function (result, param) { 1323 return result + param.staticPart(); 1324 }, '')); 1325 }; 1326 1327 1328 1329 module.exports = SolidityParam; 1330 1331 1332 },{"../utils/utils":20}],12:[function(require,module,exports){ 1333 var f = require('./formatters'); 1334 var SolidityType = require('./type'); 1335 1336 /** 1337 * SolidityTypeReal is a prototype that represents real type 1338 * It matches: 1339 * real 1340 * real[] 1341 * real[4] 1342 * real[][] 1343 * real[3][] 1344 * real[][6][], ... 1345 * real32 1346 * real64[] 1347 * real8[4] 1348 * real256[][] 1349 * real[3][] 1350 * real64[][6][], ... 1351 */ 1352 var SolidityTypeReal = function () { 1353 this._inputFormatter = f.formatInputReal; 1354 this._outputFormatter = f.formatOutputReal; 1355 }; 1356 1357 SolidityTypeReal.prototype = new SolidityType({}); 1358 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1359 1360 SolidityTypeReal.prototype.isType = function (name) { 1361 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1362 }; 1363 1364 module.exports = SolidityTypeReal; 1365 1366 },{"./formatters":9,"./type":14}],13:[function(require,module,exports){ 1367 var f = require('./formatters'); 1368 var SolidityType = require('./type'); 1369 1370 var SolidityTypeString = function () { 1371 this._inputFormatter = f.formatInputString; 1372 this._outputFormatter = f.formatOutputString; 1373 }; 1374 1375 SolidityTypeString.prototype = new SolidityType({}); 1376 SolidityTypeString.prototype.constructor = SolidityTypeString; 1377 1378 SolidityTypeString.prototype.isType = function (name) { 1379 return !!name.match(/^string(\[([0-9]*)\])*$/); 1380 }; 1381 1382 SolidityTypeString.prototype.isDynamicType = function () { 1383 return true; 1384 }; 1385 1386 module.exports = SolidityTypeString; 1387 1388 },{"./formatters":9,"./type":14}],14:[function(require,module,exports){ 1389 var f = require('./formatters'); 1390 var SolidityParam = require('./param'); 1391 1392 /** 1393 * SolidityType prototype is used to encode/decode solidity params of certain type 1394 */ 1395 var SolidityType = function (config) { 1396 this._inputFormatter = config.inputFormatter; 1397 this._outputFormatter = config.outputFormatter; 1398 }; 1399 1400 /** 1401 * Should be used to determine if this SolidityType do match given name 1402 * 1403 * @method isType 1404 * @param {String} name 1405 * @return {Bool} true if type match this SolidityType, otherwise false 1406 */ 1407 SolidityType.prototype.isType = function (name) { 1408 throw "this method should be overrwritten for type " + name; 1409 }; 1410 1411 /** 1412 * Should be used to determine what is the length of static part in given type 1413 * 1414 * @method staticPartLength 1415 * @param {String} name 1416 * @return {Number} length of static part in bytes 1417 */ 1418 SolidityType.prototype.staticPartLength = function (name) { 1419 // If name isn't an array then treat it like a single element array. 1420 return (this.nestedTypes(name) || ['[1]']) 1421 .map(function (type) { 1422 // the length of the nested array 1423 return parseInt(type.slice(1, -1), 10) || 1; 1424 }) 1425 .reduce(function (previous, current) { 1426 return previous * current; 1427 // all basic types are 32 bytes long 1428 }, 32); 1429 }; 1430 1431 /** 1432 * Should be used to determine if type is dynamic array 1433 * eg: 1434 * "type[]" => true 1435 * "type[4]" => false 1436 * 1437 * @method isDynamicArray 1438 * @param {String} name 1439 * @return {Bool} true if the type is dynamic array 1440 */ 1441 SolidityType.prototype.isDynamicArray = function (name) { 1442 var nestedTypes = this.nestedTypes(name); 1443 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1444 }; 1445 1446 /** 1447 * Should be used to determine if type is static array 1448 * eg: 1449 * "type[]" => false 1450 * "type[4]" => true 1451 * 1452 * @method isStaticArray 1453 * @param {String} name 1454 * @return {Bool} true if the type is static array 1455 */ 1456 SolidityType.prototype.isStaticArray = function (name) { 1457 var nestedTypes = this.nestedTypes(name); 1458 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1459 }; 1460 1461 /** 1462 * Should return length of static array 1463 * eg. 1464 * "int[32]" => 32 1465 * "int256[14]" => 14 1466 * "int[2][3]" => 3 1467 * "int" => 1 1468 * "int[1]" => 1 1469 * "int[]" => 1 1470 * 1471 * @method staticArrayLength 1472 * @param {String} name 1473 * @return {Number} static array length 1474 */ 1475 SolidityType.prototype.staticArrayLength = function (name) { 1476 var nestedTypes = this.nestedTypes(name); 1477 if (nestedTypes) { 1478 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1479 } 1480 return 1; 1481 }; 1482 1483 /** 1484 * Should return nested type 1485 * eg. 1486 * "int[32]" => "int" 1487 * "int256[14]" => "int256" 1488 * "int[2][3]" => "int[2]" 1489 * "int" => "int" 1490 * "int[]" => "int" 1491 * 1492 * @method nestedName 1493 * @param {String} name 1494 * @return {String} nested name 1495 */ 1496 SolidityType.prototype.nestedName = function (name) { 1497 // remove last [] in name 1498 var nestedTypes = this.nestedTypes(name); 1499 if (!nestedTypes) { 1500 return name; 1501 } 1502 1503 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1504 }; 1505 1506 /** 1507 * Should return true if type has dynamic size by default 1508 * such types are "string", "bytes" 1509 * 1510 * @method isDynamicType 1511 * @param {String} name 1512 * @return {Bool} true if is dynamic, otherwise false 1513 */ 1514 SolidityType.prototype.isDynamicType = function () { 1515 return false; 1516 }; 1517 1518 /** 1519 * Should return array of nested types 1520 * eg. 1521 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1522 * "int[] => ["[]"] 1523 * "int" => null 1524 * 1525 * @method nestedTypes 1526 * @param {String} name 1527 * @return {Array} array of nested types 1528 */ 1529 SolidityType.prototype.nestedTypes = function (name) { 1530 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1531 return name.match(/(\[[0-9]*\])/g); 1532 }; 1533 1534 /** 1535 * Should be used to encode the value 1536 * 1537 * @method encode 1538 * @param {Object} value 1539 * @param {String} name 1540 * @return {String} encoded value 1541 */ 1542 SolidityType.prototype.encode = function (value, name) { 1543 var self = this; 1544 if (this.isDynamicArray(name)) { 1545 1546 return (function () { 1547 var length = value.length; // in int 1548 var nestedName = self.nestedName(name); 1549 1550 var result = []; 1551 result.push(f.formatInputInt(length).encode()); 1552 1553 value.forEach(function (v) { 1554 result.push(self.encode(v, nestedName)); 1555 }); 1556 1557 return result; 1558 })(); 1559 1560 } else if (this.isStaticArray(name)) { 1561 1562 return (function () { 1563 var length = self.staticArrayLength(name); // in int 1564 var nestedName = self.nestedName(name); 1565 1566 var result = []; 1567 for (var i = 0; i < length; i++) { 1568 result.push(self.encode(value[i], nestedName)); 1569 } 1570 1571 return result; 1572 })(); 1573 1574 } 1575 1576 return this._inputFormatter(value, name).encode(); 1577 }; 1578 1579 /** 1580 * Should be used to decode value from bytes 1581 * 1582 * @method decode 1583 * @param {String} bytes 1584 * @param {Number} offset in bytes 1585 * @param {String} name type name 1586 * @returns {Object} decoded value 1587 */ 1588 SolidityType.prototype.decode = function (bytes, offset, name) { 1589 var self = this; 1590 1591 if (this.isDynamicArray(name)) { 1592 1593 return (function () { 1594 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1595 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1596 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1597 1598 var nestedName = self.nestedName(name); 1599 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1600 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1601 var result = []; 1602 1603 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1604 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1605 } 1606 1607 return result; 1608 })(); 1609 1610 } else if (this.isStaticArray(name)) { 1611 1612 return (function () { 1613 var length = self.staticArrayLength(name); // in int 1614 var arrayStart = offset; // in bytes 1615 1616 var nestedName = self.nestedName(name); 1617 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1618 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1619 var result = []; 1620 1621 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1622 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1623 } 1624 1625 return result; 1626 })(); 1627 } else if (this.isDynamicType(name)) { 1628 1629 return (function () { 1630 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1631 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1632 var roundedLength = Math.floor((length + 31) / 32); // in int 1633 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0); 1634 return self._outputFormatter(param, name); 1635 })(); 1636 } 1637 1638 var length = this.staticPartLength(name); 1639 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1640 return this._outputFormatter(param, name); 1641 }; 1642 1643 module.exports = SolidityType; 1644 1645 },{"./formatters":9,"./param":11}],15:[function(require,module,exports){ 1646 var f = require('./formatters'); 1647 var SolidityType = require('./type'); 1648 1649 /** 1650 * SolidityTypeUInt is a prototype that represents uint type 1651 * It matches: 1652 * uint 1653 * uint[] 1654 * uint[4] 1655 * uint[][] 1656 * uint[3][] 1657 * uint[][6][], ... 1658 * uint32 1659 * uint64[] 1660 * uint8[4] 1661 * uint256[][] 1662 * uint[3][] 1663 * uint64[][6][], ... 1664 */ 1665 var SolidityTypeUInt = function () { 1666 this._inputFormatter = f.formatInputInt; 1667 this._outputFormatter = f.formatOutputUInt; 1668 }; 1669 1670 SolidityTypeUInt.prototype = new SolidityType({}); 1671 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1672 1673 SolidityTypeUInt.prototype.isType = function (name) { 1674 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1675 }; 1676 1677 module.exports = SolidityTypeUInt; 1678 1679 },{"./formatters":9,"./type":14}],16:[function(require,module,exports){ 1680 var f = require('./formatters'); 1681 var SolidityType = require('./type'); 1682 1683 /** 1684 * SolidityTypeUReal is a prototype that represents ureal type 1685 * It matches: 1686 * ureal 1687 * ureal[] 1688 * ureal[4] 1689 * ureal[][] 1690 * ureal[3][] 1691 * ureal[][6][], ... 1692 * ureal32 1693 * ureal64[] 1694 * ureal8[4] 1695 * ureal256[][] 1696 * ureal[3][] 1697 * ureal64[][6][], ... 1698 */ 1699 var SolidityTypeUReal = function () { 1700 this._inputFormatter = f.formatInputReal; 1701 this._outputFormatter = f.formatOutputUReal; 1702 }; 1703 1704 SolidityTypeUReal.prototype = new SolidityType({}); 1705 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1706 1707 SolidityTypeUReal.prototype.isType = function (name) { 1708 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1709 }; 1710 1711 module.exports = SolidityTypeUReal; 1712 1713 },{"./formatters":9,"./type":14}],17:[function(require,module,exports){ 1714 'use strict'; 1715 1716 // go env doesn't have and need XMLHttpRequest 1717 if (typeof XMLHttpRequest === 'undefined') { 1718 exports.XMLHttpRequest = {}; 1719 } else { 1720 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1721 } 1722 1723 1724 },{}],18:[function(require,module,exports){ 1725 /* 1726 This file is part of web3.js. 1727 1728 web3.js is free software: you can redistribute it and/or modify 1729 it under the terms of the GNU Lesser General Public License as published by 1730 the Free Software Foundation, either version 3 of the License, or 1731 (at your option) any later version. 1732 1733 web3.js is distributed in the hope that it will be useful, 1734 but WITHOUT ANY WARRANTY; without even the implied warranty of 1735 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1736 GNU Lesser General Public License for more details. 1737 1738 You should have received a copy of the GNU Lesser General Public License 1739 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1740 */ 1741 /** @file config.js 1742 * @authors: 1743 * Marek Kotewicz <marek@ethdev.com> 1744 * @date 2015 1745 */ 1746 1747 /** 1748 * Utils 1749 * 1750 * @module utils 1751 */ 1752 1753 /** 1754 * Utility functions 1755 * 1756 * @class [utils] config 1757 * @constructor 1758 */ 1759 1760 1761 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1762 var BigNumber = require('bignumber.js'); 1763 1764 var ETH_UNITS = [ 1765 'wei', 1766 'kwei', 1767 'Mwei', 1768 'Gwei', 1769 'szabo', 1770 'finney', 1771 'femtoether', 1772 'picoether', 1773 'nanoether', 1774 'microether', 1775 'milliether', 1776 'nano', 1777 'micro', 1778 'milli', 1779 'ether', 1780 'grand', 1781 'Mether', 1782 'Gether', 1783 'Tether', 1784 'Pether', 1785 'Eether', 1786 'Zether', 1787 'Yether', 1788 'Nether', 1789 'Dether', 1790 'Vether', 1791 'Uether' 1792 ]; 1793 1794 module.exports = { 1795 ETH_PADDING: 32, 1796 ETH_SIGNATURE_LENGTH: 4, 1797 ETH_UNITS: ETH_UNITS, 1798 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1799 ETH_POLLING_TIMEOUT: 1000/2, 1800 defaultBlock: 'latest', 1801 defaultAccount: undefined 1802 }; 1803 1804 1805 },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){ 1806 /* 1807 This file is part of web3.js. 1808 1809 web3.js is free software: you can redistribute it and/or modify 1810 it under the terms of the GNU Lesser General Public License as published by 1811 the Free Software Foundation, either version 3 of the License, or 1812 (at your option) any later version. 1813 1814 web3.js is distributed in the hope that it will be useful, 1815 but WITHOUT ANY WARRANTY; without even the implied warranty of 1816 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1817 GNU Lesser General Public License for more details. 1818 1819 You should have received a copy of the GNU Lesser General Public License 1820 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1821 */ 1822 /** 1823 * @file sha3.js 1824 * @author Marek Kotewicz <marek@ethdev.com> 1825 * @date 2015 1826 */ 1827 1828 var CryptoJS = require('crypto-js'); 1829 var sha3 = require('crypto-js/sha3'); 1830 1831 module.exports = function (value, options) { 1832 if (options && options.encoding === 'hex') { 1833 if (value.length > 2 && value.substr(0, 2) === '0x') { 1834 value = value.substr(2); 1835 } 1836 value = CryptoJS.enc.Hex.parse(value); 1837 } 1838 1839 return sha3(value, { 1840 outputLength: 256 1841 }).toString(); 1842 }; 1843 1844 1845 },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){ 1846 /* 1847 This file is part of web3.js. 1848 1849 web3.js is free software: you can redistribute it and/or modify 1850 it under the terms of the GNU Lesser General Public License as published by 1851 the Free Software Foundation, either version 3 of the License, or 1852 (at your option) any later version. 1853 1854 web3.js is distributed in the hope that it will be useful, 1855 but WITHOUT ANY WARRANTY; without even the implied warranty of 1856 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1857 GNU Lesser General Public License for more details. 1858 1859 You should have received a copy of the GNU Lesser General Public License 1860 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1861 */ 1862 /** 1863 * @file utils.js 1864 * @author Marek Kotewicz <marek@ethdev.com> 1865 * @date 2015 1866 */ 1867 1868 /** 1869 * Utils 1870 * 1871 * @module utils 1872 */ 1873 1874 /** 1875 * Utility functions 1876 * 1877 * @class [utils] utils 1878 * @constructor 1879 */ 1880 1881 1882 var BigNumber = require('bignumber.js'); 1883 var sha3 = require('./sha3.js'); 1884 var utf8 = require('utf8'); 1885 1886 var unitMap = { 1887 'noether': '0', 1888 'wei': '1', 1889 'kwei': '1000', 1890 'Kwei': '1000', 1891 'babbage': '1000', 1892 'femtoether': '1000', 1893 'mwei': '1000000', 1894 'Mwei': '1000000', 1895 'lovelace': '1000000', 1896 'picoether': '1000000', 1897 'gwei': '1000000000', 1898 'Gwei': '1000000000', 1899 'shannon': '1000000000', 1900 'nanoether': '1000000000', 1901 'nano': '1000000000', 1902 'szabo': '1000000000000', 1903 'microether': '1000000000000', 1904 'micro': '1000000000000', 1905 'finney': '1000000000000000', 1906 'milliether': '1000000000000000', 1907 'milli': '1000000000000000', 1908 'ether': '1000000000000000000', 1909 'kether': '1000000000000000000000', 1910 'grand': '1000000000000000000000', 1911 'mether': '1000000000000000000000000', 1912 'gether': '1000000000000000000000000000', 1913 'tether': '1000000000000000000000000000000' 1914 }; 1915 1916 /** 1917 * Should be called to pad string to expected length 1918 * 1919 * @method padLeft 1920 * @param {String} string to be padded 1921 * @param {Number} characters that result string should have 1922 * @param {String} sign, by default 0 1923 * @returns {String} right aligned string 1924 */ 1925 var padLeft = function (string, chars, sign) { 1926 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1927 }; 1928 1929 /** 1930 * Should be called to pad string to expected length 1931 * 1932 * @method padRight 1933 * @param {String} string to be padded 1934 * @param {Number} characters that result string should have 1935 * @param {String} sign, by default 0 1936 * @returns {String} right aligned string 1937 */ 1938 var padRight = function (string, chars, sign) { 1939 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1940 }; 1941 1942 /** 1943 * Should be called to get utf8 from it's hex representation 1944 * 1945 * @method toUtf8 1946 * @param {String} string in hex 1947 * @returns {String} ascii string representation of hex value 1948 */ 1949 var toUtf8 = function(hex) { 1950 // Find termination 1951 var str = ""; 1952 var i = 0, l = hex.length; 1953 if (hex.substring(0, 2) === '0x') { 1954 i = 2; 1955 } 1956 for (; i < l; i+=2) { 1957 var code = parseInt(hex.substr(i, 2), 16); 1958 if (code === 0) 1959 break; 1960 str += String.fromCharCode(code); 1961 } 1962 1963 return utf8.decode(str); 1964 }; 1965 1966 /** 1967 * Should be called to get ascii from it's hex representation 1968 * 1969 * @method toAscii 1970 * @param {String} string in hex 1971 * @returns {String} ascii string representation of hex value 1972 */ 1973 var toAscii = function(hex) { 1974 // Find termination 1975 var str = ""; 1976 var i = 0, l = hex.length; 1977 if (hex.substring(0, 2) === '0x') { 1978 i = 2; 1979 } 1980 for (; i < l; i+=2) { 1981 var code = parseInt(hex.substr(i, 2), 16); 1982 str += String.fromCharCode(code); 1983 } 1984 1985 return str; 1986 }; 1987 1988 /** 1989 * Should be called to get hex representation (prefixed by 0x) of utf8 string 1990 * 1991 * @method fromUtf8 1992 * @param {String} string 1993 * @param {Number} optional padding 1994 * @returns {String} hex representation of input string 1995 */ 1996 var fromUtf8 = function(str) { 1997 str = utf8.encode(str); 1998 var hex = ""; 1999 for(var i = 0; i < str.length; i++) { 2000 var code = str.charCodeAt(i); 2001 if (code === 0) 2002 break; 2003 var n = code.toString(16); 2004 hex += n.length < 2 ? '0' + n : n; 2005 } 2006 2007 return "0x" + hex; 2008 }; 2009 2010 /** 2011 * Should be called to get hex representation (prefixed by 0x) of ascii string 2012 * 2013 * @method fromAscii 2014 * @param {String} string 2015 * @param {Number} optional padding 2016 * @returns {String} hex representation of input string 2017 */ 2018 var fromAscii = function(str) { 2019 var hex = ""; 2020 for(var i = 0; i < str.length; i++) { 2021 var code = str.charCodeAt(i); 2022 var n = code.toString(16); 2023 hex += n.length < 2 ? '0' + n : n; 2024 } 2025 2026 return "0x" + hex; 2027 }; 2028 2029 /** 2030 * Should be used to create full function/event name from json abi 2031 * 2032 * @method transformToFullName 2033 * @param {Object} json-abi 2034 * @return {String} full function/event name 2035 */ 2036 var transformToFullName = function (json) { 2037 if (json.name.indexOf('(') !== -1) { 2038 return json.name; 2039 } 2040 2041 var typeName = json.inputs.map(function(i){return i.type; }).join(); 2042 return json.name + '(' + typeName + ')'; 2043 }; 2044 2045 /** 2046 * Should be called to get display name of contract function 2047 * 2048 * @method extractDisplayName 2049 * @param {String} name of function/event 2050 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2051 */ 2052 var extractDisplayName = function (name) { 2053 var length = name.indexOf('('); 2054 return length !== -1 ? name.substr(0, length) : name; 2055 }; 2056 2057 /// @returns overloaded part of function/event name 2058 var extractTypeName = function (name) { 2059 /// TODO: make it invulnerable 2060 var length = name.indexOf('('); 2061 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2062 }; 2063 2064 /** 2065 * Converts value to it's decimal representation in string 2066 * 2067 * @method toDecimal 2068 * @param {String|Number|BigNumber} 2069 * @return {String} 2070 */ 2071 var toDecimal = function (value) { 2072 return toBigNumber(value).toNumber(); 2073 }; 2074 2075 /** 2076 * Converts value to it's hex representation 2077 * 2078 * @method fromDecimal 2079 * @param {String|Number|BigNumber} 2080 * @return {String} 2081 */ 2082 var fromDecimal = function (value) { 2083 var number = toBigNumber(value); 2084 var result = number.toString(16); 2085 2086 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2087 }; 2088 2089 /** 2090 * Auto converts any given value into it's hex representation. 2091 * 2092 * And even stringifys objects before. 2093 * 2094 * @method toHex 2095 * @param {String|Number|BigNumber|Object} 2096 * @return {String} 2097 */ 2098 var toHex = function (val) { 2099 /*jshint maxcomplexity: 8 */ 2100 2101 if (isBoolean(val)) 2102 return fromDecimal(+val); 2103 2104 if (isBigNumber(val)) 2105 return fromDecimal(val); 2106 2107 if (typeof val === 'object') 2108 return fromUtf8(JSON.stringify(val)); 2109 2110 // if its a negative number, pass it through fromDecimal 2111 if (isString(val)) { 2112 if (val.indexOf('-0x') === 0) 2113 return fromDecimal(val); 2114 else if(val.indexOf('0x') === 0) 2115 return val; 2116 else if (!isFinite(val)) 2117 return fromAscii(val); 2118 } 2119 2120 return fromDecimal(val); 2121 }; 2122 2123 /** 2124 * Returns value of unit in Wei 2125 * 2126 * @method getValueOfUnit 2127 * @param {String} unit the unit to convert to, default ether 2128 * @returns {BigNumber} value of the unit (in Wei) 2129 * @throws error if the unit is not correct:w 2130 */ 2131 var getValueOfUnit = function (unit) { 2132 unit = unit ? unit.toLowerCase() : 'ether'; 2133 var unitValue = unitMap[unit]; 2134 if (unitValue === undefined) { 2135 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2136 } 2137 return new BigNumber(unitValue, 10); 2138 }; 2139 2140 /** 2141 * Takes a number of wei and converts it to any other ether unit. 2142 * 2143 * Possible units are: 2144 * SI Short SI Full Effigy Other 2145 * - kwei femtoether babbage 2146 * - mwei picoether lovelace 2147 * - gwei nanoether shannon nano 2148 * - -- microether szabo micro 2149 * - -- milliether finney milli 2150 * - ether -- -- 2151 * - kether -- grand 2152 * - mether 2153 * - gether 2154 * - tether 2155 * 2156 * @method fromWei 2157 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2158 * @param {String} unit the unit to convert to, default ether 2159 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2160 */ 2161 var fromWei = function(number, unit) { 2162 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2163 2164 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2165 }; 2166 2167 /** 2168 * Takes a number of a unit and converts it to wei. 2169 * 2170 * Possible units are: 2171 * SI Short SI Full Effigy Other 2172 * - kwei femtoether babbage 2173 * - mwei picoether lovelace 2174 * - gwei nanoether shannon nano 2175 * - -- microether szabo micro 2176 * - -- microether szabo micro 2177 * - -- milliether finney milli 2178 * - ether -- -- 2179 * - kether -- grand 2180 * - mether 2181 * - gether 2182 * - tether 2183 * 2184 * @method toWei 2185 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2186 * @param {String} unit the unit to convert from, default ether 2187 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2188 */ 2189 var toWei = function(number, unit) { 2190 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2191 2192 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2193 }; 2194 2195 /** 2196 * Takes an input and transforms it into a bignumber 2197 * 2198 * @method toBigNumber 2199 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2200 * @return {BigNumber} BigNumber 2201 */ 2202 var toBigNumber = function(number) { 2203 /*jshint maxcomplexity:5 */ 2204 number = number || 0; 2205 if (isBigNumber(number)) 2206 return number; 2207 2208 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2209 return new BigNumber(number.replace('0x',''), 16); 2210 } 2211 2212 return new BigNumber(number.toString(10), 10); 2213 }; 2214 2215 /** 2216 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2217 * 2218 * @method toTwosComplement 2219 * @param {Number|String|BigNumber} 2220 * @return {BigNumber} 2221 */ 2222 var toTwosComplement = function (number) { 2223 var bigNumber = toBigNumber(number).round(); 2224 if (bigNumber.lessThan(0)) { 2225 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2226 } 2227 return bigNumber; 2228 }; 2229 2230 /** 2231 * Checks if the given string is strictly an address 2232 * 2233 * @method isStrictAddress 2234 * @param {String} address the given HEX address 2235 * @return {Boolean} 2236 */ 2237 var isStrictAddress = function (address) { 2238 return /^0x[0-9a-f]{40}$/i.test(address); 2239 }; 2240 2241 /** 2242 * Checks if the given string is an address 2243 * 2244 * @method isAddress 2245 * @param {String} address the given HEX address 2246 * @return {Boolean} 2247 */ 2248 var isAddress = function (address) { 2249 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2250 // check if it has the basic requirements of an address 2251 return false; 2252 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2253 // If it's all small caps or all caps, return true 2254 return true; 2255 } else { 2256 // Otherwise check each case 2257 return isChecksumAddress(address); 2258 } 2259 }; 2260 2261 /** 2262 * Checks if the given string is a checksummed address 2263 * 2264 * @method isChecksumAddress 2265 * @param {String} address the given HEX address 2266 * @return {Boolean} 2267 */ 2268 var isChecksumAddress = function (address) { 2269 // Check each case 2270 address = address.replace('0x',''); 2271 var addressHash = sha3(address.toLowerCase()); 2272 2273 for (var i = 0; i < 40; i++ ) { 2274 // the nth letter should be uppercase if the nth digit of casemap is 1 2275 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2276 return false; 2277 } 2278 } 2279 return true; 2280 }; 2281 2282 2283 2284 /** 2285 * Makes a checksum address 2286 * 2287 * @method toChecksumAddress 2288 * @param {String} address the given HEX address 2289 * @return {String} 2290 */ 2291 var toChecksumAddress = function (address) { 2292 if (typeof address === 'undefined') return ''; 2293 2294 address = address.toLowerCase().replace('0x',''); 2295 var addressHash = sha3(address); 2296 var checksumAddress = '0x'; 2297 2298 for (var i = 0; i < address.length; i++ ) { 2299 // If ith character is 9 to f then make it uppercase 2300 if (parseInt(addressHash[i], 16) > 7) { 2301 checksumAddress += address[i].toUpperCase(); 2302 } else { 2303 checksumAddress += address[i]; 2304 } 2305 } 2306 return checksumAddress; 2307 }; 2308 2309 /** 2310 * Transforms given string to valid 20 bytes-length address with 0x prefix 2311 * 2312 * @method toAddress 2313 * @param {String} address 2314 * @return {String} formatted address 2315 */ 2316 var toAddress = function (address) { 2317 if (isStrictAddress(address)) { 2318 return address; 2319 } 2320 2321 if (/^[0-9a-f]{40}$/.test(address)) { 2322 return '0x' + address; 2323 } 2324 2325 return '0x' + padLeft(toHex(address).substr(2), 40); 2326 }; 2327 2328 /** 2329 * Returns true if object is BigNumber, otherwise false 2330 * 2331 * @method isBigNumber 2332 * @param {Object} 2333 * @return {Boolean} 2334 */ 2335 var isBigNumber = function (object) { 2336 return object instanceof BigNumber || 2337 (object && object.constructor && object.constructor.name === 'BigNumber'); 2338 }; 2339 2340 /** 2341 * Returns true if object is string, otherwise false 2342 * 2343 * @method isString 2344 * @param {Object} 2345 * @return {Boolean} 2346 */ 2347 var isString = function (object) { 2348 return typeof object === 'string' || 2349 (object && object.constructor && object.constructor.name === 'String'); 2350 }; 2351 2352 /** 2353 * Returns true if object is function, otherwise false 2354 * 2355 * @method isFunction 2356 * @param {Object} 2357 * @return {Boolean} 2358 */ 2359 var isFunction = function (object) { 2360 return typeof object === 'function'; 2361 }; 2362 2363 /** 2364 * Returns true if object is Object, otherwise false 2365 * 2366 * @method isObject 2367 * @param {Object} 2368 * @return {Boolean} 2369 */ 2370 var isObject = function (object) { 2371 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2372 }; 2373 2374 /** 2375 * Returns true if object is boolean, otherwise false 2376 * 2377 * @method isBoolean 2378 * @param {Object} 2379 * @return {Boolean} 2380 */ 2381 var isBoolean = function (object) { 2382 return typeof object === 'boolean'; 2383 }; 2384 2385 /** 2386 * Returns true if object is array, otherwise false 2387 * 2388 * @method isArray 2389 * @param {Object} 2390 * @return {Boolean} 2391 */ 2392 var isArray = function (object) { 2393 return object instanceof Array; 2394 }; 2395 2396 /** 2397 * Returns true if given string is valid json object 2398 * 2399 * @method isJson 2400 * @param {String} 2401 * @return {Boolean} 2402 */ 2403 var isJson = function (str) { 2404 try { 2405 return !!JSON.parse(str); 2406 } catch (e) { 2407 return false; 2408 } 2409 }; 2410 2411 /** 2412 * Returns true if given string is a valid Ethereum block header bloom. 2413 * 2414 * @method isBloom 2415 * @param {String} hex encoded bloom filter 2416 * @return {Boolean} 2417 */ 2418 var isBloom = function (bloom) { 2419 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2420 return false; 2421 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2422 return true; 2423 } 2424 return false; 2425 }; 2426 2427 /** 2428 * Returns true if given string is a valid log topic. 2429 * 2430 * @method isTopic 2431 * @param {String} hex encoded topic 2432 * @return {Boolean} 2433 */ 2434 var isTopic = function (topic) { 2435 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2436 return false; 2437 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2438 return true; 2439 } 2440 return false; 2441 }; 2442 2443 module.exports = { 2444 padLeft: padLeft, 2445 padRight: padRight, 2446 toHex: toHex, 2447 toDecimal: toDecimal, 2448 fromDecimal: fromDecimal, 2449 toUtf8: toUtf8, 2450 toAscii: toAscii, 2451 fromUtf8: fromUtf8, 2452 fromAscii: fromAscii, 2453 transformToFullName: transformToFullName, 2454 extractDisplayName: extractDisplayName, 2455 extractTypeName: extractTypeName, 2456 toWei: toWei, 2457 fromWei: fromWei, 2458 toBigNumber: toBigNumber, 2459 toTwosComplement: toTwosComplement, 2460 toAddress: toAddress, 2461 isBigNumber: isBigNumber, 2462 isStrictAddress: isStrictAddress, 2463 isAddress: isAddress, 2464 isChecksumAddress: isChecksumAddress, 2465 toChecksumAddress: toChecksumAddress, 2466 isFunction: isFunction, 2467 isString: isString, 2468 isObject: isObject, 2469 isBoolean: isBoolean, 2470 isArray: isArray, 2471 isJson: isJson, 2472 isBloom: isBloom, 2473 isTopic: isTopic, 2474 }; 2475 2476 },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){ 2477 module.exports={ 2478 "version": "0.20.1" 2479 } 2480 2481 },{}],22:[function(require,module,exports){ 2482 /* 2483 This file is part of web3.js. 2484 2485 web3.js is free software: you can redistribute it and/or modify 2486 it under the terms of the GNU Lesser General Public License as published by 2487 the Free Software Foundation, either version 3 of the License, or 2488 (at your option) any later version. 2489 2490 web3.js is distributed in the hope that it will be useful, 2491 but WITHOUT ANY WARRANTY; without even the implied warranty of 2492 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2493 GNU Lesser General Public License for more details. 2494 2495 You should have received a copy of the GNU Lesser General Public License 2496 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2497 */ 2498 /** 2499 * @file web3.js 2500 * @authors: 2501 * Jeffrey Wilcke <jeff@ethdev.com> 2502 * Marek Kotewicz <marek@ethdev.com> 2503 * Marian Oancea <marian@ethdev.com> 2504 * Fabian Vogelsteller <fabian@ethdev.com> 2505 * Gav Wood <g@ethdev.com> 2506 * @date 2014 2507 */ 2508 2509 var RequestManager = require('./web3/requestmanager'); 2510 var Iban = require('./web3/iban'); 2511 var Eth = require('./web3/methods/eth'); 2512 var DB = require('./web3/methods/db'); 2513 var Net = require('./web3/methods/net'); 2514 var Personal = require('./web3/methods/personal'); 2515 var Settings = require('./web3/settings'); 2516 var version = require('./version.json'); 2517 var utils = require('./utils/utils'); 2518 var sha3 = require('./utils/sha3'); 2519 var extend = require('./web3/extend'); 2520 var Batch = require('./web3/batch'); 2521 var Property = require('./web3/property'); 2522 var HttpProvider = require('./web3/httpprovider'); 2523 var IpcProvider = require('./web3/ipcprovider'); 2524 var BigNumber = require('bignumber.js'); 2525 2526 2527 2528 function Web3 (provider) { 2529 this._requestManager = new RequestManager(provider); 2530 this.currentProvider = provider; 2531 this.eth = new Eth(this); 2532 this.db = new DB(this); 2533 this.net = new Net(this); 2534 this.personal = new Personal(this); 2535 this.settings = new Settings(); 2536 this.version = { 2537 api: version.version 2538 }; 2539 this.providers = { 2540 HttpProvider: HttpProvider, 2541 IpcProvider: IpcProvider 2542 }; 2543 this._extend = extend(this); 2544 this._extend({ 2545 properties: properties() 2546 }); 2547 } 2548 2549 // expose providers on the class 2550 Web3.providers = { 2551 HttpProvider: HttpProvider, 2552 IpcProvider: IpcProvider 2553 }; 2554 2555 Web3.prototype.setProvider = function (provider) { 2556 this._requestManager.setProvider(provider); 2557 this.currentProvider = provider; 2558 }; 2559 2560 Web3.prototype.reset = function (keepIsSyncing) { 2561 this._requestManager.reset(keepIsSyncing); 2562 this.settings = new Settings(); 2563 }; 2564 2565 Web3.prototype.BigNumber = BigNumber; 2566 Web3.prototype.toHex = utils.toHex; 2567 Web3.prototype.toAscii = utils.toAscii; 2568 Web3.prototype.toUtf8 = utils.toUtf8; 2569 Web3.prototype.fromAscii = utils.fromAscii; 2570 Web3.prototype.fromUtf8 = utils.fromUtf8; 2571 Web3.prototype.toDecimal = utils.toDecimal; 2572 Web3.prototype.fromDecimal = utils.fromDecimal; 2573 Web3.prototype.toBigNumber = utils.toBigNumber; 2574 Web3.prototype.toWei = utils.toWei; 2575 Web3.prototype.fromWei = utils.fromWei; 2576 Web3.prototype.isAddress = utils.isAddress; 2577 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2578 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2579 Web3.prototype.isIBAN = utils.isIBAN; 2580 Web3.prototype.padLeft = utils.padLeft; 2581 Web3.prototype.padRight = utils.padRight; 2582 2583 2584 Web3.prototype.sha3 = function(string, options) { 2585 return '0x' + sha3(string, options); 2586 }; 2587 2588 /** 2589 * Transforms direct icap to address 2590 */ 2591 Web3.prototype.fromICAP = function (icap) { 2592 var iban = new Iban(icap); 2593 return iban.address(); 2594 }; 2595 2596 var properties = function () { 2597 return [ 2598 new Property({ 2599 name: 'version.node', 2600 getter: 'web3_clientVersion' 2601 }), 2602 new Property({ 2603 name: 'version.network', 2604 getter: 'net_version', 2605 inputFormatter: utils.toDecimal 2606 }), 2607 new Property({ 2608 name: 'version.ethereum', 2609 getter: 'eth_protocolVersion', 2610 inputFormatter: utils.toDecimal 2611 }) 2612 ]; 2613 }; 2614 2615 Web3.prototype.isConnected = function(){ 2616 return (this.currentProvider && this.currentProvider.isConnected()); 2617 }; 2618 2619 Web3.prototype.createBatch = function () { 2620 return new Batch(this); 2621 }; 2622 2623 module.exports = Web3; 2624 2625 2626 },{"./utils/sha3":19,"./utils/utils":20,"./version.json":21,"./web3/batch":24,"./web3/extend":28,"./web3/httpprovider":32,"./web3/iban":33,"./web3/ipcprovider":34,"./web3/methods/db":37,"./web3/methods/eth":38,"./web3/methods/net":39,"./web3/methods/personal":40,"./web3/property":45,"./web3/requestmanager":46,"./web3/settings":47,"bignumber.js":"bignumber.js"}],23:[function(require,module,exports){ 2627 /* 2628 This file is part of web3.js. 2629 2630 web3.js is free software: you can redistribute it and/or modify 2631 it under the terms of the GNU Lesser General Public License as published by 2632 the Free Software Foundation, either version 3 of the License, or 2633 (at your option) any later version. 2634 2635 web3.js is distributed in the hope that it will be useful, 2636 but WITHOUT ANY WARRANTY; without even the implied warranty of 2637 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2638 GNU Lesser General Public License for more details. 2639 2640 You should have received a copy of the GNU Lesser General Public License 2641 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2642 */ 2643 /** 2644 * @file allevents.js 2645 * @author Marek Kotewicz <marek@ethdev.com> 2646 * @date 2014 2647 */ 2648 2649 var sha3 = require('../utils/sha3'); 2650 var SolidityEvent = require('./event'); 2651 var formatters = require('./formatters'); 2652 var utils = require('../utils/utils'); 2653 var Filter = require('./filter'); 2654 var watches = require('./methods/watches'); 2655 2656 var AllSolidityEvents = function (requestManager, json, address) { 2657 this._requestManager = requestManager; 2658 this._json = json; 2659 this._address = address; 2660 }; 2661 2662 AllSolidityEvents.prototype.encode = function (options) { 2663 options = options || {}; 2664 var result = {}; 2665 2666 ['fromBlock', 'toBlock'].filter(function (f) { 2667 return options[f] !== undefined; 2668 }).forEach(function (f) { 2669 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2670 }); 2671 2672 result.address = this._address; 2673 2674 return result; 2675 }; 2676 2677 AllSolidityEvents.prototype.decode = function (data) { 2678 data.data = data.data || ''; 2679 data.topics = data.topics || []; 2680 2681 var eventTopic = data.topics[0].slice(2); 2682 var match = this._json.filter(function (j) { 2683 return eventTopic === sha3(utils.transformToFullName(j)); 2684 })[0]; 2685 2686 if (!match) { // cannot find matching event? 2687 console.warn('cannot find event for log'); 2688 return data; 2689 } 2690 2691 var event = new SolidityEvent(this._requestManager, match, this._address); 2692 return event.decode(data); 2693 }; 2694 2695 AllSolidityEvents.prototype.execute = function (options, callback) { 2696 2697 if (utils.isFunction(arguments[arguments.length - 1])) { 2698 callback = arguments[arguments.length - 1]; 2699 if(arguments.length === 1) 2700 options = null; 2701 } 2702 2703 var o = this.encode(options); 2704 var formatter = this.decode.bind(this); 2705 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 2706 }; 2707 2708 AllSolidityEvents.prototype.attachToContract = function (contract) { 2709 var execute = this.execute.bind(this); 2710 contract.allEvents = execute; 2711 }; 2712 2713 module.exports = AllSolidityEvents; 2714 2715 2716 },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){ 2717 /* 2718 This file is part of web3.js. 2719 2720 web3.js is free software: you can redistribute it and/or modify 2721 it under the terms of the GNU Lesser General Public License as published by 2722 the Free Software Foundation, either version 3 of the License, or 2723 (at your option) any later version. 2724 2725 web3.js is distributed in the hope that it will be useful, 2726 but WITHOUT ANY WARRANTY; without even the implied warranty of 2727 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2728 GNU Lesser General Public License for more details. 2729 2730 You should have received a copy of the GNU Lesser General Public License 2731 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2732 */ 2733 /** 2734 * @file batch.js 2735 * @author Marek Kotewicz <marek@ethdev.com> 2736 * @date 2015 2737 */ 2738 2739 var Jsonrpc = require('./jsonrpc'); 2740 var errors = require('./errors'); 2741 2742 var Batch = function (web3) { 2743 this.requestManager = web3._requestManager; 2744 this.requests = []; 2745 }; 2746 2747 /** 2748 * Should be called to add create new request to batch request 2749 * 2750 * @method add 2751 * @param {Object} jsonrpc request object 2752 */ 2753 Batch.prototype.add = function (request) { 2754 this.requests.push(request); 2755 }; 2756 2757 /** 2758 * Should be called to execute batch request 2759 * 2760 * @method execute 2761 */ 2762 Batch.prototype.execute = function () { 2763 var requests = this.requests; 2764 this.requestManager.sendBatch(requests, function (err, results) { 2765 results = results || []; 2766 requests.map(function (request, index) { 2767 return results[index] || {}; 2768 }).forEach(function (result, index) { 2769 if (requests[index].callback) { 2770 2771 if (!Jsonrpc.isValidResponse(result)) { 2772 return requests[index].callback(errors.InvalidResponse(result)); 2773 } 2774 2775 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2776 } 2777 }); 2778 }); 2779 }; 2780 2781 module.exports = Batch; 2782 2783 2784 },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){ 2785 /* 2786 This file is part of web3.js. 2787 2788 web3.js is free software: you can redistribute it and/or modify 2789 it under the terms of the GNU Lesser General Public License as published by 2790 the Free Software Foundation, either version 3 of the License, or 2791 (at your option) any later version. 2792 2793 web3.js is distributed in the hope that it will be useful, 2794 but WITHOUT ANY WARRANTY; without even the implied warranty of 2795 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2796 GNU Lesser General Public License for more details. 2797 2798 You should have received a copy of the GNU Lesser General Public License 2799 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2800 */ 2801 /** 2802 * @file contract.js 2803 * @author Marek Kotewicz <marek@ethdev.com> 2804 * @date 2014 2805 */ 2806 2807 var utils = require('../utils/utils'); 2808 var coder = require('../solidity/coder'); 2809 var SolidityEvent = require('./event'); 2810 var SolidityFunction = require('./function'); 2811 var AllEvents = require('./allevents'); 2812 2813 /** 2814 * Should be called to encode constructor params 2815 * 2816 * @method encodeConstructorParams 2817 * @param {Array} abi 2818 * @param {Array} constructor params 2819 */ 2820 var encodeConstructorParams = function (abi, params) { 2821 return abi.filter(function (json) { 2822 return json.type === 'constructor' && json.inputs.length === params.length; 2823 }).map(function (json) { 2824 return json.inputs.map(function (input) { 2825 return input.type; 2826 }); 2827 }).map(function (types) { 2828 return coder.encodeParams(types, params); 2829 })[0] || ''; 2830 }; 2831 2832 /** 2833 * Should be called to add functions to contract object 2834 * 2835 * @method addFunctionsToContract 2836 * @param {Contract} contract 2837 * @param {Array} abi 2838 */ 2839 var addFunctionsToContract = function (contract) { 2840 contract.abi.filter(function (json) { 2841 return json.type === 'function'; 2842 }).map(function (json) { 2843 return new SolidityFunction(contract._eth, json, contract.address); 2844 }).forEach(function (f) { 2845 f.attachToContract(contract); 2846 }); 2847 }; 2848 2849 /** 2850 * Should be called to add events to contract object 2851 * 2852 * @method addEventsToContract 2853 * @param {Contract} contract 2854 * @param {Array} abi 2855 */ 2856 var addEventsToContract = function (contract) { 2857 var events = contract.abi.filter(function (json) { 2858 return json.type === 'event'; 2859 }); 2860 2861 var All = new AllEvents(contract._eth._requestManager, events, contract.address); 2862 All.attachToContract(contract); 2863 2864 events.map(function (json) { 2865 return new SolidityEvent(contract._eth._requestManager, json, contract.address); 2866 }).forEach(function (e) { 2867 e.attachToContract(contract); 2868 }); 2869 }; 2870 2871 2872 /** 2873 * Should be called to check if the contract gets properly deployed on the blockchain. 2874 * 2875 * @method checkForContractAddress 2876 * @param {Object} contract 2877 * @param {Function} callback 2878 * @returns {Undefined} 2879 */ 2880 var checkForContractAddress = function(contract, callback){ 2881 var count = 0, 2882 callbackFired = false; 2883 2884 // wait for receipt 2885 var filter = contract._eth.filter('latest', function(e){ 2886 if (!e && !callbackFired) { 2887 count++; 2888 2889 // stop watching after 50 blocks (timeout) 2890 if (count > 50) { 2891 2892 filter.stopWatching(function() {}); 2893 callbackFired = true; 2894 2895 if (callback) 2896 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2897 else 2898 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2899 2900 2901 } else { 2902 2903 contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 2904 if(receipt && !callbackFired) { 2905 2906 contract._eth.getCode(receipt.contractAddress, function(e, code){ 2907 /*jshint maxcomplexity: 6 */ 2908 2909 if(callbackFired || !code) 2910 return; 2911 2912 filter.stopWatching(function() {}); 2913 callbackFired = true; 2914 2915 if(code.length > 3) { 2916 2917 // console.log('Contract code deployed!'); 2918 2919 contract.address = receipt.contractAddress; 2920 2921 // attach events and methods again after we have 2922 addFunctionsToContract(contract); 2923 addEventsToContract(contract); 2924 2925 // call callback for the second time 2926 if(callback) 2927 callback(null, contract); 2928 2929 } else { 2930 if(callback) 2931 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 2932 else 2933 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 2934 } 2935 }); 2936 } 2937 }); 2938 } 2939 } 2940 }); 2941 }; 2942 2943 /** 2944 * Should be called to create new ContractFactory instance 2945 * 2946 * @method ContractFactory 2947 * @param {Array} abi 2948 */ 2949 var ContractFactory = function (eth, abi) { 2950 this.eth = eth; 2951 this.abi = abi; 2952 2953 /** 2954 * Should be called to create new contract on a blockchain 2955 * 2956 * @method new 2957 * @param {Any} contract constructor param1 (optional) 2958 * @param {Any} contract constructor param2 (optional) 2959 * @param {Object} contract transaction object (required) 2960 * @param {Function} callback 2961 * @returns {Contract} returns contract instance 2962 */ 2963 this.new = function () { 2964 /*jshint maxcomplexity: 7 */ 2965 2966 var contract = new Contract(this.eth, this.abi); 2967 2968 // parse arguments 2969 var options = {}; // required! 2970 var callback; 2971 2972 var args = Array.prototype.slice.call(arguments); 2973 if (utils.isFunction(args[args.length - 1])) { 2974 callback = args.pop(); 2975 } 2976 2977 var last = args[args.length - 1]; 2978 if (utils.isObject(last) && !utils.isArray(last)) { 2979 options = args.pop(); 2980 } 2981 2982 if (options.value > 0) { 2983 var constructorAbi = abi.filter(function (json) { 2984 return json.type === 'constructor' && json.inputs.length === args.length; 2985 })[0] || {}; 2986 2987 if (!constructorAbi.payable) { 2988 throw new Error('Cannot send value to non-payable constructor'); 2989 } 2990 } 2991 2992 var bytes = encodeConstructorParams(this.abi, args); 2993 options.data += bytes; 2994 2995 if (callback) { 2996 2997 // wait for the contract address and check if the code was deployed 2998 this.eth.sendTransaction(options, function (err, hash) { 2999 if (err) { 3000 callback(err); 3001 } else { 3002 // add the transaction hash 3003 contract.transactionHash = hash; 3004 3005 // call callback for the first time 3006 callback(null, contract); 3007 3008 checkForContractAddress(contract, callback); 3009 } 3010 }); 3011 } else { 3012 var hash = this.eth.sendTransaction(options); 3013 // add the transaction hash 3014 contract.transactionHash = hash; 3015 checkForContractAddress(contract); 3016 } 3017 3018 return contract; 3019 }; 3020 3021 this.new.getData = this.getData.bind(this); 3022 }; 3023 3024 /** 3025 * Should be called to create new ContractFactory 3026 * 3027 * @method contract 3028 * @param {Array} abi 3029 * @returns {ContractFactory} new contract factory 3030 */ 3031 //var contract = function (abi) { 3032 //return new ContractFactory(abi); 3033 //}; 3034 3035 3036 3037 /** 3038 * Should be called to get access to existing contract on a blockchain 3039 * 3040 * @method at 3041 * @param {Address} contract address (required) 3042 * @param {Function} callback {optional) 3043 * @returns {Contract} returns contract if no callback was passed, 3044 * otherwise calls callback function (err, contract) 3045 */ 3046 ContractFactory.prototype.at = function (address, callback) { 3047 var contract = new Contract(this.eth, this.abi, address); 3048 3049 // this functions are not part of prototype, 3050 // because we don't want to spoil the interface 3051 addFunctionsToContract(contract); 3052 addEventsToContract(contract); 3053 3054 if (callback) { 3055 callback(null, contract); 3056 } 3057 return contract; 3058 }; 3059 3060 /** 3061 * Gets the data, which is data to deploy plus constructor params 3062 * 3063 * @method getData 3064 */ 3065 ContractFactory.prototype.getData = function () { 3066 var options = {}; // required! 3067 var args = Array.prototype.slice.call(arguments); 3068 3069 var last = args[args.length - 1]; 3070 if (utils.isObject(last) && !utils.isArray(last)) { 3071 options = args.pop(); 3072 } 3073 3074 var bytes = encodeConstructorParams(this.abi, args); 3075 options.data += bytes; 3076 3077 return options.data; 3078 }; 3079 3080 /** 3081 * Should be called to create new contract instance 3082 * 3083 * @method Contract 3084 * @param {Array} abi 3085 * @param {Address} contract address 3086 */ 3087 var Contract = function (eth, abi, address) { 3088 this._eth = eth; 3089 this.transactionHash = null; 3090 this.address = address; 3091 this.abi = abi; 3092 }; 3093 3094 module.exports = ContractFactory; 3095 3096 },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){ 3097 /* 3098 This file is part of web3.js. 3099 3100 web3.js is free software: you can redistribute it and/or modify 3101 it under the terms of the GNU Lesser General Public License as published by 3102 the Free Software Foundation, either version 3 of the License, or 3103 (at your option) any later version. 3104 3105 web3.js is distributed in the hope that it will be useful, 3106 but WITHOUT ANY WARRANTY; without even the implied warranty of 3107 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3108 GNU Lesser General Public License for more details. 3109 3110 You should have received a copy of the GNU Lesser General Public License 3111 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3112 */ 3113 /** 3114 * @file errors.js 3115 * @author Marek Kotewicz <marek@ethdev.com> 3116 * @date 2015 3117 */ 3118 3119 module.exports = { 3120 InvalidNumberOfSolidityArgs: function () { 3121 return new Error('Invalid number of arguments to Solidity function'); 3122 }, 3123 InvalidNumberOfRPCParams: function () { 3124 return new Error('Invalid number of input parameters to RPC method'); 3125 }, 3126 InvalidConnection: function (host){ 3127 return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 3128 }, 3129 InvalidProvider: function () { 3130 return new Error('Provider not set or invalid'); 3131 }, 3132 InvalidResponse: function (result){ 3133 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3134 return new Error(message); 3135 }, 3136 ConnectionTimeout: function (ms){ 3137 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3138 } 3139 }; 3140 3141 },{}],27:[function(require,module,exports){ 3142 /* 3143 This file is part of web3.js. 3144 3145 web3.js is free software: you can redistribute it and/or modify 3146 it under the terms of the GNU Lesser General Public License as published by 3147 the Free Software Foundation, either version 3 of the License, or 3148 (at your option) any later version. 3149 3150 web3.js is distributed in the hope that it will be useful, 3151 but WITHOUT ANY WARRANTY; without even the implied warranty of 3152 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3153 GNU Lesser General Public License for more details. 3154 3155 You should have received a copy of the GNU Lesser General Public License 3156 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3157 */ 3158 /** 3159 * @file event.js 3160 * @author Marek Kotewicz <marek@ethdev.com> 3161 * @date 2014 3162 */ 3163 3164 var utils = require('../utils/utils'); 3165 var coder = require('../solidity/coder'); 3166 var formatters = require('./formatters'); 3167 var sha3 = require('../utils/sha3'); 3168 var Filter = require('./filter'); 3169 var watches = require('./methods/watches'); 3170 3171 /** 3172 * This prototype should be used to create event filters 3173 */ 3174 var SolidityEvent = function (requestManager, json, address) { 3175 this._requestManager = requestManager; 3176 this._params = json.inputs; 3177 this._name = utils.transformToFullName(json); 3178 this._address = address; 3179 this._anonymous = json.anonymous; 3180 }; 3181 3182 /** 3183 * Should be used to get filtered param types 3184 * 3185 * @method types 3186 * @param {Bool} decide if returned typed should be indexed 3187 * @return {Array} array of types 3188 */ 3189 SolidityEvent.prototype.types = function (indexed) { 3190 return this._params.filter(function (i) { 3191 return i.indexed === indexed; 3192 }).map(function (i) { 3193 return i.type; 3194 }); 3195 }; 3196 3197 /** 3198 * Should be used to get event display name 3199 * 3200 * @method displayName 3201 * @return {String} event display name 3202 */ 3203 SolidityEvent.prototype.displayName = function () { 3204 return utils.extractDisplayName(this._name); 3205 }; 3206 3207 /** 3208 * Should be used to get event type name 3209 * 3210 * @method typeName 3211 * @return {String} event type name 3212 */ 3213 SolidityEvent.prototype.typeName = function () { 3214 return utils.extractTypeName(this._name); 3215 }; 3216 3217 /** 3218 * Should be used to get event signature 3219 * 3220 * @method signature 3221 * @return {String} event signature 3222 */ 3223 SolidityEvent.prototype.signature = function () { 3224 return sha3(this._name); 3225 }; 3226 3227 /** 3228 * Should be used to encode indexed params and options to one final object 3229 * 3230 * @method encode 3231 * @param {Object} indexed 3232 * @param {Object} options 3233 * @return {Object} everything combined together and encoded 3234 */ 3235 SolidityEvent.prototype.encode = function (indexed, options) { 3236 indexed = indexed || {}; 3237 options = options || {}; 3238 var result = {}; 3239 3240 ['fromBlock', 'toBlock'].filter(function (f) { 3241 return options[f] !== undefined; 3242 }).forEach(function (f) { 3243 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3244 }); 3245 3246 result.topics = []; 3247 3248 result.address = this._address; 3249 if (!this._anonymous) { 3250 result.topics.push('0x' + this.signature()); 3251 } 3252 3253 var indexedTopics = this._params.filter(function (i) { 3254 return i.indexed === true; 3255 }).map(function (i) { 3256 var value = indexed[i.name]; 3257 if (value === undefined || value === null) { 3258 return null; 3259 } 3260 3261 if (utils.isArray(value)) { 3262 return value.map(function (v) { 3263 return '0x' + coder.encodeParam(i.type, v); 3264 }); 3265 } 3266 return '0x' + coder.encodeParam(i.type, value); 3267 }); 3268 3269 result.topics = result.topics.concat(indexedTopics); 3270 3271 return result; 3272 }; 3273 3274 /** 3275 * Should be used to decode indexed params and options 3276 * 3277 * @method decode 3278 * @param {Object} data 3279 * @return {Object} result object with decoded indexed && not indexed params 3280 */ 3281 SolidityEvent.prototype.decode = function (data) { 3282 3283 data.data = data.data || ''; 3284 data.topics = data.topics || []; 3285 3286 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3287 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3288 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3289 3290 var notIndexedData = data.data.slice(2); 3291 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3292 3293 var result = formatters.outputLogFormatter(data); 3294 result.event = this.displayName(); 3295 result.address = data.address; 3296 3297 result.args = this._params.reduce(function (acc, current) { 3298 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3299 return acc; 3300 }, {}); 3301 3302 delete result.data; 3303 delete result.topics; 3304 3305 return result; 3306 }; 3307 3308 /** 3309 * Should be used to create new filter object from event 3310 * 3311 * @method execute 3312 * @param {Object} indexed 3313 * @param {Object} options 3314 * @return {Object} filter object 3315 */ 3316 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3317 3318 if (utils.isFunction(arguments[arguments.length - 1])) { 3319 callback = arguments[arguments.length - 1]; 3320 if(arguments.length === 2) 3321 options = null; 3322 if(arguments.length === 1) { 3323 options = null; 3324 indexed = {}; 3325 } 3326 } 3327 3328 var o = this.encode(indexed, options); 3329 var formatter = this.decode.bind(this); 3330 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 3331 }; 3332 3333 /** 3334 * Should be used to attach event to contract object 3335 * 3336 * @method attachToContract 3337 * @param {Contract} 3338 */ 3339 SolidityEvent.prototype.attachToContract = function (contract) { 3340 var execute = this.execute.bind(this); 3341 var displayName = this.displayName(); 3342 if (!contract[displayName]) { 3343 contract[displayName] = execute; 3344 } 3345 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3346 }; 3347 3348 module.exports = SolidityEvent; 3349 3350 3351 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){ 3352 var formatters = require('./formatters'); 3353 var utils = require('./../utils/utils'); 3354 var Method = require('./method'); 3355 var Property = require('./property'); 3356 3357 // TODO: refactor, so the input params are not altered. 3358 // it's necessary to make same 'extension' work with multiple providers 3359 var extend = function (web3) { 3360 /* jshint maxcomplexity:5 */ 3361 var ex = function (extension) { 3362 3363 var extendedObject; 3364 if (extension.property) { 3365 if (!web3[extension.property]) { 3366 web3[extension.property] = {}; 3367 } 3368 extendedObject = web3[extension.property]; 3369 } else { 3370 extendedObject = web3; 3371 } 3372 3373 if (extension.methods) { 3374 extension.methods.forEach(function (method) { 3375 method.attachToObject(extendedObject); 3376 method.setRequestManager(web3._requestManager); 3377 }); 3378 } 3379 3380 if (extension.properties) { 3381 extension.properties.forEach(function (property) { 3382 property.attachToObject(extendedObject); 3383 property.setRequestManager(web3._requestManager); 3384 }); 3385 } 3386 }; 3387 3388 ex.formatters = formatters; 3389 ex.utils = utils; 3390 ex.Method = Method; 3391 ex.Property = Property; 3392 3393 return ex; 3394 }; 3395 3396 3397 3398 module.exports = extend; 3399 3400 3401 },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){ 3402 /* 3403 This file is part of web3.js. 3404 3405 web3.js is free software: you can redistribute it and/or modify 3406 it under the terms of the GNU Lesser General Public License as published by 3407 the Free Software Foundation, either version 3 of the License, or 3408 (at your option) any later version. 3409 3410 web3.js is distributed in the hope that it will be useful, 3411 but WITHOUT ANY WARRANTY; without even the implied warranty of 3412 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3413 GNU Lesser General Public License for more details. 3414 3415 You should have received a copy of the GNU Lesser General Public License 3416 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3417 */ 3418 /** @file filter.js 3419 * @authors: 3420 * Jeffrey Wilcke <jeff@ethdev.com> 3421 * Marek Kotewicz <marek@ethdev.com> 3422 * Marian Oancea <marian@ethdev.com> 3423 * Fabian Vogelsteller <fabian@ethdev.com> 3424 * Gav Wood <g@ethdev.com> 3425 * @date 2014 3426 */ 3427 3428 var formatters = require('./formatters'); 3429 var utils = require('../utils/utils'); 3430 3431 /** 3432 * Converts a given topic to a hex string, but also allows null values. 3433 * 3434 * @param {Mixed} value 3435 * @return {String} 3436 */ 3437 var toTopic = function(value){ 3438 3439 if(value === null || typeof value === 'undefined') 3440 return null; 3441 3442 value = String(value); 3443 3444 if(value.indexOf('0x') === 0) 3445 return value; 3446 else 3447 return utils.fromUtf8(value); 3448 }; 3449 3450 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3451 /// @param should be string or object 3452 /// @returns options string or object 3453 var getOptions = function (options, type) { 3454 /*jshint maxcomplexity: 6 */ 3455 3456 if (utils.isString(options)) { 3457 return options; 3458 } 3459 3460 options = options || {}; 3461 3462 3463 switch(type) { 3464 case 'eth': 3465 3466 // make sure topics, get converted to hex 3467 options.topics = options.topics || []; 3468 options.topics = options.topics.map(function(topic){ 3469 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3470 }); 3471 3472 return { 3473 topics: options.topics, 3474 from: options.from, 3475 to: options.to, 3476 address: options.address, 3477 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3478 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3479 }; 3480 } 3481 }; 3482 3483 /** 3484 Adds the callback and sets up the methods, to iterate over the results. 3485 3486 @method getLogsAtStart 3487 @param {Object} self 3488 @param {function} callback 3489 */ 3490 var getLogsAtStart = function(self, callback){ 3491 // call getFilterLogs for the first watch callback start 3492 if (!utils.isString(self.options)) { 3493 self.get(function (err, messages) { 3494 // don't send all the responses to all the watches again... just to self one 3495 if (err) { 3496 callback(err); 3497 } 3498 3499 if(utils.isArray(messages)) { 3500 messages.forEach(function (message) { 3501 callback(null, message); 3502 }); 3503 } 3504 }); 3505 } 3506 }; 3507 3508 /** 3509 Adds the callback and sets up the methods, to iterate over the results. 3510 3511 @method pollFilter 3512 @param {Object} self 3513 */ 3514 var pollFilter = function(self) { 3515 3516 var onMessage = function (error, messages) { 3517 if (error) { 3518 return self.callbacks.forEach(function (callback) { 3519 callback(error); 3520 }); 3521 } 3522 3523 if(utils.isArray(messages)) { 3524 messages.forEach(function (message) { 3525 message = self.formatter ? self.formatter(message) : message; 3526 self.callbacks.forEach(function (callback) { 3527 callback(null, message); 3528 }); 3529 }); 3530 } 3531 }; 3532 3533 self.requestManager.startPolling({ 3534 method: self.implementation.poll.call, 3535 params: [self.filterId], 3536 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3537 3538 }; 3539 3540 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3541 var self = this; 3542 var implementation = {}; 3543 methods.forEach(function (method) { 3544 method.setRequestManager(requestManager); 3545 method.attachToObject(implementation); 3546 }); 3547 this.requestManager = requestManager; 3548 this.options = getOptions(options, type); 3549 this.implementation = implementation; 3550 this.filterId = null; 3551 this.callbacks = []; 3552 this.getLogsCallbacks = []; 3553 this.pollFilters = []; 3554 this.formatter = formatter; 3555 this.implementation.newFilter(this.options, function(error, id){ 3556 if(error) { 3557 self.callbacks.forEach(function(cb){ 3558 cb(error); 3559 }); 3560 if (typeof filterCreationErrorCallback === 'function') { 3561 filterCreationErrorCallback(error); 3562 } 3563 } else { 3564 self.filterId = id; 3565 3566 // check if there are get pending callbacks as a consequence 3567 // of calling get() with filterId unassigned. 3568 self.getLogsCallbacks.forEach(function (cb){ 3569 self.get(cb); 3570 }); 3571 self.getLogsCallbacks = []; 3572 3573 // get filter logs for the already existing watch calls 3574 self.callbacks.forEach(function(cb){ 3575 getLogsAtStart(self, cb); 3576 }); 3577 if(self.callbacks.length > 0) 3578 pollFilter(self); 3579 3580 // start to watch immediately 3581 if(typeof callback === 'function') { 3582 return self.watch(callback); 3583 } 3584 } 3585 }); 3586 3587 return this; 3588 }; 3589 3590 Filter.prototype.watch = function (callback) { 3591 this.callbacks.push(callback); 3592 3593 if(this.filterId) { 3594 getLogsAtStart(this, callback); 3595 pollFilter(this); 3596 } 3597 3598 return this; 3599 }; 3600 3601 Filter.prototype.stopWatching = function (callback) { 3602 this.requestManager.stopPolling(this.filterId); 3603 this.callbacks = []; 3604 // remove filter async 3605 if (callback) { 3606 this.implementation.uninstallFilter(this.filterId, callback); 3607 } else { 3608 return this.implementation.uninstallFilter(this.filterId); 3609 } 3610 }; 3611 3612 Filter.prototype.get = function (callback) { 3613 var self = this; 3614 if (utils.isFunction(callback)) { 3615 if (this.filterId === null) { 3616 // If filterId is not set yet, call it back 3617 // when newFilter() assigns it. 3618 this.getLogsCallbacks.push(callback); 3619 } else { 3620 this.implementation.getLogs(this.filterId, function(err, res){ 3621 if (err) { 3622 callback(err); 3623 } else { 3624 callback(null, res.map(function (log) { 3625 return self.formatter ? self.formatter(log) : log; 3626 })); 3627 } 3628 }); 3629 } 3630 } else { 3631 if (this.filterId === null) { 3632 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3633 } 3634 var logs = this.implementation.getLogs(this.filterId); 3635 return logs.map(function (log) { 3636 return self.formatter ? self.formatter(log) : log; 3637 }); 3638 } 3639 3640 return this; 3641 }; 3642 3643 module.exports = Filter; 3644 3645 3646 },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){ 3647 'use strict' 3648 3649 /* 3650 This file is part of web3.js. 3651 3652 web3.js is free software: you can redistribute it and/or modify 3653 it under the terms of the GNU Lesser General Public License as published by 3654 the Free Software Foundation, either version 3 of the License, or 3655 (at your option) any later version. 3656 3657 web3.js is distributed in the hope that it will be useful, 3658 but WITHOUT ANY WARRANTY; without even the implied warranty of 3659 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3660 GNU Lesser General Public License for more details. 3661 3662 You should have received a copy of the GNU Lesser General Public License 3663 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3664 */ 3665 /** 3666 * @file formatters.js 3667 * @author Marek Kotewicz <marek@ethdev.com> 3668 * @author Fabian Vogelsteller <fabian@ethdev.com> 3669 * @date 2015 3670 */ 3671 3672 var utils = require('../utils/utils'); 3673 var config = require('../utils/config'); 3674 var Iban = require('./iban'); 3675 3676 /** 3677 * Should the format output to a big number 3678 * 3679 * @method outputBigNumberFormatter 3680 * @param {String|Number|BigNumber} 3681 * @returns {BigNumber} object 3682 */ 3683 var outputBigNumberFormatter = function (number) { 3684 return utils.toBigNumber(number); 3685 }; 3686 3687 var isPredefinedBlockNumber = function (blockNumber) { 3688 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest' || blockNumber === 'finalized' || blockNumber === 'safe'; 3689 }; 3690 3691 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3692 if (blockNumber === undefined) { 3693 return config.defaultBlock; 3694 } 3695 return inputBlockNumberFormatter(blockNumber); 3696 }; 3697 3698 var inputBlockNumberFormatter = function (blockNumber) { 3699 if (blockNumber === undefined) { 3700 return undefined; 3701 } else if (isPredefinedBlockNumber(blockNumber)) { 3702 return blockNumber; 3703 } 3704 return utils.toHex(blockNumber); 3705 }; 3706 3707 /** 3708 * Formats the input of a transaction and converts all values to HEX 3709 * 3710 * @method inputCallFormatter 3711 * @param {Object} transaction options 3712 * @returns object 3713 */ 3714 var inputCallFormatter = function (options){ 3715 3716 options.from = options.from || config.defaultAccount; 3717 3718 if (options.from) { 3719 options.from = inputAddressFormatter(options.from); 3720 } 3721 3722 if (options.to) { // it might be contract creation 3723 options.to = inputAddressFormatter(options.to); 3724 } 3725 3726 ['maxFeePerBlobGas', 'maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3727 return options[key] !== undefined; 3728 }).forEach(function(key){ 3729 options[key] = utils.fromDecimal(options[key]); 3730 }); 3731 3732 return options; 3733 }; 3734 3735 /** 3736 * Formats the input of a transaction and converts all values to HEX 3737 * 3738 * @method inputTransactionFormatter 3739 * @param {Object} transaction options 3740 * @returns object 3741 */ 3742 var inputTransactionFormatter = function (options){ 3743 3744 options.from = options.from || config.defaultAccount; 3745 options.from = inputAddressFormatter(options.from); 3746 3747 if (options.to) { // it might be contract creation 3748 options.to = inputAddressFormatter(options.to); 3749 } 3750 3751 ['maxFeePerBlobGas', 'maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3752 return options[key] !== undefined; 3753 }).forEach(function(key){ 3754 options[key] = utils.fromDecimal(options[key]); 3755 }); 3756 3757 return options; 3758 }; 3759 3760 /** 3761 * Formats the output of a transaction to its proper values 3762 * 3763 * @method outputTransactionFormatter 3764 * @param {Object} tx 3765 * @returns {Object} 3766 */ 3767 var outputTransactionFormatter = function (tx){ 3768 if(tx.blockNumber !== null) 3769 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3770 if(tx.transactionIndex !== null) 3771 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3772 tx.nonce = utils.toDecimal(tx.nonce); 3773 tx.gas = utils.toDecimal(tx.gas); 3774 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3775 if(tx.maxFeePerGas !== undefined) { 3776 tx.maxFeePerGas = utils.toBigNumber(tx.maxFeePerGas); 3777 } 3778 if(tx.maxPriorityFeePerGas !== undefined) { 3779 tx.maxPriorityFeePerGas = utils.toBigNumber(tx.maxPriorityFeePerGas); 3780 } 3781 if(tx.maxFeePerBlobGas !== undefined) { 3782 tx.maxFeePerBlobGas = utils.toBigNumber(tx.maxFeePerBlobGas); 3783 } 3784 tx.value = utils.toBigNumber(tx.value); 3785 return tx; 3786 }; 3787 3788 /** 3789 * Formats the output of a transaction receipt to its proper values 3790 * 3791 * @method outputTransactionReceiptFormatter 3792 * @param {Object} receipt 3793 * @returns {Object} 3794 */ 3795 var outputTransactionReceiptFormatter = function (receipt){ 3796 if(receipt.blockNumber !== null) 3797 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3798 if(receipt.transactionIndex !== null) 3799 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3800 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3801 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3802 if(receipt.effectiveGasPrice !== undefined) { 3803 receipt.effectiveGasPrice = utils.toBigNumber(receipt.effectiveGasPrice); 3804 } 3805 if(receipt.blobGasPrice !== undefined) { 3806 receipt.blobGasPrice = utils.toBigNumber(receipt.blobGasPrice); 3807 } 3808 if(receipt.blobGasUsed !== undefined) { 3809 receipt.blobGasUsed = utils.toBigNumber(receipt.blobGasUsed); 3810 } 3811 if(utils.isArray(receipt.logs)) { 3812 receipt.logs = receipt.logs.map(function(log){ 3813 return outputLogFormatter(log); 3814 }); 3815 } 3816 3817 return receipt; 3818 }; 3819 3820 /** 3821 * Formats the output of a block to its proper values 3822 * 3823 * @method outputBlockFormatter 3824 * @param {Object} block 3825 * @returns {Object} 3826 */ 3827 var outputBlockFormatter = function(block) { 3828 // transform to number 3829 if (block.baseFeePerGas !== undefined) { 3830 block.baseFeePerGas = utils.toBigNumber(block.baseFeePerGas); 3831 } 3832 if (block.blobGasUsed !== undefined) { 3833 block.blobGasUsed = utils.toBigNumber(block.blobGasUsed); 3834 } 3835 if (block.excessBlobGas !== undefined) { 3836 block.excessBlobGas = utils.toBigNumber(block.excessBlobGas); 3837 } 3838 block.gasLimit = utils.toDecimal(block.gasLimit); 3839 block.gasUsed = utils.toDecimal(block.gasUsed); 3840 block.size = utils.toDecimal(block.size); 3841 block.timestamp = utils.toDecimal(block.timestamp); 3842 if (block.number !== null) 3843 block.number = utils.toDecimal(block.number); 3844 3845 block.difficulty = utils.toBigNumber(block.difficulty); 3846 3847 if (utils.isArray(block.transactions)) { 3848 block.transactions.forEach(function(item){ 3849 if(!utils.isString(item)) 3850 return outputTransactionFormatter(item); 3851 }); 3852 } 3853 3854 return block; 3855 }; 3856 3857 /** 3858 * Formats the output of a log 3859 * 3860 * @method outputLogFormatter 3861 * @param {Object} log object 3862 * @returns {Object} log 3863 */ 3864 var outputLogFormatter = function(log) { 3865 if(log.blockNumber) 3866 log.blockNumber = utils.toDecimal(log.blockNumber); 3867 if(log.transactionIndex) 3868 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3869 if(log.logIndex) 3870 log.logIndex = utils.toDecimal(log.logIndex); 3871 3872 return log; 3873 }; 3874 3875 /** 3876 * Formats the input of a whisper post and converts all values to HEX 3877 * 3878 * @method inputPostFormatter 3879 * @param {Object} transaction object 3880 * @returns {Object} 3881 */ 3882 var inputPostFormatter = function(post) { 3883 3884 // post.payload = utils.toHex(post.payload); 3885 post.ttl = utils.fromDecimal(post.ttl); 3886 post.workToProve = utils.fromDecimal(post.workToProve); 3887 post.priority = utils.fromDecimal(post.priority); 3888 3889 // fallback 3890 if (!utils.isArray(post.topics)) { 3891 post.topics = post.topics ? [post.topics] : []; 3892 } 3893 3894 // format the following options 3895 post.topics = post.topics.map(function(topic){ 3896 // convert only if not hex 3897 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3898 }); 3899 3900 return post; 3901 }; 3902 3903 /** 3904 * Formats the output of a received post message 3905 * 3906 * @method outputPostFormatter 3907 * @param {Object} 3908 * @returns {Object} 3909 */ 3910 var outputPostFormatter = function(post){ 3911 3912 post.expiry = utils.toDecimal(post.expiry); 3913 post.sent = utils.toDecimal(post.sent); 3914 post.ttl = utils.toDecimal(post.ttl); 3915 post.workProved = utils.toDecimal(post.workProved); 3916 // post.payloadRaw = post.payload; 3917 // post.payload = utils.toAscii(post.payload); 3918 3919 // if (utils.isJson(post.payload)) { 3920 // post.payload = JSON.parse(post.payload); 3921 // } 3922 3923 // format the following options 3924 if (!post.topics) { 3925 post.topics = []; 3926 } 3927 post.topics = post.topics.map(function(topic){ 3928 return utils.toAscii(topic); 3929 }); 3930 3931 return post; 3932 }; 3933 3934 var inputAddressFormatter = function (address) { 3935 var iban = new Iban(address); 3936 if (iban.isValid() && iban.isDirect()) { 3937 return '0x' + iban.address(); 3938 } else if (utils.isStrictAddress(address)) { 3939 return address; 3940 } else if (utils.isAddress(address)) { 3941 return '0x' + address; 3942 } 3943 throw new Error('invalid address'); 3944 }; 3945 3946 3947 var outputSyncingFormatter = function(result) { 3948 if (!result) { 3949 return result; 3950 } 3951 3952 result.startingBlock = utils.toDecimal(result.startingBlock); 3953 result.currentBlock = utils.toDecimal(result.currentBlock); 3954 result.highestBlock = utils.toDecimal(result.highestBlock); 3955 result.syncedAccounts = utils.toDecimal(result.syncedAccounts); 3956 result.syncedAccountBytes = utils.toDecimal(result.syncedAccountBytes); 3957 result.syncedBytecodes = utils.toDecimal(result.syncedBytecodes); 3958 result.syncedBytecodeBytes = utils.toDecimal(result.syncedBytecodeBytes); 3959 result.syncedStorage = utils.toDecimal(result.syncedStorage); 3960 result.syncedStorageBytes = utils.toDecimal(result.syncedStorageBytes); 3961 result.healedTrienodes = utils.toDecimal(result.healedTrienodes); 3962 result.healedTrienodeBytes = utils.toDecimal(result.healedTrienodeBytes); 3963 result.healedBytecodes = utils.toDecimal(result.healedBytecodes); 3964 result.healedBytecodeBytes = utils.toDecimal(result.healedBytecodeBytes); 3965 result.healingTrienodes = utils.toDecimal(result.healingTrienodes); 3966 result.healingBytecode = utils.toDecimal(result.healingBytecode); 3967 result.txIndexFinishedBlocks = utils.toDecimal(result.txIndexFinishedBlocks); 3968 result.txIndexRemainingBlocks = utils.toDecimal(result.txIndexRemainingBlocks); 3969 result.stateIndexRemaining = utils.toDecimal(result.stateIndexRemaining) 3970 3971 return result; 3972 }; 3973 3974 module.exports = { 3975 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 3976 inputBlockNumberFormatter: inputBlockNumberFormatter, 3977 inputCallFormatter: inputCallFormatter, 3978 inputTransactionFormatter: inputTransactionFormatter, 3979 inputAddressFormatter: inputAddressFormatter, 3980 inputPostFormatter: inputPostFormatter, 3981 outputBigNumberFormatter: outputBigNumberFormatter, 3982 outputTransactionFormatter: outputTransactionFormatter, 3983 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 3984 outputBlockFormatter: outputBlockFormatter, 3985 outputLogFormatter: outputLogFormatter, 3986 outputPostFormatter: outputPostFormatter, 3987 outputSyncingFormatter: outputSyncingFormatter 3988 }; 3989 3990 3991 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 3992 /* 3993 This file is part of web3.js. 3994 3995 web3.js is free software: you can redistribute it and/or modify 3996 it under the terms of the GNU Lesser General Public License as published by 3997 the Free Software Foundation, either version 3 of the License, or 3998 (at your option) any later version. 3999 4000 web3.js is distributed in the hope that it will be useful, 4001 but WITHOUT ANY WARRANTY; without even the implied warranty of 4002 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4003 GNU Lesser General Public License for more details. 4004 4005 You should have received a copy of the GNU Lesser General Public License 4006 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4007 */ 4008 /** 4009 * @file function.js 4010 * @author Marek Kotewicz <marek@ethdev.com> 4011 * @date 2015 4012 */ 4013 4014 var coder = require('../solidity/coder'); 4015 var utils = require('../utils/utils'); 4016 var errors = require('./errors'); 4017 var formatters = require('./formatters'); 4018 var sha3 = require('../utils/sha3'); 4019 4020 /** 4021 * This prototype should be used to call/sendTransaction to solidity functions 4022 */ 4023 var SolidityFunction = function (eth, json, address) { 4024 this._eth = eth; 4025 this._inputTypes = json.inputs.map(function (i) { 4026 return i.type; 4027 }); 4028 this._outputTypes = json.outputs.map(function (i) { 4029 return i.type; 4030 }); 4031 this._constant = json.constant; 4032 this._payable = json.payable; 4033 this._name = utils.transformToFullName(json); 4034 this._address = address; 4035 }; 4036 4037 SolidityFunction.prototype.extractCallback = function (args) { 4038 if (utils.isFunction(args[args.length - 1])) { 4039 return args.pop(); // modify the args array! 4040 } 4041 }; 4042 4043 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4044 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4045 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4046 } 4047 }; 4048 4049 /** 4050 * Should be called to check if the number of arguments is correct 4051 * 4052 * @method validateArgs 4053 * @param {Array} arguments 4054 * @throws {Error} if it is not 4055 */ 4056 SolidityFunction.prototype.validateArgs = function (args) { 4057 var inputArgs = args.filter(function (a) { 4058 // filter the options object but not arguments that are arrays 4059 return !( (utils.isObject(a) === true) && 4060 (utils.isArray(a) === false) && 4061 (utils.isBigNumber(a) === false) 4062 ); 4063 }); 4064 if (inputArgs.length !== this._inputTypes.length) { 4065 throw errors.InvalidNumberOfSolidityArgs(); 4066 } 4067 }; 4068 4069 /** 4070 * Should be used to create payload from arguments 4071 * 4072 * @method toPayload 4073 * @param {Array} solidity function params 4074 * @param {Object} optional payload options 4075 */ 4076 SolidityFunction.prototype.toPayload = function (args) { 4077 var options = {}; 4078 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4079 options = args[args.length - 1]; 4080 } 4081 this.validateArgs(args); 4082 options.to = this._address; 4083 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4084 return options; 4085 }; 4086 4087 /** 4088 * Should be used to get function signature 4089 * 4090 * @method signature 4091 * @return {String} function signature 4092 */ 4093 SolidityFunction.prototype.signature = function () { 4094 return sha3(this._name).slice(0, 8); 4095 }; 4096 4097 4098 SolidityFunction.prototype.unpackOutput = function (output) { 4099 if (!output) { 4100 return; 4101 } 4102 4103 output = output.length >= 2 ? output.slice(2) : output; 4104 var result = coder.decodeParams(this._outputTypes, output); 4105 return result.length === 1 ? result[0] : result; 4106 }; 4107 4108 /** 4109 * Calls a contract function. 4110 * 4111 * @method call 4112 * @param {...Object} Contract function arguments 4113 * @param {function} If the last argument is a function, the contract function 4114 * call will be asynchronous, and the callback will be passed the 4115 * error and result. 4116 * @return {String} output bytes 4117 */ 4118 SolidityFunction.prototype.call = function () { 4119 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4120 var callback = this.extractCallback(args); 4121 var defaultBlock = this.extractDefaultBlock(args); 4122 var payload = this.toPayload(args); 4123 4124 4125 if (!callback) { 4126 var output = this._eth.call(payload, defaultBlock); 4127 return this.unpackOutput(output); 4128 } 4129 4130 var self = this; 4131 this._eth.call(payload, defaultBlock, function (error, output) { 4132 if (error) return callback(error, null); 4133 4134 var unpacked = null; 4135 try { 4136 unpacked = self.unpackOutput(output); 4137 } 4138 catch (e) { 4139 error = e; 4140 } 4141 4142 callback(error, unpacked); 4143 }); 4144 }; 4145 4146 /** 4147 * Should be used to sendTransaction to solidity function 4148 * 4149 * @method sendTransaction 4150 */ 4151 SolidityFunction.prototype.sendTransaction = function () { 4152 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4153 var callback = this.extractCallback(args); 4154 var payload = this.toPayload(args); 4155 4156 if (payload.value > 0 && !this._payable) { 4157 throw new Error('Cannot send value to non-payable function'); 4158 } 4159 4160 if (!callback) { 4161 return this._eth.sendTransaction(payload); 4162 } 4163 4164 this._eth.sendTransaction(payload, callback); 4165 }; 4166 4167 /** 4168 * Should be used to estimateGas of solidity function 4169 * 4170 * @method estimateGas 4171 */ 4172 SolidityFunction.prototype.estimateGas = function () { 4173 var args = Array.prototype.slice.call(arguments); 4174 var callback = this.extractCallback(args); 4175 var payload = this.toPayload(args); 4176 4177 if (!callback) { 4178 return this._eth.estimateGas(payload); 4179 } 4180 4181 this._eth.estimateGas(payload, callback); 4182 }; 4183 4184 /** 4185 * Return the encoded data of the call 4186 * 4187 * @method getData 4188 * @return {String} the encoded data 4189 */ 4190 SolidityFunction.prototype.getData = function () { 4191 var args = Array.prototype.slice.call(arguments); 4192 var payload = this.toPayload(args); 4193 4194 return payload.data; 4195 }; 4196 4197 /** 4198 * Should be used to get function display name 4199 * 4200 * @method displayName 4201 * @return {String} display name of the function 4202 */ 4203 SolidityFunction.prototype.displayName = function () { 4204 return utils.extractDisplayName(this._name); 4205 }; 4206 4207 /** 4208 * Should be used to get function type name 4209 * 4210 * @method typeName 4211 * @return {String} type name of the function 4212 */ 4213 SolidityFunction.prototype.typeName = function () { 4214 return utils.extractTypeName(this._name); 4215 }; 4216 4217 /** 4218 * Should be called to get rpc requests from solidity function 4219 * 4220 * @method request 4221 * @returns {Object} 4222 */ 4223 SolidityFunction.prototype.request = function () { 4224 var args = Array.prototype.slice.call(arguments); 4225 var callback = this.extractCallback(args); 4226 var payload = this.toPayload(args); 4227 var format = this.unpackOutput.bind(this); 4228 4229 return { 4230 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4231 callback: callback, 4232 params: [payload], 4233 format: format 4234 }; 4235 }; 4236 4237 /** 4238 * Should be called to execute function 4239 * 4240 * @method execute 4241 */ 4242 SolidityFunction.prototype.execute = function () { 4243 var transaction = !this._constant; 4244 4245 // send transaction 4246 if (transaction) { 4247 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4248 } 4249 4250 // call 4251 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4252 }; 4253 4254 /** 4255 * Should be called to attach function to contract 4256 * 4257 * @method attachToContract 4258 * @param {Contract} 4259 */ 4260 SolidityFunction.prototype.attachToContract = function (contract) { 4261 var execute = this.execute.bind(this); 4262 execute.request = this.request.bind(this); 4263 execute.call = this.call.bind(this); 4264 execute.sendTransaction = this.sendTransaction.bind(this); 4265 execute.estimateGas = this.estimateGas.bind(this); 4266 execute.getData = this.getData.bind(this); 4267 var displayName = this.displayName(); 4268 if (!contract[displayName]) { 4269 contract[displayName] = execute; 4270 } 4271 contract[displayName][this.typeName()] = execute; // circular!!!! 4272 }; 4273 4274 module.exports = SolidityFunction; 4275 4276 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4277 /* 4278 This file is part of web3.js. 4279 4280 web3.js is free software: you can redistribute it and/or modify 4281 it under the terms of the GNU Lesser General Public License as published by 4282 the Free Software Foundation, either version 3 of the License, or 4283 (at your option) any later version. 4284 4285 web3.js is distributed in the hope that it will be useful, 4286 but WITHOUT ANY WARRANTY; without even the implied warranty of 4287 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4288 GNU Lesser General Public License for more details. 4289 4290 You should have received a copy of the GNU Lesser General Public License 4291 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4292 */ 4293 /** @file httpprovider.js 4294 * @authors: 4295 * Marek Kotewicz <marek@ethdev.com> 4296 * Marian Oancea <marian@ethdev.com> 4297 * Fabian Vogelsteller <fabian@ethdev.com> 4298 * @date 2015 4299 */ 4300 4301 var errors = require('./errors'); 4302 4303 // workaround to use httpprovider in different envs 4304 4305 // browser 4306 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4307 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4308 // node 4309 } else { 4310 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4311 } 4312 4313 var XHR2 = require('xhr2'); // jshint ignore: line 4314 4315 /** 4316 * HttpProvider should be used to send rpc calls over http 4317 */ 4318 var HttpProvider = function (host, timeout, user, password) { 4319 this.host = host || 'http://localhost:8545'; 4320 this.timeout = timeout || 0; 4321 this.user = user; 4322 this.password = password; 4323 }; 4324 4325 /** 4326 * Should be called to prepare new XMLHttpRequest 4327 * 4328 * @method prepareRequest 4329 * @param {Boolean} true if request should be async 4330 * @return {XMLHttpRequest} object 4331 */ 4332 HttpProvider.prototype.prepareRequest = function (async) { 4333 var request; 4334 4335 if (async) { 4336 request = new XHR2(); 4337 request.timeout = this.timeout; 4338 } else { 4339 request = new XMLHttpRequest(); 4340 } 4341 4342 request.open('POST', this.host, async); 4343 if (this.user && this.password) { 4344 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4345 request.setRequestHeader('Authorization', auth); 4346 } request.setRequestHeader('Content-Type', 'application/json'); 4347 return request; 4348 }; 4349 4350 /** 4351 * Should be called to make sync request 4352 * 4353 * @method send 4354 * @param {Object} payload 4355 * @return {Object} result 4356 */ 4357 HttpProvider.prototype.send = function (payload) { 4358 var request = this.prepareRequest(false); 4359 4360 try { 4361 request.send(JSON.stringify(payload)); 4362 } catch (error) { 4363 throw errors.InvalidConnection(this.host); 4364 } 4365 4366 var result = request.responseText; 4367 4368 try { 4369 result = JSON.parse(result); 4370 } catch (e) { 4371 throw errors.InvalidResponse(request.responseText); 4372 } 4373 4374 return result; 4375 }; 4376 4377 /** 4378 * Should be used to make async request 4379 * 4380 * @method sendAsync 4381 * @param {Object} payload 4382 * @param {Function} callback triggered on end with (err, result) 4383 */ 4384 HttpProvider.prototype.sendAsync = function (payload, callback) { 4385 var request = this.prepareRequest(true); 4386 4387 request.onreadystatechange = function () { 4388 if (request.readyState === 4 && request.timeout !== 1) { 4389 var result = request.responseText; 4390 var error = null; 4391 4392 try { 4393 result = JSON.parse(result); 4394 } catch (e) { 4395 error = errors.InvalidResponse(request.responseText); 4396 } 4397 4398 callback(error, result); 4399 } 4400 }; 4401 4402 request.ontimeout = function () { 4403 callback(errors.ConnectionTimeout(this.timeout)); 4404 }; 4405 4406 try { 4407 request.send(JSON.stringify(payload)); 4408 } catch (error) { 4409 callback(errors.InvalidConnection(this.host)); 4410 } 4411 }; 4412 4413 /** 4414 * Synchronously tries to make Http request 4415 * 4416 * @method isConnected 4417 * @return {Boolean} returns true if request haven't failed. Otherwise false 4418 */ 4419 HttpProvider.prototype.isConnected = function () { 4420 try { 4421 this.send({ 4422 id: 9999999999, 4423 jsonrpc: '2.0', 4424 method: 'net_listening', 4425 params: [] 4426 }); 4427 return true; 4428 } catch (e) { 4429 return false; 4430 } 4431 }; 4432 4433 module.exports = HttpProvider; 4434 4435 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4436 /* 4437 This file is part of web3.js. 4438 4439 web3.js is free software: you can redistribute it and/or modify 4440 it under the terms of the GNU Lesser General Public License as published by 4441 the Free Software Foundation, either version 3 of the License, or 4442 (at your option) any later version. 4443 4444 web3.js is distributed in the hope that it will be useful, 4445 but WITHOUT ANY WARRANTY; without even the implied warranty of 4446 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4447 GNU Lesser General Public License for more details. 4448 4449 You should have received a copy of the GNU Lesser General Public License 4450 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4451 */ 4452 /** 4453 * @file iban.js 4454 * @author Marek Kotewicz <marek@ethdev.com> 4455 * @date 2015 4456 */ 4457 4458 var BigNumber = require('bignumber.js'); 4459 4460 var padLeft = function (string, bytes) { 4461 var result = string; 4462 while (result.length < bytes * 2) { 4463 result = '0' + result; 4464 } 4465 return result; 4466 }; 4467 4468 /** 4469 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4470 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4471 * 4472 * @method iso13616Prepare 4473 * @param {String} iban the IBAN 4474 * @returns {String} the prepared IBAN 4475 */ 4476 var iso13616Prepare = function (iban) { 4477 var A = 'A'.charCodeAt(0); 4478 var Z = 'Z'.charCodeAt(0); 4479 4480 iban = iban.toUpperCase(); 4481 iban = iban.substr(4) + iban.substr(0,4); 4482 4483 return iban.split('').map(function(n){ 4484 var code = n.charCodeAt(0); 4485 if (code >= A && code <= Z){ 4486 // A = 10, B = 11, ... Z = 35 4487 return code - A + 10; 4488 } else { 4489 return n; 4490 } 4491 }).join(''); 4492 }; 4493 4494 /** 4495 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4496 * 4497 * @method mod9710 4498 * @param {String} iban 4499 * @returns {Number} 4500 */ 4501 var mod9710 = function (iban) { 4502 var remainder = iban, 4503 block; 4504 4505 while (remainder.length > 2){ 4506 block = remainder.slice(0, 9); 4507 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4508 } 4509 4510 return parseInt(remainder, 10) % 97; 4511 }; 4512 4513 /** 4514 * This prototype should be used to create iban object from iban correct string 4515 * 4516 * @param {String} iban 4517 */ 4518 var Iban = function (iban) { 4519 this._iban = iban; 4520 }; 4521 4522 /** 4523 * This method should be used to create iban object from ethereum address 4524 * 4525 * @method fromAddress 4526 * @param {String} address 4527 * @return {Iban} the IBAN object 4528 */ 4529 Iban.fromAddress = function (address) { 4530 var asBn = new BigNumber(address, 16); 4531 var base36 = asBn.toString(36); 4532 var padded = padLeft(base36, 15); 4533 return Iban.fromBban(padded.toUpperCase()); 4534 }; 4535 4536 /** 4537 * Convert the passed BBAN to an IBAN for this country specification. 4538 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4539 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4540 * 4541 * @method fromBban 4542 * @param {String} bban the BBAN to convert to IBAN 4543 * @returns {Iban} the IBAN object 4544 */ 4545 Iban.fromBban = function (bban) { 4546 var countryCode = 'XE'; 4547 4548 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4549 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4550 4551 return new Iban(countryCode + checkDigit + bban); 4552 }; 4553 4554 /** 4555 * Should be used to create IBAN object for given institution and identifier 4556 * 4557 * @method createIndirect 4558 * @param {Object} options, required options are "institution" and "identifier" 4559 * @return {Iban} the IBAN object 4560 */ 4561 Iban.createIndirect = function (options) { 4562 return Iban.fromBban('ETH' + options.institution + options.identifier); 4563 }; 4564 4565 /** 4566 * This method should be used to check if given string is valid iban object 4567 * 4568 * @method isValid 4569 * @param {String} iban string 4570 * @return {Boolean} true if it is valid IBAN 4571 */ 4572 Iban.isValid = function (iban) { 4573 var i = new Iban(iban); 4574 return i.isValid(); 4575 }; 4576 4577 /** 4578 * Should be called to check if iban is correct 4579 * 4580 * @method isValid 4581 * @returns {Boolean} true if it is, otherwise false 4582 */ 4583 Iban.prototype.isValid = function () { 4584 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4585 mod9710(iso13616Prepare(this._iban)) === 1; 4586 }; 4587 4588 /** 4589 * Should be called to check if iban number is direct 4590 * 4591 * @method isDirect 4592 * @returns {Boolean} true if it is, otherwise false 4593 */ 4594 Iban.prototype.isDirect = function () { 4595 return this._iban.length === 34 || this._iban.length === 35; 4596 }; 4597 4598 /** 4599 * Should be called to check if iban number if indirect 4600 * 4601 * @method isIndirect 4602 * @returns {Boolean} true if it is, otherwise false 4603 */ 4604 Iban.prototype.isIndirect = function () { 4605 return this._iban.length === 20; 4606 }; 4607 4608 /** 4609 * Should be called to get iban checksum 4610 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4611 * 4612 * @method checksum 4613 * @returns {String} checksum 4614 */ 4615 Iban.prototype.checksum = function () { 4616 return this._iban.substr(2, 2); 4617 }; 4618 4619 /** 4620 * Should be called to get institution identifier 4621 * eg. XREG 4622 * 4623 * @method institution 4624 * @returns {String} institution identifier 4625 */ 4626 Iban.prototype.institution = function () { 4627 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4628 }; 4629 4630 /** 4631 * Should be called to get client identifier within institution 4632 * eg. GAVOFYORK 4633 * 4634 * @method client 4635 * @returns {String} client identifier 4636 */ 4637 Iban.prototype.client = function () { 4638 return this.isIndirect() ? this._iban.substr(11) : ''; 4639 }; 4640 4641 /** 4642 * Should be called to get client direct address 4643 * 4644 * @method address 4645 * @returns {String} client direct address 4646 */ 4647 Iban.prototype.address = function () { 4648 if (this.isDirect()) { 4649 var base36 = this._iban.substr(4); 4650 var asBn = new BigNumber(base36, 36); 4651 return padLeft(asBn.toString(16), 20); 4652 } 4653 4654 return ''; 4655 }; 4656 4657 Iban.prototype.toString = function () { 4658 return this._iban; 4659 }; 4660 4661 module.exports = Iban; 4662 4663 4664 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4665 /* 4666 This file is part of web3.js. 4667 4668 web3.js is free software: you can redistribute it and/or modify 4669 it under the terms of the GNU Lesser General Public License as published by 4670 the Free Software Foundation, either version 3 of the License, or 4671 (at your option) any later version. 4672 4673 web3.js is distributed in the hope that it will be useful, 4674 but WITHOUT ANY WARRANTY; without even the implied warranty of 4675 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4676 GNU Lesser General Public License for more details. 4677 4678 You should have received a copy of the GNU Lesser General Public License 4679 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4680 */ 4681 /** @file ipcprovider.js 4682 * @authors: 4683 * Fabian Vogelsteller <fabian@ethdev.com> 4684 * @date 2015 4685 */ 4686 4687 "use strict"; 4688 4689 var utils = require('../utils/utils'); 4690 var errors = require('./errors'); 4691 4692 4693 var IpcProvider = function (path, net) { 4694 var _this = this; 4695 this.responseCallbacks = {}; 4696 this.path = path; 4697 4698 this.connection = net.connect({path: this.path}); 4699 4700 this.connection.on('error', function(e){ 4701 console.error('IPC Connection Error', e); 4702 _this._timeout(); 4703 }); 4704 4705 this.connection.on('end', function(){ 4706 _this._timeout(); 4707 }); 4708 4709 4710 // LISTEN FOR CONNECTION RESPONSES 4711 this.connection.on('data', function(data) { 4712 /*jshint maxcomplexity: 6 */ 4713 4714 _this._parseResponse(data.toString()).forEach(function(result){ 4715 4716 var id = null; 4717 4718 // get the id which matches the returned id 4719 if(utils.isArray(result)) { 4720 result.forEach(function(load){ 4721 if(_this.responseCallbacks[load.id]) 4722 id = load.id; 4723 }); 4724 } else { 4725 id = result.id; 4726 } 4727 4728 // fire the callback 4729 if(_this.responseCallbacks[id]) { 4730 _this.responseCallbacks[id](null, result); 4731 delete _this.responseCallbacks[id]; 4732 } 4733 }); 4734 }); 4735 }; 4736 4737 /** 4738 Will parse the response and make an array out of it. 4739 4740 @method _parseResponse 4741 @param {String} data 4742 */ 4743 IpcProvider.prototype._parseResponse = function(data) { 4744 var _this = this, 4745 returnValues = []; 4746 4747 // DE-CHUNKER 4748 var dechunkedData = data 4749 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4750 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4751 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4752 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4753 .split('|--|'); 4754 4755 dechunkedData.forEach(function(data){ 4756 4757 // prepend the last chunk 4758 if(_this.lastChunk) 4759 data = _this.lastChunk + data; 4760 4761 var result = null; 4762 4763 try { 4764 result = JSON.parse(data); 4765 4766 } catch(e) { 4767 4768 _this.lastChunk = data; 4769 4770 // start timeout to cancel all requests 4771 clearTimeout(_this.lastChunkTimeout); 4772 _this.lastChunkTimeout = setTimeout(function(){ 4773 _this._timeout(); 4774 throw errors.InvalidResponse(data); 4775 }, 1000 * 15); 4776 4777 return; 4778 } 4779 4780 // cancel timeout and set chunk to null 4781 clearTimeout(_this.lastChunkTimeout); 4782 _this.lastChunk = null; 4783 4784 if(result) 4785 returnValues.push(result); 4786 }); 4787 4788 return returnValues; 4789 }; 4790 4791 4792 /** 4793 Get the adds a callback to the responseCallbacks object, 4794 which will be called if a response matching the response Id will arrive. 4795 4796 @method _addResponseCallback 4797 */ 4798 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4799 var id = payload.id || payload[0].id; 4800 var method = payload.method || payload[0].method; 4801 4802 this.responseCallbacks[id] = callback; 4803 this.responseCallbacks[id].method = method; 4804 }; 4805 4806 /** 4807 Timeout all requests when the end/error event is fired 4808 4809 @method _timeout 4810 */ 4811 IpcProvider.prototype._timeout = function() { 4812 for(var key in this.responseCallbacks) { 4813 if(this.responseCallbacks.hasOwnProperty(key)){ 4814 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4815 delete this.responseCallbacks[key]; 4816 } 4817 } 4818 }; 4819 4820 4821 /** 4822 Check if the current connection is still valid. 4823 4824 @method isConnected 4825 */ 4826 IpcProvider.prototype.isConnected = function() { 4827 var _this = this; 4828 4829 // try reconnect, when connection is gone 4830 if(!_this.connection.writable) 4831 _this.connection.connect({path: _this.path}); 4832 4833 return !!this.connection.writable; 4834 }; 4835 4836 IpcProvider.prototype.send = function (payload) { 4837 4838 if(this.connection.writeSync) { 4839 var result; 4840 4841 // try reconnect, when connection is gone 4842 if(!this.connection.writable) 4843 this.connection.connect({path: this.path}); 4844 4845 var data = this.connection.writeSync(JSON.stringify(payload)); 4846 4847 try { 4848 result = JSON.parse(data); 4849 } catch(e) { 4850 throw errors.InvalidResponse(data); 4851 } 4852 4853 return result; 4854 4855 } else { 4856 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4857 } 4858 }; 4859 4860 IpcProvider.prototype.sendAsync = function (payload, callback) { 4861 // try reconnect, when connection is gone 4862 if(!this.connection.writable) 4863 this.connection.connect({path: this.path}); 4864 4865 4866 this.connection.write(JSON.stringify(payload)); 4867 this._addResponseCallback(payload, callback); 4868 }; 4869 4870 module.exports = IpcProvider; 4871 4872 4873 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 4874 /* 4875 This file is part of web3.js. 4876 4877 web3.js is free software: you can redistribute it and/or modify 4878 it under the terms of the GNU Lesser General Public License as published by 4879 the Free Software Foundation, either version 3 of the License, or 4880 (at your option) any later version. 4881 4882 web3.js is distributed in the hope that it will be useful, 4883 but WITHOUT ANY WARRANTY; without even the implied warranty of 4884 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4885 GNU Lesser General Public License for more details. 4886 4887 You should have received a copy of the GNU Lesser General Public License 4888 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4889 */ 4890 /** @file jsonrpc.js 4891 * @authors: 4892 * Marek Kotewicz <marek@ethdev.com> 4893 * Aaron Kumavis <aaron@kumavis.me> 4894 * @date 2015 4895 */ 4896 4897 // Initialize Jsonrpc as a simple object with utility functions. 4898 var Jsonrpc = { 4899 messageId: 0 4900 }; 4901 4902 /** 4903 * Should be called to valid json create payload object 4904 * 4905 * @method toPayload 4906 * @param {Function} method of jsonrpc call, required 4907 * @param {Array} params, an array of method params, optional 4908 * @returns {Object} valid jsonrpc payload object 4909 */ 4910 Jsonrpc.toPayload = function (method, params) { 4911 if (!method) 4912 console.error('jsonrpc method should be specified!'); 4913 4914 // advance message ID 4915 Jsonrpc.messageId++; 4916 4917 return { 4918 jsonrpc: '2.0', 4919 id: Jsonrpc.messageId, 4920 method: method, 4921 params: params || [] 4922 }; 4923 }; 4924 4925 /** 4926 * Should be called to check if jsonrpc response is valid 4927 * 4928 * @method isValidResponse 4929 * @param {Object} 4930 * @returns {Boolean} true if response is valid, otherwise false 4931 */ 4932 Jsonrpc.isValidResponse = function (response) { 4933 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4934 4935 function validateSingleMessage(message){ 4936 return !!message && 4937 !message.error && 4938 message.jsonrpc === '2.0' && 4939 typeof message.id === 'number' && 4940 message.result !== undefined; // only undefined is not valid json object 4941 } 4942 }; 4943 4944 /** 4945 * Should be called to create batch payload object 4946 * 4947 * @method toBatchPayload 4948 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4949 * @returns {Array} batch payload 4950 */ 4951 Jsonrpc.toBatchPayload = function (messages) { 4952 return messages.map(function (message) { 4953 return Jsonrpc.toPayload(message.method, message.params); 4954 }); 4955 }; 4956 4957 module.exports = Jsonrpc; 4958 4959 4960 },{}],36:[function(require,module,exports){ 4961 /* 4962 This file is part of web3.js. 4963 4964 web3.js is free software: you can redistribute it and/or modify 4965 it under the terms of the GNU Lesser General Public License as published by 4966 the Free Software Foundation, either version 3 of the License, or 4967 (at your option) any later version. 4968 4969 web3.js is distributed in the hope that it will be useful, 4970 but WITHOUT ANY WARRANTY; without even the implied warranty of 4971 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4972 GNU Lesser General Public License for more details. 4973 4974 You should have received a copy of the GNU Lesser General Public License 4975 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4976 */ 4977 /** 4978 * @file method.js 4979 * @author Marek Kotewicz <marek@ethdev.com> 4980 * @date 2015 4981 */ 4982 4983 var utils = require('../utils/utils'); 4984 var errors = require('./errors'); 4985 4986 var Method = function (options) { 4987 this.name = options.name; 4988 this.call = options.call; 4989 this.params = options.params || 0; 4990 this.inputFormatter = options.inputFormatter; 4991 this.outputFormatter = options.outputFormatter; 4992 this.requestManager = null; 4993 }; 4994 4995 Method.prototype.setRequestManager = function (rm) { 4996 this.requestManager = rm; 4997 }; 4998 4999 /** 5000 * Should be used to determine name of the jsonrpc method based on arguments 5001 * 5002 * @method getCall 5003 * @param {Array} arguments 5004 * @return {String} name of jsonrpc method 5005 */ 5006 Method.prototype.getCall = function (args) { 5007 return utils.isFunction(this.call) ? this.call(args) : this.call; 5008 }; 5009 5010 /** 5011 * Should be used to extract callback from array of arguments. Modifies input param 5012 * 5013 * @method extractCallback 5014 * @param {Array} arguments 5015 * @return {Function|Null} callback, if exists 5016 */ 5017 Method.prototype.extractCallback = function (args) { 5018 if (utils.isFunction(args[args.length - 1])) { 5019 return args.pop(); // modify the args array! 5020 } 5021 }; 5022 5023 /** 5024 * Should be called to check if the number of arguments is correct 5025 * 5026 * @method validateArgs 5027 * @param {Array} arguments 5028 * @throws {Error} if it is not 5029 */ 5030 Method.prototype.validateArgs = function (args) { 5031 if (args.length !== this.params) { 5032 throw errors.InvalidNumberOfRPCParams(); 5033 } 5034 }; 5035 5036 /** 5037 * Should be called to format input args of method 5038 * 5039 * @method formatInput 5040 * @param {Array} 5041 * @return {Array} 5042 */ 5043 Method.prototype.formatInput = function (args) { 5044 if (!this.inputFormatter) { 5045 return args; 5046 } 5047 5048 return this.inputFormatter.map(function (formatter, index) { 5049 return formatter ? formatter(args[index]) : args[index]; 5050 }); 5051 }; 5052 5053 /** 5054 * Should be called to format output(result) of method 5055 * 5056 * @method formatOutput 5057 * @param {Object} 5058 * @return {Object} 5059 */ 5060 Method.prototype.formatOutput = function (result) { 5061 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5062 }; 5063 5064 /** 5065 * Should create payload from given input args 5066 * 5067 * @method toPayload 5068 * @param {Array} args 5069 * @return {Object} 5070 */ 5071 Method.prototype.toPayload = function (args) { 5072 var call = this.getCall(args); 5073 var callback = this.extractCallback(args); 5074 var params = this.formatInput(args); 5075 this.validateArgs(params); 5076 5077 return { 5078 method: call, 5079 params: params, 5080 callback: callback 5081 }; 5082 }; 5083 5084 Method.prototype.attachToObject = function (obj) { 5085 var func = this.buildCall(); 5086 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5087 var name = this.name.split('.'); 5088 if (name.length > 1) { 5089 obj[name[0]] = obj[name[0]] || {}; 5090 obj[name[0]][name[1]] = func; 5091 } else { 5092 obj[name[0]] = func; 5093 } 5094 }; 5095 5096 Method.prototype.buildCall = function() { 5097 var method = this; 5098 var send = function () { 5099 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5100 if (payload.callback) { 5101 return method.requestManager.sendAsync(payload, function (err, result) { 5102 payload.callback(err, method.formatOutput(result)); 5103 }); 5104 } 5105 return method.formatOutput(method.requestManager.send(payload)); 5106 }; 5107 send.request = this.request.bind(this); 5108 return send; 5109 }; 5110 5111 /** 5112 * Should be called to create pure JSONRPC request which can be used in batch request 5113 * 5114 * @method request 5115 * @param {...} params 5116 * @return {Object} jsonrpc request 5117 */ 5118 Method.prototype.request = function () { 5119 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5120 payload.format = this.formatOutput.bind(this); 5121 return payload; 5122 }; 5123 5124 module.exports = Method; 5125 5126 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5127 /* 5128 This file is part of web3.js. 5129 5130 web3.js is free software: you can redistribute it and/or modify 5131 it under the terms of the GNU Lesser General Public License as published by 5132 the Free Software Foundation, either version 3 of the License, or 5133 (at your option) any later version. 5134 5135 web3.js is distributed in the hope that it will be useful, 5136 but WITHOUT ANY WARRANTY; without even the implied warranty of 5137 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5138 GNU Lesser General Public License for more details. 5139 5140 You should have received a copy of the GNU Lesser General Public License 5141 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5142 */ 5143 /** @file db.js 5144 * @authors: 5145 * Marek Kotewicz <marek@ethdev.com> 5146 * @date 2015 5147 */ 5148 5149 var Method = require('../method'); 5150 5151 var DB = function (web3) { 5152 this._requestManager = web3._requestManager; 5153 5154 var self = this; 5155 5156 methods().forEach(function(method) { 5157 method.attachToObject(self); 5158 method.setRequestManager(web3._requestManager); 5159 }); 5160 }; 5161 5162 var methods = function () { 5163 var putString = new Method({ 5164 name: 'putString', 5165 call: 'db_putString', 5166 params: 3 5167 }); 5168 5169 var getString = new Method({ 5170 name: 'getString', 5171 call: 'db_getString', 5172 params: 2 5173 }); 5174 5175 var putHex = new Method({ 5176 name: 'putHex', 5177 call: 'db_putHex', 5178 params: 3 5179 }); 5180 5181 var getHex = new Method({ 5182 name: 'getHex', 5183 call: 'db_getHex', 5184 params: 2 5185 }); 5186 5187 return [ 5188 putString, getString, putHex, getHex 5189 ]; 5190 }; 5191 5192 module.exports = DB; 5193 5194 },{"../method":36}],38:[function(require,module,exports){ 5195 /* 5196 This file is part of web3.js. 5197 5198 web3.js is free software: you can redistribute it and/or modify 5199 it under the terms of the GNU Lesser General Public License as published by 5200 the Free Software Foundation, either version 3 of the License, or 5201 (at your option) any later version. 5202 5203 web3.js is distributed in the hope that it will be useful, 5204 but WITHOUT ANY WARRANTY; without even the implied warranty of 5205 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5206 GNU Lesser General Public License for more details. 5207 5208 You should have received a copy of the GNU Lesser General Public License 5209 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5210 */ 5211 /** 5212 * @file eth.js 5213 * @author Marek Kotewicz <marek@ethdev.com> 5214 * @author Fabian Vogelsteller <fabian@ethdev.com> 5215 * @date 2015 5216 */ 5217 5218 "use strict"; 5219 5220 var formatters = require('../formatters'); 5221 var utils = require('../../utils/utils'); 5222 var Method = require('../method'); 5223 var Property = require('../property'); 5224 var c = require('../../utils/config'); 5225 var Contract = require('../contract'); 5226 var watches = require('./watches'); 5227 var Filter = require('../filter'); 5228 var IsSyncing = require('../syncing'); 5229 var namereg = require('../namereg'); 5230 var Iban = require('../iban'); 5231 var transfer = require('../transfer'); 5232 5233 var blockCall = function (args) { 5234 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; 5235 }; 5236 5237 var transactionFromBlockCall = function (args) { 5238 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5239 }; 5240 5241 var uncleCall = function (args) { 5242 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5243 }; 5244 5245 var getBlockTransactionCountCall = function (args) { 5246 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5247 }; 5248 5249 var uncleCountCall = function (args) { 5250 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5251 }; 5252 5253 function Eth(web3) { 5254 this._requestManager = web3._requestManager; 5255 5256 var self = this; 5257 5258 methods().forEach(function(method) { 5259 method.attachToObject(self); 5260 method.setRequestManager(self._requestManager); 5261 }); 5262 5263 properties().forEach(function(p) { 5264 p.attachToObject(self); 5265 p.setRequestManager(self._requestManager); 5266 }); 5267 5268 5269 this.iban = Iban; 5270 this.sendIBANTransaction = transfer.bind(null, this); 5271 } 5272 5273 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5274 get: function () { 5275 return c.defaultBlock; 5276 }, 5277 set: function (val) { 5278 c.defaultBlock = val; 5279 return val; 5280 } 5281 }); 5282 5283 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5284 get: function () { 5285 return c.defaultAccount; 5286 }, 5287 set: function (val) { 5288 c.defaultAccount = val; 5289 return val; 5290 } 5291 }); 5292 5293 var methods = function () { 5294 var getBalance = new Method({ 5295 name: 'getBalance', 5296 call: 'eth_getBalance', 5297 params: 2, 5298 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5299 outputFormatter: formatters.outputBigNumberFormatter 5300 }); 5301 5302 var getStorageAt = new Method({ 5303 name: 'getStorageAt', 5304 call: 'eth_getStorageAt', 5305 params: 3, 5306 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5307 }); 5308 5309 var getCode = new Method({ 5310 name: 'getCode', 5311 call: 'eth_getCode', 5312 params: 2, 5313 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5314 }); 5315 5316 var getBlock = new Method({ 5317 name: 'getBlock', 5318 call: blockCall, 5319 params: 2, 5320 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5321 outputFormatter: formatters.outputBlockFormatter 5322 }); 5323 5324 var getUncle = new Method({ 5325 name: 'getUncle', 5326 call: uncleCall, 5327 params: 2, 5328 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5329 outputFormatter: formatters.outputBlockFormatter, 5330 5331 }); 5332 5333 var getCompilers = new Method({ 5334 name: 'getCompilers', 5335 call: 'eth_getCompilers', 5336 params: 0 5337 }); 5338 5339 var getBlockTransactionCount = new Method({ 5340 name: 'getBlockTransactionCount', 5341 call: getBlockTransactionCountCall, 5342 params: 1, 5343 inputFormatter: [formatters.inputBlockNumberFormatter], 5344 outputFormatter: utils.toDecimal 5345 }); 5346 5347 var getBlockUncleCount = new Method({ 5348 name: 'getBlockUncleCount', 5349 call: uncleCountCall, 5350 params: 1, 5351 inputFormatter: [formatters.inputBlockNumberFormatter], 5352 outputFormatter: utils.toDecimal 5353 }); 5354 5355 var getTransaction = new Method({ 5356 name: 'getTransaction', 5357 call: 'eth_getTransactionByHash', 5358 params: 1, 5359 outputFormatter: formatters.outputTransactionFormatter 5360 }); 5361 5362 var getTransactionFromBlock = new Method({ 5363 name: 'getTransactionFromBlock', 5364 call: transactionFromBlockCall, 5365 params: 2, 5366 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5367 outputFormatter: formatters.outputTransactionFormatter 5368 }); 5369 5370 var getTransactionReceipt = new Method({ 5371 name: 'getTransactionReceipt', 5372 call: 'eth_getTransactionReceipt', 5373 params: 1, 5374 outputFormatter: formatters.outputTransactionReceiptFormatter 5375 }); 5376 5377 var getTransactionCount = new Method({ 5378 name: 'getTransactionCount', 5379 call: 'eth_getTransactionCount', 5380 params: 2, 5381 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5382 outputFormatter: utils.toDecimal 5383 }); 5384 5385 var sendRawTransaction = new Method({ 5386 name: 'sendRawTransaction', 5387 call: 'eth_sendRawTransaction', 5388 params: 1, 5389 inputFormatter: [null] 5390 }); 5391 5392 var sendTransaction = new Method({ 5393 name: 'sendTransaction', 5394 call: 'eth_sendTransaction', 5395 params: 1, 5396 inputFormatter: [formatters.inputTransactionFormatter] 5397 }); 5398 5399 var signTransaction = new Method({ 5400 name: 'signTransaction', 5401 call: 'eth_signTransaction', 5402 params: 1, 5403 inputFormatter: [formatters.inputTransactionFormatter] 5404 }); 5405 5406 var sign = new Method({ 5407 name: 'sign', 5408 call: 'eth_sign', 5409 params: 2, 5410 inputFormatter: [formatters.inputAddressFormatter, null] 5411 }); 5412 5413 var call = new Method({ 5414 name: 'call', 5415 call: 'eth_call', 5416 params: 2, 5417 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5418 }); 5419 5420 var estimateGas = new Method({ 5421 name: 'estimateGas', 5422 call: 'eth_estimateGas', 5423 params: 1, 5424 inputFormatter: [formatters.inputCallFormatter], 5425 outputFormatter: utils.toDecimal 5426 }); 5427 5428 return [ 5429 getBalance, 5430 getStorageAt, 5431 getCode, 5432 getBlock, 5433 getUncle, 5434 getCompilers, 5435 getBlockTransactionCount, 5436 getBlockUncleCount, 5437 getTransaction, 5438 getTransactionFromBlock, 5439 getTransactionReceipt, 5440 getTransactionCount, 5441 call, 5442 estimateGas, 5443 sendRawTransaction, 5444 signTransaction, 5445 sendTransaction, 5446 sign 5447 ]; 5448 }; 5449 5450 5451 var properties = function () { 5452 return [ 5453 new Property({ 5454 name: 'coinbase', 5455 getter: 'eth_coinbase' 5456 }), 5457 new Property({ 5458 name: 'mining', 5459 getter: 'eth_mining' 5460 }), 5461 new Property({ 5462 name: 'hashrate', 5463 getter: 'eth_hashrate', 5464 outputFormatter: utils.toDecimal 5465 }), 5466 new Property({ 5467 name: 'syncing', 5468 getter: 'eth_syncing', 5469 outputFormatter: formatters.outputSyncingFormatter 5470 }), 5471 new Property({ 5472 name: 'gasPrice', 5473 getter: 'eth_gasPrice', 5474 outputFormatter: formatters.outputBigNumberFormatter 5475 }), 5476 new Property({ 5477 name: 'blobBaseFee', 5478 getter: 'eth_blobBaseFee', 5479 outputFormatter: formatters.outputBigNumberFormatter 5480 }), 5481 new Property({ 5482 name: 'accounts', 5483 getter: 'eth_accounts' 5484 }), 5485 new Property({ 5486 name: 'blockNumber', 5487 getter: 'eth_blockNumber', 5488 outputFormatter: utils.toDecimal 5489 }), 5490 new Property({ 5491 name: 'protocolVersion', 5492 getter: 'eth_protocolVersion' 5493 }) 5494 ]; 5495 }; 5496 5497 Eth.prototype.contract = function (abi) { 5498 var factory = new Contract(this, abi); 5499 return factory; 5500 }; 5501 5502 Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5503 return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5504 }; 5505 5506 Eth.prototype.namereg = function () { 5507 return this.contract(namereg.global.abi).at(namereg.global.address); 5508 }; 5509 5510 Eth.prototype.icapNamereg = function () { 5511 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5512 }; 5513 5514 Eth.prototype.isSyncing = function (callback) { 5515 return new IsSyncing(this._requestManager, callback); 5516 }; 5517 5518 module.exports = Eth; 5519 5520 },{"../../utils/config":18,"../../utils/utils":20,"../contract":25,"../filter":29,"../formatters":30,"../iban":33,"../method":36,"../namereg":44,"../property":45,"../syncing":48,"../transfer":49,"./watches":43}],39:[function(require,module,exports){ 5521 /* 5522 This file is part of web3.js. 5523 5524 web3.js is free software: you can redistribute it and/or modify 5525 it under the terms of the GNU Lesser General Public License as published by 5526 the Free Software Foundation, either version 3 of the License, or 5527 (at your option) any later version. 5528 5529 web3.js is distributed in the hope that it will be useful, 5530 but WITHOUT ANY WARRANTY; without even the implied warranty of 5531 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5532 GNU Lesser General Public License for more details. 5533 5534 You should have received a copy of the GNU Lesser General Public License 5535 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5536 */ 5537 /** @file eth.js 5538 * @authors: 5539 * Marek Kotewicz <marek@ethdev.com> 5540 * @date 2015 5541 */ 5542 5543 var utils = require('../../utils/utils'); 5544 var Property = require('../property'); 5545 5546 var Net = function (web3) { 5547 this._requestManager = web3._requestManager; 5548 5549 var self = this; 5550 5551 properties().forEach(function(p) { 5552 p.attachToObject(self); 5553 p.setRequestManager(web3._requestManager); 5554 }); 5555 }; 5556 5557 /// @returns an array of objects describing web3.eth api properties 5558 var properties = function () { 5559 return [ 5560 new Property({ 5561 name: 'listening', 5562 getter: 'net_listening' 5563 }), 5564 new Property({ 5565 name: 'peerCount', 5566 getter: 'net_peerCount', 5567 outputFormatter: utils.toDecimal 5568 }) 5569 ]; 5570 }; 5571 5572 module.exports = Net; 5573 5574 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 5575 /* 5576 This file is part of web3.js. 5577 5578 web3.js is free software: you can redistribute it and/or modify 5579 it under the terms of the GNU Lesser General Public License as published by 5580 the Free Software Foundation, either version 3 of the License, or 5581 (at your option) any later version. 5582 5583 web3.js is distributed in the hope that it will be useful, 5584 but WITHOUT ANY WARRANTY; without even the implied warranty of 5585 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5586 GNU Lesser General Public License for more details. 5587 5588 You should have received a copy of the GNU Lesser General Public License 5589 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5590 */ 5591 /** 5592 * @file eth.js 5593 * @author Marek Kotewicz <marek@ethdev.com> 5594 * @author Fabian Vogelsteller <fabian@ethdev.com> 5595 * @date 2015 5596 */ 5597 5598 "use strict"; 5599 5600 var Method = require('../method'); 5601 var Property = require('../property'); 5602 var formatters = require('../formatters'); 5603 5604 function Personal(web3) { 5605 this._requestManager = web3._requestManager; 5606 5607 var self = this; 5608 5609 methods().forEach(function(method) { 5610 method.attachToObject(self); 5611 method.setRequestManager(self._requestManager); 5612 }); 5613 5614 properties().forEach(function(p) { 5615 p.attachToObject(self); 5616 p.setRequestManager(self._requestManager); 5617 }); 5618 } 5619 5620 var methods = function () { 5621 var newAccount = new Method({ 5622 name: 'newAccount', 5623 call: 'personal_newAccount', 5624 params: 1, 5625 inputFormatter: [null] 5626 }); 5627 5628 var importRawKey = new Method({ 5629 name: 'importRawKey', 5630 call: 'personal_importRawKey', 5631 params: 2 5632 }); 5633 5634 var sign = new Method({ 5635 name: 'sign', 5636 call: 'personal_sign', 5637 params: 3, 5638 inputFormatter: [null, formatters.inputAddressFormatter, null] 5639 }); 5640 5641 var ecRecover = new Method({ 5642 name: 'ecRecover', 5643 call: 'personal_ecRecover', 5644 params: 2 5645 }); 5646 5647 var unlockAccount = new Method({ 5648 name: 'unlockAccount', 5649 call: 'personal_unlockAccount', 5650 params: 3, 5651 inputFormatter: [formatters.inputAddressFormatter, null, null] 5652 }); 5653 5654 var sendTransaction = new Method({ 5655 name: 'sendTransaction', 5656 call: 'personal_sendTransaction', 5657 params: 2, 5658 inputFormatter: [formatters.inputTransactionFormatter, null] 5659 }); 5660 5661 var lockAccount = new Method({ 5662 name: 'lockAccount', 5663 call: 'personal_lockAccount', 5664 params: 1, 5665 inputFormatter: [formatters.inputAddressFormatter] 5666 }); 5667 5668 return [ 5669 newAccount, 5670 importRawKey, 5671 unlockAccount, 5672 ecRecover, 5673 sign, 5674 sendTransaction, 5675 lockAccount 5676 ]; 5677 }; 5678 5679 var properties = function () { 5680 return [ 5681 new Property({ 5682 name: 'listAccounts', 5683 getter: 'personal_listAccounts' 5684 }) 5685 ]; 5686 }; 5687 5688 5689 module.exports = Personal; 5690 5691 },{"../formatters":30,"../method":36,"../property":45}],43:[function(require,module,exports){ 5692 /* 5693 This file is part of web3.js. 5694 5695 web3.js is free software: you can redistribute it and/or modify 5696 it under the terms of the GNU Lesser General Public License as published by 5697 the Free Software Foundation, either version 3 of the License, or 5698 (at your option) any later version. 5699 5700 web3.js is distributed in the hope that it will be useful, 5701 but WITHOUT ANY WARRANTY; without even the implied warranty of 5702 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5703 GNU Lesser General Public License for more details. 5704 5705 You should have received a copy of the GNU Lesser General Public License 5706 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5707 */ 5708 /** @file watches.js 5709 * @authors: 5710 * Marek Kotewicz <marek@ethdev.com> 5711 * @date 2015 5712 */ 5713 5714 var Method = require('../method'); 5715 5716 /// @returns an array of objects describing web3.eth.filter api methods 5717 var eth = function () { 5718 var newFilterCall = function (args) { 5719 var type = args[0]; 5720 5721 switch(type) { 5722 case 'latest': 5723 args.shift(); 5724 this.params = 0; 5725 return 'eth_newBlockFilter'; 5726 case 'pending': 5727 args.shift(); 5728 this.params = 0; 5729 return 'eth_newPendingTransactionFilter'; 5730 default: 5731 return 'eth_newFilter'; 5732 } 5733 }; 5734 5735 var newFilter = new Method({ 5736 name: 'newFilter', 5737 call: newFilterCall, 5738 params: 1 5739 }); 5740 5741 var uninstallFilter = new Method({ 5742 name: 'uninstallFilter', 5743 call: 'eth_uninstallFilter', 5744 params: 1 5745 }); 5746 5747 var getLogs = new Method({ 5748 name: 'getLogs', 5749 call: 'eth_getFilterLogs', 5750 params: 1 5751 }); 5752 5753 var poll = new Method({ 5754 name: 'poll', 5755 call: 'eth_getFilterChanges', 5756 params: 1 5757 }); 5758 5759 return [ 5760 newFilter, 5761 uninstallFilter, 5762 getLogs, 5763 poll 5764 ]; 5765 }; 5766 5767 module.exports = { 5768 eth: eth 5769 }; 5770 5771 5772 },{"../method":36}],44:[function(require,module,exports){ 5773 /* 5774 This file is part of web3.js. 5775 5776 web3.js is free software: you can redistribute it and/or modify 5777 it under the terms of the GNU Lesser General Public License as published by 5778 the Free Software Foundation, either version 3 of the License, or 5779 (at your option) any later version. 5780 5781 web3.js is distributed in the hope that it will be useful, 5782 but WITHOUT ANY WARRANTY; without even the implied warranty of 5783 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5784 GNU Lesser General Public License for more details. 5785 5786 You should have received a copy of the GNU Lesser General Public License 5787 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5788 */ 5789 /** 5790 * @file namereg.js 5791 * @author Marek Kotewicz <marek@ethdev.com> 5792 * @date 2015 5793 */ 5794 5795 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 5796 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 5797 5798 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 5799 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 5800 5801 module.exports = { 5802 global: { 5803 abi: globalRegistrarAbi, 5804 address: globalNameregAddress 5805 }, 5806 icap: { 5807 abi: icapRegistrarAbi, 5808 address: icapNameregAddress 5809 } 5810 }; 5811 5812 5813 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 5814 /* 5815 This file is part of web3.js. 5816 5817 web3.js is free software: you can redistribute it and/or modify 5818 it under the terms of the GNU Lesser General Public License as published by 5819 the Free Software Foundation, either version 3 of the License, or 5820 (at your option) any later version. 5821 5822 web3.js is distributed in the hope that it will be useful, 5823 but WITHOUT ANY WARRANTY; without even the implied warranty of 5824 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5825 GNU Lesser General Public License for more details. 5826 5827 You should have received a copy of the GNU Lesser General Public License 5828 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5829 */ 5830 /** 5831 * @file property.js 5832 * @author Fabian Vogelsteller <fabian@frozeman.de> 5833 * @author Marek Kotewicz <marek@ethdev.com> 5834 * @date 2015 5835 */ 5836 5837 var utils = require('../utils/utils'); 5838 5839 var Property = function (options) { 5840 this.name = options.name; 5841 this.getter = options.getter; 5842 this.setter = options.setter; 5843 this.outputFormatter = options.outputFormatter; 5844 this.inputFormatter = options.inputFormatter; 5845 this.requestManager = null; 5846 }; 5847 5848 Property.prototype.setRequestManager = function (rm) { 5849 this.requestManager = rm; 5850 }; 5851 5852 /** 5853 * Should be called to format input args of method 5854 * 5855 * @method formatInput 5856 * @param {Array} 5857 * @return {Array} 5858 */ 5859 Property.prototype.formatInput = function (arg) { 5860 return this.inputFormatter ? this.inputFormatter(arg) : arg; 5861 }; 5862 5863 /** 5864 * Should be called to format output(result) of method 5865 * 5866 * @method formatOutput 5867 * @param {Object} 5868 * @return {Object} 5869 */ 5870 Property.prototype.formatOutput = function (result) { 5871 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 5872 }; 5873 5874 /** 5875 * Should be used to extract callback from array of arguments. Modifies input param 5876 * 5877 * @method extractCallback 5878 * @param {Array} arguments 5879 * @return {Function|Null} callback, if exists 5880 */ 5881 Property.prototype.extractCallback = function (args) { 5882 if (utils.isFunction(args[args.length - 1])) { 5883 return args.pop(); // modify the args array! 5884 } 5885 }; 5886 5887 5888 /** 5889 * Should attach function to method 5890 * 5891 * @method attachToObject 5892 * @param {Object} 5893 * @param {Function} 5894 */ 5895 Property.prototype.attachToObject = function (obj) { 5896 var proto = { 5897 get: this.buildGet(), 5898 enumerable: true 5899 }; 5900 5901 var names = this.name.split('.'); 5902 var name = names[0]; 5903 if (names.length > 1) { 5904 obj[names[0]] = obj[names[0]] || {}; 5905 obj = obj[names[0]]; 5906 name = names[1]; 5907 } 5908 5909 Object.defineProperty(obj, name, proto); 5910 obj[asyncGetterName(name)] = this.buildAsyncGet(); 5911 }; 5912 5913 var asyncGetterName = function (name) { 5914 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 5915 }; 5916 5917 Property.prototype.buildGet = function () { 5918 var property = this; 5919 return function get() { 5920 return property.formatOutput(property.requestManager.send({ 5921 method: property.getter 5922 })); 5923 }; 5924 }; 5925 5926 Property.prototype.buildAsyncGet = function () { 5927 var property = this; 5928 var get = function (callback) { 5929 property.requestManager.sendAsync({ 5930 method: property.getter 5931 }, function (err, result) { 5932 callback(err, property.formatOutput(result)); 5933 }); 5934 }; 5935 get.request = this.request.bind(this); 5936 return get; 5937 }; 5938 5939 /** 5940 * Should be called to create pure JSONRPC request which can be used in batch request 5941 * 5942 * @method request 5943 * @param {...} params 5944 * @return {Object} jsonrpc request 5945 */ 5946 Property.prototype.request = function () { 5947 var payload = { 5948 method: this.getter, 5949 params: [], 5950 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 5951 }; 5952 payload.format = this.formatOutput.bind(this); 5953 return payload; 5954 }; 5955 5956 module.exports = Property; 5957 5958 5959 },{"../utils/utils":20}],46:[function(require,module,exports){ 5960 /* 5961 This file is part of web3.js. 5962 5963 web3.js is free software: you can redistribute it and/or modify 5964 it under the terms of the GNU Lesser General Public License as published by 5965 the Free Software Foundation, either version 3 of the License, or 5966 (at your option) any later version. 5967 5968 web3.js is distributed in the hope that it will be useful, 5969 but WITHOUT ANY WARRANTY; without even the implied warranty of 5970 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5971 GNU Lesser General Public License for more details. 5972 5973 You should have received a copy of the GNU Lesser General Public License 5974 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5975 */ 5976 /** 5977 * @file requestmanager.js 5978 * @author Jeffrey Wilcke <jeff@ethdev.com> 5979 * @author Marek Kotewicz <marek@ethdev.com> 5980 * @author Marian Oancea <marian@ethdev.com> 5981 * @author Fabian Vogelsteller <fabian@ethdev.com> 5982 * @author Gav Wood <g@ethdev.com> 5983 * @date 2014 5984 */ 5985 5986 var Jsonrpc = require('./jsonrpc'); 5987 var utils = require('../utils/utils'); 5988 var c = require('../utils/config'); 5989 var errors = require('./errors'); 5990 5991 /** 5992 * It's responsible for passing messages to providers 5993 * It's also responsible for polling the ethereum node for incoming messages 5994 * Default poll timeout is 1 second 5995 * Singleton 5996 */ 5997 var RequestManager = function (provider) { 5998 this.provider = provider; 5999 this.polls = {}; 6000 this.timeout = null; 6001 }; 6002 6003 /** 6004 * Should be used to synchronously send request 6005 * 6006 * @method send 6007 * @param {Object} data 6008 * @return {Object} 6009 */ 6010 RequestManager.prototype.send = function (data) { 6011 if (!this.provider) { 6012 console.error(errors.InvalidProvider()); 6013 return null; 6014 } 6015 6016 var payload = Jsonrpc.toPayload(data.method, data.params); 6017 var result = this.provider.send(payload); 6018 6019 if (!Jsonrpc.isValidResponse(result)) { 6020 throw errors.InvalidResponse(result); 6021 } 6022 6023 return result.result; 6024 }; 6025 6026 /** 6027 * Should be used to asynchronously send request 6028 * 6029 * @method sendAsync 6030 * @param {Object} data 6031 * @param {Function} callback 6032 */ 6033 RequestManager.prototype.sendAsync = function (data, callback) { 6034 if (!this.provider) { 6035 return callback(errors.InvalidProvider()); 6036 } 6037 6038 var payload = Jsonrpc.toPayload(data.method, data.params); 6039 this.provider.sendAsync(payload, function (err, result) { 6040 if (err) { 6041 return callback(err); 6042 } 6043 6044 if (!Jsonrpc.isValidResponse(result)) { 6045 return callback(errors.InvalidResponse(result)); 6046 } 6047 6048 callback(null, result.result); 6049 }); 6050 }; 6051 6052 /** 6053 * Should be called to asynchronously send batch request 6054 * 6055 * @method sendBatch 6056 * @param {Array} batch data 6057 * @param {Function} callback 6058 */ 6059 RequestManager.prototype.sendBatch = function (data, callback) { 6060 if (!this.provider) { 6061 return callback(errors.InvalidProvider()); 6062 } 6063 6064 var payload = Jsonrpc.toBatchPayload(data); 6065 6066 this.provider.sendAsync(payload, function (err, results) { 6067 if (err) { 6068 return callback(err); 6069 } 6070 6071 if (!utils.isArray(results)) { 6072 return callback(errors.InvalidResponse(results)); 6073 } 6074 6075 callback(err, results); 6076 }); 6077 }; 6078 6079 /** 6080 * Should be used to set provider of request manager 6081 * 6082 * @method setProvider 6083 * @param {Object} 6084 */ 6085 RequestManager.prototype.setProvider = function (p) { 6086 this.provider = p; 6087 }; 6088 6089 /** 6090 * Should be used to start polling 6091 * 6092 * @method startPolling 6093 * @param {Object} data 6094 * @param {Number} pollId 6095 * @param {Function} callback 6096 * @param {Function} uninstall 6097 * 6098 * @todo cleanup number of params 6099 */ 6100 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6101 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 6102 6103 6104 // start polling 6105 if (!this.timeout) { 6106 this.poll(); 6107 } 6108 }; 6109 6110 /** 6111 * Should be used to stop polling for filter with given id 6112 * 6113 * @method stopPolling 6114 * @param {Number} pollId 6115 */ 6116 RequestManager.prototype.stopPolling = function (pollId) { 6117 delete this.polls[pollId]; 6118 6119 // stop polling 6120 if(Object.keys(this.polls).length === 0 && this.timeout) { 6121 clearTimeout(this.timeout); 6122 this.timeout = null; 6123 } 6124 }; 6125 6126 /** 6127 * Should be called to reset the polling mechanism of the request manager 6128 * 6129 * @method reset 6130 */ 6131 RequestManager.prototype.reset = function (keepIsSyncing) { 6132 /*jshint maxcomplexity:5 */ 6133 6134 for (var key in this.polls) { 6135 // remove all polls, except sync polls, 6136 // they need to be removed manually by calling syncing.stopWatching() 6137 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6138 this.polls[key].uninstall(); 6139 delete this.polls[key]; 6140 } 6141 } 6142 6143 // stop polling 6144 if(Object.keys(this.polls).length === 0 && this.timeout) { 6145 clearTimeout(this.timeout); 6146 this.timeout = null; 6147 } 6148 }; 6149 6150 /** 6151 * Should be called to poll for changes on filter with given id 6152 * 6153 * @method poll 6154 */ 6155 RequestManager.prototype.poll = function () { 6156 /*jshint maxcomplexity: 6 */ 6157 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6158 6159 if (Object.keys(this.polls).length === 0) { 6160 return; 6161 } 6162 6163 if (!this.provider) { 6164 console.error(errors.InvalidProvider()); 6165 return; 6166 } 6167 6168 var pollsData = []; 6169 var pollsIds = []; 6170 for (var key in this.polls) { 6171 pollsData.push(this.polls[key].data); 6172 pollsIds.push(key); 6173 } 6174 6175 if (pollsData.length === 0) { 6176 return; 6177 } 6178 6179 var payload = Jsonrpc.toBatchPayload(pollsData); 6180 6181 // map the request id to they poll id 6182 var pollsIdMap = {}; 6183 payload.forEach(function(load, index){ 6184 pollsIdMap[load.id] = pollsIds[index]; 6185 }); 6186 6187 6188 var self = this; 6189 this.provider.sendAsync(payload, function (error, results) { 6190 6191 6192 // TODO: console log? 6193 if (error) { 6194 return; 6195 } 6196 6197 if (!utils.isArray(results)) { 6198 throw errors.InvalidResponse(results); 6199 } 6200 results.map(function (result) { 6201 var id = pollsIdMap[result.id]; 6202 6203 // make sure the filter is still installed after arrival of the request 6204 if (self.polls[id]) { 6205 result.callback = self.polls[id].callback; 6206 return result; 6207 } else 6208 return false; 6209 }).filter(function (result) { 6210 return !!result; 6211 }).filter(function (result) { 6212 var valid = Jsonrpc.isValidResponse(result); 6213 if (!valid) { 6214 result.callback(errors.InvalidResponse(result)); 6215 } 6216 return valid; 6217 }).forEach(function (result) { 6218 result.callback(null, result.result); 6219 }); 6220 }); 6221 }; 6222 6223 module.exports = RequestManager; 6224 6225 6226 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 6227 6228 6229 var Settings = function () { 6230 this.defaultBlock = 'latest'; 6231 this.defaultAccount = undefined; 6232 }; 6233 6234 module.exports = Settings; 6235 6236 6237 },{}],48:[function(require,module,exports){ 6238 /* 6239 This file is part of web3.js. 6240 6241 web3.js is free software: you can redistribute it and/or modify 6242 it under the terms of the GNU Lesser General Public License as published by 6243 the Free Software Foundation, either version 3 of the License, or 6244 (at your option) any later version. 6245 6246 web3.js is distributed in the hope that it will be useful, 6247 but WITHOUT ANY WARRANTY; without even the implied warranty of 6248 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6249 GNU Lesser General Public License for more details. 6250 6251 You should have received a copy of the GNU Lesser General Public License 6252 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6253 */ 6254 /** @file syncing.js 6255 * @authors: 6256 * Fabian Vogelsteller <fabian@ethdev.com> 6257 * @date 2015 6258 */ 6259 6260 var formatters = require('./formatters'); 6261 var utils = require('../utils/utils'); 6262 6263 var count = 1; 6264 6265 /** 6266 Adds the callback and sets up the methods, to iterate over the results. 6267 6268 @method pollSyncing 6269 @param {Object} self 6270 */ 6271 var pollSyncing = function(self) { 6272 6273 var onMessage = function (error, sync) { 6274 if (error) { 6275 return self.callbacks.forEach(function (callback) { 6276 callback(error); 6277 }); 6278 } 6279 6280 if(utils.isObject(sync) && sync.startingBlock) 6281 sync = formatters.outputSyncingFormatter(sync); 6282 6283 self.callbacks.forEach(function (callback) { 6284 if (self.lastSyncState !== sync) { 6285 6286 // call the callback with true first so the app can stop anything, before receiving the sync data 6287 if(!self.lastSyncState && utils.isObject(sync)) 6288 callback(null, true); 6289 6290 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6291 setTimeout(function() { 6292 callback(null, sync); 6293 }, 0); 6294 6295 self.lastSyncState = sync; 6296 } 6297 }); 6298 }; 6299 6300 self.requestManager.startPolling({ 6301 method: 'eth_syncing', 6302 params: [], 6303 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6304 6305 }; 6306 6307 var IsSyncing = function (requestManager, callback) { 6308 this.requestManager = requestManager; 6309 this.pollId = 'syncPoll_'+ count++; 6310 this.callbacks = []; 6311 this.addCallback(callback); 6312 this.lastSyncState = false; 6313 pollSyncing(this); 6314 6315 return this; 6316 }; 6317 6318 IsSyncing.prototype.addCallback = function (callback) { 6319 if(callback) 6320 this.callbacks.push(callback); 6321 return this; 6322 }; 6323 6324 IsSyncing.prototype.stopWatching = function () { 6325 this.requestManager.stopPolling(this.pollId); 6326 this.callbacks = []; 6327 }; 6328 6329 module.exports = IsSyncing; 6330 6331 6332 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 6333 /* 6334 This file is part of web3.js. 6335 6336 web3.js is free software: you can redistribute it and/or modify 6337 it under the terms of the GNU Lesser General Public License as published by 6338 the Free Software Foundation, either version 3 of the License, or 6339 (at your option) any later version. 6340 6341 web3.js is distributed in the hope that it will be useful, 6342 but WITHOUT ANY WARRANTY; without even the implied warranty of 6343 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6344 GNU Lesser General Public License for more details. 6345 6346 You should have received a copy of the GNU Lesser General Public License 6347 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6348 */ 6349 /** 6350 * @file transfer.js 6351 * @author Marek Kotewicz <marek@ethdev.com> 6352 * @date 2015 6353 */ 6354 6355 var Iban = require('./iban'); 6356 var exchangeAbi = require('../contracts/SmartExchange.json'); 6357 6358 /** 6359 * Should be used to make Iban transfer 6360 * 6361 * @method transfer 6362 * @param {String} from 6363 * @param {String} to iban 6364 * @param {Value} value to be transferred 6365 * @param {Function} callback, callback 6366 */ 6367 var transfer = function (eth, from, to, value, callback) { 6368 var iban = new Iban(to); 6369 if (!iban.isValid()) { 6370 throw new Error('invalid iban address'); 6371 } 6372 6373 if (iban.isDirect()) { 6374 return transferToAddress(eth, from, iban.address(), value, callback); 6375 } 6376 6377 if (!callback) { 6378 var address = eth.icapNamereg().addr(iban.institution()); 6379 return deposit(eth, from, address, value, iban.client()); 6380 } 6381 6382 eth.icapNamereg().addr(iban.institution(), function (err, address) { 6383 return deposit(eth, from, address, value, iban.client(), callback); 6384 }); 6385 6386 }; 6387 6388 /** 6389 * Should be used to transfer funds to certain address 6390 * 6391 * @method transferToAddress 6392 * @param {String} from 6393 * @param {String} to 6394 * @param {Value} value to be transferred 6395 * @param {Function} callback, callback 6396 */ 6397 var transferToAddress = function (eth, from, to, value, callback) { 6398 return eth.sendTransaction({ 6399 address: to, 6400 from: from, 6401 value: value 6402 }, callback); 6403 }; 6404 6405 /** 6406 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6407 * 6408 * @method deposit 6409 * @param {String} from 6410 * @param {String} to 6411 * @param {Value} value to be transferred 6412 * @param {String} client unique identifier 6413 * @param {Function} callback, callback 6414 */ 6415 var deposit = function (eth, from, to, value, client, callback) { 6416 var abi = exchangeAbi; 6417 return eth.contract(abi).at(to).deposit(client, { 6418 from: from, 6419 value: value 6420 }, callback); 6421 }; 6422 6423 module.exports = transfer; 6424 6425 6426 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 6427 6428 },{}],51:[function(require,module,exports){ 6429 ;(function (root, factory, undef) { 6430 if (typeof exports === "object") { 6431 // CommonJS 6432 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6433 } 6434 else if (typeof define === "function" && define.amd) { 6435 // AMD 6436 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6437 } 6438 else { 6439 // Global (browser) 6440 factory(root.CryptoJS); 6441 } 6442 }(this, function (CryptoJS) { 6443 6444 (function () { 6445 // Shortcuts 6446 var C = CryptoJS; 6447 var C_lib = C.lib; 6448 var BlockCipher = C_lib.BlockCipher; 6449 var C_algo = C.algo; 6450 6451 // Lookup tables 6452 var SBOX = []; 6453 var INV_SBOX = []; 6454 var SUB_MIX_0 = []; 6455 var SUB_MIX_1 = []; 6456 var SUB_MIX_2 = []; 6457 var SUB_MIX_3 = []; 6458 var INV_SUB_MIX_0 = []; 6459 var INV_SUB_MIX_1 = []; 6460 var INV_SUB_MIX_2 = []; 6461 var INV_SUB_MIX_3 = []; 6462 6463 // Compute lookup tables 6464 (function () { 6465 // Compute double table 6466 var d = []; 6467 for (var i = 0; i < 256; i++) { 6468 if (i < 128) { 6469 d[i] = i << 1; 6470 } else { 6471 d[i] = (i << 1) ^ 0x11b; 6472 } 6473 } 6474 6475 // Walk GF(2^8) 6476 var x = 0; 6477 var xi = 0; 6478 for (var i = 0; i < 256; i++) { 6479 // Compute sbox 6480 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6481 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6482 SBOX[x] = sx; 6483 INV_SBOX[sx] = x; 6484 6485 // Compute multiplication 6486 var x2 = d[x]; 6487 var x4 = d[x2]; 6488 var x8 = d[x4]; 6489 6490 // Compute sub bytes, mix columns tables 6491 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6492 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6493 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6494 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6495 SUB_MIX_3[x] = t; 6496 6497 // Compute inv sub bytes, inv mix columns tables 6498 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6499 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6500 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6501 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6502 INV_SUB_MIX_3[sx] = t; 6503 6504 // Compute next counter 6505 if (!x) { 6506 x = xi = 1; 6507 } else { 6508 x = x2 ^ d[d[d[x8 ^ x2]]]; 6509 xi ^= d[d[xi]]; 6510 } 6511 } 6512 }()); 6513 6514 // Precomputed Rcon lookup 6515 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6516 6517 /** 6518 * AES block cipher algorithm. 6519 */ 6520 var AES = C_algo.AES = BlockCipher.extend({ 6521 _doReset: function () { 6522 // Skip reset of nRounds has been set before and key did not change 6523 if (this._nRounds && this._keyPriorReset === this._key) { 6524 return; 6525 } 6526 6527 // Shortcuts 6528 var key = this._keyPriorReset = this._key; 6529 var keyWords = key.words; 6530 var keySize = key.sigBytes / 4; 6531 6532 // Compute number of rounds 6533 var nRounds = this._nRounds = keySize + 6; 6534 6535 // Compute number of key schedule rows 6536 var ksRows = (nRounds + 1) * 4; 6537 6538 // Compute key schedule 6539 var keySchedule = this._keySchedule = []; 6540 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 6541 if (ksRow < keySize) { 6542 keySchedule[ksRow] = keyWords[ksRow]; 6543 } else { 6544 var t = keySchedule[ksRow - 1]; 6545 6546 if (!(ksRow % keySize)) { 6547 // Rot word 6548 t = (t << 8) | (t >>> 24); 6549 6550 // Sub word 6551 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6552 6553 // Mix Rcon 6554 t ^= RCON[(ksRow / keySize) | 0] << 24; 6555 } else if (keySize > 6 && ksRow % keySize == 4) { 6556 // Sub word 6557 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6558 } 6559 6560 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 6561 } 6562 } 6563 6564 // Compute inv key schedule 6565 var invKeySchedule = this._invKeySchedule = []; 6566 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 6567 var ksRow = ksRows - invKsRow; 6568 6569 if (invKsRow % 4) { 6570 var t = keySchedule[ksRow]; 6571 } else { 6572 var t = keySchedule[ksRow - 4]; 6573 } 6574 6575 if (invKsRow < 4 || ksRow <= 4) { 6576 invKeySchedule[invKsRow] = t; 6577 } else { 6578 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 6579 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 6580 } 6581 } 6582 }, 6583 6584 encryptBlock: function (M, offset) { 6585 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 6586 }, 6587 6588 decryptBlock: function (M, offset) { 6589 // Swap 2nd and 4th rows 6590 var t = M[offset + 1]; 6591 M[offset + 1] = M[offset + 3]; 6592 M[offset + 3] = t; 6593 6594 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 6595 6596 // Inv swap 2nd and 4th rows 6597 var t = M[offset + 1]; 6598 M[offset + 1] = M[offset + 3]; 6599 M[offset + 3] = t; 6600 }, 6601 6602 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 6603 // Shortcut 6604 var nRounds = this._nRounds; 6605 6606 // Get input, add round key 6607 var s0 = M[offset] ^ keySchedule[0]; 6608 var s1 = M[offset + 1] ^ keySchedule[1]; 6609 var s2 = M[offset + 2] ^ keySchedule[2]; 6610 var s3 = M[offset + 3] ^ keySchedule[3]; 6611 6612 // Key schedule row counter 6613 var ksRow = 4; 6614 6615 // Rounds 6616 for (var round = 1; round < nRounds; round++) { 6617 // Shift rows, sub bytes, mix columns, add round key 6618 var t0 = SUB_MIX_0[s0 >>> 24] ^ SUB_MIX_1[(s1 >>> 16) & 0xff] ^ SUB_MIX_2[(s2 >>> 8) & 0xff] ^ SUB_MIX_3[s3 & 0xff] ^ keySchedule[ksRow++]; 6619 var t1 = SUB_MIX_0[s1 >>> 24] ^ SUB_MIX_1[(s2 >>> 16) & 0xff] ^ SUB_MIX_2[(s3 >>> 8) & 0xff] ^ SUB_MIX_3[s0 & 0xff] ^ keySchedule[ksRow++]; 6620 var t2 = SUB_MIX_0[s2 >>> 24] ^ SUB_MIX_1[(s3 >>> 16) & 0xff] ^ SUB_MIX_2[(s0 >>> 8) & 0xff] ^ SUB_MIX_3[s1 & 0xff] ^ keySchedule[ksRow++]; 6621 var t3 = SUB_MIX_0[s3 >>> 24] ^ SUB_MIX_1[(s0 >>> 16) & 0xff] ^ SUB_MIX_2[(s1 >>> 8) & 0xff] ^ SUB_MIX_3[s2 & 0xff] ^ keySchedule[ksRow++]; 6622 6623 // Update state 6624 s0 = t0; 6625 s1 = t1; 6626 s2 = t2; 6627 s3 = t3; 6628 } 6629 6630 // Shift rows, sub bytes, add round key 6631 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 6632 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 6633 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 6634 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 6635 6636 // Set output 6637 M[offset] = t0; 6638 M[offset + 1] = t1; 6639 M[offset + 2] = t2; 6640 M[offset + 3] = t3; 6641 }, 6642 6643 keySize: 256/32 6644 }); 6645 6646 /** 6647 * Shortcut functions to the cipher's object interface. 6648 * 6649 * @example 6650 * 6651 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 6652 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 6653 */ 6654 C.AES = BlockCipher._createHelper(AES); 6655 }()); 6656 6657 6658 return CryptoJS.AES; 6659 6660 })); 6661 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 6662 ;(function (root, factory) { 6663 if (typeof exports === "object") { 6664 // CommonJS 6665 module.exports = exports = factory(require("./core")); 6666 } 6667 else if (typeof define === "function" && define.amd) { 6668 // AMD 6669 define(["./core"], factory); 6670 } 6671 else { 6672 // Global (browser) 6673 factory(root.CryptoJS); 6674 } 6675 }(this, function (CryptoJS) { 6676 6677 /** 6678 * Cipher core components. 6679 */ 6680 CryptoJS.lib.Cipher || (function (undefined) { 6681 // Shortcuts 6682 var C = CryptoJS; 6683 var C_lib = C.lib; 6684 var Base = C_lib.Base; 6685 var WordArray = C_lib.WordArray; 6686 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 6687 var C_enc = C.enc; 6688 var Utf8 = C_enc.Utf8; 6689 var Base64 = C_enc.Base64; 6690 var C_algo = C.algo; 6691 var EvpKDF = C_algo.EvpKDF; 6692 6693 /** 6694 * Abstract base cipher template. 6695 * 6696 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 6697 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 6698 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 6699 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 6700 */ 6701 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 6702 /** 6703 * Configuration options. 6704 * 6705 * @property {WordArray} iv The IV to use for this operation. 6706 */ 6707 cfg: Base.extend(), 6708 6709 /** 6710 * Creates this cipher in encryption mode. 6711 * 6712 * @param {WordArray} key The key. 6713 * @param {Object} cfg (Optional) The configuration options to use for this operation. 6714 * 6715 * @return {Cipher} A cipher instance. 6716 * 6717 * @static 6718 * 6719 * @example 6720 * 6721 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 6722 */ 6723 createEncryptor: function (key, cfg) { 6724 return this.create(this._ENC_XFORM_MODE, key, cfg); 6725 }, 6726 6727 /** 6728 * Creates this cipher in decryption mode. 6729 * 6730 * @param {WordArray} key The key. 6731 * @param {Object} cfg (Optional) The configuration options to use for this operation. 6732 * 6733 * @return {Cipher} A cipher instance. 6734 * 6735 * @static 6736 * 6737 * @example 6738 * 6739 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 6740 */ 6741 createDecryptor: function (key, cfg) { 6742 return this.create(this._DEC_XFORM_MODE, key, cfg); 6743 }, 6744 6745 /** 6746 * Initializes a newly created cipher. 6747 * 6748 * @param {number} xformMode Either the encryption or decryption transformation mode constant. 6749 * @param {WordArray} key The key. 6750 * @param {Object} cfg (Optional) The configuration options to use for this operation. 6751 * 6752 * @example 6753 * 6754 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 6755 */ 6756 init: function (xformMode, key, cfg) { 6757 // Apply config defaults 6758 this.cfg = this.cfg.extend(cfg); 6759 6760 // Store transform mode and key 6761 this._xformMode = xformMode; 6762 this._key = key; 6763 6764 // Set initial values 6765 this.reset(); 6766 }, 6767 6768 /** 6769 * Resets this cipher to its initial state. 6770 * 6771 * @example 6772 * 6773 * cipher.reset(); 6774 */ 6775 reset: function () { 6776 // Reset data buffer 6777 BufferedBlockAlgorithm.reset.call(this); 6778 6779 // Perform concrete-cipher logic 6780 this._doReset(); 6781 }, 6782 6783 /** 6784 * Adds data to be encrypted or decrypted. 6785 * 6786 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 6787 * 6788 * @return {WordArray} The data after processing. 6789 * 6790 * @example 6791 * 6792 * var encrypted = cipher.process('data'); 6793 * var encrypted = cipher.process(wordArray); 6794 */ 6795 process: function (dataUpdate) { 6796 // Append 6797 this._append(dataUpdate); 6798 6799 // Process available blocks 6800 return this._process(); 6801 }, 6802 6803 /** 6804 * Finalizes the encryption or decryption process. 6805 * Note that the finalize operation is effectively a destructive, read-once operation. 6806 * 6807 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 6808 * 6809 * @return {WordArray} The data after final processing. 6810 * 6811 * @example 6812 * 6813 * var encrypted = cipher.finalize(); 6814 * var encrypted = cipher.finalize('data'); 6815 * var encrypted = cipher.finalize(wordArray); 6816 */ 6817 finalize: function (dataUpdate) { 6818 // Final data update 6819 if (dataUpdate) { 6820 this._append(dataUpdate); 6821 } 6822 6823 // Perform concrete-cipher logic 6824 var finalProcessedData = this._doFinalize(); 6825 6826 return finalProcessedData; 6827 }, 6828 6829 keySize: 128/32, 6830 6831 ivSize: 128/32, 6832 6833 _ENC_XFORM_MODE: 1, 6834 6835 _DEC_XFORM_MODE: 2, 6836 6837 /** 6838 * Creates shortcut functions to a cipher's object interface. 6839 * 6840 * @param {Cipher} cipher The cipher to create a helper for. 6841 * 6842 * @return {Object} An object with encrypt and decrypt shortcut functions. 6843 * 6844 * @static 6845 * 6846 * @example 6847 * 6848 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 6849 */ 6850 _createHelper: (function () { 6851 function selectCipherStrategy(key) { 6852 if (typeof key == 'string') { 6853 return PasswordBasedCipher; 6854 } else { 6855 return SerializableCipher; 6856 } 6857 } 6858 6859 return function (cipher) { 6860 return { 6861 encrypt: function (message, key, cfg) { 6862 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 6863 }, 6864 6865 decrypt: function (ciphertext, key, cfg) { 6866 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 6867 } 6868 }; 6869 }; 6870 }()) 6871 }); 6872 6873 /** 6874 * Abstract base stream cipher template. 6875 * 6876 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 6877 */ 6878 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 6879 _doFinalize: function () { 6880 // Process partial blocks 6881 var finalProcessedBlocks = this._process(!!'flush'); 6882 6883 return finalProcessedBlocks; 6884 }, 6885 6886 blockSize: 1 6887 }); 6888 6889 /** 6890 * Mode namespace. 6891 */ 6892 var C_mode = C.mode = {}; 6893 6894 /** 6895 * Abstract base block cipher mode template. 6896 */ 6897 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 6898 /** 6899 * Creates this mode for encryption. 6900 * 6901 * @param {Cipher} cipher A block cipher instance. 6902 * @param {Array} iv The IV words. 6903 * 6904 * @static 6905 * 6906 * @example 6907 * 6908 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 6909 */ 6910 createEncryptor: function (cipher, iv) { 6911 return this.Encryptor.create(cipher, iv); 6912 }, 6913 6914 /** 6915 * Creates this mode for decryption. 6916 * 6917 * @param {Cipher} cipher A block cipher instance. 6918 * @param {Array} iv The IV words. 6919 * 6920 * @static 6921 * 6922 * @example 6923 * 6924 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 6925 */ 6926 createDecryptor: function (cipher, iv) { 6927 return this.Decryptor.create(cipher, iv); 6928 }, 6929 6930 /** 6931 * Initializes a newly created mode. 6932 * 6933 * @param {Cipher} cipher A block cipher instance. 6934 * @param {Array} iv The IV words. 6935 * 6936 * @example 6937 * 6938 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 6939 */ 6940 init: function (cipher, iv) { 6941 this._cipher = cipher; 6942 this._iv = iv; 6943 } 6944 }); 6945 6946 /** 6947 * Cipher Block Chaining mode. 6948 */ 6949 var CBC = C_mode.CBC = (function () { 6950 /** 6951 * Abstract base CBC mode. 6952 */ 6953 var CBC = BlockCipherMode.extend(); 6954 6955 /** 6956 * CBC encryptor. 6957 */ 6958 CBC.Encryptor = CBC.extend({ 6959 /** 6960 * Processes the data block at offset. 6961 * 6962 * @param {Array} words The data words to operate on. 6963 * @param {number} offset The offset where the block starts. 6964 * 6965 * @example 6966 * 6967 * mode.processBlock(data.words, offset); 6968 */ 6969 processBlock: function (words, offset) { 6970 // Shortcuts 6971 var cipher = this._cipher; 6972 var blockSize = cipher.blockSize; 6973 6974 // XOR and encrypt 6975 xorBlock.call(this, words, offset, blockSize); 6976 cipher.encryptBlock(words, offset); 6977 6978 // Remember this block to use with next block 6979 this._prevBlock = words.slice(offset, offset + blockSize); 6980 } 6981 }); 6982 6983 /** 6984 * CBC decryptor. 6985 */ 6986 CBC.Decryptor = CBC.extend({ 6987 /** 6988 * Processes the data block at offset. 6989 * 6990 * @param {Array} words The data words to operate on. 6991 * @param {number} offset The offset where the block starts. 6992 * 6993 * @example 6994 * 6995 * mode.processBlock(data.words, offset); 6996 */ 6997 processBlock: function (words, offset) { 6998 // Shortcuts 6999 var cipher = this._cipher; 7000 var blockSize = cipher.blockSize; 7001 7002 // Remember this block to use with next block 7003 var thisBlock = words.slice(offset, offset + blockSize); 7004 7005 // Decrypt and XOR 7006 cipher.decryptBlock(words, offset); 7007 xorBlock.call(this, words, offset, blockSize); 7008 7009 // This block becomes the previous block 7010 this._prevBlock = thisBlock; 7011 } 7012 }); 7013 7014 function xorBlock(words, offset, blockSize) { 7015 // Shortcut 7016 var iv = this._iv; 7017 7018 // Choose mixing block 7019 if (iv) { 7020 var block = iv; 7021 7022 // Remove IV for subsequent blocks 7023 this._iv = undefined; 7024 } else { 7025 var block = this._prevBlock; 7026 } 7027 7028 // XOR blocks 7029 for (var i = 0; i < blockSize; i++) { 7030 words[offset + i] ^= block[i]; 7031 } 7032 } 7033 7034 return CBC; 7035 }()); 7036 7037 /** 7038 * Padding namespace. 7039 */ 7040 var C_pad = C.pad = {}; 7041 7042 /** 7043 * PKCS #5/7 padding strategy. 7044 */ 7045 var Pkcs7 = C_pad.Pkcs7 = { 7046 /** 7047 * Pads data using the algorithm defined in PKCS #5/7. 7048 * 7049 * @param {WordArray} data The data to pad. 7050 * @param {number} blockSize The multiple that the data should be padded to. 7051 * 7052 * @static 7053 * 7054 * @example 7055 * 7056 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7057 */ 7058 pad: function (data, blockSize) { 7059 // Shortcut 7060 var blockSizeBytes = blockSize * 4; 7061 7062 // Count padding bytes 7063 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7064 7065 // Create padding word 7066 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7067 7068 // Create padding 7069 var paddingWords = []; 7070 for (var i = 0; i < nPaddingBytes; i += 4) { 7071 paddingWords.push(paddingWord); 7072 } 7073 var padding = WordArray.create(paddingWords, nPaddingBytes); 7074 7075 // Add padding 7076 data.concat(padding); 7077 }, 7078 7079 /** 7080 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7081 * 7082 * @param {WordArray} data The data to unpad. 7083 * 7084 * @static 7085 * 7086 * @example 7087 * 7088 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7089 */ 7090 unpad: function (data) { 7091 // Get number of padding bytes from last byte 7092 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7093 7094 // Remove padding 7095 data.sigBytes -= nPaddingBytes; 7096 } 7097 }; 7098 7099 /** 7100 * Abstract base block cipher template. 7101 * 7102 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7103 */ 7104 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7105 /** 7106 * Configuration options. 7107 * 7108 * @property {Mode} mode The block mode to use. Default: CBC 7109 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7110 */ 7111 cfg: Cipher.cfg.extend({ 7112 mode: CBC, 7113 padding: Pkcs7 7114 }), 7115 7116 reset: function () { 7117 // Reset cipher 7118 Cipher.reset.call(this); 7119 7120 // Shortcuts 7121 var cfg = this.cfg; 7122 var iv = cfg.iv; 7123 var mode = cfg.mode; 7124 7125 // Reset block mode 7126 if (this._xformMode == this._ENC_XFORM_MODE) { 7127 var modeCreator = mode.createEncryptor; 7128 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7129 var modeCreator = mode.createDecryptor; 7130 7131 // Keep at least one block in the buffer for unpadding 7132 this._minBufferSize = 1; 7133 } 7134 this._mode = modeCreator.call(mode, this, iv && iv.words); 7135 }, 7136 7137 _doProcessBlock: function (words, offset) { 7138 this._mode.processBlock(words, offset); 7139 }, 7140 7141 _doFinalize: function () { 7142 // Shortcut 7143 var padding = this.cfg.padding; 7144 7145 // Finalize 7146 if (this._xformMode == this._ENC_XFORM_MODE) { 7147 // Pad data 7148 padding.pad(this._data, this.blockSize); 7149 7150 // Process final blocks 7151 var finalProcessedBlocks = this._process(!!'flush'); 7152 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7153 // Process final blocks 7154 var finalProcessedBlocks = this._process(!!'flush'); 7155 7156 // Unpad data 7157 padding.unpad(finalProcessedBlocks); 7158 } 7159 7160 return finalProcessedBlocks; 7161 }, 7162 7163 blockSize: 128/32 7164 }); 7165 7166 /** 7167 * A collection of cipher parameters. 7168 * 7169 * @property {WordArray} ciphertext The raw ciphertext. 7170 * @property {WordArray} key The key to this ciphertext. 7171 * @property {WordArray} iv The IV used in the ciphering operation. 7172 * @property {WordArray} salt The salt used with a key derivation function. 7173 * @property {Cipher} algorithm The cipher algorithm. 7174 * @property {Mode} mode The block mode used in the ciphering operation. 7175 * @property {Padding} padding The padding scheme used in the ciphering operation. 7176 * @property {number} blockSize The block size of the cipher. 7177 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7178 */ 7179 var CipherParams = C_lib.CipherParams = Base.extend({ 7180 /** 7181 * Initializes a newly created cipher params object. 7182 * 7183 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7184 * 7185 * @example 7186 * 7187 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7188 * ciphertext: ciphertextWordArray, 7189 * key: keyWordArray, 7190 * iv: ivWordArray, 7191 * salt: saltWordArray, 7192 * algorithm: CryptoJS.algo.AES, 7193 * mode: CryptoJS.mode.CBC, 7194 * padding: CryptoJS.pad.PKCS7, 7195 * blockSize: 4, 7196 * formatter: CryptoJS.format.OpenSSL 7197 * }); 7198 */ 7199 init: function (cipherParams) { 7200 this.mixIn(cipherParams); 7201 }, 7202 7203 /** 7204 * Converts this cipher params object to a string. 7205 * 7206 * @param {Format} formatter (Optional) The formatting strategy to use. 7207 * 7208 * @return {string} The stringified cipher params. 7209 * 7210 * @throws Error If neither the formatter nor the default formatter is set. 7211 * 7212 * @example 7213 * 7214 * var string = cipherParams + ''; 7215 * var string = cipherParams.toString(); 7216 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7217 */ 7218 toString: function (formatter) { 7219 return (formatter || this.formatter).stringify(this); 7220 } 7221 }); 7222 7223 /** 7224 * Format namespace. 7225 */ 7226 var C_format = C.format = {}; 7227 7228 /** 7229 * OpenSSL formatting strategy. 7230 */ 7231 var OpenSSLFormatter = C_format.OpenSSL = { 7232 /** 7233 * Converts a cipher params object to an OpenSSL-compatible string. 7234 * 7235 * @param {CipherParams} cipherParams The cipher params object. 7236 * 7237 * @return {string} The OpenSSL-compatible string. 7238 * 7239 * @static 7240 * 7241 * @example 7242 * 7243 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7244 */ 7245 stringify: function (cipherParams) { 7246 // Shortcuts 7247 var ciphertext = cipherParams.ciphertext; 7248 var salt = cipherParams.salt; 7249 7250 // Format 7251 if (salt) { 7252 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7253 } else { 7254 var wordArray = ciphertext; 7255 } 7256 7257 return wordArray.toString(Base64); 7258 }, 7259 7260 /** 7261 * Converts an OpenSSL-compatible string to a cipher params object. 7262 * 7263 * @param {string} openSSLStr The OpenSSL-compatible string. 7264 * 7265 * @return {CipherParams} The cipher params object. 7266 * 7267 * @static 7268 * 7269 * @example 7270 * 7271 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7272 */ 7273 parse: function (openSSLStr) { 7274 // Parse base64 7275 var ciphertext = Base64.parse(openSSLStr); 7276 7277 // Shortcut 7278 var ciphertextWords = ciphertext.words; 7279 7280 // Test for salt 7281 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7282 // Extract salt 7283 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7284 7285 // Remove salt from ciphertext 7286 ciphertextWords.splice(0, 4); 7287 ciphertext.sigBytes -= 16; 7288 } 7289 7290 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7291 } 7292 }; 7293 7294 /** 7295 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7296 */ 7297 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7298 /** 7299 * Configuration options. 7300 * 7301 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7302 */ 7303 cfg: Base.extend({ 7304 format: OpenSSLFormatter 7305 }), 7306 7307 /** 7308 * Encrypts a message. 7309 * 7310 * @param {Cipher} cipher The cipher algorithm to use. 7311 * @param {WordArray|string} message The message to encrypt. 7312 * @param {WordArray} key The key. 7313 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7314 * 7315 * @return {CipherParams} A cipher params object. 7316 * 7317 * @static 7318 * 7319 * @example 7320 * 7321 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7322 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7323 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7324 */ 7325 encrypt: function (cipher, message, key, cfg) { 7326 // Apply config defaults 7327 cfg = this.cfg.extend(cfg); 7328 7329 // Encrypt 7330 var encryptor = cipher.createEncryptor(key, cfg); 7331 var ciphertext = encryptor.finalize(message); 7332 7333 // Shortcut 7334 var cipherCfg = encryptor.cfg; 7335 7336 // Create and return serializable cipher params 7337 return CipherParams.create({ 7338 ciphertext: ciphertext, 7339 key: key, 7340 iv: cipherCfg.iv, 7341 algorithm: cipher, 7342 mode: cipherCfg.mode, 7343 padding: cipherCfg.padding, 7344 blockSize: cipher.blockSize, 7345 formatter: cfg.format 7346 }); 7347 }, 7348 7349 /** 7350 * Decrypts serialized ciphertext. 7351 * 7352 * @param {Cipher} cipher The cipher algorithm to use. 7353 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7354 * @param {WordArray} key The key. 7355 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7356 * 7357 * @return {WordArray} The plaintext. 7358 * 7359 * @static 7360 * 7361 * @example 7362 * 7363 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7364 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7365 */ 7366 decrypt: function (cipher, ciphertext, key, cfg) { 7367 // Apply config defaults 7368 cfg = this.cfg.extend(cfg); 7369 7370 // Convert string to CipherParams 7371 ciphertext = this._parse(ciphertext, cfg.format); 7372 7373 // Decrypt 7374 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7375 7376 return plaintext; 7377 }, 7378 7379 /** 7380 * Converts serialized ciphertext to CipherParams, 7381 * else assumed CipherParams already and returns ciphertext unchanged. 7382 * 7383 * @param {CipherParams|string} ciphertext The ciphertext. 7384 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7385 * 7386 * @return {CipherParams} The unserialized ciphertext. 7387 * 7388 * @static 7389 * 7390 * @example 7391 * 7392 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7393 */ 7394 _parse: function (ciphertext, format) { 7395 if (typeof ciphertext == 'string') { 7396 return format.parse(ciphertext, this); 7397 } else { 7398 return ciphertext; 7399 } 7400 } 7401 }); 7402 7403 /** 7404 * Key derivation function namespace. 7405 */ 7406 var C_kdf = C.kdf = {}; 7407 7408 /** 7409 * OpenSSL key derivation function. 7410 */ 7411 var OpenSSLKdf = C_kdf.OpenSSL = { 7412 /** 7413 * Derives a key and IV from a password. 7414 * 7415 * @param {string} password The password to derive from. 7416 * @param {number} keySize The size in words of the key to generate. 7417 * @param {number} ivSize The size in words of the IV to generate. 7418 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7419 * 7420 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7421 * 7422 * @static 7423 * 7424 * @example 7425 * 7426 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7427 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7428 */ 7429 execute: function (password, keySize, ivSize, salt) { 7430 // Generate random salt 7431 if (!salt) { 7432 salt = WordArray.random(64/8); 7433 } 7434 7435 // Derive key and IV 7436 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 7437 7438 // Separate key and IV 7439 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7440 key.sigBytes = keySize * 4; 7441 7442 // Return params 7443 return CipherParams.create({ key: key, iv: iv, salt: salt }); 7444 } 7445 }; 7446 7447 /** 7448 * A serializable cipher wrapper that derives the key from a password, 7449 * and returns ciphertext as a serializable cipher params object. 7450 */ 7451 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7452 /** 7453 * Configuration options. 7454 * 7455 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7456 */ 7457 cfg: SerializableCipher.cfg.extend({ 7458 kdf: OpenSSLKdf 7459 }), 7460 7461 /** 7462 * Encrypts a message using a password. 7463 * 7464 * @param {Cipher} cipher The cipher algorithm to use. 7465 * @param {WordArray|string} message The message to encrypt. 7466 * @param {string} password The password. 7467 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7468 * 7469 * @return {CipherParams} A cipher params object. 7470 * 7471 * @static 7472 * 7473 * @example 7474 * 7475 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7476 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7477 */ 7478 encrypt: function (cipher, message, password, cfg) { 7479 // Apply config defaults 7480 cfg = this.cfg.extend(cfg); 7481 7482 // Derive key and other params 7483 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7484 7485 // Add IV to config 7486 cfg.iv = derivedParams.iv; 7487 7488 // Encrypt 7489 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7490 7491 // Mix in derived params 7492 ciphertext.mixIn(derivedParams); 7493 7494 return ciphertext; 7495 }, 7496 7497 /** 7498 * Decrypts serialized ciphertext using a password. 7499 * 7500 * @param {Cipher} cipher The cipher algorithm to use. 7501 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7502 * @param {string} password The password. 7503 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7504 * 7505 * @return {WordArray} The plaintext. 7506 * 7507 * @static 7508 * 7509 * @example 7510 * 7511 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 7512 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 7513 */ 7514 decrypt: function (cipher, ciphertext, password, cfg) { 7515 // Apply config defaults 7516 cfg = this.cfg.extend(cfg); 7517 7518 // Convert string to CipherParams 7519 ciphertext = this._parse(ciphertext, cfg.format); 7520 7521 // Derive key and other params 7522 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 7523 7524 // Add IV to config 7525 cfg.iv = derivedParams.iv; 7526 7527 // Decrypt 7528 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 7529 7530 return plaintext; 7531 } 7532 }); 7533 }()); 7534 7535 7536 })); 7537 },{"./core":53}],53:[function(require,module,exports){ 7538 ;(function (root, factory) { 7539 if (typeof exports === "object") { 7540 // CommonJS 7541 module.exports = exports = factory(); 7542 } 7543 else if (typeof define === "function" && define.amd) { 7544 // AMD 7545 define([], factory); 7546 } 7547 else { 7548 // Global (browser) 7549 root.CryptoJS = factory(); 7550 } 7551 }(this, function () { 7552 7553 /** 7554 * CryptoJS core components. 7555 */ 7556 var CryptoJS = CryptoJS || (function (Math, undefined) { 7557 /* 7558 * Local polyfil of Object.create 7559 */ 7560 var create = Object.create || (function () { 7561 function F() {}; 7562 7563 return function (obj) { 7564 var subtype; 7565 7566 F.prototype = obj; 7567 7568 subtype = new F(); 7569 7570 F.prototype = null; 7571 7572 return subtype; 7573 }; 7574 }()) 7575 7576 /** 7577 * CryptoJS namespace. 7578 */ 7579 var C = {}; 7580 7581 /** 7582 * Library namespace. 7583 */ 7584 var C_lib = C.lib = {}; 7585 7586 /** 7587 * Base object for prototypal inheritance. 7588 */ 7589 var Base = C_lib.Base = (function () { 7590 7591 7592 return { 7593 /** 7594 * Creates a new object that inherits from this object. 7595 * 7596 * @param {Object} overrides Properties to copy into the new object. 7597 * 7598 * @return {Object} The new object. 7599 * 7600 * @static 7601 * 7602 * @example 7603 * 7604 * var MyType = CryptoJS.lib.Base.extend({ 7605 * field: 'value', 7606 * 7607 * method: function () { 7608 * } 7609 * }); 7610 */ 7611 extend: function (overrides) { 7612 // Spawn 7613 var subtype = create(this); 7614 7615 // Augment 7616 if (overrides) { 7617 subtype.mixIn(overrides); 7618 } 7619 7620 // Create default initializer 7621 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 7622 subtype.init = function () { 7623 subtype.$super.init.apply(this, arguments); 7624 }; 7625 } 7626 7627 // Initializer's prototype is the subtype object 7628 subtype.init.prototype = subtype; 7629 7630 // Reference supertype 7631 subtype.$super = this; 7632 7633 return subtype; 7634 }, 7635 7636 /** 7637 * Extends this object and runs the init method. 7638 * Arguments to create() will be passed to init(). 7639 * 7640 * @return {Object} The new object. 7641 * 7642 * @static 7643 * 7644 * @example 7645 * 7646 * var instance = MyType.create(); 7647 */ 7648 create: function () { 7649 var instance = this.extend(); 7650 instance.init.apply(instance, arguments); 7651 7652 return instance; 7653 }, 7654 7655 /** 7656 * Initializes a newly created object. 7657 * Override this method to add some logic when your objects are created. 7658 * 7659 * @example 7660 * 7661 * var MyType = CryptoJS.lib.Base.extend({ 7662 * init: function () { 7663 * // ... 7664 * } 7665 * }); 7666 */ 7667 init: function () { 7668 }, 7669 7670 /** 7671 * Copies properties into this object. 7672 * 7673 * @param {Object} properties The properties to mix in. 7674 * 7675 * @example 7676 * 7677 * MyType.mixIn({ 7678 * field: 'value' 7679 * }); 7680 */ 7681 mixIn: function (properties) { 7682 for (var propertyName in properties) { 7683 if (properties.hasOwnProperty(propertyName)) { 7684 this[propertyName] = properties[propertyName]; 7685 } 7686 } 7687 7688 // IE won't copy toString using the loop above 7689 if (properties.hasOwnProperty('toString')) { 7690 this.toString = properties.toString; 7691 } 7692 }, 7693 7694 /** 7695 * Creates a copy of this object. 7696 * 7697 * @return {Object} The clone. 7698 * 7699 * @example 7700 * 7701 * var clone = instance.clone(); 7702 */ 7703 clone: function () { 7704 return this.init.prototype.extend(this); 7705 } 7706 }; 7707 }()); 7708 7709 /** 7710 * An array of 32-bit words. 7711 * 7712 * @property {Array} words The array of 32-bit words. 7713 * @property {number} sigBytes The number of significant bytes in this word array. 7714 */ 7715 var WordArray = C_lib.WordArray = Base.extend({ 7716 /** 7717 * Initializes a newly created word array. 7718 * 7719 * @param {Array} words (Optional) An array of 32-bit words. 7720 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 7721 * 7722 * @example 7723 * 7724 * var wordArray = CryptoJS.lib.WordArray.create(); 7725 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 7726 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 7727 */ 7728 init: function (words, sigBytes) { 7729 words = this.words = words || []; 7730 7731 if (sigBytes != undefined) { 7732 this.sigBytes = sigBytes; 7733 } else { 7734 this.sigBytes = words.length * 4; 7735 } 7736 }, 7737 7738 /** 7739 * Converts this word array to a string. 7740 * 7741 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 7742 * 7743 * @return {string} The stringified word array. 7744 * 7745 * @example 7746 * 7747 * var string = wordArray + ''; 7748 * var string = wordArray.toString(); 7749 * var string = wordArray.toString(CryptoJS.enc.Utf8); 7750 */ 7751 toString: function (encoder) { 7752 return (encoder || Hex).stringify(this); 7753 }, 7754 7755 /** 7756 * Concatenates a word array to this word array. 7757 * 7758 * @param {WordArray} wordArray The word array to append. 7759 * 7760 * @return {WordArray} This word array. 7761 * 7762 * @example 7763 * 7764 * wordArray1.concat(wordArray2); 7765 */ 7766 concat: function (wordArray) { 7767 // Shortcuts 7768 var thisWords = this.words; 7769 var thatWords = wordArray.words; 7770 var thisSigBytes = this.sigBytes; 7771 var thatSigBytes = wordArray.sigBytes; 7772 7773 // Clamp excess bits 7774 this.clamp(); 7775 7776 // Concat 7777 if (thisSigBytes % 4) { 7778 // Copy one byte at a time 7779 for (var i = 0; i < thatSigBytes; i++) { 7780 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 7781 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 7782 } 7783 } else { 7784 // Copy one word at a time 7785 for (var i = 0; i < thatSigBytes; i += 4) { 7786 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 7787 } 7788 } 7789 this.sigBytes += thatSigBytes; 7790 7791 // Chainable 7792 return this; 7793 }, 7794 7795 /** 7796 * Removes insignificant bits. 7797 * 7798 * @example 7799 * 7800 * wordArray.clamp(); 7801 */ 7802 clamp: function () { 7803 // Shortcuts 7804 var words = this.words; 7805 var sigBytes = this.sigBytes; 7806 7807 // Clamp 7808 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 7809 words.length = Math.ceil(sigBytes / 4); 7810 }, 7811 7812 /** 7813 * Creates a copy of this word array. 7814 * 7815 * @return {WordArray} The clone. 7816 * 7817 * @example 7818 * 7819 * var clone = wordArray.clone(); 7820 */ 7821 clone: function () { 7822 var clone = Base.clone.call(this); 7823 clone.words = this.words.slice(0); 7824 7825 return clone; 7826 }, 7827 7828 /** 7829 * Creates a word array filled with random bytes. 7830 * 7831 * @param {number} nBytes The number of random bytes to generate. 7832 * 7833 * @return {WordArray} The random word array. 7834 * 7835 * @static 7836 * 7837 * @example 7838 * 7839 * var wordArray = CryptoJS.lib.WordArray.random(16); 7840 */ 7841 random: function (nBytes) { 7842 var words = []; 7843 7844 var r = (function (m_w) { 7845 var m_w = m_w; 7846 var m_z = 0x3ade68b1; 7847 var mask = 0xffffffff; 7848 7849 return function () { 7850 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 7851 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 7852 var result = ((m_z << 0x10) + m_w) & mask; 7853 result /= 0x100000000; 7854 result += 0.5; 7855 return result * (Math.random() > .5 ? 1 : -1); 7856 } 7857 }); 7858 7859 for (var i = 0, rcache; i < nBytes; i += 4) { 7860 var _r = r((rcache || Math.random()) * 0x100000000); 7861 7862 rcache = _r() * 0x3ade67b7; 7863 words.push((_r() * 0x100000000) | 0); 7864 } 7865 7866 return new WordArray.init(words, nBytes); 7867 } 7868 }); 7869 7870 /** 7871 * Encoder namespace. 7872 */ 7873 var C_enc = C.enc = {}; 7874 7875 /** 7876 * Hex encoding strategy. 7877 */ 7878 var Hex = C_enc.Hex = { 7879 /** 7880 * Converts a word array to a hex string. 7881 * 7882 * @param {WordArray} wordArray The word array. 7883 * 7884 * @return {string} The hex string. 7885 * 7886 * @static 7887 * 7888 * @example 7889 * 7890 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 7891 */ 7892 stringify: function (wordArray) { 7893 // Shortcuts 7894 var words = wordArray.words; 7895 var sigBytes = wordArray.sigBytes; 7896 7897 // Convert 7898 var hexChars = []; 7899 for (var i = 0; i < sigBytes; i++) { 7900 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 7901 hexChars.push((bite >>> 4).toString(16)); 7902 hexChars.push((bite & 0x0f).toString(16)); 7903 } 7904 7905 return hexChars.join(''); 7906 }, 7907 7908 /** 7909 * Converts a hex string to a word array. 7910 * 7911 * @param {string} hexStr The hex string. 7912 * 7913 * @return {WordArray} The word array. 7914 * 7915 * @static 7916 * 7917 * @example 7918 * 7919 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 7920 */ 7921 parse: function (hexStr) { 7922 // Shortcut 7923 var hexStrLength = hexStr.length; 7924 7925 // Convert 7926 var words = []; 7927 for (var i = 0; i < hexStrLength; i += 2) { 7928 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 7929 } 7930 7931 return new WordArray.init(words, hexStrLength / 2); 7932 } 7933 }; 7934 7935 /** 7936 * Latin1 encoding strategy. 7937 */ 7938 var Latin1 = C_enc.Latin1 = { 7939 /** 7940 * Converts a word array to a Latin1 string. 7941 * 7942 * @param {WordArray} wordArray The word array. 7943 * 7944 * @return {string} The Latin1 string. 7945 * 7946 * @static 7947 * 7948 * @example 7949 * 7950 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 7951 */ 7952 stringify: function (wordArray) { 7953 // Shortcuts 7954 var words = wordArray.words; 7955 var sigBytes = wordArray.sigBytes; 7956 7957 // Convert 7958 var latin1Chars = []; 7959 for (var i = 0; i < sigBytes; i++) { 7960 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 7961 latin1Chars.push(String.fromCharCode(bite)); 7962 } 7963 7964 return latin1Chars.join(''); 7965 }, 7966 7967 /** 7968 * Converts a Latin1 string to a word array. 7969 * 7970 * @param {string} latin1Str The Latin1 string. 7971 * 7972 * @return {WordArray} The word array. 7973 * 7974 * @static 7975 * 7976 * @example 7977 * 7978 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 7979 */ 7980 parse: function (latin1Str) { 7981 // Shortcut 7982 var latin1StrLength = latin1Str.length; 7983 7984 // Convert 7985 var words = []; 7986 for (var i = 0; i < latin1StrLength; i++) { 7987 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 7988 } 7989 7990 return new WordArray.init(words, latin1StrLength); 7991 } 7992 }; 7993 7994 /** 7995 * UTF-8 encoding strategy. 7996 */ 7997 var Utf8 = C_enc.Utf8 = { 7998 /** 7999 * Converts a word array to a UTF-8 string. 8000 * 8001 * @param {WordArray} wordArray The word array. 8002 * 8003 * @return {string} The UTF-8 string. 8004 * 8005 * @static 8006 * 8007 * @example 8008 * 8009 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8010 */ 8011 stringify: function (wordArray) { 8012 try { 8013 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8014 } catch (e) { 8015 throw new Error('Malformed UTF-8 data'); 8016 } 8017 }, 8018 8019 /** 8020 * Converts a UTF-8 string to a word array. 8021 * 8022 * @param {string} utf8Str The UTF-8 string. 8023 * 8024 * @return {WordArray} The word array. 8025 * 8026 * @static 8027 * 8028 * @example 8029 * 8030 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8031 */ 8032 parse: function (utf8Str) { 8033 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8034 } 8035 }; 8036 8037 /** 8038 * Abstract buffered block algorithm template. 8039 * 8040 * The property blockSize must be implemented in a concrete subtype. 8041 * 8042 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8043 */ 8044 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8045 /** 8046 * Resets this block algorithm's data buffer to its initial state. 8047 * 8048 * @example 8049 * 8050 * bufferedBlockAlgorithm.reset(); 8051 */ 8052 reset: function () { 8053 // Initial values 8054 this._data = new WordArray.init(); 8055 this._nDataBytes = 0; 8056 }, 8057 8058 /** 8059 * Adds new data to this block algorithm's buffer. 8060 * 8061 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8062 * 8063 * @example 8064 * 8065 * bufferedBlockAlgorithm._append('data'); 8066 * bufferedBlockAlgorithm._append(wordArray); 8067 */ 8068 _append: function (data) { 8069 // Convert string to WordArray, else assume WordArray already 8070 if (typeof data == 'string') { 8071 data = Utf8.parse(data); 8072 } 8073 8074 // Append 8075 this._data.concat(data); 8076 this._nDataBytes += data.sigBytes; 8077 }, 8078 8079 /** 8080 * Processes available data blocks. 8081 * 8082 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8083 * 8084 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8085 * 8086 * @return {WordArray} The processed data. 8087 * 8088 * @example 8089 * 8090 * var processedData = bufferedBlockAlgorithm._process(); 8091 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8092 */ 8093 _process: function (doFlush) { 8094 // Shortcuts 8095 var data = this._data; 8096 var dataWords = data.words; 8097 var dataSigBytes = data.sigBytes; 8098 var blockSize = this.blockSize; 8099 var blockSizeBytes = blockSize * 4; 8100 8101 // Count blocks ready 8102 var nBlocksReady = dataSigBytes / blockSizeBytes; 8103 if (doFlush) { 8104 // Round up to include partial blocks 8105 nBlocksReady = Math.ceil(nBlocksReady); 8106 } else { 8107 // Round down to include only full blocks, 8108 // less the number of blocks that must remain in the buffer 8109 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8110 } 8111 8112 // Count words ready 8113 var nWordsReady = nBlocksReady * blockSize; 8114 8115 // Count bytes ready 8116 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8117 8118 // Process blocks 8119 if (nWordsReady) { 8120 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8121 // Perform concrete-algorithm logic 8122 this._doProcessBlock(dataWords, offset); 8123 } 8124 8125 // Remove processed words 8126 var processedWords = dataWords.splice(0, nWordsReady); 8127 data.sigBytes -= nBytesReady; 8128 } 8129 8130 // Return processed words 8131 return new WordArray.init(processedWords, nBytesReady); 8132 }, 8133 8134 /** 8135 * Creates a copy of this object. 8136 * 8137 * @return {Object} The clone. 8138 * 8139 * @example 8140 * 8141 * var clone = bufferedBlockAlgorithm.clone(); 8142 */ 8143 clone: function () { 8144 var clone = Base.clone.call(this); 8145 clone._data = this._data.clone(); 8146 8147 return clone; 8148 }, 8149 8150 _minBufferSize: 0 8151 }); 8152 8153 /** 8154 * Abstract hasher template. 8155 * 8156 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8157 */ 8158 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8159 /** 8160 * Configuration options. 8161 */ 8162 cfg: Base.extend(), 8163 8164 /** 8165 * Initializes a newly created hasher. 8166 * 8167 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8168 * 8169 * @example 8170 * 8171 * var hasher = CryptoJS.algo.SHA256.create(); 8172 */ 8173 init: function (cfg) { 8174 // Apply config defaults 8175 this.cfg = this.cfg.extend(cfg); 8176 8177 // Set initial values 8178 this.reset(); 8179 }, 8180 8181 /** 8182 * Resets this hasher to its initial state. 8183 * 8184 * @example 8185 * 8186 * hasher.reset(); 8187 */ 8188 reset: function () { 8189 // Reset data buffer 8190 BufferedBlockAlgorithm.reset.call(this); 8191 8192 // Perform concrete-hasher logic 8193 this._doReset(); 8194 }, 8195 8196 /** 8197 * Updates this hasher with a message. 8198 * 8199 * @param {WordArray|string} messageUpdate The message to append. 8200 * 8201 * @return {Hasher} This hasher. 8202 * 8203 * @example 8204 * 8205 * hasher.update('message'); 8206 * hasher.update(wordArray); 8207 */ 8208 update: function (messageUpdate) { 8209 // Append 8210 this._append(messageUpdate); 8211 8212 // Update the hash 8213 this._process(); 8214 8215 // Chainable 8216 return this; 8217 }, 8218 8219 /** 8220 * Finalizes the hash computation. 8221 * Note that the finalize operation is effectively a destructive, read-once operation. 8222 * 8223 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8224 * 8225 * @return {WordArray} The hash. 8226 * 8227 * @example 8228 * 8229 * var hash = hasher.finalize(); 8230 * var hash = hasher.finalize('message'); 8231 * var hash = hasher.finalize(wordArray); 8232 */ 8233 finalize: function (messageUpdate) { 8234 // Final message update 8235 if (messageUpdate) { 8236 this._append(messageUpdate); 8237 } 8238 8239 // Perform concrete-hasher logic 8240 var hash = this._doFinalize(); 8241 8242 return hash; 8243 }, 8244 8245 blockSize: 512/32, 8246 8247 /** 8248 * Creates a shortcut function to a hasher's object interface. 8249 * 8250 * @param {Hasher} hasher The hasher to create a helper for. 8251 * 8252 * @return {Function} The shortcut function. 8253 * 8254 * @static 8255 * 8256 * @example 8257 * 8258 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8259 */ 8260 _createHelper: function (hasher) { 8261 return function (message, cfg) { 8262 return new hasher.init(cfg).finalize(message); 8263 }; 8264 }, 8265 8266 /** 8267 * Creates a shortcut function to the HMAC's object interface. 8268 * 8269 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8270 * 8271 * @return {Function} The shortcut function. 8272 * 8273 * @static 8274 * 8275 * @example 8276 * 8277 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8278 */ 8279 _createHmacHelper: function (hasher) { 8280 return function (message, key) { 8281 return new C_algo.HMAC.init(hasher, key).finalize(message); 8282 }; 8283 } 8284 }); 8285 8286 /** 8287 * Algorithm namespace. 8288 */ 8289 var C_algo = C.algo = {}; 8290 8291 return C; 8292 }(Math)); 8293 8294 8295 return CryptoJS; 8296 8297 })); 8298 },{}],54:[function(require,module,exports){ 8299 ;(function (root, factory) { 8300 if (typeof exports === "object") { 8301 // CommonJS 8302 module.exports = exports = factory(require("./core")); 8303 } 8304 else if (typeof define === "function" && define.amd) { 8305 // AMD 8306 define(["./core"], factory); 8307 } 8308 else { 8309 // Global (browser) 8310 factory(root.CryptoJS); 8311 } 8312 }(this, function (CryptoJS) { 8313 8314 (function () { 8315 // Shortcuts 8316 var C = CryptoJS; 8317 var C_lib = C.lib; 8318 var WordArray = C_lib.WordArray; 8319 var C_enc = C.enc; 8320 8321 /** 8322 * Base64 encoding strategy. 8323 */ 8324 var Base64 = C_enc.Base64 = { 8325 /** 8326 * Converts a word array to a Base64 string. 8327 * 8328 * @param {WordArray} wordArray The word array. 8329 * 8330 * @return {string} The Base64 string. 8331 * 8332 * @static 8333 * 8334 * @example 8335 * 8336 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8337 */ 8338 stringify: function (wordArray) { 8339 // Shortcuts 8340 var words = wordArray.words; 8341 var sigBytes = wordArray.sigBytes; 8342 var map = this._map; 8343 8344 // Clamp excess bits 8345 wordArray.clamp(); 8346 8347 // Convert 8348 var base64Chars = []; 8349 for (var i = 0; i < sigBytes; i += 3) { 8350 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8351 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8352 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8353 8354 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8355 8356 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8357 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8358 } 8359 } 8360 8361 // Add padding 8362 var paddingChar = map.charAt(64); 8363 if (paddingChar) { 8364 while (base64Chars.length % 4) { 8365 base64Chars.push(paddingChar); 8366 } 8367 } 8368 8369 return base64Chars.join(''); 8370 }, 8371 8372 /** 8373 * Converts a Base64 string to a word array. 8374 * 8375 * @param {string} base64Str The Base64 string. 8376 * 8377 * @return {WordArray} The word array. 8378 * 8379 * @static 8380 * 8381 * @example 8382 * 8383 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8384 */ 8385 parse: function (base64Str) { 8386 // Shortcuts 8387 var base64StrLength = base64Str.length; 8388 var map = this._map; 8389 var reverseMap = this._reverseMap; 8390 8391 if (!reverseMap) { 8392 reverseMap = this._reverseMap = []; 8393 for (var j = 0; j < map.length; j++) { 8394 reverseMap[map.charCodeAt(j)] = j; 8395 } 8396 } 8397 8398 // Ignore padding 8399 var paddingChar = map.charAt(64); 8400 if (paddingChar) { 8401 var paddingIndex = base64Str.indexOf(paddingChar); 8402 if (paddingIndex !== -1) { 8403 base64StrLength = paddingIndex; 8404 } 8405 } 8406 8407 // Convert 8408 return parseLoop(base64Str, base64StrLength, reverseMap); 8409 8410 }, 8411 8412 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8413 }; 8414 8415 function parseLoop(base64Str, base64StrLength, reverseMap) { 8416 var words = []; 8417 var nBytes = 0; 8418 for (var i = 0; i < base64StrLength; i++) { 8419 if (i % 4) { 8420 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8421 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8422 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8423 nBytes++; 8424 } 8425 } 8426 return WordArray.create(words, nBytes); 8427 } 8428 }()); 8429 8430 8431 return CryptoJS.enc.Base64; 8432 8433 })); 8434 },{"./core":53}],55:[function(require,module,exports){ 8435 ;(function (root, factory) { 8436 if (typeof exports === "object") { 8437 // CommonJS 8438 module.exports = exports = factory(require("./core")); 8439 } 8440 else if (typeof define === "function" && define.amd) { 8441 // AMD 8442 define(["./core"], factory); 8443 } 8444 else { 8445 // Global (browser) 8446 factory(root.CryptoJS); 8447 } 8448 }(this, function (CryptoJS) { 8449 8450 (function () { 8451 // Shortcuts 8452 var C = CryptoJS; 8453 var C_lib = C.lib; 8454 var WordArray = C_lib.WordArray; 8455 var C_enc = C.enc; 8456 8457 /** 8458 * UTF-16 BE encoding strategy. 8459 */ 8460 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8461 /** 8462 * Converts a word array to a UTF-16 BE string. 8463 * 8464 * @param {WordArray} wordArray The word array. 8465 * 8466 * @return {string} The UTF-16 BE string. 8467 * 8468 * @static 8469 * 8470 * @example 8471 * 8472 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8473 */ 8474 stringify: function (wordArray) { 8475 // Shortcuts 8476 var words = wordArray.words; 8477 var sigBytes = wordArray.sigBytes; 8478 8479 // Convert 8480 var utf16Chars = []; 8481 for (var i = 0; i < sigBytes; i += 2) { 8482 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8483 utf16Chars.push(String.fromCharCode(codePoint)); 8484 } 8485 8486 return utf16Chars.join(''); 8487 }, 8488 8489 /** 8490 * Converts a UTF-16 BE string to a word array. 8491 * 8492 * @param {string} utf16Str The UTF-16 BE string. 8493 * 8494 * @return {WordArray} The word array. 8495 * 8496 * @static 8497 * 8498 * @example 8499 * 8500 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8501 */ 8502 parse: function (utf16Str) { 8503 // Shortcut 8504 var utf16StrLength = utf16Str.length; 8505 8506 // Convert 8507 var words = []; 8508 for (var i = 0; i < utf16StrLength; i++) { 8509 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 8510 } 8511 8512 return WordArray.create(words, utf16StrLength * 2); 8513 } 8514 }; 8515 8516 /** 8517 * UTF-16 LE encoding strategy. 8518 */ 8519 C_enc.Utf16LE = { 8520 /** 8521 * Converts a word array to a UTF-16 LE string. 8522 * 8523 * @param {WordArray} wordArray The word array. 8524 * 8525 * @return {string} The UTF-16 LE string. 8526 * 8527 * @static 8528 * 8529 * @example 8530 * 8531 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 8532 */ 8533 stringify: function (wordArray) { 8534 // Shortcuts 8535 var words = wordArray.words; 8536 var sigBytes = wordArray.sigBytes; 8537 8538 // Convert 8539 var utf16Chars = []; 8540 for (var i = 0; i < sigBytes; i += 2) { 8541 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 8542 utf16Chars.push(String.fromCharCode(codePoint)); 8543 } 8544 8545 return utf16Chars.join(''); 8546 }, 8547 8548 /** 8549 * Converts a UTF-16 LE string to a word array. 8550 * 8551 * @param {string} utf16Str The UTF-16 LE string. 8552 * 8553 * @return {WordArray} The word array. 8554 * 8555 * @static 8556 * 8557 * @example 8558 * 8559 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 8560 */ 8561 parse: function (utf16Str) { 8562 // Shortcut 8563 var utf16StrLength = utf16Str.length; 8564 8565 // Convert 8566 var words = []; 8567 for (var i = 0; i < utf16StrLength; i++) { 8568 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 8569 } 8570 8571 return WordArray.create(words, utf16StrLength * 2); 8572 } 8573 }; 8574 8575 function swapEndian(word) { 8576 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 8577 } 8578 }()); 8579 8580 8581 return CryptoJS.enc.Utf16; 8582 8583 })); 8584 },{"./core":53}],56:[function(require,module,exports){ 8585 ;(function (root, factory, undef) { 8586 if (typeof exports === "object") { 8587 // CommonJS 8588 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 8589 } 8590 else if (typeof define === "function" && define.amd) { 8591 // AMD 8592 define(["./core", "./sha1", "./hmac"], factory); 8593 } 8594 else { 8595 // Global (browser) 8596 factory(root.CryptoJS); 8597 } 8598 }(this, function (CryptoJS) { 8599 8600 (function () { 8601 // Shortcuts 8602 var C = CryptoJS; 8603 var C_lib = C.lib; 8604 var Base = C_lib.Base; 8605 var WordArray = C_lib.WordArray; 8606 var C_algo = C.algo; 8607 var MD5 = C_algo.MD5; 8608 8609 /** 8610 * This key derivation function is meant to conform with EVP_BytesToKey. 8611 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 8612 */ 8613 var EvpKDF = C_algo.EvpKDF = Base.extend({ 8614 /** 8615 * Configuration options. 8616 * 8617 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 8618 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 8619 * @property {number} iterations The number of iterations to perform. Default: 1 8620 */ 8621 cfg: Base.extend({ 8622 keySize: 128/32, 8623 hasher: MD5, 8624 iterations: 1 8625 }), 8626 8627 /** 8628 * Initializes a newly created key derivation function. 8629 * 8630 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 8631 * 8632 * @example 8633 * 8634 * var kdf = CryptoJS.algo.EvpKDF.create(); 8635 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 8636 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 8637 */ 8638 init: function (cfg) { 8639 this.cfg = this.cfg.extend(cfg); 8640 }, 8641 8642 /** 8643 * Derives a key from a password. 8644 * 8645 * @param {WordArray|string} password The password. 8646 * @param {WordArray|string} salt A salt. 8647 * 8648 * @return {WordArray} The derived key. 8649 * 8650 * @example 8651 * 8652 * var key = kdf.compute(password, salt); 8653 */ 8654 compute: function (password, salt) { 8655 // Shortcut 8656 var cfg = this.cfg; 8657 8658 // Init hasher 8659 var hasher = cfg.hasher.create(); 8660 8661 // Initial values 8662 var derivedKey = WordArray.create(); 8663 8664 // Shortcuts 8665 var derivedKeyWords = derivedKey.words; 8666 var keySize = cfg.keySize; 8667 var iterations = cfg.iterations; 8668 8669 // Generate key 8670 while (derivedKeyWords.length < keySize) { 8671 if (block) { 8672 hasher.update(block); 8673 } 8674 var block = hasher.update(password).finalize(salt); 8675 hasher.reset(); 8676 8677 // Iterations 8678 for (var i = 1; i < iterations; i++) { 8679 block = hasher.finalize(block); 8680 hasher.reset(); 8681 } 8682 8683 derivedKey.concat(block); 8684 } 8685 derivedKey.sigBytes = keySize * 4; 8686 8687 return derivedKey; 8688 } 8689 }); 8690 8691 /** 8692 * Derives a key from a password. 8693 * 8694 * @param {WordArray|string} password The password. 8695 * @param {WordArray|string} salt A salt. 8696 * @param {Object} cfg (Optional) The configuration options to use for this computation. 8697 * 8698 * @return {WordArray} The derived key. 8699 * 8700 * @static 8701 * 8702 * @example 8703 * 8704 * var key = CryptoJS.EvpKDF(password, salt); 8705 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 8706 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 8707 */ 8708 C.EvpKDF = function (password, salt, cfg) { 8709 return EvpKDF.create(cfg).compute(password, salt); 8710 }; 8711 }()); 8712 8713 8714 return CryptoJS.EvpKDF; 8715 8716 })); 8717 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 8718 ;(function (root, factory, undef) { 8719 if (typeof exports === "object") { 8720 // CommonJS 8721 module.exports = exports = factory(require("./core"), require("./cipher-core")); 8722 } 8723 else if (typeof define === "function" && define.amd) { 8724 // AMD 8725 define(["./core", "./cipher-core"], factory); 8726 } 8727 else { 8728 // Global (browser) 8729 factory(root.CryptoJS); 8730 } 8731 }(this, function (CryptoJS) { 8732 8733 (function (undefined) { 8734 // Shortcuts 8735 var C = CryptoJS; 8736 var C_lib = C.lib; 8737 var CipherParams = C_lib.CipherParams; 8738 var C_enc = C.enc; 8739 var Hex = C_enc.Hex; 8740 var C_format = C.format; 8741 8742 var HexFormatter = C_format.Hex = { 8743 /** 8744 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 8745 * 8746 * @param {CipherParams} cipherParams The cipher params object. 8747 * 8748 * @return {string} The hexadecimally encoded string. 8749 * 8750 * @static 8751 * 8752 * @example 8753 * 8754 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 8755 */ 8756 stringify: function (cipherParams) { 8757 return cipherParams.ciphertext.toString(Hex); 8758 }, 8759 8760 /** 8761 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 8762 * 8763 * @param {string} input The hexadecimally encoded string. 8764 * 8765 * @return {CipherParams} The cipher params object. 8766 * 8767 * @static 8768 * 8769 * @example 8770 * 8771 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 8772 */ 8773 parse: function (input) { 8774 var ciphertext = Hex.parse(input); 8775 return CipherParams.create({ ciphertext: ciphertext }); 8776 } 8777 }; 8778 }()); 8779 8780 8781 return CryptoJS.format.Hex; 8782 8783 })); 8784 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 8785 ;(function (root, factory) { 8786 if (typeof exports === "object") { 8787 // CommonJS 8788 module.exports = exports = factory(require("./core")); 8789 } 8790 else if (typeof define === "function" && define.amd) { 8791 // AMD 8792 define(["./core"], factory); 8793 } 8794 else { 8795 // Global (browser) 8796 factory(root.CryptoJS); 8797 } 8798 }(this, function (CryptoJS) { 8799 8800 (function () { 8801 // Shortcuts 8802 var C = CryptoJS; 8803 var C_lib = C.lib; 8804 var Base = C_lib.Base; 8805 var C_enc = C.enc; 8806 var Utf8 = C_enc.Utf8; 8807 var C_algo = C.algo; 8808 8809 /** 8810 * HMAC algorithm. 8811 */ 8812 var HMAC = C_algo.HMAC = Base.extend({ 8813 /** 8814 * Initializes a newly created HMAC. 8815 * 8816 * @param {Hasher} hasher The hash algorithm to use. 8817 * @param {WordArray|string} key The secret key. 8818 * 8819 * @example 8820 * 8821 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 8822 */ 8823 init: function (hasher, key) { 8824 // Init hasher 8825 hasher = this._hasher = new hasher.init(); 8826 8827 // Convert string to WordArray, else assume WordArray already 8828 if (typeof key == 'string') { 8829 key = Utf8.parse(key); 8830 } 8831 8832 // Shortcuts 8833 var hasherBlockSize = hasher.blockSize; 8834 var hasherBlockSizeBytes = hasherBlockSize * 4; 8835 8836 // Allow arbitrary length keys 8837 if (key.sigBytes > hasherBlockSizeBytes) { 8838 key = hasher.finalize(key); 8839 } 8840 8841 // Clamp excess bits 8842 key.clamp(); 8843 8844 // Clone key for inner and outer pads 8845 var oKey = this._oKey = key.clone(); 8846 var iKey = this._iKey = key.clone(); 8847 8848 // Shortcuts 8849 var oKeyWords = oKey.words; 8850 var iKeyWords = iKey.words; 8851 8852 // XOR keys with pad constants 8853 for (var i = 0; i < hasherBlockSize; i++) { 8854 oKeyWords[i] ^= 0x5c5c5c5c; 8855 iKeyWords[i] ^= 0x36363636; 8856 } 8857 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 8858 8859 // Set initial values 8860 this.reset(); 8861 }, 8862 8863 /** 8864 * Resets this HMAC to its initial state. 8865 * 8866 * @example 8867 * 8868 * hmacHasher.reset(); 8869 */ 8870 reset: function () { 8871 // Shortcut 8872 var hasher = this._hasher; 8873 8874 // Reset 8875 hasher.reset(); 8876 hasher.update(this._iKey); 8877 }, 8878 8879 /** 8880 * Updates this HMAC with a message. 8881 * 8882 * @param {WordArray|string} messageUpdate The message to append. 8883 * 8884 * @return {HMAC} This HMAC instance. 8885 * 8886 * @example 8887 * 8888 * hmacHasher.update('message'); 8889 * hmacHasher.update(wordArray); 8890 */ 8891 update: function (messageUpdate) { 8892 this._hasher.update(messageUpdate); 8893 8894 // Chainable 8895 return this; 8896 }, 8897 8898 /** 8899 * Finalizes the HMAC computation. 8900 * Note that the finalize operation is effectively a destructive, read-once operation. 8901 * 8902 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8903 * 8904 * @return {WordArray} The HMAC. 8905 * 8906 * @example 8907 * 8908 * var hmac = hmacHasher.finalize(); 8909 * var hmac = hmacHasher.finalize('message'); 8910 * var hmac = hmacHasher.finalize(wordArray); 8911 */ 8912 finalize: function (messageUpdate) { 8913 // Shortcut 8914 var hasher = this._hasher; 8915 8916 // Compute HMAC 8917 var innerHash = hasher.finalize(messageUpdate); 8918 hasher.reset(); 8919 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 8920 8921 return hmac; 8922 } 8923 }); 8924 }()); 8925 8926 8927 })); 8928 },{"./core":53}],59:[function(require,module,exports){ 8929 ;(function (root, factory, undef) { 8930 if (typeof exports === "object") { 8931 // CommonJS 8932 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./lib-typedarrays"), require("./enc-utf16"), require("./enc-base64"), require("./md5"), require("./sha1"), require("./sha256"), require("./sha224"), require("./sha512"), require("./sha384"), require("./sha3"), require("./ripemd160"), require("./hmac"), require("./pbkdf2"), require("./evpkdf"), require("./cipher-core"), require("./mode-cfb"), require("./mode-ctr"), require("./mode-ctr-gladman"), require("./mode-ofb"), require("./mode-ecb"), require("./pad-ansix923"), require("./pad-iso10126"), require("./pad-iso97971"), require("./pad-zeropadding"), require("./pad-nopadding"), require("./format-hex"), require("./aes"), require("./tripledes"), require("./rc4"), require("./rabbit"), require("./rabbit-legacy")); 8933 } 8934 else if (typeof define === "function" && define.amd) { 8935 // AMD 8936 define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy"], factory); 8937 } 8938 else { 8939 // Global (browser) 8940 root.CryptoJS = factory(root.CryptoJS); 8941 } 8942 }(this, function (CryptoJS) { 8943 8944 return CryptoJS; 8945 8946 })); 8947 },{"./aes":51,"./cipher-core":52,"./core":53,"./enc-base64":54,"./enc-utf16":55,"./evpkdf":56,"./format-hex":57,"./hmac":58,"./lib-typedarrays":60,"./md5":61,"./mode-cfb":62,"./mode-ctr":64,"./mode-ctr-gladman":63,"./mode-ecb":65,"./mode-ofb":66,"./pad-ansix923":67,"./pad-iso10126":68,"./pad-iso97971":69,"./pad-nopadding":70,"./pad-zeropadding":71,"./pbkdf2":72,"./rabbit":74,"./rabbit-legacy":73,"./rc4":75,"./ripemd160":76,"./sha1":77,"./sha224":78,"./sha256":79,"./sha3":80,"./sha384":81,"./sha512":82,"./tripledes":83,"./x64-core":84}],60:[function(require,module,exports){ 8948 ;(function (root, factory) { 8949 if (typeof exports === "object") { 8950 // CommonJS 8951 module.exports = exports = factory(require("./core")); 8952 } 8953 else if (typeof define === "function" && define.amd) { 8954 // AMD 8955 define(["./core"], factory); 8956 } 8957 else { 8958 // Global (browser) 8959 factory(root.CryptoJS); 8960 } 8961 }(this, function (CryptoJS) { 8962 8963 (function () { 8964 // Check if typed arrays are supported 8965 if (typeof ArrayBuffer != 'function') { 8966 return; 8967 } 8968 8969 // Shortcuts 8970 var C = CryptoJS; 8971 var C_lib = C.lib; 8972 var WordArray = C_lib.WordArray; 8973 8974 // Reference original init 8975 var superInit = WordArray.init; 8976 8977 // Augment WordArray.init to handle typed arrays 8978 var subInit = WordArray.init = function (typedArray) { 8979 // Convert buffers to uint8 8980 if (typedArray instanceof ArrayBuffer) { 8981 typedArray = new Uint8Array(typedArray); 8982 } 8983 8984 // Convert other array views to uint8 8985 if ( 8986 typedArray instanceof Int8Array || 8987 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 8988 typedArray instanceof Int16Array || 8989 typedArray instanceof Uint16Array || 8990 typedArray instanceof Int32Array || 8991 typedArray instanceof Uint32Array || 8992 typedArray instanceof Float32Array || 8993 typedArray instanceof Float64Array 8994 ) { 8995 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 8996 } 8997 8998 // Handle Uint8Array 8999 if (typedArray instanceof Uint8Array) { 9000 // Shortcut 9001 var typedArrayByteLength = typedArray.byteLength; 9002 9003 // Extract bytes 9004 var words = []; 9005 for (var i = 0; i < typedArrayByteLength; i++) { 9006 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9007 } 9008 9009 // Initialize this word array 9010 superInit.call(this, words, typedArrayByteLength); 9011 } else { 9012 // Else call normal init 9013 superInit.apply(this, arguments); 9014 } 9015 }; 9016 9017 subInit.prototype = WordArray; 9018 }()); 9019 9020 9021 return CryptoJS.lib.WordArray; 9022 9023 })); 9024 },{"./core":53}],61:[function(require,module,exports){ 9025 ;(function (root, factory) { 9026 if (typeof exports === "object") { 9027 // CommonJS 9028 module.exports = exports = factory(require("./core")); 9029 } 9030 else if (typeof define === "function" && define.amd) { 9031 // AMD 9032 define(["./core"], factory); 9033 } 9034 else { 9035 // Global (browser) 9036 factory(root.CryptoJS); 9037 } 9038 }(this, function (CryptoJS) { 9039 9040 (function (Math) { 9041 // Shortcuts 9042 var C = CryptoJS; 9043 var C_lib = C.lib; 9044 var WordArray = C_lib.WordArray; 9045 var Hasher = C_lib.Hasher; 9046 var C_algo = C.algo; 9047 9048 // Constants table 9049 var T = []; 9050 9051 // Compute constants 9052 (function () { 9053 for (var i = 0; i < 64; i++) { 9054 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9055 } 9056 }()); 9057 9058 /** 9059 * MD5 hash algorithm. 9060 */ 9061 var MD5 = C_algo.MD5 = Hasher.extend({ 9062 _doReset: function () { 9063 this._hash = new WordArray.init([ 9064 0x67452301, 0xefcdab89, 9065 0x98badcfe, 0x10325476 9066 ]); 9067 }, 9068 9069 _doProcessBlock: function (M, offset) { 9070 // Swap endian 9071 for (var i = 0; i < 16; i++) { 9072 // Shortcuts 9073 var offset_i = offset + i; 9074 var M_offset_i = M[offset_i]; 9075 9076 M[offset_i] = ( 9077 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9078 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9079 ); 9080 } 9081 9082 // Shortcuts 9083 var H = this._hash.words; 9084 9085 var M_offset_0 = M[offset + 0]; 9086 var M_offset_1 = M[offset + 1]; 9087 var M_offset_2 = M[offset + 2]; 9088 var M_offset_3 = M[offset + 3]; 9089 var M_offset_4 = M[offset + 4]; 9090 var M_offset_5 = M[offset + 5]; 9091 var M_offset_6 = M[offset + 6]; 9092 var M_offset_7 = M[offset + 7]; 9093 var M_offset_8 = M[offset + 8]; 9094 var M_offset_9 = M[offset + 9]; 9095 var M_offset_10 = M[offset + 10]; 9096 var M_offset_11 = M[offset + 11]; 9097 var M_offset_12 = M[offset + 12]; 9098 var M_offset_13 = M[offset + 13]; 9099 var M_offset_14 = M[offset + 14]; 9100 var M_offset_15 = M[offset + 15]; 9101 9102 // Working variables 9103 var a = H[0]; 9104 var b = H[1]; 9105 var c = H[2]; 9106 var d = H[3]; 9107 9108 // Computation 9109 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9110 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9111 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9112 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9113 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9114 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9115 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9116 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9117 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9118 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9119 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9120 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9121 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9122 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9123 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9124 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9125 9126 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9127 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9128 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9129 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9130 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9131 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9132 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9133 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9134 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9135 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9136 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9137 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9138 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9139 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9140 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9141 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9142 9143 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9144 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9145 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9146 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9147 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9148 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9149 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9150 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9151 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9152 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9153 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9154 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9155 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9156 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9157 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9158 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9159 9160 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9161 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9162 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9163 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9164 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9165 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9166 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9167 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9168 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9169 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9170 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9171 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9172 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9173 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9174 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9175 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9176 9177 // Intermediate hash value 9178 H[0] = (H[0] + a) | 0; 9179 H[1] = (H[1] + b) | 0; 9180 H[2] = (H[2] + c) | 0; 9181 H[3] = (H[3] + d) | 0; 9182 }, 9183 9184 _doFinalize: function () { 9185 // Shortcuts 9186 var data = this._data; 9187 var dataWords = data.words; 9188 9189 var nBitsTotal = this._nDataBytes * 8; 9190 var nBitsLeft = data.sigBytes * 8; 9191 9192 // Add padding 9193 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9194 9195 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9196 var nBitsTotalL = nBitsTotal; 9197 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9198 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9199 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9200 ); 9201 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9202 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9203 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9204 ); 9205 9206 data.sigBytes = (dataWords.length + 1) * 4; 9207 9208 // Hash final blocks 9209 this._process(); 9210 9211 // Shortcuts 9212 var hash = this._hash; 9213 var H = hash.words; 9214 9215 // Swap endian 9216 for (var i = 0; i < 4; i++) { 9217 // Shortcut 9218 var H_i = H[i]; 9219 9220 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9221 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9222 } 9223 9224 // Return final computed hash 9225 return hash; 9226 }, 9227 9228 clone: function () { 9229 var clone = Hasher.clone.call(this); 9230 clone._hash = this._hash.clone(); 9231 9232 return clone; 9233 } 9234 }); 9235 9236 function FF(a, b, c, d, x, s, t) { 9237 var n = a + ((b & c) | (~b & d)) + x + t; 9238 return ((n << s) | (n >>> (32 - s))) + b; 9239 } 9240 9241 function GG(a, b, c, d, x, s, t) { 9242 var n = a + ((b & d) | (c & ~d)) + x + t; 9243 return ((n << s) | (n >>> (32 - s))) + b; 9244 } 9245 9246 function HH(a, b, c, d, x, s, t) { 9247 var n = a + (b ^ c ^ d) + x + t; 9248 return ((n << s) | (n >>> (32 - s))) + b; 9249 } 9250 9251 function II(a, b, c, d, x, s, t) { 9252 var n = a + (c ^ (b | ~d)) + x + t; 9253 return ((n << s) | (n >>> (32 - s))) + b; 9254 } 9255 9256 /** 9257 * Shortcut function to the hasher's object interface. 9258 * 9259 * @param {WordArray|string} message The message to hash. 9260 * 9261 * @return {WordArray} The hash. 9262 * 9263 * @static 9264 * 9265 * @example 9266 * 9267 * var hash = CryptoJS.MD5('message'); 9268 * var hash = CryptoJS.MD5(wordArray); 9269 */ 9270 C.MD5 = Hasher._createHelper(MD5); 9271 9272 /** 9273 * Shortcut function to the HMAC's object interface. 9274 * 9275 * @param {WordArray|string} message The message to hash. 9276 * @param {WordArray|string} key The secret key. 9277 * 9278 * @return {WordArray} The HMAC. 9279 * 9280 * @static 9281 * 9282 * @example 9283 * 9284 * var hmac = CryptoJS.HmacMD5(message, key); 9285 */ 9286 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9287 }(Math)); 9288 9289 9290 return CryptoJS.MD5; 9291 9292 })); 9293 },{"./core":53}],62:[function(require,module,exports){ 9294 ;(function (root, factory, undef) { 9295 if (typeof exports === "object") { 9296 // CommonJS 9297 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9298 } 9299 else if (typeof define === "function" && define.amd) { 9300 // AMD 9301 define(["./core", "./cipher-core"], factory); 9302 } 9303 else { 9304 // Global (browser) 9305 factory(root.CryptoJS); 9306 } 9307 }(this, function (CryptoJS) { 9308 9309 /** 9310 * Cipher Feedback block mode. 9311 */ 9312 CryptoJS.mode.CFB = (function () { 9313 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9314 9315 CFB.Encryptor = CFB.extend({ 9316 processBlock: function (words, offset) { 9317 // Shortcuts 9318 var cipher = this._cipher; 9319 var blockSize = cipher.blockSize; 9320 9321 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9322 9323 // Remember this block to use with next block 9324 this._prevBlock = words.slice(offset, offset + blockSize); 9325 } 9326 }); 9327 9328 CFB.Decryptor = CFB.extend({ 9329 processBlock: function (words, offset) { 9330 // Shortcuts 9331 var cipher = this._cipher; 9332 var blockSize = cipher.blockSize; 9333 9334 // Remember this block to use with next block 9335 var thisBlock = words.slice(offset, offset + blockSize); 9336 9337 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9338 9339 // This block becomes the previous block 9340 this._prevBlock = thisBlock; 9341 } 9342 }); 9343 9344 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9345 // Shortcut 9346 var iv = this._iv; 9347 9348 // Generate keystream 9349 if (iv) { 9350 var keystream = iv.slice(0); 9351 9352 // Remove IV for subsequent blocks 9353 this._iv = undefined; 9354 } else { 9355 var keystream = this._prevBlock; 9356 } 9357 cipher.encryptBlock(keystream, 0); 9358 9359 // Encrypt 9360 for (var i = 0; i < blockSize; i++) { 9361 words[offset + i] ^= keystream[i]; 9362 } 9363 } 9364 9365 return CFB; 9366 }()); 9367 9368 9369 return CryptoJS.mode.CFB; 9370 9371 })); 9372 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 9373 ;(function (root, factory, undef) { 9374 if (typeof exports === "object") { 9375 // CommonJS 9376 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9377 } 9378 else if (typeof define === "function" && define.amd) { 9379 // AMD 9380 define(["./core", "./cipher-core"], factory); 9381 } 9382 else { 9383 // Global (browser) 9384 factory(root.CryptoJS); 9385 } 9386 }(this, function (CryptoJS) { 9387 9388 /** @preserve 9389 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9390 * derived from CryptoJS.mode.CTR 9391 * Jan Hruby jhruby.web@gmail.com 9392 */ 9393 CryptoJS.mode.CTRGladman = (function () { 9394 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9395 9396 function incWord(word) 9397 { 9398 if (((word >> 24) & 0xff) === 0xff) { //overflow 9399 var b1 = (word >> 16)&0xff; 9400 var b2 = (word >> 8)&0xff; 9401 var b3 = word & 0xff; 9402 9403 if (b1 === 0xff) // overflow b1 9404 { 9405 b1 = 0; 9406 if (b2 === 0xff) 9407 { 9408 b2 = 0; 9409 if (b3 === 0xff) 9410 { 9411 b3 = 0; 9412 } 9413 else 9414 { 9415 ++b3; 9416 } 9417 } 9418 else 9419 { 9420 ++b2; 9421 } 9422 } 9423 else 9424 { 9425 ++b1; 9426 } 9427 9428 word = 0; 9429 word += (b1 << 16); 9430 word += (b2 << 8); 9431 word += b3; 9432 } 9433 else 9434 { 9435 word += (0x01 << 24); 9436 } 9437 return word; 9438 } 9439 9440 function incCounter(counter) 9441 { 9442 if ((counter[0] = incWord(counter[0])) === 0) 9443 { 9444 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9445 counter[1] = incWord(counter[1]); 9446 } 9447 return counter; 9448 } 9449 9450 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9451 processBlock: function (words, offset) { 9452 // Shortcuts 9453 var cipher = this._cipher 9454 var blockSize = cipher.blockSize; 9455 var iv = this._iv; 9456 var counter = this._counter; 9457 9458 // Generate keystream 9459 if (iv) { 9460 counter = this._counter = iv.slice(0); 9461 9462 // Remove IV for subsequent blocks 9463 this._iv = undefined; 9464 } 9465 9466 incCounter(counter); 9467 9468 var keystream = counter.slice(0); 9469 cipher.encryptBlock(keystream, 0); 9470 9471 // Encrypt 9472 for (var i = 0; i < blockSize; i++) { 9473 words[offset + i] ^= keystream[i]; 9474 } 9475 } 9476 }); 9477 9478 CTRGladman.Decryptor = Encryptor; 9479 9480 return CTRGladman; 9481 }()); 9482 9483 9484 9485 9486 return CryptoJS.mode.CTRGladman; 9487 9488 })); 9489 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 9490 ;(function (root, factory, undef) { 9491 if (typeof exports === "object") { 9492 // CommonJS 9493 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9494 } 9495 else if (typeof define === "function" && define.amd) { 9496 // AMD 9497 define(["./core", "./cipher-core"], factory); 9498 } 9499 else { 9500 // Global (browser) 9501 factory(root.CryptoJS); 9502 } 9503 }(this, function (CryptoJS) { 9504 9505 /** 9506 * Counter block mode. 9507 */ 9508 CryptoJS.mode.CTR = (function () { 9509 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 9510 9511 var Encryptor = CTR.Encryptor = CTR.extend({ 9512 processBlock: function (words, offset) { 9513 // Shortcuts 9514 var cipher = this._cipher 9515 var blockSize = cipher.blockSize; 9516 var iv = this._iv; 9517 var counter = this._counter; 9518 9519 // Generate keystream 9520 if (iv) { 9521 counter = this._counter = iv.slice(0); 9522 9523 // Remove IV for subsequent blocks 9524 this._iv = undefined; 9525 } 9526 var keystream = counter.slice(0); 9527 cipher.encryptBlock(keystream, 0); 9528 9529 // Increment counter 9530 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 9531 9532 // Encrypt 9533 for (var i = 0; i < blockSize; i++) { 9534 words[offset + i] ^= keystream[i]; 9535 } 9536 } 9537 }); 9538 9539 CTR.Decryptor = Encryptor; 9540 9541 return CTR; 9542 }()); 9543 9544 9545 return CryptoJS.mode.CTR; 9546 9547 })); 9548 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 9549 ;(function (root, factory, undef) { 9550 if (typeof exports === "object") { 9551 // CommonJS 9552 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9553 } 9554 else if (typeof define === "function" && define.amd) { 9555 // AMD 9556 define(["./core", "./cipher-core"], factory); 9557 } 9558 else { 9559 // Global (browser) 9560 factory(root.CryptoJS); 9561 } 9562 }(this, function (CryptoJS) { 9563 9564 /** 9565 * Electronic Codebook block mode. 9566 */ 9567 CryptoJS.mode.ECB = (function () { 9568 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 9569 9570 ECB.Encryptor = ECB.extend({ 9571 processBlock: function (words, offset) { 9572 this._cipher.encryptBlock(words, offset); 9573 } 9574 }); 9575 9576 ECB.Decryptor = ECB.extend({ 9577 processBlock: function (words, offset) { 9578 this._cipher.decryptBlock(words, offset); 9579 } 9580 }); 9581 9582 return ECB; 9583 }()); 9584 9585 9586 return CryptoJS.mode.ECB; 9587 9588 })); 9589 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 9590 ;(function (root, factory, undef) { 9591 if (typeof exports === "object") { 9592 // CommonJS 9593 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9594 } 9595 else if (typeof define === "function" && define.amd) { 9596 // AMD 9597 define(["./core", "./cipher-core"], factory); 9598 } 9599 else { 9600 // Global (browser) 9601 factory(root.CryptoJS); 9602 } 9603 }(this, function (CryptoJS) { 9604 9605 /** 9606 * Output Feedback block mode. 9607 */ 9608 CryptoJS.mode.OFB = (function () { 9609 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 9610 9611 var Encryptor = OFB.Encryptor = OFB.extend({ 9612 processBlock: function (words, offset) { 9613 // Shortcuts 9614 var cipher = this._cipher 9615 var blockSize = cipher.blockSize; 9616 var iv = this._iv; 9617 var keystream = this._keystream; 9618 9619 // Generate keystream 9620 if (iv) { 9621 keystream = this._keystream = iv.slice(0); 9622 9623 // Remove IV for subsequent blocks 9624 this._iv = undefined; 9625 } 9626 cipher.encryptBlock(keystream, 0); 9627 9628 // Encrypt 9629 for (var i = 0; i < blockSize; i++) { 9630 words[offset + i] ^= keystream[i]; 9631 } 9632 } 9633 }); 9634 9635 OFB.Decryptor = Encryptor; 9636 9637 return OFB; 9638 }()); 9639 9640 9641 return CryptoJS.mode.OFB; 9642 9643 })); 9644 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 9645 ;(function (root, factory, undef) { 9646 if (typeof exports === "object") { 9647 // CommonJS 9648 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9649 } 9650 else if (typeof define === "function" && define.amd) { 9651 // AMD 9652 define(["./core", "./cipher-core"], factory); 9653 } 9654 else { 9655 // Global (browser) 9656 factory(root.CryptoJS); 9657 } 9658 }(this, function (CryptoJS) { 9659 9660 /** 9661 * ANSI X.923 padding strategy. 9662 */ 9663 CryptoJS.pad.AnsiX923 = { 9664 pad: function (data, blockSize) { 9665 // Shortcuts 9666 var dataSigBytes = data.sigBytes; 9667 var blockSizeBytes = blockSize * 4; 9668 9669 // Count padding bytes 9670 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 9671 9672 // Compute last byte position 9673 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 9674 9675 // Pad 9676 data.clamp(); 9677 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 9678 data.sigBytes += nPaddingBytes; 9679 }, 9680 9681 unpad: function (data) { 9682 // Get number of padding bytes from last byte 9683 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 9684 9685 // Remove padding 9686 data.sigBytes -= nPaddingBytes; 9687 } 9688 }; 9689 9690 9691 return CryptoJS.pad.Ansix923; 9692 9693 })); 9694 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 9695 ;(function (root, factory, undef) { 9696 if (typeof exports === "object") { 9697 // CommonJS 9698 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9699 } 9700 else if (typeof define === "function" && define.amd) { 9701 // AMD 9702 define(["./core", "./cipher-core"], factory); 9703 } 9704 else { 9705 // Global (browser) 9706 factory(root.CryptoJS); 9707 } 9708 }(this, function (CryptoJS) { 9709 9710 /** 9711 * ISO 10126 padding strategy. 9712 */ 9713 CryptoJS.pad.Iso10126 = { 9714 pad: function (data, blockSize) { 9715 // Shortcut 9716 var blockSizeBytes = blockSize * 4; 9717 9718 // Count padding bytes 9719 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 9720 9721 // Pad 9722 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 9723 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 9724 }, 9725 9726 unpad: function (data) { 9727 // Get number of padding bytes from last byte 9728 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 9729 9730 // Remove padding 9731 data.sigBytes -= nPaddingBytes; 9732 } 9733 }; 9734 9735 9736 return CryptoJS.pad.Iso10126; 9737 9738 })); 9739 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 9740 ;(function (root, factory, undef) { 9741 if (typeof exports === "object") { 9742 // CommonJS 9743 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9744 } 9745 else if (typeof define === "function" && define.amd) { 9746 // AMD 9747 define(["./core", "./cipher-core"], factory); 9748 } 9749 else { 9750 // Global (browser) 9751 factory(root.CryptoJS); 9752 } 9753 }(this, function (CryptoJS) { 9754 9755 /** 9756 * ISO/IEC 9797-1 Padding Method 2. 9757 */ 9758 CryptoJS.pad.Iso97971 = { 9759 pad: function (data, blockSize) { 9760 // Add 0x80 byte 9761 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 9762 9763 // Zero pad the rest 9764 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 9765 }, 9766 9767 unpad: function (data) { 9768 // Remove zero padding 9769 CryptoJS.pad.ZeroPadding.unpad(data); 9770 9771 // Remove one more byte -- the 0x80 byte 9772 data.sigBytes--; 9773 } 9774 }; 9775 9776 9777 return CryptoJS.pad.Iso97971; 9778 9779 })); 9780 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 9781 ;(function (root, factory, undef) { 9782 if (typeof exports === "object") { 9783 // CommonJS 9784 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9785 } 9786 else if (typeof define === "function" && define.amd) { 9787 // AMD 9788 define(["./core", "./cipher-core"], factory); 9789 } 9790 else { 9791 // Global (browser) 9792 factory(root.CryptoJS); 9793 } 9794 }(this, function (CryptoJS) { 9795 9796 /** 9797 * A noop padding strategy. 9798 */ 9799 CryptoJS.pad.NoPadding = { 9800 pad: function () { 9801 }, 9802 9803 unpad: function () { 9804 } 9805 }; 9806 9807 9808 return CryptoJS.pad.NoPadding; 9809 9810 })); 9811 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 9812 ;(function (root, factory, undef) { 9813 if (typeof exports === "object") { 9814 // CommonJS 9815 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9816 } 9817 else if (typeof define === "function" && define.amd) { 9818 // AMD 9819 define(["./core", "./cipher-core"], factory); 9820 } 9821 else { 9822 // Global (browser) 9823 factory(root.CryptoJS); 9824 } 9825 }(this, function (CryptoJS) { 9826 9827 /** 9828 * Zero padding strategy. 9829 */ 9830 CryptoJS.pad.ZeroPadding = { 9831 pad: function (data, blockSize) { 9832 // Shortcut 9833 var blockSizeBytes = blockSize * 4; 9834 9835 // Pad 9836 data.clamp(); 9837 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 9838 }, 9839 9840 unpad: function (data) { 9841 // Shortcut 9842 var dataWords = data.words; 9843 9844 // Unpad 9845 var i = data.sigBytes - 1; 9846 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 9847 i--; 9848 } 9849 data.sigBytes = i + 1; 9850 } 9851 }; 9852 9853 9854 return CryptoJS.pad.ZeroPadding; 9855 9856 })); 9857 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 9858 ;(function (root, factory, undef) { 9859 if (typeof exports === "object") { 9860 // CommonJS 9861 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 9862 } 9863 else if (typeof define === "function" && define.amd) { 9864 // AMD 9865 define(["./core", "./sha1", "./hmac"], factory); 9866 } 9867 else { 9868 // Global (browser) 9869 factory(root.CryptoJS); 9870 } 9871 }(this, function (CryptoJS) { 9872 9873 (function () { 9874 // Shortcuts 9875 var C = CryptoJS; 9876 var C_lib = C.lib; 9877 var Base = C_lib.Base; 9878 var WordArray = C_lib.WordArray; 9879 var C_algo = C.algo; 9880 var SHA1 = C_algo.SHA1; 9881 var HMAC = C_algo.HMAC; 9882 9883 /** 9884 * Password-Based Key Derivation Function 2 algorithm. 9885 */ 9886 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 9887 /** 9888 * Configuration options. 9889 * 9890 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9891 * @property {Hasher} hasher The hasher to use. Default: SHA1 9892 * @property {number} iterations The number of iterations to perform. Default: 1 9893 */ 9894 cfg: Base.extend({ 9895 keySize: 128/32, 9896 hasher: SHA1, 9897 iterations: 1 9898 }), 9899 9900 /** 9901 * Initializes a newly created key derivation function. 9902 * 9903 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9904 * 9905 * @example 9906 * 9907 * var kdf = CryptoJS.algo.PBKDF2.create(); 9908 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 9909 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 9910 */ 9911 init: function (cfg) { 9912 this.cfg = this.cfg.extend(cfg); 9913 }, 9914 9915 /** 9916 * Computes the Password-Based Key Derivation Function 2. 9917 * 9918 * @param {WordArray|string} password The password. 9919 * @param {WordArray|string} salt A salt. 9920 * 9921 * @return {WordArray} The derived key. 9922 * 9923 * @example 9924 * 9925 * var key = kdf.compute(password, salt); 9926 */ 9927 compute: function (password, salt) { 9928 // Shortcut 9929 var cfg = this.cfg; 9930 9931 // Init HMAC 9932 var hmac = HMAC.create(cfg.hasher, password); 9933 9934 // Initial values 9935 var derivedKey = WordArray.create(); 9936 var blockIndex = WordArray.create([0x00000001]); 9937 9938 // Shortcuts 9939 var derivedKeyWords = derivedKey.words; 9940 var blockIndexWords = blockIndex.words; 9941 var keySize = cfg.keySize; 9942 var iterations = cfg.iterations; 9943 9944 // Generate key 9945 while (derivedKeyWords.length < keySize) { 9946 var block = hmac.update(salt).finalize(blockIndex); 9947 hmac.reset(); 9948 9949 // Shortcuts 9950 var blockWords = block.words; 9951 var blockWordsLength = blockWords.length; 9952 9953 // Iterations 9954 var intermediate = block; 9955 for (var i = 1; i < iterations; i++) { 9956 intermediate = hmac.finalize(intermediate); 9957 hmac.reset(); 9958 9959 // Shortcut 9960 var intermediateWords = intermediate.words; 9961 9962 // XOR intermediate with block 9963 for (var j = 0; j < blockWordsLength; j++) { 9964 blockWords[j] ^= intermediateWords[j]; 9965 } 9966 } 9967 9968 derivedKey.concat(block); 9969 blockIndexWords[0]++; 9970 } 9971 derivedKey.sigBytes = keySize * 4; 9972 9973 return derivedKey; 9974 } 9975 }); 9976 9977 /** 9978 * Computes the Password-Based Key Derivation Function 2. 9979 * 9980 * @param {WordArray|string} password The password. 9981 * @param {WordArray|string} salt A salt. 9982 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9983 * 9984 * @return {WordArray} The derived key. 9985 * 9986 * @static 9987 * 9988 * @example 9989 * 9990 * var key = CryptoJS.PBKDF2(password, salt); 9991 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 9992 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 9993 */ 9994 C.PBKDF2 = function (password, salt, cfg) { 9995 return PBKDF2.create(cfg).compute(password, salt); 9996 }; 9997 }()); 9998 9999 10000 return CryptoJS.PBKDF2; 10001 10002 })); 10003 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 10004 ;(function (root, factory, undef) { 10005 if (typeof exports === "object") { 10006 // CommonJS 10007 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10008 } 10009 else if (typeof define === "function" && define.amd) { 10010 // AMD 10011 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10012 } 10013 else { 10014 // Global (browser) 10015 factory(root.CryptoJS); 10016 } 10017 }(this, function (CryptoJS) { 10018 10019 (function () { 10020 // Shortcuts 10021 var C = CryptoJS; 10022 var C_lib = C.lib; 10023 var StreamCipher = C_lib.StreamCipher; 10024 var C_algo = C.algo; 10025 10026 // Reusable objects 10027 var S = []; 10028 var C_ = []; 10029 var G = []; 10030 10031 /** 10032 * Rabbit stream cipher algorithm. 10033 * 10034 * This is a legacy version that neglected to convert the key to little-endian. 10035 * This error doesn't affect the cipher's security, 10036 * but it does affect its compatibility with other implementations. 10037 */ 10038 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10039 _doReset: function () { 10040 // Shortcuts 10041 var K = this._key.words; 10042 var iv = this.cfg.iv; 10043 10044 // Generate initial state values 10045 var X = this._X = [ 10046 K[0], (K[3] << 16) | (K[2] >>> 16), 10047 K[1], (K[0] << 16) | (K[3] >>> 16), 10048 K[2], (K[1] << 16) | (K[0] >>> 16), 10049 K[3], (K[2] << 16) | (K[1] >>> 16) 10050 ]; 10051 10052 // Generate initial counter values 10053 var C = this._C = [ 10054 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10055 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10056 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10057 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10058 ]; 10059 10060 // Carry bit 10061 this._b = 0; 10062 10063 // Iterate the system four times 10064 for (var i = 0; i < 4; i++) { 10065 nextState.call(this); 10066 } 10067 10068 // Modify the counters 10069 for (var i = 0; i < 8; i++) { 10070 C[i] ^= X[(i + 4) & 7]; 10071 } 10072 10073 // IV setup 10074 if (iv) { 10075 // Shortcuts 10076 var IV = iv.words; 10077 var IV_0 = IV[0]; 10078 var IV_1 = IV[1]; 10079 10080 // Generate four subvectors 10081 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10082 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10083 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10084 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10085 10086 // Modify counter values 10087 C[0] ^= i0; 10088 C[1] ^= i1; 10089 C[2] ^= i2; 10090 C[3] ^= i3; 10091 C[4] ^= i0; 10092 C[5] ^= i1; 10093 C[6] ^= i2; 10094 C[7] ^= i3; 10095 10096 // Iterate the system four times 10097 for (var i = 0; i < 4; i++) { 10098 nextState.call(this); 10099 } 10100 } 10101 }, 10102 10103 _doProcessBlock: function (M, offset) { 10104 // Shortcut 10105 var X = this._X; 10106 10107 // Iterate the system 10108 nextState.call(this); 10109 10110 // Generate four keystream words 10111 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10112 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10113 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10114 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10115 10116 for (var i = 0; i < 4; i++) { 10117 // Swap endian 10118 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10119 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10120 10121 // Encrypt 10122 M[offset + i] ^= S[i]; 10123 } 10124 }, 10125 10126 blockSize: 128/32, 10127 10128 ivSize: 64/32 10129 }); 10130 10131 function nextState() { 10132 // Shortcuts 10133 var X = this._X; 10134 var C = this._C; 10135 10136 // Save old counter values 10137 for (var i = 0; i < 8; i++) { 10138 C_[i] = C[i]; 10139 } 10140 10141 // Calculate new counter values 10142 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10143 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10144 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10145 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10146 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10147 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10148 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10149 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10150 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10151 10152 // Calculate the g-values 10153 for (var i = 0; i < 8; i++) { 10154 var gx = X[i] + C[i]; 10155 10156 // Construct high and low argument for squaring 10157 var ga = gx & 0xffff; 10158 var gb = gx >>> 16; 10159 10160 // Calculate high and low result of squaring 10161 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10162 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10163 10164 // High XOR low 10165 G[i] = gh ^ gl; 10166 } 10167 10168 // Calculate new state values 10169 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10170 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10171 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10172 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10173 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10174 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10175 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10176 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10177 } 10178 10179 /** 10180 * Shortcut functions to the cipher's object interface. 10181 * 10182 * @example 10183 * 10184 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10185 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10186 */ 10187 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10188 }()); 10189 10190 10191 return CryptoJS.RabbitLegacy; 10192 10193 })); 10194 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 10195 ;(function (root, factory, undef) { 10196 if (typeof exports === "object") { 10197 // CommonJS 10198 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10199 } 10200 else if (typeof define === "function" && define.amd) { 10201 // AMD 10202 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10203 } 10204 else { 10205 // Global (browser) 10206 factory(root.CryptoJS); 10207 } 10208 }(this, function (CryptoJS) { 10209 10210 (function () { 10211 // Shortcuts 10212 var C = CryptoJS; 10213 var C_lib = C.lib; 10214 var StreamCipher = C_lib.StreamCipher; 10215 var C_algo = C.algo; 10216 10217 // Reusable objects 10218 var S = []; 10219 var C_ = []; 10220 var G = []; 10221 10222 /** 10223 * Rabbit stream cipher algorithm 10224 */ 10225 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10226 _doReset: function () { 10227 // Shortcuts 10228 var K = this._key.words; 10229 var iv = this.cfg.iv; 10230 10231 // Swap endian 10232 for (var i = 0; i < 4; i++) { 10233 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10234 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10235 } 10236 10237 // Generate initial state values 10238 var X = this._X = [ 10239 K[0], (K[3] << 16) | (K[2] >>> 16), 10240 K[1], (K[0] << 16) | (K[3] >>> 16), 10241 K[2], (K[1] << 16) | (K[0] >>> 16), 10242 K[3], (K[2] << 16) | (K[1] >>> 16) 10243 ]; 10244 10245 // Generate initial counter values 10246 var C = this._C = [ 10247 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10248 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10249 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10250 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10251 ]; 10252 10253 // Carry bit 10254 this._b = 0; 10255 10256 // Iterate the system four times 10257 for (var i = 0; i < 4; i++) { 10258 nextState.call(this); 10259 } 10260 10261 // Modify the counters 10262 for (var i = 0; i < 8; i++) { 10263 C[i] ^= X[(i + 4) & 7]; 10264 } 10265 10266 // IV setup 10267 if (iv) { 10268 // Shortcuts 10269 var IV = iv.words; 10270 var IV_0 = IV[0]; 10271 var IV_1 = IV[1]; 10272 10273 // Generate four subvectors 10274 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10275 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10276 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10277 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10278 10279 // Modify counter values 10280 C[0] ^= i0; 10281 C[1] ^= i1; 10282 C[2] ^= i2; 10283 C[3] ^= i3; 10284 C[4] ^= i0; 10285 C[5] ^= i1; 10286 C[6] ^= i2; 10287 C[7] ^= i3; 10288 10289 // Iterate the system four times 10290 for (var i = 0; i < 4; i++) { 10291 nextState.call(this); 10292 } 10293 } 10294 }, 10295 10296 _doProcessBlock: function (M, offset) { 10297 // Shortcut 10298 var X = this._X; 10299 10300 // Iterate the system 10301 nextState.call(this); 10302 10303 // Generate four keystream words 10304 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10305 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10306 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10307 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10308 10309 for (var i = 0; i < 4; i++) { 10310 // Swap endian 10311 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10312 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10313 10314 // Encrypt 10315 M[offset + i] ^= S[i]; 10316 } 10317 }, 10318 10319 blockSize: 128/32, 10320 10321 ivSize: 64/32 10322 }); 10323 10324 function nextState() { 10325 // Shortcuts 10326 var X = this._X; 10327 var C = this._C; 10328 10329 // Save old counter values 10330 for (var i = 0; i < 8; i++) { 10331 C_[i] = C[i]; 10332 } 10333 10334 // Calculate new counter values 10335 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10336 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10337 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10338 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10339 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10340 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10341 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10342 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10343 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10344 10345 // Calculate the g-values 10346 for (var i = 0; i < 8; i++) { 10347 var gx = X[i] + C[i]; 10348 10349 // Construct high and low argument for squaring 10350 var ga = gx & 0xffff; 10351 var gb = gx >>> 16; 10352 10353 // Calculate high and low result of squaring 10354 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10355 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10356 10357 // High XOR low 10358 G[i] = gh ^ gl; 10359 } 10360 10361 // Calculate new state values 10362 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10363 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10364 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10365 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10366 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10367 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10368 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10369 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10370 } 10371 10372 /** 10373 * Shortcut functions to the cipher's object interface. 10374 * 10375 * @example 10376 * 10377 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10378 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10379 */ 10380 C.Rabbit = StreamCipher._createHelper(Rabbit); 10381 }()); 10382 10383 10384 return CryptoJS.Rabbit; 10385 10386 })); 10387 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 10388 ;(function (root, factory, undef) { 10389 if (typeof exports === "object") { 10390 // CommonJS 10391 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10392 } 10393 else if (typeof define === "function" && define.amd) { 10394 // AMD 10395 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10396 } 10397 else { 10398 // Global (browser) 10399 factory(root.CryptoJS); 10400 } 10401 }(this, function (CryptoJS) { 10402 10403 (function () { 10404 // Shortcuts 10405 var C = CryptoJS; 10406 var C_lib = C.lib; 10407 var StreamCipher = C_lib.StreamCipher; 10408 var C_algo = C.algo; 10409 10410 /** 10411 * RC4 stream cipher algorithm. 10412 */ 10413 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10414 _doReset: function () { 10415 // Shortcuts 10416 var key = this._key; 10417 var keyWords = key.words; 10418 var keySigBytes = key.sigBytes; 10419 10420 // Init sbox 10421 var S = this._S = []; 10422 for (var i = 0; i < 256; i++) { 10423 S[i] = i; 10424 } 10425 10426 // Key setup 10427 for (var i = 0, j = 0; i < 256; i++) { 10428 var keyByteIndex = i % keySigBytes; 10429 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10430 10431 j = (j + S[i] + keyByte) % 256; 10432 10433 // Swap 10434 var t = S[i]; 10435 S[i] = S[j]; 10436 S[j] = t; 10437 } 10438 10439 // Counters 10440 this._i = this._j = 0; 10441 }, 10442 10443 _doProcessBlock: function (M, offset) { 10444 M[offset] ^= generateKeystreamWord.call(this); 10445 }, 10446 10447 keySize: 256/32, 10448 10449 ivSize: 0 10450 }); 10451 10452 function generateKeystreamWord() { 10453 // Shortcuts 10454 var S = this._S; 10455 var i = this._i; 10456 var j = this._j; 10457 10458 // Generate keystream word 10459 var keystreamWord = 0; 10460 for (var n = 0; n < 4; n++) { 10461 i = (i + 1) % 256; 10462 j = (j + S[i]) % 256; 10463 10464 // Swap 10465 var t = S[i]; 10466 S[i] = S[j]; 10467 S[j] = t; 10468 10469 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 10470 } 10471 10472 // Update counters 10473 this._i = i; 10474 this._j = j; 10475 10476 return keystreamWord; 10477 } 10478 10479 /** 10480 * Shortcut functions to the cipher's object interface. 10481 * 10482 * @example 10483 * 10484 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 10485 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 10486 */ 10487 C.RC4 = StreamCipher._createHelper(RC4); 10488 10489 /** 10490 * Modified RC4 stream cipher algorithm. 10491 */ 10492 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 10493 /** 10494 * Configuration options. 10495 * 10496 * @property {number} drop The number of keystream words to drop. Default 192 10497 */ 10498 cfg: RC4.cfg.extend({ 10499 drop: 192 10500 }), 10501 10502 _doReset: function () { 10503 RC4._doReset.call(this); 10504 10505 // Drop 10506 for (var i = this.cfg.drop; i > 0; i--) { 10507 generateKeystreamWord.call(this); 10508 } 10509 } 10510 }); 10511 10512 /** 10513 * Shortcut functions to the cipher's object interface. 10514 * 10515 * @example 10516 * 10517 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 10518 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 10519 */ 10520 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 10521 }()); 10522 10523 10524 return CryptoJS.RC4; 10525 10526 })); 10527 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 10528 ;(function (root, factory) { 10529 if (typeof exports === "object") { 10530 // CommonJS 10531 module.exports = exports = factory(require("./core")); 10532 } 10533 else if (typeof define === "function" && define.amd) { 10534 // AMD 10535 define(["./core"], factory); 10536 } 10537 else { 10538 // Global (browser) 10539 factory(root.CryptoJS); 10540 } 10541 }(this, function (CryptoJS) { 10542 10543 /** @preserve 10544 (c) 2012 by Cédric Mesnil. All rights reserved. 10545 10546 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10547 10548 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10549 - 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. 10550 10551 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. 10552 */ 10553 10554 (function (Math) { 10555 // Shortcuts 10556 var C = CryptoJS; 10557 var C_lib = C.lib; 10558 var WordArray = C_lib.WordArray; 10559 var Hasher = C_lib.Hasher; 10560 var C_algo = C.algo; 10561 10562 // Constants table 10563 var _zl = WordArray.create([ 10564 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10565 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 10566 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 10567 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 10568 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 10569 var _zr = WordArray.create([ 10570 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 10571 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 10572 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 10573 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 10574 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 10575 var _sl = WordArray.create([ 10576 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 10577 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 10578 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 10579 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 10580 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 10581 var _sr = WordArray.create([ 10582 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 10583 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 10584 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 10585 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 10586 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 10587 10588 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 10589 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 10590 10591 /** 10592 * RIPEMD160 hash algorithm. 10593 */ 10594 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 10595 _doReset: function () { 10596 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 10597 }, 10598 10599 _doProcessBlock: function (M, offset) { 10600 10601 // Swap endian 10602 for (var i = 0; i < 16; i++) { 10603 // Shortcuts 10604 var offset_i = offset + i; 10605 var M_offset_i = M[offset_i]; 10606 10607 // Swap 10608 M[offset_i] = ( 10609 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10610 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 10611 ); 10612 } 10613 // Shortcut 10614 var H = this._hash.words; 10615 var hl = _hl.words; 10616 var hr = _hr.words; 10617 var zl = _zl.words; 10618 var zr = _zr.words; 10619 var sl = _sl.words; 10620 var sr = _sr.words; 10621 10622 // Working variables 10623 var al, bl, cl, dl, el; 10624 var ar, br, cr, dr, er; 10625 10626 ar = al = H[0]; 10627 br = bl = H[1]; 10628 cr = cl = H[2]; 10629 dr = dl = H[3]; 10630 er = el = H[4]; 10631 // Computation 10632 var t; 10633 for (var i = 0; i < 80; i += 1) { 10634 t = (al + M[offset+zl[i]])|0; 10635 if (i<16){ 10636 t += f1(bl,cl,dl) + hl[0]; 10637 } else if (i<32) { 10638 t += f2(bl,cl,dl) + hl[1]; 10639 } else if (i<48) { 10640 t += f3(bl,cl,dl) + hl[2]; 10641 } else if (i<64) { 10642 t += f4(bl,cl,dl) + hl[3]; 10643 } else {// if (i<80) { 10644 t += f5(bl,cl,dl) + hl[4]; 10645 } 10646 t = t|0; 10647 t = rotl(t,sl[i]); 10648 t = (t+el)|0; 10649 al = el; 10650 el = dl; 10651 dl = rotl(cl, 10); 10652 cl = bl; 10653 bl = t; 10654 10655 t = (ar + M[offset+zr[i]])|0; 10656 if (i<16){ 10657 t += f5(br,cr,dr) + hr[0]; 10658 } else if (i<32) { 10659 t += f4(br,cr,dr) + hr[1]; 10660 } else if (i<48) { 10661 t += f3(br,cr,dr) + hr[2]; 10662 } else if (i<64) { 10663 t += f2(br,cr,dr) + hr[3]; 10664 } else {// if (i<80) { 10665 t += f1(br,cr,dr) + hr[4]; 10666 } 10667 t = t|0; 10668 t = rotl(t,sr[i]) ; 10669 t = (t+er)|0; 10670 ar = er; 10671 er = dr; 10672 dr = rotl(cr, 10); 10673 cr = br; 10674 br = t; 10675 } 10676 // Intermediate hash value 10677 t = (H[1] + cl + dr)|0; 10678 H[1] = (H[2] + dl + er)|0; 10679 H[2] = (H[3] + el + ar)|0; 10680 H[3] = (H[4] + al + br)|0; 10681 H[4] = (H[0] + bl + cr)|0; 10682 H[0] = t; 10683 }, 10684 10685 _doFinalize: function () { 10686 // Shortcuts 10687 var data = this._data; 10688 var dataWords = data.words; 10689 10690 var nBitsTotal = this._nDataBytes * 8; 10691 var nBitsLeft = data.sigBytes * 8; 10692 10693 // Add padding 10694 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 10695 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 10696 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 10697 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 10698 ); 10699 data.sigBytes = (dataWords.length + 1) * 4; 10700 10701 // Hash final blocks 10702 this._process(); 10703 10704 // Shortcuts 10705 var hash = this._hash; 10706 var H = hash.words; 10707 10708 // Swap endian 10709 for (var i = 0; i < 5; i++) { 10710 // Shortcut 10711 var H_i = H[i]; 10712 10713 // Swap 10714 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 10715 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 10716 } 10717 10718 // Return final computed hash 10719 return hash; 10720 }, 10721 10722 clone: function () { 10723 var clone = Hasher.clone.call(this); 10724 clone._hash = this._hash.clone(); 10725 10726 return clone; 10727 } 10728 }); 10729 10730 10731 function f1(x, y, z) { 10732 return ((x) ^ (y) ^ (z)); 10733 10734 } 10735 10736 function f2(x, y, z) { 10737 return (((x)&(y)) | ((~x)&(z))); 10738 } 10739 10740 function f3(x, y, z) { 10741 return (((x) | (~(y))) ^ (z)); 10742 } 10743 10744 function f4(x, y, z) { 10745 return (((x) & (z)) | ((y)&(~(z)))); 10746 } 10747 10748 function f5(x, y, z) { 10749 return ((x) ^ ((y) |(~(z)))); 10750 10751 } 10752 10753 function rotl(x,n) { 10754 return (x<<n) | (x>>>(32-n)); 10755 } 10756 10757 10758 /** 10759 * Shortcut function to the hasher's object interface. 10760 * 10761 * @param {WordArray|string} message The message to hash. 10762 * 10763 * @return {WordArray} The hash. 10764 * 10765 * @static 10766 * 10767 * @example 10768 * 10769 * var hash = CryptoJS.RIPEMD160('message'); 10770 * var hash = CryptoJS.RIPEMD160(wordArray); 10771 */ 10772 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 10773 10774 /** 10775 * Shortcut function to the HMAC's object interface. 10776 * 10777 * @param {WordArray|string} message The message to hash. 10778 * @param {WordArray|string} key The secret key. 10779 * 10780 * @return {WordArray} The HMAC. 10781 * 10782 * @static 10783 * 10784 * @example 10785 * 10786 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 10787 */ 10788 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 10789 }(Math)); 10790 10791 10792 return CryptoJS.RIPEMD160; 10793 10794 })); 10795 },{"./core":53}],77:[function(require,module,exports){ 10796 ;(function (root, factory) { 10797 if (typeof exports === "object") { 10798 // CommonJS 10799 module.exports = exports = factory(require("./core")); 10800 } 10801 else if (typeof define === "function" && define.amd) { 10802 // AMD 10803 define(["./core"], factory); 10804 } 10805 else { 10806 // Global (browser) 10807 factory(root.CryptoJS); 10808 } 10809 }(this, function (CryptoJS) { 10810 10811 (function () { 10812 // Shortcuts 10813 var C = CryptoJS; 10814 var C_lib = C.lib; 10815 var WordArray = C_lib.WordArray; 10816 var Hasher = C_lib.Hasher; 10817 var C_algo = C.algo; 10818 10819 // Reusable object 10820 var W = []; 10821 10822 /** 10823 * SHA-1 hash algorithm. 10824 */ 10825 var SHA1 = C_algo.SHA1 = Hasher.extend({ 10826 _doReset: function () { 10827 this._hash = new WordArray.init([ 10828 0x67452301, 0xefcdab89, 10829 0x98badcfe, 0x10325476, 10830 0xc3d2e1f0 10831 ]); 10832 }, 10833 10834 _doProcessBlock: function (M, offset) { 10835 // Shortcut 10836 var H = this._hash.words; 10837 10838 // Working variables 10839 var a = H[0]; 10840 var b = H[1]; 10841 var c = H[2]; 10842 var d = H[3]; 10843 var e = H[4]; 10844 10845 // Computation 10846 for (var i = 0; i < 80; i++) { 10847 if (i < 16) { 10848 W[i] = M[offset + i] | 0; 10849 } else { 10850 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 10851 W[i] = (n << 1) | (n >>> 31); 10852 } 10853 10854 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 10855 if (i < 20) { 10856 t += ((b & c) | (~b & d)) + 0x5a827999; 10857 } else if (i < 40) { 10858 t += (b ^ c ^ d) + 0x6ed9eba1; 10859 } else if (i < 60) { 10860 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 10861 } else /* if (i < 80) */ { 10862 t += (b ^ c ^ d) - 0x359d3e2a; 10863 } 10864 10865 e = d; 10866 d = c; 10867 c = (b << 30) | (b >>> 2); 10868 b = a; 10869 a = t; 10870 } 10871 10872 // Intermediate hash value 10873 H[0] = (H[0] + a) | 0; 10874 H[1] = (H[1] + b) | 0; 10875 H[2] = (H[2] + c) | 0; 10876 H[3] = (H[3] + d) | 0; 10877 H[4] = (H[4] + e) | 0; 10878 }, 10879 10880 _doFinalize: function () { 10881 // Shortcuts 10882 var data = this._data; 10883 var dataWords = data.words; 10884 10885 var nBitsTotal = this._nDataBytes * 8; 10886 var nBitsLeft = data.sigBytes * 8; 10887 10888 // Add padding 10889 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 10890 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 10891 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 10892 data.sigBytes = dataWords.length * 4; 10893 10894 // Hash final blocks 10895 this._process(); 10896 10897 // Return final computed hash 10898 return this._hash; 10899 }, 10900 10901 clone: function () { 10902 var clone = Hasher.clone.call(this); 10903 clone._hash = this._hash.clone(); 10904 10905 return clone; 10906 } 10907 }); 10908 10909 /** 10910 * Shortcut function to the hasher's object interface. 10911 * 10912 * @param {WordArray|string} message The message to hash. 10913 * 10914 * @return {WordArray} The hash. 10915 * 10916 * @static 10917 * 10918 * @example 10919 * 10920 * var hash = CryptoJS.SHA1('message'); 10921 * var hash = CryptoJS.SHA1(wordArray); 10922 */ 10923 C.SHA1 = Hasher._createHelper(SHA1); 10924 10925 /** 10926 * Shortcut function to the HMAC's object interface. 10927 * 10928 * @param {WordArray|string} message The message to hash. 10929 * @param {WordArray|string} key The secret key. 10930 * 10931 * @return {WordArray} The HMAC. 10932 * 10933 * @static 10934 * 10935 * @example 10936 * 10937 * var hmac = CryptoJS.HmacSHA1(message, key); 10938 */ 10939 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 10940 }()); 10941 10942 10943 return CryptoJS.SHA1; 10944 10945 })); 10946 },{"./core":53}],78:[function(require,module,exports){ 10947 ;(function (root, factory, undef) { 10948 if (typeof exports === "object") { 10949 // CommonJS 10950 module.exports = exports = factory(require("./core"), require("./sha256")); 10951 } 10952 else if (typeof define === "function" && define.amd) { 10953 // AMD 10954 define(["./core", "./sha256"], factory); 10955 } 10956 else { 10957 // Global (browser) 10958 factory(root.CryptoJS); 10959 } 10960 }(this, function (CryptoJS) { 10961 10962 (function () { 10963 // Shortcuts 10964 var C = CryptoJS; 10965 var C_lib = C.lib; 10966 var WordArray = C_lib.WordArray; 10967 var C_algo = C.algo; 10968 var SHA256 = C_algo.SHA256; 10969 10970 /** 10971 * SHA-224 hash algorithm. 10972 */ 10973 var SHA224 = C_algo.SHA224 = SHA256.extend({ 10974 _doReset: function () { 10975 this._hash = new WordArray.init([ 10976 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 10977 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 10978 ]); 10979 }, 10980 10981 _doFinalize: function () { 10982 var hash = SHA256._doFinalize.call(this); 10983 10984 hash.sigBytes -= 4; 10985 10986 return hash; 10987 } 10988 }); 10989 10990 /** 10991 * Shortcut function to the hasher's object interface. 10992 * 10993 * @param {WordArray|string} message The message to hash. 10994 * 10995 * @return {WordArray} The hash. 10996 * 10997 * @static 10998 * 10999 * @example 11000 * 11001 * var hash = CryptoJS.SHA224('message'); 11002 * var hash = CryptoJS.SHA224(wordArray); 11003 */ 11004 C.SHA224 = SHA256._createHelper(SHA224); 11005 11006 /** 11007 * Shortcut function to the HMAC's object interface. 11008 * 11009 * @param {WordArray|string} message The message to hash. 11010 * @param {WordArray|string} key The secret key. 11011 * 11012 * @return {WordArray} The HMAC. 11013 * 11014 * @static 11015 * 11016 * @example 11017 * 11018 * var hmac = CryptoJS.HmacSHA224(message, key); 11019 */ 11020 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11021 }()); 11022 11023 11024 return CryptoJS.SHA224; 11025 11026 })); 11027 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 11028 ;(function (root, factory) { 11029 if (typeof exports === "object") { 11030 // CommonJS 11031 module.exports = exports = factory(require("./core")); 11032 } 11033 else if (typeof define === "function" && define.amd) { 11034 // AMD 11035 define(["./core"], factory); 11036 } 11037 else { 11038 // Global (browser) 11039 factory(root.CryptoJS); 11040 } 11041 }(this, function (CryptoJS) { 11042 11043 (function (Math) { 11044 // Shortcuts 11045 var C = CryptoJS; 11046 var C_lib = C.lib; 11047 var WordArray = C_lib.WordArray; 11048 var Hasher = C_lib.Hasher; 11049 var C_algo = C.algo; 11050 11051 // Initialization and round constants tables 11052 var H = []; 11053 var K = []; 11054 11055 // Compute constants 11056 (function () { 11057 function isPrime(n) { 11058 var sqrtN = Math.sqrt(n); 11059 for (var factor = 2; factor <= sqrtN; factor++) { 11060 if (!(n % factor)) { 11061 return false; 11062 } 11063 } 11064 11065 return true; 11066 } 11067 11068 function getFractionalBits(n) { 11069 return ((n - (n | 0)) * 0x100000000) | 0; 11070 } 11071 11072 var n = 2; 11073 var nPrime = 0; 11074 while (nPrime < 64) { 11075 if (isPrime(n)) { 11076 if (nPrime < 8) { 11077 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11078 } 11079 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11080 11081 nPrime++; 11082 } 11083 11084 n++; 11085 } 11086 }()); 11087 11088 // Reusable object 11089 var W = []; 11090 11091 /** 11092 * SHA-256 hash algorithm. 11093 */ 11094 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11095 _doReset: function () { 11096 this._hash = new WordArray.init(H.slice(0)); 11097 }, 11098 11099 _doProcessBlock: function (M, offset) { 11100 // Shortcut 11101 var H = this._hash.words; 11102 11103 // Working variables 11104 var a = H[0]; 11105 var b = H[1]; 11106 var c = H[2]; 11107 var d = H[3]; 11108 var e = H[4]; 11109 var f = H[5]; 11110 var g = H[6]; 11111 var h = H[7]; 11112 11113 // Computation 11114 for (var i = 0; i < 64; i++) { 11115 if (i < 16) { 11116 W[i] = M[offset + i] | 0; 11117 } else { 11118 var gamma0x = W[i - 15]; 11119 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11120 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11121 (gamma0x >>> 3); 11122 11123 var gamma1x = W[i - 2]; 11124 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11125 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11126 (gamma1x >>> 10); 11127 11128 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11129 } 11130 11131 var ch = (e & f) ^ (~e & g); 11132 var maj = (a & b) ^ (a & c) ^ (b & c); 11133 11134 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11135 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11136 11137 var t1 = h + sigma1 + ch + K[i] + W[i]; 11138 var t2 = sigma0 + maj; 11139 11140 h = g; 11141 g = f; 11142 f = e; 11143 e = (d + t1) | 0; 11144 d = c; 11145 c = b; 11146 b = a; 11147 a = (t1 + t2) | 0; 11148 } 11149 11150 // Intermediate hash value 11151 H[0] = (H[0] + a) | 0; 11152 H[1] = (H[1] + b) | 0; 11153 H[2] = (H[2] + c) | 0; 11154 H[3] = (H[3] + d) | 0; 11155 H[4] = (H[4] + e) | 0; 11156 H[5] = (H[5] + f) | 0; 11157 H[6] = (H[6] + g) | 0; 11158 H[7] = (H[7] + h) | 0; 11159 }, 11160 11161 _doFinalize: function () { 11162 // Shortcuts 11163 var data = this._data; 11164 var dataWords = data.words; 11165 11166 var nBitsTotal = this._nDataBytes * 8; 11167 var nBitsLeft = data.sigBytes * 8; 11168 11169 // Add padding 11170 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11171 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11172 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11173 data.sigBytes = dataWords.length * 4; 11174 11175 // Hash final blocks 11176 this._process(); 11177 11178 // Return final computed hash 11179 return this._hash; 11180 }, 11181 11182 clone: function () { 11183 var clone = Hasher.clone.call(this); 11184 clone._hash = this._hash.clone(); 11185 11186 return clone; 11187 } 11188 }); 11189 11190 /** 11191 * Shortcut function to the hasher's object interface. 11192 * 11193 * @param {WordArray|string} message The message to hash. 11194 * 11195 * @return {WordArray} The hash. 11196 * 11197 * @static 11198 * 11199 * @example 11200 * 11201 * var hash = CryptoJS.SHA256('message'); 11202 * var hash = CryptoJS.SHA256(wordArray); 11203 */ 11204 C.SHA256 = Hasher._createHelper(SHA256); 11205 11206 /** 11207 * Shortcut function to the HMAC's object interface. 11208 * 11209 * @param {WordArray|string} message The message to hash. 11210 * @param {WordArray|string} key The secret key. 11211 * 11212 * @return {WordArray} The HMAC. 11213 * 11214 * @static 11215 * 11216 * @example 11217 * 11218 * var hmac = CryptoJS.HmacSHA256(message, key); 11219 */ 11220 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11221 }(Math)); 11222 11223 11224 return CryptoJS.SHA256; 11225 11226 })); 11227 },{"./core":53}],80:[function(require,module,exports){ 11228 ;(function (root, factory, undef) { 11229 if (typeof exports === "object") { 11230 // CommonJS 11231 module.exports = exports = factory(require("./core"), require("./x64-core")); 11232 } 11233 else if (typeof define === "function" && define.amd) { 11234 // AMD 11235 define(["./core", "./x64-core"], factory); 11236 } 11237 else { 11238 // Global (browser) 11239 factory(root.CryptoJS); 11240 } 11241 }(this, function (CryptoJS) { 11242 11243 (function (Math) { 11244 // Shortcuts 11245 var C = CryptoJS; 11246 var C_lib = C.lib; 11247 var WordArray = C_lib.WordArray; 11248 var Hasher = C_lib.Hasher; 11249 var C_x64 = C.x64; 11250 var X64Word = C_x64.Word; 11251 var C_algo = C.algo; 11252 11253 // Constants tables 11254 var RHO_OFFSETS = []; 11255 var PI_INDEXES = []; 11256 var ROUND_CONSTANTS = []; 11257 11258 // Compute Constants 11259 (function () { 11260 // Compute rho offset constants 11261 var x = 1, y = 0; 11262 for (var t = 0; t < 24; t++) { 11263 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11264 11265 var newX = y % 5; 11266 var newY = (2 * x + 3 * y) % 5; 11267 x = newX; 11268 y = newY; 11269 } 11270 11271 // Compute pi index constants 11272 for (var x = 0; x < 5; x++) { 11273 for (var y = 0; y < 5; y++) { 11274 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11275 } 11276 } 11277 11278 // Compute round constants 11279 var LFSR = 0x01; 11280 for (var i = 0; i < 24; i++) { 11281 var roundConstantMsw = 0; 11282 var roundConstantLsw = 0; 11283 11284 for (var j = 0; j < 7; j++) { 11285 if (LFSR & 0x01) { 11286 var bitPosition = (1 << j) - 1; 11287 if (bitPosition < 32) { 11288 roundConstantLsw ^= 1 << bitPosition; 11289 } else /* if (bitPosition >= 32) */ { 11290 roundConstantMsw ^= 1 << (bitPosition - 32); 11291 } 11292 } 11293 11294 // Compute next LFSR 11295 if (LFSR & 0x80) { 11296 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11297 LFSR = (LFSR << 1) ^ 0x71; 11298 } else { 11299 LFSR <<= 1; 11300 } 11301 } 11302 11303 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11304 } 11305 }()); 11306 11307 // Reusable objects for temporary values 11308 var T = []; 11309 (function () { 11310 for (var i = 0; i < 25; i++) { 11311 T[i] = X64Word.create(); 11312 } 11313 }()); 11314 11315 /** 11316 * SHA-3 hash algorithm. 11317 */ 11318 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11319 /** 11320 * Configuration options. 11321 * 11322 * @property {number} outputLength 11323 * The desired number of bits in the output hash. 11324 * Only values permitted are: 224, 256, 384, 512. 11325 * Default: 512 11326 */ 11327 cfg: Hasher.cfg.extend({ 11328 outputLength: 512 11329 }), 11330 11331 _doReset: function () { 11332 var state = this._state = [] 11333 for (var i = 0; i < 25; i++) { 11334 state[i] = new X64Word.init(); 11335 } 11336 11337 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11338 }, 11339 11340 _doProcessBlock: function (M, offset) { 11341 // Shortcuts 11342 var state = this._state; 11343 var nBlockSizeLanes = this.blockSize / 2; 11344 11345 // Absorb 11346 for (var i = 0; i < nBlockSizeLanes; i++) { 11347 // Shortcuts 11348 var M2i = M[offset + 2 * i]; 11349 var M2i1 = M[offset + 2 * i + 1]; 11350 11351 // Swap endian 11352 M2i = ( 11353 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11354 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11355 ); 11356 M2i1 = ( 11357 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11358 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11359 ); 11360 11361 // Absorb message into state 11362 var lane = state[i]; 11363 lane.high ^= M2i1; 11364 lane.low ^= M2i; 11365 } 11366 11367 // Rounds 11368 for (var round = 0; round < 24; round++) { 11369 // Theta 11370 for (var x = 0; x < 5; x++) { 11371 // Mix column lanes 11372 var tMsw = 0, tLsw = 0; 11373 for (var y = 0; y < 5; y++) { 11374 var lane = state[x + 5 * y]; 11375 tMsw ^= lane.high; 11376 tLsw ^= lane.low; 11377 } 11378 11379 // Temporary values 11380 var Tx = T[x]; 11381 Tx.high = tMsw; 11382 Tx.low = tLsw; 11383 } 11384 for (var x = 0; x < 5; x++) { 11385 // Shortcuts 11386 var Tx4 = T[(x + 4) % 5]; 11387 var Tx1 = T[(x + 1) % 5]; 11388 var Tx1Msw = Tx1.high; 11389 var Tx1Lsw = Tx1.low; 11390 11391 // Mix surrounding columns 11392 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11393 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11394 for (var y = 0; y < 5; y++) { 11395 var lane = state[x + 5 * y]; 11396 lane.high ^= tMsw; 11397 lane.low ^= tLsw; 11398 } 11399 } 11400 11401 // Rho Pi 11402 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11403 // Shortcuts 11404 var lane = state[laneIndex]; 11405 var laneMsw = lane.high; 11406 var laneLsw = lane.low; 11407 var rhoOffset = RHO_OFFSETS[laneIndex]; 11408 11409 // Rotate lanes 11410 if (rhoOffset < 32) { 11411 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11412 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11413 } else /* if (rhoOffset >= 32) */ { 11414 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11415 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11416 } 11417 11418 // Transpose lanes 11419 var TPiLane = T[PI_INDEXES[laneIndex]]; 11420 TPiLane.high = tMsw; 11421 TPiLane.low = tLsw; 11422 } 11423 11424 // Rho pi at x = y = 0 11425 var T0 = T[0]; 11426 var state0 = state[0]; 11427 T0.high = state0.high; 11428 T0.low = state0.low; 11429 11430 // Chi 11431 for (var x = 0; x < 5; x++) { 11432 for (var y = 0; y < 5; y++) { 11433 // Shortcuts 11434 var laneIndex = x + 5 * y; 11435 var lane = state[laneIndex]; 11436 var TLane = T[laneIndex]; 11437 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 11438 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 11439 11440 // Mix rows 11441 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 11442 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 11443 } 11444 } 11445 11446 // Iota 11447 var lane = state[0]; 11448 var roundConstant = ROUND_CONSTANTS[round]; 11449 lane.high ^= roundConstant.high; 11450 lane.low ^= roundConstant.low;; 11451 } 11452 }, 11453 11454 _doFinalize: function () { 11455 // Shortcuts 11456 var data = this._data; 11457 var dataWords = data.words; 11458 var nBitsTotal = this._nDataBytes * 8; 11459 var nBitsLeft = data.sigBytes * 8; 11460 var blockSizeBits = this.blockSize * 32; 11461 11462 // Add padding 11463 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 11464 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 11465 data.sigBytes = dataWords.length * 4; 11466 11467 // Hash final blocks 11468 this._process(); 11469 11470 // Shortcuts 11471 var state = this._state; 11472 var outputLengthBytes = this.cfg.outputLength / 8; 11473 var outputLengthLanes = outputLengthBytes / 8; 11474 11475 // Squeeze 11476 var hashWords = []; 11477 for (var i = 0; i < outputLengthLanes; i++) { 11478 // Shortcuts 11479 var lane = state[i]; 11480 var laneMsw = lane.high; 11481 var laneLsw = lane.low; 11482 11483 // Swap endian 11484 laneMsw = ( 11485 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 11486 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 11487 ); 11488 laneLsw = ( 11489 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 11490 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 11491 ); 11492 11493 // Squeeze state to retrieve hash 11494 hashWords.push(laneLsw); 11495 hashWords.push(laneMsw); 11496 } 11497 11498 // Return final computed hash 11499 return new WordArray.init(hashWords, outputLengthBytes); 11500 }, 11501 11502 clone: function () { 11503 var clone = Hasher.clone.call(this); 11504 11505 var state = clone._state = this._state.slice(0); 11506 for (var i = 0; i < 25; i++) { 11507 state[i] = state[i].clone(); 11508 } 11509 11510 return clone; 11511 } 11512 }); 11513 11514 /** 11515 * Shortcut function to the hasher's object interface. 11516 * 11517 * @param {WordArray|string} message The message to hash. 11518 * 11519 * @return {WordArray} The hash. 11520 * 11521 * @static 11522 * 11523 * @example 11524 * 11525 * var hash = CryptoJS.SHA3('message'); 11526 * var hash = CryptoJS.SHA3(wordArray); 11527 */ 11528 C.SHA3 = Hasher._createHelper(SHA3); 11529 11530 /** 11531 * Shortcut function to the HMAC's object interface. 11532 * 11533 * @param {WordArray|string} message The message to hash. 11534 * @param {WordArray|string} key The secret key. 11535 * 11536 * @return {WordArray} The HMAC. 11537 * 11538 * @static 11539 * 11540 * @example 11541 * 11542 * var hmac = CryptoJS.HmacSHA3(message, key); 11543 */ 11544 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 11545 }(Math)); 11546 11547 11548 return CryptoJS.SHA3; 11549 11550 })); 11551 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 11552 ;(function (root, factory, undef) { 11553 if (typeof exports === "object") { 11554 // CommonJS 11555 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 11556 } 11557 else if (typeof define === "function" && define.amd) { 11558 // AMD 11559 define(["./core", "./x64-core", "./sha512"], factory); 11560 } 11561 else { 11562 // Global (browser) 11563 factory(root.CryptoJS); 11564 } 11565 }(this, function (CryptoJS) { 11566 11567 (function () { 11568 // Shortcuts 11569 var C = CryptoJS; 11570 var C_x64 = C.x64; 11571 var X64Word = C_x64.Word; 11572 var X64WordArray = C_x64.WordArray; 11573 var C_algo = C.algo; 11574 var SHA512 = C_algo.SHA512; 11575 11576 /** 11577 * SHA-384 hash algorithm. 11578 */ 11579 var SHA384 = C_algo.SHA384 = SHA512.extend({ 11580 _doReset: function () { 11581 this._hash = new X64WordArray.init([ 11582 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 11583 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 11584 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 11585 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 11586 ]); 11587 }, 11588 11589 _doFinalize: function () { 11590 var hash = SHA512._doFinalize.call(this); 11591 11592 hash.sigBytes -= 16; 11593 11594 return hash; 11595 } 11596 }); 11597 11598 /** 11599 * Shortcut function to the hasher's object interface. 11600 * 11601 * @param {WordArray|string} message The message to hash. 11602 * 11603 * @return {WordArray} The hash. 11604 * 11605 * @static 11606 * 11607 * @example 11608 * 11609 * var hash = CryptoJS.SHA384('message'); 11610 * var hash = CryptoJS.SHA384(wordArray); 11611 */ 11612 C.SHA384 = SHA512._createHelper(SHA384); 11613 11614 /** 11615 * Shortcut function to the HMAC's object interface. 11616 * 11617 * @param {WordArray|string} message The message to hash. 11618 * @param {WordArray|string} key The secret key. 11619 * 11620 * @return {WordArray} The HMAC. 11621 * 11622 * @static 11623 * 11624 * @example 11625 * 11626 * var hmac = CryptoJS.HmacSHA384(message, key); 11627 */ 11628 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 11629 }()); 11630 11631 11632 return CryptoJS.SHA384; 11633 11634 })); 11635 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 11636 ;(function (root, factory, undef) { 11637 if (typeof exports === "object") { 11638 // CommonJS 11639 module.exports = exports = factory(require("./core"), require("./x64-core")); 11640 } 11641 else if (typeof define === "function" && define.amd) { 11642 // AMD 11643 define(["./core", "./x64-core"], factory); 11644 } 11645 else { 11646 // Global (browser) 11647 factory(root.CryptoJS); 11648 } 11649 }(this, function (CryptoJS) { 11650 11651 (function () { 11652 // Shortcuts 11653 var C = CryptoJS; 11654 var C_lib = C.lib; 11655 var Hasher = C_lib.Hasher; 11656 var C_x64 = C.x64; 11657 var X64Word = C_x64.Word; 11658 var X64WordArray = C_x64.WordArray; 11659 var C_algo = C.algo; 11660 11661 function X64Word_create() { 11662 return X64Word.create.apply(X64Word, arguments); 11663 } 11664 11665 // Constants 11666 var K = [ 11667 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 11668 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 11669 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 11670 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 11671 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 11672 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 11673 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 11674 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 11675 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 11676 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 11677 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 11678 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 11679 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 11680 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 11681 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 11682 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 11683 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 11684 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 11685 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 11686 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 11687 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 11688 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 11689 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 11690 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 11691 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 11692 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 11693 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 11694 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 11695 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 11696 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 11697 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 11698 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 11699 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 11700 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 11701 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 11702 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 11703 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 11704 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 11705 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 11706 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 11707 ]; 11708 11709 // Reusable objects 11710 var W = []; 11711 (function () { 11712 for (var i = 0; i < 80; i++) { 11713 W[i] = X64Word_create(); 11714 } 11715 }()); 11716 11717 /** 11718 * SHA-512 hash algorithm. 11719 */ 11720 var SHA512 = C_algo.SHA512 = Hasher.extend({ 11721 _doReset: function () { 11722 this._hash = new X64WordArray.init([ 11723 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 11724 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 11725 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 11726 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 11727 ]); 11728 }, 11729 11730 _doProcessBlock: function (M, offset) { 11731 // Shortcuts 11732 var H = this._hash.words; 11733 11734 var H0 = H[0]; 11735 var H1 = H[1]; 11736 var H2 = H[2]; 11737 var H3 = H[3]; 11738 var H4 = H[4]; 11739 var H5 = H[5]; 11740 var H6 = H[6]; 11741 var H7 = H[7]; 11742 11743 var H0h = H0.high; 11744 var H0l = H0.low; 11745 var H1h = H1.high; 11746 var H1l = H1.low; 11747 var H2h = H2.high; 11748 var H2l = H2.low; 11749 var H3h = H3.high; 11750 var H3l = H3.low; 11751 var H4h = H4.high; 11752 var H4l = H4.low; 11753 var H5h = H5.high; 11754 var H5l = H5.low; 11755 var H6h = H6.high; 11756 var H6l = H6.low; 11757 var H7h = H7.high; 11758 var H7l = H7.low; 11759 11760 // Working variables 11761 var ah = H0h; 11762 var al = H0l; 11763 var bh = H1h; 11764 var bl = H1l; 11765 var ch = H2h; 11766 var cl = H2l; 11767 var dh = H3h; 11768 var dl = H3l; 11769 var eh = H4h; 11770 var el = H4l; 11771 var fh = H5h; 11772 var fl = H5l; 11773 var gh = H6h; 11774 var gl = H6l; 11775 var hh = H7h; 11776 var hl = H7l; 11777 11778 // Rounds 11779 for (var i = 0; i < 80; i++) { 11780 // Shortcut 11781 var Wi = W[i]; 11782 11783 // Extend message 11784 if (i < 16) { 11785 var Wih = Wi.high = M[offset + i * 2] | 0; 11786 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 11787 } else { 11788 // Gamma0 11789 var gamma0x = W[i - 15]; 11790 var gamma0xh = gamma0x.high; 11791 var gamma0xl = gamma0x.low; 11792 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 11793 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 11794 11795 // Gamma1 11796 var gamma1x = W[i - 2]; 11797 var gamma1xh = gamma1x.high; 11798 var gamma1xl = gamma1x.low; 11799 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 11800 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 11801 11802 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 11803 var Wi7 = W[i - 7]; 11804 var Wi7h = Wi7.high; 11805 var Wi7l = Wi7.low; 11806 11807 var Wi16 = W[i - 16]; 11808 var Wi16h = Wi16.high; 11809 var Wi16l = Wi16.low; 11810 11811 var Wil = gamma0l + Wi7l; 11812 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 11813 var Wil = Wil + gamma1l; 11814 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 11815 var Wil = Wil + Wi16l; 11816 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 11817 11818 Wi.high = Wih; 11819 Wi.low = Wil; 11820 } 11821 11822 var chh = (eh & fh) ^ (~eh & gh); 11823 var chl = (el & fl) ^ (~el & gl); 11824 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 11825 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 11826 11827 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 11828 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 11829 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 11830 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 11831 11832 // t1 = h + sigma1 + ch + K[i] + W[i] 11833 var Ki = K[i]; 11834 var Kih = Ki.high; 11835 var Kil = Ki.low; 11836 11837 var t1l = hl + sigma1l; 11838 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 11839 var t1l = t1l + chl; 11840 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 11841 var t1l = t1l + Kil; 11842 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 11843 var t1l = t1l + Wil; 11844 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 11845 11846 // t2 = sigma0 + maj 11847 var t2l = sigma0l + majl; 11848 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 11849 11850 // Update working variables 11851 hh = gh; 11852 hl = gl; 11853 gh = fh; 11854 gl = fl; 11855 fh = eh; 11856 fl = el; 11857 el = (dl + t1l) | 0; 11858 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 11859 dh = ch; 11860 dl = cl; 11861 ch = bh; 11862 cl = bl; 11863 bh = ah; 11864 bl = al; 11865 al = (t1l + t2l) | 0; 11866 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 11867 } 11868 11869 // Intermediate hash value 11870 H0l = H0.low = (H0l + al); 11871 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 11872 H1l = H1.low = (H1l + bl); 11873 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 11874 H2l = H2.low = (H2l + cl); 11875 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 11876 H3l = H3.low = (H3l + dl); 11877 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 11878 H4l = H4.low = (H4l + el); 11879 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 11880 H5l = H5.low = (H5l + fl); 11881 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 11882 H6l = H6.low = (H6l + gl); 11883 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 11884 H7l = H7.low = (H7l + hl); 11885 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 11886 }, 11887 11888 _doFinalize: function () { 11889 // Shortcuts 11890 var data = this._data; 11891 var dataWords = data.words; 11892 11893 var nBitsTotal = this._nDataBytes * 8; 11894 var nBitsLeft = data.sigBytes * 8; 11895 11896 // Add padding 11897 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11898 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 11899 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 11900 data.sigBytes = dataWords.length * 4; 11901 11902 // Hash final blocks 11903 this._process(); 11904 11905 // Convert hash to 32-bit word array before returning 11906 var hash = this._hash.toX32(); 11907 11908 // Return final computed hash 11909 return hash; 11910 }, 11911 11912 clone: function () { 11913 var clone = Hasher.clone.call(this); 11914 clone._hash = this._hash.clone(); 11915 11916 return clone; 11917 }, 11918 11919 blockSize: 1024/32 11920 }); 11921 11922 /** 11923 * Shortcut function to the hasher's object interface. 11924 * 11925 * @param {WordArray|string} message The message to hash. 11926 * 11927 * @return {WordArray} The hash. 11928 * 11929 * @static 11930 * 11931 * @example 11932 * 11933 * var hash = CryptoJS.SHA512('message'); 11934 * var hash = CryptoJS.SHA512(wordArray); 11935 */ 11936 C.SHA512 = Hasher._createHelper(SHA512); 11937 11938 /** 11939 * Shortcut function to the HMAC's object interface. 11940 * 11941 * @param {WordArray|string} message The message to hash. 11942 * @param {WordArray|string} key The secret key. 11943 * 11944 * @return {WordArray} The HMAC. 11945 * 11946 * @static 11947 * 11948 * @example 11949 * 11950 * var hmac = CryptoJS.HmacSHA512(message, key); 11951 */ 11952 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 11953 }()); 11954 11955 11956 return CryptoJS.SHA512; 11957 11958 })); 11959 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 11960 ;(function (root, factory, undef) { 11961 if (typeof exports === "object") { 11962 // CommonJS 11963 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 11964 } 11965 else if (typeof define === "function" && define.amd) { 11966 // AMD 11967 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 11968 } 11969 else { 11970 // Global (browser) 11971 factory(root.CryptoJS); 11972 } 11973 }(this, function (CryptoJS) { 11974 11975 (function () { 11976 // Shortcuts 11977 var C = CryptoJS; 11978 var C_lib = C.lib; 11979 var WordArray = C_lib.WordArray; 11980 var BlockCipher = C_lib.BlockCipher; 11981 var C_algo = C.algo; 11982 11983 // Permuted Choice 1 constants 11984 var PC1 = [ 11985 57, 49, 41, 33, 25, 17, 9, 1, 11986 58, 50, 42, 34, 26, 18, 10, 2, 11987 59, 51, 43, 35, 27, 19, 11, 3, 11988 60, 52, 44, 36, 63, 55, 47, 39, 11989 31, 23, 15, 7, 62, 54, 46, 38, 11990 30, 22, 14, 6, 61, 53, 45, 37, 11991 29, 21, 13, 5, 28, 20, 12, 4 11992 ]; 11993 11994 // Permuted Choice 2 constants 11995 var PC2 = [ 11996 14, 17, 11, 24, 1, 5, 11997 3, 28, 15, 6, 21, 10, 11998 23, 19, 12, 4, 26, 8, 11999 16, 7, 27, 20, 13, 2, 12000 41, 52, 31, 37, 47, 55, 12001 30, 40, 51, 45, 33, 48, 12002 44, 49, 39, 56, 34, 53, 12003 46, 42, 50, 36, 29, 32 12004 ]; 12005 12006 // Cumulative bit shift constants 12007 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12008 12009 // SBOXes and round permutation constants 12010 var SBOX_P = [ 12011 { 12012 0x0: 0x808200, 12013 0x10000000: 0x8000, 12014 0x20000000: 0x808002, 12015 0x30000000: 0x2, 12016 0x40000000: 0x200, 12017 0x50000000: 0x808202, 12018 0x60000000: 0x800202, 12019 0x70000000: 0x800000, 12020 0x80000000: 0x202, 12021 0x90000000: 0x800200, 12022 0xa0000000: 0x8200, 12023 0xb0000000: 0x808000, 12024 0xc0000000: 0x8002, 12025 0xd0000000: 0x800002, 12026 0xe0000000: 0x0, 12027 0xf0000000: 0x8202, 12028 0x8000000: 0x0, 12029 0x18000000: 0x808202, 12030 0x28000000: 0x8202, 12031 0x38000000: 0x8000, 12032 0x48000000: 0x808200, 12033 0x58000000: 0x200, 12034 0x68000000: 0x808002, 12035 0x78000000: 0x2, 12036 0x88000000: 0x800200, 12037 0x98000000: 0x8200, 12038 0xa8000000: 0x808000, 12039 0xb8000000: 0x800202, 12040 0xc8000000: 0x800002, 12041 0xd8000000: 0x8002, 12042 0xe8000000: 0x202, 12043 0xf8000000: 0x800000, 12044 0x1: 0x8000, 12045 0x10000001: 0x2, 12046 0x20000001: 0x808200, 12047 0x30000001: 0x800000, 12048 0x40000001: 0x808002, 12049 0x50000001: 0x8200, 12050 0x60000001: 0x200, 12051 0x70000001: 0x800202, 12052 0x80000001: 0x808202, 12053 0x90000001: 0x808000, 12054 0xa0000001: 0x800002, 12055 0xb0000001: 0x8202, 12056 0xc0000001: 0x202, 12057 0xd0000001: 0x800200, 12058 0xe0000001: 0x8002, 12059 0xf0000001: 0x0, 12060 0x8000001: 0x808202, 12061 0x18000001: 0x808000, 12062 0x28000001: 0x800000, 12063 0x38000001: 0x200, 12064 0x48000001: 0x8000, 12065 0x58000001: 0x800002, 12066 0x68000001: 0x2, 12067 0x78000001: 0x8202, 12068 0x88000001: 0x8002, 12069 0x98000001: 0x800202, 12070 0xa8000001: 0x202, 12071 0xb8000001: 0x808200, 12072 0xc8000001: 0x800200, 12073 0xd8000001: 0x0, 12074 0xe8000001: 0x8200, 12075 0xf8000001: 0x808002 12076 }, 12077 { 12078 0x0: 0x40084010, 12079 0x1000000: 0x4000, 12080 0x2000000: 0x80000, 12081 0x3000000: 0x40080010, 12082 0x4000000: 0x40000010, 12083 0x5000000: 0x40084000, 12084 0x6000000: 0x40004000, 12085 0x7000000: 0x10, 12086 0x8000000: 0x84000, 12087 0x9000000: 0x40004010, 12088 0xa000000: 0x40000000, 12089 0xb000000: 0x84010, 12090 0xc000000: 0x80010, 12091 0xd000000: 0x0, 12092 0xe000000: 0x4010, 12093 0xf000000: 0x40080000, 12094 0x800000: 0x40004000, 12095 0x1800000: 0x84010, 12096 0x2800000: 0x10, 12097 0x3800000: 0x40004010, 12098 0x4800000: 0x40084010, 12099 0x5800000: 0x40000000, 12100 0x6800000: 0x80000, 12101 0x7800000: 0x40080010, 12102 0x8800000: 0x80010, 12103 0x9800000: 0x0, 12104 0xa800000: 0x4000, 12105 0xb800000: 0x40080000, 12106 0xc800000: 0x40000010, 12107 0xd800000: 0x84000, 12108 0xe800000: 0x40084000, 12109 0xf800000: 0x4010, 12110 0x10000000: 0x0, 12111 0x11000000: 0x40080010, 12112 0x12000000: 0x40004010, 12113 0x13000000: 0x40084000, 12114 0x14000000: 0x40080000, 12115 0x15000000: 0x10, 12116 0x16000000: 0x84010, 12117 0x17000000: 0x4000, 12118 0x18000000: 0x4010, 12119 0x19000000: 0x80000, 12120 0x1a000000: 0x80010, 12121 0x1b000000: 0x40000010, 12122 0x1c000000: 0x84000, 12123 0x1d000000: 0x40004000, 12124 0x1e000000: 0x40000000, 12125 0x1f000000: 0x40084010, 12126 0x10800000: 0x84010, 12127 0x11800000: 0x80000, 12128 0x12800000: 0x40080000, 12129 0x13800000: 0x4000, 12130 0x14800000: 0x40004000, 12131 0x15800000: 0x40084010, 12132 0x16800000: 0x10, 12133 0x17800000: 0x40000000, 12134 0x18800000: 0x40084000, 12135 0x19800000: 0x40000010, 12136 0x1a800000: 0x40004010, 12137 0x1b800000: 0x80010, 12138 0x1c800000: 0x0, 12139 0x1d800000: 0x4010, 12140 0x1e800000: 0x40080010, 12141 0x1f800000: 0x84000 12142 }, 12143 { 12144 0x0: 0x104, 12145 0x100000: 0x0, 12146 0x200000: 0x4000100, 12147 0x300000: 0x10104, 12148 0x400000: 0x10004, 12149 0x500000: 0x4000004, 12150 0x600000: 0x4010104, 12151 0x700000: 0x4010000, 12152 0x800000: 0x4000000, 12153 0x900000: 0x4010100, 12154 0xa00000: 0x10100, 12155 0xb00000: 0x4010004, 12156 0xc00000: 0x4000104, 12157 0xd00000: 0x10000, 12158 0xe00000: 0x4, 12159 0xf00000: 0x100, 12160 0x80000: 0x4010100, 12161 0x180000: 0x4010004, 12162 0x280000: 0x0, 12163 0x380000: 0x4000100, 12164 0x480000: 0x4000004, 12165 0x580000: 0x10000, 12166 0x680000: 0x10004, 12167 0x780000: 0x104, 12168 0x880000: 0x4, 12169 0x980000: 0x100, 12170 0xa80000: 0x4010000, 12171 0xb80000: 0x10104, 12172 0xc80000: 0x10100, 12173 0xd80000: 0x4000104, 12174 0xe80000: 0x4010104, 12175 0xf80000: 0x4000000, 12176 0x1000000: 0x4010100, 12177 0x1100000: 0x10004, 12178 0x1200000: 0x10000, 12179 0x1300000: 0x4000100, 12180 0x1400000: 0x100, 12181 0x1500000: 0x4010104, 12182 0x1600000: 0x4000004, 12183 0x1700000: 0x0, 12184 0x1800000: 0x4000104, 12185 0x1900000: 0x4000000, 12186 0x1a00000: 0x4, 12187 0x1b00000: 0x10100, 12188 0x1c00000: 0x4010000, 12189 0x1d00000: 0x104, 12190 0x1e00000: 0x10104, 12191 0x1f00000: 0x4010004, 12192 0x1080000: 0x4000000, 12193 0x1180000: 0x104, 12194 0x1280000: 0x4010100, 12195 0x1380000: 0x0, 12196 0x1480000: 0x10004, 12197 0x1580000: 0x4000100, 12198 0x1680000: 0x100, 12199 0x1780000: 0x4010004, 12200 0x1880000: 0x10000, 12201 0x1980000: 0x4010104, 12202 0x1a80000: 0x10104, 12203 0x1b80000: 0x4000004, 12204 0x1c80000: 0x4000104, 12205 0x1d80000: 0x4010000, 12206 0x1e80000: 0x4, 12207 0x1f80000: 0x10100 12208 }, 12209 { 12210 0x0: 0x80401000, 12211 0x10000: 0x80001040, 12212 0x20000: 0x401040, 12213 0x30000: 0x80400000, 12214 0x40000: 0x0, 12215 0x50000: 0x401000, 12216 0x60000: 0x80000040, 12217 0x70000: 0x400040, 12218 0x80000: 0x80000000, 12219 0x90000: 0x400000, 12220 0xa0000: 0x40, 12221 0xb0000: 0x80001000, 12222 0xc0000: 0x80400040, 12223 0xd0000: 0x1040, 12224 0xe0000: 0x1000, 12225 0xf0000: 0x80401040, 12226 0x8000: 0x80001040, 12227 0x18000: 0x40, 12228 0x28000: 0x80400040, 12229 0x38000: 0x80001000, 12230 0x48000: 0x401000, 12231 0x58000: 0x80401040, 12232 0x68000: 0x0, 12233 0x78000: 0x80400000, 12234 0x88000: 0x1000, 12235 0x98000: 0x80401000, 12236 0xa8000: 0x400000, 12237 0xb8000: 0x1040, 12238 0xc8000: 0x80000000, 12239 0xd8000: 0x400040, 12240 0xe8000: 0x401040, 12241 0xf8000: 0x80000040, 12242 0x100000: 0x400040, 12243 0x110000: 0x401000, 12244 0x120000: 0x80000040, 12245 0x130000: 0x0, 12246 0x140000: 0x1040, 12247 0x150000: 0x80400040, 12248 0x160000: 0x80401000, 12249 0x170000: 0x80001040, 12250 0x180000: 0x80401040, 12251 0x190000: 0x80000000, 12252 0x1a0000: 0x80400000, 12253 0x1b0000: 0x401040, 12254 0x1c0000: 0x80001000, 12255 0x1d0000: 0x400000, 12256 0x1e0000: 0x40, 12257 0x1f0000: 0x1000, 12258 0x108000: 0x80400000, 12259 0x118000: 0x80401040, 12260 0x128000: 0x0, 12261 0x138000: 0x401000, 12262 0x148000: 0x400040, 12263 0x158000: 0x80000000, 12264 0x168000: 0x80001040, 12265 0x178000: 0x40, 12266 0x188000: 0x80000040, 12267 0x198000: 0x1000, 12268 0x1a8000: 0x80001000, 12269 0x1b8000: 0x80400040, 12270 0x1c8000: 0x1040, 12271 0x1d8000: 0x80401000, 12272 0x1e8000: 0x400000, 12273 0x1f8000: 0x401040 12274 }, 12275 { 12276 0x0: 0x80, 12277 0x1000: 0x1040000, 12278 0x2000: 0x40000, 12279 0x3000: 0x20000000, 12280 0x4000: 0x20040080, 12281 0x5000: 0x1000080, 12282 0x6000: 0x21000080, 12283 0x7000: 0x40080, 12284 0x8000: 0x1000000, 12285 0x9000: 0x20040000, 12286 0xa000: 0x20000080, 12287 0xb000: 0x21040080, 12288 0xc000: 0x21040000, 12289 0xd000: 0x0, 12290 0xe000: 0x1040080, 12291 0xf000: 0x21000000, 12292 0x800: 0x1040080, 12293 0x1800: 0x21000080, 12294 0x2800: 0x80, 12295 0x3800: 0x1040000, 12296 0x4800: 0x40000, 12297 0x5800: 0x20040080, 12298 0x6800: 0x21040000, 12299 0x7800: 0x20000000, 12300 0x8800: 0x20040000, 12301 0x9800: 0x0, 12302 0xa800: 0x21040080, 12303 0xb800: 0x1000080, 12304 0xc800: 0x20000080, 12305 0xd800: 0x21000000, 12306 0xe800: 0x1000000, 12307 0xf800: 0x40080, 12308 0x10000: 0x40000, 12309 0x11000: 0x80, 12310 0x12000: 0x20000000, 12311 0x13000: 0x21000080, 12312 0x14000: 0x1000080, 12313 0x15000: 0x21040000, 12314 0x16000: 0x20040080, 12315 0x17000: 0x1000000, 12316 0x18000: 0x21040080, 12317 0x19000: 0x21000000, 12318 0x1a000: 0x1040000, 12319 0x1b000: 0x20040000, 12320 0x1c000: 0x40080, 12321 0x1d000: 0x20000080, 12322 0x1e000: 0x0, 12323 0x1f000: 0x1040080, 12324 0x10800: 0x21000080, 12325 0x11800: 0x1000000, 12326 0x12800: 0x1040000, 12327 0x13800: 0x20040080, 12328 0x14800: 0x20000000, 12329 0x15800: 0x1040080, 12330 0x16800: 0x80, 12331 0x17800: 0x21040000, 12332 0x18800: 0x40080, 12333 0x19800: 0x21040080, 12334 0x1a800: 0x0, 12335 0x1b800: 0x21000000, 12336 0x1c800: 0x1000080, 12337 0x1d800: 0x40000, 12338 0x1e800: 0x20040000, 12339 0x1f800: 0x20000080 12340 }, 12341 { 12342 0x0: 0x10000008, 12343 0x100: 0x2000, 12344 0x200: 0x10200000, 12345 0x300: 0x10202008, 12346 0x400: 0x10002000, 12347 0x500: 0x200000, 12348 0x600: 0x200008, 12349 0x700: 0x10000000, 12350 0x800: 0x0, 12351 0x900: 0x10002008, 12352 0xa00: 0x202000, 12353 0xb00: 0x8, 12354 0xc00: 0x10200008, 12355 0xd00: 0x202008, 12356 0xe00: 0x2008, 12357 0xf00: 0x10202000, 12358 0x80: 0x10200000, 12359 0x180: 0x10202008, 12360 0x280: 0x8, 12361 0x380: 0x200000, 12362 0x480: 0x202008, 12363 0x580: 0x10000008, 12364 0x680: 0x10002000, 12365 0x780: 0x2008, 12366 0x880: 0x200008, 12367 0x980: 0x2000, 12368 0xa80: 0x10002008, 12369 0xb80: 0x10200008, 12370 0xc80: 0x0, 12371 0xd80: 0x10202000, 12372 0xe80: 0x202000, 12373 0xf80: 0x10000000, 12374 0x1000: 0x10002000, 12375 0x1100: 0x10200008, 12376 0x1200: 0x10202008, 12377 0x1300: 0x2008, 12378 0x1400: 0x200000, 12379 0x1500: 0x10000000, 12380 0x1600: 0x10000008, 12381 0x1700: 0x202000, 12382 0x1800: 0x202008, 12383 0x1900: 0x0, 12384 0x1a00: 0x8, 12385 0x1b00: 0x10200000, 12386 0x1c00: 0x2000, 12387 0x1d00: 0x10002008, 12388 0x1e00: 0x10202000, 12389 0x1f00: 0x200008, 12390 0x1080: 0x8, 12391 0x1180: 0x202000, 12392 0x1280: 0x200000, 12393 0x1380: 0x10000008, 12394 0x1480: 0x10002000, 12395 0x1580: 0x2008, 12396 0x1680: 0x10202008, 12397 0x1780: 0x10200000, 12398 0x1880: 0x10202000, 12399 0x1980: 0x10200008, 12400 0x1a80: 0x2000, 12401 0x1b80: 0x202008, 12402 0x1c80: 0x200008, 12403 0x1d80: 0x0, 12404 0x1e80: 0x10000000, 12405 0x1f80: 0x10002008 12406 }, 12407 { 12408 0x0: 0x100000, 12409 0x10: 0x2000401, 12410 0x20: 0x400, 12411 0x30: 0x100401, 12412 0x40: 0x2100401, 12413 0x50: 0x0, 12414 0x60: 0x1, 12415 0x70: 0x2100001, 12416 0x80: 0x2000400, 12417 0x90: 0x100001, 12418 0xa0: 0x2000001, 12419 0xb0: 0x2100400, 12420 0xc0: 0x2100000, 12421 0xd0: 0x401, 12422 0xe0: 0x100400, 12423 0xf0: 0x2000000, 12424 0x8: 0x2100001, 12425 0x18: 0x0, 12426 0x28: 0x2000401, 12427 0x38: 0x2100400, 12428 0x48: 0x100000, 12429 0x58: 0x2000001, 12430 0x68: 0x2000000, 12431 0x78: 0x401, 12432 0x88: 0x100401, 12433 0x98: 0x2000400, 12434 0xa8: 0x2100000, 12435 0xb8: 0x100001, 12436 0xc8: 0x400, 12437 0xd8: 0x2100401, 12438 0xe8: 0x1, 12439 0xf8: 0x100400, 12440 0x100: 0x2000000, 12441 0x110: 0x100000, 12442 0x120: 0x2000401, 12443 0x130: 0x2100001, 12444 0x140: 0x100001, 12445 0x150: 0x2000400, 12446 0x160: 0x2100400, 12447 0x170: 0x100401, 12448 0x180: 0x401, 12449 0x190: 0x2100401, 12450 0x1a0: 0x100400, 12451 0x1b0: 0x1, 12452 0x1c0: 0x0, 12453 0x1d0: 0x2100000, 12454 0x1e0: 0x2000001, 12455 0x1f0: 0x400, 12456 0x108: 0x100400, 12457 0x118: 0x2000401, 12458 0x128: 0x2100001, 12459 0x138: 0x1, 12460 0x148: 0x2000000, 12461 0x158: 0x100000, 12462 0x168: 0x401, 12463 0x178: 0x2100400, 12464 0x188: 0x2000001, 12465 0x198: 0x2100000, 12466 0x1a8: 0x0, 12467 0x1b8: 0x2100401, 12468 0x1c8: 0x100401, 12469 0x1d8: 0x400, 12470 0x1e8: 0x2000400, 12471 0x1f8: 0x100001 12472 }, 12473 { 12474 0x0: 0x8000820, 12475 0x1: 0x20000, 12476 0x2: 0x8000000, 12477 0x3: 0x20, 12478 0x4: 0x20020, 12479 0x5: 0x8020820, 12480 0x6: 0x8020800, 12481 0x7: 0x800, 12482 0x8: 0x8020000, 12483 0x9: 0x8000800, 12484 0xa: 0x20800, 12485 0xb: 0x8020020, 12486 0xc: 0x820, 12487 0xd: 0x0, 12488 0xe: 0x8000020, 12489 0xf: 0x20820, 12490 0x80000000: 0x800, 12491 0x80000001: 0x8020820, 12492 0x80000002: 0x8000820, 12493 0x80000003: 0x8000000, 12494 0x80000004: 0x8020000, 12495 0x80000005: 0x20800, 12496 0x80000006: 0x20820, 12497 0x80000007: 0x20, 12498 0x80000008: 0x8000020, 12499 0x80000009: 0x820, 12500 0x8000000a: 0x20020, 12501 0x8000000b: 0x8020800, 12502 0x8000000c: 0x0, 12503 0x8000000d: 0x8020020, 12504 0x8000000e: 0x8000800, 12505 0x8000000f: 0x20000, 12506 0x10: 0x20820, 12507 0x11: 0x8020800, 12508 0x12: 0x20, 12509 0x13: 0x800, 12510 0x14: 0x8000800, 12511 0x15: 0x8000020, 12512 0x16: 0x8020020, 12513 0x17: 0x20000, 12514 0x18: 0x0, 12515 0x19: 0x20020, 12516 0x1a: 0x8020000, 12517 0x1b: 0x8000820, 12518 0x1c: 0x8020820, 12519 0x1d: 0x20800, 12520 0x1e: 0x820, 12521 0x1f: 0x8000000, 12522 0x80000010: 0x20000, 12523 0x80000011: 0x800, 12524 0x80000012: 0x8020020, 12525 0x80000013: 0x20820, 12526 0x80000014: 0x20, 12527 0x80000015: 0x8020000, 12528 0x80000016: 0x8000000, 12529 0x80000017: 0x8000820, 12530 0x80000018: 0x8020820, 12531 0x80000019: 0x8000020, 12532 0x8000001a: 0x8000800, 12533 0x8000001b: 0x0, 12534 0x8000001c: 0x20800, 12535 0x8000001d: 0x820, 12536 0x8000001e: 0x20020, 12537 0x8000001f: 0x8020800 12538 } 12539 ]; 12540 12541 // Masks that select the SBOX input 12542 var SBOX_MASK = [ 12543 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 12544 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 12545 ]; 12546 12547 /** 12548 * DES block cipher algorithm. 12549 */ 12550 var DES = C_algo.DES = BlockCipher.extend({ 12551 _doReset: function () { 12552 // Shortcuts 12553 var key = this._key; 12554 var keyWords = key.words; 12555 12556 // Select 56 bits according to PC1 12557 var keyBits = []; 12558 for (var i = 0; i < 56; i++) { 12559 var keyBitPos = PC1[i] - 1; 12560 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 12561 } 12562 12563 // Assemble 16 subkeys 12564 var subKeys = this._subKeys = []; 12565 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 12566 // Create subkey 12567 var subKey = subKeys[nSubKey] = []; 12568 12569 // Shortcut 12570 var bitShift = BIT_SHIFTS[nSubKey]; 12571 12572 // Select 48 bits according to PC2 12573 for (var i = 0; i < 24; i++) { 12574 // Select from the left 28 key bits 12575 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 12576 12577 // Select from the right 28 key bits 12578 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 12579 } 12580 12581 // Since each subkey is applied to an expanded 32-bit input, 12582 // the subkey can be broken into 8 values scaled to 32-bits, 12583 // which allows the key to be used without expansion 12584 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 12585 for (var i = 1; i < 7; i++) { 12586 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 12587 } 12588 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 12589 } 12590 12591 // Compute inverse subkeys 12592 var invSubKeys = this._invSubKeys = []; 12593 for (var i = 0; i < 16; i++) { 12594 invSubKeys[i] = subKeys[15 - i]; 12595 } 12596 }, 12597 12598 encryptBlock: function (M, offset) { 12599 this._doCryptBlock(M, offset, this._subKeys); 12600 }, 12601 12602 decryptBlock: function (M, offset) { 12603 this._doCryptBlock(M, offset, this._invSubKeys); 12604 }, 12605 12606 _doCryptBlock: function (M, offset, subKeys) { 12607 // Get input 12608 this._lBlock = M[offset]; 12609 this._rBlock = M[offset + 1]; 12610 12611 // Initial permutation 12612 exchangeLR.call(this, 4, 0x0f0f0f0f); 12613 exchangeLR.call(this, 16, 0x0000ffff); 12614 exchangeRL.call(this, 2, 0x33333333); 12615 exchangeRL.call(this, 8, 0x00ff00ff); 12616 exchangeLR.call(this, 1, 0x55555555); 12617 12618 // Rounds 12619 for (var round = 0; round < 16; round++) { 12620 // Shortcuts 12621 var subKey = subKeys[round]; 12622 var lBlock = this._lBlock; 12623 var rBlock = this._rBlock; 12624 12625 // Feistel function 12626 var f = 0; 12627 for (var i = 0; i < 8; i++) { 12628 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 12629 } 12630 this._lBlock = rBlock; 12631 this._rBlock = lBlock ^ f; 12632 } 12633 12634 // Undo swap from last round 12635 var t = this._lBlock; 12636 this._lBlock = this._rBlock; 12637 this._rBlock = t; 12638 12639 // Final permutation 12640 exchangeLR.call(this, 1, 0x55555555); 12641 exchangeRL.call(this, 8, 0x00ff00ff); 12642 exchangeRL.call(this, 2, 0x33333333); 12643 exchangeLR.call(this, 16, 0x0000ffff); 12644 exchangeLR.call(this, 4, 0x0f0f0f0f); 12645 12646 // Set output 12647 M[offset] = this._lBlock; 12648 M[offset + 1] = this._rBlock; 12649 }, 12650 12651 keySize: 64/32, 12652 12653 ivSize: 64/32, 12654 12655 blockSize: 64/32 12656 }); 12657 12658 // Swap bits across the left and right words 12659 function exchangeLR(offset, mask) { 12660 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 12661 this._rBlock ^= t; 12662 this._lBlock ^= t << offset; 12663 } 12664 12665 function exchangeRL(offset, mask) { 12666 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 12667 this._lBlock ^= t; 12668 this._rBlock ^= t << offset; 12669 } 12670 12671 /** 12672 * Shortcut functions to the cipher's object interface. 12673 * 12674 * @example 12675 * 12676 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 12677 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 12678 */ 12679 C.DES = BlockCipher._createHelper(DES); 12680 12681 /** 12682 * Triple-DES block cipher algorithm. 12683 */ 12684 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 12685 _doReset: function () { 12686 // Shortcuts 12687 var key = this._key; 12688 var keyWords = key.words; 12689 12690 // Create DES instances 12691 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 12692 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 12693 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 12694 }, 12695 12696 encryptBlock: function (M, offset) { 12697 this._des1.encryptBlock(M, offset); 12698 this._des2.decryptBlock(M, offset); 12699 this._des3.encryptBlock(M, offset); 12700 }, 12701 12702 decryptBlock: function (M, offset) { 12703 this._des3.decryptBlock(M, offset); 12704 this._des2.encryptBlock(M, offset); 12705 this._des1.decryptBlock(M, offset); 12706 }, 12707 12708 keySize: 192/32, 12709 12710 ivSize: 64/32, 12711 12712 blockSize: 64/32 12713 }); 12714 12715 /** 12716 * Shortcut functions to the cipher's object interface. 12717 * 12718 * @example 12719 * 12720 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 12721 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 12722 */ 12723 C.TripleDES = BlockCipher._createHelper(TripleDES); 12724 }()); 12725 12726 12727 return CryptoJS.TripleDES; 12728 12729 })); 12730 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 12731 ;(function (root, factory) { 12732 if (typeof exports === "object") { 12733 // CommonJS 12734 module.exports = exports = factory(require("./core")); 12735 } 12736 else if (typeof define === "function" && define.amd) { 12737 // AMD 12738 define(["./core"], factory); 12739 } 12740 else { 12741 // Global (browser) 12742 factory(root.CryptoJS); 12743 } 12744 }(this, function (CryptoJS) { 12745 12746 (function (undefined) { 12747 // Shortcuts 12748 var C = CryptoJS; 12749 var C_lib = C.lib; 12750 var Base = C_lib.Base; 12751 var X32WordArray = C_lib.WordArray; 12752 12753 /** 12754 * x64 namespace. 12755 */ 12756 var C_x64 = C.x64 = {}; 12757 12758 /** 12759 * A 64-bit word. 12760 */ 12761 var X64Word = C_x64.Word = Base.extend({ 12762 /** 12763 * Initializes a newly created 64-bit word. 12764 * 12765 * @param {number} high The high 32 bits. 12766 * @param {number} low The low 32 bits. 12767 * 12768 * @example 12769 * 12770 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 12771 */ 12772 init: function (high, low) { 12773 this.high = high; 12774 this.low = low; 12775 } 12776 12777 /** 12778 * Bitwise NOTs this word. 12779 * 12780 * @return {X64Word} A new x64-Word object after negating. 12781 * 12782 * @example 12783 * 12784 * var negated = x64Word.not(); 12785 */ 12786 // not: function () { 12787 // var high = ~this.high; 12788 // var low = ~this.low; 12789 12790 // return X64Word.create(high, low); 12791 // }, 12792 12793 /** 12794 * Bitwise ANDs this word with the passed word. 12795 * 12796 * @param {X64Word} word The x64-Word to AND with this word. 12797 * 12798 * @return {X64Word} A new x64-Word object after ANDing. 12799 * 12800 * @example 12801 * 12802 * var anded = x64Word.and(anotherX64Word); 12803 */ 12804 // and: function (word) { 12805 // var high = this.high & word.high; 12806 // var low = this.low & word.low; 12807 12808 // return X64Word.create(high, low); 12809 // }, 12810 12811 /** 12812 * Bitwise ORs this word with the passed word. 12813 * 12814 * @param {X64Word} word The x64-Word to OR with this word. 12815 * 12816 * @return {X64Word} A new x64-Word object after ORing. 12817 * 12818 * @example 12819 * 12820 * var ored = x64Word.or(anotherX64Word); 12821 */ 12822 // or: function (word) { 12823 // var high = this.high | word.high; 12824 // var low = this.low | word.low; 12825 12826 // return X64Word.create(high, low); 12827 // }, 12828 12829 /** 12830 * Bitwise XORs this word with the passed word. 12831 * 12832 * @param {X64Word} word The x64-Word to XOR with this word. 12833 * 12834 * @return {X64Word} A new x64-Word object after XORing. 12835 * 12836 * @example 12837 * 12838 * var xored = x64Word.xor(anotherX64Word); 12839 */ 12840 // xor: function (word) { 12841 // var high = this.high ^ word.high; 12842 // var low = this.low ^ word.low; 12843 12844 // return X64Word.create(high, low); 12845 // }, 12846 12847 /** 12848 * Shifts this word n bits to the left. 12849 * 12850 * @param {number} n The number of bits to shift. 12851 * 12852 * @return {X64Word} A new x64-Word object after shifting. 12853 * 12854 * @example 12855 * 12856 * var shifted = x64Word.shiftL(25); 12857 */ 12858 // shiftL: function (n) { 12859 // if (n < 32) { 12860 // var high = (this.high << n) | (this.low >>> (32 - n)); 12861 // var low = this.low << n; 12862 // } else { 12863 // var high = this.low << (n - 32); 12864 // var low = 0; 12865 // } 12866 12867 // return X64Word.create(high, low); 12868 // }, 12869 12870 /** 12871 * Shifts this word n bits to the right. 12872 * 12873 * @param {number} n The number of bits to shift. 12874 * 12875 * @return {X64Word} A new x64-Word object after shifting. 12876 * 12877 * @example 12878 * 12879 * var shifted = x64Word.shiftR(7); 12880 */ 12881 // shiftR: function (n) { 12882 // if (n < 32) { 12883 // var low = (this.low >>> n) | (this.high << (32 - n)); 12884 // var high = this.high >>> n; 12885 // } else { 12886 // var low = this.high >>> (n - 32); 12887 // var high = 0; 12888 // } 12889 12890 // return X64Word.create(high, low); 12891 // }, 12892 12893 /** 12894 * Rotates this word n bits to the left. 12895 * 12896 * @param {number} n The number of bits to rotate. 12897 * 12898 * @return {X64Word} A new x64-Word object after rotating. 12899 * 12900 * @example 12901 * 12902 * var rotated = x64Word.rotL(25); 12903 */ 12904 // rotL: function (n) { 12905 // return this.shiftL(n).or(this.shiftR(64 - n)); 12906 // }, 12907 12908 /** 12909 * Rotates this word n bits to the right. 12910 * 12911 * @param {number} n The number of bits to rotate. 12912 * 12913 * @return {X64Word} A new x64-Word object after rotating. 12914 * 12915 * @example 12916 * 12917 * var rotated = x64Word.rotR(7); 12918 */ 12919 // rotR: function (n) { 12920 // return this.shiftR(n).or(this.shiftL(64 - n)); 12921 // }, 12922 12923 /** 12924 * Adds this word with the passed word. 12925 * 12926 * @param {X64Word} word The x64-Word to add with this word. 12927 * 12928 * @return {X64Word} A new x64-Word object after adding. 12929 * 12930 * @example 12931 * 12932 * var added = x64Word.add(anotherX64Word); 12933 */ 12934 // add: function (word) { 12935 // var low = (this.low + word.low) | 0; 12936 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 12937 // var high = (this.high + word.high + carry) | 0; 12938 12939 // return X64Word.create(high, low); 12940 // } 12941 }); 12942 12943 /** 12944 * An array of 64-bit words. 12945 * 12946 * @property {Array} words The array of CryptoJS.x64.Word objects. 12947 * @property {number} sigBytes The number of significant bytes in this word array. 12948 */ 12949 var X64WordArray = C_x64.WordArray = Base.extend({ 12950 /** 12951 * Initializes a newly created word array. 12952 * 12953 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 12954 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 12955 * 12956 * @example 12957 * 12958 * var wordArray = CryptoJS.x64.WordArray.create(); 12959 * 12960 * var wordArray = CryptoJS.x64.WordArray.create([ 12961 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 12962 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 12963 * ]); 12964 * 12965 * var wordArray = CryptoJS.x64.WordArray.create([ 12966 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 12967 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 12968 * ], 10); 12969 */ 12970 init: function (words, sigBytes) { 12971 words = this.words = words || []; 12972 12973 if (sigBytes != undefined) { 12974 this.sigBytes = sigBytes; 12975 } else { 12976 this.sigBytes = words.length * 8; 12977 } 12978 }, 12979 12980 /** 12981 * Converts this 64-bit word array to a 32-bit word array. 12982 * 12983 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 12984 * 12985 * @example 12986 * 12987 * var x32WordArray = x64WordArray.toX32(); 12988 */ 12989 toX32: function () { 12990 // Shortcuts 12991 var x64Words = this.words; 12992 var x64WordsLength = x64Words.length; 12993 12994 // Convert 12995 var x32Words = []; 12996 for (var i = 0; i < x64WordsLength; i++) { 12997 var x64Word = x64Words[i]; 12998 x32Words.push(x64Word.high); 12999 x32Words.push(x64Word.low); 13000 } 13001 13002 return X32WordArray.create(x32Words, this.sigBytes); 13003 }, 13004 13005 /** 13006 * Creates a copy of this word array. 13007 * 13008 * @return {X64WordArray} The clone. 13009 * 13010 * @example 13011 * 13012 * var clone = x64WordArray.clone(); 13013 */ 13014 clone: function () { 13015 var clone = Base.clone.call(this); 13016 13017 // Clone "words" array 13018 var words = clone.words = this.words.slice(0); 13019 13020 // Clone each X64Word object 13021 var wordsLength = words.length; 13022 for (var i = 0; i < wordsLength; i++) { 13023 words[i] = words[i].clone(); 13024 } 13025 13026 return clone; 13027 } 13028 }); 13029 }()); 13030 13031 13032 return CryptoJS; 13033 13034 })); 13035 },{"./core":53}],85:[function(require,module,exports){ 13036 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13037 ;(function(root) { 13038 13039 // Detect free variables `exports` 13040 var freeExports = typeof exports == 'object' && exports; 13041 13042 // Detect free variable `module` 13043 var freeModule = typeof module == 'object' && module && 13044 module.exports == freeExports && module; 13045 13046 // Detect free variable `global`, from Node.js or Browserified code, 13047 // and use it as `root` 13048 var freeGlobal = typeof global == 'object' && global; 13049 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13050 root = freeGlobal; 13051 } 13052 13053 /*--------------------------------------------------------------------------*/ 13054 13055 var stringFromCharCode = String.fromCharCode; 13056 13057 // Taken from https://mths.be/punycode 13058 function ucs2decode(string) { 13059 var output = []; 13060 var counter = 0; 13061 var length = string.length; 13062 var value; 13063 var extra; 13064 while (counter < length) { 13065 value = string.charCodeAt(counter++); 13066 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13067 // high surrogate, and there is a next character 13068 extra = string.charCodeAt(counter++); 13069 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13070 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13071 } else { 13072 // unmatched surrogate; only append this code unit, in case the next 13073 // code unit is the high surrogate of a surrogate pair 13074 output.push(value); 13075 counter--; 13076 } 13077 } else { 13078 output.push(value); 13079 } 13080 } 13081 return output; 13082 } 13083 13084 // Taken from https://mths.be/punycode 13085 function ucs2encode(array) { 13086 var length = array.length; 13087 var index = -1; 13088 var value; 13089 var output = ''; 13090 while (++index < length) { 13091 value = array[index]; 13092 if (value > 0xFFFF) { 13093 value -= 0x10000; 13094 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13095 value = 0xDC00 | value & 0x3FF; 13096 } 13097 output += stringFromCharCode(value); 13098 } 13099 return output; 13100 } 13101 13102 function checkScalarValue(codePoint) { 13103 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13104 throw Error( 13105 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13106 ' is not a scalar value' 13107 ); 13108 } 13109 } 13110 /*--------------------------------------------------------------------------*/ 13111 13112 function createByte(codePoint, shift) { 13113 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13114 } 13115 13116 function encodeCodePoint(codePoint) { 13117 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13118 return stringFromCharCode(codePoint); 13119 } 13120 var symbol = ''; 13121 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13122 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13123 } 13124 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13125 checkScalarValue(codePoint); 13126 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13127 symbol += createByte(codePoint, 6); 13128 } 13129 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13130 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13131 symbol += createByte(codePoint, 12); 13132 symbol += createByte(codePoint, 6); 13133 } 13134 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13135 return symbol; 13136 } 13137 13138 function utf8encode(string) { 13139 var codePoints = ucs2decode(string); 13140 var length = codePoints.length; 13141 var index = -1; 13142 var codePoint; 13143 var byteString = ''; 13144 while (++index < length) { 13145 codePoint = codePoints[index]; 13146 byteString += encodeCodePoint(codePoint); 13147 } 13148 return byteString; 13149 } 13150 13151 /*--------------------------------------------------------------------------*/ 13152 13153 function readContinuationByte() { 13154 if (byteIndex >= byteCount) { 13155 throw Error('Invalid byte index'); 13156 } 13157 13158 var continuationByte = byteArray[byteIndex] & 0xFF; 13159 byteIndex++; 13160 13161 if ((continuationByte & 0xC0) == 0x80) { 13162 return continuationByte & 0x3F; 13163 } 13164 13165 // If we end up here, it’s not a continuation byte 13166 throw Error('Invalid continuation byte'); 13167 } 13168 13169 function decodeSymbol() { 13170 var byte1; 13171 var byte2; 13172 var byte3; 13173 var byte4; 13174 var codePoint; 13175 13176 if (byteIndex > byteCount) { 13177 throw Error('Invalid byte index'); 13178 } 13179 13180 if (byteIndex == byteCount) { 13181 return false; 13182 } 13183 13184 // Read first byte 13185 byte1 = byteArray[byteIndex] & 0xFF; 13186 byteIndex++; 13187 13188 // 1-byte sequence (no continuation bytes) 13189 if ((byte1 & 0x80) == 0) { 13190 return byte1; 13191 } 13192 13193 // 2-byte sequence 13194 if ((byte1 & 0xE0) == 0xC0) { 13195 byte2 = readContinuationByte(); 13196 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13197 if (codePoint >= 0x80) { 13198 return codePoint; 13199 } else { 13200 throw Error('Invalid continuation byte'); 13201 } 13202 } 13203 13204 // 3-byte sequence (may include unpaired surrogates) 13205 if ((byte1 & 0xF0) == 0xE0) { 13206 byte2 = readContinuationByte(); 13207 byte3 = readContinuationByte(); 13208 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13209 if (codePoint >= 0x0800) { 13210 checkScalarValue(codePoint); 13211 return codePoint; 13212 } else { 13213 throw Error('Invalid continuation byte'); 13214 } 13215 } 13216 13217 // 4-byte sequence 13218 if ((byte1 & 0xF8) == 0xF0) { 13219 byte2 = readContinuationByte(); 13220 byte3 = readContinuationByte(); 13221 byte4 = readContinuationByte(); 13222 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 13223 (byte3 << 0x06) | byte4; 13224 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 13225 return codePoint; 13226 } 13227 } 13228 13229 throw Error('Invalid UTF-8 detected'); 13230 } 13231 13232 var byteArray; 13233 var byteCount; 13234 var byteIndex; 13235 function utf8decode(byteString) { 13236 byteArray = ucs2decode(byteString); 13237 byteCount = byteArray.length; 13238 byteIndex = 0; 13239 var codePoints = []; 13240 var tmp; 13241 while ((tmp = decodeSymbol()) !== false) { 13242 codePoints.push(tmp); 13243 } 13244 return ucs2encode(codePoints); 13245 } 13246 13247 /*--------------------------------------------------------------------------*/ 13248 13249 var utf8 = { 13250 'version': '2.1.2', 13251 'encode': utf8encode, 13252 'decode': utf8decode 13253 }; 13254 13255 // Some AMD build optimizers, like r.js, check for specific condition patterns 13256 // like the following: 13257 if ( 13258 typeof define == 'function' && 13259 typeof define.amd == 'object' && 13260 define.amd 13261 ) { 13262 define(function() { 13263 return utf8; 13264 }); 13265 } else if (freeExports && !freeExports.nodeType) { 13266 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 13267 freeModule.exports = utf8; 13268 } else { // in Narwhal or RingoJS v0.7.0- 13269 var object = {}; 13270 var hasOwnProperty = object.hasOwnProperty; 13271 for (var key in utf8) { 13272 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 13273 } 13274 } 13275 } else { // in Rhino or a web browser 13276 root.utf8 = utf8; 13277 } 13278 13279 }(this)); 13280 13281 },{}],86:[function(require,module,exports){ 13282 module.exports = XMLHttpRequest; 13283 13284 },{}],"bignumber.js":[function(require,module,exports){ 13285 'use strict'; 13286 13287 module.exports = BigNumber; // jshint ignore:line 13288 13289 13290 },{}],"web3":[function(require,module,exports){ 13291 var Web3 = require('./lib/web3'); 13292 13293 // don't override global variable 13294 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 13295 window.Web3 = Web3; 13296 } 13297 13298 module.exports = Web3; 13299 13300 },{"./lib/web3":22}]},{},["web3"]) 13301