diff options
author | amougel <alix.mougel@gmail.com> | 2017-06-01 15:57:11 +0200 |
---|---|---|
committer | amougel <alix.mougel@gmail.com> | 2017-06-01 15:57:11 +0200 |
commit | 8a1f452d03f81c917182d61895b68a1a5201ca31 (patch) | |
tree | 3cb819bc8d8892e9276cb17fd0aef4585097ead4 /bip39-standalone.html | |
parent | 64a7d2aad49ddbbcd2eabea8f98f7ff468ca7ccb (diff) | |
download | BIP39-8a1f452d03f81c917182d61895b68a1a5201ca31.tar.gz BIP39-8a1f452d03f81c917182d61895b68a1a5201ca31.tar.zst BIP39-8a1f452d03f81c917182d61895b68a1a5201ca31.zip |
compiled ripple version
Diffstat (limited to 'bip39-standalone.html')
-rw-r--r-- | bip39-standalone.html | 2033 |
1 files changed, 2033 insertions, 0 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index a7d6ce9..98a33b2 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -4471,6 +4471,2016 @@ function __cons(t, a) { | |||
4471 | return eval('new t(' + a.map(function(_, i) { return 'a[' + i + ']'; }).join(',') + ')'); | 4471 | return eval('new t(' + a.map(function(_, i) { return 'a[' + i + ']'; }).join(',') + ')'); |
4472 | } | 4472 | } |
4473 | </script> | 4473 | </script> |
4474 | <script>(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.foo = f()}})(function(){var define,module,exports;return (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){ | ||
4475 | 'use strict' | ||
4476 | |||
4477 | exports.byteLength = byteLength | ||
4478 | exports.toByteArray = toByteArray | ||
4479 | exports.fromByteArray = fromByteArray | ||
4480 | |||
4481 | var lookup = [] | ||
4482 | var revLookup = [] | ||
4483 | var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array | ||
4484 | |||
4485 | var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' | ||
4486 | for (var i = 0, len = code.length; i < len; ++i) { | ||
4487 | lookup[i] = code[i] | ||
4488 | revLookup[code.charCodeAt(i)] = i | ||
4489 | } | ||
4490 | |||
4491 | revLookup['-'.charCodeAt(0)] = 62 | ||
4492 | revLookup['_'.charCodeAt(0)] = 63 | ||
4493 | |||
4494 | function placeHoldersCount (b64) { | ||
4495 | var len = b64.length | ||
4496 | if (len % 4 > 0) { | ||
4497 | throw new Error('Invalid string. Length must be a multiple of 4') | ||
4498 | } | ||
4499 | |||
4500 | // the number of equal signs (place holders) | ||
4501 | // if there are two placeholders, than the two characters before it | ||
4502 | // represent one byte | ||
4503 | // if there is only one, then the three characters before it represent 2 bytes | ||
4504 | // this is just a cheap hack to not do indexOf twice | ||
4505 | return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 | ||
4506 | } | ||
4507 | |||
4508 | function byteLength (b64) { | ||
4509 | // base64 is 4/3 + up to two characters of the original data | ||
4510 | return b64.length * 3 / 4 - placeHoldersCount(b64) | ||
4511 | } | ||
4512 | |||
4513 | function toByteArray (b64) { | ||
4514 | var i, j, l, tmp, placeHolders, arr | ||
4515 | var len = b64.length | ||
4516 | placeHolders = placeHoldersCount(b64) | ||
4517 | |||
4518 | arr = new Arr(len * 3 / 4 - placeHolders) | ||
4519 | |||
4520 | // if there are placeholders, only get up to the last complete 4 chars | ||
4521 | l = placeHolders > 0 ? len - 4 : len | ||
4522 | |||
4523 | var L = 0 | ||
4524 | |||
4525 | for (i = 0, j = 0; i < l; i += 4, j += 3) { | ||
4526 | tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] | ||
4527 | arr[L++] = (tmp >> 16) & 0xFF | ||
4528 | arr[L++] = (tmp >> 8) & 0xFF | ||
4529 | arr[L++] = tmp & 0xFF | ||
4530 | } | ||
4531 | |||
4532 | if (placeHolders === 2) { | ||
4533 | tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) | ||
4534 | arr[L++] = tmp & 0xFF | ||
4535 | } else if (placeHolders === 1) { | ||
4536 | tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) | ||
4537 | arr[L++] = (tmp >> 8) & 0xFF | ||
4538 | arr[L++] = tmp & 0xFF | ||
4539 | } | ||
4540 | |||
4541 | return arr | ||
4542 | } | ||
4543 | |||
4544 | function tripletToBase64 (num) { | ||
4545 | return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] | ||
4546 | } | ||
4547 | |||
4548 | function encodeChunk (uint8, start, end) { | ||
4549 | var tmp | ||
4550 | var output = [] | ||
4551 | for (var i = start; i < end; i += 3) { | ||
4552 | tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) | ||
4553 | output.push(tripletToBase64(tmp)) | ||
4554 | } | ||
4555 | return output.join('') | ||
4556 | } | ||
4557 | |||
4558 | function fromByteArray (uint8) { | ||
4559 | var tmp | ||
4560 | var len = uint8.length | ||
4561 | var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes | ||
4562 | var output = '' | ||
4563 | var parts = [] | ||
4564 | var maxChunkLength = 16383 // must be multiple of 3 | ||
4565 | |||
4566 | // go through the array every three bytes, we'll deal with trailing stuff later | ||
4567 | for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { | ||
4568 | parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) | ||
4569 | } | ||
4570 | |||
4571 | // pad the end with zeros, but make sure to not forget the extra bytes | ||
4572 | if (extraBytes === 1) { | ||
4573 | tmp = uint8[len - 1] | ||
4574 | output += lookup[tmp >> 2] | ||
4575 | output += lookup[(tmp << 4) & 0x3F] | ||
4576 | output += '==' | ||
4577 | } else if (extraBytes === 2) { | ||
4578 | tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) | ||
4579 | output += lookup[tmp >> 10] | ||
4580 | output += lookup[(tmp >> 4) & 0x3F] | ||
4581 | output += lookup[(tmp << 2) & 0x3F] | ||
4582 | output += '=' | ||
4583 | } | ||
4584 | |||
4585 | parts.push(output) | ||
4586 | |||
4587 | return parts.join('') | ||
4588 | } | ||
4589 | |||
4590 | },{}],2:[function(require,module,exports){ | ||
4591 | /*! | ||
4592 | * The buffer module from node.js, for the browser. | ||
4593 | * | ||
4594 | * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org> | ||
4595 | * @license MIT | ||
4596 | */ | ||
4597 | /* eslint-disable no-proto */ | ||
4598 | |||
4599 | 'use strict' | ||
4600 | |||
4601 | var base64 = require('base64-js') | ||
4602 | var ieee754 = require('ieee754') | ||
4603 | |||
4604 | exports.Buffer = Buffer | ||
4605 | exports.SlowBuffer = SlowBuffer | ||
4606 | exports.INSPECT_MAX_BYTES = 50 | ||
4607 | |||
4608 | var K_MAX_LENGTH = 0x7fffffff | ||
4609 | exports.kMaxLength = K_MAX_LENGTH | ||
4610 | |||
4611 | /** | ||
4612 | * If `Buffer.TYPED_ARRAY_SUPPORT`: | ||
4613 | * === true Use Uint8Array implementation (fastest) | ||
4614 | * === false Print warning and recommend using `buffer` v4.x which has an Object | ||
4615 | * implementation (most compatible, even IE6) | ||
4616 | * | ||
4617 | * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, | ||
4618 | * Opera 11.6+, iOS 4.2+. | ||
4619 | * | ||
4620 | * We report that the browser does not support typed arrays if the are not subclassable | ||
4621 | * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` | ||
4622 | * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support | ||
4623 | * for __proto__ and has a buggy typed array implementation. | ||
4624 | */ | ||
4625 | Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() | ||
4626 | |||
4627 | if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && | ||
4628 | typeof console.error === 'function') { | ||
4629 | console.error( | ||
4630 | 'This browser lacks typed array (Uint8Array) support which is required by ' + | ||
4631 | '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' | ||
4632 | ) | ||
4633 | } | ||
4634 | |||
4635 | function typedArraySupport () { | ||
4636 | // Can typed array instances can be augmented? | ||
4637 | try { | ||
4638 | var arr = new Uint8Array(1) | ||
4639 | arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} | ||
4640 | return arr.foo() === 42 | ||
4641 | } catch (e) { | ||
4642 | return false | ||
4643 | } | ||
4644 | } | ||
4645 | |||
4646 | function createBuffer (length) { | ||
4647 | if (length > K_MAX_LENGTH) { | ||
4648 | throw new RangeError('Invalid typed array length') | ||
4649 | } | ||
4650 | // Return an augmented `Uint8Array` instance | ||
4651 | var buf = new Uint8Array(length) | ||
4652 | buf.__proto__ = Buffer.prototype | ||
4653 | return buf | ||
4654 | } | ||
4655 | |||
4656 | /** | ||
4657 | * The Buffer constructor returns instances of `Uint8Array` that have their | ||
4658 | * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of | ||
4659 | * `Uint8Array`, so the returned instances will have all the node `Buffer` methods | ||
4660 | * and the `Uint8Array` methods. Square bracket notation works as expected -- it | ||
4661 | * returns a single octet. | ||
4662 | * | ||
4663 | * The `Uint8Array` prototype remains unmodified. | ||
4664 | */ | ||
4665 | |||
4666 | function Buffer (arg, encodingOrOffset, length) { | ||
4667 | // Common case. | ||
4668 | if (typeof arg === 'number') { | ||
4669 | if (typeof encodingOrOffset === 'string') { | ||
4670 | throw new Error( | ||
4671 | 'If encoding is specified then the first argument must be a string' | ||
4672 | ) | ||
4673 | } | ||
4674 | return allocUnsafe(arg) | ||
4675 | } | ||
4676 | return from(arg, encodingOrOffset, length) | ||
4677 | } | ||
4678 | |||
4679 | // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 | ||
4680 | if (typeof Symbol !== 'undefined' && Symbol.species && | ||
4681 | Buffer[Symbol.species] === Buffer) { | ||
4682 | Object.defineProperty(Buffer, Symbol.species, { | ||
4683 | value: null, | ||
4684 | configurable: true, | ||
4685 | enumerable: false, | ||
4686 | writable: false | ||
4687 | }) | ||
4688 | } | ||
4689 | |||
4690 | Buffer.poolSize = 8192 // not used by this implementation | ||
4691 | |||
4692 | function from (value, encodingOrOffset, length) { | ||
4693 | if (typeof value === 'number') { | ||
4694 | throw new TypeError('"value" argument must not be a number') | ||
4695 | } | ||
4696 | |||
4697 | if (value instanceof ArrayBuffer) { | ||
4698 | return fromArrayBuffer(value, encodingOrOffset, length) | ||
4699 | } | ||
4700 | |||
4701 | if (typeof value === 'string') { | ||
4702 | return fromString(value, encodingOrOffset) | ||
4703 | } | ||
4704 | |||
4705 | return fromObject(value) | ||
4706 | } | ||
4707 | |||
4708 | /** | ||
4709 | * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError | ||
4710 | * if value is a number. | ||
4711 | * Buffer.from(str[, encoding]) | ||
4712 | * Buffer.from(array) | ||
4713 | * Buffer.from(buffer) | ||
4714 | * Buffer.from(arrayBuffer[, byteOffset[, length]]) | ||
4715 | **/ | ||
4716 | Buffer.from = function (value, encodingOrOffset, length) { | ||
4717 | return from(value, encodingOrOffset, length) | ||
4718 | } | ||
4719 | |||
4720 | // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: | ||
4721 | // https://github.com/feross/buffer/pull/148 | ||
4722 | Buffer.prototype.__proto__ = Uint8Array.prototype | ||
4723 | Buffer.__proto__ = Uint8Array | ||
4724 | |||
4725 | function assertSize (size) { | ||
4726 | if (typeof size !== 'number') { | ||
4727 | throw new TypeError('"size" argument must be a number') | ||
4728 | } else if (size < 0) { | ||
4729 | throw new RangeError('"size" argument must not be negative') | ||
4730 | } | ||
4731 | } | ||
4732 | |||
4733 | function alloc (size, fill, encoding) { | ||
4734 | assertSize(size) | ||
4735 | if (size <= 0) { | ||
4736 | return createBuffer(size) | ||
4737 | } | ||
4738 | if (fill !== undefined) { | ||
4739 | // Only pay attention to encoding if it's a string. This | ||
4740 | // prevents accidentally sending in a number that would | ||
4741 | // be interpretted as a start offset. | ||
4742 | return typeof encoding === 'string' | ||
4743 | ? createBuffer(size).fill(fill, encoding) | ||
4744 | : createBuffer(size).fill(fill) | ||
4745 | } | ||
4746 | return createBuffer(size) | ||
4747 | } | ||
4748 | |||
4749 | /** | ||
4750 | * Creates a new filled Buffer instance. | ||
4751 | * alloc(size[, fill[, encoding]]) | ||
4752 | **/ | ||
4753 | Buffer.alloc = function (size, fill, encoding) { | ||
4754 | return alloc(size, fill, encoding) | ||
4755 | } | ||
4756 | |||
4757 | function allocUnsafe (size) { | ||
4758 | assertSize(size) | ||
4759 | return createBuffer(size < 0 ? 0 : checked(size) | 0) | ||
4760 | } | ||
4761 | |||
4762 | /** | ||
4763 | * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. | ||
4764 | * */ | ||
4765 | Buffer.allocUnsafe = function (size) { | ||
4766 | return allocUnsafe(size) | ||
4767 | } | ||
4768 | /** | ||
4769 | * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. | ||
4770 | */ | ||
4771 | Buffer.allocUnsafeSlow = function (size) { | ||
4772 | return allocUnsafe(size) | ||
4773 | } | ||
4774 | |||
4775 | function fromString (string, encoding) { | ||
4776 | if (typeof encoding !== 'string' || encoding === '') { | ||
4777 | encoding = 'utf8' | ||
4778 | } | ||
4779 | |||
4780 | if (!Buffer.isEncoding(encoding)) { | ||
4781 | throw new TypeError('"encoding" must be a valid string encoding') | ||
4782 | } | ||
4783 | |||
4784 | var length = byteLength(string, encoding) | 0 | ||
4785 | var buf = createBuffer(length) | ||
4786 | |||
4787 | var actual = buf.write(string, encoding) | ||
4788 | |||
4789 | if (actual !== length) { | ||
4790 | // Writing a hex string, for example, that contains invalid characters will | ||
4791 | // cause everything after the first invalid character to be ignored. (e.g. | ||
4792 | // 'abxxcd' will be treated as 'ab') | ||
4793 | buf = buf.slice(0, actual) | ||
4794 | } | ||
4795 | |||
4796 | return buf | ||
4797 | } | ||
4798 | |||
4799 | function fromArrayLike (array) { | ||
4800 | var length = array.length < 0 ? 0 : checked(array.length) | 0 | ||
4801 | var buf = createBuffer(length) | ||
4802 | for (var i = 0; i < length; i += 1) { | ||
4803 | buf[i] = array[i] & 255 | ||
4804 | } | ||
4805 | return buf | ||
4806 | } | ||
4807 | |||
4808 | function fromArrayBuffer (array, byteOffset, length) { | ||
4809 | if (byteOffset < 0 || array.byteLength < byteOffset) { | ||
4810 | throw new RangeError('\'offset\' is out of bounds') | ||
4811 | } | ||
4812 | |||
4813 | if (array.byteLength < byteOffset + (length || 0)) { | ||
4814 | throw new RangeError('\'length\' is out of bounds') | ||
4815 | } | ||
4816 | |||
4817 | var buf | ||
4818 | if (byteOffset === undefined && length === undefined) { | ||
4819 | buf = new Uint8Array(array) | ||
4820 | } else if (length === undefined) { | ||
4821 | buf = new Uint8Array(array, byteOffset) | ||
4822 | } else { | ||
4823 | buf = new Uint8Array(array, byteOffset, length) | ||
4824 | } | ||
4825 | |||
4826 | // Return an augmented `Uint8Array` instance | ||
4827 | buf.__proto__ = Buffer.prototype | ||
4828 | return buf | ||
4829 | } | ||
4830 | |||
4831 | function fromObject (obj) { | ||
4832 | if (Buffer.isBuffer(obj)) { | ||
4833 | var len = checked(obj.length) | 0 | ||
4834 | var buf = createBuffer(len) | ||
4835 | |||
4836 | if (buf.length === 0) { | ||
4837 | return buf | ||
4838 | } | ||
4839 | |||
4840 | obj.copy(buf, 0, 0, len) | ||
4841 | return buf | ||
4842 | } | ||
4843 | |||
4844 | if (obj) { | ||
4845 | if (isArrayBufferView(obj) || 'length' in obj) { | ||
4846 | if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { | ||
4847 | return createBuffer(0) | ||
4848 | } | ||
4849 | return fromArrayLike(obj) | ||
4850 | } | ||
4851 | |||
4852 | if (obj.type === 'Buffer' && Array.isArray(obj.data)) { | ||
4853 | return fromArrayLike(obj.data) | ||
4854 | } | ||
4855 | } | ||
4856 | |||
4857 | throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') | ||
4858 | } | ||
4859 | |||
4860 | function checked (length) { | ||
4861 | // Note: cannot use `length < K_MAX_LENGTH` here because that fails when | ||
4862 | // length is NaN (which is otherwise coerced to zero.) | ||
4863 | if (length >= K_MAX_LENGTH) { | ||
4864 | throw new RangeError('Attempt to allocate Buffer larger than maximum ' + | ||
4865 | 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') | ||
4866 | } | ||
4867 | return length | 0 | ||
4868 | } | ||
4869 | |||
4870 | function SlowBuffer (length) { | ||
4871 | if (+length != length) { // eslint-disable-line eqeqeq | ||
4872 | length = 0 | ||
4873 | } | ||
4874 | return Buffer.alloc(+length) | ||
4875 | } | ||
4876 | |||
4877 | Buffer.isBuffer = function isBuffer (b) { | ||
4878 | return b != null && b._isBuffer === true | ||
4879 | } | ||
4880 | |||
4881 | Buffer.compare = function compare (a, b) { | ||
4882 | if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | ||
4883 | throw new TypeError('Arguments must be Buffers') | ||
4884 | } | ||
4885 | |||
4886 | if (a === b) return 0 | ||
4887 | |||
4888 | var x = a.length | ||
4889 | var y = b.length | ||
4890 | |||
4891 | for (var i = 0, len = Math.min(x, y); i < len; ++i) { | ||
4892 | if (a[i] !== b[i]) { | ||
4893 | x = a[i] | ||
4894 | y = b[i] | ||
4895 | break | ||
4896 | } | ||
4897 | } | ||
4898 | |||
4899 | if (x < y) return -1 | ||
4900 | if (y < x) return 1 | ||
4901 | return 0 | ||
4902 | } | ||
4903 | |||
4904 | Buffer.isEncoding = function isEncoding (encoding) { | ||
4905 | switch (String(encoding).toLowerCase()) { | ||
4906 | case 'hex': | ||
4907 | case 'utf8': | ||
4908 | case 'utf-8': | ||
4909 | case 'ascii': | ||
4910 | case 'latin1': | ||
4911 | case 'binary': | ||
4912 | case 'base64': | ||
4913 | case 'ucs2': | ||
4914 | case 'ucs-2': | ||
4915 | case 'utf16le': | ||
4916 | case 'utf-16le': | ||
4917 | return true | ||
4918 | default: | ||
4919 | return false | ||
4920 | } | ||
4921 | } | ||
4922 | |||
4923 | Buffer.concat = function concat (list, length) { | ||
4924 | if (!Array.isArray(list)) { | ||
4925 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
4926 | } | ||
4927 | |||
4928 | if (list.length === 0) { | ||
4929 | return Buffer.alloc(0) | ||
4930 | } | ||
4931 | |||
4932 | var i | ||
4933 | if (length === undefined) { | ||
4934 | length = 0 | ||
4935 | for (i = 0; i < list.length; ++i) { | ||
4936 | length += list[i].length | ||
4937 | } | ||
4938 | } | ||
4939 | |||
4940 | var buffer = Buffer.allocUnsafe(length) | ||
4941 | var pos = 0 | ||
4942 | for (i = 0; i < list.length; ++i) { | ||
4943 | var buf = list[i] | ||
4944 | if (!Buffer.isBuffer(buf)) { | ||
4945 | throw new TypeError('"list" argument must be an Array of Buffers') | ||
4946 | } | ||
4947 | buf.copy(buffer, pos) | ||
4948 | pos += buf.length | ||
4949 | } | ||
4950 | return buffer | ||
4951 | } | ||
4952 | |||
4953 | function byteLength (string, encoding) { | ||
4954 | if (Buffer.isBuffer(string)) { | ||
4955 | return string.length | ||
4956 | } | ||
4957 | if (isArrayBufferView(string) || string instanceof ArrayBuffer) { | ||
4958 | return string.byteLength | ||
4959 | } | ||
4960 | if (typeof string !== 'string') { | ||
4961 | string = '' + string | ||
4962 | } | ||
4963 | |||
4964 | var len = string.length | ||
4965 | if (len === 0) return 0 | ||
4966 | |||
4967 | // Use a for loop to avoid recursion | ||
4968 | var loweredCase = false | ||
4969 | for (;;) { | ||
4970 | switch (encoding) { | ||
4971 | case 'ascii': | ||
4972 | case 'latin1': | ||
4973 | case 'binary': | ||
4974 | return len | ||
4975 | case 'utf8': | ||
4976 | case 'utf-8': | ||
4977 | case undefined: | ||
4978 | return utf8ToBytes(string).length | ||
4979 | case 'ucs2': | ||
4980 | case 'ucs-2': | ||
4981 | case 'utf16le': | ||
4982 | case 'utf-16le': | ||
4983 | return len * 2 | ||
4984 | case 'hex': | ||
4985 | return len >>> 1 | ||
4986 | case 'base64': | ||
4987 | return base64ToBytes(string).length | ||
4988 | default: | ||
4989 | if (loweredCase) return utf8ToBytes(string).length // assume utf8 | ||
4990 | encoding = ('' + encoding).toLowerCase() | ||
4991 | loweredCase = true | ||
4992 | } | ||
4993 | } | ||
4994 | } | ||
4995 | Buffer.byteLength = byteLength | ||
4996 | |||
4997 | function slowToString (encoding, start, end) { | ||
4998 | var loweredCase = false | ||
4999 | |||
5000 | // No need to verify that "this.length <= MAX_UINT32" since it's a read-only | ||
5001 | // property of a typed array. | ||
5002 | |||
5003 | // This behaves neither like String nor Uint8Array in that we set start/end | ||
5004 | // to their upper/lower bounds if the value passed is out of range. | ||
5005 | // undefined is handled specially as per ECMA-262 6th Edition, | ||
5006 | // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. | ||
5007 | if (start === undefined || start < 0) { | ||
5008 | start = 0 | ||
5009 | } | ||
5010 | // Return early if start > this.length. Done here to prevent potential uint32 | ||
5011 | // coercion fail below. | ||
5012 | if (start > this.length) { | ||
5013 | return '' | ||
5014 | } | ||
5015 | |||
5016 | if (end === undefined || end > this.length) { | ||
5017 | end = this.length | ||
5018 | } | ||
5019 | |||
5020 | if (end <= 0) { | ||
5021 | return '' | ||
5022 | } | ||
5023 | |||
5024 | // Force coersion to uint32. This will also coerce falsey/NaN values to 0. | ||
5025 | end >>>= 0 | ||
5026 | start >>>= 0 | ||
5027 | |||
5028 | if (end <= start) { | ||
5029 | return '' | ||
5030 | } | ||
5031 | |||
5032 | if (!encoding) encoding = 'utf8' | ||
5033 | |||
5034 | while (true) { | ||
5035 | switch (encoding) { | ||
5036 | case 'hex': | ||
5037 | return hexSlice(this, start, end) | ||
5038 | |||
5039 | case 'utf8': | ||
5040 | case 'utf-8': | ||
5041 | return utf8Slice(this, start, end) | ||
5042 | |||
5043 | case 'ascii': | ||
5044 | return asciiSlice(this, start, end) | ||
5045 | |||
5046 | case 'latin1': | ||
5047 | case 'binary': | ||
5048 | return latin1Slice(this, start, end) | ||
5049 | |||
5050 | case 'base64': | ||
5051 | return base64Slice(this, start, end) | ||
5052 | |||
5053 | case 'ucs2': | ||
5054 | case 'ucs-2': | ||
5055 | case 'utf16le': | ||
5056 | case 'utf-16le': | ||
5057 | return utf16leSlice(this, start, end) | ||
5058 | |||
5059 | default: | ||
5060 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
5061 | encoding = (encoding + '').toLowerCase() | ||
5062 | loweredCase = true | ||
5063 | } | ||
5064 | } | ||
5065 | } | ||
5066 | |||
5067 | // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) | ||
5068 | // to detect a Buffer instance. It's not possible to use `instanceof Buffer` | ||
5069 | // reliably in a browserify context because there could be multiple different | ||
5070 | // copies of the 'buffer' package in use. This method works even for Buffer | ||
5071 | // instances that were created from another copy of the `buffer` package. | ||
5072 | // See: https://github.com/feross/buffer/issues/154 | ||
5073 | Buffer.prototype._isBuffer = true | ||
5074 | |||
5075 | function swap (b, n, m) { | ||
5076 | var i = b[n] | ||
5077 | b[n] = b[m] | ||
5078 | b[m] = i | ||
5079 | } | ||
5080 | |||
5081 | Buffer.prototype.swap16 = function swap16 () { | ||
5082 | var len = this.length | ||
5083 | if (len % 2 !== 0) { | ||
5084 | throw new RangeError('Buffer size must be a multiple of 16-bits') | ||
5085 | } | ||
5086 | for (var i = 0; i < len; i += 2) { | ||
5087 | swap(this, i, i + 1) | ||
5088 | } | ||
5089 | return this | ||
5090 | } | ||
5091 | |||
5092 | Buffer.prototype.swap32 = function swap32 () { | ||
5093 | var len = this.length | ||
5094 | if (len % 4 !== 0) { | ||
5095 | throw new RangeError('Buffer size must be a multiple of 32-bits') | ||
5096 | } | ||
5097 | for (var i = 0; i < len; i += 4) { | ||
5098 | swap(this, i, i + 3) | ||
5099 | swap(this, i + 1, i + 2) | ||
5100 | } | ||
5101 | return this | ||
5102 | } | ||
5103 | |||
5104 | Buffer.prototype.swap64 = function swap64 () { | ||
5105 | var len = this.length | ||
5106 | if (len % 8 !== 0) { | ||
5107 | throw new RangeError('Buffer size must be a multiple of 64-bits') | ||
5108 | } | ||
5109 | for (var i = 0; i < len; i += 8) { | ||
5110 | swap(this, i, i + 7) | ||
5111 | swap(this, i + 1, i + 6) | ||
5112 | swap(this, i + 2, i + 5) | ||
5113 | swap(this, i + 3, i + 4) | ||
5114 | } | ||
5115 | return this | ||
5116 | } | ||
5117 | |||
5118 | Buffer.prototype.toString = function toString () { | ||
5119 | var length = this.length | ||
5120 | if (length === 0) return '' | ||
5121 | if (arguments.length === 0) return utf8Slice(this, 0, length) | ||
5122 | return slowToString.apply(this, arguments) | ||
5123 | } | ||
5124 | |||
5125 | Buffer.prototype.equals = function equals (b) { | ||
5126 | if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') | ||
5127 | if (this === b) return true | ||
5128 | return Buffer.compare(this, b) === 0 | ||
5129 | } | ||
5130 | |||
5131 | Buffer.prototype.inspect = function inspect () { | ||
5132 | var str = '' | ||
5133 | var max = exports.INSPECT_MAX_BYTES | ||
5134 | if (this.length > 0) { | ||
5135 | str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') | ||
5136 | if (this.length > max) str += ' ... ' | ||
5137 | } | ||
5138 | return '<Buffer ' + str + '>' | ||
5139 | } | ||
5140 | |||
5141 | Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { | ||
5142 | if (!Buffer.isBuffer(target)) { | ||
5143 | throw new TypeError('Argument must be a Buffer') | ||
5144 | } | ||
5145 | |||
5146 | if (start === undefined) { | ||
5147 | start = 0 | ||
5148 | } | ||
5149 | if (end === undefined) { | ||
5150 | end = target ? target.length : 0 | ||
5151 | } | ||
5152 | if (thisStart === undefined) { | ||
5153 | thisStart = 0 | ||
5154 | } | ||
5155 | if (thisEnd === undefined) { | ||
5156 | thisEnd = this.length | ||
5157 | } | ||
5158 | |||
5159 | if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { | ||
5160 | throw new RangeError('out of range index') | ||
5161 | } | ||
5162 | |||
5163 | if (thisStart >= thisEnd && start >= end) { | ||
5164 | return 0 | ||
5165 | } | ||
5166 | if (thisStart >= thisEnd) { | ||
5167 | return -1 | ||
5168 | } | ||
5169 | if (start >= end) { | ||
5170 | return 1 | ||
5171 | } | ||
5172 | |||
5173 | start >>>= 0 | ||
5174 | end >>>= 0 | ||
5175 | thisStart >>>= 0 | ||
5176 | thisEnd >>>= 0 | ||
5177 | |||
5178 | if (this === target) return 0 | ||
5179 | |||
5180 | var x = thisEnd - thisStart | ||
5181 | var y = end - start | ||
5182 | var len = Math.min(x, y) | ||
5183 | |||
5184 | var thisCopy = this.slice(thisStart, thisEnd) | ||
5185 | var targetCopy = target.slice(start, end) | ||
5186 | |||
5187 | for (var i = 0; i < len; ++i) { | ||
5188 | if (thisCopy[i] !== targetCopy[i]) { | ||
5189 | x = thisCopy[i] | ||
5190 | y = targetCopy[i] | ||
5191 | break | ||
5192 | } | ||
5193 | } | ||
5194 | |||
5195 | if (x < y) return -1 | ||
5196 | if (y < x) return 1 | ||
5197 | return 0 | ||
5198 | } | ||
5199 | |||
5200 | // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, | ||
5201 | // OR the last index of `val` in `buffer` at offset <= `byteOffset`. | ||
5202 | // | ||
5203 | // Arguments: | ||
5204 | // - buffer - a Buffer to search | ||
5205 | // - val - a string, Buffer, or number | ||
5206 | // - byteOffset - an index into `buffer`; will be clamped to an int32 | ||
5207 | // - encoding - an optional encoding, relevant is val is a string | ||
5208 | // - dir - true for indexOf, false for lastIndexOf | ||
5209 | function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { | ||
5210 | // Empty buffer means no match | ||
5211 | if (buffer.length === 0) return -1 | ||
5212 | |||
5213 | // Normalize byteOffset | ||
5214 | if (typeof byteOffset === 'string') { | ||
5215 | encoding = byteOffset | ||
5216 | byteOffset = 0 | ||
5217 | } else if (byteOffset > 0x7fffffff) { | ||
5218 | byteOffset = 0x7fffffff | ||
5219 | } else if (byteOffset < -0x80000000) { | ||
5220 | byteOffset = -0x80000000 | ||
5221 | } | ||
5222 | byteOffset = +byteOffset // Coerce to Number. | ||
5223 | if (numberIsNaN(byteOffset)) { | ||
5224 | // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer | ||
5225 | byteOffset = dir ? 0 : (buffer.length - 1) | ||
5226 | } | ||
5227 | |||
5228 | // Normalize byteOffset: negative offsets start from the end of the buffer | ||
5229 | if (byteOffset < 0) byteOffset = buffer.length + byteOffset | ||
5230 | if (byteOffset >= buffer.length) { | ||
5231 | if (dir) return -1 | ||
5232 | else byteOffset = buffer.length - 1 | ||
5233 | } else if (byteOffset < 0) { | ||
5234 | if (dir) byteOffset = 0 | ||
5235 | else return -1 | ||
5236 | } | ||
5237 | |||
5238 | // Normalize val | ||
5239 | if (typeof val === 'string') { | ||
5240 | val = Buffer.from(val, encoding) | ||
5241 | } | ||
5242 | |||
5243 | // Finally, search either indexOf (if dir is true) or lastIndexOf | ||
5244 | if (Buffer.isBuffer(val)) { | ||
5245 | // Special case: looking for empty string/buffer always fails | ||
5246 | if (val.length === 0) { | ||
5247 | return -1 | ||
5248 | } | ||
5249 | return arrayIndexOf(buffer, val, byteOffset, encoding, dir) | ||
5250 | } else if (typeof val === 'number') { | ||
5251 | val = val & 0xFF // Search for a byte value [0-255] | ||
5252 | if (typeof Uint8Array.prototype.indexOf === 'function') { | ||
5253 | if (dir) { | ||
5254 | return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) | ||
5255 | } else { | ||
5256 | return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) | ||
5257 | } | ||
5258 | } | ||
5259 | return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) | ||
5260 | } | ||
5261 | |||
5262 | throw new TypeError('val must be string, number or Buffer') | ||
5263 | } | ||
5264 | |||
5265 | function arrayIndexOf (arr, val, byteOffset, encoding, dir) { | ||
5266 | var indexSize = 1 | ||
5267 | var arrLength = arr.length | ||
5268 | var valLength = val.length | ||
5269 | |||
5270 | if (encoding !== undefined) { | ||
5271 | encoding = String(encoding).toLowerCase() | ||
5272 | if (encoding === 'ucs2' || encoding === 'ucs-2' || | ||
5273 | encoding === 'utf16le' || encoding === 'utf-16le') { | ||
5274 | if (arr.length < 2 || val.length < 2) { | ||
5275 | return -1 | ||
5276 | } | ||
5277 | indexSize = 2 | ||
5278 | arrLength /= 2 | ||
5279 | valLength /= 2 | ||
5280 | byteOffset /= 2 | ||
5281 | } | ||
5282 | } | ||
5283 | |||
5284 | function read (buf, i) { | ||
5285 | if (indexSize === 1) { | ||
5286 | return buf[i] | ||
5287 | } else { | ||
5288 | return buf.readUInt16BE(i * indexSize) | ||
5289 | } | ||
5290 | } | ||
5291 | |||
5292 | var i | ||
5293 | if (dir) { | ||
5294 | var foundIndex = -1 | ||
5295 | for (i = byteOffset; i < arrLength; i++) { | ||
5296 | if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { | ||
5297 | if (foundIndex === -1) foundIndex = i | ||
5298 | if (i - foundIndex + 1 === valLength) return foundIndex * indexSize | ||
5299 | } else { | ||
5300 | if (foundIndex !== -1) i -= i - foundIndex | ||
5301 | foundIndex = -1 | ||
5302 | } | ||
5303 | } | ||
5304 | } else { | ||
5305 | if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength | ||
5306 | for (i = byteOffset; i >= 0; i--) { | ||
5307 | var found = true | ||
5308 | for (var j = 0; j < valLength; j++) { | ||
5309 | if (read(arr, i + j) !== read(val, j)) { | ||
5310 | found = false | ||
5311 | break | ||
5312 | } | ||
5313 | } | ||
5314 | if (found) return i | ||
5315 | } | ||
5316 | } | ||
5317 | |||
5318 | return -1 | ||
5319 | } | ||
5320 | |||
5321 | Buffer.prototype.includes = function includes (val, byteOffset, encoding) { | ||
5322 | return this.indexOf(val, byteOffset, encoding) !== -1 | ||
5323 | } | ||
5324 | |||
5325 | Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { | ||
5326 | return bidirectionalIndexOf(this, val, byteOffset, encoding, true) | ||
5327 | } | ||
5328 | |||
5329 | Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { | ||
5330 | return bidirectionalIndexOf(this, val, byteOffset, encoding, false) | ||
5331 | } | ||
5332 | |||
5333 | function hexWrite (buf, string, offset, length) { | ||
5334 | offset = Number(offset) || 0 | ||
5335 | var remaining = buf.length - offset | ||
5336 | if (!length) { | ||
5337 | length = remaining | ||
5338 | } else { | ||
5339 | length = Number(length) | ||
5340 | if (length > remaining) { | ||
5341 | length = remaining | ||
5342 | } | ||
5343 | } | ||
5344 | |||
5345 | // must be an even number of digits | ||
5346 | var strLen = string.length | ||
5347 | if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') | ||
5348 | |||
5349 | if (length > strLen / 2) { | ||
5350 | length = strLen / 2 | ||
5351 | } | ||
5352 | for (var i = 0; i < length; ++i) { | ||
5353 | var parsed = parseInt(string.substr(i * 2, 2), 16) | ||
5354 | if (numberIsNaN(parsed)) return i | ||
5355 | buf[offset + i] = parsed | ||
5356 | } | ||
5357 | return i | ||
5358 | } | ||
5359 | |||
5360 | function utf8Write (buf, string, offset, length) { | ||
5361 | return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length) | ||
5362 | } | ||
5363 | |||
5364 | function asciiWrite (buf, string, offset, length) { | ||
5365 | return blitBuffer(asciiToBytes(string), buf, offset, length) | ||
5366 | } | ||
5367 | |||
5368 | function latin1Write (buf, string, offset, length) { | ||
5369 | return asciiWrite(buf, string, offset, length) | ||
5370 | } | ||
5371 | |||
5372 | function base64Write (buf, string, offset, length) { | ||
5373 | return blitBuffer(base64ToBytes(string), buf, offset, length) | ||
5374 | } | ||
5375 | |||
5376 | function ucs2Write (buf, string, offset, length) { | ||
5377 | return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length) | ||
5378 | } | ||
5379 | |||
5380 | Buffer.prototype.write = function write (string, offset, length, encoding) { | ||
5381 | // Buffer#write(string) | ||
5382 | if (offset === undefined) { | ||
5383 | encoding = 'utf8' | ||
5384 | length = this.length | ||
5385 | offset = 0 | ||
5386 | // Buffer#write(string, encoding) | ||
5387 | } else if (length === undefined && typeof offset === 'string') { | ||
5388 | encoding = offset | ||
5389 | length = this.length | ||
5390 | offset = 0 | ||
5391 | // Buffer#write(string, offset[, length][, encoding]) | ||
5392 | } else if (isFinite(offset)) { | ||
5393 | offset = offset >>> 0 | ||
5394 | if (isFinite(length)) { | ||
5395 | length = length >>> 0 | ||
5396 | if (encoding === undefined) encoding = 'utf8' | ||
5397 | } else { | ||
5398 | encoding = length | ||
5399 | length = undefined | ||
5400 | } | ||
5401 | } else { | ||
5402 | throw new Error( | ||
5403 | 'Buffer.write(string, encoding, offset[, length]) is no longer supported' | ||
5404 | ) | ||
5405 | } | ||
5406 | |||
5407 | var remaining = this.length - offset | ||
5408 | if (length === undefined || length > remaining) length = remaining | ||
5409 | |||
5410 | if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { | ||
5411 | throw new RangeError('Attempt to write outside buffer bounds') | ||
5412 | } | ||
5413 | |||
5414 | if (!encoding) encoding = 'utf8' | ||
5415 | |||
5416 | var loweredCase = false | ||
5417 | for (;;) { | ||
5418 | switch (encoding) { | ||
5419 | case 'hex': | ||
5420 | return hexWrite(this, string, offset, length) | ||
5421 | |||
5422 | case 'utf8': | ||
5423 | case 'utf-8': | ||
5424 | return utf8Write(this, string, offset, length) | ||
5425 | |||
5426 | case 'ascii': | ||
5427 | return asciiWrite(this, string, offset, length) | ||
5428 | |||
5429 | case 'latin1': | ||
5430 | case 'binary': | ||
5431 | return latin1Write(this, string, offset, length) | ||
5432 | |||
5433 | case 'base64': | ||
5434 | // Warning: maxLength not taken into account in base64Write | ||
5435 | return base64Write(this, string, offset, length) | ||
5436 | |||
5437 | case 'ucs2': | ||
5438 | case 'ucs-2': | ||
5439 | case 'utf16le': | ||
5440 | case 'utf-16le': | ||
5441 | return ucs2Write(this, string, offset, length) | ||
5442 | |||
5443 | default: | ||
5444 | if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding) | ||
5445 | encoding = ('' + encoding).toLowerCase() | ||
5446 | loweredCase = true | ||
5447 | } | ||
5448 | } | ||
5449 | } | ||
5450 | |||
5451 | Buffer.prototype.toJSON = function toJSON () { | ||
5452 | return { | ||
5453 | type: 'Buffer', | ||
5454 | data: Array.prototype.slice.call(this._arr || this, 0) | ||
5455 | } | ||
5456 | } | ||
5457 | |||
5458 | function base64Slice (buf, start, end) { | ||
5459 | if (start === 0 && end === buf.length) { | ||
5460 | return base64.fromByteArray(buf) | ||
5461 | } else { | ||
5462 | return base64.fromByteArray(buf.slice(start, end)) | ||
5463 | } | ||
5464 | } | ||
5465 | |||
5466 | function utf8Slice (buf, start, end) { | ||
5467 | end = Math.min(buf.length, end) | ||
5468 | var res = [] | ||
5469 | |||
5470 | var i = start | ||
5471 | while (i < end) { | ||
5472 | var firstByte = buf[i] | ||
5473 | var codePoint = null | ||
5474 | var bytesPerSequence = (firstByte > 0xEF) ? 4 | ||
5475 | : (firstByte > 0xDF) ? 3 | ||
5476 | : (firstByte > 0xBF) ? 2 | ||
5477 | : 1 | ||
5478 | |||
5479 | if (i + bytesPerSequence <= end) { | ||
5480 | var secondByte, thirdByte, fourthByte, tempCodePoint | ||
5481 | |||
5482 | switch (bytesPerSequence) { | ||
5483 | case 1: | ||
5484 | if (firstByte < 0x80) { | ||
5485 | codePoint = firstByte | ||
5486 | } | ||
5487 | break | ||
5488 | case 2: | ||
5489 | secondByte = buf[i + 1] | ||
5490 | if ((secondByte & 0xC0) === 0x80) { | ||
5491 | tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F) | ||
5492 | if (tempCodePoint > 0x7F) { | ||
5493 | codePoint = tempCodePoint | ||
5494 | } | ||
5495 | } | ||
5496 | break | ||
5497 | case 3: | ||
5498 | secondByte = buf[i + 1] | ||
5499 | thirdByte = buf[i + 2] | ||
5500 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) { | ||
5501 | tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F) | ||
5502 | if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) { | ||
5503 | codePoint = tempCodePoint | ||
5504 | } | ||
5505 | } | ||
5506 | break | ||
5507 | case 4: | ||
5508 | secondByte = buf[i + 1] | ||
5509 | thirdByte = buf[i + 2] | ||
5510 | fourthByte = buf[i + 3] | ||
5511 | if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) { | ||
5512 | tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F) | ||
5513 | if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) { | ||
5514 | codePoint = tempCodePoint | ||
5515 | } | ||
5516 | } | ||
5517 | } | ||
5518 | } | ||
5519 | |||
5520 | if (codePoint === null) { | ||
5521 | // we did not generate a valid codePoint so insert a | ||
5522 | // replacement char (U+FFFD) and advance only 1 byte | ||
5523 | codePoint = 0xFFFD | ||
5524 | bytesPerSequence = 1 | ||
5525 | } else if (codePoint > 0xFFFF) { | ||
5526 | // encode to utf16 (surrogate pair dance) | ||
5527 | codePoint -= 0x10000 | ||
5528 | res.push(codePoint >>> 10 & 0x3FF | 0xD800) | ||
5529 | codePoint = 0xDC00 | codePoint & 0x3FF | ||
5530 | } | ||
5531 | |||
5532 | res.push(codePoint) | ||
5533 | i += bytesPerSequence | ||
5534 | } | ||
5535 | |||
5536 | return decodeCodePointsArray(res) | ||
5537 | } | ||
5538 | |||
5539 | // Based on http://stackoverflow.com/a/22747272/680742, the browser with | ||
5540 | // the lowest limit is Chrome, with 0x10000 args. | ||
5541 | // We go 1 magnitude less, for safety | ||
5542 | var MAX_ARGUMENTS_LENGTH = 0x1000 | ||
5543 | |||
5544 | function decodeCodePointsArray (codePoints) { | ||
5545 | var len = codePoints.length | ||
5546 | if (len <= MAX_ARGUMENTS_LENGTH) { | ||
5547 | return String.fromCharCode.apply(String, codePoints) // avoid extra slice() | ||
5548 | } | ||
5549 | |||
5550 | // Decode in chunks to avoid "call stack size exceeded". | ||
5551 | var res = '' | ||
5552 | var i = 0 | ||
5553 | while (i < len) { | ||
5554 | res += String.fromCharCode.apply( | ||
5555 | String, | ||
5556 | codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH) | ||
5557 | ) | ||
5558 | } | ||
5559 | return res | ||
5560 | } | ||
5561 | |||
5562 | function asciiSlice (buf, start, end) { | ||
5563 | var ret = '' | ||
5564 | end = Math.min(buf.length, end) | ||
5565 | |||
5566 | for (var i = start; i < end; ++i) { | ||
5567 | ret += String.fromCharCode(buf[i] & 0x7F) | ||
5568 | } | ||
5569 | return ret | ||
5570 | } | ||
5571 | |||
5572 | function latin1Slice (buf, start, end) { | ||
5573 | var ret = '' | ||
5574 | end = Math.min(buf.length, end) | ||
5575 | |||
5576 | for (var i = start; i < end; ++i) { | ||
5577 | ret += String.fromCharCode(buf[i]) | ||
5578 | } | ||
5579 | return ret | ||
5580 | } | ||
5581 | |||
5582 | function hexSlice (buf, start, end) { | ||
5583 | var len = buf.length | ||
5584 | |||
5585 | if (!start || start < 0) start = 0 | ||
5586 | if (!end || end < 0 || end > len) end = len | ||
5587 | |||
5588 | var out = '' | ||
5589 | for (var i = start; i < end; ++i) { | ||
5590 | out += toHex(buf[i]) | ||
5591 | } | ||
5592 | return out | ||
5593 | } | ||
5594 | |||
5595 | function utf16leSlice (buf, start, end) { | ||
5596 | var bytes = buf.slice(start, end) | ||
5597 | var res = '' | ||
5598 | for (var i = 0; i < bytes.length; i += 2) { | ||
5599 | res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) | ||
5600 | } | ||
5601 | return res | ||
5602 | } | ||
5603 | |||
5604 | Buffer.prototype.slice = function slice (start, end) { | ||
5605 | var len = this.length | ||
5606 | start = ~~start | ||
5607 | end = end === undefined ? len : ~~end | ||
5608 | |||
5609 | if (start < 0) { | ||
5610 | start += len | ||
5611 | if (start < 0) start = 0 | ||
5612 | } else if (start > len) { | ||
5613 | start = len | ||
5614 | } | ||
5615 | |||
5616 | if (end < 0) { | ||
5617 | end += len | ||
5618 | if (end < 0) end = 0 | ||
5619 | } else if (end > len) { | ||
5620 | end = len | ||
5621 | } | ||
5622 | |||
5623 | if (end < start) end = start | ||
5624 | |||
5625 | var newBuf = this.subarray(start, end) | ||
5626 | // Return an augmented `Uint8Array` instance | ||
5627 | newBuf.__proto__ = Buffer.prototype | ||
5628 | return newBuf | ||
5629 | } | ||
5630 | |||
5631 | /* | ||
5632 | * Need to make sure that buffer isn't trying to write out of bounds. | ||
5633 | */ | ||
5634 | function checkOffset (offset, ext, length) { | ||
5635 | if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint') | ||
5636 | if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length') | ||
5637 | } | ||
5638 | |||
5639 | Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { | ||
5640 | offset = offset >>> 0 | ||
5641 | byteLength = byteLength >>> 0 | ||
5642 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
5643 | |||
5644 | var val = this[offset] | ||
5645 | var mul = 1 | ||
5646 | var i = 0 | ||
5647 | while (++i < byteLength && (mul *= 0x100)) { | ||
5648 | val += this[offset + i] * mul | ||
5649 | } | ||
5650 | |||
5651 | return val | ||
5652 | } | ||
5653 | |||
5654 | Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { | ||
5655 | offset = offset >>> 0 | ||
5656 | byteLength = byteLength >>> 0 | ||
5657 | if (!noAssert) { | ||
5658 | checkOffset(offset, byteLength, this.length) | ||
5659 | } | ||
5660 | |||
5661 | var val = this[offset + --byteLength] | ||
5662 | var mul = 1 | ||
5663 | while (byteLength > 0 && (mul *= 0x100)) { | ||
5664 | val += this[offset + --byteLength] * mul | ||
5665 | } | ||
5666 | |||
5667 | return val | ||
5668 | } | ||
5669 | |||
5670 | Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { | ||
5671 | offset = offset >>> 0 | ||
5672 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
5673 | return this[offset] | ||
5674 | } | ||
5675 | |||
5676 | Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { | ||
5677 | offset = offset >>> 0 | ||
5678 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
5679 | return this[offset] | (this[offset + 1] << 8) | ||
5680 | } | ||
5681 | |||
5682 | Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { | ||
5683 | offset = offset >>> 0 | ||
5684 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
5685 | return (this[offset] << 8) | this[offset + 1] | ||
5686 | } | ||
5687 | |||
5688 | Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { | ||
5689 | offset = offset >>> 0 | ||
5690 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
5691 | |||
5692 | return ((this[offset]) | | ||
5693 | (this[offset + 1] << 8) | | ||
5694 | (this[offset + 2] << 16)) + | ||
5695 | (this[offset + 3] * 0x1000000) | ||
5696 | } | ||
5697 | |||
5698 | Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { | ||
5699 | offset = offset >>> 0 | ||
5700 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
5701 | |||
5702 | return (this[offset] * 0x1000000) + | ||
5703 | ((this[offset + 1] << 16) | | ||
5704 | (this[offset + 2] << 8) | | ||
5705 | this[offset + 3]) | ||
5706 | } | ||
5707 | |||
5708 | Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { | ||
5709 | offset = offset >>> 0 | ||
5710 | byteLength = byteLength >>> 0 | ||
5711 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
5712 | |||
5713 | var val = this[offset] | ||
5714 | var mul = 1 | ||
5715 | var i = 0 | ||
5716 | while (++i < byteLength && (mul *= 0x100)) { | ||
5717 | val += this[offset + i] * mul | ||
5718 | } | ||
5719 | mul *= 0x80 | ||
5720 | |||
5721 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
5722 | |||
5723 | return val | ||
5724 | } | ||
5725 | |||
5726 | Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { | ||
5727 | offset = offset >>> 0 | ||
5728 | byteLength = byteLength >>> 0 | ||
5729 | if (!noAssert) checkOffset(offset, byteLength, this.length) | ||
5730 | |||
5731 | var i = byteLength | ||
5732 | var mul = 1 | ||
5733 | var val = this[offset + --i] | ||
5734 | while (i > 0 && (mul *= 0x100)) { | ||
5735 | val += this[offset + --i] * mul | ||
5736 | } | ||
5737 | mul *= 0x80 | ||
5738 | |||
5739 | if (val >= mul) val -= Math.pow(2, 8 * byteLength) | ||
5740 | |||
5741 | return val | ||
5742 | } | ||
5743 | |||
5744 | Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { | ||
5745 | offset = offset >>> 0 | ||
5746 | if (!noAssert) checkOffset(offset, 1, this.length) | ||
5747 | if (!(this[offset] & 0x80)) return (this[offset]) | ||
5748 | return ((0xff - this[offset] + 1) * -1) | ||
5749 | } | ||
5750 | |||
5751 | Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { | ||
5752 | offset = offset >>> 0 | ||
5753 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
5754 | var val = this[offset] | (this[offset + 1] << 8) | ||
5755 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
5756 | } | ||
5757 | |||
5758 | Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { | ||
5759 | offset = offset >>> 0 | ||
5760 | if (!noAssert) checkOffset(offset, 2, this.length) | ||
5761 | var val = this[offset + 1] | (this[offset] << 8) | ||
5762 | return (val & 0x8000) ? val | 0xFFFF0000 : val | ||
5763 | } | ||
5764 | |||
5765 | Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { | ||
5766 | offset = offset >>> 0 | ||
5767 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
5768 | |||
5769 | return (this[offset]) | | ||
5770 | (this[offset + 1] << 8) | | ||
5771 | (this[offset + 2] << 16) | | ||
5772 | (this[offset + 3] << 24) | ||
5773 | } | ||
5774 | |||
5775 | Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { | ||
5776 | offset = offset >>> 0 | ||
5777 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
5778 | |||
5779 | return (this[offset] << 24) | | ||
5780 | (this[offset + 1] << 16) | | ||
5781 | (this[offset + 2] << 8) | | ||
5782 | (this[offset + 3]) | ||
5783 | } | ||
5784 | |||
5785 | Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { | ||
5786 | offset = offset >>> 0 | ||
5787 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
5788 | return ieee754.read(this, offset, true, 23, 4) | ||
5789 | } | ||
5790 | |||
5791 | Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { | ||
5792 | offset = offset >>> 0 | ||
5793 | if (!noAssert) checkOffset(offset, 4, this.length) | ||
5794 | return ieee754.read(this, offset, false, 23, 4) | ||
5795 | } | ||
5796 | |||
5797 | Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { | ||
5798 | offset = offset >>> 0 | ||
5799 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
5800 | return ieee754.read(this, offset, true, 52, 8) | ||
5801 | } | ||
5802 | |||
5803 | Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { | ||
5804 | offset = offset >>> 0 | ||
5805 | if (!noAssert) checkOffset(offset, 8, this.length) | ||
5806 | return ieee754.read(this, offset, false, 52, 8) | ||
5807 | } | ||
5808 | |||
5809 | function checkInt (buf, value, offset, ext, max, min) { | ||
5810 | if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') | ||
5811 | if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') | ||
5812 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
5813 | } | ||
5814 | |||
5815 | Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { | ||
5816 | value = +value | ||
5817 | offset = offset >>> 0 | ||
5818 | byteLength = byteLength >>> 0 | ||
5819 | if (!noAssert) { | ||
5820 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
5821 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
5822 | } | ||
5823 | |||
5824 | var mul = 1 | ||
5825 | var i = 0 | ||
5826 | this[offset] = value & 0xFF | ||
5827 | while (++i < byteLength && (mul *= 0x100)) { | ||
5828 | this[offset + i] = (value / mul) & 0xFF | ||
5829 | } | ||
5830 | |||
5831 | return offset + byteLength | ||
5832 | } | ||
5833 | |||
5834 | Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { | ||
5835 | value = +value | ||
5836 | offset = offset >>> 0 | ||
5837 | byteLength = byteLength >>> 0 | ||
5838 | if (!noAssert) { | ||
5839 | var maxBytes = Math.pow(2, 8 * byteLength) - 1 | ||
5840 | checkInt(this, value, offset, byteLength, maxBytes, 0) | ||
5841 | } | ||
5842 | |||
5843 | var i = byteLength - 1 | ||
5844 | var mul = 1 | ||
5845 | this[offset + i] = value & 0xFF | ||
5846 | while (--i >= 0 && (mul *= 0x100)) { | ||
5847 | this[offset + i] = (value / mul) & 0xFF | ||
5848 | } | ||
5849 | |||
5850 | return offset + byteLength | ||
5851 | } | ||
5852 | |||
5853 | Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { | ||
5854 | value = +value | ||
5855 | offset = offset >>> 0 | ||
5856 | if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) | ||
5857 | this[offset] = (value & 0xff) | ||
5858 | return offset + 1 | ||
5859 | } | ||
5860 | |||
5861 | Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { | ||
5862 | value = +value | ||
5863 | offset = offset >>> 0 | ||
5864 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
5865 | this[offset] = (value & 0xff) | ||
5866 | this[offset + 1] = (value >>> 8) | ||
5867 | return offset + 2 | ||
5868 | } | ||
5869 | |||
5870 | Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { | ||
5871 | value = +value | ||
5872 | offset = offset >>> 0 | ||
5873 | if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) | ||
5874 | this[offset] = (value >>> 8) | ||
5875 | this[offset + 1] = (value & 0xff) | ||
5876 | return offset + 2 | ||
5877 | } | ||
5878 | |||
5879 | Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { | ||
5880 | value = +value | ||
5881 | offset = offset >>> 0 | ||
5882 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
5883 | this[offset + 3] = (value >>> 24) | ||
5884 | this[offset + 2] = (value >>> 16) | ||
5885 | this[offset + 1] = (value >>> 8) | ||
5886 | this[offset] = (value & 0xff) | ||
5887 | return offset + 4 | ||
5888 | } | ||
5889 | |||
5890 | Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { | ||
5891 | value = +value | ||
5892 | offset = offset >>> 0 | ||
5893 | if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) | ||
5894 | this[offset] = (value >>> 24) | ||
5895 | this[offset + 1] = (value >>> 16) | ||
5896 | this[offset + 2] = (value >>> 8) | ||
5897 | this[offset + 3] = (value & 0xff) | ||
5898 | return offset + 4 | ||
5899 | } | ||
5900 | |||
5901 | Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { | ||
5902 | value = +value | ||
5903 | offset = offset >>> 0 | ||
5904 | if (!noAssert) { | ||
5905 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
5906 | |||
5907 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
5908 | } | ||
5909 | |||
5910 | var i = 0 | ||
5911 | var mul = 1 | ||
5912 | var sub = 0 | ||
5913 | this[offset] = value & 0xFF | ||
5914 | while (++i < byteLength && (mul *= 0x100)) { | ||
5915 | if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { | ||
5916 | sub = 1 | ||
5917 | } | ||
5918 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
5919 | } | ||
5920 | |||
5921 | return offset + byteLength | ||
5922 | } | ||
5923 | |||
5924 | Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { | ||
5925 | value = +value | ||
5926 | offset = offset >>> 0 | ||
5927 | if (!noAssert) { | ||
5928 | var limit = Math.pow(2, (8 * byteLength) - 1) | ||
5929 | |||
5930 | checkInt(this, value, offset, byteLength, limit - 1, -limit) | ||
5931 | } | ||
5932 | |||
5933 | var i = byteLength - 1 | ||
5934 | var mul = 1 | ||
5935 | var sub = 0 | ||
5936 | this[offset + i] = value & 0xFF | ||
5937 | while (--i >= 0 && (mul *= 0x100)) { | ||
5938 | if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { | ||
5939 | sub = 1 | ||
5940 | } | ||
5941 | this[offset + i] = ((value / mul) >> 0) - sub & 0xFF | ||
5942 | } | ||
5943 | |||
5944 | return offset + byteLength | ||
5945 | } | ||
5946 | |||
5947 | Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { | ||
5948 | value = +value | ||
5949 | offset = offset >>> 0 | ||
5950 | if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) | ||
5951 | if (value < 0) value = 0xff + value + 1 | ||
5952 | this[offset] = (value & 0xff) | ||
5953 | return offset + 1 | ||
5954 | } | ||
5955 | |||
5956 | Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { | ||
5957 | value = +value | ||
5958 | offset = offset >>> 0 | ||
5959 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
5960 | this[offset] = (value & 0xff) | ||
5961 | this[offset + 1] = (value >>> 8) | ||
5962 | return offset + 2 | ||
5963 | } | ||
5964 | |||
5965 | Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { | ||
5966 | value = +value | ||
5967 | offset = offset >>> 0 | ||
5968 | if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) | ||
5969 | this[offset] = (value >>> 8) | ||
5970 | this[offset + 1] = (value & 0xff) | ||
5971 | return offset + 2 | ||
5972 | } | ||
5973 | |||
5974 | Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { | ||
5975 | value = +value | ||
5976 | offset = offset >>> 0 | ||
5977 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
5978 | this[offset] = (value & 0xff) | ||
5979 | this[offset + 1] = (value >>> 8) | ||
5980 | this[offset + 2] = (value >>> 16) | ||
5981 | this[offset + 3] = (value >>> 24) | ||
5982 | return offset + 4 | ||
5983 | } | ||
5984 | |||
5985 | Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { | ||
5986 | value = +value | ||
5987 | offset = offset >>> 0 | ||
5988 | if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) | ||
5989 | if (value < 0) value = 0xffffffff + value + 1 | ||
5990 | this[offset] = (value >>> 24) | ||
5991 | this[offset + 1] = (value >>> 16) | ||
5992 | this[offset + 2] = (value >>> 8) | ||
5993 | this[offset + 3] = (value & 0xff) | ||
5994 | return offset + 4 | ||
5995 | } | ||
5996 | |||
5997 | function checkIEEE754 (buf, value, offset, ext, max, min) { | ||
5998 | if (offset + ext > buf.length) throw new RangeError('Index out of range') | ||
5999 | if (offset < 0) throw new RangeError('Index out of range') | ||
6000 | } | ||
6001 | |||
6002 | function writeFloat (buf, value, offset, littleEndian, noAssert) { | ||
6003 | value = +value | ||
6004 | offset = offset >>> 0 | ||
6005 | if (!noAssert) { | ||
6006 | checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) | ||
6007 | } | ||
6008 | ieee754.write(buf, value, offset, littleEndian, 23, 4) | ||
6009 | return offset + 4 | ||
6010 | } | ||
6011 | |||
6012 | Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) { | ||
6013 | return writeFloat(this, value, offset, true, noAssert) | ||
6014 | } | ||
6015 | |||
6016 | Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) { | ||
6017 | return writeFloat(this, value, offset, false, noAssert) | ||
6018 | } | ||
6019 | |||
6020 | function writeDouble (buf, value, offset, littleEndian, noAssert) { | ||
6021 | value = +value | ||
6022 | offset = offset >>> 0 | ||
6023 | if (!noAssert) { | ||
6024 | checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) | ||
6025 | } | ||
6026 | ieee754.write(buf, value, offset, littleEndian, 52, 8) | ||
6027 | return offset + 8 | ||
6028 | } | ||
6029 | |||
6030 | Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) { | ||
6031 | return writeDouble(this, value, offset, true, noAssert) | ||
6032 | } | ||
6033 | |||
6034 | Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) { | ||
6035 | return writeDouble(this, value, offset, false, noAssert) | ||
6036 | } | ||
6037 | |||
6038 | // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) | ||
6039 | Buffer.prototype.copy = function copy (target, targetStart, start, end) { | ||
6040 | if (!start) start = 0 | ||
6041 | if (!end && end !== 0) end = this.length | ||
6042 | if (targetStart >= target.length) targetStart = target.length | ||
6043 | if (!targetStart) targetStart = 0 | ||
6044 | if (end > 0 && end < start) end = start | ||
6045 | |||
6046 | // Copy 0 bytes; we're done | ||
6047 | if (end === start) return 0 | ||
6048 | if (target.length === 0 || this.length === 0) return 0 | ||
6049 | |||
6050 | // Fatal error conditions | ||
6051 | if (targetStart < 0) { | ||
6052 | throw new RangeError('targetStart out of bounds') | ||
6053 | } | ||
6054 | if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds') | ||
6055 | if (end < 0) throw new RangeError('sourceEnd out of bounds') | ||
6056 | |||
6057 | // Are we oob? | ||
6058 | if (end > this.length) end = this.length | ||
6059 | if (target.length - targetStart < end - start) { | ||
6060 | end = target.length - targetStart + start | ||
6061 | } | ||
6062 | |||
6063 | var len = end - start | ||
6064 | var i | ||
6065 | |||
6066 | if (this === target && start < targetStart && targetStart < end) { | ||
6067 | // descending copy from end | ||
6068 | for (i = len - 1; i >= 0; --i) { | ||
6069 | target[i + targetStart] = this[i + start] | ||
6070 | } | ||
6071 | } else if (len < 1000) { | ||
6072 | // ascending copy from start | ||
6073 | for (i = 0; i < len; ++i) { | ||
6074 | target[i + targetStart] = this[i + start] | ||
6075 | } | ||
6076 | } else { | ||
6077 | Uint8Array.prototype.set.call( | ||
6078 | target, | ||
6079 | this.subarray(start, start + len), | ||
6080 | targetStart | ||
6081 | ) | ||
6082 | } | ||
6083 | |||
6084 | return len | ||
6085 | } | ||
6086 | |||
6087 | // Usage: | ||
6088 | // buffer.fill(number[, offset[, end]]) | ||
6089 | // buffer.fill(buffer[, offset[, end]]) | ||
6090 | // buffer.fill(string[, offset[, end]][, encoding]) | ||
6091 | Buffer.prototype.fill = function fill (val, start, end, encoding) { | ||
6092 | // Handle string cases: | ||
6093 | if (typeof val === 'string') { | ||
6094 | if (typeof start === 'string') { | ||
6095 | encoding = start | ||
6096 | start = 0 | ||
6097 | end = this.length | ||
6098 | } else if (typeof end === 'string') { | ||
6099 | encoding = end | ||
6100 | end = this.length | ||
6101 | } | ||
6102 | if (val.length === 1) { | ||
6103 | var code = val.charCodeAt(0) | ||
6104 | if (code < 256) { | ||
6105 | val = code | ||
6106 | } | ||
6107 | } | ||
6108 | if (encoding !== undefined && typeof encoding !== 'string') { | ||
6109 | throw new TypeError('encoding must be a string') | ||
6110 | } | ||
6111 | if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { | ||
6112 | throw new TypeError('Unknown encoding: ' + encoding) | ||
6113 | } | ||
6114 | } else if (typeof val === 'number') { | ||
6115 | val = val & 255 | ||
6116 | } | ||
6117 | |||
6118 | // Invalid ranges are not set to a default, so can range check early. | ||
6119 | if (start < 0 || this.length < start || this.length < end) { | ||
6120 | throw new RangeError('Out of range index') | ||
6121 | } | ||
6122 | |||
6123 | if (end <= start) { | ||
6124 | return this | ||
6125 | } | ||
6126 | |||
6127 | start = start >>> 0 | ||
6128 | end = end === undefined ? this.length : end >>> 0 | ||
6129 | |||
6130 | if (!val) val = 0 | ||
6131 | |||
6132 | var i | ||
6133 | if (typeof val === 'number') { | ||
6134 | for (i = start; i < end; ++i) { | ||
6135 | this[i] = val | ||
6136 | } | ||
6137 | } else { | ||
6138 | var bytes = Buffer.isBuffer(val) | ||
6139 | ? val | ||
6140 | : new Buffer(val, encoding) | ||
6141 | var len = bytes.length | ||
6142 | for (i = 0; i < end - start; ++i) { | ||
6143 | this[i + start] = bytes[i % len] | ||
6144 | } | ||
6145 | } | ||
6146 | |||
6147 | return this | ||
6148 | } | ||
6149 | |||
6150 | // HELPER FUNCTIONS | ||
6151 | // ================ | ||
6152 | |||
6153 | var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g | ||
6154 | |||
6155 | function base64clean (str) { | ||
6156 | // Node strips out invalid characters like \n and \t from the string, base64-js does not | ||
6157 | str = str.trim().replace(INVALID_BASE64_RE, '') | ||
6158 | // Node converts strings with length < 2 to '' | ||
6159 | if (str.length < 2) return '' | ||
6160 | // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not | ||
6161 | while (str.length % 4 !== 0) { | ||
6162 | str = str + '=' | ||
6163 | } | ||
6164 | return str | ||
6165 | } | ||
6166 | |||
6167 | function toHex (n) { | ||
6168 | if (n < 16) return '0' + n.toString(16) | ||
6169 | return n.toString(16) | ||
6170 | } | ||
6171 | |||
6172 | function utf8ToBytes (string, units) { | ||
6173 | units = units || Infinity | ||
6174 | var codePoint | ||
6175 | var length = string.length | ||
6176 | var leadSurrogate = null | ||
6177 | var bytes = [] | ||
6178 | |||
6179 | for (var i = 0; i < length; ++i) { | ||
6180 | codePoint = string.charCodeAt(i) | ||
6181 | |||
6182 | // is surrogate component | ||
6183 | if (codePoint > 0xD7FF && codePoint < 0xE000) { | ||
6184 | // last char was a lead | ||
6185 | if (!leadSurrogate) { | ||
6186 | // no lead yet | ||
6187 | if (codePoint > 0xDBFF) { | ||
6188 | // unexpected trail | ||
6189 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
6190 | continue | ||
6191 | } else if (i + 1 === length) { | ||
6192 | // unpaired lead | ||
6193 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
6194 | continue | ||
6195 | } | ||
6196 | |||
6197 | // valid lead | ||
6198 | leadSurrogate = codePoint | ||
6199 | |||
6200 | continue | ||
6201 | } | ||
6202 | |||
6203 | // 2 leads in a row | ||
6204 | if (codePoint < 0xDC00) { | ||
6205 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
6206 | leadSurrogate = codePoint | ||
6207 | continue | ||
6208 | } | ||
6209 | |||
6210 | // valid surrogate pair | ||
6211 | codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000 | ||
6212 | } else if (leadSurrogate) { | ||
6213 | // valid bmp char, but last char was a lead | ||
6214 | if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD) | ||
6215 | } | ||
6216 | |||
6217 | leadSurrogate = null | ||
6218 | |||
6219 | // encode utf8 | ||
6220 | if (codePoint < 0x80) { | ||
6221 | if ((units -= 1) < 0) break | ||
6222 | bytes.push(codePoint) | ||
6223 | } else if (codePoint < 0x800) { | ||
6224 | if ((units -= 2) < 0) break | ||
6225 | bytes.push( | ||
6226 | codePoint >> 0x6 | 0xC0, | ||
6227 | codePoint & 0x3F | 0x80 | ||
6228 | ) | ||
6229 | } else if (codePoint < 0x10000) { | ||
6230 | if ((units -= 3) < 0) break | ||
6231 | bytes.push( | ||
6232 | codePoint >> 0xC | 0xE0, | ||
6233 | codePoint >> 0x6 & 0x3F | 0x80, | ||
6234 | codePoint & 0x3F | 0x80 | ||
6235 | ) | ||
6236 | } else if (codePoint < 0x110000) { | ||
6237 | if ((units -= 4) < 0) break | ||
6238 | bytes.push( | ||
6239 | codePoint >> 0x12 | 0xF0, | ||
6240 | codePoint >> 0xC & 0x3F | 0x80, | ||
6241 | codePoint >> 0x6 & 0x3F | 0x80, | ||
6242 | codePoint & 0x3F | 0x80 | ||
6243 | ) | ||
6244 | } else { | ||
6245 | throw new Error('Invalid code point') | ||
6246 | } | ||
6247 | } | ||
6248 | |||
6249 | return bytes | ||
6250 | } | ||
6251 | |||
6252 | function asciiToBytes (str) { | ||
6253 | var byteArray = [] | ||
6254 | for (var i = 0; i < str.length; ++i) { | ||
6255 | // Node's code seems to be doing this and not & 0x7F.. | ||
6256 | byteArray.push(str.charCodeAt(i) & 0xFF) | ||
6257 | } | ||
6258 | return byteArray | ||
6259 | } | ||
6260 | |||
6261 | function utf16leToBytes (str, units) { | ||
6262 | var c, hi, lo | ||
6263 | var byteArray = [] | ||
6264 | for (var i = 0; i < str.length; ++i) { | ||
6265 | if ((units -= 2) < 0) break | ||
6266 | |||
6267 | c = str.charCodeAt(i) | ||
6268 | hi = c >> 8 | ||
6269 | lo = c % 256 | ||
6270 | byteArray.push(lo) | ||
6271 | byteArray.push(hi) | ||
6272 | } | ||
6273 | |||
6274 | return byteArray | ||
6275 | } | ||
6276 | |||
6277 | function base64ToBytes (str) { | ||
6278 | return base64.toByteArray(base64clean(str)) | ||
6279 | } | ||
6280 | |||
6281 | function blitBuffer (src, dst, offset, length) { | ||
6282 | for (var i = 0; i < length; ++i) { | ||
6283 | if ((i + offset >= dst.length) || (i >= src.length)) break | ||
6284 | dst[i + offset] = src[i] | ||
6285 | } | ||
6286 | return i | ||
6287 | } | ||
6288 | |||
6289 | // Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView` | ||
6290 | function isArrayBufferView (obj) { | ||
6291 | return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj) | ||
6292 | } | ||
6293 | |||
6294 | function numberIsNaN (obj) { | ||
6295 | return obj !== obj // eslint-disable-line no-self-compare | ||
6296 | } | ||
6297 | |||
6298 | },{"base64-js":1,"ieee754":3}],3:[function(require,module,exports){ | ||
6299 | exports.read = function (buffer, offset, isLE, mLen, nBytes) { | ||
6300 | var e, m | ||
6301 | var eLen = nBytes * 8 - mLen - 1 | ||
6302 | var eMax = (1 << eLen) - 1 | ||
6303 | var eBias = eMax >> 1 | ||
6304 | var nBits = -7 | ||
6305 | var i = isLE ? (nBytes - 1) : 0 | ||
6306 | var d = isLE ? -1 : 1 | ||
6307 | var s = buffer[offset + i] | ||
6308 | |||
6309 | i += d | ||
6310 | |||
6311 | e = s & ((1 << (-nBits)) - 1) | ||
6312 | s >>= (-nBits) | ||
6313 | nBits += eLen | ||
6314 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
6315 | |||
6316 | m = e & ((1 << (-nBits)) - 1) | ||
6317 | e >>= (-nBits) | ||
6318 | nBits += mLen | ||
6319 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} | ||
6320 | |||
6321 | if (e === 0) { | ||
6322 | e = 1 - eBias | ||
6323 | } else if (e === eMax) { | ||
6324 | return m ? NaN : ((s ? -1 : 1) * Infinity) | ||
6325 | } else { | ||
6326 | m = m + Math.pow(2, mLen) | ||
6327 | e = e - eBias | ||
6328 | } | ||
6329 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen) | ||
6330 | } | ||
6331 | |||
6332 | exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { | ||
6333 | var e, m, c | ||
6334 | var eLen = nBytes * 8 - mLen - 1 | ||
6335 | var eMax = (1 << eLen) - 1 | ||
6336 | var eBias = eMax >> 1 | ||
6337 | var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) | ||
6338 | var i = isLE ? 0 : (nBytes - 1) | ||
6339 | var d = isLE ? 1 : -1 | ||
6340 | var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 | ||
6341 | |||
6342 | value = Math.abs(value) | ||
6343 | |||
6344 | if (isNaN(value) || value === Infinity) { | ||
6345 | m = isNaN(value) ? 1 : 0 | ||
6346 | e = eMax | ||
6347 | } else { | ||
6348 | e = Math.floor(Math.log(value) / Math.LN2) | ||
6349 | if (value * (c = Math.pow(2, -e)) < 1) { | ||
6350 | e-- | ||
6351 | c *= 2 | ||
6352 | } | ||
6353 | if (e + eBias >= 1) { | ||
6354 | value += rt / c | ||
6355 | } else { | ||
6356 | value += rt * Math.pow(2, 1 - eBias) | ||
6357 | } | ||
6358 | if (value * c >= 2) { | ||
6359 | e++ | ||
6360 | c /= 2 | ||
6361 | } | ||
6362 | |||
6363 | if (e + eBias >= eMax) { | ||
6364 | m = 0 | ||
6365 | e = eMax | ||
6366 | } else if (e + eBias >= 1) { | ||
6367 | m = (value * c - 1) * Math.pow(2, mLen) | ||
6368 | e = e + eBias | ||
6369 | } else { | ||
6370 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) | ||
6371 | e = 0 | ||
6372 | } | ||
6373 | } | ||
6374 | |||
6375 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} | ||
6376 | |||
6377 | e = (e << mLen) | m | ||
6378 | eLen += mLen | ||
6379 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} | ||
6380 | |||
6381 | buffer[offset + i - d] |= s * 128 | ||
6382 | } | ||
6383 | |||
6384 | },{}],4:[function(require,module,exports){ | ||
6385 | window.basex = require('base-x') | ||
6386 | },{"base-x":5}],5:[function(require,module,exports){ | ||
6387 | // base-x encoding | ||
6388 | // Forked from https://github.com/cryptocoinjs/bs58 | ||
6389 | // Originally written by Mike Hearn for BitcoinJ | ||
6390 | // Copyright (c) 2011 Google Inc | ||
6391 | // Ported to JavaScript by Stefan Thomas | ||
6392 | // Merged Buffer refactorings from base58-native by Stephen Pair | ||
6393 | // Copyright (c) 2013 BitPay Inc | ||
6394 | |||
6395 | var Buffer = require('safe-buffer').Buffer | ||
6396 | |||
6397 | module.exports = function base (ALPHABET) { | ||
6398 | var ALPHABET_MAP = {} | ||
6399 | var BASE = ALPHABET.length | ||
6400 | var LEADER = ALPHABET.charAt(0) | ||
6401 | |||
6402 | // pre-compute lookup table | ||
6403 | for (var z = 0; z < ALPHABET.length; z++) { | ||
6404 | var x = ALPHABET.charAt(z) | ||
6405 | |||
6406 | if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous') | ||
6407 | ALPHABET_MAP[x] = z | ||
6408 | } | ||
6409 | |||
6410 | function encode (source) { | ||
6411 | if (source.length === 0) return '' | ||
6412 | |||
6413 | var digits = [0] | ||
6414 | for (var i = 0; i < source.length; ++i) { | ||
6415 | for (var j = 0, carry = source[i]; j < digits.length; ++j) { | ||
6416 | carry += digits[j] << 8 | ||
6417 | digits[j] = carry % BASE | ||
6418 | carry = (carry / BASE) | 0 | ||
6419 | } | ||
6420 | |||
6421 | while (carry > 0) { | ||
6422 | digits.push(carry % BASE) | ||
6423 | carry = (carry / BASE) | 0 | ||
6424 | } | ||
6425 | } | ||
6426 | |||
6427 | var string = '' | ||
6428 | |||
6429 | // deal with leading zeros | ||
6430 | for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += ALPHABET[0] | ||
6431 | // convert digits to a string | ||
6432 | for (var q = digits.length - 1; q >= 0; --q) string += ALPHABET[digits[q]] | ||
6433 | |||
6434 | return string | ||
6435 | } | ||
6436 | |||
6437 | function decodeUnsafe (string) { | ||
6438 | if (string.length === 0) return Buffer.allocUnsafe(0) | ||
6439 | |||
6440 | var bytes = [0] | ||
6441 | for (var i = 0; i < string.length; i++) { | ||
6442 | var value = ALPHABET_MAP[string[i]] | ||
6443 | if (value === undefined) return | ||
6444 | |||
6445 | for (var j = 0, carry = value; j < bytes.length; ++j) { | ||
6446 | carry += bytes[j] * BASE | ||
6447 | bytes[j] = carry & 0xff | ||
6448 | carry >>= 8 | ||
6449 | } | ||
6450 | |||
6451 | while (carry > 0) { | ||
6452 | bytes.push(carry & 0xff) | ||
6453 | carry >>= 8 | ||
6454 | } | ||
6455 | } | ||
6456 | |||
6457 | // deal with leading zeros | ||
6458 | for (var k = 0; string[k] === LEADER && k < string.length - 1; ++k) { | ||
6459 | bytes.push(0) | ||
6460 | } | ||
6461 | |||
6462 | return Buffer.from(bytes.reverse()) | ||
6463 | } | ||
6464 | |||
6465 | function decode (string) { | ||
6466 | var buffer = decodeUnsafe(string) | ||
6467 | if (buffer) return buffer | ||
6468 | |||
6469 | throw new Error('Non-base' + BASE + ' character') | ||
6470 | } | ||
6471 | |||
6472 | return { | ||
6473 | encode: encode, | ||
6474 | decodeUnsafe: decodeUnsafe, | ||
6475 | decode: decode | ||
6476 | } | ||
6477 | } | ||
6478 | |||
6479 | },{"safe-buffer":6}],6:[function(require,module,exports){ | ||
6480 | module.exports = require('buffer') | ||
6481 | |||
6482 | },{"buffer":2}]},{},[4])(4) | ||
6483 | });</script> | ||
4474 | <script>(function (root) { | 6484 | <script>(function (root) { |
4475 | "use strict"; | 6485 | "use strict"; |
4476 | 6486 | ||
@@ -36689,6 +38699,17 @@ module.exports = function stripHexPrefix(str) { | |||
36689 | 38699 | ||
36690 | },{"is-hex-prefixed":64}]},{},[31])(31) | 38700 | },{"is-hex-prefixed":64}]},{},[31])(31) |
36691 | });</script> | 38701 | });</script> |
38702 | <script>function convertRippleAdrr(address) { | ||
38703 | return window.basex('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz').encode( | ||
38704 | window.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(address) | ||
38705 | ) | ||
38706 | } | ||
38707 | |||
38708 | function convertRipplePriv(priv) { | ||
38709 | return window.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(priv).toString("hex").slice(2) | ||
38710 | } | ||
38711 | |||
38712 | </script> | ||
36692 | <script>// Select components from sjcl to suit the crypto operations bip39 requires. | 38713 | <script>// Select components from sjcl to suit the crypto operations bip39 requires. |
36693 | 38714 | ||
36694 | //// base.js | 38715 | //// base.js |
@@ -42270,6 +44291,11 @@ window.Entropy = new (function() { | |||
42270 | var checksumAddress = ethUtil.toChecksumAddress(hexAddress); | 44291 | var checksumAddress = ethUtil.toChecksumAddress(hexAddress); |
42271 | address = ethUtil.addHexPrefix(checksumAddress); | 44292 | address = ethUtil.addHexPrefix(checksumAddress); |
42272 | } | 44293 | } |
44294 | // Ripple values are different | ||
44295 | if (networks[DOM.network.val()].name == "Ripple") { | ||
44296 | privkey = convertRipplePriv(privkey); | ||
44297 | address = convertRippleAdrr(address); | ||
44298 | } | ||
42273 | addAddressToList(indexText, address, pubkey, privkey); | 44299 | addAddressToList(indexText, address, pubkey, privkey); |
42274 | }, 50) | 44300 | }, 50) |
42275 | } | 44301 | } |
@@ -42826,6 +44852,13 @@ window.Entropy = new (function() { | |||
42826 | }, | 44852 | }, |
42827 | }, | 44853 | }, |
42828 | { | 44854 | { |
44855 | name: "Ripple", | ||
44856 | onSelect: function() { | ||
44857 | network = bitcoin.networks.bitcoin; | ||
44858 | DOM.bip44coin.val(144); | ||
44859 | }, | ||
44860 | }, | ||
44861 | { | ||
42829 | name: "ShadowCash", | 44862 | name: "ShadowCash", |
42830 | onSelect: function() { | 44863 | onSelect: function() { |
42831 | network = bitcoin.networks.shadow; | 44864 | network = bitcoin.networks.shadow; |