-
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: Method identityManagerGetOrCreateIdentity
- Loading branch information
1 parent
46fd3a2
commit 0155389
Showing
22 changed files
with
592 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { TAgent, IIdentityManager, IIdentity, IKey } from 'daf-core' | ||
import { IW3c } from 'daf-w3c' | ||
|
||
type ConfiguredAgent = TAgent<IIdentityManager & IW3c> | ||
|
||
export default (testContext: { | ||
getAgent: () => ConfiguredAgent | ||
setup: () => Promise<boolean> | ||
tearDown: () => Promise<boolean> | ||
}) => { | ||
describe('web did flow', () => { | ||
let agent: ConfiguredAgent | ||
let serviceIdentity: IIdentity | ||
let serviceIdentityKey: IKey | ||
let alice: IIdentity | ||
let bob: IIdentity | ||
|
||
beforeAll(() => { | ||
testContext.setup() | ||
agent = testContext.getAgent() | ||
}) | ||
afterAll(testContext.tearDown) | ||
|
||
it('should create service identity', async () => { | ||
serviceIdentity = await agent.identityManagerGetOrCreateIdentity({ | ||
provider: 'did:web', | ||
alias: 'example.com', | ||
}) | ||
|
||
expect(serviceIdentity.provider).toEqual('did:web') | ||
expect(serviceIdentity.alias).toEqual('example.com') | ||
expect(serviceIdentity.did).toEqual('did:web:example.com') | ||
serviceIdentityKey = serviceIdentity.keys[0] | ||
}) | ||
|
||
it('should get existing service identity', async () => { | ||
const testIdentity = await agent.identityManagerGetOrCreateIdentity({ | ||
provider: 'did:web', | ||
alias: 'example.com', | ||
}) | ||
|
||
expect(testIdentity.keys[0]).toEqual(serviceIdentityKey) | ||
expect(testIdentity.provider).toEqual('did:web') | ||
expect(testIdentity.alias).toEqual('example.com') | ||
expect(testIdentity.did).toEqual('did:web:example.com') | ||
}) | ||
|
||
it('should create identity with alias: alice', async () => { | ||
alice = await agent.identityManagerGetOrCreateIdentity({ | ||
alias: 'alice', | ||
}) | ||
|
||
expect(alice.provider).toEqual('did:ethr:rinkeby') | ||
expect(alice.alias).toEqual('alice') | ||
expect(alice.did).toBeDefined() | ||
}) | ||
|
||
it('should create identity with alias: bob', async () => { | ||
bob = await agent.identityManagerGetOrCreateIdentity({ | ||
alias: 'bob', | ||
}) | ||
|
||
expect(bob.provider).toEqual('did:ethr:rinkeby') | ||
expect(bob.alias).toEqual('bob') | ||
expect(bob.did).toBeDefined() | ||
}) | ||
|
||
describe('should create verifiable credential', () => { | ||
it('issuer: serviceIdentity', async () => { | ||
const verifiableCredential = await agent.createVerifiableCredential({ | ||
credential: { | ||
issuer: { id: serviceIdentity.did }, | ||
'@context': ['https://www.w3.org/2018/credentials/v1'], | ||
type: ['VerifiableCredential'], | ||
issuanceDate: new Date().toISOString(), | ||
credentialSubject: { | ||
id: alice.did, | ||
name: 'Alice', | ||
}, | ||
}, | ||
proofFormat: 'jwt', | ||
}) | ||
|
||
expect(verifiableCredential.issuer).toEqual({ id: serviceIdentity.did }) | ||
expect(verifiableCredential.credentialSubject).toEqual({ id: alice.did, name: 'Alice' }) | ||
expect(verifiableCredential).toHaveProperty('proof.jwt') | ||
}) | ||
|
||
it('issuer - Alice, subject - Bob', async () => { | ||
const a = await agent.identityManagerGetOrCreateIdentity({ | ||
alias: 'alice', | ||
}) | ||
|
||
const b = await agent.identityManagerGetOrCreateIdentity({ | ||
alias: 'bob', | ||
}) | ||
|
||
const verifiableCredential = await agent.createVerifiableCredential({ | ||
credential: { | ||
issuer: { id: a.did }, | ||
'@context': ['https://www.w3.org/2018/credentials/v1'], | ||
type: ['VerifiableCredential'], | ||
issuanceDate: new Date().toISOString(), | ||
credentialSubject: { | ||
id: b.did, | ||
name: 'Bob', | ||
}, | ||
}, | ||
proofFormat: 'jwt', | ||
}) | ||
|
||
expect(verifiableCredential.issuer).toEqual({ id: alice.did }) | ||
expect(verifiableCredential.credentialSubject).toEqual({ id: bob.did, name: 'Bob' }) | ||
expect(verifiableCredential).toHaveProperty('proof.jwt') | ||
}) | ||
}) | ||
}) | ||
} |
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
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.