mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-06 19:03:49 +00:00
Compare commits
168 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa793f572f | ||
|
|
6973e692b0 | ||
|
|
22f8766947 | ||
|
|
8017442c50 | ||
|
|
82cf26c1cb | ||
|
|
206cbafceb | ||
|
|
9cf02dd452 | ||
|
|
f12242014d | ||
|
|
244c76022a | ||
|
|
516c16d721 | ||
|
|
f7e9fdf002 | ||
|
|
5c203fab6a | ||
|
|
40d542ba58 | ||
|
|
cc3c35487f | ||
|
|
76531b610a | ||
|
|
c845ee6f6e | ||
|
|
c394ec3c4f | ||
|
|
55367b989e | ||
|
|
732613e44c | ||
|
|
9ce31d3509 | ||
|
|
f8fae68efb | ||
|
|
93f3a286db | ||
|
|
3799728c76 | ||
|
|
b130271b2b | ||
|
|
ea2cb91a49 | ||
|
|
bfe1963eaa | ||
|
|
a04946e23e | ||
|
|
700294714c | ||
|
|
d93f2ba9f0 | ||
|
|
96ee8ab0a0 | ||
|
|
659b06a7b8 | ||
|
|
653538cd3a | ||
|
|
1ba5816184 | ||
|
|
0a23f51792 | ||
|
|
b9b3eaf670 | ||
|
|
7b29420f1a | ||
|
|
909297015e | ||
|
|
c7a092db32 | ||
|
|
de5fe245cc | ||
|
|
4dc041d77e | ||
|
|
7cfd04e318 | ||
|
|
d0428a8d21 | ||
|
|
3dbf117928 | ||
|
|
342ff964aa | ||
|
|
75138beed9 | ||
|
|
36523e0d97 | ||
|
|
44e705cd31 | ||
|
|
3e2af09e07 | ||
|
|
907172d6f0 | ||
|
|
394bce7c9e | ||
|
|
bc32c84166 | ||
|
|
76120cb0b4 | ||
|
|
385ee32fd4 | ||
|
|
5b689bd6e7 | ||
|
|
ac537983d9 | ||
|
|
5b2edb3998 | ||
|
|
eee4a60b35 | ||
|
|
dedb054fd8 | ||
|
|
079635cba1 | ||
|
|
5db3540e89 | ||
|
|
b502adc910 | ||
|
|
cab37a96c4 | ||
|
|
b603572295 | ||
|
|
8817e2487a | ||
|
|
c6c86591a9 | ||
|
|
5d1bb7d776 | ||
|
|
ea96c345cc | ||
|
|
318ec4dc9f | ||
|
|
ec38b3a263 | ||
|
|
9cec5dd2b7 | ||
|
|
31264e8bea | ||
|
|
e440d504fb | ||
|
|
786cd442cd | ||
|
|
9f675f2e47 | ||
|
|
e5c4aa4098 | ||
|
|
45e40c288f | ||
|
|
519e9dc728 | ||
|
|
67f18e2a63 | ||
|
|
c4f4208b95 | ||
|
|
881fbe2234 | ||
|
|
c7a1a00040 | ||
|
|
6aa2c1d26d | ||
|
|
9e836ac8e6 | ||
|
|
e2186682ac | ||
|
|
152f0ce966 | ||
|
|
084ff40d4f | ||
|
|
b244e34403 | ||
|
|
e33f4b2704 | ||
|
|
6c733477db | ||
|
|
a36c509c91 | ||
|
|
7d4e4cbe26 | ||
|
|
82e3938afe | ||
|
|
06cd4e7608 | ||
|
|
8b569deeae | ||
|
|
ad59508d7c | ||
|
|
562ece8004 | ||
|
|
8e3b890d26 | ||
|
|
6f53a445ee | ||
|
|
858c29e3be | ||
|
|
5a085aed79 | ||
|
|
7d68d5474e | ||
|
|
21e2e6c951 | ||
|
|
7f59c88dbc | ||
|
|
b85da0745a | ||
|
|
0ae59396f5 | ||
|
|
3451d1a81b | ||
|
|
22bb112ead | ||
|
|
af14981d83 | ||
|
|
9f3c111766 | ||
|
|
c2e4f93870 | ||
|
|
8e2d37d450 | ||
|
|
29040f3c8b | ||
|
|
6746a9a45e | ||
|
|
c768923b77 | ||
|
|
0d0099e633 | ||
|
|
bea736aeae | ||
|
|
31190ced31 | ||
|
|
575ee4de2c | ||
|
|
dfa696859a | ||
|
|
32b5b0363f | ||
|
|
c69e40942e | ||
|
|
8cb07685fd | ||
|
|
81a5a871d9 | ||
|
|
3e7b1ac938 | ||
|
|
16afe3ecbf | ||
|
|
2885ddd5f7 | ||
|
|
f9ab643475 | ||
|
|
17bb7e6953 | ||
|
|
b615704d4a | ||
|
|
c47f0030ec | ||
|
|
cb0300fc7b | ||
|
|
7cbfce747a | ||
|
|
dd99c5fde9 | ||
|
|
c4a09d67eb | ||
|
|
bf13c95fb0 | ||
|
|
30d6779baa | ||
|
|
d0889ab9de | ||
|
|
478e54ad47 | ||
|
|
3b36d6c3ba | ||
|
|
b9f4ee2d4e | ||
|
|
1b419bc615 | ||
|
|
961df0a5a5 | ||
|
|
491948dbcb | ||
|
|
7a11300336 | ||
|
|
dba22db54d | ||
|
|
6cbd3bc8c2 | ||
|
|
74762b369e | ||
|
|
5d7f36e9b2 | ||
|
|
b0be9d8b60 | ||
|
|
9d9fefbb28 | ||
|
|
584d1a41c7 | ||
|
|
a938c2f5a5 | ||
|
|
9f83f0fcd7 | ||
|
|
10980ed68c | ||
|
|
612d6b4206 | ||
|
|
d354a1dfab | ||
|
|
d52d3f3784 | ||
|
|
22c443df83 | ||
|
|
8ffa333bc9 | ||
|
|
5cdbe4620a | ||
|
|
8253325365 | ||
|
|
d100f3c0cb | ||
|
|
c1322c7c89 | ||
|
|
d9b5b5d0de | ||
|
|
97bde20b84 | ||
|
|
b1100c66eb | ||
|
|
611f76238d | ||
|
|
7ef0db981f |
60
changelog.md
60
changelog.md
@@ -1,3 +1,63 @@
|
||||
# 0.4.0
|
||||
|
||||
* Third party libraries deduplicated and minified
|
||||
* Add text reminder for multibit wallet change addresses
|
||||
* Seed field can be edited
|
||||
* Add bitcoin regtest parameters
|
||||
* Mnemonic conversion to entropy is hex encoded instead of binary
|
||||
* Entropy type can be manually selected
|
||||
* Add Bitcoin P2WSH and P2WSH-P2SH
|
||||
* Add Czech language
|
||||
|
||||
# 0.3.14
|
||||
|
||||
* Ethereum uses standard BIP44 as per majority of wallets (Issue 378)
|
||||
|
||||
# 0.3.13
|
||||
|
||||
* Add Thought network
|
||||
* Add Energyweb network
|
||||
* Add Elastos network
|
||||
* Add Groestlcoin
|
||||
* Fix for syscoin network
|
||||
* Add BSV, RPD, MONKEY, ARYA
|
||||
* Rename Zencash to Horizen
|
||||
* Update Hush network
|
||||
* Add CasinoCoin
|
||||
* Add CPUchain
|
||||
* Add Wagerr
|
||||
* Add VeChain
|
||||
* Option to not use 'change' field for ethereum networks in bip45
|
||||
* Add segwit parameters for MONKEY, BCA, BTC, MONA, SYS, VIA, DOGEt, LTCt
|
||||
* Convert mnemonic back to raw entropy
|
||||
* Add 2-of-3 phrase cards
|
||||
* Move position of hardened addresses checkbox to address table
|
||||
|
||||
# 0.3.12
|
||||
|
||||
* Fix typos
|
||||
* Fix DigiByte signing message
|
||||
* Add DeepOnion network
|
||||
* Add EOS network
|
||||
* Add LTC testnetwork
|
||||
* Add DOGE testnetwork
|
||||
* Add Stellar network
|
||||
* Add TWINS network
|
||||
* Add FIX network
|
||||
|
||||
# 0.3.11
|
||||
|
||||
* Add NIX network
|
||||
* Fix coin parameters for NMC, XMY, CLAM, ONX, LKR
|
||||
* Add DEXON network
|
||||
* Add Nebulas network
|
||||
* Add LSP network
|
||||
* Fix Crown network address format
|
||||
* Add Ellaism network
|
||||
* Add Etheresocial network
|
||||
* Add Bolivarcoin network
|
||||
* Force spellcheck and autocomplete to be off
|
||||
|
||||
# 0.3.10
|
||||
|
||||
* Add Phore network
|
||||
|
||||
22
libs/base-x/LICENSE.md
Normal file
22
libs/base-x/LICENSE.md
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 base-x contributors
|
||||
Copyright (c) 2014-2018 The Bitcoin Core developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
44
libs/base-x/package.json
Normal file
44
libs/base-x/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "base-x",
|
||||
"version": "3.0.7",
|
||||
"description": "Fast base encoding / decoding of any given alphabet",
|
||||
"keywords": [
|
||||
"base-x",
|
||||
"base58",
|
||||
"base62",
|
||||
"base64",
|
||||
"crypto",
|
||||
"crytography",
|
||||
"decode",
|
||||
"decoding",
|
||||
"encode",
|
||||
"encoding"
|
||||
],
|
||||
"homepage": "https://github.com/cryptocoinjs/base-x",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cryptocoinjs/base-x/issues"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Daniel Cousens",
|
||||
"files": [
|
||||
"src"
|
||||
],
|
||||
"main": "src/index.js",
|
||||
"types": "src/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cryptocoinjs/base-x.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p ./tsconfig.json ; standard --fix; browserify src/index.js --standalone basex > /tmp/base-x.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "12.0.10",
|
||||
"standard": "^10.0.3",
|
||||
"tape": "^4.5.1",
|
||||
"typescript": "3.5.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
}
|
||||
4
libs/base-x/readme.md
Normal file
4
libs/base-x/readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Build (will create a bundle and copy it to /tmp/base-x.js):
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
161
libs/base-x/ts_src/index.ts
Normal file
161
libs/base-x/ts_src/index.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
// base-x encoding / decoding
|
||||
// Copyright (c) 2018 base-x contributors
|
||||
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
// @ts-ignore
|
||||
const _Buffer = require('safe-buffer').Buffer;
|
||||
|
||||
function base (ALPHABET: string): base.BaseConverter {
|
||||
if (ALPHABET.length >= 255) throw new TypeError('Alphabet too long')
|
||||
|
||||
const BASE_MAP = new Uint8Array(256)
|
||||
BASE_MAP.fill(255)
|
||||
|
||||
for (let i = 0; i < ALPHABET.length; i++) {
|
||||
const x = ALPHABET.charAt(i)
|
||||
const xc = x.charCodeAt(0)
|
||||
|
||||
if (BASE_MAP[xc] !== 255) throw new TypeError(x + ' is ambiguous')
|
||||
BASE_MAP[xc] = i
|
||||
}
|
||||
|
||||
const BASE = ALPHABET.length
|
||||
const LEADER = ALPHABET.charAt(0)
|
||||
const FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
|
||||
const iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
|
||||
|
||||
function encode (source: Buffer): string {
|
||||
if (!_Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
|
||||
if (source.length === 0) return ''
|
||||
|
||||
// Skip & count leading zeroes.
|
||||
let zeroes = 0
|
||||
let length = 0
|
||||
let pbegin = 0
|
||||
const pend = source.length
|
||||
|
||||
while (pbegin !== pend && source[pbegin] === 0) {
|
||||
pbegin++
|
||||
zeroes++
|
||||
}
|
||||
|
||||
// Allocate enough space in big-endian base58 representation.
|
||||
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0
|
||||
const b58 = new Uint8Array(size)
|
||||
|
||||
// Process the bytes.
|
||||
while (pbegin !== pend) {
|
||||
let carry = source[pbegin]
|
||||
|
||||
// Apply "b58 = b58 * 256 + ch".
|
||||
let i = 0
|
||||
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
||||
carry += (256 * b58[it1]) >>> 0
|
||||
b58[it1] = (carry % BASE) >>> 0
|
||||
carry = (carry / BASE) >>> 0
|
||||
}
|
||||
|
||||
if (carry !== 0) throw new Error('Non-zero carry')
|
||||
length = i
|
||||
pbegin++
|
||||
}
|
||||
|
||||
// Skip leading zeroes in base58 result.
|
||||
let it2 = size - length
|
||||
while (it2 !== size && b58[it2] === 0) {
|
||||
it2++
|
||||
}
|
||||
|
||||
// Translate the result into a string.
|
||||
let str = LEADER.repeat(zeroes)
|
||||
for (; it2 < size; ++it2) str += ALPHABET.charAt(b58[it2])
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
function decodeUnsafe (source: string): Buffer | undefined {
|
||||
if (typeof source !== 'string') throw new TypeError('Expected String')
|
||||
if (source.length === 0) return _Buffer.alloc(0)
|
||||
|
||||
let psz = 0
|
||||
|
||||
// Skip leading spaces.
|
||||
if (source[psz] === ' ') return
|
||||
|
||||
// Skip and count leading '1's.
|
||||
let zeroes = 0
|
||||
let length = 0
|
||||
while (source[psz] === LEADER) {
|
||||
zeroes++
|
||||
psz++
|
||||
}
|
||||
|
||||
// Allocate enough space in big-endian base256 representation.
|
||||
const size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
|
||||
const b256 = new Uint8Array(size)
|
||||
|
||||
// Process the characters.
|
||||
while (source[psz]) {
|
||||
// Decode character
|
||||
let carry = BASE_MAP[source.charCodeAt(psz)]
|
||||
|
||||
// Invalid character
|
||||
if (carry === 255) return
|
||||
|
||||
let i = 0
|
||||
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
||||
carry += (BASE * b256[it3]) >>> 0
|
||||
b256[it3] = (carry % 256) >>> 0
|
||||
carry = (carry / 256) >>> 0
|
||||
}
|
||||
|
||||
if (carry !== 0) throw new Error('Non-zero carry')
|
||||
length = i
|
||||
psz++
|
||||
}
|
||||
|
||||
// Skip trailing spaces.
|
||||
if (source[psz] === ' ') return
|
||||
|
||||
// Skip leading zeroes in b256.
|
||||
let it4 = size - length
|
||||
while (it4 !== size && b256[it4] === 0) {
|
||||
it4++
|
||||
}
|
||||
|
||||
const vch = _Buffer.allocUnsafe(zeroes + (size - it4))
|
||||
vch.fill(0x00, 0, zeroes)
|
||||
|
||||
let j = zeroes
|
||||
while (it4 !== size) {
|
||||
vch[j++] = b256[it4++]
|
||||
}
|
||||
|
||||
return vch
|
||||
}
|
||||
|
||||
function decode (string: string): Buffer {
|
||||
const buffer = decodeUnsafe(string)
|
||||
if (buffer) return buffer
|
||||
|
||||
throw new Error('Non-base' + BASE + ' character')
|
||||
}
|
||||
|
||||
return {
|
||||
encode: encode,
|
||||
decodeUnsafe: decodeUnsafe,
|
||||
decode: decode
|
||||
}
|
||||
}
|
||||
|
||||
export = base;
|
||||
|
||||
declare namespace base {
|
||||
interface BaseConverter {
|
||||
encode(buffer: Buffer): string;
|
||||
decodeUnsafe(string: string): Buffer | undefined;
|
||||
decode(string: string): Buffer;
|
||||
}
|
||||
}
|
||||
31
libs/base-x/tsconfig.json
Normal file
31
libs/base-x/tsconfig.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES5",
|
||||
"module": "commonjs",
|
||||
"outDir": "./src",
|
||||
"declaration": true,
|
||||
"rootDir": "./ts_src",
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
"allowJs": false,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictBindCallApply": true,
|
||||
"strictPropertyInitialization": true,
|
||||
"noImplicitThis": true,
|
||||
"alwaysStrict": true,
|
||||
"esModuleInterop": false,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true
|
||||
},
|
||||
"include": [
|
||||
"ts_src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.spec.ts",
|
||||
"node_modules/**/*"
|
||||
]
|
||||
}
|
||||
244
libs/bitcoinjs-bip38/index.js
Normal file
244
libs/bitcoinjs-bip38/index.js
Normal file
@@ -0,0 +1,244 @@
|
||||
var aes = require('browserify-aes')
|
||||
var assert = require('assert')
|
||||
var Buffer = require('safe-buffer').Buffer
|
||||
var bs58check = require('bs58check')
|
||||
var createHash = require('create-hash')
|
||||
var scrypt = require('scryptsy')
|
||||
var xor = require('buffer-xor/inplace')
|
||||
|
||||
var ecurve = require('ecurve')
|
||||
var curve = ecurve.getCurveByName('secp256k1')
|
||||
|
||||
var BigInteger = require('bigi')
|
||||
|
||||
// constants
|
||||
var SCRYPT_PARAMS = {
|
||||
N: 16384, // specified by BIP38
|
||||
r: 8,
|
||||
p: 8
|
||||
}
|
||||
var NULL = Buffer.alloc(0)
|
||||
|
||||
function hash160 (buffer) {
|
||||
var hash
|
||||
try {
|
||||
hash = createHash('rmd160')
|
||||
} catch (e) {
|
||||
hash = createHash('ripemd160')
|
||||
}
|
||||
return hash.update(
|
||||
createHash('sha256').update(buffer).digest()
|
||||
).digest()
|
||||
}
|
||||
|
||||
function hash256 (buffer) {
|
||||
return createHash('sha256').update(
|
||||
createHash('sha256').update(buffer).digest()
|
||||
).digest()
|
||||
}
|
||||
|
||||
function getAddress (d, compressed) {
|
||||
var Q = curve.G.multiply(d).getEncoded(compressed)
|
||||
var hash = hash160(Q)
|
||||
var payload = Buffer.allocUnsafe(21)
|
||||
payload.writeUInt8(0x00, 0) // XXX TODO FIXME bitcoin only??? damn you BIP38
|
||||
hash.copy(payload, 1)
|
||||
|
||||
return bs58check.encode(payload)
|
||||
}
|
||||
|
||||
function encryptRaw (buffer, compressed, passphrase, progressCallback, scryptParams) {
|
||||
if (buffer.length !== 32) throw new Error('Invalid private key length')
|
||||
scryptParams = scryptParams || SCRYPT_PARAMS
|
||||
|
||||
var d = BigInteger.fromBuffer(buffer)
|
||||
var address = getAddress(d, compressed)
|
||||
var secret = Buffer.from(passphrase, 'utf8')
|
||||
var salt = hash256(address).slice(0, 4)
|
||||
|
||||
var N = scryptParams.N
|
||||
var r = scryptParams.r
|
||||
var p = scryptParams.p
|
||||
|
||||
var scryptBuf = scrypt(secret, salt, N, r, p, 64, progressCallback)
|
||||
var derivedHalf1 = scryptBuf.slice(0, 32)
|
||||
var derivedHalf2 = scryptBuf.slice(32, 64)
|
||||
|
||||
var xorBuf = xor(derivedHalf1, buffer)
|
||||
var cipher = aes.createCipheriv('aes-256-ecb', derivedHalf2, NULL)
|
||||
cipher.setAutoPadding(false)
|
||||
cipher.end(xorBuf)
|
||||
|
||||
var cipherText = cipher.read()
|
||||
|
||||
// 0x01 | 0x42 | flagByte | salt (4) | cipherText (32)
|
||||
var result = Buffer.allocUnsafe(7 + 32)
|
||||
result.writeUInt8(0x01, 0)
|
||||
result.writeUInt8(0x42, 1)
|
||||
result.writeUInt8(compressed ? 0xe0 : 0xc0, 2)
|
||||
salt.copy(result, 3)
|
||||
cipherText.copy(result, 7)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function encrypt (buffer, compressed, passphrase, progressCallback, scryptParams) {
|
||||
return bs58check.encode(encryptRaw(buffer, compressed, passphrase, progressCallback, scryptParams))
|
||||
}
|
||||
|
||||
// some of the techniques borrowed from: https://github.com/pointbiz/bitaddress.org
|
||||
function decryptRaw (buffer, passphrase, progressCallback, scryptParams) {
|
||||
// 39 bytes: 2 bytes prefix, 37 bytes payload
|
||||
if (buffer.length !== 39) throw new Error('Invalid BIP38 data length')
|
||||
if (buffer.readUInt8(0) !== 0x01) throw new Error('Invalid BIP38 prefix')
|
||||
scryptParams = scryptParams || SCRYPT_PARAMS
|
||||
|
||||
// check if BIP38 EC multiply
|
||||
var type = buffer.readUInt8(1)
|
||||
if (type === 0x43) return decryptECMult(buffer, passphrase, progressCallback, scryptParams)
|
||||
if (type !== 0x42) throw new Error('Invalid BIP38 type')
|
||||
|
||||
passphrase = Buffer.from(passphrase, 'utf8')
|
||||
|
||||
var flagByte = buffer.readUInt8(2)
|
||||
var compressed = flagByte === 0xe0
|
||||
if (!compressed && flagByte !== 0xc0) throw new Error('Invalid BIP38 compression flag')
|
||||
|
||||
var N = scryptParams.N
|
||||
var r = scryptParams.r
|
||||
var p = scryptParams.p
|
||||
|
||||
var salt = buffer.slice(3, 7)
|
||||
var scryptBuf = scrypt(passphrase, salt, N, r, p, 64, progressCallback)
|
||||
var derivedHalf1 = scryptBuf.slice(0, 32)
|
||||
var derivedHalf2 = scryptBuf.slice(32, 64)
|
||||
|
||||
var privKeyBuf = buffer.slice(7, 7 + 32)
|
||||
var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, NULL)
|
||||
decipher.setAutoPadding(false)
|
||||
decipher.end(privKeyBuf)
|
||||
|
||||
var plainText = decipher.read()
|
||||
var privateKey = xor(derivedHalf1, plainText)
|
||||
|
||||
// verify salt matches address
|
||||
var d = BigInteger.fromBuffer(privateKey)
|
||||
var address = getAddress(d, compressed)
|
||||
var checksum = hash256(address).slice(0, 4)
|
||||
assert.deepStrictEqual(salt, checksum)
|
||||
|
||||
return {
|
||||
privateKey: privateKey,
|
||||
compressed: compressed
|
||||
}
|
||||
}
|
||||
|
||||
function decrypt (string, passphrase, progressCallback, scryptParams) {
|
||||
return decryptRaw(bs58check.decode(string), passphrase, progressCallback, scryptParams)
|
||||
}
|
||||
|
||||
function decryptECMult (buffer, passphrase, progressCallback, scryptParams) {
|
||||
passphrase = Buffer.from(passphrase, 'utf8')
|
||||
buffer = buffer.slice(1) // FIXME: we can avoid this
|
||||
scryptParams = scryptParams || SCRYPT_PARAMS
|
||||
|
||||
var flag = buffer.readUInt8(1)
|
||||
var compressed = (flag & 0x20) !== 0
|
||||
var hasLotSeq = (flag & 0x04) !== 0
|
||||
|
||||
assert.strictEqual((flag & 0x24), flag, 'Invalid private key.')
|
||||
|
||||
var addressHash = buffer.slice(2, 6)
|
||||
var ownerEntropy = buffer.slice(6, 14)
|
||||
var ownerSalt
|
||||
|
||||
// 4 bytes ownerSalt if 4 bytes lot/sequence
|
||||
if (hasLotSeq) {
|
||||
ownerSalt = ownerEntropy.slice(0, 4)
|
||||
|
||||
// else, 8 bytes ownerSalt
|
||||
} else {
|
||||
ownerSalt = ownerEntropy
|
||||
}
|
||||
|
||||
var encryptedPart1 = buffer.slice(14, 22) // First 8 bytes
|
||||
var encryptedPart2 = buffer.slice(22, 38) // 16 bytes
|
||||
|
||||
var N = scryptParams.N
|
||||
var r = scryptParams.r
|
||||
var p = scryptParams.p
|
||||
var preFactor = scrypt(passphrase, ownerSalt, N, r, p, 32, progressCallback)
|
||||
|
||||
var passFactor
|
||||
if (hasLotSeq) {
|
||||
var hashTarget = Buffer.concat([preFactor, ownerEntropy])
|
||||
passFactor = hash256(hashTarget)
|
||||
} else {
|
||||
passFactor = preFactor
|
||||
}
|
||||
|
||||
var passInt = BigInteger.fromBuffer(passFactor)
|
||||
var passPoint = curve.G.multiply(passInt).getEncoded(true)
|
||||
|
||||
var seedBPass = scrypt(passPoint, Buffer.concat([addressHash, ownerEntropy]), 1024, 1, 1, 64)
|
||||
var derivedHalf1 = seedBPass.slice(0, 32)
|
||||
var derivedHalf2 = seedBPass.slice(32, 64)
|
||||
|
||||
var decipher = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0))
|
||||
decipher.setAutoPadding(false)
|
||||
decipher.end(encryptedPart2)
|
||||
|
||||
var decryptedPart2 = decipher.read()
|
||||
var tmp = xor(decryptedPart2, derivedHalf1.slice(16, 32))
|
||||
var seedBPart2 = tmp.slice(8, 16)
|
||||
|
||||
var decipher2 = aes.createDecipheriv('aes-256-ecb', derivedHalf2, Buffer.alloc(0))
|
||||
decipher2.setAutoPadding(false)
|
||||
decipher2.write(encryptedPart1) // first 8 bytes
|
||||
decipher2.end(tmp.slice(0, 8)) // last 8 bytes
|
||||
|
||||
var seedBPart1 = xor(decipher2.read(), derivedHalf1.slice(0, 16))
|
||||
var seedB = Buffer.concat([seedBPart1, seedBPart2], 24)
|
||||
var factorB = BigInteger.fromBuffer(hash256(seedB))
|
||||
|
||||
// d = passFactor * factorB (mod n)
|
||||
var d = passInt.multiply(factorB).mod(curve.n)
|
||||
|
||||
return {
|
||||
privateKey: d.toBuffer(32),
|
||||
compressed: compressed
|
||||
}
|
||||
}
|
||||
|
||||
function verify (string) {
|
||||
var decoded = bs58check.decodeUnsafe(string)
|
||||
if (!decoded) return false
|
||||
|
||||
if (decoded.length !== 39) return false
|
||||
if (decoded.readUInt8(0) !== 0x01) return false
|
||||
|
||||
var type = decoded.readUInt8(1)
|
||||
var flag = decoded.readUInt8(2)
|
||||
|
||||
// encrypted WIF
|
||||
if (type === 0x42) {
|
||||
if (flag !== 0xc0 && flag !== 0xe0) return false
|
||||
|
||||
// EC mult
|
||||
} else if (type === 0x43) {
|
||||
if ((flag & ~0x24)) return false
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
decrypt: decrypt,
|
||||
decryptECMult: decryptECMult,
|
||||
decryptRaw: decryptRaw,
|
||||
encrypt: encrypt,
|
||||
encryptRaw: encryptRaw,
|
||||
verify: verify
|
||||
}
|
||||
38
libs/bitcoinjs-bip38/package.json
Normal file
38
libs/bitcoinjs-bip38/package.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "bip38",
|
||||
"version": "2.0.2",
|
||||
"description": "BIP38 is a standard process to encrypt Bitcoin and crypto currency private keys that is impervious to brute force attacks thus protecting the user.",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"crypto",
|
||||
"cryptography",
|
||||
"litecoin"
|
||||
],
|
||||
"homepage": "http://cryptocoinjs.com/modules/currency/bip38/",
|
||||
"author": "JP Richardson",
|
||||
"dependencies": {
|
||||
"bigi": "^1.2.0",
|
||||
"browserify-aes": "^1.0.1",
|
||||
"bs58check": "<3.0.0",
|
||||
"buffer-xor": "^1.0.2",
|
||||
"create-hash": "^1.1.1",
|
||||
"ecurve": "^1.0.0",
|
||||
"scryptsy": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
},
|
||||
"repository": {
|
||||
"url": "git@github.com:bitcoinjs/bip38.git",
|
||||
"type": "git"
|
||||
},
|
||||
"scripts": {
|
||||
"browser-test": "mochify --wd -R spec --timeout 100000",
|
||||
"build": "browserify index.js --standalone bitcoinjs-bip38 > /tmp/bitcoinjs-bip38.js",
|
||||
"coverage": "istanbul cover _mocha -- --reporter list test/*.js",
|
||||
"coveralls": "npm run-script coverage && coveralls < coverage/lcov.info",
|
||||
"standard": "standard",
|
||||
"test": "npm run standard && npm run unit",
|
||||
"unit": "mocha --ui bdd --timeout 240000"
|
||||
}
|
||||
}
|
||||
4
libs/bitcoinjs-bip38/readme.md
Normal file
4
libs/bitcoinjs-bip38/readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Build (will create a bundle and copy it to /tmp/bitcoinjs-bip38.js):
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
5
libs/bitcoinjs-lib/bitcoinjs-lib.js
Normal file
5
libs/bitcoinjs-lib/bitcoinjs-lib.js
Normal file
@@ -0,0 +1,5 @@
|
||||
let bitcoin = require('bitcoinjs-lib')
|
||||
|
||||
module.exports = {
|
||||
bitcoin
|
||||
}
|
||||
14
libs/bitcoinjs-lib/package.json
Normal file
14
libs/bitcoinjs-lib/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "bitcoinjs-lib",
|
||||
"version": "3.3.2",
|
||||
"scripts": {
|
||||
"build": "browserify bitcoinjs-lib.js --standalone bitcoinjs > /tmp/bitcoinjs-lib.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bitcoinjs-lib": "3.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
"uglify-es": "^3.3.9"
|
||||
}
|
||||
}
|
||||
5
libs/bitcoinjs-lib/readme.md
Normal file
5
libs/bitcoinjs-lib/readme.md
Normal file
@@ -0,0 +1,5 @@
|
||||
Build (will create a bundle and copy it to /tmp/bitcoinjs-lib.js):
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
manually add changes in https://github.com/iancoleman/bip39/commit/0702ecd3520c44cb8016f80329dcb5a3c8df88fc
|
||||
105
libs/combined/index.js
Normal file
105
libs/combined/index.js
Normal file
@@ -0,0 +1,105 @@
|
||||
/* base-x */
|
||||
|
||||
let basex = require('base-x')
|
||||
|
||||
/* bchaddrjs */
|
||||
|
||||
let bchaddr = require('bchaddrjs')
|
||||
|
||||
/* bchaddrjs slp */
|
||||
|
||||
let bchaddrSlp = require('bchaddrjs-slp')
|
||||
|
||||
/* biginteger */
|
||||
|
||||
let BigInteger = require('javascript-biginteger')
|
||||
|
||||
/* bitcoinjs-bip38 */
|
||||
|
||||
let bip38 = require('bip38')
|
||||
|
||||
/* bitcoinjs-lib */
|
||||
|
||||
let bitcoin = require('bitcoinjs-lib')
|
||||
|
||||
/* buffer */
|
||||
|
||||
let buffer = require('buffer');
|
||||
|
||||
/* elastos */
|
||||
// See https://github.com/iancoleman/bip39/pull/368
|
||||
// and https://github.com/johnnynanjiang/Elastos.SDK.Keypair.Javascript/tree/iancoleman-bip39
|
||||
|
||||
let elastosjs = require('elastos-wallet-js')
|
||||
|
||||
/* ethereum-util */
|
||||
|
||||
let ethUtil = require('ethereumjs-util')
|
||||
|
||||
/* fast-levenshtein */
|
||||
|
||||
let levenshtein = require('fast-levenshtein')
|
||||
|
||||
/* groestlcoin */
|
||||
|
||||
let groestlcoinjs = require('groestlcoinjs-lib')
|
||||
|
||||
/* groestlcoin bip38 */
|
||||
|
||||
let groestlcoinjsBip38 = require('bip38grs')
|
||||
|
||||
/* kjua qr codes */
|
||||
|
||||
let kjua = require('kjua')
|
||||
|
||||
/* nebulas */
|
||||
|
||||
let nebulas = require('nebulas')
|
||||
|
||||
/* stellar-util */
|
||||
|
||||
let StellarBase = require('stellar-base');
|
||||
let edHd = require('ed25519-hd-key');
|
||||
let stellarUtil = {
|
||||
getKeypair: function (path, seed) {
|
||||
const result = edHd.derivePath(path, seed);
|
||||
return StellarBase.Keypair.fromRawEd25519Seed(result.key);
|
||||
},
|
||||
dummyNetwork: {
|
||||
bip32: {public: 0, private: 0},
|
||||
messagePrefix: '',
|
||||
pubKeyHash: 0,
|
||||
scriptHash: 0,
|
||||
wif: 0,
|
||||
},
|
||||
}
|
||||
|
||||
/* unorm */
|
||||
|
||||
let unorm = require('unorm')
|
||||
|
||||
/* zxcvbn */
|
||||
|
||||
let zxcvbn = require('zxcvbn')
|
||||
|
||||
/* exports */
|
||||
|
||||
module.exports = {
|
||||
basex,
|
||||
bchaddr,
|
||||
bchaddrSlp,
|
||||
buffer,
|
||||
BigInteger,
|
||||
bip38,
|
||||
bitcoin,
|
||||
elastosjs,
|
||||
ethUtil,
|
||||
groestlcoinjs,
|
||||
groestlcoinjsBip38,
|
||||
kjua,
|
||||
levenshtein,
|
||||
nebulas,
|
||||
stellarUtil,
|
||||
unorm,
|
||||
zxcvbn
|
||||
}
|
||||
17
libs/combined/npm-shrinkwrap.json
generated
Normal file
17
libs/combined/npm-shrinkwrap.json
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"elastos-wallet-js": {
|
||||
"version": "git://github.com/johnnynanjiang/Elastos.SDK.Keypair.Javascript.git#491dc51b64efaf0a8aae62028b68e2c8e38fde06",
|
||||
"dependencies": {
|
||||
"bitcore-lib-p256": {
|
||||
"version": "0.16.0",
|
||||
"dependencies": {
|
||||
"lodash": {
|
||||
"version": "4.17.12"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2241
libs/combined/package-lock.json
generated
Normal file
2241
libs/combined/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
libs/combined/package.json
Normal file
31
libs/combined/package.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "bip39-tool-external-libs",
|
||||
"version": "0.4.0",
|
||||
"scripts": {
|
||||
"build": "browserify index.js --standalone libs | uglifyjs -c > ../../src/js/bip39-libs.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"base-x": "3.0.7",
|
||||
"bchaddrjs": "0.4.4",
|
||||
"bchaddrjs-slp": "git://github.com/simpleledger/bchaddrjs.git#af16e44a6bfbe4b3980a62dba50e2f68ed864c6b",
|
||||
"bip38": "2.0.2",
|
||||
"bip38grs": "git://github.com/Groestlcoin/bip38grs.git#091975b01679b74dc0a4136bb743fe17791b0151",
|
||||
"bitcoinjs-lib": "git://github.com/iancoleman/bitcoinjs-lib.git#v3.3.2_16bit",
|
||||
"buffer": "5.4.3",
|
||||
"ed25519-hd-key": "^1.0.0",
|
||||
"elastos-wallet-js": "git://github.com/johnnynanjiang/Elastos.SDK.Keypair.Javascript.git#491dc51b64efaf0a8aae62028b68e2c8e38fde06",
|
||||
"ethereumjs-util": "6.0.0",
|
||||
"fast-levenshtein": "2.0.6",
|
||||
"groestlcoinjs-lib": "git://github.com/Groestlcoin/groestlcoinjs-lib.git#3.3.2",
|
||||
"javascript-biginteger": "0.9.2",
|
||||
"kjua": "0.6.0",
|
||||
"nebulas": "0.5.6",
|
||||
"stellar-base": "^0.10.0",
|
||||
"unorm": "1.6.0",
|
||||
"zxcvbn": "4.4.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
"uglify-es": "^3.3.9"
|
||||
}
|
||||
}
|
||||
6
libs/combined/readme.md
Normal file
6
libs/combined/readme.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Generate libs
|
||||
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
736
libs/ethereumjs-util/index.js
Normal file
736
libs/ethereumjs-util/index.js
Normal file
@@ -0,0 +1,736 @@
|
||||
const createKeccakHash = require('keccak')
|
||||
const secp256k1 = require('secp256k1')
|
||||
const assert = require('assert')
|
||||
const rlp = require('rlp')
|
||||
const BN = require('bn.js')
|
||||
const createHash = require('create-hash')
|
||||
const Buffer = require('safe-buffer').Buffer
|
||||
Object.assign(exports, require('ethjs-util'))
|
||||
|
||||
/**
|
||||
* the max integer that this VM can handle (a ```BN```)
|
||||
* @var {BN} MAX_INTEGER
|
||||
*/
|
||||
exports.MAX_INTEGER = new BN('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)
|
||||
|
||||
/**
|
||||
* 2^256 (a ```BN```)
|
||||
* @var {BN} TWO_POW256
|
||||
*/
|
||||
exports.TWO_POW256 = new BN('10000000000000000000000000000000000000000000000000000000000000000', 16)
|
||||
|
||||
/**
|
||||
* Keccak-256 hash of null (a ```String```)
|
||||
* @var {String} KECCAK256_NULL_S
|
||||
*/
|
||||
exports.KECCAK256_NULL_S = 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
|
||||
|
||||
/**
|
||||
* Keccak-256 hash of null (a ```Buffer```)
|
||||
* @var {Buffer} KECCAK256_NULL
|
||||
*/
|
||||
exports.KECCAK256_NULL = Buffer.from(exports.KECCAK256_NULL_S, 'hex')
|
||||
|
||||
/**
|
||||
* Keccak-256 of an RLP of an empty array (a ```String```)
|
||||
* @var {String} KECCAK256_RLP_ARRAY_S
|
||||
*/
|
||||
exports.KECCAK256_RLP_ARRAY_S = '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347'
|
||||
|
||||
/**
|
||||
* Keccak-256 of an RLP of an empty array (a ```Buffer```)
|
||||
* @var {Buffer} KECCAK256_RLP_ARRAY
|
||||
*/
|
||||
exports.KECCAK256_RLP_ARRAY = Buffer.from(exports.KECCAK256_RLP_ARRAY_S, 'hex')
|
||||
|
||||
/**
|
||||
* Keccak-256 hash of the RLP of null (a ```String```)
|
||||
* @var {String} KECCAK256_RLP_S
|
||||
*/
|
||||
exports.KECCAK256_RLP_S = '56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421'
|
||||
|
||||
/**
|
||||
* Keccak-256 hash of the RLP of null (a ```Buffer```)
|
||||
* @var {Buffer} KECCAK256_RLP
|
||||
*/
|
||||
exports.KECCAK256_RLP = Buffer.from(exports.KECCAK256_RLP_S, 'hex')
|
||||
|
||||
/**
|
||||
* [`BN`](https://github.com/indutny/bn.js)
|
||||
* @var {Function}
|
||||
*/
|
||||
exports.BN = BN
|
||||
|
||||
/**
|
||||
* [`rlp`](https://github.com/ethereumjs/rlp)
|
||||
* @var {Function}
|
||||
*/
|
||||
exports.rlp = rlp
|
||||
|
||||
/**
|
||||
* [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/)
|
||||
* @var {Object}
|
||||
*/
|
||||
exports.secp256k1 = secp256k1
|
||||
|
||||
/**
|
||||
* Returns a buffer filled with 0s
|
||||
* @method zeros
|
||||
* @param {Number} bytes the number of bytes the buffer should be
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.zeros = function (bytes) {
|
||||
return Buffer.allocUnsafe(bytes).fill(0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a zero address
|
||||
* @method zeroAddress
|
||||
* @return {String}
|
||||
*/
|
||||
exports.zeroAddress = function () {
|
||||
const addressLength = 20
|
||||
const zeroAddress = exports.zeros(addressLength)
|
||||
return exports.bufferToHex(zeroAddress)
|
||||
}
|
||||
|
||||
/**
|
||||
* Left Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
|
||||
* Or it truncates the beginning if it exceeds.
|
||||
* @method lsetLength
|
||||
* @param {Buffer|Array} msg the value to pad
|
||||
* @param {Number} length the number of bytes the output should be
|
||||
* @param {Boolean} [right=false] whether to start padding form the left or right
|
||||
* @return {Buffer|Array}
|
||||
*/
|
||||
exports.setLengthLeft = exports.setLength = function (msg, length, right) {
|
||||
const buf = exports.zeros(length)
|
||||
msg = exports.toBuffer(msg)
|
||||
if (right) {
|
||||
if (msg.length < length) {
|
||||
msg.copy(buf)
|
||||
return buf
|
||||
}
|
||||
return msg.slice(0, length)
|
||||
} else {
|
||||
if (msg.length < length) {
|
||||
msg.copy(buf, length - msg.length)
|
||||
return buf
|
||||
}
|
||||
return msg.slice(-length)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Right Pads an `Array` or `Buffer` with leading zeros till it has `length` bytes.
|
||||
* Or it truncates the beginning if it exceeds.
|
||||
* @param {Buffer|Array} msg the value to pad
|
||||
* @param {Number} length the number of bytes the output should be
|
||||
* @return {Buffer|Array}
|
||||
*/
|
||||
exports.setLengthRight = function (msg, length) {
|
||||
return exports.setLength(msg, length, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Trims leading zeros from a `Buffer` or an `Array`
|
||||
* @param {Buffer|Array|String} a
|
||||
* @return {Buffer|Array|String}
|
||||
*/
|
||||
exports.unpad = exports.stripZeros = function (a) {
|
||||
a = exports.stripHexPrefix(a)
|
||||
let first = a[0]
|
||||
while (a.length > 0 && first.toString() === '0') {
|
||||
a = a.slice(1)
|
||||
first = a[0]
|
||||
}
|
||||
return a
|
||||
}
|
||||
/**
|
||||
* Attempts to turn a value into a `Buffer`. As input it supports `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` method.
|
||||
* @param {*} v the value
|
||||
*/
|
||||
exports.toBuffer = function (v) {
|
||||
if (!Buffer.isBuffer(v)) {
|
||||
if (Array.isArray(v)) {
|
||||
v = Buffer.from(v)
|
||||
} else if (typeof v === 'string') {
|
||||
if (exports.isHexString(v)) {
|
||||
v = Buffer.from(exports.padToEven(exports.stripHexPrefix(v)), 'hex')
|
||||
} else {
|
||||
v = Buffer.from(v)
|
||||
}
|
||||
} else if (typeof v === 'number') {
|
||||
v = exports.intToBuffer(v)
|
||||
} else if (v === null || v === undefined) {
|
||||
v = Buffer.allocUnsafe(0)
|
||||
} else if (BN.isBN(v)) {
|
||||
v = v.toArrayLike(Buffer)
|
||||
} else if (v.toArray) {
|
||||
// converts a BN to a Buffer
|
||||
v = Buffer.from(v.toArray())
|
||||
} else {
|
||||
throw new Error('invalid type')
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a `Buffer` to a `Number`
|
||||
* @param {Buffer} buf
|
||||
* @return {Number}
|
||||
* @throws If the input number exceeds 53 bits.
|
||||
*/
|
||||
exports.bufferToInt = function (buf) {
|
||||
return new BN(exports.toBuffer(buf)).toNumber()
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a `Buffer` into a hex `String`
|
||||
* @param {Buffer} buf
|
||||
* @return {String}
|
||||
*/
|
||||
exports.bufferToHex = function (buf) {
|
||||
buf = exports.toBuffer(buf)
|
||||
return '0x' + buf.toString('hex')
|
||||
}
|
||||
|
||||
/**
|
||||
* Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
|
||||
* @param {Buffer} num
|
||||
* @return {BN}
|
||||
*/
|
||||
exports.fromSigned = function (num) {
|
||||
return new BN(num).fromTwos(256)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
|
||||
* @param {BN} num
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.toUnsigned = function (num) {
|
||||
return Buffer.from(num.toTwos(256).toArray())
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Keccak hash of the input
|
||||
* @param {Buffer|Array|String|Number} a the input data
|
||||
* @param {Number} [bits=256] the Keccak width
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.keccak = function (a, bits) {
|
||||
a = exports.toBuffer(a)
|
||||
if (!bits) bits = 256
|
||||
|
||||
return createKeccakHash('keccak' + bits).update(a).digest()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Keccak-256 hash of the input, alias for keccak(a, 256)
|
||||
* @param {Buffer|Array|String|Number} a the input data
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.keccak256 = function (a) {
|
||||
return exports.keccak(a)
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates SHA256 hash of the input
|
||||
* @param {Buffer|Array|String|Number} a the input data
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.sha256 = function (a) {
|
||||
a = exports.toBuffer(a)
|
||||
return createHash('sha256').update(a).digest()
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates RIPEMD160 hash of the input
|
||||
* @param {Buffer|Array|String|Number} a the input data
|
||||
* @param {Boolean} padded whether it should be padded to 256 bits or not
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.ripemd160 = function (a, padded) {
|
||||
a = exports.toBuffer(a)
|
||||
const hash = createHash('rmd160').update(a).digest()
|
||||
if (padded === true) {
|
||||
return exports.setLength(hash, 32)
|
||||
} else {
|
||||
return hash
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates SHA-3 hash of the RLP encoded version of the input
|
||||
* @param {Buffer|Array|String|Number} a the input data
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.rlphash = function (a) {
|
||||
return exports.keccak(rlp.encode(a))
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the private key satisfies the rules of the curve secp256k1.
|
||||
* @param {Buffer} privateKey
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.isValidPrivate = function (privateKey) {
|
||||
return secp256k1.privateKeyVerify(privateKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the public key satisfies the rules of the curve secp256k1
|
||||
* and the requirements of Ethereum.
|
||||
* @param {Buffer} publicKey The two points of an uncompressed key, unless sanitize is enabled
|
||||
* @param {Boolean} [sanitize=false] Accept public keys in other formats
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.isValidPublic = function (publicKey, sanitize) {
|
||||
if (publicKey.length === 64) {
|
||||
// Convert to SEC1 for secp256k1
|
||||
return secp256k1.publicKeyVerify(Buffer.concat([ Buffer.from([4]), publicKey ]))
|
||||
}
|
||||
|
||||
if (!sanitize) {
|
||||
return false
|
||||
}
|
||||
|
||||
return secp256k1.publicKeyVerify(publicKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ethereum address of a given public key.
|
||||
* Accepts "Ethereum public keys" and SEC1 encoded keys.
|
||||
* @param {Buffer} pubKey The two points of an uncompressed key, unless sanitize is enabled
|
||||
* @param {Boolean} [sanitize=false] Accept public keys in other formats
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.pubToAddress = exports.publicToAddress = function (pubKey, sanitize) {
|
||||
pubKey = exports.toBuffer(pubKey)
|
||||
if (sanitize && (pubKey.length !== 64)) {
|
||||
pubKey = secp256k1.publicKeyConvert(pubKey, false).slice(1)
|
||||
}
|
||||
assert(pubKey.length === 64)
|
||||
// Only take the lower 160bits of the hash
|
||||
return exports.keccak(pubKey).slice(-20)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ethereum public key of a given private key
|
||||
* @param {Buffer} privateKey A private key must be 256 bits wide
|
||||
* @return {Buffer}
|
||||
*/
|
||||
const privateToPublic = exports.privateToPublic = function (privateKey) {
|
||||
privateKey = exports.toBuffer(privateKey)
|
||||
// skip the type flag and use the X, Y points
|
||||
return secp256k1.publicKeyCreate(privateKey, false).slice(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a public key to the Ethereum format.
|
||||
* @param {Buffer} publicKey
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.importPublic = function (publicKey) {
|
||||
publicKey = exports.toBuffer(publicKey)
|
||||
if (publicKey.length !== 64) {
|
||||
publicKey = secp256k1.publicKeyConvert(publicKey, false).slice(1)
|
||||
}
|
||||
return publicKey
|
||||
}
|
||||
|
||||
/**
|
||||
* ECDSA sign
|
||||
* @param {Buffer} msgHash
|
||||
* @param {Buffer} privateKey
|
||||
* @param {Number} [chainId]
|
||||
* @return {Object}
|
||||
*/
|
||||
exports.ecsign = function (msgHash, privateKey, chainId) {
|
||||
const sig = secp256k1.sign(msgHash, privateKey)
|
||||
|
||||
const ret = {}
|
||||
ret.r = sig.signature.slice(0, 32)
|
||||
ret.s = sig.signature.slice(32, 64)
|
||||
ret.v = chainId ? sig.recovery + (chainId * 2 + 35) : sig.recovery + 27
|
||||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
|
||||
* The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
|
||||
* call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
|
||||
* used to produce the signature.
|
||||
* @param message
|
||||
* @returns {Buffer} hash
|
||||
*/
|
||||
exports.hashPersonalMessage = function (message) {
|
||||
const prefix = exports.toBuffer('\u0019Ethereum Signed Message:\n' + message.length.toString())
|
||||
return exports.keccak(Buffer.concat([prefix, message]))
|
||||
}
|
||||
|
||||
/**
|
||||
* ECDSA public key recovery from signature
|
||||
* @param {Buffer} msgHash
|
||||
* @param {Number} v
|
||||
* @param {Buffer} r
|
||||
* @param {Buffer} s
|
||||
* @param {Number} [chainId]
|
||||
* @return {Buffer} publicKey
|
||||
*/
|
||||
exports.ecrecover = function (msgHash, v, r, s, chainId) {
|
||||
const signature = Buffer.concat([exports.setLength(r, 32), exports.setLength(s, 32)], 64)
|
||||
const recovery = calculateSigRecovery(v, chainId)
|
||||
if (!isValidSigRecovery(recovery)) {
|
||||
throw new Error('Invalid signature v value')
|
||||
}
|
||||
const senderPubKey = secp256k1.recover(msgHash, signature, recovery)
|
||||
return secp256k1.publicKeyConvert(senderPubKey, false).slice(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert signature parameters into the format of `eth_sign` RPC method
|
||||
* @param {Number} v
|
||||
* @param {Buffer} r
|
||||
* @param {Buffer} s
|
||||
* @param {Number} [chainId]
|
||||
* @return {String} sig
|
||||
*/
|
||||
exports.toRpcSig = function (v, r, s, chainId) {
|
||||
let recovery = calculateSigRecovery(v, chainId)
|
||||
if (!isValidSigRecovery(recovery)) {
|
||||
throw new Error('Invalid signature v value')
|
||||
}
|
||||
|
||||
// geth (and the RPC eth_sign method) uses the 65 byte format used by Bitcoin
|
||||
return exports.bufferToHex(Buffer.concat([
|
||||
exports.setLengthLeft(r, 32),
|
||||
exports.setLengthLeft(s, 32),
|
||||
exports.toBuffer(v)
|
||||
]))
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert signature format of the `eth_sign` RPC method to signature parameters
|
||||
* NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
|
||||
* @param {String} sig
|
||||
* @return {Object}
|
||||
*/
|
||||
exports.fromRpcSig = function (sig) {
|
||||
sig = exports.toBuffer(sig)
|
||||
|
||||
// NOTE: with potential introduction of chainId this might need to be updated
|
||||
if (sig.length !== 65) {
|
||||
throw new Error('Invalid signature length')
|
||||
}
|
||||
|
||||
let v = sig[64]
|
||||
// support both versions of `eth_sign` responses
|
||||
if (v < 27) {
|
||||
v += 27
|
||||
}
|
||||
|
||||
return {
|
||||
v: v,
|
||||
r: sig.slice(0, 32),
|
||||
s: sig.slice(32, 64)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ethereum address of a given private key
|
||||
* @param {Buffer} privateKey A private key must be 256 bits wide
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.privateToAddress = function (privateKey) {
|
||||
return exports.publicToAddress(privateToPublic(privateKey))
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the address is a valid. Accepts checksummed addresses too
|
||||
* @param {String} address
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.isValidAddress = function (address) {
|
||||
return /^0x[0-9a-fA-F]{40}$/.test(address)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given address is a zero address
|
||||
* @method isZeroAddress
|
||||
* @param {String} address
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.isZeroAddress = function (address) {
|
||||
const zeroAddress = exports.zeroAddress()
|
||||
return zeroAddress === exports.addHexPrefix(address)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a checksummed address
|
||||
* @param {String} address
|
||||
* @return {String}
|
||||
*/
|
||||
exports.toChecksumAddress = function (address) {
|
||||
address = exports.stripHexPrefix(address).toLowerCase()
|
||||
const hash = exports.keccak(address).toString('hex')
|
||||
let ret = '0x'
|
||||
|
||||
for (let i = 0; i < address.length; i++) {
|
||||
if (parseInt(hash[i], 16) >= 8) {
|
||||
ret += address[i].toUpperCase()
|
||||
} else {
|
||||
ret += address[i]
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the address is a valid checksummed address
|
||||
* @param {Buffer} address
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.isValidChecksumAddress = function (address) {
|
||||
return exports.isValidAddress(address) && (exports.toChecksumAddress(address) === address)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an address of a newly created contract
|
||||
* @param {Buffer} from the address which is creating this new address
|
||||
* @param {Buffer} nonce the nonce of the from account
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.generateAddress = function (from, nonce) {
|
||||
from = exports.toBuffer(from)
|
||||
nonce = new BN(nonce)
|
||||
|
||||
if (nonce.isZero()) {
|
||||
// in RLP we want to encode null in the case of zero nonce
|
||||
// read the RLP documentation for an answer if you dare
|
||||
nonce = null
|
||||
} else {
|
||||
nonce = Buffer.from(nonce.toArray())
|
||||
}
|
||||
|
||||
// Only take the lower 160bits of the hash
|
||||
return exports.rlphash([from, nonce]).slice(-20)
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an address for a contract created using CREATE2
|
||||
* @param {Buffer} from the address which is creating this new address
|
||||
* @param {Buffer} salt a salt
|
||||
* @param {Buffer} initCode the init code of the contract being created
|
||||
* @return {Buffer}
|
||||
*/
|
||||
exports.generateAddress2 = function (from, salt, initCode) {
|
||||
from = exports.toBuffer(from)
|
||||
salt = exports.toBuffer(salt)
|
||||
initCode = exports.toBuffer(initCode)
|
||||
|
||||
assert(from.length === 20)
|
||||
assert(salt.length === 32)
|
||||
|
||||
let address = exports.keccak256(Buffer.concat([
|
||||
Buffer.from('ff', 'hex'),
|
||||
from,
|
||||
salt,
|
||||
exports.keccak256(initCode)
|
||||
]))
|
||||
|
||||
return address.slice(-20)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the supplied address belongs to a precompiled account (Byzantium)
|
||||
* @param {Buffer|String} address
|
||||
* @return {Boolean}
|
||||
*/
|
||||
exports.isPrecompiled = function (address) {
|
||||
const a = exports.unpad(address)
|
||||
return a.length === 1 && a[0] >= 1 && a[0] <= 8
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "0x" to a given `String` if it does not already start with "0x"
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
exports.addHexPrefix = function (str) {
|
||||
if (typeof str !== 'string') {
|
||||
return str
|
||||
}
|
||||
|
||||
return exports.isHexPrefixed(str) ? str : '0x' + str
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate ECDSA signature
|
||||
* @method isValidSignature
|
||||
* @param {Buffer} v
|
||||
* @param {Buffer} r
|
||||
* @param {Buffer} s
|
||||
* @param {Boolean} [homestead=true]
|
||||
* @param {Number} [chainId]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
exports.isValidSignature = function (v, r, s, homestead, chainId) {
|
||||
const SECP256K1_N_DIV_2 = new BN('7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0', 16)
|
||||
const SECP256K1_N = new BN('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141', 16)
|
||||
|
||||
if (r.length !== 32 || s.length !== 32) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!isValidSigRecovery(calculateSigRecovery(v, chainId))) {
|
||||
return false
|
||||
}
|
||||
|
||||
r = new BN(r)
|
||||
s = new BN(s)
|
||||
|
||||
if (r.isZero() || r.gt(SECP256K1_N) || s.isZero() || s.gt(SECP256K1_N)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if ((homestead === false) && (new BN(s).cmp(SECP256K1_N_DIV_2) === 1)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a `Buffer` or `Array` to JSON
|
||||
* @param {Buffer|Array} ba
|
||||
* @return {Array|String|null}
|
||||
*/
|
||||
exports.baToJSON = function (ba) {
|
||||
if (Buffer.isBuffer(ba)) {
|
||||
return '0x' + ba.toString('hex')
|
||||
} else if (ba instanceof Array) {
|
||||
const array = []
|
||||
for (let i = 0; i < ba.length; i++) {
|
||||
array.push(exports.baToJSON(ba[i]))
|
||||
}
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines properties on a `Object`. It make the assumption that underlying data is binary.
|
||||
* @param {Object} self the `Object` to define properties on
|
||||
* @param {Array} fields an array fields to define. Fields can contain:
|
||||
* * `name` - the name of the properties
|
||||
* * `length` - the number of bytes the field can have
|
||||
* * `allowLess` - if the field can be less than the length
|
||||
* * `allowEmpty`
|
||||
* @param {*} data data to be validated against the definitions
|
||||
*/
|
||||
exports.defineProperties = function (self, fields, data) {
|
||||
self.raw = []
|
||||
self._fields = []
|
||||
|
||||
// attach the `toJSON`
|
||||
self.toJSON = function (label) {
|
||||
if (label) {
|
||||
const obj = {}
|
||||
self._fields.forEach((field) => {
|
||||
obj[field] = '0x' + self[field].toString('hex')
|
||||
})
|
||||
return obj
|
||||
}
|
||||
return exports.baToJSON(this.raw)
|
||||
}
|
||||
|
||||
self.serialize = function serialize () {
|
||||
return rlp.encode(self.raw)
|
||||
}
|
||||
|
||||
fields.forEach((field, i) => {
|
||||
self._fields.push(field.name)
|
||||
function getter () {
|
||||
return self.raw[i]
|
||||
}
|
||||
function setter (v) {
|
||||
v = exports.toBuffer(v)
|
||||
|
||||
if (v.toString('hex') === '00' && !field.allowZero) {
|
||||
v = Buffer.allocUnsafe(0)
|
||||
}
|
||||
|
||||
if (field.allowLess && field.length) {
|
||||
v = exports.stripZeros(v)
|
||||
assert(field.length >= v.length, 'The field ' + field.name + ' must not have more ' + field.length + ' bytes')
|
||||
} else if (!(field.allowZero && v.length === 0) && field.length) {
|
||||
assert(field.length === v.length, 'The field ' + field.name + ' must have byte length of ' + field.length)
|
||||
}
|
||||
|
||||
self.raw[i] = v
|
||||
}
|
||||
|
||||
Object.defineProperty(self, field.name, {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get: getter,
|
||||
set: setter
|
||||
})
|
||||
|
||||
if (field.default) {
|
||||
self[field.name] = field.default
|
||||
}
|
||||
|
||||
// attach alias
|
||||
if (field.alias) {
|
||||
Object.defineProperty(self, field.alias, {
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
set: setter,
|
||||
get: getter
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// if the constuctor is passed data
|
||||
if (data) {
|
||||
if (typeof data === 'string') {
|
||||
data = Buffer.from(exports.stripHexPrefix(data), 'hex')
|
||||
}
|
||||
|
||||
if (Buffer.isBuffer(data)) {
|
||||
data = rlp.decode(data)
|
||||
}
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
if (data.length > self._fields.length) {
|
||||
throw (new Error('wrong number of fields in data'))
|
||||
}
|
||||
|
||||
// make sure all the items are buffers
|
||||
data.forEach((d, i) => {
|
||||
self[self._fields[i]] = exports.toBuffer(d)
|
||||
})
|
||||
} else if (typeof data === 'object') {
|
||||
const keys = Object.keys(data)
|
||||
fields.forEach((field) => {
|
||||
if (keys.indexOf(field.name) !== -1) self[field.name] = data[field.name]
|
||||
if (keys.indexOf(field.alias) !== -1) self[field.alias] = data[field.alias]
|
||||
})
|
||||
} else {
|
||||
throw new Error('invalid data')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculateSigRecovery (v, chainId) {
|
||||
return chainId ? v - (2 * chainId + 35) : v - 27
|
||||
}
|
||||
|
||||
function isValidSigRecovery (recovery) {
|
||||
return recovery === 0 || recovery === 1
|
||||
}
|
||||
125
libs/ethereumjs-util/package.json
Normal file
125
libs/ethereumjs-util/package.json
Normal file
@@ -0,0 +1,125 @@
|
||||
{
|
||||
"name": "ethereumjs-util",
|
||||
"version": "6.0.0",
|
||||
"description": "a collection of utility functions for Ethereum",
|
||||
"main": "dist/index.js",
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "browserify index.js -s ethUtil -o /tmp/ethereumjs-util.js",
|
||||
"coverage": "npm run build:dist && istanbul cover _mocha",
|
||||
"coveralls": "npm run coverage && coveralls <coverage/lcov.info",
|
||||
"lint": "standard",
|
||||
"prepublishOnly": "npm run test && npm run build:dist",
|
||||
"test": "npm run lint && npm run test:node && npm run test:browser",
|
||||
"test:browser": "npm run build:dist && karma start karma.conf.js",
|
||||
"test:node": "npm run build:dist && istanbul test mocha -- --reporter spec",
|
||||
"build:dist": "babel index.js --source-root ./ -d ./dist",
|
||||
"build:docs": "documentation build ./index.js --github --sort-order='alpha' -f md > ./docs/index.md"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ethereumjs/ethereumjs-util.git"
|
||||
},
|
||||
"keywords": [
|
||||
"ethereum",
|
||||
"utilties"
|
||||
],
|
||||
"author": "mjbecze <mjbecze@gmail.com>",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Tim Coulter",
|
||||
"email": "tim@timothyjcoulter.com",
|
||||
"url": "https://github.com/tcoulter",
|
||||
"contributions": 1,
|
||||
"additions": 2,
|
||||
"deletions": 2
|
||||
},
|
||||
{
|
||||
"name": "Nick Dodson",
|
||||
"url": "https://github.com/SilentCicero",
|
||||
"contributions": 2,
|
||||
"additions": 26,
|
||||
"deletions": 2
|
||||
},
|
||||
{
|
||||
"name": "Mr. Chico",
|
||||
"url": "https://github.com/MrChico",
|
||||
"contributions": 1,
|
||||
"additions": 11,
|
||||
"deletions": 1
|
||||
},
|
||||
{
|
||||
"name": "Dũng Trần",
|
||||
"email": "tad88.dev@gmail.com",
|
||||
"url": "https://github.com/tad88dev",
|
||||
"contributions": 2,
|
||||
"additions": 5,
|
||||
"deletions": 5
|
||||
},
|
||||
{
|
||||
"name": "Alex Beregszaszi",
|
||||
"email": "alex@rtfs.hu",
|
||||
"url": "https://github.com/axic",
|
||||
"contributions": 77,
|
||||
"additions": 1796,
|
||||
"deletions": 642
|
||||
},
|
||||
{
|
||||
"name": "Taylor Gerring",
|
||||
"url": "https://github.com/tgerring",
|
||||
"contributions": 1,
|
||||
"additions": 1,
|
||||
"deletions": 1
|
||||
},
|
||||
{
|
||||
"name": "Kirill Fomichev",
|
||||
"email": "fanatid@ya.ru",
|
||||
"url": "https://github.com/fanatid",
|
||||
"contributions": 8,
|
||||
"additions": 32,
|
||||
"deletions": 16
|
||||
},
|
||||
{
|
||||
"name": "kumavis",
|
||||
"email": "aaron@kumavis.me",
|
||||
"url": "https://github.com/kumavis",
|
||||
"contributions": 2,
|
||||
"additions": 2,
|
||||
"deletions": 2
|
||||
},
|
||||
{
|
||||
"name": "Alexander Sinyagin",
|
||||
"email": "sinyagin.alexander@gmail.com",
|
||||
"url": "https://github.com/asinyagin",
|
||||
"contributions": 1,
|
||||
"additions": 3,
|
||||
"deletions": 1
|
||||
}
|
||||
],
|
||||
"license": "MPL-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/ethereumjs/ethereumjs-util/issues"
|
||||
},
|
||||
"homepage": "https://github.com/ethereumjs/ethereumjs-util",
|
||||
"dependencies": {
|
||||
"bn.js": "^4.11.0",
|
||||
"create-hash": "^1.1.2",
|
||||
"ethjs-util": "^0.1.6",
|
||||
"keccak": "^1.0.2",
|
||||
"rlp": "^2.0.0",
|
||||
"safe-buffer": "^5.1.1",
|
||||
"secp256k1": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"standard": {
|
||||
"globals": [
|
||||
"describe",
|
||||
"it"
|
||||
],
|
||||
"ignore": [
|
||||
"dist/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
4
libs/ethereumjs-util/readme.md
Normal file
4
libs/ethereumjs-util/readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Build (will create a bundle and copy it to /tmp/ethereumjs-util.js):
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
1389
libs/stellar-util/package-lock.json
generated
Normal file
1389
libs/stellar-util/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
libs/stellar-util/package.json
Normal file
15
libs/stellar-util/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "stellar-util",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"build": "browserify stellar-util.js > /tmp/stellar-util.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"ed25519-hd-key": "^1.0.0",
|
||||
"stellar-base": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
"uglify-es": "^3.3.9"
|
||||
}
|
||||
}
|
||||
4
libs/stellar-util/readme.md
Normal file
4
libs/stellar-util/readme.md
Normal file
@@ -0,0 +1,4 @@
|
||||
Build (will create a bundle and copy it to /tmp/stellar-util.js):
|
||||
|
||||
npm install
|
||||
npm run build
|
||||
16
libs/stellar-util/stellar-util.js
Normal file
16
libs/stellar-util/stellar-util.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const StellarBase = require('stellar-base');
|
||||
const edHd = require('ed25519-hd-key');
|
||||
|
||||
window.stellarUtil = {
|
||||
getKeypair: function (path, seed) {
|
||||
const result = edHd.derivePath(path, seed);
|
||||
return StellarBase.Keypair.fromRawEd25519Seed(result.key);
|
||||
},
|
||||
dummyNetwork: {
|
||||
bip32: {public: 0, private: 0},
|
||||
messagePrefix: '',
|
||||
pubKeyHash: 0,
|
||||
scriptHash: 0,
|
||||
wif: 0,
|
||||
},
|
||||
}
|
||||
@@ -8,7 +8,8 @@ https://iancoleman.io/bip39/
|
||||
|
||||
## Standalone offline version
|
||||
|
||||
Download `bip39-standalone.html`
|
||||
Download `bip39-standalone.html` from
|
||||
[the releases](https://github.com/iancoleman/bip39/releases).
|
||||
|
||||
Open the file in a browser by double clicking it.
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ created with the following steps:
|
||||
1. include the changelog for this release as text for the release
|
||||
1. attach signature.txt.asc
|
||||
1. attach the bip39-standalone.html file
|
||||
1. Add a new post to twitter from @bip39tool with the version, link and hash
|
||||
1. Publish to any hosted locations (eg iancoleman.github.io/bip39)
|
||||
1. Download the file from the release and confirm it hashes to the expected value `sha256sum bip39-standalone.html`
|
||||
1. Download the signature from the release and verify it. `gpg --verify signature.txt.asc`
|
||||
1. Publish to any hosted locations (eg iancoleman.github.io/bip39)
|
||||
1. Add a new post to twitter from @bip39tool with the version, link and hash
|
||||
|
||||
@@ -106,3 +106,6 @@ body {
|
||||
.visual-privacy .private-data {
|
||||
display: none;
|
||||
}
|
||||
.text-weight-normal {
|
||||
font-weight: normal !important;
|
||||
}
|
||||
|
||||
119
src/index.html
119
src/index.html
@@ -15,7 +15,7 @@
|
||||
<div class="container">
|
||||
|
||||
<h1 class="text-center">Mnemonic Code Converter</h1>
|
||||
<p class="version">v0.3.10</p>
|
||||
<p class="version">v0.4.0</p>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
@@ -69,7 +69,7 @@
|
||||
<div class="form-group">
|
||||
<label for="entropy" class="col-sm-2 control-label">Entropy</label>
|
||||
<div class="col-sm-7">
|
||||
<textarea id="entropy" rows="2" class="entropy private-data form-control" placeholder="Accepts either binary, base 6, 6-sided dice, base 10, hexadecimal or cards"></textarea>
|
||||
<textarea id="entropy" rows="2" class="entropy private-data form-control" placeholder="Accepts either binary, base 6, 6-sided dice, base 10, hexadecimal or cards" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
<div class="row filter-warning text-danger hidden">
|
||||
<p class="col-sm-12">
|
||||
<strong>
|
||||
@@ -123,12 +123,42 @@
|
||||
<div class="col-sm-3">
|
||||
<p>Valid entropy values include:</p>
|
||||
<ul>
|
||||
<li><strong>Binary</strong> [0-1]<br>101010011</li>
|
||||
<li><strong>Base 6</strong> [0-5]<br>123434014</li>
|
||||
<li><strong>Dice</strong> [1-6]<br>62535634</li>
|
||||
<li><strong>Base 10</strong> [0-9]<br>90834528</li>
|
||||
<li><strong>Hex</strong> [0-9A-F]<br>4187a8bfd9</li>
|
||||
<li><strong>Card</strong> [A2-9TJQK][CDHS]<br>ahqs9dtc</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="entropy-type" value="binary">
|
||||
<strong>Binary</strong> [0-1]<br>101010011
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="entropy-type" value="base 6">
|
||||
<strong>Base 6</strong> [0-5]<br>123434014
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="entropy-type" value="dice">
|
||||
<strong>Dice</strong> [1-6]<br>62535634
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="entropy-type" value="base 10">
|
||||
<strong>Base 10</strong> [0-9]<br>90834528
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="entropy-type" value="hexadecimal" checked>
|
||||
<strong>Hex</strong> [0-9A-F]<br>4187a8bfd9
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="entropy-type" value="card">
|
||||
<strong>Card</strong> [A2-9TJQK][CDHS]<br>ahqs9dtc
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -163,25 +193,35 @@
|
||||
<a href="#french" title="French">Français</a>
|
||||
<a href="#italian" title="Italian">Italiano</a>
|
||||
<a href="#korean" title="Korean">한국어</a>
|
||||
<a href="#czech" title="Czech">Čeština</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="phrase" class="col-sm-2 control-label">BIP39 Mnemonic</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="phrase" class="phrase private-data form-control" data-show-qr></textarea>
|
||||
<textarea id="phrase" class="phrase private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="phrase" class="col-sm-2 control-label">BIP39 Split Mnemonic</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="phraseSplit" class="phraseSplit private-data form-control" title="Only 2 of 3 cards needed to recover." rows="3"></textarea>
|
||||
<p class="help-block">
|
||||
<span id="phraseSplitWarn" class="phraseSplitWarn"></span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="passphrase" class="passphrase private-data form-control"></textarea>
|
||||
<textarea id="passphrase" class="passphrase private-data form-control" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="seed" class="col-sm-2 control-label">BIP39 Seed</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="seed" class="seed private-data form-control" readonly="readonly" data-show-qr></textarea>
|
||||
<textarea id="seed" class="seed private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -195,7 +235,7 @@
|
||||
<div class="form-group">
|
||||
<label for="root-key" class="col-sm-2 control-label">BIP32 Root Key</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="root-key" class="root-key private-data form-control" data-show-qr></textarea>
|
||||
<textarea id="root-key" class="root-key private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group litecoin-ltub-container hidden">
|
||||
@@ -273,7 +313,7 @@
|
||||
<a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change" target="_blank">External / Internal</a>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<input id="change-bip44" type="text" class="change form-control" value="0">
|
||||
<input id="change-bip44" type="text" class="change form-control" value="0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -288,7 +328,7 @@
|
||||
<span>Account Extended Private Key</span>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="account-xprv-bip44" type="text" class="account-xprv private-data form-control" readonly data-show-qr></textarea>
|
||||
<textarea id="account-xprv-bip44" type="text" class="account-xprv private-data form-control" readonly data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -296,7 +336,7 @@
|
||||
<span>Account Extended Public Key</span>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="account-xpub-bip44" type="text" class="account-xpub form-control" readonly data-show-qr></textarea>
|
||||
<textarea id="account-xpub-bip44" type="text" class="account-xpub form-control" readonly data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -339,13 +379,6 @@
|
||||
<input id="bip32-path" type="text" class="path form-control" value="m/0">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-2"></div>
|
||||
<label class="col-sm-10">
|
||||
<input class="hardened-addresses" type="checkbox">
|
||||
<span>Use hardened addresses</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="core-path" class="col-sm-2 control-label">Bitcoin Core</label>
|
||||
<div class="col-sm-10">
|
||||
@@ -363,6 +396,7 @@
|
||||
<div class="col-sm-10">
|
||||
<p class="form-control no-border">
|
||||
<span>Use path <code>m/0'/0</code>.</span>
|
||||
<span>For change addresses use path <code>m/0'/1</code>.</span>
|
||||
</p>
|
||||
<p class="form-control no-border">
|
||||
<span>For more info see</span>
|
||||
@@ -448,7 +482,7 @@
|
||||
<span>Account Extended Private Key</span>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="account-xprv-bip49" type="text" class="account-xprv private-data form-control" readonly data-show-qr></textarea>
|
||||
<textarea id="account-xprv-bip49" type="text" class="account-xprv private-data form-control" readonly data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -456,7 +490,7 @@
|
||||
<span>Account Extended Public Key</span>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="account-xpub-bip49" type="text" class="account-xpub form-control" readonly data-show-qr></textarea>
|
||||
<textarea id="account-xpub-bip49" type="text" class="account-xpub form-control" readonly data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -506,6 +540,8 @@
|
||||
<select class="form-control bip141-semantics">
|
||||
<option value="p2wpkh">P2WPKH</option>
|
||||
<option value="p2wpkh-p2sh" selected>P2WPKH nested in P2SH</option>
|
||||
<option value="p2wsh">P2WSH (1-of-1 multisig)</option>
|
||||
<option value="p2wsh-p2sh">P2WSH nested in P2SH (1-of-1 multisig)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -575,7 +611,7 @@
|
||||
<span>Account Extended Private Key</span>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="account-xprv-bip84" type="text" class="account-xprv private-data form-control" readonly data-show-qr></textarea>
|
||||
<textarea id="account-xprv-bip84" type="text" class="account-xprv private-data form-control" readonly data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -583,7 +619,7 @@
|
||||
<span>Account Extended Public Key</span>
|
||||
</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="account-xpub-bip84" type="text" class="account-xpub form-control" readonly data-show-qr></textarea>
|
||||
<textarea id="account-xpub-bip84" type="text" class="account-xpub form-control" readonly data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -607,13 +643,13 @@
|
||||
<div class="form-group">
|
||||
<label for="extended-priv-key" class="col-sm-2 control-label">BIP32 Extended Private Key</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="extended-priv-key" class="extended-priv-key private-data form-control" readonly="readonly" data-show-qr></textarea>
|
||||
<textarea id="extended-priv-key" class="extended-priv-key private-data form-control" readonly="readonly" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="extended-pub-key" class="col-sm-2 control-label">BIP32 Extended Public Key</label>
|
||||
<div class="col-sm-10">
|
||||
<textarea id="extended-pub-key" class="extended-pub-key form-control" readonly="readonly" data-show-qr></textarea>
|
||||
<textarea id="extended-pub-key" class="extended-pub-key form-control" readonly="readonly" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -653,10 +689,18 @@
|
||||
<input type="checkbox" class="use-bip38">
|
||||
<span>Encrypt private keys using BIP38 and this password:</span>
|
||||
</label>
|
||||
<input class="bip38-password private-data">
|
||||
<input class="bip38-password private-data" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
|
||||
<span>Enabling BIP38 means each key will take several minutes to generate.</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input class="hardened-addresses" type="checkbox">
|
||||
<span>Use hardened addresses</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="addresses-type nav nav-tabs" role="tablist">
|
||||
<li id="table-tab" class="active">
|
||||
<a href="#table" role="tab" data-toggle="tab">Table</a>
|
||||
@@ -707,7 +751,7 @@
|
||||
</div>
|
||||
<div id="csv" class="tab-pane">
|
||||
<div class="col-md-12">
|
||||
<textarea class="csv form-control" rows="25" readonly></textarea>
|
||||
<textarea class="csv form-control" rows="25" readonly autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -913,20 +957,14 @@
|
||||
<td class="privkey private-data"><span data-show-qr></span></td>
|
||||
</tr>
|
||||
</script>
|
||||
<script src="js/polyfill.es6.js"></script>
|
||||
<script src="js/basex.js"></script>
|
||||
<script src="js/unorm.js"></script>
|
||||
<script src="js/jquery-3.2.1.js"></script>
|
||||
<script src="js/bootstrap-3.3.7.js"></script>
|
||||
<script src="js/levenshtein.js"></script>
|
||||
<script src="js/kjua-0.1.1.min.js"></script>
|
||||
<script src="js/bitcoinjs-3.3.2.js"></script>
|
||||
<script src="js/bip39-libs.js"></script>
|
||||
<script src="js/bitcoinjs-extensions.js"></script>
|
||||
<script src="js/bitcoinjs-bip38-2.0.2.js"></script>
|
||||
<script src="js/segwit-parameters.js"></script>
|
||||
<script src="js/ethereumjs-util.js"></script>
|
||||
<script src="js/ripple-util.js"></script>
|
||||
<script src="js/bchaddrjs-0.2.1.js"></script>
|
||||
<script src="js/casinocoin-util.js"></script>
|
||||
<script src="js/eos-util.js"></script>
|
||||
<script src="js/sjcl-bip39.js"></script>
|
||||
<script src="js/wordlist_english.js"></script>
|
||||
<script src="js/wordlist_japanese.js"></script>
|
||||
@@ -936,9 +974,8 @@
|
||||
<script src="js/wordlist_french.js"></script>
|
||||
<script src="js/wordlist_italian.js"></script>
|
||||
<script src="js/wordlist_korean.js"></script>
|
||||
<script src="js/wordlist_czech.js"></script>
|
||||
<script src="js/jsbip39.js"></script>
|
||||
<script src="js/biginteger.js"></script>
|
||||
<script src="js/zxcvbn.js"></script>
|
||||
<script src="js/entropy.js"></script>
|
||||
<script src="js/index.js"></script>
|
||||
</body>
|
||||
|
||||
2010
src/js/basex.js
2010
src/js/basex.js
File diff suppressed because it is too large
Load Diff
1620
src/js/biginteger.js
1620
src/js/biginteger.js
File diff suppressed because it is too large
Load Diff
1
src/js/bip39-libs.js
Normal file
1
src/js/bip39-libs.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
9
src/js/casinocoin-util.js
Normal file
9
src/js/casinocoin-util.js
Normal file
@@ -0,0 +1,9 @@
|
||||
function convertCasinoCoinAdrr(address) {
|
||||
return libs.basex('cpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2brdeCg65jkm8oFqi1tuvAxyz').encode(
|
||||
libs.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(address)
|
||||
)
|
||||
}
|
||||
|
||||
function convertCasinoCoinPriv(priv) {
|
||||
return libs.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(priv).toString("hex").slice(2,66)
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
window.Entropy = new (function() {
|
||||
|
||||
var TWO = new BigInteger(2);
|
||||
var TWO = new libs.BigInteger.BigInteger(2);
|
||||
|
||||
// matchers returns an array of the matched events for each type of entropy.
|
||||
// eg
|
||||
@@ -67,9 +67,9 @@ window.Entropy = new (function() {
|
||||
return ints;
|
||||
}
|
||||
|
||||
this.fromString = function(rawEntropyStr) {
|
||||
this.fromString = function(rawEntropyStr, baseStr) {
|
||||
// Find type of entropy being used (binary, hex, dice etc)
|
||||
var base = getBase(rawEntropyStr);
|
||||
var base = getBase(rawEntropyStr, baseStr);
|
||||
// Convert dice to base6 entropy (ie 1-6 to 0-5)
|
||||
// This is done by changing all 6s to 0s
|
||||
if (base.str == "dice") {
|
||||
@@ -103,11 +103,11 @@ window.Entropy = new (function() {
|
||||
// Convert base.ints to BigInteger.
|
||||
// Due to using unusual bases, eg cards of base52, this is not as simple as
|
||||
// using BigInteger.parse()
|
||||
var entropyInt = BigInteger.ZERO;
|
||||
var entropyInt = libs.BigInteger.BigInteger.ZERO;
|
||||
for (var i=base.ints.length-1; i>=0; i--) {
|
||||
var thisInt = BigInteger.parse(base.ints[i]);
|
||||
var thisInt = libs.BigInteger.BigInteger.parse(base.ints[i]);
|
||||
var power = (base.ints.length - 1) - i;
|
||||
var additionalEntropy = BigInteger.parse(base.asInt).pow(power).multiply(thisInt);
|
||||
var additionalEntropy = libs.BigInteger.BigInteger.parse(base.asInt).pow(power).multiply(thisInt);
|
||||
entropyInt = entropyInt.add(additionalEntropy);
|
||||
}
|
||||
// Convert entropy to binary
|
||||
@@ -166,13 +166,14 @@ window.Entropy = new (function() {
|
||||
return s;
|
||||
}
|
||||
|
||||
function getBase(str) {
|
||||
function getBase(str, baseStr) {
|
||||
// Need to get the lowest base for the supplied entropy.
|
||||
// This prevents interpreting, say, dice rolls as hexadecimal.
|
||||
var binaryMatches = matchers.binary(str);
|
||||
var hexMatches = matchers.hex(str);
|
||||
var autodetect = baseStr === undefined;
|
||||
// Find the lowest base that can be used, whilst ignoring any irrelevant chars
|
||||
if (binaryMatches.length == hexMatches.length && hexMatches.length > 0) {
|
||||
if ((binaryMatches.length == hexMatches.length && hexMatches.length > 0 && autodetect) || baseStr === "binary") {
|
||||
var ints = binaryMatches.map(function(i) { return parseInt(i, 2) });
|
||||
return {
|
||||
ints: ints,
|
||||
@@ -183,7 +184,7 @@ window.Entropy = new (function() {
|
||||
}
|
||||
}
|
||||
var cardMatches = matchers.card(str);
|
||||
if (cardMatches.length >= hexMatches.length / 2) {
|
||||
if ((cardMatches.length >= hexMatches.length / 2 && autodetect) || baseStr === "card") {
|
||||
var ints = convertCardsToInts(cardMatches);
|
||||
return {
|
||||
ints: ints,
|
||||
@@ -194,7 +195,7 @@ window.Entropy = new (function() {
|
||||
}
|
||||
}
|
||||
var diceMatches = matchers.dice(str);
|
||||
if (diceMatches.length == hexMatches.length && hexMatches.length > 0) {
|
||||
if ((diceMatches.length == hexMatches.length && hexMatches.length > 0 && autodetect) || baseStr === "dice") {
|
||||
var ints = diceMatches.map(function(i) { return parseInt(i) });
|
||||
return {
|
||||
ints: ints,
|
||||
@@ -205,7 +206,7 @@ window.Entropy = new (function() {
|
||||
}
|
||||
}
|
||||
var base6Matches = matchers.base6(str);
|
||||
if (base6Matches.length == hexMatches.length && hexMatches.length > 0) {
|
||||
if ((base6Matches.length == hexMatches.length && hexMatches.length > 0 && autodetect) || baseStr === "base 6") {
|
||||
var ints = base6Matches.map(function(i) { return parseInt(i) });
|
||||
return {
|
||||
ints: ints,
|
||||
@@ -216,7 +217,7 @@ window.Entropy = new (function() {
|
||||
}
|
||||
}
|
||||
var base10Matches = matchers.base10(str);
|
||||
if (base10Matches.length == hexMatches.length && hexMatches.length > 0) {
|
||||
if ((base10Matches.length == hexMatches.length && hexMatches.length > 0 && autodetect) || baseStr === "base 10") {
|
||||
var ints = base10Matches.map(function(i) { return parseInt(i) });
|
||||
return {
|
||||
ints: ints,
|
||||
@@ -327,7 +328,7 @@ window.Entropy = new (function() {
|
||||
// Math.LOG2E
|
||||
// log2(8) gave 2.9999999999999996 which when floored causes issues.
|
||||
// So instead use the BigInteger library to get it right.
|
||||
return BigInteger.log(x) / BigInteger.log(2);
|
||||
return libs.BigInteger.BigInteger.log(x) / libs.BigInteger.BigInteger.log(2);
|
||||
};
|
||||
|
||||
// Depends on BigInteger
|
||||
@@ -335,9 +336,9 @@ window.Entropy = new (function() {
|
||||
if (n == 0) {
|
||||
return 1;
|
||||
}
|
||||
f = BigInteger.ONE;
|
||||
f = libs.BigInteger.BigInteger.ONE;
|
||||
for (var i=1; i<=n; i++) {
|
||||
f = f.multiply(new BigInteger(i));
|
||||
f = f.multiply(new libs.BigInteger.BigInteger(i));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1072
src/js/index.js
1072
src/js/index.js
File diff suppressed because it is too large
Load Diff
@@ -97,22 +97,10 @@ var Mnemonic = function(language) {
|
||||
}
|
||||
|
||||
self.check = function(mnemonic) {
|
||||
var mnemonic = self.splitWords(mnemonic);
|
||||
if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
|
||||
return false
|
||||
var b = mnemonicToBinaryString(mnemonic);
|
||||
if (b === null) {
|
||||
return false;
|
||||
}
|
||||
// idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
|
||||
var idx = [];
|
||||
for (var i=0; i<mnemonic.length; i++) {
|
||||
var word = mnemonic[i];
|
||||
var wordIndex = wordlist.indexOf(word);
|
||||
if (wordIndex == -1) {
|
||||
return false;
|
||||
}
|
||||
var binaryIndex = zfill(wordIndex.toString(2), 11);
|
||||
idx.push(binaryIndex);
|
||||
}
|
||||
var b = idx.join('');
|
||||
var l = b.length;
|
||||
//d = b[:l / 33 * 32]
|
||||
//h = b[-l / 33:]
|
||||
@@ -128,6 +116,26 @@ var Mnemonic = function(language) {
|
||||
return h == nh;
|
||||
}
|
||||
|
||||
self.toRawEntropyHex = function(mnemonic) {
|
||||
var b = mnemonicToBinaryString(mnemonic);
|
||||
if (b === null)
|
||||
return null;
|
||||
var d = b.substring(0, b.length / 33 * 32);
|
||||
var nd = binaryStringToWordArray(d);
|
||||
|
||||
var h = "";
|
||||
for (var i=0; i<nd.length; i++) {
|
||||
h += ('0000000' + nd[i].toString(16)).slice(-8);
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
self.toRawEntropyBin = function(mnemonic) {
|
||||
var b = mnemonicToBinaryString(mnemonic);
|
||||
var d = b.substring(0, b.length / 33 * 32);
|
||||
return d;
|
||||
}
|
||||
|
||||
self.toSeed = function(mnemonic, passphrase) {
|
||||
passphrase = passphrase || '';
|
||||
mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks
|
||||
@@ -200,6 +208,25 @@ var Mnemonic = function(language) {
|
||||
return a;
|
||||
}
|
||||
|
||||
function mnemonicToBinaryString(mnemonic) {
|
||||
var mnemonic = self.splitWords(mnemonic);
|
||||
if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
|
||||
return null;
|
||||
}
|
||||
// idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
|
||||
var idx = [];
|
||||
for (var i=0; i<mnemonic.length; i++) {
|
||||
var word = mnemonic[i];
|
||||
var wordIndex = wordlist.indexOf(word);
|
||||
if (wordIndex == -1) {
|
||||
return null;
|
||||
}
|
||||
var binaryIndex = zfill(wordIndex.toString(2), 11);
|
||||
idx.push(binaryIndex);
|
||||
}
|
||||
return idx.join('');
|
||||
}
|
||||
|
||||
// Pad a numeric string on the left with zero digits until the given width
|
||||
// is reached.
|
||||
// Note this differs to the python implementation because it does not
|
||||
|
||||
2
src/js/kjua-0.1.1.min.js
vendored
2
src/js/kjua-0.1.1.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,211 +0,0 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Extend an Object with another Object's properties.
|
||||
*
|
||||
* The source objects are specified as additional arguments.
|
||||
*
|
||||
* @param dst Object the object to extend.
|
||||
*
|
||||
* @return Object the final object.
|
||||
*/
|
||||
var _extend = function(dst) {
|
||||
var sources = Array.prototype.slice.call(arguments, 1);
|
||||
for (var i=0; i<sources.length; ++i) {
|
||||
var src = sources[i];
|
||||
for (var p in src) {
|
||||
if (src.hasOwnProperty(p)) dst[p] = src[p];
|
||||
}
|
||||
}
|
||||
return dst;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Defer execution of given function.
|
||||
* @param {Function} func
|
||||
*/
|
||||
var _defer = function(func) {
|
||||
if (typeof setImmediate === 'function') {
|
||||
return setImmediate(func);
|
||||
} else {
|
||||
return setTimeout(func, 0);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Based on the algorithm at http://en.wikipedia.org/wiki/Levenshtein_distance.
|
||||
*/
|
||||
var Levenshtein = {
|
||||
/**
|
||||
* Calculate levenshtein distance of the two strings.
|
||||
*
|
||||
* @param str1 String the first string.
|
||||
* @param str2 String the second string.
|
||||
* @return Integer the levenshtein distance (0 and above).
|
||||
*/
|
||||
get: function(str1, str2) {
|
||||
// base cases
|
||||
if (str1 === str2) return 0;
|
||||
if (str1.length === 0) return str2.length;
|
||||
if (str2.length === 0) return str1.length;
|
||||
|
||||
// two rows
|
||||
var prevRow = new Array(str2.length + 1),
|
||||
curCol, nextCol, i, j, tmp;
|
||||
|
||||
// initialise previous row
|
||||
for (i=0; i<prevRow.length; ++i) {
|
||||
prevRow[i] = i;
|
||||
}
|
||||
|
||||
// calculate current row distance from previous row
|
||||
for (i=0; i<str1.length; ++i) {
|
||||
nextCol = i + 1;
|
||||
|
||||
for (j=0; j<str2.length; ++j) {
|
||||
curCol = nextCol;
|
||||
|
||||
// substution
|
||||
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
|
||||
// insertion
|
||||
tmp = curCol + 1;
|
||||
if (nextCol > tmp) {
|
||||
nextCol = tmp;
|
||||
}
|
||||
// deletion
|
||||
tmp = prevRow[j + 1] + 1;
|
||||
if (nextCol > tmp) {
|
||||
nextCol = tmp;
|
||||
}
|
||||
|
||||
// copy current col value into previous (in preparation for next iteration)
|
||||
prevRow[j] = curCol;
|
||||
}
|
||||
|
||||
// copy last col value into previous (in preparation for next iteration)
|
||||
prevRow[j] = nextCol;
|
||||
}
|
||||
|
||||
return nextCol;
|
||||
},
|
||||
|
||||
/**
|
||||
* Asynchronously calculate levenshtein distance of the two strings.
|
||||
*
|
||||
* @param str1 String the first string.
|
||||
* @param str2 String the second string.
|
||||
* @param cb Function callback function with signature: function(Error err, int distance)
|
||||
* @param [options] Object additional options.
|
||||
* @param [options.progress] Function progress callback with signature: function(percentComplete)
|
||||
*/
|
||||
getAsync: function(str1, str2, cb, options) {
|
||||
options = _extend({}, {
|
||||
progress: null
|
||||
}, options);
|
||||
|
||||
// base cases
|
||||
if (str1 === str2) return cb(null, 0);
|
||||
if (str1.length === 0) return cb(null, str2.length);
|
||||
if (str2.length === 0) return cb(null, str1.length);
|
||||
|
||||
// two rows
|
||||
var prevRow = new Array(str2.length + 1),
|
||||
curCol, nextCol,
|
||||
i, j, tmp,
|
||||
startTime, currentTime;
|
||||
|
||||
// initialise previous row
|
||||
for (i=0; i<prevRow.length; ++i) {
|
||||
prevRow[i] = i;
|
||||
}
|
||||
|
||||
nextCol = 1;
|
||||
i = 0;
|
||||
j = -1;
|
||||
|
||||
var __calculate = function() {
|
||||
// reset timer
|
||||
startTime = new Date().valueOf();
|
||||
currentTime = startTime;
|
||||
|
||||
// keep going until one second has elapsed
|
||||
while (currentTime - startTime < 1000) {
|
||||
// reached end of current row?
|
||||
if (str2.length <= (++j)) {
|
||||
// copy current into previous (in preparation for next iteration)
|
||||
prevRow[j] = nextCol;
|
||||
|
||||
// if already done all chars
|
||||
if (str1.length <= (++i)) {
|
||||
return cb(null, nextCol);
|
||||
}
|
||||
// else if we have more left to do
|
||||
else {
|
||||
nextCol = i + 1;
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// calculation
|
||||
curCol = nextCol;
|
||||
|
||||
// substution
|
||||
nextCol = prevRow[j] + ( (str1.charAt(i) === str2.charAt(j)) ? 0 : 1 );
|
||||
// insertion
|
||||
tmp = curCol + 1;
|
||||
if (nextCol > tmp) {
|
||||
nextCol = tmp;
|
||||
}
|
||||
// deletion
|
||||
tmp = prevRow[j + 1] + 1;
|
||||
if (nextCol > tmp) {
|
||||
nextCol = tmp;
|
||||
}
|
||||
|
||||
// copy current into previous (in preparation for next iteration)
|
||||
prevRow[j] = curCol;
|
||||
|
||||
// get current time
|
||||
currentTime = new Date().valueOf();
|
||||
}
|
||||
|
||||
// send a progress update?
|
||||
if (null !== options.progress) {
|
||||
try {
|
||||
options.progress.call(null, (i * 100.0/ str1.length));
|
||||
} catch (err) {
|
||||
return cb('Progress callback: ' + err.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// next iteration
|
||||
_defer(__calculate);
|
||||
};
|
||||
|
||||
__calculate();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// amd
|
||||
if (typeof define !== "undefined" && define !== null && define.amd) {
|
||||
define(function() {
|
||||
return Levenshtein;
|
||||
});
|
||||
}
|
||||
// commonjs
|
||||
else if (typeof module !== "undefined" && module !== null && typeof exports !== "undefined" && module.exports === exports) {
|
||||
module.exports = Levenshtein;
|
||||
}
|
||||
// web worker
|
||||
else if (typeof self !== "undefined" && typeof self.postMessage === 'function' && typeof self.importScripts === 'function') {
|
||||
self.Levenshtein = Levenshtein;
|
||||
}
|
||||
// browser main thread
|
||||
else if (typeof window !== "undefined" && window !== null) {
|
||||
window.Levenshtein = Levenshtein;
|
||||
}
|
||||
}());
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,10 @@
|
||||
function convertRippleAdrr(address) {
|
||||
return window.basex('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz').encode(
|
||||
window.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(address)
|
||||
return libs.basex('rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz').encode(
|
||||
libs.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(address)
|
||||
)
|
||||
}
|
||||
|
||||
function convertRipplePriv(priv) {
|
||||
return window.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(priv).toString("hex").slice(2,66)
|
||||
}
|
||||
|
||||
return libs.basex('123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz').decode(priv).toString("hex").slice(2,66)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
// p2wpkh
|
||||
|
||||
bitcoinjs.bitcoin.networks.bitcoin.p2wpkh = {
|
||||
libs.bitcoin.networks.bitcoin.p2wpkh = {
|
||||
baseNetwork: "bitcoin",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
@@ -15,7 +15,7 @@ bitcoinjs.bitcoin.networks.bitcoin.p2wpkh = {
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.testnet.p2wpkh = {
|
||||
libs.bitcoin.networks.testnet.p2wpkh = {
|
||||
baseNetwork: "testnet",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'tb',
|
||||
@@ -28,9 +28,22 @@ bitcoinjs.bitcoin.networks.testnet.p2wpkh = {
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.regtest.p2wpkh = {
|
||||
baseNetwork: "regtest",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bcrt',
|
||||
bip32: {
|
||||
public: 0x045f1cf6,
|
||||
private: 0x045f18bc
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
// p2wpkh in p2sh
|
||||
|
||||
bitcoinjs.bitcoin.networks.bitcoin.p2wpkhInP2sh = {
|
||||
libs.bitcoin.networks.bitcoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "bitcoin",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
@@ -43,7 +56,7 @@ bitcoinjs.bitcoin.networks.bitcoin.p2wpkhInP2sh = {
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.testnet.p2wpkhInP2sh = {
|
||||
libs.bitcoin.networks.testnet.p2wpkhInP2sh = {
|
||||
baseNetwork: "testnet",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'tb',
|
||||
@@ -56,7 +69,102 @@ bitcoinjs.bitcoin.networks.testnet.p2wpkhInP2sh = {
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.litecoin.p2wpkh = {
|
||||
libs.bitcoin.networks.regtest.p2wpkhInP2sh = {
|
||||
baseNetwork: "regtest",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bcrt',
|
||||
bip32: {
|
||||
public: 0x044a5262,
|
||||
private: 0x044a4e28
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
// p2wsh
|
||||
|
||||
libs.bitcoin.networks.bitcoin.p2wsh = {
|
||||
baseNetwork: "bitcoin",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
bip32: {
|
||||
public: 0x02aa7ed3,
|
||||
private: 0x02aa7a99
|
||||
},
|
||||
pubKeyHash: 0x00,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.testnet.p2wsh = {
|
||||
baseNetwork: "testnet",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'tb',
|
||||
bip32: {
|
||||
public: 0x02575483,
|
||||
private: 0x02575048
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.regtest.p2wsh = {
|
||||
baseNetwork: "regtest",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bcrt',
|
||||
bip32: {
|
||||
public: 0x02575483,
|
||||
private: 0x02575048
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
// p2wsh in p2sh
|
||||
|
||||
libs.bitcoin.networks.bitcoin.p2wshInP2sh = {
|
||||
baseNetwork: "bitcoin",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
bip32: {
|
||||
public: 0x0295b43f,
|
||||
private: 0x0295b005
|
||||
},
|
||||
pubKeyHash: 0x00,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.testnet.p2wshInP2sh = {
|
||||
baseNetwork: "testnet",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'tb',
|
||||
bip32: {
|
||||
public: 0x024289ef,
|
||||
private: 0x024285b5
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.regtest.p2wshInP2sh = {
|
||||
baseNetwork: "regtest",
|
||||
messagePrefix: '\x18Bitcoin Signed Message:\n',
|
||||
bech32: 'bcrt',
|
||||
bip32: {
|
||||
public: 0x024289ef,
|
||||
private: 0x024285b5
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.litecoin.p2wpkh = {
|
||||
baseNetwork: "litecoin",
|
||||
messagePrefix: '\x19Litecoin Signed Message:\n',
|
||||
bech32: 'ltc',
|
||||
@@ -69,7 +177,7 @@ bitcoinjs.bitcoin.networks.litecoin.p2wpkh = {
|
||||
wif: 0xb0
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.litecoin.p2wpkhInP2sh = {
|
||||
libs.bitcoin.networks.litecoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "litecoin",
|
||||
messagePrefix: '\x19Litecoin Signed Message:\n',
|
||||
bech32: 'ltc',
|
||||
@@ -82,7 +190,7 @@ bitcoinjs.bitcoin.networks.litecoin.p2wpkhInP2sh = {
|
||||
wif: 0xb0
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.fujicoin.p2wpkh = {
|
||||
libs.bitcoin.networks.fujicoin.p2wpkh = {
|
||||
baseNetwork: "fujicoin",
|
||||
messagePrefix: '\x19FujiCoin Signed Message:\n',
|
||||
bech32: 'fc',
|
||||
@@ -95,7 +203,7 @@ bitcoinjs.bitcoin.networks.fujicoin.p2wpkh = {
|
||||
wif: 0xa4
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.fujicoin.p2wpkhInP2sh = {
|
||||
libs.bitcoin.networks.fujicoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "fujicoin",
|
||||
messagePrefix: '\x19FujiCoin Signed Message:\n',
|
||||
bech32: 'fc',
|
||||
@@ -108,7 +216,7 @@ bitcoinjs.bitcoin.networks.fujicoin.p2wpkhInP2sh = {
|
||||
wif: 0xa4
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.vertcoin.p2wpkh = {
|
||||
libs.bitcoin.networks.vertcoin.p2wpkh = {
|
||||
baseNetwork: "vertcoin",
|
||||
messagePrefix: '\x18Vertcoin Signed Message:\n',
|
||||
bech32: 'vtc',
|
||||
@@ -121,7 +229,7 @@ bitcoinjs.bitcoin.networks.vertcoin.p2wpkh = {
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.vertcoin.p2wpkhInP2sh = {
|
||||
libs.bitcoin.networks.vertcoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "vertcoin",
|
||||
messagePrefix: '\x18Vertcoin Signed Message:\n',
|
||||
bip32: {
|
||||
@@ -133,7 +241,7 @@ bitcoinjs.bitcoin.networks.vertcoin.p2wpkhInP2sh = {
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.bgold.p2wpkh = {
|
||||
libs.bitcoin.networks.bgold.p2wpkh = {
|
||||
baseNetwork: "bgold",
|
||||
messagePrefix: '\x1DBitcoin Gold Signed Message:\n',
|
||||
bech32: 'btg',
|
||||
@@ -146,7 +254,7 @@ bitcoinjs.bitcoin.networks.bgold.p2wpkh = {
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.bgold.p2wpkhInP2sh = {
|
||||
libs.bitcoin.networks.bgold.p2wpkhInP2sh = {
|
||||
baseNetwork: "bgold",
|
||||
messagePrefix: '\x1DBitcoin Gold Signed Message:\n',
|
||||
bech32: 'btg',
|
||||
@@ -159,33 +267,33 @@ bitcoinjs.bitcoin.networks.bgold.p2wpkhInP2sh = {
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.digibyte.p2wpkh = {
|
||||
libs.bitcoin.networks.digibyte.p2wpkh = {
|
||||
baseNetwork: "digibyte",
|
||||
messagePrefix: '\x18DigiByte Signed Message:\n',
|
||||
messagePrefix: 'x19DigiByte Signed Message:\n',
|
||||
bech32: 'dgb',
|
||||
bip32: {
|
||||
public: 0x0488B21E,
|
||||
private: 0x0488ADE4
|
||||
public: 0x04b24746,
|
||||
private: 0x04b2430c
|
||||
},
|
||||
pubKeyHash: 0x1e,
|
||||
scriptHash: 0x3f,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.digibyte.p2wpkhInP2sh = {
|
||||
baseNetwork: "digibyte",
|
||||
messagePrefix: '\x18DigiByte Signed Message:\n',
|
||||
libs.bitcoin.networks.digibyte.p2wpkhInP2sh = {
|
||||
baseNetwork: "digibyte",
|
||||
messagePrefix: '\x19DigiByte Signed Message:\n',
|
||||
bech32: 'dgb',
|
||||
bip32: {
|
||||
public: 0x0488B21E,
|
||||
private: 0x0488ADE4
|
||||
public: 0x049d7cb2,
|
||||
private: 0x049d7878
|
||||
},
|
||||
pubKeyHash: 0x1e,
|
||||
scriptHash: 0x3f,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.blockstamp.p2wpkh = {
|
||||
libs.bitcoin.networks.blockstamp.p2wpkh = {
|
||||
baseNetwork: "blockstamp",
|
||||
messagePrefix: '\x18BlockStamp Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
@@ -198,8 +306,8 @@ bitcoinjs.bitcoin.networks.blockstamp.p2wpkh = {
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
bitcoinjs.bitcoin.networks.blockstamp.p2wpkhInP2sh = {
|
||||
baseNetwork: "blockstamp",
|
||||
libs.bitcoin.networks.blockstamp.p2wpkhInP2sh = {
|
||||
baseNetwork: "blockstamp",
|
||||
messagePrefix: '\x18BlockStamp Signed Message:\n',
|
||||
bech32: 'bc',
|
||||
bip32: {
|
||||
@@ -210,4 +318,343 @@ bitcoinjs.bitcoin.networks.blockstamp.p2wpkhInP2sh = {
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.nix.p2wpkh = {
|
||||
baseNetwork: "nix",
|
||||
messagePrefix: '\x18Nix Signed Message:\n',
|
||||
bech32: 'nix',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4,
|
||||
},
|
||||
pubKeyHash: 0x26,
|
||||
scriptHash: 0x35,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.nix.p2wpkhInP2sh = {
|
||||
baseNetwork: "nix",
|
||||
messagePrefix: '\x18Nix Signed Message:\n',
|
||||
bech32: 'nix',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4,
|
||||
},
|
||||
pubKeyHash: 0x26,
|
||||
scriptHash: 0x35,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.cpuchain.p2wpkh = {
|
||||
baseNetwork: "cpuchain",
|
||||
messagePrefix: '\x1DCPUchain Signed Message:\n',
|
||||
bech32: 'cpu',
|
||||
bip32: {
|
||||
public: 0x04b24746,
|
||||
private: 0x04b2430c
|
||||
},
|
||||
pubKeyHash: 0x1c,
|
||||
scriptHash: 0x1e,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.cpuchain.p2wpkhInP2sh = {
|
||||
baseNetwork: "cpuchain",
|
||||
messagePrefix: '\x1DCPUchain Signed Message:\n',
|
||||
bech32: 'cpu',
|
||||
bip32: {
|
||||
public: 0x049d7cb2,
|
||||
private: 0x049d7878
|
||||
},
|
||||
pubKeyHash: 0x1c,
|
||||
scriptHash: 0x1e,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.monkeyproject.p2wpkh = {
|
||||
baseNetwork: "monkeyproject",
|
||||
messagePrefix: 'Monkey Signed Message:\n',
|
||||
bech32: 'monkey',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488dde4
|
||||
},
|
||||
pubKeyHash: 0x33,
|
||||
scriptHash: 0x1c,
|
||||
wif: 0x37
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.monkeyproject.p2wpkhInP2sh = {
|
||||
baseNetwork: "monkeyproject",
|
||||
messagePrefix: 'Monkey Signed Message:\n',
|
||||
bech32: 'monkey',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488dde4
|
||||
},
|
||||
pubKeyHash: 0x33,
|
||||
scriptHash: 0x1c,
|
||||
wif: 0x37
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.atom.p2wpkh = {
|
||||
baseNetwork: "atom",
|
||||
messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
|
||||
bech32: 'atom',
|
||||
bip32: {
|
||||
public: 0x0488B21E,
|
||||
private: 0x0488ADE4
|
||||
},
|
||||
pubKeyHash: 0x17,
|
||||
scriptHash: 0x0a,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.atom.p2wpkhInP2sh = {
|
||||
baseNetwork: "atom",
|
||||
messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
|
||||
bech32: 'atom',
|
||||
bip32: {
|
||||
public: 0x0488B21E,
|
||||
private: 0x0488ADE4
|
||||
},
|
||||
pubKeyHash: 0x17,
|
||||
scriptHash: 0x0a,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.bitcore.p2wpkh = {
|
||||
baseNetwork: "bitcore",
|
||||
messagePrefix: '\x18BitCore Signed Message:\n',
|
||||
bech32: 'bitcore',
|
||||
bip32: {
|
||||
public: 0x0488B21E,
|
||||
private: 0x0488ADE4
|
||||
},
|
||||
pubKeyHash: 0x03,
|
||||
scriptHash: 0x7D,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.bitcore.p2wpkhInP2sh = {
|
||||
baseNetwork: "bitcore",
|
||||
messagePrefix: '\x18BitCore Signed Message:\n',
|
||||
bech32: 'bitcore',
|
||||
bip32: {
|
||||
public: 0x0488B21E,
|
||||
private: 0x0488ADE4
|
||||
},
|
||||
pubKeyHash: 0x03,
|
||||
scriptHash: 0x7D,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.monacoin.p2wpkh = {
|
||||
baseNetwork: "monacoin",
|
||||
messagePrefix: '\x18Monacoin Signed Message:\n',
|
||||
bech32: 'monacoin',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4
|
||||
},
|
||||
pubKeyHash: 0x32,
|
||||
scriptHash: 0x37,
|
||||
wif: 0xb0
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.monacoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "monacoin",
|
||||
messagePrefix: '\x18Monacoin Signed Message:\n',
|
||||
bech32: 'monacoin',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4
|
||||
},
|
||||
pubKeyHash: 0x32,
|
||||
scriptHash: 0x37,
|
||||
wif: 0xb0
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.syscoin.p2wpkh = {
|
||||
baseNetwork: "syscoin",
|
||||
messagePrefix: '\x18Syscoin Signed Message:\n',
|
||||
bech32: 'sys',
|
||||
bip32: {
|
||||
public: 0x04b24746,
|
||||
private: 0x04b2430c
|
||||
},
|
||||
pubKeyHash: 0x3f,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.syscoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "syscoin",
|
||||
messagePrefix: '\x18Syscoin Signed Message:\n',
|
||||
bech32: 'sys',
|
||||
bip32: {
|
||||
public: 0x049d7cb2,
|
||||
private: 0x049d7878
|
||||
},
|
||||
pubKeyHash: 0x3f,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.viacoin.p2wpkh = {
|
||||
baseNetwork: "viacoin",
|
||||
messagePrefix: '\x18Viacoin Signed Message:\n',
|
||||
bech32: 'viacoin',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4
|
||||
},
|
||||
pubKeyHash: 0x47,
|
||||
scriptHash: 0x21,
|
||||
wif: 0xc7
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.viacoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "viacoin",
|
||||
messagePrefix: '\x18Viacoin Signed Message:\n',
|
||||
bech32: 'viacoin',
|
||||
bip32: {
|
||||
public: 0x0488b21e,
|
||||
private: 0x0488ade4
|
||||
},
|
||||
pubKeyHash: 0x47,
|
||||
scriptHash: 0x21,
|
||||
wif: 0xc7
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.dogecointestnet.p2wpkh = {
|
||||
baseNetwork: "dogecointestnet",
|
||||
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||
bech32: 'dogecointestnet',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubKeyHash: 0x71,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xf1
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
|
||||
baseNetwork: "dogecointestnet",
|
||||
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||
bech32: 'dogecointestnet',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubKeyHash: 0x71,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xf1
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.dogecointestnet.p2wpkh = {
|
||||
baseNetwork: "dogecointestnet",
|
||||
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||
bech32: 'dogecointestnet',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubKeyHash: 0x71,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xf1
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
|
||||
baseNetwork: "dogecointestnet",
|
||||
messagePrefix: '\x19Dogecoin Signed Message:\n',
|
||||
bech32: 'dogecointestnet',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubKeyHash: 0x71,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xf1
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.litecointestnet.p2wpkh = {
|
||||
baseNetwork: "litecointestnet",
|
||||
messagePrefix: '\x18Litecoin Signed Message:\n',
|
||||
bech32: 'litecointestnet',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.litecointestnet.p2wpkhInP2sh = {
|
||||
baseNetwork: "litecointestnet",
|
||||
messagePrefix: '\x18Litecoin Signed Message:\n',
|
||||
bech32: 'litecointestnet',
|
||||
bip32: {
|
||||
public: 0x043587cf,
|
||||
private: 0x04358394
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.groestlcoin.p2wpkh = {
|
||||
baseNetwork: "groestlcoin",
|
||||
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||
bech32: 'grs',
|
||||
bip32: {
|
||||
public: 0x04b24746,
|
||||
private: 0x04b2430c
|
||||
},
|
||||
pubKeyHash: 0x24,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.groestlcointestnet.p2wpkh = {
|
||||
baseNetwork: "groestlcointestnet",
|
||||
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||
bech32: 'tgrs',
|
||||
bip32: {
|
||||
public: 0x045f1cf6,
|
||||
private: 0x045f18bc
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.groestlcoin.p2wpkhInP2sh = {
|
||||
baseNetwork: "groestlcoin",
|
||||
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||
bech32: 'grs',
|
||||
bip32: {
|
||||
public: 0x049d7cb2,
|
||||
private: 0x049d7878
|
||||
},
|
||||
pubKeyHash: 0x24,
|
||||
scriptHash: 0x05,
|
||||
wif: 0x80,
|
||||
};
|
||||
|
||||
libs.bitcoin.networks.groestlcointestnet.p2wpkhInP2sh = {
|
||||
baseNetwork: "groestlcointestnet",
|
||||
messagePrefix: '\x19GroestlCoin Signed Message:\n',
|
||||
bech32: 'tgrs',
|
||||
bip32: {
|
||||
public: 0x044a5262,
|
||||
private: 0x044a4e28
|
||||
},
|
||||
pubKeyHash: 0x6f,
|
||||
scriptHash: 0xc4,
|
||||
wif: 0xef
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -26,13 +26,13 @@ var sjcl = {
|
||||
|
||||
/** @namespace Key exchange functions. Right now only SRP is implemented. */
|
||||
keyexchange: {},
|
||||
|
||||
|
||||
/** @namespace Block cipher modes of operation. */
|
||||
mode: {},
|
||||
|
||||
/** @namespace Miscellaneous. HMAC and PBKDF2. */
|
||||
misc: {},
|
||||
|
||||
|
||||
/**
|
||||
* @namespace Bit array encoders and decoders.
|
||||
*
|
||||
@@ -43,7 +43,7 @@ var sjcl = {
|
||||
* the method names are "fromBits" and "toBits".
|
||||
*/
|
||||
codec: {},
|
||||
|
||||
|
||||
/** @namespace Exceptions. */
|
||||
exception: {
|
||||
/** @constructor Ciphertext is corrupt. */
|
||||
@@ -51,13 +51,13 @@ var sjcl = {
|
||||
this.toString = function() { return "CORRUPT: "+this.message; };
|
||||
this.message = message;
|
||||
},
|
||||
|
||||
|
||||
/** @constructor Invalid parameter. */
|
||||
invalid: function(message) {
|
||||
this.toString = function() { return "INVALID: "+this.message; };
|
||||
this.message = message;
|
||||
},
|
||||
|
||||
|
||||
/** @constructor Bug or missing feature in SJCL. @constructor */
|
||||
bug: function(message) {
|
||||
this.toString = function() { return "BUG: "+this.message; };
|
||||
@@ -159,7 +159,7 @@ sjcl.bitArray = {
|
||||
if (a1.length === 0 || a2.length === 0) {
|
||||
return a1.concat(a2);
|
||||
}
|
||||
|
||||
|
||||
var last = a1[a1.length-1], shift = sjcl.bitArray.getPartial(last);
|
||||
if (shift === 32) {
|
||||
return a1.concat(a2);
|
||||
@@ -245,7 +245,7 @@ sjcl.bitArray = {
|
||||
_shiftRight: function (a, shift, carry, out) {
|
||||
var i, last2=0, shift2;
|
||||
if (out === undefined) { out = []; }
|
||||
|
||||
|
||||
for (; shift >= 32; shift -= 32) {
|
||||
out.push(carry);
|
||||
carry = 0;
|
||||
@@ -253,7 +253,7 @@ sjcl.bitArray = {
|
||||
if (shift === 0) {
|
||||
return out.concat(a);
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<a.length; i++) {
|
||||
out.push(carry | a[i]>>>shift);
|
||||
carry = a[i] << (32-shift);
|
||||
@@ -263,7 +263,7 @@ sjcl.bitArray = {
|
||||
out.push(sjcl.bitArray.partial(shift+shift2 & 31, (shift + shift2 > 32) ? carry : out.pop(),1));
|
||||
return out;
|
||||
},
|
||||
|
||||
|
||||
/** xor a block of 4 words together.
|
||||
* @private
|
||||
*/
|
||||
@@ -295,7 +295,7 @@ sjcl.bitArray = {
|
||||
* @author Mike Hamburg
|
||||
* @author Dan Boneh
|
||||
*/
|
||||
|
||||
|
||||
/** @namespace UTF-8 strings */
|
||||
sjcl.codec.utf8String = {
|
||||
/** Convert from a bitArray to a UTF-8 string. */
|
||||
@@ -310,7 +310,7 @@ sjcl.codec.utf8String = {
|
||||
}
|
||||
return decodeURIComponent(escape(out));
|
||||
},
|
||||
|
||||
|
||||
/** Convert from a UTF-8 string to a bitArray. */
|
||||
toBits: function (str) {
|
||||
str = unescape(encodeURIComponent(str));
|
||||
@@ -412,7 +412,7 @@ sjcl.hash.sha512.prototype = {
|
||||
* @constant
|
||||
*/
|
||||
blockSize: 1024,
|
||||
|
||||
|
||||
/**
|
||||
* Reset the hash state.
|
||||
* @return this
|
||||
@@ -423,7 +423,7 @@ sjcl.hash.sha512.prototype = {
|
||||
this._length = 0;
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Input several words to the hash.
|
||||
* @param {bitArray|String} data the data to hash.
|
||||
@@ -441,7 +441,7 @@ sjcl.hash.sha512.prototype = {
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Complete hashing and output the hash value.
|
||||
* @return {bitArray} The hash value, an array of 16 big-endian words.
|
||||
@@ -736,12 +736,12 @@ sjcl.misc.hmac = function (key, Hash) {
|
||||
if (key.length > bs) {
|
||||
key = Hash.hash(key);
|
||||
}
|
||||
|
||||
|
||||
for (i=0; i<bs; i++) {
|
||||
exKey[0][i] = key[i]^0x36363636;
|
||||
exKey[1][i] = key[i]^0x5C5C5C5C;
|
||||
}
|
||||
|
||||
|
||||
this._baseHash[0].update(exKey[0]);
|
||||
this._baseHash[1].update(exKey[1]);
|
||||
this._resultHash = new Hash(this._baseHash[0]);
|
||||
@@ -804,34 +804,34 @@ sjcl.misc.hmac.prototype.digest = function () {
|
||||
*/
|
||||
sjcl.misc.pbkdf2 = function (password, salt, count, length, Prff) {
|
||||
count = count || 1000;
|
||||
|
||||
|
||||
if (length < 0 || count < 0) {
|
||||
throw sjcl.exception.invalid("invalid params to pbkdf2");
|
||||
}
|
||||
|
||||
|
||||
if (typeof password === "string") {
|
||||
password = sjcl.codec.utf8String.toBits(password);
|
||||
}
|
||||
|
||||
|
||||
if (typeof salt === "string") {
|
||||
salt = sjcl.codec.utf8String.toBits(salt);
|
||||
}
|
||||
|
||||
|
||||
Prff = Prff || sjcl.misc.hmac;
|
||||
|
||||
|
||||
var prf = new Prff(password),
|
||||
u, ui, i, j, k, out = [], b = sjcl.bitArray;
|
||||
|
||||
for (k = 1; 32 * out.length < (length || 1); k++) {
|
||||
u = ui = prf.encrypt(b.concat(salt,[k]));
|
||||
|
||||
|
||||
for (i=1; i<count; i++) {
|
||||
ui = prf.encrypt(ui);
|
||||
for (j=0; j<ui.length; j++) {
|
||||
u[j] ^= ui[j];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
out = out.concat(u);
|
||||
}
|
||||
|
||||
@@ -890,7 +890,7 @@ sjcl.hash.sha256.prototype = {
|
||||
* @constant
|
||||
*/
|
||||
blockSize: 512,
|
||||
|
||||
|
||||
/**
|
||||
* Reset the hash state.
|
||||
* @return this
|
||||
@@ -901,7 +901,7 @@ sjcl.hash.sha256.prototype = {
|
||||
this._length = 0;
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Input several words to the hash.
|
||||
* @param {bitArray|String} data the data to hash.
|
||||
@@ -919,7 +919,7 @@ sjcl.hash.sha256.prototype = {
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Complete hashing and output the hash value.
|
||||
* @return {bitArray} The hash value, an array of 8 big-endian words.
|
||||
@@ -929,12 +929,12 @@ sjcl.hash.sha256.prototype = {
|
||||
|
||||
// Round out and push the buffer
|
||||
b = sjcl.bitArray.concat(b, [sjcl.bitArray.partial(1,1)]);
|
||||
|
||||
|
||||
// Round out the buffer to a multiple of 16 words, less the 2 length words.
|
||||
for (i = b.length + 2; i & 15; i++) {
|
||||
b.push(0);
|
||||
}
|
||||
|
||||
|
||||
// append the length
|
||||
b.push(Math.floor(this._length / 0x100000000));
|
||||
b.push(this._length | 0);
|
||||
@@ -955,7 +955,7 @@ sjcl.hash.sha256.prototype = {
|
||||
/*
|
||||
_init:[0x6a09e667,0xbb67ae85,0x3c6ef372,0xa54ff53a,0x510e527f,0x9b05688c,0x1f83d9ab,0x5be0cd19],
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* The SHA-256 hash key, to be precomputed.
|
||||
* @private
|
||||
@@ -990,7 +990,7 @@ sjcl.hash.sha256.prototype = {
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (i<8) {
|
||||
this._init[i] = frac(Math.pow(prime, 1/2));
|
||||
}
|
||||
@@ -998,13 +998,13 @@ sjcl.hash.sha256.prototype = {
|
||||
i++;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Perform one cycle of SHA-256.
|
||||
* @param {bitArray} words one block of words.
|
||||
* @private
|
||||
*/
|
||||
_block:function (words) {
|
||||
_block:function (words) {
|
||||
var i, tmp, a, b,
|
||||
w = words.slice(0),
|
||||
h = this._h,
|
||||
@@ -1032,13 +1032,13 @@ sjcl.hash.sha256.prototype = {
|
||||
} else {
|
||||
a = w[(i+1 ) & 15];
|
||||
b = w[(i+14) & 15];
|
||||
tmp = w[i&15] = ((a>>>7 ^ a>>>18 ^ a>>>3 ^ a<<25 ^ a<<14) +
|
||||
tmp = w[i&15] = ((a>>>7 ^ a>>>18 ^ a>>>3 ^ a<<25 ^ a<<14) +
|
||||
(b>>>17 ^ b>>>19 ^ b>>>10 ^ b<<15 ^ b<<13) +
|
||||
w[i&15] + w[(i+9) & 15]) | 0;
|
||||
}
|
||||
|
||||
|
||||
tmp = (tmp + h7 + (h4>>>6 ^ h4>>>11 ^ h4>>>25 ^ h4<<26 ^ h4<<21 ^ h4<<7) + (h6 ^ h4&(h5^h6)) + k[i]); // | 0;
|
||||
|
||||
|
||||
// shift register
|
||||
h7 = h6; h6 = h5; h5 = h4;
|
||||
h4 = h3 + tmp | 0;
|
||||
|
||||
445
src/js/unorm.js
445
src/js/unorm.js
File diff suppressed because one or more lines are too long
14
src/js/wordlist_czech.js
Normal file
14
src/js/wordlist_czech.js
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -73,16 +73,23 @@ else if (browser == "chrome") {
|
||||
|
||||
// Helper functions
|
||||
|
||||
function testNetwork(done, params) {
|
||||
function testNetwork(done, params, comparePub = false) {
|
||||
var phrase = params.phrase || 'abandon abandon ability';
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys(phrase);
|
||||
selectNetwork(params.selectText);
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
getFirstAddress(function(address) {
|
||||
expect(address).toBe(params.firstAddress);
|
||||
done();
|
||||
});
|
||||
if (!comparePub) {
|
||||
getFirstAddress(function(address) {
|
||||
expect(address).toBe(params.firstAddress);
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
getFirstPublicKey(function(pubkey) {
|
||||
expect(pubkey).toBe(params.firstPubKey);
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -98,6 +105,10 @@ function getFirstAddress(handler) {
|
||||
getFirstRowValue(handler, ".address");
|
||||
}
|
||||
|
||||
function getFirstPublicKey(handler) {
|
||||
getFirstRowValue(handler, ".pubkey");
|
||||
}
|
||||
|
||||
function getFirstPath(handler) {
|
||||
getFirstRowValue(handler, ".index");
|
||||
}
|
||||
@@ -401,6 +412,13 @@ it('Allows selection of bitcoin testnet', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of bitcoin regtest', function(done) {
|
||||
var params = {
|
||||
selectText: "BTC - Bitcoin RegTest",
|
||||
firstAddress: "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of litecoin', function(done) {
|
||||
var params = {
|
||||
selectText: "LTC - Litecoin",
|
||||
@@ -408,6 +426,13 @@ it('Allows selection of litecoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of litecoin testnet', function(done) {
|
||||
var params = {
|
||||
selectText: "LTCt - Litecoin Testnet",
|
||||
firstAddress: "mucaU5iiDaJDb69BHLeDv8JFfGiyg2nJKi",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of ripple', function(done) {
|
||||
var params = {
|
||||
selectText: "XRP - Ripple",
|
||||
@@ -416,6 +441,14 @@ it('Allows selection of ripple', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of casinocoin', function(done) {
|
||||
var params = {
|
||||
selectText: "CSC - CasinoCoin",
|
||||
firstAddress: "c3P5EUb27Pzk9dcGt4s7zQDQj4sC6Y81mT",
|
||||
phrase: "ill clump only blind unit burden thing track silver cloth review awake useful craft whale all satisfy else trophy sunset walk vanish hope valve",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of dogecoin', function(done) {
|
||||
var params = {
|
||||
selectText: "DOGE - Dogecoin",
|
||||
@@ -423,6 +456,13 @@ it('Allows selection of dogecoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of dogecoin testnet', function(done) {
|
||||
var params = {
|
||||
selectText: "DOGEt - Dogecoin Testnet",
|
||||
firstAddress: "niHnSJKHdwDyDxRMLBJrtNqpvHEsAFWe6B",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of denarius', function(done) {
|
||||
var params = {
|
||||
selectText: "DNR - Denarius",
|
||||
@@ -474,11 +514,18 @@ it('Allows selection of clam', function(done) {
|
||||
});
|
||||
it('Allows selection of crown', function(done) {
|
||||
var params = {
|
||||
selectText: "CRW - Crown",
|
||||
selectText: "CRW - Crown (Legacy)",
|
||||
firstAddress: "18pWSwSUAQdiwMHUfFZB1fM2xue9X1FqE5",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of crown', function(done) {
|
||||
var params = {
|
||||
selectText: "CRW - Crown",
|
||||
firstAddress: "CRWKnVmVhvH1KWTYe6sq8xV4dFGcFpBEEkPQ",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of dash', function(done) {
|
||||
var params = {
|
||||
selectText: "DASH - Dash",
|
||||
@@ -528,6 +575,13 @@ it('Allows selection of lkrcoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of bolivarcoin', function(done) {
|
||||
var params = {
|
||||
selectText: "BOLI - Bolivarcoin",
|
||||
firstAddress: "bbKzCAUR7hZ3nqfffy7VgrSz8LmAP3S5mK",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of peercoin', function(done) {
|
||||
var params = {
|
||||
selectText: "PPC - Peercoin",
|
||||
@@ -564,6 +618,15 @@ it('Allows selection of bitcoin cash', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
|
||||
it('Allows selection of simpleledger(SLP)', function(done) {
|
||||
var params = {
|
||||
selectText: "SLP - Simple Ledger Protocol",
|
||||
firstAddress: "simpleledger:qrtffz6ajfsn74gpur7y3epjquz42pvww5acewqmre",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
|
||||
it('Allows selection of myriadcoin', function(done) {
|
||||
var params = {
|
||||
selectText: "XMY - Myriadcoin",
|
||||
@@ -592,6 +655,20 @@ it('Allows selection of maza', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of FIX', function(done) {
|
||||
var params = {
|
||||
selectText: "FIX - FIX",
|
||||
firstAddress: "FS5MEU8fs5dUvsaSCSusV8RQtC8j2h3JEh",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of FIX testnet', function(done) {
|
||||
var params = {
|
||||
selectText: "FIX - FIX Testnet",
|
||||
firstAddress: "XpnU1HHdNG5YxvG9Rez4wjmidchxqnZaNa",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of fujicoin', function(done) {
|
||||
var params = {
|
||||
selectText: "FJC - Fujicoin",
|
||||
@@ -662,6 +739,13 @@ it('Allows selection of Asiacoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Aryacoin', function(done) {
|
||||
var params = {
|
||||
selectText: "ARYA - Aryacoin",
|
||||
firstAddress: "Abr6gX25KaU9BpwD34UfsL3A4n89NvYYSf",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Auroracoin', function(done) {
|
||||
var params = {
|
||||
selectText: "AUR - Auroracoin",
|
||||
@@ -704,6 +788,13 @@ it('Allows selection of Bitcoin Private', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Bitcoin SV', function(done) {
|
||||
var params = {
|
||||
selectText: "BSV - BitcoinSV",
|
||||
firstAddress: "1N4mgtE5yxifch9jWs7Sds6oVqxdy2t576",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Bitcoinz', function(done) {
|
||||
var params = {
|
||||
selectText: "BTCZ - Bitcoinz",
|
||||
@@ -767,6 +858,13 @@ it('Allows selection of Compcoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of CPUchain', function(done) {
|
||||
var params = {
|
||||
selectText: "CPU - CPUchain",
|
||||
firstAddress: "CWSpLpW7jS4mBHJnkz3mmL5s3yQMg93zK8",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Crave', function(done) {
|
||||
var params = {
|
||||
selectText: "CRAVE - Crave",
|
||||
@@ -830,6 +928,13 @@ it('Allows selection of Einsteinium', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of EOSIO', function(done) {
|
||||
var params = {
|
||||
selectText: "EOS - EOSIO",
|
||||
firstPubKey: "EOS692VJTBK3Rmw93onNnpnZ8ZtmE9PdxjDStArvbyzoe11QUTNoy",
|
||||
};
|
||||
testNetwork(done, params, true);
|
||||
});
|
||||
it('Allows selection of Europecoin', function(done) {
|
||||
var params = {
|
||||
selectText: "ERC - Europecoin",
|
||||
@@ -991,6 +1096,13 @@ it('Allows selection of Navcoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Nebulas', function(done) {
|
||||
var params = {
|
||||
selectText: "NAS - Nebulas",
|
||||
firstAddress: "n1PbK61DGBfDoDusLw621G6sVSMfLLHdfnm",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Neoscoin', function(done) {
|
||||
var params = {
|
||||
selectText: "NEOS - Neoscoin",
|
||||
@@ -998,6 +1110,13 @@ it('Allows selection of Neoscoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Nix', function(done) {
|
||||
var params = {
|
||||
selectText: "NIX - NIX Platform",
|
||||
firstAddress: "GgcNW2SQQXB4LWHRQTHKkQF3GzXNSLqS8u",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Neurocoin', function(done) {
|
||||
var params = {
|
||||
selectText: "NRO - Neurocoin",
|
||||
@@ -1040,6 +1159,13 @@ it('Allows selection of Omnicore', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of DeepOnion', function(done) {
|
||||
var params = {
|
||||
selectText: "ONION - DeepOnion",
|
||||
firstAddress: "DYREY7XCFXVqJ3x5UuN43k2JwD2s1kif48",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Pesobit', function(done) {
|
||||
var params = {
|
||||
selectText: "PSB - Pesobit",
|
||||
@@ -1075,6 +1201,13 @@ it('Allows selection of Putincoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Rapids', function(done) {
|
||||
var params = {
|
||||
selectText: "RPD - Rapids",
|
||||
firstAddress: "Ri8XxUdZaXS5LqxmFJcFEjFinkaMbmhSUp",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Ravencoin', function(done) {
|
||||
var params = {
|
||||
selectText: "RVN - Ravencoin",
|
||||
@@ -1166,6 +1299,20 @@ it('Allows selection of Toa', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of TWINS', function(done) {
|
||||
var params = {
|
||||
selectText: "TWINS - TWINS",
|
||||
firstAddress: "WPpJnfLLubNmF7HLNxg8d8zH5haxn4wri8",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of TWINS testnet', function(done) {
|
||||
var params = {
|
||||
selectText: "TWINS - TWINS Testnet",
|
||||
firstAddress: "XpnU1HHdNG5YxvG9Rez4wjmidchxqnZaNa",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Ultimatesecurecash', function(done) {
|
||||
var params = {
|
||||
selectText: "USC - Ultimatesecurecash",
|
||||
@@ -1215,6 +1362,13 @@ it('Allows selection of Vpncoin', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of VeChain', function(done) {
|
||||
var params = {
|
||||
selectText: "VET - VeChain",
|
||||
firstAddress: "0xdba55B1B6070f3a733D5eDFf35F0da4A00E455F2",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Whitecoin', function(done) {
|
||||
var params = {
|
||||
selectText: "XWC - Whitecoin",
|
||||
@@ -1250,9 +1404,9 @@ it('Allows selection of Zclassic', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Zencash', function(done) {
|
||||
it('Allows selection of Horizen', function(done) {
|
||||
var params = {
|
||||
selectText: "ZEN - Zencash",
|
||||
selectText: "ZEN - Horizen",
|
||||
firstAddress: "znWh9XASyW2dZq5tck84wFjiwuqVysi7q3p",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
@@ -1285,6 +1439,14 @@ it('Allows selection of MIX', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Monkey Project', function(done) {
|
||||
var params = {
|
||||
selectText: "MONK - Monkey Project",
|
||||
firstAddress: "MnLrcnnUzKnf7TzufjRe5DLZqQJz18oYyu",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
|
||||
it('Allows selection of Musicoin', function(done) {
|
||||
var params = {
|
||||
selectText: "MUSIC - Musicoin",
|
||||
@@ -1315,11 +1477,18 @@ it('Allows selection of Callisto', function(done) {
|
||||
});
|
||||
it('Allows selection of HUSH', function(done) {
|
||||
var params = {
|
||||
selectText: "HUSH - Hush",
|
||||
selectText: "HUSH - Hush (Legacy)",
|
||||
firstAddress: "t1g6rLXUnJaiJuu4q4zmJjoa9Gk4fwKpiuA",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of HUSH3', function(done) {
|
||||
var params = {
|
||||
selectText: "HUSH - Hush3",
|
||||
firstAddress: "RXWSQhwvw5jHPGP8bjwJhWoRnMLBnuPDKD",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of ExchangeCoin', function(done) {
|
||||
var params = {
|
||||
selectText: "EXCC - ExchangeCoin",
|
||||
@@ -1397,6 +1566,76 @@ it('Allows selection of BlockStamp', function(done) {
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of DEXON', function(done) {
|
||||
var params = {
|
||||
selectText: "DXN - DEXON",
|
||||
firstAddress: "0x136a58788033E028CCd740FbDec6734358DB56Ec",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Ellaism', function(done) {
|
||||
var params = {
|
||||
selectText: "ELLA - Ellaism",
|
||||
firstAddress: "0xa8B0BeA09eeBc41062308546a01d6E544277e2Ca",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Ethersocial Network', function(done) {
|
||||
var params = {
|
||||
selectText: "ESN - Ethersocial Network",
|
||||
firstAddress: "0x6EE99Be2A0C7F887a71e21C8608ACF0aa0D2b767",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Stellar', function(done) {
|
||||
var params = {
|
||||
selectText: "XLM - Stellar",
|
||||
firstAddress: "GCUK3NYYUXA2QGN6KU5RR36WAKN3Y5EANZV65XNAWN4XM4CHQ3G4DMO2",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Wagerr', function(done) {
|
||||
var params = {
|
||||
selectText: "WGR - Wagerr",
|
||||
firstAddress: "WYiVgQU39VcQxcnacoCiaZHZZLjDCJoS95",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Groestlcoin', function(done) {
|
||||
var params = {
|
||||
selectText: "GRS - Groestlcoin",
|
||||
firstAddress: "FZycsFvZ1eH1hbtyjBpAgJSukVw1bN6PBN",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Groestlcoin Testnet', function(done) {
|
||||
var params = {
|
||||
selectText: "GRS - Groestlcoin Testnet",
|
||||
firstAddress: "mucaU5iiDaJDb69BHLeDv8JFfGiygRPne9",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Elastos', function(done) {
|
||||
var params = {
|
||||
selectText: "ELA - Elastos",
|
||||
firstAddress: "EMccDcsn3SwPDcfeQMf3w7utqi8ioWYtkg",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Energyweb', function(done) {
|
||||
var params = {
|
||||
selectText: "EWT - EnergyWeb",
|
||||
firstAddress: "0x22171474844Fc7E8E99A3A69CCf1eDb5574FdD4c",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
it('Allows selection of Thought', function(done) {
|
||||
var params = {
|
||||
selectText: "THT - Thought",
|
||||
firstAddress: "4B1Bh9GibDarFQrhtYU8krpc7WSjgGfYvo",
|
||||
};
|
||||
testNetwork(done, params);
|
||||
});
|
||||
|
||||
// BIP39 seed is set from phrase
|
||||
it('Sets the bip39 seed from the prhase', function(done) {
|
||||
@@ -1770,11 +2009,7 @@ it('Allows the user to set the BIP32 root key', function(done) {
|
||||
});
|
||||
|
||||
// Setting BIP32 root key clears the existing phrase, passphrase and seed
|
||||
// TODO this doesn't work in selenium with chrome
|
||||
it('Confirms the existing phrase should be cleared', function(done) {
|
||||
if (browser == "chrome") {
|
||||
pending("Selenium + Chrome headless bug for alert, see https://stackoverflow.com/q/45242264");
|
||||
}
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys('A non-blank but invalid value');
|
||||
driver.findElement(By.css('.root-key'))
|
||||
@@ -1788,11 +2023,7 @@ it('Confirms the existing phrase should be cleared', function(done) {
|
||||
});
|
||||
|
||||
// Clearing of phrase, passphrase and seed can be cancelled by user
|
||||
// TODO this doesn't work in selenium with chrome
|
||||
it('Allows the clearing of the phrase to be cancelled', function(done) {
|
||||
if (browser == "chrome") {
|
||||
pending("Selenium + Chrome headless bug for alert, see https://stackoverflow.com/q/45242264");
|
||||
}
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys('abandon abandon ability');
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
@@ -1977,6 +2208,7 @@ it('Ignores excess whitespace in the mnemonic', function(done) {
|
||||
|
||||
// Github Issue 23: Part 1: Use correct derivation path when changing tabs
|
||||
// https://github.com/iancoleman/bip39/issues/23
|
||||
// This test was failing for default timeout of 5000ms so changed it to +10s
|
||||
it('Uses the correct derivation path when changing tabs', function(done) {
|
||||
// 1) and 2) set the phrase
|
||||
driver.findElement(By.css('.phrase'))
|
||||
@@ -2001,7 +2233,7 @@ it('Uses the correct derivation path when changing tabs', function(done) {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}, generateDelay + 10000);
|
||||
|
||||
// Github Issue 23 Part 2: Coin selection in derivation path
|
||||
// https://github.com/iancoleman/bip39/issues/23#issuecomment-238011920
|
||||
@@ -3461,6 +3693,106 @@ it('Can generate BIP141 addresses with P2WPKH-in-P2SH semanitcs', function(done)
|
||||
});
|
||||
});
|
||||
|
||||
it('Can generate BIP141 addresses with P2WSH semanitcs', function(done) {
|
||||
driver.findElement(By.css('#bip141-tab a'))
|
||||
.click();
|
||||
// Choose P2WSH
|
||||
driver.executeScript(function() {
|
||||
$(".bip141-semantics option[selected]").removeAttr("selected");
|
||||
$(".bip141-semantics option").filter(function(i,e) {
|
||||
return $(e).html() == "P2WSH (1-of-1 multisig)";
|
||||
}).prop("selected", true);
|
||||
$(".bip141-semantics").trigger("change");
|
||||
});
|
||||
driver.findElement(By.css(".phrase"))
|
||||
.sendKeys("abandon abandon ability");
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css("#root-key"))
|
||||
.getAttribute("value")
|
||||
.then(function(rootKey) {
|
||||
expect(rootKey).toBe("ZprvAhadJRUYsNge9uHspaggavxU1BUQ8QwfT4Z9UGq5sKF2mSt1mVy8EckLAaoBdmLHyP5eYDJ3LxtmzMNnLg2MRFe7QN2ueF4NCH4s5PrCDR6");
|
||||
getFirstAddress(function(address) {
|
||||
expect(address).toBe("bc1q2qhee847pv438tgg8hc7mjy38n8dklleshettn344l0tgs0kj5hskz9p9r");
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Can generate BIP141 addresses with P2WSH-in-P2SH semanitcs', function(done) {
|
||||
driver.findElement(By.css('#bip141-tab a'))
|
||||
.click();
|
||||
// Choose P2WSH-in-P2SH
|
||||
driver.executeScript(function() {
|
||||
$(".bip141-semantics option[selected]").removeAttr("selected");
|
||||
$(".bip141-semantics option").filter(function(i,e) {
|
||||
return $(e).html() == "P2WSH nested in P2SH (1-of-1 multisig)";
|
||||
}).prop("selected", true);
|
||||
$(".bip141-semantics").trigger("change");
|
||||
});
|
||||
driver.findElement(By.css(".phrase"))
|
||||
.sendKeys("abandon abandon ability");
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css("#root-key"))
|
||||
.getAttribute("value")
|
||||
.then(function(rootKey) {
|
||||
expect(rootKey).toBe("YprvANkMzkodih9AJc6kzDu4NqrxqDKxBnxAXx2vgswCVJs9iM4nWqoZcZ6C9NqbdrgNZjxqnjhUtJYE74mDcycLd1xWY2LV4LEsvZ1DgqxuAKe");
|
||||
getFirstAddress(function(address) {
|
||||
expect(address).toBe("343DLC4vGDyHBbBr9myL8zzZA1MdN9TM1G");
|
||||
done();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Uses Vprv for bitcoin testnet p2wsh', function(done) {
|
||||
selectNetwork("BTC - Bitcoin Testnet");
|
||||
driver.findElement(By.css('#bip141-tab a'))
|
||||
.click()
|
||||
// Choose P2WSH
|
||||
driver.executeScript(function() {
|
||||
$(".bip141-semantics option[selected]").removeAttr("selected");
|
||||
$(".bip141-semantics option").filter(function(i,e) {
|
||||
return $(e).html() == "P2WSH (1-of-1 multisig)";
|
||||
}).prop("selected", true);
|
||||
$(".bip141-semantics").trigger("change");
|
||||
});
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys('abandon abandon ability');
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css('.root-key'))
|
||||
.getAttribute("value")
|
||||
.then(function(path) {
|
||||
expect(path).toBe("Vprv16YtLrHXxePM5ja5hXQbiJs5JKDAc4WcaXo5rZcrVMU6bMhUg1oY7fpPku3i819gvMcHvq1h8aELDsyfCEs19vj1Q3iDHRrESWyJConkoT1");
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Uses Uprv for bitcoin testnet p2wsh-in-p2sh', function(done) {
|
||||
selectNetwork("BTC - Bitcoin Testnet");
|
||||
driver.findElement(By.css('#bip141-tab a'))
|
||||
.click()
|
||||
// Choose P2WSH-in-P2SH
|
||||
driver.executeScript(function() {
|
||||
$(".bip141-semantics option[selected]").removeAttr("selected");
|
||||
$(".bip141-semantics option").filter(function(i,e) {
|
||||
return $(e).html() == "P2WSH nested in P2SH (1-of-1 multisig)";
|
||||
}).prop("selected", true);
|
||||
$(".bip141-semantics").trigger("change");
|
||||
});
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys('abandon abandon ability');
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css('.root-key'))
|
||||
.getAttribute("value")
|
||||
.then(function(path) {
|
||||
expect(path).toBe("Uprv95RJn67y7xyEuRLHenkZYVUx9LkARJzAsVx3ZJMeyHMdVwosWD9K8JTe4Z1FeE4gwBVcnqKF3f82ZvJxkBxHS5E74fYnigxvqeke8ZV3Fp2");
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('Can generate BIP141 addresses with P2WPKH semanitcs', function(done) {
|
||||
// This result tested against bitcoinjs-lib test spec for segwit address
|
||||
// using the first private key of this mnemonic and default path m/0
|
||||
@@ -3859,6 +4191,27 @@ it('Shows litecoin BIP49 addresses', function(done) {
|
||||
});
|
||||
});
|
||||
|
||||
it('Shows Groestlcoin BIP49 addresses', function(done) {
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys('abandon abandon ability');
|
||||
selectNetwork("GRS - Groestlcoin");
|
||||
driver.findElement(By.css('#bip49-tab a'))
|
||||
.click()
|
||||
// bip49 addresses are shown
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css('#bip49 .available'))
|
||||
.getAttribute("class")
|
||||
.then(function(classes) {
|
||||
expect(classes).not.toContain("hidden");
|
||||
// check first address
|
||||
getFirstAddress(function(address) {
|
||||
expect(address).toBe("3HXSCZwCypLyixMsF4Z1sN49noJtrm8gnX");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Can use root keys to generate segwit table rows', function(done) {
|
||||
// segwit uses ypub / zpub instead of xpub but the root key should still
|
||||
// be valid regardless of the encoding used to import that key.
|
||||
@@ -3878,4 +4231,114 @@ it('Can use root keys to generate segwit table rows', function(done) {
|
||||
});
|
||||
});
|
||||
|
||||
// Pull Request 271
|
||||
// Allow converting mnemonic back to raw entropy value
|
||||
it('Converts mnemonics into raw entropy', function(done) {
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys('abandon abandon about');
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css('.use-entropy'))
|
||||
.click();
|
||||
driver.findElement(By.css('.entropy'))
|
||||
.getAttribute("value")
|
||||
.then(function(entropy) {
|
||||
expect(entropy).toBe("00000001");
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.getAttribute("value")
|
||||
.then(function(phrase) {
|
||||
expect(phrase).toBe("abandon abandon about");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Pull Request 279
|
||||
// Added Split Phrase Card Output
|
||||
it('Shows split prase cards', function(done) {
|
||||
var originalPhrase = "ugly charge strong giant once anchor capable october thumb inject dwarf legal alley mixture shoot";
|
||||
var originalWords = originalPhrase.split(' ');
|
||||
driver.findElement(By.css('.phrase'))
|
||||
.sendKeys(originalPhrase);
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
driver.findElement(By.css('.phraseSplit'))
|
||||
.getAttribute("value")
|
||||
.then(function(cardsStr) {
|
||||
var cards = cardsStr.split("\n");
|
||||
expect(cards.length).toBe(3);
|
||||
// test all 2-of-3 combos can be used to form full phrase
|
||||
var combos = [[0,1],[0,2],[1,2]];
|
||||
for (var i=0; i<combos.length; i++) {
|
||||
var combo = combos[i];
|
||||
var a = combo[0];
|
||||
var b = combo[1];
|
||||
var phrase = cards[a] + " " + cards[b];
|
||||
// check all original words are present
|
||||
for (var j=0; j<originalWords.length; j++) {
|
||||
var originalWord = originalWords[j];
|
||||
expect(phrase).toContain(originalWord);
|
||||
}
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// It allows manually specifying the entropy type
|
||||
it('Allows entropy type to be manually selected', function(done) {
|
||||
driver.findElement(By.css('.use-entropy'))
|
||||
.click();
|
||||
// use decimal entropy
|
||||
driver.findElement(By.css('.entropy'))
|
||||
.sendKeys("91");
|
||||
// manually change to binary entropy
|
||||
driver.executeScript(function() {
|
||||
$(".entropy-container input[value='binary']").click();
|
||||
});
|
||||
driver.sleep(entropyFeedbackDelay).then(function() {
|
||||
driver.findElement(By.css('.entropy-container'))
|
||||
.getText()
|
||||
.then(function(text) {
|
||||
// overide 91 to be just 1
|
||||
var key = "Filtered Entropy";
|
||||
var value = "1";
|
||||
var reText = key + "\\s+" + value;
|
||||
var re = new RegExp(reText);
|
||||
expect(text).toMatch(re);
|
||||
// overide automatic decimal to binary
|
||||
var key = "Entropy Type";
|
||||
var value = "binary";
|
||||
var reText = key + "\\s+" + value;
|
||||
var re = new RegExp(reText);
|
||||
expect(text).toMatch(re);
|
||||
// overide 2 events to 1
|
||||
var key = "Event Count";
|
||||
var value = 1;
|
||||
var reText = key + "\\s+" + value;
|
||||
var re = new RegExp(reText);
|
||||
expect(text).toMatch(re);
|
||||
// overide log2(10)*2 bits to 1 bit
|
||||
var key = "Total Bits";
|
||||
var value = 1;
|
||||
var reText = key + "\\s+" + value;
|
||||
var re = new RegExp(reText);
|
||||
expect(text).toMatch(re);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// https://github.com/iancoleman/bip39/issues/388
|
||||
// Make field for bip39 seed editable
|
||||
it('Generates addresses when seed is set', function(done) {
|
||||
driver.findElement(By.css('.seed'))
|
||||
.sendKeys("20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3");
|
||||
driver.sleep(generateDelay).then(function() {
|
||||
getFirstAddress(function(address) {
|
||||
expect(address).toBe("1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user