github.com/aswedchain/aswed@v1.0.1/internal/jsre/deps/web3.js (about) 1 require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 2 module.exports=[ 3 { 4 "constant": true, 5 "inputs": [ 6 { 7 "name": "_owner", 8 "type": "address" 9 } 10 ], 11 "name": "name", 12 "outputs": [ 13 { 14 "name": "o_name", 15 "type": "bytes32" 16 } 17 ], 18 "type": "function" 19 }, 20 { 21 "constant": true, 22 "inputs": [ 23 { 24 "name": "_name", 25 "type": "bytes32" 26 } 27 ], 28 "name": "owner", 29 "outputs": [ 30 { 31 "name": "", 32 "type": "address" 33 } 34 ], 35 "type": "function" 36 }, 37 { 38 "constant": true, 39 "inputs": [ 40 { 41 "name": "_name", 42 "type": "bytes32" 43 } 44 ], 45 "name": "content", 46 "outputs": [ 47 { 48 "name": "", 49 "type": "bytes32" 50 } 51 ], 52 "type": "function" 53 }, 54 { 55 "constant": true, 56 "inputs": [ 57 { 58 "name": "_name", 59 "type": "bytes32" 60 } 61 ], 62 "name": "addr", 63 "outputs": [ 64 { 65 "name": "", 66 "type": "address" 67 } 68 ], 69 "type": "function" 70 }, 71 { 72 "constant": false, 73 "inputs": [ 74 { 75 "name": "_name", 76 "type": "bytes32" 77 } 78 ], 79 "name": "reserve", 80 "outputs": [], 81 "type": "function" 82 }, 83 { 84 "constant": true, 85 "inputs": [ 86 { 87 "name": "_name", 88 "type": "bytes32" 89 } 90 ], 91 "name": "subRegistrar", 92 "outputs": [ 93 { 94 "name": "", 95 "type": "address" 96 } 97 ], 98 "type": "function" 99 }, 100 { 101 "constant": false, 102 "inputs": [ 103 { 104 "name": "_name", 105 "type": "bytes32" 106 }, 107 { 108 "name": "_newOwner", 109 "type": "address" 110 } 111 ], 112 "name": "transfer", 113 "outputs": [], 114 "type": "function" 115 }, 116 { 117 "constant": false, 118 "inputs": [ 119 { 120 "name": "_name", 121 "type": "bytes32" 122 }, 123 { 124 "name": "_registrar", 125 "type": "address" 126 } 127 ], 128 "name": "setSubRegistrar", 129 "outputs": [], 130 "type": "function" 131 }, 132 { 133 "constant": false, 134 "inputs": [], 135 "name": "Registrar", 136 "outputs": [], 137 "type": "function" 138 }, 139 { 140 "constant": false, 141 "inputs": [ 142 { 143 "name": "_name", 144 "type": "bytes32" 145 }, 146 { 147 "name": "_a", 148 "type": "address" 149 }, 150 { 151 "name": "_primary", 152 "type": "bool" 153 } 154 ], 155 "name": "setAddress", 156 "outputs": [], 157 "type": "function" 158 }, 159 { 160 "constant": false, 161 "inputs": [ 162 { 163 "name": "_name", 164 "type": "bytes32" 165 }, 166 { 167 "name": "_content", 168 "type": "bytes32" 169 } 170 ], 171 "name": "setContent", 172 "outputs": [], 173 "type": "function" 174 }, 175 { 176 "constant": false, 177 "inputs": [ 178 { 179 "name": "_name", 180 "type": "bytes32" 181 } 182 ], 183 "name": "disown", 184 "outputs": [], 185 "type": "function" 186 }, 187 { 188 "anonymous": false, 189 "inputs": [ 190 { 191 "indexed": true, 192 "name": "_name", 193 "type": "bytes32" 194 }, 195 { 196 "indexed": false, 197 "name": "_winner", 198 "type": "address" 199 } 200 ], 201 "name": "AuctionEnded", 202 "type": "event" 203 }, 204 { 205 "anonymous": false, 206 "inputs": [ 207 { 208 "indexed": true, 209 "name": "_name", 210 "type": "bytes32" 211 }, 212 { 213 "indexed": false, 214 "name": "_bidder", 215 "type": "address" 216 }, 217 { 218 "indexed": false, 219 "name": "_value", 220 "type": "uint256" 221 } 222 ], 223 "name": "NewBid", 224 "type": "event" 225 }, 226 { 227 "anonymous": false, 228 "inputs": [ 229 { 230 "indexed": true, 231 "name": "name", 232 "type": "bytes32" 233 } 234 ], 235 "name": "Changed", 236 "type": "event" 237 }, 238 { 239 "anonymous": false, 240 "inputs": [ 241 { 242 "indexed": true, 243 "name": "name", 244 "type": "bytes32" 245 }, 246 { 247 "indexed": true, 248 "name": "addr", 249 "type": "address" 250 } 251 ], 252 "name": "PrimaryChanged", 253 "type": "event" 254 } 255 ] 256 257 },{}],2:[function(require,module,exports){ 258 module.exports=[ 259 { 260 "constant": true, 261 "inputs": [ 262 { 263 "name": "_name", 264 "type": "bytes32" 265 } 266 ], 267 "name": "owner", 268 "outputs": [ 269 { 270 "name": "", 271 "type": "address" 272 } 273 ], 274 "type": "function" 275 }, 276 { 277 "constant": false, 278 "inputs": [ 279 { 280 "name": "_name", 281 "type": "bytes32" 282 }, 283 { 284 "name": "_refund", 285 "type": "address" 286 } 287 ], 288 "name": "disown", 289 "outputs": [], 290 "type": "function" 291 }, 292 { 293 "constant": true, 294 "inputs": [ 295 { 296 "name": "_name", 297 "type": "bytes32" 298 } 299 ], 300 "name": "addr", 301 "outputs": [ 302 { 303 "name": "", 304 "type": "address" 305 } 306 ], 307 "type": "function" 308 }, 309 { 310 "constant": false, 311 "inputs": [ 312 { 313 "name": "_name", 314 "type": "bytes32" 315 } 316 ], 317 "name": "reserve", 318 "outputs": [], 319 "type": "function" 320 }, 321 { 322 "constant": false, 323 "inputs": [ 324 { 325 "name": "_name", 326 "type": "bytes32" 327 }, 328 { 329 "name": "_newOwner", 330 "type": "address" 331 } 332 ], 333 "name": "transfer", 334 "outputs": [], 335 "type": "function" 336 }, 337 { 338 "constant": false, 339 "inputs": [ 340 { 341 "name": "_name", 342 "type": "bytes32" 343 }, 344 { 345 "name": "_a", 346 "type": "address" 347 } 348 ], 349 "name": "setAddr", 350 "outputs": [], 351 "type": "function" 352 }, 353 { 354 "anonymous": false, 355 "inputs": [ 356 { 357 "indexed": true, 358 "name": "name", 359 "type": "bytes32" 360 } 361 ], 362 "name": "Changed", 363 "type": "event" 364 } 365 ] 366 367 },{}],3:[function(require,module,exports){ 368 module.exports=[ 369 { 370 "constant": false, 371 "inputs": [ 372 { 373 "name": "from", 374 "type": "bytes32" 375 }, 376 { 377 "name": "to", 378 "type": "address" 379 }, 380 { 381 "name": "value", 382 "type": "uint256" 383 } 384 ], 385 "name": "transfer", 386 "outputs": [], 387 "type": "function" 388 }, 389 { 390 "constant": false, 391 "inputs": [ 392 { 393 "name": "from", 394 "type": "bytes32" 395 }, 396 { 397 "name": "to", 398 "type": "address" 399 }, 400 { 401 "name": "indirectId", 402 "type": "bytes32" 403 }, 404 { 405 "name": "value", 406 "type": "uint256" 407 } 408 ], 409 "name": "icapTransfer", 410 "outputs": [], 411 "type": "function" 412 }, 413 { 414 "constant": false, 415 "inputs": [ 416 { 417 "name": "to", 418 "type": "bytes32" 419 } 420 ], 421 "name": "deposit", 422 "outputs": [], 423 "payable": true, 424 "type": "function" 425 }, 426 { 427 "anonymous": false, 428 "inputs": [ 429 { 430 "indexed": true, 431 "name": "from", 432 "type": "address" 433 }, 434 { 435 "indexed": false, 436 "name": "value", 437 "type": "uint256" 438 } 439 ], 440 "name": "AnonymousDeposit", 441 "type": "event" 442 }, 443 { 444 "anonymous": false, 445 "inputs": [ 446 { 447 "indexed": true, 448 "name": "from", 449 "type": "address" 450 }, 451 { 452 "indexed": true, 453 "name": "to", 454 "type": "bytes32" 455 }, 456 { 457 "indexed": false, 458 "name": "value", 459 "type": "uint256" 460 } 461 ], 462 "name": "Deposit", 463 "type": "event" 464 }, 465 { 466 "anonymous": false, 467 "inputs": [ 468 { 469 "indexed": true, 470 "name": "from", 471 "type": "bytes32" 472 }, 473 { 474 "indexed": true, 475 "name": "to", 476 "type": "address" 477 }, 478 { 479 "indexed": false, 480 "name": "value", 481 "type": "uint256" 482 } 483 ], 484 "name": "Transfer", 485 "type": "event" 486 }, 487 { 488 "anonymous": false, 489 "inputs": [ 490 { 491 "indexed": true, 492 "name": "from", 493 "type": "bytes32" 494 }, 495 { 496 "indexed": true, 497 "name": "to", 498 "type": "address" 499 }, 500 { 501 "indexed": false, 502 "name": "indirectId", 503 "type": "bytes32" 504 }, 505 { 506 "indexed": false, 507 "name": "value", 508 "type": "uint256" 509 } 510 ], 511 "name": "IcapTransfer", 512 "type": "event" 513 } 514 ] 515 516 },{}],4:[function(require,module,exports){ 517 var f = require('./formatters'); 518 var SolidityType = require('./type'); 519 520 /** 521 * SolidityTypeAddress is a 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) { 929 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 930 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 931 return new SolidityParam(result); 932 }; 933 934 /** 935 * Formats input bytes 936 * 937 * @method formatInputBytes 938 * @param {String} 939 * @returns {SolidityParam} 940 */ 941 var formatInputBytes = function (value) { 942 var result = utils.toHex(value).substr(2); 943 var l = Math.floor((result.length + 63) / 64); 944 result = utils.padRight(result, l * 64); 945 return new SolidityParam(result); 946 }; 947 948 /** 949 * Formats input bytes 950 * 951 * @method formatDynamicInputBytes 952 * @param {String} 953 * @returns {SolidityParam} 954 */ 955 var formatInputDynamicBytes = function (value) { 956 var result = utils.toHex(value).substr(2); 957 var length = result.length / 2; 958 var l = Math.floor((result.length + 63) / 64); 959 result = utils.padRight(result, l * 64); 960 return new SolidityParam(formatInputInt(length).value + result); 961 }; 962 963 /** 964 * Formats input value to byte representation of string 965 * 966 * @method formatInputString 967 * @param {String} 968 * @returns {SolidityParam} 969 */ 970 var formatInputString = function (value) { 971 var result = utils.fromUtf8(value).substr(2); 972 var length = result.length / 2; 973 var l = Math.floor((result.length + 63) / 64); 974 result = utils.padRight(result, l * 64); 975 return new SolidityParam(formatInputInt(length).value + result); 976 }; 977 978 /** 979 * Formats input value to byte representation of bool 980 * 981 * @method formatInputBool 982 * @param {Boolean} 983 * @returns {SolidityParam} 984 */ 985 var formatInputBool = function (value) { 986 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 987 return new SolidityParam(result); 988 }; 989 990 /** 991 * Formats input value to byte representation of real 992 * Values are multiplied by 2^m and encoded as integers 993 * 994 * @method formatInputReal 995 * @param {String|Number|BigNumber} 996 * @returns {SolidityParam} 997 */ 998 var formatInputReal = function (value) { 999 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1000 }; 1001 1002 /** 1003 * Check if input value is negative 1004 * 1005 * @method signedIsNegative 1006 * @param {String} value is hex format 1007 * @returns {Boolean} true if it is negative, otherwise false 1008 */ 1009 var signedIsNegative = function (value) { 1010 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1011 }; 1012 1013 /** 1014 * Formats right-aligned output bytes to int 1015 * 1016 * @method formatOutputInt 1017 * @param {SolidityParam} param 1018 * @returns {BigNumber} right-aligned output bytes formatted to big number 1019 */ 1020 var formatOutputInt = function (param) { 1021 var value = param.staticPart() || "0"; 1022 1023 // check if it's negative number 1024 // it is, return two's complement 1025 if (signedIsNegative(value)) { 1026 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1027 } 1028 return new BigNumber(value, 16); 1029 }; 1030 1031 /** 1032 * Formats right-aligned output bytes to uint 1033 * 1034 * @method formatOutputUInt 1035 * @param {SolidityParam} 1036 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1037 */ 1038 var formatOutputUInt = function (param) { 1039 var value = param.staticPart() || "0"; 1040 return new BigNumber(value, 16); 1041 }; 1042 1043 /** 1044 * Formats right-aligned output bytes to real 1045 * 1046 * @method formatOutputReal 1047 * @param {SolidityParam} 1048 * @returns {BigNumber} input bytes formatted to real 1049 */ 1050 var formatOutputReal = function (param) { 1051 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1052 }; 1053 1054 /** 1055 * Formats right-aligned output bytes to ureal 1056 * 1057 * @method formatOutputUReal 1058 * @param {SolidityParam} 1059 * @returns {BigNumber} input bytes formatted to ureal 1060 */ 1061 var formatOutputUReal = function (param) { 1062 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1063 }; 1064 1065 /** 1066 * Should be used to format output bool 1067 * 1068 * @method formatOutputBool 1069 * @param {SolidityParam} 1070 * @returns {Boolean} right-aligned input bytes formatted to bool 1071 */ 1072 var formatOutputBool = function (param) { 1073 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1074 }; 1075 1076 /** 1077 * Should be used to format output bytes 1078 * 1079 * @method formatOutputBytes 1080 * @param {SolidityParam} left-aligned hex representation of string 1081 * @param {String} name type name 1082 * @returns {String} hex string 1083 */ 1084 var formatOutputBytes = function (param, name) { 1085 var matches = name.match(/^bytes([0-9]*)/); 1086 var size = parseInt(matches[1]); 1087 return '0x' + param.staticPart().slice(0, 2 * size); 1088 }; 1089 1090 /** 1091 * Should be used to format output bytes 1092 * 1093 * @method formatOutputDynamicBytes 1094 * @param {SolidityParam} left-aligned hex representation of string 1095 * @returns {String} hex string 1096 */ 1097 var formatOutputDynamicBytes = function (param) { 1098 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1099 return '0x' + param.dynamicPart().substr(64, length); 1100 }; 1101 1102 /** 1103 * Should be used to format output string 1104 * 1105 * @method formatOutputString 1106 * @param {SolidityParam} left-aligned hex representation of string 1107 * @returns {String} ascii string 1108 */ 1109 var formatOutputString = function (param) { 1110 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1111 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1112 }; 1113 1114 /** 1115 * Should be used to format output address 1116 * 1117 * @method formatOutputAddress 1118 * @param {SolidityParam} right-aligned input bytes 1119 * @returns {String} address 1120 */ 1121 var formatOutputAddress = function (param) { 1122 var value = param.staticPart(); 1123 return "0x" + value.slice(value.length - 40, value.length); 1124 }; 1125 1126 module.exports = { 1127 formatInputInt: formatInputInt, 1128 formatInputBytes: formatInputBytes, 1129 formatInputDynamicBytes: formatInputDynamicBytes, 1130 formatInputString: formatInputString, 1131 formatInputBool: formatInputBool, 1132 formatInputReal: formatInputReal, 1133 formatOutputInt: formatOutputInt, 1134 formatOutputUInt: formatOutputUInt, 1135 formatOutputReal: formatOutputReal, 1136 formatOutputUReal: formatOutputUReal, 1137 formatOutputBool: formatOutputBool, 1138 formatOutputBytes: formatOutputBytes, 1139 formatOutputDynamicBytes: formatOutputDynamicBytes, 1140 formatOutputString: formatOutputString, 1141 formatOutputAddress: formatOutputAddress 1142 }; 1143 1144 },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){ 1145 var f = require('./formatters'); 1146 var SolidityType = require('./type'); 1147 1148 /** 1149 * SolidityTypeInt is a prootype that represents int type 1150 * It matches: 1151 * int 1152 * int[] 1153 * int[4] 1154 * int[][] 1155 * int[3][] 1156 * int[][6][], ... 1157 * int32 1158 * int64[] 1159 * int8[4] 1160 * int256[][] 1161 * int[3][] 1162 * int64[][6][], ... 1163 */ 1164 var SolidityTypeInt = function () { 1165 this._inputFormatter = f.formatInputInt; 1166 this._outputFormatter = f.formatOutputInt; 1167 }; 1168 1169 SolidityTypeInt.prototype = new SolidityType({}); 1170 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1171 1172 SolidityTypeInt.prototype.isType = function (name) { 1173 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1174 }; 1175 1176 module.exports = SolidityTypeInt; 1177 1178 },{"./formatters":9,"./type":14}],11:[function(require,module,exports){ 1179 /* 1180 This file is part of web3.js. 1181 1182 web3.js is free software: you can redistribute it and/or modify 1183 it under the terms of the GNU Lesser General Public License as published by 1184 the Free Software Foundation, either version 3 of the License, or 1185 (at your option) any later version. 1186 1187 web3.js is distributed in the hope that it will be useful, 1188 but WITHOUT ANY WARRANTY; without even the implied warranty of 1189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1190 GNU Lesser General Public License for more details. 1191 1192 You should have received a copy of the GNU Lesser General Public License 1193 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1194 */ 1195 /** 1196 * @file param.js 1197 * @author Marek Kotewicz <marek@ethdev.com> 1198 * @date 2015 1199 */ 1200 1201 var utils = require('../utils/utils'); 1202 1203 /** 1204 * SolidityParam object prototype. 1205 * Should be used when encoding, decoding solidity bytes 1206 */ 1207 var SolidityParam = function (value, offset) { 1208 this.value = value || ''; 1209 this.offset = offset; // offset in bytes 1210 }; 1211 1212 /** 1213 * This method should be used to get length of params's dynamic part 1214 * 1215 * @method dynamicPartLength 1216 * @returns {Number} length of dynamic part (in bytes) 1217 */ 1218 SolidityParam.prototype.dynamicPartLength = function () { 1219 return this.dynamicPart().length / 2; 1220 }; 1221 1222 /** 1223 * This method should be used to create copy of solidity param with different offset 1224 * 1225 * @method withOffset 1226 * @param {Number} offset length in bytes 1227 * @returns {SolidityParam} new solidity param with applied offset 1228 */ 1229 SolidityParam.prototype.withOffset = function (offset) { 1230 return new SolidityParam(this.value, offset); 1231 }; 1232 1233 /** 1234 * This method should be used to combine solidity params together 1235 * eg. when appending an array 1236 * 1237 * @method combine 1238 * @param {SolidityParam} param with which we should combine 1239 * @param {SolidityParam} result of combination 1240 */ 1241 SolidityParam.prototype.combine = function (param) { 1242 return new SolidityParam(this.value + param.value); 1243 }; 1244 1245 /** 1246 * This method should be called to check if param has dynamic size. 1247 * If it has, it returns true, otherwise false 1248 * 1249 * @method isDynamic 1250 * @returns {Boolean} 1251 */ 1252 SolidityParam.prototype.isDynamic = function () { 1253 return this.offset !== undefined; 1254 }; 1255 1256 /** 1257 * This method should be called to transform offset to bytes 1258 * 1259 * @method offsetAsBytes 1260 * @returns {String} bytes representation of offset 1261 */ 1262 SolidityParam.prototype.offsetAsBytes = function () { 1263 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1264 }; 1265 1266 /** 1267 * This method should be called to get static part of param 1268 * 1269 * @method staticPart 1270 * @returns {String} offset if it is a dynamic param, otherwise value 1271 */ 1272 SolidityParam.prototype.staticPart = function () { 1273 if (!this.isDynamic()) { 1274 return this.value; 1275 } 1276 return this.offsetAsBytes(); 1277 }; 1278 1279 /** 1280 * This method should be called to get dynamic part of param 1281 * 1282 * @method dynamicPart 1283 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1284 */ 1285 SolidityParam.prototype.dynamicPart = function () { 1286 return this.isDynamic() ? this.value : ''; 1287 }; 1288 1289 /** 1290 * This method should be called to encode param 1291 * 1292 * @method encode 1293 * @returns {String} 1294 */ 1295 SolidityParam.prototype.encode = function () { 1296 return this.staticPart() + this.dynamicPart(); 1297 }; 1298 1299 /** 1300 * This method should be called to encode array of params 1301 * 1302 * @method encodeList 1303 * @param {Array[SolidityParam]} params 1304 * @returns {String} 1305 */ 1306 SolidityParam.encodeList = function (params) { 1307 1308 // updating offsets 1309 var totalOffset = params.length * 32; 1310 var offsetParams = params.map(function (param) { 1311 if (!param.isDynamic()) { 1312 return param; 1313 } 1314 var offset = totalOffset; 1315 totalOffset += param.dynamicPartLength(); 1316 return param.withOffset(offset); 1317 }); 1318 1319 // encode everything! 1320 return offsetParams.reduce(function (result, param) { 1321 return result + param.dynamicPart(); 1322 }, offsetParams.reduce(function (result, param) { 1323 return result + param.staticPart(); 1324 }, '')); 1325 }; 1326 1327 1328 1329 module.exports = SolidityParam; 1330 1331 1332 },{"../utils/utils":20}],12:[function(require,module,exports){ 1333 var f = require('./formatters'); 1334 var SolidityType = require('./type'); 1335 1336 /** 1337 * SolidityTypeReal is a prootype that represents real type 1338 * It matches: 1339 * real 1340 * real[] 1341 * real[4] 1342 * real[][] 1343 * real[3][] 1344 * real[][6][], ... 1345 * real32 1346 * real64[] 1347 * real8[4] 1348 * real256[][] 1349 * real[3][] 1350 * real64[][6][], ... 1351 */ 1352 var SolidityTypeReal = function () { 1353 this._inputFormatter = f.formatInputReal; 1354 this._outputFormatter = f.formatOutputReal; 1355 }; 1356 1357 SolidityTypeReal.prototype = new SolidityType({}); 1358 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1359 1360 SolidityTypeReal.prototype.isType = function (name) { 1361 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1362 }; 1363 1364 module.exports = SolidityTypeReal; 1365 1366 },{"./formatters":9,"./type":14}],13:[function(require,module,exports){ 1367 var f = require('./formatters'); 1368 var SolidityType = require('./type'); 1369 1370 var SolidityTypeString = function () { 1371 this._inputFormatter = f.formatInputString; 1372 this._outputFormatter = f.formatOutputString; 1373 }; 1374 1375 SolidityTypeString.prototype = new SolidityType({}); 1376 SolidityTypeString.prototype.constructor = SolidityTypeString; 1377 1378 SolidityTypeString.prototype.isType = function (name) { 1379 return !!name.match(/^string(\[([0-9]*)\])*$/); 1380 }; 1381 1382 SolidityTypeString.prototype.isDynamicType = function () { 1383 return true; 1384 }; 1385 1386 module.exports = SolidityTypeString; 1387 1388 },{"./formatters":9,"./type":14}],14:[function(require,module,exports){ 1389 var f = require('./formatters'); 1390 var SolidityParam = require('./param'); 1391 1392 /** 1393 * SolidityType prototype is used to encode/decode solidity params of certain type 1394 */ 1395 var SolidityType = function (config) { 1396 this._inputFormatter = config.inputFormatter; 1397 this._outputFormatter = config.outputFormatter; 1398 }; 1399 1400 /** 1401 * Should be used to determine if this SolidityType do match given name 1402 * 1403 * @method isType 1404 * @param {String} name 1405 * @return {Bool} true if type match this SolidityType, otherwise false 1406 */ 1407 SolidityType.prototype.isType = function (name) { 1408 throw "this method should be overrwritten for type " + name; 1409 }; 1410 1411 /** 1412 * Should be used to determine what is the length of static part in given type 1413 * 1414 * @method staticPartLength 1415 * @param {String} name 1416 * @return {Number} length of static part in bytes 1417 */ 1418 SolidityType.prototype.staticPartLength = function (name) { 1419 // If name isn't an array then treat it like a single element array. 1420 return (this.nestedTypes(name) || ['[1]']) 1421 .map(function (type) { 1422 // the length of the nested array 1423 return parseInt(type.slice(1, -1), 10) || 1; 1424 }) 1425 .reduce(function (previous, current) { 1426 return previous * current; 1427 // all basic types are 32 bytes long 1428 }, 32); 1429 }; 1430 1431 /** 1432 * Should be used to determine if type is dynamic array 1433 * eg: 1434 * "type[]" => true 1435 * "type[4]" => false 1436 * 1437 * @method isDynamicArray 1438 * @param {String} name 1439 * @return {Bool} true if the type is dynamic array 1440 */ 1441 SolidityType.prototype.isDynamicArray = function (name) { 1442 var nestedTypes = this.nestedTypes(name); 1443 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1444 }; 1445 1446 /** 1447 * Should be used to determine if type is static array 1448 * eg: 1449 * "type[]" => false 1450 * "type[4]" => true 1451 * 1452 * @method isStaticArray 1453 * @param {String} name 1454 * @return {Bool} true if the type is static array 1455 */ 1456 SolidityType.prototype.isStaticArray = function (name) { 1457 var nestedTypes = this.nestedTypes(name); 1458 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1459 }; 1460 1461 /** 1462 * Should return length of static array 1463 * eg. 1464 * "int[32]" => 32 1465 * "int256[14]" => 14 1466 * "int[2][3]" => 3 1467 * "int" => 1 1468 * "int[1]" => 1 1469 * "int[]" => 1 1470 * 1471 * @method staticArrayLength 1472 * @param {String} name 1473 * @return {Number} static array length 1474 */ 1475 SolidityType.prototype.staticArrayLength = function (name) { 1476 var nestedTypes = this.nestedTypes(name); 1477 if (nestedTypes) { 1478 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1479 } 1480 return 1; 1481 }; 1482 1483 /** 1484 * Should return nested type 1485 * eg. 1486 * "int[32]" => "int" 1487 * "int256[14]" => "int256" 1488 * "int[2][3]" => "int[2]" 1489 * "int" => "int" 1490 * "int[]" => "int" 1491 * 1492 * @method nestedName 1493 * @param {String} name 1494 * @return {String} nested name 1495 */ 1496 SolidityType.prototype.nestedName = function (name) { 1497 // remove last [] in name 1498 var nestedTypes = this.nestedTypes(name); 1499 if (!nestedTypes) { 1500 return name; 1501 } 1502 1503 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1504 }; 1505 1506 /** 1507 * Should return true if type has dynamic size by default 1508 * such types are "string", "bytes" 1509 * 1510 * @method isDynamicType 1511 * @param {String} name 1512 * @return {Bool} true if is dynamic, otherwise false 1513 */ 1514 SolidityType.prototype.isDynamicType = function () { 1515 return false; 1516 }; 1517 1518 /** 1519 * Should return array of nested types 1520 * eg. 1521 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1522 * "int[] => ["[]"] 1523 * "int" => null 1524 * 1525 * @method nestedTypes 1526 * @param {String} name 1527 * @return {Array} array of nested types 1528 */ 1529 SolidityType.prototype.nestedTypes = function (name) { 1530 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1531 return name.match(/(\[[0-9]*\])/g); 1532 }; 1533 1534 /** 1535 * Should be used to encode the value 1536 * 1537 * @method encode 1538 * @param {Object} value 1539 * @param {String} name 1540 * @return {String} encoded value 1541 */ 1542 SolidityType.prototype.encode = function (value, name) { 1543 var self = this; 1544 if (this.isDynamicArray(name)) { 1545 1546 return (function () { 1547 var length = value.length; // in int 1548 var nestedName = self.nestedName(name); 1549 1550 var result = []; 1551 result.push(f.formatInputInt(length).encode()); 1552 1553 value.forEach(function (v) { 1554 result.push(self.encode(v, nestedName)); 1555 }); 1556 1557 return result; 1558 })(); 1559 1560 } else if (this.isStaticArray(name)) { 1561 1562 return (function () { 1563 var length = self.staticArrayLength(name); // in int 1564 var nestedName = self.nestedName(name); 1565 1566 var result = []; 1567 for (var i = 0; i < length; i++) { 1568 result.push(self.encode(value[i], nestedName)); 1569 } 1570 1571 return result; 1572 })(); 1573 1574 } 1575 1576 return this._inputFormatter(value, name).encode(); 1577 }; 1578 1579 /** 1580 * Should be used to decode value from bytes 1581 * 1582 * @method decode 1583 * @param {String} bytes 1584 * @param {Number} offset in bytes 1585 * @param {String} name type name 1586 * @returns {Object} decoded value 1587 */ 1588 SolidityType.prototype.decode = function (bytes, offset, name) { 1589 var self = this; 1590 1591 if (this.isDynamicArray(name)) { 1592 1593 return (function () { 1594 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1595 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1596 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1597 1598 var nestedName = self.nestedName(name); 1599 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1600 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1601 var result = []; 1602 1603 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1604 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1605 } 1606 1607 return result; 1608 })(); 1609 1610 } else if (this.isStaticArray(name)) { 1611 1612 return (function () { 1613 var length = self.staticArrayLength(name); // in int 1614 var arrayStart = offset; // in bytes 1615 1616 var nestedName = self.nestedName(name); 1617 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1618 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1619 var result = []; 1620 1621 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1622 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1623 } 1624 1625 return result; 1626 })(); 1627 } else if (this.isDynamicType(name)) { 1628 1629 return (function () { 1630 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1631 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1632 var roundedLength = Math.floor((length + 31) / 32); // in int 1633 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0); 1634 return self._outputFormatter(param, name); 1635 })(); 1636 } 1637 1638 var length = this.staticPartLength(name); 1639 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1640 return this._outputFormatter(param, name); 1641 }; 1642 1643 module.exports = SolidityType; 1644 1645 },{"./formatters":9,"./param":11}],15:[function(require,module,exports){ 1646 var f = require('./formatters'); 1647 var SolidityType = require('./type'); 1648 1649 /** 1650 * SolidityTypeUInt is a prootype that represents uint type 1651 * It matches: 1652 * uint 1653 * uint[] 1654 * uint[4] 1655 * uint[][] 1656 * uint[3][] 1657 * uint[][6][], ... 1658 * uint32 1659 * uint64[] 1660 * uint8[4] 1661 * uint256[][] 1662 * uint[3][] 1663 * uint64[][6][], ... 1664 */ 1665 var SolidityTypeUInt = function () { 1666 this._inputFormatter = f.formatInputInt; 1667 this._outputFormatter = f.formatOutputUInt; 1668 }; 1669 1670 SolidityTypeUInt.prototype = new SolidityType({}); 1671 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1672 1673 SolidityTypeUInt.prototype.isType = function (name) { 1674 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1675 }; 1676 1677 module.exports = SolidityTypeUInt; 1678 1679 },{"./formatters":9,"./type":14}],16:[function(require,module,exports){ 1680 var f = require('./formatters'); 1681 var SolidityType = require('./type'); 1682 1683 /** 1684 * SolidityTypeUReal is a prootype that represents ureal type 1685 * It matches: 1686 * ureal 1687 * ureal[] 1688 * ureal[4] 1689 * ureal[][] 1690 * ureal[3][] 1691 * ureal[][6][], ... 1692 * ureal32 1693 * ureal64[] 1694 * ureal8[4] 1695 * ureal256[][] 1696 * ureal[3][] 1697 * ureal64[][6][], ... 1698 */ 1699 var SolidityTypeUReal = function () { 1700 this._inputFormatter = f.formatInputReal; 1701 this._outputFormatter = f.formatOutputUReal; 1702 }; 1703 1704 SolidityTypeUReal.prototype = new SolidityType({}); 1705 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1706 1707 SolidityTypeUReal.prototype.isType = function (name) { 1708 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1709 }; 1710 1711 module.exports = SolidityTypeUReal; 1712 1713 },{"./formatters":9,"./type":14}],17:[function(require,module,exports){ 1714 'use strict'; 1715 1716 // go env doesn't have and need XMLHttpRequest 1717 if (typeof XMLHttpRequest === 'undefined') { 1718 exports.XMLHttpRequest = {}; 1719 } else { 1720 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1721 } 1722 1723 1724 },{}],18:[function(require,module,exports){ 1725 /* 1726 This file is part of web3.js. 1727 1728 web3.js is free software: you can redistribute it and/or modify 1729 it under the terms of the GNU Lesser General Public License as published by 1730 the Free Software Foundation, either version 3 of the License, or 1731 (at your option) any later version. 1732 1733 web3.js is distributed in the hope that it will be useful, 1734 but WITHOUT ANY WARRANTY; without even the implied warranty of 1735 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1736 GNU Lesser General Public License for more details. 1737 1738 You should have received a copy of the GNU Lesser General Public License 1739 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1740 */ 1741 /** @file config.js 1742 * @authors: 1743 * Marek Kotewicz <marek@ethdev.com> 1744 * @date 2015 1745 */ 1746 1747 /** 1748 * Utils 1749 * 1750 * @module utils 1751 */ 1752 1753 /** 1754 * Utility functions 1755 * 1756 * @class [utils] config 1757 * @constructor 1758 */ 1759 1760 1761 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1762 var BigNumber = require('bignumber.js'); 1763 1764 var ETH_UNITS = [ 1765 'wei', 1766 'kwei', 1767 'Mwei', 1768 'Gwei', 1769 'szabo', 1770 'finney', 1771 'femtoether', 1772 'picoether', 1773 'nanoether', 1774 'microether', 1775 'milliether', 1776 'nano', 1777 'micro', 1778 'milli', 1779 'ether', 1780 'grand', 1781 'Mether', 1782 'Gether', 1783 'Tether', 1784 'Pether', 1785 'Eether', 1786 'Zether', 1787 'Yether', 1788 'Nether', 1789 'Dether', 1790 'Vether', 1791 'Uether' 1792 ]; 1793 1794 module.exports = { 1795 ETH_PADDING: 32, 1796 ETH_SIGNATURE_LENGTH: 4, 1797 ETH_UNITS: ETH_UNITS, 1798 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1799 ETH_POLLING_TIMEOUT: 1000/2, 1800 defaultBlock: 'latest', 1801 defaultAccount: undefined 1802 }; 1803 1804 1805 },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){ 1806 /* 1807 This file is part of web3.js. 1808 1809 web3.js is free software: you can redistribute it and/or modify 1810 it under the terms of the GNU Lesser General Public License as published by 1811 the Free Software Foundation, either version 3 of the License, or 1812 (at your option) any later version. 1813 1814 web3.js is distributed in the hope that it will be useful, 1815 but WITHOUT ANY WARRANTY; without even the implied warranty of 1816 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1817 GNU Lesser General Public License for more details. 1818 1819 You should have received a copy of the GNU Lesser General Public License 1820 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1821 */ 1822 /** 1823 * @file sha3.js 1824 * @author Marek Kotewicz <marek@ethdev.com> 1825 * @date 2015 1826 */ 1827 1828 var CryptoJS = require('crypto-js'); 1829 var sha3 = require('crypto-js/sha3'); 1830 1831 module.exports = function (value, options) { 1832 if (options && options.encoding === 'hex') { 1833 if (value.length > 2 && value.substr(0, 2) === '0x') { 1834 value = value.substr(2); 1835 } 1836 value = CryptoJS.enc.Hex.parse(value); 1837 } 1838 1839 return sha3(value, { 1840 outputLength: 256 1841 }).toString(); 1842 }; 1843 1844 1845 },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){ 1846 /* 1847 This file is part of web3.js. 1848 1849 web3.js is free software: you can redistribute it and/or modify 1850 it under the terms of the GNU Lesser General Public License as published by 1851 the Free Software Foundation, either version 3 of the License, or 1852 (at your option) any later version. 1853 1854 web3.js is distributed in the hope that it will be useful, 1855 but WITHOUT ANY WARRANTY; without even the implied warranty of 1856 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1857 GNU Lesser General Public License for more details. 1858 1859 You should have received a copy of the GNU Lesser General Public License 1860 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1861 */ 1862 /** 1863 * @file utils.js 1864 * @author Marek Kotewicz <marek@ethdev.com> 1865 * @date 2015 1866 */ 1867 1868 /** 1869 * Utils 1870 * 1871 * @module utils 1872 */ 1873 1874 /** 1875 * Utility functions 1876 * 1877 * @class [utils] utils 1878 * @constructor 1879 */ 1880 1881 1882 var BigNumber = require('bignumber.js'); 1883 var sha3 = require('./sha3.js'); 1884 var utf8 = require('utf8'); 1885 1886 var unitMap = { 1887 'noether': '0', 1888 'wei': '1', 1889 'kwei': '1000', 1890 'Kwei': '1000', 1891 'babbage': '1000', 1892 'femtoether': '1000', 1893 'mwei': '1000000', 1894 'Mwei': '1000000', 1895 'lovelace': '1000000', 1896 'picoether': '1000000', 1897 'gwei': '1000000000', 1898 'Gwei': '1000000000', 1899 'shannon': '1000000000', 1900 'nanoether': '1000000000', 1901 'nano': '1000000000', 1902 'szabo': '1000000000000', 1903 'microether': '1000000000000', 1904 'micro': '1000000000000', 1905 'finney': '1000000000000000', 1906 'milliether': '1000000000000000', 1907 'milli': '1000000000000000', 1908 'ether': '1000000000000000000', 1909 'kether': '1000000000000000000000', 1910 'grand': '1000000000000000000000', 1911 'mether': '1000000000000000000000000', 1912 'gether': '1000000000000000000000000000', 1913 'tether': '1000000000000000000000000000000' 1914 }; 1915 1916 /** 1917 * Should be called to pad string to expected length 1918 * 1919 * @method padLeft 1920 * @param {String} string to be padded 1921 * @param {Number} characters that result string should have 1922 * @param {String} sign, by default 0 1923 * @returns {String} right aligned string 1924 */ 1925 var padLeft = function (string, chars, sign) { 1926 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1927 }; 1928 1929 /** 1930 * Should be called to pad string to expected length 1931 * 1932 * @method padRight 1933 * @param {String} string to be padded 1934 * @param {Number} characters that result string should have 1935 * @param {String} sign, by default 0 1936 * @returns {String} right aligned string 1937 */ 1938 var padRight = function (string, chars, sign) { 1939 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1940 }; 1941 1942 /** 1943 * Should be called to get utf8 from it's hex representation 1944 * 1945 * @method toUtf8 1946 * @param {String} string in hex 1947 * @returns {String} ascii string representation of hex value 1948 */ 1949 var toUtf8 = function(hex) { 1950 // Find termination 1951 var str = ""; 1952 var i = 0, l = hex.length; 1953 if (hex.substring(0, 2) === '0x') { 1954 i = 2; 1955 } 1956 for (; i < l; i+=2) { 1957 var code = parseInt(hex.substr(i, 2), 16); 1958 if (code === 0) 1959 break; 1960 str += String.fromCharCode(code); 1961 } 1962 1963 return utf8.decode(str); 1964 }; 1965 1966 /** 1967 * Should be called to get ascii from it's hex representation 1968 * 1969 * @method toAscii 1970 * @param {String} string in hex 1971 * @returns {String} ascii string representation of hex value 1972 */ 1973 var toAscii = function(hex) { 1974 // Find termination 1975 var str = ""; 1976 var i = 0, l = hex.length; 1977 if (hex.substring(0, 2) === '0x') { 1978 i = 2; 1979 } 1980 for (; i < l; i+=2) { 1981 var code = parseInt(hex.substr(i, 2), 16); 1982 str += String.fromCharCode(code); 1983 } 1984 1985 return str; 1986 }; 1987 1988 /** 1989 * Should be called to get hex representation (prefixed by 0x) of utf8 string 1990 * 1991 * @method fromUtf8 1992 * @param {String} string 1993 * @param {Number} optional padding 1994 * @returns {String} hex representation of input string 1995 */ 1996 var fromUtf8 = function(str) { 1997 str = utf8.encode(str); 1998 var hex = ""; 1999 for(var i = 0; i < str.length; i++) { 2000 var code = str.charCodeAt(i); 2001 if (code === 0) 2002 break; 2003 var n = code.toString(16); 2004 hex += n.length < 2 ? '0' + n : n; 2005 } 2006 2007 return "0x" + hex; 2008 }; 2009 2010 /** 2011 * Should be called to get hex representation (prefixed by 0x) of ascii string 2012 * 2013 * @method fromAscii 2014 * @param {String} string 2015 * @param {Number} optional padding 2016 * @returns {String} hex representation of input string 2017 */ 2018 var fromAscii = function(str) { 2019 var hex = ""; 2020 for(var i = 0; i < str.length; i++) { 2021 var code = str.charCodeAt(i); 2022 var n = code.toString(16); 2023 hex += n.length < 2 ? '0' + n : n; 2024 } 2025 2026 return "0x" + hex; 2027 }; 2028 2029 /** 2030 * Should be used to create full function/event name from json abi 2031 * 2032 * @method transformToFullName 2033 * @param {Object} json-abi 2034 * @return {String} full fnction/event name 2035 */ 2036 var transformToFullName = function (json) { 2037 if (json.name.indexOf('(') !== -1) { 2038 return json.name; 2039 } 2040 2041 var typeName = json.inputs.map(function(i){return i.type; }).join(); 2042 return json.name + '(' + typeName + ')'; 2043 }; 2044 2045 /** 2046 * Should be called to get display name of contract function 2047 * 2048 * @method extractDisplayName 2049 * @param {String} name of function/event 2050 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2051 */ 2052 var extractDisplayName = function (name) { 2053 var length = name.indexOf('('); 2054 return length !== -1 ? name.substr(0, length) : name; 2055 }; 2056 2057 /// @returns overloaded part of function/event name 2058 var extractTypeName = function (name) { 2059 /// TODO: make it invulnerable 2060 var length = name.indexOf('('); 2061 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2062 }; 2063 2064 /** 2065 * Converts value to it's decimal representation in string 2066 * 2067 * @method toDecimal 2068 * @param {String|Number|BigNumber} 2069 * @return {String} 2070 */ 2071 var toDecimal = function (value) { 2072 return toBigNumber(value).toNumber(); 2073 }; 2074 2075 /** 2076 * Converts value to it's hex representation 2077 * 2078 * @method fromDecimal 2079 * @param {String|Number|BigNumber} 2080 * @return {String} 2081 */ 2082 var fromDecimal = function (value) { 2083 var number = toBigNumber(value); 2084 var result = number.toString(16); 2085 2086 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2087 }; 2088 2089 /** 2090 * Auto converts any given value into it's hex representation. 2091 * 2092 * And even stringifys objects before. 2093 * 2094 * @method toHex 2095 * @param {String|Number|BigNumber|Object} 2096 * @return {String} 2097 */ 2098 var toHex = function (val) { 2099 /*jshint maxcomplexity: 8 */ 2100 2101 if (isBoolean(val)) 2102 return fromDecimal(+val); 2103 2104 if (isBigNumber(val)) 2105 return fromDecimal(val); 2106 2107 if (typeof val === 'object') 2108 return fromUtf8(JSON.stringify(val)); 2109 2110 // if its a negative number, pass it through fromDecimal 2111 if (isString(val)) { 2112 if (val.indexOf('-0x') === 0) 2113 return fromDecimal(val); 2114 else if(val.indexOf('0x') === 0) 2115 return val; 2116 else if (!isFinite(val)) 2117 return fromAscii(val); 2118 } 2119 2120 return fromDecimal(val); 2121 }; 2122 2123 /** 2124 * Returns value of unit in Wei 2125 * 2126 * @method getValueOfUnit 2127 * @param {String} unit the unit to convert to, default ether 2128 * @returns {BigNumber} value of the unit (in Wei) 2129 * @throws error if the unit is not correct:w 2130 */ 2131 var getValueOfUnit = function (unit) { 2132 unit = unit ? unit.toLowerCase() : 'ether'; 2133 var unitValue = unitMap[unit]; 2134 if (unitValue === undefined) { 2135 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2136 } 2137 return new BigNumber(unitValue, 10); 2138 }; 2139 2140 /** 2141 * Takes a number of wei and converts it to any other ether unit. 2142 * 2143 * Possible units are: 2144 * SI Short SI Full Effigy Other 2145 * - kwei femtoether babbage 2146 * - mwei picoether lovelace 2147 * - gwei nanoether shannon nano 2148 * - -- microether szabo micro 2149 * - -- milliether finney milli 2150 * - ether -- -- 2151 * - kether -- grand 2152 * - mether 2153 * - gether 2154 * - tether 2155 * 2156 * @method fromWei 2157 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2158 * @param {String} unit the unit to convert to, default ether 2159 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2160 */ 2161 var fromWei = function(number, unit) { 2162 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2163 2164 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2165 }; 2166 2167 /** 2168 * Takes a number of a unit and converts it to wei. 2169 * 2170 * Possible units are: 2171 * SI Short SI Full Effigy Other 2172 * - kwei femtoether babbage 2173 * - mwei picoether lovelace 2174 * - gwei nanoether shannon nano 2175 * - -- microether szabo micro 2176 * - -- microether szabo micro 2177 * - -- milliether finney milli 2178 * - ether -- -- 2179 * - kether -- grand 2180 * - mether 2181 * - gether 2182 * - tether 2183 * 2184 * @method toWei 2185 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2186 * @param {String} unit the unit to convert from, default ether 2187 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2188 */ 2189 var toWei = function(number, unit) { 2190 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2191 2192 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2193 }; 2194 2195 /** 2196 * Takes an input and transforms it into a bignumber 2197 * 2198 * @method toBigNumber 2199 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2200 * @return {BigNumber} BigNumber 2201 */ 2202 var toBigNumber = function(number) { 2203 /*jshint maxcomplexity:5 */ 2204 number = number || 0; 2205 if (isBigNumber(number)) 2206 return number; 2207 2208 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2209 return new BigNumber(number.replace('0x',''), 16); 2210 } 2211 2212 return new BigNumber(number.toString(10), 10); 2213 }; 2214 2215 /** 2216 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2217 * 2218 * @method toTwosComplement 2219 * @param {Number|String|BigNumber} 2220 * @return {BigNumber} 2221 */ 2222 var toTwosComplement = function (number) { 2223 var bigNumber = toBigNumber(number).round(); 2224 if (bigNumber.lessThan(0)) { 2225 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2226 } 2227 return bigNumber; 2228 }; 2229 2230 /** 2231 * Checks if the given string is strictly an address 2232 * 2233 * @method isStrictAddress 2234 * @param {String} address the given HEX address 2235 * @return {Boolean} 2236 */ 2237 var isStrictAddress = function (address) { 2238 return /^0x[0-9a-f]{40}$/i.test(address); 2239 }; 2240 2241 /** 2242 * Checks if the given string is an address 2243 * 2244 * @method isAddress 2245 * @param {String} address the given HEX address 2246 * @return {Boolean} 2247 */ 2248 var isAddress = function (address) { 2249 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2250 // check if it has the basic requirements of an address 2251 return false; 2252 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2253 // If it's all small caps or all caps, return true 2254 return true; 2255 } else { 2256 // Otherwise check each case 2257 return isChecksumAddress(address); 2258 } 2259 }; 2260 2261 /** 2262 * Checks if the given string is a checksummed address 2263 * 2264 * @method isChecksumAddress 2265 * @param {String} address the given HEX address 2266 * @return {Boolean} 2267 */ 2268 var isChecksumAddress = function (address) { 2269 // Check each case 2270 address = address.replace('0x',''); 2271 var addressHash = sha3(address.toLowerCase()); 2272 2273 for (var i = 0; i < 40; i++ ) { 2274 // the nth letter should be uppercase if the nth digit of casemap is 1 2275 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2276 return false; 2277 } 2278 } 2279 return true; 2280 }; 2281 2282 2283 2284 /** 2285 * Makes a checksum address 2286 * 2287 * @method toChecksumAddress 2288 * @param {String} address the given HEX address 2289 * @return {String} 2290 */ 2291 var toChecksumAddress = function (address) { 2292 if (typeof address === 'undefined') return ''; 2293 2294 address = address.toLowerCase().replace('0x',''); 2295 var addressHash = sha3(address); 2296 var checksumAddress = '0x'; 2297 2298 for (var i = 0; i < address.length; i++ ) { 2299 // If ith character is 9 to f then make it uppercase 2300 if (parseInt(addressHash[i], 16) > 7) { 2301 checksumAddress += address[i].toUpperCase(); 2302 } else { 2303 checksumAddress += address[i]; 2304 } 2305 } 2306 return checksumAddress; 2307 }; 2308 2309 /** 2310 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2311 * 2312 * @method toAddress 2313 * @param {String} address 2314 * @return {String} formatted address 2315 */ 2316 var toAddress = function (address) { 2317 if (isStrictAddress(address)) { 2318 return address; 2319 } 2320 2321 if (/^[0-9a-f]{40}$/.test(address)) { 2322 return '0x' + address; 2323 } 2324 2325 return '0x' + padLeft(toHex(address).substr(2), 40); 2326 }; 2327 2328 /** 2329 * Returns true if object is BigNumber, otherwise false 2330 * 2331 * @method isBigNumber 2332 * @param {Object} 2333 * @return {Boolean} 2334 */ 2335 var isBigNumber = function (object) { 2336 return object instanceof BigNumber || 2337 (object && object.constructor && object.constructor.name === 'BigNumber'); 2338 }; 2339 2340 /** 2341 * Returns true if object is string, otherwise false 2342 * 2343 * @method isString 2344 * @param {Object} 2345 * @return {Boolean} 2346 */ 2347 var isString = function (object) { 2348 return typeof object === 'string' || 2349 (object && object.constructor && object.constructor.name === 'String'); 2350 }; 2351 2352 /** 2353 * Returns true if object is function, otherwise false 2354 * 2355 * @method isFunction 2356 * @param {Object} 2357 * @return {Boolean} 2358 */ 2359 var isFunction = function (object) { 2360 return typeof object === 'function'; 2361 }; 2362 2363 /** 2364 * Returns true if object is Objet, otherwise false 2365 * 2366 * @method isObject 2367 * @param {Object} 2368 * @return {Boolean} 2369 */ 2370 var isObject = function (object) { 2371 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2372 }; 2373 2374 /** 2375 * Returns true if object is boolean, otherwise false 2376 * 2377 * @method isBoolean 2378 * @param {Object} 2379 * @return {Boolean} 2380 */ 2381 var isBoolean = function (object) { 2382 return typeof object === 'boolean'; 2383 }; 2384 2385 /** 2386 * Returns true if object is array, otherwise false 2387 * 2388 * @method isArray 2389 * @param {Object} 2390 * @return {Boolean} 2391 */ 2392 var isArray = function (object) { 2393 return object instanceof Array; 2394 }; 2395 2396 /** 2397 * Returns true if given string is valid json object 2398 * 2399 * @method isJson 2400 * @param {String} 2401 * @return {Boolean} 2402 */ 2403 var isJson = function (str) { 2404 try { 2405 return !!JSON.parse(str); 2406 } catch (e) { 2407 return false; 2408 } 2409 }; 2410 2411 /** 2412 * Returns true if given string is a valid Ethereum block header bloom. 2413 * 2414 * @method isBloom 2415 * @param {String} hex encoded bloom filter 2416 * @return {Boolean} 2417 */ 2418 var isBloom = function (bloom) { 2419 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2420 return false; 2421 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2422 return true; 2423 } 2424 return false; 2425 }; 2426 2427 /** 2428 * Returns true if given string is a valid log topic. 2429 * 2430 * @method isTopic 2431 * @param {String} hex encoded topic 2432 * @return {Boolean} 2433 */ 2434 var isTopic = function (topic) { 2435 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2436 return false; 2437 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2438 return true; 2439 } 2440 return false; 2441 }; 2442 2443 module.exports = { 2444 padLeft: padLeft, 2445 padRight: padRight, 2446 toHex: toHex, 2447 toDecimal: toDecimal, 2448 fromDecimal: fromDecimal, 2449 toUtf8: toUtf8, 2450 toAscii: toAscii, 2451 fromUtf8: fromUtf8, 2452 fromAscii: fromAscii, 2453 transformToFullName: transformToFullName, 2454 extractDisplayName: extractDisplayName, 2455 extractTypeName: extractTypeName, 2456 toWei: toWei, 2457 fromWei: fromWei, 2458 toBigNumber: toBigNumber, 2459 toTwosComplement: toTwosComplement, 2460 toAddress: toAddress, 2461 isBigNumber: isBigNumber, 2462 isStrictAddress: isStrictAddress, 2463 isAddress: isAddress, 2464 isChecksumAddress: isChecksumAddress, 2465 toChecksumAddress: toChecksumAddress, 2466 isFunction: isFunction, 2467 isString: isString, 2468 isObject: isObject, 2469 isBoolean: isBoolean, 2470 isArray: isArray, 2471 isJson: isJson, 2472 isBloom: isBloom, 2473 isTopic: isTopic, 2474 }; 2475 2476 },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){ 2477 module.exports={ 2478 "version": "0.20.1" 2479 } 2480 2481 },{}],22:[function(require,module,exports){ 2482 /* 2483 This file is part of web3.js. 2484 2485 web3.js is free software: you can redistribute it and/or modify 2486 it under the terms of the GNU Lesser General Public License as published by 2487 the Free Software Foundation, either version 3 of the License, or 2488 (at your option) any later version. 2489 2490 web3.js is distributed in the hope that it will be useful, 2491 but WITHOUT ANY WARRANTY; without even the implied warranty of 2492 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2493 GNU Lesser General Public License for more details. 2494 2495 You should have received a copy of the GNU Lesser General Public License 2496 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2497 */ 2498 /** 2499 * @file web3.js 2500 * @authors: 2501 * Jeffrey Wilcke <jeff@ethdev.com> 2502 * Marek Kotewicz <marek@ethdev.com> 2503 * Marian Oancea <marian@ethdev.com> 2504 * Fabian Vogelsteller <fabian@ethdev.com> 2505 * Gav Wood <g@ethdev.com> 2506 * @date 2014 2507 */ 2508 2509 var RequestManager = require('./web3/requestmanager'); 2510 var Iban = require('./web3/iban'); 2511 var Eth = require('./web3/methods/eth'); 2512 var DB = require('./web3/methods/db'); 2513 var Shh = require('./web3/methods/shh'); 2514 var Net = require('./web3/methods/net'); 2515 var Personal = require('./web3/methods/personal'); 2516 var Swarm = require('./web3/methods/swarm'); 2517 var Settings = require('./web3/settings'); 2518 var version = require('./version.json'); 2519 var utils = require('./utils/utils'); 2520 var sha3 = require('./utils/sha3'); 2521 var extend = require('./web3/extend'); 2522 var Batch = require('./web3/batch'); 2523 var Property = require('./web3/property'); 2524 var HttpProvider = require('./web3/httpprovider'); 2525 var IpcProvider = require('./web3/ipcprovider'); 2526 var BigNumber = require('bignumber.js'); 2527 2528 2529 2530 function Web3 (provider) { 2531 this._requestManager = new RequestManager(provider); 2532 this.currentProvider = provider; 2533 this.eth = new Eth(this); 2534 this.db = new DB(this); 2535 this.shh = new Shh(this); 2536 this.net = new Net(this); 2537 this.personal = new Personal(this); 2538 this.bzz = new Swarm(this); 2539 this.settings = new Settings(); 2540 this.version = { 2541 api: version.version 2542 }; 2543 this.providers = { 2544 HttpProvider: HttpProvider, 2545 IpcProvider: IpcProvider 2546 }; 2547 this._extend = extend(this); 2548 this._extend({ 2549 properties: properties() 2550 }); 2551 } 2552 2553 // expose providers on the class 2554 Web3.providers = { 2555 HttpProvider: HttpProvider, 2556 IpcProvider: IpcProvider 2557 }; 2558 2559 Web3.prototype.setProvider = function (provider) { 2560 this._requestManager.setProvider(provider); 2561 this.currentProvider = provider; 2562 }; 2563 2564 Web3.prototype.reset = function (keepIsSyncing) { 2565 this._requestManager.reset(keepIsSyncing); 2566 this.settings = new Settings(); 2567 }; 2568 2569 Web3.prototype.BigNumber = BigNumber; 2570 Web3.prototype.toHex = utils.toHex; 2571 Web3.prototype.toAscii = utils.toAscii; 2572 Web3.prototype.toUtf8 = utils.toUtf8; 2573 Web3.prototype.fromAscii = utils.fromAscii; 2574 Web3.prototype.fromUtf8 = utils.fromUtf8; 2575 Web3.prototype.toDecimal = utils.toDecimal; 2576 Web3.prototype.fromDecimal = utils.fromDecimal; 2577 Web3.prototype.toBigNumber = utils.toBigNumber; 2578 Web3.prototype.toWei = utils.toWei; 2579 Web3.prototype.fromWei = utils.fromWei; 2580 Web3.prototype.isAddress = utils.isAddress; 2581 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2582 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2583 Web3.prototype.isIBAN = utils.isIBAN; 2584 Web3.prototype.padLeft = utils.padLeft; 2585 Web3.prototype.padRight = utils.padRight; 2586 2587 2588 Web3.prototype.sha3 = function(string, options) { 2589 return '0x' + sha3(string, options); 2590 }; 2591 2592 /** 2593 * Transforms direct icap to address 2594 */ 2595 Web3.prototype.fromICAP = function (icap) { 2596 var iban = new Iban(icap); 2597 return iban.address(); 2598 }; 2599 2600 var properties = function () { 2601 return [ 2602 new Property({ 2603 name: 'version.node', 2604 getter: 'web3_clientVersion' 2605 }), 2606 new Property({ 2607 name: 'version.network', 2608 getter: 'net_version', 2609 inputFormatter: utils.toDecimal 2610 }), 2611 new Property({ 2612 name: 'version.ethereum', 2613 getter: 'eth_protocolVersion', 2614 inputFormatter: utils.toDecimal 2615 }), 2616 new Property({ 2617 name: 'version.whisper', 2618 getter: 'shh_version', 2619 inputFormatter: utils.toDecimal 2620 }) 2621 ]; 2622 }; 2623 2624 Web3.prototype.isConnected = function(){ 2625 return (this.currentProvider && this.currentProvider.isConnected()); 2626 }; 2627 2628 Web3.prototype.createBatch = function () { 2629 return new Batch(this); 2630 }; 2631 2632 module.exports = Web3; 2633 2634 2635 },{"./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){ 2636 /* 2637 This file is part of web3.js. 2638 2639 web3.js is free software: you can redistribute it and/or modify 2640 it under the terms of the GNU Lesser General Public License as published by 2641 the Free Software Foundation, either version 3 of the License, or 2642 (at your option) any later version. 2643 2644 web3.js is distributed in the hope that it will be useful, 2645 but WITHOUT ANY WARRANTY; without even the implied warranty of 2646 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2647 GNU Lesser General Public License for more details. 2648 2649 You should have received a copy of the GNU Lesser General Public License 2650 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2651 */ 2652 /** 2653 * @file allevents.js 2654 * @author Marek Kotewicz <marek@ethdev.com> 2655 * @date 2014 2656 */ 2657 2658 var sha3 = require('../utils/sha3'); 2659 var SolidityEvent = require('./event'); 2660 var formatters = require('./formatters'); 2661 var utils = require('../utils/utils'); 2662 var Filter = require('./filter'); 2663 var watches = require('./methods/watches'); 2664 2665 var AllSolidityEvents = function (requestManager, json, address) { 2666 this._requestManager = requestManager; 2667 this._json = json; 2668 this._address = address; 2669 }; 2670 2671 AllSolidityEvents.prototype.encode = function (options) { 2672 options = options || {}; 2673 var result = {}; 2674 2675 ['fromBlock', 'toBlock'].filter(function (f) { 2676 return options[f] !== undefined; 2677 }).forEach(function (f) { 2678 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2679 }); 2680 2681 result.address = this._address; 2682 2683 return result; 2684 }; 2685 2686 AllSolidityEvents.prototype.decode = function (data) { 2687 data.data = data.data || ''; 2688 data.topics = data.topics || []; 2689 2690 var eventTopic = data.topics[0].slice(2); 2691 var match = this._json.filter(function (j) { 2692 return eventTopic === sha3(utils.transformToFullName(j)); 2693 })[0]; 2694 2695 if (!match) { // cannot find matching event? 2696 console.warn('cannot find event for log'); 2697 return data; 2698 } 2699 2700 var event = new SolidityEvent(this._requestManager, match, this._address); 2701 return event.decode(data); 2702 }; 2703 2704 AllSolidityEvents.prototype.execute = function (options, callback) { 2705 2706 if (utils.isFunction(arguments[arguments.length - 1])) { 2707 callback = arguments[arguments.length - 1]; 2708 if(arguments.length === 1) 2709 options = null; 2710 } 2711 2712 var o = this.encode(options); 2713 var formatter = this.decode.bind(this); 2714 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 2715 }; 2716 2717 AllSolidityEvents.prototype.attachToContract = function (contract) { 2718 var execute = this.execute.bind(this); 2719 contract.allEvents = execute; 2720 }; 2721 2722 module.exports = AllSolidityEvents; 2723 2724 2725 },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){ 2726 /* 2727 This file is part of web3.js. 2728 2729 web3.js is free software: you can redistribute it and/or modify 2730 it under the terms of the GNU Lesser General Public License as published by 2731 the Free Software Foundation, either version 3 of the License, or 2732 (at your option) any later version. 2733 2734 web3.js is distributed in the hope that it will be useful, 2735 but WITHOUT ANY WARRANTY; without even the implied warranty of 2736 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2737 GNU Lesser General Public License for more details. 2738 2739 You should have received a copy of the GNU Lesser General Public License 2740 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2741 */ 2742 /** 2743 * @file batch.js 2744 * @author Marek Kotewicz <marek@ethdev.com> 2745 * @date 2015 2746 */ 2747 2748 var Jsonrpc = require('./jsonrpc'); 2749 var errors = require('./errors'); 2750 2751 var Batch = function (web3) { 2752 this.requestManager = web3._requestManager; 2753 this.requests = []; 2754 }; 2755 2756 /** 2757 * Should be called to add create new request to batch request 2758 * 2759 * @method add 2760 * @param {Object} jsonrpc requet object 2761 */ 2762 Batch.prototype.add = function (request) { 2763 this.requests.push(request); 2764 }; 2765 2766 /** 2767 * Should be called to execute batch request 2768 * 2769 * @method execute 2770 */ 2771 Batch.prototype.execute = function () { 2772 var requests = this.requests; 2773 this.requestManager.sendBatch(requests, function (err, results) { 2774 results = results || []; 2775 requests.map(function (request, index) { 2776 return results[index] || {}; 2777 }).forEach(function (result, index) { 2778 if (requests[index].callback) { 2779 2780 if (!Jsonrpc.isValidResponse(result)) { 2781 return requests[index].callback(errors.InvalidResponse(result)); 2782 } 2783 2784 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2785 } 2786 }); 2787 }); 2788 }; 2789 2790 module.exports = Batch; 2791 2792 2793 },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){ 2794 /* 2795 This file is part of web3.js. 2796 2797 web3.js is free software: you can redistribute it and/or modify 2798 it under the terms of the GNU Lesser General Public License as published by 2799 the Free Software Foundation, either version 3 of the License, or 2800 (at your option) any later version. 2801 2802 web3.js is distributed in the hope that it will be useful, 2803 but WITHOUT ANY WARRANTY; without even the implied warranty of 2804 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2805 GNU Lesser General Public License for more details. 2806 2807 You should have received a copy of the GNU Lesser General Public License 2808 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2809 */ 2810 /** 2811 * @file contract.js 2812 * @author Marek Kotewicz <marek@ethdev.com> 2813 * @date 2014 2814 */ 2815 2816 var utils = require('../utils/utils'); 2817 var coder = require('../solidity/coder'); 2818 var SolidityEvent = require('./event'); 2819 var SolidityFunction = require('./function'); 2820 var AllEvents = require('./allevents'); 2821 2822 /** 2823 * Should be called to encode constructor params 2824 * 2825 * @method encodeConstructorParams 2826 * @param {Array} abi 2827 * @param {Array} constructor params 2828 */ 2829 var encodeConstructorParams = function (abi, params) { 2830 return abi.filter(function (json) { 2831 return json.type === 'constructor' && json.inputs.length === params.length; 2832 }).map(function (json) { 2833 return json.inputs.map(function (input) { 2834 return input.type; 2835 }); 2836 }).map(function (types) { 2837 return coder.encodeParams(types, params); 2838 })[0] || ''; 2839 }; 2840 2841 /** 2842 * Should be called to add functions to contract object 2843 * 2844 * @method addFunctionsToContract 2845 * @param {Contract} contract 2846 * @param {Array} abi 2847 */ 2848 var addFunctionsToContract = function (contract) { 2849 contract.abi.filter(function (json) { 2850 return json.type === 'function'; 2851 }).map(function (json) { 2852 return new SolidityFunction(contract._eth, json, contract.address); 2853 }).forEach(function (f) { 2854 f.attachToContract(contract); 2855 }); 2856 }; 2857 2858 /** 2859 * Should be called to add events to contract object 2860 * 2861 * @method addEventsToContract 2862 * @param {Contract} contract 2863 * @param {Array} abi 2864 */ 2865 var addEventsToContract = function (contract) { 2866 var events = contract.abi.filter(function (json) { 2867 return json.type === 'event'; 2868 }); 2869 2870 var All = new AllEvents(contract._eth._requestManager, events, contract.address); 2871 All.attachToContract(contract); 2872 2873 events.map(function (json) { 2874 return new SolidityEvent(contract._eth._requestManager, json, contract.address); 2875 }).forEach(function (e) { 2876 e.attachToContract(contract); 2877 }); 2878 }; 2879 2880 2881 /** 2882 * Should be called to check if the contract gets properly deployed on the blockchain. 2883 * 2884 * @method checkForContractAddress 2885 * @param {Object} contract 2886 * @param {Function} callback 2887 * @returns {Undefined} 2888 */ 2889 var checkForContractAddress = function(contract, callback){ 2890 var count = 0, 2891 callbackFired = false; 2892 2893 // wait for receipt 2894 var filter = contract._eth.filter('latest', function(e){ 2895 if (!e && !callbackFired) { 2896 count++; 2897 2898 // stop watching after 50 blocks (timeout) 2899 if (count > 50) { 2900 2901 filter.stopWatching(function() {}); 2902 callbackFired = true; 2903 2904 if (callback) 2905 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2906 else 2907 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2908 2909 2910 } else { 2911 2912 contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 2913 if(receipt && !callbackFired) { 2914 2915 contract._eth.getCode(receipt.contractAddress, function(e, code){ 2916 /*jshint maxcomplexity: 6 */ 2917 2918 if(callbackFired || !code) 2919 return; 2920 2921 filter.stopWatching(function() {}); 2922 callbackFired = true; 2923 2924 if(code.length > 3) { 2925 2926 // console.log('Contract code deployed!'); 2927 2928 contract.address = receipt.contractAddress; 2929 2930 // attach events and methods again after we have 2931 addFunctionsToContract(contract); 2932 addEventsToContract(contract); 2933 2934 // call callback for the second time 2935 if(callback) 2936 callback(null, contract); 2937 2938 } else { 2939 if(callback) 2940 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 2941 else 2942 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 2943 } 2944 }); 2945 } 2946 }); 2947 } 2948 } 2949 }); 2950 }; 2951 2952 /** 2953 * Should be called to create new ContractFactory instance 2954 * 2955 * @method ContractFactory 2956 * @param {Array} abi 2957 */ 2958 var ContractFactory = function (eth, abi) { 2959 this.eth = eth; 2960 this.abi = abi; 2961 2962 /** 2963 * Should be called to create new contract on a blockchain 2964 * 2965 * @method new 2966 * @param {Any} contract constructor param1 (optional) 2967 * @param {Any} contract constructor param2 (optional) 2968 * @param {Object} contract transaction object (required) 2969 * @param {Function} callback 2970 * @returns {Contract} returns contract instance 2971 */ 2972 this.new = function () { 2973 /*jshint maxcomplexity: 7 */ 2974 2975 var contract = new Contract(this.eth, this.abi); 2976 2977 // parse arguments 2978 var options = {}; // required! 2979 var callback; 2980 2981 var args = Array.prototype.slice.call(arguments); 2982 if (utils.isFunction(args[args.length - 1])) { 2983 callback = args.pop(); 2984 } 2985 2986 var last = args[args.length - 1]; 2987 if (utils.isObject(last) && !utils.isArray(last)) { 2988 options = args.pop(); 2989 } 2990 2991 if (options.value > 0) { 2992 var constructorAbi = abi.filter(function (json) { 2993 return json.type === 'constructor' && json.inputs.length === args.length; 2994 })[0] || {}; 2995 2996 if (!constructorAbi.payable) { 2997 throw new Error('Cannot send value to non-payable constructor'); 2998 } 2999 } 3000 3001 var bytes = encodeConstructorParams(this.abi, args); 3002 options.data += bytes; 3003 3004 if (callback) { 3005 3006 // wait for the contract address and check if the code was deployed 3007 this.eth.sendTransaction(options, function (err, hash) { 3008 if (err) { 3009 callback(err); 3010 } else { 3011 // add the transaction hash 3012 contract.transactionHash = hash; 3013 3014 // call callback for the first time 3015 callback(null, contract); 3016 3017 checkForContractAddress(contract, callback); 3018 } 3019 }); 3020 } else { 3021 var hash = this.eth.sendTransaction(options); 3022 // add the transaction hash 3023 contract.transactionHash = hash; 3024 checkForContractAddress(contract); 3025 } 3026 3027 return contract; 3028 }; 3029 3030 this.new.getData = this.getData.bind(this); 3031 }; 3032 3033 /** 3034 * Should be called to create new ContractFactory 3035 * 3036 * @method contract 3037 * @param {Array} abi 3038 * @returns {ContractFactory} new contract factory 3039 */ 3040 //var contract = function (abi) { 3041 //return new ContractFactory(abi); 3042 //}; 3043 3044 3045 3046 /** 3047 * Should be called to get access to existing contract on a blockchain 3048 * 3049 * @method at 3050 * @param {Address} contract address (required) 3051 * @param {Function} callback {optional) 3052 * @returns {Contract} returns contract if no callback was passed, 3053 * otherwise calls callback function (err, contract) 3054 */ 3055 ContractFactory.prototype.at = function (address, callback) { 3056 var contract = new Contract(this.eth, this.abi, address); 3057 3058 // this functions are not part of prototype, 3059 // because we don't want to spoil the interface 3060 addFunctionsToContract(contract); 3061 addEventsToContract(contract); 3062 3063 if (callback) { 3064 callback(null, contract); 3065 } 3066 return contract; 3067 }; 3068 3069 /** 3070 * Gets the data, which is data to deploy plus constructor params 3071 * 3072 * @method getData 3073 */ 3074 ContractFactory.prototype.getData = function () { 3075 var options = {}; // required! 3076 var args = Array.prototype.slice.call(arguments); 3077 3078 var last = args[args.length - 1]; 3079 if (utils.isObject(last) && !utils.isArray(last)) { 3080 options = args.pop(); 3081 } 3082 3083 var bytes = encodeConstructorParams(this.abi, args); 3084 options.data += bytes; 3085 3086 return options.data; 3087 }; 3088 3089 /** 3090 * Should be called to create new contract instance 3091 * 3092 * @method Contract 3093 * @param {Array} abi 3094 * @param {Address} contract address 3095 */ 3096 var Contract = function (eth, abi, address) { 3097 this._eth = eth; 3098 this.transactionHash = null; 3099 this.address = address; 3100 this.abi = abi; 3101 }; 3102 3103 module.exports = ContractFactory; 3104 3105 },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){ 3106 /* 3107 This file is part of web3.js. 3108 3109 web3.js is free software: you can redistribute it and/or modify 3110 it under the terms of the GNU Lesser General Public License as published by 3111 the Free Software Foundation, either version 3 of the License, or 3112 (at your option) any later version. 3113 3114 web3.js is distributed in the hope that it will be useful, 3115 but WITHOUT ANY WARRANTY; without even the implied warranty of 3116 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3117 GNU Lesser General Public License for more details. 3118 3119 You should have received a copy of the GNU Lesser General Public License 3120 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3121 */ 3122 /** 3123 * @file errors.js 3124 * @author Marek Kotewicz <marek@ethdev.com> 3125 * @date 2015 3126 */ 3127 3128 module.exports = { 3129 InvalidNumberOfSolidityArgs: function () { 3130 return new Error('Invalid number of arguments to Solidity function'); 3131 }, 3132 InvalidNumberOfRPCParams: function () { 3133 return new Error('Invalid number of input parameters to RPC method'); 3134 }, 3135 InvalidConnection: function (host){ 3136 return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 3137 }, 3138 InvalidProvider: function () { 3139 return new Error('Provider not set or invalid'); 3140 }, 3141 InvalidResponse: function (result){ 3142 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3143 return new Error(message); 3144 }, 3145 ConnectionTimeout: function (ms){ 3146 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3147 } 3148 }; 3149 3150 },{}],27:[function(require,module,exports){ 3151 /* 3152 This file is part of web3.js. 3153 3154 web3.js is free software: you can redistribute it and/or modify 3155 it under the terms of the GNU Lesser General Public License as published by 3156 the Free Software Foundation, either version 3 of the License, or 3157 (at your option) any later version. 3158 3159 web3.js is distributed in the hope that it will be useful, 3160 but WITHOUT ANY WARRANTY; without even the implied warranty of 3161 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3162 GNU Lesser General Public License for more details. 3163 3164 You should have received a copy of the GNU Lesser General Public License 3165 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3166 */ 3167 /** 3168 * @file event.js 3169 * @author Marek Kotewicz <marek@ethdev.com> 3170 * @date 2014 3171 */ 3172 3173 var utils = require('../utils/utils'); 3174 var coder = require('../solidity/coder'); 3175 var formatters = require('./formatters'); 3176 var sha3 = require('../utils/sha3'); 3177 var Filter = require('./filter'); 3178 var watches = require('./methods/watches'); 3179 3180 /** 3181 * This prototype should be used to create event filters 3182 */ 3183 var SolidityEvent = function (requestManager, json, address) { 3184 this._requestManager = requestManager; 3185 this._params = json.inputs; 3186 this._name = utils.transformToFullName(json); 3187 this._address = address; 3188 this._anonymous = json.anonymous; 3189 }; 3190 3191 /** 3192 * Should be used to get filtered param types 3193 * 3194 * @method types 3195 * @param {Bool} decide if returned typed should be indexed 3196 * @return {Array} array of types 3197 */ 3198 SolidityEvent.prototype.types = function (indexed) { 3199 return this._params.filter(function (i) { 3200 return i.indexed === indexed; 3201 }).map(function (i) { 3202 return i.type; 3203 }); 3204 }; 3205 3206 /** 3207 * Should be used to get event display name 3208 * 3209 * @method displayName 3210 * @return {String} event display name 3211 */ 3212 SolidityEvent.prototype.displayName = function () { 3213 return utils.extractDisplayName(this._name); 3214 }; 3215 3216 /** 3217 * Should be used to get event type name 3218 * 3219 * @method typeName 3220 * @return {String} event type name 3221 */ 3222 SolidityEvent.prototype.typeName = function () { 3223 return utils.extractTypeName(this._name); 3224 }; 3225 3226 /** 3227 * Should be used to get event signature 3228 * 3229 * @method signature 3230 * @return {String} event signature 3231 */ 3232 SolidityEvent.prototype.signature = function () { 3233 return sha3(this._name); 3234 }; 3235 3236 /** 3237 * Should be used to encode indexed params and options to one final object 3238 * 3239 * @method encode 3240 * @param {Object} indexed 3241 * @param {Object} options 3242 * @return {Object} everything combined together and encoded 3243 */ 3244 SolidityEvent.prototype.encode = function (indexed, options) { 3245 indexed = indexed || {}; 3246 options = options || {}; 3247 var result = {}; 3248 3249 ['fromBlock', 'toBlock'].filter(function (f) { 3250 return options[f] !== undefined; 3251 }).forEach(function (f) { 3252 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3253 }); 3254 3255 result.topics = []; 3256 3257 result.address = this._address; 3258 if (!this._anonymous) { 3259 result.topics.push('0x' + this.signature()); 3260 } 3261 3262 var indexedTopics = this._params.filter(function (i) { 3263 return i.indexed === true; 3264 }).map(function (i) { 3265 var value = indexed[i.name]; 3266 if (value === undefined || value === null) { 3267 return null; 3268 } 3269 3270 if (utils.isArray(value)) { 3271 return value.map(function (v) { 3272 return '0x' + coder.encodeParam(i.type, v); 3273 }); 3274 } 3275 return '0x' + coder.encodeParam(i.type, value); 3276 }); 3277 3278 result.topics = result.topics.concat(indexedTopics); 3279 3280 return result; 3281 }; 3282 3283 /** 3284 * Should be used to decode indexed params and options 3285 * 3286 * @method decode 3287 * @param {Object} data 3288 * @return {Object} result object with decoded indexed && not indexed params 3289 */ 3290 SolidityEvent.prototype.decode = function (data) { 3291 3292 data.data = data.data || ''; 3293 data.topics = data.topics || []; 3294 3295 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3296 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3297 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3298 3299 var notIndexedData = data.data.slice(2); 3300 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3301 3302 var result = formatters.outputLogFormatter(data); 3303 result.event = this.displayName(); 3304 result.address = data.address; 3305 3306 result.args = this._params.reduce(function (acc, current) { 3307 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3308 return acc; 3309 }, {}); 3310 3311 delete result.data; 3312 delete result.topics; 3313 3314 return result; 3315 }; 3316 3317 /** 3318 * Should be used to create new filter object from event 3319 * 3320 * @method execute 3321 * @param {Object} indexed 3322 * @param {Object} options 3323 * @return {Object} filter object 3324 */ 3325 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3326 3327 if (utils.isFunction(arguments[arguments.length - 1])) { 3328 callback = arguments[arguments.length - 1]; 3329 if(arguments.length === 2) 3330 options = null; 3331 if(arguments.length === 1) { 3332 options = null; 3333 indexed = {}; 3334 } 3335 } 3336 3337 var o = this.encode(indexed, options); 3338 var formatter = this.decode.bind(this); 3339 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 3340 }; 3341 3342 /** 3343 * Should be used to attach event to contract object 3344 * 3345 * @method attachToContract 3346 * @param {Contract} 3347 */ 3348 SolidityEvent.prototype.attachToContract = function (contract) { 3349 var execute = this.execute.bind(this); 3350 var displayName = this.displayName(); 3351 if (!contract[displayName]) { 3352 contract[displayName] = execute; 3353 } 3354 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3355 }; 3356 3357 module.exports = SolidityEvent; 3358 3359 3360 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){ 3361 var formatters = require('./formatters'); 3362 var utils = require('./../utils/utils'); 3363 var Method = require('./method'); 3364 var Property = require('./property'); 3365 3366 // TODO: refactor, so the input params are not altered. 3367 // it's necessary to make same 'extension' work with multiple providers 3368 var extend = function (web3) { 3369 /* jshint maxcomplexity:5 */ 3370 var ex = function (extension) { 3371 3372 var extendedObject; 3373 if (extension.property) { 3374 if (!web3[extension.property]) { 3375 web3[extension.property] = {}; 3376 } 3377 extendedObject = web3[extension.property]; 3378 } else { 3379 extendedObject = web3; 3380 } 3381 3382 if (extension.methods) { 3383 extension.methods.forEach(function (method) { 3384 method.attachToObject(extendedObject); 3385 method.setRequestManager(web3._requestManager); 3386 }); 3387 } 3388 3389 if (extension.properties) { 3390 extension.properties.forEach(function (property) { 3391 property.attachToObject(extendedObject); 3392 property.setRequestManager(web3._requestManager); 3393 }); 3394 } 3395 }; 3396 3397 ex.formatters = formatters; 3398 ex.utils = utils; 3399 ex.Method = Method; 3400 ex.Property = Property; 3401 3402 return ex; 3403 }; 3404 3405 3406 3407 module.exports = extend; 3408 3409 3410 },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){ 3411 /* 3412 This file is part of web3.js. 3413 3414 web3.js is free software: you can redistribute it and/or modify 3415 it under the terms of the GNU Lesser General Public License as published by 3416 the Free Software Foundation, either version 3 of the License, or 3417 (at your option) any later version. 3418 3419 web3.js is distributed in the hope that it will be useful, 3420 but WITHOUT ANY WARRANTY; without even the implied warranty of 3421 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3422 GNU Lesser General Public License for more details. 3423 3424 You should have received a copy of the GNU Lesser General Public License 3425 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3426 */ 3427 /** @file filter.js 3428 * @authors: 3429 * Jeffrey Wilcke <jeff@ethdev.com> 3430 * Marek Kotewicz <marek@ethdev.com> 3431 * Marian Oancea <marian@ethdev.com> 3432 * Fabian Vogelsteller <fabian@ethdev.com> 3433 * Gav Wood <g@ethdev.com> 3434 * @date 2014 3435 */ 3436 3437 var formatters = require('./formatters'); 3438 var utils = require('../utils/utils'); 3439 3440 /** 3441 * Converts a given topic to a hex string, but also allows null values. 3442 * 3443 * @param {Mixed} value 3444 * @return {String} 3445 */ 3446 var toTopic = function(value){ 3447 3448 if(value === null || typeof value === 'undefined') 3449 return null; 3450 3451 value = String(value); 3452 3453 if(value.indexOf('0x') === 0) 3454 return value; 3455 else 3456 return utils.fromUtf8(value); 3457 }; 3458 3459 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3460 /// @param should be string or object 3461 /// @returns options string or object 3462 var getOptions = function (options, type) { 3463 /*jshint maxcomplexity: 6 */ 3464 3465 if (utils.isString(options)) { 3466 return options; 3467 } 3468 3469 options = options || {}; 3470 3471 3472 switch(type) { 3473 case 'eth': 3474 3475 // make sure topics, get converted to hex 3476 options.topics = options.topics || []; 3477 options.topics = options.topics.map(function(topic){ 3478 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3479 }); 3480 3481 return { 3482 topics: options.topics, 3483 from: options.from, 3484 to: options.to, 3485 address: options.address, 3486 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3487 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3488 }; 3489 case 'shh': 3490 return options; 3491 } 3492 }; 3493 3494 /** 3495 Adds the callback and sets up the methods, to iterate over the results. 3496 3497 @method getLogsAtStart 3498 @param {Object} self 3499 @param {function} callback 3500 */ 3501 var getLogsAtStart = function(self, callback){ 3502 // call getFilterLogs for the first watch callback start 3503 if (!utils.isString(self.options)) { 3504 self.get(function (err, messages) { 3505 // don't send all the responses to all the watches again... just to self one 3506 if (err) { 3507 callback(err); 3508 } 3509 3510 if(utils.isArray(messages)) { 3511 messages.forEach(function (message) { 3512 callback(null, message); 3513 }); 3514 } 3515 }); 3516 } 3517 }; 3518 3519 /** 3520 Adds the callback and sets up the methods, to iterate over the results. 3521 3522 @method pollFilter 3523 @param {Object} self 3524 */ 3525 var pollFilter = function(self) { 3526 3527 var onMessage = function (error, messages) { 3528 if (error) { 3529 return self.callbacks.forEach(function (callback) { 3530 callback(error); 3531 }); 3532 } 3533 3534 if(utils.isArray(messages)) { 3535 messages.forEach(function (message) { 3536 message = self.formatter ? self.formatter(message) : message; 3537 self.callbacks.forEach(function (callback) { 3538 callback(null, message); 3539 }); 3540 }); 3541 } 3542 }; 3543 3544 self.requestManager.startPolling({ 3545 method: self.implementation.poll.call, 3546 params: [self.filterId], 3547 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3548 3549 }; 3550 3551 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3552 var self = this; 3553 var implementation = {}; 3554 methods.forEach(function (method) { 3555 method.setRequestManager(requestManager); 3556 method.attachToObject(implementation); 3557 }); 3558 this.requestManager = requestManager; 3559 this.options = getOptions(options, type); 3560 this.implementation = implementation; 3561 this.filterId = null; 3562 this.callbacks = []; 3563 this.getLogsCallbacks = []; 3564 this.pollFilters = []; 3565 this.formatter = formatter; 3566 this.implementation.newFilter(this.options, function(error, id){ 3567 if(error) { 3568 self.callbacks.forEach(function(cb){ 3569 cb(error); 3570 }); 3571 if (typeof filterCreationErrorCallback === 'function') { 3572 filterCreationErrorCallback(error); 3573 } 3574 } else { 3575 self.filterId = id; 3576 3577 // check if there are get pending callbacks as a consequence 3578 // of calling get() with filterId unassigned. 3579 self.getLogsCallbacks.forEach(function (cb){ 3580 self.get(cb); 3581 }); 3582 self.getLogsCallbacks = []; 3583 3584 // get filter logs for the already existing watch calls 3585 self.callbacks.forEach(function(cb){ 3586 getLogsAtStart(self, cb); 3587 }); 3588 if(self.callbacks.length > 0) 3589 pollFilter(self); 3590 3591 // start to watch immediately 3592 if(typeof callback === 'function') { 3593 return self.watch(callback); 3594 } 3595 } 3596 }); 3597 3598 return this; 3599 }; 3600 3601 Filter.prototype.watch = function (callback) { 3602 this.callbacks.push(callback); 3603 3604 if(this.filterId) { 3605 getLogsAtStart(this, callback); 3606 pollFilter(this); 3607 } 3608 3609 return this; 3610 }; 3611 3612 Filter.prototype.stopWatching = function (callback) { 3613 this.requestManager.stopPolling(this.filterId); 3614 this.callbacks = []; 3615 // remove filter async 3616 if (callback) { 3617 this.implementation.uninstallFilter(this.filterId, callback); 3618 } else { 3619 return this.implementation.uninstallFilter(this.filterId); 3620 } 3621 }; 3622 3623 Filter.prototype.get = function (callback) { 3624 var self = this; 3625 if (utils.isFunction(callback)) { 3626 if (this.filterId === null) { 3627 // If filterId is not set yet, call it back 3628 // when newFilter() assigns it. 3629 this.getLogsCallbacks.push(callback); 3630 } else { 3631 this.implementation.getLogs(this.filterId, function(err, res){ 3632 if (err) { 3633 callback(err); 3634 } else { 3635 callback(null, res.map(function (log) { 3636 return self.formatter ? self.formatter(log) : log; 3637 })); 3638 } 3639 }); 3640 } 3641 } else { 3642 if (this.filterId === null) { 3643 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3644 } 3645 var logs = this.implementation.getLogs(this.filterId); 3646 return logs.map(function (log) { 3647 return self.formatter ? self.formatter(log) : log; 3648 }); 3649 } 3650 3651 return this; 3652 }; 3653 3654 module.exports = Filter; 3655 3656 3657 },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){ 3658 'use strict' 3659 3660 /* 3661 This file is part of web3.js. 3662 3663 web3.js is free software: you can redistribute it and/or modify 3664 it under the terms of the GNU Lesser General Public License as published by 3665 the Free Software Foundation, either version 3 of the License, or 3666 (at your option) any later version. 3667 3668 web3.js is distributed in the hope that it will be useful, 3669 but WITHOUT ANY WARRANTY; without even the implied warranty of 3670 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3671 GNU Lesser General Public License for more details. 3672 3673 You should have received a copy of the GNU Lesser General Public License 3674 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3675 */ 3676 /** 3677 * @file formatters.js 3678 * @author Marek Kotewicz <marek@ethdev.com> 3679 * @author Fabian Vogelsteller <fabian@ethdev.com> 3680 * @date 2015 3681 */ 3682 3683 var utils = require('../utils/utils'); 3684 var config = require('../utils/config'); 3685 var Iban = require('./iban'); 3686 3687 /** 3688 * Should the format output to a big number 3689 * 3690 * @method outputBigNumberFormatter 3691 * @param {String|Number|BigNumber} 3692 * @returns {BigNumber} object 3693 */ 3694 var outputBigNumberFormatter = function (number) { 3695 return utils.toBigNumber(number); 3696 }; 3697 3698 var isPredefinedBlockNumber = function (blockNumber) { 3699 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3700 }; 3701 3702 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3703 if (blockNumber === undefined) { 3704 return config.defaultBlock; 3705 } 3706 return inputBlockNumberFormatter(blockNumber); 3707 }; 3708 3709 var inputBlockNumberFormatter = function (blockNumber) { 3710 if (blockNumber === undefined) { 3711 return undefined; 3712 } else if (isPredefinedBlockNumber(blockNumber)) { 3713 return blockNumber; 3714 } 3715 return utils.toHex(blockNumber); 3716 }; 3717 3718 var inputBigNumberFormatter = function (number) { 3719 return utils.toBigNumber(number); 3720 }; 3721 3722 /** 3723 * Formats the input of a transaction and converts all values to HEX 3724 * 3725 * @method inputCallFormatter 3726 * @param {Object} transaction options 3727 * @returns object 3728 */ 3729 var inputCallFormatter = function (options){ 3730 3731 options.from = options.from || config.defaultAccount; 3732 3733 if (options.from) { 3734 options.from = inputAddressFormatter(options.from); 3735 } 3736 3737 if (options.to) { // it might be contract creation 3738 options.to = inputAddressFormatter(options.to); 3739 } 3740 3741 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3742 return options[key] !== undefined; 3743 }).forEach(function(key){ 3744 options[key] = utils.fromDecimal(options[key]); 3745 }); 3746 3747 return options; 3748 }; 3749 3750 /** 3751 * Formats the input of a transaction and converts all values to HEX 3752 * 3753 * @method inputTransactionFormatter 3754 * @param {Object} transaction options 3755 * @returns object 3756 */ 3757 var inputTransactionFormatter = function (options){ 3758 3759 options.from = options.from || config.defaultAccount; 3760 options.from = inputAddressFormatter(options.from); 3761 3762 if (options.to) { // it might be contract creation 3763 options.to = inputAddressFormatter(options.to); 3764 } 3765 3766 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3767 return options[key] !== undefined; 3768 }).forEach(function(key){ 3769 options[key] = utils.fromDecimal(options[key]); 3770 }); 3771 3772 return options; 3773 }; 3774 3775 /** 3776 * Formats the output of a transaction to its proper values 3777 * 3778 * @method outputTransactionFormatter 3779 * @param {Object} tx 3780 * @returns {Object} 3781 */ 3782 var outputTransactionFormatter = function (tx){ 3783 if(tx.blockNumber !== null) 3784 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3785 if(tx.transactionIndex !== null) 3786 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3787 tx.nonce = utils.toDecimal(tx.nonce); 3788 tx.gas = utils.toDecimal(tx.gas); 3789 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3790 tx.value = utils.toBigNumber(tx.value); 3791 return tx; 3792 }; 3793 3794 /** 3795 * Formats the output of a transaction receipt to its proper values 3796 * 3797 * @method outputTransactionReceiptFormatter 3798 * @param {Object} receipt 3799 * @returns {Object} 3800 */ 3801 var outputTransactionReceiptFormatter = function (receipt){ 3802 if(receipt.blockNumber !== null) 3803 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3804 if(receipt.transactionIndex !== null) 3805 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3806 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3807 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3808 3809 if(utils.isArray(receipt.logs)) { 3810 receipt.logs = receipt.logs.map(function(log){ 3811 return outputLogFormatter(log); 3812 }); 3813 } 3814 3815 return receipt; 3816 }; 3817 3818 /** 3819 * Formats the output of a block to its proper values 3820 * 3821 * @method outputBlockFormatter 3822 * @param {Object} block 3823 * @returns {Object} 3824 */ 3825 var outputBlockFormatter = function(block) { 3826 3827 // transform to number 3828 block.gasLimit = utils.toDecimal(block.gasLimit); 3829 block.gasUsed = utils.toDecimal(block.gasUsed); 3830 block.size = utils.toDecimal(block.size); 3831 block.timestamp = utils.toDecimal(block.timestamp); 3832 if(block.number !== null) 3833 block.number = utils.toDecimal(block.number); 3834 3835 block.difficulty = utils.toBigNumber(block.difficulty); 3836 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3837 3838 if (utils.isArray(block.transactions)) { 3839 block.transactions.forEach(function(item){ 3840 if(!utils.isString(item)) 3841 return outputTransactionFormatter(item); 3842 }); 3843 } 3844 3845 return block; 3846 }; 3847 3848 3849 var outputBlocksFormatter = function(blocks) { 3850 // [{block, []receipts}]> 3851 if (utils.isArray(blocks)){ 3852 blocks.forEach(function(item){ 3853 item.block = outputBlockFormatter(item.block) 3854 item.receipts.forEach(function(receipt){ 3855 if(!utils.isString(receipt)) 3856 return outputTransactionReceiptFormatter(receipt) 3857 }); 3858 }); 3859 } 3860 return blocks; 3861 }; 3862 3863 /** 3864 * Formats the output of a log 3865 * 3866 * @method outputLogFormatter 3867 * @param {Object} log object 3868 * @returns {Object} log 3869 */ 3870 var outputLogFormatter = function(log) { 3871 if(log.blockNumber) 3872 log.blockNumber = utils.toDecimal(log.blockNumber); 3873 if(log.transactionIndex) 3874 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3875 if(log.logIndex) 3876 log.logIndex = utils.toDecimal(log.logIndex); 3877 3878 return log; 3879 }; 3880 3881 /** 3882 * Formats the input of a whisper post and converts all values to HEX 3883 * 3884 * @method inputPostFormatter 3885 * @param {Object} transaction object 3886 * @returns {Object} 3887 */ 3888 var inputPostFormatter = function(post) { 3889 3890 // post.payload = utils.toHex(post.payload); 3891 post.ttl = utils.fromDecimal(post.ttl); 3892 post.workToProve = utils.fromDecimal(post.workToProve); 3893 post.priority = utils.fromDecimal(post.priority); 3894 3895 // fallback 3896 if (!utils.isArray(post.topics)) { 3897 post.topics = post.topics ? [post.topics] : []; 3898 } 3899 3900 // format the following options 3901 post.topics = post.topics.map(function(topic){ 3902 // convert only if not hex 3903 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3904 }); 3905 3906 return post; 3907 }; 3908 3909 /** 3910 * Formats the output of a received post message 3911 * 3912 * @method outputPostFormatter 3913 * @param {Object} 3914 * @returns {Object} 3915 */ 3916 var outputPostFormatter = function(post){ 3917 3918 post.expiry = utils.toDecimal(post.expiry); 3919 post.sent = utils.toDecimal(post.sent); 3920 post.ttl = utils.toDecimal(post.ttl); 3921 post.workProved = utils.toDecimal(post.workProved); 3922 // post.payloadRaw = post.payload; 3923 // post.payload = utils.toAscii(post.payload); 3924 3925 // if (utils.isJson(post.payload)) { 3926 // post.payload = JSON.parse(post.payload); 3927 // } 3928 3929 // format the following options 3930 if (!post.topics) { 3931 post.topics = []; 3932 } 3933 post.topics = post.topics.map(function(topic){ 3934 return utils.toAscii(topic); 3935 }); 3936 3937 return post; 3938 }; 3939 3940 var inputAddressFormatter = function (address) { 3941 var iban = new Iban(address); 3942 if (iban.isValid() && iban.isDirect()) { 3943 return '0x' + iban.address(); 3944 } else if (utils.isStrictAddress(address)) { 3945 return address; 3946 } else if (utils.isAddress(address)) { 3947 return '0x' + address; 3948 } 3949 throw new Error('invalid address'); 3950 }; 3951 3952 3953 var outputSyncingFormatter = function(result) { 3954 if (!result) { 3955 return result; 3956 } 3957 3958 result.startingBlock = utils.toDecimal(result.startingBlock); 3959 result.currentBlock = utils.toDecimal(result.currentBlock); 3960 result.highestBlock = utils.toDecimal(result.highestBlock); 3961 if (result.knownStates) { 3962 result.knownStates = utils.toDecimal(result.knownStates); 3963 result.pulledStates = utils.toDecimal(result.pulledStates); 3964 } 3965 3966 return result; 3967 }; 3968 3969 module.exports = { 3970 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 3971 inputBlockNumberFormatter: inputBlockNumberFormatter, 3972 inputCallFormatter: inputCallFormatter, 3973 inputTransactionFormatter: inputTransactionFormatter, 3974 inputAddressFormatter: inputAddressFormatter, 3975 inputPostFormatter: inputPostFormatter, 3976 inputBigNumberFormatter: inputBigNumberFormatter, 3977 outputBigNumberFormatter: outputBigNumberFormatter, 3978 outputTransactionFormatter: outputTransactionFormatter, 3979 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 3980 outputBlockFormatter: outputBlockFormatter, 3981 outputBlocksFormatter: outputBlocksFormatter, 3982 outputLogFormatter: outputLogFormatter, 3983 outputPostFormatter: outputPostFormatter, 3984 outputSyncingFormatter: outputSyncingFormatter 3985 }; 3986 3987 3988 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 3989 /* 3990 This file is part of web3.js. 3991 3992 web3.js is free software: you can redistribute it and/or modify 3993 it under the terms of the GNU Lesser General Public License as published by 3994 the Free Software Foundation, either version 3 of the License, or 3995 (at your option) any later version. 3996 3997 web3.js is distributed in the hope that it will be useful, 3998 but WITHOUT ANY WARRANTY; without even the implied warranty of 3999 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4000 GNU Lesser General Public License for more details. 4001 4002 You should have received a copy of the GNU Lesser General Public License 4003 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4004 */ 4005 /** 4006 * @file function.js 4007 * @author Marek Kotewicz <marek@ethdev.com> 4008 * @date 2015 4009 */ 4010 4011 var coder = require('../solidity/coder'); 4012 var utils = require('../utils/utils'); 4013 var errors = require('./errors'); 4014 var formatters = require('./formatters'); 4015 var sha3 = require('../utils/sha3'); 4016 4017 /** 4018 * This prototype should be used to call/sendTransaction to solidity functions 4019 */ 4020 var SolidityFunction = function (eth, json, address) { 4021 this._eth = eth; 4022 this._inputTypes = json.inputs.map(function (i) { 4023 return i.type; 4024 }); 4025 this._outputTypes = json.outputs.map(function (i) { 4026 return i.type; 4027 }); 4028 this._constant = json.constant; 4029 this._payable = json.payable; 4030 this._name = utils.transformToFullName(json); 4031 this._address = address; 4032 }; 4033 4034 SolidityFunction.prototype.extractCallback = function (args) { 4035 if (utils.isFunction(args[args.length - 1])) { 4036 return args.pop(); // modify the args array! 4037 } 4038 }; 4039 4040 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4041 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4042 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4043 } 4044 }; 4045 4046 /** 4047 * Should be called to check if the number of arguments is correct 4048 * 4049 * @method validateArgs 4050 * @param {Array} arguments 4051 * @throws {Error} if it is not 4052 */ 4053 SolidityFunction.prototype.validateArgs = function (args) { 4054 var inputArgs = args.filter(function (a) { 4055 // filter the options object but not arguments that are arrays 4056 return !( (utils.isObject(a) === true) && 4057 (utils.isArray(a) === false) && 4058 (utils.isBigNumber(a) === false) 4059 ); 4060 }); 4061 if (inputArgs.length !== this._inputTypes.length) { 4062 throw errors.InvalidNumberOfSolidityArgs(); 4063 } 4064 }; 4065 4066 /** 4067 * Should be used to create payload from arguments 4068 * 4069 * @method toPayload 4070 * @param {Array} solidity function params 4071 * @param {Object} optional payload options 4072 */ 4073 SolidityFunction.prototype.toPayload = function (args) { 4074 var options = {}; 4075 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4076 options = args[args.length - 1]; 4077 } 4078 this.validateArgs(args); 4079 options.to = this._address; 4080 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4081 return options; 4082 }; 4083 4084 /** 4085 * Should be used to get function signature 4086 * 4087 * @method signature 4088 * @return {String} function signature 4089 */ 4090 SolidityFunction.prototype.signature = function () { 4091 return sha3(this._name).slice(0, 8); 4092 }; 4093 4094 4095 SolidityFunction.prototype.unpackOutput = function (output) { 4096 if (!output) { 4097 return; 4098 } 4099 4100 output = output.length >= 2 ? output.slice(2) : output; 4101 var result = coder.decodeParams(this._outputTypes, output); 4102 return result.length === 1 ? result[0] : result; 4103 }; 4104 4105 /** 4106 * Calls a contract function. 4107 * 4108 * @method call 4109 * @param {...Object} Contract function arguments 4110 * @param {function} If the last argument is a function, the contract function 4111 * call will be asynchronous, and the callback will be passed the 4112 * error and result. 4113 * @return {String} output bytes 4114 */ 4115 SolidityFunction.prototype.call = function () { 4116 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4117 var callback = this.extractCallback(args); 4118 var defaultBlock = this.extractDefaultBlock(args); 4119 var payload = this.toPayload(args); 4120 4121 4122 if (!callback) { 4123 var output = this._eth.call(payload, defaultBlock); 4124 return this.unpackOutput(output); 4125 } 4126 4127 var self = this; 4128 this._eth.call(payload, defaultBlock, function (error, output) { 4129 if (error) return callback(error, null); 4130 4131 var unpacked = null; 4132 try { 4133 unpacked = self.unpackOutput(output); 4134 } 4135 catch (e) { 4136 error = e; 4137 } 4138 4139 callback(error, unpacked); 4140 }); 4141 }; 4142 4143 /** 4144 * Should be used to sendTransaction to solidity function 4145 * 4146 * @method sendTransaction 4147 */ 4148 SolidityFunction.prototype.sendTransaction = function () { 4149 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4150 var callback = this.extractCallback(args); 4151 var payload = this.toPayload(args); 4152 4153 if (payload.value > 0 && !this._payable) { 4154 throw new Error('Cannot send value to non-payable function'); 4155 } 4156 4157 if (!callback) { 4158 return this._eth.sendTransaction(payload); 4159 } 4160 4161 this._eth.sendTransaction(payload, callback); 4162 }; 4163 4164 /** 4165 * Should be used to estimateGas of solidity function 4166 * 4167 * @method estimateGas 4168 */ 4169 SolidityFunction.prototype.estimateGas = function () { 4170 var args = Array.prototype.slice.call(arguments); 4171 var callback = this.extractCallback(args); 4172 var payload = this.toPayload(args); 4173 4174 if (!callback) { 4175 return this._eth.estimateGas(payload); 4176 } 4177 4178 this._eth.estimateGas(payload, callback); 4179 }; 4180 4181 /** 4182 * Return the encoded data of the call 4183 * 4184 * @method getData 4185 * @return {String} the encoded data 4186 */ 4187 SolidityFunction.prototype.getData = function () { 4188 var args = Array.prototype.slice.call(arguments); 4189 var payload = this.toPayload(args); 4190 4191 return payload.data; 4192 }; 4193 4194 /** 4195 * Should be used to get function display name 4196 * 4197 * @method displayName 4198 * @return {String} display name of the function 4199 */ 4200 SolidityFunction.prototype.displayName = function () { 4201 return utils.extractDisplayName(this._name); 4202 }; 4203 4204 /** 4205 * Should be used to get function type name 4206 * 4207 * @method typeName 4208 * @return {String} type name of the function 4209 */ 4210 SolidityFunction.prototype.typeName = function () { 4211 return utils.extractTypeName(this._name); 4212 }; 4213 4214 /** 4215 * Should be called to get rpc requests from solidity function 4216 * 4217 * @method request 4218 * @returns {Object} 4219 */ 4220 SolidityFunction.prototype.request = function () { 4221 var args = Array.prototype.slice.call(arguments); 4222 var callback = this.extractCallback(args); 4223 var payload = this.toPayload(args); 4224 var format = this.unpackOutput.bind(this); 4225 4226 return { 4227 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4228 callback: callback, 4229 params: [payload], 4230 format: format 4231 }; 4232 }; 4233 4234 /** 4235 * Should be called to execute function 4236 * 4237 * @method execute 4238 */ 4239 SolidityFunction.prototype.execute = function () { 4240 var transaction = !this._constant; 4241 4242 // send transaction 4243 if (transaction) { 4244 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4245 } 4246 4247 // call 4248 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4249 }; 4250 4251 /** 4252 * Should be called to attach function to contract 4253 * 4254 * @method attachToContract 4255 * @param {Contract} 4256 */ 4257 SolidityFunction.prototype.attachToContract = function (contract) { 4258 var execute = this.execute.bind(this); 4259 execute.request = this.request.bind(this); 4260 execute.call = this.call.bind(this); 4261 execute.sendTransaction = this.sendTransaction.bind(this); 4262 execute.estimateGas = this.estimateGas.bind(this); 4263 execute.getData = this.getData.bind(this); 4264 var displayName = this.displayName(); 4265 if (!contract[displayName]) { 4266 contract[displayName] = execute; 4267 } 4268 contract[displayName][this.typeName()] = execute; // circular!!!! 4269 }; 4270 4271 module.exports = SolidityFunction; 4272 4273 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4274 /* 4275 This file is part of web3.js. 4276 4277 web3.js is free software: you can redistribute it and/or modify 4278 it under the terms of the GNU Lesser General Public License as published by 4279 the Free Software Foundation, either version 3 of the License, or 4280 (at your option) any later version. 4281 4282 web3.js is distributed in the hope that it will be useful, 4283 but WITHOUT ANY WARRANTY; without even the implied warranty of 4284 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4285 GNU Lesser General Public License for more details. 4286 4287 You should have received a copy of the GNU Lesser General Public License 4288 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4289 */ 4290 /** @file httpprovider.js 4291 * @authors: 4292 * Marek Kotewicz <marek@ethdev.com> 4293 * Marian Oancea <marian@ethdev.com> 4294 * Fabian Vogelsteller <fabian@ethdev.com> 4295 * @date 2015 4296 */ 4297 4298 var errors = require('./errors'); 4299 4300 // workaround to use httpprovider in different envs 4301 4302 // browser 4303 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4304 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4305 // node 4306 } else { 4307 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4308 } 4309 4310 var XHR2 = require('xhr2'); // jshint ignore: line 4311 4312 /** 4313 * HttpProvider should be used to send rpc calls over http 4314 */ 4315 var HttpProvider = function (host, timeout, user, password) { 4316 this.host = host || 'http://localhost:8545'; 4317 this.timeout = timeout || 0; 4318 this.user = user; 4319 this.password = password; 4320 }; 4321 4322 /** 4323 * Should be called to prepare new XMLHttpRequest 4324 * 4325 * @method prepareRequest 4326 * @param {Boolean} true if request should be async 4327 * @return {XMLHttpRequest} object 4328 */ 4329 HttpProvider.prototype.prepareRequest = function (async) { 4330 var request; 4331 4332 if (async) { 4333 request = new XHR2(); 4334 request.timeout = this.timeout; 4335 } else { 4336 request = new XMLHttpRequest(); 4337 } 4338 4339 request.open('POST', this.host, async); 4340 if (this.user && this.password) { 4341 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4342 request.setRequestHeader('Authorization', auth); 4343 } request.setRequestHeader('Content-Type', 'application/json'); 4344 return request; 4345 }; 4346 4347 /** 4348 * Should be called to make sync request 4349 * 4350 * @method send 4351 * @param {Object} payload 4352 * @return {Object} result 4353 */ 4354 HttpProvider.prototype.send = function (payload) { 4355 var request = this.prepareRequest(false); 4356 4357 try { 4358 request.send(JSON.stringify(payload)); 4359 } catch (error) { 4360 throw errors.InvalidConnection(this.host); 4361 } 4362 4363 var result = request.responseText; 4364 4365 try { 4366 result = JSON.parse(result); 4367 } catch (e) { 4368 throw errors.InvalidResponse(request.responseText); 4369 } 4370 4371 return result; 4372 }; 4373 4374 /** 4375 * Should be used to make async request 4376 * 4377 * @method sendAsync 4378 * @param {Object} payload 4379 * @param {Function} callback triggered on end with (err, result) 4380 */ 4381 HttpProvider.prototype.sendAsync = function (payload, callback) { 4382 var request = this.prepareRequest(true); 4383 4384 request.onreadystatechange = function () { 4385 if (request.readyState === 4 && request.timeout !== 1) { 4386 var result = request.responseText; 4387 var error = null; 4388 4389 try { 4390 result = JSON.parse(result); 4391 } catch (e) { 4392 error = errors.InvalidResponse(request.responseText); 4393 } 4394 4395 callback(error, result); 4396 } 4397 }; 4398 4399 request.ontimeout = function () { 4400 callback(errors.ConnectionTimeout(this.timeout)); 4401 }; 4402 4403 try { 4404 request.send(JSON.stringify(payload)); 4405 } catch (error) { 4406 callback(errors.InvalidConnection(this.host)); 4407 } 4408 }; 4409 4410 /** 4411 * Synchronously tries to make Http request 4412 * 4413 * @method isConnected 4414 * @return {Boolean} returns true if request haven't failed. Otherwise false 4415 */ 4416 HttpProvider.prototype.isConnected = function () { 4417 try { 4418 this.send({ 4419 id: 9999999999, 4420 jsonrpc: '2.0', 4421 method: 'net_listening', 4422 params: [] 4423 }); 4424 return true; 4425 } catch (e) { 4426 return false; 4427 } 4428 }; 4429 4430 module.exports = HttpProvider; 4431 4432 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4433 /* 4434 This file is part of web3.js. 4435 4436 web3.js is free software: you can redistribute it and/or modify 4437 it under the terms of the GNU Lesser General Public License as published by 4438 the Free Software Foundation, either version 3 of the License, or 4439 (at your option) any later version. 4440 4441 web3.js is distributed in the hope that it will be useful, 4442 but WITHOUT ANY WARRANTY; without even the implied warranty of 4443 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4444 GNU Lesser General Public License for more details. 4445 4446 You should have received a copy of the GNU Lesser General Public License 4447 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4448 */ 4449 /** 4450 * @file iban.js 4451 * @author Marek Kotewicz <marek@ethdev.com> 4452 * @date 2015 4453 */ 4454 4455 var BigNumber = require('bignumber.js'); 4456 4457 var padLeft = function (string, bytes) { 4458 var result = string; 4459 while (result.length < bytes * 2) { 4460 result = '0' + result; 4461 } 4462 return result; 4463 }; 4464 4465 /** 4466 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4467 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4468 * 4469 * @method iso13616Prepare 4470 * @param {String} iban the IBAN 4471 * @returns {String} the prepared IBAN 4472 */ 4473 var iso13616Prepare = function (iban) { 4474 var A = 'A'.charCodeAt(0); 4475 var Z = 'Z'.charCodeAt(0); 4476 4477 iban = iban.toUpperCase(); 4478 iban = iban.substr(4) + iban.substr(0,4); 4479 4480 return iban.split('').map(function(n){ 4481 var code = n.charCodeAt(0); 4482 if (code >= A && code <= Z){ 4483 // A = 10, B = 11, ... Z = 35 4484 return code - A + 10; 4485 } else { 4486 return n; 4487 } 4488 }).join(''); 4489 }; 4490 4491 /** 4492 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4493 * 4494 * @method mod9710 4495 * @param {String} iban 4496 * @returns {Number} 4497 */ 4498 var mod9710 = function (iban) { 4499 var remainder = iban, 4500 block; 4501 4502 while (remainder.length > 2){ 4503 block = remainder.slice(0, 9); 4504 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4505 } 4506 4507 return parseInt(remainder, 10) % 97; 4508 }; 4509 4510 /** 4511 * This prototype should be used to create iban object from iban correct string 4512 * 4513 * @param {String} iban 4514 */ 4515 var Iban = function (iban) { 4516 this._iban = iban; 4517 }; 4518 4519 /** 4520 * This method should be used to create iban object from ethereum address 4521 * 4522 * @method fromAddress 4523 * @param {String} address 4524 * @return {Iban} the IBAN object 4525 */ 4526 Iban.fromAddress = function (address) { 4527 var asBn = new BigNumber(address, 16); 4528 var base36 = asBn.toString(36); 4529 var padded = padLeft(base36, 15); 4530 return Iban.fromBban(padded.toUpperCase()); 4531 }; 4532 4533 /** 4534 * Convert the passed BBAN to an IBAN for this country specification. 4535 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4536 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4537 * 4538 * @method fromBban 4539 * @param {String} bban the BBAN to convert to IBAN 4540 * @returns {Iban} the IBAN object 4541 */ 4542 Iban.fromBban = function (bban) { 4543 var countryCode = 'XE'; 4544 4545 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4546 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4547 4548 return new Iban(countryCode + checkDigit + bban); 4549 }; 4550 4551 /** 4552 * Should be used to create IBAN object for given institution and identifier 4553 * 4554 * @method createIndirect 4555 * @param {Object} options, required options are "institution" and "identifier" 4556 * @return {Iban} the IBAN object 4557 */ 4558 Iban.createIndirect = function (options) { 4559 return Iban.fromBban('ETH' + options.institution + options.identifier); 4560 }; 4561 4562 /** 4563 * Thos method should be used to check if given string is valid iban object 4564 * 4565 * @method isValid 4566 * @param {String} iban string 4567 * @return {Boolean} true if it is valid IBAN 4568 */ 4569 Iban.isValid = function (iban) { 4570 var i = new Iban(iban); 4571 return i.isValid(); 4572 }; 4573 4574 /** 4575 * Should be called to check if iban is correct 4576 * 4577 * @method isValid 4578 * @returns {Boolean} true if it is, otherwise false 4579 */ 4580 Iban.prototype.isValid = function () { 4581 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4582 mod9710(iso13616Prepare(this._iban)) === 1; 4583 }; 4584 4585 /** 4586 * Should be called to check if iban number is direct 4587 * 4588 * @method isDirect 4589 * @returns {Boolean} true if it is, otherwise false 4590 */ 4591 Iban.prototype.isDirect = function () { 4592 return this._iban.length === 34 || this._iban.length === 35; 4593 }; 4594 4595 /** 4596 * Should be called to check if iban number if indirect 4597 * 4598 * @method isIndirect 4599 * @returns {Boolean} true if it is, otherwise false 4600 */ 4601 Iban.prototype.isIndirect = function () { 4602 return this._iban.length === 20; 4603 }; 4604 4605 /** 4606 * Should be called to get iban checksum 4607 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4608 * 4609 * @method checksum 4610 * @returns {String} checksum 4611 */ 4612 Iban.prototype.checksum = function () { 4613 return this._iban.substr(2, 2); 4614 }; 4615 4616 /** 4617 * Should be called to get institution identifier 4618 * eg. XREG 4619 * 4620 * @method institution 4621 * @returns {String} institution identifier 4622 */ 4623 Iban.prototype.institution = function () { 4624 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4625 }; 4626 4627 /** 4628 * Should be called to get client identifier within institution 4629 * eg. GAVOFYORK 4630 * 4631 * @method client 4632 * @returns {String} client identifier 4633 */ 4634 Iban.prototype.client = function () { 4635 return this.isIndirect() ? this._iban.substr(11) : ''; 4636 }; 4637 4638 /** 4639 * Should be called to get client direct address 4640 * 4641 * @method address 4642 * @returns {String} client direct address 4643 */ 4644 Iban.prototype.address = function () { 4645 if (this.isDirect()) { 4646 var base36 = this._iban.substr(4); 4647 var asBn = new BigNumber(base36, 36); 4648 return padLeft(asBn.toString(16), 20); 4649 } 4650 4651 return ''; 4652 }; 4653 4654 Iban.prototype.toString = function () { 4655 return this._iban; 4656 }; 4657 4658 module.exports = Iban; 4659 4660 4661 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4662 /* 4663 This file is part of web3.js. 4664 4665 web3.js is free software: you can redistribute it and/or modify 4666 it under the terms of the GNU Lesser General Public License as published by 4667 the Free Software Foundation, either version 3 of the License, or 4668 (at your option) any later version. 4669 4670 web3.js is distributed in the hope that it will be useful, 4671 but WITHOUT ANY WARRANTY; without even the implied warranty of 4672 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4673 GNU Lesser General Public License for more details. 4674 4675 You should have received a copy of the GNU Lesser General Public License 4676 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4677 */ 4678 /** @file ipcprovider.js 4679 * @authors: 4680 * Fabian Vogelsteller <fabian@ethdev.com> 4681 * @date 2015 4682 */ 4683 4684 "use strict"; 4685 4686 var utils = require('../utils/utils'); 4687 var errors = require('./errors'); 4688 4689 4690 var IpcProvider = function (path, net) { 4691 var _this = this; 4692 this.responseCallbacks = {}; 4693 this.path = path; 4694 4695 this.connection = net.connect({path: this.path}); 4696 4697 this.connection.on('error', function(e){ 4698 console.error('IPC Connection Error', e); 4699 _this._timeout(); 4700 }); 4701 4702 this.connection.on('end', function(){ 4703 _this._timeout(); 4704 }); 4705 4706 4707 // LISTEN FOR CONNECTION RESPONSES 4708 this.connection.on('data', function(data) { 4709 /*jshint maxcomplexity: 6 */ 4710 4711 _this._parseResponse(data.toString()).forEach(function(result){ 4712 4713 var id = null; 4714 4715 // get the id which matches the returned id 4716 if(utils.isArray(result)) { 4717 result.forEach(function(load){ 4718 if(_this.responseCallbacks[load.id]) 4719 id = load.id; 4720 }); 4721 } else { 4722 id = result.id; 4723 } 4724 4725 // fire the callback 4726 if(_this.responseCallbacks[id]) { 4727 _this.responseCallbacks[id](null, result); 4728 delete _this.responseCallbacks[id]; 4729 } 4730 }); 4731 }); 4732 }; 4733 4734 /** 4735 Will parse the response and make an array out of it. 4736 4737 @method _parseResponse 4738 @param {String} data 4739 */ 4740 IpcProvider.prototype._parseResponse = function(data) { 4741 var _this = this, 4742 returnValues = []; 4743 4744 // DE-CHUNKER 4745 var dechunkedData = data 4746 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4747 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4748 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4749 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4750 .split('|--|'); 4751 4752 dechunkedData.forEach(function(data){ 4753 4754 // prepend the last chunk 4755 if(_this.lastChunk) 4756 data = _this.lastChunk + data; 4757 4758 var result = null; 4759 4760 try { 4761 result = JSON.parse(data); 4762 4763 } catch(e) { 4764 4765 _this.lastChunk = data; 4766 4767 // start timeout to cancel all requests 4768 clearTimeout(_this.lastChunkTimeout); 4769 _this.lastChunkTimeout = setTimeout(function(){ 4770 _this._timeout(); 4771 throw errors.InvalidResponse(data); 4772 }, 1000 * 15); 4773 4774 return; 4775 } 4776 4777 // cancel timeout and set chunk to null 4778 clearTimeout(_this.lastChunkTimeout); 4779 _this.lastChunk = null; 4780 4781 if(result) 4782 returnValues.push(result); 4783 }); 4784 4785 return returnValues; 4786 }; 4787 4788 4789 /** 4790 Get the adds a callback to the responseCallbacks object, 4791 which will be called if a response matching the response Id will arrive. 4792 4793 @method _addResponseCallback 4794 */ 4795 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4796 var id = payload.id || payload[0].id; 4797 var method = payload.method || payload[0].method; 4798 4799 this.responseCallbacks[id] = callback; 4800 this.responseCallbacks[id].method = method; 4801 }; 4802 4803 /** 4804 Timeout all requests when the end/error event is fired 4805 4806 @method _timeout 4807 */ 4808 IpcProvider.prototype._timeout = function() { 4809 for(var key in this.responseCallbacks) { 4810 if(this.responseCallbacks.hasOwnProperty(key)){ 4811 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4812 delete this.responseCallbacks[key]; 4813 } 4814 } 4815 }; 4816 4817 4818 /** 4819 Check if the current connection is still valid. 4820 4821 @method isConnected 4822 */ 4823 IpcProvider.prototype.isConnected = function() { 4824 var _this = this; 4825 4826 // try reconnect, when connection is gone 4827 if(!_this.connection.writable) 4828 _this.connection.connect({path: _this.path}); 4829 4830 return !!this.connection.writable; 4831 }; 4832 4833 IpcProvider.prototype.send = function (payload) { 4834 4835 if(this.connection.writeSync) { 4836 var result; 4837 4838 // try reconnect, when connection is gone 4839 if(!this.connection.writable) 4840 this.connection.connect({path: this.path}); 4841 4842 var data = this.connection.writeSync(JSON.stringify(payload)); 4843 4844 try { 4845 result = JSON.parse(data); 4846 } catch(e) { 4847 throw errors.InvalidResponse(data); 4848 } 4849 4850 return result; 4851 4852 } else { 4853 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4854 } 4855 }; 4856 4857 IpcProvider.prototype.sendAsync = function (payload, callback) { 4858 // try reconnect, when connection is gone 4859 if(!this.connection.writable) 4860 this.connection.connect({path: this.path}); 4861 4862 4863 this.connection.write(JSON.stringify(payload)); 4864 this._addResponseCallback(payload, callback); 4865 }; 4866 4867 module.exports = IpcProvider; 4868 4869 4870 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 4871 /* 4872 This file is part of web3.js. 4873 4874 web3.js is free software: you can redistribute it and/or modify 4875 it under the terms of the GNU Lesser General Public License as published by 4876 the Free Software Foundation, either version 3 of the License, or 4877 (at your option) any later version. 4878 4879 web3.js is distributed in the hope that it will be useful, 4880 but WITHOUT ANY WARRANTY; without even the implied warranty of 4881 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4882 GNU Lesser General Public License for more details. 4883 4884 You should have received a copy of the GNU Lesser General Public License 4885 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4886 */ 4887 /** @file jsonrpc.js 4888 * @authors: 4889 * Marek Kotewicz <marek@ethdev.com> 4890 * Aaron Kumavis <aaron@kumavis.me> 4891 * @date 2015 4892 */ 4893 4894 // Initialize Jsonrpc as a simple object with utility functions. 4895 var Jsonrpc = { 4896 messageId: 0 4897 }; 4898 4899 /** 4900 * Should be called to valid json create payload object 4901 * 4902 * @method toPayload 4903 * @param {Function} method of jsonrpc call, required 4904 * @param {Array} params, an array of method params, optional 4905 * @returns {Object} valid jsonrpc payload object 4906 */ 4907 Jsonrpc.toPayload = function (method, params) { 4908 if (!method) 4909 console.error('jsonrpc method should be specified!'); 4910 4911 // advance message ID 4912 Jsonrpc.messageId++; 4913 4914 return { 4915 jsonrpc: '2.0', 4916 id: Jsonrpc.messageId, 4917 method: method, 4918 params: params || [] 4919 }; 4920 }; 4921 4922 /** 4923 * Should be called to check if jsonrpc response is valid 4924 * 4925 * @method isValidResponse 4926 * @param {Object} 4927 * @returns {Boolean} true if response is valid, otherwise false 4928 */ 4929 Jsonrpc.isValidResponse = function (response) { 4930 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4931 4932 function validateSingleMessage(message){ 4933 return !!message && 4934 !message.error && 4935 message.jsonrpc === '2.0' && 4936 typeof message.id === 'number' && 4937 message.result !== undefined; // only undefined is not valid json object 4938 } 4939 }; 4940 4941 /** 4942 * Should be called to create batch payload object 4943 * 4944 * @method toBatchPayload 4945 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4946 * @returns {Array} batch payload 4947 */ 4948 Jsonrpc.toBatchPayload = function (messages) { 4949 return messages.map(function (message) { 4950 return Jsonrpc.toPayload(message.method, message.params); 4951 }); 4952 }; 4953 4954 module.exports = Jsonrpc; 4955 4956 4957 },{}],36:[function(require,module,exports){ 4958 /* 4959 This file is part of web3.js. 4960 4961 web3.js is free software: you can redistribute it and/or modify 4962 it under the terms of the GNU Lesser General Public License as published by 4963 the Free Software Foundation, either version 3 of the License, or 4964 (at your option) any later version. 4965 4966 web3.js is distributed in the hope that it will be useful, 4967 but WITHOUT ANY WARRANTY; without even the implied warranty of 4968 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4969 GNU Lesser General Public License for more details. 4970 4971 You should have received a copy of the GNU Lesser General Public License 4972 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4973 */ 4974 /** 4975 * @file method.js 4976 * @author Marek Kotewicz <marek@ethdev.com> 4977 * @date 2015 4978 */ 4979 4980 var utils = require('../utils/utils'); 4981 var errors = require('./errors'); 4982 4983 var Method = function (options) { 4984 this.name = options.name; 4985 this.call = options.call; 4986 this.params = options.params || 0; 4987 this.inputFormatter = options.inputFormatter; 4988 this.outputFormatter = options.outputFormatter; 4989 this.requestManager = null; 4990 }; 4991 4992 Method.prototype.setRequestManager = function (rm) { 4993 this.requestManager = rm; 4994 }; 4995 4996 /** 4997 * Should be used to determine name of the jsonrpc method based on arguments 4998 * 4999 * @method getCall 5000 * @param {Array} arguments 5001 * @return {String} name of jsonrpc method 5002 */ 5003 Method.prototype.getCall = function (args) { 5004 return utils.isFunction(this.call) ? this.call(args) : this.call; 5005 }; 5006 5007 /** 5008 * Should be used to extract callback from array of arguments. Modifies input param 5009 * 5010 * @method extractCallback 5011 * @param {Array} arguments 5012 * @return {Function|Null} callback, if exists 5013 */ 5014 Method.prototype.extractCallback = function (args) { 5015 if (utils.isFunction(args[args.length - 1])) { 5016 return args.pop(); // modify the args array! 5017 } 5018 }; 5019 5020 /** 5021 * Should be called to check if the number of arguments is correct 5022 * 5023 * @method validateArgs 5024 * @param {Array} arguments 5025 * @throws {Error} if it is not 5026 */ 5027 Method.prototype.validateArgs = function (args) { 5028 if (args.length !== this.params) { 5029 throw errors.InvalidNumberOfRPCParams(); 5030 } 5031 }; 5032 5033 /** 5034 * Should be called to format input args of method 5035 * 5036 * @method formatInput 5037 * @param {Array} 5038 * @return {Array} 5039 */ 5040 Method.prototype.formatInput = function (args) { 5041 if (!this.inputFormatter) { 5042 return args; 5043 } 5044 5045 return this.inputFormatter.map(function (formatter, index) { 5046 return formatter ? formatter(args[index]) : args[index]; 5047 }); 5048 }; 5049 5050 /** 5051 * Should be called to format output(result) of method 5052 * 5053 * @method formatOutput 5054 * @param {Object} 5055 * @return {Object} 5056 */ 5057 Method.prototype.formatOutput = function (result) { 5058 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5059 }; 5060 5061 /** 5062 * Should create payload from given input args 5063 * 5064 * @method toPayload 5065 * @param {Array} args 5066 * @return {Object} 5067 */ 5068 Method.prototype.toPayload = function (args) { 5069 var call = this.getCall(args); 5070 var callback = this.extractCallback(args); 5071 var params = this.formatInput(args); 5072 this.validateArgs(params); 5073 5074 return { 5075 method: call, 5076 params: params, 5077 callback: callback 5078 }; 5079 }; 5080 5081 Method.prototype.attachToObject = function (obj) { 5082 var func = this.buildCall(); 5083 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5084 var name = this.name.split('.'); 5085 if (name.length > 1) { 5086 obj[name[0]] = obj[name[0]] || {}; 5087 obj[name[0]][name[1]] = func; 5088 } else { 5089 obj[name[0]] = func; 5090 } 5091 }; 5092 5093 Method.prototype.buildCall = function() { 5094 var method = this; 5095 var send = function () { 5096 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5097 if (payload.callback) { 5098 return method.requestManager.sendAsync(payload, function (err, result) { 5099 payload.callback(err, method.formatOutput(result)); 5100 }); 5101 } 5102 return method.formatOutput(method.requestManager.send(payload)); 5103 }; 5104 send.request = this.request.bind(this); 5105 return send; 5106 }; 5107 5108 /** 5109 * Should be called to create pure JSONRPC request which can be used in batch request 5110 * 5111 * @method request 5112 * @param {...} params 5113 * @return {Object} jsonrpc request 5114 */ 5115 Method.prototype.request = function () { 5116 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5117 payload.format = this.formatOutput.bind(this); 5118 return payload; 5119 }; 5120 5121 module.exports = Method; 5122 5123 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5124 /* 5125 This file is part of web3.js. 5126 5127 web3.js is free software: you can redistribute it and/or modify 5128 it under the terms of the GNU Lesser General Public License as published by 5129 the Free Software Foundation, either version 3 of the License, or 5130 (at your option) any later version. 5131 5132 web3.js is distributed in the hope that it will be useful, 5133 but WITHOUT ANY WARRANTY; without even the implied warranty of 5134 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5135 GNU Lesser General Public License for more details. 5136 5137 You should have received a copy of the GNU Lesser General Public License 5138 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5139 */ 5140 /** @file db.js 5141 * @authors: 5142 * Marek Kotewicz <marek@ethdev.com> 5143 * @date 2015 5144 */ 5145 5146 var Method = require('../method'); 5147 5148 var DB = function (web3) { 5149 this._requestManager = web3._requestManager; 5150 5151 var self = this; 5152 5153 methods().forEach(function(method) { 5154 method.attachToObject(self); 5155 method.setRequestManager(web3._requestManager); 5156 }); 5157 }; 5158 5159 var methods = function () { 5160 var putString = new Method({ 5161 name: 'putString', 5162 call: 'db_putString', 5163 params: 3 5164 }); 5165 5166 var getString = new Method({ 5167 name: 'getString', 5168 call: 'db_getString', 5169 params: 2 5170 }); 5171 5172 var putHex = new Method({ 5173 name: 'putHex', 5174 call: 'db_putHex', 5175 params: 3 5176 }); 5177 5178 var getHex = new Method({ 5179 name: 'getHex', 5180 call: 'db_getHex', 5181 params: 2 5182 }); 5183 5184 return [ 5185 putString, getString, putHex, getHex 5186 ]; 5187 }; 5188 5189 module.exports = DB; 5190 5191 },{"../method":36}],38:[function(require,module,exports){ 5192 /* 5193 This file is part of web3.js. 5194 5195 web3.js is free software: you can redistribute it and/or modify 5196 it under the terms of the GNU Lesser General Public License as published by 5197 the Free Software Foundation, either version 3 of the License, or 5198 (at your option) any later version. 5199 5200 web3.js is distributed in the hope that it will be useful, 5201 but WITHOUT ANY WARRANTY; without even the implied warranty of 5202 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5203 GNU Lesser General Public License for more details. 5204 5205 You should have received a copy of the GNU Lesser General Public License 5206 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5207 */ 5208 /** 5209 * @file eth.js 5210 * @author Marek Kotewicz <marek@ethdev.com> 5211 * @author Fabian Vogelsteller <fabian@ethdev.com> 5212 * @date 2015 5213 */ 5214 5215 "use strict"; 5216 5217 var formatters = require('../formatters'); 5218 var utils = require('../../utils/utils'); 5219 var Method = require('../method'); 5220 var Property = require('../property'); 5221 var c = require('../../utils/config'); 5222 var Contract = require('../contract'); 5223 var watches = require('./watches'); 5224 var Filter = require('../filter'); 5225 var IsSyncing = require('../syncing'); 5226 var namereg = require('../namereg'); 5227 var Iban = require('../iban'); 5228 var transfer = require('../transfer'); 5229 5230 var blockCall = function (args) { 5231 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; 5232 }; 5233 5234 var transactionFromBlockCall = function (args) { 5235 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5236 }; 5237 5238 var uncleCall = function (args) { 5239 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5240 }; 5241 5242 var getBlockTransactionCountCall = function (args) { 5243 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5244 }; 5245 5246 var uncleCountCall = function (args) { 5247 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5248 }; 5249 5250 function Eth(web3) { 5251 this._requestManager = web3._requestManager; 5252 5253 var self = this; 5254 5255 methods().forEach(function(method) { 5256 method.attachToObject(self); 5257 method.setRequestManager(self._requestManager); 5258 }); 5259 5260 properties().forEach(function(p) { 5261 p.attachToObject(self); 5262 p.setRequestManager(self._requestManager); 5263 }); 5264 5265 5266 this.iban = Iban; 5267 this.sendIBANTransaction = transfer.bind(null, this); 5268 } 5269 5270 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5271 get: function () { 5272 return c.defaultBlock; 5273 }, 5274 set: function (val) { 5275 c.defaultBlock = val; 5276 return val; 5277 } 5278 }); 5279 5280 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5281 get: function () { 5282 return c.defaultAccount; 5283 }, 5284 set: function (val) { 5285 c.defaultAccount = val; 5286 return val; 5287 } 5288 }); 5289 5290 var methods = function () { 5291 var getBalance = new Method({ 5292 name: 'getBalance', 5293 call: 'eth_getBalance', 5294 params: 2, 5295 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5296 outputFormatter: formatters.outputBigNumberFormatter 5297 }); 5298 5299 var getStorageAt = new Method({ 5300 name: 'getStorageAt', 5301 call: 'eth_getStorageAt', 5302 params: 3, 5303 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5304 }); 5305 5306 var getCode = new Method({ 5307 name: 'getCode', 5308 call: 'eth_getCode', 5309 params: 2, 5310 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5311 }); 5312 5313 var getBlock = new Method({ 5314 name: 'getBlock', 5315 call: blockCall, 5316 params: 2, 5317 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5318 outputFormatter: formatters.outputBlockFormatter 5319 }); 5320 5321 var getUncle = new Method({ 5322 name: 'getUncle', 5323 call: uncleCall, 5324 params: 2, 5325 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5326 outputFormatter: formatters.outputBlockFormatter, 5327 5328 }); 5329 5330 var getCompilers = new Method({ 5331 name: 'getCompilers', 5332 call: 'eth_getCompilers', 5333 params: 0 5334 }); 5335 5336 var getBlockTransactionCount = new Method({ 5337 name: 'getBlockTransactionCount', 5338 call: getBlockTransactionCountCall, 5339 params: 1, 5340 inputFormatter: [formatters.inputBlockNumberFormatter], 5341 outputFormatter: utils.toDecimal 5342 }); 5343 5344 var getBlockUncleCount = new Method({ 5345 name: 'getBlockUncleCount', 5346 call: uncleCountCall, 5347 params: 1, 5348 inputFormatter: [formatters.inputBlockNumberFormatter], 5349 outputFormatter: utils.toDecimal 5350 }); 5351 5352 var getTransaction = new Method({ 5353 name: 'getTransaction', 5354 call: 'eth_getTransactionByHash', 5355 params: 1, 5356 outputFormatter: formatters.outputTransactionFormatter 5357 }); 5358 5359 var getTransactionFromBlock = new Method({ 5360 name: 'getTransactionFromBlock', 5361 call: transactionFromBlockCall, 5362 params: 2, 5363 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5364 outputFormatter: formatters.outputTransactionFormatter 5365 }); 5366 5367 var getTransactionReceipt = new Method({ 5368 name: 'getTransactionReceipt', 5369 call: 'eth_getTransactionReceipt', 5370 params: 1, 5371 outputFormatter: formatters.outputTransactionReceiptFormatter 5372 }); 5373 5374 var getTransactionCount = new Method({ 5375 name: 'getTransactionCount', 5376 call: 'eth_getTransactionCount', 5377 params: 2, 5378 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5379 outputFormatter: utils.toDecimal 5380 }); 5381 5382 var sendRawTransaction = new Method({ 5383 name: 'sendRawTransaction', 5384 call: 'eth_sendRawTransaction', 5385 params: 1, 5386 inputFormatter: [null] 5387 }); 5388 5389 var sendTransaction = new Method({ 5390 name: 'sendTransaction', 5391 call: 'eth_sendTransaction', 5392 params: 1, 5393 inputFormatter: [formatters.inputTransactionFormatter] 5394 }); 5395 5396 var signTransaction = new Method({ 5397 name: 'signTransaction', 5398 call: 'eth_signTransaction', 5399 params: 1, 5400 inputFormatter: [formatters.inputTransactionFormatter] 5401 }); 5402 5403 var sign = new Method({ 5404 name: 'sign', 5405 call: 'eth_sign', 5406 params: 2, 5407 inputFormatter: [formatters.inputAddressFormatter, null] 5408 }); 5409 5410 var call = new Method({ 5411 name: 'call', 5412 call: 'eth_call', 5413 params: 2, 5414 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5415 }); 5416 5417 var estimateGas = new Method({ 5418 name: 'estimateGas', 5419 call: 'eth_estimateGas', 5420 params: 1, 5421 inputFormatter: [formatters.inputCallFormatter], 5422 outputFormatter: utils.toDecimal 5423 }); 5424 5425 var compileSolidity = new Method({ 5426 name: 'compile.solidity', 5427 call: 'eth_compileSolidity', 5428 params: 1 5429 }); 5430 5431 var compileLLL = new Method({ 5432 name: 'compile.lll', 5433 call: 'eth_compileLLL', 5434 params: 1 5435 }); 5436 5437 var compileSerpent = new Method({ 5438 name: 'compile.serpent', 5439 call: 'eth_compileSerpent', 5440 params: 1 5441 }); 5442 5443 var submitWork = new Method({ 5444 name: 'submitWork', 5445 call: 'eth_submitWork', 5446 params: 3 5447 }); 5448 5449 var getWork = new Method({ 5450 name: 'getWork', 5451 call: 'eth_getWork', 5452 params: 0 5453 }); 5454 5455 return [ 5456 getBalance, 5457 getStorageAt, 5458 getCode, 5459 getBlock, 5460 getUncle, 5461 getCompilers, 5462 getBlockTransactionCount, 5463 getBlockUncleCount, 5464 getTransaction, 5465 getTransactionFromBlock, 5466 getTransactionReceipt, 5467 getTransactionCount, 5468 call, 5469 estimateGas, 5470 sendRawTransaction, 5471 signTransaction, 5472 sendTransaction, 5473 sign, 5474 compileSolidity, 5475 compileLLL, 5476 compileSerpent, 5477 submitWork, 5478 getWork 5479 ]; 5480 }; 5481 5482 5483 var properties = function () { 5484 return [ 5485 new Property({ 5486 name: 'coinbase', 5487 getter: 'eth_coinbase' 5488 }), 5489 new Property({ 5490 name: 'mining', 5491 getter: 'eth_mining' 5492 }), 5493 new Property({ 5494 name: 'hashrate', 5495 getter: 'eth_hashrate', 5496 outputFormatter: utils.toDecimal 5497 }), 5498 new Property({ 5499 name: 'syncing', 5500 getter: 'eth_syncing', 5501 outputFormatter: formatters.outputSyncingFormatter 5502 }), 5503 new Property({ 5504 name: 'gasPrice', 5505 getter: 'eth_gasPrice', 5506 outputFormatter: formatters.outputBigNumberFormatter 5507 }), 5508 new Property({ 5509 name: 'accounts', 5510 getter: 'eth_accounts' 5511 }), 5512 new Property({ 5513 name: 'blockNumber', 5514 getter: 'eth_blockNumber', 5515 outputFormatter: utils.toDecimal 5516 }), 5517 new Property({ 5518 name: 'protocolVersion', 5519 getter: 'eth_protocolVersion' 5520 }) 5521 ]; 5522 }; 5523 5524 Eth.prototype.contract = function (abi) { 5525 var factory = new Contract(this, abi); 5526 return factory; 5527 }; 5528 5529 Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5530 return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5531 }; 5532 5533 Eth.prototype.namereg = function () { 5534 return this.contract(namereg.global.abi).at(namereg.global.address); 5535 }; 5536 5537 Eth.prototype.icapNamereg = function () { 5538 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5539 }; 5540 5541 Eth.prototype.isSyncing = function (callback) { 5542 return new IsSyncing(this._requestManager, callback); 5543 }; 5544 5545 module.exports = Eth; 5546 5547 },{"../../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){ 5548 /* 5549 This file is part of web3.js. 5550 5551 web3.js is free software: you can redistribute it and/or modify 5552 it under the terms of the GNU Lesser General Public License as published by 5553 the Free Software Foundation, either version 3 of the License, or 5554 (at your option) any later version. 5555 5556 web3.js is distributed in the hope that it will be useful, 5557 but WITHOUT ANY WARRANTY; without even the implied warranty of 5558 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5559 GNU Lesser General Public License for more details. 5560 5561 You should have received a copy of the GNU Lesser General Public License 5562 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5563 */ 5564 /** @file eth.js 5565 * @authors: 5566 * Marek Kotewicz <marek@ethdev.com> 5567 * @date 2015 5568 */ 5569 5570 var utils = require('../../utils/utils'); 5571 var Property = require('../property'); 5572 5573 var Net = function (web3) { 5574 this._requestManager = web3._requestManager; 5575 5576 var self = this; 5577 5578 properties().forEach(function(p) { 5579 p.attachToObject(self); 5580 p.setRequestManager(web3._requestManager); 5581 }); 5582 }; 5583 5584 /// @returns an array of objects describing web3.eth api properties 5585 var properties = function () { 5586 return [ 5587 new Property({ 5588 name: 'listening', 5589 getter: 'net_listening' 5590 }), 5591 new Property({ 5592 name: 'peerCount', 5593 getter: 'net_peerCount', 5594 outputFormatter: utils.toDecimal 5595 }) 5596 ]; 5597 }; 5598 5599 module.exports = Net; 5600 5601 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 5602 /* 5603 This file is part of web3.js. 5604 5605 web3.js is free software: you can redistribute it and/or modify 5606 it under the terms of the GNU Lesser General Public License as published by 5607 the Free Software Foundation, either version 3 of the License, or 5608 (at your option) any later version. 5609 5610 web3.js is distributed in the hope that it will be useful, 5611 but WITHOUT ANY WARRANTY; without even the implied warranty of 5612 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5613 GNU Lesser General Public License for more details. 5614 5615 You should have received a copy of the GNU Lesser General Public License 5616 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5617 */ 5618 /** 5619 * @file eth.js 5620 * @author Marek Kotewicz <marek@ethdev.com> 5621 * @author Fabian Vogelsteller <fabian@ethdev.com> 5622 * @date 2015 5623 */ 5624 5625 "use strict"; 5626 5627 var Method = require('../method'); 5628 var Property = require('../property'); 5629 var formatters = require('../formatters'); 5630 5631 function Personal(web3) { 5632 this._requestManager = web3._requestManager; 5633 5634 var self = this; 5635 5636 methods().forEach(function(method) { 5637 method.attachToObject(self); 5638 method.setRequestManager(self._requestManager); 5639 }); 5640 5641 properties().forEach(function(p) { 5642 p.attachToObject(self); 5643 p.setRequestManager(self._requestManager); 5644 }); 5645 } 5646 5647 var methods = function () { 5648 var newAccount = new Method({ 5649 name: 'newAccount', 5650 call: 'personal_newAccount', 5651 params: 1, 5652 inputFormatter: [null] 5653 }); 5654 5655 var importRawKey = new Method({ 5656 name: 'importRawKey', 5657 call: 'personal_importRawKey', 5658 params: 2 5659 }); 5660 5661 var sign = new Method({ 5662 name: 'sign', 5663 call: 'personal_sign', 5664 params: 3, 5665 inputFormatter: [null, formatters.inputAddressFormatter, null] 5666 }); 5667 5668 var ecRecover = new Method({ 5669 name: 'ecRecover', 5670 call: 'personal_ecRecover', 5671 params: 2 5672 }); 5673 5674 var unlockAccount = new Method({ 5675 name: 'unlockAccount', 5676 call: 'personal_unlockAccount', 5677 params: 3, 5678 inputFormatter: [formatters.inputAddressFormatter, null, null] 5679 }); 5680 5681 var sendTransaction = new Method({ 5682 name: 'sendTransaction', 5683 call: 'personal_sendTransaction', 5684 params: 2, 5685 inputFormatter: [formatters.inputTransactionFormatter, null] 5686 }); 5687 5688 var lockAccount = new Method({ 5689 name: 'lockAccount', 5690 call: 'personal_lockAccount', 5691 params: 1, 5692 inputFormatter: [formatters.inputAddressFormatter] 5693 }); 5694 5695 return [ 5696 newAccount, 5697 importRawKey, 5698 unlockAccount, 5699 ecRecover, 5700 sign, 5701 sendTransaction, 5702 lockAccount 5703 ]; 5704 }; 5705 5706 var properties = function () { 5707 return [ 5708 new Property({ 5709 name: 'listAccounts', 5710 getter: 'personal_listAccounts' 5711 }) 5712 ]; 5713 }; 5714 5715 5716 module.exports = Personal; 5717 5718 },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){ 5719 /* 5720 This file is part of web3.js. 5721 5722 web3.js is free software: you can redistribute it and/or modify 5723 it under the terms of the GNU Lesser General Public License as published by 5724 the Free Software Foundation, either version 3 of the License, or 5725 (at your option) any later version. 5726 5727 web3.js is distributed in the hope that it will be useful, 5728 but WITHOUT ANY WARRANTY; without even the implied warranty of 5729 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5730 GNU Lesser General Public License for more details. 5731 5732 You should have received a copy of the GNU Lesser General Public License 5733 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5734 */ 5735 /** @file shh.js 5736 * @authors: 5737 * Fabian Vogelsteller <fabian@ethereum.org> 5738 * Marek Kotewicz <marek@ethcore.io> 5739 * @date 2017 5740 */ 5741 5742 var Method = require('../method'); 5743 var Filter = require('../filter'); 5744 var watches = require('./watches'); 5745 5746 var Shh = function (web3) { 5747 this._requestManager = web3._requestManager; 5748 5749 var self = this; 5750 5751 methods().forEach(function(method) { 5752 method.attachToObject(self); 5753 method.setRequestManager(self._requestManager); 5754 }); 5755 }; 5756 5757 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 5758 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 5759 }; 5760 5761 var methods = function () { 5762 5763 return [ 5764 new Method({ 5765 name: 'version', 5766 call: 'shh_version', 5767 params: 0 5768 }), 5769 new Method({ 5770 name: 'info', 5771 call: 'shh_info', 5772 params: 0 5773 }), 5774 new Method({ 5775 name: 'setMaxMessageSize', 5776 call: 'shh_setMaxMessageSize', 5777 params: 1 5778 }), 5779 new Method({ 5780 name: 'setMinPoW', 5781 call: 'shh_setMinPoW', 5782 params: 1 5783 }), 5784 new Method({ 5785 name: 'markTrustedPeer', 5786 call: 'shh_markTrustedPeer', 5787 params: 1 5788 }), 5789 new Method({ 5790 name: 'newKeyPair', 5791 call: 'shh_newKeyPair', 5792 params: 0 5793 }), 5794 new Method({ 5795 name: 'addPrivateKey', 5796 call: 'shh_addPrivateKey', 5797 params: 1 5798 }), 5799 new Method({ 5800 name: 'deleteKeyPair', 5801 call: 'shh_deleteKeyPair', 5802 params: 1 5803 }), 5804 new Method({ 5805 name: 'hasKeyPair', 5806 call: 'shh_hasKeyPair', 5807 params: 1 5808 }), 5809 new Method({ 5810 name: 'getPublicKey', 5811 call: 'shh_getPublicKey', 5812 params: 1 5813 }), 5814 new Method({ 5815 name: 'getPrivateKey', 5816 call: 'shh_getPrivateKey', 5817 params: 1 5818 }), 5819 new Method({ 5820 name: 'newSymKey', 5821 call: 'shh_newSymKey', 5822 params: 0 5823 }), 5824 new Method({ 5825 name: 'addSymKey', 5826 call: 'shh_addSymKey', 5827 params: 1 5828 }), 5829 new Method({ 5830 name: 'generateSymKeyFromPassword', 5831 call: 'shh_generateSymKeyFromPassword', 5832 params: 1 5833 }), 5834 new Method({ 5835 name: 'hasSymKey', 5836 call: 'shh_hasSymKey', 5837 params: 1 5838 }), 5839 new Method({ 5840 name: 'getSymKey', 5841 call: 'shh_getSymKey', 5842 params: 1 5843 }), 5844 new Method({ 5845 name: 'deleteSymKey', 5846 call: 'shh_deleteSymKey', 5847 params: 1 5848 }), 5849 5850 // subscribe and unsubscribe missing 5851 5852 new Method({ 5853 name: 'post', 5854 call: 'shh_post', 5855 params: 1, 5856 inputFormatter: [null] 5857 }) 5858 ]; 5859 }; 5860 5861 module.exports = Shh; 5862 5863 5864 },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){ 5865 /* 5866 This file is part of web3.js. 5867 5868 web3.js is free software: you can redistribute it and/or modify 5869 it under the terms of the GNU Lesser General Public License as published by 5870 the Free Software Foundation, either version 3 of the License, or 5871 (at your option) any later version. 5872 5873 web3.js is distributed in the hope that it will be useful, 5874 but WITHOUT ANY WARRANTY; without even the implied warranty of 5875 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5876 GNU Lesser General Public License for more details. 5877 5878 You should have received a copy of the GNU Lesser General Public License 5879 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5880 */ 5881 /** 5882 * @file bzz.js 5883 * @author Alex Beregszaszi <alex@rtfs.hu> 5884 * @date 2016 5885 * 5886 * Reference: https://github.com/aswedchain/aswed/blob/swarm/internal/web3ext/web3ext.go#L33 5887 */ 5888 5889 "use strict"; 5890 5891 var Method = require('../method'); 5892 var Property = require('../property'); 5893 5894 function Swarm(web3) { 5895 this._requestManager = web3._requestManager; 5896 5897 var self = this; 5898 5899 methods().forEach(function(method) { 5900 method.attachToObject(self); 5901 method.setRequestManager(self._requestManager); 5902 }); 5903 5904 properties().forEach(function(p) { 5905 p.attachToObject(self); 5906 p.setRequestManager(self._requestManager); 5907 }); 5908 } 5909 5910 var methods = function () { 5911 var blockNetworkRead = new Method({ 5912 name: 'blockNetworkRead', 5913 call: 'bzz_blockNetworkRead', 5914 params: 1, 5915 inputFormatter: [null] 5916 }); 5917 5918 var syncEnabled = new Method({ 5919 name: 'syncEnabled', 5920 call: 'bzz_syncEnabled', 5921 params: 1, 5922 inputFormatter: [null] 5923 }); 5924 5925 var swapEnabled = new Method({ 5926 name: 'swapEnabled', 5927 call: 'bzz_swapEnabled', 5928 params: 1, 5929 inputFormatter: [null] 5930 }); 5931 5932 var download = new Method({ 5933 name: 'download', 5934 call: 'bzz_download', 5935 params: 2, 5936 inputFormatter: [null, null] 5937 }); 5938 5939 var upload = new Method({ 5940 name: 'upload', 5941 call: 'bzz_upload', 5942 params: 2, 5943 inputFormatter: [null, null] 5944 }); 5945 5946 var retrieve = new Method({ 5947 name: 'retrieve', 5948 call: 'bzz_retrieve', 5949 params: 1, 5950 inputFormatter: [null] 5951 }); 5952 5953 var store = new Method({ 5954 name: 'store', 5955 call: 'bzz_store', 5956 params: 2, 5957 inputFormatter: [null, null] 5958 }); 5959 5960 var get = new Method({ 5961 name: 'get', 5962 call: 'bzz_get', 5963 params: 1, 5964 inputFormatter: [null] 5965 }); 5966 5967 var put = new Method({ 5968 name: 'put', 5969 call: 'bzz_put', 5970 params: 2, 5971 inputFormatter: [null, null] 5972 }); 5973 5974 var modify = new Method({ 5975 name: 'modify', 5976 call: 'bzz_modify', 5977 params: 4, 5978 inputFormatter: [null, null, null, null] 5979 }); 5980 5981 return [ 5982 blockNetworkRead, 5983 syncEnabled, 5984 swapEnabled, 5985 download, 5986 upload, 5987 retrieve, 5988 store, 5989 get, 5990 put, 5991 modify 5992 ]; 5993 }; 5994 5995 var properties = function () { 5996 return [ 5997 new Property({ 5998 name: 'hive', 5999 getter: 'bzz_hive' 6000 }), 6001 new Property({ 6002 name: 'info', 6003 getter: 'bzz_info' 6004 }) 6005 ]; 6006 }; 6007 6008 6009 module.exports = Swarm; 6010 6011 },{"../method":36,"../property":45}],43:[function(require,module,exports){ 6012 /* 6013 This file is part of web3.js. 6014 6015 web3.js is free software: you can redistribute it and/or modify 6016 it under the terms of the GNU Lesser General Public License as published by 6017 the Free Software Foundation, either version 3 of the License, or 6018 (at your option) any later version. 6019 6020 web3.js is distributed in the hope that it will be useful, 6021 but WITHOUT ANY WARRANTY; without even the implied warranty of 6022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6023 GNU Lesser General Public License for more details. 6024 6025 You should have received a copy of the GNU Lesser General Public License 6026 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6027 */ 6028 /** @file watches.js 6029 * @authors: 6030 * Marek Kotewicz <marek@ethdev.com> 6031 * @date 2015 6032 */ 6033 6034 var Method = require('../method'); 6035 6036 /// @returns an array of objects describing web3.eth.filter api methods 6037 var eth = function () { 6038 var newFilterCall = function (args) { 6039 var type = args[0]; 6040 6041 switch(type) { 6042 case 'latest': 6043 args.shift(); 6044 this.params = 0; 6045 return 'eth_newBlockFilter'; 6046 case 'pending': 6047 args.shift(); 6048 this.params = 0; 6049 return 'eth_newPendingTransactionFilter'; 6050 default: 6051 return 'eth_newFilter'; 6052 } 6053 }; 6054 6055 var newFilter = new Method({ 6056 name: 'newFilter', 6057 call: newFilterCall, 6058 params: 1 6059 }); 6060 6061 var uninstallFilter = new Method({ 6062 name: 'uninstallFilter', 6063 call: 'eth_uninstallFilter', 6064 params: 1 6065 }); 6066 6067 var getLogs = new Method({ 6068 name: 'getLogs', 6069 call: 'eth_getFilterLogs', 6070 params: 1 6071 }); 6072 6073 var poll = new Method({ 6074 name: 'poll', 6075 call: 'eth_getFilterChanges', 6076 params: 1 6077 }); 6078 6079 return [ 6080 newFilter, 6081 uninstallFilter, 6082 getLogs, 6083 poll 6084 ]; 6085 }; 6086 6087 /// @returns an array of objects describing web3.shh.watch api methods 6088 var shh = function () { 6089 6090 return [ 6091 new Method({ 6092 name: 'newFilter', 6093 call: 'shh_newMessageFilter', 6094 params: 1 6095 }), 6096 new Method({ 6097 name: 'uninstallFilter', 6098 call: 'shh_deleteMessageFilter', 6099 params: 1 6100 }), 6101 new Method({ 6102 name: 'getLogs', 6103 call: 'shh_getFilterMessages', 6104 params: 1 6105 }), 6106 new Method({ 6107 name: 'poll', 6108 call: 'shh_getFilterMessages', 6109 params: 1 6110 }) 6111 ]; 6112 }; 6113 6114 module.exports = { 6115 eth: eth, 6116 shh: shh 6117 }; 6118 6119 6120 },{"../method":36}],44:[function(require,module,exports){ 6121 /* 6122 This file is part of web3.js. 6123 6124 web3.js is free software: you can redistribute it and/or modify 6125 it under the terms of the GNU Lesser General Public License as published by 6126 the Free Software Foundation, either version 3 of the License, or 6127 (at your option) any later version. 6128 6129 web3.js is distributed in the hope that it will be useful, 6130 but WITHOUT ANY WARRANTY; without even the implied warranty of 6131 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6132 GNU Lesser General Public License for more details. 6133 6134 You should have received a copy of the GNU Lesser General Public License 6135 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6136 */ 6137 /** 6138 * @file namereg.js 6139 * @author Marek Kotewicz <marek@ethdev.com> 6140 * @date 2015 6141 */ 6142 6143 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6144 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6145 6146 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6147 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6148 6149 module.exports = { 6150 global: { 6151 abi: globalRegistrarAbi, 6152 address: globalNameregAddress 6153 }, 6154 icap: { 6155 abi: icapRegistrarAbi, 6156 address: icapNameregAddress 6157 } 6158 }; 6159 6160 6161 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 6162 /* 6163 This file is part of web3.js. 6164 6165 web3.js is free software: you can redistribute it and/or modify 6166 it under the terms of the GNU Lesser General Public License as published by 6167 the Free Software Foundation, either version 3 of the License, or 6168 (at your option) any later version. 6169 6170 web3.js is distributed in the hope that it will be useful, 6171 but WITHOUT ANY WARRANTY; without even the implied warranty of 6172 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6173 GNU Lesser General Public License for more details. 6174 6175 You should have received a copy of the GNU Lesser General Public License 6176 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6177 */ 6178 /** 6179 * @file property.js 6180 * @author Fabian Vogelsteller <fabian@frozeman.de> 6181 * @author Marek Kotewicz <marek@ethdev.com> 6182 * @date 2015 6183 */ 6184 6185 var utils = require('../utils/utils'); 6186 6187 var Property = function (options) { 6188 this.name = options.name; 6189 this.getter = options.getter; 6190 this.setter = options.setter; 6191 this.outputFormatter = options.outputFormatter; 6192 this.inputFormatter = options.inputFormatter; 6193 this.requestManager = null; 6194 }; 6195 6196 Property.prototype.setRequestManager = function (rm) { 6197 this.requestManager = rm; 6198 }; 6199 6200 /** 6201 * Should be called to format input args of method 6202 * 6203 * @method formatInput 6204 * @param {Array} 6205 * @return {Array} 6206 */ 6207 Property.prototype.formatInput = function (arg) { 6208 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6209 }; 6210 6211 /** 6212 * Should be called to format output(result) of method 6213 * 6214 * @method formatOutput 6215 * @param {Object} 6216 * @return {Object} 6217 */ 6218 Property.prototype.formatOutput = function (result) { 6219 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6220 }; 6221 6222 /** 6223 * Should be used to extract callback from array of arguments. Modifies input param 6224 * 6225 * @method extractCallback 6226 * @param {Array} arguments 6227 * @return {Function|Null} callback, if exists 6228 */ 6229 Property.prototype.extractCallback = function (args) { 6230 if (utils.isFunction(args[args.length - 1])) { 6231 return args.pop(); // modify the args array! 6232 } 6233 }; 6234 6235 6236 /** 6237 * Should attach function to method 6238 * 6239 * @method attachToObject 6240 * @param {Object} 6241 * @param {Function} 6242 */ 6243 Property.prototype.attachToObject = function (obj) { 6244 var proto = { 6245 get: this.buildGet(), 6246 enumerable: true 6247 }; 6248 6249 var names = this.name.split('.'); 6250 var name = names[0]; 6251 if (names.length > 1) { 6252 obj[names[0]] = obj[names[0]] || {}; 6253 obj = obj[names[0]]; 6254 name = names[1]; 6255 } 6256 6257 Object.defineProperty(obj, name, proto); 6258 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6259 }; 6260 6261 var asyncGetterName = function (name) { 6262 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6263 }; 6264 6265 Property.prototype.buildGet = function () { 6266 var property = this; 6267 return function get() { 6268 return property.formatOutput(property.requestManager.send({ 6269 method: property.getter 6270 })); 6271 }; 6272 }; 6273 6274 Property.prototype.buildAsyncGet = function () { 6275 var property = this; 6276 var get = function (callback) { 6277 property.requestManager.sendAsync({ 6278 method: property.getter 6279 }, function (err, result) { 6280 callback(err, property.formatOutput(result)); 6281 }); 6282 }; 6283 get.request = this.request.bind(this); 6284 return get; 6285 }; 6286 6287 /** 6288 * Should be called to create pure JSONRPC request which can be used in batch request 6289 * 6290 * @method request 6291 * @param {...} params 6292 * @return {Object} jsonrpc request 6293 */ 6294 Property.prototype.request = function () { 6295 var payload = { 6296 method: this.getter, 6297 params: [], 6298 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6299 }; 6300 payload.format = this.formatOutput.bind(this); 6301 return payload; 6302 }; 6303 6304 module.exports = Property; 6305 6306 6307 },{"../utils/utils":20}],46:[function(require,module,exports){ 6308 /* 6309 This file is part of web3.js. 6310 6311 web3.js is free software: you can redistribute it and/or modify 6312 it under the terms of the GNU Lesser General Public License as published by 6313 the Free Software Foundation, either version 3 of the License, or 6314 (at your option) any later version. 6315 6316 web3.js is distributed in the hope that it will be useful, 6317 but WITHOUT ANY WARRANTY; without even the implied warranty of 6318 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6319 GNU Lesser General Public License for more details. 6320 6321 You should have received a copy of the GNU Lesser General Public License 6322 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6323 */ 6324 /** 6325 * @file requestmanager.js 6326 * @author Jeffrey Wilcke <jeff@ethdev.com> 6327 * @author Marek Kotewicz <marek@ethdev.com> 6328 * @author Marian Oancea <marian@ethdev.com> 6329 * @author Fabian Vogelsteller <fabian@ethdev.com> 6330 * @author Gav Wood <g@ethdev.com> 6331 * @date 2014 6332 */ 6333 6334 var Jsonrpc = require('./jsonrpc'); 6335 var utils = require('../utils/utils'); 6336 var c = require('../utils/config'); 6337 var errors = require('./errors'); 6338 6339 /** 6340 * It's responsible for passing messages to providers 6341 * It's also responsible for polling the ethereum node for incoming messages 6342 * Default poll timeout is 1 second 6343 * Singleton 6344 */ 6345 var RequestManager = function (provider) { 6346 this.provider = provider; 6347 this.polls = {}; 6348 this.timeout = null; 6349 }; 6350 6351 /** 6352 * Should be used to synchronously send request 6353 * 6354 * @method send 6355 * @param {Object} data 6356 * @return {Object} 6357 */ 6358 RequestManager.prototype.send = function (data) { 6359 if (!this.provider) { 6360 console.error(errors.InvalidProvider()); 6361 return null; 6362 } 6363 6364 var payload = Jsonrpc.toPayload(data.method, data.params); 6365 var result = this.provider.send(payload); 6366 6367 if (!Jsonrpc.isValidResponse(result)) { 6368 throw errors.InvalidResponse(result); 6369 } 6370 6371 return result.result; 6372 }; 6373 6374 /** 6375 * Should be used to asynchronously send request 6376 * 6377 * @method sendAsync 6378 * @param {Object} data 6379 * @param {Function} callback 6380 */ 6381 RequestManager.prototype.sendAsync = function (data, callback) { 6382 if (!this.provider) { 6383 return callback(errors.InvalidProvider()); 6384 } 6385 6386 var payload = Jsonrpc.toPayload(data.method, data.params); 6387 this.provider.sendAsync(payload, function (err, result) { 6388 if (err) { 6389 return callback(err); 6390 } 6391 6392 if (!Jsonrpc.isValidResponse(result)) { 6393 return callback(errors.InvalidResponse(result)); 6394 } 6395 6396 callback(null, result.result); 6397 }); 6398 }; 6399 6400 /** 6401 * Should be called to asynchronously send batch request 6402 * 6403 * @method sendBatch 6404 * @param {Array} batch data 6405 * @param {Function} callback 6406 */ 6407 RequestManager.prototype.sendBatch = function (data, callback) { 6408 if (!this.provider) { 6409 return callback(errors.InvalidProvider()); 6410 } 6411 6412 var payload = Jsonrpc.toBatchPayload(data); 6413 6414 this.provider.sendAsync(payload, function (err, results) { 6415 if (err) { 6416 return callback(err); 6417 } 6418 6419 if (!utils.isArray(results)) { 6420 return callback(errors.InvalidResponse(results)); 6421 } 6422 6423 callback(err, results); 6424 }); 6425 }; 6426 6427 /** 6428 * Should be used to set provider of request manager 6429 * 6430 * @method setProvider 6431 * @param {Object} 6432 */ 6433 RequestManager.prototype.setProvider = function (p) { 6434 this.provider = p; 6435 }; 6436 6437 /** 6438 * Should be used to start polling 6439 * 6440 * @method startPolling 6441 * @param {Object} data 6442 * @param {Number} pollId 6443 * @param {Function} callback 6444 * @param {Function} uninstall 6445 * 6446 * @todo cleanup number of params 6447 */ 6448 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6449 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 6450 6451 6452 // start polling 6453 if (!this.timeout) { 6454 this.poll(); 6455 } 6456 }; 6457 6458 /** 6459 * Should be used to stop polling for filter with given id 6460 * 6461 * @method stopPolling 6462 * @param {Number} pollId 6463 */ 6464 RequestManager.prototype.stopPolling = function (pollId) { 6465 delete this.polls[pollId]; 6466 6467 // stop polling 6468 if(Object.keys(this.polls).length === 0 && this.timeout) { 6469 clearTimeout(this.timeout); 6470 this.timeout = null; 6471 } 6472 }; 6473 6474 /** 6475 * Should be called to reset the polling mechanism of the request manager 6476 * 6477 * @method reset 6478 */ 6479 RequestManager.prototype.reset = function (keepIsSyncing) { 6480 /*jshint maxcomplexity:5 */ 6481 6482 for (var key in this.polls) { 6483 // remove all polls, except sync polls, 6484 // they need to be removed manually by calling syncing.stopWatching() 6485 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6486 this.polls[key].uninstall(); 6487 delete this.polls[key]; 6488 } 6489 } 6490 6491 // stop polling 6492 if(Object.keys(this.polls).length === 0 && this.timeout) { 6493 clearTimeout(this.timeout); 6494 this.timeout = null; 6495 } 6496 }; 6497 6498 /** 6499 * Should be called to poll for changes on filter with given id 6500 * 6501 * @method poll 6502 */ 6503 RequestManager.prototype.poll = function () { 6504 /*jshint maxcomplexity: 6 */ 6505 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6506 6507 if (Object.keys(this.polls).length === 0) { 6508 return; 6509 } 6510 6511 if (!this.provider) { 6512 console.error(errors.InvalidProvider()); 6513 return; 6514 } 6515 6516 var pollsData = []; 6517 var pollsIds = []; 6518 for (var key in this.polls) { 6519 pollsData.push(this.polls[key].data); 6520 pollsIds.push(key); 6521 } 6522 6523 if (pollsData.length === 0) { 6524 return; 6525 } 6526 6527 var payload = Jsonrpc.toBatchPayload(pollsData); 6528 6529 // map the request id to they poll id 6530 var pollsIdMap = {}; 6531 payload.forEach(function(load, index){ 6532 pollsIdMap[load.id] = pollsIds[index]; 6533 }); 6534 6535 6536 var self = this; 6537 this.provider.sendAsync(payload, function (error, results) { 6538 6539 6540 // TODO: console log? 6541 if (error) { 6542 return; 6543 } 6544 6545 if (!utils.isArray(results)) { 6546 throw errors.InvalidResponse(results); 6547 } 6548 results.map(function (result) { 6549 var id = pollsIdMap[result.id]; 6550 6551 // make sure the filter is still installed after arrival of the request 6552 if (self.polls[id]) { 6553 result.callback = self.polls[id].callback; 6554 return result; 6555 } else 6556 return false; 6557 }).filter(function (result) { 6558 return !!result; 6559 }).filter(function (result) { 6560 var valid = Jsonrpc.isValidResponse(result); 6561 if (!valid) { 6562 result.callback(errors.InvalidResponse(result)); 6563 } 6564 return valid; 6565 }).forEach(function (result) { 6566 result.callback(null, result.result); 6567 }); 6568 }); 6569 }; 6570 6571 module.exports = RequestManager; 6572 6573 6574 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 6575 6576 6577 var Settings = function () { 6578 this.defaultBlock = 'latest'; 6579 this.defaultAccount = undefined; 6580 }; 6581 6582 module.exports = Settings; 6583 6584 6585 },{}],48:[function(require,module,exports){ 6586 /* 6587 This file is part of web3.js. 6588 6589 web3.js is free software: you can redistribute it and/or modify 6590 it under the terms of the GNU Lesser General Public License as published by 6591 the Free Software Foundation, either version 3 of the License, or 6592 (at your option) any later version. 6593 6594 web3.js is distributed in the hope that it will be useful, 6595 but WITHOUT ANY WARRANTY; without even the implied warranty of 6596 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6597 GNU Lesser General Public License for more details. 6598 6599 You should have received a copy of the GNU Lesser General Public License 6600 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6601 */ 6602 /** @file syncing.js 6603 * @authors: 6604 * Fabian Vogelsteller <fabian@ethdev.com> 6605 * @date 2015 6606 */ 6607 6608 var formatters = require('./formatters'); 6609 var utils = require('../utils/utils'); 6610 6611 var count = 1; 6612 6613 /** 6614 Adds the callback and sets up the methods, to iterate over the results. 6615 6616 @method pollSyncing 6617 @param {Object} self 6618 */ 6619 var pollSyncing = function(self) { 6620 6621 var onMessage = function (error, sync) { 6622 if (error) { 6623 return self.callbacks.forEach(function (callback) { 6624 callback(error); 6625 }); 6626 } 6627 6628 if(utils.isObject(sync) && sync.startingBlock) 6629 sync = formatters.outputSyncingFormatter(sync); 6630 6631 self.callbacks.forEach(function (callback) { 6632 if (self.lastSyncState !== sync) { 6633 6634 // call the callback with true first so the app can stop anything, before receiving the sync data 6635 if(!self.lastSyncState && utils.isObject(sync)) 6636 callback(null, true); 6637 6638 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6639 setTimeout(function() { 6640 callback(null, sync); 6641 }, 0); 6642 6643 self.lastSyncState = sync; 6644 } 6645 }); 6646 }; 6647 6648 self.requestManager.startPolling({ 6649 method: 'eth_syncing', 6650 params: [], 6651 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6652 6653 }; 6654 6655 var IsSyncing = function (requestManager, callback) { 6656 this.requestManager = requestManager; 6657 this.pollId = 'syncPoll_'+ count++; 6658 this.callbacks = []; 6659 this.addCallback(callback); 6660 this.lastSyncState = false; 6661 pollSyncing(this); 6662 6663 return this; 6664 }; 6665 6666 IsSyncing.prototype.addCallback = function (callback) { 6667 if(callback) 6668 this.callbacks.push(callback); 6669 return this; 6670 }; 6671 6672 IsSyncing.prototype.stopWatching = function () { 6673 this.requestManager.stopPolling(this.pollId); 6674 this.callbacks = []; 6675 }; 6676 6677 module.exports = IsSyncing; 6678 6679 6680 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 6681 /* 6682 This file is part of web3.js. 6683 6684 web3.js is free software: you can redistribute it and/or modify 6685 it under the terms of the GNU Lesser General Public License as published by 6686 the Free Software Foundation, either version 3 of the License, or 6687 (at your option) any later version. 6688 6689 web3.js is distributed in the hope that it will be useful, 6690 but WITHOUT ANY WARRANTY; without even the implied warranty of 6691 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6692 GNU Lesser General Public License for more details. 6693 6694 You should have received a copy of the GNU Lesser General Public License 6695 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6696 */ 6697 /** 6698 * @file transfer.js 6699 * @author Marek Kotewicz <marek@ethdev.com> 6700 * @date 2015 6701 */ 6702 6703 var Iban = require('./iban'); 6704 var exchangeAbi = require('../contracts/SmartExchange.json'); 6705 6706 /** 6707 * Should be used to make Iban transfer 6708 * 6709 * @method transfer 6710 * @param {String} from 6711 * @param {String} to iban 6712 * @param {Value} value to be tranfered 6713 * @param {Function} callback, callback 6714 */ 6715 var transfer = function (eth, from, to, value, callback) { 6716 var iban = new Iban(to); 6717 if (!iban.isValid()) { 6718 throw new Error('invalid iban address'); 6719 } 6720 6721 if (iban.isDirect()) { 6722 return transferToAddress(eth, from, iban.address(), value, callback); 6723 } 6724 6725 if (!callback) { 6726 var address = eth.icapNamereg().addr(iban.institution()); 6727 return deposit(eth, from, address, value, iban.client()); 6728 } 6729 6730 eth.icapNamereg().addr(iban.institution(), function (err, address) { 6731 return deposit(eth, from, address, value, iban.client(), callback); 6732 }); 6733 6734 }; 6735 6736 /** 6737 * Should be used to transfer funds to certain address 6738 * 6739 * @method transferToAddress 6740 * @param {String} from 6741 * @param {String} to 6742 * @param {Value} value to be tranfered 6743 * @param {Function} callback, callback 6744 */ 6745 var transferToAddress = function (eth, from, to, value, callback) { 6746 return eth.sendTransaction({ 6747 address: to, 6748 from: from, 6749 value: value 6750 }, callback); 6751 }; 6752 6753 /** 6754 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6755 * 6756 * @method deposit 6757 * @param {String} from 6758 * @param {String} to 6759 * @param {Value} value to be transferred 6760 * @param {String} client unique identifier 6761 * @param {Function} callback, callback 6762 */ 6763 var deposit = function (eth, from, to, value, client, callback) { 6764 var abi = exchangeAbi; 6765 return eth.contract(abi).at(to).deposit(client, { 6766 from: from, 6767 value: value 6768 }, callback); 6769 }; 6770 6771 module.exports = transfer; 6772 6773 6774 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 6775 6776 },{}],51:[function(require,module,exports){ 6777 ;(function (root, factory, undef) { 6778 if (typeof exports === "object") { 6779 // CommonJS 6780 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6781 } 6782 else if (typeof define === "function" && define.amd) { 6783 // AMD 6784 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6785 } 6786 else { 6787 // Global (browser) 6788 factory(root.CryptoJS); 6789 } 6790 }(this, function (CryptoJS) { 6791 6792 (function () { 6793 // Shortcuts 6794 var C = CryptoJS; 6795 var C_lib = C.lib; 6796 var BlockCipher = C_lib.BlockCipher; 6797 var C_algo = C.algo; 6798 6799 // Lookup tables 6800 var SBOX = []; 6801 var INV_SBOX = []; 6802 var SUB_MIX_0 = []; 6803 var SUB_MIX_1 = []; 6804 var SUB_MIX_2 = []; 6805 var SUB_MIX_3 = []; 6806 var INV_SUB_MIX_0 = []; 6807 var INV_SUB_MIX_1 = []; 6808 var INV_SUB_MIX_2 = []; 6809 var INV_SUB_MIX_3 = []; 6810 6811 // Compute lookup tables 6812 (function () { 6813 // Compute double table 6814 var d = []; 6815 for (var i = 0; i < 256; i++) { 6816 if (i < 128) { 6817 d[i] = i << 1; 6818 } else { 6819 d[i] = (i << 1) ^ 0x11b; 6820 } 6821 } 6822 6823 // Walk GF(2^8) 6824 var x = 0; 6825 var xi = 0; 6826 for (var i = 0; i < 256; i++) { 6827 // Compute sbox 6828 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6829 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6830 SBOX[x] = sx; 6831 INV_SBOX[sx] = x; 6832 6833 // Compute multiplication 6834 var x2 = d[x]; 6835 var x4 = d[x2]; 6836 var x8 = d[x4]; 6837 6838 // Compute sub bytes, mix columns tables 6839 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6840 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6841 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6842 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6843 SUB_MIX_3[x] = t; 6844 6845 // Compute inv sub bytes, inv mix columns tables 6846 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6847 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6848 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6849 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6850 INV_SUB_MIX_3[sx] = t; 6851 6852 // Compute next counter 6853 if (!x) { 6854 x = xi = 1; 6855 } else { 6856 x = x2 ^ d[d[d[x8 ^ x2]]]; 6857 xi ^= d[d[xi]]; 6858 } 6859 } 6860 }()); 6861 6862 // Precomputed Rcon lookup 6863 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6864 6865 /** 6866 * AES block cipher algorithm. 6867 */ 6868 var AES = C_algo.AES = BlockCipher.extend({ 6869 _doReset: function () { 6870 // Skip reset of nRounds has been set before and key did not change 6871 if (this._nRounds && this._keyPriorReset === this._key) { 6872 return; 6873 } 6874 6875 // Shortcuts 6876 var key = this._keyPriorReset = this._key; 6877 var keyWords = key.words; 6878 var keySize = key.sigBytes / 4; 6879 6880 // Compute number of rounds 6881 var nRounds = this._nRounds = keySize + 6; 6882 6883 // Compute number of key schedule rows 6884 var ksRows = (nRounds + 1) * 4; 6885 6886 // Compute key schedule 6887 var keySchedule = this._keySchedule = []; 6888 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 6889 if (ksRow < keySize) { 6890 keySchedule[ksRow] = keyWords[ksRow]; 6891 } else { 6892 var t = keySchedule[ksRow - 1]; 6893 6894 if (!(ksRow % keySize)) { 6895 // Rot word 6896 t = (t << 8) | (t >>> 24); 6897 6898 // Sub word 6899 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6900 6901 // Mix Rcon 6902 t ^= RCON[(ksRow / keySize) | 0] << 24; 6903 } else if (keySize > 6 && ksRow % keySize == 4) { 6904 // Sub word 6905 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6906 } 6907 6908 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 6909 } 6910 } 6911 6912 // Compute inv key schedule 6913 var invKeySchedule = this._invKeySchedule = []; 6914 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 6915 var ksRow = ksRows - invKsRow; 6916 6917 if (invKsRow % 4) { 6918 var t = keySchedule[ksRow]; 6919 } else { 6920 var t = keySchedule[ksRow - 4]; 6921 } 6922 6923 if (invKsRow < 4 || ksRow <= 4) { 6924 invKeySchedule[invKsRow] = t; 6925 } else { 6926 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 6927 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 6928 } 6929 } 6930 }, 6931 6932 encryptBlock: function (M, offset) { 6933 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 6934 }, 6935 6936 decryptBlock: function (M, offset) { 6937 // Swap 2nd and 4th rows 6938 var t = M[offset + 1]; 6939 M[offset + 1] = M[offset + 3]; 6940 M[offset + 3] = t; 6941 6942 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 6943 6944 // Inv swap 2nd and 4th rows 6945 var t = M[offset + 1]; 6946 M[offset + 1] = M[offset + 3]; 6947 M[offset + 3] = t; 6948 }, 6949 6950 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 6951 // Shortcut 6952 var nRounds = this._nRounds; 6953 6954 // Get input, add round key 6955 var s0 = M[offset] ^ keySchedule[0]; 6956 var s1 = M[offset + 1] ^ keySchedule[1]; 6957 var s2 = M[offset + 2] ^ keySchedule[2]; 6958 var s3 = M[offset + 3] ^ keySchedule[3]; 6959 6960 // Key schedule row counter 6961 var ksRow = 4; 6962 6963 // Rounds 6964 for (var round = 1; round < nRounds; round++) { 6965 // Shift rows, sub bytes, mix columns, add round key 6966 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++]; 6967 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++]; 6968 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++]; 6969 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++]; 6970 6971 // Update state 6972 s0 = t0; 6973 s1 = t1; 6974 s2 = t2; 6975 s3 = t3; 6976 } 6977 6978 // Shift rows, sub bytes, add round key 6979 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 6980 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 6981 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 6982 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 6983 6984 // Set output 6985 M[offset] = t0; 6986 M[offset + 1] = t1; 6987 M[offset + 2] = t2; 6988 M[offset + 3] = t3; 6989 }, 6990 6991 keySize: 256/32 6992 }); 6993 6994 /** 6995 * Shortcut functions to the cipher's object interface. 6996 * 6997 * @example 6998 * 6999 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7000 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7001 */ 7002 C.AES = BlockCipher._createHelper(AES); 7003 }()); 7004 7005 7006 return CryptoJS.AES; 7007 7008 })); 7009 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 7010 ;(function (root, factory) { 7011 if (typeof exports === "object") { 7012 // CommonJS 7013 module.exports = exports = factory(require("./core")); 7014 } 7015 else if (typeof define === "function" && define.amd) { 7016 // AMD 7017 define(["./core"], factory); 7018 } 7019 else { 7020 // Global (browser) 7021 factory(root.CryptoJS); 7022 } 7023 }(this, function (CryptoJS) { 7024 7025 /** 7026 * Cipher core components. 7027 */ 7028 CryptoJS.lib.Cipher || (function (undefined) { 7029 // Shortcuts 7030 var C = CryptoJS; 7031 var C_lib = C.lib; 7032 var Base = C_lib.Base; 7033 var WordArray = C_lib.WordArray; 7034 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7035 var C_enc = C.enc; 7036 var Utf8 = C_enc.Utf8; 7037 var Base64 = C_enc.Base64; 7038 var C_algo = C.algo; 7039 var EvpKDF = C_algo.EvpKDF; 7040 7041 /** 7042 * Abstract base cipher template. 7043 * 7044 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7045 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7046 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7047 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7048 */ 7049 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7050 /** 7051 * Configuration options. 7052 * 7053 * @property {WordArray} iv The IV to use for this operation. 7054 */ 7055 cfg: Base.extend(), 7056 7057 /** 7058 * Creates this cipher in encryption mode. 7059 * 7060 * @param {WordArray} key The key. 7061 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7062 * 7063 * @return {Cipher} A cipher instance. 7064 * 7065 * @static 7066 * 7067 * @example 7068 * 7069 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7070 */ 7071 createEncryptor: function (key, cfg) { 7072 return this.create(this._ENC_XFORM_MODE, key, cfg); 7073 }, 7074 7075 /** 7076 * Creates this cipher in decryption mode. 7077 * 7078 * @param {WordArray} key The key. 7079 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7080 * 7081 * @return {Cipher} A cipher instance. 7082 * 7083 * @static 7084 * 7085 * @example 7086 * 7087 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7088 */ 7089 createDecryptor: function (key, cfg) { 7090 return this.create(this._DEC_XFORM_MODE, key, cfg); 7091 }, 7092 7093 /** 7094 * Initializes a newly created cipher. 7095 * 7096 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7097 * @param {WordArray} key The key. 7098 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7099 * 7100 * @example 7101 * 7102 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7103 */ 7104 init: function (xformMode, key, cfg) { 7105 // Apply config defaults 7106 this.cfg = this.cfg.extend(cfg); 7107 7108 // Store transform mode and key 7109 this._xformMode = xformMode; 7110 this._key = key; 7111 7112 // Set initial values 7113 this.reset(); 7114 }, 7115 7116 /** 7117 * Resets this cipher to its initial state. 7118 * 7119 * @example 7120 * 7121 * cipher.reset(); 7122 */ 7123 reset: function () { 7124 // Reset data buffer 7125 BufferedBlockAlgorithm.reset.call(this); 7126 7127 // Perform concrete-cipher logic 7128 this._doReset(); 7129 }, 7130 7131 /** 7132 * Adds data to be encrypted or decrypted. 7133 * 7134 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7135 * 7136 * @return {WordArray} The data after processing. 7137 * 7138 * @example 7139 * 7140 * var encrypted = cipher.process('data'); 7141 * var encrypted = cipher.process(wordArray); 7142 */ 7143 process: function (dataUpdate) { 7144 // Append 7145 this._append(dataUpdate); 7146 7147 // Process available blocks 7148 return this._process(); 7149 }, 7150 7151 /** 7152 * Finalizes the encryption or decryption process. 7153 * Note that the finalize operation is effectively a destructive, read-once operation. 7154 * 7155 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7156 * 7157 * @return {WordArray} The data after final processing. 7158 * 7159 * @example 7160 * 7161 * var encrypted = cipher.finalize(); 7162 * var encrypted = cipher.finalize('data'); 7163 * var encrypted = cipher.finalize(wordArray); 7164 */ 7165 finalize: function (dataUpdate) { 7166 // Final data update 7167 if (dataUpdate) { 7168 this._append(dataUpdate); 7169 } 7170 7171 // Perform concrete-cipher logic 7172 var finalProcessedData = this._doFinalize(); 7173 7174 return finalProcessedData; 7175 }, 7176 7177 keySize: 128/32, 7178 7179 ivSize: 128/32, 7180 7181 _ENC_XFORM_MODE: 1, 7182 7183 _DEC_XFORM_MODE: 2, 7184 7185 /** 7186 * Creates shortcut functions to a cipher's object interface. 7187 * 7188 * @param {Cipher} cipher The cipher to create a helper for. 7189 * 7190 * @return {Object} An object with encrypt and decrypt shortcut functions. 7191 * 7192 * @static 7193 * 7194 * @example 7195 * 7196 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7197 */ 7198 _createHelper: (function () { 7199 function selectCipherStrategy(key) { 7200 if (typeof key == 'string') { 7201 return PasswordBasedCipher; 7202 } else { 7203 return SerializableCipher; 7204 } 7205 } 7206 7207 return function (cipher) { 7208 return { 7209 encrypt: function (message, key, cfg) { 7210 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7211 }, 7212 7213 decrypt: function (ciphertext, key, cfg) { 7214 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7215 } 7216 }; 7217 }; 7218 }()) 7219 }); 7220 7221 /** 7222 * Abstract base stream cipher template. 7223 * 7224 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7225 */ 7226 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7227 _doFinalize: function () { 7228 // Process partial blocks 7229 var finalProcessedBlocks = this._process(!!'flush'); 7230 7231 return finalProcessedBlocks; 7232 }, 7233 7234 blockSize: 1 7235 }); 7236 7237 /** 7238 * Mode namespace. 7239 */ 7240 var C_mode = C.mode = {}; 7241 7242 /** 7243 * Abstract base block cipher mode template. 7244 */ 7245 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7246 /** 7247 * Creates this mode for encryption. 7248 * 7249 * @param {Cipher} cipher A block cipher instance. 7250 * @param {Array} iv The IV words. 7251 * 7252 * @static 7253 * 7254 * @example 7255 * 7256 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7257 */ 7258 createEncryptor: function (cipher, iv) { 7259 return this.Encryptor.create(cipher, iv); 7260 }, 7261 7262 /** 7263 * Creates this mode for decryption. 7264 * 7265 * @param {Cipher} cipher A block cipher instance. 7266 * @param {Array} iv The IV words. 7267 * 7268 * @static 7269 * 7270 * @example 7271 * 7272 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7273 */ 7274 createDecryptor: function (cipher, iv) { 7275 return this.Decryptor.create(cipher, iv); 7276 }, 7277 7278 /** 7279 * Initializes a newly created mode. 7280 * 7281 * @param {Cipher} cipher A block cipher instance. 7282 * @param {Array} iv The IV words. 7283 * 7284 * @example 7285 * 7286 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7287 */ 7288 init: function (cipher, iv) { 7289 this._cipher = cipher; 7290 this._iv = iv; 7291 } 7292 }); 7293 7294 /** 7295 * Cipher Block Chaining mode. 7296 */ 7297 var CBC = C_mode.CBC = (function () { 7298 /** 7299 * Abstract base CBC mode. 7300 */ 7301 var CBC = BlockCipherMode.extend(); 7302 7303 /** 7304 * CBC encryptor. 7305 */ 7306 CBC.Encryptor = CBC.extend({ 7307 /** 7308 * Processes the data block at offset. 7309 * 7310 * @param {Array} words The data words to operate on. 7311 * @param {number} offset The offset where the block starts. 7312 * 7313 * @example 7314 * 7315 * mode.processBlock(data.words, offset); 7316 */ 7317 processBlock: function (words, offset) { 7318 // Shortcuts 7319 var cipher = this._cipher; 7320 var blockSize = cipher.blockSize; 7321 7322 // XOR and encrypt 7323 xorBlock.call(this, words, offset, blockSize); 7324 cipher.encryptBlock(words, offset); 7325 7326 // Remember this block to use with next block 7327 this._prevBlock = words.slice(offset, offset + blockSize); 7328 } 7329 }); 7330 7331 /** 7332 * CBC decryptor. 7333 */ 7334 CBC.Decryptor = CBC.extend({ 7335 /** 7336 * Processes the data block at offset. 7337 * 7338 * @param {Array} words The data words to operate on. 7339 * @param {number} offset The offset where the block starts. 7340 * 7341 * @example 7342 * 7343 * mode.processBlock(data.words, offset); 7344 */ 7345 processBlock: function (words, offset) { 7346 // Shortcuts 7347 var cipher = this._cipher; 7348 var blockSize = cipher.blockSize; 7349 7350 // Remember this block to use with next block 7351 var thisBlock = words.slice(offset, offset + blockSize); 7352 7353 // Decrypt and XOR 7354 cipher.decryptBlock(words, offset); 7355 xorBlock.call(this, words, offset, blockSize); 7356 7357 // This block becomes the previous block 7358 this._prevBlock = thisBlock; 7359 } 7360 }); 7361 7362 function xorBlock(words, offset, blockSize) { 7363 // Shortcut 7364 var iv = this._iv; 7365 7366 // Choose mixing block 7367 if (iv) { 7368 var block = iv; 7369 7370 // Remove IV for subsequent blocks 7371 this._iv = undefined; 7372 } else { 7373 var block = this._prevBlock; 7374 } 7375 7376 // XOR blocks 7377 for (var i = 0; i < blockSize; i++) { 7378 words[offset + i] ^= block[i]; 7379 } 7380 } 7381 7382 return CBC; 7383 }()); 7384 7385 /** 7386 * Padding namespace. 7387 */ 7388 var C_pad = C.pad = {}; 7389 7390 /** 7391 * PKCS #5/7 padding strategy. 7392 */ 7393 var Pkcs7 = C_pad.Pkcs7 = { 7394 /** 7395 * Pads data using the algorithm defined in PKCS #5/7. 7396 * 7397 * @param {WordArray} data The data to pad. 7398 * @param {number} blockSize The multiple that the data should be padded to. 7399 * 7400 * @static 7401 * 7402 * @example 7403 * 7404 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7405 */ 7406 pad: function (data, blockSize) { 7407 // Shortcut 7408 var blockSizeBytes = blockSize * 4; 7409 7410 // Count padding bytes 7411 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7412 7413 // Create padding word 7414 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7415 7416 // Create padding 7417 var paddingWords = []; 7418 for (var i = 0; i < nPaddingBytes; i += 4) { 7419 paddingWords.push(paddingWord); 7420 } 7421 var padding = WordArray.create(paddingWords, nPaddingBytes); 7422 7423 // Add padding 7424 data.concat(padding); 7425 }, 7426 7427 /** 7428 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7429 * 7430 * @param {WordArray} data The data to unpad. 7431 * 7432 * @static 7433 * 7434 * @example 7435 * 7436 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7437 */ 7438 unpad: function (data) { 7439 // Get number of padding bytes from last byte 7440 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7441 7442 // Remove padding 7443 data.sigBytes -= nPaddingBytes; 7444 } 7445 }; 7446 7447 /** 7448 * Abstract base block cipher template. 7449 * 7450 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7451 */ 7452 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7453 /** 7454 * Configuration options. 7455 * 7456 * @property {Mode} mode The block mode to use. Default: CBC 7457 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7458 */ 7459 cfg: Cipher.cfg.extend({ 7460 mode: CBC, 7461 padding: Pkcs7 7462 }), 7463 7464 reset: function () { 7465 // Reset cipher 7466 Cipher.reset.call(this); 7467 7468 // Shortcuts 7469 var cfg = this.cfg; 7470 var iv = cfg.iv; 7471 var mode = cfg.mode; 7472 7473 // Reset block mode 7474 if (this._xformMode == this._ENC_XFORM_MODE) { 7475 var modeCreator = mode.createEncryptor; 7476 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7477 var modeCreator = mode.createDecryptor; 7478 7479 // Keep at least one block in the buffer for unpadding 7480 this._minBufferSize = 1; 7481 } 7482 this._mode = modeCreator.call(mode, this, iv && iv.words); 7483 }, 7484 7485 _doProcessBlock: function (words, offset) { 7486 this._mode.processBlock(words, offset); 7487 }, 7488 7489 _doFinalize: function () { 7490 // Shortcut 7491 var padding = this.cfg.padding; 7492 7493 // Finalize 7494 if (this._xformMode == this._ENC_XFORM_MODE) { 7495 // Pad data 7496 padding.pad(this._data, this.blockSize); 7497 7498 // Process final blocks 7499 var finalProcessedBlocks = this._process(!!'flush'); 7500 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7501 // Process final blocks 7502 var finalProcessedBlocks = this._process(!!'flush'); 7503 7504 // Unpad data 7505 padding.unpad(finalProcessedBlocks); 7506 } 7507 7508 return finalProcessedBlocks; 7509 }, 7510 7511 blockSize: 128/32 7512 }); 7513 7514 /** 7515 * A collection of cipher parameters. 7516 * 7517 * @property {WordArray} ciphertext The raw ciphertext. 7518 * @property {WordArray} key The key to this ciphertext. 7519 * @property {WordArray} iv The IV used in the ciphering operation. 7520 * @property {WordArray} salt The salt used with a key derivation function. 7521 * @property {Cipher} algorithm The cipher algorithm. 7522 * @property {Mode} mode The block mode used in the ciphering operation. 7523 * @property {Padding} padding The padding scheme used in the ciphering operation. 7524 * @property {number} blockSize The block size of the cipher. 7525 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7526 */ 7527 var CipherParams = C_lib.CipherParams = Base.extend({ 7528 /** 7529 * Initializes a newly created cipher params object. 7530 * 7531 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7532 * 7533 * @example 7534 * 7535 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7536 * ciphertext: ciphertextWordArray, 7537 * key: keyWordArray, 7538 * iv: ivWordArray, 7539 * salt: saltWordArray, 7540 * algorithm: CryptoJS.algo.AES, 7541 * mode: CryptoJS.mode.CBC, 7542 * padding: CryptoJS.pad.PKCS7, 7543 * blockSize: 4, 7544 * formatter: CryptoJS.format.OpenSSL 7545 * }); 7546 */ 7547 init: function (cipherParams) { 7548 this.mixIn(cipherParams); 7549 }, 7550 7551 /** 7552 * Converts this cipher params object to a string. 7553 * 7554 * @param {Format} formatter (Optional) The formatting strategy to use. 7555 * 7556 * @return {string} The stringified cipher params. 7557 * 7558 * @throws Error If neither the formatter nor the default formatter is set. 7559 * 7560 * @example 7561 * 7562 * var string = cipherParams + ''; 7563 * var string = cipherParams.toString(); 7564 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7565 */ 7566 toString: function (formatter) { 7567 return (formatter || this.formatter).stringify(this); 7568 } 7569 }); 7570 7571 /** 7572 * Format namespace. 7573 */ 7574 var C_format = C.format = {}; 7575 7576 /** 7577 * OpenSSL formatting strategy. 7578 */ 7579 var OpenSSLFormatter = C_format.OpenSSL = { 7580 /** 7581 * Converts a cipher params object to an OpenSSL-compatible string. 7582 * 7583 * @param {CipherParams} cipherParams The cipher params object. 7584 * 7585 * @return {string} The OpenSSL-compatible string. 7586 * 7587 * @static 7588 * 7589 * @example 7590 * 7591 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7592 */ 7593 stringify: function (cipherParams) { 7594 // Shortcuts 7595 var ciphertext = cipherParams.ciphertext; 7596 var salt = cipherParams.salt; 7597 7598 // Format 7599 if (salt) { 7600 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7601 } else { 7602 var wordArray = ciphertext; 7603 } 7604 7605 return wordArray.toString(Base64); 7606 }, 7607 7608 /** 7609 * Converts an OpenSSL-compatible string to a cipher params object. 7610 * 7611 * @param {string} openSSLStr The OpenSSL-compatible string. 7612 * 7613 * @return {CipherParams} The cipher params object. 7614 * 7615 * @static 7616 * 7617 * @example 7618 * 7619 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7620 */ 7621 parse: function (openSSLStr) { 7622 // Parse base64 7623 var ciphertext = Base64.parse(openSSLStr); 7624 7625 // Shortcut 7626 var ciphertextWords = ciphertext.words; 7627 7628 // Test for salt 7629 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7630 // Extract salt 7631 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7632 7633 // Remove salt from ciphertext 7634 ciphertextWords.splice(0, 4); 7635 ciphertext.sigBytes -= 16; 7636 } 7637 7638 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7639 } 7640 }; 7641 7642 /** 7643 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7644 */ 7645 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7646 /** 7647 * Configuration options. 7648 * 7649 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7650 */ 7651 cfg: Base.extend({ 7652 format: OpenSSLFormatter 7653 }), 7654 7655 /** 7656 * Encrypts a message. 7657 * 7658 * @param {Cipher} cipher The cipher algorithm to use. 7659 * @param {WordArray|string} message The message to encrypt. 7660 * @param {WordArray} key The key. 7661 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7662 * 7663 * @return {CipherParams} A cipher params object. 7664 * 7665 * @static 7666 * 7667 * @example 7668 * 7669 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7670 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7671 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7672 */ 7673 encrypt: function (cipher, message, key, cfg) { 7674 // Apply config defaults 7675 cfg = this.cfg.extend(cfg); 7676 7677 // Encrypt 7678 var encryptor = cipher.createEncryptor(key, cfg); 7679 var ciphertext = encryptor.finalize(message); 7680 7681 // Shortcut 7682 var cipherCfg = encryptor.cfg; 7683 7684 // Create and return serializable cipher params 7685 return CipherParams.create({ 7686 ciphertext: ciphertext, 7687 key: key, 7688 iv: cipherCfg.iv, 7689 algorithm: cipher, 7690 mode: cipherCfg.mode, 7691 padding: cipherCfg.padding, 7692 blockSize: cipher.blockSize, 7693 formatter: cfg.format 7694 }); 7695 }, 7696 7697 /** 7698 * Decrypts serialized ciphertext. 7699 * 7700 * @param {Cipher} cipher The cipher algorithm to use. 7701 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7702 * @param {WordArray} key The key. 7703 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7704 * 7705 * @return {WordArray} The plaintext. 7706 * 7707 * @static 7708 * 7709 * @example 7710 * 7711 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7712 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7713 */ 7714 decrypt: function (cipher, ciphertext, key, cfg) { 7715 // Apply config defaults 7716 cfg = this.cfg.extend(cfg); 7717 7718 // Convert string to CipherParams 7719 ciphertext = this._parse(ciphertext, cfg.format); 7720 7721 // Decrypt 7722 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7723 7724 return plaintext; 7725 }, 7726 7727 /** 7728 * Converts serialized ciphertext to CipherParams, 7729 * else assumed CipherParams already and returns ciphertext unchanged. 7730 * 7731 * @param {CipherParams|string} ciphertext The ciphertext. 7732 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7733 * 7734 * @return {CipherParams} The unserialized ciphertext. 7735 * 7736 * @static 7737 * 7738 * @example 7739 * 7740 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7741 */ 7742 _parse: function (ciphertext, format) { 7743 if (typeof ciphertext == 'string') { 7744 return format.parse(ciphertext, this); 7745 } else { 7746 return ciphertext; 7747 } 7748 } 7749 }); 7750 7751 /** 7752 * Key derivation function namespace. 7753 */ 7754 var C_kdf = C.kdf = {}; 7755 7756 /** 7757 * OpenSSL key derivation function. 7758 */ 7759 var OpenSSLKdf = C_kdf.OpenSSL = { 7760 /** 7761 * Derives a key and IV from a password. 7762 * 7763 * @param {string} password The password to derive from. 7764 * @param {number} keySize The size in words of the key to generate. 7765 * @param {number} ivSize The size in words of the IV to generate. 7766 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7767 * 7768 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7769 * 7770 * @static 7771 * 7772 * @example 7773 * 7774 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7775 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7776 */ 7777 execute: function (password, keySize, ivSize, salt) { 7778 // Generate random salt 7779 if (!salt) { 7780 salt = WordArray.random(64/8); 7781 } 7782 7783 // Derive key and IV 7784 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 7785 7786 // Separate key and IV 7787 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7788 key.sigBytes = keySize * 4; 7789 7790 // Return params 7791 return CipherParams.create({ key: key, iv: iv, salt: salt }); 7792 } 7793 }; 7794 7795 /** 7796 * A serializable cipher wrapper that derives the key from a password, 7797 * and returns ciphertext as a serializable cipher params object. 7798 */ 7799 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7800 /** 7801 * Configuration options. 7802 * 7803 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7804 */ 7805 cfg: SerializableCipher.cfg.extend({ 7806 kdf: OpenSSLKdf 7807 }), 7808 7809 /** 7810 * Encrypts a message using a password. 7811 * 7812 * @param {Cipher} cipher The cipher algorithm to use. 7813 * @param {WordArray|string} message The message to encrypt. 7814 * @param {string} password The password. 7815 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7816 * 7817 * @return {CipherParams} A cipher params object. 7818 * 7819 * @static 7820 * 7821 * @example 7822 * 7823 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7824 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7825 */ 7826 encrypt: function (cipher, message, password, cfg) { 7827 // Apply config defaults 7828 cfg = this.cfg.extend(cfg); 7829 7830 // Derive key and other params 7831 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7832 7833 // Add IV to config 7834 cfg.iv = derivedParams.iv; 7835 7836 // Encrypt 7837 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7838 7839 // Mix in derived params 7840 ciphertext.mixIn(derivedParams); 7841 7842 return ciphertext; 7843 }, 7844 7845 /** 7846 * Decrypts serialized ciphertext using a password. 7847 * 7848 * @param {Cipher} cipher The cipher algorithm to use. 7849 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7850 * @param {string} password The password. 7851 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7852 * 7853 * @return {WordArray} The plaintext. 7854 * 7855 * @static 7856 * 7857 * @example 7858 * 7859 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 7860 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 7861 */ 7862 decrypt: function (cipher, ciphertext, password, cfg) { 7863 // Apply config defaults 7864 cfg = this.cfg.extend(cfg); 7865 7866 // Convert string to CipherParams 7867 ciphertext = this._parse(ciphertext, cfg.format); 7868 7869 // Derive key and other params 7870 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 7871 7872 // Add IV to config 7873 cfg.iv = derivedParams.iv; 7874 7875 // Decrypt 7876 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 7877 7878 return plaintext; 7879 } 7880 }); 7881 }()); 7882 7883 7884 })); 7885 },{"./core":53}],53:[function(require,module,exports){ 7886 ;(function (root, factory) { 7887 if (typeof exports === "object") { 7888 // CommonJS 7889 module.exports = exports = factory(); 7890 } 7891 else if (typeof define === "function" && define.amd) { 7892 // AMD 7893 define([], factory); 7894 } 7895 else { 7896 // Global (browser) 7897 root.CryptoJS = factory(); 7898 } 7899 }(this, function () { 7900 7901 /** 7902 * CryptoJS core components. 7903 */ 7904 var CryptoJS = CryptoJS || (function (Math, undefined) { 7905 /* 7906 * Local polyfil of Object.create 7907 */ 7908 var create = Object.create || (function () { 7909 function F() {}; 7910 7911 return function (obj) { 7912 var subtype; 7913 7914 F.prototype = obj; 7915 7916 subtype = new F(); 7917 7918 F.prototype = null; 7919 7920 return subtype; 7921 }; 7922 }()) 7923 7924 /** 7925 * CryptoJS namespace. 7926 */ 7927 var C = {}; 7928 7929 /** 7930 * Library namespace. 7931 */ 7932 var C_lib = C.lib = {}; 7933 7934 /** 7935 * Base object for prototypal inheritance. 7936 */ 7937 var Base = C_lib.Base = (function () { 7938 7939 7940 return { 7941 /** 7942 * Creates a new object that inherits from this object. 7943 * 7944 * @param {Object} overrides Properties to copy into the new object. 7945 * 7946 * @return {Object} The new object. 7947 * 7948 * @static 7949 * 7950 * @example 7951 * 7952 * var MyType = CryptoJS.lib.Base.extend({ 7953 * field: 'value', 7954 * 7955 * method: function () { 7956 * } 7957 * }); 7958 */ 7959 extend: function (overrides) { 7960 // Spawn 7961 var subtype = create(this); 7962 7963 // Augment 7964 if (overrides) { 7965 subtype.mixIn(overrides); 7966 } 7967 7968 // Create default initializer 7969 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 7970 subtype.init = function () { 7971 subtype.$super.init.apply(this, arguments); 7972 }; 7973 } 7974 7975 // Initializer's prototype is the subtype object 7976 subtype.init.prototype = subtype; 7977 7978 // Reference supertype 7979 subtype.$super = this; 7980 7981 return subtype; 7982 }, 7983 7984 /** 7985 * Extends this object and runs the init method. 7986 * Arguments to create() will be passed to init(). 7987 * 7988 * @return {Object} The new object. 7989 * 7990 * @static 7991 * 7992 * @example 7993 * 7994 * var instance = MyType.create(); 7995 */ 7996 create: function () { 7997 var instance = this.extend(); 7998 instance.init.apply(instance, arguments); 7999 8000 return instance; 8001 }, 8002 8003 /** 8004 * Initializes a newly created object. 8005 * Override this method to add some logic when your objects are created. 8006 * 8007 * @example 8008 * 8009 * var MyType = CryptoJS.lib.Base.extend({ 8010 * init: function () { 8011 * // ... 8012 * } 8013 * }); 8014 */ 8015 init: function () { 8016 }, 8017 8018 /** 8019 * Copies properties into this object. 8020 * 8021 * @param {Object} properties The properties to mix in. 8022 * 8023 * @example 8024 * 8025 * MyType.mixIn({ 8026 * field: 'value' 8027 * }); 8028 */ 8029 mixIn: function (properties) { 8030 for (var propertyName in properties) { 8031 if (properties.hasOwnProperty(propertyName)) { 8032 this[propertyName] = properties[propertyName]; 8033 } 8034 } 8035 8036 // IE won't copy toString using the loop above 8037 if (properties.hasOwnProperty('toString')) { 8038 this.toString = properties.toString; 8039 } 8040 }, 8041 8042 /** 8043 * Creates a copy of this object. 8044 * 8045 * @return {Object} The clone. 8046 * 8047 * @example 8048 * 8049 * var clone = instance.clone(); 8050 */ 8051 clone: function () { 8052 return this.init.prototype.extend(this); 8053 } 8054 }; 8055 }()); 8056 8057 /** 8058 * An array of 32-bit words. 8059 * 8060 * @property {Array} words The array of 32-bit words. 8061 * @property {number} sigBytes The number of significant bytes in this word array. 8062 */ 8063 var WordArray = C_lib.WordArray = Base.extend({ 8064 /** 8065 * Initializes a newly created word array. 8066 * 8067 * @param {Array} words (Optional) An array of 32-bit words. 8068 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8069 * 8070 * @example 8071 * 8072 * var wordArray = CryptoJS.lib.WordArray.create(); 8073 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8074 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8075 */ 8076 init: function (words, sigBytes) { 8077 words = this.words = words || []; 8078 8079 if (sigBytes != undefined) { 8080 this.sigBytes = sigBytes; 8081 } else { 8082 this.sigBytes = words.length * 4; 8083 } 8084 }, 8085 8086 /** 8087 * Converts this word array to a string. 8088 * 8089 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8090 * 8091 * @return {string} The stringified word array. 8092 * 8093 * @example 8094 * 8095 * var string = wordArray + ''; 8096 * var string = wordArray.toString(); 8097 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8098 */ 8099 toString: function (encoder) { 8100 return (encoder || Hex).stringify(this); 8101 }, 8102 8103 /** 8104 * Concatenates a word array to this word array. 8105 * 8106 * @param {WordArray} wordArray The word array to append. 8107 * 8108 * @return {WordArray} This word array. 8109 * 8110 * @example 8111 * 8112 * wordArray1.concat(wordArray2); 8113 */ 8114 concat: function (wordArray) { 8115 // Shortcuts 8116 var thisWords = this.words; 8117 var thatWords = wordArray.words; 8118 var thisSigBytes = this.sigBytes; 8119 var thatSigBytes = wordArray.sigBytes; 8120 8121 // Clamp excess bits 8122 this.clamp(); 8123 8124 // Concat 8125 if (thisSigBytes % 4) { 8126 // Copy one byte at a time 8127 for (var i = 0; i < thatSigBytes; i++) { 8128 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8129 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8130 } 8131 } else { 8132 // Copy one word at a time 8133 for (var i = 0; i < thatSigBytes; i += 4) { 8134 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8135 } 8136 } 8137 this.sigBytes += thatSigBytes; 8138 8139 // Chainable 8140 return this; 8141 }, 8142 8143 /** 8144 * Removes insignificant bits. 8145 * 8146 * @example 8147 * 8148 * wordArray.clamp(); 8149 */ 8150 clamp: function () { 8151 // Shortcuts 8152 var words = this.words; 8153 var sigBytes = this.sigBytes; 8154 8155 // Clamp 8156 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8157 words.length = Math.ceil(sigBytes / 4); 8158 }, 8159 8160 /** 8161 * Creates a copy of this word array. 8162 * 8163 * @return {WordArray} The clone. 8164 * 8165 * @example 8166 * 8167 * var clone = wordArray.clone(); 8168 */ 8169 clone: function () { 8170 var clone = Base.clone.call(this); 8171 clone.words = this.words.slice(0); 8172 8173 return clone; 8174 }, 8175 8176 /** 8177 * Creates a word array filled with random bytes. 8178 * 8179 * @param {number} nBytes The number of random bytes to generate. 8180 * 8181 * @return {WordArray} The random word array. 8182 * 8183 * @static 8184 * 8185 * @example 8186 * 8187 * var wordArray = CryptoJS.lib.WordArray.random(16); 8188 */ 8189 random: function (nBytes) { 8190 var words = []; 8191 8192 var r = (function (m_w) { 8193 var m_w = m_w; 8194 var m_z = 0x3ade68b1; 8195 var mask = 0xffffffff; 8196 8197 return function () { 8198 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8199 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8200 var result = ((m_z << 0x10) + m_w) & mask; 8201 result /= 0x100000000; 8202 result += 0.5; 8203 return result * (Math.random() > .5 ? 1 : -1); 8204 } 8205 }); 8206 8207 for (var i = 0, rcache; i < nBytes; i += 4) { 8208 var _r = r((rcache || Math.random()) * 0x100000000); 8209 8210 rcache = _r() * 0x3ade67b7; 8211 words.push((_r() * 0x100000000) | 0); 8212 } 8213 8214 return new WordArray.init(words, nBytes); 8215 } 8216 }); 8217 8218 /** 8219 * Encoder namespace. 8220 */ 8221 var C_enc = C.enc = {}; 8222 8223 /** 8224 * Hex encoding strategy. 8225 */ 8226 var Hex = C_enc.Hex = { 8227 /** 8228 * Converts a word array to a hex string. 8229 * 8230 * @param {WordArray} wordArray The word array. 8231 * 8232 * @return {string} The hex string. 8233 * 8234 * @static 8235 * 8236 * @example 8237 * 8238 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8239 */ 8240 stringify: function (wordArray) { 8241 // Shortcuts 8242 var words = wordArray.words; 8243 var sigBytes = wordArray.sigBytes; 8244 8245 // Convert 8246 var hexChars = []; 8247 for (var i = 0; i < sigBytes; i++) { 8248 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8249 hexChars.push((bite >>> 4).toString(16)); 8250 hexChars.push((bite & 0x0f).toString(16)); 8251 } 8252 8253 return hexChars.join(''); 8254 }, 8255 8256 /** 8257 * Converts a hex string to a word array. 8258 * 8259 * @param {string} hexStr The hex string. 8260 * 8261 * @return {WordArray} The word array. 8262 * 8263 * @static 8264 * 8265 * @example 8266 * 8267 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8268 */ 8269 parse: function (hexStr) { 8270 // Shortcut 8271 var hexStrLength = hexStr.length; 8272 8273 // Convert 8274 var words = []; 8275 for (var i = 0; i < hexStrLength; i += 2) { 8276 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8277 } 8278 8279 return new WordArray.init(words, hexStrLength / 2); 8280 } 8281 }; 8282 8283 /** 8284 * Latin1 encoding strategy. 8285 */ 8286 var Latin1 = C_enc.Latin1 = { 8287 /** 8288 * Converts a word array to a Latin1 string. 8289 * 8290 * @param {WordArray} wordArray The word array. 8291 * 8292 * @return {string} The Latin1 string. 8293 * 8294 * @static 8295 * 8296 * @example 8297 * 8298 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8299 */ 8300 stringify: function (wordArray) { 8301 // Shortcuts 8302 var words = wordArray.words; 8303 var sigBytes = wordArray.sigBytes; 8304 8305 // Convert 8306 var latin1Chars = []; 8307 for (var i = 0; i < sigBytes; i++) { 8308 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8309 latin1Chars.push(String.fromCharCode(bite)); 8310 } 8311 8312 return latin1Chars.join(''); 8313 }, 8314 8315 /** 8316 * Converts a Latin1 string to a word array. 8317 * 8318 * @param {string} latin1Str The Latin1 string. 8319 * 8320 * @return {WordArray} The word array. 8321 * 8322 * @static 8323 * 8324 * @example 8325 * 8326 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8327 */ 8328 parse: function (latin1Str) { 8329 // Shortcut 8330 var latin1StrLength = latin1Str.length; 8331 8332 // Convert 8333 var words = []; 8334 for (var i = 0; i < latin1StrLength; i++) { 8335 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8336 } 8337 8338 return new WordArray.init(words, latin1StrLength); 8339 } 8340 }; 8341 8342 /** 8343 * UTF-8 encoding strategy. 8344 */ 8345 var Utf8 = C_enc.Utf8 = { 8346 /** 8347 * Converts a word array to a UTF-8 string. 8348 * 8349 * @param {WordArray} wordArray The word array. 8350 * 8351 * @return {string} The UTF-8 string. 8352 * 8353 * @static 8354 * 8355 * @example 8356 * 8357 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8358 */ 8359 stringify: function (wordArray) { 8360 try { 8361 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8362 } catch (e) { 8363 throw new Error('Malformed UTF-8 data'); 8364 } 8365 }, 8366 8367 /** 8368 * Converts a UTF-8 string to a word array. 8369 * 8370 * @param {string} utf8Str The UTF-8 string. 8371 * 8372 * @return {WordArray} The word array. 8373 * 8374 * @static 8375 * 8376 * @example 8377 * 8378 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8379 */ 8380 parse: function (utf8Str) { 8381 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8382 } 8383 }; 8384 8385 /** 8386 * Abstract buffered block algorithm template. 8387 * 8388 * The property blockSize must be implemented in a concrete subtype. 8389 * 8390 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8391 */ 8392 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8393 /** 8394 * Resets this block algorithm's data buffer to its initial state. 8395 * 8396 * @example 8397 * 8398 * bufferedBlockAlgorithm.reset(); 8399 */ 8400 reset: function () { 8401 // Initial values 8402 this._data = new WordArray.init(); 8403 this._nDataBytes = 0; 8404 }, 8405 8406 /** 8407 * Adds new data to this block algorithm's buffer. 8408 * 8409 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8410 * 8411 * @example 8412 * 8413 * bufferedBlockAlgorithm._append('data'); 8414 * bufferedBlockAlgorithm._append(wordArray); 8415 */ 8416 _append: function (data) { 8417 // Convert string to WordArray, else assume WordArray already 8418 if (typeof data == 'string') { 8419 data = Utf8.parse(data); 8420 } 8421 8422 // Append 8423 this._data.concat(data); 8424 this._nDataBytes += data.sigBytes; 8425 }, 8426 8427 /** 8428 * Processes available data blocks. 8429 * 8430 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8431 * 8432 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8433 * 8434 * @return {WordArray} The processed data. 8435 * 8436 * @example 8437 * 8438 * var processedData = bufferedBlockAlgorithm._process(); 8439 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8440 */ 8441 _process: function (doFlush) { 8442 // Shortcuts 8443 var data = this._data; 8444 var dataWords = data.words; 8445 var dataSigBytes = data.sigBytes; 8446 var blockSize = this.blockSize; 8447 var blockSizeBytes = blockSize * 4; 8448 8449 // Count blocks ready 8450 var nBlocksReady = dataSigBytes / blockSizeBytes; 8451 if (doFlush) { 8452 // Round up to include partial blocks 8453 nBlocksReady = Math.ceil(nBlocksReady); 8454 } else { 8455 // Round down to include only full blocks, 8456 // less the number of blocks that must remain in the buffer 8457 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8458 } 8459 8460 // Count words ready 8461 var nWordsReady = nBlocksReady * blockSize; 8462 8463 // Count bytes ready 8464 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8465 8466 // Process blocks 8467 if (nWordsReady) { 8468 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8469 // Perform concrete-algorithm logic 8470 this._doProcessBlock(dataWords, offset); 8471 } 8472 8473 // Remove processed words 8474 var processedWords = dataWords.splice(0, nWordsReady); 8475 data.sigBytes -= nBytesReady; 8476 } 8477 8478 // Return processed words 8479 return new WordArray.init(processedWords, nBytesReady); 8480 }, 8481 8482 /** 8483 * Creates a copy of this object. 8484 * 8485 * @return {Object} The clone. 8486 * 8487 * @example 8488 * 8489 * var clone = bufferedBlockAlgorithm.clone(); 8490 */ 8491 clone: function () { 8492 var clone = Base.clone.call(this); 8493 clone._data = this._data.clone(); 8494 8495 return clone; 8496 }, 8497 8498 _minBufferSize: 0 8499 }); 8500 8501 /** 8502 * Abstract hasher template. 8503 * 8504 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8505 */ 8506 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8507 /** 8508 * Configuration options. 8509 */ 8510 cfg: Base.extend(), 8511 8512 /** 8513 * Initializes a newly created hasher. 8514 * 8515 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8516 * 8517 * @example 8518 * 8519 * var hasher = CryptoJS.algo.SHA256.create(); 8520 */ 8521 init: function (cfg) { 8522 // Apply config defaults 8523 this.cfg = this.cfg.extend(cfg); 8524 8525 // Set initial values 8526 this.reset(); 8527 }, 8528 8529 /** 8530 * Resets this hasher to its initial state. 8531 * 8532 * @example 8533 * 8534 * hasher.reset(); 8535 */ 8536 reset: function () { 8537 // Reset data buffer 8538 BufferedBlockAlgorithm.reset.call(this); 8539 8540 // Perform concrete-hasher logic 8541 this._doReset(); 8542 }, 8543 8544 /** 8545 * Updates this hasher with a message. 8546 * 8547 * @param {WordArray|string} messageUpdate The message to append. 8548 * 8549 * @return {Hasher} This hasher. 8550 * 8551 * @example 8552 * 8553 * hasher.update('message'); 8554 * hasher.update(wordArray); 8555 */ 8556 update: function (messageUpdate) { 8557 // Append 8558 this._append(messageUpdate); 8559 8560 // Update the hash 8561 this._process(); 8562 8563 // Chainable 8564 return this; 8565 }, 8566 8567 /** 8568 * Finalizes the hash computation. 8569 * Note that the finalize operation is effectively a destructive, read-once operation. 8570 * 8571 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8572 * 8573 * @return {WordArray} The hash. 8574 * 8575 * @example 8576 * 8577 * var hash = hasher.finalize(); 8578 * var hash = hasher.finalize('message'); 8579 * var hash = hasher.finalize(wordArray); 8580 */ 8581 finalize: function (messageUpdate) { 8582 // Final message update 8583 if (messageUpdate) { 8584 this._append(messageUpdate); 8585 } 8586 8587 // Perform concrete-hasher logic 8588 var hash = this._doFinalize(); 8589 8590 return hash; 8591 }, 8592 8593 blockSize: 512/32, 8594 8595 /** 8596 * Creates a shortcut function to a hasher's object interface. 8597 * 8598 * @param {Hasher} hasher The hasher to create a helper for. 8599 * 8600 * @return {Function} The shortcut function. 8601 * 8602 * @static 8603 * 8604 * @example 8605 * 8606 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8607 */ 8608 _createHelper: function (hasher) { 8609 return function (message, cfg) { 8610 return new hasher.init(cfg).finalize(message); 8611 }; 8612 }, 8613 8614 /** 8615 * Creates a shortcut function to the HMAC's object interface. 8616 * 8617 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8618 * 8619 * @return {Function} The shortcut function. 8620 * 8621 * @static 8622 * 8623 * @example 8624 * 8625 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8626 */ 8627 _createHmacHelper: function (hasher) { 8628 return function (message, key) { 8629 return new C_algo.HMAC.init(hasher, key).finalize(message); 8630 }; 8631 } 8632 }); 8633 8634 /** 8635 * Algorithm namespace. 8636 */ 8637 var C_algo = C.algo = {}; 8638 8639 return C; 8640 }(Math)); 8641 8642 8643 return CryptoJS; 8644 8645 })); 8646 },{}],54:[function(require,module,exports){ 8647 ;(function (root, factory) { 8648 if (typeof exports === "object") { 8649 // CommonJS 8650 module.exports = exports = factory(require("./core")); 8651 } 8652 else if (typeof define === "function" && define.amd) { 8653 // AMD 8654 define(["./core"], factory); 8655 } 8656 else { 8657 // Global (browser) 8658 factory(root.CryptoJS); 8659 } 8660 }(this, function (CryptoJS) { 8661 8662 (function () { 8663 // Shortcuts 8664 var C = CryptoJS; 8665 var C_lib = C.lib; 8666 var WordArray = C_lib.WordArray; 8667 var C_enc = C.enc; 8668 8669 /** 8670 * Base64 encoding strategy. 8671 */ 8672 var Base64 = C_enc.Base64 = { 8673 /** 8674 * Converts a word array to a Base64 string. 8675 * 8676 * @param {WordArray} wordArray The word array. 8677 * 8678 * @return {string} The Base64 string. 8679 * 8680 * @static 8681 * 8682 * @example 8683 * 8684 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8685 */ 8686 stringify: function (wordArray) { 8687 // Shortcuts 8688 var words = wordArray.words; 8689 var sigBytes = wordArray.sigBytes; 8690 var map = this._map; 8691 8692 // Clamp excess bits 8693 wordArray.clamp(); 8694 8695 // Convert 8696 var base64Chars = []; 8697 for (var i = 0; i < sigBytes; i += 3) { 8698 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8699 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8700 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8701 8702 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8703 8704 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8705 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8706 } 8707 } 8708 8709 // Add padding 8710 var paddingChar = map.charAt(64); 8711 if (paddingChar) { 8712 while (base64Chars.length % 4) { 8713 base64Chars.push(paddingChar); 8714 } 8715 } 8716 8717 return base64Chars.join(''); 8718 }, 8719 8720 /** 8721 * Converts a Base64 string to a word array. 8722 * 8723 * @param {string} base64Str The Base64 string. 8724 * 8725 * @return {WordArray} The word array. 8726 * 8727 * @static 8728 * 8729 * @example 8730 * 8731 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8732 */ 8733 parse: function (base64Str) { 8734 // Shortcuts 8735 var base64StrLength = base64Str.length; 8736 var map = this._map; 8737 var reverseMap = this._reverseMap; 8738 8739 if (!reverseMap) { 8740 reverseMap = this._reverseMap = []; 8741 for (var j = 0; j < map.length; j++) { 8742 reverseMap[map.charCodeAt(j)] = j; 8743 } 8744 } 8745 8746 // Ignore padding 8747 var paddingChar = map.charAt(64); 8748 if (paddingChar) { 8749 var paddingIndex = base64Str.indexOf(paddingChar); 8750 if (paddingIndex !== -1) { 8751 base64StrLength = paddingIndex; 8752 } 8753 } 8754 8755 // Convert 8756 return parseLoop(base64Str, base64StrLength, reverseMap); 8757 8758 }, 8759 8760 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8761 }; 8762 8763 function parseLoop(base64Str, base64StrLength, reverseMap) { 8764 var words = []; 8765 var nBytes = 0; 8766 for (var i = 0; i < base64StrLength; i++) { 8767 if (i % 4) { 8768 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8769 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8770 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8771 nBytes++; 8772 } 8773 } 8774 return WordArray.create(words, nBytes); 8775 } 8776 }()); 8777 8778 8779 return CryptoJS.enc.Base64; 8780 8781 })); 8782 },{"./core":53}],55:[function(require,module,exports){ 8783 ;(function (root, factory) { 8784 if (typeof exports === "object") { 8785 // CommonJS 8786 module.exports = exports = factory(require("./core")); 8787 } 8788 else if (typeof define === "function" && define.amd) { 8789 // AMD 8790 define(["./core"], factory); 8791 } 8792 else { 8793 // Global (browser) 8794 factory(root.CryptoJS); 8795 } 8796 }(this, function (CryptoJS) { 8797 8798 (function () { 8799 // Shortcuts 8800 var C = CryptoJS; 8801 var C_lib = C.lib; 8802 var WordArray = C_lib.WordArray; 8803 var C_enc = C.enc; 8804 8805 /** 8806 * UTF-16 BE encoding strategy. 8807 */ 8808 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8809 /** 8810 * Converts a word array to a UTF-16 BE string. 8811 * 8812 * @param {WordArray} wordArray The word array. 8813 * 8814 * @return {string} The UTF-16 BE string. 8815 * 8816 * @static 8817 * 8818 * @example 8819 * 8820 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8821 */ 8822 stringify: function (wordArray) { 8823 // Shortcuts 8824 var words = wordArray.words; 8825 var sigBytes = wordArray.sigBytes; 8826 8827 // Convert 8828 var utf16Chars = []; 8829 for (var i = 0; i < sigBytes; i += 2) { 8830 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8831 utf16Chars.push(String.fromCharCode(codePoint)); 8832 } 8833 8834 return utf16Chars.join(''); 8835 }, 8836 8837 /** 8838 * Converts a UTF-16 BE string to a word array. 8839 * 8840 * @param {string} utf16Str The UTF-16 BE string. 8841 * 8842 * @return {WordArray} The word array. 8843 * 8844 * @static 8845 * 8846 * @example 8847 * 8848 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8849 */ 8850 parse: function (utf16Str) { 8851 // Shortcut 8852 var utf16StrLength = utf16Str.length; 8853 8854 // Convert 8855 var words = []; 8856 for (var i = 0; i < utf16StrLength; i++) { 8857 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 8858 } 8859 8860 return WordArray.create(words, utf16StrLength * 2); 8861 } 8862 }; 8863 8864 /** 8865 * UTF-16 LE encoding strategy. 8866 */ 8867 C_enc.Utf16LE = { 8868 /** 8869 * Converts a word array to a UTF-16 LE string. 8870 * 8871 * @param {WordArray} wordArray The word array. 8872 * 8873 * @return {string} The UTF-16 LE string. 8874 * 8875 * @static 8876 * 8877 * @example 8878 * 8879 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 8880 */ 8881 stringify: function (wordArray) { 8882 // Shortcuts 8883 var words = wordArray.words; 8884 var sigBytes = wordArray.sigBytes; 8885 8886 // Convert 8887 var utf16Chars = []; 8888 for (var i = 0; i < sigBytes; i += 2) { 8889 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 8890 utf16Chars.push(String.fromCharCode(codePoint)); 8891 } 8892 8893 return utf16Chars.join(''); 8894 }, 8895 8896 /** 8897 * Converts a UTF-16 LE string to a word array. 8898 * 8899 * @param {string} utf16Str The UTF-16 LE string. 8900 * 8901 * @return {WordArray} The word array. 8902 * 8903 * @static 8904 * 8905 * @example 8906 * 8907 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 8908 */ 8909 parse: function (utf16Str) { 8910 // Shortcut 8911 var utf16StrLength = utf16Str.length; 8912 8913 // Convert 8914 var words = []; 8915 for (var i = 0; i < utf16StrLength; i++) { 8916 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 8917 } 8918 8919 return WordArray.create(words, utf16StrLength * 2); 8920 } 8921 }; 8922 8923 function swapEndian(word) { 8924 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 8925 } 8926 }()); 8927 8928 8929 return CryptoJS.enc.Utf16; 8930 8931 })); 8932 },{"./core":53}],56:[function(require,module,exports){ 8933 ;(function (root, factory, undef) { 8934 if (typeof exports === "object") { 8935 // CommonJS 8936 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 8937 } 8938 else if (typeof define === "function" && define.amd) { 8939 // AMD 8940 define(["./core", "./sha1", "./hmac"], factory); 8941 } 8942 else { 8943 // Global (browser) 8944 factory(root.CryptoJS); 8945 } 8946 }(this, function (CryptoJS) { 8947 8948 (function () { 8949 // Shortcuts 8950 var C = CryptoJS; 8951 var C_lib = C.lib; 8952 var Base = C_lib.Base; 8953 var WordArray = C_lib.WordArray; 8954 var C_algo = C.algo; 8955 var MD5 = C_algo.MD5; 8956 8957 /** 8958 * This key derivation function is meant to conform with EVP_BytesToKey. 8959 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 8960 */ 8961 var EvpKDF = C_algo.EvpKDF = Base.extend({ 8962 /** 8963 * Configuration options. 8964 * 8965 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 8966 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 8967 * @property {number} iterations The number of iterations to perform. Default: 1 8968 */ 8969 cfg: Base.extend({ 8970 keySize: 128/32, 8971 hasher: MD5, 8972 iterations: 1 8973 }), 8974 8975 /** 8976 * Initializes a newly created key derivation function. 8977 * 8978 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 8979 * 8980 * @example 8981 * 8982 * var kdf = CryptoJS.algo.EvpKDF.create(); 8983 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 8984 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 8985 */ 8986 init: function (cfg) { 8987 this.cfg = this.cfg.extend(cfg); 8988 }, 8989 8990 /** 8991 * Derives a key from a password. 8992 * 8993 * @param {WordArray|string} password The password. 8994 * @param {WordArray|string} salt A salt. 8995 * 8996 * @return {WordArray} The derived key. 8997 * 8998 * @example 8999 * 9000 * var key = kdf.compute(password, salt); 9001 */ 9002 compute: function (password, salt) { 9003 // Shortcut 9004 var cfg = this.cfg; 9005 9006 // Init hasher 9007 var hasher = cfg.hasher.create(); 9008 9009 // Initial values 9010 var derivedKey = WordArray.create(); 9011 9012 // Shortcuts 9013 var derivedKeyWords = derivedKey.words; 9014 var keySize = cfg.keySize; 9015 var iterations = cfg.iterations; 9016 9017 // Generate key 9018 while (derivedKeyWords.length < keySize) { 9019 if (block) { 9020 hasher.update(block); 9021 } 9022 var block = hasher.update(password).finalize(salt); 9023 hasher.reset(); 9024 9025 // Iterations 9026 for (var i = 1; i < iterations; i++) { 9027 block = hasher.finalize(block); 9028 hasher.reset(); 9029 } 9030 9031 derivedKey.concat(block); 9032 } 9033 derivedKey.sigBytes = keySize * 4; 9034 9035 return derivedKey; 9036 } 9037 }); 9038 9039 /** 9040 * Derives a key from a password. 9041 * 9042 * @param {WordArray|string} password The password. 9043 * @param {WordArray|string} salt A salt. 9044 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9045 * 9046 * @return {WordArray} The derived key. 9047 * 9048 * @static 9049 * 9050 * @example 9051 * 9052 * var key = CryptoJS.EvpKDF(password, salt); 9053 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9054 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9055 */ 9056 C.EvpKDF = function (password, salt, cfg) { 9057 return EvpKDF.create(cfg).compute(password, salt); 9058 }; 9059 }()); 9060 9061 9062 return CryptoJS.EvpKDF; 9063 9064 })); 9065 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 9066 ;(function (root, factory, undef) { 9067 if (typeof exports === "object") { 9068 // CommonJS 9069 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9070 } 9071 else if (typeof define === "function" && define.amd) { 9072 // AMD 9073 define(["./core", "./cipher-core"], factory); 9074 } 9075 else { 9076 // Global (browser) 9077 factory(root.CryptoJS); 9078 } 9079 }(this, function (CryptoJS) { 9080 9081 (function (undefined) { 9082 // Shortcuts 9083 var C = CryptoJS; 9084 var C_lib = C.lib; 9085 var CipherParams = C_lib.CipherParams; 9086 var C_enc = C.enc; 9087 var Hex = C_enc.Hex; 9088 var C_format = C.format; 9089 9090 var HexFormatter = C_format.Hex = { 9091 /** 9092 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9093 * 9094 * @param {CipherParams} cipherParams The cipher params object. 9095 * 9096 * @return {string} The hexadecimally encoded string. 9097 * 9098 * @static 9099 * 9100 * @example 9101 * 9102 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9103 */ 9104 stringify: function (cipherParams) { 9105 return cipherParams.ciphertext.toString(Hex); 9106 }, 9107 9108 /** 9109 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9110 * 9111 * @param {string} input The hexadecimally encoded string. 9112 * 9113 * @return {CipherParams} The cipher params object. 9114 * 9115 * @static 9116 * 9117 * @example 9118 * 9119 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9120 */ 9121 parse: function (input) { 9122 var ciphertext = Hex.parse(input); 9123 return CipherParams.create({ ciphertext: ciphertext }); 9124 } 9125 }; 9126 }()); 9127 9128 9129 return CryptoJS.format.Hex; 9130 9131 })); 9132 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 9133 ;(function (root, factory) { 9134 if (typeof exports === "object") { 9135 // CommonJS 9136 module.exports = exports = factory(require("./core")); 9137 } 9138 else if (typeof define === "function" && define.amd) { 9139 // AMD 9140 define(["./core"], factory); 9141 } 9142 else { 9143 // Global (browser) 9144 factory(root.CryptoJS); 9145 } 9146 }(this, function (CryptoJS) { 9147 9148 (function () { 9149 // Shortcuts 9150 var C = CryptoJS; 9151 var C_lib = C.lib; 9152 var Base = C_lib.Base; 9153 var C_enc = C.enc; 9154 var Utf8 = C_enc.Utf8; 9155 var C_algo = C.algo; 9156 9157 /** 9158 * HMAC algorithm. 9159 */ 9160 var HMAC = C_algo.HMAC = Base.extend({ 9161 /** 9162 * Initializes a newly created HMAC. 9163 * 9164 * @param {Hasher} hasher The hash algorithm to use. 9165 * @param {WordArray|string} key The secret key. 9166 * 9167 * @example 9168 * 9169 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9170 */ 9171 init: function (hasher, key) { 9172 // Init hasher 9173 hasher = this._hasher = new hasher.init(); 9174 9175 // Convert string to WordArray, else assume WordArray already 9176 if (typeof key == 'string') { 9177 key = Utf8.parse(key); 9178 } 9179 9180 // Shortcuts 9181 var hasherBlockSize = hasher.blockSize; 9182 var hasherBlockSizeBytes = hasherBlockSize * 4; 9183 9184 // Allow arbitrary length keys 9185 if (key.sigBytes > hasherBlockSizeBytes) { 9186 key = hasher.finalize(key); 9187 } 9188 9189 // Clamp excess bits 9190 key.clamp(); 9191 9192 // Clone key for inner and outer pads 9193 var oKey = this._oKey = key.clone(); 9194 var iKey = this._iKey = key.clone(); 9195 9196 // Shortcuts 9197 var oKeyWords = oKey.words; 9198 var iKeyWords = iKey.words; 9199 9200 // XOR keys with pad constants 9201 for (var i = 0; i < hasherBlockSize; i++) { 9202 oKeyWords[i] ^= 0x5c5c5c5c; 9203 iKeyWords[i] ^= 0x36363636; 9204 } 9205 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9206 9207 // Set initial values 9208 this.reset(); 9209 }, 9210 9211 /** 9212 * Resets this HMAC to its initial state. 9213 * 9214 * @example 9215 * 9216 * hmacHasher.reset(); 9217 */ 9218 reset: function () { 9219 // Shortcut 9220 var hasher = this._hasher; 9221 9222 // Reset 9223 hasher.reset(); 9224 hasher.update(this._iKey); 9225 }, 9226 9227 /** 9228 * Updates this HMAC with a message. 9229 * 9230 * @param {WordArray|string} messageUpdate The message to append. 9231 * 9232 * @return {HMAC} This HMAC instance. 9233 * 9234 * @example 9235 * 9236 * hmacHasher.update('message'); 9237 * hmacHasher.update(wordArray); 9238 */ 9239 update: function (messageUpdate) { 9240 this._hasher.update(messageUpdate); 9241 9242 // Chainable 9243 return this; 9244 }, 9245 9246 /** 9247 * Finalizes the HMAC computation. 9248 * Note that the finalize operation is effectively a destructive, read-once operation. 9249 * 9250 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9251 * 9252 * @return {WordArray} The HMAC. 9253 * 9254 * @example 9255 * 9256 * var hmac = hmacHasher.finalize(); 9257 * var hmac = hmacHasher.finalize('message'); 9258 * var hmac = hmacHasher.finalize(wordArray); 9259 */ 9260 finalize: function (messageUpdate) { 9261 // Shortcut 9262 var hasher = this._hasher; 9263 9264 // Compute HMAC 9265 var innerHash = hasher.finalize(messageUpdate); 9266 hasher.reset(); 9267 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9268 9269 return hmac; 9270 } 9271 }); 9272 }()); 9273 9274 9275 })); 9276 },{"./core":53}],59:[function(require,module,exports){ 9277 ;(function (root, factory, undef) { 9278 if (typeof exports === "object") { 9279 // CommonJS 9280 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")); 9281 } 9282 else if (typeof define === "function" && define.amd) { 9283 // AMD 9284 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); 9285 } 9286 else { 9287 // Global (browser) 9288 root.CryptoJS = factory(root.CryptoJS); 9289 } 9290 }(this, function (CryptoJS) { 9291 9292 return CryptoJS; 9293 9294 })); 9295 },{"./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){ 9296 ;(function (root, factory) { 9297 if (typeof exports === "object") { 9298 // CommonJS 9299 module.exports = exports = factory(require("./core")); 9300 } 9301 else if (typeof define === "function" && define.amd) { 9302 // AMD 9303 define(["./core"], factory); 9304 } 9305 else { 9306 // Global (browser) 9307 factory(root.CryptoJS); 9308 } 9309 }(this, function (CryptoJS) { 9310 9311 (function () { 9312 // Check if typed arrays are supported 9313 if (typeof ArrayBuffer != 'function') { 9314 return; 9315 } 9316 9317 // Shortcuts 9318 var C = CryptoJS; 9319 var C_lib = C.lib; 9320 var WordArray = C_lib.WordArray; 9321 9322 // Reference original init 9323 var superInit = WordArray.init; 9324 9325 // Augment WordArray.init to handle typed arrays 9326 var subInit = WordArray.init = function (typedArray) { 9327 // Convert buffers to uint8 9328 if (typedArray instanceof ArrayBuffer) { 9329 typedArray = new Uint8Array(typedArray); 9330 } 9331 9332 // Convert other array views to uint8 9333 if ( 9334 typedArray instanceof Int8Array || 9335 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9336 typedArray instanceof Int16Array || 9337 typedArray instanceof Uint16Array || 9338 typedArray instanceof Int32Array || 9339 typedArray instanceof Uint32Array || 9340 typedArray instanceof Float32Array || 9341 typedArray instanceof Float64Array 9342 ) { 9343 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9344 } 9345 9346 // Handle Uint8Array 9347 if (typedArray instanceof Uint8Array) { 9348 // Shortcut 9349 var typedArrayByteLength = typedArray.byteLength; 9350 9351 // Extract bytes 9352 var words = []; 9353 for (var i = 0; i < typedArrayByteLength; i++) { 9354 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9355 } 9356 9357 // Initialize this word array 9358 superInit.call(this, words, typedArrayByteLength); 9359 } else { 9360 // Else call normal init 9361 superInit.apply(this, arguments); 9362 } 9363 }; 9364 9365 subInit.prototype = WordArray; 9366 }()); 9367 9368 9369 return CryptoJS.lib.WordArray; 9370 9371 })); 9372 },{"./core":53}],61:[function(require,module,exports){ 9373 ;(function (root, factory) { 9374 if (typeof exports === "object") { 9375 // CommonJS 9376 module.exports = exports = factory(require("./core")); 9377 } 9378 else if (typeof define === "function" && define.amd) { 9379 // AMD 9380 define(["./core"], factory); 9381 } 9382 else { 9383 // Global (browser) 9384 factory(root.CryptoJS); 9385 } 9386 }(this, function (CryptoJS) { 9387 9388 (function (Math) { 9389 // Shortcuts 9390 var C = CryptoJS; 9391 var C_lib = C.lib; 9392 var WordArray = C_lib.WordArray; 9393 var Hasher = C_lib.Hasher; 9394 var C_algo = C.algo; 9395 9396 // Constants table 9397 var T = []; 9398 9399 // Compute constants 9400 (function () { 9401 for (var i = 0; i < 64; i++) { 9402 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9403 } 9404 }()); 9405 9406 /** 9407 * MD5 hash algorithm. 9408 */ 9409 var MD5 = C_algo.MD5 = Hasher.extend({ 9410 _doReset: function () { 9411 this._hash = new WordArray.init([ 9412 0x67452301, 0xefcdab89, 9413 0x98badcfe, 0x10325476 9414 ]); 9415 }, 9416 9417 _doProcessBlock: function (M, offset) { 9418 // Swap endian 9419 for (var i = 0; i < 16; i++) { 9420 // Shortcuts 9421 var offset_i = offset + i; 9422 var M_offset_i = M[offset_i]; 9423 9424 M[offset_i] = ( 9425 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9426 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9427 ); 9428 } 9429 9430 // Shortcuts 9431 var H = this._hash.words; 9432 9433 var M_offset_0 = M[offset + 0]; 9434 var M_offset_1 = M[offset + 1]; 9435 var M_offset_2 = M[offset + 2]; 9436 var M_offset_3 = M[offset + 3]; 9437 var M_offset_4 = M[offset + 4]; 9438 var M_offset_5 = M[offset + 5]; 9439 var M_offset_6 = M[offset + 6]; 9440 var M_offset_7 = M[offset + 7]; 9441 var M_offset_8 = M[offset + 8]; 9442 var M_offset_9 = M[offset + 9]; 9443 var M_offset_10 = M[offset + 10]; 9444 var M_offset_11 = M[offset + 11]; 9445 var M_offset_12 = M[offset + 12]; 9446 var M_offset_13 = M[offset + 13]; 9447 var M_offset_14 = M[offset + 14]; 9448 var M_offset_15 = M[offset + 15]; 9449 9450 // Working varialbes 9451 var a = H[0]; 9452 var b = H[1]; 9453 var c = H[2]; 9454 var d = H[3]; 9455 9456 // Computation 9457 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9458 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9459 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9460 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9461 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9462 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9463 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9464 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9465 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9466 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9467 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9468 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9469 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9470 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9471 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9472 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9473 9474 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9475 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9476 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9477 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9478 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9479 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9480 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9481 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9482 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9483 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9484 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9485 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9486 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9487 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9488 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9489 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9490 9491 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9492 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9493 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9494 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9495 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9496 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9497 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9498 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9499 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9500 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9501 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9502 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9503 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9504 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9505 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9506 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9507 9508 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9509 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9510 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9511 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9512 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9513 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9514 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9515 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9516 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9517 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9518 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9519 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9520 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9521 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9522 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9523 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9524 9525 // Intermediate hash value 9526 H[0] = (H[0] + a) | 0; 9527 H[1] = (H[1] + b) | 0; 9528 H[2] = (H[2] + c) | 0; 9529 H[3] = (H[3] + d) | 0; 9530 }, 9531 9532 _doFinalize: function () { 9533 // Shortcuts 9534 var data = this._data; 9535 var dataWords = data.words; 9536 9537 var nBitsTotal = this._nDataBytes * 8; 9538 var nBitsLeft = data.sigBytes * 8; 9539 9540 // Add padding 9541 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9542 9543 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9544 var nBitsTotalL = nBitsTotal; 9545 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9546 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9547 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9548 ); 9549 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9550 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9551 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9552 ); 9553 9554 data.sigBytes = (dataWords.length + 1) * 4; 9555 9556 // Hash final blocks 9557 this._process(); 9558 9559 // Shortcuts 9560 var hash = this._hash; 9561 var H = hash.words; 9562 9563 // Swap endian 9564 for (var i = 0; i < 4; i++) { 9565 // Shortcut 9566 var H_i = H[i]; 9567 9568 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9569 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9570 } 9571 9572 // Return final computed hash 9573 return hash; 9574 }, 9575 9576 clone: function () { 9577 var clone = Hasher.clone.call(this); 9578 clone._hash = this._hash.clone(); 9579 9580 return clone; 9581 } 9582 }); 9583 9584 function FF(a, b, c, d, x, s, t) { 9585 var n = a + ((b & c) | (~b & d)) + x + t; 9586 return ((n << s) | (n >>> (32 - s))) + b; 9587 } 9588 9589 function GG(a, b, c, d, x, s, t) { 9590 var n = a + ((b & d) | (c & ~d)) + x + t; 9591 return ((n << s) | (n >>> (32 - s))) + b; 9592 } 9593 9594 function HH(a, b, c, d, x, s, t) { 9595 var n = a + (b ^ c ^ d) + x + t; 9596 return ((n << s) | (n >>> (32 - s))) + b; 9597 } 9598 9599 function II(a, b, c, d, x, s, t) { 9600 var n = a + (c ^ (b | ~d)) + x + t; 9601 return ((n << s) | (n >>> (32 - s))) + b; 9602 } 9603 9604 /** 9605 * Shortcut function to the hasher's object interface. 9606 * 9607 * @param {WordArray|string} message The message to hash. 9608 * 9609 * @return {WordArray} The hash. 9610 * 9611 * @static 9612 * 9613 * @example 9614 * 9615 * var hash = CryptoJS.MD5('message'); 9616 * var hash = CryptoJS.MD5(wordArray); 9617 */ 9618 C.MD5 = Hasher._createHelper(MD5); 9619 9620 /** 9621 * Shortcut function to the HMAC's object interface. 9622 * 9623 * @param {WordArray|string} message The message to hash. 9624 * @param {WordArray|string} key The secret key. 9625 * 9626 * @return {WordArray} The HMAC. 9627 * 9628 * @static 9629 * 9630 * @example 9631 * 9632 * var hmac = CryptoJS.HmacMD5(message, key); 9633 */ 9634 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9635 }(Math)); 9636 9637 9638 return CryptoJS.MD5; 9639 9640 })); 9641 },{"./core":53}],62:[function(require,module,exports){ 9642 ;(function (root, factory, undef) { 9643 if (typeof exports === "object") { 9644 // CommonJS 9645 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9646 } 9647 else if (typeof define === "function" && define.amd) { 9648 // AMD 9649 define(["./core", "./cipher-core"], factory); 9650 } 9651 else { 9652 // Global (browser) 9653 factory(root.CryptoJS); 9654 } 9655 }(this, function (CryptoJS) { 9656 9657 /** 9658 * Cipher Feedback block mode. 9659 */ 9660 CryptoJS.mode.CFB = (function () { 9661 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9662 9663 CFB.Encryptor = CFB.extend({ 9664 processBlock: function (words, offset) { 9665 // Shortcuts 9666 var cipher = this._cipher; 9667 var blockSize = cipher.blockSize; 9668 9669 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9670 9671 // Remember this block to use with next block 9672 this._prevBlock = words.slice(offset, offset + blockSize); 9673 } 9674 }); 9675 9676 CFB.Decryptor = CFB.extend({ 9677 processBlock: function (words, offset) { 9678 // Shortcuts 9679 var cipher = this._cipher; 9680 var blockSize = cipher.blockSize; 9681 9682 // Remember this block to use with next block 9683 var thisBlock = words.slice(offset, offset + blockSize); 9684 9685 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9686 9687 // This block becomes the previous block 9688 this._prevBlock = thisBlock; 9689 } 9690 }); 9691 9692 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9693 // Shortcut 9694 var iv = this._iv; 9695 9696 // Generate keystream 9697 if (iv) { 9698 var keystream = iv.slice(0); 9699 9700 // Remove IV for subsequent blocks 9701 this._iv = undefined; 9702 } else { 9703 var keystream = this._prevBlock; 9704 } 9705 cipher.encryptBlock(keystream, 0); 9706 9707 // Encrypt 9708 for (var i = 0; i < blockSize; i++) { 9709 words[offset + i] ^= keystream[i]; 9710 } 9711 } 9712 9713 return CFB; 9714 }()); 9715 9716 9717 return CryptoJS.mode.CFB; 9718 9719 })); 9720 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 9721 ;(function (root, factory, undef) { 9722 if (typeof exports === "object") { 9723 // CommonJS 9724 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9725 } 9726 else if (typeof define === "function" && define.amd) { 9727 // AMD 9728 define(["./core", "./cipher-core"], factory); 9729 } 9730 else { 9731 // Global (browser) 9732 factory(root.CryptoJS); 9733 } 9734 }(this, function (CryptoJS) { 9735 9736 /** @preserve 9737 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9738 * derived from CryptoJS.mode.CTR 9739 * Jan Hruby jhruby.web@gmail.com 9740 */ 9741 CryptoJS.mode.CTRGladman = (function () { 9742 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9743 9744 function incWord(word) 9745 { 9746 if (((word >> 24) & 0xff) === 0xff) { //overflow 9747 var b1 = (word >> 16)&0xff; 9748 var b2 = (word >> 8)&0xff; 9749 var b3 = word & 0xff; 9750 9751 if (b1 === 0xff) // overflow b1 9752 { 9753 b1 = 0; 9754 if (b2 === 0xff) 9755 { 9756 b2 = 0; 9757 if (b3 === 0xff) 9758 { 9759 b3 = 0; 9760 } 9761 else 9762 { 9763 ++b3; 9764 } 9765 } 9766 else 9767 { 9768 ++b2; 9769 } 9770 } 9771 else 9772 { 9773 ++b1; 9774 } 9775 9776 word = 0; 9777 word += (b1 << 16); 9778 word += (b2 << 8); 9779 word += b3; 9780 } 9781 else 9782 { 9783 word += (0x01 << 24); 9784 } 9785 return word; 9786 } 9787 9788 function incCounter(counter) 9789 { 9790 if ((counter[0] = incWord(counter[0])) === 0) 9791 { 9792 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9793 counter[1] = incWord(counter[1]); 9794 } 9795 return counter; 9796 } 9797 9798 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9799 processBlock: function (words, offset) { 9800 // Shortcuts 9801 var cipher = this._cipher 9802 var blockSize = cipher.blockSize; 9803 var iv = this._iv; 9804 var counter = this._counter; 9805 9806 // Generate keystream 9807 if (iv) { 9808 counter = this._counter = iv.slice(0); 9809 9810 // Remove IV for subsequent blocks 9811 this._iv = undefined; 9812 } 9813 9814 incCounter(counter); 9815 9816 var keystream = counter.slice(0); 9817 cipher.encryptBlock(keystream, 0); 9818 9819 // Encrypt 9820 for (var i = 0; i < blockSize; i++) { 9821 words[offset + i] ^= keystream[i]; 9822 } 9823 } 9824 }); 9825 9826 CTRGladman.Decryptor = Encryptor; 9827 9828 return CTRGladman; 9829 }()); 9830 9831 9832 9833 9834 return CryptoJS.mode.CTRGladman; 9835 9836 })); 9837 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 9838 ;(function (root, factory, undef) { 9839 if (typeof exports === "object") { 9840 // CommonJS 9841 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9842 } 9843 else if (typeof define === "function" && define.amd) { 9844 // AMD 9845 define(["./core", "./cipher-core"], factory); 9846 } 9847 else { 9848 // Global (browser) 9849 factory(root.CryptoJS); 9850 } 9851 }(this, function (CryptoJS) { 9852 9853 /** 9854 * Counter block mode. 9855 */ 9856 CryptoJS.mode.CTR = (function () { 9857 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 9858 9859 var Encryptor = CTR.Encryptor = CTR.extend({ 9860 processBlock: function (words, offset) { 9861 // Shortcuts 9862 var cipher = this._cipher 9863 var blockSize = cipher.blockSize; 9864 var iv = this._iv; 9865 var counter = this._counter; 9866 9867 // Generate keystream 9868 if (iv) { 9869 counter = this._counter = iv.slice(0); 9870 9871 // Remove IV for subsequent blocks 9872 this._iv = undefined; 9873 } 9874 var keystream = counter.slice(0); 9875 cipher.encryptBlock(keystream, 0); 9876 9877 // Increment counter 9878 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 9879 9880 // Encrypt 9881 for (var i = 0; i < blockSize; i++) { 9882 words[offset + i] ^= keystream[i]; 9883 } 9884 } 9885 }); 9886 9887 CTR.Decryptor = Encryptor; 9888 9889 return CTR; 9890 }()); 9891 9892 9893 return CryptoJS.mode.CTR; 9894 9895 })); 9896 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 9897 ;(function (root, factory, undef) { 9898 if (typeof exports === "object") { 9899 // CommonJS 9900 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9901 } 9902 else if (typeof define === "function" && define.amd) { 9903 // AMD 9904 define(["./core", "./cipher-core"], factory); 9905 } 9906 else { 9907 // Global (browser) 9908 factory(root.CryptoJS); 9909 } 9910 }(this, function (CryptoJS) { 9911 9912 /** 9913 * Electronic Codebook block mode. 9914 */ 9915 CryptoJS.mode.ECB = (function () { 9916 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 9917 9918 ECB.Encryptor = ECB.extend({ 9919 processBlock: function (words, offset) { 9920 this._cipher.encryptBlock(words, offset); 9921 } 9922 }); 9923 9924 ECB.Decryptor = ECB.extend({ 9925 processBlock: function (words, offset) { 9926 this._cipher.decryptBlock(words, offset); 9927 } 9928 }); 9929 9930 return ECB; 9931 }()); 9932 9933 9934 return CryptoJS.mode.ECB; 9935 9936 })); 9937 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 9938 ;(function (root, factory, undef) { 9939 if (typeof exports === "object") { 9940 // CommonJS 9941 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9942 } 9943 else if (typeof define === "function" && define.amd) { 9944 // AMD 9945 define(["./core", "./cipher-core"], factory); 9946 } 9947 else { 9948 // Global (browser) 9949 factory(root.CryptoJS); 9950 } 9951 }(this, function (CryptoJS) { 9952 9953 /** 9954 * Output Feedback block mode. 9955 */ 9956 CryptoJS.mode.OFB = (function () { 9957 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 9958 9959 var Encryptor = OFB.Encryptor = OFB.extend({ 9960 processBlock: function (words, offset) { 9961 // Shortcuts 9962 var cipher = this._cipher 9963 var blockSize = cipher.blockSize; 9964 var iv = this._iv; 9965 var keystream = this._keystream; 9966 9967 // Generate keystream 9968 if (iv) { 9969 keystream = this._keystream = iv.slice(0); 9970 9971 // Remove IV for subsequent blocks 9972 this._iv = undefined; 9973 } 9974 cipher.encryptBlock(keystream, 0); 9975 9976 // Encrypt 9977 for (var i = 0; i < blockSize; i++) { 9978 words[offset + i] ^= keystream[i]; 9979 } 9980 } 9981 }); 9982 9983 OFB.Decryptor = Encryptor; 9984 9985 return OFB; 9986 }()); 9987 9988 9989 return CryptoJS.mode.OFB; 9990 9991 })); 9992 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 9993 ;(function (root, factory, undef) { 9994 if (typeof exports === "object") { 9995 // CommonJS 9996 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9997 } 9998 else if (typeof define === "function" && define.amd) { 9999 // AMD 10000 define(["./core", "./cipher-core"], factory); 10001 } 10002 else { 10003 // Global (browser) 10004 factory(root.CryptoJS); 10005 } 10006 }(this, function (CryptoJS) { 10007 10008 /** 10009 * ANSI X.923 padding strategy. 10010 */ 10011 CryptoJS.pad.AnsiX923 = { 10012 pad: function (data, blockSize) { 10013 // Shortcuts 10014 var dataSigBytes = data.sigBytes; 10015 var blockSizeBytes = blockSize * 4; 10016 10017 // Count padding bytes 10018 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10019 10020 // Compute last byte position 10021 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10022 10023 // Pad 10024 data.clamp(); 10025 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10026 data.sigBytes += nPaddingBytes; 10027 }, 10028 10029 unpad: function (data) { 10030 // Get number of padding bytes from last byte 10031 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10032 10033 // Remove padding 10034 data.sigBytes -= nPaddingBytes; 10035 } 10036 }; 10037 10038 10039 return CryptoJS.pad.Ansix923; 10040 10041 })); 10042 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 10043 ;(function (root, factory, undef) { 10044 if (typeof exports === "object") { 10045 // CommonJS 10046 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10047 } 10048 else if (typeof define === "function" && define.amd) { 10049 // AMD 10050 define(["./core", "./cipher-core"], factory); 10051 } 10052 else { 10053 // Global (browser) 10054 factory(root.CryptoJS); 10055 } 10056 }(this, function (CryptoJS) { 10057 10058 /** 10059 * ISO 10126 padding strategy. 10060 */ 10061 CryptoJS.pad.Iso10126 = { 10062 pad: function (data, blockSize) { 10063 // Shortcut 10064 var blockSizeBytes = blockSize * 4; 10065 10066 // Count padding bytes 10067 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10068 10069 // Pad 10070 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10071 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10072 }, 10073 10074 unpad: function (data) { 10075 // Get number of padding bytes from last byte 10076 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10077 10078 // Remove padding 10079 data.sigBytes -= nPaddingBytes; 10080 } 10081 }; 10082 10083 10084 return CryptoJS.pad.Iso10126; 10085 10086 })); 10087 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 10088 ;(function (root, factory, undef) { 10089 if (typeof exports === "object") { 10090 // CommonJS 10091 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10092 } 10093 else if (typeof define === "function" && define.amd) { 10094 // AMD 10095 define(["./core", "./cipher-core"], factory); 10096 } 10097 else { 10098 // Global (browser) 10099 factory(root.CryptoJS); 10100 } 10101 }(this, function (CryptoJS) { 10102 10103 /** 10104 * ISO/IEC 9797-1 Padding Method 2. 10105 */ 10106 CryptoJS.pad.Iso97971 = { 10107 pad: function (data, blockSize) { 10108 // Add 0x80 byte 10109 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10110 10111 // Zero pad the rest 10112 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10113 }, 10114 10115 unpad: function (data) { 10116 // Remove zero padding 10117 CryptoJS.pad.ZeroPadding.unpad(data); 10118 10119 // Remove one more byte -- the 0x80 byte 10120 data.sigBytes--; 10121 } 10122 }; 10123 10124 10125 return CryptoJS.pad.Iso97971; 10126 10127 })); 10128 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 10129 ;(function (root, factory, undef) { 10130 if (typeof exports === "object") { 10131 // CommonJS 10132 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10133 } 10134 else if (typeof define === "function" && define.amd) { 10135 // AMD 10136 define(["./core", "./cipher-core"], factory); 10137 } 10138 else { 10139 // Global (browser) 10140 factory(root.CryptoJS); 10141 } 10142 }(this, function (CryptoJS) { 10143 10144 /** 10145 * A noop padding strategy. 10146 */ 10147 CryptoJS.pad.NoPadding = { 10148 pad: function () { 10149 }, 10150 10151 unpad: function () { 10152 } 10153 }; 10154 10155 10156 return CryptoJS.pad.NoPadding; 10157 10158 })); 10159 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 10160 ;(function (root, factory, undef) { 10161 if (typeof exports === "object") { 10162 // CommonJS 10163 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10164 } 10165 else if (typeof define === "function" && define.amd) { 10166 // AMD 10167 define(["./core", "./cipher-core"], factory); 10168 } 10169 else { 10170 // Global (browser) 10171 factory(root.CryptoJS); 10172 } 10173 }(this, function (CryptoJS) { 10174 10175 /** 10176 * Zero padding strategy. 10177 */ 10178 CryptoJS.pad.ZeroPadding = { 10179 pad: function (data, blockSize) { 10180 // Shortcut 10181 var blockSizeBytes = blockSize * 4; 10182 10183 // Pad 10184 data.clamp(); 10185 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10186 }, 10187 10188 unpad: function (data) { 10189 // Shortcut 10190 var dataWords = data.words; 10191 10192 // Unpad 10193 var i = data.sigBytes - 1; 10194 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10195 i--; 10196 } 10197 data.sigBytes = i + 1; 10198 } 10199 }; 10200 10201 10202 return CryptoJS.pad.ZeroPadding; 10203 10204 })); 10205 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 10206 ;(function (root, factory, undef) { 10207 if (typeof exports === "object") { 10208 // CommonJS 10209 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10210 } 10211 else if (typeof define === "function" && define.amd) { 10212 // AMD 10213 define(["./core", "./sha1", "./hmac"], factory); 10214 } 10215 else { 10216 // Global (browser) 10217 factory(root.CryptoJS); 10218 } 10219 }(this, function (CryptoJS) { 10220 10221 (function () { 10222 // Shortcuts 10223 var C = CryptoJS; 10224 var C_lib = C.lib; 10225 var Base = C_lib.Base; 10226 var WordArray = C_lib.WordArray; 10227 var C_algo = C.algo; 10228 var SHA1 = C_algo.SHA1; 10229 var HMAC = C_algo.HMAC; 10230 10231 /** 10232 * Password-Based Key Derivation Function 2 algorithm. 10233 */ 10234 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10235 /** 10236 * Configuration options. 10237 * 10238 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10239 * @property {Hasher} hasher The hasher to use. Default: SHA1 10240 * @property {number} iterations The number of iterations to perform. Default: 1 10241 */ 10242 cfg: Base.extend({ 10243 keySize: 128/32, 10244 hasher: SHA1, 10245 iterations: 1 10246 }), 10247 10248 /** 10249 * Initializes a newly created key derivation function. 10250 * 10251 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10252 * 10253 * @example 10254 * 10255 * var kdf = CryptoJS.algo.PBKDF2.create(); 10256 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10257 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10258 */ 10259 init: function (cfg) { 10260 this.cfg = this.cfg.extend(cfg); 10261 }, 10262 10263 /** 10264 * Computes the Password-Based Key Derivation Function 2. 10265 * 10266 * @param {WordArray|string} password The password. 10267 * @param {WordArray|string} salt A salt. 10268 * 10269 * @return {WordArray} The derived key. 10270 * 10271 * @example 10272 * 10273 * var key = kdf.compute(password, salt); 10274 */ 10275 compute: function (password, salt) { 10276 // Shortcut 10277 var cfg = this.cfg; 10278 10279 // Init HMAC 10280 var hmac = HMAC.create(cfg.hasher, password); 10281 10282 // Initial values 10283 var derivedKey = WordArray.create(); 10284 var blockIndex = WordArray.create([0x00000001]); 10285 10286 // Shortcuts 10287 var derivedKeyWords = derivedKey.words; 10288 var blockIndexWords = blockIndex.words; 10289 var keySize = cfg.keySize; 10290 var iterations = cfg.iterations; 10291 10292 // Generate key 10293 while (derivedKeyWords.length < keySize) { 10294 var block = hmac.update(salt).finalize(blockIndex); 10295 hmac.reset(); 10296 10297 // Shortcuts 10298 var blockWords = block.words; 10299 var blockWordsLength = blockWords.length; 10300 10301 // Iterations 10302 var intermediate = block; 10303 for (var i = 1; i < iterations; i++) { 10304 intermediate = hmac.finalize(intermediate); 10305 hmac.reset(); 10306 10307 // Shortcut 10308 var intermediateWords = intermediate.words; 10309 10310 // XOR intermediate with block 10311 for (var j = 0; j < blockWordsLength; j++) { 10312 blockWords[j] ^= intermediateWords[j]; 10313 } 10314 } 10315 10316 derivedKey.concat(block); 10317 blockIndexWords[0]++; 10318 } 10319 derivedKey.sigBytes = keySize * 4; 10320 10321 return derivedKey; 10322 } 10323 }); 10324 10325 /** 10326 * Computes the Password-Based Key Derivation Function 2. 10327 * 10328 * @param {WordArray|string} password The password. 10329 * @param {WordArray|string} salt A salt. 10330 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10331 * 10332 * @return {WordArray} The derived key. 10333 * 10334 * @static 10335 * 10336 * @example 10337 * 10338 * var key = CryptoJS.PBKDF2(password, salt); 10339 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10340 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10341 */ 10342 C.PBKDF2 = function (password, salt, cfg) { 10343 return PBKDF2.create(cfg).compute(password, salt); 10344 }; 10345 }()); 10346 10347 10348 return CryptoJS.PBKDF2; 10349 10350 })); 10351 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 10352 ;(function (root, factory, undef) { 10353 if (typeof exports === "object") { 10354 // CommonJS 10355 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10356 } 10357 else if (typeof define === "function" && define.amd) { 10358 // AMD 10359 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10360 } 10361 else { 10362 // Global (browser) 10363 factory(root.CryptoJS); 10364 } 10365 }(this, function (CryptoJS) { 10366 10367 (function () { 10368 // Shortcuts 10369 var C = CryptoJS; 10370 var C_lib = C.lib; 10371 var StreamCipher = C_lib.StreamCipher; 10372 var C_algo = C.algo; 10373 10374 // Reusable objects 10375 var S = []; 10376 var C_ = []; 10377 var G = []; 10378 10379 /** 10380 * Rabbit stream cipher algorithm. 10381 * 10382 * This is a legacy version that neglected to convert the key to little-endian. 10383 * This error doesn't affect the cipher's security, 10384 * but it does affect its compatibility with other implementations. 10385 */ 10386 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10387 _doReset: function () { 10388 // Shortcuts 10389 var K = this._key.words; 10390 var iv = this.cfg.iv; 10391 10392 // Generate initial state values 10393 var X = this._X = [ 10394 K[0], (K[3] << 16) | (K[2] >>> 16), 10395 K[1], (K[0] << 16) | (K[3] >>> 16), 10396 K[2], (K[1] << 16) | (K[0] >>> 16), 10397 K[3], (K[2] << 16) | (K[1] >>> 16) 10398 ]; 10399 10400 // Generate initial counter values 10401 var C = this._C = [ 10402 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10403 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10404 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10405 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10406 ]; 10407 10408 // Carry bit 10409 this._b = 0; 10410 10411 // Iterate the system four times 10412 for (var i = 0; i < 4; i++) { 10413 nextState.call(this); 10414 } 10415 10416 // Modify the counters 10417 for (var i = 0; i < 8; i++) { 10418 C[i] ^= X[(i + 4) & 7]; 10419 } 10420 10421 // IV setup 10422 if (iv) { 10423 // Shortcuts 10424 var IV = iv.words; 10425 var IV_0 = IV[0]; 10426 var IV_1 = IV[1]; 10427 10428 // Generate four subvectors 10429 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10430 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10431 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10432 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10433 10434 // Modify counter values 10435 C[0] ^= i0; 10436 C[1] ^= i1; 10437 C[2] ^= i2; 10438 C[3] ^= i3; 10439 C[4] ^= i0; 10440 C[5] ^= i1; 10441 C[6] ^= i2; 10442 C[7] ^= i3; 10443 10444 // Iterate the system four times 10445 for (var i = 0; i < 4; i++) { 10446 nextState.call(this); 10447 } 10448 } 10449 }, 10450 10451 _doProcessBlock: function (M, offset) { 10452 // Shortcut 10453 var X = this._X; 10454 10455 // Iterate the system 10456 nextState.call(this); 10457 10458 // Generate four keystream words 10459 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10460 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10461 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10462 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10463 10464 for (var i = 0; i < 4; i++) { 10465 // Swap endian 10466 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10467 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10468 10469 // Encrypt 10470 M[offset + i] ^= S[i]; 10471 } 10472 }, 10473 10474 blockSize: 128/32, 10475 10476 ivSize: 64/32 10477 }); 10478 10479 function nextState() { 10480 // Shortcuts 10481 var X = this._X; 10482 var C = this._C; 10483 10484 // Save old counter values 10485 for (var i = 0; i < 8; i++) { 10486 C_[i] = C[i]; 10487 } 10488 10489 // Calculate new counter values 10490 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10491 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10492 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10493 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10494 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10495 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10496 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10497 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10498 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10499 10500 // Calculate the g-values 10501 for (var i = 0; i < 8; i++) { 10502 var gx = X[i] + C[i]; 10503 10504 // Construct high and low argument for squaring 10505 var ga = gx & 0xffff; 10506 var gb = gx >>> 16; 10507 10508 // Calculate high and low result of squaring 10509 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10510 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10511 10512 // High XOR low 10513 G[i] = gh ^ gl; 10514 } 10515 10516 // Calculate new state values 10517 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10518 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10519 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10520 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10521 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10522 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10523 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10524 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10525 } 10526 10527 /** 10528 * Shortcut functions to the cipher's object interface. 10529 * 10530 * @example 10531 * 10532 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10533 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10534 */ 10535 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10536 }()); 10537 10538 10539 return CryptoJS.RabbitLegacy; 10540 10541 })); 10542 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 10543 ;(function (root, factory, undef) { 10544 if (typeof exports === "object") { 10545 // CommonJS 10546 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10547 } 10548 else if (typeof define === "function" && define.amd) { 10549 // AMD 10550 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10551 } 10552 else { 10553 // Global (browser) 10554 factory(root.CryptoJS); 10555 } 10556 }(this, function (CryptoJS) { 10557 10558 (function () { 10559 // Shortcuts 10560 var C = CryptoJS; 10561 var C_lib = C.lib; 10562 var StreamCipher = C_lib.StreamCipher; 10563 var C_algo = C.algo; 10564 10565 // Reusable objects 10566 var S = []; 10567 var C_ = []; 10568 var G = []; 10569 10570 /** 10571 * Rabbit stream cipher algorithm 10572 */ 10573 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10574 _doReset: function () { 10575 // Shortcuts 10576 var K = this._key.words; 10577 var iv = this.cfg.iv; 10578 10579 // Swap endian 10580 for (var i = 0; i < 4; i++) { 10581 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10582 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10583 } 10584 10585 // Generate initial state values 10586 var X = this._X = [ 10587 K[0], (K[3] << 16) | (K[2] >>> 16), 10588 K[1], (K[0] << 16) | (K[3] >>> 16), 10589 K[2], (K[1] << 16) | (K[0] >>> 16), 10590 K[3], (K[2] << 16) | (K[1] >>> 16) 10591 ]; 10592 10593 // Generate initial counter values 10594 var C = this._C = [ 10595 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10596 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10597 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10598 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10599 ]; 10600 10601 // Carry bit 10602 this._b = 0; 10603 10604 // Iterate the system four times 10605 for (var i = 0; i < 4; i++) { 10606 nextState.call(this); 10607 } 10608 10609 // Modify the counters 10610 for (var i = 0; i < 8; i++) { 10611 C[i] ^= X[(i + 4) & 7]; 10612 } 10613 10614 // IV setup 10615 if (iv) { 10616 // Shortcuts 10617 var IV = iv.words; 10618 var IV_0 = IV[0]; 10619 var IV_1 = IV[1]; 10620 10621 // Generate four subvectors 10622 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10623 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10624 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10625 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10626 10627 // Modify counter values 10628 C[0] ^= i0; 10629 C[1] ^= i1; 10630 C[2] ^= i2; 10631 C[3] ^= i3; 10632 C[4] ^= i0; 10633 C[5] ^= i1; 10634 C[6] ^= i2; 10635 C[7] ^= i3; 10636 10637 // Iterate the system four times 10638 for (var i = 0; i < 4; i++) { 10639 nextState.call(this); 10640 } 10641 } 10642 }, 10643 10644 _doProcessBlock: function (M, offset) { 10645 // Shortcut 10646 var X = this._X; 10647 10648 // Iterate the system 10649 nextState.call(this); 10650 10651 // Generate four keystream words 10652 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10653 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10654 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10655 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10656 10657 for (var i = 0; i < 4; i++) { 10658 // Swap endian 10659 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10660 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10661 10662 // Encrypt 10663 M[offset + i] ^= S[i]; 10664 } 10665 }, 10666 10667 blockSize: 128/32, 10668 10669 ivSize: 64/32 10670 }); 10671 10672 function nextState() { 10673 // Shortcuts 10674 var X = this._X; 10675 var C = this._C; 10676 10677 // Save old counter values 10678 for (var i = 0; i < 8; i++) { 10679 C_[i] = C[i]; 10680 } 10681 10682 // Calculate new counter values 10683 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10684 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10685 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10686 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10687 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10688 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10689 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10690 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10691 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10692 10693 // Calculate the g-values 10694 for (var i = 0; i < 8; i++) { 10695 var gx = X[i] + C[i]; 10696 10697 // Construct high and low argument for squaring 10698 var ga = gx & 0xffff; 10699 var gb = gx >>> 16; 10700 10701 // Calculate high and low result of squaring 10702 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10703 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10704 10705 // High XOR low 10706 G[i] = gh ^ gl; 10707 } 10708 10709 // Calculate new state values 10710 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10711 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10712 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10713 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10714 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10715 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10716 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10717 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10718 } 10719 10720 /** 10721 * Shortcut functions to the cipher's object interface. 10722 * 10723 * @example 10724 * 10725 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10726 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10727 */ 10728 C.Rabbit = StreamCipher._createHelper(Rabbit); 10729 }()); 10730 10731 10732 return CryptoJS.Rabbit; 10733 10734 })); 10735 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 10736 ;(function (root, factory, undef) { 10737 if (typeof exports === "object") { 10738 // CommonJS 10739 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10740 } 10741 else if (typeof define === "function" && define.amd) { 10742 // AMD 10743 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10744 } 10745 else { 10746 // Global (browser) 10747 factory(root.CryptoJS); 10748 } 10749 }(this, function (CryptoJS) { 10750 10751 (function () { 10752 // Shortcuts 10753 var C = CryptoJS; 10754 var C_lib = C.lib; 10755 var StreamCipher = C_lib.StreamCipher; 10756 var C_algo = C.algo; 10757 10758 /** 10759 * RC4 stream cipher algorithm. 10760 */ 10761 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10762 _doReset: function () { 10763 // Shortcuts 10764 var key = this._key; 10765 var keyWords = key.words; 10766 var keySigBytes = key.sigBytes; 10767 10768 // Init sbox 10769 var S = this._S = []; 10770 for (var i = 0; i < 256; i++) { 10771 S[i] = i; 10772 } 10773 10774 // Key setup 10775 for (var i = 0, j = 0; i < 256; i++) { 10776 var keyByteIndex = i % keySigBytes; 10777 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10778 10779 j = (j + S[i] + keyByte) % 256; 10780 10781 // Swap 10782 var t = S[i]; 10783 S[i] = S[j]; 10784 S[j] = t; 10785 } 10786 10787 // Counters 10788 this._i = this._j = 0; 10789 }, 10790 10791 _doProcessBlock: function (M, offset) { 10792 M[offset] ^= generateKeystreamWord.call(this); 10793 }, 10794 10795 keySize: 256/32, 10796 10797 ivSize: 0 10798 }); 10799 10800 function generateKeystreamWord() { 10801 // Shortcuts 10802 var S = this._S; 10803 var i = this._i; 10804 var j = this._j; 10805 10806 // Generate keystream word 10807 var keystreamWord = 0; 10808 for (var n = 0; n < 4; n++) { 10809 i = (i + 1) % 256; 10810 j = (j + S[i]) % 256; 10811 10812 // Swap 10813 var t = S[i]; 10814 S[i] = S[j]; 10815 S[j] = t; 10816 10817 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 10818 } 10819 10820 // Update counters 10821 this._i = i; 10822 this._j = j; 10823 10824 return keystreamWord; 10825 } 10826 10827 /** 10828 * Shortcut functions to the cipher's object interface. 10829 * 10830 * @example 10831 * 10832 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 10833 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 10834 */ 10835 C.RC4 = StreamCipher._createHelper(RC4); 10836 10837 /** 10838 * Modified RC4 stream cipher algorithm. 10839 */ 10840 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 10841 /** 10842 * Configuration options. 10843 * 10844 * @property {number} drop The number of keystream words to drop. Default 192 10845 */ 10846 cfg: RC4.cfg.extend({ 10847 drop: 192 10848 }), 10849 10850 _doReset: function () { 10851 RC4._doReset.call(this); 10852 10853 // Drop 10854 for (var i = this.cfg.drop; i > 0; i--) { 10855 generateKeystreamWord.call(this); 10856 } 10857 } 10858 }); 10859 10860 /** 10861 * Shortcut functions to the cipher's object interface. 10862 * 10863 * @example 10864 * 10865 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 10866 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 10867 */ 10868 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 10869 }()); 10870 10871 10872 return CryptoJS.RC4; 10873 10874 })); 10875 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 10876 ;(function (root, factory) { 10877 if (typeof exports === "object") { 10878 // CommonJS 10879 module.exports = exports = factory(require("./core")); 10880 } 10881 else if (typeof define === "function" && define.amd) { 10882 // AMD 10883 define(["./core"], factory); 10884 } 10885 else { 10886 // Global (browser) 10887 factory(root.CryptoJS); 10888 } 10889 }(this, function (CryptoJS) { 10890 10891 /** @preserve 10892 (c) 2012 by Cédric Mesnil. All rights reserved. 10893 10894 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10895 10896 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10897 - 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. 10898 10899 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. 10900 */ 10901 10902 (function (Math) { 10903 // Shortcuts 10904 var C = CryptoJS; 10905 var C_lib = C.lib; 10906 var WordArray = C_lib.WordArray; 10907 var Hasher = C_lib.Hasher; 10908 var C_algo = C.algo; 10909 10910 // Constants table 10911 var _zl = WordArray.create([ 10912 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10913 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 10914 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 10915 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 10916 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 10917 var _zr = WordArray.create([ 10918 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 10919 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 10920 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 10921 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 10922 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 10923 var _sl = WordArray.create([ 10924 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 10925 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 10926 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 10927 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 10928 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 10929 var _sr = WordArray.create([ 10930 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 10931 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 10932 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 10933 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 10934 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 10935 10936 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 10937 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 10938 10939 /** 10940 * RIPEMD160 hash algorithm. 10941 */ 10942 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 10943 _doReset: function () { 10944 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 10945 }, 10946 10947 _doProcessBlock: function (M, offset) { 10948 10949 // Swap endian 10950 for (var i = 0; i < 16; i++) { 10951 // Shortcuts 10952 var offset_i = offset + i; 10953 var M_offset_i = M[offset_i]; 10954 10955 // Swap 10956 M[offset_i] = ( 10957 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10958 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 10959 ); 10960 } 10961 // Shortcut 10962 var H = this._hash.words; 10963 var hl = _hl.words; 10964 var hr = _hr.words; 10965 var zl = _zl.words; 10966 var zr = _zr.words; 10967 var sl = _sl.words; 10968 var sr = _sr.words; 10969 10970 // Working variables 10971 var al, bl, cl, dl, el; 10972 var ar, br, cr, dr, er; 10973 10974 ar = al = H[0]; 10975 br = bl = H[1]; 10976 cr = cl = H[2]; 10977 dr = dl = H[3]; 10978 er = el = H[4]; 10979 // Computation 10980 var t; 10981 for (var i = 0; i < 80; i += 1) { 10982 t = (al + M[offset+zl[i]])|0; 10983 if (i<16){ 10984 t += f1(bl,cl,dl) + hl[0]; 10985 } else if (i<32) { 10986 t += f2(bl,cl,dl) + hl[1]; 10987 } else if (i<48) { 10988 t += f3(bl,cl,dl) + hl[2]; 10989 } else if (i<64) { 10990 t += f4(bl,cl,dl) + hl[3]; 10991 } else {// if (i<80) { 10992 t += f5(bl,cl,dl) + hl[4]; 10993 } 10994 t = t|0; 10995 t = rotl(t,sl[i]); 10996 t = (t+el)|0; 10997 al = el; 10998 el = dl; 10999 dl = rotl(cl, 10); 11000 cl = bl; 11001 bl = t; 11002 11003 t = (ar + M[offset+zr[i]])|0; 11004 if (i<16){ 11005 t += f5(br,cr,dr) + hr[0]; 11006 } else if (i<32) { 11007 t += f4(br,cr,dr) + hr[1]; 11008 } else if (i<48) { 11009 t += f3(br,cr,dr) + hr[2]; 11010 } else if (i<64) { 11011 t += f2(br,cr,dr) + hr[3]; 11012 } else {// if (i<80) { 11013 t += f1(br,cr,dr) + hr[4]; 11014 } 11015 t = t|0; 11016 t = rotl(t,sr[i]) ; 11017 t = (t+er)|0; 11018 ar = er; 11019 er = dr; 11020 dr = rotl(cr, 10); 11021 cr = br; 11022 br = t; 11023 } 11024 // Intermediate hash value 11025 t = (H[1] + cl + dr)|0; 11026 H[1] = (H[2] + dl + er)|0; 11027 H[2] = (H[3] + el + ar)|0; 11028 H[3] = (H[4] + al + br)|0; 11029 H[4] = (H[0] + bl + cr)|0; 11030 H[0] = t; 11031 }, 11032 11033 _doFinalize: function () { 11034 // Shortcuts 11035 var data = this._data; 11036 var dataWords = data.words; 11037 11038 var nBitsTotal = this._nDataBytes * 8; 11039 var nBitsLeft = data.sigBytes * 8; 11040 11041 // Add padding 11042 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11043 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11044 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11045 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11046 ); 11047 data.sigBytes = (dataWords.length + 1) * 4; 11048 11049 // Hash final blocks 11050 this._process(); 11051 11052 // Shortcuts 11053 var hash = this._hash; 11054 var H = hash.words; 11055 11056 // Swap endian 11057 for (var i = 0; i < 5; i++) { 11058 // Shortcut 11059 var H_i = H[i]; 11060 11061 // Swap 11062 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11063 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11064 } 11065 11066 // Return final computed hash 11067 return hash; 11068 }, 11069 11070 clone: function () { 11071 var clone = Hasher.clone.call(this); 11072 clone._hash = this._hash.clone(); 11073 11074 return clone; 11075 } 11076 }); 11077 11078 11079 function f1(x, y, z) { 11080 return ((x) ^ (y) ^ (z)); 11081 11082 } 11083 11084 function f2(x, y, z) { 11085 return (((x)&(y)) | ((~x)&(z))); 11086 } 11087 11088 function f3(x, y, z) { 11089 return (((x) | (~(y))) ^ (z)); 11090 } 11091 11092 function f4(x, y, z) { 11093 return (((x) & (z)) | ((y)&(~(z)))); 11094 } 11095 11096 function f5(x, y, z) { 11097 return ((x) ^ ((y) |(~(z)))); 11098 11099 } 11100 11101 function rotl(x,n) { 11102 return (x<<n) | (x>>>(32-n)); 11103 } 11104 11105 11106 /** 11107 * Shortcut function to the hasher's object interface. 11108 * 11109 * @param {WordArray|string} message The message to hash. 11110 * 11111 * @return {WordArray} The hash. 11112 * 11113 * @static 11114 * 11115 * @example 11116 * 11117 * var hash = CryptoJS.RIPEMD160('message'); 11118 * var hash = CryptoJS.RIPEMD160(wordArray); 11119 */ 11120 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11121 11122 /** 11123 * Shortcut function to the HMAC's object interface. 11124 * 11125 * @param {WordArray|string} message The message to hash. 11126 * @param {WordArray|string} key The secret key. 11127 * 11128 * @return {WordArray} The HMAC. 11129 * 11130 * @static 11131 * 11132 * @example 11133 * 11134 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11135 */ 11136 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11137 }(Math)); 11138 11139 11140 return CryptoJS.RIPEMD160; 11141 11142 })); 11143 },{"./core":53}],77:[function(require,module,exports){ 11144 ;(function (root, factory) { 11145 if (typeof exports === "object") { 11146 // CommonJS 11147 module.exports = exports = factory(require("./core")); 11148 } 11149 else if (typeof define === "function" && define.amd) { 11150 // AMD 11151 define(["./core"], factory); 11152 } 11153 else { 11154 // Global (browser) 11155 factory(root.CryptoJS); 11156 } 11157 }(this, function (CryptoJS) { 11158 11159 (function () { 11160 // Shortcuts 11161 var C = CryptoJS; 11162 var C_lib = C.lib; 11163 var WordArray = C_lib.WordArray; 11164 var Hasher = C_lib.Hasher; 11165 var C_algo = C.algo; 11166 11167 // Reusable object 11168 var W = []; 11169 11170 /** 11171 * SHA-1 hash algorithm. 11172 */ 11173 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11174 _doReset: function () { 11175 this._hash = new WordArray.init([ 11176 0x67452301, 0xefcdab89, 11177 0x98badcfe, 0x10325476, 11178 0xc3d2e1f0 11179 ]); 11180 }, 11181 11182 _doProcessBlock: function (M, offset) { 11183 // Shortcut 11184 var H = this._hash.words; 11185 11186 // Working variables 11187 var a = H[0]; 11188 var b = H[1]; 11189 var c = H[2]; 11190 var d = H[3]; 11191 var e = H[4]; 11192 11193 // Computation 11194 for (var i = 0; i < 80; i++) { 11195 if (i < 16) { 11196 W[i] = M[offset + i] | 0; 11197 } else { 11198 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11199 W[i] = (n << 1) | (n >>> 31); 11200 } 11201 11202 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11203 if (i < 20) { 11204 t += ((b & c) | (~b & d)) + 0x5a827999; 11205 } else if (i < 40) { 11206 t += (b ^ c ^ d) + 0x6ed9eba1; 11207 } else if (i < 60) { 11208 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11209 } else /* if (i < 80) */ { 11210 t += (b ^ c ^ d) - 0x359d3e2a; 11211 } 11212 11213 e = d; 11214 d = c; 11215 c = (b << 30) | (b >>> 2); 11216 b = a; 11217 a = t; 11218 } 11219 11220 // Intermediate hash value 11221 H[0] = (H[0] + a) | 0; 11222 H[1] = (H[1] + b) | 0; 11223 H[2] = (H[2] + c) | 0; 11224 H[3] = (H[3] + d) | 0; 11225 H[4] = (H[4] + e) | 0; 11226 }, 11227 11228 _doFinalize: function () { 11229 // Shortcuts 11230 var data = this._data; 11231 var dataWords = data.words; 11232 11233 var nBitsTotal = this._nDataBytes * 8; 11234 var nBitsLeft = data.sigBytes * 8; 11235 11236 // Add padding 11237 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11238 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11239 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11240 data.sigBytes = dataWords.length * 4; 11241 11242 // Hash final blocks 11243 this._process(); 11244 11245 // Return final computed hash 11246 return this._hash; 11247 }, 11248 11249 clone: function () { 11250 var clone = Hasher.clone.call(this); 11251 clone._hash = this._hash.clone(); 11252 11253 return clone; 11254 } 11255 }); 11256 11257 /** 11258 * Shortcut function to the hasher's object interface. 11259 * 11260 * @param {WordArray|string} message The message to hash. 11261 * 11262 * @return {WordArray} The hash. 11263 * 11264 * @static 11265 * 11266 * @example 11267 * 11268 * var hash = CryptoJS.SHA1('message'); 11269 * var hash = CryptoJS.SHA1(wordArray); 11270 */ 11271 C.SHA1 = Hasher._createHelper(SHA1); 11272 11273 /** 11274 * Shortcut function to the HMAC's object interface. 11275 * 11276 * @param {WordArray|string} message The message to hash. 11277 * @param {WordArray|string} key The secret key. 11278 * 11279 * @return {WordArray} The HMAC. 11280 * 11281 * @static 11282 * 11283 * @example 11284 * 11285 * var hmac = CryptoJS.HmacSHA1(message, key); 11286 */ 11287 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11288 }()); 11289 11290 11291 return CryptoJS.SHA1; 11292 11293 })); 11294 },{"./core":53}],78:[function(require,module,exports){ 11295 ;(function (root, factory, undef) { 11296 if (typeof exports === "object") { 11297 // CommonJS 11298 module.exports = exports = factory(require("./core"), require("./sha256")); 11299 } 11300 else if (typeof define === "function" && define.amd) { 11301 // AMD 11302 define(["./core", "./sha256"], factory); 11303 } 11304 else { 11305 // Global (browser) 11306 factory(root.CryptoJS); 11307 } 11308 }(this, function (CryptoJS) { 11309 11310 (function () { 11311 // Shortcuts 11312 var C = CryptoJS; 11313 var C_lib = C.lib; 11314 var WordArray = C_lib.WordArray; 11315 var C_algo = C.algo; 11316 var SHA256 = C_algo.SHA256; 11317 11318 /** 11319 * SHA-224 hash algorithm. 11320 */ 11321 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11322 _doReset: function () { 11323 this._hash = new WordArray.init([ 11324 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11325 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11326 ]); 11327 }, 11328 11329 _doFinalize: function () { 11330 var hash = SHA256._doFinalize.call(this); 11331 11332 hash.sigBytes -= 4; 11333 11334 return hash; 11335 } 11336 }); 11337 11338 /** 11339 * Shortcut function to the hasher's object interface. 11340 * 11341 * @param {WordArray|string} message The message to hash. 11342 * 11343 * @return {WordArray} The hash. 11344 * 11345 * @static 11346 * 11347 * @example 11348 * 11349 * var hash = CryptoJS.SHA224('message'); 11350 * var hash = CryptoJS.SHA224(wordArray); 11351 */ 11352 C.SHA224 = SHA256._createHelper(SHA224); 11353 11354 /** 11355 * Shortcut function to the HMAC's object interface. 11356 * 11357 * @param {WordArray|string} message The message to hash. 11358 * @param {WordArray|string} key The secret key. 11359 * 11360 * @return {WordArray} The HMAC. 11361 * 11362 * @static 11363 * 11364 * @example 11365 * 11366 * var hmac = CryptoJS.HmacSHA224(message, key); 11367 */ 11368 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11369 }()); 11370 11371 11372 return CryptoJS.SHA224; 11373 11374 })); 11375 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 11376 ;(function (root, factory) { 11377 if (typeof exports === "object") { 11378 // CommonJS 11379 module.exports = exports = factory(require("./core")); 11380 } 11381 else if (typeof define === "function" && define.amd) { 11382 // AMD 11383 define(["./core"], factory); 11384 } 11385 else { 11386 // Global (browser) 11387 factory(root.CryptoJS); 11388 } 11389 }(this, function (CryptoJS) { 11390 11391 (function (Math) { 11392 // Shortcuts 11393 var C = CryptoJS; 11394 var C_lib = C.lib; 11395 var WordArray = C_lib.WordArray; 11396 var Hasher = C_lib.Hasher; 11397 var C_algo = C.algo; 11398 11399 // Initialization and round constants tables 11400 var H = []; 11401 var K = []; 11402 11403 // Compute constants 11404 (function () { 11405 function isPrime(n) { 11406 var sqrtN = Math.sqrt(n); 11407 for (var factor = 2; factor <= sqrtN; factor++) { 11408 if (!(n % factor)) { 11409 return false; 11410 } 11411 } 11412 11413 return true; 11414 } 11415 11416 function getFractionalBits(n) { 11417 return ((n - (n | 0)) * 0x100000000) | 0; 11418 } 11419 11420 var n = 2; 11421 var nPrime = 0; 11422 while (nPrime < 64) { 11423 if (isPrime(n)) { 11424 if (nPrime < 8) { 11425 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11426 } 11427 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11428 11429 nPrime++; 11430 } 11431 11432 n++; 11433 } 11434 }()); 11435 11436 // Reusable object 11437 var W = []; 11438 11439 /** 11440 * SHA-256 hash algorithm. 11441 */ 11442 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11443 _doReset: function () { 11444 this._hash = new WordArray.init(H.slice(0)); 11445 }, 11446 11447 _doProcessBlock: function (M, offset) { 11448 // Shortcut 11449 var H = this._hash.words; 11450 11451 // Working variables 11452 var a = H[0]; 11453 var b = H[1]; 11454 var c = H[2]; 11455 var d = H[3]; 11456 var e = H[4]; 11457 var f = H[5]; 11458 var g = H[6]; 11459 var h = H[7]; 11460 11461 // Computation 11462 for (var i = 0; i < 64; i++) { 11463 if (i < 16) { 11464 W[i] = M[offset + i] | 0; 11465 } else { 11466 var gamma0x = W[i - 15]; 11467 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11468 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11469 (gamma0x >>> 3); 11470 11471 var gamma1x = W[i - 2]; 11472 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11473 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11474 (gamma1x >>> 10); 11475 11476 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11477 } 11478 11479 var ch = (e & f) ^ (~e & g); 11480 var maj = (a & b) ^ (a & c) ^ (b & c); 11481 11482 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11483 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11484 11485 var t1 = h + sigma1 + ch + K[i] + W[i]; 11486 var t2 = sigma0 + maj; 11487 11488 h = g; 11489 g = f; 11490 f = e; 11491 e = (d + t1) | 0; 11492 d = c; 11493 c = b; 11494 b = a; 11495 a = (t1 + t2) | 0; 11496 } 11497 11498 // Intermediate hash value 11499 H[0] = (H[0] + a) | 0; 11500 H[1] = (H[1] + b) | 0; 11501 H[2] = (H[2] + c) | 0; 11502 H[3] = (H[3] + d) | 0; 11503 H[4] = (H[4] + e) | 0; 11504 H[5] = (H[5] + f) | 0; 11505 H[6] = (H[6] + g) | 0; 11506 H[7] = (H[7] + h) | 0; 11507 }, 11508 11509 _doFinalize: function () { 11510 // Shortcuts 11511 var data = this._data; 11512 var dataWords = data.words; 11513 11514 var nBitsTotal = this._nDataBytes * 8; 11515 var nBitsLeft = data.sigBytes * 8; 11516 11517 // Add padding 11518 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11519 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11520 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11521 data.sigBytes = dataWords.length * 4; 11522 11523 // Hash final blocks 11524 this._process(); 11525 11526 // Return final computed hash 11527 return this._hash; 11528 }, 11529 11530 clone: function () { 11531 var clone = Hasher.clone.call(this); 11532 clone._hash = this._hash.clone(); 11533 11534 return clone; 11535 } 11536 }); 11537 11538 /** 11539 * Shortcut function to the hasher's object interface. 11540 * 11541 * @param {WordArray|string} message The message to hash. 11542 * 11543 * @return {WordArray} The hash. 11544 * 11545 * @static 11546 * 11547 * @example 11548 * 11549 * var hash = CryptoJS.SHA256('message'); 11550 * var hash = CryptoJS.SHA256(wordArray); 11551 */ 11552 C.SHA256 = Hasher._createHelper(SHA256); 11553 11554 /** 11555 * Shortcut function to the HMAC's object interface. 11556 * 11557 * @param {WordArray|string} message The message to hash. 11558 * @param {WordArray|string} key The secret key. 11559 * 11560 * @return {WordArray} The HMAC. 11561 * 11562 * @static 11563 * 11564 * @example 11565 * 11566 * var hmac = CryptoJS.HmacSHA256(message, key); 11567 */ 11568 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11569 }(Math)); 11570 11571 11572 return CryptoJS.SHA256; 11573 11574 })); 11575 },{"./core":53}],80:[function(require,module,exports){ 11576 ;(function (root, factory, undef) { 11577 if (typeof exports === "object") { 11578 // CommonJS 11579 module.exports = exports = factory(require("./core"), require("./x64-core")); 11580 } 11581 else if (typeof define === "function" && define.amd) { 11582 // AMD 11583 define(["./core", "./x64-core"], factory); 11584 } 11585 else { 11586 // Global (browser) 11587 factory(root.CryptoJS); 11588 } 11589 }(this, function (CryptoJS) { 11590 11591 (function (Math) { 11592 // Shortcuts 11593 var C = CryptoJS; 11594 var C_lib = C.lib; 11595 var WordArray = C_lib.WordArray; 11596 var Hasher = C_lib.Hasher; 11597 var C_x64 = C.x64; 11598 var X64Word = C_x64.Word; 11599 var C_algo = C.algo; 11600 11601 // Constants tables 11602 var RHO_OFFSETS = []; 11603 var PI_INDEXES = []; 11604 var ROUND_CONSTANTS = []; 11605 11606 // Compute Constants 11607 (function () { 11608 // Compute rho offset constants 11609 var x = 1, y = 0; 11610 for (var t = 0; t < 24; t++) { 11611 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11612 11613 var newX = y % 5; 11614 var newY = (2 * x + 3 * y) % 5; 11615 x = newX; 11616 y = newY; 11617 } 11618 11619 // Compute pi index constants 11620 for (var x = 0; x < 5; x++) { 11621 for (var y = 0; y < 5; y++) { 11622 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11623 } 11624 } 11625 11626 // Compute round constants 11627 var LFSR = 0x01; 11628 for (var i = 0; i < 24; i++) { 11629 var roundConstantMsw = 0; 11630 var roundConstantLsw = 0; 11631 11632 for (var j = 0; j < 7; j++) { 11633 if (LFSR & 0x01) { 11634 var bitPosition = (1 << j) - 1; 11635 if (bitPosition < 32) { 11636 roundConstantLsw ^= 1 << bitPosition; 11637 } else /* if (bitPosition >= 32) */ { 11638 roundConstantMsw ^= 1 << (bitPosition - 32); 11639 } 11640 } 11641 11642 // Compute next LFSR 11643 if (LFSR & 0x80) { 11644 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11645 LFSR = (LFSR << 1) ^ 0x71; 11646 } else { 11647 LFSR <<= 1; 11648 } 11649 } 11650 11651 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11652 } 11653 }()); 11654 11655 // Reusable objects for temporary values 11656 var T = []; 11657 (function () { 11658 for (var i = 0; i < 25; i++) { 11659 T[i] = X64Word.create(); 11660 } 11661 }()); 11662 11663 /** 11664 * SHA-3 hash algorithm. 11665 */ 11666 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11667 /** 11668 * Configuration options. 11669 * 11670 * @property {number} outputLength 11671 * The desired number of bits in the output hash. 11672 * Only values permitted are: 224, 256, 384, 512. 11673 * Default: 512 11674 */ 11675 cfg: Hasher.cfg.extend({ 11676 outputLength: 512 11677 }), 11678 11679 _doReset: function () { 11680 var state = this._state = [] 11681 for (var i = 0; i < 25; i++) { 11682 state[i] = new X64Word.init(); 11683 } 11684 11685 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11686 }, 11687 11688 _doProcessBlock: function (M, offset) { 11689 // Shortcuts 11690 var state = this._state; 11691 var nBlockSizeLanes = this.blockSize / 2; 11692 11693 // Absorb 11694 for (var i = 0; i < nBlockSizeLanes; i++) { 11695 // Shortcuts 11696 var M2i = M[offset + 2 * i]; 11697 var M2i1 = M[offset + 2 * i + 1]; 11698 11699 // Swap endian 11700 M2i = ( 11701 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11702 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11703 ); 11704 M2i1 = ( 11705 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11706 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11707 ); 11708 11709 // Absorb message into state 11710 var lane = state[i]; 11711 lane.high ^= M2i1; 11712 lane.low ^= M2i; 11713 } 11714 11715 // Rounds 11716 for (var round = 0; round < 24; round++) { 11717 // Theta 11718 for (var x = 0; x < 5; x++) { 11719 // Mix column lanes 11720 var tMsw = 0, tLsw = 0; 11721 for (var y = 0; y < 5; y++) { 11722 var lane = state[x + 5 * y]; 11723 tMsw ^= lane.high; 11724 tLsw ^= lane.low; 11725 } 11726 11727 // Temporary values 11728 var Tx = T[x]; 11729 Tx.high = tMsw; 11730 Tx.low = tLsw; 11731 } 11732 for (var x = 0; x < 5; x++) { 11733 // Shortcuts 11734 var Tx4 = T[(x + 4) % 5]; 11735 var Tx1 = T[(x + 1) % 5]; 11736 var Tx1Msw = Tx1.high; 11737 var Tx1Lsw = Tx1.low; 11738 11739 // Mix surrounding columns 11740 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11741 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11742 for (var y = 0; y < 5; y++) { 11743 var lane = state[x + 5 * y]; 11744 lane.high ^= tMsw; 11745 lane.low ^= tLsw; 11746 } 11747 } 11748 11749 // Rho Pi 11750 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11751 // Shortcuts 11752 var lane = state[laneIndex]; 11753 var laneMsw = lane.high; 11754 var laneLsw = lane.low; 11755 var rhoOffset = RHO_OFFSETS[laneIndex]; 11756 11757 // Rotate lanes 11758 if (rhoOffset < 32) { 11759 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11760 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11761 } else /* if (rhoOffset >= 32) */ { 11762 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11763 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11764 } 11765 11766 // Transpose lanes 11767 var TPiLane = T[PI_INDEXES[laneIndex]]; 11768 TPiLane.high = tMsw; 11769 TPiLane.low = tLsw; 11770 } 11771 11772 // Rho pi at x = y = 0 11773 var T0 = T[0]; 11774 var state0 = state[0]; 11775 T0.high = state0.high; 11776 T0.low = state0.low; 11777 11778 // Chi 11779 for (var x = 0; x < 5; x++) { 11780 for (var y = 0; y < 5; y++) { 11781 // Shortcuts 11782 var laneIndex = x + 5 * y; 11783 var lane = state[laneIndex]; 11784 var TLane = T[laneIndex]; 11785 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 11786 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 11787 11788 // Mix rows 11789 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 11790 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 11791 } 11792 } 11793 11794 // Iota 11795 var lane = state[0]; 11796 var roundConstant = ROUND_CONSTANTS[round]; 11797 lane.high ^= roundConstant.high; 11798 lane.low ^= roundConstant.low;; 11799 } 11800 }, 11801 11802 _doFinalize: function () { 11803 // Shortcuts 11804 var data = this._data; 11805 var dataWords = data.words; 11806 var nBitsTotal = this._nDataBytes * 8; 11807 var nBitsLeft = data.sigBytes * 8; 11808 var blockSizeBits = this.blockSize * 32; 11809 11810 // Add padding 11811 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 11812 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 11813 data.sigBytes = dataWords.length * 4; 11814 11815 // Hash final blocks 11816 this._process(); 11817 11818 // Shortcuts 11819 var state = this._state; 11820 var outputLengthBytes = this.cfg.outputLength / 8; 11821 var outputLengthLanes = outputLengthBytes / 8; 11822 11823 // Squeeze 11824 var hashWords = []; 11825 for (var i = 0; i < outputLengthLanes; i++) { 11826 // Shortcuts 11827 var lane = state[i]; 11828 var laneMsw = lane.high; 11829 var laneLsw = lane.low; 11830 11831 // Swap endian 11832 laneMsw = ( 11833 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 11834 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 11835 ); 11836 laneLsw = ( 11837 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 11838 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 11839 ); 11840 11841 // Squeeze state to retrieve hash 11842 hashWords.push(laneLsw); 11843 hashWords.push(laneMsw); 11844 } 11845 11846 // Return final computed hash 11847 return new WordArray.init(hashWords, outputLengthBytes); 11848 }, 11849 11850 clone: function () { 11851 var clone = Hasher.clone.call(this); 11852 11853 var state = clone._state = this._state.slice(0); 11854 for (var i = 0; i < 25; i++) { 11855 state[i] = state[i].clone(); 11856 } 11857 11858 return clone; 11859 } 11860 }); 11861 11862 /** 11863 * Shortcut function to the hasher's object interface. 11864 * 11865 * @param {WordArray|string} message The message to hash. 11866 * 11867 * @return {WordArray} The hash. 11868 * 11869 * @static 11870 * 11871 * @example 11872 * 11873 * var hash = CryptoJS.SHA3('message'); 11874 * var hash = CryptoJS.SHA3(wordArray); 11875 */ 11876 C.SHA3 = Hasher._createHelper(SHA3); 11877 11878 /** 11879 * Shortcut function to the HMAC's object interface. 11880 * 11881 * @param {WordArray|string} message The message to hash. 11882 * @param {WordArray|string} key The secret key. 11883 * 11884 * @return {WordArray} The HMAC. 11885 * 11886 * @static 11887 * 11888 * @example 11889 * 11890 * var hmac = CryptoJS.HmacSHA3(message, key); 11891 */ 11892 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 11893 }(Math)); 11894 11895 11896 return CryptoJS.SHA3; 11897 11898 })); 11899 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 11900 ;(function (root, factory, undef) { 11901 if (typeof exports === "object") { 11902 // CommonJS 11903 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 11904 } 11905 else if (typeof define === "function" && define.amd) { 11906 // AMD 11907 define(["./core", "./x64-core", "./sha512"], factory); 11908 } 11909 else { 11910 // Global (browser) 11911 factory(root.CryptoJS); 11912 } 11913 }(this, function (CryptoJS) { 11914 11915 (function () { 11916 // Shortcuts 11917 var C = CryptoJS; 11918 var C_x64 = C.x64; 11919 var X64Word = C_x64.Word; 11920 var X64WordArray = C_x64.WordArray; 11921 var C_algo = C.algo; 11922 var SHA512 = C_algo.SHA512; 11923 11924 /** 11925 * SHA-384 hash algorithm. 11926 */ 11927 var SHA384 = C_algo.SHA384 = SHA512.extend({ 11928 _doReset: function () { 11929 this._hash = new X64WordArray.init([ 11930 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 11931 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 11932 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 11933 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 11934 ]); 11935 }, 11936 11937 _doFinalize: function () { 11938 var hash = SHA512._doFinalize.call(this); 11939 11940 hash.sigBytes -= 16; 11941 11942 return hash; 11943 } 11944 }); 11945 11946 /** 11947 * Shortcut function to the hasher's object interface. 11948 * 11949 * @param {WordArray|string} message The message to hash. 11950 * 11951 * @return {WordArray} The hash. 11952 * 11953 * @static 11954 * 11955 * @example 11956 * 11957 * var hash = CryptoJS.SHA384('message'); 11958 * var hash = CryptoJS.SHA384(wordArray); 11959 */ 11960 C.SHA384 = SHA512._createHelper(SHA384); 11961 11962 /** 11963 * Shortcut function to the HMAC's object interface. 11964 * 11965 * @param {WordArray|string} message The message to hash. 11966 * @param {WordArray|string} key The secret key. 11967 * 11968 * @return {WordArray} The HMAC. 11969 * 11970 * @static 11971 * 11972 * @example 11973 * 11974 * var hmac = CryptoJS.HmacSHA384(message, key); 11975 */ 11976 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 11977 }()); 11978 11979 11980 return CryptoJS.SHA384; 11981 11982 })); 11983 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 11984 ;(function (root, factory, undef) { 11985 if (typeof exports === "object") { 11986 // CommonJS 11987 module.exports = exports = factory(require("./core"), require("./x64-core")); 11988 } 11989 else if (typeof define === "function" && define.amd) { 11990 // AMD 11991 define(["./core", "./x64-core"], factory); 11992 } 11993 else { 11994 // Global (browser) 11995 factory(root.CryptoJS); 11996 } 11997 }(this, function (CryptoJS) { 11998 11999 (function () { 12000 // Shortcuts 12001 var C = CryptoJS; 12002 var C_lib = C.lib; 12003 var Hasher = C_lib.Hasher; 12004 var C_x64 = C.x64; 12005 var X64Word = C_x64.Word; 12006 var X64WordArray = C_x64.WordArray; 12007 var C_algo = C.algo; 12008 12009 function X64Word_create() { 12010 return X64Word.create.apply(X64Word, arguments); 12011 } 12012 12013 // Constants 12014 var K = [ 12015 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12016 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12017 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12018 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12019 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12020 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12021 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12022 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12023 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12024 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12025 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12026 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12027 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12028 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12029 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12030 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12031 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12032 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12033 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12034 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12035 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12036 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12037 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12038 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12039 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12040 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12041 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12042 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12043 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12044 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12045 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12046 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12047 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12048 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12049 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12050 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12051 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12052 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12053 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12054 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12055 ]; 12056 12057 // Reusable objects 12058 var W = []; 12059 (function () { 12060 for (var i = 0; i < 80; i++) { 12061 W[i] = X64Word_create(); 12062 } 12063 }()); 12064 12065 /** 12066 * SHA-512 hash algorithm. 12067 */ 12068 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12069 _doReset: function () { 12070 this._hash = new X64WordArray.init([ 12071 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12072 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12073 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12074 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12075 ]); 12076 }, 12077 12078 _doProcessBlock: function (M, offset) { 12079 // Shortcuts 12080 var H = this._hash.words; 12081 12082 var H0 = H[0]; 12083 var H1 = H[1]; 12084 var H2 = H[2]; 12085 var H3 = H[3]; 12086 var H4 = H[4]; 12087 var H5 = H[5]; 12088 var H6 = H[6]; 12089 var H7 = H[7]; 12090 12091 var H0h = H0.high; 12092 var H0l = H0.low; 12093 var H1h = H1.high; 12094 var H1l = H1.low; 12095 var H2h = H2.high; 12096 var H2l = H2.low; 12097 var H3h = H3.high; 12098 var H3l = H3.low; 12099 var H4h = H4.high; 12100 var H4l = H4.low; 12101 var H5h = H5.high; 12102 var H5l = H5.low; 12103 var H6h = H6.high; 12104 var H6l = H6.low; 12105 var H7h = H7.high; 12106 var H7l = H7.low; 12107 12108 // Working variables 12109 var ah = H0h; 12110 var al = H0l; 12111 var bh = H1h; 12112 var bl = H1l; 12113 var ch = H2h; 12114 var cl = H2l; 12115 var dh = H3h; 12116 var dl = H3l; 12117 var eh = H4h; 12118 var el = H4l; 12119 var fh = H5h; 12120 var fl = H5l; 12121 var gh = H6h; 12122 var gl = H6l; 12123 var hh = H7h; 12124 var hl = H7l; 12125 12126 // Rounds 12127 for (var i = 0; i < 80; i++) { 12128 // Shortcut 12129 var Wi = W[i]; 12130 12131 // Extend message 12132 if (i < 16) { 12133 var Wih = Wi.high = M[offset + i * 2] | 0; 12134 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12135 } else { 12136 // Gamma0 12137 var gamma0x = W[i - 15]; 12138 var gamma0xh = gamma0x.high; 12139 var gamma0xl = gamma0x.low; 12140 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12141 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12142 12143 // Gamma1 12144 var gamma1x = W[i - 2]; 12145 var gamma1xh = gamma1x.high; 12146 var gamma1xl = gamma1x.low; 12147 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12148 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12149 12150 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12151 var Wi7 = W[i - 7]; 12152 var Wi7h = Wi7.high; 12153 var Wi7l = Wi7.low; 12154 12155 var Wi16 = W[i - 16]; 12156 var Wi16h = Wi16.high; 12157 var Wi16l = Wi16.low; 12158 12159 var Wil = gamma0l + Wi7l; 12160 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12161 var Wil = Wil + gamma1l; 12162 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12163 var Wil = Wil + Wi16l; 12164 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12165 12166 Wi.high = Wih; 12167 Wi.low = Wil; 12168 } 12169 12170 var chh = (eh & fh) ^ (~eh & gh); 12171 var chl = (el & fl) ^ (~el & gl); 12172 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12173 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12174 12175 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12176 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12177 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12178 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12179 12180 // t1 = h + sigma1 + ch + K[i] + W[i] 12181 var Ki = K[i]; 12182 var Kih = Ki.high; 12183 var Kil = Ki.low; 12184 12185 var t1l = hl + sigma1l; 12186 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12187 var t1l = t1l + chl; 12188 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12189 var t1l = t1l + Kil; 12190 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12191 var t1l = t1l + Wil; 12192 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12193 12194 // t2 = sigma0 + maj 12195 var t2l = sigma0l + majl; 12196 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12197 12198 // Update working variables 12199 hh = gh; 12200 hl = gl; 12201 gh = fh; 12202 gl = fl; 12203 fh = eh; 12204 fl = el; 12205 el = (dl + t1l) | 0; 12206 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12207 dh = ch; 12208 dl = cl; 12209 ch = bh; 12210 cl = bl; 12211 bh = ah; 12212 bl = al; 12213 al = (t1l + t2l) | 0; 12214 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12215 } 12216 12217 // Intermediate hash value 12218 H0l = H0.low = (H0l + al); 12219 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12220 H1l = H1.low = (H1l + bl); 12221 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12222 H2l = H2.low = (H2l + cl); 12223 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12224 H3l = H3.low = (H3l + dl); 12225 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12226 H4l = H4.low = (H4l + el); 12227 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12228 H5l = H5.low = (H5l + fl); 12229 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12230 H6l = H6.low = (H6l + gl); 12231 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12232 H7l = H7.low = (H7l + hl); 12233 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12234 }, 12235 12236 _doFinalize: function () { 12237 // Shortcuts 12238 var data = this._data; 12239 var dataWords = data.words; 12240 12241 var nBitsTotal = this._nDataBytes * 8; 12242 var nBitsLeft = data.sigBytes * 8; 12243 12244 // Add padding 12245 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12246 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12247 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12248 data.sigBytes = dataWords.length * 4; 12249 12250 // Hash final blocks 12251 this._process(); 12252 12253 // Convert hash to 32-bit word array before returning 12254 var hash = this._hash.toX32(); 12255 12256 // Return final computed hash 12257 return hash; 12258 }, 12259 12260 clone: function () { 12261 var clone = Hasher.clone.call(this); 12262 clone._hash = this._hash.clone(); 12263 12264 return clone; 12265 }, 12266 12267 blockSize: 1024/32 12268 }); 12269 12270 /** 12271 * Shortcut function to the hasher's object interface. 12272 * 12273 * @param {WordArray|string} message The message to hash. 12274 * 12275 * @return {WordArray} The hash. 12276 * 12277 * @static 12278 * 12279 * @example 12280 * 12281 * var hash = CryptoJS.SHA512('message'); 12282 * var hash = CryptoJS.SHA512(wordArray); 12283 */ 12284 C.SHA512 = Hasher._createHelper(SHA512); 12285 12286 /** 12287 * Shortcut function to the HMAC's object interface. 12288 * 12289 * @param {WordArray|string} message The message to hash. 12290 * @param {WordArray|string} key The secret key. 12291 * 12292 * @return {WordArray} The HMAC. 12293 * 12294 * @static 12295 * 12296 * @example 12297 * 12298 * var hmac = CryptoJS.HmacSHA512(message, key); 12299 */ 12300 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12301 }()); 12302 12303 12304 return CryptoJS.SHA512; 12305 12306 })); 12307 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 12308 ;(function (root, factory, undef) { 12309 if (typeof exports === "object") { 12310 // CommonJS 12311 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12312 } 12313 else if (typeof define === "function" && define.amd) { 12314 // AMD 12315 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12316 } 12317 else { 12318 // Global (browser) 12319 factory(root.CryptoJS); 12320 } 12321 }(this, function (CryptoJS) { 12322 12323 (function () { 12324 // Shortcuts 12325 var C = CryptoJS; 12326 var C_lib = C.lib; 12327 var WordArray = C_lib.WordArray; 12328 var BlockCipher = C_lib.BlockCipher; 12329 var C_algo = C.algo; 12330 12331 // Permuted Choice 1 constants 12332 var PC1 = [ 12333 57, 49, 41, 33, 25, 17, 9, 1, 12334 58, 50, 42, 34, 26, 18, 10, 2, 12335 59, 51, 43, 35, 27, 19, 11, 3, 12336 60, 52, 44, 36, 63, 55, 47, 39, 12337 31, 23, 15, 7, 62, 54, 46, 38, 12338 30, 22, 14, 6, 61, 53, 45, 37, 12339 29, 21, 13, 5, 28, 20, 12, 4 12340 ]; 12341 12342 // Permuted Choice 2 constants 12343 var PC2 = [ 12344 14, 17, 11, 24, 1, 5, 12345 3, 28, 15, 6, 21, 10, 12346 23, 19, 12, 4, 26, 8, 12347 16, 7, 27, 20, 13, 2, 12348 41, 52, 31, 37, 47, 55, 12349 30, 40, 51, 45, 33, 48, 12350 44, 49, 39, 56, 34, 53, 12351 46, 42, 50, 36, 29, 32 12352 ]; 12353 12354 // Cumulative bit shift constants 12355 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12356 12357 // SBOXes and round permutation constants 12358 var SBOX_P = [ 12359 { 12360 0x0: 0x808200, 12361 0x10000000: 0x8000, 12362 0x20000000: 0x808002, 12363 0x30000000: 0x2, 12364 0x40000000: 0x200, 12365 0x50000000: 0x808202, 12366 0x60000000: 0x800202, 12367 0x70000000: 0x800000, 12368 0x80000000: 0x202, 12369 0x90000000: 0x800200, 12370 0xa0000000: 0x8200, 12371 0xb0000000: 0x808000, 12372 0xc0000000: 0x8002, 12373 0xd0000000: 0x800002, 12374 0xe0000000: 0x0, 12375 0xf0000000: 0x8202, 12376 0x8000000: 0x0, 12377 0x18000000: 0x808202, 12378 0x28000000: 0x8202, 12379 0x38000000: 0x8000, 12380 0x48000000: 0x808200, 12381 0x58000000: 0x200, 12382 0x68000000: 0x808002, 12383 0x78000000: 0x2, 12384 0x88000000: 0x800200, 12385 0x98000000: 0x8200, 12386 0xa8000000: 0x808000, 12387 0xb8000000: 0x800202, 12388 0xc8000000: 0x800002, 12389 0xd8000000: 0x8002, 12390 0xe8000000: 0x202, 12391 0xf8000000: 0x800000, 12392 0x1: 0x8000, 12393 0x10000001: 0x2, 12394 0x20000001: 0x808200, 12395 0x30000001: 0x800000, 12396 0x40000001: 0x808002, 12397 0x50000001: 0x8200, 12398 0x60000001: 0x200, 12399 0x70000001: 0x800202, 12400 0x80000001: 0x808202, 12401 0x90000001: 0x808000, 12402 0xa0000001: 0x800002, 12403 0xb0000001: 0x8202, 12404 0xc0000001: 0x202, 12405 0xd0000001: 0x800200, 12406 0xe0000001: 0x8002, 12407 0xf0000001: 0x0, 12408 0x8000001: 0x808202, 12409 0x18000001: 0x808000, 12410 0x28000001: 0x800000, 12411 0x38000001: 0x200, 12412 0x48000001: 0x8000, 12413 0x58000001: 0x800002, 12414 0x68000001: 0x2, 12415 0x78000001: 0x8202, 12416 0x88000001: 0x8002, 12417 0x98000001: 0x800202, 12418 0xa8000001: 0x202, 12419 0xb8000001: 0x808200, 12420 0xc8000001: 0x800200, 12421 0xd8000001: 0x0, 12422 0xe8000001: 0x8200, 12423 0xf8000001: 0x808002 12424 }, 12425 { 12426 0x0: 0x40084010, 12427 0x1000000: 0x4000, 12428 0x2000000: 0x80000, 12429 0x3000000: 0x40080010, 12430 0x4000000: 0x40000010, 12431 0x5000000: 0x40084000, 12432 0x6000000: 0x40004000, 12433 0x7000000: 0x10, 12434 0x8000000: 0x84000, 12435 0x9000000: 0x40004010, 12436 0xa000000: 0x40000000, 12437 0xb000000: 0x84010, 12438 0xc000000: 0x80010, 12439 0xd000000: 0x0, 12440 0xe000000: 0x4010, 12441 0xf000000: 0x40080000, 12442 0x800000: 0x40004000, 12443 0x1800000: 0x84010, 12444 0x2800000: 0x10, 12445 0x3800000: 0x40004010, 12446 0x4800000: 0x40084010, 12447 0x5800000: 0x40000000, 12448 0x6800000: 0x80000, 12449 0x7800000: 0x40080010, 12450 0x8800000: 0x80010, 12451 0x9800000: 0x0, 12452 0xa800000: 0x4000, 12453 0xb800000: 0x40080000, 12454 0xc800000: 0x40000010, 12455 0xd800000: 0x84000, 12456 0xe800000: 0x40084000, 12457 0xf800000: 0x4010, 12458 0x10000000: 0x0, 12459 0x11000000: 0x40080010, 12460 0x12000000: 0x40004010, 12461 0x13000000: 0x40084000, 12462 0x14000000: 0x40080000, 12463 0x15000000: 0x10, 12464 0x16000000: 0x84010, 12465 0x17000000: 0x4000, 12466 0x18000000: 0x4010, 12467 0x19000000: 0x80000, 12468 0x1a000000: 0x80010, 12469 0x1b000000: 0x40000010, 12470 0x1c000000: 0x84000, 12471 0x1d000000: 0x40004000, 12472 0x1e000000: 0x40000000, 12473 0x1f000000: 0x40084010, 12474 0x10800000: 0x84010, 12475 0x11800000: 0x80000, 12476 0x12800000: 0x40080000, 12477 0x13800000: 0x4000, 12478 0x14800000: 0x40004000, 12479 0x15800000: 0x40084010, 12480 0x16800000: 0x10, 12481 0x17800000: 0x40000000, 12482 0x18800000: 0x40084000, 12483 0x19800000: 0x40000010, 12484 0x1a800000: 0x40004010, 12485 0x1b800000: 0x80010, 12486 0x1c800000: 0x0, 12487 0x1d800000: 0x4010, 12488 0x1e800000: 0x40080010, 12489 0x1f800000: 0x84000 12490 }, 12491 { 12492 0x0: 0x104, 12493 0x100000: 0x0, 12494 0x200000: 0x4000100, 12495 0x300000: 0x10104, 12496 0x400000: 0x10004, 12497 0x500000: 0x4000004, 12498 0x600000: 0x4010104, 12499 0x700000: 0x4010000, 12500 0x800000: 0x4000000, 12501 0x900000: 0x4010100, 12502 0xa00000: 0x10100, 12503 0xb00000: 0x4010004, 12504 0xc00000: 0x4000104, 12505 0xd00000: 0x10000, 12506 0xe00000: 0x4, 12507 0xf00000: 0x100, 12508 0x80000: 0x4010100, 12509 0x180000: 0x4010004, 12510 0x280000: 0x0, 12511 0x380000: 0x4000100, 12512 0x480000: 0x4000004, 12513 0x580000: 0x10000, 12514 0x680000: 0x10004, 12515 0x780000: 0x104, 12516 0x880000: 0x4, 12517 0x980000: 0x100, 12518 0xa80000: 0x4010000, 12519 0xb80000: 0x10104, 12520 0xc80000: 0x10100, 12521 0xd80000: 0x4000104, 12522 0xe80000: 0x4010104, 12523 0xf80000: 0x4000000, 12524 0x1000000: 0x4010100, 12525 0x1100000: 0x10004, 12526 0x1200000: 0x10000, 12527 0x1300000: 0x4000100, 12528 0x1400000: 0x100, 12529 0x1500000: 0x4010104, 12530 0x1600000: 0x4000004, 12531 0x1700000: 0x0, 12532 0x1800000: 0x4000104, 12533 0x1900000: 0x4000000, 12534 0x1a00000: 0x4, 12535 0x1b00000: 0x10100, 12536 0x1c00000: 0x4010000, 12537 0x1d00000: 0x104, 12538 0x1e00000: 0x10104, 12539 0x1f00000: 0x4010004, 12540 0x1080000: 0x4000000, 12541 0x1180000: 0x104, 12542 0x1280000: 0x4010100, 12543 0x1380000: 0x0, 12544 0x1480000: 0x10004, 12545 0x1580000: 0x4000100, 12546 0x1680000: 0x100, 12547 0x1780000: 0x4010004, 12548 0x1880000: 0x10000, 12549 0x1980000: 0x4010104, 12550 0x1a80000: 0x10104, 12551 0x1b80000: 0x4000004, 12552 0x1c80000: 0x4000104, 12553 0x1d80000: 0x4010000, 12554 0x1e80000: 0x4, 12555 0x1f80000: 0x10100 12556 }, 12557 { 12558 0x0: 0x80401000, 12559 0x10000: 0x80001040, 12560 0x20000: 0x401040, 12561 0x30000: 0x80400000, 12562 0x40000: 0x0, 12563 0x50000: 0x401000, 12564 0x60000: 0x80000040, 12565 0x70000: 0x400040, 12566 0x80000: 0x80000000, 12567 0x90000: 0x400000, 12568 0xa0000: 0x40, 12569 0xb0000: 0x80001000, 12570 0xc0000: 0x80400040, 12571 0xd0000: 0x1040, 12572 0xe0000: 0x1000, 12573 0xf0000: 0x80401040, 12574 0x8000: 0x80001040, 12575 0x18000: 0x40, 12576 0x28000: 0x80400040, 12577 0x38000: 0x80001000, 12578 0x48000: 0x401000, 12579 0x58000: 0x80401040, 12580 0x68000: 0x0, 12581 0x78000: 0x80400000, 12582 0x88000: 0x1000, 12583 0x98000: 0x80401000, 12584 0xa8000: 0x400000, 12585 0xb8000: 0x1040, 12586 0xc8000: 0x80000000, 12587 0xd8000: 0x400040, 12588 0xe8000: 0x401040, 12589 0xf8000: 0x80000040, 12590 0x100000: 0x400040, 12591 0x110000: 0x401000, 12592 0x120000: 0x80000040, 12593 0x130000: 0x0, 12594 0x140000: 0x1040, 12595 0x150000: 0x80400040, 12596 0x160000: 0x80401000, 12597 0x170000: 0x80001040, 12598 0x180000: 0x80401040, 12599 0x190000: 0x80000000, 12600 0x1a0000: 0x80400000, 12601 0x1b0000: 0x401040, 12602 0x1c0000: 0x80001000, 12603 0x1d0000: 0x400000, 12604 0x1e0000: 0x40, 12605 0x1f0000: 0x1000, 12606 0x108000: 0x80400000, 12607 0x118000: 0x80401040, 12608 0x128000: 0x0, 12609 0x138000: 0x401000, 12610 0x148000: 0x400040, 12611 0x158000: 0x80000000, 12612 0x168000: 0x80001040, 12613 0x178000: 0x40, 12614 0x188000: 0x80000040, 12615 0x198000: 0x1000, 12616 0x1a8000: 0x80001000, 12617 0x1b8000: 0x80400040, 12618 0x1c8000: 0x1040, 12619 0x1d8000: 0x80401000, 12620 0x1e8000: 0x400000, 12621 0x1f8000: 0x401040 12622 }, 12623 { 12624 0x0: 0x80, 12625 0x1000: 0x1040000, 12626 0x2000: 0x40000, 12627 0x3000: 0x20000000, 12628 0x4000: 0x20040080, 12629 0x5000: 0x1000080, 12630 0x6000: 0x21000080, 12631 0x7000: 0x40080, 12632 0x8000: 0x1000000, 12633 0x9000: 0x20040000, 12634 0xa000: 0x20000080, 12635 0xb000: 0x21040080, 12636 0xc000: 0x21040000, 12637 0xd000: 0x0, 12638 0xe000: 0x1040080, 12639 0xf000: 0x21000000, 12640 0x800: 0x1040080, 12641 0x1800: 0x21000080, 12642 0x2800: 0x80, 12643 0x3800: 0x1040000, 12644 0x4800: 0x40000, 12645 0x5800: 0x20040080, 12646 0x6800: 0x21040000, 12647 0x7800: 0x20000000, 12648 0x8800: 0x20040000, 12649 0x9800: 0x0, 12650 0xa800: 0x21040080, 12651 0xb800: 0x1000080, 12652 0xc800: 0x20000080, 12653 0xd800: 0x21000000, 12654 0xe800: 0x1000000, 12655 0xf800: 0x40080, 12656 0x10000: 0x40000, 12657 0x11000: 0x80, 12658 0x12000: 0x20000000, 12659 0x13000: 0x21000080, 12660 0x14000: 0x1000080, 12661 0x15000: 0x21040000, 12662 0x16000: 0x20040080, 12663 0x17000: 0x1000000, 12664 0x18000: 0x21040080, 12665 0x19000: 0x21000000, 12666 0x1a000: 0x1040000, 12667 0x1b000: 0x20040000, 12668 0x1c000: 0x40080, 12669 0x1d000: 0x20000080, 12670 0x1e000: 0x0, 12671 0x1f000: 0x1040080, 12672 0x10800: 0x21000080, 12673 0x11800: 0x1000000, 12674 0x12800: 0x1040000, 12675 0x13800: 0x20040080, 12676 0x14800: 0x20000000, 12677 0x15800: 0x1040080, 12678 0x16800: 0x80, 12679 0x17800: 0x21040000, 12680 0x18800: 0x40080, 12681 0x19800: 0x21040080, 12682 0x1a800: 0x0, 12683 0x1b800: 0x21000000, 12684 0x1c800: 0x1000080, 12685 0x1d800: 0x40000, 12686 0x1e800: 0x20040000, 12687 0x1f800: 0x20000080 12688 }, 12689 { 12690 0x0: 0x10000008, 12691 0x100: 0x2000, 12692 0x200: 0x10200000, 12693 0x300: 0x10202008, 12694 0x400: 0x10002000, 12695 0x500: 0x200000, 12696 0x600: 0x200008, 12697 0x700: 0x10000000, 12698 0x800: 0x0, 12699 0x900: 0x10002008, 12700 0xa00: 0x202000, 12701 0xb00: 0x8, 12702 0xc00: 0x10200008, 12703 0xd00: 0x202008, 12704 0xe00: 0x2008, 12705 0xf00: 0x10202000, 12706 0x80: 0x10200000, 12707 0x180: 0x10202008, 12708 0x280: 0x8, 12709 0x380: 0x200000, 12710 0x480: 0x202008, 12711 0x580: 0x10000008, 12712 0x680: 0x10002000, 12713 0x780: 0x2008, 12714 0x880: 0x200008, 12715 0x980: 0x2000, 12716 0xa80: 0x10002008, 12717 0xb80: 0x10200008, 12718 0xc80: 0x0, 12719 0xd80: 0x10202000, 12720 0xe80: 0x202000, 12721 0xf80: 0x10000000, 12722 0x1000: 0x10002000, 12723 0x1100: 0x10200008, 12724 0x1200: 0x10202008, 12725 0x1300: 0x2008, 12726 0x1400: 0x200000, 12727 0x1500: 0x10000000, 12728 0x1600: 0x10000008, 12729 0x1700: 0x202000, 12730 0x1800: 0x202008, 12731 0x1900: 0x0, 12732 0x1a00: 0x8, 12733 0x1b00: 0x10200000, 12734 0x1c00: 0x2000, 12735 0x1d00: 0x10002008, 12736 0x1e00: 0x10202000, 12737 0x1f00: 0x200008, 12738 0x1080: 0x8, 12739 0x1180: 0x202000, 12740 0x1280: 0x200000, 12741 0x1380: 0x10000008, 12742 0x1480: 0x10002000, 12743 0x1580: 0x2008, 12744 0x1680: 0x10202008, 12745 0x1780: 0x10200000, 12746 0x1880: 0x10202000, 12747 0x1980: 0x10200008, 12748 0x1a80: 0x2000, 12749 0x1b80: 0x202008, 12750 0x1c80: 0x200008, 12751 0x1d80: 0x0, 12752 0x1e80: 0x10000000, 12753 0x1f80: 0x10002008 12754 }, 12755 { 12756 0x0: 0x100000, 12757 0x10: 0x2000401, 12758 0x20: 0x400, 12759 0x30: 0x100401, 12760 0x40: 0x2100401, 12761 0x50: 0x0, 12762 0x60: 0x1, 12763 0x70: 0x2100001, 12764 0x80: 0x2000400, 12765 0x90: 0x100001, 12766 0xa0: 0x2000001, 12767 0xb0: 0x2100400, 12768 0xc0: 0x2100000, 12769 0xd0: 0x401, 12770 0xe0: 0x100400, 12771 0xf0: 0x2000000, 12772 0x8: 0x2100001, 12773 0x18: 0x0, 12774 0x28: 0x2000401, 12775 0x38: 0x2100400, 12776 0x48: 0x100000, 12777 0x58: 0x2000001, 12778 0x68: 0x2000000, 12779 0x78: 0x401, 12780 0x88: 0x100401, 12781 0x98: 0x2000400, 12782 0xa8: 0x2100000, 12783 0xb8: 0x100001, 12784 0xc8: 0x400, 12785 0xd8: 0x2100401, 12786 0xe8: 0x1, 12787 0xf8: 0x100400, 12788 0x100: 0x2000000, 12789 0x110: 0x100000, 12790 0x120: 0x2000401, 12791 0x130: 0x2100001, 12792 0x140: 0x100001, 12793 0x150: 0x2000400, 12794 0x160: 0x2100400, 12795 0x170: 0x100401, 12796 0x180: 0x401, 12797 0x190: 0x2100401, 12798 0x1a0: 0x100400, 12799 0x1b0: 0x1, 12800 0x1c0: 0x0, 12801 0x1d0: 0x2100000, 12802 0x1e0: 0x2000001, 12803 0x1f0: 0x400, 12804 0x108: 0x100400, 12805 0x118: 0x2000401, 12806 0x128: 0x2100001, 12807 0x138: 0x1, 12808 0x148: 0x2000000, 12809 0x158: 0x100000, 12810 0x168: 0x401, 12811 0x178: 0x2100400, 12812 0x188: 0x2000001, 12813 0x198: 0x2100000, 12814 0x1a8: 0x0, 12815 0x1b8: 0x2100401, 12816 0x1c8: 0x100401, 12817 0x1d8: 0x400, 12818 0x1e8: 0x2000400, 12819 0x1f8: 0x100001 12820 }, 12821 { 12822 0x0: 0x8000820, 12823 0x1: 0x20000, 12824 0x2: 0x8000000, 12825 0x3: 0x20, 12826 0x4: 0x20020, 12827 0x5: 0x8020820, 12828 0x6: 0x8020800, 12829 0x7: 0x800, 12830 0x8: 0x8020000, 12831 0x9: 0x8000800, 12832 0xa: 0x20800, 12833 0xb: 0x8020020, 12834 0xc: 0x820, 12835 0xd: 0x0, 12836 0xe: 0x8000020, 12837 0xf: 0x20820, 12838 0x80000000: 0x800, 12839 0x80000001: 0x8020820, 12840 0x80000002: 0x8000820, 12841 0x80000003: 0x8000000, 12842 0x80000004: 0x8020000, 12843 0x80000005: 0x20800, 12844 0x80000006: 0x20820, 12845 0x80000007: 0x20, 12846 0x80000008: 0x8000020, 12847 0x80000009: 0x820, 12848 0x8000000a: 0x20020, 12849 0x8000000b: 0x8020800, 12850 0x8000000c: 0x0, 12851 0x8000000d: 0x8020020, 12852 0x8000000e: 0x8000800, 12853 0x8000000f: 0x20000, 12854 0x10: 0x20820, 12855 0x11: 0x8020800, 12856 0x12: 0x20, 12857 0x13: 0x800, 12858 0x14: 0x8000800, 12859 0x15: 0x8000020, 12860 0x16: 0x8020020, 12861 0x17: 0x20000, 12862 0x18: 0x0, 12863 0x19: 0x20020, 12864 0x1a: 0x8020000, 12865 0x1b: 0x8000820, 12866 0x1c: 0x8020820, 12867 0x1d: 0x20800, 12868 0x1e: 0x820, 12869 0x1f: 0x8000000, 12870 0x80000010: 0x20000, 12871 0x80000011: 0x800, 12872 0x80000012: 0x8020020, 12873 0x80000013: 0x20820, 12874 0x80000014: 0x20, 12875 0x80000015: 0x8020000, 12876 0x80000016: 0x8000000, 12877 0x80000017: 0x8000820, 12878 0x80000018: 0x8020820, 12879 0x80000019: 0x8000020, 12880 0x8000001a: 0x8000800, 12881 0x8000001b: 0x0, 12882 0x8000001c: 0x20800, 12883 0x8000001d: 0x820, 12884 0x8000001e: 0x20020, 12885 0x8000001f: 0x8020800 12886 } 12887 ]; 12888 12889 // Masks that select the SBOX input 12890 var SBOX_MASK = [ 12891 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 12892 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 12893 ]; 12894 12895 /** 12896 * DES block cipher algorithm. 12897 */ 12898 var DES = C_algo.DES = BlockCipher.extend({ 12899 _doReset: function () { 12900 // Shortcuts 12901 var key = this._key; 12902 var keyWords = key.words; 12903 12904 // Select 56 bits according to PC1 12905 var keyBits = []; 12906 for (var i = 0; i < 56; i++) { 12907 var keyBitPos = PC1[i] - 1; 12908 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 12909 } 12910 12911 // Assemble 16 subkeys 12912 var subKeys = this._subKeys = []; 12913 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 12914 // Create subkey 12915 var subKey = subKeys[nSubKey] = []; 12916 12917 // Shortcut 12918 var bitShift = BIT_SHIFTS[nSubKey]; 12919 12920 // Select 48 bits according to PC2 12921 for (var i = 0; i < 24; i++) { 12922 // Select from the left 28 key bits 12923 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 12924 12925 // Select from the right 28 key bits 12926 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 12927 } 12928 12929 // Since each subkey is applied to an expanded 32-bit input, 12930 // the subkey can be broken into 8 values scaled to 32-bits, 12931 // which allows the key to be used without expansion 12932 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 12933 for (var i = 1; i < 7; i++) { 12934 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 12935 } 12936 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 12937 } 12938 12939 // Compute inverse subkeys 12940 var invSubKeys = this._invSubKeys = []; 12941 for (var i = 0; i < 16; i++) { 12942 invSubKeys[i] = subKeys[15 - i]; 12943 } 12944 }, 12945 12946 encryptBlock: function (M, offset) { 12947 this._doCryptBlock(M, offset, this._subKeys); 12948 }, 12949 12950 decryptBlock: function (M, offset) { 12951 this._doCryptBlock(M, offset, this._invSubKeys); 12952 }, 12953 12954 _doCryptBlock: function (M, offset, subKeys) { 12955 // Get input 12956 this._lBlock = M[offset]; 12957 this._rBlock = M[offset + 1]; 12958 12959 // Initial permutation 12960 exchangeLR.call(this, 4, 0x0f0f0f0f); 12961 exchangeLR.call(this, 16, 0x0000ffff); 12962 exchangeRL.call(this, 2, 0x33333333); 12963 exchangeRL.call(this, 8, 0x00ff00ff); 12964 exchangeLR.call(this, 1, 0x55555555); 12965 12966 // Rounds 12967 for (var round = 0; round < 16; round++) { 12968 // Shortcuts 12969 var subKey = subKeys[round]; 12970 var lBlock = this._lBlock; 12971 var rBlock = this._rBlock; 12972 12973 // Feistel function 12974 var f = 0; 12975 for (var i = 0; i < 8; i++) { 12976 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 12977 } 12978 this._lBlock = rBlock; 12979 this._rBlock = lBlock ^ f; 12980 } 12981 12982 // Undo swap from last round 12983 var t = this._lBlock; 12984 this._lBlock = this._rBlock; 12985 this._rBlock = t; 12986 12987 // Final permutation 12988 exchangeLR.call(this, 1, 0x55555555); 12989 exchangeRL.call(this, 8, 0x00ff00ff); 12990 exchangeRL.call(this, 2, 0x33333333); 12991 exchangeLR.call(this, 16, 0x0000ffff); 12992 exchangeLR.call(this, 4, 0x0f0f0f0f); 12993 12994 // Set output 12995 M[offset] = this._lBlock; 12996 M[offset + 1] = this._rBlock; 12997 }, 12998 12999 keySize: 64/32, 13000 13001 ivSize: 64/32, 13002 13003 blockSize: 64/32 13004 }); 13005 13006 // Swap bits across the left and right words 13007 function exchangeLR(offset, mask) { 13008 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13009 this._rBlock ^= t; 13010 this._lBlock ^= t << offset; 13011 } 13012 13013 function exchangeRL(offset, mask) { 13014 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13015 this._lBlock ^= t; 13016 this._rBlock ^= t << offset; 13017 } 13018 13019 /** 13020 * Shortcut functions to the cipher's object interface. 13021 * 13022 * @example 13023 * 13024 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13025 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13026 */ 13027 C.DES = BlockCipher._createHelper(DES); 13028 13029 /** 13030 * Triple-DES block cipher algorithm. 13031 */ 13032 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13033 _doReset: function () { 13034 // Shortcuts 13035 var key = this._key; 13036 var keyWords = key.words; 13037 13038 // Create DES instances 13039 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13040 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13041 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13042 }, 13043 13044 encryptBlock: function (M, offset) { 13045 this._des1.encryptBlock(M, offset); 13046 this._des2.decryptBlock(M, offset); 13047 this._des3.encryptBlock(M, offset); 13048 }, 13049 13050 decryptBlock: function (M, offset) { 13051 this._des3.decryptBlock(M, offset); 13052 this._des2.encryptBlock(M, offset); 13053 this._des1.decryptBlock(M, offset); 13054 }, 13055 13056 keySize: 192/32, 13057 13058 ivSize: 64/32, 13059 13060 blockSize: 64/32 13061 }); 13062 13063 /** 13064 * Shortcut functions to the cipher's object interface. 13065 * 13066 * @example 13067 * 13068 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13069 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13070 */ 13071 C.TripleDES = BlockCipher._createHelper(TripleDES); 13072 }()); 13073 13074 13075 return CryptoJS.TripleDES; 13076 13077 })); 13078 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 13079 ;(function (root, factory) { 13080 if (typeof exports === "object") { 13081 // CommonJS 13082 module.exports = exports = factory(require("./core")); 13083 } 13084 else if (typeof define === "function" && define.amd) { 13085 // AMD 13086 define(["./core"], factory); 13087 } 13088 else { 13089 // Global (browser) 13090 factory(root.CryptoJS); 13091 } 13092 }(this, function (CryptoJS) { 13093 13094 (function (undefined) { 13095 // Shortcuts 13096 var C = CryptoJS; 13097 var C_lib = C.lib; 13098 var Base = C_lib.Base; 13099 var X32WordArray = C_lib.WordArray; 13100 13101 /** 13102 * x64 namespace. 13103 */ 13104 var C_x64 = C.x64 = {}; 13105 13106 /** 13107 * A 64-bit word. 13108 */ 13109 var X64Word = C_x64.Word = Base.extend({ 13110 /** 13111 * Initializes a newly created 64-bit word. 13112 * 13113 * @param {number} high The high 32 bits. 13114 * @param {number} low The low 32 bits. 13115 * 13116 * @example 13117 * 13118 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13119 */ 13120 init: function (high, low) { 13121 this.high = high; 13122 this.low = low; 13123 } 13124 13125 /** 13126 * Bitwise NOTs this word. 13127 * 13128 * @return {X64Word} A new x64-Word object after negating. 13129 * 13130 * @example 13131 * 13132 * var negated = x64Word.not(); 13133 */ 13134 // not: function () { 13135 // var high = ~this.high; 13136 // var low = ~this.low; 13137 13138 // return X64Word.create(high, low); 13139 // }, 13140 13141 /** 13142 * Bitwise ANDs this word with the passed word. 13143 * 13144 * @param {X64Word} word The x64-Word to AND with this word. 13145 * 13146 * @return {X64Word} A new x64-Word object after ANDing. 13147 * 13148 * @example 13149 * 13150 * var anded = x64Word.and(anotherX64Word); 13151 */ 13152 // and: function (word) { 13153 // var high = this.high & word.high; 13154 // var low = this.low & word.low; 13155 13156 // return X64Word.create(high, low); 13157 // }, 13158 13159 /** 13160 * Bitwise ORs this word with the passed word. 13161 * 13162 * @param {X64Word} word The x64-Word to OR with this word. 13163 * 13164 * @return {X64Word} A new x64-Word object after ORing. 13165 * 13166 * @example 13167 * 13168 * var ored = x64Word.or(anotherX64Word); 13169 */ 13170 // or: function (word) { 13171 // var high = this.high | word.high; 13172 // var low = this.low | word.low; 13173 13174 // return X64Word.create(high, low); 13175 // }, 13176 13177 /** 13178 * Bitwise XORs this word with the passed word. 13179 * 13180 * @param {X64Word} word The x64-Word to XOR with this word. 13181 * 13182 * @return {X64Word} A new x64-Word object after XORing. 13183 * 13184 * @example 13185 * 13186 * var xored = x64Word.xor(anotherX64Word); 13187 */ 13188 // xor: function (word) { 13189 // var high = this.high ^ word.high; 13190 // var low = this.low ^ word.low; 13191 13192 // return X64Word.create(high, low); 13193 // }, 13194 13195 /** 13196 * Shifts this word n bits to the left. 13197 * 13198 * @param {number} n The number of bits to shift. 13199 * 13200 * @return {X64Word} A new x64-Word object after shifting. 13201 * 13202 * @example 13203 * 13204 * var shifted = x64Word.shiftL(25); 13205 */ 13206 // shiftL: function (n) { 13207 // if (n < 32) { 13208 // var high = (this.high << n) | (this.low >>> (32 - n)); 13209 // var low = this.low << n; 13210 // } else { 13211 // var high = this.low << (n - 32); 13212 // var low = 0; 13213 // } 13214 13215 // return X64Word.create(high, low); 13216 // }, 13217 13218 /** 13219 * Shifts this word n bits to the right. 13220 * 13221 * @param {number} n The number of bits to shift. 13222 * 13223 * @return {X64Word} A new x64-Word object after shifting. 13224 * 13225 * @example 13226 * 13227 * var shifted = x64Word.shiftR(7); 13228 */ 13229 // shiftR: function (n) { 13230 // if (n < 32) { 13231 // var low = (this.low >>> n) | (this.high << (32 - n)); 13232 // var high = this.high >>> n; 13233 // } else { 13234 // var low = this.high >>> (n - 32); 13235 // var high = 0; 13236 // } 13237 13238 // return X64Word.create(high, low); 13239 // }, 13240 13241 /** 13242 * Rotates this word n bits to the left. 13243 * 13244 * @param {number} n The number of bits to rotate. 13245 * 13246 * @return {X64Word} A new x64-Word object after rotating. 13247 * 13248 * @example 13249 * 13250 * var rotated = x64Word.rotL(25); 13251 */ 13252 // rotL: function (n) { 13253 // return this.shiftL(n).or(this.shiftR(64 - n)); 13254 // }, 13255 13256 /** 13257 * Rotates this word n bits to the right. 13258 * 13259 * @param {number} n The number of bits to rotate. 13260 * 13261 * @return {X64Word} A new x64-Word object after rotating. 13262 * 13263 * @example 13264 * 13265 * var rotated = x64Word.rotR(7); 13266 */ 13267 // rotR: function (n) { 13268 // return this.shiftR(n).or(this.shiftL(64 - n)); 13269 // }, 13270 13271 /** 13272 * Adds this word with the passed word. 13273 * 13274 * @param {X64Word} word The x64-Word to add with this word. 13275 * 13276 * @return {X64Word} A new x64-Word object after adding. 13277 * 13278 * @example 13279 * 13280 * var added = x64Word.add(anotherX64Word); 13281 */ 13282 // add: function (word) { 13283 // var low = (this.low + word.low) | 0; 13284 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13285 // var high = (this.high + word.high + carry) | 0; 13286 13287 // return X64Word.create(high, low); 13288 // } 13289 }); 13290 13291 /** 13292 * An array of 64-bit words. 13293 * 13294 * @property {Array} words The array of CryptoJS.x64.Word objects. 13295 * @property {number} sigBytes The number of significant bytes in this word array. 13296 */ 13297 var X64WordArray = C_x64.WordArray = Base.extend({ 13298 /** 13299 * Initializes a newly created word array. 13300 * 13301 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13302 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13303 * 13304 * @example 13305 * 13306 * var wordArray = CryptoJS.x64.WordArray.create(); 13307 * 13308 * var wordArray = CryptoJS.x64.WordArray.create([ 13309 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13310 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13311 * ]); 13312 * 13313 * var wordArray = CryptoJS.x64.WordArray.create([ 13314 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13315 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13316 * ], 10); 13317 */ 13318 init: function (words, sigBytes) { 13319 words = this.words = words || []; 13320 13321 if (sigBytes != undefined) { 13322 this.sigBytes = sigBytes; 13323 } else { 13324 this.sigBytes = words.length * 8; 13325 } 13326 }, 13327 13328 /** 13329 * Converts this 64-bit word array to a 32-bit word array. 13330 * 13331 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13332 * 13333 * @example 13334 * 13335 * var x32WordArray = x64WordArray.toX32(); 13336 */ 13337 toX32: function () { 13338 // Shortcuts 13339 var x64Words = this.words; 13340 var x64WordsLength = x64Words.length; 13341 13342 // Convert 13343 var x32Words = []; 13344 for (var i = 0; i < x64WordsLength; i++) { 13345 var x64Word = x64Words[i]; 13346 x32Words.push(x64Word.high); 13347 x32Words.push(x64Word.low); 13348 } 13349 13350 return X32WordArray.create(x32Words, this.sigBytes); 13351 }, 13352 13353 /** 13354 * Creates a copy of this word array. 13355 * 13356 * @return {X64WordArray} The clone. 13357 * 13358 * @example 13359 * 13360 * var clone = x64WordArray.clone(); 13361 */ 13362 clone: function () { 13363 var clone = Base.clone.call(this); 13364 13365 // Clone "words" array 13366 var words = clone.words = this.words.slice(0); 13367 13368 // Clone each X64Word object 13369 var wordsLength = words.length; 13370 for (var i = 0; i < wordsLength; i++) { 13371 words[i] = words[i].clone(); 13372 } 13373 13374 return clone; 13375 } 13376 }); 13377 }()); 13378 13379 13380 return CryptoJS; 13381 13382 })); 13383 },{"./core":53}],85:[function(require,module,exports){ 13384 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13385 ;(function(root) { 13386 13387 // Detect free variables `exports` 13388 var freeExports = typeof exports == 'object' && exports; 13389 13390 // Detect free variable `module` 13391 var freeModule = typeof module == 'object' && module && 13392 module.exports == freeExports && module; 13393 13394 // Detect free variable `global`, from Node.js or Browserified code, 13395 // and use it as `root` 13396 var freeGlobal = typeof global == 'object' && global; 13397 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13398 root = freeGlobal; 13399 } 13400 13401 /*--------------------------------------------------------------------------*/ 13402 13403 var stringFromCharCode = String.fromCharCode; 13404 13405 // Taken from https://mths.be/punycode 13406 function ucs2decode(string) { 13407 var output = []; 13408 var counter = 0; 13409 var length = string.length; 13410 var value; 13411 var extra; 13412 while (counter < length) { 13413 value = string.charCodeAt(counter++); 13414 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13415 // high surrogate, and there is a next character 13416 extra = string.charCodeAt(counter++); 13417 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13418 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13419 } else { 13420 // unmatched surrogate; only append this code unit, in case the next 13421 // code unit is the high surrogate of a surrogate pair 13422 output.push(value); 13423 counter--; 13424 } 13425 } else { 13426 output.push(value); 13427 } 13428 } 13429 return output; 13430 } 13431 13432 // Taken from https://mths.be/punycode 13433 function ucs2encode(array) { 13434 var length = array.length; 13435 var index = -1; 13436 var value; 13437 var output = ''; 13438 while (++index < length) { 13439 value = array[index]; 13440 if (value > 0xFFFF) { 13441 value -= 0x10000; 13442 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13443 value = 0xDC00 | value & 0x3FF; 13444 } 13445 output += stringFromCharCode(value); 13446 } 13447 return output; 13448 } 13449 13450 function checkScalarValue(codePoint) { 13451 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13452 throw Error( 13453 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13454 ' is not a scalar value' 13455 ); 13456 } 13457 } 13458 /*--------------------------------------------------------------------------*/ 13459 13460 function createByte(codePoint, shift) { 13461 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13462 } 13463 13464 function encodeCodePoint(codePoint) { 13465 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13466 return stringFromCharCode(codePoint); 13467 } 13468 var symbol = ''; 13469 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13470 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13471 } 13472 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13473 checkScalarValue(codePoint); 13474 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13475 symbol += createByte(codePoint, 6); 13476 } 13477 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13478 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13479 symbol += createByte(codePoint, 12); 13480 symbol += createByte(codePoint, 6); 13481 } 13482 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13483 return symbol; 13484 } 13485 13486 function utf8encode(string) { 13487 var codePoints = ucs2decode(string); 13488 var length = codePoints.length; 13489 var index = -1; 13490 var codePoint; 13491 var byteString = ''; 13492 while (++index < length) { 13493 codePoint = codePoints[index]; 13494 byteString += encodeCodePoint(codePoint); 13495 } 13496 return byteString; 13497 } 13498 13499 /*--------------------------------------------------------------------------*/ 13500 13501 function readContinuationByte() { 13502 if (byteIndex >= byteCount) { 13503 throw Error('Invalid byte index'); 13504 } 13505 13506 var continuationByte = byteArray[byteIndex] & 0xFF; 13507 byteIndex++; 13508 13509 if ((continuationByte & 0xC0) == 0x80) { 13510 return continuationByte & 0x3F; 13511 } 13512 13513 // If we end up here, it’s not a continuation byte 13514 throw Error('Invalid continuation byte'); 13515 } 13516 13517 function decodeSymbol() { 13518 var byte1; 13519 var byte2; 13520 var byte3; 13521 var byte4; 13522 var codePoint; 13523 13524 if (byteIndex > byteCount) { 13525 throw Error('Invalid byte index'); 13526 } 13527 13528 if (byteIndex == byteCount) { 13529 return false; 13530 } 13531 13532 // Read first byte 13533 byte1 = byteArray[byteIndex] & 0xFF; 13534 byteIndex++; 13535 13536 // 1-byte sequence (no continuation bytes) 13537 if ((byte1 & 0x80) == 0) { 13538 return byte1; 13539 } 13540 13541 // 2-byte sequence 13542 if ((byte1 & 0xE0) == 0xC0) { 13543 byte2 = readContinuationByte(); 13544 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13545 if (codePoint >= 0x80) { 13546 return codePoint; 13547 } else { 13548 throw Error('Invalid continuation byte'); 13549 } 13550 } 13551 13552 // 3-byte sequence (may include unpaired surrogates) 13553 if ((byte1 & 0xF0) == 0xE0) { 13554 byte2 = readContinuationByte(); 13555 byte3 = readContinuationByte(); 13556 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13557 if (codePoint >= 0x0800) { 13558 checkScalarValue(codePoint); 13559 return codePoint; 13560 } else { 13561 throw Error('Invalid continuation byte'); 13562 } 13563 } 13564 13565 // 4-byte sequence 13566 if ((byte1 & 0xF8) == 0xF0) { 13567 byte2 = readContinuationByte(); 13568 byte3 = readContinuationByte(); 13569 byte4 = readContinuationByte(); 13570 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 13571 (byte3 << 0x06) | byte4; 13572 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 13573 return codePoint; 13574 } 13575 } 13576 13577 throw Error('Invalid UTF-8 detected'); 13578 } 13579 13580 var byteArray; 13581 var byteCount; 13582 var byteIndex; 13583 function utf8decode(byteString) { 13584 byteArray = ucs2decode(byteString); 13585 byteCount = byteArray.length; 13586 byteIndex = 0; 13587 var codePoints = []; 13588 var tmp; 13589 while ((tmp = decodeSymbol()) !== false) { 13590 codePoints.push(tmp); 13591 } 13592 return ucs2encode(codePoints); 13593 } 13594 13595 /*--------------------------------------------------------------------------*/ 13596 13597 var utf8 = { 13598 'version': '2.1.2', 13599 'encode': utf8encode, 13600 'decode': utf8decode 13601 }; 13602 13603 // Some AMD build optimizers, like r.js, check for specific condition patterns 13604 // like the following: 13605 if ( 13606 typeof define == 'function' && 13607 typeof define.amd == 'object' && 13608 define.amd 13609 ) { 13610 define(function() { 13611 return utf8; 13612 }); 13613 } else if (freeExports && !freeExports.nodeType) { 13614 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 13615 freeModule.exports = utf8; 13616 } else { // in Narwhal or RingoJS v0.7.0- 13617 var object = {}; 13618 var hasOwnProperty = object.hasOwnProperty; 13619 for (var key in utf8) { 13620 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 13621 } 13622 } 13623 } else { // in Rhino or a web browser 13624 root.utf8 = utf8; 13625 } 13626 13627 }(this)); 13628 13629 },{}],86:[function(require,module,exports){ 13630 module.exports = XMLHttpRequest; 13631 13632 },{}],"bignumber.js":[function(require,module,exports){ 13633 'use strict'; 13634 13635 module.exports = BigNumber; // jshint ignore:line 13636 13637 13638 },{}],"web3":[function(require,module,exports){ 13639 var Web3 = require('./lib/web3'); 13640 13641 // don't override global variable 13642 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 13643 window.Web3 = Web3; 13644 } 13645 13646 module.exports = Web3; 13647 13648 },{"./lib/web3":22}]},{},["web3"]) 13649 //# sourceMappingURL=web3-light.js.map