diff --git a/package.json b/package.json index 98347f7..08df8ad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "warpwallet", - "version": "1.0.8", + "version": "1.0.9", "description": "Open Source JavaScript Client-Side Bitcoin Wallet Generator Using scrypt", "dependencies": { "brew": "*", diff --git a/release.txt.in b/release.txt.in index 97cb30c..657f931 100644 --- a/release.txt.in +++ b/release.txt.in @@ -21,7 +21,13 @@ https://keybase.io/warp/keybase-code-signing-key-2013.asc (ID: 4748 4E50 656D 16 Version History ================ -2015-02-01: Status ACTIVE +2017-05-30: Status ACTIVE +web/warp_1.0.9_SHA256_c067a5573248a16e56b02f748b0638b94dd0f211284ffa5c58a47b25b344f756.html + - Add tags to prevent browsers from spellchecking, autocorrecting, autocapitalizing + - Escape user content on email address, in case they're convinced to paste a script into that field + - Correct below date on v.1.0.8 which said 2015 instead of 2016 + +2016-02-01: Status ACTIVE web/warp_1.0.8_SHA256_5111a723fe008dbf628237023e6f2de72c7953f8bb4265d5c16fc9fd79384b7a.html - Announce new WW Challenge, and close old one. diff --git a/src/coffee/site.coffee b/src/coffee/site.coffee index 7c35aec..c4c609f 100644 --- a/src/coffee/site.coffee +++ b/src/coffee/site.coffee @@ -6,15 +6,15 @@ class Warper if window.SALT_DEFAULT? $('#salt').val window.SALT_DEFAULT $('#salt').attr 'disabled', true - $('.salt-label').text 'Prefilled salt' + $('.salt-label').text 'Prefilled salt' check_compatibility: -> if not Int32Array? $('.form-container').html '''

Sorry, but your browser is too old to run WarpWallet, which requires Int32Array support. -

''' - +

''' + attach_ux: -> $('#btn-submit').on 'click', => @click_submit() $('#btn-reset').on 'click', => @click_reset() @@ -27,6 +27,8 @@ class Warper $('#private-key').on 'click', -> $(@).select() $('.what-salt').on 'click', => $('.salt-explanation').toggle() + escape_user_content: (s) -> s.replace(/&/g, '&').replace(//g, '>').replace(/\"/g, '"').replace(/\'/g, ''') + any_change: -> $('.progress-form').hide() $('#private-key').val '' @@ -34,7 +36,7 @@ class Warper $('#btn-submit').attr('disabled', false).show().html 'Generate' pp = $('#passphrase').val() salt = $('#salt').val() - chk = $('#checkbox-salt-confirm').is ":checked" + chk = $('#checkbox-salt-confirm').is ":checked" err = null warn = null if not pp.length @@ -50,7 +52,7 @@ class Warper $('#btn-submit').attr('disabled', true).html err else if warn $('#btn-submit').attr('disabled', false).html warn - else + else $('#btn-submit').attr('disabled', false).html "Generate" $('.output-form').hide() $('#public-address-qr').html '' @@ -71,10 +73,10 @@ class Warper if not salt.length $('.salt-confirm').hide() if window.SALT_DEFAULT? - $('.salt-confirm').hide() - else if @salt_ok() + $('.salt-confirm').hide() + else if @salt_ok() $('.salt-confirm').show() - $('.salt-summary').text salt + $('.salt-summary').text @escape_user_content salt else $('.salt-confirm').hide() @any_change() @@ -119,7 +121,7 @@ class Warper $('.progress-pbkdf2, .progress-scrypt').html '' $('.progress-form').show() - warpwallet.run { + warpwallet.run { passphrase : $('#passphrase').val() salt : $('#salt').val() progress_hook : (o) => @progress_hook o @@ -136,7 +138,7 @@ class Warper $('#public-address').val res.public $('#private-key').val res.private @write_qrs res.public, res.private - console.log + return $ -> new Warper() diff --git a/src/css/site.css b/src/css/site.css index 971ea05..37d3f5b 100644 --- a/src/css/site.css +++ b/src/css/site.css @@ -41,7 +41,7 @@ h1 .second-half { color: #666; background-color:#ddddd8; padding:10px; - border-radius: 5px; + border-radius: 5px; } .salt-explanation p { padding:20px; @@ -147,7 +147,7 @@ h1 .second-half { .form-horizontal .progress-form { margin: 20px 0px 20px 0px; -} +} .progress-form { background-color: #eee; } @@ -168,11 +168,11 @@ h1 .second-half { color:#f90; } -hr { - display: block; +hr { + display: block; height: 1px; - border: 0; + border: 0; border-top: 1px solid #777; - margin: 1em 0; - padding: 0; -} \ No newline at end of file + margin: 1em 0; + padding: 0; +} diff --git a/src/js/deps.js b/src/js/deps.js index cf57039..e14fd62 100644 --- a/src/js/deps.js +++ b/src/js/deps.js @@ -1,5 +1,120 @@ (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.warpwallet = 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 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + return b64[len - 2] === '=' ? 2 : b64[len - 1] === '=' ? 1 : 0 +} + +function byteLength (b64) { + // base64 is 4/3 + up to two characters of the original data + return b64.length * 3 / 4 - placeHoldersCount(b64) +} + +function toByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + var len = b64.length + placeHolders = placeHoldersCount(b64) + + arr = new Arr(len * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? len - 4 : len + + var L = 0 + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)] + arr[L++] = (tmp >> 16) & 0xFF + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + if (placeHolders === 2) { + tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4) + arr[L++] = tmp & 0xFF + } else if (placeHolders === 1) { + tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2) + arr[L++] = (tmp >> 8) & 0xFF + arr[L++] = tmp & 0xFF + } + + return arr +} + +function tripletToBase64 (num) { + return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F] +} + +function encodeChunk (uint8, start, end) { + var tmp + var output = [] + for (var i = start; i < end; i += 3) { + tmp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output.push(tripletToBase64(tmp)) + } + return output.join('') +} + +function fromByteArray (uint8) { + var tmp + var len = uint8.length + var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes + var output = '' + var parts = [] + var maxChunkLength = 16383 // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength))) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1] + output += lookup[tmp >> 2] + output += lookup[(tmp << 4) & 0x3F] + output += '==' + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + (uint8[len - 1]) + output += lookup[tmp >> 10] + output += lookup[(tmp >> 4) & 0x3F] + output += lookup[(tmp << 2) & 0x3F] + output += '=' + } + + parts.push(output) + + return parts.join('') +} + +},{}],2:[function(require,module,exports){ /*! * The buffer module from node.js, for the browser. * @@ -12,59 +127,57 @@ var base64 = require('base64-js') var ieee754 = require('ieee754') -var isArray = require('isarray') exports.Buffer = Buffer exports.SlowBuffer = SlowBuffer exports.INSPECT_MAX_BYTES = 50 -Buffer.poolSize = 8192 // not used by this implementation -var rootParent = {} +var K_MAX_LENGTH = 0x7fffffff +exports.kMaxLength = K_MAX_LENGTH /** * If `Buffer.TYPED_ARRAY_SUPPORT`: * === true Use Uint8Array implementation (fastest) - * === false Use Object implementation (most compatible, even IE6) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) * * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, * Opera 11.6+, iOS 4.2+. * - * Due to various browser bugs, sometimes the Object implementation will be used even - * when the browser supports typed arrays. - * - * Note: - * - * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, - * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. - * - * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. - * - * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of - * incorrect length in some situations. - - * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they - * get the Object implementation, which is slower but behaves correctly. + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. */ -Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined - ? global.TYPED_ARRAY_SUPPORT - : typedArraySupport() +Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport() + +if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== 'undefined' && + typeof console.error === 'function') { + console.error( + 'This browser lacks typed array (Uint8Array) support which is required by ' + + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' + ) +} function typedArraySupport () { + // Can typed array instances can be augmented? try { var arr = new Uint8Array(1) - arr.foo = function () { return 42 } - return arr.foo() === 42 && // typed array instances can be augmented - typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` - arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + arr.__proto__ = {__proto__: Uint8Array.prototype, foo: function () { return 42 }} + return arr.foo() === 42 } catch (e) { return false } } -function kMaxLength () { - return Buffer.TYPED_ARRAY_SUPPORT - ? 0x7fffffff - : 0x3fffffff +function createBuffer (length) { + if (length > K_MAX_LENGTH) { + throw new RangeError('Invalid typed array length') + } + // Return an augmented `Uint8Array` instance + var buf = new Uint8Array(length) + buf.__proto__ = Buffer.prototype + return buf } /** @@ -76,197 +189,220 @@ function kMaxLength () { * * The `Uint8Array` prototype remains unmodified. */ -function Buffer (arg) { - if (!(this instanceof Buffer)) { - // Avoid going through an ArgumentsAdaptorTrampoline in the common case. - if (arguments.length > 1) return new Buffer(arg, arguments[1]) - return new Buffer(arg) + +function Buffer (arg, encodingOrOffset, length) { + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new Error( + 'If encoding is specified then the first argument must be a string' + ) + } + return allocUnsafe(arg) } + return from(arg, encodingOrOffset, length) +} + +// Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 +if (typeof Symbol !== 'undefined' && Symbol.species && + Buffer[Symbol.species] === Buffer) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }) +} + +Buffer.poolSize = 8192 // not used by this implementation - if (!Buffer.TYPED_ARRAY_SUPPORT) { - this.length = 0 - this.parent = undefined +function from (value, encodingOrOffset, length) { + if (typeof value === 'number') { + throw new TypeError('"value" argument must not be a number') } - // Common case. - if (typeof arg === 'number') { - return fromNumber(this, arg) + if (value instanceof ArrayBuffer) { + return fromArrayBuffer(value, encodingOrOffset, length) } - // Slightly less common case. - if (typeof arg === 'string') { - return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8') + if (typeof value === 'string') { + return fromString(value, encodingOrOffset) } - // Unusual. - return fromObject(this, arg) + return fromObject(value) } -// TODO: Legacy, not needed anymore. Remove in next major version. -Buffer._augment = function (arr) { - arr.__proto__ = Buffer.prototype - return arr +/** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ +Buffer.from = function (value, encodingOrOffset, length) { + return from(value, encodingOrOffset, length) +} + +// Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: +// https://github.com/feross/buffer/pull/148 +Buffer.prototype.__proto__ = Uint8Array.prototype +Buffer.__proto__ = Uint8Array + +function assertSize (size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be a number') + } else if (size < 0) { + throw new RangeError('"size" argument must not be negative') + } } -function fromNumber (that, length) { - that = allocate(that, length < 0 ? 0 : checked(length) | 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) { - for (var i = 0; i < length; i++) { - that[i] = 0 - } +function alloc (size, fill, encoding) { + assertSize(size) + if (size <= 0) { + return createBuffer(size) } - return that + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(size).fill(fill, encoding) + : createBuffer(size).fill(fill) + } + return createBuffer(size) } -function fromString (that, string, encoding) { - if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8' - - // Assumption: byteLength() return value is always < kMaxLength. - var length = byteLength(string, encoding) | 0 - that = allocate(that, length) - - that.write(string, encoding) - return that +/** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ +Buffer.alloc = function (size, fill, encoding) { + return alloc(size, fill, encoding) } -function fromObject (that, object) { - if (Buffer.isBuffer(object)) return fromBuffer(that, object) +function allocUnsafe (size) { + assertSize(size) + return createBuffer(size < 0 ? 0 : checked(size) | 0) +} - if (isArray(object)) return fromArray(that, object) +/** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ +Buffer.allocUnsafe = function (size) { + return allocUnsafe(size) +} +/** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ +Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(size) +} - if (object == null) { - throw new TypeError('must start with number, buffer, array or string') +function fromString (string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8' } - if (typeof ArrayBuffer !== 'undefined') { - if (object.buffer instanceof ArrayBuffer) { - return fromTypedArray(that, object) - } - if (object instanceof ArrayBuffer) { - return fromArrayBuffer(that, object) - } + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('"encoding" must be a valid string encoding') } - if (object.length) return fromArrayLike(that, object) + var length = byteLength(string, encoding) | 0 + var buf = createBuffer(length) - return fromJsonObject(that, object) -} + var actual = buf.write(string, encoding) -function fromBuffer (that, buffer) { - var length = checked(buffer.length) | 0 - that = allocate(that, length) - buffer.copy(that, 0, 0, length) - return that + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual) + } + + return buf } -function fromArray (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) +function fromArrayLike (array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0 + var buf = createBuffer(length) for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 + buf[i] = array[i] & 255 } - return that + return buf } -// Duplicate of fromArray() to keep fromArray() monomorphic. -function fromTypedArray (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - // Truncating the elements is probably not what people expect from typed - // arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior - // of the old Buffer constructor. - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 +function fromArrayBuffer (array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('\'offset\' is out of bounds') } - return that -} -function fromArrayBuffer (that, array) { - array.byteLength // this throws if `array` is not a valid ArrayBuffer + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('\'length\' is out of bounds') + } - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(array) - that.__proto__ = Buffer.prototype + var buf + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array) + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset) } else { - // Fallback: Return an object instance of the Buffer class - that = fromTypedArray(that, new Uint8Array(array)) + buf = new Uint8Array(array, byteOffset, length) } - return that -} -function fromArrayLike (that, array) { - var length = checked(array.length) | 0 - that = allocate(that, length) - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 - } - return that + // Return an augmented `Uint8Array` instance + buf.__proto__ = Buffer.prototype + return buf } -// Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. -// Returns a zero-length buffer for inputs that don't conform to the spec. -function fromJsonObject (that, object) { - var array - var length = 0 +function fromObject (obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0 + var buf = createBuffer(len) - if (object.type === 'Buffer' && isArray(object.data)) { - array = object.data - length = checked(array.length) | 0 - } - that = allocate(that, length) + if (buf.length === 0) { + return buf + } - for (var i = 0; i < length; i += 1) { - that[i] = array[i] & 255 + obj.copy(buf, 0, 0, len) + return buf } - return that -} -if (Buffer.TYPED_ARRAY_SUPPORT) { - Buffer.prototype.__proto__ = Uint8Array.prototype - Buffer.__proto__ = Uint8Array -} else { - // pre-set for values that may exist in the future - Buffer.prototype.length = undefined - Buffer.prototype.parent = undefined -} + if (obj) { + if (isArrayBufferView(obj) || 'length' in obj) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { + return createBuffer(0) + } + return fromArrayLike(obj) + } -function allocate (that, length) { - if (Buffer.TYPED_ARRAY_SUPPORT) { - // Return an augmented `Uint8Array` instance, for best performance - that = new Uint8Array(length) - that.__proto__ = Buffer.prototype - } else { - // Fallback: Return an object instance of the Buffer class - that.length = length + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(obj.data) + } } - var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1 - if (fromPool) that.parent = rootParent - - return that + throw new TypeError('First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.') } function checked (length) { - // Note: cannot use `length < kMaxLength` here because that fails when + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when // length is NaN (which is otherwise coerced to zero.) - if (length >= kMaxLength()) { + if (length >= K_MAX_LENGTH) { throw new RangeError('Attempt to allocate Buffer larger than maximum ' + - 'size: 0x' + kMaxLength().toString(16) + ' bytes') + 'size: 0x' + K_MAX_LENGTH.toString(16) + ' bytes') } return length | 0 } -function SlowBuffer (subject, encoding) { - if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding) - - var buf = new Buffer(subject, encoding) - delete buf.parent - return buf +function SlowBuffer (length) { + if (+length != length) { // eslint-disable-line eqeqeq + length = 0 + } + return Buffer.alloc(+length) } Buffer.isBuffer = function isBuffer (b) { - return !!(b != null && b._isBuffer) + return b != null && b._isBuffer === true } Buffer.compare = function compare (a, b) { @@ -279,17 +415,12 @@ Buffer.compare = function compare (a, b) { var x = a.length var y = b.length - var i = 0 - var len = Math.min(x, y) - while (i < len) { - if (a[i] !== b[i]) break - - ++i - } - - if (i !== len) { - x = a[i] - y = b[i] + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i] + y = b[i] + break + } } if (x < y) return -1 @@ -303,9 +434,9 @@ Buffer.isEncoding = function isEncoding (encoding) { case 'utf8': case 'utf-8': case 'ascii': + case 'latin1': case 'binary': case 'base64': - case 'raw': case 'ucs2': case 'ucs-2': case 'utf16le': @@ -317,32 +448,45 @@ Buffer.isEncoding = function isEncoding (encoding) { } Buffer.concat = function concat (list, length) { - if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.') + if (!Array.isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } if (list.length === 0) { - return new Buffer(0) + return Buffer.alloc(0) } var i if (length === undefined) { length = 0 - for (i = 0; i < list.length; i++) { + for (i = 0; i < list.length; ++i) { length += list[i].length } } - var buf = new Buffer(length) + var buffer = Buffer.allocUnsafe(length) var pos = 0 - for (i = 0; i < list.length; i++) { - var item = list[i] - item.copy(buf, pos) - pos += item.length + for (i = 0; i < list.length; ++i) { + var buf = list[i] + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers') + } + buf.copy(buffer, pos) + pos += buf.length } - return buf + return buffer } function byteLength (string, encoding) { - if (typeof string !== 'string') string = '' + string + if (Buffer.isBuffer(string)) { + return string.length + } + if (isArrayBufferView(string) || string instanceof ArrayBuffer) { + return string.byteLength + } + if (typeof string !== 'string') { + string = '' + string + } var len = string.length if (len === 0) return 0 @@ -352,13 +496,12 @@ function byteLength (string, encoding) { for (;;) { switch (encoding) { case 'ascii': + case 'latin1': case 'binary': - // Deprecated - case 'raw': - case 'raws': return len case 'utf8': case 'utf-8': + case undefined: return utf8ToBytes(string).length case 'ucs2': case 'ucs-2': @@ -381,13 +524,39 @@ Buffer.byteLength = byteLength function slowToString (encoding, start, end) { var loweredCase = false - start = start | 0 - end = end === undefined || end === Infinity ? this.length : end | 0 + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0 + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return '' + } + + if (end === undefined || end > this.length) { + end = this.length + } + + if (end <= 0) { + return '' + } + + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0 + start >>>= 0 + + if (end <= start) { + return '' + } if (!encoding) encoding = 'utf8' - if (start < 0) start = 0 - if (end > this.length) end = this.length - if (end <= start) return '' while (true) { switch (encoding) { @@ -401,8 +570,9 @@ function slowToString (encoding, start, end) { case 'ascii': return asciiSlice(this, start, end) + case 'latin1': case 'binary': - return binarySlice(this, start, end) + return latin1Slice(this, start, end) case 'base64': return base64Slice(this, start, end) @@ -421,12 +591,59 @@ function slowToString (encoding, start, end) { } } -// The property is used by `Buffer.isBuffer` and `is-buffer` (in Safari 5-7) to detect -// Buffer instances. +// This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) +// to detect a Buffer instance. It's not possible to use `instanceof Buffer` +// reliably in a browserify context because there could be multiple different +// copies of the 'buffer' package in use. This method works even for Buffer +// instances that were created from another copy of the `buffer` package. +// See: https://github.com/feross/buffer/issues/154 Buffer.prototype._isBuffer = true +function swap (b, n, m) { + var i = b[n] + b[n] = b[m] + b[m] = i +} + +Buffer.prototype.swap16 = function swap16 () { + var len = this.length + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits') + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1) + } + return this +} + +Buffer.prototype.swap32 = function swap32 () { + var len = this.length + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits') + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3) + swap(this, i + 1, i + 2) + } + return this +} + +Buffer.prototype.swap64 = function swap64 () { + var len = this.length + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits') + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7) + swap(this, i + 1, i + 6) + swap(this, i + 2, i + 5) + swap(this, i + 3, i + 4) + } + return this +} + Buffer.prototype.toString = function toString () { - var length = this.length | 0 + var length = this.length if (length === 0) return '' if (arguments.length === 0) return utf8Slice(this, 0, length) return slowToString.apply(this, arguments) @@ -448,51 +665,196 @@ Buffer.prototype.inspect = function inspect () { return '' } -Buffer.prototype.compare = function compare (b) { - if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') - if (this === b) return 0 - return Buffer.compare(this, b) -} +Buffer.prototype.compare = function compare (target, start, end, thisStart, thisEnd) { + if (!Buffer.isBuffer(target)) { + throw new TypeError('Argument must be a Buffer') + } + + if (start === undefined) { + start = 0 + } + if (end === undefined) { + end = target ? target.length : 0 + } + if (thisStart === undefined) { + thisStart = 0 + } + if (thisEnd === undefined) { + thisEnd = this.length + } + + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError('out of range index') + } -Buffer.prototype.indexOf = function indexOf (val, byteOffset) { - if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff - else if (byteOffset < -0x80000000) byteOffset = -0x80000000 - byteOffset >>= 0 + if (thisStart >= thisEnd && start >= end) { + return 0 + } + if (thisStart >= thisEnd) { + return -1 + } + if (start >= end) { + return 1 + } + + start >>>= 0 + end >>>= 0 + thisStart >>>= 0 + thisEnd >>>= 0 + + if (this === target) return 0 + + var x = thisEnd - thisStart + var y = end - start + var len = Math.min(x, y) + + var thisCopy = this.slice(thisStart, thisEnd) + var targetCopy = target.slice(start, end) + + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i] + y = targetCopy[i] + break + } + } + + if (x < y) return -1 + if (y < x) return 1 + return 0 +} - if (this.length === 0) return -1 - if (byteOffset >= this.length) return -1 +// Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, +// OR the last index of `val` in `buffer` at offset <= `byteOffset`. +// +// Arguments: +// - buffer - a Buffer to search +// - val - a string, Buffer, or number +// - byteOffset - an index into `buffer`; will be clamped to an int32 +// - encoding - an optional encoding, relevant is val is a string +// - dir - true for indexOf, false for lastIndexOf +function bidirectionalIndexOf (buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1 + + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset + byteOffset = 0 + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000 + } + byteOffset = +byteOffset // Coerce to Number. + if (numberIsNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : (buffer.length - 1) + } - // Negative offsets start from the end of the buffer - if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset + if (byteOffset >= buffer.length) { + if (dir) return -1 + else byteOffset = buffer.length - 1 + } else if (byteOffset < 0) { + if (dir) byteOffset = 0 + else return -1 + } + // Normalize val if (typeof val === 'string') { - if (val.length === 0) return -1 // special case: looking for empty string always fails - return String.prototype.indexOf.call(this, val, byteOffset) + val = Buffer.from(val, encoding) } + + // Finally, search either indexOf (if dir is true) or lastIndexOf if (Buffer.isBuffer(val)) { - return arrayIndexOf(this, val, byteOffset) + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1 + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir) + } else if (typeof val === 'number') { + val = val & 0xFF // Search for a byte value [0-255] + if (typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset) + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset) + } + } + return arrayIndexOf(buffer, [ val ], byteOffset, encoding, dir) } - if (typeof val === 'number') { - if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { - return Uint8Array.prototype.indexOf.call(this, val, byteOffset) + + throw new TypeError('val must be string, number or Buffer') +} + +function arrayIndexOf (arr, val, byteOffset, encoding, dir) { + var indexSize = 1 + var arrLength = arr.length + var valLength = val.length + + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase() + if (encoding === 'ucs2' || encoding === 'ucs-2' || + encoding === 'utf16le' || encoding === 'utf-16le') { + if (arr.length < 2 || val.length < 2) { + return -1 + } + indexSize = 2 + arrLength /= 2 + valLength /= 2 + byteOffset /= 2 + } + } + + function read (buf, i) { + if (indexSize === 1) { + return buf[i] + } else { + return buf.readUInt16BE(i * indexSize) } - return arrayIndexOf(this, [ val ], byteOffset) } - function arrayIndexOf (arr, val, byteOffset) { + var i + if (dir) { var foundIndex = -1 - for (var i = 0; byteOffset + i < arr.length; i++) { - if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { if (foundIndex === -1) foundIndex = i - if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize } else { + if (foundIndex !== -1) i -= i - foundIndex foundIndex = -1 } } - return -1 + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength + for (i = byteOffset; i >= 0; i--) { + var found = true + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false + break + } + } + if (found) return i + } } - throw new TypeError('val must be string, number or Buffer') + return -1 +} + +Buffer.prototype.includes = function includes (val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1 +} + +Buffer.prototype.indexOf = function indexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true) +} + +Buffer.prototype.lastIndexOf = function lastIndexOf (val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false) } function hexWrite (buf, string, offset, length) { @@ -509,14 +871,14 @@ function hexWrite (buf, string, offset, length) { // must be an even number of digits var strLen = string.length - if (strLen % 2 !== 0) throw new Error('Invalid hex string') + if (strLen % 2 !== 0) throw new TypeError('Invalid hex string') if (length > strLen / 2) { length = strLen / 2 } - for (var i = 0; i < length; i++) { + for (var i = 0; i < length; ++i) { var parsed = parseInt(string.substr(i * 2, 2), 16) - if (isNaN(parsed)) throw new Error('Invalid hex string') + if (numberIsNaN(parsed)) return i buf[offset + i] = parsed } return i @@ -530,7 +892,7 @@ function asciiWrite (buf, string, offset, length) { return blitBuffer(asciiToBytes(string), buf, offset, length) } -function binaryWrite (buf, string, offset, length) { +function latin1Write (buf, string, offset, length) { return asciiWrite(buf, string, offset, length) } @@ -555,27 +917,25 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { offset = 0 // Buffer#write(string, offset[, length][, encoding]) } else if (isFinite(offset)) { - offset = offset | 0 + offset = offset >>> 0 if (isFinite(length)) { - length = length | 0 + length = length >>> 0 if (encoding === undefined) encoding = 'utf8' } else { encoding = length length = undefined } - // legacy write(string, encoding, offset, length) - remove in v0.13 } else { - var swap = encoding - encoding = offset - offset = length | 0 - length = swap + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ) } var remaining = this.length - offset if (length === undefined || length > remaining) length = remaining if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { - throw new RangeError('attempt to write outside buffer bounds') + throw new RangeError('Attempt to write outside buffer bounds') } if (!encoding) encoding = 'utf8' @@ -593,8 +953,9 @@ Buffer.prototype.write = function write (string, offset, length, encoding) { case 'ascii': return asciiWrite(this, string, offset, length) + case 'latin1': case 'binary': - return binaryWrite(this, string, offset, length) + return latin1Write(this, string, offset, length) case 'base64': // Warning: maxLength not taken into account in base64Write @@ -729,17 +1090,17 @@ function asciiSlice (buf, start, end) { var ret = '' end = Math.min(buf.length, end) - for (var i = start; i < end; i++) { + for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i] & 0x7F) } return ret } -function binarySlice (buf, start, end) { +function latin1Slice (buf, start, end) { var ret = '' end = Math.min(buf.length, end) - for (var i = start; i < end; i++) { + for (var i = start; i < end; ++i) { ret += String.fromCharCode(buf[i]) } return ret @@ -752,7 +1113,7 @@ function hexSlice (buf, start, end) { if (!end || end < 0 || end > len) end = len var out = '' - for (var i = start; i < end; i++) { + for (var i = start; i < end; ++i) { out += toHex(buf[i]) } return out @@ -762,7 +1123,7 @@ function utf16leSlice (buf, start, end) { var bytes = buf.slice(start, end) var res = '' for (var i = 0; i < bytes.length; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256) + res += String.fromCharCode(bytes[i] + (bytes[i + 1] * 256)) } return res } @@ -788,20 +1149,9 @@ Buffer.prototype.slice = function slice (start, end) { if (end < start) end = start - var newBuf - if (Buffer.TYPED_ARRAY_SUPPORT) { - newBuf = this.subarray(start, end) - newBuf.__proto__ = Buffer.prototype - } else { - var sliceLen = end - start - newBuf = new Buffer(sliceLen, undefined) - for (var i = 0; i < sliceLen; i++) { - newBuf[i] = this[i + start] - } - } - - if (newBuf.length) newBuf.parent = this.parent || this - + var newBuf = this.subarray(start, end) + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype return newBuf } @@ -814,8 +1164,8 @@ function checkOffset (offset, ext, length) { } Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -829,8 +1179,8 @@ Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) } Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) { checkOffset(offset, byteLength, this.length) } @@ -845,21 +1195,25 @@ Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) } Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) return this[offset] } Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return this[offset] | (this[offset + 1] << 8) } Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) return (this[offset] << 8) | this[offset + 1] } Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ((this[offset]) | @@ -869,6 +1223,7 @@ Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { } Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] * 0x1000000) + @@ -878,8 +1233,8 @@ Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) { } Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var val = this[offset] @@ -896,8 +1251,8 @@ Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) { } Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { - offset = offset | 0 - byteLength = byteLength | 0 + offset = offset >>> 0 + byteLength = byteLength >>> 0 if (!noAssert) checkOffset(offset, byteLength, this.length) var i = byteLength @@ -914,24 +1269,28 @@ Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) { } Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 1, this.length) if (!(this[offset] & 0x80)) return (this[offset]) return ((0xff - this[offset] + 1) * -1) } Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset] | (this[offset + 1] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 2, this.length) var val = this[offset + 1] | (this[offset] << 8) return (val & 0x8000) ? val | 0xFFFF0000 : val } Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset]) | @@ -941,6 +1300,7 @@ Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) { } Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return (this[offset] << 24) | @@ -950,36 +1310,43 @@ Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) { } Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, true, 23, 4) } Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 4, this.length) return ieee754.read(this, offset, false, 23, 4) } Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, true, 52, 8) } Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + offset = offset >>> 0 if (!noAssert) checkOffset(offset, 8, this.length) return ieee754.read(this, offset, false, 52, 8) } function checkInt (buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance') - if (value > max || value < min) throw new RangeError('value is out of bounds') - if (offset + ext > buf.length) throw new RangeError('index out of range') + if (!Buffer.isBuffer(buf)) throw new TypeError('"buffer" argument must be a Buffer instance') + if (value > max || value < min) throw new RangeError('"value" argument is out of bounds') + if (offset + ext > buf.length) throw new RangeError('Index out of range') } Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } var mul = 1 var i = 0 @@ -993,9 +1360,12 @@ Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 - byteLength = byteLength | 0 - if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0) + offset = offset >>> 0 + byteLength = byteLength >>> 0 + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1 + checkInt(this, value, offset, byteLength, maxBytes, 0) + } var i = byteLength - 1 var mul = 1 @@ -1009,98 +1379,69 @@ Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) this[offset] = (value & 0xff) return offset + 1 } -function objectWriteUInt16 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { - buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> - (littleEndian ? i : 1 - i) * 8 - } -} - Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } -function objectWriteUInt32 (buf, value, offset, littleEndian) { - if (value < 0) value = 0xffffffff + value + 1 - for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { - buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff - } -} - Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset + 3] = (value >>> 24) - this[offset + 2] = (value >>> 16) - this[offset + 1] = (value >>> 8) - this[offset] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) return offset + 4 } Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } var i = 0 var mul = 1 - var sub = value < 0 ? 1 : 0 + var sub = 0 this[offset] = value & 0xFF while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1 + } this[offset + i] = ((value / mul) >> 0) - sub & 0xFF } @@ -1109,18 +1450,21 @@ Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, no Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) { - var limit = Math.pow(2, 8 * byteLength - 1) + var limit = Math.pow(2, (8 * byteLength) - 1) checkInt(this, value, offset, byteLength, limit - 1, -limit) } var i = byteLength - 1 var mul = 1 - var sub = value < 0 ? 1 : 0 + var sub = 0 this[offset + i] = value & 0xFF while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1 + } this[offset + i] = ((value / mul) >> 0) - sub & 0xFF } @@ -1129,9 +1473,8 @@ Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, no Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80) - if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) if (value < 0) value = 0xff + value + 1 this[offset] = (value & 0xff) return offset + 1 @@ -1139,67 +1482,53 @@ Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) { Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - } else { - objectWriteUInt16(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) return offset + 2 } Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 8) - this[offset + 1] = (value & 0xff) - } else { - objectWriteUInt16(this, value, offset, false) - } + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) return offset + 2 } Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value & 0xff) - this[offset + 1] = (value >>> 8) - this[offset + 2] = (value >>> 16) - this[offset + 3] = (value >>> 24) - } else { - objectWriteUInt32(this, value, offset, true) - } + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) return offset + 4 } Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) { value = +value - offset = offset | 0 + offset = offset >>> 0 if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000) if (value < 0) value = 0xffffffff + value + 1 - if (Buffer.TYPED_ARRAY_SUPPORT) { - this[offset] = (value >>> 24) - this[offset + 1] = (value >>> 16) - this[offset + 2] = (value >>> 8) - this[offset + 3] = (value & 0xff) - } else { - objectWriteUInt32(this, value, offset, false) - } + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) return offset + 4 } function checkIEEE754 (buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError('index out of range') - if (offset < 0) throw new RangeError('index out of range') + if (offset + ext > buf.length) throw new RangeError('Index out of range') + if (offset < 0) throw new RangeError('Index out of range') } function writeFloat (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) } @@ -1216,6 +1545,8 @@ Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) } function writeDouble (buf, value, offset, littleEndian, noAssert) { + value = +value + offset = offset >>> 0 if (!noAssert) { checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) } @@ -1261,12 +1592,12 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { if (this === target && start < targetStart && targetStart < end) { // descending copy from end - for (i = len - 1; i >= 0; i--) { + for (i = len - 1; i >= 0; --i) { target[i + targetStart] = this[i + start] } - } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + } else if (len < 1000) { // ascending copy from start - for (i = 0; i < len; i++) { + for (i = 0; i < len; ++i) { target[i + targetStart] = this[i + start] } } else { @@ -1280,31 +1611,63 @@ Buffer.prototype.copy = function copy (target, targetStart, start, end) { return len } -// fill(value, start=0, end=buffer.length) -Buffer.prototype.fill = function fill (value, start, end) { - if (!value) value = 0 - if (!start) start = 0 - if (!end) end = this.length - - if (end < start) throw new RangeError('end < start') - - // Fill 0 bytes; we're done - if (end === start) return - if (this.length === 0) return +// Usage: +// buffer.fill(number[, offset[, end]]) +// buffer.fill(buffer[, offset[, end]]) +// buffer.fill(string[, offset[, end]][, encoding]) +Buffer.prototype.fill = function fill (val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start + start = 0 + end = this.length + } else if (typeof end === 'string') { + encoding = end + end = this.length + } + if (val.length === 1) { + var code = val.charCodeAt(0) + if (code < 256) { + val = code + } + } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string') + } + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding) + } + } else if (typeof val === 'number') { + val = val & 255 + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index') + } + + if (end <= start) { + return this + } + + start = start >>> 0 + end = end === undefined ? this.length : end >>> 0 - if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') - if (end < 0 || end > this.length) throw new RangeError('end out of bounds') + if (!val) val = 0 var i - if (typeof value === 'number') { - for (i = start; i < end; i++) { - this[i] = value + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val } } else { - var bytes = utf8ToBytes(value.toString()) + var bytes = Buffer.isBuffer(val) + ? val + : new Buffer(val, encoding) var len = bytes.length - for (i = start; i < end; i++) { - this[i] = bytes[i % len] + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len] } } @@ -1314,11 +1677,11 @@ Buffer.prototype.fill = function fill (value, start, end) { // HELPER FUNCTIONS // ================ -var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g +var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g function base64clean (str) { // Node strips out invalid characters like \n and \t from the string, base64-js does not - str = stringtrim(str).replace(INVALID_BASE64_RE, '') + str = str.trim().replace(INVALID_BASE64_RE, '') // Node converts strings with length < 2 to '' if (str.length < 2) return '' // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not @@ -1328,11 +1691,6 @@ function base64clean (str) { return str } -function stringtrim (str) { - if (str.trim) return str.trim() - return str.replace(/^\s+|\s+$/g, '') -} - function toHex (n) { if (n < 16) return '0' + n.toString(16) return n.toString(16) @@ -1345,7 +1703,7 @@ function utf8ToBytes (string, units) { var leadSurrogate = null var bytes = [] - for (var i = 0; i < length; i++) { + for (var i = 0; i < length; ++i) { codePoint = string.charCodeAt(i) // is surrogate component @@ -1420,7 +1778,7 @@ function utf8ToBytes (string, units) { function asciiToBytes (str) { var byteArray = [] - for (var i = 0; i < str.length; i++) { + for (var i = 0; i < str.length; ++i) { // Node's code seems to be doing this and not & 0x7F.. byteArray.push(str.charCodeAt(i) & 0xFF) } @@ -1430,7 +1788,7 @@ function asciiToBytes (str) { function utf16leToBytes (str, units) { var c, hi, lo var byteArray = [] - for (var i = 0; i < str.length; i++) { + for (var i = 0; i < str.length; ++i) { if ((units -= 2) < 0) break c = str.charCodeAt(i) @@ -1448,1274 +1806,345 @@ function base64ToBytes (str) { } function blitBuffer (src, dst, offset, length) { - for (var i = 0; i < length; i++) { + for (var i = 0; i < length; ++i) { if ((i + offset >= dst.length) || (i >= src.length)) break dst[i + offset] = src[i] } return i } -}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"base64-js":2,"ieee754":3,"isarray":4}],2:[function(require,module,exports){ -;(function (exports) { - 'use strict' - - var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' - - var Arr = (typeof Uint8Array !== 'undefined') - ? Uint8Array - : Array +// Node 0.10 supports `ArrayBuffer` but lacks `ArrayBuffer.isView` +function isArrayBufferView (obj) { + return (typeof ArrayBuffer.isView === 'function') && ArrayBuffer.isView(obj) +} - var PLUS = '+'.charCodeAt(0) - var SLASH = '/'.charCodeAt(0) - var NUMBER = '0'.charCodeAt(0) - var LOWER = 'a'.charCodeAt(0) - var UPPER = 'A'.charCodeAt(0) - var PLUS_URL_SAFE = '-'.charCodeAt(0) - var SLASH_URL_SAFE = '_'.charCodeAt(0) +function numberIsNaN (obj) { + return obj !== obj // eslint-disable-line no-self-compare +} - function decode (elt) { - var code = elt.charCodeAt(0) - if (code === PLUS || code === PLUS_URL_SAFE) return 62 // '+' - if (code === SLASH || code === SLASH_URL_SAFE) return 63 // '/' - if (code < NUMBER) return -1 // no match - if (code < NUMBER + 10) return code - NUMBER + 26 + 26 - if (code < UPPER + 26) return code - UPPER - if (code < LOWER + 26) return code - LOWER + 26 - } +},{"base64-js":1,"ieee754":8}],3:[function(require,module,exports){ +// Generated by IcedCoffeeScript 108.0.11 +(function() { + var BaseError, Canceler, EscErr, EscOk, c_to_camel, ipush, make_error_klass, make_errors, make_esc, to_lower, util, + __slice = [].slice; - function b64ToByteArray (b64) { - var i, j, l, tmp, placeHolders, arr + util = require('util'); - if (b64.length % 4 > 0) { - throw new Error('Invalid string. Length must be a multiple of 4') + exports.BaseError = BaseError = function(msg, constructor) { + if (typeof Error.captureStackTrace === "function") { + Error.captureStackTrace(this, this.constructor); } + return this.message = msg || 'Error'; + }; - // the number of equal signs (place holders) - // if there are two placeholders, than the two characters before it - // represent one byte - // if there is only one, then the three characters before it represent 2 bytes - // this is just a cheap hack to not do indexOf twice - var len = b64.length - placeHolders = b64.charAt(len - 2) === '=' ? 2 : b64.charAt(len - 1) === '=' ? 1 : 0 + util.inherits(BaseError, Error); - // base64 is 4/3 + up to two characters of the original data - arr = new Arr(b64.length * 3 / 4 - placeHolders) + BaseError.prototype.name = "BaseError"; - // if there are placeholders, only get up to the last complete 4 chars - l = placeHolders > 0 ? b64.length - 4 : b64.length + to_lower = function(s) { + return s[0].toUpperCase() + s.slice(1).toLowerCase(); + }; - var L = 0 + c_to_camel = function(s) { + var p; + return ((function() { + var _i, _len, _ref, _results; + _ref = s.split(/_/); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + p = _ref[_i]; + _results.push(to_lower(p)); + } + return _results; + })()).join(''); + }; - function push (v) { - arr[L++] = v - } + make_error_klass = function(k, code, default_msg) { + var ctor; + ctor = function(msg) { + BaseError.call(this, msg || default_msg, this.constructor); + this.istack = []; + this.code = code; + return this; + }; + util.inherits(ctor, BaseError); + ctor.prototype.name = k; + ctor.prototype.inspect = function() { + return "[" + k + ": " + this.message + " (code " + this.code + ")]"; + }; + return ctor; + }; - for (i = 0, j = 0; i < l; i += 4, j += 3) { - tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) - push((tmp & 0xFF0000) >> 16) - push((tmp & 0xFF00) >> 8) - push(tmp & 0xFF) + exports.make_errors = make_errors = function(d) { + var enam, errno, k, msg, out, val; + out = { + msg: {}, + name: {}, + code: {} + }; + d.OK = "Success"; + errno = 100; + for (k in d) { + msg = d[k]; + if (k !== "OK") { + enam = (c_to_camel(k)) + "Error"; + val = errno++; + out[enam] = make_error_klass(enam, val, msg); + } else { + val = 0; + } + out[k] = val; + out.msg[k] = out.msg[val] = msg; + out.name[k] = out.name[val] = k; + out.code[k] = val; } + return out; + }; - if (placeHolders === 2) { - tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) - push(tmp & 0xFF) - } else if (placeHolders === 1) { - tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) - push((tmp >> 8) & 0xFF) - push(tmp & 0xFF) + ipush = function(e, msg) { + if (msg != null) { + if (e.istack == null) { + e.istack = []; + } + return e.istack.push(msg); } + }; - return arr - } - - function uint8ToBase64 (uint8) { - var i - var extraBytes = uint8.length % 3 // if we have 1 byte left, pad 2 bytes - var output = '' - var temp, length + exports.make_esc = make_esc = function(gcb, where) { + return function(lcb) { + return function() { + var args, err; + err = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (err == null) { + return lcb.apply(null, args); + } else if (!gcb.__esc) { + gcb.__esc = true; + ipush(err, where); + return gcb(err); + } + }; + }; + }; - function encode (num) { - return lookup.charAt(num) + exports.EscOk = EscOk = (function() { + function EscOk(gcb, where) { + this.gcb = gcb; + this.where = where; } - function tripletToBase64 (num) { - return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) - } + EscOk.prototype.bailout = function() { + var t; + if (this.gcb) { + t = this.gcb; + this.gcb = null; + return t(false); + } + }; - // go through the array every three bytes, we'll deal with trailing stuff later - for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { - temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) - output += tripletToBase64(temp) - } + EscOk.prototype.check_ok = function(cb) { + return (function(_this) { + return function() { + var args, ok; + ok = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!ok) { + return _this.bailout(); + } else { + return cb.apply(null, args); + } + }; + })(this); + }; - // pad the end with zeros, but make sure to not forget the extra bytes - switch (extraBytes) { - case 1: - temp = uint8[uint8.length - 1] - output += encode(temp >> 2) - output += encode((temp << 4) & 0x3F) - output += '==' - break - case 2: - temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) - output += encode(temp >> 10) - output += encode((temp >> 4) & 0x3F) - output += encode((temp << 2) & 0x3F) - output += '=' - break - default: - break - } + EscOk.prototype.check_err = function(cb) { + return (function(_this) { + return function() { + var args, err; + err = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (err != null) { + ipush(err, _this.where); + return _this.bailout(); + } else { + return cb.apply(null, args); + } + }; + })(this); + }; - return output - } + EscOk.prototype.check_non_null = function(cb) { + return (function(_this) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + if (args[0] == null) { + return _this.bailout(); + } else { + return cb.apply(null, args); + } + }; + })(this); + }; - exports.toByteArray = b64ToByteArray - exports.fromByteArray = uint8ToBase64 -}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) + return EscOk; -},{}],3:[function(require,module,exports){ -exports.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m - var eLen = nBytes * 8 - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var nBits = -7 - var i = isLE ? (nBytes - 1) : 0 - var d = isLE ? -1 : 1 - var s = buffer[offset + i] + })(); - i += d + exports.EscErr = EscErr = (function() { + function EscErr(gcb, where) { + this.gcb = gcb; + this.where = where; + } - e = s & ((1 << (-nBits)) - 1) - s >>= (-nBits) - nBits += eLen - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + EscErr.prototype.finish = function(err) { + var t; + if (this.gcb) { + t = this.gcb; + this.gcb = null; + return t(err); + } + }; - m = e & ((1 << (-nBits)) - 1) - e >>= (-nBits) - nBits += mLen - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + EscErr.prototype.check_ok = function(cb, eclass, emsg) { + if (eclass == null) { + eclass = Error; + } + if (emsg == null) { + emsg = null; + } + return function() { + var args, err, ok; + ok = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (!ok) { + err = new eclass(emsg); + ipush(err, this.where); + return this.finish(err); + } else { + return cb.apply(null, args); + } + }; + }; - if (e === 0) { - e = 1 - eBias - } else if (e === eMax) { - return m ? NaN : ((s ? -1 : 1) * Infinity) - } else { - m = m + Math.pow(2, mLen) - e = e - eBias - } - return (s ? -1 : 1) * m * Math.pow(2, e - mLen) -} + EscErr.prototype.check_err = function(cb) { + return function() { + var args, err; + err = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; + if (err != null) { + ipush(err, this.where); + return this.finish(err); + } else { + return cb.apply(null, args); + } + }; + }; -exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c - var eLen = nBytes * 8 - mLen - 1 - var eMax = (1 << eLen) - 1 - var eBias = eMax >> 1 - var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) - var i = isLE ? 0 : (nBytes - 1) - var d = isLE ? 1 : -1 - var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 + return EscErr; - value = Math.abs(value) + })(); - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0 - e = eMax - } else { - e = Math.floor(Math.log(value) / Math.LN2) - if (value * (c = Math.pow(2, -e)) < 1) { - e-- - c *= 2 - } - if (e + eBias >= 1) { - value += rt / c - } else { - value += rt * Math.pow(2, 1 - eBias) - } - if (value * c >= 2) { - e++ - c /= 2 + exports.Canceler = Canceler = (function() { + function Canceler(klass) { + this.klass = klass != null ? klass : Error; + this._canceled = false; } - if (e + eBias >= eMax) { - m = 0 - e = eMax - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen) - e = e + eBias - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) - e = 0 - } - } + Canceler.prototype.is_canceled = function() { + return this._canceled; + }; - for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + Canceler.prototype.is_ok = function() { + return !this._canceled; + }; - e = (e << mLen) | m - eLen += mLen - for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + Canceler.prototype.cancel = function() { + return this._canceled = true; + }; - buffer[offset + i - d] |= s * 128 -} + Canceler.prototype.err = function() { + if (this._canceled) { + return new this.klass("Aborted"); + } else { + return null; + } + }; -},{}],4:[function(require,module,exports){ -var toString = {}.toString; + return Canceler; -module.exports = Array.isArray || function (arr) { - return toString.call(arr) == '[object Array]'; -}; + })(); -},{}],5:[function(require,module,exports){ -if (typeof Object.create === 'function') { - // implementation from standard node.js 'util' module - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } - }); + exports.chain = function(cb, f) { + return function() { + var args; + args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return f(function() { + return cb.apply(null, args); + }); + }; }; -} else { - // old school shim for old browsers - module.exports = function inherits(ctor, superCtor) { - ctor.super_ = superCtor - var TempCtor = function () {} - TempCtor.prototype = superCtor.prototype - ctor.prototype = new TempCtor() - ctor.prototype.constructor = ctor - } -} - -},{}],6:[function(require,module,exports){ -// shim for using process in browser - -var process = module.exports = {}; -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; -function cleanUpNextTick() { - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} + exports.chain_err = function(cb, f) { + return function() { + var args0; + args0 = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return f(function() { + var args1; + args1 = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + return cb.apply(null, ((args1[0] != null) && !(args0[0] != null) ? args1 : args0)); + }); + }; + }; -function drainQueue() { - if (draining) { - return; - } - var timeout = setTimeout(cleanUpNextTick); - draining = true; +}).call(this); - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - clearTimeout(timeout); -} -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - setTimeout(drainQueue, 0); - } -}; -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; +},{"util":38}],4:[function(require,module,exports){ +// Generated by IcedCoffeeScript 108.0.8 +(function() { + module.exports = { + k: "__iced_k", + k_noop: "__iced_k_noop", + param: "__iced_p_", + ns: "iced", + runtime: "runtime", + Deferrals: "Deferrals", + deferrals: "__iced_deferrals", + fulfill: "_fulfill", + b_while: "_break", + t_while: "_while", + c_while: "_continue", + n_while: "_next", + n_arg: "__iced_next_arg", + defer_method: "defer", + slot: "__slot", + assign_fn: "assign_fn", + autocb: "autocb", + retslot: "ret", + trace: "__iced_trace", + passed_deferral: "__iced_passed_deferral", + findDeferral: "findDeferral", + lineno: "lineno", + parent: "parent", + filename: "filename", + funcname: "funcname", + catchExceptions: 'catchExceptions', + runtime_modes: ["node", "inline", "window", "none", "browserify", "interp"], + trampoline: "trampoline", + context: "context", + defer_arg: "__iced_defer_" + }; -function noop() {} +}).call(this); -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; +},{}],5:[function(require,module,exports){ +// Generated by IcedCoffeeScript 108.0.8 +(function() { + var C, Pipeliner, iced, __iced_k, __iced_k_noop, _iand, _ior, _timeout, + __slice = [].slice; -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; + __iced_k = __iced_k_noop = function() {}; -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; + C = require('./const'); -},{}],7:[function(require,module,exports){ -module.exports = function isBuffer(arg) { - return arg && typeof arg === 'object' - && typeof arg.copy === 'function' - && typeof arg.fill === 'function' - && typeof arg.readUInt8 === 'function'; -} -},{}],8:[function(require,module,exports){ -(function (process,global){ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -var formatRegExp = /%[sdj%]/g; -exports.format = function(f) { - if (!isString(f)) { - var objects = []; - for (var i = 0; i < arguments.length; i++) { - objects.push(inspect(arguments[i])); - } - return objects.join(' '); - } - - var i = 1; - var args = arguments; - var len = args.length; - var str = String(f).replace(formatRegExp, function(x) { - if (x === '%%') return '%'; - if (i >= len) return x; - switch (x) { - case '%s': return String(args[i++]); - case '%d': return Number(args[i++]); - case '%j': - try { - return JSON.stringify(args[i++]); - } catch (_) { - return '[Circular]'; - } - default: - return x; - } - }); - for (var x = args[i]; i < len; x = args[++i]) { - if (isNull(x) || !isObject(x)) { - str += ' ' + x; - } else { - str += ' ' + inspect(x); - } - } - return str; -}; - - -// Mark that a method should not be used. -// Returns a modified function which warns once by default. -// If --no-deprecation is set, then it is a no-op. -exports.deprecate = function(fn, msg) { - // Allow for deprecating things in the process of starting up. - if (isUndefined(global.process)) { - return function() { - return exports.deprecate(fn, msg).apply(this, arguments); - }; - } - - if (process.noDeprecation === true) { - return fn; - } - - var warned = false; - function deprecated() { - if (!warned) { - if (process.throwDeprecation) { - throw new Error(msg); - } else if (process.traceDeprecation) { - console.trace(msg); - } else { - console.error(msg); - } - warned = true; - } - return fn.apply(this, arguments); - } - - return deprecated; -}; - - -var debugs = {}; -var debugEnviron; -exports.debuglog = function(set) { - if (isUndefined(debugEnviron)) - debugEnviron = process.env.NODE_DEBUG || ''; - set = set.toUpperCase(); - if (!debugs[set]) { - if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { - var pid = process.pid; - debugs[set] = function() { - var msg = exports.format.apply(exports, arguments); - console.error('%s %d: %s', set, pid, msg); - }; - } else { - debugs[set] = function() {}; - } - } - return debugs[set]; -}; - - -/** - * Echos the value of a value. Trys to print the value out - * in the best way possible given the different types. - * - * @param {Object} obj The object to print out. - * @param {Object} opts Optional options object that alters the output. - */ -/* legacy: obj, showHidden, depth, colors*/ -function inspect(obj, opts) { - // default options - var ctx = { - seen: [], - stylize: stylizeNoColor - }; - // legacy... - if (arguments.length >= 3) ctx.depth = arguments[2]; - if (arguments.length >= 4) ctx.colors = arguments[3]; - if (isBoolean(opts)) { - // legacy... - ctx.showHidden = opts; - } else if (opts) { - // got an "options" object - exports._extend(ctx, opts); - } - // set default options - if (isUndefined(ctx.showHidden)) ctx.showHidden = false; - if (isUndefined(ctx.depth)) ctx.depth = 2; - if (isUndefined(ctx.colors)) ctx.colors = false; - if (isUndefined(ctx.customInspect)) ctx.customInspect = true; - if (ctx.colors) ctx.stylize = stylizeWithColor; - return formatValue(ctx, obj, ctx.depth); -} -exports.inspect = inspect; - - -// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics -inspect.colors = { - 'bold' : [1, 22], - 'italic' : [3, 23], - 'underline' : [4, 24], - 'inverse' : [7, 27], - 'white' : [37, 39], - 'grey' : [90, 39], - 'black' : [30, 39], - 'blue' : [34, 39], - 'cyan' : [36, 39], - 'green' : [32, 39], - 'magenta' : [35, 39], - 'red' : [31, 39], - 'yellow' : [33, 39] -}; - -// Don't use 'blue' not visible on cmd.exe -inspect.styles = { - 'special': 'cyan', - 'number': 'yellow', - 'boolean': 'yellow', - 'undefined': 'grey', - 'null': 'bold', - 'string': 'green', - 'date': 'magenta', - // "name": intentionally not styling - 'regexp': 'red' -}; - - -function stylizeWithColor(str, styleType) { - var style = inspect.styles[styleType]; - - if (style) { - return '\u001b[' + inspect.colors[style][0] + 'm' + str + - '\u001b[' + inspect.colors[style][1] + 'm'; - } else { - return str; - } -} - - -function stylizeNoColor(str, styleType) { - return str; -} - - -function arrayToHash(array) { - var hash = {}; - - array.forEach(function(val, idx) { - hash[val] = true; - }); - - return hash; -} - - -function formatValue(ctx, value, recurseTimes) { - // Provide a hook for user-specified inspect functions. - // Check that value is an object with an inspect function on it - if (ctx.customInspect && - value && - isFunction(value.inspect) && - // Filter out the util module, it's inspect function is special - value.inspect !== exports.inspect && - // Also filter out any prototype objects using the circular check. - !(value.constructor && value.constructor.prototype === value)) { - var ret = value.inspect(recurseTimes, ctx); - if (!isString(ret)) { - ret = formatValue(ctx, ret, recurseTimes); - } - return ret; - } - - // Primitive types cannot have properties - var primitive = formatPrimitive(ctx, value); - if (primitive) { - return primitive; - } - - // Look up the keys of the object. - var keys = Object.keys(value); - var visibleKeys = arrayToHash(keys); - - if (ctx.showHidden) { - keys = Object.getOwnPropertyNames(value); - } - - // IE doesn't make error fields non-enumerable - // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx - if (isError(value) - && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { - return formatError(value); - } - - // Some type of object without properties can be shortcutted. - if (keys.length === 0) { - if (isFunction(value)) { - var name = value.name ? ': ' + value.name : ''; - return ctx.stylize('[Function' + name + ']', 'special'); - } - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } - if (isDate(value)) { - return ctx.stylize(Date.prototype.toString.call(value), 'date'); - } - if (isError(value)) { - return formatError(value); - } - } - - var base = '', array = false, braces = ['{', '}']; - - // Make Array say that they are Array - if (isArray(value)) { - array = true; - braces = ['[', ']']; - } - - // Make functions say that they are functions - if (isFunction(value)) { - var n = value.name ? ': ' + value.name : ''; - base = ' [Function' + n + ']'; - } - - // Make RegExps say that they are RegExps - if (isRegExp(value)) { - base = ' ' + RegExp.prototype.toString.call(value); - } - - // Make dates with properties first say the date - if (isDate(value)) { - base = ' ' + Date.prototype.toUTCString.call(value); - } - - // Make error with message first say the error - if (isError(value)) { - base = ' ' + formatError(value); - } - - if (keys.length === 0 && (!array || value.length == 0)) { - return braces[0] + base + braces[1]; - } - - if (recurseTimes < 0) { - if (isRegExp(value)) { - return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); - } else { - return ctx.stylize('[Object]', 'special'); - } - } - - ctx.seen.push(value); - - var output; - if (array) { - output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); - } else { - output = keys.map(function(key) { - return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); - }); - } - - ctx.seen.pop(); - - return reduceToSingleString(output, base, braces); -} - - -function formatPrimitive(ctx, value) { - if (isUndefined(value)) - return ctx.stylize('undefined', 'undefined'); - if (isString(value)) { - var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') - .replace(/'/g, "\\'") - .replace(/\\"/g, '"') + '\''; - return ctx.stylize(simple, 'string'); - } - if (isNumber(value)) - return ctx.stylize('' + value, 'number'); - if (isBoolean(value)) - return ctx.stylize('' + value, 'boolean'); - // For some reason typeof null is "object", so special case here. - if (isNull(value)) - return ctx.stylize('null', 'null'); -} - - -function formatError(value) { - return '[' + Error.prototype.toString.call(value) + ']'; -} - - -function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { - var output = []; - for (var i = 0, l = value.length; i < l; ++i) { - if (hasOwnProperty(value, String(i))) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - String(i), true)); - } else { - output.push(''); - } - } - keys.forEach(function(key) { - if (!key.match(/^\d+$/)) { - output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, - key, true)); - } - }); - return output; -} - - -function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { - var name, str, desc; - desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; - if (desc.get) { - if (desc.set) { - str = ctx.stylize('[Getter/Setter]', 'special'); - } else { - str = ctx.stylize('[Getter]', 'special'); - } - } else { - if (desc.set) { - str = ctx.stylize('[Setter]', 'special'); - } - } - if (!hasOwnProperty(visibleKeys, key)) { - name = '[' + key + ']'; - } - if (!str) { - if (ctx.seen.indexOf(desc.value) < 0) { - if (isNull(recurseTimes)) { - str = formatValue(ctx, desc.value, null); - } else { - str = formatValue(ctx, desc.value, recurseTimes - 1); - } - if (str.indexOf('\n') > -1) { - if (array) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); - } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); - } - } - } else { - str = ctx.stylize('[Circular]', 'special'); - } - } - if (isUndefined(name)) { - if (array && key.match(/^\d+$/)) { - return str; - } - name = JSON.stringify('' + key); - if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { - name = name.substr(1, name.length - 2); - name = ctx.stylize(name, 'name'); - } else { - name = name.replace(/'/g, "\\'") - .replace(/\\"/g, '"') - .replace(/(^"|"$)/g, "'"); - name = ctx.stylize(name, 'string'); - } - } - - return name + ': ' + str; -} - - -function reduceToSingleString(output, base, braces) { - var numLinesEst = 0; - var length = output.reduce(function(prev, cur) { - numLinesEst++; - if (cur.indexOf('\n') >= 0) numLinesEst++; - return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; - }, 0); - - if (length > 60) { - return braces[0] + - (base === '' ? '' : base + '\n ') + - ' ' + - output.join(',\n ') + - ' ' + - braces[1]; - } - - return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; -} - - -// NOTE: These type checking functions intentionally don't use `instanceof` -// because it is fragile and can be easily faked with `Object.create()`. -function isArray(ar) { - return Array.isArray(ar); -} -exports.isArray = isArray; - -function isBoolean(arg) { - return typeof arg === 'boolean'; -} -exports.isBoolean = isBoolean; - -function isNull(arg) { - return arg === null; -} -exports.isNull = isNull; - -function isNullOrUndefined(arg) { - return arg == null; -} -exports.isNullOrUndefined = isNullOrUndefined; - -function isNumber(arg) { - return typeof arg === 'number'; -} -exports.isNumber = isNumber; - -function isString(arg) { - return typeof arg === 'string'; -} -exports.isString = isString; - -function isSymbol(arg) { - return typeof arg === 'symbol'; -} -exports.isSymbol = isSymbol; - -function isUndefined(arg) { - return arg === void 0; -} -exports.isUndefined = isUndefined; - -function isRegExp(re) { - return isObject(re) && objectToString(re) === '[object RegExp]'; -} -exports.isRegExp = isRegExp; - -function isObject(arg) { - return typeof arg === 'object' && arg !== null; -} -exports.isObject = isObject; - -function isDate(d) { - return isObject(d) && objectToString(d) === '[object Date]'; -} -exports.isDate = isDate; - -function isError(e) { - return isObject(e) && - (objectToString(e) === '[object Error]' || e instanceof Error); -} -exports.isError = isError; - -function isFunction(arg) { - return typeof arg === 'function'; -} -exports.isFunction = isFunction; - -function isPrimitive(arg) { - return arg === null || - typeof arg === 'boolean' || - typeof arg === 'number' || - typeof arg === 'string' || - typeof arg === 'symbol' || // ES6 symbol - typeof arg === 'undefined'; -} -exports.isPrimitive = isPrimitive; - -exports.isBuffer = require('./support/isBuffer'); - -function objectToString(o) { - return Object.prototype.toString.call(o); -} - - -function pad(n) { - return n < 10 ? '0' + n.toString(10) : n.toString(10); -} - - -var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; - -// 26 Feb 16:19:34 -function timestamp() { - var d = new Date(); - var time = [pad(d.getHours()), - pad(d.getMinutes()), - pad(d.getSeconds())].join(':'); - return [d.getDate(), months[d.getMonth()], time].join(' '); -} - - -// log is just a thin wrapper to console.log that prepends a timestamp -exports.log = function() { - console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); -}; - - -/** - * Inherit the prototype methods from one constructor into another. - * - * The Function.prototype.inherits from lang.js rewritten as a standalone - * function (not on Function.prototype). NOTE: If this file is to be loaded - * during bootstrapping this function needs to be rewritten using some native - * functions as prototype setup using normal JavaScript does not work as - * expected during bootstrapping (see mirror.js in r114903). - * - * @param {function} ctor Constructor function which needs to inherit the - * prototype. - * @param {function} superCtor Constructor function to inherit prototype from. - */ -exports.inherits = require('inherits'); - -exports._extend = function(origin, add) { - // Don't do anything if add isn't an object - if (!add || !isObject(add)) return origin; - - var keys = Object.keys(add); - var i = keys.length; - while (i--) { - origin[keys[i]] = add[keys[i]]; - } - return origin; -}; - -function hasOwnProperty(obj, prop) { - return Object.prototype.hasOwnProperty.call(obj, prop); -} - -}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":7,"_process":6,"inherits":5}],9:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.7.1-g -(function() { - exports.transform = function(x, options) { - return x.icedTransform(options); - }; - - exports.runtime = require('iced-runtime'); - -}).call(this); - -},{"iced-runtime":13}],10:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.7.1-c -(function() { - var BaseError, Canceler, EscErr, EscOk, c_to_camel, ipush, make_error_klass, make_errors, make_esc, to_lower, util, - __slice = [].slice; - - util = require('util'); - - exports.BaseError = BaseError = function(msg, constructor) { - Error.captureStackTrace(this, this.constructor); - return this.message = msg || 'Error'; - }; - - util.inherits(BaseError, Error); - - BaseError.prototype.name = "BaseError"; - - to_lower = function(s) { - return s[0].toUpperCase() + s.slice(1).toLowerCase(); - }; - - c_to_camel = function(s) { - var p; - return ((function() { - var _i, _len, _ref, _results; - _ref = s.split(/_/); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - p = _ref[_i]; - _results.push(to_lower(p)); - } - return _results; - })()).join(''); - }; - - make_error_klass = function(k, code, default_msg) { - var ctor; - ctor = function(msg) { - BaseError.call(this, msg || default_msg, this.constructor); - this.istack = []; - this.code = code; - return this; - }; - util.inherits(ctor, BaseError); - ctor.prototype.name = k; - ctor.prototype.inspect = function() { - return "[" + k + ": " + this.message + " (code " + this.code + ")]"; - }; - return ctor; - }; - - exports.make_errors = make_errors = function(d) { - var enam, errno, k, msg, out, val; - out = { - msg: {}, - name: {}, - code: {} - }; - d.OK = "Success"; - errno = 100; - for (k in d) { - msg = d[k]; - if (k !== "OK") { - enam = (c_to_camel(k)) + "Error"; - val = errno++; - out[enam] = make_error_klass(enam, val, msg); - } else { - val = 0; - } - out[k] = val; - out.msg[k] = out.msg[val] = msg; - out.name[k] = out.name[val] = k; - out.code[k] = val; - } - return out; - }; - - ipush = function(e, msg) { - if (msg != null) { - if (e.istack == null) { - e.istack = []; - } - return e.istack.push(msg); - } - }; - - exports.make_esc = make_esc = function(gcb, where) { - return function(lcb) { - return function() { - var args, err; - err = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (err == null) { - return lcb.apply(null, args); - } else if (!gcb.__esc) { - gcb.__esc = true; - ipush(err, where); - return gcb(err); - } - }; - }; - }; - - exports.EscOk = EscOk = (function() { - function EscOk(gcb, where) { - this.gcb = gcb; - this.where = where; - } - - EscOk.prototype.bailout = function() { - var t; - if (this.gcb) { - t = this.gcb; - this.gcb = null; - return t(false); - } - }; - - EscOk.prototype.check_ok = function(cb) { - return (function(_this) { - return function() { - var args, ok; - ok = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (!ok) { - return _this.bailout(); - } else { - return cb.apply(null, args); - } - }; - })(this); - }; - - EscOk.prototype.check_err = function(cb) { - return (function(_this) { - return function() { - var args, err; - err = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (err != null) { - ipush(err, _this.where); - return _this.bailout(); - } else { - return cb.apply(null, args); - } - }; - })(this); - }; - - EscOk.prototype.check_non_null = function(cb) { - return (function(_this) { - return function() { - var args; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if (args[0] == null) { - return _this.bailout(); - } else { - return cb.apply(null, args); - } - }; - })(this); - }; - - return EscOk; - - })(); - - exports.EscErr = EscErr = (function() { - function EscErr(gcb, where) { - this.gcb = gcb; - this.where = where; - } - - EscErr.prototype.finish = function(err) { - var t; - if (this.gcb) { - t = this.gcb; - this.gcb = null; - return t(err); - } - }; - - EscErr.prototype.check_ok = function(cb, eclass, emsg) { - if (eclass == null) { - eclass = Error; - } - if (emsg == null) { - emsg = null; - } - return function() { - var args, err, ok; - ok = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (!ok) { - err = new eclass(emsg); - ipush(err, this.where); - return this.finish(err); - } else { - return cb.apply(null, args); - } - }; - }; - - EscErr.prototype.check_err = function(cb) { - return function() { - var args, err; - err = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; - if (err != null) { - ipush(err, this.where); - return this.finish(err); - } else { - return cb.apply(null, args); - } - }; - }; - - return EscErr; - - })(); - - exports.Canceler = Canceler = (function() { - function Canceler(klass) { - this.klass = klass != null ? klass : Error; - this._canceled = false; - } - - Canceler.prototype.is_canceled = function() { - return this._canceled; - }; - - Canceler.prototype.is_ok = function() { - return !this._canceled; - }; - - Canceler.prototype.cancel = function() { - return this._canceled = true; - }; - - Canceler.prototype.err = function() { - if (this._canceled) { - return new this.klass("Aborted"); - } else { - return null; - } - }; - - return Canceler; - - })(); - - exports.chain = function(cb, f) { - return function() { - var args; - args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - return f(function() { - return cb.apply(null, args); - }); - }; - }; - - exports.chain_err = function(cb, f) { - return function() { - var args0; - args0 = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - return f(function() { - var args1; - args1 = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - return cb.apply(null, ((args1[0] != null) && !(args0[0] != null) ? args1 : args0)); - }); - }; - }; - -}).call(this); - - - -},{"util":8}],11:[function(require,module,exports){ -// Generated by IcedCoffeeScript 108.0.8 -(function() { - module.exports = { - k: "__iced_k", - k_noop: "__iced_k_noop", - param: "__iced_p_", - ns: "iced", - runtime: "runtime", - Deferrals: "Deferrals", - deferrals: "__iced_deferrals", - fulfill: "_fulfill", - b_while: "_break", - t_while: "_while", - c_while: "_continue", - n_while: "_next", - n_arg: "__iced_next_arg", - defer_method: "defer", - slot: "__slot", - assign_fn: "assign_fn", - autocb: "autocb", - retslot: "ret", - trace: "__iced_trace", - passed_deferral: "__iced_passed_deferral", - findDeferral: "findDeferral", - lineno: "lineno", - parent: "parent", - filename: "filename", - funcname: "funcname", - catchExceptions: 'catchExceptions', - runtime_modes: ["node", "inline", "window", "none", "browserify", "interp"], - trampoline: "trampoline", - context: "context", - defer_arg: "__iced_defer_" - }; - -}).call(this); - -},{}],12:[function(require,module,exports){ -// Generated by IcedCoffeeScript 108.0.8 -(function() { - var C, Pipeliner, iced, __iced_k, __iced_k_noop, _iand, _ior, _timeout, - __slice = [].slice; - - __iced_k = __iced_k_noop = function() {}; - - C = require('./const'); - - exports.iced = iced = require('./runtime'); + exports.iced = iced = require('./runtime'); _timeout = function(cb, t, res, tmp) { var arr, rv, which, ___iced_passed_deferral, __iced_deferrals, __iced_k; @@ -2999,7 +2428,7 @@ function hasOwnProperty(obj, prop) { }).call(this); -},{"./const":11,"./runtime":14}],13:[function(require,module,exports){ +},{"./const":4,"./runtime":7}],6:[function(require,module,exports){ // Generated by IcedCoffeeScript 108.0.8 (function() { var k, mod, mods, v, _i, _len; @@ -3018,7 +2447,7 @@ function hasOwnProperty(obj, prop) { }).call(this); -},{"./const":11,"./library":12,"./runtime":14}],14:[function(require,module,exports){ +},{"./const":4,"./library":5,"./runtime":7}],7:[function(require,module,exports){ (function (process){ // Generated by IcedCoffeeScript 108.0.8 (function() { @@ -3205,46 +2634,132 @@ function hasOwnProperty(obj, prop) { return make_defer_return(this, defer_args, id, {}, multi); }; - return Rendezvous; + return Rendezvous; + + })(); + + exports.stackWalk = stackWalk = function(cb) { + var line, ret, tr, _ref; + ret = []; + tr = cb ? cb[C.trace] : __active_trace; + while (tr) { + line = " at " + (_trace_to_string(tr)); + ret.push(line); + tr = tr != null ? (_ref = tr[C.parent]) != null ? _ref[C.trace] : void 0 : void 0; + } + return ret; + }; + + exports.exceptionHandler = exceptionHandler = function(err, logger) { + var stack; + if (!logger) { + logger = console.error; + } + logger(err.stack); + stack = stackWalk(); + if (stack.length) { + logger("Iced 'stack' trace (w/ real line numbers):"); + return logger(stack.join("\n")); + } + }; + + exports.catchExceptions = function(logger) { + return typeof process !== "undefined" && process !== null ? process.on('uncaughtException', function(err) { + exceptionHandler(err, logger); + return process.exit(1); + }) : void 0; + }; + +}).call(this); + +}).call(this,require('_process')) +},{"./const":4,"_process":13}],8:[function(require,module,exports){ +exports.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var nBits = -7 + var i = isLE ? (nBytes - 1) : 0 + var d = isLE ? -1 : 1 + var s = buffer[offset + i] + + i += d + + e = s & ((1 << (-nBits)) - 1) + s >>= (-nBits) + nBits += eLen + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << (-nBits)) - 1) + e >>= (-nBits) + nBits += mLen + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias + } else if (e === eMax) { + return m ? NaN : ((s ? -1 : 1) * Infinity) + } else { + m = m + Math.pow(2, mLen) + e = e - eBias + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen) +} + +exports.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c + var eLen = nBytes * 8 - mLen - 1 + var eMax = (1 << eLen) - 1 + var eBias = eMax >> 1 + var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0) + var i = isLE ? 0 : (nBytes - 1) + var d = isLE ? 1 : -1 + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0 - })(); + value = Math.abs(value) - exports.stackWalk = stackWalk = function(cb) { - var line, ret, tr, _ref; - ret = []; - tr = cb ? cb[C.trace] : __active_trace; - while (tr) { - line = " at " + (_trace_to_string(tr)); - ret.push(line); - tr = tr != null ? (_ref = tr[C.parent]) != null ? _ref[C.trace] : void 0 : void 0; + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0 + e = eMax + } else { + e = Math.floor(Math.log(value) / Math.LN2) + if (value * (c = Math.pow(2, -e)) < 1) { + e-- + c *= 2 } - return ret; - }; - - exports.exceptionHandler = exceptionHandler = function(err, logger) { - var stack; - if (!logger) { - logger = console.error; + if (e + eBias >= 1) { + value += rt / c + } else { + value += rt * Math.pow(2, 1 - eBias) } - logger(err.stack); - stack = stackWalk(); - if (stack.length) { - logger("Iced 'stack' trace (w/ real line numbers):"); - return logger(stack.join("\n")); + if (value * c >= 2) { + e++ + c /= 2 } - }; - exports.catchExceptions = function(logger) { - return typeof process !== "undefined" && process !== null ? process.on('uncaughtException', function(err) { - exceptionHandler(err, logger); - return process.exit(1); - }) : void 0; - }; + if (e + eBias >= eMax) { + m = 0 + e = eMax + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen) + e = e + eBias + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen) + e = 0 + } + } -}).call(this); + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} -}).call(this,require('_process')) -},{"./const":11,"_process":6}],15:[function(require,module,exports){ + e = (e << mLen) | m + eLen += mLen + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128 +} + +},{}],9:[function(require,module,exports){ var lib = require('./lib/lib.js'); @@ -3264,7 +2779,7 @@ exports.generate = function(buffer) { return ret; }; -},{"./lib/lib.js":16}],16:[function(require,module,exports){ +},{"./lib/lib.js":10}],10:[function(require,module,exports){ var Crypto = exports.Crypto = {}; var Bitcoin = exports.Bitcoin = {}; @@ -5469,711 +4984,1122 @@ var BigInteger = exports.BigInteger; var neg = this.negate(); var R = this; - var i; - for (i = h.bitLength() - 2; i > 0; --i) { - R = R.twice(); + var i; + for (i = h.bitLength() - 2; i > 0; --i) { + R = R.twice(); + + var hBit = h.testBit(i); + var eBit = e.testBit(i); + + if (hBit != eBit) { + R = R.add2D(hBit ? this : neg); + } + } + + return R; + }; + + ec.PointFp.prototype.isOnCurve = function () { + var x = this.getX().toBigInteger(); + var y = this.getY().toBigInteger(); + var a = this.curve.getA().toBigInteger(); + var b = this.curve.getB().toBigInteger(); + var n = this.curve.getQ(); + var lhs = y.multiply(y).mod(n); + var rhs = x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(n); + return lhs.equals(rhs); + }; + + ec.PointFp.prototype.toString = function () { + return '(' + this.getX().toBigInteger().toString() + ',' + this.getY().toBigInteger().toString() + ')'; + }; + + /** + * Validate an elliptic curve point. + * + * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive + */ + ec.PointFp.prototype.validate = function () { + var n = this.curve.getQ(); + + // Check Q != O + if (this.isInfinity()) { + throw new Error("Point is at infinity."); + } + + // Check coordinate bounds + var x = this.getX().toBigInteger(); + var y = this.getY().toBigInteger(); + if (x.compareTo(BigInteger.ONE) < 0 || x.compareTo(n.subtract(BigInteger.ONE)) > 0) { + throw new Error('x coordinate out of bounds'); + } + if (y.compareTo(BigInteger.ONE) < 0 || y.compareTo(n.subtract(BigInteger.ONE)) > 0) { + throw new Error('y coordinate out of bounds'); + } + + // Check y^2 = x^3 + ax + b (mod n) + if (!this.isOnCurve()) { + throw new Error("Point is not on the curve."); + } + + // Check nQ = 0 (Q is a scalar multiple of G) + if (this.multiply(n).isInfinity()) { + // TODO: This check doesn't work - fix. + throw new Error("Point is not a scalar multiple of G."); + } + + return true; + }; + + + + + // ---------------- + // ECCurveFp constructor + ec.CurveFp = function (q, a, b) { + this.q = q; + this.a = this.fromBigInteger(a); + this.b = this.fromBigInteger(b); + this.infinity = new ec.PointFp(this, null, null); + } + + ec.CurveFp.prototype.getQ = function () { + return this.q; + }; + + ec.CurveFp.prototype.getA = function () { + return this.a; + }; + + ec.CurveFp.prototype.getB = function () { + return this.b; + }; + + ec.CurveFp.prototype.equals = function (other) { + if (other == this) return true; + return (this.q.equals(other.q) && this.a.equals(other.a) && this.b.equals(other.b)); + }; + + ec.CurveFp.prototype.getInfinity = function () { + return this.infinity; + }; + + ec.CurveFp.prototype.fromBigInteger = function (x) { + return new ec.FieldElementFp(this.q, x); + }; + + // for now, work with hex strings because they're easier in JS + // compressed support added by bitaddress.org + ec.CurveFp.prototype.decodePointHex = function (s) { + var firstByte = parseInt(s.substr(0, 2), 16); + switch (firstByte) { // first byte + case 0: + return this.infinity; + case 2: // compressed + case 3: // compressed + var yTilde = firstByte & 1; + var xHex = s.substr(2, s.length - 2); + var X1 = new BigInteger(xHex, 16); + return this.decompressPoint(yTilde, X1); + case 4: // uncompressed + case 6: // hybrid + case 7: // hybrid + var len = (s.length - 2) / 2; + var xHex = s.substr(2, len); + var yHex = s.substr(len + 2, len); + + return new ec.PointFp(this, + this.fromBigInteger(new BigInteger(xHex, 16)), + this.fromBigInteger(new BigInteger(yHex, 16))); + + default: // unsupported + return null; + } + }; + + /* + * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) + * Ported to JavaScript by bitaddress.org + * + * Number yTilde + * BigInteger X1 + */ + ec.CurveFp.prototype.decompressPoint = function (yTilde, X1) { + var x = this.fromBigInteger(X1); + var alpha = x.multiply(x.square().add(this.getA())).add(this.getB()); + var beta = alpha.sqrt(); + // if we can't find a sqrt we haven't got a point on the curve - run! + if (beta == null) throw new Error("Invalid point compression"); + var betaValue = beta.toBigInteger(); + var bit0 = betaValue.testBit(0) ? 1 : 0; + if (bit0 != yTilde) { + // Use the other root + beta = this.fromBigInteger(this.getQ().subtract(betaValue)); + } + return new ec.PointFp(this, x, beta, null, true); + }; + + + ec.fromHex = function (s) { return new BigInteger(s, 16); }; + + ec.integerToBytes = function (i, len) { + var bytes = i.toByteArrayUnsigned(); + if (len < bytes.length) { + bytes = bytes.slice(bytes.length - len); + } else while (len > bytes.length) { + bytes.unshift(0); + } + return bytes; + }; + + + // Named EC curves + // ---------------- + // X9ECParameters constructor + ec.X9Parameters = function (curve, g, n, h) { + this.curve = curve; + this.g = g; + this.n = n; + this.h = h; + } + ec.X9Parameters.prototype.getCurve = function () { return this.curve; }; + ec.X9Parameters.prototype.getG = function () { return this.g; }; + ec.X9Parameters.prototype.getN = function () { return this.n; }; + ec.X9Parameters.prototype.getH = function () { return this.h; }; + + // secp256k1 is the Curve used by Bitcoin + ec.secNamedCurves = { + // used by Bitcoin + "secp256k1": function () { + // p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1 + var p = ec.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"); + var a = BigInteger.ZERO; + var b = ec.fromHex("7"); + var n = ec.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"); + var h = BigInteger.ONE; + var curve = new ec.CurveFp(p, a, b); + var G = curve.decodePointHex("04" + + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798" + + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"); + return new ec.X9Parameters(curve, G, n, h); + } + }; - var hBit = h.testBit(i); - var eBit = e.testBit(i); + // secp256k1 called by Bitcoin's ECKEY + ec.getSECCurveByName = function (name) { + if (ec.secNamedCurves[name] == undefined) return null; + return ec.secNamedCurves[name](); + } +})(exports); - if (hBit != eBit) { - R = R.add2D(hBit ? this : neg); - } +var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bitcoinjs-lib/09e8c6e184d6501a0c2c59d73ca64db5c0d3eb95/src/address.js +// See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE +(function (Bitcoin) { + Bitcoin.Address = function (bytes) { + if ("string" == typeof bytes) { + bytes = Bitcoin.Address.decodeString(bytes); } - - return R; + this.hash = bytes; + this.version = Bitcoin.Address.networkVersion; }; - ec.PointFp.prototype.isOnCurve = function () { - var x = this.getX().toBigInteger(); - var y = this.getY().toBigInteger(); - var a = this.curve.getA().toBigInteger(); - var b = this.curve.getB().toBigInteger(); - var n = this.curve.getQ(); - var lhs = y.multiply(y).mod(n); - var rhs = x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(n); - return lhs.equals(rhs); + Bitcoin.Address.networkVersion = 0x00; // mainnet + + /** + * Serialize this object as a standard Bitcoin address. + * + * Returns the address as a base58-encoded string in the standardized format. + */ + Bitcoin.Address.prototype.toString = function () { + // Get a copy of the hash + var hash = this.hash.slice(0); + + // Version + hash.unshift(this.version); + var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); + var bytes = hash.concat(checksum.slice(0, 4)); + return Bitcoin.Base58.encode(bytes); }; - ec.PointFp.prototype.toString = function () { - return '(' + this.getX().toBigInteger().toString() + ',' + this.getY().toBigInteger().toString() + ')'; + Bitcoin.Address.prototype.getHashBase64 = function () { + return Crypto.util.bytesToBase64(this.hash); }; /** - * Validate an elliptic curve point. - * - * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive + * Parse a Bitcoin address contained in a string. */ - ec.PointFp.prototype.validate = function () { - var n = this.curve.getQ(); - - // Check Q != O - if (this.isInfinity()) { - throw new Error("Point is at infinity."); - } + Bitcoin.Address.decodeString = function (string) { + var bytes = Bitcoin.Base58.decode(string); + var hash = bytes.slice(0, 21); + var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); - // Check coordinate bounds - var x = this.getX().toBigInteger(); - var y = this.getY().toBigInteger(); - if (x.compareTo(BigInteger.ONE) < 0 || x.compareTo(n.subtract(BigInteger.ONE)) > 0) { - throw new Error('x coordinate out of bounds'); - } - if (y.compareTo(BigInteger.ONE) < 0 || y.compareTo(n.subtract(BigInteger.ONE)) > 0) { - throw new Error('y coordinate out of bounds'); + if (checksum[0] != bytes[21] || + checksum[1] != bytes[22] || + checksum[2] != bytes[23] || + checksum[3] != bytes[24]) { + throw "Checksum validation failed!"; } - // Check y^2 = x^3 + ax + b (mod n) - if (!this.isOnCurve()) { - throw new Error("Point is not on the curve."); - } + var version = hash.shift(); - // Check nQ = 0 (Q is a scalar multiple of G) - if (this.multiply(n).isInfinity()) { - // TODO: This check doesn't work - fix. - throw new Error("Point is not a scalar multiple of G."); + if (version != 0) { + throw "Version " + version + " not supported!"; } - return true; + return hash; }; +})(Bitcoin); +//https://raw.github.com/bitcoinjs/bitcoinjs-lib/c952aaeb3ee472e3776655b8ea07299ebed702c7/src/base58.js +// See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE +(function (Bitcoin) { + Bitcoin.Base58 = { + alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", + validRegex: /^[1-9A-HJ-NP-Za-km-z]+$/, + base: BigInteger.valueOf(58), + + /** + * Convert a byte array to a base58-encoded string. + * + * Written by Mike Hearn for BitcoinJ. + * Copyright (c) 2011 Google Inc. + * + * Ported to JavaScript by Stefan Thomas. + */ + encode: function (input) { + var bi = BigInteger.fromByteArrayUnsigned(input); + var chars = []; + while (bi.compareTo(B58.base) >= 0) { + var mod = bi.mod(B58.base); + chars.unshift(B58.alphabet[mod.intValue()]); + bi = bi.subtract(mod).divide(B58.base); + } + chars.unshift(B58.alphabet[bi.intValue()]); + // Convert leading zeros too. + for (var i = 0; i < input.length; i++) { + if (input[i] == 0x00) { + chars.unshift(B58.alphabet[0]); + } else break; + } + return chars.join(''); + }, - // ---------------- - // ECCurveFp constructor - ec.CurveFp = function (q, a, b) { - this.q = q; - this.a = this.fromBigInteger(a); - this.b = this.fromBigInteger(b); - this.infinity = new ec.PointFp(this, null, null); - } + /** + * Convert a base58-encoded string to a byte array. + * + * Written by Mike Hearn for BitcoinJ. + * Copyright (c) 2011 Google Inc. + * + * Ported to JavaScript by Stefan Thomas. + */ + decode: function (input) { + var bi = BigInteger.valueOf(0); + var leadingZerosNum = 0; + for (var i = input.length - 1; i >= 0; i--) { + var alphaIndex = B58.alphabet.indexOf(input[i]); + if (alphaIndex < 0) { + throw "Invalid character"; + } + bi = bi.add(BigInteger.valueOf(alphaIndex) + .multiply(B58.base.pow(input.length - 1 - i))); - ec.CurveFp.prototype.getQ = function () { - return this.q; - }; + // This counts leading zero bytes + if (input[i] == "1") leadingZerosNum++; + else leadingZerosNum = 0; + } + var bytes = bi.toByteArrayUnsigned(); - ec.CurveFp.prototype.getA = function () { - return this.a; - }; + // Add leading zeros + while (leadingZerosNum-- > 0) bytes.unshift(0); - ec.CurveFp.prototype.getB = function () { - return this.b; + return bytes; + } }; - ec.CurveFp.prototype.equals = function (other) { - if (other == this) return true; - return (this.q.equals(other.q) && this.a.equals(other.a) && this.b.equals(other.b)); - }; + var B58 = Bitcoin.Base58; +})(Bitcoin); +//https://raw.github.com/pointbiz/bitcoinjs-lib/9b2f94a028a7bc9bed94e0722563e9ff1d8e8db8/src/eckey.js +// See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE +(function (Bitcoin) { + Bitcoin.ECKey = (function () { + var ecparams = EllipticCurve.getSECCurveByName("secp256k1"); - ec.CurveFp.prototype.getInfinity = function () { - return this.infinity; - }; + var ECKey = function (input) { + if (input instanceof BigInteger) { + // Input is a private key value + this.priv = input; + } else if (Bitcoin.Util.isArray(input)) { + // Prepend zero byte to prevent interpretation as negative integer + this.priv = BigInteger.fromByteArrayUnsigned(input); + } else if ("string" == typeof input) { + var bytes = null; + if (ECKey.isWalletImportFormat(input)) { + bytes = ECKey.decodeWalletImportFormat(input); + } else if (ECKey.isCompressedWalletImportFormat(input)) { + bytes = ECKey.decodeCompressedWalletImportFormat(input); + this.compressed = true; + } else if (ECKey.isMiniFormat(input)) { + bytes = Crypto.SHA256(input, { asBytes: true }); + } else if (ECKey.isHexFormat(input)) { + bytes = Crypto.util.hexToBytes(input); + } else if (ECKey.isBase64Format(input)) { + bytes = Crypto.util.base64ToBytes(input); + } + + if (ECKey.isBase6Format(input)) { + this.priv = new BigInteger(input, 6); + } else if (bytes == null || bytes.length != 32) { + this.priv = null; + } else { + // Prepend zero byte to prevent interpretation as negative integer + this.priv = BigInteger.fromByteArrayUnsigned(bytes); + } + } else { + throw new Error("no plausible constructor behavior"); + } - ec.CurveFp.prototype.fromBigInteger = function (x) { - return new ec.FieldElementFp(this.q, x); - }; + this.compressed = (this.compressed == undefined) ? !!ECKey.compressByDefault : this.compressed; + }; + + ECKey.privateKeyPrefix = 0x80; // mainnet 0x80 testnet 0xEF + + /** + * Whether public keys should be returned compressed by default. + */ + ECKey.compressByDefault = false; + + /** + * Set whether the public key should be returned compressed or not. + */ + ECKey.prototype.setCompressed = function (v) { + this.compressed = !!v; + if (this.pubPoint) this.pubPoint.compressed = this.compressed; + return this; + }; - // for now, work with hex strings because they're easier in JS - // compressed support added by bitaddress.org - ec.CurveFp.prototype.decodePointHex = function (s) { - var firstByte = parseInt(s.substr(0, 2), 16); - switch (firstByte) { // first byte - case 0: - return this.infinity; - case 2: // compressed - case 3: // compressed - var yTilde = firstByte & 1; - var xHex = s.substr(2, s.length - 2); - var X1 = new BigInteger(xHex, 16); - return this.decompressPoint(yTilde, X1); - case 4: // uncompressed - case 6: // hybrid - case 7: // hybrid - var len = (s.length - 2) / 2; - var xHex = s.substr(2, len); - var yHex = s.substr(len + 2, len); + /* + * Return public key as a byte array in DER encoding + */ + ECKey.prototype.getPub = function () { + if (this.compressed) { + if (this.pubComp) return this.pubComp; + return this.pubComp = this.getPubPoint().getEncoded(1); + } else { + if (this.pubUncomp) return this.pubUncomp; + return this.pubUncomp = this.getPubPoint().getEncoded(0); + } + }; - return new ec.PointFp(this, - this.fromBigInteger(new BigInteger(xHex, 16)), - this.fromBigInteger(new BigInteger(yHex, 16))); + /** + * Return public point as ECPoint object. + */ + ECKey.prototype.getPubPoint = function () { + if (!this.pubPoint) { + this.pubPoint = ecparams.getG().multiply(this.priv); + this.pubPoint.compressed = this.compressed; + } + return this.pubPoint; + }; - default: // unsupported - return null; - } - }; + ECKey.prototype.getPubKeyHex = function () { + if (this.compressed) { + if (this.pubKeyHexComp) return this.pubKeyHexComp; + return this.pubKeyHexComp = Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase(); + } else { + if (this.pubKeyHexUncomp) return this.pubKeyHexUncomp; + return this.pubKeyHexUncomp = Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase(); + } + }; - /* - * Copyright (c) 2000 - 2011 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) - * Ported to JavaScript by bitaddress.org - * - * Number yTilde - * BigInteger X1 - */ - ec.CurveFp.prototype.decompressPoint = function (yTilde, X1) { - var x = this.fromBigInteger(X1); - var alpha = x.multiply(x.square().add(this.getA())).add(this.getB()); - var beta = alpha.sqrt(); - // if we can't find a sqrt we haven't got a point on the curve - run! - if (beta == null) throw new Error("Invalid point compression"); - var betaValue = beta.toBigInteger(); - var bit0 = betaValue.testBit(0) ? 1 : 0; - if (bit0 != yTilde) { - // Use the other root - beta = this.fromBigInteger(this.getQ().subtract(betaValue)); - } - return new ec.PointFp(this, x, beta, null, true); - }; + /** + * Get the pubKeyHash for this key. + * + * This is calculated as RIPE160(SHA256([encoded pubkey])) and returned as + * a byte array. + */ + ECKey.prototype.getPubKeyHash = function () { + if (this.compressed) { + if (this.pubKeyHashComp) return this.pubKeyHashComp; + return this.pubKeyHashComp = Bitcoin.Util.sha256ripe160(this.getPub()); + } else { + if (this.pubKeyHashUncomp) return this.pubKeyHashUncomp; + return this.pubKeyHashUncomp = Bitcoin.Util.sha256ripe160(this.getPub()); + } + }; + ECKey.prototype.getBitcoinAddress = function () { + var hash = this.getPubKeyHash(); + var addr = new Bitcoin.Address(hash); + return addr.toString(); + }; - ec.fromHex = function (s) { return new BigInteger(s, 16); }; + /* + * Takes a public point as a hex string or byte array + */ + ECKey.prototype.setPub = function (pub) { + // byte array + if (Bitcoin.Util.isArray(pub)) { + pub = Crypto.util.bytesToHex(pub).toString().toUpperCase(); + } + var ecPoint = ecparams.getCurve().decodePointHex(pub); + this.setCompressed(ecPoint.compressed); + this.pubPoint = ecPoint; + return this; + }; - ec.integerToBytes = function (i, len) { - var bytes = i.toByteArrayUnsigned(); - if (len < bytes.length) { - bytes = bytes.slice(bytes.length - len); - } else while (len > bytes.length) { - bytes.unshift(0); - } - return bytes; - }; + // Sipa Private Key Wallet Import Format + ECKey.prototype.getBitcoinWalletImportFormat = function () { + var bytes = this.getBitcoinPrivateKeyByteArray(); + bytes.unshift(ECKey.privateKeyPrefix); // prepend 0x80 byte + if (this.compressed) bytes.push(0x01); // append 0x01 byte for compressed format + var checksum = Crypto.SHA256(Crypto.SHA256(bytes, { asBytes: true }), { asBytes: true }); + bytes = bytes.concat(checksum.slice(0, 4)); + var privWif = Bitcoin.Base58.encode(bytes); + return privWif; + }; + // Private Key Hex Format + ECKey.prototype.getBitcoinHexFormat = function () { + return Crypto.util.bytesToHex(this.getBitcoinPrivateKeyByteArray()).toString().toUpperCase(); + }; - // Named EC curves - // ---------------- - // X9ECParameters constructor - ec.X9Parameters = function (curve, g, n, h) { - this.curve = curve; - this.g = g; - this.n = n; - this.h = h; - } - ec.X9Parameters.prototype.getCurve = function () { return this.curve; }; - ec.X9Parameters.prototype.getG = function () { return this.g; }; - ec.X9Parameters.prototype.getN = function () { return this.n; }; - ec.X9Parameters.prototype.getH = function () { return this.h; }; + // Private Key Base64 Format + ECKey.prototype.getBitcoinBase64Format = function () { + return Crypto.util.bytesToBase64(this.getBitcoinPrivateKeyByteArray()); + }; - // secp256k1 is the Curve used by Bitcoin - ec.secNamedCurves = { - // used by Bitcoin - "secp256k1": function () { - // p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1 - var p = ec.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"); - var a = BigInteger.ZERO; - var b = ec.fromHex("7"); - var n = ec.fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141"); - var h = BigInteger.ONE; - var curve = new ec.CurveFp(p, a, b); - var G = curve.decodePointHex("04" - + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798" - + "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"); - return new ec.X9Parameters(curve, G, n, h); - } - }; + ECKey.prototype.getBitcoinPrivateKeyByteArray = function () { + // Get a copy of private key as a byte array + var bytes = this.priv.toByteArrayUnsigned(); + // zero pad if private key is less than 32 bytes + while (bytes.length < 32) bytes.unshift(0x00); + return bytes; + }; - // secp256k1 called by Bitcoin's ECKEY - ec.getSECCurveByName = function (name) { - if (ec.secNamedCurves[name] == undefined) return null; - return ec.secNamedCurves[name](); - } -})(exports); + ECKey.prototype.toString = function (format) { + format = format || ""; + if (format.toString().toLowerCase() == "base64" || format.toString().toLowerCase() == "b64") { + return this.getBitcoinBase64Format(); + } + // Wallet Import Format + else if (format.toString().toLowerCase() == "wif") { + return this.getBitcoinWalletImportFormat(); + } + else { + return this.getBitcoinHexFormat(); + } + }; -var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bitcoinjs-lib/09e8c6e184d6501a0c2c59d73ca64db5c0d3eb95/src/address.js -// See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE -(function (Bitcoin) { - Bitcoin.Address = function (bytes) { - if ("string" == typeof bytes) { - bytes = Bitcoin.Address.decodeString(bytes); - } - this.hash = bytes; - this.version = Bitcoin.Address.networkVersion; - }; + /** + * Parse a wallet import format private key contained in a string. + */ + ECKey.decodeWalletImportFormat = function (privStr) { + var bytes = Bitcoin.Base58.decode(privStr); + var hash = bytes.slice(0, 33); + var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); + if (checksum[0] != bytes[33] || + checksum[1] != bytes[34] || + checksum[2] != bytes[35] || + checksum[3] != bytes[36]) { + throw "Checksum validation failed!"; + } + var version = hash.shift(); + if (version != ECKey.privateKeyPrefix) { + throw "Version " + version + " not supported!"; + } + return hash; + }; - Bitcoin.Address.networkVersion = 0x00; // mainnet + /** + * Parse a compressed wallet import format private key contained in a string. + */ + ECKey.decodeCompressedWalletImportFormat = function (privStr) { + var bytes = Bitcoin.Base58.decode(privStr); + var hash = bytes.slice(0, 34); + var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); + if (checksum[0] != bytes[34] || + checksum[1] != bytes[35] || + checksum[2] != bytes[36] || + checksum[3] != bytes[37]) { + throw "Checksum validation failed!"; + } + var version = hash.shift(); + if (version != ECKey.privateKeyPrefix) { + throw "Version " + version + " not supported!"; + } + hash.pop(); + return hash; + }; - /** - * Serialize this object as a standard Bitcoin address. - * - * Returns the address as a base58-encoded string in the standardized format. - */ - Bitcoin.Address.prototype.toString = function () { - // Get a copy of the hash - var hash = this.hash.slice(0); + // 64 characters [0-9A-F] + ECKey.isHexFormat = function (key) { + key = key.toString(); + return /^[A-Fa-f0-9]{64}$/.test(key); + }; - // Version - hash.unshift(this.version); - var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); - var bytes = hash.concat(checksum.slice(0, 4)); - return Bitcoin.Base58.encode(bytes); - }; + // 51 characters base58, always starts with a '5' + ECKey.isWalletImportFormat = function (key) { + key = key.toString(); + return (ECKey.privateKeyPrefix == 0x80) ? + (/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)) : + (/^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)); + }; - Bitcoin.Address.prototype.getHashBase64 = function () { - return Crypto.util.bytesToBase64(this.hash); - }; + // 52 characters base58 + ECKey.isCompressedWalletImportFormat = function (key) { + key = key.toString(); + return (ECKey.privateKeyPrefix == 0x80) ? + (/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)) : + (/^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)); + }; - /** - * Parse a Bitcoin address contained in a string. - */ - Bitcoin.Address.decodeString = function (string) { - var bytes = Bitcoin.Base58.decode(string); - var hash = bytes.slice(0, 21); - var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); + // 44 characters + ECKey.isBase64Format = function (key) { + key = key.toString(); + return (/^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+\/]{44}$/.test(key)); + }; - if (checksum[0] != bytes[21] || - checksum[1] != bytes[22] || - checksum[2] != bytes[23] || - checksum[3] != bytes[24]) { - throw "Checksum validation failed!"; - } + // 99 characters, 1=1, if using dice convert 6 to 0 + ECKey.isBase6Format = function (key) { + key = key.toString(); + return (/^[012345]{99}$/.test(key)); + }; - var version = hash.shift(); + // 22, 26 or 30 characters, always starts with an 'S' + ECKey.isMiniFormat = function (key) { + key = key.toString(); + var validChars22 = /^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{21}$/.test(key); + var validChars26 = /^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{25}$/.test(key); + var validChars30 = /^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{29}$/.test(key); + var testBytes = Crypto.SHA256(key + "?", { asBytes: true }); - if (version != 0) { - throw "Version " + version + " not supported!"; - } + return ((testBytes[0] === 0x00 || testBytes[0] === 0x01) && (validChars22 || validChars26 || validChars30)); + }; - return hash; - }; -})(Bitcoin); -//https://raw.github.com/bitcoinjs/bitcoinjs-lib/c952aaeb3ee472e3776655b8ea07299ebed702c7/src/base58.js + return ECKey; + })(); +})(Bitcoin);//https://raw.github.com/bitcoinjs/bitcoinjs-lib/09e8c6e184d6501a0c2c59d73ca64db5c0d3eb95/src/util.js // See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE +// Bitcoin utility functions (function (Bitcoin) { - Bitcoin.Base58 = { - alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", - validRegex: /^[1-9A-HJ-NP-Za-km-z]+$/, - base: BigInteger.valueOf(58), - + Bitcoin.Util = { /** - * Convert a byte array to a base58-encoded string. + * Cross-browser compatibility version of Array.isArray. + */ + isArray: Array.isArray || function (o) { + return Object.prototype.toString.call(o) === '[object Array]'; + }, + /** + * Create an array of a certain length filled with a specific value. + */ + makeFilledArray: function (len, val) { + var array = []; + var i = 0; + while (i < len) { + array[i++] = val; + } + return array; + }, + /** + * Turn an integer into a "var_int". * - * Written by Mike Hearn for BitcoinJ. - * Copyright (c) 2011 Google Inc. + * "var_int" is a variable length integer used by Bitcoin's binary format. * - * Ported to JavaScript by Stefan Thomas. + * Returns a byte array. */ - encode: function (input) { - var bi = BigInteger.fromByteArrayUnsigned(input); - var chars = []; - - while (bi.compareTo(B58.base) >= 0) { - var mod = bi.mod(B58.base); - chars.unshift(B58.alphabet[mod.intValue()]); - bi = bi.subtract(mod).divide(B58.base); - } - chars.unshift(B58.alphabet[bi.intValue()]); - - // Convert leading zeros too. - for (var i = 0; i < input.length; i++) { - if (input[i] == 0x00) { - chars.unshift(B58.alphabet[0]); - } else break; + numToVarInt: function (i) { + if (i < 0xfd) { + // unsigned char + return [i]; + } else if (i <= 1 << 16) { + // unsigned short (LE) + return [0xfd, i >>> 8, i & 255]; + } else if (i <= 1 << 32) { + // unsigned int (LE) + return [0xfe].concat(Crypto.util.wordsToBytes([i])); + } else { + // unsigned long long (LE) + return [0xff].concat(Crypto.util.wordsToBytes([i >>> 32, i])); } - - return chars.join(''); }, + /** + * Parse a Bitcoin value byte array, returning a BigInteger. + */ + valueToBigInt: function (valueBuffer) { + if (valueBuffer instanceof BigInteger) return valueBuffer; + // Prepend zero byte to prevent interpretation as negative integer + return BigInteger.fromByteArrayUnsigned(valueBuffer); + }, /** - * Convert a base58-encoded string to a byte array. + * Format a Bitcoin value as a string. * - * Written by Mike Hearn for BitcoinJ. - * Copyright (c) 2011 Google Inc. + * Takes a BigInteger or byte-array and returns that amount of Bitcoins in a + * nice standard formatting. * - * Ported to JavaScript by Stefan Thomas. + * Examples: + * 12.3555 + * 0.1234 + * 900.99998888 + * 34.00 */ - decode: function (input) { - var bi = BigInteger.valueOf(0); - var leadingZerosNum = 0; - for (var i = input.length - 1; i >= 0; i--) { - var alphaIndex = B58.alphabet.indexOf(input[i]); - if (alphaIndex < 0) { - throw "Invalid character"; - } - bi = bi.add(BigInteger.valueOf(alphaIndex) - .multiply(B58.base.pow(input.length - 1 - i))); + formatValue: function (valueBuffer) { + var value = this.valueToBigInt(valueBuffer).toString(); + var integerPart = value.length > 8 ? value.substr(0, value.length - 8) : '0'; + var decimalPart = value.length > 8 ? value.substr(value.length - 8) : value; + while (decimalPart.length < 8) decimalPart = "0" + decimalPart; + decimalPart = decimalPart.replace(/0*$/, ''); + while (decimalPart.length < 2) decimalPart += "0"; + return integerPart + "." + decimalPart; + }, + /** + * Parse a floating point string as a Bitcoin value. + * + * Keep in mind that parsing user input is messy. You should always display + * the parsed value back to the user to make sure we understood his input + * correctly. + */ + parseValue: function (valueString) { + // TODO: Detect other number formats (e.g. comma as decimal separator) + var valueComp = valueString.split('.'); + var integralPart = valueComp[0]; + var fractionalPart = valueComp[1] || "0"; + while (fractionalPart.length < 8) fractionalPart += "0"; + fractionalPart = fractionalPart.replace(/^0+/g, ''); + var value = BigInteger.valueOf(parseInt(integralPart)); + value = value.multiply(BigInteger.valueOf(100000000)); + value = value.add(BigInteger.valueOf(parseInt(fractionalPart))); + return value; + }, + /** + * Calculate RIPEMD160(SHA256(data)). + * + * Takes an arbitrary byte array as inputs and returns the hash as a byte + * array. + */ + sha256ripe160: function (data) { + return Crypto.RIPEMD160(Crypto.SHA256(data, { asBytes: true }), { asBytes: true }); + }, + // double sha256 + dsha256: function (data) { + return Crypto.SHA256(Crypto.SHA256(data, { asBytes: true }), { asBytes: true }); + } + }; +})(Bitcoin); +},{}],11:[function(require,module,exports){ +// Generated by IcedCoffeeScript 1.7.1-f +(function() { + var Generator, iced, __iced_k, __iced_k_noop; - // This counts leading zero bytes - if (input[i] == "1") leadingZerosNum++; - else leadingZerosNum = 0; - } - var bytes = bi.toByteArrayUnsigned(); + iced = require('iced-runtime'); + __iced_k = __iced_k_noop = function() {}; - // Add leading zeros - while (leadingZerosNum-- > 0) bytes.unshift(0); + Generator = Generator = (function() { + function Generator(opts) { + opts = opts || {}; + this.lazy_loop_delay = opts.lazy_loop_delay || 30; + this.loop_delay = opts.loop_delay || 5; + this.work_min = opts.work_min || 1; + this.auto_stop_bits = opts.auto_stop_bits || 4096; + this.max_bits_per_delta = opts.max_bits_per_delta || 4; + this.auto_stop = opts.auto_stop ? opts.auto_stop : true; + this.entropies = []; + this.running = true; + this.is_generating = false; + this.timer_race_loop(); + } + + Generator.prototype.generate = function(bits_wanted, cb) { + var e, harvested_bits, res, ___iced_passed_deferral, __iced_deferrals, __iced_k; + __iced_k = __iced_k_noop; + ___iced_passed_deferral = iced.findDeferral(arguments); + this.is_generating = true; + if (!this.running) { + this.resume(); + } + harvested_bits = 0; + res = []; + (function(_this) { + return (function(__iced_k) { + var _results, _while; + _results = []; + _while = function(__iced_k) { + var _break, _continue, _next; + _break = function() { + return __iced_k(_results); + }; + _continue = function() { + return iced.trampoline(function() { + return _while(__iced_k); + }); + }; + _next = function(__iced_next_arg) { + _results.push(__iced_next_arg); + return _continue(); + }; + if (!(harvested_bits < bits_wanted)) { + return _break(); + } else { + (function(__iced_k) { + if (_this.entropies.length) { + e = _this.entropies.splice(0, 1)[0]; + harvested_bits += e[1]; + return __iced_k(res.push(e[0])); + } else { + (function(__iced_k) { + __iced_deferrals = new iced.Deferrals(__iced_k, { + parent: ___iced_passed_deferral, + filename: "/Users/chris/git/more-entropy/src/generator.iced", + funcname: "Generator.generate" + }); + _this.delay(__iced_deferrals.defer({ + lineno: 28 + })); + __iced_deferrals._fulfill(); + })(__iced_k); + } + })(_next); + } + }; + _while(__iced_k); + }); + })(this)((function(_this) { + return function() { + if (_this.auto_stop) { + _this.stop(); + } + _this.is_generating = false; + return cb(res); + }; + })(this)); + }; - return bytes; - } - }; + Generator.prototype.stop = function() { + return this.running = false; + }; - var B58 = Bitcoin.Base58; -})(Bitcoin); -//https://raw.github.com/pointbiz/bitcoinjs-lib/9b2f94a028a7bc9bed94e0722563e9ff1d8e8db8/src/eckey.js -// See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE -(function (Bitcoin) { - Bitcoin.ECKey = (function () { - var ecparams = EllipticCurve.getSECCurveByName("secp256k1"); + Generator.prototype.resume = function() { + this.running = true; + return this.timer_race_loop(); + }; - var ECKey = function (input) { - if (input instanceof BigInteger) { - // Input is a private key value - this.priv = input; - } else if (Bitcoin.Util.isArray(input)) { - // Prepend zero byte to prevent interpretation as negative integer - this.priv = BigInteger.fromByteArrayUnsigned(input); - } else if ("string" == typeof input) { - var bytes = null; - if (ECKey.isWalletImportFormat(input)) { - bytes = ECKey.decodeWalletImportFormat(input); - } else if (ECKey.isCompressedWalletImportFormat(input)) { - bytes = ECKey.decodeCompressedWalletImportFormat(input); - this.compressed = true; - } else if (ECKey.isMiniFormat(input)) { - bytes = Crypto.SHA256(input, { asBytes: true }); - } else if (ECKey.isHexFormat(input)) { - bytes = Crypto.util.hexToBytes(input); - } else if (ECKey.isBase64Format(input)) { - bytes = Crypto.util.base64ToBytes(input); - } - - if (ECKey.isBase6Format(input)) { - this.priv = new BigInteger(input, 6); - } else if (bytes == null || bytes.length != 32) { - this.priv = null; - } else { - // Prepend zero byte to prevent interpretation as negative integer - this.priv = BigInteger.fromByteArrayUnsigned(bytes); - } - } else { - throw new Error("no plausible constructor behavior"); - } + Generator.prototype.reset = function() { + this.entropies = []; + return this.total_bits = 0; + }; - this.compressed = (this.compressed == undefined) ? !!ECKey.compressByDefault : this.compressed; - }; + Generator.prototype.count_unused_bits = function() { + var bits, e, _i, _len, _ref; + bits = 0; + _ref = this.entropies; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + e = _ref[_i]; + bits += e[1]; + } + return bits; + }; - ECKey.privateKeyPrefix = 0x80; // mainnet 0x80 testnet 0xEF + Generator.prototype.delay = function(cb) { + var delay, ___iced_passed_deferral, __iced_deferrals, __iced_k; + __iced_k = __iced_k_noop; + ___iced_passed_deferral = iced.findDeferral(arguments); + delay = this.is_generating ? this.loop_delay : this.lazy_loop_delay; + (function(_this) { + return (function(__iced_k) { + __iced_deferrals = new iced.Deferrals(__iced_k, { + parent: ___iced_passed_deferral, + filename: "/Users/chris/git/more-entropy/src/generator.iced", + funcname: "Generator.delay" + }); + setTimeout(__iced_deferrals.defer({ + lineno: 50 + }), delay); + __iced_deferrals._fulfill(); + }); + })(this)((function(_this) { + return function() { + return cb(); + }; + })(this)); + }; - /** - * Whether public keys should be returned compressed by default. - */ - ECKey.compressByDefault = false; + Generator.prototype.timer_race_loop = function() { + var ___iced_passed_deferral, __iced_k, _results, _while; + __iced_k = __iced_k_noop; + ___iced_passed_deferral = iced.findDeferral(arguments); + this._last_count = null; + _results = []; + _while = (function(_this) { + var count, delta, entropy, v, __iced_deferrals; + return function(__iced_k) { + var _break, _continue, _next; + _break = function() { + return __iced_k(_results); + }; + _continue = function() { + return iced.trampoline(function() { + return _while(__iced_k); + }); + }; + _next = function(__iced_next_arg) { + _results.push(__iced_next_arg); + return _continue(); + }; + if (!_this.running) { + return _break(); + } else { + if (_this.count_unused_bits() < _this.auto_stop_bits) { + count = _this.millisecond_count(); + if ((_this._last_count != null) && (delta = count - _this._last_count)) { + entropy = Math.floor(_this.log_2(Math.abs(delta))); + entropy = Math.min(_this.max_bits_per_delta, entropy); + v = [delta, entropy]; + _this.entropies.push(v); + } + _this._last_count = count; + } + (function(__iced_k) { + __iced_deferrals = new iced.Deferrals(__iced_k, { + parent: ___iced_passed_deferral, + filename: "/Users/chris/git/more-entropy/src/generator.iced", + funcname: "Generator.timer_race_loop" + }); + _this.delay(__iced_deferrals.defer({ + lineno: 64 + })); + __iced_deferrals._fulfill(); + })(_next); + } + }; + })(this); + _while(__iced_k); + }; - /** - * Set whether the public key should be returned compressed or not. - */ - ECKey.prototype.setCompressed = function (v) { - this.compressed = !!v; - if (this.pubPoint) this.pubPoint.compressed = this.compressed; - return this; - }; + Generator.prototype.log_2 = function(x) { + return Math.log(x) / Math.LN2; + }; - /* - * Return public key as a byte array in DER encoding - */ - ECKey.prototype.getPub = function () { - if (this.compressed) { - if (this.pubComp) return this.pubComp; - return this.pubComp = this.getPubPoint().getEncoded(1); - } else { - if (this.pubUncomp) return this.pubUncomp; - return this.pubUncomp = this.getPubPoint().getEncoded(0); - } - }; + Generator.prototype.millisecond_count = function() { + var d, i, x; + d = Date.now(); + i = x = 0; + while (Date.now() < d + this.work_min + 1) { + i++; + x = Math.sin(Math.sqrt(Math.log(i + x))); + } + return i; + }; - /** - * Return public point as ECPoint object. - */ - ECKey.prototype.getPubPoint = function () { - if (!this.pubPoint) { - this.pubPoint = ecparams.getG().multiply(this.priv); - this.pubPoint.compressed = this.compressed; - } - return this.pubPoint; - }; + return Generator; - ECKey.prototype.getPubKeyHex = function () { - if (this.compressed) { - if (this.pubKeyHexComp) return this.pubKeyHexComp; - return this.pubKeyHexComp = Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase(); - } else { - if (this.pubKeyHexUncomp) return this.pubKeyHexUncomp; - return this.pubKeyHexUncomp = Crypto.util.bytesToHex(this.getPub()).toString().toUpperCase(); - } - }; + })(); - /** - * Get the pubKeyHash for this key. - * - * This is calculated as RIPE160(SHA256([encoded pubkey])) and returned as - * a byte array. - */ - ECKey.prototype.getPubKeyHash = function () { - if (this.compressed) { - if (this.pubKeyHashComp) return this.pubKeyHashComp; - return this.pubKeyHashComp = Bitcoin.Util.sha256ripe160(this.getPub()); - } else { - if (this.pubKeyHashUncomp) return this.pubKeyHashUncomp; - return this.pubKeyHashUncomp = Bitcoin.Util.sha256ripe160(this.getPub()); - } - }; + if (typeof window !== "undefined" && window !== null) { + window.Generator = Generator; + } - ECKey.prototype.getBitcoinAddress = function () { - var hash = this.getPubKeyHash(); - var addr = new Bitcoin.Address(hash); - return addr.toString(); - }; + if (typeof exports !== "undefined" && exports !== null) { + exports.Generator = Generator; + } - /* - * Takes a public point as a hex string or byte array - */ - ECKey.prototype.setPub = function (pub) { - // byte array - if (Bitcoin.Util.isArray(pub)) { - pub = Crypto.util.bytesToHex(pub).toString().toUpperCase(); - } - var ecPoint = ecparams.getCurve().decodePointHex(pub); - this.setCompressed(ecPoint.compressed); - this.pubPoint = ecPoint; - return this; - }; +}).call(this); - // Sipa Private Key Wallet Import Format - ECKey.prototype.getBitcoinWalletImportFormat = function () { - var bytes = this.getBitcoinPrivateKeyByteArray(); - bytes.unshift(ECKey.privateKeyPrefix); // prepend 0x80 byte - if (this.compressed) bytes.push(0x01); // append 0x01 byte for compressed format - var checksum = Crypto.SHA256(Crypto.SHA256(bytes, { asBytes: true }), { asBytes: true }); - bytes = bytes.concat(checksum.slice(0, 4)); - var privWif = Bitcoin.Base58.encode(bytes); - return privWif; - }; +},{"iced-runtime":6}],12:[function(require,module,exports){ +// Generated by IcedCoffeeScript 1.7.1-c +(function() { + exports.Generator = require('../lib/generator').Generator; - // Private Key Hex Format - ECKey.prototype.getBitcoinHexFormat = function () { - return Crypto.util.bytesToHex(this.getBitcoinPrivateKeyByteArray()).toString().toUpperCase(); - }; +}).call(this); - // Private Key Base64 Format - ECKey.prototype.getBitcoinBase64Format = function () { - return Crypto.util.bytesToBase64(this.getBitcoinPrivateKeyByteArray()); - }; +},{"../lib/generator":11}],13:[function(require,module,exports){ +// shim for using process in browser +var process = module.exports = {}; - ECKey.prototype.getBitcoinPrivateKeyByteArray = function () { - // Get a copy of private key as a byte array - var bytes = this.priv.toByteArrayUnsigned(); - // zero pad if private key is less than 32 bytes - while (bytes.length < 32) bytes.unshift(0x00); - return bytes; - }; +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. - ECKey.prototype.toString = function (format) { - format = format || ""; - if (format.toString().toLowerCase() == "base64" || format.toString().toLowerCase() == "b64") { - return this.getBitcoinBase64Format(); - } - // Wallet Import Format - else if (format.toString().toLowerCase() == "wif") { - return this.getBitcoinWalletImportFormat(); - } - else { - return this.getBitcoinHexFormat(); - } - }; +var cachedSetTimeout; +var cachedClearTimeout; - /** - * Parse a wallet import format private key contained in a string. - */ - ECKey.decodeWalletImportFormat = function (privStr) { - var bytes = Bitcoin.Base58.decode(privStr); - var hash = bytes.slice(0, 33); - var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); - if (checksum[0] != bytes[33] || - checksum[1] != bytes[34] || - checksum[2] != bytes[35] || - checksum[3] != bytes[36]) { - throw "Checksum validation failed!"; - } - var version = hash.shift(); - if (version != ECKey.privateKeyPrefix) { - throw "Version " + version + " not supported!"; - } - return hash; - }; +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // 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 + return cachedSetTimeout.call(this, fun, 0); + } + } - /** - * Parse a compressed wallet import format private key contained in a string. - */ - ECKey.decodeCompressedWalletImportFormat = function (privStr) { - var bytes = Bitcoin.Base58.decode(privStr); - var hash = bytes.slice(0, 34); - var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true }); - if (checksum[0] != bytes[34] || - checksum[1] != bytes[35] || - checksum[2] != bytes[36] || - checksum[3] != bytes[37]) { - throw "Checksum validation failed!"; - } - var version = hash.shift(); - if (version != ECKey.privateKeyPrefix) { - throw "Version " + version + " not supported!"; - } - hash.pop(); - return hash; - }; - // 64 characters [0-9A-F] - ECKey.isHexFormat = function (key) { - key = key.toString(); - return /^[A-Fa-f0-9]{64}$/.test(key); - }; +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // 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. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } - // 51 characters base58, always starts with a '5' - ECKey.isWalletImportFormat = function (key) { - key = key.toString(); - return (ECKey.privateKeyPrefix == 0x80) ? - (/^5[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)) : - (/^9[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{50}$/.test(key)); - }; - // 52 characters base58 - ECKey.isCompressedWalletImportFormat = function (key) { - key = key.toString(); - return (ECKey.privateKeyPrefix == 0x80) ? - (/^[LK][123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)) : - (/^c[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{51}$/.test(key)); - }; - // 44 characters - ECKey.isBase64Format = function (key) { - key = key.toString(); - return (/^[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789=+\/]{44}$/.test(key)); - }; +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; - // 99 characters, 1=1, if using dice convert 6 to 0 - ECKey.isBase6Format = function (key) { - key = key.toString(); - return (/^[012345]{99}$/.test(key)); - }; +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} - // 22, 26 or 30 characters, always starts with an 'S' - ECKey.isMiniFormat = function (key) { - key = key.toString(); - var validChars22 = /^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{21}$/.test(key); - var validChars26 = /^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{25}$/.test(key); - var validChars30 = /^S[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{29}$/.test(key); - var testBytes = Crypto.SHA256(key + "?", { asBytes: true }); +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; - return ((testBytes[0] === 0x00 || testBytes[0] === 0x01) && (validChars22 || validChars26 || validChars30)); - }; + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} - return ECKey; - })(); -})(Bitcoin);//https://raw.github.com/bitcoinjs/bitcoinjs-lib/09e8c6e184d6501a0c2c59d73ca64db5c0d3eb95/src/util.js -// See here for license information: https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/LICENSE -// Bitcoin utility functions -(function (Bitcoin) { - Bitcoin.Util = { - /** - * Cross-browser compatibility version of Array.isArray. - */ - isArray: Array.isArray || function (o) { - return Object.prototype.toString.call(o) === '[object Array]'; - }, - /** - * Create an array of a certain length filled with a specific value. - */ - makeFilledArray: function (len, val) { - var array = []; - var i = 0; - while (i < len) { - array[i++] = val; - } - return array; - }, - /** - * Turn an integer into a "var_int". - * - * "var_int" is a variable length integer used by Bitcoin's binary format. - * - * Returns a byte array. - */ - numToVarInt: function (i) { - if (i < 0xfd) { - // unsigned char - return [i]; - } else if (i <= 1 << 16) { - // unsigned short (LE) - return [0xfd, i >>> 8, i & 255]; - } else if (i <= 1 << 32) { - // unsigned int (LE) - return [0xfe].concat(Crypto.util.wordsToBytes([i])); - } else { - // unsigned long long (LE) - return [0xff].concat(Crypto.util.wordsToBytes([i >>> 32, i])); - } - }, - /** - * Parse a Bitcoin value byte array, returning a BigInteger. - */ - valueToBigInt: function (valueBuffer) { - if (valueBuffer instanceof BigInteger) return valueBuffer; +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; - // Prepend zero byte to prevent interpretation as negative integer - return BigInteger.fromByteArrayUnsigned(valueBuffer); - }, - /** - * Format a Bitcoin value as a string. - * - * Takes a BigInteger or byte-array and returns that amount of Bitcoins in a - * nice standard formatting. - * - * Examples: - * 12.3555 - * 0.1234 - * 900.99998888 - * 34.00 - */ - formatValue: function (valueBuffer) { - var value = this.valueToBigInt(valueBuffer).toString(); - var integerPart = value.length > 8 ? value.substr(0, value.length - 8) : '0'; - var decimalPart = value.length > 8 ? value.substr(value.length - 8) : value; - while (decimalPart.length < 8) decimalPart = "0" + decimalPart; - decimalPart = decimalPart.replace(/0*$/, ''); - while (decimalPart.length < 2) decimalPart += "0"; - return integerPart + "." + decimalPart; - }, - /** - * Parse a floating point string as a Bitcoin value. - * - * Keep in mind that parsing user input is messy. You should always display - * the parsed value back to the user to make sure we understood his input - * correctly. - */ - parseValue: function (valueString) { - // TODO: Detect other number formats (e.g. comma as decimal separator) - var valueComp = valueString.split('.'); - var integralPart = valueComp[0]; - var fractionalPart = valueComp[1] || "0"; - while (fractionalPart.length < 8) fractionalPart += "0"; - fractionalPart = fractionalPart.replace(/^0+/g, ''); - var value = BigInteger.valueOf(parseInt(integralPart)); - value = value.multiply(BigInteger.valueOf(100000000)); - value = value.add(BigInteger.valueOf(parseInt(fractionalPart))); - return value; - }, - /** - * Calculate RIPEMD160(SHA256(data)). - * - * Takes an arbitrary byte array as inputs and returns the hash as a byte - * array. - */ - sha256ripe160: function (data) { - return Crypto.RIPEMD160(Crypto.SHA256(data, { asBytes: true }), { asBytes: true }); - }, - // double sha256 - dsha256: function (data) { - return Crypto.SHA256(Crypto.SHA256(data, { asBytes: true }), { asBytes: true }); - } - }; -})(Bitcoin); -},{}],17:[function(require,module,exports){ +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + +},{}],14:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var AES, BlockCipher, G, Global, scrub_vec, @@ -6358,7 +6284,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./algbase":18,"./util":37}],18:[function(require,module,exports){ +},{"./algbase":15,"./util":34}],15:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var BlockCipher, BufferedBlockAlgorithm, Hasher, StreamCipher, WordArray, util, @@ -6543,7 +6469,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./util":37,"./wordarray":38}],19:[function(require,module,exports){ +},{"./util":34,"./wordarray":35}],16:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var CombineBase, Concat, HMAC, SHA3, SHA512, WordArray, XOR, bulk_sign, _ref, @@ -6757,7 +6683,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./hmac":24,"./sha3":34,"./sha512":35,"./wordarray":38}],20:[function(require,module,exports){ +},{"./hmac":21,"./sha3":31,"./sha512":32,"./wordarray":35}],17:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var Cipher, Counter, StreamCipher, WordArray, bulk_encrypt, encrypt, iced, __iced_k, __iced_k_noop, @@ -6916,7 +6842,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./algbase":18,"./wordarray":38,"iced-coffee-script/lib/coffee-script/iced":9}],21:[function(require,module,exports){ +},{"./algbase":15,"./wordarray":35,"iced-coffee-script/lib/coffee-script/iced":41}],18:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var AES, Base, Concat, Decryptor, SHA512, Salsa20, TwoFish, V, WordArray, ctr, decrypt, iced, make_esc, salsa20, __iced_k, __iced_k_noop, _ref, @@ -7275,7 +7201,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./aes":17,"./combine":19,"./ctr":20,"./enc":23,"./salsa20":29,"./sha512":35,"./twofish":36,"./wordarray":38,"iced-coffee-script/lib/coffee-script/iced":9,"iced-error":10}],22:[function(require,module,exports){ +},{"./aes":14,"./combine":16,"./ctr":17,"./enc":20,"./salsa20":26,"./sha512":32,"./twofish":33,"./wordarray":35,"iced-coffee-script/lib/coffee-script/iced":41,"iced-error":3}],19:[function(require,module,exports){ (function (Buffer){ // Generated by IcedCoffeeScript 1.6.3-g (function() { @@ -7486,7 +7412,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); }).call(this,require("buffer").Buffer) -},{"./combine":19,"./hmac":24,"./lock":25,"./sha3":34,"./sha512":35,"./wordarray":38,"buffer":1,"iced-coffee-script/lib/coffee-script/iced":9}],23:[function(require,module,exports){ +},{"./combine":16,"./hmac":21,"./lock":22,"./sha3":31,"./sha512":32,"./wordarray":35,"buffer":2,"iced-coffee-script/lib/coffee-script/iced":41}],20:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var AES, Base, Concat, Encryptor, HMAC_SHA256, PBKDF2, SHA512, Scrypt, TwoFish, V, WordArray, XOR, ctr, encrypt, iced, make_esc, prng, salsa20, util, __iced_k, __iced_k_noop, _ref, @@ -8248,7 +8174,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./aes":17,"./combine":19,"./ctr":20,"./hmac":24,"./pbkdf2":27,"./prng":28,"./salsa20":29,"./scrypt":30,"./sha512":35,"./twofish":36,"./util":37,"./wordarray":38,"iced-coffee-script/lib/coffee-script/iced":9,"iced-error":10}],24:[function(require,module,exports){ +},{"./aes":14,"./combine":16,"./ctr":17,"./hmac":21,"./pbkdf2":24,"./prng":25,"./salsa20":26,"./scrypt":27,"./sha512":32,"./twofish":33,"./util":34,"./wordarray":35,"iced-coffee-script/lib/coffee-script/iced":41,"iced-error":3}],21:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var HMAC, HMAC_SHA256, SHA256, SHA512, bulk_sign, iced, sign, util, __iced_k, __iced_k_noop, @@ -8398,7 +8324,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./sha256":33,"./sha512":35,"./util":37,"iced-coffee-script/lib/coffee-script/iced":9}],25:[function(require,module,exports){ +},{"./sha256":30,"./sha512":32,"./util":34,"iced-coffee-script/lib/coffee-script/iced":41}],22:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var Lock, NamedLock, Table, iced, __iced_k, __iced_k_noop, @@ -8524,7 +8450,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"iced-coffee-script/lib/coffee-script/iced":9}],26:[function(require,module,exports){ +},{"iced-coffee-script/lib/coffee-script/iced":41}],23:[function(require,module,exports){ (function (Buffer){ // Generated by IcedCoffeeScript 1.6.3-g (function() { @@ -8574,7 +8500,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); }).call(this,require("buffer").Buffer) -},{"./aes":17,"./dec":21,"./enc":23,"./hmac":24,"./pbkdf2":27,"./prng":28,"./scrypt":30,"./sha1":31,"./sha224":32,"./sha256":33,"./sha3":34,"./sha512":35,"./twofish":36,"./util":37,"./wordarray":38,"buffer":1}],27:[function(require,module,exports){ +},{"./aes":14,"./dec":18,"./enc":20,"./hmac":21,"./pbkdf2":24,"./prng":25,"./scrypt":27,"./sha1":28,"./sha224":29,"./sha256":30,"./sha3":31,"./sha512":32,"./twofish":33,"./util":34,"./wordarray":35,"buffer":2}],24:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var HMAC, PBKDF2, WordArray, iced, pbkdf2, util, __iced_k, __iced_k_noop; @@ -8785,7 +8711,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); -},{"./hmac":24,"./util":37,"./wordarray":38,"iced-coffee-script/lib/coffee-script/iced":9}],28:[function(require,module,exports){ +},{"./hmac":21,"./util":34,"./wordarray":35,"iced-coffee-script/lib/coffee-script/iced":41}],25:[function(require,module,exports){ (function (Buffer){ // Generated by IcedCoffeeScript 1.6.3-g (function() { @@ -8917,7 +8843,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); }).call(this,require("buffer").Buffer) -},{"./combine":19,"./drbg":22,"./util":37,"./wordarray":38,"buffer":1,"iced-coffee-script/lib/coffee-script/iced":9,"more-entropy":40}],29:[function(require,module,exports){ +},{"./combine":16,"./drbg":19,"./util":34,"./wordarray":35,"buffer":2,"iced-coffee-script/lib/coffee-script/iced":41,"more-entropy":12}],26:[function(require,module,exports){ (function (Buffer){ // Generated by IcedCoffeeScript 1.6.3-g (function() { @@ -9310,7 +9236,7 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }).call(this); }).call(this,require("buffer").Buffer) -},{"./algbase":18,"./ctr":20,"./util":37,"./wordarray":38,"buffer":1,"iced-coffee-script/lib/coffee-script/iced":9}],30:[function(require,module,exports){ +},{"./algbase":15,"./ctr":17,"./util":34,"./wordarray":35,"buffer":2,"iced-coffee-script/lib/coffee-script/iced":41}],27:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { var HMAC_SHA256, Salsa20InnerCore, Scrypt, WordArray, blkcpy, blkxor, default_delay, endian_reverse, fixup_uint32, iced, pbkdf2, scrub_vec, scrypt, ui8a_to_buffer, v_endian_reverse, __iced_k, __iced_k_noop, _ref, _ref1, _ref2; @@ -9749,18 +9675,190 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit }); }; - exports.Scrypt = Scrypt; + exports.Scrypt = Scrypt; + + exports.scrypt = scrypt; + + exports.v_endian_reverse = v_endian_reverse; + +}).call(this); + +},{"./hmac":21,"./pbkdf2":24,"./salsa20":26,"./util":34,"./wordarray":35,"iced-coffee-script/lib/coffee-script/iced":41}],28:[function(require,module,exports){ +// Generated by IcedCoffeeScript 1.6.3-g +(function() { + var Hasher, SHA1, W, WordArray, transform, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + + + WordArray = require('./wordarray').WordArray; + + Hasher = require('./algbase').Hasher; + + W = []; + + SHA1 = (function(_super) { + __extends(SHA1, _super); + + function SHA1() { + _ref = SHA1.__super__.constructor.apply(this, arguments); + return _ref; + } + + SHA1.blockSize = 512 / 32; + + SHA1.prototype.blockSize = SHA1.blockSize; + + SHA1.output_size = 20; + + SHA1.prototype.output_size = SHA1.output_size; + + SHA1.prototype._doReset = function() { + return this._hash = new WordArray([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]); + }; + + SHA1.prototype._doProcessBlock = function(M, offset) { + var H, a, b, c, d, e, i, n, t, _i; + H = this._hash.words; + a = H[0]; + b = H[1]; + c = H[2]; + d = H[3]; + e = H[4]; + for (i = _i = 0; _i < 80; i = ++_i) { + if (i < 16) { + W[i] = M[offset + i] | 0; + } else { + n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + W[i] = (n << 1) | (n >>> 31); + } + t = ((a << 5) | (a >>> 27)) + e + W[i]; + if (i < 20) { + t += ((b & c) | (~b & d)) + 0x5a827999; + } else if (i < 40) { + t += (b ^ c ^ d) + 0x6ed9eba1; + } else if (i < 60) { + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; + } else { + t += (b ^ c ^ d) - 0x359d3e2a; + } + e = d; + d = c; + c = (b << 30) | (b >>> 2); + b = a; + a = t; + } + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + return H[4] = (H[4] + e) | 0; + }; + + SHA1.prototype._doFinalize = function() { + var data, dataWords, nBitsLeft, nBitsTotal; + data = this._data; + dataWords = data.words; + nBitsTotal = this._nDataBytes * 8; + nBitsLeft = data.sigBytes * 8; + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + this._process(); + return this._hash; + }; + + SHA1.prototype.copy_to = function(obj) { + SHA1.__super__.copy_to.call(this, obj); + return obj._hash = this._hash.clone(); + }; + + SHA1.prototype.clone = function() { + var out; + out = new SHA1(); + this.copy_to(out); + return out; + }; + + return SHA1; + + })(Hasher); + + transform = transform = function(x) { + var out; + out = (new SHA1).finalize(x); + x.scrub(); + return out; + }; + + exports.SHA1 = SHA1; + + exports.transform = transform; + +}).call(this); + +},{"./algbase":15,"./wordarray":35}],29:[function(require,module,exports){ +// Generated by IcedCoffeeScript 1.6.3-g +(function() { + var SHA224, SHA256, WordArray, transform, _ref, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + + + WordArray = require('./wordarray').WordArray; + + SHA256 = require('./sha256').SHA256; + + SHA224 = (function(_super) { + __extends(SHA224, _super); + + function SHA224() { + _ref = SHA224.__super__.constructor.apply(this, arguments); + return _ref; + } + + SHA224.prototype._doReset = function() { + return this._hash = new WordArray([0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4]); + }; + + SHA224.prototype._doFinalize = function() { + var hash; + hash = SHA224.__super__._doFinalize.call(this); + hash.sigBytes -= 4; + return hash; + }; + + SHA224.prototype.clone = function() { + var out; + out = new SHA224(); + this.copy_to(out); + return out; + }; - exports.scrypt = scrypt; + return SHA224; - exports.v_endian_reverse = v_endian_reverse; + })(SHA256); + + transform = function(x) { + var out; + out = (new SHA224).finalize(x); + x.scrub(); + return out; + }; + + exports.SHA224 = SHA224; + + exports.transform = transform; }).call(this); -},{"./hmac":24,"./pbkdf2":27,"./salsa20":29,"./util":37,"./wordarray":38,"iced-coffee-script/lib/coffee-script/iced":9}],31:[function(require,module,exports){ +},{"./sha256":30,"./wordarray":35}],30:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { - var Hasher, SHA1, W, WordArray, transform, _ref, + var Global, Hasher, SHA256, WordArray, glbl, transform, _ref, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -9770,67 +9868,132 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit Hasher = require('./algbase').Hasher; - W = []; + Global = (function() { + function Global() { + this.H = []; + this.K = []; + this.W = []; + this.init(); + } - SHA1 = (function(_super) { - __extends(SHA1, _super); + Global.prototype.isPrime = function(n) { + var f, sqn, _i; + if (n === 2 || n === 3 || n === 5 || n === 7) { + return true; + } + if (n === 1 || n === 4 || n === 6 || n === 8 || n === 9) { + return false; + } + sqn = Math.ceil(Math.sqrt(n)); + for (f = _i = 2; 2 <= sqn ? _i <= sqn : _i >= sqn; f = 2 <= sqn ? ++_i : --_i) { + if ((n % f) === 0) { + return false; + } + } + return true; + }; - function SHA1() { - _ref = SHA1.__super__.constructor.apply(this, arguments); + Global.prototype.getFractionalBits = function(n) { + return ((n - (n | 0)) * 0x100000000) | 0; + }; + + Global.prototype.init = function() { + var n, nPrime, _results; + n = 2; + nPrime = 0; + _results = []; + while (nPrime < 64) { + if (this.isPrime(n)) { + if (nPrime < 8) { + this.H[nPrime] = this.getFractionalBits(Math.pow(n, 1 / 2)); + } + this.K[nPrime] = this.getFractionalBits(Math.pow(n, 1 / 3)); + nPrime++; + } + _results.push(n++); + } + return _results; + }; + + return Global; + + })(); + + glbl = new Global(); + + SHA256 = (function(_super) { + __extends(SHA256, _super); + + function SHA256() { + _ref = SHA256.__super__.constructor.apply(this, arguments); return _ref; } - SHA1.blockSize = 512 / 32; + SHA256.blockSize = 512 / 32; - SHA1.prototype.blockSize = SHA1.blockSize; + SHA256.prototype.blockSize = SHA256.blockSize; - SHA1.output_size = 20; + SHA256.output_size = 256 / 8; - SHA1.prototype.output_size = SHA1.output_size; + SHA256.prototype.output_size = SHA256.output_size; - SHA1.prototype._doReset = function() { - return this._hash = new WordArray([0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]); + SHA256.prototype._doReset = function() { + return this._hash = new WordArray(glbl.H.slice(0)); }; - SHA1.prototype._doProcessBlock = function(M, offset) { - var H, a, b, c, d, e, i, n, t, _i; + SHA256.prototype.get_output_size = function() { + return this.output_size; + }; + + SHA256.prototype._doProcessBlock = function(M, offset) { + var H, K, W, a, b, c, ch, d, e, f, g, gamma0, gamma0x, gamma1, gamma1x, h, i, maj, sigma0, sigma1, t1, t2, _i; H = this._hash.words; + W = glbl.W; + K = glbl.K; a = H[0]; b = H[1]; c = H[2]; d = H[3]; e = H[4]; - for (i = _i = 0; _i < 80; i = ++_i) { + f = H[5]; + g = H[6]; + h = H[7]; + for (i = _i = 0; _i < 64; i = ++_i) { if (i < 16) { W[i] = M[offset + i] | 0; } else { - n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; - W[i] = (n << 1) | (n >>> 31); - } - t = ((a << 5) | (a >>> 27)) + e + W[i]; - if (i < 20) { - t += ((b & c) | (~b & d)) + 0x5a827999; - } else if (i < 40) { - t += (b ^ c ^ d) + 0x6ed9eba1; - } else if (i < 60) { - t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; - } else { - t += (b ^ c ^ d) - 0x359d3e2a; + gamma0x = W[i - 15]; + gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ ((gamma0x << 14) | (gamma0x >>> 18)) ^ (gamma0x >>> 3); + gamma1x = W[i - 2]; + gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ ((gamma1x << 13) | (gamma1x >>> 19)) ^ (gamma1x >>> 10); + W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; } - e = d; + ch = (e & f) ^ (~e & g); + maj = (a & b) ^ (a & c) ^ (b & c); + sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); + sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); + t1 = h + sigma1 + ch + K[i] + W[i]; + t2 = sigma0 + maj; + h = g; + g = f; + f = e; + e = (d + t1) | 0; d = c; - c = (b << 30) | (b >>> 2); + c = b; b = a; - a = t; + a = (t1 + t2) | 0; } H[0] = (H[0] + a) | 0; H[1] = (H[1] + b) | 0; H[2] = (H[2] + c) | 0; H[3] = (H[3] + d) | 0; - return H[4] = (H[4] + e) | 0; + H[4] = (H[4] + e) | 0; + H[5] = (H[5] + f) | 0; + H[6] = (H[6] + g) | 0; + return H[7] = (H[7] + h) | 0; }; - SHA1.prototype._doFinalize = function() { + SHA256.prototype._doFinalize = function() { var data, dataWords, nBitsLeft, nBitsTotal; data = this._data; dataWords = data.words; @@ -9844,1809 +10007,1969 @@ var EllipticCurve = exports.EllipticCurve;//https://raw.github.com/bitcoinjs/bit return this._hash; }; - SHA1.prototype.copy_to = function(obj) { - SHA1.__super__.copy_to.call(this, obj); + SHA256.prototype.scrub = function() { + return this._hash.scrub(); + }; + + SHA256.prototype.copy_to = function(obj) { + SHA256.__super__.copy_to.call(this, obj); return obj._hash = this._hash.clone(); }; - SHA1.prototype.clone = function() { - var out; - out = new SHA1(); - this.copy_to(out); - return out; + SHA256.prototype.clone = function() { + var out; + out = new SHA256(); + this.copy_to(out); + return out; + }; + + return SHA256; + + })(Hasher); + + transform = function(x) { + var out; + out = (new SHA256).finalize(x); + x.scrub(); + return out; + }; + + exports.SHA256 = SHA256; + + exports.transform = transform; + +}).call(this); + +},{"./algbase":15,"./wordarray":35}],31:[function(require,module,exports){ +// Generated by IcedCoffeeScript 1.6.3-g +(function() { + var Global, Hasher, SHA3, WordArray, X64Word, X64WordArray, glbl, _ref, _ref1, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + + + + _ref = require('./wordarray'), WordArray = _ref.WordArray, X64Word = _ref.X64Word, X64WordArray = _ref.X64WordArray; + + Hasher = require('./algbase').Hasher; + + Global = (function() { + function Global() { + this.RHO_OFFSETS = []; + this.PI_INDEXES = []; + this.ROUND_CONSTANTS = []; + this.T = []; + this.compute_rho_offsets(); + this.compute_pi_indexes(); + this.compute_round_constants(); + this.make_reusables(); + } + + Global.prototype.compute_rho_offsets = function() { + var newX, newY, t, x, y, _i, _results; + x = 1; + y = 0; + _results = []; + for (t = _i = 0; _i < 24; t = ++_i) { + this.RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; + newX = y % 5; + newY = (2 * x + 3 * y) % 5; + x = newX; + _results.push(y = newY); + } + return _results; + }; + + Global.prototype.compute_pi_indexes = function() { + var x, y, _i, _results; + _results = []; + for (x = _i = 0; _i < 5; x = ++_i) { + _results.push((function() { + var _j, _results1; + _results1 = []; + for (y = _j = 0; _j < 5; y = ++_j) { + _results1.push(this.PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5); + } + return _results1; + }).call(this)); + } + return _results; + }; + + Global.prototype.compute_round_constants = function() { + var LFSR, bitPosition, i, j, roundConstantLsw, roundConstantMsw, _i, _j, _results; + LFSR = 0x01; + _results = []; + for (i = _i = 0; _i < 24; i = ++_i) { + roundConstantMsw = 0; + roundConstantLsw = 0; + for (j = _j = 0; _j < 7; j = ++_j) { + if (LFSR & 0x01) { + bitPosition = (1 << j) - 1; + if (bitPosition < 32) { + roundConstantLsw ^= 1 << bitPosition; + } else { + roundConstantMsw ^= 1 << (bitPosition - 32); + } + } + if (LFSR & 0x80) { + LFSR = (LFSR << 1) ^ 0x71; + } else { + LFSR <<= 1; + } + } + _results.push(this.ROUND_CONSTANTS[i] = new X64Word(roundConstantMsw, roundConstantLsw)); + } + return _results; + }; + + Global.prototype.make_reusables = function() { + var i; + return this.T = (function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 25; i = ++_i) { + _results.push(new X64Word(0, 0)); + } + return _results; + })(); }; - return SHA1; + return Global; - })(Hasher); + })(); - transform = transform = function(x) { - var out; - out = (new SHA1).finalize(x); - x.scrub(); - return out; - }; + glbl = new Global(); - exports.SHA1 = SHA1; + exports.SHA3 = SHA3 = (function(_super) { + __extends(SHA3, _super); - exports.transform = transform; + function SHA3() { + _ref1 = SHA3.__super__.constructor.apply(this, arguments); + return _ref1; + } -}).call(this); + SHA3.outputLength = 512; -},{"./algbase":18,"./wordarray":38}],32:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.6.3-g -(function() { - var SHA224, SHA256, WordArray, transform, _ref, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + SHA3.prototype.outputLength = SHA3.outputLength; + SHA3.blockSize = (1600 - 2 * SHA3.outputLength) / 32; + SHA3.prototype.blockSize = SHA3.blockSize; - WordArray = require('./wordarray').WordArray; + SHA3.output_size = SHA3.outputLength / 8; - SHA256 = require('./sha256').SHA256; + SHA3.prototype.output_size = SHA3.output_size; - SHA224 = (function(_super) { - __extends(SHA224, _super); + SHA3.prototype._doReset = function() { + var i; + return this._state = (function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 25; i = ++_i) { + _results.push(new X64Word(0, 0)); + } + return _results; + })(); + }; - function SHA224() { - _ref = SHA224.__super__.constructor.apply(this, arguments); - return _ref; - } + SHA3.prototype._doProcessBlock = function(M, offset) { + var G, M2i, M2i1, T0, TLane, TPiLane, Tx, Tx1, Tx1Lane, Tx1Lsw, Tx1Msw, Tx2Lane, Tx4, i, lane, laneIndex, laneLsw, laneMsw, nBlockSizeLanes, rhoOffset, round, roundConstant, state, state0, tLsw, tMsw, x, y, _i, _j, _k, _l, _m, _n, _o, _p, _q, _results; + G = glbl; + state = this._state; + nBlockSizeLanes = this.blockSize / 2; + for (i = _i = 0; 0 <= nBlockSizeLanes ? _i < nBlockSizeLanes : _i > nBlockSizeLanes; i = 0 <= nBlockSizeLanes ? ++_i : --_i) { + M2i = M[offset + 2 * i]; + M2i1 = M[offset + 2 * i + 1]; + M2i = (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00); + M2i1 = (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00); + lane = state[i]; + lane.high ^= M2i1; + lane.low ^= M2i; + } + _results = []; + for (round = _j = 0; _j < 24; round = ++_j) { + for (x = _k = 0; _k < 5; x = ++_k) { + tMsw = tLsw = 0; + for (y = _l = 0; _l < 5; y = ++_l) { + lane = state[x + 5 * y]; + tMsw ^= lane.high; + tLsw ^= lane.low; + } + Tx = G.T[x]; + Tx.high = tMsw; + Tx.low = tLsw; + } + for (x = _m = 0; _m < 5; x = ++_m) { + Tx4 = G.T[(x + 4) % 5]; + Tx1 = G.T[(x + 1) % 5]; + Tx1Msw = Tx1.high; + Tx1Lsw = Tx1.low; + tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); + tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); + for (y = _n = 0; _n < 5; y = ++_n) { + lane = state[x + 5 * y]; + lane.high ^= tMsw; + lane.low ^= tLsw; + } + } + for (laneIndex = _o = 1; _o < 25; laneIndex = ++_o) { + lane = state[laneIndex]; + laneMsw = lane.high; + laneLsw = lane.low; + rhoOffset = G.RHO_OFFSETS[laneIndex]; + if (rhoOffset < 32) { + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); + } else { + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); + } + TPiLane = G.T[G.PI_INDEXES[laneIndex]]; + TPiLane.high = tMsw; + TPiLane.low = tLsw; + } + T0 = G.T[0]; + state0 = state[0]; + T0.high = state0.high; + T0.low = state0.low; + for (x = _p = 0; _p < 5; x = ++_p) { + for (y = _q = 0; _q < 5; y = ++_q) { + laneIndex = x + 5 * y; + lane = state[laneIndex]; + TLane = G.T[laneIndex]; + Tx1Lane = G.T[((x + 1) % 5) + 5 * y]; + Tx2Lane = G.T[((x + 2) % 5) + 5 * y]; + lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); + lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); + } + } + lane = state[0]; + roundConstant = G.ROUND_CONSTANTS[round]; + lane.high ^= roundConstant.high; + _results.push(lane.low ^= roundConstant.low); + } + return _results; + }; - SHA224.prototype._doReset = function() { - return this._hash = new WordArray([0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4]); + SHA3.prototype._doFinalize = function() { + var blockSizeBits, data, dataWords, hashWords, i, lane, laneLsw, laneMsw, nBitsLeft, nBitsTotal, outputLengthBytes, outputLengthLanes, state, _i; + data = this._data; + dataWords = data.words; + nBitsTotal = this._nDataBytes * 8; + nBitsLeft = data.sigBytes * 8; + blockSizeBits = this.blockSize * 32; + dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); + dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; + data.sigBytes = dataWords.length * 4; + this._process(); + state = this._state; + outputLengthBytes = this.outputLength / 8; + outputLengthLanes = outputLengthBytes / 8; + hashWords = []; + for (i = _i = 0; 0 <= outputLengthLanes ? _i < outputLengthLanes : _i > outputLengthLanes; i = 0 <= outputLengthLanes ? ++_i : --_i) { + lane = state[i]; + laneMsw = lane.high; + laneLsw = lane.low; + laneMsw = (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00); + laneLsw = (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00); + hashWords.push(laneLsw); + hashWords.push(laneMsw); + } + return new WordArray(hashWords, outputLengthBytes); }; - SHA224.prototype._doFinalize = function() { - var hash; - hash = SHA224.__super__._doFinalize.call(this); - hash.sigBytes -= 4; - return hash; + SHA3.prototype.copy_to = function(obj) { + var s; + SHA3.__super__.copy_to.call(this, obj); + return obj._state = (function() { + var _i, _len, _ref2, _results; + _ref2 = this._state; + _results = []; + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + s = _ref2[_i]; + _results.push(s.clone()); + } + return _results; + }).call(this); }; - SHA224.prototype.clone = function() { + SHA3.prototype.scrub = function() {}; + + SHA3.prototype.clone = function() { var out; - out = new SHA224(); + out = new SHA3(); this.copy_to(out); return out; }; - return SHA224; + return SHA3; - })(SHA256); + })(Hasher); - transform = function(x) { + exports.transform = function(x) { var out; - out = (new SHA224).finalize(x); + out = (new SHA3).finalize(x); x.scrub(); return out; }; - exports.SHA224 = SHA224; - - exports.transform = transform; - }).call(this); -},{"./sha256":33,"./wordarray":38}],33:[function(require,module,exports){ +},{"./algbase":15,"./wordarray":35}],32:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { - var Global, Hasher, SHA256, WordArray, glbl, transform, _ref, + var Global, Hasher, SHA512, X64Word, X64WordArray, glbl, _ref, _ref1, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - WordArray = require('./wordarray').WordArray; + _ref = require('./wordarray'), X64Word = _ref.X64Word, X64WordArray = _ref.X64WordArray; Hasher = require('./algbase').Hasher; - - Global = (function() { - function Global() { - this.H = []; - this.K = []; - this.W = []; - this.init(); - } - - Global.prototype.isPrime = function(n) { - var f, sqn, _i; - if (n === 2 || n === 3 || n === 5 || n === 7) { - return true; - } - if (n === 1 || n === 4 || n === 6 || n === 8 || n === 9) { - return false; - } - sqn = Math.ceil(Math.sqrt(n)); - for (f = _i = 2; 2 <= sqn ? _i <= sqn : _i >= sqn; f = 2 <= sqn ? ++_i : --_i) { - if ((n % f) === 0) { - return false; - } - } - return true; - }; - - Global.prototype.getFractionalBits = function(n) { - return ((n - (n | 0)) * 0x100000000) | 0; - }; - - Global.prototype.init = function() { - var n, nPrime, _results; - n = 2; - nPrime = 0; + + Global = (function() { + Global.prototype.convert = function(raw) { + var i, _i, _ref1, _results; _results = []; - while (nPrime < 64) { - if (this.isPrime(n)) { - if (nPrime < 8) { - this.H[nPrime] = this.getFractionalBits(Math.pow(n, 1 / 2)); - } - this.K[nPrime] = this.getFractionalBits(Math.pow(n, 1 / 3)); - nPrime++; - } - _results.push(n++); + for (i = _i = 0, _ref1 = raw.length; _i < _ref1; i = _i += 2) { + _results.push(new X64Word(raw[i], raw[i + 1])); } return _results; }; + function Global() { + var i; + this.K = this.convert([0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817]); + this.I = new X64WordArray(this.convert([0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179])); + this.W = (function() { + var _i, _results; + _results = []; + for (i = _i = 0; _i < 80; i = ++_i) { + _results.push(new X64Word(0, 0)); + } + return _results; + })(); + } + return Global; })(); glbl = new Global(); - SHA256 = (function(_super) { - __extends(SHA256, _super); + exports.SHA512 = SHA512 = (function(_super) { + __extends(SHA512, _super); - function SHA256() { - _ref = SHA256.__super__.constructor.apply(this, arguments); - return _ref; + function SHA512() { + _ref1 = SHA512.__super__.constructor.apply(this, arguments); + return _ref1; } - SHA256.blockSize = 512 / 32; - - SHA256.prototype.blockSize = SHA256.blockSize; + SHA512.blockSize = 1024 / 32; - SHA256.output_size = 256 / 8; + SHA512.prototype.blockSize = SHA512.blockSize; - SHA256.prototype.output_size = SHA256.output_size; + SHA512.output_size = 512 / 8; - SHA256.prototype._doReset = function() { - return this._hash = new WordArray(glbl.H.slice(0)); - }; + SHA512.prototype.output_size = SHA512.output_size; - SHA256.prototype.get_output_size = function() { - return this.output_size; + SHA512.prototype._doReset = function() { + return this._hash = glbl.I.clone(); }; - SHA256.prototype._doProcessBlock = function(M, offset) { - var H, K, W, a, b, c, ch, d, e, f, g, gamma0, gamma0x, gamma1, gamma1x, h, i, maj, sigma0, sigma1, t1, t2, _i; + SHA512.prototype._doProcessBlock = function(M, offset) { + var H, H0, H0h, H0l, H1, H1h, H1l, H2, H2h, H2l, H3, H3h, H3l, H4, H4h, H4l, H5, H5h, H5l, H6, H6h, H6l, H7, H7h, H7l, Ki, Kih, Kil, W, Wi, Wi16, Wi16h, Wi16l, Wi7, Wi7h, Wi7l, Wih, Wil, ah, al, bh, bl, ch, chh, chl, cl, dh, dl, eh, el, fh, fl, gamma0h, gamma0l, gamma0x, gamma0xh, gamma0xl, gamma1h, gamma1l, gamma1x, gamma1xh, gamma1xl, gh, gl, hh, hl, i, majh, majl, sigma0h, sigma0l, sigma1h, sigma1l, t1h, t1l, t2h, t2l, _i; H = this._hash.words; W = glbl.W; - K = glbl.K; - a = H[0]; - b = H[1]; - c = H[2]; - d = H[3]; - e = H[4]; - f = H[5]; - g = H[6]; - h = H[7]; - for (i = _i = 0; _i < 64; i = ++_i) { + H0 = H[0]; + H1 = H[1]; + H2 = H[2]; + H3 = H[3]; + H4 = H[4]; + H5 = H[5]; + H6 = H[6]; + H7 = H[7]; + H0h = H0.high; + H0l = H0.low; + H1h = H1.high; + H1l = H1.low; + H2h = H2.high; + H2l = H2.low; + H3h = H3.high; + H3l = H3.low; + H4h = H4.high; + H4l = H4.low; + H5h = H5.high; + H5l = H5.low; + H6h = H6.high; + H6l = H6.low; + H7h = H7.high; + H7l = H7.low; + ah = H0h; + al = H0l; + bh = H1h; + bl = H1l; + ch = H2h; + cl = H2l; + dh = H3h; + dl = H3l; + eh = H4h; + el = H4l; + fh = H5h; + fl = H5l; + gh = H6h; + gl = H6l; + hh = H7h; + hl = H7l; + for (i = _i = 0; _i < 80; i = ++_i) { + Wi = W[i]; if (i < 16) { - W[i] = M[offset + i] | 0; + Wih = Wi.high = M[offset + i * 2] | 0; + Wil = Wi.low = M[offset + i * 2 + 1] | 0; } else { gamma0x = W[i - 15]; - gamma0 = ((gamma0x << 25) | (gamma0x >>> 7)) ^ ((gamma0x << 14) | (gamma0x >>> 18)) ^ (gamma0x >>> 3); + gamma0xh = gamma0x.high; + gamma0xl = gamma0x.low; + gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); + gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); gamma1x = W[i - 2]; - gamma1 = ((gamma1x << 15) | (gamma1x >>> 17)) ^ ((gamma1x << 13) | (gamma1x >>> 19)) ^ (gamma1x >>> 10); - W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]; + gamma1xh = gamma1x.high; + gamma1xl = gamma1x.low; + gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); + gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); + Wi7 = W[i - 7]; + Wi7h = Wi7.high; + Wi7l = Wi7.low; + Wi16 = W[i - 16]; + Wi16h = Wi16.high; + Wi16l = Wi16.low; + Wil = gamma0l + Wi7l; + Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); + Wil = Wil + gamma1l; + Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); + Wil = Wil + Wi16l; + Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); + Wi.high = Wih; + Wi.low = Wil; } - ch = (e & f) ^ (~e & g); - maj = (a & b) ^ (a & c) ^ (b & c); - sigma0 = ((a << 30) | (a >>> 2)) ^ ((a << 19) | (a >>> 13)) ^ ((a << 10) | (a >>> 22)); - sigma1 = ((e << 26) | (e >>> 6)) ^ ((e << 21) | (e >>> 11)) ^ ((e << 7) | (e >>> 25)); - t1 = h + sigma1 + ch + K[i] + W[i]; - t2 = sigma0 + maj; - h = g; - g = f; - f = e; - e = (d + t1) | 0; - d = c; - c = b; - b = a; - a = (t1 + t2) | 0; + chh = (eh & fh) ^ (~eh & gh); + chl = (el & fl) ^ (~el & gl); + majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); + majl = (al & bl) ^ (al & cl) ^ (bl & cl); + sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); + sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); + sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); + sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); + Ki = glbl.K[i]; + Kih = Ki.high; + Kil = Ki.low; + t1l = hl + sigma1l; + t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); + t1l = t1l + chl; + t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); + t1l = t1l + Kil; + t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); + t1l = t1l + Wil; + t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); + t2l = sigma0l + majl; + t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = (dl + t1l) | 0; + eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = (t1l + t2l) | 0; + ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; } - H[0] = (H[0] + a) | 0; - H[1] = (H[1] + b) | 0; - H[2] = (H[2] + c) | 0; - H[3] = (H[3] + d) | 0; - H[4] = (H[4] + e) | 0; - H[5] = (H[5] + f) | 0; - H[6] = (H[6] + g) | 0; - return H[7] = (H[7] + h) | 0; + H0l = H0.low = H0l + al; + H0.high = H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0); + H1l = H1.low = H1l + bl; + H1.high = H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0); + H2l = H2.low = H2l + cl; + H2.high = H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0); + H3l = H3.low = H3l + dl; + H3.high = H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0); + H4l = H4.low = H4l + el; + H4.high = H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0); + H5l = H5.low = H5l + fl; + H5.high = H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0); + H6l = H6.low = H6l + gl; + H6.high = H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0); + H7l = H7.low = H7l + hl; + return H7.high = H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0); }; - SHA256.prototype._doFinalize = function() { - var data, dataWords, nBitsLeft, nBitsTotal; - data = this._data; - dataWords = data.words; + SHA512.prototype._doFinalize = function() { + var dataWords, nBitsLeft, nBitsTotal; + dataWords = this._data.words; nBitsTotal = this._nDataBytes * 8; - nBitsLeft = data.sigBytes * 8; + nBitsLeft = this._data.sigBytes * 8; dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); - dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); - dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; - data.sigBytes = dataWords.length * 4; + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; + this._data.sigBytes = dataWords.length * 4; this._process(); - return this._hash; - }; - - SHA256.prototype.scrub = function() { - return this._hash.scrub(); + return this._hash.toX32(); }; - SHA256.prototype.copy_to = function(obj) { - SHA256.__super__.copy_to.call(this, obj); + SHA512.prototype.copy_to = function(obj) { + SHA512.__super__.copy_to.call(this, obj); return obj._hash = this._hash.clone(); }; - SHA256.prototype.clone = function() { + SHA512.prototype.clone = function() { var out; - out = new SHA256(); + out = new SHA512(); this.copy_to(out); return out; }; - return SHA256; + return SHA512; })(Hasher); - transform = function(x) { + exports.transform = function(x) { var out; - out = (new SHA256).finalize(x); - x.scrub(); - return out; - }; - - exports.SHA256 = SHA256; - - exports.transform = transform; + out = (new SHA512).finalize(x); + x.scrub(); + return out; + }; }).call(this); -},{"./algbase":18,"./wordarray":38}],34:[function(require,module,exports){ +},{"./algbase":15,"./wordarray":35}],33:[function(require,module,exports){ // Generated by IcedCoffeeScript 1.6.3-g (function() { - var Global, Hasher, SHA3, WordArray, X64Word, X64WordArray, glbl, _ref, _ref1, + var BlockCipher, G, Global, TwoFish, scrub_vec, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - _ref = require('./wordarray'), WordArray = _ref.WordArray, X64Word = _ref.X64Word, X64WordArray = _ref.X64WordArray; + BlockCipher = require('./algbase').BlockCipher; - Hasher = require('./algbase').Hasher; + scrub_vec = require('./util').scrub_vec; Global = (function() { function Global() { - this.RHO_OFFSETS = []; - this.PI_INDEXES = []; - this.ROUND_CONSTANTS = []; - this.T = []; - this.compute_rho_offsets(); - this.compute_pi_indexes(); - this.compute_round_constants(); - this.make_reusables(); + this.P = [[0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, 0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23, 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82, 0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61, 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B, 0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66, 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7, 0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 0xEA, 0x77, 0x39, 0xAF, 0x33, 0xC9, 0x62, 0x71, 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8, 0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 0xA1, 0x1D, 0xAA, 0xED, 0x06, 0x70, 0xB2, 0xD2, 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90, 0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 0x9E, 0x9C, 0x52, 0x1B, 0x5F, 0x93, 0x0A, 0xEF, 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B, 0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 0x2A, 0xCE, 0xCB, 0x2F, 0xFC, 0x97, 0x05, 0x7A, 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A, 0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 0xB8, 0xDA, 0xB0, 0x17, 0x55, 0x1F, 0x8A, 0x7D, 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72, 0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 0x6E, 0x50, 0xDE, 0x68, 0x65, 0xBC, 0xDB, 0xF8, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4, 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0], [0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, 0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B, 0x8A, 0x00, 0xBC, 0x9D, 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5, 0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 0xB2, 0x73, 0x4C, 0x54, 0x92, 0x74, 0x36, 0x51, 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96, 0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 0x13, 0x95, 0x9C, 0xC7, 0x24, 0x46, 0x3B, 0x70, 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8, 0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 0x03, 0x6F, 0x08, 0xBF, 0x40, 0xE7, 0x2B, 0xE2, 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9, 0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 0x66, 0x94, 0xA1, 0x1D, 0x3D, 0xF0, 0xDE, 0xB3, 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E, 0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 0x81, 0x88, 0xEE, 0x21, 0xC4, 0x1A, 0xEB, 0xD9, 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01, 0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 0x4F, 0xF2, 0x65, 0x8E, 0x78, 0x5C, 0x58, 0x19, 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64, 0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 0xCE, 0xE9, 0x68, 0x44, 0xE0, 0x4D, 0x43, 0x69, 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E, 0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 0x22, 0xC9, 0xC0, 0x9B, 0x89, 0xD4, 0xED, 0xAB, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9, 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91]]; + this.P_00 = 1; + this.P_01 = 0; + this.P_02 = 0; + this.P_03 = 1; + this.P_04 = 1; + this.P_10 = 0; + this.P_11 = 0; + this.P_12 = 1; + this.P_13 = 1; + this.P_14 = 0; + this.P_20 = 1; + this.P_21 = 1; + this.P_22 = 0; + this.P_23 = 0; + this.P_24 = 0; + this.P_30 = 0; + this.P_31 = 1; + this.P_32 = 1; + this.P_33 = 0; + this.P_34 = 1; + this.GF256_FDBK = 0x169; + this.GF256_FDBK_2 = this.GF256_FDBK / 2; + this.GF256_FDBK_4 = this.GF256_FDBK / 4; + this.RS_GF_FDBK = 0x14D; + this.SK_STEP = 0x02020202; + this.SK_BUMP = 0x01010101; + this.SK_ROTL = 9; } - Global.prototype.compute_rho_offsets = function() { - var newX, newY, t, x, y, _i, _results; - x = 1; - y = 0; - _results = []; - for (t = _i = 0; _i < 24; t = ++_i) { - this.RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; - newX = y % 5; - newY = (2 * x + 3 * y) % 5; - x = newX; - _results.push(y = newY); - } - return _results; - }; - - Global.prototype.compute_pi_indexes = function() { - var x, y, _i, _results; - _results = []; - for (x = _i = 0; _i < 5; x = ++_i) { - _results.push((function() { - var _j, _results1; - _results1 = []; - for (y = _j = 0; _j < 5; y = ++_j) { - _results1.push(this.PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5); - } - return _results1; - }).call(this)); - } - return _results; - }; - - Global.prototype.compute_round_constants = function() { - var LFSR, bitPosition, i, j, roundConstantLsw, roundConstantMsw, _i, _j, _results; - LFSR = 0x01; - _results = []; - for (i = _i = 0; _i < 24; i = ++_i) { - roundConstantMsw = 0; - roundConstantLsw = 0; - for (j = _j = 0; _j < 7; j = ++_j) { - if (LFSR & 0x01) { - bitPosition = (1 << j) - 1; - if (bitPosition < 32) { - roundConstantLsw ^= 1 << bitPosition; - } else { - roundConstantMsw ^= 1 << (bitPosition - 32); - } - } - if (LFSR & 0x80) { - LFSR = (LFSR << 1) ^ 0x71; - } else { - LFSR <<= 1; - } - } - _results.push(this.ROUND_CONSTANTS[i] = new X64Word(roundConstantMsw, roundConstantLsw)); - } - return _results; - }; - - Global.prototype.make_reusables = function() { - var i; - return this.T = (function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i < 25; i = ++_i) { - _results.push(new X64Word(0, 0)); - } - return _results; - })(); - }; - return Global; })(); - glbl = new Global(); - - exports.SHA3 = SHA3 = (function(_super) { - __extends(SHA3, _super); - - function SHA3() { - _ref1 = SHA3.__super__.constructor.apply(this, arguments); - return _ref1; - } - - SHA3.outputLength = 512; - - SHA3.prototype.outputLength = SHA3.outputLength; - - SHA3.blockSize = (1600 - 2 * SHA3.outputLength) / 32; + G = new Global(); - SHA3.prototype.blockSize = SHA3.blockSize; + exports.TwoFish = TwoFish = (function(_super) { + __extends(TwoFish, _super); - SHA3.output_size = SHA3.outputLength / 8; + TwoFish.blockSize = 4 * 4; - SHA3.prototype.output_size = SHA3.output_size; + TwoFish.prototype.blockSize = TwoFish.blockSize; - SHA3.prototype._doReset = function() { - var i; - return this._state = (function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i < 25; i = ++_i) { - _results.push(new X64Word(0, 0)); - } - return _results; - })(); - }; + TwoFish.keySize = 256 / 8; - SHA3.prototype._doProcessBlock = function(M, offset) { - var G, M2i, M2i1, T0, TLane, TPiLane, Tx, Tx1, Tx1Lane, Tx1Lsw, Tx1Msw, Tx2Lane, Tx4, i, lane, laneIndex, laneLsw, laneMsw, nBlockSizeLanes, rhoOffset, round, roundConstant, state, state0, tLsw, tMsw, x, y, _i, _j, _k, _l, _m, _n, _o, _p, _q, _results; - G = glbl; - state = this._state; - nBlockSizeLanes = this.blockSize / 2; - for (i = _i = 0; 0 <= nBlockSizeLanes ? _i < nBlockSizeLanes : _i > nBlockSizeLanes; i = 0 <= nBlockSizeLanes ? ++_i : --_i) { - M2i = M[offset + 2 * i]; - M2i1 = M[offset + 2 * i + 1]; - M2i = (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00); - M2i1 = (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00); - lane = state[i]; - lane.high ^= M2i1; - lane.low ^= M2i; - } - _results = []; - for (round = _j = 0; _j < 24; round = ++_j) { - for (x = _k = 0; _k < 5; x = ++_k) { - tMsw = tLsw = 0; - for (y = _l = 0; _l < 5; y = ++_l) { - lane = state[x + 5 * y]; - tMsw ^= lane.high; - tLsw ^= lane.low; - } - Tx = G.T[x]; - Tx.high = tMsw; - Tx.low = tLsw; - } - for (x = _m = 0; _m < 5; x = ++_m) { - Tx4 = G.T[(x + 4) % 5]; - Tx1 = G.T[(x + 1) % 5]; - Tx1Msw = Tx1.high; - Tx1Lsw = Tx1.low; - tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); - tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); - for (y = _n = 0; _n < 5; y = ++_n) { - lane = state[x + 5 * y]; - lane.high ^= tMsw; - lane.low ^= tLsw; - } - } - for (laneIndex = _o = 1; _o < 25; laneIndex = ++_o) { - lane = state[laneIndex]; - laneMsw = lane.high; - laneLsw = lane.low; - rhoOffset = G.RHO_OFFSETS[laneIndex]; - if (rhoOffset < 32) { - tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); - tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); - } else { - tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); - tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); - } - TPiLane = G.T[G.PI_INDEXES[laneIndex]]; - TPiLane.high = tMsw; - TPiLane.low = tLsw; - } - T0 = G.T[0]; - state0 = state[0]; - T0.high = state0.high; - T0.low = state0.low; - for (x = _p = 0; _p < 5; x = ++_p) { - for (y = _q = 0; _q < 5; y = ++_q) { - laneIndex = x + 5 * y; - lane = state[laneIndex]; - TLane = G.T[laneIndex]; - Tx1Lane = G.T[((x + 1) % 5) + 5 * y]; - Tx2Lane = G.T[((x + 2) % 5) + 5 * y]; - lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); - lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); - } - } - lane = state[0]; - roundConstant = G.ROUND_CONSTANTS[round]; - lane.high ^= roundConstant.high; - _results.push(lane.low ^= roundConstant.low); - } - return _results; - }; + TwoFish.prototype.keySize = TwoFish.keySize; - SHA3.prototype._doFinalize = function() { - var blockSizeBits, data, dataWords, hashWords, i, lane, laneLsw, laneMsw, nBitsLeft, nBitsTotal, outputLengthBytes, outputLengthLanes, state, _i; - data = this._data; - dataWords = data.words; - nBitsTotal = this._nDataBytes * 8; - nBitsLeft = data.sigBytes * 8; - blockSizeBits = this.blockSize * 32; - dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); - dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; - data.sigBytes = dataWords.length * 4; - this._process(); - state = this._state; - outputLengthBytes = this.outputLength / 8; - outputLengthLanes = outputLengthBytes / 8; - hashWords = []; - for (i = _i = 0; 0 <= outputLengthLanes ? _i < outputLengthLanes : _i > outputLengthLanes; i = 0 <= outputLengthLanes ? ++_i : --_i) { - lane = state[i]; - laneMsw = lane.high; - laneLsw = lane.low; - laneMsw = (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00); - laneLsw = (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00); - hashWords.push(laneLsw); - hashWords.push(laneMsw); - } - return new WordArray(hashWords, outputLengthBytes); - }; + TwoFish.ivSize = TwoFish.blockSize; - SHA3.prototype.copy_to = function(obj) { - var s; - SHA3.__super__.copy_to.call(this, obj); - return obj._state = (function() { - var _i, _len, _ref2, _results; - _ref2 = this._state; - _results = []; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - s = _ref2[_i]; - _results.push(s.clone()); - } - return _results; - }).call(this); - }; + TwoFish.prototype.ivSize = TwoFish.ivSize; - SHA3.prototype.scrub = function() {}; + function TwoFish(key) { + this._key = key.clone(); + this.gMDS0 = []; + this.gMDS1 = []; + this.gMDS2 = []; + this.gMDS3 = []; + this.gSubKeys = []; + this.gSBox = []; + this.k64Cnt = 0; + this._doReset(); + } - SHA3.prototype.clone = function() { - var out; - out = new SHA3(); - this.copy_to(out); - return out; + TwoFish.prototype.getByte = function(x, n) { + return (x >>> (n * 8)) & 0xFF; }; - return SHA3; + TwoFish.prototype.switchEndianness = function(word) { + return ((word & 0xff) << 24) | (((word >> 8) & 0xff) << 16) | (((word >> 16) & 0xff) << 8) | ((word >> 24) & 0xff); + }; - })(Hasher); + TwoFish.prototype.LFSR1 = function(x) { + return (x >> 1) ^ ((x & 0x01) !== 0 ? G.GF256_FDBK_2 : 0); + }; - exports.transform = function(x) { - var out; - out = (new SHA3).finalize(x); - x.scrub(); - return out; - }; + TwoFish.prototype.LFSR2 = function(x) { + return (x >> 2) ^ ((x & 0x02) !== 0 ? G.GF256_FDBK_2 : 0) ^ ((x & 0x01) !== 0 ? G.GF256_FDBK_4 : 0); + }; -}).call(this); + TwoFish.prototype.Mx_X = function(x) { + return x ^ this.LFSR2(x); + }; -},{"./algbase":18,"./wordarray":38}],35:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.6.3-g -(function() { - var Global, Hasher, SHA512, X64Word, X64WordArray, glbl, _ref, _ref1, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + TwoFish.prototype.Mx_Y = function(x) { + return x ^ this.LFSR1(x) ^ this.LFSR2(x); + }; + + TwoFish.prototype.RS_rem = function(x) { + var b, g2, g3; + b = (x >>> 24) & 0xff; + g2 = ((b << 1) ^ ((b & 0x80) !== 0 ? G.RS_GF_FDBK : 0)) & 0xff; + g3 = ((b >>> 1) ^ ((b & 0x01) !== 0 ? G.RS_GF_FDBK >>> 1 : 0)) ^ g2; + return (x << 8) ^ (g3 << 24) ^ (g2 << 16) ^ (g3 << 8) ^ b; + }; + TwoFish.prototype.RS_MDS_Encode = function(k0, k1) { + var i, r, _i, _j; + r = k1; + for (i = _i = 0; _i < 4; i = ++_i) { + r = this.RS_rem(r); + } + r ^= k0; + for (i = _j = 0; _j < 4; i = ++_j) { + r = this.RS_rem(r); + } + return r; + }; + TwoFish.prototype.F32 = function(x, k32) { + var b0, b1, b2, b3, k0, k1, k2, k3, m, res; + b0 = this.getByte(x, 0); + b1 = this.getByte(x, 1); + b2 = this.getByte(x, 2); + b3 = this.getByte(x, 3); + k0 = k32[0]; + k1 = k32[1]; + k2 = k32[2]; + k3 = k32[3]; + m = this.k64Cnt & 3; + res = m === 1 ? this.gMDS0[(G.P[G.P_01][b0] & 0xff) ^ this.getByte(k0, 0)] ^ this.gMDS1[(G.P[G.P_11][b1] & 0xff) ^ this.getByte(k0, 1)] ^ this.gMDS2[(G.P[G.P_21][b2] & 0xff) ^ this.getByte(k0, 2)] ^ this.gMDS3[(G.P[G.P_31][b3] & 0xff) ^ this.getByte(k0, 3)] : (m === 0 ? (b0 = (G.P[G.P_04][b0] & 0xff) ^ this.getByte(k3, 0), b1 = (G.P[G.P_14][b1] & 0xff) ^ this.getByte(k3, 1), b2 = (G.P[G.P_24][b2] & 0xff) ^ this.getByte(k3, 2), b3 = (G.P[G.P_34][b3] & 0xff) ^ this.getByte(k3, 3)) : void 0, m === 0 || m === 3 ? (b0 = (G.P[G.P_03][b0] & 0xff) ^ this.getByte(k2, 0), b1 = (G.P[G.P_13][b1] & 0xff) ^ this.getByte(k2, 1), b2 = (G.P[G.P_23][b2] & 0xff) ^ this.getByte(k2, 2), b3 = (G.P[G.P_33][b3] & 0xff) ^ this.getByte(k2, 3)) : void 0, this.gMDS0[(G.P[G.P_01][(G.P[G.P_02][b0] & 0xff) ^ this.getByte(k1, 0)] & 0xff) ^ this.getByte(k0, 0)] ^ this.gMDS1[(G.P[G.P_11][(G.P[G.P_12][b1] & 0xff) ^ this.getByte(k1, 1)] & 0xff) ^ this.getByte(k0, 1)] ^ this.gMDS2[(G.P[G.P_21][(G.P[G.P_22][b2] & 0xff) ^ this.getByte(k1, 2)] & 0xff) ^ this.getByte(k0, 2)] ^ this.gMDS3[(G.P[G.P_31][(G.P[G.P_32][b3] & 0xff) ^ this.getByte(k1, 3)] & 0xff) ^ this.getByte(k0, 3)]); + return res; + }; - _ref = require('./wordarray'), X64Word = _ref.X64Word, X64WordArray = _ref.X64WordArray; + TwoFish.prototype.Fe32_0 = function(x) { + return this.gSBox[0x000 + 2 * (x & 0xff)] ^ this.gSBox[0x001 + 2 * ((x >>> 8) & 0xff)] ^ this.gSBox[0x200 + 2 * ((x >>> 16) & 0xff)] ^ this.gSBox[0x201 + 2 * ((x >>> 24) & 0xff)]; + }; - Hasher = require('./algbase').Hasher; + TwoFish.prototype.Fe32_3 = function(x) { + return this.gSBox[0x000 + 2 * ((x >>> 24) & 0xff)] ^ this.gSBox[0x001 + 2 * (x & 0xff)] ^ this.gSBox[0x200 + 2 * ((x >>> 8) & 0xff)] ^ this.gSBox[0x201 + 2 * ((x >>> 16) & 0xff)]; + }; - Global = (function() { - Global.prototype.convert = function(raw) { - var i, _i, _ref1, _results; + TwoFish.prototype._doReset = function() { + var A, B, b0, b1, b2, b3, i, j, k0, k1, k2, k3, k32e, k32o, m, m1, mX, mY, p, q, sBoxKeys, _i, _j, _k, _l, _ref, _ref1, _results; + k32e = []; + k32o = []; + sBoxKeys = []; + m1 = []; + mX = []; + mY = []; + this.k64Cnt = this._key.words.length / 2; + if (this.k64Cnt < 1) { + throw "Key size less than 64 bits"; + } + if (this.k64Cnt > 4) { + throw "Key size larger than 256 bits"; + } + for (i = _i = 0; _i < 256; i = ++_i) { + j = G.P[0][i] & 0xff; + m1[0] = j; + mX[0] = this.Mx_X(j) & 0xff; + mY[0] = this.Mx_Y(j) & 0xff; + j = G.P[1][i] & 0xff; + m1[1] = j; + mX[1] = this.Mx_X(j) & 0xff; + mY[1] = this.Mx_Y(j) & 0xff; + this.gMDS0[i] = m1[G.P_00] | mX[G.P_00] << 8 | mY[G.P_00] << 16 | mY[G.P_00] << 24; + this.gMDS1[i] = mY[G.P_10] | mY[G.P_10] << 8 | mX[G.P_10] << 16 | m1[G.P_10] << 24; + this.gMDS2[i] = mX[G.P_20] | mY[G.P_20] << 8 | m1[G.P_20] << 16 | mY[G.P_20] << 24; + this.gMDS3[i] = mX[G.P_30] | m1[G.P_30] << 8 | mY[G.P_30] << 16 | mX[G.P_30] << 24; + } + for (i = _j = 0, _ref = this.k64Cnt; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) { + p = i * 2; + k32e[i] = this.switchEndianness(this._key.words[p]); + k32o[i] = this.switchEndianness(this._key.words[p + 1]); + sBoxKeys[this.k64Cnt - 1 - i] = this.RS_MDS_Encode(k32e[i], k32o[i]); + } + for (i = _k = 0, _ref1 = 40 / 2; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) { + q = i * G.SK_STEP; + A = this.F32(q, k32e); + B = this.F32(q + G.SK_BUMP, k32o); + B = B << 8 | B >>> 24; + A += B; + this.gSubKeys[i * 2] = A; + A += B; + this.gSubKeys[i * 2 + 1] = A << G.SK_ROTL | A >>> (32 - G.SK_ROTL); + } + k0 = sBoxKeys[0]; + k1 = sBoxKeys[1]; + k2 = sBoxKeys[2]; + k3 = sBoxKeys[3]; + this.gSBox = []; _results = []; - for (i = _i = 0, _ref1 = raw.length; _i < _ref1; i = _i += 2) { - _results.push(new X64Word(raw[i], raw[i + 1])); + for (i = _l = 0; _l < 256; i = ++_l) { + b0 = b1 = b2 = b3 = i; + m = this.k64Cnt & 3; + if (m === 1) { + this.gSBox[i * 2] = this.gMDS0[(G.P[G.P_01][b0] & 0xff) ^ this.getByte(k0, 0)]; + this.gSBox[i * 2 + 1] = this.gMDS1[(G.P[G.P_11][b1] & 0xff) ^ this.getByte(k0, 1)]; + this.gSBox[i * 2 + 0x200] = this.gMDS2[(G.P[G.P_21][b2] & 0xff) ^ this.getByte(k0, 2)]; + _results.push(this.gSBox[i * 2 + 0x201] = this.gMDS3[(G.P[G.P_31][b3] & 0xff) ^ this.getByte(k0, 3)]); + } else { + if (m === 0) { + b0 = (G.P[G.P_04][b0] & 0xff) ^ this.getByte(k3, 0); + b1 = (G.P[G.P_14][b1] & 0xff) ^ this.getByte(k3, 1); + b2 = (G.P[G.P_24][b2] & 0xff) ^ this.getByte(k3, 2); + b3 = (G.P[G.P_34][b3] & 0xff) ^ this.getByte(k3, 3); + } + if (m === 0 || m === 3) { + b0 = (G.P[G.P_03][b0] & 0xff) ^ this.getByte(k2, 0); + b1 = (G.P[G.P_13][b1] & 0xff) ^ this.getByte(k2, 1); + b2 = (G.P[G.P_23][b2] & 0xff) ^ this.getByte(k2, 2); + b3 = (G.P[G.P_33][b3] & 0xff) ^ this.getByte(k2, 3); + } + this.gSBox[i * 2] = this.gMDS0[(G.P[G.P_01][(G.P[G.P_02][b0] & 0xff) ^ this.getByte(k1, 0)] & 0xff) ^ this.getByte(k0, 0)]; + this.gSBox[i * 2 + 1] = this.gMDS1[(G.P[G.P_11][(G.P[G.P_12][b1] & 0xff) ^ this.getByte(k1, 1)] & 0xff) ^ this.getByte(k0, 1)]; + this.gSBox[i * 2 + 0x200] = this.gMDS2[(G.P[G.P_21][(G.P[G.P_22][b2] & 0xff) ^ this.getByte(k1, 2)] & 0xff) ^ this.getByte(k0, 2)]; + _results.push(this.gSBox[i * 2 + 0x201] = this.gMDS3[(G.P[G.P_31][(G.P[G.P_32][b3] & 0xff) ^ this.getByte(k1, 3)] & 0xff) ^ this.getByte(k0, 3)]); + } } return _results; }; - function Global() { - var i; - this.K = this.convert([0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019, 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2, 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3, 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5, 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725, 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df, 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001, 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8, 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb, 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec, 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207, 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b, 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a, 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817]); - this.I = new X64WordArray(this.convert([0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b, 0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b, 0x5be0cd19, 0x137e2179])); - this.W = (function() { - var _i, _results; - _results = []; - for (i = _i = 0; _i < 80; i = ++_i) { - _results.push(new X64Word(0, 0)); - } - return _results; - })(); - } + TwoFish.prototype.scrub = function() { + scrub_vec(this.gSubKeys); + scrub_vec(this.gSBox); + return this._key.scrub(); + }; - return Global; + TwoFish.prototype.decryptBlock = function(M, offset) { + var k, r, t0, t1, x0, x1, x2, x3, _i; + if (offset == null) { + offset = 0; + } + x2 = this.switchEndianness(M[offset]) ^ this.gSubKeys[4]; + x3 = this.switchEndianness(M[offset + 1]) ^ this.gSubKeys[5]; + x0 = this.switchEndianness(M[offset + 2]) ^ this.gSubKeys[6]; + x1 = this.switchEndianness(M[offset + 3]) ^ this.gSubKeys[7]; + k = 8 + 2 * 16 - 1; + for (r = _i = 0; _i < 16; r = _i += 2) { + t0 = this.Fe32_0(x2); + t1 = this.Fe32_3(x3); + x1 ^= t0 + 2 * t1 + this.gSubKeys[k--]; + x0 = (x0 << 1 | x0 >>> 31) ^ (t0 + t1 + this.gSubKeys[k--]); + x1 = x1 >>> 1 | x1 << 31; + t0 = this.Fe32_0(x0); + t1 = this.Fe32_3(x1); + x3 ^= t0 + 2 * t1 + this.gSubKeys[k--]; + x2 = (x2 << 1 | x2 >>> 31) ^ (t0 + t1 + this.gSubKeys[k--]); + x3 = x3 >>> 1 | x3 << 31; + } + M[offset] = this.switchEndianness(x0 ^ this.gSubKeys[0]); + M[offset + 1] = this.switchEndianness(x1 ^ this.gSubKeys[1]); + M[offset + 2] = this.switchEndianness(x2 ^ this.gSubKeys[2]); + return M[offset + 3] = this.switchEndianness(x3 ^ this.gSubKeys[3]); + }; + + TwoFish.prototype.encryptBlock = function(M, offset) { + var k, r, t0, t1, x0, x1, x2, x3, _i; + if (offset == null) { + offset = 0; + } + x0 = this.switchEndianness(M[offset]) ^ this.gSubKeys[0]; + x1 = this.switchEndianness(M[offset + 1]) ^ this.gSubKeys[1]; + x2 = this.switchEndianness(M[offset + 2]) ^ this.gSubKeys[2]; + x3 = this.switchEndianness(M[offset + 3]) ^ this.gSubKeys[3]; + k = 8; + for (r = _i = 0; _i < 16; r = _i += 2) { + t0 = this.Fe32_0(x0); + t1 = this.Fe32_3(x1); + x2 ^= t0 + t1 + this.gSubKeys[k++]; + x2 = x2 >>> 1 | x2 << 31; + x3 = (x3 << 1 | x3 >>> 31) ^ (t0 + 2 * t1 + this.gSubKeys[k++]); + t0 = this.Fe32_0(x2); + t1 = this.Fe32_3(x3); + x0 ^= t0 + t1 + this.gSubKeys[k++]; + x0 = x0 >>> 1 | x0 << 31; + x1 = (x1 << 1 | x1 >>> 31) ^ (t0 + 2 * t1 + this.gSubKeys[k++]); + } + M[offset] = this.switchEndianness(x2 ^ this.gSubKeys[4]); + M[offset + 1] = this.switchEndianness(x3 ^ this.gSubKeys[5]); + M[offset + 2] = this.switchEndianness(x0 ^ this.gSubKeys[6]); + return M[offset + 3] = this.switchEndianness(x1 ^ this.gSubKeys[7]); + }; - })(); + return TwoFish; - glbl = new Global(); + })(BlockCipher); - exports.SHA512 = SHA512 = (function(_super) { - __extends(SHA512, _super); +}).call(this); - function SHA512() { - _ref1 = SHA512.__super__.constructor.apply(this, arguments); - return _ref1; - } +},{"./algbase":15,"./util":34}],34:[function(require,module,exports){ +// Generated by IcedCoffeeScript 1.6.3-g +(function() { + var default_delay, iced, uint_max, __iced_k, __iced_k_noop; - SHA512.blockSize = 1024 / 32; + iced = require('iced-coffee-script/lib/coffee-script/iced').runtime; + __iced_k = __iced_k_noop = function() {}; - SHA512.prototype.blockSize = SHA512.blockSize; + uint_max = Math.pow(2, 32); - SHA512.output_size = 512 / 8; + exports.fixup_uint32 = function(x) { + var ret, x_pos; + ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x; + return ret; + }; - SHA512.prototype.output_size = SHA512.output_size; + exports.scrub_buffer = function(b) { + var i, n_full_words; + n_full_words = b.length >> 2; + i = 0; + while (i < n_full_words) { + b.writeUInt32LE(0, i); + i += 4; + } + while (i < b.length) { + b.writeUInt8(0, i); + i++; + } + return false; + }; - SHA512.prototype._doReset = function() { - return this._hash = glbl.I.clone(); - }; + exports.scrub_vec = function(v) { + var i, _i, _ref; + for (i = _i = 0, _ref = v.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + v[i] = 0; + } + return false; + }; - SHA512.prototype._doProcessBlock = function(M, offset) { - var H, H0, H0h, H0l, H1, H1h, H1l, H2, H2h, H2l, H3, H3h, H3l, H4, H4h, H4l, H5, H5h, H5l, H6, H6h, H6l, H7, H7h, H7l, Ki, Kih, Kil, W, Wi, Wi16, Wi16h, Wi16l, Wi7, Wi7h, Wi7l, Wih, Wil, ah, al, bh, bl, ch, chh, chl, cl, dh, dl, eh, el, fh, fl, gamma0h, gamma0l, gamma0x, gamma0xh, gamma0xl, gamma1h, gamma1l, gamma1x, gamma1xh, gamma1xl, gh, gl, hh, hl, i, majh, majl, sigma0h, sigma0l, sigma1h, sigma1l, t1h, t1l, t2h, t2l, _i; - H = this._hash.words; - W = glbl.W; - H0 = H[0]; - H1 = H[1]; - H2 = H[2]; - H3 = H[3]; - H4 = H[4]; - H5 = H[5]; - H6 = H[6]; - H7 = H[7]; - H0h = H0.high; - H0l = H0.low; - H1h = H1.high; - H1l = H1.low; - H2h = H2.high; - H2l = H2.low; - H3h = H3.high; - H3l = H3.low; - H4h = H4.high; - H4l = H4.low; - H5h = H5.high; - H5l = H5.low; - H6h = H6.high; - H6l = H6.low; - H7h = H7.high; - H7l = H7.low; - ah = H0h; - al = H0l; - bh = H1h; - bl = H1l; - ch = H2h; - cl = H2l; - dh = H3h; - dl = H3l; - eh = H4h; - el = H4l; - fh = H5h; - fl = H5l; - gh = H6h; - gl = H6l; - hh = H7h; - hl = H7l; - for (i = _i = 0; _i < 80; i = ++_i) { - Wi = W[i]; - if (i < 16) { - Wih = Wi.high = M[offset + i * 2] | 0; - Wil = Wi.low = M[offset + i * 2 + 1] | 0; - } else { - gamma0x = W[i - 15]; - gamma0xh = gamma0x.high; - gamma0xl = gamma0x.low; - gamma0h = ((gamma0xh >>> 1) | (gamma0xl << 31)) ^ ((gamma0xh >>> 8) | (gamma0xl << 24)) ^ (gamma0xh >>> 7); - gamma0l = ((gamma0xl >>> 1) | (gamma0xh << 31)) ^ ((gamma0xl >>> 8) | (gamma0xh << 24)) ^ ((gamma0xl >>> 7) | (gamma0xh << 25)); - gamma1x = W[i - 2]; - gamma1xh = gamma1x.high; - gamma1xl = gamma1x.low; - gamma1h = ((gamma1xh >>> 19) | (gamma1xl << 13)) ^ ((gamma1xh << 3) | (gamma1xl >>> 29)) ^ (gamma1xh >>> 6); - gamma1l = ((gamma1xl >>> 19) | (gamma1xh << 13)) ^ ((gamma1xl << 3) | (gamma1xh >>> 29)) ^ ((gamma1xl >>> 6) | (gamma1xh << 26)); - Wi7 = W[i - 7]; - Wi7h = Wi7.high; - Wi7l = Wi7.low; - Wi16 = W[i - 16]; - Wi16h = Wi16.high; - Wi16l = Wi16.low; - Wil = gamma0l + Wi7l; - Wih = gamma0h + Wi7h + ((Wil >>> 0) < (gamma0l >>> 0) ? 1 : 0); - Wil = Wil + gamma1l; - Wih = Wih + gamma1h + ((Wil >>> 0) < (gamma1l >>> 0) ? 1 : 0); - Wil = Wil + Wi16l; - Wih = Wih + Wi16h + ((Wil >>> 0) < (Wi16l >>> 0) ? 1 : 0); - Wi.high = Wih; - Wi.low = Wil; - } - chh = (eh & fh) ^ (~eh & gh); - chl = (el & fl) ^ (~el & gl); - majh = (ah & bh) ^ (ah & ch) ^ (bh & ch); - majl = (al & bl) ^ (al & cl) ^ (bl & cl); - sigma0h = ((ah >>> 28) | (al << 4)) ^ ((ah << 30) | (al >>> 2)) ^ ((ah << 25) | (al >>> 7)); - sigma0l = ((al >>> 28) | (ah << 4)) ^ ((al << 30) | (ah >>> 2)) ^ ((al << 25) | (ah >>> 7)); - sigma1h = ((eh >>> 14) | (el << 18)) ^ ((eh >>> 18) | (el << 14)) ^ ((eh << 23) | (el >>> 9)); - sigma1l = ((el >>> 14) | (eh << 18)) ^ ((el >>> 18) | (eh << 14)) ^ ((el << 23) | (eh >>> 9)); - Ki = glbl.K[i]; - Kih = Ki.high; - Kil = Ki.low; - t1l = hl + sigma1l; - t1h = hh + sigma1h + ((t1l >>> 0) < (hl >>> 0) ? 1 : 0); - t1l = t1l + chl; - t1h = t1h + chh + ((t1l >>> 0) < (chl >>> 0) ? 1 : 0); - t1l = t1l + Kil; - t1h = t1h + Kih + ((t1l >>> 0) < (Kil >>> 0) ? 1 : 0); - t1l = t1l + Wil; - t1h = t1h + Wih + ((t1l >>> 0) < (Wil >>> 0) ? 1 : 0); - t2l = sigma0l + majl; - t2h = sigma0h + majh + ((t2l >>> 0) < (sigma0l >>> 0) ? 1 : 0); - hh = gh; - hl = gl; - gh = fh; - gl = fl; - fh = eh; - fl = el; - el = (dl + t1l) | 0; - eh = (dh + t1h + ((el >>> 0) < (dl >>> 0) ? 1 : 0)) | 0; - dh = ch; - dl = cl; - ch = bh; - cl = bl; - bh = ah; - bl = al; - al = (t1l + t2l) | 0; - ah = (t1h + t2h + ((al >>> 0) < (t1l >>> 0) ? 1 : 0)) | 0; + exports.default_delay = default_delay = function(i, n, cb) { + var ___iced_passed_deferral, __iced_deferrals, __iced_k, + _this = this; + __iced_k = __iced_k_noop; + ___iced_passed_deferral = iced.findDeferral(arguments); + (function(__iced_k) { + if (typeof setImmediate !== "undefined" && setImmediate !== null) { + (function(__iced_k) { + __iced_deferrals = new iced.Deferrals(__iced_k, { + parent: ___iced_passed_deferral, + filename: "src/util.iced", + funcname: "default_delay" + }); + setImmediate(__iced_deferrals.defer({ + lineno: 37 + })); + __iced_deferrals._fulfill(); + })(__iced_k); + } else { + (function(__iced_k) { + __iced_deferrals = new iced.Deferrals(__iced_k, { + parent: ___iced_passed_deferral, + filename: "src/util.iced", + funcname: "default_delay" + }); + setTimeout(__iced_deferrals.defer({ + lineno: 39 + }), 1); + __iced_deferrals._fulfill(); + })(__iced_k); } - H0l = H0.low = H0l + al; - H0.high = H0h + ah + ((H0l >>> 0) < (al >>> 0) ? 1 : 0); - H1l = H1.low = H1l + bl; - H1.high = H1h + bh + ((H1l >>> 0) < (bl >>> 0) ? 1 : 0); - H2l = H2.low = H2l + cl; - H2.high = H2h + ch + ((H2l >>> 0) < (cl >>> 0) ? 1 : 0); - H3l = H3.low = H3l + dl; - H3.high = H3h + dh + ((H3l >>> 0) < (dl >>> 0) ? 1 : 0); - H4l = H4.low = H4l + el; - H4.high = H4h + eh + ((H4l >>> 0) < (el >>> 0) ? 1 : 0); - H5l = H5.low = H5l + fl; - H5.high = H5h + fh + ((H5l >>> 0) < (fl >>> 0) ? 1 : 0); - H6l = H6.low = H6l + gl; - H6.high = H6h + gh + ((H6l >>> 0) < (gl >>> 0) ? 1 : 0); - H7l = H7.low = H7l + hl; - return H7.high = H7h + hh + ((H7l >>> 0) < (hl >>> 0) ? 1 : 0); - }; - - SHA512.prototype._doFinalize = function() { - var dataWords, nBitsLeft, nBitsTotal; - dataWords = this._data.words; - nBitsTotal = this._nDataBytes * 8; - nBitsLeft = this._data.sigBytes * 8; - dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); - dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 30] = Math.floor(nBitsTotal / 0x100000000); - dataWords[(((nBitsLeft + 128) >>> 10) << 5) + 31] = nBitsTotal; - this._data.sigBytes = dataWords.length * 4; - this._process(); - return this._hash.toX32(); - }; - - SHA512.prototype.copy_to = function(obj) { - SHA512.__super__.copy_to.call(this, obj); - return obj._hash = this._hash.clone(); - }; + })(function() { + return cb(); + }); + }; - SHA512.prototype.clone = function() { - var out; - out = new SHA512(); - this.copy_to(out); - return out; + exports.bulk = function(n_input_bytes, _arg, _arg1) { + var call_ph, cb, default_n, delay, finalize, i, left, n, n_words, progress_hook, ret, total_words, update, what, ___iced_passed_deferral, __iced_deferrals, __iced_k, + _this = this; + __iced_k = __iced_k_noop; + ___iced_passed_deferral = iced.findDeferral(arguments); + update = _arg.update, finalize = _arg.finalize, default_n = _arg.default_n; + delay = _arg1.delay, n = _arg1.n, cb = _arg1.cb, what = _arg1.what, progress_hook = _arg1.progress_hook; + i = 0; + left = 0; + total_words = Math.ceil(n_input_bytes / 4); + delay || (delay = default_delay); + n || (n = default_n); + call_ph = function(i) { + return typeof progress_hook === "function" ? progress_hook({ + what: what, + i: i, + total: total_words + }) : void 0; }; - - return SHA512; - - })(Hasher); - - exports.transform = function(x) { - var out; - out = (new SHA512).finalize(x); - x.scrub(); - return out; + call_ph(0); + (function(__iced_k) { + var _results, _while; + _results = []; + _while = function(__iced_k) { + var _break, _continue, _next; + _break = function() { + return __iced_k(_results); + }; + _continue = function() { + return iced.trampoline(function() { + return _while(__iced_k); + }); + }; + _next = function(__iced_next_arg) { + _results.push(__iced_next_arg); + return _continue(); + }; + if (!((left = total_words - i) > 0)) { + return _break(); + } else { + n_words = Math.min(n, left); + update(i, i + n_words); + call_ph(i); + (function(__iced_k) { + __iced_deferrals = new iced.Deferrals(__iced_k, { + parent: ___iced_passed_deferral, + filename: "src/util.iced", + funcname: "bulk" + }); + delay(i, total_words, __iced_deferrals.defer({ + lineno: 73 + })); + __iced_deferrals._fulfill(); + })(function() { + return _next(i += n_words); + }); + } + }; + _while(__iced_k); + })(function() { + call_ph(total_words); + ret = finalize(); + return cb(ret); + }); }; }).call(this); -},{"./algbase":18,"./wordarray":38}],36:[function(require,module,exports){ +},{"iced-coffee-script/lib/coffee-script/iced":41}],35:[function(require,module,exports){ +(function (Buffer){ // Generated by IcedCoffeeScript 1.6.3-g (function() { - var BlockCipher, G, Global, TwoFish, scrub_vec, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + var WordArray, X64Word, X64WordArray, buffer_to_ui8a, endian_reverse, ui8a_to_buffer, util; - BlockCipher = require('./algbase').BlockCipher; + util = require('./util'); - scrub_vec = require('./util').scrub_vec; + buffer_to_ui8a = function(b) { + var i, ret, _i, _ref; + ret = new Uint8Array(b.length); + for (i = _i = 0, _ref = b.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + ret[i] = b.readUInt8(i); + } + return ret; + }; - Global = (function() { - function Global() { - this.P = [[0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, 0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23, 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82, 0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61, 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B, 0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66, 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7, 0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 0xEA, 0x77, 0x39, 0xAF, 0x33, 0xC9, 0x62, 0x71, 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8, 0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 0xA1, 0x1D, 0xAA, 0xED, 0x06, 0x70, 0xB2, 0xD2, 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90, 0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 0x9E, 0x9C, 0x52, 0x1B, 0x5F, 0x93, 0x0A, 0xEF, 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B, 0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 0x2A, 0xCE, 0xCB, 0x2F, 0xFC, 0x97, 0x05, 0x7A, 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A, 0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 0xB8, 0xDA, 0xB0, 0x17, 0x55, 0x1F, 0x8A, 0x7D, 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72, 0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 0x6E, 0x50, 0xDE, 0x68, 0x65, 0xBC, 0xDB, 0xF8, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4, 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0], [0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, 0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B, 0x8A, 0x00, 0xBC, 0x9D, 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5, 0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 0xB2, 0x73, 0x4C, 0x54, 0x92, 0x74, 0x36, 0x51, 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96, 0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 0x13, 0x95, 0x9C, 0xC7, 0x24, 0x46, 0x3B, 0x70, 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8, 0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 0x03, 0x6F, 0x08, 0xBF, 0x40, 0xE7, 0x2B, 0xE2, 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9, 0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 0x66, 0x94, 0xA1, 0x1D, 0x3D, 0xF0, 0xDE, 0xB3, 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E, 0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 0x81, 0x88, 0xEE, 0x21, 0xC4, 0x1A, 0xEB, 0xD9, 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01, 0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 0x4F, 0xF2, 0x65, 0x8E, 0x78, 0x5C, 0x58, 0x19, 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64, 0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 0xCE, 0xE9, 0x68, 0x44, 0xE0, 0x4D, 0x43, 0x69, 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E, 0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 0x22, 0xC9, 0xC0, 0x9B, 0x89, 0xD4, 0xED, 0xAB, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9, 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91]]; - this.P_00 = 1; - this.P_01 = 0; - this.P_02 = 0; - this.P_03 = 1; - this.P_04 = 1; - this.P_10 = 0; - this.P_11 = 0; - this.P_12 = 1; - this.P_13 = 1; - this.P_14 = 0; - this.P_20 = 1; - this.P_21 = 1; - this.P_22 = 0; - this.P_23 = 0; - this.P_24 = 0; - this.P_30 = 0; - this.P_31 = 1; - this.P_32 = 1; - this.P_33 = 0; - this.P_34 = 1; - this.GF256_FDBK = 0x169; - this.GF256_FDBK_2 = this.GF256_FDBK / 2; - this.GF256_FDBK_4 = this.GF256_FDBK / 4; - this.RS_GF_FDBK = 0x14D; - this.SK_STEP = 0x02020202; - this.SK_BUMP = 0x01010101; - this.SK_ROTL = 9; + ui8a_to_buffer = function(v) { + var i, ret, _i, _ref; + ret = new Buffer(v.length); + for (i = _i = 0, _ref = v.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + ret.writeUInt8(v[i], i); } + return ret; + }; - return Global; + endian_reverse = function(x) { + return ((x >>> 24) & 0xff) | (((x >>> 16) & 0xff) << 8) | (((x >>> 8) & 0xff) << 16) | ((x & 0xff) << 24); + }; - })(); + exports.WordArray = WordArray = (function() { + function WordArray(words, sigBytes) { + this.words = words || []; + this.sigBytes = sigBytes != null ? sigBytes : this.words.length * 4; + } - G = new Global(); + WordArray.prototype.concat = function(wordArray) { + var i, thatByte, thatSigBytes, thatWords, _i; + thatWords = wordArray.words; + thatSigBytes = wordArray.sigBytes; + this.clamp(); + if (this.sigBytes % 4) { + for (i = _i = 0; 0 <= thatSigBytes ? _i < thatSigBytes : _i > thatSigBytes; i = 0 <= thatSigBytes ? ++_i : --_i) { + thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + this.words[(this.sigBytes + i) >>> 2] |= thatByte << (24 - ((this.sigBytes + i) % 4) * 8); + } + } else { + this.words = this.words.concat(thatWords); + } + this.sigBytes += thatSigBytes; + return this; + }; - exports.TwoFish = TwoFish = (function(_super) { - __extends(TwoFish, _super); + WordArray.prototype.clamp = function() { + this.words[this.sigBytes >>> 2] &= 0xffffffff << (32 - (this.sigBytes % 4) * 8); + this.words.length = Math.ceil(this.sigBytes / 4); + return this; + }; - TwoFish.blockSize = 4 * 4; + WordArray.prototype.clone = function() { + return new WordArray(this.words.slice(0), this.sigBytes); + }; - TwoFish.prototype.blockSize = TwoFish.blockSize; + WordArray.prototype.to_buffer = function() { + var ch, out, p, w, _i, _len, _ref; + out = new Buffer(this.sigBytes); + p = 0; + _ref = this.words; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + w = _ref[_i]; + if (!((this.sigBytes - p) >= 4)) { + continue; + } + w = util.fixup_uint32(w); + out.writeUInt32BE(w, p); + p += 4; + } + while (p < this.sigBytes) { + ch = (this.words[p >>> 2] >>> (24 - (p % 4) * 8)) & 0xff; + out.writeUInt8(ch, p); + p++; + } + return out; + }; - TwoFish.keySize = 256 / 8; + WordArray.prototype.endian_reverse = function() { + var i, w, _i, _len, _ref; + _ref = this.words; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + w = _ref[i]; + this.words[i] = endian_reverse(w); + } + return this; + }; - TwoFish.prototype.keySize = TwoFish.keySize; + WordArray.prototype.split = function(n) { + var i, out, sz; + if (!(((this.sigBytes % 4) === 0) && ((this.words.length % n) === 0))) { + throw new Error("bad key alignment"); + } + sz = this.words.length / n; + out = (function() { + var _i, _ref, _results; + _results = []; + for (i = _i = 0, _ref = this.words.length; sz > 0 ? _i < _ref : _i > _ref; i = _i += sz) { + _results.push(new WordArray(this.words.slice(i, i + sz))); + } + return _results; + }).call(this); + return out; + }; - TwoFish.ivSize = TwoFish.blockSize; + WordArray.prototype.to_utf8 = function() { + return this.to_buffer().toString('utf8'); + }; - TwoFish.prototype.ivSize = TwoFish.ivSize; + WordArray.prototype.to_hex = function() { + return this.to_buffer().toString('hex'); + }; - function TwoFish(key) { - this._key = key.clone(); - this.gMDS0 = []; - this.gMDS1 = []; - this.gMDS2 = []; - this.gMDS3 = []; - this.gSubKeys = []; - this.gSBox = []; - this.k64Cnt = 0; - this._doReset(); - } + WordArray.prototype.to_ui8a = function() { + return buffer_to_ui8a(this.to_buffer()); + }; + + WordArray.alloc = function(b) { + if (Buffer.isBuffer(b)) { + return WordArray.from_buffer(b); + } else if ((typeof b === 'object') && (b instanceof WordArray)) { + return b; + } else if (typeof b === 'string') { + return WordArray.from_hex(b); + } else { + return null; + } + }; + + WordArray.from_buffer = function(b) { + var ch, last, p, words; + words = []; + p = 0; + while ((b.length - p) >= 4) { + words.push(b.readUInt32BE(p)); + p += 4; + } + if (p < b.length) { + last = 0; + while (p < b.length) { + ch = b.readUInt8(p); + last |= ch << (24 - (p % 4) * 8); + p++; + } + last = util.fixup_uint32(last); + words.push(last); + } + return new WordArray(words, b.length); + }; + + WordArray.from_buffer_le = function(b) { + var ch, last, p, words; + words = []; + p = 0; + while ((b.length - p) >= 4) { + words.push(b.readUInt32LE(p)); + p += 4; + } + if (p < b.length) { + last = 0; + while (p < b.length) { + ch = b.readUInt8(p); + last |= ch << ((p % 4) * 8); + p++; + } + last = util.fixup_uint32(last); + words.push(last); + } + return new WordArray(words, b.length); + }; - TwoFish.prototype.getByte = function(x, n) { - return (x >>> (n * 8)) & 0xFF; + WordArray.from_utf8 = function(s) { + return WordArray.from_buffer(new Buffer(s, 'utf8')); }; - TwoFish.prototype.switchEndianness = function(word) { - return ((word & 0xff) << 24) | (((word >> 8) & 0xff) << 16) | (((word >> 16) & 0xff) << 8) | ((word >> 24) & 0xff); + WordArray.from_utf8_le = function(s) { + return WordArray.from_buffer_le(new Buffer(s, 'utf8')); }; - TwoFish.prototype.LFSR1 = function(x) { - return (x >> 1) ^ ((x & 0x01) !== 0 ? G.GF256_FDBK_2 : 0); + WordArray.from_hex = function(s) { + return WordArray.from_buffer(new Buffer(s, 'hex')); }; - TwoFish.prototype.LFSR2 = function(x) { - return (x >> 2) ^ ((x & 0x02) !== 0 ? G.GF256_FDBK_2 : 0) ^ ((x & 0x01) !== 0 ? G.GF256_FDBK_4 : 0); + WordArray.from_hex_le = function(s) { + return WordArray.from_buffer_le(new Buffer(s, 'hex')); }; - TwoFish.prototype.Mx_X = function(x) { - return x ^ this.LFSR2(x); + WordArray.from_ui8a = function(v) { + return WordArray.from_buffer(ui8a_to_buffer(v)); }; - TwoFish.prototype.Mx_Y = function(x) { - return x ^ this.LFSR1(x) ^ this.LFSR2(x); + WordArray.from_i32a = function(v) { + return new WordArray(Array.apply([], v)); }; - TwoFish.prototype.RS_rem = function(x) { - var b, g2, g3; - b = (x >>> 24) & 0xff; - g2 = ((b << 1) ^ ((b & 0x80) !== 0 ? G.RS_GF_FDBK : 0)) & 0xff; - g3 = ((b >>> 1) ^ ((b & 0x01) !== 0 ? G.RS_GF_FDBK >>> 1 : 0)) ^ g2; - return (x << 8) ^ (g3 << 24) ^ (g2 << 16) ^ (g3 << 8) ^ b; + WordArray.prototype.equal = function(wa) { + var i, ret, w, _i, _len, _ref; + ret = true; + if (wa.sigBytes !== this.sigBytes) { + ret = false; + } else { + _ref = this.words; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + w = _ref[i]; + if (util.fixup_uint32(w) !== util.fixup_uint32(wa.words[i])) { + ret = false; + } + } + } + return ret; }; - TwoFish.prototype.RS_MDS_Encode = function(k0, k1) { - var i, r, _i, _j; - r = k1; - for (i = _i = 0; _i < 4; i = ++_i) { - r = this.RS_rem(r); + WordArray.prototype.xor = function(wa2, _arg) { + var dst_offset, i, n_words, src_offset, tmp, _i; + dst_offset = _arg.dst_offset, src_offset = _arg.src_offset, n_words = _arg.n_words; + if (!dst_offset) { + dst_offset = 0; } - r ^= k0; - for (i = _j = 0; _j < 4; i = ++_j) { - r = this.RS_rem(r); + if (!src_offset) { + src_offset = 0; } - return r; + if (n_words == null) { + n_words = wa2.words.length - src_offset; + } + if (this.words.length < dst_offset + n_words) { + throw new Error("dest range exceeded (" + this.words.length + " < " + (dst_offset + n_words) + ")"); + } + if (wa2.words.length < src_offset + n_words) { + throw new Error("source range exceeded"); + } + for (i = _i = 0; 0 <= n_words ? _i < n_words : _i > n_words; i = 0 <= n_words ? ++_i : --_i) { + tmp = this.words[dst_offset + i] ^ wa2.words[src_offset + i]; + this.words[dst_offset + i] = util.fixup_uint32(tmp); + } + return this; }; - TwoFish.prototype.F32 = function(x, k32) { - var b0, b1, b2, b3, k0, k1, k2, k3, m, res; - b0 = this.getByte(x, 0); - b1 = this.getByte(x, 1); - b2 = this.getByte(x, 2); - b3 = this.getByte(x, 3); - k0 = k32[0]; - k1 = k32[1]; - k2 = k32[2]; - k3 = k32[3]; - m = this.k64Cnt & 3; - res = m === 1 ? this.gMDS0[(G.P[G.P_01][b0] & 0xff) ^ this.getByte(k0, 0)] ^ this.gMDS1[(G.P[G.P_11][b1] & 0xff) ^ this.getByte(k0, 1)] ^ this.gMDS2[(G.P[G.P_21][b2] & 0xff) ^ this.getByte(k0, 2)] ^ this.gMDS3[(G.P[G.P_31][b3] & 0xff) ^ this.getByte(k0, 3)] : (m === 0 ? (b0 = (G.P[G.P_04][b0] & 0xff) ^ this.getByte(k3, 0), b1 = (G.P[G.P_14][b1] & 0xff) ^ this.getByte(k3, 1), b2 = (G.P[G.P_24][b2] & 0xff) ^ this.getByte(k3, 2), b3 = (G.P[G.P_34][b3] & 0xff) ^ this.getByte(k3, 3)) : void 0, m === 0 || m === 3 ? (b0 = (G.P[G.P_03][b0] & 0xff) ^ this.getByte(k2, 0), b1 = (G.P[G.P_13][b1] & 0xff) ^ this.getByte(k2, 1), b2 = (G.P[G.P_23][b2] & 0xff) ^ this.getByte(k2, 2), b3 = (G.P[G.P_33][b3] & 0xff) ^ this.getByte(k2, 3)) : void 0, this.gMDS0[(G.P[G.P_01][(G.P[G.P_02][b0] & 0xff) ^ this.getByte(k1, 0)] & 0xff) ^ this.getByte(k0, 0)] ^ this.gMDS1[(G.P[G.P_11][(G.P[G.P_12][b1] & 0xff) ^ this.getByte(k1, 1)] & 0xff) ^ this.getByte(k0, 1)] ^ this.gMDS2[(G.P[G.P_21][(G.P[G.P_22][b2] & 0xff) ^ this.getByte(k1, 2)] & 0xff) ^ this.getByte(k0, 2)] ^ this.gMDS3[(G.P[G.P_31][(G.P[G.P_32][b3] & 0xff) ^ this.getByte(k1, 3)] & 0xff) ^ this.getByte(k0, 3)]); - return res; + WordArray.prototype.truncate = function(n_bytes) { + var n_words; + if (!(n_bytes <= this.sigBytes)) { + throw new Error("Cannot truncate: " + n_bytes + " > " + this.sigBytes); + } + n_words = Math.ceil(n_bytes / 4); + return new WordArray(this.words.slice(0, n_words), n_bytes); }; - TwoFish.prototype.Fe32_0 = function(x) { - return this.gSBox[0x000 + 2 * (x & 0xff)] ^ this.gSBox[0x001 + 2 * ((x >>> 8) & 0xff)] ^ this.gSBox[0x200 + 2 * ((x >>> 16) & 0xff)] ^ this.gSBox[0x201 + 2 * ((x >>> 24) & 0xff)]; + WordArray.prototype.unshift = function(n_words) { + var ret; + if (this.words.length >= n_words) { + ret = this.words.splice(0, n_words); + this.sigBytes -= n_words * 4; + return new WordArray(ret); + } else { + return null; + } }; - TwoFish.prototype.Fe32_3 = function(x) { - return this.gSBox[0x000 + 2 * ((x >>> 24) & 0xff)] ^ this.gSBox[0x001 + 2 * (x & 0xff)] ^ this.gSBox[0x200 + 2 * ((x >>> 8) & 0xff)] ^ this.gSBox[0x201 + 2 * ((x >>> 16) & 0xff)]; + WordArray.prototype.is_scrubbed = function() { + var w, _i, _len, _ref; + _ref = this.words; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + w = _ref[_i]; + if (w !== 0) { + return false; + } + } + return true; }; - TwoFish.prototype._doReset = function() { - var A, B, b0, b1, b2, b3, i, j, k0, k1, k2, k3, k32e, k32o, m, m1, mX, mY, p, q, sBoxKeys, _i, _j, _k, _l, _ref, _ref1, _results; - k32e = []; - k32o = []; - sBoxKeys = []; - m1 = []; - mX = []; - mY = []; - this.k64Cnt = this._key.words.length / 2; - if (this.k64Cnt < 1) { - throw "Key size less than 64 bits"; - } - if (this.k64Cnt > 4) { - throw "Key size larger than 256 bits"; - } - for (i = _i = 0; _i < 256; i = ++_i) { - j = G.P[0][i] & 0xff; - m1[0] = j; - mX[0] = this.Mx_X(j) & 0xff; - mY[0] = this.Mx_Y(j) & 0xff; - j = G.P[1][i] & 0xff; - m1[1] = j; - mX[1] = this.Mx_X(j) & 0xff; - mY[1] = this.Mx_Y(j) & 0xff; - this.gMDS0[i] = m1[G.P_00] | mX[G.P_00] << 8 | mY[G.P_00] << 16 | mY[G.P_00] << 24; - this.gMDS1[i] = mY[G.P_10] | mY[G.P_10] << 8 | mX[G.P_10] << 16 | m1[G.P_10] << 24; - this.gMDS2[i] = mX[G.P_20] | mY[G.P_20] << 8 | m1[G.P_20] << 16 | mY[G.P_20] << 24; - this.gMDS3[i] = mX[G.P_30] | m1[G.P_30] << 8 | mY[G.P_30] << 16 | mX[G.P_30] << 24; + WordArray.prototype.scrub = function() { + return util.scrub_vec(this.words); + }; + + WordArray.prototype.slice = function(low, hi) { + var n, sb; + n = this.words.length; + if (!((low < hi) && (hi <= n))) { + throw new Error("Bad WordArray slice [" + low + "," + hi + ")] when only " + n + " avail"); } - for (i = _j = 0, _ref = this.k64Cnt; 0 <= _ref ? _j < _ref : _j > _ref; i = 0 <= _ref ? ++_j : --_j) { - p = i * 2; - k32e[i] = this.switchEndianness(this._key.words[p]); - k32o[i] = this.switchEndianness(this._key.words[p + 1]); - sBoxKeys[this.k64Cnt - 1 - i] = this.RS_MDS_Encode(k32e[i], k32o[i]); + sb = (hi - low) * 4; + if (hi === n) { + sb -= n * 4 - this.sigBytes; } - for (i = _k = 0, _ref1 = 40 / 2; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) { - q = i * G.SK_STEP; - A = this.F32(q, k32e); - B = this.F32(q + G.SK_BUMP, k32o); - B = B << 8 | B >>> 24; - A += B; - this.gSubKeys[i * 2] = A; - A += B; - this.gSubKeys[i * 2 + 1] = A << G.SK_ROTL | A >>> (32 - G.SK_ROTL); + return new WordArray(this.words.slice(low, hi), sb); + }; + + return WordArray; + + })(); + + exports.X64Word = X64Word = (function() { + function X64Word(high, low) { + this.high = high; + this.low = low; + } + + X64Word.prototype.clone = function() { + return new X64Word(this.high, this.low); + }; + + return X64Word; + + })(); + + exports.X64WordArray = X64WordArray = (function() { + function X64WordArray(words, sigBytes) { + this.sigBytes = sigBytes; + this.words = words || []; + if (!this.sigBytes) { + this.sigBytes = this.words.length * 8; } - k0 = sBoxKeys[0]; - k1 = sBoxKeys[1]; - k2 = sBoxKeys[2]; - k3 = sBoxKeys[3]; - this.gSBox = []; - _results = []; - for (i = _l = 0; _l < 256; i = ++_l) { - b0 = b1 = b2 = b3 = i; - m = this.k64Cnt & 3; - if (m === 1) { - this.gSBox[i * 2] = this.gMDS0[(G.P[G.P_01][b0] & 0xff) ^ this.getByte(k0, 0)]; - this.gSBox[i * 2 + 1] = this.gMDS1[(G.P[G.P_11][b1] & 0xff) ^ this.getByte(k0, 1)]; - this.gSBox[i * 2 + 0x200] = this.gMDS2[(G.P[G.P_21][b2] & 0xff) ^ this.getByte(k0, 2)]; - _results.push(this.gSBox[i * 2 + 0x201] = this.gMDS3[(G.P[G.P_31][b3] & 0xff) ^ this.getByte(k0, 3)]); - } else { - if (m === 0) { - b0 = (G.P[G.P_04][b0] & 0xff) ^ this.getByte(k3, 0); - b1 = (G.P[G.P_14][b1] & 0xff) ^ this.getByte(k3, 1); - b2 = (G.P[G.P_24][b2] & 0xff) ^ this.getByte(k3, 2); - b3 = (G.P[G.P_34][b3] & 0xff) ^ this.getByte(k3, 3); - } - if (m === 0 || m === 3) { - b0 = (G.P[G.P_03][b0] & 0xff) ^ this.getByte(k2, 0); - b1 = (G.P[G.P_13][b1] & 0xff) ^ this.getByte(k2, 1); - b2 = (G.P[G.P_23][b2] & 0xff) ^ this.getByte(k2, 2); - b3 = (G.P[G.P_33][b3] & 0xff) ^ this.getByte(k2, 3); - } - this.gSBox[i * 2] = this.gMDS0[(G.P[G.P_01][(G.P[G.P_02][b0] & 0xff) ^ this.getByte(k1, 0)] & 0xff) ^ this.getByte(k0, 0)]; - this.gSBox[i * 2 + 1] = this.gMDS1[(G.P[G.P_11][(G.P[G.P_12][b1] & 0xff) ^ this.getByte(k1, 1)] & 0xff) ^ this.getByte(k0, 1)]; - this.gSBox[i * 2 + 0x200] = this.gMDS2[(G.P[G.P_21][(G.P[G.P_22][b2] & 0xff) ^ this.getByte(k1, 2)] & 0xff) ^ this.getByte(k0, 2)]; - _results.push(this.gSBox[i * 2 + 0x201] = this.gMDS3[(G.P[G.P_31][(G.P[G.P_32][b3] & 0xff) ^ this.getByte(k1, 3)] & 0xff) ^ this.getByte(k0, 3)]); - } + } + + X64WordArray.prototype.toX32 = function() { + var v, w, _i, _len, _ref; + v = []; + _ref = this.words; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + w = _ref[_i]; + v.push(w.high); + v.push(w.low); } - return _results; + return new WordArray(v, this.sigBytes); }; - TwoFish.prototype.scrub = function() { - scrub_vec(this.gSubKeys); - scrub_vec(this.gSBox); - return this._key.scrub(); + X64WordArray.prototype.clone = function() { + var w; + return new X64WordArray((function() { + var _i, _len, _ref, _results; + _ref = this.words; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + w = _ref[_i]; + _results.push(w.clone()); + } + return _results; + }).call(this), this.sigBytes); }; - TwoFish.prototype.decryptBlock = function(M, offset) { - var k, r, t0, t1, x0, x1, x2, x3, _i; - if (offset == null) { - offset = 0; - } - x2 = this.switchEndianness(M[offset]) ^ this.gSubKeys[4]; - x3 = this.switchEndianness(M[offset + 1]) ^ this.gSubKeys[5]; - x0 = this.switchEndianness(M[offset + 2]) ^ this.gSubKeys[6]; - x1 = this.switchEndianness(M[offset + 3]) ^ this.gSubKeys[7]; - k = 8 + 2 * 16 - 1; - for (r = _i = 0; _i < 16; r = _i += 2) { - t0 = this.Fe32_0(x2); - t1 = this.Fe32_3(x3); - x1 ^= t0 + 2 * t1 + this.gSubKeys[k--]; - x0 = (x0 << 1 | x0 >>> 31) ^ (t0 + t1 + this.gSubKeys[k--]); - x1 = x1 >>> 1 | x1 << 31; - t0 = this.Fe32_0(x0); - t1 = this.Fe32_3(x1); - x3 ^= t0 + 2 * t1 + this.gSubKeys[k--]; - x2 = (x2 << 1 | x2 >>> 31) ^ (t0 + t1 + this.gSubKeys[k--]); - x3 = x3 >>> 1 | x3 << 31; + return X64WordArray; + + })(); + + exports.buffer_to_ui8a = buffer_to_ui8a; + + exports.ui8a_to_buffer = ui8a_to_buffer; + + exports.endian_reverse = endian_reverse; + +}).call(this); + +}).call(this,require("buffer").Buffer) +},{"./util":34,"buffer":2}],36:[function(require,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true } - M[offset] = this.switchEndianness(x0 ^ this.gSubKeys[0]); - M[offset + 1] = this.switchEndianness(x1 ^ this.gSubKeys[1]); - M[offset + 2] = this.switchEndianness(x2 ^ this.gSubKeys[2]); - return M[offset + 3] = this.switchEndianness(x3 ^ this.gSubKeys[3]); + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} + +},{}],37:[function(require,module,exports){ +module.exports = function isBuffer(arg) { + return arg && typeof arg === 'object' + && typeof arg.copy === 'function' + && typeof arg.fill === 'function' + && typeof arg.readUInt8 === 'function'; +} +},{}],38:[function(require,module,exports){ +(function (process,global){ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +var formatRegExp = /%[sdj%]/g; +exports.format = function(f) { + if (!isString(f)) { + var objects = []; + for (var i = 0; i < arguments.length; i++) { + objects.push(inspect(arguments[i])); + } + return objects.join(' '); + } + + var i = 1; + var args = arguments; + var len = args.length; + var str = String(f).replace(formatRegExp, function(x) { + if (x === '%%') return '%'; + if (i >= len) return x; + switch (x) { + case '%s': return String(args[i++]); + case '%d': return Number(args[i++]); + case '%j': + try { + return JSON.stringify(args[i++]); + } catch (_) { + return '[Circular]'; + } + default: + return x; + } + }); + for (var x = args[i]; i < len; x = args[++i]) { + if (isNull(x) || !isObject(x)) { + str += ' ' + x; + } else { + str += ' ' + inspect(x); + } + } + return str; +}; + + +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + // Allow for deprecating things in the process of starting up. + if (isUndefined(global.process)) { + return function() { + return exports.deprecate(fn, msg).apply(this, arguments); }; + } - TwoFish.prototype.encryptBlock = function(M, offset) { - var k, r, t0, t1, x0, x1, x2, x3, _i; - if (offset == null) { - offset = 0; - } - x0 = this.switchEndianness(M[offset]) ^ this.gSubKeys[0]; - x1 = this.switchEndianness(M[offset + 1]) ^ this.gSubKeys[1]; - x2 = this.switchEndianness(M[offset + 2]) ^ this.gSubKeys[2]; - x3 = this.switchEndianness(M[offset + 3]) ^ this.gSubKeys[3]; - k = 8; - for (r = _i = 0; _i < 16; r = _i += 2) { - t0 = this.Fe32_0(x0); - t1 = this.Fe32_3(x1); - x2 ^= t0 + t1 + this.gSubKeys[k++]; - x2 = x2 >>> 1 | x2 << 31; - x3 = (x3 << 1 | x3 >>> 31) ^ (t0 + 2 * t1 + this.gSubKeys[k++]); - t0 = this.Fe32_0(x2); - t1 = this.Fe32_3(x3); - x0 ^= t0 + t1 + this.gSubKeys[k++]; - x0 = x0 >>> 1 | x0 << 31; - x1 = (x1 << 1 | x1 >>> 31) ^ (t0 + 2 * t1 + this.gSubKeys[k++]); + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.throwDeprecation) { + throw new Error(msg); + } else if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); } - M[offset] = this.switchEndianness(x2 ^ this.gSubKeys[4]); - M[offset + 1] = this.switchEndianness(x3 ^ this.gSubKeys[5]); - M[offset + 2] = this.switchEndianness(x0 ^ this.gSubKeys[6]); - return M[offset + 3] = this.switchEndianness(x1 ^ this.gSubKeys[7]); - }; + warned = true; + } + return fn.apply(this, arguments); + } - return TwoFish; + return deprecated; +}; - })(BlockCipher); -}).call(this); +var debugs = {}; +var debugEnviron; +exports.debuglog = function(set) { + if (isUndefined(debugEnviron)) + debugEnviron = process.env.NODE_DEBUG || ''; + set = set.toUpperCase(); + if (!debugs[set]) { + if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { + var pid = process.pid; + debugs[set] = function() { + var msg = exports.format.apply(exports, arguments); + console.error('%s %d: %s', set, pid, msg); + }; + } else { + debugs[set] = function() {}; + } + } + return debugs[set]; +}; -},{"./algbase":18,"./util":37}],37:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.6.3-g -(function() { - var default_delay, iced, uint_max, __iced_k, __iced_k_noop; - iced = require('iced-coffee-script/lib/coffee-script/iced').runtime; - __iced_k = __iced_k_noop = function() {}; +/** + * Echos the value of a value. Trys to print the value out + * in the best way possible given the different types. + * + * @param {Object} obj The object to print out. + * @param {Object} opts Optional options object that alters the output. + */ +/* legacy: obj, showHidden, depth, colors*/ +function inspect(obj, opts) { + // default options + var ctx = { + seen: [], + stylize: stylizeNoColor + }; + // legacy... + if (arguments.length >= 3) ctx.depth = arguments[2]; + if (arguments.length >= 4) ctx.colors = arguments[3]; + if (isBoolean(opts)) { + // legacy... + ctx.showHidden = opts; + } else if (opts) { + // got an "options" object + exports._extend(ctx, opts); + } + // set default options + if (isUndefined(ctx.showHidden)) ctx.showHidden = false; + if (isUndefined(ctx.depth)) ctx.depth = 2; + if (isUndefined(ctx.colors)) ctx.colors = false; + if (isUndefined(ctx.customInspect)) ctx.customInspect = true; + if (ctx.colors) ctx.stylize = stylizeWithColor; + return formatValue(ctx, obj, ctx.depth); +} +exports.inspect = inspect; + - uint_max = Math.pow(2, 32); +// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics +inspect.colors = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [30, 39], + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] +}; - exports.fixup_uint32 = function(x) { - var ret, x_pos; - ret = x > uint_max || x < 0 ? (x_pos = Math.abs(x) % uint_max, x < 0 ? uint_max - x_pos : x_pos) : x; - return ret; - }; +// Don't use 'blue' not visible on cmd.exe +inspect.styles = { + 'special': 'cyan', + 'number': 'yellow', + 'boolean': 'yellow', + 'undefined': 'grey', + 'null': 'bold', + 'string': 'green', + 'date': 'magenta', + // "name": intentionally not styling + 'regexp': 'red' +}; - exports.scrub_buffer = function(b) { - var i, n_full_words; - n_full_words = b.length >> 2; - i = 0; - while (i < n_full_words) { - b.writeUInt32LE(0, i); - i += 4; - } - while (i < b.length) { - b.writeUInt8(0, i); - i++; - } - return false; - }; - exports.scrub_vec = function(v) { - var i, _i, _ref; - for (i = _i = 0, _ref = v.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - v[i] = 0; - } - return false; - }; +function stylizeWithColor(str, styleType) { + var style = inspect.styles[styleType]; - exports.default_delay = default_delay = function(i, n, cb) { - var ___iced_passed_deferral, __iced_deferrals, __iced_k, - _this = this; - __iced_k = __iced_k_noop; - ___iced_passed_deferral = iced.findDeferral(arguments); - (function(__iced_k) { - if (typeof setImmediate !== "undefined" && setImmediate !== null) { - (function(__iced_k) { - __iced_deferrals = new iced.Deferrals(__iced_k, { - parent: ___iced_passed_deferral, - filename: "src/util.iced", - funcname: "default_delay" - }); - setImmediate(__iced_deferrals.defer({ - lineno: 37 - })); - __iced_deferrals._fulfill(); - })(__iced_k); - } else { - (function(__iced_k) { - __iced_deferrals = new iced.Deferrals(__iced_k, { - parent: ___iced_passed_deferral, - filename: "src/util.iced", - funcname: "default_delay" - }); - setTimeout(__iced_deferrals.defer({ - lineno: 39 - }), 1); - __iced_deferrals._fulfill(); - })(__iced_k); - } - })(function() { - return cb(); - }); - }; + if (style) { + return '\u001b[' + inspect.colors[style][0] + 'm' + str + + '\u001b[' + inspect.colors[style][1] + 'm'; + } else { + return str; + } +} - exports.bulk = function(n_input_bytes, _arg, _arg1) { - var call_ph, cb, default_n, delay, finalize, i, left, n, n_words, progress_hook, ret, total_words, update, what, ___iced_passed_deferral, __iced_deferrals, __iced_k, - _this = this; - __iced_k = __iced_k_noop; - ___iced_passed_deferral = iced.findDeferral(arguments); - update = _arg.update, finalize = _arg.finalize, default_n = _arg.default_n; - delay = _arg1.delay, n = _arg1.n, cb = _arg1.cb, what = _arg1.what, progress_hook = _arg1.progress_hook; - i = 0; - left = 0; - total_words = Math.ceil(n_input_bytes / 4); - delay || (delay = default_delay); - n || (n = default_n); - call_ph = function(i) { - return typeof progress_hook === "function" ? progress_hook({ - what: what, - i: i, - total: total_words - }) : void 0; - }; - call_ph(0); - (function(__iced_k) { - var _results, _while; - _results = []; - _while = function(__iced_k) { - var _break, _continue, _next; - _break = function() { - return __iced_k(_results); - }; - _continue = function() { - return iced.trampoline(function() { - return _while(__iced_k); - }); - }; - _next = function(__iced_next_arg) { - _results.push(__iced_next_arg); - return _continue(); - }; - if (!((left = total_words - i) > 0)) { - return _break(); - } else { - n_words = Math.min(n, left); - update(i, i + n_words); - call_ph(i); - (function(__iced_k) { - __iced_deferrals = new iced.Deferrals(__iced_k, { - parent: ___iced_passed_deferral, - filename: "src/util.iced", - funcname: "bulk" - }); - delay(i, total_words, __iced_deferrals.defer({ - lineno: 73 - })); - __iced_deferrals._fulfill(); - })(function() { - return _next(i += n_words); - }); - } - }; - _while(__iced_k); - })(function() { - call_ph(total_words); - ret = finalize(); - return cb(ret); - }); - }; -}).call(this); +function stylizeNoColor(str, styleType) { + return str; +} -},{"iced-coffee-script/lib/coffee-script/iced":9}],38:[function(require,module,exports){ -(function (Buffer){ -// Generated by IcedCoffeeScript 1.6.3-g -(function() { - var WordArray, X64Word, X64WordArray, buffer_to_ui8a, endian_reverse, ui8a_to_buffer, util; +function arrayToHash(array) { + var hash = {}; + array.forEach(function(val, idx) { + hash[val] = true; + }); - util = require('./util'); + return hash; +} - buffer_to_ui8a = function(b) { - var i, ret, _i, _ref; - ret = new Uint8Array(b.length); - for (i = _i = 0, _ref = b.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - ret[i] = b.readUInt8(i); - } - return ret; - }; - ui8a_to_buffer = function(v) { - var i, ret, _i, _ref; - ret = new Buffer(v.length); - for (i = _i = 0, _ref = v.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - ret.writeUInt8(v[i], i); +function formatValue(ctx, value, recurseTimes) { + // Provide a hook for user-specified inspect functions. + // Check that value is an object with an inspect function on it + if (ctx.customInspect && + value && + isFunction(value.inspect) && + // Filter out the util module, it's inspect function is special + value.inspect !== exports.inspect && + // Also filter out any prototype objects using the circular check. + !(value.constructor && value.constructor.prototype === value)) { + var ret = value.inspect(recurseTimes, ctx); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); } return ret; - }; - - endian_reverse = function(x) { - return ((x >>> 24) & 0xff) | (((x >>> 16) & 0xff) << 8) | (((x >>> 8) & 0xff) << 16) | ((x & 0xff) << 24); - }; - - exports.WordArray = WordArray = (function() { - function WordArray(words, sigBytes) { - this.words = words || []; - this.sigBytes = sigBytes != null ? sigBytes : this.words.length * 4; - } - - WordArray.prototype.concat = function(wordArray) { - var i, thatByte, thatSigBytes, thatWords, _i; - thatWords = wordArray.words; - thatSigBytes = wordArray.sigBytes; - this.clamp(); - if (this.sigBytes % 4) { - for (i = _i = 0; 0 <= thatSigBytes ? _i < thatSigBytes : _i > thatSigBytes; i = 0 <= thatSigBytes ? ++_i : --_i) { - thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; - this.words[(this.sigBytes + i) >>> 2] |= thatByte << (24 - ((this.sigBytes + i) % 4) * 8); - } - } else { - this.words = this.words.concat(thatWords); - } - this.sigBytes += thatSigBytes; - return this; - }; - - WordArray.prototype.clamp = function() { - this.words[this.sigBytes >>> 2] &= 0xffffffff << (32 - (this.sigBytes % 4) * 8); - this.words.length = Math.ceil(this.sigBytes / 4); - return this; - }; + } - WordArray.prototype.clone = function() { - return new WordArray(this.words.slice(0), this.sigBytes); - }; + // Primitive types cannot have properties + var primitive = formatPrimitive(ctx, value); + if (primitive) { + return primitive; + } - WordArray.prototype.to_buffer = function() { - var ch, out, p, w, _i, _len, _ref; - out = new Buffer(this.sigBytes); - p = 0; - _ref = this.words; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - w = _ref[_i]; - if (!((this.sigBytes - p) >= 4)) { - continue; - } - w = util.fixup_uint32(w); - out.writeUInt32BE(w, p); - p += 4; - } - while (p < this.sigBytes) { - ch = (this.words[p >>> 2] >>> (24 - (p % 4) * 8)) & 0xff; - out.writeUInt8(ch, p); - p++; - } - return out; - }; + // Look up the keys of the object. + var keys = Object.keys(value); + var visibleKeys = arrayToHash(keys); - WordArray.prototype.endian_reverse = function() { - var i, w, _i, _len, _ref; - _ref = this.words; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - w = _ref[i]; - this.words[i] = endian_reverse(w); - } - return this; - }; + if (ctx.showHidden) { + keys = Object.getOwnPropertyNames(value); + } - WordArray.prototype.split = function(n) { - var i, out, sz; - if (!(((this.sigBytes % 4) === 0) && ((this.words.length % n) === 0))) { - throw new Error("bad key alignment"); - } - sz = this.words.length / n; - out = (function() { - var _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = this.words.length; sz > 0 ? _i < _ref : _i > _ref; i = _i += sz) { - _results.push(new WordArray(this.words.slice(i, i + sz))); - } - return _results; - }).call(this); - return out; - }; + // IE doesn't make error fields non-enumerable + // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx + if (isError(value) + && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { + return formatError(value); + } - WordArray.prototype.to_utf8 = function() { - return this.to_buffer().toString('utf8'); - }; + // Some type of object without properties can be shortcutted. + if (keys.length === 0) { + if (isFunction(value)) { + var name = value.name ? ': ' + value.name : ''; + return ctx.stylize('[Function' + name + ']', 'special'); + } + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } + if (isDate(value)) { + return ctx.stylize(Date.prototype.toString.call(value), 'date'); + } + if (isError(value)) { + return formatError(value); + } + } - WordArray.prototype.to_hex = function() { - return this.to_buffer().toString('hex'); - }; + var base = '', array = false, braces = ['{', '}']; - WordArray.prototype.to_ui8a = function() { - return buffer_to_ui8a(this.to_buffer()); - }; + // Make Array say that they are Array + if (isArray(value)) { + array = true; + braces = ['[', ']']; + } - WordArray.alloc = function(b) { - if (Buffer.isBuffer(b)) { - return WordArray.from_buffer(b); - } else if ((typeof b === 'object') && (b instanceof WordArray)) { - return b; - } else if (typeof b === 'string') { - return WordArray.from_hex(b); - } else { - return null; - } - }; + // Make functions say that they are functions + if (isFunction(value)) { + var n = value.name ? ': ' + value.name : ''; + base = ' [Function' + n + ']'; + } - WordArray.from_buffer = function(b) { - var ch, last, p, words; - words = []; - p = 0; - while ((b.length - p) >= 4) { - words.push(b.readUInt32BE(p)); - p += 4; - } - if (p < b.length) { - last = 0; - while (p < b.length) { - ch = b.readUInt8(p); - last |= ch << (24 - (p % 4) * 8); - p++; - } - last = util.fixup_uint32(last); - words.push(last); - } - return new WordArray(words, b.length); - }; + // Make RegExps say that they are RegExps + if (isRegExp(value)) { + base = ' ' + RegExp.prototype.toString.call(value); + } - WordArray.from_buffer_le = function(b) { - var ch, last, p, words; - words = []; - p = 0; - while ((b.length - p) >= 4) { - words.push(b.readUInt32LE(p)); - p += 4; - } - if (p < b.length) { - last = 0; - while (p < b.length) { - ch = b.readUInt8(p); - last |= ch << ((p % 4) * 8); - p++; - } - last = util.fixup_uint32(last); - words.push(last); - } - return new WordArray(words, b.length); - }; + // Make dates with properties first say the date + if (isDate(value)) { + base = ' ' + Date.prototype.toUTCString.call(value); + } - WordArray.from_utf8 = function(s) { - return WordArray.from_buffer(new Buffer(s, 'utf8')); - }; + // Make error with message first say the error + if (isError(value)) { + base = ' ' + formatError(value); + } - WordArray.from_utf8_le = function(s) { - return WordArray.from_buffer_le(new Buffer(s, 'utf8')); - }; + if (keys.length === 0 && (!array || value.length == 0)) { + return braces[0] + base + braces[1]; + } - WordArray.from_hex = function(s) { - return WordArray.from_buffer(new Buffer(s, 'hex')); - }; + if (recurseTimes < 0) { + if (isRegExp(value)) { + return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); + } else { + return ctx.stylize('[Object]', 'special'); + } + } - WordArray.from_hex_le = function(s) { - return WordArray.from_buffer_le(new Buffer(s, 'hex')); - }; + ctx.seen.push(value); - WordArray.from_ui8a = function(v) { - return WordArray.from_buffer(ui8a_to_buffer(v)); - }; + var output; + if (array) { + output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); + } else { + output = keys.map(function(key) { + return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); + }); + } - WordArray.from_i32a = function(v) { - return new WordArray(Array.apply([], v)); - }; + ctx.seen.pop(); - WordArray.prototype.equal = function(wa) { - var i, ret, w, _i, _len, _ref; - ret = true; - if (wa.sigBytes !== this.sigBytes) { - ret = false; - } else { - _ref = this.words; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - w = _ref[i]; - if (util.fixup_uint32(w) !== util.fixup_uint32(wa.words[i])) { - ret = false; - } - } - } - return ret; - }; + return reduceToSingleString(output, base, braces); +} - WordArray.prototype.xor = function(wa2, _arg) { - var dst_offset, i, n_words, src_offset, tmp, _i; - dst_offset = _arg.dst_offset, src_offset = _arg.src_offset, n_words = _arg.n_words; - if (!dst_offset) { - dst_offset = 0; - } - if (!src_offset) { - src_offset = 0; - } - if (n_words == null) { - n_words = wa2.words.length - src_offset; - } - if (this.words.length < dst_offset + n_words) { - throw new Error("dest range exceeded (" + this.words.length + " < " + (dst_offset + n_words) + ")"); - } - if (wa2.words.length < src_offset + n_words) { - throw new Error("source range exceeded"); - } - for (i = _i = 0; 0 <= n_words ? _i < n_words : _i > n_words; i = 0 <= n_words ? ++_i : --_i) { - tmp = this.words[dst_offset + i] ^ wa2.words[src_offset + i]; - this.words[dst_offset + i] = util.fixup_uint32(tmp); - } - return this; - }; - WordArray.prototype.truncate = function(n_bytes) { - var n_words; - if (!(n_bytes <= this.sigBytes)) { - throw new Error("Cannot truncate: " + n_bytes + " > " + this.sigBytes); - } - n_words = Math.ceil(n_bytes / 4); - return new WordArray(this.words.slice(0, n_words), n_bytes); - }; +function formatPrimitive(ctx, value) { + if (isUndefined(value)) + return ctx.stylize('undefined', 'undefined'); + if (isString(value)) { + var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') + .replace(/'/g, "\\'") + .replace(/\\"/g, '"') + '\''; + return ctx.stylize(simple, 'string'); + } + if (isNumber(value)) + return ctx.stylize('' + value, 'number'); + if (isBoolean(value)) + return ctx.stylize('' + value, 'boolean'); + // For some reason typeof null is "object", so special case here. + if (isNull(value)) + return ctx.stylize('null', 'null'); +} + - WordArray.prototype.unshift = function(n_words) { - var ret; - if (this.words.length >= n_words) { - ret = this.words.splice(0, n_words); - this.sigBytes -= n_words * 4; - return new WordArray(ret); - } else { - return null; - } - }; +function formatError(value) { + return '[' + Error.prototype.toString.call(value) + ']'; +} - WordArray.prototype.is_scrubbed = function() { - var w, _i, _len, _ref; - _ref = this.words; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - w = _ref[_i]; - if (w !== 0) { - return false; - } - } - return true; - }; - WordArray.prototype.scrub = function() { - return util.scrub_vec(this.words); - }; +function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { + var output = []; + for (var i = 0, l = value.length; i < l; ++i) { + if (hasOwnProperty(value, String(i))) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + String(i), true)); + } else { + output.push(''); + } + } + keys.forEach(function(key) { + if (!key.match(/^\d+$/)) { + output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, + key, true)); + } + }); + return output; +} - WordArray.prototype.slice = function(low, hi) { - var n, sb; - n = this.words.length; - if (!((low < hi) && (hi <= n))) { - throw new Error("Bad WordArray slice [" + low + "," + hi + ")] when only " + n + " avail"); + +function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { + var name, str, desc; + desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; + if (desc.get) { + if (desc.set) { + str = ctx.stylize('[Getter/Setter]', 'special'); + } else { + str = ctx.stylize('[Getter]', 'special'); + } + } else { + if (desc.set) { + str = ctx.stylize('[Setter]', 'special'); + } + } + if (!hasOwnProperty(visibleKeys, key)) { + name = '[' + key + ']'; + } + if (!str) { + if (ctx.seen.indexOf(desc.value) < 0) { + if (isNull(recurseTimes)) { + str = formatValue(ctx, desc.value, null); + } else { + str = formatValue(ctx, desc.value, recurseTimes - 1); } - sb = (hi - low) * 4; - if (hi === n) { - sb -= n * 4 - this.sigBytes; + if (str.indexOf('\n') > -1) { + if (array) { + str = str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n').substr(2); + } else { + str = '\n' + str.split('\n').map(function(line) { + return ' ' + line; + }).join('\n'); + } } - return new WordArray(this.words.slice(low, hi), sb); - }; + } else { + str = ctx.stylize('[Circular]', 'special'); + } + } + if (isUndefined(name)) { + if (array && key.match(/^\d+$/)) { + return str; + } + name = JSON.stringify('' + key); + if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { + name = name.substr(1, name.length - 2); + name = ctx.stylize(name, 'name'); + } else { + name = name.replace(/'/g, "\\'") + .replace(/\\"/g, '"') + .replace(/(^"|"$)/g, "'"); + name = ctx.stylize(name, 'string'); + } + } - return WordArray; + return name + ': ' + str; +} - })(); - exports.X64Word = X64Word = (function() { - function X64Word(high, low) { - this.high = high; - this.low = low; - } +function reduceToSingleString(output, base, braces) { + var numLinesEst = 0; + var length = output.reduce(function(prev, cur) { + numLinesEst++; + if (cur.indexOf('\n') >= 0) numLinesEst++; + return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; + }, 0); - X64Word.prototype.clone = function() { - return new X64Word(this.high, this.low); - }; + if (length > 60) { + return braces[0] + + (base === '' ? '' : base + '\n ') + + ' ' + + output.join(',\n ') + + ' ' + + braces[1]; + } - return X64Word; + return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; +} - })(); - exports.X64WordArray = X64WordArray = (function() { - function X64WordArray(words, sigBytes) { - this.sigBytes = sigBytes; - this.words = words || []; - if (!this.sigBytes) { - this.sigBytes = this.words.length * 8; - } - } +// NOTE: These type checking functions intentionally don't use `instanceof` +// because it is fragile and can be easily faked with `Object.create()`. +function isArray(ar) { + return Array.isArray(ar); +} +exports.isArray = isArray; - X64WordArray.prototype.toX32 = function() { - var v, w, _i, _len, _ref; - v = []; - _ref = this.words; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - w = _ref[_i]; - v.push(w.high); - v.push(w.low); - } - return new WordArray(v, this.sigBytes); - }; +function isBoolean(arg) { + return typeof arg === 'boolean'; +} +exports.isBoolean = isBoolean; - X64WordArray.prototype.clone = function() { - var w; - return new X64WordArray((function() { - var _i, _len, _ref, _results; - _ref = this.words; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - w = _ref[_i]; - _results.push(w.clone()); - } - return _results; - }).call(this), this.sigBytes); - }; +function isNull(arg) { + return arg === null; +} +exports.isNull = isNull; - return X64WordArray; +function isNullOrUndefined(arg) { + return arg == null; +} +exports.isNullOrUndefined = isNullOrUndefined; - })(); +function isNumber(arg) { + return typeof arg === 'number'; +} +exports.isNumber = isNumber; - exports.buffer_to_ui8a = buffer_to_ui8a; +function isString(arg) { + return typeof arg === 'string'; +} +exports.isString = isString; - exports.ui8a_to_buffer = ui8a_to_buffer; +function isSymbol(arg) { + return typeof arg === 'symbol'; +} +exports.isSymbol = isSymbol; - exports.endian_reverse = endian_reverse; +function isUndefined(arg) { + return arg === void 0; +} +exports.isUndefined = isUndefined; -}).call(this); +function isRegExp(re) { + return isObject(re) && objectToString(re) === '[object RegExp]'; +} +exports.isRegExp = isRegExp; -}).call(this,require("buffer").Buffer) -},{"./util":37,"buffer":1}],39:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.7.1-f -(function() { - var Generator, iced, __iced_k, __iced_k_noop; +function isObject(arg) { + return typeof arg === 'object' && arg !== null; +} +exports.isObject = isObject; - iced = require('iced-runtime'); - __iced_k = __iced_k_noop = function() {}; +function isDate(d) { + return isObject(d) && objectToString(d) === '[object Date]'; +} +exports.isDate = isDate; - Generator = Generator = (function() { - function Generator(opts) { - opts = opts || {}; - this.lazy_loop_delay = opts.lazy_loop_delay || 30; - this.loop_delay = opts.loop_delay || 5; - this.work_min = opts.work_min || 1; - this.auto_stop_bits = opts.auto_stop_bits || 4096; - this.max_bits_per_delta = opts.max_bits_per_delta || 4; - this.auto_stop = opts.auto_stop ? opts.auto_stop : true; - this.entropies = []; - this.running = true; - this.is_generating = false; - this.timer_race_loop(); - } +function isError(e) { + return isObject(e) && + (objectToString(e) === '[object Error]' || e instanceof Error); +} +exports.isError = isError; - Generator.prototype.generate = function(bits_wanted, cb) { - var e, harvested_bits, res, ___iced_passed_deferral, __iced_deferrals, __iced_k; - __iced_k = __iced_k_noop; - ___iced_passed_deferral = iced.findDeferral(arguments); - this.is_generating = true; - if (!this.running) { - this.resume(); - } - harvested_bits = 0; - res = []; - (function(_this) { - return (function(__iced_k) { - var _results, _while; - _results = []; - _while = function(__iced_k) { - var _break, _continue, _next; - _break = function() { - return __iced_k(_results); - }; - _continue = function() { - return iced.trampoline(function() { - return _while(__iced_k); - }); - }; - _next = function(__iced_next_arg) { - _results.push(__iced_next_arg); - return _continue(); - }; - if (!(harvested_bits < bits_wanted)) { - return _break(); - } else { - (function(__iced_k) { - if (_this.entropies.length) { - e = _this.entropies.splice(0, 1)[0]; - harvested_bits += e[1]; - return __iced_k(res.push(e[0])); - } else { - (function(__iced_k) { - __iced_deferrals = new iced.Deferrals(__iced_k, { - parent: ___iced_passed_deferral, - filename: "/Users/chris/git/more-entropy/src/generator.iced", - funcname: "Generator.generate" - }); - _this.delay(__iced_deferrals.defer({ - lineno: 28 - })); - __iced_deferrals._fulfill(); - })(__iced_k); - } - })(_next); - } - }; - _while(__iced_k); - }); - })(this)((function(_this) { - return function() { - if (_this.auto_stop) { - _this.stop(); - } - _this.is_generating = false; - return cb(res); - }; - })(this)); - }; +function isFunction(arg) { + return typeof arg === 'function'; +} +exports.isFunction = isFunction; - Generator.prototype.stop = function() { - return this.running = false; - }; +function isPrimitive(arg) { + return arg === null || + typeof arg === 'boolean' || + typeof arg === 'number' || + typeof arg === 'string' || + typeof arg === 'symbol' || // ES6 symbol + typeof arg === 'undefined'; +} +exports.isPrimitive = isPrimitive; - Generator.prototype.resume = function() { - this.running = true; - return this.timer_race_loop(); - }; +exports.isBuffer = require('./support/isBuffer'); - Generator.prototype.reset = function() { - this.entropies = []; - return this.total_bits = 0; - }; +function objectToString(o) { + return Object.prototype.toString.call(o); +} - Generator.prototype.count_unused_bits = function() { - var bits, e, _i, _len, _ref; - bits = 0; - _ref = this.entropies; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - e = _ref[_i]; - bits += e[1]; - } - return bits; - }; - Generator.prototype.delay = function(cb) { - var delay, ___iced_passed_deferral, __iced_deferrals, __iced_k; - __iced_k = __iced_k_noop; - ___iced_passed_deferral = iced.findDeferral(arguments); - delay = this.is_generating ? this.loop_delay : this.lazy_loop_delay; - (function(_this) { - return (function(__iced_k) { - __iced_deferrals = new iced.Deferrals(__iced_k, { - parent: ___iced_passed_deferral, - filename: "/Users/chris/git/more-entropy/src/generator.iced", - funcname: "Generator.delay" - }); - setTimeout(__iced_deferrals.defer({ - lineno: 50 - }), delay); - __iced_deferrals._fulfill(); - }); - })(this)((function(_this) { - return function() { - return cb(); - }; - })(this)); - }; +function pad(n) { + return n < 10 ? '0' + n.toString(10) : n.toString(10); +} - Generator.prototype.timer_race_loop = function() { - var ___iced_passed_deferral, __iced_k, _results, _while; - __iced_k = __iced_k_noop; - ___iced_passed_deferral = iced.findDeferral(arguments); - this._last_count = null; - _results = []; - _while = (function(_this) { - var count, delta, entropy, v, __iced_deferrals; - return function(__iced_k) { - var _break, _continue, _next; - _break = function() { - return __iced_k(_results); - }; - _continue = function() { - return iced.trampoline(function() { - return _while(__iced_k); - }); - }; - _next = function(__iced_next_arg) { - _results.push(__iced_next_arg); - return _continue(); - }; - if (!_this.running) { - return _break(); - } else { - if (_this.count_unused_bits() < _this.auto_stop_bits) { - count = _this.millisecond_count(); - if ((_this._last_count != null) && (delta = count - _this._last_count)) { - entropy = Math.floor(_this.log_2(Math.abs(delta))); - entropy = Math.min(_this.max_bits_per_delta, entropy); - v = [delta, entropy]; - _this.entropies.push(v); - } - _this._last_count = count; - } - (function(__iced_k) { - __iced_deferrals = new iced.Deferrals(__iced_k, { - parent: ___iced_passed_deferral, - filename: "/Users/chris/git/more-entropy/src/generator.iced", - funcname: "Generator.timer_race_loop" - }); - _this.delay(__iced_deferrals.defer({ - lineno: 64 - })); - __iced_deferrals._fulfill(); - })(_next); - } - }; - })(this); - _while(__iced_k); - }; - Generator.prototype.log_2 = function(x) { - return Math.log(x) / Math.LN2; - }; +var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', + 'Oct', 'Nov', 'Dec']; - Generator.prototype.millisecond_count = function() { - var d, i, x; - d = Date.now(); - i = x = 0; - while (Date.now() < d + this.work_min + 1) { - i++; - x = Math.sin(Math.sqrt(Math.log(i + x))); - } - return i; - }; +// 26 Feb 16:19:34 +function timestamp() { + var d = new Date(); + var time = [pad(d.getHours()), + pad(d.getMinutes()), + pad(d.getSeconds())].join(':'); + return [d.getDate(), months[d.getMonth()], time].join(' '); +} - return Generator; - })(); +// log is just a thin wrapper to console.log that prepends a timestamp +exports.log = function() { + console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); +}; - if (typeof window !== "undefined" && window !== null) { - window.Generator = Generator; - } - if (typeof exports !== "undefined" && exports !== null) { - exports.Generator = Generator; - } +/** + * Inherit the prototype methods from one constructor into another. + * + * The Function.prototype.inherits from lang.js rewritten as a standalone + * function (not on Function.prototype). NOTE: If this file is to be loaded + * during bootstrapping this function needs to be rewritten using some native + * functions as prototype setup using normal JavaScript does not work as + * expected during bootstrapping (see mirror.js in r114903). + * + * @param {function} ctor Constructor function which needs to inherit the + * prototype. + * @param {function} superCtor Constructor function to inherit prototype from. + */ +exports.inherits = require('inherits'); -}).call(this); +exports._extend = function(origin, add) { + // Don't do anything if add isn't an object + if (!add || !isObject(add)) return origin; -},{"iced-runtime":13}],40:[function(require,module,exports){ -// Generated by IcedCoffeeScript 1.7.1-c -(function() { - exports.Generator = require('../lib/generator').Generator; + var keys = Object.keys(add); + var i = keys.length; + while (i--) { + origin[keys[i]] = add[keys[i]]; + } + return origin; +}; -}).call(this); +function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); +} -},{"../lib/generator":39}],41:[function(require,module,exports){ +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./support/isBuffer":37,"_process":13,"inherits":36}],39:[function(require,module,exports){ (function (Buffer){ var HMAC_SHA256, WordArray, from_utf8, generate, iced, params, pbkdf2, run, scrypt, util, __iced_k, __iced_k_noop, _ref; @@ -11742,7 +12065,7 @@ exports.run = run = function(_arg, cb) { }; }).call(this,require("buffer").Buffer) -},{"../json/params.json":42,"buffer":1,"iced-runtime":13,"keybase-bitcoin":15,"triplesec":26}],42:[function(require,module,exports){ +},{"../json/params.json":40,"buffer":2,"iced-runtime":6,"keybase-bitcoin":9,"triplesec":23}],40:[function(require,module,exports){ module.exports={ "N" : 18, "p" : 1, @@ -11751,5 +12074,24 @@ module.exports={ "pbkdf2c" : 65536 } -},{}]},{},[41])(41) +},{}],41:[function(require,module,exports){ +// Generated by IcedCoffeeScript 108.0.11 +(function() { + exports.transform = function(x, options) { + return x.icedTransform(options); + }; + + exports.runtime = require('iced-runtime'); + +}).call(this); + +},{"iced-runtime":44}],42:[function(require,module,exports){ +arguments[4][4][0].apply(exports,arguments) +},{"dup":4}],43:[function(require,module,exports){ +arguments[4][5][0].apply(exports,arguments) +},{"./const":42,"./runtime":45,"dup":5}],44:[function(require,module,exports){ +arguments[4][6][0].apply(exports,arguments) +},{"./const":42,"./library":43,"./runtime":45,"dup":6}],45:[function(require,module,exports){ +arguments[4][7][0].apply(exports,arguments) +},{"./const":42,"_process":13,"dup":7}]},{},[39])(39) }); \ No newline at end of file diff --git a/warp_src.html b/warp_src.html index 7d79e73..dd01db0 100644 --- a/warp_src.html +++ b/warp_src.html @@ -118,7 +118,7 @@

WarpWallet

- +
@@ -127,7 +127,7 @@

WarpWallet

-