Skip to content

Commit

Permalink
fix: IIdentityManager interface
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat authored and mirceanis committed Sep 7, 2020
1 parent f79967e commit b6d1e36
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 208 deletions.
142 changes: 71 additions & 71 deletions packages/daf-core/src/identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,76 @@ import { IAgentPlugin, IIdentity, IService, IKey, IPluginMethodMap, IAgentContex
import { AbstractIdentityStore } from './abstract/abstract-identity-store'
import { IKeyManager } from './key-manager'

export interface IIdentityManagerGetIdentityArgs {
did: string
}
export interface IIdentityManagerDeleteIdentityArgs {
did: string
}
export interface IIdentityManagerCreateIdentityArgs {
alias?: string
provider?: string
kms?: string
options?: any
}

export interface IIdentityManagerGetOrCreateIdentityArgs {
alias: string
provider?: string
kms?: string
options?: any
}
export interface IIdentityManagerAddKeyArgs {
did: string
key: IKey
options?: any
}
export interface IIdentityManagerRemoveKeyArgs {
did: string
kid: string
options?: any
}
export interface IIdentityManagerAddServiceArgs {
did: string
service: IService
options?: any
}
export interface IIdentityManagerRemoveServiceArgs {
did: string
id: string
options?: any
}

export interface IIdentityManager extends IPluginMethodMap {
identityManagerGetProviders: () => Promise<string[]>
identityManagerGetIdentities: () => Promise<IIdentity[]>
identityManagerGetIdentity: (args: { did: string }) => Promise<IIdentity>
identityManagerCreateIdentity: (
args: {
alias?: string
provider?: string
kms?: string
options?: any
},
context: IAgentContext<IKeyManager>,
) => Promise<IIdentity>
identityManagerGetOrCreateIdentity: (
args: { alias: string; provider?: string; kms?: string; options?: any },
identityManagerGetProviders(): Promise<Array<string>>
identityManagerGetIdentities(): Promise<Array<IIdentity>>
identityManagerGetIdentity(args: IIdentityManagerGetIdentityArgs): Promise<IIdentity>
identityManagerCreateIdentity(
args: IIdentityManagerCreateIdentityArgs,
context: IAgentContext<IKeyManager>,
) => Promise<IIdentity>
identityManagerImportIdentity: (args: IIdentity) => Promise<IIdentity>
identityManagerDeleteIdentity: (
args: { did: string },
): Promise<IIdentity>
identityManagerGetOrCreateIdentity(
args: IIdentityManagerGetOrCreateIdentityArgs,
context: IAgentContext<IKeyManager>,
) => Promise<boolean>
identityManagerAddKey: (
args: { did: string; key: IKey; options?: any },
): Promise<IIdentity>
identityManagerImportIdentity(args: IIdentity): Promise<IIdentity>
identityManagerDeleteIdentity(
args: IIdentityManagerDeleteIdentityArgs,
context: IAgentContext<IKeyManager>,
) => Promise<any> // txHash?
identityManagerRemoveKey: (
args: { did: string; kid: string; options?: any },
): Promise<boolean>
identityManagerAddKey(args: IIdentityManagerAddKeyArgs, context: IAgentContext<IKeyManager>): Promise<any> // txHash?
identityManagerRemoveKey(
args: IIdentityManagerRemoveKeyArgs,
context: IAgentContext<IKeyManager>,
) => Promise<any> // txHash?
identityManagerAddService: (
args: { did: string; service: IService; options?: any },
): Promise<any> // txHash?
identityManagerAddService(
args: IIdentityManagerAddServiceArgs,
context: IAgentContext<IKeyManager>,
) => Promise<any> //txHash?
identityManagerRemoveService: (
args: { did: string; id: string; options?: any },
): Promise<any> //txHash?
identityManagerRemoveService(
args: IIdentityManagerRemoveServiceArgs,
context: IAgentContext<IKeyManager>,
) => Promise<any> //txHash?
): Promise<any> //txHash?
}

export class IdentityManager implements IAgentPlugin {
Expand Down Expand Up @@ -86,12 +118,12 @@ export class IdentityManager implements IAgentPlugin {
return this.store.list()
}

async identityManagerGetIdentity({ did }: { did: string }): Promise<IIdentity> {
async identityManagerGetIdentity({ did }: IIdentityManagerGetIdentityArgs): Promise<IIdentity> {
return this.store.get({ did })
}

async identityManagerCreateIdentity(
{ provider, alias, kms, options }: { alias?: string; provider?: string; kms?: string; options?: any },
{ provider, alias, kms, options }: IIdentityManagerCreateIdentityArgs,
context: IAgentContext<IKeyManager>,
): Promise<IIdentity> {
const providerName = provider || this.defaultProvider
Expand All @@ -103,7 +135,7 @@ export class IdentityManager implements IAgentPlugin {
}

async identityManagerGetOrCreateIdentity(
{ provider, alias, kms, options }: { alias: string; provider?: string; kms?: string; options?: any },
{ provider, alias, kms, options }: IIdentityManagerGetOrCreateIdentityArgs,
context: IAgentContext<IKeyManager>,
): Promise<IIdentity> {
try {
Expand All @@ -120,7 +152,7 @@ export class IdentityManager implements IAgentPlugin {
}

async identityManagerDeleteIdentity(
{ did }: { did: string },
{ did }: IIdentityManagerDeleteIdentityArgs,
context: IAgentContext<IKeyManager>,
): Promise<boolean> {
const identity = await this.store.get({ did })
Expand All @@ -130,15 +162,7 @@ export class IdentityManager implements IAgentPlugin {
}

async identityManagerAddKey(
{
did,
key,
options,
}: {
did: string
key: IKey
options?: any
},
{ did, key, options }: IIdentityManagerAddKeyArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
const identity = await this.store.get({ did })
Expand All @@ -150,15 +174,7 @@ export class IdentityManager implements IAgentPlugin {
}

async identityManagerRemoveKey(
{
did,
kid,
options,
}: {
did: string
kid: string
options?: any
},
{ did, kid, options }: IIdentityManagerRemoveKeyArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
const identity = await this.store.get({ did })
Expand All @@ -170,15 +186,7 @@ export class IdentityManager implements IAgentPlugin {
}

async identityManagerAddService(
{
did,
service,
options,
}: {
did: string
service: IService
options?: any
},
{ did, service, options }: IIdentityManagerAddServiceArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
const identity = await this.store.get({ did })
Expand All @@ -190,15 +198,7 @@ export class IdentityManager implements IAgentPlugin {
}

async identityManagerRemoveService(
{
did,
id,
options,
}: {
did: string
id: string
options?: any
},
{ did, id, options }: IIdentityManagerRemoveServiceArgs,
context: IAgentContext<IKeyManager>,
): Promise<any> {
const identity = await this.store.get({ did })
Expand Down
13 changes: 12 additions & 1 deletion packages/daf-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
*/
export { Agent, createAgent, IAgentOptions } from './agent'
export * from './types'
export { IdentityManager, IIdentityManager } from './identity-manager'
export {
IdentityManager,
IIdentityManager,
IIdentityManagerAddKeyArgs,
IIdentityManagerAddServiceArgs,
IIdentityManagerCreateIdentityArgs,
IIdentityManagerDeleteIdentityArgs,
IIdentityManagerGetIdentityArgs,
IIdentityManagerGetOrCreateIdentityArgs,
IIdentityManagerRemoveKeyArgs,
IIdentityManagerRemoveServiceArgs,
} from './identity-manager'
export {
KeyManager,
IKeyManager,
Expand Down
Loading

0 comments on commit b6d1e36

Please sign in to comment.