github.com/bcskill/bcschain/v3@v3.4.9-beta2/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 /** 3719 * Formats the input of a transaction and converts all values to HEX 3720 * 3721 * @method inputCallFormatter 3722 * @param {Object} transaction options 3723 * @returns object 3724 */ 3725 var inputCallFormatter = function (options){ 3726 3727 options.from = options.from || config.defaultAccount; 3728 3729 if (options.from) { 3730 options.from = inputAddressFormatter(options.from); 3731 } 3732 3733 if (options.to) { // it might be contract creation 3734 options.to = inputAddressFormatter(options.to); 3735 } 3736 3737 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3738 return options[key] !== undefined; 3739 }).forEach(function(key){ 3740 options[key] = utils.fromDecimal(options[key]); 3741 }); 3742 3743 return options; 3744 }; 3745 3746 /** 3747 * Formats the input of a transaction and converts all values to HEX 3748 * 3749 * @method inputTransactionFormatter 3750 * @param {Object} transaction options 3751 * @returns object 3752 */ 3753 var inputTransactionFormatter = function (options){ 3754 3755 options.from = options.from || config.defaultAccount; 3756 options.from = inputAddressFormatter(options.from); 3757 3758 if (options.to) { // it might be contract creation 3759 options.to = inputAddressFormatter(options.to); 3760 } 3761 3762 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3763 return options[key] !== undefined; 3764 }).forEach(function(key){ 3765 options[key] = utils.fromDecimal(options[key]); 3766 }); 3767 3768 return options; 3769 }; 3770 3771 /** 3772 * Formats the output of a transaction to its proper values 3773 * 3774 * @method outputTransactionFormatter 3775 * @param {Object} tx 3776 * @returns {Object} 3777 */ 3778 var outputTransactionFormatter = function (tx){ 3779 if(tx.blockNumber !== null) 3780 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3781 if(tx.transactionIndex !== null) 3782 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3783 tx.nonce = utils.toDecimal(tx.nonce); 3784 tx.gas = utils.toDecimal(tx.gas); 3785 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3786 tx.value = utils.toBigNumber(tx.value); 3787 return tx; 3788 }; 3789 3790 /** 3791 * Formats the output of a transaction receipt to its proper values 3792 * 3793 * @method outputTransactionReceiptFormatter 3794 * @param {Object} receipt 3795 * @returns {Object} 3796 */ 3797 var outputTransactionReceiptFormatter = function (receipt){ 3798 if(receipt.blockNumber !== null) 3799 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3800 if(receipt.transactionIndex !== null) 3801 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3802 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3803 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3804 3805 if(utils.isArray(receipt.logs)) { 3806 receipt.logs = receipt.logs.map(function(log){ 3807 return outputLogFormatter(log); 3808 }); 3809 } 3810 3811 return receipt; 3812 }; 3813 3814 /** 3815 * Formats the output of a block to its proper values 3816 * 3817 * @method outputBlockFormatter 3818 * @param {Object} block 3819 * @returns {Object} 3820 */ 3821 var outputBlockFormatter = function(block) { 3822 3823 // transform to number 3824 block.gasLimit = utils.toDecimal(block.gasLimit); 3825 block.gasUsed = utils.toDecimal(block.gasUsed); 3826 block.size = utils.toDecimal(block.size); 3827 block.timestamp = utils.toDecimal(block.timestamp); 3828 if(block.number !== null) 3829 block.number = utils.toDecimal(block.number); 3830 3831 block.difficulty = utils.toBigNumber(block.difficulty); 3832 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3833 3834 if (utils.isArray(block.transactions)) { 3835 block.transactions.forEach(function(item){ 3836 if(!utils.isString(item)) 3837 return outputTransactionFormatter(item); 3838 }); 3839 } 3840 3841 return block; 3842 }; 3843 3844 /** 3845 * Formats the output of a genesisAlloc to its proper values 3846 * 3847 * @method genesisAllocFormatter 3848 * @param {Object} genesisAlloc 3849 * @returns {Object} 3850 */ 3851 var genesisAllocFormatter = function(genesisAlloc) { 3852 Object.keys(genesisAlloc).forEach(function(key) { 3853 // transform to number 3854 genesisAlloc[key].balance = utils.toDecimal(genesisAlloc[key].balance) 3855 }); 3856 return genesisAlloc 3857 }; 3858 3859 /** 3860 * Formats the output of a log 3861 * 3862 * @method outputLogFormatter 3863 * @param {Object} log object 3864 * @returns {Object} log 3865 */ 3866 var outputLogFormatter = function(log) { 3867 if(log.blockNumber) 3868 log.blockNumber = utils.toDecimal(log.blockNumber); 3869 if(log.transactionIndex) 3870 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3871 if(log.logIndex) 3872 log.logIndex = utils.toDecimal(log.logIndex); 3873 3874 return log; 3875 }; 3876 3877 /** 3878 * Formats the input of a whisper post and converts all values to HEX 3879 * 3880 * @method inputPostFormatter 3881 * @param {Object} transaction object 3882 * @returns {Object} 3883 */ 3884 var inputPostFormatter = function(post) { 3885 3886 // post.payload = utils.toHex(post.payload); 3887 post.ttl = utils.fromDecimal(post.ttl); 3888 post.workToProve = utils.fromDecimal(post.workToProve); 3889 post.priority = utils.fromDecimal(post.priority); 3890 3891 // fallback 3892 if (!utils.isArray(post.topics)) { 3893 post.topics = post.topics ? [post.topics] : []; 3894 } 3895 3896 // format the following options 3897 post.topics = post.topics.map(function(topic){ 3898 // convert only if not hex 3899 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3900 }); 3901 3902 return post; 3903 }; 3904 3905 /** 3906 * Formats the output of a received post message 3907 * 3908 * @method outputPostFormatter 3909 * @param {Object} 3910 * @returns {Object} 3911 */ 3912 var outputPostFormatter = function(post){ 3913 3914 post.expiry = utils.toDecimal(post.expiry); 3915 post.sent = utils.toDecimal(post.sent); 3916 post.ttl = utils.toDecimal(post.ttl); 3917 post.workProved = utils.toDecimal(post.workProved); 3918 // post.payloadRaw = post.payload; 3919 // post.payload = utils.toAscii(post.payload); 3920 3921 // if (utils.isJson(post.payload)) { 3922 // post.payload = JSON.parse(post.payload); 3923 // } 3924 3925 // format the following options 3926 if (!post.topics) { 3927 post.topics = []; 3928 } 3929 post.topics = post.topics.map(function(topic){ 3930 return utils.toAscii(topic); 3931 }); 3932 3933 return post; 3934 }; 3935 3936 var inputAddressFormatter = function (address) { 3937 var iban = new Iban(address); 3938 if (iban.isValid() && iban.isDirect()) { 3939 return '0x' + iban.address(); 3940 } else if (utils.isStrictAddress(address)) { 3941 return address; 3942 } else if (utils.isAddress(address)) { 3943 return '0x' + address; 3944 } 3945 throw new Error('invalid address'); 3946 }; 3947 3948 3949 var outputSyncingFormatter = function(result) { 3950 if (!result) { 3951 return result; 3952 } 3953 3954 result.startingBlock = utils.toDecimal(result.startingBlock); 3955 result.currentBlock = utils.toDecimal(result.currentBlock); 3956 result.highestBlock = utils.toDecimal(result.highestBlock); 3957 if (result.knownStates) { 3958 result.knownStates = utils.toDecimal(result.knownStates); 3959 result.pulledStates = utils.toDecimal(result.pulledStates); 3960 } 3961 3962 return result; 3963 }; 3964 3965 module.exports = { 3966 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 3967 inputBlockNumberFormatter: inputBlockNumberFormatter, 3968 inputCallFormatter: inputCallFormatter, 3969 inputTransactionFormatter: inputTransactionFormatter, 3970 inputAddressFormatter: inputAddressFormatter, 3971 inputPostFormatter: inputPostFormatter, 3972 outputBigNumberFormatter: outputBigNumberFormatter, 3973 outputTransactionFormatter: outputTransactionFormatter, 3974 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 3975 outputBlockFormatter: outputBlockFormatter, 3976 genesisAllocFormatter: genesisAllocFormatter, 3977 outputLogFormatter: outputLogFormatter, 3978 outputPostFormatter: outputPostFormatter, 3979 outputSyncingFormatter: outputSyncingFormatter 3980 }; 3981 3982 3983 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 3984 /* 3985 This file is part of web3.js. 3986 3987 web3.js is free software: you can redistribute it and/or modify 3988 it under the terms of the GNU Lesser General Public License as published by 3989 the Free Software Foundation, either version 3 of the License, or 3990 (at your option) any later version. 3991 3992 web3.js is distributed in the hope that it will be useful, 3993 but WITHOUT ANY WARRANTY; without even the implied warranty of 3994 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3995 GNU Lesser General Public License for more details. 3996 3997 You should have received a copy of the GNU Lesser General Public License 3998 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3999 */ 4000 /** 4001 * @file function.js 4002 * @author Marek Kotewicz <marek@ethdev.com> 4003 * @date 2015 4004 */ 4005 4006 var coder = require('../solidity/coder'); 4007 var utils = require('../utils/utils'); 4008 var errors = require('./errors'); 4009 var formatters = require('./formatters'); 4010 var sha3 = require('../utils/sha3'); 4011 4012 /** 4013 * This prototype should be used to call/sendTransaction to solidity functions 4014 */ 4015 var SolidityFunction = function (eth, json, address) { 4016 this._eth = eth; 4017 this._inputTypes = json.inputs.map(function (i) { 4018 return i.type; 4019 }); 4020 this._outputTypes = json.outputs.map(function (i) { 4021 return i.type; 4022 }); 4023 this._constant = json.constant; 4024 this._payable = json.payable; 4025 this._name = utils.transformToFullName(json); 4026 this._address = address; 4027 }; 4028 4029 SolidityFunction.prototype.extractCallback = function (args) { 4030 if (utils.isFunction(args[args.length - 1])) { 4031 return args.pop(); // modify the args array! 4032 } 4033 }; 4034 4035 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4036 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4037 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4038 } 4039 }; 4040 4041 /** 4042 * Should be called to check if the number of arguments is correct 4043 * 4044 * @method validateArgs 4045 * @param {Array} arguments 4046 * @throws {Error} if it is not 4047 */ 4048 SolidityFunction.prototype.validateArgs = function (args) { 4049 var inputArgs = args.filter(function (a) { 4050 // filter the options object but not arguments that are arrays 4051 return !( (utils.isObject(a) === true) && 4052 (utils.isArray(a) === false) && 4053 (utils.isBigNumber(a) === false) 4054 ); 4055 }); 4056 if (inputArgs.length !== this._inputTypes.length) { 4057 throw errors.InvalidNumberOfSolidityArgs(); 4058 } 4059 }; 4060 4061 /** 4062 * Should be used to create payload from arguments 4063 * 4064 * @method toPayload 4065 * @param {Array} solidity function params 4066 * @param {Object} optional payload options 4067 */ 4068 SolidityFunction.prototype.toPayload = function (args) { 4069 var options = {}; 4070 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4071 options = args[args.length - 1]; 4072 } 4073 this.validateArgs(args); 4074 options.to = this._address; 4075 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4076 return options; 4077 }; 4078 4079 /** 4080 * Should be used to get function signature 4081 * 4082 * @method signature 4083 * @return {String} function signature 4084 */ 4085 SolidityFunction.prototype.signature = function () { 4086 return sha3(this._name).slice(0, 8); 4087 }; 4088 4089 4090 SolidityFunction.prototype.unpackOutput = function (output) { 4091 if (!output) { 4092 return; 4093 } 4094 4095 output = output.length >= 2 ? output.slice(2) : output; 4096 var result = coder.decodeParams(this._outputTypes, output); 4097 return result.length === 1 ? result[0] : result; 4098 }; 4099 4100 /** 4101 * Calls a contract function. 4102 * 4103 * @method call 4104 * @param {...Object} Contract function arguments 4105 * @param {function} If the last argument is a function, the contract function 4106 * call will be asynchronous, and the callback will be passed the 4107 * error and result. 4108 * @return {String} output bytes 4109 */ 4110 SolidityFunction.prototype.call = function () { 4111 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4112 var callback = this.extractCallback(args); 4113 var defaultBlock = this.extractDefaultBlock(args); 4114 var payload = this.toPayload(args); 4115 4116 4117 if (!callback) { 4118 var output = this._eth.call(payload, defaultBlock); 4119 return this.unpackOutput(output); 4120 } 4121 4122 var self = this; 4123 this._eth.call(payload, defaultBlock, function (error, output) { 4124 if (error) return callback(error, null); 4125 4126 var unpacked = null; 4127 try { 4128 unpacked = self.unpackOutput(output); 4129 } 4130 catch (e) { 4131 error = e; 4132 } 4133 4134 callback(error, unpacked); 4135 }); 4136 }; 4137 4138 /** 4139 * Should be used to sendTransaction to solidity function 4140 * 4141 * @method sendTransaction 4142 */ 4143 SolidityFunction.prototype.sendTransaction = function () { 4144 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4145 var callback = this.extractCallback(args); 4146 var payload = this.toPayload(args); 4147 4148 if (payload.value > 0 && !this._payable) { 4149 throw new Error('Cannot send value to non-payable function'); 4150 } 4151 4152 if (!callback) { 4153 return this._eth.sendTransaction(payload); 4154 } 4155 4156 this._eth.sendTransaction(payload, callback); 4157 }; 4158 4159 /** 4160 * Should be used to estimateGas of solidity function 4161 * 4162 * @method estimateGas 4163 */ 4164 SolidityFunction.prototype.estimateGas = function () { 4165 var args = Array.prototype.slice.call(arguments); 4166 var callback = this.extractCallback(args); 4167 var payload = this.toPayload(args); 4168 4169 if (!callback) { 4170 return this._eth.estimateGas(payload); 4171 } 4172 4173 this._eth.estimateGas(payload, callback); 4174 }; 4175 4176 /** 4177 * Return the encoded data of the call 4178 * 4179 * @method getData 4180 * @return {String} the encoded data 4181 */ 4182 SolidityFunction.prototype.getData = function () { 4183 var args = Array.prototype.slice.call(arguments); 4184 var payload = this.toPayload(args); 4185 4186 return payload.data; 4187 }; 4188 4189 /** 4190 * Should be used to get function display name 4191 * 4192 * @method displayName 4193 * @return {String} display name of the function 4194 */ 4195 SolidityFunction.prototype.displayName = function () { 4196 return utils.extractDisplayName(this._name); 4197 }; 4198 4199 /** 4200 * Should be used to get function type name 4201 * 4202 * @method typeName 4203 * @return {String} type name of the function 4204 */ 4205 SolidityFunction.prototype.typeName = function () { 4206 return utils.extractTypeName(this._name); 4207 }; 4208 4209 /** 4210 * Should be called to get rpc requests from solidity function 4211 * 4212 * @method request 4213 * @returns {Object} 4214 */ 4215 SolidityFunction.prototype.request = function () { 4216 var args = Array.prototype.slice.call(arguments); 4217 var callback = this.extractCallback(args); 4218 var payload = this.toPayload(args); 4219 var format = this.unpackOutput.bind(this); 4220 4221 return { 4222 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4223 callback: callback, 4224 params: [payload], 4225 format: format 4226 }; 4227 }; 4228 4229 /** 4230 * Should be called to execute function 4231 * 4232 * @method execute 4233 */ 4234 SolidityFunction.prototype.execute = function () { 4235 var transaction = !this._constant; 4236 4237 // send transaction 4238 if (transaction) { 4239 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4240 } 4241 4242 // call 4243 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4244 }; 4245 4246 /** 4247 * Should be called to attach function to contract 4248 * 4249 * @method attachToContract 4250 * @param {Contract} 4251 */ 4252 SolidityFunction.prototype.attachToContract = function (contract) { 4253 var execute = this.execute.bind(this); 4254 execute.request = this.request.bind(this); 4255 execute.call = this.call.bind(this); 4256 execute.sendTransaction = this.sendTransaction.bind(this); 4257 execute.estimateGas = this.estimateGas.bind(this); 4258 execute.getData = this.getData.bind(this); 4259 var displayName = this.displayName(); 4260 if (!contract[displayName]) { 4261 contract[displayName] = execute; 4262 } 4263 contract[displayName][this.typeName()] = execute; // circular!!!! 4264 }; 4265 4266 module.exports = SolidityFunction; 4267 4268 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4269 /* 4270 This file is part of web3.js. 4271 4272 web3.js is free software: you can redistribute it and/or modify 4273 it under the terms of the GNU Lesser General Public License as published by 4274 the Free Software Foundation, either version 3 of the License, or 4275 (at your option) any later version. 4276 4277 web3.js is distributed in the hope that it will be useful, 4278 but WITHOUT ANY WARRANTY; without even the implied warranty of 4279 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4280 GNU Lesser General Public License for more details. 4281 4282 You should have received a copy of the GNU Lesser General Public License 4283 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4284 */ 4285 /** @file httpprovider.js 4286 * @authors: 4287 * Marek Kotewicz <marek@ethdev.com> 4288 * Marian Oancea <marian@ethdev.com> 4289 * Fabian Vogelsteller <fabian@ethdev.com> 4290 * @date 2015 4291 */ 4292 4293 var errors = require('./errors'); 4294 4295 // workaround to use httpprovider in different envs 4296 4297 // browser 4298 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4299 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4300 // node 4301 } else { 4302 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4303 } 4304 4305 var XHR2 = require('xhr2'); // jshint ignore: line 4306 4307 /** 4308 * HttpProvider should be used to send rpc calls over http 4309 */ 4310 var HttpProvider = function (host, timeout, user, password) { 4311 this.host = host || 'http://localhost:8545'; 4312 this.timeout = timeout || 0; 4313 this.user = user; 4314 this.password = password; 4315 }; 4316 4317 /** 4318 * Should be called to prepare new XMLHttpRequest 4319 * 4320 * @method prepareRequest 4321 * @param {Boolean} true if request should be async 4322 * @return {XMLHttpRequest} object 4323 */ 4324 HttpProvider.prototype.prepareRequest = function (async) { 4325 var request; 4326 4327 if (async) { 4328 request = new XHR2(); 4329 request.timeout = this.timeout; 4330 } else { 4331 request = new XMLHttpRequest(); 4332 } 4333 4334 request.open('POST', this.host, async); 4335 if (this.user && this.password) { 4336 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4337 request.setRequestHeader('Authorization', auth); 4338 } request.setRequestHeader('Content-Type', 'application/json'); 4339 return request; 4340 }; 4341 4342 /** 4343 * Should be called to make sync request 4344 * 4345 * @method send 4346 * @param {Object} payload 4347 * @return {Object} result 4348 */ 4349 HttpProvider.prototype.send = function (payload) { 4350 var request = this.prepareRequest(false); 4351 4352 try { 4353 request.send(JSON.stringify(payload)); 4354 } catch (error) { 4355 throw errors.InvalidConnection(this.host); 4356 } 4357 4358 var result = request.responseText; 4359 4360 try { 4361 result = JSON.parse(result); 4362 } catch (e) { 4363 throw errors.InvalidResponse(request.responseText); 4364 } 4365 4366 return result; 4367 }; 4368 4369 /** 4370 * Should be used to make async request 4371 * 4372 * @method sendAsync 4373 * @param {Object} payload 4374 * @param {Function} callback triggered on end with (err, result) 4375 */ 4376 HttpProvider.prototype.sendAsync = function (payload, callback) { 4377 var request = this.prepareRequest(true); 4378 4379 request.onreadystatechange = function () { 4380 if (request.readyState === 4 && request.timeout !== 1) { 4381 var result = request.responseText; 4382 var error = null; 4383 4384 try { 4385 result = JSON.parse(result); 4386 } catch (e) { 4387 error = errors.InvalidResponse(request.responseText); 4388 } 4389 4390 callback(error, result); 4391 } 4392 }; 4393 4394 request.ontimeout = function () { 4395 callback(errors.ConnectionTimeout(this.timeout)); 4396 }; 4397 4398 try { 4399 request.send(JSON.stringify(payload)); 4400 } catch (error) { 4401 callback(errors.InvalidConnection(this.host)); 4402 } 4403 }; 4404 4405 /** 4406 * Synchronously tries to make Http request 4407 * 4408 * @method isConnected 4409 * @return {Boolean} returns true if request haven't failed. Otherwise false 4410 */ 4411 HttpProvider.prototype.isConnected = function () { 4412 try { 4413 this.send({ 4414 id: 9999999999, 4415 jsonrpc: '2.0', 4416 method: 'net_listening', 4417 params: [] 4418 }); 4419 return true; 4420 } catch (e) { 4421 return false; 4422 } 4423 }; 4424 4425 module.exports = HttpProvider; 4426 4427 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4428 /* 4429 This file is part of web3.js. 4430 4431 web3.js is free software: you can redistribute it and/or modify 4432 it under the terms of the GNU Lesser General Public License as published by 4433 the Free Software Foundation, either version 3 of the License, or 4434 (at your option) any later version. 4435 4436 web3.js is distributed in the hope that it will be useful, 4437 but WITHOUT ANY WARRANTY; without even the implied warranty of 4438 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4439 GNU Lesser General Public License for more details. 4440 4441 You should have received a copy of the GNU Lesser General Public License 4442 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4443 */ 4444 /** 4445 * @file iban.js 4446 * @author Marek Kotewicz <marek@ethdev.com> 4447 * @date 2015 4448 */ 4449 4450 var BigNumber = require('bignumber.js'); 4451 4452 var padLeft = function (string, bytes) { 4453 var result = string; 4454 while (result.length < bytes * 2) { 4455 result = '0' + result; 4456 } 4457 return result; 4458 }; 4459 4460 /** 4461 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4462 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4463 * 4464 * @method iso13616Prepare 4465 * @param {String} iban the IBAN 4466 * @returns {String} the prepared IBAN 4467 */ 4468 var iso13616Prepare = function (iban) { 4469 var A = 'A'.charCodeAt(0); 4470 var Z = 'Z'.charCodeAt(0); 4471 4472 iban = iban.toUpperCase(); 4473 iban = iban.substr(4) + iban.substr(0,4); 4474 4475 return iban.split('').map(function(n){ 4476 var code = n.charCodeAt(0); 4477 if (code >= A && code <= Z){ 4478 // A = 10, B = 11, ... Z = 35 4479 return code - A + 10; 4480 } else { 4481 return n; 4482 } 4483 }).join(''); 4484 }; 4485 4486 /** 4487 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4488 * 4489 * @method mod9710 4490 * @param {String} iban 4491 * @returns {Number} 4492 */ 4493 var mod9710 = function (iban) { 4494 var remainder = iban, 4495 block; 4496 4497 while (remainder.length > 2){ 4498 block = remainder.slice(0, 9); 4499 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4500 } 4501 4502 return parseInt(remainder, 10) % 97; 4503 }; 4504 4505 /** 4506 * This prototype should be used to create iban object from iban correct string 4507 * 4508 * @param {String} iban 4509 */ 4510 var Iban = function (iban) { 4511 this._iban = iban; 4512 }; 4513 4514 /** 4515 * This method should be used to create iban object from ethereum address 4516 * 4517 * @method fromAddress 4518 * @param {String} address 4519 * @return {Iban} the IBAN object 4520 */ 4521 Iban.fromAddress = function (address) { 4522 var asBn = new BigNumber(address, 16); 4523 var base36 = asBn.toString(36); 4524 var padded = padLeft(base36, 15); 4525 return Iban.fromBban(padded.toUpperCase()); 4526 }; 4527 4528 /** 4529 * Convert the passed BBAN to an IBAN for this country specification. 4530 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4531 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4532 * 4533 * @method fromBban 4534 * @param {String} bban the BBAN to convert to IBAN 4535 * @returns {Iban} the IBAN object 4536 */ 4537 Iban.fromBban = function (bban) { 4538 var countryCode = 'XE'; 4539 4540 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4541 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4542 4543 return new Iban(countryCode + checkDigit + bban); 4544 }; 4545 4546 /** 4547 * Should be used to create IBAN object for given institution and identifier 4548 * 4549 * @method createIndirect 4550 * @param {Object} options, required options are "institution" and "identifier" 4551 * @return {Iban} the IBAN object 4552 */ 4553 Iban.createIndirect = function (options) { 4554 return Iban.fromBban('ETH' + options.institution + options.identifier); 4555 }; 4556 4557 /** 4558 * Thos method should be used to check if given string is valid iban object 4559 * 4560 * @method isValid 4561 * @param {String} iban string 4562 * @return {Boolean} true if it is valid IBAN 4563 */ 4564 Iban.isValid = function (iban) { 4565 var i = new Iban(iban); 4566 return i.isValid(); 4567 }; 4568 4569 /** 4570 * Should be called to check if iban is correct 4571 * 4572 * @method isValid 4573 * @returns {Boolean} true if it is, otherwise false 4574 */ 4575 Iban.prototype.isValid = function () { 4576 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4577 mod9710(iso13616Prepare(this._iban)) === 1; 4578 }; 4579 4580 /** 4581 * Should be called to check if iban number is direct 4582 * 4583 * @method isDirect 4584 * @returns {Boolean} true if it is, otherwise false 4585 */ 4586 Iban.prototype.isDirect = function () { 4587 return this._iban.length === 34 || this._iban.length === 35; 4588 }; 4589 4590 /** 4591 * Should be called to check if iban number if indirect 4592 * 4593 * @method isIndirect 4594 * @returns {Boolean} true if it is, otherwise false 4595 */ 4596 Iban.prototype.isIndirect = function () { 4597 return this._iban.length === 20; 4598 }; 4599 4600 /** 4601 * Should be called to get iban checksum 4602 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4603 * 4604 * @method checksum 4605 * @returns {String} checksum 4606 */ 4607 Iban.prototype.checksum = function () { 4608 return this._iban.substr(2, 2); 4609 }; 4610 4611 /** 4612 * Should be called to get institution identifier 4613 * eg. XREG 4614 * 4615 * @method institution 4616 * @returns {String} institution identifier 4617 */ 4618 Iban.prototype.institution = function () { 4619 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4620 }; 4621 4622 /** 4623 * Should be called to get client identifier within institution 4624 * eg. GAVOFYORK 4625 * 4626 * @method client 4627 * @returns {String} client identifier 4628 */ 4629 Iban.prototype.client = function () { 4630 return this.isIndirect() ? this._iban.substr(11) : ''; 4631 }; 4632 4633 /** 4634 * Should be called to get client direct address 4635 * 4636 * @method address 4637 * @returns {String} client direct address 4638 */ 4639 Iban.prototype.address = function () { 4640 if (this.isDirect()) { 4641 var base36 = this._iban.substr(4); 4642 var asBn = new BigNumber(base36, 36); 4643 return padLeft(asBn.toString(16), 20); 4644 } 4645 4646 return ''; 4647 }; 4648 4649 Iban.prototype.toString = function () { 4650 return this._iban; 4651 }; 4652 4653 module.exports = Iban; 4654 4655 4656 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4657 /* 4658 This file is part of web3.js. 4659 4660 web3.js is free software: you can redistribute it and/or modify 4661 it under the terms of the GNU Lesser General Public License as published by 4662 the Free Software Foundation, either version 3 of the License, or 4663 (at your option) any later version. 4664 4665 web3.js is distributed in the hope that it will be useful, 4666 but WITHOUT ANY WARRANTY; without even the implied warranty of 4667 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4668 GNU Lesser General Public License for more details. 4669 4670 You should have received a copy of the GNU Lesser General Public License 4671 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4672 */ 4673 /** @file ipcprovider.js 4674 * @authors: 4675 * Fabian Vogelsteller <fabian@ethdev.com> 4676 * @date 2015 4677 */ 4678 4679 "use strict"; 4680 4681 var utils = require('../utils/utils'); 4682 var errors = require('./errors'); 4683 4684 4685 var IpcProvider = function (path, net) { 4686 var _this = this; 4687 this.responseCallbacks = {}; 4688 this.path = path; 4689 4690 this.connection = net.connect({path: this.path}); 4691 4692 this.connection.on('error', function(e){ 4693 console.error('IPC Connection Error', e); 4694 _this._timeout(); 4695 }); 4696 4697 this.connection.on('end', function(){ 4698 _this._timeout(); 4699 }); 4700 4701 4702 // LISTEN FOR CONNECTION RESPONSES 4703 this.connection.on('data', function(data) { 4704 /*jshint maxcomplexity: 6 */ 4705 4706 _this._parseResponse(data.toString()).forEach(function(result){ 4707 4708 var id = null; 4709 4710 // get the id which matches the returned id 4711 if(utils.isArray(result)) { 4712 result.forEach(function(load){ 4713 if(_this.responseCallbacks[load.id]) 4714 id = load.id; 4715 }); 4716 } else { 4717 id = result.id; 4718 } 4719 4720 // fire the callback 4721 if(_this.responseCallbacks[id]) { 4722 _this.responseCallbacks[id](null, result); 4723 delete _this.responseCallbacks[id]; 4724 } 4725 }); 4726 }); 4727 }; 4728 4729 /** 4730 Will parse the response and make an array out of it. 4731 4732 @method _parseResponse 4733 @param {String} data 4734 */ 4735 IpcProvider.prototype._parseResponse = function(data) { 4736 var _this = this, 4737 returnValues = []; 4738 4739 // DE-CHUNKER 4740 var dechunkedData = data 4741 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4742 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4743 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4744 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4745 .split('|--|'); 4746 4747 dechunkedData.forEach(function(data){ 4748 4749 // prepend the last chunk 4750 if(_this.lastChunk) 4751 data = _this.lastChunk + data; 4752 4753 var result = null; 4754 4755 try { 4756 result = JSON.parse(data); 4757 4758 } catch(e) { 4759 4760 _this.lastChunk = data; 4761 4762 // start timeout to cancel all requests 4763 clearTimeout(_this.lastChunkTimeout); 4764 _this.lastChunkTimeout = setTimeout(function(){ 4765 _this._timeout(); 4766 throw errors.InvalidResponse(data); 4767 }, 1000 * 15); 4768 4769 return; 4770 } 4771 4772 // cancel timeout and set chunk to null 4773 clearTimeout(_this.lastChunkTimeout); 4774 _this.lastChunk = null; 4775 4776 if(result) 4777 returnValues.push(result); 4778 }); 4779 4780 return returnValues; 4781 }; 4782 4783 4784 /** 4785 Get the adds a callback to the responseCallbacks object, 4786 which will be called if a response matching the response Id will arrive. 4787 4788 @method _addResponseCallback 4789 */ 4790 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4791 var id = payload.id || payload[0].id; 4792 var method = payload.method || payload[0].method; 4793 4794 this.responseCallbacks[id] = callback; 4795 this.responseCallbacks[id].method = method; 4796 }; 4797 4798 /** 4799 Timeout all requests when the end/error event is fired 4800 4801 @method _timeout 4802 */ 4803 IpcProvider.prototype._timeout = function() { 4804 for(var key in this.responseCallbacks) { 4805 if(this.responseCallbacks.hasOwnProperty(key)){ 4806 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4807 delete this.responseCallbacks[key]; 4808 } 4809 } 4810 }; 4811 4812 4813 /** 4814 Check if the current connection is still valid. 4815 4816 @method isConnected 4817 */ 4818 IpcProvider.prototype.isConnected = function() { 4819 var _this = this; 4820 4821 // try reconnect, when connection is gone 4822 if(!_this.connection.writable) 4823 _this.connection.connect({path: _this.path}); 4824 4825 return !!this.connection.writable; 4826 }; 4827 4828 IpcProvider.prototype.send = function (payload) { 4829 4830 if(this.connection.writeSync) { 4831 var result; 4832 4833 // try reconnect, when connection is gone 4834 if(!this.connection.writable) 4835 this.connection.connect({path: this.path}); 4836 4837 var data = this.connection.writeSync(JSON.stringify(payload)); 4838 4839 try { 4840 result = JSON.parse(data); 4841 } catch(e) { 4842 throw errors.InvalidResponse(data); 4843 } 4844 4845 return result; 4846 4847 } else { 4848 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4849 } 4850 }; 4851 4852 IpcProvider.prototype.sendAsync = function (payload, callback) { 4853 // try reconnect, when connection is gone 4854 if(!this.connection.writable) 4855 this.connection.connect({path: this.path}); 4856 4857 4858 this.connection.write(JSON.stringify(payload)); 4859 this._addResponseCallback(payload, callback); 4860 }; 4861 4862 module.exports = IpcProvider; 4863 4864 4865 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 4866 /* 4867 This file is part of web3.js. 4868 4869 web3.js is free software: you can redistribute it and/or modify 4870 it under the terms of the GNU Lesser General Public License as published by 4871 the Free Software Foundation, either version 3 of the License, or 4872 (at your option) any later version. 4873 4874 web3.js is distributed in the hope that it will be useful, 4875 but WITHOUT ANY WARRANTY; without even the implied warranty of 4876 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4877 GNU Lesser General Public License for more details. 4878 4879 You should have received a copy of the GNU Lesser General Public License 4880 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4881 */ 4882 /** @file jsonrpc.js 4883 * @authors: 4884 * Marek Kotewicz <marek@ethdev.com> 4885 * Aaron Kumavis <aaron@kumavis.me> 4886 * @date 2015 4887 */ 4888 4889 // Initialize Jsonrpc as a simple object with utility functions. 4890 var Jsonrpc = { 4891 messageId: 0 4892 }; 4893 4894 /** 4895 * Should be called to valid json create payload object 4896 * 4897 * @method toPayload 4898 * @param {Function} method of jsonrpc call, required 4899 * @param {Array} params, an array of method params, optional 4900 * @returns {Object} valid jsonrpc payload object 4901 */ 4902 Jsonrpc.toPayload = function (method, params) { 4903 if (!method) 4904 console.error('jsonrpc method should be specified!'); 4905 4906 // advance message ID 4907 Jsonrpc.messageId++; 4908 4909 return { 4910 jsonrpc: '2.0', 4911 id: Jsonrpc.messageId, 4912 method: method, 4913 params: params || [] 4914 }; 4915 }; 4916 4917 /** 4918 * Should be called to check if jsonrpc response is valid 4919 * 4920 * @method isValidResponse 4921 * @param {Object} 4922 * @returns {Boolean} true if response is valid, otherwise false 4923 */ 4924 Jsonrpc.isValidResponse = function (response) { 4925 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4926 4927 function validateSingleMessage(message){ 4928 return !!message && 4929 !message.error && 4930 message.jsonrpc === '2.0' && 4931 typeof message.id === 'number' && 4932 message.result !== undefined; // only undefined is not valid json object 4933 } 4934 }; 4935 4936 /** 4937 * Should be called to create batch payload object 4938 * 4939 * @method toBatchPayload 4940 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4941 * @returns {Array} batch payload 4942 */ 4943 Jsonrpc.toBatchPayload = function (messages) { 4944 return messages.map(function (message) { 4945 return Jsonrpc.toPayload(message.method, message.params); 4946 }); 4947 }; 4948 4949 module.exports = Jsonrpc; 4950 4951 4952 },{}],36:[function(require,module,exports){ 4953 /* 4954 This file is part of web3.js. 4955 4956 web3.js is free software: you can redistribute it and/or modify 4957 it under the terms of the GNU Lesser General Public License as published by 4958 the Free Software Foundation, either version 3 of the License, or 4959 (at your option) any later version. 4960 4961 web3.js is distributed in the hope that it will be useful, 4962 but WITHOUT ANY WARRANTY; without even the implied warranty of 4963 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4964 GNU Lesser General Public License for more details. 4965 4966 You should have received a copy of the GNU Lesser General Public License 4967 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4968 */ 4969 /** 4970 * @file method.js 4971 * @author Marek Kotewicz <marek@ethdev.com> 4972 * @date 2015 4973 */ 4974 4975 var utils = require('../utils/utils'); 4976 var errors = require('./errors'); 4977 4978 var Method = function (options) { 4979 this.name = options.name; 4980 this.call = options.call; 4981 this.params = options.params || 0; 4982 this.inputFormatter = options.inputFormatter; 4983 this.outputFormatter = options.outputFormatter; 4984 this.requestManager = null; 4985 }; 4986 4987 Method.prototype.setRequestManager = function (rm) { 4988 this.requestManager = rm; 4989 }; 4990 4991 /** 4992 * Should be used to determine name of the jsonrpc method based on arguments 4993 * 4994 * @method getCall 4995 * @param {Array} arguments 4996 * @return {String} name of jsonrpc method 4997 */ 4998 Method.prototype.getCall = function (args) { 4999 return utils.isFunction(this.call) ? this.call(args) : this.call; 5000 }; 5001 5002 /** 5003 * Should be used to extract callback from array of arguments. Modifies input param 5004 * 5005 * @method extractCallback 5006 * @param {Array} arguments 5007 * @return {Function|Null} callback, if exists 5008 */ 5009 Method.prototype.extractCallback = function (args) { 5010 if (utils.isFunction(args[args.length - 1])) { 5011 return args.pop(); // modify the args array! 5012 } 5013 }; 5014 5015 /** 5016 * Should be called to check if the number of arguments is correct 5017 * 5018 * @method validateArgs 5019 * @param {Array} arguments 5020 * @throws {Error} if it is not 5021 */ 5022 Method.prototype.validateArgs = function (args) { 5023 if (args.length !== this.params) { 5024 throw errors.InvalidNumberOfRPCParams(); 5025 } 5026 }; 5027 5028 /** 5029 * Should be called to format input args of method 5030 * 5031 * @method formatInput 5032 * @param {Array} 5033 * @return {Array} 5034 */ 5035 Method.prototype.formatInput = function (args) { 5036 if (!this.inputFormatter) { 5037 return args; 5038 } 5039 5040 return this.inputFormatter.map(function (formatter, index) { 5041 return formatter ? formatter(args[index]) : args[index]; 5042 }); 5043 }; 5044 5045 /** 5046 * Should be called to format output(result) of method 5047 * 5048 * @method formatOutput 5049 * @param {Object} 5050 * @return {Object} 5051 */ 5052 Method.prototype.formatOutput = function (result) { 5053 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5054 }; 5055 5056 /** 5057 * Should create payload from given input args 5058 * 5059 * @method toPayload 5060 * @param {Array} args 5061 * @return {Object} 5062 */ 5063 Method.prototype.toPayload = function (args) { 5064 var call = this.getCall(args); 5065 var callback = this.extractCallback(args); 5066 var params = this.formatInput(args); 5067 this.validateArgs(params); 5068 5069 return { 5070 method: call, 5071 params: params, 5072 callback: callback 5073 }; 5074 }; 5075 5076 Method.prototype.attachToObject = function (obj) { 5077 var func = this.buildCall(); 5078 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5079 var name = this.name.split('.'); 5080 if (name.length > 1) { 5081 obj[name[0]] = obj[name[0]] || {}; 5082 obj[name[0]][name[1]] = func; 5083 } else { 5084 obj[name[0]] = func; 5085 } 5086 }; 5087 5088 Method.prototype.buildCall = function() { 5089 var method = this; 5090 var send = function () { 5091 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5092 if (payload.callback) { 5093 return method.requestManager.sendAsync(payload, function (err, result) { 5094 payload.callback(err, method.formatOutput(result)); 5095 }); 5096 } 5097 return method.formatOutput(method.requestManager.send(payload)); 5098 }; 5099 send.request = this.request.bind(this); 5100 return send; 5101 }; 5102 5103 /** 5104 * Should be called to create pure JSONRPC request which can be used in batch request 5105 * 5106 * @method request 5107 * @param {...} params 5108 * @return {Object} jsonrpc request 5109 */ 5110 Method.prototype.request = function () { 5111 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5112 payload.format = this.formatOutput.bind(this); 5113 return payload; 5114 }; 5115 5116 module.exports = Method; 5117 5118 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5119 /* 5120 This file is part of web3.js. 5121 5122 web3.js is free software: you can redistribute it and/or modify 5123 it under the terms of the GNU Lesser General Public License as published by 5124 the Free Software Foundation, either version 3 of the License, or 5125 (at your option) any later version. 5126 5127 web3.js is distributed in the hope that it will be useful, 5128 but WITHOUT ANY WARRANTY; without even the implied warranty of 5129 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5130 GNU Lesser General Public License for more details. 5131 5132 You should have received a copy of the GNU Lesser General Public License 5133 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5134 */ 5135 /** @file db.js 5136 * @authors: 5137 * Marek Kotewicz <marek@ethdev.com> 5138 * @date 2015 5139 */ 5140 5141 var Method = require('../method'); 5142 5143 var DB = function (web3) { 5144 this._requestManager = web3._requestManager; 5145 5146 var self = this; 5147 5148 methods().forEach(function(method) { 5149 method.attachToObject(self); 5150 method.setRequestManager(web3._requestManager); 5151 }); 5152 }; 5153 5154 var methods = function () { 5155 var putString = new Method({ 5156 name: 'putString', 5157 call: 'db_putString', 5158 params: 3 5159 }); 5160 5161 var getString = new Method({ 5162 name: 'getString', 5163 call: 'db_getString', 5164 params: 2 5165 }); 5166 5167 var putHex = new Method({ 5168 name: 'putHex', 5169 call: 'db_putHex', 5170 params: 3 5171 }); 5172 5173 var getHex = new Method({ 5174 name: 'getHex', 5175 call: 'db_getHex', 5176 params: 2 5177 }); 5178 5179 return [ 5180 putString, getString, putHex, getHex 5181 ]; 5182 }; 5183 5184 module.exports = DB; 5185 5186 },{"../method":36}],38:[function(require,module,exports){ 5187 /* 5188 This file is part of web3.js. 5189 5190 web3.js is free software: you can redistribute it and/or modify 5191 it under the terms of the GNU Lesser General Public License as published by 5192 the Free Software Foundation, either version 3 of the License, or 5193 (at your option) any later version. 5194 5195 web3.js is distributed in the hope that it will be useful, 5196 but WITHOUT ANY WARRANTY; without even the implied warranty of 5197 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5198 GNU Lesser General Public License for more details. 5199 5200 You should have received a copy of the GNU Lesser General Public License 5201 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5202 */ 5203 /** 5204 * @file eth.js 5205 * @author Marek Kotewicz <marek@ethdev.com> 5206 * @author Fabian Vogelsteller <fabian@ethdev.com> 5207 * @date 2015 5208 */ 5209 5210 "use strict"; 5211 5212 var formatters = require('../formatters'); 5213 var utils = require('../../utils/utils'); 5214 var Method = require('../method'); 5215 var Property = require('../property'); 5216 var c = require('../../utils/config'); 5217 var Contract = require('../contract'); 5218 var watches = require('./watches'); 5219 var Filter = require('../filter'); 5220 var IsSyncing = require('../syncing'); 5221 var namereg = require('../namereg'); 5222 var Iban = require('../iban'); 5223 var transfer = require('../transfer'); 5224 5225 var blockCall = function (args) { 5226 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; 5227 }; 5228 5229 var transactionFromBlockCall = function (args) { 5230 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5231 }; 5232 5233 var uncleCall = function (args) { 5234 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5235 }; 5236 5237 var getBlockTransactionCountCall = function (args) { 5238 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5239 }; 5240 5241 var uncleCountCall = function (args) { 5242 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5243 }; 5244 5245 function Eth(web3) { 5246 this._requestManager = web3._requestManager; 5247 5248 var self = this; 5249 5250 methods().forEach(function(method) { 5251 method.attachToObject(self); 5252 method.setRequestManager(self._requestManager); 5253 }); 5254 5255 properties().forEach(function(p) { 5256 p.attachToObject(self); 5257 p.setRequestManager(self._requestManager); 5258 }); 5259 5260 5261 this.iban = Iban; 5262 this.sendIBANTransaction = transfer.bind(null, this); 5263 } 5264 5265 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5266 get: function () { 5267 return c.defaultBlock; 5268 }, 5269 set: function (val) { 5270 c.defaultBlock = val; 5271 return val; 5272 } 5273 }); 5274 5275 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5276 get: function () { 5277 return c.defaultAccount; 5278 }, 5279 set: function (val) { 5280 c.defaultAccount = val; 5281 return val; 5282 } 5283 }); 5284 5285 var methods = function () { 5286 var getBalance = new Method({ 5287 name: 'getBalance', 5288 call: 'eth_getBalance', 5289 params: 2, 5290 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5291 outputFormatter: formatters.outputBigNumberFormatter 5292 }); 5293 5294 var totalSupply = new Method({ 5295 name: 'totalSupply', 5296 call: 'eth_totalSupply', 5297 params: 1, 5298 inputFormatter: [formatters.inputDefaultBlockNumberFormatter], 5299 outputFormatter: formatters.outputBigNumberFormatter 5300 }); 5301 5302 var genesisAlloc = new Method({ 5303 name: 'genesisAlloc', 5304 call: 'eth_genesisAlloc', 5305 params: 0, 5306 outputFormatter: formatters.genesisAllocFormatter 5307 }); 5308 5309 var getStorageAt = new Method({ 5310 name: 'getStorageAt', 5311 call: 'eth_getStorageAt', 5312 params: 3, 5313 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5314 }); 5315 5316 var getCode = new Method({ 5317 name: 'getCode', 5318 call: 'eth_getCode', 5319 params: 2, 5320 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5321 }); 5322 5323 var getBlock = new Method({ 5324 name: 'getBlock', 5325 call: blockCall, 5326 params: 2, 5327 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5328 outputFormatter: formatters.outputBlockFormatter 5329 }); 5330 5331 var getUncle = new Method({ 5332 name: 'getUncle', 5333 call: uncleCall, 5334 params: 2, 5335 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5336 outputFormatter: formatters.outputBlockFormatter, 5337 5338 }); 5339 5340 var getCompilers = new Method({ 5341 name: 'getCompilers', 5342 call: 'eth_getCompilers', 5343 params: 0 5344 }); 5345 5346 var getBlockTransactionCount = new Method({ 5347 name: 'getBlockTransactionCount', 5348 call: getBlockTransactionCountCall, 5349 params: 1, 5350 inputFormatter: [formatters.inputBlockNumberFormatter], 5351 outputFormatter: utils.toDecimal 5352 }); 5353 5354 var getBlockUncleCount = new Method({ 5355 name: 'getBlockUncleCount', 5356 call: uncleCountCall, 5357 params: 1, 5358 inputFormatter: [formatters.inputBlockNumberFormatter], 5359 outputFormatter: utils.toDecimal 5360 }); 5361 5362 var getTransaction = new Method({ 5363 name: 'getTransaction', 5364 call: 'eth_getTransactionByHash', 5365 params: 1, 5366 outputFormatter: formatters.outputTransactionFormatter 5367 }); 5368 5369 var getTransactionFromBlock = new Method({ 5370 name: 'getTransactionFromBlock', 5371 call: transactionFromBlockCall, 5372 params: 2, 5373 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5374 outputFormatter: formatters.outputTransactionFormatter 5375 }); 5376 5377 var getTransactionReceipt = new Method({ 5378 name: 'getTransactionReceipt', 5379 call: 'eth_getTransactionReceipt', 5380 params: 1, 5381 outputFormatter: formatters.outputTransactionReceiptFormatter 5382 }); 5383 5384 var getTransactionCount = new Method({ 5385 name: 'getTransactionCount', 5386 call: 'eth_getTransactionCount', 5387 params: 2, 5388 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5389 outputFormatter: utils.toDecimal 5390 }); 5391 5392 var sendRawTransaction = new Method({ 5393 name: 'sendRawTransaction', 5394 call: 'eth_sendRawTransaction', 5395 params: 1, 5396 inputFormatter: [null] 5397 }); 5398 5399 var sendTransaction = new Method({ 5400 name: 'sendTransaction', 5401 call: 'eth_sendTransaction', 5402 params: 1, 5403 inputFormatter: [formatters.inputTransactionFormatter] 5404 }); 5405 5406 var signTransaction = new Method({ 5407 name: 'signTransaction', 5408 call: 'eth_signTransaction', 5409 params: 1, 5410 inputFormatter: [formatters.inputTransactionFormatter] 5411 }); 5412 5413 var sign = new Method({ 5414 name: 'sign', 5415 call: 'eth_sign', 5416 params: 2, 5417 inputFormatter: [formatters.inputAddressFormatter, null] 5418 }); 5419 5420 var call = new Method({ 5421 name: 'call', 5422 call: 'eth_call', 5423 params: 2, 5424 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5425 }); 5426 5427 var estimateGas = new Method({ 5428 name: 'estimateGas', 5429 call: 'eth_estimateGas', 5430 params: 1, 5431 inputFormatter: [formatters.inputCallFormatter], 5432 outputFormatter: utils.toDecimal 5433 }); 5434 5435 var compileSolidity = new Method({ 5436 name: 'compile.solidity', 5437 call: 'eth_compileSolidity', 5438 params: 1 5439 }); 5440 5441 var compileLLL = new Method({ 5442 name: 'compile.lll', 5443 call: 'eth_compileLLL', 5444 params: 1 5445 }); 5446 5447 var compileSerpent = new Method({ 5448 name: 'compile.serpent', 5449 call: 'eth_compileSerpent', 5450 params: 1 5451 }); 5452 5453 var submitWork = new Method({ 5454 name: 'submitWork', 5455 call: 'eth_submitWork', 5456 params: 3 5457 }); 5458 5459 var getWork = new Method({ 5460 name: 'getWork', 5461 call: 'eth_getWork', 5462 params: 0 5463 }); 5464 5465 return [ 5466 getBalance, 5467 totalSupply, 5468 genesisAlloc, 5469 getStorageAt, 5470 getCode, 5471 getBlock, 5472 getUncle, 5473 getCompilers, 5474 getBlockTransactionCount, 5475 getBlockUncleCount, 5476 getTransaction, 5477 getTransactionFromBlock, 5478 getTransactionReceipt, 5479 getTransactionCount, 5480 call, 5481 estimateGas, 5482 sendRawTransaction, 5483 signTransaction, 5484 sendTransaction, 5485 sign, 5486 compileSolidity, 5487 compileLLL, 5488 compileSerpent, 5489 submitWork, 5490 getWork 5491 ]; 5492 }; 5493 5494 5495 var properties = function () { 5496 return [ 5497 new Property({ 5498 name: 'coinbase', 5499 getter: 'eth_coinbase' 5500 }), 5501 new Property({ 5502 name: 'mining', 5503 getter: 'eth_mining' 5504 }), 5505 new Property({ 5506 name: 'hashrate', 5507 getter: 'eth_hashrate', 5508 outputFormatter: utils.toDecimal 5509 }), 5510 new Property({ 5511 name: 'syncing', 5512 getter: 'eth_syncing', 5513 outputFormatter: formatters.outputSyncingFormatter 5514 }), 5515 new Property({ 5516 name: 'gasPrice', 5517 getter: 'eth_gasPrice', 5518 outputFormatter: formatters.outputBigNumberFormatter 5519 }), 5520 new Property({ 5521 name: 'accounts', 5522 getter: 'eth_accounts' 5523 }), 5524 new Property({ 5525 name: 'blockNumber', 5526 getter: 'eth_blockNumber', 5527 outputFormatter: utils.toDecimal 5528 }), 5529 new Property({ 5530 name: 'protocolVersion', 5531 getter: 'eth_protocolVersion' 5532 }) 5533 ]; 5534 }; 5535 5536 Eth.prototype.contract = function (abi) { 5537 var factory = new Contract(this, abi); 5538 return factory; 5539 }; 5540 5541 Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5542 return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5543 }; 5544 5545 Eth.prototype.namereg = function () { 5546 return this.contract(namereg.global.abi).at(namereg.global.address); 5547 }; 5548 5549 Eth.prototype.icapNamereg = function () { 5550 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5551 }; 5552 5553 Eth.prototype.isSyncing = function (callback) { 5554 return new IsSyncing(this._requestManager, callback); 5555 }; 5556 5557 module.exports = Eth; 5558 5559 },{"../../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){ 5560 /* 5561 This file is part of web3.js. 5562 5563 web3.js is free software: you can redistribute it and/or modify 5564 it under the terms of the GNU Lesser General Public License as published by 5565 the Free Software Foundation, either version 3 of the License, or 5566 (at your option) any later version. 5567 5568 web3.js is distributed in the hope that it will be useful, 5569 but WITHOUT ANY WARRANTY; without even the implied warranty of 5570 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5571 GNU Lesser General Public License for more details. 5572 5573 You should have received a copy of the GNU Lesser General Public License 5574 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5575 */ 5576 /** @file eth.js 5577 * @authors: 5578 * Marek Kotewicz <marek@ethdev.com> 5579 * @date 2015 5580 */ 5581 5582 var utils = require('../../utils/utils'); 5583 var Property = require('../property'); 5584 5585 var Net = function (web3) { 5586 this._requestManager = web3._requestManager; 5587 5588 var self = this; 5589 5590 properties().forEach(function(p) { 5591 p.attachToObject(self); 5592 p.setRequestManager(web3._requestManager); 5593 }); 5594 }; 5595 5596 /// @returns an array of objects describing web3.eth api properties 5597 var properties = function () { 5598 return [ 5599 new Property({ 5600 name: 'listening', 5601 getter: 'net_listening' 5602 }), 5603 new Property({ 5604 name: 'peerCount', 5605 getter: 'net_peerCount', 5606 outputFormatter: utils.toDecimal 5607 }) 5608 ]; 5609 }; 5610 5611 module.exports = Net; 5612 5613 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 5614 /* 5615 This file is part of web3.js. 5616 5617 web3.js is free software: you can redistribute it and/or modify 5618 it under the terms of the GNU Lesser General Public License as published by 5619 the Free Software Foundation, either version 3 of the License, or 5620 (at your option) any later version. 5621 5622 web3.js is distributed in the hope that it will be useful, 5623 but WITHOUT ANY WARRANTY; without even the implied warranty of 5624 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5625 GNU Lesser General Public License for more details. 5626 5627 You should have received a copy of the GNU Lesser General Public License 5628 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5629 */ 5630 /** 5631 * @file eth.js 5632 * @author Marek Kotewicz <marek@ethdev.com> 5633 * @author Fabian Vogelsteller <fabian@ethdev.com> 5634 * @date 2015 5635 */ 5636 5637 "use strict"; 5638 5639 var Method = require('../method'); 5640 var Property = require('../property'); 5641 var formatters = require('../formatters'); 5642 5643 function Personal(web3) { 5644 this._requestManager = web3._requestManager; 5645 5646 var self = this; 5647 5648 methods().forEach(function(method) { 5649 method.attachToObject(self); 5650 method.setRequestManager(self._requestManager); 5651 }); 5652 5653 properties().forEach(function(p) { 5654 p.attachToObject(self); 5655 p.setRequestManager(self._requestManager); 5656 }); 5657 } 5658 5659 var methods = function () { 5660 var newAccount = new Method({ 5661 name: 'newAccount', 5662 call: 'personal_newAccount', 5663 params: 1, 5664 inputFormatter: [null] 5665 }); 5666 5667 var importRawKey = new Method({ 5668 name: 'importRawKey', 5669 call: 'personal_importRawKey', 5670 params: 2 5671 }); 5672 5673 var sign = new Method({ 5674 name: 'sign', 5675 call: 'personal_sign', 5676 params: 3, 5677 inputFormatter: [null, formatters.inputAddressFormatter, null] 5678 }); 5679 5680 var ecRecover = new Method({ 5681 name: 'ecRecover', 5682 call: 'personal_ecRecover', 5683 params: 2 5684 }); 5685 5686 var unlockAccount = new Method({ 5687 name: 'unlockAccount', 5688 call: 'personal_unlockAccount', 5689 params: 3, 5690 inputFormatter: [formatters.inputAddressFormatter, null, null] 5691 }); 5692 5693 var sendTransaction = new Method({ 5694 name: 'sendTransaction', 5695 call: 'personal_sendTransaction', 5696 params: 2, 5697 inputFormatter: [formatters.inputTransactionFormatter, null] 5698 }); 5699 5700 var lockAccount = new Method({ 5701 name: 'lockAccount', 5702 call: 'personal_lockAccount', 5703 params: 1, 5704 inputFormatter: [formatters.inputAddressFormatter] 5705 }); 5706 5707 return [ 5708 newAccount, 5709 importRawKey, 5710 unlockAccount, 5711 ecRecover, 5712 sign, 5713 sendTransaction, 5714 lockAccount 5715 ]; 5716 }; 5717 5718 var properties = function () { 5719 return [ 5720 new Property({ 5721 name: 'listAccounts', 5722 getter: 'personal_listAccounts' 5723 }) 5724 ]; 5725 }; 5726 5727 5728 module.exports = Personal; 5729 5730 },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){ 5731 /* 5732 This file is part of web3.js. 5733 5734 web3.js is free software: you can redistribute it and/or modify 5735 it under the terms of the GNU Lesser General Public License as published by 5736 the Free Software Foundation, either version 3 of the License, or 5737 (at your option) any later version. 5738 5739 web3.js is distributed in the hope that it will be useful, 5740 but WITHOUT ANY WARRANTY; without even the implied warranty of 5741 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5742 GNU Lesser General Public License for more details. 5743 5744 You should have received a copy of the GNU Lesser General Public License 5745 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5746 */ 5747 /** @file shh.js 5748 * @authors: 5749 * Fabian Vogelsteller <fabian@ethereum.org> 5750 * Marek Kotewicz <marek@ethcore.io> 5751 * @date 2017 5752 */ 5753 5754 var Method = require('../method'); 5755 var Filter = require('../filter'); 5756 var watches = require('./watches'); 5757 5758 var Shh = function (web3) { 5759 this._requestManager = web3._requestManager; 5760 5761 var self = this; 5762 5763 methods().forEach(function(method) { 5764 method.attachToObject(self); 5765 method.setRequestManager(self._requestManager); 5766 }); 5767 }; 5768 5769 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 5770 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 5771 }; 5772 5773 var methods = function () { 5774 5775 return [ 5776 new Method({ 5777 name: 'version', 5778 call: 'shh_version', 5779 params: 0 5780 }), 5781 new Method({ 5782 name: 'info', 5783 call: 'shh_info', 5784 params: 0 5785 }), 5786 new Method({ 5787 name: 'setMaxMessageSize', 5788 call: 'shh_setMaxMessageSize', 5789 params: 1 5790 }), 5791 new Method({ 5792 name: 'setMinPoW', 5793 call: 'shh_setMinPoW', 5794 params: 1 5795 }), 5796 new Method({ 5797 name: 'markTrustedPeer', 5798 call: 'shh_markTrustedPeer', 5799 params: 1 5800 }), 5801 new Method({ 5802 name: 'newKeyPair', 5803 call: 'shh_newKeyPair', 5804 params: 0 5805 }), 5806 new Method({ 5807 name: 'addPrivateKey', 5808 call: 'shh_addPrivateKey', 5809 params: 1 5810 }), 5811 new Method({ 5812 name: 'deleteKeyPair', 5813 call: 'shh_deleteKeyPair', 5814 params: 1 5815 }), 5816 new Method({ 5817 name: 'hasKeyPair', 5818 call: 'shh_hasKeyPair', 5819 params: 1 5820 }), 5821 new Method({ 5822 name: 'getPublicKey', 5823 call: 'shh_getPublicKey', 5824 params: 1 5825 }), 5826 new Method({ 5827 name: 'getPrivateKey', 5828 call: 'shh_getPrivateKey', 5829 params: 1 5830 }), 5831 new Method({ 5832 name: 'newSymKey', 5833 call: 'shh_newSymKey', 5834 params: 0 5835 }), 5836 new Method({ 5837 name: 'addSymKey', 5838 call: 'shh_addSymKey', 5839 params: 1 5840 }), 5841 new Method({ 5842 name: 'generateSymKeyFromPassword', 5843 call: 'shh_generateSymKeyFromPassword', 5844 params: 1 5845 }), 5846 new Method({ 5847 name: 'hasSymKey', 5848 call: 'shh_hasSymKey', 5849 params: 1 5850 }), 5851 new Method({ 5852 name: 'getSymKey', 5853 call: 'shh_getSymKey', 5854 params: 1 5855 }), 5856 new Method({ 5857 name: 'deleteSymKey', 5858 call: 'shh_deleteSymKey', 5859 params: 1 5860 }), 5861 5862 // subscribe and unsubscribe missing 5863 5864 new Method({ 5865 name: 'post', 5866 call: 'shh_post', 5867 params: 1, 5868 inputFormatter: [null] 5869 }) 5870 ]; 5871 }; 5872 5873 module.exports = Shh; 5874 5875 5876 },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){ 5877 /* 5878 This file is part of web3.js. 5879 5880 web3.js is free software: you can redistribute it and/or modify 5881 it under the terms of the GNU Lesser General Public License as published by 5882 the Free Software Foundation, either version 3 of the License, or 5883 (at your option) any later version. 5884 5885 web3.js is distributed in the hope that it will be useful, 5886 but WITHOUT ANY WARRANTY; without even the implied warranty of 5887 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5888 GNU Lesser General Public License for more details. 5889 5890 You should have received a copy of the GNU Lesser General Public License 5891 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5892 */ 5893 /** 5894 * @file bzz.js 5895 * @author Alex Beregszaszi <alex@rtfs.hu> 5896 * @date 2016 5897 * 5898 * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33 5899 */ 5900 5901 "use strict"; 5902 5903 var Method = require('../method'); 5904 var Property = require('../property'); 5905 5906 function Swarm(web3) { 5907 this._requestManager = web3._requestManager; 5908 5909 var self = this; 5910 5911 methods().forEach(function(method) { 5912 method.attachToObject(self); 5913 method.setRequestManager(self._requestManager); 5914 }); 5915 5916 properties().forEach(function(p) { 5917 p.attachToObject(self); 5918 p.setRequestManager(self._requestManager); 5919 }); 5920 } 5921 5922 var methods = function () { 5923 var blockNetworkRead = new Method({ 5924 name: 'blockNetworkRead', 5925 call: 'bzz_blockNetworkRead', 5926 params: 1, 5927 inputFormatter: [null] 5928 }); 5929 5930 var syncEnabled = new Method({ 5931 name: 'syncEnabled', 5932 call: 'bzz_syncEnabled', 5933 params: 1, 5934 inputFormatter: [null] 5935 }); 5936 5937 var swapEnabled = new Method({ 5938 name: 'swapEnabled', 5939 call: 'bzz_swapEnabled', 5940 params: 1, 5941 inputFormatter: [null] 5942 }); 5943 5944 var download = new Method({ 5945 name: 'download', 5946 call: 'bzz_download', 5947 params: 2, 5948 inputFormatter: [null, null] 5949 }); 5950 5951 var upload = new Method({ 5952 name: 'upload', 5953 call: 'bzz_upload', 5954 params: 2, 5955 inputFormatter: [null, null] 5956 }); 5957 5958 var retrieve = new Method({ 5959 name: 'retrieve', 5960 call: 'bzz_retrieve', 5961 params: 1, 5962 inputFormatter: [null] 5963 }); 5964 5965 var store = new Method({ 5966 name: 'store', 5967 call: 'bzz_store', 5968 params: 2, 5969 inputFormatter: [null, null] 5970 }); 5971 5972 var get = new Method({ 5973 name: 'get', 5974 call: 'bzz_get', 5975 params: 1, 5976 inputFormatter: [null] 5977 }); 5978 5979 var put = new Method({ 5980 name: 'put', 5981 call: 'bzz_put', 5982 params: 2, 5983 inputFormatter: [null, null] 5984 }); 5985 5986 var modify = new Method({ 5987 name: 'modify', 5988 call: 'bzz_modify', 5989 params: 4, 5990 inputFormatter: [null, null, null, null] 5991 }); 5992 5993 return [ 5994 blockNetworkRead, 5995 syncEnabled, 5996 swapEnabled, 5997 download, 5998 upload, 5999 retrieve, 6000 store, 6001 get, 6002 put, 6003 modify 6004 ]; 6005 }; 6006 6007 var properties = function () { 6008 return [ 6009 new Property({ 6010 name: 'hive', 6011 getter: 'bzz_hive' 6012 }), 6013 new Property({ 6014 name: 'info', 6015 getter: 'bzz_info' 6016 }) 6017 ]; 6018 }; 6019 6020 6021 module.exports = Swarm; 6022 6023 },{"../method":36,"../property":45}],43:[function(require,module,exports){ 6024 /* 6025 This file is part of web3.js. 6026 6027 web3.js is free software: you can redistribute it and/or modify 6028 it under the terms of the GNU Lesser General Public License as published by 6029 the Free Software Foundation, either version 3 of the License, or 6030 (at your option) any later version. 6031 6032 web3.js is distributed in the hope that it will be useful, 6033 but WITHOUT ANY WARRANTY; without even the implied warranty of 6034 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6035 GNU Lesser General Public License for more details. 6036 6037 You should have received a copy of the GNU Lesser General Public License 6038 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6039 */ 6040 /** @file watches.js 6041 * @authors: 6042 * Marek Kotewicz <marek@ethdev.com> 6043 * @date 2015 6044 */ 6045 6046 var Method = require('../method'); 6047 6048 /// @returns an array of objects describing web3.eth.filter api methods 6049 var eth = function () { 6050 var newFilterCall = function (args) { 6051 var type = args[0]; 6052 6053 switch(type) { 6054 case 'latest': 6055 args.shift(); 6056 this.params = 0; 6057 return 'eth_newBlockFilter'; 6058 case 'pending': 6059 args.shift(); 6060 this.params = 0; 6061 return 'eth_newPendingTransactionFilter'; 6062 default: 6063 return 'eth_newFilter'; 6064 } 6065 }; 6066 6067 var newFilter = new Method({ 6068 name: 'newFilter', 6069 call: newFilterCall, 6070 params: 1 6071 }); 6072 6073 var uninstallFilter = new Method({ 6074 name: 'uninstallFilter', 6075 call: 'eth_uninstallFilter', 6076 params: 1 6077 }); 6078 6079 var getLogs = new Method({ 6080 name: 'getLogs', 6081 call: 'eth_getFilterLogs', 6082 params: 1 6083 }); 6084 6085 var poll = new Method({ 6086 name: 'poll', 6087 call: 'eth_getFilterChanges', 6088 params: 1 6089 }); 6090 6091 return [ 6092 newFilter, 6093 uninstallFilter, 6094 getLogs, 6095 poll 6096 ]; 6097 }; 6098 6099 /// @returns an array of objects describing web3.shh.watch api methods 6100 var shh = function () { 6101 6102 return [ 6103 new Method({ 6104 name: 'newFilter', 6105 call: 'shh_newMessageFilter', 6106 params: 1 6107 }), 6108 new Method({ 6109 name: 'uninstallFilter', 6110 call: 'shh_deleteMessageFilter', 6111 params: 1 6112 }), 6113 new Method({ 6114 name: 'getLogs', 6115 call: 'shh_getFilterMessages', 6116 params: 1 6117 }), 6118 new Method({ 6119 name: 'poll', 6120 call: 'shh_getFilterMessages', 6121 params: 1 6122 }) 6123 ]; 6124 }; 6125 6126 module.exports = { 6127 eth: eth, 6128 shh: shh 6129 }; 6130 6131 6132 },{"../method":36}],44:[function(require,module,exports){ 6133 /* 6134 This file is part of web3.js. 6135 6136 web3.js is free software: you can redistribute it and/or modify 6137 it under the terms of the GNU Lesser General Public License as published by 6138 the Free Software Foundation, either version 3 of the License, or 6139 (at your option) any later version. 6140 6141 web3.js is distributed in the hope that it will be useful, 6142 but WITHOUT ANY WARRANTY; without even the implied warranty of 6143 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6144 GNU Lesser General Public License for more details. 6145 6146 You should have received a copy of the GNU Lesser General Public License 6147 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6148 */ 6149 /** 6150 * @file namereg.js 6151 * @author Marek Kotewicz <marek@ethdev.com> 6152 * @date 2015 6153 */ 6154 6155 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6156 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6157 6158 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6159 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6160 6161 module.exports = { 6162 global: { 6163 abi: globalRegistrarAbi, 6164 address: globalNameregAddress 6165 }, 6166 icap: { 6167 abi: icapRegistrarAbi, 6168 address: icapNameregAddress 6169 } 6170 }; 6171 6172 6173 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 6174 /* 6175 This file is part of web3.js. 6176 6177 web3.js is free software: you can redistribute it and/or modify 6178 it under the terms of the GNU Lesser General Public License as published by 6179 the Free Software Foundation, either version 3 of the License, or 6180 (at your option) any later version. 6181 6182 web3.js is distributed in the hope that it will be useful, 6183 but WITHOUT ANY WARRANTY; without even the implied warranty of 6184 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6185 GNU Lesser General Public License for more details. 6186 6187 You should have received a copy of the GNU Lesser General Public License 6188 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6189 */ 6190 /** 6191 * @file property.js 6192 * @author Fabian Vogelsteller <fabian@frozeman.de> 6193 * @author Marek Kotewicz <marek@ethdev.com> 6194 * @date 2015 6195 */ 6196 6197 var utils = require('../utils/utils'); 6198 6199 var Property = function (options) { 6200 this.name = options.name; 6201 this.getter = options.getter; 6202 this.setter = options.setter; 6203 this.outputFormatter = options.outputFormatter; 6204 this.inputFormatter = options.inputFormatter; 6205 this.requestManager = null; 6206 }; 6207 6208 Property.prototype.setRequestManager = function (rm) { 6209 this.requestManager = rm; 6210 }; 6211 6212 /** 6213 * Should be called to format input args of method 6214 * 6215 * @method formatInput 6216 * @param {Array} 6217 * @return {Array} 6218 */ 6219 Property.prototype.formatInput = function (arg) { 6220 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6221 }; 6222 6223 /** 6224 * Should be called to format output(result) of method 6225 * 6226 * @method formatOutput 6227 * @param {Object} 6228 * @return {Object} 6229 */ 6230 Property.prototype.formatOutput = function (result) { 6231 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6232 }; 6233 6234 /** 6235 * Should be used to extract callback from array of arguments. Modifies input param 6236 * 6237 * @method extractCallback 6238 * @param {Array} arguments 6239 * @return {Function|Null} callback, if exists 6240 */ 6241 Property.prototype.extractCallback = function (args) { 6242 if (utils.isFunction(args[args.length - 1])) { 6243 return args.pop(); // modify the args array! 6244 } 6245 }; 6246 6247 6248 /** 6249 * Should attach function to method 6250 * 6251 * @method attachToObject 6252 * @param {Object} 6253 * @param {Function} 6254 */ 6255 Property.prototype.attachToObject = function (obj) { 6256 var proto = { 6257 get: this.buildGet(), 6258 enumerable: true 6259 }; 6260 6261 var names = this.name.split('.'); 6262 var name = names[0]; 6263 if (names.length > 1) { 6264 obj[names[0]] = obj[names[0]] || {}; 6265 obj = obj[names[0]]; 6266 name = names[1]; 6267 } 6268 6269 Object.defineProperty(obj, name, proto); 6270 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6271 }; 6272 6273 var asyncGetterName = function (name) { 6274 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6275 }; 6276 6277 Property.prototype.buildGet = function () { 6278 var property = this; 6279 return function get() { 6280 return property.formatOutput(property.requestManager.send({ 6281 method: property.getter 6282 })); 6283 }; 6284 }; 6285 6286 Property.prototype.buildAsyncGet = function () { 6287 var property = this; 6288 var get = function (callback) { 6289 property.requestManager.sendAsync({ 6290 method: property.getter 6291 }, function (err, result) { 6292 callback(err, property.formatOutput(result)); 6293 }); 6294 }; 6295 get.request = this.request.bind(this); 6296 return get; 6297 }; 6298 6299 /** 6300 * Should be called to create pure JSONRPC request which can be used in batch request 6301 * 6302 * @method request 6303 * @param {...} params 6304 * @return {Object} jsonrpc request 6305 */ 6306 Property.prototype.request = function () { 6307 var payload = { 6308 method: this.getter, 6309 params: [], 6310 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6311 }; 6312 payload.format = this.formatOutput.bind(this); 6313 return payload; 6314 }; 6315 6316 module.exports = Property; 6317 6318 6319 },{"../utils/utils":20}],46:[function(require,module,exports){ 6320 /* 6321 This file is part of web3.js. 6322 6323 web3.js is free software: you can redistribute it and/or modify 6324 it under the terms of the GNU Lesser General Public License as published by 6325 the Free Software Foundation, either version 3 of the License, or 6326 (at your option) any later version. 6327 6328 web3.js is distributed in the hope that it will be useful, 6329 but WITHOUT ANY WARRANTY; without even the implied warranty of 6330 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6331 GNU Lesser General Public License for more details. 6332 6333 You should have received a copy of the GNU Lesser General Public License 6334 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6335 */ 6336 /** 6337 * @file requestmanager.js 6338 * @author Jeffrey Wilcke <jeff@ethdev.com> 6339 * @author Marek Kotewicz <marek@ethdev.com> 6340 * @author Marian Oancea <marian@ethdev.com> 6341 * @author Fabian Vogelsteller <fabian@ethdev.com> 6342 * @author Gav Wood <g@ethdev.com> 6343 * @date 2014 6344 */ 6345 6346 var Jsonrpc = require('./jsonrpc'); 6347 var utils = require('../utils/utils'); 6348 var c = require('../utils/config'); 6349 var errors = require('./errors'); 6350 6351 /** 6352 * It's responsible for passing messages to providers 6353 * It's also responsible for polling the ethereum node for incoming messages 6354 * Default poll timeout is 1 second 6355 * Singleton 6356 */ 6357 var RequestManager = function (provider) { 6358 this.provider = provider; 6359 this.polls = {}; 6360 this.timeout = null; 6361 }; 6362 6363 /** 6364 * Should be used to synchronously send request 6365 * 6366 * @method send 6367 * @param {Object} data 6368 * @return {Object} 6369 */ 6370 RequestManager.prototype.send = function (data) { 6371 if (!this.provider) { 6372 console.error(errors.InvalidProvider()); 6373 return null; 6374 } 6375 6376 var payload = Jsonrpc.toPayload(data.method, data.params); 6377 var result = this.provider.send(payload); 6378 6379 if (!Jsonrpc.isValidResponse(result)) { 6380 throw errors.InvalidResponse(result); 6381 } 6382 6383 return result.result; 6384 }; 6385 6386 /** 6387 * Should be used to asynchronously send request 6388 * 6389 * @method sendAsync 6390 * @param {Object} data 6391 * @param {Function} callback 6392 */ 6393 RequestManager.prototype.sendAsync = function (data, callback) { 6394 if (!this.provider) { 6395 return callback(errors.InvalidProvider()); 6396 } 6397 6398 var payload = Jsonrpc.toPayload(data.method, data.params); 6399 this.provider.sendAsync(payload, function (err, result) { 6400 if (err) { 6401 return callback(err); 6402 } 6403 6404 if (!Jsonrpc.isValidResponse(result)) { 6405 return callback(errors.InvalidResponse(result)); 6406 } 6407 6408 callback(null, result.result); 6409 }); 6410 }; 6411 6412 /** 6413 * Should be called to asynchronously send batch request 6414 * 6415 * @method sendBatch 6416 * @param {Array} batch data 6417 * @param {Function} callback 6418 */ 6419 RequestManager.prototype.sendBatch = function (data, callback) { 6420 if (!this.provider) { 6421 return callback(errors.InvalidProvider()); 6422 } 6423 6424 var payload = Jsonrpc.toBatchPayload(data); 6425 6426 this.provider.sendAsync(payload, function (err, results) { 6427 if (err) { 6428 return callback(err); 6429 } 6430 6431 if (!utils.isArray(results)) { 6432 return callback(errors.InvalidResponse(results)); 6433 } 6434 6435 callback(err, results); 6436 }); 6437 }; 6438 6439 /** 6440 * Should be used to set provider of request manager 6441 * 6442 * @method setProvider 6443 * @param {Object} 6444 */ 6445 RequestManager.prototype.setProvider = function (p) { 6446 this.provider = p; 6447 }; 6448 6449 /** 6450 * Should be used to start polling 6451 * 6452 * @method startPolling 6453 * @param {Object} data 6454 * @param {Number} pollId 6455 * @param {Function} callback 6456 * @param {Function} uninstall 6457 * 6458 * @todo cleanup number of params 6459 */ 6460 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6461 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 6462 6463 6464 // start polling 6465 if (!this.timeout) { 6466 this.poll(); 6467 } 6468 }; 6469 6470 /** 6471 * Should be used to stop polling for filter with given id 6472 * 6473 * @method stopPolling 6474 * @param {Number} pollId 6475 */ 6476 RequestManager.prototype.stopPolling = function (pollId) { 6477 delete this.polls[pollId]; 6478 6479 // stop polling 6480 if(Object.keys(this.polls).length === 0 && this.timeout) { 6481 clearTimeout(this.timeout); 6482 this.timeout = null; 6483 } 6484 }; 6485 6486 /** 6487 * Should be called to reset the polling mechanism of the request manager 6488 * 6489 * @method reset 6490 */ 6491 RequestManager.prototype.reset = function (keepIsSyncing) { 6492 /*jshint maxcomplexity:5 */ 6493 6494 for (var key in this.polls) { 6495 // remove all polls, except sync polls, 6496 // they need to be removed manually by calling syncing.stopWatching() 6497 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6498 this.polls[key].uninstall(); 6499 delete this.polls[key]; 6500 } 6501 } 6502 6503 // stop polling 6504 if(Object.keys(this.polls).length === 0 && this.timeout) { 6505 clearTimeout(this.timeout); 6506 this.timeout = null; 6507 } 6508 }; 6509 6510 /** 6511 * Should be called to poll for changes on filter with given id 6512 * 6513 * @method poll 6514 */ 6515 RequestManager.prototype.poll = function () { 6516 /*jshint maxcomplexity: 6 */ 6517 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6518 6519 if (Object.keys(this.polls).length === 0) { 6520 return; 6521 } 6522 6523 if (!this.provider) { 6524 console.error(errors.InvalidProvider()); 6525 return; 6526 } 6527 6528 var pollsData = []; 6529 var pollsIds = []; 6530 for (var key in this.polls) { 6531 pollsData.push(this.polls[key].data); 6532 pollsIds.push(key); 6533 } 6534 6535 if (pollsData.length === 0) { 6536 return; 6537 } 6538 6539 var payload = Jsonrpc.toBatchPayload(pollsData); 6540 6541 // map the request id to they poll id 6542 var pollsIdMap = {}; 6543 payload.forEach(function(load, index){ 6544 pollsIdMap[load.id] = pollsIds[index]; 6545 }); 6546 6547 6548 var self = this; 6549 this.provider.sendAsync(payload, function (error, results) { 6550 6551 6552 // TODO: console log? 6553 if (error) { 6554 return; 6555 } 6556 6557 if (!utils.isArray(results)) { 6558 throw errors.InvalidResponse(results); 6559 } 6560 results.map(function (result) { 6561 var id = pollsIdMap[result.id]; 6562 6563 // make sure the filter is still installed after arrival of the request 6564 if (self.polls[id]) { 6565 result.callback = self.polls[id].callback; 6566 return result; 6567 } else 6568 return false; 6569 }).filter(function (result) { 6570 return !!result; 6571 }).filter(function (result) { 6572 var valid = Jsonrpc.isValidResponse(result); 6573 if (!valid) { 6574 result.callback(errors.InvalidResponse(result)); 6575 } 6576 return valid; 6577 }).forEach(function (result) { 6578 result.callback(null, result.result); 6579 }); 6580 }); 6581 }; 6582 6583 module.exports = RequestManager; 6584 6585 6586 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 6587 6588 6589 var Settings = function () { 6590 this.defaultBlock = 'latest'; 6591 this.defaultAccount = undefined; 6592 }; 6593 6594 module.exports = Settings; 6595 6596 6597 },{}],48:[function(require,module,exports){ 6598 /* 6599 This file is part of web3.js. 6600 6601 web3.js is free software: you can redistribute it and/or modify 6602 it under the terms of the GNU Lesser General Public License as published by 6603 the Free Software Foundation, either version 3 of the License, or 6604 (at your option) any later version. 6605 6606 web3.js is distributed in the hope that it will be useful, 6607 but WITHOUT ANY WARRANTY; without even the implied warranty of 6608 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6609 GNU Lesser General Public License for more details. 6610 6611 You should have received a copy of the GNU Lesser General Public License 6612 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6613 */ 6614 /** @file syncing.js 6615 * @authors: 6616 * Fabian Vogelsteller <fabian@ethdev.com> 6617 * @date 2015 6618 */ 6619 6620 var formatters = require('./formatters'); 6621 var utils = require('../utils/utils'); 6622 6623 var count = 1; 6624 6625 /** 6626 Adds the callback and sets up the methods, to iterate over the results. 6627 6628 @method pollSyncing 6629 @param {Object} self 6630 */ 6631 var pollSyncing = function(self) { 6632 6633 var onMessage = function (error, sync) { 6634 if (error) { 6635 return self.callbacks.forEach(function (callback) { 6636 callback(error); 6637 }); 6638 } 6639 6640 if(utils.isObject(sync) && sync.startingBlock) 6641 sync = formatters.outputSyncingFormatter(sync); 6642 6643 self.callbacks.forEach(function (callback) { 6644 if (self.lastSyncState !== sync) { 6645 6646 // call the callback with true first so the app can stop anything, before receiving the sync data 6647 if(!self.lastSyncState && utils.isObject(sync)) 6648 callback(null, true); 6649 6650 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6651 setTimeout(function() { 6652 callback(null, sync); 6653 }, 0); 6654 6655 self.lastSyncState = sync; 6656 } 6657 }); 6658 }; 6659 6660 self.requestManager.startPolling({ 6661 method: 'eth_syncing', 6662 params: [], 6663 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6664 6665 }; 6666 6667 var IsSyncing = function (requestManager, callback) { 6668 this.requestManager = requestManager; 6669 this.pollId = 'syncPoll_'+ count++; 6670 this.callbacks = []; 6671 this.addCallback(callback); 6672 this.lastSyncState = false; 6673 pollSyncing(this); 6674 6675 return this; 6676 }; 6677 6678 IsSyncing.prototype.addCallback = function (callback) { 6679 if(callback) 6680 this.callbacks.push(callback); 6681 return this; 6682 }; 6683 6684 IsSyncing.prototype.stopWatching = function () { 6685 this.requestManager.stopPolling(this.pollId); 6686 this.callbacks = []; 6687 }; 6688 6689 module.exports = IsSyncing; 6690 6691 6692 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 6693 /* 6694 This file is part of web3.js. 6695 6696 web3.js is free software: you can redistribute it and/or modify 6697 it under the terms of the GNU Lesser General Public License as published by 6698 the Free Software Foundation, either version 3 of the License, or 6699 (at your option) any later version. 6700 6701 web3.js is distributed in the hope that it will be useful, 6702 but WITHOUT ANY WARRANTY; without even the implied warranty of 6703 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6704 GNU Lesser General Public License for more details. 6705 6706 You should have received a copy of the GNU Lesser General Public License 6707 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6708 */ 6709 /** 6710 * @file transfer.js 6711 * @author Marek Kotewicz <marek@ethdev.com> 6712 * @date 2015 6713 */ 6714 6715 var Iban = require('./iban'); 6716 var exchangeAbi = require('../contracts/SmartExchange.json'); 6717 6718 /** 6719 * Should be used to make Iban transfer 6720 * 6721 * @method transfer 6722 * @param {String} from 6723 * @param {String} to iban 6724 * @param {Value} value to be tranfered 6725 * @param {Function} callback, callback 6726 */ 6727 var transfer = function (eth, from, to, value, callback) { 6728 var iban = new Iban(to); 6729 if (!iban.isValid()) { 6730 throw new Error('invalid iban address'); 6731 } 6732 6733 if (iban.isDirect()) { 6734 return transferToAddress(eth, from, iban.address(), value, callback); 6735 } 6736 6737 if (!callback) { 6738 var address = eth.icapNamereg().addr(iban.institution()); 6739 return deposit(eth, from, address, value, iban.client()); 6740 } 6741 6742 eth.icapNamereg().addr(iban.institution(), function (err, address) { 6743 return deposit(eth, from, address, value, iban.client(), callback); 6744 }); 6745 6746 }; 6747 6748 /** 6749 * Should be used to transfer funds to certain address 6750 * 6751 * @method transferToAddress 6752 * @param {String} from 6753 * @param {String} to 6754 * @param {Value} value to be tranfered 6755 * @param {Function} callback, callback 6756 */ 6757 var transferToAddress = function (eth, from, to, value, callback) { 6758 return eth.sendTransaction({ 6759 address: to, 6760 from: from, 6761 value: value 6762 }, callback); 6763 }; 6764 6765 /** 6766 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6767 * 6768 * @method deposit 6769 * @param {String} from 6770 * @param {String} to 6771 * @param {Value} value to be transferred 6772 * @param {String} client unique identifier 6773 * @param {Function} callback, callback 6774 */ 6775 var deposit = function (eth, from, to, value, client, callback) { 6776 var abi = exchangeAbi; 6777 return eth.contract(abi).at(to).deposit(client, { 6778 from: from, 6779 value: value 6780 }, callback); 6781 }; 6782 6783 module.exports = transfer; 6784 6785 6786 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 6787 6788 },{}],51:[function(require,module,exports){ 6789 ;(function (root, factory, undef) { 6790 if (typeof exports === "object") { 6791 // CommonJS 6792 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6793 } 6794 else if (typeof define === "function" && define.amd) { 6795 // AMD 6796 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6797 } 6798 else { 6799 // Global (browser) 6800 factory(root.CryptoJS); 6801 } 6802 }(this, function (CryptoJS) { 6803 6804 (function () { 6805 // Shortcuts 6806 var C = CryptoJS; 6807 var C_lib = C.lib; 6808 var BlockCipher = C_lib.BlockCipher; 6809 var C_algo = C.algo; 6810 6811 // Lookup tables 6812 var SBOX = []; 6813 var INV_SBOX = []; 6814 var SUB_MIX_0 = []; 6815 var SUB_MIX_1 = []; 6816 var SUB_MIX_2 = []; 6817 var SUB_MIX_3 = []; 6818 var INV_SUB_MIX_0 = []; 6819 var INV_SUB_MIX_1 = []; 6820 var INV_SUB_MIX_2 = []; 6821 var INV_SUB_MIX_3 = []; 6822 6823 // Compute lookup tables 6824 (function () { 6825 // Compute double table 6826 var d = []; 6827 for (var i = 0; i < 256; i++) { 6828 if (i < 128) { 6829 d[i] = i << 1; 6830 } else { 6831 d[i] = (i << 1) ^ 0x11b; 6832 } 6833 } 6834 6835 // Walk GF(2^8) 6836 var x = 0; 6837 var xi = 0; 6838 for (var i = 0; i < 256; i++) { 6839 // Compute sbox 6840 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6841 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6842 SBOX[x] = sx; 6843 INV_SBOX[sx] = x; 6844 6845 // Compute multiplication 6846 var x2 = d[x]; 6847 var x4 = d[x2]; 6848 var x8 = d[x4]; 6849 6850 // Compute sub bytes, mix columns tables 6851 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6852 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6853 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6854 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6855 SUB_MIX_3[x] = t; 6856 6857 // Compute inv sub bytes, inv mix columns tables 6858 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6859 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6860 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6861 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6862 INV_SUB_MIX_3[sx] = t; 6863 6864 // Compute next counter 6865 if (!x) { 6866 x = xi = 1; 6867 } else { 6868 x = x2 ^ d[d[d[x8 ^ x2]]]; 6869 xi ^= d[d[xi]]; 6870 } 6871 } 6872 }()); 6873 6874 // Precomputed Rcon lookup 6875 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6876 6877 /** 6878 * AES block cipher algorithm. 6879 */ 6880 var AES = C_algo.AES = BlockCipher.extend({ 6881 _doReset: function () { 6882 // Skip reset of nRounds has been set before and key did not change 6883 if (this._nRounds && this._keyPriorReset === this._key) { 6884 return; 6885 } 6886 6887 // Shortcuts 6888 var key = this._keyPriorReset = this._key; 6889 var keyWords = key.words; 6890 var keySize = key.sigBytes / 4; 6891 6892 // Compute number of rounds 6893 var nRounds = this._nRounds = keySize + 6; 6894 6895 // Compute number of key schedule rows 6896 var ksRows = (nRounds + 1) * 4; 6897 6898 // Compute key schedule 6899 var keySchedule = this._keySchedule = []; 6900 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 6901 if (ksRow < keySize) { 6902 keySchedule[ksRow] = keyWords[ksRow]; 6903 } else { 6904 var t = keySchedule[ksRow - 1]; 6905 6906 if (!(ksRow % keySize)) { 6907 // Rot word 6908 t = (t << 8) | (t >>> 24); 6909 6910 // Sub word 6911 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6912 6913 // Mix Rcon 6914 t ^= RCON[(ksRow / keySize) | 0] << 24; 6915 } else if (keySize > 6 && ksRow % keySize == 4) { 6916 // Sub word 6917 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6918 } 6919 6920 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 6921 } 6922 } 6923 6924 // Compute inv key schedule 6925 var invKeySchedule = this._invKeySchedule = []; 6926 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 6927 var ksRow = ksRows - invKsRow; 6928 6929 if (invKsRow % 4) { 6930 var t = keySchedule[ksRow]; 6931 } else { 6932 var t = keySchedule[ksRow - 4]; 6933 } 6934 6935 if (invKsRow < 4 || ksRow <= 4) { 6936 invKeySchedule[invKsRow] = t; 6937 } else { 6938 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 6939 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 6940 } 6941 } 6942 }, 6943 6944 encryptBlock: function (M, offset) { 6945 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 6946 }, 6947 6948 decryptBlock: function (M, offset) { 6949 // Swap 2nd and 4th rows 6950 var t = M[offset + 1]; 6951 M[offset + 1] = M[offset + 3]; 6952 M[offset + 3] = t; 6953 6954 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 6955 6956 // Inv swap 2nd and 4th rows 6957 var t = M[offset + 1]; 6958 M[offset + 1] = M[offset + 3]; 6959 M[offset + 3] = t; 6960 }, 6961 6962 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 6963 // Shortcut 6964 var nRounds = this._nRounds; 6965 6966 // Get input, add round key 6967 var s0 = M[offset] ^ keySchedule[0]; 6968 var s1 = M[offset + 1] ^ keySchedule[1]; 6969 var s2 = M[offset + 2] ^ keySchedule[2]; 6970 var s3 = M[offset + 3] ^ keySchedule[3]; 6971 6972 // Key schedule row counter 6973 var ksRow = 4; 6974 6975 // Rounds 6976 for (var round = 1; round < nRounds; round++) { 6977 // Shift rows, sub bytes, mix columns, add round key 6978 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++]; 6979 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++]; 6980 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++]; 6981 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++]; 6982 6983 // Update state 6984 s0 = t0; 6985 s1 = t1; 6986 s2 = t2; 6987 s3 = t3; 6988 } 6989 6990 // Shift rows, sub bytes, add round key 6991 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 6992 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 6993 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 6994 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 6995 6996 // Set output 6997 M[offset] = t0; 6998 M[offset + 1] = t1; 6999 M[offset + 2] = t2; 7000 M[offset + 3] = t3; 7001 }, 7002 7003 keySize: 256/32 7004 }); 7005 7006 /** 7007 * Shortcut functions to the cipher's object interface. 7008 * 7009 * @example 7010 * 7011 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7012 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7013 */ 7014 C.AES = BlockCipher._createHelper(AES); 7015 }()); 7016 7017 7018 return CryptoJS.AES; 7019 7020 })); 7021 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 7022 ;(function (root, factory) { 7023 if (typeof exports === "object") { 7024 // CommonJS 7025 module.exports = exports = factory(require("./core")); 7026 } 7027 else if (typeof define === "function" && define.amd) { 7028 // AMD 7029 define(["./core"], factory); 7030 } 7031 else { 7032 // Global (browser) 7033 factory(root.CryptoJS); 7034 } 7035 }(this, function (CryptoJS) { 7036 7037 /** 7038 * Cipher core components. 7039 */ 7040 CryptoJS.lib.Cipher || (function (undefined) { 7041 // Shortcuts 7042 var C = CryptoJS; 7043 var C_lib = C.lib; 7044 var Base = C_lib.Base; 7045 var WordArray = C_lib.WordArray; 7046 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7047 var C_enc = C.enc; 7048 var Utf8 = C_enc.Utf8; 7049 var Base64 = C_enc.Base64; 7050 var C_algo = C.algo; 7051 var EvpKDF = C_algo.EvpKDF; 7052 7053 /** 7054 * Abstract base cipher template. 7055 * 7056 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7057 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7058 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7059 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7060 */ 7061 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7062 /** 7063 * Configuration options. 7064 * 7065 * @property {WordArray} iv The IV to use for this operation. 7066 */ 7067 cfg: Base.extend(), 7068 7069 /** 7070 * Creates this cipher in encryption mode. 7071 * 7072 * @param {WordArray} key The key. 7073 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7074 * 7075 * @return {Cipher} A cipher instance. 7076 * 7077 * @static 7078 * 7079 * @example 7080 * 7081 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7082 */ 7083 createEncryptor: function (key, cfg) { 7084 return this.create(this._ENC_XFORM_MODE, key, cfg); 7085 }, 7086 7087 /** 7088 * Creates this cipher in decryption mode. 7089 * 7090 * @param {WordArray} key The key. 7091 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7092 * 7093 * @return {Cipher} A cipher instance. 7094 * 7095 * @static 7096 * 7097 * @example 7098 * 7099 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7100 */ 7101 createDecryptor: function (key, cfg) { 7102 return this.create(this._DEC_XFORM_MODE, key, cfg); 7103 }, 7104 7105 /** 7106 * Initializes a newly created cipher. 7107 * 7108 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7109 * @param {WordArray} key The key. 7110 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7111 * 7112 * @example 7113 * 7114 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7115 */ 7116 init: function (xformMode, key, cfg) { 7117 // Apply config defaults 7118 this.cfg = this.cfg.extend(cfg); 7119 7120 // Store transform mode and key 7121 this._xformMode = xformMode; 7122 this._key = key; 7123 7124 // Set initial values 7125 this.reset(); 7126 }, 7127 7128 /** 7129 * Resets this cipher to its initial state. 7130 * 7131 * @example 7132 * 7133 * cipher.reset(); 7134 */ 7135 reset: function () { 7136 // Reset data buffer 7137 BufferedBlockAlgorithm.reset.call(this); 7138 7139 // Perform concrete-cipher logic 7140 this._doReset(); 7141 }, 7142 7143 /** 7144 * Adds data to be encrypted or decrypted. 7145 * 7146 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7147 * 7148 * @return {WordArray} The data after processing. 7149 * 7150 * @example 7151 * 7152 * var encrypted = cipher.process('data'); 7153 * var encrypted = cipher.process(wordArray); 7154 */ 7155 process: function (dataUpdate) { 7156 // Append 7157 this._append(dataUpdate); 7158 7159 // Process available blocks 7160 return this._process(); 7161 }, 7162 7163 /** 7164 * Finalizes the encryption or decryption process. 7165 * Note that the finalize operation is effectively a destructive, read-once operation. 7166 * 7167 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7168 * 7169 * @return {WordArray} The data after final processing. 7170 * 7171 * @example 7172 * 7173 * var encrypted = cipher.finalize(); 7174 * var encrypted = cipher.finalize('data'); 7175 * var encrypted = cipher.finalize(wordArray); 7176 */ 7177 finalize: function (dataUpdate) { 7178 // Final data update 7179 if (dataUpdate) { 7180 this._append(dataUpdate); 7181 } 7182 7183 // Perform concrete-cipher logic 7184 var finalProcessedData = this._doFinalize(); 7185 7186 return finalProcessedData; 7187 }, 7188 7189 keySize: 128/32, 7190 7191 ivSize: 128/32, 7192 7193 _ENC_XFORM_MODE: 1, 7194 7195 _DEC_XFORM_MODE: 2, 7196 7197 /** 7198 * Creates shortcut functions to a cipher's object interface. 7199 * 7200 * @param {Cipher} cipher The cipher to create a helper for. 7201 * 7202 * @return {Object} An object with encrypt and decrypt shortcut functions. 7203 * 7204 * @static 7205 * 7206 * @example 7207 * 7208 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7209 */ 7210 _createHelper: (function () { 7211 function selectCipherStrategy(key) { 7212 if (typeof key == 'string') { 7213 return PasswordBasedCipher; 7214 } else { 7215 return SerializableCipher; 7216 } 7217 } 7218 7219 return function (cipher) { 7220 return { 7221 encrypt: function (message, key, cfg) { 7222 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7223 }, 7224 7225 decrypt: function (ciphertext, key, cfg) { 7226 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7227 } 7228 }; 7229 }; 7230 }()) 7231 }); 7232 7233 /** 7234 * Abstract base stream cipher template. 7235 * 7236 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7237 */ 7238 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7239 _doFinalize: function () { 7240 // Process partial blocks 7241 var finalProcessedBlocks = this._process(!!'flush'); 7242 7243 return finalProcessedBlocks; 7244 }, 7245 7246 blockSize: 1 7247 }); 7248 7249 /** 7250 * Mode namespace. 7251 */ 7252 var C_mode = C.mode = {}; 7253 7254 /** 7255 * Abstract base block cipher mode template. 7256 */ 7257 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7258 /** 7259 * Creates this mode for encryption. 7260 * 7261 * @param {Cipher} cipher A block cipher instance. 7262 * @param {Array} iv The IV words. 7263 * 7264 * @static 7265 * 7266 * @example 7267 * 7268 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7269 */ 7270 createEncryptor: function (cipher, iv) { 7271 return this.Encryptor.create(cipher, iv); 7272 }, 7273 7274 /** 7275 * Creates this mode for decryption. 7276 * 7277 * @param {Cipher} cipher A block cipher instance. 7278 * @param {Array} iv The IV words. 7279 * 7280 * @static 7281 * 7282 * @example 7283 * 7284 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7285 */ 7286 createDecryptor: function (cipher, iv) { 7287 return this.Decryptor.create(cipher, iv); 7288 }, 7289 7290 /** 7291 * Initializes a newly created mode. 7292 * 7293 * @param {Cipher} cipher A block cipher instance. 7294 * @param {Array} iv The IV words. 7295 * 7296 * @example 7297 * 7298 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7299 */ 7300 init: function (cipher, iv) { 7301 this._cipher = cipher; 7302 this._iv = iv; 7303 } 7304 }); 7305 7306 /** 7307 * Cipher Block Chaining mode. 7308 */ 7309 var CBC = C_mode.CBC = (function () { 7310 /** 7311 * Abstract base CBC mode. 7312 */ 7313 var CBC = BlockCipherMode.extend(); 7314 7315 /** 7316 * CBC encryptor. 7317 */ 7318 CBC.Encryptor = CBC.extend({ 7319 /** 7320 * Processes the data block at offset. 7321 * 7322 * @param {Array} words The data words to operate on. 7323 * @param {number} offset The offset where the block starts. 7324 * 7325 * @example 7326 * 7327 * mode.processBlock(data.words, offset); 7328 */ 7329 processBlock: function (words, offset) { 7330 // Shortcuts 7331 var cipher = this._cipher; 7332 var blockSize = cipher.blockSize; 7333 7334 // XOR and encrypt 7335 xorBlock.call(this, words, offset, blockSize); 7336 cipher.encryptBlock(words, offset); 7337 7338 // Remember this block to use with next block 7339 this._prevBlock = words.slice(offset, offset + blockSize); 7340 } 7341 }); 7342 7343 /** 7344 * CBC decryptor. 7345 */ 7346 CBC.Decryptor = CBC.extend({ 7347 /** 7348 * Processes the data block at offset. 7349 * 7350 * @param {Array} words The data words to operate on. 7351 * @param {number} offset The offset where the block starts. 7352 * 7353 * @example 7354 * 7355 * mode.processBlock(data.words, offset); 7356 */ 7357 processBlock: function (words, offset) { 7358 // Shortcuts 7359 var cipher = this._cipher; 7360 var blockSize = cipher.blockSize; 7361 7362 // Remember this block to use with next block 7363 var thisBlock = words.slice(offset, offset + blockSize); 7364 7365 // Decrypt and XOR 7366 cipher.decryptBlock(words, offset); 7367 xorBlock.call(this, words, offset, blockSize); 7368 7369 // This block becomes the previous block 7370 this._prevBlock = thisBlock; 7371 } 7372 }); 7373 7374 function xorBlock(words, offset, blockSize) { 7375 // Shortcut 7376 var iv = this._iv; 7377 7378 // Choose mixing block 7379 if (iv) { 7380 var block = iv; 7381 7382 // Remove IV for subsequent blocks 7383 this._iv = undefined; 7384 } else { 7385 var block = this._prevBlock; 7386 } 7387 7388 // XOR blocks 7389 for (var i = 0; i < blockSize; i++) { 7390 words[offset + i] ^= block[i]; 7391 } 7392 } 7393 7394 return CBC; 7395 }()); 7396 7397 /** 7398 * Padding namespace. 7399 */ 7400 var C_pad = C.pad = {}; 7401 7402 /** 7403 * PKCS #5/7 padding strategy. 7404 */ 7405 var Pkcs7 = C_pad.Pkcs7 = { 7406 /** 7407 * Pads data using the algorithm defined in PKCS #5/7. 7408 * 7409 * @param {WordArray} data The data to pad. 7410 * @param {number} blockSize The multiple that the data should be padded to. 7411 * 7412 * @static 7413 * 7414 * @example 7415 * 7416 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7417 */ 7418 pad: function (data, blockSize) { 7419 // Shortcut 7420 var blockSizeBytes = blockSize * 4; 7421 7422 // Count padding bytes 7423 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7424 7425 // Create padding word 7426 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7427 7428 // Create padding 7429 var paddingWords = []; 7430 for (var i = 0; i < nPaddingBytes; i += 4) { 7431 paddingWords.push(paddingWord); 7432 } 7433 var padding = WordArray.create(paddingWords, nPaddingBytes); 7434 7435 // Add padding 7436 data.concat(padding); 7437 }, 7438 7439 /** 7440 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7441 * 7442 * @param {WordArray} data The data to unpad. 7443 * 7444 * @static 7445 * 7446 * @example 7447 * 7448 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7449 */ 7450 unpad: function (data) { 7451 // Get number of padding bytes from last byte 7452 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7453 7454 // Remove padding 7455 data.sigBytes -= nPaddingBytes; 7456 } 7457 }; 7458 7459 /** 7460 * Abstract base block cipher template. 7461 * 7462 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7463 */ 7464 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7465 /** 7466 * Configuration options. 7467 * 7468 * @property {Mode} mode The block mode to use. Default: CBC 7469 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7470 */ 7471 cfg: Cipher.cfg.extend({ 7472 mode: CBC, 7473 padding: Pkcs7 7474 }), 7475 7476 reset: function () { 7477 // Reset cipher 7478 Cipher.reset.call(this); 7479 7480 // Shortcuts 7481 var cfg = this.cfg; 7482 var iv = cfg.iv; 7483 var mode = cfg.mode; 7484 7485 // Reset block mode 7486 if (this._xformMode == this._ENC_XFORM_MODE) { 7487 var modeCreator = mode.createEncryptor; 7488 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7489 var modeCreator = mode.createDecryptor; 7490 7491 // Keep at least one block in the buffer for unpadding 7492 this._minBufferSize = 1; 7493 } 7494 this._mode = modeCreator.call(mode, this, iv && iv.words); 7495 }, 7496 7497 _doProcessBlock: function (words, offset) { 7498 this._mode.processBlock(words, offset); 7499 }, 7500 7501 _doFinalize: function () { 7502 // Shortcut 7503 var padding = this.cfg.padding; 7504 7505 // Finalize 7506 if (this._xformMode == this._ENC_XFORM_MODE) { 7507 // Pad data 7508 padding.pad(this._data, this.blockSize); 7509 7510 // Process final blocks 7511 var finalProcessedBlocks = this._process(!!'flush'); 7512 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7513 // Process final blocks 7514 var finalProcessedBlocks = this._process(!!'flush'); 7515 7516 // Unpad data 7517 padding.unpad(finalProcessedBlocks); 7518 } 7519 7520 return finalProcessedBlocks; 7521 }, 7522 7523 blockSize: 128/32 7524 }); 7525 7526 /** 7527 * A collection of cipher parameters. 7528 * 7529 * @property {WordArray} ciphertext The raw ciphertext. 7530 * @property {WordArray} key The key to this ciphertext. 7531 * @property {WordArray} iv The IV used in the ciphering operation. 7532 * @property {WordArray} salt The salt used with a key derivation function. 7533 * @property {Cipher} algorithm The cipher algorithm. 7534 * @property {Mode} mode The block mode used in the ciphering operation. 7535 * @property {Padding} padding The padding scheme used in the ciphering operation. 7536 * @property {number} blockSize The block size of the cipher. 7537 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7538 */ 7539 var CipherParams = C_lib.CipherParams = Base.extend({ 7540 /** 7541 * Initializes a newly created cipher params object. 7542 * 7543 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7544 * 7545 * @example 7546 * 7547 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7548 * ciphertext: ciphertextWordArray, 7549 * key: keyWordArray, 7550 * iv: ivWordArray, 7551 * salt: saltWordArray, 7552 * algorithm: CryptoJS.algo.AES, 7553 * mode: CryptoJS.mode.CBC, 7554 * padding: CryptoJS.pad.PKCS7, 7555 * blockSize: 4, 7556 * formatter: CryptoJS.format.OpenSSL 7557 * }); 7558 */ 7559 init: function (cipherParams) { 7560 this.mixIn(cipherParams); 7561 }, 7562 7563 /** 7564 * Converts this cipher params object to a string. 7565 * 7566 * @param {Format} formatter (Optional) The formatting strategy to use. 7567 * 7568 * @return {string} The stringified cipher params. 7569 * 7570 * @throws Error If neither the formatter nor the default formatter is set. 7571 * 7572 * @example 7573 * 7574 * var string = cipherParams + ''; 7575 * var string = cipherParams.toString(); 7576 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7577 */ 7578 toString: function (formatter) { 7579 return (formatter || this.formatter).stringify(this); 7580 } 7581 }); 7582 7583 /** 7584 * Format namespace. 7585 */ 7586 var C_format = C.format = {}; 7587 7588 /** 7589 * OpenSSL formatting strategy. 7590 */ 7591 var OpenSSLFormatter = C_format.OpenSSL = { 7592 /** 7593 * Converts a cipher params object to an OpenSSL-compatible string. 7594 * 7595 * @param {CipherParams} cipherParams The cipher params object. 7596 * 7597 * @return {string} The OpenSSL-compatible string. 7598 * 7599 * @static 7600 * 7601 * @example 7602 * 7603 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7604 */ 7605 stringify: function (cipherParams) { 7606 // Shortcuts 7607 var ciphertext = cipherParams.ciphertext; 7608 var salt = cipherParams.salt; 7609 7610 // Format 7611 if (salt) { 7612 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7613 } else { 7614 var wordArray = ciphertext; 7615 } 7616 7617 return wordArray.toString(Base64); 7618 }, 7619 7620 /** 7621 * Converts an OpenSSL-compatible string to a cipher params object. 7622 * 7623 * @param {string} openSSLStr The OpenSSL-compatible string. 7624 * 7625 * @return {CipherParams} The cipher params object. 7626 * 7627 * @static 7628 * 7629 * @example 7630 * 7631 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7632 */ 7633 parse: function (openSSLStr) { 7634 // Parse base64 7635 var ciphertext = Base64.parse(openSSLStr); 7636 7637 // Shortcut 7638 var ciphertextWords = ciphertext.words; 7639 7640 // Test for salt 7641 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7642 // Extract salt 7643 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7644 7645 // Remove salt from ciphertext 7646 ciphertextWords.splice(0, 4); 7647 ciphertext.sigBytes -= 16; 7648 } 7649 7650 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7651 } 7652 }; 7653 7654 /** 7655 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7656 */ 7657 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7658 /** 7659 * Configuration options. 7660 * 7661 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7662 */ 7663 cfg: Base.extend({ 7664 format: OpenSSLFormatter 7665 }), 7666 7667 /** 7668 * Encrypts a message. 7669 * 7670 * @param {Cipher} cipher The cipher algorithm to use. 7671 * @param {WordArray|string} message The message to encrypt. 7672 * @param {WordArray} key The key. 7673 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7674 * 7675 * @return {CipherParams} A cipher params object. 7676 * 7677 * @static 7678 * 7679 * @example 7680 * 7681 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7682 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7683 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7684 */ 7685 encrypt: function (cipher, message, key, cfg) { 7686 // Apply config defaults 7687 cfg = this.cfg.extend(cfg); 7688 7689 // Encrypt 7690 var encryptor = cipher.createEncryptor(key, cfg); 7691 var ciphertext = encryptor.finalize(message); 7692 7693 // Shortcut 7694 var cipherCfg = encryptor.cfg; 7695 7696 // Create and return serializable cipher params 7697 return CipherParams.create({ 7698 ciphertext: ciphertext, 7699 key: key, 7700 iv: cipherCfg.iv, 7701 algorithm: cipher, 7702 mode: cipherCfg.mode, 7703 padding: cipherCfg.padding, 7704 blockSize: cipher.blockSize, 7705 formatter: cfg.format 7706 }); 7707 }, 7708 7709 /** 7710 * Decrypts serialized ciphertext. 7711 * 7712 * @param {Cipher} cipher The cipher algorithm to use. 7713 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7714 * @param {WordArray} key The key. 7715 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7716 * 7717 * @return {WordArray} The plaintext. 7718 * 7719 * @static 7720 * 7721 * @example 7722 * 7723 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7724 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7725 */ 7726 decrypt: function (cipher, ciphertext, key, cfg) { 7727 // Apply config defaults 7728 cfg = this.cfg.extend(cfg); 7729 7730 // Convert string to CipherParams 7731 ciphertext = this._parse(ciphertext, cfg.format); 7732 7733 // Decrypt 7734 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7735 7736 return plaintext; 7737 }, 7738 7739 /** 7740 * Converts serialized ciphertext to CipherParams, 7741 * else assumed CipherParams already and returns ciphertext unchanged. 7742 * 7743 * @param {CipherParams|string} ciphertext The ciphertext. 7744 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7745 * 7746 * @return {CipherParams} The unserialized ciphertext. 7747 * 7748 * @static 7749 * 7750 * @example 7751 * 7752 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7753 */ 7754 _parse: function (ciphertext, format) { 7755 if (typeof ciphertext == 'string') { 7756 return format.parse(ciphertext, this); 7757 } else { 7758 return ciphertext; 7759 } 7760 } 7761 }); 7762 7763 /** 7764 * Key derivation function namespace. 7765 */ 7766 var C_kdf = C.kdf = {}; 7767 7768 /** 7769 * OpenSSL key derivation function. 7770 */ 7771 var OpenSSLKdf = C_kdf.OpenSSL = { 7772 /** 7773 * Derives a key and IV from a password. 7774 * 7775 * @param {string} password The password to derive from. 7776 * @param {number} keySize The size in words of the key to generate. 7777 * @param {number} ivSize The size in words of the IV to generate. 7778 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7779 * 7780 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7781 * 7782 * @static 7783 * 7784 * @example 7785 * 7786 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7787 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7788 */ 7789 execute: function (password, keySize, ivSize, salt) { 7790 // Generate random salt 7791 if (!salt) { 7792 salt = WordArray.random(64/8); 7793 } 7794 7795 // Derive key and IV 7796 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 7797 7798 // Separate key and IV 7799 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7800 key.sigBytes = keySize * 4; 7801 7802 // Return params 7803 return CipherParams.create({ key: key, iv: iv, salt: salt }); 7804 } 7805 }; 7806 7807 /** 7808 * A serializable cipher wrapper that derives the key from a password, 7809 * and returns ciphertext as a serializable cipher params object. 7810 */ 7811 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7812 /** 7813 * Configuration options. 7814 * 7815 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7816 */ 7817 cfg: SerializableCipher.cfg.extend({ 7818 kdf: OpenSSLKdf 7819 }), 7820 7821 /** 7822 * Encrypts a message using a password. 7823 * 7824 * @param {Cipher} cipher The cipher algorithm to use. 7825 * @param {WordArray|string} message The message to encrypt. 7826 * @param {string} password The password. 7827 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7828 * 7829 * @return {CipherParams} A cipher params object. 7830 * 7831 * @static 7832 * 7833 * @example 7834 * 7835 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7836 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7837 */ 7838 encrypt: function (cipher, message, password, cfg) { 7839 // Apply config defaults 7840 cfg = this.cfg.extend(cfg); 7841 7842 // Derive key and other params 7843 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7844 7845 // Add IV to config 7846 cfg.iv = derivedParams.iv; 7847 7848 // Encrypt 7849 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7850 7851 // Mix in derived params 7852 ciphertext.mixIn(derivedParams); 7853 7854 return ciphertext; 7855 }, 7856 7857 /** 7858 * Decrypts serialized ciphertext using a password. 7859 * 7860 * @param {Cipher} cipher The cipher algorithm to use. 7861 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7862 * @param {string} password The password. 7863 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7864 * 7865 * @return {WordArray} The plaintext. 7866 * 7867 * @static 7868 * 7869 * @example 7870 * 7871 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 7872 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 7873 */ 7874 decrypt: function (cipher, ciphertext, password, cfg) { 7875 // Apply config defaults 7876 cfg = this.cfg.extend(cfg); 7877 7878 // Convert string to CipherParams 7879 ciphertext = this._parse(ciphertext, cfg.format); 7880 7881 // Derive key and other params 7882 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 7883 7884 // Add IV to config 7885 cfg.iv = derivedParams.iv; 7886 7887 // Decrypt 7888 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 7889 7890 return plaintext; 7891 } 7892 }); 7893 }()); 7894 7895 7896 })); 7897 },{"./core":53}],53:[function(require,module,exports){ 7898 ;(function (root, factory) { 7899 if (typeof exports === "object") { 7900 // CommonJS 7901 module.exports = exports = factory(); 7902 } 7903 else if (typeof define === "function" && define.amd) { 7904 // AMD 7905 define([], factory); 7906 } 7907 else { 7908 // Global (browser) 7909 root.CryptoJS = factory(); 7910 } 7911 }(this, function () { 7912 7913 /** 7914 * CryptoJS core components. 7915 */ 7916 var CryptoJS = CryptoJS || (function (Math, undefined) { 7917 /* 7918 * Local polyfil of Object.create 7919 */ 7920 var create = Object.create || (function () { 7921 function F() {}; 7922 7923 return function (obj) { 7924 var subtype; 7925 7926 F.prototype = obj; 7927 7928 subtype = new F(); 7929 7930 F.prototype = null; 7931 7932 return subtype; 7933 }; 7934 }()) 7935 7936 /** 7937 * CryptoJS namespace. 7938 */ 7939 var C = {}; 7940 7941 /** 7942 * Library namespace. 7943 */ 7944 var C_lib = C.lib = {}; 7945 7946 /** 7947 * Base object for prototypal inheritance. 7948 */ 7949 var Base = C_lib.Base = (function () { 7950 7951 7952 return { 7953 /** 7954 * Creates a new object that inherits from this object. 7955 * 7956 * @param {Object} overrides Properties to copy into the new object. 7957 * 7958 * @return {Object} The new object. 7959 * 7960 * @static 7961 * 7962 * @example 7963 * 7964 * var MyType = CryptoJS.lib.Base.extend({ 7965 * field: 'value', 7966 * 7967 * method: function () { 7968 * } 7969 * }); 7970 */ 7971 extend: function (overrides) { 7972 // Spawn 7973 var subtype = create(this); 7974 7975 // Augment 7976 if (overrides) { 7977 subtype.mixIn(overrides); 7978 } 7979 7980 // Create default initializer 7981 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 7982 subtype.init = function () { 7983 subtype.$super.init.apply(this, arguments); 7984 }; 7985 } 7986 7987 // Initializer's prototype is the subtype object 7988 subtype.init.prototype = subtype; 7989 7990 // Reference supertype 7991 subtype.$super = this; 7992 7993 return subtype; 7994 }, 7995 7996 /** 7997 * Extends this object and runs the init method. 7998 * Arguments to create() will be passed to init(). 7999 * 8000 * @return {Object} The new object. 8001 * 8002 * @static 8003 * 8004 * @example 8005 * 8006 * var instance = MyType.create(); 8007 */ 8008 create: function () { 8009 var instance = this.extend(); 8010 instance.init.apply(instance, arguments); 8011 8012 return instance; 8013 }, 8014 8015 /** 8016 * Initializes a newly created object. 8017 * Override this method to add some logic when your objects are created. 8018 * 8019 * @example 8020 * 8021 * var MyType = CryptoJS.lib.Base.extend({ 8022 * init: function () { 8023 * // ... 8024 * } 8025 * }); 8026 */ 8027 init: function () { 8028 }, 8029 8030 /** 8031 * Copies properties into this object. 8032 * 8033 * @param {Object} properties The properties to mix in. 8034 * 8035 * @example 8036 * 8037 * MyType.mixIn({ 8038 * field: 'value' 8039 * }); 8040 */ 8041 mixIn: function (properties) { 8042 for (var propertyName in properties) { 8043 if (properties.hasOwnProperty(propertyName)) { 8044 this[propertyName] = properties[propertyName]; 8045 } 8046 } 8047 8048 // IE won't copy toString using the loop above 8049 if (properties.hasOwnProperty('toString')) { 8050 this.toString = properties.toString; 8051 } 8052 }, 8053 8054 /** 8055 * Creates a copy of this object. 8056 * 8057 * @return {Object} The clone. 8058 * 8059 * @example 8060 * 8061 * var clone = instance.clone(); 8062 */ 8063 clone: function () { 8064 return this.init.prototype.extend(this); 8065 } 8066 }; 8067 }()); 8068 8069 /** 8070 * An array of 32-bit words. 8071 * 8072 * @property {Array} words The array of 32-bit words. 8073 * @property {number} sigBytes The number of significant bytes in this word array. 8074 */ 8075 var WordArray = C_lib.WordArray = Base.extend({ 8076 /** 8077 * Initializes a newly created word array. 8078 * 8079 * @param {Array} words (Optional) An array of 32-bit words. 8080 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8081 * 8082 * @example 8083 * 8084 * var wordArray = CryptoJS.lib.WordArray.create(); 8085 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8086 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8087 */ 8088 init: function (words, sigBytes) { 8089 words = this.words = words || []; 8090 8091 if (sigBytes != undefined) { 8092 this.sigBytes = sigBytes; 8093 } else { 8094 this.sigBytes = words.length * 4; 8095 } 8096 }, 8097 8098 /** 8099 * Converts this word array to a string. 8100 * 8101 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8102 * 8103 * @return {string} The stringified word array. 8104 * 8105 * @example 8106 * 8107 * var string = wordArray + ''; 8108 * var string = wordArray.toString(); 8109 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8110 */ 8111 toString: function (encoder) { 8112 return (encoder || Hex).stringify(this); 8113 }, 8114 8115 /** 8116 * Concatenates a word array to this word array. 8117 * 8118 * @param {WordArray} wordArray The word array to append. 8119 * 8120 * @return {WordArray} This word array. 8121 * 8122 * @example 8123 * 8124 * wordArray1.concat(wordArray2); 8125 */ 8126 concat: function (wordArray) { 8127 // Shortcuts 8128 var thisWords = this.words; 8129 var thatWords = wordArray.words; 8130 var thisSigBytes = this.sigBytes; 8131 var thatSigBytes = wordArray.sigBytes; 8132 8133 // Clamp excess bits 8134 this.clamp(); 8135 8136 // Concat 8137 if (thisSigBytes % 4) { 8138 // Copy one byte at a time 8139 for (var i = 0; i < thatSigBytes; i++) { 8140 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8141 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8142 } 8143 } else { 8144 // Copy one word at a time 8145 for (var i = 0; i < thatSigBytes; i += 4) { 8146 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8147 } 8148 } 8149 this.sigBytes += thatSigBytes; 8150 8151 // Chainable 8152 return this; 8153 }, 8154 8155 /** 8156 * Removes insignificant bits. 8157 * 8158 * @example 8159 * 8160 * wordArray.clamp(); 8161 */ 8162 clamp: function () { 8163 // Shortcuts 8164 var words = this.words; 8165 var sigBytes = this.sigBytes; 8166 8167 // Clamp 8168 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8169 words.length = Math.ceil(sigBytes / 4); 8170 }, 8171 8172 /** 8173 * Creates a copy of this word array. 8174 * 8175 * @return {WordArray} The clone. 8176 * 8177 * @example 8178 * 8179 * var clone = wordArray.clone(); 8180 */ 8181 clone: function () { 8182 var clone = Base.clone.call(this); 8183 clone.words = this.words.slice(0); 8184 8185 return clone; 8186 }, 8187 8188 /** 8189 * Creates a word array filled with random bytes. 8190 * 8191 * @param {number} nBytes The number of random bytes to generate. 8192 * 8193 * @return {WordArray} The random word array. 8194 * 8195 * @static 8196 * 8197 * @example 8198 * 8199 * var wordArray = CryptoJS.lib.WordArray.random(16); 8200 */ 8201 random: function (nBytes) { 8202 var words = []; 8203 8204 var r = (function (m_w) { 8205 var m_w = m_w; 8206 var m_z = 0x3ade68b1; 8207 var mask = 0xffffffff; 8208 8209 return function () { 8210 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8211 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8212 var result = ((m_z << 0x10) + m_w) & mask; 8213 result /= 0x100000000; 8214 result += 0.5; 8215 return result * (Math.random() > .5 ? 1 : -1); 8216 } 8217 }); 8218 8219 for (var i = 0, rcache; i < nBytes; i += 4) { 8220 var _r = r((rcache || Math.random()) * 0x100000000); 8221 8222 rcache = _r() * 0x3ade67b7; 8223 words.push((_r() * 0x100000000) | 0); 8224 } 8225 8226 return new WordArray.init(words, nBytes); 8227 } 8228 }); 8229 8230 /** 8231 * Encoder namespace. 8232 */ 8233 var C_enc = C.enc = {}; 8234 8235 /** 8236 * Hex encoding strategy. 8237 */ 8238 var Hex = C_enc.Hex = { 8239 /** 8240 * Converts a word array to a hex string. 8241 * 8242 * @param {WordArray} wordArray The word array. 8243 * 8244 * @return {string} The hex string. 8245 * 8246 * @static 8247 * 8248 * @example 8249 * 8250 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8251 */ 8252 stringify: function (wordArray) { 8253 // Shortcuts 8254 var words = wordArray.words; 8255 var sigBytes = wordArray.sigBytes; 8256 8257 // Convert 8258 var hexChars = []; 8259 for (var i = 0; i < sigBytes; i++) { 8260 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8261 hexChars.push((bite >>> 4).toString(16)); 8262 hexChars.push((bite & 0x0f).toString(16)); 8263 } 8264 8265 return hexChars.join(''); 8266 }, 8267 8268 /** 8269 * Converts a hex string to a word array. 8270 * 8271 * @param {string} hexStr The hex string. 8272 * 8273 * @return {WordArray} The word array. 8274 * 8275 * @static 8276 * 8277 * @example 8278 * 8279 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8280 */ 8281 parse: function (hexStr) { 8282 // Shortcut 8283 var hexStrLength = hexStr.length; 8284 8285 // Convert 8286 var words = []; 8287 for (var i = 0; i < hexStrLength; i += 2) { 8288 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8289 } 8290 8291 return new WordArray.init(words, hexStrLength / 2); 8292 } 8293 }; 8294 8295 /** 8296 * Latin1 encoding strategy. 8297 */ 8298 var Latin1 = C_enc.Latin1 = { 8299 /** 8300 * Converts a word array to a Latin1 string. 8301 * 8302 * @param {WordArray} wordArray The word array. 8303 * 8304 * @return {string} The Latin1 string. 8305 * 8306 * @static 8307 * 8308 * @example 8309 * 8310 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8311 */ 8312 stringify: function (wordArray) { 8313 // Shortcuts 8314 var words = wordArray.words; 8315 var sigBytes = wordArray.sigBytes; 8316 8317 // Convert 8318 var latin1Chars = []; 8319 for (var i = 0; i < sigBytes; i++) { 8320 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8321 latin1Chars.push(String.fromCharCode(bite)); 8322 } 8323 8324 return latin1Chars.join(''); 8325 }, 8326 8327 /** 8328 * Converts a Latin1 string to a word array. 8329 * 8330 * @param {string} latin1Str The Latin1 string. 8331 * 8332 * @return {WordArray} The word array. 8333 * 8334 * @static 8335 * 8336 * @example 8337 * 8338 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8339 */ 8340 parse: function (latin1Str) { 8341 // Shortcut 8342 var latin1StrLength = latin1Str.length; 8343 8344 // Convert 8345 var words = []; 8346 for (var i = 0; i < latin1StrLength; i++) { 8347 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8348 } 8349 8350 return new WordArray.init(words, latin1StrLength); 8351 } 8352 }; 8353 8354 /** 8355 * UTF-8 encoding strategy. 8356 */ 8357 var Utf8 = C_enc.Utf8 = { 8358 /** 8359 * Converts a word array to a UTF-8 string. 8360 * 8361 * @param {WordArray} wordArray The word array. 8362 * 8363 * @return {string} The UTF-8 string. 8364 * 8365 * @static 8366 * 8367 * @example 8368 * 8369 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8370 */ 8371 stringify: function (wordArray) { 8372 try { 8373 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8374 } catch (e) { 8375 throw new Error('Malformed UTF-8 data'); 8376 } 8377 }, 8378 8379 /** 8380 * Converts a UTF-8 string to a word array. 8381 * 8382 * @param {string} utf8Str The UTF-8 string. 8383 * 8384 * @return {WordArray} The word array. 8385 * 8386 * @static 8387 * 8388 * @example 8389 * 8390 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8391 */ 8392 parse: function (utf8Str) { 8393 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8394 } 8395 }; 8396 8397 /** 8398 * Abstract buffered block algorithm template. 8399 * 8400 * The property blockSize must be implemented in a concrete subtype. 8401 * 8402 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8403 */ 8404 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8405 /** 8406 * Resets this block algorithm's data buffer to its initial state. 8407 * 8408 * @example 8409 * 8410 * bufferedBlockAlgorithm.reset(); 8411 */ 8412 reset: function () { 8413 // Initial values 8414 this._data = new WordArray.init(); 8415 this._nDataBytes = 0; 8416 }, 8417 8418 /** 8419 * Adds new data to this block algorithm's buffer. 8420 * 8421 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8422 * 8423 * @example 8424 * 8425 * bufferedBlockAlgorithm._append('data'); 8426 * bufferedBlockAlgorithm._append(wordArray); 8427 */ 8428 _append: function (data) { 8429 // Convert string to WordArray, else assume WordArray already 8430 if (typeof data == 'string') { 8431 data = Utf8.parse(data); 8432 } 8433 8434 // Append 8435 this._data.concat(data); 8436 this._nDataBytes += data.sigBytes; 8437 }, 8438 8439 /** 8440 * Processes available data blocks. 8441 * 8442 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8443 * 8444 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8445 * 8446 * @return {WordArray} The processed data. 8447 * 8448 * @example 8449 * 8450 * var processedData = bufferedBlockAlgorithm._process(); 8451 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8452 */ 8453 _process: function (doFlush) { 8454 // Shortcuts 8455 var data = this._data; 8456 var dataWords = data.words; 8457 var dataSigBytes = data.sigBytes; 8458 var blockSize = this.blockSize; 8459 var blockSizeBytes = blockSize * 4; 8460 8461 // Count blocks ready 8462 var nBlocksReady = dataSigBytes / blockSizeBytes; 8463 if (doFlush) { 8464 // Round up to include partial blocks 8465 nBlocksReady = Math.ceil(nBlocksReady); 8466 } else { 8467 // Round down to include only full blocks, 8468 // less the number of blocks that must remain in the buffer 8469 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8470 } 8471 8472 // Count words ready 8473 var nWordsReady = nBlocksReady * blockSize; 8474 8475 // Count bytes ready 8476 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8477 8478 // Process blocks 8479 if (nWordsReady) { 8480 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8481 // Perform concrete-algorithm logic 8482 this._doProcessBlock(dataWords, offset); 8483 } 8484 8485 // Remove processed words 8486 var processedWords = dataWords.splice(0, nWordsReady); 8487 data.sigBytes -= nBytesReady; 8488 } 8489 8490 // Return processed words 8491 return new WordArray.init(processedWords, nBytesReady); 8492 }, 8493 8494 /** 8495 * Creates a copy of this object. 8496 * 8497 * @return {Object} The clone. 8498 * 8499 * @example 8500 * 8501 * var clone = bufferedBlockAlgorithm.clone(); 8502 */ 8503 clone: function () { 8504 var clone = Base.clone.call(this); 8505 clone._data = this._data.clone(); 8506 8507 return clone; 8508 }, 8509 8510 _minBufferSize: 0 8511 }); 8512 8513 /** 8514 * Abstract hasher template. 8515 * 8516 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8517 */ 8518 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8519 /** 8520 * Configuration options. 8521 */ 8522 cfg: Base.extend(), 8523 8524 /** 8525 * Initializes a newly created hasher. 8526 * 8527 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8528 * 8529 * @example 8530 * 8531 * var hasher = CryptoJS.algo.SHA256.create(); 8532 */ 8533 init: function (cfg) { 8534 // Apply config defaults 8535 this.cfg = this.cfg.extend(cfg); 8536 8537 // Set initial values 8538 this.reset(); 8539 }, 8540 8541 /** 8542 * Resets this hasher to its initial state. 8543 * 8544 * @example 8545 * 8546 * hasher.reset(); 8547 */ 8548 reset: function () { 8549 // Reset data buffer 8550 BufferedBlockAlgorithm.reset.call(this); 8551 8552 // Perform concrete-hasher logic 8553 this._doReset(); 8554 }, 8555 8556 /** 8557 * Updates this hasher with a message. 8558 * 8559 * @param {WordArray|string} messageUpdate The message to append. 8560 * 8561 * @return {Hasher} This hasher. 8562 * 8563 * @example 8564 * 8565 * hasher.update('message'); 8566 * hasher.update(wordArray); 8567 */ 8568 update: function (messageUpdate) { 8569 // Append 8570 this._append(messageUpdate); 8571 8572 // Update the hash 8573 this._process(); 8574 8575 // Chainable 8576 return this; 8577 }, 8578 8579 /** 8580 * Finalizes the hash computation. 8581 * Note that the finalize operation is effectively a destructive, read-once operation. 8582 * 8583 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8584 * 8585 * @return {WordArray} The hash. 8586 * 8587 * @example 8588 * 8589 * var hash = hasher.finalize(); 8590 * var hash = hasher.finalize('message'); 8591 * var hash = hasher.finalize(wordArray); 8592 */ 8593 finalize: function (messageUpdate) { 8594 // Final message update 8595 if (messageUpdate) { 8596 this._append(messageUpdate); 8597 } 8598 8599 // Perform concrete-hasher logic 8600 var hash = this._doFinalize(); 8601 8602 return hash; 8603 }, 8604 8605 blockSize: 512/32, 8606 8607 /** 8608 * Creates a shortcut function to a hasher's object interface. 8609 * 8610 * @param {Hasher} hasher The hasher to create a helper for. 8611 * 8612 * @return {Function} The shortcut function. 8613 * 8614 * @static 8615 * 8616 * @example 8617 * 8618 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8619 */ 8620 _createHelper: function (hasher) { 8621 return function (message, cfg) { 8622 return new hasher.init(cfg).finalize(message); 8623 }; 8624 }, 8625 8626 /** 8627 * Creates a shortcut function to the HMAC's object interface. 8628 * 8629 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8630 * 8631 * @return {Function} The shortcut function. 8632 * 8633 * @static 8634 * 8635 * @example 8636 * 8637 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8638 */ 8639 _createHmacHelper: function (hasher) { 8640 return function (message, key) { 8641 return new C_algo.HMAC.init(hasher, key).finalize(message); 8642 }; 8643 } 8644 }); 8645 8646 /** 8647 * Algorithm namespace. 8648 */ 8649 var C_algo = C.algo = {}; 8650 8651 return C; 8652 }(Math)); 8653 8654 8655 return CryptoJS; 8656 8657 })); 8658 },{}],54:[function(require,module,exports){ 8659 ;(function (root, factory) { 8660 if (typeof exports === "object") { 8661 // CommonJS 8662 module.exports = exports = factory(require("./core")); 8663 } 8664 else if (typeof define === "function" && define.amd) { 8665 // AMD 8666 define(["./core"], factory); 8667 } 8668 else { 8669 // Global (browser) 8670 factory(root.CryptoJS); 8671 } 8672 }(this, function (CryptoJS) { 8673 8674 (function () { 8675 // Shortcuts 8676 var C = CryptoJS; 8677 var C_lib = C.lib; 8678 var WordArray = C_lib.WordArray; 8679 var C_enc = C.enc; 8680 8681 /** 8682 * Base64 encoding strategy. 8683 */ 8684 var Base64 = C_enc.Base64 = { 8685 /** 8686 * Converts a word array to a Base64 string. 8687 * 8688 * @param {WordArray} wordArray The word array. 8689 * 8690 * @return {string} The Base64 string. 8691 * 8692 * @static 8693 * 8694 * @example 8695 * 8696 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8697 */ 8698 stringify: function (wordArray) { 8699 // Shortcuts 8700 var words = wordArray.words; 8701 var sigBytes = wordArray.sigBytes; 8702 var map = this._map; 8703 8704 // Clamp excess bits 8705 wordArray.clamp(); 8706 8707 // Convert 8708 var base64Chars = []; 8709 for (var i = 0; i < sigBytes; i += 3) { 8710 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8711 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8712 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8713 8714 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8715 8716 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8717 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8718 } 8719 } 8720 8721 // Add padding 8722 var paddingChar = map.charAt(64); 8723 if (paddingChar) { 8724 while (base64Chars.length % 4) { 8725 base64Chars.push(paddingChar); 8726 } 8727 } 8728 8729 return base64Chars.join(''); 8730 }, 8731 8732 /** 8733 * Converts a Base64 string to a word array. 8734 * 8735 * @param {string} base64Str The Base64 string. 8736 * 8737 * @return {WordArray} The word array. 8738 * 8739 * @static 8740 * 8741 * @example 8742 * 8743 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8744 */ 8745 parse: function (base64Str) { 8746 // Shortcuts 8747 var base64StrLength = base64Str.length; 8748 var map = this._map; 8749 var reverseMap = this._reverseMap; 8750 8751 if (!reverseMap) { 8752 reverseMap = this._reverseMap = []; 8753 for (var j = 0; j < map.length; j++) { 8754 reverseMap[map.charCodeAt(j)] = j; 8755 } 8756 } 8757 8758 // Ignore padding 8759 var paddingChar = map.charAt(64); 8760 if (paddingChar) { 8761 var paddingIndex = base64Str.indexOf(paddingChar); 8762 if (paddingIndex !== -1) { 8763 base64StrLength = paddingIndex; 8764 } 8765 } 8766 8767 // Convert 8768 return parseLoop(base64Str, base64StrLength, reverseMap); 8769 8770 }, 8771 8772 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8773 }; 8774 8775 function parseLoop(base64Str, base64StrLength, reverseMap) { 8776 var words = []; 8777 var nBytes = 0; 8778 for (var i = 0; i < base64StrLength; i++) { 8779 if (i % 4) { 8780 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8781 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8782 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8783 nBytes++; 8784 } 8785 } 8786 return WordArray.create(words, nBytes); 8787 } 8788 }()); 8789 8790 8791 return CryptoJS.enc.Base64; 8792 8793 })); 8794 },{"./core":53}],55:[function(require,module,exports){ 8795 ;(function (root, factory) { 8796 if (typeof exports === "object") { 8797 // CommonJS 8798 module.exports = exports = factory(require("./core")); 8799 } 8800 else if (typeof define === "function" && define.amd) { 8801 // AMD 8802 define(["./core"], factory); 8803 } 8804 else { 8805 // Global (browser) 8806 factory(root.CryptoJS); 8807 } 8808 }(this, function (CryptoJS) { 8809 8810 (function () { 8811 // Shortcuts 8812 var C = CryptoJS; 8813 var C_lib = C.lib; 8814 var WordArray = C_lib.WordArray; 8815 var C_enc = C.enc; 8816 8817 /** 8818 * UTF-16 BE encoding strategy. 8819 */ 8820 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8821 /** 8822 * Converts a word array to a UTF-16 BE string. 8823 * 8824 * @param {WordArray} wordArray The word array. 8825 * 8826 * @return {string} The UTF-16 BE string. 8827 * 8828 * @static 8829 * 8830 * @example 8831 * 8832 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8833 */ 8834 stringify: function (wordArray) { 8835 // Shortcuts 8836 var words = wordArray.words; 8837 var sigBytes = wordArray.sigBytes; 8838 8839 // Convert 8840 var utf16Chars = []; 8841 for (var i = 0; i < sigBytes; i += 2) { 8842 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8843 utf16Chars.push(String.fromCharCode(codePoint)); 8844 } 8845 8846 return utf16Chars.join(''); 8847 }, 8848 8849 /** 8850 * Converts a UTF-16 BE string to a word array. 8851 * 8852 * @param {string} utf16Str The UTF-16 BE string. 8853 * 8854 * @return {WordArray} The word array. 8855 * 8856 * @static 8857 * 8858 * @example 8859 * 8860 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8861 */ 8862 parse: function (utf16Str) { 8863 // Shortcut 8864 var utf16StrLength = utf16Str.length; 8865 8866 // Convert 8867 var words = []; 8868 for (var i = 0; i < utf16StrLength; i++) { 8869 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 8870 } 8871 8872 return WordArray.create(words, utf16StrLength * 2); 8873 } 8874 }; 8875 8876 /** 8877 * UTF-16 LE encoding strategy. 8878 */ 8879 C_enc.Utf16LE = { 8880 /** 8881 * Converts a word array to a UTF-16 LE string. 8882 * 8883 * @param {WordArray} wordArray The word array. 8884 * 8885 * @return {string} The UTF-16 LE string. 8886 * 8887 * @static 8888 * 8889 * @example 8890 * 8891 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 8892 */ 8893 stringify: function (wordArray) { 8894 // Shortcuts 8895 var words = wordArray.words; 8896 var sigBytes = wordArray.sigBytes; 8897 8898 // Convert 8899 var utf16Chars = []; 8900 for (var i = 0; i < sigBytes; i += 2) { 8901 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 8902 utf16Chars.push(String.fromCharCode(codePoint)); 8903 } 8904 8905 return utf16Chars.join(''); 8906 }, 8907 8908 /** 8909 * Converts a UTF-16 LE string to a word array. 8910 * 8911 * @param {string} utf16Str The UTF-16 LE string. 8912 * 8913 * @return {WordArray} The word array. 8914 * 8915 * @static 8916 * 8917 * @example 8918 * 8919 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 8920 */ 8921 parse: function (utf16Str) { 8922 // Shortcut 8923 var utf16StrLength = utf16Str.length; 8924 8925 // Convert 8926 var words = []; 8927 for (var i = 0; i < utf16StrLength; i++) { 8928 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 8929 } 8930 8931 return WordArray.create(words, utf16StrLength * 2); 8932 } 8933 }; 8934 8935 function swapEndian(word) { 8936 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 8937 } 8938 }()); 8939 8940 8941 return CryptoJS.enc.Utf16; 8942 8943 })); 8944 },{"./core":53}],56:[function(require,module,exports){ 8945 ;(function (root, factory, undef) { 8946 if (typeof exports === "object") { 8947 // CommonJS 8948 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 8949 } 8950 else if (typeof define === "function" && define.amd) { 8951 // AMD 8952 define(["./core", "./sha1", "./hmac"], factory); 8953 } 8954 else { 8955 // Global (browser) 8956 factory(root.CryptoJS); 8957 } 8958 }(this, function (CryptoJS) { 8959 8960 (function () { 8961 // Shortcuts 8962 var C = CryptoJS; 8963 var C_lib = C.lib; 8964 var Base = C_lib.Base; 8965 var WordArray = C_lib.WordArray; 8966 var C_algo = C.algo; 8967 var MD5 = C_algo.MD5; 8968 8969 /** 8970 * This key derivation function is meant to conform with EVP_BytesToKey. 8971 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 8972 */ 8973 var EvpKDF = C_algo.EvpKDF = Base.extend({ 8974 /** 8975 * Configuration options. 8976 * 8977 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 8978 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 8979 * @property {number} iterations The number of iterations to perform. Default: 1 8980 */ 8981 cfg: Base.extend({ 8982 keySize: 128/32, 8983 hasher: MD5, 8984 iterations: 1 8985 }), 8986 8987 /** 8988 * Initializes a newly created key derivation function. 8989 * 8990 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 8991 * 8992 * @example 8993 * 8994 * var kdf = CryptoJS.algo.EvpKDF.create(); 8995 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 8996 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 8997 */ 8998 init: function (cfg) { 8999 this.cfg = this.cfg.extend(cfg); 9000 }, 9001 9002 /** 9003 * Derives a key from a password. 9004 * 9005 * @param {WordArray|string} password The password. 9006 * @param {WordArray|string} salt A salt. 9007 * 9008 * @return {WordArray} The derived key. 9009 * 9010 * @example 9011 * 9012 * var key = kdf.compute(password, salt); 9013 */ 9014 compute: function (password, salt) { 9015 // Shortcut 9016 var cfg = this.cfg; 9017 9018 // Init hasher 9019 var hasher = cfg.hasher.create(); 9020 9021 // Initial values 9022 var derivedKey = WordArray.create(); 9023 9024 // Shortcuts 9025 var derivedKeyWords = derivedKey.words; 9026 var keySize = cfg.keySize; 9027 var iterations = cfg.iterations; 9028 9029 // Generate key 9030 while (derivedKeyWords.length < keySize) { 9031 if (block) { 9032 hasher.update(block); 9033 } 9034 var block = hasher.update(password).finalize(salt); 9035 hasher.reset(); 9036 9037 // Iterations 9038 for (var i = 1; i < iterations; i++) { 9039 block = hasher.finalize(block); 9040 hasher.reset(); 9041 } 9042 9043 derivedKey.concat(block); 9044 } 9045 derivedKey.sigBytes = keySize * 4; 9046 9047 return derivedKey; 9048 } 9049 }); 9050 9051 /** 9052 * Derives a key from a password. 9053 * 9054 * @param {WordArray|string} password The password. 9055 * @param {WordArray|string} salt A salt. 9056 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9057 * 9058 * @return {WordArray} The derived key. 9059 * 9060 * @static 9061 * 9062 * @example 9063 * 9064 * var key = CryptoJS.EvpKDF(password, salt); 9065 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9066 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9067 */ 9068 C.EvpKDF = function (password, salt, cfg) { 9069 return EvpKDF.create(cfg).compute(password, salt); 9070 }; 9071 }()); 9072 9073 9074 return CryptoJS.EvpKDF; 9075 9076 })); 9077 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 9078 ;(function (root, factory, undef) { 9079 if (typeof exports === "object") { 9080 // CommonJS 9081 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9082 } 9083 else if (typeof define === "function" && define.amd) { 9084 // AMD 9085 define(["./core", "./cipher-core"], factory); 9086 } 9087 else { 9088 // Global (browser) 9089 factory(root.CryptoJS); 9090 } 9091 }(this, function (CryptoJS) { 9092 9093 (function (undefined) { 9094 // Shortcuts 9095 var C = CryptoJS; 9096 var C_lib = C.lib; 9097 var CipherParams = C_lib.CipherParams; 9098 var C_enc = C.enc; 9099 var Hex = C_enc.Hex; 9100 var C_format = C.format; 9101 9102 var HexFormatter = C_format.Hex = { 9103 /** 9104 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9105 * 9106 * @param {CipherParams} cipherParams The cipher params object. 9107 * 9108 * @return {string} The hexadecimally encoded string. 9109 * 9110 * @static 9111 * 9112 * @example 9113 * 9114 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9115 */ 9116 stringify: function (cipherParams) { 9117 return cipherParams.ciphertext.toString(Hex); 9118 }, 9119 9120 /** 9121 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9122 * 9123 * @param {string} input The hexadecimally encoded string. 9124 * 9125 * @return {CipherParams} The cipher params object. 9126 * 9127 * @static 9128 * 9129 * @example 9130 * 9131 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9132 */ 9133 parse: function (input) { 9134 var ciphertext = Hex.parse(input); 9135 return CipherParams.create({ ciphertext: ciphertext }); 9136 } 9137 }; 9138 }()); 9139 9140 9141 return CryptoJS.format.Hex; 9142 9143 })); 9144 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 9145 ;(function (root, factory) { 9146 if (typeof exports === "object") { 9147 // CommonJS 9148 module.exports = exports = factory(require("./core")); 9149 } 9150 else if (typeof define === "function" && define.amd) { 9151 // AMD 9152 define(["./core"], factory); 9153 } 9154 else { 9155 // Global (browser) 9156 factory(root.CryptoJS); 9157 } 9158 }(this, function (CryptoJS) { 9159 9160 (function () { 9161 // Shortcuts 9162 var C = CryptoJS; 9163 var C_lib = C.lib; 9164 var Base = C_lib.Base; 9165 var C_enc = C.enc; 9166 var Utf8 = C_enc.Utf8; 9167 var C_algo = C.algo; 9168 9169 /** 9170 * HMAC algorithm. 9171 */ 9172 var HMAC = C_algo.HMAC = Base.extend({ 9173 /** 9174 * Initializes a newly created HMAC. 9175 * 9176 * @param {Hasher} hasher The hash algorithm to use. 9177 * @param {WordArray|string} key The secret key. 9178 * 9179 * @example 9180 * 9181 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9182 */ 9183 init: function (hasher, key) { 9184 // Init hasher 9185 hasher = this._hasher = new hasher.init(); 9186 9187 // Convert string to WordArray, else assume WordArray already 9188 if (typeof key == 'string') { 9189 key = Utf8.parse(key); 9190 } 9191 9192 // Shortcuts 9193 var hasherBlockSize = hasher.blockSize; 9194 var hasherBlockSizeBytes = hasherBlockSize * 4; 9195 9196 // Allow arbitrary length keys 9197 if (key.sigBytes > hasherBlockSizeBytes) { 9198 key = hasher.finalize(key); 9199 } 9200 9201 // Clamp excess bits 9202 key.clamp(); 9203 9204 // Clone key for inner and outer pads 9205 var oKey = this._oKey = key.clone(); 9206 var iKey = this._iKey = key.clone(); 9207 9208 // Shortcuts 9209 var oKeyWords = oKey.words; 9210 var iKeyWords = iKey.words; 9211 9212 // XOR keys with pad constants 9213 for (var i = 0; i < hasherBlockSize; i++) { 9214 oKeyWords[i] ^= 0x5c5c5c5c; 9215 iKeyWords[i] ^= 0x36363636; 9216 } 9217 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9218 9219 // Set initial values 9220 this.reset(); 9221 }, 9222 9223 /** 9224 * Resets this HMAC to its initial state. 9225 * 9226 * @example 9227 * 9228 * hmacHasher.reset(); 9229 */ 9230 reset: function () { 9231 // Shortcut 9232 var hasher = this._hasher; 9233 9234 // Reset 9235 hasher.reset(); 9236 hasher.update(this._iKey); 9237 }, 9238 9239 /** 9240 * Updates this HMAC with a message. 9241 * 9242 * @param {WordArray|string} messageUpdate The message to append. 9243 * 9244 * @return {HMAC} This HMAC instance. 9245 * 9246 * @example 9247 * 9248 * hmacHasher.update('message'); 9249 * hmacHasher.update(wordArray); 9250 */ 9251 update: function (messageUpdate) { 9252 this._hasher.update(messageUpdate); 9253 9254 // Chainable 9255 return this; 9256 }, 9257 9258 /** 9259 * Finalizes the HMAC computation. 9260 * Note that the finalize operation is effectively a destructive, read-once operation. 9261 * 9262 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9263 * 9264 * @return {WordArray} The HMAC. 9265 * 9266 * @example 9267 * 9268 * var hmac = hmacHasher.finalize(); 9269 * var hmac = hmacHasher.finalize('message'); 9270 * var hmac = hmacHasher.finalize(wordArray); 9271 */ 9272 finalize: function (messageUpdate) { 9273 // Shortcut 9274 var hasher = this._hasher; 9275 9276 // Compute HMAC 9277 var innerHash = hasher.finalize(messageUpdate); 9278 hasher.reset(); 9279 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9280 9281 return hmac; 9282 } 9283 }); 9284 }()); 9285 9286 9287 })); 9288 },{"./core":53}],59:[function(require,module,exports){ 9289 ;(function (root, factory, undef) { 9290 if (typeof exports === "object") { 9291 // CommonJS 9292 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")); 9293 } 9294 else if (typeof define === "function" && define.amd) { 9295 // AMD 9296 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); 9297 } 9298 else { 9299 // Global (browser) 9300 root.CryptoJS = factory(root.CryptoJS); 9301 } 9302 }(this, function (CryptoJS) { 9303 9304 return CryptoJS; 9305 9306 })); 9307 },{"./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){ 9308 ;(function (root, factory) { 9309 if (typeof exports === "object") { 9310 // CommonJS 9311 module.exports = exports = factory(require("./core")); 9312 } 9313 else if (typeof define === "function" && define.amd) { 9314 // AMD 9315 define(["./core"], factory); 9316 } 9317 else { 9318 // Global (browser) 9319 factory(root.CryptoJS); 9320 } 9321 }(this, function (CryptoJS) { 9322 9323 (function () { 9324 // Check if typed arrays are supported 9325 if (typeof ArrayBuffer != 'function') { 9326 return; 9327 } 9328 9329 // Shortcuts 9330 var C = CryptoJS; 9331 var C_lib = C.lib; 9332 var WordArray = C_lib.WordArray; 9333 9334 // Reference original init 9335 var superInit = WordArray.init; 9336 9337 // Augment WordArray.init to handle typed arrays 9338 var subInit = WordArray.init = function (typedArray) { 9339 // Convert buffers to uint8 9340 if (typedArray instanceof ArrayBuffer) { 9341 typedArray = new Uint8Array(typedArray); 9342 } 9343 9344 // Convert other array views to uint8 9345 if ( 9346 typedArray instanceof Int8Array || 9347 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9348 typedArray instanceof Int16Array || 9349 typedArray instanceof Uint16Array || 9350 typedArray instanceof Int32Array || 9351 typedArray instanceof Uint32Array || 9352 typedArray instanceof Float32Array || 9353 typedArray instanceof Float64Array 9354 ) { 9355 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9356 } 9357 9358 // Handle Uint8Array 9359 if (typedArray instanceof Uint8Array) { 9360 // Shortcut 9361 var typedArrayByteLength = typedArray.byteLength; 9362 9363 // Extract bytes 9364 var words = []; 9365 for (var i = 0; i < typedArrayByteLength; i++) { 9366 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9367 } 9368 9369 // Initialize this word array 9370 superInit.call(this, words, typedArrayByteLength); 9371 } else { 9372 // Else call normal init 9373 superInit.apply(this, arguments); 9374 } 9375 }; 9376 9377 subInit.prototype = WordArray; 9378 }()); 9379 9380 9381 return CryptoJS.lib.WordArray; 9382 9383 })); 9384 },{"./core":53}],61:[function(require,module,exports){ 9385 ;(function (root, factory) { 9386 if (typeof exports === "object") { 9387 // CommonJS 9388 module.exports = exports = factory(require("./core")); 9389 } 9390 else if (typeof define === "function" && define.amd) { 9391 // AMD 9392 define(["./core"], factory); 9393 } 9394 else { 9395 // Global (browser) 9396 factory(root.CryptoJS); 9397 } 9398 }(this, function (CryptoJS) { 9399 9400 (function (Math) { 9401 // Shortcuts 9402 var C = CryptoJS; 9403 var C_lib = C.lib; 9404 var WordArray = C_lib.WordArray; 9405 var Hasher = C_lib.Hasher; 9406 var C_algo = C.algo; 9407 9408 // Constants table 9409 var T = []; 9410 9411 // Compute constants 9412 (function () { 9413 for (var i = 0; i < 64; i++) { 9414 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9415 } 9416 }()); 9417 9418 /** 9419 * MD5 hash algorithm. 9420 */ 9421 var MD5 = C_algo.MD5 = Hasher.extend({ 9422 _doReset: function () { 9423 this._hash = new WordArray.init([ 9424 0x67452301, 0xefcdab89, 9425 0x98badcfe, 0x10325476 9426 ]); 9427 }, 9428 9429 _doProcessBlock: function (M, offset) { 9430 // Swap endian 9431 for (var i = 0; i < 16; i++) { 9432 // Shortcuts 9433 var offset_i = offset + i; 9434 var M_offset_i = M[offset_i]; 9435 9436 M[offset_i] = ( 9437 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9438 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9439 ); 9440 } 9441 9442 // Shortcuts 9443 var H = this._hash.words; 9444 9445 var M_offset_0 = M[offset + 0]; 9446 var M_offset_1 = M[offset + 1]; 9447 var M_offset_2 = M[offset + 2]; 9448 var M_offset_3 = M[offset + 3]; 9449 var M_offset_4 = M[offset + 4]; 9450 var M_offset_5 = M[offset + 5]; 9451 var M_offset_6 = M[offset + 6]; 9452 var M_offset_7 = M[offset + 7]; 9453 var M_offset_8 = M[offset + 8]; 9454 var M_offset_9 = M[offset + 9]; 9455 var M_offset_10 = M[offset + 10]; 9456 var M_offset_11 = M[offset + 11]; 9457 var M_offset_12 = M[offset + 12]; 9458 var M_offset_13 = M[offset + 13]; 9459 var M_offset_14 = M[offset + 14]; 9460 var M_offset_15 = M[offset + 15]; 9461 9462 // Working varialbes 9463 var a = H[0]; 9464 var b = H[1]; 9465 var c = H[2]; 9466 var d = H[3]; 9467 9468 // Computation 9469 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9470 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9471 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9472 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9473 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9474 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9475 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9476 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9477 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9478 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9479 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9480 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9481 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9482 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9483 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9484 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9485 9486 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9487 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9488 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9489 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9490 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9491 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9492 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9493 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9494 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9495 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9496 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9497 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9498 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9499 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9500 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9501 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9502 9503 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9504 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9505 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9506 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9507 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9508 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9509 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9510 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9511 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9512 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9513 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9514 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9515 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9516 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9517 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9518 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9519 9520 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9521 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9522 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9523 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9524 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9525 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9526 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9527 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9528 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9529 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9530 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9531 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9532 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9533 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9534 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9535 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9536 9537 // Intermediate hash value 9538 H[0] = (H[0] + a) | 0; 9539 H[1] = (H[1] + b) | 0; 9540 H[2] = (H[2] + c) | 0; 9541 H[3] = (H[3] + d) | 0; 9542 }, 9543 9544 _doFinalize: function () { 9545 // Shortcuts 9546 var data = this._data; 9547 var dataWords = data.words; 9548 9549 var nBitsTotal = this._nDataBytes * 8; 9550 var nBitsLeft = data.sigBytes * 8; 9551 9552 // Add padding 9553 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9554 9555 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9556 var nBitsTotalL = nBitsTotal; 9557 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9558 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9559 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9560 ); 9561 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9562 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9563 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9564 ); 9565 9566 data.sigBytes = (dataWords.length + 1) * 4; 9567 9568 // Hash final blocks 9569 this._process(); 9570 9571 // Shortcuts 9572 var hash = this._hash; 9573 var H = hash.words; 9574 9575 // Swap endian 9576 for (var i = 0; i < 4; i++) { 9577 // Shortcut 9578 var H_i = H[i]; 9579 9580 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9581 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9582 } 9583 9584 // Return final computed hash 9585 return hash; 9586 }, 9587 9588 clone: function () { 9589 var clone = Hasher.clone.call(this); 9590 clone._hash = this._hash.clone(); 9591 9592 return clone; 9593 } 9594 }); 9595 9596 function FF(a, b, c, d, x, s, t) { 9597 var n = a + ((b & c) | (~b & d)) + x + t; 9598 return ((n << s) | (n >>> (32 - s))) + b; 9599 } 9600 9601 function GG(a, b, c, d, x, s, t) { 9602 var n = a + ((b & d) | (c & ~d)) + x + t; 9603 return ((n << s) | (n >>> (32 - s))) + b; 9604 } 9605 9606 function HH(a, b, c, d, x, s, t) { 9607 var n = a + (b ^ c ^ d) + x + t; 9608 return ((n << s) | (n >>> (32 - s))) + b; 9609 } 9610 9611 function II(a, b, c, d, x, s, t) { 9612 var n = a + (c ^ (b | ~d)) + x + t; 9613 return ((n << s) | (n >>> (32 - s))) + b; 9614 } 9615 9616 /** 9617 * Shortcut function to the hasher's object interface. 9618 * 9619 * @param {WordArray|string} message The message to hash. 9620 * 9621 * @return {WordArray} The hash. 9622 * 9623 * @static 9624 * 9625 * @example 9626 * 9627 * var hash = CryptoJS.MD5('message'); 9628 * var hash = CryptoJS.MD5(wordArray); 9629 */ 9630 C.MD5 = Hasher._createHelper(MD5); 9631 9632 /** 9633 * Shortcut function to the HMAC's object interface. 9634 * 9635 * @param {WordArray|string} message The message to hash. 9636 * @param {WordArray|string} key The secret key. 9637 * 9638 * @return {WordArray} The HMAC. 9639 * 9640 * @static 9641 * 9642 * @example 9643 * 9644 * var hmac = CryptoJS.HmacMD5(message, key); 9645 */ 9646 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9647 }(Math)); 9648 9649 9650 return CryptoJS.MD5; 9651 9652 })); 9653 },{"./core":53}],62:[function(require,module,exports){ 9654 ;(function (root, factory, undef) { 9655 if (typeof exports === "object") { 9656 // CommonJS 9657 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9658 } 9659 else if (typeof define === "function" && define.amd) { 9660 // AMD 9661 define(["./core", "./cipher-core"], factory); 9662 } 9663 else { 9664 // Global (browser) 9665 factory(root.CryptoJS); 9666 } 9667 }(this, function (CryptoJS) { 9668 9669 /** 9670 * Cipher Feedback block mode. 9671 */ 9672 CryptoJS.mode.CFB = (function () { 9673 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9674 9675 CFB.Encryptor = CFB.extend({ 9676 processBlock: function (words, offset) { 9677 // Shortcuts 9678 var cipher = this._cipher; 9679 var blockSize = cipher.blockSize; 9680 9681 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9682 9683 // Remember this block to use with next block 9684 this._prevBlock = words.slice(offset, offset + blockSize); 9685 } 9686 }); 9687 9688 CFB.Decryptor = CFB.extend({ 9689 processBlock: function (words, offset) { 9690 // Shortcuts 9691 var cipher = this._cipher; 9692 var blockSize = cipher.blockSize; 9693 9694 // Remember this block to use with next block 9695 var thisBlock = words.slice(offset, offset + blockSize); 9696 9697 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9698 9699 // This block becomes the previous block 9700 this._prevBlock = thisBlock; 9701 } 9702 }); 9703 9704 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9705 // Shortcut 9706 var iv = this._iv; 9707 9708 // Generate keystream 9709 if (iv) { 9710 var keystream = iv.slice(0); 9711 9712 // Remove IV for subsequent blocks 9713 this._iv = undefined; 9714 } else { 9715 var keystream = this._prevBlock; 9716 } 9717 cipher.encryptBlock(keystream, 0); 9718 9719 // Encrypt 9720 for (var i = 0; i < blockSize; i++) { 9721 words[offset + i] ^= keystream[i]; 9722 } 9723 } 9724 9725 return CFB; 9726 }()); 9727 9728 9729 return CryptoJS.mode.CFB; 9730 9731 })); 9732 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 9733 ;(function (root, factory, undef) { 9734 if (typeof exports === "object") { 9735 // CommonJS 9736 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9737 } 9738 else if (typeof define === "function" && define.amd) { 9739 // AMD 9740 define(["./core", "./cipher-core"], factory); 9741 } 9742 else { 9743 // Global (browser) 9744 factory(root.CryptoJS); 9745 } 9746 }(this, function (CryptoJS) { 9747 9748 /** @preserve 9749 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9750 * derived from CryptoJS.mode.CTR 9751 * Jan Hruby jhruby.web@gmail.com 9752 */ 9753 CryptoJS.mode.CTRGladman = (function () { 9754 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9755 9756 function incWord(word) 9757 { 9758 if (((word >> 24) & 0xff) === 0xff) { //overflow 9759 var b1 = (word >> 16)&0xff; 9760 var b2 = (word >> 8)&0xff; 9761 var b3 = word & 0xff; 9762 9763 if (b1 === 0xff) // overflow b1 9764 { 9765 b1 = 0; 9766 if (b2 === 0xff) 9767 { 9768 b2 = 0; 9769 if (b3 === 0xff) 9770 { 9771 b3 = 0; 9772 } 9773 else 9774 { 9775 ++b3; 9776 } 9777 } 9778 else 9779 { 9780 ++b2; 9781 } 9782 } 9783 else 9784 { 9785 ++b1; 9786 } 9787 9788 word = 0; 9789 word += (b1 << 16); 9790 word += (b2 << 8); 9791 word += b3; 9792 } 9793 else 9794 { 9795 word += (0x01 << 24); 9796 } 9797 return word; 9798 } 9799 9800 function incCounter(counter) 9801 { 9802 if ((counter[0] = incWord(counter[0])) === 0) 9803 { 9804 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9805 counter[1] = incWord(counter[1]); 9806 } 9807 return counter; 9808 } 9809 9810 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9811 processBlock: function (words, offset) { 9812 // Shortcuts 9813 var cipher = this._cipher 9814 var blockSize = cipher.blockSize; 9815 var iv = this._iv; 9816 var counter = this._counter; 9817 9818 // Generate keystream 9819 if (iv) { 9820 counter = this._counter = iv.slice(0); 9821 9822 // Remove IV for subsequent blocks 9823 this._iv = undefined; 9824 } 9825 9826 incCounter(counter); 9827 9828 var keystream = counter.slice(0); 9829 cipher.encryptBlock(keystream, 0); 9830 9831 // Encrypt 9832 for (var i = 0; i < blockSize; i++) { 9833 words[offset + i] ^= keystream[i]; 9834 } 9835 } 9836 }); 9837 9838 CTRGladman.Decryptor = Encryptor; 9839 9840 return CTRGladman; 9841 }()); 9842 9843 9844 9845 9846 return CryptoJS.mode.CTRGladman; 9847 9848 })); 9849 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 9850 ;(function (root, factory, undef) { 9851 if (typeof exports === "object") { 9852 // CommonJS 9853 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9854 } 9855 else if (typeof define === "function" && define.amd) { 9856 // AMD 9857 define(["./core", "./cipher-core"], factory); 9858 } 9859 else { 9860 // Global (browser) 9861 factory(root.CryptoJS); 9862 } 9863 }(this, function (CryptoJS) { 9864 9865 /** 9866 * Counter block mode. 9867 */ 9868 CryptoJS.mode.CTR = (function () { 9869 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 9870 9871 var Encryptor = CTR.Encryptor = CTR.extend({ 9872 processBlock: function (words, offset) { 9873 // Shortcuts 9874 var cipher = this._cipher 9875 var blockSize = cipher.blockSize; 9876 var iv = this._iv; 9877 var counter = this._counter; 9878 9879 // Generate keystream 9880 if (iv) { 9881 counter = this._counter = iv.slice(0); 9882 9883 // Remove IV for subsequent blocks 9884 this._iv = undefined; 9885 } 9886 var keystream = counter.slice(0); 9887 cipher.encryptBlock(keystream, 0); 9888 9889 // Increment counter 9890 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 9891 9892 // Encrypt 9893 for (var i = 0; i < blockSize; i++) { 9894 words[offset + i] ^= keystream[i]; 9895 } 9896 } 9897 }); 9898 9899 CTR.Decryptor = Encryptor; 9900 9901 return CTR; 9902 }()); 9903 9904 9905 return CryptoJS.mode.CTR; 9906 9907 })); 9908 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 9909 ;(function (root, factory, undef) { 9910 if (typeof exports === "object") { 9911 // CommonJS 9912 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9913 } 9914 else if (typeof define === "function" && define.amd) { 9915 // AMD 9916 define(["./core", "./cipher-core"], factory); 9917 } 9918 else { 9919 // Global (browser) 9920 factory(root.CryptoJS); 9921 } 9922 }(this, function (CryptoJS) { 9923 9924 /** 9925 * Electronic Codebook block mode. 9926 */ 9927 CryptoJS.mode.ECB = (function () { 9928 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 9929 9930 ECB.Encryptor = ECB.extend({ 9931 processBlock: function (words, offset) { 9932 this._cipher.encryptBlock(words, offset); 9933 } 9934 }); 9935 9936 ECB.Decryptor = ECB.extend({ 9937 processBlock: function (words, offset) { 9938 this._cipher.decryptBlock(words, offset); 9939 } 9940 }); 9941 9942 return ECB; 9943 }()); 9944 9945 9946 return CryptoJS.mode.ECB; 9947 9948 })); 9949 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 9950 ;(function (root, factory, undef) { 9951 if (typeof exports === "object") { 9952 // CommonJS 9953 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9954 } 9955 else if (typeof define === "function" && define.amd) { 9956 // AMD 9957 define(["./core", "./cipher-core"], factory); 9958 } 9959 else { 9960 // Global (browser) 9961 factory(root.CryptoJS); 9962 } 9963 }(this, function (CryptoJS) { 9964 9965 /** 9966 * Output Feedback block mode. 9967 */ 9968 CryptoJS.mode.OFB = (function () { 9969 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 9970 9971 var Encryptor = OFB.Encryptor = OFB.extend({ 9972 processBlock: function (words, offset) { 9973 // Shortcuts 9974 var cipher = this._cipher 9975 var blockSize = cipher.blockSize; 9976 var iv = this._iv; 9977 var keystream = this._keystream; 9978 9979 // Generate keystream 9980 if (iv) { 9981 keystream = this._keystream = iv.slice(0); 9982 9983 // Remove IV for subsequent blocks 9984 this._iv = undefined; 9985 } 9986 cipher.encryptBlock(keystream, 0); 9987 9988 // Encrypt 9989 for (var i = 0; i < blockSize; i++) { 9990 words[offset + i] ^= keystream[i]; 9991 } 9992 } 9993 }); 9994 9995 OFB.Decryptor = Encryptor; 9996 9997 return OFB; 9998 }()); 9999 10000 10001 return CryptoJS.mode.OFB; 10002 10003 })); 10004 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 10005 ;(function (root, factory, undef) { 10006 if (typeof exports === "object") { 10007 // CommonJS 10008 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10009 } 10010 else if (typeof define === "function" && define.amd) { 10011 // AMD 10012 define(["./core", "./cipher-core"], factory); 10013 } 10014 else { 10015 // Global (browser) 10016 factory(root.CryptoJS); 10017 } 10018 }(this, function (CryptoJS) { 10019 10020 /** 10021 * ANSI X.923 padding strategy. 10022 */ 10023 CryptoJS.pad.AnsiX923 = { 10024 pad: function (data, blockSize) { 10025 // Shortcuts 10026 var dataSigBytes = data.sigBytes; 10027 var blockSizeBytes = blockSize * 4; 10028 10029 // Count padding bytes 10030 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10031 10032 // Compute last byte position 10033 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10034 10035 // Pad 10036 data.clamp(); 10037 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10038 data.sigBytes += nPaddingBytes; 10039 }, 10040 10041 unpad: function (data) { 10042 // Get number of padding bytes from last byte 10043 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10044 10045 // Remove padding 10046 data.sigBytes -= nPaddingBytes; 10047 } 10048 }; 10049 10050 10051 return CryptoJS.pad.Ansix923; 10052 10053 })); 10054 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 10055 ;(function (root, factory, undef) { 10056 if (typeof exports === "object") { 10057 // CommonJS 10058 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10059 } 10060 else if (typeof define === "function" && define.amd) { 10061 // AMD 10062 define(["./core", "./cipher-core"], factory); 10063 } 10064 else { 10065 // Global (browser) 10066 factory(root.CryptoJS); 10067 } 10068 }(this, function (CryptoJS) { 10069 10070 /** 10071 * ISO 10126 padding strategy. 10072 */ 10073 CryptoJS.pad.Iso10126 = { 10074 pad: function (data, blockSize) { 10075 // Shortcut 10076 var blockSizeBytes = blockSize * 4; 10077 10078 // Count padding bytes 10079 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10080 10081 // Pad 10082 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10083 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10084 }, 10085 10086 unpad: function (data) { 10087 // Get number of padding bytes from last byte 10088 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10089 10090 // Remove padding 10091 data.sigBytes -= nPaddingBytes; 10092 } 10093 }; 10094 10095 10096 return CryptoJS.pad.Iso10126; 10097 10098 })); 10099 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 10100 ;(function (root, factory, undef) { 10101 if (typeof exports === "object") { 10102 // CommonJS 10103 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10104 } 10105 else if (typeof define === "function" && define.amd) { 10106 // AMD 10107 define(["./core", "./cipher-core"], factory); 10108 } 10109 else { 10110 // Global (browser) 10111 factory(root.CryptoJS); 10112 } 10113 }(this, function (CryptoJS) { 10114 10115 /** 10116 * ISO/IEC 9797-1 Padding Method 2. 10117 */ 10118 CryptoJS.pad.Iso97971 = { 10119 pad: function (data, blockSize) { 10120 // Add 0x80 byte 10121 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10122 10123 // Zero pad the rest 10124 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10125 }, 10126 10127 unpad: function (data) { 10128 // Remove zero padding 10129 CryptoJS.pad.ZeroPadding.unpad(data); 10130 10131 // Remove one more byte -- the 0x80 byte 10132 data.sigBytes--; 10133 } 10134 }; 10135 10136 10137 return CryptoJS.pad.Iso97971; 10138 10139 })); 10140 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 10141 ;(function (root, factory, undef) { 10142 if (typeof exports === "object") { 10143 // CommonJS 10144 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10145 } 10146 else if (typeof define === "function" && define.amd) { 10147 // AMD 10148 define(["./core", "./cipher-core"], factory); 10149 } 10150 else { 10151 // Global (browser) 10152 factory(root.CryptoJS); 10153 } 10154 }(this, function (CryptoJS) { 10155 10156 /** 10157 * A noop padding strategy. 10158 */ 10159 CryptoJS.pad.NoPadding = { 10160 pad: function () { 10161 }, 10162 10163 unpad: function () { 10164 } 10165 }; 10166 10167 10168 return CryptoJS.pad.NoPadding; 10169 10170 })); 10171 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 10172 ;(function (root, factory, undef) { 10173 if (typeof exports === "object") { 10174 // CommonJS 10175 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10176 } 10177 else if (typeof define === "function" && define.amd) { 10178 // AMD 10179 define(["./core", "./cipher-core"], factory); 10180 } 10181 else { 10182 // Global (browser) 10183 factory(root.CryptoJS); 10184 } 10185 }(this, function (CryptoJS) { 10186 10187 /** 10188 * Zero padding strategy. 10189 */ 10190 CryptoJS.pad.ZeroPadding = { 10191 pad: function (data, blockSize) { 10192 // Shortcut 10193 var blockSizeBytes = blockSize * 4; 10194 10195 // Pad 10196 data.clamp(); 10197 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10198 }, 10199 10200 unpad: function (data) { 10201 // Shortcut 10202 var dataWords = data.words; 10203 10204 // Unpad 10205 var i = data.sigBytes - 1; 10206 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10207 i--; 10208 } 10209 data.sigBytes = i + 1; 10210 } 10211 }; 10212 10213 10214 return CryptoJS.pad.ZeroPadding; 10215 10216 })); 10217 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 10218 ;(function (root, factory, undef) { 10219 if (typeof exports === "object") { 10220 // CommonJS 10221 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10222 } 10223 else if (typeof define === "function" && define.amd) { 10224 // AMD 10225 define(["./core", "./sha1", "./hmac"], factory); 10226 } 10227 else { 10228 // Global (browser) 10229 factory(root.CryptoJS); 10230 } 10231 }(this, function (CryptoJS) { 10232 10233 (function () { 10234 // Shortcuts 10235 var C = CryptoJS; 10236 var C_lib = C.lib; 10237 var Base = C_lib.Base; 10238 var WordArray = C_lib.WordArray; 10239 var C_algo = C.algo; 10240 var SHA1 = C_algo.SHA1; 10241 var HMAC = C_algo.HMAC; 10242 10243 /** 10244 * Password-Based Key Derivation Function 2 algorithm. 10245 */ 10246 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10247 /** 10248 * Configuration options. 10249 * 10250 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10251 * @property {Hasher} hasher The hasher to use. Default: SHA1 10252 * @property {number} iterations The number of iterations to perform. Default: 1 10253 */ 10254 cfg: Base.extend({ 10255 keySize: 128/32, 10256 hasher: SHA1, 10257 iterations: 1 10258 }), 10259 10260 /** 10261 * Initializes a newly created key derivation function. 10262 * 10263 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10264 * 10265 * @example 10266 * 10267 * var kdf = CryptoJS.algo.PBKDF2.create(); 10268 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10269 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10270 */ 10271 init: function (cfg) { 10272 this.cfg = this.cfg.extend(cfg); 10273 }, 10274 10275 /** 10276 * Computes the Password-Based Key Derivation Function 2. 10277 * 10278 * @param {WordArray|string} password The password. 10279 * @param {WordArray|string} salt A salt. 10280 * 10281 * @return {WordArray} The derived key. 10282 * 10283 * @example 10284 * 10285 * var key = kdf.compute(password, salt); 10286 */ 10287 compute: function (password, salt) { 10288 // Shortcut 10289 var cfg = this.cfg; 10290 10291 // Init HMAC 10292 var hmac = HMAC.create(cfg.hasher, password); 10293 10294 // Initial values 10295 var derivedKey = WordArray.create(); 10296 var blockIndex = WordArray.create([0x00000001]); 10297 10298 // Shortcuts 10299 var derivedKeyWords = derivedKey.words; 10300 var blockIndexWords = blockIndex.words; 10301 var keySize = cfg.keySize; 10302 var iterations = cfg.iterations; 10303 10304 // Generate key 10305 while (derivedKeyWords.length < keySize) { 10306 var block = hmac.update(salt).finalize(blockIndex); 10307 hmac.reset(); 10308 10309 // Shortcuts 10310 var blockWords = block.words; 10311 var blockWordsLength = blockWords.length; 10312 10313 // Iterations 10314 var intermediate = block; 10315 for (var i = 1; i < iterations; i++) { 10316 intermediate = hmac.finalize(intermediate); 10317 hmac.reset(); 10318 10319 // Shortcut 10320 var intermediateWords = intermediate.words; 10321 10322 // XOR intermediate with block 10323 for (var j = 0; j < blockWordsLength; j++) { 10324 blockWords[j] ^= intermediateWords[j]; 10325 } 10326 } 10327 10328 derivedKey.concat(block); 10329 blockIndexWords[0]++; 10330 } 10331 derivedKey.sigBytes = keySize * 4; 10332 10333 return derivedKey; 10334 } 10335 }); 10336 10337 /** 10338 * Computes the Password-Based Key Derivation Function 2. 10339 * 10340 * @param {WordArray|string} password The password. 10341 * @param {WordArray|string} salt A salt. 10342 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10343 * 10344 * @return {WordArray} The derived key. 10345 * 10346 * @static 10347 * 10348 * @example 10349 * 10350 * var key = CryptoJS.PBKDF2(password, salt); 10351 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10352 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10353 */ 10354 C.PBKDF2 = function (password, salt, cfg) { 10355 return PBKDF2.create(cfg).compute(password, salt); 10356 }; 10357 }()); 10358 10359 10360 return CryptoJS.PBKDF2; 10361 10362 })); 10363 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 10364 ;(function (root, factory, undef) { 10365 if (typeof exports === "object") { 10366 // CommonJS 10367 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10368 } 10369 else if (typeof define === "function" && define.amd) { 10370 // AMD 10371 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10372 } 10373 else { 10374 // Global (browser) 10375 factory(root.CryptoJS); 10376 } 10377 }(this, function (CryptoJS) { 10378 10379 (function () { 10380 // Shortcuts 10381 var C = CryptoJS; 10382 var C_lib = C.lib; 10383 var StreamCipher = C_lib.StreamCipher; 10384 var C_algo = C.algo; 10385 10386 // Reusable objects 10387 var S = []; 10388 var C_ = []; 10389 var G = []; 10390 10391 /** 10392 * Rabbit stream cipher algorithm. 10393 * 10394 * This is a legacy version that neglected to convert the key to little-endian. 10395 * This error doesn't affect the cipher's security, 10396 * but it does affect its compatibility with other implementations. 10397 */ 10398 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10399 _doReset: function () { 10400 // Shortcuts 10401 var K = this._key.words; 10402 var iv = this.cfg.iv; 10403 10404 // Generate initial state values 10405 var X = this._X = [ 10406 K[0], (K[3] << 16) | (K[2] >>> 16), 10407 K[1], (K[0] << 16) | (K[3] >>> 16), 10408 K[2], (K[1] << 16) | (K[0] >>> 16), 10409 K[3], (K[2] << 16) | (K[1] >>> 16) 10410 ]; 10411 10412 // Generate initial counter values 10413 var C = this._C = [ 10414 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10415 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10416 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10417 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10418 ]; 10419 10420 // Carry bit 10421 this._b = 0; 10422 10423 // Iterate the system four times 10424 for (var i = 0; i < 4; i++) { 10425 nextState.call(this); 10426 } 10427 10428 // Modify the counters 10429 for (var i = 0; i < 8; i++) { 10430 C[i] ^= X[(i + 4) & 7]; 10431 } 10432 10433 // IV setup 10434 if (iv) { 10435 // Shortcuts 10436 var IV = iv.words; 10437 var IV_0 = IV[0]; 10438 var IV_1 = IV[1]; 10439 10440 // Generate four subvectors 10441 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10442 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10443 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10444 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10445 10446 // Modify counter values 10447 C[0] ^= i0; 10448 C[1] ^= i1; 10449 C[2] ^= i2; 10450 C[3] ^= i3; 10451 C[4] ^= i0; 10452 C[5] ^= i1; 10453 C[6] ^= i2; 10454 C[7] ^= i3; 10455 10456 // Iterate the system four times 10457 for (var i = 0; i < 4; i++) { 10458 nextState.call(this); 10459 } 10460 } 10461 }, 10462 10463 _doProcessBlock: function (M, offset) { 10464 // Shortcut 10465 var X = this._X; 10466 10467 // Iterate the system 10468 nextState.call(this); 10469 10470 // Generate four keystream words 10471 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10472 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10473 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10474 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10475 10476 for (var i = 0; i < 4; i++) { 10477 // Swap endian 10478 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10479 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10480 10481 // Encrypt 10482 M[offset + i] ^= S[i]; 10483 } 10484 }, 10485 10486 blockSize: 128/32, 10487 10488 ivSize: 64/32 10489 }); 10490 10491 function nextState() { 10492 // Shortcuts 10493 var X = this._X; 10494 var C = this._C; 10495 10496 // Save old counter values 10497 for (var i = 0; i < 8; i++) { 10498 C_[i] = C[i]; 10499 } 10500 10501 // Calculate new counter values 10502 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10503 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10504 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10505 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10506 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10507 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10508 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10509 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10510 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10511 10512 // Calculate the g-values 10513 for (var i = 0; i < 8; i++) { 10514 var gx = X[i] + C[i]; 10515 10516 // Construct high and low argument for squaring 10517 var ga = gx & 0xffff; 10518 var gb = gx >>> 16; 10519 10520 // Calculate high and low result of squaring 10521 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10522 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10523 10524 // High XOR low 10525 G[i] = gh ^ gl; 10526 } 10527 10528 // Calculate new state values 10529 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10530 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10531 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10532 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10533 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10534 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10535 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10536 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10537 } 10538 10539 /** 10540 * Shortcut functions to the cipher's object interface. 10541 * 10542 * @example 10543 * 10544 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10545 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10546 */ 10547 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10548 }()); 10549 10550 10551 return CryptoJS.RabbitLegacy; 10552 10553 })); 10554 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 10555 ;(function (root, factory, undef) { 10556 if (typeof exports === "object") { 10557 // CommonJS 10558 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10559 } 10560 else if (typeof define === "function" && define.amd) { 10561 // AMD 10562 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10563 } 10564 else { 10565 // Global (browser) 10566 factory(root.CryptoJS); 10567 } 10568 }(this, function (CryptoJS) { 10569 10570 (function () { 10571 // Shortcuts 10572 var C = CryptoJS; 10573 var C_lib = C.lib; 10574 var StreamCipher = C_lib.StreamCipher; 10575 var C_algo = C.algo; 10576 10577 // Reusable objects 10578 var S = []; 10579 var C_ = []; 10580 var G = []; 10581 10582 /** 10583 * Rabbit stream cipher algorithm 10584 */ 10585 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10586 _doReset: function () { 10587 // Shortcuts 10588 var K = this._key.words; 10589 var iv = this.cfg.iv; 10590 10591 // Swap endian 10592 for (var i = 0; i < 4; i++) { 10593 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10594 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10595 } 10596 10597 // Generate initial state values 10598 var X = this._X = [ 10599 K[0], (K[3] << 16) | (K[2] >>> 16), 10600 K[1], (K[0] << 16) | (K[3] >>> 16), 10601 K[2], (K[1] << 16) | (K[0] >>> 16), 10602 K[3], (K[2] << 16) | (K[1] >>> 16) 10603 ]; 10604 10605 // Generate initial counter values 10606 var C = this._C = [ 10607 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10608 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10609 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10610 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10611 ]; 10612 10613 // Carry bit 10614 this._b = 0; 10615 10616 // Iterate the system four times 10617 for (var i = 0; i < 4; i++) { 10618 nextState.call(this); 10619 } 10620 10621 // Modify the counters 10622 for (var i = 0; i < 8; i++) { 10623 C[i] ^= X[(i + 4) & 7]; 10624 } 10625 10626 // IV setup 10627 if (iv) { 10628 // Shortcuts 10629 var IV = iv.words; 10630 var IV_0 = IV[0]; 10631 var IV_1 = IV[1]; 10632 10633 // Generate four subvectors 10634 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10635 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10636 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10637 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10638 10639 // Modify counter values 10640 C[0] ^= i0; 10641 C[1] ^= i1; 10642 C[2] ^= i2; 10643 C[3] ^= i3; 10644 C[4] ^= i0; 10645 C[5] ^= i1; 10646 C[6] ^= i2; 10647 C[7] ^= i3; 10648 10649 // Iterate the system four times 10650 for (var i = 0; i < 4; i++) { 10651 nextState.call(this); 10652 } 10653 } 10654 }, 10655 10656 _doProcessBlock: function (M, offset) { 10657 // Shortcut 10658 var X = this._X; 10659 10660 // Iterate the system 10661 nextState.call(this); 10662 10663 // Generate four keystream words 10664 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10665 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10666 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10667 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10668 10669 for (var i = 0; i < 4; i++) { 10670 // Swap endian 10671 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10672 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10673 10674 // Encrypt 10675 M[offset + i] ^= S[i]; 10676 } 10677 }, 10678 10679 blockSize: 128/32, 10680 10681 ivSize: 64/32 10682 }); 10683 10684 function nextState() { 10685 // Shortcuts 10686 var X = this._X; 10687 var C = this._C; 10688 10689 // Save old counter values 10690 for (var i = 0; i < 8; i++) { 10691 C_[i] = C[i]; 10692 } 10693 10694 // Calculate new counter values 10695 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10696 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10697 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10698 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10699 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10700 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10701 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10702 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10703 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10704 10705 // Calculate the g-values 10706 for (var i = 0; i < 8; i++) { 10707 var gx = X[i] + C[i]; 10708 10709 // Construct high and low argument for squaring 10710 var ga = gx & 0xffff; 10711 var gb = gx >>> 16; 10712 10713 // Calculate high and low result of squaring 10714 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10715 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10716 10717 // High XOR low 10718 G[i] = gh ^ gl; 10719 } 10720 10721 // Calculate new state values 10722 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10723 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10724 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10725 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10726 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10727 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10728 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10729 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10730 } 10731 10732 /** 10733 * Shortcut functions to the cipher's object interface. 10734 * 10735 * @example 10736 * 10737 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10738 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10739 */ 10740 C.Rabbit = StreamCipher._createHelper(Rabbit); 10741 }()); 10742 10743 10744 return CryptoJS.Rabbit; 10745 10746 })); 10747 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 10748 ;(function (root, factory, undef) { 10749 if (typeof exports === "object") { 10750 // CommonJS 10751 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10752 } 10753 else if (typeof define === "function" && define.amd) { 10754 // AMD 10755 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10756 } 10757 else { 10758 // Global (browser) 10759 factory(root.CryptoJS); 10760 } 10761 }(this, function (CryptoJS) { 10762 10763 (function () { 10764 // Shortcuts 10765 var C = CryptoJS; 10766 var C_lib = C.lib; 10767 var StreamCipher = C_lib.StreamCipher; 10768 var C_algo = C.algo; 10769 10770 /** 10771 * RC4 stream cipher algorithm. 10772 */ 10773 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10774 _doReset: function () { 10775 // Shortcuts 10776 var key = this._key; 10777 var keyWords = key.words; 10778 var keySigBytes = key.sigBytes; 10779 10780 // Init sbox 10781 var S = this._S = []; 10782 for (var i = 0; i < 256; i++) { 10783 S[i] = i; 10784 } 10785 10786 // Key setup 10787 for (var i = 0, j = 0; i < 256; i++) { 10788 var keyByteIndex = i % keySigBytes; 10789 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10790 10791 j = (j + S[i] + keyByte) % 256; 10792 10793 // Swap 10794 var t = S[i]; 10795 S[i] = S[j]; 10796 S[j] = t; 10797 } 10798 10799 // Counters 10800 this._i = this._j = 0; 10801 }, 10802 10803 _doProcessBlock: function (M, offset) { 10804 M[offset] ^= generateKeystreamWord.call(this); 10805 }, 10806 10807 keySize: 256/32, 10808 10809 ivSize: 0 10810 }); 10811 10812 function generateKeystreamWord() { 10813 // Shortcuts 10814 var S = this._S; 10815 var i = this._i; 10816 var j = this._j; 10817 10818 // Generate keystream word 10819 var keystreamWord = 0; 10820 for (var n = 0; n < 4; n++) { 10821 i = (i + 1) % 256; 10822 j = (j + S[i]) % 256; 10823 10824 // Swap 10825 var t = S[i]; 10826 S[i] = S[j]; 10827 S[j] = t; 10828 10829 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 10830 } 10831 10832 // Update counters 10833 this._i = i; 10834 this._j = j; 10835 10836 return keystreamWord; 10837 } 10838 10839 /** 10840 * Shortcut functions to the cipher's object interface. 10841 * 10842 * @example 10843 * 10844 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 10845 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 10846 */ 10847 C.RC4 = StreamCipher._createHelper(RC4); 10848 10849 /** 10850 * Modified RC4 stream cipher algorithm. 10851 */ 10852 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 10853 /** 10854 * Configuration options. 10855 * 10856 * @property {number} drop The number of keystream words to drop. Default 192 10857 */ 10858 cfg: RC4.cfg.extend({ 10859 drop: 192 10860 }), 10861 10862 _doReset: function () { 10863 RC4._doReset.call(this); 10864 10865 // Drop 10866 for (var i = this.cfg.drop; i > 0; i--) { 10867 generateKeystreamWord.call(this); 10868 } 10869 } 10870 }); 10871 10872 /** 10873 * Shortcut functions to the cipher's object interface. 10874 * 10875 * @example 10876 * 10877 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 10878 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 10879 */ 10880 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 10881 }()); 10882 10883 10884 return CryptoJS.RC4; 10885 10886 })); 10887 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 10888 ;(function (root, factory) { 10889 if (typeof exports === "object") { 10890 // CommonJS 10891 module.exports = exports = factory(require("./core")); 10892 } 10893 else if (typeof define === "function" && define.amd) { 10894 // AMD 10895 define(["./core"], factory); 10896 } 10897 else { 10898 // Global (browser) 10899 factory(root.CryptoJS); 10900 } 10901 }(this, function (CryptoJS) { 10902 10903 /** @preserve 10904 (c) 2012 by Cédric Mesnil. All rights reserved. 10905 10906 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10907 10908 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10909 - 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. 10910 10911 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. 10912 */ 10913 10914 (function (Math) { 10915 // Shortcuts 10916 var C = CryptoJS; 10917 var C_lib = C.lib; 10918 var WordArray = C_lib.WordArray; 10919 var Hasher = C_lib.Hasher; 10920 var C_algo = C.algo; 10921 10922 // Constants table 10923 var _zl = WordArray.create([ 10924 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10925 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 10926 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 10927 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 10928 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 10929 var _zr = WordArray.create([ 10930 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 10931 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 10932 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 10933 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 10934 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 10935 var _sl = WordArray.create([ 10936 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 10937 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 10938 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 10939 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 10940 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 10941 var _sr = WordArray.create([ 10942 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 10943 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 10944 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 10945 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 10946 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 10947 10948 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 10949 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 10950 10951 /** 10952 * RIPEMD160 hash algorithm. 10953 */ 10954 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 10955 _doReset: function () { 10956 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 10957 }, 10958 10959 _doProcessBlock: function (M, offset) { 10960 10961 // Swap endian 10962 for (var i = 0; i < 16; i++) { 10963 // Shortcuts 10964 var offset_i = offset + i; 10965 var M_offset_i = M[offset_i]; 10966 10967 // Swap 10968 M[offset_i] = ( 10969 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10970 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 10971 ); 10972 } 10973 // Shortcut 10974 var H = this._hash.words; 10975 var hl = _hl.words; 10976 var hr = _hr.words; 10977 var zl = _zl.words; 10978 var zr = _zr.words; 10979 var sl = _sl.words; 10980 var sr = _sr.words; 10981 10982 // Working variables 10983 var al, bl, cl, dl, el; 10984 var ar, br, cr, dr, er; 10985 10986 ar = al = H[0]; 10987 br = bl = H[1]; 10988 cr = cl = H[2]; 10989 dr = dl = H[3]; 10990 er = el = H[4]; 10991 // Computation 10992 var t; 10993 for (var i = 0; i < 80; i += 1) { 10994 t = (al + M[offset+zl[i]])|0; 10995 if (i<16){ 10996 t += f1(bl,cl,dl) + hl[0]; 10997 } else if (i<32) { 10998 t += f2(bl,cl,dl) + hl[1]; 10999 } else if (i<48) { 11000 t += f3(bl,cl,dl) + hl[2]; 11001 } else if (i<64) { 11002 t += f4(bl,cl,dl) + hl[3]; 11003 } else {// if (i<80) { 11004 t += f5(bl,cl,dl) + hl[4]; 11005 } 11006 t = t|0; 11007 t = rotl(t,sl[i]); 11008 t = (t+el)|0; 11009 al = el; 11010 el = dl; 11011 dl = rotl(cl, 10); 11012 cl = bl; 11013 bl = t; 11014 11015 t = (ar + M[offset+zr[i]])|0; 11016 if (i<16){ 11017 t += f5(br,cr,dr) + hr[0]; 11018 } else if (i<32) { 11019 t += f4(br,cr,dr) + hr[1]; 11020 } else if (i<48) { 11021 t += f3(br,cr,dr) + hr[2]; 11022 } else if (i<64) { 11023 t += f2(br,cr,dr) + hr[3]; 11024 } else {// if (i<80) { 11025 t += f1(br,cr,dr) + hr[4]; 11026 } 11027 t = t|0; 11028 t = rotl(t,sr[i]) ; 11029 t = (t+er)|0; 11030 ar = er; 11031 er = dr; 11032 dr = rotl(cr, 10); 11033 cr = br; 11034 br = t; 11035 } 11036 // Intermediate hash value 11037 t = (H[1] + cl + dr)|0; 11038 H[1] = (H[2] + dl + er)|0; 11039 H[2] = (H[3] + el + ar)|0; 11040 H[3] = (H[4] + al + br)|0; 11041 H[4] = (H[0] + bl + cr)|0; 11042 H[0] = t; 11043 }, 11044 11045 _doFinalize: function () { 11046 // Shortcuts 11047 var data = this._data; 11048 var dataWords = data.words; 11049 11050 var nBitsTotal = this._nDataBytes * 8; 11051 var nBitsLeft = data.sigBytes * 8; 11052 11053 // Add padding 11054 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11055 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11056 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11057 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11058 ); 11059 data.sigBytes = (dataWords.length + 1) * 4; 11060 11061 // Hash final blocks 11062 this._process(); 11063 11064 // Shortcuts 11065 var hash = this._hash; 11066 var H = hash.words; 11067 11068 // Swap endian 11069 for (var i = 0; i < 5; i++) { 11070 // Shortcut 11071 var H_i = H[i]; 11072 11073 // Swap 11074 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11075 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11076 } 11077 11078 // Return final computed hash 11079 return hash; 11080 }, 11081 11082 clone: function () { 11083 var clone = Hasher.clone.call(this); 11084 clone._hash = this._hash.clone(); 11085 11086 return clone; 11087 } 11088 }); 11089 11090 11091 function f1(x, y, z) { 11092 return ((x) ^ (y) ^ (z)); 11093 11094 } 11095 11096 function f2(x, y, z) { 11097 return (((x)&(y)) | ((~x)&(z))); 11098 } 11099 11100 function f3(x, y, z) { 11101 return (((x) | (~(y))) ^ (z)); 11102 } 11103 11104 function f4(x, y, z) { 11105 return (((x) & (z)) | ((y)&(~(z)))); 11106 } 11107 11108 function f5(x, y, z) { 11109 return ((x) ^ ((y) |(~(z)))); 11110 11111 } 11112 11113 function rotl(x,n) { 11114 return (x<<n) | (x>>>(32-n)); 11115 } 11116 11117 11118 /** 11119 * Shortcut function to the hasher's object interface. 11120 * 11121 * @param {WordArray|string} message The message to hash. 11122 * 11123 * @return {WordArray} The hash. 11124 * 11125 * @static 11126 * 11127 * @example 11128 * 11129 * var hash = CryptoJS.RIPEMD160('message'); 11130 * var hash = CryptoJS.RIPEMD160(wordArray); 11131 */ 11132 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11133 11134 /** 11135 * Shortcut function to the HMAC's object interface. 11136 * 11137 * @param {WordArray|string} message The message to hash. 11138 * @param {WordArray|string} key The secret key. 11139 * 11140 * @return {WordArray} The HMAC. 11141 * 11142 * @static 11143 * 11144 * @example 11145 * 11146 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11147 */ 11148 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11149 }(Math)); 11150 11151 11152 return CryptoJS.RIPEMD160; 11153 11154 })); 11155 },{"./core":53}],77:[function(require,module,exports){ 11156 ;(function (root, factory) { 11157 if (typeof exports === "object") { 11158 // CommonJS 11159 module.exports = exports = factory(require("./core")); 11160 } 11161 else if (typeof define === "function" && define.amd) { 11162 // AMD 11163 define(["./core"], factory); 11164 } 11165 else { 11166 // Global (browser) 11167 factory(root.CryptoJS); 11168 } 11169 }(this, function (CryptoJS) { 11170 11171 (function () { 11172 // Shortcuts 11173 var C = CryptoJS; 11174 var C_lib = C.lib; 11175 var WordArray = C_lib.WordArray; 11176 var Hasher = C_lib.Hasher; 11177 var C_algo = C.algo; 11178 11179 // Reusable object 11180 var W = []; 11181 11182 /** 11183 * SHA-1 hash algorithm. 11184 */ 11185 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11186 _doReset: function () { 11187 this._hash = new WordArray.init([ 11188 0x67452301, 0xefcdab89, 11189 0x98badcfe, 0x10325476, 11190 0xc3d2e1f0 11191 ]); 11192 }, 11193 11194 _doProcessBlock: function (M, offset) { 11195 // Shortcut 11196 var H = this._hash.words; 11197 11198 // Working variables 11199 var a = H[0]; 11200 var b = H[1]; 11201 var c = H[2]; 11202 var d = H[3]; 11203 var e = H[4]; 11204 11205 // Computation 11206 for (var i = 0; i < 80; i++) { 11207 if (i < 16) { 11208 W[i] = M[offset + i] | 0; 11209 } else { 11210 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11211 W[i] = (n << 1) | (n >>> 31); 11212 } 11213 11214 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11215 if (i < 20) { 11216 t += ((b & c) | (~b & d)) + 0x5a827999; 11217 } else if (i < 40) { 11218 t += (b ^ c ^ d) + 0x6ed9eba1; 11219 } else if (i < 60) { 11220 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11221 } else /* if (i < 80) */ { 11222 t += (b ^ c ^ d) - 0x359d3e2a; 11223 } 11224 11225 e = d; 11226 d = c; 11227 c = (b << 30) | (b >>> 2); 11228 b = a; 11229 a = t; 11230 } 11231 11232 // Intermediate hash value 11233 H[0] = (H[0] + a) | 0; 11234 H[1] = (H[1] + b) | 0; 11235 H[2] = (H[2] + c) | 0; 11236 H[3] = (H[3] + d) | 0; 11237 H[4] = (H[4] + e) | 0; 11238 }, 11239 11240 _doFinalize: function () { 11241 // Shortcuts 11242 var data = this._data; 11243 var dataWords = data.words; 11244 11245 var nBitsTotal = this._nDataBytes * 8; 11246 var nBitsLeft = data.sigBytes * 8; 11247 11248 // Add padding 11249 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11250 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11251 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11252 data.sigBytes = dataWords.length * 4; 11253 11254 // Hash final blocks 11255 this._process(); 11256 11257 // Return final computed hash 11258 return this._hash; 11259 }, 11260 11261 clone: function () { 11262 var clone = Hasher.clone.call(this); 11263 clone._hash = this._hash.clone(); 11264 11265 return clone; 11266 } 11267 }); 11268 11269 /** 11270 * Shortcut function to the hasher's object interface. 11271 * 11272 * @param {WordArray|string} message The message to hash. 11273 * 11274 * @return {WordArray} The hash. 11275 * 11276 * @static 11277 * 11278 * @example 11279 * 11280 * var hash = CryptoJS.SHA1('message'); 11281 * var hash = CryptoJS.SHA1(wordArray); 11282 */ 11283 C.SHA1 = Hasher._createHelper(SHA1); 11284 11285 /** 11286 * Shortcut function to the HMAC's object interface. 11287 * 11288 * @param {WordArray|string} message The message to hash. 11289 * @param {WordArray|string} key The secret key. 11290 * 11291 * @return {WordArray} The HMAC. 11292 * 11293 * @static 11294 * 11295 * @example 11296 * 11297 * var hmac = CryptoJS.HmacSHA1(message, key); 11298 */ 11299 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11300 }()); 11301 11302 11303 return CryptoJS.SHA1; 11304 11305 })); 11306 },{"./core":53}],78:[function(require,module,exports){ 11307 ;(function (root, factory, undef) { 11308 if (typeof exports === "object") { 11309 // CommonJS 11310 module.exports = exports = factory(require("./core"), require("./sha256")); 11311 } 11312 else if (typeof define === "function" && define.amd) { 11313 // AMD 11314 define(["./core", "./sha256"], factory); 11315 } 11316 else { 11317 // Global (browser) 11318 factory(root.CryptoJS); 11319 } 11320 }(this, function (CryptoJS) { 11321 11322 (function () { 11323 // Shortcuts 11324 var C = CryptoJS; 11325 var C_lib = C.lib; 11326 var WordArray = C_lib.WordArray; 11327 var C_algo = C.algo; 11328 var SHA256 = C_algo.SHA256; 11329 11330 /** 11331 * SHA-224 hash algorithm. 11332 */ 11333 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11334 _doReset: function () { 11335 this._hash = new WordArray.init([ 11336 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11337 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11338 ]); 11339 }, 11340 11341 _doFinalize: function () { 11342 var hash = SHA256._doFinalize.call(this); 11343 11344 hash.sigBytes -= 4; 11345 11346 return hash; 11347 } 11348 }); 11349 11350 /** 11351 * Shortcut function to the hasher's object interface. 11352 * 11353 * @param {WordArray|string} message The message to hash. 11354 * 11355 * @return {WordArray} The hash. 11356 * 11357 * @static 11358 * 11359 * @example 11360 * 11361 * var hash = CryptoJS.SHA224('message'); 11362 * var hash = CryptoJS.SHA224(wordArray); 11363 */ 11364 C.SHA224 = SHA256._createHelper(SHA224); 11365 11366 /** 11367 * Shortcut function to the HMAC's object interface. 11368 * 11369 * @param {WordArray|string} message The message to hash. 11370 * @param {WordArray|string} key The secret key. 11371 * 11372 * @return {WordArray} The HMAC. 11373 * 11374 * @static 11375 * 11376 * @example 11377 * 11378 * var hmac = CryptoJS.HmacSHA224(message, key); 11379 */ 11380 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11381 }()); 11382 11383 11384 return CryptoJS.SHA224; 11385 11386 })); 11387 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 11388 ;(function (root, factory) { 11389 if (typeof exports === "object") { 11390 // CommonJS 11391 module.exports = exports = factory(require("./core")); 11392 } 11393 else if (typeof define === "function" && define.amd) { 11394 // AMD 11395 define(["./core"], factory); 11396 } 11397 else { 11398 // Global (browser) 11399 factory(root.CryptoJS); 11400 } 11401 }(this, function (CryptoJS) { 11402 11403 (function (Math) { 11404 // Shortcuts 11405 var C = CryptoJS; 11406 var C_lib = C.lib; 11407 var WordArray = C_lib.WordArray; 11408 var Hasher = C_lib.Hasher; 11409 var C_algo = C.algo; 11410 11411 // Initialization and round constants tables 11412 var H = []; 11413 var K = []; 11414 11415 // Compute constants 11416 (function () { 11417 function isPrime(n) { 11418 var sqrtN = Math.sqrt(n); 11419 for (var factor = 2; factor <= sqrtN; factor++) { 11420 if (!(n % factor)) { 11421 return false; 11422 } 11423 } 11424 11425 return true; 11426 } 11427 11428 function getFractionalBits(n) { 11429 return ((n - (n | 0)) * 0x100000000) | 0; 11430 } 11431 11432 var n = 2; 11433 var nPrime = 0; 11434 while (nPrime < 64) { 11435 if (isPrime(n)) { 11436 if (nPrime < 8) { 11437 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11438 } 11439 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11440 11441 nPrime++; 11442 } 11443 11444 n++; 11445 } 11446 }()); 11447 11448 // Reusable object 11449 var W = []; 11450 11451 /** 11452 * SHA-256 hash algorithm. 11453 */ 11454 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11455 _doReset: function () { 11456 this._hash = new WordArray.init(H.slice(0)); 11457 }, 11458 11459 _doProcessBlock: function (M, offset) { 11460 // Shortcut 11461 var H = this._hash.words; 11462 11463 // Working variables 11464 var a = H[0]; 11465 var b = H[1]; 11466 var c = H[2]; 11467 var d = H[3]; 11468 var e = H[4]; 11469 var f = H[5]; 11470 var g = H[6]; 11471 var h = H[7]; 11472 11473 // Computation 11474 for (var i = 0; i < 64; i++) { 11475 if (i < 16) { 11476 W[i] = M[offset + i] | 0; 11477 } else { 11478 var gamma0x = W[i - 15]; 11479 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11480 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11481 (gamma0x >>> 3); 11482 11483 var gamma1x = W[i - 2]; 11484 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11485 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11486 (gamma1x >>> 10); 11487 11488 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11489 } 11490 11491 var ch = (e & f) ^ (~e & g); 11492 var maj = (a & b) ^ (a & c) ^ (b & c); 11493 11494 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11495 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11496 11497 var t1 = h + sigma1 + ch + K[i] + W[i]; 11498 var t2 = sigma0 + maj; 11499 11500 h = g; 11501 g = f; 11502 f = e; 11503 e = (d + t1) | 0; 11504 d = c; 11505 c = b; 11506 b = a; 11507 a = (t1 + t2) | 0; 11508 } 11509 11510 // Intermediate hash value 11511 H[0] = (H[0] + a) | 0; 11512 H[1] = (H[1] + b) | 0; 11513 H[2] = (H[2] + c) | 0; 11514 H[3] = (H[3] + d) | 0; 11515 H[4] = (H[4] + e) | 0; 11516 H[5] = (H[5] + f) | 0; 11517 H[6] = (H[6] + g) | 0; 11518 H[7] = (H[7] + h) | 0; 11519 }, 11520 11521 _doFinalize: function () { 11522 // Shortcuts 11523 var data = this._data; 11524 var dataWords = data.words; 11525 11526 var nBitsTotal = this._nDataBytes * 8; 11527 var nBitsLeft = data.sigBytes * 8; 11528 11529 // Add padding 11530 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11531 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11532 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11533 data.sigBytes = dataWords.length * 4; 11534 11535 // Hash final blocks 11536 this._process(); 11537 11538 // Return final computed hash 11539 return this._hash; 11540 }, 11541 11542 clone: function () { 11543 var clone = Hasher.clone.call(this); 11544 clone._hash = this._hash.clone(); 11545 11546 return clone; 11547 } 11548 }); 11549 11550 /** 11551 * Shortcut function to the hasher's object interface. 11552 * 11553 * @param {WordArray|string} message The message to hash. 11554 * 11555 * @return {WordArray} The hash. 11556 * 11557 * @static 11558 * 11559 * @example 11560 * 11561 * var hash = CryptoJS.SHA256('message'); 11562 * var hash = CryptoJS.SHA256(wordArray); 11563 */ 11564 C.SHA256 = Hasher._createHelper(SHA256); 11565 11566 /** 11567 * Shortcut function to the HMAC's object interface. 11568 * 11569 * @param {WordArray|string} message The message to hash. 11570 * @param {WordArray|string} key The secret key. 11571 * 11572 * @return {WordArray} The HMAC. 11573 * 11574 * @static 11575 * 11576 * @example 11577 * 11578 * var hmac = CryptoJS.HmacSHA256(message, key); 11579 */ 11580 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11581 }(Math)); 11582 11583 11584 return CryptoJS.SHA256; 11585 11586 })); 11587 },{"./core":53}],80:[function(require,module,exports){ 11588 ;(function (root, factory, undef) { 11589 if (typeof exports === "object") { 11590 // CommonJS 11591 module.exports = exports = factory(require("./core"), require("./x64-core")); 11592 } 11593 else if (typeof define === "function" && define.amd) { 11594 // AMD 11595 define(["./core", "./x64-core"], factory); 11596 } 11597 else { 11598 // Global (browser) 11599 factory(root.CryptoJS); 11600 } 11601 }(this, function (CryptoJS) { 11602 11603 (function (Math) { 11604 // Shortcuts 11605 var C = CryptoJS; 11606 var C_lib = C.lib; 11607 var WordArray = C_lib.WordArray; 11608 var Hasher = C_lib.Hasher; 11609 var C_x64 = C.x64; 11610 var X64Word = C_x64.Word; 11611 var C_algo = C.algo; 11612 11613 // Constants tables 11614 var RHO_OFFSETS = []; 11615 var PI_INDEXES = []; 11616 var ROUND_CONSTANTS = []; 11617 11618 // Compute Constants 11619 (function () { 11620 // Compute rho offset constants 11621 var x = 1, y = 0; 11622 for (var t = 0; t < 24; t++) { 11623 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11624 11625 var newX = y % 5; 11626 var newY = (2 * x + 3 * y) % 5; 11627 x = newX; 11628 y = newY; 11629 } 11630 11631 // Compute pi index constants 11632 for (var x = 0; x < 5; x++) { 11633 for (var y = 0; y < 5; y++) { 11634 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11635 } 11636 } 11637 11638 // Compute round constants 11639 var LFSR = 0x01; 11640 for (var i = 0; i < 24; i++) { 11641 var roundConstantMsw = 0; 11642 var roundConstantLsw = 0; 11643 11644 for (var j = 0; j < 7; j++) { 11645 if (LFSR & 0x01) { 11646 var bitPosition = (1 << j) - 1; 11647 if (bitPosition < 32) { 11648 roundConstantLsw ^= 1 << bitPosition; 11649 } else /* if (bitPosition >= 32) */ { 11650 roundConstantMsw ^= 1 << (bitPosition - 32); 11651 } 11652 } 11653 11654 // Compute next LFSR 11655 if (LFSR & 0x80) { 11656 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11657 LFSR = (LFSR << 1) ^ 0x71; 11658 } else { 11659 LFSR <<= 1; 11660 } 11661 } 11662 11663 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11664 } 11665 }()); 11666 11667 // Reusable objects for temporary values 11668 var T = []; 11669 (function () { 11670 for (var i = 0; i < 25; i++) { 11671 T[i] = X64Word.create(); 11672 } 11673 }()); 11674 11675 /** 11676 * SHA-3 hash algorithm. 11677 */ 11678 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11679 /** 11680 * Configuration options. 11681 * 11682 * @property {number} outputLength 11683 * The desired number of bits in the output hash. 11684 * Only values permitted are: 224, 256, 384, 512. 11685 * Default: 512 11686 */ 11687 cfg: Hasher.cfg.extend({ 11688 outputLength: 512 11689 }), 11690 11691 _doReset: function () { 11692 var state = this._state = [] 11693 for (var i = 0; i < 25; i++) { 11694 state[i] = new X64Word.init(); 11695 } 11696 11697 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11698 }, 11699 11700 _doProcessBlock: function (M, offset) { 11701 // Shortcuts 11702 var state = this._state; 11703 var nBlockSizeLanes = this.blockSize / 2; 11704 11705 // Absorb 11706 for (var i = 0; i < nBlockSizeLanes; i++) { 11707 // Shortcuts 11708 var M2i = M[offset + 2 * i]; 11709 var M2i1 = M[offset + 2 * i + 1]; 11710 11711 // Swap endian 11712 M2i = ( 11713 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11714 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11715 ); 11716 M2i1 = ( 11717 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11718 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11719 ); 11720 11721 // Absorb message into state 11722 var lane = state[i]; 11723 lane.high ^= M2i1; 11724 lane.low ^= M2i; 11725 } 11726 11727 // Rounds 11728 for (var round = 0; round < 24; round++) { 11729 // Theta 11730 for (var x = 0; x < 5; x++) { 11731 // Mix column lanes 11732 var tMsw = 0, tLsw = 0; 11733 for (var y = 0; y < 5; y++) { 11734 var lane = state[x + 5 * y]; 11735 tMsw ^= lane.high; 11736 tLsw ^= lane.low; 11737 } 11738 11739 // Temporary values 11740 var Tx = T[x]; 11741 Tx.high = tMsw; 11742 Tx.low = tLsw; 11743 } 11744 for (var x = 0; x < 5; x++) { 11745 // Shortcuts 11746 var Tx4 = T[(x + 4) % 5]; 11747 var Tx1 = T[(x + 1) % 5]; 11748 var Tx1Msw = Tx1.high; 11749 var Tx1Lsw = Tx1.low; 11750 11751 // Mix surrounding columns 11752 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11753 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11754 for (var y = 0; y < 5; y++) { 11755 var lane = state[x + 5 * y]; 11756 lane.high ^= tMsw; 11757 lane.low ^= tLsw; 11758 } 11759 } 11760 11761 // Rho Pi 11762 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11763 // Shortcuts 11764 var lane = state[laneIndex]; 11765 var laneMsw = lane.high; 11766 var laneLsw = lane.low; 11767 var rhoOffset = RHO_OFFSETS[laneIndex]; 11768 11769 // Rotate lanes 11770 if (rhoOffset < 32) { 11771 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11772 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11773 } else /* if (rhoOffset >= 32) */ { 11774 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11775 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11776 } 11777 11778 // Transpose lanes 11779 var TPiLane = T[PI_INDEXES[laneIndex]]; 11780 TPiLane.high = tMsw; 11781 TPiLane.low = tLsw; 11782 } 11783 11784 // Rho pi at x = y = 0 11785 var T0 = T[0]; 11786 var state0 = state[0]; 11787 T0.high = state0.high; 11788 T0.low = state0.low; 11789 11790 // Chi 11791 for (var x = 0; x < 5; x++) { 11792 for (var y = 0; y < 5; y++) { 11793 // Shortcuts 11794 var laneIndex = x + 5 * y; 11795 var lane = state[laneIndex]; 11796 var TLane = T[laneIndex]; 11797 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 11798 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 11799 11800 // Mix rows 11801 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 11802 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 11803 } 11804 } 11805 11806 // Iota 11807 var lane = state[0]; 11808 var roundConstant = ROUND_CONSTANTS[round]; 11809 lane.high ^= roundConstant.high; 11810 lane.low ^= roundConstant.low;; 11811 } 11812 }, 11813 11814 _doFinalize: function () { 11815 // Shortcuts 11816 var data = this._data; 11817 var dataWords = data.words; 11818 var nBitsTotal = this._nDataBytes * 8; 11819 var nBitsLeft = data.sigBytes * 8; 11820 var blockSizeBits = this.blockSize * 32; 11821 11822 // Add padding 11823 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 11824 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 11825 data.sigBytes = dataWords.length * 4; 11826 11827 // Hash final blocks 11828 this._process(); 11829 11830 // Shortcuts 11831 var state = this._state; 11832 var outputLengthBytes = this.cfg.outputLength / 8; 11833 var outputLengthLanes = outputLengthBytes / 8; 11834 11835 // Squeeze 11836 var hashWords = []; 11837 for (var i = 0; i < outputLengthLanes; i++) { 11838 // Shortcuts 11839 var lane = state[i]; 11840 var laneMsw = lane.high; 11841 var laneLsw = lane.low; 11842 11843 // Swap endian 11844 laneMsw = ( 11845 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 11846 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 11847 ); 11848 laneLsw = ( 11849 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 11850 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 11851 ); 11852 11853 // Squeeze state to retrieve hash 11854 hashWords.push(laneLsw); 11855 hashWords.push(laneMsw); 11856 } 11857 11858 // Return final computed hash 11859 return new WordArray.init(hashWords, outputLengthBytes); 11860 }, 11861 11862 clone: function () { 11863 var clone = Hasher.clone.call(this); 11864 11865 var state = clone._state = this._state.slice(0); 11866 for (var i = 0; i < 25; i++) { 11867 state[i] = state[i].clone(); 11868 } 11869 11870 return clone; 11871 } 11872 }); 11873 11874 /** 11875 * Shortcut function to the hasher's object interface. 11876 * 11877 * @param {WordArray|string} message The message to hash. 11878 * 11879 * @return {WordArray} The hash. 11880 * 11881 * @static 11882 * 11883 * @example 11884 * 11885 * var hash = CryptoJS.SHA3('message'); 11886 * var hash = CryptoJS.SHA3(wordArray); 11887 */ 11888 C.SHA3 = Hasher._createHelper(SHA3); 11889 11890 /** 11891 * Shortcut function to the HMAC's object interface. 11892 * 11893 * @param {WordArray|string} message The message to hash. 11894 * @param {WordArray|string} key The secret key. 11895 * 11896 * @return {WordArray} The HMAC. 11897 * 11898 * @static 11899 * 11900 * @example 11901 * 11902 * var hmac = CryptoJS.HmacSHA3(message, key); 11903 */ 11904 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 11905 }(Math)); 11906 11907 11908 return CryptoJS.SHA3; 11909 11910 })); 11911 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 11912 ;(function (root, factory, undef) { 11913 if (typeof exports === "object") { 11914 // CommonJS 11915 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 11916 } 11917 else if (typeof define === "function" && define.amd) { 11918 // AMD 11919 define(["./core", "./x64-core", "./sha512"], factory); 11920 } 11921 else { 11922 // Global (browser) 11923 factory(root.CryptoJS); 11924 } 11925 }(this, function (CryptoJS) { 11926 11927 (function () { 11928 // Shortcuts 11929 var C = CryptoJS; 11930 var C_x64 = C.x64; 11931 var X64Word = C_x64.Word; 11932 var X64WordArray = C_x64.WordArray; 11933 var C_algo = C.algo; 11934 var SHA512 = C_algo.SHA512; 11935 11936 /** 11937 * SHA-384 hash algorithm. 11938 */ 11939 var SHA384 = C_algo.SHA384 = SHA512.extend({ 11940 _doReset: function () { 11941 this._hash = new X64WordArray.init([ 11942 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 11943 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 11944 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 11945 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 11946 ]); 11947 }, 11948 11949 _doFinalize: function () { 11950 var hash = SHA512._doFinalize.call(this); 11951 11952 hash.sigBytes -= 16; 11953 11954 return hash; 11955 } 11956 }); 11957 11958 /** 11959 * Shortcut function to the hasher's object interface. 11960 * 11961 * @param {WordArray|string} message The message to hash. 11962 * 11963 * @return {WordArray} The hash. 11964 * 11965 * @static 11966 * 11967 * @example 11968 * 11969 * var hash = CryptoJS.SHA384('message'); 11970 * var hash = CryptoJS.SHA384(wordArray); 11971 */ 11972 C.SHA384 = SHA512._createHelper(SHA384); 11973 11974 /** 11975 * Shortcut function to the HMAC's object interface. 11976 * 11977 * @param {WordArray|string} message The message to hash. 11978 * @param {WordArray|string} key The secret key. 11979 * 11980 * @return {WordArray} The HMAC. 11981 * 11982 * @static 11983 * 11984 * @example 11985 * 11986 * var hmac = CryptoJS.HmacSHA384(message, key); 11987 */ 11988 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 11989 }()); 11990 11991 11992 return CryptoJS.SHA384; 11993 11994 })); 11995 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 11996 ;(function (root, factory, undef) { 11997 if (typeof exports === "object") { 11998 // CommonJS 11999 module.exports = exports = factory(require("./core"), require("./x64-core")); 12000 } 12001 else if (typeof define === "function" && define.amd) { 12002 // AMD 12003 define(["./core", "./x64-core"], factory); 12004 } 12005 else { 12006 // Global (browser) 12007 factory(root.CryptoJS); 12008 } 12009 }(this, function (CryptoJS) { 12010 12011 (function () { 12012 // Shortcuts 12013 var C = CryptoJS; 12014 var C_lib = C.lib; 12015 var Hasher = C_lib.Hasher; 12016 var C_x64 = C.x64; 12017 var X64Word = C_x64.Word; 12018 var X64WordArray = C_x64.WordArray; 12019 var C_algo = C.algo; 12020 12021 function X64Word_create() { 12022 return X64Word.create.apply(X64Word, arguments); 12023 } 12024 12025 // Constants 12026 var K = [ 12027 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12028 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12029 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12030 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12031 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12032 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12033 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12034 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12035 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12036 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12037 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12038 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12039 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12040 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12041 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12042 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12043 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12044 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12045 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12046 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12047 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12048 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12049 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12050 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12051 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12052 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12053 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12054 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12055 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12056 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12057 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12058 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12059 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12060 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12061 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12062 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12063 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12064 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12065 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12066 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12067 ]; 12068 12069 // Reusable objects 12070 var W = []; 12071 (function () { 12072 for (var i = 0; i < 80; i++) { 12073 W[i] = X64Word_create(); 12074 } 12075 }()); 12076 12077 /** 12078 * SHA-512 hash algorithm. 12079 */ 12080 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12081 _doReset: function () { 12082 this._hash = new X64WordArray.init([ 12083 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12084 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12085 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12086 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12087 ]); 12088 }, 12089 12090 _doProcessBlock: function (M, offset) { 12091 // Shortcuts 12092 var H = this._hash.words; 12093 12094 var H0 = H[0]; 12095 var H1 = H[1]; 12096 var H2 = H[2]; 12097 var H3 = H[3]; 12098 var H4 = H[4]; 12099 var H5 = H[5]; 12100 var H6 = H[6]; 12101 var H7 = H[7]; 12102 12103 var H0h = H0.high; 12104 var H0l = H0.low; 12105 var H1h = H1.high; 12106 var H1l = H1.low; 12107 var H2h = H2.high; 12108 var H2l = H2.low; 12109 var H3h = H3.high; 12110 var H3l = H3.low; 12111 var H4h = H4.high; 12112 var H4l = H4.low; 12113 var H5h = H5.high; 12114 var H5l = H5.low; 12115 var H6h = H6.high; 12116 var H6l = H6.low; 12117 var H7h = H7.high; 12118 var H7l = H7.low; 12119 12120 // Working variables 12121 var ah = H0h; 12122 var al = H0l; 12123 var bh = H1h; 12124 var bl = H1l; 12125 var ch = H2h; 12126 var cl = H2l; 12127 var dh = H3h; 12128 var dl = H3l; 12129 var eh = H4h; 12130 var el = H4l; 12131 var fh = H5h; 12132 var fl = H5l; 12133 var gh = H6h; 12134 var gl = H6l; 12135 var hh = H7h; 12136 var hl = H7l; 12137 12138 // Rounds 12139 for (var i = 0; i < 80; i++) { 12140 // Shortcut 12141 var Wi = W[i]; 12142 12143 // Extend message 12144 if (i < 16) { 12145 var Wih = Wi.high = M[offset + i * 2] | 0; 12146 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12147 } else { 12148 // Gamma0 12149 var gamma0x = W[i - 15]; 12150 var gamma0xh = gamma0x.high; 12151 var gamma0xl = gamma0x.low; 12152 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12153 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12154 12155 // Gamma1 12156 var gamma1x = W[i - 2]; 12157 var gamma1xh = gamma1x.high; 12158 var gamma1xl = gamma1x.low; 12159 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12160 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12161 12162 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12163 var Wi7 = W[i - 7]; 12164 var Wi7h = Wi7.high; 12165 var Wi7l = Wi7.low; 12166 12167 var Wi16 = W[i - 16]; 12168 var Wi16h = Wi16.high; 12169 var Wi16l = Wi16.low; 12170 12171 var Wil = gamma0l + Wi7l; 12172 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12173 var Wil = Wil + gamma1l; 12174 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12175 var Wil = Wil + Wi16l; 12176 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12177 12178 Wi.high = Wih; 12179 Wi.low = Wil; 12180 } 12181 12182 var chh = (eh & fh) ^ (~eh & gh); 12183 var chl = (el & fl) ^ (~el & gl); 12184 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12185 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12186 12187 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12188 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12189 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12190 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12191 12192 // t1 = h + sigma1 + ch + K[i] + W[i] 12193 var Ki = K[i]; 12194 var Kih = Ki.high; 12195 var Kil = Ki.low; 12196 12197 var t1l = hl + sigma1l; 12198 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12199 var t1l = t1l + chl; 12200 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12201 var t1l = t1l + Kil; 12202 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12203 var t1l = t1l + Wil; 12204 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12205 12206 // t2 = sigma0 + maj 12207 var t2l = sigma0l + majl; 12208 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12209 12210 // Update working variables 12211 hh = gh; 12212 hl = gl; 12213 gh = fh; 12214 gl = fl; 12215 fh = eh; 12216 fl = el; 12217 el = (dl + t1l) | 0; 12218 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12219 dh = ch; 12220 dl = cl; 12221 ch = bh; 12222 cl = bl; 12223 bh = ah; 12224 bl = al; 12225 al = (t1l + t2l) | 0; 12226 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12227 } 12228 12229 // Intermediate hash value 12230 H0l = H0.low = (H0l + al); 12231 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12232 H1l = H1.low = (H1l + bl); 12233 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12234 H2l = H2.low = (H2l + cl); 12235 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12236 H3l = H3.low = (H3l + dl); 12237 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12238 H4l = H4.low = (H4l + el); 12239 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12240 H5l = H5.low = (H5l + fl); 12241 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12242 H6l = H6.low = (H6l + gl); 12243 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12244 H7l = H7.low = (H7l + hl); 12245 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12246 }, 12247 12248 _doFinalize: function () { 12249 // Shortcuts 12250 var data = this._data; 12251 var dataWords = data.words; 12252 12253 var nBitsTotal = this._nDataBytes * 8; 12254 var nBitsLeft = data.sigBytes * 8; 12255 12256 // Add padding 12257 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12258 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12259 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12260 data.sigBytes = dataWords.length * 4; 12261 12262 // Hash final blocks 12263 this._process(); 12264 12265 // Convert hash to 32-bit word array before returning 12266 var hash = this._hash.toX32(); 12267 12268 // Return final computed hash 12269 return hash; 12270 }, 12271 12272 clone: function () { 12273 var clone = Hasher.clone.call(this); 12274 clone._hash = this._hash.clone(); 12275 12276 return clone; 12277 }, 12278 12279 blockSize: 1024/32 12280 }); 12281 12282 /** 12283 * Shortcut function to the hasher's object interface. 12284 * 12285 * @param {WordArray|string} message The message to hash. 12286 * 12287 * @return {WordArray} The hash. 12288 * 12289 * @static 12290 * 12291 * @example 12292 * 12293 * var hash = CryptoJS.SHA512('message'); 12294 * var hash = CryptoJS.SHA512(wordArray); 12295 */ 12296 C.SHA512 = Hasher._createHelper(SHA512); 12297 12298 /** 12299 * Shortcut function to the HMAC's object interface. 12300 * 12301 * @param {WordArray|string} message The message to hash. 12302 * @param {WordArray|string} key The secret key. 12303 * 12304 * @return {WordArray} The HMAC. 12305 * 12306 * @static 12307 * 12308 * @example 12309 * 12310 * var hmac = CryptoJS.HmacSHA512(message, key); 12311 */ 12312 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12313 }()); 12314 12315 12316 return CryptoJS.SHA512; 12317 12318 })); 12319 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 12320 ;(function (root, factory, undef) { 12321 if (typeof exports === "object") { 12322 // CommonJS 12323 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12324 } 12325 else if (typeof define === "function" && define.amd) { 12326 // AMD 12327 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12328 } 12329 else { 12330 // Global (browser) 12331 factory(root.CryptoJS); 12332 } 12333 }(this, function (CryptoJS) { 12334 12335 (function () { 12336 // Shortcuts 12337 var C = CryptoJS; 12338 var C_lib = C.lib; 12339 var WordArray = C_lib.WordArray; 12340 var BlockCipher = C_lib.BlockCipher; 12341 var C_algo = C.algo; 12342 12343 // Permuted Choice 1 constants 12344 var PC1 = [ 12345 57, 49, 41, 33, 25, 17, 9, 1, 12346 58, 50, 42, 34, 26, 18, 10, 2, 12347 59, 51, 43, 35, 27, 19, 11, 3, 12348 60, 52, 44, 36, 63, 55, 47, 39, 12349 31, 23, 15, 7, 62, 54, 46, 38, 12350 30, 22, 14, 6, 61, 53, 45, 37, 12351 29, 21, 13, 5, 28, 20, 12, 4 12352 ]; 12353 12354 // Permuted Choice 2 constants 12355 var PC2 = [ 12356 14, 17, 11, 24, 1, 5, 12357 3, 28, 15, 6, 21, 10, 12358 23, 19, 12, 4, 26, 8, 12359 16, 7, 27, 20, 13, 2, 12360 41, 52, 31, 37, 47, 55, 12361 30, 40, 51, 45, 33, 48, 12362 44, 49, 39, 56, 34, 53, 12363 46, 42, 50, 36, 29, 32 12364 ]; 12365 12366 // Cumulative bit shift constants 12367 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12368 12369 // SBOXes and round permutation constants 12370 var SBOX_P = [ 12371 { 12372 0x0: 0x808200, 12373 0x10000000: 0x8000, 12374 0x20000000: 0x808002, 12375 0x30000000: 0x2, 12376 0x40000000: 0x200, 12377 0x50000000: 0x808202, 12378 0x60000000: 0x800202, 12379 0x70000000: 0x800000, 12380 0x80000000: 0x202, 12381 0x90000000: 0x800200, 12382 0xa0000000: 0x8200, 12383 0xb0000000: 0x808000, 12384 0xc0000000: 0x8002, 12385 0xd0000000: 0x800002, 12386 0xe0000000: 0x0, 12387 0xf0000000: 0x8202, 12388 0x8000000: 0x0, 12389 0x18000000: 0x808202, 12390 0x28000000: 0x8202, 12391 0x38000000: 0x8000, 12392 0x48000000: 0x808200, 12393 0x58000000: 0x200, 12394 0x68000000: 0x808002, 12395 0x78000000: 0x2, 12396 0x88000000: 0x800200, 12397 0x98000000: 0x8200, 12398 0xa8000000: 0x808000, 12399 0xb8000000: 0x800202, 12400 0xc8000000: 0x800002, 12401 0xd8000000: 0x8002, 12402 0xe8000000: 0x202, 12403 0xf8000000: 0x800000, 12404 0x1: 0x8000, 12405 0x10000001: 0x2, 12406 0x20000001: 0x808200, 12407 0x30000001: 0x800000, 12408 0x40000001: 0x808002, 12409 0x50000001: 0x8200, 12410 0x60000001: 0x200, 12411 0x70000001: 0x800202, 12412 0x80000001: 0x808202, 12413 0x90000001: 0x808000, 12414 0xa0000001: 0x800002, 12415 0xb0000001: 0x8202, 12416 0xc0000001: 0x202, 12417 0xd0000001: 0x800200, 12418 0xe0000001: 0x8002, 12419 0xf0000001: 0x0, 12420 0x8000001: 0x808202, 12421 0x18000001: 0x808000, 12422 0x28000001: 0x800000, 12423 0x38000001: 0x200, 12424 0x48000001: 0x8000, 12425 0x58000001: 0x800002, 12426 0x68000001: 0x2, 12427 0x78000001: 0x8202, 12428 0x88000001: 0x8002, 12429 0x98000001: 0x800202, 12430 0xa8000001: 0x202, 12431 0xb8000001: 0x808200, 12432 0xc8000001: 0x800200, 12433 0xd8000001: 0x0, 12434 0xe8000001: 0x8200, 12435 0xf8000001: 0x808002 12436 }, 12437 { 12438 0x0: 0x40084010, 12439 0x1000000: 0x4000, 12440 0x2000000: 0x80000, 12441 0x3000000: 0x40080010, 12442 0x4000000: 0x40000010, 12443 0x5000000: 0x40084000, 12444 0x6000000: 0x40004000, 12445 0x7000000: 0x10, 12446 0x8000000: 0x84000, 12447 0x9000000: 0x40004010, 12448 0xa000000: 0x40000000, 12449 0xb000000: 0x84010, 12450 0xc000000: 0x80010, 12451 0xd000000: 0x0, 12452 0xe000000: 0x4010, 12453 0xf000000: 0x40080000, 12454 0x800000: 0x40004000, 12455 0x1800000: 0x84010, 12456 0x2800000: 0x10, 12457 0x3800000: 0x40004010, 12458 0x4800000: 0x40084010, 12459 0x5800000: 0x40000000, 12460 0x6800000: 0x80000, 12461 0x7800000: 0x40080010, 12462 0x8800000: 0x80010, 12463 0x9800000: 0x0, 12464 0xa800000: 0x4000, 12465 0xb800000: 0x40080000, 12466 0xc800000: 0x40000010, 12467 0xd800000: 0x84000, 12468 0xe800000: 0x40084000, 12469 0xf800000: 0x4010, 12470 0x10000000: 0x0, 12471 0x11000000: 0x40080010, 12472 0x12000000: 0x40004010, 12473 0x13000000: 0x40084000, 12474 0x14000000: 0x40080000, 12475 0x15000000: 0x10, 12476 0x16000000: 0x84010, 12477 0x17000000: 0x4000, 12478 0x18000000: 0x4010, 12479 0x19000000: 0x80000, 12480 0x1a000000: 0x80010, 12481 0x1b000000: 0x40000010, 12482 0x1c000000: 0x84000, 12483 0x1d000000: 0x40004000, 12484 0x1e000000: 0x40000000, 12485 0x1f000000: 0x40084010, 12486 0x10800000: 0x84010, 12487 0x11800000: 0x80000, 12488 0x12800000: 0x40080000, 12489 0x13800000: 0x4000, 12490 0x14800000: 0x40004000, 12491 0x15800000: 0x40084010, 12492 0x16800000: 0x10, 12493 0x17800000: 0x40000000, 12494 0x18800000: 0x40084000, 12495 0x19800000: 0x40000010, 12496 0x1a800000: 0x40004010, 12497 0x1b800000: 0x80010, 12498 0x1c800000: 0x0, 12499 0x1d800000: 0x4010, 12500 0x1e800000: 0x40080010, 12501 0x1f800000: 0x84000 12502 }, 12503 { 12504 0x0: 0x104, 12505 0x100000: 0x0, 12506 0x200000: 0x4000100, 12507 0x300000: 0x10104, 12508 0x400000: 0x10004, 12509 0x500000: 0x4000004, 12510 0x600000: 0x4010104, 12511 0x700000: 0x4010000, 12512 0x800000: 0x4000000, 12513 0x900000: 0x4010100, 12514 0xa00000: 0x10100, 12515 0xb00000: 0x4010004, 12516 0xc00000: 0x4000104, 12517 0xd00000: 0x10000, 12518 0xe00000: 0x4, 12519 0xf00000: 0x100, 12520 0x80000: 0x4010100, 12521 0x180000: 0x4010004, 12522 0x280000: 0x0, 12523 0x380000: 0x4000100, 12524 0x480000: 0x4000004, 12525 0x580000: 0x10000, 12526 0x680000: 0x10004, 12527 0x780000: 0x104, 12528 0x880000: 0x4, 12529 0x980000: 0x100, 12530 0xa80000: 0x4010000, 12531 0xb80000: 0x10104, 12532 0xc80000: 0x10100, 12533 0xd80000: 0x4000104, 12534 0xe80000: 0x4010104, 12535 0xf80000: 0x4000000, 12536 0x1000000: 0x4010100, 12537 0x1100000: 0x10004, 12538 0x1200000: 0x10000, 12539 0x1300000: 0x4000100, 12540 0x1400000: 0x100, 12541 0x1500000: 0x4010104, 12542 0x1600000: 0x4000004, 12543 0x1700000: 0x0, 12544 0x1800000: 0x4000104, 12545 0x1900000: 0x4000000, 12546 0x1a00000: 0x4, 12547 0x1b00000: 0x10100, 12548 0x1c00000: 0x4010000, 12549 0x1d00000: 0x104, 12550 0x1e00000: 0x10104, 12551 0x1f00000: 0x4010004, 12552 0x1080000: 0x4000000, 12553 0x1180000: 0x104, 12554 0x1280000: 0x4010100, 12555 0x1380000: 0x0, 12556 0x1480000: 0x10004, 12557 0x1580000: 0x4000100, 12558 0x1680000: 0x100, 12559 0x1780000: 0x4010004, 12560 0x1880000: 0x10000, 12561 0x1980000: 0x4010104, 12562 0x1a80000: 0x10104, 12563 0x1b80000: 0x4000004, 12564 0x1c80000: 0x4000104, 12565 0x1d80000: 0x4010000, 12566 0x1e80000: 0x4, 12567 0x1f80000: 0x10100 12568 }, 12569 { 12570 0x0: 0x80401000, 12571 0x10000: 0x80001040, 12572 0x20000: 0x401040, 12573 0x30000: 0x80400000, 12574 0x40000: 0x0, 12575 0x50000: 0x401000, 12576 0x60000: 0x80000040, 12577 0x70000: 0x400040, 12578 0x80000: 0x80000000, 12579 0x90000: 0x400000, 12580 0xa0000: 0x40, 12581 0xb0000: 0x80001000, 12582 0xc0000: 0x80400040, 12583 0xd0000: 0x1040, 12584 0xe0000: 0x1000, 12585 0xf0000: 0x80401040, 12586 0x8000: 0x80001040, 12587 0x18000: 0x40, 12588 0x28000: 0x80400040, 12589 0x38000: 0x80001000, 12590 0x48000: 0x401000, 12591 0x58000: 0x80401040, 12592 0x68000: 0x0, 12593 0x78000: 0x80400000, 12594 0x88000: 0x1000, 12595 0x98000: 0x80401000, 12596 0xa8000: 0x400000, 12597 0xb8000: 0x1040, 12598 0xc8000: 0x80000000, 12599 0xd8000: 0x400040, 12600 0xe8000: 0x401040, 12601 0xf8000: 0x80000040, 12602 0x100000: 0x400040, 12603 0x110000: 0x401000, 12604 0x120000: 0x80000040, 12605 0x130000: 0x0, 12606 0x140000: 0x1040, 12607 0x150000: 0x80400040, 12608 0x160000: 0x80401000, 12609 0x170000: 0x80001040, 12610 0x180000: 0x80401040, 12611 0x190000: 0x80000000, 12612 0x1a0000: 0x80400000, 12613 0x1b0000: 0x401040, 12614 0x1c0000: 0x80001000, 12615 0x1d0000: 0x400000, 12616 0x1e0000: 0x40, 12617 0x1f0000: 0x1000, 12618 0x108000: 0x80400000, 12619 0x118000: 0x80401040, 12620 0x128000: 0x0, 12621 0x138000: 0x401000, 12622 0x148000: 0x400040, 12623 0x158000: 0x80000000, 12624 0x168000: 0x80001040, 12625 0x178000: 0x40, 12626 0x188000: 0x80000040, 12627 0x198000: 0x1000, 12628 0x1a8000: 0x80001000, 12629 0x1b8000: 0x80400040, 12630 0x1c8000: 0x1040, 12631 0x1d8000: 0x80401000, 12632 0x1e8000: 0x400000, 12633 0x1f8000: 0x401040 12634 }, 12635 { 12636 0x0: 0x80, 12637 0x1000: 0x1040000, 12638 0x2000: 0x40000, 12639 0x3000: 0x20000000, 12640 0x4000: 0x20040080, 12641 0x5000: 0x1000080, 12642 0x6000: 0x21000080, 12643 0x7000: 0x40080, 12644 0x8000: 0x1000000, 12645 0x9000: 0x20040000, 12646 0xa000: 0x20000080, 12647 0xb000: 0x21040080, 12648 0xc000: 0x21040000, 12649 0xd000: 0x0, 12650 0xe000: 0x1040080, 12651 0xf000: 0x21000000, 12652 0x800: 0x1040080, 12653 0x1800: 0x21000080, 12654 0x2800: 0x80, 12655 0x3800: 0x1040000, 12656 0x4800: 0x40000, 12657 0x5800: 0x20040080, 12658 0x6800: 0x21040000, 12659 0x7800: 0x20000000, 12660 0x8800: 0x20040000, 12661 0x9800: 0x0, 12662 0xa800: 0x21040080, 12663 0xb800: 0x1000080, 12664 0xc800: 0x20000080, 12665 0xd800: 0x21000000, 12666 0xe800: 0x1000000, 12667 0xf800: 0x40080, 12668 0x10000: 0x40000, 12669 0x11000: 0x80, 12670 0x12000: 0x20000000, 12671 0x13000: 0x21000080, 12672 0x14000: 0x1000080, 12673 0x15000: 0x21040000, 12674 0x16000: 0x20040080, 12675 0x17000: 0x1000000, 12676 0x18000: 0x21040080, 12677 0x19000: 0x21000000, 12678 0x1a000: 0x1040000, 12679 0x1b000: 0x20040000, 12680 0x1c000: 0x40080, 12681 0x1d000: 0x20000080, 12682 0x1e000: 0x0, 12683 0x1f000: 0x1040080, 12684 0x10800: 0x21000080, 12685 0x11800: 0x1000000, 12686 0x12800: 0x1040000, 12687 0x13800: 0x20040080, 12688 0x14800: 0x20000000, 12689 0x15800: 0x1040080, 12690 0x16800: 0x80, 12691 0x17800: 0x21040000, 12692 0x18800: 0x40080, 12693 0x19800: 0x21040080, 12694 0x1a800: 0x0, 12695 0x1b800: 0x21000000, 12696 0x1c800: 0x1000080, 12697 0x1d800: 0x40000, 12698 0x1e800: 0x20040000, 12699 0x1f800: 0x20000080 12700 }, 12701 { 12702 0x0: 0x10000008, 12703 0x100: 0x2000, 12704 0x200: 0x10200000, 12705 0x300: 0x10202008, 12706 0x400: 0x10002000, 12707 0x500: 0x200000, 12708 0x600: 0x200008, 12709 0x700: 0x10000000, 12710 0x800: 0x0, 12711 0x900: 0x10002008, 12712 0xa00: 0x202000, 12713 0xb00: 0x8, 12714 0xc00: 0x10200008, 12715 0xd00: 0x202008, 12716 0xe00: 0x2008, 12717 0xf00: 0x10202000, 12718 0x80: 0x10200000, 12719 0x180: 0x10202008, 12720 0x280: 0x8, 12721 0x380: 0x200000, 12722 0x480: 0x202008, 12723 0x580: 0x10000008, 12724 0x680: 0x10002000, 12725 0x780: 0x2008, 12726 0x880: 0x200008, 12727 0x980: 0x2000, 12728 0xa80: 0x10002008, 12729 0xb80: 0x10200008, 12730 0xc80: 0x0, 12731 0xd80: 0x10202000, 12732 0xe80: 0x202000, 12733 0xf80: 0x10000000, 12734 0x1000: 0x10002000, 12735 0x1100: 0x10200008, 12736 0x1200: 0x10202008, 12737 0x1300: 0x2008, 12738 0x1400: 0x200000, 12739 0x1500: 0x10000000, 12740 0x1600: 0x10000008, 12741 0x1700: 0x202000, 12742 0x1800: 0x202008, 12743 0x1900: 0x0, 12744 0x1a00: 0x8, 12745 0x1b00: 0x10200000, 12746 0x1c00: 0x2000, 12747 0x1d00: 0x10002008, 12748 0x1e00: 0x10202000, 12749 0x1f00: 0x200008, 12750 0x1080: 0x8, 12751 0x1180: 0x202000, 12752 0x1280: 0x200000, 12753 0x1380: 0x10000008, 12754 0x1480: 0x10002000, 12755 0x1580: 0x2008, 12756 0x1680: 0x10202008, 12757 0x1780: 0x10200000, 12758 0x1880: 0x10202000, 12759 0x1980: 0x10200008, 12760 0x1a80: 0x2000, 12761 0x1b80: 0x202008, 12762 0x1c80: 0x200008, 12763 0x1d80: 0x0, 12764 0x1e80: 0x10000000, 12765 0x1f80: 0x10002008 12766 }, 12767 { 12768 0x0: 0x100000, 12769 0x10: 0x2000401, 12770 0x20: 0x400, 12771 0x30: 0x100401, 12772 0x40: 0x2100401, 12773 0x50: 0x0, 12774 0x60: 0x1, 12775 0x70: 0x2100001, 12776 0x80: 0x2000400, 12777 0x90: 0x100001, 12778 0xa0: 0x2000001, 12779 0xb0: 0x2100400, 12780 0xc0: 0x2100000, 12781 0xd0: 0x401, 12782 0xe0: 0x100400, 12783 0xf0: 0x2000000, 12784 0x8: 0x2100001, 12785 0x18: 0x0, 12786 0x28: 0x2000401, 12787 0x38: 0x2100400, 12788 0x48: 0x100000, 12789 0x58: 0x2000001, 12790 0x68: 0x2000000, 12791 0x78: 0x401, 12792 0x88: 0x100401, 12793 0x98: 0x2000400, 12794 0xa8: 0x2100000, 12795 0xb8: 0x100001, 12796 0xc8: 0x400, 12797 0xd8: 0x2100401, 12798 0xe8: 0x1, 12799 0xf8: 0x100400, 12800 0x100: 0x2000000, 12801 0x110: 0x100000, 12802 0x120: 0x2000401, 12803 0x130: 0x2100001, 12804 0x140: 0x100001, 12805 0x150: 0x2000400, 12806 0x160: 0x2100400, 12807 0x170: 0x100401, 12808 0x180: 0x401, 12809 0x190: 0x2100401, 12810 0x1a0: 0x100400, 12811 0x1b0: 0x1, 12812 0x1c0: 0x0, 12813 0x1d0: 0x2100000, 12814 0x1e0: 0x2000001, 12815 0x1f0: 0x400, 12816 0x108: 0x100400, 12817 0x118: 0x2000401, 12818 0x128: 0x2100001, 12819 0x138: 0x1, 12820 0x148: 0x2000000, 12821 0x158: 0x100000, 12822 0x168: 0x401, 12823 0x178: 0x2100400, 12824 0x188: 0x2000001, 12825 0x198: 0x2100000, 12826 0x1a8: 0x0, 12827 0x1b8: 0x2100401, 12828 0x1c8: 0x100401, 12829 0x1d8: 0x400, 12830 0x1e8: 0x2000400, 12831 0x1f8: 0x100001 12832 }, 12833 { 12834 0x0: 0x8000820, 12835 0x1: 0x20000, 12836 0x2: 0x8000000, 12837 0x3: 0x20, 12838 0x4: 0x20020, 12839 0x5: 0x8020820, 12840 0x6: 0x8020800, 12841 0x7: 0x800, 12842 0x8: 0x8020000, 12843 0x9: 0x8000800, 12844 0xa: 0x20800, 12845 0xb: 0x8020020, 12846 0xc: 0x820, 12847 0xd: 0x0, 12848 0xe: 0x8000020, 12849 0xf: 0x20820, 12850 0x80000000: 0x800, 12851 0x80000001: 0x8020820, 12852 0x80000002: 0x8000820, 12853 0x80000003: 0x8000000, 12854 0x80000004: 0x8020000, 12855 0x80000005: 0x20800, 12856 0x80000006: 0x20820, 12857 0x80000007: 0x20, 12858 0x80000008: 0x8000020, 12859 0x80000009: 0x820, 12860 0x8000000a: 0x20020, 12861 0x8000000b: 0x8020800, 12862 0x8000000c: 0x0, 12863 0x8000000d: 0x8020020, 12864 0x8000000e: 0x8000800, 12865 0x8000000f: 0x20000, 12866 0x10: 0x20820, 12867 0x11: 0x8020800, 12868 0x12: 0x20, 12869 0x13: 0x800, 12870 0x14: 0x8000800, 12871 0x15: 0x8000020, 12872 0x16: 0x8020020, 12873 0x17: 0x20000, 12874 0x18: 0x0, 12875 0x19: 0x20020, 12876 0x1a: 0x8020000, 12877 0x1b: 0x8000820, 12878 0x1c: 0x8020820, 12879 0x1d: 0x20800, 12880 0x1e: 0x820, 12881 0x1f: 0x8000000, 12882 0x80000010: 0x20000, 12883 0x80000011: 0x800, 12884 0x80000012: 0x8020020, 12885 0x80000013: 0x20820, 12886 0x80000014: 0x20, 12887 0x80000015: 0x8020000, 12888 0x80000016: 0x8000000, 12889 0x80000017: 0x8000820, 12890 0x80000018: 0x8020820, 12891 0x80000019: 0x8000020, 12892 0x8000001a: 0x8000800, 12893 0x8000001b: 0x0, 12894 0x8000001c: 0x20800, 12895 0x8000001d: 0x820, 12896 0x8000001e: 0x20020, 12897 0x8000001f: 0x8020800 12898 } 12899 ]; 12900 12901 // Masks that select the SBOX input 12902 var SBOX_MASK = [ 12903 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 12904 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 12905 ]; 12906 12907 /** 12908 * DES block cipher algorithm. 12909 */ 12910 var DES = C_algo.DES = BlockCipher.extend({ 12911 _doReset: function () { 12912 // Shortcuts 12913 var key = this._key; 12914 var keyWords = key.words; 12915 12916 // Select 56 bits according to PC1 12917 var keyBits = []; 12918 for (var i = 0; i < 56; i++) { 12919 var keyBitPos = PC1[i] - 1; 12920 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 12921 } 12922 12923 // Assemble 16 subkeys 12924 var subKeys = this._subKeys = []; 12925 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 12926 // Create subkey 12927 var subKey = subKeys[nSubKey] = []; 12928 12929 // Shortcut 12930 var bitShift = BIT_SHIFTS[nSubKey]; 12931 12932 // Select 48 bits according to PC2 12933 for (var i = 0; i < 24; i++) { 12934 // Select from the left 28 key bits 12935 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 12936 12937 // Select from the right 28 key bits 12938 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 12939 } 12940 12941 // Since each subkey is applied to an expanded 32-bit input, 12942 // the subkey can be broken into 8 values scaled to 32-bits, 12943 // which allows the key to be used without expansion 12944 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 12945 for (var i = 1; i < 7; i++) { 12946 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 12947 } 12948 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 12949 } 12950 12951 // Compute inverse subkeys 12952 var invSubKeys = this._invSubKeys = []; 12953 for (var i = 0; i < 16; i++) { 12954 invSubKeys[i] = subKeys[15 - i]; 12955 } 12956 }, 12957 12958 encryptBlock: function (M, offset) { 12959 this._doCryptBlock(M, offset, this._subKeys); 12960 }, 12961 12962 decryptBlock: function (M, offset) { 12963 this._doCryptBlock(M, offset, this._invSubKeys); 12964 }, 12965 12966 _doCryptBlock: function (M, offset, subKeys) { 12967 // Get input 12968 this._lBlock = M[offset]; 12969 this._rBlock = M[offset + 1]; 12970 12971 // Initial permutation 12972 exchangeLR.call(this, 4, 0x0f0f0f0f); 12973 exchangeLR.call(this, 16, 0x0000ffff); 12974 exchangeRL.call(this, 2, 0x33333333); 12975 exchangeRL.call(this, 8, 0x00ff00ff); 12976 exchangeLR.call(this, 1, 0x55555555); 12977 12978 // Rounds 12979 for (var round = 0; round < 16; round++) { 12980 // Shortcuts 12981 var subKey = subKeys[round]; 12982 var lBlock = this._lBlock; 12983 var rBlock = this._rBlock; 12984 12985 // Feistel function 12986 var f = 0; 12987 for (var i = 0; i < 8; i++) { 12988 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 12989 } 12990 this._lBlock = rBlock; 12991 this._rBlock = lBlock ^ f; 12992 } 12993 12994 // Undo swap from last round 12995 var t = this._lBlock; 12996 this._lBlock = this._rBlock; 12997 this._rBlock = t; 12998 12999 // Final permutation 13000 exchangeLR.call(this, 1, 0x55555555); 13001 exchangeRL.call(this, 8, 0x00ff00ff); 13002 exchangeRL.call(this, 2, 0x33333333); 13003 exchangeLR.call(this, 16, 0x0000ffff); 13004 exchangeLR.call(this, 4, 0x0f0f0f0f); 13005 13006 // Set output 13007 M[offset] = this._lBlock; 13008 M[offset + 1] = this._rBlock; 13009 }, 13010 13011 keySize: 64/32, 13012 13013 ivSize: 64/32, 13014 13015 blockSize: 64/32 13016 }); 13017 13018 // Swap bits across the left and right words 13019 function exchangeLR(offset, mask) { 13020 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13021 this._rBlock ^= t; 13022 this._lBlock ^= t << offset; 13023 } 13024 13025 function exchangeRL(offset, mask) { 13026 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13027 this._lBlock ^= t; 13028 this._rBlock ^= t << offset; 13029 } 13030 13031 /** 13032 * Shortcut functions to the cipher's object interface. 13033 * 13034 * @example 13035 * 13036 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13037 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13038 */ 13039 C.DES = BlockCipher._createHelper(DES); 13040 13041 /** 13042 * Triple-DES block cipher algorithm. 13043 */ 13044 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13045 _doReset: function () { 13046 // Shortcuts 13047 var key = this._key; 13048 var keyWords = key.words; 13049 13050 // Create DES instances 13051 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13052 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13053 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13054 }, 13055 13056 encryptBlock: function (M, offset) { 13057 this._des1.encryptBlock(M, offset); 13058 this._des2.decryptBlock(M, offset); 13059 this._des3.encryptBlock(M, offset); 13060 }, 13061 13062 decryptBlock: function (M, offset) { 13063 this._des3.decryptBlock(M, offset); 13064 this._des2.encryptBlock(M, offset); 13065 this._des1.decryptBlock(M, offset); 13066 }, 13067 13068 keySize: 192/32, 13069 13070 ivSize: 64/32, 13071 13072 blockSize: 64/32 13073 }); 13074 13075 /** 13076 * Shortcut functions to the cipher's object interface. 13077 * 13078 * @example 13079 * 13080 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13081 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13082 */ 13083 C.TripleDES = BlockCipher._createHelper(TripleDES); 13084 }()); 13085 13086 13087 return CryptoJS.TripleDES; 13088 13089 })); 13090 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 13091 ;(function (root, factory) { 13092 if (typeof exports === "object") { 13093 // CommonJS 13094 module.exports = exports = factory(require("./core")); 13095 } 13096 else if (typeof define === "function" && define.amd) { 13097 // AMD 13098 define(["./core"], factory); 13099 } 13100 else { 13101 // Global (browser) 13102 factory(root.CryptoJS); 13103 } 13104 }(this, function (CryptoJS) { 13105 13106 (function (undefined) { 13107 // Shortcuts 13108 var C = CryptoJS; 13109 var C_lib = C.lib; 13110 var Base = C_lib.Base; 13111 var X32WordArray = C_lib.WordArray; 13112 13113 /** 13114 * x64 namespace. 13115 */ 13116 var C_x64 = C.x64 = {}; 13117 13118 /** 13119 * A 64-bit word. 13120 */ 13121 var X64Word = C_x64.Word = Base.extend({ 13122 /** 13123 * Initializes a newly created 64-bit word. 13124 * 13125 * @param {number} high The high 32 bits. 13126 * @param {number} low The low 32 bits. 13127 * 13128 * @example 13129 * 13130 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13131 */ 13132 init: function (high, low) { 13133 this.high = high; 13134 this.low = low; 13135 } 13136 13137 /** 13138 * Bitwise NOTs this word. 13139 * 13140 * @return {X64Word} A new x64-Word object after negating. 13141 * 13142 * @example 13143 * 13144 * var negated = x64Word.not(); 13145 */ 13146 // not: function () { 13147 // var high = ~this.high; 13148 // var low = ~this.low; 13149 13150 // return X64Word.create(high, low); 13151 // }, 13152 13153 /** 13154 * Bitwise ANDs this word with the passed word. 13155 * 13156 * @param {X64Word} word The x64-Word to AND with this word. 13157 * 13158 * @return {X64Word} A new x64-Word object after ANDing. 13159 * 13160 * @example 13161 * 13162 * var anded = x64Word.and(anotherX64Word); 13163 */ 13164 // and: function (word) { 13165 // var high = this.high & word.high; 13166 // var low = this.low & word.low; 13167 13168 // return X64Word.create(high, low); 13169 // }, 13170 13171 /** 13172 * Bitwise ORs this word with the passed word. 13173 * 13174 * @param {X64Word} word The x64-Word to OR with this word. 13175 * 13176 * @return {X64Word} A new x64-Word object after ORing. 13177 * 13178 * @example 13179 * 13180 * var ored = x64Word.or(anotherX64Word); 13181 */ 13182 // or: function (word) { 13183 // var high = this.high | word.high; 13184 // var low = this.low | word.low; 13185 13186 // return X64Word.create(high, low); 13187 // }, 13188 13189 /** 13190 * Bitwise XORs this word with the passed word. 13191 * 13192 * @param {X64Word} word The x64-Word to XOR with this word. 13193 * 13194 * @return {X64Word} A new x64-Word object after XORing. 13195 * 13196 * @example 13197 * 13198 * var xored = x64Word.xor(anotherX64Word); 13199 */ 13200 // xor: function (word) { 13201 // var high = this.high ^ word.high; 13202 // var low = this.low ^ word.low; 13203 13204 // return X64Word.create(high, low); 13205 // }, 13206 13207 /** 13208 * Shifts this word n bits to the left. 13209 * 13210 * @param {number} n The number of bits to shift. 13211 * 13212 * @return {X64Word} A new x64-Word object after shifting. 13213 * 13214 * @example 13215 * 13216 * var shifted = x64Word.shiftL(25); 13217 */ 13218 // shiftL: function (n) { 13219 // if (n < 32) { 13220 // var high = (this.high << n) | (this.low >>> (32 - n)); 13221 // var low = this.low << n; 13222 // } else { 13223 // var high = this.low << (n - 32); 13224 // var low = 0; 13225 // } 13226 13227 // return X64Word.create(high, low); 13228 // }, 13229 13230 /** 13231 * Shifts this word n bits to the right. 13232 * 13233 * @param {number} n The number of bits to shift. 13234 * 13235 * @return {X64Word} A new x64-Word object after shifting. 13236 * 13237 * @example 13238 * 13239 * var shifted = x64Word.shiftR(7); 13240 */ 13241 // shiftR: function (n) { 13242 // if (n < 32) { 13243 // var low = (this.low >>> n) | (this.high << (32 - n)); 13244 // var high = this.high >>> n; 13245 // } else { 13246 // var low = this.high >>> (n - 32); 13247 // var high = 0; 13248 // } 13249 13250 // return X64Word.create(high, low); 13251 // }, 13252 13253 /** 13254 * Rotates this word n bits to the left. 13255 * 13256 * @param {number} n The number of bits to rotate. 13257 * 13258 * @return {X64Word} A new x64-Word object after rotating. 13259 * 13260 * @example 13261 * 13262 * var rotated = x64Word.rotL(25); 13263 */ 13264 // rotL: function (n) { 13265 // return this.shiftL(n).or(this.shiftR(64 - n)); 13266 // }, 13267 13268 /** 13269 * Rotates this word n bits to the right. 13270 * 13271 * @param {number} n The number of bits to rotate. 13272 * 13273 * @return {X64Word} A new x64-Word object after rotating. 13274 * 13275 * @example 13276 * 13277 * var rotated = x64Word.rotR(7); 13278 */ 13279 // rotR: function (n) { 13280 // return this.shiftR(n).or(this.shiftL(64 - n)); 13281 // }, 13282 13283 /** 13284 * Adds this word with the passed word. 13285 * 13286 * @param {X64Word} word The x64-Word to add with this word. 13287 * 13288 * @return {X64Word} A new x64-Word object after adding. 13289 * 13290 * @example 13291 * 13292 * var added = x64Word.add(anotherX64Word); 13293 */ 13294 // add: function (word) { 13295 // var low = (this.low + word.low) | 0; 13296 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13297 // var high = (this.high + word.high + carry) | 0; 13298 13299 // return X64Word.create(high, low); 13300 // } 13301 }); 13302 13303 /** 13304 * An array of 64-bit words. 13305 * 13306 * @property {Array} words The array of CryptoJS.x64.Word objects. 13307 * @property {number} sigBytes The number of significant bytes in this word array. 13308 */ 13309 var X64WordArray = C_x64.WordArray = Base.extend({ 13310 /** 13311 * Initializes a newly created word array. 13312 * 13313 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13314 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13315 * 13316 * @example 13317 * 13318 * var wordArray = CryptoJS.x64.WordArray.create(); 13319 * 13320 * var wordArray = CryptoJS.x64.WordArray.create([ 13321 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13322 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13323 * ]); 13324 * 13325 * var wordArray = CryptoJS.x64.WordArray.create([ 13326 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13327 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13328 * ], 10); 13329 */ 13330 init: function (words, sigBytes) { 13331 words = this.words = words || []; 13332 13333 if (sigBytes != undefined) { 13334 this.sigBytes = sigBytes; 13335 } else { 13336 this.sigBytes = words.length * 8; 13337 } 13338 }, 13339 13340 /** 13341 * Converts this 64-bit word array to a 32-bit word array. 13342 * 13343 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13344 * 13345 * @example 13346 * 13347 * var x32WordArray = x64WordArray.toX32(); 13348 */ 13349 toX32: function () { 13350 // Shortcuts 13351 var x64Words = this.words; 13352 var x64WordsLength = x64Words.length; 13353 13354 // Convert 13355 var x32Words = []; 13356 for (var i = 0; i < x64WordsLength; i++) { 13357 var x64Word = x64Words[i]; 13358 x32Words.push(x64Word.high); 13359 x32Words.push(x64Word.low); 13360 } 13361 13362 return X32WordArray.create(x32Words, this.sigBytes); 13363 }, 13364 13365 /** 13366 * Creates a copy of this word array. 13367 * 13368 * @return {X64WordArray} The clone. 13369 * 13370 * @example 13371 * 13372 * var clone = x64WordArray.clone(); 13373 */ 13374 clone: function () { 13375 var clone = Base.clone.call(this); 13376 13377 // Clone "words" array 13378 var words = clone.words = this.words.slice(0); 13379 13380 // Clone each X64Word object 13381 var wordsLength = words.length; 13382 for (var i = 0; i < wordsLength; i++) { 13383 words[i] = words[i].clone(); 13384 } 13385 13386 return clone; 13387 } 13388 }); 13389 }()); 13390 13391 13392 return CryptoJS; 13393 13394 })); 13395 },{"./core":53}],85:[function(require,module,exports){ 13396 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13397 ;(function(root) { 13398 13399 // Detect free variables `exports` 13400 var freeExports = typeof exports == 'object' && exports; 13401 13402 // Detect free variable `module` 13403 var freeModule = typeof module == 'object' && module && 13404 module.exports == freeExports && module; 13405 13406 // Detect free variable `global`, from Node.js or Browserified code, 13407 // and use it as `root` 13408 var freeGlobal = typeof global == 'object' && global; 13409 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13410 root = freeGlobal; 13411 } 13412 13413 /*--------------------------------------------------------------------------*/ 13414 13415 var stringFromCharCode = String.fromCharCode; 13416 13417 // Taken from https://mths.be/punycode 13418 function ucs2decode(string) { 13419 var output = []; 13420 var counter = 0; 13421 var length = string.length; 13422 var value; 13423 var extra; 13424 while (counter < length) { 13425 value = string.charCodeAt(counter++); 13426 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13427 // high surrogate, and there is a next character 13428 extra = string.charCodeAt(counter++); 13429 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13430 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13431 } else { 13432 // unmatched surrogate; only append this code unit, in case the next 13433 // code unit is the high surrogate of a surrogate pair 13434 output.push(value); 13435 counter--; 13436 } 13437 } else { 13438 output.push(value); 13439 } 13440 } 13441 return output; 13442 } 13443 13444 // Taken from https://mths.be/punycode 13445 function ucs2encode(array) { 13446 var length = array.length; 13447 var index = -1; 13448 var value; 13449 var output = ''; 13450 while (++index < length) { 13451 value = array[index]; 13452 if (value > 0xFFFF) { 13453 value -= 0x10000; 13454 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13455 value = 0xDC00 | value & 0x3FF; 13456 } 13457 output += stringFromCharCode(value); 13458 } 13459 return output; 13460 } 13461 13462 function checkScalarValue(codePoint) { 13463 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13464 throw Error( 13465 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13466 ' is not a scalar value' 13467 ); 13468 } 13469 } 13470 /*--------------------------------------------------------------------------*/ 13471 13472 function createByte(codePoint, shift) { 13473 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13474 } 13475 13476 function encodeCodePoint(codePoint) { 13477 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13478 return stringFromCharCode(codePoint); 13479 } 13480 var symbol = ''; 13481 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13482 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13483 } 13484 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13485 checkScalarValue(codePoint); 13486 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13487 symbol += createByte(codePoint, 6); 13488 } 13489 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13490 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13491 symbol += createByte(codePoint, 12); 13492 symbol += createByte(codePoint, 6); 13493 } 13494 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13495 return symbol; 13496 } 13497 13498 function utf8encode(string) { 13499 var codePoints = ucs2decode(string); 13500 var length = codePoints.length; 13501 var index = -1; 13502 var codePoint; 13503 var byteString = ''; 13504 while (++index < length) { 13505 codePoint = codePoints[index]; 13506 byteString += encodeCodePoint(codePoint); 13507 } 13508 return byteString; 13509 } 13510 13511 /*--------------------------------------------------------------------------*/ 13512 13513 function readContinuationByte() { 13514 if (byteIndex >= byteCount) { 13515 throw Error('Invalid byte index'); 13516 } 13517 13518 var continuationByte = byteArray[byteIndex] & 0xFF; 13519 byteIndex++; 13520 13521 if ((continuationByte & 0xC0) == 0x80) { 13522 return continuationByte & 0x3F; 13523 } 13524 13525 // If we end up here, it’s not a continuation byte 13526 throw Error('Invalid continuation byte'); 13527 } 13528 13529 function decodeSymbol() { 13530 var byte1; 13531 var byte2; 13532 var byte3; 13533 var byte4; 13534 var codePoint; 13535 13536 if (byteIndex > byteCount) { 13537 throw Error('Invalid byte index'); 13538 } 13539 13540 if (byteIndex == byteCount) { 13541 return false; 13542 } 13543 13544 // Read first byte 13545 byte1 = byteArray[byteIndex] & 0xFF; 13546 byteIndex++; 13547 13548 // 1-byte sequence (no continuation bytes) 13549 if ((byte1 & 0x80) == 0) { 13550 return byte1; 13551 } 13552 13553 // 2-byte sequence 13554 if ((byte1 & 0xE0) == 0xC0) { 13555 byte2 = readContinuationByte(); 13556 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13557 if (codePoint >= 0x80) { 13558 return codePoint; 13559 } else { 13560 throw Error('Invalid continuation byte'); 13561 } 13562 } 13563 13564 // 3-byte sequence (may include unpaired surrogates) 13565 if ((byte1 & 0xF0) == 0xE0) { 13566 byte2 = readContinuationByte(); 13567 byte3 = readContinuationByte(); 13568 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13569 if (codePoint >= 0x0800) { 13570 checkScalarValue(codePoint); 13571 return codePoint; 13572 } else { 13573 throw Error('Invalid continuation byte'); 13574 } 13575 } 13576 13577 // 4-byte sequence 13578 if ((byte1 & 0xF8) == 0xF0) { 13579 byte2 = readContinuationByte(); 13580 byte3 = readContinuationByte(); 13581 byte4 = readContinuationByte(); 13582 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 13583 (byte3 << 0x06) | byte4; 13584 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 13585 return codePoint; 13586 } 13587 } 13588 13589 throw Error('Invalid UTF-8 detected'); 13590 } 13591 13592 var byteArray; 13593 var byteCount; 13594 var byteIndex; 13595 function utf8decode(byteString) { 13596 byteArray = ucs2decode(byteString); 13597 byteCount = byteArray.length; 13598 byteIndex = 0; 13599 var codePoints = []; 13600 var tmp; 13601 while ((tmp = decodeSymbol()) !== false) { 13602 codePoints.push(tmp); 13603 } 13604 return ucs2encode(codePoints); 13605 } 13606 13607 /*--------------------------------------------------------------------------*/ 13608 13609 var utf8 = { 13610 'version': '2.1.2', 13611 'encode': utf8encode, 13612 'decode': utf8decode 13613 }; 13614 13615 // Some AMD build optimizers, like r.js, check for specific condition patterns 13616 // like the following: 13617 if ( 13618 typeof define == 'function' && 13619 typeof define.amd == 'object' && 13620 define.amd 13621 ) { 13622 define(function() { 13623 return utf8; 13624 }); 13625 } else if (freeExports && !freeExports.nodeType) { 13626 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 13627 freeModule.exports = utf8; 13628 } else { // in Narwhal or RingoJS v0.7.0- 13629 var object = {}; 13630 var hasOwnProperty = object.hasOwnProperty; 13631 for (var key in utf8) { 13632 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 13633 } 13634 } 13635 } else { // in Rhino or a web browser 13636 root.utf8 = utf8; 13637 } 13638 13639 }(this)); 13640 13641 },{}],86:[function(require,module,exports){ 13642 module.exports = XMLHttpRequest; 13643 13644 },{}],"bignumber.js":[function(require,module,exports){ 13645 'use strict'; 13646 13647 module.exports = BigNumber; // jshint ignore:line 13648 13649 13650 },{}],"web3":[function(require,module,exports){ 13651 var Web3 = require('./lib/web3'); 13652 13653 // don't override global variable 13654 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 13655 window.Web3 = Web3; 13656 } 13657 13658 module.exports = Web3; 13659 13660 },{"./lib/web3":22}]},{},["web3"]) 13661 //# sourceMappingURL=web3-light.js.map