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