github.com/core-coin/go-core/v2@v2.1.9/internal/jsre/deps/web3.js (about) 1 require = (function () { function r(e, n, t) { function o(i, f) { if (!n[i]) { if (!e[i]) { var c = "function" == typeof require && require; if (!f && c) return c(i, !0); if (u) return u(i, !0); var a = new Error("Cannot find module '" + i + "'"); throw a.code = "MODULE_NOT_FOUND", a } var p = n[i] = { exports: {} }; e[i][0].call(p.exports, function (r) { var n = e[i][1][r]; return o(n || r) }, p, p.exports, r, e, n, t) } return n[i].exports } for (var u = "function" == typeof require && require, i = 0; i < t.length; i++)o(t[i]); return o } return r })()({ 2 1: [function (require, module, exports) { 3 module.exports = [ 4 { 5 "constant": true, 6 "inputs": [ 7 { 8 "name": "_owner", 9 "type": "address" 10 } 11 ], 12 "name": "name", 13 "outputs": [ 14 { 15 "name": "o_name", 16 "type": "bytes32" 17 } 18 ], 19 "type": "function" 20 }, 21 { 22 "constant": true, 23 "inputs": [ 24 { 25 "name": "_name", 26 "type": "bytes32" 27 } 28 ], 29 "name": "owner", 30 "outputs": [ 31 { 32 "name": "", 33 "type": "address" 34 } 35 ], 36 "type": "function" 37 }, 38 { 39 "constant": true, 40 "inputs": [ 41 { 42 "name": "_name", 43 "type": "bytes32" 44 } 45 ], 46 "name": "content", 47 "outputs": [ 48 { 49 "name": "", 50 "type": "bytes32" 51 } 52 ], 53 "type": "function" 54 }, 55 { 56 "constant": true, 57 "inputs": [ 58 { 59 "name": "_name", 60 "type": "bytes32" 61 } 62 ], 63 "name": "addr", 64 "outputs": [ 65 { 66 "name": "", 67 "type": "address" 68 } 69 ], 70 "type": "function" 71 }, 72 { 73 "constant": false, 74 "inputs": [ 75 { 76 "name": "_name", 77 "type": "bytes32" 78 } 79 ], 80 "name": "reserve", 81 "outputs": [], 82 "type": "function" 83 }, 84 { 85 "constant": true, 86 "inputs": [ 87 { 88 "name": "_name", 89 "type": "bytes32" 90 } 91 ], 92 "name": "subRegistrar", 93 "outputs": [ 94 { 95 "name": "", 96 "type": "address" 97 } 98 ], 99 "type": "function" 100 }, 101 { 102 "constant": false, 103 "inputs": [ 104 { 105 "name": "_name", 106 "type": "bytes32" 107 }, 108 { 109 "name": "_newOwner", 110 "type": "address" 111 } 112 ], 113 "name": "transfer", 114 "outputs": [], 115 "type": "function" 116 }, 117 { 118 "constant": false, 119 "inputs": [ 120 { 121 "name": "_name", 122 "type": "bytes32" 123 }, 124 { 125 "name": "_registrar", 126 "type": "address" 127 } 128 ], 129 "name": "setSubRegistrar", 130 "outputs": [], 131 "type": "function" 132 }, 133 { 134 "constant": false, 135 "inputs": [], 136 "name": "Registrar", 137 "outputs": [], 138 "type": "function" 139 }, 140 { 141 "constant": false, 142 "inputs": [ 143 { 144 "name": "_name", 145 "type": "bytes32" 146 }, 147 { 148 "name": "_a", 149 "type": "address" 150 }, 151 { 152 "name": "_primary", 153 "type": "bool" 154 } 155 ], 156 "name": "setAddress", 157 "outputs": [], 158 "type": "function" 159 }, 160 { 161 "constant": false, 162 "inputs": [ 163 { 164 "name": "_name", 165 "type": "bytes32" 166 }, 167 { 168 "name": "_content", 169 "type": "bytes32" 170 } 171 ], 172 "name": "setContent", 173 "outputs": [], 174 "type": "function" 175 }, 176 { 177 "constant": false, 178 "inputs": [ 179 { 180 "name": "_name", 181 "type": "bytes32" 182 } 183 ], 184 "name": "disown", 185 "outputs": [], 186 "type": "function" 187 }, 188 { 189 "anonymous": false, 190 "inputs": [ 191 { 192 "indexed": true, 193 "name": "_name", 194 "type": "bytes32" 195 }, 196 { 197 "indexed": false, 198 "name": "_winner", 199 "type": "address" 200 } 201 ], 202 "name": "AuctionEnded", 203 "type": "event" 204 }, 205 { 206 "anonymous": false, 207 "inputs": [ 208 { 209 "indexed": true, 210 "name": "_name", 211 "type": "bytes32" 212 }, 213 { 214 "indexed": false, 215 "name": "_bidder", 216 "type": "address" 217 }, 218 { 219 "indexed": false, 220 "name": "_value", 221 "type": "uint256" 222 } 223 ], 224 "name": "NewBid", 225 "type": "event" 226 }, 227 { 228 "anonymous": false, 229 "inputs": [ 230 { 231 "indexed": true, 232 "name": "name", 233 "type": "bytes32" 234 } 235 ], 236 "name": "Changed", 237 "type": "event" 238 }, 239 { 240 "anonymous": false, 241 "inputs": [ 242 { 243 "indexed": true, 244 "name": "name", 245 "type": "bytes32" 246 }, 247 { 248 "indexed": true, 249 "name": "addr", 250 "type": "address" 251 } 252 ], 253 "name": "PrimaryChanged", 254 "type": "event" 255 } 256 ] 257 258 }, {}], 2: [function (require, module, exports) { 259 module.exports = [ 260 { 261 "constant": true, 262 "inputs": [ 263 { 264 "name": "_name", 265 "type": "bytes32" 266 } 267 ], 268 "name": "owner", 269 "outputs": [ 270 { 271 "name": "", 272 "type": "address" 273 } 274 ], 275 "type": "function" 276 }, 277 { 278 "constant": false, 279 "inputs": [ 280 { 281 "name": "_name", 282 "type": "bytes32" 283 }, 284 { 285 "name": "_refund", 286 "type": "address" 287 } 288 ], 289 "name": "disown", 290 "outputs": [], 291 "type": "function" 292 }, 293 { 294 "constant": true, 295 "inputs": [ 296 { 297 "name": "_name", 298 "type": "bytes32" 299 } 300 ], 301 "name": "addr", 302 "outputs": [ 303 { 304 "name": "", 305 "type": "address" 306 } 307 ], 308 "type": "function" 309 }, 310 { 311 "constant": false, 312 "inputs": [ 313 { 314 "name": "_name", 315 "type": "bytes32" 316 } 317 ], 318 "name": "reserve", 319 "outputs": [], 320 "type": "function" 321 }, 322 { 323 "constant": false, 324 "inputs": [ 325 { 326 "name": "_name", 327 "type": "bytes32" 328 }, 329 { 330 "name": "_newOwner", 331 "type": "address" 332 } 333 ], 334 "name": "transfer", 335 "outputs": [], 336 "type": "function" 337 }, 338 { 339 "constant": false, 340 "inputs": [ 341 { 342 "name": "_name", 343 "type": "bytes32" 344 }, 345 { 346 "name": "_a", 347 "type": "address" 348 } 349 ], 350 "name": "setAddr", 351 "outputs": [], 352 "type": "function" 353 }, 354 { 355 "anonymous": false, 356 "inputs": [ 357 { 358 "indexed": true, 359 "name": "name", 360 "type": "bytes32" 361 } 362 ], 363 "name": "Changed", 364 "type": "event" 365 } 366 ] 367 368 }, {}], 3: [function (require, module, exports) { 369 module.exports = [ 370 { 371 "constant": false, 372 "inputs": [ 373 { 374 "name": "from", 375 "type": "bytes32" 376 }, 377 { 378 "name": "to", 379 "type": "address" 380 }, 381 { 382 "name": "value", 383 "type": "uint256" 384 } 385 ], 386 "name": "transfer", 387 "outputs": [], 388 "type": "function" 389 }, 390 { 391 "constant": false, 392 "inputs": [ 393 { 394 "name": "from", 395 "type": "bytes32" 396 }, 397 { 398 "name": "to", 399 "type": "address" 400 }, 401 { 402 "name": "indirectId", 403 "type": "bytes32" 404 }, 405 { 406 "name": "value", 407 "type": "uint256" 408 } 409 ], 410 "name": "icapTransfer", 411 "outputs": [], 412 "type": "function" 413 }, 414 { 415 "constant": false, 416 "inputs": [ 417 { 418 "name": "to", 419 "type": "bytes32" 420 } 421 ], 422 "name": "deposit", 423 "outputs": [], 424 "payable": true, 425 "type": "function" 426 }, 427 { 428 "anonymous": false, 429 "inputs": [ 430 { 431 "indexed": true, 432 "name": "from", 433 "type": "address" 434 }, 435 { 436 "indexed": false, 437 "name": "value", 438 "type": "uint256" 439 } 440 ], 441 "name": "AnonymousDeposit", 442 "type": "event" 443 }, 444 { 445 "anonymous": false, 446 "inputs": [ 447 { 448 "indexed": true, 449 "name": "from", 450 "type": "address" 451 }, 452 { 453 "indexed": true, 454 "name": "to", 455 "type": "bytes32" 456 }, 457 { 458 "indexed": false, 459 "name": "value", 460 "type": "uint256" 461 } 462 ], 463 "name": "Deposit", 464 "type": "event" 465 }, 466 { 467 "anonymous": false, 468 "inputs": [ 469 { 470 "indexed": true, 471 "name": "from", 472 "type": "bytes32" 473 }, 474 { 475 "indexed": true, 476 "name": "to", 477 "type": "address" 478 }, 479 { 480 "indexed": false, 481 "name": "value", 482 "type": "uint256" 483 } 484 ], 485 "name": "Transfer", 486 "type": "event" 487 }, 488 { 489 "anonymous": false, 490 "inputs": [ 491 { 492 "indexed": true, 493 "name": "from", 494 "type": "bytes32" 495 }, 496 { 497 "indexed": true, 498 "name": "to", 499 "type": "address" 500 }, 501 { 502 "indexed": false, 503 "name": "indirectId", 504 "type": "bytes32" 505 }, 506 { 507 "indexed": false, 508 "name": "value", 509 "type": "uint256" 510 } 511 ], 512 "name": "IcapTransfer", 513 "type": "event" 514 } 515 ] 516 517 }, {}], 4: [function (require, module, exports) { 518 var f = require('./formatters'); 519 var YlemType = require('./type'); 520 521 /** 522 * YlemTypeAddress is a prootype that represents address type 523 * It matches: 524 * address 525 * address[] 526 * address[4] 527 * address[][] 528 * address[3][] 529 * address[][6][], ... 530 */ 531 var YlemTypeAddress = function () { 532 this._inputFormatter = f.formatInputInt; 533 this._outputFormatter = f.formatOutputAddress; 534 }; 535 536 YlemTypeAddress.prototype = new YlemType({}); 537 YlemTypeAddress.prototype.constructor = YlemTypeAddress; 538 539 YlemTypeAddress.prototype.isType = function (name) { 540 return !!name.match(/address(\[([0-9]*)\])?/); 541 }; 542 543 module.exports = YlemTypeAddress; 544 545 }, { "./formatters": 9, "./type": 14 }], 5: [function (require, module, exports) { 546 var f = require('./formatters'); 547 var YlemType = require('./type'); 548 549 /** 550 * YlemTypeBool is a prootype that represents bool type 551 * It matches: 552 * bool 553 * bool[] 554 * bool[4] 555 * bool[][] 556 * bool[3][] 557 * bool[][6][], ... 558 */ 559 var YlemTypeBool = function () { 560 this._inputFormatter = f.formatInputBool; 561 this._outputFormatter = f.formatOutputBool; 562 }; 563 564 YlemTypeBool.prototype = new YlemType({}); 565 YlemTypeBool.prototype.constructor = YlemTypeBool; 566 567 YlemTypeBool.prototype.isType = function (name) { 568 return !!name.match(/^bool(\[([0-9]*)\])*$/); 569 }; 570 571 module.exports = YlemTypeBool; 572 573 }, { "./formatters": 9, "./type": 14 }], 6: [function (require, module, exports) { 574 var f = require('./formatters'); 575 var YlemType = require('./type'); 576 577 /** 578 * YlemTypeBytes is a prototype that represents the bytes type. 579 * It matches: 580 * bytes 581 * bytes[] 582 * bytes[4] 583 * bytes[][] 584 * bytes[3][] 585 * bytes[][6][], ... 586 * bytes32 587 * bytes8[4] 588 * bytes[3][] 589 */ 590 var YlemTypeBytes = function () { 591 this._inputFormatter = f.formatInputBytes; 592 this._outputFormatter = f.formatOutputBytes; 593 }; 594 595 YlemTypeBytes.prototype = new YlemType({}); 596 YlemTypeBytes.prototype.constructor = YlemTypeBytes; 597 598 YlemTypeBytes.prototype.isType = function (name) { 599 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 600 }; 601 602 module.exports = YlemTypeBytes; 603 604 }, { "./formatters": 9, "./type": 14 }], 7: [function (require, module, exports) { 605 /* 606 This file is part of web3.js. 607 608 web3.js is free software: you can redistribute it and/or modify 609 it under the terms of the GNU Lesser General Public License as published by 610 the Free Software Foundation, either version 3 of the License, or 611 (at your option) any later version. 612 613 web3.js is distributed in the hope that it will be useful, 614 but WITHOUT ANY WARRANTY; without even the implied warranty of 615 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 616 GNU Lesser General Public License for more details. 617 618 You should have received a copy of the GNU Lesser General Public License 619 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 620 */ 621 /** 622 * @file coder.js 623 * @author Marek Kotewicz <marek@ethdev.com> 624 * @date 2015 625 */ 626 627 var f = require('./formatters'); 628 629 var YlemTypeAddress = require('./address'); 630 var YlemTypeBool = require('./bool'); 631 var YlemTypeInt = require('./int'); 632 var YlemTypeUInt = require('./uint'); 633 var YlemTypeDynamicBytes = require('./dynamicbytes'); 634 var YlemTypeString = require('./string'); 635 var YlemTypeReal = require('./real'); 636 var YlemTypeUReal = require('./ureal'); 637 var YlemTypeBytes = require('./bytes'); 638 639 var isDynamic = function (ylemType, type) { 640 return ylemType.isDynamicType(type) || 641 ylemType.isDynamicArray(type); 642 }; 643 644 /** 645 * YlemCoder prototype should be used to encode/decode ylem params of any type 646 */ 647 var YlemCoder = function (types) { 648 this._types = types; 649 }; 650 651 /** 652 * This method should be used to transform type to YlemType 653 * 654 * @method _requireType 655 * @param {String} type 656 * @returns {YlemType} 657 * @throws {Error} throws if no matching type is found 658 */ 659 YlemCoder.prototype._requireType = function (type) { 660 var ylemType = this._types.filter(function (t) { 661 return t.isType(type); 662 })[0]; 663 664 if (!ylemType) { 665 throw Error('invalid ylem type!: ' + type); 666 } 667 668 return ylemType; 669 }; 670 671 /** 672 * Should be used to encode plain param 673 * 674 * @method encodeParam 675 * @param {String} type 676 * @param {Object} plain param 677 * @return {String} encoded plain param 678 */ 679 YlemCoder.prototype.encodeParam = function (type, param) { 680 return this.encodeParams([type], [param]); 681 }; 682 683 /** 684 * Should be used to encode list of params 685 * 686 * @method encodeParams 687 * @param {Array} types 688 * @param {Array} params 689 * @return {String} encoded list of params 690 */ 691 YlemCoder.prototype.encodeParams = function (types, params) { 692 var ylemTypes = this.getYlemTypes(types); 693 694 var encodeds = ylemTypes.map(function (ylemType, index) { 695 return ylemType.encode(params[index], types[index]); 696 }); 697 698 var dynamicOffset = ylemTypes.reduce(function (acc, ylemType, index) { 699 var staticPartLength = ylemType.staticPartLength(types[index]); 700 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 701 702 return acc + (isDynamic(ylemTypes[index], types[index]) ? 703 32 : 704 roundedStaticPartLength); 705 }, 0); 706 707 var result = this.encodeMultiWithOffset(types, ylemTypes, encodeds, dynamicOffset); 708 709 return result; 710 }; 711 712 YlemCoder.prototype.encodeMultiWithOffset = function (types, ylemTypes, encodeds, dynamicOffset) { 713 var result = ""; 714 var self = this; 715 716 types.forEach(function (type, i) { 717 if (isDynamic(ylemTypes[i], types[i])) { 718 result += f.formatInputInt(dynamicOffset).encode(); 719 var e = self.encodeWithOffset(types[i], ylemTypes[i], encodeds[i], dynamicOffset); 720 dynamicOffset += e.length / 2; 721 } else { 722 // don't add length to dynamicOffset. it's already counted 723 result += self.encodeWithOffset(types[i], ylemTypes[i], encodeds[i], dynamicOffset); 724 } 725 726 // TODO: figure out nested arrays 727 }); 728 729 types.forEach(function (type, i) { 730 if (isDynamic(ylemTypes[i], types[i])) { 731 var e = self.encodeWithOffset(types[i], ylemTypes[i], encodeds[i], dynamicOffset); 732 dynamicOffset += e.length / 2; 733 result += e; 734 } 735 }); 736 return result; 737 }; 738 739 // TODO: refactor whole encoding! 740 YlemCoder.prototype.encodeWithOffset = function (type, ylemType, encoded, offset) { 741 var self = this; 742 if (ylemType.isDynamicArray(type)) { 743 return (function () { 744 // offset was already set 745 var nestedName = ylemType.nestedName(type); 746 var nestedStaticPartLength = ylemType.staticPartLength(nestedName); 747 var result = encoded[0]; 748 749 (function () { 750 var previousLength = 2; // in int 751 if (ylemType.isDynamicArray(nestedName)) { 752 for (var i = 1; i < encoded.length; i++) { 753 previousLength += +(encoded[i - 1])[0] || 0; 754 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 755 } 756 } 757 })(); 758 759 // first element is length, skip it 760 (function () { 761 for (var i = 0; i < encoded.length - 1; i++) { 762 var additionalOffset = result / 2; 763 result += self.encodeWithOffset(nestedName, ylemType, encoded[i + 1], offset + additionalOffset); 764 } 765 })(); 766 767 return result; 768 })(); 769 770 } else if (ylemType.isStaticArray(type)) { 771 return (function () { 772 var nestedName = ylemType.nestedName(type); 773 var nestedStaticPartLength = ylemType.staticPartLength(nestedName); 774 var result = ""; 775 776 777 if (ylemType.isDynamicArray(nestedName)) { 778 (function () { 779 var previousLength = 0; // in int 780 for (var i = 0; i < encoded.length; i++) { 781 // calculate length of previous item 782 previousLength += +(encoded[i - 1] || [])[0] || 0; 783 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 784 } 785 })(); 786 } 787 788 (function () { 789 for (var i = 0; i < encoded.length; i++) { 790 var additionalOffset = result / 2; 791 result += self.encodeWithOffset(nestedName, ylemType, encoded[i], offset + additionalOffset); 792 } 793 })(); 794 795 return result; 796 })(); 797 } 798 799 return encoded; 800 }; 801 802 /** 803 * Should be used to decode bytes to plain param 804 * 805 * @method decodeParam 806 * @param {String} type 807 * @param {String} bytes 808 * @return {Object} plain param 809 */ 810 YlemCoder.prototype.decodeParam = function (type, bytes) { 811 return this.decodeParams([type], bytes)[0]; 812 }; 813 814 /** 815 * Should be used to decode list of params 816 * 817 * @method decodeParam 818 * @param {Array} types 819 * @param {String} bytes 820 * @return {Array} array of plain params 821 */ 822 YlemCoder.prototype.decodeParams = function (types, bytes) { 823 var ylemTypes = this.getYlemTypes(types); 824 var offsets = this.getOffsets(types, ylemTypes); 825 826 return ylemTypes.map(function (ylemType, index) { 827 return ylemType.decode(bytes, offsets[index], types[index], index); 828 }); 829 }; 830 831 YlemCoder.prototype.getOffsets = function (types, ylemTypes) { 832 var lengths = ylemTypes.map(function (ylemType, index) { 833 return ylemType.staticPartLength(types[index]); 834 }); 835 836 for (var i = 1; i < lengths.length; i++) { 837 // sum with length of previous element 838 lengths[i] += lengths[i - 1]; 839 } 840 841 return lengths.map(function (length, index) { 842 // remove the current length, so the length is sum of previous elements 843 var staticPartLength = ylemTypes[index].staticPartLength(types[index]); 844 return length - staticPartLength; 845 }); 846 }; 847 848 YlemCoder.prototype.getYlemTypes = function (types) { 849 var self = this; 850 return types.map(function (type) { 851 return self._requireType(type); 852 }); 853 }; 854 855 var coder = new YlemCoder([ 856 new YlemTypeAddress(), 857 new YlemTypeBool(), 858 new YlemTypeInt(), 859 new YlemTypeUInt(), 860 new YlemTypeDynamicBytes(), 861 new YlemTypeBytes(), 862 new YlemTypeString(), 863 new YlemTypeReal(), 864 new YlemTypeUReal() 865 ]); 866 867 module.exports = coder; 868 869 }, { "./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) { 870 var f = require('./formatters'); 871 var YlemType = require('./type'); 872 873 var YlemTypeDynamicBytes = function () { 874 this._inputFormatter = f.formatInputDynamicBytes; 875 this._outputFormatter = f.formatOutputDynamicBytes; 876 }; 877 878 YlemTypeDynamicBytes.prototype = new YlemType({}); 879 YlemTypeDynamicBytes.prototype.constructor = YlemTypeDynamicBytes; 880 881 YlemTypeDynamicBytes.prototype.isType = function (name) { 882 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 883 }; 884 885 YlemTypeDynamicBytes.prototype.isDynamicType = function () { 886 return true; 887 }; 888 889 module.exports = YlemTypeDynamicBytes; 890 891 }, { "./formatters": 9, "./type": 14 }], 9: [function (require, module, exports) { 892 /* 893 This file is part of web3.js. 894 895 web3.js is free software: you can redistribute it and/or modify 896 it under the terms of the GNU Lesser General Public License as published by 897 the Free Software Foundation, either version 3 of the License, or 898 (at your option) any later version. 899 900 web3.js is distributed in the hope that it will be useful, 901 but WITHOUT ANY WARRANTY; without even the implied warranty of 902 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 903 GNU Lesser General Public License for more details. 904 905 You should have received a copy of the GNU Lesser General Public License 906 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 907 */ 908 /** 909 * @file formatters.js 910 * @author Marek Kotewicz <marek@ethdev.com> 911 * @date 2015 912 */ 913 914 var BigNumber = require('bignumber.js'); 915 var utils = require('../utils/utils'); 916 var c = require('../utils/config'); 917 var YlemParam = require('./param'); 918 919 920 /** 921 * Formats input value to byte representation of int 922 * If value is negative, return it's two's complement 923 * If the value is floating point, round it down 924 * 925 * @method formatInputInt 926 * @param {String|Number|BigNumber} value that needs to be formatted 927 * @returns {YlemParam} 928 */ 929 var formatInputInt = function (value) { 930 BigNumber.config(c.XCB_BIGNUMBER_ROUNDING_MODE); 931 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 932 return new YlemParam(result); 933 }; 934 935 /** 936 * Formats input bytes 937 * 938 * @method formatInputBytes 939 * @param {String} 940 * @returns {YlemParam} 941 */ 942 var formatInputBytes = function (value) { 943 var result = utils.toHex(value).substr(2); 944 var l = Math.floor((result.length + 63) / 64); 945 result = utils.padRight(result, l * 64); 946 return new YlemParam(result); 947 }; 948 949 /** 950 * Formats input bytes 951 * 952 * @method formatDynamicInputBytes 953 * @param {String} 954 * @returns {YlemParam} 955 */ 956 var formatInputDynamicBytes = function (value) { 957 var result = utils.toHex(value).substr(2); 958 var length = result.length / 2; 959 var l = Math.floor((result.length + 63) / 64); 960 result = utils.padRight(result, l * 64); 961 return new YlemParam(formatInputInt(length).value + result); 962 }; 963 964 /** 965 * Formats input value to byte representation of string 966 * 967 * @method formatInputString 968 * @param {String} 969 * @returns {YlemParam} 970 */ 971 var formatInputString = function (value) { 972 var result = utils.fromUtf8(value).substr(2); 973 var length = result.length / 2; 974 var l = Math.floor((result.length + 63) / 64); 975 result = utils.padRight(result, l * 64); 976 return new YlemParam(formatInputInt(length).value + result); 977 }; 978 979 /** 980 * Formats input value to byte representation of bool 981 * 982 * @method formatInputBool 983 * @param {Boolean} 984 * @returns {YlemParam} 985 */ 986 var formatInputBool = function (value) { 987 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 988 return new YlemParam(result); 989 }; 990 991 /** 992 * Formats input value to byte representation of real 993 * Values are multiplied by 2^m and encoded as integers 994 * 995 * @method formatInputReal 996 * @param {String|Number|BigNumber} 997 * @returns {YlemParam} 998 */ 999 var formatInputReal = function (value) { 1000 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 1001 }; 1002 1003 /** 1004 * Check if input value is negative 1005 * 1006 * @method signedIsNegative 1007 * @param {String} value is hex format 1008 * @returns {Boolean} true if it is negative, otherwise false 1009 */ 1010 var signedIsNegative = function (value) { 1011 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 1012 }; 1013 1014 /** 1015 * Formats right-aligned output bytes to int 1016 * 1017 * @method formatOutputInt 1018 * @param {YlemParam} param 1019 * @returns {BigNumber} right-aligned output bytes formatted to big number 1020 */ 1021 var formatOutputInt = function (param) { 1022 var value = param.staticPart() || "0"; 1023 1024 // check if it's negative number 1025 // it it is, return two's complement 1026 if (signedIsNegative(value)) { 1027 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 1028 } 1029 return new BigNumber(value, 16); 1030 }; 1031 1032 /** 1033 * Formats right-aligned output bytes to uint 1034 * 1035 * @method formatOutputUInt 1036 * @param {YlemParam} 1037 * @returns {BigNumeber} right-aligned output bytes formatted to uint 1038 */ 1039 var formatOutputUInt = function (param) { 1040 var value = param.staticPart() || "0"; 1041 return new BigNumber(value, 16); 1042 }; 1043 1044 /** 1045 * Formats right-aligned output bytes to real 1046 * 1047 * @method formatOutputReal 1048 * @param {YlemParam} 1049 * @returns {BigNumber} input bytes formatted to real 1050 */ 1051 var formatOutputReal = function (param) { 1052 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 1053 }; 1054 1055 /** 1056 * Formats right-aligned output bytes to ureal 1057 * 1058 * @method formatOutputUReal 1059 * @param {YlemParam} 1060 * @returns {BigNumber} input bytes formatted to ureal 1061 */ 1062 var formatOutputUReal = function (param) { 1063 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 1064 }; 1065 1066 /** 1067 * Should be used to format output bool 1068 * 1069 * @method formatOutputBool 1070 * @param {YlemParam} 1071 * @returns {Boolean} right-aligned input bytes formatted to bool 1072 */ 1073 var formatOutputBool = function (param) { 1074 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 1075 }; 1076 1077 /** 1078 * Should be used to format output bytes 1079 * 1080 * @method formatOutputBytes 1081 * @param {YlemParam} left-aligned hex representation of string 1082 * @param {String} name type name 1083 * @returns {String} hex string 1084 */ 1085 var formatOutputBytes = function (param, name) { 1086 var matches = name.match(/^bytes([0-9]*)/); 1087 var size = parseInt(matches[1]); 1088 return '0x' + param.staticPart().slice(0, 2 * size); 1089 }; 1090 1091 /** 1092 * Should be used to format output bytes 1093 * 1094 * @method formatOutputDynamicBytes 1095 * @param {YlemParam} left-aligned hex representation of string 1096 * @returns {String} hex string 1097 */ 1098 var formatOutputDynamicBytes = function (param) { 1099 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1100 return '0x' + param.dynamicPart().substr(64, length); 1101 }; 1102 1103 /** 1104 * Should be used to format output string 1105 * 1106 * @method formatOutputString 1107 * @param {YlemParam} left-aligned hex representation of string 1108 * @returns {String} ascii string 1109 */ 1110 var formatOutputString = function (param) { 1111 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1112 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1113 }; 1114 1115 /** 1116 * Should be used to format output address 1117 * 1118 * @method formatOutputAddress 1119 * @param {YlemParam} right-aligned input bytes 1120 * @returns {String} address 1121 */ 1122 var formatOutputAddress = function (param) { 1123 var value = param.staticPart(); 1124 return value.slice(value.length - 44, value.length); 1125 }; 1126 1127 module.exports = { 1128 formatInputInt: formatInputInt, 1129 formatInputBytes: formatInputBytes, 1130 formatInputDynamicBytes: formatInputDynamicBytes, 1131 formatInputString: formatInputString, 1132 formatInputBool: formatInputBool, 1133 formatInputReal: formatInputReal, 1134 formatOutputInt: formatOutputInt, 1135 formatOutputUInt: formatOutputUInt, 1136 formatOutputReal: formatOutputReal, 1137 formatOutputUReal: formatOutputUReal, 1138 formatOutputBool: formatOutputBool, 1139 formatOutputBytes: formatOutputBytes, 1140 formatOutputDynamicBytes: formatOutputDynamicBytes, 1141 formatOutputString: formatOutputString, 1142 formatOutputAddress: formatOutputAddress 1143 }; 1144 1145 }, { "../utils/config": 18, "../utils/utils": 20, "./param": 11, "bignumber.js": "bignumber.js" }], 10: [function (require, module, exports) { 1146 var f = require('./formatters'); 1147 var YlemType = require('./type'); 1148 1149 /** 1150 * YlemTypeInt is a prootype that represents int type 1151 * It matches: 1152 * int 1153 * int[] 1154 * int[4] 1155 * int[][] 1156 * int[3][] 1157 * int[][6][], ... 1158 * int32 1159 * int64[] 1160 * int8[4] 1161 * int256[][] 1162 * int[3][] 1163 * int64[][6][], ... 1164 */ 1165 var YlemTypeInt = function () { 1166 this._inputFormatter = f.formatInputInt; 1167 this._outputFormatter = f.formatOutputInt; 1168 }; 1169 1170 YlemTypeInt.prototype = new YlemType({}); 1171 YlemTypeInt.prototype.constructor = YlemTypeInt; 1172 1173 YlemTypeInt.prototype.isType = function (name) { 1174 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1175 }; 1176 1177 module.exports = YlemTypeInt; 1178 1179 }, { "./formatters": 9, "./type": 14 }], 11: [function (require, module, exports) { 1180 /* 1181 This file is part of web3.js. 1182 1183 web3.js is free software: you can redistribute it and/or modify 1184 it under the terms of the GNU Lesser General Public License as published by 1185 the Free Software Foundation, either version 3 of the License, or 1186 (at your option) any later version. 1187 1188 web3.js is distributed in the hope that it will be useful, 1189 but WITHOUT ANY WARRANTY; without even the implied warranty of 1190 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1191 GNU Lesser General Public License for more details. 1192 1193 You should have received a copy of the GNU Lesser General Public License 1194 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1195 */ 1196 /** 1197 * @file param.js 1198 * @author Marek Kotewicz <marek@ethdev.com> 1199 * @date 2015 1200 */ 1201 1202 var utils = require('../utils/utils'); 1203 1204 /** 1205 * YlemParam object prototype. 1206 * Should be used when encoding, decoding ylem bytes 1207 */ 1208 var YlemParam = function (value, offset) { 1209 this.value = value || ''; 1210 this.offset = offset; // offset in bytes 1211 }; 1212 1213 /** 1214 * This method should be used to get length of params's dynamic part 1215 * 1216 * @method dynamicPartLength 1217 * @returns {Number} length of dynamic part (in bytes) 1218 */ 1219 YlemParam.prototype.dynamicPartLength = function () { 1220 return this.dynamicPart().length / 2; 1221 }; 1222 1223 /** 1224 * This method should be used to create copy of ylem param with different offset 1225 * 1226 * @method withOffset 1227 * @param {Number} offset length in bytes 1228 * @returns {YlemParam} new ylem param with applied offset 1229 */ 1230 YlemParam.prototype.withOffset = function (offset) { 1231 return new YlemParam(this.value, offset); 1232 }; 1233 1234 /** 1235 * This method should be used to combine ylem params together 1236 * eg. when appending an array 1237 * 1238 * @method combine 1239 * @param {YlemParam} param with which we should combine 1240 * @param {YlemParam} result of combination 1241 */ 1242 YlemParam.prototype.combine = function (param) { 1243 return new YlemParam(this.value + param.value); 1244 }; 1245 1246 /** 1247 * This method should be called to check if param has dynamic size. 1248 * If it has, it returns true, otherwise false 1249 * 1250 * @method isDynamic 1251 * @returns {Boolean} 1252 */ 1253 YlemParam.prototype.isDynamic = function () { 1254 return this.offset !== undefined; 1255 }; 1256 1257 /** 1258 * This method should be called to transform offset to bytes 1259 * 1260 * @method offsetAsBytes 1261 * @returns {String} bytes representation of offset 1262 */ 1263 YlemParam.prototype.offsetAsBytes = function () { 1264 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1265 }; 1266 1267 /** 1268 * This method should be called to get static part of param 1269 * 1270 * @method staticPart 1271 * @returns {String} offset if it is a dynamic param, otherwise value 1272 */ 1273 YlemParam.prototype.staticPart = function () { 1274 if (!this.isDynamic()) { 1275 return this.value; 1276 } 1277 return this.offsetAsBytes(); 1278 }; 1279 1280 /** 1281 * This method should be called to get dynamic part of param 1282 * 1283 * @method dynamicPart 1284 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1285 */ 1286 YlemParam.prototype.dynamicPart = function () { 1287 return this.isDynamic() ? this.value : ''; 1288 }; 1289 1290 /** 1291 * This method should be called to encode param 1292 * 1293 * @method encode 1294 * @returns {String} 1295 */ 1296 YlemParam.prototype.encode = function () { 1297 return this.staticPart() + this.dynamicPart(); 1298 }; 1299 1300 /** 1301 * This method should be called to encode array of params 1302 * 1303 * @method encodeList 1304 * @param {Array[YlemParam]} params 1305 * @returns {String} 1306 */ 1307 YlemParam.encodeList = function (params) { 1308 1309 // updating offsets 1310 var totalOffset = params.length * 32; 1311 var offsetParams = params.map(function (param) { 1312 if (!param.isDynamic()) { 1313 return param; 1314 } 1315 var offset = totalOffset; 1316 totalOffset += param.dynamicPartLength(); 1317 return param.withOffset(offset); 1318 }); 1319 1320 // encode everything! 1321 return offsetParams.reduce(function (result, param) { 1322 return result + param.dynamicPart(); 1323 }, offsetParams.reduce(function (result, param) { 1324 return result + param.staticPart(); 1325 }, '')); 1326 }; 1327 1328 1329 1330 module.exports = YlemParam; 1331 1332 1333 }, { "../utils/utils": 20 }], 12: [function (require, module, exports) { 1334 var f = require('./formatters'); 1335 var YlemType = require('./type'); 1336 1337 /** 1338 * YlemTypeReal is a prootype that represents real type 1339 * It matches: 1340 * real 1341 * real[] 1342 * real[4] 1343 * real[][] 1344 * real[3][] 1345 * real[][6][], ... 1346 * real32 1347 * real64[] 1348 * real8[4] 1349 * real256[][] 1350 * real[3][] 1351 * real64[][6][], ... 1352 */ 1353 var YlemTypeReal = function () { 1354 this._inputFormatter = f.formatInputReal; 1355 this._outputFormatter = f.formatOutputReal; 1356 }; 1357 1358 YlemTypeReal.prototype = new YlemType({}); 1359 YlemTypeReal.prototype.constructor = YlemTypeReal; 1360 1361 YlemTypeReal.prototype.isType = function (name) { 1362 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1363 }; 1364 1365 module.exports = YlemTypeReal; 1366 1367 }, { "./formatters": 9, "./type": 14 }], 13: [function (require, module, exports) { 1368 var f = require('./formatters'); 1369 var YlemType = require('./type'); 1370 1371 var YlemTypeString = function () { 1372 this._inputFormatter = f.formatInputString; 1373 this._outputFormatter = f.formatOutputString; 1374 }; 1375 1376 YlemTypeString.prototype = new YlemType({}); 1377 YlemTypeString.prototype.constructor = YlemTypeString; 1378 1379 YlemTypeString.prototype.isType = function (name) { 1380 return !!name.match(/^string(\[([0-9]*)\])*$/); 1381 }; 1382 1383 YlemTypeString.prototype.isDynamicType = function () { 1384 return true; 1385 }; 1386 1387 module.exports = YlemTypeString; 1388 1389 }, { "./formatters": 9, "./type": 14 }], 14: [function (require, module, exports) { 1390 var f = require('./formatters'); 1391 var YlemParam = require('./param'); 1392 1393 /** 1394 * YlemType prototype is used to encode/decode ylem params of certain type 1395 */ 1396 var YlemType = function (config) { 1397 this._inputFormatter = config.inputFormatter; 1398 this._outputFormatter = config.outputFormatter; 1399 }; 1400 1401 /** 1402 * Should be used to determine if this YlemType do match given name 1403 * 1404 * @method isType 1405 * @param {String} name 1406 * @return {Bool} true if type match this YlemType, otherwise false 1407 */ 1408 YlemType.prototype.isType = function (name) { 1409 throw "this method should be overrwritten for type " + name; 1410 }; 1411 1412 /** 1413 * Should be used to determine what is the length of static part in given type 1414 * 1415 * @method staticPartLength 1416 * @param {String} name 1417 * @return {Number} length of static part in bytes 1418 */ 1419 YlemType.prototype.staticPartLength = function (name) { 1420 // If name isn't an array then treat it like a single element array. 1421 return (this.nestedTypes(name) || ['[1]']) 1422 .map(function (type) { 1423 // the length of the nested array 1424 return parseInt(type.slice(1, -1), 10) || 1; 1425 }) 1426 .reduce(function (previous, current) { 1427 return previous * current; 1428 // all basic types are 32 bytes long 1429 }, 32); 1430 }; 1431 1432 /** 1433 * Should be used to determine if type is dynamic array 1434 * eg: 1435 * "type[]" => true 1436 * "type[4]" => false 1437 * 1438 * @method isDynamicArray 1439 * @param {String} name 1440 * @return {Bool} true if the type is dynamic array 1441 */ 1442 YlemType.prototype.isDynamicArray = function (name) { 1443 var nestedTypes = this.nestedTypes(name); 1444 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1445 }; 1446 1447 /** 1448 * Should be used to determine if type is static array 1449 * eg: 1450 * "type[]" => false 1451 * "type[4]" => true 1452 * 1453 * @method isStaticArray 1454 * @param {String} name 1455 * @return {Bool} true if the type is static array 1456 */ 1457 YlemType.prototype.isStaticArray = function (name) { 1458 var nestedTypes = this.nestedTypes(name); 1459 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1460 }; 1461 1462 /** 1463 * Should return length of static array 1464 * eg. 1465 * "int[32]" => 32 1466 * "int256[14]" => 14 1467 * "int[2][3]" => 3 1468 * "int" => 1 1469 * "int[1]" => 1 1470 * "int[]" => 1 1471 * 1472 * @method staticArrayLength 1473 * @param {String} name 1474 * @return {Number} static array length 1475 */ 1476 YlemType.prototype.staticArrayLength = function (name) { 1477 var nestedTypes = this.nestedTypes(name); 1478 if (nestedTypes) { 1479 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1480 } 1481 return 1; 1482 }; 1483 1484 /** 1485 * Should return nested type 1486 * eg. 1487 * "int[32]" => "int" 1488 * "int256[14]" => "int256" 1489 * "int[2][3]" => "int[2]" 1490 * "int" => "int" 1491 * "int[]" => "int" 1492 * 1493 * @method nestedName 1494 * @param {String} name 1495 * @return {String} nested name 1496 */ 1497 YlemType.prototype.nestedName = function (name) { 1498 // remove last [] in name 1499 var nestedTypes = this.nestedTypes(name); 1500 if (!nestedTypes) { 1501 return name; 1502 } 1503 1504 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1505 }; 1506 1507 /** 1508 * Should return true if type has dynamic size by default 1509 * such types are "string", "bytes" 1510 * 1511 * @method isDynamicType 1512 * @param {String} name 1513 * @return {Bool} true if is dynamic, otherwise false 1514 */ 1515 YlemType.prototype.isDynamicType = function () { 1516 return false; 1517 }; 1518 1519 /** 1520 * Should return array of nested types 1521 * eg. 1522 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1523 * "int[] => ["[]"] 1524 * "int" => null 1525 * 1526 * @method nestedTypes 1527 * @param {String} name 1528 * @return {Array} array of nested types 1529 */ 1530 YlemType.prototype.nestedTypes = function (name) { 1531 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1532 return name.match(/(\[[0-9]*\])/g); 1533 }; 1534 1535 /** 1536 * Should be used to encode the value 1537 * 1538 * @method encode 1539 * @param {Object} value 1540 * @param {String} name 1541 * @return {String} encoded value 1542 */ 1543 YlemType.prototype.encode = function (value, name) { 1544 var self = this; 1545 if (this.isDynamicArray(name)) { 1546 1547 return (function () { 1548 var length = value.length; // in int 1549 var nestedName = self.nestedName(name); 1550 1551 var result = []; 1552 result.push(f.formatInputInt(length).encode()); 1553 1554 value.forEach(function (v) { 1555 result.push(self.encode(v, nestedName)); 1556 }); 1557 1558 return result; 1559 })(); 1560 1561 } else if (this.isStaticArray(name)) { 1562 1563 return (function () { 1564 var length = self.staticArrayLength(name); // in int 1565 var nestedName = self.nestedName(name); 1566 1567 var result = []; 1568 for (var i = 0; i < length; i++) { 1569 result.push(self.encode(value[i], nestedName)); 1570 } 1571 1572 return result; 1573 })(); 1574 1575 } 1576 1577 return this._inputFormatter(value, name).encode(); 1578 }; 1579 1580 /** 1581 * Should be used to decode value from bytes 1582 * 1583 * @method decode 1584 * @param {String} bytes 1585 * @param {Number} offset in bytes 1586 * @param {String} name type name 1587 * @returns {Object} decoded value 1588 */ 1589 YlemType.prototype.decode = function (bytes, offset, name) { 1590 var self = this; 1591 1592 if (this.isDynamicArray(name)) { 1593 1594 return (function () { 1595 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1596 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1597 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1598 1599 var nestedName = self.nestedName(name); 1600 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1601 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1602 var result = []; 1603 1604 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1605 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1606 } 1607 1608 return result; 1609 })(); 1610 1611 } else if (this.isStaticArray(name)) { 1612 1613 return (function () { 1614 var length = self.staticArrayLength(name); // in int 1615 var arrayStart = offset; // in bytes 1616 1617 var nestedName = self.nestedName(name); 1618 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1619 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1620 var result = []; 1621 1622 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1623 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1624 } 1625 1626 return result; 1627 })(); 1628 } else if (this.isDynamicType(name)) { 1629 1630 return (function () { 1631 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1632 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1633 var roundedLength = Math.floor((length + 31) / 32); // in int 1634 var param = new YlemParam(bytes.substr(dynamicOffset * 2, (1 + roundedLength) * 64), 0); 1635 return self._outputFormatter(param, name); 1636 })(); 1637 } 1638 1639 var length = this.staticPartLength(name); 1640 var param = new YlemParam(bytes.substr(offset * 2, length * 2)); 1641 return this._outputFormatter(param, name); 1642 }; 1643 1644 module.exports = YlemType; 1645 1646 }, { "./formatters": 9, "./param": 11 }], 15: [function (require, module, exports) { 1647 var f = require('./formatters'); 1648 var YlemType = require('./type'); 1649 1650 /** 1651 * YlemTypeUInt is a prootype that represents uint type 1652 * It matches: 1653 * uint 1654 * uint[] 1655 * uint[4] 1656 * uint[][] 1657 * uint[3][] 1658 * uint[][6][], ... 1659 * uint32 1660 * uint64[] 1661 * uint8[4] 1662 * uint256[][] 1663 * uint[3][] 1664 * uint64[][6][], ... 1665 */ 1666 var YlemTypeUInt = function () { 1667 this._inputFormatter = f.formatInputInt; 1668 this._outputFormatter = f.formatOutputUInt; 1669 }; 1670 1671 YlemTypeUInt.prototype = new YlemType({}); 1672 YlemTypeUInt.prototype.constructor = YlemTypeUInt; 1673 1674 YlemTypeUInt.prototype.isType = function (name) { 1675 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1676 }; 1677 1678 module.exports = YlemTypeUInt; 1679 1680 }, { "./formatters": 9, "./type": 14 }], 16: [function (require, module, exports) { 1681 var f = require('./formatters'); 1682 var YlemType = require('./type'); 1683 1684 /** 1685 * YlemTypeUReal is a prootype that represents ureal type 1686 * It matches: 1687 * ureal 1688 * ureal[] 1689 * ureal[4] 1690 * ureal[][] 1691 * ureal[3][] 1692 * ureal[][6][], ... 1693 * ureal32 1694 * ureal64[] 1695 * ureal8[4] 1696 * ureal256[][] 1697 * ureal[3][] 1698 * ureal64[][6][], ... 1699 */ 1700 var YlemTypeUReal = function () { 1701 this._inputFormatter = f.formatInputReal; 1702 this._outputFormatter = f.formatOutputUReal; 1703 }; 1704 1705 YlemTypeUReal.prototype = new YlemType({}); 1706 YlemTypeUReal.prototype.constructor = YlemTypeUReal; 1707 1708 YlemTypeUReal.prototype.isType = function (name) { 1709 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1710 }; 1711 1712 module.exports = YlemTypeUReal; 1713 1714 }, { "./formatters": 9, "./type": 14 }], 17: [function (require, module, exports) { 1715 'use strict'; 1716 1717 // go env doesn't have and need XMLHttpRequest 1718 if (typeof XMLHttpRequest === 'undefined') { 1719 exports.XMLHttpRequest = {}; 1720 } else { 1721 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1722 } 1723 1724 1725 }, {}], 18: [function (require, module, exports) { 1726 /* 1727 This file is part of web3.js. 1728 1729 web3.js is free software: you can redistribute it and/or modify 1730 it under the terms of the GNU Lesser General Public License as published by 1731 the Free Software Foundation, either version 3 of the License, or 1732 (at your option) any later version. 1733 1734 web3.js is distributed in the hope that it will be useful, 1735 but WITHOUT ANY WARRANTY; without even the implied warranty of 1736 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1737 GNU Lesser General Public License for more details. 1738 1739 You should have received a copy of the GNU Lesser General Public License 1740 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1741 */ 1742 /** @file config.js 1743 * @authors: 1744 * Marek Kotewicz <marek@ethdev.com> 1745 * @date 2015 1746 */ 1747 1748 /** 1749 * Utils 1750 * 1751 * @module utils 1752 */ 1753 1754 /** 1755 * Utility functions 1756 * 1757 * @class [utils] config 1758 * @constructor 1759 */ 1760 1761 1762 1763 /// required to define XCB_BIGNUMBER_ROUNDING_MODE 1764 var BigNumber = require('bignumber.js'); 1765 1766 var XCB_UNITS = [ 1767 'ore', 1768 'fecore', 1769 'picore', 1770 'nacore', 1771 'μcore', 1772 'micore', 1773 'core', 1774 'kicore', 1775 'Mecore', 1776 'Gicore', 1777 'Tecore', 1778 'Pecore', 1779 'Excore', 1780 'Zecore', 1781 'Yocore', 1782 ]; 1783 1784 module.exports = { 1785 XCB_PADDING: 32, 1786 XCB_SIGNATURE_LENGTH: 4, 1787 XCB_UNITS: XCB_UNITS, 1788 XCB_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }, 1789 XCB_POLLING_TIMEOUT: 1000/2, 1790 defaultBlock: 'latest', 1791 defaultAccount: undefined 1792 }; 1793 1794 1795 1796 }, { "bignumber.js": "bignumber.js" }], 19: [function (require, module, exports) { 1797 /* 1798 This file is part of web3.js. 1799 1800 web3.js is free software: you can redistribute it and/or modify 1801 it under the terms of the GNU Lesser General Public License as published by 1802 the Free Software Foundation, either version 3 of the License, or 1803 (at your option) any later version. 1804 1805 web3.js is distributed in the hope that it will be useful, 1806 but WITHOUT ANY WARRANTY; without even the implied warranty of 1807 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1808 GNU Lesser General Public License for more details. 1809 1810 You should have received a copy of the GNU Lesser General Public License 1811 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1812 */ 1813 /** 1814 * @file sha3.js 1815 * @author Marek Kotewicz <marek@ethdev.com> 1816 * @date 2015 1817 */ 1818 1819 var CryptoJS = require('crypto-js'); 1820 var sha3_256 = require('js-sha3').sha3_256; 1821 1822 module.exports = function (value, options) { 1823 if (options && options.encoding === 'hex') { 1824 if (value.length > 2 && value.substr(0, 2) === '0x') { 1825 value = value.substr(2); 1826 } 1827 value = CryptoJS.enc.Hex.parse(value); 1828 } 1829 1830 return sha3_256(value); 1831 }; 1832 1833 1834 }, { "crypto-js": 59, "js-sha3": 85 }], 20: [function (require, module, exports) { 1835 /* 1836 This file is part of web3.js. 1837 1838 web3.js is free software: you can redistribute it and/or modify 1839 it under the terms of the GNU Lesser General Public License as published by 1840 the Free Software Foundation, either version 3 of the License, or 1841 (at your option) any later version. 1842 1843 web3.js is distributed in the hope that it will be useful, 1844 but WITHOUT ANY WARRANTY; without even the implied warranty of 1845 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1846 GNU Lesser General Public License for more details. 1847 1848 You should have received a copy of the GNU Lesser General Public License 1849 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1850 */ 1851 /** 1852 * @file utils.js 1853 * @author Marek Kotewicz <marek@ethdev.com> 1854 * @date 2015 1855 */ 1856 1857 /** 1858 * Utils 1859 * 1860 * @module utils 1861 */ 1862 1863 /** 1864 * Utility functions 1865 * 1866 * @class [utils] utils 1867 * @constructor 1868 */ 1869 1870 1871 var BigNumber = require('bignumber.js'); 1872 var sha3 = require('./sha3.js'); 1873 var utf8 = require('utf8'); 1874 1875 1876 var XCB_UNITS = [ 1877 'ore', 1878 'fecore', 1879 'picore', 1880 'nacore', 1881 'μcore', 1882 'micore', 1883 'core', 1884 'kicore', 1885 'Mecore', 1886 'Gicore', 1887 'Tecore', 1888 'Pecore', 1889 'Excore', 1890 'Zecore', 1891 'Yocore', 1892 ]; 1893 1894 var unitMap = { 1895 'nocore': '0', 1896 'ore': '1', 1897 1898 'fecore': '1000', 1899 'Fecore': '1000', 1900 'Wav': '1000', 1901 'wav': '1000', 1902 1903 'picore': '1000000', 1904 'Picore': '1000000', 1905 'Grav': '1000000', 1906 'grav': '1000000', 1907 1908 'nacore': '1000000000', 1909 'Nacore': '1000000000', 1910 'Nucle': '1000000000', 1911 'nucle': '1000000000', 1912 1913 'μcore': '1000000000000', 1914 'Îœcore': '1000000000000', 1915 'Atom': '1000000000000', 1916 'atom': '1000000000000', 1917 1918 'micore': '1000000000000000', 1919 'Micore': '1000000000000000', 1920 'Moli': '1000000000000000', 1921 'moli': '1000000000000000', 1922 1923 'core': '1000000000000000000', 1924 'Core': '1000000000000000000', 1925 1926 'kicore': '1000000000000000000000', 1927 'Kicore': '1000000000000000000000', 1928 'Aer': '1000000000000000000000', 1929 'aer': '1000000000000000000000', 1930 1931 'mecore': '1000000000000000000000000', 1932 'Mecore': '1000000000000000000000000', 1933 'Orb': '1000000000000000000000000', 1934 'orb': '1000000000000000000000000', 1935 1936 'gicore': '1000000000000000000000000000', 1937 'Gicore': '1000000000000000000000000000', 1938 'Plano': '1000000000000000000000000000', 1939 'plano': '1000000000000000000000000000', 1940 1941 'tecore': '1000000000000000000000000000000', 1942 'Tecore': '1000000000000000000000000000000', 1943 'Tera': '1000000000000000000000000000000', 1944 'tera': '1000000000000000000000000000000', 1945 1946 'pecore': '1000000000000000000000000000000000', 1947 'Pecore': '1000000000000000000000000000000000', 1948 'Sola': '1000000000000000000000000000000000', 1949 'sola': '1000000000000000000000000000000000', 1950 1951 'excore': '1000000000000000000000000000000000000', 1952 'Excore': '1000000000000000000000000000000000000', 1953 'Galx': '1000000000000000000000000000000000000', 1954 'galx': '1000000000000000000000000000000000000', 1955 1956 'zecore': '1000000000000000000000000000000000000000', 1957 'Zecore': '1000000000000000000000000000000000000000', 1958 'Cluster': '1000000000000000000000000000000000000000', 1959 'cluster': '1000000000000000000000000000000000000000', 1960 1961 'yocore': '1000000000000000000000000000000000000000000', 1962 'Yocore': '1000000000000000000000000000000000000000000', 1963 'Supermatter':'1000000000000000000000000000000000000000000', 1964 'supermatter':'1000000000000000000000000000000000000000000', 1965 }; 1966 1967 /** 1968 * Should be called to pad string to expected length 1969 * 1970 * @method padLeft 1971 * @param {String} string to be padded 1972 * @param {Number} characters that result string should have 1973 * @param {String} sign, by default 0 1974 * @returns {String} right aligned string 1975 */ 1976 var padLeft = function (string, chars, sign) { 1977 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1978 }; 1979 1980 /** 1981 * Should be called to pad string to expected length 1982 * 1983 * @method padRight 1984 * @param {String} string to be padded 1985 * @param {Number} characters that result string should have 1986 * @param {String} sign, by default 0 1987 * @returns {String} right aligned string 1988 */ 1989 var padRight = function (string, chars, sign) { 1990 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1991 }; 1992 1993 /** 1994 * Should be called to get utf8 from it's hex representation 1995 * 1996 * @method toUtf8 1997 * @param {String} string in hex 1998 * @returns {String} ascii string representation of hex value 1999 */ 2000 var toUtf8 = function(hex) { 2001 // Find termination 2002 var str = ""; 2003 var i = 0, l = hex.length; 2004 if (hex.substring(0, 2) === '0x') { 2005 i = 2; 2006 } 2007 for (; i < l; i+=2) { 2008 var code = parseInt(hex.substr(i, 2), 16); 2009 if (code === 0) 2010 break; 2011 str += String.fromCharCode(code); 2012 } 2013 2014 return utf8.decode(str); 2015 }; 2016 2017 2018 /** 2019 * Should be called to get ascii from it's hex representation 2020 * 2021 * @method toAscii 2022 * @param {String} string in hex 2023 * @returns {String} ascii string representation of hex value 2024 */ 2025 var toAscii = function (hex) { 2026 // Find termination 2027 var str = ""; 2028 var i = 0, l = hex.length; 2029 if (hex.substring(0, 2) === '0x') { 2030 i = 2; 2031 } 2032 for (; i < l; i += 2) { 2033 var code = parseInt(hex.substr(i, 2), 16); 2034 str += String.fromCharCode(code); 2035 } 2036 2037 return str; 2038 }; 2039 2040 /** 2041 * Should be called to get hex representation (prefixed by 0x) of utf8 string 2042 * 2043 * @method fromUtf8 2044 * @param {String} string 2045 * @param {Number} optional padding 2046 * @returns {String} hex representation of input string 2047 */ 2048 var fromUtf8 = function (str) { 2049 str = utf8.encode(str); 2050 var hex = ""; 2051 for (var i = 0; i < str.length; i++) { 2052 var code = str.charCodeAt(i); 2053 if (code === 0) 2054 break; 2055 var n = code.toString(16); 2056 hex += n.length < 2 ? '0' + n : n; 2057 } 2058 2059 return "0x" + hex; 2060 }; 2061 2062 /** 2063 * Should be called to get hex representation (prefixed by 0x) of ascii string 2064 * 2065 * @method fromAscii 2066 * @param {String} string 2067 * @param {Number} optional padding 2068 * @returns {String} hex representation of input string 2069 */ 2070 var fromAscii = function (str) { 2071 var hex = ""; 2072 for (var i = 0; i < str.length; i++) { 2073 var code = str.charCodeAt(i); 2074 var n = code.toString(16); 2075 hex += n.length < 2 ? '0' + n : n; 2076 } 2077 2078 return "0x" + hex; 2079 }; 2080 2081 /** 2082 * Should be used to create full function/event name from json abi 2083 * 2084 * @method transformToFullName 2085 * @param {Object} json-abi 2086 * @return {String} full fnction/event name 2087 */ 2088 var transformToFullName = function (json) { 2089 if (json.name.indexOf('(') !== -1) { 2090 return json.name; 2091 } 2092 2093 var typeName = json.inputs.map(function (i) { return i.type; }).join(); 2094 return json.name + '(' + typeName + ')'; 2095 }; 2096 2097 /** 2098 * Should be called to get display name of contract function 2099 * 2100 * @method extractDisplayName 2101 * @param {String} name of function/event 2102 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2103 */ 2104 var extractDisplayName = function (name) { 2105 var length = name.indexOf('('); 2106 return length !== -1 ? name.substr(0, length) : name; 2107 }; 2108 2109 /// @returns overloaded part of function/event name 2110 var extractTypeName = function (name) { 2111 /// TODO: make it invulnerable 2112 var length = name.indexOf('('); 2113 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2114 }; 2115 2116 /** 2117 * Converts value to it's decimal representation in string 2118 * 2119 * @method toDecimal 2120 * @param {String|Number|BigNumber} 2121 * @return {String} 2122 */ 2123 var toDecimal = function (value) { 2124 return toBigNumber(value).toNumber(); 2125 }; 2126 2127 /** 2128 * Converts value to it's hex representation 2129 * 2130 * @method fromDecimal 2131 * @param {String|Number|BigNumber} 2132 * @return {String} 2133 */ 2134 var fromDecimal = function (value) { 2135 var number = toBigNumber(value); 2136 var result = number.toString(16); 2137 2138 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2139 }; 2140 2141 /** 2142 * Auto converts any given value into it's hex representation. 2143 * 2144 * And even stringifys objects before. 2145 * 2146 * @method toHex 2147 * @param {String|Number|BigNumber|Object} 2148 * @return {String} 2149 */ 2150 var toHex = function (val) { 2151 /*jshint maxcomplexity: 8 */ 2152 2153 if (isBoolean(val)) 2154 return fromDecimal(+val); 2155 2156 if (isBigNumber(val)) 2157 return fromDecimal(val); 2158 2159 if (typeof val === 'object') 2160 return fromUtf8(JSON.stringify(val)); 2161 2162 // if its a negative number, pass it through fromDecimal 2163 if (isString(val)) { 2164 if (val.indexOf('-0x') === 0) 2165 return fromDecimal(val); 2166 else if (val.indexOf('0x') === 0) 2167 return val; 2168 else if (!isFinite(val)) 2169 return fromAscii(val); 2170 } 2171 2172 return fromDecimal(val); 2173 }; 2174 2175 /** 2176 * Returns value of unit in Ore 2177 * 2178 * @method getValueOfUnit 2179 * @param {String} unit the unit to convert to, default core 2180 * @returns {BigNumber} value of the unit (in Ore) 2181 * @throws error if the unit is not correct:w 2182 */ 2183 var getValueOfUnit = function (unit) { 2184 unit = unit ? unit.toLowerCase() : 'core'; 2185 var unitValue = unitMap[unit]; 2186 if (unitValue === undefined) { 2187 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2188 } 2189 return new BigNumber(unitValue, 10); 2190 }; 2191 /** 2192 * Takes a number of ore and converts it to any other core unit. 2193 * 2194 * Possible units are: 2195 * SI Short SI Full Other 2196 * - wav fecore femto 2197 * - grav picore pico 2198 * - nucle nacore nano 2199 * - atom μcore micro 2200 * - moli millicore mili 2201 * - core Core 2202 * - aer kicore kilo 2203 * - orb Mecore mega 2204 * - Plano Gicore giga 2205 * - Tera Tecore tera 2206 * - Sola Pecore peta 2207 * - Galx Excore exa 2208 * - Cluster Zecore zetta 2209 * - Supermatter Yocore yotta 2210 * 2211 * @method fromOre 2212 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2213 * @param {String} unit the unit to convert to, default core 2214 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2215 */ 2216 var fromOre = function(number, unit) { 2217 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2218 2219 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2220 }; 2221 2222 /** 2223 * Takes a number of a unit and converts it to ore. 2224 * 2225 * Possible units are: 2226 * SI Short SI Full Other 2227 * - wav fecore femto 2228 * - grav picore pico 2229 * - nucle nacore nano 2230 * - atom μcore micro 2231 * - moli millicore mili 2232 * - core Core 2233 * - aer kicore kilo 2234 * - orb Mecore mega 2235 * - Plano Gicore giga 2236 * - Tera Tecore tera 2237 * - Sola Pecore peta 2238 * - Galx Excore exa 2239 * - Cluster Zecore zetta 2240 * - Supermatter Yocore yotta 2241 * 2242 * @method toOre 2243 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2244 * @param {String} unit the unit to convert from, default core 2245 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2246 */ 2247 var toOre = function(number, unit) { 2248 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2249 2250 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2251 }; 2252 2253 /** 2254 * Takes an input and transforms it into a bignumber 2255 2256 * 2257 * @method toBigNumber 2258 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2259 * @return {BigNumber} BigNumber 2260 */ 2261 var toBigNumber = function(number) { 2262 /*jshint maxcomplexity:5 */ 2263 number = number || 0; 2264 if (isBigNumber(number)) 2265 return number; 2266 2267 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2268 return new BigNumber(number.replace('0x',''), 16); 2269 } 2270 if (isString(number) && (number.indexOf('ce') === 0 || number.indexOf('-ce') === 0)) { 2271 return new BigNumber(number, 16); 2272 } 2273 if (isString(number) && (number.indexOf('cb') === 0 || number.indexOf('-cb') === 0)) { 2274 return new BigNumber(number, 16); 2275 } 2276 if (isString(number) && (number.indexOf('ab') === 0 || number.indexOf('-ab') === 0)) { 2277 return new BigNumber(number, 16); 2278 } 2279 2280 return new BigNumber(number.toString(10), 10); 2281 }; 2282 2283 2284 /** 2285 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2286 * 2287 * @method toTwosComplement 2288 * @param {Number|String|BigNumber} 2289 * @return {BigNumber} 2290 */ 2291 var toTwosComplement = function (number) { 2292 var bigNumber = toBigNumber(number).round(); 2293 if (bigNumber.lessThan(0)) { 2294 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2295 } 2296 return bigNumber; 2297 }; 2298 2299 /** 2300 * Checks if the given string is strictly an address 2301 * 2302 * @method isStrictAddress 2303 * @param {String} address the given HEX address 2304 * @return {Boolean} 2305 */ 2306 var isStrictAddress = function (address) { 2307 return /^[0-9a-f]{44}$/i.test(address); 2308 }; 2309 2310 /** 2311 * Checks if the given string is an address 2312 * 2313 * @method isAddress 2314 * @param {String} address the given HEX address 2315 * @return {Boolean} 2316 */ 2317 var isAddress = function (address) { 2318 if (!/^[0-9a-f]{44}$/i.test(address)) { 2319 // check if it has the basic requirements of an address 2320 return false; 2321 } else if (/^[0-9a-f]{44}$/.test(address) || /^[0-9A-F]{44}$/.test(address)) { 2322 // If it's all small caps or all caps, return true 2323 return true; 2324 } else { 2325 // Otherwise check each case 2326 return isChecksumAddress(address); 2327 } 2328 }; 2329 2330 /** 2331 * Checks if the given string is a checksummed address 2332 * 2333 * @method isChecksumAddress 2334 * @param {String} address the given HEX address 2335 * @return {Boolean} 2336 */ 2337 var isChecksumAddress = function (address) { 2338 // Check each case 2339 address = address.replace('0x',''); 2340 var addressHash = sha3(address.toLowerCase()); 2341 2342 for (var i = 0; i < 40; i++ ) { 2343 // the nth letter should be uppercase if the nth digit of casemap is 1 2344 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2345 return false; 2346 } 2347 } 2348 return true; 2349 }; 2350 2351 2352 2353 /** 2354 * Makes a checksum address 2355 * 2356 * @method toChecksumAddress 2357 * @param {String} address the given HEX address 2358 * @return {String} 2359 */ 2360 var toChecksumAddress = function (address) { 2361 if (typeof address === 'undefined') return ''; 2362 2363 address = address.toLowerCase().replace('0x',''); 2364 var addressHash = sha3(address); 2365 var checksumAddress = '0x'; 2366 2367 for (var i = 0; i < address.length; i++ ) { 2368 // If ith character is 9 to f then make it uppercase 2369 if (parseInt(addressHash[i], 16) > 7) { 2370 checksumAddress += address[i].toUpperCase(); 2371 } else { 2372 checksumAddress += address[i]; 2373 } 2374 } 2375 return checksumAddress; 2376 }; 2377 2378 /** 2379 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2380 * 2381 * @method toAddress 2382 * @param {String} address 2383 * @return {String} formatted address 2384 */ 2385 var toAddress = function (address) { 2386 if (isStrictAddress(address)) { 2387 return address; 2388 } 2389 2390 if (/^[0-9a-f]{44}$/.test(address)) { 2391 return address; 2392 } 2393 2394 return padLeft(toHex(address), 44); 2395 }; 2396 2397 /** 2398 * Returns true if object is BigNumber, otherwise false 2399 * 2400 * @method isBigNumber 2401 * @param {Object} 2402 * @return {Boolean} 2403 */ 2404 var isBigNumber = function (object) { 2405 return object instanceof BigNumber || 2406 (object && object.constructor && object.constructor.name === 'BigNumber'); 2407 }; 2408 2409 /** 2410 * Returns true if object is string, otherwise false 2411 * 2412 * @method isString 2413 * @param {Object} 2414 * @return {Boolean} 2415 */ 2416 var isString = function (object) { 2417 return typeof object === 'string' || 2418 (object && object.constructor && object.constructor.name === 'String'); 2419 }; 2420 2421 /** 2422 * Returns true if object is function, otherwise false 2423 * 2424 * @method isFunction 2425 * @param {Object} 2426 * @return {Boolean} 2427 */ 2428 var isFunction = function (object) { 2429 return typeof object === 'function'; 2430 }; 2431 2432 /** 2433 * Returns true if object is Objet, otherwise false 2434 * 2435 * @method isObject 2436 * @param {Object} 2437 * @return {Boolean} 2438 */ 2439 var isObject = function (object) { 2440 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2441 }; 2442 2443 /** 2444 * Returns true if object is boolean, otherwise false 2445 * 2446 * @method isBoolean 2447 * @param {Object} 2448 * @return {Boolean} 2449 */ 2450 var isBoolean = function (object) { 2451 return typeof object === 'boolean'; 2452 }; 2453 2454 /** 2455 * Returns true if object is array, otherwise false 2456 * 2457 * @method isArray 2458 * @param {Object} 2459 * @return {Boolean} 2460 */ 2461 var isArray = function (object) { 2462 return object instanceof Array; 2463 }; 2464 2465 /** 2466 * Returns true if given string is valid json object 2467 * 2468 * @method isJson 2469 * @param {String} 2470 * @return {Boolean} 2471 */ 2472 var isJson = function (str) { 2473 try { 2474 return !!JSON.parse(str); 2475 } catch (e) { 2476 return false; 2477 } 2478 }; 2479 2480 /** 2481 * Returns true if given string is a valid Core block header bloom. 2482 * 2483 * @method isBloom 2484 * @param {String} hex encoded bloom filter 2485 * @return {Boolean} 2486 */ 2487 var isBloom = function (bloom) { 2488 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2489 return false; 2490 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2491 return true; 2492 } 2493 return false; 2494 }; 2495 2496 /** 2497 * Returns true if given string is a valid log topic. 2498 * 2499 * @method isTopic 2500 * @param {String} hex encoded topic 2501 * @return {Boolean} 2502 */ 2503 var isTopic = function (topic) { 2504 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2505 return false; 2506 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2507 return true; 2508 } 2509 return false; 2510 }; 2511 2512 module.exports = { 2513 padLeft: padLeft, 2514 padRight: padRight, 2515 toHex: toHex, 2516 toDecimal: toDecimal, 2517 fromDecimal: fromDecimal, 2518 toUtf8: toUtf8, 2519 toAscii: toAscii, 2520 fromUtf8: fromUtf8, 2521 fromAscii: fromAscii, 2522 transformToFullName: transformToFullName, 2523 extractDisplayName: extractDisplayName, 2524 extractTypeName: extractTypeName, 2525 toOre: toOre, 2526 fromOre: fromOre, 2527 toBigNumber: toBigNumber, 2528 toTwosComplement: toTwosComplement, 2529 toAddress: toAddress, 2530 isBigNumber: isBigNumber, 2531 isStrictAddress: isStrictAddress, 2532 isAddress: isAddress, 2533 isChecksumAddress: isChecksumAddress, 2534 toChecksumAddress: toChecksumAddress, 2535 isFunction: isFunction, 2536 isString: isString, 2537 isObject: isObject, 2538 isBoolean: isBoolean, 2539 isArray: isArray, 2540 isJson: isJson, 2541 isBloom: isBloom, 2542 isTopic: isTopic, 2543 }; 2544 2545 }, { "./sha3.js": 19, "bignumber.js": "bignumber.js", "utf8": 86 }], 21: [function (require, module, exports) { 2546 module.exports = { 2547 "version": "0.20.1" 2548 } 2549 2550 }, {}], 22: [function (require, module, exports) { 2551 /* 2552 This file is part of web3.js. 2553 2554 web3.js is free software: you can redistribute it and/or modify 2555 it under the terms of the GNU Lesser General Public License as published by 2556 the Free Software Foundation, either version 3 of the License, or 2557 (at your option) any later version. 2558 2559 web3.js is distributed in the hope that it will be useful, 2560 but WITHOUT ANY WARRANTY; without even the implied warranty of 2561 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2562 GNU Lesser General Public License for more details. 2563 2564 You should have received a copy of the GNU Lesser General Public License 2565 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2566 */ 2567 /** 2568 * @file web3.js 2569 * @authors: 2570 * Jeffrey Wilcke <jeff@ethdev.com> 2571 * Marek Kotewicz <marek@ethdev.com> 2572 * Marian Oancea <marian@ethdev.com> 2573 * Fabian Vogelsteller <fabian@ethdev.com> 2574 * Gav Wood <g@ethdev.com> 2575 * @date 2014 2576 */ 2577 2578 var RequestManager = require('./web3/requestmanager'); 2579 var Iban = require('./web3/iban'); 2580 var Xcb = require('./web3/methods/xcb'); 2581 var DB = require('./web3/methods/db'); 2582 var Shh = require('./web3/methods/shh'); 2583 var Net = require('./web3/methods/net'); 2584 var Personal = require('./web3/methods/personal'); 2585 var Swarm = require('./web3/methods/swarm'); 2586 var Settings = require('./web3/settings'); 2587 var version = require('./version.json'); 2588 var utils = require('./utils/utils'); 2589 var sha3 = require('./utils/sha3'); 2590 var extend = require('./web3/extend'); 2591 var Batch = require('./web3/batch'); 2592 var Property = require('./web3/property'); 2593 var HttpProvider = require('./web3/httpprovider'); 2594 var IpcProvider = require('./web3/ipcprovider'); 2595 var BigNumber = require('bignumber.js'); 2596 2597 2598 2599 function Web3(provider) { 2600 this._requestManager = new RequestManager(provider); 2601 this.currentProvider = provider; 2602 this.xcb = new Xcb(this); 2603 this.db = new DB(this); 2604 this.shh = new Shh(this); 2605 this.net = new Net(this); 2606 this.personal = new Personal(this); 2607 this.bzz = new Swarm(this); 2608 this.settings = new Settings(); 2609 this.version = { 2610 api: version.version 2611 }; 2612 this.providers = { 2613 HttpProvider: HttpProvider, 2614 IpcProvider: IpcProvider 2615 }; 2616 this._extend = extend(this); 2617 this._extend({ 2618 properties: properties() 2619 }); 2620 } 2621 2622 // expose providers on the class 2623 Web3.providers = { 2624 HttpProvider: HttpProvider, 2625 IpcProvider: IpcProvider 2626 }; 2627 2628 Web3.prototype.setProvider = function (provider) { 2629 this._requestManager.setProvider(provider); 2630 this.currentProvider = provider; 2631 }; 2632 2633 Web3.prototype.reset = function (keepIsSyncing) { 2634 this._requestManager.reset(keepIsSyncing); 2635 this.settings = new Settings(); 2636 }; 2637 2638 Web3.prototype.BigNumber = BigNumber; 2639 Web3.prototype.toHex = utils.toHex; 2640 Web3.prototype.toAscii = utils.toAscii; 2641 Web3.prototype.toUtf8 = utils.toUtf8; 2642 Web3.prototype.fromAscii = utils.fromAscii; 2643 Web3.prototype.fromUtf8 = utils.fromUtf8; 2644 Web3.prototype.toDecimal = utils.toDecimal; 2645 Web3.prototype.fromDecimal = utils.fromDecimal; 2646 Web3.prototype.toBigNumber = utils.toBigNumber; 2647 Web3.prototype.toOre = utils.toOre; 2648 Web3.prototype.fromOre = utils.fromOre; 2649 Web3.prototype.isAddress = utils.isAddress; 2650 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2651 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2652 Web3.prototype.isIBAN = utils.isIBAN; 2653 Web3.prototype.padLeft = utils.padLeft; 2654 Web3.prototype.padRight = utils.padRight; 2655 2656 2657 Web3.prototype.sha3 = function (string, options) { 2658 return '0x' + sha3(string, options); 2659 }; 2660 2661 /** 2662 * Transforms direct icap to address 2663 */ 2664 Web3.prototype.fromICAP = function (icap) { 2665 var iban = new Iban(icap); 2666 return iban.address(); 2667 }; 2668 2669 var properties = function () { 2670 return [ 2671 new Property({ 2672 name: 'version.node', 2673 getter: 'web3_clientVersion' 2674 }), 2675 new Property({ 2676 name: 'version.network', 2677 getter: 'net_version', 2678 inputFormatter: utils.toDecimal 2679 }), 2680 new Property({ 2681 name: 'version.core', 2682 getter: 'xcb_protocolVersion', 2683 inputFormatter: utils.toDecimal 2684 }), 2685 new Property({ 2686 name: 'version.whisper', 2687 getter: 'shh_version', 2688 inputFormatter: utils.toDecimal 2689 }) 2690 ]; 2691 }; 2692 2693 Web3.prototype.isConnected = function () { 2694 return (this.currentProvider && this.currentProvider.isConnected()); 2695 }; 2696 2697 Web3.prototype.createBatch = function () { 2698 return new Batch(this); 2699 }; 2700 2701 module.exports = Web3; 2702 2703 2704 }, { "./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/xcb": 38, "./web3/methods/net": 39, "./web3/methods/personal": 40, "./web3/methods/shh": 41, "./web3/methods/swarm": 42, "./web3/property": 45, "./web3/requestmanager": 46, "./web3/settings": 47, "bignumber.js": "bignumber.js" }], 23: [function (require, module, exports) { 2705 /* 2706 This file is part of web3.js. 2707 2708 web3.js is free software: you can redistribute it and/or modify 2709 it under the terms of the GNU Lesser General Public License as published by 2710 the Free Software Foundation, either version 3 of the License, or 2711 (at your option) any later version. 2712 2713 web3.js is distributed in the hope that it will be useful, 2714 but WITHOUT ANY WARRANTY; without even the implied warranty of 2715 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2716 GNU Lesser General Public License for more details. 2717 2718 You should have received a copy of the GNU Lesser General Public License 2719 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2720 */ 2721 /** 2722 * @file allevents.js 2723 * @author Marek Kotewicz <marek@ethdev.com> 2724 * @date 2014 2725 */ 2726 2727 var sha3 = require('../utils/sha3'); 2728 var YlemEvent = require('./event'); 2729 var formatters = require('./formatters'); 2730 var utils = require('../utils/utils'); 2731 var Filter = require('./filter'); 2732 var watches = require('./methods/watches'); 2733 2734 var AllYlemEvents = function (requestManager, json, address) { 2735 this._requestManager = requestManager; 2736 this._json = json; 2737 this._address = address; 2738 }; 2739 2740 AllYlemEvents.prototype.encode = function (options) { 2741 options = options || {}; 2742 var result = {}; 2743 2744 ['fromBlock', 'toBlock'].filter(function (f) { 2745 return options[f] !== undefined; 2746 }).forEach(function (f) { 2747 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2748 }); 2749 2750 result.address = this._address; 2751 2752 return result; 2753 }; 2754 2755 AllYlemEvents.prototype.decode = function (data) { 2756 data.data = data.data || ''; 2757 data.topics = data.topics || []; 2758 2759 var eventTopic = data.topics[0].slice(2); 2760 var match = this._json.filter(function (j) { 2761 return eventTopic === sha3(utils.transformToFullName(j)); 2762 })[0]; 2763 2764 if (!match) { // cannot find matching event? 2765 console.warn('cannot find event for log'); 2766 return data; 2767 } 2768 2769 var event = new YlemEvent(this._requestManager, match, this._address); 2770 return event.decode(data); 2771 }; 2772 2773 AllYlemEvents.prototype.execute = function (options, callback) { 2774 2775 if (utils.isFunction(arguments[arguments.length - 1])) { 2776 callback = arguments[arguments.length - 1]; 2777 if (arguments.length === 1) 2778 options = null; 2779 } 2780 2781 var o = this.encode(options); 2782 var formatter = this.decode.bind(this); 2783 return new Filter(o, 'xcb', this._requestManager, watches.xcb(), formatter, callback); 2784 }; 2785 2786 AllYlemEvents.prototype.attachToContract = function (contract) { 2787 var execute = this.execute.bind(this); 2788 contract.allEvents = execute; 2789 }; 2790 2791 module.exports = AllYlemEvents; 2792 2793 2794 }, { "../utils/sha3": 19, "../utils/utils": 20, "./event": 27, "./filter": 29, "./formatters": 30, "./methods/watches": 43 }], 24: [function (require, module, exports) { 2795 /* 2796 This file is part of web3.js. 2797 2798 web3.js is free software: you can redistribute it and/or modify 2799 it under the terms of the GNU Lesser General Public License as published by 2800 the Free Software Foundation, either version 3 of the License, or 2801 (at your option) any later version. 2802 2803 web3.js is distributed in the hope that it will be useful, 2804 but WITHOUT ANY WARRANTY; without even the implied warranty of 2805 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2806 GNU Lesser General Public License for more details. 2807 2808 You should have received a copy of the GNU Lesser General Public License 2809 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2810 */ 2811 /** 2812 * @file batch.js 2813 * @author Marek Kotewicz <marek@ethdev.com> 2814 * @date 2015 2815 */ 2816 2817 var Jsonrpc = require('./jsonrpc'); 2818 var errors = require('./errors'); 2819 2820 var Batch = function (web3) { 2821 this.requestManager = web3._requestManager; 2822 this.requests = []; 2823 }; 2824 2825 /** 2826 * Should be called to add create new request to batch request 2827 * 2828 * @method add 2829 * @param {Object} jsonrpc requet object 2830 */ 2831 Batch.prototype.add = function (request) { 2832 this.requests.push(request); 2833 }; 2834 2835 /** 2836 * Should be called to execute batch request 2837 * 2838 * @method execute 2839 */ 2840 Batch.prototype.execute = function () { 2841 var requests = this.requests; 2842 this.requestManager.sendBatch(requests, function (err, results) { 2843 results = results || []; 2844 requests.map(function (request, index) { 2845 return results[index] || {}; 2846 }).forEach(function (result, index) { 2847 if (requests[index].callback) { 2848 2849 if (!Jsonrpc.isValidResponse(result)) { 2850 return requests[index].callback(errors.InvalidResponse(result)); 2851 } 2852 2853 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2854 } 2855 }); 2856 }); 2857 }; 2858 2859 module.exports = Batch; 2860 2861 2862 }, { "./errors": 26, "./jsonrpc": 35 }], 25: [function (require, module, exports) { 2863 /* 2864 This file is part of web3.js. 2865 2866 web3.js is free software: you can redistribute it and/or modify 2867 it under the terms of the GNU Lesser General Public License as published by 2868 the Free Software Foundation, either version 3 of the License, or 2869 (at your option) any later version. 2870 2871 web3.js is distributed in the hope that it will be useful, 2872 but WITHOUT ANY WARRANTY; without even the implied warranty of 2873 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2874 GNU Lesser General Public License for more details. 2875 2876 You should have received a copy of the GNU Lesser General Public License 2877 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2878 */ 2879 /** 2880 * @file contract.js 2881 * @author Marek Kotewicz <marek@ethdev.com> 2882 * @date 2014 2883 */ 2884 2885 var utils = require('../utils/utils'); 2886 var coder = require('../ylem/coder'); 2887 var YlemEvent = require('./event'); 2888 var YlemFunction = require('./function'); 2889 var AllEvents = require('./allevents'); 2890 2891 /** 2892 * Should be called to encode constructor params 2893 * 2894 * @method encodeConstructorParams 2895 * @param {Array} abi 2896 * @param {Array} constructor params 2897 */ 2898 var encodeConstructorParams = function (abi, params) { 2899 return abi.filter(function (json) { 2900 return json.type === 'constructor' && json.inputs.length === params.length; 2901 }).map(function (json) { 2902 return json.inputs.map(function (input) { 2903 return input.type; 2904 }); 2905 }).map(function (types) { 2906 return coder.encodeParams(types, params); 2907 })[0] || ''; 2908 }; 2909 2910 /** 2911 * Should be called to add functions to contract object 2912 * 2913 * @method addFunctionsToContract 2914 * @param {Contract} contract 2915 * @param {Array} abi 2916 */ 2917 var addFunctionsToContract = function (contract) { 2918 contract.abi.filter(function (json) { 2919 return json.type === 'function'; 2920 }).map(function (json) { 2921 return new YlemFunction(contract._xcb, json, contract.address); 2922 }).forEach(function (f) { 2923 f.attachToContract(contract); 2924 }); 2925 }; 2926 2927 /** 2928 * Should be called to add events to contract object 2929 * 2930 * @method addEventsToContract 2931 * @param {Contract} contract 2932 * @param {Array} abi 2933 */ 2934 var addEventsToContract = function (contract) { 2935 var events = contract.abi.filter(function (json) { 2936 return json.type === 'event'; 2937 }); 2938 2939 var All = new AllEvents(contract._xcb._requestManager, events, contract.address); 2940 All.attachToContract(contract); 2941 2942 events.map(function (json) { 2943 return new YlemEvent(contract._xcb._requestManager, json, contract.address); 2944 }).forEach(function (e) { 2945 e.attachToContract(contract); 2946 }); 2947 }; 2948 2949 2950 /** 2951 * Should be called to check if the contract gets properly deployed on the blockchain. 2952 * 2953 * @method checkForContractAddress 2954 * @param {Object} contract 2955 * @param {Function} callback 2956 * @returns {Undefined} 2957 */ 2958 var checkForContractAddress = function (contract, callback) { 2959 var count = 0, 2960 callbackFired = false; 2961 2962 // wait for receipt 2963 var filter = contract._xcb.filter('latest', function (e) { 2964 if (!e && !callbackFired) { 2965 count++; 2966 2967 // stop watching after 50 blocks (timeout) 2968 if (count > 50) { 2969 2970 filter.stopWatching(function () { }); 2971 callbackFired = true; 2972 2973 if (callback) 2974 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2975 else 2976 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2977 2978 2979 } else { 2980 2981 contract._xcb.getTransactionReceipt(contract.transactionHash, function(e, receipt){ 2982 if(receipt && !callbackFired) { 2983 2984 contract._xcb.getCode(receipt.contractAddress, function(e, code){ 2985 /*jshint maxcomplexity: 6 */ 2986 2987 if(callbackFired || !code) 2988 return; 2989 2990 filter.stopWatching(function() {}); 2991 callbackFired = true; 2992 2993 if (code.length > 3) { 2994 2995 // console.log('Contract code deployed!'); 2996 2997 contract.address = receipt.contractAddress; 2998 2999 // attach events and methods again after we have 3000 addFunctionsToContract(contract); 3001 addEventsToContract(contract); 3002 3003 // call callback for the second time 3004 if (callback) 3005 callback(null, contract); 3006 3007 } else { 3008 if(callback) 3009 callback(new Error('The contract code couldn\'t be stored, please check your energy amount.')); 3010 else 3011 throw new Error('The contract code couldn\'t be stored, please check your energy amount.'); 3012 } 3013 }); 3014 } 3015 }); 3016 } 3017 } 3018 }); 3019 }; 3020 3021 /** 3022 * Should be called to create new ContractFactory instance 3023 * 3024 * @method ContractFactory 3025 * @param {Array} abi 3026 */ 3027 var ContractFactory = function (xcb, abi) { 3028 this.xcb = xcb; 3029 this.abi = abi; 3030 3031 /** 3032 * Should be called to create new contract on a blockchain 3033 * 3034 * @method new 3035 * @param {Any} contract constructor param1 (optional) 3036 * @param {Any} contract constructor param2 (optional) 3037 * @param {Object} contract transaction object (required) 3038 * @param {Function} callback 3039 * @returns {Contract} returns contract instance 3040 */ 3041 this.new = function () { 3042 /*jshint maxcomplexity: 7 */ 3043 3044 var contract = new Contract(this.xcb, this.abi); 3045 3046 // parse arguments 3047 var options = {}; // required! 3048 var callback; 3049 3050 var args = Array.prototype.slice.call(arguments); 3051 if (utils.isFunction(args[args.length - 1])) { 3052 callback = args.pop(); 3053 } 3054 3055 var last = args[args.length - 1]; 3056 if (utils.isObject(last) && !utils.isArray(last)) { 3057 options = args.pop(); 3058 } 3059 3060 if (options.value > 0) { 3061 var constructorAbi = abi.filter(function (json) { 3062 return json.type === 'constructor' && json.inputs.length === args.length; 3063 })[0] || {}; 3064 3065 if (!(constructorAbi.stateMutability !== "payable")) { 3066 throw new Error('Cannot send value to non-payable constructor'); 3067 } 3068 } 3069 3070 var bytes = encodeConstructorParams(this.abi, args); 3071 options.data += bytes; 3072 3073 if (callback) { 3074 3075 // wait for the contract address and check if the code was deployed 3076 this.xcb.sendTransaction(options, function (err, hash) { 3077 if (err) { 3078 callback(err); 3079 } else { 3080 // add the transaction hash 3081 contract.transactionHash = hash; 3082 3083 // call callback for the first time 3084 callback(null, contract); 3085 3086 checkForContractAddress(contract, callback); 3087 } 3088 }); 3089 } else { 3090 var hash = this.xcb.sendTransaction(options); 3091 // add the transaction hash 3092 contract.transactionHash = hash; 3093 checkForContractAddress(contract); 3094 } 3095 3096 return contract; 3097 }; 3098 3099 this.new.getData = this.getData.bind(this); 3100 }; 3101 3102 /** 3103 * Should be called to create new ContractFactory 3104 * 3105 * @method contract 3106 * @param {Array} abi 3107 * @returns {ContractFactory} new contract factory 3108 */ 3109 //var contract = function (abi) { 3110 //return new ContractFactory(abi); 3111 //}; 3112 3113 3114 3115 /** 3116 * Should be called to get access to existing contract on a blockchain 3117 * 3118 * @method at 3119 * @param {Address} contract address (required) 3120 * @param {Function} callback {optional) 3121 * @returns {Contract} returns contract if no callback was passed, 3122 * otherwise calls callback function (err, contract) 3123 */ 3124 ContractFactory.prototype.at = function (address, callback) { 3125 var contract = new Contract(this.xcb, this.abi, address); 3126 3127 // this functions are not part of prototype, 3128 // because we dont want to spoil the interface 3129 addFunctionsToContract(contract); 3130 addEventsToContract(contract); 3131 3132 if (callback) { 3133 callback(null, contract); 3134 } 3135 return contract; 3136 }; 3137 3138 /** 3139 * Gets the data, which is data to deploy plus constructor params 3140 * 3141 * @method getData 3142 */ 3143 ContractFactory.prototype.getData = function () { 3144 var options = {}; // required! 3145 var args = Array.prototype.slice.call(arguments); 3146 3147 var last = args[args.length - 1]; 3148 if (utils.isObject(last) && !utils.isArray(last)) { 3149 options = args.pop(); 3150 } 3151 3152 var bytes = encodeConstructorParams(this.abi, args); 3153 options.data += bytes; 3154 3155 return options.data; 3156 }; 3157 3158 /** 3159 * Should be called to create new contract instance 3160 * 3161 * @method Contract 3162 * @param {Array} abi 3163 * @param {Address} contract address 3164 */ 3165 var Contract = function (xcb, abi, address) { 3166 this._xcb = xcb; 3167 this.transactionHash = null; 3168 this.address = address; 3169 this.abi = abi; 3170 }; 3171 3172 module.exports = ContractFactory; 3173 3174 }, { "../ylem/coder": 7, "../utils/utils": 20, "./allevents": 23, "./event": 27, "./function": 31 }], 26: [function (require, module, exports) { 3175 /* 3176 This file is part of web3.js. 3177 3178 web3.js is free software: you can redistribute it and/or modify 3179 it under the terms of the GNU Lesser General Public License as published by 3180 the Free Software Foundation, either version 3 of the License, or 3181 (at your option) any later version. 3182 3183 web3.js is distributed in the hope that it will be useful, 3184 but WITHOUT ANY WARRANTY; without even the implied warranty of 3185 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3186 GNU Lesser General Public License for more details. 3187 3188 You should have received a copy of the GNU Lesser General Public License 3189 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3190 */ 3191 /** 3192 * @file errors.js 3193 * @author Marek Kotewicz <marek@ethdev.com> 3194 * @date 2015 3195 */ 3196 3197 module.exports = { 3198 InvalidNumberOfYlemArgs: function () { 3199 return new Error('Invalid number of arguments to Ylem function'); 3200 }, 3201 InvalidNumberOfRPCParams: function () { 3202 return new Error('Invalid number of input parameters to RPC method'); 3203 }, 3204 InvalidConnection: function (host) { 3205 return new Error('CONNECTION ERROR: Couldn\'t connect to node ' + host + '.'); 3206 }, 3207 InvalidProvider: function () { 3208 return new Error('Provider not set or invalid'); 3209 }, 3210 InvalidResponse: function (result) { 3211 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3212 return new Error(message); 3213 }, 3214 ConnectionTimeout: function (ms) { 3215 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3216 } 3217 }; 3218 3219 }, {}], 27: [function (require, module, exports) { 3220 /* 3221 This file is part of web3.js. 3222 3223 web3.js is free software: you can redistribute it and/or modify 3224 it under the terms of the GNU Lesser General Public License as published by 3225 the Free Software Foundation, either version 3 of the License, or 3226 (at your option) any later version. 3227 3228 web3.js is distributed in the hope that it will be useful, 3229 but WITHOUT ANY WARRANTY; without even the implied warranty of 3230 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3231 GNU Lesser General Public License for more details. 3232 3233 You should have received a copy of the GNU Lesser General Public License 3234 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3235 */ 3236 /** 3237 * @file event.js 3238 * @author Marek Kotewicz <marek@ethdev.com> 3239 * @date 2014 3240 */ 3241 3242 var utils = require('../utils/utils'); 3243 var coder = require('../ylem/coder'); 3244 var formatters = require('./formatters'); 3245 var sha3 = require('../utils/sha3'); 3246 var Filter = require('./filter'); 3247 var watches = require('./methods/watches'); 3248 3249 /** 3250 * This prototype should be used to create event filters 3251 */ 3252 var YlemEvent = function (requestManager, json, address) { 3253 this._requestManager = requestManager; 3254 this._params = json.inputs; 3255 this._name = utils.transformToFullName(json); 3256 this._address = address; 3257 this._anonymous = json.anonymous; 3258 }; 3259 3260 /** 3261 * Should be used to get filtered param types 3262 * 3263 * @method types 3264 * @param {Bool} decide if returned typed should be indexed 3265 * @return {Array} array of types 3266 */ 3267 YlemEvent.prototype.types = function (indexed) { 3268 return this._params.filter(function (i) { 3269 return i.indexed === indexed; 3270 }).map(function (i) { 3271 return i.type; 3272 }); 3273 }; 3274 3275 /** 3276 * Should be used to get event display name 3277 * 3278 * @method displayName 3279 * @return {String} event display name 3280 */ 3281 YlemEvent.prototype.displayName = function () { 3282 return utils.extractDisplayName(this._name); 3283 }; 3284 3285 /** 3286 * Should be used to get event type name 3287 * 3288 * @method typeName 3289 * @return {String} event type name 3290 */ 3291 YlemEvent.prototype.typeName = function () { 3292 return utils.extractTypeName(this._name); 3293 }; 3294 3295 /** 3296 * Should be used to get event signature 3297 * 3298 * @method signature 3299 * @return {String} event signature 3300 */ 3301 YlemEvent.prototype.signature = function () { 3302 return sha3(this._name); 3303 }; 3304 3305 /** 3306 * Should be used to encode indexed params and options to one final object 3307 * 3308 * @method encode 3309 * @param {Object} indexed 3310 * @param {Object} options 3311 * @return {Object} everything combined together and encoded 3312 */ 3313 YlemEvent.prototype.encode = function (indexed, options) { 3314 indexed = indexed || {}; 3315 options = options || {}; 3316 var result = {}; 3317 3318 ['fromBlock', 'toBlock'].filter(function (f) { 3319 return options[f] !== undefined; 3320 }).forEach(function (f) { 3321 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3322 }); 3323 3324 result.topics = []; 3325 3326 result.address = this._address; 3327 if (!this._anonymous) { 3328 result.topics.push('0x' + this.signature()); 3329 } 3330 3331 var indexedTopics = this._params.filter(function (i) { 3332 return i.indexed === true; 3333 }).map(function (i) { 3334 var value = indexed[i.name]; 3335 if (value === undefined || value === null) { 3336 return null; 3337 } 3338 3339 if (utils.isArray(value)) { 3340 return value.map(function (v) { 3341 return '0x' + coder.encodeParam(i.type, v); 3342 }); 3343 } 3344 return '0x' + coder.encodeParam(i.type, value); 3345 }); 3346 3347 result.topics = result.topics.concat(indexedTopics); 3348 3349 return result; 3350 }; 3351 3352 /** 3353 * Should be used to decode indexed params and options 3354 * 3355 * @method decode 3356 * @param {Object} data 3357 * @return {Object} result object with decoded indexed && not indexed params 3358 */ 3359 YlemEvent.prototype.decode = function (data) { 3360 3361 data.data = data.data || ''; 3362 data.topics = data.topics || []; 3363 3364 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3365 var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join(""); 3366 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3367 3368 var notIndexedData = data.data.slice(2); 3369 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3370 3371 var result = formatters.outputLogFormatter(data); 3372 result.event = this.displayName(); 3373 result.address = data.address; 3374 3375 result.args = this._params.reduce(function (acc, current) { 3376 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3377 return acc; 3378 }, {}); 3379 3380 delete result.data; 3381 delete result.topics; 3382 3383 return result; 3384 }; 3385 3386 /** 3387 * Should be used to create new filter object from event 3388 * 3389 * @method execute 3390 * @param {Object} indexed 3391 * @param {Object} options 3392 * @return {Object} filter object 3393 */ 3394 YlemEvent.prototype.execute = function (indexed, options, callback) { 3395 3396 if (utils.isFunction(arguments[arguments.length - 1])) { 3397 callback = arguments[arguments.length - 1]; 3398 if (arguments.length === 2) 3399 options = null; 3400 if (arguments.length === 1) { 3401 options = null; 3402 indexed = {}; 3403 } 3404 } 3405 3406 var o = this.encode(indexed, options); 3407 var formatter = this.decode.bind(this); 3408 return new Filter(o, 'xcb', this._requestManager, watches.xcb(), formatter, callback); 3409 }; 3410 3411 /** 3412 * Should be used to attach event to contract object 3413 * 3414 * @method attachToContract 3415 * @param {Contract} 3416 */ 3417 YlemEvent.prototype.attachToContract = function (contract) { 3418 var execute = this.execute.bind(this); 3419 var displayName = this.displayName(); 3420 if (!contract[displayName]) { 3421 contract[displayName] = execute; 3422 } 3423 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3424 }; 3425 3426 module.exports = YlemEvent; 3427 3428 3429 }, { "../ylem/coder": 7, "../utils/sha3": 19, "../utils/utils": 20, "./filter": 29, "./formatters": 30, "./methods/watches": 43 }], 28: [function (require, module, exports) { 3430 var formatters = require('./formatters'); 3431 var utils = require('./../utils/utils'); 3432 var Method = require('./method'); 3433 var Property = require('./property'); 3434 3435 // TODO: refactor, so the input params are not altered. 3436 // it's necessary to make same 'extension' work with multiple providers 3437 var extend = function (web3) { 3438 /* jshint maxcomplexity:5 */ 3439 var ex = function (extension) { 3440 3441 var extendedObject; 3442 if (extension.property) { 3443 if (!web3[extension.property]) { 3444 web3[extension.property] = {}; 3445 } 3446 extendedObject = web3[extension.property]; 3447 } else { 3448 extendedObject = web3; 3449 } 3450 3451 if (extension.methods) { 3452 extension.methods.forEach(function (method) { 3453 method.attachToObject(extendedObject); 3454 method.setRequestManager(web3._requestManager); 3455 }); 3456 } 3457 3458 if (extension.properties) { 3459 extension.properties.forEach(function (property) { 3460 property.attachToObject(extendedObject); 3461 property.setRequestManager(web3._requestManager); 3462 }); 3463 } 3464 }; 3465 3466 ex.formatters = formatters; 3467 ex.utils = utils; 3468 ex.Method = Method; 3469 ex.Property = Property; 3470 3471 return ex; 3472 }; 3473 3474 3475 3476 module.exports = extend; 3477 3478 3479 }, { "./../utils/utils": 20, "./formatters": 30, "./method": 36, "./property": 45 }], 29: [function (require, module, exports) { 3480 /* 3481 This file is part of web3.js. 3482 3483 web3.js is free software: you can redistribute it and/or modify 3484 it under the terms of the GNU Lesser General Public License as published by 3485 the Free Software Foundation, either version 3 of the License, or 3486 (at your option) any later version. 3487 3488 web3.js is distributed in the hope that it will be useful, 3489 but WITHOUT ANY WARRANTY; without even the implied warranty of 3490 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3491 GNU Lesser General Public License for more details. 3492 3493 You should have received a copy of the GNU Lesser General Public License 3494 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3495 */ 3496 /** @file filter.js 3497 * @authors: 3498 * Jeffrey Wilcke <jeff@ethdev.com> 3499 * Marek Kotewicz <marek@ethdev.com> 3500 * Marian Oancea <marian@ethdev.com> 3501 * Fabian Vogelsteller <fabian@ethdev.com> 3502 * Gav Wood <g@ethdev.com> 3503 * @date 2014 3504 */ 3505 3506 var formatters = require('./formatters'); 3507 var utils = require('../utils/utils'); 3508 3509 /** 3510 * Converts a given topic to a hex string, but also allows null values. 3511 * 3512 * @param {Mixed} value 3513 * @return {String} 3514 */ 3515 var toTopic = function (value) { 3516 3517 if (value === null || typeof value === 'undefined') 3518 return null; 3519 3520 value = String(value); 3521 3522 if (value.indexOf('0x') === 0) 3523 return value; 3524 else 3525 return utils.fromUtf8(value); 3526 }; 3527 3528 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3529 /// @param should be string or object 3530 /// @returns options string or object 3531 var getOptions = function (options, type) { 3532 /*jshint maxcomplexity: 6 */ 3533 3534 if (utils.isString(options)) { 3535 return options; 3536 } 3537 3538 options = options || {}; 3539 3540 3541 switch (type) { 3542 case 'xcb': 3543 3544 // make sure topics, get converted to hex 3545 options.topics = options.topics || []; 3546 options.topics = options.topics.map(function (topic) { 3547 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3548 }); 3549 3550 return { 3551 topics: options.topics, 3552 from: options.from, 3553 to: options.to, 3554 address: options.address, 3555 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3556 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3557 }; 3558 case 'shh': 3559 return options; 3560 } 3561 }; 3562 3563 /** 3564 Adds the callback and sets up the methods, to iterate over the results. 3565 3566 @method getLogsAtStart 3567 @param {Object} self 3568 @param {function} callback 3569 */ 3570 var getLogsAtStart = function (self, callback) { 3571 // call getFilterLogs for the first watch callback start 3572 if (!utils.isString(self.options)) { 3573 self.get(function (err, messages) { 3574 // don't send all the responses to all the watches again... just to self one 3575 if (err) { 3576 callback(err); 3577 } 3578 3579 if (utils.isArray(messages)) { 3580 messages.forEach(function (message) { 3581 callback(null, message); 3582 }); 3583 } 3584 }); 3585 } 3586 }; 3587 3588 /** 3589 Adds the callback and sets up the methods, to iterate over the results. 3590 3591 @method pollFilter 3592 @param {Object} self 3593 */ 3594 var pollFilter = function (self) { 3595 3596 var onMessage = function (error, messages) { 3597 if (error) { 3598 return self.callbacks.forEach(function (callback) { 3599 callback(error); 3600 }); 3601 } 3602 3603 if (utils.isArray(messages)) { 3604 messages.forEach(function (message) { 3605 message = self.formatter ? self.formatter(message) : message; 3606 self.callbacks.forEach(function (callback) { 3607 callback(null, message); 3608 }); 3609 }); 3610 } 3611 }; 3612 3613 self.requestManager.startPolling({ 3614 method: self.implementation.poll.call, 3615 params: [self.filterId], 3616 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3617 3618 }; 3619 3620 var Filter = function (options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3621 var self = this; 3622 var implementation = {}; 3623 methods.forEach(function (method) { 3624 method.setRequestManager(requestManager); 3625 method.attachToObject(implementation); 3626 }); 3627 this.requestManager = requestManager; 3628 this.options = getOptions(options, type); 3629 this.implementation = implementation; 3630 this.filterId = null; 3631 this.callbacks = []; 3632 this.getLogsCallbacks = []; 3633 this.pollFilters = []; 3634 this.formatter = formatter; 3635 this.implementation.newFilter(this.options, function (error, id) { 3636 if (error) { 3637 self.callbacks.forEach(function (cb) { 3638 cb(error); 3639 }); 3640 if (typeof filterCreationErrorCallback === 'function') { 3641 filterCreationErrorCallback(error); 3642 } 3643 } else { 3644 self.filterId = id; 3645 3646 // check if there are get pending callbacks as a consequence 3647 // of calling get() with filterId unassigned. 3648 self.getLogsCallbacks.forEach(function (cb) { 3649 self.get(cb); 3650 }); 3651 self.getLogsCallbacks = []; 3652 3653 // get filter logs for the already existing watch calls 3654 self.callbacks.forEach(function (cb) { 3655 getLogsAtStart(self, cb); 3656 }); 3657 if (self.callbacks.length > 0) 3658 pollFilter(self); 3659 3660 // start to watch immediately 3661 if (typeof callback === 'function') { 3662 return self.watch(callback); 3663 } 3664 } 3665 }); 3666 3667 return this; 3668 }; 3669 3670 Filter.prototype.watch = function (callback) { 3671 this.callbacks.push(callback); 3672 3673 if (this.filterId) { 3674 getLogsAtStart(this, callback); 3675 pollFilter(this); 3676 } 3677 3678 return this; 3679 }; 3680 3681 Filter.prototype.stopWatching = function (callback) { 3682 this.requestManager.stopPolling(this.filterId); 3683 this.callbacks = []; 3684 // remove filter async 3685 if (callback) { 3686 this.implementation.uninstallFilter(this.filterId, callback); 3687 } else { 3688 return this.implementation.uninstallFilter(this.filterId); 3689 } 3690 }; 3691 3692 Filter.prototype.get = function (callback) { 3693 var self = this; 3694 if (utils.isFunction(callback)) { 3695 if (this.filterId === null) { 3696 // If filterId is not set yet, call it back 3697 // when newFilter() assigns it. 3698 this.getLogsCallbacks.push(callback); 3699 } else { 3700 this.implementation.getLogs(this.filterId, function (err, res) { 3701 if (err) { 3702 callback(err); 3703 } else { 3704 callback(null, res.map(function (log) { 3705 return self.formatter ? self.formatter(log) : log; 3706 })); 3707 } 3708 }); 3709 } 3710 } else { 3711 if (this.filterId === null) { 3712 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3713 } 3714 var logs = this.implementation.getLogs(this.filterId); 3715 return logs.map(function (log) { 3716 return self.formatter ? self.formatter(log) : log; 3717 }); 3718 } 3719 3720 return this; 3721 }; 3722 3723 module.exports = Filter; 3724 3725 3726 }, { "../utils/utils": 20, "./formatters": 30 }], 30: [function (require, module, exports) { 3727 'use strict' 3728 3729 /* 3730 This file is part of web3.js. 3731 3732 web3.js is free software: you can redistribute it and/or modify 3733 it under the terms of the GNU Lesser General Public License as published by 3734 the Free Software Foundation, either version 3 of the License, or 3735 (at your option) any later version. 3736 3737 web3.js is distributed in the hope that it will be useful, 3738 but WITHOUT ANY WARRANTY; without even the implied warranty of 3739 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3740 GNU Lesser General Public License for more details. 3741 3742 You should have received a copy of the GNU Lesser General Public License 3743 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3744 */ 3745 /** 3746 * @file formatters.js 3747 * @author Marek Kotewicz <marek@ethdev.com> 3748 * @author Fabian Vogelsteller <fabian@ethdev.com> 3749 * @date 2015 3750 */ 3751 3752 var utils = require('../utils/utils'); 3753 var config = require('../utils/config'); 3754 var Iban = require('./iban'); 3755 3756 /** 3757 * Should the format output to a big number 3758 * 3759 * @method outputBigNumberFormatter 3760 * @param {String|Number|BigNumber} 3761 * @returns {BigNumber} object 3762 */ 3763 var outputBigNumberFormatter = function (number) { 3764 return utils.toBigNumber(number); 3765 }; 3766 3767 var isPredefinedBlockNumber = function (blockNumber) { 3768 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3769 }; 3770 3771 var inputDefaultBlockNumberFormatter = function (blockNumber) { 3772 if (blockNumber === undefined) { 3773 return config.defaultBlock; 3774 } 3775 return inputBlockNumberFormatter(blockNumber); 3776 }; 3777 3778 var inputBlockNumberFormatter = function (blockNumber) { 3779 if (blockNumber === undefined) { 3780 return undefined; 3781 } else if (isPredefinedBlockNumber(blockNumber)) { 3782 return blockNumber; 3783 } 3784 return utils.toHex(blockNumber); 3785 }; 3786 3787 /** 3788 * Formats the input of a transaction and converts all values to HEX 3789 * 3790 * @method inputCallFormatter 3791 * @param {Object} transaction options 3792 * @returns object 3793 */ 3794 var inputCallFormatter = function (options) { 3795 3796 options.from = options.from || config.defaultAccount; 3797 3798 if (options.from) { 3799 options.from = inputAddressFormatter(options.from); 3800 } 3801 3802 if (options.to) { // it might be contract creation 3803 options.to = inputAddressFormatter(options.to); 3804 } 3805 3806 ['energyPrice', 'energy', 'value', 'nonce'].filter(function (key) { 3807 return options[key] !== undefined; 3808 }).forEach(function (key) { 3809 options[key] = utils.fromDecimal(options[key]); 3810 }); 3811 3812 return options; 3813 }; 3814 3815 /** 3816 * Formats the input of a transaction and converts all values to HEX 3817 * 3818 * @method inputTransactionFormatter 3819 * @param {Object} transaction options 3820 * @returns object 3821 */ 3822 var inputTransactionFormatter = function (options) { 3823 3824 options.from = options.from || config.defaultAccount; 3825 options.from = inputAddressFormatter(options.from); 3826 3827 if (options.to) { // it might be contract creation 3828 options.to = inputAddressFormatter(options.to); 3829 } 3830 3831 ['energyPrice', 'energy', 'value', 'nonce'].filter(function (key) { 3832 return options[key] !== undefined; 3833 }).forEach(function (key) { 3834 options[key] = utils.fromDecimal(options[key]); 3835 }); 3836 3837 return options; 3838 }; 3839 3840 /** 3841 * Formats the output of a transaction to its proper values 3842 * 3843 * @method outputTransactionFormatter 3844 * @param {Object} tx 3845 * @returns {Object} 3846 */ 3847 var outputTransactionFormatter = function (tx){ 3848 if(tx.blockNumber !== null) 3849 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3850 if(tx.transactionIndex !== null) 3851 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3852 tx.nonce = utils.toDecimal(tx.nonce); 3853 tx.energy = utils.toDecimal(tx.energy); 3854 tx.energyPrice = utils.toBigNumber(tx.energyPrice); 3855 tx.value = utils.toBigNumber(tx.value); 3856 return tx; 3857 }; 3858 3859 /** 3860 * Formats the output of a transaction receipt to its proper values 3861 * 3862 * @method outputTransactionReceiptFormatter 3863 * @param {Object} receipt 3864 * @returns {Object} 3865 */ 3866 var outputTransactionReceiptFormatter = function (receipt){ 3867 if(receipt.blockNumber !== null) 3868 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3869 if(receipt.transactionIndex !== null) 3870 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3871 receipt.cumulativeEnergyUsed = utils.toDecimal(receipt.cumulativeEnergyUsed); 3872 receipt.energyUsed = utils.toDecimal(receipt.energyUsed); 3873 3874 if(utils.isArray(receipt.logs)) { 3875 receipt.logs = receipt.logs.map(function(log){ 3876 return outputLogFormatter(log); 3877 }); 3878 } 3879 3880 return receipt; 3881 }; 3882 3883 /** 3884 * Formats the output of a block to its proper values 3885 * 3886 * @method outputBlockFormatter 3887 * @param {Object} block 3888 * @returns {Object} 3889 */ 3890 var outputBlockFormatter = function(block) { 3891 3892 // transform to number 3893 block.energyLimit = utils.toDecimal(block.energyLimit); 3894 block.energyUsed = utils.toDecimal(block.energyUsed); 3895 block.size = utils.toDecimal(block.size); 3896 block.timestamp = utils.toDecimal(block.timestamp); 3897 if(block.number !== null) 3898 block.number = utils.toDecimal(block.number); 3899 3900 block.difficulty = utils.toBigNumber(block.difficulty); 3901 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3902 3903 if (utils.isArray(block.transactions)) { 3904 block.transactions.forEach(function(item){ 3905 if(!utils.isString(item)) 3906 return outputTransactionFormatter(item); 3907 }); 3908 } 3909 3910 return block; 3911 }; 3912 3913 /** 3914 * Formats the output of a log 3915 * 3916 * @method outputLogFormatter 3917 * @param {Object} log object 3918 * @returns {Object} log 3919 */ 3920 var outputLogFormatter = function(log) { 3921 if(log.blockNumber) 3922 log.blockNumber = utils.toDecimal(log.blockNumber); 3923 if(log.transactionIndex) 3924 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3925 if(log.logIndex) 3926 log.logIndex = utils.toDecimal(log.logIndex); 3927 3928 return log; 3929 }; 3930 3931 /** 3932 * Formats the input of a whisper post and converts all values to HEX 3933 * 3934 * @method inputPostFormatter 3935 * @param {Object} transaction object 3936 * @returns {Object} 3937 */ 3938 var inputPostFormatter = function(post) { 3939 3940 // post.payload = utils.toHex(post.payload); 3941 post.ttl = utils.fromDecimal(post.ttl); 3942 post.workToProve = utils.fromDecimal(post.workToProve); 3943 post.priority = utils.fromDecimal(post.priority); 3944 3945 // fallback 3946 if (!utils.isArray(post.topics)) { 3947 post.topics = post.topics ? [post.topics] : []; 3948 } 3949 3950 // format the following options 3951 post.topics = post.topics.map(function (topic) { 3952 // convert only if not hex 3953 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3954 }); 3955 3956 return post; 3957 }; 3958 3959 /** 3960 * Formats the output of a received post message 3961 * 3962 * @method outputPostFormatter 3963 * @param {Object} 3964 * @returns {Object} 3965 */ 3966 var outputPostFormatter = function (post) { 3967 3968 post.expiry = utils.toDecimal(post.expiry); 3969 post.sent = utils.toDecimal(post.sent); 3970 post.ttl = utils.toDecimal(post.ttl); 3971 post.workProved = utils.toDecimal(post.workProved); 3972 // post.payloadRaw = post.payload; 3973 // post.payload = utils.toAscii(post.payload); 3974 3975 // if (utils.isJson(post.payload)) { 3976 // post.payload = JSON.parse(post.payload); 3977 // } 3978 3979 // format the following options 3980 if (!post.topics) { 3981 post.topics = []; 3982 } 3983 post.topics = post.topics.map(function (topic) { 3984 return utils.toAscii(topic); 3985 }); 3986 3987 return post; 3988 }; 3989 3990 var inputAddressFormatter = function (address) { 3991 var iban = new Iban(address); 3992 if (iban.isValid() && iban.isDirect()) { 3993 return '0x' + iban.address(); 3994 } else if (utils.isStrictAddress(address)) { 3995 return address; 3996 } else if (utils.isAddress(address)) { 3997 return '0x' + address; 3998 } 3999 throw new Error('invalid address'); 4000 }; 4001 4002 4003 var outputSyncingFormatter = function (result) { 4004 if (!result) { 4005 return result; 4006 } 4007 4008 result.startingBlock = utils.toDecimal(result.startingBlock); 4009 result.currentBlock = utils.toDecimal(result.currentBlock); 4010 result.highestBlock = utils.toDecimal(result.highestBlock); 4011 if (result.knownStates) { 4012 result.knownStates = utils.toDecimal(result.knownStates); 4013 result.pulledStates = utils.toDecimal(result.pulledStates); 4014 } 4015 4016 return result; 4017 }; 4018 4019 module.exports = { 4020 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 4021 inputBlockNumberFormatter: inputBlockNumberFormatter, 4022 inputCallFormatter: inputCallFormatter, 4023 inputTransactionFormatter: inputTransactionFormatter, 4024 inputAddressFormatter: inputAddressFormatter, 4025 inputPostFormatter: inputPostFormatter, 4026 outputBigNumberFormatter: outputBigNumberFormatter, 4027 outputTransactionFormatter: outputTransactionFormatter, 4028 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 4029 outputBlockFormatter: outputBlockFormatter, 4030 outputLogFormatter: outputLogFormatter, 4031 outputPostFormatter: outputPostFormatter, 4032 outputSyncingFormatter: outputSyncingFormatter 4033 }; 4034 4035 4036 }, { "../utils/config": 18, "../utils/utils": 20, "./iban": 33 }], 31: [function (require, module, exports) { 4037 /* 4038 This file is part of web3.js. 4039 4040 web3.js is free software: you can redistribute it and/or modify 4041 it under the terms of the GNU Lesser General Public License as published by 4042 the Free Software Foundation, either version 3 of the License, or 4043 (at your option) any later version. 4044 4045 web3.js is distributed in the hope that it will be useful, 4046 but WITHOUT ANY WARRANTY; without even the implied warranty of 4047 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4048 GNU Lesser General Public License for more details. 4049 4050 You should have received a copy of the GNU Lesser General Public License 4051 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4052 */ 4053 /** 4054 * @file function.js 4055 * @author Marek Kotewicz <marek@ethdev.com> 4056 * @date 2015 4057 */ 4058 4059 var coder = require('../ylem/coder'); 4060 var utils = require('../utils/utils'); 4061 var errors = require('./errors'); 4062 var formatters = require('./formatters'); 4063 var sha3 = require('../utils/sha3'); 4064 4065 /** 4066 * This prototype should be used to call/sendTransaction to ylem functions 4067 */ 4068 var YlemFunction = function (xcb, json, address) { 4069 this._xcb = xcb; 4070 this._inputTypes = json.inputs.map(function (i) { 4071 return i.type; 4072 }); 4073 this._outputTypes = json.outputs.map(function (i) { 4074 return i.type; 4075 }); 4076 this._constant = json.constant || json.stateMutability === "pure" || json.stateMutability === "view"; 4077 this._payable = json.stateMutability === "payable"; 4078 this._name = utils.transformToFullName(json); 4079 this._address = address; 4080 }; 4081 4082 YlemFunction.prototype.extractCallback = function (args) { 4083 if (utils.isFunction(args[args.length - 1])) { 4084 return args.pop(); // modify the args array! 4085 } 4086 }; 4087 4088 YlemFunction.prototype.extractDefaultBlock = function (args) { 4089 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length - 1])) { 4090 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4091 } 4092 }; 4093 4094 /** 4095 * Should be called to check if the number of arguments is correct 4096 * 4097 * @method validateArgs 4098 * @param {Array} arguments 4099 * @throws {Error} if it is not 4100 */ 4101 YlemFunction.prototype.validateArgs = function (args) { 4102 var inputArgs = args.filter(function (a) { 4103 // filter the options object but not arguments that are arrays 4104 return !((utils.isObject(a) === true) && 4105 (utils.isArray(a) === false) && 4106 (utils.isBigNumber(a) === false) 4107 ); 4108 }); 4109 if (inputArgs.length !== this._inputTypes.length) { 4110 throw errors.InvalidNumberOfYlemArgs(); 4111 } 4112 }; 4113 4114 /** 4115 * Should be used to create payload from arguments 4116 * 4117 * @method toPayload 4118 * @param {Array} ylem function params 4119 * @param {Object} optional payload options 4120 */ 4121 YlemFunction.prototype.toPayload = function (args) { 4122 var options = {}; 4123 if (args.length > this._inputTypes.length && utils.isObject(args[args.length - 1])) { 4124 options = args[args.length - 1]; 4125 } 4126 this.validateArgs(args); 4127 options.to = this._address; 4128 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4129 return options; 4130 }; 4131 4132 /** 4133 * Should be used to get function signature 4134 * 4135 * @method signature 4136 * @return {String} function signature 4137 */ 4138 YlemFunction.prototype.signature = function () { 4139 return sha3(this._name).slice(0, 8); 4140 }; 4141 4142 4143 YlemFunction.prototype.unpackOutput = function (output) { 4144 if (!output) { 4145 return; 4146 } 4147 4148 output = output.length >= 2 ? output.slice(2) : output; 4149 var result = coder.decodeParams(this._outputTypes, output); 4150 return result.length === 1 ? result[0] : result; 4151 }; 4152 4153 /** 4154 * Calls a contract function. 4155 * 4156 * @method call 4157 * @param {...Object} Contract function arguments 4158 * @param {function} If the last argument is a function, the contract function 4159 * call will be asynchronous, and the callback will be passed the 4160 * error and result. 4161 * @return {String} output bytes 4162 */ 4163 YlemFunction.prototype.call = function () { 4164 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4165 var callback = this.extractCallback(args); 4166 var defaultBlock = this.extractDefaultBlock(args); 4167 var payload = this.toPayload(args); 4168 4169 4170 if (!callback) { 4171 var output = this._xcb.call(payload, defaultBlock); 4172 return this.unpackOutput(output); 4173 } 4174 4175 var self = this; 4176 this._xcb.call(payload, defaultBlock, function (error, output) { 4177 if (error) return callback(error, null); 4178 4179 var unpacked = null; 4180 try { 4181 unpacked = self.unpackOutput(output); 4182 } 4183 catch (e) { 4184 error = e; 4185 } 4186 4187 callback(error, unpacked); 4188 }); 4189 }; 4190 4191 /** 4192 * Should be used to sendTransaction to ylem function 4193 * 4194 * @method sendTransaction 4195 */ 4196 YlemFunction.prototype.sendTransaction = function () { 4197 var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; }); 4198 var callback = this.extractCallback(args); 4199 var payload = this.toPayload(args); 4200 4201 if (payload.value > 0 && !this._payable) { 4202 throw new Error('Cannot send value to non-payable function'); 4203 } 4204 4205 if (!callback) { 4206 return this._xcb.sendTransaction(payload); 4207 } 4208 4209 this._xcb.sendTransaction(payload, callback); 4210 }; 4211 4212 /** 4213 * Should be used to estimateEnergy of ylem function 4214 * 4215 * @method estimateEnergy 4216 */ 4217 YlemFunction.prototype.estimateEnergy = function () { 4218 var args = Array.prototype.slice.call(arguments); 4219 var callback = this.extractCallback(args); 4220 var payload = this.toPayload(args); 4221 4222 if (!callback) { 4223 return this._xcb.estimateEnergy(payload); 4224 } 4225 4226 this._xcb.estimateEnergy(payload, callback); 4227 }; 4228 4229 /** 4230 * Return the encoded data of the call 4231 * 4232 * @method getData 4233 * @return {String} the encoded data 4234 */ 4235 YlemFunction.prototype.getData = function () { 4236 var args = Array.prototype.slice.call(arguments); 4237 var payload = this.toPayload(args); 4238 4239 return payload.data; 4240 }; 4241 4242 /** 4243 * Should be used to get function display name 4244 * 4245 * @method displayName 4246 * @return {String} display name of the function 4247 */ 4248 YlemFunction.prototype.displayName = function () { 4249 return utils.extractDisplayName(this._name); 4250 }; 4251 4252 /** 4253 * Should be used to get function type name 4254 * 4255 * @method typeName 4256 * @return {String} type name of the function 4257 */ 4258 YlemFunction.prototype.typeName = function () { 4259 return utils.extractTypeName(this._name); 4260 }; 4261 4262 /** 4263 * Should be called to get rpc requests from ylem function 4264 * 4265 * @method request 4266 * @returns {Object} 4267 */ 4268 YlemFunction.prototype.request = function () { 4269 var args = Array.prototype.slice.call(arguments); 4270 var callback = this.extractCallback(args); 4271 var payload = this.toPayload(args); 4272 var format = this.unpackOutput.bind(this); 4273 4274 return { 4275 method: this._constant ? 'xcb_call' : 'xcb_sendTransaction', 4276 callback: callback, 4277 params: [payload], 4278 format: format 4279 }; 4280 }; 4281 4282 /** 4283 * Should be called to execute function 4284 * 4285 * @method execute 4286 */ 4287 YlemFunction.prototype.execute = function () { 4288 var transaction = !this._constant; 4289 4290 // send transaction 4291 if (transaction) { 4292 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4293 } 4294 4295 // call 4296 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4297 }; 4298 4299 /** 4300 * Should be called to attach function to contract 4301 * 4302 * @method attachToContract 4303 * @param {Contract} 4304 */ 4305 YlemFunction.prototype.attachToContract = function (contract) { 4306 var execute = this.execute.bind(this); 4307 execute.request = this.request.bind(this); 4308 execute.call = this.call.bind(this); 4309 execute.sendTransaction = this.sendTransaction.bind(this); 4310 execute.estimateEnergy = this.estimateEnergy.bind(this); 4311 execute.getData = this.getData.bind(this); 4312 var displayName = this.displayName(); 4313 if (!contract[displayName]) { 4314 contract[displayName] = execute; 4315 } 4316 contract[displayName][this.typeName()] = execute; // circular!!!! 4317 }; 4318 4319 module.exports = YlemFunction; 4320 4321 }, { "../ylem/coder": 7, "../utils/sha3": 19, "../utils/utils": 20, "./errors": 26, "./formatters": 30 }], 32: [function (require, module, exports) { 4322 /* 4323 This file is part of web3.js. 4324 4325 web3.js is free software: you can redistribute it and/or modify 4326 it under the terms of the GNU Lesser General Public License as published by 4327 the Free Software Foundation, either version 3 of the License, or 4328 (at your option) any later version. 4329 4330 web3.js is distributed in the hope that it will be useful, 4331 but WITHOUT ANY WARRANTY; without even the implied warranty of 4332 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4333 GNU Lesser General Public License for more details. 4334 4335 You should have received a copy of the GNU Lesser General Public License 4336 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4337 */ 4338 /** @file httpprovider.js 4339 * @authors: 4340 * Marek Kotewicz <marek@ethdev.com> 4341 * Marian Oancea <marian@ethdev.com> 4342 * Fabian Vogelsteller <fabian@ethdev.com> 4343 * @date 2015 4344 */ 4345 4346 var errors = require('./errors'); 4347 4348 // workaround to use httpprovider in different envs 4349 4350 // browser 4351 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4352 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4353 // node 4354 } else { 4355 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4356 } 4357 4358 var XHR2 = require('xhr2'); // jshint ignore: line 4359 4360 /** 4361 * HttpProvider should be used to send rpc calls over http 4362 */ 4363 var HttpProvider = function (host, timeout, user, password) { 4364 this.host = host || 'http://localhost:8545'; 4365 this.timeout = timeout || 0; 4366 this.user = user; 4367 this.password = password; 4368 }; 4369 4370 /** 4371 * Should be called to prepare new XMLHttpRequest 4372 * 4373 * @method prepareRequest 4374 * @param {Boolean} true if request should be async 4375 * @return {XMLHttpRequest} object 4376 */ 4377 HttpProvider.prototype.prepareRequest = function (async) { 4378 var request; 4379 4380 if (async) { 4381 request = new XHR2(); 4382 request.timeout = this.timeout; 4383 } else { 4384 request = new XMLHttpRequest(); 4385 } 4386 4387 request.open('POST', this.host, async); 4388 if (this.user && this.password) { 4389 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4390 request.setRequestHeader('Authorization', auth); 4391 } request.setRequestHeader('Content-Type', 'application/json'); 4392 return request; 4393 }; 4394 4395 /** 4396 * Should be called to make sync request 4397 * 4398 * @method send 4399 * @param {Object} payload 4400 * @return {Object} result 4401 */ 4402 HttpProvider.prototype.send = function (payload) { 4403 var request = this.prepareRequest(false); 4404 4405 try { 4406 request.send(JSON.stringify(payload)); 4407 } catch (error) { 4408 throw errors.InvalidConnection(this.host); 4409 } 4410 4411 var result = request.responseText; 4412 4413 try { 4414 result = JSON.parse(result); 4415 } catch (e) { 4416 throw errors.InvalidResponse(request.responseText); 4417 } 4418 4419 return result; 4420 }; 4421 4422 /** 4423 * Should be used to make async request 4424 * 4425 * @method sendAsync 4426 * @param {Object} payload 4427 * @param {Function} callback triggered on end with (err, result) 4428 */ 4429 HttpProvider.prototype.sendAsync = function (payload, callback) { 4430 var request = this.prepareRequest(true); 4431 4432 request.onreadystatechange = function () { 4433 if (request.readyState === 4 && request.timeout !== 1) { 4434 var result = request.responseText; 4435 var error = null; 4436 4437 try { 4438 result = JSON.parse(result); 4439 } catch (e) { 4440 error = errors.InvalidResponse(request.responseText); 4441 } 4442 4443 callback(error, result); 4444 } 4445 }; 4446 4447 request.ontimeout = function () { 4448 callback(errors.ConnectionTimeout(this.timeout)); 4449 }; 4450 4451 try { 4452 request.send(JSON.stringify(payload)); 4453 } catch (error) { 4454 callback(errors.InvalidConnection(this.host)); 4455 } 4456 }; 4457 4458 /** 4459 * Synchronously tries to make Http request 4460 * 4461 * @method isConnected 4462 * @return {Boolean} returns true if request haven't failed. Otherwise false 4463 */ 4464 HttpProvider.prototype.isConnected = function () { 4465 try { 4466 this.send({ 4467 id: 9999999999, 4468 jsonrpc: '2.0', 4469 method: 'net_listening', 4470 params: [] 4471 }); 4472 return true; 4473 } catch (e) { 4474 return false; 4475 } 4476 }; 4477 4478 module.exports = HttpProvider; 4479 4480 }, { "./errors": 26, "xhr2": 87, "xmlhttprequest": 17 }], 33: [function (require, module, exports) { 4481 /* 4482 This file is part of web3.js. 4483 4484 web3.js is free software: you can redistribute it and/or modify 4485 it under the terms of the GNU Lesser General Public License as published by 4486 the Free Software Foundation, either version 3 of the License, or 4487 (at your option) any later version. 4488 4489 web3.js is distributed in the hope that it will be useful, 4490 but WITHOUT ANY WARRANTY; without even the implied warranty of 4491 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4492 GNU Lesser General Public License for more details. 4493 4494 You should have received a copy of the GNU Lesser General Public License 4495 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4496 */ 4497 /** 4498 * @file iban.js 4499 * @author Marek Kotewicz <marek@ethdev.com> 4500 * @date 2015 4501 */ 4502 4503 var BigNumber = require('bignumber.js'); 4504 4505 var padLeft = function (string, bytes) { 4506 var result = string; 4507 while (result.length < bytes * 2) { 4508 result = '0' + result; 4509 } 4510 return result; 4511 }; 4512 4513 /** 4514 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4515 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4516 * 4517 * @method iso13616Prepare 4518 * @param {String} iban the IBAN 4519 * @returns {String} the prepared IBAN 4520 */ 4521 var iso13616Prepare = function (iban) { 4522 var A = 'A'.charCodeAt(0); 4523 var Z = 'Z'.charCodeAt(0); 4524 4525 iban = iban.toUpperCase(); 4526 iban = iban.substr(4) + iban.substr(0, 4); 4527 4528 return iban.split('').map(function (n) { 4529 var code = n.charCodeAt(0); 4530 if (code >= A && code <= Z) { 4531 // A = 10, B = 11, ... Z = 35 4532 return code - A + 10; 4533 } else { 4534 return n; 4535 } 4536 }).join(''); 4537 }; 4538 4539 /** 4540 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4541 * 4542 * @method mod9710 4543 * @param {String} iban 4544 * @returns {Number} 4545 */ 4546 var mod9710 = function (iban) { 4547 var remainder = iban, 4548 block; 4549 4550 while (remainder.length > 2) { 4551 block = remainder.slice(0, 9); 4552 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4553 } 4554 4555 return parseInt(remainder, 10) % 97; 4556 }; 4557 4558 /** 4559 * This prototype should be used to create iban object from iban correct string 4560 * 4561 * @param {String} iban 4562 */ 4563 var Iban = function (iban) { 4564 this._iban = iban; 4565 }; 4566 4567 /** 4568 * This method should be used to create iban object from core address 4569 * 4570 * @method fromAddress 4571 * @param {String} address 4572 * @return {Iban} the IBAN object 4573 */ 4574 Iban.fromAddress = function (address) { 4575 var asBn = new BigNumber(address, 16); 4576 var base36 = asBn.toString(36); 4577 var padded = padLeft(base36, 15); 4578 return Iban.fromBban(padded.toUpperCase()); 4579 }; 4580 4581 /** 4582 * Convert the passed BBAN to an IBAN for this country specification. 4583 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4584 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4585 * 4586 * @method fromBban 4587 * @param {String} bban the BBAN to convert to IBAN 4588 * @returns {Iban} the IBAN object 4589 */ 4590 Iban.fromBban = function (bban) { 4591 var countryCode = 'XE'; 4592 4593 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4594 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4595 4596 return new Iban(countryCode + checkDigit + bban); 4597 }; 4598 4599 /** 4600 * Should be used to create IBAN object for given institution and identifier 4601 * 4602 * @method createIndirect 4603 * @param {Object} options, required options are "institution" and "identifier" 4604 * @return {Iban} the IBAN object 4605 */ 4606 Iban.createIndirect = function (options) { 4607 return Iban.fromBban('XCB' + options.institution + options.identifier); 4608 }; 4609 4610 /** 4611 * Thos method should be used to check if given string is valid iban object 4612 * 4613 * @method isValid 4614 * @param {String} iban string 4615 * @return {Boolean} true if it is valid IBAN 4616 */ 4617 Iban.isValid = function (iban) { 4618 var i = new Iban(iban); 4619 return i.isValid(); 4620 }; 4621 4622 /** 4623 * Should be called to check if iban is correct 4624 * 4625 * @method isValid 4626 * @returns {Boolean} true if it is, otherwise false 4627 */ 4628 Iban.prototype.isValid = function () { 4629 return /^XE[0-9]{2}(XCB[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4630 mod9710(iso13616Prepare(this._iban)) === 1; 4631 }; 4632 4633 /** 4634 * Should be called to check if iban number is direct 4635 * 4636 * @method isDirect 4637 * @returns {Boolean} true if it is, otherwise false 4638 */ 4639 Iban.prototype.isDirect = function () { 4640 return this._iban.length === 34 || this._iban.length === 35; 4641 }; 4642 4643 /** 4644 * Should be called to check if iban number if indirect 4645 * 4646 * @method isIndirect 4647 * @returns {Boolean} true if it is, otherwise false 4648 */ 4649 Iban.prototype.isIndirect = function () { 4650 return this._iban.length === 20; 4651 }; 4652 4653 /** 4654 * Should be called to get iban checksum 4655 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4656 * 4657 * @method checksum 4658 * @returns {String} checksum 4659 */ 4660 Iban.prototype.checksum = function () { 4661 return this._iban.substr(2, 2); 4662 }; 4663 4664 /** 4665 * Should be called to get institution identifier 4666 * eg. XREG 4667 * 4668 * @method institution 4669 * @returns {String} institution identifier 4670 */ 4671 Iban.prototype.institution = function () { 4672 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4673 }; 4674 4675 /** 4676 * Should be called to get client identifier within institution 4677 * eg. GAVOFYORK 4678 * 4679 * @method client 4680 * @returns {String} client identifier 4681 */ 4682 Iban.prototype.client = function () { 4683 return this.isIndirect() ? this._iban.substr(11) : ''; 4684 }; 4685 4686 /** 4687 * Should be called to get client direct address 4688 * 4689 * @method address 4690 * @returns {String} client direct address 4691 */ 4692 Iban.prototype.address = function () { 4693 if (this.isDirect()) { 4694 var base36 = this._iban.substr(4); 4695 var asBn = new BigNumber(base36, 36); 4696 return padLeft(asBn.toString(16), 20); 4697 } 4698 4699 return ''; 4700 }; 4701 4702 Iban.prototype.toString = function () { 4703 return this._iban; 4704 }; 4705 4706 module.exports = Iban; 4707 4708 4709 }, { "bignumber.js": "bignumber.js" }], 34: [function (require, module, exports) { 4710 /* 4711 This file is part of web3.js. 4712 4713 web3.js is free software: you can redistribute it and/or modify 4714 it under the terms of the GNU Lesser General Public License as published by 4715 the Free Software Foundation, either version 3 of the License, or 4716 (at your option) any later version. 4717 4718 web3.js is distributed in the hope that it will be useful, 4719 but WITHOUT ANY WARRANTY; without even the implied warranty of 4720 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4721 GNU Lesser General Public License for more details. 4722 4723 You should have received a copy of the GNU Lesser General Public License 4724 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4725 */ 4726 /** @file ipcprovider.js 4727 * @authors: 4728 * Fabian Vogelsteller <fabian@ethdev.com> 4729 * @date 2015 4730 */ 4731 4732 "use strict"; 4733 4734 var utils = require('../utils/utils'); 4735 var errors = require('./errors'); 4736 4737 4738 var IpcProvider = function (path, net) { 4739 var _this = this; 4740 this.responseCallbacks = {}; 4741 this.path = path; 4742 4743 this.connection = net.connect({ path: this.path }); 4744 4745 this.connection.on('error', function (e) { 4746 console.error('IPC Connection Error', e); 4747 _this._timeout(); 4748 }); 4749 4750 this.connection.on('end', function () { 4751 _this._timeout(); 4752 }); 4753 4754 4755 // LISTEN FOR CONNECTION RESPONSES 4756 this.connection.on('data', function (data) { 4757 /*jshint maxcomplexity: 6 */ 4758 4759 _this._parseResponse(data.toString()).forEach(function (result) { 4760 4761 var id = null; 4762 4763 // get the id which matches the returned id 4764 if (utils.isArray(result)) { 4765 result.forEach(function (load) { 4766 if (_this.responseCallbacks[load.id]) 4767 id = load.id; 4768 }); 4769 } else { 4770 id = result.id; 4771 } 4772 4773 // fire the callback 4774 if (_this.responseCallbacks[id]) { 4775 _this.responseCallbacks[id](null, result); 4776 delete _this.responseCallbacks[id]; 4777 } 4778 }); 4779 }); 4780 }; 4781 4782 /** 4783 Will parse the response and make an array out of it. 4784 4785 @method _parseResponse 4786 @param {String} data 4787 */ 4788 IpcProvider.prototype._parseResponse = function (data) { 4789 var _this = this, 4790 returnValues = []; 4791 4792 // DE-CHUNKER 4793 var dechunkedData = data 4794 .replace(/\}[\n\r]?\{/g,'}|--|{') // }{ 4795 .replace(/\}\][\n\r]?\[\{/g,'}]|--|[{') // }][{ 4796 .replace(/\}[\n\r]?\[\{/g,'}|--|[{') // }[{ 4797 .replace(/\}\][\n\r]?\{/g,'}]|--|{') // }]{ 4798 .split('|--|'); 4799 4800 dechunkedData.forEach(function(data){ 4801 4802 // prepend the last chunk 4803 if(_this.lastChunk) 4804 data = _this.lastChunk + data; 4805 4806 var result = null; 4807 4808 try { 4809 result = JSON.parse(data); 4810 4811 } catch (e) { 4812 4813 _this.lastChunk = data; 4814 4815 // start timeout to cancel all requests 4816 clearTimeout(_this.lastChunkTimeout); 4817 _this.lastChunkTimeout = setTimeout(function () { 4818 _this._timeout(); 4819 throw errors.InvalidResponse(data); 4820 }, 1000 * 15); 4821 4822 return; 4823 } 4824 4825 // cancel timeout and set chunk to null 4826 clearTimeout(_this.lastChunkTimeout); 4827 _this.lastChunk = null; 4828 4829 if (result) 4830 returnValues.push(result); 4831 }); 4832 4833 return returnValues; 4834 }; 4835 4836 4837 /** 4838 Get the adds a callback to the responseCallbacks object, 4839 which will be called if a response matching the response Id will arrive. 4840 4841 @method _addResponseCallback 4842 */ 4843 IpcProvider.prototype._addResponseCallback = function (payload, callback) { 4844 var id = payload.id || payload[0].id; 4845 var method = payload.method || payload[0].method; 4846 4847 this.responseCallbacks[id] = callback; 4848 this.responseCallbacks[id].method = method; 4849 }; 4850 4851 /** 4852 Timeout all requests when the end/error event is fired 4853 4854 @method _timeout 4855 */ 4856 IpcProvider.prototype._timeout = function () { 4857 for (var key in this.responseCallbacks) { 4858 if (this.responseCallbacks.hasOwnProperty(key)) { 4859 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4860 delete this.responseCallbacks[key]; 4861 } 4862 } 4863 }; 4864 4865 4866 /** 4867 Check if the current connection is still valid. 4868 4869 @method isConnected 4870 */ 4871 IpcProvider.prototype.isConnected = function () { 4872 var _this = this; 4873 4874 // try reconnect, when connection is gone 4875 if (!_this.connection.writable) 4876 _this.connection.connect({ path: _this.path }); 4877 4878 return !!this.connection.writable; 4879 }; 4880 4881 IpcProvider.prototype.send = function (payload) { 4882 4883 if (this.connection.writeSync) { 4884 var result; 4885 4886 // try reconnect, when connection is gone 4887 if (!this.connection.writable) 4888 this.connection.connect({ path: this.path }); 4889 4890 var data = this.connection.writeSync(JSON.stringify(payload)); 4891 4892 try { 4893 result = JSON.parse(data); 4894 } catch (e) { 4895 throw errors.InvalidResponse(data); 4896 } 4897 4898 return result; 4899 4900 } else { 4901 throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.'); 4902 } 4903 }; 4904 4905 IpcProvider.prototype.sendAsync = function (payload, callback) { 4906 // try reconnect, when connection is gone 4907 if (!this.connection.writable) 4908 this.connection.connect({ path: this.path }); 4909 4910 4911 this.connection.write(JSON.stringify(payload)); 4912 this._addResponseCallback(payload, callback); 4913 }; 4914 4915 module.exports = IpcProvider; 4916 4917 4918 }, { "../utils/utils": 20, "./errors": 26 }], 35: [function (require, module, exports) { 4919 /* 4920 This file is part of web3.js. 4921 4922 web3.js is free software: you can redistribute it and/or modify 4923 it under the terms of the GNU Lesser General Public License as published by 4924 the Free Software Foundation, either version 3 of the License, or 4925 (at your option) any later version. 4926 4927 web3.js is distributed in the hope that it will be useful, 4928 but WITHOUT ANY WARRANTY; without even the implied warranty of 4929 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4930 GNU Lesser General Public License for more details. 4931 4932 You should have received a copy of the GNU Lesser General Public License 4933 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4934 */ 4935 /** @file jsonrpc.js 4936 * @authors: 4937 * Marek Kotewicz <marek@ethdev.com> 4938 * Aaron Kumavis <aaron@kumavis.me> 4939 * @date 2015 4940 */ 4941 4942 // Initialize Jsonrpc as a simple object with utility functions. 4943 var Jsonrpc = { 4944 messageId: 0 4945 }; 4946 4947 /** 4948 * Should be called to valid json create payload object 4949 * 4950 * @method toPayload 4951 * @param {Function} method of jsonrpc call, required 4952 * @param {Array} params, an array of method params, optional 4953 * @returns {Object} valid jsonrpc payload object 4954 */ 4955 Jsonrpc.toPayload = function (method, params) { 4956 if (!method) 4957 console.error('jsonrpc method should be specified!'); 4958 4959 // advance message ID 4960 Jsonrpc.messageId++; 4961 4962 return { 4963 jsonrpc: '2.0', 4964 id: Jsonrpc.messageId, 4965 method: method, 4966 params: params || [] 4967 }; 4968 }; 4969 4970 /** 4971 * Should be called to check if jsonrpc response is valid 4972 * 4973 * @method isValidResponse 4974 * @param {Object} 4975 * @returns {Boolean} true if response is valid, otherwise false 4976 */ 4977 Jsonrpc.isValidResponse = function (response) { 4978 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4979 4980 function validateSingleMessage(message) { 4981 return !!message && 4982 !message.error && 4983 message.jsonrpc === '2.0' && 4984 typeof message.id === 'number' && 4985 message.result !== undefined; // only undefined is not valid json object 4986 } 4987 }; 4988 4989 /** 4990 * Should be called to create batch payload object 4991 * 4992 * @method toBatchPayload 4993 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4994 * @returns {Array} batch payload 4995 */ 4996 Jsonrpc.toBatchPayload = function (messages) { 4997 return messages.map(function (message) { 4998 return Jsonrpc.toPayload(message.method, message.params); 4999 }); 5000 }; 5001 5002 module.exports = Jsonrpc; 5003 5004 5005 }, {}], 36: [function (require, module, exports) { 5006 /* 5007 This file is part of web3.js. 5008 5009 web3.js is free software: you can redistribute it and/or modify 5010 it under the terms of the GNU Lesser General Public License as published by 5011 the Free Software Foundation, either version 3 of the License, or 5012 (at your option) any later version. 5013 5014 web3.js is distributed in the hope that it will be useful, 5015 but WITHOUT ANY WARRANTY; without even the implied warranty of 5016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5017 GNU Lesser General Public License for more details. 5018 5019 You should have received a copy of the GNU Lesser General Public License 5020 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5021 */ 5022 /** 5023 * @file method.js 5024 * @author Marek Kotewicz <marek@ethdev.com> 5025 * @date 2015 5026 */ 5027 5028 var utils = require('../utils/utils'); 5029 var errors = require('./errors'); 5030 5031 var Method = function (options) { 5032 this.name = options.name; 5033 this.call = options.call; 5034 this.params = options.params || 0; 5035 this.inputFormatter = options.inputFormatter; 5036 this.outputFormatter = options.outputFormatter; 5037 this.requestManager = null; 5038 }; 5039 5040 Method.prototype.setRequestManager = function (rm) { 5041 this.requestManager = rm; 5042 }; 5043 5044 /** 5045 * Should be used to determine name of the jsonrpc method based on arguments 5046 * 5047 * @method getCall 5048 * @param {Array} arguments 5049 * @return {String} name of jsonrpc method 5050 */ 5051 Method.prototype.getCall = function (args) { 5052 return utils.isFunction(this.call) ? this.call(args) : this.call; 5053 }; 5054 5055 /** 5056 * Should be used to extract callback from array of arguments. Modifies input param 5057 * 5058 * @method extractCallback 5059 * @param {Array} arguments 5060 * @return {Function|Null} callback, if exists 5061 */ 5062 Method.prototype.extractCallback = function (args) { 5063 if (utils.isFunction(args[args.length - 1])) { 5064 return args.pop(); // modify the args array! 5065 } 5066 }; 5067 5068 /** 5069 * Should be called to check if the number of arguments is correct 5070 * 5071 * @method validateArgs 5072 * @param {Array} arguments 5073 * @throws {Error} if it is not 5074 */ 5075 Method.prototype.validateArgs = function (args) { 5076 if (args.length !== this.params) { 5077 throw errors.InvalidNumberOfRPCParams(); 5078 } 5079 }; 5080 5081 /** 5082 * Should be called to format input args of method 5083 * 5084 * @method formatInput 5085 * @param {Array} 5086 * @return {Array} 5087 */ 5088 Method.prototype.formatInput = function (args) { 5089 if (!this.inputFormatter) { 5090 return args; 5091 } 5092 5093 return this.inputFormatter.map(function (formatter, index) { 5094 return formatter ? formatter(args[index]) : args[index]; 5095 }); 5096 }; 5097 5098 /** 5099 * Should be called to format output(result) of method 5100 * 5101 * @method formatOutput 5102 * @param {Object} 5103 * @return {Object} 5104 */ 5105 Method.prototype.formatOutput = function (result) { 5106 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5107 }; 5108 5109 /** 5110 * Should create payload from given input args 5111 * 5112 * @method toPayload 5113 * @param {Array} args 5114 * @return {Object} 5115 */ 5116 Method.prototype.toPayload = function (args) { 5117 var call = this.getCall(args); 5118 var callback = this.extractCallback(args); 5119 var params = this.formatInput(args); 5120 this.validateArgs(params); 5121 5122 return { 5123 method: call, 5124 params: params, 5125 callback: callback 5126 }; 5127 }; 5128 5129 Method.prototype.attachToObject = function (obj) { 5130 var func = this.buildCall(); 5131 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5132 var name = this.name.split('.'); 5133 if (name.length > 1) { 5134 obj[name[0]] = obj[name[0]] || {}; 5135 obj[name[0]][name[1]] = func; 5136 } else { 5137 obj[name[0]] = func; 5138 } 5139 }; 5140 5141 Method.prototype.buildCall = function () { 5142 var method = this; 5143 var send = function () { 5144 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5145 if (payload.callback) { 5146 return method.requestManager.sendAsync(payload, function (err, result) { 5147 payload.callback(err, method.formatOutput(result)); 5148 }); 5149 } 5150 return method.formatOutput(method.requestManager.send(payload)); 5151 }; 5152 send.request = this.request.bind(this); 5153 return send; 5154 }; 5155 5156 /** 5157 * Should be called to create pure JSONRPC request which can be used in batch request 5158 * 5159 * @method request 5160 * @param {...} params 5161 * @return {Object} jsonrpc request 5162 */ 5163 Method.prototype.request = function () { 5164 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5165 payload.format = this.formatOutput.bind(this); 5166 return payload; 5167 }; 5168 5169 module.exports = Method; 5170 5171 }, { "../utils/utils": 20, "./errors": 26 }], 37: [function (require, module, exports) { 5172 /* 5173 This file is part of web3.js. 5174 5175 web3.js is free software: you can redistribute it and/or modify 5176 it under the terms of the GNU Lesser General Public License as published by 5177 the Free Software Foundation, either version 3 of the License, or 5178 (at your option) any later version. 5179 5180 web3.js is distributed in the hope that it will be useful, 5181 but WITHOUT ANY WARRANTY; without even the implied warranty of 5182 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5183 GNU Lesser General Public License for more details. 5184 5185 You should have received a copy of the GNU Lesser General Public License 5186 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5187 */ 5188 /** @file db.js 5189 * @authors: 5190 * Marek Kotewicz <marek@ethdev.com> 5191 * @date 2015 5192 */ 5193 5194 var Method = require('../method'); 5195 5196 var DB = function (web3) { 5197 this._requestManager = web3._requestManager; 5198 5199 var self = this; 5200 5201 methods().forEach(function (method) { 5202 method.attachToObject(self); 5203 method.setRequestManager(web3._requestManager); 5204 }); 5205 }; 5206 5207 var methods = function () { 5208 var putString = new Method({ 5209 name: 'putString', 5210 call: 'db_putString', 5211 params: 3 5212 }); 5213 5214 var getString = new Method({ 5215 name: 'getString', 5216 call: 'db_getString', 5217 params: 2 5218 }); 5219 5220 var putHex = new Method({ 5221 name: 'putHex', 5222 call: 'db_putHex', 5223 params: 3 5224 }); 5225 5226 var getHex = new Method({ 5227 name: 'getHex', 5228 call: 'db_getHex', 5229 params: 2 5230 }); 5231 5232 return [ 5233 putString, getString, putHex, getHex 5234 ]; 5235 }; 5236 5237 module.exports = DB; 5238 5239 }, { "../method": 36 }], 38: [function (require, module, exports) { 5240 /* 5241 This file is part of web3.js. 5242 5243 web3.js is free software: you can redistribute it and/or modify 5244 it under the terms of the GNU Lesser General Public License as published by 5245 the Free Software Foundation, either version 3 of the License, or 5246 (at your option) any later version. 5247 5248 web3.js is distributed in the hope that it will be useful, 5249 but WITHOUT ANY WARRANTY; without even the implied warranty of 5250 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5251 GNU Lesser General Public License for more details. 5252 5253 You should have received a copy of the GNU Lesser General Public License 5254 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5255 */ 5256 /** 5257 * @file xcb.js 5258 * @author Marek Kotewicz <marek@ethdev.com> 5259 * @author Fabian Vogelsteller <fabian@ethdev.com> 5260 * @date 2015 5261 */ 5262 5263 "use strict"; 5264 5265 var formatters = require('../formatters'); 5266 var utils = require('../../utils/utils'); 5267 var Method = require('../method'); 5268 var Property = require('../property'); 5269 var c = require('../../utils/config'); 5270 var Contract = require('../contract'); 5271 var watches = require('./watches'); 5272 var Filter = require('../filter'); 5273 var IsSyncing = require('../syncing'); 5274 var namereg = require('../namereg'); 5275 var Iban = require('../iban'); 5276 var transfer = require('../transfer'); 5277 5278 var blockCall = function (args) { 5279 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "xcb_getBlockByHash" : "xcb_getBlockByNumber"; 5280 }; 5281 5282 var transactionFromBlockCall = function (args) { 5283 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'xcb_getTransactionByBlockHashAndIndex' : 'xcb_getTransactionByBlockNumberAndIndex'; 5284 }; 5285 5286 var uncleCall = function (args) { 5287 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'xcb_getUncleByBlockHashAndIndex' : 'xcb_getUncleByBlockNumberAndIndex'; 5288 }; 5289 5290 var getBlockTransactionCountCall = function (args) { 5291 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'xcb_getBlockTransactionCountByHash' : 'xcb_getBlockTransactionCountByNumber'; 5292 }; 5293 5294 var uncleCountCall = function (args) { 5295 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'xcb_getUncleCountByBlockHash' : 'xcb_getUncleCountByBlockNumber'; 5296 }; 5297 5298 function Xcb(web3) { 5299 this._requestManager = web3._requestManager; 5300 5301 var self = this; 5302 5303 methods().forEach(function (method) { 5304 method.attachToObject(self); 5305 method.setRequestManager(self._requestManager); 5306 }); 5307 5308 properties().forEach(function (p) { 5309 p.attachToObject(self); 5310 p.setRequestManager(self._requestManager); 5311 }); 5312 5313 5314 this.iban = Iban; 5315 this.sendIBANTransaction = transfer.bind(null, this); 5316 } 5317 5318 Object.defineProperty(Xcb.prototype, 'defaultBlock', { 5319 get: function () { 5320 return c.defaultBlock; 5321 }, 5322 set: function (val) { 5323 c.defaultBlock = val; 5324 return val; 5325 } 5326 }); 5327 5328 Object.defineProperty(Xcb.prototype, 'defaultAccount', { 5329 get: function () { 5330 return c.defaultAccount; 5331 }, 5332 set: function (val) { 5333 c.defaultAccount = val; 5334 return val; 5335 } 5336 }); 5337 5338 var methods = function () { 5339 var getBalance = new Method({ 5340 name: 'getBalance', 5341 call: 'xcb_getBalance', 5342 params: 2, 5343 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5344 outputFormatter: formatters.outputBigNumberFormatter 5345 }); 5346 5347 var getStorageAt = new Method({ 5348 name: 'getStorageAt', 5349 call: 'xcb_getStorageAt', 5350 params: 3, 5351 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5352 }); 5353 5354 var getCode = new Method({ 5355 name: 'getCode', 5356 call: 'xcb_getCode', 5357 params: 2, 5358 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5359 }); 5360 5361 var getBlock = new Method({ 5362 name: 'getBlock', 5363 call: blockCall, 5364 params: 2, 5365 inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }], 5366 outputFormatter: formatters.outputBlockFormatter 5367 }); 5368 5369 var getUncle = new Method({ 5370 name: 'getUncle', 5371 call: uncleCall, 5372 params: 2, 5373 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5374 outputFormatter: formatters.outputBlockFormatter, 5375 5376 }); 5377 5378 var getCompilers = new Method({ 5379 name: 'getCompilers', 5380 call: 'xcb_getCompilers', 5381 params: 0 5382 }); 5383 5384 var getBlockTransactionCount = new Method({ 5385 name: 'getBlockTransactionCount', 5386 call: getBlockTransactionCountCall, 5387 params: 1, 5388 inputFormatter: [formatters.inputBlockNumberFormatter], 5389 outputFormatter: utils.toDecimal 5390 }); 5391 5392 var getBlockUncleCount = new Method({ 5393 name: 'getBlockUncleCount', 5394 call: uncleCountCall, 5395 params: 1, 5396 inputFormatter: [formatters.inputBlockNumberFormatter], 5397 outputFormatter: utils.toDecimal 5398 }); 5399 5400 var getTransaction = new Method({ 5401 name: 'getTransaction', 5402 call: 'xcb_getTransactionByHash', 5403 params: 1, 5404 outputFormatter: formatters.outputTransactionFormatter 5405 }); 5406 5407 var getTransactionFromBlock = new Method({ 5408 name: 'getTransactionFromBlock', 5409 call: transactionFromBlockCall, 5410 params: 2, 5411 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5412 outputFormatter: formatters.outputTransactionFormatter 5413 }); 5414 5415 var getTransactionReceipt = new Method({ 5416 name: 'getTransactionReceipt', 5417 call: 'xcb_getTransactionReceipt', 5418 params: 1, 5419 outputFormatter: formatters.outputTransactionReceiptFormatter 5420 }); 5421 5422 var getTransactionCount = new Method({ 5423 name: 'getTransactionCount', 5424 call: 'xcb_getTransactionCount', 5425 params: 2, 5426 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5427 outputFormatter: utils.toDecimal 5428 }); 5429 5430 var sendRawTransaction = new Method({ 5431 name: 'sendRawTransaction', 5432 call: 'xcb_sendRawTransaction', 5433 params: 1, 5434 inputFormatter: [null] 5435 }); 5436 5437 var sendTransaction = new Method({ 5438 name: 'sendTransaction', 5439 call: 'xcb_sendTransaction', 5440 params: 1, 5441 inputFormatter: [formatters.inputTransactionFormatter] 5442 }); 5443 5444 var signTransaction = new Method({ 5445 name: 'signTransaction', 5446 call: 'xcb_signTransaction', 5447 params: 1, 5448 inputFormatter: [formatters.inputTransactionFormatter] 5449 }); 5450 5451 var sign = new Method({ 5452 name: 'sign', 5453 call: 'xcb_sign', 5454 params: 2, 5455 inputFormatter: [formatters.inputAddressFormatter, null] 5456 }); 5457 5458 var call = new Method({ 5459 name: 'call', 5460 call: 'xcb_call', 5461 params: 2, 5462 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5463 }); 5464 5465 var estimateEnergy = new Method({ 5466 name: 'estimateEnergy', 5467 call: 'xcb_estimateEnergy', 5468 params: 1, 5469 inputFormatter: [formatters.inputCallFormatter], 5470 outputFormatter: utils.toDecimal 5471 }); 5472 5473 var compileYlem = new Method({ 5474 name: 'compile.ylem', 5475 call: 'xcb_compileYlem', 5476 params: 1 5477 }); 5478 5479 var compileLLL = new Method({ 5480 name: 'compile.lll', 5481 call: 'xcb_compileLLL', 5482 params: 1 5483 }); 5484 5485 var compileSerpent = new Method({ 5486 name: 'compile.serpent', 5487 call: 'xcb_compileSerpent', 5488 params: 1 5489 }); 5490 5491 var submitWork = new Method({ 5492 name: 'submitWork', 5493 call: 'xcb_submitWork', 5494 params: 3 5495 }); 5496 5497 var getWork = new Method({ 5498 name: 'getWork', 5499 call: 'xcb_getWork', 5500 params: 0 5501 }); 5502 5503 return [ 5504 getBalance, 5505 getStorageAt, 5506 getCode, 5507 getBlock, 5508 getUncle, 5509 getCompilers, 5510 getBlockTransactionCount, 5511 getBlockUncleCount, 5512 getTransaction, 5513 getTransactionFromBlock, 5514 getTransactionReceipt, 5515 getTransactionCount, 5516 call, 5517 estimateEnergy, 5518 sendRawTransaction, 5519 signTransaction, 5520 sendTransaction, 5521 sign, 5522 compileYlem, 5523 compileLLL, 5524 compileSerpent, 5525 submitWork, 5526 getWork 5527 ]; 5528 }; 5529 5530 5531 var properties = function () { 5532 return [ 5533 new Property({ 5534 name: 'coinbase', 5535 getter: 'xcb_coinbase' 5536 }), 5537 new Property({ 5538 name: 'mining', 5539 getter: 'xcb_mining' 5540 }), 5541 new Property({ 5542 name: 'hashrate', 5543 getter: 'xcb_hashrate', 5544 outputFormatter: utils.toDecimal 5545 }), 5546 new Property({ 5547 name: 'syncing', 5548 getter: 'xcb_syncing', 5549 outputFormatter: formatters.outputSyncingFormatter 5550 }), 5551 new Property({ 5552 name: 'energyPrice', 5553 getter: 'xcb_energyPrice', 5554 outputFormatter: formatters.outputBigNumberFormatter 5555 }), 5556 new Property({ 5557 name: 'accounts', 5558 getter: 'xcb_accounts' 5559 }), 5560 new Property({ 5561 name: 'blockNumber', 5562 getter: 'xcb_blockNumber', 5563 outputFormatter: utils.toDecimal 5564 }), 5565 new Property({ 5566 name: 'protocolVersion', 5567 getter: 'xcb_protocolVersion' 5568 }) 5569 ]; 5570 }; 5571 5572 Xcb.prototype.contract = function (abi) { 5573 var factory = new Contract(this, abi); 5574 return factory; 5575 }; 5576 5577 Xcb.prototype.filter = function (options, callback, filterCreationErrorCallback) { 5578 return new Filter(options, 'xcb', this._requestManager, watches.xcb(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5579 }; 5580 5581 Xcb.prototype.namereg = function () { 5582 return this.contract(namereg.global.abi).at(namereg.global.address); 5583 }; 5584 5585 Xcb.prototype.icapNamereg = function () { 5586 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5587 }; 5588 5589 Xcb.prototype.isSyncing = function (callback) { 5590 return new IsSyncing(this._requestManager, callback); 5591 }; 5592 5593 module.exports = Xcb; 5594 5595 }, { "../../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) { 5596 /* 5597 This file is part of web3.js. 5598 5599 web3.js is free software: you can redistribute it and/or modify 5600 it under the terms of the GNU Lesser General Public License as published by 5601 the Free Software Foundation, either version 3 of the License, or 5602 (at your option) any later version. 5603 5604 web3.js is distributed in the hope that it will be useful, 5605 but WITHOUT ANY WARRANTY; without even the implied warranty of 5606 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5607 GNU Lesser General Public License for more details. 5608 5609 You should have received a copy of the GNU Lesser General Public License 5610 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5611 */ 5612 /** @file xcb.js 5613 * @authors: 5614 * Marek Kotewicz <marek@ethdev.com> 5615 * @date 2015 5616 */ 5617 5618 var utils = require('../../utils/utils'); 5619 var Property = require('../property'); 5620 5621 var Net = function (web3) { 5622 this._requestManager = web3._requestManager; 5623 5624 var self = this; 5625 5626 properties().forEach(function (p) { 5627 p.attachToObject(self); 5628 p.setRequestManager(web3._requestManager); 5629 }); 5630 }; 5631 5632 /// @returns an array of objects describing web3.xcb api properties 5633 var properties = function () { 5634 return [ 5635 new Property({ 5636 name: 'listening', 5637 getter: 'net_listening' 5638 }), 5639 new Property({ 5640 name: 'peerCount', 5641 getter: 'net_peerCount', 5642 outputFormatter: utils.toDecimal 5643 }) 5644 ]; 5645 }; 5646 5647 module.exports = Net; 5648 5649 }, { "../../utils/utils": 20, "../property": 45 }], 40: [function (require, module, exports) { 5650 /* 5651 This file is part of web3.js. 5652 5653 web3.js is free software: you can redistribute it and/or modify 5654 it under the terms of the GNU Lesser General Public License as published by 5655 the Free Software Foundation, either version 3 of the License, or 5656 (at your option) any later version. 5657 5658 web3.js is distributed in the hope that it will be useful, 5659 but WITHOUT ANY WARRANTY; without even the implied warranty of 5660 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5661 GNU Lesser General Public License for more details. 5662 5663 You should have received a copy of the GNU Lesser General Public License 5664 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5665 */ 5666 /** 5667 * @file xcb.js 5668 * @author Marek Kotewicz <marek@ethdev.com> 5669 * @author Fabian Vogelsteller <fabian@ethdev.com> 5670 * @date 2015 5671 */ 5672 5673 "use strict"; 5674 5675 var Method = require('../method'); 5676 var Property = require('../property'); 5677 var formatters = require('../formatters'); 5678 5679 function Personal(web3) { 5680 this._requestManager = web3._requestManager; 5681 5682 var self = this; 5683 5684 methods().forEach(function (method) { 5685 method.attachToObject(self); 5686 method.setRequestManager(self._requestManager); 5687 }); 5688 5689 properties().forEach(function (p) { 5690 p.attachToObject(self); 5691 p.setRequestManager(self._requestManager); 5692 }); 5693 } 5694 5695 var methods = function () { 5696 var newAccount = new Method({ 5697 name: 'newAccount', 5698 call: 'personal_newAccount', 5699 params: 1, 5700 inputFormatter: [null] 5701 }); 5702 5703 var importRawKey = new Method({ 5704 name: 'importRawKey', 5705 call: 'personal_importRawKey', 5706 params: 2 5707 }); 5708 5709 var sign = new Method({ 5710 name: 'sign', 5711 call: 'personal_sign', 5712 params: 3, 5713 inputFormatter: [null, formatters.inputAddressFormatter, null] 5714 }); 5715 5716 var ecRecover = new Method({ 5717 name: 'ecRecover', 5718 call: 'personal_ecRecover', 5719 params: 2 5720 }); 5721 5722 var unlockAccount = new Method({ 5723 name: 'unlockAccount', 5724 call: 'personal_unlockAccount', 5725 params: 3, 5726 inputFormatter: [formatters.inputAddressFormatter, null, null] 5727 }); 5728 5729 var sendTransaction = new Method({ 5730 name: 'sendTransaction', 5731 call: 'personal_sendTransaction', 5732 params: 2, 5733 inputFormatter: [formatters.inputTransactionFormatter, null] 5734 }); 5735 5736 var lockAccount = new Method({ 5737 name: 'lockAccount', 5738 call: 'personal_lockAccount', 5739 params: 1, 5740 inputFormatter: [formatters.inputAddressFormatter] 5741 }); 5742 5743 return [ 5744 newAccount, 5745 importRawKey, 5746 unlockAccount, 5747 ecRecover, 5748 sign, 5749 sendTransaction, 5750 lockAccount 5751 ]; 5752 }; 5753 5754 var properties = function () { 5755 return [ 5756 new Property({ 5757 name: 'listAccounts', 5758 getter: 'personal_listAccounts' 5759 }) 5760 ]; 5761 }; 5762 5763 5764 module.exports = Personal; 5765 5766 }, { "../formatters": 30, "../method": 36, "../property": 45 }], 41: [function (require, module, exports) { 5767 /* 5768 This file is part of web3.js. 5769 5770 web3.js is free software: you can redistribute it and/or modify 5771 it under the terms of the GNU Lesser General Public License as published by 5772 the Free Software Foundation, either version 3 of the License, or 5773 (at your option) any later version. 5774 5775 web3.js is distributed in the hope that it will be useful, 5776 but WITHOUT ANY WARRANTY; without even the implied warranty of 5777 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5778 GNU Lesser General Public License for more details. 5779 5780 You should have received a copy of the GNU Lesser General Public License 5781 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5782 */ 5783 /** @file shh.js 5784 * @authors: 5785 * Fabian Vogelsteller <fabian@core.org> 5786 * Marek Kotewicz <marek@ethcore.io> 5787 * @date 2017 5788 */ 5789 5790 var Method = require('../method'); 5791 var Filter = require('../filter'); 5792 var watches = require('./watches'); 5793 5794 var Shh = function (web3) { 5795 this._requestManager = web3._requestManager; 5796 5797 var self = this; 5798 5799 methods().forEach(function (method) { 5800 method.attachToObject(self); 5801 method.setRequestManager(self._requestManager); 5802 }); 5803 }; 5804 5805 Shh.prototype.newMessageFilter = function (options, callback, filterCreationErrorCallback) { 5806 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 5807 }; 5808 5809 var methods = function () { 5810 5811 return [ 5812 new Method({ 5813 name: 'version', 5814 call: 'shh_version', 5815 params: 0 5816 }), 5817 new Method({ 5818 name: 'info', 5819 call: 'shh_info', 5820 params: 0 5821 }), 5822 new Method({ 5823 name: 'setMaxMessageSize', 5824 call: 'shh_setMaxMessageSize', 5825 params: 1 5826 }), 5827 new Method({ 5828 name: 'setMinPoW', 5829 call: 'shh_setMinPoW', 5830 params: 1 5831 }), 5832 new Method({ 5833 name: 'markTrustedPeer', 5834 call: 'shh_markTrustedPeer', 5835 params: 1 5836 }), 5837 new Method({ 5838 name: 'newKeyPair', 5839 call: 'shh_newKeyPair', 5840 params: 0 5841 }), 5842 new Method({ 5843 name: 'addPrivateKey', 5844 call: 'shh_addPrivateKey', 5845 params: 1 5846 }), 5847 new Method({ 5848 name: 'deleteKeyPair', 5849 call: 'shh_deleteKeyPair', 5850 params: 1 5851 }), 5852 new Method({ 5853 name: 'hasKeyPair', 5854 call: 'shh_hasKeyPair', 5855 params: 1 5856 }), 5857 new Method({ 5858 name: 'getPublicKey', 5859 call: 'shh_getPublicKey', 5860 params: 1 5861 }), 5862 new Method({ 5863 name: 'getPrivateKey', 5864 call: 'shh_getPrivateKey', 5865 params: 1 5866 }), 5867 new Method({ 5868 name: 'newSymKey', 5869 call: 'shh_newSymKey', 5870 params: 0 5871 }), 5872 new Method({ 5873 name: 'addSymKey', 5874 call: 'shh_addSymKey', 5875 params: 1 5876 }), 5877 new Method({ 5878 name: 'generateSymKeyFromPassword', 5879 call: 'shh_generateSymKeyFromPassword', 5880 params: 1 5881 }), 5882 new Method({ 5883 name: 'hasSymKey', 5884 call: 'shh_hasSymKey', 5885 params: 1 5886 }), 5887 new Method({ 5888 name: 'getSymKey', 5889 call: 'shh_getSymKey', 5890 params: 1 5891 }), 5892 new Method({ 5893 name: 'deleteSymKey', 5894 call: 'shh_deleteSymKey', 5895 params: 1 5896 }), 5897 5898 // subscribe and unsubscribe missing 5899 5900 new Method({ 5901 name: 'post', 5902 call: 'shh_post', 5903 params: 1, 5904 inputFormatter: [null] 5905 }) 5906 ]; 5907 }; 5908 5909 module.exports = Shh; 5910 5911 5912 }, { "../filter": 29, "../method": 36, "./watches": 43 }], 42: [function (require, module, exports) { 5913 /* 5914 This file is part of web3.js. 5915 5916 web3.js is free software: you can redistribute it and/or modify 5917 it under the terms of the GNU Lesser General Public License as published by 5918 the Free Software Foundation, either version 3 of the License, or 5919 (at your option) any later version. 5920 5921 web3.js is distributed in the hope that it will be useful, 5922 but WITHOUT ANY WARRANTY; without even the implied warranty of 5923 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5924 GNU Lesser General Public License for more details. 5925 5926 You should have received a copy of the GNU Lesser General Public License 5927 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5928 */ 5929 /** 5930 * @file bzz.js 5931 * @author Alex Beregszaszi <alex@rtfs.hu> 5932 * @date 2016 5933 * 5934 * Reference: https://github.com/core-coin/go-core/blob/swarm/internal/web3ext/web3ext.go#L33 5935 */ 5936 5937 "use strict"; 5938 5939 var Method = require('../method'); 5940 var Property = require('../property'); 5941 5942 function Swarm(web3) { 5943 this._requestManager = web3._requestManager; 5944 5945 var self = this; 5946 5947 methods().forEach(function (method) { 5948 method.attachToObject(self); 5949 method.setRequestManager(self._requestManager); 5950 }); 5951 5952 properties().forEach(function (p) { 5953 p.attachToObject(self); 5954 p.setRequestManager(self._requestManager); 5955 }); 5956 } 5957 5958 var methods = function () { 5959 var blockNetworkRead = new Method({ 5960 name: 'blockNetworkRead', 5961 call: 'bzz_blockNetworkRead', 5962 params: 1, 5963 inputFormatter: [null] 5964 }); 5965 5966 var syncEnabled = new Method({ 5967 name: 'syncEnabled', 5968 call: 'bzz_syncEnabled', 5969 params: 1, 5970 inputFormatter: [null] 5971 }); 5972 5973 var swapEnabled = new Method({ 5974 name: 'swapEnabled', 5975 call: 'bzz_swapEnabled', 5976 params: 1, 5977 inputFormatter: [null] 5978 }); 5979 5980 var download = new Method({ 5981 name: 'download', 5982 call: 'bzz_download', 5983 params: 2, 5984 inputFormatter: [null, null] 5985 }); 5986 5987 var upload = new Method({ 5988 name: 'upload', 5989 call: 'bzz_upload', 5990 params: 2, 5991 inputFormatter: [null, null] 5992 }); 5993 5994 var retrieve = new Method({ 5995 name: 'retrieve', 5996 call: 'bzz_retrieve', 5997 params: 1, 5998 inputFormatter: [null] 5999 }); 6000 6001 var store = new Method({ 6002 name: 'store', 6003 call: 'bzz_store', 6004 params: 2, 6005 inputFormatter: [null, null] 6006 }); 6007 6008 var get = new Method({ 6009 name: 'get', 6010 call: 'bzz_get', 6011 params: 1, 6012 inputFormatter: [null] 6013 }); 6014 6015 var put = new Method({ 6016 name: 'put', 6017 call: 'bzz_put', 6018 params: 2, 6019 inputFormatter: [null, null] 6020 }); 6021 6022 var modify = new Method({ 6023 name: 'modify', 6024 call: 'bzz_modify', 6025 params: 4, 6026 inputFormatter: [null, null, null, null] 6027 }); 6028 6029 return [ 6030 blockNetworkRead, 6031 syncEnabled, 6032 swapEnabled, 6033 download, 6034 upload, 6035 retrieve, 6036 store, 6037 get, 6038 put, 6039 modify 6040 ]; 6041 }; 6042 6043 var properties = function () { 6044 return [ 6045 new Property({ 6046 name: 'hive', 6047 getter: 'bzz_hive' 6048 }), 6049 new Property({ 6050 name: 'info', 6051 getter: 'bzz_info' 6052 }) 6053 ]; 6054 }; 6055 6056 6057 module.exports = Swarm; 6058 6059 }, { "../method": 36, "../property": 45 }], 43: [function (require, module, exports) { 6060 /* 6061 This file is part of web3.js. 6062 6063 web3.js is free software: you can redistribute it and/or modify 6064 it under the terms of the GNU Lesser General Public License as published by 6065 the Free Software Foundation, either version 3 of the License, or 6066 (at your option) any later version. 6067 6068 web3.js is distributed in the hope that it will be useful, 6069 but WITHOUT ANY WARRANTY; without even the implied warranty of 6070 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6071 GNU Lesser General Public License for more details. 6072 6073 You should have received a copy of the GNU Lesser General Public License 6074 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6075 */ 6076 /** @file watches.js 6077 * @authors: 6078 * Marek Kotewicz <marek@ethdev.com> 6079 * @date 2015 6080 */ 6081 6082 var Method = require('../method'); 6083 6084 /// @returns an array of objects describing web3.xcb.filter api methods 6085 var xcb = function () { 6086 var newFilterCall = function (args) { 6087 var type = args[0]; 6088 6089 switch(type) { 6090 case 'latest': 6091 args.shift(); 6092 this.params = 0; 6093 return 'xcb_newBlockFilter'; 6094 case 'pending': 6095 args.shift(); 6096 this.params = 0; 6097 return 'xcb_newPendingTransactionFilter'; 6098 default: 6099 return 'xcb_newFilter'; 6100 } 6101 }; 6102 6103 var newFilter = new Method({ 6104 name: 'newFilter', 6105 call: newFilterCall, 6106 params: 1 6107 }); 6108 6109 var uninstallFilter = new Method({ 6110 name: 'uninstallFilter', 6111 call: 'xcb_uninstallFilter', 6112 params: 1 6113 }); 6114 6115 var getLogs = new Method({ 6116 name: 'getLogs', 6117 call: 'xcb_getFilterLogs', 6118 params: 1 6119 }); 6120 6121 var poll = new Method({ 6122 name: 'poll', 6123 call: 'xcb_getFilterChanges', 6124 params: 1 6125 }); 6126 6127 return [ 6128 newFilter, 6129 uninstallFilter, 6130 getLogs, 6131 poll 6132 ]; 6133 }; 6134 6135 /// @returns an array of objects describing web3.shh.watch api methods 6136 var shh = function () { 6137 6138 return [ 6139 new Method({ 6140 name: 'newFilter', 6141 call: 'shh_newMessageFilter', 6142 params: 1 6143 }), 6144 new Method({ 6145 name: 'uninstallFilter', 6146 call: 'shh_deleteMessageFilter', 6147 params: 1 6148 }), 6149 new Method({ 6150 name: 'getLogs', 6151 call: 'shh_getFilterMessages', 6152 params: 1 6153 }), 6154 new Method({ 6155 name: 'poll', 6156 call: 'shh_getFilterMessages', 6157 params: 1 6158 }) 6159 ]; 6160 }; 6161 6162 module.exports = { 6163 xcb: xcb, 6164 shh: shh 6165 }; 6166 6167 6168 }, { "../method": 36 }], 44: [function (require, module, exports) { 6169 /* 6170 This file is part of web3.js. 6171 6172 web3.js is free software: you can redistribute it and/or modify 6173 it under the terms of the GNU Lesser General Public License as published by 6174 the Free Software Foundation, either version 3 of the License, or 6175 (at your option) any later version. 6176 6177 web3.js is distributed in the hope that it will be useful, 6178 but WITHOUT ANY WARRANTY; without even the implied warranty of 6179 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6180 GNU Lesser General Public License for more details. 6181 6182 You should have received a copy of the GNU Lesser General Public License 6183 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6184 */ 6185 /** 6186 * @file namereg.js 6187 * @author Marek Kotewicz <marek@ethdev.com> 6188 * @date 2015 6189 */ 6190 6191 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6192 var icapRegistrarAbi= require('../contracts/ICAPRegistrar.json'); 6193 6194 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6195 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6196 6197 module.exports = { 6198 global: { 6199 abi: globalRegistrarAbi, 6200 address: globalNameregAddress 6201 }, 6202 icap: { 6203 abi: icapRegistrarAbi, 6204 address: icapNameregAddress 6205 } 6206 }; 6207 6208 6209 }, { "../contracts/GlobalRegistrar.json": 1, "../contracts/ICAPRegistrar.json": 2 }], 45: [function (require, module, exports) { 6210 /* 6211 This file is part of web3.js. 6212 6213 web3.js is free software: you can redistribute it and/or modify 6214 it under the terms of the GNU Lesser General Public License as published by 6215 the Free Software Foundation, either version 3 of the License, or 6216 (at your option) any later version. 6217 6218 web3.js is distributed in the hope that it will be useful, 6219 but WITHOUT ANY WARRANTY; without even the implied warranty of 6220 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6221 GNU Lesser General Public License for more details. 6222 6223 You should have received a copy of the GNU Lesser General Public License 6224 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6225 */ 6226 /** 6227 * @file property.js 6228 * @author Fabian Vogelsteller <fabian@frozeman.de> 6229 * @author Marek Kotewicz <marek@ethdev.com> 6230 * @date 2015 6231 */ 6232 6233 var utils = require('../utils/utils'); 6234 6235 var Property = function (options) { 6236 this.name = options.name; 6237 this.getter = options.getter; 6238 this.setter = options.setter; 6239 this.outputFormatter = options.outputFormatter; 6240 this.inputFormatter = options.inputFormatter; 6241 this.requestManager = null; 6242 }; 6243 6244 Property.prototype.setRequestManager = function (rm) { 6245 this.requestManager = rm; 6246 }; 6247 6248 /** 6249 * Should be called to format input args of method 6250 * 6251 * @method formatInput 6252 * @param {Array} 6253 * @return {Array} 6254 */ 6255 Property.prototype.formatInput = function (arg) { 6256 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6257 }; 6258 6259 /** 6260 * Should be called to format output(result) of method 6261 * 6262 * @method formatOutput 6263 * @param {Object} 6264 * @return {Object} 6265 */ 6266 Property.prototype.formatOutput = function (result) { 6267 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6268 }; 6269 6270 /** 6271 * Should be used to extract callback from array of arguments. Modifies input param 6272 * 6273 * @method extractCallback 6274 * @param {Array} arguments 6275 * @return {Function|Null} callback, if exists 6276 */ 6277 Property.prototype.extractCallback = function (args) { 6278 if (utils.isFunction(args[args.length - 1])) { 6279 return args.pop(); // modify the args array! 6280 } 6281 }; 6282 6283 6284 /** 6285 * Should attach function to method 6286 * 6287 * @method attachToObject 6288 * @param {Object} 6289 * @param {Function} 6290 */ 6291 Property.prototype.attachToObject = function (obj) { 6292 var proto = { 6293 get: this.buildGet(), 6294 enumerable: true 6295 }; 6296 6297 var names = this.name.split('.'); 6298 var name = names[0]; 6299 if (names.length > 1) { 6300 obj[names[0]] = obj[names[0]] || {}; 6301 obj = obj[names[0]]; 6302 name = names[1]; 6303 } 6304 6305 Object.defineProperty(obj, name, proto); 6306 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6307 }; 6308 6309 var asyncGetterName = function (name) { 6310 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6311 }; 6312 6313 Property.prototype.buildGet = function () { 6314 var property = this; 6315 return function get() { 6316 return property.formatOutput(property.requestManager.send({ 6317 method: property.getter 6318 })); 6319 }; 6320 }; 6321 6322 Property.prototype.buildAsyncGet = function () { 6323 var property = this; 6324 var get = function (callback) { 6325 property.requestManager.sendAsync({ 6326 method: property.getter 6327 }, function (err, result) { 6328 callback(err, property.formatOutput(result)); 6329 }); 6330 }; 6331 get.request = this.request.bind(this); 6332 return get; 6333 }; 6334 6335 /** 6336 * Should be called to create pure JSONRPC request which can be used in batch request 6337 * 6338 * @method request 6339 * @param {...} params 6340 * @return {Object} jsonrpc request 6341 */ 6342 Property.prototype.request = function () { 6343 var payload = { 6344 method: this.getter, 6345 params: [], 6346 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6347 }; 6348 payload.format = this.formatOutput.bind(this); 6349 return payload; 6350 }; 6351 6352 module.exports = Property; 6353 6354 6355 }, { "../utils/utils": 20 }], 46: [function (require, module, exports) { 6356 /* 6357 This file is part of web3.js. 6358 6359 web3.js is free software: you can redistribute it and/or modify 6360 it under the terms of the GNU Lesser General Public License as published by 6361 the Free Software Foundation, either version 3 of the License, or 6362 (at your option) any later version. 6363 6364 web3.js is distributed in the hope that it will be useful, 6365 but WITHOUT ANY WARRANTY; without even the implied warranty of 6366 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6367 GNU Lesser General Public License for more details. 6368 6369 You should have received a copy of the GNU Lesser General Public License 6370 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6371 */ 6372 /** 6373 * @file requestmanager.js 6374 * @author Jeffrey Wilcke <jeff@ethdev.com> 6375 * @author Marek Kotewicz <marek@ethdev.com> 6376 * @author Marian Oancea <marian@ethdev.com> 6377 * @author Fabian Vogelsteller <fabian@ethdev.com> 6378 * @author Gav Wood <g@ethdev.com> 6379 * @date 2014 6380 */ 6381 6382 var Jsonrpc = require('./jsonrpc'); 6383 var utils = require('../utils/utils'); 6384 var c = require('../utils/config'); 6385 var errors = require('./errors'); 6386 6387 /** 6388 * It's responsible for passing messages to providers 6389 * It's also responsible for polling the core node for incoming messages 6390 * Default poll timeout is 1 second 6391 * Singleton 6392 */ 6393 var RequestManager = function (provider) { 6394 this.provider = provider; 6395 this.polls = {}; 6396 this.timeout = null; 6397 }; 6398 6399 /** 6400 * Should be used to synchronously send request 6401 * 6402 * @method send 6403 * @param {Object} data 6404 * @return {Object} 6405 */ 6406 RequestManager.prototype.send = function (data) { 6407 if (!this.provider) { 6408 console.error(errors.InvalidProvider()); 6409 return null; 6410 } 6411 6412 var payload = Jsonrpc.toPayload(data.method, data.params); 6413 var result = this.provider.send(payload); 6414 6415 if (!Jsonrpc.isValidResponse(result)) { 6416 throw errors.InvalidResponse(result); 6417 } 6418 6419 return result.result; 6420 }; 6421 6422 /** 6423 * Should be used to asynchronously send request 6424 * 6425 * @method sendAsync 6426 * @param {Object} data 6427 * @param {Function} callback 6428 */ 6429 RequestManager.prototype.sendAsync = function (data, callback) { 6430 if (!this.provider) { 6431 return callback(errors.InvalidProvider()); 6432 } 6433 6434 var payload = Jsonrpc.toPayload(data.method, data.params); 6435 this.provider.sendAsync(payload, function (err, result) { 6436 if (err) { 6437 return callback(err); 6438 } 6439 6440 if (!Jsonrpc.isValidResponse(result)) { 6441 return callback(errors.InvalidResponse(result)); 6442 } 6443 6444 callback(null, result.result); 6445 }); 6446 }; 6447 6448 /** 6449 * Should be called to asynchronously send batch request 6450 * 6451 * @method sendBatch 6452 * @param {Array} batch data 6453 * @param {Function} callback 6454 */ 6455 RequestManager.prototype.sendBatch = function (data, callback) { 6456 if (!this.provider) { 6457 return callback(errors.InvalidProvider()); 6458 } 6459 6460 var payload = Jsonrpc.toBatchPayload(data); 6461 6462 this.provider.sendAsync(payload, function (err, results) { 6463 if (err) { 6464 return callback(err); 6465 } 6466 6467 if (!utils.isArray(results)) { 6468 return callback(errors.InvalidResponse(results)); 6469 } 6470 6471 callback(err, results); 6472 }); 6473 }; 6474 6475 /** 6476 * Should be used to set provider of request manager 6477 * 6478 * @method setProvider 6479 * @param {Object} 6480 */ 6481 RequestManager.prototype.setProvider = function (p) { 6482 this.provider = p; 6483 }; 6484 6485 /** 6486 * Should be used to start polling 6487 * 6488 * @method startPolling 6489 * @param {Object} data 6490 * @param {Number} pollId 6491 * @param {Function} callback 6492 * @param {Function} uninstall 6493 * 6494 * @todo cleanup number of params 6495 */ 6496 RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { 6497 this.polls[pollId] = { data: data, id: pollId, callback: callback, uninstall: uninstall }; 6498 6499 6500 // start polling 6501 if (!this.timeout) { 6502 this.poll(); 6503 } 6504 }; 6505 6506 /** 6507 * Should be used to stop polling for filter with given id 6508 * 6509 * @method stopPolling 6510 * @param {Number} pollId 6511 */ 6512 RequestManager.prototype.stopPolling = function (pollId) { 6513 delete this.polls[pollId]; 6514 6515 // stop polling 6516 if (Object.keys(this.polls).length === 0 && this.timeout) { 6517 clearTimeout(this.timeout); 6518 this.timeout = null; 6519 } 6520 }; 6521 6522 /** 6523 * Should be called to reset the polling mechanism of the request manager 6524 * 6525 * @method reset 6526 */ 6527 RequestManager.prototype.reset = function (keepIsSyncing) { 6528 /*jshint maxcomplexity:5 */ 6529 6530 for (var key in this.polls) { 6531 // remove all polls, except sync polls, 6532 // they need to be removed manually by calling syncing.stopWatching() 6533 if(!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6534 this.polls[key].uninstall(); 6535 delete this.polls[key]; 6536 } 6537 } 6538 6539 // stop polling 6540 if(Object.keys(this.polls).length === 0 && this.timeout) { 6541 clearTimeout(this.timeout); 6542 this.timeout = null; 6543 } 6544 }; 6545 6546 /** 6547 * Should be called to poll for changes on filter with given id 6548 * 6549 * @method poll 6550 */ 6551 RequestManager.prototype.poll = function () { 6552 /*jshint maxcomplexity: 6 */ 6553 this.timeout = setTimeout(this.poll.bind(this), c.XCB_POLLING_TIMEOUT); 6554 6555 if (Object.keys(this.polls).length === 0) { 6556 return; 6557 } 6558 6559 if (!this.provider) { 6560 console.error(errors.InvalidProvider()); 6561 return; 6562 } 6563 6564 var pollsData = []; 6565 var pollsIds = []; 6566 for (var key in this.polls) { 6567 pollsData.push(this.polls[key].data); 6568 pollsIds.push(key); 6569 } 6570 6571 if (pollsData.length === 0) { 6572 return; 6573 } 6574 6575 var payload = Jsonrpc.toBatchPayload(pollsData); 6576 6577 // map the request id to they poll id 6578 var pollsIdMap = {}; 6579 payload.forEach(function (load, index) { 6580 pollsIdMap[load.id] = pollsIds[index]; 6581 }); 6582 6583 6584 var self = this; 6585 this.provider.sendAsync(payload, function (error, results) { 6586 6587 6588 // TODO: console log? 6589 if (error) { 6590 return; 6591 } 6592 6593 if (!utils.isArray(results)) { 6594 throw errors.InvalidResponse(results); 6595 } 6596 results.map(function (result) { 6597 var id = pollsIdMap[result.id]; 6598 6599 // make sure the filter is still installed after arrival of the request 6600 if (self.polls[id]) { 6601 result.callback = self.polls[id].callback; 6602 return result; 6603 } else 6604 return false; 6605 }).filter(function (result) { 6606 return !!result; 6607 }).filter(function (result) { 6608 var valid = Jsonrpc.isValidResponse(result); 6609 if (!valid) { 6610 result.callback(errors.InvalidResponse(result)); 6611 } 6612 return valid; 6613 }).forEach(function (result) { 6614 result.callback(null, result.result); 6615 }); 6616 }); 6617 }; 6618 6619 module.exports = RequestManager; 6620 6621 6622 }, { "../utils/config": 18, "../utils/utils": 20, "./errors": 26, "./jsonrpc": 35 }], 47: [function (require, module, exports) { 6623 6624 6625 var Settings = function () { 6626 this.defaultBlock = 'latest'; 6627 this.defaultAccount = undefined; 6628 }; 6629 6630 module.exports = Settings; 6631 6632 6633 }, {}], 48: [function (require, module, exports) { 6634 /* 6635 This file is part of web3.js. 6636 6637 web3.js is free software: you can redistribute it and/or modify 6638 it under the terms of the GNU Lesser General Public License as published by 6639 the Free Software Foundation, either version 3 of the License, or 6640 (at your option) any later version. 6641 6642 web3.js is distributed in the hope that it will be useful, 6643 but WITHOUT ANY WARRANTY; without even the implied warranty of 6644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6645 GNU Lesser General Public License for more details. 6646 6647 You should have received a copy of the GNU Lesser General Public License 6648 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6649 */ 6650 /** @file syncing.js 6651 * @authors: 6652 * Fabian Vogelsteller <fabian@ethdev.com> 6653 * @date 2015 6654 */ 6655 6656 var formatters = require('./formatters'); 6657 var utils = require('../utils/utils'); 6658 6659 var count = 1; 6660 6661 /** 6662 Adds the callback and sets up the methods, to iterate over the results. 6663 6664 @method pollSyncing 6665 @param {Object} self 6666 */ 6667 var pollSyncing = function (self) { 6668 6669 var onMessage = function (error, sync) { 6670 if (error) { 6671 return self.callbacks.forEach(function (callback) { 6672 callback(error); 6673 }); 6674 } 6675 6676 if (utils.isObject(sync) && sync.startingBlock) 6677 sync = formatters.outputSyncingFormatter(sync); 6678 6679 self.callbacks.forEach(function (callback) { 6680 if (self.lastSyncState !== sync) { 6681 6682 // call the callback with true first so the app can stop anything, before receiving the sync data 6683 if (!self.lastSyncState && utils.isObject(sync)) 6684 callback(null, true); 6685 6686 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6687 setTimeout(function () { 6688 callback(null, sync); 6689 }, 0); 6690 6691 self.lastSyncState = sync; 6692 } 6693 }); 6694 }; 6695 6696 self.requestManager.startPolling({ 6697 method: 'xcb_syncing', 6698 params: [], 6699 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6700 6701 }; 6702 6703 var IsSyncing = function (requestManager, callback) { 6704 this.requestManager = requestManager; 6705 this.pollId = 'syncPoll_' + count++; 6706 this.callbacks = []; 6707 this.addCallback(callback); 6708 this.lastSyncState = false; 6709 pollSyncing(this); 6710 6711 return this; 6712 }; 6713 6714 IsSyncing.prototype.addCallback = function (callback) { 6715 if (callback) 6716 this.callbacks.push(callback); 6717 return this; 6718 }; 6719 6720 IsSyncing.prototype.stopWatching = function () { 6721 this.requestManager.stopPolling(this.pollId); 6722 this.callbacks = []; 6723 }; 6724 6725 module.exports = IsSyncing; 6726 6727 6728 }, { "../utils/utils": 20, "./formatters": 30 }], 49: [function (require, module, exports) { 6729 /* 6730 This file is part of web3.js. 6731 6732 web3.js is free software: you can redistribute it and/or modify 6733 it under the terms of the GNU Lesser General Public License as published by 6734 the Free Software Foundation, either version 3 of the License, or 6735 (at your option) any later version. 6736 6737 web3.js is distributed in the hope that it will be useful, 6738 but WITHOUT ANY WARRANTY; without even the implied warranty of 6739 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6740 GNU Lesser General Public License for more details. 6741 6742 You should have received a copy of the GNU Lesser General Public License 6743 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6744 */ 6745 /** 6746 * @file transfer.js 6747 * @author Marek Kotewicz <marek@ethdev.com> 6748 * @date 2015 6749 */ 6750 6751 var Iban = require('./iban'); 6752 var exchangeAbi = require('../contracts/SmartExchange.json'); 6753 6754 /** 6755 * Should be used to make Iban transfer 6756 * 6757 * @method transfer 6758 * @param {String} from 6759 * @param {String} to iban 6760 * @param {Value} value to be tranfered 6761 * @param {Function} callback, callback 6762 */ 6763 var transfer = function (xcb, from, to, value, callback) { 6764 var iban = new Iban(to); 6765 if (!iban.isValid()) { 6766 throw new Error('invalid iban address'); 6767 } 6768 6769 if (iban.isDirect()) { 6770 return transferToAddress(xcb, from, iban.address(), value, callback); 6771 } 6772 6773 if (!callback) { 6774 var address = xcb.icapNamereg().addr(iban.institution()); 6775 return deposit(xcb, from, address, value, iban.client()); 6776 } 6777 6778 xcb.icapNamereg().addr(iban.institution(), function (err, address) { 6779 return deposit(xcb, from, address, value, iban.client(), callback); 6780 }); 6781 6782 }; 6783 6784 /** 6785 * Should be used to transfer funds to certain address 6786 * 6787 * @method transferToAddress 6788 * @param {String} from 6789 * @param {String} to 6790 * @param {Value} value to be tranfered 6791 * @param {Function} callback, callback 6792 */ 6793 var transferToAddress = function (xcb, from, to, value, callback) { 6794 return xcb.sendTransaction({ 6795 address: to, 6796 from: from, 6797 value: value 6798 }, callback); 6799 }; 6800 6801 /** 6802 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6803 * 6804 * @method deposit 6805 * @param {String} from 6806 * @param {String} to 6807 * @param {Value} value to be transferred 6808 * @param {String} client unique identifier 6809 * @param {Function} callback, callback 6810 */ 6811 var deposit = function (xcb, from, to, value, client, callback) { 6812 var abi = exchangeAbi; 6813 return xcb.contract(abi).at(to).deposit(client, { 6814 from: from, 6815 value: value 6816 }, callback); 6817 }; 6818 6819 module.exports = transfer; 6820 6821 6822 }, { "../contracts/SmartExchange.json": 3, "./iban": 33 }], 50: [function (require, module, exports) { 6823 6824 }, {}], 51: [function (require, module, exports) { 6825 ; (function (root, factory, undef) { 6826 if (typeof exports === "object") { 6827 // CommonJS 6828 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6829 } 6830 else if (typeof define === "function" && define.amd) { 6831 // AMD 6832 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6833 } 6834 else { 6835 // Global (browser) 6836 factory(root.CryptoJS); 6837 } 6838 }(this, function (CryptoJS) { 6839 6840 (function () { 6841 // Shortcuts 6842 var C = CryptoJS; 6843 var C_lib = C.lib; 6844 var BlockCipher = C_lib.BlockCipher; 6845 var C_algo = C.algo; 6846 6847 // Lookup tables 6848 var SBOX = []; 6849 var INV_SBOX = []; 6850 var SUB_MIX_0 = []; 6851 var SUB_MIX_1 = []; 6852 var SUB_MIX_2 = []; 6853 var SUB_MIX_3 = []; 6854 var INV_SUB_MIX_0 = []; 6855 var INV_SUB_MIX_1 = []; 6856 var INV_SUB_MIX_2 = []; 6857 var INV_SUB_MIX_3 = []; 6858 6859 // Compute lookup tables 6860 (function () { 6861 // Compute double table 6862 var d = []; 6863 for (var i = 0; i < 256; i++) { 6864 if (i < 128) { 6865 d[i] = i << 1; 6866 } else { 6867 d[i] = (i << 1) ^ 0x11b; 6868 } 6869 } 6870 6871 // Walk GF(2^8) 6872 var x = 0; 6873 var xi = 0; 6874 for (var i = 0; i < 256; i++) { 6875 // Compute sbox 6876 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6877 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6878 SBOX[x] = sx; 6879 INV_SBOX[sx] = x; 6880 6881 // Compute multiplication 6882 var x2 = d[x]; 6883 var x4 = d[x2]; 6884 var x8 = d[x4]; 6885 6886 // Compute sub bytes, mix columns tables 6887 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6888 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6889 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6890 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6891 SUB_MIX_3[x] = t; 6892 6893 // Compute inv sub bytes, inv mix columns tables 6894 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6895 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6896 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6897 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6898 INV_SUB_MIX_3[sx] = t; 6899 6900 // Compute next counter 6901 if (!x) { 6902 x = xi = 1; 6903 } else { 6904 x = x2 ^ d[d[d[x8 ^ x2]]]; 6905 xi ^= d[d[xi]]; 6906 } 6907 } 6908 }()); 6909 6910 // Precomputed Rcon lookup 6911 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6912 6913 /** 6914 * AES block cipher algorithm. 6915 */ 6916 var AES = C_algo.AES = BlockCipher.extend({ 6917 _doReset: function () { 6918 // Skip reset of nRounds has been set before and key did not change 6919 if (this._nRounds && this._keyPriorReset === this._key) { 6920 return; 6921 } 6922 6923 // Shortcuts 6924 var key = this._keyPriorReset = this._key; 6925 var keyWords = key.words; 6926 var keySize = key.sigBytes / 4; 6927 6928 // Compute number of rounds 6929 var nRounds = this._nRounds = keySize + 6; 6930 6931 // Compute number of key schedule rows 6932 var ksRows = (nRounds + 1) * 4; 6933 6934 // Compute key schedule 6935 var keySchedule = this._keySchedule = []; 6936 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 6937 if (ksRow < keySize) { 6938 keySchedule[ksRow] = keyWords[ksRow]; 6939 } else { 6940 var t = keySchedule[ksRow - 1]; 6941 6942 if (!(ksRow % keySize)) { 6943 // Rot word 6944 t = (t << 8) | (t >>> 24); 6945 6946 // Sub word 6947 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6948 6949 // Mix Rcon 6950 t ^= RCON[(ksRow / keySize) | 0] << 24; 6951 } else if (keySize > 6 && ksRow % keySize == 4) { 6952 // Sub word 6953 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 6954 } 6955 6956 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 6957 } 6958 } 6959 6960 // Compute inv key schedule 6961 var invKeySchedule = this._invKeySchedule = []; 6962 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 6963 var ksRow = ksRows - invKsRow; 6964 6965 if (invKsRow % 4) { 6966 var t = keySchedule[ksRow]; 6967 } else { 6968 var t = keySchedule[ksRow - 4]; 6969 } 6970 6971 if (invKsRow < 4 || ksRow <= 4) { 6972 invKeySchedule[invKsRow] = t; 6973 } else { 6974 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 6975 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 6976 } 6977 } 6978 }, 6979 6980 encryptBlock: function (M, offset) { 6981 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 6982 }, 6983 6984 decryptBlock: function (M, offset) { 6985 // Swap 2nd and 4th rows 6986 var t = M[offset + 1]; 6987 M[offset + 1] = M[offset + 3]; 6988 M[offset + 3] = t; 6989 6990 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 6991 6992 // Inv swap 2nd and 4th rows 6993 var t = M[offset + 1]; 6994 M[offset + 1] = M[offset + 3]; 6995 M[offset + 3] = t; 6996 }, 6997 6998 _doCryptBlock: function (M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 6999 // Shortcut 7000 var nRounds = this._nRounds; 7001 7002 // Get input, add round key 7003 var s0 = M[offset] ^ keySchedule[0]; 7004 var s1 = M[offset + 1] ^ keySchedule[1]; 7005 var s2 = M[offset + 2] ^ keySchedule[2]; 7006 var s3 = M[offset + 3] ^ keySchedule[3]; 7007 7008 // Key schedule row counter 7009 var ksRow = 4; 7010 7011 // Rounds 7012 for (var round = 1; round < nRounds; round++) { 7013 // Shift rows, sub bytes, mix columns, add round key 7014 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++]; 7015 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++]; 7016 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++]; 7017 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++]; 7018 7019 // Update state 7020 s0 = t0; 7021 s1 = t1; 7022 s2 = t2; 7023 s3 = t3; 7024 } 7025 7026 // Shift rows, sub bytes, add round key 7027 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 7028 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 7029 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 7030 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 7031 7032 // Set output 7033 M[offset] = t0; 7034 M[offset + 1] = t1; 7035 M[offset + 2] = t2; 7036 M[offset + 3] = t3; 7037 }, 7038 7039 keySize: 256 / 32 7040 }); 7041 7042 /** 7043 * Shortcut functions to the cipher's object interface. 7044 * 7045 * @example 7046 * 7047 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7048 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7049 */ 7050 C.AES = BlockCipher._createHelper(AES); 7051 }()); 7052 7053 7054 return CryptoJS.AES; 7055 7056 })); 7057 }, { "./cipher-core": 52, "./core": 53, "./enc-base64": 54, "./evpkdf": 56, "./md5": 61 }], 52: [function (require, module, exports) { 7058 ; (function (root, factory, undef) { 7059 if (typeof exports === "object") { 7060 // CommonJS 7061 module.exports = exports = factory(require("./core"), require("./evpkdf")); 7062 } 7063 else if (typeof define === "function" && define.amd) { 7064 // AMD 7065 define(["./core", "./evpkdf"], factory); 7066 } 7067 else { 7068 // Global (browser) 7069 factory(root.CryptoJS); 7070 } 7071 }(this, function (CryptoJS) { 7072 7073 /** 7074 * Cipher core components. 7075 */ 7076 CryptoJS.lib.Cipher || (function (undefined) { 7077 // Shortcuts 7078 var C = CryptoJS; 7079 var C_lib = C.lib; 7080 var Base = C_lib.Base; 7081 var WordArray = C_lib.WordArray; 7082 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7083 var C_enc = C.enc; 7084 var Utf8 = C_enc.Utf8; 7085 var Base64 = C_enc.Base64; 7086 var C_algo = C.algo; 7087 var EvpKDF = C_algo.EvpKDF; 7088 7089 /** 7090 * Abstract base cipher template. 7091 * 7092 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7093 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7094 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7095 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7096 */ 7097 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7098 /** 7099 * Configuration options. 7100 * 7101 * @property {WordArray} iv The IV to use for this operation. 7102 */ 7103 cfg: Base.extend(), 7104 7105 /** 7106 * Creates this cipher in encryption mode. 7107 * 7108 * @param {WordArray} key The key. 7109 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7110 * 7111 * @return {Cipher} A cipher instance. 7112 * 7113 * @static 7114 * 7115 * @example 7116 * 7117 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7118 */ 7119 createEncryptor: function (key, cfg) { 7120 return this.create(this._ENC_XFORM_MODE, key, cfg); 7121 }, 7122 7123 /** 7124 * Creates this cipher in decryption mode. 7125 * 7126 * @param {WordArray} key The key. 7127 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7128 * 7129 * @return {Cipher} A cipher instance. 7130 * 7131 * @static 7132 * 7133 * @example 7134 * 7135 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7136 */ 7137 createDecryptor: function (key, cfg) { 7138 return this.create(this._DEC_XFORM_MODE, key, cfg); 7139 }, 7140 7141 /** 7142 * Initializes a newly created cipher. 7143 * 7144 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7145 * @param {WordArray} key The key. 7146 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7147 * 7148 * @example 7149 * 7150 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7151 */ 7152 init: function (xformMode, key, cfg) { 7153 // Apply config defaults 7154 this.cfg = this.cfg.extend(cfg); 7155 7156 // Store transform mode and key 7157 this._xformMode = xformMode; 7158 this._key = key; 7159 7160 // Set initial values 7161 this.reset(); 7162 }, 7163 7164 /** 7165 * Resets this cipher to its initial state. 7166 * 7167 * @example 7168 * 7169 * cipher.reset(); 7170 */ 7171 reset: function () { 7172 // Reset data buffer 7173 BufferedBlockAlgorithm.reset.call(this); 7174 7175 // Perform concrete-cipher logic 7176 this._doReset(); 7177 }, 7178 7179 /** 7180 * Adds data to be encrypted or decrypted. 7181 * 7182 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7183 * 7184 * @return {WordArray} The data after processing. 7185 * 7186 * @example 7187 * 7188 * var encrypted = cipher.process('data'); 7189 * var encrypted = cipher.process(wordArray); 7190 */ 7191 process: function (dataUpdate) { 7192 // Append 7193 this._append(dataUpdate); 7194 7195 // Process available blocks 7196 return this._process(); 7197 }, 7198 7199 /** 7200 * Finalizes the encryption or decryption process. 7201 * Note that the finalize operation is effectively a destructive, read-once operation. 7202 * 7203 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7204 * 7205 * @return {WordArray} The data after final processing. 7206 * 7207 * @example 7208 * 7209 * var encrypted = cipher.finalize(); 7210 * var encrypted = cipher.finalize('data'); 7211 * var encrypted = cipher.finalize(wordArray); 7212 */ 7213 finalize: function (dataUpdate) { 7214 // Final data update 7215 if (dataUpdate) { 7216 this._append(dataUpdate); 7217 } 7218 7219 // Perform concrete-cipher logic 7220 var finalProcessedData = this._doFinalize(); 7221 7222 return finalProcessedData; 7223 }, 7224 7225 keySize: 128 / 32, 7226 7227 ivSize: 128 / 32, 7228 7229 _ENC_XFORM_MODE: 1, 7230 7231 _DEC_XFORM_MODE: 2, 7232 7233 /** 7234 * Creates shortcut functions to a cipher's object interface. 7235 * 7236 * @param {Cipher} cipher The cipher to create a helper for. 7237 * 7238 * @return {Object} An object with encrypt and decrypt shortcut functions. 7239 * 7240 * @static 7241 * 7242 * @example 7243 * 7244 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7245 */ 7246 _createHelper: (function () { 7247 function selectCipherStrategy(key) { 7248 if (typeof key == 'string') { 7249 return PasswordBasedCipher; 7250 } else { 7251 return SerializableCipher; 7252 } 7253 } 7254 7255 return function (cipher) { 7256 return { 7257 encrypt: function (message, key, cfg) { 7258 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7259 }, 7260 7261 decrypt: function (ciphertext, key, cfg) { 7262 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7263 } 7264 }; 7265 }; 7266 }()) 7267 }); 7268 7269 /** 7270 * Abstract base stream cipher template. 7271 * 7272 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7273 */ 7274 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7275 _doFinalize: function () { 7276 // Process partial blocks 7277 var finalProcessedBlocks = this._process(!!'flush'); 7278 7279 return finalProcessedBlocks; 7280 }, 7281 7282 blockSize: 1 7283 }); 7284 7285 /** 7286 * Mode namespace. 7287 */ 7288 var C_mode = C.mode = {}; 7289 7290 /** 7291 * Abstract base block cipher mode template. 7292 */ 7293 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7294 /** 7295 * Creates this mode for encryption. 7296 * 7297 * @param {Cipher} cipher A block cipher instance. 7298 * @param {Array} iv The IV words. 7299 * 7300 * @static 7301 * 7302 * @example 7303 * 7304 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7305 */ 7306 createEncryptor: function (cipher, iv) { 7307 return this.Encryptor.create(cipher, iv); 7308 }, 7309 7310 /** 7311 * Creates this mode for decryption. 7312 * 7313 * @param {Cipher} cipher A block cipher instance. 7314 * @param {Array} iv The IV words. 7315 * 7316 * @static 7317 * 7318 * @example 7319 * 7320 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7321 */ 7322 createDecryptor: function (cipher, iv) { 7323 return this.Decryptor.create(cipher, iv); 7324 }, 7325 7326 /** 7327 * Initializes a newly created mode. 7328 * 7329 * @param {Cipher} cipher A block cipher instance. 7330 * @param {Array} iv The IV words. 7331 * 7332 * @example 7333 * 7334 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7335 */ 7336 init: function (cipher, iv) { 7337 this._cipher = cipher; 7338 this._iv = iv; 7339 } 7340 }); 7341 7342 /** 7343 * Cipher Block Chaining mode. 7344 */ 7345 var CBC = C_mode.CBC = (function () { 7346 /** 7347 * Abstract base CBC mode. 7348 */ 7349 var CBC = BlockCipherMode.extend(); 7350 7351 /** 7352 * CBC encryptor. 7353 */ 7354 CBC.Encryptor = CBC.extend({ 7355 /** 7356 * Processes the data block at offset. 7357 * 7358 * @param {Array} words The data words to operate on. 7359 * @param {number} offset The offset where the block starts. 7360 * 7361 * @example 7362 * 7363 * mode.processBlock(data.words, offset); 7364 */ 7365 processBlock: function (words, offset) { 7366 // Shortcuts 7367 var cipher = this._cipher; 7368 var blockSize = cipher.blockSize; 7369 7370 // XOR and encrypt 7371 xorBlock.call(this, words, offset, blockSize); 7372 cipher.encryptBlock(words, offset); 7373 7374 // Remember this block to use with next block 7375 this._prevBlock = words.slice(offset, offset + blockSize); 7376 } 7377 }); 7378 7379 /** 7380 * CBC decryptor. 7381 */ 7382 CBC.Decryptor = CBC.extend({ 7383 /** 7384 * Processes the data block at offset. 7385 * 7386 * @param {Array} words The data words to operate on. 7387 * @param {number} offset The offset where the block starts. 7388 * 7389 * @example 7390 * 7391 * mode.processBlock(data.words, offset); 7392 */ 7393 processBlock: function (words, offset) { 7394 // Shortcuts 7395 var cipher = this._cipher; 7396 var blockSize = cipher.blockSize; 7397 7398 // Remember this block to use with next block 7399 var thisBlock = words.slice(offset, offset + blockSize); 7400 7401 // Decrypt and XOR 7402 cipher.decryptBlock(words, offset); 7403 xorBlock.call(this, words, offset, blockSize); 7404 7405 // This block becomes the previous block 7406 this._prevBlock = thisBlock; 7407 } 7408 }); 7409 7410 function xorBlock(words, offset, blockSize) { 7411 // Shortcut 7412 var iv = this._iv; 7413 7414 // Choose mixing block 7415 if (iv) { 7416 var block = iv; 7417 7418 // Remove IV for subsequent blocks 7419 this._iv = undefined; 7420 } else { 7421 var block = this._prevBlock; 7422 } 7423 7424 // XOR blocks 7425 for (var i = 0; i < blockSize; i++) { 7426 words[offset + i] ^= block[i]; 7427 } 7428 } 7429 7430 return CBC; 7431 }()); 7432 7433 /** 7434 * Padding namespace. 7435 */ 7436 var C_pad = C.pad = {}; 7437 7438 /** 7439 * PKCS #5/7 padding strategy. 7440 */ 7441 var Pkcs7 = C_pad.Pkcs7 = { 7442 /** 7443 * Pads data using the algorithm defined in PKCS #5/7. 7444 * 7445 * @param {WordArray} data The data to pad. 7446 * @param {number} blockSize The multiple that the data should be padded to. 7447 * 7448 * @static 7449 * 7450 * @example 7451 * 7452 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7453 */ 7454 pad: function (data, blockSize) { 7455 // Shortcut 7456 var blockSizeBytes = blockSize * 4; 7457 7458 // Count padding bytes 7459 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7460 7461 // Create padding word 7462 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7463 7464 // Create padding 7465 var paddingWords = []; 7466 for (var i = 0; i < nPaddingBytes; i += 4) { 7467 paddingWords.push(paddingWord); 7468 } 7469 var padding = WordArray.create(paddingWords, nPaddingBytes); 7470 7471 // Add padding 7472 data.concat(padding); 7473 }, 7474 7475 /** 7476 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7477 * 7478 * @param {WordArray} data The data to unpad. 7479 * 7480 * @static 7481 * 7482 * @example 7483 * 7484 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7485 */ 7486 unpad: function (data) { 7487 // Get number of padding bytes from last byte 7488 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7489 7490 // Remove padding 7491 data.sigBytes -= nPaddingBytes; 7492 } 7493 }; 7494 7495 /** 7496 * Abstract base block cipher template. 7497 * 7498 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7499 */ 7500 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7501 /** 7502 * Configuration options. 7503 * 7504 * @property {Mode} mode The block mode to use. Default: CBC 7505 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7506 */ 7507 cfg: Cipher.cfg.extend({ 7508 mode: CBC, 7509 padding: Pkcs7 7510 }), 7511 7512 reset: function () { 7513 // Reset cipher 7514 Cipher.reset.call(this); 7515 7516 // Shortcuts 7517 var cfg = this.cfg; 7518 var iv = cfg.iv; 7519 var mode = cfg.mode; 7520 7521 // Reset block mode 7522 if (this._xformMode == this._ENC_XFORM_MODE) { 7523 var modeCreator = mode.createEncryptor; 7524 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7525 var modeCreator = mode.createDecryptor; 7526 // Keep at least one block in the buffer for unpadding 7527 this._minBufferSize = 1; 7528 } 7529 7530 if (this._mode && this._mode.__creator == modeCreator) { 7531 this._mode.init(this, iv && iv.words); 7532 } else { 7533 this._mode = modeCreator.call(mode, this, iv && iv.words); 7534 this._mode.__creator = modeCreator; 7535 } 7536 }, 7537 7538 _doProcessBlock: function (words, offset) { 7539 this._mode.processBlock(words, offset); 7540 }, 7541 7542 _doFinalize: function () { 7543 // Shortcut 7544 var padding = this.cfg.padding; 7545 7546 // Finalize 7547 if (this._xformMode == this._ENC_XFORM_MODE) { 7548 // Pad data 7549 padding.pad(this._data, this.blockSize); 7550 7551 // Process final blocks 7552 var finalProcessedBlocks = this._process(!!'flush'); 7553 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7554 // Process final blocks 7555 var finalProcessedBlocks = this._process(!!'flush'); 7556 7557 // Unpad data 7558 padding.unpad(finalProcessedBlocks); 7559 } 7560 7561 return finalProcessedBlocks; 7562 }, 7563 7564 blockSize: 128 / 32 7565 }); 7566 7567 /** 7568 * A collection of cipher parameters. 7569 * 7570 * @property {WordArray} ciphertext The raw ciphertext. 7571 * @property {WordArray} key The key to this ciphertext. 7572 * @property {WordArray} iv The IV used in the ciphering operation. 7573 * @property {WordArray} salt The salt used with a key derivation function. 7574 * @property {Cipher} algorithm The cipher algorithm. 7575 * @property {Mode} mode The block mode used in the ciphering operation. 7576 * @property {Padding} padding The padding scheme used in the ciphering operation. 7577 * @property {number} blockSize The block size of the cipher. 7578 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7579 */ 7580 var CipherParams = C_lib.CipherParams = Base.extend({ 7581 /** 7582 * Initializes a newly created cipher params object. 7583 * 7584 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7585 * 7586 * @example 7587 * 7588 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7589 * ciphertext: ciphertextWordArray, 7590 * key: keyWordArray, 7591 * iv: ivWordArray, 7592 * salt: saltWordArray, 7593 * algorithm: CryptoJS.algo.AES, 7594 * mode: CryptoJS.mode.CBC, 7595 * padding: CryptoJS.pad.PKCS7, 7596 * blockSize: 4, 7597 * formatter: CryptoJS.format.OpenSSL 7598 * }); 7599 */ 7600 init: function (cipherParams) { 7601 this.mixIn(cipherParams); 7602 }, 7603 7604 /** 7605 * Converts this cipher params object to a string. 7606 * 7607 * @param {Format} formatter (Optional) The formatting strategy to use. 7608 * 7609 * @return {string} The stringified cipher params. 7610 * 7611 * @throws Error If neither the formatter nor the default formatter is set. 7612 * 7613 * @example 7614 * 7615 * var string = cipherParams + ''; 7616 * var string = cipherParams.toString(); 7617 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7618 */ 7619 toString: function (formatter) { 7620 return (formatter || this.formatter).stringify(this); 7621 } 7622 }); 7623 7624 /** 7625 * Format namespace. 7626 */ 7627 var C_format = C.format = {}; 7628 7629 /** 7630 * OpenSSL formatting strategy. 7631 */ 7632 var OpenSSLFormatter = C_format.OpenSSL = { 7633 /** 7634 * Converts a cipher params object to an OpenSSL-compatible string. 7635 * 7636 * @param {CipherParams} cipherParams The cipher params object. 7637 * 7638 * @return {string} The OpenSSL-compatible string. 7639 * 7640 * @static 7641 * 7642 * @example 7643 * 7644 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7645 */ 7646 stringify: function (cipherParams) { 7647 // Shortcuts 7648 var ciphertext = cipherParams.ciphertext; 7649 var salt = cipherParams.salt; 7650 7651 // Format 7652 if (salt) { 7653 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7654 } else { 7655 var wordArray = ciphertext; 7656 } 7657 7658 return wordArray.toString(Base64); 7659 }, 7660 7661 /** 7662 * Converts an OpenSSL-compatible string to a cipher params object. 7663 * 7664 * @param {string} openSSLStr The OpenSSL-compatible string. 7665 * 7666 * @return {CipherParams} The cipher params object. 7667 * 7668 * @static 7669 * 7670 * @example 7671 * 7672 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7673 */ 7674 parse: function (openSSLStr) { 7675 // Parse base64 7676 var ciphertext = Base64.parse(openSSLStr); 7677 7678 // Shortcut 7679 var ciphertextWords = ciphertext.words; 7680 7681 // Test for salt 7682 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7683 // Extract salt 7684 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7685 7686 // Remove salt from ciphertext 7687 ciphertextWords.splice(0, 4); 7688 ciphertext.sigBytes -= 16; 7689 } 7690 7691 return CipherParams.create({ ciphertext: ciphertext, salt: salt }); 7692 } 7693 }; 7694 7695 /** 7696 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7697 */ 7698 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7699 /** 7700 * Configuration options. 7701 * 7702 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7703 */ 7704 cfg: Base.extend({ 7705 format: OpenSSLFormatter 7706 }), 7707 7708 /** 7709 * Encrypts a message. 7710 * 7711 * @param {Cipher} cipher The cipher algorithm to use. 7712 * @param {WordArray|string} message The message to encrypt. 7713 * @param {WordArray} key The key. 7714 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7715 * 7716 * @return {CipherParams} A cipher params object. 7717 * 7718 * @static 7719 * 7720 * @example 7721 * 7722 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7723 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7724 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7725 */ 7726 encrypt: function (cipher, message, key, cfg) { 7727 // Apply config defaults 7728 cfg = this.cfg.extend(cfg); 7729 7730 // Encrypt 7731 var encryptor = cipher.createEncryptor(key, cfg); 7732 var ciphertext = encryptor.finalize(message); 7733 7734 // Shortcut 7735 var cipherCfg = encryptor.cfg; 7736 7737 // Create and return serializable cipher params 7738 return CipherParams.create({ 7739 ciphertext: ciphertext, 7740 key: key, 7741 iv: cipherCfg.iv, 7742 algorithm: cipher, 7743 mode: cipherCfg.mode, 7744 padding: cipherCfg.padding, 7745 blockSize: cipher.blockSize, 7746 formatter: cfg.format 7747 }); 7748 }, 7749 7750 /** 7751 * Decrypts serialized ciphertext. 7752 * 7753 * @param {Cipher} cipher The cipher algorithm to use. 7754 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7755 * @param {WordArray} key The key. 7756 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7757 * 7758 * @return {WordArray} The plaintext. 7759 * 7760 * @static 7761 * 7762 * @example 7763 * 7764 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7765 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7766 */ 7767 decrypt: function (cipher, ciphertext, key, cfg) { 7768 // Apply config defaults 7769 cfg = this.cfg.extend(cfg); 7770 7771 // Convert string to CipherParams 7772 ciphertext = this._parse(ciphertext, cfg.format); 7773 7774 // Decrypt 7775 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7776 7777 return plaintext; 7778 }, 7779 7780 /** 7781 * Converts serialized ciphertext to CipherParams, 7782 * else assumed CipherParams already and returns ciphertext unchanged. 7783 * 7784 * @param {CipherParams|string} ciphertext The ciphertext. 7785 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7786 * 7787 * @return {CipherParams} The unserialized ciphertext. 7788 * 7789 * @static 7790 * 7791 * @example 7792 * 7793 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7794 */ 7795 _parse: function (ciphertext, format) { 7796 if (typeof ciphertext == 'string') { 7797 return format.parse(ciphertext, this); 7798 } else { 7799 return ciphertext; 7800 } 7801 } 7802 }); 7803 7804 /** 7805 * Key derivation function namespace. 7806 */ 7807 var C_kdf = C.kdf = {}; 7808 7809 /** 7810 * OpenSSL key derivation function. 7811 */ 7812 var OpenSSLKdf = C_kdf.OpenSSL = { 7813 /** 7814 * Derives a key and IV from a password. 7815 * 7816 * @param {string} password The password to derive from. 7817 * @param {number} keySize The size in words of the key to generate. 7818 * @param {number} ivSize The size in words of the IV to generate. 7819 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7820 * 7821 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7822 * 7823 * @static 7824 * 7825 * @example 7826 * 7827 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7828 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7829 */ 7830 execute: function (password, keySize, ivSize, salt) { 7831 // Generate random salt 7832 if (!salt) { 7833 salt = WordArray.random(64 / 8); 7834 } 7835 7836 // Derive key and IV 7837 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 7838 7839 // Separate key and IV 7840 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7841 key.sigBytes = keySize * 4; 7842 7843 // Return params 7844 return CipherParams.create({ key: key, iv: iv, salt: salt }); 7845 } 7846 }; 7847 7848 /** 7849 * A serializable cipher wrapper that derives the key from a password, 7850 * and returns ciphertext as a serializable cipher params object. 7851 */ 7852 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7853 /** 7854 * Configuration options. 7855 * 7856 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7857 */ 7858 cfg: SerializableCipher.cfg.extend({ 7859 kdf: OpenSSLKdf 7860 }), 7861 7862 /** 7863 * Encrypts a message using a password. 7864 * 7865 * @param {Cipher} cipher The cipher algorithm to use. 7866 * @param {WordArray|string} message The message to encrypt. 7867 * @param {string} password The password. 7868 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7869 * 7870 * @return {CipherParams} A cipher params object. 7871 * 7872 * @static 7873 * 7874 * @example 7875 * 7876 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7877 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7878 */ 7879 encrypt: function (cipher, message, password, cfg) { 7880 // Apply config defaults 7881 cfg = this.cfg.extend(cfg); 7882 7883 // Derive key and other params 7884 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7885 7886 // Add IV to config 7887 cfg.iv = derivedParams.iv; 7888 7889 // Encrypt 7890 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7891 7892 // Mix in derived params 7893 ciphertext.mixIn(derivedParams); 7894 7895 return ciphertext; 7896 }, 7897 7898 /** 7899 * Decrypts serialized ciphertext using a password. 7900 * 7901 * @param {Cipher} cipher The cipher algorithm to use. 7902 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7903 * @param {string} password The password. 7904 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7905 * 7906 * @return {WordArray} The plaintext. 7907 * 7908 * @static 7909 * 7910 * @example 7911 * 7912 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 7913 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 7914 */ 7915 decrypt: function (cipher, ciphertext, password, cfg) { 7916 // Apply config defaults 7917 cfg = this.cfg.extend(cfg); 7918 7919 // Convert string to CipherParams 7920 ciphertext = this._parse(ciphertext, cfg.format); 7921 7922 // Derive key and other params 7923 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 7924 7925 // Add IV to config 7926 cfg.iv = derivedParams.iv; 7927 7928 // Decrypt 7929 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 7930 7931 return plaintext; 7932 } 7933 }); 7934 }()); 7935 7936 7937 })); 7938 }, { "./core": 53, "./evpkdf": 56 }], 53: [function (require, module, exports) { 7939 ; (function (root, factory) { 7940 if (typeof exports === "object") { 7941 // CommonJS 7942 module.exports = exports = factory(); 7943 } 7944 else if (typeof define === "function" && define.amd) { 7945 // AMD 7946 define([], factory); 7947 } 7948 else { 7949 // Global (browser) 7950 root.CryptoJS = factory(); 7951 } 7952 }(this, function () { 7953 7954 /** 7955 * CryptoJS core components. 7956 */ 7957 var CryptoJS = CryptoJS || (function (Math, undefined) { 7958 /* 7959 * Local polyfil of Object.create 7960 */ 7961 var create = Object.create || (function () { 7962 function F() { }; 7963 7964 return function (obj) { 7965 var subtype; 7966 7967 F.prototype = obj; 7968 7969 subtype = new F(); 7970 7971 F.prototype = null; 7972 7973 return subtype; 7974 }; 7975 }()) 7976 7977 /** 7978 * CryptoJS namespace. 7979 */ 7980 var C = {}; 7981 7982 /** 7983 * Library namespace. 7984 */ 7985 var C_lib = C.lib = {}; 7986 7987 /** 7988 * Base object for prototypal inheritance. 7989 */ 7990 var Base = C_lib.Base = (function () { 7991 7992 7993 return { 7994 /** 7995 * Creates a new object that inherits from this object. 7996 * 7997 * @param {Object} overrides Properties to copy into the new object. 7998 * 7999 * @return {Object} The new object. 8000 * 8001 * @static 8002 * 8003 * @example 8004 * 8005 * var MyType = CryptoJS.lib.Base.extend({ 8006 * field: 'value', 8007 * 8008 * method: function () { 8009 * } 8010 * }); 8011 */ 8012 extend: function (overrides) { 8013 // Spawn 8014 var subtype = create(this); 8015 8016 // Augment 8017 if (overrides) { 8018 subtype.mixIn(overrides); 8019 } 8020 8021 // Create default initializer 8022 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 8023 subtype.init = function () { 8024 subtype.$super.init.apply(this, arguments); 8025 }; 8026 } 8027 8028 // Initializer's prototype is the subtype object 8029 subtype.init.prototype = subtype; 8030 8031 // Reference supertype 8032 subtype.$super = this; 8033 8034 return subtype; 8035 }, 8036 8037 /** 8038 * Extends this object and runs the init method. 8039 * Arguments to create() will be passed to init(). 8040 * 8041 * @return {Object} The new object. 8042 * 8043 * @static 8044 * 8045 * @example 8046 * 8047 * var instance = MyType.create(); 8048 */ 8049 create: function () { 8050 var instance = this.extend(); 8051 instance.init.apply(instance, arguments); 8052 8053 return instance; 8054 }, 8055 8056 /** 8057 * Initializes a newly created object. 8058 * Override this method to add some logic when your objects are created. 8059 * 8060 * @example 8061 * 8062 * var MyType = CryptoJS.lib.Base.extend({ 8063 * init: function () { 8064 * // ... 8065 * } 8066 * }); 8067 */ 8068 init: function () { 8069 }, 8070 8071 /** 8072 * Copies properties into this object. 8073 * 8074 * @param {Object} properties The properties to mix in. 8075 * 8076 * @example 8077 * 8078 * MyType.mixIn({ 8079 * field: 'value' 8080 * }); 8081 */ 8082 mixIn: function (properties) { 8083 for (var propertyName in properties) { 8084 if (properties.hasOwnProperty(propertyName)) { 8085 this[propertyName] = properties[propertyName]; 8086 } 8087 } 8088 8089 // IE won't copy toString using the loop above 8090 if (properties.hasOwnProperty('toString')) { 8091 this.toString = properties.toString; 8092 } 8093 }, 8094 8095 /** 8096 * Creates a copy of this object. 8097 * 8098 * @return {Object} The clone. 8099 * 8100 * @example 8101 * 8102 * var clone = instance.clone(); 8103 */ 8104 clone: function () { 8105 return this.init.prototype.extend(this); 8106 } 8107 }; 8108 }()); 8109 8110 /** 8111 * An array of 32-bit words. 8112 * 8113 * @property {Array} words The array of 32-bit words. 8114 * @property {number} sigBytes The number of significant bytes in this word array. 8115 */ 8116 var WordArray = C_lib.WordArray = Base.extend({ 8117 /** 8118 * Initializes a newly created word array. 8119 * 8120 * @param {Array} words (Optional) An array of 32-bit words. 8121 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8122 * 8123 * @example 8124 * 8125 * var wordArray = CryptoJS.lib.WordArray.create(); 8126 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8127 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8128 */ 8129 init: function (words, sigBytes) { 8130 words = this.words = words || []; 8131 8132 if (sigBytes != undefined) { 8133 this.sigBytes = sigBytes; 8134 } else { 8135 this.sigBytes = words.length * 4; 8136 } 8137 }, 8138 8139 /** 8140 * Converts this word array to a string. 8141 * 8142 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8143 * 8144 * @return {string} The stringified word array. 8145 * 8146 * @example 8147 * 8148 * var string = wordArray + ''; 8149 * var string = wordArray.toString(); 8150 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8151 */ 8152 toString: function (encoder) { 8153 return (encoder || Hex).stringify(this); 8154 }, 8155 8156 /** 8157 * Concatenates a word array to this word array. 8158 * 8159 * @param {WordArray} wordArray The word array to append. 8160 * 8161 * @return {WordArray} This word array. 8162 * 8163 * @example 8164 * 8165 * wordArray1.concat(wordArray2); 8166 */ 8167 concat: function (wordArray) { 8168 // Shortcuts 8169 var thisWords = this.words; 8170 var thatWords = wordArray.words; 8171 var thisSigBytes = this.sigBytes; 8172 var thatSigBytes = wordArray.sigBytes; 8173 8174 // Clamp excess bits 8175 this.clamp(); 8176 8177 // Concat 8178 if (thisSigBytes % 4) { 8179 // Copy one byte at a time 8180 for (var i = 0; i < thatSigBytes; i++) { 8181 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8182 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8183 } 8184 } else { 8185 // Copy one word at a time 8186 for (var i = 0; i < thatSigBytes; i += 4) { 8187 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8188 } 8189 } 8190 this.sigBytes += thatSigBytes; 8191 8192 // Chainable 8193 return this; 8194 }, 8195 8196 /** 8197 * Removes insignificant bits. 8198 * 8199 * @example 8200 * 8201 * wordArray.clamp(); 8202 */ 8203 clamp: function () { 8204 // Shortcuts 8205 var words = this.words; 8206 var sigBytes = this.sigBytes; 8207 8208 // Clamp 8209 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8210 words.length = Math.ceil(sigBytes / 4); 8211 }, 8212 8213 /** 8214 * Creates a copy of this word array. 8215 * 8216 * @return {WordArray} The clone. 8217 * 8218 * @example 8219 * 8220 * var clone = wordArray.clone(); 8221 */ 8222 clone: function () { 8223 var clone = Base.clone.call(this); 8224 clone.words = this.words.slice(0); 8225 8226 return clone; 8227 }, 8228 8229 /** 8230 * Creates a word array filled with random bytes. 8231 * 8232 * @param {number} nBytes The number of random bytes to generate. 8233 * 8234 * @return {WordArray} The random word array. 8235 * 8236 * @static 8237 * 8238 * @example 8239 * 8240 * var wordArray = CryptoJS.lib.WordArray.random(16); 8241 */ 8242 random: function (nBytes) { 8243 var words = []; 8244 8245 var r = (function (m_w) { 8246 var m_w = m_w; 8247 var m_z = 0x3ade68b1; 8248 var mask = 0xffffffff; 8249 8250 return function () { 8251 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8252 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8253 var result = ((m_z << 0x10) + m_w) & mask; 8254 result /= 0x100000000; 8255 result += 0.5; 8256 return result * (Math.random() > .5 ? 1 : -1); 8257 } 8258 }); 8259 8260 for (var i = 0, rcache; i < nBytes; i += 4) { 8261 var _r = r((rcache || Math.random()) * 0x100000000); 8262 8263 rcache = _r() * 0x3ade67b7; 8264 words.push((_r() * 0x100000000) | 0); 8265 } 8266 8267 return new WordArray.init(words, nBytes); 8268 } 8269 }); 8270 8271 /** 8272 * Encoder namespace. 8273 */ 8274 var C_enc = C.enc = {}; 8275 8276 /** 8277 * Hex encoding strategy. 8278 */ 8279 var Hex = C_enc.Hex = { 8280 /** 8281 * Converts a word array to a hex string. 8282 * 8283 * @param {WordArray} wordArray The word array. 8284 * 8285 * @return {string} The hex string. 8286 * 8287 * @static 8288 * 8289 * @example 8290 * 8291 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8292 */ 8293 stringify: function (wordArray) { 8294 // Shortcuts 8295 var words = wordArray.words; 8296 var sigBytes = wordArray.sigBytes; 8297 8298 // Convert 8299 var hexChars = []; 8300 for (var i = 0; i < sigBytes; i++) { 8301 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8302 hexChars.push((bite >>> 4).toString(16)); 8303 hexChars.push((bite & 0x0f).toString(16)); 8304 } 8305 8306 return hexChars.join(''); 8307 }, 8308 8309 /** 8310 * Converts a hex string to a word array. 8311 * 8312 * @param {string} hexStr The hex string. 8313 * 8314 * @return {WordArray} The word array. 8315 * 8316 * @static 8317 * 8318 * @example 8319 * 8320 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8321 */ 8322 parse: function (hexStr) { 8323 // Shortcut 8324 var hexStrLength = hexStr.length; 8325 8326 // Convert 8327 var words = []; 8328 for (var i = 0; i < hexStrLength; i += 2) { 8329 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8330 } 8331 8332 return new WordArray.init(words, hexStrLength / 2); 8333 } 8334 }; 8335 8336 /** 8337 * Latin1 encoding strategy. 8338 */ 8339 var Latin1 = C_enc.Latin1 = { 8340 /** 8341 * Converts a word array to a Latin1 string. 8342 * 8343 * @param {WordArray} wordArray The word array. 8344 * 8345 * @return {string} The Latin1 string. 8346 * 8347 * @static 8348 * 8349 * @example 8350 * 8351 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8352 */ 8353 stringify: function (wordArray) { 8354 // Shortcuts 8355 var words = wordArray.words; 8356 var sigBytes = wordArray.sigBytes; 8357 8358 // Convert 8359 var latin1Chars = []; 8360 for (var i = 0; i < sigBytes; i++) { 8361 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8362 latin1Chars.push(String.fromCharCode(bite)); 8363 } 8364 8365 return latin1Chars.join(''); 8366 }, 8367 8368 /** 8369 * Converts a Latin1 string to a word array. 8370 * 8371 * @param {string} latin1Str The Latin1 string. 8372 * 8373 * @return {WordArray} The word array. 8374 * 8375 * @static 8376 * 8377 * @example 8378 * 8379 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8380 */ 8381 parse: function (latin1Str) { 8382 // Shortcut 8383 var latin1StrLength = latin1Str.length; 8384 8385 // Convert 8386 var words = []; 8387 for (var i = 0; i < latin1StrLength; i++) { 8388 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8389 } 8390 8391 return new WordArray.init(words, latin1StrLength); 8392 } 8393 }; 8394 8395 /** 8396 * UTF-8 encoding strategy. 8397 */ 8398 var Utf8 = C_enc.Utf8 = { 8399 /** 8400 * Converts a word array to a UTF-8 string. 8401 * 8402 * @param {WordArray} wordArray The word array. 8403 * 8404 * @return {string} The UTF-8 string. 8405 * 8406 * @static 8407 * 8408 * @example 8409 * 8410 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8411 */ 8412 stringify: function (wordArray) { 8413 try { 8414 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8415 } catch (e) { 8416 throw new Error('Malformed UTF-8 data'); 8417 } 8418 }, 8419 8420 /** 8421 * Converts a UTF-8 string to a word array. 8422 * 8423 * @param {string} utf8Str The UTF-8 string. 8424 * 8425 * @return {WordArray} The word array. 8426 * 8427 * @static 8428 * 8429 * @example 8430 * 8431 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8432 */ 8433 parse: function (utf8Str) { 8434 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8435 } 8436 }; 8437 8438 /** 8439 * Abstract buffered block algorithm template. 8440 * 8441 * The property blockSize must be implemented in a concrete subtype. 8442 * 8443 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8444 */ 8445 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8446 /** 8447 * Resets this block algorithm's data buffer to its initial state. 8448 * 8449 * @example 8450 * 8451 * bufferedBlockAlgorithm.reset(); 8452 */ 8453 reset: function () { 8454 // Initial values 8455 this._data = new WordArray.init(); 8456 this._nDataBytes = 0; 8457 }, 8458 8459 /** 8460 * Adds new data to this block algorithm's buffer. 8461 * 8462 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8463 * 8464 * @example 8465 * 8466 * bufferedBlockAlgorithm._append('data'); 8467 * bufferedBlockAlgorithm._append(wordArray); 8468 */ 8469 _append: function (data) { 8470 // Convert string to WordArray, else assume WordArray already 8471 if (typeof data == 'string') { 8472 data = Utf8.parse(data); 8473 } 8474 8475 // Append 8476 this._data.concat(data); 8477 this._nDataBytes += data.sigBytes; 8478 }, 8479 8480 /** 8481 * Processes available data blocks. 8482 * 8483 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8484 * 8485 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8486 * 8487 * @return {WordArray} The processed data. 8488 * 8489 * @example 8490 * 8491 * var processedData = bufferedBlockAlgorithm._process(); 8492 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8493 */ 8494 _process: function (doFlush) { 8495 // Shortcuts 8496 var data = this._data; 8497 var dataWords = data.words; 8498 var dataSigBytes = data.sigBytes; 8499 var blockSize = this.blockSize; 8500 var blockSizeBytes = blockSize * 4; 8501 8502 // Count blocks ready 8503 var nBlocksReady = dataSigBytes / blockSizeBytes; 8504 if (doFlush) { 8505 // Round up to include partial blocks 8506 nBlocksReady = Math.ceil(nBlocksReady); 8507 } else { 8508 // Round down to include only full blocks, 8509 // less the number of blocks that must remain in the buffer 8510 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8511 } 8512 8513 // Count words ready 8514 var nWordsReady = nBlocksReady * blockSize; 8515 8516 // Count bytes ready 8517 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8518 8519 // Process blocks 8520 if (nWordsReady) { 8521 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8522 // Perform concrete-algorithm logic 8523 this._doProcessBlock(dataWords, offset); 8524 } 8525 8526 // Remove processed words 8527 var processedWords = dataWords.splice(0, nWordsReady); 8528 data.sigBytes -= nBytesReady; 8529 } 8530 8531 // Return processed words 8532 return new WordArray.init(processedWords, nBytesReady); 8533 }, 8534 8535 /** 8536 * Creates a copy of this object. 8537 * 8538 * @return {Object} The clone. 8539 * 8540 * @example 8541 * 8542 * var clone = bufferedBlockAlgorithm.clone(); 8543 */ 8544 clone: function () { 8545 var clone = Base.clone.call(this); 8546 clone._data = this._data.clone(); 8547 8548 return clone; 8549 }, 8550 8551 _minBufferSize: 0 8552 }); 8553 8554 /** 8555 * Abstract hasher template. 8556 * 8557 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8558 */ 8559 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8560 /** 8561 * Configuration options. 8562 */ 8563 cfg: Base.extend(), 8564 8565 /** 8566 * Initializes a newly created hasher. 8567 * 8568 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8569 * 8570 * @example 8571 * 8572 * var hasher = CryptoJS.algo.SHA256.create(); 8573 */ 8574 init: function (cfg) { 8575 // Apply config defaults 8576 this.cfg = this.cfg.extend(cfg); 8577 8578 // Set initial values 8579 this.reset(); 8580 }, 8581 8582 /** 8583 * Resets this hasher to its initial state. 8584 * 8585 * @example 8586 * 8587 * hasher.reset(); 8588 */ 8589 reset: function () { 8590 // Reset data buffer 8591 BufferedBlockAlgorithm.reset.call(this); 8592 8593 // Perform concrete-hasher logic 8594 this._doReset(); 8595 }, 8596 8597 /** 8598 * Updates this hasher with a message. 8599 * 8600 * @param {WordArray|string} messageUpdate The message to append. 8601 * 8602 * @return {Hasher} This hasher. 8603 * 8604 * @example 8605 * 8606 * hasher.update('message'); 8607 * hasher.update(wordArray); 8608 */ 8609 update: function (messageUpdate) { 8610 // Append 8611 this._append(messageUpdate); 8612 8613 // Update the hash 8614 this._process(); 8615 8616 // Chainable 8617 return this; 8618 }, 8619 8620 /** 8621 * Finalizes the hash computation. 8622 * Note that the finalize operation is effectively a destructive, read-once operation. 8623 * 8624 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8625 * 8626 * @return {WordArray} The hash. 8627 * 8628 * @example 8629 * 8630 * var hash = hasher.finalize(); 8631 * var hash = hasher.finalize('message'); 8632 * var hash = hasher.finalize(wordArray); 8633 */ 8634 finalize: function (messageUpdate) { 8635 // Final message update 8636 if (messageUpdate) { 8637 this._append(messageUpdate); 8638 } 8639 8640 // Perform concrete-hasher logic 8641 var hash = this._doFinalize(); 8642 8643 return hash; 8644 }, 8645 8646 blockSize: 512 / 32, 8647 8648 /** 8649 * Creates a shortcut function to a hasher's object interface. 8650 * 8651 * @param {Hasher} hasher The hasher to create a helper for. 8652 * 8653 * @return {Function} The shortcut function. 8654 * 8655 * @static 8656 * 8657 * @example 8658 * 8659 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8660 */ 8661 _createHelper: function (hasher) { 8662 return function (message, cfg) { 8663 return new hasher.init(cfg).finalize(message); 8664 }; 8665 }, 8666 8667 /** 8668 * Creates a shortcut function to the HMAC's object interface. 8669 * 8670 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8671 * 8672 * @return {Function} The shortcut function. 8673 * 8674 * @static 8675 * 8676 * @example 8677 * 8678 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8679 */ 8680 _createHmacHelper: function (hasher) { 8681 return function (message, key) { 8682 return new C_algo.HMAC.init(hasher, key).finalize(message); 8683 }; 8684 } 8685 }); 8686 8687 /** 8688 * Algorithm namespace. 8689 */ 8690 var C_algo = C.algo = {}; 8691 8692 return C; 8693 }(Math)); 8694 8695 8696 return CryptoJS; 8697 8698 })); 8699 }, {}], 54: [function (require, module, exports) { 8700 ; (function (root, factory) { 8701 if (typeof exports === "object") { 8702 // CommonJS 8703 module.exports = exports = factory(require("./core")); 8704 } 8705 else if (typeof define === "function" && define.amd) { 8706 // AMD 8707 define(["./core"], factory); 8708 } 8709 else { 8710 // Global (browser) 8711 factory(root.CryptoJS); 8712 } 8713 }(this, function (CryptoJS) { 8714 8715 (function () { 8716 // Shortcuts 8717 var C = CryptoJS; 8718 var C_lib = C.lib; 8719 var WordArray = C_lib.WordArray; 8720 var C_enc = C.enc; 8721 8722 /** 8723 * Base64 encoding strategy. 8724 */ 8725 var Base64 = C_enc.Base64 = { 8726 /** 8727 * Converts a word array to a Base64 string. 8728 * 8729 * @param {WordArray} wordArray The word array. 8730 * 8731 * @return {string} The Base64 string. 8732 * 8733 * @static 8734 * 8735 * @example 8736 * 8737 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8738 */ 8739 stringify: function (wordArray) { 8740 // Shortcuts 8741 var words = wordArray.words; 8742 var sigBytes = wordArray.sigBytes; 8743 var map = this._map; 8744 8745 // Clamp excess bits 8746 wordArray.clamp(); 8747 8748 // Convert 8749 var base64Chars = []; 8750 for (var i = 0; i < sigBytes; i += 3) { 8751 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8752 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8753 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8754 8755 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8756 8757 for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8758 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8759 } 8760 } 8761 8762 // Add padding 8763 var paddingChar = map.charAt(64); 8764 if (paddingChar) { 8765 while (base64Chars.length % 4) { 8766 base64Chars.push(paddingChar); 8767 } 8768 } 8769 8770 return base64Chars.join(''); 8771 }, 8772 8773 /** 8774 * Converts a Base64 string to a word array. 8775 * 8776 * @param {string} base64Str The Base64 string. 8777 * 8778 * @return {WordArray} The word array. 8779 * 8780 * @static 8781 * 8782 * @example 8783 * 8784 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8785 */ 8786 parse: function (base64Str) { 8787 // Shortcuts 8788 var base64StrLength = base64Str.length; 8789 var map = this._map; 8790 var reverseMap = this._reverseMap; 8791 8792 if (!reverseMap) { 8793 reverseMap = this._reverseMap = []; 8794 for (var j = 0; j < map.length; j++) { 8795 reverseMap[map.charCodeAt(j)] = j; 8796 } 8797 } 8798 8799 // Ignore padding 8800 var paddingChar = map.charAt(64); 8801 if (paddingChar) { 8802 var paddingIndex = base64Str.indexOf(paddingChar); 8803 if (paddingIndex !== -1) { 8804 base64StrLength = paddingIndex; 8805 } 8806 } 8807 8808 // Convert 8809 return parseLoop(base64Str, base64StrLength, reverseMap); 8810 8811 }, 8812 8813 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8814 }; 8815 8816 function parseLoop(base64Str, base64StrLength, reverseMap) { 8817 var words = []; 8818 var nBytes = 0; 8819 for (var i = 0; i < base64StrLength; i++) { 8820 if (i % 4) { 8821 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8822 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8823 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8824 nBytes++; 8825 } 8826 } 8827 return WordArray.create(words, nBytes); 8828 } 8829 }()); 8830 8831 8832 return CryptoJS.enc.Base64; 8833 8834 })); 8835 }, { "./core": 53 }], 55: [function (require, module, exports) { 8836 ; (function (root, factory) { 8837 if (typeof exports === "object") { 8838 // CommonJS 8839 module.exports = exports = factory(require("./core")); 8840 } 8841 else if (typeof define === "function" && define.amd) { 8842 // AMD 8843 define(["./core"], factory); 8844 } 8845 else { 8846 // Global (browser) 8847 factory(root.CryptoJS); 8848 } 8849 }(this, function (CryptoJS) { 8850 8851 (function () { 8852 // Shortcuts 8853 var C = CryptoJS; 8854 var C_lib = C.lib; 8855 var WordArray = C_lib.WordArray; 8856 var C_enc = C.enc; 8857 8858 /** 8859 * UTF-16 BE encoding strategy. 8860 */ 8861 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8862 /** 8863 * Converts a word array to a UTF-16 BE string. 8864 * 8865 * @param {WordArray} wordArray The word array. 8866 * 8867 * @return {string} The UTF-16 BE string. 8868 * 8869 * @static 8870 * 8871 * @example 8872 * 8873 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8874 */ 8875 stringify: function (wordArray) { 8876 // Shortcuts 8877 var words = wordArray.words; 8878 var sigBytes = wordArray.sigBytes; 8879 8880 // Convert 8881 var utf16Chars = []; 8882 for (var i = 0; i < sigBytes; i += 2) { 8883 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8884 utf16Chars.push(String.fromCharCode(codePoint)); 8885 } 8886 8887 return utf16Chars.join(''); 8888 }, 8889 8890 /** 8891 * Converts a UTF-16 BE string to a word array. 8892 * 8893 * @param {string} utf16Str The UTF-16 BE string. 8894 * 8895 * @return {WordArray} The word array. 8896 * 8897 * @static 8898 * 8899 * @example 8900 * 8901 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8902 */ 8903 parse: function (utf16Str) { 8904 // Shortcut 8905 var utf16StrLength = utf16Str.length; 8906 8907 // Convert 8908 var words = []; 8909 for (var i = 0; i < utf16StrLength; i++) { 8910 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 8911 } 8912 8913 return WordArray.create(words, utf16StrLength * 2); 8914 } 8915 }; 8916 8917 /** 8918 * UTF-16 LE encoding strategy. 8919 */ 8920 C_enc.Utf16LE = { 8921 /** 8922 * Converts a word array to a UTF-16 LE string. 8923 * 8924 * @param {WordArray} wordArray The word array. 8925 * 8926 * @return {string} The UTF-16 LE string. 8927 * 8928 * @static 8929 * 8930 * @example 8931 * 8932 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 8933 */ 8934 stringify: function (wordArray) { 8935 // Shortcuts 8936 var words = wordArray.words; 8937 var sigBytes = wordArray.sigBytes; 8938 8939 // Convert 8940 var utf16Chars = []; 8941 for (var i = 0; i < sigBytes; i += 2) { 8942 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 8943 utf16Chars.push(String.fromCharCode(codePoint)); 8944 } 8945 8946 return utf16Chars.join(''); 8947 }, 8948 8949 /** 8950 * Converts a UTF-16 LE string to a word array. 8951 * 8952 * @param {string} utf16Str The UTF-16 LE string. 8953 * 8954 * @return {WordArray} The word array. 8955 * 8956 * @static 8957 * 8958 * @example 8959 * 8960 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 8961 */ 8962 parse: function (utf16Str) { 8963 // Shortcut 8964 var utf16StrLength = utf16Str.length; 8965 8966 // Convert 8967 var words = []; 8968 for (var i = 0; i < utf16StrLength; i++) { 8969 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 8970 } 8971 8972 return WordArray.create(words, utf16StrLength * 2); 8973 } 8974 }; 8975 8976 function swapEndian(word) { 8977 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 8978 } 8979 }()); 8980 8981 8982 return CryptoJS.enc.Utf16; 8983 8984 })); 8985 }, { "./core": 53 }], 56: [function (require, module, exports) { 8986 ; (function (root, factory, undef) { 8987 if (typeof exports === "object") { 8988 // CommonJS 8989 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 8990 } 8991 else if (typeof define === "function" && define.amd) { 8992 // AMD 8993 define(["./core", "./sha1", "./hmac"], factory); 8994 } 8995 else { 8996 // Global (browser) 8997 factory(root.CryptoJS); 8998 } 8999 }(this, function (CryptoJS) { 9000 9001 (function () { 9002 // Shortcuts 9003 var C = CryptoJS; 9004 var C_lib = C.lib; 9005 var Base = C_lib.Base; 9006 var WordArray = C_lib.WordArray; 9007 var C_algo = C.algo; 9008 var MD5 = C_algo.MD5; 9009 9010 /** 9011 * This key derivation function is meant to conform with EVP_BytesToKey. 9012 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 9013 */ 9014 var EvpKDF = C_algo.EvpKDF = Base.extend({ 9015 /** 9016 * Configuration options. 9017 * 9018 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9019 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 9020 * @property {number} iterations The number of iterations to perform. Default: 1 9021 */ 9022 cfg: Base.extend({ 9023 keySize: 128 / 32, 9024 hasher: MD5, 9025 iterations: 1 9026 }), 9027 9028 /** 9029 * Initializes a newly created key derivation function. 9030 * 9031 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9032 * 9033 * @example 9034 * 9035 * var kdf = CryptoJS.algo.EvpKDF.create(); 9036 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9037 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9038 */ 9039 init: function (cfg) { 9040 this.cfg = this.cfg.extend(cfg); 9041 }, 9042 9043 /** 9044 * Derives a key from a password. 9045 * 9046 * @param {WordArray|string} password The password. 9047 * @param {WordArray|string} salt A salt. 9048 * 9049 * @return {WordArray} The derived key. 9050 * 9051 * @example 9052 * 9053 * var key = kdf.compute(password, salt); 9054 */ 9055 compute: function (password, salt) { 9056 // Shortcut 9057 var cfg = this.cfg; 9058 9059 // Init hasher 9060 var hasher = cfg.hasher.create(); 9061 9062 // Initial values 9063 var derivedKey = WordArray.create(); 9064 9065 // Shortcuts 9066 var derivedKeyWords = derivedKey.words; 9067 var keySize = cfg.keySize; 9068 var iterations = cfg.iterations; 9069 9070 // Generate key 9071 while (derivedKeyWords.length < keySize) { 9072 if (block) { 9073 hasher.update(block); 9074 } 9075 var block = hasher.update(password).finalize(salt); 9076 hasher.reset(); 9077 9078 // Iterations 9079 for (var i = 1; i < iterations; i++) { 9080 block = hasher.finalize(block); 9081 hasher.reset(); 9082 } 9083 9084 derivedKey.concat(block); 9085 } 9086 derivedKey.sigBytes = keySize * 4; 9087 9088 return derivedKey; 9089 } 9090 }); 9091 9092 /** 9093 * Derives a key from a password. 9094 * 9095 * @param {WordArray|string} password The password. 9096 * @param {WordArray|string} salt A salt. 9097 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9098 * 9099 * @return {WordArray} The derived key. 9100 * 9101 * @static 9102 * 9103 * @example 9104 * 9105 * var key = CryptoJS.EvpKDF(password, salt); 9106 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9107 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9108 */ 9109 C.EvpKDF = function (password, salt, cfg) { 9110 return EvpKDF.create(cfg).compute(password, salt); 9111 }; 9112 }()); 9113 9114 9115 return CryptoJS.EvpKDF; 9116 9117 })); 9118 }, { "./core": 53, "./hmac": 58, "./sha1": 77 }], 57: [function (require, module, exports) { 9119 ; (function (root, factory, undef) { 9120 if (typeof exports === "object") { 9121 // CommonJS 9122 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9123 } 9124 else if (typeof define === "function" && define.amd) { 9125 // AMD 9126 define(["./core", "./cipher-core"], factory); 9127 } 9128 else { 9129 // Global (browser) 9130 factory(root.CryptoJS); 9131 } 9132 }(this, function (CryptoJS) { 9133 9134 (function (undefined) { 9135 // Shortcuts 9136 var C = CryptoJS; 9137 var C_lib = C.lib; 9138 var CipherParams = C_lib.CipherParams; 9139 var C_enc = C.enc; 9140 var Hex = C_enc.Hex; 9141 var C_format = C.format; 9142 9143 var HexFormatter = C_format.Hex = { 9144 /** 9145 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9146 * 9147 * @param {CipherParams} cipherParams The cipher params object. 9148 * 9149 * @return {string} The hexadecimally encoded string. 9150 * 9151 * @static 9152 * 9153 * @example 9154 * 9155 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9156 */ 9157 stringify: function (cipherParams) { 9158 return cipherParams.ciphertext.toString(Hex); 9159 }, 9160 9161 /** 9162 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9163 * 9164 * @param {string} input The hexadecimally encoded string. 9165 * 9166 * @return {CipherParams} The cipher params object. 9167 * 9168 * @static 9169 * 9170 * @example 9171 * 9172 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9173 */ 9174 parse: function (input) { 9175 var ciphertext = Hex.parse(input); 9176 return CipherParams.create({ ciphertext: ciphertext }); 9177 } 9178 }; 9179 }()); 9180 9181 9182 return CryptoJS.format.Hex; 9183 9184 })); 9185 }, { "./cipher-core": 52, "./core": 53 }], 58: [function (require, module, exports) { 9186 ; (function (root, factory) { 9187 if (typeof exports === "object") { 9188 // CommonJS 9189 module.exports = exports = factory(require("./core")); 9190 } 9191 else if (typeof define === "function" && define.amd) { 9192 // AMD 9193 define(["./core"], factory); 9194 } 9195 else { 9196 // Global (browser) 9197 factory(root.CryptoJS); 9198 } 9199 }(this, function (CryptoJS) { 9200 9201 (function () { 9202 // Shortcuts 9203 var C = CryptoJS; 9204 var C_lib = C.lib; 9205 var Base = C_lib.Base; 9206 var C_enc = C.enc; 9207 var Utf8 = C_enc.Utf8; 9208 var C_algo = C.algo; 9209 9210 /** 9211 * HMAC algorithm. 9212 */ 9213 var HMAC = C_algo.HMAC = Base.extend({ 9214 /** 9215 * Initializes a newly created HMAC. 9216 * 9217 * @param {Hasher} hasher The hash algorithm to use. 9218 * @param {WordArray|string} key The secret key. 9219 * 9220 * @example 9221 * 9222 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9223 */ 9224 init: function (hasher, key) { 9225 // Init hasher 9226 hasher = this._hasher = new hasher.init(); 9227 9228 // Convert string to WordArray, else assume WordArray already 9229 if (typeof key == 'string') { 9230 key = Utf8.parse(key); 9231 } 9232 9233 // Shortcuts 9234 var hasherBlockSize = hasher.blockSize; 9235 var hasherBlockSizeBytes = hasherBlockSize * 4; 9236 9237 // Allow arbitrary length keys 9238 if (key.sigBytes > hasherBlockSizeBytes) { 9239 key = hasher.finalize(key); 9240 } 9241 9242 // Clamp excess bits 9243 key.clamp(); 9244 9245 // Clone key for inner and outer pads 9246 var oKey = this._oKey = key.clone(); 9247 var iKey = this._iKey = key.clone(); 9248 9249 // Shortcuts 9250 var oKeyWords = oKey.words; 9251 var iKeyWords = iKey.words; 9252 9253 // XOR keys with pad constants 9254 for (var i = 0; i < hasherBlockSize; i++) { 9255 oKeyWords[i] ^= 0x5c5c5c5c; 9256 iKeyWords[i] ^= 0x36363636; 9257 } 9258 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9259 9260 // Set initial values 9261 this.reset(); 9262 }, 9263 9264 /** 9265 * Resets this HMAC to its initial state. 9266 * 9267 * @example 9268 * 9269 * hmacHasher.reset(); 9270 */ 9271 reset: function () { 9272 // Shortcut 9273 var hasher = this._hasher; 9274 9275 // Reset 9276 hasher.reset(); 9277 hasher.update(this._iKey); 9278 }, 9279 9280 /** 9281 * Updates this HMAC with a message. 9282 * 9283 * @param {WordArray|string} messageUpdate The message to append. 9284 * 9285 * @return {HMAC} This HMAC instance. 9286 * 9287 * @example 9288 * 9289 * hmacHasher.update('message'); 9290 * hmacHasher.update(wordArray); 9291 */ 9292 update: function (messageUpdate) { 9293 this._hasher.update(messageUpdate); 9294 9295 // Chainable 9296 return this; 9297 }, 9298 9299 /** 9300 * Finalizes the HMAC computation. 9301 * Note that the finalize operation is effectively a destructive, read-once operation. 9302 * 9303 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9304 * 9305 * @return {WordArray} The HMAC. 9306 * 9307 * @example 9308 * 9309 * var hmac = hmacHasher.finalize(); 9310 * var hmac = hmacHasher.finalize('message'); 9311 * var hmac = hmacHasher.finalize(wordArray); 9312 */ 9313 finalize: function (messageUpdate) { 9314 // Shortcut 9315 var hasher = this._hasher; 9316 9317 // Compute HMAC 9318 var innerHash = hasher.finalize(messageUpdate); 9319 hasher.reset(); 9320 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9321 9322 return hmac; 9323 } 9324 }); 9325 }()); 9326 9327 9328 })); 9329 }, { "./core": 53 }], 59: [function (require, module, exports) { 9330 ; (function (root, factory, undef) { 9331 if (typeof exports === "object") { 9332 // CommonJS 9333 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")); 9334 } 9335 else if (typeof define === "function" && define.amd) { 9336 // AMD 9337 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); 9338 } 9339 else { 9340 // Global (browser) 9341 root.CryptoJS = factory(root.CryptoJS); 9342 } 9343 }(this, function (CryptoJS) { 9344 9345 return CryptoJS; 9346 9347 })); 9348 }, { "./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) { 9349 ; (function (root, factory) { 9350 if (typeof exports === "object") { 9351 // CommonJS 9352 module.exports = exports = factory(require("./core")); 9353 } 9354 else if (typeof define === "function" && define.amd) { 9355 // AMD 9356 define(["./core"], factory); 9357 } 9358 else { 9359 // Global (browser) 9360 factory(root.CryptoJS); 9361 } 9362 }(this, function (CryptoJS) { 9363 9364 (function () { 9365 // Check if typed arrays are supported 9366 if (typeof ArrayBuffer != 'function') { 9367 return; 9368 } 9369 9370 // Shortcuts 9371 var C = CryptoJS; 9372 var C_lib = C.lib; 9373 var WordArray = C_lib.WordArray; 9374 9375 // Reference original init 9376 var superInit = WordArray.init; 9377 9378 // Augment WordArray.init to handle typed arrays 9379 var subInit = WordArray.init = function (typedArray) { 9380 // Convert buffers to uint8 9381 if (typedArray instanceof ArrayBuffer) { 9382 typedArray = new Uint8Array(typedArray); 9383 } 9384 9385 // Convert other array views to uint8 9386 if ( 9387 typedArray instanceof Int8Array || 9388 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9389 typedArray instanceof Int16Array || 9390 typedArray instanceof Uint16Array || 9391 typedArray instanceof Int32Array || 9392 typedArray instanceof Uint32Array || 9393 typedArray instanceof Float32Array || 9394 typedArray instanceof Float64Array 9395 ) { 9396 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9397 } 9398 9399 // Handle Uint8Array 9400 if (typedArray instanceof Uint8Array) { 9401 // Shortcut 9402 var typedArrayByteLength = typedArray.byteLength; 9403 9404 // Extract bytes 9405 var words = []; 9406 for (var i = 0; i < typedArrayByteLength; i++) { 9407 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9408 } 9409 9410 // Initialize this word array 9411 superInit.call(this, words, typedArrayByteLength); 9412 } else { 9413 // Else call normal init 9414 superInit.apply(this, arguments); 9415 } 9416 }; 9417 9418 subInit.prototype = WordArray; 9419 }()); 9420 9421 9422 return CryptoJS.lib.WordArray; 9423 9424 })); 9425 }, { "./core": 53 }], 61: [function (require, module, exports) { 9426 ; (function (root, factory) { 9427 if (typeof exports === "object") { 9428 // CommonJS 9429 module.exports = exports = factory(require("./core")); 9430 } 9431 else if (typeof define === "function" && define.amd) { 9432 // AMD 9433 define(["./core"], factory); 9434 } 9435 else { 9436 // Global (browser) 9437 factory(root.CryptoJS); 9438 } 9439 }(this, function (CryptoJS) { 9440 9441 (function (Math) { 9442 // Shortcuts 9443 var C = CryptoJS; 9444 var C_lib = C.lib; 9445 var WordArray = C_lib.WordArray; 9446 var Hasher = C_lib.Hasher; 9447 var C_algo = C.algo; 9448 9449 // Constants table 9450 var T = []; 9451 9452 // Compute constants 9453 (function () { 9454 for (var i = 0; i < 64; i++) { 9455 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9456 } 9457 }()); 9458 9459 /** 9460 * MD5 hash algorithm. 9461 */ 9462 var MD5 = C_algo.MD5 = Hasher.extend({ 9463 _doReset: function () { 9464 this._hash = new WordArray.init([ 9465 0x67452301, 0xefcdab89, 9466 0x98badcfe, 0x10325476 9467 ]); 9468 }, 9469 9470 _doProcessBlock: function (M, offset) { 9471 // Swap endian 9472 for (var i = 0; i < 16; i++) { 9473 // Shortcuts 9474 var offset_i = offset + i; 9475 var M_offset_i = M[offset_i]; 9476 9477 M[offset_i] = ( 9478 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9479 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9480 ); 9481 } 9482 9483 // Shortcuts 9484 var H = this._hash.words; 9485 9486 var M_offset_0 = M[offset + 0]; 9487 var M_offset_1 = M[offset + 1]; 9488 var M_offset_2 = M[offset + 2]; 9489 var M_offset_3 = M[offset + 3]; 9490 var M_offset_4 = M[offset + 4]; 9491 var M_offset_5 = M[offset + 5]; 9492 var M_offset_6 = M[offset + 6]; 9493 var M_offset_7 = M[offset + 7]; 9494 var M_offset_8 = M[offset + 8]; 9495 var M_offset_9 = M[offset + 9]; 9496 var M_offset_10 = M[offset + 10]; 9497 var M_offset_11 = M[offset + 11]; 9498 var M_offset_12 = M[offset + 12]; 9499 var M_offset_13 = M[offset + 13]; 9500 var M_offset_14 = M[offset + 14]; 9501 var M_offset_15 = M[offset + 15]; 9502 9503 // Working varialbes 9504 var a = H[0]; 9505 var b = H[1]; 9506 var c = H[2]; 9507 var d = H[3]; 9508 9509 // Computation 9510 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9511 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9512 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9513 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9514 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9515 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9516 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9517 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9518 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9519 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9520 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9521 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9522 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9523 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9524 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9525 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9526 9527 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9528 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9529 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9530 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9531 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9532 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9533 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9534 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9535 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9536 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9537 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9538 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9539 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9540 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9541 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9542 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9543 9544 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9545 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9546 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9547 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9548 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9549 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9550 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9551 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9552 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9553 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9554 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9555 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9556 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9557 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9558 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9559 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9560 9561 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9562 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9563 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9564 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9565 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9566 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9567 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9568 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9569 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9570 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9571 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9572 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9573 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9574 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9575 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9576 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9577 9578 // Intermediate hash value 9579 H[0] = (H[0] + a) | 0; 9580 H[1] = (H[1] + b) | 0; 9581 H[2] = (H[2] + c) | 0; 9582 H[3] = (H[3] + d) | 0; 9583 }, 9584 9585 _doFinalize: function () { 9586 // Shortcuts 9587 var data = this._data; 9588 var dataWords = data.words; 9589 9590 var nBitsTotal = this._nDataBytes * 8; 9591 var nBitsLeft = data.sigBytes * 8; 9592 9593 // Add padding 9594 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9595 9596 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9597 var nBitsTotalL = nBitsTotal; 9598 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9599 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9600 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9601 ); 9602 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9603 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9604 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9605 ); 9606 9607 data.sigBytes = (dataWords.length + 1) * 4; 9608 9609 // Hash final blocks 9610 this._process(); 9611 9612 // Shortcuts 9613 var hash = this._hash; 9614 var H = hash.words; 9615 9616 // Swap endian 9617 for (var i = 0; i < 4; i++) { 9618 // Shortcut 9619 var H_i = H[i]; 9620 9621 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9622 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9623 } 9624 9625 // Return final computed hash 9626 return hash; 9627 }, 9628 9629 clone: function () { 9630 var clone = Hasher.clone.call(this); 9631 clone._hash = this._hash.clone(); 9632 9633 return clone; 9634 } 9635 }); 9636 9637 function FF(a, b, c, d, x, s, t) { 9638 var n = a + ((b & c) | (~b & d)) + x + t; 9639 return ((n << s) | (n >>> (32 - s))) + b; 9640 } 9641 9642 function GG(a, b, c, d, x, s, t) { 9643 var n = a + ((b & d) | (c & ~d)) + x + t; 9644 return ((n << s) | (n >>> (32 - s))) + b; 9645 } 9646 9647 function HH(a, b, c, d, x, s, t) { 9648 var n = a + (b ^ c ^ d) + x + t; 9649 return ((n << s) | (n >>> (32 - s))) + b; 9650 } 9651 9652 function II(a, b, c, d, x, s, t) { 9653 var n = a + (c ^ (b | ~d)) + x + t; 9654 return ((n << s) | (n >>> (32 - s))) + b; 9655 } 9656 9657 /** 9658 * Shortcut function to the hasher's object interface. 9659 * 9660 * @param {WordArray|string} message The message to hash. 9661 * 9662 * @return {WordArray} The hash. 9663 * 9664 * @static 9665 * 9666 * @example 9667 * 9668 * var hash = CryptoJS.MD5('message'); 9669 * var hash = CryptoJS.MD5(wordArray); 9670 */ 9671 C.MD5 = Hasher._createHelper(MD5); 9672 9673 /** 9674 * Shortcut function to the HMAC's object interface. 9675 * 9676 * @param {WordArray|string} message The message to hash. 9677 * @param {WordArray|string} key The secret key. 9678 * 9679 * @return {WordArray} The HMAC. 9680 * 9681 * @static 9682 * 9683 * @example 9684 * 9685 * var hmac = CryptoJS.HmacMD5(message, key); 9686 */ 9687 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9688 }(Math)); 9689 9690 9691 return CryptoJS.MD5; 9692 9693 })); 9694 }, { "./core": 53 }], 62: [function (require, module, exports) { 9695 ; (function (root, factory, undef) { 9696 if (typeof exports === "object") { 9697 // CommonJS 9698 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9699 } 9700 else if (typeof define === "function" && define.amd) { 9701 // AMD 9702 define(["./core", "./cipher-core"], factory); 9703 } 9704 else { 9705 // Global (browser) 9706 factory(root.CryptoJS); 9707 } 9708 }(this, function (CryptoJS) { 9709 9710 /** 9711 * Cipher Feedback block mode. 9712 */ 9713 CryptoJS.mode.CFB = (function () { 9714 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9715 9716 CFB.Encryptor = CFB.extend({ 9717 processBlock: function (words, offset) { 9718 // Shortcuts 9719 var cipher = this._cipher; 9720 var blockSize = cipher.blockSize; 9721 9722 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9723 9724 // Remember this block to use with next block 9725 this._prevBlock = words.slice(offset, offset + blockSize); 9726 } 9727 }); 9728 9729 CFB.Decryptor = CFB.extend({ 9730 processBlock: function (words, offset) { 9731 // Shortcuts 9732 var cipher = this._cipher; 9733 var blockSize = cipher.blockSize; 9734 9735 // Remember this block to use with next block 9736 var thisBlock = words.slice(offset, offset + blockSize); 9737 9738 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9739 9740 // This block becomes the previous block 9741 this._prevBlock = thisBlock; 9742 } 9743 }); 9744 9745 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9746 // Shortcut 9747 var iv = this._iv; 9748 9749 // Generate keystream 9750 if (iv) { 9751 var keystream = iv.slice(0); 9752 9753 // Remove IV for subsequent blocks 9754 this._iv = undefined; 9755 } else { 9756 var keystream = this._prevBlock; 9757 } 9758 cipher.encryptBlock(keystream, 0); 9759 9760 // Encrypt 9761 for (var i = 0; i < blockSize; i++) { 9762 words[offset + i] ^= keystream[i]; 9763 } 9764 } 9765 9766 return CFB; 9767 }()); 9768 9769 9770 return CryptoJS.mode.CFB; 9771 9772 })); 9773 }, { "./cipher-core": 52, "./core": 53 }], 63: [function (require, module, exports) { 9774 ; (function (root, factory, undef) { 9775 if (typeof exports === "object") { 9776 // CommonJS 9777 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9778 } 9779 else if (typeof define === "function" && define.amd) { 9780 // AMD 9781 define(["./core", "./cipher-core"], factory); 9782 } 9783 else { 9784 // Global (browser) 9785 factory(root.CryptoJS); 9786 } 9787 }(this, function (CryptoJS) { 9788 9789 /** @preserve 9790 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9791 * derived from CryptoJS.mode.CTR 9792 * Jan Hruby jhruby.web@gmail.com 9793 */ 9794 CryptoJS.mode.CTRGladman = (function () { 9795 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9796 9797 function incWord(word) { 9798 if (((word >> 24) & 0xff) === 0xff) { //overflow 9799 var b1 = (word >> 16) & 0xff; 9800 var b2 = (word >> 8) & 0xff; 9801 var b3 = word & 0xff; 9802 9803 if (b1 === 0xff) // overflow b1 9804 { 9805 b1 = 0; 9806 if (b2 === 0xff) { 9807 b2 = 0; 9808 if (b3 === 0xff) { 9809 b3 = 0; 9810 } 9811 else { 9812 ++b3; 9813 } 9814 } 9815 else { 9816 ++b2; 9817 } 9818 } 9819 else { 9820 ++b1; 9821 } 9822 9823 word = 0; 9824 word += (b1 << 16); 9825 word += (b2 << 8); 9826 word += b3; 9827 } 9828 else { 9829 word += (0x01 << 24); 9830 } 9831 return word; 9832 } 9833 9834 function incCounter(counter) { 9835 if ((counter[0] = incWord(counter[0])) === 0) { 9836 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9837 counter[1] = incWord(counter[1]); 9838 } 9839 return counter; 9840 } 9841 9842 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9843 processBlock: function (words, offset) { 9844 // Shortcuts 9845 var cipher = this._cipher 9846 var blockSize = cipher.blockSize; 9847 var iv = this._iv; 9848 var counter = this._counter; 9849 9850 // Generate keystream 9851 if (iv) { 9852 counter = this._counter = iv.slice(0); 9853 9854 // Remove IV for subsequent blocks 9855 this._iv = undefined; 9856 } 9857 9858 incCounter(counter); 9859 9860 var keystream = counter.slice(0); 9861 cipher.encryptBlock(keystream, 0); 9862 9863 // Encrypt 9864 for (var i = 0; i < blockSize; i++) { 9865 words[offset + i] ^= keystream[i]; 9866 } 9867 } 9868 }); 9869 9870 CTRGladman.Decryptor = Encryptor; 9871 9872 return CTRGladman; 9873 }()); 9874 9875 9876 9877 9878 return CryptoJS.mode.CTRGladman; 9879 9880 })); 9881 }, { "./cipher-core": 52, "./core": 53 }], 64: [function (require, module, exports) { 9882 ; (function (root, factory, undef) { 9883 if (typeof exports === "object") { 9884 // CommonJS 9885 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9886 } 9887 else if (typeof define === "function" && define.amd) { 9888 // AMD 9889 define(["./core", "./cipher-core"], factory); 9890 } 9891 else { 9892 // Global (browser) 9893 factory(root.CryptoJS); 9894 } 9895 }(this, function (CryptoJS) { 9896 9897 /** 9898 * Counter block mode. 9899 */ 9900 CryptoJS.mode.CTR = (function () { 9901 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 9902 9903 var Encryptor = CTR.Encryptor = CTR.extend({ 9904 processBlock: function (words, offset) { 9905 // Shortcuts 9906 var cipher = this._cipher 9907 var blockSize = cipher.blockSize; 9908 var iv = this._iv; 9909 var counter = this._counter; 9910 9911 // Generate keystream 9912 if (iv) { 9913 counter = this._counter = iv.slice(0); 9914 9915 // Remove IV for subsequent blocks 9916 this._iv = undefined; 9917 } 9918 var keystream = counter.slice(0); 9919 cipher.encryptBlock(keystream, 0); 9920 9921 // Increment counter 9922 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 9923 9924 // Encrypt 9925 for (var i = 0; i < blockSize; i++) { 9926 words[offset + i] ^= keystream[i]; 9927 } 9928 } 9929 }); 9930 9931 CTR.Decryptor = Encryptor; 9932 9933 return CTR; 9934 }()); 9935 9936 9937 return CryptoJS.mode.CTR; 9938 9939 })); 9940 }, { "./cipher-core": 52, "./core": 53 }], 65: [function (require, module, exports) { 9941 ; (function (root, factory, undef) { 9942 if (typeof exports === "object") { 9943 // CommonJS 9944 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9945 } 9946 else if (typeof define === "function" && define.amd) { 9947 // AMD 9948 define(["./core", "./cipher-core"], factory); 9949 } 9950 else { 9951 // Global (browser) 9952 factory(root.CryptoJS); 9953 } 9954 }(this, function (CryptoJS) { 9955 9956 /** 9957 * Electronic Codebook block mode. 9958 */ 9959 CryptoJS.mode.ECB = (function () { 9960 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 9961 9962 ECB.Encryptor = ECB.extend({ 9963 processBlock: function (words, offset) { 9964 this._cipher.encryptBlock(words, offset); 9965 } 9966 }); 9967 9968 ECB.Decryptor = ECB.extend({ 9969 processBlock: function (words, offset) { 9970 this._cipher.decryptBlock(words, offset); 9971 } 9972 }); 9973 9974 return ECB; 9975 }()); 9976 9977 9978 return CryptoJS.mode.ECB; 9979 9980 })); 9981 }, { "./cipher-core": 52, "./core": 53 }], 66: [function (require, module, exports) { 9982 ; (function (root, factory, undef) { 9983 if (typeof exports === "object") { 9984 // CommonJS 9985 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9986 } 9987 else if (typeof define === "function" && define.amd) { 9988 // AMD 9989 define(["./core", "./cipher-core"], factory); 9990 } 9991 else { 9992 // Global (browser) 9993 factory(root.CryptoJS); 9994 } 9995 }(this, function (CryptoJS) { 9996 9997 /** 9998 * Output Feedback block mode. 9999 */ 10000 CryptoJS.mode.OFB = (function () { 10001 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 10002 10003 var Encryptor = OFB.Encryptor = OFB.extend({ 10004 processBlock: function (words, offset) { 10005 // Shortcuts 10006 var cipher = this._cipher 10007 var blockSize = cipher.blockSize; 10008 var iv = this._iv; 10009 var keystream = this._keystream; 10010 10011 // Generate keystream 10012 if (iv) { 10013 keystream = this._keystream = iv.slice(0); 10014 10015 // Remove IV for subsequent blocks 10016 this._iv = undefined; 10017 } 10018 cipher.encryptBlock(keystream, 0); 10019 10020 // Encrypt 10021 for (var i = 0; i < blockSize; i++) { 10022 words[offset + i] ^= keystream[i]; 10023 } 10024 } 10025 }); 10026 10027 OFB.Decryptor = Encryptor; 10028 10029 return OFB; 10030 }()); 10031 10032 10033 return CryptoJS.mode.OFB; 10034 10035 })); 10036 }, { "./cipher-core": 52, "./core": 53 }], 67: [function (require, module, exports) { 10037 ; (function (root, factory, undef) { 10038 if (typeof exports === "object") { 10039 // CommonJS 10040 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10041 } 10042 else if (typeof define === "function" && define.amd) { 10043 // AMD 10044 define(["./core", "./cipher-core"], factory); 10045 } 10046 else { 10047 // Global (browser) 10048 factory(root.CryptoJS); 10049 } 10050 }(this, function (CryptoJS) { 10051 10052 /** 10053 * ANSI X.923 padding strategy. 10054 */ 10055 CryptoJS.pad.AnsiX923 = { 10056 pad: function (data, blockSize) { 10057 // Shortcuts 10058 var dataSigBytes = data.sigBytes; 10059 var blockSizeBytes = blockSize * 4; 10060 10061 // Count padding bytes 10062 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10063 10064 // Compute last byte position 10065 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10066 10067 // Pad 10068 data.clamp(); 10069 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10070 data.sigBytes += nPaddingBytes; 10071 }, 10072 10073 unpad: function (data) { 10074 // Get number of padding bytes from last byte 10075 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10076 10077 // Remove padding 10078 data.sigBytes -= nPaddingBytes; 10079 } 10080 }; 10081 10082 10083 return CryptoJS.pad.Ansix923; 10084 10085 })); 10086 }, { "./cipher-core": 52, "./core": 53 }], 68: [function (require, module, exports) { 10087 ; (function (root, factory, undef) { 10088 if (typeof exports === "object") { 10089 // CommonJS 10090 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10091 } 10092 else if (typeof define === "function" && define.amd) { 10093 // AMD 10094 define(["./core", "./cipher-core"], factory); 10095 } 10096 else { 10097 // Global (browser) 10098 factory(root.CryptoJS); 10099 } 10100 }(this, function (CryptoJS) { 10101 10102 /** 10103 * ISO 10126 padding strategy. 10104 */ 10105 CryptoJS.pad.Iso10126 = { 10106 pad: function (data, blockSize) { 10107 // Shortcut 10108 var blockSizeBytes = blockSize * 4; 10109 10110 // Count padding bytes 10111 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10112 10113 // Pad 10114 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10115 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10116 }, 10117 10118 unpad: function (data) { 10119 // Get number of padding bytes from last byte 10120 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10121 10122 // Remove padding 10123 data.sigBytes -= nPaddingBytes; 10124 } 10125 }; 10126 10127 10128 return CryptoJS.pad.Iso10126; 10129 10130 })); 10131 }, { "./cipher-core": 52, "./core": 53 }], 69: [function (require, module, exports) { 10132 ; (function (root, factory, undef) { 10133 if (typeof exports === "object") { 10134 // CommonJS 10135 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10136 } 10137 else if (typeof define === "function" && define.amd) { 10138 // AMD 10139 define(["./core", "./cipher-core"], factory); 10140 } 10141 else { 10142 // Global (browser) 10143 factory(root.CryptoJS); 10144 } 10145 }(this, function (CryptoJS) { 10146 10147 /** 10148 * ISO/IEC 9797-1 Padding Method 2. 10149 */ 10150 CryptoJS.pad.Iso97971 = { 10151 pad: function (data, blockSize) { 10152 // Add 0x80 byte 10153 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10154 10155 // Zero pad the rest 10156 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10157 }, 10158 10159 unpad: function (data) { 10160 // Remove zero padding 10161 CryptoJS.pad.ZeroPadding.unpad(data); 10162 10163 // Remove one more byte -- the 0x80 byte 10164 data.sigBytes--; 10165 } 10166 }; 10167 10168 10169 return CryptoJS.pad.Iso97971; 10170 10171 })); 10172 }, { "./cipher-core": 52, "./core": 53 }], 70: [function (require, module, exports) { 10173 ; (function (root, factory, undef) { 10174 if (typeof exports === "object") { 10175 // CommonJS 10176 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10177 } 10178 else if (typeof define === "function" && define.amd) { 10179 // AMD 10180 define(["./core", "./cipher-core"], factory); 10181 } 10182 else { 10183 // Global (browser) 10184 factory(root.CryptoJS); 10185 } 10186 }(this, function (CryptoJS) { 10187 10188 /** 10189 * A noop padding strategy. 10190 */ 10191 CryptoJS.pad.NoPadding = { 10192 pad: function () { 10193 }, 10194 10195 unpad: function () { 10196 } 10197 }; 10198 10199 10200 return CryptoJS.pad.NoPadding; 10201 10202 })); 10203 }, { "./cipher-core": 52, "./core": 53 }], 71: [function (require, module, exports) { 10204 ; (function (root, factory, undef) { 10205 if (typeof exports === "object") { 10206 // CommonJS 10207 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10208 } 10209 else if (typeof define === "function" && define.amd) { 10210 // AMD 10211 define(["./core", "./cipher-core"], factory); 10212 } 10213 else { 10214 // Global (browser) 10215 factory(root.CryptoJS); 10216 } 10217 }(this, function (CryptoJS) { 10218 10219 /** 10220 * Zero padding strategy. 10221 */ 10222 CryptoJS.pad.ZeroPadding = { 10223 pad: function (data, blockSize) { 10224 // Shortcut 10225 var blockSizeBytes = blockSize * 4; 10226 10227 // Pad 10228 data.clamp(); 10229 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10230 }, 10231 10232 unpad: function (data) { 10233 // Shortcut 10234 var dataWords = data.words; 10235 10236 // Unpad 10237 var i = data.sigBytes - 1; 10238 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10239 i--; 10240 } 10241 data.sigBytes = i + 1; 10242 } 10243 }; 10244 10245 10246 return CryptoJS.pad.ZeroPadding; 10247 10248 })); 10249 }, { "./cipher-core": 52, "./core": 53 }], 72: [function (require, module, exports) { 10250 ; (function (root, factory, undef) { 10251 if (typeof exports === "object") { 10252 // CommonJS 10253 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10254 } 10255 else if (typeof define === "function" && define.amd) { 10256 // AMD 10257 define(["./core", "./sha1", "./hmac"], factory); 10258 } 10259 else { 10260 // Global (browser) 10261 factory(root.CryptoJS); 10262 } 10263 }(this, function (CryptoJS) { 10264 10265 (function () { 10266 // Shortcuts 10267 var C = CryptoJS; 10268 var C_lib = C.lib; 10269 var Base = C_lib.Base; 10270 var WordArray = C_lib.WordArray; 10271 var C_algo = C.algo; 10272 var SHA1 = C_algo.SHA1; 10273 var HMAC = C_algo.HMAC; 10274 10275 /** 10276 * Password-Based Key Derivation Function 2 algorithm. 10277 */ 10278 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10279 /** 10280 * Configuration options. 10281 * 10282 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10283 * @property {Hasher} hasher The hasher to use. Default: SHA1 10284 * @property {number} iterations The number of iterations to perform. Default: 1 10285 */ 10286 cfg: Base.extend({ 10287 keySize: 128 / 32, 10288 hasher: SHA1, 10289 iterations: 1 10290 }), 10291 10292 /** 10293 * Initializes a newly created key derivation function. 10294 * 10295 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10296 * 10297 * @example 10298 * 10299 * var kdf = CryptoJS.algo.PBKDF2.create(); 10300 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10301 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10302 */ 10303 init: function (cfg) { 10304 this.cfg = this.cfg.extend(cfg); 10305 }, 10306 10307 /** 10308 * Computes the Password-Based Key Derivation Function 2. 10309 * 10310 * @param {WordArray|string} password The password. 10311 * @param {WordArray|string} salt A salt. 10312 * 10313 * @return {WordArray} The derived key. 10314 * 10315 * @example 10316 * 10317 * var key = kdf.compute(password, salt); 10318 */ 10319 compute: function (password, salt) { 10320 // Shortcut 10321 var cfg = this.cfg; 10322 10323 // Init HMAC 10324 var hmac = HMAC.create(cfg.hasher, password); 10325 10326 // Initial values 10327 var derivedKey = WordArray.create(); 10328 var blockIndex = WordArray.create([0x00000001]); 10329 10330 // Shortcuts 10331 var derivedKeyWords = derivedKey.words; 10332 var blockIndexWords = blockIndex.words; 10333 var keySize = cfg.keySize; 10334 var iterations = cfg.iterations; 10335 10336 // Generate key 10337 while (derivedKeyWords.length < keySize) { 10338 var block = hmac.update(salt).finalize(blockIndex); 10339 hmac.reset(); 10340 10341 // Shortcuts 10342 var blockWords = block.words; 10343 var blockWordsLength = blockWords.length; 10344 10345 // Iterations 10346 var intermediate = block; 10347 for (var i = 1; i < iterations; i++) { 10348 intermediate = hmac.finalize(intermediate); 10349 hmac.reset(); 10350 10351 // Shortcut 10352 var intermediateWords = intermediate.words; 10353 10354 // XOR intermediate with block 10355 for (var j = 0; j < blockWordsLength; j++) { 10356 blockWords[j] ^= intermediateWords[j]; 10357 } 10358 } 10359 10360 derivedKey.concat(block); 10361 blockIndexWords[0]++; 10362 } 10363 derivedKey.sigBytes = keySize * 4; 10364 10365 return derivedKey; 10366 } 10367 }); 10368 10369 /** 10370 * Computes the Password-Based Key Derivation Function 2. 10371 * 10372 * @param {WordArray|string} password The password. 10373 * @param {WordArray|string} salt A salt. 10374 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10375 * 10376 * @return {WordArray} The derived key. 10377 * 10378 * @static 10379 * 10380 * @example 10381 * 10382 * var key = CryptoJS.PBKDF2(password, salt); 10383 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10384 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10385 */ 10386 C.PBKDF2 = function (password, salt, cfg) { 10387 return PBKDF2.create(cfg).compute(password, salt); 10388 }; 10389 }()); 10390 10391 10392 return CryptoJS.PBKDF2; 10393 10394 })); 10395 }, { "./core": 53, "./hmac": 58, "./sha1": 77 }], 73: [function (require, module, exports) { 10396 ; (function (root, factory, undef) { 10397 if (typeof exports === "object") { 10398 // CommonJS 10399 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10400 } 10401 else if (typeof define === "function" && define.amd) { 10402 // AMD 10403 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10404 } 10405 else { 10406 // Global (browser) 10407 factory(root.CryptoJS); 10408 } 10409 }(this, function (CryptoJS) { 10410 10411 (function () { 10412 // Shortcuts 10413 var C = CryptoJS; 10414 var C_lib = C.lib; 10415 var StreamCipher = C_lib.StreamCipher; 10416 var C_algo = C.algo; 10417 10418 // Reusable objects 10419 var S = []; 10420 var C_ = []; 10421 var G = []; 10422 10423 /** 10424 * Rabbit stream cipher algorithm. 10425 * 10426 * This is a legacy version that neglected to convert the key to little-endian. 10427 * This error doesn't affect the cipher's security, 10428 * but it does affect its compatibility with other implementations. 10429 */ 10430 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10431 _doReset: function () { 10432 // Shortcuts 10433 var K = this._key.words; 10434 var iv = this.cfg.iv; 10435 10436 // Generate initial state values 10437 var X = this._X = [ 10438 K[0], (K[3] << 16) | (K[2] >>> 16), 10439 K[1], (K[0] << 16) | (K[3] >>> 16), 10440 K[2], (K[1] << 16) | (K[0] >>> 16), 10441 K[3], (K[2] << 16) | (K[1] >>> 16) 10442 ]; 10443 10444 // Generate initial counter values 10445 var C = this._C = [ 10446 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10447 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10448 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10449 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10450 ]; 10451 10452 // Carry bit 10453 this._b = 0; 10454 10455 // Iterate the system four times 10456 for (var i = 0; i < 4; i++) { 10457 nextState.call(this); 10458 } 10459 10460 // Modify the counters 10461 for (var i = 0; i < 8; i++) { 10462 C[i] ^= X[(i + 4) & 7]; 10463 } 10464 10465 // IV setup 10466 if (iv) { 10467 // Shortcuts 10468 var IV = iv.words; 10469 var IV_0 = IV[0]; 10470 var IV_1 = IV[1]; 10471 10472 // Generate four subvectors 10473 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10474 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10475 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10476 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10477 10478 // Modify counter values 10479 C[0] ^= i0; 10480 C[1] ^= i1; 10481 C[2] ^= i2; 10482 C[3] ^= i3; 10483 C[4] ^= i0; 10484 C[5] ^= i1; 10485 C[6] ^= i2; 10486 C[7] ^= i3; 10487 10488 // Iterate the system four times 10489 for (var i = 0; i < 4; i++) { 10490 nextState.call(this); 10491 } 10492 } 10493 }, 10494 10495 _doProcessBlock: function (M, offset) { 10496 // Shortcut 10497 var X = this._X; 10498 10499 // Iterate the system 10500 nextState.call(this); 10501 10502 // Generate four keystream words 10503 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10504 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10505 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10506 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10507 10508 for (var i = 0; i < 4; i++) { 10509 // Swap endian 10510 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10511 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10512 10513 // Encrypt 10514 M[offset + i] ^= S[i]; 10515 } 10516 }, 10517 10518 blockSize: 128 / 32, 10519 10520 ivSize: 64 / 32 10521 }); 10522 10523 function nextState() { 10524 // Shortcuts 10525 var X = this._X; 10526 var C = this._C; 10527 10528 // Save old counter values 10529 for (var i = 0; i < 8; i++) { 10530 C_[i] = C[i]; 10531 } 10532 10533 // Calculate new counter values 10534 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10535 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10536 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10537 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10538 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10539 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10540 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10541 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10542 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10543 10544 // Calculate the g-values 10545 for (var i = 0; i < 8; i++) { 10546 var gx = X[i] + C[i]; 10547 10548 // Construct high and low argument for squaring 10549 var ga = gx & 0xffff; 10550 var gb = gx >>> 16; 10551 10552 // Calculate high and low result of squaring 10553 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10554 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10555 10556 // High XOR low 10557 G[i] = gh ^ gl; 10558 } 10559 10560 // Calculate new state values 10561 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10562 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10563 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10564 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10565 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10566 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10567 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10568 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10569 } 10570 10571 /** 10572 * Shortcut functions to the cipher's object interface. 10573 * 10574 * @example 10575 * 10576 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10577 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10578 */ 10579 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10580 }()); 10581 10582 10583 return CryptoJS.RabbitLegacy; 10584 10585 })); 10586 }, { "./cipher-core": 52, "./core": 53, "./enc-base64": 54, "./evpkdf": 56, "./md5": 61 }], 74: [function (require, module, exports) { 10587 ; (function (root, factory, undef) { 10588 if (typeof exports === "object") { 10589 // CommonJS 10590 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10591 } 10592 else if (typeof define === "function" && define.amd) { 10593 // AMD 10594 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10595 } 10596 else { 10597 // Global (browser) 10598 factory(root.CryptoJS); 10599 } 10600 }(this, function (CryptoJS) { 10601 10602 (function () { 10603 // Shortcuts 10604 var C = CryptoJS; 10605 var C_lib = C.lib; 10606 var StreamCipher = C_lib.StreamCipher; 10607 var C_algo = C.algo; 10608 10609 // Reusable objects 10610 var S = []; 10611 var C_ = []; 10612 var G = []; 10613 10614 /** 10615 * Rabbit stream cipher algorithm 10616 */ 10617 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10618 _doReset: function () { 10619 // Shortcuts 10620 var K = this._key.words; 10621 var iv = this.cfg.iv; 10622 10623 // Swap endian 10624 for (var i = 0; i < 4; i++) { 10625 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10626 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10627 } 10628 10629 // Generate initial state values 10630 var X = this._X = [ 10631 K[0], (K[3] << 16) | (K[2] >>> 16), 10632 K[1], (K[0] << 16) | (K[3] >>> 16), 10633 K[2], (K[1] << 16) | (K[0] >>> 16), 10634 K[3], (K[2] << 16) | (K[1] >>> 16) 10635 ]; 10636 10637 // Generate initial counter values 10638 var C = this._C = [ 10639 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10640 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10641 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10642 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10643 ]; 10644 10645 // Carry bit 10646 this._b = 0; 10647 10648 // Iterate the system four times 10649 for (var i = 0; i < 4; i++) { 10650 nextState.call(this); 10651 } 10652 10653 // Modify the counters 10654 for (var i = 0; i < 8; i++) { 10655 C[i] ^= X[(i + 4) & 7]; 10656 } 10657 10658 // IV setup 10659 if (iv) { 10660 // Shortcuts 10661 var IV = iv.words; 10662 var IV_0 = IV[0]; 10663 var IV_1 = IV[1]; 10664 10665 // Generate four subvectors 10666 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10667 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10668 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10669 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10670 10671 // Modify counter values 10672 C[0] ^= i0; 10673 C[1] ^= i1; 10674 C[2] ^= i2; 10675 C[3] ^= i3; 10676 C[4] ^= i0; 10677 C[5] ^= i1; 10678 C[6] ^= i2; 10679 C[7] ^= i3; 10680 10681 // Iterate the system four times 10682 for (var i = 0; i < 4; i++) { 10683 nextState.call(this); 10684 } 10685 } 10686 }, 10687 10688 _doProcessBlock: function (M, offset) { 10689 // Shortcut 10690 var X = this._X; 10691 10692 // Iterate the system 10693 nextState.call(this); 10694 10695 // Generate four keystream words 10696 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10697 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10698 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10699 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10700 10701 for (var i = 0; i < 4; i++) { 10702 // Swap endian 10703 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10704 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10705 10706 // Encrypt 10707 M[offset + i] ^= S[i]; 10708 } 10709 }, 10710 10711 blockSize: 128 / 32, 10712 10713 ivSize: 64 / 32 10714 }); 10715 10716 function nextState() { 10717 // Shortcuts 10718 var X = this._X; 10719 var C = this._C; 10720 10721 // Save old counter values 10722 for (var i = 0; i < 8; i++) { 10723 C_[i] = C[i]; 10724 } 10725 10726 // Calculate new counter values 10727 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10728 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10729 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10730 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10731 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10732 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10733 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10734 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10735 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10736 10737 // Calculate the g-values 10738 for (var i = 0; i < 8; i++) { 10739 var gx = X[i] + C[i]; 10740 10741 // Construct high and low argument for squaring 10742 var ga = gx & 0xffff; 10743 var gb = gx >>> 16; 10744 10745 // Calculate high and low result of squaring 10746 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10747 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10748 10749 // High XOR low 10750 G[i] = gh ^ gl; 10751 } 10752 10753 // Calculate new state values 10754 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10755 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10756 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10757 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10758 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10759 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10760 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10761 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10762 } 10763 10764 /** 10765 * Shortcut functions to the cipher's object interface. 10766 * 10767 * @example 10768 * 10769 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10770 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10771 */ 10772 C.Rabbit = StreamCipher._createHelper(Rabbit); 10773 }()); 10774 10775 10776 return CryptoJS.Rabbit; 10777 10778 })); 10779 }, { "./cipher-core": 52, "./core": 53, "./enc-base64": 54, "./evpkdf": 56, "./md5": 61 }], 75: [function (require, module, exports) { 10780 ; (function (root, factory, undef) { 10781 if (typeof exports === "object") { 10782 // CommonJS 10783 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10784 } 10785 else if (typeof define === "function" && define.amd) { 10786 // AMD 10787 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10788 } 10789 else { 10790 // Global (browser) 10791 factory(root.CryptoJS); 10792 } 10793 }(this, function (CryptoJS) { 10794 10795 (function () { 10796 // Shortcuts 10797 var C = CryptoJS; 10798 var C_lib = C.lib; 10799 var StreamCipher = C_lib.StreamCipher; 10800 var C_algo = C.algo; 10801 10802 /** 10803 * RC4 stream cipher algorithm. 10804 */ 10805 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10806 _doReset: function () { 10807 // Shortcuts 10808 var key = this._key; 10809 var keyWords = key.words; 10810 var keySigBytes = key.sigBytes; 10811 10812 // Init sbox 10813 var S = this._S = []; 10814 for (var i = 0; i < 256; i++) { 10815 S[i] = i; 10816 } 10817 10818 // Key setup 10819 for (var i = 0, j = 0; i < 256; i++) { 10820 var keyByteIndex = i % keySigBytes; 10821 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10822 10823 j = (j + S[i] + keyByte) % 256; 10824 10825 // Swap 10826 var t = S[i]; 10827 S[i] = S[j]; 10828 S[j] = t; 10829 } 10830 10831 // Counters 10832 this._i = this._j = 0; 10833 }, 10834 10835 _doProcessBlock: function (M, offset) { 10836 M[offset] ^= generateKeystreamWord.call(this); 10837 }, 10838 10839 keySize: 256 / 32, 10840 10841 ivSize: 0 10842 }); 10843 10844 function generateKeystreamWord() { 10845 // Shortcuts 10846 var S = this._S; 10847 var i = this._i; 10848 var j = this._j; 10849 10850 // Generate keystream word 10851 var keystreamWord = 0; 10852 for (var n = 0; n < 4; n++) { 10853 i = (i + 1) % 256; 10854 j = (j + S[i]) % 256; 10855 10856 // Swap 10857 var t = S[i]; 10858 S[i] = S[j]; 10859 S[j] = t; 10860 10861 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 10862 } 10863 10864 // Update counters 10865 this._i = i; 10866 this._j = j; 10867 10868 return keystreamWord; 10869 } 10870 10871 /** 10872 * Shortcut functions to the cipher's object interface. 10873 * 10874 * @example 10875 * 10876 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 10877 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 10878 */ 10879 C.RC4 = StreamCipher._createHelper(RC4); 10880 10881 /** 10882 * Modified RC4 stream cipher algorithm. 10883 */ 10884 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 10885 /** 10886 * Configuration options. 10887 * 10888 * @property {number} drop The number of keystream words to drop. Default 192 10889 */ 10890 cfg: RC4.cfg.extend({ 10891 drop: 192 10892 }), 10893 10894 _doReset: function () { 10895 RC4._doReset.call(this); 10896 10897 // Drop 10898 for (var i = this.cfg.drop; i > 0; i--) { 10899 generateKeystreamWord.call(this); 10900 } 10901 } 10902 }); 10903 10904 /** 10905 * Shortcut functions to the cipher's object interface. 10906 * 10907 * @example 10908 * 10909 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 10910 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 10911 */ 10912 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 10913 }()); 10914 10915 10916 return CryptoJS.RC4; 10917 10918 })); 10919 }, { "./cipher-core": 52, "./core": 53, "./enc-base64": 54, "./evpkdf": 56, "./md5": 61 }], 76: [function (require, module, exports) { 10920 ; (function (root, factory) { 10921 if (typeof exports === "object") { 10922 // CommonJS 10923 module.exports = exports = factory(require("./core")); 10924 } 10925 else if (typeof define === "function" && define.amd) { 10926 // AMD 10927 define(["./core"], factory); 10928 } 10929 else { 10930 // Global (browser) 10931 factory(root.CryptoJS); 10932 } 10933 }(this, function (CryptoJS) { 10934 10935 /** @preserve 10936 (c) 2012 by CĂ©dric Mesnil. All rights reserved. 10937 10938 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 10939 10940 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 10941 - 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. 10942 10943 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. 10944 */ 10945 10946 (function (Math) { 10947 // Shortcuts 10948 var C = CryptoJS; 10949 var C_lib = C.lib; 10950 var WordArray = C_lib.WordArray; 10951 var Hasher = C_lib.Hasher; 10952 var C_algo = C.algo; 10953 10954 // Constants table 10955 var _zl = WordArray.create([ 10956 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10957 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 10958 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 10959 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 10960 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]); 10961 var _zr = WordArray.create([ 10962 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 10963 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 10964 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 10965 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 10966 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]); 10967 var _sl = WordArray.create([ 10968 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 10969 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 10970 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 10971 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 10972 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]); 10973 var _sr = WordArray.create([ 10974 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 10975 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 10976 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 10977 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 10978 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]); 10979 10980 var _hl = WordArray.create([0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 10981 var _hr = WordArray.create([0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 10982 10983 /** 10984 * RIPEMD160 hash algorithm. 10985 */ 10986 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 10987 _doReset: function () { 10988 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 10989 }, 10990 10991 _doProcessBlock: function (M, offset) { 10992 10993 // Swap endian 10994 for (var i = 0; i < 16; i++) { 10995 // Shortcuts 10996 var offset_i = offset + i; 10997 var M_offset_i = M[offset_i]; 10998 10999 // Swap 11000 M[offset_i] = ( 11001 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 11002 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 11003 ); 11004 } 11005 // Shortcut 11006 var H = this._hash.words; 11007 var hl = _hl.words; 11008 var hr = _hr.words; 11009 var zl = _zl.words; 11010 var zr = _zr.words; 11011 var sl = _sl.words; 11012 var sr = _sr.words; 11013 11014 // Working variables 11015 var al, bl, cl, dl, el; 11016 var ar, br, cr, dr, er; 11017 11018 ar = al = H[0]; 11019 br = bl = H[1]; 11020 cr = cl = H[2]; 11021 dr = dl = H[3]; 11022 er = el = H[4]; 11023 // Computation 11024 var t; 11025 for (var i = 0; i < 80; i += 1) { 11026 t = (al + M[offset + zl[i]]) | 0; 11027 if (i < 16) { 11028 t += f1(bl, cl, dl) + hl[0]; 11029 } else if (i < 32) { 11030 t += f2(bl, cl, dl) + hl[1]; 11031 } else if (i < 48) { 11032 t += f3(bl, cl, dl) + hl[2]; 11033 } else if (i < 64) { 11034 t += f4(bl, cl, dl) + hl[3]; 11035 } else {// if (i<80) { 11036 t += f5(bl, cl, dl) + hl[4]; 11037 } 11038 t = t | 0; 11039 t = rotl(t, sl[i]); 11040 t = (t + el) | 0; 11041 al = el; 11042 el = dl; 11043 dl = rotl(cl, 10); 11044 cl = bl; 11045 bl = t; 11046 11047 t = (ar + M[offset + zr[i]]) | 0; 11048 if (i < 16) { 11049 t += f5(br, cr, dr) + hr[0]; 11050 } else if (i < 32) { 11051 t += f4(br, cr, dr) + hr[1]; 11052 } else if (i < 48) { 11053 t += f3(br, cr, dr) + hr[2]; 11054 } else if (i < 64) { 11055 t += f2(br, cr, dr) + hr[3]; 11056 } else {// if (i<80) { 11057 t += f1(br, cr, dr) + hr[4]; 11058 } 11059 t = t | 0; 11060 t = rotl(t, sr[i]); 11061 t = (t + er) | 0; 11062 ar = er; 11063 er = dr; 11064 dr = rotl(cr, 10); 11065 cr = br; 11066 br = t; 11067 } 11068 // Intermediate hash value 11069 t = (H[1] + cl + dr) | 0; 11070 H[1] = (H[2] + dl + er) | 0; 11071 H[2] = (H[3] + el + ar) | 0; 11072 H[3] = (H[4] + al + br) | 0; 11073 H[4] = (H[0] + bl + cr) | 0; 11074 H[0] = t; 11075 }, 11076 11077 _doFinalize: function () { 11078 // Shortcuts 11079 var data = this._data; 11080 var dataWords = data.words; 11081 11082 var nBitsTotal = this._nDataBytes * 8; 11083 var nBitsLeft = data.sigBytes * 8; 11084 11085 // Add padding 11086 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11087 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11088 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11089 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11090 ); 11091 data.sigBytes = (dataWords.length + 1) * 4; 11092 11093 // Hash final blocks 11094 this._process(); 11095 11096 // Shortcuts 11097 var hash = this._hash; 11098 var H = hash.words; 11099 11100 // Swap endian 11101 for (var i = 0; i < 5; i++) { 11102 // Shortcut 11103 var H_i = H[i]; 11104 11105 // Swap 11106 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11107 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11108 } 11109 11110 // Return final computed hash 11111 return hash; 11112 }, 11113 11114 clone: function () { 11115 var clone = Hasher.clone.call(this); 11116 clone._hash = this._hash.clone(); 11117 11118 return clone; 11119 } 11120 }); 11121 11122 11123 function f1(x, y, z) { 11124 return ((x) ^ (y) ^ (z)); 11125 11126 } 11127 11128 function f2(x, y, z) { 11129 return (((x) & (y)) | ((~x) & (z))); 11130 } 11131 11132 function f3(x, y, z) { 11133 return (((x) | (~(y))) ^ (z)); 11134 } 11135 11136 function f4(x, y, z) { 11137 return (((x) & (z)) | ((y) & (~(z)))); 11138 } 11139 11140 function f5(x, y, z) { 11141 return ((x) ^ ((y) | (~(z)))); 11142 11143 } 11144 11145 function rotl(x, n) { 11146 return (x << n) | (x >>> (32 - n)); 11147 } 11148 11149 11150 /** 11151 * Shortcut function to the hasher's object interface. 11152 * 11153 * @param {WordArray|string} message The message to hash. 11154 * 11155 * @return {WordArray} The hash. 11156 * 11157 * @static 11158 * 11159 * @example 11160 * 11161 * var hash = CryptoJS.RIPEMD160('message'); 11162 * var hash = CryptoJS.RIPEMD160(wordArray); 11163 */ 11164 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11165 11166 /** 11167 * Shortcut function to the HMAC's object interface. 11168 * 11169 * @param {WordArray|string} message The message to hash. 11170 * @param {WordArray|string} key The secret key. 11171 * 11172 * @return {WordArray} The HMAC. 11173 * 11174 * @static 11175 * 11176 * @example 11177 * 11178 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11179 */ 11180 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11181 }(Math)); 11182 11183 11184 return CryptoJS.RIPEMD160; 11185 11186 })); 11187 }, { "./core": 53 }], 77: [function (require, module, exports) { 11188 ; (function (root, factory) { 11189 if (typeof exports === "object") { 11190 // CommonJS 11191 module.exports = exports = factory(require("./core")); 11192 } 11193 else if (typeof define === "function" && define.amd) { 11194 // AMD 11195 define(["./core"], factory); 11196 } 11197 else { 11198 // Global (browser) 11199 factory(root.CryptoJS); 11200 } 11201 }(this, function (CryptoJS) { 11202 11203 (function () { 11204 // Shortcuts 11205 var C = CryptoJS; 11206 var C_lib = C.lib; 11207 var WordArray = C_lib.WordArray; 11208 var Hasher = C_lib.Hasher; 11209 var C_algo = C.algo; 11210 11211 // Reusable object 11212 var W = []; 11213 11214 /** 11215 * SHA-1 hash algorithm. 11216 */ 11217 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11218 _doReset: function () { 11219 this._hash = new WordArray.init([ 11220 0x67452301, 0xefcdab89, 11221 0x98badcfe, 0x10325476, 11222 0xc3d2e1f0 11223 ]); 11224 }, 11225 11226 _doProcessBlock: function (M, offset) { 11227 // Shortcut 11228 var H = this._hash.words; 11229 11230 // Working variables 11231 var a = H[0]; 11232 var b = H[1]; 11233 var c = H[2]; 11234 var d = H[3]; 11235 var e = H[4]; 11236 11237 // Computation 11238 for (var i = 0; i < 80; i++) { 11239 if (i < 16) { 11240 W[i] = M[offset + i] | 0; 11241 } else { 11242 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11243 W[i] = (n << 1) | (n >>> 31); 11244 } 11245 11246 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11247 if (i < 20) { 11248 t += ((b & c) | (~b & d)) + 0x5a827999; 11249 } else if (i < 40) { 11250 t += (b ^ c ^ d) + 0x6ed9eba1; 11251 } else if (i < 60) { 11252 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11253 } else /* if (i < 80) */ { 11254 t += (b ^ c ^ d) - 0x359d3e2a; 11255 } 11256 11257 e = d; 11258 d = c; 11259 c = (b << 30) | (b >>> 2); 11260 b = a; 11261 a = t; 11262 } 11263 11264 // Intermediate hash value 11265 H[0] = (H[0] + a) | 0; 11266 H[1] = (H[1] + b) | 0; 11267 H[2] = (H[2] + c) | 0; 11268 H[3] = (H[3] + d) | 0; 11269 H[4] = (H[4] + e) | 0; 11270 }, 11271 11272 _doFinalize: function () { 11273 // Shortcuts 11274 var data = this._data; 11275 var dataWords = data.words; 11276 11277 var nBitsTotal = this._nDataBytes * 8; 11278 var nBitsLeft = data.sigBytes * 8; 11279 11280 // Add padding 11281 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11282 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11283 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11284 data.sigBytes = dataWords.length * 4; 11285 11286 // Hash final blocks 11287 this._process(); 11288 11289 // Return final computed hash 11290 return this._hash; 11291 }, 11292 11293 clone: function () { 11294 var clone = Hasher.clone.call(this); 11295 clone._hash = this._hash.clone(); 11296 11297 return clone; 11298 } 11299 }); 11300 11301 /** 11302 * Shortcut function to the hasher's object interface. 11303 * 11304 * @param {WordArray|string} message The message to hash. 11305 * 11306 * @return {WordArray} The hash. 11307 * 11308 * @static 11309 * 11310 * @example 11311 * 11312 * var hash = CryptoJS.SHA1('message'); 11313 * var hash = CryptoJS.SHA1(wordArray); 11314 */ 11315 C.SHA1 = Hasher._createHelper(SHA1); 11316 11317 /** 11318 * Shortcut function to the HMAC's object interface. 11319 * 11320 * @param {WordArray|string} message The message to hash. 11321 * @param {WordArray|string} key The secret key. 11322 * 11323 * @return {WordArray} The HMAC. 11324 * 11325 * @static 11326 * 11327 * @example 11328 * 11329 * var hmac = CryptoJS.HmacSHA1(message, key); 11330 */ 11331 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11332 }()); 11333 11334 11335 return CryptoJS.SHA1; 11336 11337 })); 11338 }, { "./core": 53 }], 78: [function (require, module, exports) { 11339 ; (function (root, factory, undef) { 11340 if (typeof exports === "object") { 11341 // CommonJS 11342 module.exports = exports = factory(require("./core"), require("./sha256")); 11343 } 11344 else if (typeof define === "function" && define.amd) { 11345 // AMD 11346 define(["./core", "./sha256"], factory); 11347 } 11348 else { 11349 // Global (browser) 11350 factory(root.CryptoJS); 11351 } 11352 }(this, function (CryptoJS) { 11353 11354 (function () { 11355 // Shortcuts 11356 var C = CryptoJS; 11357 var C_lib = C.lib; 11358 var WordArray = C_lib.WordArray; 11359 var C_algo = C.algo; 11360 var SHA256 = C_algo.SHA256; 11361 11362 /** 11363 * SHA-224 hash algorithm. 11364 */ 11365 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11366 _doReset: function () { 11367 this._hash = new WordArray.init([ 11368 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11369 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11370 ]); 11371 }, 11372 11373 _doFinalize: function () { 11374 var hash = SHA256._doFinalize.call(this); 11375 11376 hash.sigBytes -= 4; 11377 11378 return hash; 11379 } 11380 }); 11381 11382 /** 11383 * Shortcut function to the hasher's object interface. 11384 * 11385 * @param {WordArray|string} message The message to hash. 11386 * 11387 * @return {WordArray} The hash. 11388 * 11389 * @static 11390 * 11391 * @example 11392 * 11393 * var hash = CryptoJS.SHA224('message'); 11394 * var hash = CryptoJS.SHA224(wordArray); 11395 */ 11396 C.SHA224 = SHA256._createHelper(SHA224); 11397 11398 /** 11399 * Shortcut function to the HMAC's object interface. 11400 * 11401 * @param {WordArray|string} message The message to hash. 11402 * @param {WordArray|string} key The secret key. 11403 * 11404 * @return {WordArray} The HMAC. 11405 * 11406 * @static 11407 * 11408 * @example 11409 * 11410 * var hmac = CryptoJS.HmacSHA224(message, key); 11411 */ 11412 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11413 }()); 11414 11415 11416 return CryptoJS.SHA224; 11417 11418 })); 11419 }, { "./core": 53, "./sha256": 79 }], 79: [function (require, module, exports) { 11420 ; (function (root, factory) { 11421 if (typeof exports === "object") { 11422 // CommonJS 11423 module.exports = exports = factory(require("./core")); 11424 } 11425 else if (typeof define === "function" && define.amd) { 11426 // AMD 11427 define(["./core"], factory); 11428 } 11429 else { 11430 // Global (browser) 11431 factory(root.CryptoJS); 11432 } 11433 }(this, function (CryptoJS) { 11434 11435 (function (Math) { 11436 // Shortcuts 11437 var C = CryptoJS; 11438 var C_lib = C.lib; 11439 var WordArray = C_lib.WordArray; 11440 var Hasher = C_lib.Hasher; 11441 var C_algo = C.algo; 11442 11443 // Initialization and round constants tables 11444 var H = []; 11445 var K = []; 11446 11447 // Compute constants 11448 (function () { 11449 function isPrime(n) { 11450 var sqrtN = Math.sqrt(n); 11451 for (var factor = 2; factor <= sqrtN; factor++) { 11452 if (!(n % factor)) { 11453 return false; 11454 } 11455 } 11456 11457 return true; 11458 } 11459 11460 function getFractionalBits(n) { 11461 return ((n - (n | 0)) * 0x100000000) | 0; 11462 } 11463 11464 var n = 2; 11465 var nPrime = 0; 11466 while (nPrime < 64) { 11467 if (isPrime(n)) { 11468 if (nPrime < 8) { 11469 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11470 } 11471 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11472 11473 nPrime++; 11474 } 11475 11476 n++; 11477 } 11478 }()); 11479 11480 // Reusable object 11481 var W = []; 11482 11483 /** 11484 * SHA-256 hash algorithm. 11485 */ 11486 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11487 _doReset: function () { 11488 this._hash = new WordArray.init(H.slice(0)); 11489 }, 11490 11491 _doProcessBlock: function (M, offset) { 11492 // Shortcut 11493 var H = this._hash.words; 11494 11495 // Working variables 11496 var a = H[0]; 11497 var b = H[1]; 11498 var c = H[2]; 11499 var d = H[3]; 11500 var e = H[4]; 11501 var f = H[5]; 11502 var g = H[6]; 11503 var h = H[7]; 11504 11505 // Computation 11506 for (var i = 0; i < 64; i++) { 11507 if (i < 16) { 11508 W[i] = M[offset + i] | 0; 11509 } else { 11510 var gamma0x = W[i - 15]; 11511 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11512 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11513 (gamma0x >>> 3); 11514 11515 var gamma1x = W[i - 2]; 11516 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11517 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11518 (gamma1x >>> 10); 11519 11520 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11521 } 11522 11523 var ch = (e & f) ^ (~e & g); 11524 var maj = (a & b) ^ (a & c) ^ (b & c); 11525 11526 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11527 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11528 11529 var t1 = h + sigma1 + ch + K[i] + W[i]; 11530 var t2 = sigma0 + maj; 11531 11532 h = g; 11533 g = f; 11534 f = e; 11535 e = (d + t1) | 0; 11536 d = c; 11537 c = b; 11538 b = a; 11539 a = (t1 + t2) | 0; 11540 } 11541 11542 // Intermediate hash value 11543 H[0] = (H[0] + a) | 0; 11544 H[1] = (H[1] + b) | 0; 11545 H[2] = (H[2] + c) | 0; 11546 H[3] = (H[3] + d) | 0; 11547 H[4] = (H[4] + e) | 0; 11548 H[5] = (H[5] + f) | 0; 11549 H[6] = (H[6] + g) | 0; 11550 H[7] = (H[7] + h) | 0; 11551 }, 11552 11553 _doFinalize: function () { 11554 // Shortcuts 11555 var data = this._data; 11556 var dataWords = data.words; 11557 11558 var nBitsTotal = this._nDataBytes * 8; 11559 var nBitsLeft = data.sigBytes * 8; 11560 11561 // Add padding 11562 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11563 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11564 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11565 data.sigBytes = dataWords.length * 4; 11566 11567 // Hash final blocks 11568 this._process(); 11569 11570 // Return final computed hash 11571 return this._hash; 11572 }, 11573 11574 clone: function () { 11575 var clone = Hasher.clone.call(this); 11576 clone._hash = this._hash.clone(); 11577 11578 return clone; 11579 } 11580 }); 11581 11582 /** 11583 * Shortcut function to the hasher's object interface. 11584 * 11585 * @param {WordArray|string} message The message to hash. 11586 * 11587 * @return {WordArray} The hash. 11588 * 11589 * @static 11590 * 11591 * @example 11592 * 11593 * var hash = CryptoJS.SHA256('message'); 11594 * var hash = CryptoJS.SHA256(wordArray); 11595 */ 11596 C.SHA256 = Hasher._createHelper(SHA256); 11597 11598 /** 11599 * Shortcut function to the HMAC's object interface. 11600 * 11601 * @param {WordArray|string} message The message to hash. 11602 * @param {WordArray|string} key The secret key. 11603 * 11604 * @return {WordArray} The HMAC. 11605 * 11606 * @static 11607 * 11608 * @example 11609 * 11610 * var hmac = CryptoJS.HmacSHA256(message, key); 11611 */ 11612 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11613 }(Math)); 11614 11615 11616 return CryptoJS.SHA256; 11617 11618 })); 11619 }, { "./core": 53 }], 80: [function (require, module, exports) { 11620 ; (function (root, factory, undef) { 11621 if (typeof exports === "object") { 11622 // CommonJS 11623 module.exports = exports = factory(require("./core"), require("./x64-core")); 11624 } 11625 else if (typeof define === "function" && define.amd) { 11626 // AMD 11627 define(["./core", "./x64-core"], factory); 11628 } 11629 else { 11630 // Global (browser) 11631 factory(root.CryptoJS); 11632 } 11633 }(this, function (CryptoJS) { 11634 11635 (function (Math) { 11636 // Shortcuts 11637 var C = CryptoJS; 11638 var C_lib = C.lib; 11639 var WordArray = C_lib.WordArray; 11640 var Hasher = C_lib.Hasher; 11641 var C_x64 = C.x64; 11642 var X64Word = C_x64.Word; 11643 var C_algo = C.algo; 11644 11645 // Constants tables 11646 var RHO_OFFSETS = []; 11647 var PI_INDEXES = []; 11648 var ROUND_CONSTANTS = []; 11649 11650 // Compute Constants 11651 (function () { 11652 // Compute rho offset constants 11653 var x = 1, y = 0; 11654 for (var t = 0; t < 24; t++) { 11655 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11656 11657 var newX = y % 5; 11658 var newY = (2 * x + 3 * y) % 5; 11659 x = newX; 11660 y = newY; 11661 } 11662 11663 // Compute pi index constants 11664 for (var x = 0; x < 5; x++) { 11665 for (var y = 0; y < 5; y++) { 11666 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11667 } 11668 } 11669 11670 // Compute round constants 11671 var LFSR = 0x01; 11672 for (var i = 0; i < 24; i++) { 11673 var roundConstantMsw = 0; 11674 var roundConstantLsw = 0; 11675 11676 for (var j = 0; j < 7; j++) { 11677 if (LFSR & 0x01) { 11678 var bitPosition = (1 << j) - 1; 11679 if (bitPosition < 32) { 11680 roundConstantLsw ^= 1 << bitPosition; 11681 } else /* if (bitPosition >= 32) */ { 11682 roundConstantMsw ^= 1 << (bitPosition - 32); 11683 } 11684 } 11685 11686 // Compute next LFSR 11687 if (LFSR & 0x80) { 11688 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11689 LFSR = (LFSR << 1) ^ 0x71; 11690 } else { 11691 LFSR <<= 1; 11692 } 11693 } 11694 11695 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11696 } 11697 }()); 11698 11699 // Reusable objects for temporary values 11700 var T = []; 11701 (function () { 11702 for (var i = 0; i < 25; i++) { 11703 T[i] = X64Word.create(); 11704 } 11705 }()); 11706 11707 /** 11708 * SHA-3 hash algorithm. 11709 */ 11710 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11711 /** 11712 * Configuration options. 11713 * 11714 * @property {number} outputLength 11715 * The desired number of bits in the output hash. 11716 * Only values permitted are: 224, 256, 384, 512. 11717 * Default: 512 11718 */ 11719 cfg: Hasher.cfg.extend({ 11720 outputLength: 512 11721 }), 11722 11723 _doReset: function () { 11724 var state = this._state = [] 11725 for (var i = 0; i < 25; i++) { 11726 state[i] = new X64Word.init(); 11727 } 11728 11729 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11730 }, 11731 11732 _doProcessBlock: function (M, offset) { 11733 // Shortcuts 11734 var state = this._state; 11735 var nBlockSizeLanes = this.blockSize / 2; 11736 11737 // Absorb 11738 for (var i = 0; i < nBlockSizeLanes; i++) { 11739 // Shortcuts 11740 var M2i = M[offset + 2 * i]; 11741 var M2i1 = M[offset + 2 * i + 1]; 11742 11743 // Swap endian 11744 M2i = ( 11745 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11746 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11747 ); 11748 M2i1 = ( 11749 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11750 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11751 ); 11752 11753 // Absorb message into state 11754 var lane = state[i]; 11755 lane.high ^= M2i1; 11756 lane.low ^= M2i; 11757 } 11758 11759 // Rounds 11760 for (var round = 0; round < 24; round++) { 11761 // Theta 11762 for (var x = 0; x < 5; x++) { 11763 // Mix column lanes 11764 var tMsw = 0, tLsw = 0; 11765 for (var y = 0; y < 5; y++) { 11766 var lane = state[x + 5 * y]; 11767 tMsw ^= lane.high; 11768 tLsw ^= lane.low; 11769 } 11770 11771 // Temporary values 11772 var Tx = T[x]; 11773 Tx.high = tMsw; 11774 Tx.low = tLsw; 11775 } 11776 for (var x = 0; x < 5; x++) { 11777 // Shortcuts 11778 var Tx4 = T[(x + 4) % 5]; 11779 var Tx1 = T[(x + 1) % 5]; 11780 var Tx1Msw = Tx1.high; 11781 var Tx1Lsw = Tx1.low; 11782 11783 // Mix surrounding columns 11784 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11785 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11786 for (var y = 0; y < 5; y++) { 11787 var lane = state[x + 5 * y]; 11788 lane.high ^= tMsw; 11789 lane.low ^= tLsw; 11790 } 11791 } 11792 11793 // Rho Pi 11794 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11795 // Shortcuts 11796 var lane = state[laneIndex]; 11797 var laneMsw = lane.high; 11798 var laneLsw = lane.low; 11799 var rhoOffset = RHO_OFFSETS[laneIndex]; 11800 11801 // Rotate lanes 11802 if (rhoOffset < 32) { 11803 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11804 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11805 } else /* if (rhoOffset >= 32) */ { 11806 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11807 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11808 } 11809 11810 // Transpose lanes 11811 var TPiLane = T[PI_INDEXES[laneIndex]]; 11812 TPiLane.high = tMsw; 11813 TPiLane.low = tLsw; 11814 } 11815 11816 // Rho pi at x = y = 0 11817 var T0 = T[0]; 11818 var state0 = state[0]; 11819 T0.high = state0.high; 11820 T0.low = state0.low; 11821 11822 // Chi 11823 for (var x = 0; x < 5; x++) { 11824 for (var y = 0; y < 5; y++) { 11825 // Shortcuts 11826 var laneIndex = x + 5 * y; 11827 var lane = state[laneIndex]; 11828 var TLane = T[laneIndex]; 11829 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 11830 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 11831 11832 // Mix rows 11833 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 11834 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 11835 } 11836 } 11837 11838 // Iota 11839 var lane = state[0]; 11840 var roundConstant = ROUND_CONSTANTS[round]; 11841 lane.high ^= roundConstant.high; 11842 lane.low ^= roundConstant.low;; 11843 } 11844 }, 11845 11846 _doFinalize: function () { 11847 // Shortcuts 11848 var data = this._data; 11849 var dataWords = data.words; 11850 var nBitsTotal = this._nDataBytes * 8; 11851 var nBitsLeft = data.sigBytes * 8; 11852 var blockSizeBits = this.blockSize * 32; 11853 11854 // Add padding 11855 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 11856 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 11857 data.sigBytes = dataWords.length * 4; 11858 11859 // Hash final blocks 11860 this._process(); 11861 11862 // Shortcuts 11863 var state = this._state; 11864 var outputLengthBytes = this.cfg.outputLength / 8; 11865 var outputLengthLanes = outputLengthBytes / 8; 11866 11867 // Squeeze 11868 var hashWords = []; 11869 for (var i = 0; i < outputLengthLanes; i++) { 11870 // Shortcuts 11871 var lane = state[i]; 11872 var laneMsw = lane.high; 11873 var laneLsw = lane.low; 11874 11875 // Swap endian 11876 laneMsw = ( 11877 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 11878 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 11879 ); 11880 laneLsw = ( 11881 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 11882 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 11883 ); 11884 11885 // Squeeze state to retrieve hash 11886 hashWords.push(laneLsw); 11887 hashWords.push(laneMsw); 11888 } 11889 11890 // Return final computed hash 11891 return new WordArray.init(hashWords, outputLengthBytes); 11892 }, 11893 11894 clone: function () { 11895 var clone = Hasher.clone.call(this); 11896 11897 var state = clone._state = this._state.slice(0); 11898 for (var i = 0; i < 25; i++) { 11899 state[i] = state[i].clone(); 11900 } 11901 11902 return clone; 11903 } 11904 }); 11905 11906 /** 11907 * Shortcut function to the hasher's object interface. 11908 * 11909 * @param {WordArray|string} message The message to hash. 11910 * 11911 * @return {WordArray} The hash. 11912 * 11913 * @static 11914 * 11915 * @example 11916 * 11917 * var hash = CryptoJS.SHA3('message'); 11918 * var hash = CryptoJS.SHA3(wordArray); 11919 */ 11920 C.SHA3 = Hasher._createHelper(SHA3); 11921 11922 /** 11923 * Shortcut function to the HMAC's object interface. 11924 * 11925 * @param {WordArray|string} message The message to hash. 11926 * @param {WordArray|string} key The secret key. 11927 * 11928 * @return {WordArray} The HMAC. 11929 * 11930 * @static 11931 * 11932 * @example 11933 * 11934 * var hmac = CryptoJS.HmacSHA3(message, key); 11935 */ 11936 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 11937 }(Math)); 11938 11939 11940 return CryptoJS.SHA3; 11941 11942 })); 11943 }, { "./core": 53, "./x64-core": 84 }], 81: [function (require, module, exports) { 11944 ; (function (root, factory, undef) { 11945 if (typeof exports === "object") { 11946 // CommonJS 11947 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 11948 } 11949 else if (typeof define === "function" && define.amd) { 11950 // AMD 11951 define(["./core", "./x64-core", "./sha512"], factory); 11952 } 11953 else { 11954 // Global (browser) 11955 factory(root.CryptoJS); 11956 } 11957 }(this, function (CryptoJS) { 11958 11959 (function () { 11960 // Shortcuts 11961 var C = CryptoJS; 11962 var C_x64 = C.x64; 11963 var X64Word = C_x64.Word; 11964 var X64WordArray = C_x64.WordArray; 11965 var C_algo = C.algo; 11966 var SHA512 = C_algo.SHA512; 11967 11968 /** 11969 * SHA-384 hash algorithm. 11970 */ 11971 var SHA384 = C_algo.SHA384 = SHA512.extend({ 11972 _doReset: function () { 11973 this._hash = new X64WordArray.init([ 11974 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 11975 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 11976 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 11977 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 11978 ]); 11979 }, 11980 11981 _doFinalize: function () { 11982 var hash = SHA512._doFinalize.call(this); 11983 11984 hash.sigBytes -= 16; 11985 11986 return hash; 11987 } 11988 }); 11989 11990 /** 11991 * Shortcut function to the hasher's object interface. 11992 * 11993 * @param {WordArray|string} message The message to hash. 11994 * 11995 * @return {WordArray} The hash. 11996 * 11997 * @static 11998 * 11999 * @example 12000 * 12001 * var hash = CryptoJS.SHA384('message'); 12002 * var hash = CryptoJS.SHA384(wordArray); 12003 */ 12004 C.SHA384 = SHA512._createHelper(SHA384); 12005 12006 /** 12007 * Shortcut function to the HMAC's object interface. 12008 * 12009 * @param {WordArray|string} message The message to hash. 12010 * @param {WordArray|string} key The secret key. 12011 * 12012 * @return {WordArray} The HMAC. 12013 * 12014 * @static 12015 * 12016 * @example 12017 * 12018 * var hmac = CryptoJS.HmacSHA384(message, key); 12019 */ 12020 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 12021 }()); 12022 12023 12024 return CryptoJS.SHA384; 12025 12026 })); 12027 }, { "./core": 53, "./sha512": 82, "./x64-core": 84 }], 82: [function (require, module, exports) { 12028 ; (function (root, factory, undef) { 12029 if (typeof exports === "object") { 12030 // CommonJS 12031 module.exports = exports = factory(require("./core"), require("./x64-core")); 12032 } 12033 else if (typeof define === "function" && define.amd) { 12034 // AMD 12035 define(["./core", "./x64-core"], factory); 12036 } 12037 else { 12038 // Global (browser) 12039 factory(root.CryptoJS); 12040 } 12041 }(this, function (CryptoJS) { 12042 12043 (function () { 12044 // Shortcuts 12045 var C = CryptoJS; 12046 var C_lib = C.lib; 12047 var Hasher = C_lib.Hasher; 12048 var C_x64 = C.x64; 12049 var X64Word = C_x64.Word; 12050 var X64WordArray = C_x64.WordArray; 12051 var C_algo = C.algo; 12052 12053 function X64Word_create() { 12054 return X64Word.create.apply(X64Word, arguments); 12055 } 12056 12057 // Constants 12058 var K = [ 12059 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12060 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12061 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12062 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12063 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12064 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12065 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12066 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12067 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12068 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12069 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12070 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12071 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12072 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12073 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12074 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12075 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12076 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12077 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12078 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12079 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12080 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12081 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12082 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12083 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12084 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12085 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12086 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12087 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12088 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12089 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12090 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12091 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12092 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12093 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12094 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12095 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12096 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12097 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12098 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12099 ]; 12100 12101 // Reusable objects 12102 var W = []; 12103 (function () { 12104 for (var i = 0; i < 80; i++) { 12105 W[i] = X64Word_create(); 12106 } 12107 }()); 12108 12109 /** 12110 * SHA-512 hash algorithm. 12111 */ 12112 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12113 _doReset: function () { 12114 this._hash = new X64WordArray.init([ 12115 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12116 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12117 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12118 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12119 ]); 12120 }, 12121 12122 _doProcessBlock: function (M, offset) { 12123 // Shortcuts 12124 var H = this._hash.words; 12125 12126 var H0 = H[0]; 12127 var H1 = H[1]; 12128 var H2 = H[2]; 12129 var H3 = H[3]; 12130 var H4 = H[4]; 12131 var H5 = H[5]; 12132 var H6 = H[6]; 12133 var H7 = H[7]; 12134 12135 var H0h = H0.high; 12136 var H0l = H0.low; 12137 var H1h = H1.high; 12138 var H1l = H1.low; 12139 var H2h = H2.high; 12140 var H2l = H2.low; 12141 var H3h = H3.high; 12142 var H3l = H3.low; 12143 var H4h = H4.high; 12144 var H4l = H4.low; 12145 var H5h = H5.high; 12146 var H5l = H5.low; 12147 var H6h = H6.high; 12148 var H6l = H6.low; 12149 var H7h = H7.high; 12150 var H7l = H7.low; 12151 12152 // Working variables 12153 var ah = H0h; 12154 var al = H0l; 12155 var bh = H1h; 12156 var bl = H1l; 12157 var ch = H2h; 12158 var cl = H2l; 12159 var dh = H3h; 12160 var dl = H3l; 12161 var eh = H4h; 12162 var el = H4l; 12163 var fh = H5h; 12164 var fl = H5l; 12165 var gh = H6h; 12166 var gl = H6l; 12167 var hh = H7h; 12168 var hl = H7l; 12169 12170 // Rounds 12171 for (var i = 0; i < 80; i++) { 12172 // Shortcut 12173 var Wi = W[i]; 12174 12175 // Extend message 12176 if (i < 16) { 12177 var Wih = Wi.high = M[offset + i * 2] | 0; 12178 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12179 } else { 12180 // Gamma0 12181 var gamma0x = W[i - 15]; 12182 var gamma0xh = gamma0x.high; 12183 var gamma0xl = gamma0x.low; 12184 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12185 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12186 12187 // Gamma1 12188 var gamma1x = W[i - 2]; 12189 var gamma1xh = gamma1x.high; 12190 var gamma1xl = gamma1x.low; 12191 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12192 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12193 12194 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12195 var Wi7 = W[i - 7]; 12196 var Wi7h = Wi7.high; 12197 var Wi7l = Wi7.low; 12198 12199 var Wi16 = W[i - 16]; 12200 var Wi16h = Wi16.high; 12201 var Wi16l = Wi16.low; 12202 12203 var Wil = gamma0l + Wi7l; 12204 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12205 var Wil = Wil + gamma1l; 12206 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12207 var Wil = Wil + Wi16l; 12208 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12209 12210 Wi.high = Wih; 12211 Wi.low = Wil; 12212 } 12213 12214 var chh = (eh & fh) ^ (~eh & gh); 12215 var chl = (el & fl) ^ (~el & gl); 12216 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12217 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12218 12219 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12220 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12221 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12222 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12223 12224 // t1 = h + sigma1 + ch + K[i] + W[i] 12225 var Ki = K[i]; 12226 var Kih = Ki.high; 12227 var Kil = Ki.low; 12228 12229 var t1l = hl + sigma1l; 12230 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12231 var t1l = t1l + chl; 12232 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12233 var t1l = t1l + Kil; 12234 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12235 var t1l = t1l + Wil; 12236 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12237 12238 // t2 = sigma0 + maj 12239 var t2l = sigma0l + majl; 12240 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12241 12242 // Update working variables 12243 hh = gh; 12244 hl = gl; 12245 gh = fh; 12246 gl = fl; 12247 fh = eh; 12248 fl = el; 12249 el = (dl + t1l) | 0; 12250 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12251 dh = ch; 12252 dl = cl; 12253 ch = bh; 12254 cl = bl; 12255 bh = ah; 12256 bl = al; 12257 al = (t1l + t2l) | 0; 12258 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12259 } 12260 12261 // Intermediate hash value 12262 H0l = H0.low = (H0l + al); 12263 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12264 H1l = H1.low = (H1l + bl); 12265 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12266 H2l = H2.low = (H2l + cl); 12267 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12268 H3l = H3.low = (H3l + dl); 12269 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12270 H4l = H4.low = (H4l + el); 12271 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12272 H5l = H5.low = (H5l + fl); 12273 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12274 H6l = H6.low = (H6l + gl); 12275 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12276 H7l = H7.low = (H7l + hl); 12277 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12278 }, 12279 12280 _doFinalize: function () { 12281 // Shortcuts 12282 var data = this._data; 12283 var dataWords = data.words; 12284 12285 var nBitsTotal = this._nDataBytes * 8; 12286 var nBitsLeft = data.sigBytes * 8; 12287 12288 // Add padding 12289 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12290 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12291 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12292 data.sigBytes = dataWords.length * 4; 12293 12294 // Hash final blocks 12295 this._process(); 12296 12297 // Convert hash to 32-bit word array before returning 12298 var hash = this._hash.toX32(); 12299 12300 // Return final computed hash 12301 return hash; 12302 }, 12303 12304 clone: function () { 12305 var clone = Hasher.clone.call(this); 12306 clone._hash = this._hash.clone(); 12307 12308 return clone; 12309 }, 12310 12311 blockSize: 1024 / 32 12312 }); 12313 12314 /** 12315 * Shortcut function to the hasher's object interface. 12316 * 12317 * @param {WordArray|string} message The message to hash. 12318 * 12319 * @return {WordArray} The hash. 12320 * 12321 * @static 12322 * 12323 * @example 12324 * 12325 * var hash = CryptoJS.SHA512('message'); 12326 * var hash = CryptoJS.SHA512(wordArray); 12327 */ 12328 C.SHA512 = Hasher._createHelper(SHA512); 12329 12330 /** 12331 * Shortcut function to the HMAC's object interface. 12332 * 12333 * @param {WordArray|string} message The message to hash. 12334 * @param {WordArray|string} key The secret key. 12335 * 12336 * @return {WordArray} The HMAC. 12337 * 12338 * @static 12339 * 12340 * @example 12341 * 12342 * var hmac = CryptoJS.HmacSHA512(message, key); 12343 */ 12344 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12345 }()); 12346 12347 12348 return CryptoJS.SHA512; 12349 12350 })); 12351 }, { "./core": 53, "./x64-core": 84 }], 83: [function (require, module, exports) { 12352 ; (function (root, factory, undef) { 12353 if (typeof exports === "object") { 12354 // CommonJS 12355 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12356 } 12357 else if (typeof define === "function" && define.amd) { 12358 // AMD 12359 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12360 } 12361 else { 12362 // Global (browser) 12363 factory(root.CryptoJS); 12364 } 12365 }(this, function (CryptoJS) { 12366 12367 (function () { 12368 // Shortcuts 12369 var C = CryptoJS; 12370 var C_lib = C.lib; 12371 var WordArray = C_lib.WordArray; 12372 var BlockCipher = C_lib.BlockCipher; 12373 var C_algo = C.algo; 12374 12375 // Permuted Choice 1 constants 12376 var PC1 = [ 12377 57, 49, 41, 33, 25, 17, 9, 1, 12378 58, 50, 42, 34, 26, 18, 10, 2, 12379 59, 51, 43, 35, 27, 19, 11, 3, 12380 60, 52, 44, 36, 63, 55, 47, 39, 12381 31, 23, 15, 7, 62, 54, 46, 38, 12382 30, 22, 14, 6, 61, 53, 45, 37, 12383 29, 21, 13, 5, 28, 20, 12, 4 12384 ]; 12385 12386 // Permuted Choice 2 constants 12387 var PC2 = [ 12388 14, 17, 11, 24, 1, 5, 12389 3, 28, 15, 6, 21, 10, 12390 23, 19, 12, 4, 26, 8, 12391 16, 7, 27, 20, 13, 2, 12392 41, 52, 31, 37, 47, 55, 12393 30, 40, 51, 45, 33, 48, 12394 44, 49, 39, 56, 34, 53, 12395 46, 42, 50, 36, 29, 32 12396 ]; 12397 12398 // Cumulative bit shift constants 12399 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12400 12401 // SBOXes and round permutation constants 12402 var SBOX_P = [ 12403 { 12404 0x0: 0x808200, 12405 0x10000000: 0x8000, 12406 0x20000000: 0x808002, 12407 0x30000000: 0x2, 12408 0x40000000: 0x200, 12409 0x50000000: 0x808202, 12410 0x60000000: 0x800202, 12411 0x70000000: 0x800000, 12412 0x80000000: 0x202, 12413 0x90000000: 0x800200, 12414 0xa0000000: 0x8200, 12415 0xb0000000: 0x808000, 12416 0xc0000000: 0x8002, 12417 0xd0000000: 0x800002, 12418 0xe0000000: 0x0, 12419 0xf0000000: 0x8202, 12420 0x8000000: 0x0, 12421 0x18000000: 0x808202, 12422 0x28000000: 0x8202, 12423 0x38000000: 0x8000, 12424 0x48000000: 0x808200, 12425 0x58000000: 0x200, 12426 0x68000000: 0x808002, 12427 0x78000000: 0x2, 12428 0x88000000: 0x800200, 12429 0x98000000: 0x8200, 12430 0xa8000000: 0x808000, 12431 0xb8000000: 0x800202, 12432 0xc8000000: 0x800002, 12433 0xd8000000: 0x8002, 12434 0xe8000000: 0x202, 12435 0xf8000000: 0x800000, 12436 0x1: 0x8000, 12437 0x10000001: 0x2, 12438 0x20000001: 0x808200, 12439 0x30000001: 0x800000, 12440 0x40000001: 0x808002, 12441 0x50000001: 0x8200, 12442 0x60000001: 0x200, 12443 0x70000001: 0x800202, 12444 0x80000001: 0x808202, 12445 0x90000001: 0x808000, 12446 0xa0000001: 0x800002, 12447 0xb0000001: 0x8202, 12448 0xc0000001: 0x202, 12449 0xd0000001: 0x800200, 12450 0xe0000001: 0x8002, 12451 0xf0000001: 0x0, 12452 0x8000001: 0x808202, 12453 0x18000001: 0x808000, 12454 0x28000001: 0x800000, 12455 0x38000001: 0x200, 12456 0x48000001: 0x8000, 12457 0x58000001: 0x800002, 12458 0x68000001: 0x2, 12459 0x78000001: 0x8202, 12460 0x88000001: 0x8002, 12461 0x98000001: 0x800202, 12462 0xa8000001: 0x202, 12463 0xb8000001: 0x808200, 12464 0xc8000001: 0x800200, 12465 0xd8000001: 0x0, 12466 0xe8000001: 0x8200, 12467 0xf8000001: 0x808002 12468 }, 12469 { 12470 0x0: 0x40084010, 12471 0x1000000: 0x4000, 12472 0x2000000: 0x80000, 12473 0x3000000: 0x40080010, 12474 0x4000000: 0x40000010, 12475 0x5000000: 0x40084000, 12476 0x6000000: 0x40004000, 12477 0x7000000: 0x10, 12478 0x8000000: 0x84000, 12479 0x9000000: 0x40004010, 12480 0xa000000: 0x40000000, 12481 0xb000000: 0x84010, 12482 0xc000000: 0x80010, 12483 0xd000000: 0x0, 12484 0xe000000: 0x4010, 12485 0xf000000: 0x40080000, 12486 0x800000: 0x40004000, 12487 0x1800000: 0x84010, 12488 0x2800000: 0x10, 12489 0x3800000: 0x40004010, 12490 0x4800000: 0x40084010, 12491 0x5800000: 0x40000000, 12492 0x6800000: 0x80000, 12493 0x7800000: 0x40080010, 12494 0x8800000: 0x80010, 12495 0x9800000: 0x0, 12496 0xa800000: 0x4000, 12497 0xb800000: 0x40080000, 12498 0xc800000: 0x40000010, 12499 0xd800000: 0x84000, 12500 0xe800000: 0x40084000, 12501 0xf800000: 0x4010, 12502 0x10000000: 0x0, 12503 0x11000000: 0x40080010, 12504 0x12000000: 0x40004010, 12505 0x13000000: 0x40084000, 12506 0x14000000: 0x40080000, 12507 0x15000000: 0x10, 12508 0x16000000: 0x84010, 12509 0x17000000: 0x4000, 12510 0x18000000: 0x4010, 12511 0x19000000: 0x80000, 12512 0x1a000000: 0x80010, 12513 0x1b000000: 0x40000010, 12514 0x1c000000: 0x84000, 12515 0x1d000000: 0x40004000, 12516 0x1e000000: 0x40000000, 12517 0x1f000000: 0x40084010, 12518 0x10800000: 0x84010, 12519 0x11800000: 0x80000, 12520 0x12800000: 0x40080000, 12521 0x13800000: 0x4000, 12522 0x14800000: 0x40004000, 12523 0x15800000: 0x40084010, 12524 0x16800000: 0x10, 12525 0x17800000: 0x40000000, 12526 0x18800000: 0x40084000, 12527 0x19800000: 0x40000010, 12528 0x1a800000: 0x40004010, 12529 0x1b800000: 0x80010, 12530 0x1c800000: 0x0, 12531 0x1d800000: 0x4010, 12532 0x1e800000: 0x40080010, 12533 0x1f800000: 0x84000 12534 }, 12535 { 12536 0x0: 0x104, 12537 0x100000: 0x0, 12538 0x200000: 0x4000100, 12539 0x300000: 0x10104, 12540 0x400000: 0x10004, 12541 0x500000: 0x4000004, 12542 0x600000: 0x4010104, 12543 0x700000: 0x4010000, 12544 0x800000: 0x4000000, 12545 0x900000: 0x4010100, 12546 0xa00000: 0x10100, 12547 0xb00000: 0x4010004, 12548 0xc00000: 0x4000104, 12549 0xd00000: 0x10000, 12550 0xe00000: 0x4, 12551 0xf00000: 0x100, 12552 0x80000: 0x4010100, 12553 0x180000: 0x4010004, 12554 0x280000: 0x0, 12555 0x380000: 0x4000100, 12556 0x480000: 0x4000004, 12557 0x580000: 0x10000, 12558 0x680000: 0x10004, 12559 0x780000: 0x104, 12560 0x880000: 0x4, 12561 0x980000: 0x100, 12562 0xa80000: 0x4010000, 12563 0xb80000: 0x10104, 12564 0xc80000: 0x10100, 12565 0xd80000: 0x4000104, 12566 0xe80000: 0x4010104, 12567 0xf80000: 0x4000000, 12568 0x1000000: 0x4010100, 12569 0x1100000: 0x10004, 12570 0x1200000: 0x10000, 12571 0x1300000: 0x4000100, 12572 0x1400000: 0x100, 12573 0x1500000: 0x4010104, 12574 0x1600000: 0x4000004, 12575 0x1700000: 0x0, 12576 0x1800000: 0x4000104, 12577 0x1900000: 0x4000000, 12578 0x1a00000: 0x4, 12579 0x1b00000: 0x10100, 12580 0x1c00000: 0x4010000, 12581 0x1d00000: 0x104, 12582 0x1e00000: 0x10104, 12583 0x1f00000: 0x4010004, 12584 0x1080000: 0x4000000, 12585 0x1180000: 0x104, 12586 0x1280000: 0x4010100, 12587 0x1380000: 0x0, 12588 0x1480000: 0x10004, 12589 0x1580000: 0x4000100, 12590 0x1680000: 0x100, 12591 0x1780000: 0x4010004, 12592 0x1880000: 0x10000, 12593 0x1980000: 0x4010104, 12594 0x1a80000: 0x10104, 12595 0x1b80000: 0x4000004, 12596 0x1c80000: 0x4000104, 12597 0x1d80000: 0x4010000, 12598 0x1e80000: 0x4, 12599 0x1f80000: 0x10100 12600 }, 12601 { 12602 0x0: 0x80401000, 12603 0x10000: 0x80001040, 12604 0x20000: 0x401040, 12605 0x30000: 0x80400000, 12606 0x40000: 0x0, 12607 0x50000: 0x401000, 12608 0x60000: 0x80000040, 12609 0x70000: 0x400040, 12610 0x80000: 0x80000000, 12611 0x90000: 0x400000, 12612 0xa0000: 0x40, 12613 0xb0000: 0x80001000, 12614 0xc0000: 0x80400040, 12615 0xd0000: 0x1040, 12616 0xe0000: 0x1000, 12617 0xf0000: 0x80401040, 12618 0x8000: 0x80001040, 12619 0x18000: 0x40, 12620 0x28000: 0x80400040, 12621 0x38000: 0x80001000, 12622 0x48000: 0x401000, 12623 0x58000: 0x80401040, 12624 0x68000: 0x0, 12625 0x78000: 0x80400000, 12626 0x88000: 0x1000, 12627 0x98000: 0x80401000, 12628 0xa8000: 0x400000, 12629 0xb8000: 0x1040, 12630 0xc8000: 0x80000000, 12631 0xd8000: 0x400040, 12632 0xe8000: 0x401040, 12633 0xf8000: 0x80000040, 12634 0x100000: 0x400040, 12635 0x110000: 0x401000, 12636 0x120000: 0x80000040, 12637 0x130000: 0x0, 12638 0x140000: 0x1040, 12639 0x150000: 0x80400040, 12640 0x160000: 0x80401000, 12641 0x170000: 0x80001040, 12642 0x180000: 0x80401040, 12643 0x190000: 0x80000000, 12644 0x1a0000: 0x80400000, 12645 0x1b0000: 0x401040, 12646 0x1c0000: 0x80001000, 12647 0x1d0000: 0x400000, 12648 0x1e0000: 0x40, 12649 0x1f0000: 0x1000, 12650 0x108000: 0x80400000, 12651 0x118000: 0x80401040, 12652 0x128000: 0x0, 12653 0x138000: 0x401000, 12654 0x148000: 0x400040, 12655 0x158000: 0x80000000, 12656 0x168000: 0x80001040, 12657 0x178000: 0x40, 12658 0x188000: 0x80000040, 12659 0x198000: 0x1000, 12660 0x1a8000: 0x80001000, 12661 0x1b8000: 0x80400040, 12662 0x1c8000: 0x1040, 12663 0x1d8000: 0x80401000, 12664 0x1e8000: 0x400000, 12665 0x1f8000: 0x401040 12666 }, 12667 { 12668 0x0: 0x80, 12669 0x1000: 0x1040000, 12670 0x2000: 0x40000, 12671 0x3000: 0x20000000, 12672 0x4000: 0x20040080, 12673 0x5000: 0x1000080, 12674 0x6000: 0x21000080, 12675 0x7000: 0x40080, 12676 0x8000: 0x1000000, 12677 0x9000: 0x20040000, 12678 0xa000: 0x20000080, 12679 0xb000: 0x21040080, 12680 0xc000: 0x21040000, 12681 0xd000: 0x0, 12682 0xe000: 0x1040080, 12683 0xf000: 0x21000000, 12684 0x800: 0x1040080, 12685 0x1800: 0x21000080, 12686 0x2800: 0x80, 12687 0x3800: 0x1040000, 12688 0x4800: 0x40000, 12689 0x5800: 0x20040080, 12690 0x6800: 0x21040000, 12691 0x7800: 0x20000000, 12692 0x8800: 0x20040000, 12693 0x9800: 0x0, 12694 0xa800: 0x21040080, 12695 0xb800: 0x1000080, 12696 0xc800: 0x20000080, 12697 0xd800: 0x21000000, 12698 0xe800: 0x1000000, 12699 0xf800: 0x40080, 12700 0x10000: 0x40000, 12701 0x11000: 0x80, 12702 0x12000: 0x20000000, 12703 0x13000: 0x21000080, 12704 0x14000: 0x1000080, 12705 0x15000: 0x21040000, 12706 0x16000: 0x20040080, 12707 0x17000: 0x1000000, 12708 0x18000: 0x21040080, 12709 0x19000: 0x21000000, 12710 0x1a000: 0x1040000, 12711 0x1b000: 0x20040000, 12712 0x1c000: 0x40080, 12713 0x1d000: 0x20000080, 12714 0x1e000: 0x0, 12715 0x1f000: 0x1040080, 12716 0x10800: 0x21000080, 12717 0x11800: 0x1000000, 12718 0x12800: 0x1040000, 12719 0x13800: 0x20040080, 12720 0x14800: 0x20000000, 12721 0x15800: 0x1040080, 12722 0x16800: 0x80, 12723 0x17800: 0x21040000, 12724 0x18800: 0x40080, 12725 0x19800: 0x21040080, 12726 0x1a800: 0x0, 12727 0x1b800: 0x21000000, 12728 0x1c800: 0x1000080, 12729 0x1d800: 0x40000, 12730 0x1e800: 0x20040000, 12731 0x1f800: 0x20000080 12732 }, 12733 { 12734 0x0: 0x10000008, 12735 0x100: 0x2000, 12736 0x200: 0x10200000, 12737 0x300: 0x10202008, 12738 0x400: 0x10002000, 12739 0x500: 0x200000, 12740 0x600: 0x200008, 12741 0x700: 0x10000000, 12742 0x800: 0x0, 12743 0x900: 0x10002008, 12744 0xa00: 0x202000, 12745 0xb00: 0x8, 12746 0xc00: 0x10200008, 12747 0xd00: 0x202008, 12748 0xe00: 0x2008, 12749 0xf00: 0x10202000, 12750 0x80: 0x10200000, 12751 0x180: 0x10202008, 12752 0x280: 0x8, 12753 0x380: 0x200000, 12754 0x480: 0x202008, 12755 0x580: 0x10000008, 12756 0x680: 0x10002000, 12757 0x780: 0x2008, 12758 0x880: 0x200008, 12759 0x980: 0x2000, 12760 0xa80: 0x10002008, 12761 0xb80: 0x10200008, 12762 0xc80: 0x0, 12763 0xd80: 0x10202000, 12764 0xe80: 0x202000, 12765 0xf80: 0x10000000, 12766 0x1000: 0x10002000, 12767 0x1100: 0x10200008, 12768 0x1200: 0x10202008, 12769 0x1300: 0x2008, 12770 0x1400: 0x200000, 12771 0x1500: 0x10000000, 12772 0x1600: 0x10000008, 12773 0x1700: 0x202000, 12774 0x1800: 0x202008, 12775 0x1900: 0x0, 12776 0x1a00: 0x8, 12777 0x1b00: 0x10200000, 12778 0x1c00: 0x2000, 12779 0x1d00: 0x10002008, 12780 0x1e00: 0x10202000, 12781 0x1f00: 0x200008, 12782 0x1080: 0x8, 12783 0x1180: 0x202000, 12784 0x1280: 0x200000, 12785 0x1380: 0x10000008, 12786 0x1480: 0x10002000, 12787 0x1580: 0x2008, 12788 0x1680: 0x10202008, 12789 0x1780: 0x10200000, 12790 0x1880: 0x10202000, 12791 0x1980: 0x10200008, 12792 0x1a80: 0x2000, 12793 0x1b80: 0x202008, 12794 0x1c80: 0x200008, 12795 0x1d80: 0x0, 12796 0x1e80: 0x10000000, 12797 0x1f80: 0x10002008 12798 }, 12799 { 12800 0x0: 0x100000, 12801 0x10: 0x2000401, 12802 0x20: 0x400, 12803 0x30: 0x100401, 12804 0x40: 0x2100401, 12805 0x50: 0x0, 12806 0x60: 0x1, 12807 0x70: 0x2100001, 12808 0x80: 0x2000400, 12809 0x90: 0x100001, 12810 0xa0: 0x2000001, 12811 0xb0: 0x2100400, 12812 0xc0: 0x2100000, 12813 0xd0: 0x401, 12814 0xe0: 0x100400, 12815 0xf0: 0x2000000, 12816 0x8: 0x2100001, 12817 0x18: 0x0, 12818 0x28: 0x2000401, 12819 0x38: 0x2100400, 12820 0x48: 0x100000, 12821 0x58: 0x2000001, 12822 0x68: 0x2000000, 12823 0x78: 0x401, 12824 0x88: 0x100401, 12825 0x98: 0x2000400, 12826 0xa8: 0x2100000, 12827 0xb8: 0x100001, 12828 0xc8: 0x400, 12829 0xd8: 0x2100401, 12830 0xe8: 0x1, 12831 0xf8: 0x100400, 12832 0x100: 0x2000000, 12833 0x110: 0x100000, 12834 0x120: 0x2000401, 12835 0x130: 0x2100001, 12836 0x140: 0x100001, 12837 0x150: 0x2000400, 12838 0x160: 0x2100400, 12839 0x170: 0x100401, 12840 0x180: 0x401, 12841 0x190: 0x2100401, 12842 0x1a0: 0x100400, 12843 0x1b0: 0x1, 12844 0x1c0: 0x0, 12845 0x1d0: 0x2100000, 12846 0x1e0: 0x2000001, 12847 0x1f0: 0x400, 12848 0x108: 0x100400, 12849 0x118: 0x2000401, 12850 0x128: 0x2100001, 12851 0x138: 0x1, 12852 0x148: 0x2000000, 12853 0x158: 0x100000, 12854 0x168: 0x401, 12855 0x178: 0x2100400, 12856 0x188: 0x2000001, 12857 0x198: 0x2100000, 12858 0x1a8: 0x0, 12859 0x1b8: 0x2100401, 12860 0x1c8: 0x100401, 12861 0x1d8: 0x400, 12862 0x1e8: 0x2000400, 12863 0x1f8: 0x100001 12864 }, 12865 { 12866 0x0: 0x8000820, 12867 0x1: 0x20000, 12868 0x2: 0x8000000, 12869 0x3: 0x20, 12870 0x4: 0x20020, 12871 0x5: 0x8020820, 12872 0x6: 0x8020800, 12873 0x7: 0x800, 12874 0x8: 0x8020000, 12875 0x9: 0x8000800, 12876 0xa: 0x20800, 12877 0xb: 0x8020020, 12878 0xc: 0x820, 12879 0xd: 0x0, 12880 0xe: 0x8000020, 12881 0xf: 0x20820, 12882 0x80000000: 0x800, 12883 0x80000001: 0x8020820, 12884 0x80000002: 0x8000820, 12885 0x80000003: 0x8000000, 12886 0x80000004: 0x8020000, 12887 0x80000005: 0x20800, 12888 0x80000006: 0x20820, 12889 0x80000007: 0x20, 12890 0x80000008: 0x8000020, 12891 0x80000009: 0x820, 12892 0x8000000a: 0x20020, 12893 0x8000000b: 0x8020800, 12894 0x8000000c: 0x0, 12895 0x8000000d: 0x8020020, 12896 0x8000000e: 0x8000800, 12897 0x8000000f: 0x20000, 12898 0x10: 0x20820, 12899 0x11: 0x8020800, 12900 0x12: 0x20, 12901 0x13: 0x800, 12902 0x14: 0x8000800, 12903 0x15: 0x8000020, 12904 0x16: 0x8020020, 12905 0x17: 0x20000, 12906 0x18: 0x0, 12907 0x19: 0x20020, 12908 0x1a: 0x8020000, 12909 0x1b: 0x8000820, 12910 0x1c: 0x8020820, 12911 0x1d: 0x20800, 12912 0x1e: 0x820, 12913 0x1f: 0x8000000, 12914 0x80000010: 0x20000, 12915 0x80000011: 0x800, 12916 0x80000012: 0x8020020, 12917 0x80000013: 0x20820, 12918 0x80000014: 0x20, 12919 0x80000015: 0x8020000, 12920 0x80000016: 0x8000000, 12921 0x80000017: 0x8000820, 12922 0x80000018: 0x8020820, 12923 0x80000019: 0x8000020, 12924 0x8000001a: 0x8000800, 12925 0x8000001b: 0x0, 12926 0x8000001c: 0x20800, 12927 0x8000001d: 0x820, 12928 0x8000001e: 0x20020, 12929 0x8000001f: 0x8020800 12930 } 12931 ]; 12932 12933 // Masks that select the SBOX input 12934 var SBOX_MASK = [ 12935 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 12936 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 12937 ]; 12938 12939 /** 12940 * DES block cipher algorithm. 12941 */ 12942 var DES = C_algo.DES = BlockCipher.extend({ 12943 _doReset: function () { 12944 // Shortcuts 12945 var key = this._key; 12946 var keyWords = key.words; 12947 12948 // Select 56 bits according to PC1 12949 var keyBits = []; 12950 for (var i = 0; i < 56; i++) { 12951 var keyBitPos = PC1[i] - 1; 12952 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 12953 } 12954 12955 // Assemble 16 subkeys 12956 var subKeys = this._subKeys = []; 12957 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 12958 // Create subkey 12959 var subKey = subKeys[nSubKey] = []; 12960 12961 // Shortcut 12962 var bitShift = BIT_SHIFTS[nSubKey]; 12963 12964 // Select 48 bits according to PC2 12965 for (var i = 0; i < 24; i++) { 12966 // Select from the left 28 key bits 12967 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 12968 12969 // Select from the right 28 key bits 12970 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 12971 } 12972 12973 // Since each subkey is applied to an expanded 32-bit input, 12974 // the subkey can be broken into 8 values scaled to 32-bits, 12975 // which allows the key to be used without expansion 12976 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 12977 for (var i = 1; i < 7; i++) { 12978 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 12979 } 12980 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 12981 } 12982 12983 // Compute inverse subkeys 12984 var invSubKeys = this._invSubKeys = []; 12985 for (var i = 0; i < 16; i++) { 12986 invSubKeys[i] = subKeys[15 - i]; 12987 } 12988 }, 12989 12990 encryptBlock: function (M, offset) { 12991 this._doCryptBlock(M, offset, this._subKeys); 12992 }, 12993 12994 decryptBlock: function (M, offset) { 12995 this._doCryptBlock(M, offset, this._invSubKeys); 12996 }, 12997 12998 _doCryptBlock: function (M, offset, subKeys) { 12999 // Get input 13000 this._lBlock = M[offset]; 13001 this._rBlock = M[offset + 1]; 13002 13003 // Initial permutation 13004 exchangeLR.call(this, 4, 0x0f0f0f0f); 13005 exchangeLR.call(this, 16, 0x0000ffff); 13006 exchangeRL.call(this, 2, 0x33333333); 13007 exchangeRL.call(this, 8, 0x00ff00ff); 13008 exchangeLR.call(this, 1, 0x55555555); 13009 13010 // Rounds 13011 for (var round = 0; round < 16; round++) { 13012 // Shortcuts 13013 var subKey = subKeys[round]; 13014 var lBlock = this._lBlock; 13015 var rBlock = this._rBlock; 13016 13017 // Feistel function 13018 var f = 0; 13019 for (var i = 0; i < 8; i++) { 13020 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 13021 } 13022 this._lBlock = rBlock; 13023 this._rBlock = lBlock ^ f; 13024 } 13025 13026 // Undo swap from last round 13027 var t = this._lBlock; 13028 this._lBlock = this._rBlock; 13029 this._rBlock = t; 13030 13031 // Final permutation 13032 exchangeLR.call(this, 1, 0x55555555); 13033 exchangeRL.call(this, 8, 0x00ff00ff); 13034 exchangeRL.call(this, 2, 0x33333333); 13035 exchangeLR.call(this, 16, 0x0000ffff); 13036 exchangeLR.call(this, 4, 0x0f0f0f0f); 13037 13038 // Set output 13039 M[offset] = this._lBlock; 13040 M[offset + 1] = this._rBlock; 13041 }, 13042 13043 keySize: 64 / 32, 13044 13045 ivSize: 64 / 32, 13046 13047 blockSize: 64 / 32 13048 }); 13049 13050 // Swap bits across the left and right words 13051 function exchangeLR(offset, mask) { 13052 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13053 this._rBlock ^= t; 13054 this._lBlock ^= t << offset; 13055 } 13056 13057 function exchangeRL(offset, mask) { 13058 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13059 this._lBlock ^= t; 13060 this._rBlock ^= t << offset; 13061 } 13062 13063 /** 13064 * Shortcut functions to the cipher's object interface. 13065 * 13066 * @example 13067 * 13068 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13069 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13070 */ 13071 C.DES = BlockCipher._createHelper(DES); 13072 13073 /** 13074 * Triple-DES block cipher algorithm. 13075 */ 13076 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13077 _doReset: function () { 13078 // Shortcuts 13079 var key = this._key; 13080 var keyWords = key.words; 13081 13082 // Create DES instances 13083 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13084 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13085 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13086 }, 13087 13088 encryptBlock: function (M, offset) { 13089 this._des1.encryptBlock(M, offset); 13090 this._des2.decryptBlock(M, offset); 13091 this._des3.encryptBlock(M, offset); 13092 }, 13093 13094 decryptBlock: function (M, offset) { 13095 this._des3.decryptBlock(M, offset); 13096 this._des2.encryptBlock(M, offset); 13097 this._des1.decryptBlock(M, offset); 13098 }, 13099 13100 keySize: 192 / 32, 13101 13102 ivSize: 64 / 32, 13103 13104 blockSize: 64 / 32 13105 }); 13106 13107 /** 13108 * Shortcut functions to the cipher's object interface. 13109 * 13110 * @example 13111 * 13112 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13113 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13114 */ 13115 C.TripleDES = BlockCipher._createHelper(TripleDES); 13116 }()); 13117 13118 13119 return CryptoJS.TripleDES; 13120 13121 })); 13122 }, { "./cipher-core": 52, "./core": 53, "./enc-base64": 54, "./evpkdf": 56, "./md5": 61 }], 84: [function (require, module, exports) { 13123 ; (function (root, factory) { 13124 if (typeof exports === "object") { 13125 // CommonJS 13126 module.exports = exports = factory(require("./core")); 13127 } 13128 else if (typeof define === "function" && define.amd) { 13129 // AMD 13130 define(["./core"], factory); 13131 } 13132 else { 13133 // Global (browser) 13134 factory(root.CryptoJS); 13135 } 13136 }(this, function (CryptoJS) { 13137 13138 (function (undefined) { 13139 // Shortcuts 13140 var C = CryptoJS; 13141 var C_lib = C.lib; 13142 var Base = C_lib.Base; 13143 var X32WordArray = C_lib.WordArray; 13144 13145 /** 13146 * x64 namespace. 13147 */ 13148 var C_x64 = C.x64 = {}; 13149 13150 /** 13151 * A 64-bit word. 13152 */ 13153 var X64Word = C_x64.Word = Base.extend({ 13154 /** 13155 * Initializes a newly created 64-bit word. 13156 * 13157 * @param {number} high The high 32 bits. 13158 * @param {number} low The low 32 bits. 13159 * 13160 * @example 13161 * 13162 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13163 */ 13164 init: function (high, low) { 13165 this.high = high; 13166 this.low = low; 13167 } 13168 13169 /** 13170 * Bitwise NOTs this word. 13171 * 13172 * @return {X64Word} A new x64-Word object after negating. 13173 * 13174 * @example 13175 * 13176 * var negated = x64Word.not(); 13177 */ 13178 // not: function () { 13179 // var high = ~this.high; 13180 // var low = ~this.low; 13181 13182 // return X64Word.create(high, low); 13183 // }, 13184 13185 /** 13186 * Bitwise ANDs this word with the passed word. 13187 * 13188 * @param {X64Word} word The x64-Word to AND with this word. 13189 * 13190 * @return {X64Word} A new x64-Word object after ANDing. 13191 * 13192 * @example 13193 * 13194 * var anded = x64Word.and(anotherX64Word); 13195 */ 13196 // and: function (word) { 13197 // var high = this.high & word.high; 13198 // var low = this.low & word.low; 13199 13200 // return X64Word.create(high, low); 13201 // }, 13202 13203 /** 13204 * Bitwise ORs this word with the passed word. 13205 * 13206 * @param {X64Word} word The x64-Word to OR with this word. 13207 * 13208 * @return {X64Word} A new x64-Word object after ORing. 13209 * 13210 * @example 13211 * 13212 * var ored = x64Word.or(anotherX64Word); 13213 */ 13214 // or: function (word) { 13215 // var high = this.high | word.high; 13216 // var low = this.low | word.low; 13217 13218 // return X64Word.create(high, low); 13219 // }, 13220 13221 /** 13222 * Bitwise XORs this word with the passed word. 13223 * 13224 * @param {X64Word} word The x64-Word to XOR with this word. 13225 * 13226 * @return {X64Word} A new x64-Word object after XORing. 13227 * 13228 * @example 13229 * 13230 * var xored = x64Word.xor(anotherX64Word); 13231 */ 13232 // xor: function (word) { 13233 // var high = this.high ^ word.high; 13234 // var low = this.low ^ word.low; 13235 13236 // return X64Word.create(high, low); 13237 // }, 13238 13239 /** 13240 * Shifts this word n bits to the left. 13241 * 13242 * @param {number} n The number of bits to shift. 13243 * 13244 * @return {X64Word} A new x64-Word object after shifting. 13245 * 13246 * @example 13247 * 13248 * var shifted = x64Word.shiftL(25); 13249 */ 13250 // shiftL: function (n) { 13251 // if (n < 32) { 13252 // var high = (this.high << n) | (this.low >>> (32 - n)); 13253 // var low = this.low << n; 13254 // } else { 13255 // var high = this.low << (n - 32); 13256 // var low = 0; 13257 // } 13258 13259 // return X64Word.create(high, low); 13260 // }, 13261 13262 /** 13263 * Shifts this word n bits to the right. 13264 * 13265 * @param {number} n The number of bits to shift. 13266 * 13267 * @return {X64Word} A new x64-Word object after shifting. 13268 * 13269 * @example 13270 * 13271 * var shifted = x64Word.shiftR(7); 13272 */ 13273 // shiftR: function (n) { 13274 // if (n < 32) { 13275 // var low = (this.low >>> n) | (this.high << (32 - n)); 13276 // var high = this.high >>> n; 13277 // } else { 13278 // var low = this.high >>> (n - 32); 13279 // var high = 0; 13280 // } 13281 13282 // return X64Word.create(high, low); 13283 // }, 13284 13285 /** 13286 * Rotates this word n bits to the left. 13287 * 13288 * @param {number} n The number of bits to rotate. 13289 * 13290 * @return {X64Word} A new x64-Word object after rotating. 13291 * 13292 * @example 13293 * 13294 * var rotated = x64Word.rotL(25); 13295 */ 13296 // rotL: function (n) { 13297 // return this.shiftL(n).or(this.shiftR(64 - n)); 13298 // }, 13299 13300 /** 13301 * Rotates this word n bits to the right. 13302 * 13303 * @param {number} n The number of bits to rotate. 13304 * 13305 * @return {X64Word} A new x64-Word object after rotating. 13306 * 13307 * @example 13308 * 13309 * var rotated = x64Word.rotR(7); 13310 */ 13311 // rotR: function (n) { 13312 // return this.shiftR(n).or(this.shiftL(64 - n)); 13313 // }, 13314 13315 /** 13316 * Adds this word with the passed word. 13317 * 13318 * @param {X64Word} word The x64-Word to add with this word. 13319 * 13320 * @return {X64Word} A new x64-Word object after adding. 13321 * 13322 * @example 13323 * 13324 * var added = x64Word.add(anotherX64Word); 13325 */ 13326 // add: function (word) { 13327 // var low = (this.low + word.low) | 0; 13328 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13329 // var high = (this.high + word.high + carry) | 0; 13330 13331 // return X64Word.create(high, low); 13332 // } 13333 }); 13334 13335 /** 13336 * An array of 64-bit words. 13337 * 13338 * @property {Array} words The array of CryptoJS.x64.Word objects. 13339 * @property {number} sigBytes The number of significant bytes in this word array. 13340 */ 13341 var X64WordArray = C_x64.WordArray = Base.extend({ 13342 /** 13343 * Initializes a newly created word array. 13344 * 13345 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13346 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13347 * 13348 * @example 13349 * 13350 * var wordArray = CryptoJS.x64.WordArray.create(); 13351 * 13352 * var wordArray = CryptoJS.x64.WordArray.create([ 13353 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13354 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13355 * ]); 13356 * 13357 * var wordArray = CryptoJS.x64.WordArray.create([ 13358 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13359 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13360 * ], 10); 13361 */ 13362 init: function (words, sigBytes) { 13363 words = this.words = words || []; 13364 13365 if (sigBytes != undefined) { 13366 this.sigBytes = sigBytes; 13367 } else { 13368 this.sigBytes = words.length * 8; 13369 } 13370 }, 13371 13372 /** 13373 * Converts this 64-bit word array to a 32-bit word array. 13374 * 13375 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13376 * 13377 * @example 13378 * 13379 * var x32WordArray = x64WordArray.toX32(); 13380 */ 13381 toX32: function () { 13382 // Shortcuts 13383 var x64Words = this.words; 13384 var x64WordsLength = x64Words.length; 13385 13386 // Convert 13387 var x32Words = []; 13388 for (var i = 0; i < x64WordsLength; i++) { 13389 var x64Word = x64Words[i]; 13390 x32Words.push(x64Word.high); 13391 x32Words.push(x64Word.low); 13392 } 13393 13394 return X32WordArray.create(x32Words, this.sigBytes); 13395 }, 13396 13397 /** 13398 * Creates a copy of this word array. 13399 * 13400 * @return {X64WordArray} The clone. 13401 * 13402 * @example 13403 * 13404 * var clone = x64WordArray.clone(); 13405 */ 13406 clone: function () { 13407 var clone = Base.clone.call(this); 13408 13409 // Clone "words" array 13410 var words = clone.words = this.words.slice(0); 13411 13412 // Clone each X64Word object 13413 var wordsLength = words.length; 13414 for (var i = 0; i < wordsLength; i++) { 13415 words[i] = words[i].clone(); 13416 } 13417 13418 return clone; 13419 } 13420 }); 13421 }()); 13422 13423 13424 return CryptoJS; 13425 13426 })); 13427 }, { "./core": 53 }], 85: [function (require, module, exports) { 13428 /** 13429 * [js-sha3]{@link https://github.com/emn178/js-sha3} 13430 * 13431 * @version 0.8.0 13432 * @author Chen, Yi-Cyuan [emn178@gmail.com] 13433 * @copyright Chen, Yi-Cyuan 2015-2018 13434 * @license MIT 13435 */ 13436 /*jslint bitwise: true */ 13437 (function () { 13438 'use strict'; 13439 13440 var INPUT_ERROR = 'input is invalid type'; 13441 var FINALIZE_ERROR = 'finalize already called'; 13442 var WINDOW = typeof window === 'object'; 13443 var root = WINDOW ? window : {}; 13444 if (root.JS_SHA3_NO_WINDOW) { 13445 WINDOW = false; 13446 } 13447 var WEB_WORKER = !WINDOW && typeof self === 'object'; 13448 var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node; 13449 if (NODE_JS) { 13450 root = global; 13451 } else if (WEB_WORKER) { 13452 root = self; 13453 } 13454 var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports; 13455 var AMD = typeof define === 'function' && define.amd; 13456 var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined'; 13457 var HEX_CHARS = '0123456789abcdef'.split(''); 13458 var SHAKE_PADDING = [31, 7936, 2031616, 520093696]; 13459 var CSHAKE_PADDING = [4, 1024, 262144, 67108864]; 13460 var KECCAK_PADDING = [1, 256, 65536, 16777216]; 13461 var PADDING = [6, 1536, 393216, 100663296]; 13462 var SHIFT = [0, 8, 16, 24]; 13463 var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 13464 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 13465 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 13466 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 13467 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648]; 13468 var BITS = [224, 256, 384, 512]; 13469 var SHAKE_BITS = [128, 256]; 13470 var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array', 'digest']; 13471 var CSHAKE_BYTEPAD = { 13472 '128': 168, 13473 '256': 136 13474 }; 13475 13476 if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) { 13477 Array.isArray = function (obj) { 13478 return Object.prototype.toString.call(obj) === '[object Array]'; 13479 }; 13480 } 13481 13482 if (ARRAY_BUFFER && (root.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView)) { 13483 ArrayBuffer.isView = function (obj) { 13484 return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer; 13485 }; 13486 } 13487 13488 var createOutputMethod = function (bits, padding, outputType) { 13489 return function (message) { 13490 return new Keccak(bits, padding, bits).update(message)[outputType](); 13491 }; 13492 }; 13493 13494 var createShakeOutputMethod = function (bits, padding, outputType) { 13495 return function (message, outputBits) { 13496 return new Keccak(bits, padding, outputBits).update(message)[outputType](); 13497 }; 13498 }; 13499 13500 var createCshakeOutputMethod = function (bits, padding, outputType) { 13501 return function (message, outputBits, n, s) { 13502 return methods['cshake' + bits].update(message, outputBits, n, s)[outputType](); 13503 }; 13504 }; 13505 13506 var createKmacOutputMethod = function (bits, padding, outputType) { 13507 return function (key, message, outputBits, s) { 13508 return methods['kmac' + bits].update(key, message, outputBits, s)[outputType](); 13509 }; 13510 }; 13511 13512 var createOutputMethods = function (method, createMethod, bits, padding) { 13513 for (var i = 0; i < OUTPUT_TYPES.length; ++i) { 13514 var type = OUTPUT_TYPES[i]; 13515 method[type] = createMethod(bits, padding, type); 13516 } 13517 return method; 13518 }; 13519 13520 var createMethod = function (bits, padding) { 13521 var method = createOutputMethod(bits, padding, 'hex'); 13522 method.create = function () { 13523 return new Keccak(bits, padding, bits); 13524 }; 13525 method.update = function (message) { 13526 return method.create().update(message); 13527 }; 13528 return createOutputMethods(method, createOutputMethod, bits, padding); 13529 }; 13530 13531 var createShakeMethod = function (bits, padding) { 13532 var method = createShakeOutputMethod(bits, padding, 'hex'); 13533 method.create = function (outputBits) { 13534 return new Keccak(bits, padding, outputBits); 13535 }; 13536 method.update = function (message, outputBits) { 13537 return method.create(outputBits).update(message); 13538 }; 13539 return createOutputMethods(method, createShakeOutputMethod, bits, padding); 13540 }; 13541 13542 var createCshakeMethod = function (bits, padding) { 13543 var w = CSHAKE_BYTEPAD[bits]; 13544 var method = createCshakeOutputMethod(bits, padding, 'hex'); 13545 method.create = function (outputBits, n, s) { 13546 if (!n && !s) { 13547 return methods['shake' + bits].create(outputBits); 13548 } else { 13549 return new Keccak(bits, padding, outputBits).bytepad([n, s], w); 13550 } 13551 }; 13552 method.update = function (message, outputBits, n, s) { 13553 return method.create(outputBits, n, s).update(message); 13554 }; 13555 return createOutputMethods(method, createCshakeOutputMethod, bits, padding); 13556 }; 13557 13558 var createKmacMethod = function (bits, padding) { 13559 var w = CSHAKE_BYTEPAD[bits]; 13560 var method = createKmacOutputMethod(bits, padding, 'hex'); 13561 method.create = function (key, outputBits, s) { 13562 return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w); 13563 }; 13564 method.update = function (key, message, outputBits, s) { 13565 return method.create(key, outputBits, s).update(message); 13566 }; 13567 return createOutputMethods(method, createKmacOutputMethod, bits, padding); 13568 }; 13569 13570 var algorithms = [ 13571 { name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod }, 13572 { name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod }, 13573 { name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod }, 13574 { name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createCshakeMethod }, 13575 { name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod } 13576 ]; 13577 13578 var methods = {}, methodNames = []; 13579 13580 for (var i = 0; i < algorithms.length; ++i) { 13581 var algorithm = algorithms[i]; 13582 var bits = algorithm.bits; 13583 for (var j = 0; j < bits.length; ++j) { 13584 var methodName = algorithm.name + '_' + bits[j]; 13585 methodNames.push(methodName); 13586 methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding); 13587 if (algorithm.name !== 'sha3') { 13588 var newMethodName = algorithm.name + bits[j]; 13589 methodNames.push(newMethodName); 13590 methods[newMethodName] = methods[methodName]; 13591 } 13592 } 13593 } 13594 13595 function Keccak(bits, padding, outputBits) { 13596 this.blocks = []; 13597 this.s = []; 13598 this.padding = padding; 13599 this.outputBits = outputBits; 13600 this.reset = true; 13601 this.finalized = false; 13602 this.block = 0; 13603 this.start = 0; 13604 this.blockCount = (1600 - (bits << 1)) >> 5; 13605 this.byteCount = this.blockCount << 2; 13606 this.outputBlocks = outputBits >> 5; 13607 this.extraBytes = (outputBits & 31) >> 3; 13608 13609 for (var i = 0; i < 50; ++i) { 13610 this.s[i] = 0; 13611 } 13612 } 13613 13614 Keccak.prototype.update = function (message) { 13615 if (this.finalized) { 13616 throw new Error(FINALIZE_ERROR); 13617 } 13618 var notString, type = typeof message; 13619 if (type !== 'string') { 13620 if (type === 'object') { 13621 if (message === null) { 13622 throw new Error(INPUT_ERROR); 13623 } else if (ARRAY_BUFFER && message.constructor === ArrayBuffer) { 13624 message = new Uint8Array(message); 13625 } else if (!Array.isArray(message)) { 13626 if (!ARRAY_BUFFER || !ArrayBuffer.isView(message)) { 13627 throw new Error(INPUT_ERROR); 13628 } 13629 } 13630 } else { 13631 throw new Error(INPUT_ERROR); 13632 } 13633 notString = true; 13634 } 13635 var blocks = this.blocks, byteCount = this.byteCount, length = message.length, 13636 blockCount = this.blockCount, index = 0, s = this.s, i, code; 13637 13638 while (index < length) { 13639 if (this.reset) { 13640 this.reset = false; 13641 blocks[0] = this.block; 13642 for (i = 1; i < blockCount + 1; ++i) { 13643 blocks[i] = 0; 13644 } 13645 } 13646 if (notString) { 13647 for (i = this.start; index < length && i < byteCount; ++index) { 13648 blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; 13649 } 13650 } else { 13651 for (i = this.start; index < length && i < byteCount; ++index) { 13652 code = message.charCodeAt(index); 13653 if (code < 0x80) { 13654 blocks[i >> 2] |= code << SHIFT[i++ & 3]; 13655 } else if (code < 0x800) { 13656 blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; 13657 blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 13658 } else if (code < 0xd800 || code >= 0xe000) { 13659 blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; 13660 blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; 13661 blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 13662 } else { 13663 code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); 13664 blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; 13665 blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; 13666 blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; 13667 blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 13668 } 13669 } 13670 } 13671 this.lastByteIndex = i; 13672 if (i >= byteCount) { 13673 this.start = i - byteCount; 13674 this.block = blocks[blockCount]; 13675 for (i = 0; i < blockCount; ++i) { 13676 s[i] ^= blocks[i]; 13677 } 13678 f(s); 13679 this.reset = true; 13680 } else { 13681 this.start = i; 13682 } 13683 } 13684 return this; 13685 }; 13686 13687 Keccak.prototype.encode = function (x, right) { 13688 var o = x & 255, n = 1; 13689 var bytes = [o]; 13690 x = x >> 8; 13691 o = x & 255; 13692 while (o > 0) { 13693 bytes.unshift(o); 13694 x = x >> 8; 13695 o = x & 255; 13696 ++n; 13697 } 13698 if (right) { 13699 bytes.push(n); 13700 } else { 13701 bytes.unshift(n); 13702 } 13703 this.update(bytes); 13704 return bytes.length; 13705 }; 13706 13707 Keccak.prototype.encodeString = function (str) { 13708 var notString, type = typeof str; 13709 if (type !== 'string') { 13710 if (type === 'object') { 13711 if (str === null) { 13712 throw new Error(INPUT_ERROR); 13713 } else if (ARRAY_BUFFER && str.constructor === ArrayBuffer) { 13714 str = new Uint8Array(str); 13715 } else if (!Array.isArray(str)) { 13716 if (!ARRAY_BUFFER || !ArrayBuffer.isView(str)) { 13717 throw new Error(INPUT_ERROR); 13718 } 13719 } 13720 } else { 13721 throw new Error(INPUT_ERROR); 13722 } 13723 notString = true; 13724 } 13725 var bytes = 0, length = str.length; 13726 if (notString) { 13727 bytes = length; 13728 } else { 13729 for (var i = 0; i < str.length; ++i) { 13730 var code = str.charCodeAt(i); 13731 if (code < 0x80) { 13732 bytes += 1; 13733 } else if (code < 0x800) { 13734 bytes += 2; 13735 } else if (code < 0xd800 || code >= 0xe000) { 13736 bytes += 3; 13737 } else { 13738 code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff)); 13739 bytes += 4; 13740 } 13741 } 13742 } 13743 bytes += this.encode(bytes * 8); 13744 this.update(str); 13745 return bytes; 13746 }; 13747 13748 Keccak.prototype.bytepad = function (strs, w) { 13749 var bytes = this.encode(w); 13750 for (var i = 0; i < strs.length; ++i) { 13751 bytes += this.encodeString(strs[i]); 13752 } 13753 var paddingBytes = w - bytes % w; 13754 var zeros = []; 13755 zeros.length = paddingBytes; 13756 this.update(zeros); 13757 return this; 13758 }; 13759 13760 Keccak.prototype.finalize = function () { 13761 if (this.finalized) { 13762 return; 13763 } 13764 this.finalized = true; 13765 var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s; 13766 blocks[i >> 2] |= this.padding[i & 3]; 13767 if (this.lastByteIndex === this.byteCount) { 13768 blocks[0] = blocks[blockCount]; 13769 for (i = 1; i < blockCount + 1; ++i) { 13770 blocks[i] = 0; 13771 } 13772 } 13773 blocks[blockCount - 1] |= 0x80000000; 13774 for (i = 0; i < blockCount; ++i) { 13775 s[i] ^= blocks[i]; 13776 } 13777 f(s); 13778 }; 13779 13780 Keccak.prototype.toString = Keccak.prototype.hex = function () { 13781 this.finalize(); 13782 13783 var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 13784 extraBytes = this.extraBytes, i = 0, j = 0; 13785 var hex = '', block; 13786 while (j < outputBlocks) { 13787 for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { 13788 block = s[i]; 13789 hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + 13790 HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] + 13791 HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] + 13792 HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F]; 13793 } 13794 if (j % blockCount === 0) { 13795 f(s); 13796 i = 0; 13797 } 13798 } 13799 if (extraBytes) { 13800 block = s[i]; 13801 hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F]; 13802 if (extraBytes > 1) { 13803 hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F]; 13804 } 13805 if (extraBytes > 2) { 13806 hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F]; 13807 } 13808 } 13809 return hex; 13810 }; 13811 13812 Keccak.prototype.arrayBuffer = function () { 13813 this.finalize(); 13814 13815 var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 13816 extraBytes = this.extraBytes, i = 0, j = 0; 13817 var bytes = this.outputBits >> 3; 13818 var buffer; 13819 if (extraBytes) { 13820 buffer = new ArrayBuffer((outputBlocks + 1) << 2); 13821 } else { 13822 buffer = new ArrayBuffer(bytes); 13823 } 13824 var array = new Uint32Array(buffer); 13825 while (j < outputBlocks) { 13826 for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { 13827 array[j] = s[i]; 13828 } 13829 if (j % blockCount === 0) { 13830 f(s); 13831 } 13832 } 13833 if (extraBytes) { 13834 array[i] = s[i]; 13835 buffer = buffer.slice(0, bytes); 13836 } 13837 return buffer; 13838 }; 13839 13840 Keccak.prototype.buffer = Keccak.prototype.arrayBuffer; 13841 13842 Keccak.prototype.digest = Keccak.prototype.array = function () { 13843 this.finalize(); 13844 13845 var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 13846 extraBytes = this.extraBytes, i = 0, j = 0; 13847 var array = [], offset, block; 13848 while (j < outputBlocks) { 13849 for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) { 13850 offset = j << 2; 13851 block = s[i]; 13852 array[offset] = block & 0xFF; 13853 array[offset + 1] = (block >> 8) & 0xFF; 13854 array[offset + 2] = (block >> 16) & 0xFF; 13855 array[offset + 3] = (block >> 24) & 0xFF; 13856 } 13857 if (j % blockCount === 0) { 13858 f(s); 13859 } 13860 } 13861 if (extraBytes) { 13862 offset = j << 2; 13863 block = s[i]; 13864 array[offset] = block & 0xFF; 13865 if (extraBytes > 1) { 13866 array[offset + 1] = (block >> 8) & 0xFF; 13867 } 13868 if (extraBytes > 2) { 13869 array[offset + 2] = (block >> 16) & 0xFF; 13870 } 13871 } 13872 return array; 13873 }; 13874 13875 function Kmac(bits, padding, outputBits) { 13876 Keccak.call(this, bits, padding, outputBits); 13877 } 13878 13879 Kmac.prototype = new Keccak(); 13880 13881 Kmac.prototype.finalize = function () { 13882 this.encode(this.outputBits, true); 13883 return Keccak.prototype.finalize.call(this); 13884 }; 13885 13886 var f = function (s) { 13887 var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, 13888 b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, 13889 b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, 13890 b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49; 13891 for (n = 0; n < 48; n += 2) { 13892 c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; 13893 c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; 13894 c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; 13895 c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]; 13896 c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]; 13897 c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45]; 13898 c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]; 13899 c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]; 13900 c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]; 13901 c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]; 13902 13903 h = c8 ^ ((c2 << 1) | (c3 >>> 31)); 13904 l = c9 ^ ((c3 << 1) | (c2 >>> 31)); 13905 s[0] ^= h; 13906 s[1] ^= l; 13907 s[10] ^= h; 13908 s[11] ^= l; 13909 s[20] ^= h; 13910 s[21] ^= l; 13911 s[30] ^= h; 13912 s[31] ^= l; 13913 s[40] ^= h; 13914 s[41] ^= l; 13915 h = c0 ^ ((c4 << 1) | (c5 >>> 31)); 13916 l = c1 ^ ((c5 << 1) | (c4 >>> 31)); 13917 s[2] ^= h; 13918 s[3] ^= l; 13919 s[12] ^= h; 13920 s[13] ^= l; 13921 s[22] ^= h; 13922 s[23] ^= l; 13923 s[32] ^= h; 13924 s[33] ^= l; 13925 s[42] ^= h; 13926 s[43] ^= l; 13927 h = c2 ^ ((c6 << 1) | (c7 >>> 31)); 13928 l = c3 ^ ((c7 << 1) | (c6 >>> 31)); 13929 s[4] ^= h; 13930 s[5] ^= l; 13931 s[14] ^= h; 13932 s[15] ^= l; 13933 s[24] ^= h; 13934 s[25] ^= l; 13935 s[34] ^= h; 13936 s[35] ^= l; 13937 s[44] ^= h; 13938 s[45] ^= l; 13939 h = c4 ^ ((c8 << 1) | (c9 >>> 31)); 13940 l = c5 ^ ((c9 << 1) | (c8 >>> 31)); 13941 s[6] ^= h; 13942 s[7] ^= l; 13943 s[16] ^= h; 13944 s[17] ^= l; 13945 s[26] ^= h; 13946 s[27] ^= l; 13947 s[36] ^= h; 13948 s[37] ^= l; 13949 s[46] ^= h; 13950 s[47] ^= l; 13951 h = c6 ^ ((c0 << 1) | (c1 >>> 31)); 13952 l = c7 ^ ((c1 << 1) | (c0 >>> 31)); 13953 s[8] ^= h; 13954 s[9] ^= l; 13955 s[18] ^= h; 13956 s[19] ^= l; 13957 s[28] ^= h; 13958 s[29] ^= l; 13959 s[38] ^= h; 13960 s[39] ^= l; 13961 s[48] ^= h; 13962 s[49] ^= l; 13963 13964 b0 = s[0]; 13965 b1 = s[1]; 13966 b32 = (s[11] << 4) | (s[10] >>> 28); 13967 b33 = (s[10] << 4) | (s[11] >>> 28); 13968 b14 = (s[20] << 3) | (s[21] >>> 29); 13969 b15 = (s[21] << 3) | (s[20] >>> 29); 13970 b46 = (s[31] << 9) | (s[30] >>> 23); 13971 b47 = (s[30] << 9) | (s[31] >>> 23); 13972 b28 = (s[40] << 18) | (s[41] >>> 14); 13973 b29 = (s[41] << 18) | (s[40] >>> 14); 13974 b20 = (s[2] << 1) | (s[3] >>> 31); 13975 b21 = (s[3] << 1) | (s[2] >>> 31); 13976 b2 = (s[13] << 12) | (s[12] >>> 20); 13977 b3 = (s[12] << 12) | (s[13] >>> 20); 13978 b34 = (s[22] << 10) | (s[23] >>> 22); 13979 b35 = (s[23] << 10) | (s[22] >>> 22); 13980 b16 = (s[33] << 13) | (s[32] >>> 19); 13981 b17 = (s[32] << 13) | (s[33] >>> 19); 13982 b48 = (s[42] << 2) | (s[43] >>> 30); 13983 b49 = (s[43] << 2) | (s[42] >>> 30); 13984 b40 = (s[5] << 30) | (s[4] >>> 2); 13985 b41 = (s[4] << 30) | (s[5] >>> 2); 13986 b22 = (s[14] << 6) | (s[15] >>> 26); 13987 b23 = (s[15] << 6) | (s[14] >>> 26); 13988 b4 = (s[25] << 11) | (s[24] >>> 21); 13989 b5 = (s[24] << 11) | (s[25] >>> 21); 13990 b36 = (s[34] << 15) | (s[35] >>> 17); 13991 b37 = (s[35] << 15) | (s[34] >>> 17); 13992 b18 = (s[45] << 29) | (s[44] >>> 3); 13993 b19 = (s[44] << 29) | (s[45] >>> 3); 13994 b10 = (s[6] << 28) | (s[7] >>> 4); 13995 b11 = (s[7] << 28) | (s[6] >>> 4); 13996 b42 = (s[17] << 23) | (s[16] >>> 9); 13997 b43 = (s[16] << 23) | (s[17] >>> 9); 13998 b24 = (s[26] << 25) | (s[27] >>> 7); 13999 b25 = (s[27] << 25) | (s[26] >>> 7); 14000 b6 = (s[36] << 21) | (s[37] >>> 11); 14001 b7 = (s[37] << 21) | (s[36] >>> 11); 14002 b38 = (s[47] << 24) | (s[46] >>> 8); 14003 b39 = (s[46] << 24) | (s[47] >>> 8); 14004 b30 = (s[8] << 27) | (s[9] >>> 5); 14005 b31 = (s[9] << 27) | (s[8] >>> 5); 14006 b12 = (s[18] << 20) | (s[19] >>> 12); 14007 b13 = (s[19] << 20) | (s[18] >>> 12); 14008 b44 = (s[29] << 7) | (s[28] >>> 25); 14009 b45 = (s[28] << 7) | (s[29] >>> 25); 14010 b26 = (s[38] << 8) | (s[39] >>> 24); 14011 b27 = (s[39] << 8) | (s[38] >>> 24); 14012 b8 = (s[48] << 14) | (s[49] >>> 18); 14013 b9 = (s[49] << 14) | (s[48] >>> 18); 14014 14015 s[0] = b0 ^ (~b2 & b4); 14016 s[1] = b1 ^ (~b3 & b5); 14017 s[10] = b10 ^ (~b12 & b14); 14018 s[11] = b11 ^ (~b13 & b15); 14019 s[20] = b20 ^ (~b22 & b24); 14020 s[21] = b21 ^ (~b23 & b25); 14021 s[30] = b30 ^ (~b32 & b34); 14022 s[31] = b31 ^ (~b33 & b35); 14023 s[40] = b40 ^ (~b42 & b44); 14024 s[41] = b41 ^ (~b43 & b45); 14025 s[2] = b2 ^ (~b4 & b6); 14026 s[3] = b3 ^ (~b5 & b7); 14027 s[12] = b12 ^ (~b14 & b16); 14028 s[13] = b13 ^ (~b15 & b17); 14029 s[22] = b22 ^ (~b24 & b26); 14030 s[23] = b23 ^ (~b25 & b27); 14031 s[32] = b32 ^ (~b34 & b36); 14032 s[33] = b33 ^ (~b35 & b37); 14033 s[42] = b42 ^ (~b44 & b46); 14034 s[43] = b43 ^ (~b45 & b47); 14035 s[4] = b4 ^ (~b6 & b8); 14036 s[5] = b5 ^ (~b7 & b9); 14037 s[14] = b14 ^ (~b16 & b18); 14038 s[15] = b15 ^ (~b17 & b19); 14039 s[24] = b24 ^ (~b26 & b28); 14040 s[25] = b25 ^ (~b27 & b29); 14041 s[34] = b34 ^ (~b36 & b38); 14042 s[35] = b35 ^ (~b37 & b39); 14043 s[44] = b44 ^ (~b46 & b48); 14044 s[45] = b45 ^ (~b47 & b49); 14045 s[6] = b6 ^ (~b8 & b0); 14046 s[7] = b7 ^ (~b9 & b1); 14047 s[16] = b16 ^ (~b18 & b10); 14048 s[17] = b17 ^ (~b19 & b11); 14049 s[26] = b26 ^ (~b28 & b20); 14050 s[27] = b27 ^ (~b29 & b21); 14051 s[36] = b36 ^ (~b38 & b30); 14052 s[37] = b37 ^ (~b39 & b31); 14053 s[46] = b46 ^ (~b48 & b40); 14054 s[47] = b47 ^ (~b49 & b41); 14055 s[8] = b8 ^ (~b0 & b2); 14056 s[9] = b9 ^ (~b1 & b3); 14057 s[18] = b18 ^ (~b10 & b12); 14058 s[19] = b19 ^ (~b11 & b13); 14059 s[28] = b28 ^ (~b20 & b22); 14060 s[29] = b29 ^ (~b21 & b23); 14061 s[38] = b38 ^ (~b30 & b32); 14062 s[39] = b39 ^ (~b31 & b33); 14063 s[48] = b48 ^ (~b40 & b42); 14064 s[49] = b49 ^ (~b41 & b43); 14065 14066 s[0] ^= RC[n]; 14067 s[1] ^= RC[n + 1]; 14068 } 14069 }; 14070 14071 if (COMMON_JS) { 14072 module.exports = methods; 14073 } else { 14074 for (i = 0; i < methodNames.length; ++i) { 14075 root[methodNames[i]] = methods[methodNames[i]]; 14076 } 14077 if (AMD) { 14078 define(function () { 14079 return methods; 14080 }); 14081 } 14082 } 14083 })(); 14084 14085 }, {}], 86: [function (require, module, exports) { 14086 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 14087 ; (function (root) { 14088 14089 // Detect free variables `exports` 14090 var freeExports = typeof exports == 'object' && exports; 14091 14092 // Detect free variable `module` 14093 var freeModule = typeof module == 'object' && module && 14094 module.exports == freeExports && module; 14095 14096 // Detect free variable `global`, from Node.js or Browserified code, 14097 // and use it as `root` 14098 var freeGlobal = typeof global == 'object' && global; 14099 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 14100 root = freeGlobal; 14101 } 14102 14103 /*--------------------------------------------------------------------------*/ 14104 14105 var stringFromCharCode = String.fromCharCode; 14106 14107 // Taken from https://mths.be/punycode 14108 function ucs2decode(string) { 14109 var output = []; 14110 var counter = 0; 14111 var length = string.length; 14112 var value; 14113 var extra; 14114 while (counter < length) { 14115 value = string.charCodeAt(counter++); 14116 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 14117 // high surrogate, and there is a next character 14118 extra = string.charCodeAt(counter++); 14119 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 14120 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 14121 } else { 14122 // unmatched surrogate; only append this code unit, in case the next 14123 // code unit is the high surrogate of a surrogate pair 14124 output.push(value); 14125 counter--; 14126 } 14127 } else { 14128 output.push(value); 14129 } 14130 } 14131 return output; 14132 } 14133 14134 // Taken from https://mths.be/punycode 14135 function ucs2encode(array) { 14136 var length = array.length; 14137 var index = -1; 14138 var value; 14139 var output = ''; 14140 while (++index < length) { 14141 value = array[index]; 14142 if (value > 0xFFFF) { 14143 value -= 0x10000; 14144 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 14145 value = 0xDC00 | value & 0x3FF; 14146 } 14147 output += stringFromCharCode(value); 14148 } 14149 return output; 14150 } 14151 14152 function checkScalarValue(codePoint) { 14153 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 14154 throw Error( 14155 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 14156 ' is not a scalar value' 14157 ); 14158 } 14159 } 14160 /*--------------------------------------------------------------------------*/ 14161 14162 function createByte(codePoint, shift) { 14163 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 14164 } 14165 14166 function encodeCodePoint(codePoint) { 14167 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 14168 return stringFromCharCode(codePoint); 14169 } 14170 var symbol = ''; 14171 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 14172 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 14173 } 14174 else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 14175 checkScalarValue(codePoint); 14176 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 14177 symbol += createByte(codePoint, 6); 14178 } 14179 else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 14180 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 14181 symbol += createByte(codePoint, 12); 14182 symbol += createByte(codePoint, 6); 14183 } 14184 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 14185 return symbol; 14186 } 14187 14188 function utf8encode(string) { 14189 var codePoints = ucs2decode(string); 14190 var length = codePoints.length; 14191 var index = -1; 14192 var codePoint; 14193 var byteString = ''; 14194 while (++index < length) { 14195 codePoint = codePoints[index]; 14196 byteString += encodeCodePoint(codePoint); 14197 } 14198 return byteString; 14199 } 14200 14201 /*--------------------------------------------------------------------------*/ 14202 14203 function readContinuationByte() { 14204 if (byteIndex >= byteCount) { 14205 throw Error('Invalid byte index'); 14206 } 14207 14208 var continuationByte = byteArray[byteIndex] & 0xFF; 14209 byteIndex++; 14210 14211 if ((continuationByte & 0xC0) == 0x80) { 14212 return continuationByte & 0x3F; 14213 } 14214 14215 // If we end up here, it’s not a continuation byte 14216 throw Error('Invalid continuation byte'); 14217 } 14218 14219 function decodeSymbol() { 14220 var byte1; 14221 var byte2; 14222 var byte3; 14223 var byte4; 14224 var codePoint; 14225 14226 if (byteIndex > byteCount) { 14227 throw Error('Invalid byte index'); 14228 } 14229 14230 if (byteIndex == byteCount) { 14231 return false; 14232 } 14233 14234 // Read first byte 14235 byte1 = byteArray[byteIndex] & 0xFF; 14236 byteIndex++; 14237 14238 // 1-byte sequence (no continuation bytes) 14239 if ((byte1 & 0x80) == 0) { 14240 return byte1; 14241 } 14242 14243 // 2-byte sequence 14244 if ((byte1 & 0xE0) == 0xC0) { 14245 byte2 = readContinuationByte(); 14246 codePoint = ((byte1 & 0x1F) << 6) | byte2; 14247 if (codePoint >= 0x80) { 14248 return codePoint; 14249 } else { 14250 throw Error('Invalid continuation byte'); 14251 } 14252 } 14253 14254 // 3-byte sequence (may include unpaired surrogates) 14255 if ((byte1 & 0xF0) == 0xE0) { 14256 byte2 = readContinuationByte(); 14257 byte3 = readContinuationByte(); 14258 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 14259 if (codePoint >= 0x0800) { 14260 checkScalarValue(codePoint); 14261 return codePoint; 14262 } else { 14263 throw Error('Invalid continuation byte'); 14264 } 14265 } 14266 14267 // 4-byte sequence 14268 if ((byte1 & 0xF8) == 0xF0) { 14269 byte2 = readContinuationByte(); 14270 byte3 = readContinuationByte(); 14271 byte4 = readContinuationByte(); 14272 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 14273 (byte3 << 0x06) | byte4; 14274 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 14275 return codePoint; 14276 } 14277 } 14278 14279 throw Error('Invalid UTF-8 detected'); 14280 } 14281 14282 var byteArray; 14283 var byteCount; 14284 var byteIndex; 14285 function utf8decode(byteString) { 14286 byteArray = ucs2decode(byteString); 14287 byteCount = byteArray.length; 14288 byteIndex = 0; 14289 var codePoints = []; 14290 var tmp; 14291 while ((tmp = decodeSymbol()) !== false) { 14292 codePoints.push(tmp); 14293 } 14294 return ucs2encode(codePoints); 14295 } 14296 14297 /*--------------------------------------------------------------------------*/ 14298 14299 var utf8 = { 14300 'version': '2.1.2', 14301 'encode': utf8encode, 14302 'decode': utf8decode 14303 }; 14304 14305 // Some AMD build optimizers, like r.js, check for specific condition patterns 14306 // like the following: 14307 if ( 14308 typeof define == 'function' && 14309 typeof define.amd == 'object' && 14310 define.amd 14311 ) { 14312 define(function () { 14313 return utf8; 14314 }); 14315 } else if (freeExports && !freeExports.nodeType) { 14316 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 14317 freeModule.exports = utf8; 14318 } else { // in Narwhal or RingoJS v0.7.0- 14319 var object = {}; 14320 var hasOwnProperty = object.hasOwnProperty; 14321 for (var key in utf8) { 14322 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 14323 } 14324 } 14325 } else { // in Rhino or a web browser 14326 root.utf8 = utf8; 14327 } 14328 14329 }(this)); 14330 14331 }, {}], 87: [function (require, module, exports) { 14332 module.exports = XMLHttpRequest; 14333 14334 }, {}], "bignumber.js": [function (require, module, exports) { 14335 'use strict'; 14336 14337 module.exports = BigNumber; // jshint ignore:line 14338 14339 14340 }, {}], "web3": [function (require, module, exports) { 14341 var Web3 = require('./lib/web3'); 14342 14343 // dont override global variable 14344 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 14345 window.Web3 = Web3; 14346 } 14347 14348 module.exports = Web3; 14349 14350 }, { "./lib/web3": 22 }] 14351 }, {}, ["web3"]) 14352 //# sourceMappingURL=web3-light.js.map