aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-10-12 06:09:22 +0800
committerDan Finlay <dan@danfinlay.com>2016-10-12 06:12:23 +0800
commitea1a934c7defe7e1b077b675ae9125118f1f3d87 (patch)
tree27bfe79edeeebf659e6d0f4c0a8cce655c709079 /app
parentf8b52a3895e0d093f7d831695b56f236a911fb0f (diff)
downloadtangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.tar
tangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.tar.gz
tangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.tar.bz2
tangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.tar.lz
tangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.tar.xz
tangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.tar.zst
tangerine-wallet-browser-ea1a934c7defe7e1b077b675ae9125118f1f3d87.zip
Add initial KeyringController files
Diffstat (limited to 'app')
-rw-r--r--app/scripts/keyring-controller.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
new file mode 100644
index 000000000..b61242973
--- /dev/null
+++ b/app/scripts/keyring-controller.js
@@ -0,0 +1,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')
+}