Skip to content

Commit

Permalink
feat: Added identityManagerGetIdentityByAlias
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Sep 25, 2020
1 parent e8cbe6f commit 43d0817
Show file tree
Hide file tree
Showing 34 changed files with 477 additions and 17 deletions.
9 changes: 9 additions & 0 deletions __tests__/graphqlAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import resolveDid from './shared/resolveDid'
import webDidFlow from './shared/webDidFlow'
import documentationExamples from './shared/documentationExamples'
import keyManager from './shared/keyManager'
import identityManager from './shared/identityManager'

const databaseFile = 'graphql-database.sqlite'
const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand Down Expand Up @@ -84,6 +85,13 @@ const setup = async (): Promise<boolean> => {
store: new IdentityStore(dbConnection),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr': new EthrIdentityProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrIdentityProvider({
defaultKms: 'local',
network: 'rinkeby',
Expand Down Expand Up @@ -151,4 +159,5 @@ describe('GraphQL integration tests', () => {
webDidFlow(testContext)
documentationExamples(testContext)
keyManager(testContext)
identityManager(testContext)
})
9 changes: 9 additions & 0 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import webDidFlow from './shared/webDidFlow'
import saveClaims from './shared/saveClaims'
import documentationExamples from './shared/documentationExamples'
import keyManager from './shared/keyManager'
import identityManager from './shared/identityManager'

const databaseFile = 'local-database.sqlite'
const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand Down Expand Up @@ -82,6 +83,13 @@ const setup = async (): Promise<boolean> => {
store: new IdentityStore(dbConnection),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr': new EthrIdentityProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrIdentityProvider({
defaultKms: 'local',
network: 'rinkeby',
Expand Down Expand Up @@ -131,4 +139,5 @@ describe('Local integration tests', () => {
saveClaims(testContext)
documentationExamples(testContext)
keyManager(testContext)
identityManager(testContext)
})
9 changes: 9 additions & 0 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import resolveDid from './shared/resolveDid'
import webDidFlow from './shared/webDidFlow'
import documentationExamples from './shared/documentationExamples'
import keyManager from './shared/keyManager'
import identityManager from './shared/identityManager'

const databaseFile = 'rest-database.sqlite'
const infuraProjectId = '5ffc47f65c4042ce847ef66a3fa70d4c'
Expand Down Expand Up @@ -83,6 +84,13 @@ const setup = async (): Promise<boolean> => {
store: new IdentityStore(dbConnection),
defaultProvider: 'did:ethr:rinkeby',
providers: {
'did:ethr': new EthrIdentityProvider({
defaultKms: 'local',
network: 'mainnet',
rpcUrl: 'https://mainnet.infura.io/v3/' + infuraProjectId,
gas: 1000001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
'did:ethr:rinkeby': new EthrIdentityProvider({
defaultKms: 'local',
network: 'rinkeby',
Expand Down Expand Up @@ -144,4 +152,5 @@ describe('REST integration tests', () => {
webDidFlow(testContext)
documentationExamples(testContext)
keyManager(testContext)
identityManager(testContext)
})
8 changes: 8 additions & 0 deletions __tests__/shared/documentationExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ export default (testContext: {

it('daf-core-IIdentityManager-identityManagerCreateIdentity example', async () => {
const identity = await agent.identityManagerCreateIdentity({
alias: 'alice',
provider: 'did:ethr:rinkeby',
kms: 'local',
})
})

it('daf-core-IIdentityManager-identityManagerGetIdentityByAlias example', async () => {
const identity = await agent.identityManagerGetIdentityByAlias({
alias: 'alice',
provider: 'did:ethr:rinkeby',
})
})

//DO NOT EDIT MANUALLY END
})
}
106 changes: 106 additions & 0 deletions __tests__/shared/identityManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { TAgent, IIdentityManager, IKeyManager, IIdentity } from 'daf-core'

type ConfiguredAgent = TAgent<IIdentityManager & IKeyManager>

export default (testContext: {
getAgent: () => ConfiguredAgent
setup: () => Promise<boolean>
tearDown: () => Promise<boolean>
}) => {
describe('identity manager', () => {
let agent: ConfiguredAgent

beforeAll(async () => {
await testContext.setup()
agent = testContext.getAgent()
return true
})
afterAll(testContext.tearDown)

it('should get providers', async () => {
const providers = await agent.identityManagerGetProviders()
expect(providers).toEqual(['did:ethr', 'did:ethr:rinkeby', 'did:web'])
})

let identity: IIdentity
it('should create identity', async () => {
identity = await agent.identityManagerCreateIdentity({
provider: 'did:web',
alias: 'example.com',
})
expect(identity.provider).toEqual('did:web')
expect(identity.alias).toEqual('example.com')
expect(identity.did).toEqual('did:web:example.com')
expect(identity.keys.length).toEqual(1)
expect(identity.services.length).toEqual(0)
expect(identity.controllerKeyId).toEqual(identity.keys[0].kid)
})

it('should throw error for existing alias provider combo', async () => {
await expect(
agent.identityManagerCreateIdentity({
provider: 'did:web',
alias: 'example.com',
}),
).rejects.toThrow('Identity with alias: example.com, provider: did:web already exists')
})

it('should get identity', async () => {
const identity2 = await agent.identityManagerGetIdentity({
did: identity.did,
})
expect(identity2.did).toEqual(identity.did)
})

it('should throw error for non existing did', async () => {
await expect(
agent.identityManagerGetIdentity({
did: 'did:web:foobar',
}),
).rejects.toThrow('Identity not found')
})

it('should get or create identity', async () => {
const identity3 = await agent.identityManagerGetOrCreateIdentity({
alias: 'alice',
provider: 'did:ethr:rinkeby',
})

const identity4 = await agent.identityManagerGetOrCreateIdentity({
alias: 'alice',
provider: 'did:ethr:rinkeby',
})

expect(identity3).toEqual(identity4)

const identity5 = await agent.identityManagerGetOrCreateIdentity({
alias: 'alice',
provider: 'did:ethr',
})

expect(identity5).not.toEqual(identity4)

const identity6 = await agent.identityManagerGetIdentityByAlias({
alias: 'alice',
provider: 'did:ethr',
})

expect(identity6).toEqual(identity5)

const identity7 = await agent.identityManagerGetIdentityByAlias({
alias: 'alice',
// default provider is 'did:ethr:rinkeby'
})

expect(identity7).toEqual(identity4)
})

it.todo('should get identities')
it.todo('should import identity')
it.todo('should delete identity')
it.todo('should add key to identity')
it.todo('should remove key from identity')
it.todo('should add service to identity')
it.todo('should remove service from identity')
})
}
31 changes: 31 additions & 0 deletions __tests__/shared/keyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,36 @@ export default (testContext: {

expect(typeof rawTx).toEqual('string')
})

it.todo('Should Encrypt/Decrypt')
// it('Should Encrypt/Decrypt', async () => {
// const message = 'foo bar'

// const senderKey = await agent.keyManagerCreateKey({
// kms: 'local',
// type: 'Ed25519',
// })

// const recipientKey = await agent.keyManagerCreateKey({
// kms: 'local',
// type: 'Ed25519',
// })

// const encrypted = await agent.keyManagerEncryptJWE({
// kid: senderKey.kid,
// to: recipientKey,
// data: message
// })

// expect(typeof encrypted).toEqual('string')

// const decrypted = await agent.keyManagerDecryptJWE({
// kid: recipientKey.kid,
// data: encrypted
// })

// expect(decrypted).toEqual(message)

// })
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Promise&lt;[IIdentity](./daf-core.iidentity.md)<!-- -->&gt;

```typescript
const identity = await agent.identityManagerCreateIdentity({
alias: 'alice',
provider: 'did:ethr:rinkeby',
kms: 'local'
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IIdentityManager](./daf-core.iidentitymanager.md) &gt; [identityManagerGetIdentityByAlias](./daf-core.iidentitymanager.identitymanagergetidentitybyalias.md)

## IIdentityManager.identityManagerGetIdentityByAlias() method

Returns a specific identity by alias

<b>Signature:</b>

```typescript
identityManagerGetIdentityByAlias(args: IIdentityManagerGetIdentityByAliasArgs): Promise<IIdentity>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) | Required. Arguments to get the identity |

<b>Returns:</b>

Promise&lt;[IIdentity](./daf-core.iidentity.md)<!-- -->&gt;

## Example


```typescript
const identity = await agent.identityManagerGetIdentityByAlias({
alias: 'alice',
provider: 'did:ethr:rinkeby'
})

```

1 change: 1 addition & 0 deletions docs/api/daf-core.iidentitymanager.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IIdentityManager extends IPluginMethodMap
| [identityManagerDeleteIdentity(args, context)](./daf-core.iidentitymanager.identitymanagerdeleteidentity.md) | Deletes identity |
| [identityManagerGetIdentities()](./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 |
| [identityManagerGetProviders()](./daf-core.iidentitymanager.identitymanagergetproviders.md) | Returns a list of available identity providers |
| [identityManagerImportIdentity(args)](./daf-core.iidentitymanager.identitymanagerimportidentity.md) | Imports identity |
Expand Down
13 changes: 13 additions & 0 deletions docs/api/daf-core.iidentitymanagergetidentitybyaliasargs.alias.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) &gt; [alias](./daf-core.iidentitymanagergetidentitybyaliasargs.alias.md)

## IIdentityManagerGetIdentityByAliasArgs.alias property

Alias

<b>Signature:</b>

```typescript
alias: string;
```
21 changes: 21 additions & 0 deletions docs/api/daf-core.iidentitymanagergetidentitybyaliasargs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md)

## IIdentityManagerGetIdentityByAliasArgs interface

Input arguments for [identityManagerGetIdentityByAlias](./daf-core.iidentitymanager.identitymanagergetidentitybyalias.md)

<b>Signature:</b>

```typescript
export interface IIdentityManagerGetIdentityByAliasArgs
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [alias](./daf-core.iidentitymanagergetidentitybyaliasargs.alias.md) | string | Alias |
| [provider](./daf-core.iidentitymanagergetidentitybyaliasargs.provider.md) | string | Optional provider |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) &gt; [provider](./daf-core.iidentitymanagergetidentitybyaliasargs.provider.md)

## IIdentityManagerGetIdentityByAliasArgs.provider property

Optional provider

<b>Signature:</b>

```typescript
provider?: string;
```
1 change: 1 addition & 0 deletions docs/api/daf-core.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Provides [Agent](./daf-core.agent.md) implementation and defines [IResolver](./d
| [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) |
| [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) |
| [IIdentityManagerRemoveKeyArgs](./daf-core.iidentitymanagerremovekeyargs.md) | Input arguments for [identityManagerRemoveKey](./daf-core.iidentitymanager.identitymanagerremovekey.md) |
| [IIdentityManagerRemoveServiceArgs](./daf-core.iidentitymanagerremoveserviceargs.md) | Input arguments for [identityManagerRemoveService](./daf-core.iidentitymanager.identitymanagerremoveservice.md) |
Expand Down
2 changes: 1 addition & 1 deletion docs/api/daf-graphql.basetypedef.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
baseTypeDef = "\ntype Query\ntype Mutation\n\nscalar KeyMeta\n\ntype Key {\n kid: String!\n kms: String!\n type: String!\n publicKeyHex: String!\n privateKeyHex: String\n meta: KeyMeta\n}\n\ntype Service {\n id: String!\n type: String!\n serviceEndpoint: String!\n description: String\n}\n\ntype Identity {\n did: String!\n provider: String\n alias: String\n keys: [Key]\n services: [Service]\n}\n\nscalar Object\nscalar Date\nscalar VerifiablePresentation\nscalar VerifiableCredential\nscalar Presentation\nscalar Credential\n\ntype Message {\n id: ID!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: String\n from: String\n to: String\n metaData: [MetaData]\n presentations: [VerifiablePresentation]\n credentials: [VerifiableCredential]\n}\n\ntype MetaData {\n type: String!\n value: String\n}\n\n\n"
baseTypeDef = "\ntype Query\ntype Mutation\n\nscalar KeyMeta\n\ntype Key {\n kid: String!\n kms: String!\n type: String!\n publicKeyHex: String!\n privateKeyHex: String\n meta: KeyMeta\n}\n\ntype Service {\n id: String!\n type: String!\n serviceEndpoint: String!\n description: String\n}\n\ntype Identity {\n did: String!\n provider: String\n alias: String\n controllerKeyId: String\n keys: [Key]\n services: [Service]\n}\n\nscalar Object\nscalar Date\nscalar VerifiablePresentation\nscalar VerifiableCredential\nscalar Presentation\nscalar Credential\n\ntype Message {\n id: ID!\n createdAt: Date\n expiresAt: Date\n threadId: String\n type: String!\n raw: String\n data: Object\n replyTo: [String]\n replyUrl: String\n from: String\n to: String\n metaData: [MetaData]\n presentations: [VerifiablePresentation]\n credentials: [VerifiableCredential]\n}\n\ntype MetaData {\n type: String!\n value: String\n}\n\n\n"
```
3 changes: 2 additions & 1 deletion docs/api/daf-identity-manager.abstractidentitystore.get_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
```typescript
abstract get(args: {
alias: string;
provider: string;
}): Promise<IIdentity>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | { alias: string; } | |
| args | { alias: string; provider: string; } | |

<b>Returns:</b>

Expand Down
Loading

0 comments on commit 43d0817

Please sign in to comment.