github.com/klaytn/klaytn@v1.12.1/console/jsre/deps/web3.js (about) 1 // Modifications Copyright 2018 The klaytn Authors 2 // Copyright 2017 The go-ethereum Authors 3 // This file is part of the go-ethereum library. 4 // 5 // The go-ethereum library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-ethereum library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 17 // 18 // This file is derived from internal/jsre/deps/web3.js (2018/06/04). 19 // Modified and improved for the klaytn development. 20 21 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){ 22 module.exports=[ 23 { 24 "constant": true, 25 "inputs": [ 26 { 27 "name": "_owner", 28 "type": "address" 29 } 30 ], 31 "name": "name", 32 "outputs": [ 33 { 34 "name": "o_name", 35 "type": "bytes32" 36 } 37 ], 38 "type": "function" 39 }, 40 { 41 "constant": true, 42 "inputs": [ 43 { 44 "name": "_name", 45 "type": "bytes32" 46 } 47 ], 48 "name": "owner", 49 "outputs": [ 50 { 51 "name": "", 52 "type": "address" 53 } 54 ], 55 "type": "function" 56 }, 57 { 58 "constant": true, 59 "inputs": [ 60 { 61 "name": "_name", 62 "type": "bytes32" 63 } 64 ], 65 "name": "content", 66 "outputs": [ 67 { 68 "name": "", 69 "type": "bytes32" 70 } 71 ], 72 "type": "function" 73 }, 74 { 75 "constant": true, 76 "inputs": [ 77 { 78 "name": "_name", 79 "type": "bytes32" 80 } 81 ], 82 "name": "addr", 83 "outputs": [ 84 { 85 "name": "", 86 "type": "address" 87 } 88 ], 89 "type": "function" 90 }, 91 { 92 "constant": false, 93 "inputs": [ 94 { 95 "name": "_name", 96 "type": "bytes32" 97 } 98 ], 99 "name": "reserve", 100 "outputs": [], 101 "type": "function" 102 }, 103 { 104 "constant": true, 105 "inputs": [ 106 { 107 "name": "_name", 108 "type": "bytes32" 109 } 110 ], 111 "name": "subRegistrar", 112 "outputs": [ 113 { 114 "name": "", 115 "type": "address" 116 } 117 ], 118 "type": "function" 119 }, 120 { 121 "constant": false, 122 "inputs": [ 123 { 124 "name": "_name", 125 "type": "bytes32" 126 }, 127 { 128 "name": "_newOwner", 129 "type": "address" 130 } 131 ], 132 "name": "transfer", 133 "outputs": [], 134 "type": "function" 135 }, 136 { 137 "constant": false, 138 "inputs": [ 139 { 140 "name": "_name", 141 "type": "bytes32" 142 }, 143 { 144 "name": "_registrar", 145 "type": "address" 146 } 147 ], 148 "name": "setSubRegistrar", 149 "outputs": [], 150 "type": "function" 151 }, 152 { 153 "constant": false, 154 "inputs": [], 155 "name": "Registrar", 156 "outputs": [], 157 "type": "function" 158 }, 159 { 160 "constant": false, 161 "inputs": [ 162 { 163 "name": "_name", 164 "type": "bytes32" 165 }, 166 { 167 "name": "_a", 168 "type": "address" 169 }, 170 { 171 "name": "_primary", 172 "type": "bool" 173 } 174 ], 175 "name": "setAddress", 176 "outputs": [], 177 "type": "function" 178 }, 179 { 180 "constant": false, 181 "inputs": [ 182 { 183 "name": "_name", 184 "type": "bytes32" 185 }, 186 { 187 "name": "_content", 188 "type": "bytes32" 189 } 190 ], 191 "name": "setContent", 192 "outputs": [], 193 "type": "function" 194 }, 195 { 196 "constant": false, 197 "inputs": [ 198 { 199 "name": "_name", 200 "type": "bytes32" 201 } 202 ], 203 "name": "disown", 204 "outputs": [], 205 "type": "function" 206 }, 207 { 208 "anonymous": false, 209 "inputs": [ 210 { 211 "indexed": true, 212 "name": "_name", 213 "type": "bytes32" 214 }, 215 { 216 "indexed": false, 217 "name": "_winner", 218 "type": "address" 219 } 220 ], 221 "name": "AuctionEnded", 222 "type": "event" 223 }, 224 { 225 "anonymous": false, 226 "inputs": [ 227 { 228 "indexed": true, 229 "name": "_name", 230 "type": "bytes32" 231 }, 232 { 233 "indexed": false, 234 "name": "_bidder", 235 "type": "address" 236 }, 237 { 238 "indexed": false, 239 "name": "_value", 240 "type": "uint256" 241 } 242 ], 243 "name": "NewBid", 244 "type": "event" 245 }, 246 { 247 "anonymous": false, 248 "inputs": [ 249 { 250 "indexed": true, 251 "name": "name", 252 "type": "bytes32" 253 } 254 ], 255 "name": "Changed", 256 "type": "event" 257 }, 258 { 259 "anonymous": false, 260 "inputs": [ 261 { 262 "indexed": true, 263 "name": "name", 264 "type": "bytes32" 265 }, 266 { 267 "indexed": true, 268 "name": "addr", 269 "type": "address" 270 } 271 ], 272 "name": "PrimaryChanged", 273 "type": "event" 274 } 275 ] 276 277 },{}],2:[function(require,module,exports){ 278 module.exports=[ 279 { 280 "constant": true, 281 "inputs": [ 282 { 283 "name": "_name", 284 "type": "bytes32" 285 } 286 ], 287 "name": "owner", 288 "outputs": [ 289 { 290 "name": "", 291 "type": "address" 292 } 293 ], 294 "type": "function" 295 }, 296 { 297 "constant": false, 298 "inputs": [ 299 { 300 "name": "_name", 301 "type": "bytes32" 302 }, 303 { 304 "name": "_refund", 305 "type": "address" 306 } 307 ], 308 "name": "disown", 309 "outputs": [], 310 "type": "function" 311 }, 312 { 313 "constant": true, 314 "inputs": [ 315 { 316 "name": "_name", 317 "type": "bytes32" 318 } 319 ], 320 "name": "addr", 321 "outputs": [ 322 { 323 "name": "", 324 "type": "address" 325 } 326 ], 327 "type": "function" 328 }, 329 { 330 "constant": false, 331 "inputs": [ 332 { 333 "name": "_name", 334 "type": "bytes32" 335 } 336 ], 337 "name": "reserve", 338 "outputs": [], 339 "type": "function" 340 }, 341 { 342 "constant": false, 343 "inputs": [ 344 { 345 "name": "_name", 346 "type": "bytes32" 347 }, 348 { 349 "name": "_newOwner", 350 "type": "address" 351 } 352 ], 353 "name": "transfer", 354 "outputs": [], 355 "type": "function" 356 }, 357 { 358 "constant": false, 359 "inputs": [ 360 { 361 "name": "_name", 362 "type": "bytes32" 363 }, 364 { 365 "name": "_a", 366 "type": "address" 367 } 368 ], 369 "name": "setAddr", 370 "outputs": [], 371 "type": "function" 372 }, 373 { 374 "anonymous": false, 375 "inputs": [ 376 { 377 "indexed": true, 378 "name": "name", 379 "type": "bytes32" 380 } 381 ], 382 "name": "Changed", 383 "type": "event" 384 } 385 ] 386 387 },{}],3:[function(require,module,exports){ 388 module.exports=[ 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": "value", 402 "type": "uint256" 403 } 404 ], 405 "name": "transfer", 406 "outputs": [], 407 "type": "function" 408 }, 409 { 410 "constant": false, 411 "inputs": [ 412 { 413 "name": "from", 414 "type": "bytes32" 415 }, 416 { 417 "name": "to", 418 "type": "address" 419 }, 420 { 421 "name": "indirectId", 422 "type": "bytes32" 423 }, 424 { 425 "name": "value", 426 "type": "uint256" 427 } 428 ], 429 "name": "icapTransfer", 430 "outputs": [], 431 "type": "function" 432 }, 433 { 434 "constant": false, 435 "inputs": [ 436 { 437 "name": "to", 438 "type": "bytes32" 439 } 440 ], 441 "name": "deposit", 442 "outputs": [], 443 "payable": true, 444 "type": "function" 445 }, 446 { 447 "anonymous": false, 448 "inputs": [ 449 { 450 "indexed": true, 451 "name": "from", 452 "type": "address" 453 }, 454 { 455 "indexed": false, 456 "name": "value", 457 "type": "uint256" 458 } 459 ], 460 "name": "AnonymousDeposit", 461 "type": "event" 462 }, 463 { 464 "anonymous": false, 465 "inputs": [ 466 { 467 "indexed": true, 468 "name": "from", 469 "type": "address" 470 }, 471 { 472 "indexed": true, 473 "name": "to", 474 "type": "bytes32" 475 }, 476 { 477 "indexed": false, 478 "name": "value", 479 "type": "uint256" 480 } 481 ], 482 "name": "Deposit", 483 "type": "event" 484 }, 485 { 486 "anonymous": false, 487 "inputs": [ 488 { 489 "indexed": true, 490 "name": "from", 491 "type": "bytes32" 492 }, 493 { 494 "indexed": true, 495 "name": "to", 496 "type": "address" 497 }, 498 { 499 "indexed": false, 500 "name": "value", 501 "type": "uint256" 502 } 503 ], 504 "name": "Transfer", 505 "type": "event" 506 }, 507 { 508 "anonymous": false, 509 "inputs": [ 510 { 511 "indexed": true, 512 "name": "from", 513 "type": "bytes32" 514 }, 515 { 516 "indexed": true, 517 "name": "to", 518 "type": "address" 519 }, 520 { 521 "indexed": false, 522 "name": "indirectId", 523 "type": "bytes32" 524 }, 525 { 526 "indexed": false, 527 "name": "value", 528 "type": "uint256" 529 } 530 ], 531 "name": "IcapTransfer", 532 "type": "event" 533 } 534 ] 535 536 },{}],4:[function(require,module,exports){ 537 var f = require('./formatters'); 538 var SolidityType = require('./type'); 539 540 /** 541 * SolidityTypeAddress is a prootype that represents address type 542 * It matches: 543 * address 544 * address[] 545 * address[4] 546 * address[][] 547 * address[3][] 548 * address[][6][], ... 549 */ 550 var SolidityTypeAddress = function () { 551 this._inputFormatter = f.formatInputInt; 552 this._outputFormatter = f.formatOutputAddress; 553 }; 554 555 SolidityTypeAddress.prototype = new SolidityType({}); 556 SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 557 558 SolidityTypeAddress.prototype.isType = function (name) { 559 return !!name.match(/address(\[([0-9]*)\])?/); 560 }; 561 562 module.exports = SolidityTypeAddress; 563 564 },{"./formatters":9,"./type":14}],5:[function(require,module,exports){ 565 var f = require('./formatters'); 566 var SolidityType = require('./type'); 567 568 /** 569 * SolidityTypeBool is a prootype that represents bool type 570 * It matches: 571 * bool 572 * bool[] 573 * bool[4] 574 * bool[][] 575 * bool[3][] 576 * bool[][6][], ... 577 */ 578 var SolidityTypeBool = function () { 579 this._inputFormatter = f.formatInputBool; 580 this._outputFormatter = f.formatOutputBool; 581 }; 582 583 SolidityTypeBool.prototype = new SolidityType({}); 584 SolidityTypeBool.prototype.constructor = SolidityTypeBool; 585 586 SolidityTypeBool.prototype.isType = function (name) { 587 return !!name.match(/^bool(\[([0-9]*)\])*$/); 588 }; 589 590 module.exports = SolidityTypeBool; 591 592 },{"./formatters":9,"./type":14}],6:[function(require,module,exports){ 593 var f = require('./formatters'); 594 var SolidityType = require('./type'); 595 596 /** 597 * SolidityTypeBytes is a prototype that represents the bytes type. 598 * It matches: 599 * bytes 600 * bytes[] 601 * bytes[4] 602 * bytes[][] 603 * bytes[3][] 604 * bytes[][6][], ... 605 * bytes32 606 * bytes8[4] 607 * bytes[3][] 608 */ 609 var SolidityTypeBytes = function () { 610 this._inputFormatter = f.formatInputBytes; 611 this._outputFormatter = f.formatOutputBytes; 612 }; 613 614 SolidityTypeBytes.prototype = new SolidityType({}); 615 SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 616 617 SolidityTypeBytes.prototype.isType = function (name) { 618 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 619 }; 620 621 module.exports = SolidityTypeBytes; 622 623 },{"./formatters":9,"./type":14}],7:[function(require,module,exports){ 624 /* 625 This file is part of web3.js. 626 627 web3.js is free software: you can redistribute it and/or modify 628 it under the terms of the GNU Lesser General Public License as published by 629 the Free Software Foundation, either version 3 of the License, or 630 (at your option) any later version. 631 632 web3.js is distributed in the hope that it will be useful, 633 but WITHOUT ANY WARRANTY; without even the implied warranty of 634 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 635 GNU Lesser General Public License for more details. 636 637 You should have received a copy of the GNU Lesser General Public License 638 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 639 */ 640 /** 641 * @file coder.js 642 * @author Marek Kotewicz <marek@ethdev.com> 643 * @date 2015 644 */ 645 646 var f = require('./formatters'); 647 648 var SolidityTypeAddress = require('./address'); 649 var SolidityTypeBool = require('./bool'); 650 var SolidityTypeInt = require('./int'); 651 var SolidityTypeUInt = require('./uint'); 652 var SolidityTypeDynamicBytes = require('./dynamicbytes'); 653 var SolidityTypeString = require('./string'); 654 var SolidityTypeReal = require('./real'); 655 var SolidityTypeUReal = require('./ureal'); 656 var SolidityTypeBytes = require('./bytes'); 657 658 var isDynamic = function (solidityType, type) { 659 return solidityType.isDynamicType(type) || 660 solidityType.isDynamicArray(type); 661 }; 662 663 /** 664 * SolidityCoder prototype should be used to encode/decode solidity params of any type 665 */ 666 var SolidityCoder = function (types) { 667 this._types = types; 668 }; 669 670 /** 671 * This method should be used to transform type to SolidityType 672 * 673 * @method _requireType 674 * @param {String} type 675 * @returns {SolidityType} 676 * @throws {Error} throws if no matching type is found 677 */ 678 SolidityCoder.prototype._requireType = function (type) { 679 var solidityType = this._types.filter(function (t) { 680 return t.isType(type); 681 })[0]; 682 683 if (!solidityType) { 684 throw Error('invalid solidity type!: ' + type); 685 } 686 687 return solidityType; 688 }; 689 690 /** 691 * Should be used to encode plain param 692 * 693 * @method encodeParam 694 * @param {String} type 695 * @param {Object} plain param 696 * @return {String} encoded plain param 697 */ 698 SolidityCoder.prototype.encodeParam = function (type, param) { 699 return this.encodeParams([type], [param]); 700 }; 701 702 /** 703 * Should be used to encode list of params 704 * 705 * @method encodeParams 706 * @param {Array} types 707 * @param {Array} params 708 * @return {String} encoded list of params 709 */ 710 SolidityCoder.prototype.encodeParams = function (types, params) { 711 var solidityTypes = this.getSolidityTypes(types); 712 713 var encodeds = solidityTypes.map(function (solidityType, index) { 714 return solidityType.encode(params[index], types[index]); 715 }); 716 717 var dynamicOffset = solidityTypes.reduce(function (acc, solidityType, index) { 718 var staticPartLength = solidityType.staticPartLength(types[index]); 719 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 720 721 return acc + (isDynamic(solidityTypes[index], types[index]) ? 722 32 : 723 roundedStaticPartLength); 724 }, 0); 725 726 var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset); 727 728 return result; 729 }; 730 731 SolidityCoder.prototype.encodeMultiWithOffset = function (types, solidityTypes, encodeds, dynamicOffset) { 732 var result = ""; 733 var self = this; 734 735 types.forEach(function (type, i) { 736 if (isDynamic(solidityTypes[i], types[i])) { 737 result += f.formatInputInt(dynamicOffset).encode(); 738 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 739 dynamicOffset += e.length / 2; 740 } else { 741 // don't add length to dynamicOffset. it's already counted 742 result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 743 } 744 745 // TODO: figure out nested arrays 746 }); 747 748 types.forEach(function (type, i) { 749 if (isDynamic(solidityTypes[i], types[i])) { 750 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 751 dynamicOffset += e.length / 2; 752 result += e; 753 } 754 }); 755 return result; 756 }; 757 758 // TODO: refactor whole encoding! 759 SolidityCoder.prototype.encodeWithOffset = function (type, solidityType, encoded, offset) { 760 var self = this; 761 if (solidityType.isDynamicArray(type)) { 762 return (function () { 763 // offset was already set 764 var nestedName = solidityType.nestedName(type); 765 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 766 var result = encoded[0]; 767 768 (function () { 769 var previousLength = 2; // in int 770 if (solidityType.isDynamicArray(nestedName)) { 771 for (var i = 1; i < encoded.length; i++) { 772 previousLength += +(encoded[i - 1])[0] || 0; 773 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 774 } 775 } 776 })(); 777 778 // first element is length, skip it 779 (function () { 780 for (var i = 0; i < encoded.length - 1; i++) { 781 var additionalOffset = result / 2; 782 result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset); 783 } 784 })(); 785 786 return result; 787 })(); 788 789 } else if (solidityType.isStaticArray(type)) { 790 return (function () { 791 var nestedName = solidityType.nestedName(type); 792 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 793 var result = ""; 794 795 796 if (solidityType.isDynamicArray(nestedName)) { 797 (function () { 798 var previousLength = 0; // in int 799 for (var i = 0; i < encoded.length; i++) { 800 // calculate length of previous item 801 previousLength += +(encoded[i - 1] || [])[0] || 0; 802 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 803 } 804 })(); 805 } 806 807 (function () { 808 for (var i = 0; i < encoded.length; i++) { 809 var additionalOffset = result / 2; 810 result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset); 811 } 812 })(); 813 814 return result; 815 })(); 816 } 817 818 return encoded; 819 }; 820 821 /** 822 * Should be used to decode bytes to plain param 823 * 824 * @method decodeParam 825 * @param {String} type 826 * @param {String} bytes 827 * @return {Object} plain param 828 */ 829 SolidityCoder.prototype.decodeParam = function (type, bytes) { 830 return this.decodeParams([type], bytes)[0]; 831 }; 832 833 /** 834 * Should be used to decode list of params 835 * 836 * @method decodeParam 837 * @param {Array} types 838 * @param {String} bytes 839 * @return {Array} array of plain params 840 */ 841 SolidityCoder.prototype.decodeParams = function (types, bytes) { 842 var solidityTypes = this.getSolidityTypes(types); 843 var offsets = this.getOffsets(types, solidityTypes); 844 845 return solidityTypes.map(function (solidityType, index) { 846 return solidityType.decode(bytes, offsets[index], types[index], index); 847 }); 848 }; 849 850 SolidityCoder.prototype.getOffsets = function (types, solidityTypes) { 851 var lengths = solidityTypes.map(function (solidityType, index) { 852 return solidityType.staticPartLength(types[index]); 853 }); 854 855 for (var i = 1; i < lengths.length; i++) { 856 // sum with length of previous element 857 lengths[i] += lengths[i - 1]; 858 } 859 860 return lengths.map(function (length, index) { 861 // remove the current length, so the length is sum of previous elements 862 var staticPartLength = solidityTypes[index].staticPartLength(types[index]); 863 return length - staticPartLength; 864 }); 865 }; 866 867 SolidityCoder.prototype.getSolidityTypes = function (types) { 868 var self = this; 869 return types.map(function (type) { 870 return self._requireType(type); 871 }); 872 }; 873 874 var coder = new SolidityCoder([ 875 new SolidityTypeAddress(), 876 new SolidityTypeBool(), 877 new SolidityTypeInt(), 878 new SolidityTypeUInt(), 879 new SolidityTypeDynamicBytes(), 880 new SolidityTypeBytes(), 881 new SolidityTypeString(), 882 new SolidityTypeReal(), 883 new SolidityTypeUReal() 884 ]); 885 886 module.exports = coder; 887 888 },{"./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){ 889 var f = require('./formatters'); 890 var SolidityType = require('./type'); 891 892 var SolidityTypeDynamicBytes = function () { 893 this._inputFormatter = f.formatInputDynamicBytes; 894 this._outputFormatter = f.formatOutputDynamicBytes; 895 }; 896 897 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 898 SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 899 900 SolidityTypeDynamicBytes.prototype.isType = function (name) { 901 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 902 }; 903 904 SolidityTypeDynamicBytes.prototype.isDynamicType = function () { 905 return true; 906 }; 907 908 module.exports = SolidityTypeDynamicBytes; 909 910 },{"./formatters":9,"./type":14}],9:[function(require,module,exports){ 911 /* 912 This file is part of web3.js. 913 914 web3.js is free software: you can redistribute it and/or modify 915 it under the terms of the GNU Lesser General Public License as published by 916 the Free Software Foundation, either version 3 of the License, or 917 (at your option) any later version. 918 919 web3.js is distributed in the hope that it will be useful, 920 but WITHOUT ANY WARRANTY; without even the implied warranty of 921 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 922 GNU Lesser General Public License for more details. 923 924 You should have received a copy of the GNU Lesser General Public License 925 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 926 */ 927 /** 928 * @file formatters.js 929 * @author Marek Kotewicz <marek@ethdev.com> 930 * @date 2015 931 */ 932 933 var BigNumber = require('bignumber.js'); 934 var utils = require('../utils/utils'); 935 var c = require('../utils/config'); 936 var SolidityParam = require('./param'); 937 938 939 /** 940 * Formats input value to byte representation of int 941 * If value is negative, return it's two's complement 942 * If the value is floating point, round it down 943 * 944 * @method formatInputInt 945 * @param {String|Number|BigNumber} value that needs to be formatted 946 * @returns {SolidityParam} 947 */ 948 var formatInputInt = function (value) { 949 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 950 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 951 return new SolidityParam(result); 952 }; 953 954 /** 955 * Formats input bytes 956 * 957 * @method formatInputBytes 958 * @param {String} 959 * @returns {SolidityParam} 960 */ 961 var formatInputBytes = function (value) { 962 var result = utils.toHex(value).substr(2); 963 var l = Math.floor((result.length + 63) / 64); 964 result = utils.padRight(result, l * 64); 965 return new SolidityParam(result); 966 }; 967 968 /** 969 * Formats input bytes 970 * 971 * @method formatDynamicInputBytes 972 * @param {String} 973 * @returns {SolidityParam} 974 */ 975 var formatInputDynamicBytes = function (value) { 976 var result = utils.toHex(value).substr(2); 977 var length = result.length / 2; 978 var l = Math.floor((result.length + 63) / 64); 979 result = utils.padRight(result, l * 64); 980 return new SolidityParam(formatInputInt(length).value + result); 981 }; 982 983 /** 984 * Formats input value to byte representation of string 985 * 986 * @method formatInputString 987 * @param {String} 988 * @returns {SolidityParam} 989 */ 990 var formatInputString = function (value) { 991 var result = utils.fromUtf8(value).substr(2); 992 var length = result.length / 2; 993 var l = Math.floor((result.length + 63) / 64); 994 result = utils.padRight(result, l * 64); 995 return new SolidityParam(formatInputInt(length).value + result); 996 }; 997 998 /** 999 * Formats input value to byte representation of bool 1000 * 1001 * @method formatInputBool 1002 * @param {Boolean} 1003 * @returns {SolidityParam} 1004 */ 1005 var formatInputBool = function (value) { 1006 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 1007 return new SolidityParam(result); 1008 }; 1009 1010 /** 1011 * Formats input value to byte representation of real 1012 * Values are multiplied by 2^m and encoded as integers 1013 * 1014 * @method formatInputReal 1015 * @param {String|Number|BigNumber} 1016 * @returns {SolidityParam} 1017 */ 1018 var formatInputReal = function (value) { 1019 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1020 }; 1021 1022 /** 1023 * Check if input value is negative 1024 * 1025 * @method signedIsNegative 1026 * @param {String} value is hex format 1027 * @returns {Boolean} true if it is negative, otherwise false 1028 */ 1029 var signedIsNegative = function (value) { 1030 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1031 }; 1032 1033 /** 1034 * Formats right-aligned output bytes to int 1035 * 1036 * @method formatOutputInt 1037 * @param {SolidityParam} param 1038 * @returns {BigNumber} right-aligned output bytes formatted to big number 1039 */ 1040 var formatOutputInt = function (param) { 1041 var value = param.staticPart() || "0"; 1042 1043 // check if it's negative number 1044 // if it is, return two's complement 1045 if (signedIsNegative(value)) { 1046 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1047 } 1048 return new BigNumber(value, 16); 1049 }; 1050 1051 /** 1052 * Formats right-aligned output bytes to uint 1053 * 1054 * @method formatOutputUInt 1055 * @param {SolidityParam} 1056 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1057 */ 1058 var formatOutputUInt = function (param) { 1059 var value = param.staticPart() || "0"; 1060 return new BigNumber(value, 16); 1061 }; 1062 1063 /** 1064 * Formats right-aligned output bytes to real 1065 * 1066 * @method formatOutputReal 1067 * @param {SolidityParam} 1068 * @returns {BigNumber} input bytes formatted to real 1069 */ 1070 var formatOutputReal = function (param) { 1071 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1072 }; 1073 1074 /** 1075 * Formats right-aligned output bytes to ureal 1076 * 1077 * @method formatOutputUReal 1078 * @param {SolidityParam} 1079 * @returns {BigNumber} input bytes formatted to ureal 1080 */ 1081 var formatOutputUReal = function (param) { 1082 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1083 }; 1084 1085 /** 1086 * Should be used to format output bool 1087 * 1088 * @method formatOutputBool 1089 * @param {SolidityParam} 1090 * @returns {Boolean} right-aligned input bytes formatted to bool 1091 */ 1092 var formatOutputBool = function (param) { 1093 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1094 }; 1095 1096 /** 1097 * Should be used to format output bytes 1098 * 1099 * @method formatOutputBytes 1100 * @param {SolidityParam} left-aligned hex representation of string 1101 * @param {String} name type name 1102 * @returns {String} hex string 1103 */ 1104 var formatOutputBytes = function (param, name) { 1105 var matches = name.match(/^bytes([0-9]*)/); 1106 var size = parseInt(matches[1]); 1107 return '0x' + param.staticPart().slice(0, 2 * size); 1108 }; 1109 1110 /** 1111 * Should be used to format output bytes 1112 * 1113 * @method formatOutputDynamicBytes 1114 * @param {SolidityParam} left-aligned hex representation of string 1115 * @returns {String} hex string 1116 */ 1117 var formatOutputDynamicBytes = function (param) { 1118 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1119 return '0x' + param.dynamicPart().substr(64, length); 1120 }; 1121 1122 /** 1123 * Should be used to format output string 1124 * 1125 * @method formatOutputString 1126 * @param {SolidityParam} left-aligned hex representation of string 1127 * @returns {String} ascii string 1128 */ 1129 var formatOutputString = function (param) { 1130 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1131 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1132 }; 1133 1134 /** 1135 * Should be used to format output address 1136 * 1137 * @method formatOutputAddress 1138 * @param {SolidityParam} right-aligned input bytes 1139 * @returns {String} address 1140 */ 1141 var formatOutputAddress = function (param) { 1142 var value = param.staticPart(); 1143 return "0x" + value.slice(value.length - 40, value.length); 1144 }; 1145 1146 module.exports = { 1147 formatInputInt: formatInputInt, 1148 formatInputBytes: formatInputBytes, 1149 formatInputDynamicBytes: formatInputDynamicBytes, 1150 formatInputString: formatInputString, 1151 formatInputBool: formatInputBool, 1152 formatInputReal: formatInputReal, 1153 formatOutputInt: formatOutputInt, 1154 formatOutputUInt: formatOutputUInt, 1155 formatOutputReal: formatOutputReal, 1156 formatOutputUReal: formatOutputUReal, 1157 formatOutputBool: formatOutputBool, 1158 formatOutputBytes: formatOutputBytes, 1159 formatOutputDynamicBytes: formatOutputDynamicBytes, 1160 formatOutputString: formatOutputString, 1161 formatOutputAddress: formatOutputAddress 1162 }; 1163 1164 },{"../utils/config":18,"../utils/utils":20,"./param":11,"bignumber.js":"bignumber.js"}],10:[function(require,module,exports){ 1165 var f = require('./formatters'); 1166 var SolidityType = require('./type'); 1167 1168 /** 1169 * SolidityTypeInt is a prootype that represents int type 1170 * It matches: 1171 * int 1172 * int[] 1173 * int[4] 1174 * int[][] 1175 * int[3][] 1176 * int[][6][], ... 1177 * int32 1178 * int64[] 1179 * int8[4] 1180 * int256[][] 1181 * int[3][] 1182 * int64[][6][], ... 1183 */ 1184 var SolidityTypeInt = function () { 1185 this._inputFormatter = f.formatInputInt; 1186 this._outputFormatter = f.formatOutputInt; 1187 }; 1188 1189 SolidityTypeInt.prototype = new SolidityType({}); 1190 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1191 1192 SolidityTypeInt.prototype.isType = function (name) { 1193 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1194 }; 1195 1196 module.exports = SolidityTypeInt; 1197 1198 },{"./formatters":9,"./type":14}],11:[function(require,module,exports){ 1199 /* 1200 This file is part of web3.js. 1201 1202 web3.js is free software: you can redistribute it and/or modify 1203 it under the terms of the GNU Lesser General Public License as published by 1204 the Free Software Foundation, either version 3 of the License, or 1205 (at your option) any later version. 1206 1207 web3.js is distributed in the hope that it will be useful, 1208 but WITHOUT ANY WARRANTY; without even the implied warranty of 1209 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1210 GNU Lesser General Public License for more details. 1211 1212 You should have received a copy of the GNU Lesser General Public License 1213 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1214 */ 1215 /** 1216 * @file param.js 1217 * @author Marek Kotewicz <marek@ethdev.com> 1218 * @date 2015 1219 */ 1220 1221 var utils = require('../utils/utils'); 1222 1223 /** 1224 * SolidityParam object prototype. 1225 * Should be used when encoding, decoding solidity bytes 1226 */ 1227 var SolidityParam = function (value, offset) { 1228 this.value = value || ''; 1229 this.offset = offset; // offset in bytes 1230 }; 1231 1232 /** 1233 * This method should be used to get length of params's dynamic part 1234 * 1235 * @method dynamicPartLength 1236 * @returns {Number} length of dynamic part (in bytes) 1237 */ 1238 SolidityParam.prototype.dynamicPartLength = function () { 1239 return this.dynamicPart().length / 2; 1240 }; 1241 1242 /** 1243 * This method should be used to create copy of solidity param with different offset 1244 * 1245 * @method withOffset 1246 * @param {Number} offset length in bytes 1247 * @returns {SolidityParam} new solidity param with applied offset 1248 */ 1249 SolidityParam.prototype.withOffset = function (offset) { 1250 return new SolidityParam(this.value, offset); 1251 }; 1252 1253 /** 1254 * This method should be used to combine solidity params together 1255 * eg. when appending an array 1256 * 1257 * @method combine 1258 * @param {SolidityParam} param with which we should combine 1259 * @param {SolidityParam} result of combination 1260 */ 1261 SolidityParam.prototype.combine = function (param) { 1262 return new SolidityParam(this.value + param.value); 1263 }; 1264 1265 /** 1266 * This method should be called to check if param has dynamic size. 1267 * If it has, it returns true, otherwise false 1268 * 1269 * @method isDynamic 1270 * @returns {Boolean} 1271 */ 1272 SolidityParam.prototype.isDynamic = function () { 1273 return this.offset !== undefined; 1274 }; 1275 1276 /** 1277 * This method should be called to transform offset to bytes 1278 * 1279 * @method offsetAsBytes 1280 * @returns {String} bytes representation of offset 1281 */ 1282 SolidityParam.prototype.offsetAsBytes = function () { 1283 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1284 }; 1285 1286 /** 1287 * This method should be called to get static part of param 1288 * 1289 * @method staticPart 1290 * @returns {String} offset if it is a dynamic param, otherwise value 1291 */ 1292 SolidityParam.prototype.staticPart = function () { 1293 if (!this.isDynamic()) { 1294 return this.value; 1295 } 1296 return this.offsetAsBytes(); 1297 }; 1298 1299 /** 1300 * This method should be called to get dynamic part of param 1301 * 1302 * @method dynamicPart 1303 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1304 */ 1305 SolidityParam.prototype.dynamicPart = function () { 1306 return this.isDynamic() ? this.value : ''; 1307 }; 1308 1309 /** 1310 * This method should be called to encode param 1311 * 1312 * @method encode 1313 * @returns {String} 1314 */ 1315 SolidityParam.prototype.encode = function () { 1316 return this.staticPart() + this.dynamicPart(); 1317 }; 1318 1319 /** 1320 * This method should be called to encode array of params 1321 * 1322 * @method encodeList 1323 * @param {Array[SolidityParam]} params 1324 * @returns {String} 1325 */ 1326 SolidityParam.encodeList = function (params) { 1327 1328 // updating offsets 1329 var totalOffset = params.length * 32; 1330 var offsetParams = params.map(function (param) { 1331 if (!param.isDynamic()) { 1332 return param; 1333 } 1334 var offset = totalOffset; 1335 totalOffset += param.dynamicPartLength(); 1336 return param.withOffset(offset); 1337 }); 1338 1339 // encode everything! 1340 return offsetParams.reduce(function (result, param) { 1341 return result + param.dynamicPart(); 1342 }, offsetParams.reduce(function (result, param) { 1343 return result + param.staticPart(); 1344 }, '')); 1345 }; 1346 1347 1348 1349 module.exports = SolidityParam; 1350 1351 1352 },{"../utils/utils":20}],12:[function(require,module,exports){ 1353 var f = require('./formatters'); 1354 var SolidityType = require('./type'); 1355 1356 /** 1357 * SolidityTypeReal is a prootype that represents real type 1358 * It matches: 1359 * real 1360 * real[] 1361 * real[4] 1362 * real[][] 1363 * real[3][] 1364 * real[][6][], ... 1365 * real32 1366 * real64[] 1367 * real8[4] 1368 * real256[][] 1369 * real[3][] 1370 * real64[][6][], ... 1371 */ 1372 var SolidityTypeReal = function () { 1373 this._inputFormatter = f.formatInputReal; 1374 this._outputFormatter = f.formatOutputReal; 1375 }; 1376 1377 SolidityTypeReal.prototype = new SolidityType({}); 1378 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1379 1380 SolidityTypeReal.prototype.isType = function (name) { 1381 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1382 }; 1383 1384 module.exports = SolidityTypeReal; 1385 1386 },{"./formatters":9,"./type":14}],13:[function(require,module,exports){ 1387 var f = require('./formatters'); 1388 var SolidityType = require('./type'); 1389 1390 var SolidityTypeString = function () { 1391 this._inputFormatter = f.formatInputString; 1392 this._outputFormatter = f.formatOutputString; 1393 }; 1394 1395 SolidityTypeString.prototype = new SolidityType({}); 1396 SolidityTypeString.prototype.constructor = SolidityTypeString; 1397 1398 SolidityTypeString.prototype.isType = function (name) { 1399 return !!name.match(/^string(\[([0-9]*)\])*$/); 1400 }; 1401 1402 SolidityTypeString.prototype.isDynamicType = function () { 1403 return true; 1404 }; 1405 1406 module.exports = SolidityTypeString; 1407 1408 },{"./formatters":9,"./type":14}],14:[function(require,module,exports){ 1409 var f = require('./formatters'); 1410 var SolidityParam = require('./param'); 1411 1412 /** 1413 * SolidityType prototype is used to encode/decode solidity params of certain type 1414 */ 1415 var SolidityType = function (config) { 1416 this._inputFormatter = config.inputFormatter; 1417 this._outputFormatter = config.outputFormatter; 1418 }; 1419 1420 /** 1421 * Should be used to determine if this SolidityType do match given name 1422 * 1423 * @method isType 1424 * @param {String} name 1425 * @return {Bool} true if type match this SolidityType, otherwise false 1426 */ 1427 SolidityType.prototype.isType = function (name) { 1428 throw "this method should be overrwritten for type " + name; 1429 }; 1430 1431 /** 1432 * Should be used to determine what is the length of static part in given type 1433 * 1434 * @method staticPartLength 1435 * @param {String} name 1436 * @return {Number} length of static part in bytes 1437 */ 1438 SolidityType.prototype.staticPartLength = function (name) { 1439 // If name isn't an array then treat it like a single element array. 1440 return (this.nestedTypes(name) || ['[1]']) 1441 .map(function (type) { 1442 // the length of the nested array 1443 return parseInt(type.slice(1, -1), 10) || 1; 1444 }) 1445 .reduce(function (previous, current) { 1446 return previous * current; 1447 // all basic types are 32 bytes long 1448 }, 32); 1449 }; 1450 1451 /** 1452 * Should be used to determine if type is dynamic array 1453 * eg: 1454 * "type[]" => true 1455 * "type[4]" => false 1456 * 1457 * @method isDynamicArray 1458 * @param {String} name 1459 * @return {Bool} true if the type is dynamic array 1460 */ 1461 SolidityType.prototype.isDynamicArray = function (name) { 1462 var nestedTypes = this.nestedTypes(name); 1463 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1464 }; 1465 1466 /** 1467 * Should be used to determine if type is static array 1468 * eg: 1469 * "type[]" => false 1470 * "type[4]" => true 1471 * 1472 * @method isStaticArray 1473 * @param {String} name 1474 * @return {Bool} true if the type is static array 1475 */ 1476 SolidityType.prototype.isStaticArray = function (name) { 1477 var nestedTypes = this.nestedTypes(name); 1478 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1479 }; 1480 1481 /** 1482 * Should return length of static array 1483 * eg. 1484 * "int[32]" => 32 1485 * "int256[14]" => 14 1486 * "int[2][3]" => 3 1487 * "int" => 1 1488 * "int[1]" => 1 1489 * "int[]" => 1 1490 * 1491 * @method staticArrayLength 1492 * @param {String} name 1493 * @return {Number} static array length 1494 */ 1495 SolidityType.prototype.staticArrayLength = function (name) { 1496 var nestedTypes = this.nestedTypes(name); 1497 if (nestedTypes) { 1498 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1499 } 1500 return 1; 1501 }; 1502 1503 /** 1504 * Should return nested type 1505 * eg. 1506 * "int[32]" => "int" 1507 * "int256[14]" => "int256" 1508 * "int[2][3]" => "int[2]" 1509 * "int" => "int" 1510 * "int[]" => "int" 1511 * 1512 * @method nestedName 1513 * @param {String} name 1514 * @return {String} nested name 1515 */ 1516 SolidityType.prototype.nestedName = function (name) { 1517 // remove last [] in name 1518 var nestedTypes = this.nestedTypes(name); 1519 if (!nestedTypes) { 1520 return name; 1521 } 1522 1523 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1524 }; 1525 1526 /** 1527 * Should return true if type has dynamic size by default 1528 * such types are "string", "bytes" 1529 * 1530 * @method isDynamicType 1531 * @param {String} name 1532 * @return {Bool} true if is dynamic, otherwise false 1533 */ 1534 SolidityType.prototype.isDynamicType = function () { 1535 return false; 1536 }; 1537 1538 /** 1539 * Should return array of nested types 1540 * eg. 1541 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1542 * "int[] => ["[]"] 1543 * "int" => null 1544 * 1545 * @method nestedTypes 1546 * @param {String} name 1547 * @return {Array} array of nested types 1548 */ 1549 SolidityType.prototype.nestedTypes = function (name) { 1550 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1551 return name.match(/(\[[0-9]*\])/g); 1552 }; 1553 1554 /** 1555 * Should be used to encode the value 1556 * 1557 * @method encode 1558 * @param {Object} value 1559 * @param {String} name 1560 * @return {String} encoded value 1561 */ 1562 SolidityType.prototype.encode = function (value, name) { 1563 var self = this; 1564 if (this.isDynamicArray(name)) { 1565 1566 return (function () { 1567 var length = value.length; // in int 1568 var nestedName = self.nestedName(name); 1569 1570 var result = []; 1571 result.push(f.formatInputInt(length).encode()); 1572 1573 value.forEach(function (v) { 1574 result.push(self.encode(v, nestedName)); 1575 }); 1576 1577 return result; 1578 })(); 1579 1580 } else if (this.isStaticArray(name)) { 1581 1582 return (function () { 1583 var length = self.staticArrayLength(name); // in int 1584 var nestedName = self.nestedName(name); 1585 1586 var result = []; 1587 for (var i = 0; i < length; i++) { 1588 result.push(self.encode(value[i], nestedName)); 1589 } 1590 1591 return result; 1592 })(); 1593 1594 } 1595 1596 return this._inputFormatter(value, name).encode(); 1597 }; 1598 1599 /** 1600 * Should be used to decode value from bytes 1601 * 1602 * @method decode 1603 * @param {String} bytes 1604 * @param {Number} offset in bytes 1605 * @param {String} name type name 1606 * @returns {Object} decoded value 1607 */ 1608 SolidityType.prototype.decode = function (bytes, offset, name) { 1609 var self = this; 1610 1611 if (this.isDynamicArray(name)) { 1612 1613 return (function () { 1614 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1615 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1616 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1617 1618 var nestedName = self.nestedName(name); 1619 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1620 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1621 var result = []; 1622 1623 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1624 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1625 } 1626 1627 return result; 1628 })(); 1629 1630 } else if (this.isStaticArray(name)) { 1631 1632 return (function () { 1633 var length = self.staticArrayLength(name); // in int 1634 var arrayStart = offset; // in bytes 1635 1636 var nestedName = self.nestedName(name); 1637 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1638 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1639 var result = []; 1640 1641 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1642 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1643 } 1644 1645 return result; 1646 })(); 1647 } else if (this.isDynamicType(name)) { 1648 1649 return (function () { 1650 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1651 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1652 var roundedLength = Math.floor((length + 31) / 32); // in int 1653 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, ( 1 + roundedLength) * 64), 0); 1654 return self._outputFormatter(param, name); 1655 })(); 1656 } 1657 1658 var length = this.staticPartLength(name); 1659 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1660 return this._outputFormatter(param, name); 1661 }; 1662 1663 module.exports = SolidityType; 1664 1665 },{"./formatters":9,"./param":11}],15:[function(require,module,exports){ 1666 var f = require('./formatters'); 1667 var SolidityType = require('./type'); 1668 1669 /** 1670 * SolidityTypeUInt is a prootype that represents uint type 1671 * It matches: 1672 * uint 1673 * uint[] 1674 * uint[4] 1675 * uint[][] 1676 * uint[3][] 1677 * uint[][6][], ... 1678 * uint32 1679 * uint64[] 1680 * uint8[4] 1681 * uint256[][] 1682 * uint[3][] 1683 * uint64[][6][], ... 1684 */ 1685 var SolidityTypeUInt = function () { 1686 this._inputFormatter = f.formatInputInt; 1687 this._outputFormatter = f.formatOutputUInt; 1688 }; 1689 1690 SolidityTypeUInt.prototype = new SolidityType({}); 1691 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1692 1693 SolidityTypeUInt.prototype.isType = function (name) { 1694 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1695 }; 1696 1697 module.exports = SolidityTypeUInt; 1698 1699 },{"./formatters":9,"./type":14}],16:[function(require,module,exports){ 1700 var f = require('./formatters'); 1701 var SolidityType = require('./type'); 1702 1703 /** 1704 * SolidityTypeUReal is a prootype that represents ureal type 1705 * It matches: 1706 * ureal 1707 * ureal[] 1708 * ureal[4] 1709 * ureal[][] 1710 * ureal[3][] 1711 * ureal[][6][], ... 1712 * ureal32 1713 * ureal64[] 1714 * ureal8[4] 1715 * ureal256[][] 1716 * ureal[3][] 1717 * ureal64[][6][], ... 1718 */ 1719 var SolidityTypeUReal = function () { 1720 this._inputFormatter = f.formatInputReal; 1721 this._outputFormatter = f.formatOutputUReal; 1722 }; 1723 1724 SolidityTypeUReal.prototype = new SolidityType({}); 1725 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1726 1727 SolidityTypeUReal.prototype.isType = function (name) { 1728 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1729 }; 1730 1731 module.exports = SolidityTypeUReal; 1732 1733 },{"./formatters":9,"./type":14}],17:[function(require,module,exports){ 1734 'use strict'; 1735 1736 // go env doesn't have and need XMLHttpRequest 1737 if (typeof XMLHttpRequest === 'undefined') { 1738 exports.XMLHttpRequest = {}; 1739 } else { 1740 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1741 } 1742 1743 1744 },{}],18:[function(require,module,exports){ 1745 /* 1746 This file is part of web3.js. 1747 1748 web3.js is free software: you can redistribute it and/or modify 1749 it under the terms of the GNU Lesser General Public License as published by 1750 the Free Software Foundation, either version 3 of the License, or 1751 (at your option) any later version. 1752 1753 web3.js is distributed in the hope that it will be useful, 1754 but WITHOUT ANY WARRANTY; without even the implied warranty of 1755 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1756 GNU Lesser General Public License for more details. 1757 1758 You should have received a copy of the GNU Lesser General Public License 1759 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1760 */ 1761 /** @file config.js 1762 * @authors: 1763 * Marek Kotewicz <marek@ethdev.com> 1764 * @date 2015 1765 */ 1766 1767 /** 1768 * Utils 1769 * 1770 * @module utils 1771 */ 1772 1773 /** 1774 * Utility functions 1775 * 1776 * @class [utils] config 1777 * @constructor 1778 */ 1779 1780 1781 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1782 var BigNumber = require('bignumber.js'); 1783 1784 var KLAY_UNITS = [ 1785 'peb', 1786 'kpeb', 1787 'Mpeb', 1788 'Gpeb', 1789 'ston', 1790 'uKLAY', 1791 'mKLAY', 1792 'KLAY', 1793 'kKLAY', 1794 'MKLAY', 1795 'GKLAY', 1796 'TKLAY', 1797 'PKLAY', 1798 'EKLAY', 1799 'ZKLAY', 1800 'YKLAY', 1801 ]; 1802 1803 module.exports = { 1804 ETH_PADDING: 32, 1805 ETH_SIGNATURE_LENGTH: 4, 1806 ETH_UNITS: KLAY_UNITS, 1807 ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1808 ETH_POLLING_TIMEOUT: 1000/2, 1809 defaultBlock: 'latest', 1810 defaultAccount: undefined 1811 }; 1812 1813 1814 },{"bignumber.js":"bignumber.js"}],19:[function(require,module,exports){ 1815 /* 1816 This file is part of web3.js. 1817 1818 web3.js is free software: you can redistribute it and/or modify 1819 it under the terms of the GNU Lesser General Public License as published by 1820 the Free Software Foundation, either version 3 of the License, or 1821 (at your option) any later version. 1822 1823 web3.js is distributed in the hope that it will be useful, 1824 but WITHOUT ANY WARRANTY; without even the implied warranty of 1825 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1826 GNU Lesser General Public License for more details. 1827 1828 You should have received a copy of the GNU Lesser General Public License 1829 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1830 */ 1831 /** 1832 * @file sha3.js 1833 * @author Marek Kotewicz <marek@ethdev.com> 1834 * @date 2015 1835 */ 1836 1837 var CryptoJS = require('crypto-js'); 1838 var sha3 = require('crypto-js/sha3'); 1839 1840 module.exports = function (value, options) { 1841 if (options && options.encoding === 'hex') { 1842 if (value.length > 2 && value.substr(0, 2) === '0x') { 1843 value = value.substr(2); 1844 } 1845 value = CryptoJS.enc.Hex.parse(value); 1846 } 1847 1848 return sha3(value, { 1849 outputLength: 256 1850 }).toString(); 1851 }; 1852 1853 1854 },{"crypto-js":59,"crypto-js/sha3":80}],20:[function(require,module,exports){ 1855 /* 1856 This file is part of web3.js. 1857 1858 web3.js is free software: you can redistribute it and/or modify 1859 it under the terms of the GNU Lesser General Public License as published by 1860 the Free Software Foundation, either version 3 of the License, or 1861 (at your option) any later version. 1862 1863 web3.js is distributed in the hope that it will be useful, 1864 but WITHOUT ANY WARRANTY; without even the implied warranty of 1865 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1866 GNU Lesser General Public License for more details. 1867 1868 You should have received a copy of the GNU Lesser General Public License 1869 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1870 */ 1871 /** 1872 * @file utils.js 1873 * @author Marek Kotewicz <marek@ethdev.com> 1874 * @date 2015 1875 */ 1876 1877 /** 1878 * Utils 1879 * 1880 * @module utils 1881 */ 1882 1883 /** 1884 * Utility functions 1885 * 1886 * @class [utils] utils 1887 * @constructor 1888 */ 1889 1890 1891 var BigNumber = require('bignumber.js'); 1892 var sha3 = require('./sha3.js'); 1893 var utf8 = require('utf8'); 1894 1895 var unitMap = { 1896 'noKLAY': '0', 1897 'peb': '1', 1898 'kpeb': '1000', 1899 'Mpeb': '1000000', 1900 'Gpeb': '1000000000', 1901 'ston': '1000000000', 1902 'uKLAY': '1000000000000', 1903 'mKLAY': '1000000000000000', 1904 'KLAY': '1000000000000000000', 1905 'kKLAY': '1000000000000000000000', 1906 'MKLAY': '1000000000000000000000000', 1907 'GKLAY': '1000000000000000000000000000', 1908 'TKLAY': '1000000000000000000000000000000' 1909 }; 1910 1911 var unitEthToKlayMap = { 1912 'noether': 'noKLAY', 1913 'wei': 'peb', 1914 'kwei': 'kpeb', 1915 'Kwei': 'kpeb', 1916 'babbage': 'kpeb', 1917 'femtoether': 'kpeb', 1918 'mwei': 'Mpeb', 1919 'Mwei': 'Mpeb', 1920 'lovelace': 'Mpeb', 1921 'picoether': 'Mpeb', 1922 'gwei': 'Gpeb', 1923 'Gwei': 'Gpeb', 1924 'shannon': 'Gpeb', 1925 'nanoether': 'Gpeb', 1926 'nano': 'Gpeb', 1927 'szabo': 'uKLAY', 1928 'microether': 'uKLAY', 1929 'micro': 'uKLAY', 1930 'finney': 'mKLAY', 1931 'milliether': 'mKLAY', 1932 'milli': 'mKLAY', 1933 'ether': 'KLAY', 1934 'kether': 'kKLAY', 1935 'grand': 'kKLAY', 1936 'mether': 'MKLAY', 1937 'gether': 'GKLAY', 1938 'tether': 'TKLAY' 1939 }; 1940 1941 /** 1942 * Should be called to pad string to expected length 1943 * 1944 * @method padLeft 1945 * @param {String} string to be padded 1946 * @param {Number} characters that result string should have 1947 * @param {String} sign, by default 0 1948 * @returns {String} right aligned string 1949 */ 1950 var padLeft = function (string, chars, sign) { 1951 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1952 }; 1953 1954 /** 1955 * Should be called to pad string to expected length 1956 * 1957 * @method padRight 1958 * @param {String} string to be padded 1959 * @param {Number} characters that result string should have 1960 * @param {String} sign, by default 0 1961 * @returns {String} right aligned string 1962 */ 1963 var padRight = function (string, chars, sign) { 1964 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1965 }; 1966 1967 /** 1968 * Should be called to get utf8 from it's hex representation 1969 * 1970 * @method toUtf8 1971 * @param {String} string in hex 1972 * @returns {String} ascii string representation of hex value 1973 */ 1974 var toUtf8 = function(hex) { 1975 // Find termination 1976 var str = ""; 1977 var i = 0, l = hex.length; 1978 if (hex.substring(0, 2) === '0x') { 1979 i = 2; 1980 } 1981 for (; i < l; i+=2) { 1982 var code = parseInt(hex.substr(i, 2), 16); 1983 if (code === 0) 1984 break; 1985 str += String.fromCharCode(code); 1986 } 1987 1988 return utf8.decode(str); 1989 }; 1990 1991 /** 1992 * Should be called to get ascii from it's hex representation 1993 * 1994 * @method toAscii 1995 * @param {String} string in hex 1996 * @returns {String} ascii string representation of hex value 1997 */ 1998 var toAscii = function(hex) { 1999 // Find termination 2000 var str = ""; 2001 var i = 0, l = hex.length; 2002 if (hex.substring(0, 2) === '0x') { 2003 i = 2; 2004 } 2005 for (; i < l; i+=2) { 2006 var code = parseInt(hex.substr(i, 2), 16); 2007 str += String.fromCharCode(code); 2008 } 2009 2010 return str; 2011 }; 2012 2013 /** 2014 * Should be called to get hex representation (prefixed by 0x) of utf8 string 2015 * 2016 * @method fromUtf8 2017 * @param {String} string 2018 * @param {Number} optional padding 2019 * @returns {String} hex representation of input string 2020 */ 2021 var fromUtf8 = function(str) { 2022 str = utf8.encode(str); 2023 var hex = ""; 2024 for(var i = 0; i < str.length; i++) { 2025 var code = str.charCodeAt(i); 2026 if (code === 0) 2027 break; 2028 var n = code.toString(16); 2029 hex += n.length < 2 ? '0' + n : n; 2030 } 2031 2032 return "0x" + hex; 2033 }; 2034 2035 /** 2036 * Should be called to get hex representation (prefixed by 0x) of ascii string 2037 * 2038 * @method fromAscii 2039 * @param {String} string 2040 * @param {Number} optional padding 2041 * @returns {String} hex representation of input string 2042 */ 2043 var fromAscii = function(str) { 2044 var hex = ""; 2045 for(var i = 0; i < str.length; i++) { 2046 var code = str.charCodeAt(i); 2047 var n = code.toString(16); 2048 hex += n.length < 2 ? '0' + n : n; 2049 } 2050 2051 return "0x" + hex; 2052 }; 2053 2054 /** 2055 * Should be used to create full function/event name from json abi 2056 * 2057 * @method transformToFullName 2058 * @param {Object} json-abi 2059 * @return {String} full fnction/event name 2060 */ 2061 var transformToFullName = function (json) { 2062 if (json.name.indexOf('(') !== -1) { 2063 return json.name; 2064 } 2065 2066 var typeName = json.inputs.map(function(i){return i.type; }).join(); 2067 return json.name + '(' + typeName + ')'; 2068 }; 2069 2070 /** 2071 * Should be called to get display name of contract function 2072 * 2073 * @method extractDisplayName 2074 * @param {String} name of function/event 2075 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2076 */ 2077 var extractDisplayName = function (name) { 2078 var length = name.indexOf('('); 2079 return length !== -1 ? name.substr(0, length) : name; 2080 }; 2081 2082 /// @returns overloaded part of function/event name 2083 var extractTypeName = function (name) { 2084 /// TODO: make it invulnerable 2085 var length = name.indexOf('('); 2086 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2087 }; 2088 2089 /** 2090 * Converts value to it's decimal representation in string 2091 * 2092 * @method toDecimal 2093 * @param {String|Number|BigNumber} 2094 * @return {String} 2095 */ 2096 var toDecimal = function (value) { 2097 return toBigNumber(value).toNumber(); 2098 }; 2099 2100 /** 2101 * Converts value to it's hex representation 2102 * 2103 * @method fromDecimal 2104 * @param {String|Number|BigNumber} 2105 * @return {String} 2106 */ 2107 var fromDecimal = function (value) { 2108 var number = toBigNumber(value); 2109 var result = number.toString(16); 2110 2111 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2112 }; 2113 2114 /** 2115 * Auto converts any given value into it's hex representation. 2116 * 2117 * And even stringifys objects before. 2118 * 2119 * @method toHex 2120 * @param {String|Number|BigNumber|Object} 2121 * @return {String} 2122 */ 2123 var toHex = function (val) { 2124 /*jshint maxcomplexity: 8 */ 2125 2126 if (isBoolean(val)) 2127 return fromDecimal(+val); 2128 2129 if (isBigNumber(val)) 2130 return fromDecimal(val); 2131 2132 if (typeof val === 'object') 2133 return fromUtf8(JSON.stringify(val)); 2134 2135 // if its a negative number, pass it through fromDecimal 2136 if (isString(val)) { 2137 if (val.indexOf('-0x') === 0) 2138 return fromDecimal(val); 2139 else if(val.indexOf('0x') === 0) 2140 return val; 2141 else if (!isFinite(val)) 2142 return fromAscii(val); 2143 } 2144 2145 return fromDecimal(val); 2146 }; 2147 2148 /** 2149 * Return entries of JSON object 2150 */ 2151 function entries(obj) { 2152 var entry_arr = []; 2153 for (var key in obj) { 2154 if (obj.hasOwnProperty(key)) { 2155 entry_arr.push([key, obj[key]]); 2156 } 2157 } 2158 return entry_arr; 2159 }; 2160 2161 /** 2162 * Returns more readable stringified string of 2-D array object 2163 * 2164 * @method fancyStringfy2D 2165 * @param {String} 2-D array object 2166 * @returns {String} more readable stringified of 2-D array object 2167 */ 2168 function fancyStringify2D(obj) { 2169 result = ""; 2170 stringified = JSON.stringify(obj, null, 2); 2171 matches = stringified.match(/\"[a-zA-Z0-9]*\"/g); 2172 for (var i = 0; i < matches.length; i+=2) { 2173 result += matches[i] + ": " + matches[i+1] + "\n"; 2174 } 2175 return result; 2176 }; 2177 2178 /** 2179 * Returns value of unit in peb 2180 * 2181 * @method getValueOfUnit 2182 * @param {String} unit the unit to convert to, default ether 2183 * @returns {BigNumber} value of the unit (in peb) 2184 * @throws error if the unit is not correct 2185 */ 2186 var getValueOfUnit = function (unit) { 2187 unit = unit ? unit : 'KLAY'; 2188 var unitValue = unitMap[unit]; 2189 if (unitValue === undefined) { 2190 throw new Error('This unit doesn\'t exist, please use one of the following units\n' 2191 + fancyStringify2D(entries(unitMap))); 2192 } 2193 return new BigNumber(unitValue, 10); 2194 }; 2195 2196 /** 2197 * Takes a number of wei and converts it to any other ether unit. 2198 * 2199 * Possible units are: 2200 * SI Short SI Full Effigy Other 2201 * - kwei femtoether babbage 2202 * - mwei picoether lovelace 2203 * - gwei nanoether shannon nano 2204 * - -- microether szabo micro 2205 * - -- milliether finney milli 2206 * - ether -- -- 2207 * - kether -- grand 2208 * - mether 2209 * - gether 2210 * - tether 2211 * 2212 * @method fromWei 2213 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2214 * @param {String} unit the unit to convert to, default ether 2215 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2216 */ 2217 var fromWei = function(number, unit) { 2218 var klayUnit = unitEthToKlayMap[unit] ? unitEthToKlayMap[unit] : unit; 2219 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(klayUnit)); 2220 2221 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2222 }; 2223 2224 /** 2225 * Takes a number of peb and converts it to any other KLAY unit. 2226 * 2227 * Possible units are: 2228 * SI Short 2229 * - kpeb 2230 * - Mpeb 2231 * - Gpeb 2232 * - uKLAY 2233 * - mKLAY 2234 * - KLAY 2235 * - kKLAY 2236 * - MKLAY 2237 * - GKLAY 2238 * - TKLAY 2239 * 2240 * @method fromPeb 2241 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2242 * @param {String} unit the unit to convert to, default KLAY 2243 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2244 */ 2245 var fromPeb = function(number, unit) { 2246 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2247 2248 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2249 }; 2250 2251 /** 2252 * Takes a number of a unit and converts it to wei. 2253 * 2254 * Possible units are: 2255 * SI Short SI Full Effigy Other 2256 * - kwei femtoether babbage 2257 * - mwei picoether lovelace 2258 * - gwei nanoether shannon nano 2259 * - -- microether szabo micro 2260 * - -- microether szabo micro 2261 * - -- milliether finney milli 2262 * - ether -- -- 2263 * - kether -- grand 2264 * - mether 2265 * - gether 2266 * - tether 2267 * 2268 * @method toWei 2269 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2270 * @param {String} unit the unit to convert from, default ether 2271 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2272 */ 2273 var toWei = function(number, unit) { 2274 var klayUnit = unitEthToKlayMap[unit] ? unitEthToKlayMap[unit] : unit; 2275 var returnValue = toBigNumber(number).times(getValueOfUnit(klayUnit)); 2276 2277 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2278 }; 2279 2280 /** 2281 * Takes a number of a unit and converts it to peb. 2282 * 2283 * Possible units are: 2284 * SI Short 2285 * - kpeb 2286 * - Mpeb 2287 * - Gpeb 2288 * - uKLAY 2289 * - mKLAY 2290 * - KLAY 2291 * - kKLAY 2292 * - MKLAY 2293 * - GKLAY 2294 * - TKLAY 2295 * 2296 * @method toPeb 2297 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2298 * @param {String} unit the unit to convert from, default ether 2299 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2300 */ 2301 var toPeb = function(number, unit) { 2302 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2303 2304 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2305 }; 2306 2307 /** 2308 * Takes an input and transforms it into a bignumber 2309 * 2310 * @method toBigNumber 2311 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2312 * @return {BigNumber} BigNumber 2313 */ 2314 var toBigNumber = function(number) { 2315 /*jshint maxcomplexity:5 */ 2316 number = number || 0; 2317 if (isBigNumber(number)) 2318 return number; 2319 2320 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2321 return new BigNumber(number.replace('0x',''), 16); 2322 } 2323 2324 return new BigNumber(number.toString(10), 10); 2325 }; 2326 2327 /** 2328 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2329 * 2330 * @method toTwosComplement 2331 * @param {Number|String|BigNumber} 2332 * @return {BigNumber} 2333 */ 2334 var toTwosComplement = function (number) { 2335 var bigNumber = toBigNumber(number).round(); 2336 if (bigNumber.lessThan(0)) { 2337 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2338 } 2339 return bigNumber; 2340 }; 2341 2342 /** 2343 * Checks if the given string is strictly an address 2344 * 2345 * @method isStrictAddress 2346 * @param {String} address the given HEX address 2347 * @return {Boolean} 2348 */ 2349 var isStrictAddress = function (address) { 2350 return /^0x[0-9a-f]{40}$/i.test(address); 2351 }; 2352 2353 /** 2354 * Checks if the given string is an address 2355 * 2356 * @method isAddress 2357 * @param {String} address the given HEX address 2358 * @return {Boolean} 2359 */ 2360 var isAddress = function (address) { 2361 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2362 // check if it has the basic requirements of an address 2363 return false; 2364 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2365 // If it's all small caps or all caps, return true 2366 return true; 2367 } else { 2368 // Otherwise check each case 2369 return isChecksumAddress(address); 2370 } 2371 }; 2372 2373 /** 2374 * Checks if the given string is a checksummed address 2375 * 2376 * @method isChecksumAddress 2377 * @param {String} address the given HEX address 2378 * @return {Boolean} 2379 */ 2380 var isChecksumAddress = function (address) { 2381 // Check each case 2382 address = address.replace('0x',''); 2383 var addressHash = sha3(address.toLowerCase()); 2384 2385 for (var i = 0; i < 40; i++ ) { 2386 // the nth letter should be uppercase if the nth digit of casemap is 1 2387 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2388 return false; 2389 } 2390 } 2391 return true; 2392 }; 2393 2394 2395 2396 /** 2397 * Makes a checksum address 2398 * 2399 * @method toChecksumAddress 2400 * @param {String} address the given HEX address 2401 * @return {String} 2402 */ 2403 var toChecksumAddress = function (address) { 2404 if (typeof address === 'undefined') return ''; 2405 2406 address = address.toLowerCase().replace('0x',''); 2407 var addressHash = sha3(address); 2408 var checksumAddress = '0x'; 2409 2410 for (var i = 0; i < address.length; i++ ) { 2411 // If ith character is 9 to f then make it uppercase 2412 if (parseInt(addressHash[i], 16) > 7) { 2413 checksumAddress += address[i].toUpperCase(); 2414 } else { 2415 checksumAddress += address[i]; 2416 } 2417 } 2418 return checksumAddress; 2419 }; 2420 2421 /** 2422 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2423 * 2424 * @method toAddress 2425 * @param {String} address 2426 * @return {String} formatted address 2427 */ 2428 var toAddress = function (address) { 2429 if (isStrictAddress(address)) { 2430 return address; 2431 } 2432 2433 if (/^[0-9a-f]{40}$/.test(address)) { 2434 return '0x' + address; 2435 } 2436 2437 return '0x' + padLeft(toHex(address).substr(2), 40); 2438 }; 2439 2440 /** 2441 * Returns true if object is BigNumber, otherwise false 2442 * 2443 * @method isBigNumber 2444 * @param {Object} 2445 * @return {Boolean} 2446 */ 2447 var isBigNumber = function (object) { 2448 return object instanceof BigNumber || 2449 (object && object.constructor && object.constructor.name === 'BigNumber'); 2450 }; 2451 2452 /** 2453 * Returns true if object is string, otherwise false 2454 * 2455 * @method isString 2456 * @param {Object} 2457 * @return {Boolean} 2458 */ 2459 var isString = function (object) { 2460 return typeof object === 'string' || 2461 (object && object.constructor && object.constructor.name === 'String'); 2462 }; 2463 2464 /** 2465 * Returns true if object is function, otherwise false 2466 * 2467 * @method isFunction 2468 * @param {Object} 2469 * @return {Boolean} 2470 */ 2471 var isFunction = function (object) { 2472 return typeof object === 'function'; 2473 }; 2474 2475 /** 2476 * Returns true if object is Objet, otherwise false 2477 * 2478 * @method isObject 2479 * @param {Object} 2480 * @return {Boolean} 2481 */ 2482 var isObject = function (object) { 2483 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2484 }; 2485 2486 /** 2487 * Returns true if object is boolean, otherwise false 2488 * 2489 * @method isBoolean 2490 * @param {Object} 2491 * @return {Boolean} 2492 */ 2493 var isBoolean = function (object) { 2494 return typeof object === 'boolean'; 2495 }; 2496 2497 /** 2498 * Returns true if object is array, otherwise false 2499 * 2500 * @method isArray 2501 * @param {Object} 2502 * @return {Boolean} 2503 */ 2504 var isArray = function (object) { 2505 return object instanceof Array; 2506 }; 2507 2508 /** 2509 * Returns true if given string is valid json object 2510 * 2511 * @method isJson 2512 * @param {String} 2513 * @return {Boolean} 2514 */ 2515 var isJson = function (str) { 2516 try { 2517 return !!JSON.parse(str); 2518 } catch (e) { 2519 return false; 2520 } 2521 }; 2522 2523 /** 2524 * Returns true if given string is a valid Klaytn block header bloom. 2525 * 2526 * @method isBloom 2527 * @param {String} hex encoded bloom filter 2528 * @return {Boolean} 2529 */ 2530 var isBloom = function (bloom) { 2531 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2532 return false; 2533 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2534 return true; 2535 } 2536 return false; 2537 }; 2538 2539 /** 2540 * Returns true if given string is a valid log topic. 2541 * 2542 * @method isTopic 2543 * @param {String} hex encoded topic 2544 * @return {Boolean} 2545 */ 2546 var isTopic = function (topic) { 2547 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2548 return false; 2549 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2550 return true; 2551 } 2552 return false; 2553 }; 2554 2555 module.exports = { 2556 padLeft: padLeft, 2557 padRight: padRight, 2558 toHex: toHex, 2559 toDecimal: toDecimal, 2560 fromDecimal: fromDecimal, 2561 toUtf8: toUtf8, 2562 toAscii: toAscii, 2563 fromUtf8: fromUtf8, 2564 fromAscii: fromAscii, 2565 transformToFullName: transformToFullName, 2566 extractDisplayName: extractDisplayName, 2567 extractTypeName: extractTypeName, 2568 toWei: toWei, 2569 fromWei: fromWei, 2570 toPeb: toPeb, 2571 fromPeb: fromPeb, 2572 toBigNumber: toBigNumber, 2573 toTwosComplement: toTwosComplement, 2574 toAddress: toAddress, 2575 isBigNumber: isBigNumber, 2576 isStrictAddress: isStrictAddress, 2577 isAddress: isAddress, 2578 isChecksumAddress: isChecksumAddress, 2579 toChecksumAddress: toChecksumAddress, 2580 isFunction: isFunction, 2581 isString: isString, 2582 isObject: isObject, 2583 isBoolean: isBoolean, 2584 isArray: isArray, 2585 isJson: isJson, 2586 isBloom: isBloom, 2587 isTopic: isTopic, 2588 }; 2589 2590 },{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){ 2591 module.exports={ 2592 "version": "0.20.1" 2593 } 2594 2595 },{}],22:[function(require,module,exports){ 2596 /* 2597 This file is part of web3.js. 2598 2599 web3.js is free software: you can redistribute it and/or modify 2600 it under the terms of the GNU Lesser General Public License as published by 2601 the Free Software Foundation, either version 3 of the License, or 2602 (at your option) any later version. 2603 2604 web3.js is distributed in the hope that it will be useful, 2605 but WITHOUT ANY WARRANTY; without even the implied warranty of 2606 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2607 GNU Lesser General Public License for more details. 2608 2609 You should have received a copy of the GNU Lesser General Public License 2610 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2611 */ 2612 /** 2613 * @file web3.js 2614 * @authors: 2615 * Jeffrey Wilcke <jeff@ethdev.com> 2616 * Marek Kotewicz <marek@ethdev.com> 2617 * Marian Oancea <marian@ethdev.com> 2618 * Fabian Vogelsteller <fabian@ethdev.com> 2619 * Gav Wood <g@ethdev.com> 2620 * @date 2014 2621 */ 2622 2623 var RequestManager = require('./web3/requestmanager'); 2624 var Iban = require('./web3/iban'); 2625 var Klay = require('./web3/methods/klay'); 2626 var Eth = require('./web3/methods/eth'); 2627 var DB = require('./web3/methods/db'); 2628 var Shh = require('./web3/methods/shh'); 2629 var Net = require('./web3/methods/net'); 2630 var Personal = require('./web3/methods/personal'); 2631 var Swarm = require('./web3/methods/swarm'); 2632 var Settings = require('./web3/settings'); 2633 var version = require('./version.json'); 2634 var utils = require('./utils/utils'); 2635 var sha3 = require('./utils/sha3'); 2636 var extend = require('./web3/extend'); 2637 var Batch = require('./web3/batch'); 2638 var Property = require('./web3/property'); 2639 var HttpProvider = require('./web3/httpprovider'); 2640 var IpcProvider = require('./web3/ipcprovider'); 2641 var BigNumber = require('bignumber.js'); 2642 2643 2644 2645 function Web3 (provider) { 2646 this._requestManager = new RequestManager(provider); 2647 this.currentProvider = provider; 2648 this.klay = new Klay(this); 2649 this.eth = new Eth(this); 2650 this.db = new DB(this); 2651 this.shh = new Shh(this); 2652 this.net = new Net(this); 2653 this.personal = new Personal(this); 2654 this.bzz = new Swarm(this); 2655 this.settings = new Settings(); 2656 this.version = { 2657 api: version.version 2658 }; 2659 this.providers = { 2660 HttpProvider: HttpProvider, 2661 IpcProvider: IpcProvider 2662 }; 2663 this._extend = extend(this); 2664 this._extend({ 2665 properties: properties() 2666 }); 2667 this.klay.BigNumber = BigNumber; 2668 this.klay.toHex = utils.toHex; 2669 this.klay.toAscii = utils.toAscii; 2670 this.klay.toUtf8 = utils.toUtf8; 2671 this.klay.fromAscii = utils.fromAscii; 2672 this.klay.fromUtf8 = utils.fromUtf8; 2673 this.klay.toDecimal = utils.toDecimal; 2674 this.klay.fromDecimal = utils.fromDecimal; 2675 this.klay.toBigNumber = utils.toBigNumber; 2676 this.klay.toPeb = utils.toPeb; 2677 this.klay.fromPeb = utils.fromPeb; 2678 this.klay.isAddress = utils.isAddress; 2679 this.klay.isChecksumAddress = utils.isChecksumAddress; 2680 this.klay.toChecksumAddress = utils.toChecksumAddress; 2681 this.klay.isIBAN = utils.isIBAN; 2682 this.klay.padLeft = utils.padLeft; 2683 this.klay.padRight = utils.padRight; 2684 } 2685 2686 // expose providers on the class 2687 Web3.providers = { 2688 HttpProvider: HttpProvider, 2689 IpcProvider: IpcProvider 2690 }; 2691 2692 Web3.prototype.setProvider = function (provider) { 2693 this._requestManager.setProvider(provider); 2694 this.currentProvider = provider; 2695 }; 2696 2697 Web3.prototype.reset = function (keepIsSyncing) { 2698 this._requestManager.reset(keepIsSyncing); 2699 this.settings = new Settings(); 2700 }; 2701 2702 Web3.prototype.BigNumber = BigNumber; 2703 Web3.prototype.toHex = utils.toHex; 2704 Web3.prototype.toAscii = utils.toAscii; 2705 Web3.prototype.toUtf8 = utils.toUtf8; 2706 Web3.prototype.fromAscii = utils.fromAscii; 2707 Web3.prototype.fromUtf8 = utils.fromUtf8; 2708 Web3.prototype.toDecimal = utils.toDecimal; 2709 Web3.prototype.fromDecimal = utils.fromDecimal; 2710 Web3.prototype.toBigNumber = utils.toBigNumber; 2711 Web3.prototype.toWei = utils.toWei; 2712 Web3.prototype.fromWei = utils.fromWei; 2713 Web3.prototype.toPeb = utils.toPeb; 2714 Web3.prototype.fromPeb = utils.fromPeb; 2715 Web3.prototype.isAddress = utils.isAddress; 2716 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2717 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2718 Web3.prototype.isIBAN = utils.isIBAN; 2719 Web3.prototype.padLeft = utils.padLeft; 2720 Web3.prototype.padRight = utils.padRight; 2721 2722 2723 Web3.prototype.sha3 = function(string, options) { 2724 return '0x' + sha3(string, options); 2725 }; 2726 2727 /** 2728 * Transforms direct icap to address 2729 */ 2730 Web3.prototype.fromICAP = function (icap) { 2731 var iban = new Iban(icap); 2732 return iban.address(); 2733 }; 2734 2735 var properties = function () { 2736 return [ 2737 new Property({ 2738 name: 'version.node', 2739 getter: 'klay_clientVersion' 2740 }), 2741 new Property({ 2742 name: 'version.network', 2743 getter: 'net_version', 2744 inputFormatter: utils.toDecimal 2745 }), 2746 new Property({ 2747 name: 'version.klaytn', 2748 getter: 'klay_protocolVersion', 2749 inputFormatter: utils.toDecimal 2750 }), 2751 new Property({ 2752 name: 'version.whisper', 2753 getter: 'shh_version', 2754 inputFormatter: utils.toDecimal 2755 }) 2756 ]; 2757 }; 2758 2759 Web3.prototype.isConnected = function(){ 2760 return (this.currentProvider && this.currentProvider.isConnected()); 2761 }; 2762 2763 Web3.prototype.createBatch = function () { 2764 return new Batch(this); 2765 }; 2766 2767 module.exports = Web3; 2768 2769 2770 },{"./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/klay":38,"./web3/methods/eth":87,"./web3/methods/net":39,"./web3/methods/personal":40,"./web3/methods/shh":41,"./web3/methods/swarm":42,"./web3/property":45,"./web3/requestmanager":46,"./web3/settings":47,"bignumber.js":"bignumber.js"}],23:[function(require,module,exports){ 2771 /* 2772 This file is part of web3.js. 2773 2774 web3.js is free software: you can redistribute it and/or modify 2775 it under the terms of the GNU Lesser General Public License as published by 2776 the Free Software Foundation, either version 3 of the License, or 2777 (at your option) any later version. 2778 2779 web3.js is distributed in the hope that it will be useful, 2780 but WITHOUT ANY WARRANTY; without even the implied warranty of 2781 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2782 GNU Lesser General Public License for more details. 2783 2784 You should have received a copy of the GNU Lesser General Public License 2785 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2786 */ 2787 /** 2788 * @file allevents.js 2789 * @author Marek Kotewicz <marek@ethdev.com> 2790 * @date 2014 2791 */ 2792 2793 var sha3 = require('../utils/sha3'); 2794 var SolidityEvent = require('./event'); 2795 var formatters = require('./formatters'); 2796 var utils = require('../utils/utils'); 2797 var Filter = require('./filter'); 2798 var watches = require('./methods/watches'); 2799 2800 var AllSolidityEvents = function (requestManager, json, address) { 2801 this._requestManager = requestManager; 2802 this._json = json; 2803 this._address = address; 2804 }; 2805 2806 AllSolidityEvents.prototype.encode = function (options) { 2807 options = options || {}; 2808 var result = {}; 2809 2810 ['fromBlock', 'toBlock'].filter(function (f) { 2811 return options[f] !== undefined; 2812 }).forEach(function (f) { 2813 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2814 }); 2815 2816 result.address = this._address; 2817 2818 return result; 2819 }; 2820 2821 AllSolidityEvents.prototype.decode = function (data) { 2822 data.data = data.data || ''; 2823 data.topics = data.topics || []; 2824 2825 var eventTopic = data.topics[0].slice(2); 2826 var match = this._json.filter(function (j) { 2827 return eventTopic === sha3(utils.transformToFullName(j)); 2828 })[0]; 2829 2830 if (!match) { // cannot find matching event? 2831 console.warn('cannot find event for log'); 2832 return data; 2833 } 2834 2835 var event = new SolidityEvent(this._requestManager, match, this._address); 2836 return event.decode(data); 2837 }; 2838 2839 AllSolidityEvents.prototype.execute = function (options, callback) { 2840 2841 if (utils.isFunction(arguments[arguments.length - 1])) { 2842 callback = arguments[arguments.length - 1]; 2843 if(arguments.length === 1) 2844 options = null; 2845 } 2846 2847 var o = this.encode(options); 2848 var formatter = this.decode.bind(this); 2849 return new Filter(o, 'klay', this._requestManager, watches.klay(), formatter, callback); 2850 }; 2851 2852 AllSolidityEvents.prototype.attachToContract = function (contract) { 2853 var execute = this.execute.bind(this); 2854 contract.allEvents = execute; 2855 }; 2856 2857 module.exports = AllSolidityEvents; 2858 2859 2860 },{"../utils/sha3":19,"../utils/utils":20,"./event":27,"./filter":29,"./formatters":30,"./methods/watches":43}],24:[function(require,module,exports){ 2861 /* 2862 This file is part of web3.js. 2863 2864 web3.js is free software: you can redistribute it and/or modify 2865 it under the terms of the GNU Lesser General Public License as published by 2866 the Free Software Foundation, either version 3 of the License, or 2867 (at your option) any later version. 2868 2869 web3.js is distributed in the hope that it will be useful, 2870 but WITHOUT ANY WARRANTY; without even the implied warranty of 2871 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2872 GNU Lesser General Public License for more details. 2873 2874 You should have received a copy of the GNU Lesser General Public License 2875 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2876 */ 2877 /** 2878 * @file batch.js 2879 * @author Marek Kotewicz <marek@ethdev.com> 2880 * @date 2015 2881 */ 2882 2883 var Jsonrpc = require('./jsonrpc'); 2884 var errors = require('./errors'); 2885 2886 var Batch = function (web3) { 2887 this.requestManager = web3._requestManager; 2888 this.requests = []; 2889 }; 2890 2891 /** 2892 * Should be called to add create new request to batch request 2893 * 2894 * @method add 2895 * @param {Object} jsonrpc requet object 2896 */ 2897 Batch.prototype.add = function (request) { 2898 this.requests.push(request); 2899 }; 2900 2901 /** 2902 * Should be called to execute batch request 2903 * 2904 * @method execute 2905 */ 2906 Batch.prototype.execute = function () { 2907 var requests = this.requests; 2908 this.requestManager.sendBatch(requests, function (err, results) { 2909 results = results || []; 2910 requests.map(function (request, index) { 2911 return results[index] || {}; 2912 }).forEach(function (result, index) { 2913 if (requests[index].callback) { 2914 2915 if (!Jsonrpc.isValidResponse(result)) { 2916 return requests[index].callback(errors.InvalidResponse(result)); 2917 } 2918 2919 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2920 } 2921 }); 2922 }); 2923 }; 2924 2925 module.exports = Batch; 2926 2927 2928 },{"./errors":26,"./jsonrpc":35}],25:[function(require,module,exports){ 2929 /* 2930 This file is part of web3.js. 2931 2932 web3.js is free software: you can redistribute it and/or modify 2933 it under the terms of the GNU Lesser General Public License as published by 2934 the Free Software Foundation, either version 3 of the License, or 2935 (at your option) any later version. 2936 2937 web3.js is distributed in the hope that it will be useful, 2938 but WITHOUT ANY WARRANTY; without even the implied warranty of 2939 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2940 GNU Lesser General Public License for more details. 2941 2942 You should have received a copy of the GNU Lesser General Public License 2943 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2944 */ 2945 /** 2946 * @file contract.js 2947 * @author Marek Kotewicz <marek@ethdev.com> 2948 * @date 2014 2949 */ 2950 2951 var utils = require('../utils/utils'); 2952 var coder = require('../solidity/coder'); 2953 var SolidityEvent = require('./event'); 2954 var SolidityFunction = require('./function'); 2955 var AllEvents = require('./allevents'); 2956 2957 /** 2958 * Should be called to encode constructor params 2959 * 2960 * @method encodeConstructorParams 2961 * @param {Array} abi 2962 * @param {Array} constructor params 2963 */ 2964 var encodeConstructorParams = function (abi, params) { 2965 return abi.filter(function (json) { 2966 return json.type === 'constructor' && json.inputs.length === params.length; 2967 }).map(function (json) { 2968 return json.inputs.map(function (input) { 2969 return input.type; 2970 }); 2971 }).map(function (types) { 2972 return coder.encodeParams(types, params); 2973 })[0] || ''; 2974 }; 2975 2976 /** 2977 * Should be called to add functions to contract object 2978 * 2979 * @method addFunctionsToContract 2980 * @param {Contract} contract 2981 * @param {Array} abi 2982 */ 2983 var addFunctionsToContract = function (contract) { 2984 contract.abi.filter(function (json) { 2985 return json.type === 'function'; 2986 }).map(function (json) { 2987 return new SolidityFunction(contract._klay, json, contract.address); 2988 }).forEach(function (f) { 2989 f.attachToContract(contract); 2990 }); 2991 }; 2992 2993 /** 2994 * Should be called to add events to contract object 2995 * 2996 * @method addEventsToContract 2997 * @param {Contract} contract 2998 * @param {Array} abi 2999 */ 3000 var addEventsToContract = function (contract) { 3001 var events = contract.abi.filter(function (json) { 3002 return json.type === 'event'; 3003 }); 3004 3005 var All = new AllEvents(contract._klay._requestManager, events, contract.address); 3006 All.attachToContract(contract); 3007 3008 events.map(function (json) { 3009 return new SolidityEvent(contract._klay._requestManager, json, contract.address); 3010 }).forEach(function (e) { 3011 e.attachToContract(contract); 3012 }); 3013 }; 3014 3015 3016 /** 3017 * Should be called to check if the contract gets properly deployed on the blockchain. 3018 * 3019 * @method checkForContractAddress 3020 * @param {Object} contract 3021 * @param {Function} callback 3022 * @returns {Undefined} 3023 */ 3024 var checkForContractAddress = function(contract, callback){ 3025 var count = 0, 3026 callbackFired = false; 3027 3028 // wait for receipt 3029 var filter = contract._klay.filter('latest', function(e){ 3030 if (!e && !callbackFired) { 3031 count++; 3032 3033 // stop watching after 50 blocks (timeout) 3034 if (count > 50) { 3035 3036 filter.stopWatching(function() {}); 3037 callbackFired = true; 3038 3039 if (callback) 3040 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 3041 else 3042 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 3043 3044 3045 } else { 3046 3047 contract._klay.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 3048 if(receipt && !callbackFired) { 3049 3050 contract._klay.getCode(receipt.contractAddress, function(e, code){ 3051 /*jshint maxcomplexity: 6 */ 3052 3053 if(callbackFired || !code) 3054 return; 3055 3056 filter.stopWatching(function() {}); 3057 callbackFired = true; 3058 3059 if(code.length > 3) { 3060 3061 // console.log('Contract code deployed!'); 3062 3063 contract.address = receipt.contractAddress; 3064 3065 // attach events and methods again after we have 3066 addFunctionsToContract(contract); 3067 addEventsToContract(contract); 3068 3069 // call callback for the second time 3070 if(callback) 3071 callback(null, contract); 3072 3073 } else { 3074 if(callback) 3075 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 3076 else 3077 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 3078 } 3079 }); 3080 } 3081 }); 3082 } 3083 } 3084 }); 3085 }; 3086 3087 /** 3088 * Should be called to create new ContractFactory instance 3089 * 3090 * @method ContractFactory 3091 * @param {Array} abi 3092 */ 3093 var ContractFactory = function (klay, abi) { 3094 this.klay = klay; 3095 this.abi = abi; 3096 3097 /** 3098 * Should be called to create new contract on a blockchain 3099 * 3100 * @method new 3101 * @param {Any} contract constructor param1 (optional) 3102 * @param {Any} contract constructor param2 (optional) 3103 * @param {Object} contract transaction object (required) 3104 * @param {Function} callback 3105 * @returns {Contract} returns contract instance 3106 */ 3107 this.new = function () { 3108 /*jshint maxcomplexity: 7 */ 3109 3110 var contract = new Contract(this.klay, this.abi); 3111 3112 // parse arguments 3113 var options = {}; // required! 3114 var callback; 3115 3116 var args = Array.prototype.slice.call(arguments); 3117 if (utils.isFunction(args[args.length - 1])) { 3118 callback = args.pop(); 3119 } 3120 3121 var last = args[args.length - 1]; 3122 if (utils.isObject(last) && !utils.isArray(last)) { 3123 options = args.pop(); 3124 } 3125 3126 if (options.value > 0) { 3127 var constructorAbi = abi.filter(function (json) { 3128 return json.type === 'constructor' && json.inputs.length === args.length; 3129 })[0] || {}; 3130 3131 if (!constructorAbi.payable) { 3132 throw new Error('Cannot send value to non-payable constructor'); 3133 } 3134 } 3135 3136 var bytes = encodeConstructorParams(this.abi, args); 3137 options.data += bytes; 3138 3139 if (callback) { 3140 3141 // wait for the contract address adn check if the code was deployed 3142 this.klay.sendTransaction(options, function (err, hash) { 3143 if (err) { 3144 callback(err); 3145 } else { 3146 // add the transaction hash 3147 contract.transactionHash = hash; 3148 3149 // call callback for the first time 3150 callback(null, contract); 3151 3152 checkForContractAddress(contract, callback); 3153 } 3154 }); 3155 } else { 3156 var hash = this.klay.sendTransaction(options); 3157 // add the transaction hash 3158 contract.transactionHash = hash; 3159 checkForContractAddress(contract); 3160 } 3161 3162 return contract; 3163 }; 3164 3165 this.new.getData = this.getData.bind(this); 3166 }; 3167 3168 /** 3169 * Should be called to create new ContractFactory 3170 * 3171 * @method contract 3172 * @param {Array} abi 3173 * @returns {ContractFactory} new contract factory 3174 */ 3175 //var contract = function (abi) { 3176 //return new ContractFactory(abi); 3177 //}; 3178 3179 3180 3181 /** 3182 * Should be called to get access to existing contract on a blockchain 3183 * 3184 * @method at 3185 * @param {Address} contract address (required) 3186 * @param {Function} callback {optional) 3187 * @returns {Contract} returns contract if no callback was passed, 3188 * otherwise calls callback function (err, contract) 3189 */ 3190 ContractFactory.prototype.at = function (address, callback) { 3191 var contract = new Contract(this.klay, this.abi, address); 3192 3193 // this functions are not part of prototype, 3194 // because we dont want to spoil the interface 3195 addFunctionsToContract(contract); 3196 addEventsToContract(contract); 3197 3198 if (callback) { 3199 callback(null, contract); 3200 } 3201 return contract; 3202 }; 3203 3204 /** 3205 * Gets the data, which is data to deploy plus constructor params 3206 * 3207 * @method getData 3208 */ 3209 ContractFactory.prototype.getData = function () { 3210 var options = {}; // required! 3211 var args = Array.prototype.slice.call(arguments); 3212 3213 var last = args[args.length - 1]; 3214 if (utils.isObject(last) && !utils.isArray(last)) { 3215 options = args.pop(); 3216 } 3217 3218 var bytes = encodeConstructorParams(this.abi, args); 3219 options.data += bytes; 3220 3221 return options.data; 3222 }; 3223 3224 /** 3225 * Should be called to create new contract instance 3226 * 3227 * @method Contract 3228 * @param {Array} abi 3229 * @param {Address} contract address 3230 */ 3231 var Contract = function (klay, abi, address) { 3232 this._klay = klay; 3233 this.transactionHash = null; 3234 this.address = address; 3235 this.abi = abi; 3236 }; 3237 3238 module.exports = ContractFactory; 3239 3240 },{"../solidity/coder":7,"../utils/utils":20,"./allevents":23,"./event":27,"./function":31}],26:[function(require,module,exports){ 3241 /* 3242 This file is part of web3.js. 3243 3244 web3.js is free software: you can redistribute it and/or modify 3245 it under the terms of the GNU Lesser General Public License as published by 3246 the Free Software Foundation, either version 3 of the License, or 3247 (at your option) any later version. 3248 3249 web3.js is distributed in the hope that it will be useful, 3250 but WITHOUT ANY WARRANTY; without even the implied warranty of 3251 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3252 GNU Lesser General Public License for more details. 3253 3254 You should have received a copy of the GNU Lesser General Public License 3255 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3256 */ 3257 /** 3258 * @file errors.js 3259 * @author Marek Kotewicz <marek@ethdev.com> 3260 * @date 2015 3261 */ 3262 3263 module.exports = { 3264 InvalidNumberOfSolidityArgs: function () { 3265 return new Error('Invalid number of arguments to Solidity function'); 3266 }, 3267 InvalidNumberOfRPCParams: function () { 3268 return new Error('Invalid number of input parameters to RPC method'); 3269 }, 3270 InvalidConnection: function (host){ 3271 return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +'.'); 3272 }, 3273 InvalidProvider: function () { 3274 return new Error('Provider not set or invalid'); 3275 }, 3276 InvalidResponse: function (result){ 3277 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3278 return new Error(message); 3279 }, 3280 ConnectionTimeout: function (ms){ 3281 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3282 } 3283 }; 3284 3285 },{}],27:[function(require,module,exports){ 3286 /* 3287 This file is part of web3.js. 3288 3289 web3.js is free software: you can redistribute it and/or modify 3290 it under the terms of the GNU Lesser General Public License as published by 3291 the Free Software Foundation, either version 3 of the License, or 3292 (at your option) any later version. 3293 3294 web3.js is distributed in the hope that it will be useful, 3295 but WITHOUT ANY WARRANTY; without even the implied warranty of 3296 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3297 GNU Lesser General Public License for more details. 3298 3299 You should have received a copy of the GNU Lesser General Public License 3300 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3301 */ 3302 /** 3303 * @file event.js 3304 * @author Marek Kotewicz <marek@ethdev.com> 3305 * @date 2014 3306 */ 3307 3308 var utils = require('../utils/utils'); 3309 var coder = require('../solidity/coder'); 3310 var formatters = require('./formatters'); 3311 var sha3 = require('../utils/sha3'); 3312 var Filter = require('./filter'); 3313 var watches = require('./methods/watches'); 3314 3315 /** 3316 * This prototype should be used to create event filters 3317 */ 3318 var SolidityEvent = function (requestManager, json, address) { 3319 this._requestManager = requestManager; 3320 this._params = json.inputs; 3321 this._name = utils.transformToFullName(json); 3322 this._address = address; 3323 this._anonymous = json.anonymous; 3324 }; 3325 3326 /** 3327 * Should be used to get filtered param types 3328 * 3329 * @method types 3330 * @param {Bool} decide if returned typed should be indexed 3331 * @return {Array} array of types 3332 */ 3333 SolidityEvent.prototype.types = function (indexed) { 3334 return this._params.filter(function (i) { 3335 return i.indexed === indexed; 3336 }).map(function (i) { 3337 return i.type; 3338 }); 3339 }; 3340 3341 /** 3342 * Should be used to get event display name 3343 * 3344 * @method displayName 3345 * @return {String} event display name 3346 */ 3347 SolidityEvent.prototype.displayName = function () { 3348 return utils.extractDisplayName(this._name); 3349 }; 3350 3351 /** 3352 * Should be used to get event type name 3353 * 3354 * @method typeName 3355 * @return {String} event type name 3356 */ 3357 SolidityEvent.prototype.typeName = function () { 3358 return utils.extractTypeName(this._name); 3359 }; 3360 3361 /** 3362 * Should be used to get event signature 3363 * 3364 * @method signature 3365 * @return {String} event signature 3366 */ 3367 SolidityEvent.prototype.signature = function () { 3368 return sha3(this._name); 3369 }; 3370 3371 /** 3372 * Should be used to encode indexed params and options to one final object 3373 * 3374 * @method encode 3375 * @param {Object} indexed 3376 * @param {Object} options 3377 * @return {Object} everything combined together and encoded 3378 */ 3379 SolidityEvent.prototype.encode = function (indexed, options) { 3380 indexed = indexed || {}; 3381 options = options || {}; 3382 var result = {}; 3383 3384 ['fromBlock', 'toBlock'].filter(function (f) { 3385 return options[f] !== undefined; 3386 }).forEach(function (f) { 3387 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3388 }); 3389 3390 result.topics = []; 3391 3392 result.address = this._address; 3393 if (!this._anonymous) { 3394 result.topics.push('0x' + this.signature()); 3395 } 3396 3397 var indexedTopics = this._params.filter(function (i) { 3398 return i.indexed === true; 3399 }).map(function (i) { 3400 var value = indexed[i.name]; 3401 if (value === undefined || value === null) { 3402 return null; 3403 } 3404 3405 if (utils.isArray(value)) { 3406 return value.map(function (v) { 3407 return '0x' + coder.encodeParam(i.type, v); 3408 }); 3409 } 3410 return '0x' + coder.encodeParam(i.type, value); 3411 }); 3412 3413 result.topics = result.topics.concat(indexedTopics); 3414 3415 return result; 3416 }; 3417 3418 /** 3419 * Should be used to decode indexed params and options 3420 * 3421 * @method decode 3422 * @param {Object} data 3423 * @return {Object} result object with decoded indexed && not indexed params 3424 */ 3425 SolidityEvent.prototype.decode = function (data) { 3426 3427 data.data = data.data || ''; 3428 data.topics = data.topics || []; 3429 3430 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3431 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3432 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3433 3434 var notIndexedData = data.data.slice(2); 3435 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3436 3437 var result = formatters.outputLogFormatter(data); 3438 result.event = this.displayName(); 3439 result.address = data.address; 3440 3441 result.args = this._params.reduce(function (acc, current) { 3442 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3443 return acc; 3444 }, {}); 3445 3446 delete result.data; 3447 delete result.topics; 3448 3449 return result; 3450 }; 3451 3452 /** 3453 * Should be used to create new filter object from event 3454 * 3455 * @method execute 3456 * @param {Object} indexed 3457 * @param {Object} options 3458 * @return {Object} filter object 3459 */ 3460 SolidityEvent.prototype.execute = function (indexed, options, callback) { 3461 3462 if (utils.isFunction(arguments[arguments.length - 1])) { 3463 callback = arguments[arguments.length - 1]; 3464 if(arguments.length === 2) 3465 options = null; 3466 if(arguments.length === 1) { 3467 options = null; 3468 indexed = {}; 3469 } 3470 } 3471 3472 var o = this.encode(indexed, options); 3473 var formatter = this.decode.bind(this); 3474 return new Filter(o, 'klay', this._requestManager, watches.klay(), formatter, callback); 3475 }; 3476 3477 /** 3478 * Should be used to attach event to contract object 3479 * 3480 * @method attachToContract 3481 * @param {Contract} 3482 */ 3483 SolidityEvent.prototype.attachToContract = function (contract) { 3484 var execute = this.execute.bind(this); 3485 var displayName = this.displayName(); 3486 if (!contract[displayName]) { 3487 contract[displayName] = execute; 3488 } 3489 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3490 }; 3491 3492 module.exports = SolidityEvent; 3493 3494 3495 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./filter":29,"./formatters":30,"./methods/watches":43}],28:[function(require,module,exports){ 3496 var formatters = require('./formatters'); 3497 var utils = require('./../utils/utils'); 3498 var Method = require('./method'); 3499 var Property = require('./property'); 3500 3501 // TODO: refactor, so the input params are not altered. 3502 // it's necessary to make same 'extension' work with multiple providers 3503 var extend = function (web3) { 3504 /* jshint maxcomplexity:5 */ 3505 var ex = function (extension) { 3506 3507 var extendedObject; 3508 if (extension.property) { 3509 if (!web3[extension.property]) { 3510 web3[extension.property] = {}; 3511 } 3512 extendedObject = web3[extension.property]; 3513 } else { 3514 extendedObject = web3; 3515 } 3516 3517 if (extension.methods) { 3518 extension.methods.forEach(function (method) { 3519 method.attachToObject(extendedObject); 3520 method.setRequestManager(web3._requestManager); 3521 }); 3522 } 3523 3524 if (extension.properties) { 3525 extension.properties.forEach(function (property) { 3526 property.attachToObject(extendedObject); 3527 property.setRequestManager(web3._requestManager); 3528 }); 3529 } 3530 }; 3531 3532 ex.formatters = formatters; 3533 ex.utils = utils; 3534 ex.Method = Method; 3535 ex.Property = Property; 3536 3537 return ex; 3538 }; 3539 3540 3541 3542 module.exports = extend; 3543 3544 3545 },{"./../utils/utils":20,"./formatters":30,"./method":36,"./property":45}],29:[function(require,module,exports){ 3546 /* 3547 This file is part of web3.js. 3548 3549 web3.js is free software: you can redistribute it and/or modify 3550 it under the terms of the GNU Lesser General Public License as published by 3551 the Free Software Foundation, either version 3 of the License, or 3552 (at your option) any later version. 3553 3554 web3.js is distributed in the hope that it will be useful, 3555 but WITHOUT ANY WARRANTY; without even the implied warranty of 3556 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3557 GNU Lesser General Public License for more details. 3558 3559 You should have received a copy of the GNU Lesser General Public License 3560 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3561 */ 3562 /** @file filter.js 3563 * @authors: 3564 * Jeffrey Wilcke <jeff@ethdev.com> 3565 * Marek Kotewicz <marek@ethdev.com> 3566 * Marian Oancea <marian@ethdev.com> 3567 * Fabian Vogelsteller <fabian@ethdev.com> 3568 * Gav Wood <g@ethdev.com> 3569 * @date 2014 3570 */ 3571 3572 var formatters = require('./formatters'); 3573 var utils = require('../utils/utils'); 3574 3575 /** 3576 * Converts a given topic to a hex string, but also allows null values. 3577 * 3578 * @param {Mixed} value 3579 * @return {String} 3580 */ 3581 var toTopic = function(value){ 3582 3583 if(value === null || typeof value === 'undefined') 3584 return null; 3585 3586 value = String(value); 3587 3588 if(value.indexOf('0x') === 0) 3589 return value; 3590 else 3591 return utils.fromUtf8(value); 3592 }; 3593 3594 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3595 /// @param should be string or object 3596 /// @returns options string or object 3597 var getOptions = function (options, type) { 3598 /*jshint maxcomplexity: 6 */ 3599 3600 if (utils.isString(options)) { 3601 return options; 3602 } 3603 3604 options = options || {}; 3605 3606 3607 switch(type) { 3608 case 'klay': 3609 3610 // make sure topics, get converted to hex 3611 options.topics = options.topics || []; 3612 options.topics = options.topics.map(function(topic){ 3613 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3614 }); 3615 3616 return { 3617 topics: options.topics, 3618 from: options.from, 3619 to: options.to, 3620 address: options.address, 3621 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3622 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3623 }; 3624 case 'shh': 3625 return options; 3626 } 3627 }; 3628 3629 /** 3630 Adds the callback and sets up the methods, to iterate over the results. 3631 3632 @method getLogsAtStart 3633 @param {Object} self 3634 @param {function} callback 3635 */ 3636 var getLogsAtStart = function(self, callback){ 3637 // call getFilterLogs for the first watch callback start 3638 if (!utils.isString(self.options)) { 3639 self.get(function (err, messages) { 3640 // don't send all the responses to all the watches again... just to self one 3641 if (err) { 3642 callback(err); 3643 } 3644 3645 if(utils.isArray(messages)) { 3646 messages.forEach(function (message) { 3647 callback(null, message); 3648 }); 3649 } 3650 }); 3651 } 3652 }; 3653 3654 /** 3655 Adds the callback and sets up the methods, to iterate over the results. 3656 3657 @method pollFilter 3658 @param {Object} self 3659 */ 3660 var pollFilter = function(self) { 3661 3662 var onMessage = function (error, messages) { 3663 if (error) { 3664 return self.callbacks.forEach(function (callback) { 3665 callback(error); 3666 }); 3667 } 3668 3669 if(utils.isArray(messages)) { 3670 messages.forEach(function (message) { 3671 message = self.formatter ? self.formatter(message) : message; 3672 self.callbacks.forEach(function (callback) { 3673 callback(null, message); 3674 }); 3675 }); 3676 } 3677 }; 3678 3679 self.requestManager.startPolling({ 3680 method: self.implementation.poll.call, 3681 params: [self.filterId], 3682 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3683 3684 }; 3685 3686 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3687 var self = this; 3688 var implementation = {}; 3689 methods.forEach(function (method) { 3690 method.setRequestManager(requestManager); 3691 method.attachToObject(implementation); 3692 }); 3693 this.requestManager = requestManager; 3694 this.options = getOptions(options, type); 3695 this.implementation = implementation; 3696 this.filterId = null; 3697 this.callbacks = []; 3698 this.getLogsCallbacks = []; 3699 this.pollFilters = []; 3700 this.formatter = formatter; 3701 this.implementation.newFilter(this.options, function(error, id){ 3702 if(error) { 3703 self.callbacks.forEach(function(cb){ 3704 cb(error); 3705 }); 3706 if (typeof filterCreationErrorCallback === 'function') { 3707 filterCreationErrorCallback(error); 3708 } 3709 } else { 3710 self.filterId = id; 3711 3712 // check if there are get pending callbacks as a consequence 3713 // of calling get() with filterId unassigned. 3714 self.getLogsCallbacks.forEach(function (cb){ 3715 self.get(cb); 3716 }); 3717 self.getLogsCallbacks = []; 3718 3719 // get filter logs for the already existing watch calls 3720 self.callbacks.forEach(function(cb){ 3721 getLogsAtStart(self, cb); 3722 }); 3723 if(self.callbacks.length > 0) 3724 pollFilter(self); 3725 3726 // start to watch immediately 3727 if(typeof callback === 'function') { 3728 return self.watch(callback); 3729 } 3730 } 3731 }); 3732 3733 return this; 3734 }; 3735 3736 Filter.prototype.watch = function (callback) { 3737 this.callbacks.push(callback); 3738 3739 if(this.filterId) { 3740 getLogsAtStart(this, callback); 3741 pollFilter(this); 3742 } 3743 3744 return this; 3745 }; 3746 3747 Filter.prototype.stopWatching = function (callback) { 3748 this.requestManager.stopPolling(this.filterId); 3749 this.callbacks = []; 3750 // remove filter async 3751 if (callback) { 3752 this.implementation.uninstallFilter(this.filterId, callback); 3753 } else { 3754 return this.implementation.uninstallFilter(this.filterId); 3755 } 3756 }; 3757 3758 Filter.prototype.get = function (callback) { 3759 var self = this; 3760 if (utils.isFunction(callback)) { 3761 if (this.filterId === null) { 3762 // If filterId is not set yet, call it back 3763 // when newFilter() assigns it. 3764 this.getLogsCallbacks.push(callback); 3765 } else { 3766 this.implementation.getLogs(this.filterId, function(err, res){ 3767 if (err) { 3768 callback(err); 3769 } else { 3770 callback(null, res.map(function (log) { 3771 return self.formatter ? self.formatter(log) : log; 3772 })); 3773 } 3774 }); 3775 } 3776 } else { 3777 if (this.filterId === null) { 3778 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3779 } 3780 var logs = this.implementation.getLogs(this.filterId); 3781 return logs.map(function (log) { 3782 return self.formatter ? self.formatter(log) : log; 3783 }); 3784 } 3785 3786 return this; 3787 }; 3788 3789 module.exports = Filter; 3790 3791 3792 },{"../utils/utils":20,"./formatters":30}],30:[function(require,module,exports){ 3793 'use strict' 3794 3795 /* 3796 This file is part of web3.js. 3797 3798 web3.js is free software: you can redistribute it and/or modify 3799 it under the terms of the GNU Lesser General Public License as published by 3800 the Free Software Foundation, either version 3 of the License, or 3801 (at your option) any later version. 3802 3803 web3.js is distributed in the hope that it will be useful, 3804 but WITHOUT ANY WARRANTY; without even the implied warranty of 3805 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3806 GNU Lesser General Public License for more details. 3807 3808 You should have received a copy of the GNU Lesser General Public License 3809 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3810 */ 3811 /** 3812 * @file formatters.js 3813 * @author Marek Kotewicz <marek@ethdev.com> 3814 * @author Fabian Vogelsteller <fabian@ethdev.com> 3815 * @date 2015 3816 */ 3817 3818 var utils = require('../utils/utils'); 3819 var config = require('../utils/config'); 3820 var Iban = require('./iban'); 3821 3822 /** 3823 * Should the format output to a big number 3824 * 3825 * @method outputBigNumberFormatter 3826 * @param {String|Number|BigNumber} 3827 * @returns {BigNumber} object 3828 */ 3829 var outputBigNumberFormatter = function (number) { 3830 return utils.toBigNumber(number); 3831 }; 3832 3833 var isPredefinedBlockNumber = function (blockNumber) { 3834 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3835 }; 3836 3837 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3838 if (blockNumber === undefined) { 3839 return config.defaultBlock; 3840 } 3841 return inputBlockNumberFormatter(blockNumber); 3842 }; 3843 3844 var inputBlockNumberFormatter = function (blockNumber) { 3845 if (blockNumber === undefined) { 3846 return undefined; 3847 } else if (isPredefinedBlockNumber(blockNumber)) { 3848 return blockNumber; 3849 } 3850 return utils.toHex(blockNumber); 3851 }; 3852 3853 var inputEmptyFormatter = function (a) { 3854 if (a === undefined) return ""; 3855 else return a; 3856 } 3857 3858 /** 3859 * Formats the input of a transaction and converts all values to HEX 3860 * 3861 * @method inputCallFormatter 3862 * @param {Object} transaction options 3863 * @returns object 3864 */ 3865 var inputCallFormatter = function (options){ 3866 3867 options.from = options.from || config.defaultAccount; 3868 3869 if (options.from) { 3870 options.from = inputAddressFormatter(options.from); 3871 } 3872 3873 if (options.to) { // it might be contract creation 3874 options.to = inputAddressFormatter(options.to); 3875 } 3876 3877 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3878 return options[key] !== undefined; 3879 }).forEach(function(key){ 3880 options[key] = utils.fromDecimal(options[key]); 3881 }); 3882 3883 return options; 3884 }; 3885 3886 /** 3887 * Formats the input of a transaction and converts all values to HEX 3888 * 3889 * @method inputTransactionFormatter 3890 * @param {Object} transaction options 3891 * @returns object 3892 */ 3893 var inputTransactionFormatter = function (options){ 3894 3895 options.from = options.from || config.defaultAccount; 3896 options.from = inputAddressFormatter(options.from); 3897 3898 if (options.to) { // it might be contract creation 3899 options.to = inputAddressFormatter(options.to); 3900 } 3901 3902 ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) { 3903 return options[key] !== undefined; 3904 }).forEach(function(key){ 3905 options[key] = utils.fromDecimal(options[key]); 3906 }); 3907 3908 return options; 3909 }; 3910 3911 /** 3912 * Formats the output of a transaction to its proper values 3913 * 3914 * @method outputTransactionFormatter 3915 * @param {Object} tx 3916 * @returns {Object} 3917 */ 3918 var outputTransactionFormatter = function (tx){ 3919 if(tx.blockNumber !== null) 3920 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3921 if(tx.transactionIndex !== null) 3922 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3923 tx.nonce = utils.toDecimal(tx.nonce); 3924 tx.gas = utils.toDecimal(tx.gas); 3925 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3926 tx.value = utils.toBigNumber(tx.value); 3927 return tx; 3928 }; 3929 3930 /** 3931 * Formats the output of a transaction receipt to its proper values 3932 * 3933 * @method outputTransactionReceiptFormatter 3934 * @param {Object} receipt 3935 * @returns {Object} 3936 */ 3937 var outputTransactionReceiptFormatter = function (receipt){ 3938 if(receipt.blockNumber !== null) 3939 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3940 if(receipt.transactionIndex !== null) 3941 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3942 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3943 3944 3945 //console.log(receipt.txError, 'receipt.txError') 3946 //console.log(receipt.status, 'receipt.status') 3947 3948 if(utils.isArray(receipt.logs)) { 3949 receipt.logs = receipt.logs.map(function(log){ 3950 return outputLogFormatter(log); 3951 }); 3952 } 3953 3954 return receipt; 3955 }; 3956 3957 /** 3958 * Formats the output of a block to its proper values 3959 * 3960 * @method outputBlockFormatter 3961 * @param {Object} block 3962 * @returns {Object} 3963 */ 3964 var outputBlockFormatter = function(block) { 3965 3966 // transform to number 3967 block.gasUsed = utils.toDecimal(block.gasUsed); 3968 block.size = utils.toDecimal(block.size); 3969 block.timestamp = utils.toDecimal(block.timestamp); 3970 block.timestampFoS = utils.toDecimal(block.timestampFoS); 3971 if(block.number !== null) 3972 block.number = utils.toDecimal(block.number); 3973 3974 if (utils.isArray(block.transactions)) { 3975 block.transactions.forEach(function(item){ 3976 if(!utils.isString(item)) 3977 return outputTransactionFormatter(item); 3978 }); 3979 } 3980 3981 return block; 3982 }; 3983 3984 /** 3985 * Formats the output of a log 3986 * 3987 * @method outputLogFormatter 3988 * @param {Object} log object 3989 * @returns {Object} log 3990 */ 3991 var outputLogFormatter = function(log) { 3992 if(log.blockNumber) 3993 log.blockNumber = utils.toDecimal(log.blockNumber); 3994 if(log.transactionIndex) 3995 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3996 if(log.logIndex) 3997 log.logIndex = utils.toDecimal(log.logIndex); 3998 3999 return log; 4000 }; 4001 4002 /** 4003 * Formats the input of a whisper post and converts all values to HEX 4004 * 4005 * @method inputPostFormatter 4006 * @param {Object} transaction object 4007 * @returns {Object} 4008 */ 4009 var inputPostFormatter = function(post) { 4010 4011 // post.payload = utils.toHex(post.payload); 4012 post.ttl = utils.fromDecimal(post.ttl); 4013 post.workToProve = utils.fromDecimal(post.workToProve); 4014 post.priority = utils.fromDecimal(post.priority); 4015 4016 // fallback 4017 if (!utils.isArray(post.topics)) { 4018 post.topics = post.topics ? [post.topics] : []; 4019 } 4020 4021 // format the following options 4022 post.topics = post.topics.map(function(topic){ 4023 // convert only if not hex 4024 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 4025 }); 4026 4027 return post; 4028 }; 4029 4030 /** 4031 * Formats the output of a received post message 4032 * 4033 * @method outputPostFormatter 4034 * @param {Object} 4035 * @returns {Object} 4036 */ 4037 var outputPostFormatter = function(post){ 4038 4039 post.expiry = utils.toDecimal(post.expiry); 4040 post.sent = utils.toDecimal(post.sent); 4041 post.ttl = utils.toDecimal(post.ttl); 4042 post.workProved = utils.toDecimal(post.workProved); 4043 // post.payloadRaw = post.payload; 4044 // post.payload = utils.toAscii(post.payload); 4045 4046 // if (utils.isJson(post.payload)) { 4047 // post.payload = JSON.parse(post.payload); 4048 // } 4049 4050 // format the following options 4051 if (!post.topics) { 4052 post.topics = []; 4053 } 4054 post.topics = post.topics.map(function(topic){ 4055 return utils.toAscii(topic); 4056 }); 4057 4058 return post; 4059 }; 4060 4061 var inputAddressFormatter = function (address) { 4062 var iban = new Iban(address); 4063 if (iban.isValid() && iban.isDirect()) { 4064 return '0x' + iban.address(); 4065 } else if (utils.isStrictAddress(address)) { 4066 return address; 4067 } else if (utils.isAddress(address)) { 4068 return '0x' + address; 4069 } 4070 throw new Error('invalid address'); 4071 }; 4072 4073 4074 var outputSyncingFormatter = function(result) { 4075 if (!result) { 4076 return result; 4077 } 4078 4079 result.startingBlock = utils.toDecimal(result.startingBlock); 4080 result.currentBlock = utils.toDecimal(result.currentBlock); 4081 result.highestBlock = utils.toDecimal(result.highestBlock); 4082 if (result.knownStates) { 4083 result.knownStates = utils.toDecimal(result.knownStates); 4084 result.pulledStates = utils.toDecimal(result.pulledStates); 4085 } 4086 4087 return result; 4088 }; 4089 4090 module.exports = { 4091 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 4092 inputBlockNumberFormatter: inputBlockNumberFormatter, 4093 inputCallFormatter: inputCallFormatter, 4094 inputTransactionFormatter: inputTransactionFormatter, 4095 inputAddressFormatter: inputAddressFormatter, 4096 inputPostFormatter: inputPostFormatter, 4097 outputBigNumberFormatter: outputBigNumberFormatter, 4098 outputTransactionFormatter: outputTransactionFormatter, 4099 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 4100 outputBlockFormatter: outputBlockFormatter, 4101 outputLogFormatter: outputLogFormatter, 4102 outputPostFormatter: outputPostFormatter, 4103 outputSyncingFormatter: outputSyncingFormatter 4104 }; 4105 4106 4107 },{"../utils/config":18,"../utils/utils":20,"./iban":33}],31:[function(require,module,exports){ 4108 /* 4109 This file is part of web3.js. 4110 4111 web3.js is free software: you can redistribute it and/or modify 4112 it under the terms of the GNU Lesser General Public License as published by 4113 the Free Software Foundation, either version 3 of the License, or 4114 (at your option) any later version. 4115 4116 web3.js is distributed in the hope that it will be useful, 4117 but WITHOUT ANY WARRANTY; without even the implied warranty of 4118 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4119 GNU Lesser General Public License for more details. 4120 4121 You should have received a copy of the GNU Lesser General Public License 4122 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4123 */ 4124 /** 4125 * @file function.js 4126 * @author Marek Kotewicz <marek@ethdev.com> 4127 * @date 2015 4128 */ 4129 4130 var coder = require('../solidity/coder'); 4131 var utils = require('../utils/utils'); 4132 var errors = require('./errors'); 4133 var formatters = require('./formatters'); 4134 var sha3 = require('../utils/sha3'); 4135 4136 /** 4137 * This prototype should be used to call/sendTransaction to solidity functions 4138 */ 4139 var SolidityFunction = function (klay, json, address) { 4140 this._klay = klay; 4141 this._inputTypes = json.inputs.map(function (i) { 4142 return i.type; 4143 }); 4144 this._outputTypes = json.outputs.map(function (i) { 4145 return i.type; 4146 }); 4147 this._constant = json.constant; 4148 this._payable = json.payable; 4149 this._name = utils.transformToFullName(json); 4150 this._address = address; 4151 }; 4152 4153 SolidityFunction.prototype.extractCallback = function (args) { 4154 if (utils.isFunction(args[args.length - 1])) { 4155 return args.pop(); // modify the args array! 4156 } 4157 }; 4158 4159 SolidityFunction.prototype.extractDefaultBlock = function (args) { 4160 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) { 4161 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4162 } 4163 }; 4164 4165 /** 4166 * Should be called to check if the number of arguments is correct 4167 * 4168 * @method validateArgs 4169 * @param {Array} arguments 4170 * @throws {Error} if it is not 4171 */ 4172 SolidityFunction.prototype.validateArgs = function (args) { 4173 var inputArgs = args.filter(function (a) { 4174 // filter the options object but not arguments that are arrays 4175 return !( (utils.isObject(a) === true) && 4176 (utils.isArray(a) === false) && 4177 (utils.isBigNumber(a) === false) 4178 ); 4179 }); 4180 if (inputArgs.length !== this._inputTypes.length) { 4181 throw errors.InvalidNumberOfSolidityArgs(); 4182 } 4183 }; 4184 4185 /** 4186 * Should be used to create payload from arguments 4187 * 4188 * @method toPayload 4189 * @param {Array} solidity function params 4190 * @param {Object} optional payload options 4191 */ 4192 SolidityFunction.prototype.toPayload = function (args) { 4193 var options = {}; 4194 if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) { 4195 options = args[args.length - 1]; 4196 } 4197 this.validateArgs(args); 4198 options.to = this._address; 4199 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4200 return options; 4201 }; 4202 4203 /** 4204 * Should be used to get function signature 4205 * 4206 * @method signature 4207 * @return {String} function signature 4208 */ 4209 SolidityFunction.prototype.signature = function () { 4210 return sha3(this._name).slice(0, 8); 4211 }; 4212 4213 4214 SolidityFunction.prototype.unpackOutput = function (output) { 4215 if (!output) { 4216 return; 4217 } 4218 4219 output = output.length >= 2 ? output.slice(2) : output; 4220 var result = coder.decodeParams(this._outputTypes, output); 4221 return result.length === 1 ? result[0] : result; 4222 }; 4223 4224 /** 4225 * Calls a contract function. 4226 * 4227 * @method call 4228 * @param {...Object} Contract function arguments 4229 * @param {function} If the last argument is a function, the contract function 4230 * call will be asynchronous, and the callback will be passed the 4231 * error and result. 4232 * @return {String} output bytes 4233 */ 4234 SolidityFunction.prototype.call = function () { 4235 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4236 var callback = this.extractCallback(args); 4237 var defaultBlock = this.extractDefaultBlock(args); 4238 var payload = this.toPayload(args); 4239 4240 4241 if (!callback) { 4242 var output = this._klay.call(payload, defaultBlock); 4243 return this.unpackOutput(output); 4244 } 4245 4246 var self = this; 4247 this._klay.call(payload, defaultBlock, function (error, output) { 4248 if (error) return callback(error, null); 4249 4250 var unpacked = null; 4251 try { 4252 unpacked = self.unpackOutput(output); 4253 } 4254 catch (e) { 4255 error = e; 4256 } 4257 4258 callback(error, unpacked); 4259 }); 4260 }; 4261 4262 /** 4263 * Should be used to sendTransaction to solidity function 4264 * 4265 * @method sendTransaction 4266 */ 4267 SolidityFunction.prototype.sendTransaction = function () { 4268 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4269 var callback = this.extractCallback(args); 4270 var payload = this.toPayload(args); 4271 4272 if (payload.value > 0 && !this._payable) { 4273 throw new Error('Cannot send value to non-payable function'); 4274 } 4275 4276 if (!callback) { 4277 return this._klay.sendTransaction(payload); 4278 } 4279 4280 this._klay.sendTransaction(payload, callback); 4281 }; 4282 4283 /** 4284 * Should be used to estimateGas of solidity function 4285 * 4286 * @method estimateGas 4287 */ 4288 SolidityFunction.prototype.estimateGas = function () { 4289 var args = Array.prototype.slice.call(arguments); 4290 var callback = this.extractCallback(args); 4291 var payload = this.toPayload(args); 4292 4293 if (!callback) { 4294 return this._klay.estimateGas(payload); 4295 } 4296 4297 this._klay.estimateGas(payload, callback); 4298 }; 4299 4300 /** 4301 * Return the encoded data of the call 4302 * 4303 * @method getData 4304 * @return {String} the encoded data 4305 */ 4306 SolidityFunction.prototype.getData = function () { 4307 var args = Array.prototype.slice.call(arguments); 4308 var payload = this.toPayload(args); 4309 4310 return payload.data; 4311 }; 4312 4313 /** 4314 * Should be used to get function display name 4315 * 4316 * @method displayName 4317 * @return {String} display name of the function 4318 */ 4319 SolidityFunction.prototype.displayName = function () { 4320 return utils.extractDisplayName(this._name); 4321 }; 4322 4323 /** 4324 * Should be used to get function type name 4325 * 4326 * @method typeName 4327 * @return {String} type name of the function 4328 */ 4329 SolidityFunction.prototype.typeName = function () { 4330 return utils.extractTypeName(this._name); 4331 }; 4332 4333 /** 4334 * Should be called to get rpc requests from solidity function 4335 * 4336 * @method request 4337 * @returns {Object} 4338 */ 4339 SolidityFunction.prototype.request = function () { 4340 var args = Array.prototype.slice.call(arguments); 4341 var callback = this.extractCallback(args); 4342 var payload = this.toPayload(args); 4343 var format = this.unpackOutput.bind(this); 4344 4345 return { 4346 method: this._constant ? 'klay_call' : 'klay_sendTransaction', 4347 callback: callback, 4348 params: [payload], 4349 format: format 4350 }; 4351 }; 4352 4353 /** 4354 * Should be called to execute function 4355 * 4356 * @method execute 4357 */ 4358 SolidityFunction.prototype.execute = function () { 4359 var transaction = !this._constant; 4360 4361 // send transaction 4362 if (transaction) { 4363 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4364 } 4365 4366 // call 4367 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4368 }; 4369 4370 /** 4371 * Should be called to attach function to contract 4372 * 4373 * @method attachToContract 4374 * @param {Contract} 4375 */ 4376 SolidityFunction.prototype.attachToContract = function (contract) { 4377 var execute = this.execute.bind(this); 4378 execute.request = this.request.bind(this); 4379 execute.call = this.call.bind(this); 4380 execute.sendTransaction = this.sendTransaction.bind(this); 4381 execute.estimateGas = this.estimateGas.bind(this); 4382 execute.getData = this.getData.bind(this); 4383 var displayName = this.displayName(); 4384 if (!contract[displayName]) { 4385 contract[displayName] = execute; 4386 } 4387 contract[displayName][this.typeName()] = execute; // circular!!!! 4388 }; 4389 4390 module.exports = SolidityFunction; 4391 4392 },{"../solidity/coder":7,"../utils/sha3":19,"../utils/utils":20,"./errors":26,"./formatters":30}],32:[function(require,module,exports){ 4393 /* 4394 This file is part of web3.js. 4395 4396 web3.js is free software: you can redistribute it and/or modify 4397 it under the terms of the GNU Lesser General Public License as published by 4398 the Free Software Foundation, either version 3 of the License, or 4399 (at your option) any later version. 4400 4401 web3.js is distributed in the hope that it will be useful, 4402 but WITHOUT ANY WARRANTY; without even the implied warranty of 4403 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4404 GNU Lesser General Public License for more details. 4405 4406 You should have received a copy of the GNU Lesser General Public License 4407 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4408 */ 4409 /** @file httpprovider.js 4410 * @authors: 4411 * Marek Kotewicz <marek@ethdev.com> 4412 * Marian Oancea <marian@ethdev.com> 4413 * Fabian Vogelsteller <fabian@ethdev.com> 4414 * @date 2015 4415 */ 4416 4417 var errors = require('./errors'); 4418 4419 // workaround to use httpprovider in different envs 4420 4421 // browser 4422 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4423 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4424 // node 4425 } else { 4426 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4427 } 4428 4429 var XHR2 = require('xhr2'); // jshint ignore: line 4430 4431 /** 4432 * HttpProvider should be used to send rpc calls over http 4433 */ 4434 var HttpProvider = function (host, timeout, user, password) { 4435 this.host = host || 'http://localhost:8545'; 4436 this.timeout = timeout || 0; 4437 this.user = user; 4438 this.password = password; 4439 }; 4440 4441 /** 4442 * Should be called to prepare new XMLHttpRequest 4443 * 4444 * @method prepareRequest 4445 * @param {Boolean} true if request should be async 4446 * @return {XMLHttpRequest} object 4447 */ 4448 HttpProvider.prototype.prepareRequest = function (async) { 4449 var request; 4450 4451 if (async) { 4452 request = new XHR2(); 4453 request.timeout = this.timeout; 4454 } else { 4455 request = new XMLHttpRequest(); 4456 } 4457 4458 request.open('POST', this.host, async); 4459 if (this.user && this.password) { 4460 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4461 request.setRequestHeader('Authorization', auth); 4462 } request.setRequestHeader('Content-Type', 'application/json'); 4463 return request; 4464 }; 4465 4466 /** 4467 * Should be called to make sync request 4468 * 4469 * @method send 4470 * @param {Object} payload 4471 * @return {Object} result 4472 */ 4473 HttpProvider.prototype.send = function (payload) { 4474 var request = this.prepareRequest(false); 4475 4476 try { 4477 request.send(JSON.stringify(payload)); 4478 } catch (error) { 4479 throw errors.InvalidConnection(this.host); 4480 } 4481 4482 var result = request.responseText; 4483 4484 try { 4485 result = JSON.parse(result); 4486 } catch (e) { 4487 throw errors.InvalidResponse(request.responseText); 4488 } 4489 4490 return result; 4491 }; 4492 4493 /** 4494 * Should be used to make async request 4495 * 4496 * @method sendAsync 4497 * @param {Object} payload 4498 * @param {Function} callback triggered on end with (err, result) 4499 */ 4500 HttpProvider.prototype.sendAsync = function (payload, callback) { 4501 var request = this.prepareRequest(true); 4502 4503 request.onreadystatechange = function () { 4504 if (request.readyState === 4 && request.timeout !== 1) { 4505 var result = request.responseText; 4506 var error = null; 4507 4508 try { 4509 result = JSON.parse(result); 4510 } catch (e) { 4511 error = errors.InvalidResponse(request.responseText); 4512 } 4513 4514 callback(error, result); 4515 } 4516 }; 4517 4518 request.ontimeout = function () { 4519 callback(errors.ConnectionTimeout(this.timeout)); 4520 }; 4521 4522 try { 4523 request.send(JSON.stringify(payload)); 4524 } catch (error) { 4525 callback(errors.InvalidConnection(this.host)); 4526 } 4527 }; 4528 4529 /** 4530 * Synchronously tries to make Http request 4531 * 4532 * @method isConnected 4533 * @return {Boolean} returns true if request haven't failed. Otherwise false 4534 */ 4535 HttpProvider.prototype.isConnected = function () { 4536 try { 4537 this.send({ 4538 id: 9999999999, 4539 jsonrpc: '2.0', 4540 method: 'net_listening', 4541 params: [] 4542 }); 4543 return true; 4544 } catch (e) { 4545 return false; 4546 } 4547 }; 4548 4549 module.exports = HttpProvider; 4550 4551 },{"./errors":26,"xhr2":86,"xmlhttprequest":17}],33:[function(require,module,exports){ 4552 /* 4553 This file is part of web3.js. 4554 4555 web3.js is free software: you can redistribute it and/or modify 4556 it under the terms of the GNU Lesser General Public License as published by 4557 the Free Software Foundation, either version 3 of the License, or 4558 (at your option) any later version. 4559 4560 web3.js is distributed in the hope that it will be useful, 4561 but WITHOUT ANY WARRANTY; without even the implied warranty of 4562 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4563 GNU Lesser General Public License for more details. 4564 4565 You should have received a copy of the GNU Lesser General Public License 4566 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4567 */ 4568 /** 4569 * @file iban.js 4570 * @author Marek Kotewicz <marek@ethdev.com> 4571 * @date 2015 4572 */ 4573 4574 var BigNumber = require('bignumber.js'); 4575 4576 var padLeft = function (string, bytes) { 4577 var result = string; 4578 while (result.length < bytes * 2) { 4579 result = '0' + result; 4580 } 4581 return result; 4582 }; 4583 4584 /** 4585 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4586 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4587 * 4588 * @method iso13616Prepare 4589 * @param {String} iban the IBAN 4590 * @returns {String} the prepared IBAN 4591 */ 4592 var iso13616Prepare = function (iban) { 4593 var A = 'A'.charCodeAt(0); 4594 var Z = 'Z'.charCodeAt(0); 4595 4596 iban = iban.toUpperCase(); 4597 iban = iban.substr(4) + iban.substr(0,4); 4598 4599 return iban.split('').map(function(n){ 4600 var code = n.charCodeAt(0); 4601 if (code >= A && code <= Z){ 4602 // A = 10, B = 11, ... Z = 35 4603 return code - A + 10; 4604 } else { 4605 return n; 4606 } 4607 }).join(''); 4608 }; 4609 4610 /** 4611 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4612 * 4613 * @method mod9710 4614 * @param {String} iban 4615 * @returns {Number} 4616 */ 4617 var mod9710 = function (iban) { 4618 var remainder = iban, 4619 block; 4620 4621 while (remainder.length > 2){ 4622 block = remainder.slice(0, 9); 4623 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4624 } 4625 4626 return parseInt(remainder, 10) % 97; 4627 }; 4628 4629 /** 4630 * This prototype should be used to create iban object from iban correct string 4631 * 4632 * @param {String} iban 4633 */ 4634 var Iban = function (iban) { 4635 this._iban = iban; 4636 }; 4637 4638 /** 4639 * This method should be used to create iban object from ethereum address 4640 * 4641 * @method fromAddress 4642 * @param {String} address 4643 * @return {Iban} the IBAN object 4644 */ 4645 Iban.fromAddress = function (address) { 4646 var asBn = new BigNumber(address, 16); 4647 var base36 = asBn.toString(36); 4648 var padded = padLeft(base36, 15); 4649 return Iban.fromBban(padded.toUpperCase()); 4650 }; 4651 4652 /** 4653 * Convert the passed BBAN to an IBAN for this country specification. 4654 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4655 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4656 * 4657 * @method fromBban 4658 * @param {String} bban the BBAN to convert to IBAN 4659 * @returns {Iban} the IBAN object 4660 */ 4661 Iban.fromBban = function (bban) { 4662 var countryCode = 'XE'; 4663 4664 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4665 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4666 4667 return new Iban(countryCode + checkDigit + bban); 4668 }; 4669 4670 /** 4671 * Should be used to create IBAN object for given institution and identifier 4672 * 4673 * @method createIndirect 4674 * @param {Object} options, required options are "institution" and "identifier" 4675 * @return {Iban} the IBAN object 4676 */ 4677 Iban.createIndirect = function (options) { 4678 return Iban.fromBban('ETH' + options.institution + options.identifier); 4679 }; 4680 4681 /** 4682 * Thos method should be used to check if given string is valid iban object 4683 * 4684 * @method isValid 4685 * @param {String} iban string 4686 * @return {Boolean} true if it is valid IBAN 4687 */ 4688 Iban.isValid = function (iban) { 4689 var i = new Iban(iban); 4690 return i.isValid(); 4691 }; 4692 4693 /** 4694 * Should be called to check if iban is correct 4695 * 4696 * @method isValid 4697 * @returns {Boolean} true if it is, otherwise false 4698 */ 4699 Iban.prototype.isValid = function () { 4700 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4701 mod9710(iso13616Prepare(this._iban)) === 1; 4702 }; 4703 4704 /** 4705 * Should be called to check if iban number is direct 4706 * 4707 * @method isDirect 4708 * @returns {Boolean} true if it is, otherwise false 4709 */ 4710 Iban.prototype.isDirect = function () { 4711 return this._iban.length === 34 || this._iban.length === 35; 4712 }; 4713 4714 /** 4715 * Should be called to check if iban number if indirect 4716 * 4717 * @method isIndirect 4718 * @returns {Boolean} true if it is, otherwise false 4719 */ 4720 Iban.prototype.isIndirect = function () { 4721 return this._iban.length === 20; 4722 }; 4723 4724 /** 4725 * Should be called to get iban checksum 4726 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4727 * 4728 * @method checksum 4729 * @returns {String} checksum 4730 */ 4731 Iban.prototype.checksum = function () { 4732 return this._iban.substr(2, 2); 4733 }; 4734 4735 /** 4736 * Should be called to get institution identifier 4737 * eg. XREG 4738 * 4739 * @method institution 4740 * @returns {String} institution identifier 4741 */ 4742 Iban.prototype.institution = function () { 4743 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4744 }; 4745 4746 /** 4747 * Should be called to get client identifier within institution 4748 * eg. GAVOFYORK 4749 * 4750 * @method client 4751 * @returns {String} client identifier 4752 */ 4753 Iban.prototype.client = function () { 4754 return this.isIndirect() ? this._iban.substr(11) : ''; 4755 }; 4756 4757 /** 4758 * Should be called to get client direct address 4759 * 4760 * @method address 4761 * @returns {String} client direct address 4762 */ 4763 Iban.prototype.address = function () { 4764 if (this.isDirect()) { 4765 var base36 = this._iban.substr(4); 4766 var asBn = new BigNumber(base36, 36); 4767 return padLeft(asBn.toString(16), 20); 4768 } 4769 4770 return ''; 4771 }; 4772 4773 Iban.prototype.toString = function () { 4774 return this._iban; 4775 }; 4776 4777 module.exports = Iban; 4778 4779 4780 },{"bignumber.js":"bignumber.js"}],34:[function(require,module,exports){ 4781 /* 4782 This file is part of web3.js. 4783 4784 web3.js is free software: you can redistribute it and/or modify 4785 it under the terms of the GNU Lesser General Public License as published by 4786 the Free Software Foundation, either version 3 of the License, or 4787 (at your option) any later version. 4788 4789 web3.js is distributed in the hope that it will be useful, 4790 but WITHOUT ANY WARRANTY; without even the implied warranty of 4791 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4792 GNU Lesser General Public License for more details. 4793 4794 You should have received a copy of the GNU Lesser General Public License 4795 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4796 */ 4797 /** @file ipcprovider.js 4798 * @authors: 4799 * Fabian Vogelsteller <fabian@ethdev.com> 4800 * @date 2015 4801 */ 4802 4803 "use strict"; 4804 4805 var utils = require('../utils/utils'); 4806 var errors = require('./errors'); 4807 4808 4809 var IpcProvider = function (path, net) { 4810 var _this = this; 4811 this.responseCallbacks = {}; 4812 this.path = path; 4813 4814 this.connection = net.connect({path: this.path}); 4815 4816 this.connection.on('error', function(e){ 4817 console.error('IPC Connection Error', e); 4818 _this._timeout(); 4819 }); 4820 4821 this.connection.on('end', function(){ 4822 _this._timeout(); 4823 }); 4824 4825 4826 // LISTEN FOR CONNECTION RESPONSES 4827 this.connection.on('data', function(data) { 4828 /*jshint maxcomplexity: 6 */ 4829 4830 _this._parseResponse(data.toString()).forEach(function(result){ 4831 4832 var id = null; 4833 4834 // get the id which matches the returned id 4835 if(utils.isArray(result)) { 4836 result.forEach(function(load){ 4837 if(_this.responseCallbacks[load.id]) 4838 id = load.id; 4839 }); 4840 } else { 4841 id = result.id; 4842 } 4843 4844 // fire the callback 4845 if(_this.responseCallbacks[id]) { 4846 _this.responseCallbacks[id](null, result); 4847 delete _this.responseCallbacks[id]; 4848 } 4849 }); 4850 }); 4851 }; 4852 4853 /** 4854 Will parse the response and make an array out of it. 4855 4856 @method _parseResponse 4857 @param {String} data 4858 */ 4859 IpcProvider.prototype._parseResponse = function(data) { 4860 var _this = this, 4861 returnValues = []; 4862 4863 // DE-CHUNKER 4864 var dechunkedData = data 4865 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4866 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4867 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4868 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4869 .split('|--|'); 4870 4871 dechunkedData.forEach(function(data){ 4872 4873 // prepend the last chunk 4874 if(_this.lastChunk) 4875 data = _this.lastChunk + data; 4876 4877 var result = null; 4878 4879 try { 4880 result = JSON.parse(data); 4881 4882 } catch(e) { 4883 4884 _this.lastChunk = data; 4885 4886 // start timeout to cancel all requests 4887 clearTimeout(_this.lastChunkTimeout); 4888 _this.lastChunkTimeout = setTimeout(function(){ 4889 _this._timeout(); 4890 throw errors.InvalidResponse(data); 4891 }, 1000 * 15); 4892 4893 return; 4894 } 4895 4896 // cancel timeout and set chunk to null 4897 clearTimeout(_this.lastChunkTimeout); 4898 _this.lastChunk = null; 4899 4900 if(result) 4901 returnValues.push(result); 4902 }); 4903 4904 return returnValues; 4905 }; 4906 4907 4908 /** 4909 Get the adds a callback to the responseCallbacks object, 4910 which will be called if a response matching the response Id will arrive. 4911 4912 @method _addResponseCallback 4913 */ 4914 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4915 var id = payload.id || payload[0].id; 4916 var method = payload.method || payload[0].method; 4917 4918 this.responseCallbacks[id] = callback; 4919 this.responseCallbacks[id].method = method; 4920 }; 4921 4922 /** 4923 Timeout all requests when the end/error event is fired 4924 4925 @method _timeout 4926 */ 4927 IpcProvider.prototype._timeout = function() { 4928 for(var key in this.responseCallbacks) { 4929 if(this.responseCallbacks.hasOwnProperty(key)){ 4930 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4931 delete this.responseCallbacks[key]; 4932 } 4933 } 4934 }; 4935 4936 4937 /** 4938 Check if the current connection is still valid. 4939 4940 @method isConnected 4941 */ 4942 IpcProvider.prototype.isConnected = function() { 4943 var _this = this; 4944 4945 // try reconnect, when connection is gone 4946 if(!_this.connection.writable) 4947 _this.connection.connect({path: _this.path}); 4948 4949 return !!this.connection.writable; 4950 }; 4951 4952 IpcProvider.prototype.send = function (payload) { 4953 4954 if(this.connection.writeSync) { 4955 var result; 4956 4957 // try reconnect, when connection is gone 4958 if(!this.connection.writable) 4959 this.connection.connect({path: this.path}); 4960 4961 var data = this.connection.writeSync(JSON.stringify(payload)); 4962 4963 try { 4964 result = JSON.parse(data); 4965 } catch(e) { 4966 throw errors.InvalidResponse(data); 4967 } 4968 4969 return result; 4970 4971 } else { 4972 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4973 } 4974 }; 4975 4976 IpcProvider.prototype.sendAsync = function (payload, callback) { 4977 // try reconnect, when connection is gone 4978 if(!this.connection.writable) 4979 this.connection.connect({path: this.path}); 4980 4981 4982 this.connection.write(JSON.stringify(payload)); 4983 this._addResponseCallback(payload, callback); 4984 }; 4985 4986 module.exports = IpcProvider; 4987 4988 4989 },{"../utils/utils":20,"./errors":26}],35:[function(require,module,exports){ 4990 /* 4991 This file is part of web3.js. 4992 4993 web3.js is free software: you can redistribute it and/or modify 4994 it under the terms of the GNU Lesser General Public License as published by 4995 the Free Software Foundation, either version 3 of the License, or 4996 (at your option) any later version. 4997 4998 web3.js is distributed in the hope that it will be useful, 4999 but WITHOUT ANY WARRANTY; without even the implied warranty of 5000 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5001 GNU Lesser General Public License for more details. 5002 5003 You should have received a copy of the GNU Lesser General Public License 5004 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5005 */ 5006 /** @file jsonrpc.js 5007 * @authors: 5008 * Marek Kotewicz <marek@ethdev.com> 5009 * Aaron Kumavis <aaron@kumavis.me> 5010 * @date 2015 5011 */ 5012 5013 // Initialize Jsonrpc as a simple object with utility functions. 5014 var Jsonrpc = { 5015 messageId: 0 5016 }; 5017 5018 /** 5019 * Should be called to valid json create payload object 5020 * 5021 * @method toPayload 5022 * @param {Function} method of jsonrpc call, required 5023 * @param {Array} params, an array of method params, optional 5024 * @returns {Object} valid jsonrpc payload object 5025 */ 5026 Jsonrpc.toPayload = function (method, params) { 5027 if (!method) 5028 console.error('jsonrpc method should be specified!'); 5029 5030 // advance message ID 5031 Jsonrpc.messageId++; 5032 5033 return { 5034 jsonrpc: '2.0', 5035 id: Jsonrpc.messageId, 5036 method: method, 5037 params: params || [] 5038 }; 5039 }; 5040 5041 /** 5042 * Should be called to check if jsonrpc response is valid 5043 * 5044 * @method isValidResponse 5045 * @param {Object} 5046 * @returns {Boolean} true if response is valid, otherwise false 5047 */ 5048 Jsonrpc.isValidResponse = function (response) { 5049 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 5050 5051 function validateSingleMessage(message){ 5052 return !!message && 5053 !message.error && 5054 message.jsonrpc === '2.0' && 5055 typeof message.id === 'number' && 5056 message.result !== undefined; // only undefined is not valid json object 5057 } 5058 }; 5059 5060 /** 5061 * Should be called to create batch payload object 5062 * 5063 * @method toBatchPayload 5064 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 5065 * @returns {Array} batch payload 5066 */ 5067 Jsonrpc.toBatchPayload = function (messages) { 5068 return messages.map(function (message) { 5069 return Jsonrpc.toPayload(message.method, message.params); 5070 }); 5071 }; 5072 5073 module.exports = Jsonrpc; 5074 5075 5076 },{}],36:[function(require,module,exports){ 5077 /* 5078 This file is part of web3.js. 5079 5080 web3.js is free software: you can redistribute it and/or modify 5081 it under the terms of the GNU Lesser General Public License as published by 5082 the Free Software Foundation, either version 3 of the License, or 5083 (at your option) any later version. 5084 5085 web3.js is distributed in the hope that it will be useful, 5086 but WITHOUT ANY WARRANTY; without even the implied warranty of 5087 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5088 GNU Lesser General Public License for more details. 5089 5090 You should have received a copy of the GNU Lesser General Public License 5091 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5092 */ 5093 /** 5094 * @file method.js 5095 * @author Marek Kotewicz <marek@ethdev.com> 5096 * @date 2015 5097 */ 5098 5099 var utils = require('../utils/utils'); 5100 var errors = require('./errors'); 5101 5102 var Method = function (options) { 5103 this.name = options.name; 5104 this.call = options.call; 5105 this.params = options.params || 0; 5106 this.inputFormatter = options.inputFormatter; 5107 this.outputFormatter = options.outputFormatter; 5108 this.requestManager = null; 5109 }; 5110 5111 Method.prototype.setRequestManager = function (rm) { 5112 this.requestManager = rm; 5113 }; 5114 5115 /** 5116 * Should be used to determine name of the jsonrpc method based on arguments 5117 * 5118 * @method getCall 5119 * @param {Array} arguments 5120 * @return {String} name of jsonrpc method 5121 */ 5122 Method.prototype.getCall = function (args) { 5123 return utils.isFunction(this.call) ? this.call(args) : this.call; 5124 }; 5125 5126 /** 5127 * Should be used to extract callback from array of arguments. Modifies input param 5128 * 5129 * @method extractCallback 5130 * @param {Array} arguments 5131 * @return {Function|Null} callback, if exists 5132 */ 5133 Method.prototype.extractCallback = function (args) { 5134 if (utils.isFunction(args[args.length - 1])) { 5135 return args.pop(); // modify the args array! 5136 } 5137 }; 5138 5139 /** 5140 * Should be called to check if the number of arguments is correct 5141 * 5142 * @method validateArgs 5143 * @param {Array} arguments 5144 * @throws {Error} if it is not 5145 */ 5146 Method.prototype.validateArgs = function (args) { 5147 if (args.length !== this.params) { 5148 throw errors.InvalidNumberOfRPCParams(); 5149 } 5150 }; 5151 5152 /** 5153 * Should be called to format input args of method 5154 * 5155 * @method formatInput 5156 * @param {Array} 5157 * @return {Array} 5158 */ 5159 Method.prototype.formatInput = function (args) { 5160 if (!this.inputFormatter) { 5161 return args; 5162 } 5163 5164 return this.inputFormatter.map(function (formatter, index) { 5165 return formatter ? formatter(args[index]) : args[index]; 5166 }); 5167 }; 5168 5169 /** 5170 * Should be called to format output(result) of method 5171 * 5172 * @method formatOutput 5173 * @param {Object} 5174 * @return {Object} 5175 */ 5176 Method.prototype.formatOutput = function (result) { 5177 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5178 }; 5179 5180 /** 5181 * Should create payload from given input args 5182 * 5183 * @method toPayload 5184 * @param {Array} args 5185 * @return {Object} 5186 */ 5187 Method.prototype.toPayload = function (args) { 5188 var call = this.getCall(args); 5189 var callback = this.extractCallback(args); 5190 var params = this.formatInput(args); 5191 this.validateArgs(params); 5192 5193 return { 5194 method: call, 5195 params: params, 5196 callback: callback 5197 }; 5198 }; 5199 5200 Method.prototype.attachToObject = function (obj) { 5201 var func = this.buildCall(); 5202 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5203 var name = this.name.split('.'); 5204 if (name.length > 1) { 5205 obj[name[0]] = obj[name[0]] || {}; 5206 obj[name[0]][name[1]] = func; 5207 } else { 5208 obj[name[0]] = func; 5209 } 5210 }; 5211 5212 Method.prototype.buildCall = function() { 5213 var method = this; 5214 var send = function () { 5215 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5216 if (payload.callback) { 5217 return method.requestManager.sendAsync(payload, function (err, result) { 5218 payload.callback(err, method.formatOutput(result)); 5219 }); 5220 } 5221 return method.formatOutput(method.requestManager.send(payload)); 5222 }; 5223 send.request = this.request.bind(this); 5224 return send; 5225 }; 5226 5227 /** 5228 * Should be called to create pure JSONRPC request which can be used in batch request 5229 * 5230 * @method request 5231 * @param {...} params 5232 * @return {Object} jsonrpc request 5233 */ 5234 Method.prototype.request = function () { 5235 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5236 payload.format = this.formatOutput.bind(this); 5237 return payload; 5238 }; 5239 5240 module.exports = Method; 5241 5242 },{"../utils/utils":20,"./errors":26}],37:[function(require,module,exports){ 5243 /* 5244 This file is part of web3.js. 5245 5246 web3.js is free software: you can redistribute it and/or modify 5247 it under the terms of the GNU Lesser General Public License as published by 5248 the Free Software Foundation, either version 3 of the License, or 5249 (at your option) any later version. 5250 5251 web3.js is distributed in the hope that it will be useful, 5252 but WITHOUT ANY WARRANTY; without even the implied warranty of 5253 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5254 GNU Lesser General Public License for more details. 5255 5256 You should have received a copy of the GNU Lesser General Public License 5257 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5258 */ 5259 /** @file db.js 5260 * @authors: 5261 * Marek Kotewicz <marek@ethdev.com> 5262 * @date 2015 5263 */ 5264 5265 var Method = require('../method'); 5266 5267 var DB = function (web3) { 5268 this._requestManager = web3._requestManager; 5269 5270 var self = this; 5271 5272 methods().forEach(function(method) { 5273 method.attachToObject(self); 5274 method.setRequestManager(web3._requestManager); 5275 }); 5276 }; 5277 5278 var methods = function () { 5279 var putString = new Method({ 5280 name: 'putString', 5281 call: 'db_putString', 5282 params: 3 5283 }); 5284 5285 var getString = new Method({ 5286 name: 'getString', 5287 call: 'db_getString', 5288 params: 2 5289 }); 5290 5291 var putHex = new Method({ 5292 name: 'putHex', 5293 call: 'db_putHex', 5294 params: 3 5295 }); 5296 5297 var getHex = new Method({ 5298 name: 'getHex', 5299 call: 'db_getHex', 5300 params: 2 5301 }); 5302 5303 return [ 5304 putString, getString, putHex, getHex 5305 ]; 5306 }; 5307 5308 module.exports = DB; 5309 5310 },{"../method":36}],38:[function(require,module,exports){ 5311 /* 5312 This file is part of web3.js. 5313 5314 web3.js is free software: you can redistribute it and/or modify 5315 it under the terms of the GNU Lesser General Public License as published by 5316 the Free Software Foundation, either version 3 of the License, or 5317 (at your option) any later version. 5318 5319 web3.js is distributed in the hope that it will be useful, 5320 but WITHOUT ANY WARRANTY; without even the implied warranty of 5321 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5322 GNU Lesser General Public License for more details. 5323 5324 You should have received a copy of the GNU Lesser General Public License 5325 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5326 */ 5327 /** 5328 * @file eth.js 5329 * @author Marek Kotewicz <marek@ethdev.com> 5330 * @author Fabian Vogelsteller <fabian@ethdev.com> 5331 * @date 2015 5332 */ 5333 5334 "use strict"; 5335 5336 var formatters = require('../formatters'); 5337 var utils = require('../../utils/utils'); 5338 var Method = require('../method'); 5339 var Property = require('../property'); 5340 var c = require('../../utils/config'); 5341 var Contract = require('../contract'); 5342 var watches = require('./watches'); 5343 var Filter = require('../filter'); 5344 var IsSyncing = require('../syncing'); 5345 var namereg = require('../namereg'); 5346 var Iban = require('../iban'); 5347 var transfer = require('../transfer'); 5348 5349 var blockCall = function (args) { 5350 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0 && args[0].length === 66) ? "klay_getBlockByHash" : "klay_getBlockByNumber"; 5351 }; 5352 5353 var headerCall = function (args) { 5354 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0 && args[0].length === 66) ? "klay_getHeaderByHash" : "klay_getHeaderByNumber"; 5355 }; 5356 5357 var transactionFromBlockCall = function (args) { 5358 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0 && args[0].length === 66) ? 'klay_getTransactionByBlockHashAndIndex' : 'klay_getTransactionByBlockNumberAndIndex'; 5359 }; 5360 5361 var getBlockTransactionCountCall = function (args) { 5362 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0 && args[0].length === 66) ? 'klay_getBlockTransactionCountByHash' : 'klay_getBlockTransactionCountByNumber'; 5363 }; 5364 5365 function Klay(web3) { 5366 this._requestManager = web3._requestManager; 5367 5368 var self = this; 5369 5370 methods().forEach(function(method) { 5371 method.attachToObject(self); 5372 method.setRequestManager(self._requestManager); 5373 }); 5374 5375 properties().forEach(function(p) { 5376 p.attachToObject(self); 5377 p.setRequestManager(self._requestManager); 5378 }); 5379 5380 5381 this.iban = Iban; 5382 this.sendIBANTransaction = transfer.bind(null, this); 5383 } 5384 5385 Object.defineProperty(Klay.prototype, 'defaultBlock', { 5386 get: function () { 5387 return c.defaultBlock; 5388 }, 5389 set: function (val) { 5390 c.defaultBlock = val; 5391 return val; 5392 } 5393 }); 5394 5395 Object.defineProperty(Klay.prototype, 'defaultAccount', { 5396 get: function () { 5397 return c.defaultAccount; 5398 }, 5399 set: function (val) { 5400 c.defaultAccount = val; 5401 return val; 5402 } 5403 }); 5404 5405 var methods = function () { 5406 var getBalance = new Method({ 5407 name: 'getBalance', 5408 call: 'klay_getBalance', 5409 params: 2, 5410 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5411 outputFormatter: formatters.outputBigNumberFormatter 5412 }); 5413 5414 var getStorageAt = new Method({ 5415 name: 'getStorageAt', 5416 call: 'klay_getStorageAt', 5417 params: 3, 5418 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5419 }); 5420 5421 var getCode = new Method({ 5422 name: 'getCode', 5423 call: 'klay_getCode', 5424 params: 2, 5425 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5426 }); 5427 5428 var getBlock = new Method({ 5429 name: 'getBlock', 5430 call: blockCall, 5431 params: 2, 5432 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5433 outputFormatter: formatters.outputBlockFormatter 5434 }); 5435 5436 var getHeader = new Method({ 5437 name: 'getHeader', 5438 call: headerCall, 5439 params: 1, 5440 inputFormatter: [formatters.inputBlockNumberFormatter] 5441 }); 5442 5443 var getBlockTransactionCount = new Method({ 5444 name: 'getBlockTransactionCount', 5445 call: getBlockTransactionCountCall, 5446 params: 1, 5447 inputFormatter: [formatters.inputBlockNumberFormatter], 5448 outputFormatter: utils.toDecimal 5449 }); 5450 5451 var getTransaction = new Method({ 5452 name: 'getTransaction', 5453 call: 'klay_getTransactionByHash', 5454 params: 1, 5455 outputFormatter: formatters.outputTransactionFormatter 5456 }); 5457 5458 var getDecodedAnchoringTransactionByHash = new Method({ 5459 name: 'getDecodedAnchoringTransactionByHash', 5460 call: 'klay_getDecodedAnchoringTransactionByHash', 5461 params: 1 5462 }); 5463 5464 var getTransactionFromBlock = new Method({ 5465 name: 'getTransactionFromBlock', 5466 call: transactionFromBlockCall, 5467 params: 2, 5468 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5469 outputFormatter: formatters.outputTransactionFormatter 5470 }); 5471 5472 var getTransactionReceipt = new Method({ 5473 name: 'getTransactionReceipt', 5474 call: 'klay_getTransactionReceipt', 5475 params: 1, 5476 outputFormatter: formatters.outputTransactionReceiptFormatter 5477 }); 5478 5479 var getTransactionCount = new Method({ 5480 name: 'getTransactionCount', 5481 call: 'klay_getTransactionCount', 5482 params: 2, 5483 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5484 outputFormatter: utils.toDecimal 5485 }); 5486 5487 var sendRawTransaction = new Method({ 5488 name: 'sendRawTransaction', 5489 call: 'klay_sendRawTransaction', 5490 params: 1, 5491 inputFormatter: [null] 5492 }); 5493 5494 var sendTransaction = new Method({ 5495 name: 'sendTransaction', 5496 call: 'klay_sendTransaction', 5497 params: 1, 5498 inputFormatter: [formatters.inputTransactionFormatter] 5499 }); 5500 5501 var signTransaction = new Method({ 5502 name: 'signTransaction', 5503 call: 'klay_signTransaction', 5504 params: 1, 5505 inputFormatter: [formatters.inputTransactionFormatter] 5506 }); 5507 5508 var sign = new Method({ 5509 name: 'sign', 5510 call: 'klay_sign', 5511 params: 2, 5512 inputFormatter: [formatters.inputAddressFormatter, null] 5513 }); 5514 5515 var call = new Method({ 5516 name: 'call', 5517 call: 'klay_call', 5518 params: 2, 5519 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5520 }); 5521 5522 var estimateGas = new Method({ 5523 name: 'estimateGas', 5524 call: 'klay_estimateGas', 5525 params: 1, 5526 inputFormatter: [formatters.inputCallFormatter], 5527 outputFormatter: utils.toDecimal 5528 }); 5529 5530 return [ 5531 getBalance, 5532 getStorageAt, 5533 getCode, 5534 getBlock, 5535 getHeader, 5536 getBlockTransactionCount, 5537 getTransaction, 5538 getDecodedAnchoringTransactionByHash, 5539 getTransactionFromBlock, 5540 getTransactionReceipt, 5541 getTransactionCount, 5542 call, 5543 estimateGas, 5544 sendRawTransaction, 5545 signTransaction, 5546 sendTransaction, 5547 sign, 5548 ]; 5549 }; 5550 5551 5552 var properties = function () { 5553 return [ 5554 new Property({ 5555 name: 'syncing', 5556 getter: 'klay_syncing', 5557 outputFormatter: formatters.outputSyncingFormatter 5558 }), 5559 new Property({ 5560 name: 'accounts', 5561 getter: 'klay_accounts' 5562 }), 5563 new Property({ 5564 name: 'blockNumber', 5565 getter: 'klay_blockNumber', 5566 outputFormatter: utils.toDecimal 5567 }), 5568 new Property({ 5569 name: 'chainID', 5570 getter: 'klay_chainID', 5571 outputFormatter: formatters.outputBigNumberFormatter 5572 }), 5573 new Property({ 5574 name: 'chainId', 5575 getter: 'klay_chainId', 5576 outputFormatter: formatters.outputBigNumberFormatter 5577 }), 5578 new Property({ 5579 name: 'protocolVersion', 5580 getter: 'klay_protocolVersion' 5581 }) 5582 ]; 5583 }; 5584 5585 Klay.prototype.contract = function (abi) { 5586 var factory = new Contract(this, abi); 5587 return factory; 5588 }; 5589 5590 Klay.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5591 return new Filter(options, 'klay', this._requestManager, watches.klay(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5592 }; 5593 5594 Klay.prototype.namereg = function () { 5595 return this.contract(namereg.global.abi).at(namereg.global.address); 5596 }; 5597 5598 Klay.prototype.icapNamereg = function () { 5599 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5600 }; 5601 5602 Klay.prototype.isSyncing = function (callback) { 5603 return new IsSyncing(this._requestManager, callback); 5604 }; 5605 5606 module.exports = Klay; 5607 5608 },{"../../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}],87:[function(require,module,exports){ 5609 /* 5610 This file is part of web3.js. 5611 5612 web3.js is free software: you can redistribute it and/or modify 5613 it under the terms of the GNU Lesser General Public License as published by 5614 the Free Software Foundation, either version 3 of the License, or 5615 (at your option) any later version. 5616 5617 web3.js is distributed in the hope that it will be useful, 5618 but WITHOUT ANY WARRANTY; without even the implied warranty of 5619 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5620 GNU Lesser General Public License for more details. 5621 5622 You should have received a copy of the GNU Lesser General Public License 5623 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5624 */ 5625 /** 5626 * @file eth.js 5627 * @author Marek Kotewicz <marek@ethdev.com> 5628 * @author Fabian Vogelsteller <fabian@ethdev.com> 5629 * @date 2015 5630 */ 5631 5632 "use strict"; 5633 5634 var formatters = require('../formatters'); 5635 var utils = require('../../utils/utils'); 5636 var Method = require('../method'); 5637 var Property = require('../property'); 5638 var c = require('../../utils/config'); 5639 var Contract = require('../contract'); 5640 var watches = require('./watches'); 5641 var Filter = require('../filter'); 5642 var IsSyncing = require('../syncing'); 5643 var namereg = require('../namereg'); 5644 var Iban = require('../iban'); 5645 var transfer = require('../transfer'); 5646 5647 var blockCall = function (args) { 5648 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; 5649 }; 5650 5651 var transactionFromBlockCall = function (args) { 5652 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5653 }; 5654 5655 var uncleCall = function (args) { 5656 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5657 }; 5658 5659 var getBlockTransactionCountCall = function (args) { 5660 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5661 }; 5662 5663 var uncleCountCall = function (args) { 5664 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5665 }; 5666 5667 function Eth(web3) { 5668 this._requestManager = web3._requestManager; 5669 5670 var self = this; 5671 5672 methods().forEach(function(method) { 5673 method.attachToObject(self); 5674 method.setRequestManager(self._requestManager); 5675 }); 5676 5677 properties().forEach(function(p) { 5678 p.attachToObject(self); 5679 p.setRequestManager(self._requestManager); 5680 }); 5681 5682 5683 this.iban = Iban; 5684 this.sendIBANTransaction = transfer.bind(null, this); 5685 } 5686 5687 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5688 get: function () { 5689 return c.defaultBlock; 5690 }, 5691 set: function (val) { 5692 c.defaultBlock = val; 5693 return val; 5694 } 5695 }); 5696 5697 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5698 get: function () { 5699 return c.defaultAccount; 5700 }, 5701 set: function (val) { 5702 c.defaultAccount = val; 5703 return val; 5704 } 5705 }); 5706 5707 var methods = function () { 5708 var getBalance = new Method({ 5709 name: 'getBalance', 5710 call: 'eth_getBalance', 5711 params: 2, 5712 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5713 outputFormatter: formatters.outputBigNumberFormatter 5714 }); 5715 5716 var getStorageAt = new Method({ 5717 name: 'getStorageAt', 5718 call: 'eth_getStorageAt', 5719 params: 3, 5720 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5721 }); 5722 5723 var getCode = new Method({ 5724 name: 'getCode', 5725 call: 'eth_getCode', 5726 params: 2, 5727 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5728 }); 5729 5730 var getBlock = new Method({ 5731 name: 'getBlock', 5732 call: blockCall, 5733 params: 2, 5734 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5735 outputFormatter: formatters.outputBlockFormatter 5736 }); 5737 5738 var getUncle = new Method({ 5739 name: 'getUncle', 5740 call: uncleCall, 5741 params: 2, 5742 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5743 outputFormatter: formatters.outputBlockFormatter, 5744 5745 }); 5746 5747 var getBlockTransactionCount = new Method({ 5748 name: 'getBlockTransactionCount', 5749 call: getBlockTransactionCountCall, 5750 params: 1, 5751 inputFormatter: [formatters.inputBlockNumberFormatter], 5752 outputFormatter: utils.toDecimal 5753 }); 5754 5755 var getBlockUncleCount = new Method({ 5756 name: 'getBlockUncleCount', 5757 call: uncleCountCall, 5758 params: 1, 5759 inputFormatter: [formatters.inputBlockNumberFormatter], 5760 outputFormatter: utils.toDecimal 5761 }); 5762 5763 var getTransaction = new Method({ 5764 name: 'getTransaction', 5765 call: 'eth_getTransactionByHash', 5766 params: 1, 5767 outputFormatter: formatters.outputTransactionFormatter 5768 }); 5769 5770 var getTransactionFromBlock = new Method({ 5771 name: 'getTransactionFromBlock', 5772 call: transactionFromBlockCall, 5773 params: 2, 5774 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5775 outputFormatter: formatters.outputTransactionFormatter 5776 }); 5777 5778 var getTransactionReceipt = new Method({ 5779 name: 'getTransactionReceipt', 5780 call: 'eth_getTransactionReceipt', 5781 params: 1, 5782 outputFormatter: formatters.outputTransactionReceiptFormatter 5783 }); 5784 5785 var getTransactionCount = new Method({ 5786 name: 'getTransactionCount', 5787 call: 'eth_getTransactionCount', 5788 params: 2, 5789 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5790 outputFormatter: utils.toDecimal 5791 }); 5792 5793 var sendRawTransaction = new Method({ 5794 name: 'sendRawTransaction', 5795 call: 'eth_sendRawTransaction', 5796 params: 1, 5797 inputFormatter: [null] 5798 }); 5799 5800 var sendTransaction = new Method({ 5801 name: 'sendTransaction', 5802 call: 'eth_sendTransaction', 5803 params: 1, 5804 inputFormatter: [formatters.inputTransactionFormatter] 5805 }); 5806 5807 var signTransaction = new Method({ 5808 name: 'signTransaction', 5809 call: 'eth_signTransaction', 5810 params: 1, 5811 inputFormatter: [formatters.inputTransactionFormatter] 5812 }); 5813 5814 var sign = new Method({ 5815 name: 'sign', 5816 call: 'eth_sign', 5817 params: 2, 5818 inputFormatter: [formatters.inputAddressFormatter, null] 5819 }); 5820 5821 var call = new Method({ 5822 name: 'call', 5823 call: 'eth_call', 5824 params: 2, 5825 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5826 }); 5827 5828 var estimateGas = new Method({ 5829 name: 'estimateGas', 5830 call: 'eth_estimateGas', 5831 params: 1, 5832 inputFormatter: [formatters.inputCallFormatter], 5833 outputFormatter: utils.toDecimal 5834 }); 5835 5836 var submitWork = new Method({ 5837 name: 'submitWork', 5838 call: 'eth_submitWork', 5839 params: 3 5840 }); 5841 5842 var getWork = new Method({ 5843 name: 'getWork', 5844 call: 'eth_getWork', 5845 params: 0 5846 }); 5847 5848 return [ 5849 getBalance, 5850 getStorageAt, 5851 getCode, 5852 getBlock, 5853 getUncle, 5854 getBlockTransactionCount, 5855 getBlockUncleCount, 5856 getTransaction, 5857 getTransactionFromBlock, 5858 getTransactionReceipt, 5859 getTransactionCount, 5860 call, 5861 estimateGas, 5862 sendRawTransaction, 5863 signTransaction, 5864 sendTransaction, 5865 sign, 5866 submitWork, 5867 getWork 5868 ]; 5869 }; 5870 5871 5872 var properties = function () { 5873 return [ 5874 new Property({ 5875 name: 'coinbase', 5876 getter: 'eth_coinbase' 5877 }), 5878 new Property({ 5879 name: 'mining', 5880 getter: 'eth_mining' 5881 }), 5882 new Property({ 5883 name: 'hashrate', 5884 getter: 'eth_hashrate', 5885 outputFormatter: utils.toDecimal 5886 }), 5887 new Property({ 5888 name: 'syncing', 5889 getter: 'eth_syncing', 5890 outputFormatter: formatters.outputSyncingFormatter 5891 }), 5892 new Property({ 5893 name: 'gasPrice', 5894 getter: 'eth_gasPrice', 5895 outputFormatter: formatters.outputBigNumberFormatter 5896 }), 5897 new Property({ 5898 name: 'accounts', 5899 getter: 'eth_accounts' 5900 }), 5901 new Property({ 5902 name: 'blockNumber', 5903 getter: 'eth_blockNumber', 5904 outputFormatter: utils.toDecimal 5905 }), 5906 new Property({ 5907 name: 'protocolVersion', 5908 getter: 'eth_protocolVersion' 5909 }) 5910 ]; 5911 }; 5912 5913 Eth.prototype.contract = function (abi) { 5914 var factory = new Contract(this, abi); 5915 return factory; 5916 }; 5917 5918 Eth.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5919 return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5920 }; 5921 5922 Eth.prototype.namereg = function () { 5923 return this.contract(namereg.global.abi).at(namereg.global.address); 5924 }; 5925 5926 Eth.prototype.icapNamereg = function () { 5927 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5928 }; 5929 5930 Eth.prototype.isSyncing = function (callback) { 5931 return new IsSyncing(this._requestManager, callback); 5932 }; 5933 5934 module.exports = Eth; 5935 5936 },{"../../utils/config":18,"../../utils/utils":20,"../contract":25,"../filter":29,"../formatters":30,"../iban":33,"../method":36,"../namereg":44,"../property":45,"../syncing":48,"../transfer":49,"./watches":43}],39:[function(require,module,exports){ 5937 /* 5938 This file is part of web3.js. 5939 5940 web3.js is free software: you can redistribute it and/or modify 5941 it under the terms of the GNU Lesser General Public License as published by 5942 the Free Software Foundation, either version 3 of the License, or 5943 (at your option) any later version. 5944 5945 web3.js is distributed in the hope that it will be useful, 5946 but WITHOUT ANY WARRANTY; without even the implied warranty of 5947 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5948 GNU Lesser General Public License for more details. 5949 5950 You should have received a copy of the GNU Lesser General Public License 5951 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5952 */ 5953 /** @file eth.js 5954 * @authors: 5955 * Marek Kotewicz <marek@ethdev.com> 5956 * @date 2015 5957 */ 5958 5959 var utils = require('../../utils/utils'); 5960 var Property = require('../property'); 5961 5962 var Net = function (web3) { 5963 this._requestManager = web3._requestManager; 5964 5965 var self = this; 5966 5967 properties().forEach(function(p) { 5968 p.attachToObject(self); 5969 p.setRequestManager(web3._requestManager); 5970 }); 5971 }; 5972 5973 /// @returns an array of objects describing web3.eth api properties 5974 var properties = function () { 5975 return [ 5976 new Property({ 5977 name: 'listening', 5978 getter: 'net_listening' 5979 }), 5980 new Property({ 5981 name: 'peerCount', 5982 getter: 'net_peerCount', 5983 outputFormatter: utils.toDecimal 5984 }) 5985 ]; 5986 }; 5987 5988 module.exports = Net; 5989 5990 },{"../../utils/utils":20,"../property":45}],40:[function(require,module,exports){ 5991 /* 5992 This file is part of web3.js. 5993 5994 web3.js is free software: you can redistribute it and/or modify 5995 it under the terms of the GNU Lesser General Public License as published by 5996 the Free Software Foundation, either version 3 of the License, or 5997 (at your option) any later version. 5998 5999 web3.js is distributed in the hope that it will be useful, 6000 but WITHOUT ANY WARRANTY; without even the implied warranty of 6001 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6002 GNU Lesser General Public License for more details. 6003 6004 You should have received a copy of the GNU Lesser General Public License 6005 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6006 */ 6007 /** 6008 * @file eth.js 6009 * @author Marek Kotewicz <marek@ethdev.com> 6010 * @author Fabian Vogelsteller <fabian@ethdev.com> 6011 * @date 2015 6012 */ 6013 6014 "use strict"; 6015 6016 var Method = require('../method'); 6017 var Property = require('../property'); 6018 var formatters = require('../formatters'); 6019 6020 function Personal(web3) { 6021 this._requestManager = web3._requestManager; 6022 6023 var self = this; 6024 6025 methods().forEach(function(method) { 6026 method.attachToObject(self); 6027 method.setRequestManager(self._requestManager); 6028 }); 6029 6030 properties().forEach(function(p) { 6031 p.attachToObject(self); 6032 p.setRequestManager(self._requestManager); 6033 }); 6034 } 6035 6036 var methods = function () { 6037 var newAccount = new Method({ 6038 name: 'newAccount', 6039 call: 'personal_newAccount', 6040 params: 1, 6041 inputFormatter: [null] 6042 }); 6043 6044 var importRawKey = new Method({ 6045 name: 'importRawKey', 6046 call: 'personal_importRawKey', 6047 params: 2 6048 }); 6049 6050 var sign = new Method({ 6051 name: 'sign', 6052 call: 'personal_sign', 6053 params: 3, 6054 inputFormatter: [null, formatters.inputAddressFormatter, null] 6055 }); 6056 6057 var ecRecover = new Method({ 6058 name: 'ecRecover', 6059 call: 'personal_ecRecover', 6060 params: 2 6061 }); 6062 6063 var unlockAccount = new Method({ 6064 name: 'unlockAccount', 6065 call: 'personal_unlockAccount', 6066 params: 3, 6067 inputFormatter: [formatters.inputAddressFormatter, null, null] 6068 }); 6069 6070 var sendTransaction = new Method({ 6071 name: 'sendTransaction', 6072 call: 'personal_sendTransaction', 6073 params: 2, 6074 inputFormatter: [formatters.inputTransactionFormatter, null] 6075 }); 6076 6077 var lockAccount = new Method({ 6078 name: 'lockAccount', 6079 call: 'personal_lockAccount', 6080 params: 1, 6081 inputFormatter: [formatters.inputAddressFormatter] 6082 }); 6083 6084 return [ 6085 newAccount, 6086 importRawKey, 6087 unlockAccount, 6088 ecRecover, 6089 sign, 6090 sendTransaction, 6091 lockAccount 6092 ]; 6093 }; 6094 6095 var properties = function () { 6096 return [ 6097 new Property({ 6098 name: 'listAccounts', 6099 getter: 'personal_listAccounts' 6100 }) 6101 ]; 6102 }; 6103 6104 6105 module.exports = Personal; 6106 6107 },{"../formatters":30,"../method":36,"../property":45}],41:[function(require,module,exports){ 6108 /* 6109 This file is part of web3.js. 6110 6111 web3.js is free software: you can redistribute it and/or modify 6112 it under the terms of the GNU Lesser General Public License as published by 6113 the Free Software Foundation, either version 3 of the License, or 6114 (at your option) any later version. 6115 6116 web3.js is distributed in the hope that it will be useful, 6117 but WITHOUT ANY WARRANTY; without even the implied warranty of 6118 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6119 GNU Lesser General Public License for more details. 6120 6121 You should have received a copy of the GNU Lesser General Public License 6122 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6123 */ 6124 /** @file shh.js 6125 * @authors: 6126 * Fabian Vogelsteller <fabian@ethereum.org> 6127 * Marek Kotewicz <marek@ethcore.io> 6128 * @date 2017 6129 */ 6130 6131 var Method = require('../method'); 6132 var Filter = require('../filter'); 6133 var watches = require('./watches'); 6134 6135 var Shh = function (web3) { 6136 this._requestManager = web3._requestManager; 6137 6138 var self = this; 6139 6140 methods().forEach(function(method) { 6141 method.attachToObject(self); 6142 method.setRequestManager(self._requestManager); 6143 }); 6144 }; 6145 6146 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 6147 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 6148 }; 6149 6150 var methods = function () { 6151 6152 return [ 6153 new Method({ 6154 name: 'version', 6155 call: 'shh_version', 6156 params: 0 6157 }), 6158 new Method({ 6159 name: 'info', 6160 call: 'shh_info', 6161 params: 0 6162 }), 6163 new Method({ 6164 name: 'setMaxMessageSize', 6165 call: 'shh_setMaxMessageSize', 6166 params: 1 6167 }), 6168 new Method({ 6169 name: 'setMinPoW', 6170 call: 'shh_setMinPoW', 6171 params: 1 6172 }), 6173 new Method({ 6174 name: 'markTrustedPeer', 6175 call: 'shh_markTrustedPeer', 6176 params: 1 6177 }), 6178 new Method({ 6179 name: 'newKeyPair', 6180 call: 'shh_newKeyPair', 6181 params: 0 6182 }), 6183 new Method({ 6184 name: 'addPrivateKey', 6185 call: 'shh_addPrivateKey', 6186 params: 1 6187 }), 6188 new Method({ 6189 name: 'deleteKeyPair', 6190 call: 'shh_deleteKeyPair', 6191 params: 1 6192 }), 6193 new Method({ 6194 name: 'hasKeyPair', 6195 call: 'shh_hasKeyPair', 6196 params: 1 6197 }), 6198 new Method({ 6199 name: 'getPublicKey', 6200 call: 'shh_getPublicKey', 6201 params: 1 6202 }), 6203 new Method({ 6204 name: 'getPrivateKey', 6205 call: 'shh_getPrivateKey', 6206 params: 1 6207 }), 6208 new Method({ 6209 name: 'newSymKey', 6210 call: 'shh_newSymKey', 6211 params: 0 6212 }), 6213 new Method({ 6214 name: 'addSymKey', 6215 call: 'shh_addSymKey', 6216 params: 1 6217 }), 6218 new Method({ 6219 name: 'generateSymKeyFromPassword', 6220 call: 'shh_generateSymKeyFromPassword', 6221 params: 1 6222 }), 6223 new Method({ 6224 name: 'hasSymKey', 6225 call: 'shh_hasSymKey', 6226 params: 1 6227 }), 6228 new Method({ 6229 name: 'getSymKey', 6230 call: 'shh_getSymKey', 6231 params: 1 6232 }), 6233 new Method({ 6234 name: 'deleteSymKey', 6235 call: 'shh_deleteSymKey', 6236 params: 1 6237 }), 6238 6239 // subscribe and unsubscribe missing 6240 6241 new Method({ 6242 name: 'post', 6243 call: 'shh_post', 6244 params: 1, 6245 inputFormatter: [null] 6246 }) 6247 ]; 6248 }; 6249 6250 module.exports = Shh; 6251 6252 6253 },{"../filter":29,"../method":36,"./watches":43}],42:[function(require,module,exports){ 6254 /* 6255 This file is part of web3.js. 6256 6257 web3.js is free software: you can redistribute it and/or modify 6258 it under the terms of the GNU Lesser General Public License as published by 6259 the Free Software Foundation, either version 3 of the License, or 6260 (at your option) any later version. 6261 6262 web3.js is distributed in the hope that it will be useful, 6263 but WITHOUT ANY WARRANTY; without even the implied warranty of 6264 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6265 GNU Lesser General Public License for more details. 6266 6267 You should have received a copy of the GNU Lesser General Public License 6268 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6269 */ 6270 /** 6271 * @file bzz.js 6272 * @author Alex Beregszaszi <alex@rtfs.hu> 6273 * @date 2016 6274 * 6275 * Reference: https://github.com/ethereum/go-ethereum/blob/swarm/internal/web3ext/web3ext.go#L33 6276 */ 6277 6278 "use strict"; 6279 6280 var Method = require('../method'); 6281 var Property = require('../property'); 6282 6283 function Swarm(web3) { 6284 this._requestManager = web3._requestManager; 6285 6286 var self = this; 6287 6288 methods().forEach(function(method) { 6289 method.attachToObject(self); 6290 method.setRequestManager(self._requestManager); 6291 }); 6292 6293 properties().forEach(function(p) { 6294 p.attachToObject(self); 6295 p.setRequestManager(self._requestManager); 6296 }); 6297 } 6298 6299 var methods = function () { 6300 var blockNetworkRead = new Method({ 6301 name: 'blockNetworkRead', 6302 call: 'bzz_blockNetworkRead', 6303 params: 1, 6304 inputFormatter: [null] 6305 }); 6306 6307 var syncEnabled = new Method({ 6308 name: 'syncEnabled', 6309 call: 'bzz_syncEnabled', 6310 params: 1, 6311 inputFormatter: [null] 6312 }); 6313 6314 var swapEnabled = new Method({ 6315 name: 'swapEnabled', 6316 call: 'bzz_swapEnabled', 6317 params: 1, 6318 inputFormatter: [null] 6319 }); 6320 6321 var download = new Method({ 6322 name: 'download', 6323 call: 'bzz_download', 6324 params: 2, 6325 inputFormatter: [null, null] 6326 }); 6327 6328 var upload = new Method({ 6329 name: 'upload', 6330 call: 'bzz_upload', 6331 params: 2, 6332 inputFormatter: [null, null] 6333 }); 6334 6335 var retrieve = new Method({ 6336 name: 'retrieve', 6337 call: 'bzz_retrieve', 6338 params: 1, 6339 inputFormatter: [null] 6340 }); 6341 6342 var store = new Method({ 6343 name: 'store', 6344 call: 'bzz_store', 6345 params: 2, 6346 inputFormatter: [null, null] 6347 }); 6348 6349 var get = new Method({ 6350 name: 'get', 6351 call: 'bzz_get', 6352 params: 1, 6353 inputFormatter: [null] 6354 }); 6355 6356 var put = new Method({ 6357 name: 'put', 6358 call: 'bzz_put', 6359 params: 2, 6360 inputFormatter: [null, null] 6361 }); 6362 6363 var modify = new Method({ 6364 name: 'modify', 6365 call: 'bzz_modify', 6366 params: 4, 6367 inputFormatter: [null, null, null, null] 6368 }); 6369 6370 return [ 6371 blockNetworkRead, 6372 syncEnabled, 6373 swapEnabled, 6374 download, 6375 upload, 6376 retrieve, 6377 store, 6378 get, 6379 put, 6380 modify 6381 ]; 6382 }; 6383 6384 var properties = function () { 6385 return [ 6386 new Property({ 6387 name: 'hive', 6388 getter: 'bzz_hive' 6389 }), 6390 new Property({ 6391 name: 'info', 6392 getter: 'bzz_info' 6393 }) 6394 ]; 6395 }; 6396 6397 6398 module.exports = Swarm; 6399 6400 },{"../method":36,"../property":45}],43:[function(require,module,exports){ 6401 /* 6402 This file is part of web3.js. 6403 6404 web3.js is free software: you can redistribute it and/or modify 6405 it under the terms of the GNU Lesser General Public License as published by 6406 the Free Software Foundation, either version 3 of the License, or 6407 (at your option) any later version. 6408 6409 web3.js is distributed in the hope that it will be useful, 6410 but WITHOUT ANY WARRANTY; without even the implied warranty of 6411 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6412 GNU Lesser General Public License for more details. 6413 6414 You should have received a copy of the GNU Lesser General Public License 6415 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6416 */ 6417 /** @file watches.js 6418 * @authors: 6419 * Marek Kotewicz <marek@ethdev.com> 6420 * @date 2015 6421 */ 6422 6423 var Method = require('../method'); 6424 6425 /// @returns an array of objects describing web3.eth.filter api methods 6426 var klay = function () { 6427 var newFilterCall = function (args) { 6428 var type = args[0]; 6429 6430 switch(type) { 6431 case 'latest': 6432 args.shift(); 6433 this.params = 0; 6434 return 'klay_newBlockFilter'; 6435 case 'pending': 6436 args.shift(); 6437 this.params = 0; 6438 return 'klay_newPendingTransactionFilter'; 6439 default: 6440 return 'klay_newFilter'; 6441 } 6442 }; 6443 6444 var newFilter = new Method({ 6445 name: 'newFilter', 6446 call: newFilterCall, 6447 params: 1 6448 }); 6449 6450 var uninstallFilter = new Method({ 6451 name: 'uninstallFilter', 6452 call: 'klay_uninstallFilter', 6453 params: 1 6454 }); 6455 6456 var getLogs = new Method({ 6457 name: 'getLogs', 6458 call: 'klay_getFilterLogs', 6459 params: 1 6460 }); 6461 6462 var poll = new Method({ 6463 name: 'poll', 6464 call: 'klay_getFilterChanges', 6465 params: 1 6466 }); 6467 6468 return [ 6469 newFilter, 6470 uninstallFilter, 6471 getLogs, 6472 poll 6473 ]; 6474 }; 6475 6476 6477 /// @returns an array of objects describing web3.eth.filter api methods 6478 var eth = function () { 6479 var newFilterCall = function (args) { 6480 var type = args[0]; 6481 6482 switch(type) { 6483 case 'latest': 6484 args.shift(); 6485 this.params = 0; 6486 return 'eth_newBlockFilter'; 6487 case 'pending': 6488 args.shift(); 6489 this.params = 0; 6490 return 'eth_newPendingTransactionFilter'; 6491 default: 6492 return 'eth_newFilter'; 6493 } 6494 }; 6495 6496 var newFilter = new Method({ 6497 name: 'newFilter', 6498 call: newFilterCall, 6499 params: 1 6500 }); 6501 6502 var uninstallFilter = new Method({ 6503 name: 'uninstallFilter', 6504 call: 'eth_uninstallFilter', 6505 params: 1 6506 }); 6507 6508 var getLogs = new Method({ 6509 name: 'getLogs', 6510 call: 'eth_getFilterLogs', 6511 params: 1 6512 }); 6513 6514 var poll = new Method({ 6515 name: 'poll', 6516 call: 'eth_getFilterChanges', 6517 params: 1 6518 }); 6519 6520 return [ 6521 newFilter, 6522 uninstallFilter, 6523 getLogs, 6524 poll 6525 ]; 6526 }; 6527 6528 /// @returns an array of objects describing web3.shh.watch api methods 6529 var shh = function () { 6530 6531 return [ 6532 new Method({ 6533 name: 'newFilter', 6534 call: 'shh_newMessageFilter', 6535 params: 1 6536 }), 6537 new Method({ 6538 name: 'uninstallFilter', 6539 call: 'shh_deleteMessageFilter', 6540 params: 1 6541 }), 6542 new Method({ 6543 name: 'getLogs', 6544 call: 'shh_getFilterMessages', 6545 params: 1 6546 }), 6547 new Method({ 6548 name: 'poll', 6549 call: 'shh_getFilterMessages', 6550 params: 1 6551 }) 6552 ]; 6553 }; 6554 6555 module.exports = { 6556 klay: klay, 6557 eth: eth, 6558 shh: shh 6559 }; 6560 6561 6562 },{"../method":36}],44:[function(require,module,exports){ 6563 /* 6564 This file is part of web3.js. 6565 6566 web3.js is free software: you can redistribute it and/or modify 6567 it under the terms of the GNU Lesser General Public License as published by 6568 the Free Software Foundation, either version 3 of the License, or 6569 (at your option) any later version. 6570 6571 web3.js is distributed in the hope that it will be useful, 6572 but WITHOUT ANY WARRANTY; without even the implied warranty of 6573 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6574 GNU Lesser General Public License for more details. 6575 6576 You should have received a copy of the GNU Lesser General Public License 6577 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6578 */ 6579 /** 6580 * @file namereg.js 6581 * @author Marek Kotewicz <marek@ethdev.com> 6582 * @date 2015 6583 */ 6584 6585 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6586 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6587 6588 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6589 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6590 6591 module.exports = { 6592 global: { 6593 abi: globalRegistrarAbi, 6594 address: globalNameregAddress 6595 }, 6596 icap: { 6597 abi: icapRegistrarAbi, 6598 address: icapNameregAddress 6599 } 6600 }; 6601 6602 6603 },{"../contracts/GlobalRegistrar.json":1,"../contracts/ICAPRegistrar.json":2}],45:[function(require,module,exports){ 6604 /* 6605 This file is part of web3.js. 6606 6607 web3.js is free software: you can redistribute it and/or modify 6608 it under the terms of the GNU Lesser General Public License as published by 6609 the Free Software Foundation, either version 3 of the License, or 6610 (at your option) any later version. 6611 6612 web3.js is distributed in the hope that it will be useful, 6613 but WITHOUT ANY WARRANTY; without even the implied warranty of 6614 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6615 GNU Lesser General Public License for more details. 6616 6617 You should have received a copy of the GNU Lesser General Public License 6618 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6619 */ 6620 /** 6621 * @file property.js 6622 * @author Fabian Vogelsteller <fabian@frozeman.de> 6623 * @author Marek Kotewicz <marek@ethdev.com> 6624 * @date 2015 6625 */ 6626 6627 var utils = require('../utils/utils'); 6628 6629 var Property = function (options) { 6630 this.name = options.name; 6631 this.getter = options.getter; 6632 this.setter = options.setter; 6633 this.outputFormatter = options.outputFormatter; 6634 this.inputFormatter = options.inputFormatter; 6635 this.requestManager = null; 6636 }; 6637 6638 Property.prototype.setRequestManager = function (rm) { 6639 this.requestManager = rm; 6640 }; 6641 6642 /** 6643 * Should be called to format input args of method 6644 * 6645 * @method formatInput 6646 * @param {Array} 6647 * @return {Array} 6648 */ 6649 Property.prototype.formatInput = function (arg) { 6650 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6651 }; 6652 6653 /** 6654 * Should be called to format output(result) of method 6655 * 6656 * @method formatOutput 6657 * @param {Object} 6658 * @return {Object} 6659 */ 6660 Property.prototype.formatOutput = function (result) { 6661 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6662 }; 6663 6664 /** 6665 * Should be used to extract callback from array of arguments. Modifies input param 6666 * 6667 * @method extractCallback 6668 * @param {Array} arguments 6669 * @return {Function|Null} callback, if exists 6670 */ 6671 Property.prototype.extractCallback = function (args) { 6672 if (utils.isFunction(args[args.length - 1])) { 6673 return args.pop(); // modify the args array! 6674 } 6675 }; 6676 6677 6678 /** 6679 * Should attach function to method 6680 * 6681 * @method attachToObject 6682 * @param {Object} 6683 * @param {Function} 6684 */ 6685 Property.prototype.attachToObject = function (obj) { 6686 var proto = { 6687 get: this.buildGet(), 6688 enumerable: true 6689 }; 6690 6691 var names = this.name.split('.'); 6692 var name = names[0]; 6693 if (names.length > 1) { 6694 obj[names[0]] = obj[names[0]] || {}; 6695 obj = obj[names[0]]; 6696 name = names[1]; 6697 } 6698 6699 Object.defineProperty(obj, name, proto); 6700 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6701 }; 6702 6703 var asyncGetterName = function (name) { 6704 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6705 }; 6706 6707 Property.prototype.buildGet = function () { 6708 var property = this; 6709 return function get() { 6710 return property.formatOutput(property.requestManager.send({ 6711 method: property.getter 6712 })); 6713 }; 6714 }; 6715 6716 Property.prototype.buildAsyncGet = function () { 6717 var property = this; 6718 var get = function (callback) { 6719 property.requestManager.sendAsync({ 6720 method: property.getter 6721 }, function (err, result) { 6722 callback(err, property.formatOutput(result)); 6723 }); 6724 }; 6725 get.request = this.request.bind(this); 6726 return get; 6727 }; 6728 6729 /** 6730 * Should be called to create pure JSONRPC request which can be used in batch request 6731 * 6732 * @method request 6733 * @param {...} params 6734 * @return {Object} jsonrpc request 6735 */ 6736 Property.prototype.request = function () { 6737 var payload = { 6738 method: this.getter, 6739 params: [], 6740 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6741 }; 6742 payload.format = this.formatOutput.bind(this); 6743 return payload; 6744 }; 6745 6746 module.exports = Property; 6747 6748 6749 },{"../utils/utils":20}],46:[function(require,module,exports){ 6750 /* 6751 This file is part of web3.js. 6752 6753 web3.js is free software: you can redistribute it and/or modify 6754 it under the terms of the GNU Lesser General Public License as published by 6755 the Free Software Foundation, either version 3 of the License, or 6756 (at your option) any later version. 6757 6758 web3.js is distributed in the hope that it will be useful, 6759 but WITHOUT ANY WARRANTY; without even the implied warranty of 6760 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6761 GNU Lesser General Public License for more details. 6762 6763 You should have received a copy of the GNU Lesser General Public License 6764 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6765 */ 6766 /** 6767 * @file requestmanager.js 6768 * @author Jeffrey Wilcke <jeff@ethdev.com> 6769 * @author Marek Kotewicz <marek@ethdev.com> 6770 * @author Marian Oancea <marian@ethdev.com> 6771 * @author Fabian Vogelsteller <fabian@ethdev.com> 6772 * @author Gav Wood <g@ethdev.com> 6773 * @date 2014 6774 */ 6775 6776 var Jsonrpc = require('./jsonrpc'); 6777 var utils = require('../utils/utils'); 6778 var c = require('../utils/config'); 6779 var errors = require('./errors'); 6780 6781 /** 6782 * It's responsible for passing messages to providers 6783 * It's also responsible for polling the ethereum node for incoming messages 6784 * Default poll timeout is 1 second 6785 * Singleton 6786 */ 6787 var RequestManager = function (provider) { 6788 this.provider = provider; 6789 this.polls = {}; 6790 this.timeout = null; 6791 }; 6792 6793 /** 6794 * Should be used to synchronously send request 6795 * 6796 * @method send 6797 * @param {Object} data 6798 * @return {Object} 6799 */ 6800 RequestManager.prototype.send = function (data) { 6801 if (!this.provider) { 6802 console.error(errors.InvalidProvider()); 6803 return null; 6804 } 6805 6806 var payload = Jsonrpc.toPayload(data.method, data.params); 6807 var result = this.provider.send(payload); 6808 6809 if (!Jsonrpc.isValidResponse(result)) { 6810 throw errors.InvalidResponse(result); 6811 } 6812 6813 return result.result; 6814 }; 6815 6816 /** 6817 * Should be used to asynchronously send request 6818 * 6819 * @method sendAsync 6820 * @param {Object} data 6821 * @param {Function} callback 6822 */ 6823 RequestManager.prototype.sendAsync = function (data, callback) { 6824 if (!this.provider) { 6825 return callback(errors.InvalidProvider()); 6826 } 6827 6828 var payload = Jsonrpc.toPayload(data.method, data.params); 6829 this.provider.sendAsync(payload, function (err, result) { 6830 if (err) { 6831 return callback(err); 6832 } 6833 6834 if (!Jsonrpc.isValidResponse(result)) { 6835 return callback(errors.InvalidResponse(result)); 6836 } 6837 6838 callback(null, result.result); 6839 }); 6840 }; 6841 6842 /** 6843 * Should be called to asynchronously send batch request 6844 * 6845 * @method sendBatch 6846 * @param {Array} batch data 6847 * @param {Function} callback 6848 */ 6849 RequestManager.prototype.sendBatch = function (data, callback) { 6850 if (!this.provider) { 6851 return callback(errors.InvalidProvider()); 6852 } 6853 6854 var payload = Jsonrpc.toBatchPayload(data); 6855 6856 this.provider.sendAsync(payload, function (err, results) { 6857 if (err) { 6858 return callback(err); 6859 } 6860 6861 if (!utils.isArray(results)) { 6862 return callback(errors.InvalidResponse(results)); 6863 } 6864 6865 callback(err, results); 6866 }); 6867 }; 6868 6869 /** 6870 * Should be used to set provider of request manager 6871 * 6872 * @method setProvider 6873 * @param {Object} 6874 */ 6875 RequestManager.prototype.setProvider = function (p) { 6876 this.provider = p; 6877 }; 6878 6879 /** 6880 * Should be used to start polling 6881 * 6882 * @method startPolling 6883 * @param {Object} data 6884 * @param {Number} pollId 6885 * @param {Function} callback 6886 * @param {Function} uninstall 6887 * 6888 * @todo cleanup number of params 6889 */ 6890 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6891 this.polls[pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; 6892 6893 6894 // start polling 6895 if (!this.timeout) { 6896 this.poll(); 6897 } 6898 }; 6899 6900 /** 6901 * Should be used to stop polling for filter with given id 6902 * 6903 * @method stopPolling 6904 * @param {Number} pollId 6905 */ 6906 RequestManager.prototype.stopPolling = function (pollId) { 6907 delete this.polls[pollId]; 6908 6909 // stop polling 6910 if(Object.keys(this.polls).length === 0 && this.timeout) { 6911 clearTimeout(this.timeout); 6912 this.timeout = null; 6913 } 6914 }; 6915 6916 /** 6917 * Should be called to reset the polling mechanism of the request manager 6918 * 6919 * @method reset 6920 */ 6921 RequestManager.prototype.reset = function (keepIsSyncing) { 6922 /*jshint maxcomplexity:5 */ 6923 6924 for (var key in this.polls) { 6925 // remove all polls, except sync polls, 6926 // they need to be removed manually by calling syncing.stopWatching() 6927 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6928 this.polls[key].uninstall(); 6929 delete this.polls[key]; 6930 } 6931 } 6932 6933 // stop polling 6934 if(Object.keys(this.polls).length === 0 && this.timeout) { 6935 clearTimeout(this.timeout); 6936 this.timeout = null; 6937 } 6938 }; 6939 6940 /** 6941 * Should be called to poll for changes on filter with given id 6942 * 6943 * @method poll 6944 */ 6945 RequestManager.prototype.poll = function () { 6946 /*jshint maxcomplexity: 6 */ 6947 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6948 6949 if (Object.keys(this.polls).length === 0) { 6950 return; 6951 } 6952 6953 if (!this.provider) { 6954 console.error(errors.InvalidProvider()); 6955 return; 6956 } 6957 6958 var pollsData = []; 6959 var pollsIds = []; 6960 for (var key in this.polls) { 6961 pollsData.push(this.polls[key].data); 6962 pollsIds.push(key); 6963 } 6964 6965 if (pollsData.length === 0) { 6966 return; 6967 } 6968 6969 var payload = Jsonrpc.toBatchPayload(pollsData); 6970 6971 // map the request id to they poll id 6972 var pollsIdMap = {}; 6973 payload.forEach(function(load, index){ 6974 pollsIdMap[load.id] = pollsIds[index]; 6975 }); 6976 6977 6978 var self = this; 6979 this.provider.sendAsync(payload, function (error, results) { 6980 6981 6982 // TODO: console log? 6983 if (error) { 6984 return; 6985 } 6986 6987 if (!utils.isArray(results)) { 6988 throw errors.InvalidResponse(results); 6989 } 6990 results.map(function (result) { 6991 var id = pollsIdMap[result.id]; 6992 6993 // make sure the filter is still installed after arrival of the request 6994 if (self.polls[id]) { 6995 result.callback = self.polls[id].callback; 6996 return result; 6997 } else 6998 return false; 6999 }).filter(function (result) { 7000 return !!result; 7001 }).filter(function (result) { 7002 var valid = Jsonrpc.isValidResponse(result); 7003 if (!valid) { 7004 result.callback(errors.InvalidResponse(result)); 7005 } 7006 return valid; 7007 }).forEach(function (result) { 7008 result.callback(null, result.result); 7009 }); 7010 }); 7011 }; 7012 7013 module.exports = RequestManager; 7014 7015 7016 },{"../utils/config":18,"../utils/utils":20,"./errors":26,"./jsonrpc":35}],47:[function(require,module,exports){ 7017 7018 7019 var Settings = function () { 7020 this.defaultBlock = 'latest'; 7021 this.defaultAccount = undefined; 7022 }; 7023 7024 module.exports = Settings; 7025 7026 7027 },{}],48:[function(require,module,exports){ 7028 /* 7029 This file is part of web3.js. 7030 7031 web3.js is free software: you can redistribute it and/or modify 7032 it under the terms of the GNU Lesser General Public License as published by 7033 the Free Software Foundation, either version 3 of the License, or 7034 (at your option) any later version. 7035 7036 web3.js is distributed in the hope that it will be useful, 7037 but WITHOUT ANY WARRANTY; without even the implied warranty of 7038 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7039 GNU Lesser General Public License for more details. 7040 7041 You should have received a copy of the GNU Lesser General Public License 7042 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7043 */ 7044 /** @file syncing.js 7045 * @authors: 7046 * Fabian Vogelsteller <fabian@ethdev.com> 7047 * @date 2015 7048 */ 7049 7050 var formatters = require('./formatters'); 7051 var utils = require('../utils/utils'); 7052 7053 var count = 1; 7054 7055 /** 7056 Adds the callback and sets up the methods, to iterate over the results. 7057 7058 @method pollSyncing 7059 @param {Object} self 7060 */ 7061 var pollSyncing = function(self) { 7062 7063 var onMessage = function (error, sync) { 7064 if (error) { 7065 return self.callbacks.forEach(function (callback) { 7066 callback(error); 7067 }); 7068 } 7069 7070 if(utils.isObject(sync) && sync.startingBlock) 7071 sync = formatters.outputSyncingFormatter(sync); 7072 7073 self.callbacks.forEach(function (callback) { 7074 if (self.lastSyncState !== sync) { 7075 7076 // call the callback with true first so the app can stop anything, before receiving the sync data 7077 if(!self.lastSyncState && utils.isObject(sync)) 7078 callback(null, true); 7079 7080 // call on the next CPU cycle, so the actions of the sync stop can be processes first 7081 setTimeout(function() { 7082 callback(null, sync); 7083 }, 0); 7084 7085 self.lastSyncState = sync; 7086 } 7087 }); 7088 }; 7089 7090 self.requestManager.startPolling({ 7091 method: 'klay_syncing', 7092 params: [], 7093 }, self.pollId, onMessage, self.stopWatching.bind(self)); 7094 7095 }; 7096 7097 var IsSyncing = function (requestManager, callback) { 7098 this.requestManager = requestManager; 7099 this.pollId = 'syncPoll_'+ count++; 7100 this.callbacks = []; 7101 this.addCallback(callback); 7102 this.lastSyncState = false; 7103 pollSyncing(this); 7104 7105 return this; 7106 }; 7107 7108 IsSyncing.prototype.addCallback = function (callback) { 7109 if(callback) 7110 this.callbacks.push(callback); 7111 return this; 7112 }; 7113 7114 IsSyncing.prototype.stopWatching = function () { 7115 this.requestManager.stopPolling(this.pollId); 7116 this.callbacks = []; 7117 }; 7118 7119 module.exports = IsSyncing; 7120 7121 7122 },{"../utils/utils":20,"./formatters":30}],49:[function(require,module,exports){ 7123 /* 7124 This file is part of web3.js. 7125 7126 web3.js is free software: you can redistribute it and/or modify 7127 it under the terms of the GNU Lesser General Public License as published by 7128 the Free Software Foundation, either version 3 of the License, or 7129 (at your option) any later version. 7130 7131 web3.js is distributed in the hope that it will be useful, 7132 but WITHOUT ANY WARRANTY; without even the implied warranty of 7133 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 7134 GNU Lesser General Public License for more details. 7135 7136 You should have received a copy of the GNU Lesser General Public License 7137 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 7138 */ 7139 /** 7140 * @file transfer.js 7141 * @author Marek Kotewicz <marek@ethdev.com> 7142 * @date 2015 7143 */ 7144 7145 var Iban = require('./iban'); 7146 var exchangeAbi = require('../contracts/SmartExchange.json'); 7147 7148 /** 7149 * Should be used to make Iban transfer 7150 * 7151 * @method transfer 7152 * @param {String} from 7153 * @param {String} to iban 7154 * @param {Value} value to be tranfered 7155 * @param {Function} callback, callback 7156 */ 7157 var transfer = function (klay, from, to, value, callback) { 7158 var iban = new Iban(to); 7159 if (!iban.isValid()) { 7160 throw new Error('invalid iban address'); 7161 } 7162 7163 if (iban.isDirect()) { 7164 return transferToAddress(klay, from, iban.address(), value, callback); 7165 } 7166 7167 if (!callback) { 7168 var address = klay.icapNamereg().addr(iban.institution()); 7169 return deposit(klay, from, address, value, iban.client()); 7170 } 7171 7172 klay.icapNamereg().addr(iban.institution(), function (err, address) { 7173 return deposit(klay, from, address, value, iban.client(), callback); 7174 }); 7175 7176 }; 7177 7178 /** 7179 * Should be used to transfer funds to certain address 7180 * 7181 * @method transferToAddress 7182 * @param {String} from 7183 * @param {String} to 7184 * @param {Value} value to be tranfered 7185 * @param {Function} callback, callback 7186 */ 7187 var transferToAddress = function (klay, from, to, value, callback) { 7188 return klay.sendTransaction({ 7189 address: to, 7190 from: from, 7191 value: value 7192 }, callback); 7193 }; 7194 7195 /** 7196 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 7197 * 7198 * @method deposit 7199 * @param {String} from 7200 * @param {String} to 7201 * @param {Value} value to be transfered 7202 * @param {String} client unique identifier 7203 * @param {Function} callback, callback 7204 */ 7205 var deposit = function (v, from, to, value, client, callback) { 7206 var abi = exchangeAbi; 7207 return klay.contract(abi).at(to).deposit(client, { 7208 from: from, 7209 value: value 7210 }, callback); 7211 }; 7212 7213 module.exports = transfer; 7214 7215 7216 },{"../contracts/SmartExchange.json":3,"./iban":33}],50:[function(require,module,exports){ 7217 7218 },{}],51:[function(require,module,exports){ 7219 ;(function (root, factory, undef) { 7220 if (typeof exports === "object") { 7221 // CommonJS 7222 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 7223 } 7224 else if (typeof define === "function" && define.amd) { 7225 // AMD 7226 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 7227 } 7228 else { 7229 // Global (browser) 7230 factory(root.CryptoJS); 7231 } 7232 }(this, function (CryptoJS) { 7233 7234 (function () { 7235 // Shortcuts 7236 var C = CryptoJS; 7237 var C_lib = C.lib; 7238 var BlockCipher = C_lib.BlockCipher; 7239 var C_algo = C.algo; 7240 7241 // Lookup tables 7242 var SBOX = []; 7243 var INV_SBOX = []; 7244 var SUB_MIX_0 = []; 7245 var SUB_MIX_1 = []; 7246 var SUB_MIX_2 = []; 7247 var SUB_MIX_3 = []; 7248 var INV_SUB_MIX_0 = []; 7249 var INV_SUB_MIX_1 = []; 7250 var INV_SUB_MIX_2 = []; 7251 var INV_SUB_MIX_3 = []; 7252 7253 // Compute lookup tables 7254 (function () { 7255 // Compute double table 7256 var d = []; 7257 for (var i = 0; i < 256; i++) { 7258 if (i < 128) { 7259 d[i] = i << 1; 7260 } else { 7261 d[i] = (i << 1) ^ 0x11b; 7262 } 7263 } 7264 7265 // Walk GF(2^8) 7266 var x = 0; 7267 var xi = 0; 7268 for (var i = 0; i < 256; i++) { 7269 // Compute sbox 7270 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 7271 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 7272 SBOX[x] = sx; 7273 INV_SBOX[sx] = x; 7274 7275 // Compute multiplication 7276 var x2 = d[x]; 7277 var x4 = d[x2]; 7278 var x8 = d[x4]; 7279 7280 // Compute sub bytes, mix columns tables 7281 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 7282 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 7283 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 7284 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 7285 SUB_MIX_3[x] = t; 7286 7287 // Compute inv sub bytes, inv mix columns tables 7288 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 7289 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 7290 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 7291 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 7292 INV_SUB_MIX_3[sx] = t; 7293 7294 // Compute next counter 7295 if (!x) { 7296 x = xi = 1; 7297 } else { 7298 x = x2 ^ d[d[d[x8 ^ x2]]]; 7299 xi ^= d[d[xi]]; 7300 } 7301 } 7302 }()); 7303 7304 // Precomputed Rcon lookup 7305 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 7306 7307 /** 7308 * AES block cipher algorithm. 7309 */ 7310 var AES = C_algo.AES = BlockCipher.extend({ 7311 _doReset: function () { 7312 // Skip reset of nRounds has been set before and key did not change 7313 if (this._nRounds && this._keyPriorReset === this._key) { 7314 return; 7315 } 7316 7317 // Shortcuts 7318 var key = this._keyPriorReset = this._key; 7319 var keyWords = key.words; 7320 var keySize = key.sigBytes / 4; 7321 7322 // Compute number of rounds 7323 var nRounds = this._nRounds = keySize + 6; 7324 7325 // Compute number of key schedule rows 7326 var ksRows = (nRounds + 1) * 4; 7327 7328 // Compute key schedule 7329 var keySchedule = this._keySchedule = []; 7330 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 7331 if (ksRow < keySize) { 7332 keySchedule[ksRow] = keyWords[ksRow]; 7333 } else { 7334 var t = keySchedule[ksRow - 1]; 7335 7336 if (!(ksRow % keySize)) { 7337 // Rot word 7338 t = (t << 8) | (t >>> 24); 7339 7340 // Sub word 7341 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 7342 7343 // Mix Rcon 7344 t ^= RCON[(ksRow / keySize) | 0] << 24; 7345 } else if (keySize > 6 && ksRow % keySize == 4) { 7346 // Sub word 7347 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 7348 } 7349 7350 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 7351 } 7352 } 7353 7354 // Compute inv key schedule 7355 var invKeySchedule = this._invKeySchedule = []; 7356 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 7357 var ksRow = ksRows - invKsRow; 7358 7359 if (invKsRow % 4) { 7360 var t = keySchedule[ksRow]; 7361 } else { 7362 var t = keySchedule[ksRow - 4]; 7363 } 7364 7365 if (invKsRow < 4 || ksRow <= 4) { 7366 invKeySchedule[invKsRow] = t; 7367 } else { 7368 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 7369 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 7370 } 7371 } 7372 }, 7373 7374 encryptBlock: function (M, offset) { 7375 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 7376 }, 7377 7378 decryptBlock: function (M, offset) { 7379 // Swap 2nd and 4th rows 7380 var t = M[offset + 1]; 7381 M[offset + 1] = M[offset + 3]; 7382 M[offset + 3] = t; 7383 7384 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 7385 7386 // Inv swap 2nd and 4th rows 7387 var t = M[offset + 1]; 7388 M[offset + 1] = M[offset + 3]; 7389 M[offset + 3] = t; 7390 }, 7391 7392 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 7393 // Shortcut 7394 var nRounds = this._nRounds; 7395 7396 // Get input, add round key 7397 var s0 = M[offset] ^ keySchedule[0]; 7398 var s1 = M[offset + 1] ^ keySchedule[1]; 7399 var s2 = M[offset + 2] ^ keySchedule[2]; 7400 var s3 = M[offset + 3] ^ keySchedule[3]; 7401 7402 // Key schedule row counter 7403 var ksRow = 4; 7404 7405 // Rounds 7406 for (var round = 1; round < nRounds; round++) { 7407 // Shift rows, sub bytes, mix columns, add round key 7408 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++]; 7409 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++]; 7410 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++]; 7411 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++]; 7412 7413 // Update state 7414 s0 = t0; 7415 s1 = t1; 7416 s2 = t2; 7417 s3 = t3; 7418 } 7419 7420 // Shift rows, sub bytes, add round key 7421 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 7422 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 7423 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 7424 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 7425 7426 // Set output 7427 M[offset] = t0; 7428 M[offset + 1] = t1; 7429 M[offset + 2] = t2; 7430 M[offset + 3] = t3; 7431 }, 7432 7433 keySize: 256/32 7434 }); 7435 7436 /** 7437 * Shortcut functions to the cipher's object interface. 7438 * 7439 * @example 7440 * 7441 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7442 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7443 */ 7444 C.AES = BlockCipher._createHelper(AES); 7445 }()); 7446 7447 7448 return CryptoJS.AES; 7449 7450 })); 7451 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],52:[function(require,module,exports){ 7452 ;(function (root, factory) { 7453 if (typeof exports === "object") { 7454 // CommonJS 7455 module.exports = exports = factory(require("./core")); 7456 } 7457 else if (typeof define === "function" && define.amd) { 7458 // AMD 7459 define(["./core"], factory); 7460 } 7461 else { 7462 // Global (browser) 7463 factory(root.CryptoJS); 7464 } 7465 }(this, function (CryptoJS) { 7466 7467 /** 7468 * Cipher blockchain components. 7469 */ 7470 CryptoJS.lib.Cipher || (function (undefined) { 7471 // Shortcuts 7472 var C = CryptoJS; 7473 var C_lib = C.lib; 7474 var Base = C_lib.Base; 7475 var WordArray = C_lib.WordArray; 7476 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7477 var C_enc = C.enc; 7478 var Utf8 = C_enc.Utf8; 7479 var Base64 = C_enc.Base64; 7480 var C_algo = C.algo; 7481 var EvpKDF = C_algo.EvpKDF; 7482 7483 /** 7484 * Abstract base cipher template. 7485 * 7486 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7487 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7488 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7489 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7490 */ 7491 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7492 /** 7493 * Configuration options. 7494 * 7495 * @property {WordArray} iv The IV to use for this operation. 7496 */ 7497 cfg: Base.extend(), 7498 7499 /** 7500 * Creates this cipher in encryption mode. 7501 * 7502 * @param {WordArray} key The key. 7503 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7504 * 7505 * @return {Cipher} A cipher instance. 7506 * 7507 * @static 7508 * 7509 * @example 7510 * 7511 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7512 */ 7513 createEncryptor: function (key, cfg) { 7514 return this.create(this._ENC_XFORM_MODE, key, cfg); 7515 }, 7516 7517 /** 7518 * Creates this cipher in decryption mode. 7519 * 7520 * @param {WordArray} key The key. 7521 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7522 * 7523 * @return {Cipher} A cipher instance. 7524 * 7525 * @static 7526 * 7527 * @example 7528 * 7529 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7530 */ 7531 createDecryptor: function (key, cfg) { 7532 return this.create(this._DEC_XFORM_MODE, key, cfg); 7533 }, 7534 7535 /** 7536 * Initializes a newly created cipher. 7537 * 7538 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7539 * @param {WordArray} key The key. 7540 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7541 * 7542 * @example 7543 * 7544 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7545 */ 7546 init: function (xformMode, key, cfg) { 7547 // Apply config defaults 7548 this.cfg = this.cfg.extend(cfg); 7549 7550 // Store transform mode and key 7551 this._xformMode = xformMode; 7552 this._key = key; 7553 7554 // Set initial values 7555 this.reset(); 7556 }, 7557 7558 /** 7559 * Resets this cipher to its initial state. 7560 * 7561 * @example 7562 * 7563 * cipher.reset(); 7564 */ 7565 reset: function () { 7566 // Reset data buffer 7567 BufferedBlockAlgorithm.reset.call(this); 7568 7569 // Perform concrete-cipher logic 7570 this._doReset(); 7571 }, 7572 7573 /** 7574 * Adds data to be encrypted or decrypted. 7575 * 7576 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7577 * 7578 * @return {WordArray} The data after processing. 7579 * 7580 * @example 7581 * 7582 * var encrypted = cipher.process('data'); 7583 * var encrypted = cipher.process(wordArray); 7584 */ 7585 process: function (dataUpdate) { 7586 // Append 7587 this._append(dataUpdate); 7588 7589 // Process available blocks 7590 return this._process(); 7591 }, 7592 7593 /** 7594 * Finalizes the encryption or decryption process. 7595 * Note that the finalize operation is effectively a destructive, read-once operation. 7596 * 7597 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7598 * 7599 * @return {WordArray} The data after final processing. 7600 * 7601 * @example 7602 * 7603 * var encrypted = cipher.finalize(); 7604 * var encrypted = cipher.finalize('data'); 7605 * var encrypted = cipher.finalize(wordArray); 7606 */ 7607 finalize: function (dataUpdate) { 7608 // Final data update 7609 if (dataUpdate) { 7610 this._append(dataUpdate); 7611 } 7612 7613 // Perform concrete-cipher logic 7614 var finalProcessedData = this._doFinalize(); 7615 7616 return finalProcessedData; 7617 }, 7618 7619 keySize: 128/32, 7620 7621 ivSize: 128/32, 7622 7623 _ENC_XFORM_MODE: 1, 7624 7625 _DEC_XFORM_MODE: 2, 7626 7627 /** 7628 * Creates shortcut functions to a cipher's object interface. 7629 * 7630 * @param {Cipher} cipher The cipher to create a helper for. 7631 * 7632 * @return {Object} An object with encrypt and decrypt shortcut functions. 7633 * 7634 * @static 7635 * 7636 * @example 7637 * 7638 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7639 */ 7640 _createHelper: (function () { 7641 function selectCipherStrategy(key) { 7642 if (typeof key == 'string') { 7643 return PasswordBasedCipher; 7644 } else { 7645 return SerializableCipher; 7646 } 7647 } 7648 7649 return function (cipher) { 7650 return { 7651 encrypt: function (message, key, cfg) { 7652 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7653 }, 7654 7655 decrypt: function (ciphertext, key, cfg) { 7656 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7657 } 7658 }; 7659 }; 7660 }()) 7661 }); 7662 7663 /** 7664 * Abstract base stream cipher template. 7665 * 7666 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7667 */ 7668 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7669 _doFinalize: function () { 7670 // Process partial blocks 7671 var finalProcessedBlocks = this._process(!!'flush'); 7672 7673 return finalProcessedBlocks; 7674 }, 7675 7676 blockSize: 1 7677 }); 7678 7679 /** 7680 * Mode namespace. 7681 */ 7682 var C_mode = C.mode = {}; 7683 7684 /** 7685 * Abstract base block cipher mode template. 7686 */ 7687 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7688 /** 7689 * Creates this mode for encryption. 7690 * 7691 * @param {Cipher} cipher A block cipher instance. 7692 * @param {Array} iv The IV words. 7693 * 7694 * @static 7695 * 7696 * @example 7697 * 7698 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7699 */ 7700 createEncryptor: function (cipher, iv) { 7701 return this.Encryptor.create(cipher, iv); 7702 }, 7703 7704 /** 7705 * Creates this mode for decryption. 7706 * 7707 * @param {Cipher} cipher A block cipher instance. 7708 * @param {Array} iv The IV words. 7709 * 7710 * @static 7711 * 7712 * @example 7713 * 7714 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7715 */ 7716 createDecryptor: function (cipher, iv) { 7717 return this.Decryptor.create(cipher, iv); 7718 }, 7719 7720 /** 7721 * Initializes a newly created mode. 7722 * 7723 * @param {Cipher} cipher A block cipher instance. 7724 * @param {Array} iv The IV words. 7725 * 7726 * @example 7727 * 7728 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7729 */ 7730 init: function (cipher, iv) { 7731 this._cipher = cipher; 7732 this._iv = iv; 7733 } 7734 }); 7735 7736 /** 7737 * Cipher Block Chaining mode. 7738 */ 7739 var CBC = C_mode.CBC = (function () { 7740 /** 7741 * Abstract base CBC mode. 7742 */ 7743 var CBC = BlockCipherMode.extend(); 7744 7745 /** 7746 * CBC encryptor. 7747 */ 7748 CBC.Encryptor = CBC.extend({ 7749 /** 7750 * Processes the data block at offset. 7751 * 7752 * @param {Array} words The data words to operate on. 7753 * @param {number} offset The offset where the block starts. 7754 * 7755 * @example 7756 * 7757 * mode.processBlock(data.words, offset); 7758 */ 7759 processBlock: function (words, offset) { 7760 // Shortcuts 7761 var cipher = this._cipher; 7762 var blockSize = cipher.blockSize; 7763 7764 // XOR and encrypt 7765 xorBlock.call(this, words, offset, blockSize); 7766 cipher.encryptBlock(words, offset); 7767 7768 // Remember this block to use with next block 7769 this._prevBlock = words.slice(offset, offset + blockSize); 7770 } 7771 }); 7772 7773 /** 7774 * CBC decryptor. 7775 */ 7776 CBC.Decryptor = CBC.extend({ 7777 /** 7778 * Processes the data block at offset. 7779 * 7780 * @param {Array} words The data words to operate on. 7781 * @param {number} offset The offset where the block starts. 7782 * 7783 * @example 7784 * 7785 * mode.processBlock(data.words, offset); 7786 */ 7787 processBlock: function (words, offset) { 7788 // Shortcuts 7789 var cipher = this._cipher; 7790 var blockSize = cipher.blockSize; 7791 7792 // Remember this block to use with next block 7793 var thisBlock = words.slice(offset, offset + blockSize); 7794 7795 // Decrypt and XOR 7796 cipher.decryptBlock(words, offset); 7797 xorBlock.call(this, words, offset, blockSize); 7798 7799 // This block becomes the previous block 7800 this._prevBlock = thisBlock; 7801 } 7802 }); 7803 7804 function xorBlock(words, offset, blockSize) { 7805 // Shortcut 7806 var iv = this._iv; 7807 7808 // Choose mixing block 7809 if (iv) { 7810 var block = iv; 7811 7812 // Remove IV for subsequent blocks 7813 this._iv = undefined; 7814 } else { 7815 var block = this._prevBlock; 7816 } 7817 7818 // XOR blocks 7819 for (var i = 0; i < blockSize; i++) { 7820 words[offset + i] ^= block[i]; 7821 } 7822 } 7823 7824 return CBC; 7825 }()); 7826 7827 /** 7828 * Padding namespace. 7829 */ 7830 var C_pad = C.pad = {}; 7831 7832 /** 7833 * PKCS #5/7 padding strategy. 7834 */ 7835 var Pkcs7 = C_pad.Pkcs7 = { 7836 /** 7837 * Pads data using the algorithm defined in PKCS #5/7. 7838 * 7839 * @param {WordArray} data The data to pad. 7840 * @param {number} blockSize The multiple that the data should be padded to. 7841 * 7842 * @static 7843 * 7844 * @example 7845 * 7846 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7847 */ 7848 pad: function (data, blockSize) { 7849 // Shortcut 7850 var blockSizeBytes = blockSize * 4; 7851 7852 // Count padding bytes 7853 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7854 7855 // Create padding word 7856 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7857 7858 // Create padding 7859 var paddingWords = []; 7860 for (var i = 0; i < nPaddingBytes; i += 4) { 7861 paddingWords.push(paddingWord); 7862 } 7863 var padding = WordArray.create(paddingWords, nPaddingBytes); 7864 7865 // Add padding 7866 data.concat(padding); 7867 }, 7868 7869 /** 7870 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7871 * 7872 * @param {WordArray} data The data to unpad. 7873 * 7874 * @static 7875 * 7876 * @example 7877 * 7878 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7879 */ 7880 unpad: function (data) { 7881 // Get number of padding bytes from last byte 7882 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7883 7884 // Remove padding 7885 data.sigBytes -= nPaddingBytes; 7886 } 7887 }; 7888 7889 /** 7890 * Abstract base block cipher template. 7891 * 7892 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7893 */ 7894 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7895 /** 7896 * Configuration options. 7897 * 7898 * @property {Mode} mode The block mode to use. Default: CBC 7899 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7900 */ 7901 cfg: Cipher.cfg.extend({ 7902 mode: CBC, 7903 padding: Pkcs7 7904 }), 7905 7906 reset: function () { 7907 // Reset cipher 7908 Cipher.reset.call(this); 7909 7910 // Shortcuts 7911 var cfg = this.cfg; 7912 var iv = cfg.iv; 7913 var mode = cfg.mode; 7914 7915 // Reset block mode 7916 if (this._xformMode == this._ENC_XFORM_MODE) { 7917 var modeCreator = mode.createEncryptor; 7918 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7919 var modeCreator = mode.createDecryptor; 7920 7921 // Keep at least one block in the buffer for unpadding 7922 this._minBufferSize = 1; 7923 } 7924 this._mode = modeCreator.call(mode, this, iv && iv.words); 7925 }, 7926 7927 _doProcessBlock: function (words, offset) { 7928 this._mode.processBlock(words, offset); 7929 }, 7930 7931 _doFinalize: function () { 7932 // Shortcut 7933 var padding = this.cfg.padding; 7934 7935 // Finalize 7936 if (this._xformMode == this._ENC_XFORM_MODE) { 7937 // Pad data 7938 padding.pad(this._data, this.blockSize); 7939 7940 // Process final blocks 7941 var finalProcessedBlocks = this._process(!!'flush'); 7942 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7943 // Process final blocks 7944 var finalProcessedBlocks = this._process(!!'flush'); 7945 7946 // Unpad data 7947 padding.unpad(finalProcessedBlocks); 7948 } 7949 7950 return finalProcessedBlocks; 7951 }, 7952 7953 blockSize: 128/32 7954 }); 7955 7956 /** 7957 * A collection of cipher parameters. 7958 * 7959 * @property {WordArray} ciphertext The raw ciphertext. 7960 * @property {WordArray} key The key to this ciphertext. 7961 * @property {WordArray} iv The IV used in the ciphering operation. 7962 * @property {WordArray} salt The salt used with a key derivation function. 7963 * @property {Cipher} algorithm The cipher algorithm. 7964 * @property {Mode} mode The block mode used in the ciphering operation. 7965 * @property {Padding} padding The padding scheme used in the ciphering operation. 7966 * @property {number} blockSize The block size of the cipher. 7967 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7968 */ 7969 var CipherParams = C_lib.CipherParams = Base.extend({ 7970 /** 7971 * Initializes a newly created cipher params object. 7972 * 7973 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7974 * 7975 * @example 7976 * 7977 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7978 * ciphertext: ciphertextWordArray, 7979 * key: keyWordArray, 7980 * iv: ivWordArray, 7981 * salt: saltWordArray, 7982 * algorithm: CryptoJS.algo.AES, 7983 * mode: CryptoJS.mode.CBC, 7984 * padding: CryptoJS.pad.PKCS7, 7985 * blockSize: 4, 7986 * formatter: CryptoJS.format.OpenSSL 7987 * }); 7988 */ 7989 init: function (cipherParams) { 7990 this.mixIn(cipherParams); 7991 }, 7992 7993 /** 7994 * Converts this cipher params object to a string. 7995 * 7996 * @param {Format} formatter (Optional) The formatting strategy to use. 7997 * 7998 * @return {string} The stringified cipher params. 7999 * 8000 * @throws Error If neither the formatter nor the default formatter is set. 8001 * 8002 * @example 8003 * 8004 * var string = cipherParams + ''; 8005 * var string = cipherParams.toString(); 8006 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 8007 */ 8008 toString: function (formatter) { 8009 return (formatter || this.formatter).stringify(this); 8010 } 8011 }); 8012 8013 /** 8014 * Format namespace. 8015 */ 8016 var C_format = C.format = {}; 8017 8018 /** 8019 * OpenSSL formatting strategy. 8020 */ 8021 var OpenSSLFormatter = C_format.OpenSSL = { 8022 /** 8023 * Converts a cipher params object to an OpenSSL-compatible string. 8024 * 8025 * @param {CipherParams} cipherParams The cipher params object. 8026 * 8027 * @return {string} The OpenSSL-compatible string. 8028 * 8029 * @static 8030 * 8031 * @example 8032 * 8033 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 8034 */ 8035 stringify: function (cipherParams) { 8036 // Shortcuts 8037 var ciphertext = cipherParams.ciphertext; 8038 var salt = cipherParams.salt; 8039 8040 // Format 8041 if (salt) { 8042 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 8043 } else { 8044 var wordArray = ciphertext; 8045 } 8046 8047 return wordArray.toString(Base64); 8048 }, 8049 8050 /** 8051 * Converts an OpenSSL-compatible string to a cipher params object. 8052 * 8053 * @param {string} openSSLStr The OpenSSL-compatible string. 8054 * 8055 * @return {CipherParams} The cipher params object. 8056 * 8057 * @static 8058 * 8059 * @example 8060 * 8061 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 8062 */ 8063 parse: function (openSSLStr) { 8064 // Parse base64 8065 var ciphertext = Base64.parse(openSSLStr); 8066 8067 // Shortcut 8068 var ciphertextWords = ciphertext.words; 8069 8070 // Test for salt 8071 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 8072 // Extract salt 8073 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 8074 8075 // Remove salt from ciphertext 8076 ciphertextWords.splice(0, 4); 8077 ciphertext.sigBytes -= 16; 8078 } 8079 8080 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 8081 } 8082 }; 8083 8084 /** 8085 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 8086 */ 8087 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 8088 /** 8089 * Configuration options. 8090 * 8091 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 8092 */ 8093 cfg: Base.extend({ 8094 format: OpenSSLFormatter 8095 }), 8096 8097 /** 8098 * Encrypts a message. 8099 * 8100 * @param {Cipher} cipher The cipher algorithm to use. 8101 * @param {WordArray|string} message The message to encrypt. 8102 * @param {WordArray} key The key. 8103 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8104 * 8105 * @return {CipherParams} A cipher params object. 8106 * 8107 * @static 8108 * 8109 * @example 8110 * 8111 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 8112 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 8113 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8114 */ 8115 encrypt: function (cipher, message, key, cfg) { 8116 // Apply config defaults 8117 cfg = this.cfg.extend(cfg); 8118 8119 // Encrypt 8120 var encryptor = cipher.createEncryptor(key, cfg); 8121 var ciphertext = encryptor.finalize(message); 8122 8123 // Shortcut 8124 var cipherCfg = encryptor.cfg; 8125 8126 // Create and return serializable cipher params 8127 return CipherParams.create({ 8128 ciphertext: ciphertext, 8129 key: key, 8130 iv: cipherCfg.iv, 8131 algorithm: cipher, 8132 mode: cipherCfg.mode, 8133 padding: cipherCfg.padding, 8134 blockSize: cipher.blockSize, 8135 formatter: cfg.format 8136 }); 8137 }, 8138 8139 /** 8140 * Decrypts serialized ciphertext. 8141 * 8142 * @param {Cipher} cipher The cipher algorithm to use. 8143 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8144 * @param {WordArray} key The key. 8145 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8146 * 8147 * @return {WordArray} The plaintext. 8148 * 8149 * @static 8150 * 8151 * @example 8152 * 8153 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8154 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 8155 */ 8156 decrypt: function (cipher, ciphertext, key, cfg) { 8157 // Apply config defaults 8158 cfg = this.cfg.extend(cfg); 8159 8160 // Convert string to CipherParams 8161 ciphertext = this._parse(ciphertext, cfg.format); 8162 8163 // Decrypt 8164 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 8165 8166 return plaintext; 8167 }, 8168 8169 /** 8170 * Converts serialized ciphertext to CipherParams, 8171 * else assumed CipherParams already and returns ciphertext unchanged. 8172 * 8173 * @param {CipherParams|string} ciphertext The ciphertext. 8174 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 8175 * 8176 * @return {CipherParams} The unserialized ciphertext. 8177 * 8178 * @static 8179 * 8180 * @example 8181 * 8182 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 8183 */ 8184 _parse: function (ciphertext, format) { 8185 if (typeof ciphertext == 'string') { 8186 return format.parse(ciphertext, this); 8187 } else { 8188 return ciphertext; 8189 } 8190 } 8191 }); 8192 8193 /** 8194 * Key derivation function namespace. 8195 */ 8196 var C_kdf = C.kdf = {}; 8197 8198 /** 8199 * OpenSSL key derivation function. 8200 */ 8201 var OpenSSLKdf = C_kdf.OpenSSL = { 8202 /** 8203 * Derives a key and IV from a password. 8204 * 8205 * @param {string} password The password to derive from. 8206 * @param {number} keySize The size in words of the key to generate. 8207 * @param {number} ivSize The size in words of the IV to generate. 8208 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 8209 * 8210 * @return {CipherParams} A cipher params object with the key, IV, and salt. 8211 * 8212 * @static 8213 * 8214 * @example 8215 * 8216 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 8217 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 8218 */ 8219 execute: function (password, keySize, ivSize, salt) { 8220 // Generate random salt 8221 if (!salt) { 8222 salt = WordArray.random(64/8); 8223 } 8224 8225 // Derive key and IV 8226 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 8227 8228 // Separate key and IV 8229 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 8230 key.sigBytes = keySize * 4; 8231 8232 // Return params 8233 return CipherParams.create({ key: key, iv: iv, salt: salt }); 8234 } 8235 }; 8236 8237 /** 8238 * A serializable cipher wrapper that derives the key from a password, 8239 * and returns ciphertext as a serializable cipher params object. 8240 */ 8241 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 8242 /** 8243 * Configuration options. 8244 * 8245 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 8246 */ 8247 cfg: SerializableCipher.cfg.extend({ 8248 kdf: OpenSSLKdf 8249 }), 8250 8251 /** 8252 * Encrypts a message using a password. 8253 * 8254 * @param {Cipher} cipher The cipher algorithm to use. 8255 * @param {WordArray|string} message The message to encrypt. 8256 * @param {string} password The password. 8257 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8258 * 8259 * @return {CipherParams} A cipher params object. 8260 * 8261 * @static 8262 * 8263 * @example 8264 * 8265 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 8266 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 8267 */ 8268 encrypt: function (cipher, message, password, cfg) { 8269 // Apply config defaults 8270 cfg = this.cfg.extend(cfg); 8271 8272 // Derive key and other params 8273 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 8274 8275 // Add IV to config 8276 cfg.iv = derivedParams.iv; 8277 8278 // Encrypt 8279 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 8280 8281 // Mix in derived params 8282 ciphertext.mixIn(derivedParams); 8283 8284 return ciphertext; 8285 }, 8286 8287 /** 8288 * Decrypts serialized ciphertext using a password. 8289 * 8290 * @param {Cipher} cipher The cipher algorithm to use. 8291 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 8292 * @param {string} password The password. 8293 * @param {Object} cfg (Optional) The configuration options to use for this operation. 8294 * 8295 * @return {WordArray} The plaintext. 8296 * 8297 * @static 8298 * 8299 * @example 8300 * 8301 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 8302 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 8303 */ 8304 decrypt: function (cipher, ciphertext, password, cfg) { 8305 // Apply config defaults 8306 cfg = this.cfg.extend(cfg); 8307 8308 // Convert string to CipherParams 8309 ciphertext = this._parse(ciphertext, cfg.format); 8310 8311 // Derive key and other params 8312 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 8313 8314 // Add IV to config 8315 cfg.iv = derivedParams.iv; 8316 8317 // Decrypt 8318 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 8319 8320 return plaintext; 8321 } 8322 }); 8323 }()); 8324 8325 8326 })); 8327 },{"./core":53}],53:[function(require,module,exports){ 8328 ;(function (root, factory) { 8329 if (typeof exports === "object") { 8330 // CommonJS 8331 module.exports = exports = factory(); 8332 } 8333 else if (typeof define === "function" && define.amd) { 8334 // AMD 8335 define([], factory); 8336 } 8337 else { 8338 // Global (browser) 8339 root.CryptoJS = factory(); 8340 } 8341 }(this, function () { 8342 8343 /** 8344 * CryptoJS blockchain components. 8345 */ 8346 var CryptoJS = CryptoJS || (function (Math, undefined) { 8347 /* 8348 * Local polyfil of Object.create 8349 */ 8350 var create = Object.create || (function () { 8351 function F() {}; 8352 8353 return function (obj) { 8354 var subtype; 8355 8356 F.prototype = obj; 8357 8358 subtype = new F(); 8359 8360 F.prototype = null; 8361 8362 return subtype; 8363 }; 8364 }()) 8365 8366 /** 8367 * CryptoJS namespace. 8368 */ 8369 var C = {}; 8370 8371 /** 8372 * Library namespace. 8373 */ 8374 var C_lib = C.lib = {}; 8375 8376 /** 8377 * Base object for prototypal inheritance. 8378 */ 8379 var Base = C_lib.Base = (function () { 8380 8381 8382 return { 8383 /** 8384 * Creates a new object that inherits from this object. 8385 * 8386 * @param {Object} overrides Properties to copy into the new object. 8387 * 8388 * @return {Object} The new object. 8389 * 8390 * @static 8391 * 8392 * @example 8393 * 8394 * var MyType = CryptoJS.lib.Base.extend({ 8395 * field: 'value', 8396 * 8397 * method: function () { 8398 * } 8399 * }); 8400 */ 8401 extend: function (overrides) { 8402 // Spawn 8403 var subtype = create(this); 8404 8405 // Augment 8406 if (overrides) { 8407 subtype.mixIn(overrides); 8408 } 8409 8410 // Create default initializer 8411 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 8412 subtype.init = function () { 8413 subtype.$super.init.apply(this, arguments); 8414 }; 8415 } 8416 8417 // Initializer's prototype is the subtype object 8418 subtype.init.prototype = subtype; 8419 8420 // Reference supertype 8421 subtype.$super = this; 8422 8423 return subtype; 8424 }, 8425 8426 /** 8427 * Extends this object and runs the init method. 8428 * Arguments to create() will be passed to init(). 8429 * 8430 * @return {Object} The new object. 8431 * 8432 * @static 8433 * 8434 * @example 8435 * 8436 * var instance = MyType.create(); 8437 */ 8438 create: function () { 8439 var instance = this.extend(); 8440 instance.init.apply(instance, arguments); 8441 8442 return instance; 8443 }, 8444 8445 /** 8446 * Initializes a newly created object. 8447 * Override this method to add some logic when your objects are created. 8448 * 8449 * @example 8450 * 8451 * var MyType = CryptoJS.lib.Base.extend({ 8452 * init: function () { 8453 * // ... 8454 * } 8455 * }); 8456 */ 8457 init: function () { 8458 }, 8459 8460 /** 8461 * Copies properties into this object. 8462 * 8463 * @param {Object} properties The properties to mix in. 8464 * 8465 * @example 8466 * 8467 * MyType.mixIn({ 8468 * field: 'value' 8469 * }); 8470 */ 8471 mixIn: function (properties) { 8472 for (var propertyName in properties) { 8473 if (properties.hasOwnProperty(propertyName)) { 8474 this[propertyName] = properties[propertyName]; 8475 } 8476 } 8477 8478 // IE won't copy toString using the loop above 8479 if (properties.hasOwnProperty('toString')) { 8480 this.toString = properties.toString; 8481 } 8482 }, 8483 8484 /** 8485 * Creates a copy of this object. 8486 * 8487 * @return {Object} The clone. 8488 * 8489 * @example 8490 * 8491 * var clone = instance.clone(); 8492 */ 8493 clone: function () { 8494 return this.init.prototype.extend(this); 8495 } 8496 }; 8497 }()); 8498 8499 /** 8500 * An array of 32-bit words. 8501 * 8502 * @property {Array} words The array of 32-bit words. 8503 * @property {number} sigBytes The number of significant bytes in this word array. 8504 */ 8505 var WordArray = C_lib.WordArray = Base.extend({ 8506 /** 8507 * Initializes a newly created word array. 8508 * 8509 * @param {Array} words (Optional) An array of 32-bit words. 8510 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8511 * 8512 * @example 8513 * 8514 * var wordArray = CryptoJS.lib.WordArray.create(); 8515 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8516 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8517 */ 8518 init: function (words, sigBytes) { 8519 words = this.words = words || []; 8520 8521 if (sigBytes != undefined) { 8522 this.sigBytes = sigBytes; 8523 } else { 8524 this.sigBytes = words.length * 4; 8525 } 8526 }, 8527 8528 /** 8529 * Converts this word array to a string. 8530 * 8531 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8532 * 8533 * @return {string} The stringified word array. 8534 * 8535 * @example 8536 * 8537 * var string = wordArray + ''; 8538 * var string = wordArray.toString(); 8539 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8540 */ 8541 toString: function (encoder) { 8542 return (encoder || Hex).stringify(this); 8543 }, 8544 8545 /** 8546 * Concatenates a word array to this word array. 8547 * 8548 * @param {WordArray} wordArray The word array to append. 8549 * 8550 * @return {WordArray} This word array. 8551 * 8552 * @example 8553 * 8554 * wordArray1.concat(wordArray2); 8555 */ 8556 concat: function (wordArray) { 8557 // Shortcuts 8558 var thisWords = this.words; 8559 var thatWords = wordArray.words; 8560 var thisSigBytes = this.sigBytes; 8561 var thatSigBytes = wordArray.sigBytes; 8562 8563 // Clamp excess bits 8564 this.clamp(); 8565 8566 // Concat 8567 if (thisSigBytes % 4) { 8568 // Copy one byte at a time 8569 for (var i = 0; i < thatSigBytes; i++) { 8570 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8571 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8572 } 8573 } else { 8574 // Copy one word at a time 8575 for (var i = 0; i < thatSigBytes; i += 4) { 8576 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8577 } 8578 } 8579 this.sigBytes += thatSigBytes; 8580 8581 // Chainable 8582 return this; 8583 }, 8584 8585 /** 8586 * Removes insignificant bits. 8587 * 8588 * @example 8589 * 8590 * wordArray.clamp(); 8591 */ 8592 clamp: function () { 8593 // Shortcuts 8594 var words = this.words; 8595 var sigBytes = this.sigBytes; 8596 8597 // Clamp 8598 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8599 words.length = Math.ceil(sigBytes / 4); 8600 }, 8601 8602 /** 8603 * Creates a copy of this word array. 8604 * 8605 * @return {WordArray} The clone. 8606 * 8607 * @example 8608 * 8609 * var clone = wordArray.clone(); 8610 */ 8611 clone: function () { 8612 var clone = Base.clone.call(this); 8613 clone.words = this.words.slice(0); 8614 8615 return clone; 8616 }, 8617 8618 /** 8619 * Creates a word array filled with random bytes. 8620 * 8621 * @param {number} nBytes The number of random bytes to generate. 8622 * 8623 * @return {WordArray} The random word array. 8624 * 8625 * @static 8626 * 8627 * @example 8628 * 8629 * var wordArray = CryptoJS.lib.WordArray.random(16); 8630 */ 8631 random: function (nBytes) { 8632 var words = []; 8633 8634 var r = (function (m_w) { 8635 var m_w = m_w; 8636 var m_z = 0x3ade68b1; 8637 var mask = 0xffffffff; 8638 8639 return function () { 8640 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8641 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8642 var result = ((m_z << 0x10) + m_w) & mask; 8643 result /= 0x100000000; 8644 result += 0.5; 8645 return result * (Math.random() > .5 ? 1 : -1); 8646 } 8647 }); 8648 8649 for (var i = 0, rcache; i < nBytes; i += 4) { 8650 var _r = r((rcache || Math.random()) * 0x100000000); 8651 8652 rcache = _r() * 0x3ade67b7; 8653 words.push((_r() * 0x100000000) | 0); 8654 } 8655 8656 return new WordArray.init(words, nBytes); 8657 } 8658 }); 8659 8660 /** 8661 * Encoder namespace. 8662 */ 8663 var C_enc = C.enc = {}; 8664 8665 /** 8666 * Hex encoding strategy. 8667 */ 8668 var Hex = C_enc.Hex = { 8669 /** 8670 * Converts a word array to a hex string. 8671 * 8672 * @param {WordArray} wordArray The word array. 8673 * 8674 * @return {string} The hex string. 8675 * 8676 * @static 8677 * 8678 * @example 8679 * 8680 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8681 */ 8682 stringify: function (wordArray) { 8683 // Shortcuts 8684 var words = wordArray.words; 8685 var sigBytes = wordArray.sigBytes; 8686 8687 // Convert 8688 var hexChars = []; 8689 for (var i = 0; i < sigBytes; i++) { 8690 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8691 hexChars.push((bite >>> 4).toString(16)); 8692 hexChars.push((bite & 0x0f).toString(16)); 8693 } 8694 8695 return hexChars.join(''); 8696 }, 8697 8698 /** 8699 * Converts a hex string to a word array. 8700 * 8701 * @param {string} hexStr The hex string. 8702 * 8703 * @return {WordArray} The word array. 8704 * 8705 * @static 8706 * 8707 * @example 8708 * 8709 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8710 */ 8711 parse: function (hexStr) { 8712 // Shortcut 8713 var hexStrLength = hexStr.length; 8714 8715 // Convert 8716 var words = []; 8717 for (var i = 0; i < hexStrLength; i += 2) { 8718 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8719 } 8720 8721 return new WordArray.init(words, hexStrLength / 2); 8722 } 8723 }; 8724 8725 /** 8726 * Latin1 encoding strategy. 8727 */ 8728 var Latin1 = C_enc.Latin1 = { 8729 /** 8730 * Converts a word array to a Latin1 string. 8731 * 8732 * @param {WordArray} wordArray The word array. 8733 * 8734 * @return {string} The Latin1 string. 8735 * 8736 * @static 8737 * 8738 * @example 8739 * 8740 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8741 */ 8742 stringify: function (wordArray) { 8743 // Shortcuts 8744 var words = wordArray.words; 8745 var sigBytes = wordArray.sigBytes; 8746 8747 // Convert 8748 var latin1Chars = []; 8749 for (var i = 0; i < sigBytes; i++) { 8750 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8751 latin1Chars.push(String.fromCharCode(bite)); 8752 } 8753 8754 return latin1Chars.join(''); 8755 }, 8756 8757 /** 8758 * Converts a Latin1 string to a word array. 8759 * 8760 * @param {string} latin1Str The Latin1 string. 8761 * 8762 * @return {WordArray} The word array. 8763 * 8764 * @static 8765 * 8766 * @example 8767 * 8768 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8769 */ 8770 parse: function (latin1Str) { 8771 // Shortcut 8772 var latin1StrLength = latin1Str.length; 8773 8774 // Convert 8775 var words = []; 8776 for (var i = 0; i < latin1StrLength; i++) { 8777 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8778 } 8779 8780 return new WordArray.init(words, latin1StrLength); 8781 } 8782 }; 8783 8784 /** 8785 * UTF-8 encoding strategy. 8786 */ 8787 var Utf8 = C_enc.Utf8 = { 8788 /** 8789 * Converts a word array to a UTF-8 string. 8790 * 8791 * @param {WordArray} wordArray The word array. 8792 * 8793 * @return {string} The UTF-8 string. 8794 * 8795 * @static 8796 * 8797 * @example 8798 * 8799 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8800 */ 8801 stringify: function (wordArray) { 8802 try { 8803 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8804 } catch (e) { 8805 throw new Error('Malformed UTF-8 data'); 8806 } 8807 }, 8808 8809 /** 8810 * Converts a UTF-8 string to a word array. 8811 * 8812 * @param {string} utf8Str The UTF-8 string. 8813 * 8814 * @return {WordArray} The word array. 8815 * 8816 * @static 8817 * 8818 * @example 8819 * 8820 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8821 */ 8822 parse: function (utf8Str) { 8823 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8824 } 8825 }; 8826 8827 /** 8828 * Abstract buffered block algorithm template. 8829 * 8830 * The property blockSize must be implemented in a concrete subtype. 8831 * 8832 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8833 */ 8834 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8835 /** 8836 * Resets this block algorithm's data buffer to its initial state. 8837 * 8838 * @example 8839 * 8840 * bufferedBlockAlgorithm.reset(); 8841 */ 8842 reset: function () { 8843 // Initial values 8844 this._data = new WordArray.init(); 8845 this._nDataBytes = 0; 8846 }, 8847 8848 /** 8849 * Adds new data to this block algorithm's buffer. 8850 * 8851 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8852 * 8853 * @example 8854 * 8855 * bufferedBlockAlgorithm._append('data'); 8856 * bufferedBlockAlgorithm._append(wordArray); 8857 */ 8858 _append: function (data) { 8859 // Convert string to WordArray, else assume WordArray already 8860 if (typeof data == 'string') { 8861 data = Utf8.parse(data); 8862 } 8863 8864 // Append 8865 this._data.concat(data); 8866 this._nDataBytes += data.sigBytes; 8867 }, 8868 8869 /** 8870 * Processes available data blocks. 8871 * 8872 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8873 * 8874 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8875 * 8876 * @return {WordArray} The processed data. 8877 * 8878 * @example 8879 * 8880 * var processedData = bufferedBlockAlgorithm._process(); 8881 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8882 */ 8883 _process: function (doFlush) { 8884 // Shortcuts 8885 var data = this._data; 8886 var dataWords = data.words; 8887 var dataSigBytes = data.sigBytes; 8888 var blockSize = this.blockSize; 8889 var blockSizeBytes = blockSize * 4; 8890 8891 // Count blocks ready 8892 var nBlocksReady = dataSigBytes / blockSizeBytes; 8893 if (doFlush) { 8894 // Round up to include partial blocks 8895 nBlocksReady = Math.ceil(nBlocksReady); 8896 } else { 8897 // Round down to include only full blocks, 8898 // less the number of blocks that must remain in the buffer 8899 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8900 } 8901 8902 // Count words ready 8903 var nWordsReady = nBlocksReady * blockSize; 8904 8905 // Count bytes ready 8906 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8907 8908 // Process blocks 8909 if (nWordsReady) { 8910 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8911 // Perform concrete-algorithm logic 8912 this._doProcessBlock(dataWords, offset); 8913 } 8914 8915 // Remove processed words 8916 var processedWords = dataWords.splice(0, nWordsReady); 8917 data.sigBytes -= nBytesReady; 8918 } 8919 8920 // Return processed words 8921 return new WordArray.init(processedWords, nBytesReady); 8922 }, 8923 8924 /** 8925 * Creates a copy of this object. 8926 * 8927 * @return {Object} The clone. 8928 * 8929 * @example 8930 * 8931 * var clone = bufferedBlockAlgorithm.clone(); 8932 */ 8933 clone: function () { 8934 var clone = Base.clone.call(this); 8935 clone._data = this._data.clone(); 8936 8937 return clone; 8938 }, 8939 8940 _minBufferSize: 0 8941 }); 8942 8943 /** 8944 * Abstract hasher template. 8945 * 8946 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8947 */ 8948 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8949 /** 8950 * Configuration options. 8951 */ 8952 cfg: Base.extend(), 8953 8954 /** 8955 * Initializes a newly created hasher. 8956 * 8957 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8958 * 8959 * @example 8960 * 8961 * var hasher = CryptoJS.algo.SHA256.create(); 8962 */ 8963 init: function (cfg) { 8964 // Apply config defaults 8965 this.cfg = this.cfg.extend(cfg); 8966 8967 // Set initial values 8968 this.reset(); 8969 }, 8970 8971 /** 8972 * Resets this hasher to its initial state. 8973 * 8974 * @example 8975 * 8976 * hasher.reset(); 8977 */ 8978 reset: function () { 8979 // Reset data buffer 8980 BufferedBlockAlgorithm.reset.call(this); 8981 8982 // Perform concrete-hasher logic 8983 this._doReset(); 8984 }, 8985 8986 /** 8987 * Updates this hasher with a message. 8988 * 8989 * @param {WordArray|string} messageUpdate The message to append. 8990 * 8991 * @return {Hasher} This hasher. 8992 * 8993 * @example 8994 * 8995 * hasher.update('message'); 8996 * hasher.update(wordArray); 8997 */ 8998 update: function (messageUpdate) { 8999 // Append 9000 this._append(messageUpdate); 9001 9002 // Update the hash 9003 this._process(); 9004 9005 // Chainable 9006 return this; 9007 }, 9008 9009 /** 9010 * Finalizes the hash computation. 9011 * Note that the finalize operation is effectively a destructive, read-once operation. 9012 * 9013 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9014 * 9015 * @return {WordArray} The hash. 9016 * 9017 * @example 9018 * 9019 * var hash = hasher.finalize(); 9020 * var hash = hasher.finalize('message'); 9021 * var hash = hasher.finalize(wordArray); 9022 */ 9023 finalize: function (messageUpdate) { 9024 // Final message update 9025 if (messageUpdate) { 9026 this._append(messageUpdate); 9027 } 9028 9029 // Perform concrete-hasher logic 9030 var hash = this._doFinalize(); 9031 9032 return hash; 9033 }, 9034 9035 blockSize: 512/32, 9036 9037 /** 9038 * Creates a shortcut function to a hasher's object interface. 9039 * 9040 * @param {Hasher} hasher The hasher to create a helper for. 9041 * 9042 * @return {Function} The shortcut function. 9043 * 9044 * @static 9045 * 9046 * @example 9047 * 9048 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 9049 */ 9050 _createHelper: function (hasher) { 9051 return function (message, cfg) { 9052 return new hasher.init(cfg).finalize(message); 9053 }; 9054 }, 9055 9056 /** 9057 * Creates a shortcut function to the HMAC's object interface. 9058 * 9059 * @param {Hasher} hasher The hasher to use in this HMAC helper. 9060 * 9061 * @return {Function} The shortcut function. 9062 * 9063 * @static 9064 * 9065 * @example 9066 * 9067 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 9068 */ 9069 _createHmacHelper: function (hasher) { 9070 return function (message, key) { 9071 return new C_algo.HMAC.init(hasher, key).finalize(message); 9072 }; 9073 } 9074 }); 9075 9076 /** 9077 * Algorithm namespace. 9078 */ 9079 var C_algo = C.algo = {}; 9080 9081 return C; 9082 }(Math)); 9083 9084 9085 return CryptoJS; 9086 9087 })); 9088 },{}],54:[function(require,module,exports){ 9089 ;(function (root, factory) { 9090 if (typeof exports === "object") { 9091 // CommonJS 9092 module.exports = exports = factory(require("./core")); 9093 } 9094 else if (typeof define === "function" && define.amd) { 9095 // AMD 9096 define(["./core"], factory); 9097 } 9098 else { 9099 // Global (browser) 9100 factory(root.CryptoJS); 9101 } 9102 }(this, function (CryptoJS) { 9103 9104 (function () { 9105 // Shortcuts 9106 var C = CryptoJS; 9107 var C_lib = C.lib; 9108 var WordArray = C_lib.WordArray; 9109 var C_enc = C.enc; 9110 9111 /** 9112 * Base64 encoding strategy. 9113 */ 9114 var Base64 = C_enc.Base64 = { 9115 /** 9116 * Converts a word array to a Base64 string. 9117 * 9118 * @param {WordArray} wordArray The word array. 9119 * 9120 * @return {string} The Base64 string. 9121 * 9122 * @static 9123 * 9124 * @example 9125 * 9126 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 9127 */ 9128 stringify: function (wordArray) { 9129 // Shortcuts 9130 var words = wordArray.words; 9131 var sigBytes = wordArray.sigBytes; 9132 var map = this._map; 9133 9134 // Clamp excess bits 9135 wordArray.clamp(); 9136 9137 // Convert 9138 var base64Chars = []; 9139 for (var i = 0; i < sigBytes; i += 3) { 9140 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 9141 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 9142 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 9143 9144 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 9145 9146 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 9147 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 9148 } 9149 } 9150 9151 // Add padding 9152 var paddingChar = map.charAt(64); 9153 if (paddingChar) { 9154 while (base64Chars.length % 4) { 9155 base64Chars.push(paddingChar); 9156 } 9157 } 9158 9159 return base64Chars.join(''); 9160 }, 9161 9162 /** 9163 * Converts a Base64 string to a word array. 9164 * 9165 * @param {string} base64Str The Base64 string. 9166 * 9167 * @return {WordArray} The word array. 9168 * 9169 * @static 9170 * 9171 * @example 9172 * 9173 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 9174 */ 9175 parse: function (base64Str) { 9176 // Shortcuts 9177 var base64StrLength = base64Str.length; 9178 var map = this._map; 9179 var reverseMap = this._reverseMap; 9180 9181 if (!reverseMap) { 9182 reverseMap = this._reverseMap = []; 9183 for (var j = 0; j < map.length; j++) { 9184 reverseMap[map.charCodeAt(j)] = j; 9185 } 9186 } 9187 9188 // Ignore padding 9189 var paddingChar = map.charAt(64); 9190 if (paddingChar) { 9191 var paddingIndex = base64Str.indexOf(paddingChar); 9192 if (paddingIndex !== -1) { 9193 base64StrLength = paddingIndex; 9194 } 9195 } 9196 9197 // Convert 9198 return parseLoop(base64Str, base64StrLength, reverseMap); 9199 9200 }, 9201 9202 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 9203 }; 9204 9205 function parseLoop(base64Str, base64StrLength, reverseMap) { 9206 var words = []; 9207 var nBytes = 0; 9208 for (var i = 0; i < base64StrLength; i++) { 9209 if (i % 4) { 9210 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 9211 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 9212 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 9213 nBytes++; 9214 } 9215 } 9216 return WordArray.create(words, nBytes); 9217 } 9218 }()); 9219 9220 9221 return CryptoJS.enc.Base64; 9222 9223 })); 9224 },{"./core":53}],55:[function(require,module,exports){ 9225 ;(function (root, factory) { 9226 if (typeof exports === "object") { 9227 // CommonJS 9228 module.exports = exports = factory(require("./core")); 9229 } 9230 else if (typeof define === "function" && define.amd) { 9231 // AMD 9232 define(["./core"], factory); 9233 } 9234 else { 9235 // Global (browser) 9236 factory(root.CryptoJS); 9237 } 9238 }(this, function (CryptoJS) { 9239 9240 (function () { 9241 // Shortcuts 9242 var C = CryptoJS; 9243 var C_lib = C.lib; 9244 var WordArray = C_lib.WordArray; 9245 var C_enc = C.enc; 9246 9247 /** 9248 * UTF-16 BE encoding strategy. 9249 */ 9250 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 9251 /** 9252 * Converts a word array to a UTF-16 BE string. 9253 * 9254 * @param {WordArray} wordArray The word array. 9255 * 9256 * @return {string} The UTF-16 BE string. 9257 * 9258 * @static 9259 * 9260 * @example 9261 * 9262 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 9263 */ 9264 stringify: function (wordArray) { 9265 // Shortcuts 9266 var words = wordArray.words; 9267 var sigBytes = wordArray.sigBytes; 9268 9269 // Convert 9270 var utf16Chars = []; 9271 for (var i = 0; i < sigBytes; i += 2) { 9272 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 9273 utf16Chars.push(String.fromCharCode(codePoint)); 9274 } 9275 9276 return utf16Chars.join(''); 9277 }, 9278 9279 /** 9280 * Converts a UTF-16 BE string to a word array. 9281 * 9282 * @param {string} utf16Str The UTF-16 BE string. 9283 * 9284 * @return {WordArray} The word array. 9285 * 9286 * @static 9287 * 9288 * @example 9289 * 9290 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 9291 */ 9292 parse: function (utf16Str) { 9293 // Shortcut 9294 var utf16StrLength = utf16Str.length; 9295 9296 // Convert 9297 var words = []; 9298 for (var i = 0; i < utf16StrLength; i++) { 9299 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 9300 } 9301 9302 return WordArray.create(words, utf16StrLength * 2); 9303 } 9304 }; 9305 9306 /** 9307 * UTF-16 LE encoding strategy. 9308 */ 9309 C_enc.Utf16LE = { 9310 /** 9311 * Converts a word array to a UTF-16 LE string. 9312 * 9313 * @param {WordArray} wordArray The word array. 9314 * 9315 * @return {string} The UTF-16 LE string. 9316 * 9317 * @static 9318 * 9319 * @example 9320 * 9321 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 9322 */ 9323 stringify: function (wordArray) { 9324 // Shortcuts 9325 var words = wordArray.words; 9326 var sigBytes = wordArray.sigBytes; 9327 9328 // Convert 9329 var utf16Chars = []; 9330 for (var i = 0; i < sigBytes; i += 2) { 9331 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 9332 utf16Chars.push(String.fromCharCode(codePoint)); 9333 } 9334 9335 return utf16Chars.join(''); 9336 }, 9337 9338 /** 9339 * Converts a UTF-16 LE string to a word array. 9340 * 9341 * @param {string} utf16Str The UTF-16 LE string. 9342 * 9343 * @return {WordArray} The word array. 9344 * 9345 * @static 9346 * 9347 * @example 9348 * 9349 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 9350 */ 9351 parse: function (utf16Str) { 9352 // Shortcut 9353 var utf16StrLength = utf16Str.length; 9354 9355 // Convert 9356 var words = []; 9357 for (var i = 0; i < utf16StrLength; i++) { 9358 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 9359 } 9360 9361 return WordArray.create(words, utf16StrLength * 2); 9362 } 9363 }; 9364 9365 function swapEndian(word) { 9366 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 9367 } 9368 }()); 9369 9370 9371 return CryptoJS.enc.Utf16; 9372 9373 })); 9374 },{"./core":53}],56:[function(require,module,exports){ 9375 ;(function (root, factory, undef) { 9376 if (typeof exports === "object") { 9377 // CommonJS 9378 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 9379 } 9380 else if (typeof define === "function" && define.amd) { 9381 // AMD 9382 define(["./core", "./sha1", "./hmac"], factory); 9383 } 9384 else { 9385 // Global (browser) 9386 factory(root.CryptoJS); 9387 } 9388 }(this, function (CryptoJS) { 9389 9390 (function () { 9391 // Shortcuts 9392 var C = CryptoJS; 9393 var C_lib = C.lib; 9394 var Base = C_lib.Base; 9395 var WordArray = C_lib.WordArray; 9396 var C_algo = C.algo; 9397 var MD5 = C_algo.MD5; 9398 9399 /** 9400 * This key derivation function is meant to conform with EVP_BytesToKey. 9401 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 9402 */ 9403 var EvpKDF = C_algo.EvpKDF = Base.extend({ 9404 /** 9405 * Configuration options. 9406 * 9407 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9408 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 9409 * @property {number} iterations The number of iterations to perform. Default: 1 9410 */ 9411 cfg: Base.extend({ 9412 keySize: 128/32, 9413 hasher: MD5, 9414 iterations: 1 9415 }), 9416 9417 /** 9418 * Initializes a newly created key derivation function. 9419 * 9420 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9421 * 9422 * @example 9423 * 9424 * var kdf = CryptoJS.algo.EvpKDF.create(); 9425 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9426 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9427 */ 9428 init: function (cfg) { 9429 this.cfg = this.cfg.extend(cfg); 9430 }, 9431 9432 /** 9433 * Derives a key from a password. 9434 * 9435 * @param {WordArray|string} password The password. 9436 * @param {WordArray|string} salt A salt. 9437 * 9438 * @return {WordArray} The derived key. 9439 * 9440 * @example 9441 * 9442 * var key = kdf.compute(password, salt); 9443 */ 9444 compute: function (password, salt) { 9445 // Shortcut 9446 var cfg = this.cfg; 9447 9448 // Init hasher 9449 var hasher = cfg.hasher.create(); 9450 9451 // Initial values 9452 var derivedKey = WordArray.create(); 9453 9454 // Shortcuts 9455 var derivedKeyWords = derivedKey.words; 9456 var keySize = cfg.keySize; 9457 var iterations = cfg.iterations; 9458 9459 // Generate key 9460 while (derivedKeyWords.length < keySize) { 9461 if (block) { 9462 hasher.update(block); 9463 } 9464 var block = hasher.update(password).finalize(salt); 9465 hasher.reset(); 9466 9467 // Iterations 9468 for (var i = 1; i < iterations; i++) { 9469 block = hasher.finalize(block); 9470 hasher.reset(); 9471 } 9472 9473 derivedKey.concat(block); 9474 } 9475 derivedKey.sigBytes = keySize * 4; 9476 9477 return derivedKey; 9478 } 9479 }); 9480 9481 /** 9482 * Derives a key from a password. 9483 * 9484 * @param {WordArray|string} password The password. 9485 * @param {WordArray|string} salt A salt. 9486 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9487 * 9488 * @return {WordArray} The derived key. 9489 * 9490 * @static 9491 * 9492 * @example 9493 * 9494 * var key = CryptoJS.EvpKDF(password, salt); 9495 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9496 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9497 */ 9498 C.EvpKDF = function (password, salt, cfg) { 9499 return EvpKDF.create(cfg).compute(password, salt); 9500 }; 9501 }()); 9502 9503 9504 return CryptoJS.EvpKDF; 9505 9506 })); 9507 },{"./core":53,"./hmac":58,"./sha1":77}],57:[function(require,module,exports){ 9508 ;(function (root, factory, undef) { 9509 if (typeof exports === "object") { 9510 // CommonJS 9511 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9512 } 9513 else if (typeof define === "function" && define.amd) { 9514 // AMD 9515 define(["./core", "./cipher-core"], factory); 9516 } 9517 else { 9518 // Global (browser) 9519 factory(root.CryptoJS); 9520 } 9521 }(this, function (CryptoJS) { 9522 9523 (function (undefined) { 9524 // Shortcuts 9525 var C = CryptoJS; 9526 var C_lib = C.lib; 9527 var CipherParams = C_lib.CipherParams; 9528 var C_enc = C.enc; 9529 var Hex = C_enc.Hex; 9530 var C_format = C.format; 9531 9532 var HexFormatter = C_format.Hex = { 9533 /** 9534 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9535 * 9536 * @param {CipherParams} cipherParams The cipher params object. 9537 * 9538 * @return {string} The hexadecimally encoded string. 9539 * 9540 * @static 9541 * 9542 * @example 9543 * 9544 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9545 */ 9546 stringify: function (cipherParams) { 9547 return cipherParams.ciphertext.toString(Hex); 9548 }, 9549 9550 /** 9551 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9552 * 9553 * @param {string} input The hexadecimally encoded string. 9554 * 9555 * @return {CipherParams} The cipher params object. 9556 * 9557 * @static 9558 * 9559 * @example 9560 * 9561 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9562 */ 9563 parse: function (input) { 9564 var ciphertext = Hex.parse(input); 9565 return CipherParams.create({ ciphertext: ciphertext }); 9566 } 9567 }; 9568 }()); 9569 9570 9571 return CryptoJS.format.Hex; 9572 9573 })); 9574 },{"./cipher-core":52,"./core":53}],58:[function(require,module,exports){ 9575 ;(function (root, factory) { 9576 if (typeof exports === "object") { 9577 // CommonJS 9578 module.exports = exports = factory(require("./core")); 9579 } 9580 else if (typeof define === "function" && define.amd) { 9581 // AMD 9582 define(["./core"], factory); 9583 } 9584 else { 9585 // Global (browser) 9586 factory(root.CryptoJS); 9587 } 9588 }(this, function (CryptoJS) { 9589 9590 (function () { 9591 // Shortcuts 9592 var C = CryptoJS; 9593 var C_lib = C.lib; 9594 var Base = C_lib.Base; 9595 var C_enc = C.enc; 9596 var Utf8 = C_enc.Utf8; 9597 var C_algo = C.algo; 9598 9599 /** 9600 * HMAC algorithm. 9601 */ 9602 var HMAC = C_algo.HMAC = Base.extend({ 9603 /** 9604 * Initializes a newly created HMAC. 9605 * 9606 * @param {Hasher} hasher The hash algorithm to use. 9607 * @param {WordArray|string} key The secret key. 9608 * 9609 * @example 9610 * 9611 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9612 */ 9613 init: function (hasher, key) { 9614 // Init hasher 9615 hasher = this._hasher = new hasher.init(); 9616 9617 // Convert string to WordArray, else assume WordArray already 9618 if (typeof key == 'string') { 9619 key = Utf8.parse(key); 9620 } 9621 9622 // Shortcuts 9623 var hasherBlockSize = hasher.blockSize; 9624 var hasherBlockSizeBytes = hasherBlockSize * 4; 9625 9626 // Allow arbitrary length keys 9627 if (key.sigBytes > hasherBlockSizeBytes) { 9628 key = hasher.finalize(key); 9629 } 9630 9631 // Clamp excess bits 9632 key.clamp(); 9633 9634 // Clone key for inner and outer pads 9635 var oKey = this._oKey = key.clone(); 9636 var iKey = this._iKey = key.clone(); 9637 9638 // Shortcuts 9639 var oKeyWords = oKey.words; 9640 var iKeyWords = iKey.words; 9641 9642 // XOR keys with pad constants 9643 for (var i = 0; i < hasherBlockSize; i++) { 9644 oKeyWords[i] ^= 0x5c5c5c5c; 9645 iKeyWords[i] ^= 0x36363636; 9646 } 9647 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9648 9649 // Set initial values 9650 this.reset(); 9651 }, 9652 9653 /** 9654 * Resets this HMAC to its initial state. 9655 * 9656 * @example 9657 * 9658 * hmacHasher.reset(); 9659 */ 9660 reset: function () { 9661 // Shortcut 9662 var hasher = this._hasher; 9663 9664 // Reset 9665 hasher.reset(); 9666 hasher.update(this._iKey); 9667 }, 9668 9669 /** 9670 * Updates this HMAC with a message. 9671 * 9672 * @param {WordArray|string} messageUpdate The message to append. 9673 * 9674 * @return {HMAC} This HMAC instance. 9675 * 9676 * @example 9677 * 9678 * hmacHasher.update('message'); 9679 * hmacHasher.update(wordArray); 9680 */ 9681 update: function (messageUpdate) { 9682 this._hasher.update(messageUpdate); 9683 9684 // Chainable 9685 return this; 9686 }, 9687 9688 /** 9689 * Finalizes the HMAC computation. 9690 * Note that the finalize operation is effectively a destructive, read-once operation. 9691 * 9692 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9693 * 9694 * @return {WordArray} The HMAC. 9695 * 9696 * @example 9697 * 9698 * var hmac = hmacHasher.finalize(); 9699 * var hmac = hmacHasher.finalize('message'); 9700 * var hmac = hmacHasher.finalize(wordArray); 9701 */ 9702 finalize: function (messageUpdate) { 9703 // Shortcut 9704 var hasher = this._hasher; 9705 9706 // Compute HMAC 9707 var innerHash = hasher.finalize(messageUpdate); 9708 hasher.reset(); 9709 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9710 9711 return hmac; 9712 } 9713 }); 9714 }()); 9715 9716 9717 })); 9718 },{"./core":53}],59:[function(require,module,exports){ 9719 ;(function (root, factory, undef) { 9720 if (typeof exports === "object") { 9721 // CommonJS 9722 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")); 9723 } 9724 else if (typeof define === "function" && define.amd) { 9725 // AMD 9726 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); 9727 } 9728 else { 9729 // Global (browser) 9730 root.CryptoJS = factory(root.CryptoJS); 9731 } 9732 }(this, function (CryptoJS) { 9733 9734 return CryptoJS; 9735 9736 })); 9737 },{"./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){ 9738 ;(function (root, factory) { 9739 if (typeof exports === "object") { 9740 // CommonJS 9741 module.exports = exports = factory(require("./core")); 9742 } 9743 else if (typeof define === "function" && define.amd) { 9744 // AMD 9745 define(["./core"], factory); 9746 } 9747 else { 9748 // Global (browser) 9749 factory(root.CryptoJS); 9750 } 9751 }(this, function (CryptoJS) { 9752 9753 (function () { 9754 // Check if typed arrays are supported 9755 if (typeof ArrayBuffer != 'function') { 9756 return; 9757 } 9758 9759 // Shortcuts 9760 var C = CryptoJS; 9761 var C_lib = C.lib; 9762 var WordArray = C_lib.WordArray; 9763 9764 // Reference original init 9765 var superInit = WordArray.init; 9766 9767 // Augment WordArray.init to handle typed arrays 9768 var subInit = WordArray.init = function (typedArray) { 9769 // Convert buffers to uint8 9770 if (typedArray instanceof ArrayBuffer) { 9771 typedArray = new Uint8Array(typedArray); 9772 } 9773 9774 // Convert other array views to uint8 9775 if ( 9776 typedArray instanceof Int8Array || 9777 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9778 typedArray instanceof Int16Array || 9779 typedArray instanceof Uint16Array || 9780 typedArray instanceof Int32Array || 9781 typedArray instanceof Uint32Array || 9782 typedArray instanceof Float32Array || 9783 typedArray instanceof Float64Array 9784 ) { 9785 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9786 } 9787 9788 // Handle Uint8Array 9789 if (typedArray instanceof Uint8Array) { 9790 // Shortcut 9791 var typedArrayByteLength = typedArray.byteLength; 9792 9793 // Extract bytes 9794 var words = []; 9795 for (var i = 0; i < typedArrayByteLength; i++) { 9796 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9797 } 9798 9799 // Initialize this word array 9800 superInit.call(this, words, typedArrayByteLength); 9801 } else { 9802 // Else call normal init 9803 superInit.apply(this, arguments); 9804 } 9805 }; 9806 9807 subInit.prototype = WordArray; 9808 }()); 9809 9810 9811 return CryptoJS.lib.WordArray; 9812 9813 })); 9814 },{"./core":53}],61:[function(require,module,exports){ 9815 ;(function (root, factory) { 9816 if (typeof exports === "object") { 9817 // CommonJS 9818 module.exports = exports = factory(require("./core")); 9819 } 9820 else if (typeof define === "function" && define.amd) { 9821 // AMD 9822 define(["./core"], factory); 9823 } 9824 else { 9825 // Global (browser) 9826 factory(root.CryptoJS); 9827 } 9828 }(this, function (CryptoJS) { 9829 9830 (function (Math) { 9831 // Shortcuts 9832 var C = CryptoJS; 9833 var C_lib = C.lib; 9834 var WordArray = C_lib.WordArray; 9835 var Hasher = C_lib.Hasher; 9836 var C_algo = C.algo; 9837 9838 // Constants table 9839 var T = []; 9840 9841 // Compute constants 9842 (function () { 9843 for (var i = 0; i < 64; i++) { 9844 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9845 } 9846 }()); 9847 9848 /** 9849 * MD5 hash algorithm. 9850 */ 9851 var MD5 = C_algo.MD5 = Hasher.extend({ 9852 _doReset: function () { 9853 this._hash = new WordArray.init([ 9854 0x67452301, 0xefcdab89, 9855 0x98badcfe, 0x10325476 9856 ]); 9857 }, 9858 9859 _doProcessBlock: function (M, offset) { 9860 // Swap endian 9861 for (var i = 0; i < 16; i++) { 9862 // Shortcuts 9863 var offset_i = offset + i; 9864 var M_offset_i = M[offset_i]; 9865 9866 M[offset_i] = ( 9867 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9868 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9869 ); 9870 } 9871 9872 // Shortcuts 9873 var H = this._hash.words; 9874 9875 var M_offset_0 = M[offset + 0]; 9876 var M_offset_1 = M[offset + 1]; 9877 var M_offset_2 = M[offset + 2]; 9878 var M_offset_3 = M[offset + 3]; 9879 var M_offset_4 = M[offset + 4]; 9880 var M_offset_5 = M[offset + 5]; 9881 var M_offset_6 = M[offset + 6]; 9882 var M_offset_7 = M[offset + 7]; 9883 var M_offset_8 = M[offset + 8]; 9884 var M_offset_9 = M[offset + 9]; 9885 var M_offset_10 = M[offset + 10]; 9886 var M_offset_11 = M[offset + 11]; 9887 var M_offset_12 = M[offset + 12]; 9888 var M_offset_13 = M[offset + 13]; 9889 var M_offset_14 = M[offset + 14]; 9890 var M_offset_15 = M[offset + 15]; 9891 9892 // Working varialbes 9893 var a = H[0]; 9894 var b = H[1]; 9895 var c = H[2]; 9896 var d = H[3]; 9897 9898 // Computation 9899 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9900 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9901 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9902 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9903 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9904 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9905 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9906 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9907 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9908 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9909 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9910 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9911 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9912 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9913 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9914 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9915 9916 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9917 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9918 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9919 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9920 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9921 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9922 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9923 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9924 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9925 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9926 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9927 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9928 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9929 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9930 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9931 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9932 9933 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9934 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9935 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9936 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9937 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9938 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9939 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9940 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9941 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9942 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9943 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9944 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9945 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9946 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9947 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9948 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9949 9950 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9951 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9952 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9953 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9954 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9955 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9956 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9957 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9958 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9959 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9960 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9961 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9962 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9963 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9964 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9965 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9966 9967 // Intermediate hash value 9968 H[0] = (H[0] + a) | 0; 9969 H[1] = (H[1] + b) | 0; 9970 H[2] = (H[2] + c) | 0; 9971 H[3] = (H[3] + d) | 0; 9972 }, 9973 9974 _doFinalize: function () { 9975 // Shortcuts 9976 var data = this._data; 9977 var dataWords = data.words; 9978 9979 var nBitsTotal = this._nDataBytes * 8; 9980 var nBitsLeft = data.sigBytes * 8; 9981 9982 // Add padding 9983 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9984 9985 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9986 var nBitsTotalL = nBitsTotal; 9987 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9988 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9989 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9990 ); 9991 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9992 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9993 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9994 ); 9995 9996 data.sigBytes = (dataWords.length + 1) * 4; 9997 9998 // Hash final blocks 9999 this._process(); 10000 10001 // Shortcuts 10002 var hash = this._hash; 10003 var H = hash.words; 10004 10005 // Swap endian 10006 for (var i = 0; i < 4; i++) { 10007 // Shortcut 10008 var H_i = H[i]; 10009 10010 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 10011 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 10012 } 10013 10014 // Return final computed hash 10015 return hash; 10016 }, 10017 10018 clone: function () { 10019 var clone = Hasher.clone.call(this); 10020 clone._hash = this._hash.clone(); 10021 10022 return clone; 10023 } 10024 }); 10025 10026 function FF(a, b, c, d, x, s, t) { 10027 var n = a + ((b & c) | (~b & d)) + x + t; 10028 return ((n << s) | (n >>> (32 - s))) + b; 10029 } 10030 10031 function GG(a, b, c, d, x, s, t) { 10032 var n = a + ((b & d) | (c & ~d)) + x + t; 10033 return ((n << s) | (n >>> (32 - s))) + b; 10034 } 10035 10036 function HH(a, b, c, d, x, s, t) { 10037 var n = a + (b ^ c ^ d) + x + t; 10038 return ((n << s) | (n >>> (32 - s))) + b; 10039 } 10040 10041 function II(a, b, c, d, x, s, t) { 10042 var n = a + (c ^ (b | ~d)) + x + t; 10043 return ((n << s) | (n >>> (32 - s))) + b; 10044 } 10045 10046 /** 10047 * Shortcut function to the hasher's object interface. 10048 * 10049 * @param {WordArray|string} message The message to hash. 10050 * 10051 * @return {WordArray} The hash. 10052 * 10053 * @static 10054 * 10055 * @example 10056 * 10057 * var hash = CryptoJS.MD5('message'); 10058 * var hash = CryptoJS.MD5(wordArray); 10059 */ 10060 C.MD5 = Hasher._createHelper(MD5); 10061 10062 /** 10063 * Shortcut function to the HMAC's object interface. 10064 * 10065 * @param {WordArray|string} message The message to hash. 10066 * @param {WordArray|string} key The secret key. 10067 * 10068 * @return {WordArray} The HMAC. 10069 * 10070 * @static 10071 * 10072 * @example 10073 * 10074 * var hmac = CryptoJS.HmacMD5(message, key); 10075 */ 10076 C.HmacMD5 = Hasher._createHmacHelper(MD5); 10077 }(Math)); 10078 10079 10080 return CryptoJS.MD5; 10081 10082 })); 10083 },{"./core":53}],62:[function(require,module,exports){ 10084 ;(function (root, factory, undef) { 10085 if (typeof exports === "object") { 10086 // CommonJS 10087 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10088 } 10089 else if (typeof define === "function" && define.amd) { 10090 // AMD 10091 define(["./core", "./cipher-core"], factory); 10092 } 10093 else { 10094 // Global (browser) 10095 factory(root.CryptoJS); 10096 } 10097 }(this, function (CryptoJS) { 10098 10099 /** 10100 * Cipher Feedback block mode. 10101 */ 10102 CryptoJS.mode.CFB = (function () { 10103 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 10104 10105 CFB.Encryptor = CFB.extend({ 10106 processBlock: function (words, offset) { 10107 // Shortcuts 10108 var cipher = this._cipher; 10109 var blockSize = cipher.blockSize; 10110 10111 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 10112 10113 // Remember this block to use with next block 10114 this._prevBlock = words.slice(offset, offset + blockSize); 10115 } 10116 }); 10117 10118 CFB.Decryptor = CFB.extend({ 10119 processBlock: function (words, offset) { 10120 // Shortcuts 10121 var cipher = this._cipher; 10122 var blockSize = cipher.blockSize; 10123 10124 // Remember this block to use with next block 10125 var thisBlock = words.slice(offset, offset + blockSize); 10126 10127 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 10128 10129 // This block becomes the previous block 10130 this._prevBlock = thisBlock; 10131 } 10132 }); 10133 10134 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 10135 // Shortcut 10136 var iv = this._iv; 10137 10138 // Generate keystream 10139 if (iv) { 10140 var keystream = iv.slice(0); 10141 10142 // Remove IV for subsequent blocks 10143 this._iv = undefined; 10144 } else { 10145 var keystream = this._prevBlock; 10146 } 10147 cipher.encryptBlock(keystream, 0); 10148 10149 // Encrypt 10150 for (var i = 0; i < blockSize; i++) { 10151 words[offset + i] ^= keystream[i]; 10152 } 10153 } 10154 10155 return CFB; 10156 }()); 10157 10158 10159 return CryptoJS.mode.CFB; 10160 10161 })); 10162 },{"./cipher-core":52,"./core":53}],63:[function(require,module,exports){ 10163 ;(function (root, factory, undef) { 10164 if (typeof exports === "object") { 10165 // CommonJS 10166 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10167 } 10168 else if (typeof define === "function" && define.amd) { 10169 // AMD 10170 define(["./core", "./cipher-core"], factory); 10171 } 10172 else { 10173 // Global (browser) 10174 factory(root.CryptoJS); 10175 } 10176 }(this, function (CryptoJS) { 10177 10178 /** @preserve 10179 * Counter block mode compatible with Dr Brian Gladman fileenc.c 10180 * derived from CryptoJS.mode.CTR 10181 * Jan Hruby jhruby.web@gmail.com 10182 */ 10183 CryptoJS.mode.CTRGladman = (function () { 10184 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 10185 10186 function incWord(word) 10187 { 10188 if (((word >> 24) & 0xff) === 0xff) { //overflow 10189 var b1 = (word >> 16)&0xff; 10190 var b2 = (word >> 8)&0xff; 10191 var b3 = word & 0xff; 10192 10193 if (b1 === 0xff) // overflow b1 10194 { 10195 b1 = 0; 10196 if (b2 === 0xff) 10197 { 10198 b2 = 0; 10199 if (b3 === 0xff) 10200 { 10201 b3 = 0; 10202 } 10203 else 10204 { 10205 ++b3; 10206 } 10207 } 10208 else 10209 { 10210 ++b2; 10211 } 10212 } 10213 else 10214 { 10215 ++b1; 10216 } 10217 10218 word = 0; 10219 word += (b1 << 16); 10220 word += (b2 << 8); 10221 word += b3; 10222 } 10223 else 10224 { 10225 word += (0x01 << 24); 10226 } 10227 return word; 10228 } 10229 10230 function incCounter(counter) 10231 { 10232 if ((counter[0] = incWord(counter[0])) === 0) 10233 { 10234 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 10235 counter[1] = incWord(counter[1]); 10236 } 10237 return counter; 10238 } 10239 10240 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 10241 processBlock: function (words, offset) { 10242 // Shortcuts 10243 var cipher = this._cipher 10244 var blockSize = cipher.blockSize; 10245 var iv = this._iv; 10246 var counter = this._counter; 10247 10248 // Generate keystream 10249 if (iv) { 10250 counter = this._counter = iv.slice(0); 10251 10252 // Remove IV for subsequent blocks 10253 this._iv = undefined; 10254 } 10255 10256 incCounter(counter); 10257 10258 var keystream = counter.slice(0); 10259 cipher.encryptBlock(keystream, 0); 10260 10261 // Encrypt 10262 for (var i = 0; i < blockSize; i++) { 10263 words[offset + i] ^= keystream[i]; 10264 } 10265 } 10266 }); 10267 10268 CTRGladman.Decryptor = Encryptor; 10269 10270 return CTRGladman; 10271 }()); 10272 10273 10274 10275 10276 return CryptoJS.mode.CTRGladman; 10277 10278 })); 10279 },{"./cipher-core":52,"./core":53}],64:[function(require,module,exports){ 10280 ;(function (root, factory, undef) { 10281 if (typeof exports === "object") { 10282 // CommonJS 10283 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10284 } 10285 else if (typeof define === "function" && define.amd) { 10286 // AMD 10287 define(["./core", "./cipher-core"], factory); 10288 } 10289 else { 10290 // Global (browser) 10291 factory(root.CryptoJS); 10292 } 10293 }(this, function (CryptoJS) { 10294 10295 /** 10296 * Counter block mode. 10297 */ 10298 CryptoJS.mode.CTR = (function () { 10299 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 10300 10301 var Encryptor = CTR.Encryptor = CTR.extend({ 10302 processBlock: function (words, offset) { 10303 // Shortcuts 10304 var cipher = this._cipher 10305 var blockSize = cipher.blockSize; 10306 var iv = this._iv; 10307 var counter = this._counter; 10308 10309 // Generate keystream 10310 if (iv) { 10311 counter = this._counter = iv.slice(0); 10312 10313 // Remove IV for subsequent blocks 10314 this._iv = undefined; 10315 } 10316 var keystream = counter.slice(0); 10317 cipher.encryptBlock(keystream, 0); 10318 10319 // Increment counter 10320 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 10321 10322 // Encrypt 10323 for (var i = 0; i < blockSize; i++) { 10324 words[offset + i] ^= keystream[i]; 10325 } 10326 } 10327 }); 10328 10329 CTR.Decryptor = Encryptor; 10330 10331 return CTR; 10332 }()); 10333 10334 10335 return CryptoJS.mode.CTR; 10336 10337 })); 10338 },{"./cipher-core":52,"./core":53}],65:[function(require,module,exports){ 10339 ;(function (root, factory, undef) { 10340 if (typeof exports === "object") { 10341 // CommonJS 10342 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10343 } 10344 else if (typeof define === "function" && define.amd) { 10345 // AMD 10346 define(["./core", "./cipher-core"], factory); 10347 } 10348 else { 10349 // Global (browser) 10350 factory(root.CryptoJS); 10351 } 10352 }(this, function (CryptoJS) { 10353 10354 /** 10355 * Electronic Codebook block mode. 10356 */ 10357 CryptoJS.mode.ECB = (function () { 10358 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 10359 10360 ECB.Encryptor = ECB.extend({ 10361 processBlock: function (words, offset) { 10362 this._cipher.encryptBlock(words, offset); 10363 } 10364 }); 10365 10366 ECB.Decryptor = ECB.extend({ 10367 processBlock: function (words, offset) { 10368 this._cipher.decryptBlock(words, offset); 10369 } 10370 }); 10371 10372 return ECB; 10373 }()); 10374 10375 10376 return CryptoJS.mode.ECB; 10377 10378 })); 10379 },{"./cipher-core":52,"./core":53}],66:[function(require,module,exports){ 10380 ;(function (root, factory, undef) { 10381 if (typeof exports === "object") { 10382 // CommonJS 10383 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10384 } 10385 else if (typeof define === "function" && define.amd) { 10386 // AMD 10387 define(["./core", "./cipher-core"], factory); 10388 } 10389 else { 10390 // Global (browser) 10391 factory(root.CryptoJS); 10392 } 10393 }(this, function (CryptoJS) { 10394 10395 /** 10396 * Output Feedback block mode. 10397 */ 10398 CryptoJS.mode.OFB = (function () { 10399 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 10400 10401 var Encryptor = OFB.Encryptor = OFB.extend({ 10402 processBlock: function (words, offset) { 10403 // Shortcuts 10404 var cipher = this._cipher 10405 var blockSize = cipher.blockSize; 10406 var iv = this._iv; 10407 var keystream = this._keystream; 10408 10409 // Generate keystream 10410 if (iv) { 10411 keystream = this._keystream = iv.slice(0); 10412 10413 // Remove IV for subsequent blocks 10414 this._iv = undefined; 10415 } 10416 cipher.encryptBlock(keystream, 0); 10417 10418 // Encrypt 10419 for (var i = 0; i < blockSize; i++) { 10420 words[offset + i] ^= keystream[i]; 10421 } 10422 } 10423 }); 10424 10425 OFB.Decryptor = Encryptor; 10426 10427 return OFB; 10428 }()); 10429 10430 10431 return CryptoJS.mode.OFB; 10432 10433 })); 10434 },{"./cipher-core":52,"./core":53}],67:[function(require,module,exports){ 10435 ;(function (root, factory, undef) { 10436 if (typeof exports === "object") { 10437 // CommonJS 10438 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10439 } 10440 else if (typeof define === "function" && define.amd) { 10441 // AMD 10442 define(["./core", "./cipher-core"], factory); 10443 } 10444 else { 10445 // Global (browser) 10446 factory(root.CryptoJS); 10447 } 10448 }(this, function (CryptoJS) { 10449 10450 /** 10451 * ANSI X.923 padding strategy. 10452 */ 10453 CryptoJS.pad.AnsiX923 = { 10454 pad: function (data, blockSize) { 10455 // Shortcuts 10456 var dataSigBytes = data.sigBytes; 10457 var blockSizeBytes = blockSize * 4; 10458 10459 // Count padding bytes 10460 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10461 10462 // Compute last byte position 10463 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10464 10465 // Pad 10466 data.clamp(); 10467 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10468 data.sigBytes += nPaddingBytes; 10469 }, 10470 10471 unpad: function (data) { 10472 // Get number of padding bytes from last byte 10473 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10474 10475 // Remove padding 10476 data.sigBytes -= nPaddingBytes; 10477 } 10478 }; 10479 10480 10481 return CryptoJS.pad.Ansix923; 10482 10483 })); 10484 },{"./cipher-core":52,"./core":53}],68:[function(require,module,exports){ 10485 ;(function (root, factory, undef) { 10486 if (typeof exports === "object") { 10487 // CommonJS 10488 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10489 } 10490 else if (typeof define === "function" && define.amd) { 10491 // AMD 10492 define(["./core", "./cipher-core"], factory); 10493 } 10494 else { 10495 // Global (browser) 10496 factory(root.CryptoJS); 10497 } 10498 }(this, function (CryptoJS) { 10499 10500 /** 10501 * ISO 10126 padding strategy. 10502 */ 10503 CryptoJS.pad.Iso10126 = { 10504 pad: function (data, blockSize) { 10505 // Shortcut 10506 var blockSizeBytes = blockSize * 4; 10507 10508 // Count padding bytes 10509 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10510 10511 // Pad 10512 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10513 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10514 }, 10515 10516 unpad: function (data) { 10517 // Get number of padding bytes from last byte 10518 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10519 10520 // Remove padding 10521 data.sigBytes -= nPaddingBytes; 10522 } 10523 }; 10524 10525 10526 return CryptoJS.pad.Iso10126; 10527 10528 })); 10529 },{"./cipher-core":52,"./core":53}],69:[function(require,module,exports){ 10530 ;(function (root, factory, undef) { 10531 if (typeof exports === "object") { 10532 // CommonJS 10533 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10534 } 10535 else if (typeof define === "function" && define.amd) { 10536 // AMD 10537 define(["./core", "./cipher-core"], factory); 10538 } 10539 else { 10540 // Global (browser) 10541 factory(root.CryptoJS); 10542 } 10543 }(this, function (CryptoJS) { 10544 10545 /** 10546 * ISO/IEC 9797-1 Padding Method 2. 10547 */ 10548 CryptoJS.pad.Iso97971 = { 10549 pad: function (data, blockSize) { 10550 // Add 0x80 byte 10551 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10552 10553 // Zero pad the rest 10554 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10555 }, 10556 10557 unpad: function (data) { 10558 // Remove zero padding 10559 CryptoJS.pad.ZeroPadding.unpad(data); 10560 10561 // Remove one more byte -- the 0x80 byte 10562 data.sigBytes--; 10563 } 10564 }; 10565 10566 10567 return CryptoJS.pad.Iso97971; 10568 10569 })); 10570 },{"./cipher-core":52,"./core":53}],70:[function(require,module,exports){ 10571 ;(function (root, factory, undef) { 10572 if (typeof exports === "object") { 10573 // CommonJS 10574 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10575 } 10576 else if (typeof define === "function" && define.amd) { 10577 // AMD 10578 define(["./core", "./cipher-core"], factory); 10579 } 10580 else { 10581 // Global (browser) 10582 factory(root.CryptoJS); 10583 } 10584 }(this, function (CryptoJS) { 10585 10586 /** 10587 * A noop padding strategy. 10588 */ 10589 CryptoJS.pad.NoPadding = { 10590 pad: function () { 10591 }, 10592 10593 unpad: function () { 10594 } 10595 }; 10596 10597 10598 return CryptoJS.pad.NoPadding; 10599 10600 })); 10601 },{"./cipher-core":52,"./core":53}],71:[function(require,module,exports){ 10602 ;(function (root, factory, undef) { 10603 if (typeof exports === "object") { 10604 // CommonJS 10605 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10606 } 10607 else if (typeof define === "function" && define.amd) { 10608 // AMD 10609 define(["./core", "./cipher-core"], factory); 10610 } 10611 else { 10612 // Global (browser) 10613 factory(root.CryptoJS); 10614 } 10615 }(this, function (CryptoJS) { 10616 10617 /** 10618 * Zero padding strategy. 10619 */ 10620 CryptoJS.pad.ZeroPadding = { 10621 pad: function (data, blockSize) { 10622 // Shortcut 10623 var blockSizeBytes = blockSize * 4; 10624 10625 // Pad 10626 data.clamp(); 10627 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10628 }, 10629 10630 unpad: function (data) { 10631 // Shortcut 10632 var dataWords = data.words; 10633 10634 // Unpad 10635 var i = data.sigBytes - 1; 10636 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10637 i--; 10638 } 10639 data.sigBytes = i + 1; 10640 } 10641 }; 10642 10643 10644 return CryptoJS.pad.ZeroPadding; 10645 10646 })); 10647 },{"./cipher-core":52,"./core":53}],72:[function(require,module,exports){ 10648 ;(function (root, factory, undef) { 10649 if (typeof exports === "object") { 10650 // CommonJS 10651 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10652 } 10653 else if (typeof define === "function" && define.amd) { 10654 // AMD 10655 define(["./core", "./sha1", "./hmac"], factory); 10656 } 10657 else { 10658 // Global (browser) 10659 factory(root.CryptoJS); 10660 } 10661 }(this, function (CryptoJS) { 10662 10663 (function () { 10664 // Shortcuts 10665 var C = CryptoJS; 10666 var C_lib = C.lib; 10667 var Base = C_lib.Base; 10668 var WordArray = C_lib.WordArray; 10669 var C_algo = C.algo; 10670 var SHA1 = C_algo.SHA1; 10671 var HMAC = C_algo.HMAC; 10672 10673 /** 10674 * Password-Based Key Derivation Function 2 algorithm. 10675 */ 10676 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10677 /** 10678 * Configuration options. 10679 * 10680 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10681 * @property {Hasher} hasher The hasher to use. Default: SHA1 10682 * @property {number} iterations The number of iterations to perform. Default: 1 10683 */ 10684 cfg: Base.extend({ 10685 keySize: 128/32, 10686 hasher: SHA1, 10687 iterations: 1 10688 }), 10689 10690 /** 10691 * Initializes a newly created key derivation function. 10692 * 10693 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10694 * 10695 * @example 10696 * 10697 * var kdf = CryptoJS.algo.PBKDF2.create(); 10698 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10699 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10700 */ 10701 init: function (cfg) { 10702 this.cfg = this.cfg.extend(cfg); 10703 }, 10704 10705 /** 10706 * Computes the Password-Based Key Derivation Function 2. 10707 * 10708 * @param {WordArray|string} password The password. 10709 * @param {WordArray|string} salt A salt. 10710 * 10711 * @return {WordArray} The derived key. 10712 * 10713 * @example 10714 * 10715 * var key = kdf.compute(password, salt); 10716 */ 10717 compute: function (password, salt) { 10718 // Shortcut 10719 var cfg = this.cfg; 10720 10721 // Init HMAC 10722 var hmac = HMAC.create(cfg.hasher, password); 10723 10724 // Initial values 10725 var derivedKey = WordArray.create(); 10726 var blockIndex = WordArray.create([0x00000001]); 10727 10728 // Shortcuts 10729 var derivedKeyWords = derivedKey.words; 10730 var blockIndexWords = blockIndex.words; 10731 var keySize = cfg.keySize; 10732 var iterations = cfg.iterations; 10733 10734 // Generate key 10735 while (derivedKeyWords.length < keySize) { 10736 var block = hmac.update(salt).finalize(blockIndex); 10737 hmac.reset(); 10738 10739 // Shortcuts 10740 var blockWords = block.words; 10741 var blockWordsLength = blockWords.length; 10742 10743 // Iterations 10744 var intermediate = block; 10745 for (var i = 1; i < iterations; i++) { 10746 intermediate = hmac.finalize(intermediate); 10747 hmac.reset(); 10748 10749 // Shortcut 10750 var intermediateWords = intermediate.words; 10751 10752 // XOR intermediate with block 10753 for (var j = 0; j < blockWordsLength; j++) { 10754 blockWords[j] ^= intermediateWords[j]; 10755 } 10756 } 10757 10758 derivedKey.concat(block); 10759 blockIndexWords[0]++; 10760 } 10761 derivedKey.sigBytes = keySize * 4; 10762 10763 return derivedKey; 10764 } 10765 }); 10766 10767 /** 10768 * Computes the Password-Based Key Derivation Function 2. 10769 * 10770 * @param {WordArray|string} password The password. 10771 * @param {WordArray|string} salt A salt. 10772 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10773 * 10774 * @return {WordArray} The derived key. 10775 * 10776 * @static 10777 * 10778 * @example 10779 * 10780 * var key = CryptoJS.PBKDF2(password, salt); 10781 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10782 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10783 */ 10784 C.PBKDF2 = function (password, salt, cfg) { 10785 return PBKDF2.create(cfg).compute(password, salt); 10786 }; 10787 }()); 10788 10789 10790 return CryptoJS.PBKDF2; 10791 10792 })); 10793 },{"./core":53,"./hmac":58,"./sha1":77}],73:[function(require,module,exports){ 10794 ;(function (root, factory, undef) { 10795 if (typeof exports === "object") { 10796 // CommonJS 10797 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10798 } 10799 else if (typeof define === "function" && define.amd) { 10800 // AMD 10801 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10802 } 10803 else { 10804 // Global (browser) 10805 factory(root.CryptoJS); 10806 } 10807 }(this, function (CryptoJS) { 10808 10809 (function () { 10810 // Shortcuts 10811 var C = CryptoJS; 10812 var C_lib = C.lib; 10813 var StreamCipher = C_lib.StreamCipher; 10814 var C_algo = C.algo; 10815 10816 // Reusable objects 10817 var S = []; 10818 var C_ = []; 10819 var G = []; 10820 10821 /** 10822 * Rabbit stream cipher algorithm. 10823 * 10824 * This is a legacy version that neglected to convert the key to little-endian. 10825 * This error doesn't affect the cipher's security, 10826 * but it does affect its compatibility with other implementations. 10827 */ 10828 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10829 _doReset: function () { 10830 // Shortcuts 10831 var K = this._key.words; 10832 var iv = this.cfg.iv; 10833 10834 // Generate initial state values 10835 var X = this._X = [ 10836 K[0], (K[3] << 16) | (K[2] >>> 16), 10837 K[1], (K[0] << 16) | (K[3] >>> 16), 10838 K[2], (K[1] << 16) | (K[0] >>> 16), 10839 K[3], (K[2] << 16) | (K[1] >>> 16) 10840 ]; 10841 10842 // Generate initial counter values 10843 var C = this._C = [ 10844 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10845 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10846 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10847 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10848 ]; 10849 10850 // Carry bit 10851 this._b = 0; 10852 10853 // Iterate the system four times 10854 for (var i = 0; i < 4; i++) { 10855 nextState.call(this); 10856 } 10857 10858 // Modify the counters 10859 for (var i = 0; i < 8; i++) { 10860 C[i] ^= X[(i + 4) & 7]; 10861 } 10862 10863 // IV setup 10864 if (iv) { 10865 // Shortcuts 10866 var IV = iv.words; 10867 var IV_0 = IV[0]; 10868 var IV_1 = IV[1]; 10869 10870 // Generate four subvectors 10871 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10872 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10873 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10874 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10875 10876 // Modify counter values 10877 C[0] ^= i0; 10878 C[1] ^= i1; 10879 C[2] ^= i2; 10880 C[3] ^= i3; 10881 C[4] ^= i0; 10882 C[5] ^= i1; 10883 C[6] ^= i2; 10884 C[7] ^= i3; 10885 10886 // Iterate the system four times 10887 for (var i = 0; i < 4; i++) { 10888 nextState.call(this); 10889 } 10890 } 10891 }, 10892 10893 _doProcessBlock: function (M, offset) { 10894 // Shortcut 10895 var X = this._X; 10896 10897 // Iterate the system 10898 nextState.call(this); 10899 10900 // Generate four keystream words 10901 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10902 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10903 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10904 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10905 10906 for (var i = 0; i < 4; i++) { 10907 // Swap endian 10908 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10909 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10910 10911 // Encrypt 10912 M[offset + i] ^= S[i]; 10913 } 10914 }, 10915 10916 blockSize: 128/32, 10917 10918 ivSize: 64/32 10919 }); 10920 10921 function nextState() { 10922 // Shortcuts 10923 var X = this._X; 10924 var C = this._C; 10925 10926 // Save old counter values 10927 for (var i = 0; i < 8; i++) { 10928 C_[i] = C[i]; 10929 } 10930 10931 // Calculate new counter values 10932 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10933 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10934 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10935 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10936 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10937 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10938 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10939 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10940 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10941 10942 // Calculate the g-values 10943 for (var i = 0; i < 8; i++) { 10944 var gx = X[i] + C[i]; 10945 10946 // Construct high and low argument for squaring 10947 var ga = gx & 0xffff; 10948 var gb = gx >>> 16; 10949 10950 // Calculate high and low result of squaring 10951 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10952 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10953 10954 // High XOR low 10955 G[i] = gh ^ gl; 10956 } 10957 10958 // Calculate new state values 10959 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10960 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10961 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10962 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10963 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10964 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10965 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10966 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10967 } 10968 10969 /** 10970 * Shortcut functions to the cipher's object interface. 10971 * 10972 * @example 10973 * 10974 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10975 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10976 */ 10977 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10978 }()); 10979 10980 10981 return CryptoJS.RabbitLegacy; 10982 10983 })); 10984 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],74:[function(require,module,exports){ 10985 ;(function (root, factory, undef) { 10986 if (typeof exports === "object") { 10987 // CommonJS 10988 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10989 } 10990 else if (typeof define === "function" && define.amd) { 10991 // AMD 10992 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10993 } 10994 else { 10995 // Global (browser) 10996 factory(root.CryptoJS); 10997 } 10998 }(this, function (CryptoJS) { 10999 11000 (function () { 11001 // Shortcuts 11002 var C = CryptoJS; 11003 var C_lib = C.lib; 11004 var StreamCipher = C_lib.StreamCipher; 11005 var C_algo = C.algo; 11006 11007 // Reusable objects 11008 var S = []; 11009 var C_ = []; 11010 var G = []; 11011 11012 /** 11013 * Rabbit stream cipher algorithm 11014 */ 11015 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 11016 _doReset: function () { 11017 // Shortcuts 11018 var K = this._key.words; 11019 var iv = this.cfg.iv; 11020 11021 // Swap endian 11022 for (var i = 0; i < 4; i++) { 11023 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 11024 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 11025 } 11026 11027 // Generate initial state values 11028 var X = this._X = [ 11029 K[0], (K[3] << 16) | (K[2] >>> 16), 11030 K[1], (K[0] << 16) | (K[3] >>> 16), 11031 K[2], (K[1] << 16) | (K[0] >>> 16), 11032 K[3], (K[2] << 16) | (K[1] >>> 16) 11033 ]; 11034 11035 // Generate initial counter values 11036 var C = this._C = [ 11037 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 11038 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 11039 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 11040 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 11041 ]; 11042 11043 // Carry bit 11044 this._b = 0; 11045 11046 // Iterate the system four times 11047 for (var i = 0; i < 4; i++) { 11048 nextState.call(this); 11049 } 11050 11051 // Modify the counters 11052 for (var i = 0; i < 8; i++) { 11053 C[i] ^= X[(i + 4) & 7]; 11054 } 11055 11056 // IV setup 11057 if (iv) { 11058 // Shortcuts 11059 var IV = iv.words; 11060 var IV_0 = IV[0]; 11061 var IV_1 = IV[1]; 11062 11063 // Generate four subvectors 11064 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 11065 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 11066 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 11067 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 11068 11069 // Modify counter values 11070 C[0] ^= i0; 11071 C[1] ^= i1; 11072 C[2] ^= i2; 11073 C[3] ^= i3; 11074 C[4] ^= i0; 11075 C[5] ^= i1; 11076 C[6] ^= i2; 11077 C[7] ^= i3; 11078 11079 // Iterate the system four times 11080 for (var i = 0; i < 4; i++) { 11081 nextState.call(this); 11082 } 11083 } 11084 }, 11085 11086 _doProcessBlock: function (M, offset) { 11087 // Shortcut 11088 var X = this._X; 11089 11090 // Iterate the system 11091 nextState.call(this); 11092 11093 // Generate four keystream words 11094 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 11095 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 11096 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 11097 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 11098 11099 for (var i = 0; i < 4; i++) { 11100 // Swap endian 11101 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 11102 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 11103 11104 // Encrypt 11105 M[offset + i] ^= S[i]; 11106 } 11107 }, 11108 11109 blockSize: 128/32, 11110 11111 ivSize: 64/32 11112 }); 11113 11114 function nextState() { 11115 // Shortcuts 11116 var X = this._X; 11117 var C = this._C; 11118 11119 // Save old counter values 11120 for (var i = 0; i < 8; i++) { 11121 C_[i] = C[i]; 11122 } 11123 11124 // Calculate new counter values 11125 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 11126 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 11127 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 11128 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 11129 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 11130 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 11131 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 11132 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 11133 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 11134 11135 // Calculate the g-values 11136 for (var i = 0; i < 8; i++) { 11137 var gx = X[i] + C[i]; 11138 11139 // Construct high and low argument for squaring 11140 var ga = gx & 0xffff; 11141 var gb = gx >>> 16; 11142 11143 // Calculate high and low result of squaring 11144 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 11145 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 11146 11147 // High XOR low 11148 G[i] = gh ^ gl; 11149 } 11150 11151 // Calculate new state values 11152 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 11153 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 11154 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 11155 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 11156 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 11157 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 11158 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 11159 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 11160 } 11161 11162 /** 11163 * Shortcut functions to the cipher's object interface. 11164 * 11165 * @example 11166 * 11167 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 11168 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 11169 */ 11170 C.Rabbit = StreamCipher._createHelper(Rabbit); 11171 }()); 11172 11173 11174 return CryptoJS.Rabbit; 11175 11176 })); 11177 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],75:[function(require,module,exports){ 11178 ;(function (root, factory, undef) { 11179 if (typeof exports === "object") { 11180 // CommonJS 11181 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 11182 } 11183 else if (typeof define === "function" && define.amd) { 11184 // AMD 11185 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 11186 } 11187 else { 11188 // Global (browser) 11189 factory(root.CryptoJS); 11190 } 11191 }(this, function (CryptoJS) { 11192 11193 (function () { 11194 // Shortcuts 11195 var C = CryptoJS; 11196 var C_lib = C.lib; 11197 var StreamCipher = C_lib.StreamCipher; 11198 var C_algo = C.algo; 11199 11200 /** 11201 * RC4 stream cipher algorithm. 11202 */ 11203 var RC4 = C_algo.RC4 = StreamCipher.extend({ 11204 _doReset: function () { 11205 // Shortcuts 11206 var key = this._key; 11207 var keyWords = key.words; 11208 var keySigBytes = key.sigBytes; 11209 11210 // Init sbox 11211 var S = this._S = []; 11212 for (var i = 0; i < 256; i++) { 11213 S[i] = i; 11214 } 11215 11216 // Key setup 11217 for (var i = 0, j = 0; i < 256; i++) { 11218 var keyByteIndex = i % keySigBytes; 11219 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 11220 11221 j = (j + S[i] + keyByte) % 256; 11222 11223 // Swap 11224 var t = S[i]; 11225 S[i] = S[j]; 11226 S[j] = t; 11227 } 11228 11229 // Counters 11230 this._i = this._j = 0; 11231 }, 11232 11233 _doProcessBlock: function (M, offset) { 11234 M[offset] ^= generateKeystreamWord.call(this); 11235 }, 11236 11237 keySize: 256/32, 11238 11239 ivSize: 0 11240 }); 11241 11242 function generateKeystreamWord() { 11243 // Shortcuts 11244 var S = this._S; 11245 var i = this._i; 11246 var j = this._j; 11247 11248 // Generate keystream word 11249 var keystreamWord = 0; 11250 for (var n = 0; n < 4; n++) { 11251 i = (i + 1) % 256; 11252 j = (j + S[i]) % 256; 11253 11254 // Swap 11255 var t = S[i]; 11256 S[i] = S[j]; 11257 S[j] = t; 11258 11259 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 11260 } 11261 11262 // Update counters 11263 this._i = i; 11264 this._j = j; 11265 11266 return keystreamWord; 11267 } 11268 11269 /** 11270 * Shortcut functions to the cipher's object interface. 11271 * 11272 * @example 11273 * 11274 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 11275 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 11276 */ 11277 C.RC4 = StreamCipher._createHelper(RC4); 11278 11279 /** 11280 * Modified RC4 stream cipher algorithm. 11281 */ 11282 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 11283 /** 11284 * Configuration options. 11285 * 11286 * @property {number} drop The number of keystream words to drop. Default 192 11287 */ 11288 cfg: RC4.cfg.extend({ 11289 drop: 192 11290 }), 11291 11292 _doReset: function () { 11293 RC4._doReset.call(this); 11294 11295 // Drop 11296 for (var i = this.cfg.drop; i > 0; i--) { 11297 generateKeystreamWord.call(this); 11298 } 11299 } 11300 }); 11301 11302 /** 11303 * Shortcut functions to the cipher's object interface. 11304 * 11305 * @example 11306 * 11307 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 11308 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 11309 */ 11310 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 11311 }()); 11312 11313 11314 return CryptoJS.RC4; 11315 11316 })); 11317 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],76:[function(require,module,exports){ 11318 ;(function (root, factory) { 11319 if (typeof exports === "object") { 11320 // CommonJS 11321 module.exports = exports = factory(require("./core")); 11322 } 11323 else if (typeof define === "function" && define.amd) { 11324 // AMD 11325 define(["./core"], factory); 11326 } 11327 else { 11328 // Global (browser) 11329 factory(root.CryptoJS); 11330 } 11331 }(this, function (CryptoJS) { 11332 11333 /** @preserve 11334 (c) 2012 by Cédric Mesnil. All rights reserved. 11335 11336 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 11337 11338 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11339 - 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. 11340 11341 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. 11342 */ 11343 11344 (function (Math) { 11345 // Shortcuts 11346 var C = CryptoJS; 11347 var C_lib = C.lib; 11348 var WordArray = C_lib.WordArray; 11349 var Hasher = C_lib.Hasher; 11350 var C_algo = C.algo; 11351 11352 // Constants table 11353 var _zl = WordArray.create([ 11354 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 11355 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 11356 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 11357 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 11358 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 11359 var _zr = WordArray.create([ 11360 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 11361 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 11362 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 11363 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 11364 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 11365 var _sl = WordArray.create([ 11366 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 11367 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11368 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11369 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 11370 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]); 11371 var _sr = WordArray.create([ 11372 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 11373 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 11374 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 11375 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 11376 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]); 11377 11378 var _hl = WordArray.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 11379 var _hr = WordArray.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 11380 11381 /** 11382 * RIPEMD160 hash algorithm. 11383 */ 11384 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 11385 _doReset: function () { 11386 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 11387 }, 11388 11389 _doProcessBlock: function (M, offset) { 11390 11391 // Swap endian 11392 for (var i = 0; i < 16; i++) { 11393 // Shortcuts 11394 var offset_i = offset + i; 11395 var M_offset_i = M[offset_i]; 11396 11397 // Swap 11398 M[offset_i] = ( 11399 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 11400 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 11401 ); 11402 } 11403 // Shortcut 11404 var H = this._hash.words; 11405 var hl = _hl.words; 11406 var hr = _hr.words; 11407 var zl = _zl.words; 11408 var zr = _zr.words; 11409 var sl = _sl.words; 11410 var sr = _sr.words; 11411 11412 // Working variables 11413 var al, bl, cl, dl, el; 11414 var ar, br, cr, dr, er; 11415 11416 ar = al = H[0]; 11417 br = bl = H[1]; 11418 cr = cl = H[2]; 11419 dr = dl = H[3]; 11420 er = el = H[4]; 11421 // Computation 11422 var t; 11423 for (var i = 0; i < 80; i += 1) { 11424 t = (al + M[offset+zl[i]])|0; 11425 if (i<16){ 11426 t += f1(bl,cl,dl) + hl[0]; 11427 } else if (i<32) { 11428 t += f2(bl,cl,dl) + hl[1]; 11429 } else if (i<48) { 11430 t += f3(bl,cl,dl) + hl[2]; 11431 } else if (i<64) { 11432 t += f4(bl,cl,dl) + hl[3]; 11433 } else {// if (i<80) { 11434 t += f5(bl,cl,dl) + hl[4]; 11435 } 11436 t = t|0; 11437 t = rotl(t,sl[i]); 11438 t = (t+el)|0; 11439 al = el; 11440 el = dl; 11441 dl = rotl(cl, 10); 11442 cl = bl; 11443 bl = t; 11444 11445 t = (ar + M[offset+zr[i]])|0; 11446 if (i<16){ 11447 t += f5(br,cr,dr) + hr[0]; 11448 } else if (i<32) { 11449 t += f4(br,cr,dr) + hr[1]; 11450 } else if (i<48) { 11451 t += f3(br,cr,dr) + hr[2]; 11452 } else if (i<64) { 11453 t += f2(br,cr,dr) + hr[3]; 11454 } else {// if (i<80) { 11455 t += f1(br,cr,dr) + hr[4]; 11456 } 11457 t = t|0; 11458 t = rotl(t,sr[i]) ; 11459 t = (t+er)|0; 11460 ar = er; 11461 er = dr; 11462 dr = rotl(cr, 10); 11463 cr = br; 11464 br = t; 11465 } 11466 // Intermediate hash value 11467 t = (H[1] + cl + dr)|0; 11468 H[1] = (H[2] + dl + er)|0; 11469 H[2] = (H[3] + el + ar)|0; 11470 H[3] = (H[4] + al + br)|0; 11471 H[4] = (H[0] + bl + cr)|0; 11472 H[0] = t; 11473 }, 11474 11475 _doFinalize: function () { 11476 // Shortcuts 11477 var data = this._data; 11478 var dataWords = data.words; 11479 11480 var nBitsTotal = this._nDataBytes * 8; 11481 var nBitsLeft = data.sigBytes * 8; 11482 11483 // Add padding 11484 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11485 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11486 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11487 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11488 ); 11489 data.sigBytes = (dataWords.length + 1) * 4; 11490 11491 // Hash final blocks 11492 this._process(); 11493 11494 // Shortcuts 11495 var hash = this._hash; 11496 var H = hash.words; 11497 11498 // Swap endian 11499 for (var i = 0; i < 5; i++) { 11500 // Shortcut 11501 var H_i = H[i]; 11502 11503 // Swap 11504 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11505 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11506 } 11507 11508 // Return final computed hash 11509 return hash; 11510 }, 11511 11512 clone: function () { 11513 var clone = Hasher.clone.call(this); 11514 clone._hash = this._hash.clone(); 11515 11516 return clone; 11517 } 11518 }); 11519 11520 11521 function f1(x, y, z) { 11522 return ((x) ^ (y) ^ (z)); 11523 11524 } 11525 11526 function f2(x, y, z) { 11527 return (((x)&(y)) | ((~x)&(z))); 11528 } 11529 11530 function f3(x, y, z) { 11531 return (((x) | (~(y))) ^ (z)); 11532 } 11533 11534 function f4(x, y, z) { 11535 return (((x) & (z)) | ((y)&(~(z)))); 11536 } 11537 11538 function f5(x, y, z) { 11539 return ((x) ^ ((y) |(~(z)))); 11540 11541 } 11542 11543 function rotl(x,n) { 11544 return (x<<n) | (x>>>(32-n)); 11545 } 11546 11547 11548 /** 11549 * Shortcut function to the hasher's object interface. 11550 * 11551 * @param {WordArray|string} message The message to hash. 11552 * 11553 * @return {WordArray} The hash. 11554 * 11555 * @static 11556 * 11557 * @example 11558 * 11559 * var hash = CryptoJS.RIPEMD160('message'); 11560 * var hash = CryptoJS.RIPEMD160(wordArray); 11561 */ 11562 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11563 11564 /** 11565 * Shortcut function to the HMAC's object interface. 11566 * 11567 * @param {WordArray|string} message The message to hash. 11568 * @param {WordArray|string} key The secret key. 11569 * 11570 * @return {WordArray} The HMAC. 11571 * 11572 * @static 11573 * 11574 * @example 11575 * 11576 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11577 */ 11578 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11579 }(Math)); 11580 11581 11582 return CryptoJS.RIPEMD160; 11583 11584 })); 11585 },{"./core":53}],77:[function(require,module,exports){ 11586 ;(function (root, factory) { 11587 if (typeof exports === "object") { 11588 // CommonJS 11589 module.exports = exports = factory(require("./core")); 11590 } 11591 else if (typeof define === "function" && define.amd) { 11592 // AMD 11593 define(["./core"], factory); 11594 } 11595 else { 11596 // Global (browser) 11597 factory(root.CryptoJS); 11598 } 11599 }(this, function (CryptoJS) { 11600 11601 (function () { 11602 // Shortcuts 11603 var C = CryptoJS; 11604 var C_lib = C.lib; 11605 var WordArray = C_lib.WordArray; 11606 var Hasher = C_lib.Hasher; 11607 var C_algo = C.algo; 11608 11609 // Reusable object 11610 var W = []; 11611 11612 /** 11613 * SHA-1 hash algorithm. 11614 */ 11615 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11616 _doReset: function () { 11617 this._hash = new WordArray.init([ 11618 0x67452301, 0xefcdab89, 11619 0x98badcfe, 0x10325476, 11620 0xc3d2e1f0 11621 ]); 11622 }, 11623 11624 _doProcessBlock: function (M, offset) { 11625 // Shortcut 11626 var H = this._hash.words; 11627 11628 // Working variables 11629 var a = H[0]; 11630 var b = H[1]; 11631 var c = H[2]; 11632 var d = H[3]; 11633 var e = H[4]; 11634 11635 // Computation 11636 for (var i = 0; i < 80; i++) { 11637 if (i < 16) { 11638 W[i] = M[offset + i] | 0; 11639 } else { 11640 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11641 W[i] = (n << 1) | (n >>> 31); 11642 } 11643 11644 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11645 if (i < 20) { 11646 t += ((b & c) | (~b & d)) + 0x5a827999; 11647 } else if (i < 40) { 11648 t += (b ^ c ^ d) + 0x6ed9eba1; 11649 } else if (i < 60) { 11650 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11651 } else /* if (i < 80) */ { 11652 t += (b ^ c ^ d) - 0x359d3e2a; 11653 } 11654 11655 e = d; 11656 d = c; 11657 c = (b << 30) | (b >>> 2); 11658 b = a; 11659 a = t; 11660 } 11661 11662 // Intermediate hash value 11663 H[0] = (H[0] + a) | 0; 11664 H[1] = (H[1] + b) | 0; 11665 H[2] = (H[2] + c) | 0; 11666 H[3] = (H[3] + d) | 0; 11667 H[4] = (H[4] + e) | 0; 11668 }, 11669 11670 _doFinalize: function () { 11671 // Shortcuts 11672 var data = this._data; 11673 var dataWords = data.words; 11674 11675 var nBitsTotal = this._nDataBytes * 8; 11676 var nBitsLeft = data.sigBytes * 8; 11677 11678 // Add padding 11679 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11680 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11681 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11682 data.sigBytes = dataWords.length * 4; 11683 11684 // Hash final blocks 11685 this._process(); 11686 11687 // Return final computed hash 11688 return this._hash; 11689 }, 11690 11691 clone: function () { 11692 var clone = Hasher.clone.call(this); 11693 clone._hash = this._hash.clone(); 11694 11695 return clone; 11696 } 11697 }); 11698 11699 /** 11700 * Shortcut function to the hasher's object interface. 11701 * 11702 * @param {WordArray|string} message The message to hash. 11703 * 11704 * @return {WordArray} The hash. 11705 * 11706 * @static 11707 * 11708 * @example 11709 * 11710 * var hash = CryptoJS.SHA1('message'); 11711 * var hash = CryptoJS.SHA1(wordArray); 11712 */ 11713 C.SHA1 = Hasher._createHelper(SHA1); 11714 11715 /** 11716 * Shortcut function to the HMAC's object interface. 11717 * 11718 * @param {WordArray|string} message The message to hash. 11719 * @param {WordArray|string} key The secret key. 11720 * 11721 * @return {WordArray} The HMAC. 11722 * 11723 * @static 11724 * 11725 * @example 11726 * 11727 * var hmac = CryptoJS.HmacSHA1(message, key); 11728 */ 11729 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11730 }()); 11731 11732 11733 return CryptoJS.SHA1; 11734 11735 })); 11736 },{"./core":53}],78:[function(require,module,exports){ 11737 ;(function (root, factory, undef) { 11738 if (typeof exports === "object") { 11739 // CommonJS 11740 module.exports = exports = factory(require("./core"), require("./sha256")); 11741 } 11742 else if (typeof define === "function" && define.amd) { 11743 // AMD 11744 define(["./core", "./sha256"], factory); 11745 } 11746 else { 11747 // Global (browser) 11748 factory(root.CryptoJS); 11749 } 11750 }(this, function (CryptoJS) { 11751 11752 (function () { 11753 // Shortcuts 11754 var C = CryptoJS; 11755 var C_lib = C.lib; 11756 var WordArray = C_lib.WordArray; 11757 var C_algo = C.algo; 11758 var SHA256 = C_algo.SHA256; 11759 11760 /** 11761 * SHA-224 hash algorithm. 11762 */ 11763 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11764 _doReset: function () { 11765 this._hash = new WordArray.init([ 11766 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11767 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11768 ]); 11769 }, 11770 11771 _doFinalize: function () { 11772 var hash = SHA256._doFinalize.call(this); 11773 11774 hash.sigBytes -= 4; 11775 11776 return hash; 11777 } 11778 }); 11779 11780 /** 11781 * Shortcut function to the hasher's object interface. 11782 * 11783 * @param {WordArray|string} message The message to hash. 11784 * 11785 * @return {WordArray} The hash. 11786 * 11787 * @static 11788 * 11789 * @example 11790 * 11791 * var hash = CryptoJS.SHA224('message'); 11792 * var hash = CryptoJS.SHA224(wordArray); 11793 */ 11794 C.SHA224 = SHA256._createHelper(SHA224); 11795 11796 /** 11797 * Shortcut function to the HMAC's object interface. 11798 * 11799 * @param {WordArray|string} message The message to hash. 11800 * @param {WordArray|string} key The secret key. 11801 * 11802 * @return {WordArray} The HMAC. 11803 * 11804 * @static 11805 * 11806 * @example 11807 * 11808 * var hmac = CryptoJS.HmacSHA224(message, key); 11809 */ 11810 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11811 }()); 11812 11813 11814 return CryptoJS.SHA224; 11815 11816 })); 11817 },{"./core":53,"./sha256":79}],79:[function(require,module,exports){ 11818 ;(function (root, factory) { 11819 if (typeof exports === "object") { 11820 // CommonJS 11821 module.exports = exports = factory(require("./core")); 11822 } 11823 else if (typeof define === "function" && define.amd) { 11824 // AMD 11825 define(["./core"], factory); 11826 } 11827 else { 11828 // Global (browser) 11829 factory(root.CryptoJS); 11830 } 11831 }(this, function (CryptoJS) { 11832 11833 (function (Math) { 11834 // Shortcuts 11835 var C = CryptoJS; 11836 var C_lib = C.lib; 11837 var WordArray = C_lib.WordArray; 11838 var Hasher = C_lib.Hasher; 11839 var C_algo = C.algo; 11840 11841 // Initialization and round constants tables 11842 var H = []; 11843 var K = []; 11844 11845 // Compute constants 11846 (function () { 11847 function isPrime(n) { 11848 var sqrtN = Math.sqrt(n); 11849 for (var factor = 2; factor <= sqrtN; factor++) { 11850 if (!(n % factor)) { 11851 return false; 11852 } 11853 } 11854 11855 return true; 11856 } 11857 11858 function getFractionalBits(n) { 11859 return ((n - (n | 0)) * 0x100000000) | 0; 11860 } 11861 11862 var n = 2; 11863 var nPrime = 0; 11864 while (nPrime < 64) { 11865 if (isPrime(n)) { 11866 if (nPrime < 8) { 11867 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11868 } 11869 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11870 11871 nPrime++; 11872 } 11873 11874 n++; 11875 } 11876 }()); 11877 11878 // Reusable object 11879 var W = []; 11880 11881 /** 11882 * SHA-256 hash algorithm. 11883 */ 11884 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11885 _doReset: function () { 11886 this._hash = new WordArray.init(H.slice(0)); 11887 }, 11888 11889 _doProcessBlock: function (M, offset) { 11890 // Shortcut 11891 var H = this._hash.words; 11892 11893 // Working variables 11894 var a = H[0]; 11895 var b = H[1]; 11896 var c = H[2]; 11897 var d = H[3]; 11898 var e = H[4]; 11899 var f = H[5]; 11900 var g = H[6]; 11901 var h = H[7]; 11902 11903 // Computation 11904 for (var i = 0; i < 64; i++) { 11905 if (i < 16) { 11906 W[i] = M[offset + i] | 0; 11907 } else { 11908 var gamma0x = W[i - 15]; 11909 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11910 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11911 (gamma0x >>> 3); 11912 11913 var gamma1x = W[i - 2]; 11914 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11915 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11916 (gamma1x >>> 10); 11917 11918 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11919 } 11920 11921 var ch = (e & f) ^ (~e & g); 11922 var maj = (a & b) ^ (a & c) ^ (b & c); 11923 11924 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11925 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11926 11927 var t1 = h + sigma1 + ch + K[i] + W[i]; 11928 var t2 = sigma0 + maj; 11929 11930 h = g; 11931 g = f; 11932 f = e; 11933 e = (d + t1) | 0; 11934 d = c; 11935 c = b; 11936 b = a; 11937 a = (t1 + t2) | 0; 11938 } 11939 11940 // Intermediate hash value 11941 H[0] = (H[0] + a) | 0; 11942 H[1] = (H[1] + b) | 0; 11943 H[2] = (H[2] + c) | 0; 11944 H[3] = (H[3] + d) | 0; 11945 H[4] = (H[4] + e) | 0; 11946 H[5] = (H[5] + f) | 0; 11947 H[6] = (H[6] + g) | 0; 11948 H[7] = (H[7] + h) | 0; 11949 }, 11950 11951 _doFinalize: function () { 11952 // Shortcuts 11953 var data = this._data; 11954 var dataWords = data.words; 11955 11956 var nBitsTotal = this._nDataBytes * 8; 11957 var nBitsLeft = data.sigBytes * 8; 11958 11959 // Add padding 11960 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11961 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11962 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11963 data.sigBytes = dataWords.length * 4; 11964 11965 // Hash final blocks 11966 this._process(); 11967 11968 // Return final computed hash 11969 return this._hash; 11970 }, 11971 11972 clone: function () { 11973 var clone = Hasher.clone.call(this); 11974 clone._hash = this._hash.clone(); 11975 11976 return clone; 11977 } 11978 }); 11979 11980 /** 11981 * Shortcut function to the hasher's object interface. 11982 * 11983 * @param {WordArray|string} message The message to hash. 11984 * 11985 * @return {WordArray} The hash. 11986 * 11987 * @static 11988 * 11989 * @example 11990 * 11991 * var hash = CryptoJS.SHA256('message'); 11992 * var hash = CryptoJS.SHA256(wordArray); 11993 */ 11994 C.SHA256 = Hasher._createHelper(SHA256); 11995 11996 /** 11997 * Shortcut function to the HMAC's object interface. 11998 * 11999 * @param {WordArray|string} message The message to hash. 12000 * @param {WordArray|string} key The secret key. 12001 * 12002 * @return {WordArray} The HMAC. 12003 * 12004 * @static 12005 * 12006 * @example 12007 * 12008 * var hmac = CryptoJS.HmacSHA256(message, key); 12009 */ 12010 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 12011 }(Math)); 12012 12013 12014 return CryptoJS.SHA256; 12015 12016 })); 12017 },{"./core":53}],80:[function(require,module,exports){ 12018 ;(function (root, factory, undef) { 12019 if (typeof exports === "object") { 12020 // CommonJS 12021 module.exports = exports = factory(require("./core"), require("./x64-core")); 12022 } 12023 else if (typeof define === "function" && define.amd) { 12024 // AMD 12025 define(["./core", "./x64-core"], factory); 12026 } 12027 else { 12028 // Global (browser) 12029 factory(root.CryptoJS); 12030 } 12031 }(this, function (CryptoJS) { 12032 12033 (function (Math) { 12034 // Shortcuts 12035 var C = CryptoJS; 12036 var C_lib = C.lib; 12037 var WordArray = C_lib.WordArray; 12038 var Hasher = C_lib.Hasher; 12039 var C_x64 = C.x64; 12040 var X64Word = C_x64.Word; 12041 var C_algo = C.algo; 12042 12043 // Constants tables 12044 var RHO_OFFSETS = []; 12045 var PI_INDEXES = []; 12046 var ROUND_CONSTANTS = []; 12047 12048 // Compute Constants 12049 (function () { 12050 // Compute rho offset constants 12051 var x = 1, y = 0; 12052 for (var t = 0; t < 24; t++) { 12053 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 12054 12055 var newX = y % 5; 12056 var newY = (2 * x + 3 * y) % 5; 12057 x = newX; 12058 y = newY; 12059 } 12060 12061 // Compute pi index constants 12062 for (var x = 0; x < 5; x++) { 12063 for (var y = 0; y < 5; y++) { 12064 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 12065 } 12066 } 12067 12068 // Compute round constants 12069 var LFSR = 0x01; 12070 for (var i = 0; i < 24; i++) { 12071 var roundConstantMsw = 0; 12072 var roundConstantLsw = 0; 12073 12074 for (var j = 0; j < 7; j++) { 12075 if (LFSR & 0x01) { 12076 var bitPosition = (1 << j) - 1; 12077 if (bitPosition < 32) { 12078 roundConstantLsw ^= 1 << bitPosition; 12079 } else /* if (bitPosition >= 32) */ { 12080 roundConstantMsw ^= 1 << (bitPosition - 32); 12081 } 12082 } 12083 12084 // Compute next LFSR 12085 if (LFSR & 0x80) { 12086 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 12087 LFSR = (LFSR << 1) ^ 0x71; 12088 } else { 12089 LFSR <<= 1; 12090 } 12091 } 12092 12093 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 12094 } 12095 }()); 12096 12097 // Reusable objects for temporary values 12098 var T = []; 12099 (function () { 12100 for (var i = 0; i < 25; i++) { 12101 T[i] = X64Word.create(); 12102 } 12103 }()); 12104 12105 /** 12106 * SHA-3 hash algorithm. 12107 */ 12108 var SHA3 = C_algo.SHA3 = Hasher.extend({ 12109 /** 12110 * Configuration options. 12111 * 12112 * @property {number} outputLength 12113 * The desired number of bits in the output hash. 12114 * Only values permitted are: 224, 256, 384, 512. 12115 * Default: 512 12116 */ 12117 cfg: Hasher.cfg.extend({ 12118 outputLength: 512 12119 }), 12120 12121 _doReset: function () { 12122 var state = this._state = [] 12123 for (var i = 0; i < 25; i++) { 12124 state[i] = new X64Word.init(); 12125 } 12126 12127 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 12128 }, 12129 12130 _doProcessBlock: function (M, offset) { 12131 // Shortcuts 12132 var state = this._state; 12133 var nBlockSizeLanes = this.blockSize / 2; 12134 12135 // Absorb 12136 for (var i = 0; i < nBlockSizeLanes; i++) { 12137 // Shortcuts 12138 var M2i = M[offset + 2 * i]; 12139 var M2i1 = M[offset + 2 * i + 1]; 12140 12141 // Swap endian 12142 M2i = ( 12143 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 12144 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 12145 ); 12146 M2i1 = ( 12147 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 12148 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 12149 ); 12150 12151 // Absorb message into state 12152 var lane = state[i]; 12153 lane.high ^= M2i1; 12154 lane.low ^= M2i; 12155 } 12156 12157 // Rounds 12158 for (var round = 0; round < 24; round++) { 12159 // Theta 12160 for (var x = 0; x < 5; x++) { 12161 // Mix column lanes 12162 var tMsw = 0, tLsw = 0; 12163 for (var y = 0; y < 5; y++) { 12164 var lane = state[x + 5 * y]; 12165 tMsw ^= lane.high; 12166 tLsw ^= lane.low; 12167 } 12168 12169 // Temporary values 12170 var Tx = T[x]; 12171 Tx.high = tMsw; 12172 Tx.low = tLsw; 12173 } 12174 for (var x = 0; x < 5; x++) { 12175 // Shortcuts 12176 var Tx4 = T[(x + 4) % 5]; 12177 var Tx1 = T[(x + 1) % 5]; 12178 var Tx1Msw = Tx1.high; 12179 var Tx1Lsw = Tx1.low; 12180 12181 // Mix surrounding columns 12182 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 12183 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 12184 for (var y = 0; y < 5; y++) { 12185 var lane = state[x + 5 * y]; 12186 lane.high ^= tMsw; 12187 lane.low ^= tLsw; 12188 } 12189 } 12190 12191 // Rho Pi 12192 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 12193 // Shortcuts 12194 var lane = state[laneIndex]; 12195 var laneMsw = lane.high; 12196 var laneLsw = lane.low; 12197 var rhoOffset = RHO_OFFSETS[laneIndex]; 12198 12199 // Rotate lanes 12200 if (rhoOffset < 32) { 12201 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 12202 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 12203 } else /* if (rhoOffset >= 32) */ { 12204 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 12205 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 12206 } 12207 12208 // Transpose lanes 12209 var TPiLane = T[PI_INDEXES[laneIndex]]; 12210 TPiLane.high = tMsw; 12211 TPiLane.low = tLsw; 12212 } 12213 12214 // Rho pi at x = y = 0 12215 var T0 = T[0]; 12216 var state0 = state[0]; 12217 T0.high = state0.high; 12218 T0.low = state0.low; 12219 12220 // Chi 12221 for (var x = 0; x < 5; x++) { 12222 for (var y = 0; y < 5; y++) { 12223 // Shortcuts 12224 var laneIndex = x + 5 * y; 12225 var lane = state[laneIndex]; 12226 var TLane = T[laneIndex]; 12227 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 12228 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 12229 12230 // Mix rows 12231 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 12232 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 12233 } 12234 } 12235 12236 // Iota 12237 var lane = state[0]; 12238 var roundConstant = ROUND_CONSTANTS[round]; 12239 lane.high ^= roundConstant.high; 12240 lane.low ^= roundConstant.low;; 12241 } 12242 }, 12243 12244 _doFinalize: function () { 12245 // Shortcuts 12246 var data = this._data; 12247 var dataWords = data.words; 12248 var nBitsTotal = this._nDataBytes * 8; 12249 var nBitsLeft = data.sigBytes * 8; 12250 var blockSizeBits = this.blockSize * 32; 12251 12252 // Add padding 12253 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 12254 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 12255 data.sigBytes = dataWords.length * 4; 12256 12257 // Hash final blocks 12258 this._process(); 12259 12260 // Shortcuts 12261 var state = this._state; 12262 var outputLengthBytes = this.cfg.outputLength / 8; 12263 var outputLengthLanes = outputLengthBytes / 8; 12264 12265 // Squeeze 12266 var hashWords = []; 12267 for (var i = 0; i < outputLengthLanes; i++) { 12268 // Shortcuts 12269 var lane = state[i]; 12270 var laneMsw = lane.high; 12271 var laneLsw = lane.low; 12272 12273 // Swap endian 12274 laneMsw = ( 12275 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 12276 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 12277 ); 12278 laneLsw = ( 12279 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 12280 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 12281 ); 12282 12283 // Squeeze state to retrieve hash 12284 hashWords.push(laneLsw); 12285 hashWords.push(laneMsw); 12286 } 12287 12288 // Return final computed hash 12289 return new WordArray.init(hashWords, outputLengthBytes); 12290 }, 12291 12292 clone: function () { 12293 var clone = Hasher.clone.call(this); 12294 12295 var state = clone._state = this._state.slice(0); 12296 for (var i = 0; i < 25; i++) { 12297 state[i] = state[i].clone(); 12298 } 12299 12300 return clone; 12301 } 12302 }); 12303 12304 /** 12305 * Shortcut function to the hasher's object interface. 12306 * 12307 * @param {WordArray|string} message The message to hash. 12308 * 12309 * @return {WordArray} The hash. 12310 * 12311 * @static 12312 * 12313 * @example 12314 * 12315 * var hash = CryptoJS.SHA3('message'); 12316 * var hash = CryptoJS.SHA3(wordArray); 12317 */ 12318 C.SHA3 = Hasher._createHelper(SHA3); 12319 12320 /** 12321 * Shortcut function to the HMAC's object interface. 12322 * 12323 * @param {WordArray|string} message The message to hash. 12324 * @param {WordArray|string} key The secret key. 12325 * 12326 * @return {WordArray} The HMAC. 12327 * 12328 * @static 12329 * 12330 * @example 12331 * 12332 * var hmac = CryptoJS.HmacSHA3(message, key); 12333 */ 12334 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 12335 }(Math)); 12336 12337 12338 return CryptoJS.SHA3; 12339 12340 })); 12341 },{"./core":53,"./x64-core":84}],81:[function(require,module,exports){ 12342 ;(function (root, factory, undef) { 12343 if (typeof exports === "object") { 12344 // CommonJS 12345 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 12346 } 12347 else if (typeof define === "function" && define.amd) { 12348 // AMD 12349 define(["./core", "./x64-core", "./sha512"], factory); 12350 } 12351 else { 12352 // Global (browser) 12353 factory(root.CryptoJS); 12354 } 12355 }(this, function (CryptoJS) { 12356 12357 (function () { 12358 // Shortcuts 12359 var C = CryptoJS; 12360 var C_x64 = C.x64; 12361 var X64Word = C_x64.Word; 12362 var X64WordArray = C_x64.WordArray; 12363 var C_algo = C.algo; 12364 var SHA512 = C_algo.SHA512; 12365 12366 /** 12367 * SHA-384 hash algorithm. 12368 */ 12369 var SHA384 = C_algo.SHA384 = SHA512.extend({ 12370 _doReset: function () { 12371 this._hash = new X64WordArray.init([ 12372 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 12373 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 12374 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 12375 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 12376 ]); 12377 }, 12378 12379 _doFinalize: function () { 12380 var hash = SHA512._doFinalize.call(this); 12381 12382 hash.sigBytes -= 16; 12383 12384 return hash; 12385 } 12386 }); 12387 12388 /** 12389 * Shortcut function to the hasher's object interface. 12390 * 12391 * @param {WordArray|string} message The message to hash. 12392 * 12393 * @return {WordArray} The hash. 12394 * 12395 * @static 12396 * 12397 * @example 12398 * 12399 * var hash = CryptoJS.SHA384('message'); 12400 * var hash = CryptoJS.SHA384(wordArray); 12401 */ 12402 C.SHA384 = SHA512._createHelper(SHA384); 12403 12404 /** 12405 * Shortcut function to the HMAC's object interface. 12406 * 12407 * @param {WordArray|string} message The message to hash. 12408 * @param {WordArray|string} key The secret key. 12409 * 12410 * @return {WordArray} The HMAC. 12411 * 12412 * @static 12413 * 12414 * @example 12415 * 12416 * var hmac = CryptoJS.HmacSHA384(message, key); 12417 */ 12418 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 12419 }()); 12420 12421 12422 return CryptoJS.SHA384; 12423 12424 })); 12425 },{"./core":53,"./sha512":82,"./x64-core":84}],82:[function(require,module,exports){ 12426 ;(function (root, factory, undef) { 12427 if (typeof exports === "object") { 12428 // CommonJS 12429 module.exports = exports = factory(require("./core"), require("./x64-core")); 12430 } 12431 else if (typeof define === "function" && define.amd) { 12432 // AMD 12433 define(["./core", "./x64-core"], factory); 12434 } 12435 else { 12436 // Global (browser) 12437 factory(root.CryptoJS); 12438 } 12439 }(this, function (CryptoJS) { 12440 12441 (function () { 12442 // Shortcuts 12443 var C = CryptoJS; 12444 var C_lib = C.lib; 12445 var Hasher = C_lib.Hasher; 12446 var C_x64 = C.x64; 12447 var X64Word = C_x64.Word; 12448 var X64WordArray = C_x64.WordArray; 12449 var C_algo = C.algo; 12450 12451 function X64Word_create() { 12452 return X64Word.create.apply(X64Word, arguments); 12453 } 12454 12455 // Constants 12456 var K = [ 12457 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12458 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12459 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12460 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12461 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12462 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12463 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12464 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12465 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12466 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12467 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12468 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12469 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12470 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12471 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12472 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12473 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12474 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12475 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12476 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12477 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12478 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12479 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12480 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12481 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12482 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12483 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12484 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12485 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12486 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12487 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12488 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12489 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12490 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12491 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12492 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12493 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12494 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12495 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12496 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12497 ]; 12498 12499 // Reusable objects 12500 var W = []; 12501 (function () { 12502 for (var i = 0; i < 80; i++) { 12503 W[i] = X64Word_create(); 12504 } 12505 }()); 12506 12507 /** 12508 * SHA-512 hash algorithm. 12509 */ 12510 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12511 _doReset: function () { 12512 this._hash = new X64WordArray.init([ 12513 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12514 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12515 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12516 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12517 ]); 12518 }, 12519 12520 _doProcessBlock: function (M, offset) { 12521 // Shortcuts 12522 var H = this._hash.words; 12523 12524 var H0 = H[0]; 12525 var H1 = H[1]; 12526 var H2 = H[2]; 12527 var H3 = H[3]; 12528 var H4 = H[4]; 12529 var H5 = H[5]; 12530 var H6 = H[6]; 12531 var H7 = H[7]; 12532 12533 var H0h = H0.high; 12534 var H0l = H0.low; 12535 var H1h = H1.high; 12536 var H1l = H1.low; 12537 var H2h = H2.high; 12538 var H2l = H2.low; 12539 var H3h = H3.high; 12540 var H3l = H3.low; 12541 var H4h = H4.high; 12542 var H4l = H4.low; 12543 var H5h = H5.high; 12544 var H5l = H5.low; 12545 var H6h = H6.high; 12546 var H6l = H6.low; 12547 var H7h = H7.high; 12548 var H7l = H7.low; 12549 12550 // Working variables 12551 var ah = H0h; 12552 var al = H0l; 12553 var bh = H1h; 12554 var bl = H1l; 12555 var ch = H2h; 12556 var cl = H2l; 12557 var dh = H3h; 12558 var dl = H3l; 12559 var eh = H4h; 12560 var el = H4l; 12561 var fh = H5h; 12562 var fl = H5l; 12563 var gh = H6h; 12564 var gl = H6l; 12565 var hh = H7h; 12566 var hl = H7l; 12567 12568 // Rounds 12569 for (var i = 0; i < 80; i++) { 12570 // Shortcut 12571 var Wi = W[i]; 12572 12573 // Extend message 12574 if (i < 16) { 12575 var Wih = Wi.high = M[offset + i * 2] | 0; 12576 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12577 } else { 12578 // Gamma0 12579 var gamma0x = W[i - 15]; 12580 var gamma0xh = gamma0x.high; 12581 var gamma0xl = gamma0x.low; 12582 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12583 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12584 12585 // Gamma1 12586 var gamma1x = W[i - 2]; 12587 var gamma1xh = gamma1x.high; 12588 var gamma1xl = gamma1x.low; 12589 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12590 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12591 12592 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12593 var Wi7 = W[i - 7]; 12594 var Wi7h = Wi7.high; 12595 var Wi7l = Wi7.low; 12596 12597 var Wi16 = W[i - 16]; 12598 var Wi16h = Wi16.high; 12599 var Wi16l = Wi16.low; 12600 12601 var Wil = gamma0l + Wi7l; 12602 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12603 var Wil = Wil + gamma1l; 12604 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12605 var Wil = Wil + Wi16l; 12606 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12607 12608 Wi.high = Wih; 12609 Wi.low = Wil; 12610 } 12611 12612 var chh = (eh & fh) ^ (~eh & gh); 12613 var chl = (el & fl) ^ (~el & gl); 12614 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12615 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12616 12617 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12618 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12619 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12620 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12621 12622 // t1 = h + sigma1 + ch + K[i] + W[i] 12623 var Ki = K[i]; 12624 var Kih = Ki.high; 12625 var Kil = Ki.low; 12626 12627 var t1l = hl + sigma1l; 12628 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12629 var t1l = t1l + chl; 12630 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12631 var t1l = t1l + Kil; 12632 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12633 var t1l = t1l + Wil; 12634 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12635 12636 // t2 = sigma0 + maj 12637 var t2l = sigma0l + majl; 12638 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12639 12640 // Update working variables 12641 hh = gh; 12642 hl = gl; 12643 gh = fh; 12644 gl = fl; 12645 fh = eh; 12646 fl = el; 12647 el = (dl + t1l) | 0; 12648 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12649 dh = ch; 12650 dl = cl; 12651 ch = bh; 12652 cl = bl; 12653 bh = ah; 12654 bl = al; 12655 al = (t1l + t2l) | 0; 12656 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12657 } 12658 12659 // Intermediate hash value 12660 H0l = H0.low = (H0l + al); 12661 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12662 H1l = H1.low = (H1l + bl); 12663 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12664 H2l = H2.low = (H2l + cl); 12665 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12666 H3l = H3.low = (H3l + dl); 12667 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12668 H4l = H4.low = (H4l + el); 12669 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12670 H5l = H5.low = (H5l + fl); 12671 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12672 H6l = H6.low = (H6l + gl); 12673 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12674 H7l = H7.low = (H7l + hl); 12675 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12676 }, 12677 12678 _doFinalize: function () { 12679 // Shortcuts 12680 var data = this._data; 12681 var dataWords = data.words; 12682 12683 var nBitsTotal = this._nDataBytes * 8; 12684 var nBitsLeft = data.sigBytes * 8; 12685 12686 // Add padding 12687 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12688 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12689 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12690 data.sigBytes = dataWords.length * 4; 12691 12692 // Hash final blocks 12693 this._process(); 12694 12695 // Convert hash to 32-bit word array before returning 12696 var hash = this._hash.toX32(); 12697 12698 // Return final computed hash 12699 return hash; 12700 }, 12701 12702 clone: function () { 12703 var clone = Hasher.clone.call(this); 12704 clone._hash = this._hash.clone(); 12705 12706 return clone; 12707 }, 12708 12709 blockSize: 1024/32 12710 }); 12711 12712 /** 12713 * Shortcut function to the hasher's object interface. 12714 * 12715 * @param {WordArray|string} message The message to hash. 12716 * 12717 * @return {WordArray} The hash. 12718 * 12719 * @static 12720 * 12721 * @example 12722 * 12723 * var hash = CryptoJS.SHA512('message'); 12724 * var hash = CryptoJS.SHA512(wordArray); 12725 */ 12726 C.SHA512 = Hasher._createHelper(SHA512); 12727 12728 /** 12729 * Shortcut function to the HMAC's object interface. 12730 * 12731 * @param {WordArray|string} message The message to hash. 12732 * @param {WordArray|string} key The secret key. 12733 * 12734 * @return {WordArray} The HMAC. 12735 * 12736 * @static 12737 * 12738 * @example 12739 * 12740 * var hmac = CryptoJS.HmacSHA512(message, key); 12741 */ 12742 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12743 }()); 12744 12745 12746 return CryptoJS.SHA512; 12747 12748 })); 12749 },{"./core":53,"./x64-core":84}],83:[function(require,module,exports){ 12750 ;(function (root, factory, undef) { 12751 if (typeof exports === "object") { 12752 // CommonJS 12753 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12754 } 12755 else if (typeof define === "function" && define.amd) { 12756 // AMD 12757 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12758 } 12759 else { 12760 // Global (browser) 12761 factory(root.CryptoJS); 12762 } 12763 }(this, function (CryptoJS) { 12764 12765 (function () { 12766 // Shortcuts 12767 var C = CryptoJS; 12768 var C_lib = C.lib; 12769 var WordArray = C_lib.WordArray; 12770 var BlockCipher = C_lib.BlockCipher; 12771 var C_algo = C.algo; 12772 12773 // Permuted Choice 1 constants 12774 var PC1 = [ 12775 57, 49, 41, 33, 25, 17, 9, 1, 12776 58, 50, 42, 34, 26, 18, 10, 2, 12777 59, 51, 43, 35, 27, 19, 11, 3, 12778 60, 52, 44, 36, 63, 55, 47, 39, 12779 31, 23, 15, 7, 62, 54, 46, 38, 12780 30, 22, 14, 6, 61, 53, 45, 37, 12781 29, 21, 13, 5, 28, 20, 12, 4 12782 ]; 12783 12784 // Permuted Choice 2 constants 12785 var PC2 = [ 12786 14, 17, 11, 24, 1, 5, 12787 3, 28, 15, 6, 21, 10, 12788 23, 19, 12, 4, 26, 8, 12789 16, 7, 27, 20, 13, 2, 12790 41, 52, 31, 37, 47, 55, 12791 30, 40, 51, 45, 33, 48, 12792 44, 49, 39, 56, 34, 53, 12793 46, 42, 50, 36, 29, 32 12794 ]; 12795 12796 // Cumulative bit shift constants 12797 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12798 12799 // SBOXes and round permutation constants 12800 var SBOX_P = [ 12801 { 12802 0x0: 0x808200, 12803 0x10000000: 0x8000, 12804 0x20000000: 0x808002, 12805 0x30000000: 0x2, 12806 0x40000000: 0x200, 12807 0x50000000: 0x808202, 12808 0x60000000: 0x800202, 12809 0x70000000: 0x800000, 12810 0x80000000: 0x202, 12811 0x90000000: 0x800200, 12812 0xa0000000: 0x8200, 12813 0xb0000000: 0x808000, 12814 0xc0000000: 0x8002, 12815 0xd0000000: 0x800002, 12816 0xe0000000: 0x0, 12817 0xf0000000: 0x8202, 12818 0x8000000: 0x0, 12819 0x18000000: 0x808202, 12820 0x28000000: 0x8202, 12821 0x38000000: 0x8000, 12822 0x48000000: 0x808200, 12823 0x58000000: 0x200, 12824 0x68000000: 0x808002, 12825 0x78000000: 0x2, 12826 0x88000000: 0x800200, 12827 0x98000000: 0x8200, 12828 0xa8000000: 0x808000, 12829 0xb8000000: 0x800202, 12830 0xc8000000: 0x800002, 12831 0xd8000000: 0x8002, 12832 0xe8000000: 0x202, 12833 0xf8000000: 0x800000, 12834 0x1: 0x8000, 12835 0x10000001: 0x2, 12836 0x20000001: 0x808200, 12837 0x30000001: 0x800000, 12838 0x40000001: 0x808002, 12839 0x50000001: 0x8200, 12840 0x60000001: 0x200, 12841 0x70000001: 0x800202, 12842 0x80000001: 0x808202, 12843 0x90000001: 0x808000, 12844 0xa0000001: 0x800002, 12845 0xb0000001: 0x8202, 12846 0xc0000001: 0x202, 12847 0xd0000001: 0x800200, 12848 0xe0000001: 0x8002, 12849 0xf0000001: 0x0, 12850 0x8000001: 0x808202, 12851 0x18000001: 0x808000, 12852 0x28000001: 0x800000, 12853 0x38000001: 0x200, 12854 0x48000001: 0x8000, 12855 0x58000001: 0x800002, 12856 0x68000001: 0x2, 12857 0x78000001: 0x8202, 12858 0x88000001: 0x8002, 12859 0x98000001: 0x800202, 12860 0xa8000001: 0x202, 12861 0xb8000001: 0x808200, 12862 0xc8000001: 0x800200, 12863 0xd8000001: 0x0, 12864 0xe8000001: 0x8200, 12865 0xf8000001: 0x808002 12866 }, 12867 { 12868 0x0: 0x40084010, 12869 0x1000000: 0x4000, 12870 0x2000000: 0x80000, 12871 0x3000000: 0x40080010, 12872 0x4000000: 0x40000010, 12873 0x5000000: 0x40084000, 12874 0x6000000: 0x40004000, 12875 0x7000000: 0x10, 12876 0x8000000: 0x84000, 12877 0x9000000: 0x40004010, 12878 0xa000000: 0x40000000, 12879 0xb000000: 0x84010, 12880 0xc000000: 0x80010, 12881 0xd000000: 0x0, 12882 0xe000000: 0x4010, 12883 0xf000000: 0x40080000, 12884 0x800000: 0x40004000, 12885 0x1800000: 0x84010, 12886 0x2800000: 0x10, 12887 0x3800000: 0x40004010, 12888 0x4800000: 0x40084010, 12889 0x5800000: 0x40000000, 12890 0x6800000: 0x80000, 12891 0x7800000: 0x40080010, 12892 0x8800000: 0x80010, 12893 0x9800000: 0x0, 12894 0xa800000: 0x4000, 12895 0xb800000: 0x40080000, 12896 0xc800000: 0x40000010, 12897 0xd800000: 0x84000, 12898 0xe800000: 0x40084000, 12899 0xf800000: 0x4010, 12900 0x10000000: 0x0, 12901 0x11000000: 0x40080010, 12902 0x12000000: 0x40004010, 12903 0x13000000: 0x40084000, 12904 0x14000000: 0x40080000, 12905 0x15000000: 0x10, 12906 0x16000000: 0x84010, 12907 0x17000000: 0x4000, 12908 0x18000000: 0x4010, 12909 0x19000000: 0x80000, 12910 0x1a000000: 0x80010, 12911 0x1b000000: 0x40000010, 12912 0x1c000000: 0x84000, 12913 0x1d000000: 0x40004000, 12914 0x1e000000: 0x40000000, 12915 0x1f000000: 0x40084010, 12916 0x10800000: 0x84010, 12917 0x11800000: 0x80000, 12918 0x12800000: 0x40080000, 12919 0x13800000: 0x4000, 12920 0x14800000: 0x40004000, 12921 0x15800000: 0x40084010, 12922 0x16800000: 0x10, 12923 0x17800000: 0x40000000, 12924 0x18800000: 0x40084000, 12925 0x19800000: 0x40000010, 12926 0x1a800000: 0x40004010, 12927 0x1b800000: 0x80010, 12928 0x1c800000: 0x0, 12929 0x1d800000: 0x4010, 12930 0x1e800000: 0x40080010, 12931 0x1f800000: 0x84000 12932 }, 12933 { 12934 0x0: 0x104, 12935 0x100000: 0x0, 12936 0x200000: 0x4000100, 12937 0x300000: 0x10104, 12938 0x400000: 0x10004, 12939 0x500000: 0x4000004, 12940 0x600000: 0x4010104, 12941 0x700000: 0x4010000, 12942 0x800000: 0x4000000, 12943 0x900000: 0x4010100, 12944 0xa00000: 0x10100, 12945 0xb00000: 0x4010004, 12946 0xc00000: 0x4000104, 12947 0xd00000: 0x10000, 12948 0xe00000: 0x4, 12949 0xf00000: 0x100, 12950 0x80000: 0x4010100, 12951 0x180000: 0x4010004, 12952 0x280000: 0x0, 12953 0x380000: 0x4000100, 12954 0x480000: 0x4000004, 12955 0x580000: 0x10000, 12956 0x680000: 0x10004, 12957 0x780000: 0x104, 12958 0x880000: 0x4, 12959 0x980000: 0x100, 12960 0xa80000: 0x4010000, 12961 0xb80000: 0x10104, 12962 0xc80000: 0x10100, 12963 0xd80000: 0x4000104, 12964 0xe80000: 0x4010104, 12965 0xf80000: 0x4000000, 12966 0x1000000: 0x4010100, 12967 0x1100000: 0x10004, 12968 0x1200000: 0x10000, 12969 0x1300000: 0x4000100, 12970 0x1400000: 0x100, 12971 0x1500000: 0x4010104, 12972 0x1600000: 0x4000004, 12973 0x1700000: 0x0, 12974 0x1800000: 0x4000104, 12975 0x1900000: 0x4000000, 12976 0x1a00000: 0x4, 12977 0x1b00000: 0x10100, 12978 0x1c00000: 0x4010000, 12979 0x1d00000: 0x104, 12980 0x1e00000: 0x10104, 12981 0x1f00000: 0x4010004, 12982 0x1080000: 0x4000000, 12983 0x1180000: 0x104, 12984 0x1280000: 0x4010100, 12985 0x1380000: 0x0, 12986 0x1480000: 0x10004, 12987 0x1580000: 0x4000100, 12988 0x1680000: 0x100, 12989 0x1780000: 0x4010004, 12990 0x1880000: 0x10000, 12991 0x1980000: 0x4010104, 12992 0x1a80000: 0x10104, 12993 0x1b80000: 0x4000004, 12994 0x1c80000: 0x4000104, 12995 0x1d80000: 0x4010000, 12996 0x1e80000: 0x4, 12997 0x1f80000: 0x10100 12998 }, 12999 { 13000 0x0: 0x80401000, 13001 0x10000: 0x80001040, 13002 0x20000: 0x401040, 13003 0x30000: 0x80400000, 13004 0x40000: 0x0, 13005 0x50000: 0x401000, 13006 0x60000: 0x80000040, 13007 0x70000: 0x400040, 13008 0x80000: 0x80000000, 13009 0x90000: 0x400000, 13010 0xa0000: 0x40, 13011 0xb0000: 0x80001000, 13012 0xc0000: 0x80400040, 13013 0xd0000: 0x1040, 13014 0xe0000: 0x1000, 13015 0xf0000: 0x80401040, 13016 0x8000: 0x80001040, 13017 0x18000: 0x40, 13018 0x28000: 0x80400040, 13019 0x38000: 0x80001000, 13020 0x48000: 0x401000, 13021 0x58000: 0x80401040, 13022 0x68000: 0x0, 13023 0x78000: 0x80400000, 13024 0x88000: 0x1000, 13025 0x98000: 0x80401000, 13026 0xa8000: 0x400000, 13027 0xb8000: 0x1040, 13028 0xc8000: 0x80000000, 13029 0xd8000: 0x400040, 13030 0xe8000: 0x401040, 13031 0xf8000: 0x80000040, 13032 0x100000: 0x400040, 13033 0x110000: 0x401000, 13034 0x120000: 0x80000040, 13035 0x130000: 0x0, 13036 0x140000: 0x1040, 13037 0x150000: 0x80400040, 13038 0x160000: 0x80401000, 13039 0x170000: 0x80001040, 13040 0x180000: 0x80401040, 13041 0x190000: 0x80000000, 13042 0x1a0000: 0x80400000, 13043 0x1b0000: 0x401040, 13044 0x1c0000: 0x80001000, 13045 0x1d0000: 0x400000, 13046 0x1e0000: 0x40, 13047 0x1f0000: 0x1000, 13048 0x108000: 0x80400000, 13049 0x118000: 0x80401040, 13050 0x128000: 0x0, 13051 0x138000: 0x401000, 13052 0x148000: 0x400040, 13053 0x158000: 0x80000000, 13054 0x168000: 0x80001040, 13055 0x178000: 0x40, 13056 0x188000: 0x80000040, 13057 0x198000: 0x1000, 13058 0x1a8000: 0x80001000, 13059 0x1b8000: 0x80400040, 13060 0x1c8000: 0x1040, 13061 0x1d8000: 0x80401000, 13062 0x1e8000: 0x400000, 13063 0x1f8000: 0x401040 13064 }, 13065 { 13066 0x0: 0x80, 13067 0x1000: 0x1040000, 13068 0x2000: 0x40000, 13069 0x3000: 0x20000000, 13070 0x4000: 0x20040080, 13071 0x5000: 0x1000080, 13072 0x6000: 0x21000080, 13073 0x7000: 0x40080, 13074 0x8000: 0x1000000, 13075 0x9000: 0x20040000, 13076 0xa000: 0x20000080, 13077 0xb000: 0x21040080, 13078 0xc000: 0x21040000, 13079 0xd000: 0x0, 13080 0xe000: 0x1040080, 13081 0xf000: 0x21000000, 13082 0x800: 0x1040080, 13083 0x1800: 0x21000080, 13084 0x2800: 0x80, 13085 0x3800: 0x1040000, 13086 0x4800: 0x40000, 13087 0x5800: 0x20040080, 13088 0x6800: 0x21040000, 13089 0x7800: 0x20000000, 13090 0x8800: 0x20040000, 13091 0x9800: 0x0, 13092 0xa800: 0x21040080, 13093 0xb800: 0x1000080, 13094 0xc800: 0x20000080, 13095 0xd800: 0x21000000, 13096 0xe800: 0x1000000, 13097 0xf800: 0x40080, 13098 0x10000: 0x40000, 13099 0x11000: 0x80, 13100 0x12000: 0x20000000, 13101 0x13000: 0x21000080, 13102 0x14000: 0x1000080, 13103 0x15000: 0x21040000, 13104 0x16000: 0x20040080, 13105 0x17000: 0x1000000, 13106 0x18000: 0x21040080, 13107 0x19000: 0x21000000, 13108 0x1a000: 0x1040000, 13109 0x1b000: 0x20040000, 13110 0x1c000: 0x40080, 13111 0x1d000: 0x20000080, 13112 0x1e000: 0x0, 13113 0x1f000: 0x1040080, 13114 0x10800: 0x21000080, 13115 0x11800: 0x1000000, 13116 0x12800: 0x1040000, 13117 0x13800: 0x20040080, 13118 0x14800: 0x20000000, 13119 0x15800: 0x1040080, 13120 0x16800: 0x80, 13121 0x17800: 0x21040000, 13122 0x18800: 0x40080, 13123 0x19800: 0x21040080, 13124 0x1a800: 0x0, 13125 0x1b800: 0x21000000, 13126 0x1c800: 0x1000080, 13127 0x1d800: 0x40000, 13128 0x1e800: 0x20040000, 13129 0x1f800: 0x20000080 13130 }, 13131 { 13132 0x0: 0x10000008, 13133 0x100: 0x2000, 13134 0x200: 0x10200000, 13135 0x300: 0x10202008, 13136 0x400: 0x10002000, 13137 0x500: 0x200000, 13138 0x600: 0x200008, 13139 0x700: 0x10000000, 13140 0x800: 0x0, 13141 0x900: 0x10002008, 13142 0xa00: 0x202000, 13143 0xb00: 0x8, 13144 0xc00: 0x10200008, 13145 0xd00: 0x202008, 13146 0xe00: 0x2008, 13147 0xf00: 0x10202000, 13148 0x80: 0x10200000, 13149 0x180: 0x10202008, 13150 0x280: 0x8, 13151 0x380: 0x200000, 13152 0x480: 0x202008, 13153 0x580: 0x10000008, 13154 0x680: 0x10002000, 13155 0x780: 0x2008, 13156 0x880: 0x200008, 13157 0x980: 0x2000, 13158 0xa80: 0x10002008, 13159 0xb80: 0x10200008, 13160 0xc80: 0x0, 13161 0xd80: 0x10202000, 13162 0xe80: 0x202000, 13163 0xf80: 0x10000000, 13164 0x1000: 0x10002000, 13165 0x1100: 0x10200008, 13166 0x1200: 0x10202008, 13167 0x1300: 0x2008, 13168 0x1400: 0x200000, 13169 0x1500: 0x10000000, 13170 0x1600: 0x10000008, 13171 0x1700: 0x202000, 13172 0x1800: 0x202008, 13173 0x1900: 0x0, 13174 0x1a00: 0x8, 13175 0x1b00: 0x10200000, 13176 0x1c00: 0x2000, 13177 0x1d00: 0x10002008, 13178 0x1e00: 0x10202000, 13179 0x1f00: 0x200008, 13180 0x1080: 0x8, 13181 0x1180: 0x202000, 13182 0x1280: 0x200000, 13183 0x1380: 0x10000008, 13184 0x1480: 0x10002000, 13185 0x1580: 0x2008, 13186 0x1680: 0x10202008, 13187 0x1780: 0x10200000, 13188 0x1880: 0x10202000, 13189 0x1980: 0x10200008, 13190 0x1a80: 0x2000, 13191 0x1b80: 0x202008, 13192 0x1c80: 0x200008, 13193 0x1d80: 0x0, 13194 0x1e80: 0x10000000, 13195 0x1f80: 0x10002008 13196 }, 13197 { 13198 0x0: 0x100000, 13199 0x10: 0x2000401, 13200 0x20: 0x400, 13201 0x30: 0x100401, 13202 0x40: 0x2100401, 13203 0x50: 0x0, 13204 0x60: 0x1, 13205 0x70: 0x2100001, 13206 0x80: 0x2000400, 13207 0x90: 0x100001, 13208 0xa0: 0x2000001, 13209 0xb0: 0x2100400, 13210 0xc0: 0x2100000, 13211 0xd0: 0x401, 13212 0xe0: 0x100400, 13213 0xf0: 0x2000000, 13214 0x8: 0x2100001, 13215 0x18: 0x0, 13216 0x28: 0x2000401, 13217 0x38: 0x2100400, 13218 0x48: 0x100000, 13219 0x58: 0x2000001, 13220 0x68: 0x2000000, 13221 0x78: 0x401, 13222 0x88: 0x100401, 13223 0x98: 0x2000400, 13224 0xa8: 0x2100000, 13225 0xb8: 0x100001, 13226 0xc8: 0x400, 13227 0xd8: 0x2100401, 13228 0xe8: 0x1, 13229 0xf8: 0x100400, 13230 0x100: 0x2000000, 13231 0x110: 0x100000, 13232 0x120: 0x2000401, 13233 0x130: 0x2100001, 13234 0x140: 0x100001, 13235 0x150: 0x2000400, 13236 0x160: 0x2100400, 13237 0x170: 0x100401, 13238 0x180: 0x401, 13239 0x190: 0x2100401, 13240 0x1a0: 0x100400, 13241 0x1b0: 0x1, 13242 0x1c0: 0x0, 13243 0x1d0: 0x2100000, 13244 0x1e0: 0x2000001, 13245 0x1f0: 0x400, 13246 0x108: 0x100400, 13247 0x118: 0x2000401, 13248 0x128: 0x2100001, 13249 0x138: 0x1, 13250 0x148: 0x2000000, 13251 0x158: 0x100000, 13252 0x168: 0x401, 13253 0x178: 0x2100400, 13254 0x188: 0x2000001, 13255 0x198: 0x2100000, 13256 0x1a8: 0x0, 13257 0x1b8: 0x2100401, 13258 0x1c8: 0x100401, 13259 0x1d8: 0x400, 13260 0x1e8: 0x2000400, 13261 0x1f8: 0x100001 13262 }, 13263 { 13264 0x0: 0x8000820, 13265 0x1: 0x20000, 13266 0x2: 0x8000000, 13267 0x3: 0x20, 13268 0x4: 0x20020, 13269 0x5: 0x8020820, 13270 0x6: 0x8020800, 13271 0x7: 0x800, 13272 0x8: 0x8020000, 13273 0x9: 0x8000800, 13274 0xa: 0x20800, 13275 0xb: 0x8020020, 13276 0xc: 0x820, 13277 0xd: 0x0, 13278 0xe: 0x8000020, 13279 0xf: 0x20820, 13280 0x80000000: 0x800, 13281 0x80000001: 0x8020820, 13282 0x80000002: 0x8000820, 13283 0x80000003: 0x8000000, 13284 0x80000004: 0x8020000, 13285 0x80000005: 0x20800, 13286 0x80000006: 0x20820, 13287 0x80000007: 0x20, 13288 0x80000008: 0x8000020, 13289 0x80000009: 0x820, 13290 0x8000000a: 0x20020, 13291 0x8000000b: 0x8020800, 13292 0x8000000c: 0x0, 13293 0x8000000d: 0x8020020, 13294 0x8000000e: 0x8000800, 13295 0x8000000f: 0x20000, 13296 0x10: 0x20820, 13297 0x11: 0x8020800, 13298 0x12: 0x20, 13299 0x13: 0x800, 13300 0x14: 0x8000800, 13301 0x15: 0x8000020, 13302 0x16: 0x8020020, 13303 0x17: 0x20000, 13304 0x18: 0x0, 13305 0x19: 0x20020, 13306 0x1a: 0x8020000, 13307 0x1b: 0x8000820, 13308 0x1c: 0x8020820, 13309 0x1d: 0x20800, 13310 0x1e: 0x820, 13311 0x1f: 0x8000000, 13312 0x80000010: 0x20000, 13313 0x80000011: 0x800, 13314 0x80000012: 0x8020020, 13315 0x80000013: 0x20820, 13316 0x80000014: 0x20, 13317 0x80000015: 0x8020000, 13318 0x80000016: 0x8000000, 13319 0x80000017: 0x8000820, 13320 0x80000018: 0x8020820, 13321 0x80000019: 0x8000020, 13322 0x8000001a: 0x8000800, 13323 0x8000001b: 0x0, 13324 0x8000001c: 0x20800, 13325 0x8000001d: 0x820, 13326 0x8000001e: 0x20020, 13327 0x8000001f: 0x8020800 13328 } 13329 ]; 13330 13331 // Masks that select the SBOX input 13332 var SBOX_MASK = [ 13333 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 13334 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 13335 ]; 13336 13337 /** 13338 * DES block cipher algorithm. 13339 */ 13340 var DES = C_algo.DES = BlockCipher.extend({ 13341 _doReset: function () { 13342 // Shortcuts 13343 var key = this._key; 13344 var keyWords = key.words; 13345 13346 // Select 56 bits according to PC1 13347 var keyBits = []; 13348 for (var i = 0; i < 56; i++) { 13349 var keyBitPos = PC1[i] - 1; 13350 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 13351 } 13352 13353 // Assemble 16 subkeys 13354 var subKeys = this._subKeys = []; 13355 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 13356 // Create subkey 13357 var subKey = subKeys[nSubKey] = []; 13358 13359 // Shortcut 13360 var bitShift = BIT_SHIFTS[nSubKey]; 13361 13362 // Select 48 bits according to PC2 13363 for (var i = 0; i < 24; i++) { 13364 // Select from the left 28 key bits 13365 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 13366 13367 // Select from the right 28 key bits 13368 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 13369 } 13370 13371 // Since each subkey is applied to an expanded 32-bit input, 13372 // the subkey can be broken into 8 values scaled to 32-bits, 13373 // which allows the key to be used without expansion 13374 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 13375 for (var i = 1; i < 7; i++) { 13376 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 13377 } 13378 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 13379 } 13380 13381 // Compute inverse subkeys 13382 var invSubKeys = this._invSubKeys = []; 13383 for (var i = 0; i < 16; i++) { 13384 invSubKeys[i] = subKeys[15 - i]; 13385 } 13386 }, 13387 13388 encryptBlock: function (M, offset) { 13389 this._doCryptBlock(M, offset, this._subKeys); 13390 }, 13391 13392 decryptBlock: function (M, offset) { 13393 this._doCryptBlock(M, offset, this._invSubKeys); 13394 }, 13395 13396 _doCryptBlock: function (M, offset, subKeys) { 13397 // Get input 13398 this._lBlock = M[offset]; 13399 this._rBlock = M[offset + 1]; 13400 13401 // Initial permutation 13402 exchangeLR.call(this, 4, 0x0f0f0f0f); 13403 exchangeLR.call(this, 16, 0x0000ffff); 13404 exchangeRL.call(this, 2, 0x33333333); 13405 exchangeRL.call(this, 8, 0x00ff00ff); 13406 exchangeLR.call(this, 1, 0x55555555); 13407 13408 // Rounds 13409 for (var round = 0; round < 16; round++) { 13410 // Shortcuts 13411 var subKey = subKeys[round]; 13412 var lBlock = this._lBlock; 13413 var rBlock = this._rBlock; 13414 13415 // Feistel function 13416 var f = 0; 13417 for (var i = 0; i < 8; i++) { 13418 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 13419 } 13420 this._lBlock = rBlock; 13421 this._rBlock = lBlock ^ f; 13422 } 13423 13424 // Undo swap from last round 13425 var t = this._lBlock; 13426 this._lBlock = this._rBlock; 13427 this._rBlock = t; 13428 13429 // Final permutation 13430 exchangeLR.call(this, 1, 0x55555555); 13431 exchangeRL.call(this, 8, 0x00ff00ff); 13432 exchangeRL.call(this, 2, 0x33333333); 13433 exchangeLR.call(this, 16, 0x0000ffff); 13434 exchangeLR.call(this, 4, 0x0f0f0f0f); 13435 13436 // Set output 13437 M[offset] = this._lBlock; 13438 M[offset + 1] = this._rBlock; 13439 }, 13440 13441 keySize: 64/32, 13442 13443 ivSize: 64/32, 13444 13445 blockSize: 64/32 13446 }); 13447 13448 // Swap bits across the left and right words 13449 function exchangeLR(offset, mask) { 13450 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13451 this._rBlock ^= t; 13452 this._lBlock ^= t << offset; 13453 } 13454 13455 function exchangeRL(offset, mask) { 13456 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13457 this._lBlock ^= t; 13458 this._rBlock ^= t << offset; 13459 } 13460 13461 /** 13462 * Shortcut functions to the cipher's object interface. 13463 * 13464 * @example 13465 * 13466 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13467 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13468 */ 13469 C.DES = BlockCipher._createHelper(DES); 13470 13471 /** 13472 * Triple-DES block cipher algorithm. 13473 */ 13474 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13475 _doReset: function () { 13476 // Shortcuts 13477 var key = this._key; 13478 var keyWords = key.words; 13479 13480 // Create DES instances 13481 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13482 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13483 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13484 }, 13485 13486 encryptBlock: function (M, offset) { 13487 this._des1.encryptBlock(M, offset); 13488 this._des2.decryptBlock(M, offset); 13489 this._des3.encryptBlock(M, offset); 13490 }, 13491 13492 decryptBlock: function (M, offset) { 13493 this._des3.decryptBlock(M, offset); 13494 this._des2.encryptBlock(M, offset); 13495 this._des1.decryptBlock(M, offset); 13496 }, 13497 13498 keySize: 192/32, 13499 13500 ivSize: 64/32, 13501 13502 blockSize: 64/32 13503 }); 13504 13505 /** 13506 * Shortcut functions to the cipher's object interface. 13507 * 13508 * @example 13509 * 13510 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13511 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13512 */ 13513 C.TripleDES = BlockCipher._createHelper(TripleDES); 13514 }()); 13515 13516 13517 return CryptoJS.TripleDES; 13518 13519 })); 13520 },{"./cipher-core":52,"./core":53,"./enc-base64":54,"./evpkdf":56,"./md5":61}],84:[function(require,module,exports){ 13521 ;(function (root, factory) { 13522 if (typeof exports === "object") { 13523 // CommonJS 13524 module.exports = exports = factory(require("./core")); 13525 } 13526 else if (typeof define === "function" && define.amd) { 13527 // AMD 13528 define(["./core"], factory); 13529 } 13530 else { 13531 // Global (browser) 13532 factory(root.CryptoJS); 13533 } 13534 }(this, function (CryptoJS) { 13535 13536 (function (undefined) { 13537 // Shortcuts 13538 var C = CryptoJS; 13539 var C_lib = C.lib; 13540 var Base = C_lib.Base; 13541 var X32WordArray = C_lib.WordArray; 13542 13543 /** 13544 * x64 namespace. 13545 */ 13546 var C_x64 = C.x64 = {}; 13547 13548 /** 13549 * A 64-bit word. 13550 */ 13551 var X64Word = C_x64.Word = Base.extend({ 13552 /** 13553 * Initializes a newly created 64-bit word. 13554 * 13555 * @param {number} high The high 32 bits. 13556 * @param {number} low The low 32 bits. 13557 * 13558 * @example 13559 * 13560 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13561 */ 13562 init: function (high, low) { 13563 this.high = high; 13564 this.low = low; 13565 } 13566 13567 /** 13568 * Bitwise NOTs this word. 13569 * 13570 * @return {X64Word} A new x64-Word object after negating. 13571 * 13572 * @example 13573 * 13574 * var negated = x64Word.not(); 13575 */ 13576 // not: function () { 13577 // var high = ~this.high; 13578 // var low = ~this.low; 13579 13580 // return X64Word.create(high, low); 13581 // }, 13582 13583 /** 13584 * Bitwise ANDs this word with the passed word. 13585 * 13586 * @param {X64Word} word The x64-Word to AND with this word. 13587 * 13588 * @return {X64Word} A new x64-Word object after ANDing. 13589 * 13590 * @example 13591 * 13592 * var anded = x64Word.and(anotherX64Word); 13593 */ 13594 // and: function (word) { 13595 // var high = this.high & word.high; 13596 // var low = this.low & word.low; 13597 13598 // return X64Word.create(high, low); 13599 // }, 13600 13601 /** 13602 * Bitwise ORs this word with the passed word. 13603 * 13604 * @param {X64Word} word The x64-Word to OR with this word. 13605 * 13606 * @return {X64Word} A new x64-Word object after ORing. 13607 * 13608 * @example 13609 * 13610 * var ored = x64Word.or(anotherX64Word); 13611 */ 13612 // or: function (word) { 13613 // var high = this.high | word.high; 13614 // var low = this.low | word.low; 13615 13616 // return X64Word.create(high, low); 13617 // }, 13618 13619 /** 13620 * Bitwise XORs this word with the passed word. 13621 * 13622 * @param {X64Word} word The x64-Word to XOR with this word. 13623 * 13624 * @return {X64Word} A new x64-Word object after XORing. 13625 * 13626 * @example 13627 * 13628 * var xored = x64Word.xor(anotherX64Word); 13629 */ 13630 // xor: function (word) { 13631 // var high = this.high ^ word.high; 13632 // var low = this.low ^ word.low; 13633 13634 // return X64Word.create(high, low); 13635 // }, 13636 13637 /** 13638 * Shifts this word n bits to the left. 13639 * 13640 * @param {number} n The number of bits to shift. 13641 * 13642 * @return {X64Word} A new x64-Word object after shifting. 13643 * 13644 * @example 13645 * 13646 * var shifted = x64Word.shiftL(25); 13647 */ 13648 // shiftL: function (n) { 13649 // if (n < 32) { 13650 // var high = (this.high << n) | (this.low >>> (32 - n)); 13651 // var low = this.low << n; 13652 // } else { 13653 // var high = this.low << (n - 32); 13654 // var low = 0; 13655 // } 13656 13657 // return X64Word.create(high, low); 13658 // }, 13659 13660 /** 13661 * Shifts this word n bits to the right. 13662 * 13663 * @param {number} n The number of bits to shift. 13664 * 13665 * @return {X64Word} A new x64-Word object after shifting. 13666 * 13667 * @example 13668 * 13669 * var shifted = x64Word.shiftR(7); 13670 */ 13671 // shiftR: function (n) { 13672 // if (n < 32) { 13673 // var low = (this.low >>> n) | (this.high << (32 - n)); 13674 // var high = this.high >>> n; 13675 // } else { 13676 // var low = this.high >>> (n - 32); 13677 // var high = 0; 13678 // } 13679 13680 // return X64Word.create(high, low); 13681 // }, 13682 13683 /** 13684 * Rotates this word n bits to the left. 13685 * 13686 * @param {number} n The number of bits to rotate. 13687 * 13688 * @return {X64Word} A new x64-Word object after rotating. 13689 * 13690 * @example 13691 * 13692 * var rotated = x64Word.rotL(25); 13693 */ 13694 // rotL: function (n) { 13695 // return this.shiftL(n).or(this.shiftR(64 - n)); 13696 // }, 13697 13698 /** 13699 * Rotates this word n bits to the right. 13700 * 13701 * @param {number} n The number of bits to rotate. 13702 * 13703 * @return {X64Word} A new x64-Word object after rotating. 13704 * 13705 * @example 13706 * 13707 * var rotated = x64Word.rotR(7); 13708 */ 13709 // rotR: function (n) { 13710 // return this.shiftR(n).or(this.shiftL(64 - n)); 13711 // }, 13712 13713 /** 13714 * Adds this word with the passed word. 13715 * 13716 * @param {X64Word} word The x64-Word to add with this word. 13717 * 13718 * @return {X64Word} A new x64-Word object after adding. 13719 * 13720 * @example 13721 * 13722 * var added = x64Word.add(anotherX64Word); 13723 */ 13724 // add: function (word) { 13725 // var low = (this.low + word.low) | 0; 13726 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13727 // var high = (this.high + word.high + carry) | 0; 13728 13729 // return X64Word.create(high, low); 13730 // } 13731 }); 13732 13733 /** 13734 * An array of 64-bit words. 13735 * 13736 * @property {Array} words The array of CryptoJS.x64.Word objects. 13737 * @property {number} sigBytes The number of significant bytes in this word array. 13738 */ 13739 var X64WordArray = C_x64.WordArray = Base.extend({ 13740 /** 13741 * Initializes a newly created word array. 13742 * 13743 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13744 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13745 * 13746 * @example 13747 * 13748 * var wordArray = CryptoJS.x64.WordArray.create(); 13749 * 13750 * var wordArray = CryptoJS.x64.WordArray.create([ 13751 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13752 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13753 * ]); 13754 * 13755 * var wordArray = CryptoJS.x64.WordArray.create([ 13756 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13757 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13758 * ], 10); 13759 */ 13760 init: function (words, sigBytes) { 13761 words = this.words = words || []; 13762 13763 if (sigBytes != undefined) { 13764 this.sigBytes = sigBytes; 13765 } else { 13766 this.sigBytes = words.length * 8; 13767 } 13768 }, 13769 13770 /** 13771 * Converts this 64-bit word array to a 32-bit word array. 13772 * 13773 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13774 * 13775 * @example 13776 * 13777 * var x32WordArray = x64WordArray.toX32(); 13778 */ 13779 toX32: function () { 13780 // Shortcuts 13781 var x64Words = this.words; 13782 var x64WordsLength = x64Words.length; 13783 13784 // Convert 13785 var x32Words = []; 13786 for (var i = 0; i < x64WordsLength; i++) { 13787 var x64Word = x64Words[i]; 13788 x32Words.push(x64Word.high); 13789 x32Words.push(x64Word.low); 13790 } 13791 13792 return X32WordArray.create(x32Words, this.sigBytes); 13793 }, 13794 13795 /** 13796 * Creates a copy of this word array. 13797 * 13798 * @return {X64WordArray} The clone. 13799 * 13800 * @example 13801 * 13802 * var clone = x64WordArray.clone(); 13803 */ 13804 clone: function () { 13805 var clone = Base.clone.call(this); 13806 13807 // Clone "words" array 13808 var words = clone.words = this.words.slice(0); 13809 13810 // Clone each X64Word object 13811 var wordsLength = words.length; 13812 for (var i = 0; i < wordsLength; i++) { 13813 words[i] = words[i].clone(); 13814 } 13815 13816 return clone; 13817 } 13818 }); 13819 }()); 13820 13821 13822 return CryptoJS; 13823 13824 })); 13825 },{"./core":53}],85:[function(require,module,exports){ 13826 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13827 ;(function(root) { 13828 13829 // Detect free variables `exports` 13830 var freeExports = typeof exports == 'object' && exports; 13831 13832 // Detect free variable `module` 13833 var freeModule = typeof module == 'object' && module && 13834 module.exports == freeExports && module; 13835 13836 // Detect free variable `global`, from Node.js or Browserified code, 13837 // and use it as `root` 13838 var freeGlobal = typeof global == 'object' && global; 13839 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13840 root = freeGlobal; 13841 } 13842 13843 /*--------------------------------------------------------------------------*/ 13844 13845 var stringFromCharCode = String.fromCharCode; 13846 13847 // Taken from https://mths.be/punycode 13848 function ucs2decode(string) { 13849 var output = []; 13850 var counter = 0; 13851 var length = string.length; 13852 var value; 13853 var extra; 13854 while (counter < length) { 13855 value = string.charCodeAt(counter++); 13856 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13857 // high surrogate, and there is a next character 13858 extra = string.charCodeAt(counter++); 13859 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13860 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13861 } else { 13862 // unmatched surrogate; only append this code unit, in case the next 13863 // code unit is the high surrogate of a surrogate pair 13864 output.push(value); 13865 counter--; 13866 } 13867 } else { 13868 output.push(value); 13869 } 13870 } 13871 return output; 13872 } 13873 13874 // Taken from https://mths.be/punycode 13875 function ucs2encode(array) { 13876 var length = array.length; 13877 var index = -1; 13878 var value; 13879 var output = ''; 13880 while (++index < length) { 13881 value = array[index]; 13882 if (value > 0xFFFF) { 13883 value -= 0x10000; 13884 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13885 value = 0xDC00 | value & 0x3FF; 13886 } 13887 output += stringFromCharCode(value); 13888 } 13889 return output; 13890 } 13891 13892 function checkScalarValue(codePoint) { 13893 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13894 throw Error( 13895 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13896 ' is not a scalar value' 13897 ); 13898 } 13899 } 13900 /*--------------------------------------------------------------------------*/ 13901 13902 function createByte(codePoint, shift) { 13903 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13904 } 13905 13906 function encodeCodePoint(codePoint) { 13907 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13908 return stringFromCharCode(codePoint); 13909 } 13910 var symbol = ''; 13911 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13912 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13913 } 13914 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13915 checkScalarValue(codePoint); 13916 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13917 symbol += createByte(codePoint, 6); 13918 } 13919 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13920 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13921 symbol += createByte(codePoint, 12); 13922 symbol += createByte(codePoint, 6); 13923 } 13924 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13925 return symbol; 13926 } 13927 13928 function utf8encode(string) { 13929 var codePoints = ucs2decode(string); 13930 var length = codePoints.length; 13931 var index = -1; 13932 var codePoint; 13933 var byteString = ''; 13934 while (++index < length) { 13935 codePoint = codePoints[index]; 13936 byteString += encodeCodePoint(codePoint); 13937 } 13938 return byteString; 13939 } 13940 13941 /*--------------------------------------------------------------------------*/ 13942 13943 function readContinuationByte() { 13944 if (byteIndex >= byteCount) { 13945 throw Error('Invalid byte index'); 13946 } 13947 13948 var continuationByte = byteArray[byteIndex] & 0xFF; 13949 byteIndex++; 13950 13951 if ((continuationByte & 0xC0) == 0x80) { 13952 return continuationByte & 0x3F; 13953 } 13954 13955 // If we end up here, it’s not a continuation byte 13956 throw Error('Invalid continuation byte'); 13957 } 13958 13959 function decodeSymbol() { 13960 var byte1; 13961 var byte2; 13962 var byte3; 13963 var byte4; 13964 var codePoint; 13965 13966 if (byteIndex > byteCount) { 13967 throw Error('Invalid byte index'); 13968 } 13969 13970 if (byteIndex == byteCount) { 13971 return false; 13972 } 13973 13974 // Read first byte 13975 byte1 = byteArray[byteIndex] & 0xFF; 13976 byteIndex++; 13977 13978 // 1-byte sequence (no continuation bytes) 13979 if ((byte1 & 0x80) == 0) { 13980 return byte1; 13981 } 13982 13983 // 2-byte sequence 13984 if ((byte1 & 0xE0) == 0xC0) { 13985 byte2 = readContinuationByte(); 13986 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13987 if (codePoint >= 0x80) { 13988 return codePoint; 13989 } else { 13990 throw Error('Invalid continuation byte'); 13991 } 13992 } 13993 13994 // 3-byte sequence (may include unpaired surrogates) 13995 if ((byte1 & 0xF0) == 0xE0) { 13996 byte2 = readContinuationByte(); 13997 byte3 = readContinuationByte(); 13998 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13999 if (codePoint >= 0x0800) { 14000 checkScalarValue(codePoint); 14001 return codePoint; 14002 } else { 14003 throw Error('Invalid continuation byte'); 14004 } 14005 } 14006 14007 // 4-byte sequence 14008 if ((byte1 & 0xF8) == 0xF0) { 14009 byte2 = readContinuationByte(); 14010 byte3 = readContinuationByte(); 14011 byte4 = readContinuationByte(); 14012 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 14013 (byte3 << 0x06) | byte4; 14014 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 14015 return codePoint; 14016 } 14017 } 14018 14019 throw Error('Invalid UTF-8 detected'); 14020 } 14021 14022 var byteArray; 14023 var byteCount; 14024 var byteIndex; 14025 function utf8decode(byteString) { 14026 byteArray = ucs2decode(byteString); 14027 byteCount = byteArray.length; 14028 byteIndex = 0; 14029 var codePoints = []; 14030 var tmp; 14031 while ((tmp = decodeSymbol()) !== false) { 14032 codePoints.push(tmp); 14033 } 14034 return ucs2encode(codePoints); 14035 } 14036 14037 /*--------------------------------------------------------------------------*/ 14038 14039 var utf8 = { 14040 'version': '2.1.2', 14041 'encode': utf8encode, 14042 'decode': utf8decode 14043 }; 14044 14045 // Some AMD build optimizers, like r.js, check for specific condition patterns 14046 // like the following: 14047 if ( 14048 typeof define == 'function' && 14049 typeof define.amd == 'object' && 14050 define.amd 14051 ) { 14052 define(function() { 14053 return utf8; 14054 }); 14055 } else if (freeExports && !freeExports.nodeType) { 14056 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 14057 freeModule.exports = utf8; 14058 } else { // in Narwhal or RingoJS v0.7.0- 14059 var object = {}; 14060 var hasOwnProperty = object.hasOwnProperty; 14061 for (var key in utf8) { 14062 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 14063 } 14064 } 14065 } else { // in Rhino or a web browser 14066 root.utf8 = utf8; 14067 } 14068 14069 }(this)); 14070 14071 },{}],86:[function(require,module,exports){ 14072 module.exports = XMLHttpRequest; 14073 14074 },{}],"bignumber.js":[function(require,module,exports){ 14075 'use strict'; 14076 14077 module.exports = BigNumber; // jshint ignore:line 14078 14079 14080 },{}],"web3":[function(require,module,exports){ 14081 var Web3 = require('./lib/web3'); 14082 14083 // dont override global variable 14084 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 14085 window.Web3 = Web3; 14086 } 14087 14088 module.exports = Web3; 14089 14090 },{"./lib/web3":22}]},{},["web3"])