diff --git a/__tests__/graphqlAgent.test.ts b/__tests__/graphqlAgent.test.ts index 1e3cca8fb..c22d37b53 100644 --- a/__tests__/graphqlAgent.test.ts +++ b/__tests__/graphqlAgent.test.ts @@ -8,24 +8,35 @@ import { IKeyManager, IDataStore, IMessageHandler, -} from 'daf-core' -import { MessageHandler } from 'daf-message-handler' -import { KeyManager } from 'daf-key-manager' -import { IdentityManager } from 'daf-identity-manager' +} from '../packages/daf-core' +import { MessageHandler } from '../packages/daf-message-handler' +import { KeyManager } from '../packages/daf-key-manager' +import { IdentityManager } from '../packages/daf-identity-manager' import { createConnection, Connection } from 'typeorm' -import { DafResolver } from 'daf-resolver' -import { JwtMessageHandler } from 'daf-did-jwt' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from 'daf-w3c' -import { EthrIdentityProvider } from 'daf-ethr-did' -import { WebIdentityProvider } from 'daf-web-did' -import { DIDComm, DIDCommMessageHandler, IDIDComm } from 'daf-did-comm' -import { SelectiveDisclosure, ISelectiveDisclosure, SdrMessageHandler } from 'daf-selective-disclosure' -import { KeyManagementSystem, SecretBox } from 'daf-libsodium' -import { Entities, KeyStore, IdentityStore, IDataStoreORM, DataStore, DataStoreORM } from 'daf-typeorm' +import { DafResolver } from '../packages/daf-resolver' +import { JwtMessageHandler } from '../packages/daf-did-jwt' +import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/daf-w3c' +import { EthrIdentityProvider } from '../packages/daf-ethr-did' +import { WebIdentityProvider } from '../packages/daf-web-did' +import { DIDComm, DIDCommMessageHandler, IDIDComm } from '../packages/daf-did-comm' +import { + SelectiveDisclosure, + ISelectiveDisclosure, + SdrMessageHandler, +} from '../packages/daf-selective-disclosure' +import { KeyManagementSystem, SecretBox } from '../packages/daf-libsodium' +import { + Entities, + KeyStore, + IdentityStore, + IDataStoreORM, + DataStore, + DataStoreORM, +} from '../packages/daf-typeorm' import express from 'express' import { ApolloServer } from 'apollo-server-express' import { Server } from 'http' -import { createSchema, AgentGraphQLClient, supportedMethods } from 'daf-graphql' +import { createSchema, AgentGraphQLClient, supportedMethods } from '../packages/daf-graphql' import fs from 'fs' // Shared tests diff --git a/__tests__/localAgent.test.ts b/__tests__/localAgent.test.ts index 80727a23c..3c7c8bc19 100644 --- a/__tests__/localAgent.test.ts +++ b/__tests__/localAgent.test.ts @@ -6,20 +6,31 @@ import { IKeyManager, IDataStore, IMessageHandler, -} from 'daf-core' -import { MessageHandler } from 'daf-message-handler' -import { KeyManager } from 'daf-key-manager' -import { IdentityManager } from 'daf-identity-manager' +} from '../packages/daf-core' +import { MessageHandler } from '../packages/daf-message-handler' +import { KeyManager } from '../packages/daf-key-manager' +import { IdentityManager } from '../packages/daf-identity-manager' import { createConnection, Connection } from 'typeorm' -import { DafResolver } from 'daf-resolver' -import { JwtMessageHandler } from 'daf-did-jwt' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from 'daf-w3c' -import { EthrIdentityProvider } from 'daf-ethr-did' -import { WebIdentityProvider } from 'daf-web-did' -import { DIDComm, DIDCommMessageHandler, IDIDComm } from 'daf-did-comm' -import { SelectiveDisclosure, ISelectiveDisclosure, SdrMessageHandler } from 'daf-selective-disclosure' -import { KeyManagementSystem, SecretBox } from 'daf-libsodium' -import { Entities, KeyStore, IdentityStore, IDataStoreORM, DataStore, DataStoreORM } from 'daf-typeorm' +import { DafResolver } from '../packages/daf-resolver' +import { JwtMessageHandler } from '../packages/daf-did-jwt' +import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/daf-w3c' +import { EthrIdentityProvider } from '../packages/daf-ethr-did' +import { WebIdentityProvider } from '../packages/daf-web-did' +import { DIDComm, DIDCommMessageHandler, IDIDComm } from '../packages/daf-did-comm' +import { + SelectiveDisclosure, + ISelectiveDisclosure, + SdrMessageHandler, +} from '../packages/daf-selective-disclosure' +import { KeyManagementSystem, SecretBox } from '../packages/daf-libsodium' +import { + Entities, + KeyStore, + IdentityStore, + IDataStoreORM, + DataStore, + DataStoreORM, +} from '../packages/daf-typeorm' import fs from 'fs' // Shared tests diff --git a/__tests__/restAgent.test.ts b/__tests__/restAgent.test.ts index ae5d6b446..427c6f245 100644 --- a/__tests__/restAgent.test.ts +++ b/__tests__/restAgent.test.ts @@ -7,24 +7,35 @@ import { IKeyManager, IDataStore, IMessageHandler, -} from 'daf-core' -import { MessageHandler } from 'daf-message-handler' -import { KeyManager } from 'daf-key-manager' -import { IdentityManager } from 'daf-identity-manager' +} from '../packages/daf-core' +import { MessageHandler } from '../packages/daf-message-handler' +import { KeyManager } from '../packages/daf-key-manager' +import { IdentityManager } from '../packages/daf-identity-manager' import { createConnection, Connection } from 'typeorm' -import { DafResolver } from 'daf-resolver' -import { JwtMessageHandler } from 'daf-did-jwt' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from 'daf-w3c' -import { EthrIdentityProvider } from 'daf-ethr-did' -import { WebIdentityProvider } from 'daf-web-did' -import { DIDComm, DIDCommMessageHandler, IDIDComm } from 'daf-did-comm' -import { SelectiveDisclosure, ISelectiveDisclosure, SdrMessageHandler } from 'daf-selective-disclosure' -import { KeyManagementSystem, SecretBox } from 'daf-libsodium' -import { Entities, KeyStore, IdentityStore, IDataStoreORM, DataStore, DataStoreORM } from 'daf-typeorm' -import { AgentRestClient, supportedMethods } from 'daf-rest' +import { DafResolver } from '../packages/daf-resolver' +import { JwtMessageHandler } from '../packages/daf-did-jwt' +import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/daf-w3c' +import { EthrIdentityProvider } from '../packages/daf-ethr-did' +import { WebIdentityProvider } from '../packages/daf-web-did' +import { DIDComm, DIDCommMessageHandler, IDIDComm } from '../packages/daf-did-comm' +import { + SelectiveDisclosure, + ISelectiveDisclosure, + SdrMessageHandler, +} from '../packages/daf-selective-disclosure' +import { KeyManagementSystem, SecretBox } from '../packages/daf-libsodium' +import { + Entities, + KeyStore, + IdentityStore, + IDataStoreORM, + DataStore, + DataStoreORM, +} from '../packages/daf-typeorm' +import { AgentRestClient, supportedMethods } from '../packages/daf-rest' import express from 'express' import { Server } from 'http' -import { AgentRouter } from 'daf-express' +import { AgentRouter } from '../packages/daf-express' import fs from 'fs' // Shared tests diff --git a/__tests__/shared/documentationExamples.ts b/__tests__/shared/documentationExamples.ts index e83890826..9d71af040 100644 --- a/__tests__/shared/documentationExamples.ts +++ b/__tests__/shared/documentationExamples.ts @@ -56,6 +56,16 @@ export default (testContext: { }) }) + it('daf-core-IIdentityManager-identityManagerGetIdentities example', async () => { + const aliceIdentities = await agent.identityManagerGetIdentities({ + alias: 'alice', + }) + + const rinkebyIdentities = await agent.identityManagerGetIdentities({ + provider: 'did:ethr:rinkeby', + }) + }) + it('daf-core-IIdentityManager-identityManagerGetIdentityByAlias example', async () => { const identity = await agent.identityManagerGetIdentityByAlias({ alias: 'alice', diff --git a/__tests__/shared/identityManager.ts b/__tests__/shared/identityManager.ts index 4796a0152..f7d09f606 100644 --- a/__tests__/shared/identityManager.ts +++ b/__tests__/shared/identityManager.ts @@ -95,7 +95,29 @@ export default (testContext: { expect(identity7).toEqual(identity4) }) - it.todo('should get identities') + it('should get identities', async () => { + const allIdentities = await agent.identityManagerGetIdentities() + expect(allIdentities.length).toEqual(3) + + const aliceIdentities = await agent.identityManagerGetIdentities({ + alias: 'alice', + }) + expect(aliceIdentities.length).toEqual(2) + + const rinkebyIdentities = await agent.identityManagerGetIdentities({ + provider: 'did:ethr:rinkeby', + }) + expect(rinkebyIdentities.length).toEqual(1) + + // Default provider 'did:ethr:rinkeby' + await agent.identityManagerCreateIdentity() + + const rinkebyIdentities2 = await agent.identityManagerGetIdentities({ + provider: 'did:ethr:rinkeby', + }) + expect(rinkebyIdentities2.length).toEqual(2) + }) + it.todo('should import identity') it.todo('should delete identity') it.todo('should add key to identity') diff --git a/docs/api/daf-core.iidentitymanager.identitymanagergetidentities.md b/docs/api/daf-core.iidentitymanager.identitymanagergetidentities.md index 7d7441ca0..1ff94132b 100644 --- a/docs/api/daf-core.iidentitymanager.identitymanagergetidentities.md +++ b/docs/api/daf-core.iidentitymanager.identitymanagergetidentities.md @@ -9,9 +9,30 @@ Returns a list of managed identities Signature: ```typescript -identityManagerGetIdentities(): Promise>; +identityManagerGetIdentities(args: IIdentityManagerGetIdentitiesArgs): Promise>; ``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| args | [IIdentityManagerGetIdentitiesArgs](./daf-core.iidentitymanagergetidentitiesargs.md) | Required. Arguments to get the list of identities | + Returns: Promise<Array<[IIdentity](./daf-core.iidentity.md)>> +## Example + + +```typescript +const aliceIdentities = await agent.identityManagerGetIdentities({ + alias: 'alice' +}) + +const rinkebyIdentities = await agent.identityManagerGetIdentities({ + provider: 'did:ethr:rinkeby' +}) + +``` + diff --git a/docs/api/daf-core.iidentitymanager.md b/docs/api/daf-core.iidentitymanager.md index ffdcedc5f..21a26aa09 100644 --- a/docs/api/daf-core.iidentitymanager.md +++ b/docs/api/daf-core.iidentitymanager.md @@ -21,7 +21,7 @@ export interface IIdentityManager extends IPluginMethodMap | [identityManagerAddService(args, context)](./daf-core.iidentitymanager.identitymanageraddservice.md) | Adds a service to a DID Document | | [identityManagerCreateIdentity(args, context)](./daf-core.iidentitymanager.identitymanagercreateidentity.md) | Creates and returns a new identity | | [identityManagerDeleteIdentity(args, context)](./daf-core.iidentitymanager.identitymanagerdeleteidentity.md) | Deletes identity | -| [identityManagerGetIdentities()](./daf-core.iidentitymanager.identitymanagergetidentities.md) | Returns a list of managed identities | +| [identityManagerGetIdentities(args)](./daf-core.iidentitymanager.identitymanagergetidentities.md) | Returns a list of managed identities | | [identityManagerGetIdentity(args)](./daf-core.iidentitymanager.identitymanagergetidentity.md) | Returns a specific identity | | [identityManagerGetIdentityByAlias(args)](./daf-core.iidentitymanager.identitymanagergetidentitybyalias.md) | Returns a specific identity by alias | | [identityManagerGetOrCreateIdentity(args, context)](./daf-core.iidentitymanager.identitymanagergetorcreateidentity.md) | Returns an existing identity or creates a new one for a specific alias | diff --git a/docs/api/daf-core.iidentitymanagergetidentitiesargs.alias.md b/docs/api/daf-core.iidentitymanagergetidentitiesargs.alias.md new file mode 100644 index 000000000..fc7ef6625 --- /dev/null +++ b/docs/api/daf-core.iidentitymanagergetidentitiesargs.alias.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [daf-core](./daf-core.md) > [IIdentityManagerGetIdentitiesArgs](./daf-core.iidentitymanagergetidentitiesargs.md) > [alias](./daf-core.iidentitymanagergetidentitiesargs.alias.md) + +## IIdentityManagerGetIdentitiesArgs.alias property + +Optional. Alias + +Signature: + +```typescript +alias?: string; +``` diff --git a/docs/api/daf-core.iidentitymanagergetidentitiesargs.md b/docs/api/daf-core.iidentitymanagergetidentitiesargs.md new file mode 100644 index 000000000..ce3eefd73 --- /dev/null +++ b/docs/api/daf-core.iidentitymanagergetidentitiesargs.md @@ -0,0 +1,21 @@ + + +[Home](./index.md) > [daf-core](./daf-core.md) > [IIdentityManagerGetIdentitiesArgs](./daf-core.iidentitymanagergetidentitiesargs.md) + +## IIdentityManagerGetIdentitiesArgs interface + +Input arguments for [identityManagerGetIdentities](./daf-core.iidentitymanager.identitymanagergetidentities.md) + +Signature: + +```typescript +export interface IIdentityManagerGetIdentitiesArgs +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [alias](./daf-core.iidentitymanagergetidentitiesargs.alias.md) | string | Optional. Alias | +| [provider](./daf-core.iidentitymanagergetidentitiesargs.provider.md) | string | Optional. Provider | + diff --git a/docs/api/daf-core.iidentitymanagergetidentitiesargs.provider.md b/docs/api/daf-core.iidentitymanagergetidentitiesargs.provider.md new file mode 100644 index 000000000..f46f3ae94 --- /dev/null +++ b/docs/api/daf-core.iidentitymanagergetidentitiesargs.provider.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [daf-core](./daf-core.md) > [IIdentityManagerGetIdentitiesArgs](./daf-core.iidentitymanagergetidentitiesargs.md) > [provider](./daf-core.iidentitymanagergetidentitiesargs.provider.md) + +## IIdentityManagerGetIdentitiesArgs.provider property + +Optional. Provider + +Signature: + +```typescript +provider?: string; +``` diff --git a/docs/api/daf-core.md b/docs/api/daf-core.md index ff0a46315..a6b205ad1 100644 --- a/docs/api/daf-core.md +++ b/docs/api/daf-core.md @@ -35,6 +35,7 @@ Provides [Agent](./daf-core.agent.md) implementation and defines [IResolver](./d | [IIdentityManagerAddServiceArgs](./daf-core.iidentitymanageraddserviceargs.md) | Input arguments for [identityManagerAddService](./daf-core.iidentitymanager.identitymanageraddservice.md) | | [IIdentityManagerCreateIdentityArgs](./daf-core.iidentitymanagercreateidentityargs.md) | Input arguments for [identityManagerCreateIdentity](./daf-core.iidentitymanager.identitymanagercreateidentity.md) | | [IIdentityManagerDeleteIdentityArgs](./daf-core.iidentitymanagerdeleteidentityargs.md) | Input arguments for [identityManagerDeleteIdentity](./daf-core.iidentitymanager.identitymanagerdeleteidentity.md) | +| [IIdentityManagerGetIdentitiesArgs](./daf-core.iidentitymanagergetidentitiesargs.md) | Input arguments for [identityManagerGetIdentities](./daf-core.iidentitymanager.identitymanagergetidentities.md) | | [IIdentityManagerGetIdentityArgs](./daf-core.iidentitymanagergetidentityargs.md) | Input arguments for [identityManagerGetIdentity](./daf-core.iidentitymanager.identitymanagergetidentity.md) | | [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) | Input arguments for [identityManagerGetIdentityByAlias](./daf-core.iidentitymanager.identitymanagergetidentitybyalias.md) | | [IIdentityManagerGetOrCreateIdentityArgs](./daf-core.iidentitymanagergetorcreateidentityargs.md) | Input arguments for [identityManagerGetOrCreateIdentity](./daf-core.iidentitymanager.identitymanagergetorcreateidentity.md) | diff --git a/docs/api/daf-identity-manager.abstractidentitystore.list.md b/docs/api/daf-identity-manager.abstractidentitystore.list.md index 503301de9..935db3555 100644 --- a/docs/api/daf-identity-manager.abstractidentitystore.list.md +++ b/docs/api/daf-identity-manager.abstractidentitystore.list.md @@ -7,8 +7,18 @@ Signature: ```typescript -abstract list(): Promise; +abstract list(args: { + alias?: string; + provider?: string; + }): Promise; ``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| args | { alias?: string; provider?: string; } | | + Returns: Promise<[IIdentity](./daf-core.iidentity.md)\[\]> diff --git a/docs/api/daf-identity-manager.abstractidentitystore.md b/docs/api/daf-identity-manager.abstractidentitystore.md index cdbd56260..8203374d9 100644 --- a/docs/api/daf-identity-manager.abstractidentitystore.md +++ b/docs/api/daf-identity-manager.abstractidentitystore.md @@ -20,5 +20,5 @@ export declare abstract class AbstractIdentityStore | [get(args)](./daf-identity-manager.abstractidentitystore.get.md) | | | | [get(args)](./daf-identity-manager.abstractidentitystore.get_1.md) | | | | [import(args)](./daf-identity-manager.abstractidentitystore.import.md) | | | -| [list()](./daf-identity-manager.abstractidentitystore.list.md) | | | +| [list(args)](./daf-identity-manager.abstractidentitystore.list.md) | | | diff --git a/docs/api/daf-identity-manager.identitymanager.identitymanagercreateidentity.md b/docs/api/daf-identity-manager.identitymanager.identitymanagercreateidentity.md index 4f7741b8e..c28dc2d9c 100644 --- a/docs/api/daf-identity-manager.identitymanager.identitymanagercreateidentity.md +++ b/docs/api/daf-identity-manager.identitymanager.identitymanagercreateidentity.md @@ -9,14 +9,14 @@ Creates and returns a new identity Signature: ```typescript -identityManagerCreateIdentity({ provider, alias, kms, options }: IIdentityManagerCreateIdentityArgs, context: IAgentContext): Promise; +identityManagerCreateIdentity(args: IIdentityManagerCreateIdentityArgs, context: IAgentContext): Promise; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| { provider, alias, kms, options } | [IIdentityManagerCreateIdentityArgs](./daf-core.iidentitymanagercreateidentityargs.md) | | +| args | [IIdentityManagerCreateIdentityArgs](./daf-core.iidentitymanagercreateidentityargs.md) | Required. Arguments to create the identity | | context | [IAgentContext](./daf-core.iagentcontext.md)<[IKeyManager](./daf-core.ikeymanager.md)> | Execution context. Requires agent that has [IKeyManager](./daf-core.ikeymanager.md) methods | Returns: diff --git a/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentities.md b/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentities.md index 415478af4..4e5471844 100644 --- a/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentities.md +++ b/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentities.md @@ -9,8 +9,15 @@ Returns a list of managed identities Signature: ```typescript -identityManagerGetIdentities(): Promise; +identityManagerGetIdentities(args: IIdentityManagerGetIdentitiesArgs): Promise; ``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| args | [IIdentityManagerGetIdentitiesArgs](./daf-core.iidentitymanagergetidentitiesargs.md) | Required. Arguments to get the list of identities | + Returns: Promise<[IIdentity](./daf-core.iidentity.md)\[\]> diff --git a/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentitybyalias.md b/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentitybyalias.md index e26b6cdc2..2f0d98797 100644 --- a/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentitybyalias.md +++ b/docs/api/daf-identity-manager.identitymanager.identitymanagergetidentitybyalias.md @@ -9,14 +9,14 @@ Returns a specific identity by alias Signature: ```typescript -identityManagerGetIdentityByAlias({ alias, provider }: IIdentityManagerGetIdentityByAliasArgs): Promise; +identityManagerGetIdentityByAlias({ alias, provider, }: IIdentityManagerGetIdentityByAliasArgs): Promise; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| { alias, provider } | [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) | | +| { alias, provider, } | [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) | | Returns: diff --git a/docs/api/daf-identity-manager.identitymanager.md b/docs/api/daf-identity-manager.identitymanager.md index d86bc2605..32f7136c8 100644 --- a/docs/api/daf-identity-manager.identitymanager.md +++ b/docs/api/daf-identity-manager.identitymanager.md @@ -31,11 +31,11 @@ export declare class IdentityManager implements IAgentPlugin | --- | --- | --- | | [identityManagerAddKey({ did, key, options }, context)](./daf-identity-manager.identitymanager.identitymanageraddkey.md) | | Adds a key to a DID Document | | [identityManagerAddService({ did, service, options }, context)](./daf-identity-manager.identitymanager.identitymanageraddservice.md) | | Adds a service to a DID Document | -| [identityManagerCreateIdentity({ provider, alias, kms, options }, context)](./daf-identity-manager.identitymanager.identitymanagercreateidentity.md) | | Creates and returns a new identity | +| [identityManagerCreateIdentity(args, context)](./daf-identity-manager.identitymanager.identitymanagercreateidentity.md) | | Creates and returns a new identity | | [identityManagerDeleteIdentity({ did }, context)](./daf-identity-manager.identitymanager.identitymanagerdeleteidentity.md) | | Deletes identity | -| [identityManagerGetIdentities()](./daf-identity-manager.identitymanager.identitymanagergetidentities.md) | | Returns a list of managed identities | +| [identityManagerGetIdentities(args)](./daf-identity-manager.identitymanager.identitymanagergetidentities.md) | | Returns a list of managed identities | | [identityManagerGetIdentity({ did })](./daf-identity-manager.identitymanager.identitymanagergetidentity.md) | | Returns a specific identity | -| [identityManagerGetIdentityByAlias({ alias, provider })](./daf-identity-manager.identitymanager.identitymanagergetidentitybyalias.md) | | Returns a specific identity by alias | +| [identityManagerGetIdentityByAlias({ alias, provider, })](./daf-identity-manager.identitymanager.identitymanagergetidentitybyalias.md) | | Returns a specific identity by alias | | [identityManagerGetOrCreateIdentity({ provider, alias, kms, options }, context)](./daf-identity-manager.identitymanager.identitymanagergetorcreateidentity.md) | | Returns an existing identity or creates a new one for a specific alias | | [identityManagerGetProviders()](./daf-identity-manager.identitymanager.identitymanagergetproviders.md) | | Returns a list of available identity providers | | [identityManagerImportIdentity(identity)](./daf-identity-manager.identitymanager.identitymanagerimportidentity.md) | | Imports identity | diff --git a/docs/api/daf-typeorm.entities.md b/docs/api/daf-typeorm.entities.md index 99873d3de..20b846427 100644 --- a/docs/api/daf-typeorm.entities.md +++ b/docs/api/daf-typeorm.entities.md @@ -7,5 +7,5 @@ Signature: ```typescript -Entities: (typeof Credential | typeof Identity | typeof Claim | typeof Presentation | typeof Message | typeof Key | typeof Service)[] +Entities: (typeof Key | typeof Identity | typeof Service | typeof Claim | typeof Credential | typeof Presentation | typeof Message)[] ``` diff --git a/docs/api/daf-typeorm.identitystore.list.md b/docs/api/daf-typeorm.identitystore.list.md index 4448ee399..89bd6a64d 100644 --- a/docs/api/daf-typeorm.identitystore.list.md +++ b/docs/api/daf-typeorm.identitystore.list.md @@ -7,8 +7,18 @@ Signature: ```typescript -list(): Promise; +list(args: { + alias?: string; + provider?: string; + }): Promise; ``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| args | { alias?: string; provider?: string; } | | + Returns: Promise<[IIdentity](./daf-core.iidentity.md)\[\]> diff --git a/docs/api/daf-typeorm.identitystore.md b/docs/api/daf-typeorm.identitystore.md index 5733eecb6..1b0f3ef8e 100644 --- a/docs/api/daf-typeorm.identitystore.md +++ b/docs/api/daf-typeorm.identitystore.md @@ -24,5 +24,5 @@ export declare class IdentityStore extends AbstractIdentityStore | [delete({ did })](./daf-typeorm.identitystore.delete.md) | | | | [get({ did, alias, provider })](./daf-typeorm.identitystore.get.md) | | | | [import(args)](./daf-typeorm.identitystore.import.md) | | | -| [list()](./daf-typeorm.identitystore.list.md) | | | +| [list(args)](./daf-typeorm.identitystore.list.md) | | | diff --git a/docs/methods.md b/docs/methods.md index 2a19df518..8cf84e327 100644 --- a/docs/methods.md +++ b/docs/methods.md @@ -64,6 +64,15 @@ Deletes identity Returns a list of managed identities +```typescript +const aliceIdentities = await agent.identityManagerGetIdentities({ + alias: 'alice' +}) + +const rinkebyIdentities = await agent.identityManagerGetIdentities({ + provider: 'did:ethr:rinkeby' +}) +``` ### [identityManagerGetIdentity](./api/daf-core.iidentitymanager.identitymanagergetidentity.md) diff --git a/jest.json b/jest.json index 987198c2f..704ad8ad7 100644 --- a/jest.json +++ b/jest.json @@ -2,8 +2,9 @@ "moduleFileExtensions": ["ts", "tsx", "js", "jsx"], "collectCoverage": true, "collectCoverageFrom": [ - "**/src/**/*.ts", + "packages/**/src/**/*.ts", "!**/examples/**", + "!packages/daf-cli/**", "!**/types/**", "!**/build/**", "!**/node_modules/**" diff --git a/packages/daf-core/src/types.ts b/packages/daf-core/src/types.ts index 61dbf2949..b950ec02a 100644 --- a/packages/daf-core/src/types.ts +++ b/packages/daf-core/src/types.ts @@ -379,6 +379,22 @@ export interface IIdentityManagerGetIdentityArgs { did: string } +/** + * Input arguments for {@link IIdentityManager.identityManagerGetIdentities | identityManagerGetIdentities} + * @public + */ +export interface IIdentityManagerGetIdentitiesArgs { + /** + * Optional. Alias + */ + alias?: string + + /** + * Optional. Provider + */ + provider?: string +} + /** * Input arguments for {@link IIdentityManager.identityManagerGetIdentityByAlias | identityManagerGetIdentityByAlias} * @public @@ -554,8 +570,22 @@ export interface IIdentityManager extends IPluginMethodMap { /** * Returns a list of managed identities + * + * @param args - Required. Arguments to get the list of identities + * @param context - Execution context. Requires `agent` that has {@link daf-core#IKeyManager} methods + * + * @example + * ```typescript + * const aliceIdentities = await agent.identityManagerGetIdentities({ + * alias: 'alice' + * }) + * + * const rinkebyIdentities = await agent.identityManagerGetIdentities({ + * provider: 'did:ethr:rinkeby' + * }) + * ``` */ - identityManagerGetIdentities(): Promise> + identityManagerGetIdentities(args: IIdentityManagerGetIdentitiesArgs): Promise> /** * Returns a specific identity diff --git a/packages/daf-graphql/src/methods/identity-manager.ts b/packages/daf-graphql/src/methods/identity-manager.ts index 76489a7bb..6ce00d7b8 100644 --- a/packages/daf-graphql/src/methods/identity-manager.ts +++ b/packages/daf-graphql/src/methods/identity-manager.ts @@ -17,8 +17,8 @@ export const identityManagerGetProviders: IAgentGraphQLMethod = { export const identityManagerGetIdentities: IAgentGraphQLMethod = { type: 'Query', query: ` - query identityManagerGetIdentities { - identityManagerGetIdentities{ + query identityManagerGetIdentities($alias: String, $provider: String) { + identityManagerGetIdentities(alias: $alias, provider: $provider){ did provider alias @@ -40,7 +40,7 @@ export const identityManagerGetIdentities: IAgentGraphQLMethod = { `, typeDef: ` extend type Query { - identityManagerGetIdentities: [Identity] + identityManagerGetIdentities(alias: String, provider: String): [Identity] } `, } diff --git a/packages/daf-identity-manager/src/abstract-identity-store.ts b/packages/daf-identity-manager/src/abstract-identity-store.ts index 83b49cb19..0dcc2d717 100644 --- a/packages/daf-identity-manager/src/abstract-identity-store.ts +++ b/packages/daf-identity-manager/src/abstract-identity-store.ts @@ -9,5 +9,5 @@ export abstract class AbstractIdentityStore { abstract get(args: { did: string }): Promise abstract get(args: { alias: string; provider: string }): Promise abstract delete(args: { did: string }): Promise - abstract list(): Promise + abstract list(args: { alias?: string; provider?: string }): Promise } diff --git a/packages/daf-identity-manager/src/identity-manager.ts b/packages/daf-identity-manager/src/identity-manager.ts index 3f6b7eacb..2efbbb5a2 100644 --- a/packages/daf-identity-manager/src/identity-manager.ts +++ b/packages/daf-identity-manager/src/identity-manager.ts @@ -14,6 +14,7 @@ import { IIdentityManagerRemoveKeyArgs, IIdentityManagerAddServiceArgs, IIdentityManagerRemoveServiceArgs, + IIdentityManagerGetIdentitiesArgs, } from 'daf-core' import { AbstractIdentityStore } from './abstract-identity-store' @@ -68,8 +69,8 @@ export class IdentityManager implements IAgentPlugin { } /** {@inheritDoc daf-core#IIdentityManager.identityManagerGetIdentities} */ - async identityManagerGetIdentities(): Promise { - return this.store.list() + async identityManagerGetIdentities(args: IIdentityManagerGetIdentitiesArgs): Promise { + return this.store.list(args) } /** {@inheritDoc daf-core#IIdentityManager.identityManagerGetIdentity} */ @@ -88,22 +89,25 @@ export class IdentityManager implements IAgentPlugin { /** {@inheritDoc daf-core#IIdentityManager.identityManagerCreateIdentity} */ async identityManagerCreateIdentity( - { provider, alias, kms, options }: IIdentityManagerCreateIdentityArgs, + args: IIdentityManagerCreateIdentityArgs, context: IAgentContext, ): Promise { - const providerName = provider || this.defaultProvider - if (alias !== undefined) { + const providerName = args?.provider || this.defaultProvider + if (args?.alias !== undefined) { let existingIdentity try { - existingIdentity = await this.store.get({ alias, provider: providerName }) + existingIdentity = await this.store.get({ alias: args.alias, provider: providerName }) } catch (e) {} if (existingIdentity) { - throw Error(`Identity with alias: ${alias}, provider: ${providerName} already exists`) + throw Error(`Identity with alias: ${args.alias}, provider: ${providerName} already exists`) } } const identityProvider = this.getProvider(providerName) - const partialIdentity = await identityProvider.createIdentity({ kms, alias, options }, context) - const identity: IIdentity = { ...partialIdentity, alias, provider: providerName } + const partialIdentity = await identityProvider.createIdentity( + { kms: args?.kms, alias: args?.alias, options: args?.options }, + context, + ) + const identity: IIdentity = { ...partialIdentity, alias: args?.alias, provider: providerName } await this.store.import(identity) return identity } diff --git a/packages/daf-rest/src/openApiSchema.ts b/packages/daf-rest/src/openApiSchema.ts index 329ad8cea..3cf8037ac 100644 --- a/packages/daf-rest/src/openApiSchema.ts +++ b/packages/daf-rest/src/openApiSchema.ts @@ -381,6 +381,21 @@ export const openApiSchema: OpenAPIV3.Document = { "additionalProperties": false, "description": "Input arguments for {@link IIdentityManager.identityManagerDeleteIdentity | identityManagerDeleteIdentity}" }, + "IIdentityManagerGetIdentitiesArgs": { + "type": "object", + "properties": { + "alias": { + "type": "string", + "description": "Optional. Alias" + }, + "provider": { + "type": "string", + "description": "Optional. Provider" + } + }, + "additionalProperties": false, + "description": "Input arguments for {@link IIdentityManager.identityManagerGetIdentities | identityManagerGetIdentities}" + }, "IIdentityManagerGetIdentityArgs": { "type": "object", "properties": { @@ -1974,7 +1989,9 @@ export const openApiSchema: OpenAPIV3.Document = { "requestBody": { "content": { "application/json": { - "schema": {} + "schema": { + "$ref": "#/components/schemas/IIdentityManagerGetIdentitiesArgs" + } } } }, diff --git a/packages/daf-typeorm/src/identity/identity-store.ts b/packages/daf-typeorm/src/identity/identity-store.ts index 7680a18d8..99c5155cd 100644 --- a/packages/daf-typeorm/src/identity/identity-store.ts +++ b/packages/daf-typeorm/src/identity/identity-store.ts @@ -87,9 +87,13 @@ export class IdentityStore extends AbstractIdentityStore { return true } - async list(): Promise { + async list(args: { alias?: string; provider?: string }): Promise { + const where: any = { provider: args?.provider || Not(IsNull()) } + if (args?.alias) { + where['alias'] = args.alias + } const identities = await (await this.dbConnection).getRepository(Identity).find({ - where: [{ provider: Not(IsNull()) }], + where, relations: ['keys', 'services'], }) return identities diff --git a/report/daf-core.api.md b/report/daf-core.api.md index e06f4c532..ba6e97c4a 100644 --- a/report/daf-core.api.md +++ b/report/daf-core.api.md @@ -83,7 +83,7 @@ export interface IIdentityManager extends IPluginMethodMap { identityManagerAddService(args: IIdentityManagerAddServiceArgs, context: IAgentContext): Promise; identityManagerCreateIdentity(args: IIdentityManagerCreateIdentityArgs, context: IAgentContext): Promise; identityManagerDeleteIdentity(args: IIdentityManagerDeleteIdentityArgs, context: IAgentContext): Promise; - identityManagerGetIdentities(): Promise>; + identityManagerGetIdentities(args: IIdentityManagerGetIdentitiesArgs): Promise>; identityManagerGetIdentity(args: IIdentityManagerGetIdentityArgs): Promise; identityManagerGetIdentityByAlias(args: IIdentityManagerGetIdentityByAliasArgs): Promise; identityManagerGetOrCreateIdentity(args: IIdentityManagerGetOrCreateIdentityArgs, context: IAgentContext): Promise; @@ -120,6 +120,12 @@ export interface IIdentityManagerDeleteIdentityArgs { did: string; } +// @public +export interface IIdentityManagerGetIdentitiesArgs { + alias?: string; + provider?: string; +} + // @public export interface IIdentityManagerGetIdentityArgs { did: string; diff --git a/report/daf-identity-manager.api.md b/report/daf-identity-manager.api.md index 4e984a766..3c05370a3 100644 --- a/report/daf-identity-manager.api.md +++ b/report/daf-identity-manager.api.md @@ -12,6 +12,7 @@ import { IIdentityManagerAddKeyArgs } from 'daf-core'; import { IIdentityManagerAddServiceArgs } from 'daf-core'; import { IIdentityManagerCreateIdentityArgs } from 'daf-core'; import { IIdentityManagerDeleteIdentityArgs } from 'daf-core'; +import { IIdentityManagerGetIdentitiesArgs } from 'daf-core'; import { IIdentityManagerGetIdentityArgs } from 'daf-core'; import { IIdentityManagerGetIdentityByAliasArgs } from 'daf-core'; import { IIdentityManagerGetOrCreateIdentityArgs } from 'daf-core'; @@ -75,7 +76,10 @@ export abstract class AbstractIdentityStore { // (undocumented) abstract import(args: IIdentity): Promise; // (undocumented) - abstract list(): Promise; + abstract list(args: { + alias?: string; + provider?: string; + }): Promise; } // @public @@ -90,15 +94,15 @@ export class IdentityManager implements IAgentPlugin { // (undocumented) identityManagerAddService({ did, service, options }: IIdentityManagerAddServiceArgs, context: IAgentContext): Promise; // (undocumented) - identityManagerCreateIdentity({ provider, alias, kms, options }: IIdentityManagerCreateIdentityArgs, context: IAgentContext): Promise; + identityManagerCreateIdentity(args: IIdentityManagerCreateIdentityArgs, context: IAgentContext): Promise; // (undocumented) identityManagerDeleteIdentity({ did }: IIdentityManagerDeleteIdentityArgs, context: IAgentContext): Promise; // (undocumented) - identityManagerGetIdentities(): Promise; + identityManagerGetIdentities(args: IIdentityManagerGetIdentitiesArgs): Promise; // (undocumented) identityManagerGetIdentity({ did }: IIdentityManagerGetIdentityArgs): Promise; // (undocumented) - identityManagerGetIdentityByAlias({ alias, provider }: IIdentityManagerGetIdentityByAliasArgs): Promise; + identityManagerGetIdentityByAlias({ alias, provider, }: IIdentityManagerGetIdentityByAliasArgs): Promise; // (undocumented) identityManagerGetOrCreateIdentity({ provider, alias, kms, options }: IIdentityManagerGetOrCreateIdentityArgs, context: IAgentContext): Promise; // (undocumented) diff --git a/report/daf-typeorm.api.md b/report/daf-typeorm.api.md index 1105c01c6..86a99294f 100644 --- a/report/daf-typeorm.api.md +++ b/report/daf-typeorm.api.md @@ -118,7 +118,7 @@ export class DataStoreORM implements IAgentPlugin { } // @public (undocumented) -export const Entities: (typeof Credential_2 | typeof Identity | typeof Claim | typeof Presentation | typeof Message | typeof Key | typeof Service)[]; +export const Entities: (typeof Key | typeof Identity | typeof Service | typeof Claim | typeof Credential_2 | typeof Presentation | typeof Message)[]; // @public (undocumented) export interface FindArgs { @@ -228,7 +228,10 @@ export class IdentityStore extends AbstractIdentityStore { // (undocumented) import(args: IIdentity): Promise; // (undocumented) - list(): Promise; + list(args: { + alias?: string; + provider?: string; + }): Promise; } // @public (undocumented)