A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ciphermask/app/scripts/keyring-controller.js

121 lines
2.7 KiB

const EventEmitter = require('events').EventEmitter
const encryptor = require('./lib/encryptor')
const messageManager = require('./lib/message-manager')
module.exports = class KeyringController extends EventEmitter {
constructor (opts) {
super()
this.configManager = opts.configManager
this.ethStore = opts.ethStore
this.keyChains = []
}
getState() {
return {
8 years ago
isInitialized: !!this.configManager.getVault(),
isUnlocked: !!this.key,
isConfirmed: true, // this.configManager.getConfirmed(),
isEthConfirmed: this.configManager.getShouldntShowWarning(),
unconfTxs: this.configManager.unconfirmedTxs(),
transactions: this.configManager.getTxList(),
unconfMsgs: messageManager.unconfirmedMsgs(),
messages: messageManager.getMsgList(),
selectedAddress: this.configManager.getSelectedAccount(),
shapeShiftTxList: this.configManager.getShapeShiftTxList(),
currentFiat: this.configManager.getCurrentFiat(),
conversionRate: this.configManager.getConversionRate(),
conversionDate: this.configManager.getConversionDate(),
}
}
setStore(ethStore) {
this.ethStore = ethStore
}
createNewVault(password, entropy, cb) {
const salt = generateNewSalt()
this.configManager.setSalt(salt)
8 years ago
this.loadKey(password)
.then((key) => {
return encryptor.encryptWithKey(key, {})
})
.then((encryptedString) => {
this.configManager.setVault(encryptedString)
cb(null, this.getState())
})
.catch((err) => {
cb(err)
})
}
submitPassword(password, cb) {
8 years ago
this.loadKey(password)
.then((key) => {
cb(null, this.getState())
8 years ago
})
.catch((err) => {
cb(err)
})
}
loadKey(password) {
const salt = this.configManager.getSalt()
return encryptor.keyFromPassword(password + salt)
8 years ago
.then((key) => {
this.key = key
return key
})
}
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()
}
}
function generateSalt (byteCount) {
var view = new Uint8Array(32)
global.crypto.getRandomValues(view)
var b64encoded = btoa(String.fromCharCode.apply(null, view))
return b64encoded
}