refactor: Throw any storage errors when adding a key.

This commit is contained in:
Hayden Young 2023-03-06 17:56:38 +00:00
parent 7396a4ac64
commit 1fb02ea4cb
2 changed files with 14 additions and 6 deletions

View File

@ -111,12 +111,8 @@ const KeyStore = async ({ storage, path } = {}) => {
}
const addKey = async (id, key) => {
try {
await storage.put('public_' + id, key.publicKey)
await storage.put('private_' + id, key.privateKey)
} catch (e) {
console.log(e)
}
await storage.put('public_' + id, key.publicKey)
await storage.put('private_' + id, key.privateKey)
}
const createKey = async (id, { entropy } = {}) => {

View File

@ -124,6 +124,18 @@ describe('KeyStore', () => {
strictEqual(actual, expected)
})
it('creates a key when storage is closed', async () => {
let err
await keystore.close()
try {
await keystore.createKey(id)
} catch (e) {
err = e.toString()
}
strictEqual(err, 'Error: Database is not open')
})
})
describe('Options', () => {