github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/internal/jsre/deps/web3.js (about) 1 require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 2 module.exports=[ 3 { 4 "constant": true, 5 "inputs": [ 6 { 7 "name": "_owner", 8 "type": "address" 9 } 10 ], 11 "name": "name", 12 "outputs": [ 13 { 14 "name": "o_name", 15 "type": "bytes32" 16 } 17 ], 18 "type": "function" 19 }, 20 { 21 "constant": true, 22 "inputs": [ 23 { 24 "name": "_name", 25 "type": "bytes32" 26 } 27 ], 28 "name": "owner", 29 "outputs": [ 30 { 31 "name": "", 32 "type": "address" 33 } 34 ], 35 "type": "function" 36 }, 37 { 38 "constant": true, 39 "inputs": [ 40 { 41 "name": "_name", 42 "type": "bytes32" 43 } 44 ], 45 "name": "content", 46 "outputs": [ 47 { 48 "name": "", 49 "type": "bytes32" 50 } 51 ], 52 "type": "function" 53 }, 54 { 55 "constant": true, 56 "inputs": [ 57 { 58 "name": "_name", 59 "type": "bytes32" 60 } 61 ], 62 "name": "addr", 63 "outputs": [ 64 { 65 "name": "", 66 "type": "address" 67 } 68 ], 69 "type": "function" 70 }, 71 { 72 "constant": false, 73 "inputs": [ 74 { 75 "name": "_name", 76 "type": "bytes32" 77 } 78 ], 79 "name": "reserve", 80 "outputs": [], 81 "type": "function" 82 }, 83 { 84 "constant": true, 85 "inputs": [ 86 { 87 "name": "_name", 88 "type": "bytes32" 89 } 90 ], 91 "name": "subRegistrar", 92 "outputs": [ 93 { 94 "name": "", 95 "type": "address" 96 } 97 ], 98 "type": "function" 99 }, 100 { 101 "constant": false, 102 "inputs": [ 103 { 104 "name": "_name", 105 "type": "bytes32" 106 }, 107 { 108 "name": "_newOwner", 109 "type": "address" 110 } 111 ], 112 "name": "transfer", 113 "outputs": [], 114 "type": "function" 115 }, 116 { 117 "constant": false, 118 "inputs": [ 119 { 120 "name": "_name", 121 "type": "bytes32" 122 }, 123 { 124 "name": "_registrar", 125 "type": "address" 126 } 127 ], 128 "name": "setSubRegistrar", 129 "outputs": [], 130 "type": "function" 131 }, 132 { 133 "constant": false, 134 "inputs": [], 135 "name": "Registrar", 136 "outputs": [], 137 "type": "function" 138 }, 139 { 140 "constant": false, 141 "inputs": [ 142 { 143 "name": "_name", 144 "type": "bytes32" 145 }, 146 { 147 "name": "_a", 148 "type": "address" 149 }, 150 { 151 "name": "_primary", 152 "type": "bool" 153 } 154 ], 155 "name": "setAddress", 156 "outputs": [], 157 "type": "function" 158 }, 159 { 160 "constant": false, 161 "inputs": [ 162 { 163 "name": "_name", 164 "type": "bytes32" 165 }, 166 { 167 "name": "_content", 168 "type": "bytes32" 169 } 170 ], 171 "name": "setContent", 172 "outputs": [], 173 "type": "function" 174 }, 175 { 176 "constant": false, 177 "inputs": [ 178 { 179 "name": "_name", 180 "type": "bytes32" 181 } 182 ], 183 "name": "disown", 184 "outputs": [], 185 "type": "function" 186 }, 187 { 188 "anonymous": false, 189 "inputs": [ 190 { 191 "indexed": true, 192 "name": "_name", 193 "type": "bytes32" 194 }, 195 { 196 "indexed": false, 197 "name": "_winner", 198 "type": "address" 199 } 200 ], 201 "name": "AuctionEnded", 202 "type": "event" 203 }, 204 { 205 "anonymous": false, 206 "inputs": [ 207 { 208 "indexed": true, 209 "name": "_name", 210 "type": "bytes32" 211 }, 212 { 213 "indexed": false, 214 "name": "_bidder", 215 "type": "address" 216 }, 217 { 218 "indexed": false, 219 "name": "_value", 220 "type": "uint256" 221 } 222 ], 223 "name": "NewBid", 224 "type": "event" 225 }, 226 { 227 "anonymous": false, 228 "inputs": [ 229 { 230 "indexed": true, 231 "name": "name", 232 "type": "bytes32" 233 } 234 ], 235 "name": "Changed", 236 "type": "event" 237 }, 238 { 239 "anonymous": false, 240 "inputs": [ 241 { 242 "indexed": true, 243 "name": "name", 244 "type": "bytes32" 245 }, 246 { 247 "indexed": true, 248 "name": "addr", 249 "type": "address" 250 } 251 ], 252 "name": "PrimaryChanged", 253 "type": "event" 254 } 255 ] 256 257 },{}],2:[function(require,module,exports){ 258 module.exports=[ 259 { 260 "constant": true, 261 "inputs": [ 262 { 263 "name": "_name", 264 "type": "bytes32" 265 } 266 ], 267 "name": "owner", 268 "outputs": [ 269 { 270 "name": "", 271 "type": "address" 272 } 273 ], 274 "type": "function" 275 }, 276 { 277 "constant": false, 278 "inputs": [ 279 { 280 "name": "_name", 281 "type": "bytes32" 282 }, 283 { 284 "name": "_refund", 285 "type": "address" 286 } 287 ], 288 "name": "disown", 289 "outputs": [], 290 "type": "function" 291 }, 292 { 293 "constant": true, 294 "inputs": [ 295 { 296 "name": "_name", 297 "type": "bytes32" 298 } 299 ], 300 "name": "addr", 301 "outputs": [ 302 { 303 "name": "", 304 "type": "address" 305 } 306 ], 307 "type": "function" 308 }, 309 { 310 "constant": false, 311 "inputs": [ 312 { 313 "name": "_name", 314 "type": "bytes32" 315 } 316 ], 317 "name": "reserve", 318 "outputs": [], 319 "type": "function" 320 }, 321 { 322 "constant": false, 323 "inputs": [ 324 { 325 "name": "_name", 326 "type": "bytes32" 327 }, 328 { 329 "name": "_newOwner", 330 "type": "address" 331 } 332 ], 333 "name": "transfer", 334 "outputs": [], 335 "type": "function" 336 }, 337 { 338 "constant": false, 339 "inputs": [ 340 { 341 "name": "_name", 342 "type": "bytes32" 343 }, 344 { 345 "name": "_a", 346 "type": "address" 347 } 348 ], 349 "name": "setAddr", 350 "outputs": [], 351 "type": "function" 352 }, 353 { 354 "anonymous": false, 355 "inputs": [ 356 { 357 "indexed": true, 358 "name": "name", 359 "type": "bytes32" 360 } 361 ], 362 "name": "Changed", 363 "type": "event" 364 } 365 ] 366 367 },{}],3:[function(require,module,exports){ 368 module.exports=[ 369 { 370 "constant": false, 371 "inputs": [ 372 { 373 "name": "from", 374 "type": "bytes32" 375 }, 376 { 377 "name": "to", 378 "type": "address" 379 }, 380 { 381 "name": "value", 382 "type": "uint256" 383 } 384 ], 385 "name": "transfer", 386 "outputs": [], 387 "type": "function" 388 }, 389 { 390 "constant": false, 391 "inputs": [ 392 { 393 "name": "from", 394 "type": "bytes32" 395 }, 396 { 397 "name": "to", 398 "type": "address" 399 }, 400 { 401 "name": "indirectId", 402 "type": "bytes32" 403 }, 404 { 405 "name": "value", 406 "type": "uint256" 407 } 408 ], 409 "name": "icapTransfer", 410 "outputs": [], 411 "type": "function" 412 }, 413 { 414 "constant": false, 415 "inputs": [ 416 { 417 "name": "to", 418 "type": "bytes32" 419 } 420 ], 421 "name": "deposit", 422 "outputs": [], 423 "payable": true, 424 "type": "function" 425 }, 426 { 427 "anonymous": false, 428 "inputs": [ 429 { 430 "indexed": true, 431 "name": "from", 432 "type": "address" 433 }, 434 { 435 "indexed": false, 436 "name": "value", 437 "type": "uint256" 438 } 439 ], 440 "name": "AnonymousDeposit", 441 "type": "event" 442 }, 443 { 444 "anonymous": false, 445 "inputs": [ 446 { 447 "indexed": true, 448 "name": "from", 449 "type": "address" 450 }, 451 { 452 "indexed": true, 453 "name": "to", 454 "type": "bytes32" 455 }, 456 { 457 "indexed": false, 458 "name": "value", 459 "type": "uint256" 460 } 461 ], 462 "name": "Deposit", 463 "type": "event" 464 }, 465 { 466 "anonymous": false, 467 "inputs": [ 468 { 469 "indexed": true, 470 "name": "from", 471 "type": "bytes32" 472 }, 473 { 474 "indexed": true, 475 "name": "to", 476 "type": "address" 477 }, 478 { 479 "indexed": false, 480 "name": "value", 481 "type": "uint256" 482 } 483 ], 484 "name": "Transfer", 485 "type": "event" 486 }, 487 { 488 "anonymous": false, 489 "inputs": [ 490 { 491 "indexed": true, 492 "name": "from", 493 "type": "bytes32" 494 }, 495 { 496 "indexed": true, 497 "name": "to", 498 "type": "address" 499 }, 500 { 501 "indexed": false, 502 "name": "indirectId", 503 "type": "bytes32" 504 }, 505 { 506 "indexed": false, 507 "name": "value", 508 "type": "uint256" 509 } 510 ], 511 "name": "IcapTransfer", 512 "type": "event" 513 } 514 ] 515 516 },{}],4:[function(require,module,exports){ 517 var f = require('./formatters'); 518 var SolidityType = require('./type'); 519 520 /** 521 * SolidityTypeAddress is a prootype that represents address type 522 * It matches: 523 * address 524 * address[] 525 * address[4] 526 * address[][] 527 * address[3][] 528 * address[][6][], ... 529 */ 530 var SolidityTypeAddress = function () { 531 this._inputFormatter = f.formatInputInt; 532 this._outputFormatter = f.formatOutputAddress; 533 }; 534 535 SolidityTypeAddress.prototype = new SolidityType({}); 536 SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 537 538 SolidityTypeAddress.prototype.isType = function (name) { 539 return !!name.match(/address(\[([0-9]*)\])?/); 540 }; 541 542 module.exports = SolidityTypeAddress; 543 544 },{"./formatters":9,"./type":14}],5:[function(require,module,exports){ 545 var f = require('./formatters'); 546 var SolidityType = require('./type'); 547 548 /** 549 * SolidityTypeBool is a prootype that represents bool type 550 * It matches: 551 * bool 552 * bool[] 553 * bool[4] 554 * bool[][] 555 * bool[3][] 556 * bool[][6][], ... 557 */ 558 var SolidityTypeBool = function () { 559 this._inputFormatter = f.formatInputBool; 560 this._outputFormatter = f.formatOutputBool; 561 }; 562 563 SolidityTypeBool.prototype = new SolidityType({}); 564 SolidityTypeBool.prototype.constructor = SolidityTypeBool; 565 566 SolidityTypeBool.prototype.isType = function (name) { 567 return !!name.match(/^bool(\[([0-9]*)\])*$/); 568 }; 569 570 module.exports = SolidityTypeBool; 571 572 },{"./formatters":9,"./type":14}],6:[function(require,module,exports){ 573 var f = require('./formatters'); 574 var SolidityType = require('./type'); 575 576 /** 577 * SolidityTypeBytes is a prototype that represents the bytes type. 578 * It matches: 579 * bytes 580 * bytes[] 581 * bytes[4] 582 * bytes[][] 583 * bytes[3][] 584 * bytes[][6][], ... 585 * bytes32 586 * bytes8[4] 587 * bytes[3][] 588 */ 589 var SolidityTypeBytes = function () { 590 this._inputFormatter = f.formatInputBytes; 591 this._outputFormatter = f.formatOutputBytes; 592 }; 593 594 SolidityTypeBytes.prototype = new SolidityType({}); 595 SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 596 597 SolidityTypeBytes.prototype.isType = function (name) { 598 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 599 }; 600 601 module.exports = SolidityTypeBytes; 602 603 },{"./formatters":9,"./type":14}],7:[function(require,module,exports){ 604 /* 605 This file is part of web3.js. 606 607 web3.js is free software: you can redistribute it and/or modify 608 it under the terms of the GNU Lesser General Public License as published by 609 the Free Software Foundation, either version 3 of the License, or 610 (at your option) any later version. 611 612 web3.js is distributed in the hope that it will be useful, 613 but WITHOUT ANY WARRANTY; without even the implied warranty of 614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 615 GNU Lesser General Public License for more details. 616 617 You should have received a copy of the GNU Lesser General Public License 618 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 619 */ 620 /** 621 * @file coder.js 622 * @author Marek Kotewicz <marek@ethdev.com> 623 * @date 2015 624 */ 625 626 var f = require('./formatters'); 627 628 var SolidityTypeAddress = require('./address'); 629 var SolidityTypeBool = require('./bool'); 630 var SolidityTypeInt = require('./int'); 631 var SolidityTypeUInt = require('./uint'); 632 var SolidityTypeDynamicBytes = require('./dynamicbytes'); 633 var SolidityTypeString = require('./string'); 634 var SolidityTypeReal = require('./real'); 635 var SolidityTypeUReal = require('./ureal'); 636 var SolidityTypeBytes = require('./bytes'); 637 638 var isDynamic = function (solidityType, type) { 639 return solidityType.isDynamicType(type) || 640 solidityType.isDynamicArray(type); 641 }; 642 643 /** 644 * SolidityCoder prototype should be used to encode/decode solidity params of any type 645 */ 646 var SolidityCoder = function (types) { 647 this._types = types; 648 }; 649 650 /** 651 * This method should be used to transform type to SolidityType 652 * 653 * @method _requireType 654 * @param {String} type 655 * @returns {SolidityType} 656 * @throws {Error} throws if no matching type is found 657 */ 658 SolidityCoder.prototype._requireType = function (type) { 659 var solidityType = this._types.filter(function (t) { 660 return t.isType(type); 661 })[0]; 662 663 if (!solidityType) { 664 throw Error('invalid solidity type!: ' + type); 665 } 666 667 return solidityType; 668 }; 669 670 /** 671 * Should be used to encode plain param 672 * 673 * @method encodeParam 674 * @param {String} type 675 * @param {Object} plain param 676 * @return {String} encoded plain param 677 */ 678 SolidityCoder.prototype.encodeParam = function (type, param) { 679 return this.encodeParams([type], [param]); 680 }; 681 682 /** 683 * Should be used to encode list of params 684 * 685 * @method encodeParams 686 * @param {Array} types 687 * @param {Array} params 688 * @return {String} encoded list of params 689 */ 690 SolidityCoder.prototype.encodeParams = function (types, params) { 691 var solidityTypes = this.getSolidityTypes(types); 692 693 var encodeds = solidityTypes.map(function (solidityType, index) { 694 return solidityType.encode(params[index], types[index]); 695 }); 696 697 var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) { 698 var staticPartLength = solidityType.staticPartLength(types[index]); 699 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 700 701 return acc + (isDynamic(solidityTypes[index], types[index]) ? 702 32 : 703 roundedStaticPartLength); 704 }, 0); 705 706 var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset); 707 708 return result; 709 }; 710 711 SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) { 712 var result = ""; 713 var self = this; 714 715 types.forEach(function (type, i) { 716 if (isDynamic(solidityTypes[i], types[i])) { 717 result += f.formatInputInt(dynamicOffset).encode(); 718 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 719 dynamicOffset += e.length / 2; 720 } else { 721 // don't add length to dynamicOffset. it's already counted 722 result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 723 } 724 725 // TODO: figure out nested arrays 726 }); 727 728 types.forEach(function (type, i) { 729 if (isDynamic(solidityTypes[i], types[i])) { 730 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 731 dynamicOffset += e.length / 2; 732 result += e; 733 } 734 }); 735 return result; 736 }; 737 738 // TODO: refactor whole encoding! 739 SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) { 740 var self = this; 741 if (solidityType.isDynamicArray(type)) { 742 return (function () { 743 // offset was already set 744 var nestedName = solidityType.nestedName(type); 745 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 746 var result = encoded[0]; 747 748 (function () { 749 var previousLength = 2; // in int 750 if (solidityType.isDynamicArray(nestedName)) { 751 for (var i = 1; i < encoded.length; i++) { 752 previousLength += +(encoded[i - 1])[0] || 0; 753 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 754 } 755 } 756 })(); 757 758 // first element is length, skip it 759 (function () { 760 for (var i = 0; i < encoded.length - 1; i++) { 761 var additionalOffset = result / 2; 762 result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset); 763 } 764 })(); 765 766 return result; 767 })(); 768 769 } else if (solidityType.isStaticArray(type)) { 770 return (function () { 771 var nestedName = solidityType.nestedName(type); 772 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 773 var result = ""; 774 775 776 if (solidityType.isDynamicArray(nestedName)) { 777 (function () { 778 var previousLength = 0; // in int 779 for (var i = 0; i < encoded.length; i++) { 780 // calculate length of previous item 781 previousLength += +(encoded[i - 1] || [])[0] || 0; 782 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 783 } 784 })(); 785 } 786 787 (function () { 788 for (var i = 0; i < encoded.length; i++) { 789 var additionalOffset = result / 2; 790 result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset); 791 } 792 })(); 793 794 return result; 795 })(); 796 } 797 798 return encoded; 799 }; 800 801 /** 802 * Should be used to decode bytes to plain param 803 * 804 * @method decodeParam 805 * @param {String} type 806 * @param {String} bytes 807 * @return {Object} plain param 808 */ 809 SolidityCoder.prototype.decodeParam = function (type, bytes) { 810 return this.decodeParams([type], bytes)[0]; 811 }; 812 813 /** 814 * Should be used to decode list of params 815 * 816 * @method decodeParam 817 * @param {Array} types 818 * @param {String} bytes 819 * @return {Array} array of plain params 820 */ 821 SolidityCoder.prototype.decodeParams = function (types, bytes) { 822 var solidityTypes = this.getSolidityTypes(types); 823 var offsets = this.getOffsets(types, solidityTypes); 824 825 return solidityTypes.map(function (solidityType, index) { 826 return solidityType.decode(bytes, offsets[index], types[index], index); 827 }); 828 }; 829 830 SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { 831 var lengths = solidityTypes.map(function (solidityType, index) { 832 return solidityType.staticPartLength(types[index]); 833 }); 834 835 for (var i = 1; i < lengths.length; i++) { 836 // sum with length of previous element 837 lengths[i] += lengths[i - 1]; 838 } 839 840 return lengths.map(function (length, index) { 841 // remove the current length, so the length is sum of previous elements 842 var staticPartLength = solidityTypes[index].staticPartLength(types[index]); 843 return length - staticPartLength; 844 }); 845 }; 846 847 SolidityCoder.prototype.getSolidityTypes = function (types) { 848 var self = this; 849 return types.map(function (type) { 850 return self._requireType(type); 851 }); 852 }; 853 854 var coder = new SolidityCoder([ 855 new SolidityTypeAddress(), 856 new SolidityTypeBool(), 857 new SolidityTypeInt(), 858 new SolidityTypeUInt(), 859 new SolidityTypeDynamicBytes(), 860 new SolidityTypeBytes(), 861 new SolidityTypeString(), 862 new SolidityTypeReal(), 863 new SolidityTypeUReal() 864 ]); 865 866 module.exports = coder; 867 868 },{"./address":4,"./bool":5,"./bytes":6,"./dynamicbytes":8,"./formatters":9,"./int":10,"./real":12,"./string":13,"./uint":15,"./ureal":16}],8:[function(require,module,exports){ 869 var f = require('./formatters'); 870 var SolidityType = require('./type'); 871 872 var SolidityTypeDynamicBytes = function () { 873 this._inputFormatter = f.formatInputDynamicBytes; 874 this._outputFormatter = f.formatOutputDynamicBytes; 875 }; 876 877 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 878 SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 879 880 SolidityTypeDynamicBytes.prototype.isType = function (name) { 881 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 882 }; 883 884 SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 885 return true; 886 }; 887 888 module.exports = SolidityTypeDynamicBytes; 889 890 },{"./formatters":9,"./type":14}],9:[function(require,module,exports){ 891 /* 892 This file is part of web3.js. 893 894 web3.js is free software: you can redistribute it and/or modify 895 it under the terms of the GNU Lesser General Public License as published by 896 the Free Software Foundation, either version 3 of the License, or 897 (at your option) any later version. 898 899 web3.js is distributed in the hope that it will be useful, 900 but WITHOUT ANY WARRANTY; without even the implied warranty of 901 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 902 GNU Lesser General Public License for more details. 903 904 You should have received a copy of the GNU Lesser General Public License 905 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 906 */ 907 /** 908 * @file formatters.js 909 * @author Marek Kotewicz <marek@ethdev.com> 910 * @date 2015 911 */ 912 913 var BigNumber = require('bignumber.js'); 914 var utils = require('../utils/utils'); 915 var c = require('../utils/config'); 916 var SolidityParam = require('./param'); 917 918 919 /** 920 * Formats input value to byte representation of int 921 * If value is negative, return it's two's complement 922 * If the value is floating point, round it down 923 * 924 * @method formatInputInt 925 * @param {String|Number|BigNumber} value that needs to be formatted 926 * @returns {SolidityParam} 927 */ 928 var formatInputInt = function (value) { 929 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 930 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 931 return new SolidityParam(result); 932 }; 933 934 /** 935 * Formats input bytes 936 * 937 * @method formatInputBytes 938 * @param {String} 939 * @returns {SolidityParam} 940 */ 941 var formatInputBytes = function (value) { 942 var result = utils.toHex(value).substr(2); 943 var l = Math.floor((result.length + 63) / 64); 944 result = utils.padRight(result, l * 64); 945 return new SolidityParam(result); 946 }; 947 948 /** 949 * Formats input bytes 950 * 951 * @method formatDynamicInputBytes 952 * @param {String} 953 * @returns {SolidityParam} 954 */ 955 var formatInputDynamicBytes = function (value) { 956 var result = utils.toHex(value).substr(2); 957 var length = result.length / 2; 958 var l = Math.floor((result.length + 63) / 64); 959 result = utils.padRight(result, l * 64); 960 return new SolidityParam(formatInputInt(length).value + result); 961 }; 962 963 /** 964 * Formats input value to byte representation of string 965 * 966 * @method formatInputString 967 * @param {String} 968 * @returns {SolidityParam} 969 */ 970 var formatInputString = function (value) { 971 var result = utils.fromUtf8(value).substr(2); 972 var length = result.length / 2; 973 var l = Math.floor((result.length + 63) / 64); 974 result = utils.padRight(result, l * 64); 975 return new SolidityParam(formatInputInt(length).value + result); 976 }; 977 978 /** 979 * Formats input value to byte representation of bool 980 * 981 * @method formatInputBool 982 * @param {Boolean} 983 * @returns {SolidityParam} 984 */ 985 var formatInputBool = function (value) { 986 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 987 return new SolidityParam(result); 988 }; 989 990 /** 991 * Formats input value to byte representation of real 992 * Values are multiplied by 2^m and encoded as integers 993 * 994 * @method formatInputReal 995 * @param {String|Number|BigNumber} 996 * @returns {SolidityParam} 997 */ 998 var formatInputReal = function (value) { 999 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1000 }; 1001 1002 /** 1003 * Check if input value is negative 1004 * 1005 * @method signedIsNegative 1006 * @param {String} value is hex format 1007 * @returns {Boolean} true if it is negative, otherwise false 1008 */ 1009 var signedIsNegative = function (value) { 1010 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1011 }; 1012 1013 /** 1014 * Formats right-aligned output bytes to int 1015 * 1016 * @method formatOutputInt 1017 * @param {SolidityParam} param 1018 * @returns {BigNumber} right-aligned output bytes formatted to big number 1019 */ 1020 var formatOutputInt = function (param) { 1021 var value = param.staticPart() || "0"; 1022 1023 // check if it's negative number 1024 // it it is, return two's complement 1025 if (signedIsNegative(value)) { 1026 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1027 } 1028 return new BigNumber(value, 16); 1029 }; 1030 1031 /** 1032 * Formats right-aligned output bytes to uint 1033 * 1034 * @method formatOutputUInt 1035 * @param {SolidityParam} 1036 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1037 */ 1038 var formatOutputUInt = function (param) { 1039 var value = param.staticPart() || "0"; 1040 return new BigNumber(value, 16); 1041 }; 1042 1043 /** 1044 * Formats right-aligned output bytes to real 1045 * 1046 * @method formatOutputReal 1047 * @param {SolidityParam} 1048 * @returns {BigNumber} input bytes formatted to real 1049 */ 1050 var formatOutputReal = function (param) { 1051 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1052 }; 1053 1054 /** 1055 * Formats right-aligned output bytes to ureal 1056 * 1057 * @method formatOutputUReal 1058 * @param {SolidityParam} 1059 * @returns {BigNumber} input bytes formatted to ureal 1060 */ 1061 var formatOutputUReal = function (param) { 1062 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1063 }; 1064 1065 /** 1066 * Should be used to format output bool 1067 * 1068 * @method formatOutputBool 1069 * @param {SolidityParam} 1070 * @returns {Boolean} right-aligned input bytes formatted to bool 1071 */ 1072 var formatOutputBool = function (param) { 1073 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1074 }; 1075 1076 /** 1077 * Should be used to format output bytes 1078 * 1079 * @method formatOutputBytes 1080 * @param {SolidityParam} left-aligned hex representation of string 1081 * @param {String} name type name 1082 * @returns {String} hex string 1083 */ 1084 var formatOutputBytes = function (param, name) { 1085 var matches = name.match(/^bytes([0-9]*)/); 1086 var size = parseInt(matches[1]); 1087 return '0x' + param.staticPart().slice(0, 2 * size); 1088 }; 1089 1090 /** 1091 * Should be used to format output bytes 1092 * 1093 * @method formatOutputDynamicBytes 1094 * @param {SolidityParam} left-aligned hex representation of string 1095 * @returns {String} hex string 1096 */ 1097 var formatOutputDynamicBytes = function (param) { 1098 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1099 return '0x' + param.dynamicPart().substr(64, length); 1100 }; 1101 1102 /** 1103 * Should be used to format output string 1104 * 1105 * @method formatOutputString 1106 * @param {SolidityParam} left-aligned hex representation of string 1107 * @returns {String} ascii string 1108 */ 1109 var formatOutputString = function (param) { 1110 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1111 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1112 }; 1113 1114 /** 1115 * Should be used to format output address 1116 * 1117 * @method formatOutputAddress 1118 * @param {SolidityParam} right-aligned input bytes 1119 * @returns {String} address 1120 */ 1121 var formatOutputAddress = function (param) { 1122 var value = param.staticPart(); 1123 return "0x" + value.slice(value.length - 40, value.length); 1124 }; 1125 1126 module.exports = { 1127 formatInputInt: formatInputInt, 1128 formatInputBytes: formatInputBytes, 1129 formatInputDynamicBytes: formatInputDynamicBytes, 1130 formatInputString: formatInputString, 1131 formatInputBool: formatInputBool, 1132 formatInputReal: formatInputReal, 1133 formatOutputInt: formatOutputInt, 1134 formatOutputUInt: formatOutputUInt, 1135 formatOutputReal: formatOutputReal, 1136 formatOutputUReal: formatOutputUReal, 1137 formatOutputBool: formatOutputBool, 1138 formatOutputBytes: formatOutputBytes, 1139 formatOutputDynamicBytes: formatOutputDynamicBytes, 1140 formatOutputString: formatOutputString, 1141 formatOutputAddress: formatOutputAddress 1142 }; 1143 1144 },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){ 1145 var f = require('./formatters'); 1146 var SolidityType = require('./type'); 1147 1148 /** 1149 * SolidityTypeInt is a prootype that represents int type 1150 * It matches: 1151 * int 1152 * int[] 1153 * int[4] 1154 * int[][] 1155 * int[3][] 1156 * int[][6][], ... 1157 * int32 1158 * int64[] 1159 * int8[4] 1160 * int256[][] 1161 * int[3][] 1162 * int64[][6][], ... 1163 */ 1164 var SolidityTypeInt = function () { 1165 this._inputFormatter = f.formatInputInt; 1166 this._outputFormatter = f.formatOutputInt; 1167 }; 1168 1169 SolidityTypeInt.prototype = new SolidityType({}); 1170 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1171 1172 SolidityTypeInt.prototype.isType = function (name) { 1173 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1174 }; 1175 1176 module.exports = SolidityTypeInt; 1177 1178 },{"./formatters":9,"./type":14}],11:[function(require,module,exports){ 1179 /* 1180 This file is part of web3.js. 1181 1182 web3.js is free software: you can redistribute it and/or modify 1183 it under the terms of the GNU Lesser General Public License as published by 1184 the Free Software Foundation, either version 3 of the License, or 1185 (at your option) any later version. 1186 1187 web3.js is distributed in the hope that it will be useful, 1188 but WITHOUT ANY WARRANTY; without even the implied warranty of 1189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1190 GNU Lesser General Public License for more details. 1191 1192 You should have received a copy of the GNU Lesser General Public License 1193 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1194 */ 1195 /** 1196 * @file param.js 1197 * @author Marek Kotewicz <marek@ethdev.com> 1198 * @date 2015 1199 */ 1200 1201 var utils = require('../utils/utils'); 1202 1203 /** 1204 * SolidityParam object prototype. 1205 * Should be used when encoding, decoding solidity bytes 1206 */ 1207 var SolidityParam = function (value, offset) { 1208 this.value = value || ''; 1209 this.offset = offset; // offset in bytes 1210 }; 1211 1212 /** 1213 * This method should be used to get length of params's dynamic part 1214 * 1215 * @method dynamicPartLength 1216 * @returns {Number} length of dynamic part (in bytes) 1217 */ 1218 SolidityParam.prototype.dynamicPartLength = function () { 1219 return this.dynamicPart().length / 2; 1220 }; 1221 1222 /** 1223 * This method should be used to create copy of solidity param with different offset 1224 * 1225 * @method withOffset 1226 * @param {Number} offset length in bytes 1227 * @returns {SolidityParam} new solidity param with applied offset 1228 */ 1229 SolidityParam.prototype.withOffset = function (offset) { 1230 return new SolidityParam(this.value, offset); 1231 }; 1232 1233 /** 1234 * This method should be used to combine solidity params together 1235 * eg. when appending an array 1236 * 1237 * @method combine 1238 * @param {SolidityParam} param with which we should combine 1239 * @param {SolidityParam} result of combination 1240 */ 1241 SolidityParam.prototype.combine = function (param) { 1242 return new SolidityParam(this.value + param.value); 1243 }; 1244 1245 /** 1246 * This method should be called to check if param has dynamic size. 1247 * If it has, it returns true, otherwise false 1248 * 1249 * @method isDynamic 1250 * @returns {Boolean} 1251 */ 1252 SolidityParam.prototype.isDynamic = function () { 1253 return this.offset !== undefined; 1254 }; 1255 1256 /** 1257 * This method should be called to transform offset to bytes 1258 * 1259 * @method offsetAsBytes 1260 * @returns {String} bytes representation of offset 1261 */ 1262 SolidityParam.prototype.offsetAsBytes = function () { 1263 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1264 }; 1265 1266 /** 1267 * This method should be called to get static part of param 1268 * 1269 * @method staticPart 1270 * @returns {String} offset if it is a dynamic param, otherwise value 1271 */ 1272 SolidityParam.prototype.staticPart = function () { 1273 if (!this.isDynamic()) { 1274 return this.value; 1275 } 1276 return this.offsetAsBytes(); 1277 }; 1278 1279 /** 1280 * This method should be called to get dynamic part of param 1281 * 1282 * @method dynamicPart 1283 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1284 */ 1285 SolidityParam.prototype.dynamicPart = function () { 1286 return this.isDynamic() ? this.value : ''; 1287 }; 1288 1289 /** 1290 * This method should be called to encode param 1291 * 1292 * @method encode 1293 * @returns {String} 1294 */ 1295 SolidityParam.prototype.encode = function () { 1296 return this.staticPart() + this.dynamicPart(); 1297 }; 1298 1299 /** 1300 * This method should be called to encode array of params 1301 * 1302 * @method encodeList 1303 * @param {Array[SolidityParam]} params 1304 * @returns {String} 1305 */ 1306 SolidityParam.encodeList = function (params) { 1307 1308 // updating offsets 1309 var totalOffset = params.length * 32; 1310 var offsetParams = params.map(function (param) { 1311 if (!param.isDynamic()) { 1312 return param; 1313 } 1314 var offset = totalOffset; 1315 totalOffset += param.dynamicPartLength(); 1316 return param.withOffset(offset); 1317 }); 1318 1319 // encode everything! 1320 return offsetParams.reduce(function (result, param) { 1321 return result + param.dynamicPart(); 1322 }, offsetParams.reduce(function (result, param) { 1323 return result + param.staticPart(); 1324 }, '')); 1325 }; 1326 1327 1328 1329 module.exports = SolidityParam; 1330 1331 1332 },{"../utils/utils":20}],12:[function(require,module,exports){ 1333 var f = require('./formatters'); 1334 var SolidityType = require('./type'); 1335 1336 /** 1337 * SolidityTypeReal is a prootype that represents real type 1338 * It matches: 1339 * real 1340 * real[] 1341 * real[4] 1342 * real[][] 1343 * real[3][] 1344 * real[][6][], ... 1345 * real32 1346 * real64[] 1347 * real8[4] 1348 * real256[][] 1349 * real[3][] 1350 * real64[][6][], ... 1351 */ 1352 var SolidityTypeReal = function () { 1353 this._inputFormatter = f.formatInputReal; 1354 this._outputFormatter = f.formatOutputReal; 1355 }; 1356 1357 SolidityTypeReal.prototype = new SolidityType({}); 1358 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1359 1360 SolidityTypeReal.prototype.isType = function (name) { 1361 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1362 }; 1363 1364 module.exports = SolidityTypeReal; 1365 1366 },{"./formatters":9,"./type":14}],13:[function(require,module,exports){ 1367 var f = require('./formatters'); 1368 var SolidityType = require('./type'); 1369 1370 var SolidityTypeString = function () { 1371 this._inputFormatter = f.formatInputString; 1372 this._outputFormatter = f.formatOutputString; 1373 }; 1374 1375 SolidityTypeString.prototype = new SolidityType({}); 1376 SolidityTypeString.prototype.constructor = SolidityTypeString; 1377 1378 SolidityTypeString.prototype.isType = function (name) { 1379 return !!name.match(/^string(\[([0-9]*)\])*$/); 1380 }; 1381 1382 SolidityTypeString.prototype.isDynamicType = function () { 1383 return true; 1384 }; 1385 1386 module.exports = SolidityTypeString; 1387 1388 },{"./formatters":9,"./type":14}],14:[function(require,module,exports){ 1389 var f = require('./formatters'); 1390 var SolidityParam = require('./param'); 1391 1392 /** 1393 * SolidityType prototype is used to encode/decode solidity params of certain type 1394 */ 1395 var SolidityType = function (config) { 1396 this._inputFormatter = config.inputFormatter; 1397 this._outputFormatter = config.outputFormatter; 1398 }; 1399 1400 /** 1401 * Should be used to determine if this SolidityType do match given name 1402 * 1403 * @method isType 1404 * @param {String} name 1405 * @return {Bool} true if type match this SolidityType, otherwise false 1406 */ 1407 SolidityType.prototype.isType = function (name) { 1408 throw "this method should be overrwritten for type " + name; 1409 }; 1410 1411 /** 1412 * Should be used to determine what is the length of static part in given type 1413 * 1414 * @method staticPartLength 1415 * @param {String} name 1416 * @return {Number} length of static part in bytes 1417 */ 1418 SolidityType.prototype.staticPartLength = function (name) { 1419 // If name isn't an array then treat it like a single element array. 1420 return (this.nestedTypes(name) || ['[1]']) 1421 .map(function (type) { 1422 // the length of the nested array 1423 return parseInt(type.slice(1, -1), 10) || 1; 1424 }) 1425 .reduce(function (previous, current) { 1426 return previous * current; 1427 // all basic types are 32 bytes long 1428 }, 32); 1429 }; 1430 1431 /** 1432 * Should be used to determine if type is dynamic array 1433 * eg: 1434 * "type[]" => true 1435 * "type[4]" => false 1436 * 1437 * @method isDynamicArray 1438 * @param {String} name 1439 * @return {Bool} true if the type is dynamic array 1440 */ 1441 SolidityType.prototype.isDynamicArray = function (name) { 1442 var nestedTypes = this.nestedTypes(name); 1443 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1444 }; 1445 1446 /** 1447 * Should be used to determine if type is static array 1448 * eg: 1449 * "type[]" => false 1450 * "type[4]" => true 1451 * 1452 * @method isStaticArray 1453 * @param {String} name 1454 * @return {Bool} true if the type is static array 1455 */ 1456 SolidityType.prototype.isStaticArray = function (name) { 1457 var nestedTypes = this.nestedTypes(name); 1458 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1459 }; 1460 1461 /** 1462 * Should return length of static array 1463 * eg. 1464 * "int[32]" => 32 1465 * "int256[14]" => 14 1466 * "int[2][3]" => 3 1467 * "int" => 1 1468 * "int[1]" => 1 1469 * "int[]" => 1 1470 * 1471 * @method staticArrayLength 1472 * @param {String} name 1473 * @return {Number} static array length 1474 */ 1475 SolidityType.prototype.staticArrayLength = function (name) { 1476 var nestedTypes = this.nestedTypes(name); 1477 if (nestedTypes) { 1478 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1479 } 1480 return 1; 1481 }; 1482 1483 /** 1484 * Should return nested type 1485 * eg. 1486 * "int[32]" => "int" 1487 * "int256[14]" => "int256" 1488 * "int[2][3]" => "int[2]" 1489 * "int" => "int" 1490 * "int[]" => "int" 1491 * 1492 * @method nestedName 1493 * @param {String} name 1494 * @return {String} nested name 1495 */ 1496 SolidityType.prototype.nestedName = function (name) { 1497 // remove last [] in name 1498 var nestedTypes = this.nestedTypes(name); 1499 if (!nestedTypes) { 1500 return name; 1501 } 1502 1503 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1504 }; 1505 1506 /** 1507 * Should return true if type has dynamic size by default 1508 * such types are "string", "bytes" 1509 * 1510 * @method isDynamicType 1511 * @param {String} name 1512 * @return {Bool} true if is dynamic, otherwise false 1513 */ 1514 SolidityType.prototype.isDynamicType = function () { 1515 return false; 1516 }; 1517 1518 /** 1519 * Should return array of nested types 1520 * eg. 1521 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1522 * "int[] => ["[]"] 1523 * "int" => null 1524 * 1525 * @method nestedTypes 1526 * @param {String} name 1527 * @return {Array} array of nested types 1528 */ 1529 SolidityType.prototype.nestedTypes = function (name) { 1530 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1531 return name.match(/(\[[0-9]*\])/g); 1532 }; 1533 1534 /** 1535 * Should be used to encode the value 1536 * 1537 * @method encode 1538 * @param {Object} value 1539 * @param {String} name 1540 * @return {String} encoded value 1541 */ 1542 SolidityType.prototype.encode = function (value, name) { 1543 var self = this; 1544 if (this.isDynamicArray(name)) { 1545 1546 return (function () { 1547 var length = value.length; // in int 1548 var nestedName = self.nestedName(name); 1549 1550 var result = []; 1551 result.push(f.formatInputInt(length).encode()); 1552 1553 value.forEach(function (v) { 1554 result.push(self.encode(v, nestedName)); 1555 }); 1556 1557 return result; 1558 })(); 1559 1560 } else if (this.isStaticArray(name)) { 1561 1562 return (function () { 1563 var length = self.staticArrayLength(name); // in int 1564 var nestedName = self.nestedName(name); 1565 1566 var result = []; 1567 for (var i = 0; i < length; i++) { 1568 result.push(self.encode(value[i], nestedName)); 1569 } 1570 1571 return result; 1572 })(); 1573 1574 } 1575 1576 return this._inputFormatter(value, name).encode(); 1577 }; 1578 1579 /** 1580 * Should be used to decode value from bytes 1581 * 1582 * @method decode 1583 * @param {String} bytes 1584 * @param {Number} offset in bytes 1585 * @param {String} name type name 1586 * @returns {Object} decoded value 1587 */ 1588 SolidityType.prototype.decode = function (bytes, offset, name) { 1589 var self = this; 1590 1591 if (this.isDynamicArray(name)) { 1592 1593 return (function () { 1594 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1595 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1596 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1597 1598 var nestedName = self.nestedName(name); 1599 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1600 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1601 var result = []; 1602 1603 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1604 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1605 } 1606 1607 return result; 1608 })(); 1609 1610 } else if (this.isStaticArray(name)) { 1611 1612 return (function () { 1613 var length = self.staticArrayLength(name); // in int 1614 var arrayStart = offset; // in bytes 1615 1616 var nestedName = self.nestedName(name); 1617 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1618 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1619 var result = []; 1620 1621 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1622 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1623 } 1624 1625 return result; 1626 })(); 1627 } else if (this.isDynamicType(name)) { 1628 1629 return (function () { 1630 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1631 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1632 var roundedLength = Math.floor((length + 31) / 32); // in int 1633 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0); 1634 return self._outputFormatter(param, name); 1635 })(); 1636 } 1637 1638 var length = this.staticPartLength(name); 1639 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1640 return this._outputFormatter(param, name); 1641 }; 1642 1643 module.exports = SolidityType; 1644 1645 },{"./formatters":9,"./param":11}],15:[function(require,module,exports){ 1646 var f = require('./formatters'); 1647 var SolidityType = require('./type'); 1648 1649 /** 1650 * SolidityTypeUInt is a prootype that represents uint type 1651 * It matches: 1652 * uint 1653 * uint[] 1654 * uint[4] 1655 * uint[][] 1656 * uint[3][] 1657 * uint[][6][], ... 1658 * uint32 1659 * uint64[] 1660 * uint8[4] 1661 * uint256[][] 1662 * uint[3][] 1663 * uint64[][6][], ... 1664 */ 1665 var SolidityTypeUInt = function () { 1666 this._inputFormatter = f.formatInputInt; 1667 this._outputFormatter = f.formatOutputUInt; 1668 }; 1669 1670 SolidityTypeUInt.prototype = new SolidityType({}); 1671 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1672 1673 SolidityTypeUInt.prototype.isType = function (name) { 1674 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1675 }; 1676 1677 module.exports = SolidityTypeUInt; 1678 1679 },{"./formatters":9,"./type":14}],16:[function(require,module,exports){ 1680 var f = require('./formatters'); 1681 var SolidityType = require('./type'); 1682 1683 /** 1684 * SolidityTypeUReal is a prootype that represents ureal type 1685 * It matches: 1686 * ureal 1687 * ureal[] 1688 * ureal[4] 1689 * ureal[][] 1690 * ureal[3][] 1691 * ureal[][6][], ... 1692 * ureal32 1693 * ureal64[] 1694 * ureal8[4] 1695 * ureal256[][] 1696 * ureal[3][] 1697 * ureal64[][6][], ... 1698 */ 1699 var SolidityTypeUReal = function () { 1700 this._inputFormatter = f.formatInputReal; 1701 this._outputFormatter = f.formatOutputUReal; 1702 }; 1703 1704 SolidityTypeUReal.prototype = new SolidityType({}); 1705 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1706 1707 SolidityTypeUReal.prototype.isType = function (name) { 1708 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1709 }; 1710 1711 module.exports = SolidityTypeUReal; 1712 1713 },{"./formatters":9,"./type":14}],17:[function(require,module,exports){ 1714 'use strict'; 1715 1716 // go env doesn't have and need XMLHttpRequest 1717 if (typeof XMLHttpRequest === 'undefined') { 1718 exports.XMLHttpRequest = {}; 1719 } else { 1720 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1721 } 1722 1723 1724 },{}],18:[function(require,module,exports){ 1725 /* 1726 This file is part of web3.js. 1727 1728 web3.js is free software: you can redistribute it and/or modify 1729 it under the terms of the GNU Lesser General Public License as published by 1730 the Free Software Foundation, either version 3 of the License, or 1731 (at your option) any later version. 1732 1733 web3.js is distributed in the hope that it will be useful, 1734 but WITHOUT ANY WARRANTY; without even the implied warranty of 1735 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1736 GNU Lesser General Public License for more details. 1737 1738 You should have received a copy of the GNU Lesser General Public License 1739 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1740 */ 1741 /** @file config.js 1742 * @authors: 1743 * Marek Kotewicz <marek@ethdev.com> 1744 * @date 2015 1745 */ 1746 1747 /** 1748 * Utils 1749 * 1750 * @module utils 1751 */ 1752 1753 /** 1754 * Utility functions 1755 * 1756 * @class [utils] config 1757 * @constructor 1758 */ 1759 1760 1761 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1762 var BigNumber = require('bignumber.js'); 1763 1764 var ETH_UNITS = [ 1765 'wei', 1766 'kwei', 1767 'Mwei', 1768 'Gwei', 1769 'szabo', 1770 'finney', 1771 'femtoether', 1772 'picoether', 1773 'nanoether', 1774 'microether', 1775 'milliether', 1776 'nano', 1777 'micro', 1778 'milli', 1779 'ether', 1780 'grand', 1781 'Mether', 1782 'Gether', 1783 'Tether', 1784 'Pether', 1785 'Eether', 1786 'Zether', 1787 'Yether', 1788 'Nether', 1789 'Dether', 1790 'Vether', 1791 'Uether' 1792 ]; 1793 1794 module.exports = { 1795 ETH_PADDING: 32, 1796 ETH_SIGNATURE_LENGTH: 4, 1797 ETH_UNITS: ETH_UNITS, 1798 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1799 ETH_POLLING_TIMEOUT: 1000/2, 1800 defaultBlock: 'latest', 1801 defaultAccount: undefined 1802 }; 1803 1804 1805 },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){ 1806 /* 1807 This file is part of web3.js. 1808 1809 web3.js is free software: you can redistribute it and/or modify 1810 it under the terms of the GNU Lesser General Public License as published by 1811 the Free Software Foundation, either version 3 of the License, or 1812 (at your option) any later version. 1813 1814 web3.js is distributed in the hope that it will be useful, 1815 but WITHOUT ANY WARRANTY; without even the implied warranty of 1816 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1817 GNU Lesser General Public License for more details. 1818 1819 You should have received a copy of the GNU Lesser General Public License 1820 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1821 */ 1822 /** 1823 * @file sha3.js 1824 * @author Marek Kotewicz <marek@ethdev.com> 1825 * @date 2015 1826 */ 1827 1828 var CryptoJS = require('crypto-js'); 1829 var sha3 = require('crypto-js/sha3'); 1830 1831 module.exports = function (value, options) { 1832 if (options && options.encoding === 'hex') { 1833 if (value.length > 2 && value.substr(0, 2) === '0x') { 1834 value = value.substr(2); 1835 } 1836 value = CryptoJS.enc.Hex.parse(value); 1837 } 1838 1839 return sha3(value, { 1840 outputLength: 256 1841 }).toString(); 1842 }; 1843 1844 1845 },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){ 1846 /* 1847 This file is part of web3.js. 1848 1849 web3.js is free software: you can redistribute it and/or modify 1850 it under the terms of the GNU Lesser General Public License as published by 1851 the Free Software Foundation, either version 3 of the License, or 1852 (at your option) any later version. 1853 1854 web3.js is distributed in the hope that it will be useful, 1855 but WITHOUT ANY WARRANTY; without even the implied warranty of 1856 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1857 GNU Lesser General Public License for more details. 1858 1859 You should have received a copy of the GNU Lesser General Public License 1860 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1861 */ 1862 /** 1863 * @file utils.js 1864 * @author Marek Kotewicz <marek@ethdev.com> 1865 * @date 2015 1866 */ 1867 1868 /** 1869 * Utils 1870 * 1871 * @module utils 1872 */ 1873 1874 /** 1875 * Utility functions 1876 * 1877 * @class [utils] utils 1878 * @constructor 1879 */ 1880 1881 1882 var BigNumber = require('bignumber.js'); 1883 var sha3 = require('./sha3.js'); 1884 var utf8 = require('utf8'); 1885 1886 var unitMap = { 1887 'noether': '0', 1888 'wei': '1', 1889 'kwei': '1000', 1890 'Kwei': '1000', 1891 'babbage': '1000', 1892 'femtoether': '1000', 1893 'mwei': '1000000', 1894 'Mwei': '1000000', 1895 'lovelace': '1000000', 1896 'picoether': '1000000', 1897 'gwei': '1000000000', 1898 'Gwei': '1000000000', 1899 'shannon': '1000000000', 1900 'nanoether': '1000000000', 1901 'nano': '1000000000', 1902 'szabo': '1000000000000', 1903 'microether': '1000000000000', 1904 'micro': '1000000000000', 1905 'finney': '1000000000000000', 1906 'milliether': '1000000000000000', 1907 'milli': '1000000000000000', 1908 'ether': '1000000000000000000', 1909 'kether': '1000000000000000000000', 1910 'grand': '1000000000000000000000', 1911 'mether': '1000000000000000000000000', 1912 'gether': '1000000000000000000000000000', 1913 'tether': '1000000000000000000000000000000' 1914 }; 1915 1916 /** 1917 * Should be called to pad string to expected length 1918 * 1919 * @method padLeft 1920 * @param {String} string to be padded 1921 * @param {Number} characters that result string should have 1922 * @param {String} sign, by default 0 1923 * @returns {String} right aligned string 1924 */ 1925 var padLeft = function (string, chars, sign) { 1926 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1927 }; 1928 1929 /** 1930 * Should be called to pad string to expected length 1931 * 1932 * @method padRight 1933 * @param {String} string to be padded 1934 * @param {Number} characters that result string should have 1935 * @param {String} sign, by default 0 1936 * @returns {String} right aligned string 1937 */ 1938 var padRight = function (string, chars, sign) { 1939 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1940 }; 1941 1942 /** 1943 * Should be called to get utf8 from it's hex representation 1944 * 1945 * @method toUtf8 1946 * @param {String} string in hex 1947 * @returns {String} ascii string representation of hex value 1948 */ 1949 var toUtf8 = function(hex) { 1950 // Find termination 1951 var str = ""; 1952 var i = 0, l = hex.length; 1953 if (hex.substring(0, 2) === '0x') { 1954 i = 2; 1955 } 1956 for (; i < l; i+=2) { 1957 var code = parseInt(hex.substr(i, 2), 16); 1958 if (code === 0) 1959 break; 1960 str += String.fromCharCode(code); 1961 } 1962 1963 return utf8.decode(str); 1964 }; 1965 1966 /** 1967 * Should be called to get ascii from it's hex representation 1968 * 1969 * @method toAscii 1970 * @param {String} string in hex 1971 * @returns {String} ascii string representation of hex value 1972 */ 1973 var toAscii = function(hex) { 1974 // Find termination 1975 var str = ""; 1976 var i = 0, l = hex.length; 1977 if (hex.substring(0, 2) === '0x') { 1978 i = 2; 1979 } 1980 for (; i < l; i+=2) { 1981 var code = parseInt(hex.substr(i, 2), 16); 1982 str += String.fromCharCode(code); 1983 } 1984 1985 return str; 1986 }; 1987 1988 /** 1989 * Should be called to get hex representation (prefixed by 0x) of utf8 string 1990 * 1991 * @method fromUtf8 1992 * @param {String} string 1993 * @param {Number} optional padding 1994 * @returns {String} hex representation of input string 1995 */ 1996 var fromUtf8 = function(str) { 1997 str = utf8.encode(str); 1998 var hex = ""; 1999 for(var i = 0; i < str.length; i++) { 2000 var code = str.charCodeAt(i); 2001 if (code === 0) 2002 break; 2003 var n = code.toString(16); 2004 hex += n.length < 2 ? '0' + n : n; 2005 } 2006 2007 return "0x" + hex; 2008 }; 2009 2010 /** 2011 * Should be called to get hex representation (prefixed by 0x) of ascii string 2012 * 2013 * @method fromAscii 2014 * @param {String} string 2015 * @param {Number} optional padding 2016 * @returns {String} hex representation of input string 2017 */ 2018 var fromAscii = function(str) { 2019 var hex = ""; 2020 for(var i = 0; i < str.length; i++) { 2021 var code = str.charCodeAt(i); 2022 var n = code.toString(16); 2023 hex += n.length < 2 ? '0' + n : n; 2024 } 2025 2026 return "0x" + hex; 2027 }; 2028 2029 /** 2030 * Should be used to create full function/event name from json abi 2031 * 2032 * @method transformToFullName 2033 * @param {Object} json-abi 2034 * @return {String} full fnction/event name 2035 */ 2036 var transformToFullName = function (json) { 2037 if (json.name.indexOf('(') !== -1) { 2038 return json.name; 2039 } 2040 2041 var typeName = json.inputs.map(function(i){return i.type; }).join(); 2042 return json.name + '(' + typeName + ')'; 2043 }; 2044 2045 /** 2046 * Should be called to get display name of contract function 2047 * 2048 * @method extractDisplayName 2049 * @param {String} name of function/event 2050 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2051 */ 2052 var extractDisplayName = function (name) { 2053 var length = name.indexOf('('); 2054 return length !== -1 ? name.substr(0, length) : name; 2055 }; 2056 2057 /// @returns overloaded part of function/event name 2058 var extractTypeName = function (name) { 2059 /// TODO: make it invulnerable 2060 var length = name.indexOf('('); 2061 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2062 }; 2063 2064 /** 2065 * Converts value to it's decimal representation in string 2066 * 2067 * @method toDecimal 2068 * @param {String|Number|BigNumber} 2069 * @return {String} 2070 */ 2071 var toDecimal = function (value) { 2072 return toBigNumber(value).toNumber(); 2073 }; 2074 2075 /** 2076 * Converts value to it's hex representation 2077 * 2078 * @method fromDecimal 2079 * @param {String|Number|BigNumber} 2080 * @return {String} 2081 */ 2082 var fromDecimal = function (value) { 2083 var number = toBigNumber(value); 2084 var result = number.toString(16); 2085 2086 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2087 }; 2088 2089 /** 2090 * Auto converts any given value into it's hex representation. 2091 * 2092 * And even stringifys objects before. 2093 * 2094 * @method toHex 2095 * @param {String|Number|BigNumber|Object} 2096 * @return {String} 2097 */ 2098 var toHex = function (val) { 2099 /*jshint maxcomplexity: 8 */ 2100 2101 if (isBoolean(val)) 2102 return fromDecimal(+val); 2103 2104 if (isBigNumber(val)) 2105 return fromDecimal(val); 2106 2107 if (typeof val === 'object') 2108 return fromUtf8(JSON.stringify(val)); 2109 2110 // if its a negative number, pass it through fromDecimal 2111 if (isString(val)) { 2112 if (val.indexOf('-0x') === 0) 2113 return fromDecimal(val); 2114 else if(val.indexOf('0x') === 0) 2115 return val; 2116 else if (!isFinite(val)) 2117 return fromAscii(val); 2118 } 2119 2120 return fromDecimal(val); 2121 }; 2122 2123 /** 2124 * Returns value of unit in Wei 2125 * 2126 * @method getValueOfUnit 2127 * @param {String} unit the unit to convert to, default ether 2128 * @returns {BigNumber} value of the unit (in Wei) 2129 * @throws error if the unit is not correct:w 2130 */ 2131 var getValueOfUnit = function (unit) { 2132 unit = unit ? unit.toLowerCase() : 'ether'; 2133 var unitValue = unitMap[unit]; 2134 if (unitValue === undefined) { 2135 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2136 } 2137 return new BigNumber(unitValue, 10); 2138 }; 2139 2140 /** 2141 * Takes a number of wei and converts it to any other ether unit. 2142 * 2143 * Possible units are: 2144 * SI Short SI Full Effigy Other 2145 * - kwei femtoether babbage 2146 * - mwei picoether lovelace 2147 * - gwei nanoether shannon nano 2148 * - -- microether szabo micro 2149 * - -- milliether finney milli 2150 * - ether -- -- 2151 * - kether -- grand 2152 * - mether 2153 * - gether 2154 * - tether 2155 * 2156 * @method fromWei 2157 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2158 * @param {String} unit the unit to convert to, default ether 2159 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2160 */ 2161 var fromWei = function(number, unit) { 2162 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2163 2164 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2165 }; 2166 2167 /** 2168 * Takes a number of a unit and converts it to wei. 2169 * 2170 * Possible units are: 2171 * SI Short SI Full Effigy Other 2172 * - kwei femtoether babbage 2173 * - mwei picoether lovelace 2174 * - gwei nanoether shannon nano 2175 * - -- microether szabo micro 2176 * - -- microether szabo micro 2177 * - -- milliether finney milli 2178 * - ether -- -- 2179 * - kether -- grand 2180 * - mether 2181 * - gether 2182 * - tether 2183 * 2184 * @method toWei 2185 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2186 * @param {String} unit the unit to convert from, default ether 2187 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2188 */ 2189 var toWei = function(number, unit) { 2190 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2191 2192 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2193 }; 2194 2195 /** 2196 * Takes an input and transforms it into a bignumber 2197 * 2198 * @method toBigNumber 2199 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2200 * @return {BigNumber} BigNumber 2201 */ 2202 var toBigNumber = function(number) { 2203 /*jshint maxcomplexity:5 */ 2204 number = number || 0; 2205 if (isBigNumber(number)) 2206 return number; 2207 2208 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2209 return new BigNumber(number.replace('0x',''), 16); 2210 } 2211 2212 return new BigNumber(number.toString(10), 10); 2213 }; 2214 2215 /** 2216 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2217 * 2218 * @method toTwosComplement 2219 * @param {Number|String|BigNumber} 2220 * @return {BigNumber} 2221 */ 2222 var toTwosComplement = function (number) { 2223 var bigNumber = toBigNumber(number).round(); 2224 if (bigNumber.lessThan(0)) { 2225 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2226 } 2227 return bigNumber; 2228 }; 2229 2230 /** 2231 * Checks if the given string is strictly an address 2232 * 2233 * @method isStrictAddress 2234 * @param {String} address the given HEX adress 2235 * @return {Boolean} 2236 */ 2237 var isStrictAddress = function (address) { 2238 return /^0x[0-9a-f]{40}$/i.test(address); 2239 }; 2240 2241 /** 2242 * Checks if the given string is an address 2243 * 2244 * @method isAddress 2245 * @param {String} address the given HEX adress 2246 * @return {Boolean} 2247 */ 2248 var isAddress = function (address) { 2249 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2250 // check if it has the basic requirements of an address 2251 return false; 2252 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2253 // If it's all small caps or all all caps, return true 2254 return true; 2255 } else { 2256 // Otherwise check each case 2257 return isChecksumAddress(address); 2258 } 2259 }; 2260 2261 /** 2262 * Checks if the given string is a checksummed address 2263 * 2264 * @method isChecksumAddress 2265 * @param {String} address the given HEX adress 2266 * @return {Boolean} 2267 */ 2268 var isChecksumAddress = function (address) { 2269 // Check each case 2270 address = address.replace('0x',''); 2271 var addressHash = sha3(address.toLowerCase()); 2272 2273 for (var i = 0; i < 40; i++ ) { 2274 // the nth letter should be uppercase if the nth digit of casemap is 1 2275 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2276 return false; 2277 } 2278 } 2279 return true; 2280 }; 2281 2282 2283 2284 /** 2285 * Makes a checksum address 2286 * 2287 * @method toChecksumAddress 2288 * @param {String} address the given HEX adress 2289 * @return {String} 2290 */ 2291 var toChecksumAddress = function (address) { 2292 if (typeof address === 'undefined') return ''; 2293 2294 address = address.toLowerCase().replace('0x',''); 2295 var addressHash = sha3(address); 2296 var checksumAddress = '0x'; 2297 2298 for (var i = 0; i < address.length; i++ ) { 2299 // If ith character is 9 to f then make it uppercase 2300 if (parseInt(addressHash[i], 16) > 7) { 2301 checksumAddress += address[i].toUpperCase(); 2302 } else { 2303 checksumAddress += address[i]; 2304 } 2305 } 2306 return checksumAddress; 2307 }; 2308 2309 /** 2310 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2311 * 2312 * @method toAddress 2313 * @param {String} address 2314 * @return {String} formatted address 2315 */ 2316 var toAddress = function (address) { 2317 if (isStrictAddress(address)) { 2318 return address; 2319 } 2320 2321 if (/^[0-9a-f]{40}$/.test(address)) { 2322 return '0x' + address; 2323 } 2324 2325 return '0x' + padLeft(toHex(address).substr(2), 40); 2326 }; 2327 2328 /** 2329 * Returns true if object is BigNumber, otherwise false 2330 * 2331 * @method isBigNumber 2332 * @param {Object} 2333 * @return {Boolean} 2334 */ 2335 var isBigNumber = function (object) { 2336 return object instanceof BigNumber || 2337 (object && object.constructor && object.constructor.name === 'BigNumber'); 2338 }; 2339 2340 /** 2341 * Returns true if object is string, otherwise false 2342 * 2343 * @method isString 2344 * @param {Object} 2345 * @return {Boolean} 2346 */ 2347 var isString = function (object) { 2348 return typeof object === 'string' || 2349 (object && object.constructor && object.constructor.name === 'String'); 2350 }; 2351 2352 /** 2353 * Returns true if object is function, otherwise false 2354 * 2355 * @method isFunction 2356 * @param {Object} 2357 * @return {Boolean} 2358 */ 2359 var isFunction = function (object) { 2360 return typeof object === 'function'; 2361 }; 2362 2363 /** 2364 * Returns true if object is Objet, otherwise false 2365 * 2366 * @method isObject 2367 * @param {Object} 2368 * @return {Boolean} 2369 */ 2370 var isObject = function (object) { 2371 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2372 }; 2373 2374 /** 2375 * Returns true if object is boolean, otherwise false 2376 * 2377 * @method isBoolean 2378 * @param {Object} 2379 * @return {Boolean} 2380 */ 2381 var isBoolean = function (object) { 2382 return typeof object === 'boolean'; 2383 }; 2384 2385 /** 2386 * Returns true if object is array, otherwise false 2387 * 2388 * @method isArray 2389 * @param {Object} 2390 * @return {Boolean} 2391 */ 2392 var isArray = function (object) { 2393 return object instanceof Array; 2394 }; 2395 2396 /** 2397 * Returns true if given string is valid json object 2398 * 2399 * @method isJson 2400 * @param {String} 2401 * @return {Boolean} 2402 */ 2403 var isJson = function (str) { 2404 try { 2405 return !!JSON.parse(str); 2406 } catch (e) { 2407 return false; 2408 } 2409 }; 2410 2411 /** 2412 * Returns true if given string is a valid Ethereum block header bloom. 2413 * 2414 * @method isBloom 2415 * @param {String} hex encoded bloom filter 2416 * @return {Boolean} 2417 */ 2418 var isBloom = function (bloom) { 2419 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2420 return false; 2421 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2422 return true; 2423 } 2424 return false; 2425 }; 2426 2427 /** 2428 * Returns true if given string is a valid log topic. 2429 * 2430 * @method isTopic 2431 * @param {String} hex encoded topic 2432 * @return {Boolean} 2433 */ 2434 var isTopic = function (topic) { 2435 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2436 return false; 2437 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2438 return true; 2439 } 2440 return false; 2441 }; 2442 2443 module.exports = { 2444 padLeft: padLeft, 2445 padRight: padRight, 2446 toHex: toHex, 2447 toDecimal: toDecimal, 2448 fromDecimal: fromDecimal, 2449 toUtf8: toUtf8, 2450 toAscii: toAscii, 2451 fromUtf8: fromUtf8, 2452 fromAscii: fromAscii, 2453 transformToFullName: transformToFullName, 2454 extractDisplayName: extractDisplayName, 2455 extractTypeName: extractTypeName, 2456 toWei: toWei, 2457 fromWei: fromWei, 2458 toBigNumber: toBigNumber, 2459 toTwosComplement: toTwosComplement, 2460 toAddress: toAddress, 2461 isBigNumber: isBigNumber, 2462 isStrictAddress: isStrictAddress, 2463 isAddress: isAddress, 2464 isChecksumAddress: isChecksumAddress, 2465 toChecksumAddress: toChecksumAddress, 2466 isFunction: isFunction, 2467 isString: isString, 2468 isObject: isObject, 2469 isBoolean: isBoolean, 2470 isArray: isArray, 2471 isJson: isJson, 2472 isBloom: isBloom, 2473 isTopic: isTopic, 2474 }; 2475 2476 },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){ 2477 module.exports={ 2478 "version": "0.20.1" 2479 } 2480 2481 },{}],22:[function(require,module,exports){ 2482 /* 2483 This file is part of web3.js. 2484 2485 web3.js is free software: you can redistribute it and/or modify 2486 it under the terms of the GNU Lesser General Public License as published by 2487 the Free Software Foundation, either version 3 of the License, or 2488 (at your option) any later version. 2489 2490 web3.js is distributed in the hope that it will be useful, 2491 but WITHOUT ANY WARRANTY; without even the implied warranty of 2492 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2493 GNU Lesser General Public License for more details. 2494 2495 You should have received a copy of the GNU Lesser General Public License 2496 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2497 */ 2498 /** 2499 * @file web3.js 2500 * @authors: 2501 * Jeffrey Wilcke <jeff@ethdev.com> 2502 * Marek Kotewicz <marek@ethdev.com> 2503 * Marian Oancea <marian@ethdev.com> 2504 * Fabian Vogelsteller <fabian@ethdev.com> 2505 * Gav Wood <g@ethdev.com> 2506 * @date 2014 2507 */ 2508 2509 var RequestManager = require('./web3/requestmanager'); 2510 var Iban = require('./web3/iban'); 2511 var Qct = require('./web3/methods/eth'); 2512 var DB = require('./web3/methods/db'); 2513 var Shh = require('./web3/methods/shh'); 2514 var Net = require('./web3/methods/net'); 2515 var Personal = require('./web3/methods/personal'); 2516 var Swarm = require('./web3/methods/swarm'); 2517 var Settings = require('./web3/settings'); 2518 var version = require('./version.json'); 2519 var utils = require('./utils/utils'); 2520 var sha3 = require('./utils/sha3'); 2521 var extend = require('./web3/extend'); 2522 var Batch = require('./web3/batch'); 2523 var Property = require('./web3/property'); 2524 var HttpProvider = require('./web3/httpprovider'); 2525 var IpcProvider = require('./web3/ipcprovider'); 2526 var BigNumber = require('bignumber.js'); 2527 2528 function Web3 (provider) { 2529 this._requestManager = new RequestManager(provider); 2530 this.currentProvider = provider; 2531 this.qct = new Qct(this); 2532 this.db = new DB(this); 2533 this.shh = new Shh(this); 2534 this.net = new Net(this); 2535 this.personal = new Personal(this); 2536 this.bzz = new Swarm(this); 2537 this.settings = new Settings(); 2538 this.version = { 2539 api: version.version 2540 }; 2541 this.providers = { 2542 HttpProvider: HttpProvider, 2543 IpcProvider: IpcProvider 2544 }; 2545 this._extend = extend(this); 2546 this._extend({ 2547 properties: properties() 2548 }); 2549 } 2550 2551 // expose providers on the class 2552 Web3.providers = { 2553 HttpProvider: HttpProvider, 2554 IpcProvider: IpcProvider 2555 }; 2556 2557 Web3.prototype.setProvider = function (provider) { 2558 this._requestManager.setProvider(provider); 2559 this.currentProvider = provider; 2560 }; 2561 2562 Web3.prototype.reset = function (keepIsSyncing) { 2563 this._requestManager.reset(keepIsSyncing); 2564 this.settings = new Settings(); 2565 }; 2566 2567 Web3.prototype.BigNumber = BigNumber; 2568 Web3.prototype.toHex = utils.toHex; 2569 Web3.prototype.toAscii = utils.toAscii; 2570 Web3.prototype.toUtf8 = utils.toUtf8; 2571 Web3.prototype.fromAscii = utils.fromAscii; 2572 Web3.prototype.fromUtf8 = utils.fromUtf8; 2573 Web3.prototype.toDecimal = utils.toDecimal; 2574 Web3.prototype.fromDecimal = utils.fromDecimal; 2575 Web3.prototype.toBigNumber = utils.toBigNumber; 2576 Web3.prototype.toWei = utils.toWei; 2577 Web3.prototype.fromWei = utils.fromWei; 2578 Web3.prototype.isAddress = utils.isAddress; 2579 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2580 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2581 Web3.prototype.isIBAN = utils.isIBAN; 2582 Web3.prototype.padLeft = utils.padLeft; 2583 Web3.prototype.padRight = utils.padRight; 2584 2585 2586 Web3.prototype.sha3 = function(string, options) { 2587 return '0x' + sha3(string, options); 2588 }; 2589 2590 /** 2591 * Transforms direct icap to address 2592 */ 2593 Web3.prototype.fromICAP = function (icap) { 2594 var iban = new Iban(icap); 2595 return iban.address(); 2596 }; 2597 2598 var properties = function () { 2599 return [ 2600 new Property({ 2601 name: 'version.node', 2602 getter: 'web3_clientVersion' 2603 }), 2604 new Property({ 2605 name: 'version.network', 2606 getter: 'net_version', 2607 inputFormatter: utils.toDecimal 2608 }), 2609 new Property({ 2610 name: 'version.quickchain', 2611 getter: 'qct_protocolVersion', 2612 inputFormatter: utils.toDecimal 2613 }), 2614 new Property({ 2615 name: 'version.whisper', 2616 getter: 'shh_version', 2617 inputFormatter: utils.toDecimal 2618 }) 2619 ]; 2620 }; 2621 2622 Web3.prototype.isConnected = function(){ 2623 return (this.currentProvider && this.currentProvider.isConnected()); 2624 }; 2625 2626 Web3.prototype.createBatch = function () { 2627 return new Batch(this); 2628 }; 2629 2630 module.exports = Web3; 2631 2632 2633 },{"./utils/sha3":19,"./utils/utils":20,"./version.json":21,"./web3/batch":24,"./web3/extend":28,"./web3/httpprovider":32,"./web3/iban":33,"./web3/ipcprovider":34,"./web3/methods/db":37,"./web3/methods/eth":38,"./web3/methods/net":39,"./web3/methods/personal":40,"./web3/methods/shh":41,"./web3/methods/swarm":42,"./web3/property":45,"./web3/requestmanager":46,"./web3/settings":47,"bignumber.js":"bignumber.js"}],23:[function(require,module,exports){ 2634 /* 2635 This file is part of web3.js. 2636 2637 web3.js is free software: you can redistribute it and/or modify 2638 it under the terms of the GNU Lesser General Public License as published by 2639 the Free Software Foundation, either version 3 of the License, or 2640 (at your option) any later version. 2641 2642 web3.js is distributed in the hope that it will be useful, 2643 but WITHOUT ANY WARRANTY; without even the implied warranty of 2644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2645 GNU Lesser General Public License for more details. 2646 2647 You should have received a copy of the GNU Lesser General Public License 2648 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2649 */ 2650 /** 2651 * @file allevents.js 2652 * @author Marek Kotewicz <marek@ethdev.com> 2653 * @date 2014 2654 */ 2655 2656 var sha3 = require('../utils/sha3'); 2657 var SolidityEvent = require('./event'); 2658 var formatters = require('./formatters'); 2659 var utils = require('../utils/utils'); 2660 var Filter = require('./filter'); 2661 var watches = require('./methods/watches'); 2662 2663 var AllSolidityEvents = function (requestManager, json, address) { 2664 this._requestManager = requestManager; 2665 this._json = json; 2666 this._address = address; 2667 }; 2668 2669 AllSolidityEvents.prototype.encode = function (options) { 2670 options = options || {}; 2671 var result = {}; 2672 2673 ['fromBlock', 'toBlock'].filter(function (f) { 2674 return options[f] !== undefined; 2675 }).forEach(function (f) { 2676 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2677 }); 2678 2679 result.address = this._address; 2680 2681 return result; 2682 }; 2683 2684 AllSolidityEvents.prototype.decode = function (data) { 2685 data.data = data.data || ''; 2686 data.topics = data.topics || []; 2687 2688 var eventTopic = data.topics[0].slice(2); 2689 var match = this._json.filter(function (j) { 2690 return eventTopic === sha3(utils.transformToFullName(j)); 2691 })[0]; 2692 2693 if (!match) { // cannot find matching event? 2694 console.warn('cannot find event for log'); 2695 return data; 2696 } 2697 2698 var event = new SolidityEvent(this._requestManager, match, this._address); 2699 return event.decode(data); 2700 }; 2701 2702 AllSolidityEvents.prototype.execute = function (options, callback) { 2703 2704 if (utils.isFunction(arguments[arguments.length - 1])) { 2705 callback = arguments[arguments.length - 1]; 2706 if(arguments.length === 1) 2707 options = null; 2708 } 2709 2710 var o = this.encode(options); 2711 var formatter = this.decode.bind(this); 2712 return new Filter(o, 'qct', this._requestManager, watches.qct(), formatter, callback); 2713 }; 2714 2715 AllSolidityEvents.prototype.attachToContract = function (contract) { 2716 var execute = this.execute.bind(this); 2717 contract.allEvents = execute; 2718 }; 2719 2720 module.exports = AllSolidityEvents; 2721 2722 2723 },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){ 2724 /* 2725 This file is part of web3.js. 2726 2727 web3.js is free software: you can redistribute it and/or modify 2728 it under the terms of the GNU Lesser General Public License as published by 2729 the Free Software Foundation, either version 3 of the License, or 2730 (at your option) any later version. 2731 2732 web3.js is distributed in the hope that it will be useful, 2733 but WITHOUT ANY WARRANTY; without even the implied warranty of 2734 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2735 GNU Lesser General Public License for more details. 2736 2737 You should have received a copy of the GNU Lesser General Public License 2738 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2739 */ 2740 /** 2741 * @file batch.js 2742 * @author Marek Kotewicz <marek@ethdev.com> 2743 * @date 2015 2744 */ 2745 2746 var Jsonrpc = require('./jsonrpc'); 2747 var errors = require('./errors'); 2748 2749 var Batch = function (web3) { 2750 this.requestManager = web3._requestManager; 2751 this.requests = []; 2752 }; 2753 2754 /** 2755 * Should be called to add create new request to batch request 2756 * 2757 * @method add 2758 * @param {Object} jsonrpc requet object 2759 */ 2760 Batch.prototype.add = function (request) { 2761 this.requests.push(request); 2762 }; 2763 2764 /** 2765 * Should be called to execute batch request 2766 * 2767 * @method execute 2768 */ 2769 Batch.prototype.execute = function () { 2770 var requests = this.requests; 2771 this.requestManager.sendBatch(requests, function (err, results) { 2772 results = results || []; 2773 requests.map(function (request, index) { 2774 return results[index] || {}; 2775 }).forEach(function (result, index) { 2776 if (requests[index].callback) { 2777 2778 if (!Jsonrpc.isValidResponse(result)) { 2779 return requests[index].callback(errors.InvalidResponse(result)); 2780 } 2781 2782 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2783 } 2784 }); 2785 }); 2786 }; 2787 2788 module.exports = Batch; 2789 2790 2791 },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){ 2792 /* 2793 This file is part of web3.js. 2794 2795 web3.js is free software: you can redistribute it and/or modify 2796 it under the terms of the GNU Lesser General Public License as published by 2797 the Free Software Foundation, either version 3 of the License, or 2798 (at your option) any later version. 2799 2800 web3.js is distributed in the hope that it will be useful, 2801 but WITHOUT ANY WARRANTY; without even the implied warranty of 2802 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2803 GNU Lesser General Public License for more details. 2804 2805 You should have received a copy of the GNU Lesser General Public License 2806 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2807 */ 2808 /** 2809 * @file contract.js 2810 * @author Marek Kotewicz <marek@ethdev.com> 2811 * @date 2014 2812 */ 2813 2814 var utils = require('../utils/utils'); 2815 var coder = require('../solidity/coder'); 2816 var SolidityEvent = require('./event'); 2817 var SolidityFunction = require('./function'); 2818 var AllEvents = require('./allevents'); 2819 2820 /** 2821 * Should be called to encode constructor params 2822 * 2823 * @method encodeConstructorParams 2824 * @param {Array} abi 2825 * @param {Array} constructor params 2826 */ 2827 var encodeConstructorParams = function (abi, params) { 2828 return abi.filter(function (json) { 2829 return json.type === 'constructor' && json.inputs.length === params.length; 2830 }).map(function (json) { 2831 return json.inputs.map(function (input) { 2832 return input.type; 2833 }); 2834 }).map(function (types) { 2835 return coder.encodeParams(types, params); 2836 })[0] || ''; 2837 }; 2838 2839 /** 2840 * Should be called to add functions to contract object 2841 * 2842 * @method addFunctionsToContract 2843 * @param {Contract} contract 2844 * @param {Array} abi 2845 */ 2846 var addFunctionsToContract = function (contract) { 2847 contract.abi.filter(function (json) { 2848 return json.type === 'function'; 2849 }).map(function (json) { 2850 return new SolidityFunction(contract._qct, json, contract.address); 2851 }).forEach(function (f) { 2852 f.attachToContract(contract); 2853 }); 2854 }; 2855 2856 /** 2857 * Should be called to add events to contract object 2858 * 2859 * @method addEventsToContract 2860 * @param {Contract} contract 2861 * @param {Array} abi 2862 */ 2863 var addEventsToContract = function (contract) { 2864 var events = contract.abi.filter(function (json) { 2865 return json.type === 'event'; 2866 }); 2867 2868 var All = new AllEvents(contract._qct._requestManager, events, contract.address); 2869 All.attachToContract(contract); 2870 2871 events.map(function (json) { 2872 return new SolidityEvent(contract._qct._requestManager, json, contract.address); 2873 }).forEach(function (e) { 2874 e.attachToContract(contract); 2875 }); 2876 }; 2877 2878 2879 /** 2880 * Should be called to check if the contract gets properly deployed on the blockchain. 2881 * 2882 * @method checkForContractAddress 2883 * @param {Object} contract 2884 * @param {Function} callback 2885 * @returns {Undefined} 2886 */ 2887 var checkForContractAddress = function(contract, callback){ 2888 var count = 0, 2889 callbackFired = false; 2890 2891 // wait for receipt 2892 var filter = contract._qct.filter('latest', function(e){ 2893 if (!e && !callbackFired) { 2894 count++; 2895 2896 // stop watching after 50 blocks (timeout) 2897 if (count > 50) { 2898 2899 filter.stopWatching(function() {}); 2900 callbackFired = true; 2901 2902 if (callback) 2903 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2904 else 2905 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2906 2907 2908 } else { 2909 2910 contract._qct.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 2911 if(receipt && !callbackFired) { 2912 2913 contract._qct.getCode(receipt.contractAddress, function(e, code){ 2914 /*jshint maxcomplexity: 6 */ 2915 2916 if(callbackFired || !code) 2917 return; 2918 2919 filter.stopWatching(function() {}); 2920 callbackFired = true; 2921 2922 if(code.length > 3) { 2923 2924 // console.log('Contract code deployed!'); 2925 2926 contract.address = receipt.contractAddress; 2927 2928 // attach events and methods again after we have 2929 addFunctionsToContract(contract); 2930 addEventsToContract(contract); 2931 2932 // call callback for the second time 2933 if(callback) 2934 callback(null, contract); 2935 2936 } else { 2937 if(callback) 2938 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 2939 else 2940 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 2941 } 2942 }); 2943 } 2944 }); 2945 } 2946 } 2947 }); 2948 }; 2949 2950 /** 2951 * Should be called to create new ContractFactory instance 2952 * 2953 * @method ContractFactory 2954 * @param {Array} abi 2955 */ 2956 var ContractFactory = function (qct, abi) { 2957 this.qct = qct; 2958 this.abi = abi; 2959 2960 /** 2961 * Should be called to create new contract on a blockchain 2962 * 2963 * @method new 2964 * @param {Any} contract constructor param1 (optional) 2965 * @param {Any} contract constructor param2 (optional) 2966 * @param {Object} contract transaction object (required) 2967 * @param {Function} callback 2968 * @returns {Contract} returns contract instance 2969 */ 2970 this.new = function () { 2971 /*jshint maxcomplexity: 7 */ 2972 2973 var contract = new Contract(this.qct, this.abi); 2974 2975 // parse arguments 2976 var options = {}; // required! 2977 var callback; 2978 2979 var args = Array.prototype.slice.call(arguments); 2980 if (utils.isFunction(args[args.length - 1])) { 2981 callback = args.pop(); 2982 } 2983 2984 var last = args[args.length - 1]; 2985 if (utils.isObject(last) && !utils.isArray(last)) { 2986 options = args.pop(); 2987 } 2988 2989 if (options.value > 0) { 2990 var constructorAbi = abi.filter(function (json) { 2991 return json.type === 'constructor' && json.inputs.length === args.length; 2992 })[0] || {}; 2993 2994 if (!constructorAbi.payable) { 2995 throw new Error('Cannot send value to non-payable constructor'); 2996 } 2997 } 2998 2999 var bytes = encodeConstructorParams(this.abi, args); 3000 options.data += bytes; 3001 3002 if (callback) { 3003 3004 // wait for the contract address adn check if the code was deployed 3005 this.qct.sendTransaction(options, function (err, hash) { 3006 if (err) { 3007 callback(err); 3008 } else { 3009 // add the transaction hash 3010 contract.transactionHash = hash; 3011 3012 // call callback for the first time 3013 callback(null, contract); 3014 3015 checkForContractAddress(contract, callback); 3016 } 3017 }); 3018 } else { 3019 var hash = this.qct.sendTransaction(options); 3020 // add the transaction hash 3021 contract.transactionHash = hash; 3022 checkForContractAddress(contract); 3023 } 3024 3025 return contract; 3026 }; 3027 3028 this.new.getData = this.getData.bind(this); 3029 }; 3030 3031 /** 3032 * Should be called to create new ContractFactory 3033 * 3034 * @method contract 3035 * @param {Array} abi 3036 * @returns {ContractFactory} new contract factory 3037 */ 3038 //var contract = function (abi) { 3039 //return new ContractFactory(abi); 3040 //}; 3041 3042 3043 3044 /** 3045 * Should be called to get access to existing contract on a blockchain 3046 * 3047 * @method at 3048 * @param {Address} contract address (required) 3049 * @param {Function} callback {optional) 3050 * @returns {Contract} returns contract if no callback was passed, 3051 * otherwise calls callback function (err, contract) 3052 */ 3053 ContractFactory.prototype.at = function (address, callback) { 3054 var contract = new Contract(this.qct, this.abi, address); 3055 3056 // this functions are not part of prototype, 3057 // because we dont want to spoil the interface 3058 addFunctionsToContract(contract); 3059 addEventsToContract(contract); 3060 3061 if (callback) { 3062 callback(null, contract); 3063 } 3064 return contract; 3065 }; 3066 3067 /** 3068 * Gets the data, which is data to deploy plus constructor params 3069 * 3070 * @method getData 3071 */ 3072 ContractFactory.prototype.getData = function () { 3073 var options = {}; // required! 3074 var args = Array.prototype.slice.call(arguments); 3075 3076 var last = args[args.length - 1]; 3077 if (utils.isObject(last) && !utils.isArray(last)) { 3078 options = args.pop(); 3079 } 3080 3081 var bytes = encodeConstructorParams(this.abi, args); 3082 options.data += bytes; 3083 3084 return options.data; 3085 }; 3086 3087 /** 3088 * Should be called to create new contract instance 3089 * 3090 * @method Contract 3091 * @param {Array} abi 3092 * @param {Address} contract address 3093 */ 3094 var Contract = function (qct, abi, address) { 3095 this._qct = qct; 3096 this.transactionHash = null; 3097 this.address = address; 3098 this.abi = abi; 3099 }; 3100 3101 module.exports = ContractFactory; 3102 3103 },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){ 3104 /* 3105 This file is part of web3.js. 3106 3107 web3.js is free software: you can redistribute it and/or modify 3108 it under the terms of the GNU Lesser General Public License as published by 3109 the Free Software Foundation, either version 3 of the License, or 3110 (at your option) any later version. 3111 3112 web3.js is distributed in the hope that it will be useful, 3113 but WITHOUT ANY WARRANTY; without even the implied warranty of 3114 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3115 GNU Lesser General Public License for more details. 3116 3117 You should have received a copy of the GNU Lesser General Public License 3118 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3119 */ 3120 /** 3121 * @file errors.js 3122 * @author Marek Kotewicz <marek@ethdev.com> 3123 * @date 2015 3124 */ 3125 3126 module.exports = { 3127 InvalidNumberOfSolidityArgs: function () { 3128 return new Error('Invalid number of arguments to Solidity function'); 3129 }, 3130 InvalidNumberOfRPCParams: function () { 3131 return new Error('Invalid number of input parameters to RPC method'); 3132 }, 3133 InvalidConnection: function (host){ 3134 return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 3135 }, 3136 InvalidProvider: function () { 3137 return new Error('Provider not set or invalid'); 3138 }, 3139 InvalidResponse: function (result){ 3140 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3141 return new Error(message); 3142 }, 3143 ConnectionTimeout: function (ms){ 3144 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3145 } 3146 }; 3147 3148 },{}],27:[function(require,module,exports){ 3149 /* 3150 This file is part of web3.js. 3151 3152 web3.js is free software: you can redistribute it and/or modify 3153 it under the terms of the GNU Lesser General Public License as published by 3154 the Free Software Foundation, either version 3 of the License, or 3155 (at your option) any later version. 3156 3157 web3.js is distributed in the hope that it will be useful, 3158 but WITHOUT ANY WARRANTY; without even the implied warranty of 3159 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3160 GNU Lesser General Public License for more details. 3161 3162 You should have received a copy of the GNU Lesser General Public License 3163 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3164 */ 3165 /** 3166 * @file event.js 3167 * @author Marek Kotewicz <marek@ethdev.com> 3168 * @date 2014 3169 */ 3170 3171 var utils = require('../utils/utils'); 3172 var coder = require('../solidity/coder'); 3173 var formatters = require('./formatters'); 3174 var sha3 = require('../utils/sha3'); 3175 var Filter = require('./filter'); 3176 var watches = require('./methods/watches'); 3177 3178 /** 3179 * This prototype should be used to create event filters 3180 */ 3181 var SolidityEvent = function (requestManager, json, address) { 3182 this._requestManager = requestManager; 3183 this._params = json.inputs; 3184 this._name = utils.transformToFullName(json); 3185 this._address = address; 3186 this._anonymous = json.anonymous; 3187 }; 3188 3189 /** 3190 * Should be used to get filtered param types 3191 * 3192 * @method types 3193 * @param {Bool} decide if returned typed should be indexed 3194 * @return {Array} array of types 3195 */ 3196 SolidityEvent.prototype.types = function (indexed) { 3197 return this._params.filter(function (i) { 3198 return i.indexed === indexed; 3199 }).map(function (i) { 3200 return i.type; 3201 }); 3202 }; 3203 3204 /** 3205 * Should be used to get event display name 3206 * 3207 * @method displayName 3208 * @return {String} event display name 3209 */ 3210 SolidityEvent.prototype.displayName = function () { 3211 return utils.extractDisplayName(this._name); 3212 }; 3213 3214 /** 3215 * Should be used to get event type name 3216 * 3217 * @method typeName 3218 * @return {String} event type name 3219 */ 3220 SolidityEvent.prototype.typeName = function () { 3221 return utils.extractTypeName(this._name); 3222 }; 3223 3224 /** 3225 * Should be used to get event signature 3226 * 3227 * @method signature 3228 * @return {String} event signature 3229 */ 3230 SolidityEvent.prototype.signature = function () { 3231 return sha3(this._name); 3232 }; 3233 3234 /** 3235 * Should be used to encode indexed params and options to one final object 3236 * 3237 * @method encode 3238 * @param {Object} indexed 3239 * @param {Object} options 3240 * @return {Object} everything combined together and encoded 3241 */ 3242 SolidityEvent.prototype.encode = function (indexed, options) { 3243 indexed = indexed || {}; 3244 options = options || {}; 3245 var result = {}; 3246 3247 ['fromBlock', 'toBlock'].filter(function (f) { 3248 return options[f] !== undefined; 3249 }).forEach(function (f) { 3250 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3251 }); 3252 3253 result.topics = []; 3254 3255 result.address = this._address; 3256 if (!this._anonymous) { 3257 result.topics.push('0x' + this.signature()); 3258 } 3259 3260 var indexedTopics = this._params.filter(function (i) { 3261 return i.indexed === true; 3262 }).map(function (i) { 3263 var value = indexed[i.name]; 3264 if (value === undefined || value === null) { 3265 return null; 3266 } 3267 3268 if (utils.isArray(value)) { 3269 return value.map(function (v) { 3270 return '0x' + coder.encodeParam(i.type, v); 3271 }); 3272 } 3273 return '0x' + coder.encodeParam(i.type, value); 3274 }); 3275 3276 result.topics = result.topics.concat(indexedTopics); 3277 3278 return result; 3279 }; 3280 3281 /** 3282 * Should be used to decode indexed params and options 3283 * 3284 * @method decode 3285 * @param {Object} data 3286 * @return {Object} result object with decoded indexed && not indexed params 3287 */ 3288 SolidityEvent.prototype.decode = function (data) { 3289 3290 data.data = data.data || ''; 3291 data.topics = data.topics || []; 3292 3293 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3294 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3295 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3296 3297 var notIndexedData = data.data.slice(2); 3298 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3299 3300 var result = formatters.outputLogFormatter(data); 3301 result.event = this.displayName(); 3302 result.address = data.address; 3303 3304 result.args = this._params.reduce(function (acc, current) { 3305 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3306 return acc; 3307 }, {}); 3308 3309 delete result.data; 3310 delete result.topics; 3311 3312 return result; 3313 }; 3314 3315 /** 3316 * Should be used to create new filter object from event 3317 * 3318 * @method execute 3319 * @param {Object} indexed 3320 * @param {Object} options 3321 * @return {Object} filter object 3322 */ 3323 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3324 3325 if (utils.isFunction(arguments[arguments.length - 1])) { 3326 callback = arguments[arguments.length - 1]; 3327 if(arguments.length === 2) 3328 options = null; 3329 if(arguments.length === 1) { 3330 options = null; 3331 indexed = {}; 3332 } 3333 } 3334 3335 var o = this.encode(indexed, options); 3336 var formatter = this.decode.bind(this); 3337 return new Filter(o, 'qct', this._requestManager, watches.qct(), formatter, callback); 3338 }; 3339 3340 /** 3341 * Should be used to attach event to contract object 3342 * 3343 * @method attachToContract 3344 * @param {Contract} 3345 */ 3346 SolidityEvent.prototype.attachToContract = function (contract) { 3347 var execute = this.execute.bind(this); 3348 var displayName = this.displayName(); 3349 if (!contract[displayName]) { 3350 contract[displayName] = execute; 3351 } 3352 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3353 }; 3354 3355 module.exports = SolidityEvent; 3356 3357 3358 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){ 3359 var formatters = require('./formatters'); 3360 var utils = require('./../utils/utils'); 3361 var Method = require('./method'); 3362 var Property = require('./property'); 3363 3364 // TODO: refactor, so the input params are not altered. 3365 // it's necessary to make same 'extension' work with multiple providers 3366 var extend = function (web3) { 3367 /* jshint maxcomplexity:5 */ 3368 var ex = function (extension) { 3369 3370 var extendedObject; 3371 if (extension.property) { 3372 if (!web3[extension.property]) { 3373 web3[extension.property] = {}; 3374 } 3375 extendedObject = web3[extension.property]; 3376 } else { 3377 extendedObject = web3; 3378 } 3379 3380 if (extension.methods) { 3381 extension.methods.forEach(function (method) { 3382 method.attachToObject(extendedObject); 3383 method.setRequestManager(web3._requestManager); 3384 }); 3385 } 3386 3387 if (extension.properties) { 3388 extension.properties.forEach(function (property) { 3389 property.attachToObject(extendedObject); 3390 property.setRequestManager(web3._requestManager); 3391 }); 3392 } 3393 }; 3394 3395 ex.formatters = formatters; 3396 ex.utils = utils; 3397 ex.Method = Method; 3398 ex.Property = Property; 3399 3400 return ex; 3401 }; 3402 3403 3404 3405 module.exports = extend; 3406 3407 3408 },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){ 3409 /* 3410 This file is part of web3.js. 3411 3412 web3.js is free software: you can redistribute it and/or modify 3413 it under the terms of the GNU Lesser General Public License as published by 3414 the Free Software Foundation, either version 3 of the License, or 3415 (at your option) any later version. 3416 3417 web3.js is distributed in the hope that it will be useful, 3418 but WITHOUT ANY WARRANTY; without even the implied warranty of 3419 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3420 GNU Lesser General Public License for more details. 3421 3422 You should have received a copy of the GNU Lesser General Public License 3423 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3424 */ 3425 /** @file filter.js 3426 * @authors: 3427 * Jeffrey Wilcke <jeff@ethdev.com> 3428 * Marek Kotewicz <marek@ethdev.com> 3429 * Marian Oancea <marian@ethdev.com> 3430 * Fabian Vogelsteller <fabian@ethdev.com> 3431 * Gav Wood <g@ethdev.com> 3432 * @date 2014 3433 */ 3434 3435 var formatters = require('./formatters'); 3436 var utils = require('../utils/utils'); 3437 3438 /** 3439 * Converts a given topic to a hex string, but also allows null values. 3440 * 3441 * @param {Mixed} value 3442 * @return {String} 3443 */ 3444 var toTopic = function(value){ 3445 3446 if(value === null || typeof value === 'undefined') 3447 return null; 3448 3449 value = String(value); 3450 3451 if(value.indexOf('0x') === 0) 3452 return value; 3453 else 3454 return utils.fromUtf8(value); 3455 }; 3456 3457 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3458 /// @param should be string or object 3459 /// @returns options string or object 3460 var getOptions = function (options, type) { 3461 /*jshint maxcomplexity: 6 */ 3462 3463 if (utils.isString(options)) { 3464 return options; 3465 } 3466 3467 options = options || {}; 3468 3469 3470 switch(type) { 3471 case 'qct': 3472 3473 // make sure topics, get converted to hex 3474 options.topics = options.topics || []; 3475 options.topics = options.topics.map(function(topic){ 3476 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3477 }); 3478 3479 return { 3480 topics: options.topics, 3481 from: options.from, 3482 to: options.to, 3483 address: options.address, 3484 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3485 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3486 }; 3487 case 'shh': 3488 return options; 3489 } 3490 }; 3491 3492 /** 3493 Adds the callback and sets up the methods, to iterate over the results. 3494 3495 @method getLogsAtStart 3496 @param {Object} self 3497 @param {function} callback 3498 */ 3499 var getLogsAtStart = function(self, callback){ 3500 // call getFilterLogs for the first watch callback start 3501 if (!utils.isString(self.options)) { 3502 self.get(function (err, messages) { 3503 // don't send all the responses to all the watches again... just to self one 3504 if (err) { 3505 callback(err); 3506 } 3507 3508 if(utils.isArray(messages)) { 3509 messages.forEach(function (message) { 3510 callback(null, message); 3511 }); 3512 } 3513 }); 3514 } 3515 }; 3516 3517 /** 3518 Adds the callback and sets up the methods, to iterate over the results. 3519 3520 @method pollFilter 3521 @param {Object} self 3522 */ 3523 var pollFilter = function(self) { 3524 3525 var onMessage = function (error, messages) { 3526 if (error) { 3527 return self.callbacks.forEach(function (callback) { 3528 callback(error); 3529 }); 3530 } 3531 3532 if(utils.isArray(messages)) { 3533 messages.forEach(function (message) { 3534 message = self.formatter ? self.formatter(message) : message; 3535 self.callbacks.forEach(function (callback) { 3536 callback(null, message); 3537 }); 3538 }); 3539 } 3540 }; 3541 3542 self.requestManager.startPolling({ 3543 method: self.implementation.poll.call, 3544 params: [self.filterId], 3545 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3546 3547 }; 3548 3549 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3550 var self = this; 3551 var implementation = {}; 3552 methods.forEach(function (method) { 3553 method.setRequestManager(requestManager); 3554 method.attachToObject(implementation); 3555 }); 3556 this.requestManager = requestManager; 3557 this.options = getOptions(options, type); 3558 this.implementation = implementation; 3559 this.filterId = null; 3560 this.callbacks = []; 3561 this.getLogsCallbacks = []; 3562 this.pollFilters = []; 3563 this.formatter = formatter; 3564 this.implementation.newFilter(this.options, function(error, id){ 3565 if(error) { 3566 self.callbacks.forEach(function(cb){ 3567 cb(error); 3568 }); 3569 if (typeof filterCreationErrorCallback === 'function') { 3570 filterCreationErrorCallback(error); 3571 } 3572 } else { 3573 self.filterId = id; 3574 3575 // check if there are get pending callbacks as a consequence 3576 // of calling get() with filterId unassigned. 3577 self.getLogsCallbacks.forEach(function (cb){ 3578 self.get(cb); 3579 }); 3580 self.getLogsCallbacks = []; 3581 3582 // get filter logs for the already existing watch calls 3583 self.callbacks.forEach(function(cb){ 3584 getLogsAtStart(self, cb); 3585 }); 3586 if(self.callbacks.length > 0) 3587 pollFilter(self); 3588 3589 // start to watch immediately 3590 if(typeof callback === 'function') { 3591 return self.watch(callback); 3592 } 3593 } 3594 }); 3595 3596 return this; 3597 }; 3598 3599 Filter.prototype.watch = function (callback) { 3600 this.callbacks.push(callback); 3601 3602 if(this.filterId) { 3603 getLogsAtStart(this, callback); 3604 pollFilter(this); 3605 } 3606 3607 return this; 3608 }; 3609 3610 Filter.prototype.stopWatching = function (callback) { 3611 this.requestManager.stopPolling(this.filterId); 3612 this.callbacks = []; 3613 // remove filter async 3614 if (callback) { 3615 this.implementation.uninstallFilter(this.filterId, callback); 3616 } else { 3617 return this.implementation.uninstallFilter(this.filterId); 3618 } 3619 }; 3620 3621 Filter.prototype.get = function (callback) { 3622 var self = this; 3623 if (utils.isFunction(callback)) { 3624 if (this.filterId === null) { 3625 // If filterId is not set yet, call it back 3626 // when newFilter() assigns it. 3627 this.getLogsCallbacks.push(callback); 3628 } else { 3629 this.implementation.getLogs(this.filterId, function(err, res){ 3630 if (err) { 3631 callback(err); 3632 } else { 3633 callback(null, res.map(function (log) { 3634 return self.formatter ? self.formatter(log) : log; 3635 })); 3636 } 3637 }); 3638 } 3639 } else { 3640 if (this.filterId === null) { 3641 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3642 } 3643 var logs = this.implementation.getLogs(this.filterId); 3644 return logs.map(function (log) { 3645 return self.formatter ? self.formatter(log) : log; 3646 }); 3647 } 3648 3649 return this; 3650 }; 3651 3652 module.exports = Filter; 3653 3654 3655 },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){ 3656 'use strict' 3657 3658 /* 3659 This file is part of web3.js. 3660 3661 web3.js is free software: you can redistribute it and/or modify 3662 it under the terms of the GNU Lesser General Public License as published by 3663 the Free Software Foundation, either version 3 of the License, or 3664 (at your option) any later version. 3665 3666 web3.js is distributed in the hope that it will be useful, 3667 but WITHOUT ANY WARRANTY; without even the implied warranty of 3668 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3669 GNU Lesser General Public License for more details. 3670 3671 You should have received a copy of the GNU Lesser General Public License 3672 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3673 */ 3674 /** 3675 * @file formatters.js 3676 * @author Marek Kotewicz <marek@ethdev.com> 3677 * @author Fabian Vogelsteller <fabian@ethdev.com> 3678 * @date 2015 3679 */ 3680 3681 var utils = require('../utils/utils'); 3682 var config = require('../utils/config'); 3683 var Iban = require('./iban'); 3684 3685 /** 3686 * Should the format output to a big number 3687 * 3688 * @method outputBigNumberFormatter 3689 * @param {String|Number|BigNumber} 3690 * @returns {BigNumber} object 3691 */ 3692 var outputBigNumberFormatter = function (number) { 3693 return utils.toBigNumber(number); 3694 }; 3695 3696 var isPredefinedBlockNumber = function (blockNumber) { 3697 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3698 }; 3699 3700 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3701 if (blockNumber === undefined) { 3702 return config.defaultBlock; 3703 } 3704 return inputBlockNumberFormatter(blockNumber); 3705 }; 3706 3707 var inputBlockNumberFormatter = function (blockNumber) { 3708 if (blockNumber === undefined) { 3709 return undefined; 3710 } else if (isPredefinedBlockNumber(blockNumber)) { 3711 return blockNumber; 3712 } 3713 return utils.toHex(blockNumber); 3714 }; 3715 3716 /** 3717 * Formats the input of a transaction and converts all values to HEX 3718 * 3719 * @method inputCallFormatter 3720 * @param {Object} transaction options 3721 * @returns object 3722 */ 3723 var inputCallFormatter = function (options){ 3724 3725 options.from = options.from || config.defaultAccount; 3726 3727 if (options.from) { 3728 options.from = inputAddressFormatter(options.from); 3729 } 3730 3731 if (options.to) { // it might be contract creation 3732 options.to = inputAddressFormatter(options.to); 3733 } 3734 3735 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3736 return options[key] !== undefined; 3737 }).forEach(function(key){ 3738 options[key] = utils.fromDecimal(options[key]); 3739 }); 3740 3741 return options; 3742 }; 3743 3744 /** 3745 * Formats the input of a transaction and converts all values to HEX 3746 * 3747 * @method inputTransactionFormatter 3748 * @param {Object} transaction options 3749 * @returns object 3750 */ 3751 var inputTransactionFormatter = function (options){ 3752 3753 options.from = options.from || config.defaultAccount; 3754 options.from = inputAddressFormatter(options.from); 3755 3756 if (options.to) { // it might be contract creation 3757 options.to = inputAddressFormatter(options.to); 3758 } 3759 3760 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3761 return options[key] !== undefined; 3762 }).forEach(function(key){ 3763 options[key] = utils.fromDecimal(options[key]); 3764 }); 3765 3766 return options; 3767 }; 3768 3769 /** 3770 * Formats the output of a transaction to its proper values 3771 * 3772 * @method outputTransactionFormatter 3773 * @param {Object} tx 3774 * @returns {Object} 3775 */ 3776 var outputTransactionFormatter = function (tx){ 3777 if(tx.blockNumber !== null) 3778 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3779 if(tx.transactionIndex !== null) 3780 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3781 tx.nonce = utils.toDecimal(tx.nonce); 3782 tx.gas = utils.toDecimal(tx.gas); 3783 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3784 tx.value = utils.toBigNumber(tx.value); 3785 return tx; 3786 }; 3787 3788 /** 3789 * Formats the output of a transaction receipt to its proper values 3790 * 3791 * @method outputTransactionReceiptFormatter 3792 * @param {Object} receipt 3793 * @returns {Object} 3794 */ 3795 var outputTransactionReceiptFormatter = function (receipt){ 3796 if(receipt.blockNumber !== null) 3797 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3798 if(receipt.transactionIndex !== null) 3799 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3800 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3801 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3802 3803 if(utils.isArray(receipt.logs)) { 3804 receipt.logs = receipt.logs.map(function(log){ 3805 return outputLogFormatter(log); 3806 }); 3807 } 3808 3809 return receipt; 3810 }; 3811 3812 /** 3813 * Formats the output of a block to its proper values 3814 * 3815 * @method outputBlockFormatter 3816 * @param {Object} block 3817 * @returns {Object} 3818 */ 3819 var outputBlockFormatter = function(block) { 3820 3821 // transform to number 3822 block.gasLimit = utils.toDecimal(block.gasLimit); 3823 block.gasUsed = utils.toDecimal(block.gasUsed); 3824 block.size = utils.toDecimal(block.size); 3825 block.timestamp = utils.toDecimal(block.timestamp); 3826 if(block.number !== null) 3827 block.number = utils.toDecimal(block.number); 3828 3829 block.difficulty = utils.toBigNumber(block.difficulty); 3830 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3831 3832 if (utils.isArray(block.transactions)) { 3833 block.transactions.forEach(function(item){ 3834 if(!utils.isString(item)) 3835 return outputTransactionFormatter(item); 3836 }); 3837 } 3838 3839 return block; 3840 }; 3841 3842 /** 3843 * Formats the output of a log 3844 * 3845 * @method outputLogFormatter 3846 * @param {Object} log object 3847 * @returns {Object} log 3848 */ 3849 var outputLogFormatter = function(log) { 3850 if(log.blockNumber) 3851 log.blockNumber = utils.toDecimal(log.blockNumber); 3852 if(log.transactionIndex) 3853 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3854 if(log.logIndex) 3855 log.logIndex = utils.toDecimal(log.logIndex); 3856 3857 return log; 3858 }; 3859 3860 /** 3861 * Formats the input of a whisper post and converts all values to HEX 3862 * 3863 * @method inputPostFormatter 3864 * @param {Object} transaction object 3865 * @returns {Object} 3866 */ 3867 var inputPostFormatter = function(post) { 3868 3869 // post.payload = utils.toHex(post.payload); 3870 post.ttl = utils.fromDecimal(post.ttl); 3871 post.workToProve = utils.fromDecimal(post.workToProve); 3872 post.priority = utils.fromDecimal(post.priority); 3873 3874 // fallback 3875 if (!utils.isArray(post.topics)) { 3876 post.topics = post.topics ? [post.topics] : []; 3877 } 3878 3879 // format the following options 3880 post.topics = post.topics.map(function(topic){ 3881 // convert only if not hex 3882 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3883 }); 3884 3885 return post; 3886 }; 3887 3888 /** 3889 * Formats the output of a received post message 3890 * 3891 * @method outputPostFormatter 3892 * @param {Object} 3893 * @returns {Object} 3894 */ 3895 var outputPostFormatter = function(post){ 3896 3897 post.expiry = utils.toDecimal(post.expiry); 3898 post.sent = utils.toDecimal(post.sent); 3899 post.ttl = utils.toDecimal(post.ttl); 3900 post.workProved = utils.toDecimal(post.workProved); 3901 // post.payloadRaw = post.payload; 3902 // post.payload = utils.toAscii(post.payload); 3903 3904 // if (utils.isJson(post.payload)) { 3905 // post.payload = JSON.parse(post.payload); 3906 // } 3907 3908 // format the following options 3909 if (!post.topics) { 3910 post.topics = []; 3911 } 3912 post.topics = post.topics.map(function(topic){ 3913 return utils.toAscii(topic); 3914 }); 3915 3916 return post; 3917 }; 3918 3919 var inputAddressFormatter = function (address) { 3920 var iban = new Iban(address); 3921 if (iban.isValid() && iban.isDirect()) { 3922 return '0x' + iban.address(); 3923 } else if (utils.isStrictAddress(address)) { 3924 return address; 3925 } else if (utils.isAddress(address)) { 3926 return '0x' + address; 3927 } else if (address.substr(0, 3) === 'QCT' && utils.isAddress(address.substr(3, 40))) { 3928 return '0x' + address.substr(3, 40); 3929 } 3930 throw new Error('invalid address'); 3931 }; 3932 3933 3934 var outputSyncingFormatter = function(result) { 3935 if (!result) { 3936 return result; 3937 } 3938 3939 result.startingBlock = utils.toDecimal(result.startingBlock); 3940 result.currentBlock = utils.toDecimal(result.currentBlock); 3941 result.highestBlock = utils.toDecimal(result.highestBlock); 3942 if (result.knownStates) { 3943 result.knownStates = utils.toDecimal(result.knownStates); 3944 result.pulledStates = utils.toDecimal(result.pulledStates); 3945 } 3946 3947 return result; 3948 }; 3949 3950 module.exports = { 3951 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 3952 inputBlockNumberFormatter: inputBlockNumberFormatter, 3953 inputCallFormatter: inputCallFormatter, 3954 inputTransactionFormatter: inputTransactionFormatter, 3955 inputAddressFormatter: inputAddressFormatter, 3956 inputPostFormatter: inputPostFormatter, 3957 outputBigNumberFormatter: outputBigNumberFormatter, 3958 outputTransactionFormatter: outputTransactionFormatter, 3959 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 3960 outputBlockFormatter: outputBlockFormatter, 3961 outputLogFormatter: outputLogFormatter, 3962 outputPostFormatter: outputPostFormatter, 3963 outputSyncingFormatter: outputSyncingFormatter 3964 }; 3965 3966 3967 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 3968 /* 3969 This file is part of web3.js. 3970 3971 web3.js is free software: you can redistribute it and/or modify 3972 it under the terms of the GNU Lesser General Public License as published by 3973 the Free Software Foundation, either version 3 of the License, or 3974 (at your option) any later version. 3975 3976 web3.js is distributed in the hope that it will be useful, 3977 but WITHOUT ANY WARRANTY; without even the implied warranty of 3978 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3979 GNU Lesser General Public License for more details. 3980 3981 You should have received a copy of the GNU Lesser General Public License 3982 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3983 */ 3984 /** 3985 * @file function.js 3986 * @author Marek Kotewicz <marek@ethdev.com> 3987 * @date 2015 3988 */ 3989 3990 var coder = require('../solidity/coder'); 3991 var utils = require('../utils/utils'); 3992 var errors = require('./errors'); 3993 var formatters = require('./formatters'); 3994 var sha3 = require('../utils/sha3'); 3995 3996 /** 3997 * This prototype should be used to call/sendTransaction to solidity functions 3998 */ 3999 var SolidityFunction = function (qct, json, address) { 4000 this._qct = qct; 4001 this._inputTypes = json.inputs.map(function (i) { 4002 return i.type; 4003 }); 4004 this._outputTypes = json.outputs.map(function (i) { 4005 return i.type; 4006 }); 4007 this._constant = json.constant; 4008 this._payable = json.payable; 4009 this._name = utils.transformToFullName(json); 4010 this._address = address; 4011 }; 4012 4013 SolidityFunction.prototype.extractCallback = function (args) { 4014 if (utils.isFunction(args[args.length - 1])) { 4015 return args.pop(); // modify the args array! 4016 } 4017 }; 4018 4019 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4020 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4021 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4022 } 4023 }; 4024 4025 /** 4026 * Should be called to check if the number of arguments is correct 4027 * 4028 * @method validateArgs 4029 * @param {Array} arguments 4030 * @throws {Error} if it is not 4031 */ 4032 SolidityFunction.prototype.validateArgs = function (args) { 4033 var inputArgs = args.filter(function (a) { 4034 // filter the options object but not arguments that are arrays 4035 return !( (utils.isObject(a) === true) && 4036 (utils.isArray(a) === false) && 4037 (utils.isBigNumber(a) === false) 4038 ); 4039 }); 4040 if (inputArgs.length !== this._inputTypes.length) { 4041 throw errors.InvalidNumberOfSolidityArgs(); 4042 } 4043 }; 4044 4045 /** 4046 * Should be used to create payload from arguments 4047 * 4048 * @method toPayload 4049 * @param {Array} solidity function params 4050 * @param {Object} optional payload options 4051 */ 4052 SolidityFunction.prototype.toPayload = function (args) { 4053 var options = {}; 4054 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4055 options = args[args.length - 1]; 4056 } 4057 this.validateArgs(args); 4058 options.to = this._address; 4059 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4060 return options; 4061 }; 4062 4063 /** 4064 * Should be used to get function signature 4065 * 4066 * @method signature 4067 * @return {String} function signature 4068 */ 4069 SolidityFunction.prototype.signature = function () { 4070 return sha3(this._name).slice(0, 8); 4071 }; 4072 4073 4074 SolidityFunction.prototype.unpackOutput = function (output) { 4075 if (!output) { 4076 return; 4077 } 4078 4079 output = output.length >= 2 ? output.slice(2) : output; 4080 var result = coder.decodeParams(this._outputTypes, output); 4081 return result.length === 1 ? result[0] : result; 4082 }; 4083 4084 /** 4085 * Calls a contract function. 4086 * 4087 * @method call 4088 * @param {...Object} Contract function arguments 4089 * @param {function} If the last argument is a function, the contract function 4090 * call will be asynchronous, and the callback will be passed the 4091 * error and result. 4092 * @return {String} output bytes 4093 */ 4094 SolidityFunction.prototype.call = function () { 4095 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4096 var callback = this.extractCallback(args); 4097 var defaultBlock = this.extractDefaultBlock(args); 4098 var payload = this.toPayload(args); 4099 4100 4101 if (!callback) { 4102 var output = this._qct.call(payload, defaultBlock); 4103 return this.unpackOutput(output); 4104 } 4105 4106 var self = this; 4107 this._qct.call(payload, defaultBlock, function (error, output) { 4108 if (error) return callback(error, null); 4109 4110 var unpacked = null; 4111 try { 4112 unpacked = self.unpackOutput(output); 4113 } 4114 catch (e) { 4115 error = e; 4116 } 4117 4118 callback(error, unpacked); 4119 }); 4120 }; 4121 4122 /** 4123 * Should be used to sendTransaction to solidity function 4124 * 4125 * @method sendTransaction 4126 */ 4127 SolidityFunction.prototype.sendTransaction = function () { 4128 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4129 var callback = this.extractCallback(args); 4130 var payload = this.toPayload(args); 4131 4132 if (payload.value > 0 && !this._payable) { 4133 throw new Error('Cannot send value to non-payable function'); 4134 } 4135 4136 if (!callback) { 4137 return this._qct.sendTransaction(payload); 4138 } 4139 4140 this._qct.sendTransaction(payload, callback); 4141 }; 4142 4143 /** 4144 * Should be used to estimateGas of solidity function 4145 * 4146 * @method estimateGas 4147 */ 4148 SolidityFunction.prototype.estimateGas = function () { 4149 var args = Array.prototype.slice.call(arguments); 4150 var callback = this.extractCallback(args); 4151 var payload = this.toPayload(args); 4152 4153 if (!callback) { 4154 return this._qct.estimateGas(payload); 4155 } 4156 4157 this._qct.estimateGas(payload, callback); 4158 }; 4159 4160 /** 4161 * Return the encoded data of the call 4162 * 4163 * @method getData 4164 * @return {String} the encoded data 4165 */ 4166 SolidityFunction.prototype.getData = function () { 4167 var args = Array.prototype.slice.call(arguments); 4168 var payload = this.toPayload(args); 4169 4170 return payload.data; 4171 }; 4172 4173 /** 4174 * Should be used to get function display name 4175 * 4176 * @method displayName 4177 * @return {String} display name of the function 4178 */ 4179 SolidityFunction.prototype.displayName = function () { 4180 return utils.extractDisplayName(this._name); 4181 }; 4182 4183 /** 4184 * Should be used to get function type name 4185 * 4186 * @method typeName 4187 * @return {String} type name of the function 4188 */ 4189 SolidityFunction.prototype.typeName = function () { 4190 return utils.extractTypeName(this._name); 4191 }; 4192 4193 /** 4194 * Should be called to get rpc requests from solidity function 4195 * 4196 * @method request 4197 * @returns {Object} 4198 */ 4199 SolidityFunction.prototype.request = function () { 4200 var args = Array.prototype.slice.call(arguments); 4201 var callback = this.extractCallback(args); 4202 var payload = this.toPayload(args); 4203 var format = this.unpackOutput.bind(this); 4204 4205 return { 4206 method: this._constant ? 'qct_call' : 'qct_sendTransaction', 4207 callback: callback, 4208 params: [payload], 4209 format: format 4210 }; 4211 }; 4212 4213 /** 4214 * Should be called to execute function 4215 * 4216 * @method execute 4217 */ 4218 SolidityFunction.prototype.execute = function () { 4219 var transaction = !this._constant; 4220 4221 // send transaction 4222 if (transaction) { 4223 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4224 } 4225 4226 // call 4227 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4228 }; 4229 4230 /** 4231 * Should be called to attach function to contract 4232 * 4233 * @method attachToContract 4234 * @param {Contract} 4235 */ 4236 SolidityFunction.prototype.attachToContract = function (contract) { 4237 var execute = this.execute.bind(this); 4238 execute.request = this.request.bind(this); 4239 execute.call = this.call.bind(this); 4240 execute.sendTransaction = this.sendTransaction.bind(this); 4241 execute.estimateGas = this.estimateGas.bind(this); 4242 execute.getData = this.getData.bind(this); 4243 var displayName = this.displayName(); 4244 if (!contract[displayName]) { 4245 contract[displayName] = execute; 4246 } 4247 contract[displayName][this.typeName()] = execute; // circular!!!! 4248 }; 4249 4250 module.exports = SolidityFunction; 4251 4252 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4253 /* 4254 This file is part of web3.js. 4255 4256 web3.js is free software: you can redistribute it and/or modify 4257 it under the terms of the GNU Lesser General Public License as published by 4258 the Free Software Foundation, either version 3 of the License, or 4259 (at your option) any later version. 4260 4261 web3.js is distributed in the hope that it will be useful, 4262 but WITHOUT ANY WARRANTY; without even the implied warranty of 4263 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4264 GNU Lesser General Public License for more details. 4265 4266 You should have received a copy of the GNU Lesser General Public License 4267 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4268 */ 4269 /** @file httpprovider.js 4270 * @authors: 4271 * Marek Kotewicz <marek@ethdev.com> 4272 * Marian Oancea <marian@ethdev.com> 4273 * Fabian Vogelsteller <fabian@ethdev.com> 4274 * @date 2015 4275 */ 4276 4277 var errors = require('./errors'); 4278 4279 // workaround to use httpprovider in different envs 4280 4281 // browser 4282 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4283 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4284 // node 4285 } else { 4286 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4287 } 4288 4289 var XHR2 = require('xhr2'); // jshint ignore: line 4290 4291 /** 4292 * HttpProvider should be used to send rpc calls over http 4293 */ 4294 var HttpProvider = function (host, timeout, user, password) { 4295 this.host = host || 'http://localhost:8545'; 4296 this.timeout = timeout || 0; 4297 this.user = user; 4298 this.password = password; 4299 }; 4300 4301 /** 4302 * Should be called to prepare new XMLHttpRequest 4303 * 4304 * @method prepareRequest 4305 * @param {Boolean} true if request should be async 4306 * @return {XMLHttpRequest} object 4307 */ 4308 HttpProvider.prototype.prepareRequest = function (async) { 4309 var request; 4310 4311 if (async) { 4312 request = new XHR2(); 4313 request.timeout = this.timeout; 4314 } else { 4315 request = new XMLHttpRequest(); 4316 } 4317 4318 request.open('POST', this.host, async); 4319 if (this.user && this.password) { 4320 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4321 request.setRequestHeader('Authorization', auth); 4322 } request.setRequestHeader('Content-Type', 'application/json'); 4323 return request; 4324 }; 4325 4326 /** 4327 * Should be called to make sync request 4328 * 4329 * @method send 4330 * @param {Object} payload 4331 * @return {Object} result 4332 */ 4333 HttpProvider.prototype.send = function (payload) { 4334 var request = this.prepareRequest(false); 4335 4336 try { 4337 request.send(JSON.stringify(payload)); 4338 } catch (error) { 4339 throw errors.InvalidConnection(this.host); 4340 } 4341 4342 var result = request.responseText; 4343 4344 try { 4345 result = JSON.parse(result); 4346 } catch (e) { 4347 throw errors.InvalidResponse(request.responseText); 4348 } 4349 4350 return result; 4351 }; 4352 4353 /** 4354 * Should be used to make async request 4355 * 4356 * @method sendAsync 4357 * @param {Object} payload 4358 * @param {Function} callback triggered on end with (err, result) 4359 */ 4360 HttpProvider.prototype.sendAsync = function (payload, callback) { 4361 var request = this.prepareRequest(true); 4362 4363 request.onreadystatechange = function () { 4364 if (request.readyState === 4 && request.timeout !== 1) { 4365 var result = request.responseText; 4366 var error = null; 4367 4368 try { 4369 result = JSON.parse(result); 4370 } catch (e) { 4371 error = errors.InvalidResponse(request.responseText); 4372 } 4373 4374 callback(error, result); 4375 } 4376 }; 4377 4378 request.ontimeout = function () { 4379 callback(errors.ConnectionTimeout(this.timeout)); 4380 }; 4381 4382 try { 4383 request.send(JSON.stringify(payload)); 4384 } catch (error) { 4385 callback(errors.InvalidConnection(this.host)); 4386 } 4387 }; 4388 4389 /** 4390 * Synchronously tries to make Http request 4391 * 4392 * @method isConnected 4393 * @return {Boolean} returns true if request haven't failed. Otherwise false 4394 */ 4395 HttpProvider.prototype.isConnected = function () { 4396 try { 4397 this.send({ 4398 id: 9999999999, 4399 jsonrpc: '2.0', 4400 method: 'net_listening', 4401 params: [] 4402 }); 4403 return true; 4404 } catch (e) { 4405 return false; 4406 } 4407 }; 4408 4409 module.exports = HttpProvider; 4410 4411 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4412 /* 4413 This file is part of web3.js. 4414 4415 web3.js is free software: you can redistribute it and/or modify 4416 it under the terms of the GNU Lesser General Public License as published by 4417 the Free Software Foundation, either version 3 of the License, or 4418 (at your option) any later version. 4419 4420 web3.js is distributed in the hope that it will be useful, 4421 but WITHOUT ANY WARRANTY; without even the implied warranty of 4422 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4423 GNU Lesser General Public License for more details. 4424 4425 You should have received a copy of the GNU Lesser General Public License 4426 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4427 */ 4428 /** 4429 * @file iban.js 4430 * @author Marek Kotewicz <marek@ethdev.com> 4431 * @date 2015 4432 */ 4433 4434 var BigNumber = require('bignumber.js'); 4435 4436 var padLeft = function (string, bytes) { 4437 var result = string; 4438 while (result.length < bytes * 2) { 4439 result = '0' + result; 4440 } 4441 return result; 4442 }; 4443 4444 /** 4445 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4446 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4447 * 4448 * @method iso13616Prepare 4449 * @param {String} iban the IBAN 4450 * @returns {String} the prepared IBAN 4451 */ 4452 var iso13616Prepare = function (iban) { 4453 var A = 'A'.charCodeAt(0); 4454 var Z = 'Z'.charCodeAt(0); 4455 4456 iban = iban.toUpperCase(); 4457 iban = iban.substr(4) + iban.substr(0,4); 4458 4459 return iban.split('').map(function(n){ 4460 var code = n.charCodeAt(0); 4461 if (code >= A && code <= Z){ 4462 // A = 10, B = 11, ... Z = 35 4463 return code - A + 10; 4464 } else { 4465 return n; 4466 } 4467 }).join(''); 4468 }; 4469 4470 /** 4471 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4472 * 4473 * @method mod9710 4474 * @param {String} iban 4475 * @returns {Number} 4476 */ 4477 var mod9710 = function (iban) { 4478 var remainder = iban, 4479 block; 4480 4481 while (remainder.length > 2){ 4482 block = remainder.slice(0, 9); 4483 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4484 } 4485 4486 return parseInt(remainder, 10) % 97; 4487 }; 4488 4489 /** 4490 * This prototype should be used to create iban object from iban correct string 4491 * 4492 * @param {String} iban 4493 */ 4494 var Iban = function (iban) { 4495 this._iban = iban; 4496 }; 4497 4498 /** 4499 * This method should be used to create iban object from quickchain address 4500 * 4501 * @method fromAddress 4502 * @param {String} address 4503 * @return {Iban} the IBAN object 4504 */ 4505 Iban.fromAddress = function (address) { 4506 var asBn = new BigNumber(address, 16); 4507 var base36 = asBn.toString(36); 4508 var padded = padLeft(base36, 15); 4509 return Iban.fromBban(padded.toUpperCase()); 4510 }; 4511 4512 /** 4513 * Convert the passed BBAN to an IBAN for this country specification. 4514 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4515 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4516 * 4517 * @method fromBban 4518 * @param {String} bban the BBAN to convert to IBAN 4519 * @returns {Iban} the IBAN object 4520 */ 4521 Iban.fromBban = function (bban) { 4522 var countryCode = 'XE'; 4523 4524 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4525 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4526 4527 return new Iban(countryCode + checkDigit + bban); 4528 }; 4529 4530 /** 4531 * Should be used to create IBAN object for given institution and identifier 4532 * 4533 * @method createIndirect 4534 * @param {Object} options, required options are "institution" and "identifier" 4535 * @return {Iban} the IBAN object 4536 */ 4537 Iban.createIndirect = function (options) { 4538 return Iban.fromBban('QCT' + options.institution + options.identifier); 4539 }; 4540 4541 /** 4542 * Thos method should be used to check if given string is valid iban object 4543 * 4544 * @method isValid 4545 * @param {String} iban string 4546 * @return {Boolean} true if it is valid IBAN 4547 */ 4548 Iban.isValid = function (iban) { 4549 var i = new Iban(iban); 4550 return i.isValid(); 4551 }; 4552 4553 /** 4554 * Should be called to check if iban is correct 4555 * 4556 * @method isValid 4557 * @returns {Boolean} true if it is, otherwise false 4558 */ 4559 Iban.prototype.isValid = function () { 4560 return /^XE[0-9]{2}(QCT[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4561 mod9710(iso13616Prepare(this._iban)) === 1; 4562 }; 4563 4564 /** 4565 * Should be called to check if iban number is direct 4566 * 4567 * @method isDirect 4568 * @returns {Boolean} true if it is, otherwise false 4569 */ 4570 Iban.prototype.isDirect = function () { 4571 return this._iban.length === 34 || this._iban.length === 35; 4572 }; 4573 4574 /** 4575 * Should be called to check if iban number if indirect 4576 * 4577 * @method isIndirect 4578 * @returns {Boolean} true if it is, otherwise false 4579 */ 4580 Iban.prototype.isIndirect = function () { 4581 return this._iban.length === 20; 4582 }; 4583 4584 /** 4585 * Should be called to get iban checksum 4586 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4587 * 4588 * @method checksum 4589 * @returns {String} checksum 4590 */ 4591 Iban.prototype.checksum = function () { 4592 return this._iban.substr(2, 2); 4593 }; 4594 4595 /** 4596 * Should be called to get institution identifier 4597 * eg. XREG 4598 * 4599 * @method institution 4600 * @returns {String} institution identifier 4601 */ 4602 Iban.prototype.institution = function () { 4603 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4604 }; 4605 4606 /** 4607 * Should be called to get client identifier within institution 4608 * eg. GAVOFYORK 4609 * 4610 * @method client 4611 * @returns {String} client identifier 4612 */ 4613 Iban.prototype.client = function () { 4614 return this.isIndirect() ? this._iban.substr(11) : ''; 4615 }; 4616 4617 /** 4618 * Should be called to get client direct address 4619 * 4620 * @method address 4621 * @returns {String} client direct address 4622 */ 4623 Iban.prototype.address = function () { 4624 if (this.isDirect()) { 4625 var base36 = this._iban.substr(4); 4626 var asBn = new BigNumber(base36, 36); 4627 return padLeft(asBn.toString(16), 20); 4628 } 4629 4630 return ''; 4631 }; 4632 4633 Iban.prototype.toString = function () { 4634 return this._iban; 4635 }; 4636 4637 module.exports = Iban; 4638 4639 4640 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4641 /* 4642 This file is part of web3.js. 4643 4644 web3.js is free software: you can redistribute it and/or modify 4645 it under the terms of the GNU Lesser General Public License as published by 4646 the Free Software Foundation, either version 3 of the License, or 4647 (at your option) any later version. 4648 4649 web3.js is distributed in the hope that it will be useful, 4650 but WITHOUT ANY WARRANTY; without even the implied warranty of 4651 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4652 GNU Lesser General Public License for more details. 4653 4654 You should have received a copy of the GNU Lesser General Public License 4655 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4656 */ 4657 /** @file ipcprovider.js 4658 * @authors: 4659 * Fabian Vogelsteller <fabian@ethdev.com> 4660 * @date 2015 4661 */ 4662 4663 "use strict"; 4664 4665 var utils = require('../utils/utils'); 4666 var errors = require('./errors'); 4667 4668 4669 var IpcProvider = function (path, net) { 4670 var _this = this; 4671 this.responseCallbacks = {}; 4672 this.path = path; 4673 4674 this.connection = net.connect({path: this.path}); 4675 4676 this.connection.on('error', function(e){ 4677 console.error('IPC Connection Error', e); 4678 _this._timeout(); 4679 }); 4680 4681 this.connection.on('end', function(){ 4682 _this._timeout(); 4683 }); 4684 4685 4686 // LISTEN FOR CONNECTION RESPONSES 4687 this.connection.on('data', function(data) { 4688 /*jshint maxcomplexity: 6 */ 4689 4690 _this._parseResponse(data.toString()).forEach(function(result){ 4691 4692 var id = null; 4693 4694 // get the id which matches the returned id 4695 if(utils.isArray(result)) { 4696 result.forEach(function(load){ 4697 if(_this.responseCallbacks[load.id]) 4698 id = load.id; 4699 }); 4700 } else { 4701 id = result.id; 4702 } 4703 4704 // fire the callback 4705 if(_this.responseCallbacks[id]) { 4706 _this.responseCallbacks[id](null, result); 4707 delete _this.responseCallbacks[id]; 4708 } 4709 }); 4710 }); 4711 }; 4712 4713 /** 4714 Will parse the response and make an array out of it. 4715 4716 @method _parseResponse 4717 @param {String} data 4718 */ 4719 IpcProvider.prototype._parseResponse = function(data) { 4720 var _this = this, 4721 returnValues = []; 4722 4723 // DE-CHUNKER 4724 var dechunkedData = data 4725 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4726 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4727 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4728 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4729 .split('|--|'); 4730 4731 dechunkedData.forEach(function(data){ 4732 4733 // prepend the last chunk 4734 if(_this.lastChunk) 4735 data = _this.lastChunk + data; 4736 4737 var result = null; 4738 4739 try { 4740 result = JSON.parse(data); 4741 4742 } catch(e) { 4743 4744 _this.lastChunk = data; 4745 4746 // start timeout to cancel all requests 4747 clearTimeout(_this.lastChunkTimeout); 4748 _this.lastChunkTimeout = setTimeout(function(){ 4749 _this._timeout(); 4750 throw errors.InvalidResponse(data); 4751 }, 1000 * 15); 4752 4753 return; 4754 } 4755 4756 // cancel timeout and set chunk to null 4757 clearTimeout(_this.lastChunkTimeout); 4758 _this.lastChunk = null; 4759 4760 if(result) 4761 returnValues.push(result); 4762 }); 4763 4764 return returnValues; 4765 }; 4766 4767 4768 /** 4769 Get the adds a callback to the responseCallbacks object, 4770 which will be called if a response matching the response Id will arrive. 4771 4772 @method _addResponseCallback 4773 */ 4774 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4775 var id = payload.id || payload[0].id; 4776 var method = payload.method || payload[0].method; 4777 4778 this.responseCallbacks[id] = callback; 4779 this.responseCallbacks[id].method = method; 4780 }; 4781 4782 /** 4783 Timeout all requests when the end/error event is fired 4784 4785 @method _timeout 4786 */ 4787 IpcProvider.prototype._timeout = function() { 4788 for(var key in this.responseCallbacks) { 4789 if(this.responseCallbacks.hasOwnProperty(key)){ 4790 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4791 delete this.responseCallbacks[key]; 4792 } 4793 } 4794 }; 4795 4796 4797 /** 4798 Check if the current connection is still valid. 4799 4800 @method isConnected 4801 */ 4802 IpcProvider.prototype.isConnected = function() { 4803 var _this = this; 4804 4805 // try reconnect, when connection is gone 4806 if(!_this.connection.writable) 4807 _this.connection.connect({path: _this.path}); 4808 4809 return !!this.connection.writable; 4810 }; 4811 4812 IpcProvider.prototype.send = function (payload) { 4813 4814 if(this.connection.writeSync) { 4815 var result; 4816 4817 // try reconnect, when connection is gone 4818 if(!this.connection.writable) 4819 this.connection.connect({path: this.path}); 4820 4821 var data = this.connection.writeSync(JSON.stringify(payload)); 4822 4823 try { 4824 result = JSON.parse(data); 4825 } catch(e) { 4826 throw errors.InvalidResponse(data); 4827 } 4828 4829 return result; 4830 4831 } else { 4832 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4833 } 4834 }; 4835 4836 IpcProvider.prototype.sendAsync = function (payload, callback) { 4837 // try reconnect, when connection is gone 4838 if(!this.connection.writable) 4839 this.connection.connect({path: this.path}); 4840 4841 4842 this.connection.write(JSON.stringify(payload)); 4843 this._addResponseCallback(payload, callback); 4844 }; 4845 4846 module.exports = IpcProvider; 4847 4848 4849 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 4850 /* 4851 This file is part of web3.js. 4852 4853 web3.js is free software: you can redistribute it and/or modify 4854 it under the terms of the GNU Lesser General Public License as published by 4855 the Free Software Foundation, either version 3 of the License, or 4856 (at your option) any later version. 4857 4858 web3.js is distributed in the hope that it will be useful, 4859 but WITHOUT ANY WARRANTY; without even the implied warranty of 4860 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4861 GNU Lesser General Public License for more details. 4862 4863 You should have received a copy of the GNU Lesser General Public License 4864 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4865 */ 4866 /** @file jsonrpc.js 4867 * @authors: 4868 * Marek Kotewicz <marek@ethdev.com> 4869 * Aaron Kumavis <aaron@kumavis.me> 4870 * @date 2015 4871 */ 4872 4873 // Initialize Jsonrpc as a simple object with utility functions. 4874 var Jsonrpc = { 4875 messageId: 0 4876 }; 4877 4878 /** 4879 * Should be called to valid json create payload object 4880 * 4881 * @method toPayload 4882 * @param {Function} method of jsonrpc call, required 4883 * @param {Array} params, an array of method params, optional 4884 * @returns {Object} valid jsonrpc payload object 4885 */ 4886 Jsonrpc.toPayload = function (method, params) { 4887 if (!method) 4888 console.error('jsonrpc method should be specified!'); 4889 4890 // advance message ID 4891 Jsonrpc.messageId++; 4892 4893 return { 4894 jsonrpc: '2.0', 4895 id: Jsonrpc.messageId, 4896 method: method, 4897 params: params || [] 4898 }; 4899 }; 4900 4901 /** 4902 * Should be called to check if jsonrpc response is valid 4903 * 4904 * @method isValidResponse 4905 * @param {Object} 4906 * @returns {Boolean} true if response is valid, otherwise false 4907 */ 4908 Jsonrpc.isValidResponse = function (response) { 4909 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4910 4911 function validateSingleMessage(message){ 4912 return !!message && 4913 !message.error && 4914 message.jsonrpc === '2.0' && 4915 typeof message.id === 'number' && 4916 message.result !== undefined; // only undefined is not valid json object 4917 } 4918 }; 4919 4920 /** 4921 * Should be called to create batch payload object 4922 * 4923 * @method toBatchPayload 4924 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4925 * @returns {Array} batch payload 4926 */ 4927 Jsonrpc.toBatchPayload = function (messages) { 4928 return messages.map(function (message) { 4929 return Jsonrpc.toPayload(message.method, message.params); 4930 }); 4931 }; 4932 4933 module.exports = Jsonrpc; 4934 4935 4936 },{}],36:[function(require,module,exports){ 4937 /* 4938 This file is part of web3.js. 4939 4940 web3.js is free software: you can redistribute it and/or modify 4941 it under the terms of the GNU Lesser General Public License as published by 4942 the Free Software Foundation, either version 3 of the License, or 4943 (at your option) any later version. 4944 4945 web3.js is distributed in the hope that it will be useful, 4946 but WITHOUT ANY WARRANTY; without even the implied warranty of 4947 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4948 GNU Lesser General Public License for more details. 4949 4950 You should have received a copy of the GNU Lesser General Public License 4951 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4952 */ 4953 /** 4954 * @file method.js 4955 * @author Marek Kotewicz <marek@ethdev.com> 4956 * @date 2015 4957 */ 4958 4959 var utils = require('../utils/utils'); 4960 var errors = require('./errors'); 4961 4962 var Method = function (options) { 4963 this.name = options.name; 4964 this.call = options.call; 4965 this.params = options.params || 0; 4966 this.inputFormatter = options.inputFormatter; 4967 this.outputFormatter = options.outputFormatter; 4968 this.requestManager = null; 4969 }; 4970 4971 Method.prototype.setRequestManager = function (rm) { 4972 this.requestManager = rm; 4973 }; 4974 4975 /** 4976 * Should be used to determine name of the jsonrpc method based on arguments 4977 * 4978 * @method getCall 4979 * @param {Array} arguments 4980 * @return {String} name of jsonrpc method 4981 */ 4982 Method.prototype.getCall = function (args) { 4983 return utils.isFunction(this.call) ? this.call(args) : this.call; 4984 }; 4985 4986 /** 4987 * Should be used to extract callback from array of arguments. Modifies input param 4988 * 4989 * @method extractCallback 4990 * @param {Array} arguments 4991 * @return {Function|Null} callback, if exists 4992 */ 4993 Method.prototype.extractCallback = function (args) { 4994 if (utils.isFunction(args[args.length - 1])) { 4995 return args.pop(); // modify the args array! 4996 } 4997 }; 4998 4999 /** 5000 * Should be called to check if the number of arguments is correct 5001 * 5002 * @method validateArgs 5003 * @param {Array} arguments 5004 * @throws {Error} if it is not 5005 */ 5006 Method.prototype.validateArgs = function (args) { 5007 if (args.length !== this.params) { 5008 throw errors.InvalidNumberOfRPCParams(); 5009 } 5010 }; 5011 5012 /** 5013 * Should be called to format input args of method 5014 * 5015 * @method formatInput 5016 * @param {Array} 5017 * @return {Array} 5018 */ 5019 Method.prototype.formatInput = function (args) { 5020 if (!this.inputFormatter) { 5021 return args; 5022 } 5023 5024 return this.inputFormatter.map(function (formatter, index) { 5025 return formatter ? formatter(args[index]) : args[index]; 5026 }); 5027 }; 5028 5029 /** 5030 * Should be called to format output(result) of method 5031 * 5032 * @method formatOutput 5033 * @param {Object} 5034 * @return {Object} 5035 */ 5036 Method.prototype.formatOutput = function (result) { 5037 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5038 }; 5039 5040 /** 5041 * Should create payload from given input args 5042 * 5043 * @method toPayload 5044 * @param {Array} args 5045 * @return {Object} 5046 */ 5047 Method.prototype.toPayload = function (args) { 5048 var call = this.getCall(args); 5049 var callback = this.extractCallback(args); 5050 var params = this.formatInput(args); 5051 this.validateArgs(params); 5052 5053 return { 5054 method: call, 5055 params: params, 5056 callback: callback 5057 }; 5058 }; 5059 5060 Method.prototype.attachToObject = function (obj) { 5061 var func = this.buildCall(); 5062 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5063 var name = this.name.split('.'); 5064 if (name.length > 1) { 5065 obj[name[0]] = obj[name[0]] || {}; 5066 obj[name[0]][name[1]] = func; 5067 } else { 5068 obj[name[0]] = func; 5069 } 5070 }; 5071 5072 Method.prototype.buildCall = function() { 5073 var method = this; 5074 var send = function () { 5075 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5076 if (payload.callback) { 5077 return method.requestManager.sendAsync(payload, function (err, result) { 5078 payload.callback(err, method.formatOutput(result)); 5079 }); 5080 } 5081 return method.formatOutput(method.requestManager.send(payload)); 5082 }; 5083 send.request = this.request.bind(this); 5084 return send; 5085 }; 5086 5087 /** 5088 * Should be called to create pure JSONRPC request which can be used in batch request 5089 * 5090 * @method request 5091 * @param {...} params 5092 * @return {Object} jsonrpc request 5093 */ 5094 Method.prototype.request = function () { 5095 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5096 payload.format = this.formatOutput.bind(this); 5097 return payload; 5098 }; 5099 5100 module.exports = Method; 5101 5102 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5103 /* 5104 This file is part of web3.js. 5105 5106 web3.js is free software: you can redistribute it and/or modify 5107 it under the terms of the GNU Lesser General Public License as published by 5108 the Free Software Foundation, either version 3 of the License, or 5109 (at your option) any later version. 5110 5111 web3.js is distributed in the hope that it will be useful, 5112 but WITHOUT ANY WARRANTY; without even the implied warranty of 5113 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5114 GNU Lesser General Public License for more details. 5115 5116 You should have received a copy of the GNU Lesser General Public License 5117 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5118 */ 5119 /** @file db.js 5120 * @authors: 5121 * Marek Kotewicz <marek@ethdev.com> 5122 * @date 2015 5123 */ 5124 5125 var Method = require('../method'); 5126 5127 var DB = function (web3) { 5128 this._requestManager = web3._requestManager; 5129 5130 var self = this; 5131 5132 methods().forEach(function(method) { 5133 method.attachToObject(self); 5134 method.setRequestManager(web3._requestManager); 5135 }); 5136 }; 5137 5138 var methods = function () { 5139 var putString = new Method({ 5140 name: 'putString', 5141 call: 'db_putString', 5142 params: 3 5143 }); 5144 5145 var getString = new Method({ 5146 name: 'getString', 5147 call: 'db_getString', 5148 params: 2 5149 }); 5150 5151 var putHex = new Method({ 5152 name: 'putHex', 5153 call: 'db_putHex', 5154 params: 3 5155 }); 5156 5157 var getHex = new Method({ 5158 name: 'getHex', 5159 call: 'db_getHex', 5160 params: 2 5161 }); 5162 5163 return [ 5164 putString, getString, putHex, getHex 5165 ]; 5166 }; 5167 5168 module.exports = DB; 5169 5170 },{"../method":36}],38:[function(require,module,exports){ 5171 /* 5172 This file is part of web3.js. 5173 5174 web3.js is free software: you can redistribute it and/or modify 5175 it under the terms of the GNU Lesser General Public License as published by 5176 the Free Software Foundation, either version 3 of the License, or 5177 (at your option) any later version. 5178 5179 web3.js is distributed in the hope that it will be useful, 5180 but WITHOUT ANY WARRANTY; without even the implied warranty of 5181 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5182 GNU Lesser General Public License for more details. 5183 5184 You should have received a copy of the GNU Lesser General Public License 5185 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5186 */ 5187 /** 5188 * @file eth.js 5189 * @author Marek Kotewicz <marek@ethdev.com> 5190 * @author Fabian Vogelsteller <fabian@ethdev.com> 5191 * @date 2015 5192 */ 5193 5194 "use strict"; 5195 5196 var formatters = require('../formatters'); 5197 var utils = require('../../utils/utils'); 5198 var Method = require('../method'); 5199 var Property = require('../property'); 5200 var c = require('../../utils/config'); 5201 var Contract = require('../contract'); 5202 var watches = require('./watches'); 5203 var Filter = require('../filter'); 5204 var IsSyncing = require('../syncing'); 5205 var namereg = require('../namereg'); 5206 var Iban = require('../iban'); 5207 var transfer = require('../transfer'); 5208 5209 var blockCall = function (args) { 5210 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "qct_getBlockByHash" : "qct_getBlockByNumber"; 5211 }; 5212 5213 var transactionFromBlockCall = function (args) { 5214 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'qct_getTransactionByBlockHashAndIndex' : 'qct_getTransactionByBlockNumberAndIndex'; 5215 }; 5216 5217 var uncleCall = function (args) { 5218 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'qct_getUncleByBlockHashAndIndex' : 'qct_getUncleByBlockNumberAndIndex'; 5219 }; 5220 5221 var getBlockTransactionCountCall = function (args) { 5222 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'qct_getBlockTransactionCountByHash' : 'qct_getBlockTransactionCountByNumber'; 5223 }; 5224 5225 var uncleCountCall = function (args) { 5226 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'qct_getUncleCountByBlockHash' : 'qct_getUncleCountByBlockNumber'; 5227 }; 5228 5229 function Qct(web3) { 5230 this._requestManager = web3._requestManager; 5231 5232 var self = this; 5233 5234 methods().forEach(function(method) { 5235 method.attachToObject(self); 5236 method.setRequestManager(self._requestManager); 5237 }); 5238 5239 properties().forEach(function(p) { 5240 p.attachToObject(self); 5241 p.setRequestManager(self._requestManager); 5242 }); 5243 5244 5245 this.iban = Iban; 5246 this.sendIBANTransaction = transfer.bind(null, this); 5247 } 5248 5249 Object.defineProperty(Qct.prototype, 'defaultBlock', { 5250 get: function () { 5251 return c.defaultBlock; 5252 }, 5253 set: function (val) { 5254 c.defaultBlock = val; 5255 return val; 5256 } 5257 }); 5258 5259 Object.defineProperty(Qct.prototype, 'defaultAccount', { 5260 get: function () { 5261 return c.defaultAccount; 5262 }, 5263 set: function (val) { 5264 c.defaultAccount = val; 5265 return val; 5266 } 5267 }); 5268 5269 var methods = function () { 5270 var getBalance = new Method({ 5271 name: 'getBalance', 5272 call: 'qct_getBalance', 5273 params: 2, 5274 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5275 outputFormatter: formatters.outputBigNumberFormatter 5276 }); 5277 5278 var getStorageAt = new Method({ 5279 name: 'getStorageAt', 5280 call: 'qct_getStorageAt', 5281 params: 3, 5282 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5283 }); 5284 5285 var getCode = new Method({ 5286 name: 'getCode', 5287 call: 'qct_getCode', 5288 params: 2, 5289 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5290 }); 5291 5292 var getBlock = new Method({ 5293 name: 'getBlock', 5294 call: blockCall, 5295 params: 2, 5296 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5297 outputFormatter: formatters.outputBlockFormatter 5298 }); 5299 5300 var getUncle = new Method({ 5301 name: 'getUncle', 5302 call: uncleCall, 5303 params: 2, 5304 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5305 outputFormatter: formatters.outputBlockFormatter, 5306 5307 }); 5308 5309 var getCompilers = new Method({ 5310 name: 'getCompilers', 5311 call: 'qct_getCompilers', 5312 params: 0 5313 }); 5314 5315 var getBlockTransactionCount = new Method({ 5316 name: 'getBlockTransactionCount', 5317 call: getBlockTransactionCountCall, 5318 params: 1, 5319 inputFormatter: [formatters.inputBlockNumberFormatter], 5320 outputFormatter: utils.toDecimal 5321 }); 5322 5323 var getBlockUncleCount = new Method({ 5324 name: 'getBlockUncleCount', 5325 call: uncleCountCall, 5326 params: 1, 5327 inputFormatter: [formatters.inputBlockNumberFormatter], 5328 outputFormatter: utils.toDecimal 5329 }); 5330 5331 var getTransaction = new Method({ 5332 name: 'getTransaction', 5333 call: 'qct_getTransactionByHash', 5334 params: 1, 5335 outputFormatter: formatters.outputTransactionFormatter 5336 }); 5337 5338 var getTransactionFromBlock = new Method({ 5339 name: 'getTransactionFromBlock', 5340 call: transactionFromBlockCall, 5341 params: 2, 5342 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5343 outputFormatter: formatters.outputTransactionFormatter 5344 }); 5345 5346 var getTransactionReceipt = new Method({ 5347 name: 'getTransactionReceipt', 5348 call: 'qct_getTransactionReceipt', 5349 params: 1, 5350 outputFormatter: formatters.outputTransactionReceiptFormatter 5351 }); 5352 5353 var getTransactionCount = new Method({ 5354 name: 'getTransactionCount', 5355 call: 'qct_getTransactionCount', 5356 params: 2, 5357 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5358 outputFormatter: utils.toDecimal 5359 }); 5360 5361 var sendRawTransaction = new Method({ 5362 name: 'sendRawTransaction', 5363 call: 'qct_sendRawTransaction', 5364 params: 1, 5365 inputFormatter: [null] 5366 }); 5367 5368 var sendTransaction = new Method({ 5369 name: 'sendTransaction', 5370 call: 'qct_sendTransaction', 5371 params: 1, 5372 inputFormatter: [formatters.inputTransactionFormatter] 5373 }); 5374 5375 var loginCandidate = new Method({ 5376 name: 'loginCandidate', 5377 call: 'qct_loginCandidate', 5378 params: 1, 5379 inputFormatter: [formatters.inputAddressFormatter] 5380 }); 5381 5382 var logoutCandidate = new Method({ 5383 name: 'logoutCandidate', 5384 call: 'qct_logoutCandidate', 5385 params: 1, 5386 inputFormatter: [formatters.inputAddressFormatter] 5387 }); 5388 5389 var withdrawCandidate = new Method({ 5390 name: 'withdrawCandidate', 5391 call: 'qct_withdrawCandidate', 5392 params: 1, 5393 inputFormatter: [formatters.inputAddressFormatter] 5394 }); 5395 5396 var delegate = new Method({ 5397 name: 'delegate', 5398 call: 'qct_delegate', 5399 params: 2, 5400 inputFormatter: [formatters.inputAddressFormatter, formatters.inputAddressFormatter] 5401 }); 5402 5403 var undelegate = new Method({ 5404 name: 'undelegate', 5405 call: 'qct_undelegate', 5406 params: 2, 5407 inputFormatter: [formatters.inputAddressFormatter, formatters.inputAddressFormatter] 5408 }); 5409 5410 var signTransaction = new Method({ 5411 name: 'signTransaction', 5412 call: 'qct_signTransaction', 5413 params: 1, 5414 inputFormatter: [formatters.inputTransactionFormatter] 5415 }); 5416 5417 var sign = new Method({ 5418 name: 'sign', 5419 call: 'qct_sign', 5420 params: 2, 5421 inputFormatter: [formatters.inputAddressFormatter, null] 5422 }); 5423 5424 var call = new Method({ 5425 name: 'call', 5426 call: 'qct_call', 5427 params: 2, 5428 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5429 }); 5430 5431 var estimateGas = new Method({ 5432 name: 'estimateGas', 5433 call: 'qct_estimateGas', 5434 params: 1, 5435 inputFormatter: [formatters.inputCallFormatter], 5436 outputFormatter: utils.toDecimal 5437 }); 5438 5439 var compileSolidity = new Method({ 5440 name: 'compile.solidity', 5441 call: 'qct_compileSolidity', 5442 params: 1 5443 }); 5444 5445 var compileLLL = new Method({ 5446 name: 'compile.lll', 5447 call: 'qct_compileLLL', 5448 params: 1 5449 }); 5450 5451 var compileSerpent = new Method({ 5452 name: 'compile.serpent', 5453 call: 'qct_compileSerpent', 5454 params: 1 5455 }); 5456 5457 var submitWork = new Method({ 5458 name: 'submitWork', 5459 call: 'qct_submitWork', 5460 params: 3 5461 }); 5462 5463 var getWork = new Method({ 5464 name: 'getWork', 5465 call: 'qct_getWork', 5466 params: 0 5467 }); 5468 5469 return [ 5470 getBalance, 5471 getStorageAt, 5472 getCode, 5473 getBlock, 5474 getUncle, 5475 getCompilers, 5476 getBlockTransactionCount, 5477 getBlockUncleCount, 5478 getTransaction, 5479 getTransactionFromBlock, 5480 getTransactionReceipt, 5481 getTransactionCount, 5482 call, 5483 estimateGas, 5484 sendRawTransaction, 5485 signTransaction, 5486 sendTransaction, 5487 loginCandidate, 5488 logoutCandidate, 5489 withdrawCandidate, 5490 delegate, 5491 undelegate, 5492 sign, 5493 compileSolidity, 5494 compileLLL, 5495 compileSerpent, 5496 submitWork, 5497 getWork 5498 ]; 5499 }; 5500 5501 5502 var properties = function () { 5503 return [ 5504 new Property({ 5505 name: 'coinbase', 5506 getter: 'qct_coinbase' 5507 }), 5508 new Property({ 5509 name: 'mining', 5510 getter: 'qct_mining' 5511 }), 5512 new Property({ 5513 name: 'hashrate', 5514 getter: 'qct_hashrate', 5515 outputFormatter: utils.toDecimal 5516 }), 5517 new Property({ 5518 name: 'syncing', 5519 getter: 'qct_syncing', 5520 outputFormatter: formatters.outputSyncingFormatter 5521 }), 5522 new Property({ 5523 name: 'gasPrice', 5524 getter: 'qct_gasPrice', 5525 outputFormatter: formatters.outputBigNumberFormatter 5526 }), 5527 new Property({ 5528 name: 'accounts', 5529 getter: 'qct_accounts' 5530 }), 5531 new Property({ 5532 name: 'blockNumber', 5533 getter: 'qct_blockNumber', 5534 outputFormatter: utils.toDecimal 5535 }), 5536 new Property({ 5537 name: 'protocolVersion', 5538 getter: 'qct_protocolVersion' 5539 }) 5540 ]; 5541 }; 5542 5543 Qct.prototype.contract = function (abi) { 5544 var factory = new Contract(this, abi); 5545 return factory; 5546 }; 5547 5548 Qct.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5549 return new Filter(options, 'qct', this._requestManager, watches.qct(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5550 }; 5551 5552 Qct.prototype.namereg = function () { 5553 return this.contract(namereg.global.abi).at(namereg.global.address); 5554 }; 5555 5556 Qct.prototype.icapNamereg = function () { 5557 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5558 }; 5559 5560 Qct.prototype.isSyncing = function (callback) { 5561 return new IsSyncing(this._requestManager, callback); 5562 }; 5563 5564 module.exports = Qct; 5565 5566 },{"../../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){ 5567 /* 5568 This file is part of web3.js. 5569 5570 web3.js is free software: you can redistribute it and/or modify 5571 it under the terms of the GNU Lesser General Public License as published by 5572 the Free Software Foundation, either version 3 of the License, or 5573 (at your option) any later version. 5574 5575 web3.js is distributed in the hope that it will be useful, 5576 but WITHOUT ANY WARRANTY; without even the implied warranty of 5577 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5578 GNU Lesser General Public License for more details. 5579 5580 You should have received a copy of the GNU Lesser General Public License 5581 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5582 */ 5583 /** @file eth.js 5584 * @authors: 5585 * Marek Kotewicz <marek@ethdev.com> 5586 * @date 2015 5587 */ 5588 5589 var utils = require('../../utils/utils'); 5590 var Property = require('../property'); 5591 5592 var Net = function (web3) { 5593 this._requestManager = web3._requestManager; 5594 5595 var self = this; 5596 5597 properties().forEach(function(p) { 5598 p.attachToObject(self); 5599 p.setRequestManager(web3._requestManager); 5600 }); 5601 }; 5602 5603 /// @returns an array of objects describing web3.eth api properties 5604 var properties = function () { 5605 return [ 5606 new Property({ 5607 name: 'listening', 5608 getter: 'net_listening' 5609 }), 5610 new Property({ 5611 name: 'peerCount', 5612 getter: 'net_peerCount', 5613 outputFormatter: utils.toDecimal 5614 }) 5615 ]; 5616 }; 5617 5618 module.exports = Net; 5619 5620 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 5621 /* 5622 This file is part of web3.js. 5623 5624 web3.js is free software: you can redistribute it and/or modify 5625 it under the terms of the GNU Lesser General Public License as published by 5626 the Free Software Foundation, either version 3 of the License, or 5627 (at your option) any later version. 5628 5629 web3.js is distributed in the hope that it will be useful, 5630 but WITHOUT ANY WARRANTY; without even the implied warranty of 5631 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5632 GNU Lesser General Public License for more details. 5633 5634 You should have received a copy of the GNU Lesser General Public License 5635 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5636 */ 5637 /** 5638 * @file eth.js 5639 * @author Marek Kotewicz <marek@ethdev.com> 5640 * @author Fabian Vogelsteller <fabian@ethdev.com> 5641 * @date 2015 5642 */ 5643 5644 "use strict"; 5645 5646 var Method = require('../method'); 5647 var Property = require('../property'); 5648 var formatters = require('../formatters'); 5649 5650 function Personal(web3) { 5651 this._requestManager = web3._requestManager; 5652 5653 var self = this; 5654 5655 methods().forEach(function(method) { 5656 method.attachToObject(self); 5657 method.setRequestManager(self._requestManager); 5658 }); 5659 5660 properties().forEach(function(p) { 5661 p.attachToObject(self); 5662 p.setRequestManager(self._requestManager); 5663 }); 5664 } 5665 5666 var methods = function () { 5667 var newAccount = new Method({ 5668 name: 'newAccount', 5669 call: 'personal_newAccount', 5670 params: 1, 5671 inputFormatter: [null] 5672 }); 5673 5674 var importRawKey = new Method({ 5675 name: 'importRawKey', 5676 call: 'personal_importRawKey', 5677 params: 2 5678 }); 5679 5680 var sign = new Method({ 5681 name: 'sign', 5682 call: 'personal_sign', 5683 params: 3, 5684 inputFormatter: [null, formatters.inputAddressFormatter, null] 5685 }); 5686 5687 var ecRecover = new Method({ 5688 name: 'ecRecover', 5689 call: 'personal_ecRecover', 5690 params: 2 5691 }); 5692 5693 var unlockAccount = new Method({ 5694 name: 'unlockAccount', 5695 call: 'personal_unlockAccount', 5696 params: 3, 5697 inputFormatter: [formatters.inputAddressFormatter, null, null] 5698 }); 5699 5700 var sendTransaction = new Method({ 5701 name: 'sendTransaction', 5702 call: 'personal_sendTransaction', 5703 params: 2, 5704 inputFormatter: [formatters.inputTransactionFormatter, null] 5705 }); 5706 5707 var lockAccount = new Method({ 5708 name: 'lockAccount', 5709 call: 'personal_lockAccount', 5710 params: 1, 5711 inputFormatter: [formatters.inputAddressFormatter] 5712 }); 5713 5714 return [ 5715 newAccount, 5716 importRawKey, 5717 unlockAccount, 5718 ecRecover, 5719 sign, 5720 sendTransaction, 5721 lockAccount 5722 ]; 5723 }; 5724 5725 var properties = function () { 5726 return [ 5727 new Property({ 5728 name: 'listAccounts', 5729 getter: 'personal_listAccounts' 5730 }) 5731 ]; 5732 }; 5733 5734 5735 module.exports = Personal; 5736 5737 },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){ 5738 /* 5739 This file is part of web3.js. 5740 5741 web3.js is free software: you can redistribute it and/or modify 5742 it under the terms of the GNU Lesser General Public License as published by 5743 the Free Software Foundation, either version 3 of the License, or 5744 (at your option) any later version. 5745 5746 web3.js is distributed in the hope that it will be useful, 5747 but WITHOUT ANY WARRANTY; without even the implied warranty of 5748 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5749 GNU Lesser General Public License for more details. 5750 5751 You should have received a copy of the GNU Lesser General Public License 5752 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5753 */ 5754 /** @file shh.js 5755 * @authors: 5756 * Fabian Vogelsteller <fabian@quickchain.org> 5757 * Marek Kotewicz <marek@ethcore.io> 5758 * @date 2017 5759 */ 5760 5761 var Method = require('../method'); 5762 var Filter = require('../filter'); 5763 var watches = require('./watches'); 5764 5765 var Shh = function (web3) { 5766 this._requestManager = web3._requestManager; 5767 5768 var self = this; 5769 5770 methods().forEach(function(method) { 5771 method.attachToObject(self); 5772 method.setRequestManager(self._requestManager); 5773 }); 5774 }; 5775 5776 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 5777 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 5778 }; 5779 5780 var methods = function () { 5781 5782 return [ 5783 new Method({ 5784 name: 'version', 5785 call: 'shh_version', 5786 params: 0 5787 }), 5788 new Method({ 5789 name: 'info', 5790 call: 'shh_info', 5791 params: 0 5792 }), 5793 new Method({ 5794 name: 'setMaxMessageSize', 5795 call: 'shh_setMaxMessageSize', 5796 params: 1 5797 }), 5798 new Method({ 5799 name: 'setMinPoW', 5800 call: 'shh_setMinPoW', 5801 params: 1 5802 }), 5803 new Method({ 5804 name: 'markTrustedPeer', 5805 call: 'shh_markTrustedPeer', 5806 params: 1 5807 }), 5808 new Method({ 5809 name: 'newKeyPair', 5810 call: 'shh_newKeyPair', 5811 params: 0 5812 }), 5813 new Method({ 5814 name: 'addPrivateKey', 5815 call: 'shh_addPrivateKey', 5816 params: 1 5817 }), 5818 new Method({ 5819 name: 'deleteKeyPair', 5820 call: 'shh_deleteKeyPair', 5821 params: 1 5822 }), 5823 new Method({ 5824 name: 'hasKeyPair', 5825 call: 'shh_hasKeyPair', 5826 params: 1 5827 }), 5828 new Method({ 5829 name: 'getPublicKey', 5830 call: 'shh_getPublicKey', 5831 params: 1 5832 }), 5833 new Method({ 5834 name: 'getPrivateKey', 5835 call: 'shh_getPrivateKey', 5836 params: 1 5837 }), 5838 new Method({ 5839 name: 'newSymKey', 5840 call: 'shh_newSymKey', 5841 params: 0 5842 }), 5843 new Method({ 5844 name: 'addSymKey', 5845 call: 'shh_addSymKey', 5846 params: 1 5847 }), 5848 new Method({ 5849 name: 'generateSymKeyFromPassword', 5850 call: 'shh_generateSymKeyFromPassword', 5851 params: 1 5852 }), 5853 new Method({ 5854 name: 'hasSymKey', 5855 call: 'shh_hasSymKey', 5856 params: 1 5857 }), 5858 new Method({ 5859 name: 'getSymKey', 5860 call: 'shh_getSymKey', 5861 params: 1 5862 }), 5863 new Method({ 5864 name: 'deleteSymKey', 5865 call: 'shh_deleteSymKey', 5866 params: 1 5867 }), 5868 5869 // subscribe and unsubscribe missing 5870 5871 new Method({ 5872 name: 'post', 5873 call: 'shh_post', 5874 params: 1, 5875 inputFormatter: [null] 5876 }) 5877 ]; 5878 }; 5879 5880 module.exports = Shh; 5881 5882 5883 },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){ 5884 /* 5885 This file is part of web3.js. 5886 5887 web3.js is free software: you can redistribute it and/or modify 5888 it under the terms of the GNU Lesser General Public License as published by 5889 the Free Software Foundation, either version 3 of the License, or 5890 (at your option) any later version. 5891 5892 web3.js is distributed in the hope that it will be useful, 5893 but WITHOUT ANY WARRANTY; without even the implied warranty of 5894 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5895 GNU Lesser General Public License for more details. 5896 5897 You should have received a copy of the GNU Lesser General Public License 5898 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5899 */ 5900 /** 5901 * @file bzz.js 5902 * @author Alex Beregszaszi <alex@rtfs.hu> 5903 * @date 2016 5904 * 5905 * Reference: https://github.com/quickchainproject/quickchain/blob/swarm/internal/web3ext/web3ext.go#L33 5906 */ 5907 5908 "use strict"; 5909 5910 var Method = require('../method'); 5911 var Property = require('../property'); 5912 5913 function Swarm(web3) { 5914 this._requestManager = web3._requestManager; 5915 5916 var self = this; 5917 5918 methods().forEach(function(method) { 5919 method.attachToObject(self); 5920 method.setRequestManager(self._requestManager); 5921 }); 5922 5923 properties().forEach(function(p) { 5924 p.attachToObject(self); 5925 p.setRequestManager(self._requestManager); 5926 }); 5927 } 5928 5929 var methods = function () { 5930 var blockNetworkRead = new Method({ 5931 name: 'blockNetworkRead', 5932 call: 'bzz_blockNetworkRead', 5933 params: 1, 5934 inputFormatter: [null] 5935 }); 5936 5937 var syncEnabled = new Method({ 5938 name: 'syncEnabled', 5939 call: 'bzz_syncEnabled', 5940 params: 1, 5941 inputFormatter: [null] 5942 }); 5943 5944 var swapEnabled = new Method({ 5945 name: 'swapEnabled', 5946 call: 'bzz_swapEnabled', 5947 params: 1, 5948 inputFormatter: [null] 5949 }); 5950 5951 var download = new Method({ 5952 name: 'download', 5953 call: 'bzz_download', 5954 params: 2, 5955 inputFormatter: [null, null] 5956 }); 5957 5958 var upload = new Method({ 5959 name: 'upload', 5960 call: 'bzz_upload', 5961 params: 2, 5962 inputFormatter: [null, null] 5963 }); 5964 5965 var retrieve = new Method({ 5966 name: 'retrieve', 5967 call: 'bzz_retrieve', 5968 params: 1, 5969 inputFormatter: [null] 5970 }); 5971 5972 var store = new Method({ 5973 name: 'store', 5974 call: 'bzz_store', 5975 params: 2, 5976 inputFormatter: [null, null] 5977 }); 5978 5979 var get = new Method({ 5980 name: 'get', 5981 call: 'bzz_get', 5982 params: 1, 5983 inputFormatter: [null] 5984 }); 5985 5986 var put = new Method({ 5987 name: 'put', 5988 call: 'bzz_put', 5989 params: 2, 5990 inputFormatter: [null, null] 5991 }); 5992 5993 var modify = new Method({ 5994 name: 'modify', 5995 call: 'bzz_modify', 5996 params: 4, 5997 inputFormatter: [null, null, null, null] 5998 }); 5999 6000 return [ 6001 blockNetworkRead, 6002 syncEnabled, 6003 swapEnabled, 6004 download, 6005 upload, 6006 retrieve, 6007 store, 6008 get, 6009 put, 6010 modify 6011 ]; 6012 }; 6013 6014 var properties = function () { 6015 return [ 6016 new Property({ 6017 name: 'hive', 6018 getter: 'bzz_hive' 6019 }), 6020 new Property({ 6021 name: 'info', 6022 getter: 'bzz_info' 6023 }) 6024 ]; 6025 }; 6026 6027 6028 module.exports = Swarm; 6029 6030 },{"../method":36,"../property":45}],43:[function(require,module,exports){ 6031 /* 6032 This file is part of web3.js. 6033 6034 web3.js is free software: you can redistribute it and/or modify 6035 it under the terms of the GNU Lesser General Public License as published by 6036 the Free Software Foundation, either version 3 of the License, or 6037 (at your option) any later version. 6038 6039 web3.js is distributed in the hope that it will be useful, 6040 but WITHOUT ANY WARRANTY; without even the implied warranty of 6041 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6042 GNU Lesser General Public License for more details. 6043 6044 You should have received a copy of the GNU Lesser General Public License 6045 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6046 */ 6047 /** @file watches.js 6048 * @authors: 6049 * Marek Kotewicz <marek@ethdev.com> 6050 * @date 2015 6051 */ 6052 6053 var Method = require('../method'); 6054 6055 /// @returns an array of objects describing web3.eth.filter api methods 6056 var qct = function () { 6057 var newFilterCall = function (args) { 6058 var type = args[0]; 6059 6060 switch(type) { 6061 case 'latest': 6062 args.shift(); 6063 this.params = 0; 6064 return 'qct_newBlockFilter'; 6065 case 'pending': 6066 args.shift(); 6067 this.params = 0; 6068 return 'qct_newPendingTransactionFilter'; 6069 default: 6070 return 'qct_newFilter'; 6071 } 6072 }; 6073 6074 var newFilter = new Method({ 6075 name: 'newFilter', 6076 call: newFilterCall, 6077 params: 1 6078 }); 6079 6080 var uninstallFilter = new Method({ 6081 name: 'uninstallFilter', 6082 call: 'qct_uninstallFilter', 6083 params: 1 6084 }); 6085 6086 var getLogs = new Method({ 6087 name: 'getLogs', 6088 call: 'qct_getFilterLogs', 6089 params: 1 6090 }); 6091 6092 var poll = new Method({ 6093 name: 'poll', 6094 call: 'qct_getFilterChanges', 6095 params: 1 6096 }); 6097 6098 return [ 6099 newFilter, 6100 uninstallFilter, 6101 getLogs, 6102 poll 6103 ]; 6104 }; 6105 6106 /// @returns an array of objects describing web3.shh.watch api methods 6107 var shh = function () { 6108 6109 return [ 6110 new Method({ 6111 name: 'newFilter', 6112 call: 'shh_newMessageFilter', 6113 params: 1 6114 }), 6115 new Method({ 6116 name: 'uninstallFilter', 6117 call: 'shh_deleteMessageFilter', 6118 params: 1 6119 }), 6120 new Method({ 6121 name: 'getLogs', 6122 call: 'shh_getFilterMessages', 6123 params: 1 6124 }), 6125 new Method({ 6126 name: 'poll', 6127 call: 'shh_getFilterMessages', 6128 params: 1 6129 }) 6130 ]; 6131 }; 6132 6133 module.exports = { 6134 qct: qct, 6135 shh: shh 6136 }; 6137 6138 6139 },{"../method":36}],44:[function(require,module,exports){ 6140 /* 6141 This file is part of web3.js. 6142 6143 web3.js is free software: you can redistribute it and/or modify 6144 it under the terms of the GNU Lesser General Public License as published by 6145 the Free Software Foundation, either version 3 of the License, or 6146 (at your option) any later version. 6147 6148 web3.js is distributed in the hope that it will be useful, 6149 but WITHOUT ANY WARRANTY; without even the implied warranty of 6150 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6151 GNU Lesser General Public License for more details. 6152 6153 You should have received a copy of the GNU Lesser General Public License 6154 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6155 */ 6156 /** 6157 * @file namereg.js 6158 * @author Marek Kotewicz <marek@ethdev.com> 6159 * @date 2015 6160 */ 6161 6162 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6163 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6164 6165 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6166 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6167 6168 module.exports = { 6169 global: { 6170 abi: globalRegistrarAbi, 6171 address: globalNameregAddress 6172 }, 6173 icap: { 6174 abi: icapRegistrarAbi, 6175 address: icapNameregAddress 6176 } 6177 }; 6178 6179 6180 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 6181 /* 6182 This file is part of web3.js. 6183 6184 web3.js is free software: you can redistribute it and/or modify 6185 it under the terms of the GNU Lesser General Public License as published by 6186 the Free Software Foundation, either version 3 of the License, or 6187 (at your option) any later version. 6188 6189 web3.js is distributed in the hope that it will be useful, 6190 but WITHOUT ANY WARRANTY; without even the implied warranty of 6191 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6192 GNU Lesser General Public License for more details. 6193 6194 You should have received a copy of the GNU Lesser General Public License 6195 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6196 */ 6197 /** 6198 * @file property.js 6199 * @author Fabian Vogelsteller <fabian@frozeman.de> 6200 * @author Marek Kotewicz <marek@ethdev.com> 6201 * @date 2015 6202 */ 6203 6204 var utils = require('../utils/utils'); 6205 6206 var Property = function (options) { 6207 this.name = options.name; 6208 this.getter = options.getter; 6209 this.setter = options.setter; 6210 this.outputFormatter = options.outputFormatter; 6211 this.inputFormatter = options.inputFormatter; 6212 this.requestManager = null; 6213 }; 6214 6215 Property.prototype.setRequestManager = function (rm) { 6216 this.requestManager = rm; 6217 }; 6218 6219 /** 6220 * Should be called to format input args of method 6221 * 6222 * @method formatInput 6223 * @param {Array} 6224 * @return {Array} 6225 */ 6226 Property.prototype.formatInput = function (arg) { 6227 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6228 }; 6229 6230 /** 6231 * Should be called to format output(result) of method 6232 * 6233 * @method formatOutput 6234 * @param {Object} 6235 * @return {Object} 6236 */ 6237 Property.prototype.formatOutput = function (result) { 6238 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6239 }; 6240 6241 /** 6242 * Should be used to extract callback from array of arguments. Modifies input param 6243 * 6244 * @method extractCallback 6245 * @param {Array} arguments 6246 * @return {Function|Null} callback, if exists 6247 */ 6248 Property.prototype.extractCallback = function (args) { 6249 if (utils.isFunction(args[args.length - 1])) { 6250 return args.pop(); // modify the args array! 6251 } 6252 }; 6253 6254 6255 /** 6256 * Should attach function to method 6257 * 6258 * @method attachToObject 6259 * @param {Object} 6260 * @param {Function} 6261 */ 6262 Property.prototype.attachToObject = function (obj) { 6263 var proto = { 6264 get: this.buildGet(), 6265 enumerable: true 6266 }; 6267 6268 var names = this.name.split('.'); 6269 var name = names[0]; 6270 if (names.length > 1) { 6271 obj[names[0]] = obj[names[0]] || {}; 6272 obj = obj[names[0]]; 6273 name = names[1]; 6274 } 6275 6276 Object.defineProperty(obj, name, proto); 6277 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6278 }; 6279 6280 var asyncGetterName = function (name) { 6281 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6282 }; 6283 6284 Property.prototype.buildGet = function () { 6285 var property = this; 6286 return function get() { 6287 return property.formatOutput(property.requestManager.send({ 6288 method: property.getter 6289 })); 6290 }; 6291 }; 6292 6293 Property.prototype.buildAsyncGet = function () { 6294 var property = this; 6295 var get = function (callback) { 6296 property.requestManager.sendAsync({ 6297 method: property.getter 6298 }, function (err, result) { 6299 callback(err, property.formatOutput(result)); 6300 }); 6301 }; 6302 get.request = this.request.bind(this); 6303 return get; 6304 }; 6305 6306 /** 6307 * Should be called to create pure JSONRPC request which can be used in batch request 6308 * 6309 * @method request 6310 * @param {...} params 6311 * @return {Object} jsonrpc request 6312 */ 6313 Property.prototype.request = function () { 6314 var payload = { 6315 method: this.getter, 6316 params: [], 6317 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6318 }; 6319 payload.format = this.formatOutput.bind(this); 6320 return payload; 6321 }; 6322 6323 module.exports = Property; 6324 6325 6326 },{"../utils/utils":20}],46:[function(require,module,exports){ 6327 /* 6328 This file is part of web3.js. 6329 6330 web3.js is free software: you can redistribute it and/or modify 6331 it under the terms of the GNU Lesser General Public License as published by 6332 the Free Software Foundation, either version 3 of the License, or 6333 (at your option) any later version. 6334 6335 web3.js is distributed in the hope that it will be useful, 6336 but WITHOUT ANY WARRANTY; without even the implied warranty of 6337 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6338 GNU Lesser General Public License for more details. 6339 6340 You should have received a copy of the GNU Lesser General Public License 6341 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6342 */ 6343 /** 6344 * @file requestmanager.js 6345 * @author Jeffrey Wilcke <jeff@ethdev.com> 6346 * @author Marek Kotewicz <marek@ethdev.com> 6347 * @author Marian Oancea <marian@ethdev.com> 6348 * @author Fabian Vogelsteller <fabian@ethdev.com> 6349 * @author Gav Wood <g@ethdev.com> 6350 * @date 2014 6351 */ 6352 6353 var Jsonrpc = require('./jsonrpc'); 6354 var utils = require('../utils/utils'); 6355 var c = require('../utils/config'); 6356 var errors = require('./errors'); 6357 6358 /** 6359 * It's responsible for passing messages to providers 6360 * It's also responsible for polling the quickchain node for incoming messages 6361 * Default poll timeout is 1 second 6362 * Singleton 6363 */ 6364 var RequestManager = function (provider) { 6365 this.provider = provider; 6366 this.polls = {}; 6367 this.timeout = null; 6368 }; 6369 6370 /** 6371 * Should be used to synchronously send request 6372 * 6373 * @method send 6374 * @param {Object} data 6375 * @return {Object} 6376 */ 6377 RequestManager.prototype.send = function (data) { 6378 if (!this.provider) { 6379 console.error(errors.InvalidProvider()); 6380 return null; 6381 } 6382 6383 var payload = Jsonrpc.toPayload(data.method, data.params); 6384 var result = this.provider.send(payload); 6385 6386 if (!Jsonrpc.isValidResponse(result)) { 6387 throw errors.InvalidResponse(result); 6388 } 6389 6390 return result.result; 6391 }; 6392 6393 /** 6394 * Should be used to asynchronously send request 6395 * 6396 * @method sendAsync 6397 * @param {Object} data 6398 * @param {Function} callback 6399 */ 6400 RequestManager.prototype.sendAsync = function (data, callback) { 6401 if (!this.provider) { 6402 return callback(errors.InvalidProvider()); 6403 } 6404 6405 var payload = Jsonrpc.toPayload(data.method, data.params); 6406 this.provider.sendAsync(payload, function (err, result) { 6407 if (err) { 6408 return callback(err); 6409 } 6410 6411 if (!Jsonrpc.isValidResponse(result)) { 6412 return callback(errors.InvalidResponse(result)); 6413 } 6414 6415 callback(null, result.result); 6416 }); 6417 }; 6418 6419 /** 6420 * Should be called to asynchronously send batch request 6421 * 6422 * @method sendBatch 6423 * @param {Array} batch data 6424 * @param {Function} callback 6425 */ 6426 RequestManager.prototype.sendBatch = function (data, callback) { 6427 if (!this.provider) { 6428 return callback(errors.InvalidProvider()); 6429 } 6430 6431 var payload = Jsonrpc.toBatchPayload(data); 6432 6433 this.provider.sendAsync(payload, function (err, results) { 6434 if (err) { 6435 return callback(err); 6436 } 6437 6438 if (!utils.isArray(results)) { 6439 return callback(errors.InvalidResponse(results)); 6440 } 6441 6442 callback(err, results); 6443 }); 6444 }; 6445 6446 /** 6447 * Should be used to set provider of request manager 6448 * 6449 * @method setProvider 6450 * @param {Object} 6451 */ 6452 RequestManager.prototype.setProvider = function (p) { 6453 this.provider = p; 6454 }; 6455 6456 /** 6457 * Should be used to start polling 6458 * 6459 * @method startPolling 6460 * @param {Object} data 6461 * @param {Number} pollId 6462 * @param {Function} callback 6463 * @param {Function} uninstall 6464 * 6465 * @todo cleanup number of params 6466 */ 6467 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6468 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 6469 6470 6471 // start polling 6472 if (!this.timeout) { 6473 this.poll(); 6474 } 6475 }; 6476 6477 /** 6478 * Should be used to stop polling for filter with given id 6479 * 6480 * @method stopPolling 6481 * @param {Number} pollId 6482 */ 6483 RequestManager.prototype.stopPolling = function (pollId) { 6484 delete this.polls[pollId]; 6485 6486 // stop polling 6487 if(Object.keys(this.polls).length === 0 && this.timeout) { 6488 clearTimeout(this.timeout); 6489 this.timeout = null; 6490 } 6491 }; 6492 6493 /** 6494 * Should be called to reset the polling mechanism of the request manager 6495 * 6496 * @method reset 6497 */ 6498 RequestManager.prototype.reset = function (keepIsSyncing) { 6499 /*jshint maxcomplexity:5 */ 6500 6501 for (var key in this.polls) { 6502 // remove all polls, except sync polls, 6503 // they need to be removed manually by calling syncing.stopWatching() 6504 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6505 this.polls[key].uninstall(); 6506 delete this.polls[key]; 6507 } 6508 } 6509 6510 // stop polling 6511 if(Object.keys(this.polls).length === 0 && this.timeout) { 6512 clearTimeout(this.timeout); 6513 this.timeout = null; 6514 } 6515 }; 6516 6517 /** 6518 * Should be called to poll for changes on filter with given id 6519 * 6520 * @method poll 6521 */ 6522 RequestManager.prototype.poll = function () { 6523 /*jshint maxcomplexity: 6 */ 6524 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6525 6526 if (Object.keys(this.polls).length === 0) { 6527 return; 6528 } 6529 6530 if (!this.provider) { 6531 console.error(errors.InvalidProvider()); 6532 return; 6533 } 6534 6535 var pollsData = []; 6536 var pollsIds = []; 6537 for (var key in this.polls) { 6538 pollsData.push(this.polls[key].data); 6539 pollsIds.push(key); 6540 } 6541 6542 if (pollsData.length === 0) { 6543 return; 6544 } 6545 6546 var payload = Jsonrpc.toBatchPayload(pollsData); 6547 6548 // map the request id to they poll id 6549 var pollsIdMap = {}; 6550 payload.forEach(function(load, index){ 6551 pollsIdMap[load.id] = pollsIds[index]; 6552 }); 6553 6554 6555 var self = this; 6556 this.provider.sendAsync(payload, function (error, results) { 6557 6558 6559 // TODO: console log? 6560 if (error) { 6561 return; 6562 } 6563 6564 if (!utils.isArray(results)) { 6565 throw errors.InvalidResponse(results); 6566 } 6567 results.map(function (result) { 6568 var id = pollsIdMap[result.id]; 6569 6570 // make sure the filter is still installed after arrival of the request 6571 if (self.polls[id]) { 6572 result.callback = self.polls[id].callback; 6573 return result; 6574 } else 6575 return false; 6576 }).filter(function (result) { 6577 return !!result; 6578 }).filter(function (result) { 6579 var valid = Jsonrpc.isValidResponse(result); 6580 if (!valid) { 6581 result.callback(errors.InvalidResponse(result)); 6582 } 6583 return valid; 6584 }).forEach(function (result) { 6585 result.callback(null, result.result); 6586 }); 6587 }); 6588 }; 6589 6590 module.exports = RequestManager; 6591 6592 6593 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 6594 6595 6596 var Settings = function () { 6597 this.defaultBlock = 'latest'; 6598 this.defaultAccount = undefined; 6599 }; 6600 6601 module.exports = Settings; 6602 6603 6604 },{}],48:[function(require,module,exports){ 6605 /* 6606 This file is part of web3.js. 6607 6608 web3.js is free software: you can redistribute it and/or modify 6609 it under the terms of the GNU Lesser General Public License as published by 6610 the Free Software Foundation, either version 3 of the License, or 6611 (at your option) any later version. 6612 6613 web3.js is distributed in the hope that it will be useful, 6614 but WITHOUT ANY WARRANTY; without even the implied warranty of 6615 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6616 GNU Lesser General Public License for more details. 6617 6618 You should have received a copy of the GNU Lesser General Public License 6619 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6620 */ 6621 /** @file syncing.js 6622 * @authors: 6623 * Fabian Vogelsteller <fabian@ethdev.com> 6624 * @date 2015 6625 */ 6626 6627 var formatters = require('./formatters'); 6628 var utils = require('../utils/utils'); 6629 6630 var count = 1; 6631 6632 /** 6633 Adds the callback and sets up the methods, to iterate over the results. 6634 6635 @method pollSyncing 6636 @param {Object} self 6637 */ 6638 var pollSyncing = function(self) { 6639 6640 var onMessage = function (error, sync) { 6641 if (error) { 6642 return self.callbacks.forEach(function (callback) { 6643 callback(error); 6644 }); 6645 } 6646 6647 if(utils.isObject(sync) && sync.startingBlock) 6648 sync = formatters.outputSyncingFormatter(sync); 6649 6650 self.callbacks.forEach(function (callback) { 6651 if (self.lastSyncState !== sync) { 6652 6653 // call the callback with true first so the app can stop anything, before receiving the sync data 6654 if(!self.lastSyncState && utils.isObject(sync)) 6655 callback(null, true); 6656 6657 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6658 setTimeout(function() { 6659 callback(null, sync); 6660 }, 0); 6661 6662 self.lastSyncState = sync; 6663 } 6664 }); 6665 }; 6666 6667 self.requestManager.startPolling({ 6668 method: 'qct_syncing', 6669 params: [], 6670 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6671 6672 }; 6673 6674 var IsSyncing = function (requestManager, callback) { 6675 this.requestManager = requestManager; 6676 this.pollId = 'syncPoll_'+ count++; 6677 this.callbacks = []; 6678 this.addCallback(callback); 6679 this.lastSyncState = false; 6680 pollSyncing(this); 6681 6682 return this; 6683 }; 6684 6685 IsSyncing.prototype.addCallback = function (callback) { 6686 if(callback) 6687 this.callbacks.push(callback); 6688 return this; 6689 }; 6690 6691 IsSyncing.prototype.stopWatching = function () { 6692 this.requestManager.stopPolling(this.pollId); 6693 this.callbacks = []; 6694 }; 6695 6696 module.exports = IsSyncing; 6697 6698 6699 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 6700 /* 6701 This file is part of web3.js. 6702 6703 web3.js is free software: you can redistribute it and/or modify 6704 it under the terms of the GNU Lesser General Public License as published by 6705 the Free Software Foundation, either version 3 of the License, or 6706 (at your option) any later version. 6707 6708 web3.js is distributed in the hope that it will be useful, 6709 but WITHOUT ANY WARRANTY; without even the implied warranty of 6710 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6711 GNU Lesser General Public License for more details. 6712 6713 You should have received a copy of the GNU Lesser General Public License 6714 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6715 */ 6716 /** 6717 * @file transfer.js 6718 * @author Marek Kotewicz <marek@ethdev.com> 6719 * @date 2015 6720 */ 6721 6722 var Iban = require('./iban'); 6723 var exchangeAbi = require('../contracts/SmartExchange.json'); 6724 6725 /** 6726 * Should be used to make Iban transfer 6727 * 6728 * @method transfer 6729 * @param {String} from 6730 * @param {String} to iban 6731 * @param {Value} value to be tranfered 6732 * @param {Function} callback, callback 6733 */ 6734 var transfer = function (qct, from, to, value, callback) { 6735 var iban = new Iban(to); 6736 if (!iban.isValid()) { 6737 throw new Error('invalid iban address'); 6738 } 6739 6740 if (iban.isDirect()) { 6741 return transferToAddress(qct, from, iban.address(), value, callback); 6742 } 6743 6744 if (!callback) { 6745 var address = qct.icapNamereg().addr(iban.institution()); 6746 return deposit(qct, from, address, value, iban.client()); 6747 } 6748 6749 qct.icapNamereg().addr(iban.institution(), function (err, address) { 6750 return deposit(qct, from, address, value, iban.client(), callback); 6751 }); 6752 6753 }; 6754 6755 /** 6756 * Should be used to transfer funds to certain address 6757 * 6758 * @method transferToAddress 6759 * @param {String} from 6760 * @param {String} to 6761 * @param {Value} value to be tranfered 6762 * @param {Function} callback, callback 6763 */ 6764 var transferToAddress = function (qct, from, to, value, callback) { 6765 return qct.sendTransaction({ 6766 address: to, 6767 from: from, 6768 value: value 6769 }, callback); 6770 }; 6771 6772 /** 6773 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6774 * 6775 * @method deposit 6776 * @param {String} from 6777 * @param {String} to 6778 * @param {Value} value to be transfered 6779 * @param {String} client unique identifier 6780 * @param {Function} callback, callback 6781 */ 6782 var deposit = function (qct, from, to, value, client, callback) { 6783 var abi = exchangeAbi; 6784 return qct.contract(abi).at(to).deposit(client, { 6785 from: from, 6786 value: value 6787 }, callback); 6788 }; 6789 6790 module.exports = transfer; 6791 6792 6793 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 6794 6795 },{}],51:[function(require,module,exports){ 6796 ;(function (root, factory, undef) { 6797 if (typeof exports === "object") { 6798 // CommonJS 6799 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6800 } 6801 else if (typeof define === "function" && define.amd) { 6802 // AMD 6803 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6804 } 6805 else { 6806 // Global (browser) 6807 factory(root.CryptoJS); 6808 } 6809 }(this, function (CryptoJS) { 6810 6811 (function () { 6812 // Shortcuts 6813 var C = CryptoJS; 6814 var C_lib = C.lib; 6815 var BlockCipher = C_lib.BlockCipher; 6816 var C_algo = C.algo; 6817 6818 // Lookup tables 6819 var SBOX = []; 6820 var INV_SBOX = []; 6821 var SUB_MIX_0 = []; 6822 var SUB_MIX_1 = []; 6823 var SUB_MIX_2 = []; 6824 var SUB_MIX_3 = []; 6825 var INV_SUB_MIX_0 = []; 6826 var INV_SUB_MIX_1 = []; 6827 var INV_SUB_MIX_2 = []; 6828 var INV_SUB_MIX_3 = []; 6829 6830 // Compute lookup tables 6831 (function () { 6832 // Compute double table 6833 var d = []; 6834 for (var i = 0; i < 256; i++) { 6835 if (i < 128) { 6836 d[i] = i << 1; 6837 } else { 6838 d[i] = (i << 1) ^ 0x11b; 6839 } 6840 } 6841 6842 // Walk GF(2^8) 6843 var x = 0; 6844 var xi = 0; 6845 for (var i = 0; i < 256; i++) { 6846 // Compute sbox 6847 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6848 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6849 SBOX[x] = sx; 6850 INV_SBOX[sx] = x; 6851 6852 // Compute multiplication 6853 var x2 = d[x]; 6854 var x4 = d[x2]; 6855 var x8 = d[x4]; 6856 6857 // Compute sub bytes, mix columns tables 6858 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6859 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6860 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6861 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6862 SUB_MIX_3[x] = t; 6863 6864 // Compute inv sub bytes, inv mix columns tables 6865 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6866 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6867 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6868 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6869 INV_SUB_MIX_3[sx] = t; 6870 6871 // Compute next counter 6872 if (!x) { 6873 x = xi = 1; 6874 } else { 6875 x = x2 ^ d[d[d[x8 ^ x2]]]; 6876 xi ^= d[d[xi]]; 6877 } 6878 } 6879 }()); 6880 6881 // Precomputed Rcon lookup 6882 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6883 6884 /** 6885 * AES block cipher algorithm. 6886 */ 6887 var AES = C_algo.AES = BlockCipher.extend({ 6888 _doReset: function () { 6889 // Skip reset of nRounds has been set before and key did not change 6890 if (this._nRounds && this._keyPriorReset === this._key) { 6891 return; 6892 } 6893 6894 // Shortcuts 6895 var key = this._keyPriorReset = this._key; 6896 var keyWords = key.words; 6897 var keySize = key.sigBytes / 4; 6898 6899 // Compute number of rounds 6900 var nRounds = this._nRounds = keySize + 6; 6901 6902 // Compute number of key schedule rows 6903 var ksRows = (nRounds + 1) * 4; 6904 6905 // Compute key schedule 6906 var keySchedule = this._keySchedule = []; 6907 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 6908 if (ksRow < keySize) { 6909 keySchedule[ksRow] = keyWords[ksRow]; 6910 } else { 6911 var t = keySchedule[ksRow - 1]; 6912 6913 if (!(ksRow % keySize)) { 6914 // Rot word 6915 t = (t << 8) | (t >>> 24); 6916 6917 // Sub word 6918 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6919 6920 // Mix Rcon 6921 t ^= RCON[(ksRow / keySize) | 0] << 24; 6922 } else if (keySize > 6 && ksRow % keySize == 4) { 6923 // Sub word 6924 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6925 } 6926 6927 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 6928 } 6929 } 6930 6931 // Compute inv key schedule 6932 var invKeySchedule = this._invKeySchedule = []; 6933 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 6934 var ksRow = ksRows - invKsRow; 6935 6936 if (invKsRow % 4) { 6937 var t = keySchedule[ksRow]; 6938 } else { 6939 var t = keySchedule[ksRow - 4]; 6940 } 6941 6942 if (invKsRow < 4 || ksRow <= 4) { 6943 invKeySchedule[invKsRow] = t; 6944 } else { 6945 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 6946 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 6947 } 6948 } 6949 }, 6950 6951 encryptBlock: function (M, offset) { 6952 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 6953 }, 6954 6955 decryptBlock: function (M, offset) { 6956 // Swap 2nd and 4th rows 6957 var t = M[offset + 1]; 6958 M[offset + 1] = M[offset + 3]; 6959 M[offset + 3] = t; 6960 6961 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 6962 6963 // Inv swap 2nd and 4th rows 6964 var t = M[offset + 1]; 6965 M[offset + 1] = M[offset + 3]; 6966 M[offset + 3] = t; 6967 }, 6968 6969 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 6970 // Shortcut 6971 var nRounds = this._nRounds; 6972 6973 // Get input, add round key 6974 var s0 = M[offset] ^ keySchedule[0]; 6975 var s1 = M[offset + 1] ^ keySchedule[1]; 6976 var s2 = M[offset + 2] ^ keySchedule[2]; 6977 var s3 = M[offset + 3] ^ keySchedule[3]; 6978 6979 // Key schedule row counter 6980 var ksRow = 4; 6981 6982 // Rounds 6983 for (var round = 1; round < nRounds; round++) { 6984 // Shift rows, sub bytes, mix columns, add round key 6985 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++]; 6986 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++]; 6987 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++]; 6988 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++]; 6989 6990 // Update state 6991 s0 = t0; 6992 s1 = t1; 6993 s2 = t2; 6994 s3 = t3; 6995 } 6996 6997 // Shift rows, sub bytes, add round key 6998 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 6999 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 7000 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 7001 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 7002 7003 // Set output 7004 M[offset] = t0; 7005 M[offset + 1] = t1; 7006 M[offset + 2] = t2; 7007 M[offset + 3] = t3; 7008 }, 7009 7010 keySize: 256/32 7011 }); 7012 7013 /** 7014 * Shortcut functions to the cipher's object interface. 7015 * 7016 * @example 7017 * 7018 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7019 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7020 */ 7021 C.AES = BlockCipher._createHelper(AES); 7022 }()); 7023 7024 7025 return CryptoJS.AES; 7026 7027 })); 7028 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 7029 ;(function (root, factory) { 7030 if (typeof exports === "object") { 7031 // CommonJS 7032 module.exports = exports = factory(require("./core")); 7033 } 7034 else if (typeof define === "function" && define.amd) { 7035 // AMD 7036 define(["./core"], factory); 7037 } 7038 else { 7039 // Global (browser) 7040 factory(root.CryptoJS); 7041 } 7042 }(this, function (CryptoJS) { 7043 7044 /** 7045 * Cipher core components. 7046 */ 7047 CryptoJS.lib.Cipher || (function (undefined) { 7048 // Shortcuts 7049 var C = CryptoJS; 7050 var C_lib = C.lib; 7051 var Base = C_lib.Base; 7052 var WordArray = C_lib.WordArray; 7053 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7054 var C_enc = C.enc; 7055 var Utf8 = C_enc.Utf8; 7056 var Base64 = C_enc.Base64; 7057 var C_algo = C.algo; 7058 var EvpKDF = C_algo.EvpKDF; 7059 7060 /** 7061 * Abstract base cipher template. 7062 * 7063 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7064 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7065 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7066 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7067 */ 7068 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7069 /** 7070 * Configuration options. 7071 * 7072 * @property {WordArray} iv The IV to use for this operation. 7073 */ 7074 cfg: Base.extend(), 7075 7076 /** 7077 * Creates this cipher in encryption mode. 7078 * 7079 * @param {WordArray} key The key. 7080 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7081 * 7082 * @return {Cipher} A cipher instance. 7083 * 7084 * @static 7085 * 7086 * @example 7087 * 7088 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7089 */ 7090 createEncryptor: function (key, cfg) { 7091 return this.create(this._ENC_XFORM_MODE, key, cfg); 7092 }, 7093 7094 /** 7095 * Creates this cipher in decryption mode. 7096 * 7097 * @param {WordArray} key The key. 7098 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7099 * 7100 * @return {Cipher} A cipher instance. 7101 * 7102 * @static 7103 * 7104 * @example 7105 * 7106 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7107 */ 7108 createDecryptor: function (key, cfg) { 7109 return this.create(this._DEC_XFORM_MODE, key, cfg); 7110 }, 7111 7112 /** 7113 * Initializes a newly created cipher. 7114 * 7115 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7116 * @param {WordArray} key The key. 7117 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7118 * 7119 * @example 7120 * 7121 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7122 */ 7123 init: function (xformMode, key, cfg) { 7124 // Apply config defaults 7125 this.cfg = this.cfg.extend(cfg); 7126 7127 // Store transform mode and key 7128 this._xformMode = xformMode; 7129 this._key = key; 7130 7131 // Set initial values 7132 this.reset(); 7133 }, 7134 7135 /** 7136 * Resets this cipher to its initial state. 7137 * 7138 * @example 7139 * 7140 * cipher.reset(); 7141 */ 7142 reset: function () { 7143 // Reset data buffer 7144 BufferedBlockAlgorithm.reset.call(this); 7145 7146 // Perform concrete-cipher logic 7147 this._doReset(); 7148 }, 7149 7150 /** 7151 * Adds data to be encrypted or decrypted. 7152 * 7153 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7154 * 7155 * @return {WordArray} The data after processing. 7156 * 7157 * @example 7158 * 7159 * var encrypted = cipher.process('data'); 7160 * var encrypted = cipher.process(wordArray); 7161 */ 7162 process: function (dataUpdate) { 7163 // Append 7164 this._append(dataUpdate); 7165 7166 // Process available blocks 7167 return this._process(); 7168 }, 7169 7170 /** 7171 * Finalizes the encryption or decryption process. 7172 * Note that the finalize operation is effectively a destructive, read-once operation. 7173 * 7174 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7175 * 7176 * @return {WordArray} The data after final processing. 7177 * 7178 * @example 7179 * 7180 * var encrypted = cipher.finalize(); 7181 * var encrypted = cipher.finalize('data'); 7182 * var encrypted = cipher.finalize(wordArray); 7183 */ 7184 finalize: function (dataUpdate) { 7185 // Final data update 7186 if (dataUpdate) { 7187 this._append(dataUpdate); 7188 } 7189 7190 // Perform concrete-cipher logic 7191 var finalProcessedData = this._doFinalize(); 7192 7193 return finalProcessedData; 7194 }, 7195 7196 keySize: 128/32, 7197 7198 ivSize: 128/32, 7199 7200 _ENC_XFORM_MODE: 1, 7201 7202 _DEC_XFORM_MODE: 2, 7203 7204 /** 7205 * Creates shortcut functions to a cipher's object interface. 7206 * 7207 * @param {Cipher} cipher The cipher to create a helper for. 7208 * 7209 * @return {Object} An object with encrypt and decrypt shortcut functions. 7210 * 7211 * @static 7212 * 7213 * @example 7214 * 7215 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7216 */ 7217 _createHelper: (function () { 7218 function selectCipherStrategy(key) { 7219 if (typeof key == 'string') { 7220 return PasswordBasedCipher; 7221 } else { 7222 return SerializableCipher; 7223 } 7224 } 7225 7226 return function (cipher) { 7227 return { 7228 encrypt: function (message, key, cfg) { 7229 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7230 }, 7231 7232 decrypt: function (ciphertext, key, cfg) { 7233 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7234 } 7235 }; 7236 }; 7237 }()) 7238 }); 7239 7240 /** 7241 * Abstract base stream cipher template. 7242 * 7243 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7244 */ 7245 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7246 _doFinalize: function () { 7247 // Process partial blocks 7248 var finalProcessedBlocks = this._process(!!'flush'); 7249 7250 return finalProcessedBlocks; 7251 }, 7252 7253 blockSize: 1 7254 }); 7255 7256 /** 7257 * Mode namespace. 7258 */ 7259 var C_mode = C.mode = {}; 7260 7261 /** 7262 * Abstract base block cipher mode template. 7263 */ 7264 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7265 /** 7266 * Creates this mode for encryption. 7267 * 7268 * @param {Cipher} cipher A block cipher instance. 7269 * @param {Array} iv The IV words. 7270 * 7271 * @static 7272 * 7273 * @example 7274 * 7275 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7276 */ 7277 createEncryptor: function (cipher, iv) { 7278 return this.Encryptor.create(cipher, iv); 7279 }, 7280 7281 /** 7282 * Creates this mode for decryption. 7283 * 7284 * @param {Cipher} cipher A block cipher instance. 7285 * @param {Array} iv The IV words. 7286 * 7287 * @static 7288 * 7289 * @example 7290 * 7291 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7292 */ 7293 createDecryptor: function (cipher, iv) { 7294 return this.Decryptor.create(cipher, iv); 7295 }, 7296 7297 /** 7298 * Initializes a newly created mode. 7299 * 7300 * @param {Cipher} cipher A block cipher instance. 7301 * @param {Array} iv The IV words. 7302 * 7303 * @example 7304 * 7305 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7306 */ 7307 init: function (cipher, iv) { 7308 this._cipher = cipher; 7309 this._iv = iv; 7310 } 7311 }); 7312 7313 /** 7314 * Cipher Block Chaining mode. 7315 */ 7316 var CBC = C_mode.CBC = (function () { 7317 /** 7318 * Abstract base CBC mode. 7319 */ 7320 var CBC = BlockCipherMode.extend(); 7321 7322 /** 7323 * CBC encryptor. 7324 */ 7325 CBC.Encryptor = CBC.extend({ 7326 /** 7327 * Processes the data block at offset. 7328 * 7329 * @param {Array} words The data words to operate on. 7330 * @param {number} offset The offset where the block starts. 7331 * 7332 * @example 7333 * 7334 * mode.processBlock(data.words, offset); 7335 */ 7336 processBlock: function (words, offset) { 7337 // Shortcuts 7338 var cipher = this._cipher; 7339 var blockSize = cipher.blockSize; 7340 7341 // XOR and encrypt 7342 xorBlock.call(this, words, offset, blockSize); 7343 cipher.encryptBlock(words, offset); 7344 7345 // Remember this block to use with next block 7346 this._prevBlock = words.slice(offset, offset + blockSize); 7347 } 7348 }); 7349 7350 /** 7351 * CBC decryptor. 7352 */ 7353 CBC.Decryptor = CBC.extend({ 7354 /** 7355 * Processes the data block at offset. 7356 * 7357 * @param {Array} words The data words to operate on. 7358 * @param {number} offset The offset where the block starts. 7359 * 7360 * @example 7361 * 7362 * mode.processBlock(data.words, offset); 7363 */ 7364 processBlock: function (words, offset) { 7365 // Shortcuts 7366 var cipher = this._cipher; 7367 var blockSize = cipher.blockSize; 7368 7369 // Remember this block to use with next block 7370 var thisBlock = words.slice(offset, offset + blockSize); 7371 7372 // Decrypt and XOR 7373 cipher.decryptBlock(words, offset); 7374 xorBlock.call(this, words, offset, blockSize); 7375 7376 // This block becomes the previous block 7377 this._prevBlock = thisBlock; 7378 } 7379 }); 7380 7381 function xorBlock(words, offset, blockSize) { 7382 // Shortcut 7383 var iv = this._iv; 7384 7385 // Choose mixing block 7386 if (iv) { 7387 var block = iv; 7388 7389 // Remove IV for subsequent blocks 7390 this._iv = undefined; 7391 } else { 7392 var block = this._prevBlock; 7393 } 7394 7395 // XOR blocks 7396 for (var i = 0; i < blockSize; i++) { 7397 words[offset + i] ^= block[i]; 7398 } 7399 } 7400 7401 return CBC; 7402 }()); 7403 7404 /** 7405 * Padding namespace. 7406 */ 7407 var C_pad = C.pad = {}; 7408 7409 /** 7410 * PKCS #5/7 padding strategy. 7411 */ 7412 var Pkcs7 = C_pad.Pkcs7 = { 7413 /** 7414 * Pads data using the algorithm defined in PKCS #5/7. 7415 * 7416 * @param {WordArray} data The data to pad. 7417 * @param {number} blockSize The multiple that the data should be padded to. 7418 * 7419 * @static 7420 * 7421 * @example 7422 * 7423 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7424 */ 7425 pad: function (data, blockSize) { 7426 // Shortcut 7427 var blockSizeBytes = blockSize * 4; 7428 7429 // Count padding bytes 7430 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7431 7432 // Create padding word 7433 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7434 7435 // Create padding 7436 var paddingWords = []; 7437 for (var i = 0; i < nPaddingBytes; i += 4) { 7438 paddingWords.push(paddingWord); 7439 } 7440 var padding = WordArray.create(paddingWords, nPaddingBytes); 7441 7442 // Add padding 7443 data.concat(padding); 7444 }, 7445 7446 /** 7447 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7448 * 7449 * @param {WordArray} data The data to unpad. 7450 * 7451 * @static 7452 * 7453 * @example 7454 * 7455 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7456 */ 7457 unpad: function (data) { 7458 // Get number of padding bytes from last byte 7459 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7460 7461 // Remove padding 7462 data.sigBytes -= nPaddingBytes; 7463 } 7464 }; 7465 7466 /** 7467 * Abstract base block cipher template. 7468 * 7469 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7470 */ 7471 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7472 /** 7473 * Configuration options. 7474 * 7475 * @property {Mode} mode The block mode to use. Default: CBC 7476 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7477 */ 7478 cfg: Cipher.cfg.extend({ 7479 mode: CBC, 7480 padding: Pkcs7 7481 }), 7482 7483 reset: function () { 7484 // Reset cipher 7485 Cipher.reset.call(this); 7486 7487 // Shortcuts 7488 var cfg = this.cfg; 7489 var iv = cfg.iv; 7490 var mode = cfg.mode; 7491 7492 // Reset block mode 7493 if (this._xformMode == this._ENC_XFORM_MODE) { 7494 var modeCreator = mode.createEncryptor; 7495 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7496 var modeCreator = mode.createDecryptor; 7497 7498 // Keep at least one block in the buffer for unpadding 7499 this._minBufferSize = 1; 7500 } 7501 this._mode = modeCreator.call(mode, this, iv && iv.words); 7502 }, 7503 7504 _doProcessBlock: function (words, offset) { 7505 this._mode.processBlock(words, offset); 7506 }, 7507 7508 _doFinalize: function () { 7509 // Shortcut 7510 var padding = this.cfg.padding; 7511 7512 // Finalize 7513 if (this._xformMode == this._ENC_XFORM_MODE) { 7514 // Pad data 7515 padding.pad(this._data, this.blockSize); 7516 7517 // Process final blocks 7518 var finalProcessedBlocks = this._process(!!'flush'); 7519 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7520 // Process final blocks 7521 var finalProcessedBlocks = this._process(!!'flush'); 7522 7523 // Unpad data 7524 padding.unpad(finalProcessedBlocks); 7525 } 7526 7527 return finalProcessedBlocks; 7528 }, 7529 7530 blockSize: 128/32 7531 }); 7532 7533 /** 7534 * A collection of cipher parameters. 7535 * 7536 * @property {WordArray} ciphertext The raw ciphertext. 7537 * @property {WordArray} key The key to this ciphertext. 7538 * @property {WordArray} iv The IV used in the ciphering operation. 7539 * @property {WordArray} salt The salt used with a key derivation function. 7540 * @property {Cipher} algorithm The cipher algorithm. 7541 * @property {Mode} mode The block mode used in the ciphering operation. 7542 * @property {Padding} padding The padding scheme used in the ciphering operation. 7543 * @property {number} blockSize The block size of the cipher. 7544 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7545 */ 7546 var CipherParams = C_lib.CipherParams = Base.extend({ 7547 /** 7548 * Initializes a newly created cipher params object. 7549 * 7550 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7551 * 7552 * @example 7553 * 7554 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7555 * ciphertext: ciphertextWordArray, 7556 * key: keyWordArray, 7557 * iv: ivWordArray, 7558 * salt: saltWordArray, 7559 * algorithm: CryptoJS.algo.AES, 7560 * mode: CryptoJS.mode.CBC, 7561 * padding: CryptoJS.pad.PKCS7, 7562 * blockSize: 4, 7563 * formatter: CryptoJS.format.OpenSSL 7564 * }); 7565 */ 7566 init: function (cipherParams) { 7567 this.mixIn(cipherParams); 7568 }, 7569 7570 /** 7571 * Converts this cipher params object to a string. 7572 * 7573 * @param {Format} formatter (Optional) The formatting strategy to use. 7574 * 7575 * @return {string} The stringified cipher params. 7576 * 7577 * @throws Error If neither the formatter nor the default formatter is set. 7578 * 7579 * @example 7580 * 7581 * var string = cipherParams + ''; 7582 * var string = cipherParams.toString(); 7583 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7584 */ 7585 toString: function (formatter) { 7586 return (formatter || this.formatter).stringify(this); 7587 } 7588 }); 7589 7590 /** 7591 * Format namespace. 7592 */ 7593 var C_format = C.format = {}; 7594 7595 /** 7596 * OpenSSL formatting strategy. 7597 */ 7598 var OpenSSLFormatter = C_format.OpenSSL = { 7599 /** 7600 * Converts a cipher params object to an OpenSSL-compatible string. 7601 * 7602 * @param {CipherParams} cipherParams The cipher params object. 7603 * 7604 * @return {string} The OpenSSL-compatible string. 7605 * 7606 * @static 7607 * 7608 * @example 7609 * 7610 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7611 */ 7612 stringify: function (cipherParams) { 7613 // Shortcuts 7614 var ciphertext = cipherParams.ciphertext; 7615 var salt = cipherParams.salt; 7616 7617 // Format 7618 if (salt) { 7619 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7620 } else { 7621 var wordArray = ciphertext; 7622 } 7623 7624 return wordArray.toString(Base64); 7625 }, 7626 7627 /** 7628 * Converts an OpenSSL-compatible string to a cipher params object. 7629 * 7630 * @param {string} openSSLStr The OpenSSL-compatible string. 7631 * 7632 * @return {CipherParams} The cipher params object. 7633 * 7634 * @static 7635 * 7636 * @example 7637 * 7638 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7639 */ 7640 parse: function (openSSLStr) { 7641 // Parse base64 7642 var ciphertext = Base64.parse(openSSLStr); 7643 7644 // Shortcut 7645 var ciphertextWords = ciphertext.words; 7646 7647 // Test for salt 7648 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7649 // Extract salt 7650 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7651 7652 // Remove salt from ciphertext 7653 ciphertextWords.splice(0, 4); 7654 ciphertext.sigBytes -= 16; 7655 } 7656 7657 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7658 } 7659 }; 7660 7661 /** 7662 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7663 */ 7664 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7665 /** 7666 * Configuration options. 7667 * 7668 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7669 */ 7670 cfg: Base.extend({ 7671 format: OpenSSLFormatter 7672 }), 7673 7674 /** 7675 * Encrypts a message. 7676 * 7677 * @param {Cipher} cipher The cipher algorithm to use. 7678 * @param {WordArray|string} message The message to encrypt. 7679 * @param {WordArray} key The key. 7680 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7681 * 7682 * @return {CipherParams} A cipher params object. 7683 * 7684 * @static 7685 * 7686 * @example 7687 * 7688 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7689 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7690 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7691 */ 7692 encrypt: function (cipher, message, key, cfg) { 7693 // Apply config defaults 7694 cfg = this.cfg.extend(cfg); 7695 7696 // Encrypt 7697 var encryptor = cipher.createEncryptor(key, cfg); 7698 var ciphertext = encryptor.finalize(message); 7699 7700 // Shortcut 7701 var cipherCfg = encryptor.cfg; 7702 7703 // Create and return serializable cipher params 7704 return CipherParams.create({ 7705 ciphertext: ciphertext, 7706 key: key, 7707 iv: cipherCfg.iv, 7708 algorithm: cipher, 7709 mode: cipherCfg.mode, 7710 padding: cipherCfg.padding, 7711 blockSize: cipher.blockSize, 7712 formatter: cfg.format 7713 }); 7714 }, 7715 7716 /** 7717 * Decrypts serialized ciphertext. 7718 * 7719 * @param {Cipher} cipher The cipher algorithm to use. 7720 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7721 * @param {WordArray} key The key. 7722 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7723 * 7724 * @return {WordArray} The plaintext. 7725 * 7726 * @static 7727 * 7728 * @example 7729 * 7730 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7731 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7732 */ 7733 decrypt: function (cipher, ciphertext, key, cfg) { 7734 // Apply config defaults 7735 cfg = this.cfg.extend(cfg); 7736 7737 // Convert string to CipherParams 7738 ciphertext = this._parse(ciphertext, cfg.format); 7739 7740 // Decrypt 7741 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7742 7743 return plaintext; 7744 }, 7745 7746 /** 7747 * Converts serialized ciphertext to CipherParams, 7748 * else assumed CipherParams already and returns ciphertext unchanged. 7749 * 7750 * @param {CipherParams|string} ciphertext The ciphertext. 7751 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7752 * 7753 * @return {CipherParams} The unserialized ciphertext. 7754 * 7755 * @static 7756 * 7757 * @example 7758 * 7759 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7760 */ 7761 _parse: function (ciphertext, format) { 7762 if (typeof ciphertext == 'string') { 7763 return format.parse(ciphertext, this); 7764 } else { 7765 return ciphertext; 7766 } 7767 } 7768 }); 7769 7770 /** 7771 * Key derivation function namespace. 7772 */ 7773 var C_kdf = C.kdf = {}; 7774 7775 /** 7776 * OpenSSL key derivation function. 7777 */ 7778 var OpenSSLKdf = C_kdf.OpenSSL = { 7779 /** 7780 * Derives a key and IV from a password. 7781 * 7782 * @param {string} password The password to derive from. 7783 * @param {number} keySize The size in words of the key to generate. 7784 * @param {number} ivSize The size in words of the IV to generate. 7785 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7786 * 7787 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7788 * 7789 * @static 7790 * 7791 * @example 7792 * 7793 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7794 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7795 */ 7796 execute: function (password, keySize, ivSize, salt) { 7797 // Generate random salt 7798 if (!salt) { 7799 salt = WordArray.random(64/8); 7800 } 7801 7802 // Derive key and IV 7803 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 7804 7805 // Separate key and IV 7806 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7807 key.sigBytes = keySize * 4; 7808 7809 // Return params 7810 return CipherParams.create({ key: key, iv: iv, salt: salt }); 7811 } 7812 }; 7813 7814 /** 7815 * A serializable cipher wrapper that derives the key from a password, 7816 * and returns ciphertext as a serializable cipher params object. 7817 */ 7818 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7819 /** 7820 * Configuration options. 7821 * 7822 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7823 */ 7824 cfg: SerializableCipher.cfg.extend({ 7825 kdf: OpenSSLKdf 7826 }), 7827 7828 /** 7829 * Encrypts a message using a password. 7830 * 7831 * @param {Cipher} cipher The cipher algorithm to use. 7832 * @param {WordArray|string} message The message to encrypt. 7833 * @param {string} password The password. 7834 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7835 * 7836 * @return {CipherParams} A cipher params object. 7837 * 7838 * @static 7839 * 7840 * @example 7841 * 7842 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7843 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7844 */ 7845 encrypt: function (cipher, message, password, cfg) { 7846 // Apply config defaults 7847 cfg = this.cfg.extend(cfg); 7848 7849 // Derive key and other params 7850 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7851 7852 // Add IV to config 7853 cfg.iv = derivedParams.iv; 7854 7855 // Encrypt 7856 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7857 7858 // Mix in derived params 7859 ciphertext.mixIn(derivedParams); 7860 7861 return ciphertext; 7862 }, 7863 7864 /** 7865 * Decrypts serialized ciphertext using a password. 7866 * 7867 * @param {Cipher} cipher The cipher algorithm to use. 7868 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7869 * @param {string} password The password. 7870 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7871 * 7872 * @return {WordArray} The plaintext. 7873 * 7874 * @static 7875 * 7876 * @example 7877 * 7878 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 7879 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 7880 */ 7881 decrypt: function (cipher, ciphertext, password, cfg) { 7882 // Apply config defaults 7883 cfg = this.cfg.extend(cfg); 7884 7885 // Convert string to CipherParams 7886 ciphertext = this._parse(ciphertext, cfg.format); 7887 7888 // Derive key and other params 7889 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 7890 7891 // Add IV to config 7892 cfg.iv = derivedParams.iv; 7893 7894 // Decrypt 7895 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 7896 7897 return plaintext; 7898 } 7899 }); 7900 }()); 7901 7902 7903 })); 7904 },{"./core":53}],53:[function(require,module,exports){ 7905 ;(function (root, factory) { 7906 if (typeof exports === "object") { 7907 // CommonJS 7908 module.exports = exports = factory(); 7909 } 7910 else if (typeof define === "function" && define.amd) { 7911 // AMD 7912 define([], factory); 7913 } 7914 else { 7915 // Global (browser) 7916 root.CryptoJS = factory(); 7917 } 7918 }(this, function () { 7919 7920 /** 7921 * CryptoJS core components. 7922 */ 7923 var CryptoJS = CryptoJS || (function (Math, undefined) { 7924 /* 7925 * Local polyfil of Object.create 7926 */ 7927 var create = Object.create || (function () { 7928 function F() {}; 7929 7930 return function (obj) { 7931 var subtype; 7932 7933 F.prototype = obj; 7934 7935 subtype = new F(); 7936 7937 F.prototype = null; 7938 7939 return subtype; 7940 }; 7941 }()) 7942 7943 /** 7944 * CryptoJS namespace. 7945 */ 7946 var C = {}; 7947 7948 /** 7949 * Library namespace. 7950 */ 7951 var C_lib = C.lib = {}; 7952 7953 /** 7954 * Base object for prototypal inheritance. 7955 */ 7956 var Base = C_lib.Base = (function () { 7957 7958 7959 return { 7960 /** 7961 * Creates a new object that inherits from this object. 7962 * 7963 * @param {Object} overrides Properties to copy into the new object. 7964 * 7965 * @return {Object} The new object. 7966 * 7967 * @static 7968 * 7969 * @example 7970 * 7971 * var MyType = CryptoJS.lib.Base.extend({ 7972 * field: 'value', 7973 * 7974 * method: function () { 7975 * } 7976 * }); 7977 */ 7978 extend: function (overrides) { 7979 // Spawn 7980 var subtype = create(this); 7981 7982 // Augment 7983 if (overrides) { 7984 subtype.mixIn(overrides); 7985 } 7986 7987 // Create default initializer 7988 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 7989 subtype.init = function () { 7990 subtype.$super.init.apply(this, arguments); 7991 }; 7992 } 7993 7994 // Initializer's prototype is the subtype object 7995 subtype.init.prototype = subtype; 7996 7997 // Reference supertype 7998 subtype.$super = this; 7999 8000 return subtype; 8001 }, 8002 8003 /** 8004 * Extends this object and runs the init method. 8005 * Arguments to create() will be passed to init(). 8006 * 8007 * @return {Object} The new object. 8008 * 8009 * @static 8010 * 8011 * @example 8012 * 8013 * var instance = MyType.create(); 8014 */ 8015 create: function () { 8016 var instance = this.extend(); 8017 instance.init.apply(instance, arguments); 8018 8019 return instance; 8020 }, 8021 8022 /** 8023 * Initializes a newly created object. 8024 * Override this method to add some logic when your objects are created. 8025 * 8026 * @example 8027 * 8028 * var MyType = CryptoJS.lib.Base.extend({ 8029 * init: function () { 8030 * // ... 8031 * } 8032 * }); 8033 */ 8034 init: function () { 8035 }, 8036 8037 /** 8038 * Copies properties into this object. 8039 * 8040 * @param {Object} properties The properties to mix in. 8041 * 8042 * @example 8043 * 8044 * MyType.mixIn({ 8045 * field: 'value' 8046 * }); 8047 */ 8048 mixIn: function (properties) { 8049 for (var propertyName in properties) { 8050 if (properties.hasOwnProperty(propertyName)) { 8051 this[propertyName] = properties[propertyName]; 8052 } 8053 } 8054 8055 // IE won't copy toString using the loop above 8056 if (properties.hasOwnProperty('toString')) { 8057 this.toString = properties.toString; 8058 } 8059 }, 8060 8061 /** 8062 * Creates a copy of this object. 8063 * 8064 * @return {Object} The clone. 8065 * 8066 * @example 8067 * 8068 * var clone = instance.clone(); 8069 */ 8070 clone: function () { 8071 return this.init.prototype.extend(this); 8072 } 8073 }; 8074 }()); 8075 8076 /** 8077 * An array of 32-bit words. 8078 * 8079 * @property {Array} words The array of 32-bit words. 8080 * @property {number} sigBytes The number of significant bytes in this word array. 8081 */ 8082 var WordArray = C_lib.WordArray = Base.extend({ 8083 /** 8084 * Initializes a newly created word array. 8085 * 8086 * @param {Array} words (Optional) An array of 32-bit words. 8087 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8088 * 8089 * @example 8090 * 8091 * var wordArray = CryptoJS.lib.WordArray.create(); 8092 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8093 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8094 */ 8095 init: function (words, sigBytes) { 8096 words = this.words = words || []; 8097 8098 if (sigBytes != undefined) { 8099 this.sigBytes = sigBytes; 8100 } else { 8101 this.sigBytes = words.length * 4; 8102 } 8103 }, 8104 8105 /** 8106 * Converts this word array to a string. 8107 * 8108 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8109 * 8110 * @return {string} The stringified word array. 8111 * 8112 * @example 8113 * 8114 * var string = wordArray + ''; 8115 * var string = wordArray.toString(); 8116 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8117 */ 8118 toString: function (encoder) { 8119 return (encoder || Hex).stringify(this); 8120 }, 8121 8122 /** 8123 * Concatenates a word array to this word array. 8124 * 8125 * @param {WordArray} wordArray The word array to append. 8126 * 8127 * @return {WordArray} This word array. 8128 * 8129 * @example 8130 * 8131 * wordArray1.concat(wordArray2); 8132 */ 8133 concat: function (wordArray) { 8134 // Shortcuts 8135 var thisWords = this.words; 8136 var thatWords = wordArray.words; 8137 var thisSigBytes = this.sigBytes; 8138 var thatSigBytes = wordArray.sigBytes; 8139 8140 // Clamp excess bits 8141 this.clamp(); 8142 8143 // Concat 8144 if (thisSigBytes % 4) { 8145 // Copy one byte at a time 8146 for (var i = 0; i < thatSigBytes; i++) { 8147 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8148 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8149 } 8150 } else { 8151 // Copy one word at a time 8152 for (var i = 0; i < thatSigBytes; i += 4) { 8153 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8154 } 8155 } 8156 this.sigBytes += thatSigBytes; 8157 8158 // Chainable 8159 return this; 8160 }, 8161 8162 /** 8163 * Removes insignificant bits. 8164 * 8165 * @example 8166 * 8167 * wordArray.clamp(); 8168 */ 8169 clamp: function () { 8170 // Shortcuts 8171 var words = this.words; 8172 var sigBytes = this.sigBytes; 8173 8174 // Clamp 8175 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8176 words.length = Math.ceil(sigBytes / 4); 8177 }, 8178 8179 /** 8180 * Creates a copy of this word array. 8181 * 8182 * @return {WordArray} The clone. 8183 * 8184 * @example 8185 * 8186 * var clone = wordArray.clone(); 8187 */ 8188 clone: function () { 8189 var clone = Base.clone.call(this); 8190 clone.words = this.words.slice(0); 8191 8192 return clone; 8193 }, 8194 8195 /** 8196 * Creates a word array filled with random bytes. 8197 * 8198 * @param {number} nBytes The number of random bytes to generate. 8199 * 8200 * @return {WordArray} The random word array. 8201 * 8202 * @static 8203 * 8204 * @example 8205 * 8206 * var wordArray = CryptoJS.lib.WordArray.random(16); 8207 */ 8208 random: function (nBytes) { 8209 var words = []; 8210 8211 var r = (function (m_w) { 8212 var m_w = m_w; 8213 var m_z = 0x3ade68b1; 8214 var mask = 0xffffffff; 8215 8216 return function () { 8217 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8218 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8219 var result = ((m_z << 0x10) + m_w) & mask; 8220 result /= 0x100000000; 8221 result += 0.5; 8222 return result * (Math.random() > .5 ? 1 : -1); 8223 } 8224 }); 8225 8226 for (var i = 0, rcache; i < nBytes; i += 4) { 8227 var _r = r((rcache || Math.random()) * 0x100000000); 8228 8229 rcache = _r() * 0x3ade67b7; 8230 words.push((_r() * 0x100000000) | 0); 8231 } 8232 8233 return new WordArray.init(words, nBytes); 8234 } 8235 }); 8236 8237 /** 8238 * Encoder namespace. 8239 */ 8240 var C_enc = C.enc = {}; 8241 8242 /** 8243 * Hex encoding strategy. 8244 */ 8245 var Hex = C_enc.Hex = { 8246 /** 8247 * Converts a word array to a hex string. 8248 * 8249 * @param {WordArray} wordArray The word array. 8250 * 8251 * @return {string} The hex string. 8252 * 8253 * @static 8254 * 8255 * @example 8256 * 8257 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8258 */ 8259 stringify: function (wordArray) { 8260 // Shortcuts 8261 var words = wordArray.words; 8262 var sigBytes = wordArray.sigBytes; 8263 8264 // Convert 8265 var hexChars = []; 8266 for (var i = 0; i < sigBytes; i++) { 8267 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8268 hexChars.push((bite >>> 4).toString(16)); 8269 hexChars.push((bite & 0x0f).toString(16)); 8270 } 8271 8272 return hexChars.join(''); 8273 }, 8274 8275 /** 8276 * Converts a hex string to a word array. 8277 * 8278 * @param {string} hexStr The hex string. 8279 * 8280 * @return {WordArray} The word array. 8281 * 8282 * @static 8283 * 8284 * @example 8285 * 8286 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8287 */ 8288 parse: function (hexStr) { 8289 // Shortcut 8290 var hexStrLength = hexStr.length; 8291 8292 // Convert 8293 var words = []; 8294 for (var i = 0; i < hexStrLength; i += 2) { 8295 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8296 } 8297 8298 return new WordArray.init(words, hexStrLength / 2); 8299 } 8300 }; 8301 8302 /** 8303 * Latin1 encoding strategy. 8304 */ 8305 var Latin1 = C_enc.Latin1 = { 8306 /** 8307 * Converts a word array to a Latin1 string. 8308 * 8309 * @param {WordArray} wordArray The word array. 8310 * 8311 * @return {string} The Latin1 string. 8312 * 8313 * @static 8314 * 8315 * @example 8316 * 8317 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8318 */ 8319 stringify: function (wordArray) { 8320 // Shortcuts 8321 var words = wordArray.words; 8322 var sigBytes = wordArray.sigBytes; 8323 8324 // Convert 8325 var latin1Chars = []; 8326 for (var i = 0; i < sigBytes; i++) { 8327 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8328 latin1Chars.push(String.fromCharCode(bite)); 8329 } 8330 8331 return latin1Chars.join(''); 8332 }, 8333 8334 /** 8335 * Converts a Latin1 string to a word array. 8336 * 8337 * @param {string} latin1Str The Latin1 string. 8338 * 8339 * @return {WordArray} The word array. 8340 * 8341 * @static 8342 * 8343 * @example 8344 * 8345 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8346 */ 8347 parse: function (latin1Str) { 8348 // Shortcut 8349 var latin1StrLength = latin1Str.length; 8350 8351 // Convert 8352 var words = []; 8353 for (var i = 0; i < latin1StrLength; i++) { 8354 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8355 } 8356 8357 return new WordArray.init(words, latin1StrLength); 8358 } 8359 }; 8360 8361 /** 8362 * UTF-8 encoding strategy. 8363 */ 8364 var Utf8 = C_enc.Utf8 = { 8365 /** 8366 * Converts a word array to a UTF-8 string. 8367 * 8368 * @param {WordArray} wordArray The word array. 8369 * 8370 * @return {string} The UTF-8 string. 8371 * 8372 * @static 8373 * 8374 * @example 8375 * 8376 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8377 */ 8378 stringify: function (wordArray) { 8379 try { 8380 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8381 } catch (e) { 8382 throw new Error('Malformed UTF-8 data'); 8383 } 8384 }, 8385 8386 /** 8387 * Converts a UTF-8 string to a word array. 8388 * 8389 * @param {string} utf8Str The UTF-8 string. 8390 * 8391 * @return {WordArray} The word array. 8392 * 8393 * @static 8394 * 8395 * @example 8396 * 8397 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8398 */ 8399 parse: function (utf8Str) { 8400 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8401 } 8402 }; 8403 8404 /** 8405 * Abstract buffered block algorithm template. 8406 * 8407 * The property blockSize must be implemented in a concrete subtype. 8408 * 8409 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8410 */ 8411 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8412 /** 8413 * Resets this block algorithm's data buffer to its initial state. 8414 * 8415 * @example 8416 * 8417 * bufferedBlockAlgorithm.reset(); 8418 */ 8419 reset: function () { 8420 // Initial values 8421 this._data = new WordArray.init(); 8422 this._nDataBytes = 0; 8423 }, 8424 8425 /** 8426 * Adds new data to this block algorithm's buffer. 8427 * 8428 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8429 * 8430 * @example 8431 * 8432 * bufferedBlockAlgorithm._append('data'); 8433 * bufferedBlockAlgorithm._append(wordArray); 8434 */ 8435 _append: function (data) { 8436 // Convert string to WordArray, else assume WordArray already 8437 if (typeof data == 'string') { 8438 data = Utf8.parse(data); 8439 } 8440 8441 // Append 8442 this._data.concat(data); 8443 this._nDataBytes += data.sigBytes; 8444 }, 8445 8446 /** 8447 * Processes available data blocks. 8448 * 8449 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8450 * 8451 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8452 * 8453 * @return {WordArray} The processed data. 8454 * 8455 * @example 8456 * 8457 * var processedData = bufferedBlockAlgorithm._process(); 8458 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8459 */ 8460 _process: function (doFlush) { 8461 // Shortcuts 8462 var data = this._data; 8463 var dataWords = data.words; 8464 var dataSigBytes = data.sigBytes; 8465 var blockSize = this.blockSize; 8466 var blockSizeBytes = blockSize * 4; 8467 8468 // Count blocks ready 8469 var nBlocksReady = dataSigBytes / blockSizeBytes; 8470 if (doFlush) { 8471 // Round up to include partial blocks 8472 nBlocksReady = Math.ceil(nBlocksReady); 8473 } else { 8474 // Round down to include only full blocks, 8475 // less the number of blocks that must remain in the buffer 8476 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8477 } 8478 8479 // Count words ready 8480 var nWordsReady = nBlocksReady * blockSize; 8481 8482 // Count bytes ready 8483 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8484 8485 // Process blocks 8486 if (nWordsReady) { 8487 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8488 // Perform concrete-algorithm logic 8489 this._doProcessBlock(dataWords, offset); 8490 } 8491 8492 // Remove processed words 8493 var processedWords = dataWords.splice(0, nWordsReady); 8494 data.sigBytes -= nBytesReady; 8495 } 8496 8497 // Return processed words 8498 return new WordArray.init(processedWords, nBytesReady); 8499 }, 8500 8501 /** 8502 * Creates a copy of this object. 8503 * 8504 * @return {Object} The clone. 8505 * 8506 * @example 8507 * 8508 * var clone = bufferedBlockAlgorithm.clone(); 8509 */ 8510 clone: function () { 8511 var clone = Base.clone.call(this); 8512 clone._data = this._data.clone(); 8513 8514 return clone; 8515 }, 8516 8517 _minBufferSize: 0 8518 }); 8519 8520 /** 8521 * Abstract hasher template. 8522 * 8523 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8524 */ 8525 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8526 /** 8527 * Configuration options. 8528 */ 8529 cfg: Base.extend(), 8530 8531 /** 8532 * Initializes a newly created hasher. 8533 * 8534 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8535 * 8536 * @example 8537 * 8538 * var hasher = CryptoJS.algo.SHA256.create(); 8539 */ 8540 init: function (cfg) { 8541 // Apply config defaults 8542 this.cfg = this.cfg.extend(cfg); 8543 8544 // Set initial values 8545 this.reset(); 8546 }, 8547 8548 /** 8549 * Resets this hasher to its initial state. 8550 * 8551 * @example 8552 * 8553 * hasher.reset(); 8554 */ 8555 reset: function () { 8556 // Reset data buffer 8557 BufferedBlockAlgorithm.reset.call(this); 8558 8559 // Perform concrete-hasher logic 8560 this._doReset(); 8561 }, 8562 8563 /** 8564 * Updates this hasher with a message. 8565 * 8566 * @param {WordArray|string} messageUpdate The message to append. 8567 * 8568 * @return {Hasher} This hasher. 8569 * 8570 * @example 8571 * 8572 * hasher.update('message'); 8573 * hasher.update(wordArray); 8574 */ 8575 update: function (messageUpdate) { 8576 // Append 8577 this._append(messageUpdate); 8578 8579 // Update the hash 8580 this._process(); 8581 8582 // Chainable 8583 return this; 8584 }, 8585 8586 /** 8587 * Finalizes the hash computation. 8588 * Note that the finalize operation is effectively a destructive, read-once operation. 8589 * 8590 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8591 * 8592 * @return {WordArray} The hash. 8593 * 8594 * @example 8595 * 8596 * var hash = hasher.finalize(); 8597 * var hash = hasher.finalize('message'); 8598 * var hash = hasher.finalize(wordArray); 8599 */ 8600 finalize: function (messageUpdate) { 8601 // Final message update 8602 if (messageUpdate) { 8603 this._append(messageUpdate); 8604 } 8605 8606 // Perform concrete-hasher logic 8607 var hash = this._doFinalize(); 8608 8609 return hash; 8610 }, 8611 8612 blockSize: 512/32, 8613 8614 /** 8615 * Creates a shortcut function to a hasher's object interface. 8616 * 8617 * @param {Hasher} hasher The hasher to create a helper for. 8618 * 8619 * @return {Function} The shortcut function. 8620 * 8621 * @static 8622 * 8623 * @example 8624 * 8625 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8626 */ 8627 _createHelper: function (hasher) { 8628 return function (message, cfg) { 8629 return new hasher.init(cfg).finalize(message); 8630 }; 8631 }, 8632 8633 /** 8634 * Creates a shortcut function to the HMAC's object interface. 8635 * 8636 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8637 * 8638 * @return {Function} The shortcut function. 8639 * 8640 * @static 8641 * 8642 * @example 8643 * 8644 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8645 */ 8646 _createHmacHelper: function (hasher) { 8647 return function (message, key) { 8648 return new C_algo.HMAC.init(hasher, key).finalize(message); 8649 }; 8650 } 8651 }); 8652 8653 /** 8654 * Algorithm namespace. 8655 */ 8656 var C_algo = C.algo = {}; 8657 8658 return C; 8659 }(Math)); 8660 8661 8662 return CryptoJS; 8663 8664 })); 8665 },{}],54:[function(require,module,exports){ 8666 ;(function (root, factory) { 8667 if (typeof exports === "object") { 8668 // CommonJS 8669 module.exports = exports = factory(require("./core")); 8670 } 8671 else if (typeof define === "function" && define.amd) { 8672 // AMD 8673 define(["./core"], factory); 8674 } 8675 else { 8676 // Global (browser) 8677 factory(root.CryptoJS); 8678 } 8679 }(this, function (CryptoJS) { 8680 8681 (function () { 8682 // Shortcuts 8683 var C = CryptoJS; 8684 var C_lib = C.lib; 8685 var WordArray = C_lib.WordArray; 8686 var C_enc = C.enc; 8687 8688 /** 8689 * Base64 encoding strategy. 8690 */ 8691 var Base64 = C_enc.Base64 = { 8692 /** 8693 * Converts a word array to a Base64 string. 8694 * 8695 * @param {WordArray} wordArray The word array. 8696 * 8697 * @return {string} The Base64 string. 8698 * 8699 * @static 8700 * 8701 * @example 8702 * 8703 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8704 */ 8705 stringify: function (wordArray) { 8706 // Shortcuts 8707 var words = wordArray.words; 8708 var sigBytes = wordArray.sigBytes; 8709 var map = this._map; 8710 8711 // Clamp excess bits 8712 wordArray.clamp(); 8713 8714 // Convert 8715 var base64Chars = []; 8716 for (var i = 0; i < sigBytes; i += 3) { 8717 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8718 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8719 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8720 8721 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8722 8723 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8724 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8725 } 8726 } 8727 8728 // Add padding 8729 var paddingChar = map.charAt(64); 8730 if (paddingChar) { 8731 while (base64Chars.length % 4) { 8732 base64Chars.push(paddingChar); 8733 } 8734 } 8735 8736 return base64Chars.join(''); 8737 }, 8738 8739 /** 8740 * Converts a Base64 string to a word array. 8741 * 8742 * @param {string} base64Str The Base64 string. 8743 * 8744 * @return {WordArray} The word array. 8745 * 8746 * @static 8747 * 8748 * @example 8749 * 8750 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8751 */ 8752 parse: function (base64Str) { 8753 // Shortcuts 8754 var base64StrLength = base64Str.length; 8755 var map = this._map; 8756 var reverseMap = this._reverseMap; 8757 8758 if (!reverseMap) { 8759 reverseMap = this._reverseMap = []; 8760 for (var j = 0; j < map.length; j++) { 8761 reverseMap[map.charCodeAt(j)] = j; 8762 } 8763 } 8764 8765 // Ignore padding 8766 var paddingChar = map.charAt(64); 8767 if (paddingChar) { 8768 var paddingIndex = base64Str.indexOf(paddingChar); 8769 if (paddingIndex !== -1) { 8770 base64StrLength = paddingIndex; 8771 } 8772 } 8773 8774 // Convert 8775 return parseLoop(base64Str, base64StrLength, reverseMap); 8776 8777 }, 8778 8779 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8780 }; 8781 8782 function parseLoop(base64Str, base64StrLength, reverseMap) { 8783 var words = []; 8784 var nBytes = 0; 8785 for (var i = 0; i < base64StrLength; i++) { 8786 if (i % 4) { 8787 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8788 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8789 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8790 nBytes++; 8791 } 8792 } 8793 return WordArray.create(words, nBytes); 8794 } 8795 }()); 8796 8797 8798 return CryptoJS.enc.Base64; 8799 8800 })); 8801 },{"./core":53}],55:[function(require,module,exports){ 8802 ;(function (root, factory) { 8803 if (typeof exports === "object") { 8804 // CommonJS 8805 module.exports = exports = factory(require("./core")); 8806 } 8807 else if (typeof define === "function" && define.amd) { 8808 // AMD 8809 define(["./core"], factory); 8810 } 8811 else { 8812 // Global (browser) 8813 factory(root.CryptoJS); 8814 } 8815 }(this, function (CryptoJS) { 8816 8817 (function () { 8818 // Shortcuts 8819 var C = CryptoJS; 8820 var C_lib = C.lib; 8821 var WordArray = C_lib.WordArray; 8822 var C_enc = C.enc; 8823 8824 /** 8825 * UTF-16 BE encoding strategy. 8826 */ 8827 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8828 /** 8829 * Converts a word array to a UTF-16 BE string. 8830 * 8831 * @param {WordArray} wordArray The word array. 8832 * 8833 * @return {string} The UTF-16 BE string. 8834 * 8835 * @static 8836 * 8837 * @example 8838 * 8839 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8840 */ 8841 stringify: function (wordArray) { 8842 // Shortcuts 8843 var words = wordArray.words; 8844 var sigBytes = wordArray.sigBytes; 8845 8846 // Convert 8847 var utf16Chars = []; 8848 for (var i = 0; i < sigBytes; i += 2) { 8849 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8850 utf16Chars.push(String.fromCharCode(codePoint)); 8851 } 8852 8853 return utf16Chars.join(''); 8854 }, 8855 8856 /** 8857 * Converts a UTF-16 BE string to a word array. 8858 * 8859 * @param {string} utf16Str The UTF-16 BE string. 8860 * 8861 * @return {WordArray} The word array. 8862 * 8863 * @static 8864 * 8865 * @example 8866 * 8867 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8868 */ 8869 parse: function (utf16Str) { 8870 // Shortcut 8871 var utf16StrLength = utf16Str.length; 8872 8873 // Convert 8874 var words = []; 8875 for (var i = 0; i < utf16StrLength; i++) { 8876 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 8877 } 8878 8879 return WordArray.create(words, utf16StrLength * 2); 8880 } 8881 }; 8882 8883 /** 8884 * UTF-16 LE encoding strategy. 8885 */ 8886 C_enc.Utf16LE = { 8887 /** 8888 * Converts a word array to a UTF-16 LE string. 8889 * 8890 * @param {WordArray} wordArray The word array. 8891 * 8892 * @return {string} The UTF-16 LE string. 8893 * 8894 * @static 8895 * 8896 * @example 8897 * 8898 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 8899 */ 8900 stringify: function (wordArray) { 8901 // Shortcuts 8902 var words = wordArray.words; 8903 var sigBytes = wordArray.sigBytes; 8904 8905 // Convert 8906 var utf16Chars = []; 8907 for (var i = 0; i < sigBytes; i += 2) { 8908 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 8909 utf16Chars.push(String.fromCharCode(codePoint)); 8910 } 8911 8912 return utf16Chars.join(''); 8913 }, 8914 8915 /** 8916 * Converts a UTF-16 LE string to a word array. 8917 * 8918 * @param {string} utf16Str The UTF-16 LE string. 8919 * 8920 * @return {WordArray} The word array. 8921 * 8922 * @static 8923 * 8924 * @example 8925 * 8926 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 8927 */ 8928 parse: function (utf16Str) { 8929 // Shortcut 8930 var utf16StrLength = utf16Str.length; 8931 8932 // Convert 8933 var words = []; 8934 for (var i = 0; i < utf16StrLength; i++) { 8935 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 8936 } 8937 8938 return WordArray.create(words, utf16StrLength * 2); 8939 } 8940 }; 8941 8942 function swapEndian(word) { 8943 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 8944 } 8945 }()); 8946 8947 8948 return CryptoJS.enc.Utf16; 8949 8950 })); 8951 },{"./core":53}],56:[function(require,module,exports){ 8952 ;(function (root, factory, undef) { 8953 if (typeof exports === "object") { 8954 // CommonJS 8955 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 8956 } 8957 else if (typeof define === "function" && define.amd) { 8958 // AMD 8959 define(["./core", "./sha1", "./hmac"], factory); 8960 } 8961 else { 8962 // Global (browser) 8963 factory(root.CryptoJS); 8964 } 8965 }(this, function (CryptoJS) { 8966 8967 (function () { 8968 // Shortcuts 8969 var C = CryptoJS; 8970 var C_lib = C.lib; 8971 var Base = C_lib.Base; 8972 var WordArray = C_lib.WordArray; 8973 var C_algo = C.algo; 8974 var MD5 = C_algo.MD5; 8975 8976 /** 8977 * This key derivation function is meant to conform with EVP_BytesToKey. 8978 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 8979 */ 8980 var EvpKDF = C_algo.EvpKDF = Base.extend({ 8981 /** 8982 * Configuration options. 8983 * 8984 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 8985 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 8986 * @property {number} iterations The number of iterations to perform. Default: 1 8987 */ 8988 cfg: Base.extend({ 8989 keySize: 128/32, 8990 hasher: MD5, 8991 iterations: 1 8992 }), 8993 8994 /** 8995 * Initializes a newly created key derivation function. 8996 * 8997 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 8998 * 8999 * @example 9000 * 9001 * var kdf = CryptoJS.algo.EvpKDF.create(); 9002 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9003 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9004 */ 9005 init: function (cfg) { 9006 this.cfg = this.cfg.extend(cfg); 9007 }, 9008 9009 /** 9010 * Derives a key from a password. 9011 * 9012 * @param {WordArray|string} password The password. 9013 * @param {WordArray|string} salt A salt. 9014 * 9015 * @return {WordArray} The derived key. 9016 * 9017 * @example 9018 * 9019 * var key = kdf.compute(password, salt); 9020 */ 9021 compute: function (password, salt) { 9022 // Shortcut 9023 var cfg = this.cfg; 9024 9025 // Init hasher 9026 var hasher = cfg.hasher.create(); 9027 9028 // Initial values 9029 var derivedKey = WordArray.create(); 9030 9031 // Shortcuts 9032 var derivedKeyWords = derivedKey.words; 9033 var keySize = cfg.keySize; 9034 var iterations = cfg.iterations; 9035 9036 // Generate key 9037 while (derivedKeyWords.length < keySize) { 9038 if (block) { 9039 hasher.update(block); 9040 } 9041 var block = hasher.update(password).finalize(salt); 9042 hasher.reset(); 9043 9044 // Iterations 9045 for (var i = 1; i < iterations; i++) { 9046 block = hasher.finalize(block); 9047 hasher.reset(); 9048 } 9049 9050 derivedKey.concat(block); 9051 } 9052 derivedKey.sigBytes = keySize * 4; 9053 9054 return derivedKey; 9055 } 9056 }); 9057 9058 /** 9059 * Derives a key from a password. 9060 * 9061 * @param {WordArray|string} password The password. 9062 * @param {WordArray|string} salt A salt. 9063 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9064 * 9065 * @return {WordArray} The derived key. 9066 * 9067 * @static 9068 * 9069 * @example 9070 * 9071 * var key = CryptoJS.EvpKDF(password, salt); 9072 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9073 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9074 */ 9075 C.EvpKDF = function (password, salt, cfg) { 9076 return EvpKDF.create(cfg).compute(password, salt); 9077 }; 9078 }()); 9079 9080 9081 return CryptoJS.EvpKDF; 9082 9083 })); 9084 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 9085 ;(function (root, factory, undef) { 9086 if (typeof exports === "object") { 9087 // CommonJS 9088 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9089 } 9090 else if (typeof define === "function" && define.amd) { 9091 // AMD 9092 define(["./core", "./cipher-core"], factory); 9093 } 9094 else { 9095 // Global (browser) 9096 factory(root.CryptoJS); 9097 } 9098 }(this, function (CryptoJS) { 9099 9100 (function (undefined) { 9101 // Shortcuts 9102 var C = CryptoJS; 9103 var C_lib = C.lib; 9104 var CipherParams = C_lib.CipherParams; 9105 var C_enc = C.enc; 9106 var Hex = C_enc.Hex; 9107 var C_format = C.format; 9108 9109 var HexFormatter = C_format.Hex = { 9110 /** 9111 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9112 * 9113 * @param {CipherParams} cipherParams The cipher params object. 9114 * 9115 * @return {string} The hexadecimally encoded string. 9116 * 9117 * @static 9118 * 9119 * @example 9120 * 9121 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9122 */ 9123 stringify: function (cipherParams) { 9124 return cipherParams.ciphertext.toString(Hex); 9125 }, 9126 9127 /** 9128 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9129 * 9130 * @param {string} input The hexadecimally encoded string. 9131 * 9132 * @return {CipherParams} The cipher params object. 9133 * 9134 * @static 9135 * 9136 * @example 9137 * 9138 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9139 */ 9140 parse: function (input) { 9141 var ciphertext = Hex.parse(input); 9142 return CipherParams.create({ ciphertext: ciphertext }); 9143 } 9144 }; 9145 }()); 9146 9147 9148 return CryptoJS.format.Hex; 9149 9150 })); 9151 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 9152 ;(function (root, factory) { 9153 if (typeof exports === "object") { 9154 // CommonJS 9155 module.exports = exports = factory(require("./core")); 9156 } 9157 else if (typeof define === "function" && define.amd) { 9158 // AMD 9159 define(["./core"], factory); 9160 } 9161 else { 9162 // Global (browser) 9163 factory(root.CryptoJS); 9164 } 9165 }(this, function (CryptoJS) { 9166 9167 (function () { 9168 // Shortcuts 9169 var C = CryptoJS; 9170 var C_lib = C.lib; 9171 var Base = C_lib.Base; 9172 var C_enc = C.enc; 9173 var Utf8 = C_enc.Utf8; 9174 var C_algo = C.algo; 9175 9176 /** 9177 * HMAC algorithm. 9178 */ 9179 var HMAC = C_algo.HMAC = Base.extend({ 9180 /** 9181 * Initializes a newly created HMAC. 9182 * 9183 * @param {Hasher} hasher The hash algorithm to use. 9184 * @param {WordArray|string} key The secret key. 9185 * 9186 * @example 9187 * 9188 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9189 */ 9190 init: function (hasher, key) { 9191 // Init hasher 9192 hasher = this._hasher = new hasher.init(); 9193 9194 // Convert string to WordArray, else assume WordArray already 9195 if (typeof key == 'string') { 9196 key = Utf8.parse(key); 9197 } 9198 9199 // Shortcuts 9200 var hasherBlockSize = hasher.blockSize; 9201 var hasherBlockSizeBytes = hasherBlockSize * 4; 9202 9203 // Allow arbitrary length keys 9204 if (key.sigBytes > hasherBlockSizeBytes) { 9205 key = hasher.finalize(key); 9206 } 9207 9208 // Clamp excess bits 9209 key.clamp(); 9210 9211 // Clone key for inner and outer pads 9212 var oKey = this._oKey = key.clone(); 9213 var iKey = this._iKey = key.clone(); 9214 9215 // Shortcuts 9216 var oKeyWords = oKey.words; 9217 var iKeyWords = iKey.words; 9218 9219 // XOR keys with pad constants 9220 for (var i = 0; i < hasherBlockSize; i++) { 9221 oKeyWords[i] ^= 0x5c5c5c5c; 9222 iKeyWords[i] ^= 0x36363636; 9223 } 9224 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9225 9226 // Set initial values 9227 this.reset(); 9228 }, 9229 9230 /** 9231 * Resets this HMAC to its initial state. 9232 * 9233 * @example 9234 * 9235 * hmacHasher.reset(); 9236 */ 9237 reset: function () { 9238 // Shortcut 9239 var hasher = this._hasher; 9240 9241 // Reset 9242 hasher.reset(); 9243 hasher.update(this._iKey); 9244 }, 9245 9246 /** 9247 * Updates this HMAC with a message. 9248 * 9249 * @param {WordArray|string} messageUpdate The message to append. 9250 * 9251 * @return {HMAC} This HMAC instance. 9252 * 9253 * @example 9254 * 9255 * hmacHasher.update('message'); 9256 * hmacHasher.update(wordArray); 9257 */ 9258 update: function (messageUpdate) { 9259 this._hasher.update(messageUpdate); 9260 9261 // Chainable 9262 return this; 9263 }, 9264 9265 /** 9266 * Finalizes the HMAC computation. 9267 * Note that the finalize operation is effectively a destructive, read-once operation. 9268 * 9269 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9270 * 9271 * @return {WordArray} The HMAC. 9272 * 9273 * @example 9274 * 9275 * var hmac = hmacHasher.finalize(); 9276 * var hmac = hmacHasher.finalize('message'); 9277 * var hmac = hmacHasher.finalize(wordArray); 9278 */ 9279 finalize: function (messageUpdate) { 9280 // Shortcut 9281 var hasher = this._hasher; 9282 9283 // Compute HMAC 9284 var innerHash = hasher.finalize(messageUpdate); 9285 hasher.reset(); 9286 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9287 9288 return hmac; 9289 } 9290 }); 9291 }()); 9292 9293 9294 })); 9295 },{"./core":53}],59:[function(require,module,exports){ 9296 ;(function (root, factory, undef) { 9297 if (typeof exports === "object") { 9298 // CommonJS 9299 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")); 9300 } 9301 else if (typeof define === "function" && define.amd) { 9302 // AMD 9303 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); 9304 } 9305 else { 9306 // Global (browser) 9307 root.CryptoJS = factory(root.CryptoJS); 9308 } 9309 }(this, function (CryptoJS) { 9310 9311 return CryptoJS; 9312 9313 })); 9314 },{"./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){ 9315 ;(function (root, factory) { 9316 if (typeof exports === "object") { 9317 // CommonJS 9318 module.exports = exports = factory(require("./core")); 9319 } 9320 else if (typeof define === "function" && define.amd) { 9321 // AMD 9322 define(["./core"], factory); 9323 } 9324 else { 9325 // Global (browser) 9326 factory(root.CryptoJS); 9327 } 9328 }(this, function (CryptoJS) { 9329 9330 (function () { 9331 // Check if typed arrays are supported 9332 if (typeof ArrayBuffer != 'function') { 9333 return; 9334 } 9335 9336 // Shortcuts 9337 var C = CryptoJS; 9338 var C_lib = C.lib; 9339 var WordArray = C_lib.WordArray; 9340 9341 // Reference original init 9342 var superInit = WordArray.init; 9343 9344 // Augment WordArray.init to handle typed arrays 9345 var subInit = WordArray.init = function (typedArray) { 9346 // Convert buffers to uint8 9347 if (typedArray instanceof ArrayBuffer) { 9348 typedArray = new Uint8Array(typedArray); 9349 } 9350 9351 // Convert other array views to uint8 9352 if ( 9353 typedArray instanceof Int8Array || 9354 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9355 typedArray instanceof Int16Array || 9356 typedArray instanceof Uint16Array || 9357 typedArray instanceof Int32Array || 9358 typedArray instanceof Uint32Array || 9359 typedArray instanceof Float32Array || 9360 typedArray instanceof Float64Array 9361 ) { 9362 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9363 } 9364 9365 // Handle Uint8Array 9366 if (typedArray instanceof Uint8Array) { 9367 // Shortcut 9368 var typedArrayByteLength = typedArray.byteLength; 9369 9370 // Extract bytes 9371 var words = []; 9372 for (var i = 0; i < typedArrayByteLength; i++) { 9373 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9374 } 9375 9376 // Initialize this word array 9377 superInit.call(this, words, typedArrayByteLength); 9378 } else { 9379 // Else call normal init 9380 superInit.apply(this, arguments); 9381 } 9382 }; 9383 9384 subInit.prototype = WordArray; 9385 }()); 9386 9387 9388 return CryptoJS.lib.WordArray; 9389 9390 })); 9391 },{"./core":53}],61:[function(require,module,exports){ 9392 ;(function (root, factory) { 9393 if (typeof exports === "object") { 9394 // CommonJS 9395 module.exports = exports = factory(require("./core")); 9396 } 9397 else if (typeof define === "function" && define.amd) { 9398 // AMD 9399 define(["./core"], factory); 9400 } 9401 else { 9402 // Global (browser) 9403 factory(root.CryptoJS); 9404 } 9405 }(this, function (CryptoJS) { 9406 9407 (function (Math) { 9408 // Shortcuts 9409 var C = CryptoJS; 9410 var C_lib = C.lib; 9411 var WordArray = C_lib.WordArray; 9412 var Hasher = C_lib.Hasher; 9413 var C_algo = C.algo; 9414 9415 // Constants table 9416 var T = []; 9417 9418 // Compute constants 9419 (function () { 9420 for (var i = 0; i < 64; i++) { 9421 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9422 } 9423 }()); 9424 9425 /** 9426 * MD5 hash algorithm. 9427 */ 9428 var MD5 = C_algo.MD5 = Hasher.extend({ 9429 _doReset: function () { 9430 this._hash = new WordArray.init([ 9431 0x67452301, 0xefcdab89, 9432 0x98badcfe, 0x10325476 9433 ]); 9434 }, 9435 9436 _doProcessBlock: function (M, offset) { 9437 // Swap endian 9438 for (var i = 0; i < 16; i++) { 9439 // Shortcuts 9440 var offset_i = offset + i; 9441 var M_offset_i = M[offset_i]; 9442 9443 M[offset_i] = ( 9444 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9445 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9446 ); 9447 } 9448 9449 // Shortcuts 9450 var H = this._hash.words; 9451 9452 var M_offset_0 = M[offset + 0]; 9453 var M_offset_1 = M[offset + 1]; 9454 var M_offset_2 = M[offset + 2]; 9455 var M_offset_3 = M[offset + 3]; 9456 var M_offset_4 = M[offset + 4]; 9457 var M_offset_5 = M[offset + 5]; 9458 var M_offset_6 = M[offset + 6]; 9459 var M_offset_7 = M[offset + 7]; 9460 var M_offset_8 = M[offset + 8]; 9461 var M_offset_9 = M[offset + 9]; 9462 var M_offset_10 = M[offset + 10]; 9463 var M_offset_11 = M[offset + 11]; 9464 var M_offset_12 = M[offset + 12]; 9465 var M_offset_13 = M[offset + 13]; 9466 var M_offset_14 = M[offset + 14]; 9467 var M_offset_15 = M[offset + 15]; 9468 9469 // Working varialbes 9470 var a = H[0]; 9471 var b = H[1]; 9472 var c = H[2]; 9473 var d = H[3]; 9474 9475 // Computation 9476 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9477 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9478 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9479 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9480 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9481 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9482 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9483 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9484 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9485 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9486 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9487 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9488 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9489 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9490 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9491 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9492 9493 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9494 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9495 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9496 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9497 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9498 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9499 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9500 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9501 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9502 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9503 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9504 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9505 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9506 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9507 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9508 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9509 9510 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9511 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9512 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9513 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9514 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9515 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9516 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9517 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9518 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9519 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9520 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9521 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9522 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9523 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9524 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9525 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9526 9527 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9528 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9529 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9530 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9531 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9532 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9533 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9534 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9535 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9536 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9537 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9538 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9539 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9540 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9541 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9542 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9543 9544 // Intermediate hash value 9545 H[0] = (H[0] + a) | 0; 9546 H[1] = (H[1] + b) | 0; 9547 H[2] = (H[2] + c) | 0; 9548 H[3] = (H[3] + d) | 0; 9549 }, 9550 9551 _doFinalize: function () { 9552 // Shortcuts 9553 var data = this._data; 9554 var dataWords = data.words; 9555 9556 var nBitsTotal = this._nDataBytes * 8; 9557 var nBitsLeft = data.sigBytes * 8; 9558 9559 // Add padding 9560 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9561 9562 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9563 var nBitsTotalL = nBitsTotal; 9564 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9565 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9566 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9567 ); 9568 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9569 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9570 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9571 ); 9572 9573 data.sigBytes = (dataWords.length + 1) * 4; 9574 9575 // Hash final blocks 9576 this._process(); 9577 9578 // Shortcuts 9579 var hash = this._hash; 9580 var H = hash.words; 9581 9582 // Swap endian 9583 for (var i = 0; i < 4; i++) { 9584 // Shortcut 9585 var H_i = H[i]; 9586 9587 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9588 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9589 } 9590 9591 // Return final computed hash 9592 return hash; 9593 }, 9594 9595 clone: function () { 9596 var clone = Hasher.clone.call(this); 9597 clone._hash = this._hash.clone(); 9598 9599 return clone; 9600 } 9601 }); 9602 9603 function FF(a, b, c, d, x, s, t) { 9604 var n = a + ((b & c) | (~b & d)) + x + t; 9605 return ((n << s) | (n >>> (32 - s))) + b; 9606 } 9607 9608 function GG(a, b, c, d, x, s, t) { 9609 var n = a + ((b & d) | (c & ~d)) + x + t; 9610 return ((n << s) | (n >>> (32 - s))) + b; 9611 } 9612 9613 function HH(a, b, c, d, x, s, t) { 9614 var n = a + (b ^ c ^ d) + x + t; 9615 return ((n << s) | (n >>> (32 - s))) + b; 9616 } 9617 9618 function II(a, b, c, d, x, s, t) { 9619 var n = a + (c ^ (b | ~d)) + x + t; 9620 return ((n << s) | (n >>> (32 - s))) + b; 9621 } 9622 9623 /** 9624 * Shortcut function to the hasher's object interface. 9625 * 9626 * @param {WordArray|string} message The message to hash. 9627 * 9628 * @return {WordArray} The hash. 9629 * 9630 * @static 9631 * 9632 * @example 9633 * 9634 * var hash = CryptoJS.MD5('message'); 9635 * var hash = CryptoJS.MD5(wordArray); 9636 */ 9637 C.MD5 = Hasher._createHelper(MD5); 9638 9639 /** 9640 * Shortcut function to the HMAC's object interface. 9641 * 9642 * @param {WordArray|string} message The message to hash. 9643 * @param {WordArray|string} key The secret key. 9644 * 9645 * @return {WordArray} The HMAC. 9646 * 9647 * @static 9648 * 9649 * @example 9650 * 9651 * var hmac = CryptoJS.HmacMD5(message, key); 9652 */ 9653 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9654 }(Math)); 9655 9656 9657 return CryptoJS.MD5; 9658 9659 })); 9660 },{"./core":53}],62:[function(require,module,exports){ 9661 ;(function (root, factory, undef) { 9662 if (typeof exports === "object") { 9663 // CommonJS 9664 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9665 } 9666 else if (typeof define === "function" && define.amd) { 9667 // AMD 9668 define(["./core", "./cipher-core"], factory); 9669 } 9670 else { 9671 // Global (browser) 9672 factory(root.CryptoJS); 9673 } 9674 }(this, function (CryptoJS) { 9675 9676 /** 9677 * Cipher Feedback block mode. 9678 */ 9679 CryptoJS.mode.CFB = (function () { 9680 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9681 9682 CFB.Encryptor = CFB.extend({ 9683 processBlock: function (words, offset) { 9684 // Shortcuts 9685 var cipher = this._cipher; 9686 var blockSize = cipher.blockSize; 9687 9688 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9689 9690 // Remember this block to use with next block 9691 this._prevBlock = words.slice(offset, offset + blockSize); 9692 } 9693 }); 9694 9695 CFB.Decryptor = CFB.extend({ 9696 processBlock: function (words, offset) { 9697 // Shortcuts 9698 var cipher = this._cipher; 9699 var blockSize = cipher.blockSize; 9700 9701 // Remember this block to use with next block 9702 var thisBlock = words.slice(offset, offset + blockSize); 9703 9704 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9705 9706 // This block becomes the previous block 9707 this._prevBlock = thisBlock; 9708 } 9709 }); 9710 9711 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9712 // Shortcut 9713 var iv = this._iv; 9714 9715 // Generate keystream 9716 if (iv) { 9717 var keystream = iv.slice(0); 9718 9719 // Remove IV for subsequent blocks 9720 this._iv = undefined; 9721 } else { 9722 var keystream = this._prevBlock; 9723 } 9724 cipher.encryptBlock(keystream, 0); 9725 9726 // Encrypt 9727 for (var i = 0; i < blockSize; i++) { 9728 words[offset + i] ^= keystream[i]; 9729 } 9730 } 9731 9732 return CFB; 9733 }()); 9734 9735 9736 return CryptoJS.mode.CFB; 9737 9738 })); 9739 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 9740 ;(function (root, factory, undef) { 9741 if (typeof exports === "object") { 9742 // CommonJS 9743 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9744 } 9745 else if (typeof define === "function" && define.amd) { 9746 // AMD 9747 define(["./core", "./cipher-core"], factory); 9748 } 9749 else { 9750 // Global (browser) 9751 factory(root.CryptoJS); 9752 } 9753 }(this, function (CryptoJS) { 9754 9755 /** @preserve 9756 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9757 * derived from CryptoJS.mode.CTR 9758 * Jan Hruby jhruby.web@gmail.com 9759 */ 9760 CryptoJS.mode.CTRGladman = (function () { 9761 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9762 9763 function incWord(word) 9764 { 9765 if (((word >> 24) & 0xff) === 0xff) { //overflow 9766 var b1 = (word >> 16)&0xff; 9767 var b2 = (word >> 8)&0xff; 9768 var b3 = word & 0xff; 9769 9770 if (b1 === 0xff) // overflow b1 9771 { 9772 b1 = 0; 9773 if (b2 === 0xff) 9774 { 9775 b2 = 0; 9776 if (b3 === 0xff) 9777 { 9778 b3 = 0; 9779 } 9780 else 9781 { 9782 ++b3; 9783 } 9784 } 9785 else 9786 { 9787 ++b2; 9788 } 9789 } 9790 else 9791 { 9792 ++b1; 9793 } 9794 9795 word = 0; 9796 word += (b1 << 16); 9797 word += (b2 << 8); 9798 word += b3; 9799 } 9800 else 9801 { 9802 word += (0x01 << 24); 9803 } 9804 return word; 9805 } 9806 9807 function incCounter(counter) 9808 { 9809 if ((counter[0] = incWord(counter[0])) === 0) 9810 { 9811 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9812 counter[1] = incWord(counter[1]); 9813 } 9814 return counter; 9815 } 9816 9817 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9818 processBlock: function (words, offset) { 9819 // Shortcuts 9820 var cipher = this._cipher 9821 var blockSize = cipher.blockSize; 9822 var iv = this._iv; 9823 var counter = this._counter; 9824 9825 // Generate keystream 9826 if (iv) { 9827 counter = this._counter = iv.slice(0); 9828 9829 // Remove IV for subsequent blocks 9830 this._iv = undefined; 9831 } 9832 9833 incCounter(counter); 9834 9835 var keystream = counter.slice(0); 9836 cipher.encryptBlock(keystream, 0); 9837 9838 // Encrypt 9839 for (var i = 0; i < blockSize; i++) { 9840 words[offset + i] ^= keystream[i]; 9841 } 9842 } 9843 }); 9844 9845 CTRGladman.Decryptor = Encryptor; 9846 9847 return CTRGladman; 9848 }()); 9849 9850 9851 9852 9853 return CryptoJS.mode.CTRGladman; 9854 9855 })); 9856 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 9857 ;(function (root, factory, undef) { 9858 if (typeof exports === "object") { 9859 // CommonJS 9860 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9861 } 9862 else if (typeof define === "function" && define.amd) { 9863 // AMD 9864 define(["./core", "./cipher-core"], factory); 9865 } 9866 else { 9867 // Global (browser) 9868 factory(root.CryptoJS); 9869 } 9870 }(this, function (CryptoJS) { 9871 9872 /** 9873 * Counter block mode. 9874 */ 9875 CryptoJS.mode.CTR = (function () { 9876 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 9877 9878 var Encryptor = CTR.Encryptor = CTR.extend({ 9879 processBlock: function (words, offset) { 9880 // Shortcuts 9881 var cipher = this._cipher 9882 var blockSize = cipher.blockSize; 9883 var iv = this._iv; 9884 var counter = this._counter; 9885 9886 // Generate keystream 9887 if (iv) { 9888 counter = this._counter = iv.slice(0); 9889 9890 // Remove IV for subsequent blocks 9891 this._iv = undefined; 9892 } 9893 var keystream = counter.slice(0); 9894 cipher.encryptBlock(keystream, 0); 9895 9896 // Increment counter 9897 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 9898 9899 // Encrypt 9900 for (var i = 0; i < blockSize; i++) { 9901 words[offset + i] ^= keystream[i]; 9902 } 9903 } 9904 }); 9905 9906 CTR.Decryptor = Encryptor; 9907 9908 return CTR; 9909 }()); 9910 9911 9912 return CryptoJS.mode.CTR; 9913 9914 })); 9915 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 9916 ;(function (root, factory, undef) { 9917 if (typeof exports === "object") { 9918 // CommonJS 9919 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9920 } 9921 else if (typeof define === "function" && define.amd) { 9922 // AMD 9923 define(["./core", "./cipher-core"], factory); 9924 } 9925 else { 9926 // Global (browser) 9927 factory(root.CryptoJS); 9928 } 9929 }(this, function (CryptoJS) { 9930 9931 /** 9932 * Electronic Codebook block mode. 9933 */ 9934 CryptoJS.mode.ECB = (function () { 9935 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 9936 9937 ECB.Encryptor = ECB.extend({ 9938 processBlock: function (words, offset) { 9939 this._cipher.encryptBlock(words, offset); 9940 } 9941 }); 9942 9943 ECB.Decryptor = ECB.extend({ 9944 processBlock: function (words, offset) { 9945 this._cipher.decryptBlock(words, offset); 9946 } 9947 }); 9948 9949 return ECB; 9950 }()); 9951 9952 9953 return CryptoJS.mode.ECB; 9954 9955 })); 9956 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 9957 ;(function (root, factory, undef) { 9958 if (typeof exports === "object") { 9959 // CommonJS 9960 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9961 } 9962 else if (typeof define === "function" && define.amd) { 9963 // AMD 9964 define(["./core", "./cipher-core"], factory); 9965 } 9966 else { 9967 // Global (browser) 9968 factory(root.CryptoJS); 9969 } 9970 }(this, function (CryptoJS) { 9971 9972 /** 9973 * Output Feedback block mode. 9974 */ 9975 CryptoJS.mode.OFB = (function () { 9976 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 9977 9978 var Encryptor = OFB.Encryptor = OFB.extend({ 9979 processBlock: function (words, offset) { 9980 // Shortcuts 9981 var cipher = this._cipher 9982 var blockSize = cipher.blockSize; 9983 var iv = this._iv; 9984 var keystream = this._keystream; 9985 9986 // Generate keystream 9987 if (iv) { 9988 keystream = this._keystream = iv.slice(0); 9989 9990 // Remove IV for subsequent blocks 9991 this._iv = undefined; 9992 } 9993 cipher.encryptBlock(keystream, 0); 9994 9995 // Encrypt 9996 for (var i = 0; i < blockSize; i++) { 9997 words[offset + i] ^= keystream[i]; 9998 } 9999 } 10000 }); 10001 10002 OFB.Decryptor = Encryptor; 10003 10004 return OFB; 10005 }()); 10006 10007 10008 return CryptoJS.mode.OFB; 10009 10010 })); 10011 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 10012 ;(function (root, factory, undef) { 10013 if (typeof exports === "object") { 10014 // CommonJS 10015 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10016 } 10017 else if (typeof define === "function" && define.amd) { 10018 // AMD 10019 define(["./core", "./cipher-core"], factory); 10020 } 10021 else { 10022 // Global (browser) 10023 factory(root.CryptoJS); 10024 } 10025 }(this, function (CryptoJS) { 10026 10027 /** 10028 * ANSI X.923 padding strategy. 10029 */ 10030 CryptoJS.pad.AnsiX923 = { 10031 pad: function (data, blockSize) { 10032 // Shortcuts 10033 var dataSigBytes = data.sigBytes; 10034 var blockSizeBytes = blockSize * 4; 10035 10036 // Count padding bytes 10037 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10038 10039 // Compute last byte position 10040 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10041 10042 // Pad 10043 data.clamp(); 10044 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10045 data.sigBytes += nPaddingBytes; 10046 }, 10047 10048 unpad: function (data) { 10049 // Get number of padding bytes from last byte 10050 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10051 10052 // Remove padding 10053 data.sigBytes -= nPaddingBytes; 10054 } 10055 }; 10056 10057 10058 return CryptoJS.pad.Ansix923; 10059 10060 })); 10061 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 10062 ;(function (root, factory, undef) { 10063 if (typeof exports === "object") { 10064 // CommonJS 10065 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10066 } 10067 else if (typeof define === "function" && define.amd) { 10068 // AMD 10069 define(["./core", "./cipher-core"], factory); 10070 } 10071 else { 10072 // Global (browser) 10073 factory(root.CryptoJS); 10074 } 10075 }(this, function (CryptoJS) { 10076 10077 /** 10078 * ISO 10126 padding strategy. 10079 */ 10080 CryptoJS.pad.Iso10126 = { 10081 pad: function (data, blockSize) { 10082 // Shortcut 10083 var blockSizeBytes = blockSize * 4; 10084 10085 // Count padding bytes 10086 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10087 10088 // Pad 10089 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10090 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10091 }, 10092 10093 unpad: function (data) { 10094 // Get number of padding bytes from last byte 10095 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10096 10097 // Remove padding 10098 data.sigBytes -= nPaddingBytes; 10099 } 10100 }; 10101 10102 10103 return CryptoJS.pad.Iso10126; 10104 10105 })); 10106 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 10107 ;(function (root, factory, undef) { 10108 if (typeof exports === "object") { 10109 // CommonJS 10110 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10111 } 10112 else if (typeof define === "function" && define.amd) { 10113 // AMD 10114 define(["./core", "./cipher-core"], factory); 10115 } 10116 else { 10117 // Global (browser) 10118 factory(root.CryptoJS); 10119 } 10120 }(this, function (CryptoJS) { 10121 10122 /** 10123 * ISO/IEC 9797-1 Padding Method 2. 10124 */ 10125 CryptoJS.pad.Iso97971 = { 10126 pad: function (data, blockSize) { 10127 // Add 0x80 byte 10128 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10129 10130 // Zero pad the rest 10131 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10132 }, 10133 10134 unpad: function (data) { 10135 // Remove zero padding 10136 CryptoJS.pad.ZeroPadding.unpad(data); 10137 10138 // Remove one more byte -- the 0x80 byte 10139 data.sigBytes--; 10140 } 10141 }; 10142 10143 10144 return CryptoJS.pad.Iso97971; 10145 10146 })); 10147 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 10148 ;(function (root, factory, undef) { 10149 if (typeof exports === "object") { 10150 // CommonJS 10151 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10152 } 10153 else if (typeof define === "function" && define.amd) { 10154 // AMD 10155 define(["./core", "./cipher-core"], factory); 10156 } 10157 else { 10158 // Global (browser) 10159 factory(root.CryptoJS); 10160 } 10161 }(this, function (CryptoJS) { 10162 10163 /** 10164 * A noop padding strategy. 10165 */ 10166 CryptoJS.pad.NoPadding = { 10167 pad: function () { 10168 }, 10169 10170 unpad: function () { 10171 } 10172 }; 10173 10174 10175 return CryptoJS.pad.NoPadding; 10176 10177 })); 10178 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 10179 ;(function (root, factory, undef) { 10180 if (typeof exports === "object") { 10181 // CommonJS 10182 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10183 } 10184 else if (typeof define === "function" && define.amd) { 10185 // AMD 10186 define(["./core", "./cipher-core"], factory); 10187 } 10188 else { 10189 // Global (browser) 10190 factory(root.CryptoJS); 10191 } 10192 }(this, function (CryptoJS) { 10193 10194 /** 10195 * Zero padding strategy. 10196 */ 10197 CryptoJS.pad.ZeroPadding = { 10198 pad: function (data, blockSize) { 10199 // Shortcut 10200 var blockSizeBytes = blockSize * 4; 10201 10202 // Pad 10203 data.clamp(); 10204 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10205 }, 10206 10207 unpad: function (data) { 10208 // Shortcut 10209 var dataWords = data.words; 10210 10211 // Unpad 10212 var i = data.sigBytes - 1; 10213 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10214 i--; 10215 } 10216 data.sigBytes = i + 1; 10217 } 10218 }; 10219 10220 10221 return CryptoJS.pad.ZeroPadding; 10222 10223 })); 10224 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 10225 ;(function (root, factory, undef) { 10226 if (typeof exports === "object") { 10227 // CommonJS 10228 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10229 } 10230 else if (typeof define === "function" && define.amd) { 10231 // AMD 10232 define(["./core", "./sha1", "./hmac"], factory); 10233 } 10234 else { 10235 // Global (browser) 10236 factory(root.CryptoJS); 10237 } 10238 }(this, function (CryptoJS) { 10239 10240 (function () { 10241 // Shortcuts 10242 var C = CryptoJS; 10243 var C_lib = C.lib; 10244 var Base = C_lib.Base; 10245 var WordArray = C_lib.WordArray; 10246 var C_algo = C.algo; 10247 var SHA1 = C_algo.SHA1; 10248 var HMAC = C_algo.HMAC; 10249 10250 /** 10251 * Password-Based Key Derivation Function 2 algorithm. 10252 */ 10253 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10254 /** 10255 * Configuration options. 10256 * 10257 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10258 * @property {Hasher} hasher The hasher to use. Default: SHA1 10259 * @property {number} iterations The number of iterations to perform. Default: 1 10260 */ 10261 cfg: Base.extend({ 10262 keySize: 128/32, 10263 hasher: SHA1, 10264 iterations: 1 10265 }), 10266 10267 /** 10268 * Initializes a newly created key derivation function. 10269 * 10270 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10271 * 10272 * @example 10273 * 10274 * var kdf = CryptoJS.algo.PBKDF2.create(); 10275 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10276 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10277 */ 10278 init: function (cfg) { 10279 this.cfg = this.cfg.extend(cfg); 10280 }, 10281 10282 /** 10283 * Computes the Password-Based Key Derivation Function 2. 10284 * 10285 * @param {WordArray|string} password The password. 10286 * @param {WordArray|string} salt A salt. 10287 * 10288 * @return {WordArray} The derived key. 10289 * 10290 * @example 10291 * 10292 * var key = kdf.compute(password, salt); 10293 */ 10294 compute: function (password, salt) { 10295 // Shortcut 10296 var cfg = this.cfg; 10297 10298 // Init HMAC 10299 var hmac = HMAC.create(cfg.hasher, password); 10300 10301 // Initial values 10302 var derivedKey = WordArray.create(); 10303 var blockIndex = WordArray.create([0x00000001]); 10304 10305 // Shortcuts 10306 var derivedKeyWords = derivedKey.words; 10307 var blockIndexWords = blockIndex.words; 10308 var keySize = cfg.keySize; 10309 var iterations = cfg.iterations; 10310 10311 // Generate key 10312 while (derivedKeyWords.length < keySize) { 10313 var block = hmac.update(salt).finalize(blockIndex); 10314 hmac.reset(); 10315 10316 // Shortcuts 10317 var blockWords = block.words; 10318 var blockWordsLength = blockWords.length; 10319 10320 // Iterations 10321 var intermediate = block; 10322 for (var i = 1; i < iterations; i++) { 10323 intermediate = hmac.finalize(intermediate); 10324 hmac.reset(); 10325 10326 // Shortcut 10327 var intermediateWords = intermediate.words; 10328 10329 // XOR intermediate with block 10330 for (var j = 0; j < blockWordsLength; j++) { 10331 blockWords[j] ^= intermediateWords[j]; 10332 } 10333 } 10334 10335 derivedKey.concat(block); 10336 blockIndexWords[0]++; 10337 } 10338 derivedKey.sigBytes = keySize * 4; 10339 10340 return derivedKey; 10341 } 10342 }); 10343 10344 /** 10345 * Computes the Password-Based Key Derivation Function 2. 10346 * 10347 * @param {WordArray|string} password The password. 10348 * @param {WordArray|string} salt A salt. 10349 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10350 * 10351 * @return {WordArray} The derived key. 10352 * 10353 * @static 10354 * 10355 * @example 10356 * 10357 * var key = CryptoJS.PBKDF2(password, salt); 10358 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10359 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10360 */ 10361 C.PBKDF2 = function (password, salt, cfg) { 10362 return PBKDF2.create(cfg).compute(password, salt); 10363 }; 10364 }()); 10365 10366 10367 return CryptoJS.PBKDF2; 10368 10369 })); 10370 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 10371 ;(function (root, factory, undef) { 10372 if (typeof exports === "object") { 10373 // CommonJS 10374 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10375 } 10376 else if (typeof define === "function" && define.amd) { 10377 // AMD 10378 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10379 } 10380 else { 10381 // Global (browser) 10382 factory(root.CryptoJS); 10383 } 10384 }(this, function (CryptoJS) { 10385 10386 (function () { 10387 // Shortcuts 10388 var C = CryptoJS; 10389 var C_lib = C.lib; 10390 var StreamCipher = C_lib.StreamCipher; 10391 var C_algo = C.algo; 10392 10393 // Reusable objects 10394 var S = []; 10395 var C_ = []; 10396 var G = []; 10397 10398 /** 10399 * Rabbit stream cipher algorithm. 10400 * 10401 * This is a legacy version that neglected to convert the key to little-endian. 10402 * This error doesn't affect the cipher's security, 10403 * but it does affect its compatibility with other implementations. 10404 */ 10405 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10406 _doReset: function () { 10407 // Shortcuts 10408 var K = this._key.words; 10409 var iv = this.cfg.iv; 10410 10411 // Generate initial state values 10412 var X = this._X = [ 10413 K[0], (K[3] << 16) | (K[2] >>> 16), 10414 K[1], (K[0] << 16) | (K[3] >>> 16), 10415 K[2], (K[1] << 16) | (K[0] >>> 16), 10416 K[3], (K[2] << 16) | (K[1] >>> 16) 10417 ]; 10418 10419 // Generate initial counter values 10420 var C = this._C = [ 10421 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10422 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10423 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10424 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10425 ]; 10426 10427 // Carry bit 10428 this._b = 0; 10429 10430 // Iterate the system four times 10431 for (var i = 0; i < 4; i++) { 10432 nextState.call(this); 10433 } 10434 10435 // Modify the counters 10436 for (var i = 0; i < 8; i++) { 10437 C[i] ^= X[(i + 4) & 7]; 10438 } 10439 10440 // IV setup 10441 if (iv) { 10442 // Shortcuts 10443 var IV = iv.words; 10444 var IV_0 = IV[0]; 10445 var IV_1 = IV[1]; 10446 10447 // Generate four subvectors 10448 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10449 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10450 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10451 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10452 10453 // Modify counter values 10454 C[0] ^= i0; 10455 C[1] ^= i1; 10456 C[2] ^= i2; 10457 C[3] ^= i3; 10458 C[4] ^= i0; 10459 C[5] ^= i1; 10460 C[6] ^= i2; 10461 C[7] ^= i3; 10462 10463 // Iterate the system four times 10464 for (var i = 0; i < 4; i++) { 10465 nextState.call(this); 10466 } 10467 } 10468 }, 10469 10470 _doProcessBlock: function (M, offset) { 10471 // Shortcut 10472 var X = this._X; 10473 10474 // Iterate the system 10475 nextState.call(this); 10476 10477 // Generate four keystream words 10478 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10479 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10480 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10481 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10482 10483 for (var i = 0; i < 4; i++) { 10484 // Swap endian 10485 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10486 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10487 10488 // Encrypt 10489 M[offset + i] ^= S[i]; 10490 } 10491 }, 10492 10493 blockSize: 128/32, 10494 10495 ivSize: 64/32 10496 }); 10497 10498 function nextState() { 10499 // Shortcuts 10500 var X = this._X; 10501 var C = this._C; 10502 10503 // Save old counter values 10504 for (var i = 0; i < 8; i++) { 10505 C_[i] = C[i]; 10506 } 10507 10508 // Calculate new counter values 10509 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10510 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10511 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10512 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10513 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10514 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10515 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10516 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10517 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10518 10519 // Calculate the g-values 10520 for (var i = 0; i < 8; i++) { 10521 var gx = X[i] + C[i]; 10522 10523 // Construct high and low argument for squaring 10524 var ga = gx & 0xffff; 10525 var gb = gx >>> 16; 10526 10527 // Calculate high and low result of squaring 10528 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10529 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10530 10531 // High XOR low 10532 G[i] = gh ^ gl; 10533 } 10534 10535 // Calculate new state values 10536 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10537 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10538 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10539 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10540 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10541 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10542 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10543 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10544 } 10545 10546 /** 10547 * Shortcut functions to the cipher's object interface. 10548 * 10549 * @example 10550 * 10551 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10552 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10553 */ 10554 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10555 }()); 10556 10557 10558 return CryptoJS.RabbitLegacy; 10559 10560 })); 10561 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 10562 ;(function (root, factory, undef) { 10563 if (typeof exports === "object") { 10564 // CommonJS 10565 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10566 } 10567 else if (typeof define === "function" && define.amd) { 10568 // AMD 10569 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10570 } 10571 else { 10572 // Global (browser) 10573 factory(root.CryptoJS); 10574 } 10575 }(this, function (CryptoJS) { 10576 10577 (function () { 10578 // Shortcuts 10579 var C = CryptoJS; 10580 var C_lib = C.lib; 10581 var StreamCipher = C_lib.StreamCipher; 10582 var C_algo = C.algo; 10583 10584 // Reusable objects 10585 var S = []; 10586 var C_ = []; 10587 var G = []; 10588 10589 /** 10590 * Rabbit stream cipher algorithm 10591 */ 10592 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10593 _doReset: function () { 10594 // Shortcuts 10595 var K = this._key.words; 10596 var iv = this.cfg.iv; 10597 10598 // Swap endian 10599 for (var i = 0; i < 4; i++) { 10600 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10601 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10602 } 10603 10604 // Generate initial state values 10605 var X = this._X = [ 10606 K[0], (K[3] << 16) | (K[2] >>> 16), 10607 K[1], (K[0] << 16) | (K[3] >>> 16), 10608 K[2], (K[1] << 16) | (K[0] >>> 16), 10609 K[3], (K[2] << 16) | (K[1] >>> 16) 10610 ]; 10611 10612 // Generate initial counter values 10613 var C = this._C = [ 10614 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10615 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10616 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10617 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10618 ]; 10619 10620 // Carry bit 10621 this._b = 0; 10622 10623 // Iterate the system four times 10624 for (var i = 0; i < 4; i++) { 10625 nextState.call(this); 10626 } 10627 10628 // Modify the counters 10629 for (var i = 0; i < 8; i++) { 10630 C[i] ^= X[(i + 4) & 7]; 10631 } 10632 10633 // IV setup 10634 if (iv) { 10635 // Shortcuts 10636 var IV = iv.words; 10637 var IV_0 = IV[0]; 10638 var IV_1 = IV[1]; 10639 10640 // Generate four subvectors 10641 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10642 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10643 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10644 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10645 10646 // Modify counter values 10647 C[0] ^= i0; 10648 C[1] ^= i1; 10649 C[2] ^= i2; 10650 C[3] ^= i3; 10651 C[4] ^= i0; 10652 C[5] ^= i1; 10653 C[6] ^= i2; 10654 C[7] ^= i3; 10655 10656 // Iterate the system four times 10657 for (var i = 0; i < 4; i++) { 10658 nextState.call(this); 10659 } 10660 } 10661 }, 10662 10663 _doProcessBlock: function (M, offset) { 10664 // Shortcut 10665 var X = this._X; 10666 10667 // Iterate the system 10668 nextState.call(this); 10669 10670 // Generate four keystream words 10671 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10672 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10673 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10674 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10675 10676 for (var i = 0; i < 4; i++) { 10677 // Swap endian 10678 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10679 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10680 10681 // Encrypt 10682 M[offset + i] ^= S[i]; 10683 } 10684 }, 10685 10686 blockSize: 128/32, 10687 10688 ivSize: 64/32 10689 }); 10690 10691 function nextState() { 10692 // Shortcuts 10693 var X = this._X; 10694 var C = this._C; 10695 10696 // Save old counter values 10697 for (var i = 0; i < 8; i++) { 10698 C_[i] = C[i]; 10699 } 10700 10701 // Calculate new counter values 10702 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10703 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10704 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10705 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10706 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10707 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10708 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10709 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10710 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10711 10712 // Calculate the g-values 10713 for (var i = 0; i < 8; i++) { 10714 var gx = X[i] + C[i]; 10715 10716 // Construct high and low argument for squaring 10717 var ga = gx & 0xffff; 10718 var gb = gx >>> 16; 10719 10720 // Calculate high and low result of squaring 10721 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10722 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10723 10724 // High XOR low 10725 G[i] = gh ^ gl; 10726 } 10727 10728 // Calculate new state values 10729 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10730 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10731 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10732 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10733 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10734 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10735 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10736 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10737 } 10738 10739 /** 10740 * Shortcut functions to the cipher's object interface. 10741 * 10742 * @example 10743 * 10744 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10745 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10746 */ 10747 C.Rabbit = StreamCipher._createHelper(Rabbit); 10748 }()); 10749 10750 10751 return CryptoJS.Rabbit; 10752 10753 })); 10754 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 10755 ;(function (root, factory, undef) { 10756 if (typeof exports === "object") { 10757 // CommonJS 10758 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10759 } 10760 else if (typeof define === "function" && define.amd) { 10761 // AMD 10762 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10763 } 10764 else { 10765 // Global (browser) 10766 factory(root.CryptoJS); 10767 } 10768 }(this, function (CryptoJS) { 10769 10770 (function () { 10771 // Shortcuts 10772 var C = CryptoJS; 10773 var C_lib = C.lib; 10774 var StreamCipher = C_lib.StreamCipher; 10775 var C_algo = C.algo; 10776 10777 /** 10778 * RC4 stream cipher algorithm. 10779 */ 10780 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10781 _doReset: function () { 10782 // Shortcuts 10783 var key = this._key; 10784 var keyWords = key.words; 10785 var keySigBytes = key.sigBytes; 10786 10787 // Init sbox 10788 var S = this._S = []; 10789 for (var i = 0; i < 256; i++) { 10790 S[i] = i; 10791 } 10792 10793 // Key setup 10794 for (var i = 0, j = 0; i < 256; i++) { 10795 var keyByteIndex = i % keySigBytes; 10796 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10797 10798 j = (j + S[i] + keyByte) % 256; 10799 10800 // Swap 10801 var t = S[i]; 10802 S[i] = S[j]; 10803 S[j] = t; 10804 } 10805 10806 // Counters 10807 this._i = this._j = 0; 10808 }, 10809 10810 _doProcessBlock: function (M, offset) { 10811 M[offset] ^= generateKeystreamWord.call(this); 10812 }, 10813 10814 keySize: 256/32, 10815 10816 ivSize: 0 10817 }); 10818 10819 function generateKeystreamWord() { 10820 // Shortcuts 10821 var S = this._S; 10822 var i = this._i; 10823 var j = this._j; 10824 10825 // Generate keystream word 10826 var keystreamWord = 0; 10827 for (var n = 0; n < 4; n++) { 10828 i = (i + 1) % 256; 10829 j = (j + S[i]) % 256; 10830 10831 // Swap 10832 var t = S[i]; 10833 S[i] = S[j]; 10834 S[j] = t; 10835 10836 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 10837 } 10838 10839 // Update counters 10840 this._i = i; 10841 this._j = j; 10842 10843 return keystreamWord; 10844 } 10845 10846 /** 10847 * Shortcut functions to the cipher's object interface. 10848 * 10849 * @example 10850 * 10851 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 10852 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 10853 */ 10854 C.RC4 = StreamCipher._createHelper(RC4); 10855 10856 /** 10857 * Modified RC4 stream cipher algorithm. 10858 */ 10859 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 10860 /** 10861 * Configuration options. 10862 * 10863 * @property {number} drop The number of keystream words to drop. Default 192 10864 */ 10865 cfg: RC4.cfg.extend({ 10866 drop: 192 10867 }), 10868 10869 _doReset: function () { 10870 RC4._doReset.call(this); 10871 10872 // Drop 10873 for (var i = this.cfg.drop; i > 0; i--) { 10874 generateKeystreamWord.call(this); 10875 } 10876 } 10877 }); 10878 10879 /** 10880 * Shortcut functions to the cipher's object interface. 10881 * 10882 * @example 10883 * 10884 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 10885 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 10886 */ 10887 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 10888 }()); 10889 10890 10891 return CryptoJS.RC4; 10892 10893 })); 10894 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 10895 ;(function (root, factory) { 10896 if (typeof exports === "object") { 10897 // CommonJS 10898 module.exports = exports = factory(require("./core")); 10899 } 10900 else if (typeof define === "function" && define.amd) { 10901 // AMD 10902 define(["./core"], factory); 10903 } 10904 else { 10905 // Global (browser) 10906 factory(root.CryptoJS); 10907 } 10908 }(this, function (CryptoJS) { 10909 10910 /** @preserve 10911 (c) 2012 by Cédric Mesnil. All rights reserved. 10912 10913 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10914 10915 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10916 - 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. 10917 10918 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. 10919 */ 10920 10921 (function (Math) { 10922 // Shortcuts 10923 var C = CryptoJS; 10924 var C_lib = C.lib; 10925 var WordArray = C_lib.WordArray; 10926 var Hasher = C_lib.Hasher; 10927 var C_algo = C.algo; 10928 10929 // Constants table 10930 var _zl = WordArray.create([ 10931 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10932 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 10933 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 10934 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 10935 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 10936 var _zr = WordArray.create([ 10937 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 10938 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 10939 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 10940 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 10941 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 10942 var _sl = WordArray.create([ 10943 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 10944 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 10945 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 10946 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 10947 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 10948 var _sr = WordArray.create([ 10949 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 10950 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 10951 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 10952 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 10953 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 10954 10955 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 10956 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 10957 10958 /** 10959 * RIPEMD160 hash algorithm. 10960 */ 10961 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 10962 _doReset: function () { 10963 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 10964 }, 10965 10966 _doProcessBlock: function (M, offset) { 10967 10968 // Swap endian 10969 for (var i = 0; i < 16; i++) { 10970 // Shortcuts 10971 var offset_i = offset + i; 10972 var M_offset_i = M[offset_i]; 10973 10974 // Swap 10975 M[offset_i] = ( 10976 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10977 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 10978 ); 10979 } 10980 // Shortcut 10981 var H = this._hash.words; 10982 var hl = _hl.words; 10983 var hr = _hr.words; 10984 var zl = _zl.words; 10985 var zr = _zr.words; 10986 var sl = _sl.words; 10987 var sr = _sr.words; 10988 10989 // Working variables 10990 var al, bl, cl, dl, el; 10991 var ar, br, cr, dr, er; 10992 10993 ar = al = H[0]; 10994 br = bl = H[1]; 10995 cr = cl = H[2]; 10996 dr = dl = H[3]; 10997 er = el = H[4]; 10998 // Computation 10999 var t; 11000 for (var i = 0; i < 80; i += 1) { 11001 t = (al + M[offset+zl[i]])|0; 11002 if (i<16){ 11003 t += f1(bl,cl,dl) + hl[0]; 11004 } else if (i<32) { 11005 t += f2(bl,cl,dl) + hl[1]; 11006 } else if (i<48) { 11007 t += f3(bl,cl,dl) + hl[2]; 11008 } else if (i<64) { 11009 t += f4(bl,cl,dl) + hl[3]; 11010 } else {// if (i<80) { 11011 t += f5(bl,cl,dl) + hl[4]; 11012 } 11013 t = t|0; 11014 t = rotl(t,sl[i]); 11015 t = (t+el)|0; 11016 al = el; 11017 el = dl; 11018 dl = rotl(cl, 10); 11019 cl = bl; 11020 bl = t; 11021 11022 t = (ar + M[offset+zr[i]])|0; 11023 if (i<16){ 11024 t += f5(br,cr,dr) + hr[0]; 11025 } else if (i<32) { 11026 t += f4(br,cr,dr) + hr[1]; 11027 } else if (i<48) { 11028 t += f3(br,cr,dr) + hr[2]; 11029 } else if (i<64) { 11030 t += f2(br,cr,dr) + hr[3]; 11031 } else {// if (i<80) { 11032 t += f1(br,cr,dr) + hr[4]; 11033 } 11034 t = t|0; 11035 t = rotl(t,sr[i]) ; 11036 t = (t+er)|0; 11037 ar = er; 11038 er = dr; 11039 dr = rotl(cr, 10); 11040 cr = br; 11041 br = t; 11042 } 11043 // Intermediate hash value 11044 t = (H[1] + cl + dr)|0; 11045 H[1] = (H[2] + dl + er)|0; 11046 H[2] = (H[3] + el + ar)|0; 11047 H[3] = (H[4] + al + br)|0; 11048 H[4] = (H[0] + bl + cr)|0; 11049 H[0] = t; 11050 }, 11051 11052 _doFinalize: function () { 11053 // Shortcuts 11054 var data = this._data; 11055 var dataWords = data.words; 11056 11057 var nBitsTotal = this._nDataBytes * 8; 11058 var nBitsLeft = data.sigBytes * 8; 11059 11060 // Add padding 11061 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11062 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11063 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11064 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11065 ); 11066 data.sigBytes = (dataWords.length + 1) * 4; 11067 11068 // Hash final blocks 11069 this._process(); 11070 11071 // Shortcuts 11072 var hash = this._hash; 11073 var H = hash.words; 11074 11075 // Swap endian 11076 for (var i = 0; i < 5; i++) { 11077 // Shortcut 11078 var H_i = H[i]; 11079 11080 // Swap 11081 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11082 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11083 } 11084 11085 // Return final computed hash 11086 return hash; 11087 }, 11088 11089 clone: function () { 11090 var clone = Hasher.clone.call(this); 11091 clone._hash = this._hash.clone(); 11092 11093 return clone; 11094 } 11095 }); 11096 11097 11098 function f1(x, y, z) { 11099 return ((x) ^ (y) ^ (z)); 11100 11101 } 11102 11103 function f2(x, y, z) { 11104 return (((x)&(y)) | ((~x)&(z))); 11105 } 11106 11107 function f3(x, y, z) { 11108 return (((x) | (~(y))) ^ (z)); 11109 } 11110 11111 function f4(x, y, z) { 11112 return (((x) & (z)) | ((y)&(~(z)))); 11113 } 11114 11115 function f5(x, y, z) { 11116 return ((x) ^ ((y) |(~(z)))); 11117 11118 } 11119 11120 function rotl(x,n) { 11121 return (x<<n) | (x>>>(32-n)); 11122 } 11123 11124 11125 /** 11126 * Shortcut function to the hasher's object interface. 11127 * 11128 * @param {WordArray|string} message The message to hash. 11129 * 11130 * @return {WordArray} The hash. 11131 * 11132 * @static 11133 * 11134 * @example 11135 * 11136 * var hash = CryptoJS.RIPEMD160('message'); 11137 * var hash = CryptoJS.RIPEMD160(wordArray); 11138 */ 11139 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11140 11141 /** 11142 * Shortcut function to the HMAC's object interface. 11143 * 11144 * @param {WordArray|string} message The message to hash. 11145 * @param {WordArray|string} key The secret key. 11146 * 11147 * @return {WordArray} The HMAC. 11148 * 11149 * @static 11150 * 11151 * @example 11152 * 11153 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11154 */ 11155 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11156 }(Math)); 11157 11158 11159 return CryptoJS.RIPEMD160; 11160 11161 })); 11162 },{"./core":53}],77:[function(require,module,exports){ 11163 ;(function (root, factory) { 11164 if (typeof exports === "object") { 11165 // CommonJS 11166 module.exports = exports = factory(require("./core")); 11167 } 11168 else if (typeof define === "function" && define.amd) { 11169 // AMD 11170 define(["./core"], factory); 11171 } 11172 else { 11173 // Global (browser) 11174 factory(root.CryptoJS); 11175 } 11176 }(this, function (CryptoJS) { 11177 11178 (function () { 11179 // Shortcuts 11180 var C = CryptoJS; 11181 var C_lib = C.lib; 11182 var WordArray = C_lib.WordArray; 11183 var Hasher = C_lib.Hasher; 11184 var C_algo = C.algo; 11185 11186 // Reusable object 11187 var W = []; 11188 11189 /** 11190 * SHA-1 hash algorithm. 11191 */ 11192 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11193 _doReset: function () { 11194 this._hash = new WordArray.init([ 11195 0x67452301, 0xefcdab89, 11196 0x98badcfe, 0x10325476, 11197 0xc3d2e1f0 11198 ]); 11199 }, 11200 11201 _doProcessBlock: function (M, offset) { 11202 // Shortcut 11203 var H = this._hash.words; 11204 11205 // Working variables 11206 var a = H[0]; 11207 var b = H[1]; 11208 var c = H[2]; 11209 var d = H[3]; 11210 var e = H[4]; 11211 11212 // Computation 11213 for (var i = 0; i < 80; i++) { 11214 if (i < 16) { 11215 W[i] = M[offset + i] | 0; 11216 } else { 11217 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11218 W[i] = (n << 1) | (n >>> 31); 11219 } 11220 11221 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11222 if (i < 20) { 11223 t += ((b & c) | (~b & d)) + 0x5a827999; 11224 } else if (i < 40) { 11225 t += (b ^ c ^ d) + 0x6ed9eba1; 11226 } else if (i < 60) { 11227 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11228 } else /* if (i < 80) */ { 11229 t += (b ^ c ^ d) - 0x359d3e2a; 11230 } 11231 11232 e = d; 11233 d = c; 11234 c = (b << 30) | (b >>> 2); 11235 b = a; 11236 a = t; 11237 } 11238 11239 // Intermediate hash value 11240 H[0] = (H[0] + a) | 0; 11241 H[1] = (H[1] + b) | 0; 11242 H[2] = (H[2] + c) | 0; 11243 H[3] = (H[3] + d) | 0; 11244 H[4] = (H[4] + e) | 0; 11245 }, 11246 11247 _doFinalize: function () { 11248 // Shortcuts 11249 var data = this._data; 11250 var dataWords = data.words; 11251 11252 var nBitsTotal = this._nDataBytes * 8; 11253 var nBitsLeft = data.sigBytes * 8; 11254 11255 // Add padding 11256 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11257 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11258 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11259 data.sigBytes = dataWords.length * 4; 11260 11261 // Hash final blocks 11262 this._process(); 11263 11264 // Return final computed hash 11265 return this._hash; 11266 }, 11267 11268 clone: function () { 11269 var clone = Hasher.clone.call(this); 11270 clone._hash = this._hash.clone(); 11271 11272 return clone; 11273 } 11274 }); 11275 11276 /** 11277 * Shortcut function to the hasher's object interface. 11278 * 11279 * @param {WordArray|string} message The message to hash. 11280 * 11281 * @return {WordArray} The hash. 11282 * 11283 * @static 11284 * 11285 * @example 11286 * 11287 * var hash = CryptoJS.SHA1('message'); 11288 * var hash = CryptoJS.SHA1(wordArray); 11289 */ 11290 C.SHA1 = Hasher._createHelper(SHA1); 11291 11292 /** 11293 * Shortcut function to the HMAC's object interface. 11294 * 11295 * @param {WordArray|string} message The message to hash. 11296 * @param {WordArray|string} key The secret key. 11297 * 11298 * @return {WordArray} The HMAC. 11299 * 11300 * @static 11301 * 11302 * @example 11303 * 11304 * var hmac = CryptoJS.HmacSHA1(message, key); 11305 */ 11306 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11307 }()); 11308 11309 11310 return CryptoJS.SHA1; 11311 11312 })); 11313 },{"./core":53}],78:[function(require,module,exports){ 11314 ;(function (root, factory, undef) { 11315 if (typeof exports === "object") { 11316 // CommonJS 11317 module.exports = exports = factory(require("./core"), require("./sha256")); 11318 } 11319 else if (typeof define === "function" && define.amd) { 11320 // AMD 11321 define(["./core", "./sha256"], factory); 11322 } 11323 else { 11324 // Global (browser) 11325 factory(root.CryptoJS); 11326 } 11327 }(this, function (CryptoJS) { 11328 11329 (function () { 11330 // Shortcuts 11331 var C = CryptoJS; 11332 var C_lib = C.lib; 11333 var WordArray = C_lib.WordArray; 11334 var C_algo = C.algo; 11335 var SHA256 = C_algo.SHA256; 11336 11337 /** 11338 * SHA-224 hash algorithm. 11339 */ 11340 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11341 _doReset: function () { 11342 this._hash = new WordArray.init([ 11343 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11344 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11345 ]); 11346 }, 11347 11348 _doFinalize: function () { 11349 var hash = SHA256._doFinalize.call(this); 11350 11351 hash.sigBytes -= 4; 11352 11353 return hash; 11354 } 11355 }); 11356 11357 /** 11358 * Shortcut function to the hasher's object interface. 11359 * 11360 * @param {WordArray|string} message The message to hash. 11361 * 11362 * @return {WordArray} The hash. 11363 * 11364 * @static 11365 * 11366 * @example 11367 * 11368 * var hash = CryptoJS.SHA224('message'); 11369 * var hash = CryptoJS.SHA224(wordArray); 11370 */ 11371 C.SHA224 = SHA256._createHelper(SHA224); 11372 11373 /** 11374 * Shortcut function to the HMAC's object interface. 11375 * 11376 * @param {WordArray|string} message The message to hash. 11377 * @param {WordArray|string} key The secret key. 11378 * 11379 * @return {WordArray} The HMAC. 11380 * 11381 * @static 11382 * 11383 * @example 11384 * 11385 * var hmac = CryptoJS.HmacSHA224(message, key); 11386 */ 11387 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11388 }()); 11389 11390 11391 return CryptoJS.SHA224; 11392 11393 })); 11394 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 11395 ;(function (root, factory) { 11396 if (typeof exports === "object") { 11397 // CommonJS 11398 module.exports = exports = factory(require("./core")); 11399 } 11400 else if (typeof define === "function" && define.amd) { 11401 // AMD 11402 define(["./core"], factory); 11403 } 11404 else { 11405 // Global (browser) 11406 factory(root.CryptoJS); 11407 } 11408 }(this, function (CryptoJS) { 11409 11410 (function (Math) { 11411 // Shortcuts 11412 var C = CryptoJS; 11413 var C_lib = C.lib; 11414 var WordArray = C_lib.WordArray; 11415 var Hasher = C_lib.Hasher; 11416 var C_algo = C.algo; 11417 11418 // Initialization and round constants tables 11419 var H = []; 11420 var K = []; 11421 11422 // Compute constants 11423 (function () { 11424 function isPrime(n) { 11425 var sqrtN = Math.sqrt(n); 11426 for (var factor = 2; factor <= sqrtN; factor++) { 11427 if (!(n % factor)) { 11428 return false; 11429 } 11430 } 11431 11432 return true; 11433 } 11434 11435 function getFractionalBits(n) { 11436 return ((n - (n | 0)) * 0x100000000) | 0; 11437 } 11438 11439 var n = 2; 11440 var nPrime = 0; 11441 while (nPrime < 64) { 11442 if (isPrime(n)) { 11443 if (nPrime < 8) { 11444 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11445 } 11446 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11447 11448 nPrime++; 11449 } 11450 11451 n++; 11452 } 11453 }()); 11454 11455 // Reusable object 11456 var W = []; 11457 11458 /** 11459 * SHA-256 hash algorithm. 11460 */ 11461 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11462 _doReset: function () { 11463 this._hash = new WordArray.init(H.slice(0)); 11464 }, 11465 11466 _doProcessBlock: function (M, offset) { 11467 // Shortcut 11468 var H = this._hash.words; 11469 11470 // Working variables 11471 var a = H[0]; 11472 var b = H[1]; 11473 var c = H[2]; 11474 var d = H[3]; 11475 var e = H[4]; 11476 var f = H[5]; 11477 var g = H[6]; 11478 var h = H[7]; 11479 11480 // Computation 11481 for (var i = 0; i < 64; i++) { 11482 if (i < 16) { 11483 W[i] = M[offset + i] | 0; 11484 } else { 11485 var gamma0x = W[i - 15]; 11486 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11487 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11488 (gamma0x >>> 3); 11489 11490 var gamma1x = W[i - 2]; 11491 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11492 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11493 (gamma1x >>> 10); 11494 11495 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11496 } 11497 11498 var ch = (e & f) ^ (~e & g); 11499 var maj = (a & b) ^ (a & c) ^ (b & c); 11500 11501 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11502 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11503 11504 var t1 = h + sigma1 + ch + K[i] + W[i]; 11505 var t2 = sigma0 + maj; 11506 11507 h = g; 11508 g = f; 11509 f = e; 11510 e = (d + t1) | 0; 11511 d = c; 11512 c = b; 11513 b = a; 11514 a = (t1 + t2) | 0; 11515 } 11516 11517 // Intermediate hash value 11518 H[0] = (H[0] + a) | 0; 11519 H[1] = (H[1] + b) | 0; 11520 H[2] = (H[2] + c) | 0; 11521 H[3] = (H[3] + d) | 0; 11522 H[4] = (H[4] + e) | 0; 11523 H[5] = (H[5] + f) | 0; 11524 H[6] = (H[6] + g) | 0; 11525 H[7] = (H[7] + h) | 0; 11526 }, 11527 11528 _doFinalize: function () { 11529 // Shortcuts 11530 var data = this._data; 11531 var dataWords = data.words; 11532 11533 var nBitsTotal = this._nDataBytes * 8; 11534 var nBitsLeft = data.sigBytes * 8; 11535 11536 // Add padding 11537 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11538 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11539 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11540 data.sigBytes = dataWords.length * 4; 11541 11542 // Hash final blocks 11543 this._process(); 11544 11545 // Return final computed hash 11546 return this._hash; 11547 }, 11548 11549 clone: function () { 11550 var clone = Hasher.clone.call(this); 11551 clone._hash = this._hash.clone(); 11552 11553 return clone; 11554 } 11555 }); 11556 11557 /** 11558 * Shortcut function to the hasher's object interface. 11559 * 11560 * @param {WordArray|string} message The message to hash. 11561 * 11562 * @return {WordArray} The hash. 11563 * 11564 * @static 11565 * 11566 * @example 11567 * 11568 * var hash = CryptoJS.SHA256('message'); 11569 * var hash = CryptoJS.SHA256(wordArray); 11570 */ 11571 C.SHA256 = Hasher._createHelper(SHA256); 11572 11573 /** 11574 * Shortcut function to the HMAC's object interface. 11575 * 11576 * @param {WordArray|string} message The message to hash. 11577 * @param {WordArray|string} key The secret key. 11578 * 11579 * @return {WordArray} The HMAC. 11580 * 11581 * @static 11582 * 11583 * @example 11584 * 11585 * var hmac = CryptoJS.HmacSHA256(message, key); 11586 */ 11587 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11588 }(Math)); 11589 11590 11591 return CryptoJS.SHA256; 11592 11593 })); 11594 },{"./core":53}],80:[function(require,module,exports){ 11595 ;(function (root, factory, undef) { 11596 if (typeof exports === "object") { 11597 // CommonJS 11598 module.exports = exports = factory(require("./core"), require("./x64-core")); 11599 } 11600 else if (typeof define === "function" && define.amd) { 11601 // AMD 11602 define(["./core", "./x64-core"], factory); 11603 } 11604 else { 11605 // Global (browser) 11606 factory(root.CryptoJS); 11607 } 11608 }(this, function (CryptoJS) { 11609 11610 (function (Math) { 11611 // Shortcuts 11612 var C = CryptoJS; 11613 var C_lib = C.lib; 11614 var WordArray = C_lib.WordArray; 11615 var Hasher = C_lib.Hasher; 11616 var C_x64 = C.x64; 11617 var X64Word = C_x64.Word; 11618 var C_algo = C.algo; 11619 11620 // Constants tables 11621 var RHO_OFFSETS = []; 11622 var PI_INDEXES = []; 11623 var ROUND_CONSTANTS = []; 11624 11625 // Compute Constants 11626 (function () { 11627 // Compute rho offset constants 11628 var x = 1, y = 0; 11629 for (var t = 0; t < 24; t++) { 11630 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11631 11632 var newX = y % 5; 11633 var newY = (2 * x + 3 * y) % 5; 11634 x = newX; 11635 y = newY; 11636 } 11637 11638 // Compute pi index constants 11639 for (var x = 0; x < 5; x++) { 11640 for (var y = 0; y < 5; y++) { 11641 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11642 } 11643 } 11644 11645 // Compute round constants 11646 var LFSR = 0x01; 11647 for (var i = 0; i < 24; i++) { 11648 var roundConstantMsw = 0; 11649 var roundConstantLsw = 0; 11650 11651 for (var j = 0; j < 7; j++) { 11652 if (LFSR & 0x01) { 11653 var bitPosition = (1 << j) - 1; 11654 if (bitPosition < 32) { 11655 roundConstantLsw ^= 1 << bitPosition; 11656 } else /* if (bitPosition >= 32) */ { 11657 roundConstantMsw ^= 1 << (bitPosition - 32); 11658 } 11659 } 11660 11661 // Compute next LFSR 11662 if (LFSR & 0x80) { 11663 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11664 LFSR = (LFSR << 1) ^ 0x71; 11665 } else { 11666 LFSR <<= 1; 11667 } 11668 } 11669 11670 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11671 } 11672 }()); 11673 11674 // Reusable objects for temporary values 11675 var T = []; 11676 (function () { 11677 for (var i = 0; i < 25; i++) { 11678 T[i] = X64Word.create(); 11679 } 11680 }()); 11681 11682 /** 11683 * SHA-3 hash algorithm. 11684 */ 11685 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11686 /** 11687 * Configuration options. 11688 * 11689 * @property {number} outputLength 11690 * The desired number of bits in the output hash. 11691 * Only values permitted are: 224, 256, 384, 512. 11692 * Default: 512 11693 */ 11694 cfg: Hasher.cfg.extend({ 11695 outputLength: 512 11696 }), 11697 11698 _doReset: function () { 11699 var state = this._state = [] 11700 for (var i = 0; i < 25; i++) { 11701 state[i] = new X64Word.init(); 11702 } 11703 11704 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11705 }, 11706 11707 _doProcessBlock: function (M, offset) { 11708 // Shortcuts 11709 var state = this._state; 11710 var nBlockSizeLanes = this.blockSize / 2; 11711 11712 // Absorb 11713 for (var i = 0; i < nBlockSizeLanes; i++) { 11714 // Shortcuts 11715 var M2i = M[offset + 2 * i]; 11716 var M2i1 = M[offset + 2 * i + 1]; 11717 11718 // Swap endian 11719 M2i = ( 11720 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11721 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11722 ); 11723 M2i1 = ( 11724 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11725 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11726 ); 11727 11728 // Absorb message into state 11729 var lane = state[i]; 11730 lane.high ^= M2i1; 11731 lane.low ^= M2i; 11732 } 11733 11734 // Rounds 11735 for (var round = 0; round < 24; round++) { 11736 // Theta 11737 for (var x = 0; x < 5; x++) { 11738 // Mix column lanes 11739 var tMsw = 0, tLsw = 0; 11740 for (var y = 0; y < 5; y++) { 11741 var lane = state[x + 5 * y]; 11742 tMsw ^= lane.high; 11743 tLsw ^= lane.low; 11744 } 11745 11746 // Temporary values 11747 var Tx = T[x]; 11748 Tx.high = tMsw; 11749 Tx.low = tLsw; 11750 } 11751 for (var x = 0; x < 5; x++) { 11752 // Shortcuts 11753 var Tx4 = T[(x + 4) % 5]; 11754 var Tx1 = T[(x + 1) % 5]; 11755 var Tx1Msw = Tx1.high; 11756 var Tx1Lsw = Tx1.low; 11757 11758 // Mix surrounding columns 11759 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11760 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11761 for (var y = 0; y < 5; y++) { 11762 var lane = state[x + 5 * y]; 11763 lane.high ^= tMsw; 11764 lane.low ^= tLsw; 11765 } 11766 } 11767 11768 // Rho Pi 11769 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11770 // Shortcuts 11771 var lane = state[laneIndex]; 11772 var laneMsw = lane.high; 11773 var laneLsw = lane.low; 11774 var rhoOffset = RHO_OFFSETS[laneIndex]; 11775 11776 // Rotate lanes 11777 if (rhoOffset < 32) { 11778 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11779 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11780 } else /* if (rhoOffset >= 32) */ { 11781 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11782 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11783 } 11784 11785 // Transpose lanes 11786 var TPiLane = T[PI_INDEXES[laneIndex]]; 11787 TPiLane.high = tMsw; 11788 TPiLane.low = tLsw; 11789 } 11790 11791 // Rho pi at x = y = 0 11792 var T0 = T[0]; 11793 var state0 = state[0]; 11794 T0.high = state0.high; 11795 T0.low = state0.low; 11796 11797 // Chi 11798 for (var x = 0; x < 5; x++) { 11799 for (var y = 0; y < 5; y++) { 11800 // Shortcuts 11801 var laneIndex = x + 5 * y; 11802 var lane = state[laneIndex]; 11803 var TLane = T[laneIndex]; 11804 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 11805 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 11806 11807 // Mix rows 11808 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 11809 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 11810 } 11811 } 11812 11813 // Iota 11814 var lane = state[0]; 11815 var roundConstant = ROUND_CONSTANTS[round]; 11816 lane.high ^= roundConstant.high; 11817 lane.low ^= roundConstant.low;; 11818 } 11819 }, 11820 11821 _doFinalize: function () { 11822 // Shortcuts 11823 var data = this._data; 11824 var dataWords = data.words; 11825 var nBitsTotal = this._nDataBytes * 8; 11826 var nBitsLeft = data.sigBytes * 8; 11827 var blockSizeBits = this.blockSize * 32; 11828 11829 // Add padding 11830 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 11831 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 11832 data.sigBytes = dataWords.length * 4; 11833 11834 // Hash final blocks 11835 this._process(); 11836 11837 // Shortcuts 11838 var state = this._state; 11839 var outputLengthBytes = this.cfg.outputLength / 8; 11840 var outputLengthLanes = outputLengthBytes / 8; 11841 11842 // Squeeze 11843 var hashWords = []; 11844 for (var i = 0; i < outputLengthLanes; i++) { 11845 // Shortcuts 11846 var lane = state[i]; 11847 var laneMsw = lane.high; 11848 var laneLsw = lane.low; 11849 11850 // Swap endian 11851 laneMsw = ( 11852 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 11853 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 11854 ); 11855 laneLsw = ( 11856 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 11857 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 11858 ); 11859 11860 // Squeeze state to retrieve hash 11861 hashWords.push(laneLsw); 11862 hashWords.push(laneMsw); 11863 } 11864 11865 // Return final computed hash 11866 return new WordArray.init(hashWords, outputLengthBytes); 11867 }, 11868 11869 clone: function () { 11870 var clone = Hasher.clone.call(this); 11871 11872 var state = clone._state = this._state.slice(0); 11873 for (var i = 0; i < 25; i++) { 11874 state[i] = state[i].clone(); 11875 } 11876 11877 return clone; 11878 } 11879 }); 11880 11881 /** 11882 * Shortcut function to the hasher's object interface. 11883 * 11884 * @param {WordArray|string} message The message to hash. 11885 * 11886 * @return {WordArray} The hash. 11887 * 11888 * @static 11889 * 11890 * @example 11891 * 11892 * var hash = CryptoJS.SHA3('message'); 11893 * var hash = CryptoJS.SHA3(wordArray); 11894 */ 11895 C.SHA3 = Hasher._createHelper(SHA3); 11896 11897 /** 11898 * Shortcut function to the HMAC's object interface. 11899 * 11900 * @param {WordArray|string} message The message to hash. 11901 * @param {WordArray|string} key The secret key. 11902 * 11903 * @return {WordArray} The HMAC. 11904 * 11905 * @static 11906 * 11907 * @example 11908 * 11909 * var hmac = CryptoJS.HmacSHA3(message, key); 11910 */ 11911 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 11912 }(Math)); 11913 11914 11915 return CryptoJS.SHA3; 11916 11917 })); 11918 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 11919 ;(function (root, factory, undef) { 11920 if (typeof exports === "object") { 11921 // CommonJS 11922 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 11923 } 11924 else if (typeof define === "function" && define.amd) { 11925 // AMD 11926 define(["./core", "./x64-core", "./sha512"], factory); 11927 } 11928 else { 11929 // Global (browser) 11930 factory(root.CryptoJS); 11931 } 11932 }(this, function (CryptoJS) { 11933 11934 (function () { 11935 // Shortcuts 11936 var C = CryptoJS; 11937 var C_x64 = C.x64; 11938 var X64Word = C_x64.Word; 11939 var X64WordArray = C_x64.WordArray; 11940 var C_algo = C.algo; 11941 var SHA512 = C_algo.SHA512; 11942 11943 /** 11944 * SHA-384 hash algorithm. 11945 */ 11946 var SHA384 = C_algo.SHA384 = SHA512.extend({ 11947 _doReset: function () { 11948 this._hash = new X64WordArray.init([ 11949 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 11950 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 11951 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 11952 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 11953 ]); 11954 }, 11955 11956 _doFinalize: function () { 11957 var hash = SHA512._doFinalize.call(this); 11958 11959 hash.sigBytes -= 16; 11960 11961 return hash; 11962 } 11963 }); 11964 11965 /** 11966 * Shortcut function to the hasher's object interface. 11967 * 11968 * @param {WordArray|string} message The message to hash. 11969 * 11970 * @return {WordArray} The hash. 11971 * 11972 * @static 11973 * 11974 * @example 11975 * 11976 * var hash = CryptoJS.SHA384('message'); 11977 * var hash = CryptoJS.SHA384(wordArray); 11978 */ 11979 C.SHA384 = SHA512._createHelper(SHA384); 11980 11981 /** 11982 * Shortcut function to the HMAC's object interface. 11983 * 11984 * @param {WordArray|string} message The message to hash. 11985 * @param {WordArray|string} key The secret key. 11986 * 11987 * @return {WordArray} The HMAC. 11988 * 11989 * @static 11990 * 11991 * @example 11992 * 11993 * var hmac = CryptoJS.HmacSHA384(message, key); 11994 */ 11995 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 11996 }()); 11997 11998 11999 return CryptoJS.SHA384; 12000 12001 })); 12002 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 12003 ;(function (root, factory, undef) { 12004 if (typeof exports === "object") { 12005 // CommonJS 12006 module.exports = exports = factory(require("./core"), require("./x64-core")); 12007 } 12008 else if (typeof define === "function" && define.amd) { 12009 // AMD 12010 define(["./core", "./x64-core"], factory); 12011 } 12012 else { 12013 // Global (browser) 12014 factory(root.CryptoJS); 12015 } 12016 }(this, function (CryptoJS) { 12017 12018 (function () { 12019 // Shortcuts 12020 var C = CryptoJS; 12021 var C_lib = C.lib; 12022 var Hasher = C_lib.Hasher; 12023 var C_x64 = C.x64; 12024 var X64Word = C_x64.Word; 12025 var X64WordArray = C_x64.WordArray; 12026 var C_algo = C.algo; 12027 12028 function X64Word_create() { 12029 return X64Word.create.apply(X64Word, arguments); 12030 } 12031 12032 // Constants 12033 var K = [ 12034 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12035 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12036 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12037 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12038 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12039 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12040 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12041 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12042 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12043 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12044 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12045 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12046 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12047 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12048 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12049 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12050 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12051 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12052 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12053 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12054 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12055 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12056 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12057 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12058 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12059 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12060 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12061 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12062 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12063 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12064 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12065 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12066 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12067 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12068 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12069 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12070 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12071 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12072 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12073 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12074 ]; 12075 12076 // Reusable objects 12077 var W = []; 12078 (function () { 12079 for (var i = 0; i < 80; i++) { 12080 W[i] = X64Word_create(); 12081 } 12082 }()); 12083 12084 /** 12085 * SHA-512 hash algorithm. 12086 */ 12087 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12088 _doReset: function () { 12089 this._hash = new X64WordArray.init([ 12090 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12091 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12092 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12093 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12094 ]); 12095 }, 12096 12097 _doProcessBlock: function (M, offset) { 12098 // Shortcuts 12099 var H = this._hash.words; 12100 12101 var H0 = H[0]; 12102 var H1 = H[1]; 12103 var H2 = H[2]; 12104 var H3 = H[3]; 12105 var H4 = H[4]; 12106 var H5 = H[5]; 12107 var H6 = H[6]; 12108 var H7 = H[7]; 12109 12110 var H0h = H0.high; 12111 var H0l = H0.low; 12112 var H1h = H1.high; 12113 var H1l = H1.low; 12114 var H2h = H2.high; 12115 var H2l = H2.low; 12116 var H3h = H3.high; 12117 var H3l = H3.low; 12118 var H4h = H4.high; 12119 var H4l = H4.low; 12120 var H5h = H5.high; 12121 var H5l = H5.low; 12122 var H6h = H6.high; 12123 var H6l = H6.low; 12124 var H7h = H7.high; 12125 var H7l = H7.low; 12126 12127 // Working variables 12128 var ah = H0h; 12129 var al = H0l; 12130 var bh = H1h; 12131 var bl = H1l; 12132 var ch = H2h; 12133 var cl = H2l; 12134 var dh = H3h; 12135 var dl = H3l; 12136 var eh = H4h; 12137 var el = H4l; 12138 var fh = H5h; 12139 var fl = H5l; 12140 var gh = H6h; 12141 var gl = H6l; 12142 var hh = H7h; 12143 var hl = H7l; 12144 12145 // Rounds 12146 for (var i = 0; i < 80; i++) { 12147 // Shortcut 12148 var Wi = W[i]; 12149 12150 // Extend message 12151 if (i < 16) { 12152 var Wih = Wi.high = M[offset + i * 2] | 0; 12153 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12154 } else { 12155 // Gamma0 12156 var gamma0x = W[i - 15]; 12157 var gamma0xh = gamma0x.high; 12158 var gamma0xl = gamma0x.low; 12159 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12160 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12161 12162 // Gamma1 12163 var gamma1x = W[i - 2]; 12164 var gamma1xh = gamma1x.high; 12165 var gamma1xl = gamma1x.low; 12166 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12167 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12168 12169 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12170 var Wi7 = W[i - 7]; 12171 var Wi7h = Wi7.high; 12172 var Wi7l = Wi7.low; 12173 12174 var Wi16 = W[i - 16]; 12175 var Wi16h = Wi16.high; 12176 var Wi16l = Wi16.low; 12177 12178 var Wil = gamma0l + Wi7l; 12179 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12180 var Wil = Wil + gamma1l; 12181 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12182 var Wil = Wil + Wi16l; 12183 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12184 12185 Wi.high = Wih; 12186 Wi.low = Wil; 12187 } 12188 12189 var chh = (eh & fh) ^ (~eh & gh); 12190 var chl = (el & fl) ^ (~el & gl); 12191 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12192 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12193 12194 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12195 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12196 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12197 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12198 12199 // t1 = h + sigma1 + ch + K[i] + W[i] 12200 var Ki = K[i]; 12201 var Kih = Ki.high; 12202 var Kil = Ki.low; 12203 12204 var t1l = hl + sigma1l; 12205 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12206 var t1l = t1l + chl; 12207 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12208 var t1l = t1l + Kil; 12209 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12210 var t1l = t1l + Wil; 12211 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12212 12213 // t2 = sigma0 + maj 12214 var t2l = sigma0l + majl; 12215 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12216 12217 // Update working variables 12218 hh = gh; 12219 hl = gl; 12220 gh = fh; 12221 gl = fl; 12222 fh = eh; 12223 fl = el; 12224 el = (dl + t1l) | 0; 12225 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12226 dh = ch; 12227 dl = cl; 12228 ch = bh; 12229 cl = bl; 12230 bh = ah; 12231 bl = al; 12232 al = (t1l + t2l) | 0; 12233 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12234 } 12235 12236 // Intermediate hash value 12237 H0l = H0.low = (H0l + al); 12238 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12239 H1l = H1.low = (H1l + bl); 12240 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12241 H2l = H2.low = (H2l + cl); 12242 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12243 H3l = H3.low = (H3l + dl); 12244 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12245 H4l = H4.low = (H4l + el); 12246 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12247 H5l = H5.low = (H5l + fl); 12248 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12249 H6l = H6.low = (H6l + gl); 12250 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12251 H7l = H7.low = (H7l + hl); 12252 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12253 }, 12254 12255 _doFinalize: function () { 12256 // Shortcuts 12257 var data = this._data; 12258 var dataWords = data.words; 12259 12260 var nBitsTotal = this._nDataBytes * 8; 12261 var nBitsLeft = data.sigBytes * 8; 12262 12263 // Add padding 12264 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12265 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12266 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12267 data.sigBytes = dataWords.length * 4; 12268 12269 // Hash final blocks 12270 this._process(); 12271 12272 // Convert hash to 32-bit word array before returning 12273 var hash = this._hash.toX32(); 12274 12275 // Return final computed hash 12276 return hash; 12277 }, 12278 12279 clone: function () { 12280 var clone = Hasher.clone.call(this); 12281 clone._hash = this._hash.clone(); 12282 12283 return clone; 12284 }, 12285 12286 blockSize: 1024/32 12287 }); 12288 12289 /** 12290 * Shortcut function to the hasher's object interface. 12291 * 12292 * @param {WordArray|string} message The message to hash. 12293 * 12294 * @return {WordArray} The hash. 12295 * 12296 * @static 12297 * 12298 * @example 12299 * 12300 * var hash = CryptoJS.SHA512('message'); 12301 * var hash = CryptoJS.SHA512(wordArray); 12302 */ 12303 C.SHA512 = Hasher._createHelper(SHA512); 12304 12305 /** 12306 * Shortcut function to the HMAC's object interface. 12307 * 12308 * @param {WordArray|string} message The message to hash. 12309 * @param {WordArray|string} key The secret key. 12310 * 12311 * @return {WordArray} The HMAC. 12312 * 12313 * @static 12314 * 12315 * @example 12316 * 12317 * var hmac = CryptoJS.HmacSHA512(message, key); 12318 */ 12319 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12320 }()); 12321 12322 12323 return CryptoJS.SHA512; 12324 12325 })); 12326 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 12327 ;(function (root, factory, undef) { 12328 if (typeof exports === "object") { 12329 // CommonJS 12330 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12331 } 12332 else if (typeof define === "function" && define.amd) { 12333 // AMD 12334 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12335 } 12336 else { 12337 // Global (browser) 12338 factory(root.CryptoJS); 12339 } 12340 }(this, function (CryptoJS) { 12341 12342 (function () { 12343 // Shortcuts 12344 var C = CryptoJS; 12345 var C_lib = C.lib; 12346 var WordArray = C_lib.WordArray; 12347 var BlockCipher = C_lib.BlockCipher; 12348 var C_algo = C.algo; 12349 12350 // Permuted Choice 1 constants 12351 var PC1 = [ 12352 57, 49, 41, 33, 25, 17, 9, 1, 12353 58, 50, 42, 34, 26, 18, 10, 2, 12354 59, 51, 43, 35, 27, 19, 11, 3, 12355 60, 52, 44, 36, 63, 55, 47, 39, 12356 31, 23, 15, 7, 62, 54, 46, 38, 12357 30, 22, 14, 6, 61, 53, 45, 37, 12358 29, 21, 13, 5, 28, 20, 12, 4 12359 ]; 12360 12361 // Permuted Choice 2 constants 12362 var PC2 = [ 12363 14, 17, 11, 24, 1, 5, 12364 3, 28, 15, 6, 21, 10, 12365 23, 19, 12, 4, 26, 8, 12366 16, 7, 27, 20, 13, 2, 12367 41, 52, 31, 37, 47, 55, 12368 30, 40, 51, 45, 33, 48, 12369 44, 49, 39, 56, 34, 53, 12370 46, 42, 50, 36, 29, 32 12371 ]; 12372 12373 // Cumulative bit shift constants 12374 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12375 12376 // SBOXes and round permutation constants 12377 var SBOX_P = [ 12378 { 12379 0x0: 0x808200, 12380 0x10000000: 0x8000, 12381 0x20000000: 0x808002, 12382 0x30000000: 0x2, 12383 0x40000000: 0x200, 12384 0x50000000: 0x808202, 12385 0x60000000: 0x800202, 12386 0x70000000: 0x800000, 12387 0x80000000: 0x202, 12388 0x90000000: 0x800200, 12389 0xa0000000: 0x8200, 12390 0xb0000000: 0x808000, 12391 0xc0000000: 0x8002, 12392 0xd0000000: 0x800002, 12393 0xe0000000: 0x0, 12394 0xf0000000: 0x8202, 12395 0x8000000: 0x0, 12396 0x18000000: 0x808202, 12397 0x28000000: 0x8202, 12398 0x38000000: 0x8000, 12399 0x48000000: 0x808200, 12400 0x58000000: 0x200, 12401 0x68000000: 0x808002, 12402 0x78000000: 0x2, 12403 0x88000000: 0x800200, 12404 0x98000000: 0x8200, 12405 0xa8000000: 0x808000, 12406 0xb8000000: 0x800202, 12407 0xc8000000: 0x800002, 12408 0xd8000000: 0x8002, 12409 0xe8000000: 0x202, 12410 0xf8000000: 0x800000, 12411 0x1: 0x8000, 12412 0x10000001: 0x2, 12413 0x20000001: 0x808200, 12414 0x30000001: 0x800000, 12415 0x40000001: 0x808002, 12416 0x50000001: 0x8200, 12417 0x60000001: 0x200, 12418 0x70000001: 0x800202, 12419 0x80000001: 0x808202, 12420 0x90000001: 0x808000, 12421 0xa0000001: 0x800002, 12422 0xb0000001: 0x8202, 12423 0xc0000001: 0x202, 12424 0xd0000001: 0x800200, 12425 0xe0000001: 0x8002, 12426 0xf0000001: 0x0, 12427 0x8000001: 0x808202, 12428 0x18000001: 0x808000, 12429 0x28000001: 0x800000, 12430 0x38000001: 0x200, 12431 0x48000001: 0x8000, 12432 0x58000001: 0x800002, 12433 0x68000001: 0x2, 12434 0x78000001: 0x8202, 12435 0x88000001: 0x8002, 12436 0x98000001: 0x800202, 12437 0xa8000001: 0x202, 12438 0xb8000001: 0x808200, 12439 0xc8000001: 0x800200, 12440 0xd8000001: 0x0, 12441 0xe8000001: 0x8200, 12442 0xf8000001: 0x808002 12443 }, 12444 { 12445 0x0: 0x40084010, 12446 0x1000000: 0x4000, 12447 0x2000000: 0x80000, 12448 0x3000000: 0x40080010, 12449 0x4000000: 0x40000010, 12450 0x5000000: 0x40084000, 12451 0x6000000: 0x40004000, 12452 0x7000000: 0x10, 12453 0x8000000: 0x84000, 12454 0x9000000: 0x40004010, 12455 0xa000000: 0x40000000, 12456 0xb000000: 0x84010, 12457 0xc000000: 0x80010, 12458 0xd000000: 0x0, 12459 0xe000000: 0x4010, 12460 0xf000000: 0x40080000, 12461 0x800000: 0x40004000, 12462 0x1800000: 0x84010, 12463 0x2800000: 0x10, 12464 0x3800000: 0x40004010, 12465 0x4800000: 0x40084010, 12466 0x5800000: 0x40000000, 12467 0x6800000: 0x80000, 12468 0x7800000: 0x40080010, 12469 0x8800000: 0x80010, 12470 0x9800000: 0x0, 12471 0xa800000: 0x4000, 12472 0xb800000: 0x40080000, 12473 0xc800000: 0x40000010, 12474 0xd800000: 0x84000, 12475 0xe800000: 0x40084000, 12476 0xf800000: 0x4010, 12477 0x10000000: 0x0, 12478 0x11000000: 0x40080010, 12479 0x12000000: 0x40004010, 12480 0x13000000: 0x40084000, 12481 0x14000000: 0x40080000, 12482 0x15000000: 0x10, 12483 0x16000000: 0x84010, 12484 0x17000000: 0x4000, 12485 0x18000000: 0x4010, 12486 0x19000000: 0x80000, 12487 0x1a000000: 0x80010, 12488 0x1b000000: 0x40000010, 12489 0x1c000000: 0x84000, 12490 0x1d000000: 0x40004000, 12491 0x1e000000: 0x40000000, 12492 0x1f000000: 0x40084010, 12493 0x10800000: 0x84010, 12494 0x11800000: 0x80000, 12495 0x12800000: 0x40080000, 12496 0x13800000: 0x4000, 12497 0x14800000: 0x40004000, 12498 0x15800000: 0x40084010, 12499 0x16800000: 0x10, 12500 0x17800000: 0x40000000, 12501 0x18800000: 0x40084000, 12502 0x19800000: 0x40000010, 12503 0x1a800000: 0x40004010, 12504 0x1b800000: 0x80010, 12505 0x1c800000: 0x0, 12506 0x1d800000: 0x4010, 12507 0x1e800000: 0x40080010, 12508 0x1f800000: 0x84000 12509 }, 12510 { 12511 0x0: 0x104, 12512 0x100000: 0x0, 12513 0x200000: 0x4000100, 12514 0x300000: 0x10104, 12515 0x400000: 0x10004, 12516 0x500000: 0x4000004, 12517 0x600000: 0x4010104, 12518 0x700000: 0x4010000, 12519 0x800000: 0x4000000, 12520 0x900000: 0x4010100, 12521 0xa00000: 0x10100, 12522 0xb00000: 0x4010004, 12523 0xc00000: 0x4000104, 12524 0xd00000: 0x10000, 12525 0xe00000: 0x4, 12526 0xf00000: 0x100, 12527 0x80000: 0x4010100, 12528 0x180000: 0x4010004, 12529 0x280000: 0x0, 12530 0x380000: 0x4000100, 12531 0x480000: 0x4000004, 12532 0x580000: 0x10000, 12533 0x680000: 0x10004, 12534 0x780000: 0x104, 12535 0x880000: 0x4, 12536 0x980000: 0x100, 12537 0xa80000: 0x4010000, 12538 0xb80000: 0x10104, 12539 0xc80000: 0x10100, 12540 0xd80000: 0x4000104, 12541 0xe80000: 0x4010104, 12542 0xf80000: 0x4000000, 12543 0x1000000: 0x4010100, 12544 0x1100000: 0x10004, 12545 0x1200000: 0x10000, 12546 0x1300000: 0x4000100, 12547 0x1400000: 0x100, 12548 0x1500000: 0x4010104, 12549 0x1600000: 0x4000004, 12550 0x1700000: 0x0, 12551 0x1800000: 0x4000104, 12552 0x1900000: 0x4000000, 12553 0x1a00000: 0x4, 12554 0x1b00000: 0x10100, 12555 0x1c00000: 0x4010000, 12556 0x1d00000: 0x104, 12557 0x1e00000: 0x10104, 12558 0x1f00000: 0x4010004, 12559 0x1080000: 0x4000000, 12560 0x1180000: 0x104, 12561 0x1280000: 0x4010100, 12562 0x1380000: 0x0, 12563 0x1480000: 0x10004, 12564 0x1580000: 0x4000100, 12565 0x1680000: 0x100, 12566 0x1780000: 0x4010004, 12567 0x1880000: 0x10000, 12568 0x1980000: 0x4010104, 12569 0x1a80000: 0x10104, 12570 0x1b80000: 0x4000004, 12571 0x1c80000: 0x4000104, 12572 0x1d80000: 0x4010000, 12573 0x1e80000: 0x4, 12574 0x1f80000: 0x10100 12575 }, 12576 { 12577 0x0: 0x80401000, 12578 0x10000: 0x80001040, 12579 0x20000: 0x401040, 12580 0x30000: 0x80400000, 12581 0x40000: 0x0, 12582 0x50000: 0x401000, 12583 0x60000: 0x80000040, 12584 0x70000: 0x400040, 12585 0x80000: 0x80000000, 12586 0x90000: 0x400000, 12587 0xa0000: 0x40, 12588 0xb0000: 0x80001000, 12589 0xc0000: 0x80400040, 12590 0xd0000: 0x1040, 12591 0xe0000: 0x1000, 12592 0xf0000: 0x80401040, 12593 0x8000: 0x80001040, 12594 0x18000: 0x40, 12595 0x28000: 0x80400040, 12596 0x38000: 0x80001000, 12597 0x48000: 0x401000, 12598 0x58000: 0x80401040, 12599 0x68000: 0x0, 12600 0x78000: 0x80400000, 12601 0x88000: 0x1000, 12602 0x98000: 0x80401000, 12603 0xa8000: 0x400000, 12604 0xb8000: 0x1040, 12605 0xc8000: 0x80000000, 12606 0xd8000: 0x400040, 12607 0xe8000: 0x401040, 12608 0xf8000: 0x80000040, 12609 0x100000: 0x400040, 12610 0x110000: 0x401000, 12611 0x120000: 0x80000040, 12612 0x130000: 0x0, 12613 0x140000: 0x1040, 12614 0x150000: 0x80400040, 12615 0x160000: 0x80401000, 12616 0x170000: 0x80001040, 12617 0x180000: 0x80401040, 12618 0x190000: 0x80000000, 12619 0x1a0000: 0x80400000, 12620 0x1b0000: 0x401040, 12621 0x1c0000: 0x80001000, 12622 0x1d0000: 0x400000, 12623 0x1e0000: 0x40, 12624 0x1f0000: 0x1000, 12625 0x108000: 0x80400000, 12626 0x118000: 0x80401040, 12627 0x128000: 0x0, 12628 0x138000: 0x401000, 12629 0x148000: 0x400040, 12630 0x158000: 0x80000000, 12631 0x168000: 0x80001040, 12632 0x178000: 0x40, 12633 0x188000: 0x80000040, 12634 0x198000: 0x1000, 12635 0x1a8000: 0x80001000, 12636 0x1b8000: 0x80400040, 12637 0x1c8000: 0x1040, 12638 0x1d8000: 0x80401000, 12639 0x1e8000: 0x400000, 12640 0x1f8000: 0x401040 12641 }, 12642 { 12643 0x0: 0x80, 12644 0x1000: 0x1040000, 12645 0x2000: 0x40000, 12646 0x3000: 0x20000000, 12647 0x4000: 0x20040080, 12648 0x5000: 0x1000080, 12649 0x6000: 0x21000080, 12650 0x7000: 0x40080, 12651 0x8000: 0x1000000, 12652 0x9000: 0x20040000, 12653 0xa000: 0x20000080, 12654 0xb000: 0x21040080, 12655 0xc000: 0x21040000, 12656 0xd000: 0x0, 12657 0xe000: 0x1040080, 12658 0xf000: 0x21000000, 12659 0x800: 0x1040080, 12660 0x1800: 0x21000080, 12661 0x2800: 0x80, 12662 0x3800: 0x1040000, 12663 0x4800: 0x40000, 12664 0x5800: 0x20040080, 12665 0x6800: 0x21040000, 12666 0x7800: 0x20000000, 12667 0x8800: 0x20040000, 12668 0x9800: 0x0, 12669 0xa800: 0x21040080, 12670 0xb800: 0x1000080, 12671 0xc800: 0x20000080, 12672 0xd800: 0x21000000, 12673 0xe800: 0x1000000, 12674 0xf800: 0x40080, 12675 0x10000: 0x40000, 12676 0x11000: 0x80, 12677 0x12000: 0x20000000, 12678 0x13000: 0x21000080, 12679 0x14000: 0x1000080, 12680 0x15000: 0x21040000, 12681 0x16000: 0x20040080, 12682 0x17000: 0x1000000, 12683 0x18000: 0x21040080, 12684 0x19000: 0x21000000, 12685 0x1a000: 0x1040000, 12686 0x1b000: 0x20040000, 12687 0x1c000: 0x40080, 12688 0x1d000: 0x20000080, 12689 0x1e000: 0x0, 12690 0x1f000: 0x1040080, 12691 0x10800: 0x21000080, 12692 0x11800: 0x1000000, 12693 0x12800: 0x1040000, 12694 0x13800: 0x20040080, 12695 0x14800: 0x20000000, 12696 0x15800: 0x1040080, 12697 0x16800: 0x80, 12698 0x17800: 0x21040000, 12699 0x18800: 0x40080, 12700 0x19800: 0x21040080, 12701 0x1a800: 0x0, 12702 0x1b800: 0x21000000, 12703 0x1c800: 0x1000080, 12704 0x1d800: 0x40000, 12705 0x1e800: 0x20040000, 12706 0x1f800: 0x20000080 12707 }, 12708 { 12709 0x0: 0x10000008, 12710 0x100: 0x2000, 12711 0x200: 0x10200000, 12712 0x300: 0x10202008, 12713 0x400: 0x10002000, 12714 0x500: 0x200000, 12715 0x600: 0x200008, 12716 0x700: 0x10000000, 12717 0x800: 0x0, 12718 0x900: 0x10002008, 12719 0xa00: 0x202000, 12720 0xb00: 0x8, 12721 0xc00: 0x10200008, 12722 0xd00: 0x202008, 12723 0xe00: 0x2008, 12724 0xf00: 0x10202000, 12725 0x80: 0x10200000, 12726 0x180: 0x10202008, 12727 0x280: 0x8, 12728 0x380: 0x200000, 12729 0x480: 0x202008, 12730 0x580: 0x10000008, 12731 0x680: 0x10002000, 12732 0x780: 0x2008, 12733 0x880: 0x200008, 12734 0x980: 0x2000, 12735 0xa80: 0x10002008, 12736 0xb80: 0x10200008, 12737 0xc80: 0x0, 12738 0xd80: 0x10202000, 12739 0xe80: 0x202000, 12740 0xf80: 0x10000000, 12741 0x1000: 0x10002000, 12742 0x1100: 0x10200008, 12743 0x1200: 0x10202008, 12744 0x1300: 0x2008, 12745 0x1400: 0x200000, 12746 0x1500: 0x10000000, 12747 0x1600: 0x10000008, 12748 0x1700: 0x202000, 12749 0x1800: 0x202008, 12750 0x1900: 0x0, 12751 0x1a00: 0x8, 12752 0x1b00: 0x10200000, 12753 0x1c00: 0x2000, 12754 0x1d00: 0x10002008, 12755 0x1e00: 0x10202000, 12756 0x1f00: 0x200008, 12757 0x1080: 0x8, 12758 0x1180: 0x202000, 12759 0x1280: 0x200000, 12760 0x1380: 0x10000008, 12761 0x1480: 0x10002000, 12762 0x1580: 0x2008, 12763 0x1680: 0x10202008, 12764 0x1780: 0x10200000, 12765 0x1880: 0x10202000, 12766 0x1980: 0x10200008, 12767 0x1a80: 0x2000, 12768 0x1b80: 0x202008, 12769 0x1c80: 0x200008, 12770 0x1d80: 0x0, 12771 0x1e80: 0x10000000, 12772 0x1f80: 0x10002008 12773 }, 12774 { 12775 0x0: 0x100000, 12776 0x10: 0x2000401, 12777 0x20: 0x400, 12778 0x30: 0x100401, 12779 0x40: 0x2100401, 12780 0x50: 0x0, 12781 0x60: 0x1, 12782 0x70: 0x2100001, 12783 0x80: 0x2000400, 12784 0x90: 0x100001, 12785 0xa0: 0x2000001, 12786 0xb0: 0x2100400, 12787 0xc0: 0x2100000, 12788 0xd0: 0x401, 12789 0xe0: 0x100400, 12790 0xf0: 0x2000000, 12791 0x8: 0x2100001, 12792 0x18: 0x0, 12793 0x28: 0x2000401, 12794 0x38: 0x2100400, 12795 0x48: 0x100000, 12796 0x58: 0x2000001, 12797 0x68: 0x2000000, 12798 0x78: 0x401, 12799 0x88: 0x100401, 12800 0x98: 0x2000400, 12801 0xa8: 0x2100000, 12802 0xb8: 0x100001, 12803 0xc8: 0x400, 12804 0xd8: 0x2100401, 12805 0xe8: 0x1, 12806 0xf8: 0x100400, 12807 0x100: 0x2000000, 12808 0x110: 0x100000, 12809 0x120: 0x2000401, 12810 0x130: 0x2100001, 12811 0x140: 0x100001, 12812 0x150: 0x2000400, 12813 0x160: 0x2100400, 12814 0x170: 0x100401, 12815 0x180: 0x401, 12816 0x190: 0x2100401, 12817 0x1a0: 0x100400, 12818 0x1b0: 0x1, 12819 0x1c0: 0x0, 12820 0x1d0: 0x2100000, 12821 0x1e0: 0x2000001, 12822 0x1f0: 0x400, 12823 0x108: 0x100400, 12824 0x118: 0x2000401, 12825 0x128: 0x2100001, 12826 0x138: 0x1, 12827 0x148: 0x2000000, 12828 0x158: 0x100000, 12829 0x168: 0x401, 12830 0x178: 0x2100400, 12831 0x188: 0x2000001, 12832 0x198: 0x2100000, 12833 0x1a8: 0x0, 12834 0x1b8: 0x2100401, 12835 0x1c8: 0x100401, 12836 0x1d8: 0x400, 12837 0x1e8: 0x2000400, 12838 0x1f8: 0x100001 12839 }, 12840 { 12841 0x0: 0x8000820, 12842 0x1: 0x20000, 12843 0x2: 0x8000000, 12844 0x3: 0x20, 12845 0x4: 0x20020, 12846 0x5: 0x8020820, 12847 0x6: 0x8020800, 12848 0x7: 0x800, 12849 0x8: 0x8020000, 12850 0x9: 0x8000800, 12851 0xa: 0x20800, 12852 0xb: 0x8020020, 12853 0xc: 0x820, 12854 0xd: 0x0, 12855 0xe: 0x8000020, 12856 0xf: 0x20820, 12857 0x80000000: 0x800, 12858 0x80000001: 0x8020820, 12859 0x80000002: 0x8000820, 12860 0x80000003: 0x8000000, 12861 0x80000004: 0x8020000, 12862 0x80000005: 0x20800, 12863 0x80000006: 0x20820, 12864 0x80000007: 0x20, 12865 0x80000008: 0x8000020, 12866 0x80000009: 0x820, 12867 0x8000000a: 0x20020, 12868 0x8000000b: 0x8020800, 12869 0x8000000c: 0x0, 12870 0x8000000d: 0x8020020, 12871 0x8000000e: 0x8000800, 12872 0x8000000f: 0x20000, 12873 0x10: 0x20820, 12874 0x11: 0x8020800, 12875 0x12: 0x20, 12876 0x13: 0x800, 12877 0x14: 0x8000800, 12878 0x15: 0x8000020, 12879 0x16: 0x8020020, 12880 0x17: 0x20000, 12881 0x18: 0x0, 12882 0x19: 0x20020, 12883 0x1a: 0x8020000, 12884 0x1b: 0x8000820, 12885 0x1c: 0x8020820, 12886 0x1d: 0x20800, 12887 0x1e: 0x820, 12888 0x1f: 0x8000000, 12889 0x80000010: 0x20000, 12890 0x80000011: 0x800, 12891 0x80000012: 0x8020020, 12892 0x80000013: 0x20820, 12893 0x80000014: 0x20, 12894 0x80000015: 0x8020000, 12895 0x80000016: 0x8000000, 12896 0x80000017: 0x8000820, 12897 0x80000018: 0x8020820, 12898 0x80000019: 0x8000020, 12899 0x8000001a: 0x8000800, 12900 0x8000001b: 0x0, 12901 0x8000001c: 0x20800, 12902 0x8000001d: 0x820, 12903 0x8000001e: 0x20020, 12904 0x8000001f: 0x8020800 12905 } 12906 ]; 12907 12908 // Masks that select the SBOX input 12909 var SBOX_MASK = [ 12910 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 12911 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 12912 ]; 12913 12914 /** 12915 * DES block cipher algorithm. 12916 */ 12917 var DES = C_algo.DES = BlockCipher.extend({ 12918 _doReset: function () { 12919 // Shortcuts 12920 var key = this._key; 12921 var keyWords = key.words; 12922 12923 // Select 56 bits according to PC1 12924 var keyBits = []; 12925 for (var i = 0; i < 56; i++) { 12926 var keyBitPos = PC1[i] - 1; 12927 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 12928 } 12929 12930 // Assemble 16 subkeys 12931 var subKeys = this._subKeys = []; 12932 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 12933 // Create subkey 12934 var subKey = subKeys[nSubKey] = []; 12935 12936 // Shortcut 12937 var bitShift = BIT_SHIFTS[nSubKey]; 12938 12939 // Select 48 bits according to PC2 12940 for (var i = 0; i < 24; i++) { 12941 // Select from the left 28 key bits 12942 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 12943 12944 // Select from the right 28 key bits 12945 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 12946 } 12947 12948 // Since each subkey is applied to an expanded 32-bit input, 12949 // the subkey can be broken into 8 values scaled to 32-bits, 12950 // which allows the key to be used without expansion 12951 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 12952 for (var i = 1; i < 7; i++) { 12953 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 12954 } 12955 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 12956 } 12957 12958 // Compute inverse subkeys 12959 var invSubKeys = this._invSubKeys = []; 12960 for (var i = 0; i < 16; i++) { 12961 invSubKeys[i] = subKeys[15 - i]; 12962 } 12963 }, 12964 12965 encryptBlock: function (M, offset) { 12966 this._doCryptBlock(M, offset, this._subKeys); 12967 }, 12968 12969 decryptBlock: function (M, offset) { 12970 this._doCryptBlock(M, offset, this._invSubKeys); 12971 }, 12972 12973 _doCryptBlock: function (M, offset, subKeys) { 12974 // Get input 12975 this._lBlock = M[offset]; 12976 this._rBlock = M[offset + 1]; 12977 12978 // Initial permutation 12979 exchangeLR.call(this, 4, 0x0f0f0f0f); 12980 exchangeLR.call(this, 16, 0x0000ffff); 12981 exchangeRL.call(this, 2, 0x33333333); 12982 exchangeRL.call(this, 8, 0x00ff00ff); 12983 exchangeLR.call(this, 1, 0x55555555); 12984 12985 // Rounds 12986 for (var round = 0; round < 16; round++) { 12987 // Shortcuts 12988 var subKey = subKeys[round]; 12989 var lBlock = this._lBlock; 12990 var rBlock = this._rBlock; 12991 12992 // Feistel function 12993 var f = 0; 12994 for (var i = 0; i < 8; i++) { 12995 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 12996 } 12997 this._lBlock = rBlock; 12998 this._rBlock = lBlock ^ f; 12999 } 13000 13001 // Undo swap from last round 13002 var t = this._lBlock; 13003 this._lBlock = this._rBlock; 13004 this._rBlock = t; 13005 13006 // Final permutation 13007 exchangeLR.call(this, 1, 0x55555555); 13008 exchangeRL.call(this, 8, 0x00ff00ff); 13009 exchangeRL.call(this, 2, 0x33333333); 13010 exchangeLR.call(this, 16, 0x0000ffff); 13011 exchangeLR.call(this, 4, 0x0f0f0f0f); 13012 13013 // Set output 13014 M[offset] = this._lBlock; 13015 M[offset + 1] = this._rBlock; 13016 }, 13017 13018 keySize: 64/32, 13019 13020 ivSize: 64/32, 13021 13022 blockSize: 64/32 13023 }); 13024 13025 // Swap bits across the left and right words 13026 function exchangeLR(offset, mask) { 13027 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13028 this._rBlock ^= t; 13029 this._lBlock ^= t << offset; 13030 } 13031 13032 function exchangeRL(offset, mask) { 13033 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13034 this._lBlock ^= t; 13035 this._rBlock ^= t << offset; 13036 } 13037 13038 /** 13039 * Shortcut functions to the cipher's object interface. 13040 * 13041 * @example 13042 * 13043 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13044 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13045 */ 13046 C.DES = BlockCipher._createHelper(DES); 13047 13048 /** 13049 * Triple-DES block cipher algorithm. 13050 */ 13051 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13052 _doReset: function () { 13053 // Shortcuts 13054 var key = this._key; 13055 var keyWords = key.words; 13056 13057 // Create DES instances 13058 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13059 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13060 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13061 }, 13062 13063 encryptBlock: function (M, offset) { 13064 this._des1.encryptBlock(M, offset); 13065 this._des2.decryptBlock(M, offset); 13066 this._des3.encryptBlock(M, offset); 13067 }, 13068 13069 decryptBlock: function (M, offset) { 13070 this._des3.decryptBlock(M, offset); 13071 this._des2.encryptBlock(M, offset); 13072 this._des1.decryptBlock(M, offset); 13073 }, 13074 13075 keySize: 192/32, 13076 13077 ivSize: 64/32, 13078 13079 blockSize: 64/32 13080 }); 13081 13082 /** 13083 * Shortcut functions to the cipher's object interface. 13084 * 13085 * @example 13086 * 13087 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13088 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13089 */ 13090 C.TripleDES = BlockCipher._createHelper(TripleDES); 13091 }()); 13092 13093 13094 return CryptoJS.TripleDES; 13095 13096 })); 13097 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 13098 ;(function (root, factory) { 13099 if (typeof exports === "object") { 13100 // CommonJS 13101 module.exports = exports = factory(require("./core")); 13102 } 13103 else if (typeof define === "function" && define.amd) { 13104 // AMD 13105 define(["./core"], factory); 13106 } 13107 else { 13108 // Global (browser) 13109 factory(root.CryptoJS); 13110 } 13111 }(this, function (CryptoJS) { 13112 13113 (function (undefined) { 13114 // Shortcuts 13115 var C = CryptoJS; 13116 var C_lib = C.lib; 13117 var Base = C_lib.Base; 13118 var X32WordArray = C_lib.WordArray; 13119 13120 /** 13121 * x64 namespace. 13122 */ 13123 var C_x64 = C.x64 = {}; 13124 13125 /** 13126 * A 64-bit word. 13127 */ 13128 var X64Word = C_x64.Word = Base.extend({ 13129 /** 13130 * Initializes a newly created 64-bit word. 13131 * 13132 * @param {number} high The high 32 bits. 13133 * @param {number} low The low 32 bits. 13134 * 13135 * @example 13136 * 13137 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13138 */ 13139 init: function (high, low) { 13140 this.high = high; 13141 this.low = low; 13142 } 13143 13144 /** 13145 * Bitwise NOTs this word. 13146 * 13147 * @return {X64Word} A new x64-Word object after negating. 13148 * 13149 * @example 13150 * 13151 * var negated = x64Word.not(); 13152 */ 13153 // not: function () { 13154 // var high = ~this.high; 13155 // var low = ~this.low; 13156 13157 // return X64Word.create(high, low); 13158 // }, 13159 13160 /** 13161 * Bitwise ANDs this word with the passed word. 13162 * 13163 * @param {X64Word} word The x64-Word to AND with this word. 13164 * 13165 * @return {X64Word} A new x64-Word object after ANDing. 13166 * 13167 * @example 13168 * 13169 * var anded = x64Word.and(anotherX64Word); 13170 */ 13171 // and: function (word) { 13172 // var high = this.high & word.high; 13173 // var low = this.low & word.low; 13174 13175 // return X64Word.create(high, low); 13176 // }, 13177 13178 /** 13179 * Bitwise ORs this word with the passed word. 13180 * 13181 * @param {X64Word} word The x64-Word to OR with this word. 13182 * 13183 * @return {X64Word} A new x64-Word object after ORing. 13184 * 13185 * @example 13186 * 13187 * var ored = x64Word.or(anotherX64Word); 13188 */ 13189 // or: function (word) { 13190 // var high = this.high | word.high; 13191 // var low = this.low | word.low; 13192 13193 // return X64Word.create(high, low); 13194 // }, 13195 13196 /** 13197 * Bitwise XORs this word with the passed word. 13198 * 13199 * @param {X64Word} word The x64-Word to XOR with this word. 13200 * 13201 * @return {X64Word} A new x64-Word object after XORing. 13202 * 13203 * @example 13204 * 13205 * var xored = x64Word.xor(anotherX64Word); 13206 */ 13207 // xor: function (word) { 13208 // var high = this.high ^ word.high; 13209 // var low = this.low ^ word.low; 13210 13211 // return X64Word.create(high, low); 13212 // }, 13213 13214 /** 13215 * Shifts this word n bits to the left. 13216 * 13217 * @param {number} n The number of bits to shift. 13218 * 13219 * @return {X64Word} A new x64-Word object after shifting. 13220 * 13221 * @example 13222 * 13223 * var shifted = x64Word.shiftL(25); 13224 */ 13225 // shiftL: function (n) { 13226 // if (n < 32) { 13227 // var high = (this.high << n) | (this.low >>> (32 - n)); 13228 // var low = this.low << n; 13229 // } else { 13230 // var high = this.low << (n - 32); 13231 // var low = 0; 13232 // } 13233 13234 // return X64Word.create(high, low); 13235 // }, 13236 13237 /** 13238 * Shifts this word n bits to the right. 13239 * 13240 * @param {number} n The number of bits to shift. 13241 * 13242 * @return {X64Word} A new x64-Word object after shifting. 13243 * 13244 * @example 13245 * 13246 * var shifted = x64Word.shiftR(7); 13247 */ 13248 // shiftR: function (n) { 13249 // if (n < 32) { 13250 // var low = (this.low >>> n) | (this.high << (32 - n)); 13251 // var high = this.high >>> n; 13252 // } else { 13253 // var low = this.high >>> (n - 32); 13254 // var high = 0; 13255 // } 13256 13257 // return X64Word.create(high, low); 13258 // }, 13259 13260 /** 13261 * Rotates this word n bits to the left. 13262 * 13263 * @param {number} n The number of bits to rotate. 13264 * 13265 * @return {X64Word} A new x64-Word object after rotating. 13266 * 13267 * @example 13268 * 13269 * var rotated = x64Word.rotL(25); 13270 */ 13271 // rotL: function (n) { 13272 // return this.shiftL(n).or(this.shiftR(64 - n)); 13273 // }, 13274 13275 /** 13276 * Rotates this word n bits to the right. 13277 * 13278 * @param {number} n The number of bits to rotate. 13279 * 13280 * @return {X64Word} A new x64-Word object after rotating. 13281 * 13282 * @example 13283 * 13284 * var rotated = x64Word.rotR(7); 13285 */ 13286 // rotR: function (n) { 13287 // return this.shiftR(n).or(this.shiftL(64 - n)); 13288 // }, 13289 13290 /** 13291 * Adds this word with the passed word. 13292 * 13293 * @param {X64Word} word The x64-Word to add with this word. 13294 * 13295 * @return {X64Word} A new x64-Word object after adding. 13296 * 13297 * @example 13298 * 13299 * var added = x64Word.add(anotherX64Word); 13300 */ 13301 // add: function (word) { 13302 // var low = (this.low + word.low) | 0; 13303 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13304 // var high = (this.high + word.high + carry) | 0; 13305 13306 // return X64Word.create(high, low); 13307 // } 13308 }); 13309 13310 /** 13311 * An array of 64-bit words. 13312 * 13313 * @property {Array} words The array of CryptoJS.x64.Word objects. 13314 * @property {number} sigBytes The number of significant bytes in this word array. 13315 */ 13316 var X64WordArray = C_x64.WordArray = Base.extend({ 13317 /** 13318 * Initializes a newly created word array. 13319 * 13320 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13321 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13322 * 13323 * @example 13324 * 13325 * var wordArray = CryptoJS.x64.WordArray.create(); 13326 * 13327 * var wordArray = CryptoJS.x64.WordArray.create([ 13328 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13329 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13330 * ]); 13331 * 13332 * var wordArray = CryptoJS.x64.WordArray.create([ 13333 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13334 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13335 * ], 10); 13336 */ 13337 init: function (words, sigBytes) { 13338 words = this.words = words || []; 13339 13340 if (sigBytes != undefined) { 13341 this.sigBytes = sigBytes; 13342 } else { 13343 this.sigBytes = words.length * 8; 13344 } 13345 }, 13346 13347 /** 13348 * Converts this 64-bit word array to a 32-bit word array. 13349 * 13350 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13351 * 13352 * @example 13353 * 13354 * var x32WordArray = x64WordArray.toX32(); 13355 */ 13356 toX32: function () { 13357 // Shortcuts 13358 var x64Words = this.words; 13359 var x64WordsLength = x64Words.length; 13360 13361 // Convert 13362 var x32Words = []; 13363 for (var i = 0; i < x64WordsLength; i++) { 13364 var x64Word = x64Words[i]; 13365 x32Words.push(x64Word.high); 13366 x32Words.push(x64Word.low); 13367 } 13368 13369 return X32WordArray.create(x32Words, this.sigBytes); 13370 }, 13371 13372 /** 13373 * Creates a copy of this word array. 13374 * 13375 * @return {X64WordArray} The clone. 13376 * 13377 * @example 13378 * 13379 * var clone = x64WordArray.clone(); 13380 */ 13381 clone: function () { 13382 var clone = Base.clone.call(this); 13383 13384 // Clone "words" array 13385 var words = clone.words = this.words.slice(0); 13386 13387 // Clone each X64Word object 13388 var wordsLength = words.length; 13389 for (var i = 0; i < wordsLength; i++) { 13390 words[i] = words[i].clone(); 13391 } 13392 13393 return clone; 13394 } 13395 }); 13396 }()); 13397 13398 13399 return CryptoJS; 13400 13401 })); 13402 },{"./core":53}],85:[function(require,module,exports){ 13403 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13404 ;(function(root) { 13405 13406 // Detect free variables `exports` 13407 var freeExports = typeof exports == 'object' && exports; 13408 13409 // Detect free variable `module` 13410 var freeModule = typeof module == 'object' && module && 13411 module.exports == freeExports && module; 13412 13413 // Detect free variable `global`, from Node.js or Browserified code, 13414 // and use it as `root` 13415 var freeGlobal = typeof global == 'object' && global; 13416 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13417 root = freeGlobal; 13418 } 13419 13420 /*--------------------------------------------------------------------------*/ 13421 13422 var stringFromCharCode = String.fromCharCode; 13423 13424 // Taken from https://mths.be/punycode 13425 function ucs2decode(string) { 13426 var output = []; 13427 var counter = 0; 13428 var length = string.length; 13429 var value; 13430 var extra; 13431 while (counter < length) { 13432 value = string.charCodeAt(counter++); 13433 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13434 // high surrogate, and there is a next character 13435 extra = string.charCodeAt(counter++); 13436 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13437 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13438 } else { 13439 // unmatched surrogate; only append this code unit, in case the next 13440 // code unit is the high surrogate of a surrogate pair 13441 output.push(value); 13442 counter--; 13443 } 13444 } else { 13445 output.push(value); 13446 } 13447 } 13448 return output; 13449 } 13450 13451 // Taken from https://mths.be/punycode 13452 function ucs2encode(array) { 13453 var length = array.length; 13454 var index = -1; 13455 var value; 13456 var output = ''; 13457 while (++index < length) { 13458 value = array[index]; 13459 if (value > 0xFFFF) { 13460 value -= 0x10000; 13461 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13462 value = 0xDC00 | value & 0x3FF; 13463 } 13464 output += stringFromCharCode(value); 13465 } 13466 return output; 13467 } 13468 13469 function checkScalarValue(codePoint) { 13470 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13471 throw Error( 13472 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13473 ' is not a scalar value' 13474 ); 13475 } 13476 } 13477 /*--------------------------------------------------------------------------*/ 13478 13479 function createByte(codePoint, shift) { 13480 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13481 } 13482 13483 function encodeCodePoint(codePoint) { 13484 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13485 return stringFromCharCode(codePoint); 13486 } 13487 var symbol = ''; 13488 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13489 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13490 } 13491 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13492 checkScalarValue(codePoint); 13493 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13494 symbol += createByte(codePoint, 6); 13495 } 13496 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13497 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13498 symbol += createByte(codePoint, 12); 13499 symbol += createByte(codePoint, 6); 13500 } 13501 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13502 return symbol; 13503 } 13504 13505 function utf8encode(string) { 13506 var codePoints = ucs2decode(string); 13507 var length = codePoints.length; 13508 var index = -1; 13509 var codePoint; 13510 var byteString = ''; 13511 while (++index < length) { 13512 codePoint = codePoints[index]; 13513 byteString += encodeCodePoint(codePoint); 13514 } 13515 return byteString; 13516 } 13517 13518 /*--------------------------------------------------------------------------*/ 13519 13520 function readContinuationByte() { 13521 if (byteIndex >= byteCount) { 13522 throw Error('Invalid byte index'); 13523 } 13524 13525 var continuationByte = byteArray[byteIndex] & 0xFF; 13526 byteIndex++; 13527 13528 if ((continuationByte & 0xC0) == 0x80) { 13529 return continuationByte & 0x3F; 13530 } 13531 13532 // If we end up here, it’s not a continuation byte 13533 throw Error('Invalid continuation byte'); 13534 } 13535 13536 function decodeSymbol() { 13537 var byte1; 13538 var byte2; 13539 var byte3; 13540 var byte4; 13541 var codePoint; 13542 13543 if (byteIndex > byteCount) { 13544 throw Error('Invalid byte index'); 13545 } 13546 13547 if (byteIndex == byteCount) { 13548 return false; 13549 } 13550 13551 // Read first byte 13552 byte1 = byteArray[byteIndex] & 0xFF; 13553 byteIndex++; 13554 13555 // 1-byte sequence (no continuation bytes) 13556 if ((byte1 & 0x80) == 0) { 13557 return byte1; 13558 } 13559 13560 // 2-byte sequence 13561 if ((byte1 & 0xE0) == 0xC0) { 13562 byte2 = readContinuationByte(); 13563 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13564 if (codePoint >= 0x80) { 13565 return codePoint; 13566 } else { 13567 throw Error('Invalid continuation byte'); 13568 } 13569 } 13570 13571 // 3-byte sequence (may include unpaired surrogates) 13572 if ((byte1 & 0xF0) == 0xE0) { 13573 byte2 = readContinuationByte(); 13574 byte3 = readContinuationByte(); 13575 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13576 if (codePoint >= 0x0800) { 13577 checkScalarValue(codePoint); 13578 return codePoint; 13579 } else { 13580 throw Error('Invalid continuation byte'); 13581 } 13582 } 13583 13584 // 4-byte sequence 13585 if ((byte1 & 0xF8) == 0xF0) { 13586 byte2 = readContinuationByte(); 13587 byte3 = readContinuationByte(); 13588 byte4 = readContinuationByte(); 13589 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 13590 (byte3 << 0x06) | byte4; 13591 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 13592 return codePoint; 13593 } 13594 } 13595 13596 throw Error('Invalid UTF-8 detected'); 13597 } 13598 13599 var byteArray; 13600 var byteCount; 13601 var byteIndex; 13602 function utf8decode(byteString) { 13603 byteArray = ucs2decode(byteString); 13604 byteCount = byteArray.length; 13605 byteIndex = 0; 13606 var codePoints = []; 13607 var tmp; 13608 while ((tmp = decodeSymbol()) !== false) { 13609 codePoints.push(tmp); 13610 } 13611 return ucs2encode(codePoints); 13612 } 13613 13614 /*--------------------------------------------------------------------------*/ 13615 13616 var utf8 = { 13617 'version': '2.1.2', 13618 'encode': utf8encode, 13619 'decode': utf8decode 13620 }; 13621 13622 // Some AMD build optimizers, like r.js, check for specific condition patterns 13623 // like the following: 13624 if ( 13625 typeof define == 'function' && 13626 typeof define.amd == 'object' && 13627 define.amd 13628 ) { 13629 define(function() { 13630 return utf8; 13631 }); 13632 } else if (freeExports && !freeExports.nodeType) { 13633 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 13634 freeModule.exports = utf8; 13635 } else { // in Narwhal or RingoJS v0.7.0- 13636 var object = {}; 13637 var hasOwnProperty = object.hasOwnProperty; 13638 for (var key in utf8) { 13639 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 13640 } 13641 } 13642 } else { // in Rhino or a web browser 13643 root.utf8 = utf8; 13644 } 13645 13646 }(this)); 13647 13648 },{}],86:[function(require,module,exports){ 13649 module.exports = XMLHttpRequest; 13650 13651 },{}],"bignumber.js":[function(require,module,exports){ 13652 'use strict'; 13653 13654 module.exports = BigNumber; // jshint ignore:line 13655 13656 13657 },{}],"web3":[function(require,module,exports){ 13658 var Web3 = require('./lib/web3'); 13659 13660 // dont override global variable 13661 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 13662 window.Web3 = Web3; 13663 } 13664 13665 module.exports = Web3; 13666 13667 },{"./lib/web3":22}]},{},["web3"]) 13668 //# sourceMappingURL=web3-light.js.map