blob: b612429737fef530d3d218176b4d6752eefe3909 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
const scrypt = require('scrypt-async')
const bitcore = require('bitcore-lib')
const configManager = require('./lib/config-manager')
module.exports = class KeyringController {
constructor (opts) {
this.configManager = opts.configManager
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)
}
}
function generateSalt (byteCount) {
return bitcore.crypto.Random.getRandomBuffer(byteCount || 32).toString('base64')
}
|