Skip to content

Commit

Permalink
refactor: Refactor and add inline documentation to daf-w3c package
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the `IW3c` type and `W3c` class have been renamed to
`ICredentialIssuer` and `CredentialIssuer`

fix(deps): update `did-resolver` and `did-jwt` libs for all packages to maintain type consistency
  • Loading branch information
mirceanis committed Sep 7, 2020
1 parent 72d6da2 commit f0e2cb9
Show file tree
Hide file tree
Showing 61 changed files with 540 additions and 323 deletions.
6 changes: 3 additions & 3 deletions __tests__/graphqlAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IdentityManager } from 'daf-identity-manager'
import { createConnection, Connection } from 'typeorm'
import { DafResolver } from 'daf-resolver'
import { JwtMessageHandler } from 'daf-did-jwt'
import { W3c, IW3c, W3cMessageHandler } from 'daf-w3c'
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'
Expand Down Expand Up @@ -47,7 +47,7 @@ const agent = createAgent<
IResolveDid &
IMessageHandler &
IDIDComm &
IW3c &
ICredentialIssuer &
ISdr
>({
plugins: [
Expand Down Expand Up @@ -106,7 +106,7 @@ const setup = async (): Promise<boolean> => {
],
}),
new DIDComm(),
new W3c(),
new CredentialIssuer(),
new Sdr(),
],
})
Expand Down
8 changes: 4 additions & 4 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { IdentityManager } from 'daf-identity-manager'
import { createConnection, Connection } from 'typeorm'
import { DafResolver } from 'daf-resolver'
import { JwtMessageHandler } from 'daf-did-jwt'
import { W3c, IW3c, W3cMessageHandler } from 'daf-w3c'
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'
Expand Down Expand Up @@ -41,7 +41,7 @@ let agent: TAgent<
IResolveDid &
IMessageHandler &
IDIDComm &
IW3c &
ICredentialIssuer &
ISdr
>
let dbConnection: Promise<Connection>
Expand All @@ -63,7 +63,7 @@ const setup = async (): Promise<boolean> => {
IResolveDid &
IMessageHandler &
IDIDComm &
IW3c &
ICredentialIssuer &
ISdr
>({
context: {
Expand Down Expand Up @@ -104,7 +104,7 @@ const setup = async (): Promise<boolean> => {
],
}),
new DIDComm(),
new W3c(),
new CredentialIssuer(),
new Sdr(),
],
})
Expand Down
6 changes: 3 additions & 3 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { IdentityManager } from 'daf-identity-manager'
import { createConnection, Connection } from 'typeorm'
import { DafResolver } from 'daf-resolver'
import { JwtMessageHandler } from 'daf-did-jwt'
import { W3c, IW3c, W3cMessageHandler } from 'daf-w3c'
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'
Expand Down Expand Up @@ -46,7 +46,7 @@ const agent = createAgent<
IResolveDid &
IMessageHandler &
IDIDComm &
IW3c &
ICredentialIssuer &
ISdr
>({
plugins: [
Expand Down Expand Up @@ -105,7 +105,7 @@ const setup = async (): Promise<boolean> => {
],
}),
new DIDComm(),
new W3c(),
new CredentialIssuer(),
new Sdr(),
],
})
Expand Down
4 changes: 2 additions & 2 deletions __tests__/shared/createVerifiableCredential.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TAgent, IIdentityManager, IIdentity } from 'daf-core'
import { IW3c } from 'daf-w3c'
import { ICredentialIssuer } from 'daf-w3c'

type ConfiguredAgent = TAgent<IIdentityManager & IW3c>
type ConfiguredAgent = TAgent<IIdentityManager & ICredentialIssuer>

export default (testContext: {
getAgent: () => ConfiguredAgent
Expand Down
6 changes: 4 additions & 2 deletions __tests__/shared/handleSdrMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { TAgent, IIdentityManager, IIdentity, IDataStore, IMessageHandler } from 'daf-core'
import { IW3c } from 'daf-w3c'
import { ICredentialIssuer } from 'daf-w3c'
import { ISdr } from 'daf-selective-disclosure'
import { IDataStoreORM } from 'daf-typeorm'

type ConfiguredAgent = TAgent<IIdentityManager & IW3c & IDataStoreORM & IDataStore & IMessageHandler & ISdr>
type ConfiguredAgent = TAgent<
IIdentityManager & ICredentialIssuer & IDataStoreORM & IDataStore & IMessageHandler & ISdr
>

export default (testContext: {
getAgent: () => ConfiguredAgent
Expand Down
6 changes: 4 additions & 2 deletions __tests__/shared/saveClaims.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { TAgent, IIdentityManager, IIdentity, IDataStore, IMessageHandler } from 'daf-core'
import { IW3c } from 'daf-w3c'
import { ICredentialIssuer } from 'daf-w3c'
import { ISdr } from 'daf-selective-disclosure'
import { IDataStoreORM } from 'daf-typeorm'

type ConfiguredAgent = TAgent<IIdentityManager & IW3c & IDataStoreORM & IDataStore & IMessageHandler & ISdr>
type ConfiguredAgent = TAgent<
IIdentityManager & ICredentialIssuer & IDataStoreORM & IDataStore & IMessageHandler & ISdr
>

export default (testContext: {
getAgent: () => ConfiguredAgent
Expand Down
4 changes: 2 additions & 2 deletions __tests__/shared/webDidFlow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TAgent, IIdentityManager, IIdentity, IKey } from 'daf-core'
import { IW3c } from 'daf-w3c'
import { ICredentialIssuer } from 'daf-w3c'

type ConfiguredAgent = TAgent<IIdentityManager & IW3c>
type ConfiguredAgent = TAgent<IIdentityManager & ICredentialIssuer>

export default (testContext: {
getAgent: () => ConfiguredAgent
Expand Down
6 changes: 3 additions & 3 deletions docs/api/daf-core.createagent.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ Use [TAgent](./daf-core.tagent.md) to configure agent type (list of available me
```typescript
import { createAgent, IResolveDid, IMessageHandler } from 'daf-core'
import { AgentRestClient } from 'daf-rest'
import { W3c, IW3c } from 'daf-w3c'
const agent = createAgent<IResolveDid & IMessageHandler & IW3c>({
import { CredentialIssuer, ICredentialIssuer } from 'daf-w3c'
const agent = createAgent<IResolveDid & IMessageHandler & ICredentialIssuer>({
plugins: [
new W3c(),
new CredentialIssuer(),
new AgentRestClient({
url: 'http://localhost:3002/agent',
enabledMethods: [
Expand Down
2 changes: 1 addition & 1 deletion docs/api/daf-typeorm.entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
Entities: (typeof Key | typeof Identity | typeof Service | typeof Claim | typeof Credential | typeof Presentation | typeof Message)[]
Entities: (typeof Credential | typeof Identity | typeof Claim | typeof Presentation | typeof Message | typeof Key | typeof Service)[]
```
13 changes: 13 additions & 0 deletions docs/api/daf-w3c.credentialissuer._constructor_.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-w3c](./daf-w3c.md) &gt; [CredentialIssuer](./daf-w3c.credentialissuer.md) &gt; [(constructor)](./daf-w3c.credentialissuer._constructor_.md)

## CredentialIssuer.(constructor)

Constructs a new instance of the `CredentialIssuer` class

<b>Signature:</b>

```typescript
constructor();
```
31 changes: 31 additions & 0 deletions docs/api/daf-w3c.credentialissuer.createverifiablecredential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-w3c](./daf-w3c.md) &gt; [CredentialIssuer](./daf-w3c.credentialissuer.md) &gt; [createVerifiableCredential](./daf-w3c.credentialissuer.createverifiablecredential.md)

## CredentialIssuer.createVerifiableCredential() method

Creates a Verifiable Credential. The payload, signer and format are chosen based on the `args` parameter.

<b>Signature:</b>

```typescript
createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext): Promise<VerifiableCredential>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [ICreateVerifiableCredentialArgs](./daf-w3c.icreateverifiablecredentialargs.md) | Arguments necessary to create the Presentation. |
| context | IContext | This reserved param is automatically added and handled by the framework, \*do not override\* |

<b>Returns:</b>

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

- a promise that resolves to the [VerifiableCredential](./daf-core.verifiablecredential.md) that was requested or rejects with an error if there was a problem with the input or while getting the key to sign

## Remarks

Please see [Verifiable Credential data model](https://www.w3.org/TR/vc-data-model/#credentials)

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

[Home](./index.md) &gt; [daf-w3c](./daf-w3c.md) &gt; [CredentialIssuer](./daf-w3c.credentialissuer.md) &gt; [createVerifiablePresentation](./daf-w3c.credentialissuer.createverifiablepresentation.md)

## CredentialIssuer.createVerifiablePresentation() method

Creates a Verifiable Presentation. The payload, signer and format are chosen based on the `args` parameter.

<b>Signature:</b>

```typescript
createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext): Promise<VerifiablePresentation>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| args | [ICreateVerifiablePresentationArgs](./daf-w3c.icreateverifiablepresentationargs.md) | Arguments necessary to create the Presentation. |
| context | IContext | This reserved param is automatically added and handled by the framework, \*do not override\* |

<b>Returns:</b>

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

- a promise that resolves to the [VerifiablePresentation](./daf-core.verifiablepresentation.md) that was requested or rejects with an error if there was a problem with the input or while getting the key to sign

## Remarks

Please see [Verifiable Presentation data model](https://www.w3.org/TR/vc-data-model/#presentations)

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

[Home](./index.md) &gt; [daf-w3c](./daf-w3c.md) &gt; [CredentialIssuer](./daf-w3c.credentialissuer.md)

## CredentialIssuer class

A DAF plugin that implements the [ICredentialIssuer](./daf-w3c.icredentialissuer.md) methods.

<b>Signature:</b>

```typescript
export declare class CredentialIssuer implements IAgentPlugin
```
<b>Implements:</b> [IAgentPlugin](./daf-core.iagentplugin.md)
## Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)()](./daf-w3c.credentialissuer._constructor_.md) | | Constructs a new instance of the <code>CredentialIssuer</code> class |
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [methods](./daf-w3c.credentialissuer.methods.md) | | [ICredentialIssuer](./daf-w3c.icredentialissuer.md) | |
## Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [createVerifiableCredential(args, context)](./daf-w3c.credentialissuer.createverifiablecredential.md) | | Creates a Verifiable Credential. The payload, signer and format are chosen based on the <code>args</code> parameter. |
| [createVerifiablePresentation(args, context)](./daf-w3c.credentialissuer.createverifiablepresentation.md) | | Creates a Verifiable Presentation. The payload, signer and format are chosen based on the <code>args</code> parameter. |
11 changes: 11 additions & 0 deletions docs/api/daf-w3c.credentialissuer.methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [daf-w3c](./daf-w3c.md) &gt; [CredentialIssuer](./daf-w3c.credentialissuer.md) &gt; [methods](./daf-w3c.credentialissuer.methods.md)

## CredentialIssuer.methods property

<b>Signature:</b>

```typescript
readonly methods: ICredentialIssuer;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## ICreateVerifiableCredentialArgs.credential property

The json payload of the Credential according to the [canonical model](https://www.w3.org/TR/vc-data-model/#credentials)

The signer of the Credential is chosen based on the `issuer.id` property of the `credential`

<b>Signature:</b>

```typescript
Expand Down
8 changes: 5 additions & 3 deletions docs/api/daf-w3c.icreateverifiablecredentialargs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## ICreateVerifiableCredentialArgs interface

Encapsulates the parameters required to create a [W3C Verifiable Credential](https://www.w3.org/TR/vc-data-model/#credentials)

<b>Signature:</b>

```typescript
Expand All @@ -14,7 +16,7 @@ export interface ICreateVerifiableCredentialArgs

| Property | Type | Description |
| --- | --- | --- |
| [credential](./daf-w3c.icreateverifiablecredentialargs.credential.md) | W3CCredential | |
| [proofFormat](./daf-w3c.icreateverifiablecredentialargs.proofformat.md) | 'jwt' | |
| [save](./daf-w3c.icreateverifiablecredentialargs.save.md) | boolean | |
| [credential](./daf-w3c.icreateverifiablecredentialargs.credential.md) | W3CCredential | The json payload of the Credential according to the [canonical model](https://www.w3.org/TR/vc-data-model/#credentials)<!-- -->The signer of the Credential is chosen based on the <code>issuer.id</code> property of the <code>credential</code> |
| [proofFormat](./daf-w3c.icreateverifiablecredentialargs.proofformat.md) | EncodingFormat | The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported |
| [save](./daf-w3c.icreateverifiablecredentialargs.save.md) | boolean | If this parameter is true, the resulting VerifiablePresentation is sent to the [storage plugin](./daf-core.idatastore.md) to be saved |

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

## ICreateVerifiableCredentialArgs.proofFormat property

The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported

<b>Signature:</b>

```typescript
proofFormat: 'jwt';
proofFormat: EncodingFormat;
```
2 changes: 2 additions & 0 deletions docs/api/daf-w3c.icreateverifiablecredentialargs.save.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## ICreateVerifiableCredentialArgs.save property

If this parameter is true, the resulting VerifiablePresentation is sent to the [storage plugin](./daf-core.idatastore.md) to be saved

<b>Signature:</b>

```typescript
Expand Down
8 changes: 5 additions & 3 deletions docs/api/daf-w3c.icreateverifiablepresentationargs.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## ICreateVerifiablePresentationArgs interface

Encapsulates the parameters required to create a [W3C Verifiable Presentation](https://www.w3.org/TR/vc-data-model/#presentations)

<b>Signature:</b>

```typescript
Expand All @@ -14,7 +16,7 @@ export interface ICreateVerifiablePresentationArgs

| Property | Type | Description |
| --- | --- | --- |
| [presentation](./daf-w3c.icreateverifiablepresentationargs.presentation.md) | W3CPresentation | |
| [proofFormat](./daf-w3c.icreateverifiablepresentationargs.proofformat.md) | 'jwt' | |
| [save](./daf-w3c.icreateverifiablepresentationargs.save.md) | boolean | |
| [presentation](./daf-w3c.icreateverifiablepresentationargs.presentation.md) | W3CPresentation | The json payload of the Presentation according to the [canonical model](https://www.w3.org/TR/vc-data-model/#presentations)<!-- -->.<!-- -->The signer of the Presentation is chosen based on the <code>holder</code> property of the <code>presentation</code> |
| [proofFormat](./daf-w3c.icreateverifiablepresentationargs.proofformat.md) | EncodingFormat | The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported |
| [save](./daf-w3c.icreateverifiablepresentationargs.save.md) | boolean | If this parameter is true, the resulting VerifiablePresentation is sent to the [storage plugin](./daf-core.idatastore.md) to be saved |

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## ICreateVerifiablePresentationArgs.presentation property

The json payload of the Presentation according to the [canonical model](https://www.w3.org/TR/vc-data-model/#presentations)<!-- -->.

The signer of the Presentation is chosen based on the `holder` property of the `presentation`

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

## ICreateVerifiablePresentationArgs.proofFormat property

The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported

<b>Signature:</b>

```typescript
proofFormat: 'jwt';
proofFormat: EncodingFormat;
```
2 changes: 2 additions & 0 deletions docs/api/daf-w3c.icreateverifiablepresentationargs.save.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## ICreateVerifiablePresentationArgs.save property

If this parameter is true, the resulting VerifiablePresentation is sent to the [storage plugin](./daf-core.idatastore.md) to be saved

<b>Signature:</b>

```typescript
Expand Down
Loading

0 comments on commit f0e2cb9

Please sign in to comment.