Skip to content

Commit

Permalink
feat: Unique (with hash) VC/VP in ORM results
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Oct 2, 2020
1 parent 8496e99 commit bcfc3e8
Show file tree
Hide file tree
Showing 66 changed files with 2,018 additions and 575 deletions.
4 changes: 2 additions & 2 deletions __tests__/graphqlAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { createSchema, AgentGraphQLClient, supportedMethods } from '../packages/
import fs from 'fs'

// Shared tests
import createVerifiableCredential from './shared/createVerifiableCredential'
import verifiableData from './shared/verifiableData'
import handleSdrMessage from './shared/handleSdrMessage'
import resolveDid from './shared/resolveDid'
import webDidFlow from './shared/webDidFlow'
Expand Down Expand Up @@ -164,7 +164,7 @@ const getAgent = () => agent
const testContext = { getAgent, setup, tearDown }

describe('GraphQL integration tests', () => {
createVerifiableCredential(testContext)
verifiableData(testContext)
handleSdrMessage(testContext)
resolveDid(testContext)
webDidFlow(testContext)
Expand Down
4 changes: 2 additions & 2 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
import fs from 'fs'

// Shared tests
import createVerifiableCredential from './shared/createVerifiableCredential'
import verifiableData from './shared/verifiableData'
import handleSdrMessage from './shared/handleSdrMessage'
import resolveDid from './shared/resolveDid'
import webDidFlow from './shared/webDidFlow'
Expand Down Expand Up @@ -143,7 +143,7 @@ const getAgent = () => agent
const testContext = { getAgent, setup, tearDown }

describe('Local integration tests', () => {
createVerifiableCredential(testContext)
verifiableData(testContext)
handleSdrMessage(testContext)
resolveDid(testContext)
webDidFlow(testContext)
Expand Down
4 changes: 2 additions & 2 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { AgentRouter } from '../packages/daf-express/src'
import fs from 'fs'

// Shared tests
import createVerifiableCredential from './shared/createVerifiableCredential'
import verifiableData from './shared/verifiableData'
import handleSdrMessage from './shared/handleSdrMessage'
import resolveDid from './shared/resolveDid'
import webDidFlow from './shared/webDidFlow'
Expand Down Expand Up @@ -157,7 +157,7 @@ const getAgent = () => agent
const testContext = { getAgent, setup, tearDown }

describe('REST integration tests', () => {
createVerifiableCredential(testContext)
verifiableData(testContext)
handleSdrMessage(testContext)
resolveDid(testContext)
webDidFlow(testContext)
Expand Down
47 changes: 0 additions & 47 deletions __tests__/shared/createVerifiableCredential.ts

This file was deleted.

103 changes: 103 additions & 0 deletions __tests__/shared/verifiableData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { TAgent, IIdentityManager, IIdentity, IDataStore } from '../../packages/daf-core/src'
import { IDataStoreORM } from '../../packages/daf-typeorm/src'
import { ICredentialIssuer } from '../../packages/daf-w3c/src'

type ConfiguredAgent = TAgent<IIdentityManager & ICredentialIssuer & IDataStore & IDataStoreORM>

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

beforeAll(() => {
testContext.setup()
agent = testContext.getAgent()
})
afterAll(testContext.tearDown)

it('should create identity', async () => {
identity = await agent.identityManagerCreateIdentity({ kms: 'local' })
expect(identity).toHaveProperty('did')
})

it('should create verifiable credential', async () => {
const verifiableCredential = await agent.createVerifiableCredential({
credential: {
issuer: { id: identity.did },
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: 'did:web:example.com',
you: 'Rock',
},
},
proofFormat: 'jwt',
})

expect(verifiableCredential).toHaveProperty('proof.jwt')

const hash = await agent.dataStoreSaveVerifiableCredential({ verifiableCredential })
expect(typeof hash).toEqual('string')

const verifiableCredential2 = await agent.dataStoreGetVerifiableCredential({ hash })
expect(verifiableCredential).toEqual(verifiableCredential2)
})

it('should create verifiable presentation', async () => {
const verifiableCredential = await agent.createVerifiableCredential({
credential: {
issuer: { id: identity.did },
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiableCredential'],
issuanceDate: new Date().toISOString(),
credentialSubject: {
id: 'did:web:example.com',
you: 'Rock',
},
},
proofFormat: 'jwt',
})

const verifiablePresentation = await agent.createVerifiablePresentation({
presentation: {
holder: identity.did,
verifier: [],
'@context': ['https://www.w3.org/2018/credentials/v1'],
type: ['VerifiablePresentation'],
issuanceDate: new Date().toISOString(),
verifiableCredential: [verifiableCredential],
},
proofFormat: 'jwt',
})

expect(verifiablePresentation).toHaveProperty('proof.jwt')

const hash = await agent.dataStoreSaveVerifiablePresentation({ verifiablePresentation })
expect(typeof hash).toEqual('string')

const verifiablePresentation2 = await agent.dataStoreGetVerifiablePresentation({ hash })
expect(verifiablePresentation).toEqual(verifiablePresentation2)
})

it('should query for credentials', async () => {
const allCredentials = await agent.dataStoreORMGetVerifiableCredentials({})
expect(allCredentials[0]).toHaveProperty('hash')
expect(allCredentials[0]).toHaveProperty('verifiableCredential')
const credentialCount = await agent.dataStoreORMGetVerifiableCredentialsCount()
expect(allCredentials.length).toEqual(credentialCount)
})

it('should query for presentations', async () => {
const allPresentations = await agent.dataStoreORMGetVerifiablePresentations({})
expect(allPresentations[0]).toHaveProperty('hash')
expect(allPresentations[0]).toHaveProperty('verifiablePresentation')
const presentationCount = await agent.dataStoreORMGetVerifiablePresentationsCount()
expect(allPresentations.length).toEqual(presentationCount)
})
})
}
26 changes: 26 additions & 0 deletions docs/api/daf-core.idatastore.datastoregetmessage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IDataStore](./daf-core.idatastore.md) &gt; [dataStoreGetMessage](./daf-core.idatastore.datastoregetmessage.md)

## IDataStore.dataStoreGetMessage() method

Gets message from the data store

<b>Signature:</b>

```typescript
dataStoreGetMessage(args: IDataStoreGetMessageArgs): Promise<IMessage>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [IDataStoreGetMessageArgs](./daf-core.idatastoregetmessageargs.md) | arguments for getting message |

<b>Returns:</b>

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

a promise that resolves to the message

26 changes: 26 additions & 0 deletions docs/api/daf-core.idatastore.datastoregetverifiablecredential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IDataStore](./daf-core.idatastore.md) &gt; [dataStoreGetVerifiableCredential](./daf-core.idatastore.datastoregetverifiablecredential.md)

## IDataStore.dataStoreGetVerifiableCredential() method

Gets verifiable credential from the data store

<b>Signature:</b>

```typescript
dataStoreGetVerifiableCredential(args: IDataStoreGetVerifiableCredentialArgs): Promise<VerifiableCredential>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [IDataStoreGetVerifiableCredentialArgs](./daf-core.idatastoregetverifiablecredentialargs.md) | arguments for getting verifiable credential |

<b>Returns:</b>

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

a promise that resolves to the verifiable credential

26 changes: 26 additions & 0 deletions docs/api/daf-core.idatastore.datastoregetverifiablepresentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-core](./daf-core.md) &gt; [IDataStore](./daf-core.idatastore.md) &gt; [dataStoreGetVerifiablePresentation](./daf-core.idatastore.datastoregetverifiablepresentation.md)

## IDataStore.dataStoreGetVerifiablePresentation() method

Gets verifiable presentation from the data store

<b>Signature:</b>

```typescript
dataStoreGetVerifiablePresentation(args: IDataStoreGetVerifiablePresentationArgs): Promise<VerifiablePresentation>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [IDataStoreGetVerifiablePresentationArgs](./daf-core.idatastoregetverifiablepresentationargs.md) | arguments for getting Verifiable Presentation |

<b>Returns:</b>

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

a promise that resolves to the Verifiable Presentation

8 changes: 4 additions & 4 deletions docs/api/daf-core.idatastore.datastoresavemessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Saves message to the data store
<b>Signature:</b>

```typescript
dataStoreSaveMessage(args: IMessage): Promise<boolean>;
dataStoreSaveMessage(args: IDataStoreSaveMessageArgs): Promise<string>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [IMessage](./daf-core.imessage.md) | message |
| args | [IDataStoreSaveMessageArgs](./daf-core.idatastoresavemessageargs.md) | message |

<b>Returns:</b>

Promise&lt;boolean&gt;
Promise&lt;string&gt;

`true` if successful
a promise that resolves to the id of the message

Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Saves verifiable credential to the data store
<b>Signature:</b>

```typescript
dataStoreSaveVerifiableCredential(args: VerifiableCredential): Promise<boolean>;
dataStoreSaveVerifiableCredential(args: IDataStoreSaveVerifiableCredentialArgs): Promise<string>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [VerifiableCredential](./daf-core.verifiablecredential.md) | verifiable credential |
| args | [IDataStoreSaveVerifiableCredentialArgs](./daf-core.idatastoresaveverifiablecredentialargs.md) | verifiable credential |

<b>Returns:</b>

Promise&lt;boolean&gt;
Promise&lt;string&gt;

`true` if successful
a promise that resolves to the hash of the VerifiableCredential

Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ Saves verifiable presentation to the data store
<b>Signature:</b>

```typescript
dataStoreSaveVerifiablePresentation(args: VerifiablePresentation): Promise<boolean>;
dataStoreSaveVerifiablePresentation(args: IDataStoreSaveVerifiablePresentationArgs): Promise<string>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [VerifiablePresentation](./daf-core.verifiablepresentation.md) | verifiable presentation |
| args | [IDataStoreSaveVerifiablePresentationArgs](./daf-core.idatastoresaveverifiablepresentationargs.md) | verifiable presentation |

<b>Returns:</b>

Promise&lt;boolean&gt;
Promise&lt;string&gt;

`true` if successful
a promise that resolves to the hash of the VerifiablePresentation

3 changes: 3 additions & 0 deletions docs/api/daf-core.idatastore.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export interface IDataStore extends IPluginMethodMap
| Method | Description |
| --- | --- |
| [dataStoreGetMessage(args)](./daf-core.idatastore.datastoregetmessage.md) | Gets message from the data store |
| [dataStoreGetVerifiableCredential(args)](./daf-core.idatastore.datastoregetverifiablecredential.md) | Gets verifiable credential from the data store |
| [dataStoreGetVerifiablePresentation(args)](./daf-core.idatastore.datastoregetverifiablepresentation.md) | Gets verifiable presentation from the data store |
| [dataStoreSaveMessage(args)](./daf-core.idatastore.datastoresavemessage.md) | Saves message to the data store |
| [dataStoreSaveVerifiableCredential(args)](./daf-core.idatastore.datastoresaveverifiablecredential.md) | Saves verifiable credential to the data store |
| [dataStoreSaveVerifiablePresentation(args)](./daf-core.idatastore.datastoresaveverifiablepresentation.md) | Saves verifiable presentation to the data store |
Expand Down
13 changes: 13 additions & 0 deletions docs/api/daf-core.idatastoregetmessageargs.id.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; [IDataStoreGetMessageArgs](./daf-core.idatastoregetmessageargs.md) &gt; [id](./daf-core.idatastoregetmessageargs.id.md)

## IDataStoreGetMessageArgs.id property

Required. Message ID

<b>Signature:</b>

```typescript
id: string;
```
Loading

0 comments on commit bcfc3e8

Please sign in to comment.