github.com/unicornultrafoundation/go-u2u@v1.0.0-rc1.0.20240205080301-e74a83d3fadc/internal/jsre/deps/web3.js (about) 1 require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 2 module.exports=[ 3 { 4 "constant": true, 5 "inputs": [ 6 { 7 "name": "_owner", 8 "type": "address" 9 } 10 ], 11 "name": "name", 12 "outputs": [ 13 { 14 "name": "o_name", 15 "type": "bytes32" 16 } 17 ], 18 "type": "function" 19 }, 20 { 21 "constant": true, 22 "inputs": [ 23 { 24 "name": "_name", 25 "type": "bytes32" 26 } 27 ], 28 "name": "owner", 29 "outputs": [ 30 { 31 "name": "", 32 "type": "address" 33 } 34 ], 35 "type": "function" 36 }, 37 { 38 "constant": true, 39 "inputs": [ 40 { 41 "name": "_name", 42 "type": "bytes32" 43 } 44 ], 45 "name": "content", 46 "outputs": [ 47 { 48 "name": "", 49 "type": "bytes32" 50 } 51 ], 52 "type": "function" 53 }, 54 { 55 "constant": true, 56 "inputs": [ 57 { 58 "name": "_name", 59 "type": "bytes32" 60 } 61 ], 62 "name": "addr", 63 "outputs": [ 64 { 65 "name": "", 66 "type": "address" 67 } 68 ], 69 "type": "function" 70 }, 71 { 72 "constant": false, 73 "inputs": [ 74 { 75 "name": "_name", 76 "type": "bytes32" 77 } 78 ], 79 "name": "reserve", 80 "outputs": [], 81 "type": "function" 82 }, 83 { 84 "constant": true, 85 "inputs": [ 86 { 87 "name": "_name", 88 "type": "bytes32" 89 } 90 ], 91 "name": "subRegistrar", 92 "outputs": [ 93 { 94 "name": "", 95 "type": "address" 96 } 97 ], 98 "type": "function" 99 }, 100 { 101 "constant": false, 102 "inputs": [ 103 { 104 "name": "_name", 105 "type": "bytes32" 106 }, 107 { 108 "name": "_newOwner", 109 "type": "address" 110 } 111 ], 112 "name": "transfer", 113 "outputs": [], 114 "type": "function" 115 }, 116 { 117 "constant": false, 118 "inputs": [ 119 { 120 "name": "_name", 121 "type": "bytes32" 122 }, 123 { 124 "name": "_registrar", 125 "type": "address" 126 } 127 ], 128 "name": "setSubRegistrar", 129 "outputs": [], 130 "type": "function" 131 }, 132 { 133 "constant": false, 134 "inputs": [], 135 "name": "Registrar", 136 "outputs": [], 137 "type": "function" 138 }, 139 { 140 "constant": false, 141 "inputs": [ 142 { 143 "name": "_name", 144 "type": "bytes32" 145 }, 146 { 147 "name": "_a", 148 "type": "address" 149 }, 150 { 151 "name": "_primary", 152 "type": "bool" 153 } 154 ], 155 "name": "setAddress", 156 "outputs": [], 157 "type": "function" 158 }, 159 { 160 "constant": false, 161 "inputs": [ 162 { 163 "name": "_name", 164 "type": "bytes32" 165 }, 166 { 167 "name": "_content", 168 "type": "bytes32" 169 } 170 ], 171 "name": "setContent", 172 "outputs": [], 173 "type": "function" 174 }, 175 { 176 "constant": false, 177 "inputs": [ 178 { 179 "name": "_name", 180 "type": "bytes32" 181 } 182 ], 183 "name": "disown", 184 "outputs": [], 185 "type": "function" 186 }, 187 { 188 "anonymous": false, 189 "inputs": [ 190 { 191 "indexed": true, 192 "name": "_name", 193 "type": "bytes32" 194 }, 195 { 196 "indexed": false, 197 "name": "_winner", 198 "type": "address" 199 } 200 ], 201 "name": "AuctionEnded", 202 "type": "event" 203 }, 204 { 205 "anonymous": false, 206 "inputs": [ 207 { 208 "indexed": true, 209 "name": "_name", 210 "type": "bytes32" 211 }, 212 { 213 "indexed": false, 214 "name": "_bidder", 215 "type": "address" 216 }, 217 { 218 "indexed": false, 219 "name": "_value", 220 "type": "uint256" 221 } 222 ], 223 "name": "NewBid", 224 "type": "event" 225 }, 226 { 227 "anonymous": false, 228 "inputs": [ 229 { 230 "indexed": true, 231 "name": "name", 232 "type": "bytes32" 233 } 234 ], 235 "name": "Changed", 236 "type": "event" 237 }, 238 { 239 "anonymous": false, 240 "inputs": [ 241 { 242 "indexed": true, 243 "name": "name", 244 "type": "bytes32" 245 }, 246 { 247 "indexed": true, 248 "name": "addr", 249 "type": "address" 250 } 251 ], 252 "name": "PrimaryChanged", 253 "type": "event" 254 } 255 ] 256 257 },{}],2:[function(require,module,exports){ 258 module.exports=[ 259 { 260 "constant": true, 261 "inputs": [ 262 { 263 "name": "_name", 264 "type": "bytes32" 265 } 266 ], 267 "name": "owner", 268 "outputs": [ 269 { 270 "name": "", 271 "type": "address" 272 } 273 ], 274 "type": "function" 275 }, 276 { 277 "constant": false, 278 "inputs": [ 279 { 280 "name": "_name", 281 "type": "bytes32" 282 }, 283 { 284 "name": "_refund", 285 "type": "address" 286 } 287 ], 288 "name": "disown", 289 "outputs": [], 290 "type": "function" 291 }, 292 { 293 "constant": true, 294 "inputs": [ 295 { 296 "name": "_name", 297 "type": "bytes32" 298 } 299 ], 300 "name": "addr", 301 "outputs": [ 302 { 303 "name": "", 304 "type": "address" 305 } 306 ], 307 "type": "function" 308 }, 309 { 310 "constant": false, 311 "inputs": [ 312 { 313 "name": "_name", 314 "type": "bytes32" 315 } 316 ], 317 "name": "reserve", 318 "outputs": [], 319 "type": "function" 320 }, 321 { 322 "constant": false, 323 "inputs": [ 324 { 325 "name": "_name", 326 "type": "bytes32" 327 }, 328 { 329 "name": "_newOwner", 330 "type": "address" 331 } 332 ], 333 "name": "transfer", 334 "outputs": [], 335 "type": "function" 336 }, 337 { 338 "constant": false, 339 "inputs": [ 340 { 341 "name": "_name", 342 "type": "bytes32" 343 }, 344 { 345 "name": "_a", 346 "type": "address" 347 } 348 ], 349 "name": "setAddr", 350 "outputs": [], 351 "type": "function" 352 }, 353 { 354 "anonymous": false, 355 "inputs": [ 356 { 357 "indexed": true, 358 "name": "name", 359 "type": "bytes32" 360 } 361 ], 362 "name": "Changed", 363 "type": "event" 364 } 365 ] 366 367 },{}],3:[function(require,module,exports){ 368 module.exports=[ 369 { 370 "constant": false, 371 "inputs": [ 372 { 373 "name": "from", 374 "type": "bytes32" 375 }, 376 { 377 "name": "to", 378 "type": "address" 379 }, 380 { 381 "name": "value", 382 "type": "uint256" 383 } 384 ], 385 "name": "transfer", 386 "outputs": [], 387 "type": "function" 388 }, 389 { 390 "constant": false, 391 "inputs": [ 392 { 393 "name": "from", 394 "type": "bytes32" 395 }, 396 { 397 "name": "to", 398 "type": "address" 399 }, 400 { 401 "name": "indirectId", 402 "type": "bytes32" 403 }, 404 { 405 "name": "value", 406 "type": "uint256" 407 } 408 ], 409 "name": "icapTransfer", 410 "outputs": [], 411 "type": "function" 412 }, 413 { 414 "constant": false, 415 "inputs": [ 416 { 417 "name": "to", 418 "type": "bytes32" 419 } 420 ], 421 "name": "deposit", 422 "outputs": [], 423 "payable": true, 424 "type": "function" 425 }, 426 { 427 "anonymous": false, 428 "inputs": [ 429 { 430 "indexed": true, 431 "name": "from", 432 "type": "address" 433 }, 434 { 435 "indexed": false, 436 "name": "value", 437 "type": "uint256" 438 } 439 ], 440 "name": "AnonymousDeposit", 441 "type": "event" 442 }, 443 { 444 "anonymous": false, 445 "inputs": [ 446 { 447 "indexed": true, 448 "name": "from", 449 "type": "address" 450 }, 451 { 452 "indexed": true, 453 "name": "to", 454 "type": "bytes32" 455 }, 456 { 457 "indexed": false, 458 "name": "value", 459 "type": "uint256" 460 } 461 ], 462 "name": "Deposit", 463 "type": "event" 464 }, 465 { 466 "anonymous": false, 467 "inputs": [ 468 { 469 "indexed": true, 470 "name": "from", 471 "type": "bytes32" 472 }, 473 { 474 "indexed": true, 475 "name": "to", 476 "type": "address" 477 }, 478 { 479 "indexed": false, 480 "name": "value", 481 "type": "uint256" 482 } 483 ], 484 "name": "Transfer", 485 "type": "event" 486 }, 487 { 488 "anonymous": false, 489 "inputs": [ 490 { 491 "indexed": true, 492 "name": "from", 493 "type": "bytes32" 494 }, 495 { 496 "indexed": true, 497 "name": "to", 498 "type": "address" 499 }, 500 { 501 "indexed": false, 502 "name": "indirectId", 503 "type": "bytes32" 504 }, 505 { 506 "indexed": false, 507 "name": "value", 508 "type": "uint256" 509 } 510 ], 511 "name": "IcapTransfer", 512 "type": "event" 513 } 514 ] 515 516 },{}],4:[function(require,module,exports){ 517 var f = require('./formatters'); 518 var SolidityType = require('./type'); 519 520 /** 521 * SolidityTypeAddress is a prootype that represents address type 522 * It matches: 523 * address 524 * address[] 525 * address[4] 526 * address[][] 527 * address[3][] 528 * address[][6][], ... 529 */ 530 var SolidityTypeAddress = function () { 531 this._inputFormatter = f.formatInputInt; 532 this._outputFormatter = f.formatOutputAddress; 533 }; 534 535 SolidityTypeAddress.prototype = new SolidityType({}); 536 SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 537 538 SolidityTypeAddress.prototype.isType = function (name) { 539 return !!name.match(/address(\[([0-9]*)\])?/); 540 }; 541 542 module.exports = SolidityTypeAddress; 543 544 },{"./formatters":9,"./type":14}],5:[function(require,module,exports){ 545 var f = require('./formatters'); 546 var SolidityType = require('./type'); 547 548 /** 549 * SolidityTypeBool is a prootype that represents bool type 550 * It matches: 551 * bool 552 * bool[] 553 * bool[4] 554 * bool[][] 555 * bool[3][] 556 * bool[][6][], ... 557 */ 558 var SolidityTypeBool = function () { 559 this._inputFormatter = f.formatInputBool; 560 this._outputFormatter = f.formatOutputBool; 561 }; 562 563 SolidityTypeBool.prototype = new SolidityType({}); 564 SolidityTypeBool.prototype.constructor = SolidityTypeBool; 565 566 SolidityTypeBool.prototype.isType = function (name) { 567 return !!name.match(/^bool(\[([0-9]*)\])*$/); 568 }; 569 570 module.exports = SolidityTypeBool; 571 572 },{"./formatters":9,"./type":14}],6:[function(require,module,exports){ 573 var f = require('./formatters'); 574 var SolidityType = require('./type'); 575 576 /** 577 * SolidityTypeBytes is a prototype that represents the bytes type. 578 * It matches: 579 * bytes 580 * bytes[] 581 * bytes[4] 582 * bytes[][] 583 * bytes[3][] 584 * bytes[][6][], ... 585 * bytes32 586 * bytes8[4] 587 * bytes[3][] 588 */ 589 var SolidityTypeBytes = function () { 590 this._inputFormatter = f.formatInputBytes; 591 this._outputFormatter = f.formatOutputBytes; 592 }; 593 594 SolidityTypeBytes.prototype = new SolidityType({}); 595 SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 596 597 SolidityTypeBytes.prototype.isType = function (name) { 598 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 599 }; 600 601 module.exports = SolidityTypeBytes; 602 603 },{"./formatters":9,"./type":14}],7:[function(require,module,exports){ 604 /* 605 This file is part of web3.js. 606 607 web3.js is free software: you can redistribute it and/or modify 608 it under the terms of the GNU Lesser General Public License as published by 609 the Free Software Foundation, either version 3 of the License, or 610 (at your option) any later version. 611 612 web3.js is distributed in the hope that it will be useful, 613 but WITHOUT ANY WARRANTY; without even the implied warranty of 614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 615 GNU Lesser General Public License for more details. 616 617 You should have received a copy of the GNU Lesser General Public License 618 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 619 */ 620 /** 621 * @file coder.js 622 * @author Marek Kotewicz <marek@ethdev.com> 623 * @date 2015 624 */ 625 626 var f = require('./formatters'); 627 628 var SolidityTypeAddress = require('./address'); 629 var SolidityTypeBool = require('./bool'); 630 var SolidityTypeInt = require('./int'); 631 var SolidityTypeUInt = require('./uint'); 632 var SolidityTypeDynamicBytes = require('./dynamicbytes'); 633 var SolidityTypeString = require('./string'); 634 var SolidityTypeReal = require('./real'); 635 var SolidityTypeUReal = require('./ureal'); 636 var SolidityTypeBytes = require('./bytes'); 637 638 var isDynamic = function (solidityType, type) { 639 return solidityType.isDynamicType(type) || 640 solidityType.isDynamicArray(type); 641 }; 642 643 /** 644 * SolidityCoder prototype should be used to encode/decode solidity params of any type 645 */ 646 var SolidityCoder = function (types) { 647 this._types = types; 648 }; 649 650 /** 651 * This method should be used to transform type to SolidityType 652 * 653 * @method _requireType 654 * @param {String} type 655 * @returns {SolidityType} 656 * @throws {Error} throws if no matching type is found 657 */ 658 SolidityCoder.prototype._requireType = function (type) { 659 var solidityType = this._types.filter(function (t) { 660 return t.isType(type); 661 })[0]; 662 663 if (!solidityType) { 664 throw Error('invalid solidity type!: ' + type); 665 } 666 667 return solidityType; 668 }; 669 670 /** 671 * Should be used to encode plain param 672 * 673 * @method encodeParam 674 * @param {String} type 675 * @param {Object} plain param 676 * @return {String} encoded plain param 677 */ 678 SolidityCoder.prototype.encodeParam = function (type, param) { 679 return this.encodeParams([type], [param]); 680 }; 681 682 /** 683 * Should be used to encode list of params 684 * 685 * @method encodeParams 686 * @param {Array} types 687 * @param {Array} params 688 * @return {String} encoded list of params 689 */ 690 SolidityCoder.prototype.encodeParams = function (types, params) { 691 var solidityTypes = this.getSolidityTypes(types); 692 693 var encodeds = solidityTypes.map(function (solidityType, index) { 694 return solidityType.encode(params[index], types[index]); 695 }); 696 697 var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) { 698 var staticPartLength = solidityType.staticPartLength(types[index]); 699 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 700 701 return acc + (isDynamic(solidityTypes[index], types[index]) ? 702 32 : 703 roundedStaticPartLength); 704 }, 0); 705 706 var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset); 707 708 return result; 709 }; 710 711 SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) { 712 var result = ""; 713 var self = this; 714 715 types.forEach(function (type, i) { 716 if (isDynamic(solidityTypes[i], types[i])) { 717 result += f.formatInputInt(dynamicOffset).encode(); 718 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 719 dynamicOffset += e.length / 2; 720 } else { 721 // don't add length to dynamicOffset. it's already counted 722 result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 723 } 724 725 // TODO: figure out nested arrays 726 }); 727 728 types.forEach(function (type, i) { 729 if (isDynamic(solidityTypes[i], types[i])) { 730 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 731 dynamicOffset += e.length / 2; 732 result += e; 733 } 734 }); 735 return result; 736 }; 737 738 // TODO: refactor whole encoding! 739 SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) { 740 var self = this; 741 if (solidityType.isDynamicArray(type)) { 742 return (function () { 743 // offset was already set 744 var nestedName = solidityType.nestedName(type); 745 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 746 var result = encoded[0]; 747 748 (function () { 749 var previousLength = 2; // in int 750 if (solidityType.isDynamicArray(nestedName)) { 751 for (var i = 1; i < encoded.length; i++) { 752 previousLength += +(encoded[i - 1])[0] || 0; 753 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 754 } 755 } 756 })(); 757 758 // first element is length, skip it 759 (function () { 760 for (var i = 0; i < encoded.length - 1; i++) { 761 var additionalOffset = result / 2; 762 result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset); 763 } 764 })(); 765 766 return result; 767 })(); 768 769 } else if (solidityType.isStaticArray(type)) { 770 return (function () { 771 var nestedName = solidityType.nestedName(type); 772 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 773 var result = ""; 774 775 776 if (solidityType.isDynamicArray(nestedName)) { 777 (function () { 778 var previousLength = 0; // in int 779 for (var i = 0; i < encoded.length; i++) { 780 // calculate length of previous item 781 previousLength += +(encoded[i - 1] || [])[0] || 0; 782 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 783 } 784 })(); 785 } 786 787 (function () { 788 for (var i = 0; i < encoded.length; i++) { 789 var additionalOffset = result / 2; 790 result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset); 791 } 792 })(); 793 794 return result; 795 })(); 796 } 797 798 return encoded; 799 }; 800 801 /** 802 * Should be used to decode bytes to plain param 803 * 804 * @method decodeParam 805 * @param {String} type 806 * @param {String} bytes 807 * @return {Object} plain param 808 */ 809 SolidityCoder.prototype.decodeParam = function (type, bytes) { 810 return this.decodeParams([type], bytes)[0]; 811 }; 812 813 /** 814 * Should be used to decode list of params 815 * 816 * @method decodeParam 817 * @param {Array} types 818 * @param {String} bytes 819 * @return {Array} array of plain params 820 */ 821 SolidityCoder.prototype.decodeParams = function (types, bytes) { 822 var solidityTypes = this.getSolidityTypes(types); 823 var offsets = this.getOffsets(types, solidityTypes); 824 825 return solidityTypes.map(function (solidityType, index) { 826 return solidityType.decode(bytes, offsets[index], types[index], index); 827 }); 828 }; 829 830 SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { 831 var lengths = solidityTypes.map(function (solidityType, index) { 832 return solidityType.staticPartLength(types[index]); 833 }); 834 835 for (var i = 1; i < lengths.length; i++) { 836 // sum with length of previous element 837 lengths[i] += lengths[i - 1]; 838 } 839 840 return lengths.map(function (length, index) { 841 // remove the current length, so the length is sum of previous elements 842 var staticPartLength = solidityTypes[index].staticPartLength(types[index]); 843 return length - staticPartLength; 844 }); 845 }; 846 847 SolidityCoder.prototype.getSolidityTypes = function (types) { 848 var self = this; 849 return types.map(function (type) { 850 return self._requireType(type); 851 }); 852 }; 853 854 var coder = new SolidityCoder([ 855 new SolidityTypeAddress(), 856 new SolidityTypeBool(), 857 new SolidityTypeInt(), 858 new SolidityTypeUInt(), 859 new SolidityTypeDynamicBytes(), 860 new SolidityTypeBytes(), 861 new SolidityTypeString(), 862 new SolidityTypeReal(), 863 new SolidityTypeUReal() 864 ]); 865 866 module.exports = coder; 867 868 },{"./address":4,"./bool":5,"./bytes":6,"./dynamicbytes":8,"./formatters":9,"./int":10,"./real":12,"./string":13,"./uint":15,"./ureal":16}],8:[function(require,module,exports){ 869 var f = require('./formatters'); 870 var SolidityType = require('./type'); 871 872 var SolidityTypeDynamicBytes = function () { 873 this._inputFormatter = f.formatInputDynamicBytes; 874 this._outputFormatter = f.formatOutputDynamicBytes; 875 }; 876 877 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 878 SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 879 880 SolidityTypeDynamicBytes.prototype.isType = function (name) { 881 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 882 }; 883 884 SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 885 return true; 886 }; 887 888 module.exports = SolidityTypeDynamicBytes; 889 890 },{"./formatters":9,"./type":14}],9:[function(require,module,exports){ 891 /* 892 This file is part of web3.js. 893 894 web3.js is free software: you can redistribute it and/or modify 895 it under the terms of the GNU Lesser General Public License as published by 896 the Free Software Foundation, either version 3 of the License, or 897 (at your option) any later version. 898 899 web3.js is distributed in the hope that it will be useful, 900 but WITHOUT ANY WARRANTY; without even the implied warranty of 901 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 902 GNU Lesser General Public License for more details. 903 904 You should have received a copy of the GNU Lesser General Public License 905 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 906 */ 907 /** 908 * @file formatters.js 909 * @author Marek Kotewicz <marek@ethdev.com> 910 * @date 2015 911 */ 912 913 var BigNumber = require('bignumber.js'); 914 var utils = require('../utils/utils'); 915 var c = require('../utils/config'); 916 var SolidityParam = require('./param'); 917 918 919 /** 920 * Formats input value to byte representation of int 921 * If value is negative, return it's two's complement 922 * If the value is floating point, round it down 923 * 924 * @method formatInputInt 925 * @param {String|Number|BigNumber} value that needs to be formatted 926 * @returns {SolidityParam} 927 */ 928 var formatInputInt = function (value) { 929 BigNumber.config(c.U2U_BIGNUMBER_ROUNDING_MODE); 930 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 931 return new SolidityParam(result); 932 }; 933 934 /** 935 * Formats input bytes 936 * 937 * @method formatInputBytes 938 * @param {String} 939 * @returns {SolidityParam} 940 */ 941 var formatInputBytes = function (value) { 942 var result = utils.toHex(value).substr(2); 943 var l = Math.floor((result.length + 63) / 64); 944 result = utils.padRight(result, l * 64); 945 return new SolidityParam(result); 946 }; 947 948 /** 949 * Formats input bytes 950 * 951 * @method formatDynamicInputBytes 952 * @param {String} 953 * @returns {SolidityParam} 954 */ 955 var formatInputDynamicBytes = function (value) { 956 var result = utils.toHex(value).substr(2); 957 var length = result.length / 2; 958 var l = Math.floor((result.length + 63) / 64); 959 result = utils.padRight(result, l * 64); 960 return new SolidityParam(formatInputInt(length).value + result); 961 }; 962 963 /** 964 * Formats input value to byte representation of string 965 * 966 * @method formatInputString 967 * @param {String} 968 * @returns {SolidityParam} 969 */ 970 var formatInputString = function (value) { 971 var result = utils.fromUtf8(value).substr(2); 972 var length = result.length / 2; 973 var l = Math.floor((result.length + 63) / 64); 974 result = utils.padRight(result, l * 64); 975 return new SolidityParam(formatInputInt(length).value + result); 976 }; 977 978 /** 979 * Formats input value to byte representation of bool 980 * 981 * @method formatInputBool 982 * @param {Boolean} 983 * @returns {SolidityParam} 984 */ 985 var formatInputBool = function (value) { 986 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 987 return new SolidityParam(result); 988 }; 989 990 /** 991 * Formats input value to byte representation of real 992 * Values are multiplied by 2^m and encoded as integers 993 * 994 * @method formatInputReal 995 * @param {String|Number|BigNumber} 996 * @returns {SolidityParam} 997 */ 998 var formatInputReal = function (value) { 999 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1000 }; 1001 1002 /** 1003 * Check if input value is negative 1004 * 1005 * @method signedIsNegative 1006 * @param {String} value is hex format 1007 * @returns {Boolean} true if it is negative, otherwise false 1008 */ 1009 var signedIsNegative = function (value) { 1010 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1011 }; 1012 1013 /** 1014 * Formats right-aligned output bytes to int 1015 * 1016 * @method formatOutputInt 1017 * @param {SolidityParam} param 1018 * @returns {BigNumber} right-aligned output bytes formatted to big number 1019 */ 1020 var formatOutputInt = function (param) { 1021 var value = param.staticPart() || "0"; 1022 1023 // check if it's negative number 1024 // it is, return two's complement 1025 if (signedIsNegative(value)) { 1026 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1027 } 1028 return new BigNumber(value, 16); 1029 }; 1030 1031 /** 1032 * Formats right-aligned output bytes to uint 1033 * 1034 * @method formatOutputUInt 1035 * @param {SolidityParam} 1036 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1037 */ 1038 var formatOutputUInt = function (param) { 1039 var value = param.staticPart() || "0"; 1040 return new BigNumber(value, 16); 1041 }; 1042 1043 /** 1044 * Formats right-aligned output bytes to real 1045 * 1046 * @method formatOutputReal 1047 * @param {SolidityParam} 1048 * @returns {BigNumber} input bytes formatted to real 1049 */ 1050 var formatOutputReal = function (param) { 1051 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1052 }; 1053 1054 /** 1055 * Formats right-aligned output bytes to ureal 1056 * 1057 * @method formatOutputUReal 1058 * @param {SolidityParam} 1059 * @returns {BigNumber} input bytes formatted to ureal 1060 */ 1061 var formatOutputUReal = function (param) { 1062 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1063 }; 1064 1065 /** 1066 * Should be used to format output bool 1067 * 1068 * @method formatOutputBool 1069 * @param {SolidityParam} 1070 * @returns {Boolean} right-aligned input bytes formatted to bool 1071 */ 1072 var formatOutputBool = function (param) { 1073 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1074 }; 1075 1076 /** 1077 * Should be used to format output bytes 1078 * 1079 * @method formatOutputBytes 1080 * @param {SolidityParam} left-aligned hex representation of string 1081 * @param {String} name type name 1082 * @returns {String} hex string 1083 */ 1084 var formatOutputBytes = function (param, name) { 1085 var matches = name.match(/^bytes([0-9]*)/); 1086 var size = parseInt(matches[1]); 1087 return '0x' + param.staticPart().slice(0, 2 * size); 1088 }; 1089 1090 /** 1091 * Should be used to format output bytes 1092 * 1093 * @method formatOutputDynamicBytes 1094 * @param {SolidityParam} left-aligned hex representation of string 1095 * @returns {String} hex string 1096 */ 1097 var formatOutputDynamicBytes = function (param) { 1098 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1099 return '0x' + param.dynamicPart().substr(64, length); 1100 }; 1101 1102 /** 1103 * Should be used to format output string 1104 * 1105 * @method formatOutputString 1106 * @param {SolidityParam} left-aligned hex representation of string 1107 * @returns {String} ascii string 1108 */ 1109 var formatOutputString = function (param) { 1110 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1111 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1112 }; 1113 1114 /** 1115 * Should be used to format output address 1116 * 1117 * @method formatOutputAddress 1118 * @param {SolidityParam} right-aligned input bytes 1119 * @returns {String} address 1120 */ 1121 var formatOutputAddress = function (param) { 1122 var value = param.staticPart(); 1123 return "0x" + value.slice(value.length - 40, value.length); 1124 }; 1125 1126 module.exports = { 1127 formatInputInt: formatInputInt, 1128 formatInputBytes: formatInputBytes, 1129 formatInputDynamicBytes: formatInputDynamicBytes, 1130 formatInputString: formatInputString, 1131 formatInputBool: formatInputBool, 1132 formatInputReal: formatInputReal, 1133 formatOutputInt: formatOutputInt, 1134 formatOutputUInt: formatOutputUInt, 1135 formatOutputReal: formatOutputReal, 1136 formatOutputUReal: formatOutputUReal, 1137 formatOutputBool: formatOutputBool, 1138 formatOutputBytes: formatOutputBytes, 1139 formatOutputDynamicBytes: formatOutputDynamicBytes, 1140 formatOutputString: formatOutputString, 1141 formatOutputAddress: formatOutputAddress 1142 }; 1143 1144 },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){ 1145 var f = require('./formatters'); 1146 var SolidityType = require('./type'); 1147 1148 /** 1149 * SolidityTypeInt is a prootype that represents int type 1150 * It matches: 1151 * int 1152 * int[] 1153 * int[4] 1154 * int[][] 1155 * int[3][] 1156 * int[][6][], ... 1157 * int32 1158 * int64[] 1159 * int8[4] 1160 * int256[][] 1161 * int[3][] 1162 * int64[][6][], ... 1163 */ 1164 var SolidityTypeInt = function () { 1165 this._inputFormatter = f.formatInputInt; 1166 this._outputFormatter = f.formatOutputInt; 1167 }; 1168 1169 SolidityTypeInt.prototype = new SolidityType({}); 1170 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1171 1172 SolidityTypeInt.prototype.isType = function (name) { 1173 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1174 }; 1175 1176 module.exports = SolidityTypeInt; 1177 1178 },{"./formatters":9,"./type":14}],11:[function(require,module,exports){ 1179 /* 1180 This file is part of web3.js. 1181 1182 web3.js is free software: you can redistribute it and/or modify 1183 it under the terms of the GNU Lesser General Public License as published by 1184 the Free Software Foundation, either version 3 of the License, or 1185 (at your option) any later version. 1186 1187 web3.js is distributed in the hope that it will be useful, 1188 but WITHOUT ANY WARRANTY; without even the implied warranty of 1189 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1190 GNU Lesser General Public License for more details. 1191 1192 You should have received a copy of the GNU Lesser General Public License 1193 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1194 */ 1195 /** 1196 * @file param.js 1197 * @author Marek Kotewicz <marek@ethdev.com> 1198 * @date 2015 1199 */ 1200 1201 var utils = require('../utils/utils'); 1202 1203 /** 1204 * SolidityParam object prototype. 1205 * Should be used when encoding, decoding solidity bytes 1206 */ 1207 var SolidityParam = function (value, offset) { 1208 this.value = value || ''; 1209 this.offset = offset; // offset in bytes 1210 }; 1211 1212 /** 1213 * This method should be used to get length of params's dynamic part 1214 * 1215 * @method dynamicPartLength 1216 * @returns {Number} length of dynamic part (in bytes) 1217 */ 1218 SolidityParam.prototype.dynamicPartLength = function () { 1219 return this.dynamicPart().length / 2; 1220 }; 1221 1222 /** 1223 * This method should be used to create copy of solidity param with different offset 1224 * 1225 * @method withOffset 1226 * @param {Number} offset length in bytes 1227 * @returns {SolidityParam} new solidity param with applied offset 1228 */ 1229 SolidityParam.prototype.withOffset = function (offset) { 1230 return new SolidityParam(this.value, offset); 1231 }; 1232 1233 /** 1234 * This method should be used to combine solidity params together 1235 * eg. when appending an array 1236 * 1237 * @method combine 1238 * @param {SolidityParam} param with which we should combine 1239 * @param {SolidityParam} result of combination 1240 */ 1241 SolidityParam.prototype.combine = function (param) { 1242 return new SolidityParam(this.value + param.value); 1243 }; 1244 1245 /** 1246 * This method should be called to check if param has dynamic size. 1247 * If it has, it returns true, otherwise false 1248 * 1249 * @method isDynamic 1250 * @returns {Boolean} 1251 */ 1252 SolidityParam.prototype.isDynamic = function () { 1253 return this.offset !== undefined; 1254 }; 1255 1256 /** 1257 * This method should be called to transform offset to bytes 1258 * 1259 * @method offsetAsBytes 1260 * @returns {String} bytes representation of offset 1261 */ 1262 SolidityParam.prototype.offsetAsBytes = function () { 1263 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1264 }; 1265 1266 /** 1267 * This method should be called to get static part of param 1268 * 1269 * @method staticPart 1270 * @returns {String} offset if it is a dynamic param, otherwise value 1271 */ 1272 SolidityParam.prototype.staticPart = function () { 1273 if (!this.isDynamic()) { 1274 return this.value; 1275 } 1276 return this.offsetAsBytes(); 1277 }; 1278 1279 /** 1280 * This method should be called to get dynamic part of param 1281 * 1282 * @method dynamicPart 1283 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1284 */ 1285 SolidityParam.prototype.dynamicPart = function () { 1286 return this.isDynamic() ? this.value : ''; 1287 }; 1288 1289 /** 1290 * This method should be called to encode param 1291 * 1292 * @method encode 1293 * @returns {String} 1294 */ 1295 SolidityParam.prototype.encode = function () { 1296 return this.staticPart() + this.dynamicPart(); 1297 }; 1298 1299 /** 1300 * This method should be called to encode array of params 1301 * 1302 * @method encodeList 1303 * @param {Array[SolidityParam]} params 1304 * @returns {String} 1305 */ 1306 SolidityParam.encodeList = function (params) { 1307 1308 // updating offsets 1309 var totalOffset = params.length * 32; 1310 var offsetParams = params.map(function (param) { 1311 if (!param.isDynamic()) { 1312 return param; 1313 } 1314 var offset = totalOffset; 1315 totalOffset += param.dynamicPartLength(); 1316 return param.withOffset(offset); 1317 }); 1318 1319 // encode everything! 1320 return offsetParams.reduce(function (result, param) { 1321 return result + param.dynamicPart(); 1322 }, offsetParams.reduce(function (result, param) { 1323 return result + param.staticPart(); 1324 }, '')); 1325 }; 1326 1327 1328 1329 module.exports = SolidityParam; 1330 1331 1332 },{"../utils/utils":20}],12:[function(require,module,exports){ 1333 var f = require('./formatters'); 1334 var SolidityType = require('./type'); 1335 1336 /** 1337 * SolidityTypeReal is a prootype that represents real type 1338 * It matches: 1339 * real 1340 * real[] 1341 * real[4] 1342 * real[][] 1343 * real[3][] 1344 * real[][6][], ... 1345 * real32 1346 * real64[] 1347 * real8[4] 1348 * real256[][] 1349 * real[3][] 1350 * real64[][6][], ... 1351 */ 1352 var SolidityTypeReal = function () { 1353 this._inputFormatter = f.formatInputReal; 1354 this._outputFormatter = f.formatOutputReal; 1355 }; 1356 1357 SolidityTypeReal.prototype = new SolidityType({}); 1358 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1359 1360 SolidityTypeReal.prototype.isType = function (name) { 1361 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1362 }; 1363 1364 module.exports = SolidityTypeReal; 1365 1366 },{"./formatters":9,"./type":14}],13:[function(require,module,exports){ 1367 var f = require('./formatters'); 1368 var SolidityType = require('./type'); 1369 1370 var SolidityTypeString = function () { 1371 this._inputFormatter = f.formatInputString; 1372 this._outputFormatter = f.formatOutputString; 1373 }; 1374 1375 SolidityTypeString.prototype = new SolidityType({}); 1376 SolidityTypeString.prototype.constructor = SolidityTypeString; 1377 1378 SolidityTypeString.prototype.isType = function (name) { 1379 return !!name.match(/^string(\[([0-9]*)\])*$/); 1380 }; 1381 1382 SolidityTypeString.prototype.isDynamicType = function () { 1383 return true; 1384 }; 1385 1386 module.exports = SolidityTypeString; 1387 1388 },{"./formatters":9,"./type":14}],14:[function(require,module,exports){ 1389 var f = require('./formatters'); 1390 var SolidityParam = require('./param'); 1391 1392 /** 1393 * SolidityType prototype is used to encode/decode solidity params of certain type 1394 */ 1395 var SolidityType = function (config) { 1396 this._inputFormatter = config.inputFormatter; 1397 this._outputFormatter = config.outputFormatter; 1398 }; 1399 1400 /** 1401 * Should be used to determine if this SolidityType do match given name 1402 * 1403 * @method isType 1404 * @param {String} name 1405 * @return {Bool} true if type match this SolidityType, otherwise false 1406 */ 1407 SolidityType.prototype.isType = function (name) { 1408 throw "this method should be overrwritten for type " + name; 1409 }; 1410 1411 /** 1412 * Should be used to determine what is the length of static part in given type 1413 * 1414 * @method staticPartLength 1415 * @param {String} name 1416 * @return {Number} length of static part in bytes 1417 */ 1418 SolidityType.prototype.staticPartLength = function (name) { 1419 // If name isn't an array then treat it like a single element array. 1420 return (this.nestedTypes(name) || ['[1]']) 1421 .map(function (type) { 1422 // the length of the nested array 1423 return parseInt(type.slice(1, -1), 10) || 1; 1424 }) 1425 .reduce(function (previous, current) { 1426 return previous * current; 1427 // all basic types are 32 bytes long 1428 }, 32); 1429 }; 1430 1431 /** 1432 * Should be used to determine if type is dynamic array 1433 * eg: 1434 * "type[]" => true 1435 * "type[4]" => false 1436 * 1437 * @method isDynamicArray 1438 * @param {String} name 1439 * @return {Bool} true if the type is dynamic array 1440 */ 1441 SolidityType.prototype.isDynamicArray = function (name) { 1442 var nestedTypes = this.nestedTypes(name); 1443 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1444 }; 1445 1446 /** 1447 * Should be used to determine if type is static array 1448 * eg: 1449 * "type[]" => false 1450 * "type[4]" => true 1451 * 1452 * @method isStaticArray 1453 * @param {String} name 1454 * @return {Bool} true if the type is static array 1455 */ 1456 SolidityType.prototype.isStaticArray = function (name) { 1457 var nestedTypes = this.nestedTypes(name); 1458 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1459 }; 1460 1461 /** 1462 * Should return length of static array 1463 * eg. 1464 * "int[32]" => 32 1465 * "int256[14]" => 14 1466 * "int[2][3]" => 3 1467 * "int" => 1 1468 * "int[1]" => 1 1469 * "int[]" => 1 1470 * 1471 * @method staticArrayLength 1472 * @param {String} name 1473 * @return {Number} static array length 1474 */ 1475 SolidityType.prototype.staticArrayLength = function (name) { 1476 var nestedTypes = this.nestedTypes(name); 1477 if (nestedTypes) { 1478 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1479 } 1480 return 1; 1481 }; 1482 1483 /** 1484 * Should return nested type 1485 * eg. 1486 * "int[32]" => "int" 1487 * "int256[14]" => "int256" 1488 * "int[2][3]" => "int[2]" 1489 * "int" => "int" 1490 * "int[]" => "int" 1491 * 1492 * @method nestedName 1493 * @param {String} name 1494 * @return {String} nested name 1495 */ 1496 SolidityType.prototype.nestedName = function (name) { 1497 // remove last [] in name 1498 var nestedTypes = this.nestedTypes(name); 1499 if (!nestedTypes) { 1500 return name; 1501 } 1502 1503 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1504 }; 1505 1506 /** 1507 * Should return true if type has dynamic size by default 1508 * such types are "string", "bytes" 1509 * 1510 * @method isDynamicType 1511 * @param {String} name 1512 * @return {Bool} true if is dynamic, otherwise false 1513 */ 1514 SolidityType.prototype.isDynamicType = function () { 1515 return false; 1516 }; 1517 1518 /** 1519 * Should return array of nested types 1520 * eg. 1521 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1522 * "int[] => ["[]"] 1523 * "int" => null 1524 * 1525 * @method nestedTypes 1526 * @param {String} name 1527 * @return {Array} array of nested types 1528 */ 1529 SolidityType.prototype.nestedTypes = function (name) { 1530 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1531 return name.match(/(\[[0-9]*\])/g); 1532 }; 1533 1534 /** 1535 * Should be used to encode the value 1536 * 1537 * @method encode 1538 * @param {Object} value 1539 * @param {String} name 1540 * @return {String} encoded value 1541 */ 1542 SolidityType.prototype.encode = function (value, name) { 1543 var self = this; 1544 if (this.isDynamicArray(name)) { 1545 1546 return (function () { 1547 var length = value.length; // in int 1548 var nestedName = self.nestedName(name); 1549 1550 var result = []; 1551 result.push(f.formatInputInt(length).encode()); 1552 1553 value.forEach(function (v) { 1554 result.push(self.encode(v, nestedName)); 1555 }); 1556 1557 return result; 1558 })(); 1559 1560 } else if (this.isStaticArray(name)) { 1561 1562 return (function () { 1563 var length = self.staticArrayLength(name); // in int 1564 var nestedName = self.nestedName(name); 1565 1566 var result = []; 1567 for (var i = 0; i < length; i++) { 1568 result.push(self.encode(value[i], nestedName)); 1569 } 1570 1571 return result; 1572 })(); 1573 1574 } 1575 1576 return this._inputFormatter(value, name).encode(); 1577 }; 1578 1579 /** 1580 * Should be used to decode value from bytes 1581 * 1582 * @method decode 1583 * @param {String} bytes 1584 * @param {Number} offset in bytes 1585 * @param {String} name type name 1586 * @returns {Object} decoded value 1587 */ 1588 SolidityType.prototype.decode = function (bytes, offset, name) { 1589 var self = this; 1590 1591 if (this.isDynamicArray(name)) { 1592 1593 return (function () { 1594 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1595 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1596 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1597 1598 var nestedName = self.nestedName(name); 1599 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1600 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1601 var result = []; 1602 1603 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1604 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1605 } 1606 1607 return result; 1608 })(); 1609 1610 } else if (this.isStaticArray(name)) { 1611 1612 return (function () { 1613 var length = self.staticArrayLength(name); // in int 1614 var arrayStart = offset; // in bytes 1615 1616 var nestedName = self.nestedName(name); 1617 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1618 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1619 var result = []; 1620 1621 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1622 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1623 } 1624 1625 return result; 1626 })(); 1627 } else if (this.isDynamicType(name)) { 1628 1629 return (function () { 1630 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1631 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1632 var roundedLength = Math.floor((length + 31) / 32); // in int 1633 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0); 1634 return self._outputFormatter(param, name); 1635 })(); 1636 } 1637 1638 var length = this.staticPartLength(name); 1639 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1640 return this._outputFormatter(param, name); 1641 }; 1642 1643 module.exports = SolidityType; 1644 1645 },{"./formatters":9,"./param":11}],15:[function(require,module,exports){ 1646 var f = require('./formatters'); 1647 var SolidityType = require('./type'); 1648 1649 /** 1650 * SolidityTypeUInt is a prootype that represents uint type 1651 * It matches: 1652 * uint 1653 * uint[] 1654 * uint[4] 1655 * uint[][] 1656 * uint[3][] 1657 * uint[][6][], ... 1658 * uint32 1659 * uint64[] 1660 * uint8[4] 1661 * uint256[][] 1662 * uint[3][] 1663 * uint64[][6][], ... 1664 */ 1665 var SolidityTypeUInt = function () { 1666 this._inputFormatter = f.formatInputInt; 1667 this._outputFormatter = f.formatOutputUInt; 1668 }; 1669 1670 SolidityTypeUInt.prototype = new SolidityType({}); 1671 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1672 1673 SolidityTypeUInt.prototype.isType = function (name) { 1674 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1675 }; 1676 1677 module.exports = SolidityTypeUInt; 1678 1679 },{"./formatters":9,"./type":14}],16:[function(require,module,exports){ 1680 var f = require('./formatters'); 1681 var SolidityType = require('./type'); 1682 1683 /** 1684 * SolidityTypeUReal is a prootype that represents ureal type 1685 * It matches: 1686 * ureal 1687 * ureal[] 1688 * ureal[4] 1689 * ureal[][] 1690 * ureal[3][] 1691 * ureal[][6][], ... 1692 * ureal32 1693 * ureal64[] 1694 * ureal8[4] 1695 * ureal256[][] 1696 * ureal[3][] 1697 * ureal64[][6][], ... 1698 */ 1699 var SolidityTypeUReal = function () { 1700 this._inputFormatter = f.formatInputReal; 1701 this._outputFormatter = f.formatOutputUReal; 1702 }; 1703 1704 SolidityTypeUReal.prototype = new SolidityType({}); 1705 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1706 1707 SolidityTypeUReal.prototype.isType = function (name) { 1708 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1709 }; 1710 1711 module.exports = SolidityTypeUReal; 1712 1713 },{"./formatters":9,"./type":14}],17:[function(require,module,exports){ 1714 'use strict'; 1715 1716 // go env doesn't have and need XMLHttpRequest 1717 if (typeof XMLHttpRequest === 'undefined') { 1718 exports.XMLHttpRequest = {}; 1719 } else { 1720 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1721 } 1722 1723 1724 },{}],18:[function(require,module,exports){ 1725 /* 1726 This file is part of web3.js. 1727 1728 web3.js is free software: you can redistribute it and/or modify 1729 it under the terms of the GNU Lesser General Public License as published by 1730 the Free Software Foundation, either version 3 of the License, or 1731 (at your option) any later version. 1732 1733 web3.js is distributed in the hope that it will be useful, 1734 but WITHOUT ANY WARRANTY; without even the implied warranty of 1735 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1736 GNU Lesser General Public License for more details. 1737 1738 You should have received a copy of the GNU Lesser General Public License 1739 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1740 */ 1741 /** @file config.js 1742 * @authors: 1743 * Marek Kotewicz <marek@ethdev.com> 1744 * @date 2015 1745 */ 1746 1747 /** 1748 * Utils 1749 * 1750 * @module utils 1751 */ 1752 1753 /** 1754 * Utility functions 1755 * 1756 * @class [utils] config 1757 * @constructor 1758 */ 1759 1760 1761 /// required to define U2U_BIGNUMBER_ROUNDING_MODE 1762 var BigNumber = require('bignumber.js'); 1763 1764 var U2U_UNITS = [ 1765 'wei', 1766 'kwei', 1767 'Mwei', 1768 'Gwei', 1769 'szabo', 1770 'finney', 1771 'femtoether', 1772 'picoether', 1773 'nanoether', 1774 'microether', 1775 'milliether', 1776 'nano', 1777 'micro', 1778 'milli', 1779 'ether', 1780 'grand', 1781 'Mether', 1782 'Gether', 1783 'Tether', 1784 'Pether', 1785 'Eether', 1786 'Zether', 1787 'Yether', 1788 'Nether', 1789 'Dether', 1790 'Vether', 1791 'Uether' 1792 ]; 1793 1794 module.exports = { 1795 U2U_PADDING: 32, 1796 U2U_SIGNATURE_LENGTH: 4, 1797 U2U_UNITS: U2U_UNITS, 1798 U2U_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1799 U2U_POLLING_TIMEOUT: 1000/2, 1800 defaultBlock: 'latest', 1801 defaultAccount: undefined 1802 }; 1803 1804 1805 },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){ 1806 /* 1807 This file is part of web3.js. 1808 1809 web3.js is free software: you can redistribute it and/or modify 1810 it under the terms of the GNU Lesser General Public License as published by 1811 the Free Software Foundation, either version 3 of the License, or 1812 (at your option) any later version. 1813 1814 web3.js is distributed in the hope that it will be useful, 1815 but WITHOUT ANY WARRANTY; without even the implied warranty of 1816 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1817 GNU Lesser General Public License for more details. 1818 1819 You should have received a copy of the GNU Lesser General Public License 1820 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1821 */ 1822 /** 1823 * @file sha3.js 1824 * @author Marek Kotewicz <marek@ethdev.com> 1825 * @date 2015 1826 */ 1827 1828 var CryptoJS = require('crypto-js'); 1829 var sha3 = require('crypto-js/sha3'); 1830 1831 module.exports = function (value, options) { 1832 if (options && options.encoding === 'hex') { 1833 if (value.length > 2 && value.substr(0, 2) === '0x') { 1834 value = value.substr(2); 1835 } 1836 value = CryptoJS.enc.Hex.parse(value); 1837 } 1838 1839 return sha3(value, { 1840 outputLength: 256 1841 }).toString(); 1842 }; 1843 1844 1845 },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){ 1846 /* 1847 This file is part of web3.js. 1848 1849 web3.js is free software: you can redistribute it and/or modify 1850 it under the terms of the GNU Lesser General Public License as published by 1851 the Free Software Foundation, either version 3 of the License, or 1852 (at your option) any later version. 1853 1854 web3.js is distributed in the hope that it will be useful, 1855 but WITHOUT ANY WARRANTY; without even the implied warranty of 1856 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1857 GNU Lesser General Public License for more details. 1858 1859 You should have received a copy of the GNU Lesser General Public License 1860 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1861 */ 1862 /** 1863 * @file utils.js 1864 * @author Marek Kotewicz <marek@ethdev.com> 1865 * @date 2015 1866 */ 1867 1868 /** 1869 * Utils 1870 * 1871 * @module utils 1872 */ 1873 1874 /** 1875 * Utility functions 1876 * 1877 * @class [utils] utils 1878 * @constructor 1879 */ 1880 1881 1882 var BigNumber = require('bignumber.js'); 1883 var sha3 = require('./sha3.js'); 1884 var utf8 = require('utf8'); 1885 1886 var unitMap = { 1887 'noether': '0', 1888 'wei': '1', 1889 'kwei': '1000', 1890 'Kwei': '1000', 1891 'babbage': '1000', 1892 'femtoether': '1000', 1893 'mwei': '1000000', 1894 'Mwei': '1000000', 1895 'lovelace': '1000000', 1896 'picoether': '1000000', 1897 'gwei': '1000000000', 1898 'Gwei': '1000000000', 1899 'shannon': '1000000000', 1900 'nanoether': '1000000000', 1901 'nano': '1000000000', 1902 'szabo': '1000000000000', 1903 'microether': '1000000000000', 1904 'micro': '1000000000000', 1905 'finney': '1000000000000000', 1906 'milliether': '1000000000000000', 1907 'milli': '1000000000000000', 1908 'ether': '1000000000000000000', 1909 'kether': '1000000000000000000000', 1910 'grand': '1000000000000000000000', 1911 'mether': '1000000000000000000000000', 1912 'gether': '1000000000000000000000000000', 1913 'tether': '1000000000000000000000000000000', 1914 1915 'nou2u': '0', 1916 'femtou2u': '1000', 1917 'picou2u': '1000000', 1918 'nanou2u': '1000000000', 1919 'microu2u': '1000000000000', 1920 'milliu2u': '1000000000000000', 1921 'u2u': '1000000000000000000', 1922 'ku2u': '1000000000000000000000', 1923 'mu2u': '1000000000000000000000000', 1924 'gu2u': '1000000000000000000000000000', 1925 'tu2u': '1000000000000000000000000000000' 1926 }; 1927 1928 /** 1929 * Should be called to validator descriptions to hex-string over JSON 1930 * 1931 * @method toMoniker 1932 * @param {String} name is validator name in utf8 1933 * @param {String} description is validator description in utf8 1934 * @param {String} webSite is validator web site URL 1935 * @returns {String} hex string with JSON data 1936 */ 1937 var toMoniker = function (name, description, webSite) { 1938 var jsData = { 1939 Name: name, 1940 Description: description, 1941 WebSite: webSite 1942 }; 1943 1944 return toHex(jsData) 1945 }; 1946 1947 /** 1948 * Should be called to pad string to expected length 1949 * 1950 * @method padLeft 1951 * @param {String} string to be padded 1952 * @param {Number} characters that result string should have 1953 * @param {String} sign, by default 0 1954 * @returns {String} right aligned string 1955 */ 1956 var padLeft = function (string, chars, sign) { 1957 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1958 }; 1959 1960 /** 1961 * Should be called to pad string to expected length 1962 * 1963 * @method padRight 1964 * @param {String} string to be padded 1965 * @param {Number} characters that result string should have 1966 * @param {String} sign, by default 0 1967 * @returns {String} right aligned string 1968 */ 1969 var padRight = function (string, chars, sign) { 1970 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1971 }; 1972 1973 /** 1974 * Should be called to get utf8 from it's hex representation 1975 * 1976 * @method toUtf8 1977 * @param {String} string in hex 1978 * @returns {String} ascii string representation of hex value 1979 */ 1980 var toUtf8 = function(hex) { 1981 // Find termination 1982 var str = ""; 1983 var i = 0, l = hex.length; 1984 if (hex.substring(0, 2) === '0x') { 1985 i = 2; 1986 } 1987 for (; i < l; i+=2) { 1988 var code = parseInt(hex.substr(i, 2), 16); 1989 if (code === 0) 1990 break; 1991 str += String.fromCharCode(code); 1992 } 1993 1994 return utf8.decode(str); 1995 }; 1996 1997 /** 1998 * Should be called to get ascii from it's hex representation 1999 * 2000 * @method toAscii 2001 * @param {String} string in hex 2002 * @returns {String} ascii string representation of hex value 2003 */ 2004 var toAscii = function(hex) { 2005 // Find termination 2006 var str = ""; 2007 var i = 0, l = hex.length; 2008 if (hex.substring(0, 2) === '0x') { 2009 i = 2; 2010 } 2011 for (; i < l; i+=2) { 2012 var code = parseInt(hex.substr(i, 2), 16); 2013 str += String.fromCharCode(code); 2014 } 2015 2016 return str; 2017 }; 2018 2019 /** 2020 * Should be called to get hex representation (prefixed by 0x) of utf8 string 2021 * 2022 * @method fromUtf8 2023 * @param {String} string 2024 * @param {Number} optional padding 2025 * @returns {String} hex representation of input string 2026 */ 2027 var fromUtf8 = function(str) { 2028 str = utf8.encode(str); 2029 var hex = ""; 2030 for(var i = 0; i < str.length; i++) { 2031 var code = str.charCodeAt(i); 2032 if (code === 0) 2033 break; 2034 var n = code.toString(16); 2035 hex += n.length < 2 ? '0' + n : n; 2036 } 2037 2038 return "0x" + hex; 2039 }; 2040 2041 /** 2042 * Should be called to get hex representation (prefixed by 0x) of ascii string 2043 * 2044 * @method fromAscii 2045 * @param {String} string 2046 * @param {Number} optional padding 2047 * @returns {String} hex representation of input string 2048 */ 2049 var fromAscii = function(str) { 2050 var hex = ""; 2051 for(var i = 0; i < str.length; i++) { 2052 var code = str.charCodeAt(i); 2053 var n = code.toString(16); 2054 hex += n.length < 2 ? '0' + n : n; 2055 } 2056 2057 return "0x" + hex; 2058 }; 2059 2060 /** 2061 * Should be used to create full function/event name from json abi 2062 * 2063 * @method transformToFullName 2064 * @param {Object} json-abi 2065 * @return {String} full fnction/event name 2066 */ 2067 var transformToFullName = function (json) { 2068 if (json.name.indexOf('(') !== -1) { 2069 return json.name; 2070 } 2071 2072 var typeName = json.inputs.map(function(i){return i.type; }).join(); 2073 return json.name + '(' + typeName + ')'; 2074 }; 2075 2076 /** 2077 * Should be called to get display name of contract function 2078 * 2079 * @method extractDisplayName 2080 * @param {String} name of function/event 2081 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2082 */ 2083 var extractDisplayName = function (name) { 2084 var length = name.indexOf('('); 2085 return length !== -1 ? name.substr(0, length) : name; 2086 }; 2087 2088 /// @returns overloaded part of function/event name 2089 var extractTypeName = function (name) { 2090 /// TODO: make it invulnerable 2091 var length = name.indexOf('('); 2092 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2093 }; 2094 2095 /** 2096 * Converts value to it's decimal representation in string 2097 * 2098 * @method toDecimal 2099 * @param {String|Number|BigNumber} 2100 * @return {String} 2101 */ 2102 var toDecimal = function (value) { 2103 return toBigNumber(value).toNumber(); 2104 }; 2105 2106 /** 2107 * Converts value to it's hex representation 2108 * 2109 * @method fromDecimal 2110 * @param {String|Number|BigNumber} 2111 * @return {String} 2112 */ 2113 var fromDecimal = function (value) { 2114 var number = toBigNumber(value); 2115 var result = number.toString(16); 2116 2117 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2118 }; 2119 2120 /** 2121 * Auto converts any given value into it's hex representation. 2122 * 2123 * And even stringifys objects before. 2124 * 2125 * @method toHex 2126 * @param {String|Number|BigNumber|Object} 2127 * @return {String} 2128 */ 2129 var toHex = function (val) { 2130 /*jshint maxcomplexity: 8 */ 2131 2132 if (isBoolean(val)) 2133 return fromDecimal(+val); 2134 2135 if (isBigNumber(val)) 2136 return fromDecimal(val); 2137 2138 if (typeof val === 'object') 2139 return fromUtf8(JSON.stringify(val)); 2140 2141 // if its a negative number, pass it through fromDecimal 2142 if (isString(val)) { 2143 if (val.indexOf('-0x') === 0) 2144 return fromDecimal(val); 2145 else if(val.indexOf('0x') === 0) 2146 return val; 2147 else if (!isFinite(val)) 2148 return fromAscii(val); 2149 } 2150 2151 return fromDecimal(val); 2152 }; 2153 2154 /** 2155 * Returns value of unit in Wei 2156 * 2157 * @method getValueOfUnit 2158 * @param {String} unit the unit to convert to, default ether 2159 * @returns {BigNumber} value of the unit (in Wei) 2160 * @throws error if the unit is not correct:w 2161 */ 2162 var getValueOfUnit = function (unit) { 2163 unit = unit ? unit.toLowerCase() : 'ether'; 2164 var unitValue = unitMap[unit]; 2165 if (unitValue === undefined) { 2166 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2167 } 2168 return new BigNumber(unitValue, 10); 2169 }; 2170 2171 /** 2172 * Takes a number of wei and converts it to any other ether unit. 2173 * 2174 * Possible units are: 2175 * SI Short SI Full Effigy Other 2176 * - kwei femtoether babbage 2177 * - mwei picoether lovelace 2178 * - gwei nanoether shannon nano 2179 * - -- microether szabo micro 2180 * - -- milliether finney milli 2181 * - ether -- -- 2182 * - kether -- grand 2183 * - mether 2184 * - gether 2185 * - tether 2186 * 2187 * @method fromWei 2188 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2189 * @param {String} unit the unit to convert to, default ether 2190 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2191 */ 2192 var fromWei = function(number, unit) { 2193 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2194 2195 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2196 }; 2197 2198 /** 2199 * Takes a number of a unit and converts it to wei. 2200 * 2201 * Possible units are: 2202 * SI Short SI Full Effigy Other 2203 * - kwei femtoether babbage 2204 * - mwei picoether lovelace 2205 * - gwei nanoether shannon nano 2206 * - -- microether szabo micro 2207 * - -- microether szabo micro 2208 * - -- milliether finney milli 2209 * - ether -- -- 2210 * - kether -- grand 2211 * - mether 2212 * - gether 2213 * - tether 2214 * 2215 * @method toWei 2216 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2217 * @param {String} unit the unit to convert from, default ether 2218 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2219 */ 2220 var toWei = function(number, unit) { 2221 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2222 2223 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2224 }; 2225 2226 /** 2227 * Takes an input and transforms it into a bignumber 2228 * 2229 * @method toBigNumber 2230 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2231 * @return {BigNumber} BigNumber 2232 */ 2233 var toBigNumber = function(number) { 2234 /*jshint maxcomplexity:5 */ 2235 number = number || 0; 2236 if (isBigNumber(number)) 2237 return number; 2238 2239 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2240 return new BigNumber(number.replace('0x',''), 16); 2241 } 2242 2243 return new BigNumber(number.toString(10), 10); 2244 }; 2245 2246 /** 2247 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2248 * 2249 * @method toTwosComplement 2250 * @param {Number|String|BigNumber} 2251 * @return {BigNumber} 2252 */ 2253 var toTwosComplement = function (number) { 2254 var bigNumber = toBigNumber(number).round(); 2255 if (bigNumber.lessThan(0)) { 2256 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2257 } 2258 return bigNumber; 2259 }; 2260 2261 /** 2262 * Checks if the given string is strictly an address 2263 * 2264 * @method isStrictAddress 2265 * @param {String} address the given HEX address 2266 * @return {Boolean} 2267 */ 2268 var isStrictAddress = function (address) { 2269 return /^0x[0-9a-f]{40}$/i.test(address); 2270 }; 2271 2272 /** 2273 * Checks if the given string is an address 2274 * 2275 * @method isAddress 2276 * @param {String} address the given HEX address 2277 * @return {Boolean} 2278 */ 2279 var isAddress = function (address) { 2280 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2281 // check if it has the basic requirements of an address 2282 return false; 2283 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2284 // If it's all small caps or all caps, return true 2285 return true; 2286 } else { 2287 // Otherwise check each case 2288 return isChecksumAddress(address); 2289 } 2290 }; 2291 2292 /** 2293 * Checks if the given string is a checksummed address 2294 * 2295 * @method isChecksumAddress 2296 * @param {String} address the given HEX address 2297 * @return {Boolean} 2298 */ 2299 var isChecksumAddress = function (address) { 2300 // Check each case 2301 address = address.replace('0x',''); 2302 var addressHash = sha3(address.toLowerCase()); 2303 2304 for (var i = 0; i < 40; i++ ) { 2305 // the nth letter should be uppercase if the nth digit of casemap is 1 2306 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2307 return false; 2308 } 2309 } 2310 return true; 2311 }; 2312 2313 2314 2315 /** 2316 * Makes a checksum address 2317 * 2318 * @method toChecksumAddress 2319 * @param {String} address the given HEX address 2320 * @return {String} 2321 */ 2322 var toChecksumAddress = function (address) { 2323 if (typeof address === 'undefined') return ''; 2324 2325 address = address.toLowerCase().replace('0x',''); 2326 var addressHash = sha3(address); 2327 var checksumAddress = '0x'; 2328 2329 for (var i = 0; i < address.length; i++ ) { 2330 // If ith character is 9 to f then make it uppercase 2331 if (parseInt(addressHash[i], 16) > 7) { 2332 checksumAddress += address[i].toUpperCase(); 2333 } else { 2334 checksumAddress += address[i]; 2335 } 2336 } 2337 return checksumAddress; 2338 }; 2339 2340 /** 2341 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2342 * 2343 * @method toAddress 2344 * @param {String} address 2345 * @return {String} formatted address 2346 */ 2347 var toAddress = function (address) { 2348 if (isStrictAddress(address)) { 2349 return address; 2350 } 2351 2352 if (/^[0-9a-f]{40}$/.test(address)) { 2353 return '0x' + address; 2354 } 2355 2356 return '0x' + padLeft(toHex(address).substr(2), 40); 2357 }; 2358 2359 /** 2360 * Returns true if object is BigNumber, otherwise false 2361 * 2362 * @method isBigNumber 2363 * @param {Object} 2364 * @return {Boolean} 2365 */ 2366 var isBigNumber = function (object) { 2367 return object instanceof BigNumber || 2368 (object && object.constructor && object.constructor.name === 'BigNumber'); 2369 }; 2370 2371 /** 2372 * Returns true if object is string, otherwise false 2373 * 2374 * @method isString 2375 * @param {Object} 2376 * @return {Boolean} 2377 */ 2378 var isString = function (object) { 2379 return typeof object === 'string' || 2380 (object && object.constructor && object.constructor.name === 'String'); 2381 }; 2382 2383 /** 2384 * Returns true if object is function, otherwise false 2385 * 2386 * @method isFunction 2387 * @param {Object} 2388 * @return {Boolean} 2389 */ 2390 var isFunction = function (object) { 2391 return typeof object === 'function'; 2392 }; 2393 2394 /** 2395 * Returns true if object is Objet, otherwise false 2396 * 2397 * @method isObject 2398 * @param {Object} 2399 * @return {Boolean} 2400 */ 2401 var isObject = function (object) { 2402 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2403 }; 2404 2405 /** 2406 * Returns true if object is boolean, otherwise false 2407 * 2408 * @method isBoolean 2409 * @param {Object} 2410 * @return {Boolean} 2411 */ 2412 var isBoolean = function (object) { 2413 return typeof object === 'boolean'; 2414 }; 2415 2416 /** 2417 * Returns true if object is array, otherwise false 2418 * 2419 * @method isArray 2420 * @param {Object} 2421 * @return {Boolean} 2422 */ 2423 var isArray = function (object) { 2424 return object instanceof Array; 2425 }; 2426 2427 /** 2428 * Returns true if given string is valid json object 2429 * 2430 * @method isJson 2431 * @param {String} 2432 * @return {Boolean} 2433 */ 2434 var isJson = function (str) { 2435 try { 2436 return !!JSON.parse(str); 2437 } catch (e) { 2438 return false; 2439 } 2440 }; 2441 2442 /** 2443 * Returns true if given string is a valid Ethereum block header bloom. 2444 * 2445 * @method isBloom 2446 * @param {String} hex encoded bloom filter 2447 * @return {Boolean} 2448 */ 2449 var isBloom = function (bloom) { 2450 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2451 return false; 2452 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2453 return true; 2454 } 2455 return false; 2456 }; 2457 2458 /** 2459 * Returns true if given string is a valid log topic. 2460 * 2461 * @method isTopic 2462 * @param {String} hex encoded topic 2463 * @return {Boolean} 2464 */ 2465 var isTopic = function (topic) { 2466 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2467 return false; 2468 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2469 return true; 2470 } 2471 return false; 2472 }; 2473 2474 module.exports = { 2475 toMoniker: toMoniker, 2476 padLeft: padLeft, 2477 padRight: padRight, 2478 toHex: toHex, 2479 toDecimal: toDecimal, 2480 fromDecimal: fromDecimal, 2481 toUtf8: toUtf8, 2482 toAscii: toAscii, 2483 fromUtf8: fromUtf8, 2484 fromAscii: fromAscii, 2485 transformToFullName: transformToFullName, 2486 extractDisplayName: extractDisplayName, 2487 extractTypeName: extractTypeName, 2488 toWei: toWei, 2489 fromWei: fromWei, 2490 toBigNumber: toBigNumber, 2491 toTwosComplement: toTwosComplement, 2492 toAddress: toAddress, 2493 isBigNumber: isBigNumber, 2494 isStrictAddress: isStrictAddress, 2495 isAddress: isAddress, 2496 isChecksumAddress: isChecksumAddress, 2497 toChecksumAddress: toChecksumAddress, 2498 isFunction: isFunction, 2499 isString: isString, 2500 isObject: isObject, 2501 isBoolean: isBoolean, 2502 isArray: isArray, 2503 isJson: isJson, 2504 isBloom: isBloom, 2505 isTopic: isTopic, 2506 }; 2507 2508 },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){ 2509 module.exports={ 2510 "version": "0.20.1" 2511 } 2512 2513 },{}],22:[function(require,module,exports){ 2514 /* 2515 This file is part of web3.js. 2516 2517 web3.js is free software: you can redistribute it and/or modify 2518 it under the terms of the GNU Lesser General Public License as published by 2519 the Free Software Foundation, either version 3 of the License, or 2520 (at your option) any later version. 2521 2522 web3.js is distributed in the hope that it will be useful, 2523 but WITHOUT ANY WARRANTY; without even the implied warranty of 2524 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2525 GNU Lesser General Public License for more details. 2526 2527 You should have received a copy of the GNU Lesser General Public License 2528 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2529 */ 2530 /** 2531 * @file web3.js 2532 * @authors: 2533 * Jeffrey Wilcke <jeff@ethdev.com> 2534 * Marek Kotewicz <marek@ethdev.com> 2535 * Marian Oancea <marian@ethdev.com> 2536 * Fabian Vogelsteller <fabian@ethdev.com> 2537 * Gav Wood <g@ethdev.com> 2538 * @date 2014 2539 */ 2540 2541 var RequestManager = require('./web3/requestmanager'); 2542 var Iban = require('./web3/iban'); 2543 var U2u = require('./web3/methods/u2u'); 2544 var Debug = require('./web3/methods/debug'); 2545 var Sfc = require('./web3/methods/sfc'); 2546 var Abft = require('./web3/methods/abft'); 2547 var Dag = require('./web3/methods/dag'); 2548 var DB = require('./web3/methods/db'); 2549 var Shh = require('./web3/methods/shh'); 2550 var Net = require('./web3/methods/net'); 2551 var Personal = require('./web3/methods/personal'); 2552 var Swarm = require('./web3/methods/swarm'); 2553 var Settings = require('./web3/settings'); 2554 var version = require('./version.json'); 2555 var utils = require('./utils/utils'); 2556 var sha3 = require('./utils/sha3'); 2557 var extend = require('./web3/extend'); 2558 var Batch = require('./web3/batch'); 2559 var Property = require('./web3/property'); 2560 var HttpProvider = require('./web3/httpprovider'); 2561 var IpcProvider = require('./web3/ipcprovider'); 2562 var BigNumber = require('bignumber.js'); 2563 2564 2565 2566 function Web3 (provider) { 2567 this._requestManager = new RequestManager(provider); 2568 this.currentProvider = provider; 2569 this.u2u = new U2u(this); 2570 this.debug = new Debug(this); 2571 this.sfc = new Sfc(this); 2572 this.abft = new Abft(this); 2573 this.dag = new Dag(this); 2574 this.db = new DB(this); 2575 this.shh = new Shh(this); 2576 this.net = new Net(this); 2577 this.personal = new Personal(this); 2578 this.bzz = new Swarm(this); 2579 this.settings = new Settings(); 2580 this.version = { 2581 api: version.version 2582 }; 2583 this.providers = { 2584 HttpProvider: HttpProvider, 2585 IpcProvider: IpcProvider 2586 }; 2587 this._extend = extend(this); 2588 this._extend({ 2589 properties: properties() 2590 }); 2591 } 2592 2593 // expose providers on the class 2594 Web3.providers = { 2595 HttpProvider: HttpProvider, 2596 IpcProvider: IpcProvider 2597 }; 2598 2599 Web3.prototype.setProvider = function (provider) { 2600 this._requestManager.setProvider(provider); 2601 this.currentProvider = provider; 2602 }; 2603 2604 Web3.prototype.reset = function (keepIsSyncing) { 2605 this._requestManager.reset(keepIsSyncing); 2606 this.settings = new Settings(); 2607 }; 2608 2609 Web3.prototype.BigNumber = BigNumber; 2610 Web3.prototype.toHex = utils.toHex; 2611 Web3.prototype.toAscii = utils.toAscii; 2612 Web3.prototype.toUtf8 = utils.toUtf8; 2613 Web3.prototype.fromAscii = utils.fromAscii; 2614 Web3.prototype.fromUtf8 = utils.fromUtf8; 2615 Web3.prototype.toDecimal = utils.toDecimal; 2616 Web3.prototype.fromDecimal = utils.fromDecimal; 2617 Web3.prototype.toBigNumber = utils.toBigNumber; 2618 Web3.prototype.toWei = utils.toWei; 2619 Web3.prototype.fromWei = utils.fromWei; 2620 Web3.prototype.isAddress = utils.isAddress; 2621 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2622 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2623 Web3.prototype.isIBAN = utils.isIBAN; 2624 Web3.prototype.padLeft = utils.padLeft; 2625 Web3.prototype.padRight = utils.padRight; 2626 Web3.prototype.toMoniker = utils.toMoniker; 2627 2628 Web3.prototype.sha3 = function(string, options) { 2629 return '0x' + sha3(string, options); 2630 }; 2631 2632 /** 2633 * Transforms direct icap to address 2634 */ 2635 Web3.prototype.fromICAP = function (icap) { 2636 var iban = new Iban(icap); 2637 return iban.address(); 2638 }; 2639 2640 var properties = function () { 2641 return [ 2642 new Property({ 2643 name: 'version.node', 2644 getter: 'web3_clientVersion' 2645 }), 2646 new Property({ 2647 name: 'version.network', 2648 getter: 'net_version', 2649 inputFormatter: utils.toDecimal 2650 }), 2651 new Property({ 2652 name: 'version.u2u', 2653 getter: 'eth_protocolVersion', 2654 inputFormatter: utils.toDecimal 2655 }) 2656 ]; 2657 }; 2658 2659 Web3.prototype.isConnected = function(){ 2660 return (this.currentProvider && this.currentProvider.isConnected()); 2661 }; 2662 2663 Web3.prototype.createBatch = function () { 2664 return new Batch(this); 2665 }; 2666 2667 module.exports = Web3; 2668 2669 2670 },{"./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/u2u":38,"./web3/methods/debug":380,"./web3/methods/sfc":381,"./web3/methods/abft":382,"./web3/methods/dag":383,"./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){ 2671 /* 2672 This file is part of web3.js. 2673 2674 web3.js is free software: you can redistribute it and/or modify 2675 it under the terms of the GNU Lesser General Public License as published by 2676 the Free Software Foundation, either version 3 of the License, or 2677 (at your option) any later version. 2678 2679 web3.js is distributed in the hope that it will be useful, 2680 but WITHOUT ANY WARRANTY; without even the implied warranty of 2681 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2682 GNU Lesser General Public License for more details. 2683 2684 You should have received a copy of the GNU Lesser General Public License 2685 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2686 */ 2687 /** 2688 * @file allevents.js 2689 * @author Marek Kotewicz <marek@ethdev.com> 2690 * @date 2014 2691 */ 2692 2693 var sha3 = require('../utils/sha3'); 2694 var SolidityEvent = require('./event'); 2695 var formatters = require('./formatters'); 2696 var utils = require('../utils/utils'); 2697 var Filter = require('./filter'); 2698 var watches = require('./methods/watches'); 2699 2700 var AllSolidityEvents = function (requestManager, json, address) { 2701 this._requestManager = requestManager; 2702 this._json = json; 2703 this._address = address; 2704 }; 2705 2706 AllSolidityEvents.prototype.encode = function (options) { 2707 options = options || {}; 2708 var result = {}; 2709 2710 ['fromBlock', 'toBlock'].filter(function (f) { 2711 return options[f] !== undefined; 2712 }).forEach(function (f) { 2713 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2714 }); 2715 2716 result.address = this._address; 2717 2718 return result; 2719 }; 2720 2721 AllSolidityEvents.prototype.decode = function (data) { 2722 data.data = data.data || ''; 2723 data.topics = data.topics || []; 2724 2725 var eventTopic = data.topics[0].slice(2); 2726 var match = this._json.filter(function (j) { 2727 return eventTopic === sha3(utils.transformToFullName(j)); 2728 })[0]; 2729 2730 if (!match) { // cannot find matching event? 2731 console.warn('cannot find event for log'); 2732 return data; 2733 } 2734 2735 var event = new SolidityEvent(this._requestManager, match, this._address); 2736 return event.decode(data); 2737 }; 2738 2739 AllSolidityEvents.prototype.execute = function (options, callback) { 2740 2741 if (utils.isFunction(arguments[arguments.length - 1])) { 2742 callback = arguments[arguments.length - 1]; 2743 if(arguments.length === 1) 2744 options = null; 2745 } 2746 2747 var o = this.encode(options); 2748 var formatter = this.decode.bind(this); 2749 return new Filter(o, 'u2u', this._requestManager, watches.u2u(), formatter, callback); 2750 }; 2751 2752 AllSolidityEvents.prototype.attachToContract = function (contract) { 2753 var execute = this.execute.bind(this); 2754 contract.allEvents = execute; 2755 }; 2756 2757 module.exports = AllSolidityEvents; 2758 2759 2760 },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){ 2761 /* 2762 This file is part of web3.js. 2763 2764 web3.js is free software: you can redistribute it and/or modify 2765 it under the terms of the GNU Lesser General Public License as published by 2766 the Free Software Foundation, either version 3 of the License, or 2767 (at your option) any later version. 2768 2769 web3.js is distributed in the hope that it will be useful, 2770 but WITHOUT ANY WARRANTY; without even the implied warranty of 2771 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2772 GNU Lesser General Public License for more details. 2773 2774 You should have received a copy of the GNU Lesser General Public License 2775 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2776 */ 2777 /** 2778 * @file batch.js 2779 * @author Marek Kotewicz <marek@ethdev.com> 2780 * @date 2015 2781 */ 2782 2783 var Jsonrpc = require('./jsonrpc'); 2784 var errors = require('./errors'); 2785 2786 var Batch = function (web3) { 2787 this.requestManager = web3._requestManager; 2788 this.requests = []; 2789 }; 2790 2791 /** 2792 * Should be called to add create new request to batch request 2793 * 2794 * @method add 2795 * @param {Object} jsonrpc requet object 2796 */ 2797 Batch.prototype.add = function (request) { 2798 this.requests.push(request); 2799 }; 2800 2801 /** 2802 * Should be called to execute batch request 2803 * 2804 * @method execute 2805 */ 2806 Batch.prototype.execute = function () { 2807 var requests = this.requests; 2808 this.requestManager.sendBatch(requests, function (err, results) { 2809 results = results || []; 2810 requests.map(function (request, index) { 2811 return results[index] || {}; 2812 }).forEach(function (result, index) { 2813 if (requests[index].callback) { 2814 2815 if (!Jsonrpc.isValidResponse(result)) { 2816 return requests[index].callback(errors.InvalidResponse(result)); 2817 } 2818 2819 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2820 } 2821 }); 2822 }); 2823 }; 2824 2825 module.exports = Batch; 2826 2827 2828 },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){ 2829 /* 2830 This file is part of web3.js. 2831 2832 web3.js is free software: you can redistribute it and/or modify 2833 it under the terms of the GNU Lesser General Public License as published by 2834 the Free Software Foundation, either version 3 of the License, or 2835 (at your option) any later version. 2836 2837 web3.js is distributed in the hope that it will be useful, 2838 but WITHOUT ANY WARRANTY; without even the implied warranty of 2839 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2840 GNU Lesser General Public License for more details. 2841 2842 You should have received a copy of the GNU Lesser General Public License 2843 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2844 */ 2845 /** 2846 * @file contract.js 2847 * @author Marek Kotewicz <marek@ethdev.com> 2848 * @date 2014 2849 */ 2850 2851 var utils = require('../utils/utils'); 2852 var coder = require('../solidity/coder'); 2853 var SolidityEvent = require('./event'); 2854 var SolidityFunction = require('./function'); 2855 var AllEvents = require('./allevents'); 2856 2857 /** 2858 * Should be called to encode constructor params 2859 * 2860 * @method encodeConstructorParams 2861 * @param {Array} abi 2862 * @param {Array} constructor params 2863 */ 2864 var encodeConstructorParams = function (abi, params) { 2865 return abi.filter(function (json) { 2866 return json.type === 'constructor' && json.inputs.length === params.length; 2867 }).map(function (json) { 2868 return json.inputs.map(function (input) { 2869 return input.type; 2870 }); 2871 }).map(function (types) { 2872 return coder.encodeParams(types, params); 2873 })[0] || ''; 2874 }; 2875 2876 /** 2877 * Should be called to add functions to contract object 2878 * 2879 * @method addFunctionsToContract 2880 * @param {Contract} contract 2881 * @param {Array} abi 2882 */ 2883 var addFunctionsToContract = function (contract) { 2884 contract.abi.filter(function (json) { 2885 return json.type === 'function'; 2886 }).map(function (json) { 2887 return new SolidityFunction(contract._u2u, json, contract.address); 2888 }).forEach(function (f) { 2889 f.attachToContract(contract); 2890 }); 2891 }; 2892 2893 /** 2894 * Should be called to add events to contract object 2895 * 2896 * @method addEventsToContract 2897 * @param {Contract} contract 2898 * @param {Array} abi 2899 */ 2900 var addEventsToContract = function (contract) { 2901 var events = contract.abi.filter(function (json) { 2902 return json.type === 'event'; 2903 }); 2904 2905 var All = new AllEvents(contract._u2u._requestManager, events, contract.address); 2906 All.attachToContract(contract); 2907 2908 events.map(function (json) { 2909 return new SolidityEvent(contract._u2u._requestManager, json, contract.address); 2910 }).forEach(function (e) { 2911 e.attachToContract(contract); 2912 }); 2913 }; 2914 2915 2916 /** 2917 * Should be called to check if the contract gets properly deployed on the blockchain. 2918 * 2919 * @method checkForContractAddress 2920 * @param {Object} contract 2921 * @param {Function} callback 2922 * @returns {Undefined} 2923 */ 2924 var checkForContractAddress = function(contract, callback){ 2925 var count = 0, 2926 callbackFired = false; 2927 2928 // wait for receipt 2929 var filter = contract._u2u.filter('latest', function(e){ 2930 if (!e && !callbackFired) { 2931 count++; 2932 2933 // stop watching after 50 blocks (timeout) 2934 if (count > 50) { 2935 2936 filter.stopWatching(function() {}); 2937 callbackFired = true; 2938 2939 if (callback) 2940 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2941 else 2942 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2943 2944 2945 } else { 2946 2947 contract._u2u.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 2948 if(receipt && !callbackFired) { 2949 2950 contract._u2u.getCode(receipt.contractAddress, function(e, code){ 2951 /*jshint maxcomplexity: 6 */ 2952 2953 if(callbackFired || !code) 2954 return; 2955 2956 filter.stopWatching(function() {}); 2957 callbackFired = true; 2958 2959 if(code.length > 3) { 2960 2961 // console.log('Contract code deployed!'); 2962 2963 contract.address = receipt.contractAddress; 2964 2965 // attach events and methods again after we have 2966 addFunctionsToContract(contract); 2967 addEventsToContract(contract); 2968 2969 // call callback for the second time 2970 if(callback) 2971 callback(null, contract); 2972 2973 } else { 2974 if(callback) 2975 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 2976 else 2977 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 2978 } 2979 }); 2980 } 2981 }); 2982 } 2983 } 2984 }); 2985 }; 2986 2987 /** 2988 * Should be called to create new ContractFactory instance 2989 * 2990 * @method ContractFactory 2991 * @param {Array} abi 2992 */ 2993 var ContractFactory = function (u2u, abi) { 2994 this.u2u = u2u; 2995 this.abi = abi; 2996 2997 /** 2998 * Should be called to create new contract on a blockchain 2999 * 3000 * @method new 3001 * @param {Any} contract constructor param1 (optional) 3002 * @param {Any} contract constructor param2 (optional) 3003 * @param {Object} contract transaction object (required) 3004 * @param {Function} callback 3005 * @returns {Contract} returns contract instance 3006 */ 3007 this.new = function () { 3008 /*jshint maxcomplexity: 7 */ 3009 3010 var contract = new Contract(this.u2u, this.abi); 3011 3012 // parse arguments 3013 var options = {}; // required! 3014 var callback; 3015 3016 var args = Array.prototype.slice.call(arguments); 3017 if (utils.isFunction(args[args.length - 1])) { 3018 callback = args.pop(); 3019 } 3020 3021 var last = args[args.length - 1]; 3022 if (utils.isObject(last) && !utils.isArray(last)) { 3023 options = args.pop(); 3024 } 3025 3026 if (options.value > 0) { 3027 var constructorAbi = abi.filter(function (json) { 3028 return json.type === 'constructor' && json.inputs.length === args.length; 3029 })[0] || {}; 3030 3031 if (!constructorAbi.payable) { 3032 throw new Error('Cannot send value to non-payable constructor'); 3033 } 3034 } 3035 3036 var bytes = encodeConstructorParams(this.abi, args); 3037 options.data += bytes; 3038 3039 if (callback) { 3040 3041 // wait for the contract address and check if the code was deployed 3042 this.u2u.sendTransaction(options, function (err, hash) { 3043 if (err) { 3044 callback(err); 3045 } else { 3046 // add the transaction hash 3047 contract.transactionHash = hash; 3048 3049 // call callback for the first time 3050 callback(null, contract); 3051 3052 checkForContractAddress(contract, callback); 3053 } 3054 }); 3055 } else { 3056 var hash = this.u2u.sendTransaction(options); 3057 // add the transaction hash 3058 contract.transactionHash = hash; 3059 checkForContractAddress(contract); 3060 } 3061 3062 return contract; 3063 }; 3064 3065 this.new.getData = this.getData.bind(this); 3066 }; 3067 3068 /** 3069 * Should be called to create new ContractFactory 3070 * 3071 * @method contract 3072 * @param {Array} abi 3073 * @returns {ContractFactory} new contract factory 3074 */ 3075 //var contract = function (abi) { 3076 //return new ContractFactory(abi); 3077 //}; 3078 3079 3080 3081 /** 3082 * Should be called to get access to existing contract on a blockchain 3083 * 3084 * @method at 3085 * @param {Address} contract address (required) 3086 * @param {Function} callback {optional) 3087 * @returns {Contract} returns contract if no callback was passed, 3088 * otherwise calls callback function (err, contract) 3089 */ 3090 ContractFactory.prototype.at = function (address, callback) { 3091 var contract = new Contract(this.u2u, this.abi, address); 3092 3093 // this functions are not part of prototype, 3094 // because we don't want to spoil the interface 3095 addFunctionsToContract(contract); 3096 addEventsToContract(contract); 3097 3098 if (callback) { 3099 callback(null, contract); 3100 } 3101 return contract; 3102 }; 3103 3104 /** 3105 * Gets the data, which is data to deploy plus constructor params 3106 * 3107 * @method getData 3108 */ 3109 ContractFactory.prototype.getData = function () { 3110 var options = {}; // required! 3111 var args = Array.prototype.slice.call(arguments); 3112 3113 var last = args[args.length - 1]; 3114 if (utils.isObject(last) && !utils.isArray(last)) { 3115 options = args.pop(); 3116 } 3117 3118 var bytes = encodeConstructorParams(this.abi, args); 3119 options.data += bytes; 3120 3121 return options.data; 3122 }; 3123 3124 /** 3125 * Should be called to create new contract instance 3126 * 3127 * @method Contract 3128 * @param {Array} abi 3129 * @param {Address} contract address 3130 */ 3131 var Contract = function (u2u, abi, address) { 3132 this._u2u = u2u; 3133 this.transactionHash = null; 3134 this.address = address; 3135 this.abi = abi; 3136 }; 3137 3138 module.exports = ContractFactory; 3139 3140 },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){ 3141 /* 3142 This file is part of web3.js. 3143 3144 web3.js is free software: you can redistribute it and/or modify 3145 it under the terms of the GNU Lesser General Public License as published by 3146 the Free Software Foundation, either version 3 of the License, or 3147 (at your option) any later version. 3148 3149 web3.js is distributed in the hope that it will be useful, 3150 but WITHOUT ANY WARRANTY; without even the implied warranty of 3151 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3152 GNU Lesser General Public License for more details. 3153 3154 You should have received a copy of the GNU Lesser General Public License 3155 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3156 */ 3157 /** 3158 * @file errors.js 3159 * @author Marek Kotewicz <marek@ethdev.com> 3160 * @date 2015 3161 */ 3162 3163 module.exports = { 3164 InvalidNumberOfSolidityArgs: function () { 3165 return new Error('Invalid number of arguments to Solidity function'); 3166 }, 3167 InvalidNumberOfRPCParams: function () { 3168 return new Error('Invalid number of input parameters to RPC method'); 3169 }, 3170 InvalidConnection: function (host){ 3171 return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 3172 }, 3173 InvalidProvider: function () { 3174 return new Error('Provider not set or invalid'); 3175 }, 3176 InvalidResponse: function (result){ 3177 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3178 return new Error(message); 3179 }, 3180 ConnectionTimeout: function (ms){ 3181 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3182 } 3183 }; 3184 3185 },{}],27:[function(require,module,exports){ 3186 /* 3187 This file is part of web3.js. 3188 3189 web3.js is free software: you can redistribute it and/or modify 3190 it under the terms of the GNU Lesser General Public License as published by 3191 the Free Software Foundation, either version 3 of the License, or 3192 (at your option) any later version. 3193 3194 web3.js is distributed in the hope that it will be useful, 3195 but WITHOUT ANY WARRANTY; without even the implied warranty of 3196 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3197 GNU Lesser General Public License for more details. 3198 3199 You should have received a copy of the GNU Lesser General Public License 3200 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3201 */ 3202 /** 3203 * @file event.js 3204 * @author Marek Kotewicz <marek@ethdev.com> 3205 * @date 2014 3206 */ 3207 3208 var utils = require('../utils/utils'); 3209 var coder = require('../solidity/coder'); 3210 var formatters = require('./formatters'); 3211 var sha3 = require('../utils/sha3'); 3212 var Filter = require('./filter'); 3213 var watches = require('./methods/watches'); 3214 3215 /** 3216 * This prototype should be used to create event filters 3217 */ 3218 var SolidityEvent = function (requestManager, json, address) { 3219 this._requestManager = requestManager; 3220 this._params = json.inputs; 3221 this._name = utils.transformToFullName(json); 3222 this._address = address; 3223 this._anonymous = json.anonymous; 3224 }; 3225 3226 /** 3227 * Should be used to get filtered param types 3228 * 3229 * @method types 3230 * @param {Bool} decide if returned typed should be indexed 3231 * @return {Array} array of types 3232 */ 3233 SolidityEvent.prototype.types = function (indexed) { 3234 return this._params.filter(function (i) { 3235 return i.indexed === indexed; 3236 }).map(function (i) { 3237 return i.type; 3238 }); 3239 }; 3240 3241 /** 3242 * Should be used to get event display name 3243 * 3244 * @method displayName 3245 * @return {String} event display name 3246 */ 3247 SolidityEvent.prototype.displayName = function () { 3248 return utils.extractDisplayName(this._name); 3249 }; 3250 3251 /** 3252 * Should be used to get event type name 3253 * 3254 * @method typeName 3255 * @return {String} event type name 3256 */ 3257 SolidityEvent.prototype.typeName = function () { 3258 return utils.extractTypeName(this._name); 3259 }; 3260 3261 /** 3262 * Should be used to get event signature 3263 * 3264 * @method signature 3265 * @return {String} event signature 3266 */ 3267 SolidityEvent.prototype.signature = function () { 3268 return sha3(this._name); 3269 }; 3270 3271 /** 3272 * Should be used to encode indexed params and options to one final object 3273 * 3274 * @method encode 3275 * @param {Object} indexed 3276 * @param {Object} options 3277 * @return {Object} everything combined together and encoded 3278 */ 3279 SolidityEvent.prototype.encode = function (indexed, options) { 3280 indexed = indexed || {}; 3281 options = options || {}; 3282 var result = {}; 3283 3284 ['fromBlock', 'toBlock'].filter(function (f) { 3285 return options[f] !== undefined; 3286 }).forEach(function (f) { 3287 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3288 }); 3289 3290 result.topics = []; 3291 3292 result.address = this._address; 3293 if (!this._anonymous) { 3294 result.topics.push('0x' + this.signature()); 3295 } 3296 3297 var indexedTopics = this._params.filter(function (i) { 3298 return i.indexed === true; 3299 }).map(function (i) { 3300 var value = indexed[i.name]; 3301 if (value === undefined || value === null) { 3302 return null; 3303 } 3304 3305 if (utils.isArray(value)) { 3306 return value.map(function (v) { 3307 return '0x' + coder.encodeParam(i.type, v); 3308 }); 3309 } 3310 return '0x' + coder.encodeParam(i.type, value); 3311 }); 3312 3313 result.topics = result.topics.concat(indexedTopics); 3314 3315 return result; 3316 }; 3317 3318 /** 3319 * Should be used to decode indexed params and options 3320 * 3321 * @method decode 3322 * @param {Object} data 3323 * @return {Object} result object with decoded indexed && not indexed params 3324 */ 3325 SolidityEvent.prototype.decode = function (data) { 3326 3327 data.data = data.data || ''; 3328 data.topics = data.topics || []; 3329 3330 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3331 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3332 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3333 3334 var notIndexedData = data.data.slice(2); 3335 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3336 3337 var result = formatters.outputLogFormatter(data); 3338 result.event = this.displayName(); 3339 result.address = data.address; 3340 3341 result.args = this._params.reduce(function (acc, current) { 3342 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3343 return acc; 3344 }, {}); 3345 3346 delete result.data; 3347 delete result.topics; 3348 3349 return result; 3350 }; 3351 3352 /** 3353 * Should be used to create new filter object from event 3354 * 3355 * @method execute 3356 * @param {Object} indexed 3357 * @param {Object} options 3358 * @return {Object} filter object 3359 */ 3360 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3361 3362 if (utils.isFunction(arguments[arguments.length - 1])) { 3363 callback = arguments[arguments.length - 1]; 3364 if(arguments.length === 2) 3365 options = null; 3366 if(arguments.length === 1) { 3367 options = null; 3368 indexed = {}; 3369 } 3370 } 3371 3372 var o = this.encode(indexed, options); 3373 var formatter = this.decode.bind(this); 3374 return new Filter(o, 'u2u', this._requestManager, watches.u2u(), formatter, callback); 3375 }; 3376 3377 /** 3378 * Should be used to attach event to contract object 3379 * 3380 * @method attachToContract 3381 * @param {Contract} 3382 */ 3383 SolidityEvent.prototype.attachToContract = function (contract) { 3384 var execute = this.execute.bind(this); 3385 var displayName = this.displayName(); 3386 if (!contract[displayName]) { 3387 contract[displayName] = execute; 3388 } 3389 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3390 }; 3391 3392 module.exports = SolidityEvent; 3393 3394 3395 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){ 3396 var formatters = require('./formatters'); 3397 var utils = require('./../utils/utils'); 3398 var Method = require('./method'); 3399 var Property = require('./property'); 3400 3401 // TODO: refactor, so the input params are not altered. 3402 // it's necessary to make same 'extension' work with multiple providers 3403 var extend = function (web3) { 3404 /* jshint maxcomplexity:5 */ 3405 var ex = function (extension) { 3406 3407 var extendedObject; 3408 if (extension.property) { 3409 if (!web3[extension.property]) { 3410 web3[extension.property] = {}; 3411 } 3412 extendedObject = web3[extension.property]; 3413 } else { 3414 extendedObject = web3; 3415 } 3416 3417 if (extension.methods) { 3418 extension.methods.forEach(function (method) { 3419 method.attachToObject(extendedObject); 3420 method.setRequestManager(web3._requestManager); 3421 }); 3422 } 3423 3424 if (extension.properties) { 3425 extension.properties.forEach(function (property) { 3426 property.attachToObject(extendedObject); 3427 property.setRequestManager(web3._requestManager); 3428 }); 3429 } 3430 }; 3431 3432 ex.formatters = formatters; 3433 ex.utils = utils; 3434 ex.Method = Method; 3435 ex.Property = Property; 3436 3437 return ex; 3438 }; 3439 3440 3441 3442 module.exports = extend; 3443 3444 3445 },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){ 3446 /* 3447 This file is part of web3.js. 3448 3449 web3.js is free software: you can redistribute it and/or modify 3450 it under the terms of the GNU Lesser General Public License as published by 3451 the Free Software Foundation, either version 3 of the License, or 3452 (at your option) any later version. 3453 3454 web3.js is distributed in the hope that it will be useful, 3455 but WITHOUT ANY WARRANTY; without even the implied warranty of 3456 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3457 GNU Lesser General Public License for more details. 3458 3459 You should have received a copy of the GNU Lesser General Public License 3460 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3461 */ 3462 /** @file filter.js 3463 * @authors: 3464 * Jeffrey Wilcke <jeff@ethdev.com> 3465 * Marek Kotewicz <marek@ethdev.com> 3466 * Marian Oancea <marian@ethdev.com> 3467 * Fabian Vogelsteller <fabian@ethdev.com> 3468 * Gav Wood <g@ethdev.com> 3469 * @date 2014 3470 */ 3471 3472 var formatters = require('./formatters'); 3473 var utils = require('../utils/utils'); 3474 3475 /** 3476 * Converts a given topic to a hex string, but also allows null values. 3477 * 3478 * @param {Mixed} value 3479 * @return {String} 3480 */ 3481 var toTopic = function(value){ 3482 3483 if(value === null || typeof value === 'undefined') 3484 return null; 3485 3486 value = String(value); 3487 3488 if(value.indexOf('0x') === 0) 3489 return value; 3490 else 3491 return utils.fromUtf8(value); 3492 }; 3493 3494 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3495 /// @param should be string or object 3496 /// @returns options string or object 3497 var getOptions = function (options, type) { 3498 /*jshint maxcomplexity: 6 */ 3499 3500 if (utils.isString(options)) { 3501 return options; 3502 } 3503 3504 options = options || {}; 3505 3506 3507 switch(type) { 3508 case 'u2u': 3509 3510 // make sure topics, get converted to hex 3511 options.topics = options.topics || []; 3512 options.topics = options.topics.map(function(topic){ 3513 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3514 }); 3515 3516 return { 3517 topics: options.topics, 3518 from: options.from, 3519 to: options.to, 3520 address: options.address, 3521 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3522 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3523 }; 3524 case 'shh': 3525 return options; 3526 } 3527 }; 3528 3529 /** 3530 Adds the callback and sets up the methods, to iterate over the results. 3531 3532 @method getLogsAtStart 3533 @param {Object} self 3534 @param {function} callback 3535 */ 3536 var getLogsAtStart = function(self, callback){ 3537 // call getFilterLogs for the first watch callback start 3538 if (!utils.isString(self.options)) { 3539 self.get(function (err, messages) { 3540 // don't send all the responses to all the watches again... just to self one 3541 if (err) { 3542 callback(err); 3543 } 3544 3545 if(utils.isArray(messages)) { 3546 messages.forEach(function (message) { 3547 callback(null, message); 3548 }); 3549 } 3550 }); 3551 } 3552 }; 3553 3554 /** 3555 Adds the callback and sets up the methods, to iterate over the results. 3556 3557 @method pollFilter 3558 @param {Object} self 3559 */ 3560 var pollFilter = function(self) { 3561 3562 var onMessage = function (error, messages) { 3563 if (error) { 3564 return self.callbacks.forEach(function (callback) { 3565 callback(error); 3566 }); 3567 } 3568 3569 if(utils.isArray(messages)) { 3570 messages.forEach(function (message) { 3571 message = self.formatter ? self.formatter(message) : message; 3572 self.callbacks.forEach(function (callback) { 3573 callback(null, message); 3574 }); 3575 }); 3576 } 3577 }; 3578 3579 self.requestManager.startPolling({ 3580 method: self.implementation.poll.call, 3581 params: [self.filterId], 3582 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3583 3584 }; 3585 3586 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3587 var self = this; 3588 var implementation = {}; 3589 methods.forEach(function (method) { 3590 method.setRequestManager(requestManager); 3591 method.attachToObject(implementation); 3592 }); 3593 this.requestManager = requestManager; 3594 this.options = getOptions(options, type); 3595 this.implementation = implementation; 3596 this.filterId = null; 3597 this.callbacks = []; 3598 this.getLogsCallbacks = []; 3599 this.pollFilters = []; 3600 this.formatter = formatter; 3601 this.implementation.newFilter(this.options, function(error, id){ 3602 if(error) { 3603 self.callbacks.forEach(function(cb){ 3604 cb(error); 3605 }); 3606 if (typeof filterCreationErrorCallback === 'function') { 3607 filterCreationErrorCallback(error); 3608 } 3609 } else { 3610 self.filterId = id; 3611 3612 // check if there are get pending callbacks as a consequence 3613 // of calling get() with filterId unassigned. 3614 self.getLogsCallbacks.forEach(function (cb){ 3615 self.get(cb); 3616 }); 3617 self.getLogsCallbacks = []; 3618 3619 // get filter logs for the already existing watch calls 3620 self.callbacks.forEach(function(cb){ 3621 getLogsAtStart(self, cb); 3622 }); 3623 if(self.callbacks.length > 0) 3624 pollFilter(self); 3625 3626 // start to watch immediately 3627 if(typeof callback === 'function') { 3628 return self.watch(callback); 3629 } 3630 } 3631 }); 3632 3633 return this; 3634 }; 3635 3636 Filter.prototype.watch = function (callback) { 3637 this.callbacks.push(callback); 3638 3639 if(this.filterId) { 3640 getLogsAtStart(this, callback); 3641 pollFilter(this); 3642 } 3643 3644 return this; 3645 }; 3646 3647 Filter.prototype.stopWatching = function (callback) { 3648 this.requestManager.stopPolling(this.filterId); 3649 this.callbacks = []; 3650 // remove filter async 3651 if (callback) { 3652 this.implementation.uninstallFilter(this.filterId, callback); 3653 } else { 3654 return this.implementation.uninstallFilter(this.filterId); 3655 } 3656 }; 3657 3658 Filter.prototype.get = function (callback) { 3659 var self = this; 3660 if (utils.isFunction(callback)) { 3661 if (this.filterId === null) { 3662 // If filterId is not set yet, call it back 3663 // when newFilter() assigns it. 3664 this.getLogsCallbacks.push(callback); 3665 } else { 3666 this.implementation.getLogs(this.filterId, function(err, res){ 3667 if (err) { 3668 callback(err); 3669 } else { 3670 callback(null, res.map(function (log) { 3671 return self.formatter ? self.formatter(log) : log; 3672 })); 3673 } 3674 }); 3675 } 3676 } else { 3677 if (this.filterId === null) { 3678 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3679 } 3680 var logs = this.implementation.getLogs(this.filterId); 3681 return logs.map(function (log) { 3682 return self.formatter ? self.formatter(log) : log; 3683 }); 3684 } 3685 3686 return this; 3687 }; 3688 3689 module.exports = Filter; 3690 3691 3692 },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){ 3693 'use strict' 3694 3695 /* 3696 This file is part of web3.js. 3697 3698 web3.js is free software: you can redistribute it and/or modify 3699 it under the terms of the GNU Lesser General Public License as published by 3700 the Free Software Foundation, either version 3 of the License, or 3701 (at your option) any later version. 3702 3703 web3.js is distributed in the hope that it will be useful, 3704 but WITHOUT ANY WARRANTY; without even the implied warranty of 3705 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3706 GNU Lesser General Public License for more details. 3707 3708 You should have received a copy of the GNU Lesser General Public License 3709 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3710 */ 3711 /** 3712 * @file formatters.js 3713 * @author Marek Kotewicz <marek@ethdev.com> 3714 * @author Fabian Vogelsteller <fabian@ethdev.com> 3715 * @date 2015 3716 */ 3717 3718 var utils = require('../utils/utils'); 3719 var config = require('../utils/config'); 3720 var Iban = require('./iban'); 3721 3722 /** 3723 * Should the format output to a big number 3724 * 3725 * @method outputBigNumberFormatter 3726 * @param {String|Number|BigNumber} 3727 * @returns {BigNumber} object 3728 */ 3729 var outputBigNumberFormatter = function (number) { 3730 return utils.toBigNumber(number); 3731 }; 3732 3733 var isPredefinedBlockNumber = function (blockNumber) { 3734 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3735 }; 3736 3737 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3738 if (blockNumber === undefined) { 3739 return config.defaultBlock; 3740 } 3741 return inputBlockNumberFormatter(blockNumber); 3742 }; 3743 3744 var inputBlockNumberFormatter = function (blockNumber) { 3745 if (blockNumber === undefined) { 3746 return undefined; 3747 } else if (isPredefinedBlockNumber(blockNumber)) { 3748 return blockNumber; 3749 } 3750 return utils.toHex(blockNumber); 3751 }; 3752 3753 /** 3754 * Formats the input of a transaction and converts all values to HEX 3755 * 3756 * @method inputCallFormatter 3757 * @param {Object} transaction options 3758 * @returns object 3759 */ 3760 var inputCallFormatter = function (options){ 3761 3762 options.from = options.from || config.defaultAccount; 3763 3764 if (options.from) { 3765 options.from = inputAddressFormatter(options.from); 3766 } 3767 3768 if (options.to) { // it might be contract creation 3769 options.to = inputAddressFormatter(options.to); 3770 } 3771 3772 ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3773 return options[key] !== undefined; 3774 }).forEach(function(key){ 3775 options[key] = utils.fromDecimal(options[key]); 3776 }); 3777 3778 return options; 3779 }; 3780 3781 /** 3782 * Formats the input of a transaction and converts all values to HEX 3783 * 3784 * @method inputTransactionFormatter 3785 * @param {Object} transaction options 3786 * @returns object 3787 */ 3788 var inputTransactionFormatter = function (options){ 3789 3790 options.from = options.from || config.defaultAccount; 3791 options.from = inputAddressFormatter(options.from); 3792 3793 if (options.to) { // it might be contract creation 3794 options.to = inputAddressFormatter(options.to); 3795 } 3796 3797 ['maxFeePerGas', 'maxPriorityFeePerGas', 'gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3798 return options[key] !== undefined; 3799 }).forEach(function(key){ 3800 options[key] = utils.fromDecimal(options[key]); 3801 }); 3802 3803 return options; 3804 }; 3805 3806 /** 3807 * Formats the output of a transaction to its proper values 3808 * 3809 * @method outputTransactionFormatter 3810 * @param {Object} tx 3811 * @returns {Object} 3812 */ 3813 var outputTransactionFormatter = function (tx){ 3814 if(tx.blockNumber !== null) 3815 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3816 if(tx.transactionIndex !== null) 3817 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3818 tx.nonce = utils.toDecimal(tx.nonce); 3819 tx.gas = utils.toDecimal(tx.gas); 3820 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3821 if(tx.maxFeePerGas !== undefined) { 3822 tx.maxFeePerGas = utils.toBigNumber(tx.maxFeePerGas); 3823 } 3824 if(tx.maxPriorityFeePerGas !== undefined) { 3825 tx.maxPriorityFeePerGas = utils.toBigNumber(tx.maxPriorityFeePerGas); 3826 } 3827 tx.value = utils.toBigNumber(tx.value); 3828 return tx; 3829 }; 3830 3831 /** 3832 * Formats the output of a transaction receipt to its proper values 3833 * 3834 * @method outputTransactionReceiptFormatter 3835 * @param {Object} receipt 3836 * @returns {Object} 3837 */ 3838 var outputTransactionReceiptFormatter = function (receipt){ 3839 if(receipt.blockNumber !== null) 3840 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3841 if(receipt.transactionIndex !== null) 3842 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3843 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3844 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3845 if(receipt.effectiveGasPrice !== undefined) { 3846 receipt.effectiveGasPrice = utils.toBigNumber(receipt.effectiveGasPrice); 3847 } 3848 if(utils.isArray(receipt.logs)) { 3849 receipt.logs = receipt.logs.map(function(log){ 3850 return outputLogFormatter(log); 3851 }); 3852 } 3853 3854 return receipt; 3855 }; 3856 3857 /** 3858 * Formats the output of a block to its proper values 3859 * 3860 * @method outputBlockFormatter 3861 * @param {Object} block 3862 * @returns {Object} 3863 */ 3864 var outputBlockFormatter = function(block) { 3865 // transform to number 3866 if (block.baseFeePerGas !== undefined) { 3867 block.baseFeePerGas = utils.toBigNumber(block.baseFeePerGas); 3868 } 3869 block.gasLimit = utils.toDecimal(block.gasLimit); 3870 block.gasUsed = utils.toDecimal(block.gasUsed); 3871 block.size = utils.toDecimal(block.size); 3872 block.timestamp = utils.toDecimal(block.timestamp); 3873 block.timestampNano = utils.toDecimal(block.timestampNano); 3874 if(block.number !== null) 3875 block.number = utils.toDecimal(block.number); 3876 3877 block.difficulty = utils.toBigNumber(block.difficulty); 3878 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3879 3880 if (utils.isArray(block.transactions)) { 3881 block.transactions.forEach(function(item){ 3882 if(!utils.isString(item)) 3883 return outputTransactionFormatter(item); 3884 }); 3885 } 3886 3887 return block; 3888 }; 3889 3890 /** 3891 * @method outputEpochStatsFormatter 3892 * @param {Object} epoch stats data 3893 * @returns {Object} 3894 */ 3895 var outputEpochStatsFormatter = function(data) { 3896 3897 // transform to number 3898 data.epoch = utils.toDecimal(data.epoch); 3899 data.start = utils.toDecimal(data.start); 3900 data.end = utils.toDecimal(data.end); 3901 data.totalBaseRewardWeight = utils.toBigNumber(data.totalBaseRewardWeight); 3902 data.totalFee = utils.toBigNumber(data.totalFee); 3903 data.totalTxRewardWeight = utils.toBigNumber(data.totalTxRewardWeight); 3904 3905 return data; 3906 }; 3907 3908 /** 3909 * @method outputDagEventFormatter 3910 * @param {Object} DAG event data 3911 * @returns {Object} 3912 */ 3913 var outputDagEventFormatter = function(data) { 3914 //"id": hexutil.Bytes(header.ID().Bytes()), 3915 //"prevEpochHash": header.PrevEpochHash(), 3916 //"parents": eventIDsToHex(header.Parents()), 3917 //"extraData": hexutil.Bytes(header.Extra()), 3918 //"transactionsRoot": hexutil.Bytes(header.TxHash().Bytes()), 3919 3920 // transform to number 3921 data.epoch = utils.toDecimal(data.epoch); 3922 data.seq = utils.toDecimal(data.seq); 3923 data.frame = utils.toDecimal(data.frame); 3924 data.creator = utils.toDecimal(data.creator); 3925 data.lamport = utils.toDecimal(data.lamport); 3926 data.creationTime = utils.toDecimal(data.creationTime); 3927 data.medianTime = utils.toDecimal(data.medianTime); 3928 data.gasPowerLeft.shortTerm = utils.toDecimal(data.gasPowerLeft.shortTerm); 3929 data.gasPowerLeft.longTerm = utils.toDecimal(data.gasPowerLeft.longTerm); 3930 data.gasPowerUsed = utils.toDecimal(data.gasPowerUsed); 3931 if (data.hasOwnProperty('size')) { 3932 data.size = utils.toDecimal(data.size); 3933 } 3934 if (data.hasOwnProperty('transactions') && utils.isArray(data.transactions)) { 3935 data.transactions.forEach(function(item, i) { 3936 if (!utils.isString(item)) { 3937 data.transactions[i] = outputTransactionFormatter(item) 3938 } 3939 }) 3940 } 3941 3942 return data; 3943 }; 3944 3945 /** 3946 * @method outputHeadsFormatter 3947 * @param {Object} stakers data 3948 * @returns {Object} 3949 */ 3950 var outputHeadsFormatter = function(data) { 3951 if (utils.isArray(data)) { 3952 data.forEach(function(item, i) { 3953 data[i] = item // TODO: format 3954 }) 3955 }; 3956 3957 return data; 3958 }; 3959 3960 /** 3961 * @method outputStakerFormatter 3962 * @param {Object} staker data 3963 * @returns {Object} 3964 */ 3965 var outputStakerFormatter = function(data) { 3966 data.id = utils.toDecimal(data.id); 3967 data.createdEpoch = utils.toDecimal(data.createdEpoch); 3968 data.createdTime = utils.toBigNumber(data.createdTime); 3969 data.deactivatedEpoch = utils.toDecimal(data.deactivatedEpoch); 3970 data.deactivatedTime = utils.toBigNumber(data.deactivatedTime); 3971 data.delegatedMe = utils.toDecimal(data.delegatedMe); 3972 data.stake = utils.toBigNumber(data.stake); 3973 data.totalStake = utils.toBigNumber(data.totalStake); 3974 3975 if (data.hasOwnProperty('baseRewardWeight')) { 3976 data.baseRewardWeight = utils.toBigNumber(data.baseRewardWeight); 3977 data.claimedRewards = utils.toBigNumber(data.claimedRewards); 3978 data.delegationsClaimedRewards = utils.toBigNumber(data.delegationsClaimedRewards); 3979 data.downtime = utils.toBigNumber(data.downtime); 3980 data.missedBlocks = utils.toBigNumber(data.missedBlocks); 3981 data.originationScore = utils.toBigNumber(data.originationScore); 3982 data.poi = utils.toBigNumber(data.poi); 3983 data.txRewardWeight = utils.toBigNumber(data.txRewardWeight); 3984 data.validationScore = utils.toBigNumber(data.validationScore); 3985 }; 3986 3987 return data; 3988 }; 3989 3990 /** 3991 * @method outputStakersFormatter 3992 * @param {Object} stakers data 3993 * @returns {Object} 3994 */ 3995 var outputStakersFormatter = function(data) { 3996 if (utils.isArray(data)) { 3997 data.forEach(function(item, i) { 3998 if (typeof(item) != 'string') { 3999 data[i] = outputStakerFormatter(item) 4000 } else { 4001 data[i] = utils.toDecimal(item) 4002 } 4003 }) 4004 }; 4005 4006 return data; 4007 }; 4008 4009 /** 4010 * @method outputDelegationFormatter 4011 * @param {Object} staker data 4012 * @returns {Object} 4013 */ 4014 var outputDelegationFormatter = function(data) { 4015 data.toStakerID = utils.toDecimal(data.toStakerID); 4016 data.amount = utils.toBigNumber(data.amount); 4017 data.createdEpoch = utils.toDecimal(data.createdEpoch); 4018 data.createdTime = utils.toBigNumber(data.createdTime); 4019 data.deactivatedEpoch = utils.toDecimal(data.deactivatedEpoch); 4020 data.deactivatedTime = utils.toBigNumber(data.deactivatedTime); 4021 4022 if (data.hasOwnProperty('claimedRewards')) { 4023 data.claimedRewards = utils.toBigNumber(data.claimedRewards); 4024 } 4025 4026 return data; 4027 }; 4028 4029 /** 4030 * @method outputDelegationsFormatter 4031 * @param {Object} delegations data 4032 * @returns {Object} 4033 */ 4034 var outputDelegationsFormatter = function(data) { 4035 if (utils.isArray(data)) { 4036 data.forEach(function(item, i) { 4037 if (typeof(item) != 'string') { 4038 data[i] = outputDelegationFormatter(item) 4039 } 4040 }) 4041 } 4042 4043 return data; 4044 }; 4045 4046 /** 4047 * @method outputHistogramFormatter 4048 * @param {Array} histogram data 4049 * @returns {Array} 4050 */ 4051 var outputHistogramFormatter = function(data) { 4052 if (utils.isArray(data)) { 4053 data.forEach(function(item, i) { 4054 item.count = utils.toDecimal(item.count); 4055 data[i] = item 4056 }) 4057 } 4058 4059 return data; 4060 }; 4061 4062 /** 4063 * @method outputDecimalProperties 4064 * @param {Object} data 4065 * @returns {Object} 4066 */ 4067 var outputDecimalProperties = function(data) { 4068 Object.keys(data).forEach(function(k){ 4069 data[k] = utils.toDecimal(data[k]) 4070 }); 4071 4072 return data; 4073 }; 4074 4075 /** 4076 * @method outputBlocksTTFFormatter 4077 * @param {Object} blocksTTF stats data 4078 * @returns {Object} 4079 */ 4080 var outputBlocksTTFFormatter = function(data) { 4081 // transform to number 4082 data.stats.samples = utils.toDecimal(data.stats.samples); 4083 4084 // histogram 4085 if (data.hasOwnProperty('histogram') && utils.isArray(data.histogram)) { 4086 data.histogram = outputHistogramFormatter(data.histogram) 4087 } 4088 4089 return data; 4090 }; 4091 4092 /** 4093 * @method outputKeysToDecimal 4094 * @param {Object} data 4095 * @returns {Object} 4096 */ 4097 var outputKeysToDecimal = function(data) { 4098 var newData = new Object(); 4099 Object.keys(data).forEach(function(k){ 4100 newData[utils.toDecimal(k)] = data[k] 4101 }); 4102 4103 return newData; 4104 }; 4105 4106 /** 4107 * @method outputKeyValuesToDecimal 4108 * @param {Object} data 4109 * @returns {Object} 4110 */ 4111 var outputKeyValuesToDecimal = function(data) { 4112 var newData = new Object(); 4113 Object.keys(data).forEach(function(k){ 4114 newData[utils.toDecimal(k)] = utils.toDecimal(data[k]) 4115 }); 4116 4117 return newData; 4118 }; 4119 4120 /** 4121 * @method outputBlocksTPSFormatter 4122 * @param {Object} data 4123 * @returns {Float} 4124 */ 4125 var outputBlocksTPSFormatter = function(data) { 4126 var minTime = 0; 4127 var maxTime = 0; 4128 var totalCount = 0; 4129 Object.keys(data).forEach(function(k){ 4130 var time = utils.toDecimal(k); 4131 var count = utils.toDecimal(data[k]); 4132 if (minTime == 0 || minTime > time) { 4133 minTime = time; 4134 } 4135 if (maxTime == 0 || maxTime < time) { 4136 maxTime = time 4137 } 4138 totalCount += count; 4139 }); 4140 if (maxTime <= minTime) { 4141 return 0.0; 4142 } 4143 4144 return totalCount * 1e9 / (maxTime - minTime); 4145 }; 4146 4147 /** 4148 * @method outputValidatorTimeDriftsFormatter 4149 * @param {Object} validatorTimeDrifts stats data 4150 * @returns {Object} 4151 */ 4152 var outputValidatorTimeDriftsFormatter = function(data) { 4153 Object.keys(data).forEach(function(k){ 4154 data[k].stats.samples = utils.toDecimal(data[k].stats.samples); 4155 4156 if (data[k].hasOwnProperty('histogram') && utils.isArray(data[k].histogram)) { 4157 data[k].histogram = outputHistogramFormatter(data[k].histogram) 4158 } 4159 }); 4160 4161 return outputKeysToDecimal(data); 4162 }; 4163 4164 /** 4165 * Formats the output of a log 4166 * 4167 * @method outputLogFormatter 4168 * @param {Object} log object 4169 * @returns {Object} log 4170 */ 4171 var outputLogFormatter = function(log) { 4172 if(log.blockNumber) 4173 log.blockNumber = utils.toDecimal(log.blockNumber); 4174 if(log.transactionIndex) 4175 log.transactionIndex = utils.toDecimal(log.transactionIndex); 4176 if(log.logIndex) 4177 log.logIndex = utils.toDecimal(log.logIndex); 4178 4179 return log; 4180 }; 4181 4182 /** 4183 * Formats the input of a whisper post and converts all values to HEX 4184 * 4185 * @method inputPostFormatter 4186 * @param {Object} transaction object 4187 * @returns {Object} 4188 */ 4189 var inputPostFormatter = function(post) { 4190 4191 // post.payload = utils.toHex(post.payload); 4192 post.ttl = utils.fromDecimal(post.ttl); 4193 post.workToProve = utils.fromDecimal(post.workToProve); 4194 post.priority = utils.fromDecimal(post.priority); 4195 4196 // fallback 4197 if (!utils.isArray(post.topics)) { 4198 post.topics = post.topics ? [post.topics] : []; 4199 } 4200 4201 // format the following options 4202 post.topics = post.topics.map(function(topic){ 4203 // convert only if not hex 4204 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 4205 }); 4206 4207 return post; 4208 }; 4209 4210 /** 4211 * Formats the output of a received post message 4212 * 4213 * @method outputPostFormatter 4214 * @param {Object} 4215 * @returns {Object} 4216 */ 4217 var outputPostFormatter = function(post){ 4218 4219 post.expiry = utils.toDecimal(post.expiry); 4220 post.sent = utils.toDecimal(post.sent); 4221 post.ttl = utils.toDecimal(post.ttl); 4222 post.workProved = utils.toDecimal(post.workProved); 4223 // post.payloadRaw = post.payload; 4224 // post.payload = utils.toAscii(post.payload); 4225 4226 // if (utils.isJson(post.payload)) { 4227 // post.payload = JSON.parse(post.payload); 4228 // } 4229 4230 // format the following options 4231 if (!post.topics) { 4232 post.topics = []; 4233 } 4234 post.topics = post.topics.map(function(topic){ 4235 return utils.toAscii(topic); 4236 }); 4237 4238 return post; 4239 }; 4240 4241 var inputAddressFormatter = function (address) { 4242 var iban = new Iban(address); 4243 if (iban.isValid() && iban.isDirect()) { 4244 return '0x' + iban.address(); 4245 } else if (utils.isStrictAddress(address)) { 4246 return address; 4247 } else if (utils.isAddress(address)) { 4248 return '0x' + address; 4249 } 4250 throw new Error('invalid address'); 4251 }; 4252 4253 4254 var outputSyncingFormatter = function(result) { 4255 if (!result) { 4256 return result; 4257 } 4258 4259 result.startingBlock = utils.toDecimal(result.startingBlock); 4260 result.currentBlock = utils.toDecimal(result.currentBlock); 4261 result.highestBlock = utils.toDecimal(result.highestBlock); 4262 if (result.knownStates) { 4263 result.knownStates = utils.toDecimal(result.knownStates); 4264 result.pulledStates = utils.toDecimal(result.pulledStates); 4265 } 4266 4267 return result; 4268 }; 4269 4270 module.exports = { 4271 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 4272 inputBlockNumberFormatter: inputBlockNumberFormatter, 4273 inputCallFormatter: inputCallFormatter, 4274 inputTransactionFormatter: inputTransactionFormatter, 4275 inputAddressFormatter: inputAddressFormatter, 4276 inputPostFormatter: inputPostFormatter, 4277 outputBigNumberFormatter: outputBigNumberFormatter, 4278 outputTransactionFormatter: outputTransactionFormatter, 4279 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 4280 outputBlockFormatter: outputBlockFormatter, 4281 outputLogFormatter: outputLogFormatter, 4282 outputPostFormatter: outputPostFormatter, 4283 outputSyncingFormatter: outputSyncingFormatter, 4284 outputEpochStatsFormatter: outputEpochStatsFormatter, 4285 outputDagEventFormatter: outputDagEventFormatter, 4286 outputHeadsFormatter: outputHeadsFormatter, 4287 outputBlocksTTFFormatter: outputBlocksTTFFormatter, 4288 outputValidatorTimeDriftsFormatter: outputValidatorTimeDriftsFormatter, 4289 outputDecimalProperties: outputDecimalProperties, 4290 outputStakerFormatter: outputStakerFormatter, 4291 outputStakersFormatter: outputStakersFormatter, 4292 outputKeysToDecimal: outputKeysToDecimal, 4293 outputKeyValuesToDecimal: outputKeyValuesToDecimal, 4294 outputBlocksTPSFormatter: outputBlocksTPSFormatter, 4295 outputDelegationFormatter: outputDelegationFormatter, 4296 outputDelegationsFormatter: outputDelegationsFormatter 4297 }; 4298 4299 4300 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 4301 /* 4302 This file is part of web3.js. 4303 4304 web3.js is free software: you can redistribute it and/or modify 4305 it under the terms of the GNU Lesser General Public License as published by 4306 the Free Software Foundation, either version 3 of the License, or 4307 (at your option) any later version. 4308 4309 web3.js is distributed in the hope that it will be useful, 4310 but WITHOUT ANY WARRANTY; without even the implied warranty of 4311 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4312 GNU Lesser General Public License for more details. 4313 4314 You should have received a copy of the GNU Lesser General Public License 4315 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4316 */ 4317 /** 4318 * @file function.js 4319 * @author Marek Kotewicz <marek@ethdev.com> 4320 * @date 2015 4321 */ 4322 4323 var coder = require('../solidity/coder'); 4324 var utils = require('../utils/utils'); 4325 var errors = require('./errors'); 4326 var formatters = require('./formatters'); 4327 var sha3 = require('../utils/sha3'); 4328 4329 /** 4330 * This prototype should be used to call/sendTransaction to solidity functions 4331 */ 4332 var SolidityFunction = function (u2u, json, address) { 4333 this._u2u = u2u; 4334 this._inputTypes = json.inputs.map(function (i) { 4335 return i.type; 4336 }); 4337 this._outputTypes = json.outputs.map(function (i) { 4338 return i.type; 4339 }); 4340 this._constant = json.constant; 4341 this._payable = json.payable; 4342 this._name = utils.transformToFullName(json); 4343 this._address = address; 4344 }; 4345 4346 SolidityFunction.prototype.extractCallback = function (args) { 4347 if (utils.isFunction(args[args.length - 1])) { 4348 return args.pop(); // modify the args array! 4349 } 4350 }; 4351 4352 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4353 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4354 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4355 } 4356 }; 4357 4358 /** 4359 * Should be called to check if the number of arguments is correct 4360 * 4361 * @method validateArgs 4362 * @param {Array} arguments 4363 * @throws {Error} if it is not 4364 */ 4365 SolidityFunction.prototype.validateArgs = function (args) { 4366 var inputArgs = args.filter(function (a) { 4367 // filter the options object but not arguments that are arrays 4368 return !( (utils.isObject(a) === true) && 4369 (utils.isArray(a) === false) && 4370 (utils.isBigNumber(a) === false) 4371 ); 4372 }); 4373 if (inputArgs.length !== this._inputTypes.length) { 4374 throw errors.InvalidNumberOfSolidityArgs(); 4375 } 4376 }; 4377 4378 /** 4379 * Should be used to create payload from arguments 4380 * 4381 * @method toPayload 4382 * @param {Array} solidity function params 4383 * @param {Object} optional payload options 4384 */ 4385 SolidityFunction.prototype.toPayload = function (args) { 4386 var options = {}; 4387 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4388 options = args[args.length - 1]; 4389 } 4390 this.validateArgs(args); 4391 options.to = this._address; 4392 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4393 return options; 4394 }; 4395 4396 /** 4397 * Should be used to get function signature 4398 * 4399 * @method signature 4400 * @return {String} function signature 4401 */ 4402 SolidityFunction.prototype.signature = function () { 4403 return sha3(this._name).slice(0, 8); 4404 }; 4405 4406 4407 SolidityFunction.prototype.unpackOutput = function (output) { 4408 if (!output) { 4409 return; 4410 } 4411 4412 output = output.length >= 2 ? output.slice(2) : output; 4413 var result = coder.decodeParams(this._outputTypes, output); 4414 return result.length === 1 ? result[0] : result; 4415 }; 4416 4417 /** 4418 * Calls a contract function. 4419 * 4420 * @method call 4421 * @param {...Object} Contract function arguments 4422 * @param {function} If the last argument is a function, the contract function 4423 * call will be asynchronous, and the callback will be passed the 4424 * error and result. 4425 * @return {String} output bytes 4426 */ 4427 SolidityFunction.prototype.call = function () { 4428 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4429 var callback = this.extractCallback(args); 4430 var defaultBlock = this.extractDefaultBlock(args); 4431 var payload = this.toPayload(args); 4432 4433 4434 if (!callback) { 4435 var output = this._u2u.call(payload, defaultBlock); 4436 return this.unpackOutput(output); 4437 } 4438 4439 var self = this; 4440 this._u2u.call(payload, defaultBlock, function (error, output) { 4441 if (error) return callback(error, null); 4442 4443 var unpacked = null; 4444 try { 4445 unpacked = self.unpackOutput(output); 4446 } 4447 catch (e) { 4448 error = e; 4449 } 4450 4451 callback(error, unpacked); 4452 }); 4453 }; 4454 4455 /** 4456 * Should be used to sendTransaction to solidity function 4457 * 4458 * @method sendTransaction 4459 */ 4460 SolidityFunction.prototype.sendTransaction = function () { 4461 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4462 var callback = this.extractCallback(args); 4463 var payload = this.toPayload(args); 4464 4465 if (payload.value > 0 && !this._payable) { 4466 throw new Error('Cannot send value to non-payable function'); 4467 } 4468 4469 if (!callback) { 4470 return this._u2u.sendTransaction(payload); 4471 } 4472 4473 this._u2u.sendTransaction(payload, callback); 4474 }; 4475 4476 /** 4477 * Should be used to estimateGas of solidity function 4478 * 4479 * @method estimateGas 4480 */ 4481 SolidityFunction.prototype.estimateGas = function () { 4482 var args = Array.prototype.slice.call(arguments); 4483 var callback = this.extractCallback(args); 4484 var payload = this.toPayload(args); 4485 4486 if (!callback) { 4487 return this._u2u.estimateGas(payload); 4488 } 4489 4490 this._u2u.estimateGas(payload, callback); 4491 }; 4492 4493 /** 4494 * Return the encoded data of the call 4495 * 4496 * @method getData 4497 * @return {String} the encoded data 4498 */ 4499 SolidityFunction.prototype.getData = function () { 4500 var args = Array.prototype.slice.call(arguments); 4501 var payload = this.toPayload(args); 4502 4503 return payload.data; 4504 }; 4505 4506 /** 4507 * Should be used to get function display name 4508 * 4509 * @method displayName 4510 * @return {String} display name of the function 4511 */ 4512 SolidityFunction.prototype.displayName = function () { 4513 return utils.extractDisplayName(this._name); 4514 }; 4515 4516 /** 4517 * Should be used to get function type name 4518 * 4519 * @method typeName 4520 * @return {String} type name of the function 4521 */ 4522 SolidityFunction.prototype.typeName = function () { 4523 return utils.extractTypeName(this._name); 4524 }; 4525 4526 /** 4527 * Should be called to get rpc requests from solidity function 4528 * 4529 * @method request 4530 * @returns {Object} 4531 */ 4532 SolidityFunction.prototype.request = function () { 4533 var args = Array.prototype.slice.call(arguments); 4534 var callback = this.extractCallback(args); 4535 var payload = this.toPayload(args); 4536 var format = this.unpackOutput.bind(this); 4537 4538 return { 4539 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4540 callback: callback, 4541 params: [payload], 4542 format: format 4543 }; 4544 }; 4545 4546 /** 4547 * Should be called to execute function 4548 * 4549 * @method execute 4550 */ 4551 SolidityFunction.prototype.execute = function () { 4552 var transaction = !this._constant; 4553 4554 // send transaction 4555 if (transaction) { 4556 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4557 } 4558 4559 // call 4560 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4561 }; 4562 4563 /** 4564 * Should be called to attach function to contract 4565 * 4566 * @method attachToContract 4567 * @param {Contract} 4568 */ 4569 SolidityFunction.prototype.attachToContract = function (contract) { 4570 var execute = this.execute.bind(this); 4571 execute.request = this.request.bind(this); 4572 execute.call = this.call.bind(this); 4573 execute.sendTransaction = this.sendTransaction.bind(this); 4574 execute.estimateGas = this.estimateGas.bind(this); 4575 execute.getData = this.getData.bind(this); 4576 var displayName = this.displayName(); 4577 if (!contract[displayName]) { 4578 contract[displayName] = execute; 4579 } 4580 contract[displayName][this.typeName()] = execute; // circular!!!! 4581 }; 4582 4583 module.exports = SolidityFunction; 4584 4585 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4586 /* 4587 This file is part of web3.js. 4588 4589 web3.js is free software: you can redistribute it and/or modify 4590 it under the terms of the GNU Lesser General Public License as published by 4591 the Free Software Foundation, either version 3 of the License, or 4592 (at your option) any later version. 4593 4594 web3.js is distributed in the hope that it will be useful, 4595 but WITHOUT ANY WARRANTY; without even the implied warranty of 4596 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4597 GNU Lesser General Public License for more details. 4598 4599 You should have received a copy of the GNU Lesser General Public License 4600 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4601 */ 4602 /** @file httpprovider.js 4603 * @authors: 4604 * Marek Kotewicz <marek@ethdev.com> 4605 * Marian Oancea <marian@ethdev.com> 4606 * Fabian Vogelsteller <fabian@ethdev.com> 4607 * @date 2015 4608 */ 4609 4610 var errors = require('./errors'); 4611 4612 // workaround to use httpprovider in different envs 4613 4614 // browser 4615 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4616 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4617 // node 4618 } else { 4619 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4620 } 4621 4622 var XHR2 = require('xhr2'); // jshint ignore: line 4623 4624 /** 4625 * HttpProvider should be used to send rpc calls over http 4626 */ 4627 var HttpProvider = function (host, timeout, user, password) { 4628 this.host = host || 'http://localhost:8545'; 4629 this.timeout = timeout || 0; 4630 this.user = user; 4631 this.password = password; 4632 }; 4633 4634 /** 4635 * Should be called to prepare new XMLHttpRequest 4636 * 4637 * @method prepareRequest 4638 * @param {Boolean} true if request should be async 4639 * @return {XMLHttpRequest} object 4640 */ 4641 HttpProvider.prototype.prepareRequest = function (async) { 4642 var request; 4643 4644 if (async) { 4645 request = new XHR2(); 4646 request.timeout = this.timeout; 4647 } else { 4648 request = new XMLHttpRequest(); 4649 } 4650 4651 request.open('POST', this.host, async); 4652 if (this.user && this.password) { 4653 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4654 request.setRequestHeader('Authorization', auth); 4655 } request.setRequestHeader('Content-Type', 'application/json'); 4656 return request; 4657 }; 4658 4659 /** 4660 * Should be called to make sync request 4661 * 4662 * @method send 4663 * @param {Object} payload 4664 * @return {Object} result 4665 */ 4666 HttpProvider.prototype.send = function (payload) { 4667 var request = this.prepareRequest(false); 4668 4669 try { 4670 request.send(JSON.stringify(payload)); 4671 } catch (error) { 4672 throw errors.InvalidConnection(this.host); 4673 } 4674 4675 var result = request.responseText; 4676 4677 try { 4678 result = JSON.parse(result); 4679 } catch (e) { 4680 throw errors.InvalidResponse(request.responseText); 4681 } 4682 4683 return result; 4684 }; 4685 4686 /** 4687 * Should be used to make async request 4688 * 4689 * @method sendAsync 4690 * @param {Object} payload 4691 * @param {Function} callback triggered on end with (err, result) 4692 */ 4693 HttpProvider.prototype.sendAsync = function (payload, callback) { 4694 var request = this.prepareRequest(true); 4695 4696 request.onreadystatechange = function () { 4697 if (request.readyState === 4 && request.timeout !== 1) { 4698 var result = request.responseText; 4699 var error = null; 4700 4701 try { 4702 result = JSON.parse(result); 4703 } catch (e) { 4704 error = errors.InvalidResponse(request.responseText); 4705 } 4706 4707 callback(error, result); 4708 } 4709 }; 4710 4711 request.ontimeout = function () { 4712 callback(errors.ConnectionTimeout(this.timeout)); 4713 }; 4714 4715 try { 4716 request.send(JSON.stringify(payload)); 4717 } catch (error) { 4718 callback(errors.InvalidConnection(this.host)); 4719 } 4720 }; 4721 4722 /** 4723 * Synchronously tries to make Http request 4724 * 4725 * @method isConnected 4726 * @return {Boolean} returns true if request haven't failed. Otherwise false 4727 */ 4728 HttpProvider.prototype.isConnected = function () { 4729 try { 4730 this.send({ 4731 id: 9999999999, 4732 jsonrpc: '2.0', 4733 method: 'net_listening', 4734 params: [] 4735 }); 4736 return true; 4737 } catch (e) { 4738 return false; 4739 } 4740 }; 4741 4742 module.exports = HttpProvider; 4743 4744 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4745 /* 4746 This file is part of web3.js. 4747 4748 web3.js is free software: you can redistribute it and/or modify 4749 it under the terms of the GNU Lesser General Public License as published by 4750 the Free Software Foundation, either version 3 of the License, or 4751 (at your option) any later version. 4752 4753 web3.js is distributed in the hope that it will be useful, 4754 but WITHOUT ANY WARRANTY; without even the implied warranty of 4755 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4756 GNU Lesser General Public License for more details. 4757 4758 You should have received a copy of the GNU Lesser General Public License 4759 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4760 */ 4761 /** 4762 * @file iban.js 4763 * @author Marek Kotewicz <marek@ethdev.com> 4764 * @date 2015 4765 */ 4766 4767 var BigNumber = require('bignumber.js'); 4768 4769 var padLeft = function (string, bytes) { 4770 var result = string; 4771 while (result.length < bytes * 2) { 4772 result = '0' + result; 4773 } 4774 return result; 4775 }; 4776 4777 /** 4778 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4779 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4780 * 4781 * @method iso13616Prepare 4782 * @param {String} iban the IBAN 4783 * @returns {String} the prepared IBAN 4784 */ 4785 var iso13616Prepare = function (iban) { 4786 var A = 'A'.charCodeAt(0); 4787 var Z = 'Z'.charCodeAt(0); 4788 4789 iban = iban.toUpperCase(); 4790 iban = iban.substr(4) + iban.substr(0,4); 4791 4792 return iban.split('').map(function(n){ 4793 var code = n.charCodeAt(0); 4794 if (code >= A && code <= Z){ 4795 // A = 10, B = 11, ... Z = 35 4796 return code - A + 10; 4797 } else { 4798 return n; 4799 } 4800 }).join(''); 4801 }; 4802 4803 /** 4804 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4805 * 4806 * @method mod9710 4807 * @param {String} iban 4808 * @returns {Number} 4809 */ 4810 var mod9710 = function (iban) { 4811 var remainder = iban, 4812 block; 4813 4814 while (remainder.length > 2){ 4815 block = remainder.slice(0, 9); 4816 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4817 } 4818 4819 return parseInt(remainder, 10) % 97; 4820 }; 4821 4822 /** 4823 * This prototype should be used to create iban object from iban correct string 4824 * 4825 * @param {String} iban 4826 */ 4827 var Iban = function (iban) { 4828 this._iban = iban; 4829 }; 4830 4831 /** 4832 * This method should be used to create iban object from ethereum address 4833 * 4834 * @method fromAddress 4835 * @param {String} address 4836 * @return {Iban} the IBAN object 4837 */ 4838 Iban.fromAddress = function (address) { 4839 var asBn = new BigNumber(address, 16); 4840 var base36 = asBn.toString(36); 4841 var padded = padLeft(base36, 15); 4842 return Iban.fromBban(padded.toUpperCase()); 4843 }; 4844 4845 /** 4846 * Convert the passed BBAN to an IBAN for this country specification. 4847 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4848 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4849 * 4850 * @method fromBban 4851 * @param {String} bban the BBAN to convert to IBAN 4852 * @returns {Iban} the IBAN object 4853 */ 4854 Iban.fromBban = function (bban) { 4855 var countryCode = 'XE'; 4856 4857 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4858 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4859 4860 return new Iban(countryCode + checkDigit + bban); 4861 }; 4862 4863 /** 4864 * Should be used to create IBAN object for given institution and identifier 4865 * 4866 * @method createIndirect 4867 * @param {Object} options, required options are "institution" and "identifier" 4868 * @return {Iban} the IBAN object 4869 */ 4870 Iban.createIndirect = function (options) { 4871 return Iban.fromBban('ETH' + options.institution + options.identifier); 4872 }; 4873 4874 /** 4875 * Thos method should be used to check if given string is valid iban object 4876 * 4877 * @method isValid 4878 * @param {String} iban string 4879 * @return {Boolean} true if it is valid IBAN 4880 */ 4881 Iban.isValid = function (iban) { 4882 var i = new Iban(iban); 4883 return i.isValid(); 4884 }; 4885 4886 /** 4887 * Should be called to check if iban is correct 4888 * 4889 * @method isValid 4890 * @returns {Boolean} true if it is, otherwise false 4891 */ 4892 Iban.prototype.isValid = function () { 4893 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4894 mod9710(iso13616Prepare(this._iban)) === 1; 4895 }; 4896 4897 /** 4898 * Should be called to check if iban number is direct 4899 * 4900 * @method isDirect 4901 * @returns {Boolean} true if it is, otherwise false 4902 */ 4903 Iban.prototype.isDirect = function () { 4904 return this._iban.length === 34 || this._iban.length === 35; 4905 }; 4906 4907 /** 4908 * Should be called to check if iban number if indirect 4909 * 4910 * @method isIndirect 4911 * @returns {Boolean} true if it is, otherwise false 4912 */ 4913 Iban.prototype.isIndirect = function () { 4914 return this._iban.length === 20; 4915 }; 4916 4917 /** 4918 * Should be called to get iban checksum 4919 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4920 * 4921 * @method checksum 4922 * @returns {String} checksum 4923 */ 4924 Iban.prototype.checksum = function () { 4925 return this._iban.substr(2, 2); 4926 }; 4927 4928 /** 4929 * Should be called to get institution identifier 4930 * eg. XREG 4931 * 4932 * @method institution 4933 * @returns {String} institution identifier 4934 */ 4935 Iban.prototype.institution = function () { 4936 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4937 }; 4938 4939 /** 4940 * Should be called to get client identifier within institution 4941 * eg. GAVOFYORK 4942 * 4943 * @method client 4944 * @returns {String} client identifier 4945 */ 4946 Iban.prototype.client = function () { 4947 return this.isIndirect() ? this._iban.substr(11) : ''; 4948 }; 4949 4950 /** 4951 * Should be called to get client direct address 4952 * 4953 * @method address 4954 * @returns {String} client direct address 4955 */ 4956 Iban.prototype.address = function () { 4957 if (this.isDirect()) { 4958 var base36 = this._iban.substr(4); 4959 var asBn = new BigNumber(base36, 36); 4960 return padLeft(asBn.toString(16), 20); 4961 } 4962 4963 return ''; 4964 }; 4965 4966 Iban.prototype.toString = function () { 4967 return this._iban; 4968 }; 4969 4970 module.exports = Iban; 4971 4972 4973 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4974 /* 4975 This file is part of web3.js. 4976 4977 web3.js is free software: you can redistribute it and/or modify 4978 it under the terms of the GNU Lesser General Public License as published by 4979 the Free Software Foundation, either version 3 of the License, or 4980 (at your option) any later version. 4981 4982 web3.js is distributed in the hope that it will be useful, 4983 but WITHOUT ANY WARRANTY; without even the implied warranty of 4984 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4985 GNU Lesser General Public License for more details. 4986 4987 You should have received a copy of the GNU Lesser General Public License 4988 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4989 */ 4990 /** @file ipcprovider.js 4991 * @authors: 4992 * Fabian Vogelsteller <fabian@ethdev.com> 4993 * @date 2015 4994 */ 4995 4996 "use strict"; 4997 4998 var utils = require('../utils/utils'); 4999 var errors = require('./errors'); 5000 5001 5002 var IpcProvider = function (path, net) { 5003 var _this = this; 5004 this.responseCallbacks = {}; 5005 this.path = path; 5006 5007 this.connection = net.connect({path: this.path}); 5008 5009 this.connection.on('error', function(e){ 5010 console.error('IPC Connection Error', e); 5011 _this._timeout(); 5012 }); 5013 5014 this.connection.on('end', function(){ 5015 _this._timeout(); 5016 }); 5017 5018 5019 // LISTEN FOR CONNECTION RESPONSES 5020 this.connection.on('data', function(data) { 5021 /*jshint maxcomplexity: 6 */ 5022 5023 _this._parseResponse(data.toString()).forEach(function(result){ 5024 5025 var id = null; 5026 5027 // get the id which matches the returned id 5028 if(utils.isArray(result)) { 5029 result.forEach(function(load){ 5030 if(_this.responseCallbacks[load.id]) 5031 id = load.id; 5032 }); 5033 } else { 5034 id = result.id; 5035 } 5036 5037 // fire the callback 5038 if(_this.responseCallbacks[id]) { 5039 _this.responseCallbacks[id](null, result); 5040 delete _this.responseCallbacks[id]; 5041 } 5042 }); 5043 }); 5044 }; 5045 5046 /** 5047 Will parse the response and make an array out of it. 5048 5049 @method _parseResponse 5050 @param {String} data 5051 */ 5052 IpcProvider.prototype._parseResponse = function(data) { 5053 var _this = this, 5054 returnValues = []; 5055 5056 // DE-CHUNKER 5057 var dechunkedData = data 5058 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 5059 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 5060 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 5061 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 5062 .split('|--|'); 5063 5064 dechunkedData.forEach(function(data){ 5065 5066 // prepend the last chunk 5067 if(_this.lastChunk) 5068 data = _this.lastChunk + data; 5069 5070 var result = null; 5071 5072 try { 5073 result = JSON.parse(data); 5074 5075 } catch(e) { 5076 5077 _this.lastChunk = data; 5078 5079 // start timeout to cancel all requests 5080 clearTimeout(_this.lastChunkTimeout); 5081 _this.lastChunkTimeout = setTimeout(function(){ 5082 _this._timeout(); 5083 throw errors.InvalidResponse(data); 5084 }, 1000 * 15); 5085 5086 return; 5087 } 5088 5089 // cancel timeout and set chunk to null 5090 clearTimeout(_this.lastChunkTimeout); 5091 _this.lastChunk = null; 5092 5093 if(result) 5094 returnValues.push(result); 5095 }); 5096 5097 return returnValues; 5098 }; 5099 5100 5101 /** 5102 Get the adds a callback to the responseCallbacks object, 5103 which will be called if a response matching the response Id will arrive. 5104 5105 @method _addResponseCallback 5106 */ 5107 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 5108 var id = payload.id || payload[0].id; 5109 var method = payload.method || payload[0].method; 5110 5111 this.responseCallbacks[id] = callback; 5112 this.responseCallbacks[id].method = method; 5113 }; 5114 5115 /** 5116 Timeout all requests when the end/error event is fired 5117 5118 @method _timeout 5119 */ 5120 IpcProvider.prototype._timeout = function() { 5121 for(var key in this.responseCallbacks) { 5122 if(this.responseCallbacks.hasOwnProperty(key)){ 5123 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 5124 delete this.responseCallbacks[key]; 5125 } 5126 } 5127 }; 5128 5129 5130 /** 5131 Check if the current connection is still valid. 5132 5133 @method isConnected 5134 */ 5135 IpcProvider.prototype.isConnected = function() { 5136 var _this = this; 5137 5138 // try reconnect, when connection is gone 5139 if(!_this.connection.writable) 5140 _this.connection.connect({path: _this.path}); 5141 5142 return !!this.connection.writable; 5143 }; 5144 5145 IpcProvider.prototype.send = function (payload) { 5146 5147 if(this.connection.writeSync) { 5148 var result; 5149 5150 // try reconnect, when connection is gone 5151 if(!this.connection.writable) 5152 this.connection.connect({path: this.path}); 5153 5154 var data = this.connection.writeSync(JSON.stringify(payload)); 5155 5156 try { 5157 result = JSON.parse(data); 5158 } catch(e) { 5159 throw errors.InvalidResponse(data); 5160 } 5161 5162 return result; 5163 5164 } else { 5165 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 5166 } 5167 }; 5168 5169 IpcProvider.prototype.sendAsync = function (payload, callback) { 5170 // try reconnect, when connection is gone 5171 if(!this.connection.writable) 5172 this.connection.connect({path: this.path}); 5173 5174 5175 this.connection.write(JSON.stringify(payload)); 5176 this._addResponseCallback(payload, callback); 5177 }; 5178 5179 module.exports = IpcProvider; 5180 5181 5182 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 5183 /* 5184 This file is part of web3.js. 5185 5186 web3.js is free software: you can redistribute it and/or modify 5187 it under the terms of the GNU Lesser General Public License as published by 5188 the Free Software Foundation, either version 3 of the License, or 5189 (at your option) any later version. 5190 5191 web3.js is distributed in the hope that it will be useful, 5192 but WITHOUT ANY WARRANTY; without even the implied warranty of 5193 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5194 GNU Lesser General Public License for more details. 5195 5196 You should have received a copy of the GNU Lesser General Public License 5197 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5198 */ 5199 /** @file jsonrpc.js 5200 * @authors: 5201 * Marek Kotewicz <marek@ethdev.com> 5202 * Aaron Kumavis <aaron@kumavis.me> 5203 * @date 2015 5204 */ 5205 5206 // Initialize Jsonrpc as a simple object with utility functions. 5207 var Jsonrpc = { 5208 messageId: 0 5209 }; 5210 5211 /** 5212 * Should be called to valid json create payload object 5213 * 5214 * @method toPayload 5215 * @param {Function} method of jsonrpc call, required 5216 * @param {Array} params, an array of method params, optional 5217 * @returns {Object} valid jsonrpc payload object 5218 */ 5219 Jsonrpc.toPayload = function (method, params) { 5220 if (!method) 5221 console.error('jsonrpc method should be specified!'); 5222 5223 // advance message ID 5224 Jsonrpc.messageId++; 5225 5226 return { 5227 jsonrpc: '2.0', 5228 id: Jsonrpc.messageId, 5229 method: method, 5230 params: params || [] 5231 }; 5232 }; 5233 5234 /** 5235 * Should be called to check if jsonrpc response is valid 5236 * 5237 * @method isValidResponse 5238 * @param {Object} 5239 * @returns {Boolean} true if response is valid, otherwise false 5240 */ 5241 Jsonrpc.isValidResponse = function (response) { 5242 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 5243 5244 function validateSingleMessage(message){ 5245 return !!message && 5246 !message.error && 5247 message.jsonrpc === '2.0' && 5248 typeof message.id === 'number' && 5249 message.result !== undefined; // only undefined is not valid json object 5250 } 5251 }; 5252 5253 /** 5254 * Should be called to create batch payload object 5255 * 5256 * @method toBatchPayload 5257 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 5258 * @returns {Array} batch payload 5259 */ 5260 Jsonrpc.toBatchPayload = function (messages) { 5261 return messages.map(function (message) { 5262 return Jsonrpc.toPayload(message.method, message.params); 5263 }); 5264 }; 5265 5266 module.exports = Jsonrpc; 5267 5268 5269 },{}],36:[function(require,module,exports){ 5270 /* 5271 This file is part of web3.js. 5272 5273 web3.js is free software: you can redistribute it and/or modify 5274 it under the terms of the GNU Lesser General Public License as published by 5275 the Free Software Foundation, either version 3 of the License, or 5276 (at your option) any later version. 5277 5278 web3.js is distributed in the hope that it will be useful, 5279 but WITHOUT ANY WARRANTY; without even the implied warranty of 5280 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5281 GNU Lesser General Public License for more details. 5282 5283 You should have received a copy of the GNU Lesser General Public License 5284 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5285 */ 5286 /** 5287 * @file method.js 5288 * @author Marek Kotewicz <marek@ethdev.com> 5289 * @date 2015 5290 */ 5291 5292 var utils = require('../utils/utils'); 5293 var errors = require('./errors'); 5294 5295 var Method = function (options) { 5296 this.name = options.name; 5297 this.call = options.call; 5298 this.params = options.params || 0; 5299 this.inputFormatter = options.inputFormatter; 5300 this.outputFormatter = options.outputFormatter; 5301 this.requestManager = null; 5302 }; 5303 5304 Method.prototype.setRequestManager = function (rm) { 5305 this.requestManager = rm; 5306 }; 5307 5308 /** 5309 * Should be used to determine name of the jsonrpc method based on arguments 5310 * 5311 * @method getCall 5312 * @param {Array} arguments 5313 * @return {String} name of jsonrpc method 5314 */ 5315 Method.prototype.getCall = function (args) { 5316 return utils.isFunction(this.call) ? this.call(args) : this.call; 5317 }; 5318 5319 /** 5320 * Should be used to extract callback from array of arguments. Modifies input param 5321 * 5322 * @method extractCallback 5323 * @param {Array} arguments 5324 * @return {Function|Null} callback, if exists 5325 */ 5326 Method.prototype.extractCallback = function (args) { 5327 if (utils.isFunction(args[args.length - 1])) { 5328 return args.pop(); // modify the args array! 5329 } 5330 }; 5331 5332 /** 5333 * Should be called to check if the number of arguments is correct 5334 * 5335 * @method validateArgs 5336 * @param {Array} arguments 5337 * @throws {Error} if it is not 5338 */ 5339 Method.prototype.validateArgs = function (args) { 5340 if (args.length !== this.params) { 5341 throw errors.InvalidNumberOfRPCParams(); 5342 } 5343 }; 5344 5345 /** 5346 * Should be called to format input args of method 5347 * 5348 * @method formatInput 5349 * @param {Array} 5350 * @return {Array} 5351 */ 5352 Method.prototype.formatInput = function (args) { 5353 if (!this.inputFormatter) { 5354 return args; 5355 } 5356 5357 return this.inputFormatter.map(function (formatter, index) { 5358 return formatter ? formatter(args[index]) : args[index]; 5359 }); 5360 }; 5361 5362 /** 5363 * Should be called to format output(result) of method 5364 * 5365 * @method formatOutput 5366 * @param {Object} 5367 * @return {Object} 5368 */ 5369 Method.prototype.formatOutput = function (result) { 5370 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5371 }; 5372 5373 /** 5374 * Should create payload from given input args 5375 * 5376 * @method toPayload 5377 * @param {Array} args 5378 * @return {Object} 5379 */ 5380 Method.prototype.toPayload = function (args) { 5381 var call = this.getCall(args); 5382 var callback = this.extractCallback(args); 5383 var params = this.formatInput(args); 5384 this.validateArgs(params); 5385 5386 return { 5387 method: call, 5388 params: params, 5389 callback: callback 5390 }; 5391 }; 5392 5393 Method.prototype.attachToObject = function (obj) { 5394 var func = this.buildCall(); 5395 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5396 var name = this.name.split('.'); 5397 if (name.length > 1) { 5398 obj[name[0]] = obj[name[0]] || {}; 5399 obj[name[0]][name[1]] = func; 5400 } else { 5401 obj[name[0]] = func; 5402 } 5403 }; 5404 5405 Method.prototype.buildCall = function() { 5406 var method = this; 5407 var send = function () { 5408 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5409 if (payload.callback) { 5410 return method.requestManager.sendAsync(payload, function (err, result) { 5411 payload.callback(err, method.formatOutput(result)); 5412 }); 5413 } 5414 return method.formatOutput(method.requestManager.send(payload)); 5415 }; 5416 send.request = this.request.bind(this); 5417 return send; 5418 }; 5419 5420 /** 5421 * Should be called to create pure JSONRPC request which can be used in batch request 5422 * 5423 * @method request 5424 * @param {...} params 5425 * @return {Object} jsonrpc request 5426 */ 5427 Method.prototype.request = function () { 5428 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5429 payload.format = this.formatOutput.bind(this); 5430 return payload; 5431 }; 5432 5433 module.exports = Method; 5434 5435 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5436 /* 5437 This file is part of web3.js. 5438 5439 web3.js is free software: you can redistribute it and/or modify 5440 it under the terms of the GNU Lesser General Public License as published by 5441 the Free Software Foundation, either version 3 of the License, or 5442 (at your option) any later version. 5443 5444 web3.js is distributed in the hope that it will be useful, 5445 but WITHOUT ANY WARRANTY; without even the implied warranty of 5446 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5447 GNU Lesser General Public License for more details. 5448 5449 You should have received a copy of the GNU Lesser General Public License 5450 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5451 */ 5452 /** @file db.js 5453 * @authors: 5454 * Marek Kotewicz <marek@ethdev.com> 5455 * @date 2015 5456 */ 5457 5458 var Method = require('../method'); 5459 5460 var DB = function (web3) { 5461 this._requestManager = web3._requestManager; 5462 5463 var self = this; 5464 5465 methods().forEach(function(method) { 5466 method.attachToObject(self); 5467 method.setRequestManager(web3._requestManager); 5468 }); 5469 }; 5470 5471 var methods = function () { 5472 var putString = new Method({ 5473 name: 'putString', 5474 call: 'db_putString', 5475 params: 3 5476 }); 5477 5478 var getString = new Method({ 5479 name: 'getString', 5480 call: 'db_getString', 5481 params: 2 5482 }); 5483 5484 var putHex = new Method({ 5485 name: 'putHex', 5486 call: 'db_putHex', 5487 params: 3 5488 }); 5489 5490 var getHex = new Method({ 5491 name: 'getHex', 5492 call: 'db_getHex', 5493 params: 2 5494 }); 5495 5496 return [ 5497 putString, getString, putHex, getHex 5498 ]; 5499 }; 5500 5501 module.exports = DB; 5502 5503 },{"../method":36}],38:[function(require,module,exports){ 5504 /* 5505 This file is part of web3.js. 5506 5507 web3.js is free software: you can redistribute it and/or modify 5508 it under the terms of the GNU Lesser General Public License as published by 5509 the Free Software Foundation, either version 3 of the License, or 5510 (at your option) any later version. 5511 5512 web3.js is distributed in the hope that it will be useful, 5513 but WITHOUT ANY WARRANTY; without even the implied warranty of 5514 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5515 GNU Lesser General Public License for more details. 5516 5517 You should have received a copy of the GNU Lesser General Public License 5518 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5519 */ 5520 /** 5521 * @file eth.js 5522 * @author Marek Kotewicz <marek@ethdev.com> 5523 * @author Fabian Vogelsteller <fabian@ethdev.com> 5524 * @date 2015 5525 */ 5526 5527 "use strict"; 5528 5529 var formatters = require('../formatters'); 5530 var utils = require('../../utils/utils'); 5531 var Method = require('../method'); 5532 var Property = require('../property'); 5533 var c = require('../../utils/config'); 5534 var Contract = require('../contract'); 5535 var watches = require('./watches'); 5536 var Filter = require('../filter'); 5537 var IsSyncing = require('../syncing'); 5538 var namereg = require('../namereg'); 5539 var Iban = require('../iban'); 5540 var transfer = require('../transfer'); 5541 5542 var blockCall = function (args) { 5543 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; 5544 }; 5545 5546 var transactionFromBlockCall = function (args) { 5547 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5548 }; 5549 5550 var uncleCall = function (args) { 5551 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5552 }; 5553 5554 var getBlockTransactionCountCall = function (args) { 5555 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5556 }; 5557 5558 var uncleCountCall = function (args) { 5559 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5560 }; 5561 5562 function U2u(web3) { 5563 this._requestManager = web3._requestManager; 5564 5565 var self = this; 5566 5567 methods().forEach(function(method) { 5568 method.attachToObject(self); 5569 method.setRequestManager(self._requestManager); 5570 }); 5571 5572 properties().forEach(function(p) { 5573 p.attachToObject(self); 5574 p.setRequestManager(self._requestManager); 5575 }); 5576 5577 5578 this.iban = Iban; 5579 this.sendIBANTransaction = transfer.bind(null, this); 5580 } 5581 5582 Object.defineProperty(U2u.prototype, 'defaultBlock', { 5583 get: function () { 5584 return c.defaultBlock; 5585 }, 5586 set: function (val) { 5587 c.defaultBlock = val; 5588 return val; 5589 } 5590 }); 5591 5592 Object.defineProperty(U2u.prototype, 'defaultAccount', { 5593 get: function () { 5594 return c.defaultAccount; 5595 }, 5596 set: function (val) { 5597 c.defaultAccount = val; 5598 return val; 5599 } 5600 }); 5601 5602 var methods = function () { 5603 var getBalance = new Method({ 5604 name: 'getBalance', 5605 call: 'eth_getBalance', 5606 params: 2, 5607 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5608 outputFormatter: formatters.outputBigNumberFormatter 5609 }); 5610 5611 var getStorageAt = new Method({ 5612 name: 'getStorageAt', 5613 call: 'eth_getStorageAt', 5614 params: 3, 5615 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5616 }); 5617 5618 var getCode = new Method({ 5619 name: 'getCode', 5620 call: 'eth_getCode', 5621 params: 2, 5622 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5623 }); 5624 5625 var getBlock = new Method({ 5626 name: 'getBlock', 5627 call: blockCall, 5628 params: 2, 5629 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5630 outputFormatter: formatters.outputBlockFormatter 5631 }); 5632 5633 var getUncle = new Method({ 5634 name: 'getUncle', 5635 call: uncleCall, 5636 params: 2, 5637 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5638 outputFormatter: formatters.outputBlockFormatter, 5639 5640 }); 5641 5642 var getCompilers = new Method({ 5643 name: 'getCompilers', 5644 call: 'eth_getCompilers', 5645 params: 0 5646 }); 5647 5648 var getBlockTransactionCount = new Method({ 5649 name: 'getBlockTransactionCount', 5650 call: getBlockTransactionCountCall, 5651 params: 1, 5652 inputFormatter: [formatters.inputBlockNumberFormatter], 5653 outputFormatter: utils.toDecimal 5654 }); 5655 5656 var getBlockUncleCount = new Method({ 5657 name: 'getBlockUncleCount', 5658 call: uncleCountCall, 5659 params: 1, 5660 inputFormatter: [formatters.inputBlockNumberFormatter], 5661 outputFormatter: utils.toDecimal 5662 }); 5663 5664 var getTransaction = new Method({ 5665 name: 'getTransaction', 5666 call: 'eth_getTransactionByHash', 5667 params: 1, 5668 outputFormatter: formatters.outputTransactionFormatter 5669 }); 5670 5671 var getTransactionFromBlock = new Method({ 5672 name: 'getTransactionFromBlock', 5673 call: transactionFromBlockCall, 5674 params: 2, 5675 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5676 outputFormatter: formatters.outputTransactionFormatter 5677 }); 5678 5679 var getTransactionReceipt = new Method({ 5680 name: 'getTransactionReceipt', 5681 call: 'eth_getTransactionReceipt', 5682 params: 1, 5683 outputFormatter: formatters.outputTransactionReceiptFormatter 5684 }); 5685 5686 var getTransactionCount = new Method({ 5687 name: 'getTransactionCount', 5688 call: 'eth_getTransactionCount', 5689 params: 2, 5690 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5691 outputFormatter: utils.toDecimal 5692 }); 5693 5694 var sendRawTransaction = new Method({ 5695 name: 'sendRawTransaction', 5696 call: 'eth_sendRawTransaction', 5697 params: 1, 5698 inputFormatter: [null] 5699 }); 5700 5701 var sendTransaction = new Method({ 5702 name: 'sendTransaction', 5703 call: 'eth_sendTransaction', 5704 params: 1, 5705 inputFormatter: [formatters.inputTransactionFormatter] 5706 }); 5707 5708 var signTransaction = new Method({ 5709 name: 'signTransaction', 5710 call: 'eth_signTransaction', 5711 params: 1, 5712 inputFormatter: [formatters.inputTransactionFormatter] 5713 }); 5714 5715 var sign = new Method({ 5716 name: 'sign', 5717 call: 'eth_sign', 5718 params: 2, 5719 inputFormatter: [formatters.inputAddressFormatter, null] 5720 }); 5721 5722 var call = new Method({ 5723 name: 'call', 5724 call: 'eth_call', 5725 params: 2, 5726 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5727 }); 5728 5729 var estimateGas = new Method({ 5730 name: 'estimateGas', 5731 call: 'eth_estimateGas', 5732 params: 1, 5733 inputFormatter: [formatters.inputCallFormatter], 5734 outputFormatter: utils.toDecimal 5735 }); 5736 5737 var compileSolidity = new Method({ 5738 name: 'compile.solidity', 5739 call: 'eth_compileSolidity', 5740 params: 1 5741 }); 5742 5743 var compileLLL = new Method({ 5744 name: 'compile.lll', 5745 call: 'eth_compileLLL', 5746 params: 1 5747 }); 5748 5749 var compileSerpent = new Method({ 5750 name: 'compile.serpent', 5751 call: 'eth_compileSerpent', 5752 params: 1 5753 }); 5754 5755 var submitWork = new Method({ 5756 name: 'submitWork', 5757 call: 'eth_submitWork', 5758 params: 3 5759 }); 5760 5761 var getWork = new Method({ 5762 name: 'getWork', 5763 call: 'eth_getWork', 5764 params: 0 5765 }); 5766 5767 var getEvent = new Method({ 5768 name: 'getEvent', 5769 call: 'u2u_getEvent', 5770 params: 2 5771 }); 5772 5773 var getEventHeader = new Method({ 5774 name: 'getEventHeader', 5775 call: 'u2u_getEventHeader', 5776 params: 1 5777 }); 5778 5779 var getHeads = new Method({ 5780 name: 'getHeads', 5781 call: 'u2u_getHeads', 5782 params: 1, 5783 inputFormatter: [formatters.inputBlockNumberFormatter] 5784 }); 5785 5786 var getConsensusTime = new Method({ 5787 name: 'getConsensusTime', 5788 call: 'u2u_getConsensusTime', 5789 params: 1, 5790 outputFormatter: utils.toDecimal 5791 }); 5792 5793 var currentEpoch = new Method({ 5794 name: 'currentEpoch', 5795 call: 'u2u_currentEpoch', 5796 params: 0, 5797 outputFormatter: utils.toDecimal 5798 }); 5799 5800 var getEpochStats = new Method({ 5801 name: 'getEpochStats', 5802 call: 'u2u_getEpochStats', 5803 params: 1, 5804 inputFormatter: [formatters.inputBlockNumberFormatter], 5805 outputFormatter: formatters.outputEpochStatsFormatter 5806 }); 5807 5808 return [ 5809 getBalance, 5810 getStorageAt, 5811 getCode, 5812 getBlock, 5813 getUncle, 5814 getCompilers, 5815 getBlockTransactionCount, 5816 getBlockUncleCount, 5817 getTransaction, 5818 getTransactionFromBlock, 5819 getTransactionReceipt, 5820 getTransactionCount, 5821 call, 5822 estimateGas, 5823 sendRawTransaction, 5824 signTransaction, 5825 sendTransaction, 5826 sign, 5827 compileSolidity, 5828 compileLLL, 5829 compileSerpent, 5830 submitWork, 5831 getWork, 5832 getEvent, 5833 getEventHeader, 5834 getHeads, 5835 getConsensusTime, 5836 currentEpoch, 5837 getEpochStats 5838 ]; 5839 }; 5840 5841 5842 var properties = function () { 5843 return [ 5844 new Property({ 5845 name: 'coinbase', 5846 getter: 'eth_coinbase' 5847 }), 5848 new Property({ 5849 name: 'hashrate', 5850 getter: 'eth_hashrate', 5851 outputFormatter: utils.toDecimal 5852 }), 5853 new Property({ 5854 name: 'syncing', 5855 getter: 'eth_syncing', 5856 outputFormatter: formatters.outputSyncingFormatter 5857 }), 5858 new Property({ 5859 name: 'gasPrice', 5860 getter: 'eth_gasPrice', 5861 outputFormatter: formatters.outputBigNumberFormatter 5862 }), 5863 new Property({ 5864 name: 'accounts', 5865 getter: 'eth_accounts' 5866 }), 5867 new Property({ 5868 name: 'blockNumber', 5869 getter: 'eth_blockNumber', 5870 outputFormatter: utils.toDecimal 5871 }), 5872 new Property({ 5873 name: 'protocolVersion', 5874 getter: 'eth_protocolVersion' 5875 }) 5876 ]; 5877 }; 5878 5879 U2u.prototype.contract = function (abi) { 5880 var factory = new Contract(this, abi); 5881 return factory; 5882 }; 5883 5884 U2u.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5885 return new Filter(options, 'u2u', this._requestManager, watches.u2u(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5886 }; 5887 5888 U2u.prototype.namereg = function () { 5889 return this.contract(namereg.global.abi).at(namereg.global.address); 5890 }; 5891 5892 U2u.prototype.icapNamereg = function () { 5893 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5894 }; 5895 5896 U2u.prototype.isSyncing = function (callback) { 5897 return new IsSyncing(this._requestManager, callback); 5898 }; 5899 5900 module.exports = U2u; 5901 5902 },{"../../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}],380:[function(require,module,exports){ 5903 /* 5904 This file is part of web3.js. 5905 5906 web3.js is free software: you can redistribute it and/or modify 5907 it under the terms of the GNU Lesser General Public License as published by 5908 the Free Software Foundation, either version 3 of the License, or 5909 (at your option) any later version. 5910 5911 web3.js is distributed in the hope that it will be useful, 5912 but WITHOUT ANY WARRANTY; without even the implied warranty of 5913 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5914 GNU Lesser General Public License for more details. 5915 5916 You should have received a copy of the GNU Lesser General Public License 5917 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5918 */ 5919 /** 5920 * @file debug.js 5921 * @author Marek Kotewicz <marek@ethdev.com> 5922 * @author Fabian Vogelsteller <fabian@ethdev.com> 5923 * @date 2015 5924 */ 5925 5926 "use strict"; 5927 5928 var formatters = require('../formatters'); 5929 var utils = require('../../utils/utils'); 5930 var Method = require('../method'); 5931 var Property = require('../property'); 5932 var c = require('../../utils/config'); 5933 var Contract = require('../contract'); 5934 var watches = require('./watches'); 5935 var Filter = require('../filter'); 5936 var IsSyncing = require('../syncing'); 5937 var namereg = require('../namereg'); 5938 var Iban = require('../iban'); 5939 var transfer = require('../transfer'); 5940 5941 function Debug(web3) { 5942 this._requestManager = web3._requestManager; 5943 5944 var self = this; 5945 5946 methods().forEach(function(method) { 5947 method.attachToObject(self); 5948 method.setRequestManager(self._requestManager); 5949 }); 5950 5951 properties().forEach(function(p) { 5952 p.attachToObject(self); 5953 p.setRequestManager(self._requestManager); 5954 }); 5955 5956 5957 this.iban = Iban; 5958 this.sendIBANTransaction = transfer.bind(null, this); 5959 } 5960 5961 var methods = function () { 5962 // Output formaters for 'samples' and 'count'? 5963 5964 var validatorTimeDrifts = new Method({ 5965 name: 'validatorTimeDrifts', 5966 call: 'debug_validatorTimeDrifts', 5967 params: 3, 5968 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex, utils.toHex], 5969 outputFormatter: formatters.outputValidatorTimeDriftsFormatter 5970 }); 5971 5972 var validatorVersions = new Method({ 5973 name: 'validatorVersions', 5974 call: 'debug_validatorVersions', 5975 params: 2, 5976 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5977 outputFormatter: formatters.outputKeysToDecimal 5978 }); 5979 5980 var blocksTransactionTimes = new Method({ 5981 name: 'blocksTransactionTimes', 5982 call: 'debug_blocksTransactionTimes', 5983 params: 2, 5984 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5985 outputFormatter: formatters.outputKeyValuesToDecimal 5986 }); 5987 5988 var blocksTTF = new Method({ 5989 name: 'blocksTTF', 5990 call: 'debug_blocksTTF', 5991 params: 4, 5992 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex, null, utils.toHex ], 5993 outputFormatter: formatters.outputBlocksTTFFormatter 5994 }); 5995 5996 var blocksTPS = new Method({ 5997 name: 'blocksTPS', 5998 call: 'debug_blocksTransactionTimes', 5999 params: 2, 6000 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 6001 outputFormatter: formatters.outputBlocksTPSFormatter 6002 }); 6003 6004 return [ 6005 validatorTimeDrifts, 6006 validatorVersions, 6007 blocksTransactionTimes, 6008 blocksTTF, 6009 blocksTPS 6010 ]; 6011 }; 6012 6013 var properties = function () { 6014 return []; 6015 }; 6016 6017 module.exports = Debug; 6018 6019 },{"../../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}],381:[function(require,module,exports){ 6020 /* 6021 This file is part of web3.js. 6022 6023 web3.js is free software: you can redistribute it and/or modify 6024 it under the terms of the GNU Lesser General Public License as published by 6025 the Free Software Foundation, either version 3 of the License, or 6026 (at your option) any later version. 6027 6028 web3.js is distributed in the hope that it will be useful, 6029 but WITHOUT ANY WARRANTY; without even the implied warranty of 6030 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6031 GNU Lesser General Public License for more details. 6032 6033 You should have received a copy of the GNU Lesser General Public License 6034 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6035 */ 6036 /** 6037 * @file sfc.js 6038 * @author Marek Kotewicz <marek@ethdev.com> 6039 * @author Fabian Vogelsteller <fabian@ethdev.com> 6040 * @author devintegral3 <devintegral3@sfxdx.ru> 6041 * @date 2020 6042 */ 6043 6044 "use strict"; 6045 6046 var formatters = require('../formatters'); 6047 var utils = require('../../utils/utils'); 6048 var Method = require('../method'); 6049 6050 function Sfc(web3) { 6051 this._requestManager = web3._requestManager; 6052 6053 var self = this; 6054 6055 methods().forEach(function(method) { 6056 method.attachToObject(self); 6057 method.setRequestManager(self._requestManager); 6058 }); 6059 6060 properties().forEach(function(p) { 6061 p.attachToObject(self); 6062 p.setRequestManager(self._requestManager); 6063 }); 6064 } 6065 6066 var methods = function () { 6067 6068 var getValidationScore = new Method({ 6069 name: 'getValidationScore', 6070 call: 'sfc_getValidationScore', 6071 params: 1, 6072 inputFormatter: [utils.toHex], 6073 outputFormatter: formatters.outputBigNumberFormatter 6074 }); 6075 6076 var getOriginationScore = new Method({ 6077 name: 'getOriginationScore', 6078 call: 'sfc_getOriginationScore', 6079 params: 1, 6080 inputFormatter: [utils.toHex], 6081 outputFormatter: formatters.outputBigNumberFormatter 6082 }); 6083 6084 var getStakerPoI = new Method({ 6085 name: 'getStakerPoI', 6086 call: 'sfc_getStakerPoI', 6087 params: 1, 6088 inputFormatter: [utils.toHex], 6089 outputFormatter: formatters.outputBigNumberFormatter 6090 }); 6091 6092 var getRewardWeights = new Method({ 6093 name: 'getRewardWeights', 6094 call: 'sfc_getRewardWeights', 6095 params: 1, 6096 inputFormatter: [utils.toHex], 6097 outputFormatter: formatters.outputDecimalProperties 6098 }); 6099 6100 var getDowntime = new Method({ 6101 name: 'getDowntime', 6102 call: 'sfc_getDowntime', 6103 params: 1, 6104 inputFormatter: [utils.toHex], 6105 outputFormatter: formatters.outputDecimalProperties 6106 }); 6107 6108 var getStaker = new Method({ 6109 name: 'getStaker', 6110 call: 'sfc_getStaker', 6111 params: 2, 6112 inputFormatter: [utils.toHex, utils.toHex], 6113 outputFormatter: formatters.outputStakerFormatter 6114 }); 6115 6116 var getStakerByAddress = new Method({ 6117 name: 'getStakerByAddress', 6118 call: 'sfc_getStakerByAddress', 6119 params: 2, 6120 inputFormatter: [utils.toHex, utils.toHex], 6121 outputFormatter: formatters.outputStakerFormatter 6122 }); 6123 6124 var getStakers = new Method({ 6125 name: 'getStakers', 6126 call: 'sfc_getStakers', 6127 params: 1, 6128 inputFormatter: [utils.toHex], 6129 outputFormatter: formatters.outputStakersFormatter 6130 }); 6131 6132 var getDelegationsOf = new Method({ 6133 name: 'getDelegationsOf', 6134 call: 'sfc_getDelegationsOf', 6135 params: 2, 6136 inputFormatter: [utils.toHex, utils.toHex], 6137 outputFormatter: formatters.outputDelegationsFormatter 6138 }); 6139 6140 var getDelegationsByAddress = new Method({ 6141 name: 'getDelegationsByAddress', 6142 call: 'sfc_getDelegationsByAddress', 6143 params: 2, 6144 inputFormatter: [utils.toHex, utils.toHex], 6145 outputFormatter: formatters.outputDelegationsFormatter 6146 }); 6147 6148 var getDelegation = new Method({ 6149 name: 'getDelegation', 6150 call: 'sfc_getDelegation', 6151 params: 3, 6152 inputFormatter: [utils.toHex, utils.toHex, utils.toHex], 6153 outputFormatter: formatters.outputDelegationFormatter 6154 }); 6155 6156 var getDelegationClaimedRewards = new Method({ 6157 name: 'getDelegationClaimedRewards', 6158 call: 'sfc_getDelegationClaimedRewards', 6159 params: 2, 6160 inputFormatter: [utils.toHex, utils.toHex], 6161 outputFormatter: formatters.outputBigNumberFormatter 6162 }); 6163 6164 var getStakerClaimedRewards = new Method({ 6165 name: 'getStakerClaimedRewards', 6166 call: 'sfc_getStakerClaimedRewards', 6167 params: 1, 6168 inputFormatter: [utils.toHex], 6169 outputFormatter: formatters.outputBigNumberFormatter 6170 }); 6171 6172 var getStakerDelegationsClaimedRewards = new Method({ 6173 name: 'getStakerDelegationsClaimedRewards', 6174 call: 'sfc_getStakerDelegationsClaimedRewards', 6175 params: 1, 6176 inputFormatter: [utils.toHex], 6177 outputFormatter: formatters.outputBigNumberFormatter 6178 }); 6179 6180 return [ 6181 getValidationScore, 6182 getOriginationScore, 6183 getStakerPoI, 6184 getRewardWeights, 6185 getDowntime, 6186 getStaker, 6187 getStakerByAddress, 6188 getStakers, 6189 getDelegationsOf, 6190 getDelegationsByAddress, 6191 getDelegation, 6192 getDelegationClaimedRewards, 6193 getStakerClaimedRewards, 6194 getStakerDelegationsClaimedRewards 6195 ]; 6196 }; 6197 6198 var properties = function () { 6199 return []; 6200 }; 6201 6202 module.exports = Sfc; 6203 6204 },{"../../utils/utils":20,"../formatters":30,"../method":36,}],382:[function(require,module,exports){ 6205 /* 6206 This file is part of web3.js. 6207 6208 web3.js is free software: you can redistribute it and/or modify 6209 it under the terms of the GNU Lesser General Public License as published by 6210 the Free Software Foundation, either version 3 of the License, or 6211 (at your option) any later version. 6212 6213 web3.js is distributed in the hope that it will be useful, 6214 but WITHOUT ANY WARRANTY; without even the implied warranty of 6215 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6216 GNU Lesser General Public License for more details. 6217 6218 You should have received a copy of the GNU Lesser General Public License 6219 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6220 */ 6221 /** 6222 * @file abft.js 6223 * @author alex <rusdev.alex@gmail.com> 6224 * @date 2021 6225 */ 6226 6227 "use strict"; 6228 6229 var formatters = require('../formatters'); 6230 var utils = require('../../utils/utils'); 6231 var Method = require('../method'); 6232 6233 function Abft(web3) { 6234 this._requestManager = web3._requestManager; 6235 6236 var self = this; 6237 6238 methods().forEach(function(method) { 6239 method.attachToObject(self); 6240 method.setRequestManager(self._requestManager); 6241 }); 6242 6243 properties().forEach(function(p) { 6244 p.attachToObject(self); 6245 p.setRequestManager(self._requestManager); 6246 }); 6247 6248 } 6249 6250 var methods = function () { 6251 6252 var getDowntime = new Method({ 6253 name: 'getDowntime', 6254 call: 'abft_getDowntime', 6255 params: 1, 6256 inputFormatter: [utils.toHex], 6257 outputFormatter: formatters.outputDecimalProperties 6258 }); 6259 6260 var getEpochUptime = new Method({ 6261 name: 'getEpochUptime', 6262 call: 'abft_getEpochUptime', 6263 params: 1, 6264 inputFormatter: [utils.toHex], 6265 outputFormatter: formatters.outputBigNumberFormatter 6266 }); 6267 6268 var getOriginatedEpochFee = new Method({ 6269 name: 'getOriginatedEpochFee', 6270 call: 'abft_getOriginatedEpochFee', 6271 params: 1, 6272 inputFormatter: [utils.toHex], 6273 outputFormatter: formatters.outputBigNumberFormatter 6274 }); 6275 6276 return [ 6277 getDowntime, 6278 getEpochUptime, 6279 getOriginatedEpochFee, 6280 ]; 6281 }; 6282 6283 var properties = function () { 6284 return []; 6285 }; 6286 6287 module.exports = Abft; 6288 6289 },{"../../utils/utils":20,"../formatters":30,"../method":36}],383:[function(require,module,exports){ 6290 /* 6291 This file is part of web3.js. 6292 6293 web3.js is free software: you can redistribute it and/or modify 6294 it under the terms of the GNU Lesser General Public License as published by 6295 the Free Software Foundation, either version 3 of the License, or 6296 (at your option) any later version. 6297 6298 web3.js is distributed in the hope that it will be useful, 6299 but WITHOUT ANY WARRANTY; without even the implied warranty of 6300 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6301 GNU Lesser General Public License for more details. 6302 6303 You should have received a copy of the GNU Lesser General Public License 6304 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6305 */ 6306 /** 6307 * @file dag.js 6308 * @author alex <rusdev.alex@gmail.com> 6309 * @date 2021 6310 */ 6311 6312 "use strict"; 6313 6314 var formatters = require('../formatters'); 6315 var utils = require('../../utils/utils'); 6316 var Method = require('../method'); 6317 6318 function Dag(web3) { 6319 this._requestManager = web3._requestManager; 6320 6321 var self = this; 6322 6323 methods().forEach(function(method) { 6324 method.attachToObject(self); 6325 method.setRequestManager(self._requestManager); 6326 }); 6327 6328 properties().forEach(function(p) { 6329 p.attachToObject(self); 6330 p.setRequestManager(self._requestManager); 6331 }); 6332 6333 } 6334 6335 var methods = function () { 6336 6337 var getEvent = new Method({ 6338 name: 'getEvent', 6339 call: 'dag_getEvent', 6340 params: 1, 6341 inputFormatter: [null], 6342 outputFormatter: formatters.outputDagEventFormatter 6343 }); 6344 6345 var getEventPayload = new Method({ 6346 name: 'getEventPayload', 6347 call: 'dag_getEventPayload', 6348 params: 2, 6349 inputFormatter: [null, function (val) { return !!val; }], 6350 outputFormatter: formatters.outputDagEventFormatter 6351 }); 6352 6353 var getHeads = new Method({ 6354 name: 'getHeads', 6355 call: 'dag_getHeads', 6356 params: 1, 6357 inputFormatter: [formatters.inputBlockNumberFormatter], 6358 outputFormatter: formatters.outputHeadsFormatter 6359 }); 6360 6361 return [ 6362 getEvent, 6363 getEventPayload, 6364 getHeads, 6365 ]; 6366 }; 6367 6368 var properties = function () { 6369 return []; 6370 }; 6371 6372 module.exports = Dag; 6373 6374 },{"../../utils/utils":20,"../formatters":30,"../method":36}],39:[function(require,module,exports){ 6375 /* 6376 This file is part of web3.js. 6377 6378 web3.js is free software: you can redistribute it and/or modify 6379 it under the terms of the GNU Lesser General Public License as published by 6380 the Free Software Foundation, either version 3 of the License, or 6381 (at your option) any later version. 6382 6383 web3.js is distributed in the hope that it will be useful, 6384 but WITHOUT ANY WARRANTY; without even the implied warranty of 6385 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6386 GNU Lesser General Public License for more details. 6387 6388 You should have received a copy of the GNU Lesser General Public License 6389 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6390 */ 6391 /** @file eth.js 6392 * @authors: 6393 * Marek Kotewicz <marek@ethdev.com> 6394 * @date 2015 6395 */ 6396 6397 var utils = require('../../utils/utils'); 6398 var Property = require('../property'); 6399 6400 var Net = function (web3) { 6401 this._requestManager = web3._requestManager; 6402 6403 var self = this; 6404 6405 properties().forEach(function(p) { 6406 p.attachToObject(self); 6407 p.setRequestManager(web3._requestManager); 6408 }); 6409 }; 6410 6411 /// @returns an array of objects describing web3.eth api properties 6412 var properties = function () { 6413 return [ 6414 new Property({ 6415 name: 'listening', 6416 getter: 'net_listening' 6417 }), 6418 new Property({ 6419 name: 'peerCount', 6420 getter: 'net_peerCount', 6421 outputFormatter: utils.toDecimal 6422 }) 6423 ]; 6424 }; 6425 6426 module.exports = Net; 6427 6428 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 6429 /* 6430 This file is part of web3.js. 6431 6432 web3.js is free software: you can redistribute it and/or modify 6433 it under the terms of the GNU Lesser General Public License as published by 6434 the Free Software Foundation, either version 3 of the License, or 6435 (at your option) any later version. 6436 6437 web3.js is distributed in the hope that it will be useful, 6438 but WITHOUT ANY WARRANTY; without even the implied warranty of 6439 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6440 GNU Lesser General Public License for more details. 6441 6442 You should have received a copy of the GNU Lesser General Public License 6443 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6444 */ 6445 /** 6446 * @file eth.js 6447 * @author Marek Kotewicz <marek@ethdev.com> 6448 * @author Fabian Vogelsteller <fabian@ethdev.com> 6449 * @date 2015 6450 */ 6451 6452 "use strict"; 6453 6454 var Method = require('../method'); 6455 var Property = require('../property'); 6456 var formatters = require('../formatters'); 6457 6458 function Personal(web3) { 6459 this._requestManager = web3._requestManager; 6460 6461 var self = this; 6462 6463 methods().forEach(function(method) { 6464 method.attachToObject(self); 6465 method.setRequestManager(self._requestManager); 6466 }); 6467 6468 properties().forEach(function(p) { 6469 p.attachToObject(self); 6470 p.setRequestManager(self._requestManager); 6471 }); 6472 } 6473 6474 var methods = function () { 6475 var newAccount = new Method({ 6476 name: 'newAccount', 6477 call: 'personal_newAccount', 6478 params: 1, 6479 inputFormatter: [null] 6480 }); 6481 6482 var importRawKey = new Method({ 6483 name: 'importRawKey', 6484 call: 'personal_importRawKey', 6485 params: 2 6486 }); 6487 6488 var sign = new Method({ 6489 name: 'sign', 6490 call: 'personal_sign', 6491 params: 3, 6492 inputFormatter: [null, formatters.inputAddressFormatter, null] 6493 }); 6494 6495 var ecRecover = new Method({ 6496 name: 'ecRecover', 6497 call: 'personal_ecRecover', 6498 params: 2 6499 }); 6500 6501 var unlockAccount = new Method({ 6502 name: 'unlockAccount', 6503 call: 'personal_unlockAccount', 6504 params: 3, 6505 inputFormatter: [formatters.inputAddressFormatter, null, null] 6506 }); 6507 6508 var sendTransaction = new Method({ 6509 name: 'sendTransaction', 6510 call: 'personal_sendTransaction', 6511 params: 2, 6512 inputFormatter: [formatters.inputTransactionFormatter, null] 6513 }); 6514 6515 var lockAccount = new Method({ 6516 name: 'lockAccount', 6517 call: 'personal_lockAccount', 6518 params: 1, 6519 inputFormatter: [formatters.inputAddressFormatter] 6520 }); 6521 6522 return [ 6523 newAccount, 6524 importRawKey, 6525 unlockAccount, 6526 ecRecover, 6527 sign, 6528 sendTransaction, 6529 lockAccount 6530 ]; 6531 }; 6532 6533 var properties = function () { 6534 return [ 6535 new Property({ 6536 name: 'listAccounts', 6537 getter: 'personal_listAccounts' 6538 }) 6539 ]; 6540 }; 6541 6542 6543 module.exports = Personal; 6544 6545 },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){ 6546 /* 6547 This file is part of web3.js. 6548 6549 web3.js is free software: you can redistribute it and/or modify 6550 it under the terms of the GNU Lesser General Public License as published by 6551 the Free Software Foundation, either version 3 of the License, or 6552 (at your option) any later version. 6553 6554 web3.js is distributed in the hope that it will be useful, 6555 but WITHOUT ANY WARRANTY; without even the implied warranty of 6556 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6557 GNU Lesser General Public License for more details. 6558 6559 You should have received a copy of the GNU Lesser General Public License 6560 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6561 */ 6562 /** @file shh.js 6563 * @authors: 6564 * Fabian Vogelsteller <fabian@ethereum.org> 6565 * Marek Kotewicz <marek@ethcore.io> 6566 * @date 2017 6567 */ 6568 6569 var Method = require('../method'); 6570 var Filter = require('../filter'); 6571 var watches = require('./watches'); 6572 6573 var Shh = function (web3) { 6574 this._requestManager = web3._requestManager; 6575 6576 var self = this; 6577 6578 methods().forEach(function(method) { 6579 method.attachToObject(self); 6580 method.setRequestManager(self._requestManager); 6581 }); 6582 }; 6583 6584 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 6585 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 6586 }; 6587 6588 var methods = function () { 6589 6590 return [ 6591 new Method({ 6592 name: 'version', 6593 call: 'shh_version', 6594 params: 0 6595 }), 6596 new Method({ 6597 name: 'info', 6598 call: 'shh_info', 6599 params: 0 6600 }), 6601 new Method({ 6602 name: 'setMaxMessageSize', 6603 call: 'shh_setMaxMessageSize', 6604 params: 1 6605 }), 6606 new Method({ 6607 name: 'setMinPoW', 6608 call: 'shh_setMinPoW', 6609 params: 1 6610 }), 6611 new Method({ 6612 name: 'markTrustedPeer', 6613 call: 'shh_markTrustedPeer', 6614 params: 1 6615 }), 6616 new Method({ 6617 name: 'newKeyPair', 6618 call: 'shh_newKeyPair', 6619 params: 0 6620 }), 6621 new Method({ 6622 name: 'addPrivateKey', 6623 call: 'shh_addPrivateKey', 6624 params: 1 6625 }), 6626 new Method({ 6627 name: 'deleteKeyPair', 6628 call: 'shh_deleteKeyPair', 6629 params: 1 6630 }), 6631 new Method({ 6632 name: 'hasKeyPair', 6633 call: 'shh_hasKeyPair', 6634 params: 1 6635 }), 6636 new Method({ 6637 name: 'getPublicKey', 6638 call: 'shh_getPublicKey', 6639 params: 1 6640 }), 6641 new Method({ 6642 name: 'getPrivateKey', 6643 call: 'shh_getPrivateKey', 6644 params: 1 6645 }), 6646 new Method({ 6647 name: 'newSymKey', 6648 call: 'shh_newSymKey', 6649 params: 0 6650 }), 6651 new Method({ 6652 name: 'addSymKey', 6653 call: 'shh_addSymKey', 6654 params: 1 6655 }), 6656 new Method({ 6657 name: 'generateSymKeyFromPassword', 6658 call: 'shh_generateSymKeyFromPassword', 6659 params: 1 6660 }), 6661 new Method({ 6662 name: 'hasSymKey', 6663 call: 'shh_hasSymKey', 6664 params: 1 6665 }), 6666 new Method({ 6667 name: 'getSymKey', 6668 call: 'shh_getSymKey', 6669 params: 1 6670 }), 6671 new Method({ 6672 name: 'deleteSymKey', 6673 call: 'shh_deleteSymKey', 6674 params: 1 6675 }), 6676 6677 // subscribe and unsubscribe missing 6678 6679 new Method({ 6680 name: 'post', 6681 call: 'shh_post', 6682 params: 1, 6683 inputFormatter: [null] 6684 }) 6685 ]; 6686 }; 6687 6688 module.exports = Shh; 6689 6690 6691 },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){ 6692 /* 6693 This file is part of web3.js. 6694 6695 web3.js is free software: you can redistribute it and/or modify 6696 it under the terms of the GNU Lesser General Public License as published by 6697 the Free Software Foundation, either version 3 of the License, or 6698 (at your option) any later version. 6699 6700 web3.js is distributed in the hope that it will be useful, 6701 but WITHOUT ANY WARRANTY; without even the implied warranty of 6702 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6703 GNU Lesser General Public License for more details. 6704 6705 You should have received a copy of the GNU Lesser General Public License 6706 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6707 */ 6708 /** 6709 * @file bzz.js 6710 * @author Alex Beregszaszi <alex@rtfs.hu> 6711 * @date 2016 6712 * 6713 * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33 6714 */ 6715 "use strict"; 6716 6717 var Method = require('../method'); 6718 var Property = require('../property'); 6719 6720 function Swarm(web3) { 6721 this._requestManager = web3._requestManager; 6722 6723 var self = this; 6724 6725 methods().forEach(function(method) { 6726 method.attachToObject(self); 6727 method.setRequestManager(self._requestManager); 6728 }); 6729 6730 properties().forEach(function(p) { 6731 p.attachToObject(self); 6732 p.setRequestManager(self._requestManager); 6733 }); 6734 } 6735 6736 var methods = function () { 6737 var blockNetworkRead = new Method({ 6738 name: 'blockNetworkRead', 6739 call: 'bzz_blockNetworkRead', 6740 params: 1, 6741 inputFormatter: [null] 6742 }); 6743 6744 var syncEnabled = new Method({ 6745 name: 'syncEnabled', 6746 call: 'bzz_syncEnabled', 6747 params: 1, 6748 inputFormatter: [null] 6749 }); 6750 6751 var swapEnabled = new Method({ 6752 name: 'swapEnabled', 6753 call: 'bzz_swapEnabled', 6754 params: 1, 6755 inputFormatter: [null] 6756 }); 6757 6758 var download = new Method({ 6759 name: 'download', 6760 call: 'bzz_download', 6761 params: 2, 6762 inputFormatter: [null, null] 6763 }); 6764 6765 var upload = new Method({ 6766 name: 'upload', 6767 call: 'bzz_upload', 6768 params: 2, 6769 inputFormatter: [null, null] 6770 }); 6771 6772 var retrieve = new Method({ 6773 name: 'retrieve', 6774 call: 'bzz_retrieve', 6775 params: 1, 6776 inputFormatter: [null] 6777 }); 6778 6779 var store = new Method({ 6780 name: 'store', 6781 call: 'bzz_store', 6782 params: 2, 6783 inputFormatter: [null, null] 6784 }); 6785 6786 var get = new Method({ 6787 name: 'get', 6788 call: 'bzz_get', 6789 params: 1, 6790 inputFormatter: [null] 6791 }); 6792 6793 var put = new Method({ 6794 name: 'put', 6795 call: 'bzz_put', 6796 params: 2, 6797 inputFormatter: [null, null] 6798 }); 6799 6800 var modify = new Method({ 6801 name: 'modify', 6802 call: 'bzz_modify', 6803 params: 4, 6804 inputFormatter: [null, null, null, null] 6805 }); 6806 6807 return [ 6808 blockNetworkRead, 6809 syncEnabled, 6810 swapEnabled, 6811 download, 6812 upload, 6813 retrieve, 6814 store, 6815 get, 6816 put, 6817 modify 6818 ]; 6819 }; 6820 6821 var properties = function () { 6822 return []; 6823 }; 6824 6825 6826 module.exports = Swarm; 6827 6828 },{"../method":36,"../property":45}],43:[function(require,module,exports){ 6829 /* 6830 This file is part of web3.js. 6831 6832 web3.js is free software: you can redistribute it and/or modify 6833 it under the terms of the GNU Lesser General Public License as published by 6834 the Free Software Foundation, either version 3 of the License, or 6835 (at your option) any later version. 6836 6837 web3.js is distributed in the hope that it will be useful, 6838 but WITHOUT ANY WARRANTY; without even the implied warranty of 6839 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6840 GNU Lesser General Public License for more details. 6841 6842 You should have received a copy of the GNU Lesser General Public License 6843 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6844 */ 6845 /** @file watches.js 6846 * @authors: 6847 * Marek Kotewicz <marek@ethdev.com> 6848 * @date 2015 6849 */ 6850 6851 var Method = require('../method'); 6852 6853 /// @returns an array of objects describing web3.eth.filter api methods 6854 var u2u = function () { 6855 var newFilterCall = function (args) { 6856 var type = args[0]; 6857 6858 switch(type) { 6859 case 'latest': 6860 args.shift(); 6861 this.params = 0; 6862 return 'eth_newBlockFilter'; 6863 case 'pending': 6864 args.shift(); 6865 this.params = 0; 6866 return 'eth_newPendingTransactionFilter'; 6867 default: 6868 return 'eth_newFilter'; 6869 } 6870 }; 6871 6872 var newFilter = new Method({ 6873 name: 'newFilter', 6874 call: newFilterCall, 6875 params: 1 6876 }); 6877 6878 var uninstallFilter = new Method({ 6879 name: 'uninstallFilter', 6880 call: 'eth_uninstallFilter', 6881 params: 1 6882 }); 6883 6884 var getLogs = new Method({ 6885 name: 'getLogs', 6886 call: 'eth_getFilterLogs', 6887 params: 1 6888 }); 6889 6890 var poll = new Method({ 6891 name: 'poll', 6892 call: 'eth_getFilterChanges', 6893 params: 1 6894 }); 6895 6896 return [ 6897 newFilter, 6898 uninstallFilter, 6899 getLogs, 6900 poll 6901 ]; 6902 }; 6903 6904 /// @returns an array of objects describing web3.shh.watch api methods 6905 var shh = function () { 6906 6907 return [ 6908 new Method({ 6909 name: 'newFilter', 6910 call: 'shh_newMessageFilter', 6911 params: 1 6912 }), 6913 new Method({ 6914 name: 'uninstallFilter', 6915 call: 'shh_deleteMessageFilter', 6916 params: 1 6917 }), 6918 new Method({ 6919 name: 'getLogs', 6920 call: 'shh_getFilterMessages', 6921 params: 1 6922 }), 6923 new Method({ 6924 name: 'poll', 6925 call: 'shh_getFilterMessages', 6926 params: 1 6927 }) 6928 ]; 6929 }; 6930 6931 module.exports = { 6932 u2u: u2u, 6933 shh: shh 6934 }; 6935 6936 6937 },{"../method":36}],44:[function(require,module,exports){ 6938 /* 6939 This file is part of web3.js. 6940 6941 web3.js is free software: you can redistribute it and/or modify 6942 it under the terms of the GNU Lesser General Public License as published by 6943 the Free Software Foundation, either version 3 of the License, or 6944 (at your option) any later version. 6945 6946 web3.js is distributed in the hope that it will be useful, 6947 but WITHOUT ANY WARRANTY; without even the implied warranty of 6948 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6949 GNU Lesser General Public License for more details. 6950 6951 You should have received a copy of the GNU Lesser General Public License 6952 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6953 */ 6954 /** 6955 * @file namereg.js 6956 * @author Marek Kotewicz <marek@ethdev.com> 6957 * @date 2015 6958 */ 6959 6960 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6961 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6962 6963 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6964 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6965 6966 module.exports = { 6967 global: { 6968 abi: globalRegistrarAbi, 6969 address: globalNameregAddress 6970 }, 6971 icap: { 6972 abi: icapRegistrarAbi, 6973 address: icapNameregAddress 6974 } 6975 }; 6976 6977 6978 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 6979 /* 6980 This file is part of web3.js. 6981 6982 web3.js is free software: you can redistribute it and/or modify 6983 it under the terms of the GNU Lesser General Public License as published by 6984 the Free Software Foundation, either version 3 of the License, or 6985 (at your option) any later version. 6986 6987 web3.js is distributed in the hope that it will be useful, 6988 but WITHOUT ANY WARRANTY; without even the implied warranty of 6989 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6990 GNU Lesser General Public License for more details. 6991 6992 You should have received a copy of the GNU Lesser General Public License 6993 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6994 */ 6995 /** 6996 * @file property.js 6997 * @author Fabian Vogelsteller <fabian@frozeman.de> 6998 * @author Marek Kotewicz <marek@ethdev.com> 6999 * @date 2015 7000 */ 7001 7002 var utils = require('../utils/utils'); 7003 7004 var Property = function (options) { 7005 this.name = options.name; 7006 this.getter = options.getter; 7007 this.setter = options.setter; 7008 this.outputFormatter = options.outputFormatter; 7009 this.inputFormatter = options.inputFormatter; 7010 this.requestManager = null; 7011 }; 7012 7013 Property.prototype.setRequestManager = function (rm) { 7014 this.requestManager = rm; 7015 }; 7016 7017 /** 7018 * Should be called to format input args of method 7019 * 7020 * @method formatInput 7021 * @param {Array} 7022 * @return {Array} 7023 */ 7024 Property.prototype.formatInput = function (arg) { 7025 return this.inputFormatter ? this.inputFormatter(arg) : arg; 7026 }; 7027 7028 /** 7029 * Should be called to format output(result) of method 7030 * 7031 * @method formatOutput 7032 * @param {Object} 7033 * @return {Object} 7034 */ 7035 Property.prototype.formatOutput = function (result) { 7036 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 7037 }; 7038 7039 /** 7040 * Should be used to extract callback from array of arguments. Modifies input param 7041 * 7042 * @method extractCallback 7043 * @param {Array} arguments 7044 * @return {Function|Null} callback, if exists 7045 */ 7046 Property.prototype.extractCallback = function (args) { 7047 if (utils.isFunction(args[args.length - 1])) { 7048 return args.pop(); // modify the args array! 7049 } 7050 }; 7051 7052 7053 /** 7054 * Should attach function to method 7055 * 7056 * @method attachToObject 7057 * @param {Object} 7058 * @param {Function} 7059 */ 7060 Property.prototype.attachToObject = function (obj) { 7061 var proto = { 7062 get: this.buildGet(), 7063 enumerable: true 7064 }; 7065 7066 var names = this.name.split('.'); 7067 var name = names[0]; 7068 if (names.length > 1) { 7069 obj[names[0]] = obj[names[0]] || {}; 7070 obj = obj[names[0]]; 7071 name = names[1]; 7072 } 7073 7074 Object.defineProperty(obj, name, proto); 7075 obj[asyncGetterName(name)] = this.buildAsyncGet(); 7076 }; 7077 7078 var asyncGetterName = function (name) { 7079 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 7080 }; 7081 7082 Property.prototype.buildGet = function () { 7083 var property = this; 7084 return function get() { 7085 return property.formatOutput(property.requestManager.send({ 7086 method: property.getter 7087 })); 7088 }; 7089 }; 7090 7091 Property.prototype.buildAsyncGet = function () { 7092 var property = this; 7093 var get = function (callback) { 7094 property.requestManager.sendAsync({ 7095 method: property.getter 7096 }, function (err, result) { 7097 callback(err, property.formatOutput(result)); 7098 }); 7099 }; 7100 get.request = this.request.bind(this); 7101 return get; 7102 }; 7103 7104 /** 7105 * Should be called to create pure JSONRPC request which can be used in batch request 7106 * 7107 * @method request 7108 * @param {...} params 7109 * @return {Object} jsonrpc request 7110 */ 7111 Property.prototype.request = function () { 7112 var payload = { 7113 method: this.getter, 7114 params: [], 7115 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 7116 }; 7117 payload.format = this.formatOutput.bind(this); 7118 return payload; 7119 }; 7120 7121 module.exports = Property; 7122 7123 7124 },{"../utils/utils":20}],46:[function(require,module,exports){ 7125 /* 7126 This file is part of web3.js. 7127 7128 web3.js is free software: you can redistribute it and/or modify 7129 it under the terms of the GNU Lesser General Public License as published by 7130 the Free Software Foundation, either version 3 of the License, or 7131 (at your option) any later version. 7132 7133 web3.js is distributed in the hope that it will be useful, 7134 but WITHOUT ANY WARRANTY; without even the implied warranty of 7135 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7136 GNU Lesser General Public License for more details. 7137 7138 You should have received a copy of the GNU Lesser General Public License 7139 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7140 */ 7141 /** 7142 * @file requestmanager.js 7143 * @author Jeffrey Wilcke <jeff@ethdev.com> 7144 * @author Marek Kotewicz <marek@ethdev.com> 7145 * @author Marian Oancea <marian@ethdev.com> 7146 * @author Fabian Vogelsteller <fabian@ethdev.com> 7147 * @author Gav Wood <g@ethdev.com> 7148 * @date 2014 7149 */ 7150 7151 var Jsonrpc = require('./jsonrpc'); 7152 var utils = require('../utils/utils'); 7153 var c = require('../utils/config'); 7154 var errors = require('./errors'); 7155 7156 /** 7157 * It's responsible for passing messages to providers 7158 * It's also responsible for polling the ethereum node for incoming messages 7159 * Default poll timeout is 1 second 7160 * Singleton 7161 */ 7162 var RequestManager = function (provider) { 7163 this.provider = provider; 7164 this.polls = {}; 7165 this.timeout = null; 7166 }; 7167 7168 /** 7169 * Should be used to synchronously send request 7170 * 7171 * @method send 7172 * @param {Object} data 7173 * @return {Object} 7174 */ 7175 RequestManager.prototype.send = function (data) { 7176 if (!this.provider) { 7177 console.error(errors.InvalidProvider()); 7178 return null; 7179 } 7180 7181 var payload = Jsonrpc.toPayload(data.method, data.params); 7182 var result = this.provider.send(payload); 7183 7184 if (!Jsonrpc.isValidResponse(result)) { 7185 throw errors.InvalidResponse(result); 7186 } 7187 7188 return result.result; 7189 }; 7190 7191 /** 7192 * Should be used to asynchronously send request 7193 * 7194 * @method sendAsync 7195 * @param {Object} data 7196 * @param {Function} callback 7197 */ 7198 RequestManager.prototype.sendAsync = function (data, callback) { 7199 if (!this.provider) { 7200 return callback(errors.InvalidProvider()); 7201 } 7202 7203 var payload = Jsonrpc.toPayload(data.method, data.params); 7204 this.provider.sendAsync(payload, function (err, result) { 7205 if (err) { 7206 return callback(err); 7207 } 7208 7209 if (!Jsonrpc.isValidResponse(result)) { 7210 return callback(errors.InvalidResponse(result)); 7211 } 7212 7213 callback(null, result.result); 7214 }); 7215 }; 7216 7217 /** 7218 * Should be called to asynchronously send batch request 7219 * 7220 * @method sendBatch 7221 * @param {Array} batch data 7222 * @param {Function} callback 7223 */ 7224 RequestManager.prototype.sendBatch = function (data, callback) { 7225 if (!this.provider) { 7226 return callback(errors.InvalidProvider()); 7227 } 7228 7229 var payload = Jsonrpc.toBatchPayload(data); 7230 7231 this.provider.sendAsync(payload, function (err, results) { 7232 if (err) { 7233 return callback(err); 7234 } 7235 7236 if (!utils.isArray(results)) { 7237 return callback(errors.InvalidResponse(results)); 7238 } 7239 7240 callback(err, results); 7241 }); 7242 }; 7243 7244 /** 7245 * Should be used to set provider of request manager 7246 * 7247 * @method setProvider 7248 * @param {Object} 7249 */ 7250 RequestManager.prototype.setProvider = function (p) { 7251 this.provider = p; 7252 }; 7253 7254 /** 7255 * Should be used to start polling 7256 * 7257 * @method startPolling 7258 * @param {Object} data 7259 * @param {Number} pollId 7260 * @param {Function} callback 7261 * @param {Function} uninstall 7262 * 7263 * @todo cleanup number of params 7264 */ 7265 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 7266 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 7267 7268 7269 // start polling 7270 if (!this.timeout) { 7271 this.poll(); 7272 } 7273 }; 7274 7275 /** 7276 * Should be used to stop polling for filter with given id 7277 * 7278 * @method stopPolling 7279 * @param {Number} pollId 7280 */ 7281 RequestManager.prototype.stopPolling = function (pollId) { 7282 delete this.polls[pollId]; 7283 7284 // stop polling 7285 if(Object.keys(this.polls).length === 0 && this.timeout) { 7286 clearTimeout(this.timeout); 7287 this.timeout = null; 7288 } 7289 }; 7290 7291 /** 7292 * Should be called to reset the polling mechanism of the request manager 7293 * 7294 * @method reset 7295 */ 7296 RequestManager.prototype.reset = function (keepIsSyncing) { 7297 /*jshint maxcomplexity:5 */ 7298 7299 for (var key in this.polls) { 7300 // remove all polls, except sync polls, 7301 // they need to be removed manually by calling syncing.stopWatching() 7302 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 7303 this.polls[key].uninstall(); 7304 delete this.polls[key]; 7305 } 7306 } 7307 7308 // stop polling 7309 if(Object.keys(this.polls).length === 0 && this.timeout) { 7310 clearTimeout(this.timeout); 7311 this.timeout = null; 7312 } 7313 }; 7314 7315 /** 7316 * Should be called to poll for changes on filter with given id 7317 * 7318 * @method poll 7319 */ 7320 RequestManager.prototype.poll = function () { 7321 /*jshint maxcomplexity: 6 */ 7322 this.timeout = setTimeout(this.poll.bind(this), c.U2U_POLLING_TIMEOUT); 7323 7324 if (Object.keys(this.polls).length === 0) { 7325 return; 7326 } 7327 7328 if (!this.provider) { 7329 console.error(errors.InvalidProvider()); 7330 return; 7331 } 7332 7333 var pollsData = []; 7334 var pollsIds = []; 7335 for (var key in this.polls) { 7336 pollsData.push(this.polls[key].data); 7337 pollsIds.push(key); 7338 } 7339 7340 if (pollsData.length === 0) { 7341 return; 7342 } 7343 7344 var payload = Jsonrpc.toBatchPayload(pollsData); 7345 7346 // map the request id to they poll id 7347 var pollsIdMap = {}; 7348 payload.forEach(function(load, index){ 7349 pollsIdMap[load.id] = pollsIds[index]; 7350 }); 7351 7352 7353 var self = this; 7354 this.provider.sendAsync(payload, function (error, results) { 7355 7356 7357 // TODO: console log? 7358 if (error) { 7359 return; 7360 } 7361 7362 if (!utils.isArray(results)) { 7363 throw errors.InvalidResponse(results); 7364 } 7365 results.map(function (result) { 7366 var id = pollsIdMap[result.id]; 7367 7368 // make sure the filter is still installed after arrival of the request 7369 if (self.polls[id]) { 7370 result.callback = self.polls[id].callback; 7371 return result; 7372 } else 7373 return false; 7374 }).filter(function (result) { 7375 return !!result; 7376 }).filter(function (result) { 7377 var valid = Jsonrpc.isValidResponse(result); 7378 if (!valid) { 7379 result.callback(errors.InvalidResponse(result)); 7380 } 7381 return valid; 7382 }).forEach(function (result) { 7383 result.callback(null, result.result); 7384 }); 7385 }); 7386 }; 7387 7388 module.exports = RequestManager; 7389 7390 7391 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 7392 7393 7394 var Settings = function () { 7395 this.defaultBlock = 'latest'; 7396 this.defaultAccount = undefined; 7397 }; 7398 7399 module.exports = Settings; 7400 7401 7402 },{}],48:[function(require,module,exports){ 7403 /* 7404 This file is part of web3.js. 7405 7406 web3.js is free software: you can redistribute it and/or modify 7407 it under the terms of the GNU Lesser General Public License as published by 7408 the Free Software Foundation, either version 3 of the License, or 7409 (at your option) any later version. 7410 7411 web3.js is distributed in the hope that it will be useful, 7412 but WITHOUT ANY WARRANTY; without even the implied warranty of 7413 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7414 GNU Lesser General Public License for more details. 7415 7416 You should have received a copy of the GNU Lesser General Public License 7417 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7418 */ 7419 /** @file syncing.js 7420 * @authors: 7421 * Fabian Vogelsteller <fabian@ethdev.com> 7422 * @date 2015 7423 */ 7424 7425 var formatters = require('./formatters'); 7426 var utils = require('../utils/utils'); 7427 7428 var count = 1; 7429 7430 /** 7431 Adds the callback and sets up the methods, to iterate over the results. 7432 7433 @method pollSyncing 7434 @param {Object} self 7435 */ 7436 var pollSyncing = function(self) { 7437 7438 var onMessage = function (error, sync) { 7439 if (error) { 7440 return self.callbacks.forEach(function (callback) { 7441 callback(error); 7442 }); 7443 } 7444 7445 if(utils.isObject(sync) && sync.startingBlock) 7446 sync = formatters.outputSyncingFormatter(sync); 7447 7448 self.callbacks.forEach(function (callback) { 7449 if (self.lastSyncState !== sync) { 7450 7451 // call the callback with true first so the app can stop anything, before receiving the sync data 7452 if(!self.lastSyncState && utils.isObject(sync)) 7453 callback(null, true); 7454 7455 // call on the next CPU cycle, so the actions of the sync stop can be processes first 7456 setTimeout(function() { 7457 callback(null, sync); 7458 }, 0); 7459 7460 self.lastSyncState = sync; 7461 } 7462 }); 7463 }; 7464 7465 self.requestManager.startPolling({ 7466 method: 'eth_syncing', 7467 params: [], 7468 }, self.pollId, onMessage, self.stopWatching.bind(self)); 7469 7470 }; 7471 7472 var IsSyncing = function (requestManager, callback) { 7473 this.requestManager = requestManager; 7474 this.pollId = 'syncPoll_'+ count++; 7475 this.callbacks = []; 7476 this.addCallback(callback); 7477 this.lastSyncState = false; 7478 pollSyncing(this); 7479 7480 return this; 7481 }; 7482 7483 IsSyncing.prototype.addCallback = function (callback) { 7484 if(callback) 7485 this.callbacks.push(callback); 7486 return this; 7487 }; 7488 7489 IsSyncing.prototype.stopWatching = function () { 7490 this.requestManager.stopPolling(this.pollId); 7491 this.callbacks = []; 7492 }; 7493 7494 module.exports = IsSyncing; 7495 7496 7497 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 7498 /* 7499 This file is part of web3.js. 7500 7501 web3.js is free software: you can redistribute it and/or modify 7502 it under the terms of the GNU Lesser General Public License as published by 7503 the Free Software Foundation, either version 3 of the License, or 7504 (at your option) any later version. 7505 7506 web3.js is distributed in the hope that it will be useful, 7507 but WITHOUT ANY WARRANTY; without even the implied warranty of 7508 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7509 GNU Lesser General Public License for more details. 7510 7511 You should have received a copy of the GNU Lesser General Public License 7512 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7513 */ 7514 /** 7515 * @file transfer.js 7516 * @author Marek Kotewicz <marek@ethdev.com> 7517 * @date 2015 7518 */ 7519 7520 var Iban = require('./iban'); 7521 var exchangeAbi = require('../contracts/SmartExchange.json'); 7522 7523 /** 7524 * Should be used to make Iban transfer 7525 * 7526 * @method transfer 7527 * @param {String} from 7528 * @param {String} to iban 7529 * @param {Value} value to be tranfered 7530 * @param {Function} callback, callback 7531 */ 7532 var transfer = function (u2u, from, to, value, callback) { 7533 var iban = new Iban(to); 7534 if (!iban.isValid()) { 7535 throw new Error('invalid iban address'); 7536 } 7537 7538 if (iban.isDirect()) { 7539 return transferToAddress(u2u, from, iban.address(), value, callback); 7540 } 7541 7542 if (!callback) { 7543 var address = u2u.icapNamereg().addr(iban.institution()); 7544 return deposit(u2u, from, address, value, iban.client()); 7545 } 7546 7547 u2u.icapNamereg().addr(iban.institution(), function (err, address) { 7548 return deposit(u2u, from, address, value, iban.client(), callback); 7549 }); 7550 7551 }; 7552 7553 /** 7554 * Should be used to transfer funds to certain address 7555 * 7556 * @method transferToAddress 7557 * @param {String} from 7558 * @param {String} to 7559 * @param {Value} value to be tranfered 7560 * @param {Function} callback, callback 7561 */ 7562 var transferToAddress = function (u2u, from, to, value, callback) { 7563 return u2u.sendTransaction({ 7564 address: to, 7565 from: from, 7566 value: value 7567 }, callback); 7568 }; 7569 7570 /** 7571 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 7572 * 7573 * @method deposit 7574 * @param {String} from 7575 * @param {String} to 7576 * @param {Value} value to be transferred 7577 * @param {String} client unique identifier 7578 * @param {Function} callback, callback 7579 */ 7580 var deposit = function (u2u, from, to, value, client, callback) { 7581 var abi = exchangeAbi; 7582 return u2u.contract(abi).at(to).deposit(client, { 7583 from: from, 7584 value: value 7585 }, callback); 7586 }; 7587 7588 module.exports = transfer; 7589 7590 7591 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 7592 7593 },{}],51:[function(require,module,exports){ 7594 ;(function (root, factory, undef) { 7595 if (typeof exports === "object") { 7596 // CommonJS 7597 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 7598 } 7599 else if (typeof define === "function" && define.amd) { 7600 // AMD 7601 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 7602 } 7603 else { 7604 // Global (browser) 7605 factory(root.CryptoJS); 7606 } 7607 }(this, function (CryptoJS) { 7608 7609 (function () { 7610 // Shortcuts 7611 var C = CryptoJS; 7612 var C_lib = C.lib; 7613 var BlockCipher = C_lib.BlockCipher; 7614 var C_algo = C.algo; 7615 7616 // Lookup tables 7617 var SBOX = []; 7618 var INV_SBOX = []; 7619 var SUB_MIX_0 = []; 7620 var SUB_MIX_1 = []; 7621 var SUB_MIX_2 = []; 7622 var SUB_MIX_3 = []; 7623 var INV_SUB_MIX_0 = []; 7624 var INV_SUB_MIX_1 = []; 7625 var INV_SUB_MIX_2 = []; 7626 var INV_SUB_MIX_3 = []; 7627 7628 // Compute lookup tables 7629 (function () { 7630 // Compute double table 7631 var d = []; 7632 for (var i = 0; i < 256; i++) { 7633 if (i < 128) { 7634 d[i] = i << 1; 7635 } else { 7636 d[i] = (i << 1) ^ 0x11b; 7637 } 7638 } 7639 7640 // Walk GF(2^8) 7641 var x = 0; 7642 var xi = 0; 7643 for (var i = 0; i < 256; i++) { 7644 // Compute sbox 7645 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 7646 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 7647 SBOX[x] = sx; 7648 INV_SBOX[sx] = x; 7649 7650 // Compute multiplication 7651 var x2 = d[x]; 7652 var x4 = d[x2]; 7653 var x8 = d[x4]; 7654 7655 // Compute sub bytes, mix columns tables 7656 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 7657 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 7658 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 7659 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 7660 SUB_MIX_3[x] = t; 7661 7662 // Compute inv sub bytes, inv mix columns tables 7663 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 7664 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 7665 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 7666 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 7667 INV_SUB_MIX_3[sx] = t; 7668 7669 // Compute next counter 7670 if (!x) { 7671 x = xi = 1; 7672 } else { 7673 x = x2 ^ d[d[d[x8 ^ x2]]]; 7674 xi ^= d[d[xi]]; 7675 } 7676 } 7677 }()); 7678 7679 // Precomputed Rcon lookup 7680 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 7681 7682 /** 7683 * AES block cipher algorithm. 7684 */ 7685 var AES = C_algo.AES = BlockCipher.extend({ 7686 _doReset: function () { 7687 // Skip reset of nRounds has been set before and key did not change 7688 if (this._nRounds && this._keyPriorReset === this._key) { 7689 return; 7690 } 7691 7692 // Shortcuts 7693 var key = this._keyPriorReset = this._key; 7694 var keyWords = key.words; 7695 var keySize = key.sigBytes / 4; 7696 7697 // Compute number of rounds 7698 var nRounds = this._nRounds = keySize + 6; 7699 7700 // Compute number of key schedule rows 7701 var ksRows = (nRounds + 1) * 4; 7702 7703 // Compute key schedule 7704 var keySchedule = this._keySchedule = []; 7705 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 7706 if (ksRow < keySize) { 7707 keySchedule[ksRow] = keyWords[ksRow]; 7708 } else { 7709 var t = keySchedule[ksRow - 1]; 7710 7711 if (!(ksRow % keySize)) { 7712 // Rot word 7713 t = (t << 8) | (t >>> 24); 7714 7715 // Sub word 7716 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 7717 7718 // Mix Rcon 7719 t ^= RCON[(ksRow / keySize) | 0] << 24; 7720 } else if (keySize > 6 && ksRow % keySize == 4) { 7721 // Sub word 7722 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 7723 } 7724 7725 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 7726 } 7727 } 7728 7729 // Compute inv key schedule 7730 var invKeySchedule = this._invKeySchedule = []; 7731 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 7732 var ksRow = ksRows - invKsRow; 7733 7734 if (invKsRow % 4) { 7735 var t = keySchedule[ksRow]; 7736 } else { 7737 var t = keySchedule[ksRow - 4]; 7738 } 7739 7740 if (invKsRow < 4 || ksRow <= 4) { 7741 invKeySchedule[invKsRow] = t; 7742 } else { 7743 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 7744 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 7745 } 7746 } 7747 }, 7748 7749 encryptBlock: function (M, offset) { 7750 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 7751 }, 7752 7753 decryptBlock: function (M, offset) { 7754 // Swap 2nd and 4th rows 7755 var t = M[offset + 1]; 7756 M[offset + 1] = M[offset + 3]; 7757 M[offset + 3] = t; 7758 7759 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 7760 7761 // Inv swap 2nd and 4th rows 7762 var t = M[offset + 1]; 7763 M[offset + 1] = M[offset + 3]; 7764 M[offset + 3] = t; 7765 }, 7766 7767 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 7768 // Shortcut 7769 var nRounds = this._nRounds; 7770 7771 // Get input, add round key 7772 var s0 = M[offset] ^ keySchedule[0]; 7773 var s1 = M[offset + 1] ^ keySchedule[1]; 7774 var s2 = M[offset + 2] ^ keySchedule[2]; 7775 var s3 = M[offset + 3] ^ keySchedule[3]; 7776 7777 // Key schedule row counter 7778 var ksRow = 4; 7779 7780 // Rounds 7781 for (var round = 1; round < nRounds; round++) { 7782 // Shift rows, sub bytes, mix columns, add round key 7783 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++]; 7784 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++]; 7785 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++]; 7786 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++]; 7787 7788 // Update state 7789 s0 = t0; 7790 s1 = t1; 7791 s2 = t2; 7792 s3 = t3; 7793 } 7794 7795 // Shift rows, sub bytes, add round key 7796 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 7797 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 7798 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 7799 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 7800 7801 // Set output 7802 M[offset] = t0; 7803 M[offset + 1] = t1; 7804 M[offset + 2] = t2; 7805 M[offset + 3] = t3; 7806 }, 7807 7808 keySize: 256/32 7809 }); 7810 7811 /** 7812 * Shortcut functions to the cipher's object interface. 7813 * 7814 * @example 7815 * 7816 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7817 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7818 */ 7819 C.AES = BlockCipher._createHelper(AES); 7820 }()); 7821 7822 7823 return CryptoJS.AES; 7824 7825 })); 7826 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 7827 ;(function (root, factory) { 7828 if (typeof exports === "object") { 7829 // CommonJS 7830 module.exports = exports = factory(require("./core")); 7831 } 7832 else if (typeof define === "function" && define.amd) { 7833 // AMD 7834 define(["./core"], factory); 7835 } 7836 else { 7837 // Global (browser) 7838 factory(root.CryptoJS); 7839 } 7840 }(this, function (CryptoJS) { 7841 7842 /** 7843 * Cipher core components. 7844 */ 7845 CryptoJS.lib.Cipher || (function (undefined) { 7846 // Shortcuts 7847 var C = CryptoJS; 7848 var C_lib = C.lib; 7849 var Base = C_lib.Base; 7850 var WordArray = C_lib.WordArray; 7851 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7852 var C_enc = C.enc; 7853 var Utf8 = C_enc.Utf8; 7854 var Base64 = C_enc.Base64; 7855 var C_algo = C.algo; 7856 var EvpKDF = C_algo.EvpKDF; 7857 7858 /** 7859 * Abstract base cipher template. 7860 * 7861 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7862 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7863 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7864 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7865 */ 7866 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7867 /** 7868 * Configuration options. 7869 * 7870 * @property {WordArray} iv The IV to use for this operation. 7871 */ 7872 cfg: Base.extend(), 7873 7874 /** 7875 * Creates this cipher in encryption mode. 7876 * 7877 * @param {WordArray} key The key. 7878 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7879 * 7880 * @return {Cipher} A cipher instance. 7881 * 7882 * @static 7883 * 7884 * @example 7885 * 7886 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7887 */ 7888 createEncryptor: function (key, cfg) { 7889 return this.create(this._ENC_XFORM_MODE, key, cfg); 7890 }, 7891 7892 /** 7893 * Creates this cipher in decryption mode. 7894 * 7895 * @param {WordArray} key The key. 7896 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7897 * 7898 * @return {Cipher} A cipher instance. 7899 * 7900 * @static 7901 * 7902 * @example 7903 * 7904 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7905 */ 7906 createDecryptor: function (key, cfg) { 7907 return this.create(this._DEC_XFORM_MODE, key, cfg); 7908 }, 7909 7910 /** 7911 * Initializes a newly created cipher. 7912 * 7913 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7914 * @param {WordArray} key The key. 7915 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7916 * 7917 * @example 7918 * 7919 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7920 */ 7921 init: function (xformMode, key, cfg) { 7922 // Apply config defaults 7923 this.cfg = this.cfg.extend(cfg); 7924 7925 // Store transform mode and key 7926 this._xformMode = xformMode; 7927 this._key = key; 7928 7929 // Set initial values 7930 this.reset(); 7931 }, 7932 7933 /** 7934 * Resets this cipher to its initial state. 7935 * 7936 * @example 7937 * 7938 * cipher.reset(); 7939 */ 7940 reset: function () { 7941 // Reset data buffer 7942 BufferedBlockAlgorithm.reset.call(this); 7943 7944 // Perform concrete-cipher logic 7945 this._doReset(); 7946 }, 7947 7948 /** 7949 * Adds data to be encrypted or decrypted. 7950 * 7951 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7952 * 7953 * @return {WordArray} The data after processing. 7954 * 7955 * @example 7956 * 7957 * var encrypted = cipher.process('data'); 7958 * var encrypted = cipher.process(wordArray); 7959 */ 7960 process: function (dataUpdate) { 7961 // Append 7962 this._append(dataUpdate); 7963 7964 // Process available blocks 7965 return this._process(); 7966 }, 7967 7968 /** 7969 * Finalizes the encryption or decryption process. 7970 * Note that the finalize operation is effectively a destructive, read-once operation. 7971 * 7972 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7973 * 7974 * @return {WordArray} The data after final processing. 7975 * 7976 * @example 7977 * 7978 * var encrypted = cipher.finalize(); 7979 * var encrypted = cipher.finalize('data'); 7980 * var encrypted = cipher.finalize(wordArray); 7981 */ 7982 finalize: function (dataUpdate) { 7983 // Final data update 7984 if (dataUpdate) { 7985 this._append(dataUpdate); 7986 } 7987 7988 // Perform concrete-cipher logic 7989 var finalProcessedData = this._doFinalize(); 7990 7991 return finalProcessedData; 7992 }, 7993 7994 keySize: 128/32, 7995 7996 ivSize: 128/32, 7997 7998 _ENC_XFORM_MODE: 1, 7999 8000 _DEC_XFORM_MODE: 2, 8001 8002 /** 8003 * Creates shortcut functions to a cipher's object interface. 8004 * 8005 * @param {Cipher} cipher The cipher to create a helper for. 8006 * 8007 * @return {Object} An object with encrypt and decrypt shortcut functions. 8008 * 8009 * @static 8010 * 8011 * @example 8012 * 8013 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 8014 */ 8015 _createHelper: (function () { 8016 function selectCipherStrategy(key) { 8017 if (typeof key == 'string') { 8018 return PasswordBasedCipher; 8019 } else { 8020 return SerializableCipher; 8021 } 8022 } 8023 8024 return function (cipher) { 8025 return { 8026 encrypt: function (message, key, cfg) { 8027 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 8028 }, 8029 8030 decrypt: function (ciphertext, key, cfg) { 8031 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 8032 } 8033 }; 8034 }; 8035 }()) 8036 }); 8037 8038 /** 8039 * Abstract base stream cipher template. 8040 * 8041 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 8042 */ 8043 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 8044 _doFinalize: function () { 8045 // Process partial blocks 8046 var finalProcessedBlocks = this._process(!!'flush'); 8047 8048 return finalProcessedBlocks; 8049 }, 8050 8051 blockSize: 1 8052 }); 8053 8054 /** 8055 * Mode namespace. 8056 */ 8057 var C_mode = C.mode = {}; 8058 8059 /** 8060 * Abstract base block cipher mode template. 8061 */ 8062 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 8063 /** 8064 * Creates this mode for encryption. 8065 * 8066 * @param {Cipher} cipher A block cipher instance. 8067 * @param {Array} iv The IV words. 8068 * 8069 * @static 8070 * 8071 * @example 8072 * 8073 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 8074 */ 8075 createEncryptor: function (cipher, iv) { 8076 return this.Encryptor.create(cipher, iv); 8077 }, 8078 8079 /** 8080 * Creates this mode for decryption. 8081 * 8082 * @param {Cipher} cipher A block cipher instance. 8083 * @param {Array} iv The IV words. 8084 * 8085 * @static 8086 * 8087 * @example 8088 * 8089 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 8090 */ 8091 createDecryptor: function (cipher, iv) { 8092 return this.Decryptor.create(cipher, iv); 8093 }, 8094 8095 /** 8096 * Initializes a newly created mode. 8097 * 8098 * @param {Cipher} cipher A block cipher instance. 8099 * @param {Array} iv The IV words. 8100 * 8101 * @example 8102 * 8103 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 8104 */ 8105 init: function (cipher, iv) { 8106 this._cipher = cipher; 8107 this._iv = iv; 8108 } 8109 }); 8110 8111 /** 8112 * Cipher Block Chaining mode. 8113 */ 8114 var CBC = C_mode.CBC = (function () { 8115 /** 8116 * Abstract base CBC mode. 8117 */ 8118 var CBC = BlockCipherMode.extend(); 8119 8120 /** 8121 * CBC encryptor. 8122 */ 8123 CBC.Encryptor = CBC.extend({ 8124 /** 8125 * Processes the data block at offset. 8126 * 8127 * @param {Array} words The data words to operate on. 8128 * @param {number} offset The offset where the block starts. 8129 * 8130 * @example 8131 * 8132 * mode.processBlock(data.words, offset); 8133 */ 8134 processBlock: function (words, offset) { 8135 // Shortcuts 8136 var cipher = this._cipher; 8137 var blockSize = cipher.blockSize; 8138 8139 // XOR and encrypt 8140 xorBlock.call(this, words, offset, blockSize); 8141 cipher.encryptBlock(words, offset); 8142 8143 // Remember this block to use with next block 8144 this._prevBlock = words.slice(offset, offset + blockSize); 8145 } 8146 }); 8147 8148 /** 8149 * CBC decryptor. 8150 */ 8151 CBC.Decryptor = CBC.extend({ 8152 /** 8153 * Processes the data block at offset. 8154 * 8155 * @param {Array} words The data words to operate on. 8156 * @param {number} offset The offset where the block starts. 8157 * 8158 * @example 8159 * 8160 * mode.processBlock(data.words, offset); 8161 */ 8162 processBlock: function (words, offset) { 8163 // Shortcuts 8164 var cipher = this._cipher; 8165 var blockSize = cipher.blockSize; 8166 8167 // Remember this block to use with next block 8168 var thisBlock = words.slice(offset, offset + blockSize); 8169 8170 // Decrypt and XOR 8171 cipher.decryptBlock(words, offset); 8172 xorBlock.call(this, words, offset, blockSize); 8173 8174 // This block becomes the previous block 8175 this._prevBlock = thisBlock; 8176 } 8177 }); 8178 8179 function xorBlock(words, offset, blockSize) { 8180 // Shortcut 8181 var iv = this._iv; 8182 8183 // Choose mixing block 8184 if (iv) { 8185 var block = iv; 8186 8187 // Remove IV for subsequent blocks 8188 this._iv = undefined; 8189 } else { 8190 var block = this._prevBlock; 8191 } 8192 8193 // XOR blocks 8194 for (var i = 0; i < blockSize; i++) { 8195 words[offset + i] ^= block[i]; 8196 } 8197 } 8198 8199 return CBC; 8200 }()); 8201 8202 /** 8203 * Padding namespace. 8204 */ 8205 var C_pad = C.pad = {}; 8206 8207 /** 8208 * PKCS #5/7 padding strategy. 8209 */ 8210 var Pkcs7 = C_pad.Pkcs7 = { 8211 /** 8212 * Pads data using the algorithm defined in PKCS #5/7. 8213 * 8214 * @param {WordArray} data The data to pad. 8215 * @param {number} blockSize The multiple that the data should be padded to. 8216 * 8217 * @static 8218 * 8219 * @example 8220 * 8221 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 8222 */ 8223 pad: function (data, blockSize) { 8224 // Shortcut 8225 var blockSizeBytes = blockSize * 4; 8226 8227 // Count padding bytes 8228 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 8229 8230 // Create padding word 8231 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 8232 8233 // Create padding 8234 var paddingWords = []; 8235 for (var i = 0; i < nPaddingBytes; i += 4) { 8236 paddingWords.push(paddingWord); 8237 } 8238 var padding = WordArray.create(paddingWords, nPaddingBytes); 8239 8240 // Add padding 8241 data.concat(padding); 8242 }, 8243 8244 /** 8245 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 8246 * 8247 * @param {WordArray} data The data to unpad. 8248 * 8249 * @static 8250 * 8251 * @example 8252 * 8253 * CryptoJS.pad.Pkcs7.unpad(wordArray); 8254 */ 8255 unpad: function (data) { 8256 // Get number of padding bytes from last byte 8257 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 8258 8259 // Remove padding 8260 data.sigBytes -= nPaddingBytes; 8261 } 8262 }; 8263 8264 /** 8265 * Abstract base block cipher template. 8266 * 8267 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 8268 */ 8269 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 8270 /** 8271 * Configuration options. 8272 * 8273 * @property {Mode} mode The block mode to use. Default: CBC 8274 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 8275 */ 8276 cfg: Cipher.cfg.extend({ 8277 mode: CBC, 8278 padding: Pkcs7 8279 }), 8280 8281 reset: function () { 8282 // Reset cipher 8283 Cipher.reset.call(this); 8284 8285 // Shortcuts 8286 var cfg = this.cfg; 8287 var iv = cfg.iv; 8288 var mode = cfg.mode; 8289 8290 // Reset block mode 8291 if (this._xformMode == this._ENC_XFORM_MODE) { 8292 var modeCreator = mode.createEncryptor; 8293 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 8294 var modeCreator = mode.createDecryptor; 8295 8296 // Keep at least one block in the buffer for unpadding 8297 this._minBufferSize = 1; 8298 } 8299 this._mode = modeCreator.call(mode, this, iv && iv.words); 8300 }, 8301 8302 _doProcessBlock: function (words, offset) { 8303 this._mode.processBlock(words, offset); 8304 }, 8305 8306 _doFinalize: function () { 8307 // Shortcut 8308 var padding = this.cfg.padding; 8309 8310 // Finalize 8311 if (this._xformMode == this._ENC_XFORM_MODE) { 8312 // Pad data 8313 padding.pad(this._data, this.blockSize); 8314 8315 // Process final blocks 8316 var finalProcessedBlocks = this._process(!!'flush'); 8317 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 8318 // Process final blocks 8319 var finalProcessedBlocks = this._process(!!'flush'); 8320 8321 // Unpad data 8322 padding.unpad(finalProcessedBlocks); 8323 } 8324 8325 return finalProcessedBlocks; 8326 }, 8327 8328 blockSize: 128/32 8329 }); 8330 8331 /** 8332 * A collection of cipher parameters. 8333 * 8334 * @property {WordArray} ciphertext The raw ciphertext. 8335 * @property {WordArray} key The key to this ciphertext. 8336 * @property {WordArray} iv The IV used in the ciphering operation. 8337 * @property {WordArray} salt The salt used with a key derivation function. 8338 * @property {Cipher} algorithm The cipher algorithm. 8339 * @property {Mode} mode The block mode used in the ciphering operation. 8340 * @property {Padding} padding The padding scheme used in the ciphering operation. 8341 * @property {number} blockSize The block size of the cipher. 8342 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 8343 */ 8344 var CipherParams = C_lib.CipherParams = Base.extend({ 8345 /** 8346 * Initializes a newly created cipher params object. 8347 * 8348 * @param {Object} cipherParams An object with any of the possible cipher parameters. 8349 * 8350 * @example 8351 * 8352 * var cipherParams = CryptoJS.lib.CipherParams.create({ 8353 * ciphertext: ciphertextWordArray, 8354 * key: keyWordArray, 8355 * iv: ivWordArray, 8356 * salt: saltWordArray, 8357 * algorithm: CryptoJS.algo.AES, 8358 * mode: CryptoJS.mode.CBC, 8359 * padding: CryptoJS.pad.PKCS7, 8360 * blockSize: 4, 8361 * formatter: CryptoJS.format.OpenSSL 8362 * }); 8363 */ 8364 init: function (cipherParams) { 8365 this.mixIn(cipherParams); 8366 }, 8367 8368 /** 8369 * Converts this cipher params object to a string. 8370 * 8371 * @param {Format} formatter (Optional) The formatting strategy to use. 8372 * 8373 * @return {string} The stringified cipher params. 8374 * 8375 * @throws Error If neither the formatter nor the default formatter is set. 8376 * 8377 * @example 8378 * 8379 * var string = cipherParams + ''; 8380 * var string = cipherParams.toString(); 8381 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 8382 */ 8383 toString: function (formatter) { 8384 return (formatter || this.formatter).stringify(this); 8385 } 8386 }); 8387 8388 /** 8389 * Format namespace. 8390 */ 8391 var C_format = C.format = {}; 8392 8393 /** 8394 * OpenSSL formatting strategy. 8395 */ 8396 var OpenSSLFormatter = C_format.OpenSSL = { 8397 /** 8398 * Converts a cipher params object to an OpenSSL-compatible string. 8399 * 8400 * @param {CipherParams} cipherParams The cipher params object. 8401 * 8402 * @return {string} The OpenSSL-compatible string. 8403 * 8404 * @static 8405 * 8406 * @example 8407 * 8408 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 8409 */ 8410 stringify: function (cipherParams) { 8411 // Shortcuts 8412 var ciphertext = cipherParams.ciphertext; 8413 var salt = cipherParams.salt; 8414 8415 // Format 8416 if (salt) { 8417 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 8418 } else { 8419 var wordArray = ciphertext; 8420 } 8421 8422 return wordArray.toString(Base64); 8423 }, 8424 8425 /** 8426 * Converts an OpenSSL-compatible string to a cipher params object. 8427 * 8428 * @param {string} openSSLStr The OpenSSL-compatible string. 8429 * 8430 * @return {CipherParams} The cipher params object. 8431 * 8432 * @static 8433 * 8434 * @example 8435 * 8436 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 8437 */ 8438 parse: function (openSSLStr) { 8439 // Parse base64 8440 var ciphertext = Base64.parse(openSSLStr); 8441 8442 // Shortcut 8443 var ciphertextWords = ciphertext.words; 8444 8445 // Test for salt 8446 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 8447 // Extract salt 8448 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 8449 8450 // Remove salt from ciphertext 8451 ciphertextWords.splice(0, 4); 8452 ciphertext.sigBytes -= 16; 8453 } 8454 8455 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 8456 } 8457 }; 8458 8459 /** 8460 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 8461 */ 8462 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 8463 /** 8464 * Configuration options. 8465 * 8466 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 8467 */ 8468 cfg: Base.extend({ 8469 format: OpenSSLFormatter 8470 }), 8471 8472 /** 8473 * Encrypts a message. 8474 * 8475 * @param {Cipher} cipher The cipher algorithm to use. 8476 * @param {WordArray|string} message The message to encrypt. 8477 * @param {WordArray} key The key. 8478 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8479 * 8480 * @return {CipherParams} A cipher params object. 8481 * 8482 * @static 8483 * 8484 * @example 8485 * 8486 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 8487 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 8488 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8489 */ 8490 encrypt: function (cipher, message, key, cfg) { 8491 // Apply config defaults 8492 cfg = this.cfg.extend(cfg); 8493 8494 // Encrypt 8495 var encryptor = cipher.createEncryptor(key, cfg); 8496 var ciphertext = encryptor.finalize(message); 8497 8498 // Shortcut 8499 var cipherCfg = encryptor.cfg; 8500 8501 // Create and return serializable cipher params 8502 return CipherParams.create({ 8503 ciphertext: ciphertext, 8504 key: key, 8505 iv: cipherCfg.iv, 8506 algorithm: cipher, 8507 mode: cipherCfg.mode, 8508 padding: cipherCfg.padding, 8509 blockSize: cipher.blockSize, 8510 formatter: cfg.format 8511 }); 8512 }, 8513 8514 /** 8515 * Decrypts serialized ciphertext. 8516 * 8517 * @param {Cipher} cipher The cipher algorithm to use. 8518 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8519 * @param {WordArray} key The key. 8520 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8521 * 8522 * @return {WordArray} The plaintext. 8523 * 8524 * @static 8525 * 8526 * @example 8527 * 8528 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8529 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8530 */ 8531 decrypt: function (cipher, ciphertext, key, cfg) { 8532 // Apply config defaults 8533 cfg = this.cfg.extend(cfg); 8534 8535 // Convert string to CipherParams 8536 ciphertext = this._parse(ciphertext, cfg.format); 8537 8538 // Decrypt 8539 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 8540 8541 return plaintext; 8542 }, 8543 8544 /** 8545 * Converts serialized ciphertext to CipherParams, 8546 * else assumed CipherParams already and returns ciphertext unchanged. 8547 * 8548 * @param {CipherParams|string} ciphertext The ciphertext. 8549 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 8550 * 8551 * @return {CipherParams} The unserialized ciphertext. 8552 * 8553 * @static 8554 * 8555 * @example 8556 * 8557 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 8558 */ 8559 _parse: function (ciphertext, format) { 8560 if (typeof ciphertext == 'string') { 8561 return format.parse(ciphertext, this); 8562 } else { 8563 return ciphertext; 8564 } 8565 } 8566 }); 8567 8568 /** 8569 * Key derivation function namespace. 8570 */ 8571 var C_kdf = C.kdf = {}; 8572 8573 /** 8574 * OpenSSL key derivation function. 8575 */ 8576 var OpenSSLKdf = C_kdf.OpenSSL = { 8577 /** 8578 * Derives a key and IV from a password. 8579 * 8580 * @param {string} password The password to derive from. 8581 * @param {number} keySize The size in words of the key to generate. 8582 * @param {number} ivSize The size in words of the IV to generate. 8583 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 8584 * 8585 * @return {CipherParams} A cipher params object with the key, IV, and salt. 8586 * 8587 * @static 8588 * 8589 * @example 8590 * 8591 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 8592 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 8593 */ 8594 execute: function (password, keySize, ivSize, salt) { 8595 // Generate random salt 8596 if (!salt) { 8597 salt = WordArray.random(64/8); 8598 } 8599 8600 // Derive key and IV 8601 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 8602 8603 // Separate key and IV 8604 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 8605 key.sigBytes = keySize * 4; 8606 8607 // Return params 8608 return CipherParams.create({ key: key, iv: iv, salt: salt }); 8609 } 8610 }; 8611 8612 /** 8613 * A serializable cipher wrapper that derives the key from a password, 8614 * and returns ciphertext as a serializable cipher params object. 8615 */ 8616 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 8617 /** 8618 * Configuration options. 8619 * 8620 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 8621 */ 8622 cfg: SerializableCipher.cfg.extend({ 8623 kdf: OpenSSLKdf 8624 }), 8625 8626 /** 8627 * Encrypts a message using a password. 8628 * 8629 * @param {Cipher} cipher The cipher algorithm to use. 8630 * @param {WordArray|string} message The message to encrypt. 8631 * @param {string} password The password. 8632 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8633 * 8634 * @return {CipherParams} A cipher params object. 8635 * 8636 * @static 8637 * 8638 * @example 8639 * 8640 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 8641 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 8642 */ 8643 encrypt: function (cipher, message, password, cfg) { 8644 // Apply config defaults 8645 cfg = this.cfg.extend(cfg); 8646 8647 // Derive key and other params 8648 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 8649 8650 // Add IV to config 8651 cfg.iv = derivedParams.iv; 8652 8653 // Encrypt 8654 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 8655 8656 // Mix in derived params 8657 ciphertext.mixIn(derivedParams); 8658 8659 return ciphertext; 8660 }, 8661 8662 /** 8663 * Decrypts serialized ciphertext using a password. 8664 * 8665 * @param {Cipher} cipher The cipher algorithm to use. 8666 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8667 * @param {string} password The password. 8668 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8669 * 8670 * @return {WordArray} The plaintext. 8671 * 8672 * @static 8673 * 8674 * @example 8675 * 8676 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 8677 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 8678 */ 8679 decrypt: function (cipher, ciphertext, password, cfg) { 8680 // Apply config defaults 8681 cfg = this.cfg.extend(cfg); 8682 8683 // Convert string to CipherParams 8684 ciphertext = this._parse(ciphertext, cfg.format); 8685 8686 // Derive key and other params 8687 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 8688 8689 // Add IV to config 8690 cfg.iv = derivedParams.iv; 8691 8692 // Decrypt 8693 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 8694 8695 return plaintext; 8696 } 8697 }); 8698 }()); 8699 8700 8701 })); 8702 },{"./core":53}],53:[function(require,module,exports){ 8703 ;(function (root, factory) { 8704 if (typeof exports === "object") { 8705 // CommonJS 8706 module.exports = exports = factory(); 8707 } 8708 else if (typeof define === "function" && define.amd) { 8709 // AMD 8710 define([], factory); 8711 } 8712 else { 8713 // Global (browser) 8714 root.CryptoJS = factory(); 8715 } 8716 }(this, function () { 8717 8718 /** 8719 * CryptoJS core components. 8720 */ 8721 var CryptoJS = CryptoJS || (function (Math, undefined) { 8722 /* 8723 * Local polyfil of Object.create 8724 */ 8725 var create = Object.create || (function () { 8726 function F() {}; 8727 8728 return function (obj) { 8729 var subtype; 8730 8731 F.prototype = obj; 8732 8733 subtype = new F(); 8734 8735 F.prototype = null; 8736 8737 return subtype; 8738 }; 8739 }()) 8740 8741 /** 8742 * CryptoJS namespace. 8743 */ 8744 var C = {}; 8745 8746 /** 8747 * Library namespace. 8748 */ 8749 var C_lib = C.lib = {}; 8750 8751 /** 8752 * Base object for prototypal inheritance. 8753 */ 8754 var Base = C_lib.Base = (function () { 8755 8756 8757 return { 8758 /** 8759 * Creates a new object that inherits from this object. 8760 * 8761 * @param {Object} overrides Properties to copy into the new object. 8762 * 8763 * @return {Object} The new object. 8764 * 8765 * @static 8766 * 8767 * @example 8768 * 8769 * var MyType = CryptoJS.lib.Base.extend({ 8770 * field: 'value', 8771 * 8772 * method: function () { 8773 * } 8774 * }); 8775 */ 8776 extend: function (overrides) { 8777 // Spawn 8778 var subtype = create(this); 8779 8780 // Augment 8781 if (overrides) { 8782 subtype.mixIn(overrides); 8783 } 8784 8785 // Create default initializer 8786 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 8787 subtype.init = function () { 8788 subtype.$super.init.apply(this, arguments); 8789 }; 8790 } 8791 8792 // Initializer's prototype is the subtype object 8793 subtype.init.prototype = subtype; 8794 8795 // Reference supertype 8796 subtype.$super = this; 8797 8798 return subtype; 8799 }, 8800 8801 /** 8802 * Extends this object and runs the init method. 8803 * Arguments to create() will be passed to init(). 8804 * 8805 * @return {Object} The new object. 8806 * 8807 * @static 8808 * 8809 * @example 8810 * 8811 * var instance = MyType.create(); 8812 */ 8813 create: function () { 8814 var instance = this.extend(); 8815 instance.init.apply(instance, arguments); 8816 8817 return instance; 8818 }, 8819 8820 /** 8821 * Initializes a newly created object. 8822 * Override this method to add some logic when your objects are created. 8823 * 8824 * @example 8825 * 8826 * var MyType = CryptoJS.lib.Base.extend({ 8827 * init: function () { 8828 * // ... 8829 * } 8830 * }); 8831 */ 8832 init: function () { 8833 }, 8834 8835 /** 8836 * Copies properties into this object. 8837 * 8838 * @param {Object} properties The properties to mix in. 8839 * 8840 * @example 8841 * 8842 * MyType.mixIn({ 8843 * field: 'value' 8844 * }); 8845 */ 8846 mixIn: function (properties) { 8847 for (var propertyName in properties) { 8848 if (properties.hasOwnProperty(propertyName)) { 8849 this[propertyName] = properties[propertyName]; 8850 } 8851 } 8852 8853 // IE won't copy toString using the loop above 8854 if (properties.hasOwnProperty('toString')) { 8855 this.toString = properties.toString; 8856 } 8857 }, 8858 8859 /** 8860 * Creates a copy of this object. 8861 * 8862 * @return {Object} The clone. 8863 * 8864 * @example 8865 * 8866 * var clone = instance.clone(); 8867 */ 8868 clone: function () { 8869 return this.init.prototype.extend(this); 8870 } 8871 }; 8872 }()); 8873 8874 /** 8875 * An array of 32-bit words. 8876 * 8877 * @property {Array} words The array of 32-bit words. 8878 * @property {number} sigBytes The number of significant bytes in this word array. 8879 */ 8880 var WordArray = C_lib.WordArray = Base.extend({ 8881 /** 8882 * Initializes a newly created word array. 8883 * 8884 * @param {Array} words (Optional) An array of 32-bit words. 8885 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8886 * 8887 * @example 8888 * 8889 * var wordArray = CryptoJS.lib.WordArray.create(); 8890 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8891 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8892 */ 8893 init: function (words, sigBytes) { 8894 words = this.words = words || []; 8895 8896 if (sigBytes != undefined) { 8897 this.sigBytes = sigBytes; 8898 } else { 8899 this.sigBytes = words.length * 4; 8900 } 8901 }, 8902 8903 /** 8904 * Converts this word array to a string. 8905 * 8906 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8907 * 8908 * @return {string} The stringified word array. 8909 * 8910 * @example 8911 * 8912 * var string = wordArray + ''; 8913 * var string = wordArray.toString(); 8914 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8915 */ 8916 toString: function (encoder) { 8917 return (encoder || Hex).stringify(this); 8918 }, 8919 8920 /** 8921 * Concatenates a word array to this word array. 8922 * 8923 * @param {WordArray} wordArray The word array to append. 8924 * 8925 * @return {WordArray} This word array. 8926 * 8927 * @example 8928 * 8929 * wordArray1.concat(wordArray2); 8930 */ 8931 concat: function (wordArray) { 8932 // Shortcuts 8933 var thisWords = this.words; 8934 var thatWords = wordArray.words; 8935 var thisSigBytes = this.sigBytes; 8936 var thatSigBytes = wordArray.sigBytes; 8937 8938 // Clamp excess bits 8939 this.clamp(); 8940 8941 // Concat 8942 if (thisSigBytes % 4) { 8943 // Copy one byte at a time 8944 for (var i = 0; i < thatSigBytes; i++) { 8945 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8946 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8947 } 8948 } else { 8949 // Copy one word at a time 8950 for (var i = 0; i < thatSigBytes; i += 4) { 8951 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8952 } 8953 } 8954 this.sigBytes += thatSigBytes; 8955 8956 // Chainable 8957 return this; 8958 }, 8959 8960 /** 8961 * Removes insignificant bits. 8962 * 8963 * @example 8964 * 8965 * wordArray.clamp(); 8966 */ 8967 clamp: function () { 8968 // Shortcuts 8969 var words = this.words; 8970 var sigBytes = this.sigBytes; 8971 8972 // Clamp 8973 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8974 words.length = Math.ceil(sigBytes / 4); 8975 }, 8976 8977 /** 8978 * Creates a copy of this word array. 8979 * 8980 * @return {WordArray} The clone. 8981 * 8982 * @example 8983 * 8984 * var clone = wordArray.clone(); 8985 */ 8986 clone: function () { 8987 var clone = Base.clone.call(this); 8988 clone.words = this.words.slice(0); 8989 8990 return clone; 8991 }, 8992 8993 /** 8994 * Creates a word array filled with random bytes. 8995 * 8996 * @param {number} nBytes The number of random bytes to generate. 8997 * 8998 * @return {WordArray} The random word array. 8999 * 9000 * @static 9001 * 9002 * @example 9003 * 9004 * var wordArray = CryptoJS.lib.WordArray.random(16); 9005 */ 9006 random: function (nBytes) { 9007 var words = []; 9008 9009 var r = (function (m_w) { 9010 var m_w = m_w; 9011 var m_z = 0x3ade68b1; 9012 var mask = 0xffffffff; 9013 9014 return function () { 9015 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 9016 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 9017 var result = ((m_z << 0x10) + m_w) & mask; 9018 result /= 0x100000000; 9019 result += 0.5; 9020 return result * (Math.random() > .5 ? 1 : -1); 9021 } 9022 }); 9023 9024 for (var i = 0, rcache; i < nBytes; i += 4) { 9025 var _r = r((rcache || Math.random()) * 0x100000000); 9026 9027 rcache = _r() * 0x3ade67b7; 9028 words.push((_r() * 0x100000000) | 0); 9029 } 9030 9031 return new WordArray.init(words, nBytes); 9032 } 9033 }); 9034 9035 /** 9036 * Encoder namespace. 9037 */ 9038 var C_enc = C.enc = {}; 9039 9040 /** 9041 * Hex encoding strategy. 9042 */ 9043 var Hex = C_enc.Hex = { 9044 /** 9045 * Converts a word array to a hex string. 9046 * 9047 * @param {WordArray} wordArray The word array. 9048 * 9049 * @return {string} The hex string. 9050 * 9051 * @static 9052 * 9053 * @example 9054 * 9055 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 9056 */ 9057 stringify: function (wordArray) { 9058 // Shortcuts 9059 var words = wordArray.words; 9060 var sigBytes = wordArray.sigBytes; 9061 9062 // Convert 9063 var hexChars = []; 9064 for (var i = 0; i < sigBytes; i++) { 9065 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 9066 hexChars.push((bite >>> 4).toString(16)); 9067 hexChars.push((bite & 0x0f).toString(16)); 9068 } 9069 9070 return hexChars.join(''); 9071 }, 9072 9073 /** 9074 * Converts a hex string to a word array. 9075 * 9076 * @param {string} hexStr The hex string. 9077 * 9078 * @return {WordArray} The word array. 9079 * 9080 * @static 9081 * 9082 * @example 9083 * 9084 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 9085 */ 9086 parse: function (hexStr) { 9087 // Shortcut 9088 var hexStrLength = hexStr.length; 9089 9090 // Convert 9091 var words = []; 9092 for (var i = 0; i < hexStrLength; i += 2) { 9093 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 9094 } 9095 9096 return new WordArray.init(words, hexStrLength / 2); 9097 } 9098 }; 9099 9100 /** 9101 * Latin1 encoding strategy. 9102 */ 9103 var Latin1 = C_enc.Latin1 = { 9104 /** 9105 * Converts a word array to a Latin1 string. 9106 * 9107 * @param {WordArray} wordArray The word array. 9108 * 9109 * @return {string} The Latin1 string. 9110 * 9111 * @static 9112 * 9113 * @example 9114 * 9115 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 9116 */ 9117 stringify: function (wordArray) { 9118 // Shortcuts 9119 var words = wordArray.words; 9120 var sigBytes = wordArray.sigBytes; 9121 9122 // Convert 9123 var latin1Chars = []; 9124 for (var i = 0; i < sigBytes; i++) { 9125 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 9126 latin1Chars.push(String.fromCharCode(bite)); 9127 } 9128 9129 return latin1Chars.join(''); 9130 }, 9131 9132 /** 9133 * Converts a Latin1 string to a word array. 9134 * 9135 * @param {string} latin1Str The Latin1 string. 9136 * 9137 * @return {WordArray} The word array. 9138 * 9139 * @static 9140 * 9141 * @example 9142 * 9143 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 9144 */ 9145 parse: function (latin1Str) { 9146 // Shortcut 9147 var latin1StrLength = latin1Str.length; 9148 9149 // Convert 9150 var words = []; 9151 for (var i = 0; i < latin1StrLength; i++) { 9152 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 9153 } 9154 9155 return new WordArray.init(words, latin1StrLength); 9156 } 9157 }; 9158 9159 /** 9160 * UTF-8 encoding strategy. 9161 */ 9162 var Utf8 = C_enc.Utf8 = { 9163 /** 9164 * Converts a word array to a UTF-8 string. 9165 * 9166 * @param {WordArray} wordArray The word array. 9167 * 9168 * @return {string} The UTF-8 string. 9169 * 9170 * @static 9171 * 9172 * @example 9173 * 9174 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 9175 */ 9176 stringify: function (wordArray) { 9177 try { 9178 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 9179 } catch (e) { 9180 throw new Error('Malformed UTF-8 data'); 9181 } 9182 }, 9183 9184 /** 9185 * Converts a UTF-8 string to a word array. 9186 * 9187 * @param {string} utf8Str The UTF-8 string. 9188 * 9189 * @return {WordArray} The word array. 9190 * 9191 * @static 9192 * 9193 * @example 9194 * 9195 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 9196 */ 9197 parse: function (utf8Str) { 9198 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 9199 } 9200 }; 9201 9202 /** 9203 * Abstract buffered block algorithm template. 9204 * 9205 * The property blockSize must be implemented in a concrete subtype. 9206 * 9207 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 9208 */ 9209 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 9210 /** 9211 * Resets this block algorithm's data buffer to its initial state. 9212 * 9213 * @example 9214 * 9215 * bufferedBlockAlgorithm.reset(); 9216 */ 9217 reset: function () { 9218 // Initial values 9219 this._data = new WordArray.init(); 9220 this._nDataBytes = 0; 9221 }, 9222 9223 /** 9224 * Adds new data to this block algorithm's buffer. 9225 * 9226 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 9227 * 9228 * @example 9229 * 9230 * bufferedBlockAlgorithm._append('data'); 9231 * bufferedBlockAlgorithm._append(wordArray); 9232 */ 9233 _append: function (data) { 9234 // Convert string to WordArray, else assume WordArray already 9235 if (typeof data == 'string') { 9236 data = Utf8.parse(data); 9237 } 9238 9239 // Append 9240 this._data.concat(data); 9241 this._nDataBytes += data.sigBytes; 9242 }, 9243 9244 /** 9245 * Processes available data blocks. 9246 * 9247 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 9248 * 9249 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 9250 * 9251 * @return {WordArray} The processed data. 9252 * 9253 * @example 9254 * 9255 * var processedData = bufferedBlockAlgorithm._process(); 9256 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 9257 */ 9258 _process: function (doFlush) { 9259 // Shortcuts 9260 var data = this._data; 9261 var dataWords = data.words; 9262 var dataSigBytes = data.sigBytes; 9263 var blockSize = this.blockSize; 9264 var blockSizeBytes = blockSize * 4; 9265 9266 // Count blocks ready 9267 var nBlocksReady = dataSigBytes / blockSizeBytes; 9268 if (doFlush) { 9269 // Round up to include partial blocks 9270 nBlocksReady = Math.ceil(nBlocksReady); 9271 } else { 9272 // Round down to include only full blocks, 9273 // less the number of blocks that must remain in the buffer 9274 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 9275 } 9276 9277 // Count words ready 9278 var nWordsReady = nBlocksReady * blockSize; 9279 9280 // Count bytes ready 9281 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 9282 9283 // Process blocks 9284 if (nWordsReady) { 9285 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 9286 // Perform concrete-algorithm logic 9287 this._doProcessBlock(dataWords, offset); 9288 } 9289 9290 // Remove processed words 9291 var processedWords = dataWords.splice(0, nWordsReady); 9292 data.sigBytes -= nBytesReady; 9293 } 9294 9295 // Return processed words 9296 return new WordArray.init(processedWords, nBytesReady); 9297 }, 9298 9299 /** 9300 * Creates a copy of this object. 9301 * 9302 * @return {Object} The clone. 9303 * 9304 * @example 9305 * 9306 * var clone = bufferedBlockAlgorithm.clone(); 9307 */ 9308 clone: function () { 9309 var clone = Base.clone.call(this); 9310 clone._data = this._data.clone(); 9311 9312 return clone; 9313 }, 9314 9315 _minBufferSize: 0 9316 }); 9317 9318 /** 9319 * Abstract hasher template. 9320 * 9321 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 9322 */ 9323 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 9324 /** 9325 * Configuration options. 9326 */ 9327 cfg: Base.extend(), 9328 9329 /** 9330 * Initializes a newly created hasher. 9331 * 9332 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 9333 * 9334 * @example 9335 * 9336 * var hasher = CryptoJS.algo.SHA256.create(); 9337 */ 9338 init: function (cfg) { 9339 // Apply config defaults 9340 this.cfg = this.cfg.extend(cfg); 9341 9342 // Set initial values 9343 this.reset(); 9344 }, 9345 9346 /** 9347 * Resets this hasher to its initial state. 9348 * 9349 * @example 9350 * 9351 * hasher.reset(); 9352 */ 9353 reset: function () { 9354 // Reset data buffer 9355 BufferedBlockAlgorithm.reset.call(this); 9356 9357 // Perform concrete-hasher logic 9358 this._doReset(); 9359 }, 9360 9361 /** 9362 * Updates this hasher with a message. 9363 * 9364 * @param {WordArray|string} messageUpdate The message to append. 9365 * 9366 * @return {Hasher} This hasher. 9367 * 9368 * @example 9369 * 9370 * hasher.update('message'); 9371 * hasher.update(wordArray); 9372 */ 9373 update: function (messageUpdate) { 9374 // Append 9375 this._append(messageUpdate); 9376 9377 // Update the hash 9378 this._process(); 9379 9380 // Chainable 9381 return this; 9382 }, 9383 9384 /** 9385 * Finalizes the hash computation. 9386 * Note that the finalize operation is effectively a destructive, read-once operation. 9387 * 9388 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9389 * 9390 * @return {WordArray} The hash. 9391 * 9392 * @example 9393 * 9394 * var hash = hasher.finalize(); 9395 * var hash = hasher.finalize('message'); 9396 * var hash = hasher.finalize(wordArray); 9397 */ 9398 finalize: function (messageUpdate) { 9399 // Final message update 9400 if (messageUpdate) { 9401 this._append(messageUpdate); 9402 } 9403 9404 // Perform concrete-hasher logic 9405 var hash = this._doFinalize(); 9406 9407 return hash; 9408 }, 9409 9410 blockSize: 512/32, 9411 9412 /** 9413 * Creates a shortcut function to a hasher's object interface. 9414 * 9415 * @param {Hasher} hasher The hasher to create a helper for. 9416 * 9417 * @return {Function} The shortcut function. 9418 * 9419 * @static 9420 * 9421 * @example 9422 * 9423 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 9424 */ 9425 _createHelper: function (hasher) { 9426 return function (message, cfg) { 9427 return new hasher.init(cfg).finalize(message); 9428 }; 9429 }, 9430 9431 /** 9432 * Creates a shortcut function to the HMAC's object interface. 9433 * 9434 * @param {Hasher} hasher The hasher to use in this HMAC helper. 9435 * 9436 * @return {Function} The shortcut function. 9437 * 9438 * @static 9439 * 9440 * @example 9441 * 9442 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 9443 */ 9444 _createHmacHelper: function (hasher) { 9445 return function (message, key) { 9446 return new C_algo.HMAC.init(hasher, key).finalize(message); 9447 }; 9448 } 9449 }); 9450 9451 /** 9452 * Algorithm namespace. 9453 */ 9454 var C_algo = C.algo = {}; 9455 9456 return C; 9457 }(Math)); 9458 9459 9460 return CryptoJS; 9461 9462 })); 9463 },{}],54:[function(require,module,exports){ 9464 ;(function (root, factory) { 9465 if (typeof exports === "object") { 9466 // CommonJS 9467 module.exports = exports = factory(require("./core")); 9468 } 9469 else if (typeof define === "function" && define.amd) { 9470 // AMD 9471 define(["./core"], factory); 9472 } 9473 else { 9474 // Global (browser) 9475 factory(root.CryptoJS); 9476 } 9477 }(this, function (CryptoJS) { 9478 9479 (function () { 9480 // Shortcuts 9481 var C = CryptoJS; 9482 var C_lib = C.lib; 9483 var WordArray = C_lib.WordArray; 9484 var C_enc = C.enc; 9485 9486 /** 9487 * Base64 encoding strategy. 9488 */ 9489 var Base64 = C_enc.Base64 = { 9490 /** 9491 * Converts a word array to a Base64 string. 9492 * 9493 * @param {WordArray} wordArray The word array. 9494 * 9495 * @return {string} The Base64 string. 9496 * 9497 * @static 9498 * 9499 * @example 9500 * 9501 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 9502 */ 9503 stringify: function (wordArray) { 9504 // Shortcuts 9505 var words = wordArray.words; 9506 var sigBytes = wordArray.sigBytes; 9507 var map = this._map; 9508 9509 // Clamp excess bits 9510 wordArray.clamp(); 9511 9512 // Convert 9513 var base64Chars = []; 9514 for (var i = 0; i < sigBytes; i += 3) { 9515 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 9516 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 9517 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 9518 9519 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 9520 9521 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 9522 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 9523 } 9524 } 9525 9526 // Add padding 9527 var paddingChar = map.charAt(64); 9528 if (paddingChar) { 9529 while (base64Chars.length % 4) { 9530 base64Chars.push(paddingChar); 9531 } 9532 } 9533 9534 return base64Chars.join(''); 9535 }, 9536 9537 /** 9538 * Converts a Base64 string to a word array. 9539 * 9540 * @param {string} base64Str The Base64 string. 9541 * 9542 * @return {WordArray} The word array. 9543 * 9544 * @static 9545 * 9546 * @example 9547 * 9548 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 9549 */ 9550 parse: function (base64Str) { 9551 // Shortcuts 9552 var base64StrLength = base64Str.length; 9553 var map = this._map; 9554 var reverseMap = this._reverseMap; 9555 9556 if (!reverseMap) { 9557 reverseMap = this._reverseMap = []; 9558 for (var j = 0; j < map.length; j++) { 9559 reverseMap[map.charCodeAt(j)] = j; 9560 } 9561 } 9562 9563 // Ignore padding 9564 var paddingChar = map.charAt(64); 9565 if (paddingChar) { 9566 var paddingIndex = base64Str.indexOf(paddingChar); 9567 if (paddingIndex !== -1) { 9568 base64StrLength = paddingIndex; 9569 } 9570 } 9571 9572 // Convert 9573 return parseLoop(base64Str, base64StrLength, reverseMap); 9574 9575 }, 9576 9577 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 9578 }; 9579 9580 function parseLoop(base64Str, base64StrLength, reverseMap) { 9581 var words = []; 9582 var nBytes = 0; 9583 for (var i = 0; i < base64StrLength; i++) { 9584 if (i % 4) { 9585 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 9586 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 9587 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 9588 nBytes++; 9589 } 9590 } 9591 return WordArray.create(words, nBytes); 9592 } 9593 }()); 9594 9595 9596 return CryptoJS.enc.Base64; 9597 9598 })); 9599 },{"./core":53}],55:[function(require,module,exports){ 9600 ;(function (root, factory) { 9601 if (typeof exports === "object") { 9602 // CommonJS 9603 module.exports = exports = factory(require("./core")); 9604 } 9605 else if (typeof define === "function" && define.amd) { 9606 // AMD 9607 define(["./core"], factory); 9608 } 9609 else { 9610 // Global (browser) 9611 factory(root.CryptoJS); 9612 } 9613 }(this, function (CryptoJS) { 9614 9615 (function () { 9616 // Shortcuts 9617 var C = CryptoJS; 9618 var C_lib = C.lib; 9619 var WordArray = C_lib.WordArray; 9620 var C_enc = C.enc; 9621 9622 /** 9623 * UTF-16 BE encoding strategy. 9624 */ 9625 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 9626 /** 9627 * Converts a word array to a UTF-16 BE string. 9628 * 9629 * @param {WordArray} wordArray The word array. 9630 * 9631 * @return {string} The UTF-16 BE string. 9632 * 9633 * @static 9634 * 9635 * @example 9636 * 9637 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 9638 */ 9639 stringify: function (wordArray) { 9640 // Shortcuts 9641 var words = wordArray.words; 9642 var sigBytes = wordArray.sigBytes; 9643 9644 // Convert 9645 var utf16Chars = []; 9646 for (var i = 0; i < sigBytes; i += 2) { 9647 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 9648 utf16Chars.push(String.fromCharCode(codePoint)); 9649 } 9650 9651 return utf16Chars.join(''); 9652 }, 9653 9654 /** 9655 * Converts a UTF-16 BE string to a word array. 9656 * 9657 * @param {string} utf16Str The UTF-16 BE string. 9658 * 9659 * @return {WordArray} The word array. 9660 * 9661 * @static 9662 * 9663 * @example 9664 * 9665 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 9666 */ 9667 parse: function (utf16Str) { 9668 // Shortcut 9669 var utf16StrLength = utf16Str.length; 9670 9671 // Convert 9672 var words = []; 9673 for (var i = 0; i < utf16StrLength; i++) { 9674 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 9675 } 9676 9677 return WordArray.create(words, utf16StrLength * 2); 9678 } 9679 }; 9680 9681 /** 9682 * UTF-16 LE encoding strategy. 9683 */ 9684 C_enc.Utf16LE = { 9685 /** 9686 * Converts a word array to a UTF-16 LE string. 9687 * 9688 * @param {WordArray} wordArray The word array. 9689 * 9690 * @return {string} The UTF-16 LE string. 9691 * 9692 * @static 9693 * 9694 * @example 9695 * 9696 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 9697 */ 9698 stringify: function (wordArray) { 9699 // Shortcuts 9700 var words = wordArray.words; 9701 var sigBytes = wordArray.sigBytes; 9702 9703 // Convert 9704 var utf16Chars = []; 9705 for (var i = 0; i < sigBytes; i += 2) { 9706 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 9707 utf16Chars.push(String.fromCharCode(codePoint)); 9708 } 9709 9710 return utf16Chars.join(''); 9711 }, 9712 9713 /** 9714 * Converts a UTF-16 LE string to a word array. 9715 * 9716 * @param {string} utf16Str The UTF-16 LE string. 9717 * 9718 * @return {WordArray} The word array. 9719 * 9720 * @static 9721 * 9722 * @example 9723 * 9724 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 9725 */ 9726 parse: function (utf16Str) { 9727 // Shortcut 9728 var utf16StrLength = utf16Str.length; 9729 9730 // Convert 9731 var words = []; 9732 for (var i = 0; i < utf16StrLength; i++) { 9733 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 9734 } 9735 9736 return WordArray.create(words, utf16StrLength * 2); 9737 } 9738 }; 9739 9740 function swapEndian(word) { 9741 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 9742 } 9743 }()); 9744 9745 9746 return CryptoJS.enc.Utf16; 9747 9748 })); 9749 },{"./core":53}],56:[function(require,module,exports){ 9750 ;(function (root, factory, undef) { 9751 if (typeof exports === "object") { 9752 // CommonJS 9753 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 9754 } 9755 else if (typeof define === "function" && define.amd) { 9756 // AMD 9757 define(["./core", "./sha1", "./hmac"], factory); 9758 } 9759 else { 9760 // Global (browser) 9761 factory(root.CryptoJS); 9762 } 9763 }(this, function (CryptoJS) { 9764 9765 (function () { 9766 // Shortcuts 9767 var C = CryptoJS; 9768 var C_lib = C.lib; 9769 var Base = C_lib.Base; 9770 var WordArray = C_lib.WordArray; 9771 var C_algo = C.algo; 9772 var MD5 = C_algo.MD5; 9773 9774 /** 9775 * This key derivation function is meant to conform with EVP_BytesToKey. 9776 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 9777 */ 9778 var EvpKDF = C_algo.EvpKDF = Base.extend({ 9779 /** 9780 * Configuration options. 9781 * 9782 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9783 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 9784 * @property {number} iterations The number of iterations to perform. Default: 1 9785 */ 9786 cfg: Base.extend({ 9787 keySize: 128/32, 9788 hasher: MD5, 9789 iterations: 1 9790 }), 9791 9792 /** 9793 * Initializes a newly created key derivation function. 9794 * 9795 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9796 * 9797 * @example 9798 * 9799 * var kdf = CryptoJS.algo.EvpKDF.create(); 9800 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9801 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9802 */ 9803 init: function (cfg) { 9804 this.cfg = this.cfg.extend(cfg); 9805 }, 9806 9807 /** 9808 * Derives a key from a password. 9809 * 9810 * @param {WordArray|string} password The password. 9811 * @param {WordArray|string} salt A salt. 9812 * 9813 * @return {WordArray} The derived key. 9814 * 9815 * @example 9816 * 9817 * var key = kdf.compute(password, salt); 9818 */ 9819 compute: function (password, salt) { 9820 // Shortcut 9821 var cfg = this.cfg; 9822 9823 // Init hasher 9824 var hasher = cfg.hasher.create(); 9825 9826 // Initial values 9827 var derivedKey = WordArray.create(); 9828 9829 // Shortcuts 9830 var derivedKeyWords = derivedKey.words; 9831 var keySize = cfg.keySize; 9832 var iterations = cfg.iterations; 9833 9834 // Generate key 9835 while (derivedKeyWords.length < keySize) { 9836 if (block) { 9837 hasher.update(block); 9838 } 9839 var block = hasher.update(password).finalize(salt); 9840 hasher.reset(); 9841 9842 // Iterations 9843 for (var i = 1; i < iterations; i++) { 9844 block = hasher.finalize(block); 9845 hasher.reset(); 9846 } 9847 9848 derivedKey.concat(block); 9849 } 9850 derivedKey.sigBytes = keySize * 4; 9851 9852 return derivedKey; 9853 } 9854 }); 9855 9856 /** 9857 * Derives a key from a password. 9858 * 9859 * @param {WordArray|string} password The password. 9860 * @param {WordArray|string} salt A salt. 9861 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9862 * 9863 * @return {WordArray} The derived key. 9864 * 9865 * @static 9866 * 9867 * @example 9868 * 9869 * var key = CryptoJS.EvpKDF(password, salt); 9870 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9871 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9872 */ 9873 C.EvpKDF = function (password, salt, cfg) { 9874 return EvpKDF.create(cfg).compute(password, salt); 9875 }; 9876 }()); 9877 9878 9879 return CryptoJS.EvpKDF; 9880 9881 })); 9882 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 9883 ;(function (root, factory, undef) { 9884 if (typeof exports === "object") { 9885 // CommonJS 9886 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9887 } 9888 else if (typeof define === "function" && define.amd) { 9889 // AMD 9890 define(["./core", "./cipher-core"], factory); 9891 } 9892 else { 9893 // Global (browser) 9894 factory(root.CryptoJS); 9895 } 9896 }(this, function (CryptoJS) { 9897 9898 (function (undefined) { 9899 // Shortcuts 9900 var C = CryptoJS; 9901 var C_lib = C.lib; 9902 var CipherParams = C_lib.CipherParams; 9903 var C_enc = C.enc; 9904 var Hex = C_enc.Hex; 9905 var C_format = C.format; 9906 9907 var HexFormatter = C_format.Hex = { 9908 /** 9909 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9910 * 9911 * @param {CipherParams} cipherParams The cipher params object. 9912 * 9913 * @return {string} The hexadecimally encoded string. 9914 * 9915 * @static 9916 * 9917 * @example 9918 * 9919 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9920 */ 9921 stringify: function (cipherParams) { 9922 return cipherParams.ciphertext.toString(Hex); 9923 }, 9924 9925 /** 9926 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9927 * 9928 * @param {string} input The hexadecimally encoded string. 9929 * 9930 * @return {CipherParams} The cipher params object. 9931 * 9932 * @static 9933 * 9934 * @example 9935 * 9936 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9937 */ 9938 parse: function (input) { 9939 var ciphertext = Hex.parse(input); 9940 return CipherParams.create({ ciphertext: ciphertext }); 9941 } 9942 }; 9943 }()); 9944 9945 9946 return CryptoJS.format.Hex; 9947 9948 })); 9949 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 9950 ;(function (root, factory) { 9951 if (typeof exports === "object") { 9952 // CommonJS 9953 module.exports = exports = factory(require("./core")); 9954 } 9955 else if (typeof define === "function" && define.amd) { 9956 // AMD 9957 define(["./core"], factory); 9958 } 9959 else { 9960 // Global (browser) 9961 factory(root.CryptoJS); 9962 } 9963 }(this, function (CryptoJS) { 9964 9965 (function () { 9966 // Shortcuts 9967 var C = CryptoJS; 9968 var C_lib = C.lib; 9969 var Base = C_lib.Base; 9970 var C_enc = C.enc; 9971 var Utf8 = C_enc.Utf8; 9972 var C_algo = C.algo; 9973 9974 /** 9975 * HMAC algorithm. 9976 */ 9977 var HMAC = C_algo.HMAC = Base.extend({ 9978 /** 9979 * Initializes a newly created HMAC. 9980 * 9981 * @param {Hasher} hasher The hash algorithm to use. 9982 * @param {WordArray|string} key The secret key. 9983 * 9984 * @example 9985 * 9986 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9987 */ 9988 init: function (hasher, key) { 9989 // Init hasher 9990 hasher = this._hasher = new hasher.init(); 9991 9992 // Convert string to WordArray, else assume WordArray already 9993 if (typeof key == 'string') { 9994 key = Utf8.parse(key); 9995 } 9996 9997 // Shortcuts 9998 var hasherBlockSize = hasher.blockSize; 9999 var hasherBlockSizeBytes = hasherBlockSize * 4; 10000 10001 // Allow arbitrary length keys 10002 if (key.sigBytes > hasherBlockSizeBytes) { 10003 key = hasher.finalize(key); 10004 } 10005 10006 // Clamp excess bits 10007 key.clamp(); 10008 10009 // Clone key for inner and outer pads 10010 var oKey = this._oKey = key.clone(); 10011 var iKey = this._iKey = key.clone(); 10012 10013 // Shortcuts 10014 var oKeyWords = oKey.words; 10015 var iKeyWords = iKey.words; 10016 10017 // XOR keys with pad constants 10018 for (var i = 0; i < hasherBlockSize; i++) { 10019 oKeyWords[i] ^= 0x5c5c5c5c; 10020 iKeyWords[i] ^= 0x36363636; 10021 } 10022 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 10023 10024 // Set initial values 10025 this.reset(); 10026 }, 10027 10028 /** 10029 * Resets this HMAC to its initial state. 10030 * 10031 * @example 10032 * 10033 * hmacHasher.reset(); 10034 */ 10035 reset: function () { 10036 // Shortcut 10037 var hasher = this._hasher; 10038 10039 // Reset 10040 hasher.reset(); 10041 hasher.update(this._iKey); 10042 }, 10043 10044 /** 10045 * Updates this HMAC with a message. 10046 * 10047 * @param {WordArray|string} messageUpdate The message to append. 10048 * 10049 * @return {HMAC} This HMAC instance. 10050 * 10051 * @example 10052 * 10053 * hmacHasher.update('message'); 10054 * hmacHasher.update(wordArray); 10055 */ 10056 update: function (messageUpdate) { 10057 this._hasher.update(messageUpdate); 10058 10059 // Chainable 10060 return this; 10061 }, 10062 10063 /** 10064 * Finalizes the HMAC computation. 10065 * Note that the finalize operation is effectively a destructive, read-once operation. 10066 * 10067 * @param {WordArray|string} messageUpdate (Optional) A final message update. 10068 * 10069 * @return {WordArray} The HMAC. 10070 * 10071 * @example 10072 * 10073 * var hmac = hmacHasher.finalize(); 10074 * var hmac = hmacHasher.finalize('message'); 10075 * var hmac = hmacHasher.finalize(wordArray); 10076 */ 10077 finalize: function (messageUpdate) { 10078 // Shortcut 10079 var hasher = this._hasher; 10080 10081 // Compute HMAC 10082 var innerHash = hasher.finalize(messageUpdate); 10083 hasher.reset(); 10084 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 10085 10086 return hmac; 10087 } 10088 }); 10089 }()); 10090 10091 10092 })); 10093 },{"./core":53}],59:[function(require,module,exports){ 10094 ;(function (root, factory, undef) { 10095 if (typeof exports === "object") { 10096 // CommonJS 10097 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")); 10098 } 10099 else if (typeof define === "function" && define.amd) { 10100 // AMD 10101 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); 10102 } 10103 else { 10104 // Global (browser) 10105 root.CryptoJS = factory(root.CryptoJS); 10106 } 10107 }(this, function (CryptoJS) { 10108 10109 return CryptoJS; 10110 10111 })); 10112 },{"./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){ 10113 ;(function (root, factory) { 10114 if (typeof exports === "object") { 10115 // CommonJS 10116 module.exports = exports = factory(require("./core")); 10117 } 10118 else if (typeof define === "function" && define.amd) { 10119 // AMD 10120 define(["./core"], factory); 10121 } 10122 else { 10123 // Global (browser) 10124 factory(root.CryptoJS); 10125 } 10126 }(this, function (CryptoJS) { 10127 10128 (function () { 10129 // Check if typed arrays are supported 10130 if (typeof ArrayBuffer != 'function') { 10131 return; 10132 } 10133 10134 // Shortcuts 10135 var C = CryptoJS; 10136 var C_lib = C.lib; 10137 var WordArray = C_lib.WordArray; 10138 10139 // Reference original init 10140 var superInit = WordArray.init; 10141 10142 // Augment WordArray.init to handle typed arrays 10143 var subInit = WordArray.init = function (typedArray) { 10144 // Convert buffers to uint8 10145 if (typedArray instanceof ArrayBuffer) { 10146 typedArray = new Uint8Array(typedArray); 10147 } 10148 10149 // Convert other array views to uint8 10150 if ( 10151 typedArray instanceof Int8Array || 10152 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 10153 typedArray instanceof Int16Array || 10154 typedArray instanceof Uint16Array || 10155 typedArray instanceof Int32Array || 10156 typedArray instanceof Uint32Array || 10157 typedArray instanceof Float32Array || 10158 typedArray instanceof Float64Array 10159 ) { 10160 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 10161 } 10162 10163 // Handle Uint8Array 10164 if (typedArray instanceof Uint8Array) { 10165 // Shortcut 10166 var typedArrayByteLength = typedArray.byteLength; 10167 10168 // Extract bytes 10169 var words = []; 10170 for (var i = 0; i < typedArrayByteLength; i++) { 10171 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 10172 } 10173 10174 // Initialize this word array 10175 superInit.call(this, words, typedArrayByteLength); 10176 } else { 10177 // Else call normal init 10178 superInit.apply(this, arguments); 10179 } 10180 }; 10181 10182 subInit.prototype = WordArray; 10183 }()); 10184 10185 10186 return CryptoJS.lib.WordArray; 10187 10188 })); 10189 },{"./core":53}],61:[function(require,module,exports){ 10190 ;(function (root, factory) { 10191 if (typeof exports === "object") { 10192 // CommonJS 10193 module.exports = exports = factory(require("./core")); 10194 } 10195 else if (typeof define === "function" && define.amd) { 10196 // AMD 10197 define(["./core"], factory); 10198 } 10199 else { 10200 // Global (browser) 10201 factory(root.CryptoJS); 10202 } 10203 }(this, function (CryptoJS) { 10204 10205 (function (Math) { 10206 // Shortcuts 10207 var C = CryptoJS; 10208 var C_lib = C.lib; 10209 var WordArray = C_lib.WordArray; 10210 var Hasher = C_lib.Hasher; 10211 var C_algo = C.algo; 10212 10213 // Constants table 10214 var T = []; 10215 10216 // Compute constants 10217 (function () { 10218 for (var i = 0; i < 64; i++) { 10219 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 10220 } 10221 }()); 10222 10223 /** 10224 * MD5 hash algorithm. 10225 */ 10226 var MD5 = C_algo.MD5 = Hasher.extend({ 10227 _doReset: function () { 10228 this._hash = new WordArray.init([ 10229 0x67452301, 0xefcdab89, 10230 0x98badcfe, 0x10325476 10231 ]); 10232 }, 10233 10234 _doProcessBlock: function (M, offset) { 10235 // Swap endian 10236 for (var i = 0; i < 16; i++) { 10237 // Shortcuts 10238 var offset_i = offset + i; 10239 var M_offset_i = M[offset_i]; 10240 10241 M[offset_i] = ( 10242 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 10243 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 10244 ); 10245 } 10246 10247 // Shortcuts 10248 var H = this._hash.words; 10249 10250 var M_offset_0 = M[offset + 0]; 10251 var M_offset_1 = M[offset + 1]; 10252 var M_offset_2 = M[offset + 2]; 10253 var M_offset_3 = M[offset + 3]; 10254 var M_offset_4 = M[offset + 4]; 10255 var M_offset_5 = M[offset + 5]; 10256 var M_offset_6 = M[offset + 6]; 10257 var M_offset_7 = M[offset + 7]; 10258 var M_offset_8 = M[offset + 8]; 10259 var M_offset_9 = M[offset + 9]; 10260 var M_offset_10 = M[offset + 10]; 10261 var M_offset_11 = M[offset + 11]; 10262 var M_offset_12 = M[offset + 12]; 10263 var M_offset_13 = M[offset + 13]; 10264 var M_offset_14 = M[offset + 14]; 10265 var M_offset_15 = M[offset + 15]; 10266 10267 // Working varialbes 10268 var a = H[0]; 10269 var b = H[1]; 10270 var c = H[2]; 10271 var d = H[3]; 10272 10273 // Computation 10274 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 10275 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 10276 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 10277 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 10278 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 10279 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 10280 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 10281 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 10282 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 10283 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 10284 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 10285 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 10286 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 10287 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 10288 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 10289 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 10290 10291 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 10292 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 10293 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 10294 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 10295 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 10296 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 10297 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 10298 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 10299 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 10300 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 10301 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 10302 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 10303 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 10304 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 10305 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 10306 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 10307 10308 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 10309 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 10310 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 10311 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 10312 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 10313 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 10314 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 10315 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 10316 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 10317 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 10318 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 10319 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 10320 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 10321 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 10322 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 10323 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 10324 10325 a = II(a, b, c, d, M_offset_0, 6, T[48]); 10326 d = II(d, a, b, c, M_offset_7, 10, T[49]); 10327 c = II(c, d, a, b, M_offset_14, 15, T[50]); 10328 b = II(b, c, d, a, M_offset_5, 21, T[51]); 10329 a = II(a, b, c, d, M_offset_12, 6, T[52]); 10330 d = II(d, a, b, c, M_offset_3, 10, T[53]); 10331 c = II(c, d, a, b, M_offset_10, 15, T[54]); 10332 b = II(b, c, d, a, M_offset_1, 21, T[55]); 10333 a = II(a, b, c, d, M_offset_8, 6, T[56]); 10334 d = II(d, a, b, c, M_offset_15, 10, T[57]); 10335 c = II(c, d, a, b, M_offset_6, 15, T[58]); 10336 b = II(b, c, d, a, M_offset_13, 21, T[59]); 10337 a = II(a, b, c, d, M_offset_4, 6, T[60]); 10338 d = II(d, a, b, c, M_offset_11, 10, T[61]); 10339 c = II(c, d, a, b, M_offset_2, 15, T[62]); 10340 b = II(b, c, d, a, M_offset_9, 21, T[63]); 10341 10342 // Intermediate hash value 10343 H[0] = (H[0] + a) | 0; 10344 H[1] = (H[1] + b) | 0; 10345 H[2] = (H[2] + c) | 0; 10346 H[3] = (H[3] + d) | 0; 10347 }, 10348 10349 _doFinalize: function () { 10350 // Shortcuts 10351 var data = this._data; 10352 var dataWords = data.words; 10353 10354 var nBitsTotal = this._nDataBytes * 8; 10355 var nBitsLeft = data.sigBytes * 8; 10356 10357 // Add padding 10358 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 10359 10360 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 10361 var nBitsTotalL = nBitsTotal; 10362 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 10363 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 10364 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 10365 ); 10366 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 10367 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 10368 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 10369 ); 10370 10371 data.sigBytes = (dataWords.length + 1) * 4; 10372 10373 // Hash final blocks 10374 this._process(); 10375 10376 // Shortcuts 10377 var hash = this._hash; 10378 var H = hash.words; 10379 10380 // Swap endian 10381 for (var i = 0; i < 4; i++) { 10382 // Shortcut 10383 var H_i = H[i]; 10384 10385 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 10386 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 10387 } 10388 10389 // Return final computed hash 10390 return hash; 10391 }, 10392 10393 clone: function () { 10394 var clone = Hasher.clone.call(this); 10395 clone._hash = this._hash.clone(); 10396 10397 return clone; 10398 } 10399 }); 10400 10401 function FF(a, b, c, d, x, s, t) { 10402 var n = a + ((b & c) | (~b & d)) + x + t; 10403 return ((n << s) | (n >>> (32 - s))) + b; 10404 } 10405 10406 function GG(a, b, c, d, x, s, t) { 10407 var n = a + ((b & d) | (c & ~d)) + x + t; 10408 return ((n << s) | (n >>> (32 - s))) + b; 10409 } 10410 10411 function HH(a, b, c, d, x, s, t) { 10412 var n = a + (b ^ c ^ d) + x + t; 10413 return ((n << s) | (n >>> (32 - s))) + b; 10414 } 10415 10416 function II(a, b, c, d, x, s, t) { 10417 var n = a + (c ^ (b | ~d)) + x + t; 10418 return ((n << s) | (n >>> (32 - s))) + b; 10419 } 10420 10421 /** 10422 * Shortcut function to the hasher's object interface. 10423 * 10424 * @param {WordArray|string} message The message to hash. 10425 * 10426 * @return {WordArray} The hash. 10427 * 10428 * @static 10429 * 10430 * @example 10431 * 10432 * var hash = CryptoJS.MD5('message'); 10433 * var hash = CryptoJS.MD5(wordArray); 10434 */ 10435 C.MD5 = Hasher._createHelper(MD5); 10436 10437 /** 10438 * Shortcut function to the HMAC's object interface. 10439 * 10440 * @param {WordArray|string} message The message to hash. 10441 * @param {WordArray|string} key The secret key. 10442 * 10443 * @return {WordArray} The HMAC. 10444 * 10445 * @static 10446 * 10447 * @example 10448 * 10449 * var hmac = CryptoJS.HmacMD5(message, key); 10450 */ 10451 C.HmacMD5 = Hasher._createHmacHelper(MD5); 10452 }(Math)); 10453 10454 10455 return CryptoJS.MD5; 10456 10457 })); 10458 },{"./core":53}],62:[function(require,module,exports){ 10459 ;(function (root, factory, undef) { 10460 if (typeof exports === "object") { 10461 // CommonJS 10462 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10463 } 10464 else if (typeof define === "function" && define.amd) { 10465 // AMD 10466 define(["./core", "./cipher-core"], factory); 10467 } 10468 else { 10469 // Global (browser) 10470 factory(root.CryptoJS); 10471 } 10472 }(this, function (CryptoJS) { 10473 10474 /** 10475 * Cipher Feedback block mode. 10476 */ 10477 CryptoJS.mode.CFB = (function () { 10478 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 10479 10480 CFB.Encryptor = CFB.extend({ 10481 processBlock: function (words, offset) { 10482 // Shortcuts 10483 var cipher = this._cipher; 10484 var blockSize = cipher.blockSize; 10485 10486 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 10487 10488 // Remember this block to use with next block 10489 this._prevBlock = words.slice(offset, offset + blockSize); 10490 } 10491 }); 10492 10493 CFB.Decryptor = CFB.extend({ 10494 processBlock: function (words, offset) { 10495 // Shortcuts 10496 var cipher = this._cipher; 10497 var blockSize = cipher.blockSize; 10498 10499 // Remember this block to use with next block 10500 var thisBlock = words.slice(offset, offset + blockSize); 10501 10502 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 10503 10504 // This block becomes the previous block 10505 this._prevBlock = thisBlock; 10506 } 10507 }); 10508 10509 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 10510 // Shortcut 10511 var iv = this._iv; 10512 10513 // Generate keystream 10514 if (iv) { 10515 var keystream = iv.slice(0); 10516 10517 // Remove IV for subsequent blocks 10518 this._iv = undefined; 10519 } else { 10520 var keystream = this._prevBlock; 10521 } 10522 cipher.encryptBlock(keystream, 0); 10523 10524 // Encrypt 10525 for (var i = 0; i < blockSize; i++) { 10526 words[offset + i] ^= keystream[i]; 10527 } 10528 } 10529 10530 return CFB; 10531 }()); 10532 10533 10534 return CryptoJS.mode.CFB; 10535 10536 })); 10537 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 10538 ;(function (root, factory, undef) { 10539 if (typeof exports === "object") { 10540 // CommonJS 10541 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10542 } 10543 else if (typeof define === "function" && define.amd) { 10544 // AMD 10545 define(["./core", "./cipher-core"], factory); 10546 } 10547 else { 10548 // Global (browser) 10549 factory(root.CryptoJS); 10550 } 10551 }(this, function (CryptoJS) { 10552 10553 /** @preserve 10554 * Counter block mode compatible with Dr Brian Gladman fileenc.c 10555 * derived from CryptoJS.mode.CTR 10556 * Jan Hruby jhruby.web@gmail.com 10557 */ 10558 CryptoJS.mode.CTRGladman = (function () { 10559 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 10560 10561 function incWord(word) 10562 { 10563 if (((word >> 24) & 0xff) === 0xff) { //overflow 10564 var b1 = (word >> 16)&0xff; 10565 var b2 = (word >> 8)&0xff; 10566 var b3 = word & 0xff; 10567 10568 if (b1 === 0xff) // overflow b1 10569 { 10570 b1 = 0; 10571 if (b2 === 0xff) 10572 { 10573 b2 = 0; 10574 if (b3 === 0xff) 10575 { 10576 b3 = 0; 10577 } 10578 else 10579 { 10580 ++b3; 10581 } 10582 } 10583 else 10584 { 10585 ++b2; 10586 } 10587 } 10588 else 10589 { 10590 ++b1; 10591 } 10592 10593 word = 0; 10594 word += (b1 << 16); 10595 word += (b2 << 8); 10596 word += b3; 10597 } 10598 else 10599 { 10600 word += (0x01 << 24); 10601 } 10602 return word; 10603 } 10604 10605 function incCounter(counter) 10606 { 10607 if ((counter[0] = incWord(counter[0])) === 0) 10608 { 10609 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 10610 counter[1] = incWord(counter[1]); 10611 } 10612 return counter; 10613 } 10614 10615 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 10616 processBlock: function (words, offset) { 10617 // Shortcuts 10618 var cipher = this._cipher 10619 var blockSize = cipher.blockSize; 10620 var iv = this._iv; 10621 var counter = this._counter; 10622 10623 // Generate keystream 10624 if (iv) { 10625 counter = this._counter = iv.slice(0); 10626 10627 // Remove IV for subsequent blocks 10628 this._iv = undefined; 10629 } 10630 10631 incCounter(counter); 10632 10633 var keystream = counter.slice(0); 10634 cipher.encryptBlock(keystream, 0); 10635 10636 // Encrypt 10637 for (var i = 0; i < blockSize; i++) { 10638 words[offset + i] ^= keystream[i]; 10639 } 10640 } 10641 }); 10642 10643 CTRGladman.Decryptor = Encryptor; 10644 10645 return CTRGladman; 10646 }()); 10647 10648 10649 10650 10651 return CryptoJS.mode.CTRGladman; 10652 10653 })); 10654 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 10655 ;(function (root, factory, undef) { 10656 if (typeof exports === "object") { 10657 // CommonJS 10658 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10659 } 10660 else if (typeof define === "function" && define.amd) { 10661 // AMD 10662 define(["./core", "./cipher-core"], factory); 10663 } 10664 else { 10665 // Global (browser) 10666 factory(root.CryptoJS); 10667 } 10668 }(this, function (CryptoJS) { 10669 10670 /** 10671 * Counter block mode. 10672 */ 10673 CryptoJS.mode.CTR = (function () { 10674 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 10675 10676 var Encryptor = CTR.Encryptor = CTR.extend({ 10677 processBlock: function (words, offset) { 10678 // Shortcuts 10679 var cipher = this._cipher 10680 var blockSize = cipher.blockSize; 10681 var iv = this._iv; 10682 var counter = this._counter; 10683 10684 // Generate keystream 10685 if (iv) { 10686 counter = this._counter = iv.slice(0); 10687 10688 // Remove IV for subsequent blocks 10689 this._iv = undefined; 10690 } 10691 var keystream = counter.slice(0); 10692 cipher.encryptBlock(keystream, 0); 10693 10694 // Increment counter 10695 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 10696 10697 // Encrypt 10698 for (var i = 0; i < blockSize; i++) { 10699 words[offset + i] ^= keystream[i]; 10700 } 10701 } 10702 }); 10703 10704 CTR.Decryptor = Encryptor; 10705 10706 return CTR; 10707 }()); 10708 10709 10710 return CryptoJS.mode.CTR; 10711 10712 })); 10713 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 10714 ;(function (root, factory, undef) { 10715 if (typeof exports === "object") { 10716 // CommonJS 10717 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10718 } 10719 else if (typeof define === "function" && define.amd) { 10720 // AMD 10721 define(["./core", "./cipher-core"], factory); 10722 } 10723 else { 10724 // Global (browser) 10725 factory(root.CryptoJS); 10726 } 10727 }(this, function (CryptoJS) { 10728 10729 /** 10730 * Electronic Codebook block mode. 10731 */ 10732 CryptoJS.mode.ECB = (function () { 10733 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 10734 10735 ECB.Encryptor = ECB.extend({ 10736 processBlock: function (words, offset) { 10737 this._cipher.encryptBlock(words, offset); 10738 } 10739 }); 10740 10741 ECB.Decryptor = ECB.extend({ 10742 processBlock: function (words, offset) { 10743 this._cipher.decryptBlock(words, offset); 10744 } 10745 }); 10746 10747 return ECB; 10748 }()); 10749 10750 10751 return CryptoJS.mode.ECB; 10752 10753 })); 10754 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 10755 ;(function (root, factory, undef) { 10756 if (typeof exports === "object") { 10757 // CommonJS 10758 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10759 } 10760 else if (typeof define === "function" && define.amd) { 10761 // AMD 10762 define(["./core", "./cipher-core"], factory); 10763 } 10764 else { 10765 // Global (browser) 10766 factory(root.CryptoJS); 10767 } 10768 }(this, function (CryptoJS) { 10769 10770 /** 10771 * Output Feedback block mode. 10772 */ 10773 CryptoJS.mode.OFB = (function () { 10774 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 10775 10776 var Encryptor = OFB.Encryptor = OFB.extend({ 10777 processBlock: function (words, offset) { 10778 // Shortcuts 10779 var cipher = this._cipher 10780 var blockSize = cipher.blockSize; 10781 var iv = this._iv; 10782 var keystream = this._keystream; 10783 10784 // Generate keystream 10785 if (iv) { 10786 keystream = this._keystream = iv.slice(0); 10787 10788 // Remove IV for subsequent blocks 10789 this._iv = undefined; 10790 } 10791 cipher.encryptBlock(keystream, 0); 10792 10793 // Encrypt 10794 for (var i = 0; i < blockSize; i++) { 10795 words[offset + i] ^= keystream[i]; 10796 } 10797 } 10798 }); 10799 10800 OFB.Decryptor = Encryptor; 10801 10802 return OFB; 10803 }()); 10804 10805 10806 return CryptoJS.mode.OFB; 10807 10808 })); 10809 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 10810 ;(function (root, factory, undef) { 10811 if (typeof exports === "object") { 10812 // CommonJS 10813 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10814 } 10815 else if (typeof define === "function" && define.amd) { 10816 // AMD 10817 define(["./core", "./cipher-core"], factory); 10818 } 10819 else { 10820 // Global (browser) 10821 factory(root.CryptoJS); 10822 } 10823 }(this, function (CryptoJS) { 10824 10825 /** 10826 * ANSI X.923 padding strategy. 10827 */ 10828 CryptoJS.pad.AnsiX923 = { 10829 pad: function (data, blockSize) { 10830 // Shortcuts 10831 var dataSigBytes = data.sigBytes; 10832 var blockSizeBytes = blockSize * 4; 10833 10834 // Count padding bytes 10835 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10836 10837 // Compute last byte position 10838 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10839 10840 // Pad 10841 data.clamp(); 10842 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10843 data.sigBytes += nPaddingBytes; 10844 }, 10845 10846 unpad: function (data) { 10847 // Get number of padding bytes from last byte 10848 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10849 10850 // Remove padding 10851 data.sigBytes -= nPaddingBytes; 10852 } 10853 }; 10854 10855 10856 return CryptoJS.pad.Ansix923; 10857 10858 })); 10859 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 10860 ;(function (root, factory, undef) { 10861 if (typeof exports === "object") { 10862 // CommonJS 10863 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10864 } 10865 else if (typeof define === "function" && define.amd) { 10866 // AMD 10867 define(["./core", "./cipher-core"], factory); 10868 } 10869 else { 10870 // Global (browser) 10871 factory(root.CryptoJS); 10872 } 10873 }(this, function (CryptoJS) { 10874 10875 /** 10876 * ISO 10126 padding strategy. 10877 */ 10878 CryptoJS.pad.Iso10126 = { 10879 pad: function (data, blockSize) { 10880 // Shortcut 10881 var blockSizeBytes = blockSize * 4; 10882 10883 // Count padding bytes 10884 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10885 10886 // Pad 10887 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10888 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10889 }, 10890 10891 unpad: function (data) { 10892 // Get number of padding bytes from last byte 10893 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10894 10895 // Remove padding 10896 data.sigBytes -= nPaddingBytes; 10897 } 10898 }; 10899 10900 10901 return CryptoJS.pad.Iso10126; 10902 10903 })); 10904 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 10905 ;(function (root, factory, undef) { 10906 if (typeof exports === "object") { 10907 // CommonJS 10908 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10909 } 10910 else if (typeof define === "function" && define.amd) { 10911 // AMD 10912 define(["./core", "./cipher-core"], factory); 10913 } 10914 else { 10915 // Global (browser) 10916 factory(root.CryptoJS); 10917 } 10918 }(this, function (CryptoJS) { 10919 10920 /** 10921 * ISO/IEC 9797-1 Padding Method 2. 10922 */ 10923 CryptoJS.pad.Iso97971 = { 10924 pad: function (data, blockSize) { 10925 // Add 0x80 byte 10926 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10927 10928 // Zero pad the rest 10929 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10930 }, 10931 10932 unpad: function (data) { 10933 // Remove zero padding 10934 CryptoJS.pad.ZeroPadding.unpad(data); 10935 10936 // Remove one more byte -- the 0x80 byte 10937 data.sigBytes--; 10938 } 10939 }; 10940 10941 10942 return CryptoJS.pad.Iso97971; 10943 10944 })); 10945 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 10946 ;(function (root, factory, undef) { 10947 if (typeof exports === "object") { 10948 // CommonJS 10949 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10950 } 10951 else if (typeof define === "function" && define.amd) { 10952 // AMD 10953 define(["./core", "./cipher-core"], factory); 10954 } 10955 else { 10956 // Global (browser) 10957 factory(root.CryptoJS); 10958 } 10959 }(this, function (CryptoJS) { 10960 10961 /** 10962 * A noop padding strategy. 10963 */ 10964 CryptoJS.pad.NoPadding = { 10965 pad: function () { 10966 }, 10967 10968 unpad: function () { 10969 } 10970 }; 10971 10972 10973 return CryptoJS.pad.NoPadding; 10974 10975 })); 10976 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 10977 ;(function (root, factory, undef) { 10978 if (typeof exports === "object") { 10979 // CommonJS 10980 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10981 } 10982 else if (typeof define === "function" && define.amd) { 10983 // AMD 10984 define(["./core", "./cipher-core"], factory); 10985 } 10986 else { 10987 // Global (browser) 10988 factory(root.CryptoJS); 10989 } 10990 }(this, function (CryptoJS) { 10991 10992 /** 10993 * Zero padding strategy. 10994 */ 10995 CryptoJS.pad.ZeroPadding = { 10996 pad: function (data, blockSize) { 10997 // Shortcut 10998 var blockSizeBytes = blockSize * 4; 10999 11000 // Pad 11001 data.clamp(); 11002 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 11003 }, 11004 11005 unpad: function (data) { 11006 // Shortcut 11007 var dataWords = data.words; 11008 11009 // Unpad 11010 var i = data.sigBytes - 1; 11011 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 11012 i--; 11013 } 11014 data.sigBytes = i + 1; 11015 } 11016 }; 11017 11018 11019 return CryptoJS.pad.ZeroPadding; 11020 11021 })); 11022 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 11023 ;(function (root, factory, undef) { 11024 if (typeof exports === "object") { 11025 // CommonJS 11026 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 11027 } 11028 else if (typeof define === "function" && define.amd) { 11029 // AMD 11030 define(["./core", "./sha1", "./hmac"], factory); 11031 } 11032 else { 11033 // Global (browser) 11034 factory(root.CryptoJS); 11035 } 11036 }(this, function (CryptoJS) { 11037 11038 (function () { 11039 // Shortcuts 11040 var C = CryptoJS; 11041 var C_lib = C.lib; 11042 var Base = C_lib.Base; 11043 var WordArray = C_lib.WordArray; 11044 var C_algo = C.algo; 11045 var SHA1 = C_algo.SHA1; 11046 var HMAC = C_algo.HMAC; 11047 11048 /** 11049 * Password-Based Key Derivation Function 2 algorithm. 11050 */ 11051 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 11052 /** 11053 * Configuration options. 11054 * 11055 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 11056 * @property {Hasher} hasher The hasher to use. Default: SHA1 11057 * @property {number} iterations The number of iterations to perform. Default: 1 11058 */ 11059 cfg: Base.extend({ 11060 keySize: 128/32, 11061 hasher: SHA1, 11062 iterations: 1 11063 }), 11064 11065 /** 11066 * Initializes a newly created key derivation function. 11067 * 11068 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 11069 * 11070 * @example 11071 * 11072 * var kdf = CryptoJS.algo.PBKDF2.create(); 11073 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 11074 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 11075 */ 11076 init: function (cfg) { 11077 this.cfg = this.cfg.extend(cfg); 11078 }, 11079 11080 /** 11081 * Computes the Password-Based Key Derivation Function 2. 11082 * 11083 * @param {WordArray|string} password The password. 11084 * @param {WordArray|string} salt A salt. 11085 * 11086 * @return {WordArray} The derived key. 11087 * 11088 * @example 11089 * 11090 * var key = kdf.compute(password, salt); 11091 */ 11092 compute: function (password, salt) { 11093 // Shortcut 11094 var cfg = this.cfg; 11095 11096 // Init HMAC 11097 var hmac = HMAC.create(cfg.hasher, password); 11098 11099 // Initial values 11100 var derivedKey = WordArray.create(); 11101 var blockIndex = WordArray.create([0x00000001]); 11102 11103 // Shortcuts 11104 var derivedKeyWords = derivedKey.words; 11105 var blockIndexWords = blockIndex.words; 11106 var keySize = cfg.keySize; 11107 var iterations = cfg.iterations; 11108 11109 // Generate key 11110 while (derivedKeyWords.length < keySize) { 11111 var block = hmac.update(salt).finalize(blockIndex); 11112 hmac.reset(); 11113 11114 // Shortcuts 11115 var blockWords = block.words; 11116 var blockWordsLength = blockWords.length; 11117 11118 // Iterations 11119 var intermediate = block; 11120 for (var i = 1; i < iterations; i++) { 11121 intermediate = hmac.finalize(intermediate); 11122 hmac.reset(); 11123 11124 // Shortcut 11125 var intermediateWords = intermediate.words; 11126 11127 // XOR intermediate with block 11128 for (var j = 0; j < blockWordsLength; j++) { 11129 blockWords[j] ^= intermediateWords[j]; 11130 } 11131 } 11132 11133 derivedKey.concat(block); 11134 blockIndexWords[0]++; 11135 } 11136 derivedKey.sigBytes = keySize * 4; 11137 11138 return derivedKey; 11139 } 11140 }); 11141 11142 /** 11143 * Computes the Password-Based Key Derivation Function 2. 11144 * 11145 * @param {WordArray|string} password The password. 11146 * @param {WordArray|string} salt A salt. 11147 * @param {Object} cfg (Optional) The configuration options to use for this computation. 11148 * 11149 * @return {WordArray} The derived key. 11150 * 11151 * @static 11152 * 11153 * @example 11154 * 11155 * var key = CryptoJS.PBKDF2(password, salt); 11156 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 11157 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 11158 */ 11159 C.PBKDF2 = function (password, salt, cfg) { 11160 return PBKDF2.create(cfg).compute(password, salt); 11161 }; 11162 }()); 11163 11164 11165 return CryptoJS.PBKDF2; 11166 11167 })); 11168 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 11169 ;(function (root, factory, undef) { 11170 if (typeof exports === "object") { 11171 // CommonJS 11172 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 11173 } 11174 else if (typeof define === "function" && define.amd) { 11175 // AMD 11176 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 11177 } 11178 else { 11179 // Global (browser) 11180 factory(root.CryptoJS); 11181 } 11182 }(this, function (CryptoJS) { 11183 11184 (function () { 11185 // Shortcuts 11186 var C = CryptoJS; 11187 var C_lib = C.lib; 11188 var StreamCipher = C_lib.StreamCipher; 11189 var C_algo = C.algo; 11190 11191 // Reusable objects 11192 var S = []; 11193 var C_ = []; 11194 var G = []; 11195 11196 /** 11197 * Rabbit stream cipher algorithm. 11198 * 11199 * This is a legacy version that neglected to convert the key to little-endian. 11200 * This error doesn't affect the cipher's security, 11201 * but it does affect its compatibility with other implementations. 11202 */ 11203 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 11204 _doReset: function () { 11205 // Shortcuts 11206 var K = this._key.words; 11207 var iv = this.cfg.iv; 11208 11209 // Generate initial state values 11210 var X = this._X = [ 11211 K[0], (K[3] << 16) | (K[2] >>> 16), 11212 K[1], (K[0] << 16) | (K[3] >>> 16), 11213 K[2], (K[1] << 16) | (K[0] >>> 16), 11214 K[3], (K[2] << 16) | (K[1] >>> 16) 11215 ]; 11216 11217 // Generate initial counter values 11218 var C = this._C = [ 11219 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 11220 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 11221 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 11222 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 11223 ]; 11224 11225 // Carry bit 11226 this._b = 0; 11227 11228 // Iterate the system four times 11229 for (var i = 0; i < 4; i++) { 11230 nextState.call(this); 11231 } 11232 11233 // Modify the counters 11234 for (var i = 0; i < 8; i++) { 11235 C[i] ^= X[(i + 4) & 7]; 11236 } 11237 11238 // IV setup 11239 if (iv) { 11240 // Shortcuts 11241 var IV = iv.words; 11242 var IV_0 = IV[0]; 11243 var IV_1 = IV[1]; 11244 11245 // Generate four subvectors 11246 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 11247 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 11248 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 11249 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 11250 11251 // Modify counter values 11252 C[0] ^= i0; 11253 C[1] ^= i1; 11254 C[2] ^= i2; 11255 C[3] ^= i3; 11256 C[4] ^= i0; 11257 C[5] ^= i1; 11258 C[6] ^= i2; 11259 C[7] ^= i3; 11260 11261 // Iterate the system four times 11262 for (var i = 0; i < 4; i++) { 11263 nextState.call(this); 11264 } 11265 } 11266 }, 11267 11268 _doProcessBlock: function (M, offset) { 11269 // Shortcut 11270 var X = this._X; 11271 11272 // Iterate the system 11273 nextState.call(this); 11274 11275 // Generate four keystream words 11276 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 11277 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 11278 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 11279 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 11280 11281 for (var i = 0; i < 4; i++) { 11282 // Swap endian 11283 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 11284 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 11285 11286 // Encrypt 11287 M[offset + i] ^= S[i]; 11288 } 11289 }, 11290 11291 blockSize: 128/32, 11292 11293 ivSize: 64/32 11294 }); 11295 11296 function nextState() { 11297 // Shortcuts 11298 var X = this._X; 11299 var C = this._C; 11300 11301 // Save old counter values 11302 for (var i = 0; i < 8; i++) { 11303 C_[i] = C[i]; 11304 } 11305 11306 // Calculate new counter values 11307 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 11308 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 11309 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 11310 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 11311 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 11312 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 11313 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 11314 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 11315 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 11316 11317 // Calculate the g-values 11318 for (var i = 0; i < 8; i++) { 11319 var gx = X[i] + C[i]; 11320 11321 // Construct high and low argument for squaring 11322 var ga = gx & 0xffff; 11323 var gb = gx >>> 16; 11324 11325 // Calculate high and low result of squaring 11326 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 11327 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 11328 11329 // High XOR low 11330 G[i] = gh ^ gl; 11331 } 11332 11333 // Calculate new state values 11334 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 11335 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 11336 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 11337 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 11338 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 11339 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 11340 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 11341 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 11342 } 11343 11344 /** 11345 * Shortcut functions to the cipher's object interface. 11346 * 11347 * @example 11348 * 11349 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 11350 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 11351 */ 11352 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 11353 }()); 11354 11355 11356 return CryptoJS.RabbitLegacy; 11357 11358 })); 11359 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 11360 ;(function (root, factory, undef) { 11361 if (typeof exports === "object") { 11362 // CommonJS 11363 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 11364 } 11365 else if (typeof define === "function" && define.amd) { 11366 // AMD 11367 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 11368 } 11369 else { 11370 // Global (browser) 11371 factory(root.CryptoJS); 11372 } 11373 }(this, function (CryptoJS) { 11374 11375 (function () { 11376 // Shortcuts 11377 var C = CryptoJS; 11378 var C_lib = C.lib; 11379 var StreamCipher = C_lib.StreamCipher; 11380 var C_algo = C.algo; 11381 11382 // Reusable objects 11383 var S = []; 11384 var C_ = []; 11385 var G = []; 11386 11387 /** 11388 * Rabbit stream cipher algorithm 11389 */ 11390 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 11391 _doReset: function () { 11392 // Shortcuts 11393 var K = this._key.words; 11394 var iv = this.cfg.iv; 11395 11396 // Swap endian 11397 for (var i = 0; i < 4; i++) { 11398 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 11399 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 11400 } 11401 11402 // Generate initial state values 11403 var X = this._X = [ 11404 K[0], (K[3] << 16) | (K[2] >>> 16), 11405 K[1], (K[0] << 16) | (K[3] >>> 16), 11406 K[2], (K[1] << 16) | (K[0] >>> 16), 11407 K[3], (K[2] << 16) | (K[1] >>> 16) 11408 ]; 11409 11410 // Generate initial counter values 11411 var C = this._C = [ 11412 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 11413 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 11414 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 11415 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 11416 ]; 11417 11418 // Carry bit 11419 this._b = 0; 11420 11421 // Iterate the system four times 11422 for (var i = 0; i < 4; i++) { 11423 nextState.call(this); 11424 } 11425 11426 // Modify the counters 11427 for (var i = 0; i < 8; i++) { 11428 C[i] ^= X[(i + 4) & 7]; 11429 } 11430 11431 // IV setup 11432 if (iv) { 11433 // Shortcuts 11434 var IV = iv.words; 11435 var IV_0 = IV[0]; 11436 var IV_1 = IV[1]; 11437 11438 // Generate four subvectors 11439 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 11440 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 11441 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 11442 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 11443 11444 // Modify counter values 11445 C[0] ^= i0; 11446 C[1] ^= i1; 11447 C[2] ^= i2; 11448 C[3] ^= i3; 11449 C[4] ^= i0; 11450 C[5] ^= i1; 11451 C[6] ^= i2; 11452 C[7] ^= i3; 11453 11454 // Iterate the system four times 11455 for (var i = 0; i < 4; i++) { 11456 nextState.call(this); 11457 } 11458 } 11459 }, 11460 11461 _doProcessBlock: function (M, offset) { 11462 // Shortcut 11463 var X = this._X; 11464 11465 // Iterate the system 11466 nextState.call(this); 11467 11468 // Generate four keystream words 11469 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 11470 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 11471 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 11472 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 11473 11474 for (var i = 0; i < 4; i++) { 11475 // Swap endian 11476 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 11477 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 11478 11479 // Encrypt 11480 M[offset + i] ^= S[i]; 11481 } 11482 }, 11483 11484 blockSize: 128/32, 11485 11486 ivSize: 64/32 11487 }); 11488 11489 function nextState() { 11490 // Shortcuts 11491 var X = this._X; 11492 var C = this._C; 11493 11494 // Save old counter values 11495 for (var i = 0; i < 8; i++) { 11496 C_[i] = C[i]; 11497 } 11498 11499 // Calculate new counter values 11500 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 11501 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 11502 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 11503 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 11504 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 11505 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 11506 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 11507 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 11508 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 11509 11510 // Calculate the g-values 11511 for (var i = 0; i < 8; i++) { 11512 var gx = X[i] + C[i]; 11513 11514 // Construct high and low argument for squaring 11515 var ga = gx & 0xffff; 11516 var gb = gx >>> 16; 11517 11518 // Calculate high and low result of squaring 11519 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 11520 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 11521 11522 // High XOR low 11523 G[i] = gh ^ gl; 11524 } 11525 11526 // Calculate new state values 11527 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 11528 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 11529 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 11530 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 11531 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 11532 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 11533 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 11534 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 11535 } 11536 11537 /** 11538 * Shortcut functions to the cipher's object interface. 11539 * 11540 * @example 11541 * 11542 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 11543 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 11544 */ 11545 C.Rabbit = StreamCipher._createHelper(Rabbit); 11546 }()); 11547 11548 11549 return CryptoJS.Rabbit; 11550 11551 })); 11552 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 11553 ;(function (root, factory, undef) { 11554 if (typeof exports === "object") { 11555 // CommonJS 11556 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 11557 } 11558 else if (typeof define === "function" && define.amd) { 11559 // AMD 11560 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 11561 } 11562 else { 11563 // Global (browser) 11564 factory(root.CryptoJS); 11565 } 11566 }(this, function (CryptoJS) { 11567 11568 (function () { 11569 // Shortcuts 11570 var C = CryptoJS; 11571 var C_lib = C.lib; 11572 var StreamCipher = C_lib.StreamCipher; 11573 var C_algo = C.algo; 11574 11575 /** 11576 * RC4 stream cipher algorithm. 11577 */ 11578 var RC4 = C_algo.RC4 = StreamCipher.extend({ 11579 _doReset: function () { 11580 // Shortcuts 11581 var key = this._key; 11582 var keyWords = key.words; 11583 var keySigBytes = key.sigBytes; 11584 11585 // Init sbox 11586 var S = this._S = []; 11587 for (var i = 0; i < 256; i++) { 11588 S[i] = i; 11589 } 11590 11591 // Key setup 11592 for (var i = 0, j = 0; i < 256; i++) { 11593 var keyByteIndex = i % keySigBytes; 11594 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 11595 11596 j = (j + S[i] + keyByte) % 256; 11597 11598 // Swap 11599 var t = S[i]; 11600 S[i] = S[j]; 11601 S[j] = t; 11602 } 11603 11604 // Counters 11605 this._i = this._j = 0; 11606 }, 11607 11608 _doProcessBlock: function (M, offset) { 11609 M[offset] ^= generateKeystreamWord.call(this); 11610 }, 11611 11612 keySize: 256/32, 11613 11614 ivSize: 0 11615 }); 11616 11617 function generateKeystreamWord() { 11618 // Shortcuts 11619 var S = this._S; 11620 var i = this._i; 11621 var j = this._j; 11622 11623 // Generate keystream word 11624 var keystreamWord = 0; 11625 for (var n = 0; n < 4; n++) { 11626 i = (i + 1) % 256; 11627 j = (j + S[i]) % 256; 11628 11629 // Swap 11630 var t = S[i]; 11631 S[i] = S[j]; 11632 S[j] = t; 11633 11634 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 11635 } 11636 11637 // Update counters 11638 this._i = i; 11639 this._j = j; 11640 11641 return keystreamWord; 11642 } 11643 11644 /** 11645 * Shortcut functions to the cipher's object interface. 11646 * 11647 * @example 11648 * 11649 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 11650 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 11651 */ 11652 C.RC4 = StreamCipher._createHelper(RC4); 11653 11654 /** 11655 * Modified RC4 stream cipher algorithm. 11656 */ 11657 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 11658 /** 11659 * Configuration options. 11660 * 11661 * @property {number} drop The number of keystream words to drop. Default 192 11662 */ 11663 cfg: RC4.cfg.extend({ 11664 drop: 192 11665 }), 11666 11667 _doReset: function () { 11668 RC4._doReset.call(this); 11669 11670 // Drop 11671 for (var i = this.cfg.drop; i > 0; i--) { 11672 generateKeystreamWord.call(this); 11673 } 11674 } 11675 }); 11676 11677 /** 11678 * Shortcut functions to the cipher's object interface. 11679 * 11680 * @example 11681 * 11682 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 11683 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 11684 */ 11685 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 11686 }()); 11687 11688 11689 return CryptoJS.RC4; 11690 11691 })); 11692 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 11693 ;(function (root, factory) { 11694 if (typeof exports === "object") { 11695 // CommonJS 11696 module.exports = exports = factory(require("./core")); 11697 } 11698 else if (typeof define === "function" && define.amd) { 11699 // AMD 11700 define(["./core"], factory); 11701 } 11702 else { 11703 // Global (browser) 11704 factory(root.CryptoJS); 11705 } 11706 }(this, function (CryptoJS) { 11707 11708 /** @preserve 11709 (c) 2012 by Cédric Mesnil. All rights reserved. 11710 11711 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 11712 11713 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11714 - 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. 11715 11716 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11717 */ 11718 11719 (function (Math) { 11720 // Shortcuts 11721 var C = CryptoJS; 11722 var C_lib = C.lib; 11723 var WordArray = C_lib.WordArray; 11724 var Hasher = C_lib.Hasher; 11725 var C_algo = C.algo; 11726 11727 // Constants table 11728 var _zl = WordArray.create([ 11729 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 11730 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 11731 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 11732 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 11733 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 11734 var _zr = WordArray.create([ 11735 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 11736 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 11737 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 11738 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 11739 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 11740 var _sl = WordArray.create([ 11741 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 11742 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11743 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11744 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 11745 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 11746 var _sr = WordArray.create([ 11747 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 11748 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 11749 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 11750 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 11751 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 11752 11753 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 11754 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 11755 11756 /** 11757 * RIPEMD160 hash algorithm. 11758 */ 11759 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 11760 _doReset: function () { 11761 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 11762 }, 11763 11764 _doProcessBlock: function (M, offset) { 11765 11766 // Swap endian 11767 for (var i = 0; i < 16; i++) { 11768 // Shortcuts 11769 var offset_i = offset + i; 11770 var M_offset_i = M[offset_i]; 11771 11772 // Swap 11773 M[offset_i] = ( 11774 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 11775 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 11776 ); 11777 } 11778 // Shortcut 11779 var H = this._hash.words; 11780 var hl = _hl.words; 11781 var hr = _hr.words; 11782 var zl = _zl.words; 11783 var zr = _zr.words; 11784 var sl = _sl.words; 11785 var sr = _sr.words; 11786 11787 // Working variables 11788 var al, bl, cl, dl, el; 11789 var ar, br, cr, dr, er; 11790 11791 ar = al = H[0]; 11792 br = bl = H[1]; 11793 cr = cl = H[2]; 11794 dr = dl = H[3]; 11795 er = el = H[4]; 11796 // Computation 11797 var t; 11798 for (var i = 0; i < 80; i += 1) { 11799 t = (al + M[offset+zl[i]])|0; 11800 if (i<16){ 11801 t += f1(bl,cl,dl) + hl[0]; 11802 } else if (i<32) { 11803 t += f2(bl,cl,dl) + hl[1]; 11804 } else if (i<48) { 11805 t += f3(bl,cl,dl) + hl[2]; 11806 } else if (i<64) { 11807 t += f4(bl,cl,dl) + hl[3]; 11808 } else {// if (i<80) { 11809 t += f5(bl,cl,dl) + hl[4]; 11810 } 11811 t = t|0; 11812 t = rotl(t,sl[i]); 11813 t = (t+el)|0; 11814 al = el; 11815 el = dl; 11816 dl = rotl(cl, 10); 11817 cl = bl; 11818 bl = t; 11819 11820 t = (ar + M[offset+zr[i]])|0; 11821 if (i<16){ 11822 t += f5(br,cr,dr) + hr[0]; 11823 } else if (i<32) { 11824 t += f4(br,cr,dr) + hr[1]; 11825 } else if (i<48) { 11826 t += f3(br,cr,dr) + hr[2]; 11827 } else if (i<64) { 11828 t += f2(br,cr,dr) + hr[3]; 11829 } else {// if (i<80) { 11830 t += f1(br,cr,dr) + hr[4]; 11831 } 11832 t = t|0; 11833 t = rotl(t,sr[i]) ; 11834 t = (t+er)|0; 11835 ar = er; 11836 er = dr; 11837 dr = rotl(cr, 10); 11838 cr = br; 11839 br = t; 11840 } 11841 // Intermediate hash value 11842 t = (H[1] + cl + dr)|0; 11843 H[1] = (H[2] + dl + er)|0; 11844 H[2] = (H[3] + el + ar)|0; 11845 H[3] = (H[4] + al + br)|0; 11846 H[4] = (H[0] + bl + cr)|0; 11847 H[0] = t; 11848 }, 11849 11850 _doFinalize: function () { 11851 // Shortcuts 11852 var data = this._data; 11853 var dataWords = data.words; 11854 11855 var nBitsTotal = this._nDataBytes * 8; 11856 var nBitsLeft = data.sigBytes * 8; 11857 11858 // Add padding 11859 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11860 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11861 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11862 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11863 ); 11864 data.sigBytes = (dataWords.length + 1) * 4; 11865 11866 // Hash final blocks 11867 this._process(); 11868 11869 // Shortcuts 11870 var hash = this._hash; 11871 var H = hash.words; 11872 11873 // Swap endian 11874 for (var i = 0; i < 5; i++) { 11875 // Shortcut 11876 var H_i = H[i]; 11877 11878 // Swap 11879 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11880 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11881 } 11882 11883 // Return final computed hash 11884 return hash; 11885 }, 11886 11887 clone: function () { 11888 var clone = Hasher.clone.call(this); 11889 clone._hash = this._hash.clone(); 11890 11891 return clone; 11892 } 11893 }); 11894 11895 11896 function f1(x, y, z) { 11897 return ((x) ^ (y) ^ (z)); 11898 11899 } 11900 11901 function f2(x, y, z) { 11902 return (((x)&(y)) | ((~x)&(z))); 11903 } 11904 11905 function f3(x, y, z) { 11906 return (((x) | (~(y))) ^ (z)); 11907 } 11908 11909 function f4(x, y, z) { 11910 return (((x) & (z)) | ((y)&(~(z)))); 11911 } 11912 11913 function f5(x, y, z) { 11914 return ((x) ^ ((y) |(~(z)))); 11915 11916 } 11917 11918 function rotl(x,n) { 11919 return (x<<n) | (x>>>(32-n)); 11920 } 11921 11922 11923 /** 11924 * Shortcut function to the hasher's object interface. 11925 * 11926 * @param {WordArray|string} message The message to hash. 11927 * 11928 * @return {WordArray} The hash. 11929 * 11930 * @static 11931 * 11932 * @example 11933 * 11934 * var hash = CryptoJS.RIPEMD160('message'); 11935 * var hash = CryptoJS.RIPEMD160(wordArray); 11936 */ 11937 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11938 11939 /** 11940 * Shortcut function to the HMAC's object interface. 11941 * 11942 * @param {WordArray|string} message The message to hash. 11943 * @param {WordArray|string} key The secret key. 11944 * 11945 * @return {WordArray} The HMAC. 11946 * 11947 * @static 11948 * 11949 * @example 11950 * 11951 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11952 */ 11953 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11954 }(Math)); 11955 11956 11957 return CryptoJS.RIPEMD160; 11958 11959 })); 11960 },{"./core":53}],77:[function(require,module,exports){ 11961 ;(function (root, factory) { 11962 if (typeof exports === "object") { 11963 // CommonJS 11964 module.exports = exports = factory(require("./core")); 11965 } 11966 else if (typeof define === "function" && define.amd) { 11967 // AMD 11968 define(["./core"], factory); 11969 } 11970 else { 11971 // Global (browser) 11972 factory(root.CryptoJS); 11973 } 11974 }(this, function (CryptoJS) { 11975 11976 (function () { 11977 // Shortcuts 11978 var C = CryptoJS; 11979 var C_lib = C.lib; 11980 var WordArray = C_lib.WordArray; 11981 var Hasher = C_lib.Hasher; 11982 var C_algo = C.algo; 11983 11984 // Reusable object 11985 var W = []; 11986 11987 /** 11988 * SHA-1 hash algorithm. 11989 */ 11990 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11991 _doReset: function () { 11992 this._hash = new WordArray.init([ 11993 0x67452301, 0xefcdab89, 11994 0x98badcfe, 0x10325476, 11995 0xc3d2e1f0 11996 ]); 11997 }, 11998 11999 _doProcessBlock: function (M, offset) { 12000 // Shortcut 12001 var H = this._hash.words; 12002 12003 // Working variables 12004 var a = H[0]; 12005 var b = H[1]; 12006 var c = H[2]; 12007 var d = H[3]; 12008 var e = H[4]; 12009 12010 // Computation 12011 for (var i = 0; i < 80; i++) { 12012 if (i < 16) { 12013 W[i] = M[offset + i] | 0; 12014 } else { 12015 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 12016 W[i] = (n << 1) | (n >>> 31); 12017 } 12018 12019 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 12020 if (i < 20) { 12021 t += ((b & c) | (~b & d)) + 0x5a827999; 12022 } else if (i < 40) { 12023 t += (b ^ c ^ d) + 0x6ed9eba1; 12024 } else if (i < 60) { 12025 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 12026 } else /* if (i < 80) */ { 12027 t += (b ^ c ^ d) - 0x359d3e2a; 12028 } 12029 12030 e = d; 12031 d = c; 12032 c = (b << 30) | (b >>> 2); 12033 b = a; 12034 a = t; 12035 } 12036 12037 // Intermediate hash value 12038 H[0] = (H[0] + a) | 0; 12039 H[1] = (H[1] + b) | 0; 12040 H[2] = (H[2] + c) | 0; 12041 H[3] = (H[3] + d) | 0; 12042 H[4] = (H[4] + e) | 0; 12043 }, 12044 12045 _doFinalize: function () { 12046 // Shortcuts 12047 var data = this._data; 12048 var dataWords = data.words; 12049 12050 var nBitsTotal = this._nDataBytes * 8; 12051 var nBitsLeft = data.sigBytes * 8; 12052 12053 // Add padding 12054 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12055 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 12056 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 12057 data.sigBytes = dataWords.length * 4; 12058 12059 // Hash final blocks 12060 this._process(); 12061 12062 // Return final computed hash 12063 return this._hash; 12064 }, 12065 12066 clone: function () { 12067 var clone = Hasher.clone.call(this); 12068 clone._hash = this._hash.clone(); 12069 12070 return clone; 12071 } 12072 }); 12073 12074 /** 12075 * Shortcut function to the hasher's object interface. 12076 * 12077 * @param {WordArray|string} message The message to hash. 12078 * 12079 * @return {WordArray} The hash. 12080 * 12081 * @static 12082 * 12083 * @example 12084 * 12085 * var hash = CryptoJS.SHA1('message'); 12086 * var hash = CryptoJS.SHA1(wordArray); 12087 */ 12088 C.SHA1 = Hasher._createHelper(SHA1); 12089 12090 /** 12091 * Shortcut function to the HMAC's object interface. 12092 * 12093 * @param {WordArray|string} message The message to hash. 12094 * @param {WordArray|string} key The secret key. 12095 * 12096 * @return {WordArray} The HMAC. 12097 * 12098 * @static 12099 * 12100 * @example 12101 * 12102 * var hmac = CryptoJS.HmacSHA1(message, key); 12103 */ 12104 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 12105 }()); 12106 12107 12108 return CryptoJS.SHA1; 12109 12110 })); 12111 },{"./core":53}],78:[function(require,module,exports){ 12112 ;(function (root, factory, undef) { 12113 if (typeof exports === "object") { 12114 // CommonJS 12115 module.exports = exports = factory(require("./core"), require("./sha256")); 12116 } 12117 else if (typeof define === "function" && define.amd) { 12118 // AMD 12119 define(["./core", "./sha256"], factory); 12120 } 12121 else { 12122 // Global (browser) 12123 factory(root.CryptoJS); 12124 } 12125 }(this, function (CryptoJS) { 12126 12127 (function () { 12128 // Shortcuts 12129 var C = CryptoJS; 12130 var C_lib = C.lib; 12131 var WordArray = C_lib.WordArray; 12132 var C_algo = C.algo; 12133 var SHA256 = C_algo.SHA256; 12134 12135 /** 12136 * SHA-224 hash algorithm. 12137 */ 12138 var SHA224 = C_algo.SHA224 = SHA256.extend({ 12139 _doReset: function () { 12140 this._hash = new WordArray.init([ 12141 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 12142 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 12143 ]); 12144 }, 12145 12146 _doFinalize: function () { 12147 var hash = SHA256._doFinalize.call(this); 12148 12149 hash.sigBytes -= 4; 12150 12151 return hash; 12152 } 12153 }); 12154 12155 /** 12156 * Shortcut function to the hasher's object interface. 12157 * 12158 * @param {WordArray|string} message The message to hash. 12159 * 12160 * @return {WordArray} The hash. 12161 * 12162 * @static 12163 * 12164 * @example 12165 * 12166 * var hash = CryptoJS.SHA224('message'); 12167 * var hash = CryptoJS.SHA224(wordArray); 12168 */ 12169 C.SHA224 = SHA256._createHelper(SHA224); 12170 12171 /** 12172 * Shortcut function to the HMAC's object interface. 12173 * 12174 * @param {WordArray|string} message The message to hash. 12175 * @param {WordArray|string} key The secret key. 12176 * 12177 * @return {WordArray} The HMAC. 12178 * 12179 * @static 12180 * 12181 * @example 12182 * 12183 * var hmac = CryptoJS.HmacSHA224(message, key); 12184 */ 12185 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 12186 }()); 12187 12188 12189 return CryptoJS.SHA224; 12190 12191 })); 12192 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 12193 ;(function (root, factory) { 12194 if (typeof exports === "object") { 12195 // CommonJS 12196 module.exports = exports = factory(require("./core")); 12197 } 12198 else if (typeof define === "function" && define.amd) { 12199 // AMD 12200 define(["./core"], factory); 12201 } 12202 else { 12203 // Global (browser) 12204 factory(root.CryptoJS); 12205 } 12206 }(this, function (CryptoJS) { 12207 12208 (function (Math) { 12209 // Shortcuts 12210 var C = CryptoJS; 12211 var C_lib = C.lib; 12212 var WordArray = C_lib.WordArray; 12213 var Hasher = C_lib.Hasher; 12214 var C_algo = C.algo; 12215 12216 // Initialization and round constants tables 12217 var H = []; 12218 var K = []; 12219 12220 // Compute constants 12221 (function () { 12222 function isPrime(n) { 12223 var sqrtN = Math.sqrt(n); 12224 for (var factor = 2; factor <= sqrtN; factor++) { 12225 if (!(n % factor)) { 12226 return false; 12227 } 12228 } 12229 12230 return true; 12231 } 12232 12233 function getFractionalBits(n) { 12234 return ((n - (n | 0)) * 0x100000000) | 0; 12235 } 12236 12237 var n = 2; 12238 var nPrime = 0; 12239 while (nPrime < 64) { 12240 if (isPrime(n)) { 12241 if (nPrime < 8) { 12242 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 12243 } 12244 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 12245 12246 nPrime++; 12247 } 12248 12249 n++; 12250 } 12251 }()); 12252 12253 // Reusable object 12254 var W = []; 12255 12256 /** 12257 * SHA-256 hash algorithm. 12258 */ 12259 var SHA256 = C_algo.SHA256 = Hasher.extend({ 12260 _doReset: function () { 12261 this._hash = new WordArray.init(H.slice(0)); 12262 }, 12263 12264 _doProcessBlock: function (M, offset) { 12265 // Shortcut 12266 var H = this._hash.words; 12267 12268 // Working variables 12269 var a = H[0]; 12270 var b = H[1]; 12271 var c = H[2]; 12272 var d = H[3]; 12273 var e = H[4]; 12274 var f = H[5]; 12275 var g = H[6]; 12276 var h = H[7]; 12277 12278 // Computation 12279 for (var i = 0; i < 64; i++) { 12280 if (i < 16) { 12281 W[i] = M[offset + i] | 0; 12282 } else { 12283 var gamma0x = W[i - 15]; 12284 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 12285 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 12286 (gamma0x >>> 3); 12287 12288 var gamma1x = W[i - 2]; 12289 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 12290 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 12291 (gamma1x >>> 10); 12292 12293 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 12294 } 12295 12296 var ch = (e & f) ^ (~e & g); 12297 var maj = (a & b) ^ (a & c) ^ (b & c); 12298 12299 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 12300 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 12301 12302 var t1 = h + sigma1 + ch + K[i] + W[i]; 12303 var t2 = sigma0 + maj; 12304 12305 h = g; 12306 g = f; 12307 f = e; 12308 e = (d + t1) | 0; 12309 d = c; 12310 c = b; 12311 b = a; 12312 a = (t1 + t2) | 0; 12313 } 12314 12315 // Intermediate hash value 12316 H[0] = (H[0] + a) | 0; 12317 H[1] = (H[1] + b) | 0; 12318 H[2] = (H[2] + c) | 0; 12319 H[3] = (H[3] + d) | 0; 12320 H[4] = (H[4] + e) | 0; 12321 H[5] = (H[5] + f) | 0; 12322 H[6] = (H[6] + g) | 0; 12323 H[7] = (H[7] + h) | 0; 12324 }, 12325 12326 _doFinalize: function () { 12327 // Shortcuts 12328 var data = this._data; 12329 var dataWords = data.words; 12330 12331 var nBitsTotal = this._nDataBytes * 8; 12332 var nBitsLeft = data.sigBytes * 8; 12333 12334 // Add padding 12335 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12336 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 12337 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 12338 data.sigBytes = dataWords.length * 4; 12339 12340 // Hash final blocks 12341 this._process(); 12342 12343 // Return final computed hash 12344 return this._hash; 12345 }, 12346 12347 clone: function () { 12348 var clone = Hasher.clone.call(this); 12349 clone._hash = this._hash.clone(); 12350 12351 return clone; 12352 } 12353 }); 12354 12355 /** 12356 * Shortcut function to the hasher's object interface. 12357 * 12358 * @param {WordArray|string} message The message to hash. 12359 * 12360 * @return {WordArray} The hash. 12361 * 12362 * @static 12363 * 12364 * @example 12365 * 12366 * var hash = CryptoJS.SHA256('message'); 12367 * var hash = CryptoJS.SHA256(wordArray); 12368 */ 12369 C.SHA256 = Hasher._createHelper(SHA256); 12370 12371 /** 12372 * Shortcut function to the HMAC's object interface. 12373 * 12374 * @param {WordArray|string} message The message to hash. 12375 * @param {WordArray|string} key The secret key. 12376 * 12377 * @return {WordArray} The HMAC. 12378 * 12379 * @static 12380 * 12381 * @example 12382 * 12383 * var hmac = CryptoJS.HmacSHA256(message, key); 12384 */ 12385 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 12386 }(Math)); 12387 12388 12389 return CryptoJS.SHA256; 12390 12391 })); 12392 },{"./core":53}],80:[function(require,module,exports){ 12393 ;(function (root, factory, undef) { 12394 if (typeof exports === "object") { 12395 // CommonJS 12396 module.exports = exports = factory(require("./core"), require("./x64-core")); 12397 } 12398 else if (typeof define === "function" && define.amd) { 12399 // AMD 12400 define(["./core", "./x64-core"], factory); 12401 } 12402 else { 12403 // Global (browser) 12404 factory(root.CryptoJS); 12405 } 12406 }(this, function (CryptoJS) { 12407 12408 (function (Math) { 12409 // Shortcuts 12410 var C = CryptoJS; 12411 var C_lib = C.lib; 12412 var WordArray = C_lib.WordArray; 12413 var Hasher = C_lib.Hasher; 12414 var C_x64 = C.x64; 12415 var X64Word = C_x64.Word; 12416 var C_algo = C.algo; 12417 12418 // Constants tables 12419 var RHO_OFFSETS = []; 12420 var PI_INDEXES = []; 12421 var ROUND_CONSTANTS = []; 12422 12423 // Compute Constants 12424 (function () { 12425 // Compute rho offset constants 12426 var x = 1, y = 0; 12427 for (var t = 0; t < 24; t++) { 12428 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 12429 12430 var newX = y % 5; 12431 var newY = (2 * x + 3 * y) % 5; 12432 x = newX; 12433 y = newY; 12434 } 12435 12436 // Compute pi index constants 12437 for (var x = 0; x < 5; x++) { 12438 for (var y = 0; y < 5; y++) { 12439 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 12440 } 12441 } 12442 12443 // Compute round constants 12444 var LFSR = 0x01; 12445 for (var i = 0; i < 24; i++) { 12446 var roundConstantMsw = 0; 12447 var roundConstantLsw = 0; 12448 12449 for (var j = 0; j < 7; j++) { 12450 if (LFSR & 0x01) { 12451 var bitPosition = (1 << j) - 1; 12452 if (bitPosition < 32) { 12453 roundConstantLsw ^= 1 << bitPosition; 12454 } else /* if (bitPosition >= 32) */ { 12455 roundConstantMsw ^= 1 << (bitPosition - 32); 12456 } 12457 } 12458 12459 // Compute next LFSR 12460 if (LFSR & 0x80) { 12461 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 12462 LFSR = (LFSR << 1) ^ 0x71; 12463 } else { 12464 LFSR <<= 1; 12465 } 12466 } 12467 12468 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 12469 } 12470 }()); 12471 12472 // Reusable objects for temporary values 12473 var T = []; 12474 (function () { 12475 for (var i = 0; i < 25; i++) { 12476 T[i] = X64Word.create(); 12477 } 12478 }()); 12479 12480 /** 12481 * SHA-3 hash algorithm. 12482 */ 12483 var SHA3 = C_algo.SHA3 = Hasher.extend({ 12484 /** 12485 * Configuration options. 12486 * 12487 * @property {number} outputLength 12488 * The desired number of bits in the output hash. 12489 * Only values permitted are: 224, 256, 384, 512. 12490 * Default: 512 12491 */ 12492 cfg: Hasher.cfg.extend({ 12493 outputLength: 512 12494 }), 12495 12496 _doReset: function () { 12497 var state = this._state = [] 12498 for (var i = 0; i < 25; i++) { 12499 state[i] = new X64Word.init(); 12500 } 12501 12502 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 12503 }, 12504 12505 _doProcessBlock: function (M, offset) { 12506 // Shortcuts 12507 var state = this._state; 12508 var nBlockSizeLanes = this.blockSize / 2; 12509 12510 // Absorb 12511 for (var i = 0; i < nBlockSizeLanes; i++) { 12512 // Shortcuts 12513 var M2i = M[offset + 2 * i]; 12514 var M2i1 = M[offset + 2 * i + 1]; 12515 12516 // Swap endian 12517 M2i = ( 12518 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 12519 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 12520 ); 12521 M2i1 = ( 12522 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 12523 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 12524 ); 12525 12526 // Absorb message into state 12527 var lane = state[i]; 12528 lane.high ^= M2i1; 12529 lane.low ^= M2i; 12530 } 12531 12532 // Rounds 12533 for (var round = 0; round < 24; round++) { 12534 // Theta 12535 for (var x = 0; x < 5; x++) { 12536 // Mix column lanes 12537 var tMsw = 0, tLsw = 0; 12538 for (var y = 0; y < 5; y++) { 12539 var lane = state[x + 5 * y]; 12540 tMsw ^= lane.high; 12541 tLsw ^= lane.low; 12542 } 12543 12544 // Temporary values 12545 var Tx = T[x]; 12546 Tx.high = tMsw; 12547 Tx.low = tLsw; 12548 } 12549 for (var x = 0; x < 5; x++) { 12550 // Shortcuts 12551 var Tx4 = T[(x + 4) % 5]; 12552 var Tx1 = T[(x + 1) % 5]; 12553 var Tx1Msw = Tx1.high; 12554 var Tx1Lsw = Tx1.low; 12555 12556 // Mix surrounding columns 12557 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 12558 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 12559 for (var y = 0; y < 5; y++) { 12560 var lane = state[x + 5 * y]; 12561 lane.high ^= tMsw; 12562 lane.low ^= tLsw; 12563 } 12564 } 12565 12566 // Rho Pi 12567 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 12568 // Shortcuts 12569 var lane = state[laneIndex]; 12570 var laneMsw = lane.high; 12571 var laneLsw = lane.low; 12572 var rhoOffset = RHO_OFFSETS[laneIndex]; 12573 12574 // Rotate lanes 12575 if (rhoOffset < 32) { 12576 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 12577 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 12578 } else /* if (rhoOffset >= 32) */ { 12579 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 12580 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 12581 } 12582 12583 // Transpose lanes 12584 var TPiLane = T[PI_INDEXES[laneIndex]]; 12585 TPiLane.high = tMsw; 12586 TPiLane.low = tLsw; 12587 } 12588 12589 // Rho pi at x = y = 0 12590 var T0 = T[0]; 12591 var state0 = state[0]; 12592 T0.high = state0.high; 12593 T0.low = state0.low; 12594 12595 // Chi 12596 for (var x = 0; x < 5; x++) { 12597 for (var y = 0; y < 5; y++) { 12598 // Shortcuts 12599 var laneIndex = x + 5 * y; 12600 var lane = state[laneIndex]; 12601 var TLane = T[laneIndex]; 12602 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 12603 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 12604 12605 // Mix rows 12606 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 12607 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 12608 } 12609 } 12610 12611 // Iota 12612 var lane = state[0]; 12613 var roundConstant = ROUND_CONSTANTS[round]; 12614 lane.high ^= roundConstant.high; 12615 lane.low ^= roundConstant.low;; 12616 } 12617 }, 12618 12619 _doFinalize: function () { 12620 // Shortcuts 12621 var data = this._data; 12622 var dataWords = data.words; 12623 var nBitsTotal = this._nDataBytes * 8; 12624 var nBitsLeft = data.sigBytes * 8; 12625 var blockSizeBits = this.blockSize * 32; 12626 12627 // Add padding 12628 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 12629 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 12630 data.sigBytes = dataWords.length * 4; 12631 12632 // Hash final blocks 12633 this._process(); 12634 12635 // Shortcuts 12636 var state = this._state; 12637 var outputLengthBytes = this.cfg.outputLength / 8; 12638 var outputLengthLanes = outputLengthBytes / 8; 12639 12640 // Squeeze 12641 var hashWords = []; 12642 for (var i = 0; i < outputLengthLanes; i++) { 12643 // Shortcuts 12644 var lane = state[i]; 12645 var laneMsw = lane.high; 12646 var laneLsw = lane.low; 12647 12648 // Swap endian 12649 laneMsw = ( 12650 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 12651 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 12652 ); 12653 laneLsw = ( 12654 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 12655 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 12656 ); 12657 12658 // Squeeze state to retrieve hash 12659 hashWords.push(laneLsw); 12660 hashWords.push(laneMsw); 12661 } 12662 12663 // Return final computed hash 12664 return new WordArray.init(hashWords, outputLengthBytes); 12665 }, 12666 12667 clone: function () { 12668 var clone = Hasher.clone.call(this); 12669 12670 var state = clone._state = this._state.slice(0); 12671 for (var i = 0; i < 25; i++) { 12672 state[i] = state[i].clone(); 12673 } 12674 12675 return clone; 12676 } 12677 }); 12678 12679 /** 12680 * Shortcut function to the hasher's object interface. 12681 * 12682 * @param {WordArray|string} message The message to hash. 12683 * 12684 * @return {WordArray} The hash. 12685 * 12686 * @static 12687 * 12688 * @example 12689 * 12690 * var hash = CryptoJS.SHA3('message'); 12691 * var hash = CryptoJS.SHA3(wordArray); 12692 */ 12693 C.SHA3 = Hasher._createHelper(SHA3); 12694 12695 /** 12696 * Shortcut function to the HMAC's object interface. 12697 * 12698 * @param {WordArray|string} message The message to hash. 12699 * @param {WordArray|string} key The secret key. 12700 * 12701 * @return {WordArray} The HMAC. 12702 * 12703 * @static 12704 * 12705 * @example 12706 * 12707 * var hmac = CryptoJS.HmacSHA3(message, key); 12708 */ 12709 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 12710 }(Math)); 12711 12712 12713 return CryptoJS.SHA3; 12714 12715 })); 12716 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 12717 ;(function (root, factory, undef) { 12718 if (typeof exports === "object") { 12719 // CommonJS 12720 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 12721 } 12722 else if (typeof define === "function" && define.amd) { 12723 // AMD 12724 define(["./core", "./x64-core", "./sha512"], factory); 12725 } 12726 else { 12727 // Global (browser) 12728 factory(root.CryptoJS); 12729 } 12730 }(this, function (CryptoJS) { 12731 12732 (function () { 12733 // Shortcuts 12734 var C = CryptoJS; 12735 var C_x64 = C.x64; 12736 var X64Word = C_x64.Word; 12737 var X64WordArray = C_x64.WordArray; 12738 var C_algo = C.algo; 12739 var SHA512 = C_algo.SHA512; 12740 12741 /** 12742 * SHA-384 hash algorithm. 12743 */ 12744 var SHA384 = C_algo.SHA384 = SHA512.extend({ 12745 _doReset: function () { 12746 this._hash = new X64WordArray.init([ 12747 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 12748 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 12749 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 12750 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 12751 ]); 12752 }, 12753 12754 _doFinalize: function () { 12755 var hash = SHA512._doFinalize.call(this); 12756 12757 hash.sigBytes -= 16; 12758 12759 return hash; 12760 } 12761 }); 12762 12763 /** 12764 * Shortcut function to the hasher's object interface. 12765 * 12766 * @param {WordArray|string} message The message to hash. 12767 * 12768 * @return {WordArray} The hash. 12769 * 12770 * @static 12771 * 12772 * @example 12773 * 12774 * var hash = CryptoJS.SHA384('message'); 12775 * var hash = CryptoJS.SHA384(wordArray); 12776 */ 12777 C.SHA384 = SHA512._createHelper(SHA384); 12778 12779 /** 12780 * Shortcut function to the HMAC's object interface. 12781 * 12782 * @param {WordArray|string} message The message to hash. 12783 * @param {WordArray|string} key The secret key. 12784 * 12785 * @return {WordArray} The HMAC. 12786 * 12787 * @static 12788 * 12789 * @example 12790 * 12791 * var hmac = CryptoJS.HmacSHA384(message, key); 12792 */ 12793 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 12794 }()); 12795 12796 12797 return CryptoJS.SHA384; 12798 12799 })); 12800 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 12801 ;(function (root, factory, undef) { 12802 if (typeof exports === "object") { 12803 // CommonJS 12804 module.exports = exports = factory(require("./core"), require("./x64-core")); 12805 } 12806 else if (typeof define === "function" && define.amd) { 12807 // AMD 12808 define(["./core", "./x64-core"], factory); 12809 } 12810 else { 12811 // Global (browser) 12812 factory(root.CryptoJS); 12813 } 12814 }(this, function (CryptoJS) { 12815 12816 (function () { 12817 // Shortcuts 12818 var C = CryptoJS; 12819 var C_lib = C.lib; 12820 var Hasher = C_lib.Hasher; 12821 var C_x64 = C.x64; 12822 var X64Word = C_x64.Word; 12823 var X64WordArray = C_x64.WordArray; 12824 var C_algo = C.algo; 12825 12826 function X64Word_create() { 12827 return X64Word.create.apply(X64Word, arguments); 12828 } 12829 12830 // Constants 12831 var K = [ 12832 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12833 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12834 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12835 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12836 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12837 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12838 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12839 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12840 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12841 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12842 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12843 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12844 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12845 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12846 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12847 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12848 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12849 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12850 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12851 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12852 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12853 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12854 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12855 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12856 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12857 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12858 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12859 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12860 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12861 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12862 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12863 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12864 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12865 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12866 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12867 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12868 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12869 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12870 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12871 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12872 ]; 12873 12874 // Reusable objects 12875 var W = []; 12876 (function () { 12877 for (var i = 0; i < 80; i++) { 12878 W[i] = X64Word_create(); 12879 } 12880 }()); 12881 12882 /** 12883 * SHA-512 hash algorithm. 12884 */ 12885 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12886 _doReset: function () { 12887 this._hash = new X64WordArray.init([ 12888 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12889 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12890 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12891 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12892 ]); 12893 }, 12894 12895 _doProcessBlock: function (M, offset) { 12896 // Shortcuts 12897 var H = this._hash.words; 12898 12899 var H0 = H[0]; 12900 var H1 = H[1]; 12901 var H2 = H[2]; 12902 var H3 = H[3]; 12903 var H4 = H[4]; 12904 var H5 = H[5]; 12905 var H6 = H[6]; 12906 var H7 = H[7]; 12907 12908 var H0h = H0.high; 12909 var H0l = H0.low; 12910 var H1h = H1.high; 12911 var H1l = H1.low; 12912 var H2h = H2.high; 12913 var H2l = H2.low; 12914 var H3h = H3.high; 12915 var H3l = H3.low; 12916 var H4h = H4.high; 12917 var H4l = H4.low; 12918 var H5h = H5.high; 12919 var H5l = H5.low; 12920 var H6h = H6.high; 12921 var H6l = H6.low; 12922 var H7h = H7.high; 12923 var H7l = H7.low; 12924 12925 // Working variables 12926 var ah = H0h; 12927 var al = H0l; 12928 var bh = H1h; 12929 var bl = H1l; 12930 var ch = H2h; 12931 var cl = H2l; 12932 var dh = H3h; 12933 var dl = H3l; 12934 var eh = H4h; 12935 var el = H4l; 12936 var fh = H5h; 12937 var fl = H5l; 12938 var gh = H6h; 12939 var gl = H6l; 12940 var hh = H7h; 12941 var hl = H7l; 12942 12943 // Rounds 12944 for (var i = 0; i < 80; i++) { 12945 // Shortcut 12946 var Wi = W[i]; 12947 12948 // Extend message 12949 if (i < 16) { 12950 var Wih = Wi.high = M[offset + i * 2] | 0; 12951 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12952 } else { 12953 // Gamma0 12954 var gamma0x = W[i - 15]; 12955 var gamma0xh = gamma0x.high; 12956 var gamma0xl = gamma0x.low; 12957 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12958 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12959 12960 // Gamma1 12961 var gamma1x = W[i - 2]; 12962 var gamma1xh = gamma1x.high; 12963 var gamma1xl = gamma1x.low; 12964 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12965 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12966 12967 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12968 var Wi7 = W[i - 7]; 12969 var Wi7h = Wi7.high; 12970 var Wi7l = Wi7.low; 12971 12972 var Wi16 = W[i - 16]; 12973 var Wi16h = Wi16.high; 12974 var Wi16l = Wi16.low; 12975 12976 var Wil = gamma0l + Wi7l; 12977 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12978 var Wil = Wil + gamma1l; 12979 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12980 var Wil = Wil + Wi16l; 12981 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12982 12983 Wi.high = Wih; 12984 Wi.low = Wil; 12985 } 12986 12987 var chh = (eh & fh) ^ (~eh & gh); 12988 var chl = (el & fl) ^ (~el & gl); 12989 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12990 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12991 12992 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12993 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12994 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12995 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12996 12997 // t1 = h + sigma1 + ch + K[i] + W[i] 12998 var Ki = K[i]; 12999 var Kih = Ki.high; 13000 var Kil = Ki.low; 13001 13002 var t1l = hl + sigma1l; 13003 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 13004 var t1l = t1l + chl; 13005 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 13006 var t1l = t1l + Kil; 13007 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 13008 var t1l = t1l + Wil; 13009 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 13010 13011 // t2 = sigma0 + maj 13012 var t2l = sigma0l + majl; 13013 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 13014 13015 // Update working variables 13016 hh = gh; 13017 hl = gl; 13018 gh = fh; 13019 gl = fl; 13020 fh = eh; 13021 fl = el; 13022 el = (dl + t1l) | 0; 13023 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 13024 dh = ch; 13025 dl = cl; 13026 ch = bh; 13027 cl = bl; 13028 bh = ah; 13029 bl = al; 13030 al = (t1l + t2l) | 0; 13031 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 13032 } 13033 13034 // Intermediate hash value 13035 H0l = H0.low = (H0l + al); 13036 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 13037 H1l = H1.low = (H1l + bl); 13038 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 13039 H2l = H2.low = (H2l + cl); 13040 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 13041 H3l = H3.low = (H3l + dl); 13042 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 13043 H4l = H4.low = (H4l + el); 13044 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 13045 H5l = H5.low = (H5l + fl); 13046 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 13047 H6l = H6.low = (H6l + gl); 13048 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 13049 H7l = H7.low = (H7l + hl); 13050 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 13051 }, 13052 13053 _doFinalize: function () { 13054 // Shortcuts 13055 var data = this._data; 13056 var dataWords = data.words; 13057 13058 var nBitsTotal = this._nDataBytes * 8; 13059 var nBitsLeft = data.sigBytes * 8; 13060 13061 // Add padding 13062 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 13063 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 13064 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 13065 data.sigBytes = dataWords.length * 4; 13066 13067 // Hash final blocks 13068 this._process(); 13069 13070 // Convert hash to 32-bit word array before returning 13071 var hash = this._hash.toX32(); 13072 13073 // Return final computed hash 13074 return hash; 13075 }, 13076 13077 clone: function () { 13078 var clone = Hasher.clone.call(this); 13079 clone._hash = this._hash.clone(); 13080 13081 return clone; 13082 }, 13083 13084 blockSize: 1024/32 13085 }); 13086 13087 /** 13088 * Shortcut function to the hasher's object interface. 13089 * 13090 * @param {WordArray|string} message The message to hash. 13091 * 13092 * @return {WordArray} The hash. 13093 * 13094 * @static 13095 * 13096 * @example 13097 * 13098 * var hash = CryptoJS.SHA512('message'); 13099 * var hash = CryptoJS.SHA512(wordArray); 13100 */ 13101 C.SHA512 = Hasher._createHelper(SHA512); 13102 13103 /** 13104 * Shortcut function to the HMAC's object interface. 13105 * 13106 * @param {WordArray|string} message The message to hash. 13107 * @param {WordArray|string} key The secret key. 13108 * 13109 * @return {WordArray} The HMAC. 13110 * 13111 * @static 13112 * 13113 * @example 13114 * 13115 * var hmac = CryptoJS.HmacSHA512(message, key); 13116 */ 13117 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 13118 }()); 13119 13120 13121 return CryptoJS.SHA512; 13122 13123 })); 13124 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 13125 ;(function (root, factory, undef) { 13126 if (typeof exports === "object") { 13127 // CommonJS 13128 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 13129 } 13130 else if (typeof define === "function" && define.amd) { 13131 // AMD 13132 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 13133 } 13134 else { 13135 // Global (browser) 13136 factory(root.CryptoJS); 13137 } 13138 }(this, function (CryptoJS) { 13139 13140 (function () { 13141 // Shortcuts 13142 var C = CryptoJS; 13143 var C_lib = C.lib; 13144 var WordArray = C_lib.WordArray; 13145 var BlockCipher = C_lib.BlockCipher; 13146 var C_algo = C.algo; 13147 13148 // Permuted Choice 1 constants 13149 var PC1 = [ 13150 57, 49, 41, 33, 25, 17, 9, 1, 13151 58, 50, 42, 34, 26, 18, 10, 2, 13152 59, 51, 43, 35, 27, 19, 11, 3, 13153 60, 52, 44, 36, 63, 55, 47, 39, 13154 31, 23, 15, 7, 62, 54, 46, 38, 13155 30, 22, 14, 6, 61, 53, 45, 37, 13156 29, 21, 13, 5, 28, 20, 12, 4 13157 ]; 13158 13159 // Permuted Choice 2 constants 13160 var PC2 = [ 13161 14, 17, 11, 24, 1, 5, 13162 3, 28, 15, 6, 21, 10, 13163 23, 19, 12, 4, 26, 8, 13164 16, 7, 27, 20, 13, 2, 13165 41, 52, 31, 37, 47, 55, 13166 30, 40, 51, 45, 33, 48, 13167 44, 49, 39, 56, 34, 53, 13168 46, 42, 50, 36, 29, 32 13169 ]; 13170 13171 // Cumulative bit shift constants 13172 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 13173 13174 // SBOXes and round permutation constants 13175 var SBOX_P = [ 13176 { 13177 0x0: 0x808200, 13178 0x10000000: 0x8000, 13179 0x20000000: 0x808002, 13180 0x30000000: 0x2, 13181 0x40000000: 0x200, 13182 0x50000000: 0x808202, 13183 0x60000000: 0x800202, 13184 0x70000000: 0x800000, 13185 0x80000000: 0x202, 13186 0x90000000: 0x800200, 13187 0xa0000000: 0x8200, 13188 0xb0000000: 0x808000, 13189 0xc0000000: 0x8002, 13190 0xd0000000: 0x800002, 13191 0xe0000000: 0x0, 13192 0xf0000000: 0x8202, 13193 0x8000000: 0x0, 13194 0x18000000: 0x808202, 13195 0x28000000: 0x8202, 13196 0x38000000: 0x8000, 13197 0x48000000: 0x808200, 13198 0x58000000: 0x200, 13199 0x68000000: 0x808002, 13200 0x78000000: 0x2, 13201 0x88000000: 0x800200, 13202 0x98000000: 0x8200, 13203 0xa8000000: 0x808000, 13204 0xb8000000: 0x800202, 13205 0xc8000000: 0x800002, 13206 0xd8000000: 0x8002, 13207 0xe8000000: 0x202, 13208 0xf8000000: 0x800000, 13209 0x1: 0x8000, 13210 0x10000001: 0x2, 13211 0x20000001: 0x808200, 13212 0x30000001: 0x800000, 13213 0x40000001: 0x808002, 13214 0x50000001: 0x8200, 13215 0x60000001: 0x200, 13216 0x70000001: 0x800202, 13217 0x80000001: 0x808202, 13218 0x90000001: 0x808000, 13219 0xa0000001: 0x800002, 13220 0xb0000001: 0x8202, 13221 0xc0000001: 0x202, 13222 0xd0000001: 0x800200, 13223 0xe0000001: 0x8002, 13224 0xf0000001: 0x0, 13225 0x8000001: 0x808202, 13226 0x18000001: 0x808000, 13227 0x28000001: 0x800000, 13228 0x38000001: 0x200, 13229 0x48000001: 0x8000, 13230 0x58000001: 0x800002, 13231 0x68000001: 0x2, 13232 0x78000001: 0x8202, 13233 0x88000001: 0x8002, 13234 0x98000001: 0x800202, 13235 0xa8000001: 0x202, 13236 0xb8000001: 0x808200, 13237 0xc8000001: 0x800200, 13238 0xd8000001: 0x0, 13239 0xe8000001: 0x8200, 13240 0xf8000001: 0x808002 13241 }, 13242 { 13243 0x0: 0x40084010, 13244 0x1000000: 0x4000, 13245 0x2000000: 0x80000, 13246 0x3000000: 0x40080010, 13247 0x4000000: 0x40000010, 13248 0x5000000: 0x40084000, 13249 0x6000000: 0x40004000, 13250 0x7000000: 0x10, 13251 0x8000000: 0x84000, 13252 0x9000000: 0x40004010, 13253 0xa000000: 0x40000000, 13254 0xb000000: 0x84010, 13255 0xc000000: 0x80010, 13256 0xd000000: 0x0, 13257 0xe000000: 0x4010, 13258 0xf000000: 0x40080000, 13259 0x800000: 0x40004000, 13260 0x1800000: 0x84010, 13261 0x2800000: 0x10, 13262 0x3800000: 0x40004010, 13263 0x4800000: 0x40084010, 13264 0x5800000: 0x40000000, 13265 0x6800000: 0x80000, 13266 0x7800000: 0x40080010, 13267 0x8800000: 0x80010, 13268 0x9800000: 0x0, 13269 0xa800000: 0x4000, 13270 0xb800000: 0x40080000, 13271 0xc800000: 0x40000010, 13272 0xd800000: 0x84000, 13273 0xe800000: 0x40084000, 13274 0xf800000: 0x4010, 13275 0x10000000: 0x0, 13276 0x11000000: 0x40080010, 13277 0x12000000: 0x40004010, 13278 0x13000000: 0x40084000, 13279 0x14000000: 0x40080000, 13280 0x15000000: 0x10, 13281 0x16000000: 0x84010, 13282 0x17000000: 0x4000, 13283 0x18000000: 0x4010, 13284 0x19000000: 0x80000, 13285 0x1a000000: 0x80010, 13286 0x1b000000: 0x40000010, 13287 0x1c000000: 0x84000, 13288 0x1d000000: 0x40004000, 13289 0x1e000000: 0x40000000, 13290 0x1f000000: 0x40084010, 13291 0x10800000: 0x84010, 13292 0x11800000: 0x80000, 13293 0x12800000: 0x40080000, 13294 0x13800000: 0x4000, 13295 0x14800000: 0x40004000, 13296 0x15800000: 0x40084010, 13297 0x16800000: 0x10, 13298 0x17800000: 0x40000000, 13299 0x18800000: 0x40084000, 13300 0x19800000: 0x40000010, 13301 0x1a800000: 0x40004010, 13302 0x1b800000: 0x80010, 13303 0x1c800000: 0x0, 13304 0x1d800000: 0x4010, 13305 0x1e800000: 0x40080010, 13306 0x1f800000: 0x84000 13307 }, 13308 { 13309 0x0: 0x104, 13310 0x100000: 0x0, 13311 0x200000: 0x4000100, 13312 0x300000: 0x10104, 13313 0x400000: 0x10004, 13314 0x500000: 0x4000004, 13315 0x600000: 0x4010104, 13316 0x700000: 0x4010000, 13317 0x800000: 0x4000000, 13318 0x900000: 0x4010100, 13319 0xa00000: 0x10100, 13320 0xb00000: 0x4010004, 13321 0xc00000: 0x4000104, 13322 0xd00000: 0x10000, 13323 0xe00000: 0x4, 13324 0xf00000: 0x100, 13325 0x80000: 0x4010100, 13326 0x180000: 0x4010004, 13327 0x280000: 0x0, 13328 0x380000: 0x4000100, 13329 0x480000: 0x4000004, 13330 0x580000: 0x10000, 13331 0x680000: 0x10004, 13332 0x780000: 0x104, 13333 0x880000: 0x4, 13334 0x980000: 0x100, 13335 0xa80000: 0x4010000, 13336 0xb80000: 0x10104, 13337 0xc80000: 0x10100, 13338 0xd80000: 0x4000104, 13339 0xe80000: 0x4010104, 13340 0xf80000: 0x4000000, 13341 0x1000000: 0x4010100, 13342 0x1100000: 0x10004, 13343 0x1200000: 0x10000, 13344 0x1300000: 0x4000100, 13345 0x1400000: 0x100, 13346 0x1500000: 0x4010104, 13347 0x1600000: 0x4000004, 13348 0x1700000: 0x0, 13349 0x1800000: 0x4000104, 13350 0x1900000: 0x4000000, 13351 0x1a00000: 0x4, 13352 0x1b00000: 0x10100, 13353 0x1c00000: 0x4010000, 13354 0x1d00000: 0x104, 13355 0x1e00000: 0x10104, 13356 0x1f00000: 0x4010004, 13357 0x1080000: 0x4000000, 13358 0x1180000: 0x104, 13359 0x1280000: 0x4010100, 13360 0x1380000: 0x0, 13361 0x1480000: 0x10004, 13362 0x1580000: 0x4000100, 13363 0x1680000: 0x100, 13364 0x1780000: 0x4010004, 13365 0x1880000: 0x10000, 13366 0x1980000: 0x4010104, 13367 0x1a80000: 0x10104, 13368 0x1b80000: 0x4000004, 13369 0x1c80000: 0x4000104, 13370 0x1d80000: 0x4010000, 13371 0x1e80000: 0x4, 13372 0x1f80000: 0x10100 13373 }, 13374 { 13375 0x0: 0x80401000, 13376 0x10000: 0x80001040, 13377 0x20000: 0x401040, 13378 0x30000: 0x80400000, 13379 0x40000: 0x0, 13380 0x50000: 0x401000, 13381 0x60000: 0x80000040, 13382 0x70000: 0x400040, 13383 0x80000: 0x80000000, 13384 0x90000: 0x400000, 13385 0xa0000: 0x40, 13386 0xb0000: 0x80001000, 13387 0xc0000: 0x80400040, 13388 0xd0000: 0x1040, 13389 0xe0000: 0x1000, 13390 0xf0000: 0x80401040, 13391 0x8000: 0x80001040, 13392 0x18000: 0x40, 13393 0x28000: 0x80400040, 13394 0x38000: 0x80001000, 13395 0x48000: 0x401000, 13396 0x58000: 0x80401040, 13397 0x68000: 0x0, 13398 0x78000: 0x80400000, 13399 0x88000: 0x1000, 13400 0x98000: 0x80401000, 13401 0xa8000: 0x400000, 13402 0xb8000: 0x1040, 13403 0xc8000: 0x80000000, 13404 0xd8000: 0x400040, 13405 0xe8000: 0x401040, 13406 0xf8000: 0x80000040, 13407 0x100000: 0x400040, 13408 0x110000: 0x401000, 13409 0x120000: 0x80000040, 13410 0x130000: 0x0, 13411 0x140000: 0x1040, 13412 0x150000: 0x80400040, 13413 0x160000: 0x80401000, 13414 0x170000: 0x80001040, 13415 0x180000: 0x80401040, 13416 0x190000: 0x80000000, 13417 0x1a0000: 0x80400000, 13418 0x1b0000: 0x401040, 13419 0x1c0000: 0x80001000, 13420 0x1d0000: 0x400000, 13421 0x1e0000: 0x40, 13422 0x1f0000: 0x1000, 13423 0x108000: 0x80400000, 13424 0x118000: 0x80401040, 13425 0x128000: 0x0, 13426 0x138000: 0x401000, 13427 0x148000: 0x400040, 13428 0x158000: 0x80000000, 13429 0x168000: 0x80001040, 13430 0x178000: 0x40, 13431 0x188000: 0x80000040, 13432 0x198000: 0x1000, 13433 0x1a8000: 0x80001000, 13434 0x1b8000: 0x80400040, 13435 0x1c8000: 0x1040, 13436 0x1d8000: 0x80401000, 13437 0x1e8000: 0x400000, 13438 0x1f8000: 0x401040 13439 }, 13440 { 13441 0x0: 0x80, 13442 0x1000: 0x1040000, 13443 0x2000: 0x40000, 13444 0x3000: 0x20000000, 13445 0x4000: 0x20040080, 13446 0x5000: 0x1000080, 13447 0x6000: 0x21000080, 13448 0x7000: 0x40080, 13449 0x8000: 0x1000000, 13450 0x9000: 0x20040000, 13451 0xa000: 0x20000080, 13452 0xb000: 0x21040080, 13453 0xc000: 0x21040000, 13454 0xd000: 0x0, 13455 0xe000: 0x1040080, 13456 0xf000: 0x21000000, 13457 0x800: 0x1040080, 13458 0x1800: 0x21000080, 13459 0x2800: 0x80, 13460 0x3800: 0x1040000, 13461 0x4800: 0x40000, 13462 0x5800: 0x20040080, 13463 0x6800: 0x21040000, 13464 0x7800: 0x20000000, 13465 0x8800: 0x20040000, 13466 0x9800: 0x0, 13467 0xa800: 0x21040080, 13468 0xb800: 0x1000080, 13469 0xc800: 0x20000080, 13470 0xd800: 0x21000000, 13471 0xe800: 0x1000000, 13472 0xf800: 0x40080, 13473 0x10000: 0x40000, 13474 0x11000: 0x80, 13475 0x12000: 0x20000000, 13476 0x13000: 0x21000080, 13477 0x14000: 0x1000080, 13478 0x15000: 0x21040000, 13479 0x16000: 0x20040080, 13480 0x17000: 0x1000000, 13481 0x18000: 0x21040080, 13482 0x19000: 0x21000000, 13483 0x1a000: 0x1040000, 13484 0x1b000: 0x20040000, 13485 0x1c000: 0x40080, 13486 0x1d000: 0x20000080, 13487 0x1e000: 0x0, 13488 0x1f000: 0x1040080, 13489 0x10800: 0x21000080, 13490 0x11800: 0x1000000, 13491 0x12800: 0x1040000, 13492 0x13800: 0x20040080, 13493 0x14800: 0x20000000, 13494 0x15800: 0x1040080, 13495 0x16800: 0x80, 13496 0x17800: 0x21040000, 13497 0x18800: 0x40080, 13498 0x19800: 0x21040080, 13499 0x1a800: 0x0, 13500 0x1b800: 0x21000000, 13501 0x1c800: 0x1000080, 13502 0x1d800: 0x40000, 13503 0x1e800: 0x20040000, 13504 0x1f800: 0x20000080 13505 }, 13506 { 13507 0x0: 0x10000008, 13508 0x100: 0x2000, 13509 0x200: 0x10200000, 13510 0x300: 0x10202008, 13511 0x400: 0x10002000, 13512 0x500: 0x200000, 13513 0x600: 0x200008, 13514 0x700: 0x10000000, 13515 0x800: 0x0, 13516 0x900: 0x10002008, 13517 0xa00: 0x202000, 13518 0xb00: 0x8, 13519 0xc00: 0x10200008, 13520 0xd00: 0x202008, 13521 0xe00: 0x2008, 13522 0xf00: 0x10202000, 13523 0x80: 0x10200000, 13524 0x180: 0x10202008, 13525 0x280: 0x8, 13526 0x380: 0x200000, 13527 0x480: 0x202008, 13528 0x580: 0x10000008, 13529 0x680: 0x10002000, 13530 0x780: 0x2008, 13531 0x880: 0x200008, 13532 0x980: 0x2000, 13533 0xa80: 0x10002008, 13534 0xb80: 0x10200008, 13535 0xc80: 0x0, 13536 0xd80: 0x10202000, 13537 0xe80: 0x202000, 13538 0xf80: 0x10000000, 13539 0x1000: 0x10002000, 13540 0x1100: 0x10200008, 13541 0x1200: 0x10202008, 13542 0x1300: 0x2008, 13543 0x1400: 0x200000, 13544 0x1500: 0x10000000, 13545 0x1600: 0x10000008, 13546 0x1700: 0x202000, 13547 0x1800: 0x202008, 13548 0x1900: 0x0, 13549 0x1a00: 0x8, 13550 0x1b00: 0x10200000, 13551 0x1c00: 0x2000, 13552 0x1d00: 0x10002008, 13553 0x1e00: 0x10202000, 13554 0x1f00: 0x200008, 13555 0x1080: 0x8, 13556 0x1180: 0x202000, 13557 0x1280: 0x200000, 13558 0x1380: 0x10000008, 13559 0x1480: 0x10002000, 13560 0x1580: 0x2008, 13561 0x1680: 0x10202008, 13562 0x1780: 0x10200000, 13563 0x1880: 0x10202000, 13564 0x1980: 0x10200008, 13565 0x1a80: 0x2000, 13566 0x1b80: 0x202008, 13567 0x1c80: 0x200008, 13568 0x1d80: 0x0, 13569 0x1e80: 0x10000000, 13570 0x1f80: 0x10002008 13571 }, 13572 { 13573 0x0: 0x100000, 13574 0x10: 0x2000401, 13575 0x20: 0x400, 13576 0x30: 0x100401, 13577 0x40: 0x2100401, 13578 0x50: 0x0, 13579 0x60: 0x1, 13580 0x70: 0x2100001, 13581 0x80: 0x2000400, 13582 0x90: 0x100001, 13583 0xa0: 0x2000001, 13584 0xb0: 0x2100400, 13585 0xc0: 0x2100000, 13586 0xd0: 0x401, 13587 0xe0: 0x100400, 13588 0xf0: 0x2000000, 13589 0x8: 0x2100001, 13590 0x18: 0x0, 13591 0x28: 0x2000401, 13592 0x38: 0x2100400, 13593 0x48: 0x100000, 13594 0x58: 0x2000001, 13595 0x68: 0x2000000, 13596 0x78: 0x401, 13597 0x88: 0x100401, 13598 0x98: 0x2000400, 13599 0xa8: 0x2100000, 13600 0xb8: 0x100001, 13601 0xc8: 0x400, 13602 0xd8: 0x2100401, 13603 0xe8: 0x1, 13604 0xf8: 0x100400, 13605 0x100: 0x2000000, 13606 0x110: 0x100000, 13607 0x120: 0x2000401, 13608 0x130: 0x2100001, 13609 0x140: 0x100001, 13610 0x150: 0x2000400, 13611 0x160: 0x2100400, 13612 0x170: 0x100401, 13613 0x180: 0x401, 13614 0x190: 0x2100401, 13615 0x1a0: 0x100400, 13616 0x1b0: 0x1, 13617 0x1c0: 0x0, 13618 0x1d0: 0x2100000, 13619 0x1e0: 0x2000001, 13620 0x1f0: 0x400, 13621 0x108: 0x100400, 13622 0x118: 0x2000401, 13623 0x128: 0x2100001, 13624 0x138: 0x1, 13625 0x148: 0x2000000, 13626 0x158: 0x100000, 13627 0x168: 0x401, 13628 0x178: 0x2100400, 13629 0x188: 0x2000001, 13630 0x198: 0x2100000, 13631 0x1a8: 0x0, 13632 0x1b8: 0x2100401, 13633 0x1c8: 0x100401, 13634 0x1d8: 0x400, 13635 0x1e8: 0x2000400, 13636 0x1f8: 0x100001 13637 }, 13638 { 13639 0x0: 0x8000820, 13640 0x1: 0x20000, 13641 0x2: 0x8000000, 13642 0x3: 0x20, 13643 0x4: 0x20020, 13644 0x5: 0x8020820, 13645 0x6: 0x8020800, 13646 0x7: 0x800, 13647 0x8: 0x8020000, 13648 0x9: 0x8000800, 13649 0xa: 0x20800, 13650 0xb: 0x8020020, 13651 0xc: 0x820, 13652 0xd: 0x0, 13653 0xe: 0x8000020, 13654 0xf: 0x20820, 13655 0x80000000: 0x800, 13656 0x80000001: 0x8020820, 13657 0x80000002: 0x8000820, 13658 0x80000003: 0x8000000, 13659 0x80000004: 0x8020000, 13660 0x80000005: 0x20800, 13661 0x80000006: 0x20820, 13662 0x80000007: 0x20, 13663 0x80000008: 0x8000020, 13664 0x80000009: 0x820, 13665 0x8000000a: 0x20020, 13666 0x8000000b: 0x8020800, 13667 0x8000000c: 0x0, 13668 0x8000000d: 0x8020020, 13669 0x8000000e: 0x8000800, 13670 0x8000000f: 0x20000, 13671 0x10: 0x20820, 13672 0x11: 0x8020800, 13673 0x12: 0x20, 13674 0x13: 0x800, 13675 0x14: 0x8000800, 13676 0x15: 0x8000020, 13677 0x16: 0x8020020, 13678 0x17: 0x20000, 13679 0x18: 0x0, 13680 0x19: 0x20020, 13681 0x1a: 0x8020000, 13682 0x1b: 0x8000820, 13683 0x1c: 0x8020820, 13684 0x1d: 0x20800, 13685 0x1e: 0x820, 13686 0x1f: 0x8000000, 13687 0x80000010: 0x20000, 13688 0x80000011: 0x800, 13689 0x80000012: 0x8020020, 13690 0x80000013: 0x20820, 13691 0x80000014: 0x20, 13692 0x80000015: 0x8020000, 13693 0x80000016: 0x8000000, 13694 0x80000017: 0x8000820, 13695 0x80000018: 0x8020820, 13696 0x80000019: 0x8000020, 13697 0x8000001a: 0x8000800, 13698 0x8000001b: 0x0, 13699 0x8000001c: 0x20800, 13700 0x8000001d: 0x820, 13701 0x8000001e: 0x20020, 13702 0x8000001f: 0x8020800 13703 } 13704 ]; 13705 13706 // Masks that select the SBOX input 13707 var SBOX_MASK = [ 13708 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 13709 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 13710 ]; 13711 13712 /** 13713 * DES block cipher algorithm. 13714 */ 13715 var DES = C_algo.DES = BlockCipher.extend({ 13716 _doReset: function () { 13717 // Shortcuts 13718 var key = this._key; 13719 var keyWords = key.words; 13720 13721 // Select 56 bits according to PC1 13722 var keyBits = []; 13723 for (var i = 0; i < 56; i++) { 13724 var keyBitPos = PC1[i] - 1; 13725 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 13726 } 13727 13728 // Assemble 16 subkeys 13729 var subKeys = this._subKeys = []; 13730 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 13731 // Create subkey 13732 var subKey = subKeys[nSubKey] = []; 13733 13734 // Shortcut 13735 var bitShift = BIT_SHIFTS[nSubKey]; 13736 13737 // Select 48 bits according to PC2 13738 for (var i = 0; i < 24; i++) { 13739 // Select from the left 28 key bits 13740 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 13741 13742 // Select from the right 28 key bits 13743 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 13744 } 13745 13746 // Since each subkey is applied to an expanded 32-bit input, 13747 // the subkey can be broken into 8 values scaled to 32-bits, 13748 // which allows the key to be used without expansion 13749 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 13750 for (var i = 1; i < 7; i++) { 13751 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 13752 } 13753 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 13754 } 13755 13756 // Compute inverse subkeys 13757 var invSubKeys = this._invSubKeys = []; 13758 for (var i = 0; i < 16; i++) { 13759 invSubKeys[i] = subKeys[15 - i]; 13760 } 13761 }, 13762 13763 encryptBlock: function (M, offset) { 13764 this._doCryptBlock(M, offset, this._subKeys); 13765 }, 13766 13767 decryptBlock: function (M, offset) { 13768 this._doCryptBlock(M, offset, this._invSubKeys); 13769 }, 13770 13771 _doCryptBlock: function (M, offset, subKeys) { 13772 // Get input 13773 this._lBlock = M[offset]; 13774 this._rBlock = M[offset + 1]; 13775 13776 // Initial permutation 13777 exchangeLR.call(this, 4, 0x0f0f0f0f); 13778 exchangeLR.call(this, 16, 0x0000ffff); 13779 exchangeRL.call(this, 2, 0x33333333); 13780 exchangeRL.call(this, 8, 0x00ff00ff); 13781 exchangeLR.call(this, 1, 0x55555555); 13782 13783 // Rounds 13784 for (var round = 0; round < 16; round++) { 13785 // Shortcuts 13786 var subKey = subKeys[round]; 13787 var lBlock = this._lBlock; 13788 var rBlock = this._rBlock; 13789 13790 // Feistel function 13791 var f = 0; 13792 for (var i = 0; i < 8; i++) { 13793 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 13794 } 13795 this._lBlock = rBlock; 13796 this._rBlock = lBlock ^ f; 13797 } 13798 13799 // Undo swap from last round 13800 var t = this._lBlock; 13801 this._lBlock = this._rBlock; 13802 this._rBlock = t; 13803 13804 // Final permutation 13805 exchangeLR.call(this, 1, 0x55555555); 13806 exchangeRL.call(this, 8, 0x00ff00ff); 13807 exchangeRL.call(this, 2, 0x33333333); 13808 exchangeLR.call(this, 16, 0x0000ffff); 13809 exchangeLR.call(this, 4, 0x0f0f0f0f); 13810 13811 // Set output 13812 M[offset] = this._lBlock; 13813 M[offset + 1] = this._rBlock; 13814 }, 13815 13816 keySize: 64/32, 13817 13818 ivSize: 64/32, 13819 13820 blockSize: 64/32 13821 }); 13822 13823 // Swap bits across the left and right words 13824 function exchangeLR(offset, mask) { 13825 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13826 this._rBlock ^= t; 13827 this._lBlock ^= t << offset; 13828 } 13829 13830 function exchangeRL(offset, mask) { 13831 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13832 this._lBlock ^= t; 13833 this._rBlock ^= t << offset; 13834 } 13835 13836 /** 13837 * Shortcut functions to the cipher's object interface. 13838 * 13839 * @example 13840 * 13841 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13842 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13843 */ 13844 C.DES = BlockCipher._createHelper(DES); 13845 13846 /** 13847 * Triple-DES block cipher algorithm. 13848 */ 13849 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13850 _doReset: function () { 13851 // Shortcuts 13852 var key = this._key; 13853 var keyWords = key.words; 13854 13855 // Create DES instances 13856 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13857 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13858 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13859 }, 13860 13861 encryptBlock: function (M, offset) { 13862 this._des1.encryptBlock(M, offset); 13863 this._des2.decryptBlock(M, offset); 13864 this._des3.encryptBlock(M, offset); 13865 }, 13866 13867 decryptBlock: function (M, offset) { 13868 this._des3.decryptBlock(M, offset); 13869 this._des2.encryptBlock(M, offset); 13870 this._des1.decryptBlock(M, offset); 13871 }, 13872 13873 keySize: 192/32, 13874 13875 ivSize: 64/32, 13876 13877 blockSize: 64/32 13878 }); 13879 13880 /** 13881 * Shortcut functions to the cipher's object interface. 13882 * 13883 * @example 13884 * 13885 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13886 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13887 */ 13888 C.TripleDES = BlockCipher._createHelper(TripleDES); 13889 }()); 13890 13891 13892 return CryptoJS.TripleDES; 13893 13894 })); 13895 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 13896 ;(function (root, factory) { 13897 if (typeof exports === "object") { 13898 // CommonJS 13899 module.exports = exports = factory(require("./core")); 13900 } 13901 else if (typeof define === "function" && define.amd) { 13902 // AMD 13903 define(["./core"], factory); 13904 } 13905 else { 13906 // Global (browser) 13907 factory(root.CryptoJS); 13908 } 13909 }(this, function (CryptoJS) { 13910 13911 (function (undefined) { 13912 // Shortcuts 13913 var C = CryptoJS; 13914 var C_lib = C.lib; 13915 var Base = C_lib.Base; 13916 var X32WordArray = C_lib.WordArray; 13917 13918 /** 13919 * x64 namespace. 13920 */ 13921 var C_x64 = C.x64 = {}; 13922 13923 /** 13924 * A 64-bit word. 13925 */ 13926 var X64Word = C_x64.Word = Base.extend({ 13927 /** 13928 * Initializes a newly created 64-bit word. 13929 * 13930 * @param {number} high The high 32 bits. 13931 * @param {number} low The low 32 bits. 13932 * 13933 * @example 13934 * 13935 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13936 */ 13937 init: function (high, low) { 13938 this.high = high; 13939 this.low = low; 13940 } 13941 13942 /** 13943 * Bitwise NOTs this word. 13944 * 13945 * @return {X64Word} A new x64-Word object after negating. 13946 * 13947 * @example 13948 * 13949 * var negated = x64Word.not(); 13950 */ 13951 // not: function () { 13952 // var high = ~this.high; 13953 // var low = ~this.low; 13954 13955 // return X64Word.create(high, low); 13956 // }, 13957 13958 /** 13959 * Bitwise ANDs this word with the passed word. 13960 * 13961 * @param {X64Word} word The x64-Word to AND with this word. 13962 * 13963 * @return {X64Word} A new x64-Word object after ANDing. 13964 * 13965 * @example 13966 * 13967 * var anded = x64Word.and(anotherX64Word); 13968 */ 13969 // and: function (word) { 13970 // var high = this.high & word.high; 13971 // var low = this.low & word.low; 13972 13973 // return X64Word.create(high, low); 13974 // }, 13975 13976 /** 13977 * Bitwise ORs this word with the passed word. 13978 * 13979 * @param {X64Word} word The x64-Word to OR with this word. 13980 * 13981 * @return {X64Word} A new x64-Word object after ORing. 13982 * 13983 * @example 13984 * 13985 * var ored = x64Word.or(anotherX64Word); 13986 */ 13987 // or: function (word) { 13988 // var high = this.high | word.high; 13989 // var low = this.low | word.low; 13990 13991 // return X64Word.create(high, low); 13992 // }, 13993 13994 /** 13995 * Bitwise XORs this word with the passed word. 13996 * 13997 * @param {X64Word} word The x64-Word to XOR with this word. 13998 * 13999 * @return {X64Word} A new x64-Word object after XORing. 14000 * 14001 * @example 14002 * 14003 * var xored = x64Word.xor(anotherX64Word); 14004 */ 14005 // xor: function (word) { 14006 // var high = this.high ^ word.high; 14007 // var low = this.low ^ word.low; 14008 14009 // return X64Word.create(high, low); 14010 // }, 14011 14012 /** 14013 * Shifts this word n bits to the left. 14014 * 14015 * @param {number} n The number of bits to shift. 14016 * 14017 * @return {X64Word} A new x64-Word object after shifting. 14018 * 14019 * @example 14020 * 14021 * var shifted = x64Word.shiftL(25); 14022 */ 14023 // shiftL: function (n) { 14024 // if (n < 32) { 14025 // var high = (this.high << n) | (this.low >>> (32 - n)); 14026 // var low = this.low << n; 14027 // } else { 14028 // var high = this.low << (n - 32); 14029 // var low = 0; 14030 // } 14031 14032 // return X64Word.create(high, low); 14033 // }, 14034 14035 /** 14036 * Shifts this word n bits to the right. 14037 * 14038 * @param {number} n The number of bits to shift. 14039 * 14040 * @return {X64Word} A new x64-Word object after shifting. 14041 * 14042 * @example 14043 * 14044 * var shifted = x64Word.shiftR(7); 14045 */ 14046 // shiftR: function (n) { 14047 // if (n < 32) { 14048 // var low = (this.low >>> n) | (this.high << (32 - n)); 14049 // var high = this.high >>> n; 14050 // } else { 14051 // var low = this.high >>> (n - 32); 14052 // var high = 0; 14053 // } 14054 14055 // return X64Word.create(high, low); 14056 // }, 14057 14058 /** 14059 * Rotates this word n bits to the left. 14060 * 14061 * @param {number} n The number of bits to rotate. 14062 * 14063 * @return {X64Word} A new x64-Word object after rotating. 14064 * 14065 * @example 14066 * 14067 * var rotated = x64Word.rotL(25); 14068 */ 14069 // rotL: function (n) { 14070 // return this.shiftL(n).or(this.shiftR(64 - n)); 14071 // }, 14072 14073 /** 14074 * Rotates this word n bits to the right. 14075 * 14076 * @param {number} n The number of bits to rotate. 14077 * 14078 * @return {X64Word} A new x64-Word object after rotating. 14079 * 14080 * @example 14081 * 14082 * var rotated = x64Word.rotR(7); 14083 */ 14084 // rotR: function (n) { 14085 // return this.shiftR(n).or(this.shiftL(64 - n)); 14086 // }, 14087 14088 /** 14089 * Adds this word with the passed word. 14090 * 14091 * @param {X64Word} word The x64-Word to add with this word. 14092 * 14093 * @return {X64Word} A new x64-Word object after adding. 14094 * 14095 * @example 14096 * 14097 * var added = x64Word.add(anotherX64Word); 14098 */ 14099 // add: function (word) { 14100 // var low = (this.low + word.low) | 0; 14101 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 14102 // var high = (this.high + word.high + carry) | 0; 14103 14104 // return X64Word.create(high, low); 14105 // } 14106 }); 14107 14108 /** 14109 * An array of 64-bit words. 14110 * 14111 * @property {Array} words The array of CryptoJS.x64.Word objects. 14112 * @property {number} sigBytes The number of significant bytes in this word array. 14113 */ 14114 var X64WordArray = C_x64.WordArray = Base.extend({ 14115 /** 14116 * Initializes a newly created word array. 14117 * 14118 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 14119 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 14120 * 14121 * @example 14122 * 14123 * var wordArray = CryptoJS.x64.WordArray.create(); 14124 * 14125 * var wordArray = CryptoJS.x64.WordArray.create([ 14126 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 14127 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 14128 * ]); 14129 * 14130 * var wordArray = CryptoJS.x64.WordArray.create([ 14131 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 14132 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 14133 * ], 10); 14134 */ 14135 init: function (words, sigBytes) { 14136 words = this.words = words || []; 14137 14138 if (sigBytes != undefined) { 14139 this.sigBytes = sigBytes; 14140 } else { 14141 this.sigBytes = words.length * 8; 14142 } 14143 }, 14144 14145 /** 14146 * Converts this 64-bit word array to a 32-bit word array. 14147 * 14148 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 14149 * 14150 * @example 14151 * 14152 * var x32WordArray = x64WordArray.toX32(); 14153 */ 14154 toX32: function () { 14155 // Shortcuts 14156 var x64Words = this.words; 14157 var x64WordsLength = x64Words.length; 14158 14159 // Convert 14160 var x32Words = []; 14161 for (var i = 0; i < x64WordsLength; i++) { 14162 var x64Word = x64Words[i]; 14163 x32Words.push(x64Word.high); 14164 x32Words.push(x64Word.low); 14165 } 14166 14167 return X32WordArray.create(x32Words, this.sigBytes); 14168 }, 14169 14170 /** 14171 * Creates a copy of this word array. 14172 * 14173 * @return {X64WordArray} The clone. 14174 * 14175 * @example 14176 * 14177 * var clone = x64WordArray.clone(); 14178 */ 14179 clone: function () { 14180 var clone = Base.clone.call(this); 14181 14182 // Clone "words" array 14183 var words = clone.words = this.words.slice(0); 14184 14185 // Clone each X64Word object 14186 var wordsLength = words.length; 14187 for (var i = 0; i < wordsLength; i++) { 14188 words[i] = words[i].clone(); 14189 } 14190 14191 return clone; 14192 } 14193 }); 14194 }()); 14195 14196 14197 return CryptoJS; 14198 14199 })); 14200 },{"./core":53}],85:[function(require,module,exports){ 14201 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 14202 ;(function(root) { 14203 14204 // Detect free variables `exports` 14205 var freeExports = typeof exports == 'object' && exports; 14206 14207 // Detect free variable `module` 14208 var freeModule = typeof module == 'object' && module && 14209 module.exports == freeExports && module; 14210 14211 // Detect free variable `global`, from Node.js or Browserified code, 14212 // and use it as `root` 14213 var freeGlobal = typeof global == 'object' && global; 14214 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 14215 root = freeGlobal; 14216 } 14217 14218 /*--------------------------------------------------------------------------*/ 14219 14220 var stringFromCharCode = String.fromCharCode; 14221 14222 // Taken from https://mths.be/punycode 14223 function ucs2decode(string) { 14224 var output = []; 14225 var counter = 0; 14226 var length = string.length; 14227 var value; 14228 var extra; 14229 while (counter < length) { 14230 value = string.charCodeAt(counter++); 14231 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 14232 // high surrogate, and there is a next character 14233 extra = string.charCodeAt(counter++); 14234 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 14235 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 14236 } else { 14237 // unmatched surrogate; only append this code unit, in case the next 14238 // code unit is the high surrogate of a surrogate pair 14239 output.push(value); 14240 counter--; 14241 } 14242 } else { 14243 output.push(value); 14244 } 14245 } 14246 return output; 14247 } 14248 14249 // Taken from https://mths.be/punycode 14250 function ucs2encode(array) { 14251 var length = array.length; 14252 var index = -1; 14253 var value; 14254 var output = ''; 14255 while (++index < length) { 14256 value = array[index]; 14257 if (value > 0xFFFF) { 14258 value -= 0x10000; 14259 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 14260 value = 0xDC00 | value & 0x3FF; 14261 } 14262 output += stringFromCharCode(value); 14263 } 14264 return output; 14265 } 14266 14267 function checkScalarValue(codePoint) { 14268 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 14269 throw Error( 14270 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 14271 ' is not a scalar value' 14272 ); 14273 } 14274 } 14275 /*--------------------------------------------------------------------------*/ 14276 14277 function createByte(codePoint, shift) { 14278 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 14279 } 14280 14281 function encodeCodePoint(codePoint) { 14282 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 14283 return stringFromCharCode(codePoint); 14284 } 14285 var symbol = ''; 14286 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 14287 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 14288 } 14289 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 14290 checkScalarValue(codePoint); 14291 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 14292 symbol += createByte(codePoint, 6); 14293 } 14294 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 14295 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 14296 symbol += createByte(codePoint, 12); 14297 symbol += createByte(codePoint, 6); 14298 } 14299 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 14300 return symbol; 14301 } 14302 14303 function utf8encode(string) { 14304 var codePoints = ucs2decode(string); 14305 var length = codePoints.length; 14306 var index = -1; 14307 var codePoint; 14308 var byteString = ''; 14309 while (++index < length) { 14310 codePoint = codePoints[index]; 14311 byteString += encodeCodePoint(codePoint); 14312 } 14313 return byteString; 14314 } 14315 14316 /*--------------------------------------------------------------------------*/ 14317 14318 function readContinuationByte() { 14319 if (byteIndex >= byteCount) { 14320 throw Error('Invalid byte index'); 14321 } 14322 14323 var continuationByte = byteArray[byteIndex] & 0xFF; 14324 byteIndex++; 14325 14326 if ((continuationByte & 0xC0) == 0x80) { 14327 return continuationByte & 0x3F; 14328 } 14329 14330 // If we end up here, it’s not a continuation byte 14331 throw Error('Invalid continuation byte'); 14332 } 14333 14334 function decodeSymbol() { 14335 var byte1; 14336 var byte2; 14337 var byte3; 14338 var byte4; 14339 var codePoint; 14340 14341 if (byteIndex > byteCount) { 14342 throw Error('Invalid byte index'); 14343 } 14344 14345 if (byteIndex == byteCount) { 14346 return false; 14347 } 14348 14349 // Read first byte 14350 byte1 = byteArray[byteIndex] & 0xFF; 14351 byteIndex++; 14352 14353 // 1-byte sequence (no continuation bytes) 14354 if ((byte1 & 0x80) == 0) { 14355 return byte1; 14356 } 14357 14358 // 2-byte sequence 14359 if ((byte1 & 0xE0) == 0xC0) { 14360 byte2 = readContinuationByte(); 14361 codePoint = ((byte1 & 0x1F) << 6) | byte2; 14362 if (codePoint >= 0x80) { 14363 return codePoint; 14364 } else { 14365 throw Error('Invalid continuation byte'); 14366 } 14367 } 14368 14369 // 3-byte sequence (may include unpaired surrogates) 14370 if ((byte1 & 0xF0) == 0xE0) { 14371 byte2 = readContinuationByte(); 14372 byte3 = readContinuationByte(); 14373 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 14374 if (codePoint >= 0x0800) { 14375 checkScalarValue(codePoint); 14376 return codePoint; 14377 } else { 14378 throw Error('Invalid continuation byte'); 14379 } 14380 } 14381 14382 // 4-byte sequence 14383 if ((byte1 & 0xF8) == 0xF0) { 14384 byte2 = readContinuationByte(); 14385 byte3 = readContinuationByte(); 14386 byte4 = readContinuationByte(); 14387 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 14388 (byte3 << 0x06) | byte4; 14389 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 14390 return codePoint; 14391 } 14392 } 14393 14394 throw Error('Invalid UTF-8 detected'); 14395 } 14396 14397 var byteArray; 14398 var byteCount; 14399 var byteIndex; 14400 function utf8decode(byteString) { 14401 byteArray = ucs2decode(byteString); 14402 byteCount = byteArray.length; 14403 byteIndex = 0; 14404 var codePoints = []; 14405 var tmp; 14406 while ((tmp = decodeSymbol()) !== false) { 14407 codePoints.push(tmp); 14408 } 14409 return ucs2encode(codePoints); 14410 } 14411 14412 /*--------------------------------------------------------------------------*/ 14413 14414 var utf8 = { 14415 'version': '2.1.2', 14416 'encode': utf8encode, 14417 'decode': utf8decode 14418 }; 14419 14420 // Some AMD build optimizers, like r.js, check for specific condition patterns 14421 // like the following: 14422 if ( 14423 typeof define == 'function' && 14424 typeof define.amd == 'object' && 14425 define.amd 14426 ) { 14427 define(function() { 14428 return utf8; 14429 }); 14430 } else if (freeExports && !freeExports.nodeType) { 14431 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 14432 freeModule.exports = utf8; 14433 } else { // in Narwhal or RingoJS v0.7.0- 14434 var object = {}; 14435 var hasOwnProperty = object.hasOwnProperty; 14436 for (var key in utf8) { 14437 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 14438 } 14439 } 14440 } else { // in Rhino or a web browser 14441 root.utf8 = utf8; 14442 } 14443 14444 }(this)); 14445 14446 },{}],86:[function(require,module,exports){ 14447 module.exports = XMLHttpRequest; 14448 14449 },{}],"bignumber.js":[function(require,module,exports){ 14450 'use strict'; 14451 14452 module.exports = BigNumber; // jshint ignore:line 14453 14454 14455 },{}],"web3":[function(require,module,exports){ 14456 var Web3 = require('./lib/web3'); 14457 14458 // don't override global variable 14459 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 14460 window.Web3 = Web3; 14461 } 14462 14463 module.exports = Web3; 14464 14465 },{"./lib/web3":22}]},{},["web3"]) 14466 //# sourceMappingURL=web3-light.js.map 14467 //