1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 2(function (global){ 3var ethJSABI = require("ethjs-abi"); 4var BlockchainUtils = require("truffle-blockchain-utils"); 5var Web3 = require("web3"); 6 7// For browserified version. If browserify gave us an empty version, 8// look for the one provided by the user. 9if (typeof Web3 == "object" && Object.keys(Web3).length == 0) { 10 Web3 = global.Web3; 11} 12 13var contract = (function(module) { 14 15 // Planned for future features, logging, etc. 16 function Provider(provider) { 17 this.provider = provider; 18 } 19 20 Provider.prototype.send = function() { 21 return this.provider.send.apply(this.provider, arguments); 22 }; 23 24 Provider.prototype.sendAsync = function() { 25 return this.provider.sendAsync.apply(this.provider, arguments); 26 }; 27 28 var BigNumber = (new Web3()).toBigNumber(0).constructor; 29 30 var Utils = { 31 is_object: function(val) { 32 return typeof val == "object" && !Array.isArray(val); 33 }, 34 is_big_number: function(val) { 35 if (typeof val != "object") return false; 36 37 // Instanceof won't work because we have multiple versions of Web3. 38 try { 39 new BigNumber(val); 40 return true; 41 } catch (e) { 42 return false; 43 } 44 }, 45 decodeLogs: function(C, instance, logs) { 46 return logs.map(function(log) { 47 var logABI = C.events[log.topics[0]]; 48 49 if (logABI == null) { 50 return null; 51 } 52 53 // This function has been adapted from web3's SolidityEvent.decode() method, 54 // and built to work with ethjs-abi. 55 56 var copy = Utils.merge({}, log); 57 58 function partialABI(fullABI, indexed) { 59 var inputs = fullABI.inputs.filter(function (i) { 60 return i.indexed === indexed; 61 }); 62 63 var partial = { 64 inputs: inputs, 65 name: fullABI.name, 66 type: fullABI.type, 67 anonymous: fullABI.anonymous 68 }; 69 70 return partial; 71 } 72 73 var argTopics = logABI.anonymous ? copy.topics : copy.topics.slice(1); 74 var indexedData = "0x" + argTopics.map(function (topics) { return topics.slice(2); }).join(""); 75 var indexedParams = ethJSABI.decodeEvent(partialABI(logABI, true), indexedData); 76 77 var notIndexedData = copy.data; 78 var notIndexedParams = ethJSABI.decodeEvent(partialABI(logABI, false), notIndexedData); 79 80 copy.event = logABI.name; 81 82 copy.args = logABI.inputs.reduce(function (acc, current) { 83 var val = indexedParams[current.name]; 84 85 if (val === undefined) { 86 val = notIndexedParams[current.name]; 87 } 88 89 acc[current.name] = val; 90 return acc; 91 }, {}); 92 93 Object.keys(copy.args).forEach(function(key) { 94 var val = copy.args[key]; 95 96 // We have BN. Convert it to BigNumber 97 if (val.constructor.isBN) { 98 copy.args[key] = C.web3.toBigNumber("0x" + val.toString(16)); 99 } 100 }); 101 102 delete copy.data; 103 delete copy.topics; 104 105 return copy; 106 }).filter(function(log) { 107 return log != null; 108 }); 109 }, 110 promisifyFunction: function(fn, C) { 111 var self = this; 112 return function() { 113 var instance = this; 114 115 var args = Array.prototype.slice.call(arguments); 116 var tx_params = {}; 117 var last_arg = args[args.length - 1]; 118 119 // It's only tx_params if it's an object and not a BigNumber. 120 if (Utils.is_object(last_arg) && !Utils.is_big_number(last_arg)) { 121 tx_params = args.pop(); 122 } 123 124 tx_params = Utils.merge(C.class_defaults, tx_params); 125 126 return C.detectNetwork().then(function() { 127 return new Promise(function(accept, reject) { 128 var callback = function(error, result) { 129 if (error != null) { 130 reject(error); 131 } else { 132 accept(result); 133 } 134 }; 135 args.push(tx_params, callback);
136 fn.apply(instance.contract, args); 137 }); 138 }); 139 }; 140 }, 141 synchronizeFunction: function(fn, instance, C) { 142 var self = this; 143 return function() { 144 var args = Array.prototype.slice.call(arguments); 145 var tx_params = {}; 146 var last_arg = args[args.length - 1]; 147 148 // It's only tx_params if it's an object and not a BigNumber. 149 if (Utils.is_object(last_arg) && !Utils.is_big_number(last_arg)) { 150 tx_params = args.pop(); 151 } 152 153 tx_params = Utils.merge(C.class_defaults, tx_params); 154 155 return C.detectNetwork().then(function() { 156 return new Promise(function(accept, reject) { 157 var callback = function(error, tx) { 158 if (error != null) { 159 reject(error); 160 return; 161 } 162 163 var timeout = C.synchronization_timeout || 240000; 164 var start = new Date().getTime(); 165 166 var make_attempt = function() { 167 C.web3.eth.getTransactionReceipt(tx, function(err, receipt) { 168 if (err) return reject(err); 169 170 if (receipt != null) { 171 return accept({ 172 tx: tx, 173 receipt: receipt, 174 logs: Utils.decodeLogs(C, instance, receipt.logs) 175 }); 176 } 177 178 if (timeout > 0 && new Date().getTime() - start > timeout) { 179 return reject(new Error("Transaction " + tx + " wasn't processed in " + (timeout / 1000) + " seconds!")); 180 } 181 182 setTimeout(make_attempt, 1000); 183 }); 184 }; 185 186 make_attempt(); 187 }; 188 189 args.push(tx_params, callback); 190 fn.apply(self, args); 191 }); 192 }); 193 }; 194 }, 195 merge: function() { 196 var merged = {}; 197 var args = Array.prototype.slice.call(arguments); 198 199 for (var i = 0; i < args.length; i++) { 200 var object = args[i]; 201 var keys = Object.keys(object); 202 for (var j = 0; j < keys.length; j++) { 203 var key = keys[j]; 204 var value = object[key]; 205 merged[key] = value; 206 } 207 } 208 209 return merged; 210 }, 211 parallel: function (arr, callback) { 212 callback = callback || function () {}; 213 if (!arr.length) { 214 return callback(null, []); 215 } 216 var index = 0; 217 var results = new Array(arr.length); 218 arr.forEach(function (fn, position) { 219 fn(function (err, result) { 220 if (err) { 221 callback(err); 222 callback = function () {}; 223 } else { 224 index++; 225 results[position] = result; 226 if (index >= arr.length) { 227 callback(null, results); 228 } 229 } 230 }); 231 }); 232 }, 233 bootstrap: function(fn) { 234 // Add our static methods 235 Object.keys(fn._static_methods).forEach(function(key) { 236 fn[key] = fn._static_methods[key].bind(fn); 237 }); 238 239 // Add our properties. 240 Object.keys(fn._properties).forEach(function(key) { 241 fn.addProp(key, fn._properties[key]); 242 }); 243 244 return fn; 245 } 246 }; 247 248 // Accepts a contract object created with web3.eth.contract. 249 // Optionally, if called without `new`, accepts a network_id and will 250 // create a new version of the contract abstraction with that network_id set. 251 function Contract(contract) { 252 var self = this; 253 var constructor = this.constructor; 254 this.abi = constructor.abi; 255 256 if (typeof contract == "string") { 257 var address = contract; 258 var contract_class = constructor.web3.eth.contract(this.abi); 259 contract = contract_class.at(address); 260 } 261 262 this.contract = contract; 263 264 // Provision our functions. 265 for (var i = 0; i < this.abi.length; i++) { 266 var item = this.abi[i]; 267 if (item.type == "function") { 268 if (item.constant == true) { 269 this[item.name] = Utils.promisifyFunction(contract[item.name], constructor); 270 } else { 271 this[item.name] = Utils.synchronizeFunction(contract[item.name], this, constructor); 272 } 273 274 this[item.name].call = Utils.promisifyFunction(contract[item.name].call, constructor); 275 this[item.name].sendTransaction = Utils.promisifyFunction(contract[item.name].sendTransaction, constructor); 276 this[item.name].request = contract[item.name].request; 277 this[item.name].estimateGas = Utils.promisifyFunction(contract[item.name].estimateGas, c
277onstructor); 278 } 279 280 if (item.type == "event") { 281 this[item.name] = contract[item.name]; 282 } 283 } 284 285 this.sendTransaction = Utils.synchronizeFunction(function(tx_params, callback) { 286 if (typeof tx_params == "function") { 287 callback = tx_params; 288 tx_params = {}; 289 } 290 291 tx_params.to = self.address; 292 293 constructor.web3.eth.sendTransaction.apply(constructor.web3.eth, [tx_params, callback]); 294 }, this, constructor); 295 296 this.send = function(value) { 297 return self.sendTransaction({value: value}); 298 }; 299 300 this.allEvents = contract.allEvents; 301 this.address = contract.address; 302 this.transactionHash = contract.transactionHash; 303 }; 304 305 Contract._static_methods = { 306 setProvider: function(provider) { 307 if (!provider) { 308 throw new Error("Invalid provider passed to setProvider(); provider is " + provider); 309 } 310 311 var wrapped = new Provider(provider); 312 this.web3.setProvider(wrapped); 313 this.currentProvider = provider; 314 }, 315 316 new: function() { 317 var self = this; 318 319 if (this.currentProvider == null) { 320 throw new Error(this.contract_name + " error: Please call setProvider() first before calling new()."); 321 } 322 323 var args = Array.prototype.slice.call(arguments); 324 325 if (!this.unlinked_binary) { 326 throw new Error(this._json.contract_name + " error: contract binary not set. Can't deploy new instance."); 327 } 328 329 return self.detectNetwork().then(function(network_id) { 330 // After the network is set, check to make sure everything's ship shape. 331 var regex = /__[^_]+_+/g; 332 var unlinked_libraries = self.binary.match(regex); 333 334 if (unlinked_libraries != null) { 335 unlinked_libraries = unlinked_libraries.map(function(name) { 336 // Remove underscores 337 return name.replace(/_/g, ""); 338 }).sort().filter(function(name, index, arr) { 339 // Remove duplicates 340 if (index + 1 >= arr.length) { 341 return true; 342 } 343 344 return name != arr[index + 1]; 345 }).join(", "); 346 347 throw new Error(self.contract_name + " contains unresolved libraries. You must deploy and link the following libraries before you can deploy a new version of " + self._json.contract_name + ": " + unlinked_libraries); 348 } 349 }).then(function() { 350 return new Promise(function(accept, reject) { 351 var contract_class = self.web3.eth.contract(self.abi); 352 var tx_params = {}; 353 var last_arg = args[args.length - 1]; 354 355 // It's only tx_params if it's an object and not a BigNumber. 356 if (Utils.is_object(last_arg) && !Utils.is_big_number(last_arg)) { 357 tx_params = args.pop(); 358 } 359 360 tx_params = Utils.merge(self.class_defaults, tx_params); 361 362 if (tx_params.data == null) { 363 tx_params.data = self.binary; 364 } 365 366 // web3 0.9.0 and above calls new this callback twice. 367 // Why, I have no idea... 368 var intermediary = function(err, web3_instance) { 369 if (err != null) { 370 reject(err); 371 return; 372 } 373 374 if (err == null && web3_instance != null && web3_instance.address != null) { 375 accept(new self(web3_instance)); 376 } 377 }; 378 379 args.push(tx_params, intermediary); 380 contract_class.new.apply(contract_class, args); 381 }); 382 }); 383 }, 384 385 at: function(address) { 386 var self = this; 387 388 if (address == null || typeof address != "string" || address.length != 42) { 389 throw new Error("Invalid address passed to " + this._json.contract_name + ".at(): " + address); 390 } 391 392 var contract = new this(address); 393 394 // Add thennable to allow people opt into new recommended usage. 395 contract.then = function(fn) { 396 return self.detectNetwork().then(function(network_id) { 397 var instance = new self(address); 398 399 return new Promise(function(accept, reject) {
400 self.web3.eth.getCode(address, function(err, code) { 401 if (err) return reject(err); 402 403 if (!code || new BigNumber(code).eq(0)) { 404 return reject(new Error("Cannot create instance of " + self.contract_name + "; no code at address " + address)); 405 } 406 407 accept(instance); 408 }); 409 }); 410 }).then(fn); 411 }; 412 413 return contract; 414 }, 415 416 deployed: function() { 417 var self = this; 418 var val = {}; //this.at(this.address); 419 420 // Add thennable to allow people to opt into new recommended usage. 421 val.then = function(fn) { 422 return self.detectNetwork().then(function() { 423 // We don't have a network config for the one we found 424 if (self._json.networks[self.network_id] == null) { 425 throw new Error(self.contract_name + " has not been deployed to detected network (network/artifact mismatch)"); 426 } 427 428 // If we found the network but it's not deployed 429 if (!self.isDeployed()) { 430 throw new Error(self.contract_name + " has not been deployed to detected network (" + self.network_id + ")"); 431 } 432 433 return new self(self.address); 434 }).then(fn); 435 }; 436 437 return val; 438 }, 439 440 defaults: function(class_defaults) { 441 if (this.class_defaults == null) { 442 this.class_defaults = {}; 443 } 444 445 if (class_defaults == null) { 446 class_defaults = {}; 447 } 448 449 var self = this; 450 Object.keys(class_defaults).forEach(function(key) { 451 var value = class_defaults[key]; 452 self.class_defaults[key] = value; 453 }); 454 455 return this.class_defaults; 456 }, 457 458 hasNetwork: function(network_id) { 459 return this._json.networks[network_id + ""] != null; 460 }, 461 462 isDeployed: function() { 463 if (this.network_id == null) { 464 return false; 465 } 466 467 if (this._json.networks[this.network_id] == null) { 468 return false; 469 } 470 471 return !!this.network.address; 472 }, 473 474 detectNetwork: function() { 475 var self = this; 476 477 return new Promise(function(accept, reject) { 478 // Try to detect the network we have artifacts for. 479 if (self.network_id) { 480 // We have a network id and a configuration, let's go with it. 481 if (self.networks[self.network_id] != null) { 482 return accept(self.network_id); 483 } 484 } 485 486 self.web3.version.getNetwork(function(err, result) { 487 if (err) return reject(err); 488 489 var network_id = result.toString(); 490 491 // If we found the network via a number, let's use that. 492 if (self.hasNetwork(network_id)) { 493 self.setNetwork(network_id); 494 return accept(); 495 } 496 497 // Otherwise, go through all the networks that are listed as 498 // blockchain uris and see if they match. 499 var uris = Object.keys(self._json.networks).filter(function(network) { 500 return network.indexOf("blockchain://") == 0; 501 }); 502 503 var matches = uris.map(function(uri) { 504 return BlockchainUtils.matches.bind(BlockchainUtils, uri, self.web3.currentProvider); 505 }); 506 507 Utils.parallel(matches, function(err, results) { 508 if (err) return reject(err); 509 510 for (var i = 0; i < results.length; i++) { 511 if (results[i]) { 512 self.setNetwork(uris[i]); 513 return accept(); 514 } 515 } 516 517 // We found nothing. Set the network id to whatever the provider states. 518 self.setNetwork(network_id); 519 520 accept(); 521 }); 522 523 }); 524 }); 525 }, 526 527 setNetwork: function(network_id) { 528 if (!network_id) return; 529 this.network_id = network_id + ""; 530 }, 531 532 // Overrides the deployed address to null. 533 // You must call this explicitly so you don't inadvertently do this otherwise. 534 resetAddress: function() { 535 delete this.network.address; 536 }, 537 538 link: function(name, address) { 539 var self = this; 540 541 if (typeof name == "function") { 542 var contract = name; 543 544 if (contract.isDeployed() == false) { 545 throw new Error("Cannot link contract without an address."); 546 } 547 548 this.link(contract.contract_name, contract.address); 549 550 // Merge events so this contract knows about library's events
551 Object.keys(contract.events).forEach(function(topic) { 552 self.network.events[topic] = contract.events[topic]; 553 }); 554 555 return; 556 } 557 558 if (typeof name == "object") { 559 var obj = name; 560 Object.keys(obj).forEach(function(name) { 561 var a = obj[name]; 562 self.link(name, a); 563 }); 564 return; 565 } 566 567 if (this._json.networks[this.network_id] == null) { 568 this._json.networks[this.network_id] = { 569 events: {}, 570 links: {} 571 }; 572 } 573 574 this.network.links[name] = address; 575 }, 576 577 clone: function(options) { 578 var self = this; 579 var temp = function TruffleContract() { 580 this.constructor = temp; 581 return Contract.apply(this, arguments); 582 }; 583 584 var json = options; 585 var network_id; 586 587 if (typeof options != "object") { 588 json = self._json; 589 network_id = options; 590 options = {}; 591 } 592 593 temp.prototype = Object.create(self.prototype); 594 595 temp._static_methods = this._static_methods; 596 temp._properties = this._properties; 597 598 temp._property_values = {}; 599 temp._json = json || {}; 600 601 Utils.bootstrap(temp); 602 603 temp.web3 = new Web3(); 604 temp.class_defaults = temp.prototype.defaults || {}; 605 606 if (network_id) { 607 temp.setNetwork(network_id); 608 } 609 610 // Copy over custom options 611 Object.keys(options).forEach(function(key) { 612 if (key.indexOf("x-") != 0) return; 613 temp[key] = options[key]; 614 }); 615 616 return temp; 617 }, 618 619 addProp: function(key, fn) { 620 var self = this; 621 622 var getter = function() { 623 if (fn.get != null) { 624 return fn.get.call(self); 625 } 626 627 return self._property_values[key] || fn.call(self); 628 } 629 var setter = function(val) { 630 if (fn.set != null) { 631 fn.set.call(self, val); 632 return; 633 } 634 635 // If there's not a setter, then the property is immutable. 636 throw new Error(key + " property is immutable"); 637 }; 638 639 var definition = {}; 640 definition.enumerable = false; 641 definition.configurable = false; 642 definition.get = getter; 643 definition.set = setter; 644 645 Object.defineProperty(this, key, definition); 646 }, 647 648 toJSON: function() { 649 return this._json; 650 } 651 }; 652 653 // Getter functions are scoped to Contract object. 654 Contract._properties = { 655 contract_name: { 656 get: function() { 657 return this._json.contract_name; 658 }, 659 set: function(val) { 660 this._json.contract_name = val; 661 } 662 }, 663 abi: { 664 get: function() { 665 return this._json.abi; 666 }, 667 set: function(val) { 668 this._json.abi = val; 669 } 670 }, 671 network: function() { 672 var network_id = this.network_id; 673 674 if (network_id == null) { 675 throw new Error(this.contract_name + " has no network id set, cannot lookup artifact data. Either set the network manually using " + this.contract_name + ".setNetwork(), run " + this.contract_name + ".detectNetwork(), or use new(), at() or deployed() as a thenable which will detect the network automatically."); 676 } 677 678 // TODO: this might be bad; setting a value on a get. 679 if (this._json.networks[network_id] == null) { 680 throw new Error(this.contract_name + " has no network configuration for its current network id (" + network_id + ")."); 681 } 682 683 return this._json.networks[network_id]; 684 }, 685 networks: function() { 686 return this._json.networks; 687 }, 688 address: { 689 get: function() { 690 var address = this.network.address; 691 692 if (address == null) { 693 throw new Error("Cannot find deployed address: " + this.contract_name + " not deployed or address not set."); 694 } 695 696 return address; 697 }, 698 set: function(val) { 699 if (val == null) { 700 throw new Error("Cannot set deployed address; malformed value: " + val); 701 } 702 703 var network_id = this.network_id; 704 705 if (network_id == null) { 706 throw new Error(this.contract_name + " has no network id set, cannot lookup artifact data. Either set the network manually using " + this.contract_name + ".setNetwork(), run " + this.contract_name + ".detectNetwork(), or use new(), at() or deployed() as a thenable which will detect the network automatically."); 707 } 708 709 // Create a network if we don't have one. 710 if (this._json.networks[network_id] == null) { 711 this._json.networks[network_id] = { 712 events: {}, 713 links: {} 714 }; 715 } 716 717 // Finally, set the address. 718 this.network.address = val; 719 } 720 }, 721 links: function() { 722 if (this._json.networks[this.network_id] == null) { 723 return {}; 724 } 725 726 return this.network.links || {}; 727 }, 728 events: function() { 729 // helper web3; not used for provider 730 var web3 = new Web3(); 731 732 var events; 733 734 if (this._json.networks[this.network_id] == null) { 735 events = {}; 736 } else { 737 events = this.network.events || {}; 738 } 739 740 // Merge abi events with whatever's returned. 741 var abi = this.abi; 742
743 abi.forEach(function(item) { 744 if (item.type != "event") return; 745 746 var signature = item.name + "("; 747 748 item.inputs.forEach(function(input, index) { 749 signature += input.type; 750 751 if (index < item.inputs.length - 1) { 752 signature += ","; 753 } 754 }); 755 756 signature += ")"; 757 758 var topic = web3.sha3(signature); 759 760 events[topic] = item; 761 }); 762 763 return events; 764 }, 765 binary: function() { 766 var self = this; 767 var binary = this.unlinked_binary; 768 769 Object.keys(this.links).forEach(function(library_name) { 770 var library_address = self.links[library_name]; 771 var regex = new RegExp("__" + library_name + "_*", "g"); 772 773 binary = binary.replace(regex, library_address.replace("0x", "")); 774 }); 775 776 return binary; 777 }, 778 unlinked_binary: { 779 get: function() { 780 return this._json.unlinked_binary; 781 }, 782 set: function(val) { 783 // TODO: Ensure 0x prefix. 784 this._json.unlinked_binary = val; 785 } 786 }, 787 schema_version: function() { 788 return this._json.schema_version; 789 }, 790 updated_at: function() { 791 try { 792 return this.network.updated_at || this._json.updated_at; 793 } catch (e) { 794 return this._json.updated_at; 795 } 796 } 797 }; 798 799 Utils.bootstrap(Contract); 800 801 module.exports = Contract; 802 803 return Contract; 804})(module || {}); 805 806}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 807},{"ethjs-abi":7,"truffle-blockchain-utils":15,"web3":5}],2:[function(require,module,exports){ 808var Schema = require("truffle-contract-schema"); 809var Contract = require("./contract.js"); 810 811var contract = function(options) { 812 options = Schema.normalizeOptions(options); 813 var binary = Schema.generateBinary(options, {}, {dirty: false}); 814 815 // Note we don't use `new` here at all. This will cause the class to 816 // "mutate" instead of instantiate an instance. 817 return Contract.clone(binary); 818}; 819 820// To be used to upgrade old .sol.js abstractions 821contract.fromSolJS = function(soljs_abstraction, ignore_default_network) { 822 if (ignore_default_network == null) { 823 ignore_default_network = false; 824 } 825 826 // Find the latest binary 827 var latest_network = null; 828 var latest_network_updated_at = 0; 829 830 var networks = {}; 831 832 Object.keys(soljs_abstraction.all_networks).forEach(function(network_name) { 833 834 if (network_name == "default") { 835 if (ignore_default_network == true ) { 836 return; 837 } else { 838 throw new Error(soljs_abstraction.contract_name + " has legacy 'default' network artifacts stored within it. Generally these artifacts were a result of running Truffle on a development environment -- in order to store contracts with truffle-contract, all networks must have an identified id. If you're sure this default network represents your development environment, you can ignore processing of the default network by passing `true` as the second argument to this function. However, if you think this network represents artifacts you'd like to keep (i.e., addresses deployed to the main network), you'll need to edit your .sol.js file yourself and change the default network id to be the id of your desired network. For most people, ignoring the default network is the correct option."); 839 } 840 } 841 842 if (soljs_abstraction.all_networks[network_name].updated_at > latest_network_updated_at) { 843 latest_network = network_name; 844 latest_network_updated_at = soljs_abstraction.all_networks[network_name].updated_at; 845 } 846 847 networks[network_name] = {}; 848 849 ["address", "events", "links", "updated_at"].forEach(function(key) { 850 networks[network_name][key] = soljs_abstraction.all_networks[network_name][key]; 851 }) 852 }); 853 854 latest_network = soljs_abstraction.all_networks[latest_network] || {}; 855 856 var json = { 857 contract_name: soljs_abstraction.contract_name, 858 unlinked_binary: latest_network.unlinked_binary, 859 abi: latest_network.abi, 860 networks: networks, 861 updated_at: latest_network_updated_at == 0 ? undefined : latest_network_updated_at 862 }; 863 864 return contract(json); 865}; 866 867module.exports = contract; 868 869if (typeof window !== "undefined") { 870 window.TruffleContract = contract; 871} 872 873},{"./contract.js":1,"truffle-contract-schema":16}],3:[function(require,module,exports){ 874'use strict' 875 876exports.byteLength = byteLength 877exports.toByteArray = toByteArray 878exports.fromByteArray = fromByteArray 879 880var lookup = [] 881var revLookup = [] 882var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array 883 884var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
vendor: 10,397 bytes, lines 884-1295
884+/' 885for (var i = 0, len = code.length; i < len; ++i) { 886 lookup[i] = code[i] 887 revLookup[code.charCodeAt(i)] = i 888} 889 890revLookup['-'.charCodeAt(0)] = 62 891revLookup['_'.charCodeAt(0)] = 63 892 893function placeHoldersCount (b64) { 894 var len = b64.length 895 if (len % 4 > 0) { 896 throw new Error('Invalid string. Length must be a multiple of 4') 897 } 898 899 // the number of equal signs (place holders) 900 // if there are two placeholders, than the two characters before it 901 // represent one byte 902 // if there is only one, then the three characters before it represent 2 bytes 903 // this is just a cheap hack to not do indexOf twice 904 return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 905} 906 907function byteLength (b64) { 908 // base64 is 4/3 + up to two characters of the original data 909 return b64.length * 3 / 4 - placeHoldersCount(b64) 910} 911 912function toByteArray (b64) { 913 var i, j, l, tmp, placeHolders, arr 914 var len = b64.length 915 placeHolders = placeHoldersCount(b64) 916 917 arr = new Arr(len * 3 / 4 - placeHolders) 918 919 // if there are placeholders, only get up to the last complete 4 chars 920 l = placeHolders > 0 ? len - 4 : len 921 922 var L = 0 923 924 for (i = 0, j = 0; i < l; i += 4, j += 3) { 925 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] 926 arr[L++] = (tmp >> 16) & 0xFF 927 arr[L++] = (tmp >> 8) & 0xFF 928 arr[L++] = tmp & 0xFF 929 } 930 931 if (placeHolders === 2) { 932 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) 933 arr[L++] = tmp & 0xFF 934 } else if (placeHolders === 1) { 935 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) 936 arr[L++] = (tmp >> 8) & 0xFF 937 arr[L++] = tmp & 0xFF 938 } 939 940 return arr 941} 942 943function tripletToBase64 (num) { 944 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] 945} 946 947function encodeChunk (uint8, start, end) { 948 var tmp 949 var output = [] 950 for (var i = start; i < end; i += 3) { 951 tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) 952 output.push(tripletToBase64(tmp)) 953 } 954 return output.join('') 955} 956 957function fromByteArray (uint8) { 958 var tmp 959 var len = uint8.length 960 var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes 961 var output = '' 962 var parts = [] 963 var maxChunkLength = 16383 // must be multiple of 3 964 965 // go through the array every three bytes, we'll deal with trailing stuff later 966 for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { 967 parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) 968 } 969 970 // pad the end with zeros, but make sure to not forget the extra bytes 971 if (extraBytes === 1) { 972 tmp = uint8[len - 1] 973 output += lookup[tmp >> 2] 974 output += lookup[(tmp << 4) & 0x3F] 975 output += '==' 976 } else if (extraBytes === 2) { 977 tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) 978 output += lookup[tmp >> 10] 979 output += lookup[(tmp >> 4) & 0x3F] 980 output += lookup[(tmp << 2) & 0x3F] 981 output += '=' 982 } 983 984 parts.push(output) 985 986 return parts.join('') 987} 988 989},{}],4:[function(require,module,exports){ 990(function (module, exports) { 991 'use strict'; 992 993 // Utils 994 function assert (val, msg) { 995 if (!val) throw new Error(msg || 'Assertion failed'); 996 } 997 998 // Could use `inherits` module, but don't want to move from single file 999 // architecture yet. 1000 function inherits (ctor, superCtor) { 1001 ctor.super_ = superCtor; 1002 var TempCtor = function () {}; 1003 TempCtor.prototype = superCtor.prototype; 1004 ctor.prototype = new TempCtor(); 1005 ctor.prototype.constructor = ctor; 1006 } 1007 1008 // BN 1009 1010 function BN (number, base, endian) { 1011 if (BN.isBN(number)) { 1012 return number; 1013 } 1014 1015 this.negative = 0; 1016 this.words = null; 1017 this.length = 0; 1018 1019 // Reduction context 1020 this.red = null; 1021 1022 if (number !== null) { 1023 if (base === 'le' || base === 'be') { 1024 endian = base; 1025 base = 10; 1026 } 1027 1028 this._init(number || 0, base || 10, endian || 'be'); 1029 } 1030 } 1031 if (typeof module === 'object') { 1032 module.exports = BN; 1033 } else { 1034 exports.BN = BN; 1035 } 1036 1037 BN.BN = BN; 1038 BN.wordSize = 26; 1039 1040 var Buffer; 1041 try { 1042 Buffer = require('buf' + 'fer').Buffer; 1043 } catch (e) { 1044 } 1045 1046 BN.isBN = function isBN (num) { 1047 if (num instanceof BN) { 1048 return true; 1049 } 1050 1051 return num !== null && typeof num === 'object' && 1052 num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); 1053 }; 1054 1055 BN.max = function max (left, right) { 1056 if (left.cmp(right) > 0) return left; 1057 return right; 1058 }; 1059 1060 BN.min = function min (left, right) { 1061 if (left.cmp(right) < 0) return left; 1062 return right; 1063 }; 1064 1065 BN.prototype._init = function init (number, base, endian) { 1066 if (typeof number === 'number') { 1067 return this._initNumber(number, base, endian); 1068 } 1069 1070 if (typeof number === 'object') { 1071 return this._initArray(number, base, endian); 1072 } 1073 1074 if (base === 'hex') { 1075 base = 16; 1076 } 1077 assert(base === (base | 0) && base >= 2 && base <= 36); 1078 1079 number = number.toString().replace(/\s+/g, ''); 1080 var start = 0; 1081 if (number[0] === '-') { 1082 start++; 1083 } 1084 1085 if (base === 16) { 1086 this._parseHex(number, start); 1087 } else { 1088 this._parseBase(number, base, start); 1089 } 1090 1091 if (number[0] === '-') { 1092 this.negative = 1; 1093 } 1094 1095 this.strip(); 1096 1097 if (endian !== 'le') return; 1098 1099 this._initArray(this.toArray(), base, endian); 1100 }; 1101 1102 BN.prototype._initNumber = function _initNumber (number, base, endian) { 1103 if (number < 0) { 1104 this.negative = 1; 1105 number = -number; 1106 } 1107 if (number < 0x4000000) { 1108 this.words = [ number & 0x3ffffff ]; 1109 this.length = 1; 1110 } else if (number < 0x10000000000000) { 1111 this.words = [ 1112 number & 0x3ffffff, 1113 (number / 0x4000000) & 0x3ffffff 1114 ]; 1115 this.length = 2; 1116 } else { 1117 assert(number < 0x20000000000000); // 2 ^ 53 (unsafe) 1118 this.words = [ 1119 number & 0x3ffffff, 1120 (number / 0x4000000) & 0x3ffffff, 1121 1 1122 ]; 1123 this.length = 3; 1124 } 1125 1126 if (endian !== 'le') return; 1127 1128 // Reverse the bytes 1129 this._initArray(this.toArray(), base, endian); 1130 }; 1131 1132 BN.prototype._initArray = function _initArray (number, base, endian) { 1133 // Perhaps a Uint8Array 1134 assert(typeof number.length === 'number'); 1135 if (number.length <= 0) { 1136 this.words = [ 0 ]; 1137 this.length = 1; 1138 return this; 1139 } 1140 1141 this.length = Math.ceil(number.length / 3); 1142 this.words = new Array(this.length); 1143 for (var i = 0; i < this.length; i++) { 1144 this.words[i] = 0; 1145 } 1146 1147 var j, w; 1148 var off = 0; 1149 if (endian === 'be') { 1150 for (i = number.length - 1, j = 0; i >= 0; i -= 3) { 1151 w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16); 1152 this.words[j] |= (w << off) & 0x3ffffff; 1153 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; 1154 off += 24; 1155 if (off >= 26) { 1156 off -= 26; 1157 j++; 1158 } 1159 } 1160 } else if (endian === 'le') { 1161 for (i = 0, j = 0; i < number.length; i += 3) { 1162 w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16); 1163 this.words[j] |= (w << off) & 0x3ffffff; 1164 this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff; 1165 off += 24; 1166 if (off >= 26) { 1167 off -= 26; 1168 j++; 1169 } 1170 } 1171 } 1172 return this.strip(); 1173 }; 1174 1175 function parseHex (str, start, end) { 1176 var r = 0; 1177 var len = Math.min(str.length, end); 1178 for (var i = start; i < len; i++) { 1179 var c = str.charCodeAt(i) - 48; 1180 1181 r <<= 4; 1182 1183 // 'a' - 'f' 1184 if (c >= 49 && c <= 54) { 1185 r |= c - 49 + 0xa; 1186 1187 // 'A' - 'F' 1188 } else if (c >= 17 && c <= 22) { 1189 r |= c - 17 + 0xa; 1190 1191 // '0' - '9' 1192 } else { 1193 r |= c & 0xf; 1194 } 1195 } 1196 return r; 1197 } 1198 1199 BN.prototype._parseHex = function _parseHex (number, start) { 1200 // Create possibly bigger array to ensure that it fits the number 1201 this.length = Math.ceil((number.length - start) / 6); 1202 this.words = new Array(this.length); 1203 for (var i = 0; i < this.length; i++) { 1204 this.words[i] = 0; 1205 } 1206 1207 var j, w; 1208 // Scan 24-bit chunks and add them to the number 1209 var off = 0; 1210 for (i = number.length - 6, j = 0; i >= start; i -= 6) { 1211 w = parseHex(number, i, i + 6); 1212 this.words[j] |= (w << off) & 0x3ffffff; 1213 // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb 1214 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; 1215 off += 24; 1216 if (off >= 26) { 1217 off -= 26; 1218 j++; 1219 } 1220 } 1221 if (i + 6 !== start) { 1222 w = parseHex(number, start, i + 6); 1223 this.words[j] |= (w << off) & 0x3ffffff; 1224 this.words[j + 1] |= w >>> (26 - off) & 0x3fffff; 1225 } 1226 this.strip(); 1227 }; 1228 1229 function parseBase (str, start, end, mul) { 1230 var r = 0; 1231 var len = Math.min(str.length, end); 1232 for (var i = start; i < len; i++) { 1233 var c = str.charCodeAt(i) - 48; 1234 1235 r *= mul; 1236 1237 // 'a' 1238 if (c >= 49) { 1239 r += c - 49 + 0xa; 1240 1241 // 'A' 1242 } else if (c >= 17) { 1243 r += c - 17 + 0xa; 1244 1245 // '0' - '9' 1246 } else { 1247 r += c; 1248 } 1249 } 1250 return r; 1251 } 1252 1253 BN.prototype._parseBase = function _parseBase (number, base, start) { 1254 // Initialize as zero 1255 this.words = [ 0 ]; 1256 this.length = 1; 1257 1258 // Find length of limb in base 1259 for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) { 1260 limbLen++; 1261 } 1262 limbLen--; 1263 limbPow = (limbPow / base) | 0; 1264 1265 var total = number.length - start; 1266 var mod = total % limbLen; 1267 var end = Math.min(total, total - mod) + start; 1268 1269 var word = 0; 1270 for (var i = start; i < end; i += limbLen) { 1271 word = parseBase(number, i, i + limbLen, base); 1272 1273 this.imuln(limbPow); 1274 if (this.words[0] + word < 0x4000000) { 1275 this.words[0] += word; 1276 } else { 1277 this._iaddn(word); 1278 } 1279 } 1280 1281 if (mod !== 0) { 1282 var pow = 1; 1283 word = parseBase(number, i, number.length, base); 1284 1285 for (i = 0; i < mod; i++) { 1286 pow *= base; 1287 } 1288 1289 this.imuln(pow); 1290 if (this.words[0] + word < 0x4000000) { 1291 this.words[0] += word; 1292 } else { 1293 this._iaddn(word); 1294 } 1295 }
vendor: 68,018 bytes, lines 1295-3899
1295 1296 }; 1297 1298 BN.prototype.copy = function copy (dest) { 1299 dest.words = new Array(this.length); 1300 for (var i = 0; i < this.length; i++) { 1301 dest.words[i] = this.words[i]; 1302 } 1303 dest.length = this.length; 1304 dest.negative = this.negative; 1305 dest.red = this.red; 1306 }; 1307 1308 BN.prototype.clone = function clone () { 1309 var r = new BN(null); 1310 this.copy(r); 1311 return r; 1312 }; 1313 1314 BN.prototype._expand = function _expand (size) { 1315 while (this.length < size) { 1316 this.words[this.length++] = 0; 1317 } 1318 return this; 1319 }; 1320 1321 // Remove leading `0` from `this` 1322 BN.prototype.strip = function strip () { 1323 while (this.length > 1 && this.words[this.length - 1] === 0) { 1324 this.length--; 1325 } 1326 return this._normSign(); 1327 }; 1328 1329 BN.prototype._normSign = function _normSign () { 1330 // -0 = 0 1331 if (this.length === 1 && this.words[0] === 0) { 1332 this.negative = 0; 1333 } 1334 return this; 1335 }; 1336 1337 BN.prototype.inspect = function inspect () { 1338 return (this.red ? '<BN-R: ' : '<BN: ') + this.toString(16) + '>'; 1339 }; 1340 1341 /* 1342 1343 var zeros = []; 1344 var groupSizes = []; 1345 var groupBases = []; 1346 1347 var s = ''; 1348 var i = -1; 1349 while (++i < BN.wordSize) { 1350 zeros[i] = s; 1351 s += '0'; 1352 } 1353 groupSizes[0] = 0; 1354 groupSizes[1] = 0; 1355 groupBases[0] = 0; 1356 groupBases[1] = 0; 1357 var base = 2 - 1; 1358 while (++base < 36 + 1) { 1359 var groupSize = 0; 1360 var groupBase = 1; 1361 while (groupBase < (1 << BN.wordSize) / base) { 1362 groupBase *= base; 1363 groupSize += 1; 1364 } 1365 groupSizes[base] = groupSize; 1366 groupBases[base] = groupBase; 1367 } 1368 1369 */ 1370 1371 var zeros = [ 1372 '', 1373 '0', 1374 '00', 1375 '000', 1376 '0000', 1377 '00000', 1378 '000000', 1379 '0000000', 1380 '00000000', 1381 '000000000', 1382 '0000000000', 1383 '00000000000', 1384 '000000000000', 1385 '0000000000000', 1386 '00000000000000', 1387 '000000000000000', 1388 '0000000000000000', 1389 '00000000000000000', 1390 '000000000000000000', 1391 '0000000000000000000', 1392 '00000000000000000000', 1393 '000000000000000000000', 1394 '0000000000000000000000', 1395 '00000000000000000000000', 1396 '000000000000000000000000', 1397 '0000000000000000000000000' 1398 ]; 1399 1400 var groupSizes = [ 1401 0, 0, 1402 25, 16, 12, 11, 10, 9, 8, 1403 8, 7, 7, 7, 7, 6, 6, 1404 6, 6, 6, 6, 6, 5, 5, 1405 5, 5, 5, 5, 5, 5, 5, 1406 5, 5, 5, 5, 5, 5, 5 1407 ]; 1408 1409 var groupBases = [ 1410 0, 0, 1411 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 1412 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 1413 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 1414 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 1415 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176 1416 ]; 1417 1418 BN.prototype.toString = function toString (base, padding) { 1419 base = base || 10; 1420 padding = padding | 0 || 1; 1421 1422 var out; 1423 if (base === 16 || base === 'hex') { 1424 out = ''; 1425 var off = 0; 1426 var carry = 0; 1427 for (var i = 0; i < this.length; i++) { 1428 var w = this.words[i]; 1429 var word = (((w << off) | carry) & 0xffffff).toString(16); 1430 carry = (w >>> (24 - off)) & 0xffffff; 1431 if (carry !== 0 || i !== this.length - 1) { 1432 out = zeros[6 - word.length] + word + out; 1433 } else { 1434 out = word + out; 1435 } 1436 off += 2; 1437 if (off >= 26) { 1438 off -= 26; 1439 i--; 1440 } 1441 } 1442 if (carry !== 0) { 1443 out = carry.toString(16) + out; 1444 } 1445 while (out.length % padding !== 0) { 1446 out = '0' + out; 1447 } 1448 if (this.negative !== 0) { 1449 out = '-' + out; 1450 } 1451 return out; 1452 } 1453 1454 if (base === (base | 0) && base >= 2 && base <= 36) { 1455 // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); 1456 var groupSize = groupSizes[base]; 1457 // var groupBase = Math.pow(base, groupSize); 1458 var groupBase = groupBases[base]; 1459 out = ''; 1460 var c = this.clone(); 1461 c.negative = 0; 1462 while (!c.isZero()) { 1463 var r = c.modn(groupBase).toString(base); 1464 c = c.idivn(groupBase); 1465 1466 if (!c.isZero()) { 1467 out = zeros[groupSize - r.length] + r + out; 1468 } else { 1469 out = r + out; 1470 } 1471 } 1472 if (this.isZero()) { 1473 out = '0' + out; 1474 } 1475 while (out.length % padding !== 0) { 1476 out = '0' + out; 1477 } 1478 if (this.negative !== 0) { 1479 out = '-' + out; 1480 } 1481 return out; 1482 } 1483 1484 assert(false, 'Base should be between 2 and 36'); 1485 }; 1486 1487 BN.prototype.toNumber = function toNumber () { 1488 var ret = this.words[0]; 1489 if (this.length === 2) { 1490 ret += this.words[1] * 0x4000000; 1491 } else if (this.length === 3 && this.words[2] === 0x01) { 1492 // NOTE: at this stage it is known that the top bit is set 1493 ret += 0x10000000000000 + (this.words[1] * 0x4000000); 1494 } else if (this.length > 2) { 1495 assert(false, 'Number can only safely store up to 53 bits'); 1496 } 1497 return (this.negative !== 0) ? -ret : ret; 1498 }; 1499 1500 BN.prototype.toJSON = function toJSON () { 1501 return this.toString(16); 1502 }; 1503 1504 BN.prototype.toBuffer = function toBuffer (endian, length) { 1505 assert(typeof Buffer !== 'undefined'); 1506 return this.toArrayLike(Buffer, endian, length); 1507 }; 1508 1509 BN.prototype.toArray = function toArray (endian, length) { 1510 return this.toArrayLike(Array, endian, length); 1511 }; 1512 1513 BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) { 1514 var byteLength = this.byteLength(); 1515 var reqLength = length || Math.max(1, byteLength); 1516 assert(byteLength <= reqLength, 'byte array longer than desired length'); 1517 assert(reqLength > 0, 'Requested array length <= 0'); 1518 1519 this.strip(); 1520 var littleEndian = endian === 'le'; 1521 var res = new ArrayType(reqLength); 1522 1523 var b, i; 1524 var q = this.clone(); 1525 if (!littleEndian) { 1526 // Assume big-endian 1527 for (i = 0; i < reqLength - byteLength; i++) { 1528 res[i] = 0; 1529 } 1530 1531 for (i = 0; !q.isZero(); i++) { 1532 b = q.andln(0xff); 1533 q.iushrn(8); 1534 1535 res[reqLength - i - 1] = b; 1536 } 1537 } else { 1538 for (i = 0; !q.isZero(); i++) { 1539 b = q.andln(0xff); 1540 q.iushrn(8); 1541 1542 res[i] = b; 1543 } 1544 1545 for (; i < reqLength; i++) { 1546 res[i] = 0; 1547 } 1548 } 1549 1550 return res; 1551 }; 1552 1553 if (Math.clz32) { 1554 BN.prototype._countBits = function _countBits (w) { 1555 return 32 - Math.clz32(w); 1556 }; 1557 } else { 1558 BN.prototype._countBits = function _countBits (w) { 1559 var t = w; 1560 var r = 0; 1561 if (t >= 0x1000) { 1562 r += 13; 1563 t >>>= 13; 1564 } 1565 if (t >= 0x40) { 1566 r += 7; 1567 t >>>= 7; 1568 } 1569 if (t >= 0x8) { 1570 r += 4; 1571 t >>>= 4; 1572 } 1573 if (t >= 0x02) { 1574 r += 2; 1575 t >>>= 2; 1576 } 1577 return r + t; 1578 }; 1579 } 1580 1581 BN.prototype._zeroBits = function _zeroBits (w) { 1582 // Short-cut 1583 if (w === 0) return 26; 1584 1585 var t = w; 1586 var r = 0; 1587 if ((t & 0x1fff) === 0) { 1588 r += 13; 1589 t >>>= 13; 1590 } 1591 if ((t & 0x7f) === 0) { 1592 r += 7; 1593 t >>>= 7; 1594 } 1595 if ((t & 0xf) === 0) { 1596 r += 4; 1597 t >>>= 4; 1598 } 1599 if ((t & 0x3) === 0) { 1600 r += 2; 1601 t >>>= 2; 1602 } 1603 if ((t & 0x1) === 0) { 1604 r++; 1605 } 1606 return r; 1607 }; 1608 1609 // Return number of used bits in a BN 1610 BN.prototype.bitLength = function bitLength () { 1611 var w = this.words[this.length - 1]; 1612 var hi = this._countBits(w); 1613 return (this.length - 1) * 26 + hi; 1614 }; 1615 1616 function toBitArray (num) { 1617 var w = new Array(num.bitLength()); 1618 1619 for (var bit = 0; bit < w.length; bit++) { 1620 var off = (bit / 26) | 0; 1621 var wbit = bit % 26; 1622 1623 w[bit] = (num.words[off] & (1 << wbit)) >>> wbit; 1624 } 1625 1626 return w; 1627 } 1628 1629 // Number of trailing zero bits 1630 BN.prototype.zeroBits = function zeroBits () { 1631 if (this.isZero()) return 0; 1632 1633 var r = 0; 1634 for (var i = 0; i < this.length; i++) { 1635 var b = this._zeroBits(this.words[i]); 1636 r += b; 1637 if (b !== 26) break; 1638 } 1639 return r; 1640 }; 1641 1642 BN.prototype.byteLength = function byteLength () { 1643 return Math.ceil(this.bitLength() / 8); 1644 }; 1645 1646 BN.prototype.toTwos = function toTwos (width) { 1647 if (this.negative !== 0) { 1648 return this.abs().inotn(width).iaddn(1); 1649 } 1650 return this.clone(); 1651 }; 1652 1653 BN.prototype.fromTwos = function fromTwos (width) { 1654 if (this.testn(width - 1)) { 1655 return this.notn(width).iaddn(1).ineg(); 1656 } 1657 return this.clone(); 1658 }; 1659 1660 BN.prototype.isNeg = function isNeg () { 1661 return this.negative !== 0; 1662 }; 1663 1664 // Return negative clone of `this` 1665 BN.prototype.neg = function neg () { 1666 return this.clone().ineg(); 1667 }; 1668 1669 BN.prototype.ineg = function ineg () { 1670 if (!this.isZero()) { 1671 this.negative ^= 1; 1672 } 1673 1674 return this; 1675 }; 1676 1677 // Or `num` with `this` in-place 1678 BN.prototype.iuor = function iuor (num) { 1679 while (this.length < num.length) { 1680 this.words[this.length++] = 0; 1681 } 1682 1683 for (var i = 0; i < num.length; i++) { 1684 this.words[i] = this.words[i] | num.words[i]; 1685 } 1686 1687 return this.strip(); 1688 }; 1689 1690 BN.prototype.ior = function ior (num) { 1691 assert((this.negative | num.negative) === 0); 1692 return this.iuor(num); 1693 }; 1694 1695 // Or `num` with `this` 1696 BN.prototype.or = function or (num) { 1697 if (this.length > num.length) return this.clone().ior(num); 1698 return num.clone().ior(this); 1699 }; 1700 1701 BN.prototype.uor = function uor (num) { 1702 if (this.length > num.length) return this.clone().iuor(num); 1703 return num.clone().iuor(this); 1704 }; 1705 1706 // And `num` with `this` in-place 1707 BN.prototype.iuand = function iuand (num) { 1708 // b = min-length(num, this) 1709 var b; 1710 if (this.length > num.length) { 1711 b = num; 1712 } else { 1713 b = this; 1714 } 1715 1716 for (var i = 0; i < b.length; i++) { 1717 this.words[i] = this.words[i] & num.words[i]; 1718 } 1719 1720 this.length = b.length; 1721 1722 return this.strip(); 1723 }; 1724 1725 BN.prototype.iand = function iand (num) { 1726 assert((this.negative | num.negative) === 0); 1727 return this.iuand(num); 1728 }; 1729 1730 // And `num` with `this` 1731 BN.prototype.and = function and (num) { 1732 if (this.length > num.length) return this.clone().iand(num); 1733 return num.clone().iand(this); 1734 }; 1735 1736 BN.prototype.uand = function uand (num) { 1737 if (this.length > num.length) return this.clone().iuand(num); 1738 return num.clone().iuand(this); 1739 }; 1740 1741 // Xor `num` with `this` in-place 1742 BN.prototype.iuxor = function iuxor (num) { 1743 // a.length > b.length 1744 var a; 1745 var b; 1746 if (this.length > num.length) { 1747 a = this; 1748 b = num; 1749 } else { 1750 a = num; 1751 b = this; 1752 } 1753 1754 for (var i = 0; i < b.length; i++) { 1755 this.words[i] = a.words[i] ^ b.words[i]; 1756 } 1757 1758 if (this !== a) { 1759 for (; i < a.length; i++) { 1760 this.words[i] = a.words[i]; 1761 } 1762 } 1763 1764 this.length = a.length; 1765 1766 return this.strip(); 1767 }; 1768 1769 BN.prototype.ixor = function ixor (num) { 1770 assert((this.negative | num.negative) === 0); 1771 return this.iuxor(num); 1772 }; 1773 1774 // Xor `num` with `this` 1775 BN.prototype.xor = function xor (num) { 1776 if (this.length > num.length) return this.clone().ixor(num); 1777 return num.clone().ixor(this); 1778 }; 1779 1780 BN.prototype.uxor = function uxor (num) { 1781 if (this.length > num.length) return this.clone().iuxor(num); 1782 return num.clone().iuxor(this); 1783 }; 1784 1785 // Not ``this`` with ``width`` bitwidth 1786 BN.prototype.inotn = function inotn (width) { 1787 assert(typeof width === 'number' && width >= 0); 1788 1789 var bytesNeeded = Math.ceil(width / 26) | 0; 1790 var bitsLeft = width % 26; 1791 1792 // Extend the buffer with leading zeroes 1793 this._expand(bytesNeeded); 1794 1795 if (bitsLeft > 0) { 1796 bytesNeeded--; 1797 } 1798 1799 // Handle complete words 1800 for (var i = 0; i < bytesNeeded; i++) { 1801 this.words[i] = ~this.words[i] & 0x3ffffff; 1802 } 1803 1804 // Handle the residue 1805 if (bitsLeft > 0) { 1806 this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft)); 1807 } 1808 1809 // And remove leading zeroes 1810 return this.strip(); 1811 }; 1812 1813 BN.prototype.notn = function notn (width) { 1814 return this.clone().inotn(width); 1815 }; 1816 1817 // Set `bit` of `this` 1818 BN.prototype.setn = function setn (bit, val) { 1819 assert(typeof bit === 'number' && bit >= 0); 1820 1821 var off = (bit / 26) | 0; 1822 var wbit = bit % 26; 1823 1824 this._expand(off + 1); 1825 1826 if (val) { 1827 this.words[off] = this.words[off] | (1 << wbit); 1828 } else { 1829 this.words[off] = this.words[off] & ~(1 << wbit); 1830 } 1831 1832 return this.strip(); 1833 }; 1834 1835 // Add `num` to `this` in-place 1836 BN.prototype.iadd = function iadd (num) { 1837 var r; 1838 1839 // negative + positive 1840 if (this.negative !== 0 && num.negative === 0) { 1841 this.negative = 0; 1842 r = this.isub(num); 1843 this.negative ^= 1; 1844 return this._normSign(); 1845 1846 // positive + negative 1847 } else if (this.negative === 0 && num.negative !== 0) { 1848 num.negative = 0; 1849 r = this.isub(num); 1850 num.negative = 1; 1851 return r._normSign(); 1852 } 1853 1854 // a.length > b.length 1855 var a, b; 1856 if (this.length > num.length) { 1857 a = this; 1858 b = num; 1859 } else { 1860 a = num; 1861 b = this; 1862 } 1863 1864 var carry = 0; 1865 for (var i = 0; i < b.length; i++) { 1866 r = (a.words[i] | 0) + (b.words[i] | 0) + carry; 1867 this.words[i] = r & 0x3ffffff; 1868 carry = r >>> 26; 1869 } 1870 for (; carry !== 0 && i < a.length; i++) { 1871 r = (a.words[i] | 0) + carry; 1872 this.words[i] = r & 0x3ffffff; 1873 carry = r >>> 26; 1874 } 1875 1876 this.length = a.length; 1877 if (carry !== 0) { 1878 this.words[this.length] = carry; 1879 this.length++; 1880 // Copy the rest of the words 1881 } else if (a !== this) { 1882 for (; i < a.length; i++) { 1883 this.words[i] = a.words[i]; 1884 } 1885 } 1886 1887 return this; 1888 }; 1889 1890 // Add `num` to `this` 1891 BN.prototype.add = function add (num) { 1892 var res; 1893 if (num.negative !== 0 && this.negative === 0) { 1894 num.negative = 0; 1895 res = this.sub(num); 1896 num.negative ^= 1; 1897 return res; 1898 } else if (num.negative === 0 && this.negative !== 0) { 1899 this.negative = 0; 1900 res = num.sub(this); 1901 this.negative = 1; 1902 return res; 1903 } 1904 1905 if (this.length > num.length) return this.clone().iadd(num); 1906 1907 return num.clone().iadd(this); 1908 }; 1909 1910 // Subtract `num` from `this` in-place 1911 BN.prototype.isub = function isub (num) { 1912 // this - (-num) = this + num 1913 if (num.negative !== 0) { 1914 num.negative = 0; 1915 var r = this.iadd(num); 1916 num.negative = 1; 1917 return r._normSign(); 1918 1919 // -this - num = -(this + num) 1920 } else if (this.negative !== 0) { 1921 this.negative = 0; 1922 this.iadd(num); 1923 this.negative = 1; 1924 return this._normSign(); 1925 } 1926 1927 // At this point both numbers are positive 1928 var cmp = this.cmp(num); 1929 1930 // Optimization - zeroify 1931 if (cmp === 0) { 1932 this.negative = 0; 1933 this.length = 1; 1934 this.words[0] = 0; 1935 return this; 1936 } 1937 1938 // a > b 1939 var a, b; 1940 if (cmp > 0) { 1941 a = this; 1942 b = num; 1943 } else { 1944 a = num; 1945 b = this; 1946 } 1947 1948 var carry = 0; 1949 for (var i = 0; i < b.length; i++) { 1950 r = (a.words[i] | 0) - (b.words[i] | 0) + carry; 1951 carry = r >> 26; 1952 this.words[i] = r & 0x3ffffff; 1953 } 1954 for (; carry !== 0 && i < a.length; i++) { 1955 r = (a.words[i] | 0) + carry; 1956 carry = r >> 26; 1957 this.words[i] = r & 0x3ffffff; 1958 } 1959 1960 // Copy rest of the words 1961 if (carry === 0 && i < a.length && a !== this) { 1962 for (; i < a.length; i++) { 1963 this.words[i] = a.words[i]; 1964 } 1965 } 1966 1967 this.length = Math.max(this.length, i); 1968 1969 if (a !== this) { 1970 this.negative = 1; 1971 } 1972 1973 return this.strip(); 1974 }; 1975 1976 // Subtract `num` from `this` 1977 BN.prototype.sub = function sub (num) { 1978 return this.clone().isub(num); 1979 }; 1980 1981 function smallMulTo (self, num, out) { 1982 out.negative = num.negative ^ self.negative; 1983 var len = (self.length + num.length) | 0; 1984 out.length = len; 1985 len = (len - 1) | 0; 1986 1987 // Peel one iteration (compiler can't do it, because of code complexity) 1988 var a = self.words[0] | 0; 1989 var b = num.words[0] | 0; 1990 var r = a * b; 1991 1992 var lo = r & 0x3ffffff; 1993 var carry = (r / 0x4000000) | 0; 1994 out.words[0] = lo; 1995 1996 for (var k = 1; k < len; k++) { 1997 // Sum all words with the same `i + j = k` and accumulate `ncarry`, 1998 // note that ncarry could be >= 0x3ffffff 1999 var ncarry = carry >>> 26; 2000 var rword = carry & 0x3ffffff; 2001 var maxJ = Math.min(k, num.length - 1); 2002 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { 2003 var i = (k - j) | 0; 2004 a = self.words[i] | 0; 2005 b = num.words[j] | 0; 2006 r = a * b + rword; 2007 ncarry += (r / 0x4000000) | 0; 2008 rword = r & 0x3ffffff; 2009 } 2010 out.words[k] = rword | 0; 2011 carry = ncarry | 0; 2012 } 2013 if (carry !== 0) { 2014 out.words[k] = carry | 0; 2015 } else { 2016 out.length--; 2017 } 2018 2019 return out.strip(); 2020 } 2021 2022 // TODO(indutny): it may be reasonable to omit it for users who don't need 2023 // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit 2024 // multiplication (like elliptic secp256k1). 2025 var comb10MulTo = function comb10MulTo (self, num, out) { 2026 var a = self.words; 2027 var b = num.words; 2028 var o = out.words; 2029 var c = 0; 2030 var lo; 2031 var mid; 2032 var hi; 2033 var a0 = a[0] | 0; 2034 var al0 = a0 & 0x1fff; 2035 var ah0 = a0 >>> 13; 2036 var a1 = a[1] | 0; 2037 var al1 = a1 & 0x1fff; 2038 var ah1 = a1 >>> 13; 2039 var a2 = a[2] | 0; 2040 var al2 = a2 & 0x1fff; 2041 var ah2 = a2 >>> 13; 2042 var a3 = a[3] | 0; 2043 var al3 = a3 & 0x1fff; 2044 var ah3 = a3 >>> 13; 2045 var a4 = a[4] | 0; 2046 var al4 = a4 & 0x1fff; 2047 var ah4 = a4 >>> 13; 2048 var a5 = a[5] | 0; 2049 var al5 = a5 & 0x1fff; 2050 var ah5 = a5 >>> 13; 2051 var a6 = a[6] | 0; 2052 var al6 = a6 & 0x1fff; 2053 var ah6 = a6 >>> 13; 2054 var a7 = a[7] | 0; 2055 var al7 = a7 & 0x1fff; 2056 var ah7 = a7 >>> 13; 2057 var a8 = a[8] | 0; 2058 var al8 = a8 & 0x1fff; 2059 var ah8 = a8 >>> 13; 2060 var a9 = a[9] | 0; 2061 var al9 = a9 & 0x1fff; 2062 var ah9 = a9 >>> 13; 2063 var b0 = b[0] | 0; 2064 var bl0 = b0 & 0x1fff; 2065 var bh0 = b0 >>> 13; 2066 var b1 = b[1] | 0; 2067 var bl1 = b1 & 0x1fff; 2068 var bh1 = b1 >>> 13; 2069 var b2 = b[2] | 0; 2070 var bl2 = b2 & 0x1fff; 2071 var bh2 = b2 >>> 13; 2072 var b3 = b[3] | 0; 2073 var bl3 = b3 & 0x1fff; 2074 var bh3 = b3 >>> 13; 2075 var b4 = b[4] | 0; 2076 var bl4 = b4 & 0x1fff; 2077 var bh4 = b4 >>> 13; 2078 var b5 = b[5] | 0; 2079 var bl5 = b5 & 0x1fff; 2080 var bh5 = b5 >>> 13; 2081 var b6 = b[6] | 0; 2082 var bl6 = b6 & 0x1fff; 2083 var bh6 = b6 >>> 13; 2084 var b7 = b[7] | 0; 2085 var bl7 = b7 & 0x1fff; 2086 var bh7 = b7 >>> 13; 2087 var b8 = b[8] | 0; 2088 var bl8 = b8 & 0x1fff; 2089 var bh8 = b8 >>> 13; 2090 var b9 = b[9] | 0; 2091 var bl9 = b9 & 0x1fff; 2092 var bh9 = b9 >>> 13; 2093 2094 out.negative = self.negative ^ num.negative; 2095 out.length = 19; 2096 /* k = 0 */ 2097 lo = Math.imul(al0, bl0); 2098 mid = Math.imul(al0, bh0); 2099 mid = (mid + Math.imul(ah0, bl0)) | 0; 2100 hi = Math.imul(ah0, bh0); 2101 var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2102 c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0; 2103 w0 &= 0x3ffffff; 2104 /* k = 1 */ 2105 lo = Math.imul(al1, bl0); 2106 mid = Math.imul(al1, bh0); 2107 mid = (mid + Math.imul(ah1, bl0)) | 0; 2108 hi = Math.imul(ah1, bh0); 2109 lo = (lo + Math.imul(al0, bl1)) | 0; 2110 mid = (mid + Math.imul(al0, bh1)) | 0; 2111 mid = (mid + Math.imul(ah0, bl1)) | 0; 2112 hi = (hi + Math.imul(ah0, bh1)) | 0; 2113 var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2114 c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0; 2115 w1 &= 0x3ffffff; 2116 /* k = 2 */ 2117 lo = Math.imul(al2, bl0); 2118 mid = Math.imul(al2, bh0); 2119 mid = (mid + Math.imul(ah2, bl0)) | 0; 2120 hi = Math.imul(ah2, bh0); 2121 lo = (lo + Math.imul(al1, bl1)) | 0; 2122 mid = (mid + Math.imul(al1, bh1)) | 0; 2123 mid = (mid + Math.imul(ah1, bl1)) | 0; 2124 hi = (hi + Math.imul(ah1, bh1)) | 0; 2125 lo = (lo + Math.imul(al0, bl2)) | 0; 2126 mid = (mid + Math.imul(al0, bh2)) | 0; 2127 mid = (mid + Math.imul(ah0, bl2)) | 0; 2128 hi = (hi + Math.imul(ah0, bh2)) | 0; 2129 var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2130 c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0; 2131 w2 &= 0x3ffffff; 2132 /* k = 3 */ 2133 lo = Math.imul(al3, bl0); 2134 mid = Math.imul(al3, bh0); 2135 mid = (mid + Math.imul(ah3, bl0)) | 0; 2136 hi = Math.imul(ah3, bh0); 2137 lo = (lo + Math.imul(al2, bl1)) | 0; 2138 mid = (mid + Math.imul(al2, bh1)) | 0; 2139 mid = (mid + Math.imul(ah2, bl1)) | 0; 2140 hi = (hi + Math.imul(ah2, bh1)) | 0; 2141 lo = (lo + Math.imul(al1, bl2)) | 0; 2142 mid = (mid + Math.imul(al1, bh2)) | 0; 2143 mid = (mid + Math.imul(ah1, bl2)) | 0; 2144 hi = (hi + Math.imul(ah1, bh2)) | 0; 2145 lo = (lo + Math.imul(al0, bl3)) | 0; 2146 mid = (mid + Math.imul(al0, bh3)) | 0; 2147 mid = (mid + Math.imul(ah0, bl3)) | 0; 2148 hi = (hi + Math.imul(ah0, bh3)) | 0; 2149 var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2150 c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0; 2151 w3 &= 0x3ffffff; 2152 /* k = 4 */ 2153 lo = Math.imul(al4, bl0); 2154 mid = Math.imul(al4, bh0); 2155 mid = (mid + Math.imul(ah4, bl0)) | 0; 2156 hi = Math.imul(ah4, bh0); 2157 lo = (lo + Math.imul(al3, bl1)) | 0; 2158 mid = (mid + Math.imul(al3, bh1)) | 0; 2159 mid = (mid + Math.imul(ah3, bl1)) | 0; 2160 hi = (hi + Math.imul(ah3, bh1)) | 0; 2161 lo = (lo + Math.imul(al2, bl2)) | 0; 2162 mid = (mid + Math.imul(al2, bh2)) | 0; 2163 mid = (mid + Math.imul(ah2, bl2)) | 0; 2164 hi = (hi + Math.imul(ah2, bh2)) | 0; 2165 lo = (lo + Math.imul(al1, bl3)) | 0; 2166 mid = (mid + Math.imul(al1, bh3)) | 0; 2167 mid = (mid + Math.imul(ah1, bl3)) | 0; 2168 hi = (hi + Math.imul(ah1, bh3)) | 0; 2169 lo = (lo + Math.imul(al0, bl4)) | 0; 2170 mid = (mid + Math.imul(al0, bh4)) | 0; 2171 mid = (mid + Math.imul(ah0, bl4)) | 0; 2172 hi = (hi + Math.imul(ah0, bh4)) | 0; 2173 var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2174 c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0; 2175 w4 &= 0x3ffffff; 2176 /* k = 5 */ 2177 lo = Math.imul(al5, bl0); 2178 mid = Math.imul(al5, bh0); 2179 mid = (mid + Math.imul(ah5, bl0)) | 0; 2180 hi = Math.imul(ah5, bh0); 2181 lo = (lo + Math.imul(al4, bl1)) | 0; 2182 mid = (mid + Math.imul(al4, bh1)) | 0; 2183 mid = (mid + Math.imul(ah4, bl1)) | 0; 2184 hi = (hi + Math.imul(ah4, bh1)) | 0; 2185 lo = (lo + Math.imul(al3, bl2)) | 0; 2186 mid = (mid + Math.imul(al3, bh2)) | 0; 2187 mid = (mid + Math.imul(ah3, bl2)) | 0; 2188 hi = (hi + Math.imul(ah3, bh2)) | 0; 2189 lo = (lo + Math.imul(al2, bl3)) | 0; 2190 mid = (mid + Math.imul(al2, bh3)) | 0; 2191 mid = (mid + Math.imul(ah2, bl3)) | 0; 2192 hi = (hi + Math.imul(ah2, bh3)) | 0; 2193 lo = (lo + Math.imul(al1, bl4)) | 0; 2194 mid = (mid + Math.imul(al1, bh4)) | 0; 2195 mid = (mid + Math.imul(ah1, bl4)) | 0; 2196 hi = (hi + Math.imul(ah1, bh4)) | 0; 2197 lo = (lo + Math.imul(al0, bl5)) | 0; 2198 mid = (mid + Math.imul(al0, bh5)) | 0; 2199 mid = (mid + Math.imul(ah0, bl5)) | 0; 2200 hi = (hi + Math.imul(ah0, bh5)) | 0; 2201 var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2202 c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0; 2203 w5 &= 0x3ffffff; 2204 /* k = 6 */ 2205 lo = Math.imul(al6, bl0); 2206 mid = Math.imul(al6, bh0); 2207 mid = (mid + Math.imul(ah6, bl0)) | 0; 2208 hi = Math.imul(ah6, bh0); 2209 lo = (lo + Math.imul(al5, bl1)) | 0; 2210 mid = (mid + Math.imul(al5, bh1)) | 0; 2211 mid = (mid + Math.imul(ah5, bl1)) | 0; 2212 hi = (hi + Math.imul(ah5, bh1)) | 0; 2213 lo = (lo + Math.imul(al4, bl2)) | 0; 2214 mid = (mid + Math.imul(al4, bh2)) | 0; 2215 mid = (mid + Math.imul(ah4, bl2)) | 0; 2216 hi = (hi + Math.imul(ah4, bh2)) | 0; 2217 lo = (lo + Math.imul(al3, bl3)) | 0; 2218 mid = (mid + Math.imul(al3, bh3)) | 0; 2219 mid = (mid + Math.imul(ah3, bl3)) | 0; 2220 hi = (hi + Math.imul(ah3, bh3)) | 0; 2221 lo = (lo + Math.imul(al2, bl4)) | 0; 2222 mid = (mid + Math.imul(al2, bh4)) | 0; 2223 mid = (mid + Math.imul(ah2, bl4)) | 0; 2224 hi = (hi + Math.imul(ah2, bh4)) | 0; 2225 lo = (lo + Math.imul(al1, bl5)) | 0; 2226 mid = (mid + Math.imul(al1, bh5)) | 0; 2227 mid = (mid + Math.imul(ah1, bl5)) | 0; 2228 hi = (hi + Math.imul(ah1, bh5)) | 0; 2229 lo = (lo + Math.imul(al0, bl6)) | 0; 2230 mid = (mid + Math.imul(al0, bh6)) | 0; 2231 mid = (mid + Math.imul(ah0, bl6)) | 0; 2232 hi = (hi + Math.imul(ah0, bh6)) | 0; 2233 var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2234 c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0; 2235 w6 &= 0x3ffffff; 2236 /* k = 7 */ 2237 lo = Math.imul(al7, bl0); 2238 mid = Math.imul(al7, bh0); 2239 mid = (mid + Math.imul(ah7, bl0)) | 0; 2240 hi = Math.imul(ah7, bh0); 2241 lo = (lo + Math.imul(al6, bl1)) | 0; 2242 mid = (mid + Math.imul(al6, bh1)) | 0; 2243 mid = (mid + Math.imul(ah6, bl1)) | 0; 2244 hi = (hi + Math.imul(ah6, bh1)) | 0; 2245 lo = (lo + Math.imul(al5, bl2)) | 0; 2246 mid = (mid + Math.imul(al5, bh2)) | 0; 2247 mid = (mid + Math.imul(ah5, bl2)) | 0; 2248 hi = (hi + Math.imul(ah5, bh2)) | 0; 2249 lo = (lo + Math.imul(al4, bl3)) | 0; 2250 mid = (mid + Math.imul(al4, bh3)) | 0; 2251 mid = (mid + Math.imul(ah4, bl3)) | 0; 2252 hi = (hi + Math.imul(ah4, bh3)) | 0; 2253 lo = (lo + Math.imul(al3, bl4)) | 0; 2254 mid = (mid + Math.imul(al3, bh4)) | 0; 2255 mid = (mid + Math.imul(ah3, bl4)) | 0; 2256 hi = (hi + Math.imul(ah3, bh4)) | 0; 2257 lo = (lo + Math.imul(al2, bl5)) | 0; 2258 mid = (mid + Math.imul(al2, bh5)) | 0; 2259 mid = (mid + Math.imul(ah2, bl5)) | 0; 2260 hi = (hi + Math.imul(ah2, bh5)) | 0; 2261 lo = (lo + Math.imul(al1, bl6)) | 0; 2262 mid = (mid + Math.imul(al1, bh6)) | 0; 2263 mid = (mid + Math.imul(ah1, bl6)) | 0; 2264 hi = (hi + Math.imul(ah1, bh6)) | 0; 2265 lo = (lo + Math.imul(al0, bl7)) | 0; 2266 mid = (mid + Math.imul(al0, bh7)) | 0; 2267 mid = (mid + Math.imul(ah0, bl7)) | 0; 2268 hi = (hi + Math.imul(ah0, bh7)) | 0; 2269 var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2270 c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0; 2271 w7 &= 0x3ffffff; 2272 /* k = 8 */ 2273 lo = Math.imul(al8, bl0); 2274 mid = Math.imul(al8, bh0); 2275 mid = (mid + Math.imul(ah8, bl0)) | 0; 2276 hi = Math.imul(ah8, bh0); 2277 lo = (lo + Math.imul(al7, bl1)) | 0; 2278 mid = (mid + Math.imul(al7, bh1)) | 0; 2279 mid = (mid + Math.imul(ah7, bl1)) | 0; 2280 hi = (hi + Math.imul(ah7, bh1)) | 0; 2281 lo = (lo + Math.imul(al6, bl2)) | 0; 2282 mid = (mid + Math.imul(al6, bh2)) | 0; 2283 mid = (mid + Math.imul(ah6, bl2)) | 0; 2284 hi = (hi + Math.imul(ah6, bh2)) | 0; 2285 lo = (lo + Math.imul(al5, bl3)) | 0; 2286 mid = (mid + Math.imul(al5, bh3)) | 0; 2287 mid = (mid + Math.imul(ah5, bl3)) | 0; 2288 hi = (hi + Math.imul(ah5, bh3)) | 0; 2289 lo = (lo + Math.imul(al4, bl4)) | 0; 2290 mid = (mid + Math.imul(al4, bh4)) | 0; 2291 mid = (mid + Math.imul(ah4, bl4)) | 0; 2292 hi = (hi + Math.imul(ah4, bh4)) | 0; 2293 lo = (lo + Math.imul(al3, bl5)) | 0; 2294 mid = (mid + Math.imul(al3, bh5)) | 0; 2295 mid = (mid + Math.imul(ah3, bl5)) | 0; 2296 hi = (hi + Math.imul(ah3, bh5)) | 0; 2297 lo = (lo + Math.imul(al2, bl6)) | 0; 2298 mid = (mid + Math.imul(al2, bh6)) | 0; 2299 mid = (mid + Math.imul(ah2, bl6)) | 0; 2300 hi = (hi + Math.imul(ah2, bh6)) | 0; 2301 lo = (lo + Math.imul(al1, bl7)) | 0; 2302 mid = (mid + Math.imul(al1, bh7)) | 0; 2303 mid = (mid + Math.imul(ah1, bl7)) | 0; 2304 hi = (hi + Math.imul(ah1, bh7)) | 0; 2305 lo = (lo + Math.imul(al0, bl8)) | 0; 2306 mid = (mid + Math.imul(al0, bh8)) | 0; 2307 mid = (mid + Math.imul(ah0, bl8)) | 0; 2308 hi = (hi + Math.imul(ah0, bh8)) | 0; 2309 var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2310 c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0; 2311 w8 &= 0x3ffffff; 2312 /* k = 9 */ 2313 lo = Math.imul(al9, bl0); 2314 mid = Math.imul(al9, bh0); 2315 mid = (mid + Math.imul(ah9, bl0)) | 0; 2316 hi = Math.imul(ah9, bh0); 2317 lo = (lo + Math.imul(al8, bl1)) | 0; 2318 mid = (mid + Math.imul(al8, bh1)) | 0; 2319 mid = (mid + Math.imul(ah8, bl1)) | 0; 2320 hi = (hi + Math.imul(ah8, bh1)) | 0; 2321 lo = (lo + Math.imul(al7, bl2)) | 0; 2322 mid = (mid + Math.imul(al7, bh2)) | 0; 2323 mid = (mid + Math.imul(ah7, bl2)) | 0; 2324 hi = (hi + Math.imul(ah7, bh2)) | 0; 2325 lo = (lo + Math.imul(al6, bl3)) | 0; 2326 mid = (mid + Math.imul(al6, bh3)) | 0; 2327 mid = (mid + Math.imul(ah6, bl3)) | 0; 2328 hi = (hi + Math.imul(ah6, bh3)) | 0; 2329 lo = (lo + Math.imul(al5, bl4)) | 0; 2330 mid = (mid + Math.imul(al5, bh4)) | 0; 2331 mid = (mid + Math.imul(ah5, bl4)) | 0; 2332 hi = (hi + Math.imul(ah5, bh4)) | 0; 2333 lo = (lo + Math.imul(al4, bl5)) | 0; 2334 mid = (mid + Math.imul(al4, bh5)) | 0; 2335 mid = (mid + Math.imul(ah4, bl5)) | 0; 2336 hi = (hi + Math.imul(ah4, bh5)) | 0; 2337 lo = (lo + Math.imul(al3, bl6)) | 0; 2338 mid = (mid + Math.imul(al3, bh6)) | 0; 2339 mid = (mid + Math.imul(ah3, bl6)) | 0; 2340 hi = (hi + Math.imul(ah3, bh6)) | 0; 2341 lo = (lo + Math.imul(al2, bl7)) | 0; 2342 mid = (mid + Math.imul(al2, bh7)) | 0; 2343 mid = (mid + Math.imul(ah2, bl7)) | 0; 2344 hi = (hi + Math.imul(ah2, bh7)) | 0; 2345 lo = (lo + Math.imul(al1, bl8)) | 0; 2346 mid = (mid + Math.imul(al1, bh8)) | 0; 2347 mid = (mid + Math.imul(ah1, bl8)) | 0; 2348 hi = (hi + Math.imul(ah1, bh8)) | 0; 2349 lo = (lo + Math.imul(al0, bl9)) | 0; 2350 mid = (mid + Math.imul(al0, bh9)) | 0; 2351 mid = (mid + Math.imul(ah0, bl9)) | 0; 2352 hi = (hi + Math.imul(ah0, bh9)) | 0; 2353 var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2354 c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0; 2355 w9 &= 0x3ffffff; 2356 /* k = 10 */ 2357 lo = Math.imul(al9, bl1); 2358 mid = Math.imul(al9, bh1); 2359 mid = (mid + Math.imul(ah9, bl1)) | 0; 2360 hi = Math.imul(ah9, bh1); 2361 lo = (lo + Math.imul(al8, bl2)) | 0; 2362 mid = (mid + Math.imul(al8, bh2)) | 0; 2363 mid = (mid + Math.imul(ah8, bl2)) | 0; 2364 hi = (hi + Math.imul(ah8, bh2)) | 0; 2365 lo = (lo + Math.imul(al7, bl3)) | 0; 2366 mid = (mid + Math.imul(al7, bh3)) | 0; 2367 mid = (mid + Math.imul(ah7, bl3)) | 0; 2368 hi = (hi + Math.imul(ah7, bh3)) | 0; 2369 lo = (lo + Math.imul(al6, bl4)) | 0; 2370 mid = (mid + Math.imul(al6, bh4)) | 0; 2371 mid = (mid + Math.imul(ah6, bl4)) | 0; 2372 hi = (hi + Math.imul(ah6, bh4)) | 0; 2373 lo = (lo + Math.imul(al5, bl5)) | 0; 2374 mid = (mid + Math.imul(al5, bh5)) | 0; 2375 mid = (mid + Math.imul(ah5, bl5)) | 0; 2376 hi = (hi + Math.imul(ah5, bh5)) | 0; 2377 lo = (lo + Math.imul(al4, bl6)) | 0; 2378 mid = (mid + Math.imul(al4, bh6)) | 0; 2379 mid = (mid + Math.imul(ah4, bl6)) | 0; 2380 hi = (hi + Math.imul(ah4, bh6)) | 0; 2381 lo = (lo + Math.imul(al3, bl7)) | 0; 2382 mid = (mid + Math.imul(al3, bh7)) | 0; 2383 mid = (mid + Math.imul(ah3, bl7)) | 0; 2384 hi = (hi + Math.imul(ah3, bh7)) | 0; 2385 lo = (lo + Math.imul(al2, bl8)) | 0; 2386 mid = (mid + Math.imul(al2, bh8)) | 0; 2387 mid = (mid + Math.imul(ah2, bl8)) | 0; 2388 hi = (hi + Math.imul(ah2, bh8)) | 0; 2389 lo = (lo + Math.imul(al1, bl9)) | 0; 2390 mid = (mid + Math.imul(al1, bh9)) | 0; 2391 mid = (mid + Math.imul(ah1, bl9)) | 0; 2392 hi = (hi + Math.imul(ah1, bh9)) | 0; 2393 var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2394 c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0; 2395 w10 &= 0x3ffffff; 2396 /* k = 11 */ 2397 lo = Math.imul(al9, bl2); 2398 mid = Math.imul(al9, bh2); 2399 mid = (mid + Math.imul(ah9, bl2)) | 0; 2400 hi = Math.imul(ah9, bh2); 2401 lo = (lo + Math.imul(al8, bl3)) | 0; 2402 mid = (mid + Math.imul(al8, bh3)) | 0; 2403 mid = (mid + Math.imul(ah8, bl3)) | 0; 2404 hi = (hi + Math.imul(ah8, bh3)) | 0; 2405 lo = (lo + Math.imul(al7, bl4)) | 0; 2406 mid = (mid + Math.imul(al7, bh4)) | 0; 2407 mid = (mid + Math.imul(ah7, bl4)) | 0; 2408 hi = (hi + Math.imul(ah7, bh4)) | 0; 2409 lo = (lo + Math.imul(al6, bl5)) | 0; 2410 mid = (mid + Math.imul(al6, bh5)) | 0; 2411 mid = (mid + Math.imul(ah6, bl5)) | 0; 2412 hi = (hi + Math.imul(ah6, bh5)) | 0; 2413 lo = (lo + Math.imul(al5, bl6)) | 0; 2414 mid = (mid + Math.imul(al5, bh6)) | 0; 2415 mid = (mid + Math.imul(ah5, bl6)) | 0; 2416 hi = (hi + Math.imul(ah5, bh6)) | 0; 2417 lo = (lo + Math.imul(al4, bl7)) | 0; 2418 mid = (mid + Math.imul(al4, bh7)) | 0; 2419 mid = (mid + Math.imul(ah4, bl7)) | 0; 2420 hi = (hi + Math.imul(ah4, bh7)) | 0; 2421 lo = (lo + Math.imul(al3, bl8)) | 0; 2422 mid = (mid + Math.imul(al3, bh8)) | 0; 2423 mid = (mid + Math.imul(ah3, bl8)) | 0; 2424 hi = (hi + Math.imul(ah3, bh8)) | 0; 2425 lo = (lo + Math.imul(al2, bl9)) | 0; 2426 mid = (mid + Math.imul(al2, bh9)) | 0; 2427 mid = (mid + Math.imul(ah2, bl9)) | 0; 2428 hi = (hi + Math.imul(ah2, bh9)) | 0; 2429 var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2430 c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0; 2431 w11 &= 0x3ffffff; 2432 /* k = 12 */ 2433 lo = Math.imul(al9, bl3); 2434 mid = Math.imul(al9, bh3); 2435 mid = (mid + Math.imul(ah9, bl3)) | 0; 2436 hi = Math.imul(ah9, bh3); 2437 lo = (lo + Math.imul(al8, bl4)) | 0; 2438 mid = (mid + Math.imul(al8, bh4)) | 0; 2439 mid = (mid + Math.imul(ah8, bl4)) | 0; 2440 hi = (hi + Math.imul(ah8, bh4)) | 0; 2441 lo = (lo + Math.imul(al7, bl5)) | 0; 2442 mid = (mid + Math.imul(al7, bh5)) | 0; 2443 mid = (mid + Math.imul(ah7, bl5)) | 0; 2444 hi = (hi + Math.imul(ah7, bh5)) | 0; 2445 lo = (lo + Math.imul(al6, bl6)) | 0; 2446 mid = (mid + Math.imul(al6, bh6)) | 0; 2447 mid = (mid + Math.imul(ah6, bl6)) | 0; 2448 hi = (hi + Math.imul(ah6, bh6)) | 0; 2449 lo = (lo + Math.imul(al5, bl7)) | 0; 2450 mid = (mid + Math.imul(al5, bh7)) | 0; 2451 mid = (mid + Math.imul(ah5, bl7)) | 0; 2452 hi = (hi + Math.imul(ah5, bh7)) | 0; 2453 lo = (lo + Math.imul(al4, bl8)) | 0; 2454 mid = (mid + Math.imul(al4, bh8)) | 0; 2455 mid = (mid + Math.imul(ah4, bl8)) | 0; 2456 hi = (hi + Math.imul(ah4, bh8)) | 0; 2457 lo = (lo + Math.imul(al3, bl9)) | 0; 2458 mid = (mid + Math.imul(al3, bh9)) | 0; 2459 mid = (mid + Math.imul(ah3, bl9)) | 0; 2460 hi = (hi + Math.imul(ah3, bh9)) | 0; 2461 var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2462 c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0; 2463 w12 &= 0x3ffffff; 2464 /* k = 13 */ 2465 lo = Math.imul(al9, bl4); 2466 mid = Math.imul(al9, bh4); 2467 mid = (mid + Math.imul(ah9, bl4)) | 0; 2468 hi = Math.imul(ah9, bh4); 2469 lo = (lo + Math.imul(al8, bl5)) | 0; 2470 mid = (mid + Math.imul(al8, bh5)) | 0; 2471 mid = (mid + Math.imul(ah8, bl5)) | 0; 2472 hi = (hi + Math.imul(ah8, bh5)) | 0; 2473 lo = (lo + Math.imul(al7, bl6)) | 0; 2474 mid = (mid + Math.imul(al7, bh6)) | 0; 2475 mid = (mid + Math.imul(ah7, bl6)) | 0; 2476 hi = (hi + Math.imul(ah7, bh6)) | 0; 2477 lo = (lo + Math.imul(al6, bl7)) | 0; 2478 mid = (mid + Math.imul(al6, bh7)) | 0; 2479 mid = (mid + Math.imul(ah6, bl7)) | 0; 2480 hi = (hi + Math.imul(ah6, bh7)) | 0; 2481 lo = (lo + Math.imul(al5, bl8)) | 0; 2482 mid = (mid + Math.imul(al5, bh8)) | 0; 2483 mid = (mid + Math.imul(ah5, bl8)) | 0; 2484 hi = (hi + Math.imul(ah5, bh8)) | 0; 2485 lo = (lo + Math.imul(al4, bl9)) | 0; 2486 mid = (mid + Math.imul(al4, bh9)) | 0; 2487 mid = (mid + Math.imul(ah4, bl9)) | 0; 2488 hi = (hi + Math.imul(ah4, bh9)) | 0; 2489 var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2490 c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0; 2491 w13 &= 0x3ffffff; 2492 /* k = 14 */ 2493 lo = Math.imul(al9, bl5); 2494 mid = Math.imul(al9, bh5); 2495 mid = (mid + Math.imul(ah9, bl5)) | 0; 2496 hi = Math.imul(ah9, bh5); 2497 lo = (lo + Math.imul(al8, bl6)) | 0; 2498 mid = (mid + Math.imul(al8, bh6)) | 0; 2499 mid = (mid + Math.imul(ah8, bl6)) | 0; 2500 hi = (hi + Math.imul(ah8, bh6)) | 0; 2501 lo = (lo + Math.imul(al7, bl7)) | 0; 2502 mid = (mid + Math.imul(al7, bh7)) | 0; 2503 mid = (mid + Math.imul(ah7, bl7)) | 0; 2504 hi = (hi + Math.imul(ah7, bh7)) | 0; 2505 lo = (lo + Math.imul(al6, bl8)) | 0; 2506 mid = (mid + Math.imul(al6, bh8)) | 0; 2507 mid = (mid + Math.imul(ah6, bl8)) | 0; 2508 hi = (hi + Math.imul(ah6, bh8)) | 0; 2509 lo = (lo + Math.imul(al5, bl9)) | 0; 2510 mid = (mid + Math.imul(al5, bh9)) | 0; 2511 mid = (mid + Math.imul(ah5, bl9)) | 0; 2512 hi = (hi + Math.imul(ah5, bh9)) | 0; 2513 var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2514 c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0; 2515 w14 &= 0x3ffffff; 2516 /* k = 15 */ 2517 lo = Math.imul(al9, bl6); 2518 mid = Math.imul(al9, bh6); 2519 mid = (mid + Math.imul(ah9, bl6)) | 0; 2520 hi = Math.imul(ah9, bh6); 2521 lo = (lo + Math.imul(al8, bl7)) | 0; 2522 mid = (mid + Math.imul(al8, bh7)) | 0; 2523 mid = (mid + Math.imul(ah8, bl7)) | 0; 2524 hi = (hi + Math.imul(ah8, bh7)) | 0; 2525 lo = (lo + Math.imul(al7, bl8)) | 0; 2526 mid = (mid + Math.imul(al7, bh8)) | 0; 2527 mid = (mid + Math.imul(ah7, bl8)) | 0; 2528 hi = (hi + Math.imul(ah7, bh8)) | 0; 2529 lo = (lo + Math.imul(al6, bl9)) | 0; 2530 mid = (mid + Math.imul(al6, bh9)) | 0; 2531 mid = (mid + Math.imul(ah6, bl9)) | 0; 2532 hi = (hi + Math.imul(ah6, bh9)) | 0; 2533 var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2534 c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0; 2535 w15 &= 0x3ffffff; 2536 /* k = 16 */ 2537 lo = Math.imul(al9, bl7); 2538 mid = Math.imul(al9, bh7); 2539 mid = (mid + Math.imul(ah9, bl7)) | 0; 2540 hi = Math.imul(ah9, bh7); 2541 lo = (lo + Math.imul(al8, bl8)) | 0; 2542 mid = (mid + Math.imul(al8, bh8)) | 0; 2543 mid = (mid + Math.imul(ah8, bl8)) | 0; 2544 hi = (hi + Math.imul(ah8, bh8)) | 0; 2545 lo = (lo + Math.imul(al7, bl9)) | 0; 2546 mid = (mid + Math.imul(al7, bh9)) | 0; 2547 mid = (mid + Math.imul(ah7, bl9)) | 0; 2548 hi = (hi + Math.imul(ah7, bh9)) | 0; 2549 var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2550 c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0; 2551 w16 &= 0x3ffffff; 2552 /* k = 17 */ 2553 lo = Math.imul(al9, bl8); 2554 mid = Math.imul(al9, bh8); 2555 mid = (mid + Math.imul(ah9, bl8)) | 0; 2556 hi = Math.imul(ah9, bh8); 2557 lo = (lo + Math.imul(al8, bl9)) | 0; 2558 mid = (mid + Math.imul(al8, bh9)) | 0; 2559 mid = (mid + Math.imul(ah8, bl9)) | 0; 2560 hi = (hi + Math.imul(ah8, bh9)) | 0; 2561 var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2562 c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0; 2563 w17 &= 0x3ffffff; 2564 /* k = 18 */ 2565 lo = Math.imul(al9, bl9); 2566 mid = Math.imul(al9, bh9); 2567 mid = (mid + Math.imul(ah9, bl9)) | 0; 2568 hi = Math.imul(ah9, bh9); 2569 var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0; 2570 c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0; 2571 w18 &= 0x3ffffff; 2572 o[0] = w0; 2573 o[1] = w1; 2574 o[2] = w2; 2575 o[3] = w3; 2576 o[4] = w4; 2577 o[5] = w5; 2578 o[6] = w6; 2579 o[7] = w7; 2580 o[8] = w8; 2581 o[9] = w9; 2582 o[10] = w10; 2583 o[11] = w11; 2584 o[12] = w12; 2585 o[13] = w13; 2586 o[14] = w14; 2587 o[15] = w15; 2588 o[16] = w16; 2589 o[17] = w17; 2590 o[18] = w18; 2591 if (c !== 0) { 2592 o[19] = c; 2593 out.length++; 2594 } 2595 return out; 2596 }; 2597 2598 // Polyfill comb 2599 if (!Math.imul) { 2600 comb10MulTo = smallMulTo; 2601 } 2602 2603 function bigMulTo (self, num, out) { 2604 out.negative = num.negative ^ self.negative; 2605 out.length = self.length + num.length; 2606 2607 var carry = 0; 2608 var hncarry = 0; 2609 for (var k = 0; k < out.length - 1; k++) { 2610 // Sum all words with the same `i + j = k` and accumulate `ncarry`, 2611 // note that ncarry could be >= 0x3ffffff 2612 var ncarry = hncarry; 2613 hncarry = 0; 2614 var rword = carry & 0x3ffffff; 2615 var maxJ = Math.min(k, num.length - 1); 2616 for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { 2617 var i = k - j; 2618 var a = self.words[i] | 0; 2619 var b = num.words[j] | 0; 2620 var r = a * b; 2621 2622 var lo = r & 0x3ffffff; 2623 ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0; 2624 lo = (lo + rword) | 0; 2625 rword = lo & 0x3ffffff; 2626 ncarry = (ncarry + (lo >>> 26)) | 0; 2627 2628 hncarry += ncarry >>> 26; 2629 ncarry &= 0x3ffffff; 2630 } 2631 out.words[k] = rword; 2632 carry = ncarry; 2633 ncarry = hncarry; 2634 } 2635 if (carry !== 0) { 2636 out.words[k] = carry; 2637 } else { 2638 out.length--; 2639 } 2640 2641 return out.strip(); 2642 } 2643 2644 function jumboMulTo (self, num, out) { 2645 var fftm = new FFTM(); 2646 return fftm.mulp(self, num, out); 2647 } 2648 2649 BN.prototype.mulTo = function mulTo (num, out) { 2650 var res; 2651 var len = this.length + num.length; 2652 if (this.length === 10 && num.length === 10) { 2653 res = comb10MulTo(this, num, out); 2654 } else if (len < 63) { 2655 res = smallMulTo(this, num, out); 2656 } else if (len < 1024) { 2657 res = bigMulTo(this, num, out); 2658 } else { 2659 res = jumboMulTo(this, num, out); 2660 } 2661 2662 return res; 2663 }; 2664 2665 // Cooley-Tukey algorithm for FFT 2666 // slightly revisited to rely on looping instead of recursion 2667 2668 function FFTM (x, y) { 2669 this.x = x; 2670 this.y = y; 2671 } 2672 2673 FFTM.prototype.makeRBT = function makeRBT (N) { 2674 var t = new Array(N); 2675 var l = BN.prototype._countBits(N) - 1; 2676 for (var i = 0; i < N; i++) { 2677 t[i] = this.revBin(i, l, N); 2678 } 2679 2680 return t; 2681 }; 2682 2683 // Returns binary-reversed representation of `x` 2684 FFTM.prototype.revBin = function revBin (x, l, N) { 2685 if (x === 0 || x === N - 1) return x; 2686 2687 var rb = 0; 2688 for (var i = 0; i < l; i++) { 2689 rb |= (x & 1) << (l - i - 1); 2690 x >>= 1; 2691 } 2692 2693 return rb; 2694 }; 2695 2696 // Performs "tweedling" phase, therefore 'emulating' 2697 // behaviour of the recursive algorithm 2698 FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) { 2699 for (var i = 0; i < N; i++) { 2700 rtws[i] = rws[rbt[i]]; 2701 itws[i] = iws[rbt[i]]; 2702 } 2703 }; 2704 2705 FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) { 2706 this.permute(rbt, rws, iws, rtws, itws, N); 2707 2708 for (var s = 1; s < N; s <<= 1) { 2709 var l = s << 1; 2710 2711 var rtwdf = Math.cos(2 * Math.PI / l); 2712 var itwdf = Math.sin(2 * Math.PI / l); 2713 2714 for (var p = 0; p < N; p += l) { 2715 var rtwdf_ = rtwdf; 2716 var itwdf_ = itwdf; 2717 2718 for (var j = 0; j < s; j++) { 2719 var re = rtws[p + j]; 2720 var ie = itws[p + j]; 2721 2722 var ro = rtws[p + j + s]; 2723 var io = itws[p + j + s]; 2724 2725 var rx = rtwdf_ * ro - itwdf_ * io; 2726 2727 io = rtwdf_ * io + itwdf_ * ro; 2728 ro = rx; 2729 2730 rtws[p + j] = re + ro; 2731 itws[p + j] = ie + io; 2732 2733 rtws[p + j + s] = re - ro; 2734 itws[p + j + s] = ie - io; 2735 2736 /* jshint maxdepth : false */ 2737 if (j !== l) { 2738 rx = rtwdf * rtwdf_ - itwdf * itwdf_; 2739 2740 itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; 2741 rtwdf_ = rx; 2742 } 2743 } 2744 } 2745 } 2746 }; 2747 2748 FFTM.prototype.guessLen13b = function guessLen13b (n, m) { 2749 var N = Math.max(m, n) | 1; 2750 var odd = N & 1; 2751 var i = 0; 2752 for (N = N / 2 | 0; N; N = N >>> 1) { 2753 i++; 2754 } 2755 2756 return 1 << i + 1 + odd; 2757 }; 2758 2759 FFTM.prototype.conjugate = function conjugate (rws, iws, N) { 2760 if (N <= 1) return; 2761 2762 for (var i = 0; i < N / 2; i++) { 2763 var t = rws[i]; 2764 2765 rws[i] = rws[N - i - 1]; 2766 rws[N - i - 1] = t; 2767 2768 t = iws[i]; 2769 2770 iws[i] = -iws[N - i - 1]; 2771 iws[N - i - 1] = -t; 2772 } 2773 }; 2774 2775 FFTM.prototype.normalize13b = function normalize13b (ws, N) { 2776 var carry = 0; 2777 for (var i = 0; i < N / 2; i++) { 2778 var w = Math.round(ws[2 * i + 1] / N) * 0x2000 + 2779 Math.round(ws[2 * i] / N) + 2780 carry; 2781 2782 ws[i] = w & 0x3ffffff; 2783 2784 if (w < 0x4000000) { 2785 carry = 0; 2786 } else { 2787 carry = w / 0x4000000 | 0; 2788 } 2789 } 2790 2791 return ws; 2792 }; 2793 2794 FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) { 2795 var carry = 0; 2796 for (var i = 0; i < len; i++) { 2797 carry = carry + (ws[i] | 0); 2798 2799 rws[2 * i] = carry & 0x1fff; carry = carry >>> 13; 2800 rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13; 2801 } 2802 2803 // Pad with zeroes 2804 for (i = 2 * len; i < N; ++i) { 2805 rws[i] = 0; 2806 } 2807 2808 assert(carry === 0); 2809 assert((carry & ~0x1fff) === 0); 2810 }; 2811 2812 FFTM.prototype.stub = function stub (N) { 2813 var ph = new Array(N); 2814 for (var i = 0; i < N; i++) { 2815 ph[i] = 0; 2816 } 2817 2818 return ph; 2819 }; 2820 2821 FFTM.prototype.mulp = function mulp (x, y, out) { 2822 var N = 2 * this.guessLen13b(x.length, y.length); 2823 2824 var rbt = this.makeRBT(N); 2825 2826 var _ = this.stub(N); 2827 2828 var rws = new Array(N); 2829 var rwst = new Array(N); 2830 var iwst = new Array(N); 2831 2832 var nrws = new Array(N); 2833 var nrwst = new Array(N); 2834 var niwst = new Array(N); 2835 2836 var rmws = out.words; 2837 rmws.length = N; 2838 2839 this.convert13b(x.words, x.length, rws, N); 2840 this.convert13b(y.words, y.length, nrws, N); 2841 2842 this.transform(rws, _, rwst, iwst, N, rbt); 2843 this.transform(nrws, _, nrwst, niwst, N, rbt); 2844 2845 for (var i = 0; i < N; i++) { 2846 var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; 2847 iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; 2848 rwst[i] = rx; 2849 } 2850 2851 this.conjugate(rwst, iwst, N); 2852 this.transform(rwst, iwst, rmws, _, N, rbt); 2853 this.conjugate(rmws, _, N); 2854 this.normalize13b(rmws, N); 2855 2856 out.negative = x.negative ^ y.negative; 2857 out.length = x.length + y.length; 2858 return out.strip(); 2859 }; 2860 2861 // Multiply `this` by `num` 2862 BN.prototype.mul = function mul (num) { 2863 var out = new BN(null); 2864 out.words = new Array(this.length + num.length); 2865 return this.mulTo(num, out); 2866 }; 2867 2868 // Multiply employing FFT 2869 BN.prototype.mulf = function mulf (num) { 2870 var out = new BN(null); 2871 out.words = new Array(this.length + num.length); 2872 return jumboMulTo(this, num, out); 2873 }; 2874 2875 // In-place Multiplication 2876 BN.prototype.imul = function imul (num) { 2877 return this.clone().mulTo(num, this); 2878 }; 2879 2880 BN.prototype.imuln = function imuln (num) { 2881 assert(typeof num === 'number'); 2882 assert(num < 0x4000000); 2883 2884 // Carry 2885 var carry = 0; 2886 for (var i = 0; i < this.length; i++) { 2887 var w = (this.words[i] | 0) * num; 2888 var lo = (w & 0x3ffffff) + (carry & 0x3ffffff); 2889 carry >>= 26; 2890 carry += (w / 0x4000000) | 0; 2891 // NOTE: lo is 27bit maximum 2892 carry += lo >>> 26; 2893 this.words[i] = lo & 0x3ffffff; 2894 } 2895 2896 if (carry !== 0) { 2897 this.words[i] = carry; 2898 this.length++; 2899 } 2900 2901 return this; 2902 }; 2903 2904 BN.prototype.muln = function muln (num) { 2905 return this.clone().imuln(num); 2906 }; 2907 2908 // `this` * `this` 2909 BN.prototype.sqr = function sqr () { 2910 return this.mul(this); 2911 }; 2912 2913 // `this` * `this` in-place 2914 BN.prototype.isqr = function isqr () { 2915 return this.imul(this.clone()); 2916 }; 2917 2918 // Math.pow(`this`, `num`) 2919 BN.prototype.pow = function pow (num) { 2920 var w = toBitArray(num); 2921 if (w.length === 0) return new BN(1); 2922 2923 // Skip leading zeroes 2924 var res = this; 2925 for (var i = 0; i < w.length; i++, res = res.sqr()) { 2926 if (w[i] !== 0) break; 2927 } 2928 2929 if (++i < w.length) { 2930 for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { 2931 if (w[i] === 0) continue; 2932 2933 res = res.mul(q); 2934 } 2935 } 2936 2937 return res; 2938 }; 2939 2940 // Shift-left in-place 2941 BN.prototype.iushln = function iushln (bits) { 2942 assert(typeof bits === 'number' && bits >= 0); 2943 var r = bits % 26; 2944 var s = (bits - r) / 26; 2945 var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r); 2946 var i; 2947 2948 if (r !== 0) { 2949 var carry = 0; 2950 2951 for (i = 0; i < this.length; i++) { 2952 var newCarry = this.words[i] & carryMask; 2953 var c = ((this.words[i] | 0) - newCarry) << r; 2954 this.words[i] = c | carry; 2955 carry = newCarry >>> (26 - r); 2956 } 2957 2958 if (carry) { 2959 this.words[i] = carry; 2960 this.length++; 2961 } 2962 } 2963 2964 if (s !== 0) { 2965 for (i = this.length - 1; i >= 0; i--) { 2966 this.words[i + s] = this.words[i]; 2967 } 2968 2969 for (i = 0; i < s; i++) { 2970 this.words[i] = 0; 2971 } 2972 2973 this.length += s; 2974 } 2975 2976 return this.strip(); 2977 }; 2978 2979 BN.prototype.ishln = function ishln (bits) { 2980 // TODO(indutny): implement me 2981 assert(this.negative === 0); 2982 return this.iushln(bits); 2983 }; 2984 2985 // Shift-right in-place 2986 // NOTE: `hint` is a lowest bit before trailing zeroes 2987 // NOTE: if `extended` is present - it will be filled with destroyed bits 2988 BN.prototype.iushrn = function iushrn (bits, hint, extended) { 2989 assert(typeof bits === 'number' && bits >= 0); 2990 var h; 2991 if (hint) { 2992 h = (hint - (hint % 26)) / 26; 2993 } else { 2994 h = 0; 2995 } 2996 2997 var r = bits % 26; 2998 var s = Math.min((bits - r) / 26, this.length); 2999 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r); 3000 var maskedWords = extended; 3001 3002 h -= s; 3003 h = Math.max(0, h); 3004 3005 // Extended mode, copy masked part 3006 if (maskedWords) { 3007 for (var i = 0; i < s; i++) { 3008 maskedWords.words[i] = this.words[i]; 3009 } 3010 maskedWords.length = s; 3011 } 3012 3013 if (s === 0) { 3014 // No-op, we should not move anything at all 3015 } else if (this.length > s) { 3016 this.length -= s; 3017 for (i = 0; i < this.length; i++) { 3018 this.words[i] = this.words[i + s]; 3019 } 3020 } else { 3021 this.words[0] = 0; 3022 this.length = 1; 3023 } 3024 3025 var carry = 0; 3026 for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { 3027 var word = this.words[i] | 0; 3028 this.words[i] = (carry << (26 - r)) | (word >>> r); 3029 carry = word & mask; 3030 } 3031 3032 // Push carried bits as a mask 3033 if (maskedWords && carry !== 0) { 3034 maskedWords.words[maskedWords.length++] = carry; 3035 } 3036 3037 if (this.length === 0) { 3038 this.words[0] = 0; 3039 this.length = 1; 3040 } 3041 3042 return this.strip(); 3043 }; 3044 3045 BN.prototype.ishrn = function ishrn (bits, hint, extended) { 3046 // TODO(indutny): implement me 3047 assert(this.negative === 0); 3048 return this.iushrn(bits, hint, extended); 3049 }; 3050 3051 // Shift-left 3052 BN.prototype.shln = function shln (bits) { 3053 return this.clone().ishln(bits); 3054 }; 3055 3056 BN.prototype.ushln = function ushln (bits) { 3057 return this.clone().iushln(bits); 3058 }; 3059 3060 // Shift-right 3061 BN.prototype.shrn = function shrn (bits) { 3062 return this.clone().ishrn(bits); 3063 }; 3064 3065 BN.prototype.ushrn = function ushrn (bits) { 3066 return this.clone().iushrn(bits); 3067 }; 3068 3069 // Test if n bit is set 3070 BN.prototype.testn = function testn (bit) { 3071 assert(typeof bit === 'number' && bit >= 0); 3072 var r = bit % 26; 3073 var s = (bit - r) / 26; 3074 var q = 1 << r; 3075 3076 // Fast case: bit is much higher than all existing words 3077 if (this.length <= s) return false; 3078 3079 // Check bit and return 3080 var w = this.words[s]; 3081 3082 return !!(w & q); 3083 }; 3084 3085 // Return only lowers bits of number (in-place) 3086 BN.prototype.imaskn = function imaskn (bits) { 3087 assert(typeof bits === 'number' && bits >= 0); 3088 var r = bits % 26; 3089 var s = (bits - r) / 26; 3090 3091 assert(this.negative === 0, 'imaskn works only with positive numbers'); 3092 3093 if (this.length <= s) { 3094 return this; 3095 } 3096 3097 if (r !== 0) { 3098 s++; 3099 } 3100 this.length = Math.min(s, this.length); 3101 3102 if (r !== 0) { 3103 var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r); 3104 this.words[this.length - 1] &= mask; 3105 } 3106 3107 return this.strip(); 3108 }; 3109 3110 // Return only lowers bits of number 3111 BN.prototype.maskn = function maskn (bits) { 3112 return this.clone().imaskn(bits); 3113 }; 3114 3115 // Add plain number `num` to `this` 3116 BN.prototype.iaddn = function iaddn (num) { 3117 assert(typeof num === 'number'); 3118 assert(num < 0x4000000); 3119 if (num < 0) return this.isubn(-num); 3120 3121 // Possible sign change 3122 if (this.negative !== 0) { 3123 if (this.length === 1 && (this.words[0] | 0) < num) { 3124 this.words[0] = num - (this.words[0] | 0); 3125 this.negative = 0; 3126 return this; 3127 } 3128 3129 this.negative = 0; 3130 this.isubn(num); 3131 this.negative = 1; 3132 return this; 3133 } 3134 3135 // Add without checks 3136 return this._iaddn(num); 3137 }; 3138 3139 BN.prototype._iaddn = function _iaddn (num) { 3140 this.words[0] += num; 3141 3142 // Carry 3143 for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) { 3144 this.words[i] -= 0x4000000; 3145 if (i === this.length - 1) { 3146 this.words[i + 1] = 1; 3147 } else { 3148 this.words[i + 1]++; 3149 } 3150 } 3151 this.length = Math.max(this.length, i + 1); 3152 3153 return this; 3154 }; 3155 3156 // Subtract plain number `num` from `this` 3157 BN.prototype.isubn = function isubn (num) { 3158 assert(typeof num === 'number'); 3159 assert(num < 0x4000000); 3160 if (num < 0) return this.iaddn(-num); 3161 3162 if (this.negative !== 0) { 3163 this.negative = 0; 3164 this.iaddn(num); 3165 this.negative = 1; 3166 return this; 3167 } 3168 3169 this.words[0] -= num; 3170 3171 if (this.length === 1 && this.words[0] < 0) { 3172 this.words[0] = -this.words[0]; 3173 this.negative = 1; 3174 } else { 3175 // Carry 3176 for (var i = 0; i < this.length && this.words[i] < 0; i++) { 3177 this.words[i] += 0x4000000; 3178 this.words[i + 1] -= 1; 3179 } 3180 } 3181 3182 return this.strip(); 3183 }; 3184 3185 BN.prototype.addn = function addn (num) { 3186 return this.clone().iaddn(num); 3187 }; 3188 3189 BN.prototype.subn = function subn (num) { 3190 return this.clone().isubn(num); 3191 }; 3192 3193 BN.prototype.iabs = function iabs () { 3194 this.negative = 0; 3195 3196 return this; 3197 }; 3198 3199 BN.prototype.abs = function abs () { 3200 return this.clone().iabs(); 3201 }; 3202 3203 BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) { 3204 var len = num.length + shift; 3205 var i; 3206 3207 this._expand(len); 3208 3209 var w; 3210 var carry = 0; 3211 for (i = 0; i < num.length; i++) { 3212 w = (this.words[i + shift] | 0) + carry; 3213 var right = (num.words[i] | 0) * mul; 3214 w -= right & 0x3ffffff; 3215 carry = (w >> 26) - ((right / 0x4000000) | 0); 3216 this.words[i + shift] = w & 0x3ffffff; 3217 } 3218 for (; i < this.length - shift; i++) { 3219 w = (this.words[i + shift] | 0) + carry; 3220 carry = w >> 26; 3221 this.words[i + shift] = w & 0x3ffffff; 3222 } 3223 3224 if (carry === 0) return this.strip(); 3225 3226 // Subtraction overflow 3227 assert(carry === -1); 3228 carry = 0; 3229 for (i = 0; i < this.length; i++) { 3230 w = -(this.words[i] | 0) + carry; 3231 carry = w >> 26; 3232 this.words[i] = w & 0x3ffffff; 3233 } 3234 this.negative = 1; 3235 3236 return this.strip(); 3237 }; 3238 3239 BN.prototype._wordDiv = function _wordDiv (num, mode) { 3240 var shift = this.length - num.length; 3241 3242 var a = this.clone(); 3243 var b = num; 3244 3245 // Normalize 3246 var bhi = b.words[b.length - 1] | 0; 3247 var bhiBits = this._countBits(bhi); 3248 shift = 26 - bhiBits; 3249 if (shift !== 0) { 3250 b = b.ushln(shift); 3251 a.iushln(shift); 3252 bhi = b.words[b.length - 1] | 0; 3253 } 3254 3255 // Initialize quotient 3256 var m = a.length - b.length; 3257 var q; 3258 3259 if (mode !== 'mod') { 3260 q = new BN(null); 3261 q.length = m + 1; 3262 q.words = new Array(q.length); 3263 for (var i = 0; i < q.length; i++) { 3264 q.words[i] = 0; 3265 } 3266 } 3267 3268 var diff = a.clone()._ishlnsubmul(b, 1, m); 3269 if (diff.negative === 0) { 3270 a = diff; 3271 if (q) { 3272 q.words[m] = 1; 3273 } 3274 } 3275 3276 for (var j = m - 1; j >= 0; j--) { 3277 var qj = (a.words[b.length + j] | 0) * 0x4000000 + 3278 (a.words[b.length + j - 1] | 0); 3279 3280 // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max 3281 // (0x7ffffff) 3282 qj = Math.min((qj / bhi) | 0, 0x3ffffff); 3283 3284 a._ishlnsubmul(b, qj, j); 3285 while (a.negative !== 0) { 3286 qj--; 3287 a.negative = 0; 3288 a._ishlnsubmul(b, 1, j); 3289 if (!a.isZero()) { 3290 a.negative ^= 1; 3291 } 3292 } 3293 if (q) { 3294 q.words[j] = qj; 3295 } 3296 } 3297 if (q) { 3298 q.strip(); 3299 } 3300 a.strip(); 3301 3302 // Denormalize 3303 if (mode !== 'div' && shift !== 0) { 3304 a.iushrn(shift); 3305 } 3306 3307 return { 3308 div: q || null, 3309 mod: a 3310 }; 3311 }; 3312 3313 // NOTE: 1) `mode` can be set to `mod` to request mod only, 3314 // to `div` to request div only, or be absent to 3315 // request both div & mod 3316 // 2) `positive` is true if unsigned mod is requested 3317 BN.prototype.divmod = function divmod (num, mode, positive) { 3318 assert(!num.isZero()); 3319 3320 if (this.isZero()) { 3321 return { 3322 div: new BN(0), 3323 mod: new BN(0) 3324 }; 3325 } 3326 3327 var div, mod, res; 3328 if (this.negative !== 0 && num.negative === 0) { 3329 res = this.neg().divmod(num, mode); 3330 3331 if (mode !== 'mod') { 3332 div = res.div.neg(); 3333 } 3334 3335 if (mode !== 'div') { 3336 mod = res.mod.neg(); 3337 if (positive && mod.negative !== 0) { 3338 mod.iadd(num); 3339 } 3340 } 3341 3342 return { 3343 div: div, 3344 mod: mod 3345 }; 3346 } 3347 3348 if (this.negative === 0 && num.negative !== 0) { 3349 res = this.divmod(num.neg(), mode); 3350 3351 if (mode !== 'mod') { 3352 div = res.div.neg(); 3353 } 3354 3355 return { 3356 div: div, 3357 mod: res.mod 3358 }; 3359 } 3360 3361 if ((this.negative & num.negative) !== 0) { 3362 res = this.neg().divmod(num.neg(), mode); 3363 3364 if (mode !== 'div') { 3365 mod = res.mod.neg(); 3366 if (positive && mod.negative !== 0) { 3367 mod.isub(num); 3368 } 3369 } 3370 3371 return { 3372 div: res.div, 3373 mod: mod 3374 }; 3375 } 3376 3377 // Both numbers are positive at this point 3378 3379 // Strip both numbers to approximate shift value 3380 if (num.length > this.length || this.cmp(num) < 0) { 3381 return { 3382 div: new BN(0), 3383 mod: this 3384 }; 3385 } 3386 3387 // Very short reduction 3388 if (num.length === 1) { 3389 if (mode === 'div') { 3390 return { 3391 div: this.divn(num.words[0]), 3392 mod: null 3393 }; 3394 } 3395 3396 if (mode === 'mod') { 3397 return { 3398 div: null, 3399 mod: new BN(this.modn(num.words[0])) 3400 }; 3401 } 3402 3403 return { 3404 div: this.divn(num.words[0]), 3405 mod: new BN(this.modn(num.words[0])) 3406 }; 3407 } 3408 3409 return this._wordDiv(num, mode); 3410 }; 3411 3412 // Find `this` / `num` 3413 BN.prototype.div = function div (num) { 3414 return this.divmod(num, 'div', false).div; 3415 }; 3416 3417 // Find `this` % `num` 3418 BN.prototype.mod = function mod (num) { 3419 return this.divmod(num, 'mod', false).mod; 3420 }; 3421 3422 BN.prototype.umod = function umod (num) { 3423 return this.divmod(num, 'mod', true).mod; 3424 }; 3425 3426 // Find Round(`this` / `num`) 3427 BN.prototype.divRound = function divRound (num) { 3428 var dm = this.divmod(num); 3429 3430 // Fast case - exact division 3431 if (dm.mod.isZero()) return dm.div; 3432 3433 var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; 3434 3435 var half = num.ushrn(1); 3436 var r2 = num.andln(1); 3437 var cmp = mod.cmp(half); 3438 3439 // Round down 3440 if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; 3441 3442 // Round up 3443 return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); 3444 }; 3445 3446 BN.prototype.modn = function modn (num) { 3447 assert(num <= 0x3ffffff); 3448 var p = (1 << 26) % num; 3449 3450 var acc = 0; 3451 for (var i = this.length - 1; i >= 0; i--) { 3452 acc = (p * acc + (this.words[i] | 0)) % num; 3453 } 3454 3455 return acc; 3456 }; 3457 3458 // In-place division by number 3459 BN.prototype.idivn = function idivn (num) { 3460 assert(num <= 0x3ffffff); 3461 3462 var carry = 0; 3463 for (var i = this.length - 1; i >= 0; i--) { 3464 var w = (this.words[i] | 0) + carry * 0x4000000; 3465 this.words[i] = (w / num) | 0; 3466 carry = w % num; 3467 } 3468 3469 return this.strip(); 3470 }; 3471 3472 BN.prototype.divn = function divn (num) { 3473 return this.clone().idivn(num); 3474 }; 3475 3476 BN.prototype.egcd = function egcd (p) { 3477 assert(p.negative === 0); 3478 assert(!p.isZero()); 3479 3480 var x = this; 3481 var y = p.clone(); 3482 3483 if (x.negative !== 0) { 3484 x = x.umod(p); 3485 } else { 3486 x = x.clone(); 3487 } 3488 3489 // A * x + B * y = x 3490 var A = new BN(1); 3491 var B = new BN(0); 3492 3493 // C * x + D * y = y 3494 var C = new BN(0); 3495 var D = new BN(1); 3496 3497 var g = 0; 3498 3499 while (x.isEven() && y.isEven()) { 3500 x.iushrn(1); 3501 y.iushrn(1); 3502 ++g; 3503 } 3504 3505 var yp = y.clone(); 3506 var xp = x.clone(); 3507 3508 while (!x.isZero()) { 3509 for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); 3510 if (i > 0) { 3511 x.iushrn(i); 3512 while (i-- > 0) { 3513 if (A.isOdd() || B.isOdd()) { 3514 A.iadd(yp); 3515 B.isub(xp); 3516 } 3517 3518 A.iushrn(1); 3519 B.iushrn(1); 3520 } 3521 } 3522 3523 for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); 3524 if (j > 0) { 3525 y.iushrn(j); 3526 while (j-- > 0) { 3527 if (C.isOdd() || D.isOdd()) { 3528 C.iadd(yp); 3529 D.isub(xp); 3530 } 3531 3532 C.iushrn(1); 3533 D.iushrn(1); 3534 } 3535 } 3536 3537 if (x.cmp(y) >= 0) { 3538 x.isub(y); 3539 A.isub(C); 3540 B.isub(D); 3541 } else { 3542 y.isub(x); 3543 C.isub(A); 3544 D.isub(B); 3545 } 3546 } 3547 3548 return { 3549 a: C, 3550 b: D, 3551 gcd: y.iushln(g) 3552 }; 3553 }; 3554 3555 // This is reduced incarnation of the binary EEA 3556 // above, designated to invert members of the 3557 // _prime_ fields F(p) at a maximal speed 3558 BN.prototype._invmp = function _invmp (p) { 3559 assert(p.negative === 0); 3560 assert(!p.isZero()); 3561 3562 var a = this; 3563 var b = p.clone(); 3564 3565 if (a.negative !== 0) { 3566 a = a.umod(p); 3567 } else { 3568 a = a.clone(); 3569 } 3570 3571 var x1 = new BN(1); 3572 var x2 = new BN(0); 3573 3574 var delta = b.clone(); 3575 3576 while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { 3577 for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); 3578 if (i > 0) { 3579 a.iushrn(i); 3580 while (i-- > 0) { 3581 if (x1.isOdd()) { 3582 x1.iadd(delta); 3583 } 3584 3585 x1.iushrn(1); 3586 } 3587 } 3588 3589 for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); 3590 if (j > 0) { 3591 b.iushrn(j); 3592 while (j-- > 0) { 3593 if (x2.isOdd()) { 3594 x2.iadd(delta); 3595 } 3596 3597 x2.iushrn(1); 3598 } 3599 } 3600 3601 if (a.cmp(b) >= 0) { 3602 a.isub(b); 3603 x1.isub(x2); 3604 } else { 3605 b.isub(a); 3606 x2.isub(x1); 3607 } 3608 } 3609 3610 var res; 3611 if (a.cmpn(1) === 0) { 3612 res = x1; 3613 } else { 3614 res = x2; 3615 } 3616 3617 if (res.cmpn(0) < 0) { 3618 res.iadd(p); 3619 } 3620 3621 return res; 3622 }; 3623 3624 BN.prototype.gcd = function gcd (num) { 3625 if (this.isZero()) return num.abs(); 3626 if (num.isZero()) return this.abs(); 3627 3628 var a = this.clone(); 3629 var b = num.clone(); 3630 a.negative = 0; 3631 b.negative = 0; 3632 3633 // Remove common factor of two 3634 for (var shift = 0; a.isEven() && b.isEven(); shift++) { 3635 a.iushrn(1); 3636 b.iushrn(1); 3637 } 3638 3639 do { 3640 while (a.isEven()) { 3641 a.iushrn(1); 3642 } 3643 while (b.isEven()) { 3644 b.iushrn(1); 3645 } 3646 3647 var r = a.cmp(b); 3648 if (r < 0) { 3649 // Swap `a` and `b` to make `a` always bigger than `b` 3650 var t = a; 3651 a = b; 3652 b = t; 3653 } else if (r === 0 || b.cmpn(1) === 0) { 3654 break; 3655 } 3656 3657 a.isub(b); 3658 } while (true); 3659 3660 return b.iushln(shift); 3661 }; 3662 3663 // Invert number in the field F(num) 3664 BN.prototype.invm = function invm (num) { 3665 return this.egcd(num).a.umod(num); 3666 }; 3667 3668 BN.prototype.isEven = function isEven () { 3669 return (this.words[0] & 1) === 0; 3670 }; 3671 3672 BN.prototype.isOdd = function isOdd () { 3673 return (this.words[0] & 1) === 1; 3674 }; 3675 3676 // And first word and num 3677 BN.prototype.andln = function andln (num) { 3678 return this.words[0] & num; 3679 }; 3680 3681 // Increment at the bit position in-line 3682 BN.prototype.bincn = function bincn (bit) { 3683 assert(typeof bit === 'number'); 3684 var r = bit % 26; 3685 var s = (bit - r) / 26; 3686 var q = 1 << r; 3687 3688 // Fast case: bit is much higher than all existing words 3689 if (this.length <= s) { 3690 this._expand(s + 1); 3691 this.words[s] |= q; 3692 return this; 3693 } 3694 3695 // Add bit and propagate, if needed 3696 var carry = q; 3697 for (var i = s; carry !== 0 && i < this.length; i++) { 3698 var w = this.words[i] | 0; 3699 w += carry; 3700 carry = w >>> 26; 3701 w &= 0x3ffffff; 3702 this.words[i] = w; 3703 } 3704 if (carry !== 0) { 3705 this.words[i] = carry; 3706 this.length++; 3707 } 3708 return this; 3709 }; 3710 3711 BN.prototype.isZero = function isZero () { 3712 return this.length === 1 && this.words[0] === 0; 3713 }; 3714 3715 BN.prototype.cmpn = function cmpn (num) { 3716 var negative = num < 0; 3717 3718 if (this.negative !== 0 && !negative) return -1; 3719 if (this.negative === 0 && negative) return 1; 3720 3721 this.strip(); 3722 3723 var res; 3724 if (this.length > 1) { 3725 res = 1; 3726 } else { 3727 if (negative) { 3728 num = -num; 3729 } 3730 3731 assert(num <= 0x3ffffff, 'Number is too big'); 3732 3733 var w = this.words[0] | 0; 3734 res = w === num ? 0 : w < num ? -1 : 1; 3735 } 3736 if (this.negative !== 0) return -res | 0; 3737 return res; 3738 }; 3739 3740 // Compare two numbers and return: 3741 // 1 - if `this` > `num` 3742 // 0 - if `this` == `num` 3743 // -1 - if `this` < `num` 3744 BN.prototype.cmp = function cmp (num) { 3745 if (this.negative !== 0 && num.negative === 0) return -1; 3746 if (this.negative === 0 && num.negative !== 0) return 1; 3747 3748 var res = this.ucmp(num); 3749 if (this.negative !== 0) return -res | 0; 3750 return res; 3751 }; 3752 3753 // Unsigned comparison 3754 BN.prototype.ucmp = function ucmp (num) { 3755 // At this point both numbers have the same sign 3756 if (this.length > num.length) return 1; 3757 if (this.length < num.length) return -1; 3758 3759 var res = 0; 3760 for (var i = this.length - 1; i >= 0; i--) { 3761 var a = this.words[i] | 0; 3762 var b = num.words[i] | 0; 3763 3764 if (a === b) continue; 3765 if (a < b) { 3766 res = -1; 3767 } else if (a > b) { 3768 res = 1; 3769 } 3770 break; 3771 } 3772 return res; 3773 }; 3774 3775 BN.prototype.gtn = function gtn (num) { 3776 return this.cmpn(num) === 1; 3777 }; 3778 3779 BN.prototype.gt = function gt (num) { 3780 return this.cmp(num) === 1; 3781 }; 3782 3783 BN.prototype.gten = function gten (num) { 3784 return this.cmpn(num) >= 0; 3785 }; 3786 3787 BN.prototype.gte = function gte (num) { 3788 return this.cmp(num) >= 0; 3789 }; 3790 3791 BN.prototype.ltn = function ltn (num) { 3792 return this.cmpn(num) === -1; 3793 }; 3794 3795 BN.prototype.lt = function lt (num) { 3796 return this.cmp(num) === -1; 3797 }; 3798 3799 BN.prototype.lten = function lten (num) { 3800 return this.cmpn(num) <= 0; 3801 }; 3802 3803 BN.prototype.lte = function lte (num) { 3804 return this.cmp(num) <= 0; 3805 }; 3806 3807 BN.prototype.eqn = function eqn (num) { 3808 return this.cmpn(num) === 0; 3809 }; 3810 3811 BN.prototype.eq = function eq (num) { 3812 return this.cmp(num) === 0; 3813 }; 3814 3815 // 3816 // A reduce context, could be using montgomery or something better, depending 3817 // on the `m` itself. 3818 // 3819 BN.red = function red (num) { 3820 return new Red(num); 3821 }; 3822 3823 BN.prototype.toRed = function toRed (ctx) { 3824 assert(!this.red, 'Already a number in reduction context'); 3825 assert(this.negative === 0, 'red works only with positives'); 3826 return ctx.convertTo(this)._forceRed(ctx); 3827 }; 3828 3829 BN.prototype.fromRed = function fromRed () { 3830 assert(this.red, 'fromRed works only with numbers in reduction context'); 3831 return this.red.convertFrom(this); 3832 }; 3833 3834 BN.prototype._forceRed = function _forceRed (ctx) { 3835 this.red = ctx; 3836 return this; 3837 }; 3838 3839 BN.prototype.forceRed = function forceRed (ctx) { 3840 assert(!this.red, 'Already a number in reduction context'); 3841 return this._forceRed(ctx); 3842 }; 3843 3844 BN.prototype.redAdd = function redAdd (num) { 3845 assert(this.red, 'redAdd works only with red numbers'); 3846 return this.red.add(this, num); 3847 }; 3848 3849 BN.prototype.redIAdd = function redIAdd (num) { 3850 assert(this.red, 'redIAdd works only with red numbers'); 3851 return this.red.iadd(this, num); 3852 }; 3853 3854 BN.prototype.redSub = function redSub (num) { 3855 assert(this.red, 'redSub works only with red numbers'); 3856 return this.red.sub(this, num); 3857 }; 3858 3859 BN.prototype.redISub = function redISub (num) { 3860 assert(this.red, 'redISub works only with red numbers'); 3861 return this.red.isub(this, num); 3862 }; 3863 3864 BN.prototype.redShl = function redShl (num) { 3865 assert(this.red, 'redShl works only with red numbers'); 3866 return this.red.shl(this, num); 3867 }; 3868 3869 BN.prototype.redMul = function redMul (num) { 3870 assert(this.red, 'redMul works only with red numbers'); 3871 this.red._verify2(this, num); 3872 return this.red.mul(this, num); 3873 }; 3874 3875 BN.prototype.redIMul = function redIMul (num) { 3876 assert(this.red, 'redMul works only with red numbers'); 3877 this.red._verify2(this, num); 3878 return this.red.imul(this, num); 3879 }; 3880 3881 BN.prototype.redSqr = function redSqr () { 3882 assert(this.red, 'redSqr works only with red numbers'); 3883 this.red._verify1(this); 3884 return this.red.sqr(this); 3885 }; 3886 3887 BN.prototype.redISqr = function redISqr () { 3888 assert(this.red, 'redISqr works only with red numbers'); 3889 this.red._verify1(this); 3890 return this.red.isqr(this); 3891 }; 3892 3893 // Square root over p 3894 BN.prototype.redSqrt = function redSqrt () { 3895 assert(this.red, 'redSqrt works only with red numbers'); 3896 this.red._verify1(this); 3897 return this.red.sqrt(this); 3898 }; 3899
vendor: 8,763 bytes, lines 3900-4279
3900 BN.prototype.redInvm = function redInvm () { 3901 assert(this.red, 'redInvm works only with red numbers'); 3902 this.red._verify1(this); 3903 return this.red.invm(this); 3904 }; 3905 3906 // Return negative clone of `this` % `red modulo` 3907 BN.prototype.redNeg = function redNeg () { 3908 assert(this.red, 'redNeg works only with red numbers'); 3909 this.red._verify1(this); 3910 return this.red.neg(this); 3911 }; 3912 3913 BN.prototype.redPow = function redPow (num) { 3914 assert(this.red && !num.red, 'redPow(normalNum)'); 3915 this.red._verify1(this); 3916 return this.red.pow(this, num); 3917 }; 3918 3919 // Prime numbers with efficient reduction 3920 var primes = { 3921 k256: null, 3922 p224: null, 3923 p192: null, 3924 p25519: null 3925 }; 3926 3927 // Pseudo-Mersenne prime 3928 function MPrime (name, p) { 3929 // P = 2 ^ N - K 3930 this.name = name; 3931 this.p = new BN(p, 16); 3932 this.n = this.p.bitLength(); 3933 this.k = new BN(1).iushln(this.n).isub(this.p); 3934 3935 this.tmp = this._tmp(); 3936 } 3937 3938 MPrime.prototype._tmp = function _tmp () { 3939 var tmp = new BN(null); 3940 tmp.words = new Array(Math.ceil(this.n / 13)); 3941 return tmp; 3942 }; 3943 3944 MPrime.prototype.ireduce = function ireduce (num) { 3945 // Assumes that `num` is less than `P^2` 3946 // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) 3947 var r = num; 3948 var rlen; 3949 3950 do { 3951 this.split(r, this.tmp); 3952 r = this.imulK(r); 3953 r = r.iadd(this.tmp); 3954 rlen = r.bitLength(); 3955 } while (rlen > this.n); 3956 3957 var cmp = rlen < this.n ? -1 : r.ucmp(this.p); 3958 if (cmp === 0) { 3959 r.words[0] = 0; 3960 r.length = 1; 3961 } else if (cmp > 0) { 3962 r.isub(this.p); 3963 } else { 3964 r.strip(); 3965 } 3966 3967 return r; 3968 }; 3969 3970 MPrime.prototype.split = function split (input, out) { 3971 input.iushrn(this.n, 0, out); 3972 }; 3973 3974 MPrime.prototype.imulK = function imulK (num) { 3975 return num.imul(this.k); 3976 }; 3977 3978 function K256 () { 3979 MPrime.call( 3980 this, 3981 'k256', 3982 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f'); 3983 } 3984 inherits(K256, MPrime); 3985 3986 K256.prototype.split = function split (input, output) { 3987 // 256 = 9 * 26 + 22 3988 var mask = 0x3fffff; 3989 3990 var outLen = Math.min(input.length, 9); 3991 for (var i = 0; i < outLen; i++) { 3992 output.words[i] = input.words[i]; 3993 } 3994 output.length = outLen; 3995 3996 if (input.length <= 9) { 3997 input.words[0] = 0; 3998 input.length = 1; 3999 return; 4000 } 4001 4002 // Shift by 9 limbs 4003 var prev = input.words[9]; 4004 output.words[output.length++] = prev & mask; 4005 4006 for (i = 10; i < input.length; i++) { 4007 var next = input.words[i] | 0; 4008 input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22); 4009 prev = next; 4010 } 4011 prev >>>= 22; 4012 input.words[i - 10] = prev; 4013 if (prev === 0 && input.length > 10) { 4014 input.length -= 10; 4015 } else { 4016 input.length -= 9; 4017 } 4018 }; 4019 4020 K256.prototype.imulK = function imulK (num) { 4021 // K = 0x1000003d1 = [ 0x40, 0x3d1 ] 4022 num.words[num.length] = 0; 4023 num.words[num.length + 1] = 0; 4024 num.length += 2; 4025 4026 // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 4027 var lo = 0; 4028 for (var i = 0; i < num.length; i++) { 4029 var w = num.words[i] | 0; 4030 lo += w * 0x3d1; 4031 num.words[i] = lo & 0x3ffffff; 4032 lo = w * 0x40 + ((lo / 0x4000000) | 0); 4033 } 4034 4035 // Fast length reduction 4036 if (num.words[num.length - 1] === 0) { 4037 num.length--; 4038 if (num.words[num.length - 1] === 0) { 4039 num.length--; 4040 } 4041 } 4042 return num; 4043 }; 4044 4045 function P224 () { 4046 MPrime.call( 4047 this, 4048 'p224', 4049 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001'); 4050 } 4051 inherits(P224, MPrime); 4052 4053 function P192 () { 4054 MPrime.call( 4055 this, 4056 'p192', 4057 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff'); 4058 } 4059 inherits(P192, MPrime); 4060 4061 function P25519 () { 4062 // 2 ^ 255 - 19 4063 MPrime.call( 4064 this, 4065 '25519', 4066 '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed'); 4067 } 4068 inherits(P25519, MPrime); 4069 4070 P25519.prototype.imulK = function imulK (num) { 4071 // K = 0x13 4072 var carry = 0; 4073 for (var i = 0; i < num.length; i++) { 4074 var hi = (num.words[i] | 0) * 0x13 + carry; 4075 var lo = hi & 0x3ffffff; 4076 hi >>>= 26; 4077 4078 num.words[i] = lo; 4079 carry = hi; 4080 } 4081 if (carry !== 0) { 4082 num.words[num.length++] = carry; 4083 } 4084 return num; 4085 }; 4086 4087 // Exported mostly for testing purposes, use plain name instead 4088 BN._prime = function prime (name) { 4089 // Cached version of prime 4090 if (primes[name]) return primes[name]; 4091 4092 var prime; 4093 if (name === 'k256') { 4094 prime = new K256(); 4095 } else if (name === 'p224') { 4096 prime = new P224(); 4097 } else if (name === 'p192') { 4098 prime = new P192(); 4099 } else if (name === 'p25519') { 4100 prime = new P25519(); 4101 } else { 4102 throw new Error('Unknown prime ' + name); 4103 } 4104 primes[name] = prime; 4105 4106 return prime; 4107 }; 4108 4109 // 4110 // Base reduction engine 4111 // 4112 function Red (m) { 4113 if (typeof m === 'string') { 4114 var prime = BN._prime(m); 4115 this.m = prime.p; 4116 this.prime = prime; 4117 } else { 4118 assert(m.gtn(1), 'modulus must be greater than 1'); 4119 this.m = m; 4120 this.prime = null; 4121 } 4122 } 4123 4124 Red.prototype._verify1 = function _verify1 (a) { 4125 assert(a.negative === 0, 'red works only with positives'); 4126 assert(a.red, 'red works only with red numbers'); 4127 }; 4128 4129 Red.prototype._verify2 = function _verify2 (a, b) { 4130 assert((a.negative | b.negative) === 0, 'red works only with positives'); 4131 assert(a.red && a.red === b.red, 4132 'red works only with red numbers'); 4133 }; 4134 4135 Red.prototype.imod = function imod (a) { 4136 if (this.prime) return this.prime.ireduce(a)._forceRed(this); 4137 return a.umod(this.m)._forceRed(this); 4138 }; 4139 4140 Red.prototype.neg = function neg (a) { 4141 if (a.isZero()) { 4142 return a.clone(); 4143 } 4144 4145 return this.m.sub(a)._forceRed(this); 4146 }; 4147 4148 Red.prototype.add = function add (a, b) { 4149 this._verify2(a, b); 4150 4151 var res = a.add(b); 4152 if (res.cmp(this.m) >= 0) { 4153 res.isub(this.m); 4154 } 4155 return res._forceRed(this); 4156 }; 4157 4158 Red.prototype.iadd = function iadd (a, b) { 4159 this._verify2(a, b); 4160 4161 var res = a.iadd(b); 4162 if (res.cmp(this.m) >= 0) { 4163 res.isub(this.m); 4164 } 4165 return res; 4166 }; 4167 4168 Red.prototype.sub = function sub (a, b) { 4169 this._verify2(a, b); 4170 4171 var res = a.sub(b); 4172 if (res.cmpn(0) < 0) { 4173 res.iadd(this.m); 4174 } 4175 return res._forceRed(this); 4176 }; 4177 4178 Red.prototype.isub = function isub (a, b) { 4179 this._verify2(a, b); 4180 4181 var res = a.isub(b); 4182 if (res.cmpn(0) < 0) { 4183 res.iadd(this.m); 4184 } 4185 return res; 4186 }; 4187 4188 Red.prototype.shl = function shl (a, num) { 4189 this._verify1(a); 4190 return this.imod(a.ushln(num)); 4191 }; 4192 4193 Red.prototype.imul = function imul (a, b) { 4194 this._verify2(a, b); 4195 return this.imod(a.imul(b)); 4196 }; 4197 4198 Red.prototype.mul = function mul (a, b) { 4199 this._verify2(a, b); 4200 return this.imod(a.mul(b)); 4201 }; 4202 4203 Red.prototype.isqr = function isqr (a) { 4204 return this.imul(a, a.clone()); 4205 }; 4206 4207 Red.prototype.sqr = function sqr (a) { 4208 return this.mul(a, a); 4209 }; 4210 4211 Red.prototype.sqrt = function sqrt (a) { 4212 if (a.isZero()) return a.clone(); 4213 4214 var mod3 = this.m.andln(3); 4215 assert(mod3 % 2 === 1); 4216 4217 // Fast case 4218 if (mod3 === 3) { 4219 var pow = this.m.add(new BN(1)).iushrn(2); 4220 return this.pow(a, pow); 4221 } 4222 4223 // Tonelli-Shanks algorithm (Totally unoptimized and slow) 4224 // 4225 // Find Q and S, that Q * 2 ^ S = (P - 1) 4226 var q = this.m.subn(1); 4227 var s = 0; 4228 while (!q.isZero() && q.andln(1) === 0) { 4229 s++; 4230 q.iushrn(1); 4231 } 4232 assert(!q.isZero()); 4233 4234 var one = new BN(1).toRed(this); 4235 var nOne = one.redNeg(); 4236 4237 // Find quadratic non-residue 4238 // NOTE: Max is such because of generalized Riemann hypothesis. 4239 var lpow = this.m.subn(1).iushrn(1); 4240 var z = this.m.bitLength(); 4241 z = new BN(2 * z * z).toRed(this); 4242 4243 while (this.pow(z, lpow).cmp(nOne) !== 0) { 4244 z.redIAdd(nOne); 4245 } 4246 4247 var c = this.pow(z, q); 4248 var r = this.pow(a, q.addn(1).iushrn(1)); 4249 var t = this.pow(a, q); 4250 var m = s; 4251 while (t.cmp(one) !== 0) { 4252 var tmp = t; 4253 for (var i = 0; tmp.cmp(one) !== 0; i++) { 4254 tmp = tmp.redSqr(); 4255 } 4256 assert(i < m); 4257 var b = this.pow(c, new BN(1).iushln(m - i - 1)); 4258 4259 r = r.redMul(b); 4260 c = b.redSqr(); 4261 t = t.redMul(c); 4262 m = i; 4263 } 4264 4265 return r; 4266 }; 4267 4268 Red.prototype.invm = function invm (a) { 4269 var inv = a._invmp(this.m); 4270 if (inv.negative !== 0) { 4271 inv.negative = 0; 4272 return this.imod(inv).redNeg(); 4273 } else { 4274 return this.imod(inv); 4275 } 4276 }; 4277 4278 Red.prototype.pow = function pow (a, num) { 4279 if (num.isZero()) return new BN(1)
vendor: 3,714 bytes, lines 4279-4438
4279; 4280 if (num.cmpn(1) === 0) return a.clone(); 4281 4282 var windowSize = 4; 4283 var wnd = new Array(1 << windowSize); 4284 wnd[0] = new BN(1).toRed(this); 4285 wnd[1] = a; 4286 for (var i = 2; i < wnd.length; i++) { 4287 wnd[i] = this.mul(wnd[i - 1], a); 4288 } 4289 4290 var res = wnd[0]; 4291 var current = 0; 4292 var currentLen = 0; 4293 var start = num.bitLength() % 26; 4294 if (start === 0) { 4295 start = 26; 4296 } 4297 4298 for (i = num.length - 1; i >= 0; i--) { 4299 var word = num.words[i]; 4300 for (var j = start - 1; j >= 0; j--) { 4301 var bit = (word >> j) & 1; 4302 if (res !== wnd[0]) { 4303 res = this.sqr(res); 4304 } 4305 4306 if (bit === 0 && current === 0) { 4307 currentLen = 0; 4308 continue; 4309 } 4310 4311 current <<= 1; 4312 current |= bit; 4313 currentLen++; 4314 if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; 4315 4316 res = this.mul(res, wnd[current]); 4317 currentLen = 0; 4318 current = 0; 4319 } 4320 start = 26; 4321 } 4322 4323 return res; 4324 }; 4325 4326 Red.prototype.convertTo = function convertTo (num) { 4327 var r = num.umod(this.m); 4328 4329 return r === num ? r.clone() : r; 4330 }; 4331 4332 Red.prototype.convertFrom = function convertFrom (num) { 4333 var res = num.clone(); 4334 res.red = null; 4335 return res; 4336 }; 4337 4338 // 4339 // Montgomery method engine 4340 // 4341 4342 BN.mont = function mont (num) { 4343 return new Mont(num); 4344 }; 4345 4346 function Mont (m) { 4347 Red.call(this, m); 4348 4349 this.shift = this.m.bitLength(); 4350 if (this.shift % 26 !== 0) { 4351 this.shift += 26 - (this.shift % 26); 4352 } 4353 4354 this.r = new BN(1).iushln(this.shift); 4355 this.r2 = this.imod(this.r.sqr()); 4356 this.rinv = this.r._invmp(this.m); 4357 4358 this.minv = this.rinv.mul(this.r).isubn(1).div(this.m); 4359 this.minv = this.minv.umod(this.r); 4360 this.minv = this.r.sub(this.minv); 4361 } 4362 inherits(Mont, Red); 4363 4364 Mont.prototype.convertTo = function convertTo (num) { 4365 return this.imod(num.ushln(this.shift)); 4366 }; 4367 4368 Mont.prototype.convertFrom = function convertFrom (num) { 4369 var r = this.imod(num.mul(this.rinv)); 4370 r.red = null; 4371 return r; 4372 }; 4373 4374 Mont.prototype.imul = function imul (a, b) { 4375 if (a.isZero() || b.isZero()) { 4376 a.words[0] = 0; 4377 a.length = 1; 4378 return a; 4379 } 4380 4381 var t = a.imul(b); 4382 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m); 4383 var u = t.isub(c).iushrn(this.shift); 4384 var res = u; 4385 4386 if (u.cmp(this.m) >= 0) { 4387 res = u.isub(this.m); 4388 } else if (u.cmpn(0) < 0) { 4389 res = u.iadd(this.m); 4390 } 4391 4392 return res._forceRed(this); 4393 }; 4394 4395 Mont.prototype.mul = function mul (a, b) { 4396 if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this); 4397 4398 var t = a.mul(b); 4399 var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m); 4400 var u = t.isub(c).iushrn(this.shift); 4401 var res = u; 4402 if (u.cmp(this.m) >= 0) { 4403 res = u.isub(this.m); 4404 } else if (u.cmpn(0) < 0) { 4405 res = u.iadd(this.m); 4406 } 4407 4408 return res._forceRed(this); 4409 }; 4410 4411 Mont.prototype.invm = function invm (a) { 4412 // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R 4413 var res = this.imod(a._invmp(this.m).mul(this.r2)); 4414 return res._forceRed(this); 4415 }; 4416})(typeof module === 'undefined' || module, this); 4417 4418},{}],5:[function(require,module,exports){ 4419 4420},{}],6:[function(require,module,exports){ 4421/*! 4422 * The buffer module from node.js, for the browser. 4423 * 4424 * @author Feross Aboukhadijeh <[email protected]> <http://feross.org> 4425 * @license MIT 4426 */ 4427/* eslint-disable no-proto */ 4428 4429'use strict' 4430 4431var base64 = require('base64-js') 4432var ieee754 = require('ieee754') 4433 4434exports.Buffer = Buffer 4435exports.SlowBuffer = SlowBuffer 4436exports.INSPECT_MAX_BYTES = 50 4437 4438var K_MAX_LENGTH = 0x7fffffff
4439exports.kMaxLength = K_MAX_LENGTH 4440 4441/** 4442 * If `Buffer.TYPED_ARRAY_SUPPORT`: 4443 * === true Use Uint8Array implementation (fastest) 4444 * === false Print warning and recommend using `buffer` v4.x which has an Object 4445 * implementation (most compatible, even IE6) 4446 * 4447 * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, 4448 * Opera 11.6+, iOS 4.2+. 4449 * 4450 * We report that the browser does not support typed arrays if the are not subclassable 4451 * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` 4452 * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support 4453 * for __proto__ and has a buggy typed array implementation. 4454 */ 4455Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() 4456 4457if (!Buffer.TYPED_ARRAY_SUPPORT) { 4458 console.error( 4459 'This browser lacks typed array (Uint8Array) support which is required by ' + 4460 '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.') 4461} 4462 4463function typedArraySupport () { 4464 // Can typed array instances can be augmented? 4465 try { 4466 var arr = new Uint8Array(1) 4467 arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} 4468 return arr.foo() === 42 4469 } catch (e) { 4470 return false 4471 } 4472} 4473 4474function createBuffer (length) { 4475 if (length > K_MAX_LENGTH) { 4476 throw new RangeError('Invalid typed array length') 4477 } 4478 // Return an augmented `Uint8Array` instance 4479 var buf = new Uint8Array(length) 4480 buf.__proto__ = Buffer.prototype 4481 return buf 4482} 4483 4484/** 4485 * The Buffer constructor returns instances of `Uint8Array` that have their 4486 * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of 4487 * `Uint8Array`, so the returned instances will have all the node `Buffer` methods 4488 * and the `Uint8Array` methods. Square bracket notation works as expected -- it 4489 * returns a single octet. 4490 * 4491 * The `Uint8Array` prototype remains unmodified. 4492 */ 4493 4494function Buffer (arg, encodingOrOffset, length) { 4495 // Common case. 4496 if (typeof arg === 'number') { 4497 if (typeof encodingOrOffset === 'string') { 4498 throw new Error( 4499 'If encoding is specified then the first argument must be a string' 4500 ) 4501 } 4502 return allocUnsafe(arg) 4503 } 4504 return from(arg, encodingOrOffset, length) 4505} 4506 4507// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 4508if (typeof Symbol !== 'undefined' && Symbol.species && 4509 Buffer[Symbol.species] === Buffer) { 4510 Object.defineProperty(Buffer, Symbol.species, { 4511 value: null, 4512 configurable: true, 4513 enumerable: false, 4514 writable: false 4515 }) 4516} 4517 4518Buffer.poolSize = 8192 // not used by this implementation 4519 4520function from (value, encodingOrOffset, length) { 4521 if (typeof value === 'number') { 4522 throw new TypeError('"value" argument must not be a number') 4523 } 4524 4525 if (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { 4526 return fromArrayBuffer(value, encodingOrOffset, length) 4527 } 4528 4529 if (typeof value === 'string') { 4530 return fromString(value, encodingOrOffset) 4531 } 4532 4533 return fromObject(value) 4534} 4535 4536/** 4537 * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError 4538 * if value is a number. 4539 * Buffer.from(str[, encoding]) 4540 * Buffer.from(array) 4541 * Buffer.from(buffer) 4542 * Buffer.from(arrayBuffer[, byteOffset[, length]]) 4543 **/ 4544Buffer.from = function (value, encodingOrOffset, length) { 4545 return from(value, encodingOrOffset, length) 4546} 4547 4548// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: 4549// https://github.com/feross/buffer/pull/148 4550Buffer.prototype.__proto__ = Uint8Array.prototype 4551Buffer.__proto__ = Uint8Array 4552 4553function assertSize (size) { 4554 if (typeof size !== 'number') { 4555 throw new TypeError('"size" argument must be a number') 4556 } else if (size < 0) { 4557 throw new RangeError('"size" argument must not be negative') 4558 } 4559} 4560 4561function alloc (size, fill, encoding) { 4562 assertSize(size) 4563 if (size <= 0) { 4564 return createBuffer(size) 4565 } 4566 if (fill !== undefined) { 4567 // Only pay attention to encoding if it's a string. This 4568 // prevents accidentally sending in a number that would 4569 // be interpretted as a start offset. 4570 return typeof encoding === 'string' 4571 ? createBuffer(size).fill(fill, encoding) 4572 : createBuffer(size).fill(fill) 4573 } 4574 return createBuffer(size) 4575} 4576 4577/** 4578 * Creates a new filled Buffer instance. 4579 * alloc(size[, fill[, encoding]]) 4580 **/ 4581Buffer.alloc = function (size, fill, encoding) { 4582 return alloc(size, fill, encoding) 4583} 4584 4585function allocUnsafe (size) { 4586 assertSize(size) 4587 return createBuffer(size < 0 ? 0 : checked(size) | 0) 4588} 4589 4590/** 4591 * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. 4592 * */ 4593Buffer.allocUnsafe = function (size) { 4594 return allocUnsafe(size) 4595} 4596/** 4597 * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. 4598 */ 4599Buffer.allocUnsafeSlow = function (size) { 4600 return allocUnsafe(size) 4601} 4602 4603function fromString (string, encoding) { 4604 if (typeof encoding !== 'string' || encoding === '') { 4605 encoding = 'utf8' 4606 } 4607 4608 if (!Buffer.isEncoding(encoding)) { 4609 throw new TypeError('"encoding" must be a valid string encoding') 4610 } 4611 4612 var length = byteLength(string, encoding) | 0 4613 var buf = createBuffer(length) 4614 4615 var actual = buf.write(string, encoding) 4616 4617 if (actual !== length) {
vendor: 4,097 bytes, lines 4618-4788
4618 // Writing a hex string, for example, that contains invalid characters will 4619 // cause everything after the first invalid character to be ignored. (e.g. 4620 // 'abxxcd' will be treated as 'ab') 4621 buf = buf.slice(0, actual) 4622 } 4623 4624 return buf 4625} 4626 4627function fromArrayLike (array) { 4628 var length = array.length < 0 ? 0 : checked(array.length) | 0 4629 var buf = createBuffer(length) 4630 for (var i = 0; i < length; i += 1) { 4631 buf[i] = array[i] & 255 4632 } 4633 return buf 4634} 4635 4636function fromArrayBuffer (array, byteOffset, length) { 4637 array.byteLength // this throws if `array` is not a valid ArrayBuffer 4638 4639 if (byteOffset < 0 || array.byteLength < byteOffset) { 4640 throw new RangeError('\'offset\' is out of bounds') 4641 } 4642 4643 if (array.byteLength < byteOffset + (length || 0)) { 4644 throw new RangeError('\'length\' is out of bounds') 4645 } 4646 4647 var buf 4648 if (byteOffset === undefined && length === undefined) { 4649 buf = new Uint8Array(array) 4650 } else if (length === undefined) { 4651 buf = new Uint8Array(array, byteOffset) 4652 } else { 4653 buf = new Uint8Array(array, byteOffset, length) 4654 } 4655 4656 // Return an augmented `Uint8Array` instance 4657 buf.__proto__ = Buffer.prototype 4658 return buf 4659} 4660 4661function fromObject (obj) { 4662 if (Buffer.isBuffer(obj)) { 4663 var len = checked(obj.length) | 0 4664 var buf = createBuffer(len) 4665 4666 if (buf.length === 0) { 4667 return buf 4668 } 4669 4670 obj.copy(buf, 0, 0, len) 4671 return buf 4672 } 4673 4674 if (obj) { 4675 if ((typeof ArrayBuffer !== 'undefined' && 4676 obj.buffer instanceof ArrayBuffer) || 'length' in obj) { 4677 if (typeof obj.length !== 'number' || isnan(obj.length)) { 4678 return createBuffer(0) 4679 } 4680 return fromArrayLike(obj) 4681 } 4682 4683 if (obj.type === 'Buffer' && Array.isArray(obj.data)) { 4684 return fromArrayLike(obj.data) 4685 } 4686 } 4687 4688 throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') 4689} 4690 4691function checked (length) { 4692 // Note: cannot use `length < K_MAX_LENGTH` here because that fails when 4693 // length is NaN (which is otherwise coerced to zero.) 4694 if (length >= K_MAX_LENGTH) { 4695 throw new RangeError('Attempt to allocate Buffer larger than maximum ' + 4696 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') 4697 } 4698 return length | 0 4699} 4700 4701function SlowBuffer (length) { 4702 if (+length != length) { // eslint-disable-line eqeqeq 4703 length = 0 4704 } 4705 return Buffer.alloc(+length) 4706} 4707 4708Buffer.isBuffer = function isBuffer (b) { 4709 return !!(b != null && b._isBuffer) 4710} 4711 4712Buffer.compare = function compare (a, b) { 4713 if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { 4714 throw new TypeError('Arguments must be Buffers') 4715 } 4716 4717 if (a === b) return 0 4718 4719 var x = a.length 4720 var y = b.length 4721 4722 for (var i = 0, len = Math.min(x, y); i < len; ++i) { 4723 if (a[i] !== b[i]) { 4724 x = a[i] 4725 y = b[i] 4726 break 4727 } 4728 } 4729 4730 if (x < y) return -1 4731 if (y < x) return 1 4732 return 0 4733} 4734 4735Buffer.isEncoding = function isEncoding (encoding) { 4736 switch (String(encoding).toLowerCase()) { 4737 case 'hex': 4738 case 'utf8': 4739 case 'utf-8': 4740 case 'ascii': 4741 case 'latin1': 4742 case 'binary': 4743 case 'base64': 4744 case 'ucs2': 4745 case 'ucs-2': 4746 case 'utf16le': 4747 case 'utf-16le': 4748 return true 4749 default: 4750 return false 4751 } 4752} 4753 4754Buffer.concat = function concat (list, length) { 4755 if (!Array.isArray(list)) { 4756 throw new TypeError('"list" argument must be an Array of Buffers') 4757 } 4758 4759 if (list.length === 0) { 4760 return Buffer.alloc(0) 4761 } 4762 4763 var i 4764 if (length === undefined) { 4765 length = 0 4766 for (i = 0; i < list.length; ++i) { 4767 length += list[i].length 4768 } 4769 } 4770 4771 var buffer = Buffer.allocUnsafe(length) 4772 var pos = 0 4773 for (i = 0; i < list.length; ++i) { 4774 var buf = list[i] 4775 if (!Buffer.isBuffer(buf)) { 4776 throw new TypeError('"list" argument must be an Array of Buffers') 4777 } 4778 buf.copy(buffer, pos) 4779 pos += buf.length 4780 } 4781 return buffer 4782} 4783 4784function byteLength (string, encoding) { 4785 if (Buffer.isBuffer(string)) { 4786 return string.length 4787 } 4788 if (typeof ArrayBuffer !== 'undefined' && typeof ArrayBuffer.isView === 'function' &&
vendor: 3,786 bytes, lines 4789-4947
4789 (ArrayBuffer.isView(string) || string instanceof ArrayBuffer)) { 4790 return string.byteLength 4791 } 4792 if (typeof string !== 'string') { 4793 string = '' + string 4794 } 4795 4796 var len = string.length 4797 if (len === 0) return 0 4798 4799 // Use a for loop to avoid recursion 4800 var loweredCase = false 4801 for (;;) { 4802 switch (encoding) { 4803 case 'ascii': 4804 case 'latin1': 4805 case 'binary': 4806 return len 4807 case 'utf8': 4808 case 'utf-8': 4809 case undefined: 4810 return utf8ToBytes(string).length 4811 case 'ucs2': 4812 case 'ucs-2': 4813 case 'utf16le': 4814 case 'utf-16le': 4815 return len * 2 4816 case 'hex': 4817 return len >>> 1 4818 case 'base64': 4819 return base64ToBytes(string).length 4820 default: 4821 if (loweredCase) return utf8ToBytes(string).length // assume utf8 4822 encoding = ('' + encoding).toLowerCase() 4823 loweredCase = true 4824 } 4825 } 4826} 4827Buffer.byteLength = byteLength 4828 4829function slowToString (encoding, start, end) { 4830 var loweredCase = false 4831 4832 // No need to verify that "this.length <= MAX_UINT32" since it's a read-only 4833 // property of a typed array. 4834 4835 // This behaves neither like String nor Uint8Array in that we set start/end 4836 // to their upper/lower bounds if the value passed is out of range. 4837 // undefined is handled specially as per ECMA-262 6th Edition, 4838 // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. 4839 if (start === undefined || start < 0) { 4840 start = 0 4841 } 4842 // Return early if start > this.length. Done here to prevent potential uint32 4843 // coercion fail below. 4844 if (start > this.length) { 4845 return '' 4846 } 4847 4848 if (end === undefined || end > this.length) { 4849 end = this.length 4850 } 4851 4852 if (end <= 0) { 4853 return '' 4854 } 4855 4856 // Force coersion to uint32. This will also coerce falsey/NaN values to 0. 4857 end >>>= 0 4858 start >>>= 0 4859 4860 if (end <= start) { 4861 return '' 4862 } 4863 4864 if (!encoding) encoding = 'utf8' 4865 4866 while (true) { 4867 switch (encoding) { 4868 case 'hex': 4869 return hexSlice(this, start, end) 4870 4871 case 'utf8': 4872 case 'utf-8': 4873 return utf8Slice(this, start, end) 4874 4875 case 'ascii': 4876 return asciiSlice(this, start, end) 4877 4878 case 'latin1': 4879 case 'binary': 4880 return latin1Slice(this, start, end) 4881 4882 case 'base64': 4883 return base64Slice(this, start, end) 4884 4885 case 'ucs2': 4886 case 'ucs-2': 4887 case 'utf16le': 4888 case 'utf-16le': 4889 return utf16leSlice(this, start, end) 4890 4891 default: 4892 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) 4893 encoding = (encoding + '').toLowerCase() 4894 loweredCase = true 4895 } 4896 } 4897} 4898 4899// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect 4900// Buffer instances. 4901Buffer.prototype._isBuffer = true 4902 4903function swap (b, n, m) { 4904 var i = b[n] 4905 b[n] = b[m] 4906 b[m] = i 4907} 4908 4909Buffer.prototype.swap16 = function swap16 () { 4910 var len = this.length 4911 if (len % 2 !== 0) { 4912 throw new RangeError('Buffer size must be a multiple of 16-bits') 4913 } 4914 for (var i = 0; i < len; i += 2) { 4915 swap(this, i, i + 1) 4916 } 4917 return this 4918} 4919 4920Buffer.prototype.swap32 = function swap32 () { 4921 var len = this.length 4922 if (len % 4 !== 0) { 4923 throw new RangeError('Buffer size must be a multiple of 32-bits') 4924 } 4925 for (var i = 0; i < len; i += 4) { 4926 swap(this, i, i + 3) 4927 swap(this, i + 1, i + 2) 4928 } 4929 return this 4930} 4931 4932Buffer.prototype.swap64 = function swap64 () { 4933 var len = this.length 4934 if (len % 8 !== 0) { 4935 throw new RangeError('Buffer size must be a multiple of 64-bits') 4936 } 4937 for (var i = 0; i < len; i += 8) { 4938 swap(this, i, i + 7) 4939 swap(this, i + 1, i + 6) 4940 swap(this, i + 2, i + 5) 4941 swap(this, i + 3, i + 4) 4942 } 4943 return this 4944} 4945 4946Buffer.prototype.toString = function toString () { 4947 var length = this.length
vendor: 3,612 bytes, lines 4947-5080
4947 4948 if (length === 0) return '' 4949 if (arguments.length === 0) return utf8Slice(this, 0, length) 4950 return slowToString.apply(this, arguments) 4951} 4952 4953Buffer.prototype.equals = function equals (b) { 4954 if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') 4955 if (this === b) return true 4956 return Buffer.compare(this, b) === 0 4957} 4958 4959Buffer.prototype.inspect = function inspect () { 4960 var str = '' 4961 var max = exports.INSPECT_MAX_BYTES 4962 if (this.length > 0) { 4963 str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') 4964 if (this.length > max) str += ' ... ' 4965 } 4966 return '<Buffer ' + str + '>' 4967} 4968 4969Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { 4970 if (!Buffer.isBuffer(target)) { 4971 throw new TypeError('Argument must be a Buffer') 4972 } 4973 4974 if (start === undefined) { 4975 start = 0 4976 } 4977 if (end === undefined) { 4978 end = target ? target.length : 0 4979 } 4980 if (thisStart === undefined) { 4981 thisStart = 0 4982 } 4983 if (thisEnd === undefined) { 4984 thisEnd = this.length 4985 } 4986 4987 if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { 4988 throw new RangeError('out of range index') 4989 } 4990 4991 if (thisStart >= thisEnd && start >= end) { 4992 return 0 4993 } 4994 if (thisStart >= thisEnd) { 4995 return -1 4996 } 4997 if (start >= end) { 4998 return 1 4999 } 5000 5001 start >>>= 0 5002 end >>>= 0 5003 thisStart >>>= 0 5004 thisEnd >>>= 0 5005 5006 if (this === target) return 0 5007 5008 var x = thisEnd - thisStart 5009 var y = end - start 5010 var len = Math.min(x, y) 5011 5012 var thisCopy = this.slice(thisStart, thisEnd) 5013 var targetCopy = target.slice(start, end) 5014 5015 for (var i = 0; i < len; ++i) { 5016 if (thisCopy[i] !== targetCopy[i]) { 5017 x = thisCopy[i] 5018 y = targetCopy[i] 5019 break 5020 } 5021 } 5022 5023 if (x < y) return -1 5024 if (y < x) return 1 5025 return 0 5026} 5027 5028// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, 5029// OR the last index of `val` in `buffer` at offset <= `byteOffset`. 5030// 5031// Arguments: 5032// - buffer - a Buffer to search 5033// - val - a string, Buffer, or number 5034// - byteOffset - an index into `buffer`; will be clamped to an int32 5035// - encoding - an optional encoding, relevant is val is a string 5036// - dir - true for indexOf, false for lastIndexOf 5037function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { 5038 // Empty buffer means no match 5039 if (buffer.length === 0) return -1 5040 5041 // Normalize byteOffset 5042 if (typeof byteOffset === 'string') { 5043 encoding = byteOffset 5044 byteOffset = 0 5045 } else if (byteOffset > 0x7fffffff) { 5046 byteOffset = 0x7fffffff 5047 } else if (byteOffset < -0x80000000) { 5048 byteOffset = -0x80000000 5049 } 5050 byteOffset = +byteOffset // Coerce to Number. 5051 if (isNaN(byteOffset)) { 5052 // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer 5053 byteOffset = dir ? 0 : (buffer.length - 1) 5054 } 5055 5056 // Normalize byteOffset: negative offsets start from the end of the buffer 5057 if (byteOffset < 0) byteOffset = buffer.length + byteOffset 5058 if (byteOffset >= buffer.length) { 5059 if (dir) return -1 5060 else byteOffset = buffer.length - 1 5061 } else if (byteOffset < 0) { 5062 if (dir) byteOffset = 0 5063 else return -1 5064 } 5065 5066 // Normalize val 5067 if (typeof val === 'string') { 5068 val = Buffer.from(val, encoding) 5069 } 5070 5071 // Finally, search either indexOf (if dir is true) or lastIndexOf 5072 if (Buffer.isBuffer(val)) { 5073 // Special case: looking for empty string/buffer always fails 5074 if (val.length === 0) { 5075 return -1 5076 } 5077 return arrayIndexOf(buffer, val, byteOffset, encoding, dir) 5078 } else if (typeof val === 'number') { 5079 val = val & 0xFF // Search for a byte value [0-255] 5080 if (
vendor: 7,959 bytes, lines 5080-5357
5080typeof Uint8Array.prototype.indexOf === 'function') { 5081 if (dir) { 5082 return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) 5083 } else { 5084 return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) 5085 } 5086 } 5087 return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) 5088 } 5089 5090 throw new TypeError('val must be string, number or Buffer') 5091} 5092 5093function arrayIndexOf (arr, val, byteOffset, encoding, dir) { 5094 var indexSize = 1 5095 var arrLength = arr.length 5096 var valLength = val.length 5097 5098 if (encoding !== undefined) { 5099 encoding = String(encoding).toLowerCase() 5100 if (encoding === 'ucs2' || encoding === 'ucs-2' || 5101 encoding === 'utf16le' || encoding === 'utf-16le') { 5102 if (arr.length < 2 || val.length < 2) { 5103 return -1 5104 } 5105 indexSize = 2 5106 arrLength /= 2 5107 valLength /= 2 5108 byteOffset /= 2 5109 } 5110 } 5111 5112 function read (buf, i) { 5113 if (indexSize === 1) { 5114 return buf[i] 5115 } else { 5116 return buf.readUInt16BE(i * indexSize) 5117 } 5118 } 5119 5120 var i 5121 if (dir) { 5122 var foundIndex = -1 5123 for (i = byteOffset; i < arrLength; i++) { 5124 if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { 5125 if (foundIndex === -1) foundIndex = i 5126 if (i - foundIndex + 1 === valLength) return foundIndex * indexSize 5127 } else { 5128 if (foundIndex !== -1) i -= i - foundIndex 5129 foundIndex = -1 5130 } 5131 } 5132 } else { 5133 if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength 5134 for (i = byteOffset; i >= 0; i--) { 5135 var found = true 5136 for (var j = 0; j < valLength; j++) { 5137 if (read(arr, i + j) !== read(val, j)) { 5138 found = false 5139 break 5140 } 5141 } 5142 if (found) return i 5143 } 5144 } 5145 5146 return -1 5147} 5148 5149Buffer.prototype.includes = function includes (val, byteOffset, encoding) { 5150 return this.indexOf(val, byteOffset, encoding) !== -1 5151} 5152 5153Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { 5154 return bidirectionalIndexOf(this, val, byteOffset, encoding, true) 5155} 5156 5157Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { 5158 return bidirectionalIndexOf(this, val, byteOffset, encoding, false) 5159} 5160 5161function hexWrite (buf, string, offset, length) { 5162 offset = Number(offset) || 0 5163 var remaining = buf.length - offset 5164 if (!length) { 5165 length = remaining 5166 } else { 5167 length = Number(length) 5168 if (length > remaining) { 5169 length = remaining 5170 } 5171 } 5172 5173 // must be an even number of digits 5174 var strLen = string.length 5175 if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') 5176 5177 if (length > strLen / 2) { 5178 length = strLen / 2 5179 } 5180 for (var i = 0; i < length; ++i) { 5181 var parsed = parseInt(string.substr(i * 2, 2), 16) 5182 if (isNaN(parsed)) return i 5183 buf[offset + i] = parsed 5184 } 5185 return i 5186} 5187 5188function utf8Write (buf, string, offset, length) { 5189 return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) 5190} 5191 5192function asciiWrite (buf, string, offset, length) { 5193 return blitBuffer(asciiToBytes(string), buf, offset, length) 5194} 5195 5196function latin1Write (buf, string, offset, length) { 5197 return asciiWrite(buf, string, offset, length) 5198} 5199 5200function base64Write (buf, string, offset, length) { 5201 return blitBuffer(base64ToBytes(string), buf, offset, length) 5202} 5203 5204function ucs2Write (buf, string, offset, length) { 5205 return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) 5206} 5207 5208Buffer.prototype.write = function write (string, offset, length, encoding) { 5209 // Buffer#write(string) 5210 if (offset === undefined) { 5211 encoding = 'utf8' 5212 length = this.length 5213 offset = 0 5214 // Buffer#write(string, encoding) 5215 } else if (length === undefined && typeof offset === 'string') { 5216 encoding = offset 5217 length = this.length 5218 offset = 0 5219 // Buffer#write(string, offset[, length][, encoding]) 5220 } else if (isFinite(offset)) { 5221 offset = offset >>> 0 5222 if (isFinite(length)) { 5223 length = length >>> 0 5224 if (encoding === undefined) encoding = 'utf8' 5225 } else { 5226 encoding = length 5227 length = undefined 5228 } 5229 // legacy write(string, encoding, offset, length) - remove in v0.13 5230 } else { 5231 throw new Error( 5232 'Buffer.write(string, encoding, offset[, length]) is no longer supported' 5233 ) 5234 } 5235 5236 var remaining = this.length - offset 5237 if (length === undefined || length > remaining) length = remaining 5238 5239 if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { 5240 throw new RangeError('Attempt to write outside buffer bounds') 5241 } 5242 5243 if (!encoding) encoding = 'utf8' 5244 5245 var loweredCase = false 5246 for (;;) { 5247 switch (encoding) { 5248 case 'hex': 5249 return hexWrite(this, string, offset, length) 5250 5251 case 'utf8': 5252 case 'utf-8': 5253 return utf8Write(this, string, offset, length) 5254 5255 case 'ascii': 5256 return asciiWrite(this, string, offset, length) 5257 5258 case 'latin1': 5259 case 'binary': 5260 return latin1Write(this, string, offset, length) 5261 5262 case 'base64': 5263 // Warning: maxLength not taken into account in base64Write 5264 return base64Write(this, string, offset, length) 5265 5266 case 'ucs2': 5267 case 'ucs-2': 5268 case 'utf16le': 5269 case 'utf-16le': 5270 return ucs2Write(this, string, offset, length) 5271 5272 default: 5273 if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) 5274 encoding = ('' + encoding).toLowerCase() 5275 loweredCase = true 5276 } 5277 } 5278} 5279 5280Buffer.prototype.toJSON = function toJSON () { 5281 return { 5282 type: 'Buffer', 5283 data: Array.prototype.slice.call(this._arr || this, 0) 5284 } 5285} 5286 5287function base64Slice (buf, start, end) { 5288 if (start === 0 && end === buf.length) { 5289 return base64.fromByteArray(buf) 5290 } else { 5291 return base64.fromByteArray(buf.slice(start, end)) 5292 } 5293} 5294 5295function utf8Slice (buf, start, end) { 5296 end = Math.min(buf.length, end) 5297 var res = [] 5298 5299 var i = start 5300 while (i < end) { 5301 var firstByte = buf[i] 5302 var codePoint = null 5303 var bytesPerSequence = (firstByte > 0xEF) ? 4 5304 : (firstByte > 0xDF) ? 3 5305 : (firstByte > 0xBF) ? 2 5306 : 1 5307 5308 if (i + bytesPerSequence <= end) { 5309 var secondByte, thirdByte, fourthByte, tempCodePoint 5310 5311 switch (bytesPerSequence) { 5312 case 1: 5313 if (firstByte < 0x80) { 5314 codePoint = firstByte 5315 } 5316 break 5317 case 2: 5318 secondByte = buf[i + 1] 5319 if ((secondByte & 0xC0) === 0x80) { 5320 tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) 5321 if (tempCodePoint > 0x7F) { 5322 codePoint = tempCodePoint 5323 } 5324 } 5325 break 5326 case 3: 5327 secondByte = buf[i + 1] 5328 thirdByte = buf[i + 2] 5329 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { 5330 tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) 5331 if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { 5332 codePoint = tempCodePoint 5333 } 5334 } 5335 break 5336 case 4: 5337 secondByte = buf[i + 1] 5338 thirdByte = buf[i + 2] 5339 fourthByte = buf[i + 3] 5340 if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { 5341 tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) 5342 if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { 5343 codePoint = tempCodePoint 5344 } 5345 } 5346 } 5347 } 5348 5349 if (codePoint === null) { 5350 // we did not generate a valid codePoint so insert a 5351 // replacement char (U+FFFD) and advance only 1 byte 5352 codePoint = 0xFFFD 5353 bytesPerSequence = 1 5354 } else if (codePoint > 0xFFFF) { 5355 // encode to utf16 (surrogate pair dance) 5356 codePoint -= 0x10000 5357 res.push(codePoint >>>
vendor: 1,624 bytes, lines 5357-5428
5357 10 & 0x3FF | 0xD800) 5358 codePoint = 0xDC00 | codePoint & 0x3FF 5359 } 5360 5361 res.push(codePoint) 5362 i += bytesPerSequence 5363 } 5364 5365 return decodeCodePointsArray(res) 5366} 5367 5368// Based on http://stackoverflow.com/a/22747272/680742, the browser with 5369// the lowest limit is Chrome, with 0x10000 args. 5370// We go 1 magnitude less, for safety 5371var MAX_ARGUMENTS_LENGTH = 0x1000 5372 5373function decodeCodePointsArray (codePoints) { 5374 var len = codePoints.length 5375 if (len <= MAX_ARGUMENTS_LENGTH) { 5376 return String.fromCharCode.apply(String, codePoints) // avoid extra slice() 5377 } 5378 5379 // Decode in chunks to avoid "call stack size exceeded". 5380 var res = '' 5381 var i = 0 5382 while (i < len) { 5383 res += String.fromCharCode.apply( 5384 String, 5385 codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) 5386 ) 5387 } 5388 return res 5389} 5390 5391function asciiSlice (buf, start, end) { 5392 var ret = '' 5393 end = Math.min(buf.length, end) 5394 5395 for (var i = start; i < end; ++i) { 5396 ret += String.fromCharCode(buf[i] & 0x7F) 5397 } 5398 return ret 5399} 5400 5401function latin1Slice (buf, start, end) { 5402 var ret = '' 5403 end = Math.min(buf.length, end) 5404 5405 for (var i = start; i < end; ++i) { 5406 ret += String.fromCharCode(buf[i]) 5407 } 5408 return ret 5409} 5410 5411function hexSlice (buf, start, end) { 5412 var len = buf.length 5413 5414 if (!start || start < 0) start = 0 5415 if (!end || end < 0 || end > len) end = len 5416 5417 var out = '' 5418 for (var i = start; i < end; ++i) { 5419 out += toHex(buf[i]) 5420 } 5421 return out 5422} 5423 5424function utf16leSlice (buf, start, end) { 5425 var bytes = buf.slice(start, end) 5426 var res = '' 5427 for (var i = 0; i < bytes.length; i += 2) { 5428 res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256
vendor: 8,639 bytes, lines 5428-5734
5428) 5429 } 5430 return res 5431} 5432 5433Buffer.prototype.slice = function slice (start, end) { 5434 var len = this.length 5435 start = ~~start 5436 end = end === undefined ? len : ~~end 5437 5438 if (start < 0) { 5439 start += len 5440 if (start < 0) start = 0 5441 } else if (start > len) { 5442 start = len 5443 } 5444 5445 if (end < 0) { 5446 end += len 5447 if (end < 0) end = 0 5448 } else if (end > len) { 5449 end = len 5450 } 5451 5452 if (end < start) end = start 5453 5454 var newBuf = this.subarray(start, end) 5455 // Return an augmented `Uint8Array` instance 5456 newBuf.__proto__ = Buffer.prototype 5457 return newBuf 5458} 5459 5460/* 5461 * Need to make sure that buffer isn't trying to write out of bounds. 5462 */ 5463function checkOffset (offset, ext, length) { 5464 if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') 5465 if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') 5466} 5467 5468Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { 5469 offset = offset >>> 0 5470 byteLength = byteLength >>> 0 5471 if (!noAssert) checkOffset(offset, byteLength, this.length) 5472 5473 var val = this[offset] 5474 var mul = 1 5475 var i = 0 5476 while (++i < byteLength && (mul *= 0x100)) { 5477 val += this[offset + i] * mul 5478 } 5479 5480 return val 5481} 5482 5483Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { 5484 offset = offset >>> 0 5485 byteLength = byteLength >>> 0 5486 if (!noAssert) { 5487 checkOffset(offset, byteLength, this.length) 5488 } 5489 5490 var val = this[offset + --byteLength] 5491 var mul = 1 5492 while (byteLength > 0 && (mul *= 0x100)) { 5493 val += this[offset + --byteLength] * mul 5494 } 5495 5496 return val 5497} 5498 5499Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { 5500 offset = offset >>> 0 5501 if (!noAssert) checkOffset(offset, 1, this.length) 5502 return this[offset] 5503} 5504 5505Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { 5506 offset = offset >>> 0 5507 if (!noAssert) checkOffset(offset, 2, this.length) 5508 return this[offset] | (this[offset + 1] << 8) 5509} 5510 5511Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { 5512 offset = offset >>> 0 5513 if (!noAssert) checkOffset(offset, 2, this.length) 5514 return (this[offset] << 8) | this[offset + 1] 5515} 5516 5517Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { 5518 offset = offset >>> 0 5519 if (!noAssert) checkOffset(offset, 4, this.length) 5520 5521 return ((this[offset]) | 5522 (this[offset + 1] << 8) | 5523 (this[offset + 2] << 16)) + 5524 (this[offset + 3] * 0x1000000) 5525} 5526 5527Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { 5528 offset = offset >>> 0 5529 if (!noAssert) checkOffset(offset, 4, this.length) 5530 5531 return (this[offset] * 0x1000000) + 5532 ((this[offset + 1] << 16) | 5533 (this[offset + 2] << 8) | 5534 this[offset + 3]) 5535} 5536 5537Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { 5538 offset = offset >>> 0 5539 byteLength = byteLength >>> 0 5540 if (!noAssert) checkOffset(offset, byteLength, this.length) 5541 5542 var val = this[offset] 5543 var mul = 1 5544 var i = 0 5545 while (++i < byteLength && (mul *= 0x100)) { 5546 val += this[offset + i] * mul 5547 } 5548 mul *= 0x80 5549 5550 if (val >= mul) val -= Math.pow(2, 8 * byteLength) 5551 5552 return val 5553} 5554 5555Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { 5556 offset = offset >>> 0 5557 byteLength = byteLength >>> 0 5558 if (!noAssert) checkOffset(offset, byteLength, this.length) 5559 5560 var i = byteLength 5561 var mul = 1 5562 var val = this[offset + --i] 5563 while (i > 0 && (mul *= 0x100)) { 5564 val += this[offset + --i] * mul 5565 } 5566 mul *= 0x80 5567 5568 if (val >= mul) val -= Math.pow(2, 8 * byteLength) 5569 5570 return val 5571} 5572 5573Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { 5574 offset = offset >>> 0 5575 if (!noAssert) checkOffset(offset, 1, this.length) 5576 if (!(this[offset] & 0x80)) return (this[offset]) 5577 return ((0xff - this[offset] + 1) * -1) 5578} 5579 5580Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { 5581 offset = offset >>> 0 5582 if (!noAssert) checkOffset(offset, 2, this.length) 5583 var val = this[offset] | (this[offset + 1] << 8) 5584 return (val & 0x8000) ? val | 0xFFFF0000 : val 5585} 5586 5587Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { 5588 offset = offset >>> 0 5589 if (!noAssert) checkOffset(offset, 2, this.length) 5590 var val = this[offset + 1] | (this[offset] << 8) 5591 return (val & 0x8000) ? val | 0xFFFF0000 : val 5592} 5593 5594Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { 5595 offset = offset >>> 0 5596 if (!noAssert) checkOffset(offset, 4, this.length) 5597 5598 return (this[offset]) | 5599 (this[offset + 1] << 8) | 5600 (this[offset + 2] << 16) | 5601 (this[offset + 3] << 24) 5602} 5603 5604Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { 5605 offset = offset >>> 0 5606 if (!noAssert) checkOffset(offset, 4, this.length) 5607 5608 return (this[offset] << 24) | 5609 (this[offset + 1] << 16) | 5610 (this[offset + 2] << 8) | 5611 (this[offset + 3]) 5612} 5613 5614Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { 5615 offset = offset >>> 0 5616 if (!noAssert) checkOffset(offset, 4, this.length) 5617 return ieee754.read(this, offset, true, 23, 4) 5618} 5619 5620Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { 5621 offset = offset >>> 0 5622 if (!noAssert) checkOffset(offset, 4, this.length) 5623 return ieee754.read(this, offset, false, 23, 4) 5624} 5625 5626Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { 5627 offset = offset >>> 0 5628 if (!noAssert) checkOffset(offset, 8, this.length) 5629 return ieee754.read(this, offset, true, 52, 8) 5630} 5631 5632Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { 5633 offset = offset >>> 0 5634 if (!noAssert) checkOffset(offset, 8, this.length) 5635 return ieee754.read(this, offset, false, 52, 8) 5636} 5637 5638function checkInt (buf, value, offset, ext, max, min) { 5639 if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') 5640 if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') 5641 if (offset + ext > buf.length) throw new RangeError('Index out of range') 5642} 5643 5644Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { 5645 value = +value 5646 offset = offset >>> 0 5647 byteLength = byteLength >>> 0 5648 if (!noAssert) { 5649 var maxBytes = Math.pow(2, 8 * byteLength) - 1 5650 checkInt(this, value, offset, byteLength, maxBytes, 0) 5651 } 5652 5653 var mul = 1 5654 var i = 0 5655 this[offset] = value & 0xFF 5656 while (++i < byteLength && (mul *= 0x100)) { 5657 this[offset + i] = (value / mul) & 0xFF 5658 } 5659 5660 return offset + byteLength 5661} 5662 5663Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { 5664 value = +value 5665 offset = offset >>> 0 5666 byteLength = byteLength >>> 0 5667 if (!noAssert) { 5668 var maxBytes = Math.pow(2, 8 * byteLength) - 1 5669 checkInt(this, value, offset, byteLength, maxBytes, 0) 5670 } 5671 5672 var i = byteLength - 1 5673 var mul = 1 5674 this[offset + i] = value & 0xFF 5675 while (--i >= 0 && (mul *= 0x100)) { 5676 this[offset + i] = (value / mul) & 0xFF 5677 } 5678 5679 return offset + byteLength 5680} 5681 5682Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { 5683 value = +value 5684 offset = offset >>> 0 5685 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) 5686 this[offset] = (value & 0xff) 5687 return offset + 1 5688} 5689 5690Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { 5691 value = +value 5692 offset = offset >>> 0 5693 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) 5694 this[offset] = (value & 0xff) 5695 this[offset + 1] = (value >>> 8) 5696 return offset + 2 5697} 5698 5699Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { 5700 value = +value 5701 offset = offset >>> 0 5702 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) 5703 this[offset] = (value >>> 8) 5704 this[offset + 1] = (value & 0xff) 5705 return offset + 2 5706} 5707 5708Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { 5709 value = +value 5710 offset = offset >>> 0 5711 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) 5712 this[offset + 3] = (value >>> 24) 5713 this[offset + 2] = (value >>> 16) 5714 this[offset + 1] = (value >>> 8) 5715 this[offset] = (value & 0xff) 5716 return offset + 4 5717} 5718 5719Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { 5720 value = +value 5721 offset = offset >>> 0 5722 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) 5723 this[offset] = (value >>> 24) 5724 this[offset + 1] = (value >>> 16) 5725 this[offset + 2] = (value >>> 8) 5726 this[offset + 3] = (value & 0xff) 5727 return offset + 4 5728} 5729 5730Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { 5731 value = +value 5732 offset = offset >>> 0 5733 if (!noAssert) { 5734 var limit = Math.pow(2,
vendor: 1,236 bytes, lines 5734-5784
57348 * byteLength - 1) 5735 5736 checkInt(this, value, offset, byteLength, limit - 1, -limit) 5737 } 5738 5739 var i = 0 5740 var mul = 1 5741 var sub = 0 5742 this[offset] = value & 0xFF 5743 while (++i < byteLength && (mul *= 0x100)) { 5744 if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { 5745 sub = 1 5746 } 5747 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 5748 } 5749 5750 return offset + byteLength 5751} 5752 5753Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { 5754 value = +value 5755 offset = offset >>> 0 5756 if (!noAssert) { 5757 var limit = Math.pow(2, 8 * byteLength - 1) 5758 5759 checkInt(this, value, offset, byteLength, limit - 1, -limit) 5760 } 5761 5762 var i = byteLength - 1 5763 var mul = 1 5764 var sub = 0 5765 this[offset + i] = value & 0xFF 5766 while (--i >= 0 && (mul *= 0x100)) { 5767 if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { 5768 sub = 1 5769 } 5770 this[offset + i] = ((value / mul) >> 0) - sub & 0xFF 5771 } 5772 5773 return offset + byteLength 5774} 5775 5776Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { 5777 value = +value 5778 offset = offset >>> 0 5779 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) 5780 if (value < 0) value = 0xff + value + 1 5781 this[offset] = (value & 0xff) 5782 return offset + 1 5783} 5784
vendor: 7,879 bytes, lines 5785-6060
5785Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { 5786 value = +value 5787 offset = offset >>> 0 5788 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) 5789 this[offset] = (value & 0xff) 5790 this[offset + 1] = (value >>> 8) 5791 return offset + 2 5792} 5793 5794Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { 5795 value = +value 5796 offset = offset >>> 0 5797 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) 5798 this[offset] = (value >>> 8) 5799 this[offset + 1] = (value & 0xff) 5800 return offset + 2 5801} 5802 5803Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { 5804 value = +value 5805 offset = offset >>> 0 5806 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 5807 this[offset] = (value & 0xff) 5808 this[offset + 1] = (value >>> 8) 5809 this[offset + 2] = (value >>> 16) 5810 this[offset + 3] = (value >>> 24) 5811 return offset + 4 5812} 5813 5814Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { 5815 value = +value 5816 offset = offset >>> 0 5817 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) 5818 if (value < 0) value = 0xffffffff + value + 1 5819 this[offset] = (value >>> 24) 5820 this[offset + 1] = (value >>> 16) 5821 this[offset + 2] = (value >>> 8) 5822 this[offset + 3] = (value & 0xff) 5823 return offset + 4 5824} 5825 5826function checkIEEE754 (buf, value, offset, ext, max, min) { 5827 if (offset + ext > buf.length) throw new RangeError('Index out of range') 5828 if (offset < 0) throw new RangeError('Index out of range') 5829} 5830 5831function writeFloat (buf, value, offset, littleEndian, noAssert) { 5832 value = +value 5833 offset = offset >>> 0 5834 if (!noAssert) { 5835 checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) 5836 } 5837 ieee754.write(buf, value, offset, littleEndian, 23, 4) 5838 return offset + 4 5839} 5840 5841Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { 5842 return writeFloat(this, value, offset, true, noAssert) 5843} 5844 5845Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { 5846 return writeFloat(this, value, offset, false, noAssert) 5847} 5848 5849function writeDouble (buf, value, offset, littleEndian, noAssert) { 5850 value = +value 5851 offset = offset >>> 0 5852 if (!noAssert) { 5853 checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) 5854 } 5855 ieee754.write(buf, value, offset, littleEndian, 52, 8) 5856 return offset + 8 5857} 5858 5859Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { 5860 return writeDouble(this, value, offset, true, noAssert) 5861} 5862 5863Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { 5864 return writeDouble(this, value, offset, false, noAssert) 5865} 5866 5867// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) 5868Buffer.prototype.copy = function copy (target, targetStart, start, end) { 5869 if (!start) start = 0 5870 if (!end && end !== 0) end = this.length 5871 if (targetStart >= target.length) targetStart = target.length 5872 if (!targetStart) targetStart = 0 5873 if (end > 0 && end < start) end = start 5874 5875 // Copy 0 bytes; we're done 5876 if (end === start) return 0 5877 if (target.length === 0 || this.length === 0) return 0 5878 5879 // Fatal error conditions 5880 if (targetStart < 0) { 5881 throw new RangeError('targetStart out of bounds') 5882 } 5883 if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') 5884 if (end < 0) throw new RangeError('sourceEnd out of bounds') 5885 5886 // Are we oob? 5887 if (end > this.length) end = this.length 5888 if (target.length - targetStart < end - start) { 5889 end = target.length - targetStart + start 5890 } 5891 5892 var len = end - start 5893 var i 5894 5895 if (this === target && start < targetStart && targetStart < end) { 5896 // descending copy from end 5897 for (i = len - 1; i >= 0; --i) { 5898 target[i + targetStart] = this[i + start] 5899 } 5900 } else if (len < 1000) { 5901 // ascending copy from start 5902 for (i = 0; i < len; ++i) { 5903 target[i + targetStart] = this[i + start] 5904 } 5905 } else { 5906 Uint8Array.prototype.set.call( 5907 target, 5908 this.subarray(start, start + len), 5909 targetStart 5910 ) 5911 } 5912 5913 return len 5914} 5915 5916// Usage: 5917// buffer.fill(number[, offset[, end]]) 5918// buffer.fill(buffer[, offset[, end]]) 5919// buffer.fill(string[, offset[, end]][, encoding]) 5920Buffer.prototype.fill = function fill (val, start, end, encoding) { 5921 // Handle string cases: 5922 if (typeof val === 'string') { 5923 if (typeof start === 'string') { 5924 encoding = start 5925 start = 0 5926 end = this.length 5927 } else if (typeof end === 'string') { 5928 encoding = end 5929 end = this.length 5930 } 5931 if (val.length === 1) { 5932 var code = val.charCodeAt(0) 5933 if (code < 256) { 5934 val = code 5935 } 5936 } 5937 if (encoding !== undefined && typeof encoding !== 'string') { 5938 throw new TypeError('encoding must be a string') 5939 } 5940 if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { 5941 throw new TypeError('Unknown encoding: ' + encoding) 5942 } 5943 } else if (typeof val === 'number') { 5944 val = val & 255 5945 } 5946 5947 // Invalid ranges are not set to a default, so can range check early. 5948 if (start < 0 || this.length < start || this.length < end) { 5949 throw new RangeError('Out of range index') 5950 } 5951 5952 if (end <= start) { 5953 return this 5954 } 5955 5956 start = start >>> 0 5957 end = end === undefined ? this.length : end >>> 0 5958 5959 if (!val) val = 0 5960 5961 var i 5962 if (typeof val === 'number') { 5963 for (i = start; i < end; ++i) { 5964 this[i] = val 5965 } 5966 } else { 5967 var bytes = Buffer.isBuffer(val) 5968 ? val 5969 : new Buffer(val, encoding) 5970 var len = bytes.length 5971 for (i = 0; i < end - start; ++i) { 5972 this[i + start] = bytes[i % len] 5973 } 5974 } 5975 5976 return this 5977} 5978 5979// HELPER FUNCTIONS 5980// ================ 5981 5982var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g 5983 5984function base64clean (str) { 5985 // Node strips out invalid characters like \n and \t from the string, base64-js does not 5986 str = stringtrim(str).replace(INVALID_BASE64_RE, '') 5987 // Node converts strings with length < 2 to '' 5988 if (str.length < 2) return '' 5989 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not 5990 while (str.length % 4 !== 0) { 5991 str = str + '=' 5992 } 5993 return str 5994} 5995 5996function stringtrim (str) { 5997 if (str.trim) return str.trim() 5998 return str.replace(/^\s+|\s+$/g, '') 5999} 6000 6001function toHex (n) { 6002 if (n < 16) return '0' + n.toString(16) 6003 return n.toString(16) 6004} 6005 6006function utf8ToBytes (string, units) { 6007 units = units || Infinity 6008 var codePoint 6009 var length = string.length 6010 var leadSurrogate = null 6011 var bytes = [] 6012 6013 for (var i = 0; i < length; ++i) { 6014 codePoint = string.charCodeAt(i) 6015 6016 // is surrogate component 6017 if (codePoint > 0xD7FF && codePoint < 0xE000) { 6018 // last char was a lead 6019 if (!leadSurrogate) { 6020 // no lead yet 6021 if (codePoint > 0xDBFF) { 6022 // unexpected trail 6023 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 6024 continue 6025 } else if (i + 1 === length) { 6026 // unpaired lead 6027 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 6028 continue 6029 } 6030 6031 // valid lead 6032 leadSurrogate = codePoint 6033 6034 continue 6035 } 6036 6037 // 2 leads in a row 6038 if (codePoint < 0xDC00) { 6039 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 6040 leadSurrogate = codePoint 6041 continue 6042 } 6043 6044 // valid surrogate pair 6045 codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 6046 } else if (leadSurrogate) { 6047 // valid bmp char, but last char was a lead 6048 if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) 6049 } 6050 6051 leadSurrogate = null 6052 6053 // encode utf8 6054 if (codePoint < 0x80) { 6055 if ((units -= 1) < 0) break 6056 bytes.push(codePoint) 6057 } else if (codePoint < 0x800) { 6058 if ((units -= 2) < 0) break 6059 bytes.push( 6060 codePoint >> 0x6 | 0xC0,
6061 codePoint & 0x3F | 0x80 6062 ) 6063 } else if (codePoint < 0x10000) { 6064 if ((units -= 3) < 0) break 6065 bytes.push( 6066 codePoint >> 0xC | 0xE0, 6067 codePoint >> 0x6 & 0x3F | 0x80, 6068 codePoint & 0x3F | 0x80 6069 ) 6070 } else if (codePoint < 0x110000) { 6071 if ((units -= 4) < 0) break 6072 bytes.push( 6073 codePoint >> 0x12 | 0xF0, 6074 codePoint >> 0xC & 0x3F | 0x80, 6075 codePoint >> 0x6 & 0x3F | 0x80, 6076 codePoint & 0x3F | 0x80 6077 ) 6078 } else { 6079 throw new Error('Invalid code point') 6080 } 6081 } 6082 6083 return bytes 6084} 6085 6086function asciiToBytes (str) { 6087 var byteArray = [] 6088 for (var i = 0; i < str.length; ++i) { 6089 // Node's code seems to be doing this and not & 0x7F.. 6090 byteArray.push(str.charCodeAt(i) & 0xFF) 6091 } 6092 return byteArray 6093} 6094 6095function utf16leToBytes (str, units) { 6096 var c, hi, lo 6097 var byteArray = [] 6098 for (var i = 0; i < str.length; ++i) { 6099 if ((units -= 2) < 0) break 6100 6101 c = str.charCodeAt(i) 6102 hi = c >> 8 6103 lo = c % 256 6104 byteArray.push(lo) 6105 byteArray.push(hi) 6106 } 6107 6108 return byteArray 6109} 6110 6111function base64ToBytes (str) { 6112 return base64.toByteArray(base64clean(str)) 6113} 6114 6115function blitBuffer (src, dst, offset, length) { 6116 for (var i = 0; i < length; ++i) { 6117 if ((i + offset >= dst.length) || (i >= src.length)) break 6118 dst[i + offset] = src[i] 6119 } 6120 return i 6121} 6122 6123function isnan (val) { 6124 return val !== val // eslint-disable-line no-self-compare 6125} 6126 6127},{"base64-js":3,"ieee754":9}],7:[function(require,module,exports){ 6128(function (Buffer){ 6129'use strict'; 6130 6131/* eslint-disable */ 6132 6133var utils = require('./utils/index.js'); 6134var uint256Coder = utils.uint256Coder; 6135var coderBoolean = utils.coderBoolean; 6136var coderFixedBytes = utils.coderFixedBytes; 6137var coderAddress = utils.coderAddress; 6138var coderDynamicBytes = utils.coderDynamicBytes; 6139var coderString = utils.coderString; 6140var coderArray = utils.coderArray; 6141var paramTypePart = utils.paramTypePart; 6142var getParamCoder = utils.getParamCoder; 6143 6144function Result() {} 6145 6146function encodeParams(types, values) { 6147 if (types.length !== values.length) { 6148 throw new Error('[ethjs-abi] while encoding params, types/values mismatch, types length ' + types.length + ' should be ' + values.length); 6149 } 6150 6151 var parts = []; 6152 6153 types.forEach(function (type, index) { 6154 var coder = getParamCoder(type); 6155 parts.push({ dynamic: coder.dynamic, value: coder.encode(values[index]) }); 6156 }); 6157 6158 function alignSize(size) { 6159 return parseInt(32 * Math.ceil(size / 32)); 6160 } 6161 6162 var staticSize = 0, 6163 dynamicSize = 0; 6164 parts.forEach(function (part) { 6165 if (part.dynamic) { 6166 staticSize += 32; 6167 dynamicSize += alignSize(part.value.length); 6168 } else { 6169 staticSize += alignSize(part.value.length); 6170 } 6171 }); 6172 6173 var offset = 0, 6174 dynamicOffset = staticSize; 6175 var data = new Buffer(staticSize + dynamicSize); 6176 6177 parts.forEach(function (part, index) { 6178 if (part.dynamic) { 6179 uint256Coder.encode(dynamicOffset).copy(data, offset); 6180 offset += 32; 6181 6182 part.value.copy(data, dynamicOffset); 6183 dynamicOffset += alignSize(part.value.length); 6184 } else { 6185 part.value.copy(data, offset); 6186 offset += alignSize(part.value.length); 6187 } 6188 }); 6189 6190 return '0x' + data.toString('hex'); 6191} 6192 6193// decode bytecode data from output names and types 6194function decodeParams(names, types, data) { 6195 // Names is optional, so shift over all the parameters if not provided 6196 if (arguments.length < 3) { 6197 data = types; 6198 types = names; 6199 names = []; 6200 } 6201 6202 data = utils.hexOrBuffer(data); 6203 var values = new Result(); 6204 6205 var offset = 0; 6206 types.forEach(function (type, index) { 6207 var coder = getParamCoder(type); 6208 if (coder.dynamic) { 6209 var dynamicOffset = uint256Coder.decode(data, offset); 6210 var result = coder.decode(data, dynamicOffset.value.toNumber()); 6211 offset += dynamicOffset.consumed; 6212 } else { 6213 var result = coder.decode(data, offset); 6214 offset += result.consumed; 6215 } 6216 values[index] = result.value; 6217 if (names[index]) { 6218 values[names[index]] = result.value; 6219 } 6220 }); 6221 return values; 6222} 6223 6224// encode method ABI object with values in an array, output bytecode 6225function encodeMethod(method, values) { 6226 var signature = method.name + '(' + utils.getKeys(method.inputs, 'type').join(',') + ')'; 6227 var signatureEncoded = '0x' + new Buffer(utils.keccak256(signature), 'hex').slice(0, 4).toString('hex'); 6228 var paramsEncoded = encodeParams(utils.getKeys(method.inputs, 'type'), values).substring(2); 6229 6230 return '' + signatureEncoded + paramsEncoded; 6231} 6232 6233// decode method data bytecode, from method ABI object 6234function decodeMethod(method, data) {
6235 var outputNames = utils.getKeys(method.outputs, 'name', true); 6236 var outputTypes = utils.getKeys(method.outputs, 'type'); 6237 6238 return decodeParams(outputNames, outputTypes, utils.hexOrBuffer(data)); 6239} 6240 6241// decode method data bytecode, from method ABI object 6242function encodeEvent(eventObject, values) { 6243 return encodeMethod(eventObject, values); 6244} 6245 6246// decode method data bytecode, from method ABI object 6247function decodeEvent(eventObject, data) { 6248 var inputNames = utils.getKeys(eventObject.inputs, 'name', true); 6249 var inputTypes = utils.getKeys(eventObject.inputs, 'type'); 6250 6251 return decodeParams(inputNames, inputTypes, utils.hexOrBuffer(data)); 6252} 6253 6254module.exports = { 6255 encodeParams: encodeParams, 6256 decodeParams: decodeParams, 6257 encodeMethod: encodeMethod, 6258 decodeMethod: decodeMethod, 6259 encodeEvent: encodeEvent, 6260 decodeEvent: decodeEvent 6261}; 6262}).call(this,require("buffer").Buffer) 6263},{"./utils/index.js":8,"buffer":6}],8:[function(require,module,exports){ 6264(function (Buffer){ 6265'use strict'; 6266 6267var BN = require('bn.js'); 6268var numberToBN = require('number-to-bn'); 6269var keccak256 = require('js-sha3').keccak_256; 6270 6271// from ethereumjs-util 6272function stripZeros(aInput) { 6273 var a = aInput; // eslint-disable-line 6274 var first = a[0]; // eslint-disable-line 6275 while (a.length > 0 && first.toString() === '0') { 6276 a = a.slice(1); 6277 first = a[0]; 6278 } 6279 return a; 6280} 6281 6282function bnToBuffer(bnInput) { 6283 var bn = bnInput; // eslint-disable-line 6284 var hex = bn.toString(16); // eslint-disable-line 6285 if (hex.length % 2) { 6286 hex = '0' + hex; 6287 } 6288 return stripZeros(new Buffer(hex, 'hex')); 6289} 6290 6291function isHexString(value, length) { 6292 if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) { 6293 return false; 6294 } 6295 if (length && value.length !== 2 + 2 * length) { 6296 return false; 6297 } 6298 return true; 6299} 6300 6301function hexOrBuffer(valueInput, name) { 6302 var value = valueInput; // eslint-disable-line 6303 if (!Buffer.isBuffer(value)) { 6304 if (!isHexString(value)) { 6305 var error = new Error(name ? '[ethjs-abi] invalid ' + name : '[ethjs-abi] invalid hex or buffer, must be a prefixed alphanumeric even length hex string'); 6306 error.reason = '[ethjs-abi] invalid hex string, hex must be prefixed and alphanumeric (e.g. 0x023..)'; 6307 error.value = value; 6308 throw error; 6309 } 6310 6311 value = value.substring(2); 6312 if (value.length % 2) { 6313 value = '0' + value; 6314 } 6315 value = new Buffer(value, 'hex'); 6316 } 6317 6318 return value; 6319} 6320 6321function hexlify(value) { 6322 if (typeof value === 'number') { 6323 return '0x' + bnToBuffer(new BN(value)).toString('hex'); 6324 } else if (value.mod || value.modulo) { 6325 return '0x' + bnToBuffer(value).toString('hex'); 6326 } else { 6327 // eslint-disable-line 6328 return '0x' + hexOrBuffer(value).toString('hex'); 6329 } 6330} 6331 6332// getKeys([{a: 1, b: 2}, {a: 3, b: 4}], 'a') => [1, 3] 6333function getKeys(params, key, allowEmpty) { 6334 var result = []; // eslint-disable-line 6335 6336 if (!Array.isArray(params)) { 6337 throw new Error('[ethjs-abi] while getting keys, invalid params value ' + JSON.stringify(params)); 6338 } 6339 6340 for (var i = 0; i < params.length; i++) { 6341 // eslint-disable-line 6342 var value = params[i][key]; // eslint-disable-line 6343 if (allowEmpty && !value) { 6344 value = ''; 6345 } else if (typeof value !== 'string') { 6346 throw new Error('[ethjs-abi] while getKeys found invalid ABI data structure, type value not string'); 6347 } 6348 result.push(value); 6349 } 6350 6351 return result; 6352} 6353 6354function coderNumber(size, signed) { 6355 return { 6356 encode: function encodeNumber(valueInput) { 6357 var value = valueInput; // eslint-disable-line 6358 6359 if (typeof value === 'object' && value.toString && (value.toTwos || value.dividedToIntegerBy)) { 6360 value = value.toString(10).split('.')[0]; 6361 } 6362 6363 if (typeof value === 'string' || typeof value === 'number') { 6364 value = String(value).split('.')[0]; 6365 } 6366 6367 value = numberToBN(value); 6368 value = value.toTwos(size * 8).maskn(size * 8); 6369 if (signed) { 6370 value = value.fromTwos(size * 8).toTwos(256); 6371 } 6372 return value.toArrayLike(Buffer, 'be', 32); 6373 }, 6374 decode: function decodeNumber(data, offset) { 6375 var junkLength = 32 - size; // eslint-disable-line 6376 var value = new BN(data.slice(offset + junkLength, offset + 32)); // eslint-disable-line 6377 if (signed) { 6378 value = value.fromTwos(size * 8); 6379 } else { 6380 value = value.maskn(size * 8); 6381 } 6382 return { 6383 consumed: 32, 6384 value: new BN(value.toString(10)) 6385 }; 6386 } 6387 }; 6388} 6389var uint256Coder = coderNumber(32, false); 6390
6391var coderBoolean = { 6392 encode: function encodeBoolean(value) { 6393 return uint256Coder.encode(value ? 1 : 0); 6394 }, 6395 decode: function decodeBoolean(data, offset) { 6396 var result = uint256Coder.decode(data, offset); // eslint-disable-line 6397 return { 6398 consumed: result.consumed, 6399 value: !result.value.isZero() 6400 }; 6401 } 6402}; 6403 6404function coderFixedBytes(length) { 6405 return { 6406 encode: function encodeFixedBytes(valueInput) { 6407 var value = valueInput; // eslint-disable-line 6408 value = hexOrBuffer(value); 6409 6410 if (value.length === 32) { 6411 return value; 6412 } 6413 6414 var result = new Buffer(32); // eslint-disable-line 6415 result.fill(0); 6416 value.copy(result); 6417 return result; 6418 }, 6419 decode: function decodeFixedBytes(data, offset) { 6420 if (data.length < offset + 32) { 6421 throw new Error('[ethjs-abi] while decoding fixed bytes, invalid bytes data length: ' + length); 6422 } 6423 6424 return { 6425 consumed: 32, 6426 value: '0x' + data.slice(offset, offset + length).toString('hex') 6427 }; 6428 } 6429 }; 6430} 6431 6432var coderAddress = { 6433 encode: function encodeAddress(valueInput) { 6434 var value = valueInput; // eslint-disable-line 6435 var result = new Buffer(32); // eslint-disable-line 6436 if (!isHexString(value, 20)) { 6437 throw new Error('[ethjs-abi] while encoding address, invalid address value, not alphanumeric 20 byte hex string'); 6438 } 6439 value = hexOrBuffer(value); 6440 result.fill(0); 6441 value.copy(result, 12); 6442 return result; 6443 }, 6444 decode: function decodeAddress(data, offset) { 6445 if (data.length === 0) { 6446 return { 6447 consumed: 32, 6448 value: '0x' 6449 }; 6450 } 6451 if (data.length < offset + 32) { 6452 throw new Error('[ethjs-abi] while decoding address data, invalid address data, invalid byte length ' + data.length); 6453 } 6454 return { 6455 consumed: 32, 6456 value: '0x' + data.slice(offset + 12, offset + 32).toString('hex') 6457 }; 6458 } 6459}; 6460 6461function encodeDynamicBytesHelper(value) { 6462 var dataLength = parseInt(32 * Math.ceil(value.length / 32)); // eslint-disable-line 6463 var padding = new Buffer(dataLength - value.length); // eslint-disable-line 6464 padding.fill(0); 6465 6466 return Buffer.concat([uint256Coder.encode(value.length), value, padding]); 6467} 6468 6469function decodeDynamicBytesHelper(data, offset) { 6470 if (data.length < offset + 32) { 6471 throw new Error('[ethjs-abi] while decoding dynamic bytes data, invalid bytes length: ' + data.length + ' should be less than ' + (offset + 32)); 6472 } 6473 6474 var length = uint256Coder.decode(data, offset).value; // eslint-disable-line 6475 length = length.toNumber(); 6476 if (data.length < offset + 32 + length) { 6477 throw new Error('[ethjs-abi] while decoding dynamic bytes data, invalid bytes length: ' + data.length + ' should be less than ' + (offset + 32 + length)); 6478 } 6479 6480 return { 6481 consumed: parseInt(32 + 32 * Math.ceil(length / 32), 10), 6482 value: data.slice(offset + 32, offset + 32 + length) 6483 }; 6484} 6485 6486var coderDynamicBytes = { 6487 encode: function encodeDynamicBytes(value) { 6488 return encodeDynamicBytesHelper(hexOrBuffer(value)); 6489 }, 6490 decode: function decodeDynamicBytes(data, offset) { 6491 var result = decodeDynamicBytesHelper(data, offset); // eslint-disable-line 6492 result.value = '0x' + result.value.toString('hex'); 6493 return result; 6494 }, 6495 dynamic: true 6496}; 6497 6498var coderString = { 6499 encode: function encodeString(value) { 6500 return encodeDynamicBytesHelper(new Buffer(value, 'utf8')); 6501 }, 6502 decode: function decodeString(data, offset) { 6503 var result = decodeDynamicBytesHelper(data, offset); // eslint-disable-line 6504 result.value = result.value.toString('utf8'); 6505 return result; 6506 }, 6507 dynamic: true 6508}; 6509 6510function coderArray(coder, lengthInput) { 6511 return { 6512 encode: function encodeArray(value) { 6513 var result = new Buffer(0); // eslint-disable-line 6514 var length = lengthInput; // eslint-disable-line 6515 6516 if (!Array.isArray(value)) { 6517 throw new Error('[ethjs-abi] while encoding array, invalid array data, not type Object (Array)'); 6518 } 6519 6520 if (length === -1) { 6521 length = value.length; 6522 result = uint256Coder.encode(length); 6523 } 6524 6525 if (length !== value.length) { 6526 throw new Error('[ethjs-abi] while encoding array, size mismatch array length ' + length + ' does not equal ' + value.length); 6527 } 6528 6529 value.forEach(function (resultValue) {
6530 result = Buffer.concat([result, coder.encode(resultValue)]); 6531 }); 6532 6533 return result; 6534 }, 6535 decode: function decodeArray(data, offsetInput) { 6536 var length = lengthInput; // eslint-disable-line 6537 var offset = offsetInput; // eslint-disable-line 6538 // @TODO: 6539 // if (data.length < offset + length * 32) { throw new Error('invalid array'); } 6540 6541 var consumed = 0; // eslint-disable-line 6542 var decodeResult; // eslint-disable-line 6543 6544 if (length === -1) { 6545 decodeResult = uint256Coder.decode(data, offset); 6546 length = decodeResult.value.toNumber(); 6547 consumed += decodeResult.consumed; 6548 offset += decodeResult.consumed; 6549 } 6550 6551 var value = []; // eslint-disable-line 6552 6553 for (var i = 0; i < length; i++) { 6554 // eslint-disable-line 6555 var loopResult = coder.decode(data, offset); 6556 consumed += loopResult.consumed; 6557 offset += loopResult.consumed; 6558 value.push(loopResult.value); 6559 } 6560 6561 return { 6562 consumed: consumed, 6563 value: value 6564 }; 6565 }, 6566 dynamic: lengthInput === -1 6567 }; 6568} 6569 6570// Break the type up into [staticType][staticArray]*[dynamicArray]? | [dynamicType] and 6571// build the coder up from its parts 6572var paramTypePart = new RegExp(/^((u?int|bytes)([0-9]*)|(address|bool|string)|(\[([0-9]*)\]))/); 6573 6574function getParamCoder(typeInput) { 6575 var type = typeInput; // eslint-disable-line 6576 var coder = null; // eslint-disable-line 6577 var invalidTypeErrorMessage = '[ethjs-abi] while getting param coder (getParamCoder) type value ' + JSON.stringify(type) + ' is either invalid or unsupported by ethjs-abi.'; 6578 6579 while (type) { 6580 var part = type.match(paramTypePart); // eslint-disable-line 6581 if (!part) { 6582 throw new Error(invalidTypeErrorMessage); 6583 } 6584 type = type.substring(part[0].length); 6585 6586 var prefix = part[2] || part[4] || part[5]; // eslint-disable-line 6587 switch (prefix) { 6588 case 'int':case 'uint': 6589 if (coder) { 6590 throw new Error(invalidTypeErrorMessage); 6591 } 6592 var intSize = parseInt(part[3] || 256); // eslint-disable-line 6593 if (intSize === 0 || intSize > 256 || intSize % 8 !== 0) { 6594 throw new Error('[ethjs-abi] while getting param coder for type ' + type + ', invalid ' + prefix + '<N> width: ' + type); 6595 } 6596 6597 coder = coderNumber(intSize / 8, prefix === 'int'); 6598 break; 6599 6600 case 'bool': 6601 if (coder) { 6602 throw new Error(invalidTypeErrorMessage); 6603 } 6604 coder = coderBoolean; 6605 break; 6606 6607 case 'string': 6608 if (coder) { 6609 throw new Error(invalidTypeErrorMessage); 6610 } 6611 coder = coderString; 6612 break; 6613 6614 case 'bytes': 6615 if (coder) { 6616 throw new Error(invalidTypeErrorMessage); 6617 } 6618 if (part[3]) { 6619 var size = parseInt(part[3]); // eslint-disable-line 6620 if (size === 0 || size > 32) { 6621 throw new Error('[ethjs-abi] while getting param coder for prefix bytes, invalid type ' + type + ', size ' + size + ' should be 0 or greater than 32'); 6622 } 6623 coder = coderFixedBytes(size); 6624 } else { 6625 coder = coderDynamicBytes; 6626 } 6627 break; 6628 6629 case 'address': 6630 if (coder) { 6631 throw new Error(invalidTypeErrorMessage); 6632 } 6633 coder = coderAddress; 6634 break; 6635 6636 case '[]': 6637 if (!coder || coder.dynamic) { 6638 throw new Error(invalidTypeErrorMessage); 6639 } 6640 coder = coderArray(coder, -1); 6641 break; 6642 6643 // "[0-9+]" 6644 default: 6645 if (!coder || coder.dynamic) { 6646 throw new Error(invalidTypeErrorMessage); 6647 } 6648 var defaultSize = parseInt(part[6]); // eslint-disable-line 6649 coder = coderArray(coder, defaultSize); 6650 } 6651 } 6652 6653 if (!coder) { 6654 throw new Error(invalidTypeErrorMessage); 6655 } 6656 return coder; 6657} 6658 6659module.exports = { 6660 BN: BN, 6661 bnToBuffer: bnToBuffer, 6662 isHexString: isHexString, 6663 hexOrBuffer: hexOrBuffer, 6664 hexlify: hexlify, 6665 stripZeros: stripZeros, 6666 6667 keccak256: keccak256, 6668 6669 getKeys: getKeys, 6670 numberToBN: numberToBN, 6671 coderNumber: coderNumber, 6672 uint256Coder: uint256Coder,
6673 coderBoolean: coderBoolean, 6674 coderFixedBytes: coderFixedBytes, 6675 coderAddress: coderAddress, 6676 coderDynamicBytes: coderDynamicBytes, 6677 coderString: coderString, 6678 coderArray: coderArray, 6679 paramTypePart: paramTypePart, 6680 getParamCoder: getParamCoder 6681}; 6682}).call(this,require("buffer").Buffer) 6683},{"bn.js":4,"buffer":6,"js-sha3":11,"number-to-bn":12}],9:[function(require,module,exports){ 6684exports.read = function (buffer, offset, isLE, mLen, nBytes) { 6685 var e, m 6686 var eLen = nBytes * 8 - mLen - 1 6687 var eMax = (1 << eLen) - 1 6688 var eBias = eMax >> 1 6689 var nBits = -7 6690 var i = isLE ? (nBytes - 1) : 0 6691 var d = isLE ? -1 : 1 6692 var s = buffer[offset + i] 6693 6694 i += d 6695 6696 e = s & ((1 << (-nBits)) - 1) 6697 s >>= (-nBits) 6698 nBits += eLen 6699 for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} 6700 6701 m = e & ((1 << (-nBits)) - 1) 6702 e >>= (-nBits) 6703 nBits += mLen 6704 for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} 6705 6706 if (e === 0) { 6707 e = 1 - eBias 6708 } else if (e === eMax) { 6709 return m ? NaN : ((s ? -1 : 1) * Infinity) 6710 } else { 6711 m = m + Math.pow(2, mLen) 6712 e = e - eBias 6713 } 6714 return (s ? -1 : 1) * m * Math.pow(2, e - mLen) 6715} 6716 6717exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { 6718 var e, m, c 6719 var eLen = nBytes * 8 - mLen - 1 6720 var eMax = (1 << eLen) - 1 6721 var eBias = eMax >> 1 6722 var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) 6723 var i = isLE ? 0 : (nBytes - 1) 6724 var d = isLE ? 1 : -1 6725 var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 6726 6727 value = Math.abs(value) 6728 6729 if (isNaN(value) || value === Infinity) { 6730 m = isNaN(value) ? 1 : 0 6731 e = eMax 6732 } else { 6733 e = Math.floor(Math.log(value) / Math.LN2) 6734 if (value * (c = Math.pow(2, -e)) < 1) { 6735 e-- 6736 c *= 2 6737 } 6738 if (e + eBias >= 1) { 6739 value += rt / c 6740 } else { 6741 value += rt * Math.pow(2, 1 - eBias) 6742 } 6743 if (value * c >= 2) { 6744 e++ 6745 c /= 2 6746 } 6747 6748 if (e + eBias >= eMax) { 6749 m = 0 6750 e = eMax 6751 } else if (e + eBias >= 1) { 6752 m = (value * c - 1) * Math.pow(2, mLen) 6753 e = e + eBias 6754 } else { 6755 m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) 6756 e = 0 6757 } 6758 } 6759 6760 for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} 6761 6762 e = (e << mLen) | m 6763 eLen += mLen 6764 for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} 6765 6766 buffer[offset + i - d] |= s * 128 6767} 6768 6769},{}],10:[function(require,module,exports){ 6770/** 6771 * Returns a `Boolean` on whether or not the a `String` starts with '0x' 6772 * @param {String} str the string input value 6773 * @return {Boolean} a boolean if it is or is not hex prefixed 6774 * @throws if the str input is not a string 6775 */ 6776module.exports = function isHexPrefixed(str) { 6777 if (typeof str !== 'string') { 6778 throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed."); 6779 } 6780 6781 return str.slice(0, 2) === '0x'; 6782} 6783 6784},{}],11:[function(require,module,exports){ 6785(function (process,global){ 6786/** 6787 * [js-sha3]{@link https://github.com/emn178/js-sha3} 6788 * 6789 * @version 0.5.5 6790 * @author Chen, Yi-Cyuan [[email protected]] 6791 * @copyright Chen, Yi-Cyuan 2015-2016 6792 * @license MIT 6793 */ 6794(function (root) { 6795 'use strict'; 6796 6797 var NODE_JS = typeof process == 'object' && process.versions && process.versions.node; 6798 if (NODE_JS) { 6799 root = global; 6800 } 6801 var COMMON_JS = !root.JS_SHA3_TEST && typeof module == 'object' && module.exports; 6802 var HEX_CHARS = '0123456789abcdef'.split(''); 6803 var SHAKE_PADDING = [31, 7936, 2031616, 520093696]; 6804 var KECCAK_PADDING = [1, 256, 65536, 16777216]; 6805 var PADDING = [6, 1536, 393216, 100663296]; 6806 var SHIFT = [0, 8, 16, 24]; 6807 var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 6808 0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0, 6809 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 6810 2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 6811 2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648]; 6812 var BITS = [224, 256, 384, 512]; 6813 var SHAKE_BITS = [128, 256]; 6814 var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array']; 6815 6816 var createOutputMethod = function (bits, padding, outputType) { 6817 return function (message) { 6818 return new Keccak(bits, padding, bits).update(message)[outputType](); 6819 } 6820 }; 6821 6822 var createShakeOutputMethod = function (bits, padding, outputType) { 6823 return function (message, outputBits) { 6824 return new Keccak(bits, padding, outputBits).update(message)[outputType](); 6825 } 6826 }; 6827 6828 var createMethod = function (bits, padding) { 6829 var method = createOutputMethod(bits, padding, 'hex'); 6830 method.create = function () { 6831 return new Keccak(bits, padding, bits); 6832 }; 6833 method.update = function (message) { 6834 return method.create().update(message); 6835 }; 6836 for (var i = 0;i < OUTPUT_TYPES.length;++i) { 6837 var type = OUTPUT_TYPES[i]; 6838 method[type] = createOutputMethod(bits, padding, type); 6839 } 6840 return method; 6841 }; 6842 6843 var createShakeMethod = function (bits, padding) { 6844 var method = createShakeOutputMethod(bits, padding, 'hex'); 6845 method.create = function (outputBits) { 6846 return new Keccak(bits, padding, outputBits); 6847 }; 6848 method.update = function (message, outputBits) { 6849 return method.create(outputBits).update(message); 6850 }; 6851 for (var i = 0;i < OUTPUT_TYPES.length;++i) { 6852 var type = OUTPUT_TYPES[i]; 6853 method[type] = createShakeOutputMethod(bits, padding, type); 6854 } 6855 return method; 6856 }; 6857 6858 var algorithms = [ 6859 {name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod}, 6860 {name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod},
6861 {name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod} 6862 ]; 6863 6864 var methods = {}; 6865 6866 for (var i = 0;i < algorithms.length;++i) { 6867 var algorithm = algorithms[i]; 6868 var bits = algorithm.bits; 6869 for (var j = 0;j < bits.length;++j) { 6870 methods[algorithm.name +'_' + bits[j]] = algorithm.createMethod(bits[j], algorithm.padding); 6871 } 6872 } 6873 6874 function Keccak(bits, padding, outputBits) { 6875 this.blocks = []; 6876 this.s = []; 6877 this.padding = padding; 6878 this.outputBits = outputBits; 6879 this.reset = true; 6880 this.block = 0; 6881 this.start = 0; 6882 this.blockCount = (1600 - (bits << 1)) >> 5; 6883 this.byteCount = this.blockCount << 2; 6884 this.outputBlocks = outputBits >> 5; 6885 this.extraBytes = (outputBits & 31) >> 3; 6886 6887 for (var i = 0;i < 50;++i) { 6888 this.s[i] = 0; 6889 } 6890 }; 6891 6892 Keccak.prototype.update = function (message) { 6893 var notString = typeof message != 'string'; 6894 if (notString && message.constructor == root.ArrayBuffer) { 6895 message = new Uint8Array(message); 6896 } 6897 var length = message.length, blocks = this.blocks, byteCount = this.byteCount, 6898 blockCount = this.blockCount, index = 0, s = this.s, i, code; 6899 6900 while (index < length) { 6901 if (this.reset) { 6902 this.reset = false; 6903 blocks[0] = this.block; 6904 for (i = 1;i < blockCount + 1;++i) { 6905 blocks[i] = 0; 6906 } 6907 } 6908 if (notString) { 6909 for (i = this.start;index < length && i < byteCount;++index) { 6910 blocks[i >> 2] |= message[index] << SHIFT[i++ & 3]; 6911 } 6912 } else { 6913 for (i = this.start;index < length && i < byteCount;++index) { 6914 code = message.charCodeAt(index); 6915 if (code < 0x80) { 6916 blocks[i >> 2] |= code << SHIFT[i++ & 3]; 6917 } else if (code < 0x800) { 6918 blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3]; 6919 blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 6920 } else if (code < 0xd800 || code >= 0xe000) { 6921 blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3]; 6922 blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; 6923 blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 6924 } else { 6925 code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff)); 6926 blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3]; 6927 blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3]; 6928 blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3]; 6929 blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3]; 6930 } 6931 } 6932 } 6933 this.lastByteIndex = i; 6934 if (i >= byteCount) { 6935 this.start = i - byteCount; 6936 this.block = blocks[blockCount]; 6937 for (i = 0;i < blockCount;++i) { 6938 s[i] ^= blocks[i]; 6939 } 6940 f(s); 6941 this.reset = true; 6942 } else { 6943 this.start = i; 6944 } 6945 } 6946 return this; 6947 }; 6948 6949 Keccak.prototype.finalize = function () { 6950 var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s; 6951 blocks[i >> 2] |= this.padding[i & 3]; 6952 if (this.lastByteIndex == this.byteCount) { 6953 blocks[0] = blocks[blockCount]; 6954 for (i = 1;i < blockCount + 1;++i) { 6955 blocks[i] = 0; 6956 } 6957 } 6958 blocks[blockCount - 1] |= 0x80000000; 6959 for (i = 0;i < blockCount;++i) { 6960 s[i] ^= blocks[i]; 6961 } 6962 f(s); 6963 }; 6964 6965 Keccak.prototype.toString = Keccak.prototype.hex = function () { 6966 this.finalize(); 6967 6968 var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 6969 extraBytes = this.extraBytes, i = 0, j = 0; 6970 var hex = '', block; 6971 while (j < outputBlocks) { 6972 for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) { 6973 block = s[i]; 6974 hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + 6975 HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] + 6976 HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] + 6977 HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F]; 6978 } 6979 if (j % blockCount == 0) { 6980 f(s); 6981 i = 0; 6982 } 6983 } 6984 if (extraBytes) { 6985 block = s[i]; 6986 if (extraBytes > 0) { 6987 hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F]; 6988 } 6989 if (extraBytes > 1) { 6990 hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F]; 6991 } 6992 if (extraBytes > 2) { 6993 hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F]; 6994 } 6995 } 6996 return hex; 6997 }; 6998 6999 Keccak.prototype.arrayBuffer = function () { 7000 this.finalize(); 7001 7002 var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 7003 extraBytes = this.extraBytes, i = 0, j = 0; 7004 var bytes = this.outputBits >> 3; 7005 var buffer; 7006 if (extraBytes) { 7007 buffer = new ArrayBuffer((outputBlocks + 1) << 2); 7008 } else { 7009 buffer = new ArrayBuffer(bytes); 7010 } 7011 var array = new Uint32Array(buffer); 7012 while (j < outputBlocks) { 7013 for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) { 7014 array[j] = s[i]; 7015 } 7016 if (j % blockCount == 0) { 7017 f(s); 7018 } 7019 } 7020 if (extraBytes) { 7021 array[i] = s[i]; 7022 buffer = buffer.slice(0, bytes); 7023 } 7024 return buffer; 7025 }; 7026 7027 Keccak.prototype.buffer = Keccak.prototype.arrayBuffer; 7028 7029 Keccak.prototype.digest = Keccak.prototype.array = function () { 7030 this.finalize(); 7031 7032 var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, 7033 extraBytes = this.extraBytes, i = 0, j = 0; 7034 var array = [], offset, block; 7035 while (j < outputBlocks) { 7036 for (i = 0;i < blockCount && j < outputBlocks;++i, ++j) { 7037 offset = j << 2; 7038 block = s[i]; 7039 array[offset] = block & 0xFF; 7040 array[offset + 1] = (block >> 8) & 0xFF; 7041 array[offset + 2] = (block >> 16) & 0xFF; 7042 array[offset + 3] = (block >> 24) & 0xFF; 7043 } 7044 if (j % blockCount == 0) { 7045 f(s); 7046 } 7047 } 7048 if (extraBytes) { 7049 offset = j << 2; 7050 block = s[i]; 7051 if (extraBytes > 0) { 7052 array[offset] = block & 0xFF; 7053 } 7054 if (extraBytes > 1) { 7055 array[offset + 1] = (block >> 8) & 0xFF; 7056 } 7057 if (extraBytes > 2) { 7058 array[offset + 2] = (block >> 16) & 0xFF; 7059 } 7060 } 7061 return array; 7062 }; 7063 7064 var f = function (s) { 7065 var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, 7066 b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, 7067 b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, 7068 b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49; 7069 for (n = 0;n < 48;n += 2) { 7070 c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40]; 7071 c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41]; 7072 c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42]; 7073 c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43]; 7074 c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44]; 7075 c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
vendor: 4,163 bytes, lines 7076-7209
7076 c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46]; 7077 c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47]; 7078 c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48]; 7079 c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49]; 7080 7081 h = c8 ^ ((c2 << 1) | (c3 >>> 31)); 7082 l = c9 ^ ((c3 << 1) | (c2 >>> 31)); 7083 s[0] ^= h; 7084 s[1] ^= l; 7085 s[10] ^= h; 7086 s[11] ^= l; 7087 s[20] ^= h; 7088 s[21] ^= l; 7089 s[30] ^= h; 7090 s[31] ^= l; 7091 s[40] ^= h; 7092 s[41] ^= l; 7093 h = c0 ^ ((c4 << 1) | (c5 >>> 31)); 7094 l = c1 ^ ((c5 << 1) | (c4 >>> 31)); 7095 s[2] ^= h; 7096 s[3] ^= l; 7097 s[12] ^= h; 7098 s[13] ^= l; 7099 s[22] ^= h; 7100 s[23] ^= l; 7101 s[32] ^= h; 7102 s[33] ^= l; 7103 s[42] ^= h; 7104 s[43] ^= l; 7105 h = c2 ^ ((c6 << 1) | (c7 >>> 31)); 7106 l = c3 ^ ((c7 << 1) | (c6 >>> 31)); 7107 s[4] ^= h; 7108 s[5] ^= l; 7109 s[14] ^= h; 7110 s[15] ^= l; 7111 s[24] ^= h; 7112 s[25] ^= l; 7113 s[34] ^= h; 7114 s[35] ^= l; 7115 s[44] ^= h; 7116 s[45] ^= l; 7117 h = c4 ^ ((c8 << 1) | (c9 >>> 31)); 7118 l = c5 ^ ((c9 << 1) | (c8 >>> 31)); 7119 s[6] ^= h; 7120 s[7] ^= l; 7121 s[16] ^= h; 7122 s[17] ^= l; 7123 s[26] ^= h; 7124 s[27] ^= l; 7125 s[36] ^= h; 7126 s[37] ^= l; 7127 s[46] ^= h; 7128 s[47] ^= l; 7129 h = c6 ^ ((c0 << 1) | (c1 >>> 31)); 7130 l = c7 ^ ((c1 << 1) | (c0 >>> 31)); 7131 s[8] ^= h; 7132 s[9] ^= l; 7133 s[18] ^= h; 7134 s[19] ^= l; 7135 s[28] ^= h; 7136 s[29] ^= l; 7137 s[38] ^= h; 7138 s[39] ^= l; 7139 s[48] ^= h; 7140 s[49] ^= l; 7141 7142 b0 = s[0]; 7143 b1 = s[1]; 7144 b32 = (s[11] << 4) | (s[10] >>> 28); 7145 b33 = (s[10] << 4) | (s[11] >>> 28); 7146 b14 = (s[20] << 3) | (s[21] >>> 29); 7147 b15 = (s[21] << 3) | (s[20] >>> 29); 7148 b46 = (s[31] << 9) | (s[30] >>> 23); 7149 b47 = (s[30] << 9) | (s[31] >>> 23); 7150 b28 = (s[40] << 18) | (s[41] >>> 14); 7151 b29 = (s[41] << 18) | (s[40] >>> 14); 7152 b20 = (s[2] << 1) | (s[3] >>> 31); 7153 b21 = (s[3] << 1) | (s[2] >>> 31); 7154 b2 = (s[13] << 12) | (s[12] >>> 20); 7155 b3 = (s[12] << 12) | (s[13] >>> 20); 7156 b34 = (s[22] << 10) | (s[23] >>> 22); 7157 b35 = (s[23] << 10) | (s[22] >>> 22); 7158 b16 = (s[33] << 13) | (s[32] >>> 19); 7159 b17 = (s[32] << 13) | (s[33] >>> 19); 7160 b48 = (s[42] << 2) | (s[43] >>> 30); 7161 b49 = (s[43] << 2) | (s[42] >>> 30); 7162 b40 = (s[5] << 30) | (s[4] >>> 2); 7163 b41 = (s[4] << 30) | (s[5] >>> 2); 7164 b22 = (s[14] << 6) | (s[15] >>> 26); 7165 b23 = (s[15] << 6) | (s[14] >>> 26); 7166 b4 = (s[25] << 11) | (s[24] >>> 21); 7167 b5 = (s[24] << 11) | (s[25] >>> 21); 7168 b36 = (s[34] << 15) | (s[35] >>> 17); 7169 b37 = (s[35] << 15) | (s[34] >>> 17); 7170 b18 = (s[45] << 29) | (s[44] >>> 3); 7171 b19 = (s[44] << 29) | (s[45] >>> 3); 7172 b10 = (s[6] << 28) | (s[7] >>> 4); 7173 b11 = (s[7] << 28) | (s[6] >>> 4); 7174 b42 = (s[17] << 23) | (s[16] >>> 9); 7175 b43 = (s[16] << 23) | (s[17] >>> 9); 7176 b24 = (s[26] << 25) | (s[27] >>> 7); 7177 b25 = (s[27] << 25) | (s[26] >>> 7); 7178 b6 = (s[36] << 21) | (s[37] >>> 11); 7179 b7 = (s[37] << 21) | (s[36] >>> 11); 7180 b38 = (s[47] << 24) | (s[46] >>> 8); 7181 b39 = (s[46] << 24) | (s[47] >>> 8); 7182 b30 = (s[8] << 27) | (s[9] >>> 5); 7183 b31 = (s[9] << 27) | (s[8] >>> 5); 7184 b12 = (s[18] << 20) | (s[19] >>> 12); 7185 b13 = (s[19] << 20) | (s[18] >>> 12); 7186 b44 = (s[29] << 7) | (s[28] >>> 25); 7187 b45 = (s[28] << 7) | (s[29] >>> 25); 7188 b26 = (s[38] << 8) | (s[39] >>> 24); 7189 b27 = (s[39] << 8) | (s[38] >>> 24); 7190 b8 = (s[48] << 14) | (s[49] >>> 18); 7191 b9 = (s[49] << 14) | (s[48] >>> 18); 7192 7193 s[0] = b0 ^ (~b2 & b4); 7194 s[1] = b1 ^ (~b3 & b5); 7195 s[10] = b10 ^ (~b12 & b14); 7196 s[11] = b11 ^ (~b13 & b15); 7197 s[20] = b20 ^ (~b22 & b24); 7198 s[21] = b21 ^ (~b23 & b25); 7199 s[30] = b30 ^ (~b32 & b34); 7200 s[31] = b31 ^ (~b33 & b35); 7201 s[40] = b40 ^ (~b42 & b44); 7202 s[41] = b41 ^ (~b43 & b45); 7203 s[2] = b2 ^ (~b4 & b6); 7204 s[3] = b3 ^ (~b5 & b7); 7205 s[12] = b12 ^ (~b14 & b16); 7206 s[13] = b13 ^ (~b15 & b17); 7207 s[22] = b22 ^ (~b24 & b26); 7208 s[23] = b23 ^ (~b25 & b27); 7209 s[32] = b32 ^ (~b34 & b36);
7210 s[33] = b33 ^ (~b35 & b37); 7211 s[42] = b42 ^ (~b44 & b46); 7212 s[43] = b43 ^ (~b45 & b47); 7213 s[4] = b4 ^ (~b6 & b8); 7214 s[5] = b5 ^ (~b7 & b9); 7215 s[14] = b14 ^ (~b16 & b18); 7216 s[15] = b15 ^ (~b17 & b19); 7217 s[24] = b24 ^ (~b26 & b28); 7218 s[25] = b25 ^ (~b27 & b29); 7219 s[34] = b34 ^ (~b36 & b38); 7220 s[35] = b35 ^ (~b37 & b39); 7221 s[44] = b44 ^ (~b46 & b48); 7222 s[45] = b45 ^ (~b47 & b49); 7223 s[6] = b6 ^ (~b8 & b0); 7224 s[7] = b7 ^ (~b9 & b1); 7225 s[16] = b16 ^ (~b18 & b10); 7226 s[17] = b17 ^ (~b19 & b11); 7227 s[26] = b26 ^ (~b28 & b20); 7228 s[27] = b27 ^ (~b29 & b21); 7229 s[36] = b36 ^ (~b38 & b30); 7230 s[37] = b37 ^ (~b39 & b31); 7231 s[46] = b46 ^ (~b48 & b40); 7232 s[47] = b47 ^ (~b49 & b41); 7233 s[8] = b8 ^ (~b0 & b2); 7234 s[9] = b9 ^ (~b1 & b3); 7235 s[18] = b18 ^ (~b10 & b12); 7236 s[19] = b19 ^ (~b11 & b13); 7237 s[28] = b28 ^ (~b20 & b22); 7238 s[29] = b29 ^ (~b21 & b23); 7239 s[38] = b38 ^ (~b30 & b32); 7240 s[39] = b39 ^ (~b31 & b33); 7241 s[48] = b48 ^ (~b40 & b42); 7242 s[49] = b49 ^ (~b41 & b43); 7243 7244 s[0] ^= RC[n]; 7245 s[1] ^= RC[n + 1]; 7246 } 7247 } 7248 7249 if (COMMON_JS) { 7250 module.exports = methods; 7251 } else if (root) { 7252 for (var key in methods) { 7253 root[key] = methods[key]; 7254 } 7255 } 7256}(this)); 7257 7258}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) 7259},{"_process":13}],12:[function(require,module,exports){ 7260var BN = require('bn.js'); 7261var stripHexPrefix = require('strip-hex-prefix'); 7262 7263/** 7264 * Returns a BN object, converts a number value to a BN 7265 * @param {String|Number|Object} `arg` input a string number, hex string number, number, BigNumber or BN object 7266 * @return {Object} `output` BN object of the number 7267 * @throws if the argument is not an array, object that isn't a bignumber, not a string number or number 7268 */ 7269module.exports = function numberToBN(arg) { 7270 if (typeof arg === 'string' || typeof arg === 'number') { 7271 var multiplier = new BN(1); // eslint-disable-line 7272 var formattedString = String(arg).toLowerCase().trim(); 7273 var isHexPrefixed = formattedString.substr(0, 2) === '0x' || formattedString.substr(0, 3) === '-0x'; 7274 var stringArg = stripHexPrefix(formattedString); // eslint-disable-line 7275 if (stringArg.substr(0, 1) === '-') { 7276 stringArg = stripHexPrefix(stringArg.slice(1)); 7277 multiplier = new BN(-1, 10); 7278 } 7279 stringArg = stringArg === '' ? '0' : stringArg; 7280 7281 if ((!stringArg.match(/^-?[0-9]+$/) && stringArg.match(/^[0-9A-Fa-f]+$/)) 7282 || stringArg.match(/^[a-fA-F]+$/) 7283 || (isHexPrefixed === true && stringArg.match(/^[0-9A-Fa-f]+$/))) { 7284 return new BN(stringArg, 16).mul(multiplier); 7285 } 7286 7287 if ((stringArg.match(/^-?[0-9]+$/) || stringArg === '') && isHexPrefixed === false) { 7288 return new BN(stringArg, 10).mul(multiplier); 7289 } 7290 } else if (typeof arg === 'object' && arg.toString && (!arg.pop && !arg.push)) { 7291 if (arg.toString(10).match(/^-?[0-9]+$/) && (arg.mul || arg.dividedToIntegerBy)) { 7292 return new BN(arg.toString(10), 10); 7293 } 7294 } 7295 7296 throw new Error('[number-to-bn] while converting number ' + JSON.stringify(arg) + ' to BN.js instance, error: invalid number value. Value must be an integer, hex string, BN or BigNumber instance. Note, decimals are not supported.'); 7297} 7298 7299},{"bn.js":4,"strip-hex-prefix":14}],13:[function(require,module,exports){ 7300// shim for using process in browser 7301var process = module.exports = {}; 7302 7303// cached from whatever global is present so that test runners that stub it 7304// don't break things. But we need to wrap it in a try catch in case it is 7305// wrapped in strict mode code which doesn't define any globals. It's inside a 7306// function because try/catches deoptimize in certain engines. 7307 7308var cachedSetTimeout; 7309var cachedClearTimeout; 7310 7311function defaultSetTimout() { 7312 throw new Error('setTimeout has not been defined'); 7313} 7314function defaultClearTimeout () { 7315 throw new Error('clearTimeout has not been defined'); 7316} 7317(function () { 7318 try { 7319 if (typeof setTimeout === 'function') { 7320 cachedSetTimeout = setTimeout; 7321 } else { 7322 cachedSetTimeout = defaultSetTimout; 7323 } 7324 } catch (e) { 7325 cachedSetTimeout = defaultSetTimout; 7326 } 7327 try { 7328 if (typeof clearTimeout === 'function') { 7329 cachedClearTimeout = clearTimeout; 7330 } else { 7331 cachedClearTimeout = defaultClearTimeout; 7332 } 7333 } catch (e) { 7334 cachedClearTimeout = defaultClearTimeout; 7335 } 7336} ()) 7337function runTimeout(fun) { 7338 if (cachedSetTimeout === setTimeout) { 7339 //normal enviroments in sane situations 7340 return setTimeout(fun, 0); 7341 } 7342 // if setTimeout wasn't available but was latter defined 7343 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { 7344 cachedSetTimeout = setTimeout; 7345 return setTimeout(fun, 0); 7346 } 7347 try { 7348 // when when somebody has screwed with setTimeout but no I.E. maddness 7349 return cachedSetTimeout(fun, 0); 7350 } catch(e){ 7351 try { 7352 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 7353 return cachedSetTimeout.call(null, fun, 0); 7354 } catch(e){ 7355 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error 7356 return cachedSetTimeout.call(this, fun, 0); 7357 } 7358 } 7359 7360 7361} 7362function runClearTimeout(marker) { 7363 if (cachedClearTimeout === clearTimeout) { 7364 //normal enviroments in sane situations 7365 return clearTimeout(marker); 7366 } 7367 // if clearTimeout wasn't available but was latter defined 7368 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { 7369 cachedClearTimeout = clearTimeout; 7370 return clearTimeout(marker); 7371 } 7372 try { 7373 // when when somebody has screwed with setTimeout but no I.E. maddness 7374 return cachedClearTimeout(marker); 7375 } catch (e){ 7376 try { 7377 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally 7378 return cachedClearTimeout.call(null, marker); 7379 } catch (e){ 7380 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. 7381 // Some versions of I.E. have different rules for clearTimeout vs setTimeout 7382 return cachedClearTimeout.call(this, marker); 7383 } 7384 } 7385 7386 7387 7388} 7389var queue = []; 7390var draining = false;
7391var currentQueue; 7392var queueIndex = -1; 7393 7394function cleanUpNextTick() { 7395 if (!draining || !currentQueue) { 7396 return; 7397 } 7398 draining = false; 7399 if (currentQueue.length) { 7400 queue = currentQueue.concat(queue); 7401 } else { 7402 queueIndex = -1; 7403 } 7404 if (queue.length) { 7405 drainQueue(); 7406 } 7407} 7408 7409function drainQueue() { 7410 if (draining) { 7411 return; 7412 } 7413 var timeout = runTimeout(cleanUpNextTick); 7414 draining = true; 7415 7416 var len = queue.length; 7417 while(len) { 7418 currentQueue = queue; 7419 queue = []; 7420 while (++queueIndex < len) { 7421 if (currentQueue) { 7422 currentQueue[queueIndex].run(); 7423 } 7424 } 7425 queueIndex = -1; 7426 len = queue.length; 7427 } 7428 currentQueue = null; 7429 draining = false; 7430 runClearTimeout(timeout); 7431} 7432 7433process.nextTick = function (fun) { 7434 var args = new Array(arguments.length - 1); 7435 if (arguments.length > 1) { 7436 for (var i = 1; i < arguments.length; i++) { 7437 args[i - 1] = arguments[i]; 7438 } 7439 } 7440 queue.push(new Item(fun, args)); 7441 if (queue.length === 1 && !draining) { 7442 runTimeout(drainQueue); 7443 } 7444}; 7445 7446// v8 likes predictible objects 7447function Item(fun, array) { 7448 this.fun = fun; 7449 this.array = array; 7450} 7451Item.prototype.run = function () { 7452 this.fun.apply(null, this.array); 7453}; 7454process.title = 'browser'; 7455process.browser = true; 7456process.env = {}; 7457process.argv = []; 7458process.version = ''; // empty string to avoid regexp issues 7459process.versions = {}; 7460 7461function noop() {} 7462 7463process.on = noop; 7464process.addListener = noop; 7465process.once = noop; 7466process.off = noop; 7467process.removeListener = noop; 7468process.removeAllListeners = noop; 7469process.emit = noop; 7470 7471process.binding = function (name) { 7472 throw new Error('process.binding is not supported'); 7473}; 7474 7475process.cwd = function () { return '/' }; 7476process.chdir = function (dir) { 7477 throw new Error('process.chdir is not supported'); 7478}; 7479process.umask = function() { return 0; }; 7480 7481},{}],14:[function(require,module,exports){ 7482var isHexPrefixed = require('is-hex-prefixed'); 7483 7484/** 7485 * Removes '0x' from a given `String` is present 7486 * @param {String} str the string value 7487 * @return {String|Optional} a string by pass if necessary 7488 */ 7489module.exports = function stripHexPrefix(str) { 7490 if (typeof str !== 'string') { 7491 return str; 7492 } 7493 7494 return isHexPrefixed(str) ? str.slice(2) : str; 7495} 7496 7497},{"is-hex-prefixed":10}],15:[function(require,module,exports){ 7498// TODO: remove web3 requirement 7499// Call functions directly on the provider. 7500var Web3 = require("web3"); 7501 7502var Blockchain = { 7503 parse: function(uri) { 7504 var parsed = {}; 7505 if (uri.indexOf("blockchain://") != 0) return parsed; 7506 7507 uri = uri.replace("blockchain://", ""); 7508 7509 var pieces = uri.split("/block/"); 7510 7511 parsed.genesis_hash = "0x" + pieces[0]; 7512 parsed.block_hash = "0x" + pieces[1]; 7513 7514 return parsed; 7515 }, 7516 7517 asURI: function(provider, callback) { 7518 var web3 = new Web3(provider); 7519 7520 web3.eth.getBlock(0, function(err, genesis) { 7521 if (err) return callback(err); 7522 7523 web3.eth.getBlock("latest", function(err, latest) { 7524 if (err) return callback(err); 7525 7526 var url = "blockchain://" + genesis.hash.replace("0x", "") + "/block/" + latest.hash.replace("0x", ""); 7527 7528 callback(null, url); 7529 }); 7530 }); 7531 }, 7532 7533 matches: function(uri, provider, callback) { 7534 uri = this.parse(uri); 7535 7536 var expected_genesis = uri.genesis_hash; 7537 var expected_block = uri.block_hash; 7538 7539 var web3 = new Web3(provider); 7540 7541 web3.eth.getBlock(0, function(err, block) { 7542 if (err) return callback(err); 7543 if (block.hash != expected_genesis) return callback(null, false); 7544 7545 web3.eth.getBlock(expected_block, function(err, block) { 7546 // Treat an error as if the block didn't exist. This is because 7547 // some clients respond differently. 7548 if (err || block == null) { 7549 return callback(null, false); 7550 } 7551 7552 callback(null, true); 7553 }); 7554 }); 7555 } 7556}; 7557 7558module.exports = Blockchain; 7559 7560},{"web3":5}],16:[function(require,module,exports){ 7561var sha3 = require("crypto-js/sha3"); 7562var schema_version = require("./package.json").version; 7563 7564var TruffleSchema = { 7565 // Normalize options passed in to be the exact options required 7566 // for truffle-contract. 7567 // 7568 // options can be three things: 7569 // - normal object 7570 // - contract object 7571 // - solc output 7572 // 7573 // TODO: Is extra_options still necessary? 7574 normalizeOptions: function(options, extra_options) { 7575 extra_options = extra_options || {}; 7576 var normalized = {}; 7577 var expected_keys = [ 7578 "contract_name", 7579 "abi", 7580 "binary", 7581 "unlinked_binary", 7582 "address", 7583 "networks", 7584 "links", 7585 "events", 7586 "network_id", 7587 "default_network", 7588 "updated_at" 7589 ]; 7590 7591 // Merge options/contract object first, then extra_options 7592 expected_keys.forEach(function(key) { 7593 var value; 7594
7595 try { 7596 // Will throw an error if key == address and address doesn't exist. 7597 value = options[key]; 7598 7599 if (value != undefined) { 7600 normalized[key] = value; 7601 } 7602 } catch (e) { 7603 // Do nothing. 7604 } 7605 7606 try { 7607 // Will throw an error if key == address and address doesn't exist. 7608 value = extra_options[key]; 7609 7610 if (value != undefined) { 7611 normalized[key] = value; 7612 } 7613 } catch (e) { 7614 // Do nothing. 7615 } 7616 }); 7617 7618 // Now look for solc specific items. 7619 if (options.interface != null) { 7620 normalized.abi = JSON.parse(options.interface); 7621 } 7622 7623 if (options.bytecode != null) { 7624 normalized.unlinked_binary = options.bytecode 7625 } 7626 7627 // Assume any binary passed is the unlinked binary 7628 if (normalized.unlinked_binary == null && normalized.binary) { 7629 normalized.unlinked_binary = normalized.binary; 7630 } 7631 7632 delete normalized.binary; 7633 7634 this.copyCustomOptions(options, normalized); 7635 7636 return normalized; 7637 }, 7638 7639 // Generate a proper binary from normalized options, and optionally 7640 // merge it with an existing binary. 7641 generateBinary: function(options, existing_binary, extra_options) { 7642 extra_options = extra_options || {}; 7643 7644 existing_binary = existing_binary || {}; 7645 7646 if (options.overwrite == true) { 7647 existing_binary = {}; 7648 } 7649 7650 existing_binary.contract_name = options.contract_name || existing_binary.contract_name || "Contract"; 7651 existing_binary.default_network = options.default_network || existing_binary.default_network; 7652 7653 existing_binary.abi = options.abi || existing_binary.abi; 7654 existing_binary.unlinked_binary = options.unlinked_binary || existing_binary.unlinked_binary; 7655 7656 // Ensure unlinked binary starts with a 0x 7657 if (existing_binary.unlinked_binary && existing_binary.unlinked_binary.indexOf("0x") < 0) { 7658 existing_binary.unlinked_binary = "0x" + existing_binary.unlinked_binary; 7659 } 7660 7661 // Merge existing networks with any passed in networks. 7662 existing_binary.networks = existing_binary.networks || {}; 7663 options.networks = options.networks || {}; 7664 Object.keys(options.networks).forEach(function(network_id) { 7665 existing_binary.networks[network_id] = options.networks[network_id]; 7666 }); 7667 7668 var updated_at = new Date().getTime(); 7669 7670 if (options.network_id) { 7671 // Ensure an object exists for this network. 7672 existing_binary.networks[options.network_id] = existing_binary.networks[options.network_id] || {}; 7673 7674 var network = existing_binary.networks[options.network_id]; 7675 7676 // Override specific keys 7677 network.address = options.address || network.address; 7678 network.links = options.links; 7679 7680 // merge events with any that previously existed 7681 network.events = network.events || {}; 7682 options.events = options.events || {}; 7683 Object.keys(options.events).forEach(function(event_id) { 7684 options.events[event_id] = options.events[event_id]; 7685 }); 7686 7687 // Now overwrite any events with the most recent data from the ABI. 7688 existing_binary.abi.forEach(function(item) { 7689 if (item.type != "event") return; 7690 7691 var signature = item.name + "(" + item.inputs.map(function(param) {return param.type;}).join(",") + ")"; 7692 network.events["0x" + sha3(signature, {outputLength: 256})] = item; 7693 }); 7694 7695 if (extra_options.dirty !== false) { 7696 network.updated_at = updated_at; 7697 } 7698 } else { 7699 if (options.address) { 7700 throw new Error("Cannot set address without network id"); 7701 } 7702 } 7703 7704 // Ensure all networks have a `links` object. 7705 Object.keys(existing_binary.networks).forEach(function(network_id) { 7706 var network = existing_binary.networks[network_id]; 7707 network.links = network.links || {}; 7708 }); 7709 7710 existing_binary.schema_version = schema_version; 7711 7712 if (extra_options.dirty !== false) { 7713 existing_binary.updated_at = updated_at; 7714 } else { 7715 existing_binary.updated_at = options.updated_at || existing_binary.updated_at || updated_at; 7716 } 7717 7718 this.copyCustomOptions(options, existing_binary); 7719 7720 return existing_binary; 7721 }, 7722 7723 copyCustomOptions: function(from, to) { 7724 // Now let all x- options through. 7725 Object.keys(from).forEach(function(key) { 7726 if (key.indexOf("x-") != 0) return; 7727
7728 try { 7729 value = from[key]; 7730 7731 if (value != undefined) { 7732 to[key] = value; 7733 } 7734 } catch (e) { 7735 // Do nothing. 7736 } 7737 }); 7738 } 7739}; 7740 7741module.exports = TruffleSchema; 7742 7743},{"./package.json":20,"crypto-js/sha3":18}],17:[function(require,module,exports){ 7744;(function (root, factory) { 7745 if (typeof exports === "object") { 7746 // CommonJS 7747 module.exports = exports = factory(); 7748 } 7749 else if (typeof define === "function" && define.amd) { 7750 // AMD 7751 define([], factory); 7752 } 7753 else { 7754 // Global (browser) 7755 root.CryptoJS = factory(); 7756 } 7757}(this, function () { 7758 7759 /** 7760 * CryptoJS core components. 7761 */ 7762 var CryptoJS = CryptoJS || (function (Math, undefined) { 7763 /* 7764 * Local polyfil of Object.create 7765 */ 7766 var create = Object.create || (function () { 7767 function F() {}; 7768 7769 return function (obj) { 7770 var subtype; 7771 7772 F.prototype = obj; 7773 7774 subtype = new F(); 7775 7776 F.prototype = null; 7777 7778 return subtype; 7779 }; 7780 }()) 7781 7782 /** 7783 * CryptoJS namespace. 7784 */ 7785 var C = {}; 7786 7787 /** 7788 * Library namespace. 7789 */ 7790 var C_lib = C.lib = {}; 7791 7792 /** 7793 * Base object for prototypal inheritance. 7794 */ 7795 var Base = C_lib.Base = (function () { 7796 7797 7798 return { 7799 /** 7800 * Creates a new object that inherits from this object. 7801 * 7802 * @param {Object} overrides Properties to copy into the new object. 7803 * 7804 * @return {Object} The new object. 7805 * 7806 * @static 7807 * 7808 * @example 7809 * 7810 * var MyType = CryptoJS.lib.Base.extend({ 7811 * field: 'value', 7812 * 7813 * method: function () { 7814 * } 7815 * }); 7816 */ 7817 extend: function (overrides) { 7818 // Spawn 7819 var subtype = create(this); 7820 7821 // Augment 7822 if (overrides) { 7823 subtype.mixIn(overrides); 7824 } 7825 7826 // Create default initializer 7827 if (!subtype.hasOwnProperty('init') || this.init === subtype.init) { 7828 subtype.init = function () { 7829 subtype.$super.init.apply(this, arguments); 7830 }; 7831 } 7832 7833 // Initializer's prototype is the subtype object 7834 subtype.init.prototype = subtype; 7835 7836 // Reference supertype 7837 subtype.$super = this; 7838 7839 return subtype; 7840 }, 7841 7842 /** 7843 * Extends this object and runs the init method. 7844 * Arguments to create() will be passed to init(). 7845 * 7846 * @return {Object} The new object. 7847 * 7848 * @static 7849 * 7850 * @example 7851 * 7852 * var instance = MyType.create(); 7853 */ 7854 create: function () { 7855 var instance = this.extend(); 7856 instance.init.apply(instance, arguments); 7857 7858 return instance; 7859 }, 7860 7861 /** 7862 * Initializes a newly created object. 7863 * Override this method to add some logic when your objects are created. 7864 * 7865 * @example 7866 * 7867 * var MyType = CryptoJS.lib.Base.extend({ 7868 * init: function () { 7869 * // ... 7870 * } 7871 * }); 7872 */ 7873 init: function () { 7874 }, 7875 7876 /** 7877 * Copies properties into this object. 7878 * 7879 * @param {Object} properties The properties to mix in. 7880 * 7881 * @example 7882 * 7883 * MyType.mixIn({ 7884 * field: 'value' 7885 * }); 7886 */ 7887 mixIn: function (properties) { 7888 for (var propertyName in properties) { 7889 if (properties.hasOwnProperty(propertyName)) { 7890 this[propertyName] = properties[propertyName]; 7891 } 7892 } 7893 7894 // IE won't copy toString using the loop above 7895 if (properties.hasOwnProperty('toString')) { 7896 this.toString = properties.toString; 7897 } 7898 }, 7899 7900 /** 7901 * Creates a copy of this object. 7902 * 7903 * @return {Object} The clone. 7904 * 7905 * @example 7906 * 7907 * var clone = instance.clone(); 7908 */ 7909 clone: function () { 7910 return this.init.prototype.extend(this); 7911 } 7912 }; 7913 }()); 7914 7915 /** 7916 * An array of 32-bit words. 7917 * 7918 * @property {Array} words The array of 32-bit words. 7919 * @property {number} sigBytes The number of significant bytes in this word array.
vendor: 4,927 bytes, lines 7920-8069
7920 */ 7921 var WordArray = C_lib.WordArray = Base.extend({ 7922 /** 7923 * Initializes a newly created word array. 7924 * 7925 * @param {Array} words (Optional) An array of 32-bit words. 7926 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 7927 * 7928 * @example 7929 * 7930 * var wordArray = CryptoJS.lib.WordArray.create(); 7931 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]); 7932 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6); 7933 */ 7934 init: function (words, sigBytes) { 7935 words = this.words = words || []; 7936 7937 if (sigBytes != undefined) { 7938 this.sigBytes = sigBytes; 7939 } else { 7940 this.sigBytes = words.length * 4; 7941 } 7942 }, 7943 7944 /** 7945 * Converts this word array to a string. 7946 * 7947 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex 7948 * 7949 * @return {string} The stringified word array. 7950 * 7951 * @example 7952 * 7953 * var string = wordArray + ''; 7954 * var string = wordArray.toString(); 7955 * var string = wordArray.toString(CryptoJS.enc.Utf8); 7956 */ 7957 toString: function (encoder) { 7958 return (encoder || Hex).stringify(this); 7959 }, 7960 7961 /** 7962 * Concatenates a word array to this word array. 7963 * 7964 * @param {WordArray} wordArray The word array to append. 7965 * 7966 * @return {WordArray} This word array. 7967 * 7968 * @example 7969 * 7970 * wordArray1.concat(wordArray2); 7971 */ 7972 concat: function (wordArray) { 7973 // Shortcuts 7974 var thisWords = this.words; 7975 var thatWords = wordArray.words; 7976 var thisSigBytes = this.sigBytes; 7977 var thatSigBytes = wordArray.sigBytes; 7978 7979 // Clamp excess bits 7980 this.clamp(); 7981 7982 // Concat 7983 if (thisSigBytes % 4) { 7984 // Copy one byte at a time 7985 for (var i = 0; i < thatSigBytes; i++) { 7986 var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 7987 thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8); 7988 } 7989 } else { 7990 // Copy one word at a time 7991 for (var i = 0; i < thatSigBytes; i += 4) { 7992 thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2]; 7993 } 7994 } 7995 this.sigBytes += thatSigBytes; 7996 7997 // Chainable 7998 return this; 7999 }, 8000 8001 /** 8002 * Removes insignificant bits. 8003 * 8004 * @example 8005 * 8006 * wordArray.clamp(); 8007 */ 8008 clamp: function () { 8009 // Shortcuts 8010 var words = this.words; 8011 var sigBytes = this.sigBytes; 8012 8013 // Clamp 8014 words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8); 8015 words.length = Math.ceil(sigBytes / 4); 8016 }, 8017 8018 /** 8019 * Creates a copy of this word array. 8020 * 8021 * @return {WordArray} The clone. 8022 * 8023 * @example 8024 * 8025 * var clone = wordArray.clone(); 8026 */ 8027 clone: function () { 8028 var clone = Base.clone.call(this); 8029 clone.words = this.words.slice(0); 8030 8031 return clone; 8032 }, 8033 8034 /** 8035 * Creates a word array filled with random bytes. 8036 * 8037 * @param {number} nBytes The number of random bytes to generate. 8038 * 8039 * @return {WordArray} The random word array. 8040 * 8041 * @static 8042 * 8043 * @example 8044 * 8045 * var wordArray = CryptoJS.lib.WordArray.random(16); 8046 */ 8047 random: function (nBytes) { 8048 var words = []; 8049 8050 var r = (function (m_w) { 8051 var m_w = m_w; 8052 var m_z = 0x3ade68b1; 8053 var mask = 0xffffffff; 8054 8055 return function () { 8056 m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; 8057 m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; 8058 var result = ((m_z << 0x10) + m_w) & mask; 8059 result /= 0x100000000; 8060 result += 0.5; 8061 return result * (Math.random() > .5 ? 1 : -1); 8062 } 8063 }); 8064 8065 for (var i = 0, rcache; i < nBytes; i += 4) { 8066 var _r = r((rcache || Math.random()) * 0x100000000); 8067 8068 rcache = _r() * 0x3ade67b7; 8069 words.push((_r() * 0x100000000) | 0
vendor: 6,794 bytes, lines 8069-8300
8069); 8070 } 8071 8072 return new WordArray.init(words, nBytes); 8073 } 8074 }); 8075 8076 /** 8077 * Encoder namespace. 8078 */ 8079 var C_enc = C.enc = {}; 8080 8081 /** 8082 * Hex encoding strategy. 8083 */ 8084 var Hex = C_enc.Hex = { 8085 /** 8086 * Converts a word array to a hex string. 8087 * 8088 * @param {WordArray} wordArray The word array. 8089 * 8090 * @return {string} The hex string. 8091 * 8092 * @static 8093 * 8094 * @example 8095 * 8096 * var hexString = CryptoJS.enc.Hex.stringify(wordArray); 8097 */ 8098 stringify: function (wordArray) { 8099 // Shortcuts 8100 var words = wordArray.words; 8101 var sigBytes = wordArray.sigBytes; 8102 8103 // Convert 8104 var hexChars = []; 8105 for (var i = 0; i < sigBytes; i++) { 8106 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8107 hexChars.push((bite >>> 4).toString(16)); 8108 hexChars.push((bite & 0x0f).toString(16)); 8109 } 8110 8111 return hexChars.join(''); 8112 }, 8113 8114 /** 8115 * Converts a hex string to a word array. 8116 * 8117 * @param {string} hexStr The hex string. 8118 * 8119 * @return {WordArray} The word array. 8120 * 8121 * @static 8122 * 8123 * @example 8124 * 8125 * var wordArray = CryptoJS.enc.Hex.parse(hexString); 8126 */ 8127 parse: function (hexStr) { 8128 // Shortcut 8129 var hexStrLength = hexStr.length; 8130 8131 // Convert 8132 var words = []; 8133 for (var i = 0; i < hexStrLength; i += 2) { 8134 words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); 8135 } 8136 8137 return new WordArray.init(words, hexStrLength / 2); 8138 } 8139 }; 8140 8141 /** 8142 * Latin1 encoding strategy. 8143 */ 8144 var Latin1 = C_enc.Latin1 = { 8145 /** 8146 * Converts a word array to a Latin1 string. 8147 * 8148 * @param {WordArray} wordArray The word array. 8149 * 8150 * @return {string} The Latin1 string. 8151 * 8152 * @static 8153 * 8154 * @example 8155 * 8156 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray); 8157 */ 8158 stringify: function (wordArray) { 8159 // Shortcuts 8160 var words = wordArray.words; 8161 var sigBytes = wordArray.sigBytes; 8162 8163 // Convert 8164 var latin1Chars = []; 8165 for (var i = 0; i < sigBytes; i++) { 8166 var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; 8167 latin1Chars.push(String.fromCharCode(bite)); 8168 } 8169 8170 return latin1Chars.join(''); 8171 }, 8172 8173 /** 8174 * Converts a Latin1 string to a word array. 8175 * 8176 * @param {string} latin1Str The Latin1 string. 8177 * 8178 * @return {WordArray} The word array. 8179 * 8180 * @static 8181 * 8182 * @example 8183 * 8184 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String); 8185 */ 8186 parse: function (latin1Str) { 8187 // Shortcut 8188 var latin1StrLength = latin1Str.length; 8189 8190 // Convert 8191 var words = []; 8192 for (var i = 0; i < latin1StrLength; i++) { 8193 words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); 8194 } 8195 8196 return new WordArray.init(words, latin1StrLength); 8197 } 8198 }; 8199 8200 /** 8201 * UTF-8 encoding strategy. 8202 */ 8203 var Utf8 = C_enc.Utf8 = { 8204 /** 8205 * Converts a word array to a UTF-8 string. 8206 * 8207 * @param {WordArray} wordArray The word array. 8208 * 8209 * @return {string} The UTF-8 string. 8210 * 8211 * @static 8212 * 8213 * @example 8214 * 8215 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray); 8216 */ 8217 stringify: function (wordArray) { 8218 try { 8219 return decodeURIComponent(escape(Latin1.stringify(wordArray))); 8220 } catch (e) { 8221 throw new Error('Malformed UTF-8 data'); 8222 } 8223 }, 8224 8225 /** 8226 * Converts a UTF-8 string to a word array. 8227 * 8228 * @param {string} utf8Str The UTF-8 string. 8229 * 8230 * @return {WordArray} The word array. 8231 * 8232 * @static 8233 * 8234 * @example 8235 * 8236 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String); 8237 */ 8238 parse: function (utf8Str) { 8239 return Latin1.parse(unescape(encodeURIComponent(utf8Str))); 8240 } 8241 }; 8242 8243 /** 8244 * Abstract buffered block algorithm template. 8245 * 8246 * The property blockSize must be implemented in a concrete subtype. 8247 * 8248 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0 8249 */ 8250 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({ 8251 /** 8252 * Resets this block algorithm's data buffer to its initial state. 8253 * 8254 * @example 8255 * 8256 * bufferedBlockAlgorithm.reset(); 8257 */ 8258 reset: function () { 8259 // Initial values 8260 this._data = new WordArray.init(); 8261 this._nDataBytes = 0; 8262 }, 8263 8264 /** 8265 * Adds new data to this block algorithm's buffer. 8266 * 8267 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8. 8268 * 8269 * @example 8270 * 8271 * bufferedBlockAlgorithm._append('data'); 8272 * bufferedBlockAlgorithm._append(wordArray); 8273 */ 8274 _append: function (data) { 8275 // Convert string to WordArray, else assume WordArray already 8276 if (typeof data == 'string') { 8277 data = Utf8.parse(data); 8278 } 8279 8280 // Append 8281 this._data.concat(data); 8282 this._nDataBytes += data.sigBytes; 8283 }, 8284 8285 /** 8286 * Processes available data blocks. 8287 * 8288 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. 8289 * 8290 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed. 8291 * 8292 * @return {WordArray} The processed data. 8293 * 8294 * @example 8295 * 8296 * var processedData = bufferedBlockAlgorithm._process(); 8297 * var processedData = bufferedBlockAlgorithm._process(!!'flush'); 8298 */ 8299 _process: function (doFlush) { 8300
8300// Shortcuts 8301 var data = this._data; 8302 var dataWords = data.words; 8303 var dataSigBytes = data.sigBytes; 8304 var blockSize = this.blockSize; 8305 var blockSizeBytes = blockSize * 4; 8306 8307 // Count blocks ready 8308 var nBlocksReady = dataSigBytes / blockSizeBytes; 8309 if (doFlush) { 8310 // Round up to include partial blocks 8311 nBlocksReady = Math.ceil(nBlocksReady); 8312 } else { 8313 // Round down to include only full blocks, 8314 // less the number of blocks that must remain in the buffer 8315 nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); 8316 } 8317 8318 // Count words ready 8319 var nWordsReady = nBlocksReady * blockSize; 8320 8321 // Count bytes ready 8322 var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes); 8323 8324 // Process blocks 8325 if (nWordsReady) { 8326 for (var offset = 0; offset < nWordsReady; offset += blockSize) { 8327 // Perform concrete-algorithm logic 8328 this._doProcessBlock(dataWords, offset); 8329 } 8330 8331 // Remove processed words 8332 var processedWords = dataWords.splice(0, nWordsReady); 8333 data.sigBytes -= nBytesReady; 8334 } 8335 8336 // Return processed words 8337 return new WordArray.init(processedWords, nBytesReady); 8338 }, 8339 8340 /** 8341 * Creates a copy of this object. 8342 * 8343 * @return {Object} The clone. 8344 * 8345 * @example 8346 * 8347 * var clone = bufferedBlockAlgorithm.clone(); 8348 */ 8349 clone: function () { 8350 var clone = Base.clone.call(this); 8351 clone._data = this._data.clone(); 8352 8353 return clone; 8354 }, 8355 8356 _minBufferSize: 0 8357 }); 8358 8359 /** 8360 * Abstract hasher template. 8361 * 8362 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits) 8363 */ 8364 var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({ 8365 /** 8366 * Configuration options. 8367 */ 8368 cfg: Base.extend(), 8369 8370 /** 8371 * Initializes a newly created hasher. 8372 * 8373 * @param {Object} cfg (Optional) The configuration options to use for this hash computation. 8374 * 8375 * @example 8376 * 8377 * var hasher = CryptoJS.algo.SHA256.create(); 8378 */ 8379 init: function (cfg) { 8380 // Apply config defaults 8381 this.cfg = this.cfg.extend(cfg); 8382 8383 // Set initial values 8384 this.reset(); 8385 }, 8386 8387 /** 8388 * Resets this hasher to its initial state. 8389 * 8390 * @example 8391 * 8392 * hasher.reset(); 8393 */ 8394 reset: function () { 8395 // Reset data buffer 8396 BufferedBlockAlgorithm.reset.call(this); 8397 8398 // Perform concrete-hasher logic 8399 this._doReset(); 8400 }, 8401 8402 /** 8403 * Updates this hasher with a message. 8404 * 8405 * @param {WordArray|string} messageUpdate The message to append. 8406 * 8407 * @return {Hasher} This hasher. 8408 * 8409 * @example 8410 * 8411 * hasher.update('message'); 8412 * hasher.update(wordArray); 8413 */ 8414 update: function (messageUpdate) { 8415 // Append 8416 this._append(messageUpdate); 8417 8418 // Update the hash 8419 this._process(); 8420 8421 // Chainable 8422 return this; 8423 }, 8424 8425 /** 8426 * Finalizes the hash computation. 8427 * Note that the finalize operation is effectively a destructive, read-once operation. 8428 * 8429 * @param {WordArray|string} messageUpdate (Optional) A final message update. 8430 * 8431 * @return {WordArray} The hash. 8432 * 8433 * @example 8434 * 8435 * var hash = hasher.finalize(); 8436 * var hash = hasher.finalize('message'); 8437 * var hash = hasher.finalize(wordArray); 8438 */ 8439 finalize: function (messageUpdate) { 8440 // Final message update 8441 if (messageUpdate) { 8442 this._append(messageUpdate); 8443 } 8444 8445 // Perform concrete-hasher logic 8446 var hash = this._doFinalize(); 8447 8448 return hash; 8449 }, 8450 8451 blockSize: 512/32, 8452 8453 /** 8454 * Creates a shortcut function to a hasher's object interface. 8455 * 8456 * @param {Hasher} hasher The hasher to create a helper for. 8457 * 8458 * @return {Function} The shortcut function. 8459 * 8460 * @static 8461 * 8462 * @example 8463 * 8464 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256); 8465 */ 8466 _createHelper: function (hasher) { 8467 return function (message, cfg) { 8468 return new hasher.init(cfg).finalize(message); 8469 }; 8470 }, 8471 8472 /** 8473 * Creates a shortcut function to the HMAC's object interface. 8474 * 8475 * @param {Hasher} hasher The hasher to use in this HMAC helper. 8476 * 8477 * @return {Function} The shortcut function. 8478 * 8479 * @static 8480 * 8481 * @example 8482 * 8483 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256); 8484 */ 8485 _createHmacHelper: function (hasher) { 8486 return function (message, key) { 8487 return new C_algo.HMAC.init(hasher, key).finalize(message); 8488 }; 8489 } 8490 }); 8491 8492 /** 8493 * Algorithm namespace. 8494 */ 8495 var C_algo = C.algo = {}; 8496 8497 return C; 8498 }(Math)); 8499 8500 8501 return CryptoJS; 8502 8503})); 8504},{}],18:[function(require,module,exports){ 8505;(function (root, factory, undef) { 8506 if (typeof exports === "object") { 8507 // CommonJS 8508 module.exports = exports = factory(require("./core"), require("./x64-core")); 8509 } 8510 else if (typeof define === "function" && define.amd) { 8511 // AMD 8512 define(["./core", "./x64-core"], factory); 8513 } 8514 else { 8515 // Global (browser) 8516 factory(root.CryptoJS); 8517 } 8518}(this, function (CryptoJS) { 8519 8520 (function (Math) { 8521 // Shortcuts 8522 var C = CryptoJS; 8523 var C_lib = C.lib; 8524 var WordArray = C_lib.WordArray; 8525 var Hasher = C_lib.Hasher; 8526 var C_x64 = C.x64; 8527 var X64Word = C_x64.Word; 8528 var C_algo = C.algo; 8529 8530 // Constants tables 8531 var RHO_OFFSETS = []; 8532 var PI_INDEXES = []; 8533 var ROUND_CONSTANTS = []; 8534 8535 // Compute Constants 8536 (function () { 8537 // Compute rho offset constants 8538 var x = 1, y = 0; 8539 for (var t = 0; t < 24; t++) { 8540 RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; 8541 8542 var newX = y % 5; 8543 var newY = (2 * x + 3 * y) % 5; 8544 x = newX; 8545 y = newY; 8546 } 8547 8548 // Compute pi index constants 8549 for (var x = 0; x < 5; x++) { 8550 for (var y = 0; y < 5; y++) { 8551 PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; 8552 } 8553 } 8554
vendor: 15,595 bytes, lines 8555-9045
8555 // Compute round constants 8556 var LFSR = 0x01; 8557 for (var i = 0; i < 24; i++) { 8558 var roundConstantMsw = 0; 8559 var roundConstantLsw = 0; 8560 8561 for (var j = 0; j < 7; j++) { 8562 if (LFSR & 0x01) { 8563 var bitPosition = (1 << j) - 1; 8564 if (bitPosition < 32) { 8565 roundConstantLsw ^= 1 << bitPosition; 8566 } else /* if (bitPosition >= 32) */ { 8567 roundConstantMsw ^= 1 << (bitPosition - 32); 8568 } 8569 } 8570 8571 // Compute next LFSR 8572 if (LFSR & 0x80) { 8573 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 8574 LFSR = (LFSR << 1) ^ 0x71; 8575 } else { 8576 LFSR <<= 1; 8577 } 8578 } 8579 8580 ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw); 8581 } 8582 }()); 8583 8584 // Reusable objects for temporary values 8585 var T = []; 8586 (function () { 8587 for (var i = 0; i < 25; i++) { 8588 T[i] = X64Word.create(); 8589 } 8590 }()); 8591 8592 /** 8593 * SHA-3 hash algorithm. 8594 */ 8595 var SHA3 = C_algo.SHA3 = Hasher.extend({ 8596 /** 8597 * Configuration options. 8598 * 8599 * @property {number} outputLength 8600 * The desired number of bits in the output hash. 8601 * Only values permitted are: 224, 256, 384, 512. 8602 * Default: 512 8603 */ 8604 cfg: Hasher.cfg.extend({ 8605 outputLength: 512 8606 }), 8607 8608 _doReset: function () { 8609 var state = this._state = [] 8610 for (var i = 0; i < 25; i++) { 8611 state[i] = new X64Word.init(); 8612 } 8613 8614 this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; 8615 }, 8616 8617 _doProcessBlock: function (M, offset) { 8618 // Shortcuts 8619 var state = this._state; 8620 var nBlockSizeLanes = this.blockSize / 2; 8621 8622 // Absorb 8623 for (var i = 0; i < nBlockSizeLanes; i++) { 8624 // Shortcuts 8625 var M2i = M[offset + 2 * i]; 8626 var M2i1 = M[offset + 2 * i + 1]; 8627 8628 // Swap endian 8629 M2i = ( 8630 (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | 8631 (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) 8632 ); 8633 M2i1 = ( 8634 (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | 8635 (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) 8636 ); 8637 8638 // Absorb message into state 8639 var lane = state[i]; 8640 lane.high ^= M2i1; 8641 lane.low ^= M2i; 8642 } 8643 8644 // Rounds 8645 for (var round = 0; round < 24; round++) { 8646 // Theta 8647 for (var x = 0; x < 5; x++) { 8648 // Mix column lanes 8649 var tMsw = 0, tLsw = 0; 8650 for (var y = 0; y < 5; y++) { 8651 var lane = state[x + 5 * y]; 8652 tMsw ^= lane.high; 8653 tLsw ^= lane.low; 8654 } 8655 8656 // Temporary values 8657 var Tx = T[x]; 8658 Tx.high = tMsw; 8659 Tx.low = tLsw; 8660 } 8661 for (var x = 0; x < 5; x++) { 8662 // Shortcuts 8663 var Tx4 = T[(x + 4) % 5]; 8664 var Tx1 = T[(x + 1) % 5]; 8665 var Tx1Msw = Tx1.high; 8666 var Tx1Lsw = Tx1.low; 8667 8668 // Mix surrounding columns 8669 var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); 8670 var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); 8671 for (var y = 0; y < 5; y++) { 8672 var lane = state[x + 5 * y]; 8673 lane.high ^= tMsw; 8674 lane.low ^= tLsw; 8675 } 8676 } 8677 8678 // Rho Pi 8679 for (var laneIndex = 1; laneIndex < 25; laneIndex++) { 8680 // Shortcuts 8681 var lane = state[laneIndex]; 8682 var laneMsw = lane.high; 8683 var laneLsw = lane.low; 8684 var rhoOffset = RHO_OFFSETS[laneIndex]; 8685 8686 // Rotate lanes 8687 if (rhoOffset < 32) { 8688 var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); 8689 var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); 8690 } else /* if (rhoOffset >= 32) */ { 8691 var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); 8692 var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); 8693 } 8694 8695 // Transpose lanes 8696 var TPiLane = T[PI_INDEXES[laneIndex]]; 8697 TPiLane.high = tMsw; 8698 TPiLane.low = tLsw; 8699 } 8700 8701 // Rho pi at x = y = 0 8702 var T0 = T[0]; 8703 var state0 = state[0]; 8704 T0.high = state0.high; 8705 T0.low = state0.low; 8706 8707 // Chi 8708 for (var x = 0; x < 5; x++) { 8709 for (var y = 0; y < 5; y++) { 8710 // Shortcuts 8711 var laneIndex = x + 5 * y; 8712 var lane = state[laneIndex]; 8713 var TLane = T[laneIndex]; 8714 var Tx1Lane = T[((x + 1) % 5) + 5 * y]; 8715 var Tx2Lane = T[((x + 2) % 5) + 5 * y]; 8716 8717 // Mix rows 8718 lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); 8719 lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); 8720 } 8721 } 8722 8723 // Iota 8724 var lane = state[0]; 8725 var roundConstant = ROUND_CONSTANTS[round]; 8726 lane.high ^= roundConstant.high; 8727 lane.low ^= roundConstant.low;; 8728 } 8729 }, 8730 8731 _doFinalize: function () { 8732 // Shortcuts 8733 var data = this._data; 8734 var dataWords = data.words; 8735 var nBitsTotal = this._nDataBytes * 8; 8736 var nBitsLeft = data.sigBytes * 8; 8737 var blockSizeBits = this.blockSize * 32; 8738 8739 // Add padding 8740 dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); 8741 dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; 8742 data.sigBytes = dataWords.length * 4; 8743 8744 // Hash final blocks 8745 this._process(); 8746 8747 // Shortcuts 8748 var state = this._state; 8749 var outputLengthBytes = this.cfg.outputLength / 8; 8750 var outputLengthLanes = outputLengthBytes / 8; 8751 8752 // Squeeze 8753 var hashWords = []; 8754 for (var i = 0; i < outputLengthLanes; i++) { 8755 // Shortcuts 8756 var lane = state[i]; 8757 var laneMsw = lane.high; 8758 var laneLsw = lane.low; 8759 8760 // Swap endian 8761 laneMsw = ( 8762 (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | 8763 (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) 8764 ); 8765 laneLsw = ( 8766 (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | 8767 (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) 8768 ); 8769 8770 // Squeeze state to retrieve hash 8771 hashWords.push(laneLsw); 8772 hashWords.push(laneMsw); 8773 } 8774 8775 // Return final computed hash 8776 return new WordArray.init(hashWords, outputLengthBytes); 8777 }, 8778 8779 clone: function () { 8780 var clone = Hasher.clone.call(this); 8781 8782 var state = clone._state = this._state.slice(0); 8783 for (var i = 0; i < 25; i++) { 8784 state[i] = state[i].clone(); 8785 } 8786 8787 return clone; 8788 } 8789 }); 8790 8791 /** 8792 * Shortcut function to the hasher's object interface. 8793 * 8794 * @param {WordArray|string} message The message to hash. 8795 * 8796 * @return {WordArray} The hash. 8797 * 8798 * @static 8799 * 8800 * @example 8801 * 8802 * var hash = CryptoJS.SHA3('message'); 8803 * var hash = CryptoJS.SHA3(wordArray); 8804 */ 8805 C.SHA3 = Hasher._createHelper(SHA3); 8806 8807 /** 8808 * Shortcut function to the HMAC's object interface. 8809 * 8810 * @param {WordArray|string} message The message to hash. 8811 * @param {WordArray|string} key The secret key. 8812 * 8813 * @return {WordArray} The HMAC. 8814 * 8815 * @static 8816 * 8817 * @example 8818 * 8819 * var hmac = CryptoJS.HmacSHA3(message, key); 8820 */ 8821 C.HmacSHA3 = Hasher._createHmacHelper(SHA3); 8822 }(Math)); 8823 8824 8825 return CryptoJS.SHA3; 8826 8827})); 8828},{"./core":17,"./x64-core":19}],19:[function(require,module,exports){ 8829;(function (root, factory) { 8830 if (typeof exports === "object") { 8831 // CommonJS 8832 module.exports = exports = factory(require("./core")); 8833 } 8834 else if (typeof define === "function" && define.amd) { 8835 // AMD 8836 define(["./core"], factory); 8837 } 8838 else { 8839 // Global (browser) 8840 factory(root.CryptoJS); 8841 } 8842}(this, function (CryptoJS) { 8843 8844 (function (undefined) { 8845 // Shortcuts 8846 var C = CryptoJS; 8847 var C_lib = C.lib; 8848 var Base = C_lib.Base; 8849 var X32WordArray = C_lib.WordArray; 8850 8851 /** 8852 * x64 namespace. 8853 */ 8854 var C_x64 = C.x64 = {}; 8855 8856 /** 8857 * A 64-bit word. 8858 */ 8859 var X64Word = C_x64.Word = Base.extend({ 8860 /** 8861 * Initializes a newly created 64-bit word. 8862 * 8863 * @param {number} high The high 32 bits. 8864 * @param {number} low The low 32 bits. 8865 * 8866 * @example 8867 * 8868 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607); 8869 */ 8870 init: function (high, low) { 8871 this.high = high; 8872 this.low = low; 8873 } 8874 8875 /** 8876 * Bitwise NOTs this word. 8877 * 8878 * @return {X64Word} A new x64-Word object after negating. 8879 * 8880 * @example 8881 * 8882 * var negated = x64Word.not(); 8883 */ 8884 // not: function () { 8885 // var high = ~this.high; 8886 // var low = ~this.low; 8887 8888 // return X64Word.create(high, low); 8889 // }, 8890 8891 /** 8892 * Bitwise ANDs this word with the passed word. 8893 * 8894 * @param {X64Word} word The x64-Word to AND with this word. 8895 * 8896 * @return {X64Word} A new x64-Word object after ANDing. 8897 * 8898 * @example 8899 * 8900 * var anded = x64Word.and(anotherX64Word); 8901 */ 8902 // and: function (word) { 8903 // var high = this.high & word.high; 8904 // var low = this.low & word.low; 8905 8906 // return X64Word.create(high, low); 8907 // }, 8908 8909 /** 8910 * Bitwise ORs this word with the passed word. 8911 * 8912 * @param {X64Word} word The x64-Word to OR with this word. 8913 * 8914 * @return {X64Word} A new x64-Word object after ORing. 8915 * 8916 * @example 8917 * 8918 * var ored = x64Word.or(anotherX64Word); 8919 */ 8920 // or: function (word) { 8921 // var high = this.high | word.high; 8922 // var low = this.low | word.low; 8923 8924 // return X64Word.create(high, low); 8925 // }, 8926 8927 /** 8928 * Bitwise XORs this word with the passed word. 8929 * 8930 * @param {X64Word} word The x64-Word to XOR with this word. 8931 * 8932 * @return {X64Word} A new x64-Word object after XORing. 8933 * 8934 * @example 8935 * 8936 * var xored = x64Word.xor(anotherX64Word); 8937 */ 8938 // xor: function (word) { 8939 // var high = this.high ^ word.high; 8940 // var low = this.low ^ word.low; 8941 8942 // return X64Word.create(high, low); 8943 // }, 8944 8945 /** 8946 * Shifts this word n bits to the left. 8947 * 8948 * @param {number} n The number of bits to shift. 8949 * 8950 * @return {X64Word} A new x64-Word object after shifting. 8951 * 8952 * @example 8953 * 8954 * var shifted = x64Word.shiftL(25); 8955 */ 8956 // shiftL: function (n) { 8957 // if (n < 32) { 8958 // var high = (this.high << n) | (this.low >>> (32 - n)); 8959 // var low = this.low << n; 8960 // } else { 8961 // var high = this.low << (n - 32); 8962 // var low = 0; 8963 // } 8964 8965 // return X64Word.create(high, low); 8966 // }, 8967 8968 /** 8969 * Shifts this word n bits to the right. 8970 * 8971 * @param {number} n The number of bits to shift. 8972 * 8973 * @return {X64Word} A new x64-Word object after shifting. 8974 * 8975 * @example 8976 * 8977 * var shifted = x64Word.shiftR(7); 8978 */ 8979 // shiftR: function (n) { 8980 // if (n < 32) { 8981 // var low = (this.low >>> n) | (this.high << (32 - n)); 8982 // var high = this.high >>> n; 8983 // } else { 8984 // var low = this.high >>> (n - 32); 8985 // var high = 0; 8986 // } 8987 8988 // return X64Word.create(high, low); 8989 // }, 8990 8991 /** 8992 * Rotates this word n bits to the left. 8993 * 8994 * @param {number} n The number of bits to rotate. 8995 * 8996 * @return {X64Word} A new x64-Word object after rotating. 8997 * 8998 * @example 8999 * 9000 * var rotated = x64Word.rotL(25); 9001 */ 9002 // rotL: function (n) { 9003 // return this.shiftL(n).or(this.shiftR(64 - n)); 9004 // }, 9005 9006 /** 9007 * Rotates this word n bits to the right. 9008 * 9009 * @param {number} n The number of bits to rotate. 9010 * 9011 * @return {X64Word} A new x64-Word object after rotating. 9012 * 9013 * @example 9014 * 9015 * var rotated = x64Word.rotR(7); 9016 */ 9017 // rotR: function (n) { 9018 // return this.shiftR(n).or(this.shiftL(64 - n)); 9019 // }, 9020 9021 /** 9022 * Adds this word with the passed word. 9023 * 9024 * @param {X64Word} word The x64-Word to add with this word. 9025 * 9026 * @return {X64Word} A new x64-Word object after adding. 9027 * 9028 * @example 9029 * 9030 * var added = x64Word.add(anotherX64Word); 9031 */ 9032 // add: function (word) { 9033 // var low = (this.low + word.low) | 0; 9034 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0; 9035 // var high = (this.high + word.high + carry) | 0; 9036 9037 // return X64Word.create(high, low); 9038 // } 9039 }); 9040 9041 /** 9042 * An array of 64-bit words. 9043 * 9044 * @property {Array} words The array of CryptoJS.x64.Word objects. 9045 * @property {number} sigBytes The number of significant bytes in this word array.
9046 */ 9047 var X64WordArray = C_x64.WordArray = Base.extend({ 9048 /** 9049 * Initializes a newly created word array. 9050 * 9051 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects. 9052 * @param {number} sigBytes (Optional) The number of significant bytes in the words. 9053 * 9054 * @example 9055 * 9056 * var wordArray = CryptoJS.x64.WordArray.create(); 9057 * 9058 * var wordArray = CryptoJS.x64.WordArray.create([ 9059 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 9060 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 9061 * ]); 9062 * 9063 * var wordArray = CryptoJS.x64.WordArray.create([ 9064 * CryptoJS.x64.Word.create(0x00010203, 0x04050607), 9065 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f) 9066 * ], 10); 9067 */ 9068 init: function (words, sigBytes) { 9069 words = this.words = words || []; 9070 9071 if (sigBytes != undefined) { 9072 this.sigBytes = sigBytes; 9073 } else { 9074 this.sigBytes = words.length * 8; 9075 } 9076 }, 9077 9078 /** 9079 * Converts this 64-bit word array to a 32-bit word array. 9080 * 9081 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array. 9082 * 9083 * @example 9084 * 9085 * var x32WordArray = x64WordArray.toX32(); 9086 */ 9087 toX32: function () { 9088 // Shortcuts 9089 var x64Words = this.words; 9090 var x64WordsLength = x64Words.length; 9091 9092 // Convert 9093 var x32Words = []; 9094 for (var i = 0; i < x64WordsLength; i++) { 9095 var x64Word = x64Words[i]; 9096 x32Words.push(x64Word.high); 9097 x32Words.push(x64Word.low); 9098 } 9099 9100 return X32WordArray.create(x32Words, this.sigBytes); 9101 }, 9102 9103 /** 9104 * Creates a copy of this word array. 9105 * 9106 * @return {X64WordArray} The clone. 9107 * 9108 * @example 9109 * 9110 * var clone = x64WordArray.clone(); 9111 */ 9112 clone: function () { 9113 var clone = Base.clone.call(this); 9114 9115 // Clone "words" array 9116 var words = clone.words = this.words.slice(0); 9117 9118 // Clone each X64Word object 9119 var wordsLength = words.length; 9120 for (var i = 0; i < wordsLength; i++) { 9121 words[i] = words[i].clone(); 9122 } 9123 9124 return clone; 9125 } 9126 }); 9127 }()); 9128 9129 9130 return CryptoJS; 9131 9132})); 9133},{"./core":17}],20:[function(require,module,exports){ 9134module.exports={ 9135 "_args": [ 9136 [ 9137 { 9138 "raw": "[email protected]", 9139 "scope": null, 9140 "escapedName": "truffle-contract-schema", 9141 "name": "truffle-contract-schema", 9142 "rawSpec": "0.0.5", 9143 "spec": "0.0.5", 9144 "type": "version" 9145 }, 9146 "/Users/tim/Documents/workspace/Consensys/truffle-contract" 9147 ] 9148 ], 9149 "_from": "[email protected]", 9150 "_id": "[email protected]", 9151 "_inCache": true, 9152 "_location": "/truffle-contract-schema", 9153 "_nodeVersion": "6.9.1", 9154 "_npmOperationalInternal": { 9155 "host": "packages-12-west.internal.npmjs.com", 9156 "tmp": "tmp/truffle-contract-schema-0.0.5.tgz_1485557985137_0.46875762194395065" 9157 }, 9158 "_npmUser": { 9159 "name": "tcoulter", 9160 "email": "[email protected]" 9161 }, 9162 "_npmVersion": "3.10.8", 9163 "_phantomChildren": {}, 9164 "_requested": { 9165 "raw": "[email protected]", 9166 "scope": null, 9167 "escapedName": "truffle-contract-schema", 9168 "name": "truffle-contract-schema", 9169 "rawSpec": "0.0.5", 9170 "spec": "0.0.5", 9171 "type": "version" 9172 }, 9173 "_requiredBy": [ 9174 "/" 9175 ], 9176 "_resolved": "https://registry.npmjs.org/truffle-contract-schema/-/truffle-contract-schema-0.0.5.tgz", 9177 "_shasum": "5e9d20bd0bf2a27fe94310748249d484eee49961", 9178 "_shrinkwrap": null, 9179 "_spec": "[email protected]", 9180 "_where": "/Users/tim/Documents/workspace/Consensys/truffle-contract", 9181 "author": { 9182 "name": "Tim Coulter", 9183 "email": "[email protected]" 9184 }, 9185 "bugs": { 9186 "url": "https://github.com/trufflesuite/truffle-schema/issues" 9187 },
9188 "dependencies": { 9189 "crypto-js": "^3.1.9-1" 9190 }, 9191 "description": "JSON schema for contract artifacts", 9192 "devDependencies": { 9193 "mocha": "^3.2.0" 9194 }, 9195 "directories": {}, 9196 "dist": { 9197 "shasum": "5e9d20bd0bf2a27fe94310748249d484eee49961", 9198 "tarball": "https://registry.npmjs.org/truffle-contract-schema/-/truffle-contract-schema-0.0.5.tgz" 9199 }, 9200 "gitHead": "cfa4313bd4bb95bf5b94f85185203ead418f9ee6", 9201 "homepage": "https://github.com/trufflesuite/truffle-schema#readme", 9202 "keywords": [ 9203 "ethereum", 9204 "json", 9205 "schema", 9206 "contract", 9207 "artifacts" 9208 ], 9209 "license": "MIT", 9210 "main": "index.js", 9211 "maintainers": [ 9212 { 9213 "name": "tcoulter", 9214 "email": "[email protected]" 9215 } 9216 ], 9217 "name": "truffle-contract-schema", 9218 "optionalDependencies": {}, 9219 "readme": "ERROR: No README data found!", 9220 "repository": { 9221 "type": "git", 9222 "url": "git+https://github.com/trufflesuite/truffle-schema.git" 9223 }, 9224 "scripts": { 9225 "test": "mocha" 9226 }, 9227 "version": "0.0.5" 9228} 9229 9230},{}]},{},[2]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.