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