From 97e9e3e67afc6c846f1dd102a243b08d9ce649cc Mon Sep 17 00:00:00 2001 From: Mircea Nistor Date: Fri, 27 Jan 2023 12:41:25 +0100 Subject: [PATCH] fix(did-manager): rename AbstractDIDStore methods for SES compatibility The only problem method name was `import`, but all methods were renamed to maintain consistency in the API. fixes #1090 BREAKING CHANGE: implementations of AbstractDIDStore need to rename their methods to conform to the new API. Functionality remains the same. --- .gitignore | 5 ++- .../src/identifier/did-store.ts | 8 ++-- .../data-store/src/identifier/did-store.ts | 8 ++-- .../src/abstract-identifier-store.ts | 10 ++--- packages/did-manager/src/id-manager.ts | 42 +++++++++---------- packages/did-manager/src/memory-did-store.ts | 8 ++-- 6 files changed, 41 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index 496fa1d75e..7136e71ee3 100644 --- a/.gitignore +++ b/.gitignore @@ -32,10 +32,11 @@ key-store.json .vscode/ node_modules -temp +temp/ +tmp/ agent.yml data .vscode-upload.json -local-database*.json \ No newline at end of file +local-database*.json diff --git a/packages/data-store-json/src/identifier/did-store.ts b/packages/data-store-json/src/identifier/did-store.ts index 7e9012991c..d3e03e3dee 100644 --- a/packages/data-store-json/src/identifier/did-store.ts +++ b/packages/data-store-json/src/identifier/did-store.ts @@ -37,7 +37,7 @@ export class DIDStoreJson extends AbstractDIDStore { } } - async get({ + async getDID({ did, alias, provider, @@ -70,7 +70,7 @@ export class DIDStoreJson extends AbstractDIDStore { return deserialize(serialize(identifier)) } - async delete({ did }: { did: string }) { + async deleteDID({ did }: { did: string }) { if (this.cacheTree.dids[did]) { const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) delete this.cacheTree.dids[did] @@ -81,7 +81,7 @@ export class DIDStoreJson extends AbstractDIDStore { return false } - async import(args: IIdentifier) { + async importDID(args: IIdentifier) { const oldTree = deserialize(serialize(this.cacheTree, { lossy: true })) this.cacheTree.dids[args.did] = args args.keys.forEach((key) => { @@ -96,7 +96,7 @@ export class DIDStoreJson extends AbstractDIDStore { return true } - async list(args: { alias?: string; provider?: string }): Promise { + async listDIDs(args: { alias?: string; provider?: string }): Promise { const result = Object.values(this.cacheTree.dids).filter( (iid: IIdentifier) => (!args.provider || (args.provider && iid.provider === args.provider)) && diff --git a/packages/data-store/src/identifier/did-store.ts b/packages/data-store/src/identifier/did-store.ts index 79ea38523d..d004ece2ad 100644 --- a/packages/data-store/src/identifier/did-store.ts +++ b/packages/data-store/src/identifier/did-store.ts @@ -30,7 +30,7 @@ export class DIDStore extends AbstractDIDStore { super() } - async get({ + async getDID({ did, alias, provider, @@ -87,7 +87,7 @@ export class DIDStore extends AbstractDIDStore { return result } - async delete({ did }: { did: string }) { + async deleteDID({ did }: { did: string }) { const identifier = await (await getConnectedDb(this.dbConnection)).getRepository(Identifier).findOne({ where: { did }, relations: ['keys', 'services', 'issuedCredentials', 'issuedPresentations'], @@ -123,7 +123,7 @@ export class DIDStore extends AbstractDIDStore { return true } - async import(args: IIdentifier) { + async importDID(args: IIdentifier) { const identifier = new Identifier() identifier.did = args.did if (args.controllerKeyId) { @@ -160,7 +160,7 @@ export class DIDStore extends AbstractDIDStore { return true } - async list(args: { alias?: string; provider?: string }): Promise { + async listDIDs(args: { alias?: string; provider?: string }): Promise { const where: any = { provider: args?.provider || Not(IsNull()) } if (args?.alias) { where['alias'] = args.alias diff --git a/packages/did-manager/src/abstract-identifier-store.ts b/packages/did-manager/src/abstract-identifier-store.ts index 80460b11b8..8fbd1229ac 100644 --- a/packages/did-manager/src/abstract-identifier-store.ts +++ b/packages/did-manager/src/abstract-identifier-store.ts @@ -5,9 +5,9 @@ import { IIdentifier } from '@veramo/core' * @public */ export abstract class AbstractDIDStore { - abstract import(args: IIdentifier): Promise - abstract get(args: { did: string }): Promise - abstract get(args: { alias: string; provider: string }): Promise - abstract delete(args: { did: string }): Promise - abstract list(args: { alias?: string; provider?: string }): Promise + abstract importDID(args: IIdentifier): Promise + abstract getDID(args: { did: string }): Promise + abstract getDID(args: { alias: string; provider: string }): Promise + abstract deleteDID(args: { did: string }): Promise + abstract listDIDs(args: { alias?: string; provider?: string }): Promise } diff --git a/packages/did-manager/src/id-manager.ts b/packages/did-manager/src/id-manager.ts index d0c7f0803e..ada96f516f 100644 --- a/packages/did-manager/src/id-manager.ts +++ b/packages/did-manager/src/id-manager.ts @@ -84,18 +84,18 @@ export class DIDManager implements IAgentPlugin { /** {@inheritDoc @veramo/core#IDIDManager.didManagerFind} */ async didManagerFind(args: IDIDManagerFindArgs): Promise { - return this.store.list(args) + return this.store.listDIDs(args) } /** {@inheritDoc @veramo/core#IDIDManager.didManagerGet} */ async didManagerGet({ did }: IDIDManagerGetArgs): Promise { - return this.store.get({ did }) + return this.store.getDID({ did }) } /** {@inheritDoc @veramo/core#IDIDManager.didManagerGetByAlias} */ async didManagerGetByAlias({ alias, provider }: IDIDManagerGetByAliasArgs): Promise { const providerName = provider || this.defaultProvider - return this.store.get({ alias, provider: providerName }) + return this.store.getDID({ alias, provider: providerName }) } /** {@inheritDoc @veramo/core#IDIDManager.didManagerCreate} */ @@ -107,7 +107,7 @@ export class DIDManager implements IAgentPlugin { if (args?.alias !== undefined) { let existingIdentifier try { - existingIdentifier = await this.store.get({ alias: args.alias, provider: providerName }) + existingIdentifier = await this.store.getDID({ alias: args.alias, provider: providerName }) } catch (e) {} if (existingIdentifier) { throw Error( @@ -124,7 +124,7 @@ export class DIDManager implements IAgentPlugin { if (args?.alias) { identifier.alias = args.alias } - await this.store.import(identifier) + await this.store.importDID(identifier) return identifier } @@ -136,7 +136,7 @@ export class DIDManager implements IAgentPlugin { try { const providerName = provider || this.defaultProvider // @ts-ignore - const identifier = await this.store.get({ alias, provider: providerName }) + const identifier = await this.store.getDID({ alias, provider: providerName }) return identifier } catch { return this.didManagerCreate({ provider, alias, kms, options }, context) @@ -157,7 +157,7 @@ export class DIDManager implements IAgentPlugin { * 6. Update the identifier in the store * 7. Return the identifier */ - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) const identifierProvider = this.getProvider(identifier.provider) if (typeof identifierProvider?.updateIdentifier !== 'function') { throw new Error(`not_supported: ${identifier?.provider} provider does not implement full document updates`) @@ -166,7 +166,7 @@ export class DIDManager implements IAgentPlugin { { did, document, options }, context, ) - await this.store.import(updatedIdentifier) + await this.store.importDID(updatedIdentifier) return updatedIdentifier } @@ -175,9 +175,9 @@ export class DIDManager implements IAgentPlugin { { did, alias }: IDIDManagerSetAliasArgs, context: IAgentContext, ): Promise { - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) identifier.alias = alias - return await this.store.import(identifier) + return await this.store.importDID(identifier) } /** {@inheritDoc @veramo/core#IDIDManager.didManagerImport} */ @@ -196,7 +196,7 @@ export class DIDManager implements IAgentPlugin { keys, services, } - await this.store.import(importedDID) + await this.store.importDID(importedDID) return importedDID } @@ -205,10 +205,10 @@ export class DIDManager implements IAgentPlugin { { did }: IDIDManagerDeleteArgs, context: IAgentContext, ): Promise { - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) const provider = this.getProvider(identifier.provider) await provider.deleteIdentifier(identifier, context) - return this.store.delete({ did }) + return this.store.deleteDID({ did }) } /** {@inheritDoc @veramo/core#IDIDManager.didManagerAddKey} */ @@ -216,11 +216,11 @@ export class DIDManager implements IAgentPlugin { { did, key, options }: IDIDManagerAddKeyArgs, context: IAgentContext, ): Promise { - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) const provider = this.getProvider(identifier.provider) const result = await provider.addKey({ identifier, key, options }, context) identifier.keys.push(key) - await this.store.import(identifier) + await this.store.importDID(identifier) return result } @@ -229,11 +229,11 @@ export class DIDManager implements IAgentPlugin { { did, kid, options }: IDIDManagerRemoveKeyArgs, context: IAgentContext, ): Promise { - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) const provider = this.getProvider(identifier.provider) const result = await provider.removeKey({ identifier, kid, options }, context) identifier.keys = identifier.keys.filter((k) => k.kid !== kid) - await this.store.import(identifier) + await this.store.importDID(identifier) return result } @@ -242,11 +242,11 @@ export class DIDManager implements IAgentPlugin { { did, service, options }: IDIDManagerAddServiceArgs, context: IAgentContext, ): Promise { - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) const provider = this.getProvider(identifier.provider) const result = await provider.addService({ identifier, service, options }, context) identifier.services.push(service) - await this.store.import(identifier) + await this.store.importDID(identifier) return result } @@ -255,11 +255,11 @@ export class DIDManager implements IAgentPlugin { { did, id, options }: IDIDManagerRemoveServiceArgs, context: IAgentContext, ): Promise { - const identifier = await this.store.get({ did }) + const identifier = await this.store.getDID({ did }) const provider = this.getProvider(identifier.provider) const result = await provider.removeService({ identifier, id, options }, context) identifier.services = identifier.services.filter((s) => s.id !== id) - await this.store.import(identifier) + await this.store.importDID(identifier) return result } } diff --git a/packages/did-manager/src/memory-did-store.ts b/packages/did-manager/src/memory-did-store.ts index b4b7c5b7f8..5d18727586 100644 --- a/packages/did-manager/src/memory-did-store.ts +++ b/packages/did-manager/src/memory-did-store.ts @@ -9,7 +9,7 @@ import { AbstractDIDStore } from './abstract-identifier-store' export class MemoryDIDStore extends AbstractDIDStore { private identifiers: Record = {} - async get({ + async getDID({ did, alias, provider, @@ -33,12 +33,12 @@ export class MemoryDIDStore extends AbstractDIDStore { throw Error(`not_found: IIdentifier not found with alias=${alias} provider=${provider}`) } - async delete({ did }: { did: string }) { + async deleteDID({ did }: { did: string }) { delete this.identifiers[did] return true } - async import(args: IIdentifier) { + async importDID(args: IIdentifier) { const identifier = { ...args } for (const key of identifier.keys) { if (key.privateKeyHex) { @@ -49,7 +49,7 @@ export class MemoryDIDStore extends AbstractDIDStore { return true } - async list(args: { alias?: string; provider?: string }): Promise { + async listDIDs(args: { alias?: string; provider?: string }): Promise { let result: IIdentifier[] = [] for (const key of Object.keys(this.identifiers)) {