github.com/cranelv/ethereum_mpc@v0.0.0-20191031014521-23aeb1415092/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 prootype 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 prootype 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,name) { 929 throw new Error('invalid address 111 ' + name + " : " + value); 930 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 931 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 932 return new SolidityParam(result); 933 }; 934 935 /** 936 * Formats input bytes 937 * 938 * @method formatInputBytes 939 * @param {String} 940 * @returns {SolidityParam} 941 */ 942 var formatInputBytes = function (value) { 943 var result = utils.toHex(value).substr(2); 944 var l = Math.floor((result.length + 63) / 64); 945 result = utils.padRight(result, l * 64); 946 return new SolidityParam(result); 947 }; 948 949 /** 950 * Formats input bytes 951 * 952 * @method formatDynamicInputBytes 953 * @param {String} 954 * @returns {SolidityParam} 955 */ 956 var formatInputDynamicBytes = function (value) { 957 var result = utils.toHex(value).substr(2); 958 var length = result.length / 2; 959 var l = Math.floor((result.length + 63) / 64); 960 result = utils.padRight(result, l * 64); 961 return new SolidityParam(formatInputInt(length).value + result); 962 }; 963 964 /** 965 * Formats input value to byte representation of string 966 * 967 * @method formatInputString 968 * @param {String} 969 * @returns {SolidityParam} 970 */ 971 var formatInputString = function (value,name) { 972 throw new Error('invalid address 111 ' + name + " : " + value); 973 var result = utils.fromUtf8(value).substr(2); 974 var length = result.length / 2; 975 var l = Math.floor((result.length + 63) / 64); 976 result = utils.padRight(result, l * 64); 977 return new SolidityParam(formatInputInt(length).value + result); 978 }; 979 980 /** 981 * Formats input value to byte representation of bool 982 * 983 * @method formatInputBool 984 * @param {Boolean} 985 * @returns {SolidityParam} 986 */ 987 var formatInputBool = function (value) { 988 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 989 return new SolidityParam(result); 990 }; 991 992 /** 993 * Formats input value to byte representation of real 994 * Values are multiplied by 2^m and encoded as integers 995 * 996 * @method formatInputReal 997 * @param {String|Number|BigNumber} 998 * @returns {SolidityParam} 999 */ 1000 var formatInputReal = function (value) { 1001 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1002 }; 1003 1004 /** 1005 * Check if input value is negative 1006 * 1007 * @method signedIsNegative 1008 * @param {String} value is hex format 1009 * @returns {Boolean} true if it is negative, otherwise false 1010 */ 1011 var signedIsNegative = function (value) { 1012 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1013 }; 1014 1015 /** 1016 * Formats right-aligned output bytes to int 1017 * 1018 * @method formatOutputInt 1019 * @param {SolidityParam} param 1020 * @returns {BigNumber} right-aligned output bytes formatted to big number 1021 */ 1022 var formatOutputInt = function (param) { 1023 var value = param.staticPart() || "0"; 1024 1025 // check if it's negative number 1026 // it it is, return two's complement 1027 if (signedIsNegative(value)) { 1028 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1029 } 1030 return new BigNumber(value, 16); 1031 }; 1032 1033 /** 1034 * Formats right-aligned output bytes to uint 1035 * 1036 * @method formatOutputUInt 1037 * @param {SolidityParam} 1038 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1039 */ 1040 var formatOutputUInt = function (param) { 1041 var value = param.staticPart() || "0"; 1042 return new BigNumber(value, 16); 1043 }; 1044 1045 /** 1046 * Formats right-aligned output bytes to real 1047 * 1048 * @method formatOutputReal 1049 * @param {SolidityParam} 1050 * @returns {BigNumber} input bytes formatted to real 1051 */ 1052 var formatOutputReal = function (param) { 1053 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1054 }; 1055 1056 /** 1057 * Formats right-aligned output bytes to ureal 1058 * 1059 * @method formatOutputUReal 1060 * @param {SolidityParam} 1061 * @returns {BigNumber} input bytes formatted to ureal 1062 */ 1063 var formatOutputUReal = function (param) { 1064 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1065 }; 1066 1067 /** 1068 * Should be used to format output bool 1069 * 1070 * @method formatOutputBool 1071 * @param {SolidityParam} 1072 * @returns {Boolean} right-aligned input bytes formatted to bool 1073 */ 1074 var formatOutputBool = function (param) { 1075 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1076 }; 1077 1078 /** 1079 * Should be used to format output bytes 1080 * 1081 * @method formatOutputBytes 1082 * @param {SolidityParam} left-aligned hex representation of string 1083 * @param {String} name type name 1084 * @returns {String} hex string 1085 */ 1086 var formatOutputBytes = function (param, name) { 1087 var matches = name.match(/^bytes([0-9]*)/); 1088 var size = parseInt(matches[1]); 1089 return '0x' + param.staticPart().slice(0, 2 * size); 1090 }; 1091 1092 /** 1093 * Should be used to format output bytes 1094 * 1095 * @method formatOutputDynamicBytes 1096 * @param {SolidityParam} left-aligned hex representation of string 1097 * @returns {String} hex string 1098 */ 1099 var formatOutputDynamicBytes = function (param) { 1100 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1101 return '0x' + param.dynamicPart().substr(64, length); 1102 }; 1103 1104 /** 1105 * Should be used to format output string 1106 * 1107 * @method formatOutputString 1108 * @param {SolidityParam} left-aligned hex representation of string 1109 * @returns {String} ascii string 1110 */ 1111 var formatOutputString = function (param) { 1112 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1113 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1114 }; 1115 1116 /** 1117 * Should be used to format output address 1118 * 1119 * @method formatOutputAddress 1120 * @param {SolidityParam} right-aligned input bytes 1121 * @returns {String} address 1122 */ 1123 var formatOutputAddress = function (param) { 1124 var value = param.staticPart(); 1125 return "0x" + value.slice(value.length - 40, value.length); 1126 }; 1127 1128 module.exports = { 1129 formatInputInt: formatInputInt, 1130 formatInputBytes: formatInputBytes, 1131 formatInputDynamicBytes: formatInputDynamicBytes, 1132 formatInputString: formatInputString, 1133 formatInputBool: formatInputBool, 1134 formatInputReal: formatInputReal, 1135 formatOutputInt: formatOutputInt, 1136 formatOutputUInt: formatOutputUInt, 1137 formatOutputReal: formatOutputReal, 1138 formatOutputUReal: formatOutputUReal, 1139 formatOutputBool: formatOutputBool, 1140 formatOutputBytes: formatOutputBytes, 1141 formatOutputDynamicBytes: formatOutputDynamicBytes, 1142 formatOutputString: formatOutputString, 1143 formatOutputAddress: formatOutputAddress 1144 }; 1145 1146 },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){ 1147 var f = require('./formatters'); 1148 var SolidityType = require('./type'); 1149 1150 /** 1151 * SolidityTypeInt is a prootype that represents int type 1152 * It matches: 1153 * int 1154 * int[] 1155 * int[4] 1156 * int[][] 1157 * int[3][] 1158 * int[][6][], ... 1159 * int32 1160 * int64[] 1161 * int8[4] 1162 * int256[][] 1163 * int[3][] 1164 * int64[][6][], ... 1165 */ 1166 var SolidityTypeInt = function () { 1167 this._inputFormatter = f.formatInputInt; 1168 this._outputFormatter = f.formatOutputInt; 1169 }; 1170 1171 SolidityTypeInt.prototype = new SolidityType({}); 1172 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1173 1174 SolidityTypeInt.prototype.isType = function (name) { 1175 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1176 }; 1177 1178 module.exports = SolidityTypeInt; 1179 1180 },{"./formatters":9,"./type":14}],11:[function(require,module,exports){ 1181 /* 1182 This file is part of web3.js. 1183 1184 web3.js is free software: you can redistribute it and/or modify 1185 it under the terms of the GNU Lesser General Public License as published by 1186 the Free Software Foundation, either version 3 of the License, or 1187 (at your option) any later version. 1188 1189 web3.js is distributed in the hope that it will be useful, 1190 but WITHOUT ANY WARRANTY; without even the implied warranty of 1191 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1192 GNU Lesser General Public License for more details. 1193 1194 You should have received a copy of the GNU Lesser General Public License 1195 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1196 */ 1197 /** 1198 * @file param.js 1199 * @author Marek Kotewicz <marek@ethdev.com> 1200 * @date 2015 1201 */ 1202 1203 var utils = require('../utils/utils'); 1204 1205 /** 1206 * SolidityParam object prototype. 1207 * Should be used when encoding, decoding solidity bytes 1208 */ 1209 var SolidityParam = function (value, offset) { 1210 this.value = value || ''; 1211 this.offset = offset; // offset in bytes 1212 }; 1213 1214 /** 1215 * This method should be used to get length of params's dynamic part 1216 * 1217 * @method dynamicPartLength 1218 * @returns {Number} length of dynamic part (in bytes) 1219 */ 1220 SolidityParam.prototype.dynamicPartLength = function () { 1221 return this.dynamicPart().length / 2; 1222 }; 1223 1224 /** 1225 * This method should be used to create copy of solidity param with different offset 1226 * 1227 * @method withOffset 1228 * @param {Number} offset length in bytes 1229 * @returns {SolidityParam} new solidity param with applied offset 1230 */ 1231 SolidityParam.prototype.withOffset = function (offset) { 1232 return new SolidityParam(this.value, offset); 1233 }; 1234 1235 /** 1236 * This method should be used to combine solidity params together 1237 * eg. when appending an array 1238 * 1239 * @method combine 1240 * @param {SolidityParam} param with which we should combine 1241 * @param {SolidityParam} result of combination 1242 */ 1243 SolidityParam.prototype.combine = function (param) { 1244 return new SolidityParam(this.value + param.value); 1245 }; 1246 1247 /** 1248 * This method should be called to check if param has dynamic size. 1249 * If it has, it returns true, otherwise false 1250 * 1251 * @method isDynamic 1252 * @returns {Boolean} 1253 */ 1254 SolidityParam.prototype.isDynamic = function () { 1255 return this.offset !== undefined; 1256 }; 1257 1258 /** 1259 * This method should be called to transform offset to bytes 1260 * 1261 * @method offsetAsBytes 1262 * @returns {String} bytes representation of offset 1263 */ 1264 SolidityParam.prototype.offsetAsBytes = function () { 1265 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1266 }; 1267 1268 /** 1269 * This method should be called to get static part of param 1270 * 1271 * @method staticPart 1272 * @returns {String} offset if it is a dynamic param, otherwise value 1273 */ 1274 SolidityParam.prototype.staticPart = function () { 1275 if (!this.isDynamic()) { 1276 return this.value; 1277 } 1278 return this.offsetAsBytes(); 1279 }; 1280 1281 /** 1282 * This method should be called to get dynamic part of param 1283 * 1284 * @method dynamicPart 1285 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1286 */ 1287 SolidityParam.prototype.dynamicPart = function () { 1288 return this.isDynamic() ? this.value : ''; 1289 }; 1290 1291 /** 1292 * This method should be called to encode param 1293 * 1294 * @method encode 1295 * @returns {String} 1296 */ 1297 SolidityParam.prototype.encode = function () { 1298 return this.staticPart() + this.dynamicPart(); 1299 }; 1300 1301 /** 1302 * This method should be called to encode array of params 1303 * 1304 * @method encodeList 1305 * @param {Array[SolidityParam]} params 1306 * @returns {String} 1307 */ 1308 SolidityParam.encodeList = function (params) { 1309 1310 // updating offsets 1311 var totalOffset = params.length * 32; 1312 var offsetParams = params.map(function (param) { 1313 if (!param.isDynamic()) { 1314 return param; 1315 } 1316 var offset = totalOffset; 1317 totalOffset += param.dynamicPartLength(); 1318 return param.withOffset(offset); 1319 }); 1320 1321 // encode everything! 1322 return offsetParams.reduce(function (result, param) { 1323 return result + param.dynamicPart(); 1324 }, offsetParams.reduce(function (result, param) { 1325 return result + param.staticPart(); 1326 }, '')); 1327 }; 1328 1329 1330 1331 module.exports = SolidityParam; 1332 1333 1334 },{"../utils/utils":20}],12:[function(require,module,exports){ 1335 var f = require('./formatters'); 1336 var SolidityType = require('./type'); 1337 1338 /** 1339 * SolidityTypeReal is a prootype that represents real type 1340 * It matches: 1341 * real 1342 * real[] 1343 * real[4] 1344 * real[][] 1345 * real[3][] 1346 * real[][6][], ... 1347 * real32 1348 * real64[] 1349 * real8[4] 1350 * real256[][] 1351 * real[3][] 1352 * real64[][6][], ... 1353 */ 1354 var SolidityTypeReal = function () { 1355 this._inputFormatter = f.formatInputReal; 1356 this._outputFormatter = f.formatOutputReal; 1357 }; 1358 1359 SolidityTypeReal.prototype = new SolidityType({}); 1360 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1361 1362 SolidityTypeReal.prototype.isType = function (name) { 1363 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1364 }; 1365 1366 module.exports = SolidityTypeReal; 1367 1368 },{"./formatters":9,"./type":14}],13:[function(require,module,exports){ 1369 var f = require('./formatters'); 1370 var SolidityType = require('./type'); 1371 1372 var SolidityTypeString = function () { 1373 this._inputFormatter = f.formatInputString; 1374 this._outputFormatter = f.formatOutputString; 1375 }; 1376 1377 SolidityTypeString.prototype = new SolidityType({}); 1378 SolidityTypeString.prototype.constructor = SolidityTypeString; 1379 1380 SolidityTypeString.prototype.isType = function (name) { 1381 return !!name.match(/^string(\[([0-9]*)\])*$/); 1382 }; 1383 1384 SolidityTypeString.prototype.isDynamicType = function () { 1385 return true; 1386 }; 1387 1388 module.exports = SolidityTypeString; 1389 1390 },{"./formatters":9,"./type":14}],14:[function(require,module,exports){ 1391 var f = require('./formatters'); 1392 var SolidityParam = require('./param'); 1393 1394 /** 1395 * SolidityType prototype is used to encode/decode solidity params of certain type 1396 */ 1397 var SolidityType = function (config) { 1398 this._inputFormatter = config.inputFormatter; 1399 this._outputFormatter = config.outputFormatter; 1400 }; 1401 1402 /** 1403 * Should be used to determine if this SolidityType do match given name 1404 * 1405 * @method isType 1406 * @param {String} name 1407 * @return {Bool} true if type match this SolidityType, otherwise false 1408 */ 1409 SolidityType.prototype.isType = function (name) { 1410 throw "this method should be overrwritten for type " + name; 1411 }; 1412 1413 /** 1414 * Should be used to determine what is the length of static part in given type 1415 * 1416 * @method staticPartLength 1417 * @param {String} name 1418 * @return {Number} length of static part in bytes 1419 */ 1420 SolidityType.prototype.staticPartLength = function (name) { 1421 // If name isn't an array then treat it like a single element array. 1422 return (this.nestedTypes(name) || ['[1]']) 1423 .map(function (type) { 1424 // the length of the nested array 1425 return parseInt(type.slice(1, -1), 10) || 1; 1426 }) 1427 .reduce(function (previous, current) { 1428 return previous * current; 1429 // all basic types are 32 bytes long 1430 }, 32); 1431 }; 1432 1433 /** 1434 * Should be used to determine if type is dynamic array 1435 * eg: 1436 * "type[]" => true 1437 * "type[4]" => false 1438 * 1439 * @method isDynamicArray 1440 * @param {String} name 1441 * @return {Bool} true if the type is dynamic array 1442 */ 1443 SolidityType.prototype.isDynamicArray = function (name) { 1444 var nestedTypes = this.nestedTypes(name); 1445 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1446 }; 1447 1448 /** 1449 * Should be used to determine if type is static array 1450 * eg: 1451 * "type[]" => false 1452 * "type[4]" => true 1453 * 1454 * @method isStaticArray 1455 * @param {String} name 1456 * @return {Bool} true if the type is static array 1457 */ 1458 SolidityType.prototype.isStaticArray = function (name) { 1459 var nestedTypes = this.nestedTypes(name); 1460 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1461 }; 1462 1463 /** 1464 * Should return length of static array 1465 * eg. 1466 * "int[32]" => 32 1467 * "int256[14]" => 14 1468 * "int[2][3]" => 3 1469 * "int" => 1 1470 * "int[1]" => 1 1471 * "int[]" => 1 1472 * 1473 * @method staticArrayLength 1474 * @param {String} name 1475 * @return {Number} static array length 1476 */ 1477 SolidityType.prototype.staticArrayLength = function (name) { 1478 var nestedTypes = this.nestedTypes(name); 1479 if (nestedTypes) { 1480 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1481 } 1482 return 1; 1483 }; 1484 1485 /** 1486 * Should return nested type 1487 * eg. 1488 * "int[32]" => "int" 1489 * "int256[14]" => "int256" 1490 * "int[2][3]" => "int[2]" 1491 * "int" => "int" 1492 * "int[]" => "int" 1493 * 1494 * @method nestedName 1495 * @param {String} name 1496 * @return {String} nested name 1497 */ 1498 SolidityType.prototype.nestedName = function (name) { 1499 // remove last [] in name 1500 var nestedTypes = this.nestedTypes(name); 1501 if (!nestedTypes) { 1502 return name; 1503 } 1504 1505 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1506 }; 1507 1508 /** 1509 * Should return true if type has dynamic size by default 1510 * such types are "string", "bytes" 1511 * 1512 * @method isDynamicType 1513 * @param {String} name 1514 * @return {Bool} true if is dynamic, otherwise false 1515 */ 1516 SolidityType.prototype.isDynamicType = function () { 1517 return false; 1518 }; 1519 1520 /** 1521 * Should return array of nested types 1522 * eg. 1523 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1524 * "int[] => ["[]"] 1525 * "int" => null 1526 * 1527 * @method nestedTypes 1528 * @param {String} name 1529 * @return {Array} array of nested types 1530 */ 1531 SolidityType.prototype.nestedTypes = function (name) { 1532 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1533 return name.match(/(\[[0-9]*\])/g); 1534 }; 1535 1536 /** 1537 * Should be used to encode the value 1538 * 1539 * @method encode 1540 * @param {Object} value 1541 * @param {String} name 1542 * @return {String} encoded value 1543 */ 1544 SolidityType.prototype.encode = function (value, name) { 1545 var self = this; 1546 if (this.isDynamicArray(name)) { 1547 1548 return (function () { 1549 var length = value.length; // in int 1550 var nestedName = self.nestedName(name); 1551 1552 var result = []; 1553 result.push(f.formatInputInt(length).encode()); 1554 1555 value.forEach(function (v) { 1556 result.push(self.encode(v, nestedName)); 1557 }); 1558 1559 return result; 1560 })(); 1561 1562 } else if (this.isStaticArray(name)) { 1563 1564 return (function () { 1565 var length = self.staticArrayLength(name); // in int 1566 var nestedName = self.nestedName(name); 1567 1568 var result = []; 1569 for (var i = 0; i < length; i++) { 1570 result.push(self.encode(value[i], nestedName)); 1571 } 1572 1573 return result; 1574 })(); 1575 1576 } 1577 // throw new Error('invalid address 111 ' + name + " : " + value); 1578 return this._inputFormatter(value, name).encode(); 1579 }; 1580 1581 /** 1582 * Should be used to decode value from bytes 1583 * 1584 * @method decode 1585 * @param {String} bytes 1586 * @param {Number} offset in bytes 1587 * @param {String} name type name 1588 * @returns {Object} decoded value 1589 */ 1590 SolidityType.prototype.decode = function (bytes, offset, name) { 1591 var self = this; 1592 1593 if (this.isDynamicArray(name)) { 1594 1595 return (function () { 1596 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1597 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1598 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1599 1600 var nestedName = self.nestedName(name); 1601 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1602 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1603 var result = []; 1604 1605 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1606 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1607 } 1608 1609 return result; 1610 })(); 1611 1612 } else if (this.isStaticArray(name)) { 1613 1614 return (function () { 1615 var length = self.staticArrayLength(name); // in int 1616 var arrayStart = offset; // in bytes 1617 1618 var nestedName = self.nestedName(name); 1619 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1620 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1621 var result = []; 1622 1623 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1624 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1625 } 1626 1627 return result; 1628 })(); 1629 } else if (this.isDynamicType(name)) { 1630 1631 return (function () { 1632 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1633 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1634 var roundedLength = Math.floor((length + 31) / 32); // in int 1635 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0); 1636 return self._outputFormatter(param, name); 1637 })(); 1638 } 1639 1640 var length = this.staticPartLength(name); 1641 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1642 return this._outputFormatter(param, name); 1643 }; 1644 1645 module.exports = SolidityType; 1646 1647 },{"./formatters":9,"./param":11}],15:[function(require,module,exports){ 1648 var f = require('./formatters'); 1649 var SolidityType = require('./type'); 1650 1651 /** 1652 * SolidityTypeUInt is a prootype that represents uint type 1653 * It matches: 1654 * uint 1655 * uint[] 1656 * uint[4] 1657 * uint[][] 1658 * uint[3][] 1659 * uint[][6][], ... 1660 * uint32 1661 * uint64[] 1662 * uint8[4] 1663 * uint256[][] 1664 * uint[3][] 1665 * uint64[][6][], ... 1666 */ 1667 var SolidityTypeUInt = function () { 1668 this._inputFormatter = f.formatInputInt; 1669 this._outputFormatter = f.formatOutputUInt; 1670 }; 1671 1672 SolidityTypeUInt.prototype = new SolidityType({}); 1673 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1674 1675 SolidityTypeUInt.prototype.isType = function (name) { 1676 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1677 }; 1678 1679 module.exports = SolidityTypeUInt; 1680 1681 },{"./formatters":9,"./type":14}],16:[function(require,module,exports){ 1682 var f = require('./formatters'); 1683 var SolidityType = require('./type'); 1684 1685 /** 1686 * SolidityTypeUReal is a prootype that represents ureal type 1687 * It matches: 1688 * ureal 1689 * ureal[] 1690 * ureal[4] 1691 * ureal[][] 1692 * ureal[3][] 1693 * ureal[][6][], ... 1694 * ureal32 1695 * ureal64[] 1696 * ureal8[4] 1697 * ureal256[][] 1698 * ureal[3][] 1699 * ureal64[][6][], ... 1700 */ 1701 var SolidityTypeUReal = function () { 1702 this._inputFormatter = f.formatInputReal; 1703 this._outputFormatter = f.formatOutputUReal; 1704 }; 1705 1706 SolidityTypeUReal.prototype = new SolidityType({}); 1707 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1708 1709 SolidityTypeUReal.prototype.isType = function (name) { 1710 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1711 }; 1712 1713 module.exports = SolidityTypeUReal; 1714 1715 },{"./formatters":9,"./type":14}],17:[function(require,module,exports){ 1716 'use strict'; 1717 1718 // go env doesn't have and need XMLHttpRequest 1719 if (typeof XMLHttpRequest === 'undefined') { 1720 exports.XMLHttpRequest = {}; 1721 } else { 1722 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1723 } 1724 1725 1726 },{}],18:[function(require,module,exports){ 1727 /* 1728 This file is part of web3.js. 1729 1730 web3.js is free software: you can redistribute it and/or modify 1731 it under the terms of the GNU Lesser General Public License as published by 1732 the Free Software Foundation, either version 3 of the License, or 1733 (at your option) any later version. 1734 1735 web3.js is distributed in the hope that it will be useful, 1736 but WITHOUT ANY WARRANTY; without even the implied warranty of 1737 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1738 GNU Lesser General Public License for more details. 1739 1740 You should have received a copy of the GNU Lesser General Public License 1741 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1742 */ 1743 /** @file config.js 1744 * @authors: 1745 * Marek Kotewicz <marek@ethdev.com> 1746 * @date 2015 1747 */ 1748 1749 /** 1750 * Utils 1751 * 1752 * @module utils 1753 */ 1754 1755 /** 1756 * Utility functions 1757 * 1758 * @class [utils] config 1759 * @constructor 1760 */ 1761 1762 1763 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1764 var BigNumber = require('bignumber.js'); 1765 1766 var ETH_UNITS = [ 1767 'wei', 1768 'kwei', 1769 'Mwei', 1770 'Gwei', 1771 'szabo', 1772 'finney', 1773 'femtoether', 1774 'picoether', 1775 'nanoether', 1776 'microether', 1777 'milliether', 1778 'nano', 1779 'micro', 1780 'milli', 1781 'ether', 1782 'grand', 1783 'Mether', 1784 'Gether', 1785 'Tether', 1786 'Pether', 1787 'Eether', 1788 'Zether', 1789 'Yether', 1790 'Nether', 1791 'Dether', 1792 'Vether', 1793 'Uether' 1794 ]; 1795 1796 module.exports = { 1797 ETH_PADDING: 32, 1798 ETH_SIGNATURE_LENGTH: 4, 1799 ETH_UNITS: ETH_UNITS, 1800 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1801 ETH_POLLING_TIMEOUT: 1000/2, 1802 defaultBlock: 'latest', 1803 defaultAccount: undefined 1804 }; 1805 1806 1807 },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){ 1808 /* 1809 This file is part of web3.js. 1810 1811 web3.js is free software: you can redistribute it and/or modify 1812 it under the terms of the GNU Lesser General Public License as published by 1813 the Free Software Foundation, either version 3 of the License, or 1814 (at your option) any later version. 1815 1816 web3.js is distributed in the hope that it will be useful, 1817 but WITHOUT ANY WARRANTY; without even the implied warranty of 1818 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1819 GNU Lesser General Public License for more details. 1820 1821 You should have received a copy of the GNU Lesser General Public License 1822 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1823 */ 1824 /** 1825 * @file sha3.js 1826 * @author Marek Kotewicz <marek@ethdev.com> 1827 * @date 2015 1828 */ 1829 1830 var CryptoJS = require('crypto-js'); 1831 var sha3 = require('crypto-js/sha3'); 1832 1833 module.exports = function (value, options) { 1834 if (options && options.encoding === 'hex') { 1835 if (value.length > 2 && value.substr(0, 2) === '0x') { 1836 value = value.substr(2); 1837 } 1838 value = CryptoJS.enc.Hex.parse(value); 1839 } 1840 1841 return sha3(value, { 1842 outputLength: 256 1843 }).toString(); 1844 }; 1845 1846 1847 },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){ 1848 /* 1849 This file is part of web3.js. 1850 1851 web3.js is free software: you can redistribute it and/or modify 1852 it under the terms of the GNU Lesser General Public License as published by 1853 the Free Software Foundation, either version 3 of the License, or 1854 (at your option) any later version. 1855 1856 web3.js is distributed in the hope that it will be useful, 1857 but WITHOUT ANY WARRANTY; without even the implied warranty of 1858 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1859 GNU Lesser General Public License for more details. 1860 1861 You should have received a copy of the GNU Lesser General Public License 1862 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1863 */ 1864 /** 1865 * @file utils.js 1866 * @author Marek Kotewicz <marek@ethdev.com> 1867 * @date 2015 1868 */ 1869 1870 /** 1871 * Utils 1872 * 1873 * @module utils 1874 */ 1875 1876 /** 1877 * Utility functions 1878 * 1879 * @class [utils] utils 1880 * @constructor 1881 */ 1882 1883 1884 var BigNumber = require('bignumber.js'); 1885 var sha3 = require('./sha3.js'); 1886 var utf8 = require('utf8'); 1887 1888 var unitMap = { 1889 'noether': '0', 1890 'wei': '1', 1891 'kwei': '1000', 1892 'Kwei': '1000', 1893 'babbage': '1000', 1894 'femtoether': '1000', 1895 'mwei': '1000000', 1896 'Mwei': '1000000', 1897 'lovelace': '1000000', 1898 'picoether': '1000000', 1899 'gwei': '1000000000', 1900 'Gwei': '1000000000', 1901 'shannon': '1000000000', 1902 'nanoether': '1000000000', 1903 'nano': '1000000000', 1904 'szabo': '1000000000000', 1905 'microether': '1000000000000', 1906 'micro': '1000000000000', 1907 'finney': '1000000000000000', 1908 'milliether': '1000000000000000', 1909 'milli': '1000000000000000', 1910 'ether': '1000000000000000000', 1911 'kether': '1000000000000000000000', 1912 'grand': '1000000000000000000000', 1913 'mether': '1000000000000000000000000', 1914 'gether': '1000000000000000000000000000', 1915 'tether': '1000000000000000000000000000000' 1916 }; 1917 1918 /** 1919 * Should be called to pad string to expected length 1920 * 1921 * @method padLeft 1922 * @param {String} string to be padded 1923 * @param {Number} characters that result string should have 1924 * @param {String} sign, by default 0 1925 * @returns {String} right aligned string 1926 */ 1927 var padLeft = function (string, chars, sign) { 1928 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1929 }; 1930 1931 /** 1932 * Should be called to pad string to expected length 1933 * 1934 * @method padRight 1935 * @param {String} string to be padded 1936 * @param {Number} characters that result string should have 1937 * @param {String} sign, by default 0 1938 * @returns {String} right aligned string 1939 */ 1940 var padRight = function (string, chars, sign) { 1941 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1942 }; 1943 1944 /** 1945 * Should be called to get utf8 from it's hex representation 1946 * 1947 * @method toUtf8 1948 * @param {String} string in hex 1949 * @returns {String} ascii string representation of hex value 1950 */ 1951 var toUtf8 = function(hex) { 1952 // Find termination 1953 var str = ""; 1954 var i = 0, l = hex.length; 1955 if (hex.substring(0, 2) === '0x') { 1956 i = 2; 1957 } 1958 for (; i < l; i+=2) { 1959 var code = parseInt(hex.substr(i, 2), 16); 1960 if (code === 0) 1961 break; 1962 str += String.fromCharCode(code); 1963 } 1964 1965 return utf8.decode(str); 1966 }; 1967 1968 /** 1969 * Should be called to get ascii from it's hex representation 1970 * 1971 * @method toAscii 1972 * @param {String} string in hex 1973 * @returns {String} ascii string representation of hex value 1974 */ 1975 var toAscii = function(hex) { 1976 // Find termination 1977 var str = ""; 1978 var i = 0, l = hex.length; 1979 if (hex.substring(0, 2) === '0x') { 1980 i = 2; 1981 } 1982 for (; i < l; i+=2) { 1983 var code = parseInt(hex.substr(i, 2), 16); 1984 str += String.fromCharCode(code); 1985 } 1986 1987 return str; 1988 }; 1989 1990 /** 1991 * Should be called to get hex representation (prefixed by 0x) of utf8 string 1992 * 1993 * @method fromUtf8 1994 * @param {String} string 1995 * @param {Number} optional padding 1996 * @returns {String} hex representation of input string 1997 */ 1998 var fromUtf8 = function(str) { 1999 str = utf8.encode(str); 2000 var hex = ""; 2001 for(var i = 0; i < str.length; i++) { 2002 var code = str.charCodeAt(i); 2003 if (code === 0) 2004 break; 2005 var n = code.toString(16); 2006 hex += n.length < 2 ? '0' + n : n; 2007 } 2008 2009 return "0x" + hex; 2010 }; 2011 2012 /** 2013 * Should be called to get hex representation (prefixed by 0x) of ascii string 2014 * 2015 * @method fromAscii 2016 * @param {String} string 2017 * @param {Number} optional padding 2018 * @returns {String} hex representation of input string 2019 */ 2020 var fromAscii = function(str) { 2021 var hex = ""; 2022 for(var i = 0; i < str.length; i++) { 2023 var code = str.charCodeAt(i); 2024 var n = code.toString(16); 2025 hex += n.length < 2 ? '0' + n : n; 2026 } 2027 2028 return "0x" + hex; 2029 }; 2030 2031 /** 2032 * Should be used to create full function/event name from json abi 2033 * 2034 * @method transformToFullName 2035 * @param {Object} json-abi 2036 * @return {String} full fnction/event name 2037 */ 2038 var transformToFullName = function (json) { 2039 if (json.name.indexOf('(') !== -1) { 2040 return json.name; 2041 } 2042 2043 var typeName = json.inputs.map(function(i){return i.type; }).join(); 2044 return json.name + '(' + typeName + ')'; 2045 }; 2046 2047 /** 2048 * Should be called to get display name of contract function 2049 * 2050 * @method extractDisplayName 2051 * @param {String} name of function/event 2052 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2053 */ 2054 var extractDisplayName = function (name) { 2055 var length = name.indexOf('('); 2056 return length !== -1 ? name.substr(0, length) : name; 2057 }; 2058 2059 /// @returns overloaded part of function/event name 2060 var extractTypeName = function (name) { 2061 /// TODO: make it invulnerable 2062 var length = name.indexOf('('); 2063 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2064 }; 2065 2066 /** 2067 * Converts value to it's decimal representation in string 2068 * 2069 * @method toDecimal 2070 * @param {String|Number|BigNumber} 2071 * @return {String} 2072 */ 2073 var toDecimal = function (value) { 2074 return toBigNumber(value).toNumber(); 2075 }; 2076 2077 /** 2078 * Converts value to it's hex representation 2079 * 2080 * @method fromDecimal 2081 * @param {String|Number|BigNumber} 2082 * @return {String} 2083 */ 2084 var fromDecimal = function (value) { 2085 var number = toBigNumber(value); 2086 var result = number.toString(16); 2087 2088 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2089 }; 2090 2091 /** 2092 * Auto converts any given value into it's hex representation. 2093 * 2094 * And even stringifys objects before. 2095 * 2096 * @method toHex 2097 * @param {String|Number|BigNumber|Object} 2098 * @return {String} 2099 */ 2100 var toHex = function (val) { 2101 /*jshint maxcomplexity: 8 */ 2102 2103 if (isBoolean(val)) 2104 return fromDecimal(+val); 2105 2106 if (isBigNumber(val)) 2107 return fromDecimal(val); 2108 2109 if (typeof val === 'object') 2110 return fromUtf8(JSON.stringify(val)); 2111 2112 // if its a negative number, pass it through fromDecimal 2113 if (isString(val)) { 2114 if (val.indexOf('-0x') === 0) 2115 return fromDecimal(val); 2116 else if(val.indexOf('0x') === 0) 2117 return val; 2118 else if (!isFinite(val)) 2119 return fromAscii(val); 2120 } 2121 2122 return fromDecimal(val); 2123 }; 2124 2125 /** 2126 * Returns value of unit in Wei 2127 * 2128 * @method getValueOfUnit 2129 * @param {String} unit the unit to convert to, default ether 2130 * @returns {BigNumber} value of the unit (in Wei) 2131 * @throws error if the unit is not correct:w 2132 */ 2133 var getValueOfUnit = function (unit) { 2134 unit = unit ? unit.toLowerCase() : 'ether'; 2135 var unitValue = unitMap[unit]; 2136 if (unitValue === undefined) { 2137 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2138 } 2139 return new BigNumber(unitValue, 10); 2140 }; 2141 2142 /** 2143 * Takes a number of wei and converts it to any other ether unit. 2144 * 2145 * Possible units are: 2146 * SI Short SI Full Effigy Other 2147 * - kwei femtoether babbage 2148 * - mwei picoether lovelace 2149 * - gwei nanoether shannon nano 2150 * - -- microether szabo micro 2151 * - -- milliether finney milli 2152 * - ether -- -- 2153 * - kether -- grand 2154 * - mether 2155 * - gether 2156 * - tether 2157 * 2158 * @method fromWei 2159 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2160 * @param {String} unit the unit to convert to, default ether 2161 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2162 */ 2163 var fromWei = function(number, unit) { 2164 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2165 2166 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2167 }; 2168 2169 /** 2170 * Takes a number of a unit and converts it to wei. 2171 * 2172 * Possible units are: 2173 * SI Short SI Full Effigy Other 2174 * - kwei femtoether babbage 2175 * - mwei picoether lovelace 2176 * - gwei nanoether shannon nano 2177 * - -- microether szabo micro 2178 * - -- microether szabo micro 2179 * - -- milliether finney milli 2180 * - ether -- -- 2181 * - kether -- grand 2182 * - mether 2183 * - gether 2184 * - tether 2185 * 2186 * @method toWei 2187 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2188 * @param {String} unit the unit to convert from, default ether 2189 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2190 */ 2191 var toWei = function(number, unit) { 2192 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2193 2194 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2195 }; 2196 2197 /** 2198 * Takes an input and transforms it into a bignumber 2199 * 2200 * @method toBigNumber 2201 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2202 * @return {BigNumber} BigNumber 2203 */ 2204 var toBigNumber = function(number) { 2205 /*jshint maxcomplexity:5 */ 2206 number = number || 0; 2207 if (isBigNumber(number)) 2208 return number; 2209 2210 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2211 return new BigNumber(number.replace('0x',''), 16); 2212 } 2213 2214 return new BigNumber(number.toString(10), 10); 2215 }; 2216 2217 /** 2218 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2219 * 2220 * @method toTwosComplement 2221 * @param {Number|String|BigNumber} 2222 * @return {BigNumber} 2223 */ 2224 var toTwosComplement = function (number) { 2225 var bigNumber = toBigNumber(number).round(); 2226 if (bigNumber.lessThan(0)) { 2227 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2228 } 2229 return bigNumber; 2230 }; 2231 2232 /** 2233 * Checks if the given string is strictly an address 2234 * 2235 * @method isStrictAddress 2236 * @param {String} address the given HEX adress 2237 * @return {Boolean} 2238 */ 2239 var isStrictAddress = function (address) { 2240 return /^0x[0-9a-f]{40}$/i.test(address); 2241 }; 2242 2243 /** 2244 * Checks if the given string is an address 2245 * 2246 * @method isAddress 2247 * @param {String} address the given HEX adress 2248 * @return {Boolean} 2249 */ 2250 var isAddress = function (address) { 2251 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2252 // check if it has the basic requirements of an address 2253 return false; 2254 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2255 // If it's all small caps or all all caps, return true 2256 return true; 2257 } else { 2258 // Otherwise check each case 2259 return isChecksumAddress(address); 2260 } 2261 }; 2262 2263 /** 2264 * Checks if the given string is a checksummed address 2265 * 2266 * @method isChecksumAddress 2267 * @param {String} address the given HEX adress 2268 * @return {Boolean} 2269 */ 2270 var isChecksumAddress = function (address) { 2271 // Check each case 2272 address = address.replace('0x',''); 2273 var addressHash = sha3(address.toLowerCase()); 2274 2275 for (var i = 0; i < 40; i++ ) { 2276 // the nth letter should be uppercase if the nth digit of casemap is 1 2277 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2278 return false; 2279 } 2280 } 2281 return true; 2282 }; 2283 2284 2285 2286 /** 2287 * Makes a checksum address 2288 * 2289 * @method toChecksumAddress 2290 * @param {String} address the given HEX adress 2291 * @return {String} 2292 */ 2293 var toChecksumAddress = function (address) { 2294 if (typeof address === 'undefined') return ''; 2295 2296 address = address.toLowerCase().replace('0x',''); 2297 var addressHash = sha3(address); 2298 var checksumAddress = '0x'; 2299 2300 for (var i = 0; i < address.length; i++ ) { 2301 // If ith character is 9 to f then make it uppercase 2302 if (parseInt(addressHash[i], 16) > 7) { 2303 checksumAddress += address[i].toUpperCase(); 2304 } else { 2305 checksumAddress += address[i]; 2306 } 2307 } 2308 return checksumAddress; 2309 }; 2310 2311 /** 2312 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2313 * 2314 * @method toAddress 2315 * @param {String} address 2316 * @return {String} formatted address 2317 */ 2318 var toAddress = function (address) { 2319 if (isStrictAddress(address)) { 2320 return address; 2321 } 2322 2323 if (/^[0-9a-f]{40}$/.test(address)) { 2324 return '0x' + address; 2325 } 2326 2327 return '0x' + padLeft(toHex(address).substr(2), 40); 2328 }; 2329 2330 /** 2331 * Returns true if object is BigNumber, otherwise false 2332 * 2333 * @method isBigNumber 2334 * @param {Object} 2335 * @return {Boolean} 2336 */ 2337 var isBigNumber = function (object) { 2338 return object instanceof BigNumber || 2339 (object && object.constructor && object.constructor.name === 'BigNumber'); 2340 }; 2341 2342 /** 2343 * Returns true if object is string, otherwise false 2344 * 2345 * @method isString 2346 * @param {Object} 2347 * @return {Boolean} 2348 */ 2349 var isString = function (object) { 2350 return typeof object === 'string' || 2351 (object && object.constructor && object.constructor.name === 'String'); 2352 }; 2353 2354 /** 2355 * Returns true if object is function, otherwise false 2356 * 2357 * @method isFunction 2358 * @param {Object} 2359 * @return {Boolean} 2360 */ 2361 var isFunction = function (object) { 2362 return typeof object === 'function'; 2363 }; 2364 2365 /** 2366 * Returns true if object is Objet, otherwise false 2367 * 2368 * @method isObject 2369 * @param {Object} 2370 * @return {Boolean} 2371 */ 2372 var isObject = function (object) { 2373 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2374 }; 2375 2376 /** 2377 * Returns true if object is boolean, otherwise false 2378 * 2379 * @method isBoolean 2380 * @param {Object} 2381 * @return {Boolean} 2382 */ 2383 var isBoolean = function (object) { 2384 return typeof object === 'boolean'; 2385 }; 2386 2387 /** 2388 * Returns true if object is array, otherwise false 2389 * 2390 * @method isArray 2391 * @param {Object} 2392 * @return {Boolean} 2393 */ 2394 var isArray = function (object) { 2395 return object instanceof Array; 2396 }; 2397 2398 /** 2399 * Returns true if given string is valid json object 2400 * 2401 * @method isJson 2402 * @param {String} 2403 * @return {Boolean} 2404 */ 2405 var isJson = function (str) { 2406 try { 2407 return !!JSON.parse(str); 2408 } catch (e) { 2409 return false; 2410 } 2411 }; 2412 2413 /** 2414 * Returns true if given string is a valid Ethereum block header bloom. 2415 * 2416 * @method isBloom 2417 * @param {String} hex encoded bloom filter 2418 * @return {Boolean} 2419 */ 2420 var isBloom = function (bloom) { 2421 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2422 return false; 2423 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2424 return true; 2425 } 2426 return false; 2427 }; 2428 2429 /** 2430 * Returns true if given string is a valid log topic. 2431 * 2432 * @method isTopic 2433 * @param {String} hex encoded topic 2434 * @return {Boolean} 2435 */ 2436 var isTopic = function (topic) { 2437 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2438 return false; 2439 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2440 return true; 2441 } 2442 return false; 2443 }; 2444 2445 module.exports = { 2446 padLeft: padLeft, 2447 padRight: padRight, 2448 toHex: toHex, 2449 toDecimal: toDecimal, 2450 fromDecimal: fromDecimal, 2451 toUtf8: toUtf8, 2452 toAscii: toAscii, 2453 fromUtf8: fromUtf8, 2454 fromAscii: fromAscii, 2455 transformToFullName: transformToFullName, 2456 extractDisplayName: extractDisplayName, 2457 extractTypeName: extractTypeName, 2458 toWei: toWei, 2459 fromWei: fromWei, 2460 toBigNumber: toBigNumber, 2461 toTwosComplement: toTwosComplement, 2462 toAddress: toAddress, 2463 isBigNumber: isBigNumber, 2464 isStrictAddress: isStrictAddress, 2465 isAddress: isAddress, 2466 isChecksumAddress: isChecksumAddress, 2467 toChecksumAddress: toChecksumAddress, 2468 isFunction: isFunction, 2469 isString: isString, 2470 isObject: isObject, 2471 isBoolean: isBoolean, 2472 isArray: isArray, 2473 isJson: isJson, 2474 isBloom: isBloom, 2475 isTopic: isTopic, 2476 }; 2477 2478 },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){ 2479 module.exports={ 2480 "version": "0.20.1" 2481 } 2482 2483 },{}],22:[function(require,module,exports){ 2484 /* 2485 This file is part of web3.js. 2486 2487 web3.js is free software: you can redistribute it and/or modify 2488 it under the terms of the GNU Lesser General Public License as published by 2489 the Free Software Foundation, either version 3 of the License, or 2490 (at your option) any later version. 2491 2492 web3.js is distributed in the hope that it will be useful, 2493 but WITHOUT ANY WARRANTY; without even the implied warranty of 2494 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2495 GNU Lesser General Public License for more details. 2496 2497 You should have received a copy of the GNU Lesser General Public License 2498 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2499 */ 2500 /** 2501 * @file web3.js 2502 * @authors: 2503 * Jeffrey Wilcke <jeff@ethdev.com> 2504 * Marek Kotewicz <marek@ethdev.com> 2505 * Marian Oancea <marian@ethdev.com> 2506 * Fabian Vogelsteller <fabian@ethdev.com> 2507 * Gav Wood <g@ethdev.com> 2508 * @date 2014 2509 */ 2510 2511 var RequestManager = require('./web3/requestmanager'); 2512 var Iban = require('./web3/iban'); 2513 var Eth = require('./web3/methods/eth'); 2514 var DB = require('./web3/methods/db'); 2515 var Shh = require('./web3/methods/shh'); 2516 var Net = require('./web3/methods/net'); 2517 var Personal = require('./web3/methods/personal'); 2518 var Swarm = require('./web3/methods/swarm'); 2519 var Settings = require('./web3/settings'); 2520 var version = require('./version.json'); 2521 var utils = require('./utils/utils'); 2522 var sha3 = require('./utils/sha3'); 2523 var extend = require('./web3/extend'); 2524 var Batch = require('./web3/batch'); 2525 var Property = require('./web3/property'); 2526 var HttpProvider = require('./web3/httpprovider'); 2527 var IpcProvider = require('./web3/ipcprovider'); 2528 var BigNumber = require('bignumber.js'); 2529 2530 2531 2532 function Web3 (provider) { 2533 this._requestManager = new RequestManager(provider); 2534 this.currentProvider = provider; 2535 this.eth = new Eth(this); 2536 this.db = new DB(this); 2537 this.shh = new Shh(this); 2538 this.net = new Net(this); 2539 this.personal = new Personal(this); 2540 this.bzz = new Swarm(this); 2541 this.settings = new Settings(); 2542 this.version = { 2543 api: version.version 2544 }; 2545 this.providers = { 2546 HttpProvider: HttpProvider, 2547 IpcProvider: IpcProvider 2548 }; 2549 this._extend = extend(this); 2550 this._extend({ 2551 properties: properties() 2552 }); 2553 } 2554 2555 // expose providers on the class 2556 Web3.providers = { 2557 HttpProvider: HttpProvider, 2558 IpcProvider: IpcProvider 2559 }; 2560 2561 Web3.prototype.setProvider = function (provider) { 2562 this._requestManager.setProvider(provider); 2563 this.currentProvider = provider; 2564 }; 2565 2566 Web3.prototype.reset = function (keepIsSyncing) { 2567 this._requestManager.reset(keepIsSyncing); 2568 this.settings = new Settings(); 2569 }; 2570 2571 Web3.prototype.BigNumber = BigNumber; 2572 Web3.prototype.toHex = utils.toHex; 2573 Web3.prototype.toAscii = utils.toAscii; 2574 Web3.prototype.toUtf8 = utils.toUtf8; 2575 Web3.prototype.fromAscii = utils.fromAscii; 2576 Web3.prototype.fromUtf8 = utils.fromUtf8; 2577 Web3.prototype.toDecimal = utils.toDecimal; 2578 Web3.prototype.fromDecimal = utils.fromDecimal; 2579 Web3.prototype.toBigNumber = utils.toBigNumber; 2580 Web3.prototype.toWei = utils.toWei; 2581 Web3.prototype.fromWei = utils.fromWei; 2582 Web3.prototype.isAddress = utils.isAddress; 2583 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2584 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2585 Web3.prototype.isIBAN = utils.isIBAN; 2586 Web3.prototype.padLeft = utils.padLeft; 2587 Web3.prototype.padRight = utils.padRight; 2588 2589 2590 Web3.prototype.sha3 = function(string, options) { 2591 return '0x' + sha3(string, options); 2592 }; 2593 2594 /** 2595 * Transforms direct icap to address 2596 */ 2597 Web3.prototype.fromICAP = function (icap) { 2598 var iban = new Iban(icap); 2599 return iban.address(); 2600 }; 2601 2602 var properties = function () { 2603 return [ 2604 new Property({ 2605 name: 'version.node', 2606 getter: 'web3_clientVersion' 2607 }), 2608 new Property({ 2609 name: 'version.network', 2610 getter: 'net_version', 2611 inputFormatter: utils.toDecimal 2612 }), 2613 new Property({ 2614 name: 'version.ethereum', 2615 getter: 'eth_protocolVersion', 2616 inputFormatter: utils.toDecimal 2617 }), 2618 new Property({ 2619 name: 'version.whisper', 2620 getter: 'shh_version', 2621 inputFormatter: utils.toDecimal 2622 }) 2623 ]; 2624 }; 2625 2626 Web3.prototype.isConnected = function(){ 2627 return (this.currentProvider && this.currentProvider.isConnected()); 2628 }; 2629 2630 Web3.prototype.createBatch = function () { 2631 return new Batch(this); 2632 }; 2633 2634 module.exports = Web3; 2635 2636 2637 },{"./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/methods/shh":41,"./web3/methods/swarm":42,"./web3/property":45,"./web3/requestmanager":46,"./web3/settings":47,"bignumber.js":"bignumber.js"}],23:[function(require,module,exports){ 2638 /* 2639 This file is part of web3.js. 2640 2641 web3.js is free software: you can redistribute it and/or modify 2642 it under the terms of the GNU Lesser General Public License as published by 2643 the Free Software Foundation, either version 3 of the License, or 2644 (at your option) any later version. 2645 2646 web3.js is distributed in the hope that it will be useful, 2647 but WITHOUT ANY WARRANTY; without even the implied warranty of 2648 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2649 GNU Lesser General Public License for more details. 2650 2651 You should have received a copy of the GNU Lesser General Public License 2652 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2653 */ 2654 /** 2655 * @file allevents.js 2656 * @author Marek Kotewicz <marek@ethdev.com> 2657 * @date 2014 2658 */ 2659 2660 var sha3 = require('../utils/sha3'); 2661 var SolidityEvent = require('./event'); 2662 var formatters = require('./formatters'); 2663 var utils = require('../utils/utils'); 2664 var Filter = require('./filter'); 2665 var watches = require('./methods/watches'); 2666 2667 var AllSolidityEvents = function (requestManager, json, address) { 2668 this._requestManager = requestManager; 2669 this._json = json; 2670 this._address = address; 2671 }; 2672 2673 AllSolidityEvents.prototype.encode = function (options) { 2674 options = options || {}; 2675 var result = {}; 2676 2677 ['fromBlock', 'toBlock'].filter(function (f) { 2678 return options[f] !== undefined; 2679 }).forEach(function (f) { 2680 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2681 }); 2682 2683 result.address = this._address; 2684 2685 return result; 2686 }; 2687 2688 AllSolidityEvents.prototype.decode = function (data) { 2689 data.data = data.data || ''; 2690 data.topics = data.topics || []; 2691 2692 var eventTopic = data.topics[0].slice(2); 2693 var match = this._json.filter(function (j) { 2694 return eventTopic === sha3(utils.transformToFullName(j)); 2695 })[0]; 2696 2697 if (!match) { // cannot find matching event? 2698 console.warn('cannot find event for log'); 2699 return data; 2700 } 2701 2702 var event = new SolidityEvent(this._requestManager, match, this._address); 2703 return event.decode(data); 2704 }; 2705 2706 AllSolidityEvents.prototype.execute = function (options, callback) { 2707 2708 if (utils.isFunction(arguments[arguments.length - 1])) { 2709 callback = arguments[arguments.length - 1]; 2710 if(arguments.length === 1) 2711 options = null; 2712 } 2713 2714 var o = this.encode(options); 2715 var formatter = this.decode.bind(this); 2716 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 2717 }; 2718 2719 AllSolidityEvents.prototype.attachToContract = function (contract) { 2720 var execute = this.execute.bind(this); 2721 contract.allEvents = execute; 2722 }; 2723 2724 module.exports = AllSolidityEvents; 2725 2726 2727 },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){ 2728 /* 2729 This file is part of web3.js. 2730 2731 web3.js is free software: you can redistribute it and/or modify 2732 it under the terms of the GNU Lesser General Public License as published by 2733 the Free Software Foundation, either version 3 of the License, or 2734 (at your option) any later version. 2735 2736 web3.js is distributed in the hope that it will be useful, 2737 but WITHOUT ANY WARRANTY; without even the implied warranty of 2738 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2739 GNU Lesser General Public License for more details. 2740 2741 You should have received a copy of the GNU Lesser General Public License 2742 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2743 */ 2744 /** 2745 * @file batch.js 2746 * @author Marek Kotewicz <marek@ethdev.com> 2747 * @date 2015 2748 */ 2749 2750 var Jsonrpc = require('./jsonrpc'); 2751 var errors = require('./errors'); 2752 2753 var Batch = function (web3) { 2754 this.requestManager = web3._requestManager; 2755 this.requests = []; 2756 }; 2757 2758 /** 2759 * Should be called to add create new request to batch request 2760 * 2761 * @method add 2762 * @param {Object} jsonrpc requet object 2763 */ 2764 Batch.prototype.add = function (request) { 2765 this.requests.push(request); 2766 }; 2767 2768 /** 2769 * Should be called to execute batch request 2770 * 2771 * @method execute 2772 */ 2773 Batch.prototype.execute = function () { 2774 var requests = this.requests; 2775 this.requestManager.sendBatch(requests, function (err, results) { 2776 results = results || []; 2777 requests.map(function (request, index) { 2778 return results[index] || {}; 2779 }).forEach(function (result, index) { 2780 if (requests[index].callback) { 2781 2782 if (!Jsonrpc.isValidResponse(result)) { 2783 return requests[index].callback(errors.InvalidResponse(result)); 2784 } 2785 2786 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2787 } 2788 }); 2789 }); 2790 }; 2791 2792 module.exports = Batch; 2793 2794 2795 },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){ 2796 /* 2797 This file is part of web3.js. 2798 2799 web3.js is free software: you can redistribute it and/or modify 2800 it under the terms of the GNU Lesser General Public License as published by 2801 the Free Software Foundation, either version 3 of the License, or 2802 (at your option) any later version. 2803 2804 web3.js is distributed in the hope that it will be useful, 2805 but WITHOUT ANY WARRANTY; without even the implied warranty of 2806 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2807 GNU Lesser General Public License for more details. 2808 2809 You should have received a copy of the GNU Lesser General Public License 2810 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2811 */ 2812 /** 2813 * @file contract.js 2814 * @author Marek Kotewicz <marek@ethdev.com> 2815 * @date 2014 2816 */ 2817 2818 var utils = require('../utils/utils'); 2819 var coder = require('../solidity/coder'); 2820 var SolidityEvent = require('./event'); 2821 var SolidityFunction = require('./function'); 2822 var AllEvents = require('./allevents'); 2823 2824 /** 2825 * Should be called to encode constructor params 2826 * 2827 * @method encodeConstructorParams 2828 * @param {Array} abi 2829 * @param {Array} constructor params 2830 */ 2831 var encodeConstructorParams = function (abi, params) { 2832 return abi.filter(function (json) { 2833 return json.type === 'constructor' && json.inputs.length === params.length; 2834 }).map(function (json) { 2835 return json.inputs.map(function (input) { 2836 return input.type; 2837 }); 2838 }).map(function (types) { 2839 return coder.encodeParams(types, params); 2840 })[0] || ''; 2841 }; 2842 2843 /** 2844 * Should be called to add functions to contract object 2845 * 2846 * @method addFunctionsToContract 2847 * @param {Contract} contract 2848 * @param {Array} abi 2849 */ 2850 var addFunctionsToContract = function (contract) { 2851 contract.abi.filter(function (json) { 2852 return json.type === 'function'; 2853 }).map(function (json) { 2854 return new SolidityFunction(contract._eth, json, contract.address); 2855 }).forEach(function (f) { 2856 f.attachToContract(contract); 2857 }); 2858 }; 2859 2860 /** 2861 * Should be called to add events to contract object 2862 * 2863 * @method addEventsToContract 2864 * @param {Contract} contract 2865 * @param {Array} abi 2866 */ 2867 var addEventsToContract = function (contract) { 2868 var events = contract.abi.filter(function (json) { 2869 return json.type === 'event'; 2870 }); 2871 2872 var All = new AllEvents(contract._eth._requestManager, events, contract.address); 2873 All.attachToContract(contract); 2874 2875 events.map(function (json) { 2876 return new SolidityEvent(contract._eth._requestManager, json, contract.address); 2877 }).forEach(function (e) { 2878 e.attachToContract(contract); 2879 }); 2880 }; 2881 2882 2883 /** 2884 * Should be called to check if the contract gets properly deployed on the blockchain. 2885 * 2886 * @method checkForContractAddress 2887 * @param {Object} contract 2888 * @param {Function} callback 2889 * @returns {Undefined} 2890 */ 2891 var checkForContractAddress = function(contract, callback){ 2892 var count = 0, 2893 callbackFired = false; 2894 2895 // wait for receipt 2896 var filter = contract._eth.filter('latest', function(e){ 2897 if (!e && !callbackFired) { 2898 count++; 2899 2900 // stop watching after 50 blocks (timeout) 2901 if (count > 50) { 2902 2903 filter.stopWatching(function() {}); 2904 callbackFired = true; 2905 2906 if (callback) 2907 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2908 else 2909 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2910 2911 2912 } else { 2913 2914 contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 2915 if(receipt && !callbackFired) { 2916 2917 contract._eth.getCode(receipt.contractAddress, function(e, code){ 2918 /*jshint maxcomplexity: 6 */ 2919 2920 if(callbackFired || !code) 2921 return; 2922 2923 filter.stopWatching(function() {}); 2924 callbackFired = true; 2925 2926 if(code.length > 3) { 2927 2928 // console.log('Contract code deployed!'); 2929 2930 contract.address = receipt.contractAddress; 2931 2932 // attach events and methods again after we have 2933 addFunctionsToContract(contract); 2934 addEventsToContract(contract); 2935 2936 // call callback for the second time 2937 if(callback) 2938 callback(null, contract); 2939 2940 } else { 2941 if(callback) 2942 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 2943 else 2944 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 2945 } 2946 }); 2947 } 2948 }); 2949 } 2950 } 2951 }); 2952 }; 2953 2954 /** 2955 * Should be called to create new ContractFactory instance 2956 * 2957 * @method ContractFactory 2958 * @param {Array} abi 2959 */ 2960 var ContractFactory = function (eth, abi) { 2961 this.eth = eth; 2962 this.abi = abi; 2963 2964 /** 2965 * Should be called to create new contract on a blockchain 2966 * 2967 * @method new 2968 * @param {Any} contract constructor param1 (optional) 2969 * @param {Any} contract constructor param2 (optional) 2970 * @param {Object} contract transaction object (required) 2971 * @param {Function} callback 2972 * @returns {Contract} returns contract instance 2973 */ 2974 this.new = function () { 2975 /*jshint maxcomplexity: 7 */ 2976 2977 var contract = new Contract(this.eth, this.abi); 2978 2979 // parse arguments 2980 var options = {}; // required! 2981 var callback; 2982 2983 var args = Array.prototype.slice.call(arguments); 2984 if (utils.isFunction(args[args.length - 1])) { 2985 callback = args.pop(); 2986 } 2987 2988 var last = args[args.length - 1]; 2989 if (utils.isObject(last) && !utils.isArray(last)) { 2990 options = args.pop(); 2991 } 2992 2993 if (options.value > 0) { 2994 var constructorAbi = abi.filter(function (json) { 2995 return json.type === 'constructor' && json.inputs.length === args.length; 2996 })[0] || {}; 2997 2998 if (!constructorAbi.payable) { 2999 throw new Error('Cannot send value to non-payable constructor'); 3000 } 3001 } 3002 3003 var bytes = encodeConstructorParams(this.abi, args); 3004 options.data += bytes; 3005 3006 if (callback) { 3007 3008 // wait for the contract address adn check if the code was deployed 3009 this.eth.sendTransaction(options, function (err, hash) { 3010 if (err) { 3011 callback(err); 3012 } else { 3013 // add the transaction hash 3014 contract.transactionHash = hash; 3015 3016 // call callback for the first time 3017 callback(null, contract); 3018 3019 checkForContractAddress(contract, callback); 3020 } 3021 }); 3022 } else { 3023 var hash = this.eth.sendTransaction(options); 3024 // add the transaction hash 3025 contract.transactionHash = hash; 3026 checkForContractAddress(contract); 3027 } 3028 3029 return contract; 3030 }; 3031 3032 this.new.getData = this.getData.bind(this); 3033 }; 3034 3035 /** 3036 * Should be called to create new ContractFactory 3037 * 3038 * @method contract 3039 * @param {Array} abi 3040 * @returns {ContractFactory} new contract factory 3041 */ 3042 //var contract = function (abi) { 3043 //return new ContractFactory(abi); 3044 //}; 3045 3046 3047 3048 /** 3049 * Should be called to get access to existing contract on a blockchain 3050 * 3051 * @method at 3052 * @param {Address} contract address (required) 3053 * @param {Function} callback {optional) 3054 * @returns {Contract} returns contract if no callback was passed, 3055 * otherwise calls callback function (err, contract) 3056 */ 3057 ContractFactory.prototype.at = function (address, callback) { 3058 var contract = new Contract(this.eth, this.abi, address); 3059 3060 // this functions are not part of prototype, 3061 // because we dont want to spoil the interface 3062 addFunctionsToContract(contract); 3063 addEventsToContract(contract); 3064 3065 if (callback) { 3066 callback(null, contract); 3067 } 3068 return contract; 3069 }; 3070 3071 /** 3072 * Gets the data, which is data to deploy plus constructor params 3073 * 3074 * @method getData 3075 */ 3076 ContractFactory.prototype.getData = function () { 3077 var options = {}; // required! 3078 var args = Array.prototype.slice.call(arguments); 3079 3080 var last = args[args.length - 1]; 3081 if (utils.isObject(last) && !utils.isArray(last)) { 3082 options = args.pop(); 3083 } 3084 3085 var bytes = encodeConstructorParams(this.abi, args); 3086 options.data += bytes; 3087 3088 return options.data; 3089 }; 3090 3091 /** 3092 * Should be called to create new contract instance 3093 * 3094 * @method Contract 3095 * @param {Array} abi 3096 * @param {Address} contract address 3097 */ 3098 var Contract = function (eth, abi, address) { 3099 this._eth = eth; 3100 this.transactionHash = null; 3101 this.address = address; 3102 this.abi = abi; 3103 }; 3104 3105 module.exports = ContractFactory; 3106 3107 },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){ 3108 /* 3109 This file is part of web3.js. 3110 3111 web3.js is free software: you can redistribute it and/or modify 3112 it under the terms of the GNU Lesser General Public License as published by 3113 the Free Software Foundation, either version 3 of the License, or 3114 (at your option) any later version. 3115 3116 web3.js is distributed in the hope that it will be useful, 3117 but WITHOUT ANY WARRANTY; without even the implied warranty of 3118 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3119 GNU Lesser General Public License for more details. 3120 3121 You should have received a copy of the GNU Lesser General Public License 3122 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3123 */ 3124 /** 3125 * @file errors.js 3126 * @author Marek Kotewicz <marek@ethdev.com> 3127 * @date 2015 3128 */ 3129 3130 module.exports = { 3131 InvalidNumberOfSolidityArgs: function () { 3132 return new Error('Invalid number of arguments to Solidity function'); 3133 }, 3134 InvalidNumberOfRPCParams: function () { 3135 return new Error('Invalid number of input parameters to RPC method'); 3136 }, 3137 InvalidConnection: function (host){ 3138 return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 3139 }, 3140 InvalidProvider: function () { 3141 return new Error('Provider not set or invalid'); 3142 }, 3143 InvalidResponse: function (result){ 3144 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3145 return new Error(message); 3146 }, 3147 ConnectionTimeout: function (ms){ 3148 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3149 } 3150 }; 3151 3152 },{}],27:[function(require,module,exports){ 3153 /* 3154 This file is part of web3.js. 3155 3156 web3.js is free software: you can redistribute it and/or modify 3157 it under the terms of the GNU Lesser General Public License as published by 3158 the Free Software Foundation, either version 3 of the License, or 3159 (at your option) any later version. 3160 3161 web3.js is distributed in the hope that it will be useful, 3162 but WITHOUT ANY WARRANTY; without even the implied warranty of 3163 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3164 GNU Lesser General Public License for more details. 3165 3166 You should have received a copy of the GNU Lesser General Public License 3167 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3168 */ 3169 /** 3170 * @file event.js 3171 * @author Marek Kotewicz <marek@ethdev.com> 3172 * @date 2014 3173 */ 3174 3175 var utils = require('../utils/utils'); 3176 var coder = require('../solidity/coder'); 3177 var formatters = require('./formatters'); 3178 var sha3 = require('../utils/sha3'); 3179 var Filter = require('./filter'); 3180 var watches = require('./methods/watches'); 3181 3182 /** 3183 * This prototype should be used to create event filters 3184 */ 3185 var SolidityEvent = function (requestManager, json, address) { 3186 this._requestManager = requestManager; 3187 this._params = json.inputs; 3188 this._name = utils.transformToFullName(json); 3189 this._address = address; 3190 this._anonymous = json.anonymous; 3191 }; 3192 3193 /** 3194 * Should be used to get filtered param types 3195 * 3196 * @method types 3197 * @param {Bool} decide if returned typed should be indexed 3198 * @return {Array} array of types 3199 */ 3200 SolidityEvent.prototype.types = function (indexed) { 3201 return this._params.filter(function (i) { 3202 return i.indexed === indexed; 3203 }).map(function (i) { 3204 return i.type; 3205 }); 3206 }; 3207 3208 /** 3209 * Should be used to get event display name 3210 * 3211 * @method displayName 3212 * @return {String} event display name 3213 */ 3214 SolidityEvent.prototype.displayName = function () { 3215 return utils.extractDisplayName(this._name); 3216 }; 3217 3218 /** 3219 * Should be used to get event type name 3220 * 3221 * @method typeName 3222 * @return {String} event type name 3223 */ 3224 SolidityEvent.prototype.typeName = function () { 3225 return utils.extractTypeName(this._name); 3226 }; 3227 3228 /** 3229 * Should be used to get event signature 3230 * 3231 * @method signature 3232 * @return {String} event signature 3233 */ 3234 SolidityEvent.prototype.signature = function () { 3235 return sha3(this._name); 3236 }; 3237 3238 /** 3239 * Should be used to encode indexed params and options to one final object 3240 * 3241 * @method encode 3242 * @param {Object} indexed 3243 * @param {Object} options 3244 * @return {Object} everything combined together and encoded 3245 */ 3246 SolidityEvent.prototype.encode = function (indexed, options) { 3247 indexed = indexed || {}; 3248 options = options || {}; 3249 var result = {}; 3250 3251 ['fromBlock', 'toBlock'].filter(function (f) { 3252 return options[f] !== undefined; 3253 }).forEach(function (f) { 3254 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3255 }); 3256 3257 result.topics = []; 3258 3259 result.address = this._address; 3260 if (!this._anonymous) { 3261 result.topics.push('0x' + this.signature()); 3262 } 3263 3264 var indexedTopics = this._params.filter(function (i) { 3265 return i.indexed === true; 3266 }).map(function (i) { 3267 var value = indexed[i.name]; 3268 if (value === undefined || value === null) { 3269 return null; 3270 } 3271 3272 if (utils.isArray(value)) { 3273 return value.map(function (v) { 3274 return '0x' + coder.encodeParam(i.type, v); 3275 }); 3276 } 3277 return '0x' + coder.encodeParam(i.type, value); 3278 }); 3279 3280 result.topics = result.topics.concat(indexedTopics); 3281 3282 return result; 3283 }; 3284 3285 /** 3286 * Should be used to decode indexed params and options 3287 * 3288 * @method decode 3289 * @param {Object} data 3290 * @return {Object} result object with decoded indexed && not indexed params 3291 */ 3292 SolidityEvent.prototype.decode = function (data) { 3293 3294 data.data = data.data || ''; 3295 data.topics = data.topics || []; 3296 3297 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3298 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3299 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3300 3301 var notIndexedData = data.data.slice(2); 3302 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3303 3304 var result = formatters.outputLogFormatter(data); 3305 result.event = this.displayName(); 3306 result.address = data.address; 3307 3308 result.args = this._params.reduce(function (acc, current) { 3309 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3310 return acc; 3311 }, {}); 3312 3313 delete result.data; 3314 delete result.topics; 3315 3316 return result; 3317 }; 3318 3319 /** 3320 * Should be used to create new filter object from event 3321 * 3322 * @method execute 3323 * @param {Object} indexed 3324 * @param {Object} options 3325 * @return {Object} filter object 3326 */ 3327 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3328 3329 if (utils.isFunction(arguments[arguments.length - 1])) { 3330 callback = arguments[arguments.length - 1]; 3331 if(arguments.length === 2) 3332 options = null; 3333 if(arguments.length === 1) { 3334 options = null; 3335 indexed = {}; 3336 } 3337 } 3338 3339 var o = this.encode(indexed, options); 3340 var formatter = this.decode.bind(this); 3341 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 3342 }; 3343 3344 /** 3345 * Should be used to attach event to contract object 3346 * 3347 * @method attachToContract 3348 * @param {Contract} 3349 */ 3350 SolidityEvent.prototype.attachToContract = function (contract) { 3351 var execute = this.execute.bind(this); 3352 var displayName = this.displayName(); 3353 if (!contract[displayName]) { 3354 contract[displayName] = execute; 3355 } 3356 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3357 }; 3358 3359 module.exports = SolidityEvent; 3360 3361 3362 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){ 3363 var formatters = require('./formatters'); 3364 var utils = require('./../utils/utils'); 3365 var Method = require('./method'); 3366 var Property = require('./property'); 3367 3368 // TODO: refactor, so the input params are not altered. 3369 // it's necessary to make same 'extension' work with multiple providers 3370 var extend = function (web3) { 3371 /* jshint maxcomplexity:5 */ 3372 var ex = function (extension) { 3373 3374 var extendedObject; 3375 if (extension.property) { 3376 if (!web3[extension.property]) { 3377 web3[extension.property] = {}; 3378 } 3379 extendedObject = web3[extension.property]; 3380 } else { 3381 extendedObject = web3; 3382 } 3383 3384 if (extension.methods) { 3385 extension.methods.forEach(function (method) { 3386 method.attachToObject(extendedObject); 3387 method.setRequestManager(web3._requestManager); 3388 }); 3389 } 3390 3391 if (extension.properties) { 3392 extension.properties.forEach(function (property) { 3393 property.attachToObject(extendedObject); 3394 property.setRequestManager(web3._requestManager); 3395 }); 3396 } 3397 }; 3398 3399 ex.formatters = formatters; 3400 ex.utils = utils; 3401 ex.Method = Method; 3402 ex.Property = Property; 3403 3404 return ex; 3405 }; 3406 3407 3408 3409 module.exports = extend; 3410 3411 3412 },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){ 3413 /* 3414 This file is part of web3.js. 3415 3416 web3.js is free software: you can redistribute it and/or modify 3417 it under the terms of the GNU Lesser General Public License as published by 3418 the Free Software Foundation, either version 3 of the License, or 3419 (at your option) any later version. 3420 3421 web3.js is distributed in the hope that it will be useful, 3422 but WITHOUT ANY WARRANTY; without even the implied warranty of 3423 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3424 GNU Lesser General Public License for more details. 3425 3426 You should have received a copy of the GNU Lesser General Public License 3427 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3428 */ 3429 /** @file filter.js 3430 * @authors: 3431 * Jeffrey Wilcke <jeff@ethdev.com> 3432 * Marek Kotewicz <marek@ethdev.com> 3433 * Marian Oancea <marian@ethdev.com> 3434 * Fabian Vogelsteller <fabian@ethdev.com> 3435 * Gav Wood <g@ethdev.com> 3436 * @date 2014 3437 */ 3438 3439 var formatters = require('./formatters'); 3440 var utils = require('../utils/utils'); 3441 3442 /** 3443 * Converts a given topic to a hex string, but also allows null values. 3444 * 3445 * @param {Mixed} value 3446 * @return {String} 3447 */ 3448 var toTopic = function(value){ 3449 3450 if(value === null || typeof value === 'undefined') 3451 return null; 3452 3453 value = String(value); 3454 3455 if(value.indexOf('0x') === 0) 3456 return value; 3457 else 3458 return utils.fromUtf8(value); 3459 }; 3460 3461 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3462 /// @param should be string or object 3463 /// @returns options string or object 3464 var getOptions = function (options, type) { 3465 /*jshint maxcomplexity: 6 */ 3466 3467 if (utils.isString(options)) { 3468 return options; 3469 } 3470 3471 options = options || {}; 3472 3473 3474 switch(type) { 3475 case 'eth': 3476 3477 // make sure topics, get converted to hex 3478 options.topics = options.topics || []; 3479 options.topics = options.topics.map(function(topic){ 3480 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3481 }); 3482 3483 return { 3484 topics: options.topics, 3485 from: options.from, 3486 to: options.to, 3487 address: options.address, 3488 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3489 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3490 }; 3491 case 'shh': 3492 return options; 3493 } 3494 }; 3495 3496 /** 3497 Adds the callback and sets up the methods, to iterate over the results. 3498 3499 @method getLogsAtStart 3500 @param {Object} self 3501 @param {function} callback 3502 */ 3503 var getLogsAtStart = function(self, callback){ 3504 // call getFilterLogs for the first watch callback start 3505 if (!utils.isString(self.options)) { 3506 self.get(function (err, messages) { 3507 // don't send all the responses to all the watches again... just to self one 3508 if (err) { 3509 callback(err); 3510 } 3511 3512 if(utils.isArray(messages)) { 3513 messages.forEach(function (message) { 3514 callback(null, message); 3515 }); 3516 } 3517 }); 3518 } 3519 }; 3520 3521 /** 3522 Adds the callback and sets up the methods, to iterate over the results. 3523 3524 @method pollFilter 3525 @param {Object} self 3526 */ 3527 var pollFilter = function(self) { 3528 3529 var onMessage = function (error, messages) { 3530 if (error) { 3531 return self.callbacks.forEach(function (callback) { 3532 callback(error); 3533 }); 3534 } 3535 3536 if(utils.isArray(messages)) { 3537 messages.forEach(function (message) { 3538 message = self.formatter ? self.formatter(message) : message; 3539 self.callbacks.forEach(function (callback) { 3540 callback(null, message); 3541 }); 3542 }); 3543 } 3544 }; 3545 3546 self.requestManager.startPolling({ 3547 method: self.implementation.poll.call, 3548 params: [self.filterId], 3549 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3550 3551 }; 3552 3553 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3554 var self = this; 3555 var implementation = {}; 3556 methods.forEach(function (method) { 3557 method.setRequestManager(requestManager); 3558 method.attachToObject(implementation); 3559 }); 3560 this.requestManager = requestManager; 3561 this.options = getOptions(options, type); 3562 this.implementation = implementation; 3563 this.filterId = null; 3564 this.callbacks = []; 3565 this.getLogsCallbacks = []; 3566 this.pollFilters = []; 3567 this.formatter = formatter; 3568 this.implementation.newFilter(this.options, function(error, id){ 3569 if(error) { 3570 self.callbacks.forEach(function(cb){ 3571 cb(error); 3572 }); 3573 if (typeof filterCreationErrorCallback === 'function') { 3574 filterCreationErrorCallback(error); 3575 } 3576 } else { 3577 self.filterId = id; 3578 3579 // check if there are get pending callbacks as a consequence 3580 // of calling get() with filterId unassigned. 3581 self.getLogsCallbacks.forEach(function (cb){ 3582 self.get(cb); 3583 }); 3584 self.getLogsCallbacks = []; 3585 3586 // get filter logs for the already existing watch calls 3587 self.callbacks.forEach(function(cb){ 3588 getLogsAtStart(self, cb); 3589 }); 3590 if(self.callbacks.length > 0) 3591 pollFilter(self); 3592 3593 // start to watch immediately 3594 if(typeof callback === 'function') { 3595 return self.watch(callback); 3596 } 3597 } 3598 }); 3599 3600 return this; 3601 }; 3602 3603 Filter.prototype.watch = function (callback) { 3604 this.callbacks.push(callback); 3605 3606 if(this.filterId) { 3607 getLogsAtStart(this, callback); 3608 pollFilter(this); 3609 } 3610 3611 return this; 3612 }; 3613 3614 Filter.prototype.stopWatching = function (callback) { 3615 this.requestManager.stopPolling(this.filterId); 3616 this.callbacks = []; 3617 // remove filter async 3618 if (callback) { 3619 this.implementation.uninstallFilter(this.filterId, callback); 3620 } else { 3621 return this.implementation.uninstallFilter(this.filterId); 3622 } 3623 }; 3624 3625 Filter.prototype.get = function (callback) { 3626 var self = this; 3627 if (utils.isFunction(callback)) { 3628 if (this.filterId === null) { 3629 // If filterId is not set yet, call it back 3630 // when newFilter() assigns it. 3631 this.getLogsCallbacks.push(callback); 3632 } else { 3633 this.implementation.getLogs(this.filterId, function(err, res){ 3634 if (err) { 3635 callback(err); 3636 } else { 3637 callback(null, res.map(function (log) { 3638 return self.formatter ? self.formatter(log) : log; 3639 })); 3640 } 3641 }); 3642 } 3643 } else { 3644 if (this.filterId === null) { 3645 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3646 } 3647 var logs = this.implementation.getLogs(this.filterId); 3648 return logs.map(function (log) { 3649 return self.formatter ? self.formatter(log) : log; 3650 }); 3651 } 3652 3653 return this; 3654 }; 3655 3656 module.exports = Filter; 3657 3658 3659 },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){ 3660 'use strict' 3661 3662 /* 3663 This file is part of web3.js. 3664 3665 web3.js is free software: you can redistribute it and/or modify 3666 it under the terms of the GNU Lesser General Public License as published by 3667 the Free Software Foundation, either version 3 of the License, or 3668 (at your option) any later version. 3669 3670 web3.js is distributed in the hope that it will be useful, 3671 but WITHOUT ANY WARRANTY; without even the implied warranty of 3672 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3673 GNU Lesser General Public License for more details. 3674 3675 You should have received a copy of the GNU Lesser General Public License 3676 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3677 */ 3678 /** 3679 * @file formatters.js 3680 * @author Marek Kotewicz <marek@ethdev.com> 3681 * @author Fabian Vogelsteller <fabian@ethdev.com> 3682 * @date 2015 3683 */ 3684 3685 var utils = require('../utils/utils'); 3686 var config = require('../utils/config'); 3687 var Iban = require('./iban'); 3688 3689 /** 3690 * Should the format output to a big number 3691 * 3692 * @method outputBigNumberFormatter 3693 * @param {String|Number|BigNumber} 3694 * @returns {BigNumber} object 3695 */ 3696 var outputBigNumberFormatter = function (number) { 3697 return utils.toBigNumber(number); 3698 }; 3699 3700 var isPredefinedBlockNumber = function (blockNumber) { 3701 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3702 }; 3703 3704 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3705 if (blockNumber === undefined) { 3706 return config.defaultBlock; 3707 } 3708 return inputBlockNumberFormatter(blockNumber); 3709 }; 3710 3711 var inputBlockNumberFormatter = function (blockNumber) { 3712 if (blockNumber === undefined) { 3713 return undefined; 3714 } else if (isPredefinedBlockNumber(blockNumber)) { 3715 return blockNumber; 3716 } 3717 return utils.toHex(blockNumber); 3718 }; 3719 3720 /** 3721 * Formats the input of a transaction and converts all values to HEX 3722 * 3723 * @method inputCallFormatter 3724 * @param {Object} transaction options 3725 * @returns object 3726 */ 3727 var inputCallFormatter = function (options){ 3728 3729 options.from = options.from || config.defaultAccount; 3730 3731 if (options.from) { 3732 options.from = inputAddressFormatter(options.from); 3733 } 3734 3735 if (options.to) { // it might be contract creation 3736 options.to = inputAddressFormatter(options.to); 3737 } 3738 3739 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3740 return options[key] !== undefined; 3741 }).forEach(function(key){ 3742 options[key] = utils.fromDecimal(options[key]); 3743 }); 3744 3745 return options; 3746 }; 3747 3748 /** 3749 * Formats the input of a transaction and converts all values to HEX 3750 * 3751 * @method inputTransactionFormatter 3752 * @param {Object} transaction options 3753 * @returns object 3754 */ 3755 var inputTransactionFormatter = function (options){ 3756 3757 options.from = options.from || config.defaultAccount; 3758 options.from = inputAddressFormatter(options.from); 3759 3760 if (options.to) { // it might be contract creation 3761 options.to = inputAddressFormatter(options.to); 3762 } 3763 3764 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3765 return options[key] !== undefined; 3766 }).forEach(function(key){ 3767 options[key] = utils.fromDecimal(options[key]); 3768 }); 3769 3770 return options; 3771 }; 3772 3773 /** 3774 * Formats the output of a transaction to its proper values 3775 * 3776 * @method outputTransactionFormatter 3777 * @param {Object} tx 3778 * @returns {Object} 3779 */ 3780 var outputTransactionFormatter = function (tx){ 3781 if(tx.blockNumber !== null) 3782 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3783 if(tx.transactionIndex !== null) 3784 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3785 tx.nonce = utils.toDecimal(tx.nonce); 3786 tx.gas = utils.toDecimal(tx.gas); 3787 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3788 tx.value = utils.toBigNumber(tx.value); 3789 return tx; 3790 }; 3791 3792 /** 3793 * Formats the output of a transaction receipt to its proper values 3794 * 3795 * @method outputTransactionReceiptFormatter 3796 * @param {Object} receipt 3797 * @returns {Object} 3798 */ 3799 var outputTransactionReceiptFormatter = function (receipt){ 3800 if(receipt.blockNumber !== null) 3801 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3802 if(receipt.transactionIndex !== null) 3803 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3804 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3805 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3806 3807 if(utils.isArray(receipt.logs)) { 3808 receipt.logs = receipt.logs.map(function(log){ 3809 return outputLogFormatter(log); 3810 }); 3811 } 3812 3813 return receipt; 3814 }; 3815 var outputBlockInfoFormatter = function(Signs) { 3816 Signs.forEach(function(Sign){ 3817 Sign.account = inputAddressFormatter(Sign.account); 3818 if(Sign.validate){ 3819 Sign.validate = "true"; 3820 }else{ 3821 Sign.validate = "false"; 3822 } 3823 }) 3824 return Signs; 3825 }; 3826 /** 3827 * Formats the output of a block to its proper values 3828 * 3829 * @method outputBlockFormatter 3830 * @param {Object} block 3831 * @returns {Object} 3832 */ 3833 var outputBlockFormatter = function(block) { 3834 3835 // transform to number 3836 block.gasLimit = utils.toDecimal(block.gasLimit); 3837 block.gasUsed = utils.toDecimal(block.gasUsed); 3838 block.size = utils.toDecimal(block.size); 3839 block.timestamp = utils.toDecimal(block.timestamp); 3840 if(block.number !== null) 3841 block.number = utils.toDecimal(block.number); 3842 3843 block.difficulty = utils.toBigNumber(block.difficulty); 3844 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3845 3846 if (utils.isArray(block.transactions)) { 3847 block.transactions.forEach(function(item){ 3848 if(!utils.isString(item)) 3849 return outputTransactionFormatter(item); 3850 }); 3851 } 3852 3853 return block; 3854 }; 3855 3856 /** 3857 * Formats the output of a log 3858 * 3859 * @method outputLogFormatter 3860 * @param {Object} log object 3861 * @returns {Object} log 3862 */ 3863 var outputLogFormatter = function(log) { 3864 if(log.blockNumber) 3865 log.blockNumber = utils.toDecimal(log.blockNumber); 3866 if(log.transactionIndex) 3867 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3868 if(log.logIndex) 3869 log.logIndex = utils.toDecimal(log.logIndex); 3870 3871 return log; 3872 }; 3873 3874 /** 3875 * Formats the input of a whisper post and converts all values to HEX 3876 * 3877 * @method inputPostFormatter 3878 * @param {Object} transaction object 3879 * @returns {Object} 3880 */ 3881 var inputPostFormatter = function(post) { 3882 3883 // post.payload = utils.toHex(post.payload); 3884 post.ttl = utils.fromDecimal(post.ttl); 3885 post.workToProve = utils.fromDecimal(post.workToProve); 3886 post.priority = utils.fromDecimal(post.priority); 3887 3888 // fallback 3889 if (!utils.isArray(post.topics)) { 3890 post.topics = post.topics ? [post.topics] : []; 3891 } 3892 3893 // format the following options 3894 post.topics = post.topics.map(function(topic){ 3895 // convert only if not hex 3896 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3897 }); 3898 3899 return post; 3900 }; 3901 3902 /** 3903 * Formats the output of a received post message 3904 * 3905 * @method outputPostFormatter 3906 * @param {Object} 3907 * @returns {Object} 3908 */ 3909 var outputPostFormatter = function(post){ 3910 3911 post.expiry = utils.toDecimal(post.expiry); 3912 post.sent = utils.toDecimal(post.sent); 3913 post.ttl = utils.toDecimal(post.ttl); 3914 post.workProved = utils.toDecimal(post.workProved); 3915 // post.payloadRaw = post.payload; 3916 // post.payload = utils.toAscii(post.payload); 3917 3918 // if (utils.isJson(post.payload)) { 3919 // post.payload = JSON.parse(post.payload); 3920 // } 3921 3922 // format the following options 3923 if (!post.topics) { 3924 post.topics = []; 3925 } 3926 post.topics = post.topics.map(function(topic){ 3927 return utils.toAscii(topic); 3928 }); 3929 3930 return post; 3931 }; 3932 3933 var inputAddressFormatter = function (address) { 3934 var iban = new Iban(address); 3935 if (iban.isValid() && iban.isDirect()) { 3936 return '0x' + iban.address(); 3937 } else if (utils.isStrictAddress(address)) { 3938 return address; 3939 } else if (utils.isAddress(address)) { 3940 return '0x' + address; 3941 } 3942 throw new Error('invalid address'); 3943 }; 3944 3945 3946 var outputSyncingFormatter = function(result) { 3947 if (!result) { 3948 return result; 3949 } 3950 3951 result.startingBlock = utils.toDecimal(result.startingBlock); 3952 result.currentBlock = utils.toDecimal(result.currentBlock); 3953 result.highestBlock = utils.toDecimal(result.highestBlock); 3954 if (result.knownStates) { 3955 result.knownStates = utils.toDecimal(result.knownStates); 3956 result.pulledStates = utils.toDecimal(result.pulledStates); 3957 } 3958 3959 return result; 3960 }; 3961 3962 module.exports = { 3963 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 3964 inputBlockNumberFormatter: inputBlockNumberFormatter, 3965 inputCallFormatter: inputCallFormatter, 3966 inputTransactionFormatter: inputTransactionFormatter, 3967 inputAddressFormatter: inputAddressFormatter, 3968 inputPostFormatter: inputPostFormatter, 3969 outputBigNumberFormatter: outputBigNumberFormatter, 3970 outputTransactionFormatter: outputTransactionFormatter, 3971 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 3972 outputBlockFormatter: outputBlockFormatter, 3973 outputBlockInfoFormatter:outputBlockInfoFormatter, 3974 outputLogFormatter: outputLogFormatter, 3975 outputPostFormatter: outputPostFormatter, 3976 outputSyncingFormatter: outputSyncingFormatter 3977 }; 3978 3979 3980 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 3981 /* 3982 This file is part of web3.js. 3983 3984 web3.js is free software: you can redistribute it and/or modify 3985 it under the terms of the GNU Lesser General Public License as published by 3986 the Free Software Foundation, either version 3 of the License, or 3987 (at your option) any later version. 3988 3989 web3.js is distributed in the hope that it will be useful, 3990 but WITHOUT ANY WARRANTY; without even the implied warranty of 3991 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3992 GNU Lesser General Public License for more details. 3993 3994 You should have received a copy of the GNU Lesser General Public License 3995 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3996 */ 3997 /** 3998 * @file function.js 3999 * @author Marek Kotewicz <marek@ethdev.com> 4000 * @date 2015 4001 */ 4002 4003 var coder = require('../solidity/coder'); 4004 var utils = require('../utils/utils'); 4005 var errors = require('./errors'); 4006 var formatters = require('./formatters'); 4007 var sha3 = require('../utils/sha3'); 4008 4009 /** 4010 * This prototype should be used to call/sendTransaction to solidity functions 4011 */ 4012 var SolidityFunction = function (eth, json, address) { 4013 this._eth = eth; 4014 this._inputTypes = json.inputs.map(function (i) { 4015 return i.type; 4016 }); 4017 this._outputTypes = json.outputs.map(function (i) { 4018 return i.type; 4019 }); 4020 this._constant = json.constant; 4021 this._payable = json.payable; 4022 this._name = utils.transformToFullName(json); 4023 this._address = address; 4024 }; 4025 4026 SolidityFunction.prototype.extractCallback = function (args) { 4027 if (utils.isFunction(args[args.length - 1])) { 4028 return args.pop(); // modify the args array! 4029 } 4030 }; 4031 4032 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4033 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4034 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4035 } 4036 }; 4037 4038 /** 4039 * Should be called to check if the number of arguments is correct 4040 * 4041 * @method validateArgs 4042 * @param {Array} arguments 4043 * @throws {Error} if it is not 4044 */ 4045 SolidityFunction.prototype.validateArgs = function (args) { 4046 var inputArgs = args.filter(function (a) { 4047 // filter the options object but not arguments that are arrays 4048 return !( (utils.isObject(a) === true) && 4049 (utils.isArray(a) === false) && 4050 (utils.isBigNumber(a) === false) 4051 ); 4052 }); 4053 if (inputArgs.length !== this._inputTypes.length) { 4054 throw errors.InvalidNumberOfSolidityArgs(); 4055 } 4056 }; 4057 4058 /** 4059 * Should be used to create payload from arguments 4060 * 4061 * @method toPayload 4062 * @param {Array} solidity function params 4063 * @param {Object} optional payload options 4064 */ 4065 SolidityFunction.prototype.toPayload = function (args) { 4066 var options = {}; 4067 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4068 options = args[args.length - 1]; 4069 } 4070 this.validateArgs(args); 4071 options.to = this._address; 4072 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4073 return options; 4074 }; 4075 4076 /** 4077 * Should be used to get function signature 4078 * 4079 * @method signature 4080 * @return {String} function signature 4081 */ 4082 SolidityFunction.prototype.signature = function () { 4083 return sha3(this._name).slice(0, 8); 4084 }; 4085 4086 4087 SolidityFunction.prototype.unpackOutput = function (output) { 4088 if (!output) { 4089 return; 4090 } 4091 4092 output = output.length >= 2 ? output.slice(2) : output; 4093 var result = coder.decodeParams(this._outputTypes, output); 4094 return result.length === 1 ? result[0] : result; 4095 }; 4096 4097 /** 4098 * Calls a contract function. 4099 * 4100 * @method call 4101 * @param {...Object} Contract function arguments 4102 * @param {function} If the last argument is a function, the contract function 4103 * call will be asynchronous, and the callback will be passed the 4104 * error and result. 4105 * @return {String} output bytes 4106 */ 4107 SolidityFunction.prototype.call = function () { 4108 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4109 var callback = this.extractCallback(args); 4110 var defaultBlock = this.extractDefaultBlock(args); 4111 var payload = this.toPayload(args); 4112 4113 4114 if (!callback) { 4115 var output = this._eth.call(payload, defaultBlock); 4116 return this.unpackOutput(output); 4117 } 4118 4119 var self = this; 4120 this._eth.call(payload, defaultBlock, function (error, output) { 4121 if (error) return callback(error, null); 4122 4123 var unpacked = null; 4124 try { 4125 unpacked = self.unpackOutput(output); 4126 } 4127 catch (e) { 4128 error = e; 4129 } 4130 4131 callback(error, unpacked); 4132 }); 4133 }; 4134 4135 /** 4136 * Should be used to sendTransaction to solidity function 4137 * 4138 * @method sendTransaction 4139 */ 4140 SolidityFunction.prototype.sendTransaction = function () { 4141 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4142 var callback = this.extractCallback(args); 4143 var payload = this.toPayload(args); 4144 4145 if (payload.value > 0 && !this._payable) { 4146 throw new Error('Cannot send value to non-payable function'); 4147 } 4148 4149 if (!callback) { 4150 return this._eth.sendTransaction(payload); 4151 } 4152 4153 this._eth.sendTransaction(payload, callback); 4154 }; 4155 4156 /** 4157 * Should be used to estimateGas of solidity function 4158 * 4159 * @method estimateGas 4160 */ 4161 SolidityFunction.prototype.estimateGas = function () { 4162 var args = Array.prototype.slice.call(arguments); 4163 var callback = this.extractCallback(args); 4164 var payload = this.toPayload(args); 4165 4166 if (!callback) { 4167 return this._eth.estimateGas(payload); 4168 } 4169 4170 this._eth.estimateGas(payload, callback); 4171 }; 4172 4173 /** 4174 * Return the encoded data of the call 4175 * 4176 * @method getData 4177 * @return {String} the encoded data 4178 */ 4179 SolidityFunction.prototype.getData = function () { 4180 var args = Array.prototype.slice.call(arguments); 4181 var payload = this.toPayload(args); 4182 4183 return payload.data; 4184 }; 4185 4186 /** 4187 * Should be used to get function display name 4188 * 4189 * @method displayName 4190 * @return {String} display name of the function 4191 */ 4192 SolidityFunction.prototype.displayName = function () { 4193 return utils.extractDisplayName(this._name); 4194 }; 4195 4196 /** 4197 * Should be used to get function type name 4198 * 4199 * @method typeName 4200 * @return {String} type name of the function 4201 */ 4202 SolidityFunction.prototype.typeName = function () { 4203 return utils.extractTypeName(this._name); 4204 }; 4205 4206 /** 4207 * Should be called to get rpc requests from solidity function 4208 * 4209 * @method request 4210 * @returns {Object} 4211 */ 4212 SolidityFunction.prototype.request = function () { 4213 var args = Array.prototype.slice.call(arguments); 4214 var callback = this.extractCallback(args); 4215 var payload = this.toPayload(args); 4216 var format = this.unpackOutput.bind(this); 4217 4218 return { 4219 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4220 callback: callback, 4221 params: [payload], 4222 format: format 4223 }; 4224 }; 4225 4226 /** 4227 * Should be called to execute function 4228 * 4229 * @method execute 4230 */ 4231 SolidityFunction.prototype.execute = function () { 4232 var transaction = !this._constant; 4233 4234 // send transaction 4235 if (transaction) { 4236 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4237 } 4238 4239 // call 4240 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4241 }; 4242 4243 /** 4244 * Should be called to attach function to contract 4245 * 4246 * @method attachToContract 4247 * @param {Contract} 4248 */ 4249 SolidityFunction.prototype.attachToContract = function (contract) { 4250 var execute = this.execute.bind(this); 4251 execute.request = this.request.bind(this); 4252 execute.call = this.call.bind(this); 4253 execute.sendTransaction = this.sendTransaction.bind(this); 4254 execute.estimateGas = this.estimateGas.bind(this); 4255 execute.getData = this.getData.bind(this); 4256 var displayName = this.displayName(); 4257 if (!contract[displayName]) { 4258 contract[displayName] = execute; 4259 } 4260 contract[displayName][this.typeName()] = execute; // circular!!!! 4261 }; 4262 4263 module.exports = SolidityFunction; 4264 4265 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4266 /* 4267 This file is part of web3.js. 4268 4269 web3.js is free software: you can redistribute it and/or modify 4270 it under the terms of the GNU Lesser General Public License as published by 4271 the Free Software Foundation, either version 3 of the License, or 4272 (at your option) any later version. 4273 4274 web3.js is distributed in the hope that it will be useful, 4275 but WITHOUT ANY WARRANTY; without even the implied warranty of 4276 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4277 GNU Lesser General Public License for more details. 4278 4279 You should have received a copy of the GNU Lesser General Public License 4280 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4281 */ 4282 /** @file httpprovider.js 4283 * @authors: 4284 * Marek Kotewicz <marek@ethdev.com> 4285 * Marian Oancea <marian@ethdev.com> 4286 * Fabian Vogelsteller <fabian@ethdev.com> 4287 * @date 2015 4288 */ 4289 4290 var errors = require('./errors'); 4291 4292 // workaround to use httpprovider in different envs 4293 4294 // browser 4295 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4296 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4297 // node 4298 } else { 4299 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4300 } 4301 4302 var XHR2 = require('xhr2'); // jshint ignore: line 4303 4304 /** 4305 * HttpProvider should be used to send rpc calls over http 4306 */ 4307 var HttpProvider = function (host, timeout, user, password) { 4308 this.host = host || 'http://localhost:8545'; 4309 this.timeout = timeout || 0; 4310 this.user = user; 4311 this.password = password; 4312 }; 4313 4314 /** 4315 * Should be called to prepare new XMLHttpRequest 4316 * 4317 * @method prepareRequest 4318 * @param {Boolean} true if request should be async 4319 * @return {XMLHttpRequest} object 4320 */ 4321 HttpProvider.prototype.prepareRequest = function (async) { 4322 var request; 4323 4324 if (async) { 4325 request = new XHR2(); 4326 request.timeout = this.timeout; 4327 } else { 4328 request = new XMLHttpRequest(); 4329 } 4330 4331 request.open('POST', this.host, async); 4332 if (this.user && this.password) { 4333 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4334 request.setRequestHeader('Authorization', auth); 4335 } request.setRequestHeader('Content-Type', 'application/json'); 4336 return request; 4337 }; 4338 4339 /** 4340 * Should be called to make sync request 4341 * 4342 * @method send 4343 * @param {Object} payload 4344 * @return {Object} result 4345 */ 4346 HttpProvider.prototype.send = function (payload) { 4347 var request = this.prepareRequest(false); 4348 4349 try { 4350 request.send(JSON.stringify(payload)); 4351 } catch (error) { 4352 throw errors.InvalidConnection(this.host); 4353 } 4354 4355 var result = request.responseText; 4356 4357 try { 4358 result = JSON.parse(result); 4359 } catch (e) { 4360 throw errors.InvalidResponse(request.responseText); 4361 } 4362 4363 return result; 4364 }; 4365 4366 /** 4367 * Should be used to make async request 4368 * 4369 * @method sendAsync 4370 * @param {Object} payload 4371 * @param {Function} callback triggered on end with (err, result) 4372 */ 4373 HttpProvider.prototype.sendAsync = function (payload, callback) { 4374 var request = this.prepareRequest(true); 4375 4376 request.onreadystatechange = function () { 4377 if (request.readyState === 4 && request.timeout !== 1) { 4378 var result = request.responseText; 4379 var error = null; 4380 4381 try { 4382 result = JSON.parse(result); 4383 } catch (e) { 4384 error = errors.InvalidResponse(request.responseText); 4385 } 4386 4387 callback(error, result); 4388 } 4389 }; 4390 4391 request.ontimeout = function () { 4392 callback(errors.ConnectionTimeout(this.timeout)); 4393 }; 4394 4395 try { 4396 request.send(JSON.stringify(payload)); 4397 } catch (error) { 4398 callback(errors.InvalidConnection(this.host)); 4399 } 4400 }; 4401 4402 /** 4403 * Synchronously tries to make Http request 4404 * 4405 * @method isConnected 4406 * @return {Boolean} returns true if request haven't failed. Otherwise false 4407 */ 4408 HttpProvider.prototype.isConnected = function () { 4409 try { 4410 this.send({ 4411 id: 9999999999, 4412 jsonrpc: '2.0', 4413 method: 'net_listening', 4414 params: [] 4415 }); 4416 return true; 4417 } catch (e) { 4418 return false; 4419 } 4420 }; 4421 4422 module.exports = HttpProvider; 4423 4424 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4425 /* 4426 This file is part of web3.js. 4427 4428 web3.js is free software: you can redistribute it and/or modify 4429 it under the terms of the GNU Lesser General Public License as published by 4430 the Free Software Foundation, either version 3 of the License, or 4431 (at your option) any later version. 4432 4433 web3.js is distributed in the hope that it will be useful, 4434 but WITHOUT ANY WARRANTY; without even the implied warranty of 4435 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4436 GNU Lesser General Public License for more details. 4437 4438 You should have received a copy of the GNU Lesser General Public License 4439 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4440 */ 4441 /** 4442 * @file iban.js 4443 * @author Marek Kotewicz <marek@ethdev.com> 4444 * @date 2015 4445 */ 4446 4447 var BigNumber = require('bignumber.js'); 4448 4449 var padLeft = function (string, bytes) { 4450 var result = string; 4451 while (result.length < bytes * 2) { 4452 result = '0' + result; 4453 } 4454 return result; 4455 }; 4456 4457 /** 4458 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4459 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4460 * 4461 * @method iso13616Prepare 4462 * @param {String} iban the IBAN 4463 * @returns {String} the prepared IBAN 4464 */ 4465 var iso13616Prepare = function (iban) { 4466 var A = 'A'.charCodeAt(0); 4467 var Z = 'Z'.charCodeAt(0); 4468 4469 iban = iban.toUpperCase(); 4470 iban = iban.substr(4) + iban.substr(0,4); 4471 4472 return iban.split('').map(function(n){ 4473 var code = n.charCodeAt(0); 4474 if (code >= A && code <= Z){ 4475 // A = 10, B = 11, ... Z = 35 4476 return code - A + 10; 4477 } else { 4478 return n; 4479 } 4480 }).join(''); 4481 }; 4482 4483 /** 4484 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4485 * 4486 * @method mod9710 4487 * @param {String} iban 4488 * @returns {Number} 4489 */ 4490 var mod9710 = function (iban) { 4491 var remainder = iban, 4492 block; 4493 4494 while (remainder.length > 2){ 4495 block = remainder.slice(0, 9); 4496 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4497 } 4498 4499 return parseInt(remainder, 10) % 97; 4500 }; 4501 4502 /** 4503 * This prototype should be used to create iban object from iban correct string 4504 * 4505 * @param {String} iban 4506 */ 4507 var Iban = function (iban) { 4508 this._iban = iban; 4509 }; 4510 4511 /** 4512 * This method should be used to create iban object from ethereum address 4513 * 4514 * @method fromAddress 4515 * @param {String} address 4516 * @return {Iban} the IBAN object 4517 */ 4518 Iban.fromAddress = function (address) { 4519 var asBn = new BigNumber(address, 16); 4520 var base36 = asBn.toString(36); 4521 var padded = padLeft(base36, 15); 4522 return Iban.fromBban(padded.toUpperCase()); 4523 }; 4524 4525 /** 4526 * Convert the passed BBAN to an IBAN for this country specification. 4527 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4528 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4529 * 4530 * @method fromBban 4531 * @param {String} bban the BBAN to convert to IBAN 4532 * @returns {Iban} the IBAN object 4533 */ 4534 Iban.fromBban = function (bban) { 4535 var countryCode = 'XE'; 4536 4537 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4538 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4539 4540 return new Iban(countryCode + checkDigit + bban); 4541 }; 4542 4543 /** 4544 * Should be used to create IBAN object for given institution and identifier 4545 * 4546 * @method createIndirect 4547 * @param {Object} options, required options are "institution" and "identifier" 4548 * @return {Iban} the IBAN object 4549 */ 4550 Iban.createIndirect = function (options) { 4551 return Iban.fromBban('ETH' + options.institution + options.identifier); 4552 }; 4553 4554 /** 4555 * Thos method should be used to check if given string is valid iban object 4556 * 4557 * @method isValid 4558 * @param {String} iban string 4559 * @return {Boolean} true if it is valid IBAN 4560 */ 4561 Iban.isValid = function (iban) { 4562 var i = new Iban(iban); 4563 return i.isValid(); 4564 }; 4565 4566 /** 4567 * Should be called to check if iban is correct 4568 * 4569 * @method isValid 4570 * @returns {Boolean} true if it is, otherwise false 4571 */ 4572 Iban.prototype.isValid = function () { 4573 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4574 mod9710(iso13616Prepare(this._iban)) === 1; 4575 }; 4576 4577 /** 4578 * Should be called to check if iban number is direct 4579 * 4580 * @method isDirect 4581 * @returns {Boolean} true if it is, otherwise false 4582 */ 4583 Iban.prototype.isDirect = function () { 4584 return this._iban.length === 34 || this._iban.length === 35; 4585 }; 4586 4587 /** 4588 * Should be called to check if iban number if indirect 4589 * 4590 * @method isIndirect 4591 * @returns {Boolean} true if it is, otherwise false 4592 */ 4593 Iban.prototype.isIndirect = function () { 4594 return this._iban.length === 20; 4595 }; 4596 4597 /** 4598 * Should be called to get iban checksum 4599 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4600 * 4601 * @method checksum 4602 * @returns {String} checksum 4603 */ 4604 Iban.prototype.checksum = function () { 4605 return this._iban.substr(2, 2); 4606 }; 4607 4608 /** 4609 * Should be called to get institution identifier 4610 * eg. XREG 4611 * 4612 * @method institution 4613 * @returns {String} institution identifier 4614 */ 4615 Iban.prototype.institution = function () { 4616 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4617 }; 4618 4619 /** 4620 * Should be called to get client identifier within institution 4621 * eg. GAVOFYORK 4622 * 4623 * @method client 4624 * @returns {String} client identifier 4625 */ 4626 Iban.prototype.client = function () { 4627 return this.isIndirect() ? this._iban.substr(11) : ''; 4628 }; 4629 4630 /** 4631 * Should be called to get client direct address 4632 * 4633 * @method address 4634 * @returns {String} client direct address 4635 */ 4636 Iban.prototype.address = function () { 4637 if (this.isDirect()) { 4638 var base36 = this._iban.substr(4); 4639 var asBn = new BigNumber(base36, 36); 4640 return padLeft(asBn.toString(16), 20); 4641 } 4642 4643 return ''; 4644 }; 4645 4646 Iban.prototype.toString = function () { 4647 return this._iban; 4648 }; 4649 4650 module.exports = Iban; 4651 4652 4653 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4654 /* 4655 This file is part of web3.js. 4656 4657 web3.js is free software: you can redistribute it and/or modify 4658 it under the terms of the GNU Lesser General Public License as published by 4659 the Free Software Foundation, either version 3 of the License, or 4660 (at your option) any later version. 4661 4662 web3.js is distributed in the hope that it will be useful, 4663 but WITHOUT ANY WARRANTY; without even the implied warranty of 4664 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4665 GNU Lesser General Public License for more details. 4666 4667 You should have received a copy of the GNU Lesser General Public License 4668 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4669 */ 4670 /** @file ipcprovider.js 4671 * @authors: 4672 * Fabian Vogelsteller <fabian@ethdev.com> 4673 * @date 2015 4674 */ 4675 4676 "use strict"; 4677 4678 var utils = require('../utils/utils'); 4679 var errors = require('./errors'); 4680 4681 4682 var IpcProvider = function (path, net) { 4683 var _this = this; 4684 this.responseCallbacks = {}; 4685 this.path = path; 4686 4687 this.connection = net.connect({path: this.path}); 4688 4689 this.connection.on('error', function(e){ 4690 console.error('IPC Connection Error', e); 4691 _this._timeout(); 4692 }); 4693 4694 this.connection.on('end', function(){ 4695 _this._timeout(); 4696 }); 4697 4698 4699 // LISTEN FOR CONNECTION RESPONSES 4700 this.connection.on('data', function(data) { 4701 /*jshint maxcomplexity: 6 */ 4702 4703 _this._parseResponse(data.toString()).forEach(function(result){ 4704 4705 var id = null; 4706 4707 // get the id which matches the returned id 4708 if(utils.isArray(result)) { 4709 result.forEach(function(load){ 4710 if(_this.responseCallbacks[load.id]) 4711 id = load.id; 4712 }); 4713 } else { 4714 id = result.id; 4715 } 4716 4717 // fire the callback 4718 if(_this.responseCallbacks[id]) { 4719 _this.responseCallbacks[id](null, result); 4720 delete _this.responseCallbacks[id]; 4721 } 4722 }); 4723 }); 4724 }; 4725 4726 /** 4727 Will parse the response and make an array out of it. 4728 4729 @method _parseResponse 4730 @param {String} data 4731 */ 4732 IpcProvider.prototype._parseResponse = function(data) { 4733 var _this = this, 4734 returnValues = []; 4735 4736 // DE-CHUNKER 4737 var dechunkedData = data 4738 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4739 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4740 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4741 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4742 .split('|--|'); 4743 4744 dechunkedData.forEach(function(data){ 4745 4746 // prepend the last chunk 4747 if(_this.lastChunk) 4748 data = _this.lastChunk + data; 4749 4750 var result = null; 4751 4752 try { 4753 result = JSON.parse(data); 4754 4755 } catch(e) { 4756 4757 _this.lastChunk = data; 4758 4759 // start timeout to cancel all requests 4760 clearTimeout(_this.lastChunkTimeout); 4761 _this.lastChunkTimeout = setTimeout(function(){ 4762 _this._timeout(); 4763 throw errors.InvalidResponse(data); 4764 }, 1000 * 15); 4765 4766 return; 4767 } 4768 4769 // cancel timeout and set chunk to null 4770 clearTimeout(_this.lastChunkTimeout); 4771 _this.lastChunk = null; 4772 4773 if(result) 4774 returnValues.push(result); 4775 }); 4776 4777 return returnValues; 4778 }; 4779 4780 4781 /** 4782 Get the adds a callback to the responseCallbacks object, 4783 which will be called if a response matching the response Id will arrive. 4784 4785 @method _addResponseCallback 4786 */ 4787 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4788 var id = payload.id || payload[0].id; 4789 var method = payload.method || payload[0].method; 4790 4791 this.responseCallbacks[id] = callback; 4792 this.responseCallbacks[id].method = method; 4793 }; 4794 4795 /** 4796 Timeout all requests when the end/error event is fired 4797 4798 @method _timeout 4799 */ 4800 IpcProvider.prototype._timeout = function() { 4801 for(var key in this.responseCallbacks) { 4802 if(this.responseCallbacks.hasOwnProperty(key)){ 4803 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4804 delete this.responseCallbacks[key]; 4805 } 4806 } 4807 }; 4808 4809 4810 /** 4811 Check if the current connection is still valid. 4812 4813 @method isConnected 4814 */ 4815 IpcProvider.prototype.isConnected = function() { 4816 var _this = this; 4817 4818 // try reconnect, when connection is gone 4819 if(!_this.connection.writable) 4820 _this.connection.connect({path: _this.path}); 4821 4822 return !!this.connection.writable; 4823 }; 4824 4825 IpcProvider.prototype.send = function (payload) { 4826 4827 if(this.connection.writeSync) { 4828 var result; 4829 4830 // try reconnect, when connection is gone 4831 if(!this.connection.writable) 4832 this.connection.connect({path: this.path}); 4833 4834 var data = this.connection.writeSync(JSON.stringify(payload)); 4835 4836 try { 4837 result = JSON.parse(data); 4838 } catch(e) { 4839 throw errors.InvalidResponse(data); 4840 } 4841 4842 return result; 4843 4844 } else { 4845 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4846 } 4847 }; 4848 4849 IpcProvider.prototype.sendAsync = function (payload, callback) { 4850 // try reconnect, when connection is gone 4851 if(!this.connection.writable) 4852 this.connection.connect({path: this.path}); 4853 4854 4855 this.connection.write(JSON.stringify(payload)); 4856 this._addResponseCallback(payload, callback); 4857 }; 4858 4859 module.exports = IpcProvider; 4860 4861 4862 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 4863 /* 4864 This file is part of web3.js. 4865 4866 web3.js is free software: you can redistribute it and/or modify 4867 it under the terms of the GNU Lesser General Public License as published by 4868 the Free Software Foundation, either version 3 of the License, or 4869 (at your option) any later version. 4870 4871 web3.js is distributed in the hope that it will be useful, 4872 but WITHOUT ANY WARRANTY; without even the implied warranty of 4873 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4874 GNU Lesser General Public License for more details. 4875 4876 You should have received a copy of the GNU Lesser General Public License 4877 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4878 */ 4879 /** @file jsonrpc.js 4880 * @authors: 4881 * Marek Kotewicz <marek@ethdev.com> 4882 * Aaron Kumavis <aaron@kumavis.me> 4883 * @date 2015 4884 */ 4885 4886 // Initialize Jsonrpc as a simple object with utility functions. 4887 var Jsonrpc = { 4888 messageId: 0 4889 }; 4890 4891 /** 4892 * Should be called to valid json create payload object 4893 * 4894 * @method toPayload 4895 * @param {Function} method of jsonrpc call, required 4896 * @param {Array} params, an array of method params, optional 4897 * @returns {Object} valid jsonrpc payload object 4898 */ 4899 Jsonrpc.toPayload = function (method, params) { 4900 if (!method) 4901 console.error('jsonrpc method should be specified!'); 4902 4903 // advance message ID 4904 Jsonrpc.messageId++; 4905 4906 return { 4907 jsonrpc: '2.0', 4908 id: Jsonrpc.messageId, 4909 method: method, 4910 params: params || [] 4911 }; 4912 }; 4913 4914 /** 4915 * Should be called to check if jsonrpc response is valid 4916 * 4917 * @method isValidResponse 4918 * @param {Object} 4919 * @returns {Boolean} true if response is valid, otherwise false 4920 */ 4921 Jsonrpc.isValidResponse = function (response) { 4922 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4923 4924 function validateSingleMessage(message){ 4925 return !!message && 4926 !message.error && 4927 message.jsonrpc === '2.0' && 4928 typeof message.id === 'number' && 4929 message.result !== undefined; // only undefined is not valid json object 4930 } 4931 }; 4932 4933 /** 4934 * Should be called to create batch payload object 4935 * 4936 * @method toBatchPayload 4937 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4938 * @returns {Array} batch payload 4939 */ 4940 Jsonrpc.toBatchPayload = function (messages) { 4941 return messages.map(function (message) { 4942 return Jsonrpc.toPayload(message.method, message.params); 4943 }); 4944 }; 4945 4946 module.exports = Jsonrpc; 4947 4948 4949 },{}],36:[function(require,module,exports){ 4950 /* 4951 This file is part of web3.js. 4952 4953 web3.js is free software: you can redistribute it and/or modify 4954 it under the terms of the GNU Lesser General Public License as published by 4955 the Free Software Foundation, either version 3 of the License, or 4956 (at your option) any later version. 4957 4958 web3.js is distributed in the hope that it will be useful, 4959 but WITHOUT ANY WARRANTY; without even the implied warranty of 4960 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4961 GNU Lesser General Public License for more details. 4962 4963 You should have received a copy of the GNU Lesser General Public License 4964 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4965 */ 4966 /** 4967 * @file method.js 4968 * @author Marek Kotewicz <marek@ethdev.com> 4969 * @date 2015 4970 */ 4971 4972 var utils = require('../utils/utils'); 4973 var errors = require('./errors'); 4974 4975 var Method = function (options) { 4976 this.name = options.name; 4977 this.call = options.call; 4978 this.params = options.params || 0; 4979 this.inputFormatter = options.inputFormatter; 4980 this.outputFormatter = options.outputFormatter; 4981 this.requestManager = null; 4982 }; 4983 4984 Method.prototype.setRequestManager = function (rm) { 4985 this.requestManager = rm; 4986 }; 4987 4988 /** 4989 * Should be used to determine name of the jsonrpc method based on arguments 4990 * 4991 * @method getCall 4992 * @param {Array} arguments 4993 * @return {String} name of jsonrpc method 4994 */ 4995 Method.prototype.getCall = function (args) { 4996 return utils.isFunction(this.call) ? this.call(args) : this.call; 4997 }; 4998 4999 /** 5000 * Should be used to extract callback from array of arguments. Modifies input param 5001 * 5002 * @method extractCallback 5003 * @param {Array} arguments 5004 * @return {Function|Null} callback, if exists 5005 */ 5006 Method.prototype.extractCallback = function (args) { 5007 if (utils.isFunction(args[args.length - 1])) { 5008 return args.pop(); // modify the args array! 5009 } 5010 }; 5011 5012 /** 5013 * Should be called to check if the number of arguments is correct 5014 * 5015 * @method validateArgs 5016 * @param {Array} arguments 5017 * @throws {Error} if it is not 5018 */ 5019 Method.prototype.validateArgs = function (args) { 5020 if (args.length !== this.params) { 5021 throw errors.InvalidNumberOfRPCParams(); 5022 } 5023 }; 5024 5025 /** 5026 * Should be called to format input args of method 5027 * 5028 * @method formatInput 5029 * @param {Array} 5030 * @return {Array} 5031 */ 5032 Method.prototype.formatInput = function (args) { 5033 if (!this.inputFormatter) { 5034 return args; 5035 } 5036 5037 return this.inputFormatter.map(function (formatter, index) { 5038 return formatter ? formatter(args[index]) : args[index]; 5039 }); 5040 }; 5041 5042 /** 5043 * Should be called to format output(result) of method 5044 * 5045 * @method formatOutput 5046 * @param {Object} 5047 * @return {Object} 5048 */ 5049 Method.prototype.formatOutput = function (result) { 5050 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5051 }; 5052 5053 /** 5054 * Should create payload from given input args 5055 * 5056 * @method toPayload 5057 * @param {Array} args 5058 * @return {Object} 5059 */ 5060 Method.prototype.toPayload = function (args) { 5061 var call = this.getCall(args); 5062 var callback = this.extractCallback(args); 5063 var params = this.formatInput(args); 5064 this.validateArgs(params); 5065 5066 return { 5067 method: call, 5068 params: params, 5069 callback: callback 5070 }; 5071 }; 5072 5073 Method.prototype.attachToObject = function (obj) { 5074 var func = this.buildCall(); 5075 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5076 var name = this.name.split('.'); 5077 if (name.length > 1) { 5078 obj[name[0]] = obj[name[0]] || {}; 5079 obj[name[0]][name[1]] = func; 5080 } else { 5081 obj[name[0]] = func; 5082 } 5083 }; 5084 5085 Method.prototype.buildCall = function() { 5086 var method = this; 5087 var send = function () { 5088 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5089 if (payload.callback) { 5090 return method.requestManager.sendAsync(payload, function (err, result) { 5091 payload.callback(err, method.formatOutput(result)); 5092 }); 5093 } 5094 return method.formatOutput(method.requestManager.send(payload)); 5095 }; 5096 send.request = this.request.bind(this); 5097 return send; 5098 }; 5099 5100 /** 5101 * Should be called to create pure JSONRPC request which can be used in batch request 5102 * 5103 * @method request 5104 * @param {...} params 5105 * @return {Object} jsonrpc request 5106 */ 5107 Method.prototype.request = function () { 5108 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5109 payload.format = this.formatOutput.bind(this); 5110 return payload; 5111 }; 5112 5113 module.exports = Method; 5114 5115 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5116 /* 5117 This file is part of web3.js. 5118 5119 web3.js is free software: you can redistribute it and/or modify 5120 it under the terms of the GNU Lesser General Public License as published by 5121 the Free Software Foundation, either version 3 of the License, or 5122 (at your option) any later version. 5123 5124 web3.js is distributed in the hope that it will be useful, 5125 but WITHOUT ANY WARRANTY; without even the implied warranty of 5126 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5127 GNU Lesser General Public License for more details. 5128 5129 You should have received a copy of the GNU Lesser General Public License 5130 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5131 */ 5132 /** @file db.js 5133 * @authors: 5134 * Marek Kotewicz <marek@ethdev.com> 5135 * @date 2015 5136 */ 5137 5138 var Method = require('../method'); 5139 5140 var DB = function (web3) { 5141 this._requestManager = web3._requestManager; 5142 5143 var self = this; 5144 5145 methods().forEach(function(method) { 5146 method.attachToObject(self); 5147 method.setRequestManager(web3._requestManager); 5148 }); 5149 }; 5150 5151 var methods = function () { 5152 var putString = new Method({ 5153 name: 'putString', 5154 call: 'db_putString', 5155 params: 3 5156 }); 5157 5158 var getString = new Method({ 5159 name: 'getString', 5160 call: 'db_getString', 5161 params: 2 5162 }); 5163 5164 var putHex = new Method({ 5165 name: 'putHex', 5166 call: 'db_putHex', 5167 params: 3 5168 }); 5169 5170 var getHex = new Method({ 5171 name: 'getHex', 5172 call: 'db_getHex', 5173 params: 2 5174 }); 5175 5176 return [ 5177 putString, getString, putHex, getHex 5178 ]; 5179 }; 5180 5181 module.exports = DB; 5182 5183 },{"../method":36}],38:[function(require,module,exports){ 5184 /* 5185 This file is part of web3.js. 5186 5187 web3.js is free software: you can redistribute it and/or modify 5188 it under the terms of the GNU Lesser General Public License as published by 5189 the Free Software Foundation, either version 3 of the License, or 5190 (at your option) any later version. 5191 5192 web3.js is distributed in the hope that it will be useful, 5193 but WITHOUT ANY WARRANTY; without even the implied warranty of 5194 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5195 GNU Lesser General Public License for more details. 5196 5197 You should have received a copy of the GNU Lesser General Public License 5198 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5199 */ 5200 /** 5201 * @file eth.js 5202 * @author Marek Kotewicz <marek@ethdev.com> 5203 * @author Fabian Vogelsteller <fabian@ethdev.com> 5204 * @date 2015 5205 */ 5206 5207 "use strict"; 5208 5209 var formatters = require('../formatters'); 5210 var utils = require('../../utils/utils'); 5211 var Method = require('../method'); 5212 var Property = require('../property'); 5213 var c = require('../../utils/config'); 5214 var Contract = require('../contract'); 5215 var watches = require('./watches'); 5216 var Filter = require('../filter'); 5217 var IsSyncing = require('../syncing'); 5218 var namereg = require('../namereg'); 5219 var Iban = require('../iban'); 5220 var transfer = require('../transfer'); 5221 5222 var blockCall = function (args) { 5223 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockInfoByHash" : "eth_getBlockInfoByNumber"; 5224 }; 5225 5226 var transactionFromBlockCall = function (args) { 5227 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5228 }; 5229 5230 var uncleCall = function (args) { 5231 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5232 }; 5233 5234 var getBlockTransactionCountCall = function (args) { 5235 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5236 }; 5237 5238 var uncleCountCall = function (args) { 5239 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5240 }; 5241 5242 function Eth(web3) { 5243 this._requestManager = web3._requestManager; 5244 5245 var self = this; 5246 5247 methods().forEach(function(method) { 5248 method.attachToObject(self); 5249 method.setRequestManager(self._requestManager); 5250 }); 5251 5252 properties().forEach(function(p) { 5253 p.attachToObject(self); 5254 p.setRequestManager(self._requestManager); 5255 }); 5256 5257 5258 this.iban = Iban; 5259 this.sendIBANTransaction = transfer.bind(null, this); 5260 } 5261 5262 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5263 get: function () { 5264 return c.defaultBlock; 5265 }, 5266 set: function (val) { 5267 c.defaultBlock = val; 5268 return val; 5269 } 5270 }); 5271 5272 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5273 get: function () { 5274 return c.defaultAccount; 5275 }, 5276 set: function (val) { 5277 c.defaultAccount = val; 5278 return val; 5279 } 5280 }); 5281 5282 var methods = function () { 5283 var getBalance = new Method({ 5284 name: 'getBalance', 5285 call: 'eth_getBalance', 5286 params: 2, 5287 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5288 outputFormatter: formatters.outputBigNumberFormatter 5289 }); 5290 5291 var getStorageAt = new Method({ 5292 name: 'getStorageAt', 5293 call: 'eth_getStorageAt', 5294 params: 3, 5295 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5296 }); 5297 5298 var getCode = new Method({ 5299 name: 'getCode', 5300 call: 'eth_getCode', 5301 params: 2, 5302 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5303 }); 5304 5305 var getBlock = new Method({ 5306 name: 'getBlock', 5307 call: blockCall, 5308 params: 2, 5309 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5310 outputFormatter: formatters.outputBlockFormatter 5311 }); 5312 var getBlockInfo = new Method({ 5313 name: 'getBlockInfo', 5314 call: blockCall, 5315 params: 2, 5316 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5317 outputFormatter: formatters.outputBlockInfoFormatter 5318 }); 5319 var getUncle = new Method({ 5320 name: 'getUncle', 5321 call: uncleCall, 5322 params: 2, 5323 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5324 outputFormatter: formatters.outputBlockFormatter, 5325 5326 }); 5327 5328 var getCompilers = new Method({ 5329 name: 'getCompilers', 5330 call: 'eth_getCompilers', 5331 params: 0 5332 }); 5333 5334 var getBlockTransactionCount = new Method({ 5335 name: 'getBlockTransactionCount', 5336 call: getBlockTransactionCountCall, 5337 params: 1, 5338 inputFormatter: [formatters.inputBlockNumberFormatter], 5339 outputFormatter: utils.toDecimal 5340 }); 5341 5342 var getBlockUncleCount = new Method({ 5343 name: 'getBlockUncleCount', 5344 call: uncleCountCall, 5345 params: 1, 5346 inputFormatter: [formatters.inputBlockNumberFormatter], 5347 outputFormatter: utils.toDecimal 5348 }); 5349 5350 var getTransaction = new Method({ 5351 name: 'getTransaction', 5352 call: 'eth_getTransactionByHash', 5353 params: 1, 5354 outputFormatter: formatters.outputTransactionFormatter 5355 }); 5356 5357 var getTransactionFromBlock = new Method({ 5358 name: 'getTransactionFromBlock', 5359 call: transactionFromBlockCall, 5360 params: 2, 5361 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5362 outputFormatter: formatters.outputTransactionFormatter 5363 }); 5364 5365 var getTransactionReceipt = new Method({ 5366 name: 'getTransactionReceipt', 5367 call: 'eth_getTransactionReceipt', 5368 params: 1, 5369 outputFormatter: formatters.outputTransactionReceiptFormatter 5370 }); 5371 5372 var getTransactionCount = new Method({ 5373 name: 'getTransactionCount', 5374 call: 'eth_getTransactionCount', 5375 params: 2, 5376 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5377 outputFormatter: utils.toDecimal 5378 }); 5379 5380 var sendRawTransaction = new Method({ 5381 name: 'sendRawTransaction', 5382 call: 'eth_sendRawTransaction', 5383 params: 1, 5384 inputFormatter: [null] 5385 }); 5386 5387 var sendTransaction = new Method({ 5388 name: 'sendTransaction', 5389 call: 'eth_sendTransaction', 5390 params: 1, 5391 inputFormatter: [formatters.inputTransactionFormatter] 5392 }); 5393 5394 var signTransaction = new Method({ 5395 name: 'signTransaction', 5396 call: 'eth_signTransaction', 5397 params: 1, 5398 inputFormatter: [formatters.inputTransactionFormatter] 5399 }); 5400 5401 var sign = new Method({ 5402 name: 'sign', 5403 call: 'eth_sign', 5404 params: 2, 5405 inputFormatter: [formatters.inputAddressFormatter, null] 5406 }); 5407 5408 var call = new Method({ 5409 name: 'call', 5410 call: 'eth_call', 5411 params: 2, 5412 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5413 }); 5414 5415 var estimateGas = new Method({ 5416 name: 'estimateGas', 5417 call: 'eth_estimateGas', 5418 params: 1, 5419 inputFormatter: [formatters.inputCallFormatter], 5420 outputFormatter: utils.toDecimal 5421 }); 5422 5423 var compileSolidity = new Method({ 5424 name: 'compile.solidity', 5425 call: 'eth_compileSolidity', 5426 params: 1 5427 }); 5428 5429 var compileLLL = new Method({ 5430 name: 'compile.lll', 5431 call: 'eth_compileLLL', 5432 params: 1 5433 }); 5434 5435 var compileSerpent = new Method({ 5436 name: 'compile.serpent', 5437 call: 'eth_compileSerpent', 5438 params: 1 5439 }); 5440 5441 var submitWork = new Method({ 5442 name: 'submitWork', 5443 call: 'eth_submitWork', 5444 params: 3 5445 }); 5446 5447 var getWork = new Method({ 5448 name: 'getWork', 5449 call: 'eth_getWork', 5450 params: 0 5451 }); 5452 var createMpcAccount = new Method({ 5453 name: 'createMpcAccount', 5454 call: 'eth_createMpcAccount', 5455 params: 0 5456 }); 5457 return [ 5458 getBalance, 5459 getStorageAt, 5460 getCode, 5461 getBlock, 5462 getBlockInfo, 5463 getUncle, 5464 getCompilers, 5465 getBlockTransactionCount, 5466 getBlockUncleCount, 5467 getTransaction, 5468 getTransactionFromBlock, 5469 getTransactionReceipt, 5470 getTransactionCount, 5471 call, 5472 estimateGas, 5473 sendRawTransaction, 5474 signTransaction, 5475 sendTransaction, 5476 sign, 5477 compileSolidity, 5478 compileLLL, 5479 compileSerpent, 5480 submitWork, 5481 getWork, 5482 createMpcAccount 5483 ]; 5484 }; 5485 5486 5487 var properties = function () { 5488 return [ 5489 new Property({ 5490 name: 'coinbase', 5491 getter: 'eth_coinbase' 5492 }), 5493 new Property({ 5494 name: 'mining', 5495 getter: 'eth_mining' 5496 }), 5497 new Property({ 5498 name: 'hashrate', 5499 getter: 'eth_hashrate', 5500 outputFormatter: utils.toDecimal 5501 }), 5502 new Property({ 5503 name: 'syncing', 5504 getter: 'eth_syncing', 5505 outputFormatter: formatters.outputSyncingFormatter 5506 }), 5507 new Property({ 5508 name: 'gasPrice', 5509 getter: 'eth_gasPrice', 5510 outputFormatter: formatters.outputBigNumberFormatter 5511 }), 5512 new Property({ 5513 name: 'accounts', 5514 getter: 'eth_accounts' 5515 }), 5516 new Property({ 5517 name: 'blockNumber', 5518 getter: 'eth_blockNumber', 5519 outputFormatter: utils.toDecimal 5520 }), 5521 new Property({ 5522 name: 'protocolVersion', 5523 getter: 'eth_protocolVersion' 5524 }) 5525 ]; 5526 }; 5527 5528 Eth.prototype.contract = function (abi) { 5529 var factory = new Contract(this, abi); 5530 return factory; 5531 }; 5532 5533 Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5534 return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5535 }; 5536 5537 Eth.prototype.namereg = function () { 5538 return this.contract(namereg.global.abi).at(namereg.global.address); 5539 }; 5540 5541 Eth.prototype.icapNamereg = function () { 5542 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5543 }; 5544 5545 Eth.prototype.isSyncing = function (callback) { 5546 return new IsSyncing(this._requestManager, callback); 5547 }; 5548 5549 module.exports = Eth; 5550 5551 },{"../../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){ 5552 /* 5553 This file is part of web3.js. 5554 5555 web3.js is free software: you can redistribute it and/or modify 5556 it under the terms of the GNU Lesser General Public License as published by 5557 the Free Software Foundation, either version 3 of the License, or 5558 (at your option) any later version. 5559 5560 web3.js is distributed in the hope that it will be useful, 5561 but WITHOUT ANY WARRANTY; without even the implied warranty of 5562 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5563 GNU Lesser General Public License for more details. 5564 5565 You should have received a copy of the GNU Lesser General Public License 5566 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5567 */ 5568 /** @file eth.js 5569 * @authors: 5570 * Marek Kotewicz <marek@ethdev.com> 5571 * @date 2015 5572 */ 5573 5574 var utils = require('../../utils/utils'); 5575 var Property = require('../property'); 5576 5577 var Net = function (web3) { 5578 this._requestManager = web3._requestManager; 5579 5580 var self = this; 5581 5582 properties().forEach(function(p) { 5583 p.attachToObject(self); 5584 p.setRequestManager(web3._requestManager); 5585 }); 5586 }; 5587 5588 /// @returns an array of objects describing web3.eth api properties 5589 var properties = function () { 5590 return [ 5591 new Property({ 5592 name: 'listening', 5593 getter: 'net_listening' 5594 }), 5595 new Property({ 5596 name: 'peerCount', 5597 getter: 'net_peerCount', 5598 outputFormatter: utils.toDecimal 5599 }) 5600 ]; 5601 }; 5602 5603 module.exports = Net; 5604 5605 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 5606 /* 5607 This file is part of web3.js. 5608 5609 web3.js is free software: you can redistribute it and/or modify 5610 it under the terms of the GNU Lesser General Public License as published by 5611 the Free Software Foundation, either version 3 of the License, or 5612 (at your option) any later version. 5613 5614 web3.js is distributed in the hope that it will be useful, 5615 but WITHOUT ANY WARRANTY; without even the implied warranty of 5616 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5617 GNU Lesser General Public License for more details. 5618 5619 You should have received a copy of the GNU Lesser General Public License 5620 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5621 */ 5622 /** 5623 * @file eth.js 5624 * @author Marek Kotewicz <marek@ethdev.com> 5625 * @author Fabian Vogelsteller <fabian@ethdev.com> 5626 * @date 2015 5627 */ 5628 5629 "use strict"; 5630 5631 var Method = require('../method'); 5632 var Property = require('../property'); 5633 var formatters = require('../formatters'); 5634 5635 function Personal(web3) { 5636 this._requestManager = web3._requestManager; 5637 5638 var self = this; 5639 5640 methods().forEach(function(method) { 5641 method.attachToObject(self); 5642 method.setRequestManager(self._requestManager); 5643 }); 5644 5645 properties().forEach(function(p) { 5646 p.attachToObject(self); 5647 p.setRequestManager(self._requestManager); 5648 }); 5649 } 5650 5651 var methods = function () { 5652 var newAccount = new Method({ 5653 name: 'newAccount', 5654 call: 'personal_newAccount', 5655 params: 1, 5656 inputFormatter: [null] 5657 }); 5658 5659 var importRawKey = new Method({ 5660 name: 'importRawKey', 5661 call: 'personal_importRawKey', 5662 params: 2 5663 }); 5664 5665 var sign = new Method({ 5666 name: 'sign', 5667 call: 'personal_sign', 5668 params: 3, 5669 inputFormatter: [null, formatters.inputAddressFormatter, null] 5670 }); 5671 5672 var ecRecover = new Method({ 5673 name: 'ecRecover', 5674 call: 'personal_ecRecover', 5675 params: 2 5676 }); 5677 5678 var unlockAccount = new Method({ 5679 name: 'unlockAccount', 5680 call: 'personal_unlockAccount', 5681 params: 3, 5682 inputFormatter: [formatters.inputAddressFormatter, null, null] 5683 }); 5684 5685 var sendTransaction = new Method({ 5686 name: 'sendTransaction', 5687 call: 'personal_sendTransaction', 5688 params: 2, 5689 inputFormatter: [formatters.inputTransactionFormatter, null] 5690 }); 5691 5692 var lockAccount = new Method({ 5693 name: 'lockAccount', 5694 call: 'personal_lockAccount', 5695 params: 1, 5696 inputFormatter: [formatters.inputAddressFormatter] 5697 }); 5698 5699 return [ 5700 newAccount, 5701 importRawKey, 5702 unlockAccount, 5703 ecRecover, 5704 sign, 5705 sendTransaction, 5706 lockAccount 5707 ]; 5708 }; 5709 5710 var properties = function () { 5711 return [ 5712 new Property({ 5713 name: 'listAccounts', 5714 getter: 'personal_listAccounts' 5715 }) 5716 ]; 5717 }; 5718 5719 5720 module.exports = Personal; 5721 5722 },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){ 5723 /* 5724 This file is part of web3.js. 5725 5726 web3.js is free software: you can redistribute it and/or modify 5727 it under the terms of the GNU Lesser General Public License as published by 5728 the Free Software Foundation, either version 3 of the License, or 5729 (at your option) any later version. 5730 5731 web3.js is distributed in the hope that it will be useful, 5732 but WITHOUT ANY WARRANTY; without even the implied warranty of 5733 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5734 GNU Lesser General Public License for more details. 5735 5736 You should have received a copy of the GNU Lesser General Public License 5737 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5738 */ 5739 /** @file shh.js 5740 * @authors: 5741 * Fabian Vogelsteller <fabian@ethereum.org> 5742 * Marek Kotewicz <marek@ethcore.io> 5743 * @date 2017 5744 */ 5745 5746 var Method = require('../method'); 5747 var Filter = require('../filter'); 5748 var watches = require('./watches'); 5749 5750 var Shh = function (web3) { 5751 this._requestManager = web3._requestManager; 5752 5753 var self = this; 5754 5755 methods().forEach(function(method) { 5756 method.attachToObject(self); 5757 method.setRequestManager(self._requestManager); 5758 }); 5759 }; 5760 5761 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 5762 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 5763 }; 5764 5765 var methods = function () { 5766 5767 return [ 5768 new Method({ 5769 name: 'version', 5770 call: 'shh_version', 5771 params: 0 5772 }), 5773 new Method({ 5774 name: 'info', 5775 call: 'shh_info', 5776 params: 0 5777 }), 5778 new Method({ 5779 name: 'setMaxMessageSize', 5780 call: 'shh_setMaxMessageSize', 5781 params: 1 5782 }), 5783 new Method({ 5784 name: 'setMinPoW', 5785 call: 'shh_setMinPoW', 5786 params: 1 5787 }), 5788 new Method({ 5789 name: 'markTrustedPeer', 5790 call: 'shh_markTrustedPeer', 5791 params: 1 5792 }), 5793 new Method({ 5794 name: 'newKeyPair', 5795 call: 'shh_newKeyPair', 5796 params: 0 5797 }), 5798 new Method({ 5799 name: 'addPrivateKey', 5800 call: 'shh_addPrivateKey', 5801 params: 1 5802 }), 5803 new Method({ 5804 name: 'deleteKeyPair', 5805 call: 'shh_deleteKeyPair', 5806 params: 1 5807 }), 5808 new Method({ 5809 name: 'hasKeyPair', 5810 call: 'shh_hasKeyPair', 5811 params: 1 5812 }), 5813 new Method({ 5814 name: 'getPublicKey', 5815 call: 'shh_getPublicKey', 5816 params: 1 5817 }), 5818 new Method({ 5819 name: 'getPrivateKey', 5820 call: 'shh_getPrivateKey', 5821 params: 1 5822 }), 5823 new Method({ 5824 name: 'newSymKey', 5825 call: 'shh_newSymKey', 5826 params: 0 5827 }), 5828 new Method({ 5829 name: 'addSymKey', 5830 call: 'shh_addSymKey', 5831 params: 1 5832 }), 5833 new Method({ 5834 name: 'generateSymKeyFromPassword', 5835 call: 'shh_generateSymKeyFromPassword', 5836 params: 1 5837 }), 5838 new Method({ 5839 name: 'hasSymKey', 5840 call: 'shh_hasSymKey', 5841 params: 1 5842 }), 5843 new Method({ 5844 name: 'getSymKey', 5845 call: 'shh_getSymKey', 5846 params: 1 5847 }), 5848 new Method({ 5849 name: 'deleteSymKey', 5850 call: 'shh_deleteSymKey', 5851 params: 1 5852 }), 5853 5854 // subscribe and unsubscribe missing 5855 5856 new Method({ 5857 name: 'post', 5858 call: 'shh_post', 5859 params: 1, 5860 inputFormatter: [null] 5861 }) 5862 ]; 5863 }; 5864 5865 module.exports = Shh; 5866 5867 5868 },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){ 5869 /* 5870 This file is part of web3.js. 5871 5872 web3.js is free software: you can redistribute it and/or modify 5873 it under the terms of the GNU Lesser General Public License as published by 5874 the Free Software Foundation, either version 3 of the License, or 5875 (at your option) any later version. 5876 5877 web3.js is distributed in the hope that it will be useful, 5878 but WITHOUT ANY WARRANTY; without even the implied warranty of 5879 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5880 GNU Lesser General Public License for more details. 5881 5882 You should have received a copy of the GNU Lesser General Public License 5883 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5884 */ 5885 /** 5886 * @file bzz.js 5887 * @author Alex Beregszaszi <alex@rtfs.hu> 5888 * @date 2016 5889 * 5890 * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33 5891 */ 5892 5893 "use strict"; 5894 5895 var Method = require('../method'); 5896 var Property = require('../property'); 5897 5898 function Swarm(web3) { 5899 this._requestManager = web3._requestManager; 5900 5901 var self = this; 5902 5903 methods().forEach(function(method) { 5904 method.attachToObject(self); 5905 method.setRequestManager(self._requestManager); 5906 }); 5907 5908 properties().forEach(function(p) { 5909 p.attachToObject(self); 5910 p.setRequestManager(self._requestManager); 5911 }); 5912 } 5913 5914 var methods = function () { 5915 var blockNetworkRead = new Method({ 5916 name: 'blockNetworkRead', 5917 call: 'bzz_blockNetworkRead', 5918 params: 1, 5919 inputFormatter: [null] 5920 }); 5921 5922 var syncEnabled = new Method({ 5923 name: 'syncEnabled', 5924 call: 'bzz_syncEnabled', 5925 params: 1, 5926 inputFormatter: [null] 5927 }); 5928 5929 var swapEnabled = new Method({ 5930 name: 'swapEnabled', 5931 call: 'bzz_swapEnabled', 5932 params: 1, 5933 inputFormatter: [null] 5934 }); 5935 5936 var download = new Method({ 5937 name: 'download', 5938 call: 'bzz_download', 5939 params: 2, 5940 inputFormatter: [null, null] 5941 }); 5942 5943 var upload = new Method({ 5944 name: 'upload', 5945 call: 'bzz_upload', 5946 params: 2, 5947 inputFormatter: [null, null] 5948 }); 5949 5950 var retrieve = new Method({ 5951 name: 'retrieve', 5952 call: 'bzz_retrieve', 5953 params: 1, 5954 inputFormatter: [null] 5955 }); 5956 5957 var store = new Method({ 5958 name: 'store', 5959 call: 'bzz_store', 5960 params: 2, 5961 inputFormatter: [null, null] 5962 }); 5963 5964 var get = new Method({ 5965 name: 'get', 5966 call: 'bzz_get', 5967 params: 1, 5968 inputFormatter: [null] 5969 }); 5970 5971 var put = new Method({ 5972 name: 'put', 5973 call: 'bzz_put', 5974 params: 2, 5975 inputFormatter: [null, null] 5976 }); 5977 5978 var modify = new Method({ 5979 name: 'modify', 5980 call: 'bzz_modify', 5981 params: 4, 5982 inputFormatter: [null, null, null, null] 5983 }); 5984 5985 return [ 5986 blockNetworkRead, 5987 syncEnabled, 5988 swapEnabled, 5989 download, 5990 upload, 5991 retrieve, 5992 store, 5993 get, 5994 put, 5995 modify 5996 ]; 5997 }; 5998 5999 var properties = function () { 6000 return [ 6001 new Property({ 6002 name: 'hive', 6003 getter: 'bzz_hive' 6004 }), 6005 new Property({ 6006 name: 'info', 6007 getter: 'bzz_info' 6008 }) 6009 ]; 6010 }; 6011 6012 6013 module.exports = Swarm; 6014 6015 },{"../method":36,"../property":45}],43:[function(require,module,exports){ 6016 /* 6017 This file is part of web3.js. 6018 6019 web3.js is free software: you can redistribute it and/or modify 6020 it under the terms of the GNU Lesser General Public License as published by 6021 the Free Software Foundation, either version 3 of the License, or 6022 (at your option) any later version. 6023 6024 web3.js is distributed in the hope that it will be useful, 6025 but WITHOUT ANY WARRANTY; without even the implied warranty of 6026 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6027 GNU Lesser General Public License for more details. 6028 6029 You should have received a copy of the GNU Lesser General Public License 6030 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6031 */ 6032 /** @file watches.js 6033 * @authors: 6034 * Marek Kotewicz <marek@ethdev.com> 6035 * @date 2015 6036 */ 6037 6038 var Method = require('../method'); 6039 6040 /// @returns an array of objects describing web3.eth.filter api methods 6041 var eth = function () { 6042 var newFilterCall = function (args) { 6043 var type = args[0]; 6044 6045 switch(type) { 6046 case 'latest': 6047 args.shift(); 6048 this.params = 0; 6049 return 'eth_newBlockFilter'; 6050 case 'pending': 6051 args.shift(); 6052 this.params = 0; 6053 return 'eth_newPendingTransactionFilter'; 6054 default: 6055 return 'eth_newFilter'; 6056 } 6057 }; 6058 6059 var newFilter = new Method({ 6060 name: 'newFilter', 6061 call: newFilterCall, 6062 params: 1 6063 }); 6064 6065 var uninstallFilter = new Method({ 6066 name: 'uninstallFilter', 6067 call: 'eth_uninstallFilter', 6068 params: 1 6069 }); 6070 6071 var getLogs = new Method({ 6072 name: 'getLogs', 6073 call: 'eth_getFilterLogs', 6074 params: 1 6075 }); 6076 6077 var poll = new Method({ 6078 name: 'poll', 6079 call: 'eth_getFilterChanges', 6080 params: 1 6081 }); 6082 6083 return [ 6084 newFilter, 6085 uninstallFilter, 6086 getLogs, 6087 poll 6088 ]; 6089 }; 6090 6091 /// @returns an array of objects describing web3.shh.watch api methods 6092 var shh = function () { 6093 6094 return [ 6095 new Method({ 6096 name: 'newFilter', 6097 call: 'shh_newMessageFilter', 6098 params: 1 6099 }), 6100 new Method({ 6101 name: 'uninstallFilter', 6102 call: 'shh_deleteMessageFilter', 6103 params: 1 6104 }), 6105 new Method({ 6106 name: 'getLogs', 6107 call: 'shh_getFilterMessages', 6108 params: 1 6109 }), 6110 new Method({ 6111 name: 'poll', 6112 call: 'shh_getFilterMessages', 6113 params: 1 6114 }) 6115 ]; 6116 }; 6117 6118 module.exports = { 6119 eth: eth, 6120 shh: shh 6121 }; 6122 6123 6124 },{"../method":36}],44:[function(require,module,exports){ 6125 /* 6126 This file is part of web3.js. 6127 6128 web3.js is free software: you can redistribute it and/or modify 6129 it under the terms of the GNU Lesser General Public License as published by 6130 the Free Software Foundation, either version 3 of the License, or 6131 (at your option) any later version. 6132 6133 web3.js is distributed in the hope that it will be useful, 6134 but WITHOUT ANY WARRANTY; without even the implied warranty of 6135 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6136 GNU Lesser General Public License for more details. 6137 6138 You should have received a copy of the GNU Lesser General Public License 6139 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6140 */ 6141 /** 6142 * @file namereg.js 6143 * @author Marek Kotewicz <marek@ethdev.com> 6144 * @date 2015 6145 */ 6146 6147 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6148 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6149 6150 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6151 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6152 6153 module.exports = { 6154 global: { 6155 abi: globalRegistrarAbi, 6156 address: globalNameregAddress 6157 }, 6158 icap: { 6159 abi: icapRegistrarAbi, 6160 address: icapNameregAddress 6161 } 6162 }; 6163 6164 6165 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 6166 /* 6167 This file is part of web3.js. 6168 6169 web3.js is free software: you can redistribute it and/or modify 6170 it under the terms of the GNU Lesser General Public License as published by 6171 the Free Software Foundation, either version 3 of the License, or 6172 (at your option) any later version. 6173 6174 web3.js is distributed in the hope that it will be useful, 6175 but WITHOUT ANY WARRANTY; without even the implied warranty of 6176 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6177 GNU Lesser General Public License for more details. 6178 6179 You should have received a copy of the GNU Lesser General Public License 6180 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6181 */ 6182 /** 6183 * @file property.js 6184 * @author Fabian Vogelsteller <fabian@frozeman.de> 6185 * @author Marek Kotewicz <marek@ethdev.com> 6186 * @date 2015 6187 */ 6188 6189 var utils = require('../utils/utils'); 6190 6191 var Property = function (options) { 6192 this.name = options.name; 6193 this.getter = options.getter; 6194 this.setter = options.setter; 6195 this.outputFormatter = options.outputFormatter; 6196 this.inputFormatter = options.inputFormatter; 6197 this.requestManager = null; 6198 }; 6199 6200 Property.prototype.setRequestManager = function (rm) { 6201 this.requestManager = rm; 6202 }; 6203 6204 /** 6205 * Should be called to format input args of method 6206 * 6207 * @method formatInput 6208 * @param {Array} 6209 * @return {Array} 6210 */ 6211 Property.prototype.formatInput = function (arg) { 6212 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6213 }; 6214 6215 /** 6216 * Should be called to format output(result) of method 6217 * 6218 * @method formatOutput 6219 * @param {Object} 6220 * @return {Object} 6221 */ 6222 Property.prototype.formatOutput = function (result) { 6223 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6224 }; 6225 6226 /** 6227 * Should be used to extract callback from array of arguments. Modifies input param 6228 * 6229 * @method extractCallback 6230 * @param {Array} arguments 6231 * @return {Function|Null} callback, if exists 6232 */ 6233 Property.prototype.extractCallback = function (args) { 6234 if (utils.isFunction(args[args.length - 1])) { 6235 return args.pop(); // modify the args array! 6236 } 6237 }; 6238 6239 6240 /** 6241 * Should attach function to method 6242 * 6243 * @method attachToObject 6244 * @param {Object} 6245 * @param {Function} 6246 */ 6247 Property.prototype.attachToObject = function (obj) { 6248 var proto = { 6249 get: this.buildGet(), 6250 enumerable: true 6251 }; 6252 6253 var names = this.name.split('.'); 6254 var name = names[0]; 6255 if (names.length > 1) { 6256 obj[names[0]] = obj[names[0]] || {}; 6257 obj = obj[names[0]]; 6258 name = names[1]; 6259 } 6260 6261 Object.defineProperty(obj, name, proto); 6262 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6263 }; 6264 6265 var asyncGetterName = function (name) { 6266 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6267 }; 6268 6269 Property.prototype.buildGet = function () { 6270 var property = this; 6271 return function get() { 6272 return property.formatOutput(property.requestManager.send({ 6273 method: property.getter 6274 })); 6275 }; 6276 }; 6277 6278 Property.prototype.buildAsyncGet = function () { 6279 var property = this; 6280 var get = function (callback) { 6281 property.requestManager.sendAsync({ 6282 method: property.getter 6283 }, function (err, result) { 6284 callback(err, property.formatOutput(result)); 6285 }); 6286 }; 6287 get.request = this.request.bind(this); 6288 return get; 6289 }; 6290 6291 /** 6292 * Should be called to create pure JSONRPC request which can be used in batch request 6293 * 6294 * @method request 6295 * @param {...} params 6296 * @return {Object} jsonrpc request 6297 */ 6298 Property.prototype.request = function () { 6299 var payload = { 6300 method: this.getter, 6301 params: [], 6302 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6303 }; 6304 payload.format = this.formatOutput.bind(this); 6305 return payload; 6306 }; 6307 6308 module.exports = Property; 6309 6310 6311 },{"../utils/utils":20}],46:[function(require,module,exports){ 6312 /* 6313 This file is part of web3.js. 6314 6315 web3.js is free software: you can redistribute it and/or modify 6316 it under the terms of the GNU Lesser General Public License as published by 6317 the Free Software Foundation, either version 3 of the License, or 6318 (at your option) any later version. 6319 6320 web3.js is distributed in the hope that it will be useful, 6321 but WITHOUT ANY WARRANTY; without even the implied warranty of 6322 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6323 GNU Lesser General Public License for more details. 6324 6325 You should have received a copy of the GNU Lesser General Public License 6326 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6327 */ 6328 /** 6329 * @file requestmanager.js 6330 * @author Jeffrey Wilcke <jeff@ethdev.com> 6331 * @author Marek Kotewicz <marek@ethdev.com> 6332 * @author Marian Oancea <marian@ethdev.com> 6333 * @author Fabian Vogelsteller <fabian@ethdev.com> 6334 * @author Gav Wood <g@ethdev.com> 6335 * @date 2014 6336 */ 6337 6338 var Jsonrpc = require('./jsonrpc'); 6339 var utils = require('../utils/utils'); 6340 var c = require('../utils/config'); 6341 var errors = require('./errors'); 6342 6343 /** 6344 * It's responsible for passing messages to providers 6345 * It's also responsible for polling the ethereum node for incoming messages 6346 * Default poll timeout is 1 second 6347 * Singleton 6348 */ 6349 var RequestManager = function (provider) { 6350 this.provider = provider; 6351 this.polls = {}; 6352 this.timeout = null; 6353 }; 6354 6355 /** 6356 * Should be used to synchronously send request 6357 * 6358 * @method send 6359 * @param {Object} data 6360 * @return {Object} 6361 */ 6362 RequestManager.prototype.send = function (data) { 6363 if (!this.provider) { 6364 console.error(errors.InvalidProvider()); 6365 return null; 6366 } 6367 6368 var payload = Jsonrpc.toPayload(data.method, data.params); 6369 var result = this.provider.send(payload); 6370 6371 if (!Jsonrpc.isValidResponse(result)) { 6372 throw errors.InvalidResponse(result); 6373 } 6374 6375 return result.result; 6376 }; 6377 6378 /** 6379 * Should be used to asynchronously send request 6380 * 6381 * @method sendAsync 6382 * @param {Object} data 6383 * @param {Function} callback 6384 */ 6385 RequestManager.prototype.sendAsync = function (data, callback) { 6386 if (!this.provider) { 6387 return callback(errors.InvalidProvider()); 6388 } 6389 6390 var payload = Jsonrpc.toPayload(data.method, data.params); 6391 this.provider.sendAsync(payload, function (err, result) { 6392 if (err) { 6393 return callback(err); 6394 } 6395 6396 if (!Jsonrpc.isValidResponse(result)) { 6397 return callback(errors.InvalidResponse(result)); 6398 } 6399 6400 callback(null, result.result); 6401 }); 6402 }; 6403 6404 /** 6405 * Should be called to asynchronously send batch request 6406 * 6407 * @method sendBatch 6408 * @param {Array} batch data 6409 * @param {Function} callback 6410 */ 6411 RequestManager.prototype.sendBatch = function (data, callback) { 6412 if (!this.provider) { 6413 return callback(errors.InvalidProvider()); 6414 } 6415 6416 var payload = Jsonrpc.toBatchPayload(data); 6417 6418 this.provider.sendAsync(payload, function (err, results) { 6419 if (err) { 6420 return callback(err); 6421 } 6422 6423 if (!utils.isArray(results)) { 6424 return callback(errors.InvalidResponse(results)); 6425 } 6426 6427 callback(err, results); 6428 }); 6429 }; 6430 6431 /** 6432 * Should be used to set provider of request manager 6433 * 6434 * @method setProvider 6435 * @param {Object} 6436 */ 6437 RequestManager.prototype.setProvider = function (p) { 6438 this.provider = p; 6439 }; 6440 6441 /** 6442 * Should be used to start polling 6443 * 6444 * @method startPolling 6445 * @param {Object} data 6446 * @param {Number} pollId 6447 * @param {Function} callback 6448 * @param {Function} uninstall 6449 * 6450 * @todo cleanup number of params 6451 */ 6452 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6453 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 6454 6455 6456 // start polling 6457 if (!this.timeout) { 6458 this.poll(); 6459 } 6460 }; 6461 6462 /** 6463 * Should be used to stop polling for filter with given id 6464 * 6465 * @method stopPolling 6466 * @param {Number} pollId 6467 */ 6468 RequestManager.prototype.stopPolling = function (pollId) { 6469 delete this.polls[pollId]; 6470 6471 // stop polling 6472 if(Object.keys(this.polls).length === 0 && this.timeout) { 6473 clearTimeout(this.timeout); 6474 this.timeout = null; 6475 } 6476 }; 6477 6478 /** 6479 * Should be called to reset the polling mechanism of the request manager 6480 * 6481 * @method reset 6482 */ 6483 RequestManager.prototype.reset = function (keepIsSyncing) { 6484 /*jshint maxcomplexity:5 */ 6485 6486 for (var key in this.polls) { 6487 // remove all polls, except sync polls, 6488 // they need to be removed manually by calling syncing.stopWatching() 6489 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6490 this.polls[key].uninstall(); 6491 delete this.polls[key]; 6492 } 6493 } 6494 6495 // stop polling 6496 if(Object.keys(this.polls).length === 0 && this.timeout) { 6497 clearTimeout(this.timeout); 6498 this.timeout = null; 6499 } 6500 }; 6501 6502 /** 6503 * Should be called to poll for changes on filter with given id 6504 * 6505 * @method poll 6506 */ 6507 RequestManager.prototype.poll = function () { 6508 /*jshint maxcomplexity: 6 */ 6509 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6510 6511 if (Object.keys(this.polls).length === 0) { 6512 return; 6513 } 6514 6515 if (!this.provider) { 6516 console.error(errors.InvalidProvider()); 6517 return; 6518 } 6519 6520 var pollsData = []; 6521 var pollsIds = []; 6522 for (var key in this.polls) { 6523 pollsData.push(this.polls[key].data); 6524 pollsIds.push(key); 6525 } 6526 6527 if (pollsData.length === 0) { 6528 return; 6529 } 6530 6531 var payload = Jsonrpc.toBatchPayload(pollsData); 6532 6533 // map the request id to they poll id 6534 var pollsIdMap = {}; 6535 payload.forEach(function(load, index){ 6536 pollsIdMap[load.id] = pollsIds[index]; 6537 }); 6538 6539 6540 var self = this; 6541 this.provider.sendAsync(payload, function (error, results) { 6542 6543 6544 // TODO: console log? 6545 if (error) { 6546 return; 6547 } 6548 6549 if (!utils.isArray(results)) { 6550 throw errors.InvalidResponse(results); 6551 } 6552 results.map(function (result) { 6553 var id = pollsIdMap[result.id]; 6554 6555 // make sure the filter is still installed after arrival of the request 6556 if (self.polls[id]) { 6557 result.callback = self.polls[id].callback; 6558 return result; 6559 } else 6560 return false; 6561 }).filter(function (result) { 6562 return !!result; 6563 }).filter(function (result) { 6564 var valid = Jsonrpc.isValidResponse(result); 6565 if (!valid) { 6566 result.callback(errors.InvalidResponse(result)); 6567 } 6568 return valid; 6569 }).forEach(function (result) { 6570 result.callback(null, result.result); 6571 }); 6572 }); 6573 }; 6574 6575 module.exports = RequestManager; 6576 6577 6578 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 6579 6580 6581 var Settings = function () { 6582 this.defaultBlock = 'latest'; 6583 this.defaultAccount = undefined; 6584 }; 6585 6586 module.exports = Settings; 6587 6588 6589 },{}],48:[function(require,module,exports){ 6590 /* 6591 This file is part of web3.js. 6592 6593 web3.js is free software: you can redistribute it and/or modify 6594 it under the terms of the GNU Lesser General Public License as published by 6595 the Free Software Foundation, either version 3 of the License, or 6596 (at your option) any later version. 6597 6598 web3.js is distributed in the hope that it will be useful, 6599 but WITHOUT ANY WARRANTY; without even the implied warranty of 6600 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6601 GNU Lesser General Public License for more details. 6602 6603 You should have received a copy of the GNU Lesser General Public License 6604 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6605 */ 6606 /** @file syncing.js 6607 * @authors: 6608 * Fabian Vogelsteller <fabian@ethdev.com> 6609 * @date 2015 6610 */ 6611 6612 var formatters = require('./formatters'); 6613 var utils = require('../utils/utils'); 6614 6615 var count = 1; 6616 6617 /** 6618 Adds the callback and sets up the methods, to iterate over the results. 6619 6620 @method pollSyncing 6621 @param {Object} self 6622 */ 6623 var pollSyncing = function(self) { 6624 6625 var onMessage = function (error, sync) { 6626 if (error) { 6627 return self.callbacks.forEach(function (callback) { 6628 callback(error); 6629 }); 6630 } 6631 6632 if(utils.isObject(sync) && sync.startingBlock) 6633 sync = formatters.outputSyncingFormatter(sync); 6634 6635 self.callbacks.forEach(function (callback) { 6636 if (self.lastSyncState !== sync) { 6637 6638 // call the callback with true first so the app can stop anything, before receiving the sync data 6639 if(!self.lastSyncState && utils.isObject(sync)) 6640 callback(null, true); 6641 6642 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6643 setTimeout(function() { 6644 callback(null, sync); 6645 }, 0); 6646 6647 self.lastSyncState = sync; 6648 } 6649 }); 6650 }; 6651 6652 self.requestManager.startPolling({ 6653 method: 'eth_syncing', 6654 params: [], 6655 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6656 6657 }; 6658 6659 var IsSyncing = function (requestManager, callback) { 6660 this.requestManager = requestManager; 6661 this.pollId = 'syncPoll_'+ count++; 6662 this.callbacks = []; 6663 this.addCallback(callback); 6664 this.lastSyncState = false; 6665 pollSyncing(this); 6666 6667 return this; 6668 }; 6669 6670 IsSyncing.prototype.addCallback = function (callback) { 6671 if(callback) 6672 this.callbacks.push(callback); 6673 return this; 6674 }; 6675 6676 IsSyncing.prototype.stopWatching = function () { 6677 this.requestManager.stopPolling(this.pollId); 6678 this.callbacks = []; 6679 }; 6680 6681 module.exports = IsSyncing; 6682 6683 6684 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 6685 /* 6686 This file is part of web3.js. 6687 6688 web3.js is free software: you can redistribute it and/or modify 6689 it under the terms of the GNU Lesser General Public License as published by 6690 the Free Software Foundation, either version 3 of the License, or 6691 (at your option) any later version. 6692 6693 web3.js is distributed in the hope that it will be useful, 6694 but WITHOUT ANY WARRANTY; without even the implied warranty of 6695 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6696 GNU Lesser General Public License for more details. 6697 6698 You should have received a copy of the GNU Lesser General Public License 6699 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6700 */ 6701 /** 6702 * @file transfer.js 6703 * @author Marek Kotewicz <marek@ethdev.com> 6704 * @date 2015 6705 */ 6706 6707 var Iban = require('./iban'); 6708 var exchangeAbi = require('../contracts/SmartExchange.json'); 6709 6710 /** 6711 * Should be used to make Iban transfer 6712 * 6713 * @method transfer 6714 * @param {String} from 6715 * @param {String} to iban 6716 * @param {Value} value to be tranfered 6717 * @param {Function} callback, callback 6718 */ 6719 var transfer = function (eth, from, to, value, callback) { 6720 var iban = new Iban(to); 6721 if (!iban.isValid()) { 6722 throw new Error('invalid iban address'); 6723 } 6724 6725 if (iban.isDirect()) { 6726 return transferToAddress(eth, from, iban.address(), value, callback); 6727 } 6728 6729 if (!callback) { 6730 var address = eth.icapNamereg().addr(iban.institution()); 6731 return deposit(eth, from, address, value, iban.client()); 6732 } 6733 6734 eth.icapNamereg().addr(iban.institution(), function (err, address) { 6735 return deposit(eth, from, address, value, iban.client(), callback); 6736 }); 6737 6738 }; 6739 6740 /** 6741 * Should be used to transfer funds to certain address 6742 * 6743 * @method transferToAddress 6744 * @param {String} from 6745 * @param {String} to 6746 * @param {Value} value to be tranfered 6747 * @param {Function} callback, callback 6748 */ 6749 var transferToAddress = function (eth, from, to, value, callback) { 6750 return eth.sendTransaction({ 6751 address: to, 6752 from: from, 6753 value: value 6754 }, callback); 6755 }; 6756 6757 /** 6758 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6759 * 6760 * @method deposit 6761 * @param {String} from 6762 * @param {String} to 6763 * @param {Value} value to be transfered 6764 * @param {String} client unique identifier 6765 * @param {Function} callback, callback 6766 */ 6767 var deposit = function (eth, from, to, value, client, callback) { 6768 var abi = exchangeAbi; 6769 return eth.contract(abi).at(to).deposit(client, { 6770 from: from, 6771 value: value 6772 }, callback); 6773 }; 6774 6775 module.exports = transfer; 6776 6777 6778 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 6779 6780 },{}],51:[function(require,module,exports){ 6781 ;(function (root, factory, undef) { 6782 if (typeof exports === "object") { 6783 // CommonJS 6784 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6785 } 6786 else if (typeof define === "function" && define.amd) { 6787 // AMD 6788 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6789 } 6790 else { 6791 // Global (browser) 6792 factory(root.CryptoJS); 6793 } 6794 }(this, function (CryptoJS) { 6795 6796 (function () { 6797 // Shortcuts 6798 var C = CryptoJS; 6799 var C_lib = C.lib; 6800 var BlockCipher = C_lib.BlockCipher; 6801 var C_algo = C.algo; 6802 6803 // Lookup tables 6804 var SBOX = []; 6805 var INV_SBOX = []; 6806 var SUB_MIX_0 = []; 6807 var SUB_MIX_1 = []; 6808 var SUB_MIX_2 = []; 6809 var SUB_MIX_3 = []; 6810 var INV_SUB_MIX_0 = []; 6811 var INV_SUB_MIX_1 = []; 6812 var INV_SUB_MIX_2 = []; 6813 var INV_SUB_MIX_3 = []; 6814 6815 // Compute lookup tables 6816 (function () { 6817 // Compute double table 6818 var d = []; 6819 for (var i = 0; i < 256; i++) { 6820 if (i < 128) { 6821 d[i] = i << 1; 6822 } else { 6823 d[i] = (i << 1) ^ 0x11b; 6824 } 6825 } 6826 6827 // Walk GF(2^8) 6828 var x = 0; 6829 var xi = 0; 6830 for (var i = 0; i < 256; i++) { 6831 // Compute sbox 6832 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6833 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6834 SBOX[x] = sx; 6835 INV_SBOX[sx] = x; 6836 6837 // Compute multiplication 6838 var x2 = d[x]; 6839 var x4 = d[x2]; 6840 var x8 = d[x4]; 6841 6842 // Compute sub bytes, mix columns tables 6843 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6844 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6845 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6846 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6847 SUB_MIX_3[x] = t; 6848 6849 // Compute inv sub bytes, inv mix columns tables 6850 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6851 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6852 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6853 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6854 INV_SUB_MIX_3[sx] = t; 6855 6856 // Compute next counter 6857 if (!x) { 6858 x = xi = 1; 6859 } else { 6860 x = x2 ^ d[d[d[x8 ^ x2]]]; 6861 xi ^= d[d[xi]]; 6862 } 6863 } 6864 }()); 6865 6866 // Precomputed Rcon lookup 6867 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6868 6869 /** 6870 * AES block cipher algorithm. 6871 */ 6872 var AES = C_algo.AES = BlockCipher.extend({ 6873 _doReset: function () { 6874 // Skip reset of nRounds has been set before and key did not change 6875 if (this._nRounds && this._keyPriorReset === this._key) { 6876 return; 6877 } 6878 6879 // Shortcuts 6880 var key = this._keyPriorReset = this._key; 6881 var keyWords = key.words; 6882 var keySize = key.sigBytes / 4; 6883 6884 // Compute number of rounds 6885 var nRounds = this._nRounds = keySize + 6; 6886 6887 // Compute number of key schedule rows 6888 var ksRows = (nRounds + 1) * 4; 6889 6890 // Compute key schedule 6891 var keySchedule = this._keySchedule = []; 6892 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 6893 if (ksRow < keySize) { 6894 keySchedule[ksRow] = keyWords[ksRow]; 6895 } else { 6896 var t = keySchedule[ksRow - 1]; 6897 6898 if (!(ksRow % keySize)) { 6899 // Rot word 6900 t = (t << 8) | (t >>> 24); 6901 6902 // Sub word 6903 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6904 6905 // Mix Rcon 6906 t ^= RCON[(ksRow / keySize) | 0] << 24; 6907 } else if (keySize > 6 && ksRow % keySize == 4) { 6908 // Sub word 6909 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6910 } 6911 6912 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 6913 } 6914 } 6915 6916 // Compute inv key schedule 6917 var invKeySchedule = this._invKeySchedule = []; 6918 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 6919 var ksRow = ksRows - invKsRow; 6920 6921 if (invKsRow % 4) { 6922 var t = keySchedule[ksRow]; 6923 } else { 6924 var t = keySchedule[ksRow - 4]; 6925 } 6926 6927 if (invKsRow < 4 || ksRow <= 4) { 6928 invKeySchedule[invKsRow] = t; 6929 } else { 6930 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 6931 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 6932 } 6933 } 6934 }, 6935 6936 encryptBlock: function (M, offset) { 6937 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 6938 }, 6939 6940 decryptBlock: function (M, offset) { 6941 // Swap 2nd and 4th rows 6942 var t = M[offset + 1]; 6943 M[offset + 1] = M[offset + 3]; 6944 M[offset + 3] = t; 6945 6946 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 6947 6948 // Inv swap 2nd and 4th rows 6949 var t = M[offset + 1]; 6950 M[offset + 1] = M[offset + 3]; 6951 M[offset + 3] = t; 6952 }, 6953 6954 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 6955 // Shortcut 6956 var nRounds = this._nRounds; 6957 6958 // Get input, add round key 6959 var s0 = M[offset] ^ keySchedule[0]; 6960 var s1 = M[offset + 1] ^ keySchedule[1]; 6961 var s2 = M[offset + 2] ^ keySchedule[2]; 6962 var s3 = M[offset + 3] ^ keySchedule[3]; 6963 6964 // Key schedule row counter 6965 var ksRow = 4; 6966 6967 // Rounds 6968 for (var round = 1; round < nRounds; round++) { 6969 // Shift rows, sub bytes, mix columns, add round key 6970 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++]; 6971 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++]; 6972 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++]; 6973 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++]; 6974 6975 // Update state 6976 s0 = t0; 6977 s1 = t1; 6978 s2 = t2; 6979 s3 = t3; 6980 } 6981 6982 // Shift rows, sub bytes, add round key 6983 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 6984 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 6985 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 6986 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 6987 6988 // Set output 6989 M[offset] = t0; 6990 M[offset + 1] = t1; 6991 M[offset + 2] = t2; 6992 M[offset + 3] = t3; 6993 }, 6994 6995 keySize: 256/32 6996 }); 6997 6998 /** 6999 * Shortcut functions to the cipher's object interface. 7000 * 7001 * @example 7002 * 7003 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7004 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7005 */ 7006 C.AES = BlockCipher._createHelper(AES); 7007 }()); 7008 7009 7010 return CryptoJS.AES; 7011 7012 })); 7013 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 7014 ;(function (root, factory) { 7015 if (typeof exports === "object") { 7016 // CommonJS 7017 module.exports = exports = factory(require("./core")); 7018 } 7019 else if (typeof define === "function" && define.amd) { 7020 // AMD 7021 define(["./core"], factory); 7022 } 7023 else { 7024 // Global (browser) 7025 factory(root.CryptoJS); 7026 } 7027 }(this, function (CryptoJS) { 7028 7029 /** 7030 * Cipher core components. 7031 */ 7032 CryptoJS.lib.Cipher || (function (undefined) { 7033 // Shortcuts 7034 var C = CryptoJS; 7035 var C_lib = C.lib; 7036 var Base = C_lib.Base; 7037 var WordArray = C_lib.WordArray; 7038 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7039 var C_enc = C.enc; 7040 var Utf8 = C_enc.Utf8; 7041 var Base64 = C_enc.Base64; 7042 var C_algo = C.algo; 7043 var EvpKDF = C_algo.EvpKDF; 7044 7045 /** 7046 * Abstract base cipher template. 7047 * 7048 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7049 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7050 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7051 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7052 */ 7053 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7054 /** 7055 * Configuration options. 7056 * 7057 * @property {WordArray} iv The IV to use for this operation. 7058 */ 7059 cfg: Base.extend(), 7060 7061 /** 7062 * Creates this cipher in encryption mode. 7063 * 7064 * @param {WordArray} key The key. 7065 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7066 * 7067 * @return {Cipher} A cipher instance. 7068 * 7069 * @static 7070 * 7071 * @example 7072 * 7073 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7074 */ 7075 createEncryptor: function (key, cfg) { 7076 return this.create(this._ENC_XFORM_MODE, key, cfg); 7077 }, 7078 7079 /** 7080 * Creates this cipher in decryption mode. 7081 * 7082 * @param {WordArray} key The key. 7083 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7084 * 7085 * @return {Cipher} A cipher instance. 7086 * 7087 * @static 7088 * 7089 * @example 7090 * 7091 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7092 */ 7093 createDecryptor: function (key, cfg) { 7094 return this.create(this._DEC_XFORM_MODE, key, cfg); 7095 }, 7096 7097 /** 7098 * Initializes a newly created cipher. 7099 * 7100 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7101 * @param {WordArray} key The key. 7102 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7103 * 7104 * @example 7105 * 7106 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7107 */ 7108 init: function (xformMode, key, cfg) { 7109 // Apply config defaults 7110 this.cfg = this.cfg.extend(cfg); 7111 7112 // Store transform mode and key 7113 this._xformMode = xformMode; 7114 this._key = key; 7115 7116 // Set initial values 7117 this.reset(); 7118 }, 7119 7120 /** 7121 * Resets this cipher to its initial state. 7122 * 7123 * @example 7124 * 7125 * cipher.reset(); 7126 */ 7127 reset: function () { 7128 // Reset data buffer 7129 BufferedBlockAlgorithm.reset.call(this); 7130 7131 // Perform concrete-cipher logic 7132 this._doReset(); 7133 }, 7134 7135 /** 7136 * Adds data to be encrypted or decrypted. 7137 * 7138 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7139 * 7140 * @return {WordArray} The data after processing. 7141 * 7142 * @example 7143 * 7144 * var encrypted = cipher.process('data'); 7145 * var encrypted = cipher.process(wordArray); 7146 */ 7147 process: function (dataUpdate) { 7148 // Append 7149 this._append(dataUpdate); 7150 7151 // Process available blocks 7152 return this._process(); 7153 }, 7154 7155 /** 7156 * Finalizes the encryption or decryption process. 7157 * Note that the finalize operation is effectively a destructive, read-once operation. 7158 * 7159 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7160 * 7161 * @return {WordArray} The data after final processing. 7162 * 7163 * @example 7164 * 7165 * var encrypted = cipher.finalize(); 7166 * var encrypted = cipher.finalize('data'); 7167 * var encrypted = cipher.finalize(wordArray); 7168 */ 7169 finalize: function (dataUpdate) { 7170 // Final data update 7171 if (dataUpdate) { 7172 this._append(dataUpdate); 7173 } 7174 7175 // Perform concrete-cipher logic 7176 var finalProcessedData = this._doFinalize(); 7177 7178 return finalProcessedData; 7179 }, 7180 7181 keySize: 128/32, 7182 7183 ivSize: 128/32, 7184 7185 _ENC_XFORM_MODE: 1, 7186 7187 _DEC_XFORM_MODE: 2, 7188 7189 /** 7190 * Creates shortcut functions to a cipher's object interface. 7191 * 7192 * @param {Cipher} cipher The cipher to create a helper for. 7193 * 7194 * @return {Object} An object with encrypt and decrypt shortcut functions. 7195 * 7196 * @static 7197 * 7198 * @example 7199 * 7200 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7201 */ 7202 _createHelper: (function () { 7203 function selectCipherStrategy(key) { 7204 if (typeof key == 'string') { 7205 return PasswordBasedCipher; 7206 } else { 7207 return SerializableCipher; 7208 } 7209 } 7210 7211 return function (cipher) { 7212 return { 7213 encrypt: function (message, key, cfg) { 7214 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7215 }, 7216 7217 decrypt: function (ciphertext, key, cfg) { 7218 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7219 } 7220 }; 7221 }; 7222 }()) 7223 }); 7224 7225 /** 7226 * Abstract base stream cipher template. 7227 * 7228 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7229 */ 7230 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7231 _doFinalize: function () { 7232 // Process partial blocks 7233 var finalProcessedBlocks = this._process(!!'flush'); 7234 7235 return finalProcessedBlocks; 7236 }, 7237 7238 blockSize: 1 7239 }); 7240 7241 /** 7242 * Mode namespace. 7243 */ 7244 var C_mode = C.mode = {}; 7245 7246 /** 7247 * Abstract base block cipher mode template. 7248 */ 7249 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7250 /** 7251 * Creates this mode for encryption. 7252 * 7253 * @param {Cipher} cipher A block cipher instance. 7254 * @param {Array} iv The IV words. 7255 * 7256 * @static 7257 * 7258 * @example 7259 * 7260 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7261 */ 7262 createEncryptor: function (cipher, iv) { 7263 return this.Encryptor.create(cipher, iv); 7264 }, 7265 7266 /** 7267 * Creates this mode for decryption. 7268 * 7269 * @param {Cipher} cipher A block cipher instance. 7270 * @param {Array} iv The IV words. 7271 * 7272 * @static 7273 * 7274 * @example 7275 * 7276 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7277 */ 7278 createDecryptor: function (cipher, iv) { 7279 return this.Decryptor.create(cipher, iv); 7280 }, 7281 7282 /** 7283 * Initializes a newly created mode. 7284 * 7285 * @param {Cipher} cipher A block cipher instance. 7286 * @param {Array} iv The IV words. 7287 * 7288 * @example 7289 * 7290 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7291 */ 7292 init: function (cipher, iv) { 7293 this._cipher = cipher; 7294 this._iv = iv; 7295 } 7296 }); 7297 7298 /** 7299 * Cipher Block Chaining mode. 7300 */ 7301 var CBC = C_mode.CBC = (function () { 7302 /** 7303 * Abstract base CBC mode. 7304 */ 7305 var CBC = BlockCipherMode.extend(); 7306 7307 /** 7308 * CBC encryptor. 7309 */ 7310 CBC.Encryptor = CBC.extend({ 7311 /** 7312 * Processes the data block at offset. 7313 * 7314 * @param {Array} words The data words to operate on. 7315 * @param {number} offset The offset where the block starts. 7316 * 7317 * @example 7318 * 7319 * mode.processBlock(data.words, offset); 7320 */ 7321 processBlock: function (words, offset) { 7322 // Shortcuts 7323 var cipher = this._cipher; 7324 var blockSize = cipher.blockSize; 7325 7326 // XOR and encrypt 7327 xorBlock.call(this, words, offset, blockSize); 7328 cipher.encryptBlock(words, offset); 7329 7330 // Remember this block to use with next block 7331 this._prevBlock = words.slice(offset, offset + blockSize); 7332 } 7333 }); 7334 7335 /** 7336 * CBC decryptor. 7337 */ 7338 CBC.Decryptor = CBC.extend({ 7339 /** 7340 * Processes the data block at offset. 7341 * 7342 * @param {Array} words The data words to operate on. 7343 * @param {number} offset The offset where the block starts. 7344 * 7345 * @example 7346 * 7347 * mode.processBlock(data.words, offset); 7348 */ 7349 processBlock: function (words, offset) { 7350 // Shortcuts 7351 var cipher = this._cipher; 7352 var blockSize = cipher.blockSize; 7353 7354 // Remember this block to use with next block 7355 var thisBlock = words.slice(offset, offset + blockSize); 7356 7357 // Decrypt and XOR 7358 cipher.decryptBlock(words, offset); 7359 xorBlock.call(this, words, offset, blockSize); 7360 7361 // This block becomes the previous block 7362 this._prevBlock = thisBlock; 7363 } 7364 }); 7365 7366 function xorBlock(words, offset, blockSize) { 7367 // Shortcut 7368 var iv = this._iv; 7369 7370 // Choose mixing block 7371 if (iv) { 7372 var block = iv; 7373 7374 // Remove IV for subsequent blocks 7375 this._iv = undefined; 7376 } else { 7377 var block = this._prevBlock; 7378 } 7379 7380 // XOR blocks 7381 for (var i = 0; i < blockSize; i++) { 7382 words[offset + i] ^= block[i]; 7383 } 7384 } 7385 7386 return CBC; 7387 }()); 7388 7389 /** 7390 * Padding namespace. 7391 */ 7392 var C_pad = C.pad = {}; 7393 7394 /** 7395 * PKCS #5/7 padding strategy. 7396 */ 7397 var Pkcs7 = C_pad.Pkcs7 = { 7398 /** 7399 * Pads data using the algorithm defined in PKCS #5/7. 7400 * 7401 * @param {WordArray} data The data to pad. 7402 * @param {number} blockSize The multiple that the data should be padded to. 7403 * 7404 * @static 7405 * 7406 * @example 7407 * 7408 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7409 */ 7410 pad: function (data, blockSize) { 7411 // Shortcut 7412 var blockSizeBytes = blockSize * 4; 7413 7414 // Count padding bytes 7415 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7416 7417 // Create padding word 7418 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7419 7420 // Create padding 7421 var paddingWords = []; 7422 for (var i = 0; i < nPaddingBytes; i += 4) { 7423 paddingWords.push(paddingWord); 7424 } 7425 var padding = WordArray.create(paddingWords, nPaddingBytes); 7426 7427 // Add padding 7428 data.concat(padding); 7429 }, 7430 7431 /** 7432 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7433 * 7434 * @param {WordArray} data The data to unpad. 7435 * 7436 * @static 7437 * 7438 * @example 7439 * 7440 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7441 */ 7442 unpad: function (data) { 7443 // Get number of padding bytes from last byte 7444 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7445 7446 // Remove padding 7447 data.sigBytes -= nPaddingBytes; 7448 } 7449 }; 7450 7451 /** 7452 * Abstract base block cipher template. 7453 * 7454 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7455 */ 7456 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7457 /** 7458 * Configuration options. 7459 * 7460 * @property {Mode} mode The block mode to use. Default: CBC 7461 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7462 */ 7463 cfg: Cipher.cfg.extend({ 7464 mode: CBC, 7465 padding: Pkcs7 7466 }), 7467 7468 reset: function () { 7469 // Reset cipher 7470 Cipher.reset.call(this); 7471 7472 // Shortcuts 7473 var cfg = this.cfg; 7474 var iv = cfg.iv; 7475 var mode = cfg.mode; 7476 7477 // Reset block mode 7478 if (this._xformMode == this._ENC_XFORM_MODE) { 7479 var modeCreator = mode.createEncryptor; 7480 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7481 var modeCreator = mode.createDecryptor; 7482 7483 // Keep at least one block in the buffer for unpadding 7484 this._minBufferSize = 1; 7485 } 7486 this._mode = modeCreator.call(mode, this, iv && iv.words); 7487 }, 7488 7489 _doProcessBlock: function (words, offset) { 7490 this._mode.processBlock(words, offset); 7491 }, 7492 7493 _doFinalize: function () { 7494 // Shortcut 7495 var padding = this.cfg.padding; 7496 7497 // Finalize 7498 if (this._xformMode == this._ENC_XFORM_MODE) { 7499 // Pad data 7500 padding.pad(this._data, this.blockSize); 7501 7502 // Process final blocks 7503 var finalProcessedBlocks = this._process(!!'flush'); 7504 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7505 // Process final blocks 7506 var finalProcessedBlocks = this._process(!!'flush'); 7507 7508 // Unpad data 7509 padding.unpad(finalProcessedBlocks); 7510 } 7511 7512 return finalProcessedBlocks; 7513 }, 7514 7515 blockSize: 128/32 7516 }); 7517 7518 /** 7519 * A collection of cipher parameters. 7520 * 7521 * @property {WordArray} ciphertext The raw ciphertext. 7522 * @property {WordArray} key The key to this ciphertext. 7523 * @property {WordArray} iv The IV used in the ciphering operation. 7524 * @property {WordArray} salt The salt used with a key derivation function. 7525 * @property {Cipher} algorithm The cipher algorithm. 7526 * @property {Mode} mode The block mode used in the ciphering operation. 7527 * @property {Padding} padding The padding scheme used in the ciphering operation. 7528 * @property {number} blockSize The block size of the cipher. 7529 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7530 */ 7531 var CipherParams = C_lib.CipherParams = Base.extend({ 7532 /** 7533 * Initializes a newly created cipher params object. 7534 * 7535 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7536 * 7537 * @example 7538 * 7539 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7540 * ciphertext: ciphertextWordArray, 7541 * key: keyWordArray, 7542 * iv: ivWordArray, 7543 * salt: saltWordArray, 7544 * algorithm: CryptoJS.algo.AES, 7545 * mode: CryptoJS.mode.CBC, 7546 * padding: CryptoJS.pad.PKCS7, 7547 * blockSize: 4, 7548 * formatter: CryptoJS.format.OpenSSL 7549 * }); 7550 */ 7551 init: function (cipherParams) { 7552 this.mixIn(cipherParams); 7553 }, 7554 7555 /** 7556 * Converts this cipher params object to a string. 7557 * 7558 * @param {Format} formatter (Optional) The formatting strategy to use. 7559 * 7560 * @return {string} The stringified cipher params. 7561 * 7562 * @throws Error If neither the formatter nor the default formatter is set. 7563 * 7564 * @example 7565 * 7566 * var string = cipherParams + ''; 7567 * var string = cipherParams.toString(); 7568 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7569 */ 7570 toString: function (formatter) { 7571 return (formatter || this.formatter).stringify(this); 7572 } 7573 }); 7574 7575 /** 7576 * Format namespace. 7577 */ 7578 var C_format = C.format = {}; 7579 7580 /** 7581 * OpenSSL formatting strategy. 7582 */ 7583 var OpenSSLFormatter = C_format.OpenSSL = { 7584 /** 7585 * Converts a cipher params object to an OpenSSL-compatible string. 7586 * 7587 * @param {CipherParams} cipherParams The cipher params object. 7588 * 7589 * @return {string} The OpenSSL-compatible string. 7590 * 7591 * @static 7592 * 7593 * @example 7594 * 7595 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7596 */ 7597 stringify: function (cipherParams) { 7598 // Shortcuts 7599 var ciphertext = cipherParams.ciphertext; 7600 var salt = cipherParams.salt; 7601 7602 // Format 7603 if (salt) { 7604 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7605 } else { 7606 var wordArray = ciphertext; 7607 } 7608 7609 return wordArray.toString(Base64); 7610 }, 7611 7612 /** 7613 * Converts an OpenSSL-compatible string to a cipher params object. 7614 * 7615 * @param {string} openSSLStr The OpenSSL-compatible string. 7616 * 7617 * @return {CipherParams} The cipher params object. 7618 * 7619 * @static 7620 * 7621 * @example 7622 * 7623 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7624 */ 7625 parse: function (openSSLStr) { 7626 // Parse base64 7627 var ciphertext = Base64.parse(openSSLStr); 7628 7629 // Shortcut 7630 var ciphertextWords = ciphertext.words; 7631 7632 // Test for salt 7633 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7634 // Extract salt 7635 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7636 7637 // Remove salt from ciphertext 7638 ciphertextWords.splice(0, 4); 7639 ciphertext.sigBytes -= 16; 7640 } 7641 7642 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7643 } 7644 }; 7645 7646 /** 7647 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7648 */ 7649 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7650 /** 7651 * Configuration options. 7652 * 7653 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7654 */ 7655 cfg: Base.extend({ 7656 format: OpenSSLFormatter 7657 }), 7658 7659 /** 7660 * Encrypts a message. 7661 * 7662 * @param {Cipher} cipher The cipher algorithm to use. 7663 * @param {WordArray|string} message The message to encrypt. 7664 * @param {WordArray} key The key. 7665 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7666 * 7667 * @return {CipherParams} A cipher params object. 7668 * 7669 * @static 7670 * 7671 * @example 7672 * 7673 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7674 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7675 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7676 */ 7677 encrypt: function (cipher, message, key, cfg) { 7678 // Apply config defaults 7679 cfg = this.cfg.extend(cfg); 7680 7681 // Encrypt 7682 var encryptor = cipher.createEncryptor(key, cfg); 7683 var ciphertext = encryptor.finalize(message); 7684 7685 // Shortcut 7686 var cipherCfg = encryptor.cfg; 7687 7688 // Create and return serializable cipher params 7689 return CipherParams.create({ 7690 ciphertext: ciphertext, 7691 key: key, 7692 iv: cipherCfg.iv, 7693 algorithm: cipher, 7694 mode: cipherCfg.mode, 7695 padding: cipherCfg.padding, 7696 blockSize: cipher.blockSize, 7697 formatter: cfg.format 7698 }); 7699 }, 7700 7701 /** 7702 * Decrypts serialized ciphertext. 7703 * 7704 * @param {Cipher} cipher The cipher algorithm to use. 7705 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7706 * @param {WordArray} key The key. 7707 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7708 * 7709 * @return {WordArray} The plaintext. 7710 * 7711 * @static 7712 * 7713 * @example 7714 * 7715 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7716 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7717 */ 7718 decrypt: function (cipher, ciphertext, key, cfg) { 7719 // Apply config defaults 7720 cfg = this.cfg.extend(cfg); 7721 7722 // Convert string to CipherParams 7723 ciphertext = this._parse(ciphertext, cfg.format); 7724 7725 // Decrypt 7726 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7727 7728 return plaintext; 7729 }, 7730 7731 /** 7732 * Converts serialized ciphertext to CipherParams, 7733 * else assumed CipherParams already and returns ciphertext unchanged. 7734 * 7735 * @param {CipherParams|string} ciphertext The ciphertext. 7736 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7737 * 7738 * @return {CipherParams} The unserialized ciphertext. 7739 * 7740 * @static 7741 * 7742 * @example 7743 * 7744 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7745 */ 7746 _parse: function (ciphertext, format) { 7747 if (typeof ciphertext == 'string') { 7748 return format.parse(ciphertext, this); 7749 } else { 7750 return ciphertext; 7751 } 7752 } 7753 }); 7754 7755 /** 7756 * Key derivation function namespace. 7757 */ 7758 var C_kdf = C.kdf = {}; 7759 7760 /** 7761 * OpenSSL key derivation function. 7762 */ 7763 var OpenSSLKdf = C_kdf.OpenSSL = { 7764 /** 7765 * Derives a key and IV from a password. 7766 * 7767 * @param {string} password The password to derive from. 7768 * @param {number} keySize The size in words of the key to generate. 7769 * @param {number} ivSize The size in words of the IV to generate. 7770 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7771 * 7772 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7773 * 7774 * @static 7775 * 7776 * @example 7777 * 7778 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7779 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7780 */ 7781 execute: function (password, keySize, ivSize, salt) { 7782 // Generate random salt 7783 if (!salt) { 7784 salt = WordArray.random(64/8); 7785 } 7786 7787 // Derive key and IV 7788 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 7789 7790 // Separate key and IV 7791 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7792 key.sigBytes = keySize * 4; 7793 7794 // Return params 7795 return CipherParams.create({ key: key, iv: iv, salt: salt }); 7796 } 7797 }; 7798 7799 /** 7800 * A serializable cipher wrapper that derives the key from a password, 7801 * and returns ciphertext as a serializable cipher params object. 7802 */ 7803 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7804 /** 7805 * Configuration options. 7806 * 7807 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7808 */ 7809 cfg: SerializableCipher.cfg.extend({ 7810 kdf: OpenSSLKdf 7811 }), 7812 7813 /** 7814 * Encrypts a message using a password. 7815 * 7816 * @param {Cipher} cipher The cipher algorithm to use. 7817 * @param {WordArray|string} message The message to encrypt. 7818 * @param {string} password The password. 7819 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7820 * 7821 * @return {CipherParams} A cipher params object. 7822 * 7823 * @static 7824 * 7825 * @example 7826 * 7827 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7828 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7829 */ 7830 encrypt: function (cipher, message, password, cfg) { 7831 // Apply config defaults 7832 cfg = this.cfg.extend(cfg); 7833 7834 // Derive key and other params 7835 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7836 7837 // Add IV to config 7838 cfg.iv = derivedParams.iv; 7839 7840 // Encrypt 7841 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7842 7843 // Mix in derived params 7844 ciphertext.mixIn(derivedParams); 7845 7846 return ciphertext; 7847 }, 7848 7849 /** 7850 * Decrypts serialized ciphertext using a password. 7851 * 7852 * @param {Cipher} cipher The cipher algorithm to use. 7853 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7854 * @param {string} password The password. 7855 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7856 * 7857 * @return {WordArray} The plaintext. 7858 * 7859 * @static 7860 * 7861 * @example 7862 * 7863 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 7864 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 7865 */ 7866 decrypt: function (cipher, ciphertext, password, cfg) { 7867 // Apply config defaults 7868 cfg = this.cfg.extend(cfg); 7869 7870 // Convert string to CipherParams 7871 ciphertext = this._parse(ciphertext, cfg.format); 7872 7873 // Derive key and other params 7874 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 7875 7876 // Add IV to config 7877 cfg.iv = derivedParams.iv; 7878 7879 // Decrypt 7880 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 7881 7882 return plaintext; 7883 } 7884 }); 7885 }()); 7886 7887 7888 })); 7889 },{"./core":53}],53:[function(require,module,exports){ 7890 ;(function (root, factory) { 7891 if (typeof exports === "object") { 7892 // CommonJS 7893 module.exports = exports = factory(); 7894 } 7895 else if (typeof define === "function" && define.amd) { 7896 // AMD 7897 define([], factory); 7898 } 7899 else { 7900 // Global (browser) 7901 root.CryptoJS = factory(); 7902 } 7903 }(this, function () { 7904 7905 /** 7906 * CryptoJS core components. 7907 */ 7908 var CryptoJS = CryptoJS || (function (Math, undefined) { 7909 /* 7910 * Local polyfil of Object.create 7911 */ 7912 var create = Object.create || (function () { 7913 function F() {}; 7914 7915 return function (obj) { 7916 var subtype; 7917 7918 F.prototype = obj; 7919 7920 subtype = new F(); 7921 7922 F.prototype = null; 7923 7924 return subtype; 7925 }; 7926 }()) 7927 7928 /** 7929 * CryptoJS namespace. 7930 */ 7931 var C = {}; 7932 7933 /** 7934 * Library namespace. 7935 */ 7936 var C_lib = C.lib = {}; 7937 7938 /** 7939 * Base object for prototypal inheritance. 7940 */ 7941 var Base = C_lib.Base = (function () { 7942 7943 7944 return { 7945 /** 7946 * Creates a new object that inherits from this object. 7947 * 7948 * @param {Object} overrides Properties to copy into the new object. 7949 * 7950 * @return {Object} The new object. 7951 * 7952 * @static 7953 * 7954 * @example 7955 * 7956 * var MyType = CryptoJS.lib.Base.extend({ 7957 * field: 'value', 7958 * 7959 * method: function () { 7960 * } 7961 * }); 7962 */ 7963 extend: function (overrides) { 7964 // Spawn 7965 var subtype = create(this); 7966 7967 // Augment 7968 if (overrides) { 7969 subtype.mixIn(overrides); 7970 } 7971 7972 // Create default initializer 7973 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 7974 subtype.init = function () { 7975 subtype.$super.init.apply(this, arguments); 7976 }; 7977 } 7978 7979 // Initializer's prototype is the subtype object 7980 subtype.init.prototype = subtype; 7981 7982 // Reference supertype 7983 subtype.$super = this; 7984 7985 return subtype; 7986 }, 7987 7988 /** 7989 * Extends this object and runs the init method. 7990 * Arguments to create() will be passed to init(). 7991 * 7992 * @return {Object} The new object. 7993 * 7994 * @static 7995 * 7996 * @example 7997 * 7998 * var instance = MyType.create(); 7999 */ 8000 create: function () { 8001 var instance = this.extend(); 8002 instance.init.apply(instance, arguments); 8003 8004 return instance; 8005 }, 8006 8007 /** 8008 * Initializes a newly created object. 8009 * Override this method to add some logic when your objects are created. 8010 * 8011 * @example 8012 * 8013 * var MyType = CryptoJS.lib.Base.extend({ 8014 * init: function () { 8015 * // ... 8016 * } 8017 * }); 8018 */ 8019 init: function () { 8020 }, 8021 8022 /** 8023 * Copies properties into this object. 8024 * 8025 * @param {Object} properties The properties to mix in. 8026 * 8027 * @example 8028 * 8029 * MyType.mixIn({ 8030 * field: 'value' 8031 * }); 8032 */ 8033 mixIn: function (properties) { 8034 for (var propertyName in properties) { 8035 if (properties.hasOwnProperty(propertyName)) { 8036 this[propertyName] = properties[propertyName]; 8037 } 8038 } 8039 8040 // IE won't copy toString using the loop above 8041 if (properties.hasOwnProperty('toString')) { 8042 this.toString = properties.toString; 8043 } 8044 }, 8045 8046 /** 8047 * Creates a copy of this object. 8048 * 8049 * @return {Object} The clone. 8050 * 8051 * @example 8052 * 8053 * var clone = instance.clone(); 8054 */ 8055 clone: function () { 8056 return this.init.prototype.extend(this); 8057 } 8058 }; 8059 }()); 8060 8061 /** 8062 * An array of 32-bit words. 8063 * 8064 * @property {Array} words The array of 32-bit words. 8065 * @property {number} sigBytes The number of significant bytes in this word array. 8066 */ 8067 var WordArray = C_lib.WordArray = Base.extend({ 8068 /** 8069 * Initializes a newly created word array. 8070 * 8071 * @param {Array} words (Optional) An array of 32-bit words. 8072 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8073 * 8074 * @example 8075 * 8076 * var wordArray = CryptoJS.lib.WordArray.create(); 8077 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8078 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8079 */ 8080 init: function (words, sigBytes) { 8081 words = this.words = words || []; 8082 8083 if (sigBytes != undefined) { 8084 this.sigBytes = sigBytes; 8085 } else { 8086 this.sigBytes = words.length * 4; 8087 } 8088 }, 8089 8090 /** 8091 * Converts this word array to a string. 8092 * 8093 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8094 * 8095 * @return {string} The stringified word array. 8096 * 8097 * @example 8098 * 8099 * var string = wordArray + ''; 8100 * var string = wordArray.toString(); 8101 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8102 */ 8103 toString: function (encoder) { 8104 return (encoder || Hex).stringify(this); 8105 }, 8106 8107 /** 8108 * Concatenates a word array to this word array. 8109 * 8110 * @param {WordArray} wordArray The word array to append. 8111 * 8112 * @return {WordArray} This word array. 8113 * 8114 * @example 8115 * 8116 * wordArray1.concat(wordArray2); 8117 */ 8118 concat: function (wordArray) { 8119 // Shortcuts 8120 var thisWords = this.words; 8121 var thatWords = wordArray.words; 8122 var thisSigBytes = this.sigBytes; 8123 var thatSigBytes = wordArray.sigBytes; 8124 8125 // Clamp excess bits 8126 this.clamp(); 8127 8128 // Concat 8129 if (thisSigBytes % 4) { 8130 // Copy one byte at a time 8131 for (var i = 0; i < thatSigBytes; i++) { 8132 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8133 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8134 } 8135 } else { 8136 // Copy one word at a time 8137 for (var i = 0; i < thatSigBytes; i += 4) { 8138 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8139 } 8140 } 8141 this.sigBytes += thatSigBytes; 8142 8143 // Chainable 8144 return this; 8145 }, 8146 8147 /** 8148 * Removes insignificant bits. 8149 * 8150 * @example 8151 * 8152 * wordArray.clamp(); 8153 */ 8154 clamp: function () { 8155 // Shortcuts 8156 var words = this.words; 8157 var sigBytes = this.sigBytes; 8158 8159 // Clamp 8160 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8161 words.length = Math.ceil(sigBytes / 4); 8162 }, 8163 8164 /** 8165 * Creates a copy of this word array. 8166 * 8167 * @return {WordArray} The clone. 8168 * 8169 * @example 8170 * 8171 * var clone = wordArray.clone(); 8172 */ 8173 clone: function () { 8174 var clone = Base.clone.call(this); 8175 clone.words = this.words.slice(0); 8176 8177 return clone; 8178 }, 8179 8180 /** 8181 * Creates a word array filled with random bytes. 8182 * 8183 * @param {number} nBytes The number of random bytes to generate. 8184 * 8185 * @return {WordArray} The random word array. 8186 * 8187 * @static 8188 * 8189 * @example 8190 * 8191 * var wordArray = CryptoJS.lib.WordArray.random(16); 8192 */ 8193 random: function (nBytes) { 8194 var words = []; 8195 8196 var r = (function (m_w) { 8197 var m_w = m_w; 8198 var m_z = 0x3ade68b1; 8199 var mask = 0xffffffff; 8200 8201 return function () { 8202 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8203 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8204 var result = ((m_z << 0x10) + m_w) & mask; 8205 result /= 0x100000000; 8206 result += 0.5; 8207 return result * (Math.random() > .5 ? 1 : -1); 8208 } 8209 }); 8210 8211 for (var i = 0, rcache; i < nBytes; i += 4) { 8212 var _r = r((rcache || Math.random()) * 0x100000000); 8213 8214 rcache = _r() * 0x3ade67b7; 8215 words.push((_r() * 0x100000000) | 0); 8216 } 8217 8218 return new WordArray.init(words, nBytes); 8219 } 8220 }); 8221 8222 /** 8223 * Encoder namespace. 8224 */ 8225 var C_enc = C.enc = {}; 8226 8227 /** 8228 * Hex encoding strategy. 8229 */ 8230 var Hex = C_enc.Hex = { 8231 /** 8232 * Converts a word array to a hex string. 8233 * 8234 * @param {WordArray} wordArray The word array. 8235 * 8236 * @return {string} The hex string. 8237 * 8238 * @static 8239 * 8240 * @example 8241 * 8242 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8243 */ 8244 stringify: function (wordArray) { 8245 // Shortcuts 8246 var words = wordArray.words; 8247 var sigBytes = wordArray.sigBytes; 8248 8249 // Convert 8250 var hexChars = []; 8251 for (var i = 0; i < sigBytes; i++) { 8252 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8253 hexChars.push((bite >>> 4).toString(16)); 8254 hexChars.push((bite & 0x0f).toString(16)); 8255 } 8256 8257 return hexChars.join(''); 8258 }, 8259 8260 /** 8261 * Converts a hex string to a word array. 8262 * 8263 * @param {string} hexStr The hex string. 8264 * 8265 * @return {WordArray} The word array. 8266 * 8267 * @static 8268 * 8269 * @example 8270 * 8271 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8272 */ 8273 parse: function (hexStr) { 8274 // Shortcut 8275 var hexStrLength = hexStr.length; 8276 8277 // Convert 8278 var words = []; 8279 for (var i = 0; i < hexStrLength; i += 2) { 8280 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8281 } 8282 8283 return new WordArray.init(words, hexStrLength / 2); 8284 } 8285 }; 8286 8287 /** 8288 * Latin1 encoding strategy. 8289 */ 8290 var Latin1 = C_enc.Latin1 = { 8291 /** 8292 * Converts a word array to a Latin1 string. 8293 * 8294 * @param {WordArray} wordArray The word array. 8295 * 8296 * @return {string} The Latin1 string. 8297 * 8298 * @static 8299 * 8300 * @example 8301 * 8302 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8303 */ 8304 stringify: function (wordArray) { 8305 // Shortcuts 8306 var words = wordArray.words; 8307 var sigBytes = wordArray.sigBytes; 8308 8309 // Convert 8310 var latin1Chars = []; 8311 for (var i = 0; i < sigBytes; i++) { 8312 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8313 latin1Chars.push(String.fromCharCode(bite)); 8314 } 8315 8316 return latin1Chars.join(''); 8317 }, 8318 8319 /** 8320 * Converts a Latin1 string to a word array. 8321 * 8322 * @param {string} latin1Str The Latin1 string. 8323 * 8324 * @return {WordArray} The word array. 8325 * 8326 * @static 8327 * 8328 * @example 8329 * 8330 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8331 */ 8332 parse: function (latin1Str) { 8333 // Shortcut 8334 var latin1StrLength = latin1Str.length; 8335 8336 // Convert 8337 var words = []; 8338 for (var i = 0; i < latin1StrLength; i++) { 8339 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8340 } 8341 8342 return new WordArray.init(words, latin1StrLength); 8343 } 8344 }; 8345 8346 /** 8347 * UTF-8 encoding strategy. 8348 */ 8349 var Utf8 = C_enc.Utf8 = { 8350 /** 8351 * Converts a word array to a UTF-8 string. 8352 * 8353 * @param {WordArray} wordArray The word array. 8354 * 8355 * @return {string} The UTF-8 string. 8356 * 8357 * @static 8358 * 8359 * @example 8360 * 8361 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8362 */ 8363 stringify: function (wordArray) { 8364 try { 8365 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8366 } catch (e) { 8367 throw new Error('Malformed UTF-8 data'); 8368 } 8369 }, 8370 8371 /** 8372 * Converts a UTF-8 string to a word array. 8373 * 8374 * @param {string} utf8Str The UTF-8 string. 8375 * 8376 * @return {WordArray} The word array. 8377 * 8378 * @static 8379 * 8380 * @example 8381 * 8382 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8383 */ 8384 parse: function (utf8Str) { 8385 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8386 } 8387 }; 8388 8389 /** 8390 * Abstract buffered block algorithm template. 8391 * 8392 * The property blockSize must be implemented in a concrete subtype. 8393 * 8394 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8395 */ 8396 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8397 /** 8398 * Resets this block algorithm's data buffer to its initial state. 8399 * 8400 * @example 8401 * 8402 * bufferedBlockAlgorithm.reset(); 8403 */ 8404 reset: function () { 8405 // Initial values 8406 this._data = new WordArray.init(); 8407 this._nDataBytes = 0; 8408 }, 8409 8410 /** 8411 * Adds new data to this block algorithm's buffer. 8412 * 8413 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8414 * 8415 * @example 8416 * 8417 * bufferedBlockAlgorithm._append('data'); 8418 * bufferedBlockAlgorithm._append(wordArray); 8419 */ 8420 _append: function (data) { 8421 // Convert string to WordArray, else assume WordArray already 8422 if (typeof data == 'string') { 8423 data = Utf8.parse(data); 8424 } 8425 8426 // Append 8427 this._data.concat(data); 8428 this._nDataBytes += data.sigBytes; 8429 }, 8430 8431 /** 8432 * Processes available data blocks. 8433 * 8434 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8435 * 8436 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8437 * 8438 * @return {WordArray} The processed data. 8439 * 8440 * @example 8441 * 8442 * var processedData = bufferedBlockAlgorithm._process(); 8443 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8444 */ 8445 _process: function (doFlush) { 8446 // Shortcuts 8447 var data = this._data; 8448 var dataWords = data.words; 8449 var dataSigBytes = data.sigBytes; 8450 var blockSize = this.blockSize; 8451 var blockSizeBytes = blockSize * 4; 8452 8453 // Count blocks ready 8454 var nBlocksReady = dataSigBytes / blockSizeBytes; 8455 if (doFlush) { 8456 // Round up to include partial blocks 8457 nBlocksReady = Math.ceil(nBlocksReady); 8458 } else { 8459 // Round down to include only full blocks, 8460 // less the number of blocks that must remain in the buffer 8461 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8462 } 8463 8464 // Count words ready 8465 var nWordsReady = nBlocksReady * blockSize; 8466 8467 // Count bytes ready 8468 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8469 8470 // Process blocks 8471 if (nWordsReady) { 8472 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8473 // Perform concrete-algorithm logic 8474 this._doProcessBlock(dataWords, offset); 8475 } 8476 8477 // Remove processed words 8478 var processedWords = dataWords.splice(0, nWordsReady); 8479 data.sigBytes -= nBytesReady; 8480 } 8481 8482 // Return processed words 8483 return new WordArray.init(processedWords, nBytesReady); 8484 }, 8485 8486 /** 8487 * Creates a copy of this object. 8488 * 8489 * @return {Object} The clone. 8490 * 8491 * @example 8492 * 8493 * var clone = bufferedBlockAlgorithm.clone(); 8494 */ 8495 clone: function () { 8496 var clone = Base.clone.call(this); 8497 clone._data = this._data.clone(); 8498 8499 return clone; 8500 }, 8501 8502 _minBufferSize: 0 8503 }); 8504 8505 /** 8506 * Abstract hasher template. 8507 * 8508 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8509 */ 8510 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8511 /** 8512 * Configuration options. 8513 */ 8514 cfg: Base.extend(), 8515 8516 /** 8517 * Initializes a newly created hasher. 8518 * 8519 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8520 * 8521 * @example 8522 * 8523 * var hasher = CryptoJS.algo.SHA256.create(); 8524 */ 8525 init: function (cfg) { 8526 // Apply config defaults 8527 this.cfg = this.cfg.extend(cfg); 8528 8529 // Set initial values 8530 this.reset(); 8531 }, 8532 8533 /** 8534 * Resets this hasher to its initial state. 8535 * 8536 * @example 8537 * 8538 * hasher.reset(); 8539 */ 8540 reset: function () { 8541 // Reset data buffer 8542 BufferedBlockAlgorithm.reset.call(this); 8543 8544 // Perform concrete-hasher logic 8545 this._doReset(); 8546 }, 8547 8548 /** 8549 * Updates this hasher with a message. 8550 * 8551 * @param {WordArray|string} messageUpdate The message to append. 8552 * 8553 * @return {Hasher} This hasher. 8554 * 8555 * @example 8556 * 8557 * hasher.update('message'); 8558 * hasher.update(wordArray); 8559 */ 8560 update: function (messageUpdate) { 8561 // Append 8562 this._append(messageUpdate); 8563 8564 // Update the hash 8565 this._process(); 8566 8567 // Chainable 8568 return this; 8569 }, 8570 8571 /** 8572 * Finalizes the hash computation. 8573 * Note that the finalize operation is effectively a destructive, read-once operation. 8574 * 8575 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8576 * 8577 * @return {WordArray} The hash. 8578 * 8579 * @example 8580 * 8581 * var hash = hasher.finalize(); 8582 * var hash = hasher.finalize('message'); 8583 * var hash = hasher.finalize(wordArray); 8584 */ 8585 finalize: function (messageUpdate) { 8586 // Final message update 8587 if (messageUpdate) { 8588 this._append(messageUpdate); 8589 } 8590 8591 // Perform concrete-hasher logic 8592 var hash = this._doFinalize(); 8593 8594 return hash; 8595 }, 8596 8597 blockSize: 512/32, 8598 8599 /** 8600 * Creates a shortcut function to a hasher's object interface. 8601 * 8602 * @param {Hasher} hasher The hasher to create a helper for. 8603 * 8604 * @return {Function} The shortcut function. 8605 * 8606 * @static 8607 * 8608 * @example 8609 * 8610 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8611 */ 8612 _createHelper: function (hasher) { 8613 return function (message, cfg) { 8614 return new hasher.init(cfg).finalize(message); 8615 }; 8616 }, 8617 8618 /** 8619 * Creates a shortcut function to the HMAC's object interface. 8620 * 8621 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8622 * 8623 * @return {Function} The shortcut function. 8624 * 8625 * @static 8626 * 8627 * @example 8628 * 8629 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8630 */ 8631 _createHmacHelper: function (hasher) { 8632 return function (message, key) { 8633 return new C_algo.HMAC.init(hasher, key).finalize(message); 8634 }; 8635 } 8636 }); 8637 8638 /** 8639 * Algorithm namespace. 8640 */ 8641 var C_algo = C.algo = {}; 8642 8643 return C; 8644 }(Math)); 8645 8646 8647 return CryptoJS; 8648 8649 })); 8650 },{}],54:[function(require,module,exports){ 8651 ;(function (root, factory) { 8652 if (typeof exports === "object") { 8653 // CommonJS 8654 module.exports = exports = factory(require("./core")); 8655 } 8656 else if (typeof define === "function" && define.amd) { 8657 // AMD 8658 define(["./core"], factory); 8659 } 8660 else { 8661 // Global (browser) 8662 factory(root.CryptoJS); 8663 } 8664 }(this, function (CryptoJS) { 8665 8666 (function () { 8667 // Shortcuts 8668 var C = CryptoJS; 8669 var C_lib = C.lib; 8670 var WordArray = C_lib.WordArray; 8671 var C_enc = C.enc; 8672 8673 /** 8674 * Base64 encoding strategy. 8675 */ 8676 var Base64 = C_enc.Base64 = { 8677 /** 8678 * Converts a word array to a Base64 string. 8679 * 8680 * @param {WordArray} wordArray The word array. 8681 * 8682 * @return {string} The Base64 string. 8683 * 8684 * @static 8685 * 8686 * @example 8687 * 8688 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8689 */ 8690 stringify: function (wordArray) { 8691 // Shortcuts 8692 var words = wordArray.words; 8693 var sigBytes = wordArray.sigBytes; 8694 var map = this._map; 8695 8696 // Clamp excess bits 8697 wordArray.clamp(); 8698 8699 // Convert 8700 var base64Chars = []; 8701 for (var i = 0; i < sigBytes; i += 3) { 8702 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8703 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8704 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8705 8706 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8707 8708 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8709 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8710 } 8711 } 8712 8713 // Add padding 8714 var paddingChar = map.charAt(64); 8715 if (paddingChar) { 8716 while (base64Chars.length % 4) { 8717 base64Chars.push(paddingChar); 8718 } 8719 } 8720 8721 return base64Chars.join(''); 8722 }, 8723 8724 /** 8725 * Converts a Base64 string to a word array. 8726 * 8727 * @param {string} base64Str The Base64 string. 8728 * 8729 * @return {WordArray} The word array. 8730 * 8731 * @static 8732 * 8733 * @example 8734 * 8735 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8736 */ 8737 parse: function (base64Str) { 8738 // Shortcuts 8739 var base64StrLength = base64Str.length; 8740 var map = this._map; 8741 var reverseMap = this._reverseMap; 8742 8743 if (!reverseMap) { 8744 reverseMap = this._reverseMap = []; 8745 for (var j = 0; j < map.length; j++) { 8746 reverseMap[map.charCodeAt(j)] = j; 8747 } 8748 } 8749 8750 // Ignore padding 8751 var paddingChar = map.charAt(64); 8752 if (paddingChar) { 8753 var paddingIndex = base64Str.indexOf(paddingChar); 8754 if (paddingIndex !== -1) { 8755 base64StrLength = paddingIndex; 8756 } 8757 } 8758 8759 // Convert 8760 return parseLoop(base64Str, base64StrLength, reverseMap); 8761 8762 }, 8763 8764 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8765 }; 8766 8767 function parseLoop(base64Str, base64StrLength, reverseMap) { 8768 var words = []; 8769 var nBytes = 0; 8770 for (var i = 0; i < base64StrLength; i++) { 8771 if (i % 4) { 8772 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8773 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8774 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8775 nBytes++; 8776 } 8777 } 8778 return WordArray.create(words, nBytes); 8779 } 8780 }()); 8781 8782 8783 return CryptoJS.enc.Base64; 8784 8785 })); 8786 },{"./core":53}],55:[function(require,module,exports){ 8787 ;(function (root, factory) { 8788 if (typeof exports === "object") { 8789 // CommonJS 8790 module.exports = exports = factory(require("./core")); 8791 } 8792 else if (typeof define === "function" && define.amd) { 8793 // AMD 8794 define(["./core"], factory); 8795 } 8796 else { 8797 // Global (browser) 8798 factory(root.CryptoJS); 8799 } 8800 }(this, function (CryptoJS) { 8801 8802 (function () { 8803 // Shortcuts 8804 var C = CryptoJS; 8805 var C_lib = C.lib; 8806 var WordArray = C_lib.WordArray; 8807 var C_enc = C.enc; 8808 8809 /** 8810 * UTF-16 BE encoding strategy. 8811 */ 8812 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8813 /** 8814 * Converts a word array to a UTF-16 BE string. 8815 * 8816 * @param {WordArray} wordArray The word array. 8817 * 8818 * @return {string} The UTF-16 BE string. 8819 * 8820 * @static 8821 * 8822 * @example 8823 * 8824 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8825 */ 8826 stringify: function (wordArray) { 8827 // Shortcuts 8828 var words = wordArray.words; 8829 var sigBytes = wordArray.sigBytes; 8830 8831 // Convert 8832 var utf16Chars = []; 8833 for (var i = 0; i < sigBytes; i += 2) { 8834 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8835 utf16Chars.push(String.fromCharCode(codePoint)); 8836 } 8837 8838 return utf16Chars.join(''); 8839 }, 8840 8841 /** 8842 * Converts a UTF-16 BE string to a word array. 8843 * 8844 * @param {string} utf16Str The UTF-16 BE string. 8845 * 8846 * @return {WordArray} The word array. 8847 * 8848 * @static 8849 * 8850 * @example 8851 * 8852 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8853 */ 8854 parse: function (utf16Str) { 8855 // Shortcut 8856 var utf16StrLength = utf16Str.length; 8857 8858 // Convert 8859 var words = []; 8860 for (var i = 0; i < utf16StrLength; i++) { 8861 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 8862 } 8863 8864 return WordArray.create(words, utf16StrLength * 2); 8865 } 8866 }; 8867 8868 /** 8869 * UTF-16 LE encoding strategy. 8870 */ 8871 C_enc.Utf16LE = { 8872 /** 8873 * Converts a word array to a UTF-16 LE string. 8874 * 8875 * @param {WordArray} wordArray The word array. 8876 * 8877 * @return {string} The UTF-16 LE string. 8878 * 8879 * @static 8880 * 8881 * @example 8882 * 8883 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 8884 */ 8885 stringify: function (wordArray) { 8886 // Shortcuts 8887 var words = wordArray.words; 8888 var sigBytes = wordArray.sigBytes; 8889 8890 // Convert 8891 var utf16Chars = []; 8892 for (var i = 0; i < sigBytes; i += 2) { 8893 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 8894 utf16Chars.push(String.fromCharCode(codePoint)); 8895 } 8896 8897 return utf16Chars.join(''); 8898 }, 8899 8900 /** 8901 * Converts a UTF-16 LE string to a word array. 8902 * 8903 * @param {string} utf16Str The UTF-16 LE string. 8904 * 8905 * @return {WordArray} The word array. 8906 * 8907 * @static 8908 * 8909 * @example 8910 * 8911 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 8912 */ 8913 parse: function (utf16Str) { 8914 // Shortcut 8915 var utf16StrLength = utf16Str.length; 8916 8917 // Convert 8918 var words = []; 8919 for (var i = 0; i < utf16StrLength; i++) { 8920 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 8921 } 8922 8923 return WordArray.create(words, utf16StrLength * 2); 8924 } 8925 }; 8926 8927 function swapEndian(word) { 8928 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 8929 } 8930 }()); 8931 8932 8933 return CryptoJS.enc.Utf16; 8934 8935 })); 8936 },{"./core":53}],56:[function(require,module,exports){ 8937 ;(function (root, factory, undef) { 8938 if (typeof exports === "object") { 8939 // CommonJS 8940 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 8941 } 8942 else if (typeof define === "function" && define.amd) { 8943 // AMD 8944 define(["./core", "./sha1", "./hmac"], factory); 8945 } 8946 else { 8947 // Global (browser) 8948 factory(root.CryptoJS); 8949 } 8950 }(this, function (CryptoJS) { 8951 8952 (function () { 8953 // Shortcuts 8954 var C = CryptoJS; 8955 var C_lib = C.lib; 8956 var Base = C_lib.Base; 8957 var WordArray = C_lib.WordArray; 8958 var C_algo = C.algo; 8959 var MD5 = C_algo.MD5; 8960 8961 /** 8962 * This key derivation function is meant to conform with EVP_BytesToKey. 8963 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 8964 */ 8965 var EvpKDF = C_algo.EvpKDF = Base.extend({ 8966 /** 8967 * Configuration options. 8968 * 8969 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 8970 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 8971 * @property {number} iterations The number of iterations to perform. Default: 1 8972 */ 8973 cfg: Base.extend({ 8974 keySize: 128/32, 8975 hasher: MD5, 8976 iterations: 1 8977 }), 8978 8979 /** 8980 * Initializes a newly created key derivation function. 8981 * 8982 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 8983 * 8984 * @example 8985 * 8986 * var kdf = CryptoJS.algo.EvpKDF.create(); 8987 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 8988 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 8989 */ 8990 init: function (cfg) { 8991 this.cfg = this.cfg.extend(cfg); 8992 }, 8993 8994 /** 8995 * Derives a key from a password. 8996 * 8997 * @param {WordArray|string} password The password. 8998 * @param {WordArray|string} salt A salt. 8999 * 9000 * @return {WordArray} The derived key. 9001 * 9002 * @example 9003 * 9004 * var key = kdf.compute(password, salt); 9005 */ 9006 compute: function (password, salt) { 9007 // Shortcut 9008 var cfg = this.cfg; 9009 9010 // Init hasher 9011 var hasher = cfg.hasher.create(); 9012 9013 // Initial values 9014 var derivedKey = WordArray.create(); 9015 9016 // Shortcuts 9017 var derivedKeyWords = derivedKey.words; 9018 var keySize = cfg.keySize; 9019 var iterations = cfg.iterations; 9020 9021 // Generate key 9022 while (derivedKeyWords.length < keySize) { 9023 if (block) { 9024 hasher.update(block); 9025 } 9026 var block = hasher.update(password).finalize(salt); 9027 hasher.reset(); 9028 9029 // Iterations 9030 for (var i = 1; i < iterations; i++) { 9031 block = hasher.finalize(block); 9032 hasher.reset(); 9033 } 9034 9035 derivedKey.concat(block); 9036 } 9037 derivedKey.sigBytes = keySize * 4; 9038 9039 return derivedKey; 9040 } 9041 }); 9042 9043 /** 9044 * Derives a key from a password. 9045 * 9046 * @param {WordArray|string} password The password. 9047 * @param {WordArray|string} salt A salt. 9048 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9049 * 9050 * @return {WordArray} The derived key. 9051 * 9052 * @static 9053 * 9054 * @example 9055 * 9056 * var key = CryptoJS.EvpKDF(password, salt); 9057 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9058 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9059 */ 9060 C.EvpKDF = function (password, salt, cfg) { 9061 return EvpKDF.create(cfg).compute(password, salt); 9062 }; 9063 }()); 9064 9065 9066 return CryptoJS.EvpKDF; 9067 9068 })); 9069 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 9070 ;(function (root, factory, undef) { 9071 if (typeof exports === "object") { 9072 // CommonJS 9073 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9074 } 9075 else if (typeof define === "function" && define.amd) { 9076 // AMD 9077 define(["./core", "./cipher-core"], factory); 9078 } 9079 else { 9080 // Global (browser) 9081 factory(root.CryptoJS); 9082 } 9083 }(this, function (CryptoJS) { 9084 9085 (function (undefined) { 9086 // Shortcuts 9087 var C = CryptoJS; 9088 var C_lib = C.lib; 9089 var CipherParams = C_lib.CipherParams; 9090 var C_enc = C.enc; 9091 var Hex = C_enc.Hex; 9092 var C_format = C.format; 9093 9094 var HexFormatter = C_format.Hex = { 9095 /** 9096 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9097 * 9098 * @param {CipherParams} cipherParams The cipher params object. 9099 * 9100 * @return {string} The hexadecimally encoded string. 9101 * 9102 * @static 9103 * 9104 * @example 9105 * 9106 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9107 */ 9108 stringify: function (cipherParams) { 9109 return cipherParams.ciphertext.toString(Hex); 9110 }, 9111 9112 /** 9113 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9114 * 9115 * @param {string} input The hexadecimally encoded string. 9116 * 9117 * @return {CipherParams} The cipher params object. 9118 * 9119 * @static 9120 * 9121 * @example 9122 * 9123 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9124 */ 9125 parse: function (input) { 9126 var ciphertext = Hex.parse(input); 9127 return CipherParams.create({ ciphertext: ciphertext }); 9128 } 9129 }; 9130 }()); 9131 9132 9133 return CryptoJS.format.Hex; 9134 9135 })); 9136 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 9137 ;(function (root, factory) { 9138 if (typeof exports === "object") { 9139 // CommonJS 9140 module.exports = exports = factory(require("./core")); 9141 } 9142 else if (typeof define === "function" && define.amd) { 9143 // AMD 9144 define(["./core"], factory); 9145 } 9146 else { 9147 // Global (browser) 9148 factory(root.CryptoJS); 9149 } 9150 }(this, function (CryptoJS) { 9151 9152 (function () { 9153 // Shortcuts 9154 var C = CryptoJS; 9155 var C_lib = C.lib; 9156 var Base = C_lib.Base; 9157 var C_enc = C.enc; 9158 var Utf8 = C_enc.Utf8; 9159 var C_algo = C.algo; 9160 9161 /** 9162 * HMAC algorithm. 9163 */ 9164 var HMAC = C_algo.HMAC = Base.extend({ 9165 /** 9166 * Initializes a newly created HMAC. 9167 * 9168 * @param {Hasher} hasher The hash algorithm to use. 9169 * @param {WordArray|string} key The secret key. 9170 * 9171 * @example 9172 * 9173 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9174 */ 9175 init: function (hasher, key) { 9176 // Init hasher 9177 hasher = this._hasher = new hasher.init(); 9178 9179 // Convert string to WordArray, else assume WordArray already 9180 if (typeof key == 'string') { 9181 key = Utf8.parse(key); 9182 } 9183 9184 // Shortcuts 9185 var hasherBlockSize = hasher.blockSize; 9186 var hasherBlockSizeBytes = hasherBlockSize * 4; 9187 9188 // Allow arbitrary length keys 9189 if (key.sigBytes > hasherBlockSizeBytes) { 9190 key = hasher.finalize(key); 9191 } 9192 9193 // Clamp excess bits 9194 key.clamp(); 9195 9196 // Clone key for inner and outer pads 9197 var oKey = this._oKey = key.clone(); 9198 var iKey = this._iKey = key.clone(); 9199 9200 // Shortcuts 9201 var oKeyWords = oKey.words; 9202 var iKeyWords = iKey.words; 9203 9204 // XOR keys with pad constants 9205 for (var i = 0; i < hasherBlockSize; i++) { 9206 oKeyWords[i] ^= 0x5c5c5c5c; 9207 iKeyWords[i] ^= 0x36363636; 9208 } 9209 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9210 9211 // Set initial values 9212 this.reset(); 9213 }, 9214 9215 /** 9216 * Resets this HMAC to its initial state. 9217 * 9218 * @example 9219 * 9220 * hmacHasher.reset(); 9221 */ 9222 reset: function () { 9223 // Shortcut 9224 var hasher = this._hasher; 9225 9226 // Reset 9227 hasher.reset(); 9228 hasher.update(this._iKey); 9229 }, 9230 9231 /** 9232 * Updates this HMAC with a message. 9233 * 9234 * @param {WordArray|string} messageUpdate The message to append. 9235 * 9236 * @return {HMAC} This HMAC instance. 9237 * 9238 * @example 9239 * 9240 * hmacHasher.update('message'); 9241 * hmacHasher.update(wordArray); 9242 */ 9243 update: function (messageUpdate) { 9244 this._hasher.update(messageUpdate); 9245 9246 // Chainable 9247 return this; 9248 }, 9249 9250 /** 9251 * Finalizes the HMAC computation. 9252 * Note that the finalize operation is effectively a destructive, read-once operation. 9253 * 9254 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9255 * 9256 * @return {WordArray} The HMAC. 9257 * 9258 * @example 9259 * 9260 * var hmac = hmacHasher.finalize(); 9261 * var hmac = hmacHasher.finalize('message'); 9262 * var hmac = hmacHasher.finalize(wordArray); 9263 */ 9264 finalize: function (messageUpdate) { 9265 // Shortcut 9266 var hasher = this._hasher; 9267 9268 // Compute HMAC 9269 var innerHash = hasher.finalize(messageUpdate); 9270 hasher.reset(); 9271 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9272 9273 return hmac; 9274 } 9275 }); 9276 }()); 9277 9278 9279 })); 9280 },{"./core":53}],59:[function(require,module,exports){ 9281 ;(function (root, factory, undef) { 9282 if (typeof exports === "object") { 9283 // CommonJS 9284 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")); 9285 } 9286 else if (typeof define === "function" && define.amd) { 9287 // AMD 9288 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); 9289 } 9290 else { 9291 // Global (browser) 9292 root.CryptoJS = factory(root.CryptoJS); 9293 } 9294 }(this, function (CryptoJS) { 9295 9296 return CryptoJS; 9297 9298 })); 9299 },{"./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){ 9300 ;(function (root, factory) { 9301 if (typeof exports === "object") { 9302 // CommonJS 9303 module.exports = exports = factory(require("./core")); 9304 } 9305 else if (typeof define === "function" && define.amd) { 9306 // AMD 9307 define(["./core"], factory); 9308 } 9309 else { 9310 // Global (browser) 9311 factory(root.CryptoJS); 9312 } 9313 }(this, function (CryptoJS) { 9314 9315 (function () { 9316 // Check if typed arrays are supported 9317 if (typeof ArrayBuffer != 'function') { 9318 return; 9319 } 9320 9321 // Shortcuts 9322 var C = CryptoJS; 9323 var C_lib = C.lib; 9324 var WordArray = C_lib.WordArray; 9325 9326 // Reference original init 9327 var superInit = WordArray.init; 9328 9329 // Augment WordArray.init to handle typed arrays 9330 var subInit = WordArray.init = function (typedArray) { 9331 // Convert buffers to uint8 9332 if (typedArray instanceof ArrayBuffer) { 9333 typedArray = new Uint8Array(typedArray); 9334 } 9335 9336 // Convert other array views to uint8 9337 if ( 9338 typedArray instanceof Int8Array || 9339 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9340 typedArray instanceof Int16Array || 9341 typedArray instanceof Uint16Array || 9342 typedArray instanceof Int32Array || 9343 typedArray instanceof Uint32Array || 9344 typedArray instanceof Float32Array || 9345 typedArray instanceof Float64Array 9346 ) { 9347 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9348 } 9349 9350 // Handle Uint8Array 9351 if (typedArray instanceof Uint8Array) { 9352 // Shortcut 9353 var typedArrayByteLength = typedArray.byteLength; 9354 9355 // Extract bytes 9356 var words = []; 9357 for (var i = 0; i < typedArrayByteLength; i++) { 9358 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9359 } 9360 9361 // Initialize this word array 9362 superInit.call(this, words, typedArrayByteLength); 9363 } else { 9364 // Else call normal init 9365 superInit.apply(this, arguments); 9366 } 9367 }; 9368 9369 subInit.prototype = WordArray; 9370 }()); 9371 9372 9373 return CryptoJS.lib.WordArray; 9374 9375 })); 9376 },{"./core":53}],61:[function(require,module,exports){ 9377 ;(function (root, factory) { 9378 if (typeof exports === "object") { 9379 // CommonJS 9380 module.exports = exports = factory(require("./core")); 9381 } 9382 else if (typeof define === "function" && define.amd) { 9383 // AMD 9384 define(["./core"], factory); 9385 } 9386 else { 9387 // Global (browser) 9388 factory(root.CryptoJS); 9389 } 9390 }(this, function (CryptoJS) { 9391 9392 (function (Math) { 9393 // Shortcuts 9394 var C = CryptoJS; 9395 var C_lib = C.lib; 9396 var WordArray = C_lib.WordArray; 9397 var Hasher = C_lib.Hasher; 9398 var C_algo = C.algo; 9399 9400 // Constants table 9401 var T = []; 9402 9403 // Compute constants 9404 (function () { 9405 for (var i = 0; i < 64; i++) { 9406 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9407 } 9408 }()); 9409 9410 /** 9411 * MD5 hash algorithm. 9412 */ 9413 var MD5 = C_algo.MD5 = Hasher.extend({ 9414 _doReset: function () { 9415 this._hash = new WordArray.init([ 9416 0x67452301, 0xefcdab89, 9417 0x98badcfe, 0x10325476 9418 ]); 9419 }, 9420 9421 _doProcessBlock: function (M, offset) { 9422 // Swap endian 9423 for (var i = 0; i < 16; i++) { 9424 // Shortcuts 9425 var offset_i = offset + i; 9426 var M_offset_i = M[offset_i]; 9427 9428 M[offset_i] = ( 9429 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9430 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9431 ); 9432 } 9433 9434 // Shortcuts 9435 var H = this._hash.words; 9436 9437 var M_offset_0 = M[offset + 0]; 9438 var M_offset_1 = M[offset + 1]; 9439 var M_offset_2 = M[offset + 2]; 9440 var M_offset_3 = M[offset + 3]; 9441 var M_offset_4 = M[offset + 4]; 9442 var M_offset_5 = M[offset + 5]; 9443 var M_offset_6 = M[offset + 6]; 9444 var M_offset_7 = M[offset + 7]; 9445 var M_offset_8 = M[offset + 8]; 9446 var M_offset_9 = M[offset + 9]; 9447 var M_offset_10 = M[offset + 10]; 9448 var M_offset_11 = M[offset + 11]; 9449 var M_offset_12 = M[offset + 12]; 9450 var M_offset_13 = M[offset + 13]; 9451 var M_offset_14 = M[offset + 14]; 9452 var M_offset_15 = M[offset + 15]; 9453 9454 // Working varialbes 9455 var a = H[0]; 9456 var b = H[1]; 9457 var c = H[2]; 9458 var d = H[3]; 9459 9460 // Computation 9461 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9462 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9463 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9464 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9465 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9466 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9467 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9468 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9469 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9470 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9471 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9472 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9473 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9474 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9475 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9476 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9477 9478 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9479 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9480 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9481 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9482 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9483 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9484 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9485 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9486 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9487 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9488 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9489 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9490 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9491 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9492 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9493 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9494 9495 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9496 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9497 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9498 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9499 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9500 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9501 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9502 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9503 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9504 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9505 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9506 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9507 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9508 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9509 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9510 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9511 9512 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9513 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9514 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9515 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9516 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9517 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9518 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9519 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9520 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9521 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9522 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9523 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9524 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9525 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9526 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9527 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9528 9529 // Intermediate hash value 9530 H[0] = (H[0] + a) | 0; 9531 H[1] = (H[1] + b) | 0; 9532 H[2] = (H[2] + c) | 0; 9533 H[3] = (H[3] + d) | 0; 9534 }, 9535 9536 _doFinalize: function () { 9537 // Shortcuts 9538 var data = this._data; 9539 var dataWords = data.words; 9540 9541 var nBitsTotal = this._nDataBytes * 8; 9542 var nBitsLeft = data.sigBytes * 8; 9543 9544 // Add padding 9545 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9546 9547 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9548 var nBitsTotalL = nBitsTotal; 9549 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9550 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9551 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9552 ); 9553 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9554 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9555 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9556 ); 9557 9558 data.sigBytes = (dataWords.length + 1) * 4; 9559 9560 // Hash final blocks 9561 this._process(); 9562 9563 // Shortcuts 9564 var hash = this._hash; 9565 var H = hash.words; 9566 9567 // Swap endian 9568 for (var i = 0; i < 4; i++) { 9569 // Shortcut 9570 var H_i = H[i]; 9571 9572 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9573 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9574 } 9575 9576 // Return final computed hash 9577 return hash; 9578 }, 9579 9580 clone: function () { 9581 var clone = Hasher.clone.call(this); 9582 clone._hash = this._hash.clone(); 9583 9584 return clone; 9585 } 9586 }); 9587 9588 function FF(a, b, c, d, x, s, t) { 9589 var n = a + ((b & c) | (~b & d)) + x + t; 9590 return ((n << s) | (n >>> (32 - s))) + b; 9591 } 9592 9593 function GG(a, b, c, d, x, s, t) { 9594 var n = a + ((b & d) | (c & ~d)) + x + t; 9595 return ((n << s) | (n >>> (32 - s))) + b; 9596 } 9597 9598 function HH(a, b, c, d, x, s, t) { 9599 var n = a + (b ^ c ^ d) + x + t; 9600 return ((n << s) | (n >>> (32 - s))) + b; 9601 } 9602 9603 function II(a, b, c, d, x, s, t) { 9604 var n = a + (c ^ (b | ~d)) + x + t; 9605 return ((n << s) | (n >>> (32 - s))) + b; 9606 } 9607 9608 /** 9609 * Shortcut function to the hasher's object interface. 9610 * 9611 * @param {WordArray|string} message The message to hash. 9612 * 9613 * @return {WordArray} The hash. 9614 * 9615 * @static 9616 * 9617 * @example 9618 * 9619 * var hash = CryptoJS.MD5('message'); 9620 * var hash = CryptoJS.MD5(wordArray); 9621 */ 9622 C.MD5 = Hasher._createHelper(MD5); 9623 9624 /** 9625 * Shortcut function to the HMAC's object interface. 9626 * 9627 * @param {WordArray|string} message The message to hash. 9628 * @param {WordArray|string} key The secret key. 9629 * 9630 * @return {WordArray} The HMAC. 9631 * 9632 * @static 9633 * 9634 * @example 9635 * 9636 * var hmac = CryptoJS.HmacMD5(message, key); 9637 */ 9638 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9639 }(Math)); 9640 9641 9642 return CryptoJS.MD5; 9643 9644 })); 9645 },{"./core":53}],62:[function(require,module,exports){ 9646 ;(function (root, factory, undef) { 9647 if (typeof exports === "object") { 9648 // CommonJS 9649 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9650 } 9651 else if (typeof define === "function" && define.amd) { 9652 // AMD 9653 define(["./core", "./cipher-core"], factory); 9654 } 9655 else { 9656 // Global (browser) 9657 factory(root.CryptoJS); 9658 } 9659 }(this, function (CryptoJS) { 9660 9661 /** 9662 * Cipher Feedback block mode. 9663 */ 9664 CryptoJS.mode.CFB = (function () { 9665 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9666 9667 CFB.Encryptor = CFB.extend({ 9668 processBlock: function (words, offset) { 9669 // Shortcuts 9670 var cipher = this._cipher; 9671 var blockSize = cipher.blockSize; 9672 9673 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9674 9675 // Remember this block to use with next block 9676 this._prevBlock = words.slice(offset, offset + blockSize); 9677 } 9678 }); 9679 9680 CFB.Decryptor = CFB.extend({ 9681 processBlock: function (words, offset) { 9682 // Shortcuts 9683 var cipher = this._cipher; 9684 var blockSize = cipher.blockSize; 9685 9686 // Remember this block to use with next block 9687 var thisBlock = words.slice(offset, offset + blockSize); 9688 9689 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9690 9691 // This block becomes the previous block 9692 this._prevBlock = thisBlock; 9693 } 9694 }); 9695 9696 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9697 // Shortcut 9698 var iv = this._iv; 9699 9700 // Generate keystream 9701 if (iv) { 9702 var keystream = iv.slice(0); 9703 9704 // Remove IV for subsequent blocks 9705 this._iv = undefined; 9706 } else { 9707 var keystream = this._prevBlock; 9708 } 9709 cipher.encryptBlock(keystream, 0); 9710 9711 // Encrypt 9712 for (var i = 0; i < blockSize; i++) { 9713 words[offset + i] ^= keystream[i]; 9714 } 9715 } 9716 9717 return CFB; 9718 }()); 9719 9720 9721 return CryptoJS.mode.CFB; 9722 9723 })); 9724 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 9725 ;(function (root, factory, undef) { 9726 if (typeof exports === "object") { 9727 // CommonJS 9728 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9729 } 9730 else if (typeof define === "function" && define.amd) { 9731 // AMD 9732 define(["./core", "./cipher-core"], factory); 9733 } 9734 else { 9735 // Global (browser) 9736 factory(root.CryptoJS); 9737 } 9738 }(this, function (CryptoJS) { 9739 9740 /** @preserve 9741 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9742 * derived from CryptoJS.mode.CTR 9743 * Jan Hruby jhruby.web@gmail.com 9744 */ 9745 CryptoJS.mode.CTRGladman = (function () { 9746 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9747 9748 function incWord(word) 9749 { 9750 if (((word >> 24) & 0xff) === 0xff) { //overflow 9751 var b1 = (word >> 16)&0xff; 9752 var b2 = (word >> 8)&0xff; 9753 var b3 = word & 0xff; 9754 9755 if (b1 === 0xff) // overflow b1 9756 { 9757 b1 = 0; 9758 if (b2 === 0xff) 9759 { 9760 b2 = 0; 9761 if (b3 === 0xff) 9762 { 9763 b3 = 0; 9764 } 9765 else 9766 { 9767 ++b3; 9768 } 9769 } 9770 else 9771 { 9772 ++b2; 9773 } 9774 } 9775 else 9776 { 9777 ++b1; 9778 } 9779 9780 word = 0; 9781 word += (b1 << 16); 9782 word += (b2 << 8); 9783 word += b3; 9784 } 9785 else 9786 { 9787 word += (0x01 << 24); 9788 } 9789 return word; 9790 } 9791 9792 function incCounter(counter) 9793 { 9794 if ((counter[0] = incWord(counter[0])) === 0) 9795 { 9796 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9797 counter[1] = incWord(counter[1]); 9798 } 9799 return counter; 9800 } 9801 9802 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9803 processBlock: function (words, offset) { 9804 // Shortcuts 9805 var cipher = this._cipher 9806 var blockSize = cipher.blockSize; 9807 var iv = this._iv; 9808 var counter = this._counter; 9809 9810 // Generate keystream 9811 if (iv) { 9812 counter = this._counter = iv.slice(0); 9813 9814 // Remove IV for subsequent blocks 9815 this._iv = undefined; 9816 } 9817 9818 incCounter(counter); 9819 9820 var keystream = counter.slice(0); 9821 cipher.encryptBlock(keystream, 0); 9822 9823 // Encrypt 9824 for (var i = 0; i < blockSize; i++) { 9825 words[offset + i] ^= keystream[i]; 9826 } 9827 } 9828 }); 9829 9830 CTRGladman.Decryptor = Encryptor; 9831 9832 return CTRGladman; 9833 }()); 9834 9835 9836 9837 9838 return CryptoJS.mode.CTRGladman; 9839 9840 })); 9841 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 9842 ;(function (root, factory, undef) { 9843 if (typeof exports === "object") { 9844 // CommonJS 9845 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9846 } 9847 else if (typeof define === "function" && define.amd) { 9848 // AMD 9849 define(["./core", "./cipher-core"], factory); 9850 } 9851 else { 9852 // Global (browser) 9853 factory(root.CryptoJS); 9854 } 9855 }(this, function (CryptoJS) { 9856 9857 /** 9858 * Counter block mode. 9859 */ 9860 CryptoJS.mode.CTR = (function () { 9861 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 9862 9863 var Encryptor = CTR.Encryptor = CTR.extend({ 9864 processBlock: function (words, offset) { 9865 // Shortcuts 9866 var cipher = this._cipher 9867 var blockSize = cipher.blockSize; 9868 var iv = this._iv; 9869 var counter = this._counter; 9870 9871 // Generate keystream 9872 if (iv) { 9873 counter = this._counter = iv.slice(0); 9874 9875 // Remove IV for subsequent blocks 9876 this._iv = undefined; 9877 } 9878 var keystream = counter.slice(0); 9879 cipher.encryptBlock(keystream, 0); 9880 9881 // Increment counter 9882 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 9883 9884 // Encrypt 9885 for (var i = 0; i < blockSize; i++) { 9886 words[offset + i] ^= keystream[i]; 9887 } 9888 } 9889 }); 9890 9891 CTR.Decryptor = Encryptor; 9892 9893 return CTR; 9894 }()); 9895 9896 9897 return CryptoJS.mode.CTR; 9898 9899 })); 9900 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 9901 ;(function (root, factory, undef) { 9902 if (typeof exports === "object") { 9903 // CommonJS 9904 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9905 } 9906 else if (typeof define === "function" && define.amd) { 9907 // AMD 9908 define(["./core", "./cipher-core"], factory); 9909 } 9910 else { 9911 // Global (browser) 9912 factory(root.CryptoJS); 9913 } 9914 }(this, function (CryptoJS) { 9915 9916 /** 9917 * Electronic Codebook block mode. 9918 */ 9919 CryptoJS.mode.ECB = (function () { 9920 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 9921 9922 ECB.Encryptor = ECB.extend({ 9923 processBlock: function (words, offset) { 9924 this._cipher.encryptBlock(words, offset); 9925 } 9926 }); 9927 9928 ECB.Decryptor = ECB.extend({ 9929 processBlock: function (words, offset) { 9930 this._cipher.decryptBlock(words, offset); 9931 } 9932 }); 9933 9934 return ECB; 9935 }()); 9936 9937 9938 return CryptoJS.mode.ECB; 9939 9940 })); 9941 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 9942 ;(function (root, factory, undef) { 9943 if (typeof exports === "object") { 9944 // CommonJS 9945 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9946 } 9947 else if (typeof define === "function" && define.amd) { 9948 // AMD 9949 define(["./core", "./cipher-core"], factory); 9950 } 9951 else { 9952 // Global (browser) 9953 factory(root.CryptoJS); 9954 } 9955 }(this, function (CryptoJS) { 9956 9957 /** 9958 * Output Feedback block mode. 9959 */ 9960 CryptoJS.mode.OFB = (function () { 9961 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 9962 9963 var Encryptor = OFB.Encryptor = OFB.extend({ 9964 processBlock: function (words, offset) { 9965 // Shortcuts 9966 var cipher = this._cipher 9967 var blockSize = cipher.blockSize; 9968 var iv = this._iv; 9969 var keystream = this._keystream; 9970 9971 // Generate keystream 9972 if (iv) { 9973 keystream = this._keystream = iv.slice(0); 9974 9975 // Remove IV for subsequent blocks 9976 this._iv = undefined; 9977 } 9978 cipher.encryptBlock(keystream, 0); 9979 9980 // Encrypt 9981 for (var i = 0; i < blockSize; i++) { 9982 words[offset + i] ^= keystream[i]; 9983 } 9984 } 9985 }); 9986 9987 OFB.Decryptor = Encryptor; 9988 9989 return OFB; 9990 }()); 9991 9992 9993 return CryptoJS.mode.OFB; 9994 9995 })); 9996 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 9997 ;(function (root, factory, undef) { 9998 if (typeof exports === "object") { 9999 // CommonJS 10000 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10001 } 10002 else if (typeof define === "function" && define.amd) { 10003 // AMD 10004 define(["./core", "./cipher-core"], factory); 10005 } 10006 else { 10007 // Global (browser) 10008 factory(root.CryptoJS); 10009 } 10010 }(this, function (CryptoJS) { 10011 10012 /** 10013 * ANSI X.923 padding strategy. 10014 */ 10015 CryptoJS.pad.AnsiX923 = { 10016 pad: function (data, blockSize) { 10017 // Shortcuts 10018 var dataSigBytes = data.sigBytes; 10019 var blockSizeBytes = blockSize * 4; 10020 10021 // Count padding bytes 10022 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10023 10024 // Compute last byte position 10025 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10026 10027 // Pad 10028 data.clamp(); 10029 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10030 data.sigBytes += nPaddingBytes; 10031 }, 10032 10033 unpad: function (data) { 10034 // Get number of padding bytes from last byte 10035 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10036 10037 // Remove padding 10038 data.sigBytes -= nPaddingBytes; 10039 } 10040 }; 10041 10042 10043 return CryptoJS.pad.Ansix923; 10044 10045 })); 10046 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 10047 ;(function (root, factory, undef) { 10048 if (typeof exports === "object") { 10049 // CommonJS 10050 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10051 } 10052 else if (typeof define === "function" && define.amd) { 10053 // AMD 10054 define(["./core", "./cipher-core"], factory); 10055 } 10056 else { 10057 // Global (browser) 10058 factory(root.CryptoJS); 10059 } 10060 }(this, function (CryptoJS) { 10061 10062 /** 10063 * ISO 10126 padding strategy. 10064 */ 10065 CryptoJS.pad.Iso10126 = { 10066 pad: function (data, blockSize) { 10067 // Shortcut 10068 var blockSizeBytes = blockSize * 4; 10069 10070 // Count padding bytes 10071 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10072 10073 // Pad 10074 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10075 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10076 }, 10077 10078 unpad: function (data) { 10079 // Get number of padding bytes from last byte 10080 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10081 10082 // Remove padding 10083 data.sigBytes -= nPaddingBytes; 10084 } 10085 }; 10086 10087 10088 return CryptoJS.pad.Iso10126; 10089 10090 })); 10091 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 10092 ;(function (root, factory, undef) { 10093 if (typeof exports === "object") { 10094 // CommonJS 10095 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10096 } 10097 else if (typeof define === "function" && define.amd) { 10098 // AMD 10099 define(["./core", "./cipher-core"], factory); 10100 } 10101 else { 10102 // Global (browser) 10103 factory(root.CryptoJS); 10104 } 10105 }(this, function (CryptoJS) { 10106 10107 /** 10108 * ISO/IEC 9797-1 Padding Method 2. 10109 */ 10110 CryptoJS.pad.Iso97971 = { 10111 pad: function (data, blockSize) { 10112 // Add 0x80 byte 10113 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10114 10115 // Zero pad the rest 10116 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10117 }, 10118 10119 unpad: function (data) { 10120 // Remove zero padding 10121 CryptoJS.pad.ZeroPadding.unpad(data); 10122 10123 // Remove one more byte -- the 0x80 byte 10124 data.sigBytes--; 10125 } 10126 }; 10127 10128 10129 return CryptoJS.pad.Iso97971; 10130 10131 })); 10132 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 10133 ;(function (root, factory, undef) { 10134 if (typeof exports === "object") { 10135 // CommonJS 10136 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10137 } 10138 else if (typeof define === "function" && define.amd) { 10139 // AMD 10140 define(["./core", "./cipher-core"], factory); 10141 } 10142 else { 10143 // Global (browser) 10144 factory(root.CryptoJS); 10145 } 10146 }(this, function (CryptoJS) { 10147 10148 /** 10149 * A noop padding strategy. 10150 */ 10151 CryptoJS.pad.NoPadding = { 10152 pad: function () { 10153 }, 10154 10155 unpad: function () { 10156 } 10157 }; 10158 10159 10160 return CryptoJS.pad.NoPadding; 10161 10162 })); 10163 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 10164 ;(function (root, factory, undef) { 10165 if (typeof exports === "object") { 10166 // CommonJS 10167 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10168 } 10169 else if (typeof define === "function" && define.amd) { 10170 // AMD 10171 define(["./core", "./cipher-core"], factory); 10172 } 10173 else { 10174 // Global (browser) 10175 factory(root.CryptoJS); 10176 } 10177 }(this, function (CryptoJS) { 10178 10179 /** 10180 * Zero padding strategy. 10181 */ 10182 CryptoJS.pad.ZeroPadding = { 10183 pad: function (data, blockSize) { 10184 // Shortcut 10185 var blockSizeBytes = blockSize * 4; 10186 10187 // Pad 10188 data.clamp(); 10189 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10190 }, 10191 10192 unpad: function (data) { 10193 // Shortcut 10194 var dataWords = data.words; 10195 10196 // Unpad 10197 var i = data.sigBytes - 1; 10198 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10199 i--; 10200 } 10201 data.sigBytes = i + 1; 10202 } 10203 }; 10204 10205 10206 return CryptoJS.pad.ZeroPadding; 10207 10208 })); 10209 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 10210 ;(function (root, factory, undef) { 10211 if (typeof exports === "object") { 10212 // CommonJS 10213 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10214 } 10215 else if (typeof define === "function" && define.amd) { 10216 // AMD 10217 define(["./core", "./sha1", "./hmac"], factory); 10218 } 10219 else { 10220 // Global (browser) 10221 factory(root.CryptoJS); 10222 } 10223 }(this, function (CryptoJS) { 10224 10225 (function () { 10226 // Shortcuts 10227 var C = CryptoJS; 10228 var C_lib = C.lib; 10229 var Base = C_lib.Base; 10230 var WordArray = C_lib.WordArray; 10231 var C_algo = C.algo; 10232 var SHA1 = C_algo.SHA1; 10233 var HMAC = C_algo.HMAC; 10234 10235 /** 10236 * Password-Based Key Derivation Function 2 algorithm. 10237 */ 10238 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10239 /** 10240 * Configuration options. 10241 * 10242 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10243 * @property {Hasher} hasher The hasher to use. Default: SHA1 10244 * @property {number} iterations The number of iterations to perform. Default: 1 10245 */ 10246 cfg: Base.extend({ 10247 keySize: 128/32, 10248 hasher: SHA1, 10249 iterations: 1 10250 }), 10251 10252 /** 10253 * Initializes a newly created key derivation function. 10254 * 10255 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10256 * 10257 * @example 10258 * 10259 * var kdf = CryptoJS.algo.PBKDF2.create(); 10260 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10261 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10262 */ 10263 init: function (cfg) { 10264 this.cfg = this.cfg.extend(cfg); 10265 }, 10266 10267 /** 10268 * Computes the Password-Based Key Derivation Function 2. 10269 * 10270 * @param {WordArray|string} password The password. 10271 * @param {WordArray|string} salt A salt. 10272 * 10273 * @return {WordArray} The derived key. 10274 * 10275 * @example 10276 * 10277 * var key = kdf.compute(password, salt); 10278 */ 10279 compute: function (password, salt) { 10280 // Shortcut 10281 var cfg = this.cfg; 10282 10283 // Init HMAC 10284 var hmac = HMAC.create(cfg.hasher, password); 10285 10286 // Initial values 10287 var derivedKey = WordArray.create(); 10288 var blockIndex = WordArray.create([0x00000001]); 10289 10290 // Shortcuts 10291 var derivedKeyWords = derivedKey.words; 10292 var blockIndexWords = blockIndex.words; 10293 var keySize = cfg.keySize; 10294 var iterations = cfg.iterations; 10295 10296 // Generate key 10297 while (derivedKeyWords.length < keySize) { 10298 var block = hmac.update(salt).finalize(blockIndex); 10299 hmac.reset(); 10300 10301 // Shortcuts 10302 var blockWords = block.words; 10303 var blockWordsLength = blockWords.length; 10304 10305 // Iterations 10306 var intermediate = block; 10307 for (var i = 1; i < iterations; i++) { 10308 intermediate = hmac.finalize(intermediate); 10309 hmac.reset(); 10310 10311 // Shortcut 10312 var intermediateWords = intermediate.words; 10313 10314 // XOR intermediate with block 10315 for (var j = 0; j < blockWordsLength; j++) { 10316 blockWords[j] ^= intermediateWords[j]; 10317 } 10318 } 10319 10320 derivedKey.concat(block); 10321 blockIndexWords[0]++; 10322 } 10323 derivedKey.sigBytes = keySize * 4; 10324 10325 return derivedKey; 10326 } 10327 }); 10328 10329 /** 10330 * Computes the Password-Based Key Derivation Function 2. 10331 * 10332 * @param {WordArray|string} password The password. 10333 * @param {WordArray|string} salt A salt. 10334 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10335 * 10336 * @return {WordArray} The derived key. 10337 * 10338 * @static 10339 * 10340 * @example 10341 * 10342 * var key = CryptoJS.PBKDF2(password, salt); 10343 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10344 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10345 */ 10346 C.PBKDF2 = function (password, salt, cfg) { 10347 return PBKDF2.create(cfg).compute(password, salt); 10348 }; 10349 }()); 10350 10351 10352 return CryptoJS.PBKDF2; 10353 10354 })); 10355 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 10356 ;(function (root, factory, undef) { 10357 if (typeof exports === "object") { 10358 // CommonJS 10359 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10360 } 10361 else if (typeof define === "function" && define.amd) { 10362 // AMD 10363 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10364 } 10365 else { 10366 // Global (browser) 10367 factory(root.CryptoJS); 10368 } 10369 }(this, function (CryptoJS) { 10370 10371 (function () { 10372 // Shortcuts 10373 var C = CryptoJS; 10374 var C_lib = C.lib; 10375 var StreamCipher = C_lib.StreamCipher; 10376 var C_algo = C.algo; 10377 10378 // Reusable objects 10379 var S = []; 10380 var C_ = []; 10381 var G = []; 10382 10383 /** 10384 * Rabbit stream cipher algorithm. 10385 * 10386 * This is a legacy version that neglected to convert the key to little-endian. 10387 * This error doesn't affect the cipher's security, 10388 * but it does affect its compatibility with other implementations. 10389 */ 10390 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10391 _doReset: function () { 10392 // Shortcuts 10393 var K = this._key.words; 10394 var iv = this.cfg.iv; 10395 10396 // Generate initial state values 10397 var X = this._X = [ 10398 K[0], (K[3] << 16) | (K[2] >>> 16), 10399 K[1], (K[0] << 16) | (K[3] >>> 16), 10400 K[2], (K[1] << 16) | (K[0] >>> 16), 10401 K[3], (K[2] << 16) | (K[1] >>> 16) 10402 ]; 10403 10404 // Generate initial counter values 10405 var C = this._C = [ 10406 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10407 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10408 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10409 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10410 ]; 10411 10412 // Carry bit 10413 this._b = 0; 10414 10415 // Iterate the system four times 10416 for (var i = 0; i < 4; i++) { 10417 nextState.call(this); 10418 } 10419 10420 // Modify the counters 10421 for (var i = 0; i < 8; i++) { 10422 C[i] ^= X[(i + 4) & 7]; 10423 } 10424 10425 // IV setup 10426 if (iv) { 10427 // Shortcuts 10428 var IV = iv.words; 10429 var IV_0 = IV[0]; 10430 var IV_1 = IV[1]; 10431 10432 // Generate four subvectors 10433 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10434 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10435 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10436 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10437 10438 // Modify counter values 10439 C[0] ^= i0; 10440 C[1] ^= i1; 10441 C[2] ^= i2; 10442 C[3] ^= i3; 10443 C[4] ^= i0; 10444 C[5] ^= i1; 10445 C[6] ^= i2; 10446 C[7] ^= i3; 10447 10448 // Iterate the system four times 10449 for (var i = 0; i < 4; i++) { 10450 nextState.call(this); 10451 } 10452 } 10453 }, 10454 10455 _doProcessBlock: function (M, offset) { 10456 // Shortcut 10457 var X = this._X; 10458 10459 // Iterate the system 10460 nextState.call(this); 10461 10462 // Generate four keystream words 10463 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10464 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10465 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10466 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10467 10468 for (var i = 0; i < 4; i++) { 10469 // Swap endian 10470 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10471 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10472 10473 // Encrypt 10474 M[offset + i] ^= S[i]; 10475 } 10476 }, 10477 10478 blockSize: 128/32, 10479 10480 ivSize: 64/32 10481 }); 10482 10483 function nextState() { 10484 // Shortcuts 10485 var X = this._X; 10486 var C = this._C; 10487 10488 // Save old counter values 10489 for (var i = 0; i < 8; i++) { 10490 C_[i] = C[i]; 10491 } 10492 10493 // Calculate new counter values 10494 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10495 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10496 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10497 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10498 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10499 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10500 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10501 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10502 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10503 10504 // Calculate the g-values 10505 for (var i = 0; i < 8; i++) { 10506 var gx = X[i] + C[i]; 10507 10508 // Construct high and low argument for squaring 10509 var ga = gx & 0xffff; 10510 var gb = gx >>> 16; 10511 10512 // Calculate high and low result of squaring 10513 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10514 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10515 10516 // High XOR low 10517 G[i] = gh ^ gl; 10518 } 10519 10520 // Calculate new state values 10521 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10522 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10523 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10524 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10525 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10526 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10527 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10528 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10529 } 10530 10531 /** 10532 * Shortcut functions to the cipher's object interface. 10533 * 10534 * @example 10535 * 10536 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10537 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10538 */ 10539 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10540 }()); 10541 10542 10543 return CryptoJS.RabbitLegacy; 10544 10545 })); 10546 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 10547 ;(function (root, factory, undef) { 10548 if (typeof exports === "object") { 10549 // CommonJS 10550 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10551 } 10552 else if (typeof define === "function" && define.amd) { 10553 // AMD 10554 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10555 } 10556 else { 10557 // Global (browser) 10558 factory(root.CryptoJS); 10559 } 10560 }(this, function (CryptoJS) { 10561 10562 (function () { 10563 // Shortcuts 10564 var C = CryptoJS; 10565 var C_lib = C.lib; 10566 var StreamCipher = C_lib.StreamCipher; 10567 var C_algo = C.algo; 10568 10569 // Reusable objects 10570 var S = []; 10571 var C_ = []; 10572 var G = []; 10573 10574 /** 10575 * Rabbit stream cipher algorithm 10576 */ 10577 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10578 _doReset: function () { 10579 // Shortcuts 10580 var K = this._key.words; 10581 var iv = this.cfg.iv; 10582 10583 // Swap endian 10584 for (var i = 0; i < 4; i++) { 10585 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10586 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10587 } 10588 10589 // Generate initial state values 10590 var X = this._X = [ 10591 K[0], (K[3] << 16) | (K[2] >>> 16), 10592 K[1], (K[0] << 16) | (K[3] >>> 16), 10593 K[2], (K[1] << 16) | (K[0] >>> 16), 10594 K[3], (K[2] << 16) | (K[1] >>> 16) 10595 ]; 10596 10597 // Generate initial counter values 10598 var C = this._C = [ 10599 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10600 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10601 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10602 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10603 ]; 10604 10605 // Carry bit 10606 this._b = 0; 10607 10608 // Iterate the system four times 10609 for (var i = 0; i < 4; i++) { 10610 nextState.call(this); 10611 } 10612 10613 // Modify the counters 10614 for (var i = 0; i < 8; i++) { 10615 C[i] ^= X[(i + 4) & 7]; 10616 } 10617 10618 // IV setup 10619 if (iv) { 10620 // Shortcuts 10621 var IV = iv.words; 10622 var IV_0 = IV[0]; 10623 var IV_1 = IV[1]; 10624 10625 // Generate four subvectors 10626 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10627 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10628 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10629 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10630 10631 // Modify counter values 10632 C[0] ^= i0; 10633 C[1] ^= i1; 10634 C[2] ^= i2; 10635 C[3] ^= i3; 10636 C[4] ^= i0; 10637 C[5] ^= i1; 10638 C[6] ^= i2; 10639 C[7] ^= i3; 10640 10641 // Iterate the system four times 10642 for (var i = 0; i < 4; i++) { 10643 nextState.call(this); 10644 } 10645 } 10646 }, 10647 10648 _doProcessBlock: function (M, offset) { 10649 // Shortcut 10650 var X = this._X; 10651 10652 // Iterate the system 10653 nextState.call(this); 10654 10655 // Generate four keystream words 10656 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10657 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10658 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10659 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10660 10661 for (var i = 0; i < 4; i++) { 10662 // Swap endian 10663 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10664 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10665 10666 // Encrypt 10667 M[offset + i] ^= S[i]; 10668 } 10669 }, 10670 10671 blockSize: 128/32, 10672 10673 ivSize: 64/32 10674 }); 10675 10676 function nextState() { 10677 // Shortcuts 10678 var X = this._X; 10679 var C = this._C; 10680 10681 // Save old counter values 10682 for (var i = 0; i < 8; i++) { 10683 C_[i] = C[i]; 10684 } 10685 10686 // Calculate new counter values 10687 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10688 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10689 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10690 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10691 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10692 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10693 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10694 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10695 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10696 10697 // Calculate the g-values 10698 for (var i = 0; i < 8; i++) { 10699 var gx = X[i] + C[i]; 10700 10701 // Construct high and low argument for squaring 10702 var ga = gx & 0xffff; 10703 var gb = gx >>> 16; 10704 10705 // Calculate high and low result of squaring 10706 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10707 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10708 10709 // High XOR low 10710 G[i] = gh ^ gl; 10711 } 10712 10713 // Calculate new state values 10714 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10715 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10716 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10717 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10718 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10719 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10720 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10721 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10722 } 10723 10724 /** 10725 * Shortcut functions to the cipher's object interface. 10726 * 10727 * @example 10728 * 10729 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10730 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10731 */ 10732 C.Rabbit = StreamCipher._createHelper(Rabbit); 10733 }()); 10734 10735 10736 return CryptoJS.Rabbit; 10737 10738 })); 10739 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 10740 ;(function (root, factory, undef) { 10741 if (typeof exports === "object") { 10742 // CommonJS 10743 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10744 } 10745 else if (typeof define === "function" && define.amd) { 10746 // AMD 10747 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10748 } 10749 else { 10750 // Global (browser) 10751 factory(root.CryptoJS); 10752 } 10753 }(this, function (CryptoJS) { 10754 10755 (function () { 10756 // Shortcuts 10757 var C = CryptoJS; 10758 var C_lib = C.lib; 10759 var StreamCipher = C_lib.StreamCipher; 10760 var C_algo = C.algo; 10761 10762 /** 10763 * RC4 stream cipher algorithm. 10764 */ 10765 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10766 _doReset: function () { 10767 // Shortcuts 10768 var key = this._key; 10769 var keyWords = key.words; 10770 var keySigBytes = key.sigBytes; 10771 10772 // Init sbox 10773 var S = this._S = []; 10774 for (var i = 0; i < 256; i++) { 10775 S[i] = i; 10776 } 10777 10778 // Key setup 10779 for (var i = 0, j = 0; i < 256; i++) { 10780 var keyByteIndex = i % keySigBytes; 10781 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10782 10783 j = (j + S[i] + keyByte) % 256; 10784 10785 // Swap 10786 var t = S[i]; 10787 S[i] = S[j]; 10788 S[j] = t; 10789 } 10790 10791 // Counters 10792 this._i = this._j = 0; 10793 }, 10794 10795 _doProcessBlock: function (M, offset) { 10796 M[offset] ^= generateKeystreamWord.call(this); 10797 }, 10798 10799 keySize: 256/32, 10800 10801 ivSize: 0 10802 }); 10803 10804 function generateKeystreamWord() { 10805 // Shortcuts 10806 var S = this._S; 10807 var i = this._i; 10808 var j = this._j; 10809 10810 // Generate keystream word 10811 var keystreamWord = 0; 10812 for (var n = 0; n < 4; n++) { 10813 i = (i + 1) % 256; 10814 j = (j + S[i]) % 256; 10815 10816 // Swap 10817 var t = S[i]; 10818 S[i] = S[j]; 10819 S[j] = t; 10820 10821 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 10822 } 10823 10824 // Update counters 10825 this._i = i; 10826 this._j = j; 10827 10828 return keystreamWord; 10829 } 10830 10831 /** 10832 * Shortcut functions to the cipher's object interface. 10833 * 10834 * @example 10835 * 10836 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 10837 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 10838 */ 10839 C.RC4 = StreamCipher._createHelper(RC4); 10840 10841 /** 10842 * Modified RC4 stream cipher algorithm. 10843 */ 10844 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 10845 /** 10846 * Configuration options. 10847 * 10848 * @property {number} drop The number of keystream words to drop. Default 192 10849 */ 10850 cfg: RC4.cfg.extend({ 10851 drop: 192 10852 }), 10853 10854 _doReset: function () { 10855 RC4._doReset.call(this); 10856 10857 // Drop 10858 for (var i = this.cfg.drop; i > 0; i--) { 10859 generateKeystreamWord.call(this); 10860 } 10861 } 10862 }); 10863 10864 /** 10865 * Shortcut functions to the cipher's object interface. 10866 * 10867 * @example 10868 * 10869 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 10870 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 10871 */ 10872 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 10873 }()); 10874 10875 10876 return CryptoJS.RC4; 10877 10878 })); 10879 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 10880 ;(function (root, factory) { 10881 if (typeof exports === "object") { 10882 // CommonJS 10883 module.exports = exports = factory(require("./core")); 10884 } 10885 else if (typeof define === "function" && define.amd) { 10886 // AMD 10887 define(["./core"], factory); 10888 } 10889 else { 10890 // Global (browser) 10891 factory(root.CryptoJS); 10892 } 10893 }(this, function (CryptoJS) { 10894 10895 /** @preserve 10896 (c) 2012 by Cédric Mesnil. All rights reserved. 10897 10898 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10899 10900 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10901 - 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. 10902 10903 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. 10904 */ 10905 10906 (function (Math) { 10907 // Shortcuts 10908 var C = CryptoJS; 10909 var C_lib = C.lib; 10910 var WordArray = C_lib.WordArray; 10911 var Hasher = C_lib.Hasher; 10912 var C_algo = C.algo; 10913 10914 // Constants table 10915 var _zl = WordArray.create([ 10916 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10917 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 10918 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 10919 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 10920 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 10921 var _zr = WordArray.create([ 10922 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 10923 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 10924 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 10925 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 10926 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 10927 var _sl = WordArray.create([ 10928 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 10929 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 10930 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 10931 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 10932 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 10933 var _sr = WordArray.create([ 10934 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 10935 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 10936 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 10937 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 10938 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 10939 10940 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 10941 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 10942 10943 /** 10944 * RIPEMD160 hash algorithm. 10945 */ 10946 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 10947 _doReset: function () { 10948 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 10949 }, 10950 10951 _doProcessBlock: function (M, offset) { 10952 10953 // Swap endian 10954 for (var i = 0; i < 16; i++) { 10955 // Shortcuts 10956 var offset_i = offset + i; 10957 var M_offset_i = M[offset_i]; 10958 10959 // Swap 10960 M[offset_i] = ( 10961 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10962 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 10963 ); 10964 } 10965 // Shortcut 10966 var H = this._hash.words; 10967 var hl = _hl.words; 10968 var hr = _hr.words; 10969 var zl = _zl.words; 10970 var zr = _zr.words; 10971 var sl = _sl.words; 10972 var sr = _sr.words; 10973 10974 // Working variables 10975 var al, bl, cl, dl, el; 10976 var ar, br, cr, dr, er; 10977 10978 ar = al = H[0]; 10979 br = bl = H[1]; 10980 cr = cl = H[2]; 10981 dr = dl = H[3]; 10982 er = el = H[4]; 10983 // Computation 10984 var t; 10985 for (var i = 0; i < 80; i += 1) { 10986 t = (al + M[offset+zl[i]])|0; 10987 if (i<16){ 10988 t += f1(bl,cl,dl) + hl[0]; 10989 } else if (i<32) { 10990 t += f2(bl,cl,dl) + hl[1]; 10991 } else if (i<48) { 10992 t += f3(bl,cl,dl) + hl[2]; 10993 } else if (i<64) { 10994 t += f4(bl,cl,dl) + hl[3]; 10995 } else {// if (i<80) { 10996 t += f5(bl,cl,dl) + hl[4]; 10997 } 10998 t = t|0; 10999 t = rotl(t,sl[i]); 11000 t = (t+el)|0; 11001 al = el; 11002 el = dl; 11003 dl = rotl(cl, 10); 11004 cl = bl; 11005 bl = t; 11006 11007 t = (ar + M[offset+zr[i]])|0; 11008 if (i<16){ 11009 t += f5(br,cr,dr) + hr[0]; 11010 } else if (i<32) { 11011 t += f4(br,cr,dr) + hr[1]; 11012 } else if (i<48) { 11013 t += f3(br,cr,dr) + hr[2]; 11014 } else if (i<64) { 11015 t += f2(br,cr,dr) + hr[3]; 11016 } else {// if (i<80) { 11017 t += f1(br,cr,dr) + hr[4]; 11018 } 11019 t = t|0; 11020 t = rotl(t,sr[i]) ; 11021 t = (t+er)|0; 11022 ar = er; 11023 er = dr; 11024 dr = rotl(cr, 10); 11025 cr = br; 11026 br = t; 11027 } 11028 // Intermediate hash value 11029 t = (H[1] + cl + dr)|0; 11030 H[1] = (H[2] + dl + er)|0; 11031 H[2] = (H[3] + el + ar)|0; 11032 H[3] = (H[4] + al + br)|0; 11033 H[4] = (H[0] + bl + cr)|0; 11034 H[0] = t; 11035 }, 11036 11037 _doFinalize: function () { 11038 // Shortcuts 11039 var data = this._data; 11040 var dataWords = data.words; 11041 11042 var nBitsTotal = this._nDataBytes * 8; 11043 var nBitsLeft = data.sigBytes * 8; 11044 11045 // Add padding 11046 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11047 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11048 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11049 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11050 ); 11051 data.sigBytes = (dataWords.length + 1) * 4; 11052 11053 // Hash final blocks 11054 this._process(); 11055 11056 // Shortcuts 11057 var hash = this._hash; 11058 var H = hash.words; 11059 11060 // Swap endian 11061 for (var i = 0; i < 5; i++) { 11062 // Shortcut 11063 var H_i = H[i]; 11064 11065 // Swap 11066 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11067 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11068 } 11069 11070 // Return final computed hash 11071 return hash; 11072 }, 11073 11074 clone: function () { 11075 var clone = Hasher.clone.call(this); 11076 clone._hash = this._hash.clone(); 11077 11078 return clone; 11079 } 11080 }); 11081 11082 11083 function f1(x, y, z) { 11084 return ((x) ^ (y) ^ (z)); 11085 11086 } 11087 11088 function f2(x, y, z) { 11089 return (((x)&(y)) | ((~x)&(z))); 11090 } 11091 11092 function f3(x, y, z) { 11093 return (((x) | (~(y))) ^ (z)); 11094 } 11095 11096 function f4(x, y, z) { 11097 return (((x) & (z)) | ((y)&(~(z)))); 11098 } 11099 11100 function f5(x, y, z) { 11101 return ((x) ^ ((y) |(~(z)))); 11102 11103 } 11104 11105 function rotl(x,n) { 11106 return (x<<n) | (x>>>(32-n)); 11107 } 11108 11109 11110 /** 11111 * Shortcut function to the hasher's object interface. 11112 * 11113 * @param {WordArray|string} message The message to hash. 11114 * 11115 * @return {WordArray} The hash. 11116 * 11117 * @static 11118 * 11119 * @example 11120 * 11121 * var hash = CryptoJS.RIPEMD160('message'); 11122 * var hash = CryptoJS.RIPEMD160(wordArray); 11123 */ 11124 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11125 11126 /** 11127 * Shortcut function to the HMAC's object interface. 11128 * 11129 * @param {WordArray|string} message The message to hash. 11130 * @param {WordArray|string} key The secret key. 11131 * 11132 * @return {WordArray} The HMAC. 11133 * 11134 * @static 11135 * 11136 * @example 11137 * 11138 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11139 */ 11140 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11141 }(Math)); 11142 11143 11144 return CryptoJS.RIPEMD160; 11145 11146 })); 11147 },{"./core":53}],77:[function(require,module,exports){ 11148 ;(function (root, factory) { 11149 if (typeof exports === "object") { 11150 // CommonJS 11151 module.exports = exports = factory(require("./core")); 11152 } 11153 else if (typeof define === "function" && define.amd) { 11154 // AMD 11155 define(["./core"], factory); 11156 } 11157 else { 11158 // Global (browser) 11159 factory(root.CryptoJS); 11160 } 11161 }(this, function (CryptoJS) { 11162 11163 (function () { 11164 // Shortcuts 11165 var C = CryptoJS; 11166 var C_lib = C.lib; 11167 var WordArray = C_lib.WordArray; 11168 var Hasher = C_lib.Hasher; 11169 var C_algo = C.algo; 11170 11171 // Reusable object 11172 var W = []; 11173 11174 /** 11175 * SHA-1 hash algorithm. 11176 */ 11177 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11178 _doReset: function () { 11179 this._hash = new WordArray.init([ 11180 0x67452301, 0xefcdab89, 11181 0x98badcfe, 0x10325476, 11182 0xc3d2e1f0 11183 ]); 11184 }, 11185 11186 _doProcessBlock: function (M, offset) { 11187 // Shortcut 11188 var H = this._hash.words; 11189 11190 // Working variables 11191 var a = H[0]; 11192 var b = H[1]; 11193 var c = H[2]; 11194 var d = H[3]; 11195 var e = H[4]; 11196 11197 // Computation 11198 for (var i = 0; i < 80; i++) { 11199 if (i < 16) { 11200 W[i] = M[offset + i] | 0; 11201 } else { 11202 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11203 W[i] = (n << 1) | (n >>> 31); 11204 } 11205 11206 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11207 if (i < 20) { 11208 t += ((b & c) | (~b & d)) + 0x5a827999; 11209 } else if (i < 40) { 11210 t += (b ^ c ^ d) + 0x6ed9eba1; 11211 } else if (i < 60) { 11212 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11213 } else /* if (i < 80) */ { 11214 t += (b ^ c ^ d) - 0x359d3e2a; 11215 } 11216 11217 e = d; 11218 d = c; 11219 c = (b << 30) | (b >>> 2); 11220 b = a; 11221 a = t; 11222 } 11223 11224 // Intermediate hash value 11225 H[0] = (H[0] + a) | 0; 11226 H[1] = (H[1] + b) | 0; 11227 H[2] = (H[2] + c) | 0; 11228 H[3] = (H[3] + d) | 0; 11229 H[4] = (H[4] + e) | 0; 11230 }, 11231 11232 _doFinalize: function () { 11233 // Shortcuts 11234 var data = this._data; 11235 var dataWords = data.words; 11236 11237 var nBitsTotal = this._nDataBytes * 8; 11238 var nBitsLeft = data.sigBytes * 8; 11239 11240 // Add padding 11241 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11242 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11243 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11244 data.sigBytes = dataWords.length * 4; 11245 11246 // Hash final blocks 11247 this._process(); 11248 11249 // Return final computed hash 11250 return this._hash; 11251 }, 11252 11253 clone: function () { 11254 var clone = Hasher.clone.call(this); 11255 clone._hash = this._hash.clone(); 11256 11257 return clone; 11258 } 11259 }); 11260 11261 /** 11262 * Shortcut function to the hasher's object interface. 11263 * 11264 * @param {WordArray|string} message The message to hash. 11265 * 11266 * @return {WordArray} The hash. 11267 * 11268 * @static 11269 * 11270 * @example 11271 * 11272 * var hash = CryptoJS.SHA1('message'); 11273 * var hash = CryptoJS.SHA1(wordArray); 11274 */ 11275 C.SHA1 = Hasher._createHelper(SHA1); 11276 11277 /** 11278 * Shortcut function to the HMAC's object interface. 11279 * 11280 * @param {WordArray|string} message The message to hash. 11281 * @param {WordArray|string} key The secret key. 11282 * 11283 * @return {WordArray} The HMAC. 11284 * 11285 * @static 11286 * 11287 * @example 11288 * 11289 * var hmac = CryptoJS.HmacSHA1(message, key); 11290 */ 11291 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11292 }()); 11293 11294 11295 return CryptoJS.SHA1; 11296 11297 })); 11298 },{"./core":53}],78:[function(require,module,exports){ 11299 ;(function (root, factory, undef) { 11300 if (typeof exports === "object") { 11301 // CommonJS 11302 module.exports = exports = factory(require("./core"), require("./sha256")); 11303 } 11304 else if (typeof define === "function" && define.amd) { 11305 // AMD 11306 define(["./core", "./sha256"], factory); 11307 } 11308 else { 11309 // Global (browser) 11310 factory(root.CryptoJS); 11311 } 11312 }(this, function (CryptoJS) { 11313 11314 (function () { 11315 // Shortcuts 11316 var C = CryptoJS; 11317 var C_lib = C.lib; 11318 var WordArray = C_lib.WordArray; 11319 var C_algo = C.algo; 11320 var SHA256 = C_algo.SHA256; 11321 11322 /** 11323 * SHA-224 hash algorithm. 11324 */ 11325 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11326 _doReset: function () { 11327 this._hash = new WordArray.init([ 11328 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11329 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11330 ]); 11331 }, 11332 11333 _doFinalize: function () { 11334 var hash = SHA256._doFinalize.call(this); 11335 11336 hash.sigBytes -= 4; 11337 11338 return hash; 11339 } 11340 }); 11341 11342 /** 11343 * Shortcut function to the hasher's object interface. 11344 * 11345 * @param {WordArray|string} message The message to hash. 11346 * 11347 * @return {WordArray} The hash. 11348 * 11349 * @static 11350 * 11351 * @example 11352 * 11353 * var hash = CryptoJS.SHA224('message'); 11354 * var hash = CryptoJS.SHA224(wordArray); 11355 */ 11356 C.SHA224 = SHA256._createHelper(SHA224); 11357 11358 /** 11359 * Shortcut function to the HMAC's object interface. 11360 * 11361 * @param {WordArray|string} message The message to hash. 11362 * @param {WordArray|string} key The secret key. 11363 * 11364 * @return {WordArray} The HMAC. 11365 * 11366 * @static 11367 * 11368 * @example 11369 * 11370 * var hmac = CryptoJS.HmacSHA224(message, key); 11371 */ 11372 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11373 }()); 11374 11375 11376 return CryptoJS.SHA224; 11377 11378 })); 11379 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 11380 ;(function (root, factory) { 11381 if (typeof exports === "object") { 11382 // CommonJS 11383 module.exports = exports = factory(require("./core")); 11384 } 11385 else if (typeof define === "function" && define.amd) { 11386 // AMD 11387 define(["./core"], factory); 11388 } 11389 else { 11390 // Global (browser) 11391 factory(root.CryptoJS); 11392 } 11393 }(this, function (CryptoJS) { 11394 11395 (function (Math) { 11396 // Shortcuts 11397 var C = CryptoJS; 11398 var C_lib = C.lib; 11399 var WordArray = C_lib.WordArray; 11400 var Hasher = C_lib.Hasher; 11401 var C_algo = C.algo; 11402 11403 // Initialization and round constants tables 11404 var H = []; 11405 var K = []; 11406 11407 // Compute constants 11408 (function () { 11409 function isPrime(n) { 11410 var sqrtN = Math.sqrt(n); 11411 for (var factor = 2; factor <= sqrtN; factor++) { 11412 if (!(n % factor)) { 11413 return false; 11414 } 11415 } 11416 11417 return true; 11418 } 11419 11420 function getFractionalBits(n) { 11421 return ((n - (n | 0)) * 0x100000000) | 0; 11422 } 11423 11424 var n = 2; 11425 var nPrime = 0; 11426 while (nPrime < 64) { 11427 if (isPrime(n)) { 11428 if (nPrime < 8) { 11429 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11430 } 11431 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11432 11433 nPrime++; 11434 } 11435 11436 n++; 11437 } 11438 }()); 11439 11440 // Reusable object 11441 var W = []; 11442 11443 /** 11444 * SHA-256 hash algorithm. 11445 */ 11446 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11447 _doReset: function () { 11448 this._hash = new WordArray.init(H.slice(0)); 11449 }, 11450 11451 _doProcessBlock: function (M, offset) { 11452 // Shortcut 11453 var H = this._hash.words; 11454 11455 // Working variables 11456 var a = H[0]; 11457 var b = H[1]; 11458 var c = H[2]; 11459 var d = H[3]; 11460 var e = H[4]; 11461 var f = H[5]; 11462 var g = H[6]; 11463 var h = H[7]; 11464 11465 // Computation 11466 for (var i = 0; i < 64; i++) { 11467 if (i < 16) { 11468 W[i] = M[offset + i] | 0; 11469 } else { 11470 var gamma0x = W[i - 15]; 11471 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11472 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11473 (gamma0x >>> 3); 11474 11475 var gamma1x = W[i - 2]; 11476 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11477 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11478 (gamma1x >>> 10); 11479 11480 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11481 } 11482 11483 var ch = (e & f) ^ (~e & g); 11484 var maj = (a & b) ^ (a & c) ^ (b & c); 11485 11486 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11487 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11488 11489 var t1 = h + sigma1 + ch + K[i] + W[i]; 11490 var t2 = sigma0 + maj; 11491 11492 h = g; 11493 g = f; 11494 f = e; 11495 e = (d + t1) | 0; 11496 d = c; 11497 c = b; 11498 b = a; 11499 a = (t1 + t2) | 0; 11500 } 11501 11502 // Intermediate hash value 11503 H[0] = (H[0] + a) | 0; 11504 H[1] = (H[1] + b) | 0; 11505 H[2] = (H[2] + c) | 0; 11506 H[3] = (H[3] + d) | 0; 11507 H[4] = (H[4] + e) | 0; 11508 H[5] = (H[5] + f) | 0; 11509 H[6] = (H[6] + g) | 0; 11510 H[7] = (H[7] + h) | 0; 11511 }, 11512 11513 _doFinalize: function () { 11514 // Shortcuts 11515 var data = this._data; 11516 var dataWords = data.words; 11517 11518 var nBitsTotal = this._nDataBytes * 8; 11519 var nBitsLeft = data.sigBytes * 8; 11520 11521 // Add padding 11522 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11523 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11524 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11525 data.sigBytes = dataWords.length * 4; 11526 11527 // Hash final blocks 11528 this._process(); 11529 11530 // Return final computed hash 11531 return this._hash; 11532 }, 11533 11534 clone: function () { 11535 var clone = Hasher.clone.call(this); 11536 clone._hash = this._hash.clone(); 11537 11538 return clone; 11539 } 11540 }); 11541 11542 /** 11543 * Shortcut function to the hasher's object interface. 11544 * 11545 * @param {WordArray|string} message The message to hash. 11546 * 11547 * @return {WordArray} The hash. 11548 * 11549 * @static 11550 * 11551 * @example 11552 * 11553 * var hash = CryptoJS.SHA256('message'); 11554 * var hash = CryptoJS.SHA256(wordArray); 11555 */ 11556 C.SHA256 = Hasher._createHelper(SHA256); 11557 11558 /** 11559 * Shortcut function to the HMAC's object interface. 11560 * 11561 * @param {WordArray|string} message The message to hash. 11562 * @param {WordArray|string} key The secret key. 11563 * 11564 * @return {WordArray} The HMAC. 11565 * 11566 * @static 11567 * 11568 * @example 11569 * 11570 * var hmac = CryptoJS.HmacSHA256(message, key); 11571 */ 11572 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11573 }(Math)); 11574 11575 11576 return CryptoJS.SHA256; 11577 11578 })); 11579 },{"./core":53}],80:[function(require,module,exports){ 11580 ;(function (root, factory, undef) { 11581 if (typeof exports === "object") { 11582 // CommonJS 11583 module.exports = exports = factory(require("./core"), require("./x64-core")); 11584 } 11585 else if (typeof define === "function" && define.amd) { 11586 // AMD 11587 define(["./core", "./x64-core"], factory); 11588 } 11589 else { 11590 // Global (browser) 11591 factory(root.CryptoJS); 11592 } 11593 }(this, function (CryptoJS) { 11594 11595 (function (Math) { 11596 // Shortcuts 11597 var C = CryptoJS; 11598 var C_lib = C.lib; 11599 var WordArray = C_lib.WordArray; 11600 var Hasher = C_lib.Hasher; 11601 var C_x64 = C.x64; 11602 var X64Word = C_x64.Word; 11603 var C_algo = C.algo; 11604 11605 // Constants tables 11606 var RHO_OFFSETS = []; 11607 var PI_INDEXES = []; 11608 var ROUND_CONSTANTS = []; 11609 11610 // Compute Constants 11611 (function () { 11612 // Compute rho offset constants 11613 var x = 1, y = 0; 11614 for (var t = 0; t < 24; t++) { 11615 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11616 11617 var newX = y % 5; 11618 var newY = (2 * x + 3 * y) % 5; 11619 x = newX; 11620 y = newY; 11621 } 11622 11623 // Compute pi index constants 11624 for (var x = 0; x < 5; x++) { 11625 for (var y = 0; y < 5; y++) { 11626 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11627 } 11628 } 11629 11630 // Compute round constants 11631 var LFSR = 0x01; 11632 for (var i = 0; i < 24; i++) { 11633 var roundConstantMsw = 0; 11634 var roundConstantLsw = 0; 11635 11636 for (var j = 0; j < 7; j++) { 11637 if (LFSR & 0x01) { 11638 var bitPosition = (1 << j) - 1; 11639 if (bitPosition < 32) { 11640 roundConstantLsw ^= 1 << bitPosition; 11641 } else /* if (bitPosition >= 32) */ { 11642 roundConstantMsw ^= 1 << (bitPosition - 32); 11643 } 11644 } 11645 11646 // Compute next LFSR 11647 if (LFSR & 0x80) { 11648 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11649 LFSR = (LFSR << 1) ^ 0x71; 11650 } else { 11651 LFSR <<= 1; 11652 } 11653 } 11654 11655 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11656 } 11657 }()); 11658 11659 // Reusable objects for temporary values 11660 var T = []; 11661 (function () { 11662 for (var i = 0; i < 25; i++) { 11663 T[i] = X64Word.create(); 11664 } 11665 }()); 11666 11667 /** 11668 * SHA-3 hash algorithm. 11669 */ 11670 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11671 /** 11672 * Configuration options. 11673 * 11674 * @property {number} outputLength 11675 * The desired number of bits in the output hash. 11676 * Only values permitted are: 224, 256, 384, 512. 11677 * Default: 512 11678 */ 11679 cfg: Hasher.cfg.extend({ 11680 outputLength: 512 11681 }), 11682 11683 _doReset: function () { 11684 var state = this._state = [] 11685 for (var i = 0; i < 25; i++) { 11686 state[i] = new X64Word.init(); 11687 } 11688 11689 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11690 }, 11691 11692 _doProcessBlock: function (M, offset) { 11693 // Shortcuts 11694 var state = this._state; 11695 var nBlockSizeLanes = this.blockSize / 2; 11696 11697 // Absorb 11698 for (var i = 0; i < nBlockSizeLanes; i++) { 11699 // Shortcuts 11700 var M2i = M[offset + 2 * i]; 11701 var M2i1 = M[offset + 2 * i + 1]; 11702 11703 // Swap endian 11704 M2i = ( 11705 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11706 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11707 ); 11708 M2i1 = ( 11709 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11710 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11711 ); 11712 11713 // Absorb message into state 11714 var lane = state[i]; 11715 lane.high ^= M2i1; 11716 lane.low ^= M2i; 11717 } 11718 11719 // Rounds 11720 for (var round = 0; round < 24; round++) { 11721 // Theta 11722 for (var x = 0; x < 5; x++) { 11723 // Mix column lanes 11724 var tMsw = 0, tLsw = 0; 11725 for (var y = 0; y < 5; y++) { 11726 var lane = state[x + 5 * y]; 11727 tMsw ^= lane.high; 11728 tLsw ^= lane.low; 11729 } 11730 11731 // Temporary values 11732 var Tx = T[x]; 11733 Tx.high = tMsw; 11734 Tx.low = tLsw; 11735 } 11736 for (var x = 0; x < 5; x++) { 11737 // Shortcuts 11738 var Tx4 = T[(x + 4) % 5]; 11739 var Tx1 = T[(x + 1) % 5]; 11740 var Tx1Msw = Tx1.high; 11741 var Tx1Lsw = Tx1.low; 11742 11743 // Mix surrounding columns 11744 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11745 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11746 for (var y = 0; y < 5; y++) { 11747 var lane = state[x + 5 * y]; 11748 lane.high ^= tMsw; 11749 lane.low ^= tLsw; 11750 } 11751 } 11752 11753 // Rho Pi 11754 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11755 // Shortcuts 11756 var lane = state[laneIndex]; 11757 var laneMsw = lane.high; 11758 var laneLsw = lane.low; 11759 var rhoOffset = RHO_OFFSETS[laneIndex]; 11760 11761 // Rotate lanes 11762 if (rhoOffset < 32) { 11763 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11764 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11765 } else /* if (rhoOffset >= 32) */ { 11766 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11767 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11768 } 11769 11770 // Transpose lanes 11771 var TPiLane = T[PI_INDEXES[laneIndex]]; 11772 TPiLane.high = tMsw; 11773 TPiLane.low = tLsw; 11774 } 11775 11776 // Rho pi at x = y = 0 11777 var T0 = T[0]; 11778 var state0 = state[0]; 11779 T0.high = state0.high; 11780 T0.low = state0.low; 11781 11782 // Chi 11783 for (var x = 0; x < 5; x++) { 11784 for (var y = 0; y < 5; y++) { 11785 // Shortcuts 11786 var laneIndex = x + 5 * y; 11787 var lane = state[laneIndex]; 11788 var TLane = T[laneIndex]; 11789 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 11790 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 11791 11792 // Mix rows 11793 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 11794 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 11795 } 11796 } 11797 11798 // Iota 11799 var lane = state[0]; 11800 var roundConstant = ROUND_CONSTANTS[round]; 11801 lane.high ^= roundConstant.high; 11802 lane.low ^= roundConstant.low;; 11803 } 11804 }, 11805 11806 _doFinalize: function () { 11807 // Shortcuts 11808 var data = this._data; 11809 var dataWords = data.words; 11810 var nBitsTotal = this._nDataBytes * 8; 11811 var nBitsLeft = data.sigBytes * 8; 11812 var blockSizeBits = this.blockSize * 32; 11813 11814 // Add padding 11815 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 11816 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 11817 data.sigBytes = dataWords.length * 4; 11818 11819 // Hash final blocks 11820 this._process(); 11821 11822 // Shortcuts 11823 var state = this._state; 11824 var outputLengthBytes = this.cfg.outputLength / 8; 11825 var outputLengthLanes = outputLengthBytes / 8; 11826 11827 // Squeeze 11828 var hashWords = []; 11829 for (var i = 0; i < outputLengthLanes; i++) { 11830 // Shortcuts 11831 var lane = state[i]; 11832 var laneMsw = lane.high; 11833 var laneLsw = lane.low; 11834 11835 // Swap endian 11836 laneMsw = ( 11837 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 11838 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 11839 ); 11840 laneLsw = ( 11841 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 11842 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 11843 ); 11844 11845 // Squeeze state to retrieve hash 11846 hashWords.push(laneLsw); 11847 hashWords.push(laneMsw); 11848 } 11849 11850 // Return final computed hash 11851 return new WordArray.init(hashWords, outputLengthBytes); 11852 }, 11853 11854 clone: function () { 11855 var clone = Hasher.clone.call(this); 11856 11857 var state = clone._state = this._state.slice(0); 11858 for (var i = 0; i < 25; i++) { 11859 state[i] = state[i].clone(); 11860 } 11861 11862 return clone; 11863 } 11864 }); 11865 11866 /** 11867 * Shortcut function to the hasher's object interface. 11868 * 11869 * @param {WordArray|string} message The message to hash. 11870 * 11871 * @return {WordArray} The hash. 11872 * 11873 * @static 11874 * 11875 * @example 11876 * 11877 * var hash = CryptoJS.SHA3('message'); 11878 * var hash = CryptoJS.SHA3(wordArray); 11879 */ 11880 C.SHA3 = Hasher._createHelper(SHA3); 11881 11882 /** 11883 * Shortcut function to the HMAC's object interface. 11884 * 11885 * @param {WordArray|string} message The message to hash. 11886 * @param {WordArray|string} key The secret key. 11887 * 11888 * @return {WordArray} The HMAC. 11889 * 11890 * @static 11891 * 11892 * @example 11893 * 11894 * var hmac = CryptoJS.HmacSHA3(message, key); 11895 */ 11896 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 11897 }(Math)); 11898 11899 11900 return CryptoJS.SHA3; 11901 11902 })); 11903 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 11904 ;(function (root, factory, undef) { 11905 if (typeof exports === "object") { 11906 // CommonJS 11907 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 11908 } 11909 else if (typeof define === "function" && define.amd) { 11910 // AMD 11911 define(["./core", "./x64-core", "./sha512"], factory); 11912 } 11913 else { 11914 // Global (browser) 11915 factory(root.CryptoJS); 11916 } 11917 }(this, function (CryptoJS) { 11918 11919 (function () { 11920 // Shortcuts 11921 var C = CryptoJS; 11922 var C_x64 = C.x64; 11923 var X64Word = C_x64.Word; 11924 var X64WordArray = C_x64.WordArray; 11925 var C_algo = C.algo; 11926 var SHA512 = C_algo.SHA512; 11927 11928 /** 11929 * SHA-384 hash algorithm. 11930 */ 11931 var SHA384 = C_algo.SHA384 = SHA512.extend({ 11932 _doReset: function () { 11933 this._hash = new X64WordArray.init([ 11934 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 11935 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 11936 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 11937 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 11938 ]); 11939 }, 11940 11941 _doFinalize: function () { 11942 var hash = SHA512._doFinalize.call(this); 11943 11944 hash.sigBytes -= 16; 11945 11946 return hash; 11947 } 11948 }); 11949 11950 /** 11951 * Shortcut function to the hasher's object interface. 11952 * 11953 * @param {WordArray|string} message The message to hash. 11954 * 11955 * @return {WordArray} The hash. 11956 * 11957 * @static 11958 * 11959 * @example 11960 * 11961 * var hash = CryptoJS.SHA384('message'); 11962 * var hash = CryptoJS.SHA384(wordArray); 11963 */ 11964 C.SHA384 = SHA512._createHelper(SHA384); 11965 11966 /** 11967 * Shortcut function to the HMAC's object interface. 11968 * 11969 * @param {WordArray|string} message The message to hash. 11970 * @param {WordArray|string} key The secret key. 11971 * 11972 * @return {WordArray} The HMAC. 11973 * 11974 * @static 11975 * 11976 * @example 11977 * 11978 * var hmac = CryptoJS.HmacSHA384(message, key); 11979 */ 11980 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 11981 }()); 11982 11983 11984 return CryptoJS.SHA384; 11985 11986 })); 11987 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 11988 ;(function (root, factory, undef) { 11989 if (typeof exports === "object") { 11990 // CommonJS 11991 module.exports = exports = factory(require("./core"), require("./x64-core")); 11992 } 11993 else if (typeof define === "function" && define.amd) { 11994 // AMD 11995 define(["./core", "./x64-core"], factory); 11996 } 11997 else { 11998 // Global (browser) 11999 factory(root.CryptoJS); 12000 } 12001 }(this, function (CryptoJS) { 12002 12003 (function () { 12004 // Shortcuts 12005 var C = CryptoJS; 12006 var C_lib = C.lib; 12007 var Hasher = C_lib.Hasher; 12008 var C_x64 = C.x64; 12009 var X64Word = C_x64.Word; 12010 var X64WordArray = C_x64.WordArray; 12011 var C_algo = C.algo; 12012 12013 function X64Word_create() { 12014 return X64Word.create.apply(X64Word, arguments); 12015 } 12016 12017 // Constants 12018 var K = [ 12019 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12020 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12021 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12022 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12023 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12024 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12025 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12026 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12027 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12028 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12029 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12030 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12031 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12032 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12033 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12034 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12035 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12036 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12037 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12038 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12039 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12040 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12041 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12042 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12043 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12044 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12045 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12046 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12047 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12048 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12049 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12050 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12051 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12052 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12053 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12054 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12055 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12056 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12057 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12058 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12059 ]; 12060 12061 // Reusable objects 12062 var W = []; 12063 (function () { 12064 for (var i = 0; i < 80; i++) { 12065 W[i] = X64Word_create(); 12066 } 12067 }()); 12068 12069 /** 12070 * SHA-512 hash algorithm. 12071 */ 12072 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12073 _doReset: function () { 12074 this._hash = new X64WordArray.init([ 12075 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12076 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12077 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12078 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12079 ]); 12080 }, 12081 12082 _doProcessBlock: function (M, offset) { 12083 // Shortcuts 12084 var H = this._hash.words; 12085 12086 var H0 = H[0]; 12087 var H1 = H[1]; 12088 var H2 = H[2]; 12089 var H3 = H[3]; 12090 var H4 = H[4]; 12091 var H5 = H[5]; 12092 var H6 = H[6]; 12093 var H7 = H[7]; 12094 12095 var H0h = H0.high; 12096 var H0l = H0.low; 12097 var H1h = H1.high; 12098 var H1l = H1.low; 12099 var H2h = H2.high; 12100 var H2l = H2.low; 12101 var H3h = H3.high; 12102 var H3l = H3.low; 12103 var H4h = H4.high; 12104 var H4l = H4.low; 12105 var H5h = H5.high; 12106 var H5l = H5.low; 12107 var H6h = H6.high; 12108 var H6l = H6.low; 12109 var H7h = H7.high; 12110 var H7l = H7.low; 12111 12112 // Working variables 12113 var ah = H0h; 12114 var al = H0l; 12115 var bh = H1h; 12116 var bl = H1l; 12117 var ch = H2h; 12118 var cl = H2l; 12119 var dh = H3h; 12120 var dl = H3l; 12121 var eh = H4h; 12122 var el = H4l; 12123 var fh = H5h; 12124 var fl = H5l; 12125 var gh = H6h; 12126 var gl = H6l; 12127 var hh = H7h; 12128 var hl = H7l; 12129 12130 // Rounds 12131 for (var i = 0; i < 80; i++) { 12132 // Shortcut 12133 var Wi = W[i]; 12134 12135 // Extend message 12136 if (i < 16) { 12137 var Wih = Wi.high = M[offset + i * 2] | 0; 12138 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12139 } else { 12140 // Gamma0 12141 var gamma0x = W[i - 15]; 12142 var gamma0xh = gamma0x.high; 12143 var gamma0xl = gamma0x.low; 12144 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12145 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12146 12147 // Gamma1 12148 var gamma1x = W[i - 2]; 12149 var gamma1xh = gamma1x.high; 12150 var gamma1xl = gamma1x.low; 12151 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12152 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12153 12154 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12155 var Wi7 = W[i - 7]; 12156 var Wi7h = Wi7.high; 12157 var Wi7l = Wi7.low; 12158 12159 var Wi16 = W[i - 16]; 12160 var Wi16h = Wi16.high; 12161 var Wi16l = Wi16.low; 12162 12163 var Wil = gamma0l + Wi7l; 12164 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12165 var Wil = Wil + gamma1l; 12166 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12167 var Wil = Wil + Wi16l; 12168 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12169 12170 Wi.high = Wih; 12171 Wi.low = Wil; 12172 } 12173 12174 var chh = (eh & fh) ^ (~eh & gh); 12175 var chl = (el & fl) ^ (~el & gl); 12176 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12177 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12178 12179 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12180 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12181 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12182 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12183 12184 // t1 = h + sigma1 + ch + K[i] + W[i] 12185 var Ki = K[i]; 12186 var Kih = Ki.high; 12187 var Kil = Ki.low; 12188 12189 var t1l = hl + sigma1l; 12190 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12191 var t1l = t1l + chl; 12192 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12193 var t1l = t1l + Kil; 12194 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12195 var t1l = t1l + Wil; 12196 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12197 12198 // t2 = sigma0 + maj 12199 var t2l = sigma0l + majl; 12200 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12201 12202 // Update working variables 12203 hh = gh; 12204 hl = gl; 12205 gh = fh; 12206 gl = fl; 12207 fh = eh; 12208 fl = el; 12209 el = (dl + t1l) | 0; 12210 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12211 dh = ch; 12212 dl = cl; 12213 ch = bh; 12214 cl = bl; 12215 bh = ah; 12216 bl = al; 12217 al = (t1l + t2l) | 0; 12218 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12219 } 12220 12221 // Intermediate hash value 12222 H0l = H0.low = (H0l + al); 12223 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12224 H1l = H1.low = (H1l + bl); 12225 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12226 H2l = H2.low = (H2l + cl); 12227 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12228 H3l = H3.low = (H3l + dl); 12229 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12230 H4l = H4.low = (H4l + el); 12231 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12232 H5l = H5.low = (H5l + fl); 12233 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12234 H6l = H6.low = (H6l + gl); 12235 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12236 H7l = H7.low = (H7l + hl); 12237 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12238 }, 12239 12240 _doFinalize: function () { 12241 // Shortcuts 12242 var data = this._data; 12243 var dataWords = data.words; 12244 12245 var nBitsTotal = this._nDataBytes * 8; 12246 var nBitsLeft = data.sigBytes * 8; 12247 12248 // Add padding 12249 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12250 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12251 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12252 data.sigBytes = dataWords.length * 4; 12253 12254 // Hash final blocks 12255 this._process(); 12256 12257 // Convert hash to 32-bit word array before returning 12258 var hash = this._hash.toX32(); 12259 12260 // Return final computed hash 12261 return hash; 12262 }, 12263 12264 clone: function () { 12265 var clone = Hasher.clone.call(this); 12266 clone._hash = this._hash.clone(); 12267 12268 return clone; 12269 }, 12270 12271 blockSize: 1024/32 12272 }); 12273 12274 /** 12275 * Shortcut function to the hasher's object interface. 12276 * 12277 * @param {WordArray|string} message The message to hash. 12278 * 12279 * @return {WordArray} The hash. 12280 * 12281 * @static 12282 * 12283 * @example 12284 * 12285 * var hash = CryptoJS.SHA512('message'); 12286 * var hash = CryptoJS.SHA512(wordArray); 12287 */ 12288 C.SHA512 = Hasher._createHelper(SHA512); 12289 12290 /** 12291 * Shortcut function to the HMAC's object interface. 12292 * 12293 * @param {WordArray|string} message The message to hash. 12294 * @param {WordArray|string} key The secret key. 12295 * 12296 * @return {WordArray} The HMAC. 12297 * 12298 * @static 12299 * 12300 * @example 12301 * 12302 * var hmac = CryptoJS.HmacSHA512(message, key); 12303 */ 12304 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12305 }()); 12306 12307 12308 return CryptoJS.SHA512; 12309 12310 })); 12311 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 12312 ;(function (root, factory, undef) { 12313 if (typeof exports === "object") { 12314 // CommonJS 12315 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12316 } 12317 else if (typeof define === "function" && define.amd) { 12318 // AMD 12319 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12320 } 12321 else { 12322 // Global (browser) 12323 factory(root.CryptoJS); 12324 } 12325 }(this, function (CryptoJS) { 12326 12327 (function () { 12328 // Shortcuts 12329 var C = CryptoJS; 12330 var C_lib = C.lib; 12331 var WordArray = C_lib.WordArray; 12332 var BlockCipher = C_lib.BlockCipher; 12333 var C_algo = C.algo; 12334 12335 // Permuted Choice 1 constants 12336 var PC1 = [ 12337 57, 49, 41, 33, 25, 17, 9, 1, 12338 58, 50, 42, 34, 26, 18, 10, 2, 12339 59, 51, 43, 35, 27, 19, 11, 3, 12340 60, 52, 44, 36, 63, 55, 47, 39, 12341 31, 23, 15, 7, 62, 54, 46, 38, 12342 30, 22, 14, 6, 61, 53, 45, 37, 12343 29, 21, 13, 5, 28, 20, 12, 4 12344 ]; 12345 12346 // Permuted Choice 2 constants 12347 var PC2 = [ 12348 14, 17, 11, 24, 1, 5, 12349 3, 28, 15, 6, 21, 10, 12350 23, 19, 12, 4, 26, 8, 12351 16, 7, 27, 20, 13, 2, 12352 41, 52, 31, 37, 47, 55, 12353 30, 40, 51, 45, 33, 48, 12354 44, 49, 39, 56, 34, 53, 12355 46, 42, 50, 36, 29, 32 12356 ]; 12357 12358 // Cumulative bit shift constants 12359 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12360 12361 // SBOXes and round permutation constants 12362 var SBOX_P = [ 12363 { 12364 0x0: 0x808200, 12365 0x10000000: 0x8000, 12366 0x20000000: 0x808002, 12367 0x30000000: 0x2, 12368 0x40000000: 0x200, 12369 0x50000000: 0x808202, 12370 0x60000000: 0x800202, 12371 0x70000000: 0x800000, 12372 0x80000000: 0x202, 12373 0x90000000: 0x800200, 12374 0xa0000000: 0x8200, 12375 0xb0000000: 0x808000, 12376 0xc0000000: 0x8002, 12377 0xd0000000: 0x800002, 12378 0xe0000000: 0x0, 12379 0xf0000000: 0x8202, 12380 0x8000000: 0x0, 12381 0x18000000: 0x808202, 12382 0x28000000: 0x8202, 12383 0x38000000: 0x8000, 12384 0x48000000: 0x808200, 12385 0x58000000: 0x200, 12386 0x68000000: 0x808002, 12387 0x78000000: 0x2, 12388 0x88000000: 0x800200, 12389 0x98000000: 0x8200, 12390 0xa8000000: 0x808000, 12391 0xb8000000: 0x800202, 12392 0xc8000000: 0x800002, 12393 0xd8000000: 0x8002, 12394 0xe8000000: 0x202, 12395 0xf8000000: 0x800000, 12396 0x1: 0x8000, 12397 0x10000001: 0x2, 12398 0x20000001: 0x808200, 12399 0x30000001: 0x800000, 12400 0x40000001: 0x808002, 12401 0x50000001: 0x8200, 12402 0x60000001: 0x200, 12403 0x70000001: 0x800202, 12404 0x80000001: 0x808202, 12405 0x90000001: 0x808000, 12406 0xa0000001: 0x800002, 12407 0xb0000001: 0x8202, 12408 0xc0000001: 0x202, 12409 0xd0000001: 0x800200, 12410 0xe0000001: 0x8002, 12411 0xf0000001: 0x0, 12412 0x8000001: 0x808202, 12413 0x18000001: 0x808000, 12414 0x28000001: 0x800000, 12415 0x38000001: 0x200, 12416 0x48000001: 0x8000, 12417 0x58000001: 0x800002, 12418 0x68000001: 0x2, 12419 0x78000001: 0x8202, 12420 0x88000001: 0x8002, 12421 0x98000001: 0x800202, 12422 0xa8000001: 0x202, 12423 0xb8000001: 0x808200, 12424 0xc8000001: 0x800200, 12425 0xd8000001: 0x0, 12426 0xe8000001: 0x8200, 12427 0xf8000001: 0x808002 12428 }, 12429 { 12430 0x0: 0x40084010, 12431 0x1000000: 0x4000, 12432 0x2000000: 0x80000, 12433 0x3000000: 0x40080010, 12434 0x4000000: 0x40000010, 12435 0x5000000: 0x40084000, 12436 0x6000000: 0x40004000, 12437 0x7000000: 0x10, 12438 0x8000000: 0x84000, 12439 0x9000000: 0x40004010, 12440 0xa000000: 0x40000000, 12441 0xb000000: 0x84010, 12442 0xc000000: 0x80010, 12443 0xd000000: 0x0, 12444 0xe000000: 0x4010, 12445 0xf000000: 0x40080000, 12446 0x800000: 0x40004000, 12447 0x1800000: 0x84010, 12448 0x2800000: 0x10, 12449 0x3800000: 0x40004010, 12450 0x4800000: 0x40084010, 12451 0x5800000: 0x40000000, 12452 0x6800000: 0x80000, 12453 0x7800000: 0x40080010, 12454 0x8800000: 0x80010, 12455 0x9800000: 0x0, 12456 0xa800000: 0x4000, 12457 0xb800000: 0x40080000, 12458 0xc800000: 0x40000010, 12459 0xd800000: 0x84000, 12460 0xe800000: 0x40084000, 12461 0xf800000: 0x4010, 12462 0x10000000: 0x0, 12463 0x11000000: 0x40080010, 12464 0x12000000: 0x40004010, 12465 0x13000000: 0x40084000, 12466 0x14000000: 0x40080000, 12467 0x15000000: 0x10, 12468 0x16000000: 0x84010, 12469 0x17000000: 0x4000, 12470 0x18000000: 0x4010, 12471 0x19000000: 0x80000, 12472 0x1a000000: 0x80010, 12473 0x1b000000: 0x40000010, 12474 0x1c000000: 0x84000, 12475 0x1d000000: 0x40004000, 12476 0x1e000000: 0x40000000, 12477 0x1f000000: 0x40084010, 12478 0x10800000: 0x84010, 12479 0x11800000: 0x80000, 12480 0x12800000: 0x40080000, 12481 0x13800000: 0x4000, 12482 0x14800000: 0x40004000, 12483 0x15800000: 0x40084010, 12484 0x16800000: 0x10, 12485 0x17800000: 0x40000000, 12486 0x18800000: 0x40084000, 12487 0x19800000: 0x40000010, 12488 0x1a800000: 0x40004010, 12489 0x1b800000: 0x80010, 12490 0x1c800000: 0x0, 12491 0x1d800000: 0x4010, 12492 0x1e800000: 0x40080010, 12493 0x1f800000: 0x84000 12494 }, 12495 { 12496 0x0: 0x104, 12497 0x100000: 0x0, 12498 0x200000: 0x4000100, 12499 0x300000: 0x10104, 12500 0x400000: 0x10004, 12501 0x500000: 0x4000004, 12502 0x600000: 0x4010104, 12503 0x700000: 0x4010000, 12504 0x800000: 0x4000000, 12505 0x900000: 0x4010100, 12506 0xa00000: 0x10100, 12507 0xb00000: 0x4010004, 12508 0xc00000: 0x4000104, 12509 0xd00000: 0x10000, 12510 0xe00000: 0x4, 12511 0xf00000: 0x100, 12512 0x80000: 0x4010100, 12513 0x180000: 0x4010004, 12514 0x280000: 0x0, 12515 0x380000: 0x4000100, 12516 0x480000: 0x4000004, 12517 0x580000: 0x10000, 12518 0x680000: 0x10004, 12519 0x780000: 0x104, 12520 0x880000: 0x4, 12521 0x980000: 0x100, 12522 0xa80000: 0x4010000, 12523 0xb80000: 0x10104, 12524 0xc80000: 0x10100, 12525 0xd80000: 0x4000104, 12526 0xe80000: 0x4010104, 12527 0xf80000: 0x4000000, 12528 0x1000000: 0x4010100, 12529 0x1100000: 0x10004, 12530 0x1200000: 0x10000, 12531 0x1300000: 0x4000100, 12532 0x1400000: 0x100, 12533 0x1500000: 0x4010104, 12534 0x1600000: 0x4000004, 12535 0x1700000: 0x0, 12536 0x1800000: 0x4000104, 12537 0x1900000: 0x4000000, 12538 0x1a00000: 0x4, 12539 0x1b00000: 0x10100, 12540 0x1c00000: 0x4010000, 12541 0x1d00000: 0x104, 12542 0x1e00000: 0x10104, 12543 0x1f00000: 0x4010004, 12544 0x1080000: 0x4000000, 12545 0x1180000: 0x104, 12546 0x1280000: 0x4010100, 12547 0x1380000: 0x0, 12548 0x1480000: 0x10004, 12549 0x1580000: 0x4000100, 12550 0x1680000: 0x100, 12551 0x1780000: 0x4010004, 12552 0x1880000: 0x10000, 12553 0x1980000: 0x4010104, 12554 0x1a80000: 0x10104, 12555 0x1b80000: 0x4000004, 12556 0x1c80000: 0x4000104, 12557 0x1d80000: 0x4010000, 12558 0x1e80000: 0x4, 12559 0x1f80000: 0x10100 12560 }, 12561 { 12562 0x0: 0x80401000, 12563 0x10000: 0x80001040, 12564 0x20000: 0x401040, 12565 0x30000: 0x80400000, 12566 0x40000: 0x0, 12567 0x50000: 0x401000, 12568 0x60000: 0x80000040, 12569 0x70000: 0x400040, 12570 0x80000: 0x80000000, 12571 0x90000: 0x400000, 12572 0xa0000: 0x40, 12573 0xb0000: 0x80001000, 12574 0xc0000: 0x80400040, 12575 0xd0000: 0x1040, 12576 0xe0000: 0x1000, 12577 0xf0000: 0x80401040, 12578 0x8000: 0x80001040, 12579 0x18000: 0x40, 12580 0x28000: 0x80400040, 12581 0x38000: 0x80001000, 12582 0x48000: 0x401000, 12583 0x58000: 0x80401040, 12584 0x68000: 0x0, 12585 0x78000: 0x80400000, 12586 0x88000: 0x1000, 12587 0x98000: 0x80401000, 12588 0xa8000: 0x400000, 12589 0xb8000: 0x1040, 12590 0xc8000: 0x80000000, 12591 0xd8000: 0x400040, 12592 0xe8000: 0x401040, 12593 0xf8000: 0x80000040, 12594 0x100000: 0x400040, 12595 0x110000: 0x401000, 12596 0x120000: 0x80000040, 12597 0x130000: 0x0, 12598 0x140000: 0x1040, 12599 0x150000: 0x80400040, 12600 0x160000: 0x80401000, 12601 0x170000: 0x80001040, 12602 0x180000: 0x80401040, 12603 0x190000: 0x80000000, 12604 0x1a0000: 0x80400000, 12605 0x1b0000: 0x401040, 12606 0x1c0000: 0x80001000, 12607 0x1d0000: 0x400000, 12608 0x1e0000: 0x40, 12609 0x1f0000: 0x1000, 12610 0x108000: 0x80400000, 12611 0x118000: 0x80401040, 12612 0x128000: 0x0, 12613 0x138000: 0x401000, 12614 0x148000: 0x400040, 12615 0x158000: 0x80000000, 12616 0x168000: 0x80001040, 12617 0x178000: 0x40, 12618 0x188000: 0x80000040, 12619 0x198000: 0x1000, 12620 0x1a8000: 0x80001000, 12621 0x1b8000: 0x80400040, 12622 0x1c8000: 0x1040, 12623 0x1d8000: 0x80401000, 12624 0x1e8000: 0x400000, 12625 0x1f8000: 0x401040 12626 }, 12627 { 12628 0x0: 0x80, 12629 0x1000: 0x1040000, 12630 0x2000: 0x40000, 12631 0x3000: 0x20000000, 12632 0x4000: 0x20040080, 12633 0x5000: 0x1000080, 12634 0x6000: 0x21000080, 12635 0x7000: 0x40080, 12636 0x8000: 0x1000000, 12637 0x9000: 0x20040000, 12638 0xa000: 0x20000080, 12639 0xb000: 0x21040080, 12640 0xc000: 0x21040000, 12641 0xd000: 0x0, 12642 0xe000: 0x1040080, 12643 0xf000: 0x21000000, 12644 0x800: 0x1040080, 12645 0x1800: 0x21000080, 12646 0x2800: 0x80, 12647 0x3800: 0x1040000, 12648 0x4800: 0x40000, 12649 0x5800: 0x20040080, 12650 0x6800: 0x21040000, 12651 0x7800: 0x20000000, 12652 0x8800: 0x20040000, 12653 0x9800: 0x0, 12654 0xa800: 0x21040080, 12655 0xb800: 0x1000080, 12656 0xc800: 0x20000080, 12657 0xd800: 0x21000000, 12658 0xe800: 0x1000000, 12659 0xf800: 0x40080, 12660 0x10000: 0x40000, 12661 0x11000: 0x80, 12662 0x12000: 0x20000000, 12663 0x13000: 0x21000080, 12664 0x14000: 0x1000080, 12665 0x15000: 0x21040000, 12666 0x16000: 0x20040080, 12667 0x17000: 0x1000000, 12668 0x18000: 0x21040080, 12669 0x19000: 0x21000000, 12670 0x1a000: 0x1040000, 12671 0x1b000: 0x20040000, 12672 0x1c000: 0x40080, 12673 0x1d000: 0x20000080, 12674 0x1e000: 0x0, 12675 0x1f000: 0x1040080, 12676 0x10800: 0x21000080, 12677 0x11800: 0x1000000, 12678 0x12800: 0x1040000, 12679 0x13800: 0x20040080, 12680 0x14800: 0x20000000, 12681 0x15800: 0x1040080, 12682 0x16800: 0x80, 12683 0x17800: 0x21040000, 12684 0x18800: 0x40080, 12685 0x19800: 0x21040080, 12686 0x1a800: 0x0, 12687 0x1b800: 0x21000000, 12688 0x1c800: 0x1000080, 12689 0x1d800: 0x40000, 12690 0x1e800: 0x20040000, 12691 0x1f800: 0x20000080 12692 }, 12693 { 12694 0x0: 0x10000008, 12695 0x100: 0x2000, 12696 0x200: 0x10200000, 12697 0x300: 0x10202008, 12698 0x400: 0x10002000, 12699 0x500: 0x200000, 12700 0x600: 0x200008, 12701 0x700: 0x10000000, 12702 0x800: 0x0, 12703 0x900: 0x10002008, 12704 0xa00: 0x202000, 12705 0xb00: 0x8, 12706 0xc00: 0x10200008, 12707 0xd00: 0x202008, 12708 0xe00: 0x2008, 12709 0xf00: 0x10202000, 12710 0x80: 0x10200000, 12711 0x180: 0x10202008, 12712 0x280: 0x8, 12713 0x380: 0x200000, 12714 0x480: 0x202008, 12715 0x580: 0x10000008, 12716 0x680: 0x10002000, 12717 0x780: 0x2008, 12718 0x880: 0x200008, 12719 0x980: 0x2000, 12720 0xa80: 0x10002008, 12721 0xb80: 0x10200008, 12722 0xc80: 0x0, 12723 0xd80: 0x10202000, 12724 0xe80: 0x202000, 12725 0xf80: 0x10000000, 12726 0x1000: 0x10002000, 12727 0x1100: 0x10200008, 12728 0x1200: 0x10202008, 12729 0x1300: 0x2008, 12730 0x1400: 0x200000, 12731 0x1500: 0x10000000, 12732 0x1600: 0x10000008, 12733 0x1700: 0x202000, 12734 0x1800: 0x202008, 12735 0x1900: 0x0, 12736 0x1a00: 0x8, 12737 0x1b00: 0x10200000, 12738 0x1c00: 0x2000, 12739 0x1d00: 0x10002008, 12740 0x1e00: 0x10202000, 12741 0x1f00: 0x200008, 12742 0x1080: 0x8, 12743 0x1180: 0x202000, 12744 0x1280: 0x200000, 12745 0x1380: 0x10000008, 12746 0x1480: 0x10002000, 12747 0x1580: 0x2008, 12748 0x1680: 0x10202008, 12749 0x1780: 0x10200000, 12750 0x1880: 0x10202000, 12751 0x1980: 0x10200008, 12752 0x1a80: 0x2000, 12753 0x1b80: 0x202008, 12754 0x1c80: 0x200008, 12755 0x1d80: 0x0, 12756 0x1e80: 0x10000000, 12757 0x1f80: 0x10002008 12758 }, 12759 { 12760 0x0: 0x100000, 12761 0x10: 0x2000401, 12762 0x20: 0x400, 12763 0x30: 0x100401, 12764 0x40: 0x2100401, 12765 0x50: 0x0, 12766 0x60: 0x1, 12767 0x70: 0x2100001, 12768 0x80: 0x2000400, 12769 0x90: 0x100001, 12770 0xa0: 0x2000001, 12771 0xb0: 0x2100400, 12772 0xc0: 0x2100000, 12773 0xd0: 0x401, 12774 0xe0: 0x100400, 12775 0xf0: 0x2000000, 12776 0x8: 0x2100001, 12777 0x18: 0x0, 12778 0x28: 0x2000401, 12779 0x38: 0x2100400, 12780 0x48: 0x100000, 12781 0x58: 0x2000001, 12782 0x68: 0x2000000, 12783 0x78: 0x401, 12784 0x88: 0x100401, 12785 0x98: 0x2000400, 12786 0xa8: 0x2100000, 12787 0xb8: 0x100001, 12788 0xc8: 0x400, 12789 0xd8: 0x2100401, 12790 0xe8: 0x1, 12791 0xf8: 0x100400, 12792 0x100: 0x2000000, 12793 0x110: 0x100000, 12794 0x120: 0x2000401, 12795 0x130: 0x2100001, 12796 0x140: 0x100001, 12797 0x150: 0x2000400, 12798 0x160: 0x2100400, 12799 0x170: 0x100401, 12800 0x180: 0x401, 12801 0x190: 0x2100401, 12802 0x1a0: 0x100400, 12803 0x1b0: 0x1, 12804 0x1c0: 0x0, 12805 0x1d0: 0x2100000, 12806 0x1e0: 0x2000001, 12807 0x1f0: 0x400, 12808 0x108: 0x100400, 12809 0x118: 0x2000401, 12810 0x128: 0x2100001, 12811 0x138: 0x1, 12812 0x148: 0x2000000, 12813 0x158: 0x100000, 12814 0x168: 0x401, 12815 0x178: 0x2100400, 12816 0x188: 0x2000001, 12817 0x198: 0x2100000, 12818 0x1a8: 0x0, 12819 0x1b8: 0x2100401, 12820 0x1c8: 0x100401, 12821 0x1d8: 0x400, 12822 0x1e8: 0x2000400, 12823 0x1f8: 0x100001 12824 }, 12825 { 12826 0x0: 0x8000820, 12827 0x1: 0x20000, 12828 0x2: 0x8000000, 12829 0x3: 0x20, 12830 0x4: 0x20020, 12831 0x5: 0x8020820, 12832 0x6: 0x8020800, 12833 0x7: 0x800, 12834 0x8: 0x8020000, 12835 0x9: 0x8000800, 12836 0xa: 0x20800, 12837 0xb: 0x8020020, 12838 0xc: 0x820, 12839 0xd: 0x0, 12840 0xe: 0x8000020, 12841 0xf: 0x20820, 12842 0x80000000: 0x800, 12843 0x80000001: 0x8020820, 12844 0x80000002: 0x8000820, 12845 0x80000003: 0x8000000, 12846 0x80000004: 0x8020000, 12847 0x80000005: 0x20800, 12848 0x80000006: 0x20820, 12849 0x80000007: 0x20, 12850 0x80000008: 0x8000020, 12851 0x80000009: 0x820, 12852 0x8000000a: 0x20020, 12853 0x8000000b: 0x8020800, 12854 0x8000000c: 0x0, 12855 0x8000000d: 0x8020020, 12856 0x8000000e: 0x8000800, 12857 0x8000000f: 0x20000, 12858 0x10: 0x20820, 12859 0x11: 0x8020800, 12860 0x12: 0x20, 12861 0x13: 0x800, 12862 0x14: 0x8000800, 12863 0x15: 0x8000020, 12864 0x16: 0x8020020, 12865 0x17: 0x20000, 12866 0x18: 0x0, 12867 0x19: 0x20020, 12868 0x1a: 0x8020000, 12869 0x1b: 0x8000820, 12870 0x1c: 0x8020820, 12871 0x1d: 0x20800, 12872 0x1e: 0x820, 12873 0x1f: 0x8000000, 12874 0x80000010: 0x20000, 12875 0x80000011: 0x800, 12876 0x80000012: 0x8020020, 12877 0x80000013: 0x20820, 12878 0x80000014: 0x20, 12879 0x80000015: 0x8020000, 12880 0x80000016: 0x8000000, 12881 0x80000017: 0x8000820, 12882 0x80000018: 0x8020820, 12883 0x80000019: 0x8000020, 12884 0x8000001a: 0x8000800, 12885 0x8000001b: 0x0, 12886 0x8000001c: 0x20800, 12887 0x8000001d: 0x820, 12888 0x8000001e: 0x20020, 12889 0x8000001f: 0x8020800 12890 } 12891 ]; 12892 12893 // Masks that select the SBOX input 12894 var SBOX_MASK = [ 12895 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 12896 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 12897 ]; 12898 12899 /** 12900 * DES block cipher algorithm. 12901 */ 12902 var DES = C_algo.DES = BlockCipher.extend({ 12903 _doReset: function () { 12904 // Shortcuts 12905 var key = this._key; 12906 var keyWords = key.words; 12907 12908 // Select 56 bits according to PC1 12909 var keyBits = []; 12910 for (var i = 0; i < 56; i++) { 12911 var keyBitPos = PC1[i] - 1; 12912 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 12913 } 12914 12915 // Assemble 16 subkeys 12916 var subKeys = this._subKeys = []; 12917 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 12918 // Create subkey 12919 var subKey = subKeys[nSubKey] = []; 12920 12921 // Shortcut 12922 var bitShift = BIT_SHIFTS[nSubKey]; 12923 12924 // Select 48 bits according to PC2 12925 for (var i = 0; i < 24; i++) { 12926 // Select from the left 28 key bits 12927 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 12928 12929 // Select from the right 28 key bits 12930 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 12931 } 12932 12933 // Since each subkey is applied to an expanded 32-bit input, 12934 // the subkey can be broken into 8 values scaled to 32-bits, 12935 // which allows the key to be used without expansion 12936 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 12937 for (var i = 1; i < 7; i++) { 12938 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 12939 } 12940 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 12941 } 12942 12943 // Compute inverse subkeys 12944 var invSubKeys = this._invSubKeys = []; 12945 for (var i = 0; i < 16; i++) { 12946 invSubKeys[i] = subKeys[15 - i]; 12947 } 12948 }, 12949 12950 encryptBlock: function (M, offset) { 12951 this._doCryptBlock(M, offset, this._subKeys); 12952 }, 12953 12954 decryptBlock: function (M, offset) { 12955 this._doCryptBlock(M, offset, this._invSubKeys); 12956 }, 12957 12958 _doCryptBlock: function (M, offset, subKeys) { 12959 // Get input 12960 this._lBlock = M[offset]; 12961 this._rBlock = M[offset + 1]; 12962 12963 // Initial permutation 12964 exchangeLR.call(this, 4, 0x0f0f0f0f); 12965 exchangeLR.call(this, 16, 0x0000ffff); 12966 exchangeRL.call(this, 2, 0x33333333); 12967 exchangeRL.call(this, 8, 0x00ff00ff); 12968 exchangeLR.call(this, 1, 0x55555555); 12969 12970 // Rounds 12971 for (var round = 0; round < 16; round++) { 12972 // Shortcuts 12973 var subKey = subKeys[round]; 12974 var lBlock = this._lBlock; 12975 var rBlock = this._rBlock; 12976 12977 // Feistel function 12978 var f = 0; 12979 for (var i = 0; i < 8; i++) { 12980 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 12981 } 12982 this._lBlock = rBlock; 12983 this._rBlock = lBlock ^ f; 12984 } 12985 12986 // Undo swap from last round 12987 var t = this._lBlock; 12988 this._lBlock = this._rBlock; 12989 this._rBlock = t; 12990 12991 // Final permutation 12992 exchangeLR.call(this, 1, 0x55555555); 12993 exchangeRL.call(this, 8, 0x00ff00ff); 12994 exchangeRL.call(this, 2, 0x33333333); 12995 exchangeLR.call(this, 16, 0x0000ffff); 12996 exchangeLR.call(this, 4, 0x0f0f0f0f); 12997 12998 // Set output 12999 M[offset] = this._lBlock; 13000 M[offset + 1] = this._rBlock; 13001 }, 13002 13003 keySize: 64/32, 13004 13005 ivSize: 64/32, 13006 13007 blockSize: 64/32 13008 }); 13009 13010 // Swap bits across the left and right words 13011 function exchangeLR(offset, mask) { 13012 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13013 this._rBlock ^= t; 13014 this._lBlock ^= t << offset; 13015 } 13016 13017 function exchangeRL(offset, mask) { 13018 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13019 this._lBlock ^= t; 13020 this._rBlock ^= t << offset; 13021 } 13022 13023 /** 13024 * Shortcut functions to the cipher's object interface. 13025 * 13026 * @example 13027 * 13028 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13029 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13030 */ 13031 C.DES = BlockCipher._createHelper(DES); 13032 13033 /** 13034 * Triple-DES block cipher algorithm. 13035 */ 13036 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13037 _doReset: function () { 13038 // Shortcuts 13039 var key = this._key; 13040 var keyWords = key.words; 13041 13042 // Create DES instances 13043 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13044 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13045 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13046 }, 13047 13048 encryptBlock: function (M, offset) { 13049 this._des1.encryptBlock(M, offset); 13050 this._des2.decryptBlock(M, offset); 13051 this._des3.encryptBlock(M, offset); 13052 }, 13053 13054 decryptBlock: function (M, offset) { 13055 this._des3.decryptBlock(M, offset); 13056 this._des2.encryptBlock(M, offset); 13057 this._des1.decryptBlock(M, offset); 13058 }, 13059 13060 keySize: 192/32, 13061 13062 ivSize: 64/32, 13063 13064 blockSize: 64/32 13065 }); 13066 13067 /** 13068 * Shortcut functions to the cipher's object interface. 13069 * 13070 * @example 13071 * 13072 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13073 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13074 */ 13075 C.TripleDES = BlockCipher._createHelper(TripleDES); 13076 }()); 13077 13078 13079 return CryptoJS.TripleDES; 13080 13081 })); 13082 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 13083 ;(function (root, factory) { 13084 if (typeof exports === "object") { 13085 // CommonJS 13086 module.exports = exports = factory(require("./core")); 13087 } 13088 else if (typeof define === "function" && define.amd) { 13089 // AMD 13090 define(["./core"], factory); 13091 } 13092 else { 13093 // Global (browser) 13094 factory(root.CryptoJS); 13095 } 13096 }(this, function (CryptoJS) { 13097 13098 (function (undefined) { 13099 // Shortcuts 13100 var C = CryptoJS; 13101 var C_lib = C.lib; 13102 var Base = C_lib.Base; 13103 var X32WordArray = C_lib.WordArray; 13104 13105 /** 13106 * x64 namespace. 13107 */ 13108 var C_x64 = C.x64 = {}; 13109 13110 /** 13111 * A 64-bit word. 13112 */ 13113 var X64Word = C_x64.Word = Base.extend({ 13114 /** 13115 * Initializes a newly created 64-bit word. 13116 * 13117 * @param {number} high The high 32 bits. 13118 * @param {number} low The low 32 bits. 13119 * 13120 * @example 13121 * 13122 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13123 */ 13124 init: function (high, low) { 13125 this.high = high; 13126 this.low = low; 13127 } 13128 13129 /** 13130 * Bitwise NOTs this word. 13131 * 13132 * @return {X64Word} A new x64-Word object after negating. 13133 * 13134 * @example 13135 * 13136 * var negated = x64Word.not(); 13137 */ 13138 // not: function () { 13139 // var high = ~this.high; 13140 // var low = ~this.low; 13141 13142 // return X64Word.create(high, low); 13143 // }, 13144 13145 /** 13146 * Bitwise ANDs this word with the passed word. 13147 * 13148 * @param {X64Word} word The x64-Word to AND with this word. 13149 * 13150 * @return {X64Word} A new x64-Word object after ANDing. 13151 * 13152 * @example 13153 * 13154 * var anded = x64Word.and(anotherX64Word); 13155 */ 13156 // and: function (word) { 13157 // var high = this.high & word.high; 13158 // var low = this.low & word.low; 13159 13160 // return X64Word.create(high, low); 13161 // }, 13162 13163 /** 13164 * Bitwise ORs this word with the passed word. 13165 * 13166 * @param {X64Word} word The x64-Word to OR with this word. 13167 * 13168 * @return {X64Word} A new x64-Word object after ORing. 13169 * 13170 * @example 13171 * 13172 * var ored = x64Word.or(anotherX64Word); 13173 */ 13174 // or: function (word) { 13175 // var high = this.high | word.high; 13176 // var low = this.low | word.low; 13177 13178 // return X64Word.create(high, low); 13179 // }, 13180 13181 /** 13182 * Bitwise XORs this word with the passed word. 13183 * 13184 * @param {X64Word} word The x64-Word to XOR with this word. 13185 * 13186 * @return {X64Word} A new x64-Word object after XORing. 13187 * 13188 * @example 13189 * 13190 * var xored = x64Word.xor(anotherX64Word); 13191 */ 13192 // xor: function (word) { 13193 // var high = this.high ^ word.high; 13194 // var low = this.low ^ word.low; 13195 13196 // return X64Word.create(high, low); 13197 // }, 13198 13199 /** 13200 * Shifts this word n bits to the left. 13201 * 13202 * @param {number} n The number of bits to shift. 13203 * 13204 * @return {X64Word} A new x64-Word object after shifting. 13205 * 13206 * @example 13207 * 13208 * var shifted = x64Word.shiftL(25); 13209 */ 13210 // shiftL: function (n) { 13211 // if (n < 32) { 13212 // var high = (this.high << n) | (this.low >>> (32 - n)); 13213 // var low = this.low << n; 13214 // } else { 13215 // var high = this.low << (n - 32); 13216 // var low = 0; 13217 // } 13218 13219 // return X64Word.create(high, low); 13220 // }, 13221 13222 /** 13223 * Shifts this word n bits to the right. 13224 * 13225 * @param {number} n The number of bits to shift. 13226 * 13227 * @return {X64Word} A new x64-Word object after shifting. 13228 * 13229 * @example 13230 * 13231 * var shifted = x64Word.shiftR(7); 13232 */ 13233 // shiftR: function (n) { 13234 // if (n < 32) { 13235 // var low = (this.low >>> n) | (this.high << (32 - n)); 13236 // var high = this.high >>> n; 13237 // } else { 13238 // var low = this.high >>> (n - 32); 13239 // var high = 0; 13240 // } 13241 13242 // return X64Word.create(high, low); 13243 // }, 13244 13245 /** 13246 * Rotates this word n bits to the left. 13247 * 13248 * @param {number} n The number of bits to rotate. 13249 * 13250 * @return {X64Word} A new x64-Word object after rotating. 13251 * 13252 * @example 13253 * 13254 * var rotated = x64Word.rotL(25); 13255 */ 13256 // rotL: function (n) { 13257 // return this.shiftL(n).or(this.shiftR(64 - n)); 13258 // }, 13259 13260 /** 13261 * Rotates this word n bits to the right. 13262 * 13263 * @param {number} n The number of bits to rotate. 13264 * 13265 * @return {X64Word} A new x64-Word object after rotating. 13266 * 13267 * @example 13268 * 13269 * var rotated = x64Word.rotR(7); 13270 */ 13271 // rotR: function (n) { 13272 // return this.shiftR(n).or(this.shiftL(64 - n)); 13273 // }, 13274 13275 /** 13276 * Adds this word with the passed word. 13277 * 13278 * @param {X64Word} word The x64-Word to add with this word. 13279 * 13280 * @return {X64Word} A new x64-Word object after adding. 13281 * 13282 * @example 13283 * 13284 * var added = x64Word.add(anotherX64Word); 13285 */ 13286 // add: function (word) { 13287 // var low = (this.low + word.low) | 0; 13288 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13289 // var high = (this.high + word.high + carry) | 0; 13290 13291 // return X64Word.create(high, low); 13292 // } 13293 }); 13294 13295 /** 13296 * An array of 64-bit words. 13297 * 13298 * @property {Array} words The array of CryptoJS.x64.Word objects. 13299 * @property {number} sigBytes The number of significant bytes in this word array. 13300 */ 13301 var X64WordArray = C_x64.WordArray = Base.extend({ 13302 /** 13303 * Initializes a newly created word array. 13304 * 13305 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13306 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13307 * 13308 * @example 13309 * 13310 * var wordArray = CryptoJS.x64.WordArray.create(); 13311 * 13312 * var wordArray = CryptoJS.x64.WordArray.create([ 13313 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13314 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13315 * ]); 13316 * 13317 * var wordArray = CryptoJS.x64.WordArray.create([ 13318 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13319 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13320 * ], 10); 13321 */ 13322 init: function (words, sigBytes) { 13323 words = this.words = words || []; 13324 13325 if (sigBytes != undefined) { 13326 this.sigBytes = sigBytes; 13327 } else { 13328 this.sigBytes = words.length * 8; 13329 } 13330 }, 13331 13332 /** 13333 * Converts this 64-bit word array to a 32-bit word array. 13334 * 13335 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13336 * 13337 * @example 13338 * 13339 * var x32WordArray = x64WordArray.toX32(); 13340 */ 13341 toX32: function () { 13342 // Shortcuts 13343 var x64Words = this.words; 13344 var x64WordsLength = x64Words.length; 13345 13346 // Convert 13347 var x32Words = []; 13348 for (var i = 0; i < x64WordsLength; i++) { 13349 var x64Word = x64Words[i]; 13350 x32Words.push(x64Word.high); 13351 x32Words.push(x64Word.low); 13352 } 13353 13354 return X32WordArray.create(x32Words, this.sigBytes); 13355 }, 13356 13357 /** 13358 * Creates a copy of this word array. 13359 * 13360 * @return {X64WordArray} The clone. 13361 * 13362 * @example 13363 * 13364 * var clone = x64WordArray.clone(); 13365 */ 13366 clone: function () { 13367 var clone = Base.clone.call(this); 13368 13369 // Clone "words" array 13370 var words = clone.words = this.words.slice(0); 13371 13372 // Clone each X64Word object 13373 var wordsLength = words.length; 13374 for (var i = 0; i < wordsLength; i++) { 13375 words[i] = words[i].clone(); 13376 } 13377 13378 return clone; 13379 } 13380 }); 13381 }()); 13382 13383 13384 return CryptoJS; 13385 13386 })); 13387 },{"./core":53}],85:[function(require,module,exports){ 13388 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13389 ;(function(root) { 13390 13391 // Detect free variables `exports` 13392 var freeExports = typeof exports == 'object' && exports; 13393 13394 // Detect free variable `module` 13395 var freeModule = typeof module == 'object' && module && 13396 module.exports == freeExports && module; 13397 13398 // Detect free variable `global`, from Node.js or Browserified code, 13399 // and use it as `root` 13400 var freeGlobal = typeof global == 'object' && global; 13401 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13402 root = freeGlobal; 13403 } 13404 13405 /*--------------------------------------------------------------------------*/ 13406 13407 var stringFromCharCode = String.fromCharCode; 13408 13409 // Taken from https://mths.be/punycode 13410 function ucs2decode(string) { 13411 var output = []; 13412 var counter = 0; 13413 var length = string.length; 13414 var value; 13415 var extra; 13416 while (counter < length) { 13417 value = string.charCodeAt(counter++); 13418 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13419 // high surrogate, and there is a next character 13420 extra = string.charCodeAt(counter++); 13421 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13422 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13423 } else { 13424 // unmatched surrogate; only append this code unit, in case the next 13425 // code unit is the high surrogate of a surrogate pair 13426 output.push(value); 13427 counter--; 13428 } 13429 } else { 13430 output.push(value); 13431 } 13432 } 13433 return output; 13434 } 13435 13436 // Taken from https://mths.be/punycode 13437 function ucs2encode(array) { 13438 var length = array.length; 13439 var index = -1; 13440 var value; 13441 var output = ''; 13442 while (++index < length) { 13443 value = array[index]; 13444 if (value > 0xFFFF) { 13445 value -= 0x10000; 13446 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13447 value = 0xDC00 | value & 0x3FF; 13448 } 13449 output += stringFromCharCode(value); 13450 } 13451 return output; 13452 } 13453 13454 function checkScalarValue(codePoint) { 13455 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13456 throw Error( 13457 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13458 ' is not a scalar value' 13459 ); 13460 } 13461 } 13462 /*--------------------------------------------------------------------------*/ 13463 13464 function createByte(codePoint, shift) { 13465 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13466 } 13467 13468 function encodeCodePoint(codePoint) { 13469 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13470 return stringFromCharCode(codePoint); 13471 } 13472 var symbol = ''; 13473 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13474 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13475 } 13476 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13477 checkScalarValue(codePoint); 13478 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13479 symbol += createByte(codePoint, 6); 13480 } 13481 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13482 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13483 symbol += createByte(codePoint, 12); 13484 symbol += createByte(codePoint, 6); 13485 } 13486 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13487 return symbol; 13488 } 13489 13490 function utf8encode(string) { 13491 var codePoints = ucs2decode(string); 13492 var length = codePoints.length; 13493 var index = -1; 13494 var codePoint; 13495 var byteString = ''; 13496 while (++index < length) { 13497 codePoint = codePoints[index]; 13498 byteString += encodeCodePoint(codePoint); 13499 } 13500 return byteString; 13501 } 13502 13503 /*--------------------------------------------------------------------------*/ 13504 13505 function readContinuationByte() { 13506 if (byteIndex >= byteCount) { 13507 throw Error('Invalid byte index'); 13508 } 13509 13510 var continuationByte = byteArray[byteIndex] & 0xFF; 13511 byteIndex++; 13512 13513 if ((continuationByte & 0xC0) == 0x80) { 13514 return continuationByte & 0x3F; 13515 } 13516 13517 // If we end up here, it’s not a continuation byte 13518 throw Error('Invalid continuation byte'); 13519 } 13520 13521 function decodeSymbol() { 13522 var byte1; 13523 var byte2; 13524 var byte3; 13525 var byte4; 13526 var codePoint; 13527 13528 if (byteIndex > byteCount) { 13529 throw Error('Invalid byte index'); 13530 } 13531 13532 if (byteIndex == byteCount) { 13533 return false; 13534 } 13535 13536 // Read first byte 13537 byte1 = byteArray[byteIndex] & 0xFF; 13538 byteIndex++; 13539 13540 // 1-byte sequence (no continuation bytes) 13541 if ((byte1 & 0x80) == 0) { 13542 return byte1; 13543 } 13544 13545 // 2-byte sequence 13546 if ((byte1 & 0xE0) == 0xC0) { 13547 byte2 = readContinuationByte(); 13548 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13549 if (codePoint >= 0x80) { 13550 return codePoint; 13551 } else { 13552 throw Error('Invalid continuation byte'); 13553 } 13554 } 13555 13556 // 3-byte sequence (may include unpaired surrogates) 13557 if ((byte1 & 0xF0) == 0xE0) { 13558 byte2 = readContinuationByte(); 13559 byte3 = readContinuationByte(); 13560 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13561 if (codePoint >= 0x0800) { 13562 checkScalarValue(codePoint); 13563 return codePoint; 13564 } else { 13565 throw Error('Invalid continuation byte'); 13566 } 13567 } 13568 13569 // 4-byte sequence 13570 if ((byte1 & 0xF8) == 0xF0) { 13571 byte2 = readContinuationByte(); 13572 byte3 = readContinuationByte(); 13573 byte4 = readContinuationByte(); 13574 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 13575 (byte3 << 0x06) | byte4; 13576 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 13577 return codePoint; 13578 } 13579 } 13580 13581 throw Error('Invalid UTF-8 detected'); 13582 } 13583 13584 var byteArray; 13585 var byteCount; 13586 var byteIndex; 13587 function utf8decode(byteString) { 13588 byteArray = ucs2decode(byteString); 13589 byteCount = byteArray.length; 13590 byteIndex = 0; 13591 var codePoints = []; 13592 var tmp; 13593 while ((tmp = decodeSymbol()) !== false) { 13594 codePoints.push(tmp); 13595 } 13596 return ucs2encode(codePoints); 13597 } 13598 13599 /*--------------------------------------------------------------------------*/ 13600 13601 var utf8 = { 13602 'version': '2.1.2', 13603 'encode': utf8encode, 13604 'decode': utf8decode 13605 }; 13606 13607 // Some AMD build optimizers, like r.js, check for specific condition patterns 13608 // like the following: 13609 if ( 13610 typeof define == 'function' && 13611 typeof define.amd == 'object' && 13612 define.amd 13613 ) { 13614 define(function() { 13615 return utf8; 13616 }); 13617 } else if (freeExports && !freeExports.nodeType) { 13618 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 13619 freeModule.exports = utf8; 13620 } else { // in Narwhal or RingoJS v0.7.0- 13621 var object = {}; 13622 var hasOwnProperty = object.hasOwnProperty; 13623 for (var key in utf8) { 13624 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 13625 } 13626 } 13627 } else { // in Rhino or a web browser 13628 root.utf8 = utf8; 13629 } 13630 13631 }(this)); 13632 13633 },{}],86:[function(require,module,exports){ 13634 module.exports = XMLHttpRequest; 13635 13636 },{}],"bignumber.js":[function(require,module,exports){ 13637 'use strict'; 13638 13639 module.exports = BigNumber; // jshint ignore:line 13640 13641 13642 },{}],"web3":[function(require,module,exports){ 13643 var Web3 = require('./lib/web3'); 13644 13645 // dont override global variable 13646 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 13647 window.Web3 = Web3; 13648 } 13649 13650 module.exports = Web3; 13651 13652 },{"./lib/web3":22}]},{},["web3"]) 13653 //# sourceMappingURL=web3-light.js.map