mirror of
https://github.com/status-im/bip39.git
synced 2025-02-10 19:46:46 +00:00
move helper function definitions before usage
This commit is contained in:
parent
f6bcccc258
commit
f55f62f1a5
24
index.js
24
index.js
@ -5,6 +5,11 @@ var randomBytes = require('randombytes')
|
||||
// use unorm until String.prototype.normalize gets better browser support
|
||||
var unorm = require('unorm')
|
||||
|
||||
function lpad (str, padString, length) {
|
||||
while (str.length < length) str = padString + str
|
||||
return str
|
||||
}
|
||||
|
||||
var ENGLISH_WORDLIST = require('./wordlists/english.json')
|
||||
var FRENCH_WORDLIST = require('./wordlists/french.json')
|
||||
var ITALIAN_WORDLIST = require('./wordlists/italian.json')
|
||||
@ -106,6 +111,12 @@ function validateMnemonic (mnemonic, wordlist) {
|
||||
return true
|
||||
}
|
||||
|
||||
function bytesToBinary (bytes) {
|
||||
return bytes.map(function (x) {
|
||||
return lpad(x.toString(2), '0', 8)
|
||||
}).join('')
|
||||
}
|
||||
|
||||
function checksumBits (entropyBuffer) {
|
||||
var hash = createHash('sha256').update(entropyBuffer).digest()
|
||||
|
||||
@ -116,19 +127,6 @@ function checksumBits (entropyBuffer) {
|
||||
return bytesToBinary([].slice.call(hash)).slice(0, CS)
|
||||
}
|
||||
|
||||
// =========== helper methods from bitcoinjs-lib ========
|
||||
|
||||
function bytesToBinary (bytes) {
|
||||
return bytes.map(function (x) {
|
||||
return lpad(x.toString(2), '0', 8)
|
||||
}).join('')
|
||||
}
|
||||
|
||||
function lpad (str, padString, length) {
|
||||
while (str.length < length) str = padString + str
|
||||
return str
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
mnemonicToSeed: mnemonicToSeed,
|
||||
mnemonicToSeedHex: mnemonicToSeedHex,
|
||||
|
Loading…
x
Reference in New Issue
Block a user