From 839c2a10aad21f451b8a3629e4ddcfc5ad3f6e10 Mon Sep 17 00:00:00 2001 From: ricmoo Date: Mon, 1 Aug 2016 19:24:52 -0400 Subject: [PATCH] Added summonBrainWallet function. --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index f7b2440e2..fa8c34014 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict'; var rlp = require('rlp'); +var scrypt = require('scrypt-js'); var Contract = require('./lib/contract.js'); var secretStorage = require('./lib/secret-storage.js'); @@ -32,6 +33,8 @@ utils.defineProperty(exportUtils, 'getContractAddress', function(transaction) { module.exports = Wallet; +utils.defineProperty(Wallet, 'etherSymbol', '\uD835\uDF63'); + utils.defineProperty(Wallet, 'getAddress', SigningKey.getAddress); utils.defineProperty(Wallet, 'getIcapAddress', SigningKey.getIcapAddress); @@ -63,6 +66,20 @@ utils.defineProperty(Wallet.prototype, 'encrypt', function(password, options, ca secretStorage.encrypt(this.privateKey, password, options, callback); }); +utils.defineProperty(Wallet, 'summonBrainWallet', function(username, password, callback) { + if (typeof(callback) !== 'function') { throw new Error('invalid callback'); } + + scrypt(password, username, (1 << 18), 8, 1, 32, function(error, progress, key) { + if (key) { + console.log(key, new Buffer(key), (new Buffer(key)).toString('hex')); + return callback(error, new Wallet(new Buffer(key)), 1); + } else { + return callback(error, null, progress); + } + }); +}); + + utils.defineProperty(Wallet, 'randomish', new Randomish()); module.exports = Wallet;