+
+ Mnemonics with less than 12 words have low entropy and may be guessed by an attacker.
+
+
@@ -6970,6 +6975,11 @@ button.close {
+
+
+ The mnemonic will appear more secure than it really is.
+
+
@@ -7460,13 +7470,25 @@ button.close {
Derived Addresses
Note these addresses are derived from the BIP32 Extended Key
-
-
+
+
+
+
+
+
+
+
@@ -7475,7 +7497,7 @@ button.close {
Encrypt private keys using BIP38 and this password:
- Enabling BIP38 means each key will take take several minutes to generate.
+ Enabling BIP38 means each key will take several minutes to generate.
@@ -33218,19 +33240,13 @@ function hasOwnProperty(obj, prop) {
}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./support/isBuffer":32,"_process":13,"inherits":31}],34:[function(require,module,exports){
-bitcoin = {
- base58: require('bs58'),
- bitcoin: require('bitcoinjs-lib'),
- ecurve: require('ecurve'),
- BigInteger: require('bigi'),
- Buffer: require('buffer'),
- elliptic: require('elliptic'),
- bs58check: require('bs58check'),
-}
+let bitcoin = require('bitcoinjs-lib');
-module.exports = bitcoin;
+module.exports = {
+ bitcoin
+}
-},{"bigi":39,"bitcoinjs-lib":52,"bs58":83,"bs58check":85,"buffer":5,"ecurve":94,"elliptic":97}],35:[function(require,module,exports){
+},{"bitcoinjs-lib":52}],35:[function(require,module,exports){
// base-x encoding
// Forked from https://github.com/cryptocoinjs/bs58
// Originally written by Mike Hearn for BitcoinJ
@@ -33274,7 +33290,7 @@ module.exports = function base (ALPHABET) {
var string = ''
// deal with leading zeros
- for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += ALPHABET[0]
+ for (var k = 0; source[k] === 0 && k < source.length - 1; ++k) string += LEADER
// convert digits to a string
for (var q = digits.length - 1; q >= 0; --q) string += ALPHABET[digits[q]]
@@ -33282,6 +33298,7 @@ module.exports = function base (ALPHABET) {
}
function decodeUnsafe (string) {
+ if (typeof string !== 'string') throw new TypeError('Expected String')
if (string.length === 0) return Buffer.allocUnsafe(0)
var bytes = [0]
@@ -33323,21 +33340,21 @@ module.exports = function base (ALPHABET) {
}
}
-},{"safe-buffer":128}],36:[function(require,module,exports){
+},{"safe-buffer":101}],36:[function(require,module,exports){
'use strict'
-let ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
+var ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
// pre-compute lookup table
-let ALPHABET_MAP = {}
-for (let z = 0; z < ALPHABET.length; z++) {
- let x = ALPHABET.charAt(z)
+var ALPHABET_MAP = {}
+for (var z = 0; z < ALPHABET.length; z++) {
+ var x = ALPHABET.charAt(z)
if (ALPHABET_MAP[x] !== undefined) throw new TypeError(x + ' is ambiguous')
ALPHABET_MAP[x] = z
}
function polymodStep (pre) {
- let b = pre >> 25
+ var b = pre >> 25
return ((pre & 0x1FFFFFF) << 5) ^
(-((b >> 0) & 1) & 0x3b6a57b2) ^
(-((b >> 1) & 1) & 0x26508e6d) ^
@@ -33347,73 +33364,76 @@ function polymodStep (pre) {
}
function prefixChk (prefix) {
- let chk = 1
- for (let i = 0; i < prefix.length; ++i) {
- let c = prefix.charCodeAt(i)
+ var chk = 1
+ for (var i = 0; i < prefix.length; ++i) {
+ var c = prefix.charCodeAt(i)
if (c < 33 || c > 126) throw new Error('Invalid prefix (' + prefix + ')')
chk = polymodStep(chk) ^ (c >> 5)
}
chk = polymodStep(chk)
- for (let i = 0; i < prefix.length; ++i) {
- let v = prefix.charCodeAt(i)
+ for (i = 0; i < prefix.length; ++i) {
+ var v = prefix.charCodeAt(i)
chk = polymodStep(chk) ^ (v & 0x1f)
}
return chk
}
-function encode (prefix, words) {
- // too long?
- if ((prefix.length + 7 + words.length) > 90) throw new TypeError('Exceeds Bech32 maximum length')
+function encode (prefix, words, LIMIT) {
+ LIMIT = LIMIT || 90
+ if ((prefix.length + 7 + words.length) > LIMIT) throw new TypeError('Exceeds length limit')
+
prefix = prefix.toLowerCase()
// determine chk mod
- let chk = prefixChk(prefix)
- let result = prefix + '1'
- for (let i = 0; i < words.length; ++i) {
- let x = words[i]
+ var chk = prefixChk(prefix)
+ var result = prefix + '1'
+ for (var i = 0; i < words.length; ++i) {
+ var x = words[i]
if ((x >> 5) !== 0) throw new Error('Non 5-bit word')
chk = polymodStep(chk) ^ x
result += ALPHABET.charAt(x)
}
- for (let i = 0; i < 6; ++i) {
+ for (i = 0; i < 6; ++i) {
chk = polymodStep(chk)
}
chk ^= 1
- for (let i = 0; i < 6; ++i) {
- let v = (chk >> ((5 - i) * 5)) & 0x1f
+ for (i = 0; i < 6; ++i) {
+ var v = (chk >> ((5 - i) * 5)) & 0x1f
result += ALPHABET.charAt(v)
}
return result
}
-function decode (str) {
+function decode (str, LIMIT) {
+ LIMIT = LIMIT || 90
if (str.length < 8) throw new TypeError(str + ' too short')
- if (str.length > 90) throw new TypeError(str + ' too long')
+ if (str.length > LIMIT) throw new TypeError('Exceeds length limit')
// don't allow mixed case
- let lowered = str.toLowerCase()
- let uppered = str.toUpperCase()
+ var lowered = str.toLowerCase()
+ var uppered = str.toUpperCase()
if (str !== lowered && str !== uppered) throw new Error('Mixed-case string ' + str)
str = lowered
- let split = str.lastIndexOf('1')
+ var split = str.lastIndexOf('1')
+ if (split === -1) throw new Error('No separator character for ' + str)
if (split === 0) throw new Error('Missing prefix for ' + str)
- let prefix = str.slice(0, split)
- let wordChars = str.slice(split + 1)
+ var prefix = str.slice(0, split)
+ var wordChars = str.slice(split + 1)
if (wordChars.length < 6) throw new Error('Data too short')
- let chk = prefixChk(prefix)
- let words = []
- for (let i = 0; i < wordChars.length; ++i) {
- let c = wordChars.charAt(i)
- let v = ALPHABET_MAP[c]
+ var chk = prefixChk(prefix)
+ var words = []
+ for (var i = 0; i < wordChars.length; ++i) {
+ var c = wordChars.charAt(i)
+ var v = ALPHABET_MAP[c]
if (v === undefined) throw new Error('Unknown character ' + c)
chk = polymodStep(chk) ^ v
@@ -33423,16 +33443,16 @@ function decode (str) {
}
if (chk !== 1) throw new Error('Invalid checksum for ' + str)
- return { prefix, words }
+ return { prefix: prefix, words: words }
}
function convert (data, inBits, outBits, pad) {
- let value = 0
- let bits = 0
- let maxV = (1 << outBits) - 1
+ var value = 0
+ var bits = 0
+ var maxV = (1 << outBits) - 1
- let result = []
- for (let i = 0; i < data.length; ++i) {
+ var result = []
+ for (var i = 0; i < data.length; ++i) {
value = (value << inBits) | data[i]
bits += inBits
@@ -33462,7 +33482,12 @@ function fromWords (words) {
return convert(words, 5, 8, false)
}
-module.exports = { decode, encode, toWords, fromWords }
+module.exports = {
+ decode: decode,
+ encode: encode,
+ toWords: toWords,
+ fromWords: fromWords
+}
},{}],37:[function(require,module,exports){
// (public) Constructor
@@ -35081,11 +35106,11 @@ module.exports = BigInteger
module.exports={
"_args": [
[
- "bigi",
- "/home/ian/git/bitcoin/bitcoinjs-lib-browser"
+ "bigi@^1.4.0",
+ "/home/ian/git/bitcoin/bitcoinjs-lib-browser/node_modules/bitcoinjs-lib"
]
],
- "_from": "bigi@latest",
+ "_from": "bigi@>=1.4.0 <2.0.0",
"_id": "bigi@1.4.2",
"_inCache": true,
"_installable": true,
@@ -35103,22 +35128,21 @@ module.exports={
"_phantomChildren": {},
"_requested": {
"name": "bigi",
- "raw": "bigi",
- "rawSpec": "",
+ "raw": "bigi@^1.4.0",
+ "rawSpec": "^1.4.0",
"scope": null,
- "spec": "latest",
- "type": "tag"
+ "spec": ">=1.4.0 <2.0.0",
+ "type": "range"
},
"_requiredBy": [
- "#USER",
"/bitcoinjs-lib",
"/ecurve"
],
"_resolved": "https://registry.npmjs.org/bigi/-/bigi-1.4.2.tgz",
"_shasum": "9c665a95f88b8b08fc05cfd731f561859d725825",
"_shrinkwrap": null,
- "_spec": "bigi",
- "_where": "/home/ian/git/bitcoin/bitcoinjs-lib-browser",
+ "_spec": "bigi@^1.4.0",
+ "_where": "/home/ian/git/bitcoin/bitcoinjs-lib-browser/node_modules/bitcoinjs-lib",
"bugs": {
"url": "https://github.com/cryptocoinjs/bigi/issues"
},
@@ -35319,7 +35343,7 @@ module.exports = {
encode: encode
}
-},{"safe-buffer":128}],42:[function(require,module,exports){
+},{"safe-buffer":101}],42:[function(require,module,exports){
module.exports={
"OP_FALSE": 0,
"OP_0": 0,
@@ -35328,8 +35352,8 @@ module.exports={
"OP_PUSHDATA4": 78,
"OP_1NEGATE": 79,
"OP_RESERVED": 80,
- "OP_1": 81,
"OP_TRUE": 81,
+ "OP_1": 81,
"OP_2": 82,
"OP_3": 83,
"OP_4": 84,
@@ -35434,10 +35458,13 @@ module.exports={
"OP_CHECKMULTISIGVERIFY": 175,
"OP_NOP1": 176,
+
"OP_NOP2": 177,
"OP_CHECKLOCKTIMEVERIFY": 177,
"OP_NOP3": 178,
+ "OP_CHECKSEQUENCEVERIFY": 178,
+
"OP_NOP4": 179,
"OP_NOP5": 180,
"OP_NOP6": 181,
@@ -35497,13 +35524,24 @@ function fromBech32 (address) {
}
function toBase58Check (hash, version) {
- typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments)
+ if (version < 256){
+ typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments)
- var payload = Buffer.allocUnsafe(21)
- payload.writeUInt8(version, 0)
- hash.copy(payload, 1)
+ var payload = Buffer.allocUnsafe(21)
+ payload.writeUInt8(version, 0)
+ hash.copy(payload, 1)
- return bs58check.encode(payload)
+ return bs58check.encode(payload)
+ }
+ else{
+ typeforce(types.tuple(types.Hash160bit, types.UInt16), arguments)
+
+ var payload = Buffer.allocUnsafe(22)
+ payload.writeUInt16BE(version, 0)
+ hash.copy(payload, 2)
+
+ return bs58check.encode(payload)
+ }
}
function toBech32 (data, version, prefix) {
@@ -35561,7 +35599,7 @@ module.exports = {
toOutputScript: toOutputScript
}
-},{"./networks":53,"./script":54,"./templates":56,"./types":80,"bech32":36,"bs58check":85,"safe-buffer":128,"typeforce":139}],45:[function(require,module,exports){
+},{"./networks":53,"./script":54,"./templates":56,"./types":80,"bech32":36,"bs58check":83,"safe-buffer":101,"typeforce":112}],45:[function(require,module,exports){
var Buffer = require('safe-buffer').Buffer
var bcrypto = require('./crypto')
var fastMerkleRoot = require('merkle-lib/fastRoot')
@@ -35740,7 +35778,7 @@ Block.prototype.checkProofOfWork = function () {
module.exports = Block
-},{"./crypto":47,"./transaction":78,"./types":80,"merkle-lib/fastRoot":122,"safe-buffer":128,"typeforce":139,"varuint-bitcoin":141}],46:[function(require,module,exports){
+},{"./crypto":47,"./transaction":78,"./types":80,"merkle-lib/fastRoot":97,"safe-buffer":101,"typeforce":112,"varuint-bitcoin":114}],46:[function(require,module,exports){
var pushdata = require('pushdata-bitcoin')
var varuint = require('varuint-bitcoin')
@@ -35798,7 +35836,7 @@ module.exports = {
writeVarInt: writeVarInt
}
-},{"pushdata-bitcoin":125,"varuint-bitcoin":141}],47:[function(require,module,exports){
+},{"pushdata-bitcoin":98,"varuint-bitcoin":114}],47:[function(require,module,exports){
var createHash = require('create-hash')
function ripemd160 (buffer) {
@@ -35829,7 +35867,7 @@ module.exports = {
sha256: sha256
}
-},{"create-hash":87}],48:[function(require,module,exports){
+},{"create-hash":85}],48:[function(require,module,exports){
var Buffer = require('safe-buffer').Buffer
var createHmac = require('create-hmac')
var typeforce = require('typeforce')
@@ -35992,7 +36030,7 @@ module.exports = {
__curve: secp256k1
}
-},{"./ecsignature":50,"./types":80,"bigi":39,"create-hmac":90,"ecurve":94,"safe-buffer":128,"typeforce":139}],49:[function(require,module,exports){
+},{"./ecsignature":50,"./types":80,"bigi":39,"create-hmac":88,"ecurve":92,"safe-buffer":101,"typeforce":112}],49:[function(require,module,exports){
var baddress = require('./address')
var bcrypto = require('./crypto')
var ecdsa = require('./ecdsa')
@@ -36125,7 +36163,7 @@ ECPair.prototype.verify = function (hash, signature) {
module.exports = ECPair
-},{"./address":44,"./crypto":47,"./ecdsa":48,"./networks":53,"./types":80,"bigi":39,"ecurve":94,"randombytes":126,"typeforce":139,"wif":142}],50:[function(require,module,exports){
+},{"./address":44,"./crypto":47,"./ecdsa":48,"./networks":53,"./types":80,"bigi":39,"ecurve":92,"randombytes":99,"typeforce":112,"wif":115}],50:[function(require,module,exports){
(function (Buffer){
var bip66 = require('bip66')
var typeforce = require('typeforce')
@@ -36226,7 +36264,7 @@ ECSignature.prototype.toScriptSignature = function (hashType) {
module.exports = ECSignature
}).call(this,require("buffer").Buffer)
-},{"./types":80,"bigi":39,"bip66":41,"buffer":5,"typeforce":139}],51:[function(require,module,exports){
+},{"./types":80,"bigi":39,"bip66":41,"buffer":5,"typeforce":112}],51:[function(require,module,exports){
var Buffer = require('safe-buffer').Buffer
var base58check = require('bs58check')
var bcrypto = require('./crypto')
@@ -36544,7 +36582,7 @@ HDNode.prototype.derivePath = function (path) {
module.exports = HDNode
-},{"./crypto":47,"./ecpair":49,"./networks":53,"./types":80,"bigi":39,"bs58check":85,"create-hmac":90,"ecurve":94,"safe-buffer":128,"typeforce":139}],52:[function(require,module,exports){
+},{"./crypto":47,"./ecpair":49,"./networks":53,"./types":80,"bigi":39,"bs58check":83,"create-hmac":88,"ecurve":92,"safe-buffer":101,"typeforce":112}],52:[function(require,module,exports){
var script = require('./script')
var templates = require('./templates')
@@ -36824,7 +36862,7 @@ module.exports = {
isDefinedHashType: isDefinedHashType
}
-},{"./script_number":55,"./types":80,"bip66":41,"bitcoin-ops":42,"bitcoin-ops/map":43,"pushdata-bitcoin":125,"safe-buffer":128,"typeforce":139}],55:[function(require,module,exports){
+},{"./script_number":55,"./types":80,"bip66":41,"bitcoin-ops":42,"bitcoin-ops/map":43,"pushdata-bitcoin":98,"safe-buffer":101,"typeforce":112}],55:[function(require,module,exports){
var Buffer = require('safe-buffer').Buffer
function decode (buffer, maxLength, minimal) {
@@ -36894,7 +36932,7 @@ module.exports = {
encode: encode
}
-},{"safe-buffer":128}],56:[function(require,module,exports){
+},{"safe-buffer":101}],56:[function(require,module,exports){
var decompile = require('../script').decompile
var multisig = require('./multisig')
var nullData = require('./nulldata')
@@ -37032,6 +37070,7 @@ function encode (signatures, scriptPubKey) {
}
function decodeStack (stack, allowIncomplete) {
+ typeforce(typeforce.Array, stack)
typeforce(check, stack, allowIncomplete)
return stack.slice(1)
}
@@ -37049,7 +37088,7 @@ module.exports = {
encodeStack: encodeStack
}
-},{"../../script":54,"./output":59,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],59:[function(require,module,exports){
+},{"../../script":54,"./output":59,"bitcoin-ops":42,"safe-buffer":101,"typeforce":112}],59:[function(require,module,exports){
// m [pubKeys ...] n OP_CHECKMULTISIG
var bscript = require('../../script')
@@ -37115,7 +37154,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],60:[function(require,module,exports){
+},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":112}],60:[function(require,module,exports){
// OP_RETURN {data}
var bscript = require('../script')
@@ -37151,7 +37190,7 @@ module.exports = {
}
}
-},{"../script":54,"../types":80,"bitcoin-ops":42,"typeforce":139}],61:[function(require,module,exports){
+},{"../script":54,"../types":80,"bitcoin-ops":42,"typeforce":112}],61:[function(require,module,exports){
arguments[4][57][0].apply(exports,arguments)
},{"./input":62,"./output":63,"dup":57}],62:[function(require,module,exports){
// {signature}
@@ -37177,6 +37216,7 @@ function encode (signature) {
}
function decodeStack (stack) {
+ typeforce(typeforce.Array, stack)
typeforce(check, stack)
return stack[0]
}
@@ -37194,7 +37234,7 @@ module.exports = {
encodeStack: encodeStack
}
-},{"../../script":54,"typeforce":139}],63:[function(require,module,exports){
+},{"../../script":54,"typeforce":112}],63:[function(require,module,exports){
// {pubKey} OP_CHECKSIG
var bscript = require('../../script')
@@ -37229,7 +37269,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"bitcoin-ops":42,"typeforce":139}],64:[function(require,module,exports){
+},{"../../script":54,"bitcoin-ops":42,"typeforce":112}],64:[function(require,module,exports){
arguments[4][57][0].apply(exports,arguments)
},{"./input":65,"./output":66,"dup":57}],65:[function(require,module,exports){
// {signature} {pubKey}
@@ -37263,6 +37303,7 @@ function encode (signature, pubKey) {
}
function decodeStack (stack) {
+ typeforce(typeforce.Array, stack)
typeforce(check, stack)
return {
@@ -37284,7 +37325,7 @@ module.exports = {
encodeStack: encodeStack
}
-},{"../../script":54,"typeforce":139}],66:[function(require,module,exports){
+},{"../../script":54,"typeforce":112}],66:[function(require,module,exports){
// OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
var bscript = require('../../script')
@@ -37328,7 +37369,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],67:[function(require,module,exports){
+},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":112}],67:[function(require,module,exports){
arguments[4][57][0].apply(exports,arguments)
},{"./input":68,"./output":69,"dup":57}],68:[function(require,module,exports){
// {serialized scriptPubKey script}
@@ -37392,6 +37433,7 @@ function encode (redeemScriptSig, redeemScript) {
}
function decodeStack (stack) {
+ typeforce(typeforce.Array, stack)
typeforce(check, stack)
return {
@@ -37416,7 +37458,7 @@ module.exports = {
encodeStack: encodeStack
}
-},{"../../script":54,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"../witnesspubkeyhash/output":74,"../witnessscripthash/output":77,"safe-buffer":128,"typeforce":139}],69:[function(require,module,exports){
+},{"../../script":54,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"../witnesspubkeyhash/output":74,"../witnessscripthash/output":77,"safe-buffer":101,"typeforce":112}],69:[function(require,module,exports){
// OP_HASH160 {scriptHash} OP_EQUAL
var bscript = require('../../script')
@@ -37452,7 +37494,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],70:[function(require,module,exports){
+},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":112}],70:[function(require,module,exports){
module.exports = {
output: require('./output')
}
@@ -37501,7 +37543,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"../../types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],72:[function(require,module,exports){
+},{"../../script":54,"../../types":80,"bitcoin-ops":42,"safe-buffer":101,"typeforce":112}],72:[function(require,module,exports){
arguments[4][57][0].apply(exports,arguments)
},{"./input":73,"./output":74,"dup":57}],73:[function(require,module,exports){
// {signature} {pubKey}
@@ -37535,6 +37577,7 @@ function encodeStack (signature, pubKey) {
}
function decodeStack (stack) {
+ typeforce(typeforce.Array, stack)
typeforce(check, stack)
return {
@@ -37549,7 +37592,7 @@ module.exports = {
encodeStack: encodeStack
}
-},{"../../script":54,"typeforce":139}],74:[function(require,module,exports){
+},{"../../script":54,"typeforce":112}],74:[function(require,module,exports){
// OP_0 {pubKeyHash}
var bscript = require('../../script')
@@ -37584,7 +37627,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],75:[function(require,module,exports){
+},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":112}],75:[function(require,module,exports){
arguments[4][57][0].apply(exports,arguments)
},{"./input":76,"./output":77,"dup":57}],76:[function(require,module,exports){
(function (Buffer){
@@ -37638,11 +37681,12 @@ function encodeStack (witnessData, witnessScript) {
return [].concat(witnessData, witnessScript)
}
-function decodeStack (chunks) {
- typeforce(check, chunks)
+function decodeStack (stack) {
+ typeforce(typeforce.Array, stack)
+ typeforce(check, stack)
return {
- witnessData: chunks.slice(0, -1),
- witnessScript: chunks[chunks.length - 1]
+ witnessData: stack.slice(0, -1),
+ witnessScript: stack[stack.length - 1]
}
}
@@ -37653,7 +37697,7 @@ module.exports = {
}
}).call(this,{"isBuffer":require("../../../../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
-},{"../../../../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10,"../../script":54,"../../types":80,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"typeforce":139}],77:[function(require,module,exports){
+},{"../../../../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10,"../../script":54,"../../types":80,"../multisig/":57,"../pubkey/":61,"../pubkeyhash/":64,"typeforce":112}],77:[function(require,module,exports){
// OP_0 {scriptHash}
var bscript = require('../../script')
@@ -37688,7 +37732,7 @@ module.exports = {
encode: encode
}
-},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":139}],78:[function(require,module,exports){
+},{"../../script":54,"../../types":80,"bitcoin-ops":42,"typeforce":112}],78:[function(require,module,exports){
var Buffer = require('safe-buffer').Buffer
var bcrypto = require('./crypto')
var bscript = require('./script')
@@ -38182,7 +38226,7 @@ Transaction.prototype.setWitness = function (index, witness) {
module.exports = Transaction
-},{"./bufferutils":46,"./crypto":47,"./script":54,"./types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139,"varuint-bitcoin":141}],79:[function(require,module,exports){
+},{"./bufferutils":46,"./crypto":47,"./script":54,"./types":80,"bitcoin-ops":42,"safe-buffer":101,"typeforce":112,"varuint-bitcoin":114}],79:[function(require,module,exports){
var Buffer = require('safe-buffer').Buffer
var baddress = require('./address')
var bcrypto = require('./crypto')
@@ -38654,7 +38698,7 @@ function TransactionBuilder (network, maximumFeeRate) {
this.network = network || networks.bitcoin
// WARNING: This is __NOT__ to be relied on, its just another potential safety mechanism (safety in-depth)
- this.maximumFeeRate = maximumFeeRate || 1000
+ this.maximumFeeRate = maximumFeeRate || 2500
this.inputs = []
this.tx = new Transaction()
@@ -38961,7 +39005,7 @@ TransactionBuilder.prototype.__overMaximumFees = function (bytes) {
module.exports = TransactionBuilder
-},{"./address":44,"./crypto":47,"./ecpair":49,"./ecsignature":50,"./networks":53,"./script":54,"./templates":56,"./transaction":78,"./types":80,"bitcoin-ops":42,"safe-buffer":128,"typeforce":139}],80:[function(require,module,exports){
+},{"./address":44,"./crypto":47,"./ecpair":49,"./ecsignature":50,"./networks":53,"./script":54,"./templates":56,"./transaction":78,"./types":80,"bitcoin-ops":42,"safe-buffer":101,"typeforce":112}],80:[function(require,module,exports){
var typeforce = require('typeforce')
var UINT31_MAX = Math.pow(2, 31) - 1
@@ -38991,8 +39035,8 @@ var Network = typeforce.compile({
public: typeforce.UInt32,
private: typeforce.UInt32
},
- pubKeyHash: typeforce.UInt8,
- scriptHash: typeforce.UInt8,
+ pubKeyHash: typeforce.oneOf(typeforce.UInt8, typeforce.UInt16),
+ scriptHash: typeforce.oneOf(typeforce.UInt8, typeforce.UInt16),
wif: typeforce.UInt8
})
@@ -39016,15115 +39060,7175 @@ for (var typeName in typeforce) {
module.exports = types
-},{"typeforce":139}],81:[function(require,module,exports){
-(function (module, exports) {
- 'use strict';
+},{"typeforce":112}],81:[function(require,module,exports){
+var basex = require('base-x')
+var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
- // Utils
- function assert (val, msg) {
- if (!val) throw new Error(msg || 'Assertion failed');
- }
+module.exports = basex(ALPHABET)
- // Could use `inherits` module, but don't want to move from single file
- // architecture yet.
- function inherits (ctor, superCtor) {
- ctor.super_ = superCtor;
- var TempCtor = function () {};
- TempCtor.prototype = superCtor.prototype;
- ctor.prototype = new TempCtor();
- ctor.prototype.constructor = ctor;
- }
+},{"base-x":35}],82:[function(require,module,exports){
+'use strict'
- // BN
+var base58 = require('bs58')
+var Buffer = require('safe-buffer').Buffer
- function BN (number, base, endian) {
- if (BN.isBN(number)) {
- return number;
- }
+module.exports = function (checksumFn) {
+ // Encode a buffer as a base58-check encoded string
+ function encode (payload) {
+ var checksum = checksumFn(payload)
- this.negative = 0;
- this.words = null;
- this.length = 0;
+ return base58.encode(Buffer.concat([
+ payload,
+ checksum
+ ], payload.length + 4))
+ }
- // Reduction context
- this.red = null;
+ function decodeRaw (buffer) {
+ var payload = buffer.slice(0, -4)
+ var checksum = buffer.slice(-4)
+ var newChecksum = checksumFn(payload)
- if (number !== null) {
- if (base === 'le' || base === 'be') {
- endian = base;
- base = 10;
- }
+ if (checksum[0] ^ newChecksum[0] |
+ checksum[1] ^ newChecksum[1] |
+ checksum[2] ^ newChecksum[2] |
+ checksum[3] ^ newChecksum[3]) return
- this._init(number || 0, base || 10, endian || 'be');
- }
+ return payload
}
- if (typeof module === 'object') {
- module.exports = BN;
- } else {
- exports.BN = BN;
+
+ // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
+ function decodeUnsafe (string) {
+ var buffer = base58.decodeUnsafe(string)
+ if (!buffer) return
+
+ return decodeRaw(buffer)
}
- BN.BN = BN;
- BN.wordSize = 26;
+ function decode (string) {
+ var buffer = base58.decode(string)
+ var payload = decodeRaw(buffer, checksumFn)
+ if (!payload) throw new Error('Invalid checksum')
+ return payload
+ }
- var Buffer;
- try {
- Buffer = require('buf' + 'fer').Buffer;
- } catch (e) {
+ return {
+ encode: encode,
+ decode: decode,
+ decodeUnsafe: decodeUnsafe
}
+}
- BN.isBN = function isBN (num) {
- if (num instanceof BN) {
- return true;
- }
+},{"bs58":81,"safe-buffer":101}],83:[function(require,module,exports){
+'use strict'
- return num !== null && typeof num === 'object' &&
- num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
- };
+var createHash = require('create-hash')
+var bs58checkBase = require('./base')
- BN.max = function max (left, right) {
- if (left.cmp(right) > 0) return left;
- return right;
- };
+// SHA256(SHA256(buffer))
+function sha256x2 (buffer) {
+ var tmp = createHash('sha256').update(buffer).digest()
+ return createHash('sha256').update(tmp).digest()
+}
- BN.min = function min (left, right) {
- if (left.cmp(right) < 0) return left;
- return right;
- };
+module.exports = bs58checkBase(sha256x2)
- BN.prototype._init = function init (number, base, endian) {
- if (typeof number === 'number') {
- return this._initNumber(number, base, endian);
- }
+},{"./base":82,"create-hash":85}],84:[function(require,module,exports){
+var Buffer = require('safe-buffer').Buffer
+var Transform = require('stream').Transform
+var StringDecoder = require('string_decoder').StringDecoder
+var inherits = require('inherits')
- if (typeof number === 'object') {
- return this._initArray(number, base, endian);
- }
+function CipherBase (hashMode) {
+ Transform.call(this)
+ this.hashMode = typeof hashMode === 'string'
+ if (this.hashMode) {
+ this[hashMode] = this._finalOrDigest
+ } else {
+ this.final = this._finalOrDigest
+ }
+ if (this._final) {
+ this.__final = this._final
+ this._final = null
+ }
+ this._decoder = null
+ this._encoding = null
+}
+inherits(CipherBase, Transform)
- if (base === 'hex') {
- base = 16;
- }
- assert(base === (base | 0) && base >= 2 && base <= 36);
+CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
+ if (typeof data === 'string') {
+ data = Buffer.from(data, inputEnc)
+ }
- number = number.toString().replace(/\s+/g, '');
- var start = 0;
- if (number[0] === '-') {
- start++;
- }
+ var outData = this._update(data)
+ if (this.hashMode) return this
- if (base === 16) {
- this._parseHex(number, start);
- } else {
- this._parseBase(number, base, start);
- }
+ if (outputEnc) {
+ outData = this._toString(outData, outputEnc)
+ }
- if (number[0] === '-') {
- this.negative = 1;
- }
+ return outData
+}
- this.strip();
+CipherBase.prototype.setAutoPadding = function () {}
+CipherBase.prototype.getAuthTag = function () {
+ throw new Error('trying to get auth tag in unsupported state')
+}
- if (endian !== 'le') return;
+CipherBase.prototype.setAuthTag = function () {
+ throw new Error('trying to set auth tag in unsupported state')
+}
- this._initArray(this.toArray(), base, endian);
- };
+CipherBase.prototype.setAAD = function () {
+ throw new Error('trying to set aad in unsupported state')
+}
- BN.prototype._initNumber = function _initNumber (number, base, endian) {
- if (number < 0) {
- this.negative = 1;
- number = -number;
- }
- if (number < 0x4000000) {
- this.words = [ number & 0x3ffffff ];
- this.length = 1;
- } else if (number < 0x10000000000000) {
- this.words = [
- number & 0x3ffffff,
- (number / 0x4000000) & 0x3ffffff
- ];
- this.length = 2;
+CipherBase.prototype._transform = function (data, _, next) {
+ var err
+ try {
+ if (this.hashMode) {
+ this._update(data)
} else {
- assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
- this.words = [
- number & 0x3ffffff,
- (number / 0x4000000) & 0x3ffffff,
- 1
- ];
- this.length = 3;
+ this.push(this._update(data))
}
+ } catch (e) {
+ err = e
+ } finally {
+ next(err)
+ }
+}
+CipherBase.prototype._flush = function (done) {
+ var err
+ try {
+ this.push(this.__final())
+ } catch (e) {
+ err = e
+ }
- if (endian !== 'le') return;
-
- // Reverse the bytes
- this._initArray(this.toArray(), base, endian);
- };
+ done(err)
+}
+CipherBase.prototype._finalOrDigest = function (outputEnc) {
+ var outData = this.__final() || Buffer.alloc(0)
+ if (outputEnc) {
+ outData = this._toString(outData, outputEnc, true)
+ }
+ return outData
+}
- BN.prototype._initArray = function _initArray (number, base, endian) {
- // Perhaps a Uint8Array
- assert(typeof number.length === 'number');
- if (number.length <= 0) {
- this.words = [ 0 ];
- this.length = 1;
- return this;
- }
+CipherBase.prototype._toString = function (value, enc, fin) {
+ if (!this._decoder) {
+ this._decoder = new StringDecoder(enc)
+ this._encoding = enc
+ }
- this.length = Math.ceil(number.length / 3);
- this.words = new Array(this.length);
- for (var i = 0; i < this.length; i++) {
- this.words[i] = 0;
- }
+ if (this._encoding !== enc) throw new Error('can\'t switch encodings')
- var j, w;
- var off = 0;
- if (endian === 'be') {
- for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
- w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
- this.words[j] |= (w << off) & 0x3ffffff;
- this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
- off += 24;
- if (off >= 26) {
- off -= 26;
- j++;
- }
- }
- } else if (endian === 'le') {
- for (i = 0, j = 0; i < number.length; i += 3) {
- w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
- this.words[j] |= (w << off) & 0x3ffffff;
- this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
- off += 24;
- if (off >= 26) {
- off -= 26;
- j++;
- }
- }
- }
- return this.strip();
- };
+ var out = this._decoder.write(value)
+ if (fin) {
+ out += this._decoder.end()
+ }
- function parseHex (str, start, end) {
- var r = 0;
- var len = Math.min(str.length, end);
- for (var i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
+ return out
+}
- r <<= 4;
+module.exports = CipherBase
- // 'a' - 'f'
- if (c >= 49 && c <= 54) {
- r |= c - 49 + 0xa;
+},{"inherits":96,"safe-buffer":101,"stream":28,"string_decoder":29}],85:[function(require,module,exports){
+(function (Buffer){
+'use strict'
+var inherits = require('inherits')
+var md5 = require('./md5')
+var RIPEMD160 = require('ripemd160')
+var sha = require('sha.js')
- // 'A' - 'F'
- } else if (c >= 17 && c <= 22) {
- r |= c - 17 + 0xa;
+var Base = require('cipher-base')
- // '0' - '9'
- } else {
- r |= c & 0xf;
- }
- }
- return r;
- }
+function HashNoConstructor (hash) {
+ Base.call(this, 'digest')
- BN.prototype._parseHex = function _parseHex (number, start) {
- // Create possibly bigger array to ensure that it fits the number
- this.length = Math.ceil((number.length - start) / 6);
- this.words = new Array(this.length);
- for (var i = 0; i < this.length; i++) {
- this.words[i] = 0;
- }
+ this._hash = hash
+ this.buffers = []
+}
- var j, w;
- // Scan 24-bit chunks and add them to the number
- var off = 0;
- for (i = number.length - 6, j = 0; i >= start; i -= 6) {
- w = parseHex(number, i, i + 6);
- this.words[j] |= (w << off) & 0x3ffffff;
- // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
- this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
- off += 24;
- if (off >= 26) {
- off -= 26;
- j++;
- }
- }
- if (i + 6 !== start) {
- w = parseHex(number, start, i + 6);
- this.words[j] |= (w << off) & 0x3ffffff;
- this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
- }
- this.strip();
- };
+inherits(HashNoConstructor, Base)
- function parseBase (str, start, end, mul) {
- var r = 0;
- var len = Math.min(str.length, end);
- for (var i = start; i < len; i++) {
- var c = str.charCodeAt(i) - 48;
+HashNoConstructor.prototype._update = function (data) {
+ this.buffers.push(data)
+}
- r *= mul;
+HashNoConstructor.prototype._final = function () {
+ var buf = Buffer.concat(this.buffers)
+ var r = this._hash(buf)
+ this.buffers = null
- // 'a'
- if (c >= 49) {
- r += c - 49 + 0xa;
+ return r
+}
- // 'A'
- } else if (c >= 17) {
- r += c - 17 + 0xa;
+function Hash (hash) {
+ Base.call(this, 'digest')
- // '0' - '9'
- } else {
- r += c;
- }
- }
- return r;
- }
+ this._hash = hash
+}
- BN.prototype._parseBase = function _parseBase (number, base, start) {
- // Initialize as zero
- this.words = [ 0 ];
- this.length = 1;
+inherits(Hash, Base)
- // Find length of limb in base
- for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
- limbLen++;
- }
- limbLen--;
- limbPow = (limbPow / base) | 0;
+Hash.prototype._update = function (data) {
+ this._hash.update(data)
+}
- var total = number.length - start;
- var mod = total % limbLen;
- var end = Math.min(total, total - mod) + start;
+Hash.prototype._final = function () {
+ return this._hash.digest()
+}
- var word = 0;
- for (var i = start; i < end; i += limbLen) {
- word = parseBase(number, i, i + limbLen, base);
+module.exports = function createHash (alg) {
+ alg = alg.toLowerCase()
+ if (alg === 'md5') return new HashNoConstructor(md5)
+ if (alg === 'rmd160' || alg === 'ripemd160') return new Hash(new RIPEMD160())
- this.imuln(limbPow);
- if (this.words[0] + word < 0x4000000) {
- this.words[0] += word;
- } else {
- this._iaddn(word);
- }
- }
+ return new Hash(sha(alg))
+}
- if (mod !== 0) {
- var pow = 1;
- word = parseBase(number, i, number.length, base);
+}).call(this,require("buffer").Buffer)
+},{"./md5":87,"buffer":5,"cipher-base":84,"inherits":96,"ripemd160":100,"sha.js":103}],86:[function(require,module,exports){
+(function (Buffer){
+'use strict'
+var intSize = 4
+var zeroBuffer = new Buffer(intSize)
+zeroBuffer.fill(0)
- for (i = 0; i < mod; i++) {
- pow *= base;
- }
+var charSize = 8
+var hashSize = 16
- this.imuln(pow);
- if (this.words[0] + word < 0x4000000) {
- this.words[0] += word;
- } else {
- this._iaddn(word);
- }
- }
- };
+function toArray (buf) {
+ if ((buf.length % intSize) !== 0) {
+ var len = buf.length + (intSize - (buf.length % intSize))
+ buf = Buffer.concat([buf, zeroBuffer], len)
+ }
- BN.prototype.copy = function copy (dest) {
- dest.words = new Array(this.length);
- for (var i = 0; i < this.length; i++) {
- dest.words[i] = this.words[i];
- }
- dest.length = this.length;
- dest.negative = this.negative;
- dest.red = this.red;
- };
+ var arr = new Array(buf.length >>> 2)
+ for (var i = 0, j = 0; i < buf.length; i += intSize, j++) {
+ arr[j] = buf.readInt32LE(i)
+ }
- BN.prototype.clone = function clone () {
- var r = new BN(null);
- this.copy(r);
- return r;
- };
+ return arr
+}
- BN.prototype._expand = function _expand (size) {
- while (this.length < size) {
- this.words[this.length++] = 0;
- }
- return this;
- };
+module.exports = function hash (buf, fn) {
+ var arr = fn(toArray(buf), buf.length * charSize)
+ buf = new Buffer(hashSize)
+ for (var i = 0; i < arr.length; i++) {
+ buf.writeInt32LE(arr[i], i << 2, true)
+ }
+ return buf
+}
- // Remove leading `0` from `this`
- BN.prototype.strip = function strip () {
- while (this.length > 1 && this.words[this.length - 1] === 0) {
- this.length--;
- }
- return this._normSign();
- };
-
- BN.prototype._normSign = function _normSign () {
- // -0 = 0
- if (this.length === 1 && this.words[0] === 0) {
- this.negative = 0;
- }
- return this;
- };
+}).call(this,require("buffer").Buffer)
+},{"buffer":5}],87:[function(require,module,exports){
+'use strict'
+/*
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
+ * Digest Algorithm, as defined in RFC 1321.
+ * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for more info.
+ */
- BN.prototype.inspect = function inspect () {
- return (this.red ? '';
- };
+var makeHash = require('./make-hash')
- /*
+/*
+ * Calculate the MD5 of an array of little-endian words, and a bit length
+ */
+function core_md5 (x, len) {
+ /* append padding */
+ x[len >> 5] |= 0x80 << ((len) % 32)
+ x[(((len + 64) >>> 9) << 4) + 14] = len
- var zeros = [];
- var groupSizes = [];
- var groupBases = [];
+ var a = 1732584193
+ var b = -271733879
+ var c = -1732584194
+ var d = 271733878
- var s = '';
- var i = -1;
- while (++i < BN.wordSize) {
- zeros[i] = s;
- s += '0';
- }
- groupSizes[0] = 0;
- groupSizes[1] = 0;
- groupBases[0] = 0;
- groupBases[1] = 0;
- var base = 2 - 1;
- while (++base < 36 + 1) {
- var groupSize = 0;
- var groupBase = 1;
- while (groupBase < (1 << BN.wordSize) / base) {
- groupBase *= base;
- groupSize += 1;
- }
- groupSizes[base] = groupSize;
- groupBases[base] = groupBase;
- }
+ for (var i = 0; i < x.length; i += 16) {
+ var olda = a
+ var oldb = b
+ var oldc = c
+ var oldd = d
- */
+ a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936)
+ d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586)
+ c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819)
+ b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330)
+ a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897)
+ d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426)
+ c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341)
+ b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983)
+ a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416)
+ d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417)
+ c = md5_ff(c, d, a, b, x[i + 10], 17, -42063)
+ b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162)
+ a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682)
+ d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101)
+ c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290)
+ b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329)
- var zeros = [
- '',
- '0',
- '00',
- '000',
- '0000',
- '00000',
- '000000',
- '0000000',
- '00000000',
- '000000000',
- '0000000000',
- '00000000000',
- '000000000000',
- '0000000000000',
- '00000000000000',
- '000000000000000',
- '0000000000000000',
- '00000000000000000',
- '000000000000000000',
- '0000000000000000000',
- '00000000000000000000',
- '000000000000000000000',
- '0000000000000000000000',
- '00000000000000000000000',
- '000000000000000000000000',
- '0000000000000000000000000'
- ];
+ a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510)
+ d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632)
+ c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713)
+ b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302)
+ a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691)
+ d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083)
+ c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335)
+ b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848)
+ a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438)
+ d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690)
+ c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961)
+ b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501)
+ a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467)
+ d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784)
+ c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473)
+ b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734)
- var groupSizes = [
- 0, 0,
- 25, 16, 12, 11, 10, 9, 8,
- 8, 7, 7, 7, 7, 6, 6,
- 6, 6, 6, 6, 6, 5, 5,
- 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5
- ];
+ a = md5_hh(a, b, c, d, x[i + 5], 4, -378558)
+ d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463)
+ c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562)
+ b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556)
+ a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060)
+ d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353)
+ c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632)
+ b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640)
+ a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174)
+ d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222)
+ c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979)
+ b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189)
+ a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487)
+ d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835)
+ c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520)
+ b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651)
- var groupBases = [
- 0, 0,
- 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
- 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
- 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
- 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
- 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
- ];
+ a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844)
+ d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415)
+ c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905)
+ b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055)
+ a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571)
+ d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606)
+ c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523)
+ b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799)
+ a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359)
+ d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744)
+ c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380)
+ b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649)
+ a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070)
+ d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379)
+ c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259)
+ b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551)
- BN.prototype.toString = function toString (base, padding) {
- base = base || 10;
- padding = padding | 0 || 1;
+ a = safe_add(a, olda)
+ b = safe_add(b, oldb)
+ c = safe_add(c, oldc)
+ d = safe_add(d, oldd)
+ }
- var out;
- if (base === 16 || base === 'hex') {
- out = '';
- var off = 0;
- var carry = 0;
- for (var i = 0; i < this.length; i++) {
- var w = this.words[i];
- var word = (((w << off) | carry) & 0xffffff).toString(16);
- carry = (w >>> (24 - off)) & 0xffffff;
- if (carry !== 0 || i !== this.length - 1) {
- out = zeros[6 - word.length] + word + out;
- } else {
- out = word + out;
- }
- off += 2;
- if (off >= 26) {
- off -= 26;
- i--;
- }
- }
- if (carry !== 0) {
- out = carry.toString(16) + out;
- }
- while (out.length % padding !== 0) {
- out = '0' + out;
- }
- if (this.negative !== 0) {
- out = '-' + out;
- }
- return out;
- }
+ return [a, b, c, d]
+}
- if (base === (base | 0) && base >= 2 && base <= 36) {
- // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
- var groupSize = groupSizes[base];
- // var groupBase = Math.pow(base, groupSize);
- var groupBase = groupBases[base];
- out = '';
- var c = this.clone();
- c.negative = 0;
- while (!c.isZero()) {
- var r = c.modn(groupBase).toString(base);
- c = c.idivn(groupBase);
+/*
+ * These functions implement the four basic operations the algorithm uses.
+ */
+function md5_cmn (q, a, b, x, s, t) {
+ return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b)
+}
- if (!c.isZero()) {
- out = zeros[groupSize - r.length] + r + out;
- } else {
- out = r + out;
- }
- }
- if (this.isZero()) {
- out = '0' + out;
- }
- while (out.length % padding !== 0) {
- out = '0' + out;
- }
- if (this.negative !== 0) {
- out = '-' + out;
- }
- return out;
- }
+function md5_ff (a, b, c, d, x, s, t) {
+ return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t)
+}
- assert(false, 'Base should be between 2 and 36');
- };
+function md5_gg (a, b, c, d, x, s, t) {
+ return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t)
+}
- BN.prototype.toNumber = function toNumber () {
- var ret = this.words[0];
- if (this.length === 2) {
- ret += this.words[1] * 0x4000000;
- } else if (this.length === 3 && this.words[2] === 0x01) {
- // NOTE: at this stage it is known that the top bit is set
- ret += 0x10000000000000 + (this.words[1] * 0x4000000);
- } else if (this.length > 2) {
- assert(false, 'Number can only safely store up to 53 bits');
- }
- return (this.negative !== 0) ? -ret : ret;
- };
+function md5_hh (a, b, c, d, x, s, t) {
+ return md5_cmn(b ^ c ^ d, a, b, x, s, t)
+}
- BN.prototype.toJSON = function toJSON () {
- return this.toString(16);
- };
+function md5_ii (a, b, c, d, x, s, t) {
+ return md5_cmn(c ^ (b | (~d)), a, b, x, s, t)
+}
- BN.prototype.toBuffer = function toBuffer (endian, length) {
- assert(typeof Buffer !== 'undefined');
- return this.toArrayLike(Buffer, endian, length);
- };
+/*
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
+ * to work around bugs in some JS interpreters.
+ */
+function safe_add (x, y) {
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF)
+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16)
+ return (msw << 16) | (lsw & 0xFFFF)
+}
- BN.prototype.toArray = function toArray (endian, length) {
- return this.toArrayLike(Array, endian, length);
- };
+/*
+ * Bitwise rotate a 32-bit number to the left.
+ */
+function bit_rol (num, cnt) {
+ return (num << cnt) | (num >>> (32 - cnt))
+}
- BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
- var byteLength = this.byteLength();
- var reqLength = length || Math.max(1, byteLength);
- assert(byteLength <= reqLength, 'byte array longer than desired length');
- assert(reqLength > 0, 'Requested array length <= 0');
+module.exports = function md5 (buf) {
+ return makeHash(buf, core_md5)
+}
- this.strip();
- var littleEndian = endian === 'le';
- var res = new ArrayType(reqLength);
+},{"./make-hash":86}],88:[function(require,module,exports){
+'use strict'
+var inherits = require('inherits')
+var Legacy = require('./legacy')
+var Base = require('cipher-base')
+var Buffer = require('safe-buffer').Buffer
+var md5 = require('create-hash/md5')
+var RIPEMD160 = require('ripemd160')
- var b, i;
- var q = this.clone();
- if (!littleEndian) {
- // Assume big-endian
- for (i = 0; i < reqLength - byteLength; i++) {
- res[i] = 0;
- }
+var sha = require('sha.js')
- for (i = 0; !q.isZero(); i++) {
- b = q.andln(0xff);
- q.iushrn(8);
+var ZEROS = Buffer.alloc(128)
- res[reqLength - i - 1] = b;
- }
- } else {
- for (i = 0; !q.isZero(); i++) {
- b = q.andln(0xff);
- q.iushrn(8);
+function Hmac (alg, key) {
+ Base.call(this, 'digest')
+ if (typeof key === 'string') {
+ key = Buffer.from(key)
+ }
- res[i] = b;
- }
+ var blocksize = (alg === 'sha512' || alg === 'sha384') ? 128 : 64
- for (; i < reqLength; i++) {
- res[i] = 0;
- }
- }
+ this._alg = alg
+ this._key = key
+ if (key.length > blocksize) {
+ var hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
+ key = hash.update(key).digest()
+ } else if (key.length < blocksize) {
+ key = Buffer.concat([key, ZEROS], blocksize)
+ }
- return res;
- };
+ var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
+ var opad = this._opad = Buffer.allocUnsafe(blocksize)
- if (Math.clz32) {
- BN.prototype._countBits = function _countBits (w) {
- return 32 - Math.clz32(w);
- };
- } else {
- BN.prototype._countBits = function _countBits (w) {
- var t = w;
- var r = 0;
- if (t >= 0x1000) {
- r += 13;
- t >>>= 13;
- }
- if (t >= 0x40) {
- r += 7;
- t >>>= 7;
- }
- if (t >= 0x8) {
- r += 4;
- t >>>= 4;
- }
- if (t >= 0x02) {
- r += 2;
- t >>>= 2;
- }
- return r + t;
- };
+ for (var i = 0; i < blocksize; i++) {
+ ipad[i] = key[i] ^ 0x36
+ opad[i] = key[i] ^ 0x5C
}
+ this._hash = alg === 'rmd160' ? new RIPEMD160() : sha(alg)
+ this._hash.update(ipad)
+}
- BN.prototype._zeroBits = function _zeroBits (w) {
- // Short-cut
- if (w === 0) return 26;
+inherits(Hmac, Base)
- var t = w;
- var r = 0;
- if ((t & 0x1fff) === 0) {
- r += 13;
- t >>>= 13;
- }
- if ((t & 0x7f) === 0) {
- r += 7;
- t >>>= 7;
- }
- if ((t & 0xf) === 0) {
- r += 4;
- t >>>= 4;
- }
- if ((t & 0x3) === 0) {
- r += 2;
- t >>>= 2;
- }
- if ((t & 0x1) === 0) {
- r++;
- }
- return r;
- };
+Hmac.prototype._update = function (data) {
+ this._hash.update(data)
+}
- // Return number of used bits in a BN
- BN.prototype.bitLength = function bitLength () {
- var w = this.words[this.length - 1];
- var hi = this._countBits(w);
- return (this.length - 1) * 26 + hi;
- };
+Hmac.prototype._final = function () {
+ var h = this._hash.digest()
+ var hash = this._alg === 'rmd160' ? new RIPEMD160() : sha(this._alg)
+ return hash.update(this._opad).update(h).digest()
+}
- function toBitArray (num) {
- var w = new Array(num.bitLength());
+module.exports = function createHmac (alg, key) {
+ alg = alg.toLowerCase()
+ if (alg === 'rmd160' || alg === 'ripemd160') {
+ return new Hmac('rmd160', key)
+ }
+ if (alg === 'md5') {
+ return new Legacy(md5, key)
+ }
+ return new Hmac(alg, key)
+}
- for (var bit = 0; bit < w.length; bit++) {
- var off = (bit / 26) | 0;
- var wbit = bit % 26;
+},{"./legacy":89,"cipher-base":84,"create-hash/md5":87,"inherits":96,"ripemd160":100,"safe-buffer":101,"sha.js":103}],89:[function(require,module,exports){
+'use strict'
+var inherits = require('inherits')
+var Buffer = require('safe-buffer').Buffer
- w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
- }
+var Base = require('cipher-base')
- return w;
+var ZEROS = Buffer.alloc(128)
+var blocksize = 64
+
+function Hmac (alg, key) {
+ Base.call(this, 'digest')
+ if (typeof key === 'string') {
+ key = Buffer.from(key)
}
- // Number of trailing zero bits
- BN.prototype.zeroBits = function zeroBits () {
- if (this.isZero()) return 0;
+ this._alg = alg
+ this._key = key
- var r = 0;
- for (var i = 0; i < this.length; i++) {
- var b = this._zeroBits(this.words[i]);
- r += b;
- if (b !== 26) break;
- }
- return r;
- };
+ if (key.length > blocksize) {
+ key = alg(key)
+ } else if (key.length < blocksize) {
+ key = Buffer.concat([key, ZEROS], blocksize)
+ }
- BN.prototype.byteLength = function byteLength () {
- return Math.ceil(this.bitLength() / 8);
- };
+ var ipad = this._ipad = Buffer.allocUnsafe(blocksize)
+ var opad = this._opad = Buffer.allocUnsafe(blocksize)
- BN.prototype.toTwos = function toTwos (width) {
- if (this.negative !== 0) {
- return this.abs().inotn(width).iaddn(1);
- }
- return this.clone();
- };
+ for (var i = 0; i < blocksize; i++) {
+ ipad[i] = key[i] ^ 0x36
+ opad[i] = key[i] ^ 0x5C
+ }
- BN.prototype.fromTwos = function fromTwos (width) {
- if (this.testn(width - 1)) {
- return this.notn(width).iaddn(1).ineg();
- }
- return this.clone();
- };
+ this._hash = [ipad]
+}
- BN.prototype.isNeg = function isNeg () {
- return this.negative !== 0;
- };
+inherits(Hmac, Base)
- // Return negative clone of `this`
- BN.prototype.neg = function neg () {
- return this.clone().ineg();
- };
+Hmac.prototype._update = function (data) {
+ this._hash.push(data)
+}
- BN.prototype.ineg = function ineg () {
- if (!this.isZero()) {
- this.negative ^= 1;
- }
+Hmac.prototype._final = function () {
+ var h = this._alg(Buffer.concat(this._hash))
+ return this._alg(Buffer.concat([this._opad, h]))
+}
+module.exports = Hmac
- return this;
- };
+},{"cipher-base":84,"inherits":96,"safe-buffer":101}],90:[function(require,module,exports){
+var assert = require('assert')
+var BigInteger = require('bigi')
- // Or `num` with `this` in-place
- BN.prototype.iuor = function iuor (num) {
- while (this.length < num.length) {
- this.words[this.length++] = 0;
- }
+var Point = require('./point')
- for (var i = 0; i < num.length; i++) {
- this.words[i] = this.words[i] | num.words[i];
- }
+function Curve (p, a, b, Gx, Gy, n, h) {
+ this.p = p
+ this.a = a
+ this.b = b
+ this.G = Point.fromAffine(this, Gx, Gy)
+ this.n = n
+ this.h = h
- return this.strip();
- };
+ this.infinity = new Point(this, null, null, BigInteger.ZERO)
- BN.prototype.ior = function ior (num) {
- assert((this.negative | num.negative) === 0);
- return this.iuor(num);
- };
+ // result caching
+ this.pOverFour = p.add(BigInteger.ONE).shiftRight(2)
- // Or `num` with `this`
- BN.prototype.or = function or (num) {
- if (this.length > num.length) return this.clone().ior(num);
- return num.clone().ior(this);
- };
+ // determine size of p in bytes
+ this.pLength = Math.floor((this.p.bitLength() + 7) / 8)
+}
- BN.prototype.uor = function uor (num) {
- if (this.length > num.length) return this.clone().iuor(num);
- return num.clone().iuor(this);
- };
+Curve.prototype.pointFromX = function (isOdd, x) {
+ var alpha = x.pow(3).add(this.a.multiply(x)).add(this.b).mod(this.p)
+ var beta = alpha.modPow(this.pOverFour, this.p) // XXX: not compatible with all curves
- // And `num` with `this` in-place
- BN.prototype.iuand = function iuand (num) {
- // b = min-length(num, this)
- var b;
- if (this.length > num.length) {
- b = num;
- } else {
- b = this;
- }
+ var y = beta
+ if (beta.isEven() ^ !isOdd) {
+ y = this.p.subtract(y) // -y % p
+ }
- for (var i = 0; i < b.length; i++) {
- this.words[i] = this.words[i] & num.words[i];
- }
+ return Point.fromAffine(this, x, y)
+}
- this.length = b.length;
+Curve.prototype.isInfinity = function (Q) {
+ if (Q === this.infinity) return true
- return this.strip();
- };
+ return Q.z.signum() === 0 && Q.y.signum() !== 0
+}
- BN.prototype.iand = function iand (num) {
- assert((this.negative | num.negative) === 0);
- return this.iuand(num);
- };
+Curve.prototype.isOnCurve = function (Q) {
+ if (this.isInfinity(Q)) return true
- // And `num` with `this`
- BN.prototype.and = function and (num) {
- if (this.length > num.length) return this.clone().iand(num);
- return num.clone().iand(this);
- };
+ var x = Q.affineX
+ var y = Q.affineY
+ var a = this.a
+ var b = this.b
+ var p = this.p
- BN.prototype.uand = function uand (num) {
- if (this.length > num.length) return this.clone().iuand(num);
- return num.clone().iuand(this);
- };
+ // Check that xQ and yQ are integers in the interval [0, p - 1]
+ if (x.signum() < 0 || x.compareTo(p) >= 0) return false
+ if (y.signum() < 0 || y.compareTo(p) >= 0) return false
- // Xor `num` with `this` in-place
- BN.prototype.iuxor = function iuxor (num) {
- // a.length > b.length
- var a;
- var b;
- if (this.length > num.length) {
- a = this;
- b = num;
- } else {
- a = num;
- b = this;
- }
+ // and check that y^2 = x^3 + ax + b (mod p)
+ var lhs = y.square().mod(p)
+ var rhs = x.pow(3).add(a.multiply(x)).add(b).mod(p)
+ return lhs.equals(rhs)
+}
- for (var i = 0; i < b.length; i++) {
- this.words[i] = a.words[i] ^ b.words[i];
- }
+/**
+ * Validate an elliptic curve point.
+ *
+ * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive
+ */
+Curve.prototype.validate = function (Q) {
+ // Check Q != O
+ assert(!this.isInfinity(Q), 'Point is at infinity')
+ assert(this.isOnCurve(Q), 'Point is not on the curve')
- if (this !== a) {
- for (; i < a.length; i++) {
- this.words[i] = a.words[i];
- }
- }
+ // Check nQ = O (where Q is a scalar multiple of G)
+ var nQ = Q.multiply(this.n)
+ assert(this.isInfinity(nQ), 'Point is not a scalar multiple of G')
- this.length = a.length;
+ return true
+}
- return this.strip();
- };
+module.exports = Curve
- BN.prototype.ixor = function ixor (num) {
- assert((this.negative | num.negative) === 0);
- return this.iuxor(num);
- };
+},{"./point":94,"assert":1,"bigi":39}],91:[function(require,module,exports){
+module.exports={
+ "secp128r1": {
+ "p": "fffffffdffffffffffffffffffffffff",
+ "a": "fffffffdfffffffffffffffffffffffc",
+ "b": "e87579c11079f43dd824993c2cee5ed3",
+ "n": "fffffffe0000000075a30d1b9038a115",
+ "h": "01",
+ "Gx": "161ff7528b899b2d0c28607ca52c5b86",
+ "Gy": "cf5ac8395bafeb13c02da292dded7a83"
+ },
+ "secp160k1": {
+ "p": "fffffffffffffffffffffffffffffffeffffac73",
+ "a": "00",
+ "b": "07",
+ "n": "0100000000000000000001b8fa16dfab9aca16b6b3",
+ "h": "01",
+ "Gx": "3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",
+ "Gy": "938cf935318fdced6bc28286531733c3f03c4fee"
+ },
+ "secp160r1": {
+ "p": "ffffffffffffffffffffffffffffffff7fffffff",
+ "a": "ffffffffffffffffffffffffffffffff7ffffffc",
+ "b": "1c97befc54bd7a8b65acf89f81d4d4adc565fa45",
+ "n": "0100000000000000000001f4c8f927aed3ca752257",
+ "h": "01",
+ "Gx": "4a96b5688ef573284664698968c38bb913cbfc82",
+ "Gy": "23a628553168947d59dcc912042351377ac5fb32"
+ },
+ "secp192k1": {
+ "p": "fffffffffffffffffffffffffffffffffffffffeffffee37",
+ "a": "00",
+ "b": "03",
+ "n": "fffffffffffffffffffffffe26f2fc170f69466a74defd8d",
+ "h": "01",
+ "Gx": "db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",
+ "Gy": "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"
+ },
+ "secp192r1": {
+ "p": "fffffffffffffffffffffffffffffffeffffffffffffffff",
+ "a": "fffffffffffffffffffffffffffffffefffffffffffffffc",
+ "b": "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",
+ "n": "ffffffffffffffffffffffff99def836146bc9b1b4d22831",
+ "h": "01",
+ "Gx": "188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
+ "Gy": "07192b95ffc8da78631011ed6b24cdd573f977a11e794811"
+ },
+ "secp256k1": {
+ "p": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
+ "a": "00",
+ "b": "07",
+ "n": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
+ "h": "01",
+ "Gx": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
+ "Gy": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
+ },
+ "secp256r1": {
+ "p": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
+ "a": "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",
+ "b": "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
+ "n": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
+ "h": "01",
+ "Gx": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
+ "Gy": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
+ }
+}
- // Xor `num` with `this`
- BN.prototype.xor = function xor (num) {
- if (this.length > num.length) return this.clone().ixor(num);
- return num.clone().ixor(this);
- };
+},{}],92:[function(require,module,exports){
+var Point = require('./point')
+var Curve = require('./curve')
- BN.prototype.uxor = function uxor (num) {
- if (this.length > num.length) return this.clone().iuxor(num);
- return num.clone().iuxor(this);
- };
+var getCurveByName = require('./names')
- // Not ``this`` with ``width`` bitwidth
- BN.prototype.inotn = function inotn (width) {
- assert(typeof width === 'number' && width >= 0);
+module.exports = {
+ Curve: Curve,
+ Point: Point,
+ getCurveByName: getCurveByName
+}
- var bytesNeeded = Math.ceil(width / 26) | 0;
- var bitsLeft = width % 26;
+},{"./curve":90,"./names":93,"./point":94}],93:[function(require,module,exports){
+var BigInteger = require('bigi')
- // Extend the buffer with leading zeroes
- this._expand(bytesNeeded);
+var curves = require('./curves.json')
+var Curve = require('./curve')
- if (bitsLeft > 0) {
- bytesNeeded--;
- }
+function getCurveByName (name) {
+ var curve = curves[name]
+ if (!curve) return null
- // Handle complete words
- for (var i = 0; i < bytesNeeded; i++) {
- this.words[i] = ~this.words[i] & 0x3ffffff;
- }
+ var p = new BigInteger(curve.p, 16)
+ var a = new BigInteger(curve.a, 16)
+ var b = new BigInteger(curve.b, 16)
+ var n = new BigInteger(curve.n, 16)
+ var h = new BigInteger(curve.h, 16)
+ var Gx = new BigInteger(curve.Gx, 16)
+ var Gy = new BigInteger(curve.Gy, 16)
- // Handle the residue
- if (bitsLeft > 0) {
- this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
- }
+ return new Curve(p, a, b, Gx, Gy, n, h)
+}
- // And remove leading zeroes
- return this.strip();
- };
+module.exports = getCurveByName
- BN.prototype.notn = function notn (width) {
- return this.clone().inotn(width);
- };
+},{"./curve":90,"./curves.json":91,"bigi":39}],94:[function(require,module,exports){
+var assert = require('assert')
+var Buffer = require('safe-buffer').Buffer
+var BigInteger = require('bigi')
- // Set `bit` of `this`
- BN.prototype.setn = function setn (bit, val) {
- assert(typeof bit === 'number' && bit >= 0);
+var THREE = BigInteger.valueOf(3)
- var off = (bit / 26) | 0;
- var wbit = bit % 26;
+function Point (curve, x, y, z) {
+ assert.notStrictEqual(z, undefined, 'Missing Z coordinate')
- this._expand(off + 1);
+ this.curve = curve
+ this.x = x
+ this.y = y
+ this.z = z
+ this._zInv = null
- if (val) {
- this.words[off] = this.words[off] | (1 << wbit);
- } else {
- this.words[off] = this.words[off] & ~(1 << wbit);
+ this.compressed = true
+}
+
+Object.defineProperty(Point.prototype, 'zInv', {
+ get: function () {
+ if (this._zInv === null) {
+ this._zInv = this.z.modInverse(this.curve.p)
}
- return this.strip();
- };
+ return this._zInv
+ }
+})
- // Add `num` to `this` in-place
- BN.prototype.iadd = function iadd (num) {
- var r;
+Object.defineProperty(Point.prototype, 'affineX', {
+ get: function () {
+ return this.x.multiply(this.zInv).mod(this.curve.p)
+ }
+})
- // negative + positive
- if (this.negative !== 0 && num.negative === 0) {
- this.negative = 0;
- r = this.isub(num);
- this.negative ^= 1;
- return this._normSign();
+Object.defineProperty(Point.prototype, 'affineY', {
+ get: function () {
+ return this.y.multiply(this.zInv).mod(this.curve.p)
+ }
+})
- // positive + negative
- } else if (this.negative === 0 && num.negative !== 0) {
- num.negative = 0;
- r = this.isub(num);
- num.negative = 1;
- return r._normSign();
- }
+Point.fromAffine = function (curve, x, y) {
+ return new Point(curve, x, y, BigInteger.ONE)
+}
- // a.length > b.length
- var a, b;
- if (this.length > num.length) {
- a = this;
- b = num;
- } else {
- a = num;
- b = this;
- }
+Point.prototype.equals = function (other) {
+ if (other === this) return true
+ if (this.curve.isInfinity(this)) return this.curve.isInfinity(other)
+ if (this.curve.isInfinity(other)) return this.curve.isInfinity(this)
- var carry = 0;
- for (var i = 0; i < b.length; i++) {
- r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
- this.words[i] = r & 0x3ffffff;
- carry = r >>> 26;
- }
- for (; carry !== 0 && i < a.length; i++) {
- r = (a.words[i] | 0) + carry;
- this.words[i] = r & 0x3ffffff;
- carry = r >>> 26;
- }
+ // u = Y2 * Z1 - Y1 * Z2
+ var u = other.y.multiply(this.z).subtract(this.y.multiply(other.z)).mod(this.curve.p)
- this.length = a.length;
- if (carry !== 0) {
- this.words[this.length] = carry;
- this.length++;
- // Copy the rest of the words
- } else if (a !== this) {
- for (; i < a.length; i++) {
- this.words[i] = a.words[i];
- }
- }
+ if (u.signum() !== 0) return false
- return this;
- };
+ // v = X2 * Z1 - X1 * Z2
+ var v = other.x.multiply(this.z).subtract(this.x.multiply(other.z)).mod(this.curve.p)
- // Add `num` to `this`
- BN.prototype.add = function add (num) {
- var res;
- if (num.negative !== 0 && this.negative === 0) {
- num.negative = 0;
- res = this.sub(num);
- num.negative ^= 1;
- return res;
- } else if (num.negative === 0 && this.negative !== 0) {
- this.negative = 0;
- res = num.sub(this);
- this.negative = 1;
- return res;
- }
+ return v.signum() === 0
+}
- if (this.length > num.length) return this.clone().iadd(num);
+Point.prototype.negate = function () {
+ var y = this.curve.p.subtract(this.y)
- return num.clone().iadd(this);
- };
+ return new Point(this.curve, this.x, y, this.z)
+}
- // Subtract `num` from `this` in-place
- BN.prototype.isub = function isub (num) {
- // this - (-num) = this + num
- if (num.negative !== 0) {
- num.negative = 0;
- var r = this.iadd(num);
- num.negative = 1;
- return r._normSign();
+Point.prototype.add = function (b) {
+ if (this.curve.isInfinity(this)) return b
+ if (this.curve.isInfinity(b)) return this
- // -this - num = -(this + num)
- } else if (this.negative !== 0) {
- this.negative = 0;
- this.iadd(num);
- this.negative = 1;
- return this._normSign();
- }
+ var x1 = this.x
+ var y1 = this.y
+ var x2 = b.x
+ var y2 = b.y
- // At this point both numbers are positive
- var cmp = this.cmp(num);
+ // u = Y2 * Z1 - Y1 * Z2
+ var u = y2.multiply(this.z).subtract(y1.multiply(b.z)).mod(this.curve.p)
+ // v = X2 * Z1 - X1 * Z2
+ var v = x2.multiply(this.z).subtract(x1.multiply(b.z)).mod(this.curve.p)
- // Optimization - zeroify
- if (cmp === 0) {
- this.negative = 0;
- this.length = 1;
- this.words[0] = 0;
- return this;
+ if (v.signum() === 0) {
+ if (u.signum() === 0) {
+ return this.twice() // this == b, so double
}
- // a > b
- var a, b;
- if (cmp > 0) {
- a = this;
- b = num;
- } else {
- a = num;
- b = this;
- }
+ return this.curve.infinity // this = -b, so infinity
+ }
- var carry = 0;
- for (var i = 0; i < b.length; i++) {
- r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
- carry = r >> 26;
- this.words[i] = r & 0x3ffffff;
- }
- for (; carry !== 0 && i < a.length; i++) {
- r = (a.words[i] | 0) + carry;
- carry = r >> 26;
- this.words[i] = r & 0x3ffffff;
- }
+ var v2 = v.square()
+ var v3 = v2.multiply(v)
+ var x1v2 = x1.multiply(v2)
+ var zu2 = u.square().multiply(this.z)
- // Copy rest of the words
- if (carry === 0 && i < a.length && a !== this) {
- for (; i < a.length; i++) {
- this.words[i] = a.words[i];
- }
- }
+ // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
+ var x3 = zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.p)
+ // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
+ var y3 = x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.p)
+ // z3 = v^3 * z1 * z2
+ var z3 = v3.multiply(this.z).multiply(b.z).mod(this.curve.p)
- this.length = Math.max(this.length, i);
+ return new Point(this.curve, x3, y3, z3)
+}
- if (a !== this) {
- this.negative = 1;
- }
+Point.prototype.twice = function () {
+ if (this.curve.isInfinity(this)) return this
+ if (this.y.signum() === 0) return this.curve.infinity
- return this.strip();
- };
+ var x1 = this.x
+ var y1 = this.y
- // Subtract `num` from `this`
- BN.prototype.sub = function sub (num) {
- return this.clone().isub(num);
- };
+ var y1z1 = y1.multiply(this.z).mod(this.curve.p)
+ var y1sqz1 = y1z1.multiply(y1).mod(this.curve.p)
+ var a = this.curve.a
- function smallMulTo (self, num, out) {
- out.negative = num.negative ^ self.negative;
- var len = (self.length + num.length) | 0;
- out.length = len;
- len = (len - 1) | 0;
+ // w = 3 * x1^2 + a * z1^2
+ var w = x1.square().multiply(THREE)
- // Peel one iteration (compiler can't do it, because of code complexity)
- var a = self.words[0] | 0;
- var b = num.words[0] | 0;
- var r = a * b;
+ if (a.signum() !== 0) {
+ w = w.add(this.z.square().multiply(a))
+ }
- var lo = r & 0x3ffffff;
- var carry = (r / 0x4000000) | 0;
- out.words[0] = lo;
+ w = w.mod(this.curve.p)
+ // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
+ var x3 = w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.p)
+ // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
+ var y3 = w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.pow(3)).mod(this.curve.p)
+ // z3 = 8 * (y1 * z1)^3
+ var z3 = y1z1.pow(3).shiftLeft(3).mod(this.curve.p)
- for (var k = 1; k < len; k++) {
- // Sum all words with the same `i + j = k` and accumulate `ncarry`,
- // note that ncarry could be >= 0x3ffffff
- var ncarry = carry >>> 26;
- var rword = carry & 0x3ffffff;
- var maxJ = Math.min(k, num.length - 1);
- for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
- var i = (k - j) | 0;
- a = self.words[i] | 0;
- b = num.words[j] | 0;
- r = a * b + rword;
- ncarry += (r / 0x4000000) | 0;
- rword = r & 0x3ffffff;
+ return new Point(this.curve, x3, y3, z3)
+}
+
+// Simple NAF (Non-Adjacent Form) multiplication algorithm
+// TODO: modularize the multiplication algorithm
+Point.prototype.multiply = function (k) {
+ if (this.curve.isInfinity(this)) return this
+ if (k.signum() === 0) return this.curve.infinity
+
+ var e = k
+ var h = e.multiply(THREE)
+
+ var neg = this.negate()
+ var R = this
+
+ for (var i = h.bitLength() - 2; i > 0; --i) {
+ var hBit = h.testBit(i)
+ var eBit = e.testBit(i)
+
+ R = R.twice()
+
+ if (hBit !== eBit) {
+ R = R.add(hBit ? this : neg)
+ }
+ }
+
+ return R
+}
+
+// Compute this*j + x*k (simultaneous multiplication)
+Point.prototype.multiplyTwo = function (j, x, k) {
+ var i = Math.max(j.bitLength(), k.bitLength()) - 1
+ var R = this.curve.infinity
+ var both = this.add(x)
+
+ while (i >= 0) {
+ var jBit = j.testBit(i)
+ var kBit = k.testBit(i)
+
+ R = R.twice()
+
+ if (jBit) {
+ if (kBit) {
+ R = R.add(both)
+ } else {
+ R = R.add(this)
}
- out.words[k] = rword | 0;
- carry = ncarry | 0;
+ } else if (kBit) {
+ R = R.add(x)
}
- if (carry !== 0) {
- out.words[k] = carry | 0;
- } else {
- out.length--;
+ --i
+ }
+
+ return R
+}
+
+Point.prototype.getEncoded = function (compressed) {
+ if (compressed == null) compressed = this.compressed
+ if (this.curve.isInfinity(this)) return Buffer.alloc(1, 0) // Infinity point encoded is simply '00'
+
+ var x = this.affineX
+ var y = this.affineY
+ var byteLength = this.curve.pLength
+ var buffer
+
+ // 0x02/0x03 | X
+ if (compressed) {
+ buffer = Buffer.allocUnsafe(1 + byteLength)
+ buffer.writeUInt8(y.isEven() ? 0x02 : 0x03, 0)
+
+ // 0x04 | X | Y
+ } else {
+ buffer = Buffer.allocUnsafe(1 + byteLength + byteLength)
+ buffer.writeUInt8(0x04, 0)
+
+ y.toBuffer(byteLength).copy(buffer, 1 + byteLength)
+ }
+
+ x.toBuffer(byteLength).copy(buffer, 1)
+
+ return buffer
+}
+
+Point.decodeFrom = function (curve, buffer) {
+ var type = buffer.readUInt8(0)
+ var compressed = (type !== 4)
+
+ var byteLength = Math.floor((curve.p.bitLength() + 7) / 8)
+ var x = BigInteger.fromBuffer(buffer.slice(1, 1 + byteLength))
+
+ var Q
+ if (compressed) {
+ assert.equal(buffer.length, byteLength + 1, 'Invalid sequence length')
+ assert(type === 0x02 || type === 0x03, 'Invalid sequence tag')
+
+ var isOdd = (type === 0x03)
+ Q = curve.pointFromX(isOdd, x)
+ } else {
+ assert.equal(buffer.length, 1 + byteLength + byteLength, 'Invalid sequence length')
+
+ var y = BigInteger.fromBuffer(buffer.slice(1 + byteLength))
+ Q = Point.fromAffine(curve, x, y)
+ }
+
+ Q.compressed = compressed
+ return Q
+}
+
+Point.prototype.toString = function () {
+ if (this.curve.isInfinity(this)) return '(INFINITY)'
+
+ return '(' + this.affineX.toString() + ',' + this.affineY.toString() + ')'
+}
+
+module.exports = Point
+
+},{"assert":1,"bigi":39,"safe-buffer":101}],95:[function(require,module,exports){
+(function (Buffer){
+'use strict'
+var Transform = require('stream').Transform
+var inherits = require('inherits')
+
+function HashBase (blockSize) {
+ Transform.call(this)
+
+ this._block = new Buffer(blockSize)
+ this._blockSize = blockSize
+ this._blockOffset = 0
+ this._length = [0, 0, 0, 0]
+
+ this._finalized = false
+}
+
+inherits(HashBase, Transform)
+
+HashBase.prototype._transform = function (chunk, encoding, callback) {
+ var error = null
+ try {
+ if (encoding !== 'buffer') chunk = new Buffer(chunk, encoding)
+ this.update(chunk)
+ } catch (err) {
+ error = err
+ }
+
+ callback(error)
+}
+
+HashBase.prototype._flush = function (callback) {
+ var error = null
+ try {
+ this.push(this._digest())
+ } catch (err) {
+ error = err
+ }
+
+ callback(error)
+}
+
+HashBase.prototype.update = function (data, encoding) {
+ if (!Buffer.isBuffer(data) && typeof data !== 'string') throw new TypeError('Data must be a string or a buffer')
+ if (this._finalized) throw new Error('Digest already called')
+ if (!Buffer.isBuffer(data)) data = new Buffer(data, encoding || 'binary')
+
+ // consume data
+ var block = this._block
+ var offset = 0
+ while (this._blockOffset + data.length - offset >= this._blockSize) {
+ for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
+ this._update()
+ this._blockOffset = 0
+ }
+ while (offset < data.length) block[this._blockOffset++] = data[offset++]
+
+ // update length
+ for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
+ this._length[j] += carry
+ carry = (this._length[j] / 0x0100000000) | 0
+ if (carry > 0) this._length[j] -= 0x0100000000 * carry
+ }
+
+ return this
+}
+
+HashBase.prototype._update = function (data) {
+ throw new Error('_update is not implemented')
+}
+
+HashBase.prototype.digest = function (encoding) {
+ if (this._finalized) throw new Error('Digest already called')
+ this._finalized = true
+
+ var digest = this._digest()
+ if (encoding !== undefined) digest = digest.toString(encoding)
+ return digest
+}
+
+HashBase.prototype._digest = function () {
+ throw new Error('_digest is not implemented')
+}
+
+module.exports = HashBase
+
+}).call(this,require("buffer").Buffer)
+},{"buffer":5,"inherits":96,"stream":28}],96:[function(require,module,exports){
+arguments[4][9][0].apply(exports,arguments)
+},{"dup":9}],97:[function(require,module,exports){
+(function (Buffer){
+// constant-space merkle root calculation algorithm
+module.exports = function fastRoot (values, digestFn) {
+ if (!Array.isArray(values)) throw TypeError('Expected values Array')
+ if (typeof digestFn !== 'function') throw TypeError('Expected digest Function')
+
+ var length = values.length
+ var results = values.concat()
+
+ while (length > 1) {
+ var j = 0
+
+ for (var i = 0; i < length; i += 2, ++j) {
+ var left = results[i]
+ var right = i + 1 === length ? left : results[i + 1]
+ var data = Buffer.concat([left, right])
+
+ results[j] = digestFn(data)
}
- return out.strip();
+ length = j
}
- // TODO(indutny): it may be reasonable to omit it for users who don't need
- // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
- // multiplication (like elliptic secp256k1).
- var comb10MulTo = function comb10MulTo (self, num, out) {
- var a = self.words;
- var b = num.words;
- var o = out.words;
- var c = 0;
- var lo;
- var mid;
- var hi;
- var a0 = a[0] | 0;
- var al0 = a0 & 0x1fff;
- var ah0 = a0 >>> 13;
- var a1 = a[1] | 0;
- var al1 = a1 & 0x1fff;
- var ah1 = a1 >>> 13;
- var a2 = a[2] | 0;
- var al2 = a2 & 0x1fff;
- var ah2 = a2 >>> 13;
- var a3 = a[3] | 0;
- var al3 = a3 & 0x1fff;
- var ah3 = a3 >>> 13;
- var a4 = a[4] | 0;
- var al4 = a4 & 0x1fff;
- var ah4 = a4 >>> 13;
- var a5 = a[5] | 0;
- var al5 = a5 & 0x1fff;
- var ah5 = a5 >>> 13;
- var a6 = a[6] | 0;
- var al6 = a6 & 0x1fff;
- var ah6 = a6 >>> 13;
- var a7 = a[7] | 0;
- var al7 = a7 & 0x1fff;
- var ah7 = a7 >>> 13;
- var a8 = a[8] | 0;
- var al8 = a8 & 0x1fff;
- var ah8 = a8 >>> 13;
- var a9 = a[9] | 0;
- var al9 = a9 & 0x1fff;
- var ah9 = a9 >>> 13;
- var b0 = b[0] | 0;
- var bl0 = b0 & 0x1fff;
- var bh0 = b0 >>> 13;
- var b1 = b[1] | 0;
- var bl1 = b1 & 0x1fff;
- var bh1 = b1 >>> 13;
- var b2 = b[2] | 0;
- var bl2 = b2 & 0x1fff;
- var bh2 = b2 >>> 13;
- var b3 = b[3] | 0;
- var bl3 = b3 & 0x1fff;
- var bh3 = b3 >>> 13;
- var b4 = b[4] | 0;
- var bl4 = b4 & 0x1fff;
- var bh4 = b4 >>> 13;
- var b5 = b[5] | 0;
- var bl5 = b5 & 0x1fff;
- var bh5 = b5 >>> 13;
- var b6 = b[6] | 0;
- var bl6 = b6 & 0x1fff;
- var bh6 = b6 >>> 13;
- var b7 = b[7] | 0;
- var bl7 = b7 & 0x1fff;
- var bh7 = b7 >>> 13;
- var b8 = b[8] | 0;
- var bl8 = b8 & 0x1fff;
- var bh8 = b8 >>> 13;
- var b9 = b[9] | 0;
- var bl9 = b9 & 0x1fff;
- var bh9 = b9 >>> 13;
+ return results[0]
+}
- out.negative = self.negative ^ num.negative;
- out.length = 19;
- /* k = 0 */
- lo = Math.imul(al0, bl0);
- mid = Math.imul(al0, bh0);
- mid = (mid + Math.imul(ah0, bl0)) | 0;
- hi = Math.imul(ah0, bh0);
- var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
- w0 &= 0x3ffffff;
- /* k = 1 */
- lo = Math.imul(al1, bl0);
- mid = Math.imul(al1, bh0);
- mid = (mid + Math.imul(ah1, bl0)) | 0;
- hi = Math.imul(ah1, bh0);
- lo = (lo + Math.imul(al0, bl1)) | 0;
- mid = (mid + Math.imul(al0, bh1)) | 0;
- mid = (mid + Math.imul(ah0, bl1)) | 0;
- hi = (hi + Math.imul(ah0, bh1)) | 0;
- var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
- w1 &= 0x3ffffff;
- /* k = 2 */
- lo = Math.imul(al2, bl0);
- mid = Math.imul(al2, bh0);
- mid = (mid + Math.imul(ah2, bl0)) | 0;
- hi = Math.imul(ah2, bh0);
- lo = (lo + Math.imul(al1, bl1)) | 0;
- mid = (mid + Math.imul(al1, bh1)) | 0;
- mid = (mid + Math.imul(ah1, bl1)) | 0;
- hi = (hi + Math.imul(ah1, bh1)) | 0;
- lo = (lo + Math.imul(al0, bl2)) | 0;
- mid = (mid + Math.imul(al0, bh2)) | 0;
- mid = (mid + Math.imul(ah0, bl2)) | 0;
- hi = (hi + Math.imul(ah0, bh2)) | 0;
- var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
- w2 &= 0x3ffffff;
- /* k = 3 */
- lo = Math.imul(al3, bl0);
- mid = Math.imul(al3, bh0);
- mid = (mid + Math.imul(ah3, bl0)) | 0;
- hi = Math.imul(ah3, bh0);
- lo = (lo + Math.imul(al2, bl1)) | 0;
- mid = (mid + Math.imul(al2, bh1)) | 0;
- mid = (mid + Math.imul(ah2, bl1)) | 0;
- hi = (hi + Math.imul(ah2, bh1)) | 0;
- lo = (lo + Math.imul(al1, bl2)) | 0;
- mid = (mid + Math.imul(al1, bh2)) | 0;
- mid = (mid + Math.imul(ah1, bl2)) | 0;
- hi = (hi + Math.imul(ah1, bh2)) | 0;
- lo = (lo + Math.imul(al0, bl3)) | 0;
- mid = (mid + Math.imul(al0, bh3)) | 0;
- mid = (mid + Math.imul(ah0, bl3)) | 0;
- hi = (hi + Math.imul(ah0, bh3)) | 0;
- var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
- w3 &= 0x3ffffff;
- /* k = 4 */
- lo = Math.imul(al4, bl0);
- mid = Math.imul(al4, bh0);
- mid = (mid + Math.imul(ah4, bl0)) | 0;
- hi = Math.imul(ah4, bh0);
- lo = (lo + Math.imul(al3, bl1)) | 0;
- mid = (mid + Math.imul(al3, bh1)) | 0;
- mid = (mid + Math.imul(ah3, bl1)) | 0;
- hi = (hi + Math.imul(ah3, bh1)) | 0;
- lo = (lo + Math.imul(al2, bl2)) | 0;
- mid = (mid + Math.imul(al2, bh2)) | 0;
- mid = (mid + Math.imul(ah2, bl2)) | 0;
- hi = (hi + Math.imul(ah2, bh2)) | 0;
- lo = (lo + Math.imul(al1, bl3)) | 0;
- mid = (mid + Math.imul(al1, bh3)) | 0;
- mid = (mid + Math.imul(ah1, bl3)) | 0;
- hi = (hi + Math.imul(ah1, bh3)) | 0;
- lo = (lo + Math.imul(al0, bl4)) | 0;
- mid = (mid + Math.imul(al0, bh4)) | 0;
- mid = (mid + Math.imul(ah0, bl4)) | 0;
- hi = (hi + Math.imul(ah0, bh4)) | 0;
- var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
- w4 &= 0x3ffffff;
- /* k = 5 */
- lo = Math.imul(al5, bl0);
- mid = Math.imul(al5, bh0);
- mid = (mid + Math.imul(ah5, bl0)) | 0;
- hi = Math.imul(ah5, bh0);
- lo = (lo + Math.imul(al4, bl1)) | 0;
- mid = (mid + Math.imul(al4, bh1)) | 0;
- mid = (mid + Math.imul(ah4, bl1)) | 0;
- hi = (hi + Math.imul(ah4, bh1)) | 0;
- lo = (lo + Math.imul(al3, bl2)) | 0;
- mid = (mid + Math.imul(al3, bh2)) | 0;
- mid = (mid + Math.imul(ah3, bl2)) | 0;
- hi = (hi + Math.imul(ah3, bh2)) | 0;
- lo = (lo + Math.imul(al2, bl3)) | 0;
- mid = (mid + Math.imul(al2, bh3)) | 0;
- mid = (mid + Math.imul(ah2, bl3)) | 0;
- hi = (hi + Math.imul(ah2, bh3)) | 0;
- lo = (lo + Math.imul(al1, bl4)) | 0;
- mid = (mid + Math.imul(al1, bh4)) | 0;
- mid = (mid + Math.imul(ah1, bl4)) | 0;
- hi = (hi + Math.imul(ah1, bh4)) | 0;
- lo = (lo + Math.imul(al0, bl5)) | 0;
- mid = (mid + Math.imul(al0, bh5)) | 0;
- mid = (mid + Math.imul(ah0, bl5)) | 0;
- hi = (hi + Math.imul(ah0, bh5)) | 0;
- var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
- w5 &= 0x3ffffff;
- /* k = 6 */
- lo = Math.imul(al6, bl0);
- mid = Math.imul(al6, bh0);
- mid = (mid + Math.imul(ah6, bl0)) | 0;
- hi = Math.imul(ah6, bh0);
- lo = (lo + Math.imul(al5, bl1)) | 0;
- mid = (mid + Math.imul(al5, bh1)) | 0;
- mid = (mid + Math.imul(ah5, bl1)) | 0;
- hi = (hi + Math.imul(ah5, bh1)) | 0;
- lo = (lo + Math.imul(al4, bl2)) | 0;
- mid = (mid + Math.imul(al4, bh2)) | 0;
- mid = (mid + Math.imul(ah4, bl2)) | 0;
- hi = (hi + Math.imul(ah4, bh2)) | 0;
- lo = (lo + Math.imul(al3, bl3)) | 0;
- mid = (mid + Math.imul(al3, bh3)) | 0;
- mid = (mid + Math.imul(ah3, bl3)) | 0;
- hi = (hi + Math.imul(ah3, bh3)) | 0;
- lo = (lo + Math.imul(al2, bl4)) | 0;
- mid = (mid + Math.imul(al2, bh4)) | 0;
- mid = (mid + Math.imul(ah2, bl4)) | 0;
- hi = (hi + Math.imul(ah2, bh4)) | 0;
- lo = (lo + Math.imul(al1, bl5)) | 0;
- mid = (mid + Math.imul(al1, bh5)) | 0;
- mid = (mid + Math.imul(ah1, bl5)) | 0;
- hi = (hi + Math.imul(ah1, bh5)) | 0;
- lo = (lo + Math.imul(al0, bl6)) | 0;
- mid = (mid + Math.imul(al0, bh6)) | 0;
- mid = (mid + Math.imul(ah0, bl6)) | 0;
- hi = (hi + Math.imul(ah0, bh6)) | 0;
- var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
- w6 &= 0x3ffffff;
- /* k = 7 */
- lo = Math.imul(al7, bl0);
- mid = Math.imul(al7, bh0);
- mid = (mid + Math.imul(ah7, bl0)) | 0;
- hi = Math.imul(ah7, bh0);
- lo = (lo + Math.imul(al6, bl1)) | 0;
- mid = (mid + Math.imul(al6, bh1)) | 0;
- mid = (mid + Math.imul(ah6, bl1)) | 0;
- hi = (hi + Math.imul(ah6, bh1)) | 0;
- lo = (lo + Math.imul(al5, bl2)) | 0;
- mid = (mid + Math.imul(al5, bh2)) | 0;
- mid = (mid + Math.imul(ah5, bl2)) | 0;
- hi = (hi + Math.imul(ah5, bh2)) | 0;
- lo = (lo + Math.imul(al4, bl3)) | 0;
- mid = (mid + Math.imul(al4, bh3)) | 0;
- mid = (mid + Math.imul(ah4, bl3)) | 0;
- hi = (hi + Math.imul(ah4, bh3)) | 0;
- lo = (lo + Math.imul(al3, bl4)) | 0;
- mid = (mid + Math.imul(al3, bh4)) | 0;
- mid = (mid + Math.imul(ah3, bl4)) | 0;
- hi = (hi + Math.imul(ah3, bh4)) | 0;
- lo = (lo + Math.imul(al2, bl5)) | 0;
- mid = (mid + Math.imul(al2, bh5)) | 0;
- mid = (mid + Math.imul(ah2, bl5)) | 0;
- hi = (hi + Math.imul(ah2, bh5)) | 0;
- lo = (lo + Math.imul(al1, bl6)) | 0;
- mid = (mid + Math.imul(al1, bh6)) | 0;
- mid = (mid + Math.imul(ah1, bl6)) | 0;
- hi = (hi + Math.imul(ah1, bh6)) | 0;
- lo = (lo + Math.imul(al0, bl7)) | 0;
- mid = (mid + Math.imul(al0, bh7)) | 0;
- mid = (mid + Math.imul(ah0, bl7)) | 0;
- hi = (hi + Math.imul(ah0, bh7)) | 0;
- var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
- w7 &= 0x3ffffff;
- /* k = 8 */
- lo = Math.imul(al8, bl0);
- mid = Math.imul(al8, bh0);
- mid = (mid + Math.imul(ah8, bl0)) | 0;
- hi = Math.imul(ah8, bh0);
- lo = (lo + Math.imul(al7, bl1)) | 0;
- mid = (mid + Math.imul(al7, bh1)) | 0;
- mid = (mid + Math.imul(ah7, bl1)) | 0;
- hi = (hi + Math.imul(ah7, bh1)) | 0;
- lo = (lo + Math.imul(al6, bl2)) | 0;
- mid = (mid + Math.imul(al6, bh2)) | 0;
- mid = (mid + Math.imul(ah6, bl2)) | 0;
- hi = (hi + Math.imul(ah6, bh2)) | 0;
- lo = (lo + Math.imul(al5, bl3)) | 0;
- mid = (mid + Math.imul(al5, bh3)) | 0;
- mid = (mid + Math.imul(ah5, bl3)) | 0;
- hi = (hi + Math.imul(ah5, bh3)) | 0;
- lo = (lo + Math.imul(al4, bl4)) | 0;
- mid = (mid + Math.imul(al4, bh4)) | 0;
- mid = (mid + Math.imul(ah4, bl4)) | 0;
- hi = (hi + Math.imul(ah4, bh4)) | 0;
- lo = (lo + Math.imul(al3, bl5)) | 0;
- mid = (mid + Math.imul(al3, bh5)) | 0;
- mid = (mid + Math.imul(ah3, bl5)) | 0;
- hi = (hi + Math.imul(ah3, bh5)) | 0;
- lo = (lo + Math.imul(al2, bl6)) | 0;
- mid = (mid + Math.imul(al2, bh6)) | 0;
- mid = (mid + Math.imul(ah2, bl6)) | 0;
- hi = (hi + Math.imul(ah2, bh6)) | 0;
- lo = (lo + Math.imul(al1, bl7)) | 0;
- mid = (mid + Math.imul(al1, bh7)) | 0;
- mid = (mid + Math.imul(ah1, bl7)) | 0;
- hi = (hi + Math.imul(ah1, bh7)) | 0;
- lo = (lo + Math.imul(al0, bl8)) | 0;
- mid = (mid + Math.imul(al0, bh8)) | 0;
- mid = (mid + Math.imul(ah0, bl8)) | 0;
- hi = (hi + Math.imul(ah0, bh8)) | 0;
- var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
- w8 &= 0x3ffffff;
- /* k = 9 */
- lo = Math.imul(al9, bl0);
- mid = Math.imul(al9, bh0);
- mid = (mid + Math.imul(ah9, bl0)) | 0;
- hi = Math.imul(ah9, bh0);
- lo = (lo + Math.imul(al8, bl1)) | 0;
- mid = (mid + Math.imul(al8, bh1)) | 0;
- mid = (mid + Math.imul(ah8, bl1)) | 0;
- hi = (hi + Math.imul(ah8, bh1)) | 0;
- lo = (lo + Math.imul(al7, bl2)) | 0;
- mid = (mid + Math.imul(al7, bh2)) | 0;
- mid = (mid + Math.imul(ah7, bl2)) | 0;
- hi = (hi + Math.imul(ah7, bh2)) | 0;
- lo = (lo + Math.imul(al6, bl3)) | 0;
- mid = (mid + Math.imul(al6, bh3)) | 0;
- mid = (mid + Math.imul(ah6, bl3)) | 0;
- hi = (hi + Math.imul(ah6, bh3)) | 0;
- lo = (lo + Math.imul(al5, bl4)) | 0;
- mid = (mid + Math.imul(al5, bh4)) | 0;
- mid = (mid + Math.imul(ah5, bl4)) | 0;
- hi = (hi + Math.imul(ah5, bh4)) | 0;
- lo = (lo + Math.imul(al4, bl5)) | 0;
- mid = (mid + Math.imul(al4, bh5)) | 0;
- mid = (mid + Math.imul(ah4, bl5)) | 0;
- hi = (hi + Math.imul(ah4, bh5)) | 0;
- lo = (lo + Math.imul(al3, bl6)) | 0;
- mid = (mid + Math.imul(al3, bh6)) | 0;
- mid = (mid + Math.imul(ah3, bl6)) | 0;
- hi = (hi + Math.imul(ah3, bh6)) | 0;
- lo = (lo + Math.imul(al2, bl7)) | 0;
- mid = (mid + Math.imul(al2, bh7)) | 0;
- mid = (mid + Math.imul(ah2, bl7)) | 0;
- hi = (hi + Math.imul(ah2, bh7)) | 0;
- lo = (lo + Math.imul(al1, bl8)) | 0;
- mid = (mid + Math.imul(al1, bh8)) | 0;
- mid = (mid + Math.imul(ah1, bl8)) | 0;
- hi = (hi + Math.imul(ah1, bh8)) | 0;
- lo = (lo + Math.imul(al0, bl9)) | 0;
- mid = (mid + Math.imul(al0, bh9)) | 0;
- mid = (mid + Math.imul(ah0, bl9)) | 0;
- hi = (hi + Math.imul(ah0, bh9)) | 0;
- var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
- w9 &= 0x3ffffff;
- /* k = 10 */
- lo = Math.imul(al9, bl1);
- mid = Math.imul(al9, bh1);
- mid = (mid + Math.imul(ah9, bl1)) | 0;
- hi = Math.imul(ah9, bh1);
- lo = (lo + Math.imul(al8, bl2)) | 0;
- mid = (mid + Math.imul(al8, bh2)) | 0;
- mid = (mid + Math.imul(ah8, bl2)) | 0;
- hi = (hi + Math.imul(ah8, bh2)) | 0;
- lo = (lo + Math.imul(al7, bl3)) | 0;
- mid = (mid + Math.imul(al7, bh3)) | 0;
- mid = (mid + Math.imul(ah7, bl3)) | 0;
- hi = (hi + Math.imul(ah7, bh3)) | 0;
- lo = (lo + Math.imul(al6, bl4)) | 0;
- mid = (mid + Math.imul(al6, bh4)) | 0;
- mid = (mid + Math.imul(ah6, bl4)) | 0;
- hi = (hi + Math.imul(ah6, bh4)) | 0;
- lo = (lo + Math.imul(al5, bl5)) | 0;
- mid = (mid + Math.imul(al5, bh5)) | 0;
- mid = (mid + Math.imul(ah5, bl5)) | 0;
- hi = (hi + Math.imul(ah5, bh5)) | 0;
- lo = (lo + Math.imul(al4, bl6)) | 0;
- mid = (mid + Math.imul(al4, bh6)) | 0;
- mid = (mid + Math.imul(ah4, bl6)) | 0;
- hi = (hi + Math.imul(ah4, bh6)) | 0;
- lo = (lo + Math.imul(al3, bl7)) | 0;
- mid = (mid + Math.imul(al3, bh7)) | 0;
- mid = (mid + Math.imul(ah3, bl7)) | 0;
- hi = (hi + Math.imul(ah3, bh7)) | 0;
- lo = (lo + Math.imul(al2, bl8)) | 0;
- mid = (mid + Math.imul(al2, bh8)) | 0;
- mid = (mid + Math.imul(ah2, bl8)) | 0;
- hi = (hi + Math.imul(ah2, bh8)) | 0;
- lo = (lo + Math.imul(al1, bl9)) | 0;
- mid = (mid + Math.imul(al1, bh9)) | 0;
- mid = (mid + Math.imul(ah1, bl9)) | 0;
- hi = (hi + Math.imul(ah1, bh9)) | 0;
- var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
- w10 &= 0x3ffffff;
- /* k = 11 */
- lo = Math.imul(al9, bl2);
- mid = Math.imul(al9, bh2);
- mid = (mid + Math.imul(ah9, bl2)) | 0;
- hi = Math.imul(ah9, bh2);
- lo = (lo + Math.imul(al8, bl3)) | 0;
- mid = (mid + Math.imul(al8, bh3)) | 0;
- mid = (mid + Math.imul(ah8, bl3)) | 0;
- hi = (hi + Math.imul(ah8, bh3)) | 0;
- lo = (lo + Math.imul(al7, bl4)) | 0;
- mid = (mid + Math.imul(al7, bh4)) | 0;
- mid = (mid + Math.imul(ah7, bl4)) | 0;
- hi = (hi + Math.imul(ah7, bh4)) | 0;
- lo = (lo + Math.imul(al6, bl5)) | 0;
- mid = (mid + Math.imul(al6, bh5)) | 0;
- mid = (mid + Math.imul(ah6, bl5)) | 0;
- hi = (hi + Math.imul(ah6, bh5)) | 0;
- lo = (lo + Math.imul(al5, bl6)) | 0;
- mid = (mid + Math.imul(al5, bh6)) | 0;
- mid = (mid + Math.imul(ah5, bl6)) | 0;
- hi = (hi + Math.imul(ah5, bh6)) | 0;
- lo = (lo + Math.imul(al4, bl7)) | 0;
- mid = (mid + Math.imul(al4, bh7)) | 0;
- mid = (mid + Math.imul(ah4, bl7)) | 0;
- hi = (hi + Math.imul(ah4, bh7)) | 0;
- lo = (lo + Math.imul(al3, bl8)) | 0;
- mid = (mid + Math.imul(al3, bh8)) | 0;
- mid = (mid + Math.imul(ah3, bl8)) | 0;
- hi = (hi + Math.imul(ah3, bh8)) | 0;
- lo = (lo + Math.imul(al2, bl9)) | 0;
- mid = (mid + Math.imul(al2, bh9)) | 0;
- mid = (mid + Math.imul(ah2, bl9)) | 0;
- hi = (hi + Math.imul(ah2, bh9)) | 0;
- var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
- w11 &= 0x3ffffff;
- /* k = 12 */
- lo = Math.imul(al9, bl3);
- mid = Math.imul(al9, bh3);
- mid = (mid + Math.imul(ah9, bl3)) | 0;
- hi = Math.imul(ah9, bh3);
- lo = (lo + Math.imul(al8, bl4)) | 0;
- mid = (mid + Math.imul(al8, bh4)) | 0;
- mid = (mid + Math.imul(ah8, bl4)) | 0;
- hi = (hi + Math.imul(ah8, bh4)) | 0;
- lo = (lo + Math.imul(al7, bl5)) | 0;
- mid = (mid + Math.imul(al7, bh5)) | 0;
- mid = (mid + Math.imul(ah7, bl5)) | 0;
- hi = (hi + Math.imul(ah7, bh5)) | 0;
- lo = (lo + Math.imul(al6, bl6)) | 0;
- mid = (mid + Math.imul(al6, bh6)) | 0;
- mid = (mid + Math.imul(ah6, bl6)) | 0;
- hi = (hi + Math.imul(ah6, bh6)) | 0;
- lo = (lo + Math.imul(al5, bl7)) | 0;
- mid = (mid + Math.imul(al5, bh7)) | 0;
- mid = (mid + Math.imul(ah5, bl7)) | 0;
- hi = (hi + Math.imul(ah5, bh7)) | 0;
- lo = (lo + Math.imul(al4, bl8)) | 0;
- mid = (mid + Math.imul(al4, bh8)) | 0;
- mid = (mid + Math.imul(ah4, bl8)) | 0;
- hi = (hi + Math.imul(ah4, bh8)) | 0;
- lo = (lo + Math.imul(al3, bl9)) | 0;
- mid = (mid + Math.imul(al3, bh9)) | 0;
- mid = (mid + Math.imul(ah3, bl9)) | 0;
- hi = (hi + Math.imul(ah3, bh9)) | 0;
- var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
- w12 &= 0x3ffffff;
- /* k = 13 */
- lo = Math.imul(al9, bl4);
- mid = Math.imul(al9, bh4);
- mid = (mid + Math.imul(ah9, bl4)) | 0;
- hi = Math.imul(ah9, bh4);
- lo = (lo + Math.imul(al8, bl5)) | 0;
- mid = (mid + Math.imul(al8, bh5)) | 0;
- mid = (mid + Math.imul(ah8, bl5)) | 0;
- hi = (hi + Math.imul(ah8, bh5)) | 0;
- lo = (lo + Math.imul(al7, bl6)) | 0;
- mid = (mid + Math.imul(al7, bh6)) | 0;
- mid = (mid + Math.imul(ah7, bl6)) | 0;
- hi = (hi + Math.imul(ah7, bh6)) | 0;
- lo = (lo + Math.imul(al6, bl7)) | 0;
- mid = (mid + Math.imul(al6, bh7)) | 0;
- mid = (mid + Math.imul(ah6, bl7)) | 0;
- hi = (hi + Math.imul(ah6, bh7)) | 0;
- lo = (lo + Math.imul(al5, bl8)) | 0;
- mid = (mid + Math.imul(al5, bh8)) | 0;
- mid = (mid + Math.imul(ah5, bl8)) | 0;
- hi = (hi + Math.imul(ah5, bh8)) | 0;
- lo = (lo + Math.imul(al4, bl9)) | 0;
- mid = (mid + Math.imul(al4, bh9)) | 0;
- mid = (mid + Math.imul(ah4, bl9)) | 0;
- hi = (hi + Math.imul(ah4, bh9)) | 0;
- var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
- w13 &= 0x3ffffff;
- /* k = 14 */
- lo = Math.imul(al9, bl5);
- mid = Math.imul(al9, bh5);
- mid = (mid + Math.imul(ah9, bl5)) | 0;
- hi = Math.imul(ah9, bh5);
- lo = (lo + Math.imul(al8, bl6)) | 0;
- mid = (mid + Math.imul(al8, bh6)) | 0;
- mid = (mid + Math.imul(ah8, bl6)) | 0;
- hi = (hi + Math.imul(ah8, bh6)) | 0;
- lo = (lo + Math.imul(al7, bl7)) | 0;
- mid = (mid + Math.imul(al7, bh7)) | 0;
- mid = (mid + Math.imul(ah7, bl7)) | 0;
- hi = (hi + Math.imul(ah7, bh7)) | 0;
- lo = (lo + Math.imul(al6, bl8)) | 0;
- mid = (mid + Math.imul(al6, bh8)) | 0;
- mid = (mid + Math.imul(ah6, bl8)) | 0;
- hi = (hi + Math.imul(ah6, bh8)) | 0;
- lo = (lo + Math.imul(al5, bl9)) | 0;
- mid = (mid + Math.imul(al5, bh9)) | 0;
- mid = (mid + Math.imul(ah5, bl9)) | 0;
- hi = (hi + Math.imul(ah5, bh9)) | 0;
- var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
- w14 &= 0x3ffffff;
- /* k = 15 */
- lo = Math.imul(al9, bl6);
- mid = Math.imul(al9, bh6);
- mid = (mid + Math.imul(ah9, bl6)) | 0;
- hi = Math.imul(ah9, bh6);
- lo = (lo + Math.imul(al8, bl7)) | 0;
- mid = (mid + Math.imul(al8, bh7)) | 0;
- mid = (mid + Math.imul(ah8, bl7)) | 0;
- hi = (hi + Math.imul(ah8, bh7)) | 0;
- lo = (lo + Math.imul(al7, bl8)) | 0;
- mid = (mid + Math.imul(al7, bh8)) | 0;
- mid = (mid + Math.imul(ah7, bl8)) | 0;
- hi = (hi + Math.imul(ah7, bh8)) | 0;
- lo = (lo + Math.imul(al6, bl9)) | 0;
- mid = (mid + Math.imul(al6, bh9)) | 0;
- mid = (mid + Math.imul(ah6, bl9)) | 0;
- hi = (hi + Math.imul(ah6, bh9)) | 0;
- var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
- w15 &= 0x3ffffff;
- /* k = 16 */
- lo = Math.imul(al9, bl7);
- mid = Math.imul(al9, bh7);
- mid = (mid + Math.imul(ah9, bl7)) | 0;
- hi = Math.imul(ah9, bh7);
- lo = (lo + Math.imul(al8, bl8)) | 0;
- mid = (mid + Math.imul(al8, bh8)) | 0;
- mid = (mid + Math.imul(ah8, bl8)) | 0;
- hi = (hi + Math.imul(ah8, bh8)) | 0;
- lo = (lo + Math.imul(al7, bl9)) | 0;
- mid = (mid + Math.imul(al7, bh9)) | 0;
- mid = (mid + Math.imul(ah7, bl9)) | 0;
- hi = (hi + Math.imul(ah7, bh9)) | 0;
- var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
- w16 &= 0x3ffffff;
- /* k = 17 */
- lo = Math.imul(al9, bl8);
- mid = Math.imul(al9, bh8);
- mid = (mid + Math.imul(ah9, bl8)) | 0;
- hi = Math.imul(ah9, bh8);
- lo = (lo + Math.imul(al8, bl9)) | 0;
- mid = (mid + Math.imul(al8, bh9)) | 0;
- mid = (mid + Math.imul(ah8, bl9)) | 0;
- hi = (hi + Math.imul(ah8, bh9)) | 0;
- var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
- w17 &= 0x3ffffff;
- /* k = 18 */
- lo = Math.imul(al9, bl9);
- mid = Math.imul(al9, bh9);
- mid = (mid + Math.imul(ah9, bl9)) | 0;
- hi = Math.imul(ah9, bh9);
- var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
- c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
- w18 &= 0x3ffffff;
- o[0] = w0;
- o[1] = w1;
- o[2] = w2;
- o[3] = w3;
- o[4] = w4;
- o[5] = w5;
- o[6] = w6;
- o[7] = w7;
- o[8] = w8;
- o[9] = w9;
- o[10] = w10;
- o[11] = w11;
- o[12] = w12;
- o[13] = w13;
- o[14] = w14;
- o[15] = w15;
- o[16] = w16;
- o[17] = w17;
- o[18] = w18;
- if (c !== 0) {
- o[19] = c;
- out.length++;
- }
- return out;
- };
-
- // Polyfill comb
- if (!Math.imul) {
- comb10MulTo = smallMulTo;
- }
+}).call(this,require("buffer").Buffer)
+},{"buffer":5}],98:[function(require,module,exports){
+var OPS = require('bitcoin-ops')
- function bigMulTo (self, num, out) {
- out.negative = num.negative ^ self.negative;
- out.length = self.length + num.length;
+function encodingLength (i) {
+ return i < OPS.OP_PUSHDATA1 ? 1
+ : i <= 0xff ? 2
+ : i <= 0xffff ? 3
+ : 5
+}
- var carry = 0;
- var hncarry = 0;
- for (var k = 0; k < out.length - 1; k++) {
- // Sum all words with the same `i + j = k` and accumulate `ncarry`,
- // note that ncarry could be >= 0x3ffffff
- var ncarry = hncarry;
- hncarry = 0;
- var rword = carry & 0x3ffffff;
- var maxJ = Math.min(k, num.length - 1);
- for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
- var i = k - j;
- var a = self.words[i] | 0;
- var b = num.words[j] | 0;
- var r = a * b;
+function encode (buffer, number, offset) {
+ var size = encodingLength(number)
- var lo = r & 0x3ffffff;
- ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
- lo = (lo + rword) | 0;
- rword = lo & 0x3ffffff;
- ncarry = (ncarry + (lo >>> 26)) | 0;
+ // ~6 bit
+ if (size === 1) {
+ buffer.writeUInt8(number, offset)
- hncarry += ncarry >>> 26;
- ncarry &= 0x3ffffff;
- }
- out.words[k] = rword;
- carry = ncarry;
- ncarry = hncarry;
- }
- if (carry !== 0) {
- out.words[k] = carry;
- } else {
- out.length--;
- }
+ // 8 bit
+ } else if (size === 2) {
+ buffer.writeUInt8(OPS.OP_PUSHDATA1, offset)
+ buffer.writeUInt8(number, offset + 1)
- return out.strip();
- }
+ // 16 bit
+ } else if (size === 3) {
+ buffer.writeUInt8(OPS.OP_PUSHDATA2, offset)
+ buffer.writeUInt16LE(number, offset + 1)
- function jumboMulTo (self, num, out) {
- var fftm = new FFTM();
- return fftm.mulp(self, num, out);
+ // 32 bit
+ } else {
+ buffer.writeUInt8(OPS.OP_PUSHDATA4, offset)
+ buffer.writeUInt32LE(number, offset + 1)
}
- BN.prototype.mulTo = function mulTo (num, out) {
- var res;
- var len = this.length + num.length;
- if (this.length === 10 && num.length === 10) {
- res = comb10MulTo(this, num, out);
- } else if (len < 63) {
- res = smallMulTo(this, num, out);
- } else if (len < 1024) {
- res = bigMulTo(this, num, out);
- } else {
- res = jumboMulTo(this, num, out);
- }
+ return size
+}
- return res;
- };
+function decode (buffer, offset) {
+ var opcode = buffer.readUInt8(offset)
+ var number, size
- // Cooley-Tukey algorithm for FFT
- // slightly revisited to rely on looping instead of recursion
+ // ~6 bit
+ if (opcode < OPS.OP_PUSHDATA1) {
+ number = opcode
+ size = 1
- function FFTM (x, y) {
- this.x = x;
- this.y = y;
- }
+ // 8 bit
+ } else if (opcode === OPS.OP_PUSHDATA1) {
+ if (offset + 2 > buffer.length) return null
+ number = buffer.readUInt8(offset + 1)
+ size = 2
- FFTM.prototype.makeRBT = function makeRBT (N) {
- var t = new Array(N);
- var l = BN.prototype._countBits(N) - 1;
- for (var i = 0; i < N; i++) {
- t[i] = this.revBin(i, l, N);
- }
+ // 16 bit
+ } else if (opcode === OPS.OP_PUSHDATA2) {
+ if (offset + 3 > buffer.length) return null
+ number = buffer.readUInt16LE(offset + 1)
+ size = 3
- return t;
- };
+ // 32 bit
+ } else {
+ if (offset + 5 > buffer.length) return null
+ if (opcode !== OPS.OP_PUSHDATA4) throw new Error('Unexpected opcode')
- // Returns binary-reversed representation of `x`
- FFTM.prototype.revBin = function revBin (x, l, N) {
- if (x === 0 || x === N - 1) return x;
+ number = buffer.readUInt32LE(offset + 1)
+ size = 5
+ }
- var rb = 0;
- for (var i = 0; i < l; i++) {
- rb |= (x & 1) << (l - i - 1);
- x >>= 1;
- }
+ return {
+ opcode: opcode,
+ number: number,
+ size: size
+ }
+}
- return rb;
- };
+module.exports = {
+ encodingLength: encodingLength,
+ encode: encode,
+ decode: decode
+}
- // Performs "tweedling" phase, therefore 'emulating'
- // behaviour of the recursive algorithm
- FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
- for (var i = 0; i < N; i++) {
- rtws[i] = rws[rbt[i]];
- itws[i] = iws[rbt[i]];
- }
- };
+},{"bitcoin-ops":42}],99:[function(require,module,exports){
+(function (process,global){
+'use strict'
- FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
- this.permute(rbt, rws, iws, rtws, itws, N);
+function oldBrowser () {
+ throw new Error('Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11')
+}
- for (var s = 1; s < N; s <<= 1) {
- var l = s << 1;
+var Buffer = require('safe-buffer').Buffer
+var crypto = global.crypto || global.msCrypto
- var rtwdf = Math.cos(2 * Math.PI / l);
- var itwdf = Math.sin(2 * Math.PI / l);
+if (crypto && crypto.getRandomValues) {
+ module.exports = randomBytes
+} else {
+ module.exports = oldBrowser
+}
- for (var p = 0; p < N; p += l) {
- var rtwdf_ = rtwdf;
- var itwdf_ = itwdf;
+function randomBytes (size, cb) {
+ // phantomjs needs to throw
+ if (size > 65536) throw new Error('requested too many random bytes')
+ // in case browserify isn't using the Uint8Array version
+ var rawBytes = new global.Uint8Array(size)
- for (var j = 0; j < s; j++) {
- var re = rtws[p + j];
- var ie = itws[p + j];
+ // This will not work in older browsers.
+ // See https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues
+ if (size > 0) { // getRandomValues fails on IE if size == 0
+ crypto.getRandomValues(rawBytes)
+ }
- var ro = rtws[p + j + s];
- var io = itws[p + j + s];
+ // XXX: phantomjs doesn't like a buffer being passed here
+ var bytes = Buffer.from(rawBytes.buffer)
- var rx = rtwdf_ * ro - itwdf_ * io;
+ if (typeof cb === 'function') {
+ return process.nextTick(function () {
+ cb(null, bytes)
+ })
+ }
- io = rtwdf_ * io + itwdf_ * ro;
- ro = rx;
+ return bytes
+}
- rtws[p + j] = re + ro;
- itws[p + j] = ie + io;
-
- rtws[p + j + s] = re - ro;
- itws[p + j + s] = ie - io;
-
- /* jshint maxdepth : false */
- if (j !== l) {
- rx = rtwdf * rtwdf_ - itwdf * itwdf_;
-
- itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
- rtwdf_ = rx;
- }
- }
- }
- }
- };
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"_process":13,"safe-buffer":101}],100:[function(require,module,exports){
+(function (Buffer){
+'use strict'
+var inherits = require('inherits')
+var HashBase = require('hash-base')
- FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
- var N = Math.max(m, n) | 1;
- var odd = N & 1;
- var i = 0;
- for (N = N / 2 | 0; N; N = N >>> 1) {
- i++;
- }
+function RIPEMD160 () {
+ HashBase.call(this, 64)
- return 1 << i + 1 + odd;
- };
+ // state
+ this._a = 0x67452301
+ this._b = 0xefcdab89
+ this._c = 0x98badcfe
+ this._d = 0x10325476
+ this._e = 0xc3d2e1f0
+}
- FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
- if (N <= 1) return;
+inherits(RIPEMD160, HashBase)
- for (var i = 0; i < N / 2; i++) {
- var t = rws[i];
+RIPEMD160.prototype._update = function () {
+ var m = new Array(16)
+ for (var i = 0; i < 16; ++i) m[i] = this._block.readInt32LE(i * 4)
- rws[i] = rws[N - i - 1];
- rws[N - i - 1] = t;
+ var al = this._a
+ var bl = this._b
+ var cl = this._c
+ var dl = this._d
+ var el = this._e
- t = iws[i];
+ // Mj = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+ // K = 0x00000000
+ // Sj = 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8
+ al = fn1(al, bl, cl, dl, el, m[0], 0x00000000, 11); cl = rotl(cl, 10)
+ el = fn1(el, al, bl, cl, dl, m[1], 0x00000000, 14); bl = rotl(bl, 10)
+ dl = fn1(dl, el, al, bl, cl, m[2], 0x00000000, 15); al = rotl(al, 10)
+ cl = fn1(cl, dl, el, al, bl, m[3], 0x00000000, 12); el = rotl(el, 10)
+ bl = fn1(bl, cl, dl, el, al, m[4], 0x00000000, 5); dl = rotl(dl, 10)
+ al = fn1(al, bl, cl, dl, el, m[5], 0x00000000, 8); cl = rotl(cl, 10)
+ el = fn1(el, al, bl, cl, dl, m[6], 0x00000000, 7); bl = rotl(bl, 10)
+ dl = fn1(dl, el, al, bl, cl, m[7], 0x00000000, 9); al = rotl(al, 10)
+ cl = fn1(cl, dl, el, al, bl, m[8], 0x00000000, 11); el = rotl(el, 10)
+ bl = fn1(bl, cl, dl, el, al, m[9], 0x00000000, 13); dl = rotl(dl, 10)
+ al = fn1(al, bl, cl, dl, el, m[10], 0x00000000, 14); cl = rotl(cl, 10)
+ el = fn1(el, al, bl, cl, dl, m[11], 0x00000000, 15); bl = rotl(bl, 10)
+ dl = fn1(dl, el, al, bl, cl, m[12], 0x00000000, 6); al = rotl(al, 10)
+ cl = fn1(cl, dl, el, al, bl, m[13], 0x00000000, 7); el = rotl(el, 10)
+ bl = fn1(bl, cl, dl, el, al, m[14], 0x00000000, 9); dl = rotl(dl, 10)
+ al = fn1(al, bl, cl, dl, el, m[15], 0x00000000, 8); cl = rotl(cl, 10)
- iws[i] = -iws[N - i - 1];
- iws[N - i - 1] = -t;
- }
- };
+ // Mj = 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8
+ // K = 0x5a827999
+ // Sj = 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12
+ el = fn2(el, al, bl, cl, dl, m[7], 0x5a827999, 7); bl = rotl(bl, 10)
+ dl = fn2(dl, el, al, bl, cl, m[4], 0x5a827999, 6); al = rotl(al, 10)
+ cl = fn2(cl, dl, el, al, bl, m[13], 0x5a827999, 8); el = rotl(el, 10)
+ bl = fn2(bl, cl, dl, el, al, m[1], 0x5a827999, 13); dl = rotl(dl, 10)
+ al = fn2(al, bl, cl, dl, el, m[10], 0x5a827999, 11); cl = rotl(cl, 10)
+ el = fn2(el, al, bl, cl, dl, m[6], 0x5a827999, 9); bl = rotl(bl, 10)
+ dl = fn2(dl, el, al, bl, cl, m[15], 0x5a827999, 7); al = rotl(al, 10)
+ cl = fn2(cl, dl, el, al, bl, m[3], 0x5a827999, 15); el = rotl(el, 10)
+ bl = fn2(bl, cl, dl, el, al, m[12], 0x5a827999, 7); dl = rotl(dl, 10)
+ al = fn2(al, bl, cl, dl, el, m[0], 0x5a827999, 12); cl = rotl(cl, 10)
+ el = fn2(el, al, bl, cl, dl, m[9], 0x5a827999, 15); bl = rotl(bl, 10)
+ dl = fn2(dl, el, al, bl, cl, m[5], 0x5a827999, 9); al = rotl(al, 10)
+ cl = fn2(cl, dl, el, al, bl, m[2], 0x5a827999, 11); el = rotl(el, 10)
+ bl = fn2(bl, cl, dl, el, al, m[14], 0x5a827999, 7); dl = rotl(dl, 10)
+ al = fn2(al, bl, cl, dl, el, m[11], 0x5a827999, 13); cl = rotl(cl, 10)
+ el = fn2(el, al, bl, cl, dl, m[8], 0x5a827999, 12); bl = rotl(bl, 10)
- FFTM.prototype.normalize13b = function normalize13b (ws, N) {
- var carry = 0;
- for (var i = 0; i < N / 2; i++) {
- var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
- Math.round(ws[2 * i] / N) +
- carry;
+ // Mj = 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12
+ // K = 0x6ed9eba1
+ // Sj = 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5
+ dl = fn3(dl, el, al, bl, cl, m[3], 0x6ed9eba1, 11); al = rotl(al, 10)
+ cl = fn3(cl, dl, el, al, bl, m[10], 0x6ed9eba1, 13); el = rotl(el, 10)
+ bl = fn3(bl, cl, dl, el, al, m[14], 0x6ed9eba1, 6); dl = rotl(dl, 10)
+ al = fn3(al, bl, cl, dl, el, m[4], 0x6ed9eba1, 7); cl = rotl(cl, 10)
+ el = fn3(el, al, bl, cl, dl, m[9], 0x6ed9eba1, 14); bl = rotl(bl, 10)
+ dl = fn3(dl, el, al, bl, cl, m[15], 0x6ed9eba1, 9); al = rotl(al, 10)
+ cl = fn3(cl, dl, el, al, bl, m[8], 0x6ed9eba1, 13); el = rotl(el, 10)
+ bl = fn3(bl, cl, dl, el, al, m[1], 0x6ed9eba1, 15); dl = rotl(dl, 10)
+ al = fn3(al, bl, cl, dl, el, m[2], 0x6ed9eba1, 14); cl = rotl(cl, 10)
+ el = fn3(el, al, bl, cl, dl, m[7], 0x6ed9eba1, 8); bl = rotl(bl, 10)
+ dl = fn3(dl, el, al, bl, cl, m[0], 0x6ed9eba1, 13); al = rotl(al, 10)
+ cl = fn3(cl, dl, el, al, bl, m[6], 0x6ed9eba1, 6); el = rotl(el, 10)
+ bl = fn3(bl, cl, dl, el, al, m[13], 0x6ed9eba1, 5); dl = rotl(dl, 10)
+ al = fn3(al, bl, cl, dl, el, m[11], 0x6ed9eba1, 12); cl = rotl(cl, 10)
+ el = fn3(el, al, bl, cl, dl, m[5], 0x6ed9eba1, 7); bl = rotl(bl, 10)
+ dl = fn3(dl, el, al, bl, cl, m[12], 0x6ed9eba1, 5); al = rotl(al, 10)
- ws[i] = w & 0x3ffffff;
+ // Mj = 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2
+ // K = 0x8f1bbcdc
+ // Sj = 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12
+ cl = fn4(cl, dl, el, al, bl, m[1], 0x8f1bbcdc, 11); el = rotl(el, 10)
+ bl = fn4(bl, cl, dl, el, al, m[9], 0x8f1bbcdc, 12); dl = rotl(dl, 10)
+ al = fn4(al, bl, cl, dl, el, m[11], 0x8f1bbcdc, 14); cl = rotl(cl, 10)
+ el = fn4(el, al, bl, cl, dl, m[10], 0x8f1bbcdc, 15); bl = rotl(bl, 10)
+ dl = fn4(dl, el, al, bl, cl, m[0], 0x8f1bbcdc, 14); al = rotl(al, 10)
+ cl = fn4(cl, dl, el, al, bl, m[8], 0x8f1bbcdc, 15); el = rotl(el, 10)
+ bl = fn4(bl, cl, dl, el, al, m[12], 0x8f1bbcdc, 9); dl = rotl(dl, 10)
+ al = fn4(al, bl, cl, dl, el, m[4], 0x8f1bbcdc, 8); cl = rotl(cl, 10)
+ el = fn4(el, al, bl, cl, dl, m[13], 0x8f1bbcdc, 9); bl = rotl(bl, 10)
+ dl = fn4(dl, el, al, bl, cl, m[3], 0x8f1bbcdc, 14); al = rotl(al, 10)
+ cl = fn4(cl, dl, el, al, bl, m[7], 0x8f1bbcdc, 5); el = rotl(el, 10)
+ bl = fn4(bl, cl, dl, el, al, m[15], 0x8f1bbcdc, 6); dl = rotl(dl, 10)
+ al = fn4(al, bl, cl, dl, el, m[14], 0x8f1bbcdc, 8); cl = rotl(cl, 10)
+ el = fn4(el, al, bl, cl, dl, m[5], 0x8f1bbcdc, 6); bl = rotl(bl, 10)
+ dl = fn4(dl, el, al, bl, cl, m[6], 0x8f1bbcdc, 5); al = rotl(al, 10)
+ cl = fn4(cl, dl, el, al, bl, m[2], 0x8f1bbcdc, 12); el = rotl(el, 10)
- if (w < 0x4000000) {
- carry = 0;
- } else {
- carry = w / 0x4000000 | 0;
- }
- }
+ // Mj = 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13
+ // K = 0xa953fd4e
+ // Sj = 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6
+ bl = fn5(bl, cl, dl, el, al, m[4], 0xa953fd4e, 9); dl = rotl(dl, 10)
+ al = fn5(al, bl, cl, dl, el, m[0], 0xa953fd4e, 15); cl = rotl(cl, 10)
+ el = fn5(el, al, bl, cl, dl, m[5], 0xa953fd4e, 5); bl = rotl(bl, 10)
+ dl = fn5(dl, el, al, bl, cl, m[9], 0xa953fd4e, 11); al = rotl(al, 10)
+ cl = fn5(cl, dl, el, al, bl, m[7], 0xa953fd4e, 6); el = rotl(el, 10)
+ bl = fn5(bl, cl, dl, el, al, m[12], 0xa953fd4e, 8); dl = rotl(dl, 10)
+ al = fn5(al, bl, cl, dl, el, m[2], 0xa953fd4e, 13); cl = rotl(cl, 10)
+ el = fn5(el, al, bl, cl, dl, m[10], 0xa953fd4e, 12); bl = rotl(bl, 10)
+ dl = fn5(dl, el, al, bl, cl, m[14], 0xa953fd4e, 5); al = rotl(al, 10)
+ cl = fn5(cl, dl, el, al, bl, m[1], 0xa953fd4e, 12); el = rotl(el, 10)
+ bl = fn5(bl, cl, dl, el, al, m[3], 0xa953fd4e, 13); dl = rotl(dl, 10)
+ al = fn5(al, bl, cl, dl, el, m[8], 0xa953fd4e, 14); cl = rotl(cl, 10)
+ el = fn5(el, al, bl, cl, dl, m[11], 0xa953fd4e, 11); bl = rotl(bl, 10)
+ dl = fn5(dl, el, al, bl, cl, m[6], 0xa953fd4e, 8); al = rotl(al, 10)
+ cl = fn5(cl, dl, el, al, bl, m[15], 0xa953fd4e, 5); el = rotl(el, 10)
+ bl = fn5(bl, cl, dl, el, al, m[13], 0xa953fd4e, 6); dl = rotl(dl, 10)
- return ws;
- };
+ var ar = this._a
+ var br = this._b
+ var cr = this._c
+ var dr = this._d
+ var er = this._e
- FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
- var carry = 0;
- for (var i = 0; i < len; i++) {
- carry = carry + (ws[i] | 0);
+ // M'j = 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12
+ // K' = 0x50a28be6
+ // S'j = 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6
+ ar = fn5(ar, br, cr, dr, er, m[5], 0x50a28be6, 8); cr = rotl(cr, 10)
+ er = fn5(er, ar, br, cr, dr, m[14], 0x50a28be6, 9); br = rotl(br, 10)
+ dr = fn5(dr, er, ar, br, cr, m[7], 0x50a28be6, 9); ar = rotl(ar, 10)
+ cr = fn5(cr, dr, er, ar, br, m[0], 0x50a28be6, 11); er = rotl(er, 10)
+ br = fn5(br, cr, dr, er, ar, m[9], 0x50a28be6, 13); dr = rotl(dr, 10)
+ ar = fn5(ar, br, cr, dr, er, m[2], 0x50a28be6, 15); cr = rotl(cr, 10)
+ er = fn5(er, ar, br, cr, dr, m[11], 0x50a28be6, 15); br = rotl(br, 10)
+ dr = fn5(dr, er, ar, br, cr, m[4], 0x50a28be6, 5); ar = rotl(ar, 10)
+ cr = fn5(cr, dr, er, ar, br, m[13], 0x50a28be6, 7); er = rotl(er, 10)
+ br = fn5(br, cr, dr, er, ar, m[6], 0x50a28be6, 7); dr = rotl(dr, 10)
+ ar = fn5(ar, br, cr, dr, er, m[15], 0x50a28be6, 8); cr = rotl(cr, 10)
+ er = fn5(er, ar, br, cr, dr, m[8], 0x50a28be6, 11); br = rotl(br, 10)
+ dr = fn5(dr, er, ar, br, cr, m[1], 0x50a28be6, 14); ar = rotl(ar, 10)
+ cr = fn5(cr, dr, er, ar, br, m[10], 0x50a28be6, 14); er = rotl(er, 10)
+ br = fn5(br, cr, dr, er, ar, m[3], 0x50a28be6, 12); dr = rotl(dr, 10)
+ ar = fn5(ar, br, cr, dr, er, m[12], 0x50a28be6, 6); cr = rotl(cr, 10)
- rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
- rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
- }
+ // M'j = 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2
+ // K' = 0x5c4dd124
+ // S'j = 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11
+ er = fn4(er, ar, br, cr, dr, m[6], 0x5c4dd124, 9); br = rotl(br, 10)
+ dr = fn4(dr, er, ar, br, cr, m[11], 0x5c4dd124, 13); ar = rotl(ar, 10)
+ cr = fn4(cr, dr, er, ar, br, m[3], 0x5c4dd124, 15); er = rotl(er, 10)
+ br = fn4(br, cr, dr, er, ar, m[7], 0x5c4dd124, 7); dr = rotl(dr, 10)
+ ar = fn4(ar, br, cr, dr, er, m[0], 0x5c4dd124, 12); cr = rotl(cr, 10)
+ er = fn4(er, ar, br, cr, dr, m[13], 0x5c4dd124, 8); br = rotl(br, 10)
+ dr = fn4(dr, er, ar, br, cr, m[5], 0x5c4dd124, 9); ar = rotl(ar, 10)
+ cr = fn4(cr, dr, er, ar, br, m[10], 0x5c4dd124, 11); er = rotl(er, 10)
+ br = fn4(br, cr, dr, er, ar, m[14], 0x5c4dd124, 7); dr = rotl(dr, 10)
+ ar = fn4(ar, br, cr, dr, er, m[15], 0x5c4dd124, 7); cr = rotl(cr, 10)
+ er = fn4(er, ar, br, cr, dr, m[8], 0x5c4dd124, 12); br = rotl(br, 10)
+ dr = fn4(dr, er, ar, br, cr, m[12], 0x5c4dd124, 7); ar = rotl(ar, 10)
+ cr = fn4(cr, dr, er, ar, br, m[4], 0x5c4dd124, 6); er = rotl(er, 10)
+ br = fn4(br, cr, dr, er, ar, m[9], 0x5c4dd124, 15); dr = rotl(dr, 10)
+ ar = fn4(ar, br, cr, dr, er, m[1], 0x5c4dd124, 13); cr = rotl(cr, 10)
+ er = fn4(er, ar, br, cr, dr, m[2], 0x5c4dd124, 11); br = rotl(br, 10)
- // Pad with zeroes
- for (i = 2 * len; i < N; ++i) {
- rws[i] = 0;
- }
+ // M'j = 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13
+ // K' = 0x6d703ef3
+ // S'j = 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5
+ dr = fn3(dr, er, ar, br, cr, m[15], 0x6d703ef3, 9); ar = rotl(ar, 10)
+ cr = fn3(cr, dr, er, ar, br, m[5], 0x6d703ef3, 7); er = rotl(er, 10)
+ br = fn3(br, cr, dr, er, ar, m[1], 0x6d703ef3, 15); dr = rotl(dr, 10)
+ ar = fn3(ar, br, cr, dr, er, m[3], 0x6d703ef3, 11); cr = rotl(cr, 10)
+ er = fn3(er, ar, br, cr, dr, m[7], 0x6d703ef3, 8); br = rotl(br, 10)
+ dr = fn3(dr, er, ar, br, cr, m[14], 0x6d703ef3, 6); ar = rotl(ar, 10)
+ cr = fn3(cr, dr, er, ar, br, m[6], 0x6d703ef3, 6); er = rotl(er, 10)
+ br = fn3(br, cr, dr, er, ar, m[9], 0x6d703ef3, 14); dr = rotl(dr, 10)
+ ar = fn3(ar, br, cr, dr, er, m[11], 0x6d703ef3, 12); cr = rotl(cr, 10)
+ er = fn3(er, ar, br, cr, dr, m[8], 0x6d703ef3, 13); br = rotl(br, 10)
+ dr = fn3(dr, er, ar, br, cr, m[12], 0x6d703ef3, 5); ar = rotl(ar, 10)
+ cr = fn3(cr, dr, er, ar, br, m[2], 0x6d703ef3, 14); er = rotl(er, 10)
+ br = fn3(br, cr, dr, er, ar, m[10], 0x6d703ef3, 13); dr = rotl(dr, 10)
+ ar = fn3(ar, br, cr, dr, er, m[0], 0x6d703ef3, 13); cr = rotl(cr, 10)
+ er = fn3(er, ar, br, cr, dr, m[4], 0x6d703ef3, 7); br = rotl(br, 10)
+ dr = fn3(dr, er, ar, br, cr, m[13], 0x6d703ef3, 5); ar = rotl(ar, 10)
- assert(carry === 0);
- assert((carry & ~0x1fff) === 0);
- };
+ // M'j = 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14
+ // K' = 0x7a6d76e9
+ // S'j = 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8
+ cr = fn2(cr, dr, er, ar, br, m[8], 0x7a6d76e9, 15); er = rotl(er, 10)
+ br = fn2(br, cr, dr, er, ar, m[6], 0x7a6d76e9, 5); dr = rotl(dr, 10)
+ ar = fn2(ar, br, cr, dr, er, m[4], 0x7a6d76e9, 8); cr = rotl(cr, 10)
+ er = fn2(er, ar, br, cr, dr, m[1], 0x7a6d76e9, 11); br = rotl(br, 10)
+ dr = fn2(dr, er, ar, br, cr, m[3], 0x7a6d76e9, 14); ar = rotl(ar, 10)
+ cr = fn2(cr, dr, er, ar, br, m[11], 0x7a6d76e9, 14); er = rotl(er, 10)
+ br = fn2(br, cr, dr, er, ar, m[15], 0x7a6d76e9, 6); dr = rotl(dr, 10)
+ ar = fn2(ar, br, cr, dr, er, m[0], 0x7a6d76e9, 14); cr = rotl(cr, 10)
+ er = fn2(er, ar, br, cr, dr, m[5], 0x7a6d76e9, 6); br = rotl(br, 10)
+ dr = fn2(dr, er, ar, br, cr, m[12], 0x7a6d76e9, 9); ar = rotl(ar, 10)
+ cr = fn2(cr, dr, er, ar, br, m[2], 0x7a6d76e9, 12); er = rotl(er, 10)
+ br = fn2(br, cr, dr, er, ar, m[13], 0x7a6d76e9, 9); dr = rotl(dr, 10)
+ ar = fn2(ar, br, cr, dr, er, m[9], 0x7a6d76e9, 12); cr = rotl(cr, 10)
+ er = fn2(er, ar, br, cr, dr, m[7], 0x7a6d76e9, 5); br = rotl(br, 10)
+ dr = fn2(dr, er, ar, br, cr, m[10], 0x7a6d76e9, 15); ar = rotl(ar, 10)
+ cr = fn2(cr, dr, er, ar, br, m[14], 0x7a6d76e9, 8); er = rotl(er, 10)
- FFTM.prototype.stub = function stub (N) {
- var ph = new Array(N);
- for (var i = 0; i < N; i++) {
- ph[i] = 0;
- }
+ // M'j = 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11
+ // K' = 0x00000000
+ // S'j = 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11
+ br = fn1(br, cr, dr, er, ar, m[12], 0x00000000, 8); dr = rotl(dr, 10)
+ ar = fn1(ar, br, cr, dr, er, m[15], 0x00000000, 5); cr = rotl(cr, 10)
+ er = fn1(er, ar, br, cr, dr, m[10], 0x00000000, 12); br = rotl(br, 10)
+ dr = fn1(dr, er, ar, br, cr, m[4], 0x00000000, 9); ar = rotl(ar, 10)
+ cr = fn1(cr, dr, er, ar, br, m[1], 0x00000000, 12); er = rotl(er, 10)
+ br = fn1(br, cr, dr, er, ar, m[5], 0x00000000, 5); dr = rotl(dr, 10)
+ ar = fn1(ar, br, cr, dr, er, m[8], 0x00000000, 14); cr = rotl(cr, 10)
+ er = fn1(er, ar, br, cr, dr, m[7], 0x00000000, 6); br = rotl(br, 10)
+ dr = fn1(dr, er, ar, br, cr, m[6], 0x00000000, 8); ar = rotl(ar, 10)
+ cr = fn1(cr, dr, er, ar, br, m[2], 0x00000000, 13); er = rotl(er, 10)
+ br = fn1(br, cr, dr, er, ar, m[13], 0x00000000, 6); dr = rotl(dr, 10)
+ ar = fn1(ar, br, cr, dr, er, m[14], 0x00000000, 5); cr = rotl(cr, 10)
+ er = fn1(er, ar, br, cr, dr, m[0], 0x00000000, 15); br = rotl(br, 10)
+ dr = fn1(dr, er, ar, br, cr, m[3], 0x00000000, 13); ar = rotl(ar, 10)
+ cr = fn1(cr, dr, er, ar, br, m[9], 0x00000000, 11); er = rotl(er, 10)
+ br = fn1(br, cr, dr, er, ar, m[11], 0x00000000, 11); dr = rotl(dr, 10)
- return ph;
- };
+ // change state
+ var t = (this._b + cl + dr) | 0
+ this._b = (this._c + dl + er) | 0
+ this._c = (this._d + el + ar) | 0
+ this._d = (this._e + al + br) | 0
+ this._e = (this._a + bl + cr) | 0
+ this._a = t
+}
- FFTM.prototype.mulp = function mulp (x, y, out) {
- var N = 2 * this.guessLen13b(x.length, y.length);
+RIPEMD160.prototype._digest = function () {
+ // create padding and handle blocks
+ this._block[this._blockOffset++] = 0x80
+ if (this._blockOffset > 56) {
+ this._block.fill(0, this._blockOffset, 64)
+ this._update()
+ this._blockOffset = 0
+ }
- var rbt = this.makeRBT(N);
+ this._block.fill(0, this._blockOffset, 56)
+ this._block.writeUInt32LE(this._length[0], 56)
+ this._block.writeUInt32LE(this._length[1], 60)
+ this._update()
- var _ = this.stub(N);
+ // produce result
+ var buffer = new Buffer(20)
+ buffer.writeInt32LE(this._a, 0)
+ buffer.writeInt32LE(this._b, 4)
+ buffer.writeInt32LE(this._c, 8)
+ buffer.writeInt32LE(this._d, 12)
+ buffer.writeInt32LE(this._e, 16)
+ return buffer
+}
- var rws = new Array(N);
- var rwst = new Array(N);
- var iwst = new Array(N);
+function rotl (x, n) {
+ return (x << n) | (x >>> (32 - n))
+}
- var nrws = new Array(N);
- var nrwst = new Array(N);
- var niwst = new Array(N);
+function fn1 (a, b, c, d, e, m, k, s) {
+ return (rotl((a + (b ^ c ^ d) + m + k) | 0, s) + e) | 0
+}
- var rmws = out.words;
- rmws.length = N;
+function fn2 (a, b, c, d, e, m, k, s) {
+ return (rotl((a + ((b & c) | ((~b) & d)) + m + k) | 0, s) + e) | 0
+}
- this.convert13b(x.words, x.length, rws, N);
- this.convert13b(y.words, y.length, nrws, N);
+function fn3 (a, b, c, d, e, m, k, s) {
+ return (rotl((a + ((b | (~c)) ^ d) + m + k) | 0, s) + e) | 0
+}
- this.transform(rws, _, rwst, iwst, N, rbt);
- this.transform(nrws, _, nrwst, niwst, N, rbt);
+function fn4 (a, b, c, d, e, m, k, s) {
+ return (rotl((a + ((b & d) | (c & (~d))) + m + k) | 0, s) + e) | 0
+}
- for (var i = 0; i < N; i++) {
- var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
- iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
- rwst[i] = rx;
- }
+function fn5 (a, b, c, d, e, m, k, s) {
+ return (rotl((a + (b ^ (c | (~d))) + m + k) | 0, s) + e) | 0
+}
- this.conjugate(rwst, iwst, N);
- this.transform(rwst, iwst, rmws, _, N, rbt);
- this.conjugate(rmws, _, N);
- this.normalize13b(rmws, N);
+module.exports = RIPEMD160
- out.negative = x.negative ^ y.negative;
- out.length = x.length + y.length;
- return out.strip();
- };
+}).call(this,require("buffer").Buffer)
+},{"buffer":5,"hash-base":95,"inherits":96}],101:[function(require,module,exports){
+/* eslint-disable node/no-deprecated-api */
+var buffer = require('buffer')
+var Buffer = buffer.Buffer
- // Multiply `this` by `num`
- BN.prototype.mul = function mul (num) {
- var out = new BN(null);
- out.words = new Array(this.length + num.length);
- return this.mulTo(num, out);
- };
+// alternative to using Object.keys for old browsers
+function copyProps (src, dst) {
+ for (var key in src) {
+ dst[key] = src[key]
+ }
+}
+if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
+ module.exports = buffer
+} else {
+ // Copy properties from require('buffer')
+ copyProps(buffer, exports)
+ exports.Buffer = SafeBuffer
+}
- // Multiply employing FFT
- BN.prototype.mulf = function mulf (num) {
- var out = new BN(null);
- out.words = new Array(this.length + num.length);
- return jumboMulTo(this, num, out);
- };
+function SafeBuffer (arg, encodingOrOffset, length) {
+ return Buffer(arg, encodingOrOffset, length)
+}
- // In-place Multiplication
- BN.prototype.imul = function imul (num) {
- return this.clone().mulTo(num, this);
- };
+// Copy static methods from Buffer
+copyProps(Buffer, SafeBuffer)
- BN.prototype.imuln = function imuln (num) {
- assert(typeof num === 'number');
- assert(num < 0x4000000);
+SafeBuffer.from = function (arg, encodingOrOffset, length) {
+ if (typeof arg === 'number') {
+ throw new TypeError('Argument must not be a number')
+ }
+ return Buffer(arg, encodingOrOffset, length)
+}
- // Carry
- var carry = 0;
- for (var i = 0; i < this.length; i++) {
- var w = (this.words[i] | 0) * num;
- var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
- carry >>= 26;
- carry += (w / 0x4000000) | 0;
- // NOTE: lo is 27bit maximum
- carry += lo >>> 26;
- this.words[i] = lo & 0x3ffffff;
+SafeBuffer.alloc = function (size, fill, encoding) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ var buf = Buffer(size)
+ if (fill !== undefined) {
+ if (typeof encoding === 'string') {
+ buf.fill(fill, encoding)
+ } else {
+ buf.fill(fill)
}
+ } else {
+ buf.fill(0)
+ }
+ return buf
+}
- if (carry !== 0) {
- this.words[i] = carry;
- this.length++;
- }
+SafeBuffer.allocUnsafe = function (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ return Buffer(size)
+}
- return this;
- };
+SafeBuffer.allocUnsafeSlow = function (size) {
+ if (typeof size !== 'number') {
+ throw new TypeError('Argument must be a number')
+ }
+ return buffer.SlowBuffer(size)
+}
- BN.prototype.muln = function muln (num) {
- return this.clone().imuln(num);
- };
+},{"buffer":5}],102:[function(require,module,exports){
+var Buffer = require('safe-buffer').Buffer
- // `this` * `this`
- BN.prototype.sqr = function sqr () {
- return this.mul(this);
- };
+// prototype class for hash functions
+function Hash (blockSize, finalSize) {
+ this._block = Buffer.alloc(blockSize)
+ this._finalSize = finalSize
+ this._blockSize = blockSize
+ this._len = 0
+}
- // `this` * `this` in-place
- BN.prototype.isqr = function isqr () {
- return this.imul(this.clone());
- };
+Hash.prototype.update = function (data, enc) {
+ if (typeof data === 'string') {
+ enc = enc || 'utf8'
+ data = Buffer.from(data, enc)
+ }
- // Math.pow(`this`, `num`)
- BN.prototype.pow = function pow (num) {
- var w = toBitArray(num);
- if (w.length === 0) return new BN(1);
+ var block = this._block
+ var blockSize = this._blockSize
+ var length = data.length
+ var accum = this._len
- // Skip leading zeroes
- var res = this;
- for (var i = 0; i < w.length; i++, res = res.sqr()) {
- if (w[i] !== 0) break;
+ for (var offset = 0; offset < length;) {
+ var assigned = accum % blockSize
+ var remainder = Math.min(length - offset, blockSize - assigned)
+
+ for (var i = 0; i < remainder; i++) {
+ block[assigned + i] = data[offset + i]
}
- if (++i < w.length) {
- for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
- if (w[i] === 0) continue;
+ accum += remainder
+ offset += remainder
- res = res.mul(q);
- }
+ if ((accum % blockSize) === 0) {
+ this._update(block)
}
+ }
- return res;
- };
-
- // Shift-left in-place
- BN.prototype.iushln = function iushln (bits) {
- assert(typeof bits === 'number' && bits >= 0);
- var r = bits % 26;
- var s = (bits - r) / 26;
- var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
- var i;
+ this._len += length
+ return this
+}
- if (r !== 0) {
- var carry = 0;
+Hash.prototype.digest = function (enc) {
+ var rem = this._len % this._blockSize
- for (i = 0; i < this.length; i++) {
- var newCarry = this.words[i] & carryMask;
- var c = ((this.words[i] | 0) - newCarry) << r;
- this.words[i] = c | carry;
- carry = newCarry >>> (26 - r);
- }
+ this._block[rem] = 0x80
- if (carry) {
- this.words[i] = carry;
- this.length++;
- }
- }
+ // zero (rem + 1) trailing bits, where (rem + 1) is the smallest
+ // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize
+ this._block.fill(0, rem + 1)
- if (s !== 0) {
- for (i = this.length - 1; i >= 0; i--) {
- this.words[i + s] = this.words[i];
- }
+ if (rem >= this._finalSize) {
+ this._update(this._block)
+ this._block.fill(0)
+ }
- for (i = 0; i < s; i++) {
- this.words[i] = 0;
- }
+ var bits = this._len * 8
- this.length += s;
- }
+ // uint32
+ if (bits <= 0xffffffff) {
+ this._block.writeUInt32BE(bits, this._blockSize - 4)
- return this.strip();
- };
+ // uint64
+ } else {
+ var lowBits = (bits & 0xffffffff) >>> 0
+ var highBits = (bits - lowBits) / 0x100000000
- BN.prototype.ishln = function ishln (bits) {
- // TODO(indutny): implement me
- assert(this.negative === 0);
- return this.iushln(bits);
- };
+ this._block.writeUInt32BE(highBits, this._blockSize - 8)
+ this._block.writeUInt32BE(lowBits, this._blockSize - 4)
+ }
- // Shift-right in-place
- // NOTE: `hint` is a lowest bit before trailing zeroes
- // NOTE: if `extended` is present - it will be filled with destroyed bits
- BN.prototype.iushrn = function iushrn (bits, hint, extended) {
- assert(typeof bits === 'number' && bits >= 0);
- var h;
- if (hint) {
- h = (hint - (hint % 26)) / 26;
- } else {
- h = 0;
- }
+ this._update(this._block)
+ var hash = this._hash()
- var r = bits % 26;
- var s = Math.min((bits - r) / 26, this.length);
- var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
- var maskedWords = extended;
+ return enc ? hash.toString(enc) : hash
+}
- h -= s;
- h = Math.max(0, h);
+Hash.prototype._update = function () {
+ throw new Error('_update must be implemented by subclass')
+}
- // Extended mode, copy masked part
- if (maskedWords) {
- for (var i = 0; i < s; i++) {
- maskedWords.words[i] = this.words[i];
- }
- maskedWords.length = s;
- }
+module.exports = Hash
- if (s === 0) {
- // No-op, we should not move anything at all
- } else if (this.length > s) {
- this.length -= s;
- for (i = 0; i < this.length; i++) {
- this.words[i] = this.words[i + s];
- }
- } else {
- this.words[0] = 0;
- this.length = 1;
- }
+},{"safe-buffer":101}],103:[function(require,module,exports){
+var exports = module.exports = function SHA (algorithm) {
+ algorithm = algorithm.toLowerCase()
- var carry = 0;
- for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
- var word = this.words[i] | 0;
- this.words[i] = (carry << (26 - r)) | (word >>> r);
- carry = word & mask;
- }
+ var Algorithm = exports[algorithm]
+ if (!Algorithm) throw new Error(algorithm + ' is not supported (we accept pull requests)')
- // Push carried bits as a mask
- if (maskedWords && carry !== 0) {
- maskedWords.words[maskedWords.length++] = carry;
- }
+ return new Algorithm()
+}
- if (this.length === 0) {
- this.words[0] = 0;
- this.length = 1;
- }
+exports.sha = require('./sha')
+exports.sha1 = require('./sha1')
+exports.sha224 = require('./sha224')
+exports.sha256 = require('./sha256')
+exports.sha384 = require('./sha384')
+exports.sha512 = require('./sha512')
- return this.strip();
- };
+},{"./sha":104,"./sha1":105,"./sha224":106,"./sha256":107,"./sha384":108,"./sha512":109}],104:[function(require,module,exports){
+/*
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined
+ * in FIPS PUB 180-1
+ * This source code is derived from sha1.js of the same repository.
+ * The difference between SHA-0 and SHA-1 is just a bitwise rotate left
+ * operation was added.
+ */
- BN.prototype.ishrn = function ishrn (bits, hint, extended) {
- // TODO(indutny): implement me
- assert(this.negative === 0);
- return this.iushrn(bits, hint, extended);
- };
+var inherits = require('inherits')
+var Hash = require('./hash')
+var Buffer = require('safe-buffer').Buffer
- // Shift-left
- BN.prototype.shln = function shln (bits) {
- return this.clone().ishln(bits);
- };
+var K = [
+ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
+]
- BN.prototype.ushln = function ushln (bits) {
- return this.clone().iushln(bits);
- };
+var W = new Array(80)
- // Shift-right
- BN.prototype.shrn = function shrn (bits) {
- return this.clone().ishrn(bits);
- };
+function Sha () {
+ this.init()
+ this._w = W
- BN.prototype.ushrn = function ushrn (bits) {
- return this.clone().iushrn(bits);
- };
+ Hash.call(this, 64, 56)
+}
- // Test if n bit is set
- BN.prototype.testn = function testn (bit) {
- assert(typeof bit === 'number' && bit >= 0);
- var r = bit % 26;
- var s = (bit - r) / 26;
- var q = 1 << r;
+inherits(Sha, Hash)
- // Fast case: bit is much higher than all existing words
- if (this.length <= s) return false;
+Sha.prototype.init = function () {
+ this._a = 0x67452301
+ this._b = 0xefcdab89
+ this._c = 0x98badcfe
+ this._d = 0x10325476
+ this._e = 0xc3d2e1f0
- // Check bit and return
- var w = this.words[s];
+ return this
+}
- return !!(w & q);
- };
+function rotl5 (num) {
+ return (num << 5) | (num >>> 27)
+}
- // Return only lowers bits of number (in-place)
- BN.prototype.imaskn = function imaskn (bits) {
- assert(typeof bits === 'number' && bits >= 0);
- var r = bits % 26;
- var s = (bits - r) / 26;
+function rotl30 (num) {
+ return (num << 30) | (num >>> 2)
+}
- assert(this.negative === 0, 'imaskn works only with positive numbers');
+function ft (s, b, c, d) {
+ if (s === 0) return (b & c) | ((~b) & d)
+ if (s === 2) return (b & c) | (b & d) | (c & d)
+ return b ^ c ^ d
+}
- if (this.length <= s) {
- return this;
- }
+Sha.prototype._update = function (M) {
+ var W = this._w
- if (r !== 0) {
- s++;
- }
- this.length = Math.min(s, this.length);
+ var a = this._a | 0
+ var b = this._b | 0
+ var c = this._c | 0
+ var d = this._d | 0
+ var e = this._e | 0
- if (r !== 0) {
- var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
- this.words[this.length - 1] &= mask;
- }
+ for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
+ for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]
- return this.strip();
- };
+ for (var j = 0; j < 80; ++j) {
+ var s = ~~(j / 20)
+ var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
- // Return only lowers bits of number
- BN.prototype.maskn = function maskn (bits) {
- return this.clone().imaskn(bits);
- };
+ e = d
+ d = c
+ c = rotl30(b)
+ b = a
+ a = t
+ }
- // Add plain number `num` to `this`
- BN.prototype.iaddn = function iaddn (num) {
- assert(typeof num === 'number');
- assert(num < 0x4000000);
- if (num < 0) return this.isubn(-num);
+ this._a = (a + this._a) | 0
+ this._b = (b + this._b) | 0
+ this._c = (c + this._c) | 0
+ this._d = (d + this._d) | 0
+ this._e = (e + this._e) | 0
+}
- // Possible sign change
- if (this.negative !== 0) {
- if (this.length === 1 && (this.words[0] | 0) < num) {
- this.words[0] = num - (this.words[0] | 0);
- this.negative = 0;
- return this;
- }
+Sha.prototype._hash = function () {
+ var H = Buffer.allocUnsafe(20)
- this.negative = 0;
- this.isubn(num);
- this.negative = 1;
- return this;
- }
+ H.writeInt32BE(this._a | 0, 0)
+ H.writeInt32BE(this._b | 0, 4)
+ H.writeInt32BE(this._c | 0, 8)
+ H.writeInt32BE(this._d | 0, 12)
+ H.writeInt32BE(this._e | 0, 16)
- // Add without checks
- return this._iaddn(num);
- };
+ return H
+}
- BN.prototype._iaddn = function _iaddn (num) {
- this.words[0] += num;
+module.exports = Sha
- // Carry
- for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
- this.words[i] -= 0x4000000;
- if (i === this.length - 1) {
- this.words[i + 1] = 1;
- } else {
- this.words[i + 1]++;
- }
- }
- this.length = Math.max(this.length, i + 1);
+},{"./hash":102,"inherits":96,"safe-buffer":101}],105:[function(require,module,exports){
+/*
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
+ * in FIPS PUB 180-1
+ * Version 2.1a Copyright Paul Johnston 2000 - 2002.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ * Distributed under the BSD License
+ * See http://pajhome.org.uk/crypt/md5 for details.
+ */
- return this;
- };
+var inherits = require('inherits')
+var Hash = require('./hash')
+var Buffer = require('safe-buffer').Buffer
- // Subtract plain number `num` from `this`
- BN.prototype.isubn = function isubn (num) {
- assert(typeof num === 'number');
- assert(num < 0x4000000);
- if (num < 0) return this.iaddn(-num);
+var K = [
+ 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc | 0, 0xca62c1d6 | 0
+]
- if (this.negative !== 0) {
- this.negative = 0;
- this.iaddn(num);
- this.negative = 1;
- return this;
- }
+var W = new Array(80)
- this.words[0] -= num;
+function Sha1 () {
+ this.init()
+ this._w = W
- if (this.length === 1 && this.words[0] < 0) {
- this.words[0] = -this.words[0];
- this.negative = 1;
- } else {
- // Carry
- for (var i = 0; i < this.length && this.words[i] < 0; i++) {
- this.words[i] += 0x4000000;
- this.words[i + 1] -= 1;
- }
- }
+ Hash.call(this, 64, 56)
+}
- return this.strip();
- };
+inherits(Sha1, Hash)
- BN.prototype.addn = function addn (num) {
- return this.clone().iaddn(num);
- };
+Sha1.prototype.init = function () {
+ this._a = 0x67452301
+ this._b = 0xefcdab89
+ this._c = 0x98badcfe
+ this._d = 0x10325476
+ this._e = 0xc3d2e1f0
- BN.prototype.subn = function subn (num) {
- return this.clone().isubn(num);
- };
+ return this
+}
- BN.prototype.iabs = function iabs () {
- this.negative = 0;
+function rotl1 (num) {
+ return (num << 1) | (num >>> 31)
+}
- return this;
- };
+function rotl5 (num) {
+ return (num << 5) | (num >>> 27)
+}
- BN.prototype.abs = function abs () {
- return this.clone().iabs();
- };
+function rotl30 (num) {
+ return (num << 30) | (num >>> 2)
+}
- BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
- var len = num.length + shift;
- var i;
+function ft (s, b, c, d) {
+ if (s === 0) return (b & c) | ((~b) & d)
+ if (s === 2) return (b & c) | (b & d) | (c & d)
+ return b ^ c ^ d
+}
- this._expand(len);
+Sha1.prototype._update = function (M) {
+ var W = this._w
- var w;
- var carry = 0;
- for (i = 0; i < num.length; i++) {
- w = (this.words[i + shift] | 0) + carry;
- var right = (num.words[i] | 0) * mul;
- w -= right & 0x3ffffff;
- carry = (w >> 26) - ((right / 0x4000000) | 0);
- this.words[i + shift] = w & 0x3ffffff;
- }
- for (; i < this.length - shift; i++) {
- w = (this.words[i + shift] | 0) + carry;
- carry = w >> 26;
- this.words[i + shift] = w & 0x3ffffff;
- }
+ var a = this._a | 0
+ var b = this._b | 0
+ var c = this._c | 0
+ var d = this._d | 0
+ var e = this._e | 0
- if (carry === 0) return this.strip();
+ for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
+ for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16])
- // Subtraction overflow
- assert(carry === -1);
- carry = 0;
- for (i = 0; i < this.length; i++) {
- w = -(this.words[i] | 0) + carry;
- carry = w >> 26;
- this.words[i] = w & 0x3ffffff;
- }
- this.negative = 1;
+ for (var j = 0; j < 80; ++j) {
+ var s = ~~(j / 20)
+ var t = (rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s]) | 0
- return this.strip();
- };
+ e = d
+ d = c
+ c = rotl30(b)
+ b = a
+ a = t
+ }
- BN.prototype._wordDiv = function _wordDiv (num, mode) {
- var shift = this.length - num.length;
+ this._a = (a + this._a) | 0
+ this._b = (b + this._b) | 0
+ this._c = (c + this._c) | 0
+ this._d = (d + this._d) | 0
+ this._e = (e + this._e) | 0
+}
- var a = this.clone();
- var b = num;
+Sha1.prototype._hash = function () {
+ var H = Buffer.allocUnsafe(20)
- // Normalize
- var bhi = b.words[b.length - 1] | 0;
- var bhiBits = this._countBits(bhi);
- shift = 26 - bhiBits;
- if (shift !== 0) {
- b = b.ushln(shift);
- a.iushln(shift);
- bhi = b.words[b.length - 1] | 0;
- }
+ H.writeInt32BE(this._a | 0, 0)
+ H.writeInt32BE(this._b | 0, 4)
+ H.writeInt32BE(this._c | 0, 8)
+ H.writeInt32BE(this._d | 0, 12)
+ H.writeInt32BE(this._e | 0, 16)
- // Initialize quotient
- var m = a.length - b.length;
- var q;
+ return H
+}
- if (mode !== 'mod') {
- q = new BN(null);
- q.length = m + 1;
- q.words = new Array(q.length);
- for (var i = 0; i < q.length; i++) {
- q.words[i] = 0;
- }
- }
+module.exports = Sha1
- var diff = a.clone()._ishlnsubmul(b, 1, m);
- if (diff.negative === 0) {
- a = diff;
- if (q) {
- q.words[m] = 1;
- }
- }
+},{"./hash":102,"inherits":96,"safe-buffer":101}],106:[function(require,module,exports){
+/**
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
+ * in FIPS 180-2
+ * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ *
+ */
- for (var j = m - 1; j >= 0; j--) {
- var qj = (a.words[b.length + j] | 0) * 0x4000000 +
- (a.words[b.length + j - 1] | 0);
+var inherits = require('inherits')
+var Sha256 = require('./sha256')
+var Hash = require('./hash')
+var Buffer = require('safe-buffer').Buffer
- // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
- // (0x7ffffff)
- qj = Math.min((qj / bhi) | 0, 0x3ffffff);
+var W = new Array(64)
- a._ishlnsubmul(b, qj, j);
- while (a.negative !== 0) {
- qj--;
- a.negative = 0;
- a._ishlnsubmul(b, 1, j);
- if (!a.isZero()) {
- a.negative ^= 1;
- }
- }
- if (q) {
- q.words[j] = qj;
- }
- }
- if (q) {
- q.strip();
- }
- a.strip();
+function Sha224 () {
+ this.init()
- // Denormalize
- if (mode !== 'div' && shift !== 0) {
- a.iushrn(shift);
- }
+ this._w = W // new Array(64)
- return {
- div: q || null,
- mod: a
- };
- };
+ Hash.call(this, 64, 56)
+}
- // NOTE: 1) `mode` can be set to `mod` to request mod only,
- // to `div` to request div only, or be absent to
- // request both div & mod
- // 2) `positive` is true if unsigned mod is requested
- BN.prototype.divmod = function divmod (num, mode, positive) {
- assert(!num.isZero());
+inherits(Sha224, Sha256)
- if (this.isZero()) {
- return {
- div: new BN(0),
- mod: new BN(0)
- };
- }
+Sha224.prototype.init = function () {
+ this._a = 0xc1059ed8
+ this._b = 0x367cd507
+ this._c = 0x3070dd17
+ this._d = 0xf70e5939
+ this._e = 0xffc00b31
+ this._f = 0x68581511
+ this._g = 0x64f98fa7
+ this._h = 0xbefa4fa4
- var div, mod, res;
- if (this.negative !== 0 && num.negative === 0) {
- res = this.neg().divmod(num, mode);
+ return this
+}
- if (mode !== 'mod') {
- div = res.div.neg();
- }
+Sha224.prototype._hash = function () {
+ var H = Buffer.allocUnsafe(28)
- if (mode !== 'div') {
- mod = res.mod.neg();
- if (positive && mod.negative !== 0) {
- mod.iadd(num);
- }
- }
+ H.writeInt32BE(this._a, 0)
+ H.writeInt32BE(this._b, 4)
+ H.writeInt32BE(this._c, 8)
+ H.writeInt32BE(this._d, 12)
+ H.writeInt32BE(this._e, 16)
+ H.writeInt32BE(this._f, 20)
+ H.writeInt32BE(this._g, 24)
- return {
- div: div,
- mod: mod
- };
- }
+ return H
+}
- if (this.negative === 0 && num.negative !== 0) {
- res = this.divmod(num.neg(), mode);
+module.exports = Sha224
- if (mode !== 'mod') {
- div = res.div.neg();
- }
+},{"./hash":102,"./sha256":107,"inherits":96,"safe-buffer":101}],107:[function(require,module,exports){
+/**
+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
+ * in FIPS 180-2
+ * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
+ *
+ */
- return {
- div: div,
- mod: res.mod
- };
- }
+var inherits = require('inherits')
+var Hash = require('./hash')
+var Buffer = require('safe-buffer').Buffer
- if ((this.negative & num.negative) !== 0) {
- res = this.neg().divmod(num.neg(), mode);
+var K = [
+ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
+ 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
+ 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
+ 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
+ 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
+ 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
+ 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
+ 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
+ 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
+ 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
+ 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
+ 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
+ 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
+ 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
+ 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
+ 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
+]
- if (mode !== 'div') {
- mod = res.mod.neg();
- if (positive && mod.negative !== 0) {
- mod.isub(num);
- }
- }
+var W = new Array(64)
- return {
- div: res.div,
- mod: mod
- };
- }
+function Sha256 () {
+ this.init()
- // Both numbers are positive at this point
+ this._w = W // new Array(64)
- // Strip both numbers to approximate shift value
- if (num.length > this.length || this.cmp(num) < 0) {
- return {
- div: new BN(0),
- mod: this
- };
- }
+ Hash.call(this, 64, 56)
+}
- // Very short reduction
- if (num.length === 1) {
- if (mode === 'div') {
- return {
- div: this.divn(num.words[0]),
- mod: null
- };
- }
+inherits(Sha256, Hash)
- if (mode === 'mod') {
- return {
- div: null,
- mod: new BN(this.modn(num.words[0]))
- };
- }
+Sha256.prototype.init = function () {
+ this._a = 0x6a09e667
+ this._b = 0xbb67ae85
+ this._c = 0x3c6ef372
+ this._d = 0xa54ff53a
+ this._e = 0x510e527f
+ this._f = 0x9b05688c
+ this._g = 0x1f83d9ab
+ this._h = 0x5be0cd19
- return {
- div: this.divn(num.words[0]),
- mod: new BN(this.modn(num.words[0]))
- };
- }
+ return this
+}
- return this._wordDiv(num, mode);
- };
+function ch (x, y, z) {
+ return z ^ (x & (y ^ z))
+}
- // Find `this` / `num`
- BN.prototype.div = function div (num) {
- return this.divmod(num, 'div', false).div;
- };
+function maj (x, y, z) {
+ return (x & y) | (z & (x | y))
+}
- // Find `this` % `num`
- BN.prototype.mod = function mod (num) {
- return this.divmod(num, 'mod', false).mod;
- };
+function sigma0 (x) {
+ return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10)
+}
- BN.prototype.umod = function umod (num) {
- return this.divmod(num, 'mod', true).mod;
- };
+function sigma1 (x) {
+ return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7)
+}
- // Find Round(`this` / `num`)
- BN.prototype.divRound = function divRound (num) {
- var dm = this.divmod(num);
+function gamma0 (x) {
+ return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ (x >>> 3)
+}
- // Fast case - exact division
- if (dm.mod.isZero()) return dm.div;
+function gamma1 (x) {
+ return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ (x >>> 10)
+}
- var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
+Sha256.prototype._update = function (M) {
+ var W = this._w
- var half = num.ushrn(1);
- var r2 = num.andln(1);
- var cmp = mod.cmp(half);
+ var a = this._a | 0
+ var b = this._b | 0
+ var c = this._c | 0
+ var d = this._d | 0
+ var e = this._e | 0
+ var f = this._f | 0
+ var g = this._g | 0
+ var h = this._h | 0
- // Round down
- if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
+ for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4)
+ for (; i < 64; ++i) W[i] = (gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16]) | 0
- // Round up
- return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
- };
+ for (var j = 0; j < 64; ++j) {
+ var T1 = (h + sigma1(e) + ch(e, f, g) + K[j] + W[j]) | 0
+ var T2 = (sigma0(a) + maj(a, b, c)) | 0
- BN.prototype.modn = function modn (num) {
- assert(num <= 0x3ffffff);
- var p = (1 << 26) % num;
+ h = g
+ g = f
+ f = e
+ e = (d + T1) | 0
+ d = c
+ c = b
+ b = a
+ a = (T1 + T2) | 0
+ }
- var acc = 0;
- for (var i = this.length - 1; i >= 0; i--) {
- acc = (p * acc + (this.words[i] | 0)) % num;
- }
+ this._a = (a + this._a) | 0
+ this._b = (b + this._b) | 0
+ this._c = (c + this._c) | 0
+ this._d = (d + this._d) | 0
+ this._e = (e + this._e) | 0
+ this._f = (f + this._f) | 0
+ this._g = (g + this._g) | 0
+ this._h = (h + this._h) | 0
+}
- return acc;
- };
+Sha256.prototype._hash = function () {
+ var H = Buffer.allocUnsafe(32)
- // In-place division by number
- BN.prototype.idivn = function idivn (num) {
- assert(num <= 0x3ffffff);
+ H.writeInt32BE(this._a, 0)
+ H.writeInt32BE(this._b, 4)
+ H.writeInt32BE(this._c, 8)
+ H.writeInt32BE(this._d, 12)
+ H.writeInt32BE(this._e, 16)
+ H.writeInt32BE(this._f, 20)
+ H.writeInt32BE(this._g, 24)
+ H.writeInt32BE(this._h, 28)
- var carry = 0;
- for (var i = this.length - 1; i >= 0; i--) {
- var w = (this.words[i] | 0) + carry * 0x4000000;
- this.words[i] = (w / num) | 0;
- carry = w % num;
- }
+ return H
+}
- return this.strip();
- };
+module.exports = Sha256
- BN.prototype.divn = function divn (num) {
- return this.clone().idivn(num);
- };
+},{"./hash":102,"inherits":96,"safe-buffer":101}],108:[function(require,module,exports){
+var inherits = require('inherits')
+var SHA512 = require('./sha512')
+var Hash = require('./hash')
+var Buffer = require('safe-buffer').Buffer
- BN.prototype.egcd = function egcd (p) {
- assert(p.negative === 0);
- assert(!p.isZero());
+var W = new Array(160)
- var x = this;
- var y = p.clone();
+function Sha384 () {
+ this.init()
+ this._w = W
- if (x.negative !== 0) {
- x = x.umod(p);
- } else {
- x = x.clone();
- }
+ Hash.call(this, 128, 112)
+}
- // A * x + B * y = x
- var A = new BN(1);
- var B = new BN(0);
+inherits(Sha384, SHA512)
- // C * x + D * y = y
- var C = new BN(0);
- var D = new BN(1);
+Sha384.prototype.init = function () {
+ this._ah = 0xcbbb9d5d
+ this._bh = 0x629a292a
+ this._ch = 0x9159015a
+ this._dh = 0x152fecd8
+ this._eh = 0x67332667
+ this._fh = 0x8eb44a87
+ this._gh = 0xdb0c2e0d
+ this._hh = 0x47b5481d
- var g = 0;
+ this._al = 0xc1059ed8
+ this._bl = 0x367cd507
+ this._cl = 0x3070dd17
+ this._dl = 0xf70e5939
+ this._el = 0xffc00b31
+ this._fl = 0x68581511
+ this._gl = 0x64f98fa7
+ this._hl = 0xbefa4fa4
- while (x.isEven() && y.isEven()) {
- x.iushrn(1);
- y.iushrn(1);
- ++g;
- }
+ return this
+}
- var yp = y.clone();
- var xp = x.clone();
+Sha384.prototype._hash = function () {
+ var H = Buffer.allocUnsafe(48)
- while (!x.isZero()) {
- for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) {
- x.iushrn(i);
- while (i-- > 0) {
- if (A.isOdd() || B.isOdd()) {
- A.iadd(yp);
- B.isub(xp);
- }
+ function writeInt64BE (h, l, offset) {
+ H.writeInt32BE(h, offset)
+ H.writeInt32BE(l, offset + 4)
+ }
- A.iushrn(1);
- B.iushrn(1);
- }
- }
+ writeInt64BE(this._ah, this._al, 0)
+ writeInt64BE(this._bh, this._bl, 8)
+ writeInt64BE(this._ch, this._cl, 16)
+ writeInt64BE(this._dh, this._dl, 24)
+ writeInt64BE(this._eh, this._el, 32)
+ writeInt64BE(this._fh, this._fl, 40)
- for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) {
- y.iushrn(j);
- while (j-- > 0) {
- if (C.isOdd() || D.isOdd()) {
- C.iadd(yp);
- D.isub(xp);
- }
+ return H
+}
- C.iushrn(1);
- D.iushrn(1);
- }
- }
+module.exports = Sha384
- if (x.cmp(y) >= 0) {
- x.isub(y);
- A.isub(C);
- B.isub(D);
- } else {
- y.isub(x);
- C.isub(A);
- D.isub(B);
- }
- }
+},{"./hash":102,"./sha512":109,"inherits":96,"safe-buffer":101}],109:[function(require,module,exports){
+var inherits = require('inherits')
+var Hash = require('./hash')
+var Buffer = require('safe-buffer').Buffer
- return {
- a: C,
- b: D,
- gcd: y.iushln(g)
- };
- };
+var K = [
+ 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 is reduced incarnation of the binary EEA
- // above, designated to invert members of the
- // _prime_ fields F(p) at a maximal speed
- BN.prototype._invmp = function _invmp (p) {
- assert(p.negative === 0);
- assert(!p.isZero());
+var W = new Array(160)
- var a = this;
- var b = p.clone();
+function Sha512 () {
+ this.init()
+ this._w = W
- if (a.negative !== 0) {
- a = a.umod(p);
- } else {
- a = a.clone();
- }
+ Hash.call(this, 128, 112)
+}
- var x1 = new BN(1);
- var x2 = new BN(0);
+inherits(Sha512, Hash)
- var delta = b.clone();
+Sha512.prototype.init = function () {
+ this._ah = 0x6a09e667
+ this._bh = 0xbb67ae85
+ this._ch = 0x3c6ef372
+ this._dh = 0xa54ff53a
+ this._eh = 0x510e527f
+ this._fh = 0x9b05688c
+ this._gh = 0x1f83d9ab
+ this._hh = 0x5be0cd19
- while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
- for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
- if (i > 0) {
- a.iushrn(i);
- while (i-- > 0) {
- if (x1.isOdd()) {
- x1.iadd(delta);
- }
+ this._al = 0xf3bcc908
+ this._bl = 0x84caa73b
+ this._cl = 0xfe94f82b
+ this._dl = 0x5f1d36f1
+ this._el = 0xade682d1
+ this._fl = 0x2b3e6c1f
+ this._gl = 0xfb41bd6b
+ this._hl = 0x137e2179
- x1.iushrn(1);
- }
- }
+ return this
+}
- for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
- if (j > 0) {
- b.iushrn(j);
- while (j-- > 0) {
- if (x2.isOdd()) {
- x2.iadd(delta);
- }
+function Ch (x, y, z) {
+ return z ^ (x & (y ^ z))
+}
- x2.iushrn(1);
- }
- }
+function maj (x, y, z) {
+ return (x & y) | (z & (x | y))
+}
- if (a.cmp(b) >= 0) {
- a.isub(b);
- x1.isub(x2);
- } else {
- b.isub(a);
- x2.isub(x1);
- }
- }
+function sigma0 (x, xl) {
+ return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25)
+}
- var res;
- if (a.cmpn(1) === 0) {
- res = x1;
- } else {
- res = x2;
- }
+function sigma1 (x, xl) {
+ return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23)
+}
- if (res.cmpn(0) < 0) {
- res.iadd(p);
- }
+function Gamma0 (x, xl) {
+ return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7)
+}
- return res;
- };
+function Gamma0l (x, xl) {
+ return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25)
+}
- BN.prototype.gcd = function gcd (num) {
- if (this.isZero()) return num.abs();
- if (num.isZero()) return this.abs();
+function Gamma1 (x, xl) {
+ return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6)
+}
- var a = this.clone();
- var b = num.clone();
- a.negative = 0;
- b.negative = 0;
+function Gamma1l (x, xl) {
+ return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26)
+}
- // Remove common factor of two
- for (var shift = 0; a.isEven() && b.isEven(); shift++) {
- a.iushrn(1);
- b.iushrn(1);
- }
+function getCarry (a, b) {
+ return (a >>> 0) < (b >>> 0) ? 1 : 0
+}
- do {
- while (a.isEven()) {
- a.iushrn(1);
- }
- while (b.isEven()) {
- b.iushrn(1);
- }
+Sha512.prototype._update = function (M) {
+ var W = this._w
- var r = a.cmp(b);
- if (r < 0) {
- // Swap `a` and `b` to make `a` always bigger than `b`
- var t = a;
- a = b;
- b = t;
- } else if (r === 0 || b.cmpn(1) === 0) {
- break;
- }
+ var ah = this._ah | 0
+ var bh = this._bh | 0
+ var ch = this._ch | 0
+ var dh = this._dh | 0
+ var eh = this._eh | 0
+ var fh = this._fh | 0
+ var gh = this._gh | 0
+ var hh = this._hh | 0
- a.isub(b);
- } while (true);
+ var al = this._al | 0
+ var bl = this._bl | 0
+ var cl = this._cl | 0
+ var dl = this._dl | 0
+ var el = this._el | 0
+ var fl = this._fl | 0
+ var gl = this._gl | 0
+ var hl = this._hl | 0
- return b.iushln(shift);
- };
+ for (var i = 0; i < 32; i += 2) {
+ W[i] = M.readInt32BE(i * 4)
+ W[i + 1] = M.readInt32BE(i * 4 + 4)
+ }
+ for (; i < 160; i += 2) {
+ var xh = W[i - 15 * 2]
+ var xl = W[i - 15 * 2 + 1]
+ var gamma0 = Gamma0(xh, xl)
+ var gamma0l = Gamma0l(xl, xh)
- // Invert number in the field F(num)
- BN.prototype.invm = function invm (num) {
- return this.egcd(num).a.umod(num);
- };
+ xh = W[i - 2 * 2]
+ xl = W[i - 2 * 2 + 1]
+ var gamma1 = Gamma1(xh, xl)
+ var gamma1l = Gamma1l(xl, xh)
- BN.prototype.isEven = function isEven () {
- return (this.words[0] & 1) === 0;
- };
+ // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
+ var Wi7h = W[i - 7 * 2]
+ var Wi7l = W[i - 7 * 2 + 1]
- BN.prototype.isOdd = function isOdd () {
- return (this.words[0] & 1) === 1;
- };
+ var Wi16h = W[i - 16 * 2]
+ var Wi16l = W[i - 16 * 2 + 1]
- // And first word and num
- BN.prototype.andln = function andln (num) {
- return this.words[0] & num;
- };
+ var Wil = (gamma0l + Wi7l) | 0
+ var Wih = (gamma0 + Wi7h + getCarry(Wil, gamma0l)) | 0
+ Wil = (Wil + gamma1l) | 0
+ Wih = (Wih + gamma1 + getCarry(Wil, gamma1l)) | 0
+ Wil = (Wil + Wi16l) | 0
+ Wih = (Wih + Wi16h + getCarry(Wil, Wi16l)) | 0
- // Increment at the bit position in-line
- BN.prototype.bincn = function bincn (bit) {
- assert(typeof bit === 'number');
- var r = bit % 26;
- var s = (bit - r) / 26;
- var q = 1 << r;
+ W[i] = Wih
+ W[i + 1] = Wil
+ }
- // Fast case: bit is much higher than all existing words
- if (this.length <= s) {
- this._expand(s + 1);
- this.words[s] |= q;
- return this;
- }
+ for (var j = 0; j < 160; j += 2) {
+ Wih = W[j]
+ Wil = W[j + 1]
- // Add bit and propagate, if needed
- var carry = q;
- for (var i = s; carry !== 0 && i < this.length; i++) {
- var w = this.words[i] | 0;
- w += carry;
- carry = w >>> 26;
- w &= 0x3ffffff;
- this.words[i] = w;
- }
- if (carry !== 0) {
- this.words[i] = carry;
- this.length++;
- }
- return this;
- };
+ var majh = maj(ah, bh, ch)
+ var majl = maj(al, bl, cl)
- BN.prototype.isZero = function isZero () {
- return this.length === 1 && this.words[0] === 0;
- };
+ var sigma0h = sigma0(ah, al)
+ var sigma0l = sigma0(al, ah)
+ var sigma1h = sigma1(eh, el)
+ var sigma1l = sigma1(el, eh)
- BN.prototype.cmpn = function cmpn (num) {
- var negative = num < 0;
+ // t1 = h + sigma1 + ch + K[j] + W[j]
+ var Kih = K[j]
+ var Kil = K[j + 1]
- if (this.negative !== 0 && !negative) return -1;
- if (this.negative === 0 && negative) return 1;
+ var chh = Ch(eh, fh, gh)
+ var chl = Ch(el, fl, gl)
- this.strip();
+ var t1l = (hl + sigma1l) | 0
+ var t1h = (hh + sigma1h + getCarry(t1l, hl)) | 0
+ t1l = (t1l + chl) | 0
+ t1h = (t1h + chh + getCarry(t1l, chl)) | 0
+ t1l = (t1l + Kil) | 0
+ t1h = (t1h + Kih + getCarry(t1l, Kil)) | 0
+ t1l = (t1l + Wil) | 0
+ t1h = (t1h + Wih + getCarry(t1l, Wil)) | 0
- var res;
- if (this.length > 1) {
- res = 1;
- } else {
- if (negative) {
- num = -num;
- }
+ // t2 = sigma0 + maj
+ var t2l = (sigma0l + majl) | 0
+ var t2h = (sigma0h + majh + getCarry(t2l, sigma0l)) | 0
- assert(num <= 0x3ffffff, 'Number is too big');
+ hh = gh
+ hl = gl
+ gh = fh
+ gl = fl
+ fh = eh
+ fl = el
+ el = (dl + t1l) | 0
+ eh = (dh + t1h + getCarry(el, dl)) | 0
+ dh = ch
+ dl = cl
+ ch = bh
+ cl = bl
+ bh = ah
+ bl = al
+ al = (t1l + t2l) | 0
+ ah = (t1h + t2h + getCarry(al, t1l)) | 0
+ }
- var w = this.words[0] | 0;
- res = w === num ? 0 : w < num ? -1 : 1;
- }
- if (this.negative !== 0) return -res | 0;
- return res;
- };
+ this._al = (this._al + al) | 0
+ this._bl = (this._bl + bl) | 0
+ this._cl = (this._cl + cl) | 0
+ this._dl = (this._dl + dl) | 0
+ this._el = (this._el + el) | 0
+ this._fl = (this._fl + fl) | 0
+ this._gl = (this._gl + gl) | 0
+ this._hl = (this._hl + hl) | 0
- // Compare two numbers and return:
- // 1 - if `this` > `num`
- // 0 - if `this` == `num`
- // -1 - if `this` < `num`
- BN.prototype.cmp = function cmp (num) {
- if (this.negative !== 0 && num.negative === 0) return -1;
- if (this.negative === 0 && num.negative !== 0) return 1;
+ this._ah = (this._ah + ah + getCarry(this._al, al)) | 0
+ this._bh = (this._bh + bh + getCarry(this._bl, bl)) | 0
+ this._ch = (this._ch + ch + getCarry(this._cl, cl)) | 0
+ this._dh = (this._dh + dh + getCarry(this._dl, dl)) | 0
+ this._eh = (this._eh + eh + getCarry(this._el, el)) | 0
+ this._fh = (this._fh + fh + getCarry(this._fl, fl)) | 0
+ this._gh = (this._gh + gh + getCarry(this._gl, gl)) | 0
+ this._hh = (this._hh + hh + getCarry(this._hl, hl)) | 0
+}
- var res = this.ucmp(num);
- if (this.negative !== 0) return -res | 0;
- return res;
- };
+Sha512.prototype._hash = function () {
+ var H = Buffer.allocUnsafe(64)
- // Unsigned comparison
- BN.prototype.ucmp = function ucmp (num) {
- // At this point both numbers have the same sign
- if (this.length > num.length) return 1;
- if (this.length < num.length) return -1;
+ function writeInt64BE (h, l, offset) {
+ H.writeInt32BE(h, offset)
+ H.writeInt32BE(l, offset + 4)
+ }
- var res = 0;
- for (var i = this.length - 1; i >= 0; i--) {
- var a = this.words[i] | 0;
- var b = num.words[i] | 0;
+ writeInt64BE(this._ah, this._al, 0)
+ writeInt64BE(this._bh, this._bl, 8)
+ writeInt64BE(this._ch, this._cl, 16)
+ writeInt64BE(this._dh, this._dl, 24)
+ writeInt64BE(this._eh, this._el, 32)
+ writeInt64BE(this._fh, this._fl, 40)
+ writeInt64BE(this._gh, this._gl, 48)
+ writeInt64BE(this._hh, this._hl, 56)
- if (a === b) continue;
- if (a < b) {
- res = -1;
- } else if (a > b) {
- res = 1;
- }
- break;
- }
- return res;
- };
+ return H
+}
- BN.prototype.gtn = function gtn (num) {
- return this.cmpn(num) === 1;
- };
+module.exports = Sha512
- BN.prototype.gt = function gt (num) {
- return this.cmp(num) === 1;
- };
+},{"./hash":102,"inherits":96,"safe-buffer":101}],110:[function(require,module,exports){
+var native = require('./native')
- BN.prototype.gten = function gten (num) {
- return this.cmpn(num) >= 0;
- };
+function getTypeName (fn) {
+ return fn.name || fn.toString().match(/function (.*?)\s*\(/)[1]
+}
- BN.prototype.gte = function gte (num) {
- return this.cmp(num) >= 0;
- };
+function getValueTypeName (value) {
+ return native.Nil(value) ? '' : getTypeName(value.constructor)
+}
- BN.prototype.ltn = function ltn (num) {
- return this.cmpn(num) === -1;
- };
+function getValue (value) {
+ if (native.Function(value)) return ''
+ if (native.String(value)) return JSON.stringify(value)
+ if (value && native.Object(value)) return ''
+ return value
+}
- BN.prototype.lt = function lt (num) {
- return this.cmp(num) === -1;
- };
+function tfJSON (type) {
+ if (native.Function(type)) return type.toJSON ? type.toJSON() : getTypeName(type)
+ if (native.Array(type)) return 'Array'
+ if (type && native.Object(type)) return 'Object'
- BN.prototype.lten = function lten (num) {
- return this.cmpn(num) <= 0;
- };
+ return type !== undefined ? type : ''
+}
- BN.prototype.lte = function lte (num) {
- return this.cmp(num) <= 0;
- };
+function tfErrorString (type, value, valueTypeName) {
+ var valueJson = getValue(value)
- BN.prototype.eqn = function eqn (num) {
- return this.cmpn(num) === 0;
- };
+ return 'Expected ' + tfJSON(type) + ', got' +
+ (valueTypeName !== '' ? ' ' + valueTypeName : '') +
+ (valueJson !== '' ? ' ' + valueJson : '')
+}
- BN.prototype.eq = function eq (num) {
- return this.cmp(num) === 0;
- };
+function TfTypeError (type, value, valueTypeName) {
+ valueTypeName = valueTypeName || getValueTypeName(value)
+ this.message = tfErrorString(type, value, valueTypeName)
- //
- // A reduce context, could be using montgomery or something better, depending
- // on the `m` itself.
- //
- BN.red = function red (num) {
- return new Red(num);
- };
+ Error.captureStackTrace(this, TfTypeError)
+ this.__type = type
+ this.__value = value
+ this.__valueTypeName = valueTypeName
+}
- BN.prototype.toRed = function toRed (ctx) {
- assert(!this.red, 'Already a number in reduction context');
- assert(this.negative === 0, 'red works only with positives');
- return ctx.convertTo(this)._forceRed(ctx);
- };
+TfTypeError.prototype = Object.create(Error.prototype)
+TfTypeError.prototype.constructor = TfTypeError
- BN.prototype.fromRed = function fromRed () {
- assert(this.red, 'fromRed works only with numbers in reduction context');
- return this.red.convertFrom(this);
- };
+function tfPropertyErrorString (type, label, name, value, valueTypeName) {
+ var description = '" of type '
+ if (label === 'key') description = '" with key type '
- BN.prototype._forceRed = function _forceRed (ctx) {
- this.red = ctx;
- return this;
- };
+ return tfErrorString('property "' + tfJSON(name) + description + tfJSON(type), value, valueTypeName)
+}
- BN.prototype.forceRed = function forceRed (ctx) {
- assert(!this.red, 'Already a number in reduction context');
- return this._forceRed(ctx);
- };
+function TfPropertyTypeError (type, property, label, value, valueTypeName) {
+ if (type) {
+ valueTypeName = valueTypeName || getValueTypeName(value)
+ this.message = tfPropertyErrorString(type, label, property, value, valueTypeName)
+ } else {
+ this.message = 'Unexpected property "' + property + '"'
+ }
- BN.prototype.redAdd = function redAdd (num) {
- assert(this.red, 'redAdd works only with red numbers');
- return this.red.add(this, num);
- };
+ Error.captureStackTrace(this, TfTypeError)
+ this.__label = label
+ this.__property = property
+ this.__type = type
+ this.__value = value
+ this.__valueTypeName = valueTypeName
+}
- BN.prototype.redIAdd = function redIAdd (num) {
- assert(this.red, 'redIAdd works only with red numbers');
- return this.red.iadd(this, num);
- };
+TfPropertyTypeError.prototype = Object.create(Error.prototype)
+TfPropertyTypeError.prototype.constructor = TfTypeError
- BN.prototype.redSub = function redSub (num) {
- assert(this.red, 'redSub works only with red numbers');
- return this.red.sub(this, num);
- };
+function tfCustomError (expected, actual) {
+ return new TfTypeError(expected, {}, actual)
+}
- BN.prototype.redISub = function redISub (num) {
- assert(this.red, 'redISub works only with red numbers');
- return this.red.isub(this, num);
- };
+function tfSubError (e, property, label) {
+ // sub child?
+ if (e instanceof TfPropertyTypeError) {
+ property = property + '.' + e.__property
- BN.prototype.redShl = function redShl (num) {
- assert(this.red, 'redShl works only with red numbers');
- return this.red.shl(this, num);
- };
+ e = new TfPropertyTypeError(
+ e.__type, property, e.__label, e.__value, e.__valueTypeName
+ )
- BN.prototype.redMul = function redMul (num) {
- assert(this.red, 'redMul works only with red numbers');
- this.red._verify2(this, num);
- return this.red.mul(this, num);
- };
+ // child?
+ } else if (e instanceof TfTypeError) {
+ e = new TfPropertyTypeError(
+ e.__type, property, label, e.__value, e.__valueTypeName
+ )
+ }
- BN.prototype.redIMul = function redIMul (num) {
- assert(this.red, 'redMul works only with red numbers');
- this.red._verify2(this, num);
- return this.red.imul(this, num);
- };
+ Error.captureStackTrace(e)
+ return e
+}
- BN.prototype.redSqr = function redSqr () {
- assert(this.red, 'redSqr works only with red numbers');
- this.red._verify1(this);
- return this.red.sqr(this);
- };
+module.exports = {
+ TfTypeError: TfTypeError,
+ TfPropertyTypeError: TfPropertyTypeError,
+ tfCustomError: tfCustomError,
+ tfSubError: tfSubError,
+ tfJSON: tfJSON,
+ getValueTypeName: getValueTypeName
+}
- BN.prototype.redISqr = function redISqr () {
- assert(this.red, 'redISqr works only with red numbers');
- this.red._verify1(this);
- return this.red.isqr(this);
- };
+},{"./native":113}],111:[function(require,module,exports){
+(function (Buffer){
+var NATIVE = require('./native')
+var ERRORS = require('./errors')
- // Square root over p
- BN.prototype.redSqrt = function redSqrt () {
- assert(this.red, 'redSqrt works only with red numbers');
- this.red._verify1(this);
- return this.red.sqrt(this);
- };
+function _Buffer (value) {
+ return Buffer.isBuffer(value)
+}
- BN.prototype.redInvm = function redInvm () {
- assert(this.red, 'redInvm works only with red numbers');
- this.red._verify1(this);
- return this.red.invm(this);
- };
+function Hex (value) {
+ return typeof value === 'string' && /^([0-9a-f]{2})+$/i.test(value)
+}
- // Return negative clone of `this` % `red modulo`
- BN.prototype.redNeg = function redNeg () {
- assert(this.red, 'redNeg works only with red numbers');
- this.red._verify1(this);
- return this.red.neg(this);
- };
+function _LengthN (type, length) {
+ var name = type.toJSON()
- BN.prototype.redPow = function redPow (num) {
- assert(this.red && !num.red, 'redPow(normalNum)');
- this.red._verify1(this);
- return this.red.pow(this, num);
- };
+ function Length (value) {
+ if (!type(value)) return false
+ if (value.length === length) return true
- // Prime numbers with efficient reduction
- var primes = {
- k256: null,
- p224: null,
- p192: null,
- p25519: null
- };
+ throw ERRORS.tfCustomError(name + '(Length: ' + length + ')', name + '(Length: ' + value.length + ')')
+ }
+ Length.toJSON = function () { return name }
- // Pseudo-Mersenne prime
- function MPrime (name, p) {
- // P = 2 ^ N - K
- this.name = name;
- this.p = new BN(p, 16);
- this.n = this.p.bitLength();
- this.k = new BN(1).iushln(this.n).isub(this.p);
+ return Length
+}
- this.tmp = this._tmp();
- }
+var _ArrayN = _LengthN.bind(null, NATIVE.Array)
+var _BufferN = _LengthN.bind(null, _Buffer)
+var _HexN = _LengthN.bind(null, Hex)
+var _StringN = _LengthN.bind(null, NATIVE.String)
- MPrime.prototype._tmp = function _tmp () {
- var tmp = new BN(null);
- tmp.words = new Array(Math.ceil(this.n / 13));
- return tmp;
- };
+var UINT53_MAX = Math.pow(2, 53) - 1
- MPrime.prototype.ireduce = function ireduce (num) {
- // Assumes that `num` is less than `P^2`
- // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
- var r = num;
- var rlen;
-
- do {
- this.split(r, this.tmp);
- r = this.imulK(r);
- r = r.iadd(this.tmp);
- rlen = r.bitLength();
- } while (rlen > this.n);
+function Finite (value) {
+ return typeof value === 'number' && isFinite(value)
+}
+function Int8 (value) { return ((value << 24) >> 24) === value }
+function Int16 (value) { return ((value << 16) >> 16) === value }
+function Int32 (value) { return (value | 0) === value }
+function UInt8 (value) { return (value & 0xff) === value }
+function UInt16 (value) { return (value & 0xffff) === value }
+function UInt32 (value) { return (value >>> 0) === value }
+function UInt53 (value) {
+ return typeof value === 'number' &&
+ value >= 0 &&
+ value <= UINT53_MAX &&
+ Math.floor(value) === value
+}
- var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
- if (cmp === 0) {
- r.words[0] = 0;
- r.length = 1;
- } else if (cmp > 0) {
- r.isub(this.p);
- } else {
- r.strip();
- }
+var types = {
+ ArrayN: _ArrayN,
+ Buffer: _Buffer,
+ BufferN: _BufferN,
+ Finite: Finite,
+ Hex: Hex,
+ HexN: _HexN,
+ Int8: Int8,
+ Int16: Int16,
+ Int32: Int32,
+ StringN: _StringN,
+ UInt8: UInt8,
+ UInt16: UInt16,
+ UInt32: UInt32,
+ UInt53: UInt53
+}
- return r;
- };
+for (var typeName in types) {
+ types[typeName].toJSON = function (t) {
+ return t
+ }.bind(null, typeName)
+}
- MPrime.prototype.split = function split (input, out) {
- input.iushrn(this.n, 0, out);
- };
+module.exports = types
- MPrime.prototype.imulK = function imulK (num) {
- return num.imul(this.k);
- };
+}).call(this,{"isBuffer":require("../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js")})
+},{"../../../../../.nvm/versions/node/v6.0.0/lib/node_modules/browserify/node_modules/is-buffer/index.js":10,"./errors":110,"./native":113}],112:[function(require,module,exports){
+var ERRORS = require('./errors')
+var NATIVE = require('./native')
- function K256 () {
- MPrime.call(
- this,
- 'k256',
- 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
- }
- inherits(K256, MPrime);
+// short-hand
+var tfJSON = ERRORS.tfJSON
+var TfTypeError = ERRORS.TfTypeError
+var TfPropertyTypeError = ERRORS.TfPropertyTypeError
+var tfSubError = ERRORS.tfSubError
+var getValueTypeName = ERRORS.getValueTypeName
- K256.prototype.split = function split (input, output) {
- // 256 = 9 * 26 + 22
- var mask = 0x3fffff;
+var TYPES = {
+ arrayOf: function arrayOf (type) {
+ type = compile(type)
- var outLen = Math.min(input.length, 9);
- for (var i = 0; i < outLen; i++) {
- output.words[i] = input.words[i];
- }
- output.length = outLen;
+ function _arrayOf (array, strict) {
+ if (!NATIVE.Array(array)) return false
+ if (NATIVE.Nil(array)) return false
- if (input.length <= 9) {
- input.words[0] = 0;
- input.length = 1;
- return;
+ return array.every(function (value, i) {
+ try {
+ return typeforce(type, value, strict)
+ } catch (e) {
+ throw tfSubError(e, i)
+ }
+ })
}
+ _arrayOf.toJSON = function () { return '[' + tfJSON(type) + ']' }
- // Shift by 9 limbs
- var prev = input.words[9];
- output.words[output.length++] = prev & mask;
-
- for (i = 10; i < input.length; i++) {
- var next = input.words[i] | 0;
- input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
- prev = next;
- }
- prev >>>= 22;
- input.words[i - 10] = prev;
- if (prev === 0 && input.length > 10) {
- input.length -= 10;
- } else {
- input.length -= 9;
- }
- };
+ return _arrayOf
+ },
- K256.prototype.imulK = function imulK (num) {
- // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
- num.words[num.length] = 0;
- num.words[num.length + 1] = 0;
- num.length += 2;
+ maybe: function maybe (type) {
+ type = compile(type)
- // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
- var lo = 0;
- for (var i = 0; i < num.length; i++) {
- var w = num.words[i] | 0;
- lo += w * 0x3d1;
- num.words[i] = lo & 0x3ffffff;
- lo = w * 0x40 + ((lo / 0x4000000) | 0);
+ function _maybe (value, strict) {
+ return NATIVE.Nil(value) || type(value, strict, maybe)
}
+ _maybe.toJSON = function () { return '?' + tfJSON(type) }
- // Fast length reduction
- if (num.words[num.length - 1] === 0) {
- num.length--;
- if (num.words[num.length - 1] === 0) {
- num.length--;
- }
- }
- return num;
- };
+ return _maybe
+ },
- function P224 () {
- MPrime.call(
- this,
- 'p224',
- 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
- }
- inherits(P224, MPrime);
+ map: function map (propertyType, propertyKeyType) {
+ propertyType = compile(propertyType)
+ if (propertyKeyType) propertyKeyType = compile(propertyKeyType)
- function P192 () {
- MPrime.call(
- this,
- 'p192',
- 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
- }
- inherits(P192, MPrime);
+ function _map (value, strict) {
+ if (!NATIVE.Object(value)) return false
+ if (NATIVE.Nil(value)) return false
- function P25519 () {
- // 2 ^ 255 - 19
- MPrime.call(
- this,
- '25519',
- '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
- }
- inherits(P25519, MPrime);
+ for (var propertyName in value) {
+ try {
+ if (propertyKeyType) {
+ typeforce(propertyKeyType, propertyName, strict)
+ }
+ } catch (e) {
+ throw tfSubError(e, propertyName, 'key')
+ }
- P25519.prototype.imulK = function imulK (num) {
- // K = 0x13
- var carry = 0;
- for (var i = 0; i < num.length; i++) {
- var hi = (num.words[i] | 0) * 0x13 + carry;
- var lo = hi & 0x3ffffff;
- hi >>>= 26;
+ try {
+ var propertyValue = value[propertyName]
+ typeforce(propertyType, propertyValue, strict)
+ } catch (e) {
+ throw tfSubError(e, propertyName)
+ }
+ }
- num.words[i] = lo;
- carry = hi;
- }
- if (carry !== 0) {
- num.words[num.length++] = carry;
+ return true
}
- return num;
- };
-
- // Exported mostly for testing purposes, use plain name instead
- BN._prime = function prime (name) {
- // Cached version of prime
- if (primes[name]) return primes[name];
- var prime;
- if (name === 'k256') {
- prime = new K256();
- } else if (name === 'p224') {
- prime = new P224();
- } else if (name === 'p192') {
- prime = new P192();
- } else if (name === 'p25519') {
- prime = new P25519();
+ if (propertyKeyType) {
+ _map.toJSON = function () {
+ return '{' + tfJSON(propertyKeyType) + ': ' + tfJSON(propertyType) + '}'
+ }
} else {
- throw new Error('Unknown prime ' + name);
+ _map.toJSON = function () { return '{' + tfJSON(propertyType) + '}' }
}
- primes[name] = prime;
- return prime;
- };
+ return _map
+ },
- //
- // Base reduction engine
- //
- function Red (m) {
- if (typeof m === 'string') {
- var prime = BN._prime(m);
- this.m = prime.p;
- this.prime = prime;
- } else {
- assert(m.gtn(1), 'modulus must be greater than 1');
- this.m = m;
- this.prime = null;
+ object: function object (uncompiled) {
+ var type = {}
+
+ for (var typePropertyName in uncompiled) {
+ type[typePropertyName] = compile(uncompiled[typePropertyName])
}
- }
- Red.prototype._verify1 = function _verify1 (a) {
- assert(a.negative === 0, 'red works only with positives');
- assert(a.red, 'red works only with red numbers');
- };
+ function _object (value, strict) {
+ if (!NATIVE.Object(value)) return false
+ if (NATIVE.Nil(value)) return false
- Red.prototype._verify2 = function _verify2 (a, b) {
- assert((a.negative | b.negative) === 0, 'red works only with positives');
- assert(a.red && a.red === b.red,
- 'red works only with red numbers');
- };
+ var propertyName
- Red.prototype.imod = function imod (a) {
- if (this.prime) return this.prime.ireduce(a)._forceRed(this);
- return a.umod(this.m)._forceRed(this);
- };
+ try {
+ for (propertyName in type) {
+ var propertyType = type[propertyName]
+ var propertyValue = value[propertyName]
- Red.prototype.neg = function neg (a) {
- if (a.isZero()) {
- return a.clone();
+ typeforce(propertyType, propertyValue, strict)
+ }
+ } catch (e) {
+ throw tfSubError(e, propertyName)
+ }
+
+ if (strict) {
+ for (propertyName in value) {
+ if (type[propertyName]) continue
+
+ throw new TfPropertyTypeError(undefined, propertyName)
+ }
+ }
+
+ return true
}
+ _object.toJSON = function () { return tfJSON(type) }
- return this.m.sub(a)._forceRed(this);
- };
+ return _object
+ },
- Red.prototype.add = function add (a, b) {
- this._verify2(a, b);
+ oneOf: function oneOf () {
+ var types = [].slice.call(arguments).map(compile)
- var res = a.add(b);
- if (res.cmp(this.m) >= 0) {
- res.isub(this.m);
+ function _oneOf (value, strict) {
+ return types.some(function (type) {
+ try {
+ return typeforce(type, value, strict)
+ } catch (e) {
+ return false
+ }
+ })
}
- return res._forceRed(this);
- };
+ _oneOf.toJSON = function () { return types.map(tfJSON).join('|') }
- Red.prototype.iadd = function iadd (a, b) {
- this._verify2(a, b);
+ return _oneOf
+ },
- var res = a.iadd(b);
- if (res.cmp(this.m) >= 0) {
- res.isub(this.m);
+ quacksLike: function quacksLike (type) {
+ function _quacksLike (value) {
+ return type === getValueTypeName(value)
}
- return res;
- };
+ _quacksLike.toJSON = function () { return type }
- Red.prototype.sub = function sub (a, b) {
- this._verify2(a, b);
+ return _quacksLike
+ },
- var res = a.sub(b);
- if (res.cmpn(0) < 0) {
- res.iadd(this.m);
+ tuple: function tuple () {
+ var types = [].slice.call(arguments).map(compile)
+
+ function _tuple (values, strict) {
+ if (NATIVE.Nil(values)) return false
+ if (NATIVE.Nil(values.length)) return false
+ if (strict && (values.length !== types.length)) return false
+
+ return types.every(function (type, i) {
+ try {
+ return typeforce(type, values[i], strict)
+ } catch (e) {
+ throw tfSubError(e, i)
+ }
+ })
}
- return res._forceRed(this);
- };
+ _tuple.toJSON = function () { return '(' + types.map(tfJSON).join(', ') + ')' }
- Red.prototype.isub = function isub (a, b) {
- this._verify2(a, b);
+ return _tuple
+ },
- var res = a.isub(b);
- if (res.cmpn(0) < 0) {
- res.iadd(this.m);
+ value: function value (expected) {
+ function _value (actual) {
+ return actual === expected
}
- return res;
- };
+ _value.toJSON = function () { return expected }
- Red.prototype.shl = function shl (a, num) {
- this._verify1(a);
- return this.imod(a.ushln(num));
- };
+ return _value
+ }
+}
- Red.prototype.imul = function imul (a, b) {
- this._verify2(a, b);
- return this.imod(a.imul(b));
- };
+function compile (type) {
+ if (NATIVE.String(type)) {
+ if (type[0] === '?') return TYPES.maybe(type.slice(1))
- Red.prototype.mul = function mul (a, b) {
- this._verify2(a, b);
- return this.imod(a.mul(b));
- };
+ return NATIVE[type] || TYPES.quacksLike(type)
+ } else if (type && NATIVE.Object(type)) {
+ if (NATIVE.Array(type)) return TYPES.arrayOf(type[0])
- Red.prototype.isqr = function isqr (a) {
- return this.imul(a, a.clone());
- };
+ return TYPES.object(type)
+ } else if (NATIVE.Function(type)) {
+ return type
+ }
- Red.prototype.sqr = function sqr (a) {
- return this.mul(a, a);
- };
+ return TYPES.value(type)
+}
- Red.prototype.sqrt = function sqrt (a) {
- if (a.isZero()) return a.clone();
+function typeforce (type, value, strict, surrogate) {
+ if (NATIVE.Function(type)) {
+ if (type(value, strict)) return true
- var mod3 = this.m.andln(3);
- assert(mod3 % 2 === 1);
+ throw new TfTypeError(surrogate || type, value)
+ }
- // Fast case
- if (mod3 === 3) {
- var pow = this.m.add(new BN(1)).iushrn(2);
- return this.pow(a, pow);
- }
+ // JIT
+ return typeforce(compile(type), value, strict)
+}
- // Tonelli-Shanks algorithm (Totally unoptimized and slow)
- //
- // Find Q and S, that Q * 2 ^ S = (P - 1)
- var q = this.m.subn(1);
- var s = 0;
- while (!q.isZero() && q.andln(1) === 0) {
- s++;
- q.iushrn(1);
- }
- assert(!q.isZero());
+// assign types to typeforce function
+for (var typeName in NATIVE) {
+ typeforce[typeName] = NATIVE[typeName]
+}
- var one = new BN(1).toRed(this);
- var nOne = one.redNeg();
+for (typeName in TYPES) {
+ typeforce[typeName] = TYPES[typeName]
+}
- // Find quadratic non-residue
- // NOTE: Max is such because of generalized Riemann hypothesis.
- var lpow = this.m.subn(1).iushrn(1);
- var z = this.m.bitLength();
- z = new BN(2 * z * z).toRed(this);
+var EXTRA = require('./extra')
+for (typeName in EXTRA) {
+ typeforce[typeName] = EXTRA[typeName]
+}
- while (this.pow(z, lpow).cmp(nOne) !== 0) {
- z.redIAdd(nOne);
- }
+// async wrapper
+function __async (type, value, strict, callback) {
+ // default to falsy strict if using shorthand overload
+ if (typeof strict === 'function') return __async(type, value, false, strict)
- var c = this.pow(z, q);
- var r = this.pow(a, q.addn(1).iushrn(1));
- var t = this.pow(a, q);
- var m = s;
- while (t.cmp(one) !== 0) {
- var tmp = t;
- for (var i = 0; tmp.cmp(one) !== 0; i++) {
- tmp = tmp.redSqr();
- }
- assert(i < m);
- var b = this.pow(c, new BN(1).iushln(m - i - 1));
+ try {
+ typeforce(type, value, strict)
+ } catch (e) {
+ return callback(e)
+ }
- r = r.redMul(b);
- c = b.redSqr();
- t = t.redMul(c);
- m = i;
- }
+ callback()
+}
- return r;
- };
+typeforce.async = __async
+typeforce.compile = compile
+typeforce.TfTypeError = TfTypeError
+typeforce.TfPropertyTypeError = TfPropertyTypeError
- Red.prototype.invm = function invm (a) {
- var inv = a._invmp(this.m);
- if (inv.negative !== 0) {
- inv.negative = 0;
- return this.imod(inv).redNeg();
- } else {
- return this.imod(inv);
- }
- };
+module.exports = typeforce
- Red.prototype.pow = function pow (a, num) {
- if (num.isZero()) return new BN(1);
- if (num.cmpn(1) === 0) return a.clone();
+},{"./errors":110,"./extra":111,"./native":113}],113:[function(require,module,exports){
+var types = {
+ Array: function (value) { return value !== null && value !== undefined && value.constructor === Array },
+ Boolean: function (value) { return typeof value === 'boolean' },
+ Function: function (value) { return typeof value === 'function' },
+ Nil: function (value) { return value === undefined || value === null },
+ Number: function (value) { return typeof value === 'number' },
+ Object: function (value) { return typeof value === 'object' },
+ String: function (value) { return typeof value === 'string' },
+ '': function () { return true }
+}
- var windowSize = 4;
- var wnd = new Array(1 << windowSize);
- wnd[0] = new BN(1).toRed(this);
- wnd[1] = a;
- for (var i = 2; i < wnd.length; i++) {
- wnd[i] = this.mul(wnd[i - 1], a);
- }
+// TODO: deprecate
+types.Null = types.Nil
- var res = wnd[0];
- var current = 0;
- var currentLen = 0;
- var start = num.bitLength() % 26;
- if (start === 0) {
- start = 26;
- }
-
- for (i = num.length - 1; i >= 0; i--) {
- var word = num.words[i];
- for (var j = start - 1; j >= 0; j--) {
- var bit = (word >> j) & 1;
- if (res !== wnd[0]) {
- res = this.sqr(res);
- }
-
- if (bit === 0 && current === 0) {
- currentLen = 0;
- continue;
- }
-
- current <<= 1;
- current |= bit;
- currentLen++;
- if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
-
- res = this.mul(res, wnd[current]);
- currentLen = 0;
- current = 0;
- }
- start = 26;
- }
+for (var typeName in types) {
+ types[typeName].toJSON = function (t) {
+ return t
+ }.bind(null, typeName)
+}
- return res;
- };
+module.exports = types
- Red.prototype.convertTo = function convertTo (num) {
- var r = num.umod(this.m);
+},{}],114:[function(require,module,exports){
+'use strict'
+var Buffer = require('safe-buffer').Buffer
- return r === num ? r.clone() : r;
- };
+// Number.MAX_SAFE_INTEGER
+var MAX_SAFE_INTEGER = 9007199254740991
- Red.prototype.convertFrom = function convertFrom (num) {
- var res = num.clone();
- res.red = null;
- return res;
- };
+function checkUInt53 (n) {
+ if (n < 0 || n > MAX_SAFE_INTEGER || n % 1 !== 0) throw new RangeError('value out of range')
+}
- //
- // Montgomery method engine
- //
+function encode (number, buffer, offset) {
+ checkUInt53(number)
- BN.mont = function mont (num) {
- return new Mont(num);
- };
+ if (!buffer) buffer = Buffer.allocUnsafe(encodingLength(number))
+ if (!Buffer.isBuffer(buffer)) throw new TypeError('buffer must be a Buffer instance')
+ if (!offset) offset = 0
- function Mont (m) {
- Red.call(this, m);
+ // 8 bit
+ if (number < 0xfd) {
+ buffer.writeUInt8(number, offset)
+ encode.bytes = 1
- this.shift = this.m.bitLength();
- if (this.shift % 26 !== 0) {
- this.shift += 26 - (this.shift % 26);
- }
+ // 16 bit
+ } else if (number <= 0xffff) {
+ buffer.writeUInt8(0xfd, offset)
+ buffer.writeUInt16LE(number, offset + 1)
+ encode.bytes = 3
- this.r = new BN(1).iushln(this.shift);
- this.r2 = this.imod(this.r.sqr());
- this.rinv = this.r._invmp(this.m);
+ // 32 bit
+ } else if (number <= 0xffffffff) {
+ buffer.writeUInt8(0xfe, offset)
+ buffer.writeUInt32LE(number, offset + 1)
+ encode.bytes = 5
- this.minv = this.rinv.mul(this.r).isubn(1).div(this.m);
- this.minv = this.minv.umod(this.r);
- this.minv = this.r.sub(this.minv);
+ // 64 bit
+ } else {
+ buffer.writeUInt8(0xff, offset)
+ buffer.writeUInt32LE(number >>> 0, offset + 1)
+ buffer.writeUInt32LE((number / 0x100000000) | 0, offset + 5)
+ encode.bytes = 9
}
- inherits(Mont, Red);
-
- Mont.prototype.convertTo = function convertTo (num) {
- return this.imod(num.ushln(this.shift));
- };
-
- Mont.prototype.convertFrom = function convertFrom (num) {
- var r = this.imod(num.mul(this.rinv));
- r.red = null;
- return r;
- };
-
- Mont.prototype.imul = function imul (a, b) {
- if (a.isZero() || b.isZero()) {
- a.words[0] = 0;
- a.length = 1;
- return a;
- }
-
- var t = a.imul(b);
- var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
- var u = t.isub(c).iushrn(this.shift);
- var res = u;
-
- if (u.cmp(this.m) >= 0) {
- res = u.isub(this.m);
- } else if (u.cmpn(0) < 0) {
- res = u.iadd(this.m);
- }
-
- return res._forceRed(this);
- };
- Mont.prototype.mul = function mul (a, b) {
- if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
+ return buffer
+}
- var t = a.mul(b);
- var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
- var u = t.isub(c).iushrn(this.shift);
- var res = u;
- if (u.cmp(this.m) >= 0) {
- res = u.isub(this.m);
- } else if (u.cmpn(0) < 0) {
- res = u.iadd(this.m);
- }
+function decode (buffer, offset) {
+ if (!Buffer.isBuffer(buffer)) throw new TypeError('buffer must be a Buffer instance')
+ if (!offset) offset = 0
- return res._forceRed(this);
- };
+ var first = buffer.readUInt8(offset)
- Mont.prototype.invm = function invm (a) {
- // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
- var res = this.imod(a._invmp(this.m).mul(this.r2));
- return res._forceRed(this);
- };
-})(typeof module === 'undefined' || module, this);
+ // 8 bit
+ if (first < 0xfd) {
+ decode.bytes = 1
+ return first
-},{}],82:[function(require,module,exports){
-var r;
+ // 16 bit
+ } else if (first === 0xfd) {
+ decode.bytes = 3
+ return buffer.readUInt16LE(offset + 1)
-module.exports = function rand(len) {
- if (!r)
- r = new Rand(null);
+ // 32 bit
+ } else if (first === 0xfe) {
+ decode.bytes = 5
+ return buffer.readUInt32LE(offset + 1)
- return r.generate(len);
-};
+ // 64 bit
+ } else {
+ decode.bytes = 9
+ var lo = buffer.readUInt32LE(offset + 1)
+ var hi = buffer.readUInt32LE(offset + 5)
+ var number = hi * 0x0100000000 + lo
+ checkUInt53(number)
-function Rand(rand) {
- this.rand = rand;
+ return number
+ }
}
-module.exports.Rand = Rand;
-
-Rand.prototype.generate = function generate(len) {
- return this._rand(len);
-};
-
-// Emulate crypto API using randy
-Rand.prototype._rand = function _rand(n) {
- if (this.rand.getBytes)
- return this.rand.getBytes(n);
-
- var res = new Uint8Array(n);
- for (var i = 0; i < res.length; i++)
- res[i] = this.rand.getByte();
- return res;
-};
-
-if (typeof self === 'object') {
- if (self.crypto && self.crypto.getRandomValues) {
- // Modern browsers
- Rand.prototype._rand = function _rand(n) {
- var arr = new Uint8Array(n);
- self.crypto.getRandomValues(arr);
- return arr;
- };
- } else if (self.msCrypto && self.msCrypto.getRandomValues) {
- // IE
- Rand.prototype._rand = function _rand(n) {
- var arr = new Uint8Array(n);
- self.msCrypto.getRandomValues(arr);
- return arr;
- };
- // Safari's WebWorkers do not have `crypto`
- } else if (typeof window === 'object') {
- // Old junk
- Rand.prototype._rand = function() {
- throw new Error('Not implemented yet');
- };
- }
-} else {
- // Node.js or Web worker with no crypto support
- try {
- var crypto = require('crypto');
- if (typeof crypto.randomBytes !== 'function')
- throw new Error('Not supported');
+function encodingLength (number) {
+ checkUInt53(number)
- Rand.prototype._rand = function _rand(n) {
- return crypto.randomBytes(n);
- };
- } catch (e) {
- }
+ return (
+ number < 0xfd ? 1
+ : number <= 0xffff ? 3
+ : number <= 0xffffffff ? 5
+ : 9
+ )
}
-},{"crypto":3}],83:[function(require,module,exports){
-var basex = require('base-x')
-var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
-
-module.exports = basex(ALPHABET)
+module.exports = { encode: encode, decode: decode, encodingLength: encodingLength }
-},{"base-x":35}],84:[function(require,module,exports){
+},{"safe-buffer":101}],115:[function(require,module,exports){
(function (Buffer){
-'use strict'
-
-var base58 = require('bs58')
-
-module.exports = function (checksumFn) {
- // Encode a buffer as a base58-check encoded string
- function encode (payload) {
- var checksum = checksumFn(payload)
-
- return base58.encode(Buffer.concat([
- payload,
- checksum
- ], payload.length + 4))
- }
-
- function decodeRaw (buffer) {
- var payload = buffer.slice(0, -4)
- var checksum = buffer.slice(-4)
- var newChecksum = checksumFn(payload)
+var bs58check = require('bs58check')
- if (checksum[0] ^ newChecksum[0] |
- checksum[1] ^ newChecksum[1] |
- checksum[2] ^ newChecksum[2] |
- checksum[3] ^ newChecksum[3]) return
+function decodeRaw (buffer, version) {
+ // check version only if defined
+ if (version !== undefined && buffer[0] !== version) throw new Error('Invalid network version')
- return payload
+ // uncompressed
+ if (buffer.length === 33) {
+ return {
+ version: buffer[0],
+ privateKey: buffer.slice(1, 33),
+ compressed: false
+ }
}
- // Decode a base58-check encoded string to a buffer, no result if checksum is wrong
- function decodeUnsafe (string) {
- var buffer = base58.decodeUnsafe(string)
- if (!buffer) return
-
- return decodeRaw(buffer)
- }
+ // invalid length
+ if (buffer.length !== 34) throw new Error('Invalid WIF length')
- function decode (string) {
- var buffer = base58.decode(string)
- var payload = decodeRaw(buffer, checksumFn)
- if (!payload) throw new Error('Invalid checksum')
- return payload
- }
+ // invalid compression flag
+ if (buffer[33] !== 0x01) throw new Error('Invalid compression flag')
return {
- encode: encode,
- decode: decode,
- decodeUnsafe: decodeUnsafe
- }
-}
-
-}).call(this,require("buffer").Buffer)
-},{"bs58":83,"buffer":5}],85:[function(require,module,exports){
-'use strict'
-
-var createHash = require('create-hash')
-var bs58checkBase = require('./base')
-
-// SHA256(SHA256(buffer))
-function sha256x2 (buffer) {
- var tmp = createHash('sha256').update(buffer).digest()
- return createHash('sha256').update(tmp).digest()
-}
-
-module.exports = bs58checkBase(sha256x2)
-
-},{"./base":84,"create-hash":87}],86:[function(require,module,exports){
-var Buffer = require('safe-buffer').Buffer
-var Transform = require('stream').Transform
-var StringDecoder = require('string_decoder').StringDecoder
-var inherits = require('inherits')
-
-function CipherBase (hashMode) {
- Transform.call(this)
- this.hashMode = typeof hashMode === 'string'
- if (this.hashMode) {
- this[hashMode] = this._finalOrDigest
- } else {
- this.final = this._finalOrDigest
- }
- if (this._final) {
- this.__final = this._final
- this._final = null
+ version: buffer[0],
+ privateKey: buffer.slice(1, 33),
+ compressed: true
}
- this._decoder = null
- this._encoding = null
}
-inherits(CipherBase, Transform)
-CipherBase.prototype.update = function (data, inputEnc, outputEnc) {
- if (typeof data === 'string') {
- data = Buffer.from(data, inputEnc)
- }
+function encodeRaw (version, privateKey, compressed) {
+ var result = new Buffer(compressed ? 34 : 33)
- var outData = this._update(data)
- if (this.hashMode) return this
+ result.writeUInt8(version, 0)
+ privateKey.copy(result, 1)
- if (outputEnc) {
- outData = this._toString(outData, outputEnc)
+ if (compressed) {
+ result[33] = 0x01
}
- return outData
+ return result
}
-CipherBase.prototype.setAutoPadding = function () {}
-CipherBase.prototype.getAuthTag = function () {
- throw new Error('trying to get auth tag in unsupported state')
+function decode (string, version) {
+ return decodeRaw(bs58check.decode(string), version)
}
-CipherBase.prototype.setAuthTag = function () {
- throw new Error('trying to set auth tag in unsupported state')
-}
+function encode (version, privateKey, compressed) {
+ if (typeof version === 'number') return bs58check.encode(encodeRaw(version, privateKey, compressed))
-CipherBase.prototype.setAAD = function () {
- throw new Error('trying to set aad in unsupported state')
+ return bs58check.encode(
+ encodeRaw(
+ version.version,
+ version.privateKey,
+ version.compressed
+ )
+ )
}
-CipherBase.prototype._transform = function (data, _, next) {
- var err
- try {
- if (this.hashMode) {
- this._update(data)
- } else {
- this.push(this._update(data))
- }
- } catch (e) {
- err = e
- } finally {
- next(err)
- }
+module.exports = {
+ decode: decode,
+ decodeRaw: decodeRaw,
+ encode: encode,
+ encodeRaw: encodeRaw
}
-CipherBase.prototype._flush = function (done) {
- var err
- try {
- this.push(this.__final())
- } catch (e) {
- err = e
- }
- done(err)
-}
-CipherBase.prototype._finalOrDigest = function (outputEnc) {
- var outData = this.__final() || Buffer.alloc(0)
- if (outputEnc) {
- outData = this._toString(outData, outputEnc, true)
- }
- return outData
-}
+}).call(this,require("buffer").Buffer)
+},{"bs58check":83,"buffer":5}]},{},[34])(34)
+});
+
+
-
-
+
+
-