Skip to content

Commit

Permalink
fix(did-manager): rename AbstractDIDStore methods for SES compatibility
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mirceanis committed Jan 27, 2023
1 parent 4945932 commit 97e9e3e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 40 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ key-store.json

.vscode/
node_modules
temp
temp/
tmp/

agent.yml
data
.vscode-upload.json

local-database*.json
local-database*.json
8 changes: 4 additions & 4 deletions packages/data-store-json/src/identifier/did-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class DIDStoreJson extends AbstractDIDStore {
}
}

async get({
async getDID({
did,
alias,
provider,
Expand Down Expand Up @@ -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]
Expand All @@ -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) => {
Expand All @@ -96,7 +96,7 @@ export class DIDStoreJson extends AbstractDIDStore {
return true
}

async list(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {
async listDIDs(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {
const result = Object.values(this.cacheTree.dids).filter(
(iid: IIdentifier) =>
(!args.provider || (args.provider && iid.provider === args.provider)) &&
Expand Down
8 changes: 4 additions & 4 deletions packages/data-store/src/identifier/did-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class DIDStore extends AbstractDIDStore {
super()
}

async get({
async getDID({
did,
alias,
provider,
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -160,7 +160,7 @@ export class DIDStore extends AbstractDIDStore {
return true
}

async list(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {
async listDIDs(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {
const where: any = { provider: args?.provider || Not(IsNull()) }
if (args?.alias) {
where['alias'] = args.alias
Expand Down
10 changes: 5 additions & 5 deletions packages/did-manager/src/abstract-identifier-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { IIdentifier } from '@veramo/core'
* @public
*/
export abstract class AbstractDIDStore {
abstract import(args: IIdentifier): Promise<boolean>
abstract get(args: { did: string }): Promise<IIdentifier>
abstract get(args: { alias: string; provider: string }): Promise<IIdentifier>
abstract delete(args: { did: string }): Promise<boolean>
abstract list(args: { alias?: string; provider?: string }): Promise<IIdentifier[]>
abstract importDID(args: IIdentifier): Promise<boolean>
abstract getDID(args: { did: string }): Promise<IIdentifier>
abstract getDID(args: { alias: string; provider: string }): Promise<IIdentifier>
abstract deleteDID(args: { did: string }): Promise<boolean>
abstract listDIDs(args: { alias?: string; provider?: string }): Promise<IIdentifier[]>
}
42 changes: 21 additions & 21 deletions packages/did-manager/src/id-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ export class DIDManager implements IAgentPlugin {

/** {@inheritDoc @veramo/core#IDIDManager.didManagerFind} */
async didManagerFind(args: IDIDManagerFindArgs): Promise<IIdentifier[]> {
return this.store.list(args)
return this.store.listDIDs(args)
}

/** {@inheritDoc @veramo/core#IDIDManager.didManagerGet} */
async didManagerGet({ did }: IDIDManagerGetArgs): Promise<IIdentifier> {
return this.store.get({ did })
return this.store.getDID({ did })
}

/** {@inheritDoc @veramo/core#IDIDManager.didManagerGetByAlias} */
async didManagerGetByAlias({ alias, provider }: IDIDManagerGetByAliasArgs): Promise<IIdentifier> {
const providerName = provider || this.defaultProvider
return this.store.get({ alias, provider: providerName })
return this.store.getDID({ alias, provider: providerName })
}

/** {@inheritDoc @veramo/core#IDIDManager.didManagerCreate} */
Expand All @@ -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(
Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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`)
Expand All @@ -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
}

Expand All @@ -175,9 +175,9 @@ export class DIDManager implements IAgentPlugin {
{ did, alias }: IDIDManagerSetAliasArgs,
context: IAgentContext<IKeyManager>,
): Promise<boolean> {
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} */
Expand All @@ -196,7 +196,7 @@ export class DIDManager implements IAgentPlugin {
keys,
services,
}
await this.store.import(importedDID)
await this.store.importDID(importedDID)
return importedDID
}

Expand All @@ -205,22 +205,22 @@ export class DIDManager implements IAgentPlugin {
{ did }: IDIDManagerDeleteArgs,
context: IAgentContext<IKeyManager>,
): Promise<boolean> {
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} */
async didManagerAddKey(
{ did, key, options }: IDIDManagerAddKeyArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
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
}

Expand All @@ -229,11 +229,11 @@ export class DIDManager implements IAgentPlugin {
{ did, kid, options }: IDIDManagerRemoveKeyArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
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
}

Expand All @@ -242,11 +242,11 @@ export class DIDManager implements IAgentPlugin {
{ did, service, options }: IDIDManagerAddServiceArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
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
}

Expand All @@ -255,11 +255,11 @@ export class DIDManager implements IAgentPlugin {
{ did, id, options }: IDIDManagerRemoveServiceArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
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
}
}
8 changes: 4 additions & 4 deletions packages/did-manager/src/memory-did-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AbstractDIDStore } from './abstract-identifier-store'
export class MemoryDIDStore extends AbstractDIDStore {
private identifiers: Record<string, IIdentifier> = {}

async get({
async getDID({
did,
alias,
provider,
Expand All @@ -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) {
Expand All @@ -49,7 +49,7 @@ export class MemoryDIDStore extends AbstractDIDStore {
return true
}

async list(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {
async listDIDs(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {
let result: IIdentifier[] = []

for (const key of Object.keys(this.identifiers)) {
Expand Down

0 comments on commit 97e9e3e

Please sign in to comment.