github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/internal/jsre/deps/web3.js (about) 1 require = (function e(t, n, r) { 2 function s(o, u) { 3 if (!n[o]) { 4 if (!t[o]) { 5 var a = typeof require == "function" && require; 6 if (!u && a) return a(o, !0); 7 if (i) return i(o, !0); 8 var f = new Error("Cannot find module '" + o + "'"); 9 throw f.code = "MODULE_NOT_FOUND", f 10 } 11 var l = n[o] = { 12 exports: {} 13 }; 14 t[o][0].call(l.exports, function(e) { 15 var n = t[o][1][e]; 16 return s(n ? n : e) 17 }, l, l.exports, e, t, n, r) 18 } 19 return n[o].exports 20 } 21 var i = typeof require == "function" && require; 22 for (var o = 0; o < r.length; o++) s(r[o]); 23 return s 24 })({ 25 1: [function(require, module, exports) { 26 module.exports = [{ 27 "constant": true, 28 "inputs": [{ 29 "name": "_owner", 30 "type": "address" 31 }], 32 "name": "name", 33 "outputs": [{ 34 "name": "o_name", 35 "type": "bytes32" 36 }], 37 "type": "function" 38 }, { 39 "constant": true, 40 "inputs": [{ 41 "name": "_name", 42 "type": "bytes32" 43 }], 44 "name": "owner", 45 "outputs": [{ 46 "name": "", 47 "type": "address" 48 }], 49 "type": "function" 50 }, { 51 "constant": true, 52 "inputs": [{ 53 "name": "_name", 54 "type": "bytes32" 55 }], 56 "name": "content", 57 "outputs": [{ 58 "name": "", 59 "type": "bytes32" 60 }], 61 "type": "function" 62 }, { 63 "constant": true, 64 "inputs": [{ 65 "name": "_name", 66 "type": "bytes32" 67 }], 68 "name": "addr", 69 "outputs": [{ 70 "name": "", 71 "type": "address" 72 }], 73 "type": "function" 74 }, { 75 "constant": false, 76 "inputs": [{ 77 "name": "_name", 78 "type": "bytes32" 79 }], 80 "name": "reserve", 81 "outputs": [], 82 "type": "function" 83 }, { 84 "constant": true, 85 "inputs": [{ 86 "name": "_name", 87 "type": "bytes32" 88 }], 89 "name": "subRegistrar", 90 "outputs": [{ 91 "name": "", 92 "type": "address" 93 }], 94 "type": "function" 95 }, { 96 "constant": false, 97 "inputs": [{ 98 "name": "_name", 99 "type": "bytes32" 100 }, { 101 "name": "_newOwner", 102 "type": "address" 103 }], 104 "name": "transfer", 105 "outputs": [], 106 "type": "function" 107 }, { 108 "constant": false, 109 "inputs": [{ 110 "name": "_name", 111 "type": "bytes32" 112 }, { 113 "name": "_registrar", 114 "type": "address" 115 }], 116 "name": "setSubRegistrar", 117 "outputs": [], 118 "type": "function" 119 }, { 120 "constant": false, 121 "inputs": [], 122 "name": "Registrar", 123 "outputs": [], 124 "type": "function" 125 }, { 126 "constant": false, 127 "inputs": [{ 128 "name": "_name", 129 "type": "bytes32" 130 }, { 131 "name": "_a", 132 "type": "address" 133 }, { 134 "name": "_primary", 135 "type": "bool" 136 }], 137 "name": "setAddress", 138 "outputs": [], 139 "type": "function" 140 }, { 141 "constant": false, 142 "inputs": [{ 143 "name": "_name", 144 "type": "bytes32" 145 }, { 146 "name": "_content", 147 "type": "bytes32" 148 }], 149 "name": "setContent", 150 "outputs": [], 151 "type": "function" 152 }, { 153 "constant": false, 154 "inputs": [{ 155 "name": "_name", 156 "type": "bytes32" 157 }], 158 "name": "disown", 159 "outputs": [], 160 "type": "function" 161 }, { 162 "anonymous": false, 163 "inputs": [{ 164 "indexed": true, 165 "name": "_name", 166 "type": "bytes32" 167 }, { 168 "indexed": false, 169 "name": "_winner", 170 "type": "address" 171 }], 172 "name": "AuctionEnded", 173 "type": "event" 174 }, { 175 "anonymous": false, 176 "inputs": [{ 177 "indexed": true, 178 "name": "_name", 179 "type": "bytes32" 180 }, { 181 "indexed": false, 182 "name": "_bidder", 183 "type": "address" 184 }, { 185 "indexed": false, 186 "name": "_value", 187 "type": "uint256" 188 }], 189 "name": "NewBid", 190 "type": "event" 191 }, { 192 "anonymous": false, 193 "inputs": [{ 194 "indexed": true, 195 "name": "name", 196 "type": "bytes32" 197 }], 198 "name": "Changed", 199 "type": "event" 200 }, { 201 "anonymous": false, 202 "inputs": [{ 203 "indexed": true, 204 "name": "name", 205 "type": "bytes32" 206 }, { 207 "indexed": true, 208 "name": "addr", 209 "type": "address" 210 }], 211 "name": "PrimaryChanged", 212 "type": "event" 213 }] 214 215 }, {}], 216 2: [function(require, module, exports) { 217 module.exports = [{ 218 "constant": true, 219 "inputs": [{ 220 "name": "_name", 221 "type": "bytes32" 222 }], 223 "name": "owner", 224 "outputs": [{ 225 "name": "", 226 "type": "address" 227 }], 228 "type": "function" 229 }, { 230 "constant": false, 231 "inputs": [{ 232 "name": "_name", 233 "type": "bytes32" 234 }, { 235 "name": "_refund", 236 "type": "address" 237 }], 238 "name": "disown", 239 "outputs": [], 240 "type": "function" 241 }, { 242 "constant": true, 243 "inputs": [{ 244 "name": "_name", 245 "type": "bytes32" 246 }], 247 "name": "addr", 248 "outputs": [{ 249 "name": "", 250 "type": "address" 251 }], 252 "type": "function" 253 }, { 254 "constant": false, 255 "inputs": [{ 256 "name": "_name", 257 "type": "bytes32" 258 }], 259 "name": "reserve", 260 "outputs": [], 261 "type": "function" 262 }, { 263 "constant": false, 264 "inputs": [{ 265 "name": "_name", 266 "type": "bytes32" 267 }, { 268 "name": "_newOwner", 269 "type": "address" 270 }], 271 "name": "transfer", 272 "outputs": [], 273 "type": "function" 274 }, { 275 "constant": false, 276 "inputs": [{ 277 "name": "_name", 278 "type": "bytes32" 279 }, { 280 "name": "_a", 281 "type": "address" 282 }], 283 "name": "setAddr", 284 "outputs": [], 285 "type": "function" 286 }, { 287 "anonymous": false, 288 "inputs": [{ 289 "indexed": true, 290 "name": "name", 291 "type": "bytes32" 292 }], 293 "name": "Changed", 294 "type": "event" 295 }] 296 297 }, {}], 298 3: [function(require, module, exports) { 299 module.exports = [{ 300 "constant": false, 301 "inputs": [{ 302 "name": "from", 303 "type": "bytes32" 304 }, { 305 "name": "to", 306 "type": "address" 307 }, { 308 "name": "value", 309 "type": "uint256" 310 }], 311 "name": "transfer", 312 "outputs": [], 313 "type": "function" 314 }, { 315 "constant": false, 316 "inputs": [{ 317 "name": "from", 318 "type": "bytes32" 319 }, { 320 "name": "to", 321 "type": "address" 322 }, { 323 "name": "indirectId", 324 "type": "bytes32" 325 }, { 326 "name": "value", 327 "type": "uint256" 328 }], 329 "name": "icapTransfer", 330 "outputs": [], 331 "type": "function" 332 }, { 333 "constant": false, 334 "inputs": [{ 335 "name": "to", 336 "type": "bytes32" 337 }], 338 "name": "deposit", 339 "outputs": [], 340 "payable": true, 341 "type": "function" 342 }, { 343 "anonymous": false, 344 "inputs": [{ 345 "indexed": true, 346 "name": "from", 347 "type": "address" 348 }, { 349 "indexed": false, 350 "name": "value", 351 "type": "uint256" 352 }], 353 "name": "AnonymousDeposit", 354 "type": "event" 355 }, { 356 "anonymous": false, 357 "inputs": [{ 358 "indexed": true, 359 "name": "from", 360 "type": "address" 361 }, { 362 "indexed": true, 363 "name": "to", 364 "type": "bytes32" 365 }, { 366 "indexed": false, 367 "name": "value", 368 "type": "uint256" 369 }], 370 "name": "Deposit", 371 "type": "event" 372 }, { 373 "anonymous": false, 374 "inputs": [{ 375 "indexed": true, 376 "name": "from", 377 "type": "bytes32" 378 }, { 379 "indexed": true, 380 "name": "to", 381 "type": "address" 382 }, { 383 "indexed": false, 384 "name": "value", 385 "type": "uint256" 386 }], 387 "name": "Transfer", 388 "type": "event" 389 }, { 390 "anonymous": false, 391 "inputs": [{ 392 "indexed": true, 393 "name": "from", 394 "type": "bytes32" 395 }, { 396 "indexed": true, 397 "name": "to", 398 "type": "address" 399 }, { 400 "indexed": false, 401 "name": "indirectId", 402 "type": "bytes32" 403 }, { 404 "indexed": false, 405 "name": "value", 406 "type": "uint256" 407 }], 408 "name": "IcapTransfer", 409 "type": "event" 410 }] 411 412 }, {}], 413 4: [function(require, module, exports) { 414 var f = require('./formatters'); 415 var SolidityType = require('./type'); 416 417 /** 418 * SolidityTypeAddress is a prootype that represents address type 419 * It matches: 420 * address 421 * address[] 422 * address[4] 423 * address[][] 424 * address[3][] 425 * address[][6][], ... 426 */ 427 var SolidityTypeAddress = function() { 428 this._inputFormatter = f.formatInputInt; 429 this._outputFormatter = f.formatOutputAddress; 430 }; 431 432 SolidityTypeAddress.prototype = new SolidityType({}); 433 SolidityTypeAddress.prototype.constructor = SolidityTypeAddress; 434 435 SolidityTypeAddress.prototype.isType = function(name) { 436 return !!name.match(/address(\[([0-9]*)\])?/); 437 }; 438 439 module.exports = SolidityTypeAddress; 440 441 }, { 442 "./formatters": 9, 443 "./type": 14 444 }], 445 5: [function(require, module, exports) { 446 var f = require('./formatters'); 447 var SolidityType = require('./type'); 448 449 /** 450 * SolidityTypeBool is a prootype that represents bool type 451 * It matches: 452 * bool 453 * bool[] 454 * bool[4] 455 * bool[][] 456 * bool[3][] 457 * bool[][6][], ... 458 */ 459 var SolidityTypeBool = function() { 460 this._inputFormatter = f.formatInputBool; 461 this._outputFormatter = f.formatOutputBool; 462 }; 463 464 SolidityTypeBool.prototype = new SolidityType({}); 465 SolidityTypeBool.prototype.constructor = SolidityTypeBool; 466 467 SolidityTypeBool.prototype.isType = function(name) { 468 return !!name.match(/^bool(\[([0-9]*)\])*$/); 469 }; 470 471 module.exports = SolidityTypeBool; 472 473 }, { 474 "./formatters": 9, 475 "./type": 14 476 }], 477 6: [function(require, module, exports) { 478 var f = require('./formatters'); 479 var SolidityType = require('./type'); 480 481 /** 482 * SolidityTypeBytes is a prototype that represents the bytes type. 483 * It matches: 484 * bytes 485 * bytes[] 486 * bytes[4] 487 * bytes[][] 488 * bytes[3][] 489 * bytes[][6][], ... 490 * bytes32 491 * bytes8[4] 492 * bytes[3][] 493 */ 494 var SolidityTypeBytes = function() { 495 this._inputFormatter = f.formatInputBytes; 496 this._outputFormatter = f.formatOutputBytes; 497 }; 498 499 SolidityTypeBytes.prototype = new SolidityType({}); 500 SolidityTypeBytes.prototype.constructor = SolidityTypeBytes; 501 502 SolidityTypeBytes.prototype.isType = function(name) { 503 return !!name.match(/^bytes([0-9]{1,})(\[([0-9]*)\])*$/); 504 }; 505 506 module.exports = SolidityTypeBytes; 507 508 }, { 509 "./formatters": 9, 510 "./type": 14 511 }], 512 7: [function(require, module, exports) { 513 /* 514 This file is part of web3.js. 515 516 web3.js is free software: you can redistribute it and/or modify 517 it under the terms of the GNU Lesser General Public License as published by 518 the Free Software Foundation, either version 3 of the License, or 519 (at your option) any later version. 520 521 web3.js is distributed in the hope that it will be useful, 522 but WITHOUT ANY WARRANTY; without even the implied warranty of 523 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 524 GNU Lesser General Public License for more details. 525 526 You should have received a copy of the GNU Lesser General Public License 527 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 528 */ 529 /** 530 * @file coder.js 531 * @author Marek Kotewicz <marek@ethdev.com> 532 * @date 2015 533 */ 534 535 var f = require('./formatters'); 536 537 var SolidityTypeAddress = require('./address'); 538 var SolidityTypeBool = require('./bool'); 539 var SolidityTypeInt = require('./int'); 540 var SolidityTypeUInt = require('./uint'); 541 var SolidityTypeDynamicBytes = require('./dynamicbytes'); 542 var SolidityTypeString = require('./string'); 543 var SolidityTypeReal = require('./real'); 544 var SolidityTypeUReal = require('./ureal'); 545 var SolidityTypeBytes = require('./bytes'); 546 547 var isDynamic = function(solidityType, type) { 548 return solidityType.isDynamicType(type) || 549 solidityType.isDynamicArray(type); 550 }; 551 552 /** 553 * SolidityCoder prototype should be used to encode/decode solidity params of any type 554 */ 555 var SolidityCoder = function(types) { 556 this._types = types; 557 }; 558 559 /** 560 * This method should be used to transform type to SolidityType 561 * 562 * @method _requireType 563 * @param {String} type 564 * @returns {SolidityType} 565 * @throws {Error} throws if no matching type is found 566 */ 567 SolidityCoder.prototype._requireType = function(type) { 568 var solidityType = this._types.filter(function(t) { 569 return t.isType(type); 570 })[0]; 571 572 if (!solidityType) { 573 throw Error('invalid solidity type!: ' + type); 574 } 575 576 return solidityType; 577 }; 578 579 /** 580 * Should be used to encode plain param 581 * 582 * @method encodeParam 583 * @param {String} type 584 * @param {Object} plain param 585 * @return {String} encoded plain param 586 */ 587 SolidityCoder.prototype.encodeParam = function(type, param) { 588 return this.encodeParams([type], [param]); 589 }; 590 591 /** 592 * Should be used to encode list of params 593 * 594 * @method encodeParams 595 * @param {Array} types 596 * @param {Array} params 597 * @return {String} encoded list of params 598 */ 599 SolidityCoder.prototype.encodeParams = function(types, params) { 600 var solidityTypes = this.getSolidityTypes(types); 601 602 var encodeds = solidityTypes.map(function(solidityType, index) { 603 return solidityType.encode(params[index], types[index]); 604 }); 605 606 var dynamicOffset = solidityTypes.reduce(function(acc, solidityType, index) { 607 var staticPartLength = solidityType.staticPartLength(types[index]); 608 var roundedStaticPartLength = Math.floor((staticPartLength + 31) / 32) * 32; 609 610 return acc + (isDynamic(solidityTypes[index], types[index]) ? 611 32 : 612 roundedStaticPartLength); 613 }, 0); 614 615 var result = this.encodeMultiWithOffset(types, solidityTypes, encodeds, dynamicOffset); 616 617 return result; 618 }; 619 620 SolidityCoder.prototype.encodeMultiWithOffset = function(types, solidityTypes, encodeds, dynamicOffset) { 621 var result = ""; 622 var self = this; 623 624 types.forEach(function(type, i) { 625 if (isDynamic(solidityTypes[i], types[i])) { 626 result += f.formatInputInt(dynamicOffset).encode(); 627 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 628 dynamicOffset += e.length / 2; 629 } else { 630 // don't add length to dynamicOffset. it's already counted 631 result += self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 632 } 633 634 // TODO: figure out nested arrays 635 }); 636 637 types.forEach(function(type, i) { 638 if (isDynamic(solidityTypes[i], types[i])) { 639 var e = self.encodeWithOffset(types[i], solidityTypes[i], encodeds[i], dynamicOffset); 640 dynamicOffset += e.length / 2; 641 result += e; 642 } 643 }); 644 return result; 645 }; 646 647 // TODO: refactor whole encoding! 648 SolidityCoder.prototype.encodeWithOffset = function(type, solidityType, encoded, offset) { 649 var self = this; 650 if (solidityType.isDynamicArray(type)) { 651 return (function() { 652 // offset was already set 653 var nestedName = solidityType.nestedName(type); 654 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 655 var result = encoded[0]; 656 657 (function() { 658 var previousLength = 2; // in int 659 if (solidityType.isDynamicArray(nestedName)) { 660 for (var i = 1; i < encoded.length; i++) { 661 previousLength += +(encoded[i - 1])[0] || 0; 662 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 663 } 664 } 665 })(); 666 667 // first element is length, skip it 668 (function() { 669 for (var i = 0; i < encoded.length - 1; i++) { 670 var additionalOffset = result / 2; 671 result += self.encodeWithOffset(nestedName, solidityType, encoded[i + 1], offset + additionalOffset); 672 } 673 })(); 674 675 return result; 676 })(); 677 678 } else if (solidityType.isStaticArray(type)) { 679 return (function() { 680 var nestedName = solidityType.nestedName(type); 681 var nestedStaticPartLength = solidityType.staticPartLength(nestedName); 682 var result = ""; 683 684 685 if (solidityType.isDynamicArray(nestedName)) { 686 (function() { 687 var previousLength = 0; // in int 688 for (var i = 0; i < encoded.length; i++) { 689 // calculate length of previous item 690 previousLength += +(encoded[i - 1] || [])[0] || 0; 691 result += f.formatInputInt(offset + i * nestedStaticPartLength + previousLength * 32).encode(); 692 } 693 })(); 694 } 695 696 (function() { 697 for (var i = 0; i < encoded.length; i++) { 698 var additionalOffset = result / 2; 699 result += self.encodeWithOffset(nestedName, solidityType, encoded[i], offset + additionalOffset); 700 } 701 })(); 702 703 return result; 704 })(); 705 } 706 707 return encoded; 708 }; 709 710 /** 711 * Should be used to decode bytes to plain param 712 * 713 * @method decodeParam 714 * @param {String} type 715 * @param {String} bytes 716 * @return {Object} plain param 717 */ 718 SolidityCoder.prototype.decodeParam = function(type, bytes) { 719 return this.decodeParams([type], bytes)[0]; 720 }; 721 722 /** 723 * Should be used to decode list of params 724 * 725 * @method decodeParam 726 * @param {Array} types 727 * @param {String} bytes 728 * @return {Array} array of plain params 729 */ 730 SolidityCoder.prototype.decodeParams = function(types, bytes) { 731 var solidityTypes = this.getSolidityTypes(types); 732 var offsets = this.getOffsets(types, solidityTypes); 733 734 return solidityTypes.map(function(solidityType, index) { 735 return solidityType.decode(bytes, offsets[index], types[index], index); 736 }); 737 }; 738 739 SolidityCoder.prototype.getOffsets = function(types, solidityTypes) { 740 var lengths = solidityTypes.map(function(solidityType, index) { 741 return solidityType.staticPartLength(types[index]); 742 }); 743 744 for (var i = 1; i < lengths.length; i++) { 745 // sum with length of previous element 746 lengths[i] += lengths[i - 1]; 747 } 748 749 return lengths.map(function(length, index) { 750 // remove the current length, so the length is sum of previous elements 751 var staticPartLength = solidityTypes[index].staticPartLength(types[index]); 752 return length - staticPartLength; 753 }); 754 }; 755 756 SolidityCoder.prototype.getSolidityTypes = function(types) { 757 var self = this; 758 return types.map(function(type) { 759 return self._requireType(type); 760 }); 761 }; 762 763 var coder = new SolidityCoder([ 764 new SolidityTypeAddress(), 765 new SolidityTypeBool(), 766 new SolidityTypeInt(), 767 new SolidityTypeUInt(), 768 new SolidityTypeDynamicBytes(), 769 new SolidityTypeBytes(), 770 new SolidityTypeString(), 771 new SolidityTypeReal(), 772 new SolidityTypeUReal() 773 ]); 774 775 module.exports = coder; 776 777 }, { 778 "./address": 4, 779 "./bool": 5, 780 "./bytes": 6, 781 "./dynamicbytes": 8, 782 "./formatters": 9, 783 "./int": 10, 784 "./real": 12, 785 "./string": 13, 786 "./uint": 15, 787 "./ureal": 16 788 }], 789 8: [function(require, module, exports) { 790 var f = require('./formatters'); 791 var SolidityType = require('./type'); 792 793 var SolidityTypeDynamicBytes = function() { 794 this._inputFormatter = f.formatInputDynamicBytes; 795 this._outputFormatter = f.formatOutputDynamicBytes; 796 }; 797 798 SolidityTypeDynamicBytes.prototype = new SolidityType({}); 799 SolidityTypeDynamicBytes.prototype.constructor = SolidityTypeDynamicBytes; 800 801 SolidityTypeDynamicBytes.prototype.isType = function(name) { 802 return !!name.match(/^bytes(\[([0-9]*)\])*$/); 803 }; 804 805 SolidityTypeDynamicBytes.prototype.isDynamicType = function() { 806 return true; 807 }; 808 809 module.exports = SolidityTypeDynamicBytes; 810 811 }, { 812 "./formatters": 9, 813 "./type": 14 814 }], 815 9: [function(require, module, exports) { 816 /* 817 This file is part of web3.js. 818 819 web3.js is free software: you can redistribute it and/or modify 820 it under the terms of the GNU Lesser General Public License as published by 821 the Free Software Foundation, either version 3 of the License, or 822 (at your option) any later version. 823 824 web3.js is distributed in the hope that it will be useful, 825 but WITHOUT ANY WARRANTY; without even the implied warranty of 826 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 827 GNU Lesser General Public License for more details. 828 829 You should have received a copy of the GNU Lesser General Public License 830 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 831 */ 832 /** 833 * @file formatters.js 834 * @author Marek Kotewicz <marek@ethdev.com> 835 * @date 2015 836 */ 837 838 var BigNumber = require('bignumber.js'); 839 var utils = require('../utils/utils'); 840 var c = require('../utils/config'); 841 var SolidityParam = require('./param'); 842 843 844 /** 845 * Formats input value to byte representation of int 846 * If value is negative, return it's two's complement 847 * If the value is floating point, round it down 848 * 849 * @method formatInputInt 850 * @param {String|Number|BigNumber} value that needs to be formatted 851 * @returns {SolidityParam} 852 */ 853 var formatInputInt = function(value) { 854 BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE); 855 var result = utils.padLeft(utils.toTwosComplement(value).toString(16), 64); 856 return new SolidityParam(result); 857 }; 858 859 /** 860 * Formats input bytes 861 * 862 * @method formatInputBytes 863 * @param {String} 864 * @returns {SolidityParam} 865 */ 866 var formatInputBytes = function(value) { 867 var result = utils.toHex(value).substr(2); 868 var l = Math.floor((result.length + 63) / 64); 869 result = utils.padRight(result, l * 64); 870 return new SolidityParam(result); 871 }; 872 873 /** 874 * Formats input bytes 875 * 876 * @method formatDynamicInputBytes 877 * @param {String} 878 * @returns {SolidityParam} 879 */ 880 var formatInputDynamicBytes = function(value) { 881 var result = utils.toHex(value).substr(2); 882 var length = result.length / 2; 883 var l = Math.floor((result.length + 63) / 64); 884 result = utils.padRight(result, l * 64); 885 return new SolidityParam(formatInputInt(length).value + result); 886 }; 887 888 /** 889 * Formats input value to byte representation of string 890 * 891 * @method formatInputString 892 * @param {String} 893 * @returns {SolidityParam} 894 */ 895 var formatInputString = function(value) { 896 var result = utils.fromUtf8(value).substr(2); 897 var length = result.length / 2; 898 var l = Math.floor((result.length + 63) / 64); 899 result = utils.padRight(result, l * 64); 900 return new SolidityParam(formatInputInt(length).value + result); 901 }; 902 903 /** 904 * Formats input value to byte representation of bool 905 * 906 * @method formatInputBool 907 * @param {Boolean} 908 * @returns {SolidityParam} 909 */ 910 var formatInputBool = function(value) { 911 var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0'); 912 return new SolidityParam(result); 913 }; 914 915 /** 916 * Formats input value to byte representation of real 917 * Values are multiplied by 2^m and encoded as integers 918 * 919 * @method formatInputReal 920 * @param {String|Number|BigNumber} 921 * @returns {SolidityParam} 922 */ 923 var formatInputReal = function(value) { 924 return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); 925 }; 926 927 /** 928 * Check if input value is negative 929 * 930 * @method signedIsNegative 931 * @param {String} value is hex format 932 * @returns {Boolean} true if it is negative, otherwise false 933 */ 934 var signedIsNegative = function(value) { 935 return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1'; 936 }; 937 938 /** 939 * Formats right-aligned output bytes to int 940 * 941 * @method formatOutputInt 942 * @param {SolidityParam} param 943 * @returns {BigNumber} right-aligned output bytes formatted to big number 944 */ 945 var formatOutputInt = function(param) { 946 var value = param.staticPart() || "0"; 947 948 // check if it's negative number 949 // it is, return two's complement 950 if (signedIsNegative(value)) { 951 return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1); 952 } 953 return new BigNumber(value, 16); 954 }; 955 956 /** 957 * Formats right-aligned output bytes to uint 958 * 959 * @method formatOutputUInt 960 * @param {SolidityParam} 961 * @returns {BigNumeber} right-aligned output bytes formatted to uint 962 */ 963 var formatOutputUInt = function(param) { 964 var value = param.staticPart() || "0"; 965 return new BigNumber(value, 16); 966 }; 967 968 /** 969 * Formats right-aligned output bytes to real 970 * 971 * @method formatOutputReal 972 * @param {SolidityParam} 973 * @returns {BigNumber} input bytes formatted to real 974 */ 975 var formatOutputReal = function(param) { 976 return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128)); 977 }; 978 979 /** 980 * Formats right-aligned output bytes to ureal 981 * 982 * @method formatOutputUReal 983 * @param {SolidityParam} 984 * @returns {BigNumber} input bytes formatted to ureal 985 */ 986 var formatOutputUReal = function(param) { 987 return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128)); 988 }; 989 990 /** 991 * Should be used to format output bool 992 * 993 * @method formatOutputBool 994 * @param {SolidityParam} 995 * @returns {Boolean} right-aligned input bytes formatted to bool 996 */ 997 var formatOutputBool = function(param) { 998 return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false; 999 }; 1000 1001 /** 1002 * Should be used to format output bytes 1003 * 1004 * @method formatOutputBytes 1005 * @param {SolidityParam} left-aligned hex representation of string 1006 * @param {String} name type name 1007 * @returns {String} hex string 1008 */ 1009 var formatOutputBytes = function(param, name) { 1010 var matches = name.match(/^bytes([0-9]*)/); 1011 var size = parseInt(matches[1]); 1012 return '0x' + param.staticPart().slice(0, 2 * size); 1013 }; 1014 1015 /** 1016 * Should be used to format output bytes 1017 * 1018 * @method formatOutputDynamicBytes 1019 * @param {SolidityParam} left-aligned hex representation of string 1020 * @returns {String} hex string 1021 */ 1022 var formatOutputDynamicBytes = function(param) { 1023 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1024 return '0x' + param.dynamicPart().substr(64, length); 1025 }; 1026 1027 /** 1028 * Should be used to format output string 1029 * 1030 * @method formatOutputString 1031 * @param {SolidityParam} left-aligned hex representation of string 1032 * @returns {String} ascii string 1033 */ 1034 var formatOutputString = function(param) { 1035 var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2; 1036 return utils.toUtf8(param.dynamicPart().substr(64, length)); 1037 }; 1038 1039 /** 1040 * Should be used to format output address 1041 * 1042 * @method formatOutputAddress 1043 * @param {SolidityParam} right-aligned input bytes 1044 * @returns {String} address 1045 */ 1046 var formatOutputAddress = function(param) { 1047 var value = param.staticPart(); 1048 return "0x" + value.slice(value.length - 40, value.length); 1049 }; 1050 1051 module.exports = { 1052 formatInputInt: formatInputInt, 1053 formatInputBytes: formatInputBytes, 1054 formatInputDynamicBytes: formatInputDynamicBytes, 1055 formatInputString: formatInputString, 1056 formatInputBool: formatInputBool, 1057 formatInputReal: formatInputReal, 1058 formatOutputInt: formatOutputInt, 1059 formatOutputUInt: formatOutputUInt, 1060 formatOutputReal: formatOutputReal, 1061 formatOutputUReal: formatOutputUReal, 1062 formatOutputBool: formatOutputBool, 1063 formatOutputBytes: formatOutputBytes, 1064 formatOutputDynamicBytes: formatOutputDynamicBytes, 1065 formatOutputString: formatOutputString, 1066 formatOutputAddress: formatOutputAddress 1067 }; 1068 1069 }, { 1070 "../utils/config": 18, 1071 "../utils/utils": 20, 1072 "./param": 11, 1073 "bignumber.js": "bignumber.js" 1074 }], 1075 10: [function(require, module, exports) { 1076 var f = require('./formatters'); 1077 var SolidityType = require('./type'); 1078 1079 /** 1080 * SolidityTypeInt is a prootype that represents int type 1081 * It matches: 1082 * int 1083 * int[] 1084 * int[4] 1085 * int[][] 1086 * int[3][] 1087 * int[][6][], ... 1088 * int32 1089 * int64[] 1090 * int8[4] 1091 * int256[][] 1092 * int[3][] 1093 * int64[][6][], ... 1094 */ 1095 var SolidityTypeInt = function() { 1096 this._inputFormatter = f.formatInputInt; 1097 this._outputFormatter = f.formatOutputInt; 1098 }; 1099 1100 SolidityTypeInt.prototype = new SolidityType({}); 1101 SolidityTypeInt.prototype.constructor = SolidityTypeInt; 1102 1103 SolidityTypeInt.prototype.isType = function(name) { 1104 return !!name.match(/^int([0-9]*)?(\[([0-9]*)\])*$/); 1105 }; 1106 1107 module.exports = SolidityTypeInt; 1108 1109 }, { 1110 "./formatters": 9, 1111 "./type": 14 1112 }], 1113 11: [function(require, module, exports) { 1114 /* 1115 This file is part of web3.js. 1116 1117 web3.js is free software: you can redistribute it and/or modify 1118 it under the terms of the GNU Lesser General Public License as published by 1119 the Free Software Foundation, either version 3 of the License, or 1120 (at your option) any later version. 1121 1122 web3.js is distributed in the hope that it will be useful, 1123 but WITHOUT ANY WARRANTY; without even the implied warranty of 1124 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1125 GNU Lesser General Public License for more details. 1126 1127 You should have received a copy of the GNU Lesser General Public License 1128 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1129 */ 1130 /** 1131 * @file param.js 1132 * @author Marek Kotewicz <marek@ethdev.com> 1133 * @date 2015 1134 */ 1135 1136 var utils = require('../utils/utils'); 1137 1138 /** 1139 * SolidityParam object prototype. 1140 * Should be used when encoding, decoding solidity bytes 1141 */ 1142 var SolidityParam = function(value, offset) { 1143 this.value = value || ''; 1144 this.offset = offset; // offset in bytes 1145 }; 1146 1147 /** 1148 * This method should be used to get length of params's dynamic part 1149 * 1150 * @method dynamicPartLength 1151 * @returns {Number} length of dynamic part (in bytes) 1152 */ 1153 SolidityParam.prototype.dynamicPartLength = function() { 1154 return this.dynamicPart().length / 2; 1155 }; 1156 1157 /** 1158 * This method should be used to create copy of solidity param with different offset 1159 * 1160 * @method withOffset 1161 * @param {Number} offset length in bytes 1162 * @returns {SolidityParam} new solidity param with applied offset 1163 */ 1164 SolidityParam.prototype.withOffset = function(offset) { 1165 return new SolidityParam(this.value, offset); 1166 }; 1167 1168 /** 1169 * This method should be used to combine solidity params together 1170 * eg. when appending an array 1171 * 1172 * @method combine 1173 * @param {SolidityParam} param with which we should combine 1174 * @param {SolidityParam} result of combination 1175 */ 1176 SolidityParam.prototype.combine = function(param) { 1177 return new SolidityParam(this.value + param.value); 1178 }; 1179 1180 /** 1181 * This method should be called to check if param has dynamic size. 1182 * If it has, it returns true, otherwise false 1183 * 1184 * @method isDynamic 1185 * @returns {Boolean} 1186 */ 1187 SolidityParam.prototype.isDynamic = function() { 1188 return this.offset !== undefined; 1189 }; 1190 1191 /** 1192 * This method should be called to transform offset to bytes 1193 * 1194 * @method offsetAsBytes 1195 * @returns {String} bytes representation of offset 1196 */ 1197 SolidityParam.prototype.offsetAsBytes = function() { 1198 return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64); 1199 }; 1200 1201 /** 1202 * This method should be called to get static part of param 1203 * 1204 * @method staticPart 1205 * @returns {String} offset if it is a dynamic param, otherwise value 1206 */ 1207 SolidityParam.prototype.staticPart = function() { 1208 if (!this.isDynamic()) { 1209 return this.value; 1210 } 1211 return this.offsetAsBytes(); 1212 }; 1213 1214 /** 1215 * This method should be called to get dynamic part of param 1216 * 1217 * @method dynamicPart 1218 * @returns {String} returns a value if it is a dynamic param, otherwise empty string 1219 */ 1220 SolidityParam.prototype.dynamicPart = function() { 1221 return this.isDynamic() ? this.value : ''; 1222 }; 1223 1224 /** 1225 * This method should be called to encode param 1226 * 1227 * @method encode 1228 * @returns {String} 1229 */ 1230 SolidityParam.prototype.encode = function() { 1231 return this.staticPart() + this.dynamicPart(); 1232 }; 1233 1234 /** 1235 * This method should be called to encode array of params 1236 * 1237 * @method encodeList 1238 * @param {Array[SolidityParam]} params 1239 * @returns {String} 1240 */ 1241 SolidityParam.encodeList = function(params) { 1242 1243 // updating offsets 1244 var totalOffset = params.length * 32; 1245 var offsetParams = params.map(function(param) { 1246 if (!param.isDynamic()) { 1247 return param; 1248 } 1249 var offset = totalOffset; 1250 totalOffset += param.dynamicPartLength(); 1251 return param.withOffset(offset); 1252 }); 1253 1254 // encode everything! 1255 return offsetParams.reduce(function(result, param) { 1256 return result + param.dynamicPart(); 1257 }, offsetParams.reduce(function(result, param) { 1258 return result + param.staticPart(); 1259 }, '')); 1260 }; 1261 1262 1263 1264 module.exports = SolidityParam; 1265 1266 1267 }, { 1268 "../utils/utils": 20 1269 }], 1270 12: [function(require, module, exports) { 1271 var f = require('./formatters'); 1272 var SolidityType = require('./type'); 1273 1274 /** 1275 * SolidityTypeReal is a prootype that represents real type 1276 * It matches: 1277 * real 1278 * real[] 1279 * real[4] 1280 * real[][] 1281 * real[3][] 1282 * real[][6][], ... 1283 * real32 1284 * real64[] 1285 * real8[4] 1286 * real256[][] 1287 * real[3][] 1288 * real64[][6][], ... 1289 */ 1290 var SolidityTypeReal = function() { 1291 this._inputFormatter = f.formatInputReal; 1292 this._outputFormatter = f.formatOutputReal; 1293 }; 1294 1295 SolidityTypeReal.prototype = new SolidityType({}); 1296 SolidityTypeReal.prototype.constructor = SolidityTypeReal; 1297 1298 SolidityTypeReal.prototype.isType = function(name) { 1299 return !!name.match(/real([0-9]*)?(\[([0-9]*)\])?/); 1300 }; 1301 1302 module.exports = SolidityTypeReal; 1303 1304 }, { 1305 "./formatters": 9, 1306 "./type": 14 1307 }], 1308 13: [function(require, module, exports) { 1309 var f = require('./formatters'); 1310 var SolidityType = require('./type'); 1311 1312 var SolidityTypeString = function() { 1313 this._inputFormatter = f.formatInputString; 1314 this._outputFormatter = f.formatOutputString; 1315 }; 1316 1317 SolidityTypeString.prototype = new SolidityType({}); 1318 SolidityTypeString.prototype.constructor = SolidityTypeString; 1319 1320 SolidityTypeString.prototype.isType = function(name) { 1321 return !!name.match(/^string(\[([0-9]*)\])*$/); 1322 }; 1323 1324 SolidityTypeString.prototype.isDynamicType = function() { 1325 return true; 1326 }; 1327 1328 module.exports = SolidityTypeString; 1329 1330 }, { 1331 "./formatters": 9, 1332 "./type": 14 1333 }], 1334 14: [function(require, module, exports) { 1335 var f = require('./formatters'); 1336 var SolidityParam = require('./param'); 1337 1338 /** 1339 * SolidityType prototype is used to encode/decode solidity params of certain type 1340 */ 1341 var SolidityType = function(config) { 1342 this._inputFormatter = config.inputFormatter; 1343 this._outputFormatter = config.outputFormatter; 1344 }; 1345 1346 /** 1347 * Should be used to determine if this SolidityType do match given name 1348 * 1349 * @method isType 1350 * @param {String} name 1351 * @return {Bool} true if type match this SolidityType, otherwise false 1352 */ 1353 SolidityType.prototype.isType = function(name) { 1354 throw "this method should be overrwritten for type " + name; 1355 }; 1356 1357 /** 1358 * Should be used to determine what is the length of static part in given type 1359 * 1360 * @method staticPartLength 1361 * @param {String} name 1362 * @return {Number} length of static part in bytes 1363 */ 1364 SolidityType.prototype.staticPartLength = function(name) { 1365 // If name isn't an array then treat it like a single element array. 1366 return (this.nestedTypes(name) || ['[1]']) 1367 .map(function(type) { 1368 // the length of the nested array 1369 return parseInt(type.slice(1, -1), 10) || 1; 1370 }) 1371 .reduce(function(previous, current) { 1372 return previous * current; 1373 // all basic types are 32 bytes long 1374 }, 32); 1375 }; 1376 1377 /** 1378 * Should be used to determine if type is dynamic array 1379 * eg: 1380 * "type[]" => true 1381 * "type[4]" => false 1382 * 1383 * @method isDynamicArray 1384 * @param {String} name 1385 * @return {Bool} true if the type is dynamic array 1386 */ 1387 SolidityType.prototype.isDynamicArray = function(name) { 1388 var nestedTypes = this.nestedTypes(name); 1389 return !!nestedTypes && !nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1390 }; 1391 1392 /** 1393 * Should be used to determine if type is static array 1394 * eg: 1395 * "type[]" => false 1396 * "type[4]" => true 1397 * 1398 * @method isStaticArray 1399 * @param {String} name 1400 * @return {Bool} true if the type is static array 1401 */ 1402 SolidityType.prototype.isStaticArray = function(name) { 1403 var nestedTypes = this.nestedTypes(name); 1404 return !!nestedTypes && !!nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g); 1405 }; 1406 1407 /** 1408 * Should return length of static array 1409 * eg. 1410 * "int[32]" => 32 1411 * "int256[14]" => 14 1412 * "int[2][3]" => 3 1413 * "int" => 1 1414 * "int[1]" => 1 1415 * "int[]" => 1 1416 * 1417 * @method staticArrayLength 1418 * @param {String} name 1419 * @return {Number} static array length 1420 */ 1421 SolidityType.prototype.staticArrayLength = function(name) { 1422 var nestedTypes = this.nestedTypes(name); 1423 if (nestedTypes) { 1424 return parseInt(nestedTypes[nestedTypes.length - 1].match(/[0-9]{1,}/g) || 1); 1425 } 1426 return 1; 1427 }; 1428 1429 /** 1430 * Should return nested type 1431 * eg. 1432 * "int[32]" => "int" 1433 * "int256[14]" => "int256" 1434 * "int[2][3]" => "int[2]" 1435 * "int" => "int" 1436 * "int[]" => "int" 1437 * 1438 * @method nestedName 1439 * @param {String} name 1440 * @return {String} nested name 1441 */ 1442 SolidityType.prototype.nestedName = function(name) { 1443 // remove last [] in name 1444 var nestedTypes = this.nestedTypes(name); 1445 if (!nestedTypes) { 1446 return name; 1447 } 1448 1449 return name.substr(0, name.length - nestedTypes[nestedTypes.length - 1].length); 1450 }; 1451 1452 /** 1453 * Should return true if type has dynamic size by default 1454 * such types are "string", "bytes" 1455 * 1456 * @method isDynamicType 1457 * @param {String} name 1458 * @return {Bool} true if is dynamic, otherwise false 1459 */ 1460 SolidityType.prototype.isDynamicType = function() { 1461 return false; 1462 }; 1463 1464 /** 1465 * Should return array of nested types 1466 * eg. 1467 * "int[2][3][]" => ["[2]", "[3]", "[]"] 1468 * "int[] => ["[]"] 1469 * "int" => null 1470 * 1471 * @method nestedTypes 1472 * @param {String} name 1473 * @return {Array} array of nested types 1474 */ 1475 SolidityType.prototype.nestedTypes = function(name) { 1476 // return list of strings eg. "[]", "[3]", "[]", "[2]" 1477 return name.match(/(\[[0-9]*\])/g); 1478 }; 1479 1480 /** 1481 * Should be used to encode the value 1482 * 1483 * @method encode 1484 * @param {Object} value 1485 * @param {String} name 1486 * @return {String} encoded value 1487 */ 1488 SolidityType.prototype.encode = function(value, name) { 1489 var self = this; 1490 if (this.isDynamicArray(name)) { 1491 1492 return (function() { 1493 var length = value.length; // in int 1494 var nestedName = self.nestedName(name); 1495 1496 var result = []; 1497 result.push(f.formatInputInt(length).encode()); 1498 1499 value.forEach(function(v) { 1500 result.push(self.encode(v, nestedName)); 1501 }); 1502 1503 return result; 1504 })(); 1505 1506 } else if (this.isStaticArray(name)) { 1507 1508 return (function() { 1509 var length = self.staticArrayLength(name); // in int 1510 var nestedName = self.nestedName(name); 1511 1512 var result = []; 1513 for (var i = 0; i < length; i++) { 1514 result.push(self.encode(value[i], nestedName)); 1515 } 1516 1517 return result; 1518 })(); 1519 1520 } 1521 1522 return this._inputFormatter(value, name).encode(); 1523 }; 1524 1525 /** 1526 * Should be used to decode value from bytes 1527 * 1528 * @method decode 1529 * @param {String} bytes 1530 * @param {Number} offset in bytes 1531 * @param {String} name type name 1532 * @returns {Object} decoded value 1533 */ 1534 SolidityType.prototype.decode = function(bytes, offset, name) { 1535 var self = this; 1536 1537 if (this.isDynamicArray(name)) { 1538 1539 return (function() { 1540 var arrayOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1541 var length = parseInt('0x' + bytes.substr(arrayOffset * 2, 64)); // in int 1542 var arrayStart = arrayOffset + 32; // array starts after length; // in bytes 1543 1544 var nestedName = self.nestedName(name); 1545 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1546 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1547 var result = []; 1548 1549 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1550 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1551 } 1552 1553 return result; 1554 })(); 1555 1556 } else if (this.isStaticArray(name)) { 1557 1558 return (function() { 1559 var length = self.staticArrayLength(name); // in int 1560 var arrayStart = offset; // in bytes 1561 1562 var nestedName = self.nestedName(name); 1563 var nestedStaticPartLength = self.staticPartLength(nestedName); // in bytes 1564 var roundedNestedStaticPartLength = Math.floor((nestedStaticPartLength + 31) / 32) * 32; 1565 var result = []; 1566 1567 for (var i = 0; i < length * roundedNestedStaticPartLength; i += roundedNestedStaticPartLength) { 1568 result.push(self.decode(bytes, arrayStart + i, nestedName)); 1569 } 1570 1571 return result; 1572 })(); 1573 } else if (this.isDynamicType(name)) { 1574 1575 return (function() { 1576 var dynamicOffset = parseInt('0x' + bytes.substr(offset * 2, 64)); // in bytes 1577 var length = parseInt('0x' + bytes.substr(dynamicOffset * 2, 64)); // in bytes 1578 var roundedLength = Math.floor((length + 31) / 32); // in int 1579 var param = new SolidityParam(bytes.substr(dynamicOffset * 2, (1 + roundedLength) * 64), 0); 1580 return self._outputFormatter(param, name); 1581 })(); 1582 } 1583 1584 var length = this.staticPartLength(name); 1585 var param = new SolidityParam(bytes.substr(offset * 2, length * 2)); 1586 return this._outputFormatter(param, name); 1587 }; 1588 1589 module.exports = SolidityType; 1590 1591 }, { 1592 "./formatters": 9, 1593 "./param": 11 1594 }], 1595 15: [function(require, module, exports) { 1596 var f = require('./formatters'); 1597 var SolidityType = require('./type'); 1598 1599 /** 1600 * SolidityTypeUInt is a prootype that represents uint type 1601 * It matches: 1602 * uint 1603 * uint[] 1604 * uint[4] 1605 * uint[][] 1606 * uint[3][] 1607 * uint[][6][], ... 1608 * uint32 1609 * uint64[] 1610 * uint8[4] 1611 * uint256[][] 1612 * uint[3][] 1613 * uint64[][6][], ... 1614 */ 1615 var SolidityTypeUInt = function() { 1616 this._inputFormatter = f.formatInputInt; 1617 this._outputFormatter = f.formatOutputUInt; 1618 }; 1619 1620 SolidityTypeUInt.prototype = new SolidityType({}); 1621 SolidityTypeUInt.prototype.constructor = SolidityTypeUInt; 1622 1623 SolidityTypeUInt.prototype.isType = function(name) { 1624 return !!name.match(/^uint([0-9]*)?(\[([0-9]*)\])*$/); 1625 }; 1626 1627 module.exports = SolidityTypeUInt; 1628 1629 }, { 1630 "./formatters": 9, 1631 "./type": 14 1632 }], 1633 16: [function(require, module, exports) { 1634 var f = require('./formatters'); 1635 var SolidityType = require('./type'); 1636 1637 /** 1638 * SolidityTypeUReal is a prootype that represents ureal type 1639 * It matches: 1640 * ureal 1641 * ureal[] 1642 * ureal[4] 1643 * ureal[][] 1644 * ureal[3][] 1645 * ureal[][6][], ... 1646 * ureal32 1647 * ureal64[] 1648 * ureal8[4] 1649 * ureal256[][] 1650 * ureal[3][] 1651 * ureal64[][6][], ... 1652 */ 1653 var SolidityTypeUReal = function() { 1654 this._inputFormatter = f.formatInputReal; 1655 this._outputFormatter = f.formatOutputUReal; 1656 }; 1657 1658 SolidityTypeUReal.prototype = new SolidityType({}); 1659 SolidityTypeUReal.prototype.constructor = SolidityTypeUReal; 1660 1661 SolidityTypeUReal.prototype.isType = function(name) { 1662 return !!name.match(/^ureal([0-9]*)?(\[([0-9]*)\])*$/); 1663 }; 1664 1665 module.exports = SolidityTypeUReal; 1666 1667 }, { 1668 "./formatters": 9, 1669 "./type": 14 1670 }], 1671 17: [function(require, module, exports) { 1672 'use strict'; 1673 1674 // go env doesn't have and need XMLHttpRequest 1675 if (typeof XMLHttpRequest === 'undefined') { 1676 exports.XMLHttpRequest = {}; 1677 } else { 1678 exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line 1679 } 1680 1681 1682 }, {}], 1683 18: [function(require, module, exports) { 1684 /* 1685 This file is part of web3.js. 1686 1687 web3.js is free software: you can redistribute it and/or modify 1688 it under the terms of the GNU Lesser General Public License as published by 1689 the Free Software Foundation, either version 3 of the License, or 1690 (at your option) any later version. 1691 1692 web3.js is distributed in the hope that it will be useful, 1693 but WITHOUT ANY WARRANTY; without even the implied warranty of 1694 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1695 GNU Lesser General Public License for more details. 1696 1697 You should have received a copy of the GNU Lesser General Public License 1698 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1699 */ 1700 /** @file config.js 1701 * @authors: 1702 * Marek Kotewicz <marek@ethdev.com> 1703 * @date 2015 1704 */ 1705 1706 /** 1707 * Utils 1708 * 1709 * @module utils 1710 */ 1711 1712 /** 1713 * Utility functions 1714 * 1715 * @class [utils] config 1716 * @constructor 1717 */ 1718 1719 1720 /// required to define ETH_BIGNUMBER_ROUNDING_MODE 1721 var BigNumber = require('bignumber.js'); 1722 1723 var ETH_UNITS = [ 1724 'wei', 1725 'kwei', 1726 'Mwei', 1727 'Gwei', 1728 'szabo', 1729 'finney', 1730 'femtoether', 1731 'picoether', 1732 'nanoether', 1733 'microether', 1734 'milliether', 1735 'nano', 1736 'micro', 1737 'milli', 1738 'ether', 1739 'grand', 1740 'Mether', 1741 'Gether', 1742 'Tether', 1743 'Pether', 1744 'Eether', 1745 'Zether', 1746 'Yether', 1747 'Nether', 1748 'Dether', 1749 'Vether', 1750 'Uether' 1751 ]; 1752 1753 module.exports = { 1754 ETH_PADDING: 32, 1755 ETH_SIGNATURE_LENGTH: 4, 1756 ETH_UNITS: ETH_UNITS, 1757 ETH_BIGNUMBER_ROUNDING_MODE: { 1758 ROUNDING_MODE: BigNumber.ROUND_DOWN 1759 }, 1760 ETH_POLLING_TIMEOUT: 1000 / 2, 1761 defaultBlock: 'latest', 1762 defaultAccount: undefined 1763 }; 1764 1765 1766 }, { 1767 "bignumber.js": "bignumber.js" 1768 }], 1769 19: [function(require, module, exports) { 1770 /* 1771 This file is part of web3.js. 1772 1773 web3.js is free software: you can redistribute it and/or modify 1774 it under the terms of the GNU Lesser General Public License as published by 1775 the Free Software Foundation, either version 3 of the License, or 1776 (at your option) any later version. 1777 1778 web3.js is distributed in the hope that it will be useful, 1779 but WITHOUT ANY WARRANTY; without even the implied warranty of 1780 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1781 GNU Lesser General Public License for more details. 1782 1783 You should have received a copy of the GNU Lesser General Public License 1784 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1785 */ 1786 /** 1787 * @file sha3.js 1788 * @author Marek Kotewicz <marek@ethdev.com> 1789 * @date 2015 1790 */ 1791 1792 var CryptoJS = require('crypto-js'); 1793 var sha3 = require('crypto-js/sha3'); 1794 1795 module.exports = function(value, options) { 1796 if (options && options.encoding === 'hex') { 1797 if (value.length > 2 && value.substr(0, 2) === '0x') { 1798 value = value.substr(2); 1799 } 1800 value = CryptoJS.enc.Hex.parse(value); 1801 } 1802 1803 return sha3(value, { 1804 outputLength: 256 1805 }).toString(); 1806 }; 1807 1808 1809 }, { 1810 "crypto-js": 59, 1811 "crypto-js/sha3": 80 1812 }], 1813 20: [function(require, module, exports) { 1814 /* 1815 This file is part of web3.js. 1816 1817 web3.js is free software: you can redistribute it and/or modify 1818 it under the terms of the GNU Lesser General Public License as published by 1819 the Free Software Foundation, either version 3 of the License, or 1820 (at your option) any later version. 1821 1822 web3.js is distributed in the hope that it will be useful, 1823 but WITHOUT ANY WARRANTY; without even the implied warranty of 1824 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1825 GNU Lesser General Public License for more details. 1826 1827 You should have received a copy of the GNU Lesser General Public License 1828 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 1829 */ 1830 /** 1831 * @file utils.js 1832 * @author Marek Kotewicz <marek@ethdev.com> 1833 * @date 2015 1834 */ 1835 1836 /** 1837 * Utils 1838 * 1839 * @module utils 1840 */ 1841 1842 /** 1843 * Utility functions 1844 * 1845 * @class [utils] utils 1846 * @constructor 1847 */ 1848 1849 1850 var BigNumber = require('bignumber.js'); 1851 var sha3 = require('./sha3.js'); 1852 var utf8 = require('utf8'); 1853 1854 var unitMap = { 1855 'noether': '0', 1856 'wei': '1', 1857 'kwei': '1000', 1858 'Kwei': '1000', 1859 'babbage': '1000', 1860 'femtoether': '1000', 1861 'mwei': '1000000', 1862 'Mwei': '1000000', 1863 'lovelace': '1000000', 1864 'picoether': '1000000', 1865 'gwei': '1000000000', 1866 'Gwei': '1000000000', 1867 'shannon': '1000000000', 1868 'nanoether': '1000000000', 1869 'nano': '1000000000', 1870 'szabo': '1000000000000', 1871 'microether': '1000000000000', 1872 'micro': '1000000000000', 1873 'finney': '1000000000000000', 1874 'milliether': '1000000000000000', 1875 'milli': '1000000000000000', 1876 'ether': '1000000000000000000', 1877 'kether': '1000000000000000000000', 1878 'grand': '1000000000000000000000', 1879 'mether': '1000000000000000000000000', 1880 'gether': '1000000000000000000000000000', 1881 'tether': '1000000000000000000000000000000' 1882 }; 1883 1884 /** 1885 * Should be called to pad string to expected length 1886 * 1887 * @method padLeft 1888 * @param {String} string to be padded 1889 * @param {Number} characters that result string should have 1890 * @param {String} sign, by default 0 1891 * @returns {String} right aligned string 1892 */ 1893 var padLeft = function(string, chars, sign) { 1894 return new Array(chars - string.length + 1).join(sign ? sign : "0") + string; 1895 }; 1896 1897 /** 1898 * Should be called to pad string to expected length 1899 * 1900 * @method padRight 1901 * @param {String} string to be padded 1902 * @param {Number} characters that result string should have 1903 * @param {String} sign, by default 0 1904 * @returns {String} right aligned string 1905 */ 1906 var padRight = function(string, chars, sign) { 1907 return string + (new Array(chars - string.length + 1).join(sign ? sign : "0")); 1908 }; 1909 1910 /** 1911 * Should be called to get utf8 from it's hex representation 1912 * 1913 * @method toUtf8 1914 * @param {String} string in hex 1915 * @returns {String} ascii string representation of hex value 1916 */ 1917 var toUtf8 = function(hex) { 1918 // Find termination 1919 var str = ""; 1920 var i = 0, 1921 l = hex.length; 1922 if (hex.substring(0, 2) === '0x') { 1923 i = 2; 1924 } 1925 for (; i < l; i += 2) { 1926 var code = parseInt(hex.substr(i, 2), 16); 1927 if (code === 0) 1928 break; 1929 str += String.fromCharCode(code); 1930 } 1931 1932 return utf8.decode(str); 1933 }; 1934 1935 /** 1936 * Should be called to get ascii from it's hex representation 1937 * 1938 * @method toAscii 1939 * @param {String} string in hex 1940 * @returns {String} ascii string representation of hex value 1941 */ 1942 var toAscii = function(hex) { 1943 // Find termination 1944 var str = ""; 1945 var i = 0, 1946 l = hex.length; 1947 if (hex.substring(0, 2) === '0x') { 1948 i = 2; 1949 } 1950 for (; i < l; i += 2) { 1951 var code = parseInt(hex.substr(i, 2), 16); 1952 str += String.fromCharCode(code); 1953 } 1954 1955 return str; 1956 }; 1957 1958 /** 1959 * Should be called to get hex representation (prefixed by 0x) of utf8 string 1960 * 1961 * @method fromUtf8 1962 * @param {String} string 1963 * @param {Number} optional padding 1964 * @returns {String} hex representation of input string 1965 */ 1966 var fromUtf8 = function(str) { 1967 str = utf8.encode(str); 1968 var hex = ""; 1969 for (var i = 0; i < str.length; i++) { 1970 var code = str.charCodeAt(i); 1971 if (code === 0) 1972 break; 1973 var n = code.toString(16); 1974 hex += n.length < 2 ? '0' + n : n; 1975 } 1976 1977 return "0x" + hex; 1978 }; 1979 1980 /** 1981 * Should be called to get hex representation (prefixed by 0x) of ascii string 1982 * 1983 * @method fromAscii 1984 * @param {String} string 1985 * @param {Number} optional padding 1986 * @returns {String} hex representation of input string 1987 */ 1988 var fromAscii = function(str) { 1989 var hex = ""; 1990 for (var i = 0; i < str.length; i++) { 1991 var code = str.charCodeAt(i); 1992 var n = code.toString(16); 1993 hex += n.length < 2 ? '0' + n : n; 1994 } 1995 1996 return "0x" + hex; 1997 }; 1998 1999 /** 2000 * Should be used to create full function/event name from json abi 2001 * 2002 * @method transformToFullName 2003 * @param {Object} json-abi 2004 * @return {String} full fnction/event name 2005 */ 2006 var transformToFullName = function(json) { 2007 if (json.name.indexOf('(') !== -1) { 2008 return json.name; 2009 } 2010 2011 var typeName = json.inputs.map(function(i) { 2012 return i.type; 2013 }).join(); 2014 return json.name + '(' + typeName + ')'; 2015 }; 2016 2017 /** 2018 * Should be called to get display name of contract function 2019 * 2020 * @method extractDisplayName 2021 * @param {String} name of function/event 2022 * @returns {String} display name for function/event eg. multiply(uint256) -> multiply 2023 */ 2024 var extractDisplayName = function(name) { 2025 var length = name.indexOf('('); 2026 return length !== -1 ? name.substr(0, length) : name; 2027 }; 2028 2029 /// @returns overloaded part of function/event name 2030 var extractTypeName = function(name) { 2031 /// TODO: make it invulnerable 2032 var length = name.indexOf('('); 2033 return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; 2034 }; 2035 2036 /** 2037 * Converts value to it's decimal representation in string 2038 * 2039 * @method toDecimal 2040 * @param {String|Number|BigNumber} 2041 * @return {String} 2042 */ 2043 var toDecimal = function(value) { 2044 return toBigNumber(value).toNumber(); 2045 }; 2046 2047 /** 2048 * Converts value to it's hex representation 2049 * 2050 * @method fromDecimal 2051 * @param {String|Number|BigNumber} 2052 * @return {String} 2053 */ 2054 var fromDecimal = function(value) { 2055 var number = toBigNumber(value); 2056 var result = number.toString(16); 2057 2058 return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result; 2059 }; 2060 2061 /** 2062 * Auto converts any given value into it's hex representation. 2063 * 2064 * And even stringifys objects before. 2065 * 2066 * @method toHex 2067 * @param {String|Number|BigNumber|Object} 2068 * @return {String} 2069 */ 2070 var toHex = function(val) { 2071 /*jshint maxcomplexity: 8 */ 2072 2073 if (isBoolean(val)) 2074 return fromDecimal(+val); 2075 2076 if (isBigNumber(val)) 2077 return fromDecimal(val); 2078 2079 if (typeof val === 'object') 2080 return fromUtf8(JSON.stringify(val)); 2081 2082 // if its a negative number, pass it through fromDecimal 2083 if (isString(val)) { 2084 if (val.indexOf('-0x') === 0) 2085 return fromDecimal(val); 2086 else if (val.indexOf('0x') === 0) 2087 return val; 2088 else if (!isFinite(val)) 2089 return fromAscii(val); 2090 } 2091 2092 return fromDecimal(val); 2093 }; 2094 2095 /** 2096 * Returns value of unit in Wei 2097 * 2098 * @method getValueOfUnit 2099 * @param {String} unit the unit to convert to, default ether 2100 * @returns {BigNumber} value of the unit (in Wei) 2101 * @throws error if the unit is not correct:w 2102 */ 2103 var getValueOfUnit = function(unit) { 2104 unit = unit ? unit.toLowerCase() : 'ether'; 2105 var unitValue = unitMap[unit]; 2106 if (unitValue === undefined) { 2107 throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2)); 2108 } 2109 return new BigNumber(unitValue, 10); 2110 }; 2111 2112 /** 2113 * Takes a number of wei and converts it to any other ether unit. 2114 * 2115 * Possible units are: 2116 * SI Short SI Full Effigy Other 2117 * - kwei femtoether babbage 2118 * - mwei picoether lovelace 2119 * - gwei nanoether shannon nano 2120 * - -- microether szabo micro 2121 * - -- milliether finney milli 2122 * - ether -- -- 2123 * - kether -- grand 2124 * - mether 2125 * - gether 2126 * - tether 2127 * 2128 * @method fromWei 2129 * @param {Number|String} number can be a number, number string or a HEX of a decimal 2130 * @param {String} unit the unit to convert to, default ether 2131 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2132 */ 2133 var fromWei = function(number, unit) { 2134 var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit)); 2135 2136 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2137 }; 2138 2139 /** 2140 * Takes a number of a unit and converts it to wei. 2141 * 2142 * Possible units are: 2143 * SI Short SI Full Effigy Other 2144 * - kwei femtoether babbage 2145 * - mwei picoether lovelace 2146 * - gwei nanoether shannon nano 2147 * - -- microether szabo micro 2148 * - -- microether szabo micro 2149 * - -- milliether finney milli 2150 * - ether -- -- 2151 * - kether -- grand 2152 * - mether 2153 * - gether 2154 * - tether 2155 * 2156 * @method toWei 2157 * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal 2158 * @param {String} unit the unit to convert from, default ether 2159 * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number 2160 */ 2161 var toWei = function(number, unit) { 2162 var returnValue = toBigNumber(number).times(getValueOfUnit(unit)); 2163 2164 return isBigNumber(number) ? returnValue : returnValue.toString(10); 2165 }; 2166 2167 /** 2168 * Takes an input and transforms it into a bignumber 2169 * 2170 * @method toBigNumber 2171 * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber 2172 * @return {BigNumber} BigNumber 2173 */ 2174 var toBigNumber = function(number) { 2175 /*jshint maxcomplexity:5 */ 2176 number = number || 0; 2177 if (isBigNumber(number)) 2178 return number; 2179 2180 if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) { 2181 return new BigNumber(number.replace('0x', ''), 16); 2182 } 2183 2184 return new BigNumber(number.toString(10), 10); 2185 }; 2186 2187 /** 2188 * Takes and input transforms it into bignumber and if it is negative value, into two's complement 2189 * 2190 * @method toTwosComplement 2191 * @param {Number|String|BigNumber} 2192 * @return {BigNumber} 2193 */ 2194 var toTwosComplement = function(number) { 2195 var bigNumber = toBigNumber(number).round(); 2196 if (bigNumber.lessThan(0)) { 2197 return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1); 2198 } 2199 return bigNumber; 2200 }; 2201 2202 /** 2203 * Checks if the given string is strictly an address 2204 * 2205 * @method isStrictAddress 2206 * @param {String} address the given HEX address 2207 * @return {Boolean} 2208 */ 2209 var isStrictAddress = function(address) { 2210 return /^0x[0-9a-f]{40}$/i.test(address); 2211 }; 2212 2213 /** 2214 * Checks if the given string is an address 2215 * 2216 * @method isAddress 2217 * @param {String} address the given HEX address 2218 * @return {Boolean} 2219 */ 2220 var isAddress = function(address) { 2221 if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) { 2222 // check if it has the basic requirements of an address 2223 return false; 2224 } else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) { 2225 // If it's all small caps or all caps, return true 2226 return true; 2227 } else { 2228 // Otherwise check each case 2229 return isChecksumAddress(address); 2230 } 2231 }; 2232 2233 /** 2234 * Checks if the given string is a checksummed address 2235 * 2236 * @method isChecksumAddress 2237 * @param {String} address the given HEX address 2238 * @return {Boolean} 2239 */ 2240 var isChecksumAddress = function(address) { 2241 // Check each case 2242 address = address.replace('0x', ''); 2243 var addressHash = sha3(address.toLowerCase()); 2244 2245 for (var i = 0; i < 40; i++) { 2246 // the nth letter should be uppercase if the nth digit of casemap is 1 2247 if ((parseInt(addressHash[i], 16) > 7 && address[i].toUpperCase() !== address[i]) || (parseInt(addressHash[i], 16) <= 7 && address[i].toLowerCase() !== address[i])) { 2248 return false; 2249 } 2250 } 2251 return true; 2252 }; 2253 2254 2255 2256 /** 2257 * Makes a checksum address 2258 * 2259 * @method toChecksumAddress 2260 * @param {String} address the given HEX address 2261 * @return {String} 2262 */ 2263 var toChecksumAddress = function(address) { 2264 if (typeof address === 'undefined') return ''; 2265 2266 address = address.toLowerCase().replace('0x', ''); 2267 var addressHash = sha3(address); 2268 var checksumAddress = '0x'; 2269 2270 for (var i = 0; i < address.length; i++) { 2271 // If ith character is 9 to f then make it uppercase 2272 if (parseInt(addressHash[i], 16) > 7) { 2273 checksumAddress += address[i].toUpperCase(); 2274 } else { 2275 checksumAddress += address[i]; 2276 } 2277 } 2278 return checksumAddress; 2279 }; 2280 2281 /** 2282 * Transforms given string to valid 20 bytes-length addres with 0x prefix 2283 * 2284 * @method toAddress 2285 * @param {String} address 2286 * @return {String} formatted address 2287 */ 2288 var toAddress = function(address) { 2289 if (isStrictAddress(address)) { 2290 return address; 2291 } 2292 2293 if (/^[0-9a-f]{40}$/.test(address)) { 2294 return '0x' + address; 2295 } 2296 2297 return '0x' + padLeft(toHex(address).substr(2), 40); 2298 }; 2299 2300 /** 2301 * Returns true if object is BigNumber, otherwise false 2302 * 2303 * @method isBigNumber 2304 * @param {Object} 2305 * @return {Boolean} 2306 */ 2307 var isBigNumber = function(object) { 2308 return object instanceof BigNumber || 2309 (object && object.constructor && object.constructor.name === 'BigNumber'); 2310 }; 2311 2312 /** 2313 * Returns true if object is string, otherwise false 2314 * 2315 * @method isString 2316 * @param {Object} 2317 * @return {Boolean} 2318 */ 2319 var isString = function(object) { 2320 return typeof object === 'string' || 2321 (object && object.constructor && object.constructor.name === 'String'); 2322 }; 2323 2324 /** 2325 * Returns true if object is function, otherwise false 2326 * 2327 * @method isFunction 2328 * @param {Object} 2329 * @return {Boolean} 2330 */ 2331 var isFunction = function(object) { 2332 return typeof object === 'function'; 2333 }; 2334 2335 /** 2336 * Returns true if object is Objet, otherwise false 2337 * 2338 * @method isObject 2339 * @param {Object} 2340 * @return {Boolean} 2341 */ 2342 var isObject = function(object) { 2343 return object !== null && !(object instanceof Array) && typeof object === 'object'; 2344 }; 2345 2346 /** 2347 * Returns true if object is boolean, otherwise false 2348 * 2349 * @method isBoolean 2350 * @param {Object} 2351 * @return {Boolean} 2352 */ 2353 var isBoolean = function(object) { 2354 return typeof object === 'boolean'; 2355 }; 2356 2357 /** 2358 * Returns true if object is array, otherwise false 2359 * 2360 * @method isArray 2361 * @param {Object} 2362 * @return {Boolean} 2363 */ 2364 var isArray = function(object) { 2365 return object instanceof Array; 2366 }; 2367 2368 /** 2369 * Returns true if given string is valid json object 2370 * 2371 * @method isJson 2372 * @param {String} 2373 * @return {Boolean} 2374 */ 2375 var isJson = function(str) { 2376 try { 2377 return !!JSON.parse(str); 2378 } catch (e) { 2379 return false; 2380 } 2381 }; 2382 2383 /** 2384 * Returns true if given string is a valid Ethereum block header bloom. 2385 * 2386 * @method isBloom 2387 * @param {String} hex encoded bloom filter 2388 * @return {Boolean} 2389 */ 2390 var isBloom = function(bloom) { 2391 if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) { 2392 return false; 2393 } else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) { 2394 return true; 2395 } 2396 return false; 2397 }; 2398 2399 /** 2400 * Returns true if given string is a valid log topic. 2401 * 2402 * @method isTopic 2403 * @param {String} hex encoded topic 2404 * @return {Boolean} 2405 */ 2406 var isTopic = function(topic) { 2407 if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) { 2408 return false; 2409 } else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) { 2410 return true; 2411 } 2412 return false; 2413 }; 2414 2415 module.exports = { 2416 padLeft: padLeft, 2417 padRight: padRight, 2418 toHex: toHex, 2419 toDecimal: toDecimal, 2420 fromDecimal: fromDecimal, 2421 toUtf8: toUtf8, 2422 toAscii: toAscii, 2423 fromUtf8: fromUtf8, 2424 fromAscii: fromAscii, 2425 transformToFullName: transformToFullName, 2426 extractDisplayName: extractDisplayName, 2427 extractTypeName: extractTypeName, 2428 toWei: toWei, 2429 fromWei: fromWei, 2430 toBigNumber: toBigNumber, 2431 toTwosComplement: toTwosComplement, 2432 toAddress: toAddress, 2433 isBigNumber: isBigNumber, 2434 isStrictAddress: isStrictAddress, 2435 isAddress: isAddress, 2436 isChecksumAddress: isChecksumAddress, 2437 toChecksumAddress: toChecksumAddress, 2438 isFunction: isFunction, 2439 isString: isString, 2440 isObject: isObject, 2441 isBoolean: isBoolean, 2442 isArray: isArray, 2443 isJson: isJson, 2444 isBloom: isBloom, 2445 isTopic: isTopic, 2446 }; 2447 2448 }, { 2449 "./sha3.js": 19, 2450 "bignumber.js": "bignumber.js", 2451 "utf8": 85 2452 }], 2453 21: [function(require, module, exports) { 2454 module.exports = { 2455 "version": "0.20.1" 2456 } 2457 2458 }, {}], 2459 22: [function(require, module, exports) { 2460 /* 2461 This file is part of web3.js. 2462 2463 web3.js is free software: you can redistribute it and/or modify 2464 it under the terms of the GNU Lesser General Public License as published by 2465 the Free Software Foundation, either version 3 of the License, or 2466 (at your option) any later version. 2467 2468 web3.js is distributed in the hope that it will be useful, 2469 but WITHOUT ANY WARRANTY; without even the implied warranty of 2470 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2471 GNU Lesser General Public License for more details. 2472 2473 You should have received a copy of the GNU Lesser General Public License 2474 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2475 */ 2476 /** 2477 * @file web3.js 2478 * @authors: 2479 * Jeffrey Wilcke <jeff@ethdev.com> 2480 * Marek Kotewicz <marek@ethdev.com> 2481 * Marian Oancea <marian@ethdev.com> 2482 * Fabian Vogelsteller <fabian@ethdev.com> 2483 * Gav Wood <g@ethdev.com> 2484 * @date 2014 2485 */ 2486 2487 var RequestManager = require('./web3/requestmanager'); 2488 var Iban = require('./web3/iban'); 2489 var Eth = require('./web3/methods/eth'); 2490 var DB = require('./web3/methods/db'); 2491 var Shh = require('./web3/methods/shh'); 2492 var Net = require('./web3/methods/net'); 2493 var Personal = require('./web3/methods/personal'); 2494 var Swarm = require('./web3/methods/swarm'); 2495 var Settings = require('./web3/settings'); 2496 var version = require('./version.json'); 2497 var utils = require('./utils/utils'); 2498 var sha3 = require('./utils/sha3'); 2499 var extend = require('./web3/extend'); 2500 var Batch = require('./web3/batch'); 2501 var Property = require('./web3/property'); 2502 var HttpProvider = require('./web3/httpprovider'); 2503 var IpcProvider = require('./web3/ipcprovider'); 2504 var BigNumber = require('bignumber.js'); 2505 2506 2507 2508 function Web3(provider) { 2509 this._requestManager = new RequestManager(provider); 2510 this.currentProvider = provider; 2511 this.eth = new Eth(this); 2512 this.db = new DB(this); 2513 this.shh = new Shh(this); 2514 this.net = new Net(this); 2515 this.personal = new Personal(this); 2516 this.bzz = new Swarm(this); 2517 this.settings = new Settings(); 2518 this.version = { 2519 api: version.version 2520 }; 2521 this.providers = { 2522 HttpProvider: HttpProvider, 2523 IpcProvider: IpcProvider 2524 }; 2525 this._extend = extend(this); 2526 this._extend({ 2527 properties: properties() 2528 }); 2529 } 2530 2531 // expose providers on the class 2532 Web3.providers = { 2533 HttpProvider: HttpProvider, 2534 IpcProvider: IpcProvider 2535 }; 2536 2537 Web3.prototype.setProvider = function(provider) { 2538 this._requestManager.setProvider(provider); 2539 this.currentProvider = provider; 2540 }; 2541 2542 Web3.prototype.reset = function(keepIsSyncing) { 2543 this._requestManager.reset(keepIsSyncing); 2544 this.settings = new Settings(); 2545 }; 2546 2547 Web3.prototype.BigNumber = BigNumber; 2548 Web3.prototype.toHex = utils.toHex; 2549 Web3.prototype.toAscii = utils.toAscii; 2550 Web3.prototype.toUtf8 = utils.toUtf8; 2551 Web3.prototype.fromAscii = utils.fromAscii; 2552 Web3.prototype.fromUtf8 = utils.fromUtf8; 2553 Web3.prototype.toDecimal = utils.toDecimal; 2554 Web3.prototype.fromDecimal = utils.fromDecimal; 2555 Web3.prototype.toBigNumber = utils.toBigNumber; 2556 Web3.prototype.toWei = utils.toWei; 2557 Web3.prototype.fromWei = utils.fromWei; 2558 Web3.prototype.isAddress = utils.isAddress; 2559 Web3.prototype.isChecksumAddress = utils.isChecksumAddress; 2560 Web3.prototype.toChecksumAddress = utils.toChecksumAddress; 2561 Web3.prototype.isIBAN = utils.isIBAN; 2562 Web3.prototype.padLeft = utils.padLeft; 2563 Web3.prototype.padRight = utils.padRight; 2564 2565 2566 Web3.prototype.sha3 = function(string, options) { 2567 return '0x' + sha3(string, options); 2568 }; 2569 2570 /** 2571 * Transforms direct icap to address 2572 */ 2573 Web3.prototype.fromICAP = function(icap) { 2574 var iban = new Iban(icap); 2575 return iban.address(); 2576 }; 2577 2578 var properties = function() { 2579 return [ 2580 new Property({ 2581 name: 'version.node', 2582 getter: 'web3_clientVersion' 2583 }), 2584 new Property({ 2585 name: 'version.network', 2586 getter: 'net_version', 2587 inputFormatter: utils.toDecimal 2588 }), 2589 new Property({ 2590 name: 'version.ethereum', 2591 getter: 'eth_protocolVersion', 2592 inputFormatter: utils.toDecimal 2593 }), 2594 new Property({ 2595 name: 'version.whisper', 2596 getter: 'shh_version', 2597 inputFormatter: utils.toDecimal 2598 }) 2599 ]; 2600 }; 2601 2602 Web3.prototype.isConnected = function() { 2603 return (this.currentProvider && this.currentProvider.isConnected()); 2604 }; 2605 2606 Web3.prototype.createBatch = function() { 2607 return new Batch(this); 2608 }; 2609 2610 module.exports = Web3; 2611 2612 2613 }, { 2614 "./utils/sha3": 19, 2615 "./utils/utils": 20, 2616 "./version.json": 21, 2617 "./web3/batch": 24, 2618 "./web3/extend": 28, 2619 "./web3/httpprovider": 32, 2620 "./web3/iban": 33, 2621 "./web3/ipcprovider": 34, 2622 "./web3/methods/db": 37, 2623 "./web3/methods/eth": 38, 2624 "./web3/methods/net": 39, 2625 "./web3/methods/personal": 40, 2626 "./web3/methods/shh": 41, 2627 "./web3/methods/swarm": 42, 2628 "./web3/property": 45, 2629 "./web3/requestmanager": 46, 2630 "./web3/settings": 47, 2631 "bignumber.js": "bignumber.js" 2632 }], 2633 23: [function(require, module, exports) { 2634 /* 2635 This file is part of web3.js. 2636 2637 web3.js is free software: you can redistribute it and/or modify 2638 it under the terms of the GNU Lesser General Public License as published by 2639 the Free Software Foundation, either version 3 of the License, or 2640 (at your option) any later version. 2641 2642 web3.js is distributed in the hope that it will be useful, 2643 but WITHOUT ANY WARRANTY; without even the implied warranty of 2644 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2645 GNU Lesser General Public License for more details. 2646 2647 You should have received a copy of the GNU Lesser General Public License 2648 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2649 */ 2650 /** 2651 * @file allevents.js 2652 * @author Marek Kotewicz <marek@ethdev.com> 2653 * @date 2014 2654 */ 2655 2656 var sha3 = require('../utils/sha3'); 2657 var SolidityEvent = require('./event'); 2658 var formatters = require('./formatters'); 2659 var utils = require('../utils/utils'); 2660 var Filter = require('./filter'); 2661 var watches = require('./methods/watches'); 2662 2663 var AllSolidityEvents = function(requestManager, json, address) { 2664 this._requestManager = requestManager; 2665 this._json = json; 2666 this._address = address; 2667 }; 2668 2669 AllSolidityEvents.prototype.encode = function(options) { 2670 options = options || {}; 2671 var result = {}; 2672 2673 ['fromBlock', 'toBlock'].filter(function(f) { 2674 return options[f] !== undefined; 2675 }).forEach(function(f) { 2676 result[f] = formatters.inputBlockNumberFormatter(options[f]); 2677 }); 2678 2679 result.address = this._address; 2680 2681 return result; 2682 }; 2683 2684 AllSolidityEvents.prototype.decode = function(data) { 2685 data.data = data.data || ''; 2686 data.topics = data.topics || []; 2687 2688 var eventTopic = data.topics[0].slice(2); 2689 var match = this._json.filter(function(j) { 2690 return eventTopic === sha3(utils.transformToFullName(j)); 2691 })[0]; 2692 2693 if (!match) { // cannot find matching event? 2694 console.warn('cannot find event for log'); 2695 return data; 2696 } 2697 2698 var event = new SolidityEvent(this._requestManager, match, this._address); 2699 return event.decode(data); 2700 }; 2701 2702 AllSolidityEvents.prototype.execute = function(options, callback) { 2703 2704 if (utils.isFunction(arguments[arguments.length - 1])) { 2705 callback = arguments[arguments.length - 1]; 2706 if (arguments.length === 1) 2707 options = null; 2708 } 2709 2710 var o = this.encode(options); 2711 var formatter = this.decode.bind(this); 2712 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 2713 }; 2714 2715 AllSolidityEvents.prototype.attachToContract = function(contract) { 2716 var execute = this.execute.bind(this); 2717 contract.allEvents = execute; 2718 }; 2719 2720 module.exports = AllSolidityEvents; 2721 2722 2723 }, { 2724 "../utils/sha3": 19, 2725 "../utils/utils": 20, 2726 "./event": 27, 2727 "./filter": 29, 2728 "./formatters": 30, 2729 "./methods/watches": 43 2730 }], 2731 24: [function(require, module, exports) { 2732 /* 2733 This file is part of web3.js. 2734 2735 web3.js is free software: you can redistribute it and/or modify 2736 it under the terms of the GNU Lesser General Public License as published by 2737 the Free Software Foundation, either version 3 of the License, or 2738 (at your option) any later version. 2739 2740 web3.js is distributed in the hope that it will be useful, 2741 but WITHOUT ANY WARRANTY; without even the implied warranty of 2742 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2743 GNU Lesser General Public License for more details. 2744 2745 You should have received a copy of the GNU Lesser General Public License 2746 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2747 */ 2748 /** 2749 * @file batch.js 2750 * @author Marek Kotewicz <marek@ethdev.com> 2751 * @date 2015 2752 */ 2753 2754 var Jsonrpc = require('./jsonrpc'); 2755 var errors = require('./errors'); 2756 2757 var Batch = function(web3) { 2758 this.requestManager = web3._requestManager; 2759 this.requests = []; 2760 }; 2761 2762 /** 2763 * Should be called to add create new request to batch request 2764 * 2765 * @method add 2766 * @param {Object} jsonrpc requet object 2767 */ 2768 Batch.prototype.add = function(request) { 2769 this.requests.push(request); 2770 }; 2771 2772 /** 2773 * Should be called to execute batch request 2774 * 2775 * @method execute 2776 */ 2777 Batch.prototype.execute = function() { 2778 var requests = this.requests; 2779 this.requestManager.sendBatch(requests, function(err, results) { 2780 results = results || []; 2781 requests.map(function(request, index) { 2782 return results[index] || {}; 2783 }).forEach(function(result, index) { 2784 if (requests[index].callback) { 2785 2786 if (!Jsonrpc.isValidResponse(result)) { 2787 return requests[index].callback(errors.InvalidResponse(result)); 2788 } 2789 2790 requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result)); 2791 } 2792 }); 2793 }); 2794 }; 2795 2796 module.exports = Batch; 2797 2798 2799 }, { 2800 "./errors": 26, 2801 "./jsonrpc": 35 2802 }], 2803 25: [function(require, module, exports) { 2804 /* 2805 This file is part of web3.js. 2806 2807 web3.js is free software: you can redistribute it and/or modify 2808 it under the terms of the GNU Lesser General Public License as published by 2809 the Free Software Foundation, either version 3 of the License, or 2810 (at your option) any later version. 2811 2812 web3.js is distributed in the hope that it will be useful, 2813 but WITHOUT ANY WARRANTY; without even the implied warranty of 2814 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2815 GNU Lesser General Public License for more details. 2816 2817 You should have received a copy of the GNU Lesser General Public License 2818 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 2819 */ 2820 /** 2821 * @file contract.js 2822 * @author Marek Kotewicz <marek@ethdev.com> 2823 * @date 2014 2824 */ 2825 2826 var utils = require('../utils/utils'); 2827 var coder = require('../solidity/coder'); 2828 var SolidityEvent = require('./event'); 2829 var SolidityFunction = require('./function'); 2830 var AllEvents = require('./allevents'); 2831 2832 /** 2833 * Should be called to encode constructor params 2834 * 2835 * @method encodeConstructorParams 2836 * @param {Array} abi 2837 * @param {Array} constructor params 2838 */ 2839 var encodeConstructorParams = function(abi, params) { 2840 return abi.filter(function(json) { 2841 return json.type === 'constructor' && json.inputs.length === params.length; 2842 }).map(function(json) { 2843 return json.inputs.map(function(input) { 2844 return input.type; 2845 }); 2846 }).map(function(types) { 2847 return coder.encodeParams(types, params); 2848 })[0] || ''; 2849 }; 2850 2851 /** 2852 * Should be called to add functions to contract object 2853 * 2854 * @method addFunctionsToContract 2855 * @param {Contract} contract 2856 * @param {Array} abi 2857 */ 2858 var addFunctionsToContract = function(contract) { 2859 contract.abi.filter(function(json) { 2860 return json.type === 'function'; 2861 }).map(function(json) { 2862 return new SolidityFunction(contract._eth, json, contract.address); 2863 }).forEach(function(f) { 2864 f.attachToContract(contract); 2865 }); 2866 }; 2867 2868 /** 2869 * Should be called to add events to contract object 2870 * 2871 * @method addEventsToContract 2872 * @param {Contract} contract 2873 * @param {Array} abi 2874 */ 2875 var addEventsToContract = function(contract) { 2876 var events = contract.abi.filter(function(json) { 2877 return json.type === 'event'; 2878 }); 2879 2880 var All = new AllEvents(contract._eth._requestManager, events, contract.address); 2881 All.attachToContract(contract); 2882 2883 events.map(function(json) { 2884 return new SolidityEvent(contract._eth._requestManager, json, contract.address); 2885 }).forEach(function(e) { 2886 e.attachToContract(contract); 2887 }); 2888 }; 2889 2890 2891 /** 2892 * Should be called to check if the contract gets properly deployed on the blockchain. 2893 * 2894 * @method checkForContractAddress 2895 * @param {Object} contract 2896 * @param {Function} callback 2897 * @returns {Undefined} 2898 */ 2899 var checkForContractAddress = function(contract, callback) { 2900 var count = 0, 2901 callbackFired = false; 2902 2903 // wait for receipt 2904 var filter = contract._eth.filter('latest', function(e) { 2905 if (!e && !callbackFired) { 2906 count++; 2907 2908 // stop watching after 50 blocks (timeout) 2909 if (count > 50) { 2910 2911 filter.stopWatching(function() {}); 2912 callbackFired = true; 2913 2914 if (callback) 2915 callback(new Error('Contract transaction couldn\'t be found after 50 blocks')); 2916 else 2917 throw new Error('Contract transaction couldn\'t be found after 50 blocks'); 2918 2919 2920 } else { 2921 2922 contract._eth.getTransactionReceipt(contract.transactionHash, function(e, receipt) { 2923 if (receipt && !callbackFired) { 2924 2925 contract._eth.getCode(receipt.contractAddress, function(e, code) { 2926 /*jshint maxcomplexity: 6 */ 2927 2928 if (callbackFired || !code) 2929 return; 2930 2931 filter.stopWatching(function() {}); 2932 callbackFired = true; 2933 2934 if (code.length > 3) { 2935 2936 // console.log('Contract code deployed!'); 2937 2938 contract.address = receipt.contractAddress; 2939 2940 // attach events and methods again after we have 2941 addFunctionsToContract(contract); 2942 addEventsToContract(contract); 2943 2944 // call callback for the second time 2945 if (callback) 2946 callback(null, contract); 2947 2948 } else { 2949 if (callback) 2950 callback(new Error('The contract code couldn\'t be stored, please check your gas amount.')); 2951 else 2952 throw new Error('The contract code couldn\'t be stored, please check your gas amount.'); 2953 } 2954 }); 2955 } 2956 }); 2957 } 2958 } 2959 }); 2960 }; 2961 2962 /** 2963 * Should be called to create new ContractFactory instance 2964 * 2965 * @method ContractFactory 2966 * @param {Array} abi 2967 */ 2968 var ContractFactory = function(eth, abi) { 2969 this.eth = eth; 2970 this.abi = abi; 2971 2972 /** 2973 * Should be called to create new contract on a blockchain 2974 * 2975 * @method new 2976 * @param {Any} contract constructor param1 (optional) 2977 * @param {Any} contract constructor param2 (optional) 2978 * @param {Object} contract transaction object (required) 2979 * @param {Function} callback 2980 * @returns {Contract} returns contract instance 2981 */ 2982 this.new = function() { 2983 /*jshint maxcomplexity: 7 */ 2984 2985 var contract = new Contract(this.eth, this.abi); 2986 2987 // parse arguments 2988 var options = {}; // required! 2989 var callback; 2990 2991 var args = Array.prototype.slice.call(arguments); 2992 if (utils.isFunction(args[args.length - 1])) { 2993 callback = args.pop(); 2994 } 2995 2996 var last = args[args.length - 1]; 2997 if (utils.isObject(last) && !utils.isArray(last)) { 2998 options = args.pop(); 2999 } 3000 3001 if (options.value > 0) { 3002 var constructorAbi = abi.filter(function(json) { 3003 return json.type === 'constructor' && json.inputs.length === args.length; 3004 })[0] || {}; 3005 3006 if (!constructorAbi.payable) { 3007 throw new Error('Cannot send value to non-payable constructor'); 3008 } 3009 } 3010 3011 var bytes = encodeConstructorParams(this.abi, args); 3012 options.data += bytes; 3013 3014 if (callback) { 3015 3016 // wait for the contract address and check if the code was deployed 3017 this.eth.sendTransaction(options, function(err, hash) { 3018 if (err) { 3019 callback(err); 3020 } else { 3021 // add the transaction hash 3022 contract.transactionHash = hash; 3023 3024 // call callback for the first time 3025 callback(null, contract); 3026 3027 checkForContractAddress(contract, callback); 3028 } 3029 }); 3030 } else { 3031 var hash = this.eth.sendTransaction(options); 3032 // add the transaction hash 3033 contract.transactionHash = hash; 3034 checkForContractAddress(contract); 3035 } 3036 3037 return contract; 3038 }; 3039 3040 this.new.getData = this.getData.bind(this); 3041 }; 3042 3043 /** 3044 * Should be called to create new ContractFactory 3045 * 3046 * @method contract 3047 * @param {Array} abi 3048 * @returns {ContractFactory} new contract factory 3049 */ 3050 //var contract = function (abi) { 3051 //return new ContractFactory(abi); 3052 //}; 3053 3054 3055 3056 /** 3057 * Should be called to get access to existing contract on a blockchain 3058 * 3059 * @method at 3060 * @param {Address} contract address (required) 3061 * @param {Function} callback {optional) 3062 * @returns {Contract} returns contract if no callback was passed, 3063 * otherwise calls callback function (err, contract) 3064 */ 3065 ContractFactory.prototype.at = function(address, callback) { 3066 var contract = new Contract(this.eth, this.abi, address); 3067 3068 // this functions are not part of prototype, 3069 // because we dont want to spoil the interface 3070 addFunctionsToContract(contract); 3071 addEventsToContract(contract); 3072 3073 if (callback) { 3074 callback(null, contract); 3075 } 3076 return contract; 3077 }; 3078 3079 /** 3080 * Gets the data, which is data to deploy plus constructor params 3081 * 3082 * @method getData 3083 */ 3084 ContractFactory.prototype.getData = function() { 3085 var options = {}; // required! 3086 var args = Array.prototype.slice.call(arguments); 3087 3088 var last = args[args.length - 1]; 3089 if (utils.isObject(last) && !utils.isArray(last)) { 3090 options = args.pop(); 3091 } 3092 3093 var bytes = encodeConstructorParams(this.abi, args); 3094 options.data += bytes; 3095 3096 return options.data; 3097 }; 3098 3099 /** 3100 * Should be called to create new contract instance 3101 * 3102 * @method Contract 3103 * @param {Array} abi 3104 * @param {Address} contract address 3105 */ 3106 var Contract = function(eth, abi, address) { 3107 this._eth = eth; 3108 this.transactionHash = null; 3109 this.address = address; 3110 this.abi = abi; 3111 }; 3112 3113 module.exports = ContractFactory; 3114 3115 }, { 3116 "../solidity/coder": 7, 3117 "../utils/utils": 20, 3118 "./allevents": 23, 3119 "./event": 27, 3120 "./function": 31 3121 }], 3122 26: [function(require, module, exports) { 3123 /* 3124 This file is part of web3.js. 3125 3126 web3.js is free software: you can redistribute it and/or modify 3127 it under the terms of the GNU Lesser General Public License as published by 3128 the Free Software Foundation, either version 3 of the License, or 3129 (at your option) any later version. 3130 3131 web3.js is distributed in the hope that it will be useful, 3132 but WITHOUT ANY WARRANTY; without even the implied warranty of 3133 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3134 GNU Lesser General Public License for more details. 3135 3136 You should have received a copy of the GNU Lesser General Public License 3137 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3138 */ 3139 /** 3140 * @file errors.js 3141 * @author Marek Kotewicz <marek@ethdev.com> 3142 * @date 2015 3143 */ 3144 3145 module.exports = { 3146 InvalidNumberOfSolidityArgs: function() { 3147 return new Error('Invalid number of arguments to Solidity function'); 3148 }, 3149 InvalidNumberOfRPCParams: function() { 3150 return new Error('Invalid number of input parameters to RPC method'); 3151 }, 3152 InvalidConnection: function(host) { 3153 return new Error('CONNECTION ERROR: Couldn\'t connect to node ' + host + '.'); 3154 }, 3155 InvalidProvider: function() { 3156 return new Error('Provider not set or invalid'); 3157 }, 3158 InvalidResponse: function(result) { 3159 var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: ' + JSON.stringify(result); 3160 return new Error(message); 3161 }, 3162 ConnectionTimeout: function(ms) { 3163 return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived'); 3164 } 3165 }; 3166 3167 }, {}], 3168 27: [function(require, module, exports) { 3169 /* 3170 This file is part of web3.js. 3171 3172 web3.js is free software: you can redistribute it and/or modify 3173 it under the terms of the GNU Lesser General Public License as published by 3174 the Free Software Foundation, either version 3 of the License, or 3175 (at your option) any later version. 3176 3177 web3.js is distributed in the hope that it will be useful, 3178 but WITHOUT ANY WARRANTY; without even the implied warranty of 3179 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3180 GNU Lesser General Public License for more details. 3181 3182 You should have received a copy of the GNU Lesser General Public License 3183 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3184 */ 3185 /** 3186 * @file event.js 3187 * @author Marek Kotewicz <marek@ethdev.com> 3188 * @date 2014 3189 */ 3190 3191 var utils = require('../utils/utils'); 3192 var coder = require('../solidity/coder'); 3193 var formatters = require('./formatters'); 3194 var sha3 = require('../utils/sha3'); 3195 var Filter = require('./filter'); 3196 var watches = require('./methods/watches'); 3197 3198 /** 3199 * This prototype should be used to create event filters 3200 */ 3201 var SolidityEvent = function(requestManager, json, address) { 3202 this._requestManager = requestManager; 3203 this._params = json.inputs; 3204 this._name = utils.transformToFullName(json); 3205 this._address = address; 3206 this._anonymous = json.anonymous; 3207 }; 3208 3209 /** 3210 * Should be used to get filtered param types 3211 * 3212 * @method types 3213 * @param {Bool} decide if returned typed should be indexed 3214 * @return {Array} array of types 3215 */ 3216 SolidityEvent.prototype.types = function(indexed) { 3217 return this._params.filter(function(i) { 3218 return i.indexed === indexed; 3219 }).map(function(i) { 3220 return i.type; 3221 }); 3222 }; 3223 3224 /** 3225 * Should be used to get event display name 3226 * 3227 * @method displayName 3228 * @return {String} event display name 3229 */ 3230 SolidityEvent.prototype.displayName = function() { 3231 return utils.extractDisplayName(this._name); 3232 }; 3233 3234 /** 3235 * Should be used to get event type name 3236 * 3237 * @method typeName 3238 * @return {String} event type name 3239 */ 3240 SolidityEvent.prototype.typeName = function() { 3241 return utils.extractTypeName(this._name); 3242 }; 3243 3244 /** 3245 * Should be used to get event signature 3246 * 3247 * @method signature 3248 * @return {String} event signature 3249 */ 3250 SolidityEvent.prototype.signature = function() { 3251 return sha3(this._name); 3252 }; 3253 3254 /** 3255 * Should be used to encode indexed params and options to one final object 3256 * 3257 * @method encode 3258 * @param {Object} indexed 3259 * @param {Object} options 3260 * @return {Object} everything combined together and encoded 3261 */ 3262 SolidityEvent.prototype.encode = function(indexed, options) { 3263 indexed = indexed || {}; 3264 options = options || {}; 3265 var result = {}; 3266 3267 ['fromBlock', 'toBlock'].filter(function(f) { 3268 return options[f] !== undefined; 3269 }).forEach(function(f) { 3270 result[f] = formatters.inputBlockNumberFormatter(options[f]); 3271 }); 3272 3273 result.topics = []; 3274 3275 result.address = this._address; 3276 if (!this._anonymous) { 3277 result.topics.push('0x' + this.signature()); 3278 } 3279 3280 var indexedTopics = this._params.filter(function(i) { 3281 return i.indexed === true; 3282 }).map(function(i) { 3283 var value = indexed[i.name]; 3284 if (value === undefined || value === null) { 3285 return null; 3286 } 3287 3288 if (utils.isArray(value)) { 3289 return value.map(function(v) { 3290 return '0x' + coder.encodeParam(i.type, v); 3291 }); 3292 } 3293 return '0x' + coder.encodeParam(i.type, value); 3294 }); 3295 3296 result.topics = result.topics.concat(indexedTopics); 3297 3298 return result; 3299 }; 3300 3301 /** 3302 * Should be used to decode indexed params and options 3303 * 3304 * @method decode 3305 * @param {Object} data 3306 * @return {Object} result object with decoded indexed && not indexed params 3307 */ 3308 SolidityEvent.prototype.decode = function(data) { 3309 3310 data.data = data.data || ''; 3311 data.topics = data.topics || []; 3312 3313 var argTopics = this._anonymous ? data.topics : data.topics.slice(1); 3314 var indexedData = argTopics.map(function(topics) { 3315 return topics.slice(2); 3316 }).join(""); 3317 var indexedParams = coder.decodeParams(this.types(true), indexedData); 3318 3319 var notIndexedData = data.data.slice(2); 3320 var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData); 3321 3322 var result = formatters.outputLogFormatter(data); 3323 result.event = this.displayName(); 3324 result.address = data.address; 3325 3326 result.args = this._params.reduce(function(acc, current) { 3327 acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift(); 3328 return acc; 3329 }, {}); 3330 3331 delete result.data; 3332 delete result.topics; 3333 3334 return result; 3335 }; 3336 3337 /** 3338 * Should be used to create new filter object from event 3339 * 3340 * @method execute 3341 * @param {Object} indexed 3342 * @param {Object} options 3343 * @return {Object} filter object 3344 */ 3345 SolidityEvent.prototype.execute = function(indexed, options, callback) { 3346 3347 if (utils.isFunction(arguments[arguments.length - 1])) { 3348 callback = arguments[arguments.length - 1]; 3349 if (arguments.length === 2) 3350 options = null; 3351 if (arguments.length === 1) { 3352 options = null; 3353 indexed = {}; 3354 } 3355 } 3356 3357 var o = this.encode(indexed, options); 3358 var formatter = this.decode.bind(this); 3359 return new Filter(o, 'eth', this._requestManager, watches.eth(), formatter, callback); 3360 }; 3361 3362 /** 3363 * Should be used to attach event to contract object 3364 * 3365 * @method attachToContract 3366 * @param {Contract} 3367 */ 3368 SolidityEvent.prototype.attachToContract = function(contract) { 3369 var execute = this.execute.bind(this); 3370 var displayName = this.displayName(); 3371 if (!contract[displayName]) { 3372 contract[displayName] = execute; 3373 } 3374 contract[displayName][this.typeName()] = this.execute.bind(this, contract); 3375 }; 3376 3377 module.exports = SolidityEvent; 3378 3379 3380 }, { 3381 "../solidity/coder": 7, 3382 "../utils/sha3": 19, 3383 "../utils/utils": 20, 3384 "./filter": 29, 3385 "./formatters": 30, 3386 "./methods/watches": 43 3387 }], 3388 28: [function(require, module, exports) { 3389 var formatters = require('./formatters'); 3390 var utils = require('./../utils/utils'); 3391 var Method = require('./method'); 3392 var Property = require('./property'); 3393 3394 // TODO: refactor, so the input params are not altered. 3395 // it's necessary to make same 'extension' work with multiple providers 3396 var extend = function(web3) { 3397 /* jshint maxcomplexity:5 */ 3398 var ex = function(extension) { 3399 3400 var extendedObject; 3401 if (extension.property) { 3402 if (!web3[extension.property]) { 3403 web3[extension.property] = {}; 3404 } 3405 extendedObject = web3[extension.property]; 3406 } else { 3407 extendedObject = web3; 3408 } 3409 3410 if (extension.methods) { 3411 extension.methods.forEach(function(method) { 3412 method.attachToObject(extendedObject); 3413 method.setRequestManager(web3._requestManager); 3414 }); 3415 } 3416 3417 if (extension.properties) { 3418 extension.properties.forEach(function(property) { 3419 property.attachToObject(extendedObject); 3420 property.setRequestManager(web3._requestManager); 3421 }); 3422 } 3423 }; 3424 3425 ex.formatters = formatters; 3426 ex.utils = utils; 3427 ex.Method = Method; 3428 ex.Property = Property; 3429 3430 return ex; 3431 }; 3432 3433 3434 3435 module.exports = extend; 3436 3437 3438 }, { 3439 "./../utils/utils": 20, 3440 "./formatters": 30, 3441 "./method": 36, 3442 "./property": 45 3443 }], 3444 29: [function(require, module, exports) { 3445 /* 3446 This file is part of web3.js. 3447 3448 web3.js is free software: you can redistribute it and/or modify 3449 it under the terms of the GNU Lesser General Public License as published by 3450 the Free Software Foundation, either version 3 of the License, or 3451 (at your option) any later version. 3452 3453 web3.js is distributed in the hope that it will be useful, 3454 but WITHOUT ANY WARRANTY; without even the implied warranty of 3455 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3456 GNU Lesser General Public License for more details. 3457 3458 You should have received a copy of the GNU Lesser General Public License 3459 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3460 */ 3461 /** @file filter.js 3462 * @authors: 3463 * Jeffrey Wilcke <jeff@ethdev.com> 3464 * Marek Kotewicz <marek@ethdev.com> 3465 * Marian Oancea <marian@ethdev.com> 3466 * Fabian Vogelsteller <fabian@ethdev.com> 3467 * Gav Wood <g@ethdev.com> 3468 * @date 2014 3469 */ 3470 3471 var formatters = require('./formatters'); 3472 var utils = require('../utils/utils'); 3473 3474 /** 3475 * Converts a given topic to a hex string, but also allows null values. 3476 * 3477 * @param {Mixed} value 3478 * @return {String} 3479 */ 3480 var toTopic = function(value) { 3481 3482 if (value === null || typeof value === 'undefined') 3483 return null; 3484 3485 value = String(value); 3486 3487 if (value.indexOf('0x') === 0) 3488 return value; 3489 else 3490 return utils.fromUtf8(value); 3491 }; 3492 3493 /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones 3494 /// @param should be string or object 3495 /// @returns options string or object 3496 var getOptions = function(options, type) { 3497 /*jshint maxcomplexity: 6 */ 3498 3499 if (utils.isString(options)) { 3500 return options; 3501 } 3502 3503 options = options || {}; 3504 3505 3506 switch (type) { 3507 case 'eth': 3508 3509 // make sure topics, get converted to hex 3510 options.topics = options.topics || []; 3511 options.topics = options.topics.map(function(topic) { 3512 return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic); 3513 }); 3514 3515 return { 3516 topics: options.topics, 3517 from: options.from, 3518 to: options.to, 3519 address: options.address, 3520 fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock), 3521 toBlock: formatters.inputBlockNumberFormatter(options.toBlock) 3522 }; 3523 case 'shh': 3524 return options; 3525 } 3526 }; 3527 3528 /** 3529 Adds the callback and sets up the methods, to iterate over the results. 3530 3531 @method getLogsAtStart 3532 @param {Object} self 3533 @param {function} callback 3534 */ 3535 var getLogsAtStart = function(self, callback) { 3536 // call getFilterLogs for the first watch callback start 3537 if (!utils.isString(self.options)) { 3538 self.get(function(err, messages) { 3539 // don't send all the responses to all the watches again... just to self one 3540 if (err) { 3541 callback(err); 3542 } 3543 3544 if (utils.isArray(messages)) { 3545 messages.forEach(function(message) { 3546 callback(null, message); 3547 }); 3548 } 3549 }); 3550 } 3551 }; 3552 3553 /** 3554 Adds the callback and sets up the methods, to iterate over the results. 3555 3556 @method pollFilter 3557 @param {Object} self 3558 */ 3559 var pollFilter = function(self) { 3560 3561 var onMessage = function(error, messages) { 3562 if (error) { 3563 return self.callbacks.forEach(function(callback) { 3564 callback(error); 3565 }); 3566 } 3567 3568 if (utils.isArray(messages)) { 3569 messages.forEach(function(message) { 3570 message = self.formatter ? self.formatter(message) : message; 3571 self.callbacks.forEach(function(callback) { 3572 callback(null, message); 3573 }); 3574 }); 3575 } 3576 }; 3577 3578 self.requestManager.startPolling({ 3579 method: self.implementation.poll.call, 3580 params: [self.filterId], 3581 }, self.filterId, onMessage, self.stopWatching.bind(self)); 3582 3583 }; 3584 3585 var Filter = function(options, type, requestManager, methods, formatter, callback, filterCreationErrorCallback) { 3586 var self = this; 3587 var implementation = {}; 3588 methods.forEach(function(method) { 3589 method.setRequestManager(requestManager); 3590 method.attachToObject(implementation); 3591 }); 3592 this.requestManager = requestManager; 3593 this.options = getOptions(options, type); 3594 this.implementation = implementation; 3595 this.filterId = null; 3596 this.callbacks = []; 3597 this.getLogsCallbacks = []; 3598 this.pollFilters = []; 3599 this.formatter = formatter; 3600 this.implementation.newFilter(this.options, function(error, id) { 3601 if (error) { 3602 self.callbacks.forEach(function(cb) { 3603 cb(error); 3604 }); 3605 if (typeof filterCreationErrorCallback === 'function') { 3606 filterCreationErrorCallback(error); 3607 } 3608 } else { 3609 self.filterId = id; 3610 3611 // check if there are get pending callbacks as a consequence 3612 // of calling get() with filterId unassigned. 3613 self.getLogsCallbacks.forEach(function(cb) { 3614 self.get(cb); 3615 }); 3616 self.getLogsCallbacks = []; 3617 3618 // get filter logs for the already existing watch calls 3619 self.callbacks.forEach(function(cb) { 3620 getLogsAtStart(self, cb); 3621 }); 3622 if (self.callbacks.length > 0) 3623 pollFilter(self); 3624 3625 // start to watch immediately 3626 if (typeof callback === 'function') { 3627 return self.watch(callback); 3628 } 3629 } 3630 }); 3631 3632 return this; 3633 }; 3634 3635 Filter.prototype.watch = function(callback) { 3636 this.callbacks.push(callback); 3637 3638 if (this.filterId) { 3639 getLogsAtStart(this, callback); 3640 pollFilter(this); 3641 } 3642 3643 return this; 3644 }; 3645 3646 Filter.prototype.stopWatching = function(callback) { 3647 this.requestManager.stopPolling(this.filterId); 3648 this.callbacks = []; 3649 // remove filter async 3650 if (callback) { 3651 this.implementation.uninstallFilter(this.filterId, callback); 3652 } else { 3653 return this.implementation.uninstallFilter(this.filterId); 3654 } 3655 }; 3656 3657 Filter.prototype.get = function(callback) { 3658 var self = this; 3659 if (utils.isFunction(callback)) { 3660 if (this.filterId === null) { 3661 // If filterId is not set yet, call it back 3662 // when newFilter() assigns it. 3663 this.getLogsCallbacks.push(callback); 3664 } else { 3665 this.implementation.getLogs(this.filterId, function(err, res) { 3666 if (err) { 3667 callback(err); 3668 } else { 3669 callback(null, res.map(function(log) { 3670 return self.formatter ? self.formatter(log) : log; 3671 })); 3672 } 3673 }); 3674 } 3675 } else { 3676 if (this.filterId === null) { 3677 throw new Error('Filter ID Error: filter().get() can\'t be chained synchronous, please provide a callback for the get() method.'); 3678 } 3679 var logs = this.implementation.getLogs(this.filterId); 3680 return logs.map(function(log) { 3681 return self.formatter ? self.formatter(log) : log; 3682 }); 3683 } 3684 3685 return this; 3686 }; 3687 3688 module.exports = Filter; 3689 3690 3691 }, { 3692 "../utils/utils": 20, 3693 "./formatters": 30 3694 }], 3695 30: [function(require, module, exports) { 3696 'use strict' 3697 3698 /* 3699 This file is part of web3.js. 3700 3701 web3.js is free software: you can redistribute it and/or modify 3702 it under the terms of the GNU Lesser General Public License as published by 3703 the Free Software Foundation, either version 3 of the License, or 3704 (at your option) any later version. 3705 3706 web3.js is distributed in the hope that it will be useful, 3707 but WITHOUT ANY WARRANTY; without even the implied warranty of 3708 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3709 GNU Lesser General Public License for more details. 3710 3711 You should have received a copy of the GNU Lesser General Public License 3712 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 3713 */ 3714 /** 3715 * @file formatters.js 3716 * @author Marek Kotewicz <marek@ethdev.com> 3717 * @author Fabian Vogelsteller <fabian@ethdev.com> 3718 * @date 2015 3719 */ 3720 3721 var utils = require('../utils/utils'); 3722 var config = require('../utils/config'); 3723 var Iban = require('./iban'); 3724 3725 /** 3726 * Should the format output to a big number 3727 * 3728 * @method outputBigNumberFormatter 3729 * @param {String|Number|BigNumber} 3730 * @returns {BigNumber} object 3731 */ 3732 var outputBigNumberFormatter = function(number) { 3733 return utils.toBigNumber(number); 3734 }; 3735 3736 var isPredefinedBlockNumber = function(blockNumber) { 3737 return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest'; 3738 }; 3739 3740 var inputDefaultBlockNumberFormatter = function(blockNumber) { 3741 if (blockNumber === undefined) { 3742 return config.defaultBlock; 3743 } 3744 return inputBlockNumberFormatter(blockNumber); 3745 }; 3746 3747 var inputBlockNumberFormatter = function(blockNumber) { 3748 if (blockNumber === undefined) { 3749 return undefined; 3750 } else if (isPredefinedBlockNumber(blockNumber)) { 3751 return blockNumber; 3752 } 3753 return utils.toHex(blockNumber); 3754 }; 3755 3756 /** 3757 * Formats the input of a transaction and converts all values to HEX 3758 * 3759 * @method inputCallFormatter 3760 * @param {Object} transaction options 3761 * @returns object 3762 */ 3763 var inputCallFormatter = function(options) { 3764 3765 options.from = options.from || config.defaultAccount; 3766 3767 if (options.from) { 3768 options.from = inputAddressFormatter(options.from); 3769 } 3770 3771 if (options.to) { // it might be contract creation 3772 options.to = inputAddressFormatter(options.to); 3773 } 3774 3775 ['gasPrice', 'gas', 'value', 'nonce'].filter(function(key) { 3776 return options[key] !== undefined; 3777 }).forEach(function(key) { 3778 options[key] = utils.fromDecimal(options[key]); 3779 }); 3780 3781 return options; 3782 }; 3783 3784 /** 3785 * Formats the input of a transaction and converts all values to HEX 3786 * 3787 * @method inputTransactionFormatter 3788 * @param {Object} transaction options 3789 * @returns object 3790 */ 3791 var inputTransactionFormatter = function(options) { 3792 3793 options.from = options.from || config.defaultAccount; 3794 options.from = inputAddressFormatter(options.from); 3795 3796 if (options.to) { // it might be contract creation 3797 options.to = inputAddressFormatter(options.to); 3798 } 3799 3800 ['gasPrice', 'gas', 'value', 'nonce'].filter(function(key) { 3801 return options[key] !== undefined; 3802 }).forEach(function(key) { 3803 options[key] = utils.fromDecimal(options[key]); 3804 }); 3805 3806 return options; 3807 }; 3808 3809 /** 3810 * Formats the output of a transaction to its proper values 3811 * 3812 * @method outputTransactionFormatter 3813 * @param {Object} tx 3814 * @returns {Object} 3815 */ 3816 var outputTransactionFormatter = function(tx) { 3817 if (tx.blockNumber !== null) 3818 tx.blockNumber = utils.toDecimal(tx.blockNumber); 3819 if (tx.transactionIndex !== null) 3820 tx.transactionIndex = utils.toDecimal(tx.transactionIndex); 3821 tx.nonce = utils.toDecimal(tx.nonce); 3822 tx.gas = utils.toDecimal(tx.gas); 3823 tx.gasPrice = utils.toBigNumber(tx.gasPrice); 3824 tx.value = utils.toBigNumber(tx.value); 3825 return tx; 3826 }; 3827 3828 /** 3829 * Formats the output of a transaction receipt to its proper values 3830 * 3831 * @method outputTransactionReceiptFormatter 3832 * @param {Object} receipt 3833 * @returns {Object} 3834 */ 3835 var outputTransactionReceiptFormatter = function(receipt) { 3836 if (receipt.blockNumber !== null) 3837 receipt.blockNumber = utils.toDecimal(receipt.blockNumber); 3838 if (receipt.transactionIndex !== null) 3839 receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex); 3840 receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed); 3841 receipt.gasUsed = utils.toDecimal(receipt.gasUsed); 3842 3843 if (utils.isArray(receipt.logs)) { 3844 receipt.logs = receipt.logs.map(function(log) { 3845 return outputLogFormatter(log); 3846 }); 3847 } 3848 3849 return receipt; 3850 }; 3851 3852 /** 3853 * Formats the output of a block to its proper values 3854 * 3855 * @method outputBlockFormatter 3856 * @param {Object} block 3857 * @returns {Object} 3858 */ 3859 var outputBlockFormatter = function(block) { 3860 3861 // transform to number 3862 block.gasLimit = utils.toDecimal(block.gasLimit); 3863 block.gasUsed = utils.toDecimal(block.gasUsed); 3864 block.size = utils.toDecimal(block.size); 3865 block.timestamp = utils.toDecimal(block.timestamp); 3866 if (block.number !== null) 3867 block.number = utils.toDecimal(block.number); 3868 3869 block.difficulty = utils.toBigNumber(block.difficulty); 3870 block.totalDifficulty = utils.toBigNumber(block.totalDifficulty); 3871 3872 if (utils.isArray(block.transactions)) { 3873 block.transactions.forEach(function(item) { 3874 if (!utils.isString(item)) 3875 return outputTransactionFormatter(item); 3876 }); 3877 } 3878 3879 return block; 3880 }; 3881 3882 /** 3883 * Formats the output of a log 3884 * 3885 * @method outputLogFormatter 3886 * @param {Object} log object 3887 * @returns {Object} log 3888 */ 3889 var outputLogFormatter = function(log) { 3890 if (log.blockNumber) 3891 log.blockNumber = utils.toDecimal(log.blockNumber); 3892 if (log.transactionIndex) 3893 log.transactionIndex = utils.toDecimal(log.transactionIndex); 3894 if (log.logIndex) 3895 log.logIndex = utils.toDecimal(log.logIndex); 3896 3897 return log; 3898 }; 3899 3900 /** 3901 * Formats the input of a whisper post and converts all values to HEX 3902 * 3903 * @method inputPostFormatter 3904 * @param {Object} transaction object 3905 * @returns {Object} 3906 */ 3907 var inputPostFormatter = function(post) { 3908 3909 // post.payload = utils.toHex(post.payload); 3910 post.ttl = utils.fromDecimal(post.ttl); 3911 post.workToProve = utils.fromDecimal(post.workToProve); 3912 post.priority = utils.fromDecimal(post.priority); 3913 3914 // fallback 3915 if (!utils.isArray(post.topics)) { 3916 post.topics = post.topics ? [post.topics] : []; 3917 } 3918 3919 // format the following options 3920 post.topics = post.topics.map(function(topic) { 3921 // convert only if not hex 3922 return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic); 3923 }); 3924 3925 return post; 3926 }; 3927 3928 /** 3929 * Formats the output of a received post message 3930 * 3931 * @method outputPostFormatter 3932 * @param {Object} 3933 * @returns {Object} 3934 */ 3935 var outputPostFormatter = function(post) { 3936 3937 post.expiry = utils.toDecimal(post.expiry); 3938 post.sent = utils.toDecimal(post.sent); 3939 post.ttl = utils.toDecimal(post.ttl); 3940 post.workProved = utils.toDecimal(post.workProved); 3941 // post.payloadRaw = post.payload; 3942 // post.payload = utils.toAscii(post.payload); 3943 3944 // if (utils.isJson(post.payload)) { 3945 // post.payload = JSON.parse(post.payload); 3946 // } 3947 3948 // format the following options 3949 if (!post.topics) { 3950 post.topics = []; 3951 } 3952 post.topics = post.topics.map(function(topic) { 3953 return utils.toAscii(topic); 3954 }); 3955 3956 return post; 3957 }; 3958 3959 var inputAddressFormatter = function(address) { 3960 var iban = new Iban(address); 3961 if (iban.isValid() && iban.isDirect()) { 3962 return '0x' + iban.address(); 3963 } else if (utils.isStrictAddress(address)) { 3964 return address; 3965 } else if (utils.isAddress(address)) { 3966 return '0x' + address; 3967 } 3968 throw new Error('invalid address'); 3969 }; 3970 3971 3972 var outputSyncingFormatter = function(result) { 3973 if (!result) { 3974 return result; 3975 } 3976 3977 result.startingBlock = utils.toDecimal(result.startingBlock); 3978 result.currentBlock = utils.toDecimal(result.currentBlock); 3979 result.highestBlock = utils.toDecimal(result.highestBlock); 3980 if (result.knownStates) { 3981 result.knownStates = utils.toDecimal(result.knownStates); 3982 result.pulledStates = utils.toDecimal(result.pulledStates); 3983 } 3984 3985 return result; 3986 }; 3987 3988 module.exports = { 3989 inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter, 3990 inputBlockNumberFormatter: inputBlockNumberFormatter, 3991 inputCallFormatter: inputCallFormatter, 3992 inputTransactionFormatter: inputTransactionFormatter, 3993 inputAddressFormatter: inputAddressFormatter, 3994 inputPostFormatter: inputPostFormatter, 3995 outputBigNumberFormatter: outputBigNumberFormatter, 3996 outputTransactionFormatter: outputTransactionFormatter, 3997 outputTransactionReceiptFormatter: outputTransactionReceiptFormatter, 3998 outputBlockFormatter: outputBlockFormatter, 3999 outputLogFormatter: outputLogFormatter, 4000 outputPostFormatter: outputPostFormatter, 4001 outputSyncingFormatter: outputSyncingFormatter 4002 }; 4003 4004 4005 }, { 4006 "../utils/config": 18, 4007 "../utils/utils": 20, 4008 "./iban": 33 4009 }], 4010 31: [function(require, module, exports) { 4011 /* 4012 This file is part of web3.js. 4013 4014 web3.js is free software: you can redistribute it and/or modify 4015 it under the terms of the GNU Lesser General Public License as published by 4016 the Free Software Foundation, either version 3 of the License, or 4017 (at your option) any later version. 4018 4019 web3.js is distributed in the hope that it will be useful, 4020 but WITHOUT ANY WARRANTY; without even the implied warranty of 4021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4022 GNU Lesser General Public License for more details. 4023 4024 You should have received a copy of the GNU Lesser General Public License 4025 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4026 */ 4027 /** 4028 * @file function.js 4029 * @author Marek Kotewicz <marek@ethdev.com> 4030 * @date 2015 4031 */ 4032 4033 var coder = require('../solidity/coder'); 4034 var utils = require('../utils/utils'); 4035 var errors = require('./errors'); 4036 var formatters = require('./formatters'); 4037 var sha3 = require('../utils/sha3'); 4038 4039 /** 4040 * This prototype should be used to call/sendTransaction to solidity functions 4041 */ 4042 var SolidityFunction = function(eth, json, address) { 4043 this._eth = eth; 4044 this._inputTypes = json.inputs.map(function(i) { 4045 return i.type; 4046 }); 4047 this._outputTypes = json.outputs.map(function(i) { 4048 return i.type; 4049 }); 4050 this._constant = json.constant; 4051 this._payable = json.payable; 4052 this._name = utils.transformToFullName(json); 4053 this._address = address; 4054 }; 4055 4056 SolidityFunction.prototype.extractCallback = function(args) { 4057 if (utils.isFunction(args[args.length - 1])) { 4058 return args.pop(); // modify the args array! 4059 } 4060 }; 4061 4062 SolidityFunction.prototype.extractDefaultBlock = function(args) { 4063 if (args.length > this._inputTypes.length && !utils.isObject(args[args.length - 1])) { 4064 return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array! 4065 } 4066 }; 4067 4068 /** 4069 * Should be called to check if the number of arguments is correct 4070 * 4071 * @method validateArgs 4072 * @param {Array} arguments 4073 * @throws {Error} if it is not 4074 */ 4075 SolidityFunction.prototype.validateArgs = function(args) { 4076 var inputArgs = args.filter(function(a) { 4077 // filter the options object but not arguments that are arrays 4078 return !((utils.isObject(a) === true) && 4079 (utils.isArray(a) === false) && 4080 (utils.isBigNumber(a) === false) 4081 ); 4082 }); 4083 if (inputArgs.length !== this._inputTypes.length) { 4084 throw errors.InvalidNumberOfSolidityArgs(); 4085 } 4086 }; 4087 4088 /** 4089 * Should be used to create payload from arguments 4090 * 4091 * @method toPayload 4092 * @param {Array} solidity function params 4093 * @param {Object} optional payload options 4094 */ 4095 SolidityFunction.prototype.toPayload = function(args) { 4096 var options = {}; 4097 if (args.length > this._inputTypes.length && utils.isObject(args[args.length - 1])) { 4098 options = args[args.length - 1]; 4099 } 4100 this.validateArgs(args); 4101 options.to = this._address; 4102 options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args); 4103 return options; 4104 }; 4105 4106 /** 4107 * Should be used to get function signature 4108 * 4109 * @method signature 4110 * @return {String} function signature 4111 */ 4112 SolidityFunction.prototype.signature = function() { 4113 return sha3(this._name).slice(0, 8); 4114 }; 4115 4116 4117 SolidityFunction.prototype.unpackOutput = function(output) { 4118 if (!output) { 4119 return; 4120 } 4121 4122 output = output.length >= 2 ? output.slice(2) : output; 4123 var result = coder.decodeParams(this._outputTypes, output); 4124 return result.length === 1 ? result[0] : result; 4125 }; 4126 4127 /** 4128 * Calls a contract function. 4129 * 4130 * @method call 4131 * @param {...Object} Contract function arguments 4132 * @param {function} If the last argument is a function, the contract function 4133 * call will be asynchronous, and the callback will be passed the 4134 * error and result. 4135 * @return {String} output bytes 4136 */ 4137 SolidityFunction.prototype.call = function() { 4138 var args = Array.prototype.slice.call(arguments).filter(function(a) { 4139 return a !== undefined; 4140 }); 4141 var callback = this.extractCallback(args); 4142 var defaultBlock = this.extractDefaultBlock(args); 4143 var payload = this.toPayload(args); 4144 4145 4146 if (!callback) { 4147 var output = this._eth.call(payload, defaultBlock); 4148 return this.unpackOutput(output); 4149 } 4150 4151 var self = this; 4152 this._eth.call(payload, defaultBlock, function(error, output) { 4153 if (error) return callback(error, null); 4154 4155 var unpacked = null; 4156 try { 4157 unpacked = self.unpackOutput(output); 4158 } catch (e) { 4159 error = e; 4160 } 4161 4162 callback(error, unpacked); 4163 }); 4164 }; 4165 4166 /** 4167 * Should be used to sendTransaction to solidity function 4168 * 4169 * @method sendTransaction 4170 */ 4171 SolidityFunction.prototype.sendTransaction = function() { 4172 var args = Array.prototype.slice.call(arguments).filter(function(a) { 4173 return a !== undefined; 4174 }); 4175 var callback = this.extractCallback(args); 4176 var payload = this.toPayload(args); 4177 4178 if (payload.value > 0 && !this._payable) { 4179 throw new Error('Cannot send value to non-payable function'); 4180 } 4181 4182 if (!callback) { 4183 return this._eth.sendTransaction(payload); 4184 } 4185 4186 this._eth.sendTransaction(payload, callback); 4187 }; 4188 4189 /** 4190 * Should be used to estimateGas of solidity function 4191 * 4192 * @method estimateGas 4193 */ 4194 SolidityFunction.prototype.estimateGas = function() { 4195 var args = Array.prototype.slice.call(arguments); 4196 var callback = this.extractCallback(args); 4197 var payload = this.toPayload(args); 4198 4199 if (!callback) { 4200 return this._eth.estimateGas(payload); 4201 } 4202 4203 this._eth.estimateGas(payload, callback); 4204 }; 4205 4206 /** 4207 * Return the encoded data of the call 4208 * 4209 * @method getData 4210 * @return {String} the encoded data 4211 */ 4212 SolidityFunction.prototype.getData = function() { 4213 var args = Array.prototype.slice.call(arguments); 4214 var payload = this.toPayload(args); 4215 4216 return payload.data; 4217 }; 4218 4219 /** 4220 * Should be used to get function display name 4221 * 4222 * @method displayName 4223 * @return {String} display name of the function 4224 */ 4225 SolidityFunction.prototype.displayName = function() { 4226 return utils.extractDisplayName(this._name); 4227 }; 4228 4229 /** 4230 * Should be used to get function type name 4231 * 4232 * @method typeName 4233 * @return {String} type name of the function 4234 */ 4235 SolidityFunction.prototype.typeName = function() { 4236 return utils.extractTypeName(this._name); 4237 }; 4238 4239 /** 4240 * Should be called to get rpc requests from solidity function 4241 * 4242 * @method request 4243 * @returns {Object} 4244 */ 4245 SolidityFunction.prototype.request = function() { 4246 var args = Array.prototype.slice.call(arguments); 4247 var callback = this.extractCallback(args); 4248 var payload = this.toPayload(args); 4249 var format = this.unpackOutput.bind(this); 4250 4251 return { 4252 method: this._constant ? 'eth_call' : 'eth_sendTransaction', 4253 callback: callback, 4254 params: [payload], 4255 format: format 4256 }; 4257 }; 4258 4259 /** 4260 * Should be called to execute function 4261 * 4262 * @method execute 4263 */ 4264 SolidityFunction.prototype.execute = function() { 4265 var transaction = !this._constant; 4266 4267 // send transaction 4268 if (transaction) { 4269 return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments)); 4270 } 4271 4272 // call 4273 return this.call.apply(this, Array.prototype.slice.call(arguments)); 4274 }; 4275 4276 /** 4277 * Should be called to attach function to contract 4278 * 4279 * @method attachToContract 4280 * @param {Contract} 4281 */ 4282 SolidityFunction.prototype.attachToContract = function(contract) { 4283 var execute = this.execute.bind(this); 4284 execute.request = this.request.bind(this); 4285 execute.call = this.call.bind(this); 4286 execute.sendTransaction = this.sendTransaction.bind(this); 4287 execute.estimateGas = this.estimateGas.bind(this); 4288 execute.getData = this.getData.bind(this); 4289 var displayName = this.displayName(); 4290 if (!contract[displayName]) { 4291 contract[displayName] = execute; 4292 } 4293 contract[displayName][this.typeName()] = execute; // circular!!!! 4294 }; 4295 4296 module.exports = SolidityFunction; 4297 4298 }, { 4299 "../solidity/coder": 7, 4300 "../utils/sha3": 19, 4301 "../utils/utils": 20, 4302 "./errors": 26, 4303 "./formatters": 30 4304 }], 4305 32: [function(require, module, exports) { 4306 /* 4307 This file is part of web3.js. 4308 4309 web3.js is free software: you can redistribute it and/or modify 4310 it under the terms of the GNU Lesser General Public License as published by 4311 the Free Software Foundation, either version 3 of the License, or 4312 (at your option) any later version. 4313 4314 web3.js is distributed in the hope that it will be useful, 4315 but WITHOUT ANY WARRANTY; without even the implied warranty of 4316 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4317 GNU Lesser General Public License for more details. 4318 4319 You should have received a copy of the GNU Lesser General Public License 4320 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4321 */ 4322 /** @file httpprovider.js 4323 * @authors: 4324 * Marek Kotewicz <marek@ethdev.com> 4325 * Marian Oancea <marian@ethdev.com> 4326 * Fabian Vogelsteller <fabian@ethdev.com> 4327 * @date 2015 4328 */ 4329 4330 var errors = require('./errors'); 4331 4332 // workaround to use httpprovider in different envs 4333 4334 // browser 4335 if (typeof window !== 'undefined' && window.XMLHttpRequest) { 4336 XMLHttpRequest = window.XMLHttpRequest; // jshint ignore: line 4337 // node 4338 } else { 4339 XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore: line 4340 } 4341 4342 var XHR2 = require('xhr2'); // jshint ignore: line 4343 4344 /** 4345 * HttpProvider should be used to send rpc calls over http 4346 */ 4347 var HttpProvider = function(host, timeout, user, password) { 4348 this.host = host || 'http://localhost:8545'; 4349 this.timeout = timeout || 0; 4350 this.user = user; 4351 this.password = password; 4352 }; 4353 4354 /** 4355 * Should be called to prepare new XMLHttpRequest 4356 * 4357 * @method prepareRequest 4358 * @param {Boolean} true if request should be async 4359 * @return {XMLHttpRequest} object 4360 */ 4361 HttpProvider.prototype.prepareRequest = function(async) { 4362 var request; 4363 4364 if (async) { 4365 request = new XHR2(); 4366 request.timeout = this.timeout; 4367 } else { 4368 request = new XMLHttpRequest(); 4369 } 4370 4371 request.open('POST', this.host, async); 4372 if (this.user && this.password) { 4373 var auth = 'Basic ' + new Buffer(this.user + ':' + this.password).toString('base64'); 4374 request.setRequestHeader('Authorization', auth); 4375 } 4376 request.setRequestHeader('Content-Type', 'application/json'); 4377 return request; 4378 }; 4379 4380 /** 4381 * Should be called to make sync request 4382 * 4383 * @method send 4384 * @param {Object} payload 4385 * @return {Object} result 4386 */ 4387 HttpProvider.prototype.send = function(payload) { 4388 var request = this.prepareRequest(false); 4389 4390 try { 4391 request.send(JSON.stringify(payload)); 4392 } catch (error) { 4393 throw errors.InvalidConnection(this.host); 4394 } 4395 4396 var result = request.responseText; 4397 4398 try { 4399 result = JSON.parse(result); 4400 } catch (e) { 4401 throw errors.InvalidResponse(request.responseText); 4402 } 4403 4404 return result; 4405 }; 4406 4407 /** 4408 * Should be used to make async request 4409 * 4410 * @method sendAsync 4411 * @param {Object} payload 4412 * @param {Function} callback triggered on end with (err, result) 4413 */ 4414 HttpProvider.prototype.sendAsync = function(payload, callback) { 4415 var request = this.prepareRequest(true); 4416 4417 request.onreadystatechange = function() { 4418 if (request.readyState === 4 && request.timeout !== 1) { 4419 var result = request.responseText; 4420 var error = null; 4421 4422 try { 4423 result = JSON.parse(result); 4424 } catch (e) { 4425 error = errors.InvalidResponse(request.responseText); 4426 } 4427 4428 callback(error, result); 4429 } 4430 }; 4431 4432 request.ontimeout = function() { 4433 callback(errors.ConnectionTimeout(this.timeout)); 4434 }; 4435 4436 try { 4437 request.send(JSON.stringify(payload)); 4438 } catch (error) { 4439 callback(errors.InvalidConnection(this.host)); 4440 } 4441 }; 4442 4443 /** 4444 * Synchronously tries to make Http request 4445 * 4446 * @method isConnected 4447 * @return {Boolean} returns true if request haven't failed. Otherwise false 4448 */ 4449 HttpProvider.prototype.isConnected = function() { 4450 try { 4451 this.send({ 4452 id: 9999999999, 4453 jsonrpc: '2.0', 4454 method: 'net_listening', 4455 params: [] 4456 }); 4457 return true; 4458 } catch (e) { 4459 return false; 4460 } 4461 }; 4462 4463 module.exports = HttpProvider; 4464 4465 }, { 4466 "./errors": 26, 4467 "xhr2": 86, 4468 "xmlhttprequest": 17 4469 }], 4470 33: [function(require, module, exports) { 4471 /* 4472 This file is part of web3.js. 4473 4474 web3.js is free software: you can redistribute it and/or modify 4475 it under the terms of the GNU Lesser General Public License as published by 4476 the Free Software Foundation, either version 3 of the License, or 4477 (at your option) any later version. 4478 4479 web3.js is distributed in the hope that it will be useful, 4480 but WITHOUT ANY WARRANTY; without even the implied warranty of 4481 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4482 GNU Lesser General Public License for more details. 4483 4484 You should have received a copy of the GNU Lesser General Public License 4485 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4486 */ 4487 /** 4488 * @file iban.js 4489 * @author Marek Kotewicz <marek@ethdev.com> 4490 * @date 2015 4491 */ 4492 4493 var BigNumber = require('bignumber.js'); 4494 4495 var padLeft = function(string, bytes) { 4496 var result = string; 4497 while (result.length < bytes * 2) { 4498 result = '0' + result; 4499 } 4500 return result; 4501 }; 4502 4503 /** 4504 * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to 4505 * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616. 4506 * 4507 * @method iso13616Prepare 4508 * @param {String} iban the IBAN 4509 * @returns {String} the prepared IBAN 4510 */ 4511 var iso13616Prepare = function(iban) { 4512 var A = 'A'.charCodeAt(0); 4513 var Z = 'Z'.charCodeAt(0); 4514 4515 iban = iban.toUpperCase(); 4516 iban = iban.substr(4) + iban.substr(0, 4); 4517 4518 return iban.split('').map(function(n) { 4519 var code = n.charCodeAt(0); 4520 if (code >= A && code <= Z) { 4521 // A = 10, B = 11, ... Z = 35 4522 return code - A + 10; 4523 } else { 4524 return n; 4525 } 4526 }).join(''); 4527 }; 4528 4529 /** 4530 * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064. 4531 * 4532 * @method mod9710 4533 * @param {String} iban 4534 * @returns {Number} 4535 */ 4536 var mod9710 = function(iban) { 4537 var remainder = iban, 4538 block; 4539 4540 while (remainder.length > 2) { 4541 block = remainder.slice(0, 9); 4542 remainder = parseInt(block, 10) % 97 + remainder.slice(block.length); 4543 } 4544 4545 return parseInt(remainder, 10) % 97; 4546 }; 4547 4548 /** 4549 * This prototype should be used to create iban object from iban correct string 4550 * 4551 * @param {String} iban 4552 */ 4553 var Iban = function(iban) { 4554 this._iban = iban; 4555 }; 4556 4557 /** 4558 * This method should be used to create iban object from ethereum address 4559 * 4560 * @method fromAddress 4561 * @param {String} address 4562 * @return {Iban} the IBAN object 4563 */ 4564 Iban.fromAddress = function(address) { 4565 var asBn = new BigNumber(address, 16); 4566 var base36 = asBn.toString(36); 4567 var padded = padLeft(base36, 15); 4568 return Iban.fromBban(padded.toUpperCase()); 4569 }; 4570 4571 /** 4572 * Convert the passed BBAN to an IBAN for this country specification. 4573 * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>. 4574 * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits 4575 * 4576 * @method fromBban 4577 * @param {String} bban the BBAN to convert to IBAN 4578 * @returns {Iban} the IBAN object 4579 */ 4580 Iban.fromBban = function(bban) { 4581 var countryCode = 'XE'; 4582 4583 var remainder = mod9710(iso13616Prepare(countryCode + '00' + bban)); 4584 var checkDigit = ('0' + (98 - remainder)).slice(-2); 4585 4586 return new Iban(countryCode + checkDigit + bban); 4587 }; 4588 4589 /** 4590 * Should be used to create IBAN object for given institution and identifier 4591 * 4592 * @method createIndirect 4593 * @param {Object} options, required options are "institution" and "identifier" 4594 * @return {Iban} the IBAN object 4595 */ 4596 Iban.createIndirect = function(options) { 4597 return Iban.fromBban('ETH' + options.institution + options.identifier); 4598 }; 4599 4600 /** 4601 * Thos method should be used to check if given string is valid iban object 4602 * 4603 * @method isValid 4604 * @param {String} iban string 4605 * @return {Boolean} true if it is valid IBAN 4606 */ 4607 Iban.isValid = function(iban) { 4608 var i = new Iban(iban); 4609 return i.isValid(); 4610 }; 4611 4612 /** 4613 * Should be called to check if iban is correct 4614 * 4615 * @method isValid 4616 * @returns {Boolean} true if it is, otherwise false 4617 */ 4618 Iban.prototype.isValid = function() { 4619 return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban) && 4620 mod9710(iso13616Prepare(this._iban)) === 1; 4621 }; 4622 4623 /** 4624 * Should be called to check if iban number is direct 4625 * 4626 * @method isDirect 4627 * @returns {Boolean} true if it is, otherwise false 4628 */ 4629 Iban.prototype.isDirect = function() { 4630 return this._iban.length === 34 || this._iban.length === 35; 4631 }; 4632 4633 /** 4634 * Should be called to check if iban number if indirect 4635 * 4636 * @method isIndirect 4637 * @returns {Boolean} true if it is, otherwise false 4638 */ 4639 Iban.prototype.isIndirect = function() { 4640 return this._iban.length === 20; 4641 }; 4642 4643 /** 4644 * Should be called to get iban checksum 4645 * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) 4646 * 4647 * @method checksum 4648 * @returns {String} checksum 4649 */ 4650 Iban.prototype.checksum = function() { 4651 return this._iban.substr(2, 2); 4652 }; 4653 4654 /** 4655 * Should be called to get institution identifier 4656 * eg. XREG 4657 * 4658 * @method institution 4659 * @returns {String} institution identifier 4660 */ 4661 Iban.prototype.institution = function() { 4662 return this.isIndirect() ? this._iban.substr(7, 4) : ''; 4663 }; 4664 4665 /** 4666 * Should be called to get client identifier within institution 4667 * eg. GAVOFYORK 4668 * 4669 * @method client 4670 * @returns {String} client identifier 4671 */ 4672 Iban.prototype.client = function() { 4673 return this.isIndirect() ? this._iban.substr(11) : ''; 4674 }; 4675 4676 /** 4677 * Should be called to get client direct address 4678 * 4679 * @method address 4680 * @returns {String} client direct address 4681 */ 4682 Iban.prototype.address = function() { 4683 if (this.isDirect()) { 4684 var base36 = this._iban.substr(4); 4685 var asBn = new BigNumber(base36, 36); 4686 return padLeft(asBn.toString(16), 20); 4687 } 4688 4689 return ''; 4690 }; 4691 4692 Iban.prototype.toString = function() { 4693 return this._iban; 4694 }; 4695 4696 module.exports = Iban; 4697 4698 4699 }, { 4700 "bignumber.js": "bignumber.js" 4701 }], 4702 34: [function(require, module, exports) { 4703 /* 4704 This file is part of web3.js. 4705 4706 web3.js is free software: you can redistribute it and/or modify 4707 it under the terms of the GNU Lesser General Public License as published by 4708 the Free Software Foundation, either version 3 of the License, or 4709 (at your option) any later version. 4710 4711 web3.js is distributed in the hope that it will be useful, 4712 but WITHOUT ANY WARRANTY; without even the implied warranty of 4713 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4714 GNU Lesser General Public License for more details. 4715 4716 You should have received a copy of the GNU Lesser General Public License 4717 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4718 */ 4719 /** @file ipcprovider.js 4720 * @authors: 4721 * Fabian Vogelsteller <fabian@ethdev.com> 4722 * @date 2015 4723 */ 4724 4725 "use strict"; 4726 4727 var utils = require('../utils/utils'); 4728 var errors = require('./errors'); 4729 4730 4731 var IpcProvider = function(path, net) { 4732 var _this = this; 4733 this.responseCallbacks = {}; 4734 this.path = path; 4735 4736 this.connection = net.connect({ 4737 path: this.path 4738 }); 4739 4740 this.connection.on('error', function(e) { 4741 console.error('IPC Connection Error', e); 4742 _this._timeout(); 4743 }); 4744 4745 this.connection.on('end', function() { 4746 _this._timeout(); 4747 }); 4748 4749 4750 // LISTEN FOR CONNECTION RESPONSES 4751 this.connection.on('data', function(data) { 4752 /*jshint maxcomplexity: 6 */ 4753 4754 _this._parseResponse(data.toString()).forEach(function(result) { 4755 4756 var id = null; 4757 4758 // get the id which matches the returned id 4759 if (utils.isArray(result)) { 4760 result.forEach(function(load) { 4761 if (_this.responseCallbacks[load.id]) 4762 id = load.id; 4763 }); 4764 } else { 4765 id = result.id; 4766 } 4767 4768 // fire the callback 4769 if (_this.responseCallbacks[id]) { 4770 _this.responseCallbacks[id](null, result); 4771 delete _this.responseCallbacks[id]; 4772 } 4773 }); 4774 }); 4775 }; 4776 4777 /** 4778 Will parse the response and make an array out of it. 4779 4780 @method _parseResponse 4781 @param {String} data 4782 */ 4783 IpcProvider.prototype._parseResponse = function(data) { 4784 var _this = this, 4785 returnValues = []; 4786 4787 // DE-CHUNKER 4788 var dechunkedData = data 4789 .replace(/\}[\n\r]?\{/g, '}|--|{') // }{ 4790 .replace(/\}\][\n\r]?\[\{/g, '}]|--|[{') // }][{ 4791 .replace(/\}[\n\r]?\[\{/g, '}|--|[{') // }[{ 4792 .replace(/\}\][\n\r]?\{/g, '}]|--|{') // }]{ 4793 .split('|--|'); 4794 4795 dechunkedData.forEach(function(data) { 4796 4797 // prepend the last chunk 4798 if (_this.lastChunk) 4799 data = _this.lastChunk + data; 4800 4801 var result = null; 4802 4803 try { 4804 result = JSON.parse(data); 4805 4806 } catch (e) { 4807 4808 _this.lastChunk = data; 4809 4810 // start timeout to cancel all requests 4811 clearTimeout(_this.lastChunkTimeout); 4812 _this.lastChunkTimeout = setTimeout(function() { 4813 _this._timeout(); 4814 throw errors.InvalidResponse(data); 4815 }, 1000 * 15); 4816 4817 return; 4818 } 4819 4820 // cancel timeout and set chunk to null 4821 clearTimeout(_this.lastChunkTimeout); 4822 _this.lastChunk = null; 4823 4824 if (result) 4825 returnValues.push(result); 4826 }); 4827 4828 return returnValues; 4829 }; 4830 4831 4832 /** 4833 Get the adds a callback to the responseCallbacks object, 4834 which will be called if a response matching the response Id will arrive. 4835 4836 @method _addResponseCallback 4837 */ 4838 IpcProvider.prototype._addResponseCallback = function(payload, callback) { 4839 var id = payload.id || payload[0].id; 4840 var method = payload.method || payload[0].method; 4841 4842 this.responseCallbacks[id] = callback; 4843 this.responseCallbacks[id].method = method; 4844 }; 4845 4846 /** 4847 Timeout all requests when the end/error event is fired 4848 4849 @method _timeout 4850 */ 4851 IpcProvider.prototype._timeout = function() { 4852 for (var key in this.responseCallbacks) { 4853 if (this.responseCallbacks.hasOwnProperty(key)) { 4854 this.responseCallbacks[key](errors.InvalidConnection('on IPC')); 4855 delete this.responseCallbacks[key]; 4856 } 4857 } 4858 }; 4859 4860 4861 /** 4862 Check if the current connection is still valid. 4863 4864 @method isConnected 4865 */ 4866 IpcProvider.prototype.isConnected = function() { 4867 var _this = this; 4868 4869 // try reconnect, when connection is gone 4870 if (!_this.connection.writable) 4871 _this.connection.connect({ 4872 path: _this.path 4873 }); 4874 4875 return !!this.connection.writable; 4876 }; 4877 4878 IpcProvider.prototype.send = function(payload) { 4879 4880 if (this.connection.writeSync) { 4881 var result; 4882 4883 // try reconnect, when connection is gone 4884 if (!this.connection.writable) 4885 this.connection.connect({ 4886 path: this.path 4887 }); 4888 4889 var data = this.connection.writeSync(JSON.stringify(payload)); 4890 4891 try { 4892 result = JSON.parse(data); 4893 } catch (e) { 4894 throw errors.InvalidResponse(data); 4895 } 4896 4897 return result; 4898 4899 } else { 4900 throw new Error('You tried to send "' + payload.method + '" synchronously. Synchronous requests are not supported by the IPC provider.'); 4901 } 4902 }; 4903 4904 IpcProvider.prototype.sendAsync = function(payload, callback) { 4905 // try reconnect, when connection is gone 4906 if (!this.connection.writable) 4907 this.connection.connect({ 4908 path: this.path 4909 }); 4910 4911 4912 this.connection.write(JSON.stringify(payload)); 4913 this._addResponseCallback(payload, callback); 4914 }; 4915 4916 module.exports = IpcProvider; 4917 4918 4919 }, { 4920 "../utils/utils": 20, 4921 "./errors": 26 4922 }], 4923 35: [function(require, module, exports) { 4924 /* 4925 This file is part of web3.js. 4926 4927 web3.js is free software: you can redistribute it and/or modify 4928 it under the terms of the GNU Lesser General Public License as published by 4929 the Free Software Foundation, either version 3 of the License, or 4930 (at your option) any later version. 4931 4932 web3.js is distributed in the hope that it will be useful, 4933 but WITHOUT ANY WARRANTY; without even the implied warranty of 4934 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 4935 GNU Lesser General Public License for more details. 4936 4937 You should have received a copy of the GNU Lesser General Public License 4938 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 4939 */ 4940 /** @file jsonrpc.js 4941 * @authors: 4942 * Marek Kotewicz <marek@ethdev.com> 4943 * Aaron Kumavis <aaron@kumavis.me> 4944 * @date 2015 4945 */ 4946 4947 // Initialize Jsonrpc as a simple object with utility functions. 4948 var Jsonrpc = { 4949 messageId: 0 4950 }; 4951 4952 /** 4953 * Should be called to valid json create payload object 4954 * 4955 * @method toPayload 4956 * @param {Function} method of jsonrpc call, required 4957 * @param {Array} params, an array of method params, optional 4958 * @returns {Object} valid jsonrpc payload object 4959 */ 4960 Jsonrpc.toPayload = function(method, params) { 4961 if (!method) 4962 console.error('jsonrpc method should be specified!'); 4963 4964 // advance message ID 4965 Jsonrpc.messageId++; 4966 4967 return { 4968 jsonrpc: '2.0', 4969 id: Jsonrpc.messageId, 4970 method: method, 4971 params: params || [] 4972 }; 4973 }; 4974 4975 /** 4976 * Should be called to check if jsonrpc response is valid 4977 * 4978 * @method isValidResponse 4979 * @param {Object} 4980 * @returns {Boolean} true if response is valid, otherwise false 4981 */ 4982 Jsonrpc.isValidResponse = function(response) { 4983 return Array.isArray(response) ? response.every(validateSingleMessage) : validateSingleMessage(response); 4984 4985 function validateSingleMessage(message) { 4986 return !!message && 4987 !message.error && 4988 message.jsonrpc === '2.0' && 4989 typeof message.id === 'number' && 4990 message.result !== undefined; // only undefined is not valid json object 4991 } 4992 }; 4993 4994 /** 4995 * Should be called to create batch payload object 4996 * 4997 * @method toBatchPayload 4998 * @param {Array} messages, an array of objects with method (required) and params (optional) fields 4999 * @returns {Array} batch payload 5000 */ 5001 Jsonrpc.toBatchPayload = function(messages) { 5002 return messages.map(function(message) { 5003 return Jsonrpc.toPayload(message.method, message.params); 5004 }); 5005 }; 5006 5007 module.exports = Jsonrpc; 5008 5009 5010 }, {}], 5011 36: [function(require, module, exports) { 5012 /* 5013 This file is part of web3.js. 5014 5015 web3.js is free software: you can redistribute it and/or modify 5016 it under the terms of the GNU Lesser General Public License as published by 5017 the Free Software Foundation, either version 3 of the License, or 5018 (at your option) any later version. 5019 5020 web3.js is distributed in the hope that it will be useful, 5021 but WITHOUT ANY WARRANTY; without even the implied warranty of 5022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5023 GNU Lesser General Public License for more details. 5024 5025 You should have received a copy of the GNU Lesser General Public License 5026 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5027 */ 5028 /** 5029 * @file method.js 5030 * @author Marek Kotewicz <marek@ethdev.com> 5031 * @date 2015 5032 */ 5033 5034 var utils = require('../utils/utils'); 5035 var errors = require('./errors'); 5036 5037 var Method = function(options) { 5038 this.name = options.name; 5039 this.call = options.call; 5040 this.params = options.params || 0; 5041 this.inputFormatter = options.inputFormatter; 5042 this.outputFormatter = options.outputFormatter; 5043 this.requestManager = null; 5044 }; 5045 5046 Method.prototype.setRequestManager = function(rm) { 5047 this.requestManager = rm; 5048 }; 5049 5050 /** 5051 * Should be used to determine name of the jsonrpc method based on arguments 5052 * 5053 * @method getCall 5054 * @param {Array} arguments 5055 * @return {String} name of jsonrpc method 5056 */ 5057 Method.prototype.getCall = function(args) { 5058 return utils.isFunction(this.call) ? this.call(args) : this.call; 5059 }; 5060 5061 /** 5062 * Should be used to extract callback from array of arguments. Modifies input param 5063 * 5064 * @method extractCallback 5065 * @param {Array} arguments 5066 * @return {Function|Null} callback, if exists 5067 */ 5068 Method.prototype.extractCallback = function(args) { 5069 if (utils.isFunction(args[args.length - 1])) { 5070 return args.pop(); // modify the args array! 5071 } 5072 }; 5073 5074 /** 5075 * Should be called to check if the number of arguments is correct 5076 * 5077 * @method validateArgs 5078 * @param {Array} arguments 5079 * @throws {Error} if it is not 5080 */ 5081 Method.prototype.validateArgs = function(args) { 5082 if (args.length !== this.params) { 5083 throw errors.InvalidNumberOfRPCParams(); 5084 } 5085 }; 5086 5087 /** 5088 * Should be called to format input args of method 5089 * 5090 * @method formatInput 5091 * @param {Array} 5092 * @return {Array} 5093 */ 5094 Method.prototype.formatInput = function(args) { 5095 if (!this.inputFormatter) { 5096 return args; 5097 } 5098 5099 return this.inputFormatter.map(function(formatter, index) { 5100 return formatter ? formatter(args[index]) : args[index]; 5101 }); 5102 }; 5103 5104 /** 5105 * Should be called to format output(result) of method 5106 * 5107 * @method formatOutput 5108 * @param {Object} 5109 * @return {Object} 5110 */ 5111 Method.prototype.formatOutput = function(result) { 5112 return this.outputFormatter && result ? this.outputFormatter(result) : result; 5113 }; 5114 5115 /** 5116 * Should create payload from given input args 5117 * 5118 * @method toPayload 5119 * @param {Array} args 5120 * @return {Object} 5121 */ 5122 Method.prototype.toPayload = function(args) { 5123 var call = this.getCall(args); 5124 var callback = this.extractCallback(args); 5125 var params = this.formatInput(args); 5126 this.validateArgs(params); 5127 5128 return { 5129 method: call, 5130 params: params, 5131 callback: callback 5132 }; 5133 }; 5134 5135 Method.prototype.attachToObject = function(obj) { 5136 var func = this.buildCall(); 5137 func.call = this.call; // TODO!!! that's ugly. filter.js uses it 5138 var name = this.name.split('.'); 5139 if (name.length > 1) { 5140 obj[name[0]] = obj[name[0]] || {}; 5141 obj[name[0]][name[1]] = func; 5142 } else { 5143 obj[name[0]] = func; 5144 } 5145 }; 5146 5147 Method.prototype.buildCall = function() { 5148 var method = this; 5149 var send = function() { 5150 var payload = method.toPayload(Array.prototype.slice.call(arguments)); 5151 if (payload.callback) { 5152 return method.requestManager.sendAsync(payload, function(err, result) { 5153 payload.callback(err, method.formatOutput(result)); 5154 }); 5155 } 5156 return method.formatOutput(method.requestManager.send(payload)); 5157 }; 5158 send.request = this.request.bind(this); 5159 return send; 5160 }; 5161 5162 /** 5163 * Should be called to create pure JSONRPC request which can be used in batch request 5164 * 5165 * @method request 5166 * @param {...} params 5167 * @return {Object} jsonrpc request 5168 */ 5169 Method.prototype.request = function() { 5170 var payload = this.toPayload(Array.prototype.slice.call(arguments)); 5171 payload.format = this.formatOutput.bind(this); 5172 return payload; 5173 }; 5174 5175 module.exports = Method; 5176 5177 }, { 5178 "../utils/utils": 20, 5179 "./errors": 26 5180 }], 5181 37: [function(require, module, exports) { 5182 /* 5183 This file is part of web3.js. 5184 5185 web3.js is free software: you can redistribute it and/or modify 5186 it under the terms of the GNU Lesser General Public License as published by 5187 the Free Software Foundation, either version 3 of the License, or 5188 (at your option) any later version. 5189 5190 web3.js is distributed in the hope that it will be useful, 5191 but WITHOUT ANY WARRANTY; without even the implied warranty of 5192 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5193 GNU Lesser General Public License for more details. 5194 5195 You should have received a copy of the GNU Lesser General Public License 5196 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5197 */ 5198 /** @file db.js 5199 * @authors: 5200 * Marek Kotewicz <marek@ethdev.com> 5201 * @date 2015 5202 */ 5203 5204 var Method = require('../method'); 5205 5206 var DB = function(web3) { 5207 this._requestManager = web3._requestManager; 5208 5209 var self = this; 5210 5211 methods().forEach(function(method) { 5212 method.attachToObject(self); 5213 method.setRequestManager(web3._requestManager); 5214 }); 5215 }; 5216 5217 var methods = function() { 5218 var putString = new Method({ 5219 name: 'putString', 5220 call: 'db_putString', 5221 params: 3 5222 }); 5223 5224 var getString = new Method({ 5225 name: 'getString', 5226 call: 'db_getString', 5227 params: 2 5228 }); 5229 5230 var putHex = new Method({ 5231 name: 'putHex', 5232 call: 'db_putHex', 5233 params: 3 5234 }); 5235 5236 var getHex = new Method({ 5237 name: 'getHex', 5238 call: 'db_getHex', 5239 params: 2 5240 }); 5241 5242 return [ 5243 putString, getString, putHex, getHex 5244 ]; 5245 }; 5246 5247 module.exports = DB; 5248 5249 }, { 5250 "../method": 36 5251 }], 5252 38: [function(require, module, exports) { 5253 /* 5254 This file is part of web3.js. 5255 5256 web3.js is free software: you can redistribute it and/or modify 5257 it under the terms of the GNU Lesser General Public License as published by 5258 the Free Software Foundation, either version 3 of the License, or 5259 (at your option) any later version. 5260 5261 web3.js is distributed in the hope that it will be useful, 5262 but WITHOUT ANY WARRANTY; without even the implied warranty of 5263 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5264 GNU Lesser General Public License for more details. 5265 5266 You should have received a copy of the GNU Lesser General Public License 5267 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5268 */ 5269 /** 5270 * @file eth.js 5271 * @author Marek Kotewicz <marek@ethdev.com> 5272 * @author Fabian Vogelsteller <fabian@ethdev.com> 5273 * @date 2015 5274 */ 5275 5276 "use strict"; 5277 5278 var formatters = require('../formatters'); 5279 var utils = require('../../utils/utils'); 5280 var Method = require('../method'); 5281 var Property = require('../property'); 5282 var c = require('../../utils/config'); 5283 var Contract = require('../contract'); 5284 var watches = require('./watches'); 5285 var Filter = require('../filter'); 5286 var IsSyncing = require('../syncing'); 5287 var namereg = require('../namereg'); 5288 var Iban = require('../iban'); 5289 var transfer = require('../transfer'); 5290 5291 var blockCall = function(args) { 5292 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber"; 5293 }; 5294 5295 var transactionFromBlockCall = function(args) { 5296 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex'; 5297 }; 5298 5299 var uncleCall = function(args) { 5300 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex'; 5301 }; 5302 5303 var getBlockTransactionCountCall = function(args) { 5304 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber'; 5305 }; 5306 5307 var uncleCountCall = function(args) { 5308 return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber'; 5309 }; 5310 5311 function Eth(web3) { 5312 this._requestManager = web3._requestManager; 5313 5314 var self = this; 5315 5316 methods().forEach(function(method) { 5317 method.attachToObject(self); 5318 method.setRequestManager(self._requestManager); 5319 }); 5320 5321 properties().forEach(function(p) { 5322 p.attachToObject(self); 5323 p.setRequestManager(self._requestManager); 5324 }); 5325 5326 5327 this.iban = Iban; 5328 this.sendIBANTransaction = transfer.bind(null, this); 5329 } 5330 5331 Object.defineProperty(Eth.prototype, 'defaultBlock', { 5332 get: function() { 5333 return c.defaultBlock; 5334 }, 5335 set: function(val) { 5336 c.defaultBlock = val; 5337 return val; 5338 } 5339 }); 5340 5341 Object.defineProperty(Eth.prototype, 'defaultAccount', { 5342 get: function() { 5343 return c.defaultAccount; 5344 }, 5345 set: function(val) { 5346 c.defaultAccount = val; 5347 return val; 5348 } 5349 }); 5350 5351 var methods = function() { 5352 var getBalance = new Method({ 5353 name: 'getBalance', 5354 call: 'eth_getBalance', 5355 params: 2, 5356 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter], 5357 outputFormatter: formatters.outputBigNumberFormatter 5358 }); 5359 5360 var getStorageAt = new Method({ 5361 name: 'getStorageAt', 5362 call: 'eth_getStorageAt', 5363 params: 3, 5364 inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter] 5365 }); 5366 5367 var getCode = new Method({ 5368 name: 'getCode', 5369 call: 'eth_getCode', 5370 params: 2, 5371 inputFormatter: [formatters.inputAddressFormatter, formatters.inputDefaultBlockNumberFormatter] 5372 }); 5373 5374 var getBlock = new Method({ 5375 name: 'getBlock', 5376 call: blockCall, 5377 params: 2, 5378 inputFormatter: [formatters.inputBlockNumberFormatter, function(val) { 5379 return !!val; 5380 }], 5381 outputFormatter: formatters.outputBlockFormatter 5382 }); 5383 5384 var getUncle = new Method({ 5385 name: 'getUncle', 5386 call: uncleCall, 5387 params: 2, 5388 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5389 outputFormatter: formatters.outputBlockFormatter, 5390 5391 }); 5392 5393 var getCompilers = new Method({ 5394 name: 'getCompilers', 5395 call: 'eth_getCompilers', 5396 params: 0 5397 }); 5398 5399 var getBlockTransactionCount = new Method({ 5400 name: 'getBlockTransactionCount', 5401 call: getBlockTransactionCountCall, 5402 params: 1, 5403 inputFormatter: [formatters.inputBlockNumberFormatter], 5404 outputFormatter: utils.toDecimal 5405 }); 5406 5407 var getBlockUncleCount = new Method({ 5408 name: 'getBlockUncleCount', 5409 call: uncleCountCall, 5410 params: 1, 5411 inputFormatter: [formatters.inputBlockNumberFormatter], 5412 outputFormatter: utils.toDecimal 5413 }); 5414 5415 var getTransaction = new Method({ 5416 name: 'getTransaction', 5417 call: 'eth_getTransactionByHash', 5418 params: 1, 5419 outputFormatter: formatters.outputTransactionFormatter 5420 }); 5421 5422 var getTransactionFromBlock = new Method({ 5423 name: 'getTransactionFromBlock', 5424 call: transactionFromBlockCall, 5425 params: 2, 5426 inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex], 5427 outputFormatter: formatters.outputTransactionFormatter 5428 }); 5429 5430 var getTransactionReceipt = new Method({ 5431 name: 'getTransactionReceipt', 5432 call: 'eth_getTransactionReceipt', 5433 params: 1, 5434 outputFormatter: formatters.outputTransactionReceiptFormatter 5435 }); 5436 5437 var getTransactionCount = new Method({ 5438 name: 'getTransactionCount', 5439 call: 'eth_getTransactionCount', 5440 params: 2, 5441 inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter], 5442 outputFormatter: utils.toDecimal 5443 }); 5444 5445 var sendRawTransaction = new Method({ 5446 name: 'sendRawTransaction', 5447 call: 'eth_sendRawTransaction', 5448 params: 1, 5449 inputFormatter: [null] 5450 }); 5451 5452 var sendTransaction = new Method({ 5453 name: 'sendTransaction', 5454 call: 'eth_sendTransaction', 5455 params: 1, 5456 inputFormatter: [formatters.inputTransactionFormatter] 5457 }); 5458 5459 var signTransaction = new Method({ 5460 name: 'signTransaction', 5461 call: 'eth_signTransaction', 5462 params: 1, 5463 inputFormatter: [formatters.inputTransactionFormatter] 5464 }); 5465 5466 var sign = new Method({ 5467 name: 'sign', 5468 call: 'eth_sign', 5469 params: 2, 5470 inputFormatter: [formatters.inputAddressFormatter, null] 5471 }); 5472 5473 var call = new Method({ 5474 name: 'call', 5475 call: 'eth_call', 5476 params: 2, 5477 inputFormatter: [formatters.inputCallFormatter, formatters.inputDefaultBlockNumberFormatter] 5478 }); 5479 5480 var estimateGas = new Method({ 5481 name: 'estimateGas', 5482 call: 'eth_estimateGas', 5483 params: 1, 5484 inputFormatter: [formatters.inputCallFormatter], 5485 outputFormatter: utils.toDecimal 5486 }); 5487 5488 var compileSolidity = new Method({ 5489 name: 'compile.solidity', 5490 call: 'eth_compileSolidity', 5491 params: 1 5492 }); 5493 5494 var compileLLL = new Method({ 5495 name: 'compile.lll', 5496 call: 'eth_compileLLL', 5497 params: 1 5498 }); 5499 5500 var compileSerpent = new Method({ 5501 name: 'compile.serpent', 5502 call: 'eth_compileSerpent', 5503 params: 1 5504 }); 5505 5506 var submitWork = new Method({ 5507 name: 'submitWork', 5508 call: 'eth_submitWork', 5509 params: 3 5510 }); 5511 5512 var getWork = new Method({ 5513 name: 'getWork', 5514 call: 'eth_getWork', 5515 params: 0 5516 }); 5517 5518 return [ 5519 getBalance, 5520 getStorageAt, 5521 getCode, 5522 getBlock, 5523 getUncle, 5524 getCompilers, 5525 getBlockTransactionCount, 5526 getBlockUncleCount, 5527 getTransaction, 5528 getTransactionFromBlock, 5529 getTransactionReceipt, 5530 getTransactionCount, 5531 call, 5532 estimateGas, 5533 sendRawTransaction, 5534 signTransaction, 5535 sendTransaction, 5536 sign, 5537 compileSolidity, 5538 compileLLL, 5539 compileSerpent, 5540 submitWork, 5541 getWork 5542 ]; 5543 }; 5544 5545 5546 var properties = function() { 5547 return [ 5548 new Property({ 5549 name: 'coinbase', 5550 getter: 'eth_coinbase' 5551 }), 5552 new Property({ 5553 name: 'mining', 5554 getter: 'eth_mining' 5555 }), 5556 new Property({ 5557 name: 'hashrate', 5558 getter: 'eth_hashrate', 5559 outputFormatter: utils.toDecimal 5560 }), 5561 new Property({ 5562 name: 'syncing', 5563 getter: 'eth_syncing', 5564 outputFormatter: formatters.outputSyncingFormatter 5565 }), 5566 new Property({ 5567 name: 'gasPrice', 5568 getter: 'eth_gasPrice', 5569 outputFormatter: formatters.outputBigNumberFormatter 5570 }), 5571 new Property({ 5572 name: 'accounts', 5573 getter: 'eth_accounts' 5574 }), 5575 new Property({ 5576 name: 'blockNumber', 5577 getter: 'eth_blockNumber', 5578 outputFormatter: utils.toDecimal 5579 }), 5580 new Property({ 5581 name: 'protocolVersion', 5582 getter: 'eth_protocolVersion' 5583 }) 5584 ]; 5585 }; 5586 5587 Eth.prototype.contract = function(abi) { 5588 var factory = new Contract(this, abi); 5589 return factory; 5590 }; 5591 5592 Eth.prototype.filter = function(options, callback, filterCreationErrorCallback) { 5593 return new Filter(options, 'eth', this._requestManager, watches.eth(), formatters.outputLogFormatter, callback, filterCreationErrorCallback); 5594 }; 5595 5596 Eth.prototype.namereg = function() { 5597 return this.contract(namereg.global.abi).at(namereg.global.address); 5598 }; 5599 5600 Eth.prototype.icapNamereg = function() { 5601 return this.contract(namereg.icap.abi).at(namereg.icap.address); 5602 }; 5603 5604 Eth.prototype.isSyncing = function(callback) { 5605 return new IsSyncing(this._requestManager, callback); 5606 }; 5607 5608 module.exports = Eth; 5609 5610 }, { 5611 "../../utils/config": 18, 5612 "../../utils/utils": 20, 5613 "../contract": 25, 5614 "../filter": 29, 5615 "../formatters": 30, 5616 "../iban": 33, 5617 "../method": 36, 5618 "../namereg": 44, 5619 "../property": 45, 5620 "../syncing": 48, 5621 "../transfer": 49, 5622 "./watches": 43 5623 }], 5624 39: [function(require, module, exports) { 5625 /* 5626 This file is part of web3.js. 5627 5628 web3.js is free software: you can redistribute it and/or modify 5629 it under the terms of the GNU Lesser General Public License as published by 5630 the Free Software Foundation, either version 3 of the License, or 5631 (at your option) any later version. 5632 5633 web3.js is distributed in the hope that it will be useful, 5634 but WITHOUT ANY WARRANTY; without even the implied warranty of 5635 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5636 GNU Lesser General Public License for more details. 5637 5638 You should have received a copy of the GNU Lesser General Public License 5639 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5640 */ 5641 /** @file eth.js 5642 * @authors: 5643 * Marek Kotewicz <marek@ethdev.com> 5644 * @date 2015 5645 */ 5646 5647 var utils = require('../../utils/utils'); 5648 var Property = require('../property'); 5649 5650 var Net = function(web3) { 5651 this._requestManager = web3._requestManager; 5652 5653 var self = this; 5654 5655 properties().forEach(function(p) { 5656 p.attachToObject(self); 5657 p.setRequestManager(web3._requestManager); 5658 }); 5659 }; 5660 5661 /// @returns an array of objects describing web3.eth api properties 5662 var properties = function() { 5663 return [ 5664 new Property({ 5665 name: 'listening', 5666 getter: 'net_listening' 5667 }), 5668 new Property({ 5669 name: 'peerCount', 5670 getter: 'net_peerCount', 5671 outputFormatter: utils.toDecimal 5672 }) 5673 ]; 5674 }; 5675 5676 module.exports = Net; 5677 5678 }, { 5679 "../../utils/utils": 20, 5680 "../property": 45 5681 }], 5682 40: [function(require, module, exports) { 5683 /* 5684 This file is part of web3.js. 5685 5686 web3.js is free software: you can redistribute it and/or modify 5687 it under the terms of the GNU Lesser General Public License as published by 5688 the Free Software Foundation, either version 3 of the License, or 5689 (at your option) any later version. 5690 5691 web3.js is distributed in the hope that it will be useful, 5692 but WITHOUT ANY WARRANTY; without even the implied warranty of 5693 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5694 GNU Lesser General Public License for more details. 5695 5696 You should have received a copy of the GNU Lesser General Public License 5697 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5698 */ 5699 /** 5700 * @file eth.js 5701 * @author Marek Kotewicz <marek@ethdev.com> 5702 * @author Fabian Vogelsteller <fabian@ethdev.com> 5703 * @date 2015 5704 */ 5705 5706 "use strict"; 5707 5708 var Method = require('../method'); 5709 var Property = require('../property'); 5710 var formatters = require('../formatters'); 5711 5712 function Personal(web3) { 5713 this._requestManager = web3._requestManager; 5714 5715 var self = this; 5716 5717 methods().forEach(function(method) { 5718 method.attachToObject(self); 5719 method.setRequestManager(self._requestManager); 5720 }); 5721 5722 properties().forEach(function(p) { 5723 p.attachToObject(self); 5724 p.setRequestManager(self._requestManager); 5725 }); 5726 } 5727 5728 var methods = function() { 5729 var newAccount = new Method({ 5730 name: 'newAccount', 5731 call: 'personal_newAccount', 5732 params: 1, 5733 inputFormatter: [null] 5734 }); 5735 5736 var newAccountByCA = new Method({ 5737 name: 'newAccountByCA', 5738 call: 'personal_newAccountByCA', 5739 params: 2, 5740 inputFormatter: [null,null] 5741 }); 5742 5743 var importRawKey = new Method({ 5744 name: 'importRawKey', 5745 call: 'personal_importRawKey', 5746 params: 2 5747 }); 5748 5749 var sign = new Method({ 5750 name: 'sign', 5751 call: 'personal_sign', 5752 params: 3, 5753 inputFormatter: [null, formatters.inputAddressFormatter, null] 5754 }); 5755 5756 var ecRecover = new Method({ 5757 name: 'ecRecover', 5758 call: 'personal_ecRecover', 5759 params: 2 5760 }); 5761 5762 var unlockAccount = new Method({ 5763 name: 'unlockAccount', 5764 call: 'personal_unlockAccount', 5765 params: 3, 5766 inputFormatter: [formatters.inputAddressFormatter, null, null] 5767 }); 5768 5769 var sendTransaction = new Method({ 5770 name: 'sendTransaction', 5771 call: 'personal_sendTransaction', 5772 params: 2, 5773 inputFormatter: [formatters.inputTransactionFormatter, null] 5774 }); 5775 5776 var lockAccount = new Method({ 5777 name: 'lockAccount', 5778 call: 'personal_lockAccount', 5779 params: 1, 5780 inputFormatter: [formatters.inputAddressFormatter] 5781 }); 5782 5783 return [ 5784 newAccount, 5785 newAccountByCA, 5786 importRawKey, 5787 unlockAccount, 5788 ecRecover, 5789 sign, 5790 sendTransaction, 5791 lockAccount 5792 ]; 5793 }; 5794 5795 var properties = function() { 5796 return [ 5797 new Property({ 5798 name: 'listAccounts', 5799 getter: 'personal_listAccounts' 5800 }) 5801 ]; 5802 }; 5803 5804 5805 module.exports = Personal; 5806 5807 }, { 5808 "../formatters": 30, 5809 "../method": 36, 5810 "../property": 45 5811 }], 5812 41: [function(require, module, exports) { 5813 /* 5814 This file is part of web3.js. 5815 5816 web3.js is free software: you can redistribute it and/or modify 5817 it under the terms of the GNU Lesser General Public License as published by 5818 the Free Software Foundation, either version 3 of the License, or 5819 (at your option) any later version. 5820 5821 web3.js is distributed in the hope that it will be useful, 5822 but WITHOUT ANY WARRANTY; without even the implied warranty of 5823 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5824 GNU Lesser General Public License for more details. 5825 5826 You should have received a copy of the GNU Lesser General Public License 5827 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5828 */ 5829 /** @file shh.js 5830 * @authors: 5831 * Fabian Vogelsteller <fabian@ethereum.org> 5832 * Marek Kotewicz <marek@ethcore.io> 5833 * @date 2017 5834 */ 5835 5836 var Method = require('../method'); 5837 var Filter = require('../filter'); 5838 var watches = require('./watches'); 5839 5840 var Shh = function(web3) { 5841 this._requestManager = web3._requestManager; 5842 5843 var self = this; 5844 5845 methods().forEach(function(method) { 5846 method.attachToObject(self); 5847 method.setRequestManager(self._requestManager); 5848 }); 5849 }; 5850 5851 Shh.prototype.newMessageFilter = function(options, callback, filterCreationErrorCallback) { 5852 return new Filter(options, 'shh', this._requestManager, watches.shh(), null, callback, filterCreationErrorCallback); 5853 }; 5854 5855 var methods = function() { 5856 5857 return [ 5858 new Method({ 5859 name: 'version', 5860 call: 'shh_version', 5861 params: 0 5862 }), 5863 new Method({ 5864 name: 'info', 5865 call: 'shh_info', 5866 params: 0 5867 }), 5868 new Method({ 5869 name: 'setMaxMessageSize', 5870 call: 'shh_setMaxMessageSize', 5871 params: 1 5872 }), 5873 new Method({ 5874 name: 'setMinPoW', 5875 call: 'shh_setMinPoW', 5876 params: 1 5877 }), 5878 new Method({ 5879 name: 'markTrustedPeer', 5880 call: 'shh_markTrustedPeer', 5881 params: 1 5882 }), 5883 new Method({ 5884 name: 'newKeyPair', 5885 call: 'shh_newKeyPair', 5886 params: 0 5887 }), 5888 new Method({ 5889 name: 'addPrivateKey', 5890 call: 'shh_addPrivateKey', 5891 params: 1 5892 }), 5893 new Method({ 5894 name: 'deleteKeyPair', 5895 call: 'shh_deleteKeyPair', 5896 params: 1 5897 }), 5898 new Method({ 5899 name: 'hasKeyPair', 5900 call: 'shh_hasKeyPair', 5901 params: 1 5902 }), 5903 new Method({ 5904 name: 'getPublicKey', 5905 call: 'shh_getPublicKey', 5906 params: 1 5907 }), 5908 new Method({ 5909 name: 'getPrivateKey', 5910 call: 'shh_getPrivateKey', 5911 params: 1 5912 }), 5913 new Method({ 5914 name: 'newSymKey', 5915 call: 'shh_newSymKey', 5916 params: 0 5917 }), 5918 new Method({ 5919 name: 'addSymKey', 5920 call: 'shh_addSymKey', 5921 params: 1 5922 }), 5923 new Method({ 5924 name: 'generateSymKeyFromPassword', 5925 call: 'shh_generateSymKeyFromPassword', 5926 params: 1 5927 }), 5928 new Method({ 5929 name: 'hasSymKey', 5930 call: 'shh_hasSymKey', 5931 params: 1 5932 }), 5933 new Method({ 5934 name: 'getSymKey', 5935 call: 'shh_getSymKey', 5936 params: 1 5937 }), 5938 new Method({ 5939 name: 'deleteSymKey', 5940 call: 'shh_deleteSymKey', 5941 params: 1 5942 }), 5943 5944 // subscribe and unsubscribe missing 5945 5946 new Method({ 5947 name: 'post', 5948 call: 'shh_post', 5949 params: 1, 5950 inputFormatter: [null] 5951 }) 5952 ]; 5953 }; 5954 5955 module.exports = Shh; 5956 5957 5958 }, { 5959 "../filter": 29, 5960 "../method": 36, 5961 "./watches": 43 5962 }], 5963 42: [function(require, module, exports) { 5964 /* 5965 This file is part of web3.js. 5966 5967 web3.js is free software: you can redistribute it and/or modify 5968 it under the terms of the GNU Lesser General Public License as published by 5969 the Free Software Foundation, either version 3 of the License, or 5970 (at your option) any later version. 5971 5972 web3.js is distributed in the hope that it will be useful, 5973 but WITHOUT ANY WARRANTY; without even the implied warranty of 5974 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 5975 GNU Lesser General Public License for more details. 5976 5977 You should have received a copy of the GNU Lesser General Public License 5978 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 5979 */ 5980 /** 5981 * @file bzz.js 5982 * @author Alex Beregszaszi <alex@rtfs.hu> 5983 * @date 2016 5984 * 5985 * Reference: https://github.com/simplechain-org/go-simplechain/blob/swarm/internal/web3ext/web3ext.go#L33 5986 */ 5987 5988 "use strict"; 5989 5990 var Method = require('../method'); 5991 var Property = require('../property'); 5992 5993 function Swarm(web3) { 5994 this._requestManager = web3._requestManager; 5995 5996 var self = this; 5997 5998 methods().forEach(function(method) { 5999 method.attachToObject(self); 6000 method.setRequestManager(self._requestManager); 6001 }); 6002 6003 properties().forEach(function(p) { 6004 p.attachToObject(self); 6005 p.setRequestManager(self._requestManager); 6006 }); 6007 } 6008 6009 var methods = function() { 6010 var blockNetworkRead = new Method({ 6011 name: 'blockNetworkRead', 6012 call: 'bzz_blockNetworkRead', 6013 params: 1, 6014 inputFormatter: [null] 6015 }); 6016 6017 var syncEnabled = new Method({ 6018 name: 'syncEnabled', 6019 call: 'bzz_syncEnabled', 6020 params: 1, 6021 inputFormatter: [null] 6022 }); 6023 6024 var swapEnabled = new Method({ 6025 name: 'swapEnabled', 6026 call: 'bzz_swapEnabled', 6027 params: 1, 6028 inputFormatter: [null] 6029 }); 6030 6031 var download = new Method({ 6032 name: 'download', 6033 call: 'bzz_download', 6034 params: 2, 6035 inputFormatter: [null, null] 6036 }); 6037 6038 var upload = new Method({ 6039 name: 'upload', 6040 call: 'bzz_upload', 6041 params: 2, 6042 inputFormatter: [null, null] 6043 }); 6044 6045 var retrieve = new Method({ 6046 name: 'retrieve', 6047 call: 'bzz_retrieve', 6048 params: 1, 6049 inputFormatter: [null] 6050 }); 6051 6052 var store = new Method({ 6053 name: 'store', 6054 call: 'bzz_store', 6055 params: 2, 6056 inputFormatter: [null, null] 6057 }); 6058 6059 var get = new Method({ 6060 name: 'get', 6061 call: 'bzz_get', 6062 params: 1, 6063 inputFormatter: [null] 6064 }); 6065 6066 var put = new Method({ 6067 name: 'put', 6068 call: 'bzz_put', 6069 params: 2, 6070 inputFormatter: [null, null] 6071 }); 6072 6073 var modify = new Method({ 6074 name: 'modify', 6075 call: 'bzz_modify', 6076 params: 4, 6077 inputFormatter: [null, null, null, null] 6078 }); 6079 6080 return [ 6081 blockNetworkRead, 6082 syncEnabled, 6083 swapEnabled, 6084 download, 6085 upload, 6086 retrieve, 6087 store, 6088 get, 6089 put, 6090 modify 6091 ]; 6092 }; 6093 6094 var properties = function() { 6095 return [ 6096 new Property({ 6097 name: 'hive', 6098 getter: 'bzz_hive' 6099 }), 6100 new Property({ 6101 name: 'info', 6102 getter: 'bzz_info' 6103 }) 6104 ]; 6105 }; 6106 6107 6108 module.exports = Swarm; 6109 6110 }, { 6111 "../method": 36, 6112 "../property": 45 6113 }], 6114 43: [function(require, module, exports) { 6115 /* 6116 This file is part of web3.js. 6117 6118 web3.js is free software: you can redistribute it and/or modify 6119 it under the terms of the GNU Lesser General Public License as published by 6120 the Free Software Foundation, either version 3 of the License, or 6121 (at your option) any later version. 6122 6123 web3.js is distributed in the hope that it will be useful, 6124 but WITHOUT ANY WARRANTY; without even the implied warranty of 6125 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6126 GNU Lesser General Public License for more details. 6127 6128 You should have received a copy of the GNU Lesser General Public License 6129 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6130 */ 6131 /** @file watches.js 6132 * @authors: 6133 * Marek Kotewicz <marek@ethdev.com> 6134 * @date 2015 6135 */ 6136 6137 var Method = require('../method'); 6138 6139 /// @returns an array of objects describing web3.eth.filter api methods 6140 var eth = function() { 6141 var newFilterCall = function(args) { 6142 var type = args[0]; 6143 6144 switch (type) { 6145 case 'latest': 6146 args.shift(); 6147 this.params = 0; 6148 return 'eth_newBlockFilter'; 6149 case 'pending': 6150 args.shift(); 6151 this.params = 0; 6152 return 'eth_newPendingTransactionFilter'; 6153 default: 6154 return 'eth_newFilter'; 6155 } 6156 }; 6157 6158 var newFilter = new Method({ 6159 name: 'newFilter', 6160 call: newFilterCall, 6161 params: 1 6162 }); 6163 6164 var uninstallFilter = new Method({ 6165 name: 'uninstallFilter', 6166 call: 'eth_uninstallFilter', 6167 params: 1 6168 }); 6169 6170 var getLogs = new Method({ 6171 name: 'getLogs', 6172 call: 'eth_getFilterLogs', 6173 params: 1 6174 }); 6175 6176 var poll = new Method({ 6177 name: 'poll', 6178 call: 'eth_getFilterChanges', 6179 params: 1 6180 }); 6181 6182 return [ 6183 newFilter, 6184 uninstallFilter, 6185 getLogs, 6186 poll 6187 ]; 6188 }; 6189 6190 /// @returns an array of objects describing web3.shh.watch api methods 6191 var shh = function() { 6192 6193 return [ 6194 new Method({ 6195 name: 'newFilter', 6196 call: 'shh_newMessageFilter', 6197 params: 1 6198 }), 6199 new Method({ 6200 name: 'uninstallFilter', 6201 call: 'shh_deleteMessageFilter', 6202 params: 1 6203 }), 6204 new Method({ 6205 name: 'getLogs', 6206 call: 'shh_getFilterMessages', 6207 params: 1 6208 }), 6209 new Method({ 6210 name: 'poll', 6211 call: 'shh_getFilterMessages', 6212 params: 1 6213 }) 6214 ]; 6215 }; 6216 6217 module.exports = { 6218 eth: eth, 6219 shh: shh 6220 }; 6221 6222 6223 }, { 6224 "../method": 36 6225 }], 6226 44: [function(require, module, exports) { 6227 /* 6228 This file is part of web3.js. 6229 6230 web3.js is free software: you can redistribute it and/or modify 6231 it under the terms of the GNU Lesser General Public License as published by 6232 the Free Software Foundation, either version 3 of the License, or 6233 (at your option) any later version. 6234 6235 web3.js is distributed in the hope that it will be useful, 6236 but WITHOUT ANY WARRANTY; without even the implied warranty of 6237 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6238 GNU Lesser General Public License for more details. 6239 6240 You should have received a copy of the GNU Lesser General Public License 6241 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6242 */ 6243 /** 6244 * @file namereg.js 6245 * @author Marek Kotewicz <marek@ethdev.com> 6246 * @date 2015 6247 */ 6248 6249 var globalRegistrarAbi = require('../contracts/GlobalRegistrar.json'); 6250 var icapRegistrarAbi = require('../contracts/ICAPRegistrar.json'); 6251 6252 var globalNameregAddress = '0xc6d9d2cd449a754c494264e1809c50e34d64562b'; 6253 var icapNameregAddress = '0xa1a111bc074c9cfa781f0c38e63bd51c91b8af00'; 6254 6255 module.exports = { 6256 global: { 6257 abi: globalRegistrarAbi, 6258 address: globalNameregAddress 6259 }, 6260 icap: { 6261 abi: icapRegistrarAbi, 6262 address: icapNameregAddress 6263 } 6264 }; 6265 6266 6267 }, { 6268 "../contracts/GlobalRegistrar.json": 1, 6269 "../contracts/ICAPRegistrar.json": 2 6270 }], 6271 45: [function(require, module, exports) { 6272 /* 6273 This file is part of web3.js. 6274 6275 web3.js is free software: you can redistribute it and/or modify 6276 it under the terms of the GNU Lesser General Public License as published by 6277 the Free Software Foundation, either version 3 of the License, or 6278 (at your option) any later version. 6279 6280 web3.js is distributed in the hope that it will be useful, 6281 but WITHOUT ANY WARRANTY; without even the implied warranty of 6282 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6283 GNU Lesser General Public License for more details. 6284 6285 You should have received a copy of the GNU Lesser General Public License 6286 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6287 */ 6288 /** 6289 * @file property.js 6290 * @author Fabian Vogelsteller <fabian@frozeman.de> 6291 * @author Marek Kotewicz <marek@ethdev.com> 6292 * @date 2015 6293 */ 6294 6295 var utils = require('../utils/utils'); 6296 6297 var Property = function(options) { 6298 this.name = options.name; 6299 this.getter = options.getter; 6300 this.setter = options.setter; 6301 this.outputFormatter = options.outputFormatter; 6302 this.inputFormatter = options.inputFormatter; 6303 this.requestManager = null; 6304 }; 6305 6306 Property.prototype.setRequestManager = function(rm) { 6307 this.requestManager = rm; 6308 }; 6309 6310 /** 6311 * Should be called to format input args of method 6312 * 6313 * @method formatInput 6314 * @param {Array} 6315 * @return {Array} 6316 */ 6317 Property.prototype.formatInput = function(arg) { 6318 return this.inputFormatter ? this.inputFormatter(arg) : arg; 6319 }; 6320 6321 /** 6322 * Should be called to format output(result) of method 6323 * 6324 * @method formatOutput 6325 * @param {Object} 6326 * @return {Object} 6327 */ 6328 Property.prototype.formatOutput = function(result) { 6329 return this.outputFormatter && result !== null && result !== undefined ? this.outputFormatter(result) : result; 6330 }; 6331 6332 /** 6333 * Should be used to extract callback from array of arguments. Modifies input param 6334 * 6335 * @method extractCallback 6336 * @param {Array} arguments 6337 * @return {Function|Null} callback, if exists 6338 */ 6339 Property.prototype.extractCallback = function(args) { 6340 if (utils.isFunction(args[args.length - 1])) { 6341 return args.pop(); // modify the args array! 6342 } 6343 }; 6344 6345 6346 /** 6347 * Should attach function to method 6348 * 6349 * @method attachToObject 6350 * @param {Object} 6351 * @param {Function} 6352 */ 6353 Property.prototype.attachToObject = function(obj) { 6354 var proto = { 6355 get: this.buildGet(), 6356 enumerable: true 6357 }; 6358 6359 var names = this.name.split('.'); 6360 var name = names[0]; 6361 if (names.length > 1) { 6362 obj[names[0]] = obj[names[0]] || {}; 6363 obj = obj[names[0]]; 6364 name = names[1]; 6365 } 6366 6367 Object.defineProperty(obj, name, proto); 6368 obj[asyncGetterName(name)] = this.buildAsyncGet(); 6369 }; 6370 6371 var asyncGetterName = function(name) { 6372 return 'get' + name.charAt(0).toUpperCase() + name.slice(1); 6373 }; 6374 6375 Property.prototype.buildGet = function() { 6376 var property = this; 6377 return function get() { 6378 return property.formatOutput(property.requestManager.send({ 6379 method: property.getter 6380 })); 6381 }; 6382 }; 6383 6384 Property.prototype.buildAsyncGet = function() { 6385 var property = this; 6386 var get = function(callback) { 6387 property.requestManager.sendAsync({ 6388 method: property.getter 6389 }, function(err, result) { 6390 callback(err, property.formatOutput(result)); 6391 }); 6392 }; 6393 get.request = this.request.bind(this); 6394 return get; 6395 }; 6396 6397 /** 6398 * Should be called to create pure JSONRPC request which can be used in batch request 6399 * 6400 * @method request 6401 * @param {...} params 6402 * @return {Object} jsonrpc request 6403 */ 6404 Property.prototype.request = function() { 6405 var payload = { 6406 method: this.getter, 6407 params: [], 6408 callback: this.extractCallback(Array.prototype.slice.call(arguments)) 6409 }; 6410 payload.format = this.formatOutput.bind(this); 6411 return payload; 6412 }; 6413 6414 module.exports = Property; 6415 6416 6417 }, { 6418 "../utils/utils": 20 6419 }], 6420 46: [function(require, module, exports) { 6421 /* 6422 This file is part of web3.js. 6423 6424 web3.js is free software: you can redistribute it and/or modify 6425 it under the terms of the GNU Lesser General Public License as published by 6426 the Free Software Foundation, either version 3 of the License, or 6427 (at your option) any later version. 6428 6429 web3.js is distributed in the hope that it will be useful, 6430 but WITHOUT ANY WARRANTY; without even the implied warranty of 6431 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6432 GNU Lesser General Public License for more details. 6433 6434 You should have received a copy of the GNU Lesser General Public License 6435 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6436 */ 6437 /** 6438 * @file requestmanager.js 6439 * @author Jeffrey Wilcke <jeff@ethdev.com> 6440 * @author Marek Kotewicz <marek@ethdev.com> 6441 * @author Marian Oancea <marian@ethdev.com> 6442 * @author Fabian Vogelsteller <fabian@ethdev.com> 6443 * @author Gav Wood <g@ethdev.com> 6444 * @date 2014 6445 */ 6446 6447 var Jsonrpc = require('./jsonrpc'); 6448 var utils = require('../utils/utils'); 6449 var c = require('../utils/config'); 6450 var errors = require('./errors'); 6451 6452 /** 6453 * It's responsible for passing messages to providers 6454 * It's also responsible for polling the ethereum node for incoming messages 6455 * Default poll timeout is 1 second 6456 * Singleton 6457 */ 6458 var RequestManager = function(provider) { 6459 this.provider = provider; 6460 this.polls = {}; 6461 this.timeout = null; 6462 }; 6463 6464 /** 6465 * Should be used to synchronously send request 6466 * 6467 * @method send 6468 * @param {Object} data 6469 * @return {Object} 6470 */ 6471 RequestManager.prototype.send = function(data) { 6472 if (!this.provider) { 6473 console.error(errors.InvalidProvider()); 6474 return null; 6475 } 6476 6477 var payload = Jsonrpc.toPayload(data.method, data.params); 6478 var result = this.provider.send(payload); 6479 6480 if (!Jsonrpc.isValidResponse(result)) { 6481 throw errors.InvalidResponse(result); 6482 } 6483 6484 return result.result; 6485 }; 6486 6487 /** 6488 * Should be used to asynchronously send request 6489 * 6490 * @method sendAsync 6491 * @param {Object} data 6492 * @param {Function} callback 6493 */ 6494 RequestManager.prototype.sendAsync = function(data, callback) { 6495 if (!this.provider) { 6496 return callback(errors.InvalidProvider()); 6497 } 6498 6499 var payload = Jsonrpc.toPayload(data.method, data.params); 6500 this.provider.sendAsync(payload, function(err, result) { 6501 if (err) { 6502 return callback(err); 6503 } 6504 6505 if (!Jsonrpc.isValidResponse(result)) { 6506 return callback(errors.InvalidResponse(result)); 6507 } 6508 6509 callback(null, result.result); 6510 }); 6511 }; 6512 6513 /** 6514 * Should be called to asynchronously send batch request 6515 * 6516 * @method sendBatch 6517 * @param {Array} batch data 6518 * @param {Function} callback 6519 */ 6520 RequestManager.prototype.sendBatch = function(data, callback) { 6521 if (!this.provider) { 6522 return callback(errors.InvalidProvider()); 6523 } 6524 6525 var payload = Jsonrpc.toBatchPayload(data); 6526 6527 this.provider.sendAsync(payload, function(err, results) { 6528 if (err) { 6529 return callback(err); 6530 } 6531 6532 if (!utils.isArray(results)) { 6533 return callback(errors.InvalidResponse(results)); 6534 } 6535 6536 callback(err, results); 6537 }); 6538 }; 6539 6540 /** 6541 * Should be used to set provider of request manager 6542 * 6543 * @method setProvider 6544 * @param {Object} 6545 */ 6546 RequestManager.prototype.setProvider = function(p) { 6547 this.provider = p; 6548 }; 6549 6550 /** 6551 * Should be used to start polling 6552 * 6553 * @method startPolling 6554 * @param {Object} data 6555 * @param {Number} pollId 6556 * @param {Function} callback 6557 * @param {Function} uninstall 6558 * 6559 * @todo cleanup number of params 6560 */ 6561 RequestManager.prototype.startPolling = function(data, pollId, callback, uninstall) { 6562 this.polls[pollId] = { 6563 data: data, 6564 id: pollId, 6565 callback: callback, 6566 uninstall: uninstall 6567 }; 6568 6569 6570 // start polling 6571 if (!this.timeout) { 6572 this.poll(); 6573 } 6574 }; 6575 6576 /** 6577 * Should be used to stop polling for filter with given id 6578 * 6579 * @method stopPolling 6580 * @param {Number} pollId 6581 */ 6582 RequestManager.prototype.stopPolling = function(pollId) { 6583 delete this.polls[pollId]; 6584 6585 // stop polling 6586 if (Object.keys(this.polls).length === 0 && this.timeout) { 6587 clearTimeout(this.timeout); 6588 this.timeout = null; 6589 } 6590 }; 6591 6592 /** 6593 * Should be called to reset the polling mechanism of the request manager 6594 * 6595 * @method reset 6596 */ 6597 RequestManager.prototype.reset = function(keepIsSyncing) { 6598 /*jshint maxcomplexity:5 */ 6599 6600 for (var key in this.polls) { 6601 // remove all polls, except sync polls, 6602 // they need to be removed manually by calling syncing.stopWatching() 6603 if (!keepIsSyncing || key.indexOf('syncPoll_') === -1) { 6604 this.polls[key].uninstall(); 6605 delete this.polls[key]; 6606 } 6607 } 6608 6609 // stop polling 6610 if (Object.keys(this.polls).length === 0 && this.timeout) { 6611 clearTimeout(this.timeout); 6612 this.timeout = null; 6613 } 6614 }; 6615 6616 /** 6617 * Should be called to poll for changes on filter with given id 6618 * 6619 * @method poll 6620 */ 6621 RequestManager.prototype.poll = function() { 6622 /*jshint maxcomplexity: 6 */ 6623 this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); 6624 6625 if (Object.keys(this.polls).length === 0) { 6626 return; 6627 } 6628 6629 if (!this.provider) { 6630 console.error(errors.InvalidProvider()); 6631 return; 6632 } 6633 6634 var pollsData = []; 6635 var pollsIds = []; 6636 for (var key in this.polls) { 6637 pollsData.push(this.polls[key].data); 6638 pollsIds.push(key); 6639 } 6640 6641 if (pollsData.length === 0) { 6642 return; 6643 } 6644 6645 var payload = Jsonrpc.toBatchPayload(pollsData); 6646 6647 // map the request id to they poll id 6648 var pollsIdMap = {}; 6649 payload.forEach(function(load, index) { 6650 pollsIdMap[load.id] = pollsIds[index]; 6651 }); 6652 6653 6654 var self = this; 6655 this.provider.sendAsync(payload, function(error, results) { 6656 6657 6658 // TODO: console log? 6659 if (error) { 6660 return; 6661 } 6662 6663 if (!utils.isArray(results)) { 6664 throw errors.InvalidResponse(results); 6665 } 6666 results.map(function(result) { 6667 var id = pollsIdMap[result.id]; 6668 6669 // make sure the filter is still installed after arrival of the request 6670 if (self.polls[id]) { 6671 result.callback = self.polls[id].callback; 6672 return result; 6673 } else 6674 return false; 6675 }).filter(function(result) { 6676 return !!result; 6677 }).filter(function(result) { 6678 var valid = Jsonrpc.isValidResponse(result); 6679 if (!valid) { 6680 result.callback(errors.InvalidResponse(result)); 6681 } 6682 return valid; 6683 }).forEach(function(result) { 6684 result.callback(null, result.result); 6685 }); 6686 }); 6687 }; 6688 6689 module.exports = RequestManager; 6690 6691 6692 }, { 6693 "../utils/config": 18, 6694 "../utils/utils": 20, 6695 "./errors": 26, 6696 "./jsonrpc": 35 6697 }], 6698 47: [function(require, module, exports) { 6699 6700 6701 var Settings = function() { 6702 this.defaultBlock = 'latest'; 6703 this.defaultAccount = undefined; 6704 }; 6705 6706 module.exports = Settings; 6707 6708 6709 }, {}], 6710 48: [function(require, module, exports) { 6711 /* 6712 This file is part of web3.js. 6713 6714 web3.js is free software: you can redistribute it and/or modify 6715 it under the terms of the GNU Lesser General Public License as published by 6716 the Free Software Foundation, either version 3 of the License, or 6717 (at your option) any later version. 6718 6719 web3.js is distributed in the hope that it will be useful, 6720 but WITHOUT ANY WARRANTY; without even the implied warranty of 6721 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6722 GNU Lesser General Public License for more details. 6723 6724 You should have received a copy of the GNU Lesser General Public License 6725 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6726 */ 6727 /** @file syncing.js 6728 * @authors: 6729 * Fabian Vogelsteller <fabian@ethdev.com> 6730 * @date 2015 6731 */ 6732 6733 var formatters = require('./formatters'); 6734 var utils = require('../utils/utils'); 6735 6736 var count = 1; 6737 6738 /** 6739 Adds the callback and sets up the methods, to iterate over the results. 6740 6741 @method pollSyncing 6742 @param {Object} self 6743 */ 6744 var pollSyncing = function(self) { 6745 6746 var onMessage = function(error, sync) { 6747 if (error) { 6748 return self.callbacks.forEach(function(callback) { 6749 callback(error); 6750 }); 6751 } 6752 6753 if (utils.isObject(sync) && sync.startingBlock) 6754 sync = formatters.outputSyncingFormatter(sync); 6755 6756 self.callbacks.forEach(function(callback) { 6757 if (self.lastSyncState !== sync) { 6758 6759 // call the callback with true first so the app can stop anything, before receiving the sync data 6760 if (!self.lastSyncState && utils.isObject(sync)) 6761 callback(null, true); 6762 6763 // call on the next CPU cycle, so the actions of the sync stop can be processes first 6764 setTimeout(function() { 6765 callback(null, sync); 6766 }, 0); 6767 6768 self.lastSyncState = sync; 6769 } 6770 }); 6771 }; 6772 6773 self.requestManager.startPolling({ 6774 method: 'eth_syncing', 6775 params: [], 6776 }, self.pollId, onMessage, self.stopWatching.bind(self)); 6777 6778 }; 6779 6780 var IsSyncing = function(requestManager, callback) { 6781 this.requestManager = requestManager; 6782 this.pollId = 'syncPoll_' + count++; 6783 this.callbacks = []; 6784 this.addCallback(callback); 6785 this.lastSyncState = false; 6786 pollSyncing(this); 6787 6788 return this; 6789 }; 6790 6791 IsSyncing.prototype.addCallback = function(callback) { 6792 if (callback) 6793 this.callbacks.push(callback); 6794 return this; 6795 }; 6796 6797 IsSyncing.prototype.stopWatching = function() { 6798 this.requestManager.stopPolling(this.pollId); 6799 this.callbacks = []; 6800 }; 6801 6802 module.exports = IsSyncing; 6803 6804 6805 }, { 6806 "../utils/utils": 20, 6807 "./formatters": 30 6808 }], 6809 49: [function(require, module, exports) { 6810 /* 6811 This file is part of web3.js. 6812 6813 web3.js is free software: you can redistribute it and/or modify 6814 it under the terms of the GNU Lesser General Public License as published by 6815 the Free Software Foundation, either version 3 of the License, or 6816 (at your option) any later version. 6817 6818 web3.js is distributed in the hope that it will be useful, 6819 but WITHOUT ANY WARRANTY; without even the implied warranty of 6820 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 6821 GNU Lesser General Public License for more details. 6822 6823 You should have received a copy of the GNU Lesser General Public License 6824 along with web3.js. If not, see <http://www.gnu.org/licenses/>. 6825 */ 6826 /** 6827 * @file transfer.js 6828 * @author Marek Kotewicz <marek@ethdev.com> 6829 * @date 2015 6830 */ 6831 6832 var Iban = require('./iban'); 6833 var exchangeAbi = require('../contracts/SmartExchange.json'); 6834 6835 /** 6836 * Should be used to make Iban transfer 6837 * 6838 * @method transfer 6839 * @param {String} from 6840 * @param {String} to iban 6841 * @param {Value} value to be tranfered 6842 * @param {Function} callback, callback 6843 */ 6844 var transfer = function(eth, from, to, value, callback) { 6845 var iban = new Iban(to); 6846 if (!iban.isValid()) { 6847 throw new Error('invalid iban address'); 6848 } 6849 6850 if (iban.isDirect()) { 6851 return transferToAddress(eth, from, iban.address(), value, callback); 6852 } 6853 6854 if (!callback) { 6855 var address = eth.icapNamereg().addr(iban.institution()); 6856 return deposit(eth, from, address, value, iban.client()); 6857 } 6858 6859 eth.icapNamereg().addr(iban.institution(), function(err, address) { 6860 return deposit(eth, from, address, value, iban.client(), callback); 6861 }); 6862 6863 }; 6864 6865 /** 6866 * Should be used to transfer funds to certain address 6867 * 6868 * @method transferToAddress 6869 * @param {String} from 6870 * @param {String} to 6871 * @param {Value} value to be tranfered 6872 * @param {Function} callback, callback 6873 */ 6874 var transferToAddress = function(eth, from, to, value, callback) { 6875 return eth.sendTransaction({ 6876 address: to, 6877 from: from, 6878 value: value 6879 }, callback); 6880 }; 6881 6882 /** 6883 * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!) 6884 * 6885 * @method deposit 6886 * @param {String} from 6887 * @param {String} to 6888 * @param {Value} value to be transferred 6889 * @param {String} client unique identifier 6890 * @param {Function} callback, callback 6891 */ 6892 var deposit = function(eth, from, to, value, client, callback) { 6893 var abi = exchangeAbi; 6894 return eth.contract(abi).at(to).deposit(client, { 6895 from: from, 6896 value: value 6897 }, callback); 6898 }; 6899 6900 module.exports = transfer; 6901 6902 6903 }, { 6904 "../contracts/SmartExchange.json": 3, 6905 "./iban": 33 6906 }], 6907 50: [function(require, module, exports) { 6908 6909 }, {}], 6910 51: [function(require, module, exports) {; 6911 (function(root, factory, undef) { 6912 if (typeof exports === "object") { 6913 // CommonJS 6914 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 6915 } else if (typeof define === "function" && define.amd) { 6916 // AMD 6917 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 6918 } else { 6919 // Global (browser) 6920 factory(root.CryptoJS); 6921 } 6922 }(this, function(CryptoJS) { 6923 6924 (function() { 6925 // Shortcuts 6926 var C = CryptoJS; 6927 var C_lib = C.lib; 6928 var BlockCipher = C_lib.BlockCipher; 6929 var C_algo = C.algo; 6930 6931 // Lookup tables 6932 var SBOX = []; 6933 var INV_SBOX = []; 6934 var SUB_MIX_0 = []; 6935 var SUB_MIX_1 = []; 6936 var SUB_MIX_2 = []; 6937 var SUB_MIX_3 = []; 6938 var INV_SUB_MIX_0 = []; 6939 var INV_SUB_MIX_1 = []; 6940 var INV_SUB_MIX_2 = []; 6941 var INV_SUB_MIX_3 = []; 6942 6943 // Compute lookup tables 6944 (function() { 6945 // Compute double table 6946 var d = []; 6947 for (var i = 0; i < 256; i++) { 6948 if (i < 128) { 6949 d[i] = i << 1; 6950 } else { 6951 d[i] = (i << 1) ^ 0x11b; 6952 } 6953 } 6954 6955 // Walk GF(2^8) 6956 var x = 0; 6957 var xi = 0; 6958 for (var i = 0; i < 256; i++) { 6959 // Compute sbox 6960 var sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); 6961 sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; 6962 SBOX[x] = sx; 6963 INV_SBOX[sx] = x; 6964 6965 // Compute multiplication 6966 var x2 = d[x]; 6967 var x4 = d[x2]; 6968 var x8 = d[x4]; 6969 6970 // Compute sub bytes, mix columns tables 6971 var t = (d[sx] * 0x101) ^ (sx * 0x1010100); 6972 SUB_MIX_0[x] = (t << 24) | (t >>> 8); 6973 SUB_MIX_1[x] = (t << 16) | (t >>> 16); 6974 SUB_MIX_2[x] = (t << 8) | (t >>> 24); 6975 SUB_MIX_3[x] = t; 6976 6977 // Compute inv sub bytes, inv mix columns tables 6978 var t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); 6979 INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); 6980 INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); 6981 INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); 6982 INV_SUB_MIX_3[sx] = t; 6983 6984 // Compute next counter 6985 if (!x) { 6986 x = xi = 1; 6987 } else { 6988 x = x2 ^ d[d[d[x8 ^ x2]]]; 6989 xi ^= d[d[xi]]; 6990 } 6991 } 6992 }()); 6993 6994 // Precomputed Rcon lookup 6995 var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; 6996 6997 /** 6998 * AES block cipher algorithm. 6999 */ 7000 var AES = C_algo.AES = BlockCipher.extend({ 7001 _doReset: function() { 7002 // Skip reset of nRounds has been set before and key did not change 7003 if (this._nRounds && this._keyPriorReset === this._key) { 7004 return; 7005 } 7006 7007 // Shortcuts 7008 var key = this._keyPriorReset = this._key; 7009 var keyWords = key.words; 7010 var keySize = key.sigBytes / 4; 7011 7012 // Compute number of rounds 7013 var nRounds = this._nRounds = keySize + 6; 7014 7015 // Compute number of key schedule rows 7016 var ksRows = (nRounds + 1) * 4; 7017 7018 // Compute key schedule 7019 var keySchedule = this._keySchedule = []; 7020 for (var ksRow = 0; ksRow < ksRows; ksRow++) { 7021 if (ksRow < keySize) { 7022 keySchedule[ksRow] = keyWords[ksRow]; 7023 } else { 7024 var t = keySchedule[ksRow - 1]; 7025 7026 if (!(ksRow % keySize)) { 7027 // Rot word 7028 t = (t << 8) | (t >>> 24); 7029 7030 // Sub word 7031 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 7032 7033 // Mix Rcon 7034 t ^= RCON[(ksRow / keySize) | 0] << 24; 7035 } else if (keySize > 6 && ksRow % keySize == 4) { 7036 // Sub word 7037 t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; 7038 } 7039 7040 keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; 7041 } 7042 } 7043 7044 // Compute inv key schedule 7045 var invKeySchedule = this._invKeySchedule = []; 7046 for (var invKsRow = 0; invKsRow < ksRows; invKsRow++) { 7047 var ksRow = ksRows - invKsRow; 7048 7049 if (invKsRow % 4) { 7050 var t = keySchedule[ksRow]; 7051 } else { 7052 var t = keySchedule[ksRow - 4]; 7053 } 7054 7055 if (invKsRow < 4 || ksRow <= 4) { 7056 invKeySchedule[invKsRow] = t; 7057 } else { 7058 invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ 7059 INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; 7060 } 7061 } 7062 }, 7063 7064 encryptBlock: function(M, offset) { 7065 this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); 7066 }, 7067 7068 decryptBlock: function(M, offset) { 7069 // Swap 2nd and 4th rows 7070 var t = M[offset + 1]; 7071 M[offset + 1] = M[offset + 3]; 7072 M[offset + 3] = t; 7073 7074 this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); 7075 7076 // Inv swap 2nd and 4th rows 7077 var t = M[offset + 1]; 7078 M[offset + 1] = M[offset + 3]; 7079 M[offset + 3] = t; 7080 }, 7081 7082 _doCryptBlock: function(M, offset, keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX) { 7083 // Shortcut 7084 var nRounds = this._nRounds; 7085 7086 // Get input, add round key 7087 var s0 = M[offset] ^ keySchedule[0]; 7088 var s1 = M[offset + 1] ^ keySchedule[1]; 7089 var s2 = M[offset + 2] ^ keySchedule[2]; 7090 var s3 = M[offset + 3] ^ keySchedule[3]; 7091 7092 // Key schedule row counter 7093 var ksRow = 4; 7094 7095 // Rounds 7096 for (var round = 1; round < nRounds; round++) { 7097 // Shift rows, sub bytes, mix columns, add round key 7098 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++]; 7099 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++]; 7100 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++]; 7101 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++]; 7102 7103 // Update state 7104 s0 = t0; 7105 s1 = t1; 7106 s2 = t2; 7107 s3 = t3; 7108 } 7109 7110 // Shift rows, sub bytes, add round key 7111 var t0 = ((SBOX[s0 >>> 24] << 24) | (SBOX[(s1 >>> 16) & 0xff] << 16) | (SBOX[(s2 >>> 8) & 0xff] << 8) | SBOX[s3 & 0xff]) ^ keySchedule[ksRow++]; 7112 var t1 = ((SBOX[s1 >>> 24] << 24) | (SBOX[(s2 >>> 16) & 0xff] << 16) | (SBOX[(s3 >>> 8) & 0xff] << 8) | SBOX[s0 & 0xff]) ^ keySchedule[ksRow++]; 7113 var t2 = ((SBOX[s2 >>> 24] << 24) | (SBOX[(s3 >>> 16) & 0xff] << 16) | (SBOX[(s0 >>> 8) & 0xff] << 8) | SBOX[s1 & 0xff]) ^ keySchedule[ksRow++]; 7114 var t3 = ((SBOX[s3 >>> 24] << 24) | (SBOX[(s0 >>> 16) & 0xff] << 16) | (SBOX[(s1 >>> 8) & 0xff] << 8) | SBOX[s2 & 0xff]) ^ keySchedule[ksRow++]; 7115 7116 // Set output 7117 M[offset] = t0; 7118 M[offset + 1] = t1; 7119 M[offset + 2] = t2; 7120 M[offset + 3] = t3; 7121 }, 7122 7123 keySize: 256 / 32 7124 }); 7125 7126 /** 7127 * Shortcut functions to the cipher's object interface. 7128 * 7129 * @example 7130 * 7131 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg); 7132 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg); 7133 */ 7134 C.AES = BlockCipher._createHelper(AES); 7135 }()); 7136 7137 7138 return CryptoJS.AES; 7139 7140 })); 7141 }, { 7142 "./cipher-core": 52, 7143 "./core": 53, 7144 "./enc-base64": 54, 7145 "./evpkdf": 56, 7146 "./md5": 61 7147 }], 7148 52: [function(require, module, exports) {; 7149 (function(root, factory) { 7150 if (typeof exports === "object") { 7151 // CommonJS 7152 module.exports = exports = factory(require("./core")); 7153 } else if (typeof define === "function" && define.amd) { 7154 // AMD 7155 define(["./core"], factory); 7156 } else { 7157 // Global (browser) 7158 factory(root.CryptoJS); 7159 } 7160 }(this, function(CryptoJS) { 7161 7162 /** 7163 * Cipher core components. 7164 */ 7165 CryptoJS.lib.Cipher || (function(undefined) { 7166 // Shortcuts 7167 var C = CryptoJS; 7168 var C_lib = C.lib; 7169 var Base = C_lib.Base; 7170 var WordArray = C_lib.WordArray; 7171 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 7172 var C_enc = C.enc; 7173 var Utf8 = C_enc.Utf8; 7174 var Base64 = C_enc.Base64; 7175 var C_algo = C.algo; 7176 var EvpKDF = C_algo.EvpKDF; 7177 7178 /** 7179 * Abstract base cipher template. 7180 * 7181 * @property {number} keySize This cipher's key size. Default: 4 (128 bits) 7182 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits) 7183 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode. 7184 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode. 7185 */ 7186 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 7187 /** 7188 * Configuration options. 7189 * 7190 * @property {WordArray} iv The IV to use for this operation. 7191 */ 7192 cfg: Base.extend(), 7193 7194 /** 7195 * Creates this cipher in encryption mode. 7196 * 7197 * @param {WordArray} key The key. 7198 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7199 * 7200 * @return {Cipher} A cipher instance. 7201 * 7202 * @static 7203 * 7204 * @example 7205 * 7206 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 7207 */ 7208 createEncryptor: function(key, cfg) { 7209 return this.create(this._ENC_XFORM_MODE, key, cfg); 7210 }, 7211 7212 /** 7213 * Creates this cipher in decryption mode. 7214 * 7215 * @param {WordArray} key The key. 7216 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7217 * 7218 * @return {Cipher} A cipher instance. 7219 * 7220 * @static 7221 * 7222 * @example 7223 * 7224 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 7225 */ 7226 createDecryptor: function(key, cfg) { 7227 return this.create(this._DEC_XFORM_MODE, key, cfg); 7228 }, 7229 7230 /** 7231 * Initializes a newly created cipher. 7232 * 7233 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 7234 * @param {WordArray} key The key. 7235 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7236 * 7237 * @example 7238 * 7239 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 7240 */ 7241 init: function(xformMode, key, cfg) { 7242 // Apply config defaults 7243 this.cfg = this.cfg.extend(cfg); 7244 7245 // Store transform mode and key 7246 this._xformMode = xformMode; 7247 this._key = key; 7248 7249 // Set initial values 7250 this.reset(); 7251 }, 7252 7253 /** 7254 * Resets this cipher to its initial state. 7255 * 7256 * @example 7257 * 7258 * cipher.reset(); 7259 */ 7260 reset: function() { 7261 // Reset data buffer 7262 BufferedBlockAlgorithm.reset.call(this); 7263 7264 // Perform concrete-cipher logic 7265 this._doReset(); 7266 }, 7267 7268 /** 7269 * Adds data to be encrypted or decrypted. 7270 * 7271 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 7272 * 7273 * @return {WordArray} The data after processing. 7274 * 7275 * @example 7276 * 7277 * var encrypted = cipher.process('data'); 7278 * var encrypted = cipher.process(wordArray); 7279 */ 7280 process: function(dataUpdate) { 7281 // Append 7282 this._append(dataUpdate); 7283 7284 // Process available blocks 7285 return this._process(); 7286 }, 7287 7288 /** 7289 * Finalizes the encryption or decryption process. 7290 * Note that the finalize operation is effectively a destructive, read-once operation. 7291 * 7292 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 7293 * 7294 * @return {WordArray} The data after final processing. 7295 * 7296 * @example 7297 * 7298 * var encrypted = cipher.finalize(); 7299 * var encrypted = cipher.finalize('data'); 7300 * var encrypted = cipher.finalize(wordArray); 7301 */ 7302 finalize: function(dataUpdate) { 7303 // Final data update 7304 if (dataUpdate) { 7305 this._append(dataUpdate); 7306 } 7307 7308 // Perform concrete-cipher logic 7309 var finalProcessedData = this._doFinalize(); 7310 7311 return finalProcessedData; 7312 }, 7313 7314 keySize: 128 / 32, 7315 7316 ivSize: 128 / 32, 7317 7318 _ENC_XFORM_MODE: 1, 7319 7320 _DEC_XFORM_MODE: 2, 7321 7322 /** 7323 * Creates shortcut functions to a cipher's object interface. 7324 * 7325 * @param {Cipher} cipher The cipher to create a helper for. 7326 * 7327 * @return {Object} An object with encrypt and decrypt shortcut functions. 7328 * 7329 * @static 7330 * 7331 * @example 7332 * 7333 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 7334 */ 7335 _createHelper: (function() { 7336 function selectCipherStrategy(key) { 7337 if (typeof key == 'string') { 7338 return PasswordBasedCipher; 7339 } else { 7340 return SerializableCipher; 7341 } 7342 } 7343 7344 return function(cipher) { 7345 return { 7346 encrypt: function(message, key, cfg) { 7347 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 7348 }, 7349 7350 decrypt: function(ciphertext, key, cfg) { 7351 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 7352 } 7353 }; 7354 }; 7355 }()) 7356 }); 7357 7358 /** 7359 * Abstract base stream cipher template. 7360 * 7361 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits) 7362 */ 7363 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 7364 _doFinalize: function() { 7365 // Process partial blocks 7366 var finalProcessedBlocks = this._process(!!'flush'); 7367 7368 return finalProcessedBlocks; 7369 }, 7370 7371 blockSize: 1 7372 }); 7373 7374 /** 7375 * Mode namespace. 7376 */ 7377 var C_mode = C.mode = {}; 7378 7379 /** 7380 * Abstract base block cipher mode template. 7381 */ 7382 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 7383 /** 7384 * Creates this mode for encryption. 7385 * 7386 * @param {Cipher} cipher A block cipher instance. 7387 * @param {Array} iv The IV words. 7388 * 7389 * @static 7390 * 7391 * @example 7392 * 7393 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 7394 */ 7395 createEncryptor: function(cipher, iv) { 7396 return this.Encryptor.create(cipher, iv); 7397 }, 7398 7399 /** 7400 * Creates this mode for decryption. 7401 * 7402 * @param {Cipher} cipher A block cipher instance. 7403 * @param {Array} iv The IV words. 7404 * 7405 * @static 7406 * 7407 * @example 7408 * 7409 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 7410 */ 7411 createDecryptor: function(cipher, iv) { 7412 return this.Decryptor.create(cipher, iv); 7413 }, 7414 7415 /** 7416 * Initializes a newly created mode. 7417 * 7418 * @param {Cipher} cipher A block cipher instance. 7419 * @param {Array} iv The IV words. 7420 * 7421 * @example 7422 * 7423 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 7424 */ 7425 init: function(cipher, iv) { 7426 this._cipher = cipher; 7427 this._iv = iv; 7428 } 7429 }); 7430 7431 /** 7432 * Cipher Block Chaining mode. 7433 */ 7434 var CBC = C_mode.CBC = (function() { 7435 /** 7436 * Abstract base CBC mode. 7437 */ 7438 var CBC = BlockCipherMode.extend(); 7439 7440 /** 7441 * CBC encryptor. 7442 */ 7443 CBC.Encryptor = CBC.extend({ 7444 /** 7445 * Processes the data block at offset. 7446 * 7447 * @param {Array} words The data words to operate on. 7448 * @param {number} offset The offset where the block starts. 7449 * 7450 * @example 7451 * 7452 * mode.processBlock(data.words, offset); 7453 */ 7454 processBlock: function(words, offset) { 7455 // Shortcuts 7456 var cipher = this._cipher; 7457 var blockSize = cipher.blockSize; 7458 7459 // XOR and encrypt 7460 xorBlock.call(this, words, offset, blockSize); 7461 cipher.encryptBlock(words, offset); 7462 7463 // Remember this block to use with next block 7464 this._prevBlock = words.slice(offset, offset + blockSize); 7465 } 7466 }); 7467 7468 /** 7469 * CBC decryptor. 7470 */ 7471 CBC.Decryptor = CBC.extend({ 7472 /** 7473 * Processes the data block at offset. 7474 * 7475 * @param {Array} words The data words to operate on. 7476 * @param {number} offset The offset where the block starts. 7477 * 7478 * @example 7479 * 7480 * mode.processBlock(data.words, offset); 7481 */ 7482 processBlock: function(words, offset) { 7483 // Shortcuts 7484 var cipher = this._cipher; 7485 var blockSize = cipher.blockSize; 7486 7487 // Remember this block to use with next block 7488 var thisBlock = words.slice(offset, offset + blockSize); 7489 7490 // Decrypt and XOR 7491 cipher.decryptBlock(words, offset); 7492 xorBlock.call(this, words, offset, blockSize); 7493 7494 // This block becomes the previous block 7495 this._prevBlock = thisBlock; 7496 } 7497 }); 7498 7499 function xorBlock(words, offset, blockSize) { 7500 // Shortcut 7501 var iv = this._iv; 7502 7503 // Choose mixing block 7504 if (iv) { 7505 var block = iv; 7506 7507 // Remove IV for subsequent blocks 7508 this._iv = undefined; 7509 } else { 7510 var block = this._prevBlock; 7511 } 7512 7513 // XOR blocks 7514 for (var i = 0; i < blockSize; i++) { 7515 words[offset + i] ^= block[i]; 7516 } 7517 } 7518 7519 return CBC; 7520 }()); 7521 7522 /** 7523 * Padding namespace. 7524 */ 7525 var C_pad = C.pad = {}; 7526 7527 /** 7528 * PKCS #5/7 padding strategy. 7529 */ 7530 var Pkcs7 = C_pad.Pkcs7 = { 7531 /** 7532 * Pads data using the algorithm defined in PKCS #5/7. 7533 * 7534 * @param {WordArray} data The data to pad. 7535 * @param {number} blockSize The multiple that the data should be padded to. 7536 * 7537 * @static 7538 * 7539 * @example 7540 * 7541 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 7542 */ 7543 pad: function(data, blockSize) { 7544 // Shortcut 7545 var blockSizeBytes = blockSize * 4; 7546 7547 // Count padding bytes 7548 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 7549 7550 // Create padding word 7551 var paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; 7552 7553 // Create padding 7554 var paddingWords = []; 7555 for (var i = 0; i < nPaddingBytes; i += 4) { 7556 paddingWords.push(paddingWord); 7557 } 7558 var padding = WordArray.create(paddingWords, nPaddingBytes); 7559 7560 // Add padding 7561 data.concat(padding); 7562 }, 7563 7564 /** 7565 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 7566 * 7567 * @param {WordArray} data The data to unpad. 7568 * 7569 * @static 7570 * 7571 * @example 7572 * 7573 * CryptoJS.pad.Pkcs7.unpad(wordArray); 7574 */ 7575 unpad: function(data) { 7576 // Get number of padding bytes from last byte 7577 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 7578 7579 // Remove padding 7580 data.sigBytes -= nPaddingBytes; 7581 } 7582 }; 7583 7584 /** 7585 * Abstract base block cipher template. 7586 * 7587 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits) 7588 */ 7589 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 7590 /** 7591 * Configuration options. 7592 * 7593 * @property {Mode} mode The block mode to use. Default: CBC 7594 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 7595 */ 7596 cfg: Cipher.cfg.extend({ 7597 mode: CBC, 7598 padding: Pkcs7 7599 }), 7600 7601 reset: function() { 7602 // Reset cipher 7603 Cipher.reset.call(this); 7604 7605 // Shortcuts 7606 var cfg = this.cfg; 7607 var iv = cfg.iv; 7608 var mode = cfg.mode; 7609 7610 // Reset block mode 7611 if (this._xformMode == this._ENC_XFORM_MODE) { 7612 var modeCreator = mode.createEncryptor; 7613 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7614 var modeCreator = mode.createDecryptor; 7615 7616 // Keep at least one block in the buffer for unpadding 7617 this._minBufferSize = 1; 7618 } 7619 this._mode = modeCreator.call(mode, this, iv && iv.words); 7620 }, 7621 7622 _doProcessBlock: function(words, offset) { 7623 this._mode.processBlock(words, offset); 7624 }, 7625 7626 _doFinalize: function() { 7627 // Shortcut 7628 var padding = this.cfg.padding; 7629 7630 // Finalize 7631 if (this._xformMode == this._ENC_XFORM_MODE) { 7632 // Pad data 7633 padding.pad(this._data, this.blockSize); 7634 7635 // Process final blocks 7636 var finalProcessedBlocks = this._process(!!'flush'); 7637 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { 7638 // Process final blocks 7639 var finalProcessedBlocks = this._process(!!'flush'); 7640 7641 // Unpad data 7642 padding.unpad(finalProcessedBlocks); 7643 } 7644 7645 return finalProcessedBlocks; 7646 }, 7647 7648 blockSize: 128 / 32 7649 }); 7650 7651 /** 7652 * A collection of cipher parameters. 7653 * 7654 * @property {WordArray} ciphertext The raw ciphertext. 7655 * @property {WordArray} key The key to this ciphertext. 7656 * @property {WordArray} iv The IV used in the ciphering operation. 7657 * @property {WordArray} salt The salt used with a key derivation function. 7658 * @property {Cipher} algorithm The cipher algorithm. 7659 * @property {Mode} mode The block mode used in the ciphering operation. 7660 * @property {Padding} padding The padding scheme used in the ciphering operation. 7661 * @property {number} blockSize The block size of the cipher. 7662 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string. 7663 */ 7664 var CipherParams = C_lib.CipherParams = Base.extend({ 7665 /** 7666 * Initializes a newly created cipher params object. 7667 * 7668 * @param {Object} cipherParams An object with any of the possible cipher parameters. 7669 * 7670 * @example 7671 * 7672 * var cipherParams = CryptoJS.lib.CipherParams.create({ 7673 * ciphertext: ciphertextWordArray, 7674 * key: keyWordArray, 7675 * iv: ivWordArray, 7676 * salt: saltWordArray, 7677 * algorithm: CryptoJS.algo.AES, 7678 * mode: CryptoJS.mode.CBC, 7679 * padding: CryptoJS.pad.PKCS7, 7680 * blockSize: 4, 7681 * formatter: CryptoJS.format.OpenSSL 7682 * }); 7683 */ 7684 init: function(cipherParams) { 7685 this.mixIn(cipherParams); 7686 }, 7687 7688 /** 7689 * Converts this cipher params object to a string. 7690 * 7691 * @param {Format} formatter (Optional) The formatting strategy to use. 7692 * 7693 * @return {string} The stringified cipher params. 7694 * 7695 * @throws Error If neither the formatter nor the default formatter is set. 7696 * 7697 * @example 7698 * 7699 * var string = cipherParams + ''; 7700 * var string = cipherParams.toString(); 7701 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 7702 */ 7703 toString: function(formatter) { 7704 return (formatter || this.formatter).stringify(this); 7705 } 7706 }); 7707 7708 /** 7709 * Format namespace. 7710 */ 7711 var C_format = C.format = {}; 7712 7713 /** 7714 * OpenSSL formatting strategy. 7715 */ 7716 var OpenSSLFormatter = C_format.OpenSSL = { 7717 /** 7718 * Converts a cipher params object to an OpenSSL-compatible string. 7719 * 7720 * @param {CipherParams} cipherParams The cipher params object. 7721 * 7722 * @return {string} The OpenSSL-compatible string. 7723 * 7724 * @static 7725 * 7726 * @example 7727 * 7728 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 7729 */ 7730 stringify: function(cipherParams) { 7731 // Shortcuts 7732 var ciphertext = cipherParams.ciphertext; 7733 var salt = cipherParams.salt; 7734 7735 // Format 7736 if (salt) { 7737 var wordArray = WordArray.create([0x53616c74, 0x65645f5f]).concat(salt).concat(ciphertext); 7738 } else { 7739 var wordArray = ciphertext; 7740 } 7741 7742 return wordArray.toString(Base64); 7743 }, 7744 7745 /** 7746 * Converts an OpenSSL-compatible string to a cipher params object. 7747 * 7748 * @param {string} openSSLStr The OpenSSL-compatible string. 7749 * 7750 * @return {CipherParams} The cipher params object. 7751 * 7752 * @static 7753 * 7754 * @example 7755 * 7756 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 7757 */ 7758 parse: function(openSSLStr) { 7759 // Parse base64 7760 var ciphertext = Base64.parse(openSSLStr); 7761 7762 // Shortcut 7763 var ciphertextWords = ciphertext.words; 7764 7765 // Test for salt 7766 if (ciphertextWords[0] == 0x53616c74 && ciphertextWords[1] == 0x65645f5f) { 7767 // Extract salt 7768 var salt = WordArray.create(ciphertextWords.slice(2, 4)); 7769 7770 // Remove salt from ciphertext 7771 ciphertextWords.splice(0, 4); 7772 ciphertext.sigBytes -= 16; 7773 } 7774 7775 return CipherParams.create({ 7776 ciphertext: ciphertext, 7777 salt: salt 7778 }); 7779 } 7780 }; 7781 7782 /** 7783 * A cipher wrapper that returns ciphertext as a serializable cipher params object. 7784 */ 7785 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 7786 /** 7787 * Configuration options. 7788 * 7789 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 7790 */ 7791 cfg: Base.extend({ 7792 format: OpenSSLFormatter 7793 }), 7794 7795 /** 7796 * Encrypts a message. 7797 * 7798 * @param {Cipher} cipher The cipher algorithm to use. 7799 * @param {WordArray|string} message The message to encrypt. 7800 * @param {WordArray} key The key. 7801 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7802 * 7803 * @return {CipherParams} A cipher params object. 7804 * 7805 * @static 7806 * 7807 * @example 7808 * 7809 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 7810 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 7811 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7812 */ 7813 encrypt: function(cipher, message, key, cfg) { 7814 // Apply config defaults 7815 cfg = this.cfg.extend(cfg); 7816 7817 // Encrypt 7818 var encryptor = cipher.createEncryptor(key, cfg); 7819 var ciphertext = encryptor.finalize(message); 7820 7821 // Shortcut 7822 var cipherCfg = encryptor.cfg; 7823 7824 // Create and return serializable cipher params 7825 return CipherParams.create({ 7826 ciphertext: ciphertext, 7827 key: key, 7828 iv: cipherCfg.iv, 7829 algorithm: cipher, 7830 mode: cipherCfg.mode, 7831 padding: cipherCfg.padding, 7832 blockSize: cipher.blockSize, 7833 formatter: cfg.format 7834 }); 7835 }, 7836 7837 /** 7838 * Decrypts serialized ciphertext. 7839 * 7840 * @param {Cipher} cipher The cipher algorithm to use. 7841 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7842 * @param {WordArray} key The key. 7843 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7844 * 7845 * @return {WordArray} The plaintext. 7846 * 7847 * @static 7848 * 7849 * @example 7850 * 7851 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7852 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 7853 */ 7854 decrypt: function(cipher, ciphertext, key, cfg) { 7855 // Apply config defaults 7856 cfg = this.cfg.extend(cfg); 7857 7858 // Convert string to CipherParams 7859 ciphertext = this._parse(ciphertext, cfg.format); 7860 7861 // Decrypt 7862 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 7863 7864 return plaintext; 7865 }, 7866 7867 /** 7868 * Converts serialized ciphertext to CipherParams, 7869 * else assumed CipherParams already and returns ciphertext unchanged. 7870 * 7871 * @param {CipherParams|string} ciphertext The ciphertext. 7872 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 7873 * 7874 * @return {CipherParams} The unserialized ciphertext. 7875 * 7876 * @static 7877 * 7878 * @example 7879 * 7880 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 7881 */ 7882 _parse: function(ciphertext, format) { 7883 if (typeof ciphertext == 'string') { 7884 return format.parse(ciphertext, this); 7885 } else { 7886 return ciphertext; 7887 } 7888 } 7889 }); 7890 7891 /** 7892 * Key derivation function namespace. 7893 */ 7894 var C_kdf = C.kdf = {}; 7895 7896 /** 7897 * OpenSSL key derivation function. 7898 */ 7899 var OpenSSLKdf = C_kdf.OpenSSL = { 7900 /** 7901 * Derives a key and IV from a password. 7902 * 7903 * @param {string} password The password to derive from. 7904 * @param {number} keySize The size in words of the key to generate. 7905 * @param {number} ivSize The size in words of the IV to generate. 7906 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 7907 * 7908 * @return {CipherParams} A cipher params object with the key, IV, and salt. 7909 * 7910 * @static 7911 * 7912 * @example 7913 * 7914 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 7915 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 7916 */ 7917 execute: function(password, keySize, ivSize, salt) { 7918 // Generate random salt 7919 if (!salt) { 7920 salt = WordArray.random(64 / 8); 7921 } 7922 7923 // Derive key and IV 7924 var key = EvpKDF.create({ 7925 keySize: keySize + ivSize 7926 }).compute(password, salt); 7927 7928 // Separate key and IV 7929 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 7930 key.sigBytes = keySize * 4; 7931 7932 // Return params 7933 return CipherParams.create({ 7934 key: key, 7935 iv: iv, 7936 salt: salt 7937 }); 7938 } 7939 }; 7940 7941 /** 7942 * A serializable cipher wrapper that derives the key from a password, 7943 * and returns ciphertext as a serializable cipher params object. 7944 */ 7945 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 7946 /** 7947 * Configuration options. 7948 * 7949 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 7950 */ 7951 cfg: SerializableCipher.cfg.extend({ 7952 kdf: OpenSSLKdf 7953 }), 7954 7955 /** 7956 * Encrypts a message using a password. 7957 * 7958 * @param {Cipher} cipher The cipher algorithm to use. 7959 * @param {WordArray|string} message The message to encrypt. 7960 * @param {string} password The password. 7961 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7962 * 7963 * @return {CipherParams} A cipher params object. 7964 * 7965 * @static 7966 * 7967 * @example 7968 * 7969 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 7970 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 7971 */ 7972 encrypt: function(cipher, message, password, cfg) { 7973 // Apply config defaults 7974 cfg = this.cfg.extend(cfg); 7975 7976 // Derive key and other params 7977 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize); 7978 7979 // Add IV to config 7980 cfg.iv = derivedParams.iv; 7981 7982 // Encrypt 7983 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 7984 7985 // Mix in derived params 7986 ciphertext.mixIn(derivedParams); 7987 7988 return ciphertext; 7989 }, 7990 7991 /** 7992 * Decrypts serialized ciphertext using a password. 7993 * 7994 * @param {Cipher} cipher The cipher algorithm to use. 7995 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 7996 * @param {string} password The password. 7997 * @param {Object} cfg (Optional) The configuration options to use for this operation. 7998 * 7999 * @return {WordArray} The plaintext. 8000 * 8001 * @static 8002 * 8003 * @example 8004 * 8005 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 8006 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 8007 */ 8008 decrypt: function(cipher, ciphertext, password, cfg) { 8009 // Apply config defaults 8010 cfg = this.cfg.extend(cfg); 8011 8012 // Convert string to CipherParams 8013 ciphertext = this._parse(ciphertext, cfg.format); 8014 8015 // Derive key and other params 8016 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); 8017 8018 // Add IV to config 8019 cfg.iv = derivedParams.iv; 8020 8021 // Decrypt 8022 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 8023 8024 return plaintext; 8025 } 8026 }); 8027 }()); 8028 8029 8030 })); 8031 }, { 8032 "./core": 53 8033 }], 8034 53: [function(require, module, exports) {; 8035 (function(root, factory) { 8036 if (typeof exports === "object") { 8037 // CommonJS 8038 module.exports = exports = factory(); 8039 } else if (typeof define === "function" && define.amd) { 8040 // AMD 8041 define([], factory); 8042 } else { 8043 // Global (browser) 8044 root.CryptoJS = factory(); 8045 } 8046 }(this, function() { 8047 8048 /** 8049 * CryptoJS core components. 8050 */ 8051 var CryptoJS = CryptoJS || (function(Math, undefined) { 8052 /* 8053 * Local polyfil of Object.create 8054 */ 8055 var create = Object.create || (function() { 8056 function F() {}; 8057 8058 return function(obj) { 8059 var subtype; 8060 8061 F.prototype = obj; 8062 8063 subtype = new F(); 8064 8065 F.prototype = null; 8066 8067 return subtype; 8068 }; 8069 }()) 8070 8071 /** 8072 * CryptoJS namespace. 8073 */ 8074 var C = {}; 8075 8076 /** 8077 * Library namespace. 8078 */ 8079 var C_lib = C.lib = {}; 8080 8081 /** 8082 * Base object for prototypal inheritance. 8083 */ 8084 var Base = C_lib.Base = (function() { 8085 8086 8087 return { 8088 /** 8089 * Creates a new object that inherits from this object. 8090 * 8091 * @param {Object} overrides Properties to copy into the new object. 8092 * 8093 * @return {Object} The new object. 8094 * 8095 * @static 8096 * 8097 * @example 8098 * 8099 * var MyType = CryptoJS.lib.Base.extend({ 8100 * field: 'value', 8101 * 8102 * method: function () { 8103 * } 8104 * }); 8105 */ 8106 extend: function(overrides) { 8107 // Spawn 8108 var subtype = create(this); 8109 8110 // Augment 8111 if (overrides) { 8112 subtype.mixIn(overrides); 8113 } 8114 8115 // Create default initializer 8116 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 8117 subtype.init = function() { 8118 subtype.$super.init.apply(this, arguments); 8119 }; 8120 } 8121 8122 // Initializer's prototype is the subtype object 8123 subtype.init.prototype = subtype; 8124 8125 // Reference supertype 8126 subtype.$super = this; 8127 8128 return subtype; 8129 }, 8130 8131 /** 8132 * Extends this object and runs the init method. 8133 * Arguments to create() will be passed to init(). 8134 * 8135 * @return {Object} The new object. 8136 * 8137 * @static 8138 * 8139 * @example 8140 * 8141 * var instance = MyType.create(); 8142 */ 8143 create: function() { 8144 var instance = this.extend(); 8145 instance.init.apply(instance, arguments); 8146 8147 return instance; 8148 }, 8149 8150 /** 8151 * Initializes a newly created object. 8152 * Override this method to add some logic when your objects are created. 8153 * 8154 * @example 8155 * 8156 * var MyType = CryptoJS.lib.Base.extend({ 8157 * init: function () { 8158 * // ... 8159 * } 8160 * }); 8161 */ 8162 init: function() {}, 8163 8164 /** 8165 * Copies properties into this object. 8166 * 8167 * @param {Object} properties The properties to mix in. 8168 * 8169 * @example 8170 * 8171 * MyType.mixIn({ 8172 * field: 'value' 8173 * }); 8174 */ 8175 mixIn: function(properties) { 8176 for (var propertyName in properties) { 8177 if (properties.hasOwnProperty(propertyName)) { 8178 this[propertyName] = properties[propertyName]; 8179 } 8180 } 8181 8182 // IE won't copy toString using the loop above 8183 if (properties.hasOwnProperty('toString')) { 8184 this.toString = properties.toString; 8185 } 8186 }, 8187 8188 /** 8189 * Creates a copy of this object. 8190 * 8191 * @return {Object} The clone. 8192 * 8193 * @example 8194 * 8195 * var clone = instance.clone(); 8196 */ 8197 clone: function() { 8198 return this.init.prototype.extend(this); 8199 } 8200 }; 8201 }()); 8202 8203 /** 8204 * An array of 32-bit words. 8205 * 8206 * @property {Array} words The array of 32-bit words. 8207 * @property {number} sigBytes The number of significant bytes in this word array. 8208 */ 8209 var WordArray = C_lib.WordArray = Base.extend({ 8210 /** 8211 * Initializes a newly created word array. 8212 * 8213 * @param {Array} words (Optional) An array of 32-bit words. 8214 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 8215 * 8216 * @example 8217 * 8218 * var wordArray = CryptoJS.lib.WordArray.create(); 8219 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 8220 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 8221 */ 8222 init: function(words, sigBytes) { 8223 words = this.words = words || []; 8224 8225 if (sigBytes != undefined) { 8226 this.sigBytes = sigBytes; 8227 } else { 8228 this.sigBytes = words.length * 4; 8229 } 8230 }, 8231 8232 /** 8233 * Converts this word array to a string. 8234 * 8235 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 8236 * 8237 * @return {string} The stringified word array. 8238 * 8239 * @example 8240 * 8241 * var string = wordArray + ''; 8242 * var string = wordArray.toString(); 8243 * var string = wordArray.toString(CryptoJS.enc.Utf8); 8244 */ 8245 toString: function(encoder) { 8246 return (encoder || Hex).stringify(this); 8247 }, 8248 8249 /** 8250 * Concatenates a word array to this word array. 8251 * 8252 * @param {WordArray} wordArray The word array to append. 8253 * 8254 * @return {WordArray} This word array. 8255 * 8256 * @example 8257 * 8258 * wordArray1.concat(wordArray2); 8259 */ 8260 concat: function(wordArray) { 8261 // Shortcuts 8262 var thisWords = this.words; 8263 var thatWords = wordArray.words; 8264 var thisSigBytes = this.sigBytes; 8265 var thatSigBytes = wordArray.sigBytes; 8266 8267 // Clamp excess bits 8268 this.clamp(); 8269 8270 // Concat 8271 if (thisSigBytes % 4) { 8272 // Copy one byte at a time 8273 for (var i = 0; i < thatSigBytes; i++) { 8274 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8275 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 8276 } 8277 } else { 8278 // Copy one word at a time 8279 for (var i = 0; i < thatSigBytes; i += 4) { 8280 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 8281 } 8282 } 8283 this.sigBytes += thatSigBytes; 8284 8285 // Chainable 8286 return this; 8287 }, 8288 8289 /** 8290 * Removes insignificant bits. 8291 * 8292 * @example 8293 * 8294 * wordArray.clamp(); 8295 */ 8296 clamp: function() { 8297 // Shortcuts 8298 var words = this.words; 8299 var sigBytes = this.sigBytes; 8300 8301 // Clamp 8302 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8303 words.length = Math.ceil(sigBytes / 4); 8304 }, 8305 8306 /** 8307 * Creates a copy of this word array. 8308 * 8309 * @return {WordArray} The clone. 8310 * 8311 * @example 8312 * 8313 * var clone = wordArray.clone(); 8314 */ 8315 clone: function() { 8316 var clone = Base.clone.call(this); 8317 clone.words = this.words.slice(0); 8318 8319 return clone; 8320 }, 8321 8322 /** 8323 * Creates a word array filled with random bytes. 8324 * 8325 * @param {number} nBytes The number of random bytes to generate. 8326 * 8327 * @return {WordArray} The random word array. 8328 * 8329 * @static 8330 * 8331 * @example 8332 * 8333 * var wordArray = CryptoJS.lib.WordArray.random(16); 8334 */ 8335 random: function(nBytes) { 8336 var words = []; 8337 8338 var r = (function(m_w) { 8339 var m_w = m_w; 8340 var m_z = 0x3ade68b1; 8341 var mask = 0xffffffff; 8342 8343 return function() { 8344 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8345 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8346 var result = ((m_z << 0x10) + m_w) & mask; 8347 result /= 0x100000000; 8348 result += 0.5; 8349 return result * (Math.random() > .5 ? 1 : -1); 8350 } 8351 }); 8352 8353 for (var i = 0, rcache; i < nBytes; i += 4) { 8354 var _r = r((rcache || Math.random()) * 0x100000000); 8355 8356 rcache = _r() * 0x3ade67b7; 8357 words.push((_r() * 0x100000000) | 0); 8358 } 8359 8360 return new WordArray.init(words, nBytes); 8361 } 8362 }); 8363 8364 /** 8365 * Encoder namespace. 8366 */ 8367 var C_enc = C.enc = {}; 8368 8369 /** 8370 * Hex encoding strategy. 8371 */ 8372 var Hex = C_enc.Hex = { 8373 /** 8374 * Converts a word array to a hex string. 8375 * 8376 * @param {WordArray} wordArray The word array. 8377 * 8378 * @return {string} The hex string. 8379 * 8380 * @static 8381 * 8382 * @example 8383 * 8384 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8385 */ 8386 stringify: function(wordArray) { 8387 // Shortcuts 8388 var words = wordArray.words; 8389 var sigBytes = wordArray.sigBytes; 8390 8391 // Convert 8392 var hexChars = []; 8393 for (var i = 0; i < sigBytes; i++) { 8394 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8395 hexChars.push((bite >>> 4).toString(16)); 8396 hexChars.push((bite & 0x0f).toString(16)); 8397 } 8398 8399 return hexChars.join(''); 8400 }, 8401 8402 /** 8403 * Converts a hex string to a word array. 8404 * 8405 * @param {string} hexStr The hex string. 8406 * 8407 * @return {WordArray} The word array. 8408 * 8409 * @static 8410 * 8411 * @example 8412 * 8413 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8414 */ 8415 parse: function(hexStr) { 8416 // Shortcut 8417 var hexStrLength = hexStr.length; 8418 8419 // Convert 8420 var words = []; 8421 for (var i = 0; i < hexStrLength; i += 2) { 8422 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8423 } 8424 8425 return new WordArray.init(words, hexStrLength / 2); 8426 } 8427 }; 8428 8429 /** 8430 * Latin1 encoding strategy. 8431 */ 8432 var Latin1 = C_enc.Latin1 = { 8433 /** 8434 * Converts a word array to a Latin1 string. 8435 * 8436 * @param {WordArray} wordArray The word array. 8437 * 8438 * @return {string} The Latin1 string. 8439 * 8440 * @static 8441 * 8442 * @example 8443 * 8444 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8445 */ 8446 stringify: function(wordArray) { 8447 // Shortcuts 8448 var words = wordArray.words; 8449 var sigBytes = wordArray.sigBytes; 8450 8451 // Convert 8452 var latin1Chars = []; 8453 for (var i = 0; i < sigBytes; i++) { 8454 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8455 latin1Chars.push(String.fromCharCode(bite)); 8456 } 8457 8458 return latin1Chars.join(''); 8459 }, 8460 8461 /** 8462 * Converts a Latin1 string to a word array. 8463 * 8464 * @param {string} latin1Str The Latin1 string. 8465 * 8466 * @return {WordArray} The word array. 8467 * 8468 * @static 8469 * 8470 * @example 8471 * 8472 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8473 */ 8474 parse: function(latin1Str) { 8475 // Shortcut 8476 var latin1StrLength = latin1Str.length; 8477 8478 // Convert 8479 var words = []; 8480 for (var i = 0; i < latin1StrLength; i++) { 8481 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8482 } 8483 8484 return new WordArray.init(words, latin1StrLength); 8485 } 8486 }; 8487 8488 /** 8489 * UTF-8 encoding strategy. 8490 */ 8491 var Utf8 = C_enc.Utf8 = { 8492 /** 8493 * Converts a word array to a UTF-8 string. 8494 * 8495 * @param {WordArray} wordArray The word array. 8496 * 8497 * @return {string} The UTF-8 string. 8498 * 8499 * @static 8500 * 8501 * @example 8502 * 8503 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8504 */ 8505 stringify: function(wordArray) { 8506 try { 8507 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8508 } catch (e) { 8509 throw new Error('Malformed UTF-8 data'); 8510 } 8511 }, 8512 8513 /** 8514 * Converts a UTF-8 string to a word array. 8515 * 8516 * @param {string} utf8Str The UTF-8 string. 8517 * 8518 * @return {WordArray} The word array. 8519 * 8520 * @static 8521 * 8522 * @example 8523 * 8524 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8525 */ 8526 parse: function(utf8Str) { 8527 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8528 } 8529 }; 8530 8531 /** 8532 * Abstract buffered block algorithm template. 8533 * 8534 * The property blockSize must be implemented in a concrete subtype. 8535 * 8536 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8537 */ 8538 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8539 /** 8540 * Resets this block algorithm's data buffer to its initial state. 8541 * 8542 * @example 8543 * 8544 * bufferedBlockAlgorithm.reset(); 8545 */ 8546 reset: function() { 8547 // Initial values 8548 this._data = new WordArray.init(); 8549 this._nDataBytes = 0; 8550 }, 8551 8552 /** 8553 * Adds new data to this block algorithm's buffer. 8554 * 8555 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8556 * 8557 * @example 8558 * 8559 * bufferedBlockAlgorithm._append('data'); 8560 * bufferedBlockAlgorithm._append(wordArray); 8561 */ 8562 _append: function(data) { 8563 // Convert string to WordArray, else assume WordArray already 8564 if (typeof data == 'string') { 8565 data = Utf8.parse(data); 8566 } 8567 8568 // Append 8569 this._data.concat(data); 8570 this._nDataBytes += data.sigBytes; 8571 }, 8572 8573 /** 8574 * Processes available data blocks. 8575 * 8576 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8577 * 8578 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8579 * 8580 * @return {WordArray} The processed data. 8581 * 8582 * @example 8583 * 8584 * var processedData = bufferedBlockAlgorithm._process(); 8585 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8586 */ 8587 _process: function(doFlush) { 8588 // Shortcuts 8589 var data = this._data; 8590 var dataWords = data.words; 8591 var dataSigBytes = data.sigBytes; 8592 var blockSize = this.blockSize; 8593 var blockSizeBytes = blockSize * 4; 8594 8595 // Count blocks ready 8596 var nBlocksReady = dataSigBytes / blockSizeBytes; 8597 if (doFlush) { 8598 // Round up to include partial blocks 8599 nBlocksReady = Math.ceil(nBlocksReady); 8600 } else { 8601 // Round down to include only full blocks, 8602 // less the number of blocks that must remain in the buffer 8603 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8604 } 8605 8606 // Count words ready 8607 var nWordsReady = nBlocksReady * blockSize; 8608 8609 // Count bytes ready 8610 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8611 8612 // Process blocks 8613 if (nWordsReady) { 8614 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8615 // Perform concrete-algorithm logic 8616 this._doProcessBlock(dataWords, offset); 8617 } 8618 8619 // Remove processed words 8620 var processedWords = dataWords.splice(0, nWordsReady); 8621 data.sigBytes -= nBytesReady; 8622 } 8623 8624 // Return processed words 8625 return new WordArray.init(processedWords, nBytesReady); 8626 }, 8627 8628 /** 8629 * Creates a copy of this object. 8630 * 8631 * @return {Object} The clone. 8632 * 8633 * @example 8634 * 8635 * var clone = bufferedBlockAlgorithm.clone(); 8636 */ 8637 clone: function() { 8638 var clone = Base.clone.call(this); 8639 clone._data = this._data.clone(); 8640 8641 return clone; 8642 }, 8643 8644 _minBufferSize: 0 8645 }); 8646 8647 /** 8648 * Abstract hasher template. 8649 * 8650 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8651 */ 8652 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8653 /** 8654 * Configuration options. 8655 */ 8656 cfg: Base.extend(), 8657 8658 /** 8659 * Initializes a newly created hasher. 8660 * 8661 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8662 * 8663 * @example 8664 * 8665 * var hasher = CryptoJS.algo.SHA256.create(); 8666 */ 8667 init: function(cfg) { 8668 // Apply config defaults 8669 this.cfg = this.cfg.extend(cfg); 8670 8671 // Set initial values 8672 this.reset(); 8673 }, 8674 8675 /** 8676 * Resets this hasher to its initial state. 8677 * 8678 * @example 8679 * 8680 * hasher.reset(); 8681 */ 8682 reset: function() { 8683 // Reset data buffer 8684 BufferedBlockAlgorithm.reset.call(this); 8685 8686 // Perform concrete-hasher logic 8687 this._doReset(); 8688 }, 8689 8690 /** 8691 * Updates this hasher with a message. 8692 * 8693 * @param {WordArray|string} messageUpdate The message to append. 8694 * 8695 * @return {Hasher} This hasher. 8696 * 8697 * @example 8698 * 8699 * hasher.update('message'); 8700 * hasher.update(wordArray); 8701 */ 8702 update: function(messageUpdate) { 8703 // Append 8704 this._append(messageUpdate); 8705 8706 // Update the hash 8707 this._process(); 8708 8709 // Chainable 8710 return this; 8711 }, 8712 8713 /** 8714 * Finalizes the hash computation. 8715 * Note that the finalize operation is effectively a destructive, read-once operation. 8716 * 8717 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8718 * 8719 * @return {WordArray} The hash. 8720 * 8721 * @example 8722 * 8723 * var hash = hasher.finalize(); 8724 * var hash = hasher.finalize('message'); 8725 * var hash = hasher.finalize(wordArray); 8726 */ 8727 finalize: function(messageUpdate) { 8728 // Final message update 8729 if (messageUpdate) { 8730 this._append(messageUpdate); 8731 } 8732 8733 // Perform concrete-hasher logic 8734 var hash = this._doFinalize(); 8735 8736 return hash; 8737 }, 8738 8739 blockSize: 512 / 32, 8740 8741 /** 8742 * Creates a shortcut function to a hasher's object interface. 8743 * 8744 * @param {Hasher} hasher The hasher to create a helper for. 8745 * 8746 * @return {Function} The shortcut function. 8747 * 8748 * @static 8749 * 8750 * @example 8751 * 8752 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8753 */ 8754 _createHelper: function(hasher) { 8755 return function(message, cfg) { 8756 return new hasher.init(cfg).finalize(message); 8757 }; 8758 }, 8759 8760 /** 8761 * Creates a shortcut function to the HMAC's object interface. 8762 * 8763 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8764 * 8765 * @return {Function} The shortcut function. 8766 * 8767 * @static 8768 * 8769 * @example 8770 * 8771 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8772 */ 8773 _createHmacHelper: function(hasher) { 8774 return function(message, key) { 8775 return new C_algo.HMAC.init(hasher, key).finalize(message); 8776 }; 8777 } 8778 }); 8779 8780 /** 8781 * Algorithm namespace. 8782 */ 8783 var C_algo = C.algo = {}; 8784 8785 return C; 8786 }(Math)); 8787 8788 8789 return CryptoJS; 8790 8791 })); 8792 }, {}], 8793 54: [function(require, module, exports) {; 8794 (function(root, factory) { 8795 if (typeof exports === "object") { 8796 // CommonJS 8797 module.exports = exports = factory(require("./core")); 8798 } else if (typeof define === "function" && define.amd) { 8799 // AMD 8800 define(["./core"], factory); 8801 } else { 8802 // Global (browser) 8803 factory(root.CryptoJS); 8804 } 8805 }(this, function(CryptoJS) { 8806 8807 (function() { 8808 // Shortcuts 8809 var C = CryptoJS; 8810 var C_lib = C.lib; 8811 var WordArray = C_lib.WordArray; 8812 var C_enc = C.enc; 8813 8814 /** 8815 * Base64 encoding strategy. 8816 */ 8817 var Base64 = C_enc.Base64 = { 8818 /** 8819 * Converts a word array to a Base64 string. 8820 * 8821 * @param {WordArray} wordArray The word array. 8822 * 8823 * @return {string} The Base64 string. 8824 * 8825 * @static 8826 * 8827 * @example 8828 * 8829 * var base64String = CryptoJS.enc.Base64.stringify(wordArray); 8830 */ 8831 stringify: function(wordArray) { 8832 // Shortcuts 8833 var words = wordArray.words; 8834 var sigBytes = wordArray.sigBytes; 8835 var map = this._map; 8836 8837 // Clamp excess bits 8838 wordArray.clamp(); 8839 8840 // Convert 8841 var base64Chars = []; 8842 for (var i = 0; i < sigBytes; i += 3) { 8843 var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8844 var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; 8845 var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; 8846 8847 var triplet = (byte1 << 16) | (byte2 << 8) | byte3; 8848 8849 for (var j = 0; 8850 (j < 4) && (i + j * 0.75 < sigBytes); j++) { 8851 base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); 8852 } 8853 } 8854 8855 // Add padding 8856 var paddingChar = map.charAt(64); 8857 if (paddingChar) { 8858 while (base64Chars.length % 4) { 8859 base64Chars.push(paddingChar); 8860 } 8861 } 8862 8863 return base64Chars.join(''); 8864 }, 8865 8866 /** 8867 * Converts a Base64 string to a word array. 8868 * 8869 * @param {string} base64Str The Base64 string. 8870 * 8871 * @return {WordArray} The word array. 8872 * 8873 * @static 8874 * 8875 * @example 8876 * 8877 * var wordArray = CryptoJS.enc.Base64.parse(base64String); 8878 */ 8879 parse: function(base64Str) { 8880 // Shortcuts 8881 var base64StrLength = base64Str.length; 8882 var map = this._map; 8883 var reverseMap = this._reverseMap; 8884 8885 if (!reverseMap) { 8886 reverseMap = this._reverseMap = []; 8887 for (var j = 0; j < map.length; j++) { 8888 reverseMap[map.charCodeAt(j)] = j; 8889 } 8890 } 8891 8892 // Ignore padding 8893 var paddingChar = map.charAt(64); 8894 if (paddingChar) { 8895 var paddingIndex = base64Str.indexOf(paddingChar); 8896 if (paddingIndex !== -1) { 8897 base64StrLength = paddingIndex; 8898 } 8899 } 8900 8901 // Convert 8902 return parseLoop(base64Str, base64StrLength, reverseMap); 8903 8904 }, 8905 8906 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' 8907 }; 8908 8909 function parseLoop(base64Str, base64StrLength, reverseMap) { 8910 var words = []; 8911 var nBytes = 0; 8912 for (var i = 0; i < base64StrLength; i++) { 8913 if (i % 4) { 8914 var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); 8915 var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); 8916 words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); 8917 nBytes++; 8918 } 8919 } 8920 return WordArray.create(words, nBytes); 8921 } 8922 }()); 8923 8924 8925 return CryptoJS.enc.Base64; 8926 8927 })); 8928 }, { 8929 "./core": 53 8930 }], 8931 55: [function(require, module, exports) {; 8932 (function(root, factory) { 8933 if (typeof exports === "object") { 8934 // CommonJS 8935 module.exports = exports = factory(require("./core")); 8936 } else if (typeof define === "function" && define.amd) { 8937 // AMD 8938 define(["./core"], factory); 8939 } else { 8940 // Global (browser) 8941 factory(root.CryptoJS); 8942 } 8943 }(this, function(CryptoJS) { 8944 8945 (function() { 8946 // Shortcuts 8947 var C = CryptoJS; 8948 var C_lib = C.lib; 8949 var WordArray = C_lib.WordArray; 8950 var C_enc = C.enc; 8951 8952 /** 8953 * UTF-16 BE encoding strategy. 8954 */ 8955 var Utf16BE = C_enc.Utf16 = C_enc.Utf16BE = { 8956 /** 8957 * Converts a word array to a UTF-16 BE string. 8958 * 8959 * @param {WordArray} wordArray The word array. 8960 * 8961 * @return {string} The UTF-16 BE string. 8962 * 8963 * @static 8964 * 8965 * @example 8966 * 8967 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray); 8968 */ 8969 stringify: function(wordArray) { 8970 // Shortcuts 8971 var words = wordArray.words; 8972 var sigBytes = wordArray.sigBytes; 8973 8974 // Convert 8975 var utf16Chars = []; 8976 for (var i = 0; i < sigBytes; i += 2) { 8977 var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; 8978 utf16Chars.push(String.fromCharCode(codePoint)); 8979 } 8980 8981 return utf16Chars.join(''); 8982 }, 8983 8984 /** 8985 * Converts a UTF-16 BE string to a word array. 8986 * 8987 * @param {string} utf16Str The UTF-16 BE string. 8988 * 8989 * @return {WordArray} The word array. 8990 * 8991 * @static 8992 * 8993 * @example 8994 * 8995 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String); 8996 */ 8997 parse: function(utf16Str) { 8998 // Shortcut 8999 var utf16StrLength = utf16Str.length; 9000 9001 // Convert 9002 var words = []; 9003 for (var i = 0; i < utf16StrLength; i++) { 9004 words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); 9005 } 9006 9007 return WordArray.create(words, utf16StrLength * 2); 9008 } 9009 }; 9010 9011 /** 9012 * UTF-16 LE encoding strategy. 9013 */ 9014 C_enc.Utf16LE = { 9015 /** 9016 * Converts a word array to a UTF-16 LE string. 9017 * 9018 * @param {WordArray} wordArray The word array. 9019 * 9020 * @return {string} The UTF-16 LE string. 9021 * 9022 * @static 9023 * 9024 * @example 9025 * 9026 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray); 9027 */ 9028 stringify: function(wordArray) { 9029 // Shortcuts 9030 var words = wordArray.words; 9031 var sigBytes = wordArray.sigBytes; 9032 9033 // Convert 9034 var utf16Chars = []; 9035 for (var i = 0; i < sigBytes; i += 2) { 9036 var codePoint = swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); 9037 utf16Chars.push(String.fromCharCode(codePoint)); 9038 } 9039 9040 return utf16Chars.join(''); 9041 }, 9042 9043 /** 9044 * Converts a UTF-16 LE string to a word array. 9045 * 9046 * @param {string} utf16Str The UTF-16 LE string. 9047 * 9048 * @return {WordArray} The word array. 9049 * 9050 * @static 9051 * 9052 * @example 9053 * 9054 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str); 9055 */ 9056 parse: function(utf16Str) { 9057 // Shortcut 9058 var utf16StrLength = utf16Str.length; 9059 9060 // Convert 9061 var words = []; 9062 for (var i = 0; i < utf16StrLength; i++) { 9063 words[i >>> 1] |= swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); 9064 } 9065 9066 return WordArray.create(words, utf16StrLength * 2); 9067 } 9068 }; 9069 9070 function swapEndian(word) { 9071 return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); 9072 } 9073 }()); 9074 9075 9076 return CryptoJS.enc.Utf16; 9077 9078 })); 9079 }, { 9080 "./core": 53 9081 }], 9082 56: [function(require, module, exports) {; 9083 (function(root, factory, undef) { 9084 if (typeof exports === "object") { 9085 // CommonJS 9086 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 9087 } else if (typeof define === "function" && define.amd) { 9088 // AMD 9089 define(["./core", "./sha1", "./hmac"], factory); 9090 } else { 9091 // Global (browser) 9092 factory(root.CryptoJS); 9093 } 9094 }(this, function(CryptoJS) { 9095 9096 (function() { 9097 // Shortcuts 9098 var C = CryptoJS; 9099 var C_lib = C.lib; 9100 var Base = C_lib.Base; 9101 var WordArray = C_lib.WordArray; 9102 var C_algo = C.algo; 9103 var MD5 = C_algo.MD5; 9104 9105 /** 9106 * This key derivation function is meant to conform with EVP_BytesToKey. 9107 * www.openssl.org/docs/crypto/EVP_BytesToKey.html 9108 */ 9109 var EvpKDF = C_algo.EvpKDF = Base.extend({ 9110 /** 9111 * Configuration options. 9112 * 9113 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 9114 * @property {Hasher} hasher The hash algorithm to use. Default: MD5 9115 * @property {number} iterations The number of iterations to perform. Default: 1 9116 */ 9117 cfg: Base.extend({ 9118 keySize: 128 / 32, 9119 hasher: MD5, 9120 iterations: 1 9121 }), 9122 9123 /** 9124 * Initializes a newly created key derivation function. 9125 * 9126 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 9127 * 9128 * @example 9129 * 9130 * var kdf = CryptoJS.algo.EvpKDF.create(); 9131 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 }); 9132 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 }); 9133 */ 9134 init: function(cfg) { 9135 this.cfg = this.cfg.extend(cfg); 9136 }, 9137 9138 /** 9139 * Derives a key from a password. 9140 * 9141 * @param {WordArray|string} password The password. 9142 * @param {WordArray|string} salt A salt. 9143 * 9144 * @return {WordArray} The derived key. 9145 * 9146 * @example 9147 * 9148 * var key = kdf.compute(password, salt); 9149 */ 9150 compute: function(password, salt) { 9151 // Shortcut 9152 var cfg = this.cfg; 9153 9154 // Init hasher 9155 var hasher = cfg.hasher.create(); 9156 9157 // Initial values 9158 var derivedKey = WordArray.create(); 9159 9160 // Shortcuts 9161 var derivedKeyWords = derivedKey.words; 9162 var keySize = cfg.keySize; 9163 var iterations = cfg.iterations; 9164 9165 // Generate key 9166 while (derivedKeyWords.length < keySize) { 9167 if (block) { 9168 hasher.update(block); 9169 } 9170 var block = hasher.update(password).finalize(salt); 9171 hasher.reset(); 9172 9173 // Iterations 9174 for (var i = 1; i < iterations; i++) { 9175 block = hasher.finalize(block); 9176 hasher.reset(); 9177 } 9178 9179 derivedKey.concat(block); 9180 } 9181 derivedKey.sigBytes = keySize * 4; 9182 9183 return derivedKey; 9184 } 9185 }); 9186 9187 /** 9188 * Derives a key from a password. 9189 * 9190 * @param {WordArray|string} password The password. 9191 * @param {WordArray|string} salt A salt. 9192 * @param {Object} cfg (Optional) The configuration options to use for this computation. 9193 * 9194 * @return {WordArray} The derived key. 9195 * 9196 * @static 9197 * 9198 * @example 9199 * 9200 * var key = CryptoJS.EvpKDF(password, salt); 9201 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 }); 9202 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 }); 9203 */ 9204 C.EvpKDF = function(password, salt, cfg) { 9205 return EvpKDF.create(cfg).compute(password, salt); 9206 }; 9207 }()); 9208 9209 9210 return CryptoJS.EvpKDF; 9211 9212 })); 9213 }, { 9214 "./core": 53, 9215 "./hmac": 58, 9216 "./sha1": 77 9217 }], 9218 57: [function(require, module, exports) {; 9219 (function(root, factory, undef) { 9220 if (typeof exports === "object") { 9221 // CommonJS 9222 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9223 } else if (typeof define === "function" && define.amd) { 9224 // AMD 9225 define(["./core", "./cipher-core"], factory); 9226 } else { 9227 // Global (browser) 9228 factory(root.CryptoJS); 9229 } 9230 }(this, function(CryptoJS) { 9231 9232 (function(undefined) { 9233 // Shortcuts 9234 var C = CryptoJS; 9235 var C_lib = C.lib; 9236 var CipherParams = C_lib.CipherParams; 9237 var C_enc = C.enc; 9238 var Hex = C_enc.Hex; 9239 var C_format = C.format; 9240 9241 var HexFormatter = C_format.Hex = { 9242 /** 9243 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string. 9244 * 9245 * @param {CipherParams} cipherParams The cipher params object. 9246 * 9247 * @return {string} The hexadecimally encoded string. 9248 * 9249 * @static 9250 * 9251 * @example 9252 * 9253 * var hexString = CryptoJS.format.Hex.stringify(cipherParams); 9254 */ 9255 stringify: function(cipherParams) { 9256 return cipherParams.ciphertext.toString(Hex); 9257 }, 9258 9259 /** 9260 * Converts a hexadecimally encoded ciphertext string to a cipher params object. 9261 * 9262 * @param {string} input The hexadecimally encoded string. 9263 * 9264 * @return {CipherParams} The cipher params object. 9265 * 9266 * @static 9267 * 9268 * @example 9269 * 9270 * var cipherParams = CryptoJS.format.Hex.parse(hexString); 9271 */ 9272 parse: function(input) { 9273 var ciphertext = Hex.parse(input); 9274 return CipherParams.create({ 9275 ciphertext: ciphertext 9276 }); 9277 } 9278 }; 9279 }()); 9280 9281 9282 return CryptoJS.format.Hex; 9283 9284 })); 9285 }, { 9286 "./cipher-core": 52, 9287 "./core": 53 9288 }], 9289 58: [function(require, module, exports) {; 9290 (function(root, factory) { 9291 if (typeof exports === "object") { 9292 // CommonJS 9293 module.exports = exports = factory(require("./core")); 9294 } else if (typeof define === "function" && define.amd) { 9295 // AMD 9296 define(["./core"], factory); 9297 } else { 9298 // Global (browser) 9299 factory(root.CryptoJS); 9300 } 9301 }(this, function(CryptoJS) { 9302 9303 (function() { 9304 // Shortcuts 9305 var C = CryptoJS; 9306 var C_lib = C.lib; 9307 var Base = C_lib.Base; 9308 var C_enc = C.enc; 9309 var Utf8 = C_enc.Utf8; 9310 var C_algo = C.algo; 9311 9312 /** 9313 * HMAC algorithm. 9314 */ 9315 var HMAC = C_algo.HMAC = Base.extend({ 9316 /** 9317 * Initializes a newly created HMAC. 9318 * 9319 * @param {Hasher} hasher The hash algorithm to use. 9320 * @param {WordArray|string} key The secret key. 9321 * 9322 * @example 9323 * 9324 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); 9325 */ 9326 init: function(hasher, key) { 9327 // Init hasher 9328 hasher = this._hasher = new hasher.init(); 9329 9330 // Convert string to WordArray, else assume WordArray already 9331 if (typeof key == 'string') { 9332 key = Utf8.parse(key); 9333 } 9334 9335 // Shortcuts 9336 var hasherBlockSize = hasher.blockSize; 9337 var hasherBlockSizeBytes = hasherBlockSize * 4; 9338 9339 // Allow arbitrary length keys 9340 if (key.sigBytes > hasherBlockSizeBytes) { 9341 key = hasher.finalize(key); 9342 } 9343 9344 // Clamp excess bits 9345 key.clamp(); 9346 9347 // Clone key for inner and outer pads 9348 var oKey = this._oKey = key.clone(); 9349 var iKey = this._iKey = key.clone(); 9350 9351 // Shortcuts 9352 var oKeyWords = oKey.words; 9353 var iKeyWords = iKey.words; 9354 9355 // XOR keys with pad constants 9356 for (var i = 0; i < hasherBlockSize; i++) { 9357 oKeyWords[i] ^= 0x5c5c5c5c; 9358 iKeyWords[i] ^= 0x36363636; 9359 } 9360 oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; 9361 9362 // Set initial values 9363 this.reset(); 9364 }, 9365 9366 /** 9367 * Resets this HMAC to its initial state. 9368 * 9369 * @example 9370 * 9371 * hmacHasher.reset(); 9372 */ 9373 reset: function() { 9374 // Shortcut 9375 var hasher = this._hasher; 9376 9377 // Reset 9378 hasher.reset(); 9379 hasher.update(this._iKey); 9380 }, 9381 9382 /** 9383 * Updates this HMAC with a message. 9384 * 9385 * @param {WordArray|string} messageUpdate The message to append. 9386 * 9387 * @return {HMAC} This HMAC instance. 9388 * 9389 * @example 9390 * 9391 * hmacHasher.update('message'); 9392 * hmacHasher.update(wordArray); 9393 */ 9394 update: function(messageUpdate) { 9395 this._hasher.update(messageUpdate); 9396 9397 // Chainable 9398 return this; 9399 }, 9400 9401 /** 9402 * Finalizes the HMAC computation. 9403 * Note that the finalize operation is effectively a destructive, read-once operation. 9404 * 9405 * @param {WordArray|string} messageUpdate (Optional) A final message update. 9406 * 9407 * @return {WordArray} The HMAC. 9408 * 9409 * @example 9410 * 9411 * var hmac = hmacHasher.finalize(); 9412 * var hmac = hmacHasher.finalize('message'); 9413 * var hmac = hmacHasher.finalize(wordArray); 9414 */ 9415 finalize: function(messageUpdate) { 9416 // Shortcut 9417 var hasher = this._hasher; 9418 9419 // Compute HMAC 9420 var innerHash = hasher.finalize(messageUpdate); 9421 hasher.reset(); 9422 var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); 9423 9424 return hmac; 9425 } 9426 }); 9427 }()); 9428 9429 9430 })); 9431 }, { 9432 "./core": 53 9433 }], 9434 59: [function(require, module, exports) {; 9435 (function(root, factory, undef) { 9436 if (typeof exports === "object") { 9437 // CommonJS 9438 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")); 9439 } else if (typeof define === "function" && define.amd) { 9440 // AMD 9441 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); 9442 } else { 9443 // Global (browser) 9444 root.CryptoJS = factory(root.CryptoJS); 9445 } 9446 }(this, function(CryptoJS) { 9447 9448 return CryptoJS; 9449 9450 })); 9451 }, { 9452 "./aes": 51, 9453 "./cipher-core": 52, 9454 "./core": 53, 9455 "./enc-base64": 54, 9456 "./enc-utf16": 55, 9457 "./evpkdf": 56, 9458 "./format-hex": 57, 9459 "./hmac": 58, 9460 "./lib-typedarrays": 60, 9461 "./md5": 61, 9462 "./mode-cfb": 62, 9463 "./mode-ctr": 64, 9464 "./mode-ctr-gladman": 63, 9465 "./mode-ecb": 65, 9466 "./mode-ofb": 66, 9467 "./pad-ansix923": 67, 9468 "./pad-iso10126": 68, 9469 "./pad-iso97971": 69, 9470 "./pad-nopadding": 70, 9471 "./pad-zeropadding": 71, 9472 "./pbkdf2": 72, 9473 "./rabbit": 74, 9474 "./rabbit-legacy": 73, 9475 "./rc4": 75, 9476 "./ripemd160": 76, 9477 "./sha1": 77, 9478 "./sha224": 78, 9479 "./sha256": 79, 9480 "./sha3": 80, 9481 "./sha384": 81, 9482 "./sha512": 82, 9483 "./tripledes": 83, 9484 "./x64-core": 84 9485 }], 9486 60: [function(require, module, exports) {; 9487 (function(root, factory) { 9488 if (typeof exports === "object") { 9489 // CommonJS 9490 module.exports = exports = factory(require("./core")); 9491 } else if (typeof define === "function" && define.amd) { 9492 // AMD 9493 define(["./core"], factory); 9494 } else { 9495 // Global (browser) 9496 factory(root.CryptoJS); 9497 } 9498 }(this, function(CryptoJS) { 9499 9500 (function() { 9501 // Check if typed arrays are supported 9502 if (typeof ArrayBuffer != 'function') { 9503 return; 9504 } 9505 9506 // Shortcuts 9507 var C = CryptoJS; 9508 var C_lib = C.lib; 9509 var WordArray = C_lib.WordArray; 9510 9511 // Reference original init 9512 var superInit = WordArray.init; 9513 9514 // Augment WordArray.init to handle typed arrays 9515 var subInit = WordArray.init = function(typedArray) { 9516 // Convert buffers to uint8 9517 if (typedArray instanceof ArrayBuffer) { 9518 typedArray = new Uint8Array(typedArray); 9519 } 9520 9521 // Convert other array views to uint8 9522 if ( 9523 typedArray instanceof Int8Array || 9524 (typeof Uint8ClampedArray !== "undefined" && typedArray instanceof Uint8ClampedArray) || 9525 typedArray instanceof Int16Array || 9526 typedArray instanceof Uint16Array || 9527 typedArray instanceof Int32Array || 9528 typedArray instanceof Uint32Array || 9529 typedArray instanceof Float32Array || 9530 typedArray instanceof Float64Array 9531 ) { 9532 typedArray = new Uint8Array(typedArray.buffer, typedArray.byteOffset, typedArray.byteLength); 9533 } 9534 9535 // Handle Uint8Array 9536 if (typedArray instanceof Uint8Array) { 9537 // Shortcut 9538 var typedArrayByteLength = typedArray.byteLength; 9539 9540 // Extract bytes 9541 var words = []; 9542 for (var i = 0; i < typedArrayByteLength; i++) { 9543 words[i >>> 2] |= typedArray[i] << (24 - (i % 4) * 8); 9544 } 9545 9546 // Initialize this word array 9547 superInit.call(this, words, typedArrayByteLength); 9548 } else { 9549 // Else call normal init 9550 superInit.apply(this, arguments); 9551 } 9552 }; 9553 9554 subInit.prototype = WordArray; 9555 }()); 9556 9557 9558 return CryptoJS.lib.WordArray; 9559 9560 })); 9561 }, { 9562 "./core": 53 9563 }], 9564 61: [function(require, module, exports) {; 9565 (function(root, factory) { 9566 if (typeof exports === "object") { 9567 // CommonJS 9568 module.exports = exports = factory(require("./core")); 9569 } else if (typeof define === "function" && define.amd) { 9570 // AMD 9571 define(["./core"], factory); 9572 } else { 9573 // Global (browser) 9574 factory(root.CryptoJS); 9575 } 9576 }(this, function(CryptoJS) { 9577 9578 (function(Math) { 9579 // Shortcuts 9580 var C = CryptoJS; 9581 var C_lib = C.lib; 9582 var WordArray = C_lib.WordArray; 9583 var Hasher = C_lib.Hasher; 9584 var C_algo = C.algo; 9585 9586 // Constants table 9587 var T = []; 9588 9589 // Compute constants 9590 (function() { 9591 for (var i = 0; i < 64; i++) { 9592 T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; 9593 } 9594 }()); 9595 9596 /** 9597 * MD5 hash algorithm. 9598 */ 9599 var MD5 = C_algo.MD5 = Hasher.extend({ 9600 _doReset: function() { 9601 this._hash = new WordArray.init([ 9602 0x67452301, 0xefcdab89, 9603 0x98badcfe, 0x10325476 9604 ]); 9605 }, 9606 9607 _doProcessBlock: function(M, offset) { 9608 // Swap endian 9609 for (var i = 0; i < 16; i++) { 9610 // Shortcuts 9611 var offset_i = offset + i; 9612 var M_offset_i = M[offset_i]; 9613 9614 M[offset_i] = ( 9615 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 9616 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 9617 ); 9618 } 9619 9620 // Shortcuts 9621 var H = this._hash.words; 9622 9623 var M_offset_0 = M[offset + 0]; 9624 var M_offset_1 = M[offset + 1]; 9625 var M_offset_2 = M[offset + 2]; 9626 var M_offset_3 = M[offset + 3]; 9627 var M_offset_4 = M[offset + 4]; 9628 var M_offset_5 = M[offset + 5]; 9629 var M_offset_6 = M[offset + 6]; 9630 var M_offset_7 = M[offset + 7]; 9631 var M_offset_8 = M[offset + 8]; 9632 var M_offset_9 = M[offset + 9]; 9633 var M_offset_10 = M[offset + 10]; 9634 var M_offset_11 = M[offset + 11]; 9635 var M_offset_12 = M[offset + 12]; 9636 var M_offset_13 = M[offset + 13]; 9637 var M_offset_14 = M[offset + 14]; 9638 var M_offset_15 = M[offset + 15]; 9639 9640 // Working varialbes 9641 var a = H[0]; 9642 var b = H[1]; 9643 var c = H[2]; 9644 var d = H[3]; 9645 9646 // Computation 9647 a = FF(a, b, c, d, M_offset_0, 7, T[0]); 9648 d = FF(d, a, b, c, M_offset_1, 12, T[1]); 9649 c = FF(c, d, a, b, M_offset_2, 17, T[2]); 9650 b = FF(b, c, d, a, M_offset_3, 22, T[3]); 9651 a = FF(a, b, c, d, M_offset_4, 7, T[4]); 9652 d = FF(d, a, b, c, M_offset_5, 12, T[5]); 9653 c = FF(c, d, a, b, M_offset_6, 17, T[6]); 9654 b = FF(b, c, d, a, M_offset_7, 22, T[7]); 9655 a = FF(a, b, c, d, M_offset_8, 7, T[8]); 9656 d = FF(d, a, b, c, M_offset_9, 12, T[9]); 9657 c = FF(c, d, a, b, M_offset_10, 17, T[10]); 9658 b = FF(b, c, d, a, M_offset_11, 22, T[11]); 9659 a = FF(a, b, c, d, M_offset_12, 7, T[12]); 9660 d = FF(d, a, b, c, M_offset_13, 12, T[13]); 9661 c = FF(c, d, a, b, M_offset_14, 17, T[14]); 9662 b = FF(b, c, d, a, M_offset_15, 22, T[15]); 9663 9664 a = GG(a, b, c, d, M_offset_1, 5, T[16]); 9665 d = GG(d, a, b, c, M_offset_6, 9, T[17]); 9666 c = GG(c, d, a, b, M_offset_11, 14, T[18]); 9667 b = GG(b, c, d, a, M_offset_0, 20, T[19]); 9668 a = GG(a, b, c, d, M_offset_5, 5, T[20]); 9669 d = GG(d, a, b, c, M_offset_10, 9, T[21]); 9670 c = GG(c, d, a, b, M_offset_15, 14, T[22]); 9671 b = GG(b, c, d, a, M_offset_4, 20, T[23]); 9672 a = GG(a, b, c, d, M_offset_9, 5, T[24]); 9673 d = GG(d, a, b, c, M_offset_14, 9, T[25]); 9674 c = GG(c, d, a, b, M_offset_3, 14, T[26]); 9675 b = GG(b, c, d, a, M_offset_8, 20, T[27]); 9676 a = GG(a, b, c, d, M_offset_13, 5, T[28]); 9677 d = GG(d, a, b, c, M_offset_2, 9, T[29]); 9678 c = GG(c, d, a, b, M_offset_7, 14, T[30]); 9679 b = GG(b, c, d, a, M_offset_12, 20, T[31]); 9680 9681 a = HH(a, b, c, d, M_offset_5, 4, T[32]); 9682 d = HH(d, a, b, c, M_offset_8, 11, T[33]); 9683 c = HH(c, d, a, b, M_offset_11, 16, T[34]); 9684 b = HH(b, c, d, a, M_offset_14, 23, T[35]); 9685 a = HH(a, b, c, d, M_offset_1, 4, T[36]); 9686 d = HH(d, a, b, c, M_offset_4, 11, T[37]); 9687 c = HH(c, d, a, b, M_offset_7, 16, T[38]); 9688 b = HH(b, c, d, a, M_offset_10, 23, T[39]); 9689 a = HH(a, b, c, d, M_offset_13, 4, T[40]); 9690 d = HH(d, a, b, c, M_offset_0, 11, T[41]); 9691 c = HH(c, d, a, b, M_offset_3, 16, T[42]); 9692 b = HH(b, c, d, a, M_offset_6, 23, T[43]); 9693 a = HH(a, b, c, d, M_offset_9, 4, T[44]); 9694 d = HH(d, a, b, c, M_offset_12, 11, T[45]); 9695 c = HH(c, d, a, b, M_offset_15, 16, T[46]); 9696 b = HH(b, c, d, a, M_offset_2, 23, T[47]); 9697 9698 a = II(a, b, c, d, M_offset_0, 6, T[48]); 9699 d = II(d, a, b, c, M_offset_7, 10, T[49]); 9700 c = II(c, d, a, b, M_offset_14, 15, T[50]); 9701 b = II(b, c, d, a, M_offset_5, 21, T[51]); 9702 a = II(a, b, c, d, M_offset_12, 6, T[52]); 9703 d = II(d, a, b, c, M_offset_3, 10, T[53]); 9704 c = II(c, d, a, b, M_offset_10, 15, T[54]); 9705 b = II(b, c, d, a, M_offset_1, 21, T[55]); 9706 a = II(a, b, c, d, M_offset_8, 6, T[56]); 9707 d = II(d, a, b, c, M_offset_15, 10, T[57]); 9708 c = II(c, d, a, b, M_offset_6, 15, T[58]); 9709 b = II(b, c, d, a, M_offset_13, 21, T[59]); 9710 a = II(a, b, c, d, M_offset_4, 6, T[60]); 9711 d = II(d, a, b, c, M_offset_11, 10, T[61]); 9712 c = II(c, d, a, b, M_offset_2, 15, T[62]); 9713 b = II(b, c, d, a, M_offset_9, 21, T[63]); 9714 9715 // Intermediate hash value 9716 H[0] = (H[0] + a) | 0; 9717 H[1] = (H[1] + b) | 0; 9718 H[2] = (H[2] + c) | 0; 9719 H[3] = (H[3] + d) | 0; 9720 }, 9721 9722 _doFinalize: function() { 9723 // Shortcuts 9724 var data = this._data; 9725 var dataWords = data.words; 9726 9727 var nBitsTotal = this._nDataBytes * 8; 9728 var nBitsLeft = data.sigBytes * 8; 9729 9730 // Add padding 9731 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 9732 9733 var nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); 9734 var nBitsTotalL = nBitsTotal; 9735 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( 9736 (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | 9737 (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) 9738 ); 9739 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 9740 (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | 9741 (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) 9742 ); 9743 9744 data.sigBytes = (dataWords.length + 1) * 4; 9745 9746 // Hash final blocks 9747 this._process(); 9748 9749 // Shortcuts 9750 var hash = this._hash; 9751 var H = hash.words; 9752 9753 // Swap endian 9754 for (var i = 0; i < 4; i++) { 9755 // Shortcut 9756 var H_i = H[i]; 9757 9758 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 9759 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 9760 } 9761 9762 // Return final computed hash 9763 return hash; 9764 }, 9765 9766 clone: function() { 9767 var clone = Hasher.clone.call(this); 9768 clone._hash = this._hash.clone(); 9769 9770 return clone; 9771 } 9772 }); 9773 9774 function FF(a, b, c, d, x, s, t) { 9775 var n = a + ((b & c) | (~b & d)) + x + t; 9776 return ((n << s) | (n >>> (32 - s))) + b; 9777 } 9778 9779 function GG(a, b, c, d, x, s, t) { 9780 var n = a + ((b & d) | (c & ~d)) + x + t; 9781 return ((n << s) | (n >>> (32 - s))) + b; 9782 } 9783 9784 function HH(a, b, c, d, x, s, t) { 9785 var n = a + (b ^ c ^ d) + x + t; 9786 return ((n << s) | (n >>> (32 - s))) + b; 9787 } 9788 9789 function II(a, b, c, d, x, s, t) { 9790 var n = a + (c ^ (b | ~d)) + x + t; 9791 return ((n << s) | (n >>> (32 - s))) + b; 9792 } 9793 9794 /** 9795 * Shortcut function to the hasher's object interface. 9796 * 9797 * @param {WordArray|string} message The message to hash. 9798 * 9799 * @return {WordArray} The hash. 9800 * 9801 * @static 9802 * 9803 * @example 9804 * 9805 * var hash = CryptoJS.MD5('message'); 9806 * var hash = CryptoJS.MD5(wordArray); 9807 */ 9808 C.MD5 = Hasher._createHelper(MD5); 9809 9810 /** 9811 * Shortcut function to the HMAC's object interface. 9812 * 9813 * @param {WordArray|string} message The message to hash. 9814 * @param {WordArray|string} key The secret key. 9815 * 9816 * @return {WordArray} The HMAC. 9817 * 9818 * @static 9819 * 9820 * @example 9821 * 9822 * var hmac = CryptoJS.HmacMD5(message, key); 9823 */ 9824 C.HmacMD5 = Hasher._createHmacHelper(MD5); 9825 }(Math)); 9826 9827 9828 return CryptoJS.MD5; 9829 9830 })); 9831 }, { 9832 "./core": 53 9833 }], 9834 62: [function(require, module, exports) {; 9835 (function(root, factory, undef) { 9836 if (typeof exports === "object") { 9837 // CommonJS 9838 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9839 } else if (typeof define === "function" && define.amd) { 9840 // AMD 9841 define(["./core", "./cipher-core"], factory); 9842 } else { 9843 // Global (browser) 9844 factory(root.CryptoJS); 9845 } 9846 }(this, function(CryptoJS) { 9847 9848 /** 9849 * Cipher Feedback block mode. 9850 */ 9851 CryptoJS.mode.CFB = (function() { 9852 var CFB = CryptoJS.lib.BlockCipherMode.extend(); 9853 9854 CFB.Encryptor = CFB.extend({ 9855 processBlock: function(words, offset) { 9856 // Shortcuts 9857 var cipher = this._cipher; 9858 var blockSize = cipher.blockSize; 9859 9860 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9861 9862 // Remember this block to use with next block 9863 this._prevBlock = words.slice(offset, offset + blockSize); 9864 } 9865 }); 9866 9867 CFB.Decryptor = CFB.extend({ 9868 processBlock: function(words, offset) { 9869 // Shortcuts 9870 var cipher = this._cipher; 9871 var blockSize = cipher.blockSize; 9872 9873 // Remember this block to use with next block 9874 var thisBlock = words.slice(offset, offset + blockSize); 9875 9876 generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); 9877 9878 // This block becomes the previous block 9879 this._prevBlock = thisBlock; 9880 } 9881 }); 9882 9883 function generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { 9884 // Shortcut 9885 var iv = this._iv; 9886 9887 // Generate keystream 9888 if (iv) { 9889 var keystream = iv.slice(0); 9890 9891 // Remove IV for subsequent blocks 9892 this._iv = undefined; 9893 } else { 9894 var keystream = this._prevBlock; 9895 } 9896 cipher.encryptBlock(keystream, 0); 9897 9898 // Encrypt 9899 for (var i = 0; i < blockSize; i++) { 9900 words[offset + i] ^= keystream[i]; 9901 } 9902 } 9903 9904 return CFB; 9905 }()); 9906 9907 9908 return CryptoJS.mode.CFB; 9909 9910 })); 9911 }, { 9912 "./cipher-core": 52, 9913 "./core": 53 9914 }], 9915 63: [function(require, module, exports) {; 9916 (function(root, factory, undef) { 9917 if (typeof exports === "object") { 9918 // CommonJS 9919 module.exports = exports = factory(require("./core"), require("./cipher-core")); 9920 } else if (typeof define === "function" && define.amd) { 9921 // AMD 9922 define(["./core", "./cipher-core"], factory); 9923 } else { 9924 // Global (browser) 9925 factory(root.CryptoJS); 9926 } 9927 }(this, function(CryptoJS) { 9928 9929 /** @preserve 9930 * Counter block mode compatible with Dr Brian Gladman fileenc.c 9931 * derived from CryptoJS.mode.CTR 9932 * Jan Hruby jhruby.web@gmail.com 9933 */ 9934 CryptoJS.mode.CTRGladman = (function() { 9935 var CTRGladman = CryptoJS.lib.BlockCipherMode.extend(); 9936 9937 function incWord(word) { 9938 if (((word >> 24) & 0xff) === 0xff) { //overflow 9939 var b1 = (word >> 16) & 0xff; 9940 var b2 = (word >> 8) & 0xff; 9941 var b3 = word & 0xff; 9942 9943 if (b1 === 0xff) // overflow b1 9944 { 9945 b1 = 0; 9946 if (b2 === 0xff) { 9947 b2 = 0; 9948 if (b3 === 0xff) { 9949 b3 = 0; 9950 } else { 9951 ++b3; 9952 } 9953 } else { 9954 ++b2; 9955 } 9956 } else { 9957 ++b1; 9958 } 9959 9960 word = 0; 9961 word += (b1 << 16); 9962 word += (b2 << 8); 9963 word += b3; 9964 } else { 9965 word += (0x01 << 24); 9966 } 9967 return word; 9968 } 9969 9970 function incCounter(counter) { 9971 if ((counter[0] = incWord(counter[0])) === 0) { 9972 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 9973 counter[1] = incWord(counter[1]); 9974 } 9975 return counter; 9976 } 9977 9978 var Encryptor = CTRGladman.Encryptor = CTRGladman.extend({ 9979 processBlock: function(words, offset) { 9980 // Shortcuts 9981 var cipher = this._cipher 9982 var blockSize = cipher.blockSize; 9983 var iv = this._iv; 9984 var counter = this._counter; 9985 9986 // Generate keystream 9987 if (iv) { 9988 counter = this._counter = iv.slice(0); 9989 9990 // Remove IV for subsequent blocks 9991 this._iv = undefined; 9992 } 9993 9994 incCounter(counter); 9995 9996 var keystream = counter.slice(0); 9997 cipher.encryptBlock(keystream, 0); 9998 9999 // Encrypt 10000 for (var i = 0; i < blockSize; i++) { 10001 words[offset + i] ^= keystream[i]; 10002 } 10003 } 10004 }); 10005 10006 CTRGladman.Decryptor = Encryptor; 10007 10008 return CTRGladman; 10009 }()); 10010 10011 10012 10013 return CryptoJS.mode.CTRGladman; 10014 10015 })); 10016 }, { 10017 "./cipher-core": 52, 10018 "./core": 53 10019 }], 10020 64: [function(require, module, exports) {; 10021 (function(root, factory, undef) { 10022 if (typeof exports === "object") { 10023 // CommonJS 10024 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10025 } else if (typeof define === "function" && define.amd) { 10026 // AMD 10027 define(["./core", "./cipher-core"], factory); 10028 } else { 10029 // Global (browser) 10030 factory(root.CryptoJS); 10031 } 10032 }(this, function(CryptoJS) { 10033 10034 /** 10035 * Counter block mode. 10036 */ 10037 CryptoJS.mode.CTR = (function() { 10038 var CTR = CryptoJS.lib.BlockCipherMode.extend(); 10039 10040 var Encryptor = CTR.Encryptor = CTR.extend({ 10041 processBlock: function(words, offset) { 10042 // Shortcuts 10043 var cipher = this._cipher 10044 var blockSize = cipher.blockSize; 10045 var iv = this._iv; 10046 var counter = this._counter; 10047 10048 // Generate keystream 10049 if (iv) { 10050 counter = this._counter = iv.slice(0); 10051 10052 // Remove IV for subsequent blocks 10053 this._iv = undefined; 10054 } 10055 var keystream = counter.slice(0); 10056 cipher.encryptBlock(keystream, 0); 10057 10058 // Increment counter 10059 counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 10060 10061 // Encrypt 10062 for (var i = 0; i < blockSize; i++) { 10063 words[offset + i] ^= keystream[i]; 10064 } 10065 } 10066 }); 10067 10068 CTR.Decryptor = Encryptor; 10069 10070 return CTR; 10071 }()); 10072 10073 10074 return CryptoJS.mode.CTR; 10075 10076 })); 10077 }, { 10078 "./cipher-core": 52, 10079 "./core": 53 10080 }], 10081 65: [function(require, module, exports) {; 10082 (function(root, factory, undef) { 10083 if (typeof exports === "object") { 10084 // CommonJS 10085 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10086 } else if (typeof define === "function" && define.amd) { 10087 // AMD 10088 define(["./core", "./cipher-core"], factory); 10089 } else { 10090 // Global (browser) 10091 factory(root.CryptoJS); 10092 } 10093 }(this, function(CryptoJS) { 10094 10095 /** 10096 * Electronic Codebook block mode. 10097 */ 10098 CryptoJS.mode.ECB = (function() { 10099 var ECB = CryptoJS.lib.BlockCipherMode.extend(); 10100 10101 ECB.Encryptor = ECB.extend({ 10102 processBlock: function(words, offset) { 10103 this._cipher.encryptBlock(words, offset); 10104 } 10105 }); 10106 10107 ECB.Decryptor = ECB.extend({ 10108 processBlock: function(words, offset) { 10109 this._cipher.decryptBlock(words, offset); 10110 } 10111 }); 10112 10113 return ECB; 10114 }()); 10115 10116 10117 return CryptoJS.mode.ECB; 10118 10119 })); 10120 }, { 10121 "./cipher-core": 52, 10122 "./core": 53 10123 }], 10124 66: [function(require, module, exports) {; 10125 (function(root, factory, undef) { 10126 if (typeof exports === "object") { 10127 // CommonJS 10128 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10129 } else if (typeof define === "function" && define.amd) { 10130 // AMD 10131 define(["./core", "./cipher-core"], factory); 10132 } else { 10133 // Global (browser) 10134 factory(root.CryptoJS); 10135 } 10136 }(this, function(CryptoJS) { 10137 10138 /** 10139 * Output Feedback block mode. 10140 */ 10141 CryptoJS.mode.OFB = (function() { 10142 var OFB = CryptoJS.lib.BlockCipherMode.extend(); 10143 10144 var Encryptor = OFB.Encryptor = OFB.extend({ 10145 processBlock: function(words, offset) { 10146 // Shortcuts 10147 var cipher = this._cipher 10148 var blockSize = cipher.blockSize; 10149 var iv = this._iv; 10150 var keystream = this._keystream; 10151 10152 // Generate keystream 10153 if (iv) { 10154 keystream = this._keystream = iv.slice(0); 10155 10156 // Remove IV for subsequent blocks 10157 this._iv = undefined; 10158 } 10159 cipher.encryptBlock(keystream, 0); 10160 10161 // Encrypt 10162 for (var i = 0; i < blockSize; i++) { 10163 words[offset + i] ^= keystream[i]; 10164 } 10165 } 10166 }); 10167 10168 OFB.Decryptor = Encryptor; 10169 10170 return OFB; 10171 }()); 10172 10173 10174 return CryptoJS.mode.OFB; 10175 10176 })); 10177 }, { 10178 "./cipher-core": 52, 10179 "./core": 53 10180 }], 10181 67: [function(require, module, exports) {; 10182 (function(root, factory, undef) { 10183 if (typeof exports === "object") { 10184 // CommonJS 10185 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10186 } else if (typeof define === "function" && define.amd) { 10187 // AMD 10188 define(["./core", "./cipher-core"], factory); 10189 } else { 10190 // Global (browser) 10191 factory(root.CryptoJS); 10192 } 10193 }(this, function(CryptoJS) { 10194 10195 /** 10196 * ANSI X.923 padding strategy. 10197 */ 10198 CryptoJS.pad.AnsiX923 = { 10199 pad: function(data, blockSize) { 10200 // Shortcuts 10201 var dataSigBytes = data.sigBytes; 10202 var blockSizeBytes = blockSize * 4; 10203 10204 // Count padding bytes 10205 var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; 10206 10207 // Compute last byte position 10208 var lastBytePos = dataSigBytes + nPaddingBytes - 1; 10209 10210 // Pad 10211 data.clamp(); 10212 data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); 10213 data.sigBytes += nPaddingBytes; 10214 }, 10215 10216 unpad: function(data) { 10217 // Get number of padding bytes from last byte 10218 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10219 10220 // Remove padding 10221 data.sigBytes -= nPaddingBytes; 10222 } 10223 }; 10224 10225 10226 return CryptoJS.pad.Ansix923; 10227 10228 })); 10229 }, { 10230 "./cipher-core": 52, 10231 "./core": 53 10232 }], 10233 68: [function(require, module, exports) {; 10234 (function(root, factory, undef) { 10235 if (typeof exports === "object") { 10236 // CommonJS 10237 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10238 } else if (typeof define === "function" && define.amd) { 10239 // AMD 10240 define(["./core", "./cipher-core"], factory); 10241 } else { 10242 // Global (browser) 10243 factory(root.CryptoJS); 10244 } 10245 }(this, function(CryptoJS) { 10246 10247 /** 10248 * ISO 10126 padding strategy. 10249 */ 10250 CryptoJS.pad.Iso10126 = { 10251 pad: function(data, blockSize) { 10252 // Shortcut 10253 var blockSizeBytes = blockSize * 4; 10254 10255 // Count padding bytes 10256 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 10257 10258 // Pad 10259 data.concat(CryptoJS.lib.WordArray.random(nPaddingBytes - 1)). 10260 concat(CryptoJS.lib.WordArray.create([nPaddingBytes << 24], 1)); 10261 }, 10262 10263 unpad: function(data) { 10264 // Get number of padding bytes from last byte 10265 var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; 10266 10267 // Remove padding 10268 data.sigBytes -= nPaddingBytes; 10269 } 10270 }; 10271 10272 10273 return CryptoJS.pad.Iso10126; 10274 10275 })); 10276 }, { 10277 "./cipher-core": 52, 10278 "./core": 53 10279 }], 10280 69: [function(require, module, exports) {; 10281 (function(root, factory, undef) { 10282 if (typeof exports === "object") { 10283 // CommonJS 10284 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10285 } else if (typeof define === "function" && define.amd) { 10286 // AMD 10287 define(["./core", "./cipher-core"], factory); 10288 } else { 10289 // Global (browser) 10290 factory(root.CryptoJS); 10291 } 10292 }(this, function(CryptoJS) { 10293 10294 /** 10295 * ISO/IEC 9797-1 Padding Method 2. 10296 */ 10297 CryptoJS.pad.Iso97971 = { 10298 pad: function(data, blockSize) { 10299 // Add 0x80 byte 10300 data.concat(CryptoJS.lib.WordArray.create([0x80000000], 1)); 10301 10302 // Zero pad the rest 10303 CryptoJS.pad.ZeroPadding.pad(data, blockSize); 10304 }, 10305 10306 unpad: function(data) { 10307 // Remove zero padding 10308 CryptoJS.pad.ZeroPadding.unpad(data); 10309 10310 // Remove one more byte -- the 0x80 byte 10311 data.sigBytes--; 10312 } 10313 }; 10314 10315 10316 return CryptoJS.pad.Iso97971; 10317 10318 })); 10319 }, { 10320 "./cipher-core": 52, 10321 "./core": 53 10322 }], 10323 70: [function(require, module, exports) {; 10324 (function(root, factory, undef) { 10325 if (typeof exports === "object") { 10326 // CommonJS 10327 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10328 } else if (typeof define === "function" && define.amd) { 10329 // AMD 10330 define(["./core", "./cipher-core"], factory); 10331 } else { 10332 // Global (browser) 10333 factory(root.CryptoJS); 10334 } 10335 }(this, function(CryptoJS) { 10336 10337 /** 10338 * A noop padding strategy. 10339 */ 10340 CryptoJS.pad.NoPadding = { 10341 pad: function() {}, 10342 10343 unpad: function() {} 10344 }; 10345 10346 10347 return CryptoJS.pad.NoPadding; 10348 10349 })); 10350 }, { 10351 "./cipher-core": 52, 10352 "./core": 53 10353 }], 10354 71: [function(require, module, exports) {; 10355 (function(root, factory, undef) { 10356 if (typeof exports === "object") { 10357 // CommonJS 10358 module.exports = exports = factory(require("./core"), require("./cipher-core")); 10359 } else if (typeof define === "function" && define.amd) { 10360 // AMD 10361 define(["./core", "./cipher-core"], factory); 10362 } else { 10363 // Global (browser) 10364 factory(root.CryptoJS); 10365 } 10366 }(this, function(CryptoJS) { 10367 10368 /** 10369 * Zero padding strategy. 10370 */ 10371 CryptoJS.pad.ZeroPadding = { 10372 pad: function(data, blockSize) { 10373 // Shortcut 10374 var blockSizeBytes = blockSize * 4; 10375 10376 // Pad 10377 data.clamp(); 10378 data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); 10379 }, 10380 10381 unpad: function(data) { 10382 // Shortcut 10383 var dataWords = data.words; 10384 10385 // Unpad 10386 var i = data.sigBytes - 1; 10387 while (!((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { 10388 i--; 10389 } 10390 data.sigBytes = i + 1; 10391 } 10392 }; 10393 10394 10395 return CryptoJS.pad.ZeroPadding; 10396 10397 })); 10398 }, { 10399 "./cipher-core": 52, 10400 "./core": 53 10401 }], 10402 72: [function(require, module, exports) {; 10403 (function(root, factory, undef) { 10404 if (typeof exports === "object") { 10405 // CommonJS 10406 module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); 10407 } else if (typeof define === "function" && define.amd) { 10408 // AMD 10409 define(["./core", "./sha1", "./hmac"], factory); 10410 } else { 10411 // Global (browser) 10412 factory(root.CryptoJS); 10413 } 10414 }(this, function(CryptoJS) { 10415 10416 (function() { 10417 // Shortcuts 10418 var C = CryptoJS; 10419 var C_lib = C.lib; 10420 var Base = C_lib.Base; 10421 var WordArray = C_lib.WordArray; 10422 var C_algo = C.algo; 10423 var SHA1 = C_algo.SHA1; 10424 var HMAC = C_algo.HMAC; 10425 10426 /** 10427 * Password-Based Key Derivation Function 2 algorithm. 10428 */ 10429 var PBKDF2 = C_algo.PBKDF2 = Base.extend({ 10430 /** 10431 * Configuration options. 10432 * 10433 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) 10434 * @property {Hasher} hasher The hasher to use. Default: SHA1 10435 * @property {number} iterations The number of iterations to perform. Default: 1 10436 */ 10437 cfg: Base.extend({ 10438 keySize: 128 / 32, 10439 hasher: SHA1, 10440 iterations: 1 10441 }), 10442 10443 /** 10444 * Initializes a newly created key derivation function. 10445 * 10446 * @param {Object} cfg (Optional) The configuration options to use for the derivation. 10447 * 10448 * @example 10449 * 10450 * var kdf = CryptoJS.algo.PBKDF2.create(); 10451 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); 10452 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); 10453 */ 10454 init: function(cfg) { 10455 this.cfg = this.cfg.extend(cfg); 10456 }, 10457 10458 /** 10459 * Computes the Password-Based Key Derivation Function 2. 10460 * 10461 * @param {WordArray|string} password The password. 10462 * @param {WordArray|string} salt A salt. 10463 * 10464 * @return {WordArray} The derived key. 10465 * 10466 * @example 10467 * 10468 * var key = kdf.compute(password, salt); 10469 */ 10470 compute: function(password, salt) { 10471 // Shortcut 10472 var cfg = this.cfg; 10473 10474 // Init HMAC 10475 var hmac = HMAC.create(cfg.hasher, password); 10476 10477 // Initial values 10478 var derivedKey = WordArray.create(); 10479 var blockIndex = WordArray.create([0x00000001]); 10480 10481 // Shortcuts 10482 var derivedKeyWords = derivedKey.words; 10483 var blockIndexWords = blockIndex.words; 10484 var keySize = cfg.keySize; 10485 var iterations = cfg.iterations; 10486 10487 // Generate key 10488 while (derivedKeyWords.length < keySize) { 10489 var block = hmac.update(salt).finalize(blockIndex); 10490 hmac.reset(); 10491 10492 // Shortcuts 10493 var blockWords = block.words; 10494 var blockWordsLength = blockWords.length; 10495 10496 // Iterations 10497 var intermediate = block; 10498 for (var i = 1; i < iterations; i++) { 10499 intermediate = hmac.finalize(intermediate); 10500 hmac.reset(); 10501 10502 // Shortcut 10503 var intermediateWords = intermediate.words; 10504 10505 // XOR intermediate with block 10506 for (var j = 0; j < blockWordsLength; j++) { 10507 blockWords[j] ^= intermediateWords[j]; 10508 } 10509 } 10510 10511 derivedKey.concat(block); 10512 blockIndexWords[0]++; 10513 } 10514 derivedKey.sigBytes = keySize * 4; 10515 10516 return derivedKey; 10517 } 10518 }); 10519 10520 /** 10521 * Computes the Password-Based Key Derivation Function 2. 10522 * 10523 * @param {WordArray|string} password The password. 10524 * @param {WordArray|string} salt A salt. 10525 * @param {Object} cfg (Optional) The configuration options to use for this computation. 10526 * 10527 * @return {WordArray} The derived key. 10528 * 10529 * @static 10530 * 10531 * @example 10532 * 10533 * var key = CryptoJS.PBKDF2(password, salt); 10534 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); 10535 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); 10536 */ 10537 C.PBKDF2 = function(password, salt, cfg) { 10538 return PBKDF2.create(cfg).compute(password, salt); 10539 }; 10540 }()); 10541 10542 10543 return CryptoJS.PBKDF2; 10544 10545 })); 10546 }, { 10547 "./core": 53, 10548 "./hmac": 58, 10549 "./sha1": 77 10550 }], 10551 73: [function(require, module, exports) {; 10552 (function(root, factory, undef) { 10553 if (typeof exports === "object") { 10554 // CommonJS 10555 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10556 } else if (typeof define === "function" && define.amd) { 10557 // AMD 10558 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10559 } else { 10560 // Global (browser) 10561 factory(root.CryptoJS); 10562 } 10563 }(this, function(CryptoJS) { 10564 10565 (function() { 10566 // Shortcuts 10567 var C = CryptoJS; 10568 var C_lib = C.lib; 10569 var StreamCipher = C_lib.StreamCipher; 10570 var C_algo = C.algo; 10571 10572 // Reusable objects 10573 var S = []; 10574 var C_ = []; 10575 var G = []; 10576 10577 /** 10578 * Rabbit stream cipher algorithm. 10579 * 10580 * This is a legacy version that neglected to convert the key to little-endian. 10581 * This error doesn't affect the cipher's security, 10582 * but it does affect its compatibility with other implementations. 10583 */ 10584 var RabbitLegacy = C_algo.RabbitLegacy = StreamCipher.extend({ 10585 _doReset: function() { 10586 // Shortcuts 10587 var K = this._key.words; 10588 var iv = this.cfg.iv; 10589 10590 // Generate initial state values 10591 var X = this._X = [ 10592 K[0], (K[3] << 16) | (K[2] >>> 16), 10593 K[1], (K[0] << 16) | (K[3] >>> 16), 10594 K[2], (K[1] << 16) | (K[0] >>> 16), 10595 K[3], (K[2] << 16) | (K[1] >>> 16) 10596 ]; 10597 10598 // Generate initial counter values 10599 var C = this._C = [ 10600 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10601 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10602 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10603 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10604 ]; 10605 10606 // Carry bit 10607 this._b = 0; 10608 10609 // Iterate the system four times 10610 for (var i = 0; i < 4; i++) { 10611 nextState.call(this); 10612 } 10613 10614 // Modify the counters 10615 for (var i = 0; i < 8; i++) { 10616 C[i] ^= X[(i + 4) & 7]; 10617 } 10618 10619 // IV setup 10620 if (iv) { 10621 // Shortcuts 10622 var IV = iv.words; 10623 var IV_0 = IV[0]; 10624 var IV_1 = IV[1]; 10625 10626 // Generate four subvectors 10627 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10628 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10629 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10630 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10631 10632 // Modify counter values 10633 C[0] ^= i0; 10634 C[1] ^= i1; 10635 C[2] ^= i2; 10636 C[3] ^= i3; 10637 C[4] ^= i0; 10638 C[5] ^= i1; 10639 C[6] ^= i2; 10640 C[7] ^= i3; 10641 10642 // Iterate the system four times 10643 for (var i = 0; i < 4; i++) { 10644 nextState.call(this); 10645 } 10646 } 10647 }, 10648 10649 _doProcessBlock: function(M, offset) { 10650 // Shortcut 10651 var X = this._X; 10652 10653 // Iterate the system 10654 nextState.call(this); 10655 10656 // Generate four keystream words 10657 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10658 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10659 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10660 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10661 10662 for (var i = 0; i < 4; i++) { 10663 // Swap endian 10664 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10665 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10666 10667 // Encrypt 10668 M[offset + i] ^= S[i]; 10669 } 10670 }, 10671 10672 blockSize: 128 / 32, 10673 10674 ivSize: 64 / 32 10675 }); 10676 10677 function nextState() { 10678 // Shortcuts 10679 var X = this._X; 10680 var C = this._C; 10681 10682 // Save old counter values 10683 for (var i = 0; i < 8; i++) { 10684 C_[i] = C[i]; 10685 } 10686 10687 // Calculate new counter values 10688 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10689 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10690 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10691 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10692 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10693 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10694 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10695 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10696 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10697 10698 // Calculate the g-values 10699 for (var i = 0; i < 8; i++) { 10700 var gx = X[i] + C[i]; 10701 10702 // Construct high and low argument for squaring 10703 var ga = gx & 0xffff; 10704 var gb = gx >>> 16; 10705 10706 // Calculate high and low result of squaring 10707 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10708 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10709 10710 // High XOR low 10711 G[i] = gh ^ gl; 10712 } 10713 10714 // Calculate new state values 10715 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10716 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10717 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10718 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10719 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10720 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10721 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10722 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10723 } 10724 10725 /** 10726 * Shortcut functions to the cipher's object interface. 10727 * 10728 * @example 10729 * 10730 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg); 10731 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg); 10732 */ 10733 C.RabbitLegacy = StreamCipher._createHelper(RabbitLegacy); 10734 }()); 10735 10736 10737 return CryptoJS.RabbitLegacy; 10738 10739 })); 10740 }, { 10741 "./cipher-core": 52, 10742 "./core": 53, 10743 "./enc-base64": 54, 10744 "./evpkdf": 56, 10745 "./md5": 61 10746 }], 10747 74: [function(require, module, exports) {; 10748 (function(root, factory, undef) { 10749 if (typeof exports === "object") { 10750 // CommonJS 10751 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10752 } else if (typeof define === "function" && define.amd) { 10753 // AMD 10754 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10755 } else { 10756 // Global (browser) 10757 factory(root.CryptoJS); 10758 } 10759 }(this, function(CryptoJS) { 10760 10761 (function() { 10762 // Shortcuts 10763 var C = CryptoJS; 10764 var C_lib = C.lib; 10765 var StreamCipher = C_lib.StreamCipher; 10766 var C_algo = C.algo; 10767 10768 // Reusable objects 10769 var S = []; 10770 var C_ = []; 10771 var G = []; 10772 10773 /** 10774 * Rabbit stream cipher algorithm 10775 */ 10776 var Rabbit = C_algo.Rabbit = StreamCipher.extend({ 10777 _doReset: function() { 10778 // Shortcuts 10779 var K = this._key.words; 10780 var iv = this.cfg.iv; 10781 10782 // Swap endian 10783 for (var i = 0; i < 4; i++) { 10784 K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | 10785 (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); 10786 } 10787 10788 // Generate initial state values 10789 var X = this._X = [ 10790 K[0], (K[3] << 16) | (K[2] >>> 16), 10791 K[1], (K[0] << 16) | (K[3] >>> 16), 10792 K[2], (K[1] << 16) | (K[0] >>> 16), 10793 K[3], (K[2] << 16) | (K[1] >>> 16) 10794 ]; 10795 10796 // Generate initial counter values 10797 var C = this._C = [ 10798 (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), 10799 (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), 10800 (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), 10801 (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) 10802 ]; 10803 10804 // Carry bit 10805 this._b = 0; 10806 10807 // Iterate the system four times 10808 for (var i = 0; i < 4; i++) { 10809 nextState.call(this); 10810 } 10811 10812 // Modify the counters 10813 for (var i = 0; i < 8; i++) { 10814 C[i] ^= X[(i + 4) & 7]; 10815 } 10816 10817 // IV setup 10818 if (iv) { 10819 // Shortcuts 10820 var IV = iv.words; 10821 var IV_0 = IV[0]; 10822 var IV_1 = IV[1]; 10823 10824 // Generate four subvectors 10825 var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); 10826 var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); 10827 var i1 = (i0 >>> 16) | (i2 & 0xffff0000); 10828 var i3 = (i2 << 16) | (i0 & 0x0000ffff); 10829 10830 // Modify counter values 10831 C[0] ^= i0; 10832 C[1] ^= i1; 10833 C[2] ^= i2; 10834 C[3] ^= i3; 10835 C[4] ^= i0; 10836 C[5] ^= i1; 10837 C[6] ^= i2; 10838 C[7] ^= i3; 10839 10840 // Iterate the system four times 10841 for (var i = 0; i < 4; i++) { 10842 nextState.call(this); 10843 } 10844 } 10845 }, 10846 10847 _doProcessBlock: function(M, offset) { 10848 // Shortcut 10849 var X = this._X; 10850 10851 // Iterate the system 10852 nextState.call(this); 10853 10854 // Generate four keystream words 10855 S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); 10856 S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); 10857 S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); 10858 S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); 10859 10860 for (var i = 0; i < 4; i++) { 10861 // Swap endian 10862 S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | 10863 (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); 10864 10865 // Encrypt 10866 M[offset + i] ^= S[i]; 10867 } 10868 }, 10869 10870 blockSize: 128 / 32, 10871 10872 ivSize: 64 / 32 10873 }); 10874 10875 function nextState() { 10876 // Shortcuts 10877 var X = this._X; 10878 var C = this._C; 10879 10880 // Save old counter values 10881 for (var i = 0; i < 8; i++) { 10882 C_[i] = C[i]; 10883 } 10884 10885 // Calculate new counter values 10886 C[0] = (C[0] + 0x4d34d34d + this._b) | 0; 10887 C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; 10888 C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; 10889 C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; 10890 C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; 10891 C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; 10892 C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; 10893 C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; 10894 this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; 10895 10896 // Calculate the g-values 10897 for (var i = 0; i < 8; i++) { 10898 var gx = X[i] + C[i]; 10899 10900 // Construct high and low argument for squaring 10901 var ga = gx & 0xffff; 10902 var gb = gx >>> 16; 10903 10904 // Calculate high and low result of squaring 10905 var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; 10906 var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); 10907 10908 // High XOR low 10909 G[i] = gh ^ gl; 10910 } 10911 10912 // Calculate new state values 10913 X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; 10914 X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; 10915 X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; 10916 X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; 10917 X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; 10918 X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; 10919 X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; 10920 X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; 10921 } 10922 10923 /** 10924 * Shortcut functions to the cipher's object interface. 10925 * 10926 * @example 10927 * 10928 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg); 10929 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg); 10930 */ 10931 C.Rabbit = StreamCipher._createHelper(Rabbit); 10932 }()); 10933 10934 10935 return CryptoJS.Rabbit; 10936 10937 })); 10938 }, { 10939 "./cipher-core": 52, 10940 "./core": 53, 10941 "./enc-base64": 54, 10942 "./evpkdf": 56, 10943 "./md5": 61 10944 }], 10945 75: [function(require, module, exports) {; 10946 (function(root, factory, undef) { 10947 if (typeof exports === "object") { 10948 // CommonJS 10949 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 10950 } else if (typeof define === "function" && define.amd) { 10951 // AMD 10952 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 10953 } else { 10954 // Global (browser) 10955 factory(root.CryptoJS); 10956 } 10957 }(this, function(CryptoJS) { 10958 10959 (function() { 10960 // Shortcuts 10961 var C = CryptoJS; 10962 var C_lib = C.lib; 10963 var StreamCipher = C_lib.StreamCipher; 10964 var C_algo = C.algo; 10965 10966 /** 10967 * RC4 stream cipher algorithm. 10968 */ 10969 var RC4 = C_algo.RC4 = StreamCipher.extend({ 10970 _doReset: function() { 10971 // Shortcuts 10972 var key = this._key; 10973 var keyWords = key.words; 10974 var keySigBytes = key.sigBytes; 10975 10976 // Init sbox 10977 var S = this._S = []; 10978 for (var i = 0; i < 256; i++) { 10979 S[i] = i; 10980 } 10981 10982 // Key setup 10983 for (var i = 0, j = 0; i < 256; i++) { 10984 var keyByteIndex = i % keySigBytes; 10985 var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; 10986 10987 j = (j + S[i] + keyByte) % 256; 10988 10989 // Swap 10990 var t = S[i]; 10991 S[i] = S[j]; 10992 S[j] = t; 10993 } 10994 10995 // Counters 10996 this._i = this._j = 0; 10997 }, 10998 10999 _doProcessBlock: function(M, offset) { 11000 M[offset] ^= generateKeystreamWord.call(this); 11001 }, 11002 11003 keySize: 256 / 32, 11004 11005 ivSize: 0 11006 }); 11007 11008 function generateKeystreamWord() { 11009 // Shortcuts 11010 var S = this._S; 11011 var i = this._i; 11012 var j = this._j; 11013 11014 // Generate keystream word 11015 var keystreamWord = 0; 11016 for (var n = 0; n < 4; n++) { 11017 i = (i + 1) % 256; 11018 j = (j + S[i]) % 256; 11019 11020 // Swap 11021 var t = S[i]; 11022 S[i] = S[j]; 11023 S[j] = t; 11024 11025 keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); 11026 } 11027 11028 // Update counters 11029 this._i = i; 11030 this._j = j; 11031 11032 return keystreamWord; 11033 } 11034 11035 /** 11036 * Shortcut functions to the cipher's object interface. 11037 * 11038 * @example 11039 * 11040 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg); 11041 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg); 11042 */ 11043 C.RC4 = StreamCipher._createHelper(RC4); 11044 11045 /** 11046 * Modified RC4 stream cipher algorithm. 11047 */ 11048 var RC4Drop = C_algo.RC4Drop = RC4.extend({ 11049 /** 11050 * Configuration options. 11051 * 11052 * @property {number} drop The number of keystream words to drop. Default 192 11053 */ 11054 cfg: RC4.cfg.extend({ 11055 drop: 192 11056 }), 11057 11058 _doReset: function() { 11059 RC4._doReset.call(this); 11060 11061 // Drop 11062 for (var i = this.cfg.drop; i > 0; i--) { 11063 generateKeystreamWord.call(this); 11064 } 11065 } 11066 }); 11067 11068 /** 11069 * Shortcut functions to the cipher's object interface. 11070 * 11071 * @example 11072 * 11073 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg); 11074 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg); 11075 */ 11076 C.RC4Drop = StreamCipher._createHelper(RC4Drop); 11077 }()); 11078 11079 11080 return CryptoJS.RC4; 11081 11082 })); 11083 }, { 11084 "./cipher-core": 52, 11085 "./core": 53, 11086 "./enc-base64": 54, 11087 "./evpkdf": 56, 11088 "./md5": 61 11089 }], 11090 76: [function(require, module, exports) {; 11091 (function(root, factory) { 11092 if (typeof exports === "object") { 11093 // CommonJS 11094 module.exports = exports = factory(require("./core")); 11095 } else if (typeof define === "function" && define.amd) { 11096 // AMD 11097 define(["./core"], factory); 11098 } else { 11099 // Global (browser) 11100 factory(root.CryptoJS); 11101 } 11102 }(this, function(CryptoJS) { 11103 11104 /** @preserve 11105 (c) 2012 by Cédric Mesnil. All rights reserved. 11106 11107 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 11108 11109 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 11110 - 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. 11111 11112 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. 11113 */ 11114 11115 (function(Math) { 11116 // Shortcuts 11117 var C = CryptoJS; 11118 var C_lib = C.lib; 11119 var WordArray = C_lib.WordArray; 11120 var Hasher = C_lib.Hasher; 11121 var C_algo = C.algo; 11122 11123 // Constants table 11124 var _zl = WordArray.create([ 11125 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 11126 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 11127 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 11128 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 11129 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13 11130 ]); 11131 var _zr = WordArray.create([ 11132 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 11133 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 11134 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 11135 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 11136 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11 11137 ]); 11138 var _sl = WordArray.create([ 11139 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 11140 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11141 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11142 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 11143 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 11144 ]); 11145 var _sr = WordArray.create([ 11146 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 11147 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 11148 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 11149 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 11150 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 11151 ]); 11152 11153 var _hl = WordArray.create([0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]); 11154 var _hr = WordArray.create([0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]); 11155 11156 /** 11157 * RIPEMD160 hash algorithm. 11158 */ 11159 var RIPEMD160 = C_algo.RIPEMD160 = Hasher.extend({ 11160 _doReset: function() { 11161 this._hash = WordArray.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]); 11162 }, 11163 11164 _doProcessBlock: function(M, offset) { 11165 11166 // Swap endian 11167 for (var i = 0; i < 16; i++) { 11168 // Shortcuts 11169 var offset_i = offset + i; 11170 var M_offset_i = M[offset_i]; 11171 11172 // Swap 11173 M[offset_i] = ( 11174 (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | 11175 (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) 11176 ); 11177 } 11178 // Shortcut 11179 var H = this._hash.words; 11180 var hl = _hl.words; 11181 var hr = _hr.words; 11182 var zl = _zl.words; 11183 var zr = _zr.words; 11184 var sl = _sl.words; 11185 var sr = _sr.words; 11186 11187 // Working variables 11188 var al, bl, cl, dl, el; 11189 var ar, br, cr, dr, er; 11190 11191 ar = al = H[0]; 11192 br = bl = H[1]; 11193 cr = cl = H[2]; 11194 dr = dl = H[3]; 11195 er = el = H[4]; 11196 // Computation 11197 var t; 11198 for (var i = 0; i < 80; i += 1) { 11199 t = (al + M[offset + zl[i]]) | 0; 11200 if (i < 16) { 11201 t += f1(bl, cl, dl) + hl[0]; 11202 } else if (i < 32) { 11203 t += f2(bl, cl, dl) + hl[1]; 11204 } else if (i < 48) { 11205 t += f3(bl, cl, dl) + hl[2]; 11206 } else if (i < 64) { 11207 t += f4(bl, cl, dl) + hl[3]; 11208 } else { // if (i<80) { 11209 t += f5(bl, cl, dl) + hl[4]; 11210 } 11211 t = t | 0; 11212 t = rotl(t, sl[i]); 11213 t = (t + el) | 0; 11214 al = el; 11215 el = dl; 11216 dl = rotl(cl, 10); 11217 cl = bl; 11218 bl = t; 11219 11220 t = (ar + M[offset + zr[i]]) | 0; 11221 if (i < 16) { 11222 t += f5(br, cr, dr) + hr[0]; 11223 } else if (i < 32) { 11224 t += f4(br, cr, dr) + hr[1]; 11225 } else if (i < 48) { 11226 t += f3(br, cr, dr) + hr[2]; 11227 } else if (i < 64) { 11228 t += f2(br, cr, dr) + hr[3]; 11229 } else { // if (i<80) { 11230 t += f1(br, cr, dr) + hr[4]; 11231 } 11232 t = t | 0; 11233 t = rotl(t, sr[i]); 11234 t = (t + er) | 0; 11235 ar = er; 11236 er = dr; 11237 dr = rotl(cr, 10); 11238 cr = br; 11239 br = t; 11240 } 11241 // Intermediate hash value 11242 t = (H[1] + cl + dr) | 0; 11243 H[1] = (H[2] + dl + er) | 0; 11244 H[2] = (H[3] + el + ar) | 0; 11245 H[3] = (H[4] + al + br) | 0; 11246 H[4] = (H[0] + bl + cr) | 0; 11247 H[0] = t; 11248 }, 11249 11250 _doFinalize: function() { 11251 // Shortcuts 11252 var data = this._data; 11253 var dataWords = data.words; 11254 11255 var nBitsTotal = this._nDataBytes * 8; 11256 var nBitsLeft = data.sigBytes * 8; 11257 11258 // Add padding 11259 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11260 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( 11261 (((nBitsTotal << 8) | (nBitsTotal >>> 24)) & 0x00ff00ff) | 11262 (((nBitsTotal << 24) | (nBitsTotal >>> 8)) & 0xff00ff00) 11263 ); 11264 data.sigBytes = (dataWords.length + 1) * 4; 11265 11266 // Hash final blocks 11267 this._process(); 11268 11269 // Shortcuts 11270 var hash = this._hash; 11271 var H = hash.words; 11272 11273 // Swap endian 11274 for (var i = 0; i < 5; i++) { 11275 // Shortcut 11276 var H_i = H[i]; 11277 11278 // Swap 11279 H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | 11280 (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); 11281 } 11282 11283 // Return final computed hash 11284 return hash; 11285 }, 11286 11287 clone: function() { 11288 var clone = Hasher.clone.call(this); 11289 clone._hash = this._hash.clone(); 11290 11291 return clone; 11292 } 11293 }); 11294 11295 11296 function f1(x, y, z) { 11297 return ((x) ^ (y) ^ (z)); 11298 11299 } 11300 11301 function f2(x, y, z) { 11302 return (((x) & (y)) | ((~x) & (z))); 11303 } 11304 11305 function f3(x, y, z) { 11306 return (((x) | (~(y))) ^ (z)); 11307 } 11308 11309 function f4(x, y, z) { 11310 return (((x) & (z)) | ((y) & (~(z)))); 11311 } 11312 11313 function f5(x, y, z) { 11314 return ((x) ^ ((y) | (~(z)))); 11315 11316 } 11317 11318 function rotl(x, n) { 11319 return (x << n) | (x >>> (32 - n)); 11320 } 11321 11322 11323 /** 11324 * Shortcut function to the hasher's object interface. 11325 * 11326 * @param {WordArray|string} message The message to hash. 11327 * 11328 * @return {WordArray} The hash. 11329 * 11330 * @static 11331 * 11332 * @example 11333 * 11334 * var hash = CryptoJS.RIPEMD160('message'); 11335 * var hash = CryptoJS.RIPEMD160(wordArray); 11336 */ 11337 C.RIPEMD160 = Hasher._createHelper(RIPEMD160); 11338 11339 /** 11340 * Shortcut function to the HMAC's object interface. 11341 * 11342 * @param {WordArray|string} message The message to hash. 11343 * @param {WordArray|string} key The secret key. 11344 * 11345 * @return {WordArray} The HMAC. 11346 * 11347 * @static 11348 * 11349 * @example 11350 * 11351 * var hmac = CryptoJS.HmacRIPEMD160(message, key); 11352 */ 11353 C.HmacRIPEMD160 = Hasher._createHmacHelper(RIPEMD160); 11354 }(Math)); 11355 11356 11357 return CryptoJS.RIPEMD160; 11358 11359 })); 11360 }, { 11361 "./core": 53 11362 }], 11363 77: [function(require, module, exports) {; 11364 (function(root, factory) { 11365 if (typeof exports === "object") { 11366 // CommonJS 11367 module.exports = exports = factory(require("./core")); 11368 } else if (typeof define === "function" && define.amd) { 11369 // AMD 11370 define(["./core"], factory); 11371 } else { 11372 // Global (browser) 11373 factory(root.CryptoJS); 11374 } 11375 }(this, function(CryptoJS) { 11376 11377 (function() { 11378 // Shortcuts 11379 var C = CryptoJS; 11380 var C_lib = C.lib; 11381 var WordArray = C_lib.WordArray; 11382 var Hasher = C_lib.Hasher; 11383 var C_algo = C.algo; 11384 11385 // Reusable object 11386 var W = []; 11387 11388 /** 11389 * SHA-1 hash algorithm. 11390 */ 11391 var SHA1 = C_algo.SHA1 = Hasher.extend({ 11392 _doReset: function() { 11393 this._hash = new WordArray.init([ 11394 0x67452301, 0xefcdab89, 11395 0x98badcfe, 0x10325476, 11396 0xc3d2e1f0 11397 ]); 11398 }, 11399 11400 _doProcessBlock: function(M, offset) { 11401 // Shortcut 11402 var H = this._hash.words; 11403 11404 // Working variables 11405 var a = H[0]; 11406 var b = H[1]; 11407 var c = H[2]; 11408 var d = H[3]; 11409 var e = H[4]; 11410 11411 // Computation 11412 for (var i = 0; i < 80; i++) { 11413 if (i < 16) { 11414 W[i] = M[offset + i] | 0; 11415 } else { 11416 var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; 11417 W[i] = (n << 1) | (n >>> 31); 11418 } 11419 11420 var t = ((a << 5) | (a >>> 27)) + e + W[i]; 11421 if (i < 20) { 11422 t += ((b & c) | (~b & d)) + 0x5a827999; 11423 } else if (i < 40) { 11424 t += (b ^ c ^ d) + 0x6ed9eba1; 11425 } else if (i < 60) { 11426 t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; 11427 } else /* if (i < 80) */ { 11428 t += (b ^ c ^ d) - 0x359d3e2a; 11429 } 11430 11431 e = d; 11432 d = c; 11433 c = (b << 30) | (b >>> 2); 11434 b = a; 11435 a = t; 11436 } 11437 11438 // Intermediate hash value 11439 H[0] = (H[0] + a) | 0; 11440 H[1] = (H[1] + b) | 0; 11441 H[2] = (H[2] + c) | 0; 11442 H[3] = (H[3] + d) | 0; 11443 H[4] = (H[4] + e) | 0; 11444 }, 11445 11446 _doFinalize: function() { 11447 // Shortcuts 11448 var data = this._data; 11449 var dataWords = data.words; 11450 11451 var nBitsTotal = this._nDataBytes * 8; 11452 var nBitsLeft = data.sigBytes * 8; 11453 11454 // Add padding 11455 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11456 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11457 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11458 data.sigBytes = dataWords.length * 4; 11459 11460 // Hash final blocks 11461 this._process(); 11462 11463 // Return final computed hash 11464 return this._hash; 11465 }, 11466 11467 clone: function() { 11468 var clone = Hasher.clone.call(this); 11469 clone._hash = this._hash.clone(); 11470 11471 return clone; 11472 } 11473 }); 11474 11475 /** 11476 * Shortcut function to the hasher's object interface. 11477 * 11478 * @param {WordArray|string} message The message to hash. 11479 * 11480 * @return {WordArray} The hash. 11481 * 11482 * @static 11483 * 11484 * @example 11485 * 11486 * var hash = CryptoJS.SHA1('message'); 11487 * var hash = CryptoJS.SHA1(wordArray); 11488 */ 11489 C.SHA1 = Hasher._createHelper(SHA1); 11490 11491 /** 11492 * Shortcut function to the HMAC's object interface. 11493 * 11494 * @param {WordArray|string} message The message to hash. 11495 * @param {WordArray|string} key The secret key. 11496 * 11497 * @return {WordArray} The HMAC. 11498 * 11499 * @static 11500 * 11501 * @example 11502 * 11503 * var hmac = CryptoJS.HmacSHA1(message, key); 11504 */ 11505 C.HmacSHA1 = Hasher._createHmacHelper(SHA1); 11506 }()); 11507 11508 11509 return CryptoJS.SHA1; 11510 11511 })); 11512 }, { 11513 "./core": 53 11514 }], 11515 78: [function(require, module, exports) {; 11516 (function(root, factory, undef) { 11517 if (typeof exports === "object") { 11518 // CommonJS 11519 module.exports = exports = factory(require("./core"), require("./sha256")); 11520 } else if (typeof define === "function" && define.amd) { 11521 // AMD 11522 define(["./core", "./sha256"], factory); 11523 } else { 11524 // Global (browser) 11525 factory(root.CryptoJS); 11526 } 11527 }(this, function(CryptoJS) { 11528 11529 (function() { 11530 // Shortcuts 11531 var C = CryptoJS; 11532 var C_lib = C.lib; 11533 var WordArray = C_lib.WordArray; 11534 var C_algo = C.algo; 11535 var SHA256 = C_algo.SHA256; 11536 11537 /** 11538 * SHA-224 hash algorithm. 11539 */ 11540 var SHA224 = C_algo.SHA224 = SHA256.extend({ 11541 _doReset: function() { 11542 this._hash = new WordArray.init([ 11543 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 11544 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4 11545 ]); 11546 }, 11547 11548 _doFinalize: function() { 11549 var hash = SHA256._doFinalize.call(this); 11550 11551 hash.sigBytes -= 4; 11552 11553 return hash; 11554 } 11555 }); 11556 11557 /** 11558 * Shortcut function to the hasher's object interface. 11559 * 11560 * @param {WordArray|string} message The message to hash. 11561 * 11562 * @return {WordArray} The hash. 11563 * 11564 * @static 11565 * 11566 * @example 11567 * 11568 * var hash = CryptoJS.SHA224('message'); 11569 * var hash = CryptoJS.SHA224(wordArray); 11570 */ 11571 C.SHA224 = SHA256._createHelper(SHA224); 11572 11573 /** 11574 * Shortcut function to the HMAC's object interface. 11575 * 11576 * @param {WordArray|string} message The message to hash. 11577 * @param {WordArray|string} key The secret key. 11578 * 11579 * @return {WordArray} The HMAC. 11580 * 11581 * @static 11582 * 11583 * @example 11584 * 11585 * var hmac = CryptoJS.HmacSHA224(message, key); 11586 */ 11587 C.HmacSHA224 = SHA256._createHmacHelper(SHA224); 11588 }()); 11589 11590 11591 return CryptoJS.SHA224; 11592 11593 })); 11594 }, { 11595 "./core": 53, 11596 "./sha256": 79 11597 }], 11598 79: [function(require, module, exports) {; 11599 (function(root, factory) { 11600 if (typeof exports === "object") { 11601 // CommonJS 11602 module.exports = exports = factory(require("./core")); 11603 } else if (typeof define === "function" && define.amd) { 11604 // AMD 11605 define(["./core"], factory); 11606 } else { 11607 // Global (browser) 11608 factory(root.CryptoJS); 11609 } 11610 }(this, function(CryptoJS) { 11611 11612 (function(Math) { 11613 // Shortcuts 11614 var C = CryptoJS; 11615 var C_lib = C.lib; 11616 var WordArray = C_lib.WordArray; 11617 var Hasher = C_lib.Hasher; 11618 var C_algo = C.algo; 11619 11620 // Initialization and round constants tables 11621 var H = []; 11622 var K = []; 11623 11624 // Compute constants 11625 (function() { 11626 function isPrime(n) { 11627 var sqrtN = Math.sqrt(n); 11628 for (var factor = 2; factor <= sqrtN; factor++) { 11629 if (!(n % factor)) { 11630 return false; 11631 } 11632 } 11633 11634 return true; 11635 } 11636 11637 function getFractionalBits(n) { 11638 return ((n - (n | 0)) * 0x100000000) | 0; 11639 } 11640 11641 var n = 2; 11642 var nPrime = 0; 11643 while (nPrime < 64) { 11644 if (isPrime(n)) { 11645 if (nPrime < 8) { 11646 H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2)); 11647 } 11648 K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3)); 11649 11650 nPrime++; 11651 } 11652 11653 n++; 11654 } 11655 }()); 11656 11657 // Reusable object 11658 var W = []; 11659 11660 /** 11661 * SHA-256 hash algorithm. 11662 */ 11663 var SHA256 = C_algo.SHA256 = Hasher.extend({ 11664 _doReset: function() { 11665 this._hash = new WordArray.init(H.slice(0)); 11666 }, 11667 11668 _doProcessBlock: function(M, offset) { 11669 // Shortcut 11670 var H = this._hash.words; 11671 11672 // Working variables 11673 var a = H[0]; 11674 var b = H[1]; 11675 var c = H[2]; 11676 var d = H[3]; 11677 var e = H[4]; 11678 var f = H[5]; 11679 var g = H[6]; 11680 var h = H[7]; 11681 11682 // Computation 11683 for (var i = 0; i < 64; i++) { 11684 if (i < 16) { 11685 W[i] = M[offset + i] | 0; 11686 } else { 11687 var gamma0x = W[i - 15]; 11688 var gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ 11689 ((gamma0x << 14) | (gamma0x >>> 18)) ^ 11690 (gamma0x >>> 3); 11691 11692 var gamma1x = W[i - 2]; 11693 var gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ 11694 ((gamma1x << 13) | (gamma1x >>> 19)) ^ 11695 (gamma1x >>> 10); 11696 11697 W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; 11698 } 11699 11700 var ch = (e & f) ^ (~e & g); 11701 var maj = (a & b) ^ (a & c) ^ (b & c); 11702 11703 var sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); 11704 var sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); 11705 11706 var t1 = h + sigma1 + ch + K[i] + W[i]; 11707 var t2 = sigma0 + maj; 11708 11709 h = g; 11710 g = f; 11711 f = e; 11712 e = (d + t1) | 0; 11713 d = c; 11714 c = b; 11715 b = a; 11716 a = (t1 + t2) | 0; 11717 } 11718 11719 // Intermediate hash value 11720 H[0] = (H[0] + a) | 0; 11721 H[1] = (H[1] + b) | 0; 11722 H[2] = (H[2] + c) | 0; 11723 H[3] = (H[3] + d) | 0; 11724 H[4] = (H[4] + e) | 0; 11725 H[5] = (H[5] + f) | 0; 11726 H[6] = (H[6] + g) | 0; 11727 H[7] = (H[7] + h) | 0; 11728 }, 11729 11730 _doFinalize: function() { 11731 // Shortcuts 11732 var data = this._data; 11733 var dataWords = data.words; 11734 11735 var nBitsTotal = this._nDataBytes * 8; 11736 var nBitsLeft = data.sigBytes * 8; 11737 11738 // Add padding 11739 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 11740 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); 11741 dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; 11742 data.sigBytes = dataWords.length * 4; 11743 11744 // Hash final blocks 11745 this._process(); 11746 11747 // Return final computed hash 11748 return this._hash; 11749 }, 11750 11751 clone: function() { 11752 var clone = Hasher.clone.call(this); 11753 clone._hash = this._hash.clone(); 11754 11755 return clone; 11756 } 11757 }); 11758 11759 /** 11760 * Shortcut function to the hasher's object interface. 11761 * 11762 * @param {WordArray|string} message The message to hash. 11763 * 11764 * @return {WordArray} The hash. 11765 * 11766 * @static 11767 * 11768 * @example 11769 * 11770 * var hash = CryptoJS.SHA256('message'); 11771 * var hash = CryptoJS.SHA256(wordArray); 11772 */ 11773 C.SHA256 = Hasher._createHelper(SHA256); 11774 11775 /** 11776 * Shortcut function to the HMAC's object interface. 11777 * 11778 * @param {WordArray|string} message The message to hash. 11779 * @param {WordArray|string} key The secret key. 11780 * 11781 * @return {WordArray} The HMAC. 11782 * 11783 * @static 11784 * 11785 * @example 11786 * 11787 * var hmac = CryptoJS.HmacSHA256(message, key); 11788 */ 11789 C.HmacSHA256 = Hasher._createHmacHelper(SHA256); 11790 }(Math)); 11791 11792 11793 return CryptoJS.SHA256; 11794 11795 })); 11796 }, { 11797 "./core": 53 11798 }], 11799 80: [function(require, module, exports) {; 11800 (function(root, factory, undef) { 11801 if (typeof exports === "object") { 11802 // CommonJS 11803 module.exports = exports = factory(require("./core"), require("./x64-core")); 11804 } else if (typeof define === "function" && define.amd) { 11805 // AMD 11806 define(["./core", "./x64-core"], factory); 11807 } else { 11808 // Global (browser) 11809 factory(root.CryptoJS); 11810 } 11811 }(this, function(CryptoJS) { 11812 11813 (function(Math) { 11814 // Shortcuts 11815 var C = CryptoJS; 11816 var C_lib = C.lib; 11817 var WordArray = C_lib.WordArray; 11818 var Hasher = C_lib.Hasher; 11819 var C_x64 = C.x64; 11820 var X64Word = C_x64.Word; 11821 var C_algo = C.algo; 11822 11823 // Constants tables 11824 var RHO_OFFSETS = []; 11825 var PI_INDEXES = []; 11826 var ROUND_CONSTANTS = []; 11827 11828 // Compute Constants 11829 (function() { 11830 // Compute rho offset constants 11831 var x = 1, 11832 y = 0; 11833 for (var t = 0; t < 24; t++) { 11834 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 11835 11836 var newX = y % 5; 11837 var newY = (2 * x + 3 * y) % 5; 11838 x = newX; 11839 y = newY; 11840 } 11841 11842 // Compute pi index constants 11843 for (var x = 0; x < 5; x++) { 11844 for (var y = 0; y < 5; y++) { 11845 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 11846 } 11847 } 11848 11849 // Compute round constants 11850 var LFSR = 0x01; 11851 for (var i = 0; i < 24; i++) { 11852 var roundConstantMsw = 0; 11853 var roundConstantLsw = 0; 11854 11855 for (var j = 0; j < 7; j++) { 11856 if (LFSR & 0x01) { 11857 var bitPosition = (1 << j) - 1; 11858 if (bitPosition < 32) { 11859 roundConstantLsw ^= 1 << bitPosition; 11860 } else /* if (bitPosition >= 32) */ { 11861 roundConstantMsw ^= 1 << (bitPosition - 32); 11862 } 11863 } 11864 11865 // Compute next LFSR 11866 if (LFSR & 0x80) { 11867 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 11868 LFSR = (LFSR << 1) ^ 0x71; 11869 } else { 11870 LFSR <<= 1; 11871 } 11872 } 11873 11874 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 11875 } 11876 }()); 11877 11878 // Reusable objects for temporary values 11879 var T = []; 11880 (function() { 11881 for (var i = 0; i < 25; i++) { 11882 T[i] = X64Word.create(); 11883 } 11884 }()); 11885 11886 /** 11887 * SHA-3 hash algorithm. 11888 */ 11889 var SHA3 = C_algo.SHA3 = Hasher.extend({ 11890 /** 11891 * Configuration options. 11892 * 11893 * @property {number} outputLength 11894 * The desired number of bits in the output hash. 11895 * Only values permitted are: 224, 256, 384, 512. 11896 * Default: 512 11897 */ 11898 cfg: Hasher.cfg.extend({ 11899 outputLength: 512 11900 }), 11901 11902 _doReset: function() { 11903 var state = this._state = [] 11904 for (var i = 0; i < 25; i++) { 11905 state[i] = new X64Word.init(); 11906 } 11907 11908 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 11909 }, 11910 11911 _doProcessBlock: function(M, offset) { 11912 // Shortcuts 11913 var state = this._state; 11914 var nBlockSizeLanes = this.blockSize / 2; 11915 11916 // Absorb 11917 for (var i = 0; i < nBlockSizeLanes; i++) { 11918 // Shortcuts 11919 var M2i = M[offset + 2 * i]; 11920 var M2i1 = M[offset + 2 * i + 1]; 11921 11922 // Swap endian 11923 M2i = ( 11924 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 11925 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 11926 ); 11927 M2i1 = ( 11928 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 11929 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 11930 ); 11931 11932 // Absorb message into state 11933 var lane = state[i]; 11934 lane.high ^= M2i1; 11935 lane.low ^= M2i; 11936 } 11937 11938 // Rounds 11939 for (var round = 0; round < 24; round++) { 11940 // Theta 11941 for (var x = 0; x < 5; x++) { 11942 // Mix column lanes 11943 var tMsw = 0, 11944 tLsw = 0; 11945 for (var y = 0; y < 5; y++) { 11946 var lane = state[x + 5 * y]; 11947 tMsw ^= lane.high; 11948 tLsw ^= lane.low; 11949 } 11950 11951 // Temporary values 11952 var Tx = T[x]; 11953 Tx.high = tMsw; 11954 Tx.low = tLsw; 11955 } 11956 for (var x = 0; x < 5; x++) { 11957 // Shortcuts 11958 var Tx4 = T[(x + 4) % 5]; 11959 var Tx1 = T[(x + 1) % 5]; 11960 var Tx1Msw = Tx1.high; 11961 var Tx1Lsw = Tx1.low; 11962 11963 // Mix surrounding columns 11964 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 11965 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 11966 for (var y = 0; y < 5; y++) { 11967 var lane = state[x + 5 * y]; 11968 lane.high ^= tMsw; 11969 lane.low ^= tLsw; 11970 } 11971 } 11972 11973 // Rho Pi 11974 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 11975 // Shortcuts 11976 var lane = state[laneIndex]; 11977 var laneMsw = lane.high; 11978 var laneLsw = lane.low; 11979 var rhoOffset = RHO_OFFSETS[laneIndex]; 11980 11981 // Rotate lanes 11982 if (rhoOffset < 32) { 11983 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 11984 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 11985 } else /* if (rhoOffset >= 32) */ { 11986 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 11987 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 11988 } 11989 11990 // Transpose lanes 11991 var TPiLane = T[PI_INDEXES[laneIndex]]; 11992 TPiLane.high = tMsw; 11993 TPiLane.low = tLsw; 11994 } 11995 11996 // Rho pi at x = y = 0 11997 var T0 = T[0]; 11998 var state0 = state[0]; 11999 T0.high = state0.high; 12000 T0.low = state0.low; 12001 12002 // Chi 12003 for (var x = 0; x < 5; x++) { 12004 for (var y = 0; y < 5; y++) { 12005 // Shortcuts 12006 var laneIndex = x + 5 * y; 12007 var lane = state[laneIndex]; 12008 var TLane = T[laneIndex]; 12009 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 12010 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 12011 12012 // Mix rows 12013 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 12014 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 12015 } 12016 } 12017 12018 // Iota 12019 var lane = state[0]; 12020 var roundConstant = ROUND_CONSTANTS[round]; 12021 lane.high ^= roundConstant.high; 12022 lane.low ^= roundConstant.low;; 12023 } 12024 }, 12025 12026 _doFinalize: function() { 12027 // Shortcuts 12028 var data = this._data; 12029 var dataWords = data.words; 12030 var nBitsTotal = this._nDataBytes * 8; 12031 var nBitsLeft = data.sigBytes * 8; 12032 var blockSizeBits = this.blockSize * 32; 12033 12034 // Add padding 12035 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 12036 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 12037 data.sigBytes = dataWords.length * 4; 12038 12039 // Hash final blocks 12040 this._process(); 12041 12042 // Shortcuts 12043 var state = this._state; 12044 var outputLengthBytes = this.cfg.outputLength / 8; 12045 var outputLengthLanes = outputLengthBytes / 8; 12046 12047 // Squeeze 12048 var hashWords = []; 12049 for (var i = 0; i < outputLengthLanes; i++) { 12050 // Shortcuts 12051 var lane = state[i]; 12052 var laneMsw = lane.high; 12053 var laneLsw = lane.low; 12054 12055 // Swap endian 12056 laneMsw = ( 12057 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 12058 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 12059 ); 12060 laneLsw = ( 12061 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 12062 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 12063 ); 12064 12065 // Squeeze state to retrieve hash 12066 hashWords.push(laneLsw); 12067 hashWords.push(laneMsw); 12068 } 12069 12070 // Return final computed hash 12071 return new WordArray.init(hashWords, outputLengthBytes); 12072 }, 12073 12074 clone: function() { 12075 var clone = Hasher.clone.call(this); 12076 12077 var state = clone._state = this._state.slice(0); 12078 for (var i = 0; i < 25; i++) { 12079 state[i] = state[i].clone(); 12080 } 12081 12082 return clone; 12083 } 12084 }); 12085 12086 /** 12087 * Shortcut function to the hasher's object interface. 12088 * 12089 * @param {WordArray|string} message The message to hash. 12090 * 12091 * @return {WordArray} The hash. 12092 * 12093 * @static 12094 * 12095 * @example 12096 * 12097 * var hash = CryptoJS.SHA3('message'); 12098 * var hash = CryptoJS.SHA3(wordArray); 12099 */ 12100 C.SHA3 = Hasher._createHelper(SHA3); 12101 12102 /** 12103 * Shortcut function to the HMAC's object interface. 12104 * 12105 * @param {WordArray|string} message The message to hash. 12106 * @param {WordArray|string} key The secret key. 12107 * 12108 * @return {WordArray} The HMAC. 12109 * 12110 * @static 12111 * 12112 * @example 12113 * 12114 * var hmac = CryptoJS.HmacSHA3(message, key); 12115 */ 12116 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 12117 }(Math)); 12118 12119 12120 return CryptoJS.SHA3; 12121 12122 })); 12123 }, { 12124 "./core": 53, 12125 "./x64-core": 84 12126 }], 12127 81: [function(require, module, exports) {; 12128 (function(root, factory, undef) { 12129 if (typeof exports === "object") { 12130 // CommonJS 12131 module.exports = exports = factory(require("./core"), require("./x64-core"), require("./sha512")); 12132 } else if (typeof define === "function" && define.amd) { 12133 // AMD 12134 define(["./core", "./x64-core", "./sha512"], factory); 12135 } else { 12136 // Global (browser) 12137 factory(root.CryptoJS); 12138 } 12139 }(this, function(CryptoJS) { 12140 12141 (function() { 12142 // Shortcuts 12143 var C = CryptoJS; 12144 var C_x64 = C.x64; 12145 var X64Word = C_x64.Word; 12146 var X64WordArray = C_x64.WordArray; 12147 var C_algo = C.algo; 12148 var SHA512 = C_algo.SHA512; 12149 12150 /** 12151 * SHA-384 hash algorithm. 12152 */ 12153 var SHA384 = C_algo.SHA384 = SHA512.extend({ 12154 _doReset: function() { 12155 this._hash = new X64WordArray.init([ 12156 new X64Word.init(0xcbbb9d5d, 0xc1059ed8), new X64Word.init(0x629a292a, 0x367cd507), 12157 new X64Word.init(0x9159015a, 0x3070dd17), new X64Word.init(0x152fecd8, 0xf70e5939), 12158 new X64Word.init(0x67332667, 0xffc00b31), new X64Word.init(0x8eb44a87, 0x68581511), 12159 new X64Word.init(0xdb0c2e0d, 0x64f98fa7), new X64Word.init(0x47b5481d, 0xbefa4fa4) 12160 ]); 12161 }, 12162 12163 _doFinalize: function() { 12164 var hash = SHA512._doFinalize.call(this); 12165 12166 hash.sigBytes -= 16; 12167 12168 return hash; 12169 } 12170 }); 12171 12172 /** 12173 * Shortcut function to the hasher's object interface. 12174 * 12175 * @param {WordArray|string} message The message to hash. 12176 * 12177 * @return {WordArray} The hash. 12178 * 12179 * @static 12180 * 12181 * @example 12182 * 12183 * var hash = CryptoJS.SHA384('message'); 12184 * var hash = CryptoJS.SHA384(wordArray); 12185 */ 12186 C.SHA384 = SHA512._createHelper(SHA384); 12187 12188 /** 12189 * Shortcut function to the HMAC's object interface. 12190 * 12191 * @param {WordArray|string} message The message to hash. 12192 * @param {WordArray|string} key The secret key. 12193 * 12194 * @return {WordArray} The HMAC. 12195 * 12196 * @static 12197 * 12198 * @example 12199 * 12200 * var hmac = CryptoJS.HmacSHA384(message, key); 12201 */ 12202 C.HmacSHA384 = SHA512._createHmacHelper(SHA384); 12203 }()); 12204 12205 12206 return CryptoJS.SHA384; 12207 12208 })); 12209 }, { 12210 "./core": 53, 12211 "./sha512": 82, 12212 "./x64-core": 84 12213 }], 12214 82: [function(require, module, exports) {; 12215 (function(root, factory, undef) { 12216 if (typeof exports === "object") { 12217 // CommonJS 12218 module.exports = exports = factory(require("./core"), require("./x64-core")); 12219 } else if (typeof define === "function" && define.amd) { 12220 // AMD 12221 define(["./core", "./x64-core"], factory); 12222 } else { 12223 // Global (browser) 12224 factory(root.CryptoJS); 12225 } 12226 }(this, function(CryptoJS) { 12227 12228 (function() { 12229 // Shortcuts 12230 var C = CryptoJS; 12231 var C_lib = C.lib; 12232 var Hasher = C_lib.Hasher; 12233 var C_x64 = C.x64; 12234 var X64Word = C_x64.Word; 12235 var X64WordArray = C_x64.WordArray; 12236 var C_algo = C.algo; 12237 12238 function X64Word_create() { 12239 return X64Word.create.apply(X64Word, arguments); 12240 } 12241 12242 // Constants 12243 var K = [ 12244 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd), 12245 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc), 12246 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019), 12247 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118), 12248 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe), 12249 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2), 12250 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1), 12251 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694), 12252 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3), 12253 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65), 12254 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483), 12255 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5), 12256 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210), 12257 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4), 12258 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725), 12259 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70), 12260 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926), 12261 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df), 12262 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8), 12263 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b), 12264 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001), 12265 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30), 12266 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910), 12267 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8), 12268 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53), 12269 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8), 12270 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb), 12271 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3), 12272 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60), 12273 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec), 12274 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9), 12275 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b), 12276 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207), 12277 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178), 12278 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6), 12279 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b), 12280 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493), 12281 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c), 12282 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a), 12283 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817) 12284 ]; 12285 12286 // Reusable objects 12287 var W = []; 12288 (function() { 12289 for (var i = 0; i < 80; i++) { 12290 W[i] = X64Word_create(); 12291 } 12292 }()); 12293 12294 /** 12295 * SHA-512 hash algorithm. 12296 */ 12297 var SHA512 = C_algo.SHA512 = Hasher.extend({ 12298 _doReset: function() { 12299 this._hash = new X64WordArray.init([ 12300 new X64Word.init(0x6a09e667, 0xf3bcc908), new X64Word.init(0xbb67ae85, 0x84caa73b), 12301 new X64Word.init(0x3c6ef372, 0xfe94f82b), new X64Word.init(0xa54ff53a, 0x5f1d36f1), 12302 new X64Word.init(0x510e527f, 0xade682d1), new X64Word.init(0x9b05688c, 0x2b3e6c1f), 12303 new X64Word.init(0x1f83d9ab, 0xfb41bd6b), new X64Word.init(0x5be0cd19, 0x137e2179) 12304 ]); 12305 }, 12306 12307 _doProcessBlock: function(M, offset) { 12308 // Shortcuts 12309 var H = this._hash.words; 12310 12311 var H0 = H[0]; 12312 var H1 = H[1]; 12313 var H2 = H[2]; 12314 var H3 = H[3]; 12315 var H4 = H[4]; 12316 var H5 = H[5]; 12317 var H6 = H[6]; 12318 var H7 = H[7]; 12319 12320 var H0h = H0.high; 12321 var H0l = H0.low; 12322 var H1h = H1.high; 12323 var H1l = H1.low; 12324 var H2h = H2.high; 12325 var H2l = H2.low; 12326 var H3h = H3.high; 12327 var H3l = H3.low; 12328 var H4h = H4.high; 12329 var H4l = H4.low; 12330 var H5h = H5.high; 12331 var H5l = H5.low; 12332 var H6h = H6.high; 12333 var H6l = H6.low; 12334 var H7h = H7.high; 12335 var H7l = H7.low; 12336 12337 // Working variables 12338 var ah = H0h; 12339 var al = H0l; 12340 var bh = H1h; 12341 var bl = H1l; 12342 var ch = H2h; 12343 var cl = H2l; 12344 var dh = H3h; 12345 var dl = H3l; 12346 var eh = H4h; 12347 var el = H4l; 12348 var fh = H5h; 12349 var fl = H5l; 12350 var gh = H6h; 12351 var gl = H6l; 12352 var hh = H7h; 12353 var hl = H7l; 12354 12355 // Rounds 12356 for (var i = 0; i < 80; i++) { 12357 // Shortcut 12358 var Wi = W[i]; 12359 12360 // Extend message 12361 if (i < 16) { 12362 var Wih = Wi.high = M[offset + i * 2] | 0; 12363 var Wil = Wi.low = M[offset + i * 2 + 1] | 0; 12364 } else { 12365 // Gamma0 12366 var gamma0x = W[i - 15]; 12367 var gamma0xh = gamma0x.high; 12368 var gamma0xl = gamma0x.low; 12369 var gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); 12370 var gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); 12371 12372 // Gamma1 12373 var gamma1x = W[i - 2]; 12374 var gamma1xh = gamma1x.high; 12375 var gamma1xl = gamma1x.low; 12376 var gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); 12377 var gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); 12378 12379 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] 12380 var Wi7 = W[i - 7]; 12381 var Wi7h = Wi7.high; 12382 var Wi7l = Wi7.low; 12383 12384 var Wi16 = W[i - 16]; 12385 var Wi16h = Wi16.high; 12386 var Wi16l = Wi16.low; 12387 12388 var Wil = gamma0l + Wi7l; 12389 var Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); 12390 var Wil = Wil + gamma1l; 12391 var Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); 12392 var Wil = Wil + Wi16l; 12393 var Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); 12394 12395 Wi.high = Wih; 12396 Wi.low = Wil; 12397 } 12398 12399 var chh = (eh & fh) ^ (~eh & gh); 12400 var chl = (el & fl) ^ (~el & gl); 12401 var majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); 12402 var majl = (al & bl) ^ (al & cl) ^ (bl & cl); 12403 12404 var sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); 12405 var sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); 12406 var sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); 12407 var sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); 12408 12409 // t1 = h + sigma1 + ch + K[i] + W[i] 12410 var Ki = K[i]; 12411 var Kih = Ki.high; 12412 var Kil = Ki.low; 12413 12414 var t1l = hl + sigma1l; 12415 var t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); 12416 var t1l = t1l + chl; 12417 var t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); 12418 var t1l = t1l + Kil; 12419 var t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); 12420 var t1l = t1l + Wil; 12421 var t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); 12422 12423 // t2 = sigma0 + maj 12424 var t2l = sigma0l + majl; 12425 var t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); 12426 12427 // Update working variables 12428 hh = gh; 12429 hl = gl; 12430 gh = fh; 12431 gl = fl; 12432 fh = eh; 12433 fl = el; 12434 el = (dl + t1l) | 0; 12435 eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; 12436 dh = ch; 12437 dl = cl; 12438 ch = bh; 12439 cl = bl; 12440 bh = ah; 12441 bl = al; 12442 al = (t1l + t2l) | 0; 12443 ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; 12444 } 12445 12446 // Intermediate hash value 12447 H0l = H0.low = (H0l + al); 12448 H0.high = (H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0)); 12449 H1l = H1.low = (H1l + bl); 12450 H1.high = (H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0)); 12451 H2l = H2.low = (H2l + cl); 12452 H2.high = (H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0)); 12453 H3l = H3.low = (H3l + dl); 12454 H3.high = (H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0)); 12455 H4l = H4.low = (H4l + el); 12456 H4.high = (H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0)); 12457 H5l = H5.low = (H5l + fl); 12458 H5.high = (H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0)); 12459 H6l = H6.low = (H6l + gl); 12460 H6.high = (H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0)); 12461 H7l = H7.low = (H7l + hl); 12462 H7.high = (H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0)); 12463 }, 12464 12465 _doFinalize: function() { 12466 // Shortcuts 12467 var data = this._data; 12468 var dataWords = data.words; 12469 12470 var nBitsTotal = this._nDataBytes * 8; 12471 var nBitsLeft = data.sigBytes * 8; 12472 12473 // Add padding 12474 dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); 12475 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); 12476 dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; 12477 data.sigBytes = dataWords.length * 4; 12478 12479 // Hash final blocks 12480 this._process(); 12481 12482 // Convert hash to 32-bit word array before returning 12483 var hash = this._hash.toX32(); 12484 12485 // Return final computed hash 12486 return hash; 12487 }, 12488 12489 clone: function() { 12490 var clone = Hasher.clone.call(this); 12491 clone._hash = this._hash.clone(); 12492 12493 return clone; 12494 }, 12495 12496 blockSize: 1024 / 32 12497 }); 12498 12499 /** 12500 * Shortcut function to the hasher's object interface. 12501 * 12502 * @param {WordArray|string} message The message to hash. 12503 * 12504 * @return {WordArray} The hash. 12505 * 12506 * @static 12507 * 12508 * @example 12509 * 12510 * var hash = CryptoJS.SHA512('message'); 12511 * var hash = CryptoJS.SHA512(wordArray); 12512 */ 12513 C.SHA512 = Hasher._createHelper(SHA512); 12514 12515 /** 12516 * Shortcut function to the HMAC's object interface. 12517 * 12518 * @param {WordArray|string} message The message to hash. 12519 * @param {WordArray|string} key The secret key. 12520 * 12521 * @return {WordArray} The HMAC. 12522 * 12523 * @static 12524 * 12525 * @example 12526 * 12527 * var hmac = CryptoJS.HmacSHA512(message, key); 12528 */ 12529 C.HmacSHA512 = Hasher._createHmacHelper(SHA512); 12530 }()); 12531 12532 12533 return CryptoJS.SHA512; 12534 12535 })); 12536 }, { 12537 "./core": 53, 12538 "./x64-core": 84 12539 }], 12540 83: [function(require, module, exports) {; 12541 (function(root, factory, undef) { 12542 if (typeof exports === "object") { 12543 // CommonJS 12544 module.exports = exports = factory(require("./core"), require("./enc-base64"), require("./md5"), require("./evpkdf"), require("./cipher-core")); 12545 } else if (typeof define === "function" && define.amd) { 12546 // AMD 12547 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory); 12548 } else { 12549 // Global (browser) 12550 factory(root.CryptoJS); 12551 } 12552 }(this, function(CryptoJS) { 12553 12554 (function() { 12555 // Shortcuts 12556 var C = CryptoJS; 12557 var C_lib = C.lib; 12558 var WordArray = C_lib.WordArray; 12559 var BlockCipher = C_lib.BlockCipher; 12560 var C_algo = C.algo; 12561 12562 // Permuted Choice 1 constants 12563 var PC1 = [ 12564 57, 49, 41, 33, 25, 17, 9, 1, 12565 58, 50, 42, 34, 26, 18, 10, 2, 12566 59, 51, 43, 35, 27, 19, 11, 3, 12567 60, 52, 44, 36, 63, 55, 47, 39, 12568 31, 23, 15, 7, 62, 54, 46, 38, 12569 30, 22, 14, 6, 61, 53, 45, 37, 12570 29, 21, 13, 5, 28, 20, 12, 4 12571 ]; 12572 12573 // Permuted Choice 2 constants 12574 var PC2 = [ 12575 14, 17, 11, 24, 1, 5, 12576 3, 28, 15, 6, 21, 10, 12577 23, 19, 12, 4, 26, 8, 12578 16, 7, 27, 20, 13, 2, 12579 41, 52, 31, 37, 47, 55, 12580 30, 40, 51, 45, 33, 48, 12581 44, 49, 39, 56, 34, 53, 12582 46, 42, 50, 36, 29, 32 12583 ]; 12584 12585 // Cumulative bit shift constants 12586 var BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; 12587 12588 // SBOXes and round permutation constants 12589 var SBOX_P = [{ 12590 0x0: 0x808200, 12591 0x10000000: 0x8000, 12592 0x20000000: 0x808002, 12593 0x30000000: 0x2, 12594 0x40000000: 0x200, 12595 0x50000000: 0x808202, 12596 0x60000000: 0x800202, 12597 0x70000000: 0x800000, 12598 0x80000000: 0x202, 12599 0x90000000: 0x800200, 12600 0xa0000000: 0x8200, 12601 0xb0000000: 0x808000, 12602 0xc0000000: 0x8002, 12603 0xd0000000: 0x800002, 12604 0xe0000000: 0x0, 12605 0xf0000000: 0x8202, 12606 0x8000000: 0x0, 12607 0x18000000: 0x808202, 12608 0x28000000: 0x8202, 12609 0x38000000: 0x8000, 12610 0x48000000: 0x808200, 12611 0x58000000: 0x200, 12612 0x68000000: 0x808002, 12613 0x78000000: 0x2, 12614 0x88000000: 0x800200, 12615 0x98000000: 0x8200, 12616 0xa8000000: 0x808000, 12617 0xb8000000: 0x800202, 12618 0xc8000000: 0x800002, 12619 0xd8000000: 0x8002, 12620 0xe8000000: 0x202, 12621 0xf8000000: 0x800000, 12622 0x1: 0x8000, 12623 0x10000001: 0x2, 12624 0x20000001: 0x808200, 12625 0x30000001: 0x800000, 12626 0x40000001: 0x808002, 12627 0x50000001: 0x8200, 12628 0x60000001: 0x200, 12629 0x70000001: 0x800202, 12630 0x80000001: 0x808202, 12631 0x90000001: 0x808000, 12632 0xa0000001: 0x800002, 12633 0xb0000001: 0x8202, 12634 0xc0000001: 0x202, 12635 0xd0000001: 0x800200, 12636 0xe0000001: 0x8002, 12637 0xf0000001: 0x0, 12638 0x8000001: 0x808202, 12639 0x18000001: 0x808000, 12640 0x28000001: 0x800000, 12641 0x38000001: 0x200, 12642 0x48000001: 0x8000, 12643 0x58000001: 0x800002, 12644 0x68000001: 0x2, 12645 0x78000001: 0x8202, 12646 0x88000001: 0x8002, 12647 0x98000001: 0x800202, 12648 0xa8000001: 0x202, 12649 0xb8000001: 0x808200, 12650 0xc8000001: 0x800200, 12651 0xd8000001: 0x0, 12652 0xe8000001: 0x8200, 12653 0xf8000001: 0x808002 12654 }, { 12655 0x0: 0x40084010, 12656 0x1000000: 0x4000, 12657 0x2000000: 0x80000, 12658 0x3000000: 0x40080010, 12659 0x4000000: 0x40000010, 12660 0x5000000: 0x40084000, 12661 0x6000000: 0x40004000, 12662 0x7000000: 0x10, 12663 0x8000000: 0x84000, 12664 0x9000000: 0x40004010, 12665 0xa000000: 0x40000000, 12666 0xb000000: 0x84010, 12667 0xc000000: 0x80010, 12668 0xd000000: 0x0, 12669 0xe000000: 0x4010, 12670 0xf000000: 0x40080000, 12671 0x800000: 0x40004000, 12672 0x1800000: 0x84010, 12673 0x2800000: 0x10, 12674 0x3800000: 0x40004010, 12675 0x4800000: 0x40084010, 12676 0x5800000: 0x40000000, 12677 0x6800000: 0x80000, 12678 0x7800000: 0x40080010, 12679 0x8800000: 0x80010, 12680 0x9800000: 0x0, 12681 0xa800000: 0x4000, 12682 0xb800000: 0x40080000, 12683 0xc800000: 0x40000010, 12684 0xd800000: 0x84000, 12685 0xe800000: 0x40084000, 12686 0xf800000: 0x4010, 12687 0x10000000: 0x0, 12688 0x11000000: 0x40080010, 12689 0x12000000: 0x40004010, 12690 0x13000000: 0x40084000, 12691 0x14000000: 0x40080000, 12692 0x15000000: 0x10, 12693 0x16000000: 0x84010, 12694 0x17000000: 0x4000, 12695 0x18000000: 0x4010, 12696 0x19000000: 0x80000, 12697 0x1a000000: 0x80010, 12698 0x1b000000: 0x40000010, 12699 0x1c000000: 0x84000, 12700 0x1d000000: 0x40004000, 12701 0x1e000000: 0x40000000, 12702 0x1f000000: 0x40084010, 12703 0x10800000: 0x84010, 12704 0x11800000: 0x80000, 12705 0x12800000: 0x40080000, 12706 0x13800000: 0x4000, 12707 0x14800000: 0x40004000, 12708 0x15800000: 0x40084010, 12709 0x16800000: 0x10, 12710 0x17800000: 0x40000000, 12711 0x18800000: 0x40084000, 12712 0x19800000: 0x40000010, 12713 0x1a800000: 0x40004010, 12714 0x1b800000: 0x80010, 12715 0x1c800000: 0x0, 12716 0x1d800000: 0x4010, 12717 0x1e800000: 0x40080010, 12718 0x1f800000: 0x84000 12719 }, { 12720 0x0: 0x104, 12721 0x100000: 0x0, 12722 0x200000: 0x4000100, 12723 0x300000: 0x10104, 12724 0x400000: 0x10004, 12725 0x500000: 0x4000004, 12726 0x600000: 0x4010104, 12727 0x700000: 0x4010000, 12728 0x800000: 0x4000000, 12729 0x900000: 0x4010100, 12730 0xa00000: 0x10100, 12731 0xb00000: 0x4010004, 12732 0xc00000: 0x4000104, 12733 0xd00000: 0x10000, 12734 0xe00000: 0x4, 12735 0xf00000: 0x100, 12736 0x80000: 0x4010100, 12737 0x180000: 0x4010004, 12738 0x280000: 0x0, 12739 0x380000: 0x4000100, 12740 0x480000: 0x4000004, 12741 0x580000: 0x10000, 12742 0x680000: 0x10004, 12743 0x780000: 0x104, 12744 0x880000: 0x4, 12745 0x980000: 0x100, 12746 0xa80000: 0x4010000, 12747 0xb80000: 0x10104, 12748 0xc80000: 0x10100, 12749 0xd80000: 0x4000104, 12750 0xe80000: 0x4010104, 12751 0xf80000: 0x4000000, 12752 0x1000000: 0x4010100, 12753 0x1100000: 0x10004, 12754 0x1200000: 0x10000, 12755 0x1300000: 0x4000100, 12756 0x1400000: 0x100, 12757 0x1500000: 0x4010104, 12758 0x1600000: 0x4000004, 12759 0x1700000: 0x0, 12760 0x1800000: 0x4000104, 12761 0x1900000: 0x4000000, 12762 0x1a00000: 0x4, 12763 0x1b00000: 0x10100, 12764 0x1c00000: 0x4010000, 12765 0x1d00000: 0x104, 12766 0x1e00000: 0x10104, 12767 0x1f00000: 0x4010004, 12768 0x1080000: 0x4000000, 12769 0x1180000: 0x104, 12770 0x1280000: 0x4010100, 12771 0x1380000: 0x0, 12772 0x1480000: 0x10004, 12773 0x1580000: 0x4000100, 12774 0x1680000: 0x100, 12775 0x1780000: 0x4010004, 12776 0x1880000: 0x10000, 12777 0x1980000: 0x4010104, 12778 0x1a80000: 0x10104, 12779 0x1b80000: 0x4000004, 12780 0x1c80000: 0x4000104, 12781 0x1d80000: 0x4010000, 12782 0x1e80000: 0x4, 12783 0x1f80000: 0x10100 12784 }, { 12785 0x0: 0x80401000, 12786 0x10000: 0x80001040, 12787 0x20000: 0x401040, 12788 0x30000: 0x80400000, 12789 0x40000: 0x0, 12790 0x50000: 0x401000, 12791 0x60000: 0x80000040, 12792 0x70000: 0x400040, 12793 0x80000: 0x80000000, 12794 0x90000: 0x400000, 12795 0xa0000: 0x40, 12796 0xb0000: 0x80001000, 12797 0xc0000: 0x80400040, 12798 0xd0000: 0x1040, 12799 0xe0000: 0x1000, 12800 0xf0000: 0x80401040, 12801 0x8000: 0x80001040, 12802 0x18000: 0x40, 12803 0x28000: 0x80400040, 12804 0x38000: 0x80001000, 12805 0x48000: 0x401000, 12806 0x58000: 0x80401040, 12807 0x68000: 0x0, 12808 0x78000: 0x80400000, 12809 0x88000: 0x1000, 12810 0x98000: 0x80401000, 12811 0xa8000: 0x400000, 12812 0xb8000: 0x1040, 12813 0xc8000: 0x80000000, 12814 0xd8000: 0x400040, 12815 0xe8000: 0x401040, 12816 0xf8000: 0x80000040, 12817 0x100000: 0x400040, 12818 0x110000: 0x401000, 12819 0x120000: 0x80000040, 12820 0x130000: 0x0, 12821 0x140000: 0x1040, 12822 0x150000: 0x80400040, 12823 0x160000: 0x80401000, 12824 0x170000: 0x80001040, 12825 0x180000: 0x80401040, 12826 0x190000: 0x80000000, 12827 0x1a0000: 0x80400000, 12828 0x1b0000: 0x401040, 12829 0x1c0000: 0x80001000, 12830 0x1d0000: 0x400000, 12831 0x1e0000: 0x40, 12832 0x1f0000: 0x1000, 12833 0x108000: 0x80400000, 12834 0x118000: 0x80401040, 12835 0x128000: 0x0, 12836 0x138000: 0x401000, 12837 0x148000: 0x400040, 12838 0x158000: 0x80000000, 12839 0x168000: 0x80001040, 12840 0x178000: 0x40, 12841 0x188000: 0x80000040, 12842 0x198000: 0x1000, 12843 0x1a8000: 0x80001000, 12844 0x1b8000: 0x80400040, 12845 0x1c8000: 0x1040, 12846 0x1d8000: 0x80401000, 12847 0x1e8000: 0x400000, 12848 0x1f8000: 0x401040 12849 }, { 12850 0x0: 0x80, 12851 0x1000: 0x1040000, 12852 0x2000: 0x40000, 12853 0x3000: 0x20000000, 12854 0x4000: 0x20040080, 12855 0x5000: 0x1000080, 12856 0x6000: 0x21000080, 12857 0x7000: 0x40080, 12858 0x8000: 0x1000000, 12859 0x9000: 0x20040000, 12860 0xa000: 0x20000080, 12861 0xb000: 0x21040080, 12862 0xc000: 0x21040000, 12863 0xd000: 0x0, 12864 0xe000: 0x1040080, 12865 0xf000: 0x21000000, 12866 0x800: 0x1040080, 12867 0x1800: 0x21000080, 12868 0x2800: 0x80, 12869 0x3800: 0x1040000, 12870 0x4800: 0x40000, 12871 0x5800: 0x20040080, 12872 0x6800: 0x21040000, 12873 0x7800: 0x20000000, 12874 0x8800: 0x20040000, 12875 0x9800: 0x0, 12876 0xa800: 0x21040080, 12877 0xb800: 0x1000080, 12878 0xc800: 0x20000080, 12879 0xd800: 0x21000000, 12880 0xe800: 0x1000000, 12881 0xf800: 0x40080, 12882 0x10000: 0x40000, 12883 0x11000: 0x80, 12884 0x12000: 0x20000000, 12885 0x13000: 0x21000080, 12886 0x14000: 0x1000080, 12887 0x15000: 0x21040000, 12888 0x16000: 0x20040080, 12889 0x17000: 0x1000000, 12890 0x18000: 0x21040080, 12891 0x19000: 0x21000000, 12892 0x1a000: 0x1040000, 12893 0x1b000: 0x20040000, 12894 0x1c000: 0x40080, 12895 0x1d000: 0x20000080, 12896 0x1e000: 0x0, 12897 0x1f000: 0x1040080, 12898 0x10800: 0x21000080, 12899 0x11800: 0x1000000, 12900 0x12800: 0x1040000, 12901 0x13800: 0x20040080, 12902 0x14800: 0x20000000, 12903 0x15800: 0x1040080, 12904 0x16800: 0x80, 12905 0x17800: 0x21040000, 12906 0x18800: 0x40080, 12907 0x19800: 0x21040080, 12908 0x1a800: 0x0, 12909 0x1b800: 0x21000000, 12910 0x1c800: 0x1000080, 12911 0x1d800: 0x40000, 12912 0x1e800: 0x20040000, 12913 0x1f800: 0x20000080 12914 }, { 12915 0x0: 0x10000008, 12916 0x100: 0x2000, 12917 0x200: 0x10200000, 12918 0x300: 0x10202008, 12919 0x400: 0x10002000, 12920 0x500: 0x200000, 12921 0x600: 0x200008, 12922 0x700: 0x10000000, 12923 0x800: 0x0, 12924 0x900: 0x10002008, 12925 0xa00: 0x202000, 12926 0xb00: 0x8, 12927 0xc00: 0x10200008, 12928 0xd00: 0x202008, 12929 0xe00: 0x2008, 12930 0xf00: 0x10202000, 12931 0x80: 0x10200000, 12932 0x180: 0x10202008, 12933 0x280: 0x8, 12934 0x380: 0x200000, 12935 0x480: 0x202008, 12936 0x580: 0x10000008, 12937 0x680: 0x10002000, 12938 0x780: 0x2008, 12939 0x880: 0x200008, 12940 0x980: 0x2000, 12941 0xa80: 0x10002008, 12942 0xb80: 0x10200008, 12943 0xc80: 0x0, 12944 0xd80: 0x10202000, 12945 0xe80: 0x202000, 12946 0xf80: 0x10000000, 12947 0x1000: 0x10002000, 12948 0x1100: 0x10200008, 12949 0x1200: 0x10202008, 12950 0x1300: 0x2008, 12951 0x1400: 0x200000, 12952 0x1500: 0x10000000, 12953 0x1600: 0x10000008, 12954 0x1700: 0x202000, 12955 0x1800: 0x202008, 12956 0x1900: 0x0, 12957 0x1a00: 0x8, 12958 0x1b00: 0x10200000, 12959 0x1c00: 0x2000, 12960 0x1d00: 0x10002008, 12961 0x1e00: 0x10202000, 12962 0x1f00: 0x200008, 12963 0x1080: 0x8, 12964 0x1180: 0x202000, 12965 0x1280: 0x200000, 12966 0x1380: 0x10000008, 12967 0x1480: 0x10002000, 12968 0x1580: 0x2008, 12969 0x1680: 0x10202008, 12970 0x1780: 0x10200000, 12971 0x1880: 0x10202000, 12972 0x1980: 0x10200008, 12973 0x1a80: 0x2000, 12974 0x1b80: 0x202008, 12975 0x1c80: 0x200008, 12976 0x1d80: 0x0, 12977 0x1e80: 0x10000000, 12978 0x1f80: 0x10002008 12979 }, { 12980 0x0: 0x100000, 12981 0x10: 0x2000401, 12982 0x20: 0x400, 12983 0x30: 0x100401, 12984 0x40: 0x2100401, 12985 0x50: 0x0, 12986 0x60: 0x1, 12987 0x70: 0x2100001, 12988 0x80: 0x2000400, 12989 0x90: 0x100001, 12990 0xa0: 0x2000001, 12991 0xb0: 0x2100400, 12992 0xc0: 0x2100000, 12993 0xd0: 0x401, 12994 0xe0: 0x100400, 12995 0xf0: 0x2000000, 12996 0x8: 0x2100001, 12997 0x18: 0x0, 12998 0x28: 0x2000401, 12999 0x38: 0x2100400, 13000 0x48: 0x100000, 13001 0x58: 0x2000001, 13002 0x68: 0x2000000, 13003 0x78: 0x401, 13004 0x88: 0x100401, 13005 0x98: 0x2000400, 13006 0xa8: 0x2100000, 13007 0xb8: 0x100001, 13008 0xc8: 0x400, 13009 0xd8: 0x2100401, 13010 0xe8: 0x1, 13011 0xf8: 0x100400, 13012 0x100: 0x2000000, 13013 0x110: 0x100000, 13014 0x120: 0x2000401, 13015 0x130: 0x2100001, 13016 0x140: 0x100001, 13017 0x150: 0x2000400, 13018 0x160: 0x2100400, 13019 0x170: 0x100401, 13020 0x180: 0x401, 13021 0x190: 0x2100401, 13022 0x1a0: 0x100400, 13023 0x1b0: 0x1, 13024 0x1c0: 0x0, 13025 0x1d0: 0x2100000, 13026 0x1e0: 0x2000001, 13027 0x1f0: 0x400, 13028 0x108: 0x100400, 13029 0x118: 0x2000401, 13030 0x128: 0x2100001, 13031 0x138: 0x1, 13032 0x148: 0x2000000, 13033 0x158: 0x100000, 13034 0x168: 0x401, 13035 0x178: 0x2100400, 13036 0x188: 0x2000001, 13037 0x198: 0x2100000, 13038 0x1a8: 0x0, 13039 0x1b8: 0x2100401, 13040 0x1c8: 0x100401, 13041 0x1d8: 0x400, 13042 0x1e8: 0x2000400, 13043 0x1f8: 0x100001 13044 }, { 13045 0x0: 0x8000820, 13046 0x1: 0x20000, 13047 0x2: 0x8000000, 13048 0x3: 0x20, 13049 0x4: 0x20020, 13050 0x5: 0x8020820, 13051 0x6: 0x8020800, 13052 0x7: 0x800, 13053 0x8: 0x8020000, 13054 0x9: 0x8000800, 13055 0xa: 0x20800, 13056 0xb: 0x8020020, 13057 0xc: 0x820, 13058 0xd: 0x0, 13059 0xe: 0x8000020, 13060 0xf: 0x20820, 13061 0x80000000: 0x800, 13062 0x80000001: 0x8020820, 13063 0x80000002: 0x8000820, 13064 0x80000003: 0x8000000, 13065 0x80000004: 0x8020000, 13066 0x80000005: 0x20800, 13067 0x80000006: 0x20820, 13068 0x80000007: 0x20, 13069 0x80000008: 0x8000020, 13070 0x80000009: 0x820, 13071 0x8000000a: 0x20020, 13072 0x8000000b: 0x8020800, 13073 0x8000000c: 0x0, 13074 0x8000000d: 0x8020020, 13075 0x8000000e: 0x8000800, 13076 0x8000000f: 0x20000, 13077 0x10: 0x20820, 13078 0x11: 0x8020800, 13079 0x12: 0x20, 13080 0x13: 0x800, 13081 0x14: 0x8000800, 13082 0x15: 0x8000020, 13083 0x16: 0x8020020, 13084 0x17: 0x20000, 13085 0x18: 0x0, 13086 0x19: 0x20020, 13087 0x1a: 0x8020000, 13088 0x1b: 0x8000820, 13089 0x1c: 0x8020820, 13090 0x1d: 0x20800, 13091 0x1e: 0x820, 13092 0x1f: 0x8000000, 13093 0x80000010: 0x20000, 13094 0x80000011: 0x800, 13095 0x80000012: 0x8020020, 13096 0x80000013: 0x20820, 13097 0x80000014: 0x20, 13098 0x80000015: 0x8020000, 13099 0x80000016: 0x8000000, 13100 0x80000017: 0x8000820, 13101 0x80000018: 0x8020820, 13102 0x80000019: 0x8000020, 13103 0x8000001a: 0x8000800, 13104 0x8000001b: 0x0, 13105 0x8000001c: 0x20800, 13106 0x8000001d: 0x820, 13107 0x8000001e: 0x20020, 13108 0x8000001f: 0x8020800 13109 }]; 13110 13111 // Masks that select the SBOX input 13112 var SBOX_MASK = [ 13113 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, 13114 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f 13115 ]; 13116 13117 /** 13118 * DES block cipher algorithm. 13119 */ 13120 var DES = C_algo.DES = BlockCipher.extend({ 13121 _doReset: function() { 13122 // Shortcuts 13123 var key = this._key; 13124 var keyWords = key.words; 13125 13126 // Select 56 bits according to PC1 13127 var keyBits = []; 13128 for (var i = 0; i < 56; i++) { 13129 var keyBitPos = PC1[i] - 1; 13130 keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; 13131 } 13132 13133 // Assemble 16 subkeys 13134 var subKeys = this._subKeys = []; 13135 for (var nSubKey = 0; nSubKey < 16; nSubKey++) { 13136 // Create subkey 13137 var subKey = subKeys[nSubKey] = []; 13138 13139 // Shortcut 13140 var bitShift = BIT_SHIFTS[nSubKey]; 13141 13142 // Select 48 bits according to PC2 13143 for (var i = 0; i < 24; i++) { 13144 // Select from the left 28 key bits 13145 subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); 13146 13147 // Select from the right 28 key bits 13148 subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); 13149 } 13150 13151 // Since each subkey is applied to an expanded 32-bit input, 13152 // the subkey can be broken into 8 values scaled to 32-bits, 13153 // which allows the key to be used without expansion 13154 subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); 13155 for (var i = 1; i < 7; i++) { 13156 subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); 13157 } 13158 subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); 13159 } 13160 13161 // Compute inverse subkeys 13162 var invSubKeys = this._invSubKeys = []; 13163 for (var i = 0; i < 16; i++) { 13164 invSubKeys[i] = subKeys[15 - i]; 13165 } 13166 }, 13167 13168 encryptBlock: function(M, offset) { 13169 this._doCryptBlock(M, offset, this._subKeys); 13170 }, 13171 13172 decryptBlock: function(M, offset) { 13173 this._doCryptBlock(M, offset, this._invSubKeys); 13174 }, 13175 13176 _doCryptBlock: function(M, offset, subKeys) { 13177 // Get input 13178 this._lBlock = M[offset]; 13179 this._rBlock = M[offset + 1]; 13180 13181 // Initial permutation 13182 exchangeLR.call(this, 4, 0x0f0f0f0f); 13183 exchangeLR.call(this, 16, 0x0000ffff); 13184 exchangeRL.call(this, 2, 0x33333333); 13185 exchangeRL.call(this, 8, 0x00ff00ff); 13186 exchangeLR.call(this, 1, 0x55555555); 13187 13188 // Rounds 13189 for (var round = 0; round < 16; round++) { 13190 // Shortcuts 13191 var subKey = subKeys[round]; 13192 var lBlock = this._lBlock; 13193 var rBlock = this._rBlock; 13194 13195 // Feistel function 13196 var f = 0; 13197 for (var i = 0; i < 8; i++) { 13198 f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; 13199 } 13200 this._lBlock = rBlock; 13201 this._rBlock = lBlock ^ f; 13202 } 13203 13204 // Undo swap from last round 13205 var t = this._lBlock; 13206 this._lBlock = this._rBlock; 13207 this._rBlock = t; 13208 13209 // Final permutation 13210 exchangeLR.call(this, 1, 0x55555555); 13211 exchangeRL.call(this, 8, 0x00ff00ff); 13212 exchangeRL.call(this, 2, 0x33333333); 13213 exchangeLR.call(this, 16, 0x0000ffff); 13214 exchangeLR.call(this, 4, 0x0f0f0f0f); 13215 13216 // Set output 13217 M[offset] = this._lBlock; 13218 M[offset + 1] = this._rBlock; 13219 }, 13220 13221 keySize: 64 / 32, 13222 13223 ivSize: 64 / 32, 13224 13225 blockSize: 64 / 32 13226 }); 13227 13228 // Swap bits across the left and right words 13229 function exchangeLR(offset, mask) { 13230 var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; 13231 this._rBlock ^= t; 13232 this._lBlock ^= t << offset; 13233 } 13234 13235 function exchangeRL(offset, mask) { 13236 var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; 13237 this._lBlock ^= t; 13238 this._rBlock ^= t << offset; 13239 } 13240 13241 /** 13242 * Shortcut functions to the cipher's object interface. 13243 * 13244 * @example 13245 * 13246 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg); 13247 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg); 13248 */ 13249 C.DES = BlockCipher._createHelper(DES); 13250 13251 /** 13252 * Triple-DES block cipher algorithm. 13253 */ 13254 var TripleDES = C_algo.TripleDES = BlockCipher.extend({ 13255 _doReset: function() { 13256 // Shortcuts 13257 var key = this._key; 13258 var keyWords = key.words; 13259 13260 // Create DES instances 13261 this._des1 = DES.createEncryptor(WordArray.create(keyWords.slice(0, 2))); 13262 this._des2 = DES.createEncryptor(WordArray.create(keyWords.slice(2, 4))); 13263 this._des3 = DES.createEncryptor(WordArray.create(keyWords.slice(4, 6))); 13264 }, 13265 13266 encryptBlock: function(M, offset) { 13267 this._des1.encryptBlock(M, offset); 13268 this._des2.decryptBlock(M, offset); 13269 this._des3.encryptBlock(M, offset); 13270 }, 13271 13272 decryptBlock: function(M, offset) { 13273 this._des3.decryptBlock(M, offset); 13274 this._des2.encryptBlock(M, offset); 13275 this._des1.decryptBlock(M, offset); 13276 }, 13277 13278 keySize: 192 / 32, 13279 13280 ivSize: 64 / 32, 13281 13282 blockSize: 64 / 32 13283 }); 13284 13285 /** 13286 * Shortcut functions to the cipher's object interface. 13287 * 13288 * @example 13289 * 13290 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg); 13291 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg); 13292 */ 13293 C.TripleDES = BlockCipher._createHelper(TripleDES); 13294 }()); 13295 13296 13297 return CryptoJS.TripleDES; 13298 13299 })); 13300 }, { 13301 "./cipher-core": 52, 13302 "./core": 53, 13303 "./enc-base64": 54, 13304 "./evpkdf": 56, 13305 "./md5": 61 13306 }], 13307 84: [function(require, module, exports) {; 13308 (function(root, factory) { 13309 if (typeof exports === "object") { 13310 // CommonJS 13311 module.exports = exports = factory(require("./core")); 13312 } else if (typeof define === "function" && define.amd) { 13313 // AMD 13314 define(["./core"], factory); 13315 } else { 13316 // Global (browser) 13317 factory(root.CryptoJS); 13318 } 13319 }(this, function(CryptoJS) { 13320 13321 (function(undefined) { 13322 // Shortcuts 13323 var C = CryptoJS; 13324 var C_lib = C.lib; 13325 var Base = C_lib.Base; 13326 var X32WordArray = C_lib.WordArray; 13327 13328 /** 13329 * x64 namespace. 13330 */ 13331 var C_x64 = C.x64 = {}; 13332 13333 /** 13334 * A 64-bit word. 13335 */ 13336 var X64Word = C_x64.Word = Base.extend({ 13337 /** 13338 * Initializes a newly created 64-bit word. 13339 * 13340 * @param {number} high The high 32 bits. 13341 * @param {number} low The low 32 bits. 13342 * 13343 * @example 13344 * 13345 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 13346 */ 13347 init: function(high, low) { 13348 this.high = high; 13349 this.low = low; 13350 } 13351 13352 /** 13353 * Bitwise NOTs this word. 13354 * 13355 * @return {X64Word} A new x64-Word object after negating. 13356 * 13357 * @example 13358 * 13359 * var negated = x64Word.not(); 13360 */ 13361 // not: function () { 13362 // var high = ~this.high; 13363 // var low = ~this.low; 13364 13365 // return X64Word.create(high, low); 13366 // }, 13367 13368 /** 13369 * Bitwise ANDs this word with the passed word. 13370 * 13371 * @param {X64Word} word The x64-Word to AND with this word. 13372 * 13373 * @return {X64Word} A new x64-Word object after ANDing. 13374 * 13375 * @example 13376 * 13377 * var anded = x64Word.and(anotherX64Word); 13378 */ 13379 // and: function (word) { 13380 // var high = this.high & word.high; 13381 // var low = this.low & word.low; 13382 13383 // return X64Word.create(high, low); 13384 // }, 13385 13386 /** 13387 * Bitwise ORs this word with the passed word. 13388 * 13389 * @param {X64Word} word The x64-Word to OR with this word. 13390 * 13391 * @return {X64Word} A new x64-Word object after ORing. 13392 * 13393 * @example 13394 * 13395 * var ored = x64Word.or(anotherX64Word); 13396 */ 13397 // or: function (word) { 13398 // var high = this.high | word.high; 13399 // var low = this.low | word.low; 13400 13401 // return X64Word.create(high, low); 13402 // }, 13403 13404 /** 13405 * Bitwise XORs this word with the passed word. 13406 * 13407 * @param {X64Word} word The x64-Word to XOR with this word. 13408 * 13409 * @return {X64Word} A new x64-Word object after XORing. 13410 * 13411 * @example 13412 * 13413 * var xored = x64Word.xor(anotherX64Word); 13414 */ 13415 // xor: function (word) { 13416 // var high = this.high ^ word.high; 13417 // var low = this.low ^ word.low; 13418 13419 // return X64Word.create(high, low); 13420 // }, 13421 13422 /** 13423 * Shifts this word n bits to the left. 13424 * 13425 * @param {number} n The number of bits to shift. 13426 * 13427 * @return {X64Word} A new x64-Word object after shifting. 13428 * 13429 * @example 13430 * 13431 * var shifted = x64Word.shiftL(25); 13432 */ 13433 // shiftL: function (n) { 13434 // if (n < 32) { 13435 // var high = (this.high << n) | (this.low >>> (32 - n)); 13436 // var low = this.low << n; 13437 // } else { 13438 // var high = this.low << (n - 32); 13439 // var low = 0; 13440 // } 13441 13442 // return X64Word.create(high, low); 13443 // }, 13444 13445 /** 13446 * Shifts this word n bits to the right. 13447 * 13448 * @param {number} n The number of bits to shift. 13449 * 13450 * @return {X64Word} A new x64-Word object after shifting. 13451 * 13452 * @example 13453 * 13454 * var shifted = x64Word.shiftR(7); 13455 */ 13456 // shiftR: function (n) { 13457 // if (n < 32) { 13458 // var low = (this.low >>> n) | (this.high << (32 - n)); 13459 // var high = this.high >>> n; 13460 // } else { 13461 // var low = this.high >>> (n - 32); 13462 // var high = 0; 13463 // } 13464 13465 // return X64Word.create(high, low); 13466 // }, 13467 13468 /** 13469 * Rotates this word n bits to the left. 13470 * 13471 * @param {number} n The number of bits to rotate. 13472 * 13473 * @return {X64Word} A new x64-Word object after rotating. 13474 * 13475 * @example 13476 * 13477 * var rotated = x64Word.rotL(25); 13478 */ 13479 // rotL: function (n) { 13480 // return this.shiftL(n).or(this.shiftR(64 - n)); 13481 // }, 13482 13483 /** 13484 * Rotates this word n bits to the right. 13485 * 13486 * @param {number} n The number of bits to rotate. 13487 * 13488 * @return {X64Word} A new x64-Word object after rotating. 13489 * 13490 * @example 13491 * 13492 * var rotated = x64Word.rotR(7); 13493 */ 13494 // rotR: function (n) { 13495 // return this.shiftR(n).or(this.shiftL(64 - n)); 13496 // }, 13497 13498 /** 13499 * Adds this word with the passed word. 13500 * 13501 * @param {X64Word} word The x64-Word to add with this word. 13502 * 13503 * @return {X64Word} A new x64-Word object after adding. 13504 * 13505 * @example 13506 * 13507 * var added = x64Word.add(anotherX64Word); 13508 */ 13509 // add: function (word) { 13510 // var low = (this.low + word.low) | 0; 13511 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 13512 // var high = (this.high + word.high + carry) | 0; 13513 13514 // return X64Word.create(high, low); 13515 // } 13516 }); 13517 13518 /** 13519 * An array of 64-bit words. 13520 * 13521 * @property {Array} words The array of CryptoJS.x64.Word objects. 13522 * @property {number} sigBytes The number of significant bytes in this word array. 13523 */ 13524 var X64WordArray = C_x64.WordArray = Base.extend({ 13525 /** 13526 * Initializes a newly created word array. 13527 * 13528 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 13529 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 13530 * 13531 * @example 13532 * 13533 * var wordArray = CryptoJS.x64.WordArray.create(); 13534 * 13535 * var wordArray = CryptoJS.x64.WordArray.create([ 13536 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13537 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13538 * ]); 13539 * 13540 * var wordArray = CryptoJS.x64.WordArray.create([ 13541 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 13542 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 13543 * ], 10); 13544 */ 13545 init: function(words, sigBytes) { 13546 words = this.words = words || []; 13547 13548 if (sigBytes != undefined) { 13549 this.sigBytes = sigBytes; 13550 } else { 13551 this.sigBytes = words.length * 8; 13552 } 13553 }, 13554 13555 /** 13556 * Converts this 64-bit word array to a 32-bit word array. 13557 * 13558 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 13559 * 13560 * @example 13561 * 13562 * var x32WordArray = x64WordArray.toX32(); 13563 */ 13564 toX32: function() { 13565 // Shortcuts 13566 var x64Words = this.words; 13567 var x64WordsLength = x64Words.length; 13568 13569 // Convert 13570 var x32Words = []; 13571 for (var i = 0; i < x64WordsLength; i++) { 13572 var x64Word = x64Words[i]; 13573 x32Words.push(x64Word.high); 13574 x32Words.push(x64Word.low); 13575 } 13576 13577 return X32WordArray.create(x32Words, this.sigBytes); 13578 }, 13579 13580 /** 13581 * Creates a copy of this word array. 13582 * 13583 * @return {X64WordArray} The clone. 13584 * 13585 * @example 13586 * 13587 * var clone = x64WordArray.clone(); 13588 */ 13589 clone: function() { 13590 var clone = Base.clone.call(this); 13591 13592 // Clone "words" array 13593 var words = clone.words = this.words.slice(0); 13594 13595 // Clone each X64Word object 13596 var wordsLength = words.length; 13597 for (var i = 0; i < wordsLength; i++) { 13598 words[i] = words[i].clone(); 13599 } 13600 13601 return clone; 13602 } 13603 }); 13604 }()); 13605 13606 13607 return CryptoJS; 13608 13609 })); 13610 }, { 13611 "./core": 53 13612 }], 13613 85: [function(require, module, exports) { 13614 /*! https://mths.be/utf8js v2.1.2 by @mathias */ 13615 ; 13616 (function(root) { 13617 13618 // Detect free variables `exports` 13619 var freeExports = typeof exports == 'object' && exports; 13620 13621 // Detect free variable `module` 13622 var freeModule = typeof module == 'object' && module && 13623 module.exports == freeExports && module; 13624 13625 // Detect free variable `global`, from Node.js or Browserified code, 13626 // and use it as `root` 13627 var freeGlobal = typeof global == 'object' && global; 13628 if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) { 13629 root = freeGlobal; 13630 } 13631 13632 /*--------------------------------------------------------------------------*/ 13633 13634 var stringFromCharCode = String.fromCharCode; 13635 13636 // Taken from https://mths.be/punycode 13637 function ucs2decode(string) { 13638 var output = []; 13639 var counter = 0; 13640 var length = string.length; 13641 var value; 13642 var extra; 13643 while (counter < length) { 13644 value = string.charCodeAt(counter++); 13645 if (value >= 0xD800 && value <= 0xDBFF && counter < length) { 13646 // high surrogate, and there is a next character 13647 extra = string.charCodeAt(counter++); 13648 if ((extra & 0xFC00) == 0xDC00) { // low surrogate 13649 output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000); 13650 } else { 13651 // unmatched surrogate; only append this code unit, in case the next 13652 // code unit is the high surrogate of a surrogate pair 13653 output.push(value); 13654 counter--; 13655 } 13656 } else { 13657 output.push(value); 13658 } 13659 } 13660 return output; 13661 } 13662 13663 // Taken from https://mths.be/punycode 13664 function ucs2encode(array) { 13665 var length = array.length; 13666 var index = -1; 13667 var value; 13668 var output = ''; 13669 while (++index < length) { 13670 value = array[index]; 13671 if (value > 0xFFFF) { 13672 value -= 0x10000; 13673 output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800); 13674 value = 0xDC00 | value & 0x3FF; 13675 } 13676 output += stringFromCharCode(value); 13677 } 13678 return output; 13679 } 13680 13681 function checkScalarValue(codePoint) { 13682 if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { 13683 throw Error( 13684 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() + 13685 ' is not a scalar value' 13686 ); 13687 } 13688 } 13689 /*--------------------------------------------------------------------------*/ 13690 13691 function createByte(codePoint, shift) { 13692 return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80); 13693 } 13694 13695 function encodeCodePoint(codePoint) { 13696 if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence 13697 return stringFromCharCode(codePoint); 13698 } 13699 var symbol = ''; 13700 if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence 13701 symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0); 13702 } else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence 13703 checkScalarValue(codePoint); 13704 symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0); 13705 symbol += createByte(codePoint, 6); 13706 } else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence 13707 symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0); 13708 symbol += createByte(codePoint, 12); 13709 symbol += createByte(codePoint, 6); 13710 } 13711 symbol += stringFromCharCode((codePoint & 0x3F) | 0x80); 13712 return symbol; 13713 } 13714 13715 function utf8encode(string) { 13716 var codePoints = ucs2decode(string); 13717 var length = codePoints.length; 13718 var index = -1; 13719 var codePoint; 13720 var byteString = ''; 13721 while (++index < length) { 13722 codePoint = codePoints[index]; 13723 byteString += encodeCodePoint(codePoint); 13724 } 13725 return byteString; 13726 } 13727 13728 /*--------------------------------------------------------------------------*/ 13729 13730 function readContinuationByte() { 13731 if (byteIndex >= byteCount) { 13732 throw Error('Invalid byte index'); 13733 } 13734 13735 var continuationByte = byteArray[byteIndex] & 0xFF; 13736 byteIndex++; 13737 13738 if ((continuationByte & 0xC0) == 0x80) { 13739 return continuationByte & 0x3F; 13740 } 13741 13742 // If we end up here, it’s not a continuation byte 13743 throw Error('Invalid continuation byte'); 13744 } 13745 13746 function decodeSymbol() { 13747 var byte1; 13748 var byte2; 13749 var byte3; 13750 var byte4; 13751 var codePoint; 13752 13753 if (byteIndex > byteCount) { 13754 throw Error('Invalid byte index'); 13755 } 13756 13757 if (byteIndex == byteCount) { 13758 return false; 13759 } 13760 13761 // Read first byte 13762 byte1 = byteArray[byteIndex] & 0xFF; 13763 byteIndex++; 13764 13765 // 1-byte sequence (no continuation bytes) 13766 if ((byte1 & 0x80) == 0) { 13767 return byte1; 13768 } 13769 13770 // 2-byte sequence 13771 if ((byte1 & 0xE0) == 0xC0) { 13772 byte2 = readContinuationByte(); 13773 codePoint = ((byte1 & 0x1F) << 6) | byte2; 13774 if (codePoint >= 0x80) { 13775 return codePoint; 13776 } else { 13777 throw Error('Invalid continuation byte'); 13778 } 13779 } 13780 13781 // 3-byte sequence (may include unpaired surrogates) 13782 if ((byte1 & 0xF0) == 0xE0) { 13783 byte2 = readContinuationByte(); 13784 byte3 = readContinuationByte(); 13785 codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3; 13786 if (codePoint >= 0x0800) { 13787 checkScalarValue(codePoint); 13788 return codePoint; 13789 } else { 13790 throw Error('Invalid continuation byte'); 13791 } 13792 } 13793 13794 // 4-byte sequence 13795 if ((byte1 & 0xF8) == 0xF0) { 13796 byte2 = readContinuationByte(); 13797 byte3 = readContinuationByte(); 13798 byte4 = readContinuationByte(); 13799 codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) | 13800 (byte3 << 0x06) | byte4; 13801 if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) { 13802 return codePoint; 13803 } 13804 } 13805 13806 throw Error('Invalid UTF-8 detected'); 13807 } 13808 13809 var byteArray; 13810 var byteCount; 13811 var byteIndex; 13812 13813 function utf8decode(byteString) { 13814 byteArray = ucs2decode(byteString); 13815 byteCount = byteArray.length; 13816 byteIndex = 0; 13817 var codePoints = []; 13818 var tmp; 13819 while ((tmp = decodeSymbol()) !== false) { 13820 codePoints.push(tmp); 13821 } 13822 return ucs2encode(codePoints); 13823 } 13824 13825 /*--------------------------------------------------------------------------*/ 13826 13827 var utf8 = { 13828 'version': '2.1.2', 13829 'encode': utf8encode, 13830 'decode': utf8decode 13831 }; 13832 13833 // Some AMD build optimizers, like r.js, check for specific condition patterns 13834 // like the following: 13835 if ( 13836 typeof define == 'function' && 13837 typeof define.amd == 'object' && 13838 define.amd 13839 ) { 13840 define(function() { 13841 return utf8; 13842 }); 13843 } else if (freeExports && !freeExports.nodeType) { 13844 if (freeModule) { // in Node.js or RingoJS v0.8.0+ 13845 freeModule.exports = utf8; 13846 } else { // in Narwhal or RingoJS v0.7.0- 13847 var object = {}; 13848 var hasOwnProperty = object.hasOwnProperty; 13849 for (var key in utf8) { 13850 hasOwnProperty.call(utf8, key) && (freeExports[key] = utf8[key]); 13851 } 13852 } 13853 } else { // in Rhino or a web browser 13854 root.utf8 = utf8; 13855 } 13856 13857 }(this)); 13858 13859 }, {}], 13860 86: [function(require, module, exports) { 13861 module.exports = XMLHttpRequest; 13862 13863 }, {}], 13864 "bignumber.js": [function(require, module, exports) { 13865 'use strict'; 13866 13867 module.exports = BigNumber; // jshint ignore:line 13868 13869 13870 }, {}], 13871 "web3": [function(require, module, exports) { 13872 var Web3 = require('./lib/web3'); 13873 13874 // dont override global variable 13875 if (typeof window !== 'undefined' && typeof window.Web3 === 'undefined') { 13876 window.Web3 = Web3; 13877 } 13878 13879 module.exports = Web3; 13880 13881 }, { 13882 "./lib/web3": 22 13883 }] 13884 }, {}, ["web3"]) 13885 //# sourceMappingURL=web3-light.js.map