2016-10-12 00:09:22 +02:00
|
|
|
const scrypt = require('scrypt-async')
|
|
|
|
const bitcore = require('bitcore-lib')
|
|
|
|
const configManager = require('./lib/config-manager')
|
2016-10-13 01:43:48 +02:00
|
|
|
const EventEmitter = require('events').EventEmitter
|
2016-10-12 00:09:22 +02:00
|
|
|
|
2016-10-13 01:43:48 +02:00
|
|
|
module.exports = class KeyringController extends EventEmitter {
|
2016-10-12 00:09:22 +02:00
|
|
|
|
|
|
|
constructor (opts) {
|
2016-10-13 01:43:48 +02:00
|
|
|
super()
|
2016-10-12 00:09:22 +02:00
|
|
|
this.configManager = opts.configManager
|
2016-10-13 01:43:48 +02:00
|
|
|
this.ethStore = opts.ethStore
|
2016-10-12 00:09:22 +02:00
|
|
|
this.keyChains = []
|
|
|
|
}
|
|
|
|
|
|
|
|
getKeyForPassword(password, callback) {
|
|
|
|
let salt = this.configManager.getSalt()
|
|
|
|
|
|
|
|
if (!salt) {
|
|
|
|
salt = generateSalt(32)
|
|
|
|
configManager.setSalt(salt)
|
|
|
|
}
|
|
|
|
|
|
|
|
var logN = 14
|
|
|
|
var r = 8
|
|
|
|
var dkLen = 32
|
|
|
|
var interruptStep = 200
|
|
|
|
|
|
|
|
var cb = function(derKey) {
|
|
|
|
try {
|
|
|
|
var ui8arr = (new Uint8Array(derKey))
|
|
|
|
this.pwDerivedKey = ui8arr
|
|
|
|
callback(null, ui8arr)
|
|
|
|
} catch (err) {
|
|
|
|
callback(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
scrypt(password, salt, logN, r, dkLen, interruptStep, cb, null)
|
|
|
|
}
|
|
|
|
|
2016-10-13 01:43:48 +02:00
|
|
|
getState() {
|
|
|
|
return {}
|
|
|
|
}
|
|
|
|
|
|
|
|
setStore(ethStore) {
|
|
|
|
this.ethStore = ethStore
|
|
|
|
}
|
|
|
|
|
|
|
|
createNewVault(password, entropy, cb) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
|
|
|
submitPassword(password, cb) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelectedAddress(address, cb) {
|
|
|
|
this.selectedAddress = address
|
|
|
|
cb(null, address)
|
|
|
|
}
|
|
|
|
|
|
|
|
approveTransaction(txId, cb) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelTransaction(txId, cb) {
|
|
|
|
if (cb && typeof cb === 'function') {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
signMessage(msgParams, cb) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelMessage(msgId, cb) {
|
|
|
|
if (cb && typeof cb === 'function') {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setLocked(cb) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
|
|
|
exportAccount(address, cb) {
|
|
|
|
cb(null, '0xPrivateKey')
|
|
|
|
}
|
|
|
|
|
|
|
|
saveAccountLabel(account, label, cb) {
|
|
|
|
cb(/* null, label */)
|
|
|
|
}
|
|
|
|
|
|
|
|
tryPassword(password, cb) {
|
|
|
|
cb()
|
|
|
|
}
|
|
|
|
|
2016-10-12 00:09:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function generateSalt (byteCount) {
|
|
|
|
return bitcore.crypto.Random.getRandomBuffer(byteCount || 32).toString('base64')
|
|
|
|
}
|