Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.digest()
.toString('hex')
const hmacDigestHash = crypto
.createHash('sha256')
.update(hmacDigest)
.digest()
.toString('hex')
if (hmacSigHash !== hmacDigestHash) {
// not authentic
throw new Error('Wrong password (HMAC mismatch)')
}
const mnemonic = await denormalizeMnemonic(plaintext)
if (!bip39.validateMnemonic(mnemonic)) {
throw new Error('Wrong password (invalid plaintext)')
}
return mnemonic
}
switch (numberOfWords) {
case 12:
return 128;
case 18:
return 160;
case 21:
return 224;
case 24:
return 256;
default:
return 128;
}
}(arguments[0]));
this.seed = bip39.generateMnemonic(strength);
} else if (typeof (arguments[0]) === 'string') {
if (bip39.validateMnemonic(arguments[0])) {
this.seed = arguments[0];
} else {
this.seed = null;
console.log('The input is not a set of valid seed phrases.');
}
} else {
this.seed = null;
console.log('The number of seed phrases must be one of 12, 18, 21, 24.');
}
} else {
console.log('The argument must be empty, number of seed phrases, or valid seed phrases.');
}
return this.seed;
}
default:
logger.fatal('Unsupported blockchain:', LNSWAP_CHAIN);
process.exit();
}
const bitcoinjsNetwork = networks[LNSWAP_CHAIN];
const [partA, partB] = LNSWAP_CHAIN_RPC_API.split('@');
const [rpcUsername, rpcPassword] = partA.split(':');
const [rpcHost, rpcPort] = partB.split(':');
if (!LNSWAP_CLAIM_ADDRESS) {
logger.fatal('Please set variable LNSWAP_CLAIM_ADDRESS');
process.exit();
}
if (!validateMnemonic(LNSWAP_CLAIM_BIP39_SEED)) {
logger.fatal('ExpectedValidMnemonic');
process.exit();
}
const seed = mnemonicToSeed(LNSWAP_CLAIM_BIP39_SEED);
const root = HDNode.fromSeedBuffer(seed, bitcoinjsNetwork);
const zmqRawBlockSocket = zmq.socket('sub');
const zmqRawTxSocket = zmq.socket('sub');
let currentBlockHeight = 0;
function getAddressesFromOuts(outs) {
const outputAddresses = [];
outs.forEach(({ script, value }, index) => {
try {
const address = bitcoin.address.fromOutputScript(script, bitcoinjsNetwork);
(function() {
try {
var mnemonic = data.mnemonic;
var passphrase = data.passphrase;
if (!bip39.validateMnemonic(mnemonic)) {
e = new Error('Invalid passphrase');
e.id = data.id;
throw e;
}
var seed = bip39.mnemonicToSeedHex(mnemonic, passphrase);
self.postMessage({id: data.id, seed: seed, mnemonic: mnemonic});
} catch (e) {
e.id = data.id;
throw e;
}
})();
break;
static importWithMnemonic(
label: string,
mnemonic: string,
password: string,
params?: ScryptParams
): Account {
mnemonic = mnemonic.trim();
if (!bip39.validateMnemonic(mnemonic)) {
throw ERROR_CODE.INVALID_PARAMS;
}
const seed = bip39.mnemonicToSeedHex(mnemonic);
const hdkey = HDKey.fromMasterSeed(Buffer.from(seed, 'hex'));
const pri = hdkey.derive(ONT_BIP44_PATH);
const key = Buffer.from(pri.privateKey).toString('hex');
const privateKey = new PrivateKey(key);
const account = Account.create(privateKey, password, label, params);
return account;
}
private selectWord = (word: string): void => {
const { mnemonic, markedWord } = this.state
const isLastWord = markedWord === mnemonic.length
mnemonic[markedWord] = word
const mnemonicValid =
mnemonic.length === 12 && validateMnemonic(mnemonic.join(' '))
if (mnemonicValid && this.textInput) {
this.textInput.blur()
}
this.setState({
inputValue: isLastWord ? '' : word,
mnemonic,
markedWord: isLastWord ? mnemonic.length : markedWord,
isMnemonicValid: mnemonicValid,
suggestions: [],
inputState: WordState.editing,
})
}
export function validateMnemonics(mnemonic: string, wordlist: Array = bip39.wordlists.EN): Boolean {
return mnemonic && bip39.validateMnemonic(mnemonic, wordlist);
}
static determineWordList(mnemonic: string): any[] {
for (const list of BIP39Signer.wordLists()) {
if (bip39.validateMnemonic(BIP39Signer.prepareMnemonic(mnemonic), list)) {
return list
}
}
}
hasInvalidWords() {
return !bip39.validateMnemonic(this.state.wordList);
}