lib/account.js
function (input, password, nonStrict) {
        /*jshint maxcomplexity:10 */

        var json = (typeof input === 'object') ? input : JSON.parse(nonStrict ? input.toLowerCase() : input);
        if (json.version !== KeyVersion3 && json.version !== KeyCurrentVersion) {
            throw new Error('Not supported wallet version');
        }
        var derivedKey;
        var kdfparams;
        if (json.crypto.kdf === 'scrypt') {
            kdfparams = json.crypto.kdfparams;
            derivedKey = cryptoUtils.scrypt(new Buffer(password), new Buffer(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
        } else if (json.crypto.kdf === 'pbkdf2') {
            kdfparams = json.crypto.kdfparams;
            if (kdfparams.prf !== 'hmac-sha256') {
                throw new Error('Unsupported parameters to PBKDF2');
            }
            derivedKey = cryptoUtils.crypto.pbkdf2Sync(new Buffer(password), new Buffer(kdfparams.salt, 'hex'), kdfparams.c, kdfparams.dklen, 'sha256');
        } else {
            throw new Error('Unsupported key derivation scheme');
        }
        var ciphertext = new Buffer(json.crypto.ciphertext, 'hex');
        var mac;

        if (json.version === KeyCurrentVersion) {
            mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), ciphertext,
                new Buffer(json.crypto.cipherparams.iv, 'hex'), new Buffer(json.crypto.cipher)]));
        } else {
            // KeyVersion3
            mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), ciphertext]));
        }

        if (mac.toString('hex') !== json.crypto.mac) {
            throw new Error('Key derivation failed - possibly wrong passphrase');
        }
        var decipher = cryptoUtils.crypto.createDecipheriv(json.crypto.cipher, derivedKey.slice(0, 16), new Buffer(json.crypto.cipherparams.iv, 'hex'));
        var seed = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
        while (seed.length < 32) {
            var nullBuff = new Buffer([0x00]);
            seed = Buffer.concat([nullBuff, seed]);
        }
        this.setPrivateKey(seed);
        return this;
    }
function (input, password, nonStrict) {
        /*jshint maxcomplexity:10 */

        var json = (typeof input === 'object') ? input : JSON.parse(nonStrict ? input.toLowerCase() : input);
        if (json.version !== KeyVersion3 && json.version !== KeyCurrentVersion) {
            throw new Error('Not supported wallet version');
        }
        var derivedKey;
        var kdfparams;
        if (json.crypto.kdf === 'scrypt') {
            kdfparams = json.crypto.kdfparams;
            derivedKey = cryptoUtils.scrypt(new Buffer(password), new Buffer(kdfparams.salt, 'hex'), kdfparams.n, kdfparams.r, kdfparams.p, kdfparams.dklen);
        } else if (json.crypto.kdf === 'pbkdf2') {
            kdfparams = json.crypto.kdfparams;
            if (kdfparams.prf !== 'hmac-sha256') {
                throw new Error('Unsupported parameters to PBKDF2');
            }
            derivedKey = cryptoUtils.crypto.pbkdf2Sync(new Buffer(password), new Buffer(kdfparams.salt, 'hex'), kdfparams.c, kdfparams.dklen, 'sha256');
        } else {
            throw new Error('Unsupported key derivation scheme');
        }
        var ciphertext = new Buffer(json.crypto.ciphertext, 'hex');
        var mac;

        if (json.version === KeyCurrentVersion) {
            mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), ciphertext,
                new Buffer(json.crypto.cipherparams.iv, 'hex'), new Buffer(json.crypto.cipher)]));
        } else {
            // KeyVersion3
            mac = cryptoUtils.sha3(Buffer.concat([derivedKey.slice(16, 32), ciphertext]));
        }

        if (mac.toString('hex') !== json.crypto.mac) {
            throw new Error('Key derivation failed - possibly wrong passphrase');
        }
        var decipher = cryptoUtils.crypto.createDecipheriv(json.crypto.cipher, derivedKey.slice(0, 16), new Buffer(json.crypto.cipherparams.iv, 'hex'));
        var seed = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
        while (seed.length < 32) {
            var nullBuff = new Buffer([0x00]);
            seed = Buffer.concat([nullBuff, seed]);
        }
        this.setPrivateKey(seed);
        return this;
    }
function ( input , password , nonStrict ) { /*jshint maxcomplexity:10 */ var json = ( typeof input === 'object' ) ? input : JSON . parse ( nonStrict ? input . toLowerCase ( ) : input ) ; if ( json . version !== KeyVersion3 && json . version !== KeyCurrentVersion ) { throw new Error ( 'Not supported wallet version' ) ; } var derivedKey ; var kdfparams ; if ( json . crypto . kdf === 'scrypt' ) { kdfparams = json . crypto . kdfparams ; derivedKey = cryptoUtils . scrypt ( new Buffer ( password ) , new Buffer ( kdfparams . salt , 'hex' ) , kdfparams . n , kdfparams . r , kdfparams . p , kdfparams . dklen ) ; } else if ( json . crypto . kdf === 'pbkdf2' ) { kdfparams = json . crypto . kdfparams ; if ( kdfparams . prf !== 'hmac-sha256' ) { throw new Error ( 'Unsupported parameters to PBKDF2' ) ; } derivedKey = cryptoUtils . crypto . pbkdf2Sync ( new Buffer ( password ) , new Buffer ( kdfparams . salt , 'hex' ) , kdfparams . c , kdfparams . dklen , 'sha256' ) ; } else { throw new Error ( 'Unsupported key derivation scheme' ) ; } var ciphertext = new Buffer ( json . crypto . ciphertext , 'hex' ) ; var mac ; if ( json . version === KeyCurrentVersion ) { mac = cryptoUtils . sha3 ( Buffer . concat ( [ derivedKey . slice ( 16 , 32 ) , ciphertext , new Buffer ( json . crypto . cipherparams . iv , 'hex' ) , new Buffer ( json . crypto . cipher ) ] ) ) ; } else { // KeyVersion3 mac = cryptoUtils . sha3 ( Buffer . concat ( [ derivedKey . slice ( 16 , 32 ) , ciphertext ] ) ) ; } if ( mac . toString ( 'hex' ) !== json . crypto . mac ) { throw new Error ( 'Key derivation failed - possibly wrong passphrase' ) ; } var decipher = cryptoUtils . crypto . createDecipheriv ( json . crypto . cipher , derivedKey . slice ( 0 , 16 ) , new Buffer ( json . crypto . cipherparams . iv , 'hex' ) ) ; var seed = Buffer . concat ( [ decipher . update ( ciphertext ) , decipher . final ( ) ] ) ; while ( seed . length < 32 ) { var nullBuff = new Buffer ( [ 0x00 ] ) ; seed = Buffer . concat ( [ nullBuff , seed ] ) ; } this . setPrivateKey ( seed ) ; return this ; }
Restore account from key and passphrase.

@param {Key} input - Key Object.
@param {Password} password - Provided password.
@param {Boolean} nonStrict - Strict сase sensitivity flag.

@return {@link Account} - Instance of Account restored from key and passphrase.
Restore account from key and passphrase .