AraBlocks / ara-reward-dcdn

Ara-Reward-DCDN
GNU Lesser General Public License v3.0
2 stars 1 forks source link

Move `loadKey` to `ara-util` #55

Open vipyne opened 5 years ago

vipyne commented 5 years ago
  async loadKey() {
    if (!this.did || !this.password) {
      throw new Error('Missing ara identity or password')
    }

    let keystore
    let password
    try {
      const publicKey = Buffer.from(this.did, 'hex')
      const hash = crypto.blake2b(publicKey).toString('hex')
      const path = resolve(rc.network.identity.root, hash, 'keystore/ara')
      keystore = JSON.parse(await pify(readFile)(path, 'utf8'))
      password = crypto.blake2b(Buffer.from(this.password))
    } catch (err) {
      throw new Error('Failed to load keystore')
    }

    try {
      this.secretKey = ss.decrypt(keystore, { key: password.slice(0, 16) })
    } catch (err) {
      debug(err)
      throw new Error('Password failed to decrypt key')
    }
  }

from https://github.com/AraBlocks/ara-reward-dcdn/blob/master/src/user.js to https://github.com/AraBlocks/ara-util/blob/master/keyring.js

see comment in https://github.com/AraBlocks/ara-reward-dcdn/pull/50

Specifications