-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added identityManagerGetIdentityByAlias
- Loading branch information
1 parent
e8cbe6f
commit 43d0817
Showing
34 changed files
with
477 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
docs/api/daf-core.iidentitymanager.identitymanagergetidentitybyalias.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [daf-core](./daf-core.md) > [IIdentityManager](./daf-core.iidentitymanager.md) > [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<[IIdentity](./daf-core.iidentity.md)<!-- -->> | ||
|
||
## Example | ||
|
||
|
||
```typescript | ||
const identity = await agent.identityManagerGetIdentityByAlias({ | ||
alias: 'alice', | ||
provider: 'did:ethr:rinkeby' | ||
}) | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
docs/api/daf-core.iidentitymanagergetidentitybyaliasargs.alias.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [daf-core](./daf-core.md) > [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) > [alias](./daf-core.iidentitymanagergetidentitybyaliasargs.alias.md) | ||
|
||
## IIdentityManagerGetIdentityByAliasArgs.alias property | ||
|
||
Alias | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
alias: string; | ||
``` |
21 changes: 21 additions & 0 deletions
21
docs/api/daf-core.iidentitymanagergetidentitybyaliasargs.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [daf-core](./daf-core.md) > [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 | | ||
|
13 changes: 13 additions & 0 deletions
13
docs/api/daf-core.iidentitymanagergetidentitybyaliasargs.provider.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) > [daf-core](./daf-core.md) > [IIdentityManagerGetIdentityByAliasArgs](./daf-core.iidentitymanagergetidentitybyaliasargs.md) > [provider](./daf-core.iidentitymanagergetidentitybyaliasargs.provider.md) | ||
|
||
## IIdentityManagerGetIdentityByAliasArgs.provider property | ||
|
||
Optional provider | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
provider?: string; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.