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