2020-08-05 17:14:12 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const multibase = require('multibase')
|
|
|
|
const ciphers = require('../ciphers/aes-gcm')
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
|
|
* Attempts to decrypt a base64 encoded PrivateKey string
|
|
|
|
* with the given password. The privateKey must have been exported
|
|
|
|
* using the same password and underlying cipher (aes-gcm)
|
|
|
|
*
|
|
|
|
* @param {string} privateKey A base64 encoded encrypted key
|
|
|
|
* @param {string} password
|
2020-08-07 15:23:02 +01:00
|
|
|
* @returns {Promise<Uint8Array>} The private key protobuf
|
2020-08-05 17:14:12 +02:00
|
|
|
*/
|
|
|
|
import: async function (privateKey, password) {
|
|
|
|
const base64 = multibase.names.base64
|
|
|
|
const encryptedKey = base64.decode(privateKey)
|
|
|
|
const cipher = ciphers.create()
|
|
|
|
return await cipher.decrypt(encryptedKey, password)
|
|
|
|
}
|
|
|
|
}
|