src/crypto/cryptoHelpers.js
function(common, walletAccount, algo) {
    // Errors
    if(!common || !walletAccount || !algo) throw new Error('Missing argument !');

    let r = undefined;

    if (algo === "trezor") { // HW wallet
        r = { 'priv': '' };
        common.isHW = true;
    } else if (!common.password) {
        throw new Error('Missing argument !');
    }

    // Processing
    if (algo === "pass:6k") { // Brain wallets
        if (!walletAccount.encrypted && !walletAccount.iv) {
            // Account private key is generated simply using a passphrase so it has no encrypted and iv
            r = derivePassSha(common.password, 6000);
        } else if (!walletAccount.encrypted || !walletAccount.iv) {
            // Else if one is missing there is a problem
            //console.log("Account might be compromised, missing encrypted or iv");
            return false;
        } else {
            // Else child accounts have encrypted and iv so we decrypt
            let pass = derivePassSha(common.password, 20);
            let obj = {
                ciphertext: CryptoJS.enc.Hex.parse(walletAccount.encrypted),
                iv: convert.hex2ua(walletAccount.iv),
                key: convert.hex2ua(pass.priv)
            };
            let d = decrypt(obj);
            r = { 'priv': d };
        }
    } else if (algo === "pass:bip32") { // Wallets from PRNG
        let pass = derivePassSha(common.password, 20);
        let obj = {
            ciphertext: CryptoJS.enc.Hex.parse(walletAccount.encrypted),
            iv: convert.hex2ua(walletAccount.iv),
            key: convert.hex2ua(pass.priv)
        };
        let d = decrypt(obj);
        r = { 'priv': d };
    } else if (algo === "pass:enc") { // Private Key wallets
        let pass = derivePassSha(common.password, 20);
        let obj = {
            ciphertext: CryptoJS.enc.Hex.parse(walletAccount.encrypted),
            iv: convert.hex2ua(walletAccount.iv),
            key: convert.hex2ua(pass.priv)
        };
        let d = decrypt(obj);
        r = { 'priv': d };
    } else if (!r) {
        //console.log("Unknown wallet encryption method");
        return false;
    }
    // Result
    common.privateKey = r.priv;
    return true;
}
function(common, walletAccount, algo) {
    // Errors
    if(!common || !walletAccount || !algo) throw new Error('Missing argument !');

    let r = undefined;

    if (algo === "trezor") { // HW wallet
        r = { 'priv': '' };
        common.isHW = true;
    } else if (!common.password) {
        throw new Error('Missing argument !');
    }

    // Processing
    if (algo === "pass:6k") { // Brain wallets
        if (!walletAccount.encrypted && !walletAccount.iv) {
            // Account private key is generated simply using a passphrase so it has no encrypted and iv
            r = derivePassSha(common.password, 6000);
        } else if (!walletAccount.encrypted || !walletAccount.iv) {
            // Else if one is missing there is a problem
            //console.log("Account might be compromised, missing encrypted or iv");
            return false;
        } else {
            // Else child accounts have encrypted and iv so we decrypt
            let pass = derivePassSha(common.password, 20);
            let obj = {
                ciphertext: CryptoJS.enc.Hex.parse(walletAccount.encrypted),
                iv: convert.hex2ua(walletAccount.iv),
                key: convert.hex2ua(pass.priv)
            };
            let d = decrypt(obj);
            r = { 'priv': d };
        }
    } else if (algo === "pass:bip32") { // Wallets from PRNG
        let pass = derivePassSha(common.password, 20);
        let obj = {
            ciphertext: CryptoJS.enc.Hex.parse(walletAccount.encrypted),
            iv: convert.hex2ua(walletAccount.iv),
            key: convert.hex2ua(pass.priv)
        };
        let d = decrypt(obj);
        r = { 'priv': d };
    } else if (algo === "pass:enc") { // Private Key wallets
        let pass = derivePassSha(common.password, 20);
        let obj = {
            ciphertext: CryptoJS.enc.Hex.parse(walletAccount.encrypted),
            iv: convert.hex2ua(walletAccount.iv),
            key: convert.hex2ua(pass.priv)
        };
        let d = decrypt(obj);
        r = { 'priv': d };
    } else if (!r) {
        //console.log("Unknown wallet encryption method");
        return false;
    }
    // Result
    common.privateKey = r.priv;
    return true;
}
function ( common , walletAccount , algo ) { // Errors if ( ! common || ! walletAccount || ! algo ) throw new Error ( 'Missing argument !' ) ; let r = undefined ; if ( algo === "trezor" ) { // HW wallet r = { 'priv' : '' } ; common . isHW = true ; } else if ( ! common . password ) { throw new Error ( 'Missing argument !' ) ; } // Processing if ( algo === "pass:6k" ) { // Brain wallets if ( ! walletAccount . encrypted && ! walletAccount . iv ) { // Account private key is generated simply using a passphrase so it has no encrypted and iv r = derivePassSha ( common . password , 6000 ) ; } else if ( ! walletAccount . encrypted || ! walletAccount . iv ) { // Else if one is missing there is a problem //console.log("Account might be compromised, missing encrypted or iv"); return false ; } else { // Else child accounts have encrypted and iv so we decrypt let pass = derivePassSha ( common . password , 20 ) ; let obj = { ciphertext : CryptoJS . enc . Hex . parse ( walletAccount . encrypted ) , iv : convert . hex2ua ( walletAccount . iv ) , key : convert . hex2ua ( pass . priv ) } ; let d = decrypt ( obj ) ; r = { 'priv' : d } ; } } else if ( algo === "pass:bip32" ) { // Wallets from PRNG let pass = derivePassSha ( common . password , 20 ) ; let obj = { ciphertext : CryptoJS . enc . Hex . parse ( walletAccount . encrypted ) , iv : convert . hex2ua ( walletAccount . iv ) , key : convert . hex2ua ( pass . priv ) } ; let d = decrypt ( obj ) ; r = { 'priv' : d } ; } else if ( algo === "pass:enc" ) { // Private Key wallets let pass = derivePassSha ( common . password , 20 ) ; let obj = { ciphertext : CryptoJS . enc . Hex . parse ( walletAccount . encrypted ) , iv : convert . hex2ua ( walletAccount . iv ) , key : convert . hex2ua ( pass . priv ) } ; let d = decrypt ( obj ) ; r = { 'priv' : d } ; } else if ( ! r ) { //console.log("Unknown wallet encryption method"); return false ; } // Result common . privateKey = r . priv ; return true ; }
Reveal the private key of an account or derive it from the wallet password

@param {object} common- An object containing password and privateKey field
@param {object} walletAccount - A wallet account object
@param {string} algo - A wallet algorithm

@return {object|boolean} - The account private key in and object or false
Reveal the private key of an account or derive it from the wallet password