Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

close keystore after signing #30

Open
wants to merge 7 commits into
base: fix/persistent-store
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 73 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"standard": "^12.0.1",
"webpack": "^4.27.1",
"webpack-cli": "^3.1.2",
"localstorage-level-migration": "^0.0.1"
"localstorage-level-migration": "github:orbitdb/localstorage-level-migration#fix/persistent-store"
},
"standard": {
"env": [
Expand All @@ -47,6 +47,6 @@
},
"dependencies": {
"ethers": "^4.0.20",
"orbit-db-keystore": "~0.2.0"
"orbit-db-keystore": "orbitdb/orbit-db-keystore#fix/persistent-leveldb-connection"
}
}
6 changes: 5 additions & 1 deletion src/identities.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class Identities {
const IdentityProvider = getHandlerFor(options.type)
const identityProvider = new IdentityProvider(options)
const id = await identityProvider.getId(options)

if (options.migrate) {
await options.migrate({ targetPath: this._keystore.path, targetId: id })
await options.migrate({ targetStore: this._keystore._store, targetId: id })
}
const { publicKey, idSignature } = await this.signId(id)
const pubKeyIdSignature = await identityProvider.signIdentity(publicKey + idSignature, options)
Expand All @@ -50,6 +51,9 @@ class Identities {
const key = await keystore.getKey(id) || await keystore.createKey(id)
const publicKey = keystore.getPublic(key)
const idSignature = await keystore.sign(key, id)
if (this._keystore.close) {
await this._keystore.close()
}
return { publicKey, idSignature }
}

Expand Down
6 changes: 5 additions & 1 deletion src/orbit-db-identity-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ class OrbitDBIdentityProvider extends IdentityProvider {
if (!key) {
throw new Error(`Signing key for '${id}' not found`)
}
const sig = await keystore.sign(key, data)
if (this._keystore.close) {
await this._keystore.close()
}

return keystore.sign(key, data)
return sig
}

static async verifyIdentity (identity) {
Expand Down
4 changes: 4 additions & 0 deletions test/identity-provider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ describe('Identity Provider', function () {
const id = 'QmFoo'
let identity

before(async () => {
await identityKeystore.open()
})

it('identity pkSignature verifies', async () => {
identity = await Identities.createIdentity({ id, type, keystore: identityKeystore })
const verified = await Keystore.verify(identity.signatures.id, identity.publicKey, identity.id)
Expand Down