diff --git a/__tests__/graphqlAgent.test.ts b/__tests__/graphqlAgent.test.ts index f5982b2da..a4f6fbb3f 100644 --- a/__tests__/graphqlAgent.test.ts +++ b/__tests__/graphqlAgent.test.ts @@ -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' @@ -47,7 +47,7 @@ const agent = createAgent< IResolveDid & IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ plugins: [ @@ -106,7 +106,7 @@ const setup = async (): Promise => { ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) diff --git a/__tests__/localAgent.test.ts b/__tests__/localAgent.test.ts index 8a2df1cf5..97aeadd49 100644 --- a/__tests__/localAgent.test.ts +++ b/__tests__/localAgent.test.ts @@ -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' @@ -41,7 +41,7 @@ let agent: TAgent< IResolveDid & IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr > let dbConnection: Promise @@ -63,7 +63,7 @@ const setup = async (): Promise => { IResolveDid & IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ context: { @@ -104,7 +104,7 @@ const setup = async (): Promise => { ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) diff --git a/__tests__/restAgent.test.ts b/__tests__/restAgent.test.ts index 9c52a2aba..bead1b577 100644 --- a/__tests__/restAgent.test.ts +++ b/__tests__/restAgent.test.ts @@ -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' @@ -46,7 +46,7 @@ const agent = createAgent< IResolveDid & IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ plugins: [ @@ -105,7 +105,7 @@ const setup = async (): Promise => { ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) diff --git a/__tests__/shared/createVerifiableCredential.ts b/__tests__/shared/createVerifiableCredential.ts index d44b43d56..4a62288b5 100644 --- a/__tests__/shared/createVerifiableCredential.ts +++ b/__tests__/shared/createVerifiableCredential.ts @@ -1,7 +1,7 @@ import { TAgent, IIdentityManager, IIdentity } from 'daf-core' -import { IW3c } from 'daf-w3c' +import { ICredentialIssuer } from 'daf-w3c' -type ConfiguredAgent = TAgent +type ConfiguredAgent = TAgent export default (testContext: { getAgent: () => ConfiguredAgent diff --git a/__tests__/shared/handleSdrMessage.ts b/__tests__/shared/handleSdrMessage.ts index 693593af0..717da4455 100644 --- a/__tests__/shared/handleSdrMessage.ts +++ b/__tests__/shared/handleSdrMessage.ts @@ -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 +type ConfiguredAgent = TAgent< + IIdentityManager & ICredentialIssuer & IDataStoreORM & IDataStore & IMessageHandler & ISdr +> export default (testContext: { getAgent: () => ConfiguredAgent diff --git a/__tests__/shared/saveClaims.ts b/__tests__/shared/saveClaims.ts index 7b5bba3ac..276f21b19 100644 --- a/__tests__/shared/saveClaims.ts +++ b/__tests__/shared/saveClaims.ts @@ -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 +type ConfiguredAgent = TAgent< + IIdentityManager & ICredentialIssuer & IDataStoreORM & IDataStore & IMessageHandler & ISdr +> export default (testContext: { getAgent: () => ConfiguredAgent diff --git a/__tests__/shared/webDidFlow.ts b/__tests__/shared/webDidFlow.ts index dd551ba72..15a98307c 100644 --- a/__tests__/shared/webDidFlow.ts +++ b/__tests__/shared/webDidFlow.ts @@ -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 +type ConfiguredAgent = TAgent export default (testContext: { getAgent: () => ConfiguredAgent diff --git a/docs/api/daf-core.createagent.md b/docs/api/daf-core.createagent.md index 1e1689116..206cf3924 100644 --- a/docs/api/daf-core.createagent.md +++ b/docs/api/daf-core.createagent.md @@ -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({ +import { CredentialIssuer, ICredentialIssuer } from 'daf-w3c' +const agent = createAgent({ plugins: [ - new W3c(), + new CredentialIssuer(), new AgentRestClient({ url: 'http://localhost:3002/agent', enabledMethods: [ diff --git a/docs/api/daf-typeorm.entities.md b/docs/api/daf-typeorm.entities.md index 20b846427..99873d3de 100644 --- a/docs/api/daf-typeorm.entities.md +++ b/docs/api/daf-typeorm.entities.md @@ -7,5 +7,5 @@ Signature: ```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)[] ``` diff --git a/docs/api/daf-w3c.credentialissuer._constructor_.md b/docs/api/daf-w3c.credentialissuer._constructor_.md new file mode 100644 index 000000000..3289c1a77 --- /dev/null +++ b/docs/api/daf-w3c.credentialissuer._constructor_.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [CredentialIssuer](./daf-w3c.credentialissuer.md) > [(constructor)](./daf-w3c.credentialissuer._constructor_.md) + +## CredentialIssuer.(constructor) + +Constructs a new instance of the `CredentialIssuer` class + +Signature: + +```typescript +constructor(); +``` diff --git a/docs/api/daf-w3c.credentialissuer.createverifiablecredential.md b/docs/api/daf-w3c.credentialissuer.createverifiablecredential.md new file mode 100644 index 000000000..08ff7aa43 --- /dev/null +++ b/docs/api/daf-w3c.credentialissuer.createverifiablecredential.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [CredentialIssuer](./daf-w3c.credentialissuer.md) > [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. + +Signature: + +```typescript +createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext): Promise; +``` + +## 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\* | + +Returns: + +Promise<[VerifiableCredential](./daf-core.verifiablecredential.md)> + +- 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) + diff --git a/docs/api/daf-w3c.credentialissuer.createverifiablepresentation.md b/docs/api/daf-w3c.credentialissuer.createverifiablepresentation.md new file mode 100644 index 000000000..f6abf2556 --- /dev/null +++ b/docs/api/daf-w3c.credentialissuer.createverifiablepresentation.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [CredentialIssuer](./daf-w3c.credentialissuer.md) > [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. + +Signature: + +```typescript +createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext): Promise; +``` + +## 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\* | + +Returns: + +Promise<[VerifiablePresentation](./daf-core.verifiablepresentation.md)> + +- 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) + diff --git a/docs/api/daf-w3c.credentialissuer.md b/docs/api/daf-w3c.credentialissuer.md new file mode 100644 index 000000000..81e8b4763 --- /dev/null +++ b/docs/api/daf-w3c.credentialissuer.md @@ -0,0 +1,34 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [CredentialIssuer](./daf-w3c.credentialissuer.md) + +## CredentialIssuer class + +A DAF plugin that implements the [ICredentialIssuer](./daf-w3c.icredentialissuer.md) methods. + +Signature: + +```typescript +export declare class CredentialIssuer implements IAgentPlugin +``` +Implements: [IAgentPlugin](./daf-core.iagentplugin.md) + +## Constructors + +| Constructor | Modifiers | Description | +| --- | --- | --- | +| [(constructor)()](./daf-w3c.credentialissuer._constructor_.md) | | Constructs a new instance of the CredentialIssuer 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 args parameter. | +| [createVerifiablePresentation(args, context)](./daf-w3c.credentialissuer.createverifiablepresentation.md) | | Creates a Verifiable Presentation. The payload, signer and format are chosen based on the args parameter. | + diff --git a/docs/api/daf-w3c.credentialissuer.methods.md b/docs/api/daf-w3c.credentialissuer.methods.md new file mode 100644 index 000000000..7f6cc585c --- /dev/null +++ b/docs/api/daf-w3c.credentialissuer.methods.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [CredentialIssuer](./daf-w3c.credentialissuer.md) > [methods](./daf-w3c.credentialissuer.methods.md) + +## CredentialIssuer.methods property + +Signature: + +```typescript +readonly methods: ICredentialIssuer; +``` diff --git a/docs/api/daf-w3c.icreateverifiablecredentialargs.credential.md b/docs/api/daf-w3c.icreateverifiablecredentialargs.credential.md index 4e0a20999..e51c1feef 100644 --- a/docs/api/daf-w3c.icreateverifiablecredentialargs.credential.md +++ b/docs/api/daf-w3c.icreateverifiablecredentialargs.credential.md @@ -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` + Signature: ```typescript diff --git a/docs/api/daf-w3c.icreateverifiablecredentialargs.md b/docs/api/daf-w3c.icreateverifiablecredentialargs.md index d3ed95c2c..e30983c6a 100644 --- a/docs/api/daf-w3c.icreateverifiablecredentialargs.md +++ b/docs/api/daf-w3c.icreateverifiablecredentialargs.md @@ -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) + Signature: ```typescript @@ -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 issuer.id property of the credential | +| [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 | diff --git a/docs/api/daf-w3c.icreateverifiablecredentialargs.proofformat.md b/docs/api/daf-w3c.icreateverifiablecredentialargs.proofformat.md index 81b477874..579a65581 100644 --- a/docs/api/daf-w3c.icreateverifiablecredentialargs.proofformat.md +++ b/docs/api/daf-w3c.icreateverifiablecredentialargs.proofformat.md @@ -4,8 +4,10 @@ ## ICreateVerifiableCredentialArgs.proofFormat property +The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported + Signature: ```typescript -proofFormat: 'jwt'; +proofFormat: EncodingFormat; ``` diff --git a/docs/api/daf-w3c.icreateverifiablecredentialargs.save.md b/docs/api/daf-w3c.icreateverifiablecredentialargs.save.md index a034a6b1d..56226f2da 100644 --- a/docs/api/daf-w3c.icreateverifiablecredentialargs.save.md +++ b/docs/api/daf-w3c.icreateverifiablecredentialargs.save.md @@ -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 + Signature: ```typescript diff --git a/docs/api/daf-w3c.icreateverifiablepresentationargs.md b/docs/api/daf-w3c.icreateverifiablepresentationargs.md index c29cecf3c..8040e3d9d 100644 --- a/docs/api/daf-w3c.icreateverifiablepresentationargs.md +++ b/docs/api/daf-w3c.icreateverifiablepresentationargs.md @@ -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) + Signature: ```typescript @@ -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 holder property of the presentation | +| [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 | diff --git a/docs/api/daf-w3c.icreateverifiablepresentationargs.presentation.md b/docs/api/daf-w3c.icreateverifiablepresentationargs.presentation.md index a1e1c9feb..13e99f386 100644 --- a/docs/api/daf-w3c.icreateverifiablepresentationargs.presentation.md +++ b/docs/api/daf-w3c.icreateverifiablepresentationargs.presentation.md @@ -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` + Signature: ```typescript diff --git a/docs/api/daf-w3c.icreateverifiablepresentationargs.proofformat.md b/docs/api/daf-w3c.icreateverifiablepresentationargs.proofformat.md index 20a5d359a..82941639e 100644 --- a/docs/api/daf-w3c.icreateverifiablepresentationargs.proofformat.md +++ b/docs/api/daf-w3c.icreateverifiablepresentationargs.proofformat.md @@ -4,8 +4,10 @@ ## ICreateVerifiablePresentationArgs.proofFormat property +The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported + Signature: ```typescript -proofFormat: 'jwt'; +proofFormat: EncodingFormat; ``` diff --git a/docs/api/daf-w3c.icreateverifiablepresentationargs.save.md b/docs/api/daf-w3c.icreateverifiablepresentationargs.save.md index 79d5b0327..29e077e08 100644 --- a/docs/api/daf-w3c.icreateverifiablepresentationargs.save.md +++ b/docs/api/daf-w3c.icreateverifiablepresentationargs.save.md @@ -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 + Signature: ```typescript diff --git a/docs/api/daf-w3c.icredentialissuer.createverifiablecredential.md b/docs/api/daf-w3c.icredentialissuer.createverifiablecredential.md new file mode 100644 index 000000000..e013e938a --- /dev/null +++ b/docs/api/daf-w3c.icredentialissuer.createverifiablecredential.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [ICredentialIssuer](./daf-w3c.icredentialissuer.md) > [createVerifiableCredential](./daf-w3c.icredentialissuer.createverifiablecredential.md) + +## ICredentialIssuer.createVerifiableCredential() method + +Creates a Verifiable Credential. The payload, signer and format are chosen based on the `args` parameter. + +Signature: + +```typescript +createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext): Promise; +``` + +## 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\* | + +Returns: + +Promise<[VerifiableCredential](./daf-core.verifiablecredential.md)> + +- 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) + diff --git a/docs/api/daf-w3c.icredentialissuer.createverifiablepresentation.md b/docs/api/daf-w3c.icredentialissuer.createverifiablepresentation.md new file mode 100644 index 000000000..fd59c4bf0 --- /dev/null +++ b/docs/api/daf-w3c.icredentialissuer.createverifiablepresentation.md @@ -0,0 +1,31 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [ICredentialIssuer](./daf-w3c.icredentialissuer.md) > [createVerifiablePresentation](./daf-w3c.icredentialissuer.createverifiablepresentation.md) + +## ICredentialIssuer.createVerifiablePresentation() method + +Creates a Verifiable Presentation. The payload, signer and format are chosen based on the `args` parameter. + +Signature: + +```typescript +createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext): Promise; +``` + +## 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\* | + +Returns: + +Promise<[VerifiablePresentation](./daf-core.verifiablepresentation.md)> + +- 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) + diff --git a/docs/api/daf-w3c.icredentialissuer.md b/docs/api/daf-w3c.icredentialissuer.md new file mode 100644 index 000000000..8b3effb57 --- /dev/null +++ b/docs/api/daf-w3c.icredentialissuer.md @@ -0,0 +1,26 @@ + + +[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [ICredentialIssuer](./daf-w3c.icredentialissuer.md) + +## ICredentialIssuer interface + +The interface definition for a plugin that can generate Verifiable Credentials and Presentations + +Signature: + +```typescript +export interface ICredentialIssuer extends IPluginMethodMap +``` +Extends: [IPluginMethodMap](./daf-core.ipluginmethodmap.md) + +## Remarks + +Please see [W3C Verifiable Credentials data model](https://www.w3.org/TR/vc-data-model) + +## Methods + +| Method | Description | +| --- | --- | +| [createVerifiableCredential(args, context)](./daf-w3c.icredentialissuer.createverifiablecredential.md) | Creates a Verifiable Credential. The payload, signer and format are chosen based on the args parameter. | +| [createVerifiablePresentation(args, context)](./daf-w3c.icredentialissuer.createverifiablepresentation.md) | Creates a Verifiable Presentation. The payload, signer and format are chosen based on the args parameter. | + diff --git a/docs/api/daf-w3c.iw3c.createverifiablecredential.md b/docs/api/daf-w3c.iw3c.createverifiablecredential.md deleted file mode 100644 index 69fee952c..000000000 --- a/docs/api/daf-w3c.iw3c.createverifiablecredential.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [IW3c](./daf-w3c.iw3c.md) > [createVerifiableCredential](./daf-w3c.iw3c.createverifiablecredential.md) - -## IW3c.createVerifiableCredential() method - -Signature: - -```typescript -createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| args | [ICreateVerifiableCredentialArgs](./daf-w3c.icreateverifiablecredentialargs.md) | | -| context | IContext | | - -Returns: - -Promise<[VerifiableCredential](./daf-core.verifiablecredential.md)> - diff --git a/docs/api/daf-w3c.iw3c.createverifiablepresentation.md b/docs/api/daf-w3c.iw3c.createverifiablepresentation.md deleted file mode 100644 index 34e63744a..000000000 --- a/docs/api/daf-w3c.iw3c.createverifiablepresentation.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [IW3c](./daf-w3c.iw3c.md) > [createVerifiablePresentation](./daf-w3c.iw3c.createverifiablepresentation.md) - -## IW3c.createVerifiablePresentation() method - -Signature: - -```typescript -createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| args | [ICreateVerifiablePresentationArgs](./daf-w3c.icreateverifiablepresentationargs.md) | | -| context | IContext | | - -Returns: - -Promise<[VerifiablePresentation](./daf-core.verifiablepresentation.md)> - diff --git a/docs/api/daf-w3c.iw3c.md b/docs/api/daf-w3c.iw3c.md deleted file mode 100644 index b6c865035..000000000 --- a/docs/api/daf-w3c.iw3c.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [IW3c](./daf-w3c.iw3c.md) - -## IW3c interface - -Signature: - -```typescript -export interface IW3c extends IPluginMethodMap -``` -Extends: [IPluginMethodMap](./daf-core.ipluginmethodmap.md) - -## Methods - -| Method | Description | -| --- | --- | -| [createVerifiableCredential(args, context)](./daf-w3c.iw3c.createverifiablecredential.md) | | -| [createVerifiablePresentation(args, context)](./daf-w3c.iw3c.createverifiablepresentation.md) | | - diff --git a/docs/api/daf-w3c.md b/docs/api/daf-w3c.md index bdc0e2360..413a9da44 100644 --- a/docs/api/daf-w3c.md +++ b/docs/api/daf-w3c.md @@ -8,20 +8,14 @@ | Class | Description | | --- | --- | -| [W3c](./daf-w3c.w3c.md) | | -| [W3cMessageHandler](./daf-w3c.w3cmessagehandler.md) | | +| [CredentialIssuer](./daf-w3c.credentialissuer.md) | A DAF plugin that implements the [ICredentialIssuer](./daf-w3c.icredentialissuer.md) methods. | +| [W3cMessageHandler](./daf-w3c.w3cmessagehandler.md) | An implementation of the [AbstractMessageHandler](./daf-message-handler.abstractmessagehandler.md).This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them for internal storage as [Message](./daf-message-handler.message.md) types.The current version can only handle JWT encoded | ## Interfaces | Interface | Description | | --- | --- | -| [ICreateVerifiableCredentialArgs](./daf-w3c.icreateverifiablecredentialargs.md) | | -| [ICreateVerifiablePresentationArgs](./daf-w3c.icreateverifiablepresentationargs.md) | | -| [IW3c](./daf-w3c.iw3c.md) | | - -## Variables - -| Variable | Description | -| --- | --- | -| [MessageTypes](./daf-w3c.messagetypes.md) | | +| [ICreateVerifiableCredentialArgs](./daf-w3c.icreateverifiablecredentialargs.md) | Encapsulates the parameters required to create a [W3C Verifiable Credential](https://www.w3.org/TR/vc-data-model/#credentials) | +| [ICreateVerifiablePresentationArgs](./daf-w3c.icreateverifiablepresentationargs.md) | Encapsulates the parameters required to create a [W3C Verifiable Presentation](https://www.w3.org/TR/vc-data-model/#presentations) | +| [ICredentialIssuer](./daf-w3c.icredentialissuer.md) | The interface definition for a plugin that can generate Verifiable Credentials and Presentations | diff --git a/docs/api/daf-w3c.messagetypes.md b/docs/api/daf-w3c.messagetypes.md deleted file mode 100644 index 9f0b0359e..000000000 --- a/docs/api/daf-w3c.messagetypes.md +++ /dev/null @@ -1,14 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [MessageTypes](./daf-w3c.messagetypes.md) - -## MessageTypes variable - -Signature: - -```typescript -MessageTypes: { - vc: string; - vp: string; -} -``` diff --git a/docs/api/daf-w3c.w3c._constructor_.md b/docs/api/daf-w3c.w3c._constructor_.md deleted file mode 100644 index f5d173972..000000000 --- a/docs/api/daf-w3c.w3c._constructor_.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [W3c](./daf-w3c.w3c.md) > [(constructor)](./daf-w3c.w3c._constructor_.md) - -## W3c.(constructor) - -Constructs a new instance of the `W3c` class - -Signature: - -```typescript -constructor(); -``` diff --git a/docs/api/daf-w3c.w3c.createverifiablecredential.md b/docs/api/daf-w3c.w3c.createverifiablecredential.md deleted file mode 100644 index 6b986dc13..000000000 --- a/docs/api/daf-w3c.w3c.createverifiablecredential.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [W3c](./daf-w3c.w3c.md) > [createVerifiableCredential](./daf-w3c.w3c.createverifiablecredential.md) - -## W3c.createVerifiableCredential() method - -Signature: - -```typescript -createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| args | [ICreateVerifiableCredentialArgs](./daf-w3c.icreateverifiablecredentialargs.md) | | -| context | IContext | | - -Returns: - -Promise<[VerifiableCredential](./daf-core.verifiablecredential.md)> - diff --git a/docs/api/daf-w3c.w3c.createverifiablepresentation.md b/docs/api/daf-w3c.w3c.createverifiablepresentation.md deleted file mode 100644 index 904131656..000000000 --- a/docs/api/daf-w3c.w3c.createverifiablepresentation.md +++ /dev/null @@ -1,23 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [W3c](./daf-w3c.w3c.md) > [createVerifiablePresentation](./daf-w3c.w3c.createverifiablepresentation.md) - -## W3c.createVerifiablePresentation() method - -Signature: - -```typescript -createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| args | [ICreateVerifiablePresentationArgs](./daf-w3c.icreateverifiablepresentationargs.md) | | -| context | IContext | | - -Returns: - -Promise<[VerifiablePresentation](./daf-core.verifiablepresentation.md)> - diff --git a/docs/api/daf-w3c.w3c.md b/docs/api/daf-w3c.w3c.md deleted file mode 100644 index 3479fee00..000000000 --- a/docs/api/daf-w3c.w3c.md +++ /dev/null @@ -1,32 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [W3c](./daf-w3c.w3c.md) - -## W3c class - -Signature: - -```typescript -export declare class W3c implements IAgentPlugin -``` -Implements: [IAgentPlugin](./daf-core.iagentplugin.md) - -## Constructors - -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)()](./daf-w3c.w3c._constructor_.md) | | Constructs a new instance of the W3c class | - -## Properties - -| Property | Modifiers | Type | Description | -| --- | --- | --- | --- | -| [methods](./daf-w3c.w3c.methods.md) | | [IW3c](./daf-w3c.iw3c.md) | | - -## Methods - -| Method | Modifiers | Description | -| --- | --- | --- | -| [createVerifiableCredential(args, context)](./daf-w3c.w3c.createverifiablecredential.md) | | | -| [createVerifiablePresentation(args, context)](./daf-w3c.w3c.createverifiablepresentation.md) | | | - diff --git a/docs/api/daf-w3c.w3c.methods.md b/docs/api/daf-w3c.w3c.methods.md deleted file mode 100644 index 8846115d1..000000000 --- a/docs/api/daf-w3c.w3c.methods.md +++ /dev/null @@ -1,11 +0,0 @@ - - -[Home](./index.md) > [daf-w3c](./daf-w3c.md) > [W3c](./daf-w3c.w3c.md) > [methods](./daf-w3c.w3c.methods.md) - -## W3c.methods property - -Signature: - -```typescript -readonly methods: IW3c; -``` diff --git a/docs/api/daf-w3c.w3cmessagehandler.md b/docs/api/daf-w3c.w3cmessagehandler.md index 3da6436df..b1c09e8f9 100644 --- a/docs/api/daf-w3c.w3cmessagehandler.md +++ b/docs/api/daf-w3c.w3cmessagehandler.md @@ -4,6 +4,12 @@ ## W3cMessageHandler class +An implementation of the [AbstractMessageHandler](./daf-message-handler.abstractmessagehandler.md). + +This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them for internal storage as [Message](./daf-message-handler.message.md) types. + +The current version can only handle `JWT` encoded + Signature: ```typescript @@ -11,6 +17,10 @@ export declare class W3cMessageHandler extends AbstractMessageHandler ``` Extends: [AbstractMessageHandler](./daf-message-handler.abstractmessagehandler.md) +## Remarks + +[IDataStore](./daf-core.idatastore.md) + ## Methods | Method | Modifiers | Description | diff --git a/docs/api/index.md b/docs/api/index.md index 88c7b7f88..2337417a2 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -56,8 +56,8 @@ | [keyManagerImportKey](./daf-core.ikeymanager.keymanagerimportkey.md) | Imports a created key | | [keyManagerSignEthTX](./daf-core.ikeymanager.keymanagersignethtx.md) | Signs Ethereum transaction | | [keyManagerSignJWT](./daf-core.ikeymanager.keymanagersignjwt.md) | Signs JWT | -| [createVerifiableCredential](./daf-w3c.iw3c.createverifiablecredential.md) | | -| [createVerifiablePresentation](./daf-w3c.iw3c.createverifiablepresentation.md) | | +| [createVerifiableCredential](./daf-w3c.icredentialissuer.createverifiablecredential.md) | Creates a Verifiable Credential. The payload, signer and format are chosen based on the | +| [createVerifiablePresentation](./daf-w3c.icredentialissuer.createverifiablepresentation.md) | Creates a Verifiable Presentation. The payload, signer and format are chosen based on the | | [createSelectiveDisclosureRequest](./daf-selective-disclosure.isdr.createselectivedisclosurerequest.md) | | | [getVerifiableCredentialsForSdr](./daf-selective-disclosure.isdr.getverifiablecredentialsforsdr.md) | | | [validatePresentationAgainstSdr](./daf-selective-disclosure.isdr.validatepresentationagainstsdr.md) | | diff --git a/docs/setup.md b/docs/setup.md index 7011e5980..b7f5c8040 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -25,7 +25,7 @@ import { KeyManager } from 'daf-key-manager' import { IdentityManager } from 'daf-identity-manager' 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' @@ -52,9 +52,9 @@ export const agent = createAgent< IDataStore & IDataStoreORM & IResolveDid & - IHandleMessage & + IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ plugins: [ @@ -90,7 +90,7 @@ export const agent = createAgent< ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) @@ -110,7 +110,7 @@ yarn add daf-core@beta daf-rest@beta daf-w3c@beta daf-did-comm@beta daf-selectiv ```typescript // agent.ts import { createAgent, IIdentityManager, IResolveDid, IKeyManager, IDataStore, IHandleMessage} from 'daf-core' -import { IW3c } from 'daf-w3c' +import { ICredentialIssuer } from 'daf-w3c' import { IDIDComm } from 'daf-did-comm' import { ISdr } from 'daf-selective-disclosure' import { IDataStoreORM } from 'daf-typeorm' @@ -122,9 +122,9 @@ export const agent = createAgent< IDataStore & IDataStoreORM & IResolveDid & - IHandleMessage & + IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ plugins: [ @@ -147,9 +147,9 @@ export const agent = createAgent< IDataStore & IDataStoreORM & IResolveDid & - IHandleMessage & + IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ plugins: [ @@ -192,7 +192,7 @@ export const agent = createAgent< ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) diff --git a/examples/generic/setup.ts b/examples/generic/setup.ts index f81523307..3884dd6eb 100644 --- a/examples/generic/setup.ts +++ b/examples/generic/setup.ts @@ -4,14 +4,14 @@ import { IResolveDid, IDataStore, IKeyManager, - IHandleMessage, + IMessageHandler, } from 'daf-core' import { MessageHandler } from 'daf-message-handler' import { KeyManager } from 'daf-key-manager' import { IdentityManager } from 'daf-identity-manager' 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 { Sdr, ISdr, SdrMessageHandler } from 'daf-selective-disclosure' import { DIDComm, DIDCommMessageHandler, IDIDComm } from 'daf-did-comm' import { EthrIdentityProvider } from 'daf-ethr-did' @@ -36,9 +36,9 @@ export const agent = createAgent< IDataStore & IDataStoreORM & IResolveDid & - IHandleMessage & + IMessageHandler & IDIDComm & - IW3c & + ICredentialIssuer & ISdr >({ context: { @@ -76,7 +76,7 @@ export const agent = createAgent< ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) diff --git a/examples/remote-methods/src/client/index.ts b/examples/remote-methods/src/client/index.ts index 23474e0cb..426a4034b 100644 --- a/examples/remote-methods/src/client/index.ts +++ b/examples/remote-methods/src/client/index.ts @@ -1,7 +1,7 @@ import 'cross-fetch/polyfill' -import { createAgent, TAgent, IIdentityManager, IResolveDid, IHandleMessage, IDataStore } from 'daf-core' +import { createAgent, TAgent, IIdentityManager, IResolveDid, IMessageHandler, IDataStore } from 'daf-core' import { IDataStoreORM } from 'daf-typeorm' -import { IW3c } from 'daf-w3c' +import { ICredentialIssuer } from 'daf-w3c' import { ISdr } from 'daf-selective-disclosure' import { AgentGraphQLClient } from 'daf-graphql' import { AgentRestClient } from 'daf-rest' @@ -15,10 +15,10 @@ const agent = createAgent< | 'identityManagerCreateIdentity' > & IResolveDid & - IHandleMessage & + IMessageHandler & IDataStoreORM & IDataStore & - IW3c & + ICredentialIssuer & ISdr >({ plugins: [ diff --git a/examples/remote-methods/src/server-graphql-apollo/setup.ts b/examples/remote-methods/src/server-graphql-apollo/setup.ts index f328503c6..66f8be5be 100644 --- a/examples/remote-methods/src/server-graphql-apollo/setup.ts +++ b/examples/remote-methods/src/server-graphql-apollo/setup.ts @@ -4,7 +4,7 @@ import { KeyManager } from 'daf-key-manager' import { IdentityManager } from 'daf-identity-manager' import { DafResolver } from 'daf-resolver' import { JwtMessageHandler } from 'daf-did-jwt' -import { W3c, W3cMessageHandler } from 'daf-w3c' +import { CredentialIssuer, W3cMessageHandler } from 'daf-w3c' import { DIDComm, DIDCommMessageHandler } from 'daf-did-comm' import { EthrIdentityProvider } from 'daf-ethr-did' import { KeyManagementSystem, SecretBox } from 'daf-libsodium' @@ -53,6 +53,6 @@ export const agent = new Agent({ messageHandlers: [new DIDCommMessageHandler(), new JwtMessageHandler(), new W3cMessageHandler()], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), ], }) diff --git a/examples/remote-methods/src/server-rest-express/setup.ts b/examples/remote-methods/src/server-rest-express/setup.ts index c5f9e3f5c..bd04f844a 100644 --- a/examples/remote-methods/src/server-rest-express/setup.ts +++ b/examples/remote-methods/src/server-rest-express/setup.ts @@ -4,7 +4,7 @@ import { KeyManager } from 'daf-key-manager' import { IdentityManager } from 'daf-identity-manager' import { DafResolver } from 'daf-resolver' import { JwtMessageHandler } from 'daf-did-jwt' -import { W3c, W3cMessageHandler } from 'daf-w3c' +import { CredentialIssuer, W3cMessageHandler } from 'daf-w3c' import { Sdr, SdrMessageHandler } from 'daf-selective-disclosure' import { DIDComm, DIDCommMessageHandler } from 'daf-did-comm' import { EthrIdentityProvider } from 'daf-ethr-did' @@ -59,7 +59,7 @@ export const agent = new Agent({ ], }), new DIDComm(), - new W3c(), + new CredentialIssuer(), new Sdr(), ], }) diff --git a/packages/daf-core/package.json b/packages/daf-core/package.json index 2dfd4a883..c9326a64e 100644 --- a/packages/daf-core/package.json +++ b/packages/daf-core/package.json @@ -14,7 +14,7 @@ }, "devDependencies": { "@types/debug": "^4.1.5", - "did-resolver": "^1.1.0", + "did-resolver": "2.1.1", "typescript": "^3.8.3" }, "files": [ diff --git a/packages/daf-core/src/agent.ts b/packages/daf-core/src/agent.ts index e9b17cf6f..eb8206d95 100644 --- a/packages/daf-core/src/agent.ts +++ b/packages/daf-core/src/agent.ts @@ -151,10 +151,10 @@ export class Agent implements IAgent { * ```typescript * import { createAgent, IResolveDid, IMessageHandler } from 'daf-core' * import { AgentRestClient } from 'daf-rest' - * import { W3c, IW3c } from 'daf-w3c' - * const agent = createAgent({ + * import { CredentialIssuer, ICredentialIssuer } from 'daf-w3c' + * const agent = createAgent({ * plugins: [ - * new W3c(), + * new CredentialIssuer(), * new AgentRestClient({ * url: 'http://localhost:3002/agent', * enabledMethods: [ diff --git a/packages/daf-did-jwt/package.json b/packages/daf-did-jwt/package.json index 3d5260edb..27a8737fd 100644 --- a/packages/daf-did-jwt/package.json +++ b/packages/daf-did-jwt/package.json @@ -11,8 +11,8 @@ "daf-core": "^7.0.0-beta.15", "daf-message-handler": "^7.0.0-beta.15", "debug": "^4.1.1", - "did-jwt": "^4.3.2", - "did-resolver": "^1.1.0" + "did-jwt": "4.5.0", + "did-resolver": "2.1.1" }, "devDependencies": { "@types/debug": "^4.1.5", diff --git a/packages/daf-did-jwt/src/__tests__/message-handler.test.ts b/packages/daf-did-jwt/src/__tests__/message-handler.test.ts index 5f01f5fe6..7086b2a52 100644 --- a/packages/daf-did-jwt/src/__tests__/message-handler.test.ts +++ b/packages/daf-did-jwt/src/__tests__/message-handler.test.ts @@ -67,7 +67,7 @@ describe('daf-did-jwt', () => { { id: `${args?.didUrl}#owner`, type: 'Secp256k1VerificationKey2018', - owner: args?.didUrl, + controller: args?.didUrl, ethereumAddress: args?.didUrl.slice(-42), }, ], diff --git a/packages/daf-libsodium/package.json b/packages/daf-libsodium/package.json index f9a0964c4..97484635d 100644 --- a/packages/daf-libsodium/package.json +++ b/packages/daf-libsodium/package.json @@ -12,7 +12,7 @@ "daf-core": "^7.0.0-beta.15", "daf-key-manager": "^7.0.0-beta.15", "debug": "^4.1.1", - "did-jwt": "^4.3.2", + "did-jwt": "4.5.0", "elliptic": "^6.5.2", "ethjs-signer": "^0.1.1", "libsodium-wrappers": "^0.7.6" diff --git a/packages/daf-resolver-universal/package.json b/packages/daf-resolver-universal/package.json index 27754d369..6ed234858 100644 --- a/packages/daf-resolver-universal/package.json +++ b/packages/daf-resolver-universal/package.json @@ -11,7 +11,7 @@ "cross-fetch": "^3.0.5", "daf-core": "^7.0.0-beta.15", "debug": "^4.1.1", - "did-resolver": "^1.1.0" + "did-resolver": "2.1.1" }, "devDependencies": { "@types/debug": "^4.1.5", diff --git a/packages/daf-resolver/package.json b/packages/daf-resolver/package.json index 6fdac6cb7..b371f6775 100644 --- a/packages/daf-resolver/package.json +++ b/packages/daf-resolver/package.json @@ -10,7 +10,7 @@ "dependencies": { "daf-core": "^7.0.0-beta.15", "debug": "^4.1.1", - "did-resolver": "^2.0.1", + "did-resolver": "2.1.1", "ethr-did-resolver": "^2.2.0", "nacl-did": "^1.0.1", "web-did-resolver": "^1.3.0" diff --git a/packages/daf-rest/src/openApiSchema.ts b/packages/daf-rest/src/openApiSchema.ts index 535d075ec..70bd7d4e5 100644 --- a/packages/daf-rest/src/openApiSchema.ts +++ b/packages/daf-rest/src/openApiSchema.ts @@ -868,23 +868,24 @@ export const openApiSchema: OpenAPIV3.Document = { "type": "object", "properties": { "credential": { - "$ref": "#/components/schemas/W3CCredential" + "$ref": "#/components/schemas/W3CCredential", + "description": "The json payload of the Credential according to the\n{@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model}\n\nThe signer of the Credential is chosen based on the `issuer.id` property\nof the `credential`" }, "save": { - "type": "boolean" + "type": "boolean", + "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n{@link daf-core#IDataStore | storage plugin} to be saved" }, "proofFormat": { - "type": "string", - "enum": [ - "jwt" - ] + "$ref": "#/components/schemas/EncodingFormat", + "description": "The desired format for the VerifiablePresentation to be created.\nCurrently, only JWT is supported" } }, "required": [ "credential", "proofFormat" ], - "additionalProperties": false + "additionalProperties": false, + "description": "Encapsulates the parameters required to create a\n{@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential}" }, "W3CCredential": { "type": "object", @@ -961,27 +962,35 @@ export const openApiSchema: OpenAPIV3.Document = { ], "additionalProperties": false }, + "EncodingFormat": { + "type": "string", + "enum": [ + "jwt" + ], + "description": "The type of encoding to be used for the Verifiable Credential or Presentation to be generated.\n\nOnly `jwt` is supported at the moment." + }, "ICreateVerifiablePresentationArgs": { "type": "object", "properties": { "presentation": { - "$ref": "#/components/schemas/W3CPresentation" + "$ref": "#/components/schemas/W3CPresentation", + "description": "The json payload of the Presentation according to the\n{@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model}.\n\nThe signer of the Presentation is chosen based on the `holder` property\nof the `presentation`" }, "save": { - "type": "boolean" + "type": "boolean", + "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n{@link daf-core#IDataStore | storage plugin} to be saved" }, "proofFormat": { - "type": "string", - "enum": [ - "jwt" - ] + "$ref": "#/components/schemas/EncodingFormat", + "description": "The desired format for the VerifiablePresentation to be created.\nCurrently, only JWT is supported" } }, "required": [ "presentation", "proofFormat" ], - "additionalProperties": false + "additionalProperties": false, + "description": "Encapsulates the parameters required to create a\n{@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation}" }, "W3CPresentation": { "type": "object", @@ -2408,7 +2417,7 @@ export const openApiSchema: OpenAPIV3.Document = { }, "/createVerifiableCredential": { "post": { - "description": "", + "description": "Creates a Verifiable Credential. The payload, signer and format are chosen based on the ", "operationId": "createVerifiableCredential", "requestBody": { "content": { @@ -2421,7 +2430,7 @@ export const openApiSchema: OpenAPIV3.Document = { }, "responses": { "200": { - "description": "", + "description": "Creates a Verifiable Credential. The payload, signer and format are chosen based on the ", "content": { "application/json": { "schema": { @@ -2435,7 +2444,7 @@ export const openApiSchema: OpenAPIV3.Document = { }, "/createVerifiablePresentation": { "post": { - "description": "", + "description": "Creates a Verifiable Presentation. The payload, signer and format are chosen based on the ", "operationId": "createVerifiablePresentation", "requestBody": { "content": { @@ -2448,7 +2457,7 @@ export const openApiSchema: OpenAPIV3.Document = { }, "responses": { "200": { - "description": "", + "description": "Creates a Verifiable Presentation. The payload, signer and format are chosen based on the ", "content": { "application/json": { "schema": { diff --git a/packages/daf-selective-disclosure/package.json b/packages/daf-selective-disclosure/package.json index 5d60f16e1..9cee6d487 100644 --- a/packages/daf-selective-disclosure/package.json +++ b/packages/daf-selective-disclosure/package.json @@ -14,7 +14,7 @@ "daf-message-handler": "^7.0.0-beta.15", "daf-typeorm": "^7.0.0-beta.15", "debug": "^4.1.1", - "did-jwt": "^4.3.2" + "did-jwt": "4.5.0" }, "devDependencies": { "@types/debug": "^4.1.5", diff --git a/packages/daf-w3c/package.json b/packages/daf-w3c/package.json index 12ebee17e..2086d0298 100644 --- a/packages/daf-w3c/package.json +++ b/packages/daf-w3c/package.json @@ -15,7 +15,7 @@ "daf-resolver": "^7.0.0-beta.15", "debug": "^4.1.1", "did-jwt-vc": "^1.0.3", - "did-resolver": "^1.1.0" + "did-resolver": "2.1.1" }, "devDependencies": { "@types/debug": "^4.1.5", diff --git a/packages/daf-w3c/src/__tests__/action-handler.test.ts b/packages/daf-w3c/src/__tests__/action-handler.test.ts index 52bc87a64..70ad611c7 100644 --- a/packages/daf-w3c/src/__tests__/action-handler.test.ts +++ b/packages/daf-w3c/src/__tests__/action-handler.test.ts @@ -16,7 +16,7 @@ const mockDidJwtVc = { jest.mock('did-jwt-vc', () => mockDidJwtVc) -import { W3c, IContext } from '../action-handler' +import { CredentialIssuer, IContext } from '../action-handler' const mockIdentity1: IIdentity = { did: 'did:example:111', @@ -62,7 +62,7 @@ const context: IContext = { }, } -const w3c = new W3c() +const w3c = new CredentialIssuer() describe('daf-w3c', () => { it('handles createVerifiableCredential', async () => { diff --git a/packages/daf-w3c/src/__tests__/message-handler.test.ts b/packages/daf-w3c/src/__tests__/message-handler.test.ts index e76b30093..8b2ce5d18 100644 --- a/packages/daf-w3c/src/__tests__/message-handler.test.ts +++ b/packages/daf-w3c/src/__tests__/message-handler.test.ts @@ -71,7 +71,7 @@ describe('daf-w3c', () => { { id: `${args?.didUrl}#owner`, type: 'Secp256k1VerificationKey2018', - owner: args?.didUrl, + controller: args?.didUrl, ethereumAddress: args?.didUrl.slice(-42), }, ], diff --git a/packages/daf-w3c/src/action-handler.ts b/packages/daf-w3c/src/action-handler.ts index 8964f4989..2fb4896b6 100644 --- a/packages/daf-w3c/src/action-handler.ts +++ b/packages/daf-w3c/src/action-handler.ts @@ -11,11 +11,10 @@ import { VerifiablePresentation, IDataStore, } from 'daf-core' + import { createVerifiableCredentialJwt, createVerifiablePresentationJwt, - transformCredentialInput, - transformPresentationInput, normalizeCredential, normalizePresentation, } from 'did-jwt-vc' @@ -23,28 +22,122 @@ import { import Debug from 'debug' const debug = Debug('daf:w3c:action-handler') +/** + * The type of encoding to be used for the Verifiable Credential or Presentation to be generated. + * + * Only `jwt` is supported at the moment. + * + * @public + */ +export type EncodingFormat = 'jwt' // | "json" | "json-ld" + +/** + * Encapsulates the parameters required to create a + * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation} + * + * @public + */ export interface ICreateVerifiablePresentationArgs { + /** + * The json payload of the Presentation according to the + * {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model}. + * + * The signer of the Presentation is chosen based on the `holder` property + * of the `presentation` + */ presentation: W3CPresentation + + /** + * If this parameter is true, the resulting VerifiablePresentation is sent to the + * {@link daf-core#IDataStore | storage plugin} to be saved + */ save?: boolean - proofFormat: 'jwt' + + /** + * The desired format for the VerifiablePresentation to be created. + * Currently, only JWT is supported + */ + proofFormat: EncodingFormat } +/** + * Encapsulates the parameters required to create a + * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential} + * + * @public + */ export interface ICreateVerifiableCredentialArgs { + /** + * The json payload of the Credential according to the + * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model} + * + * The signer of the Credential is chosen based on the `issuer.id` property + * of the `credential` + */ credential: W3CCredential + + /** + * If this parameter is true, the resulting VerifiablePresentation is sent to the + * {@link daf-core#IDataStore | storage plugin} to be saved + */ save?: boolean - proofFormat: 'jwt' + + /** + * The desired format for the VerifiablePresentation to be created. + * Currently, only JWT is supported + */ + proofFormat: EncodingFormat } -export interface IW3c extends IPluginMethodMap { +/** + * The interface definition for a plugin that can generate Verifiable Credentials and Presentations + * + * @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model} + * + * @public + */ +export interface ICredentialIssuer extends IPluginMethodMap { + /** + * Creates a Verifiable Presentation. + * The payload, signer and format are chosen based on the `args` parameter. + * + * @param args - Arguments necessary to create the Presentation. + * @param context - This reserved param is automatically added and handled by the framework, *do not override* + * + * @returns - a promise that resolves to the {@link daf-core#VerifiablePresentation} 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 {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Presentation data model } + */ createVerifiablePresentation( args: ICreateVerifiablePresentationArgs, context: IContext, ): Promise + + /** + * Creates a Verifiable Credential. + * The payload, signer and format are chosen based on the `args` parameter. + * + * @param args - Arguments necessary to create the Presentation. + * @param context - This reserved param is automatically added and handled by the framework, *do not override* + * + * @returns - a promise that resolves to the {@link daf-core#VerifiableCredential} 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 {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model} + */ createVerifiableCredential( args: ICreateVerifiableCredentialArgs, context: IContext, ): Promise } + +/** + * Represents the requirements that this plugin has. + * The agent that is using this plugin is expected to provide these methods. + * + * This interface can be used for static type checks, to make sure your application is properly initialized. + */ export type IContext = IAgentContext< IResolveDid & Pick & @@ -52,8 +145,13 @@ export type IContext = IAgentContext< Pick > -export class W3c implements IAgentPlugin { - readonly methods: IW3c +/** + * A DAF plugin that implements the {@link ICredentialIssuer} methods. + * + * @public + */ +export class CredentialIssuer implements IAgentPlugin { + readonly methods: ICredentialIssuer constructor() { this.methods = { @@ -62,17 +160,22 @@ export class W3c implements IAgentPlugin { } } + /** {@inheritdoc ICredentialIssuer.createVerifiablePresentation} */ async createVerifiablePresentation( args: ICreateVerifiablePresentationArgs, context: IContext, ): Promise { try { + //FIXME: if the identity is not found, the error message should reflect that. const identity = await context.agent.identityManagerGetIdentity({ did: args.presentation.holder }) + //FIXME: `args` should allow picking a key or key type const key = identity.keys.find((k) => k.type === 'Secp256k1') if (!key) throw Error('No signing key for ' + identity.did) + //FIXME: Throw an `unsupported_format` error if the `args.proofFormat` is not `jwt` const signer = (data: string) => context.agent.keyManagerSignJWT({ kid: key.kid, data }) debug('Signing VP with', identity.did) const jwt = await createVerifiablePresentationJwt(args.presentation, { did: identity.did, signer }) + //FIXME: flagging this as a potential privacy leak. debug(jwt) const presentation = normalizePresentation(jwt) if (args.save) { @@ -85,18 +188,23 @@ export class W3c implements IAgentPlugin { } } + /** {@inheritdoc ICredentialIssuer.createVerifiableCredential} */ async createVerifiableCredential( args: ICreateVerifiableCredentialArgs, context: IContext, ): Promise { try { + //FIXME: if the identity is not found, the error message should reflect that. const identity = await context.agent.identityManagerGetIdentity({ did: args.credential.issuer.id }) + //FIXME: `args` should allow picking a key or key type const key = identity.keys.find((k) => k.type === 'Secp256k1') if (!key) throw Error('No signing key for ' + identity.did) + //FIXME: Throw an `unsupported_format` error if the `args.proofFormat` is not `jwt` const signer = (data: string) => context.agent.keyManagerSignJWT({ kid: key.kid, data }) debug('Signing VC with', identity.did) const jwt = await createVerifiableCredentialJwt(args.credential, { did: identity.did, signer }) + //FIXME: flagging this as a potential privacy leak. debug(jwt) const credential = normalizeCredential(jwt) if (args.save) { diff --git a/packages/daf-w3c/src/index.ts b/packages/daf-w3c/src/index.ts index e42179e13..6a7e0ee27 100644 --- a/packages/daf-w3c/src/index.ts +++ b/packages/daf-w3c/src/index.ts @@ -1,8 +1,8 @@ import { IAgentPlugin, IPluginMethodMap } from 'daf-core' export { W3cMessageHandler, MessageTypes } from './message-handler' export { - W3c, - IW3c, + CredentialIssuer, + ICredentialIssuer, ICreateVerifiableCredentialArgs, ICreateVerifiablePresentationArgs, } from './action-handler' diff --git a/packages/daf-w3c/src/message-handler.ts b/packages/daf-w3c/src/message-handler.ts index 171858b3f..f129fc611 100644 --- a/packages/daf-w3c/src/message-handler.ts +++ b/packages/daf-w3c/src/message-handler.ts @@ -12,13 +12,38 @@ import { import Debug from 'debug' const debug = Debug('daf:w3c:message-handler') +/** + * These types are used by the DAF data store when storing Verifiable Credentials and Presentations + * + * @internal + */ export const MessageTypes = { + /** Represents a Verifiable Credential */ vc: 'w3c.vc', + /** Represents a Verifiable Presentation */ vp: 'w3c.vp', } +/** + * Represents the requirements that this plugin has. + * The agent that is using this plugin is expected to provide these methods. + * + * This interface can be used for static type checks, to make sure your application is properly initialized. + */ export type IContext = IAgentContext +/** + * An implementation of the {@link daf-message-handler#AbstractMessageHandler}. + * + * This plugin can handle incoming W3C Verifiable Credentials and Presentations and prepare them + * for internal storage as {@link daf-message-handler#Message} types. + * + * The current version can only handle `JWT` encoded + * + * @remarks {@link daf-core#IDataStore | IDataStore } + * + * @public + */ export class W3cMessageHandler extends AbstractMessageHandler { async handle(message: Message, context: IContext): Promise { const meta = message.getLastMetaData() @@ -29,6 +54,7 @@ export class W3cMessageHandler extends AbstractMessageHandler { try { validateJwtPresentationPayload(data) + //FIXME: flagging this for potential privacy leaks debug('JWT is', MessageTypes.vp) const presentation = normalizePresentation(message.raw) const credentials = presentation.verifiableCredential @@ -51,6 +77,7 @@ export class W3cMessageHandler extends AbstractMessageHandler { try { validateJwtCredentialPayload(data) + //FIXME: flagging this for potential privacy leaks debug('JWT is', MessageTypes.vc) const credential = normalizeCredential(message.raw) diff --git a/report/daf-typeorm.api.md b/report/daf-typeorm.api.md index 52cc13acf..f6e18a282 100644 --- a/report/daf-typeorm.api.md +++ b/report/daf-typeorm.api.md @@ -118,7 +118,7 @@ export class DataStoreORM implements IAgentPlugin { } // @public (undocumented) -export const Entities: (typeof Key | typeof Identity | typeof Service | typeof Claim | typeof Credential_2 | typeof Presentation | typeof Message)[]; +export const Entities: (typeof Credential_2 | typeof Identity | typeof Claim | typeof Presentation | typeof Message | typeof Key | typeof Service)[]; // @public (undocumented) export interface FindArgs { diff --git a/report/daf-w3c.api.md b/report/daf-w3c.api.md index 6abc7e104..4df4033e6 100644 --- a/report/daf-w3c.api.md +++ b/report/daf-w3c.api.md @@ -18,54 +18,46 @@ import { VerifiablePresentation } from 'daf-core'; import { W3CCredential } from 'daf-core'; import { W3CPresentation } from 'daf-core'; -// @public (undocumented) -export interface ICreateVerifiableCredentialArgs { +// @public +export class CredentialIssuer implements IAgentPlugin { + constructor(); + createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext_2): Promise; + // Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts + createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext_2): Promise; // (undocumented) + readonly methods: ICredentialIssuer; +} + +// @public +export interface ICreateVerifiableCredentialArgs { credential: W3CCredential; - // (undocumented) - proofFormat: 'jwt'; - // (undocumented) + // Warning: (ae-forgotten-export) The symbol "EncodingFormat" needs to be exported by the entry point index.d.ts + proofFormat: EncodingFormat; save?: boolean; } -// @public (undocumented) +// @public export interface ICreateVerifiablePresentationArgs { - // (undocumented) presentation: W3CPresentation; - // (undocumented) - proofFormat: 'jwt'; - // (undocumented) + proofFormat: EncodingFormat; save?: boolean; } -// @public (undocumented) -export interface IW3c extends IPluginMethodMap { - // (undocumented) +// @public +export interface ICredentialIssuer extends IPluginMethodMap { createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext_2): Promise; - // Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts - // - // (undocumented) createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext_2): Promise; } -// @public (undocumented) +// Warning: (ae-internal-missing-underscore) The name "MessageTypes" should be prefixed with an underscore because the declaration is marked as @internal +// +// @internal export const MessageTypes: { vc: string; vp: string; }; -// @public (undocumented) -export class W3c implements IAgentPlugin { - constructor(); - // (undocumented) - createVerifiableCredential(args: ICreateVerifiableCredentialArgs, context: IContext_2): Promise; - // (undocumented) - createVerifiablePresentation(args: ICreateVerifiablePresentationArgs, context: IContext_2): Promise; - // (undocumented) - readonly methods: IW3c; -} - -// @public (undocumented) +// @public export class W3cMessageHandler extends AbstractMessageHandler { // Warning: (ae-forgotten-export) The symbol "IContext" needs to be exported by the entry point index.d.ts // diff --git a/scripts/generate-schemas.ts b/scripts/generate-schemas.ts index bdefae97f..e57e5434b 100644 --- a/scripts/generate-schemas.ts +++ b/scripts/generate-schemas.ts @@ -17,7 +17,7 @@ const outputFile = 'packages/daf-rest/src/openApiSchema.ts' const agentPlugins: Record> = { 'daf-core': ['IIdentityManager', 'IResolveDid', 'IMessageHandler', 'IDataStore', 'IKeyManager'], - 'daf-w3c': ['IW3c'], + 'daf-w3c': ['ICredentialIssuer'], 'daf-selective-disclosure': ['ISdr'], 'daf-did-comm': ['IDIDComm'], 'daf-typeorm': ['IDataStoreORM'], diff --git a/yarn.lock b/yarn.lock index 0b39dd216..6573a07be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -266,6 +266,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.11.2": + version "7.11.2" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.11.2.tgz#f549c13c754cc40b87644b9fa9f09a6a95fe0736" + integrity sha512-TeWkU52so0mPtDcaCTxNBI/IHiz0pZgr8VEFqXFtZWpYD08ZB6FaSwVAS8MKRQAP3bYKiVjwysOJgMFY28o6Tw== + dependencies: + regenerator-runtime "^0.13.4" + "@babel/template@^7.10.1", "@babel/template@^7.10.3", "@babel/template@^7.3.3": version "7.10.3" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.10.3.tgz#4d13bc8e30bf95b0ce9d175d30306f42a2c9a7b8" @@ -4084,6 +4091,21 @@ did-jwt-vc@^1.0.3: dependencies: did-jwt "^4.3.2" +did-jwt@4.5.0: + version "4.5.0" + resolved "https://registry.yarnpkg.com/did-jwt/-/did-jwt-4.5.0.tgz#9dfb1490d0c497cb86b5a1ee601b7d072e77a948" + integrity sha512-5duVhz8d9Af9ZoBYEGGfaGdM1RM2VDawbjs6FUg8gjNCfkKd9R6RNYdAma/pZAuHY1lGXnFQBKzBZhib0y5Y3g== + dependencies: + "@babel/runtime" "^7.11.2" + "@stablelib/utf8" "^1.0.0" + buffer "^5.6.0" + did-resolver "^2.1.0" + elliptic "^6.5.3" + js-sha256 "^0.9.0" + js-sha3 "^0.8.0" + tweetnacl "^1.0.3" + uport-base64url "3.0.2-alpha.0" + did-jwt@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/did-jwt/-/did-jwt-0.1.3.tgz#0d23c74ed4e5188e9c10fb85b5e8c3e42ecb9da9" @@ -4124,7 +4146,12 @@ did-resolver@1.0.0: resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-1.0.0.tgz#892bcffe66352b1360c928a23082a731c83ca7c3" integrity sha512-mgJG0oqlkG7jfRzW0yN9qKawp24M4thGFdfIaZI30SAJXhpkkjqbkRxqMZLJNwqXEM0cqFbXaiFDqnd9Q1UUaw== -did-resolver@^1.0.0, did-resolver@^1.1.0: +did-resolver@2.1.1, did-resolver@^2.1.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-2.1.1.tgz#43796f8a3e921644e5fb15a8147684ca87019cfd" + integrity sha512-FYLTkNWofjYNDGV1HTQlyVu1OqZiFxR4I8KM+oxGVOkbXva15NfWzbzciqdXUDqOhe6so5aroAdrVip6gSAYSA== + +did-resolver@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/did-resolver/-/did-resolver-1.1.0.tgz#27a63b6f2aa8dee3d622cd8b8b47360661e24f1e" integrity sha512-Q02Sc5VuQnJzzR8fQ/DzyCHiYb31WpQdocOsxppI66wwT4XalYRDeCr3a48mL6sYPQo76AkBh0mxte9ZBuQzxA== @@ -4251,7 +4278,7 @@ elliptic@6.3.2: hash.js "^1.0.0" inherits "^2.0.1" -elliptic@^6.4.0, elliptic@^6.5.2: +elliptic@^6.4.0, elliptic@^6.5.2, elliptic@^6.5.3: version "6.5.3" resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.3.tgz#cb59eb2efdaf73a0bd78ccd7015a62ad6e0f93d6" integrity sha512-IMqzv5wNQf+E6aHeIqATs0tOLeOTwj1QKbRcS3jBbYkl5oLAserA8yJTT7/VyHUYG91PRmPyeQDObKLPpeS4dw==