diff --git a/__tests__/localAgent.test.ts b/__tests__/localAgent.test.ts index 50fa71022..26998dda2 100644 --- a/__tests__/localAgent.test.ts +++ b/__tests__/localAgent.test.ts @@ -10,6 +10,7 @@ import { createAgent, IAgentOptions, + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -23,7 +24,7 @@ import { KeyManager } from '../packages/key-manager/src' import { AliasDiscoveryProvider, DIDManager } from '../packages/did-manager/src' import { DIDResolverPlugin } from '../packages/did-resolver/src' import { JwtMessageHandler } from '../packages/did-jwt/src' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/credential-w3c/src' +import { CredentialPlugin, W3cMessageHandler } from '../packages/credential-w3c/src' import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src' import { CredentialIssuerLD, @@ -97,7 +98,7 @@ let agent: TAgent< IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure & @@ -133,7 +134,7 @@ const setup = async (options?: IAgentOptions): Promise => { IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure & @@ -219,7 +220,7 @@ const setup = async (options?: IAgentOptions): Promise => { ], }), new DIDComm([new DIDCommHttpTransport()]), - new CredentialIssuer(), + new CredentialPlugin(), new CredentialIssuerEIP712(), new CredentialIssuerLD({ contextMaps: [LdDefaultContexts, credential_contexts as any], diff --git a/__tests__/localJsonStoreAgent.test.ts b/__tests__/localJsonStoreAgent.test.ts index 83c64107e..40975dbcd 100644 --- a/__tests__/localJsonStoreAgent.test.ts +++ b/__tests__/localJsonStoreAgent.test.ts @@ -8,6 +8,7 @@ import { createAgent, IAgentOptions, + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -21,7 +22,7 @@ import { KeyManager } from '../packages/key-manager/src' import { DIDManager } from '../packages/did-manager/src' import { DIDResolverPlugin } from '../packages/did-resolver/src' import { JwtMessageHandler } from '../packages/did-jwt/src' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/credential-w3c/src' +import { CredentialPlugin, W3cMessageHandler } from '../packages/credential-w3c/src' import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src' import { CredentialIssuerLD, @@ -34,10 +35,19 @@ import { EthrDIDProvider } from '../packages/did-provider-ethr/src' import { WebDIDProvider } from '../packages/did-provider-web/src' import { getDidKeyResolver, KeyDIDProvider } from '../packages/did-provider-key/src' import { DIDComm, DIDCommMessageHandler, IDIDComm } from '../packages/did-comm/src' -import { ISelectiveDisclosure, SdrMessageHandler, SelectiveDisclosure, } from '../packages/selective-disclosure/src' +import { + ISelectiveDisclosure, + SdrMessageHandler, + SelectiveDisclosure, +} from '../packages/selective-disclosure/src' import { KeyManagementSystem, SecretBox } from '../packages/kms-local/src' import { Web3KeyManagementSystem } from '../packages/kms-web3/src' -import { DataStoreJson, DIDStoreJson, KeyStoreJson, PrivateKeyStoreJson, } from '../packages/data-store-json/src' +import { + DataStoreJson, + DIDStoreJson, + KeyStoreJson, + PrivateKeyStoreJson, +} from '../packages/data-store-json/src' import { FakeDidProvider, FakeDidResolver } from '../packages/test-utils/src' import { Resolver } from 'did-resolver' @@ -76,7 +86,7 @@ let agent: TAgent< IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure @@ -100,7 +110,7 @@ const setup = async (options?: IAgentOptions): Promise => { IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure @@ -168,7 +178,7 @@ const setup = async (options?: IAgentOptions): Promise => { ], }), new DIDComm(), - new CredentialIssuer(), + new CredentialPlugin(), new CredentialIssuerEIP712(), new CredentialIssuerLD({ contextMaps: [LdDefaultContexts, credential_contexts as any], diff --git a/__tests__/localMemoryStoreAgent.test.ts b/__tests__/localMemoryStoreAgent.test.ts index 7f41bced5..84c2a985b 100644 --- a/__tests__/localMemoryStoreAgent.test.ts +++ b/__tests__/localMemoryStoreAgent.test.ts @@ -8,6 +8,7 @@ import { createAgent, IAgentOptions, + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -22,7 +23,7 @@ import { DIDManager, MemoryDIDStore } from '../packages/did-manager/src' import { DataSource } from 'typeorm' import { DIDResolverPlugin } from '../packages/did-resolver/src' import { JwtMessageHandler } from '../packages/did-jwt/src' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/credential-w3c/src' +import { CredentialPlugin, W3cMessageHandler } from '../packages/credential-w3c/src' import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src' import { CredentialIssuerLD, @@ -79,7 +80,7 @@ let agent: TAgent< IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure @@ -107,7 +108,7 @@ const setup = async (options?: IAgentOptions): Promise => { IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure @@ -176,7 +177,7 @@ const setup = async (options?: IAgentOptions): Promise => { ], }), new DIDComm(), - new CredentialIssuer(), + new CredentialPlugin(), new CredentialIssuerEIP712(), new CredentialIssuerLD({ contextMaps: [LdDefaultContexts, credential_contexts as any], diff --git a/__tests__/restAgent.test.ts b/__tests__/restAgent.test.ts index 5e5b3623b..218bee5eb 100644 --- a/__tests__/restAgent.test.ts +++ b/__tests__/restAgent.test.ts @@ -27,7 +27,12 @@ import { KeyManager } from '../packages/key-manager/src' import { AliasDiscoveryProvider, DIDManager } from '../packages/did-manager/src' import { DIDResolverPlugin } from '../packages/did-resolver/src' import { JwtMessageHandler } from '../packages/did-jwt/src' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '../packages/credential-w3c/src' +import { + CredentialIssuer, + ICredentialIssuer, + ICredentialVerifier, + W3cMessageHandler, +} from '../packages/credential-w3c/src' import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src' import { CredentialIssuerLD, @@ -109,7 +114,8 @@ const getAgent = (options?: IAgentOptions) => IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialIssuer & // import from old package to check compatibility + ICredentialVerifier & ICredentialIssuerLD & ICredentialIssuerEIP712 & ISelectiveDisclosure & @@ -200,6 +206,7 @@ const setup = async (options?: IAgentOptions): Promise => { ], }), new DIDComm([new DIDCommHttpTransport()]), + // intentionally use the deprecated name to test compatibility new CredentialIssuer(), new CredentialIssuerEIP712(), new CredentialIssuerLD({ diff --git a/__tests__/shared/credentialStatus.ts b/__tests__/shared/credentialStatus.ts index 9f66f8e03..cbbc6a901 100644 --- a/__tests__/shared/credentialStatus.ts +++ b/__tests__/shared/credentialStatus.ts @@ -4,6 +4,7 @@ import { CredentialStatus } from 'credential-status' import { CredentialPayload, IAgentOptions, + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -11,9 +12,8 @@ import { TAgent, } from '../../packages/core/src' import { CredentialStatusPlugin } from '../../packages/credential-status/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' -type ConfiguredAgent = TAgent +type ConfiguredAgent = TAgent // Constant used to simulate exception flows const simulateStatusVerificationFailure = 'Any unexpected failure during status verification.' diff --git a/__tests__/shared/dbInitOptions.ts b/__tests__/shared/dbInitOptions.ts index afb052db2..06be78fbf 100644 --- a/__tests__/shared/dbInitOptions.ts +++ b/__tests__/shared/dbInitOptions.ts @@ -2,6 +2,7 @@ import { IAgentOptions, + ICredentialIssuer, IDataStore, IDataStoreORM, IDIDManager, @@ -12,7 +13,6 @@ import { IResolver, TAgent, } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' import { IDIDComm, IPackedDIDCommMessage } from '../../packages/did-comm/src' import { extractIssuer } from '../../packages/utils/src' diff --git a/__tests__/shared/didCommWithEthrDidFlow.ts b/__tests__/shared/didCommWithEthrDidFlow.ts index ea5b446ff..53703a5ca 100644 --- a/__tests__/shared/didCommWithEthrDidFlow.ts +++ b/__tests__/shared/didCommWithEthrDidFlow.ts @@ -140,7 +140,7 @@ export default (testContext: { service: { id: 'localhost-useless-endpoint-2', type: 'DIDComm', - serviceEndpoint: {uri: `http://localhost:${listeningPort}/foobar`}, + serviceEndpoint: { uri: `http://localhost:${listeningPort}/foobar` }, description: 'this endpoint will be removed', }, }) @@ -148,9 +148,9 @@ export default (testContext: { const resolution = await agent.resolveDid({ didUrl: alice.did }) - expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual( - {uri: `http://localhost:${listeningPort}/foobar`}, - ) + expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual({ + uri: `http://localhost:${listeningPort}/foobar`, + }) }) it('should remove dummy service 2 from identifier', async () => { @@ -167,14 +167,13 @@ export default (testContext: { expect([...(resolution?.didDocument?.service || [])]).toEqual([]) }) - it('should add dummy service 3 to identifier', async () => { const result = await agent.didManagerAddService({ did: alice.did, service: { id: 'localhost-useless-endpoint-3', type: 'DIDComm', - serviceEndpoint: [{uri: `http://localhost:${listeningPort}/foobar`}], + serviceEndpoint: [{ uri: `http://localhost:${listeningPort}/foobar` }], description: 'this endpoint will be removed', }, }) @@ -182,9 +181,9 @@ export default (testContext: { const resolution = await agent.resolveDid({ didUrl: alice.did }) - expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual( - [{uri: `http://localhost:${listeningPort}/foobar`}], - ) + expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual([ + { uri: `http://localhost:${listeningPort}/foobar` }, + ]) }) it('should remove dummy service 3 from identifier', async () => { @@ -215,9 +214,9 @@ export default (testContext: { const resolution = await agent.resolveDid({ didUrl: alice.did }) - expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual( - [`http://localhost:${listeningPort}/foobar`], - ) + expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual([ + `http://localhost:${listeningPort}/foobar`, + ]) }) it('should remove dummy service 4 from identifier', async () => { @@ -325,7 +324,7 @@ export default (testContext: { expect.anything(), ) }) - + it('should remove DIDComm service from receiver', async () => { const result = await agent.didManagerRemoveService({ did: alice.did, @@ -340,7 +339,6 @@ export default (testContext: { expect([...(resolution?.didDocument?.service || [])]).toEqual([]) }) - it('should add DIDComm service to receiver DID with serviceEndpoint as array of strings', async () => { const result = await agent.didManagerAddService({ did: alice.did, @@ -355,9 +353,9 @@ export default (testContext: { const resolution = await agent.resolveDid({ didUrl: alice.did }) - expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual( - [`http://localhost:${listeningPort}/messaging`], - ) + expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual([ + `http://localhost:${listeningPort}/messaging`, + ]) }) it('should send an signed message from bob to alice with serviceEndpoint as array of strings', async () => { @@ -404,7 +402,6 @@ export default (testContext: { ) }) - it('should remove DIDComm service from receiver', async () => { const result = await agent.didManagerRemoveService({ did: alice.did, @@ -418,7 +415,7 @@ export default (testContext: { expect(resolution?.didDocument).not.toBeNull() expect([...(resolution?.didDocument?.service || [])]).toEqual([]) }) - + it('should add DIDComm service to receiver DID with ServiceEndpoint as object', async () => { const result = await agent.didManagerAddService({ did: alice.did, @@ -433,9 +430,9 @@ export default (testContext: { const resolution = await agent.resolveDid({ didUrl: alice.did }) - expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual( - { uri: `http://localhost:${listeningPort}/messaging` }, - ) + expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual({ + uri: `http://localhost:${listeningPort}/messaging`, + }) }) it('should send an signed message from bob to alice with ServiceEndpoint as object', async () => { @@ -482,7 +479,6 @@ export default (testContext: { ) }) - it('should remove DIDComm service from receiver', async () => { const result = await agent.didManagerRemoveService({ did: alice.did, @@ -496,7 +492,7 @@ export default (testContext: { expect(resolution?.didDocument).not.toBeNull() expect([...(resolution?.didDocument?.service || [])]).toEqual([]) }) - + it('should add DIDComm service to receiver DID with serviceEndpoint as array of ServiceEndpoint objects', async () => { const result = await agent.didManagerAddService({ did: alice.did, @@ -511,9 +507,9 @@ export default (testContext: { const resolution = await agent.resolveDid({ didUrl: alice.did }) - expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual( - [{ uri: `http://localhost:${listeningPort}/messaging` }], - ) + expect(resolution?.didDocument?.service?.[0].serviceEndpoint).toEqual([ + { uri: `http://localhost:${listeningPort}/messaging` }, + ]) }) it('should send an signed message from bob to alice with serviceEndpoint as array of ServiceEndpoint objects', async () => { @@ -675,7 +671,7 @@ export default (testContext: { id: 'test-authcrypt-fail', body: { hello: 'world' }, } - const packedMessage = await await expect( + const packedMessage = await expect( agent.packDIDCommMessage({ packing: 'authcrypt', message, diff --git a/__tests__/shared/didDiscovery.ts b/__tests__/shared/didDiscovery.ts index c582ca6bb..cc6096978 100644 --- a/__tests__/shared/didDiscovery.ts +++ b/__tests__/shared/didDiscovery.ts @@ -1,8 +1,7 @@ // noinspection ES6PreferShortImport import { IDIDDiscovery } from '../../packages/did-discovery/src' -import { IAgentOptions, IDataStoreORM, IDIDManager, TAgent } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' +import { IAgentOptions, ICredentialIssuer, IDataStoreORM, IDIDManager, TAgent } from '../../packages/core/src' type ConfiguredAgent = TAgent diff --git a/__tests__/shared/didManager.ts b/__tests__/shared/didManager.ts index 9cacadc14..343fcefaf 100644 --- a/__tests__/shared/didManager.ts +++ b/__tests__/shared/didManager.ts @@ -51,8 +51,8 @@ export default (testContext: { options: { // this expects the `did:ethr` provider to matchPrefix and use the `arbitrum:rinkeby` network specifier // because the configured network has that name - network: 421611 - } + network: 421611, + }, }) expect(identifier.provider).toEqual('did:ethr') expect(identifier.did).toMatch(/^did:ethr:arbitrum:rinkeby:0x.*$/) diff --git a/__tests__/shared/documentationExamples.ts b/__tests__/shared/documentationExamples.ts index 1ef8f98c4..d1fab3656 100644 --- a/__tests__/shared/documentationExamples.ts +++ b/__tests__/shared/documentationExamples.ts @@ -8,8 +8,14 @@ * `generate-plugin-schema`. */ -import { IDataStore, IDataStoreORM, IDIDManager, IMessageHandler, TAgent } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' +import { + ICredentialIssuer, + IDataStore, + IDataStoreORM, + IDIDManager, + IMessageHandler, + TAgent, +} from '../../packages/core/src' import { ISelectiveDisclosure } from '../../packages/selective-disclosure/src' type ConfiguredAgent = TAgent< diff --git a/__tests__/shared/handleSdrMessage.ts b/__tests__/shared/handleSdrMessage.ts index 915bdd0db..dfedf62ba 100644 --- a/__tests__/shared/handleSdrMessage.ts +++ b/__tests__/shared/handleSdrMessage.ts @@ -1,6 +1,7 @@ // noinspection ES6PreferShortImport import { + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -8,11 +9,10 @@ import { IMessageHandler, TAgent, } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' import { ISelectiveDisclosure, SelectiveDisclosure } from '../../packages/selective-disclosure/src' type ConfiguredAgent = TAgent< - IDIDManager & ICredentialIssuer & IDataStoreORM & IDataStore & IMessageHandler & ISelectiveDisclosure + IDIDManager & ICredentialPlugin & IDataStoreORM & IDataStore & IMessageHandler & ISelectiveDisclosure > export default (testContext: { diff --git a/__tests__/shared/saveClaims.ts b/__tests__/shared/saveClaims.ts index 09003be29..4d0c12ae3 100644 --- a/__tests__/shared/saveClaims.ts +++ b/__tests__/shared/saveClaims.ts @@ -2,6 +2,7 @@ import { FindCredentialsArgs, + ICredentialIssuer, IDataStore, IDataStoreORM, IDIDManager, @@ -9,7 +10,6 @@ import { IMessageHandler, TAgent, } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' import { ISelectiveDisclosure } from '../../packages/selective-disclosure/src' type ConfiguredAgent = TAgent< diff --git a/__tests__/shared/verifiableDataEIP712.ts b/__tests__/shared/verifiableDataEIP712.ts index 28069f0d3..cc0108b4f 100644 --- a/__tests__/shared/verifiableDataEIP712.ts +++ b/__tests__/shared/verifiableDataEIP712.ts @@ -1,6 +1,7 @@ // noinspection ES6PreferShortImport import { + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -9,11 +10,10 @@ import { VerifiableCredential, VerifiablePresentation, } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' import { ICredentialIssuerEIP712 } from '../../packages/credential-eip712/src' type ConfiguredAgent = TAgent< - IDIDManager & ICredentialIssuer & ICredentialIssuerEIP712 & IDataStore & IDataStoreORM + IDIDManager & ICredentialPlugin & ICredentialIssuerEIP712 & IDataStore & IDataStoreORM > export default (testContext: { diff --git a/__tests__/shared/verifiableDataJWT.ts b/__tests__/shared/verifiableDataJWT.ts index 694dfbf27..c3ec82026 100644 --- a/__tests__/shared/verifiableDataJWT.ts +++ b/__tests__/shared/verifiableDataJWT.ts @@ -1,6 +1,7 @@ // noinspection ES6PreferShortImport import { + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -10,11 +11,10 @@ import { VerifiableCredential, VerifiablePresentation, } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' import { decodeJWT } from 'did-jwt' import { VC_JWT_ERROR } from 'did-jwt-vc' -type ConfiguredAgent = TAgent +type ConfiguredAgent = TAgent export default (testContext: { getAgent: () => ConfiguredAgent diff --git a/__tests__/shared/verifiableDataLD.ts b/__tests__/shared/verifiableDataLD.ts index ca16e9615..5c457925e 100644 --- a/__tests__/shared/verifiableDataLD.ts +++ b/__tests__/shared/verifiableDataLD.ts @@ -1,18 +1,21 @@ // noinspection ES6PreferShortImport import { + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, IIdentifier, + IMessageHandler, TAgent, VerifiableCredential, VerifiablePresentation, } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' import { IDIDComm } from '../../packages/did-comm/src' -type ConfiguredAgent = TAgent +type ConfiguredAgent = TAgent< + IDIDManager & ICredentialPlugin & IDataStore & IDataStoreORM & IDIDComm & IMessageHandler +> export default (testContext: { getAgent: () => ConfiguredAgent diff --git a/__tests__/shared/webDidFlow.ts b/__tests__/shared/webDidFlow.ts index 3bd86ace1..64791b7da 100644 --- a/__tests__/shared/webDidFlow.ts +++ b/__tests__/shared/webDidFlow.ts @@ -1,7 +1,6 @@ // noinspection ES6PreferShortImport -import { IDIDManager, IIdentifier, IKey, TAgent } from '../../packages/core/src' -import { ICredentialIssuer } from '../../packages/credential-w3c/src' +import { ICredentialIssuer, IDIDManager, IIdentifier, IKey, TAgent } from '../../packages/core/src' type ConfiguredAgent = TAgent diff --git a/packages/cli/default/default.yml b/packages/cli/default/default.yml index f2eaa5beb..9fafe5076 100644 --- a/packages/cli/default/default.yml +++ b/packages/cli/default/default.yml @@ -302,7 +302,7 @@ agent: - $ref: /didDiscovery - $ref: /messageHandler - $require: '@veramo/did-comm#DIDComm' - - $require: '@veramo/credential-w3c#CredentialIssuer' + - $require: '@veramo/credential-w3c#CredentialPlugin' - $ref: /credentialIssuerLD - $require: '@veramo/selective-disclosure#SelectiveDisclosure' - $require: '@veramo/data-store#DataStore' diff --git a/packages/cli/src/config.ts b/packages/cli/src/config.ts index 7cb7427c1..fd0f38085 100644 --- a/packages/cli/src/config.ts +++ b/packages/cli/src/config.ts @@ -1,7 +1,8 @@ import 'cross-fetch/polyfill' import { program } from 'commander' import { SecretBox } from '@veramo/kms-local' -import { getAgent, getConfig } from './setup' +import { getAgent } from './setup' + const fs = require('fs') const { dirname } = require('path') diff --git a/packages/cli/src/setup.ts b/packages/cli/src/setup.ts index 366d51297..028ca2d1d 100644 --- a/packages/cli/src/setup.ts +++ b/packages/cli/src/setup.ts @@ -1,6 +1,7 @@ import 'cross-fetch/polyfill' import yaml from 'yaml' import { + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, @@ -9,7 +10,6 @@ import { IResolver, TAgent, } from '@veramo/core' -import { ICredentialIssuer } from '@veramo/credential-w3c' import { ISelectiveDisclosure } from '@veramo/selective-disclosure' import { IDIDComm } from '@veramo/did-comm' import { IDIDDiscovery } from '@veramo/did-discovery' @@ -40,13 +40,13 @@ export type EnabledInterfaces = IDIDManager & IResolver & IMessageHandler & IDIDComm & - ICredentialIssuer & + ICredentialPlugin & ISelectiveDisclosure & IDIDDiscovery export type ConfiguredAgent = TAgent -export function getAgent(fileName: string) { +export function getAgent(fileName: string): ConfiguredAgent { try { return createAgentFromConfig(getConfig(fileName)) } catch (e: any) { diff --git a/packages/core/package.json b/packages/core/package.json index 797ebf007..d24e23813 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -16,6 +16,9 @@ "IDataStore": "./src/types/IDataStore.ts", "IDataStoreORM": "./src/types/IDataStoreORM.ts", "IMessageHandler": "./src/types/IMessageHandler.ts", + "ICredentialIssuer": "./src/types/ICredentialIssuer.ts", + "ICredentialVerifier": "./src/types/ICredentialVerifier.ts", + "ICredentialPlugin": "./src/types/ICredentialPlugin.ts", "ICredentialStatus": "./src/types/ICredentialStatus.ts", "ICredentialStatusVerifier": "./src/types/ICredentialStatusVerifier.ts", "ICredentialStatusManager": "./src/types/ICredentialStatusManager.ts" diff --git a/packages/core/plugin.schema.json b/packages/core/plugin.schema.json index d6f646ccf..fba54a99e 100644 --- a/packages/core/plugin.schema.json +++ b/packages/core/plugin.schema.json @@ -3547,6 +3547,759 @@ } } }, + "ICredentialIssuer": { + "components": { + "schemas": { + "ICreateVerifiableCredentialArgs": { + "type": "object", + "properties": { + "credential": { + "$ref": "#/components/schemas/CredentialPayload", + "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 of the `credential`\n\n`@context`, `type` and `issuanceDate` will be added automatically if omitted" + }, + "save": { + "type": "boolean", + "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core#IDataStore | storage plugin } to be saved.", + "deprecated": "Please call\n{@link @veramo/core#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to save\nthe credential after creating it." + }, + "proofFormat": { + "$ref": "#/components/schemas/ProofFormat", + "description": "The desired format for the VerifiablePresentation to be created." + }, + "removeOriginalFields": { + "type": "boolean", + "description": "Remove payload members during JWT-JSON transformation. Defaults to `true`. See https://www.w3.org/TR/vc-data-model/#jwt-encoding" + }, + "keyRef": { + "type": "string", + "description": "[Optional] The ID of the key that should sign this credential. If this is not specified, the first matching key will be used." + }, + "fetchRemoteContexts": { + "type": "boolean", + "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.\n\nDefaults to `false`" + } + }, + "required": [ + "credential", + "proofFormat" + ], + "additionalProperties": { + "description": "Any other options that can be forwarded to the lower level libraries" + }, + "description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }" + }, + "CredentialPayload": { + "type": "object", + "properties": { + "issuer": { + "$ref": "#/components/schemas/IssuerType" + }, + "credentialSubject": { + "$ref": "#/components/schemas/CredentialSubject" + }, + "type": { + "type": "array", + "items": { + "type": "string" + } + }, + "@context": { + "type": "array", + "items": { + "type": "string" + } + }, + "issuanceDate": { + "$ref": "#/components/schemas/DateType" + }, + "expirationDate": { + "$ref": "#/components/schemas/DateType" + }, + "credentialStatus": { + "$ref": "#/components/schemas/CredentialStatusReference" + }, + "id": { + "type": "string" + } + }, + "required": [ + "issuer" + ], + "description": "Used as input when creating Verifiable Credentials" + }, + "IssuerType": { + "anyOf": [ + { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ] + }, + { + "type": "string" + } + ], + "description": "The issuer of a {@link VerifiableCredential } or the holder of a {@link VerifiablePresentation } .\n\nThe value of the issuer property MUST be either a URI or an object containing an id property. It is RECOMMENDED that the URI in the issuer or its id be one which, if de-referenced, results in a document containing machine-readable information about the issuer that can be used to verify the information expressed in the credential.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#issuer | Issuer data model }" + }, + "CredentialSubject": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "description": "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }" + }, + "DateType": { + "type": "string", + "description": "Represents an issuance or expiration date for Credentials / Presentations. This is used as input when creating them." + }, + "CredentialStatusReference": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "id", + "type" + ], + "description": "Used for the discovery of information about the current status of a verifiable credential, such as whether it is suspended or revoked. The precise contents of the credential status information is determined by the specific `credentialStatus` type definition, and varies depending on factors such as whether it is simple to implement or if it is privacy-enhancing.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#status | Credential Status }" + }, + "ProofFormat": { + "type": "string", + "enum": [ + "jwt", + "lds", + "EthereumEip712Signature2021" + ], + "description": "The type of encoding to be used for the Verifiable Credential or Presentation to be generated.\n\nOnly `jwt` and `lds` is supported at the moment." + }, + "VerifiableCredential": { + "type": "object", + "properties": { + "proof": { + "$ref": "#/components/schemas/ProofType" + }, + "issuer": { + "$ref": "#/components/schemas/IssuerType" + }, + "credentialSubject": { + "$ref": "#/components/schemas/CredentialSubject" + }, + "type": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "@context": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "issuanceDate": { + "type": "string" + }, + "expirationDate": { + "type": "string" + }, + "credentialStatus": { + "$ref": "#/components/schemas/CredentialStatusReference" + }, + "id": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "proof" + ], + "description": "Represents a signed Verifiable Credential payload (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" + }, + "ProofType": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + }, + "description": "A proof property of a {@link VerifiableCredential } or {@link VerifiablePresentation }" + }, + "ICreateVerifiablePresentationArgs": { + "type": "object", + "properties": { + "presentation": { + "$ref": "#/components/schemas/PresentationPayload", + "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 of the `presentation`\n\n`@context`, `type` and `issuanceDate` will be added automatically if omitted" + }, + "save": { + "type": "boolean", + "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core#IDataStore | storage plugin } to be saved.

", + "deprecated": "Please call\n{@link @veramo/core#IDataStore.dataStoreSaveVerifiablePresentation | dataStoreSaveVerifiablePresentation()} to\nsave the credential after creating it." + }, + "challenge": { + "type": "string", + "description": "Optional (only JWT) string challenge parameter to add to the verifiable presentation." + }, + "domain": { + "type": "string", + "description": "Optional string domain parameter to add to the verifiable presentation." + }, + "proofFormat": { + "$ref": "#/components/schemas/ProofFormat", + "description": "The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported" + }, + "removeOriginalFields": { + "type": "boolean", + "description": "Remove payload members during JWT-JSON transformation. Defaults to `true`. See https://www.w3.org/TR/vc-data-model/#jwt-encoding" + }, + "keyRef": { + "type": "string", + "description": "[Optional] The ID of the key that should sign this presentation. If this is not specified, the first matching key will be used." + }, + "fetchRemoteContexts": { + "type": "boolean", + "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.\n\nDefaults to `false`" + } + }, + "required": [ + "presentation", + "proofFormat" + ], + "additionalProperties": { + "description": "Any other options that can be forwarded to the lower level libraries" + }, + "description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }" + }, + "PresentationPayload": { + "type": "object", + "properties": { + "holder": { + "type": "string" + }, + "verifiableCredential": { + "type": "array", + "items": { + "$ref": "#/components/schemas/W3CVerifiableCredential" + } + }, + "type": { + "type": "array", + "items": { + "type": "string" + } + }, + "@context": { + "type": "array", + "items": { + "type": "string" + } + }, + "verifier": { + "type": "array", + "items": { + "type": "string" + } + }, + "issuanceDate": { + "$ref": "#/components/schemas/DateType" + }, + "expirationDate": { + "$ref": "#/components/schemas/DateType" + }, + "id": { + "type": "string" + } + }, + "required": [ + "holder" + ], + "description": "Used as input when creating Verifiable Presentations" + }, + "W3CVerifiableCredential": { + "anyOf": [ + { + "$ref": "#/components/schemas/VerifiableCredential" + }, + { + "$ref": "#/components/schemas/CompactJWT" + } + ], + "description": "Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model } \nSee {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats }" + }, + "CompactJWT": { + "type": "string", + "description": "Represents a Json Web Token in compact form. \"header.payload.signature\"" + }, + "VerifiablePresentation": { + "type": "object", + "properties": { + "proof": { + "$ref": "#/components/schemas/ProofType" + }, + "holder": { + "type": "string" + }, + "verifiableCredential": { + "type": "array", + "items": { + "$ref": "#/components/schemas/W3CVerifiableCredential" + } + }, + "type": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "@context": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "verifier": { + "type": "array", + "items": { + "type": "string" + } + }, + "issuanceDate": { + "type": "string" + }, + "expirationDate": { + "type": "string" + }, + "id": { + "type": "string" + } + }, + "required": [ + "@context", + "holder", + "proof" + ], + "description": "Represents a signed Verifiable Presentation (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" + } + }, + "methods": { + "createVerifiableCredential": { + "description": "Creates a Verifiable Credential. The payload, signer and format are chosen based on the ", + "arguments": { + "$ref": "#/components/schemas/ICreateVerifiableCredentialArgs" + }, + "returnType": { + "$ref": "#/components/schemas/VerifiableCredential" + } + }, + "createVerifiablePresentation": { + "description": "Creates a Verifiable Presentation. The payload, signer and format are chosen based on the ", + "arguments": { + "$ref": "#/components/schemas/ICreateVerifiablePresentationArgs" + }, + "returnType": { + "$ref": "#/components/schemas/VerifiablePresentation" + } + } + } + } + }, + "ICredentialVerifier": { + "components": { + "schemas": { + "IVerifyCredentialArgs": { + "type": "object", + "properties": { + "credential": { + "$ref": "#/components/schemas/W3CVerifiableCredential", + "description": "The Verifiable Credential object according to the\n {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model } or the JWT representation.\n\nThe signer of the Credential is verified based on the `issuer.id` property of the `credential` or the `iss` property of the JWT payload respectively" + }, + "fetchRemoteContexts": { + "type": "boolean", + "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.\n\nDefaults to `false`" + }, + "policies": { + "$ref": "#/components/schemas/VerificationPolicies", + "description": "Overrides specific aspects of credential verification, where possible." + } + }, + "required": [ + "credential" + ], + "additionalProperties": { + "description": "Other options can be specified for verification. They will be forwarded to the lower level modules. that perform the checks" + }, + "description": "Encapsulates the parameters required to verify a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }" + }, + "W3CVerifiableCredential": { + "anyOf": [ + { + "$ref": "#/components/schemas/VerifiableCredential" + }, + { + "$ref": "#/components/schemas/CompactJWT" + } + ], + "description": "Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model } \nSee {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats }" + }, + "VerifiableCredential": { + "type": "object", + "properties": { + "proof": { + "$ref": "#/components/schemas/ProofType" + }, + "issuer": { + "$ref": "#/components/schemas/IssuerType" + }, + "credentialSubject": { + "$ref": "#/components/schemas/CredentialSubject" + }, + "type": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "@context": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "issuanceDate": { + "type": "string" + }, + "expirationDate": { + "type": "string" + }, + "credentialStatus": { + "$ref": "#/components/schemas/CredentialStatusReference" + }, + "id": { + "type": "string" + } + }, + "required": [ + "@context", + "credentialSubject", + "issuanceDate", + "issuer", + "proof" + ], + "description": "Represents a signed Verifiable Credential payload (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" + }, + "ProofType": { + "type": "object", + "properties": { + "type": { + "type": "string" + } + }, + "description": "A proof property of a {@link VerifiableCredential } or {@link VerifiablePresentation }" + }, + "IssuerType": { + "anyOf": [ + { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "required": [ + "id" + ] + }, + { + "type": "string" + } + ], + "description": "The issuer of a {@link VerifiableCredential } or the holder of a {@link VerifiablePresentation } .\n\nThe value of the issuer property MUST be either a URI or an object containing an id property. It is RECOMMENDED that the URI in the issuer or its id be one which, if de-referenced, results in a document containing machine-readable information about the issuer that can be used to verify the information expressed in the credential.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#issuer | Issuer data model }" + }, + "CredentialSubject": { + "type": "object", + "properties": { + "id": { + "type": "string" + } + }, + "description": "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }" + }, + "CredentialStatusReference": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "type": { + "type": "string" + } + }, + "required": [ + "id", + "type" + ], + "description": "Used for the discovery of information about the current status of a verifiable credential, such as whether it is suspended or revoked. The precise contents of the credential status information is determined by the specific `credentialStatus` type definition, and varies depending on factors such as whether it is simple to implement or if it is privacy-enhancing.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#status | Credential Status }" + }, + "CompactJWT": { + "type": "string", + "description": "Represents a Json Web Token in compact form. \"header.payload.signature\"" + }, + "VerificationPolicies": { + "type": "object", + "properties": { + "now": { + "type": "number", + "description": "policy to over the now (current time) during the verification check (UNIX time in seconds)" + }, + "issuanceDate": { + "type": "boolean", + "description": "policy to skip the issuanceDate (nbf) timestamp check when set to `false`" + }, + "expirationDate": { + "type": "boolean", + "description": "policy to skip the expirationDate (exp) timestamp check when set to `false`" + }, + "audience": { + "type": "boolean", + "description": "policy to skip the audience check when set to `false`" + }, + "credentialStatus": { + "type": "boolean", + "description": "policy to skip the revocation check (credentialStatus) when set to `false`" + } + }, + "additionalProperties": { + "description": "Other options can be specified for verification. They will be forwarded to the lower level modules that perform the checks" + }, + "description": "These optional settings can be used to override some default checks that are performed on Presentations during verification." + }, + "IVerifyResult": { + "type": "object", + "properties": { + "verified": { + "type": "boolean", + "description": "This value is used to transmit the result of verification." + }, + "error": { + "$ref": "#/components/schemas/IError", + "description": "Optional Error object for the but currently the machine readable errors are not expored from DID-JWT package to be imported here" + } + }, + "required": [ + "verified" + ], + "additionalProperties": { + "description": "Other options can be specified for verification. They will be forwarded to the lower level modules. that performt the checks" + }, + "description": "Encapsulates the response object to verifyPresentation method after verifying a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }" + }, + "IError": { + "type": "object", + "properties": { + "message": { + "type": "string", + "description": "The details of the error being throw or forwarded" + }, + "errorCode": { + "type": "string", + "description": "The code for the error being throw" + } + }, + "description": "An error object, which can contain a code." + }, + "IVerifyPresentationArgs": { + "type": "object", + "properties": { + "presentation": { + "$ref": "#/components/schemas/W3CVerifiablePresentation", + "description": "The Verifiable Presentation object according to the\n {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model } or the JWT representation.\n\nThe signer of the Presentation is verified based on the `holder` property of the `presentation` or the `iss` property of the JWT payload respectively" + }, + "challenge": { + "type": "string", + "description": "Optional (only for JWT) string challenge parameter to verify the verifiable presentation against" + }, + "domain": { + "type": "string", + "description": "Optional (only for JWT) string domain parameter to verify the verifiable presentation against" + }, + "fetchRemoteContexts": { + "type": "boolean", + "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.\n\nDefaults to `false`" + }, + "policies": { + "$ref": "#/components/schemas/VerificationPolicies", + "description": "Overrides specific aspects of credential verification, where possible." + } + }, + "required": [ + "presentation" + ], + "additionalProperties": { + "description": "Other options can be specified for verification. They will be forwarded to the lower level modules. that perform the checks" + }, + "description": "Encapsulates the parameters required to verify a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }" + }, + "W3CVerifiablePresentation": { + "anyOf": [ + { + "$ref": "#/components/schemas/VerifiablePresentation" + }, + { + "$ref": "#/components/schemas/CompactJWT" + } + ], + "description": "Represents a signed Verifiable Presentation (includes proof) in either JSON or compact JWT format. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" + }, + "VerifiablePresentation": { + "type": "object", + "properties": { + "proof": { + "$ref": "#/components/schemas/ProofType" + }, + "holder": { + "type": "string" + }, + "verifiableCredential": { + "type": "array", + "items": { + "$ref": "#/components/schemas/W3CVerifiableCredential" + } + }, + "type": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "@context": { + "anyOf": [ + { + "type": "array", + "items": { + "type": "string" + } + }, + { + "type": "string" + } + ] + }, + "verifier": { + "type": "array", + "items": { + "type": "string" + } + }, + "issuanceDate": { + "type": "string" + }, + "expirationDate": { + "type": "string" + }, + "id": { + "type": "string" + } + }, + "required": [ + "@context", + "holder", + "proof" + ], + "description": "Represents a signed Verifiable Presentation (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" + } + }, + "methods": { + "verifyCredential": { + "description": "Verifies a Verifiable Credential JWT, LDS Format or EIP712.", + "arguments": { + "$ref": "#/components/schemas/IVerifyCredentialArgs" + }, + "returnType": { + "$ref": "#/components/schemas/IVerifyResult" + } + }, + "verifyPresentation": { + "description": "Verifies a Verifiable Presentation JWT or LDS Format.", + "arguments": { + "$ref": "#/components/schemas/IVerifyPresentationArgs" + }, + "returnType": { + "$ref": "#/components/schemas/IVerifyResult" + } + } + } + } + }, + "ICredentialPlugin": { + "components": { + "schemas": {}, + "methods": {} + } + }, "ICredentialStatus": { "components": { "schemas": {}, diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index d801ce511..03d59e746 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,6 +7,9 @@ export { Agent, createAgent, IAgentOptions } from './agent' export { ValidationError } from './validator' export { CoreEvents } from './coreEvents' export * from './types/IAgent' +export * from './types/ICredentialPlugin' +export * from './types/ICredentialIssuer' +export * from './types/ICredentialVerifier' export * from './types/ICredentialStatus' export * from './types/ICredentialStatusManager' export * from './types/ICredentialStatusVerifier' diff --git a/packages/core/src/types/ICredentialIssuer.ts b/packages/core/src/types/ICredentialIssuer.ts new file mode 100644 index 000000000..d6db2734d --- /dev/null +++ b/packages/core/src/types/ICredentialIssuer.ts @@ -0,0 +1,218 @@ +import { IAgentContext, IPluginMethodMap } from './IAgent' +import { + CredentialPayload, + PresentationPayload, + VerifiableCredential, + VerifiablePresentation, +} from './vc-data-model' +import { IResolver } from './IResolver' +import { IDIDManager } from './IDIDManager' +import { IDataStore } from './IDataStore' +import { IKeyManager } from './IKeyManager' + +/** + * The type of encoding to be used for the Verifiable Credential or Presentation to be generated. + * + * Only `jwt` and `lds` is supported at the moment. + * + * @public + */ +export type ProofFormat = 'jwt' | 'lds' | 'EthereumEip712Signature2021' + +/** + * 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` + * + * `@context`, `type` and `issuanceDate` will be added automatically if omitted + */ + presentation: PresentationPayload + + /** + * If this parameter is true, the resulting VerifiablePresentation is sent to the + * {@link @veramo/core#IDataStore | storage plugin} to be saved. + *

+ * @deprecated Please call + * {@link @veramo/core#IDataStore.dataStoreSaveVerifiablePresentation | dataStoreSaveVerifiablePresentation()} to + * save the credential after creating it. + */ + save?: boolean + + /** + * Optional (only JWT) string challenge parameter to add to the verifiable presentation. + */ + challenge?: string + + /** + * Optional string domain parameter to add to the verifiable presentation. + */ + domain?: string + + /** + * The desired format for the VerifiablePresentation to be created. + * Currently, only JWT is supported + */ + proofFormat: ProofFormat + + /** + * Remove payload members during JWT-JSON transformation. Defaults to `true`. + * See https://www.w3.org/TR/vc-data-model/#jwt-encoding + */ + removeOriginalFields?: boolean + + /** + * [Optional] The ID of the key that should sign this presentation. + * If this is not specified, the first matching key will be used. + */ + keyRef?: string + + /** + * When dealing with JSON-LD you also MUST provide the proper contexts. + * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. + * The context definitions SHOULD rather be provided at startup instead of being fetched. + * + * Defaults to `false` + */ + fetchRemoteContexts?: boolean + + /** + * Any other options that can be forwarded to the lower level libraries + */ + [x: string]: any +} + +/** + * 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` + * + * `@context`, `type` and `issuanceDate` will be added automatically if omitted + */ + credential: CredentialPayload + + /** + * If this parameter is true, the resulting VerifiablePresentation is sent to the + * {@link @veramo/core#IDataStore | storage plugin} to be saved. + * + * @deprecated Please call + * {@link @veramo/core#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to save + * the credential after creating it. + */ + save?: boolean + + /** + * The desired format for the VerifiablePresentation to be created. + */ + proofFormat: ProofFormat + + /** + * Remove payload members during JWT-JSON transformation. Defaults to `true`. + * See https://www.w3.org/TR/vc-data-model/#jwt-encoding + */ + removeOriginalFields?: boolean + + /** + * [Optional] The ID of the key that should sign this credential. + * If this is not specified, the first matching key will be used. + */ + keyRef?: string + + /** + * When dealing with JSON-LD you also MUST provide the proper contexts. + * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. + * The context definitions SHOULD rather be provided at startup instead of being fetched. + * + * Defaults to `false` + */ + fetchRemoteContexts?: boolean + + /** + * Any other options that can be forwarded to the lower level libraries + */ + [x: string]: any +} + +/** + * Encapsulates the response object to verifyPresentation method after verifying a + * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation} + * + * @public + */ + +/** + * The interface definition for a plugin that can generate Verifiable Credentials and Presentations + * + * @see {@link @veramo/credential-w3c#CredentialPlugin} for an implementation. + * @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 @veramo/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: IssuerAgentContext, + ): 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 @veramo/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: IssuerAgentContext, + ): 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. + * + * @beta + */ +export type IssuerAgentContext = IAgentContext< + IResolver & + Pick & + Pick & + Pick +> diff --git a/packages/core/src/types/ICredentialPlugin.ts b/packages/core/src/types/ICredentialPlugin.ts new file mode 100644 index 000000000..0033b8286 --- /dev/null +++ b/packages/core/src/types/ICredentialPlugin.ts @@ -0,0 +1,11 @@ +import { ICredentialIssuer } from './ICredentialIssuer' +import { ICredentialVerifier } from './ICredentialVerifier' + +/** + * The interface definition for a plugin that can generate and verify Verifiable Credentials and Presentations + * + * @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model} + * + * @public + */ +export type ICredentialPlugin = ICredentialIssuer & ICredentialVerifier diff --git a/packages/core/src/types/ICredentialVerifier.ts b/packages/core/src/types/ICredentialVerifier.ts new file mode 100644 index 000000000..2bbb43f54 --- /dev/null +++ b/packages/core/src/types/ICredentialVerifier.ts @@ -0,0 +1,186 @@ +import { IAgentContext, IPluginMethodMap } from './IAgent' +import { IVerifyResult } from './IVerifyResult' +import { W3CVerifiableCredential, W3CVerifiablePresentation } from './vc-data-model' +import { IResolver } from './IResolver' +import { IDIDManager } from './IDIDManager' +import { ICredentialStatusVerifier } from './ICredentialStatusVerifier' + +/** + * Encapsulates the parameters required to verify a + * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential} + * + * @public + */ +export interface IVerifyCredentialArgs { + /** + * The Verifiable Credential object according to the + * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model} or the JWT representation. + * + * The signer of the Credential is verified based on the `issuer.id` property + * of the `credential` or the `iss` property of the JWT payload respectively + * + */ + credential: W3CVerifiableCredential + + /** + * When dealing with JSON-LD you also MUST provide the proper contexts. + * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. + * The context definitions SHOULD rather be provided at startup instead of being fetched. + * + * Defaults to `false` + */ + fetchRemoteContexts?: boolean + + /** + * Overrides specific aspects of credential verification, where possible. + */ + policies?: VerificationPolicies + + /** + * Other options can be specified for verification. + * They will be forwarded to the lower level modules. that perform the checks + */ + [x: string]: any +} + +/** + * Encapsulates the parameters required to verify a + * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation} + * + * @public + */ +export interface IVerifyPresentationArgs { + /** + * The Verifiable Presentation object according to the + * {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model} or the JWT representation. + * + * The signer of the Presentation is verified based on the `holder` property + * of the `presentation` or the `iss` property of the JWT payload respectively + * + */ + presentation: W3CVerifiablePresentation + + /** + * Optional (only for JWT) string challenge parameter to verify the verifiable presentation against + */ + challenge?: string + + /** + * Optional (only for JWT) string domain parameter to verify the verifiable presentation against + */ + domain?: string + + /** + * When dealing with JSON-LD you also MUST provide the proper contexts. + * Set this to `true` ONLY if you want the `@context` URLs to be fetched in case they are not preloaded. + * The context definitions SHOULD rather be provided at startup instead of being fetched. + * + * Defaults to `false` + */ + fetchRemoteContexts?: boolean + + /** + * Overrides specific aspects of credential verification, where possible. + */ + policies?: VerificationPolicies + + /** + * Other options can be specified for verification. + * They will be forwarded to the lower level modules. that perform the checks + */ + [x: string]: any +} + +/** + * These optional settings can be used to override some default checks that are performed on Presentations during + * verification. + * + * @beta + */ +export interface VerificationPolicies { + /** + * policy to over the now (current time) during the verification check (UNIX time in seconds) + */ + now?: number + + /** + * policy to skip the issuanceDate (nbf) timestamp check when set to `false` + */ + issuanceDate?: boolean + + /** + * policy to skip the expirationDate (exp) timestamp check when set to `false` + */ + expirationDate?: boolean + + /** + * policy to skip the audience check when set to `false` + */ + audience?: boolean + + /** + * policy to skip the revocation check (credentialStatus) when set to `false` + */ + credentialStatus?: boolean + + /** + * Other options can be specified for verification. + * They will be forwarded to the lower level modules that perform the checks + */ + [x: string]: any +} + +/** + * Encapsulates the response object to verifyPresentation method after verifying a + * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation} + * + * @public + */ + +/** + * The interface definition for a plugin that can generate Verifiable Credentials and Presentations + * + * @see {@link @veramo/credential-w3c#CredentialPlugin} for an implementation. + * @remarks Please see {@link https://www.w3.org/TR/vc-data-model | W3C Verifiable Credentials data model} + * + * @public + */ +export interface ICredentialVerifier extends IPluginMethodMap { + /** + * Verifies a Verifiable Credential JWT, LDS Format or EIP712. + * + * @param args - Arguments necessary to verify a VerifiableCredential + * @param context - This reserved param is automatically added and handled by the framework, *do not override* + * + * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error` + * for details + * + * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model} + */ + verifyCredential(args: IVerifyCredentialArgs, context: VerifierAgentContext): Promise + + /** + * Verifies a Verifiable Presentation JWT or LDS Format. + * + * @param args - Arguments necessary to verify a VerifiableCredential + * @param context - This reserved param is automatically added and handled by the framework, *do not override* + * + * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error` + * for details + * + * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Credential data model} + */ + verifyPresentation(args: IVerifyPresentationArgs, context: VerifierAgentContext): 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. + * + * @beta + */ +export type VerifierAgentContext = IAgentContext< + IResolver & Pick +> diff --git a/packages/core/src/types/IKeyManager.ts b/packages/core/src/types/IKeyManager.ts index 50470e467..4e3402944 100644 --- a/packages/core/src/types/IKeyManager.ts +++ b/packages/core/src/types/IKeyManager.ts @@ -194,7 +194,7 @@ export interface IKeyManagerSignEthTXArgs { * * The methods of this plugin are used automatically by other plugins, such as * {@link @veramo/did-manager#DIDManager | DIDManager}, - * {@link @veramo/credential-w3c#CredentialIssuer | CredentialIssuer}, or {@link @veramo/did-comm#DIDComm | DIDComm} to + * {@link @veramo/credential-w3c#CredentialPlugin | CredentialPlugin}, or {@link @veramo/did-comm#DIDComm | DIDComm} to * perform their required cryptographic operations using the managed keys. * * @public diff --git a/packages/credential-ld/src/__tests__/issue-verify-flow.test.ts b/packages/credential-ld/src/__tests__/issue-verify-flow.test.ts index 7f57baa48..472843a87 100644 --- a/packages/credential-ld/src/__tests__/issue-verify-flow.test.ts +++ b/packages/credential-ld/src/__tests__/issue-verify-flow.test.ts @@ -1,13 +1,14 @@ import { createAgent, CredentialPayload, + ICredentialPlugin, IDIDManager, IIdentifier, IKeyManager, IResolver, TAgent, } from '../../../core/src' -import { CredentialIssuer, ICredentialIssuer } from '../../../credential-w3c/src' +import { CredentialPlugin } from '../../../credential-w3c/src' import { DIDManager, MemoryDIDStore } from '../../../did-manager/src' import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-manager/src' import { KeyManagementSystem } from '../../../kms-local/src' @@ -37,7 +38,7 @@ const infuraProjectId = '3586660d179141e3801c3895de1c2eba' describe('credential-LD full flow', () => { let didKeyIdentifier: IIdentifier let didEthrIdentifier: IIdentifier - let agent: TAgent + let agent: TAgent beforeAll(async () => { agent = createAgent({ @@ -65,7 +66,7 @@ describe('credential-LD full flow', () => { ...ethrDidResolver({ infuraProjectId }), }), }), - new CredentialIssuer(), + new CredentialPlugin(), new CredentialIssuerLD({ contextMaps: [LdDefaultContexts, customContext], suites: [new VeramoEd25519Signature2018(), new VeramoEcdsaSecp256k1RecoverySignature2020()], diff --git a/packages/credential-ld/src/index.ts b/packages/credential-ld/src/index.ts index aea45d00f..5bed7e0e1 100644 --- a/packages/credential-ld/src/index.ts +++ b/packages/credential-ld/src/index.ts @@ -5,7 +5,7 @@ * * This plugin adds support for working with JSON-LD credentials. * When installed, this plugin will be automatically used by - * {@link @veramo/credential-w3c#CredentialIssuer | CredentialIssuer} if the user requests the credential to be signed + * {@link @veramo/credential-w3c#CredentialPlugin | CredentialPlugin} if the user requests the credential to be signed * by one of the installed signature suites. * * @packageDocumentation diff --git a/packages/credential-w3c/package.json b/packages/credential-w3c/package.json index b4adce6fb..bf6c7b67a 100644 --- a/packages/credential-w3c/package.json +++ b/packages/credential-w3c/package.json @@ -6,12 +6,7 @@ "types": "build/index.d.ts", "scripts": { "build": "tsc", - "generate-plugin-schema": "yarn veramo dev generate-plugin-schema" - }, - "veramo": { - "pluginInterfaces": { - "ICredentialIssuer": "./src/action-handler.ts" - } + "extract-api": "yarn veramo dev extract-api" }, "dependencies": { "@veramo/core": "^3.1.4", diff --git a/packages/credential-w3c/plugin.schema.json b/packages/credential-w3c/plugin.schema.json deleted file mode 100644 index 8863d0bf4..000000000 --- a/packages/credential-w3c/plugin.schema.json +++ /dev/null @@ -1,553 +0,0 @@ -{ - "ICredentialIssuer": { - "components": { - "schemas": { - "ICreateVerifiableCredentialArgs": { - "type": "object", - "properties": { - "credential": { - "$ref": "#/components/schemas/CredentialPayload", - "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 of the `credential`\n\n`@context`, `type` and `issuanceDate` will be added automatically if omitted" - }, - "save": { - "type": "boolean", - "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core#IDataStore | storage plugin } to be saved.", - "deprecated": "Please call\n{@link @veramo/core#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to save\nthe credential after creating it." - }, - "proofFormat": { - "$ref": "#/components/schemas/ProofFormat", - "description": "The desired format for the VerifiablePresentation to be created." - }, - "removeOriginalFields": { - "type": "boolean", - "description": "Remove payload members during JWT-JSON transformation. Defaults to `true`. See https://www.w3.org/TR/vc-data-model/#jwt-encoding" - }, - "keyRef": { - "type": "string", - "description": "[Optional] The ID of the key that should sign this credential. If this is not specified, the first matching key will be used." - }, - "fetchRemoteContexts": { - "type": "boolean", - "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.", - "default": false - } - }, - "required": [ - "credential", - "proofFormat" - ], - "additionalProperties": { - "description": "Any other options that can be forwarded to the lower level libraries" - }, - "description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }" - }, - "CredentialPayload": { - "type": "object", - "properties": { - "issuer": { - "$ref": "#/components/schemas/IssuerType" - }, - "credentialSubject": { - "$ref": "#/components/schemas/CredentialSubject" - }, - "type": { - "type": "array", - "items": { - "type": "string" - } - }, - "@context": { - "type": "array", - "items": { - "type": "string" - } - }, - "issuanceDate": { - "$ref": "#/components/schemas/DateType" - }, - "expirationDate": { - "$ref": "#/components/schemas/DateType" - }, - "credentialStatus": { - "$ref": "#/components/schemas/CredentialStatusReference" - }, - "id": { - "type": "string" - } - }, - "required": [ - "issuer" - ], - "description": "Used as input when creating Verifiable Credentials" - }, - "IssuerType": { - "anyOf": [ - { - "type": "object", - "properties": { - "id": { - "type": "string" - } - }, - "required": [ - "id" - ] - }, - { - "type": "string" - } - ], - "description": "The issuer of a {@link VerifiableCredential } or the holder of a {@link VerifiablePresentation } .\n\nThe value of the issuer property MUST be either a URI or an object containing an id property. It is RECOMMENDED that the URI in the issuer or its id be one which, if de-referenced, results in a document containing machine-readable information about the issuer that can be used to verify the information expressed in the credential.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#issuer | Issuer data model }" - }, - "CredentialSubject": { - "type": "object", - "properties": { - "id": { - "type": "string" - } - }, - "description": "The value of the credentialSubject property is defined as a set of objects that contain one or more properties that are each related to a subject of the verifiable credential. Each object MAY contain an id.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject }" - }, - "DateType": { - "type": "string", - "description": "Represents an issuance or expiration date for Credentials / Presentations. This is used as input when creating them." - }, - "CredentialStatusReference": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "type": { - "type": "string" - } - }, - "required": [ - "id", - "type" - ], - "description": "Used for the discovery of information about the current status of a verifiable credential, such as whether it is suspended or revoked. The precise contents of the credential status information is determined by the specific `credentialStatus` type definition, and varies depending on factors such as whether it is simple to implement or if it is privacy-enhancing.\n\nSee {@link https://www.w3.org/TR/vc-data-model/#status | Credential Status }" - }, - "ProofFormat": { - "type": "string", - "enum": [ - "jwt", - "lds", - "EthereumEip712Signature2021" - ], - "description": "The type of encoding to be used for the Verifiable Credential or Presentation to be generated.\n\nOnly `jwt` and `lds` is supported at the moment." - }, - "VerifiableCredential": { - "type": "object", - "properties": { - "proof": { - "$ref": "#/components/schemas/ProofType" - }, - "issuer": { - "$ref": "#/components/schemas/IssuerType" - }, - "credentialSubject": { - "$ref": "#/components/schemas/CredentialSubject" - }, - "type": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "string" - } - ] - }, - "@context": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "string" - } - ] - }, - "issuanceDate": { - "type": "string" - }, - "expirationDate": { - "type": "string" - }, - "credentialStatus": { - "$ref": "#/components/schemas/CredentialStatusReference" - }, - "id": { - "type": "string" - } - }, - "required": [ - "@context", - "credentialSubject", - "issuanceDate", - "issuer", - "proof" - ], - "description": "Represents a signed Verifiable Credential payload (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" - }, - "ProofType": { - "type": "object", - "properties": { - "type": { - "type": "string" - } - }, - "description": "A proof property of a {@link VerifiableCredential } or {@link VerifiablePresentation }" - }, - "ICreateVerifiablePresentationArgs": { - "type": "object", - "properties": { - "presentation": { - "$ref": "#/components/schemas/PresentationPayload", - "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 of the `presentation`\n\n`@context`, `type` and `issuanceDate` will be added automatically if omitted" - }, - "save": { - "type": "boolean", - "description": "If this parameter is true, the resulting VerifiablePresentation is sent to the\n {@link @veramo/core#IDataStore | storage plugin } to be saved.

", - "deprecated": "Please call\n{@link @veramo/core#IDataStore.dataStoreSaveVerifiablePresentation | dataStoreSaveVerifiablePresentation()} to\nsave the credential after creating it." - }, - "challenge": { - "type": "string", - "description": "Optional (only JWT) string challenge parameter to add to the verifiable presentation." - }, - "domain": { - "type": "string", - "description": "Optional string domain parameter to add to the verifiable presentation." - }, - "proofFormat": { - "$ref": "#/components/schemas/ProofFormat", - "description": "The desired format for the VerifiablePresentation to be created. Currently, only JWT is supported" - }, - "removeOriginalFields": { - "type": "boolean", - "description": "Remove payload members during JWT-JSON transformation. Defaults to `true`. See https://www.w3.org/TR/vc-data-model/#jwt-encoding" - }, - "keyRef": { - "type": "string", - "description": "[Optional] The ID of the key that should sign this presentation. If this is not specified, the first matching key will be used." - }, - "fetchRemoteContexts": { - "type": "boolean", - "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.", - "default": false - } - }, - "required": [ - "presentation", - "proofFormat" - ], - "additionalProperties": { - "description": "Any other options that can be forwarded to the lower level libraries" - }, - "description": "Encapsulates the parameters required to create a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }" - }, - "PresentationPayload": { - "type": "object", - "properties": { - "holder": { - "type": "string" - }, - "verifiableCredential": { - "type": "array", - "items": { - "$ref": "#/components/schemas/W3CVerifiableCredential" - } - }, - "type": { - "type": "array", - "items": { - "type": "string" - } - }, - "@context": { - "type": "array", - "items": { - "type": "string" - } - }, - "verifier": { - "type": "array", - "items": { - "type": "string" - } - }, - "issuanceDate": { - "$ref": "#/components/schemas/DateType" - }, - "expirationDate": { - "$ref": "#/components/schemas/DateType" - }, - "id": { - "type": "string" - } - }, - "required": [ - "holder" - ], - "description": "Used as input when creating Verifiable Presentations" - }, - "W3CVerifiableCredential": { - "anyOf": [ - { - "$ref": "#/components/schemas/VerifiableCredential" - }, - { - "$ref": "#/components/schemas/CompactJWT" - } - ], - "description": "Represents a signed Verifiable Credential (includes proof), in either JSON or compact JWT format. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model } \nSee {@link https://www.w3.org/TR/vc-data-model/#proof-formats | proof formats }" - }, - "CompactJWT": { - "type": "string", - "description": "Represents a Json Web Token in compact form. \"header.payload.signature\"" - }, - "VerifiablePresentation": { - "type": "object", - "properties": { - "proof": { - "$ref": "#/components/schemas/ProofType" - }, - "holder": { - "type": "string" - }, - "verifiableCredential": { - "type": "array", - "items": { - "$ref": "#/components/schemas/W3CVerifiableCredential" - } - }, - "type": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "string" - } - ] - }, - "@context": { - "anyOf": [ - { - "type": "array", - "items": { - "type": "string" - } - }, - { - "type": "string" - } - ] - }, - "verifier": { - "type": "array", - "items": { - "type": "string" - } - }, - "issuanceDate": { - "type": "string" - }, - "expirationDate": { - "type": "string" - }, - "id": { - "type": "string" - } - }, - "required": [ - "@context", - "holder", - "proof" - ], - "description": "Represents a signed Verifiable Presentation (includes proof), using a JSON representation. See {@link https://www.w3.org/TR/vc-data-model/#presentations | VP data model }" - }, - "IVerifyCredentialArgs": { - "type": "object", - "properties": { - "credential": { - "$ref": "#/components/schemas/W3CVerifiableCredential", - "description": "The Verifiable Credential object according to the\n {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model } or the JWT representation.\n\nThe signer of the Credential is verified based on the `issuer.id` property of the `credential` or the `iss` property of the JWT payload respectively" - }, - "fetchRemoteContexts": { - "type": "boolean", - "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.", - "default": false - }, - "policies": { - "$ref": "#/components/schemas/VerificationPolicies", - "description": "Overrides specific aspects of credential verification, where possible." - } - }, - "required": [ - "credential" - ], - "additionalProperties": { - "description": "Other options can be specified for verification. They will be forwarded to the lower level modules. that perform the checks" - }, - "description": "Encapsulates the parameters required to verify a\n {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential }" - }, - "VerificationPolicies": { - "type": "object", - "properties": { - "now": { - "type": "number", - "description": "policy to over the now (current time) during the verification check (UNIX time in seconds)" - }, - "issuanceDate": { - "type": "boolean", - "description": "policy to skip the issuanceDate (nbf) timestamp check when set to `false`" - }, - "expirationDate": { - "type": "boolean", - "description": "policy to skip the expirationDate (exp) timestamp check when set to `false`" - }, - "audience": { - "type": "boolean", - "description": "policy to skip the audience check when set to `false`" - }, - "credentialStatus": { - "type": "boolean", - "description": "policy to skip the revocation check (credentialStatus) when set to `false`" - } - }, - "additionalProperties": { - "description": "Other options can be specified for verification. They will be forwarded to the lower level modules that perform the checks" - }, - "description": "These optional settings can be used to override some default checks that are performed on Presentations during verification." - }, - "IVerifyResult": { - "type": "object", - "properties": { - "verified": { - "type": "boolean", - "description": "This value is used to transmit the result of verification." - }, - "error": { - "$ref": "#/components/schemas/IError", - "description": "Optional Error object for the but currently the machine readable errors are not expored from DID-JWT package to be imported here" - } - }, - "required": [ - "verified" - ], - "additionalProperties": { - "description": "Other options can be specified for verification. They will be forwarded to the lower level modules. that performt the checks" - }, - "description": "Encapsulates the response object to verifyPresentation method after verifying a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }" - }, - "IError": { - "type": "object", - "properties": { - "message": { - "type": "string", - "description": "The details of the error being throw or forwarded" - }, - "errorCode": { - "type": "string", - "description": "The code for the error being throw" - } - }, - "description": "An error object, which can contain a code." - }, - "IVerifyPresentationArgs": { - "type": "object", - "properties": { - "presentation": { - "$ref": "#/components/schemas/W3CVerifiablePresentation", - "description": "The Verifiable Presentation object according to the\n {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model } or the JWT representation.\n\nThe signer of the Presentation is verified based on the `holder` property of the `presentation` or the `iss` property of the JWT payload respectively" - }, - "challenge": { - "type": "string", - "description": "Optional (only for JWT) string challenge parameter to verify the verifiable presentation against" - }, - "domain": { - "type": "string", - "description": "Optional (only for JWT) string domain parameter to verify the verifiable presentation against" - }, - "fetchRemoteContexts": { - "type": "boolean", - "description": "When dealing with JSON-LD you also MUST provide the proper contexts. Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. The context definitions SHOULD rather be provided at startup instead of being fetched.", - "default": false - }, - "policies": { - "$ref": "#/components/schemas/VerificationPolicies", - "description": "Overrides specific aspects of credential verification, where possible." - } - }, - "required": [ - "presentation" - ], - "additionalProperties": { - "description": "Other options can be specified for verification. They will be forwarded to the lower level modules. that perform the checks" - }, - "description": "Encapsulates the parameters required to verify a\n {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation }" - }, - "W3CVerifiablePresentation": { - "anyOf": [ - { - "$ref": "#/components/schemas/VerifiablePresentation" - }, - { - "$ref": "#/components/schemas/CompactJWT" - } - ], - "description": "Represents a signed Verifiable Presentation (includes proof) in either JSON or compact JWT format. See {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model }" - } - }, - "methods": { - "createVerifiableCredential": { - "description": "Creates a Verifiable Credential. The payload, signer and format are chosen based on the ", - "arguments": { - "$ref": "#/components/schemas/ICreateVerifiableCredentialArgs" - }, - "returnType": { - "$ref": "#/components/schemas/VerifiableCredential" - } - }, - "createVerifiablePresentation": { - "description": "Creates a Verifiable Presentation. The payload, signer and format are chosen based on the ", - "arguments": { - "$ref": "#/components/schemas/ICreateVerifiablePresentationArgs" - }, - "returnType": { - "$ref": "#/components/schemas/VerifiablePresentation" - } - }, - "verifyCredential": { - "description": "Verifies a Verifiable Credential JWT, LDS Format or EIP712.", - "arguments": { - "$ref": "#/components/schemas/IVerifyCredentialArgs" - }, - "returnType": { - "$ref": "#/components/schemas/IVerifyResult" - } - }, - "verifyPresentation": { - "description": "Verifies a Verifiable Presentation JWT or LDS Format.", - "arguments": { - "$ref": "#/components/schemas/IVerifyPresentationArgs" - }, - "returnType": { - "$ref": "#/components/schemas/IVerifyResult" - } - } - } - } - } -} \ No newline at end of file diff --git a/packages/credential-w3c/src/__tests__/action-handler.test.ts b/packages/credential-w3c/src/__tests__/action-handler.test.ts index ddec04dda..2cc309130 100644 --- a/packages/credential-w3c/src/__tests__/action-handler.test.ts +++ b/packages/credential-w3c/src/__tests__/action-handler.test.ts @@ -10,8 +10,20 @@ jest.mock('did-jwt-vc', () => { return mockDidJwtVc }) -import { CredentialPayload, IIdentifier, IKey, PresentationPayload, VerifiableCredential } from '@veramo/core' -import { CredentialIssuer, IContext } from '../action-handler' +import { + CredentialPayload, + ICredentialPlugin, + IDataStore, + IDIDManager, + IIdentifier, + IKey, + IKeyManager, + IResolver, + PresentationPayload, + TAgent, + VerifiableCredential, +} from '@veramo/core' +import { CredentialPlugin } from '../action-handler' const mockIdentifiers: IIdentifier[] = [ { @@ -58,7 +70,7 @@ const mockIdentifiers: IIdentifier[] = [ }, ] -const w3c = new CredentialIssuer() +const w3c = new CredentialPlugin() let agent = { execute: jest.fn(), @@ -84,14 +96,14 @@ let agent = { createVerifiablePresentationLD: jest.fn(), verifyCredentialLD: jest.fn(), verifyPresentationLD: jest.fn(), -} +} as any as TAgent describe('@veramo/credential-w3c', () => { test.each(mockIdentifiers)('handles createVerifiableCredential', async (mockIdentifier) => { expect.assertions(3) agent.didManagerGet = jest.fn().mockImplementation(async (args): Promise => mockIdentifier) - const context: IContext = { agent: agent } + const context = { agent } const credential: CredentialPayload = { '@context': ['https://www.w3.org/2018/credentials/v1', 'https://www.w3.org/2020/demo/4342323'], @@ -130,7 +142,7 @@ describe('@veramo/credential-w3c', () => { expect.assertions(3) agent.didManagerGet = jest.fn().mockImplementation(async (args): Promise => mockIdentifier) - const context: IContext = { agent: agent } + const context = { agent } const credential: VerifiableCredential = { '@context': ['https://www.w3.org/2018/credentials/v1'], diff --git a/packages/credential-w3c/src/__tests__/issue-verify-flow.test.ts b/packages/credential-w3c/src/__tests__/issue-verify-flow.test.ts index edae37d6a..0ed587138 100644 --- a/packages/credential-w3c/src/__tests__/issue-verify-flow.test.ts +++ b/packages/credential-w3c/src/__tests__/issue-verify-flow.test.ts @@ -1,19 +1,20 @@ import { createAgent, CredentialPayload, + ICredentialPlugin, IDIDManager, IIdentifier, IKeyManager, IResolver, TAgent, } from '../../../core/src' -import { CredentialIssuer, ICredentialIssuer } from '../../../credential-w3c/src' +import { CredentialIssuer } from '../../../credential-w3c/src' import { DIDManager, MemoryDIDStore } from '../../../did-manager/src' import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-manager/src' import { KeyManagementSystem } from '../../../kms-local/src' import { getDidKeyResolver, KeyDIDProvider } from '../../../did-provider-key/src' import { DIDResolverPlugin } from '../../../did-resolver/src' -import { EthrDIDProvider } from "../../../did-provider-ethr/src"; +import { EthrDIDProvider } from '../../../did-provider-ethr/src' import { ContextDoc } from '../../../credential-ld/src/types' import { Resolver } from 'did-resolver' import { getResolver as ethrDidResolver } from 'ethr-did-resolver' @@ -33,7 +34,7 @@ const infuraProjectId = '3586660d179141e3801c3895de1c2eba' describe('credential-w3c full flow', () => { let didKeyIdentifier: IIdentifier let didEthrIdentifier: IIdentifier - let agent: TAgent + let agent: TAgent beforeAll(async () => { agent = createAgent({ @@ -58,14 +59,14 @@ describe('credential-w3c full flow', () => { new DIDResolverPlugin({ resolver: new Resolver({ ...getDidKeyResolver(), - ...ethrDidResolver({ infuraProjectId, }), + ...ethrDidResolver({ infuraProjectId }), }), }), new CredentialIssuer(), ], }) didKeyIdentifier = await agent.didManagerCreate() - didEthrIdentifier = await agent.didManagerCreate({ provider: "did:ethr:goerli" }) + didEthrIdentifier = await agent.didManagerCreate({ provider: 'did:ethr:goerli' }) }) it('verify a verifiablePresentation', async () => { @@ -84,9 +85,9 @@ describe('credential-w3c full flow', () => { const verifiablePresentation = await agent.createVerifiablePresentation({ presentation: { verifiableCredential: [verifiableCredential1], - holder: didKeyIdentifier.did + holder: didKeyIdentifier.did, }, - challenge: "VERAMO", + challenge: 'VERAMO', proofFormat: 'jwt', }) @@ -94,14 +95,15 @@ describe('credential-w3c full flow', () => { const response = await agent.verifyPresentation({ presentation: verifiablePresentation, - challenge: "VERAMO", + challenge: 'VERAMO', }) expect(response.verified).toBe(true) }) it.only('fails the verification of an expired credential', async () => { - const presentationJWT = 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjAyOTcyMTAsInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZVByZXNlbnRhdGlvbiJdLCJ2ZXJpZmlhYmxlQ3JlZGVudGlhbCI6WyJleUpoYkdjaU9pSkZaRVJUUVNJc0luUjVjQ0k2SWtwWFZDSjkuZXlKbGVIQWlPakUyTmpBeU9UY3lNVEFzSW5aaklqcDdJa0JqYjI1MFpYaDBJanBiSW1oMGRIQnpPaTh2ZDNkM0xuY3pMbTl5Wnk4eU1ERTRMMk55WldSbGJuUnBZV3h6TDNZeElpd2lZM1Z6ZEc5dE9tVjRZVzF3YkdVdVkyOXVkR1Y0ZENKZExDSjBlWEJsSWpwYklsWmxjbWxtYVdGaWJHVkRjbVZrWlc1MGFXRnNJbDBzSW1OeVpXUmxiblJwWVd4VGRXSnFaV04wSWpwN0ltNXZkR2hwYm1jaU9pSmxiSE5sSUcxaGRIUmxjbk1pZlgwc0ltNWlaaUk2TVRZMk1ESTVOekl4TUN3aWFYTnpJam9pWkdsa09tdGxlVHA2TmsxcmFWVTNVbk5hVnpOeWFXVmxRMjg1U25OMVVEUnpRWEZYZFdGRE0zbGhjbWwxWVZCMlVXcHRZVzVsWTFBaWZRLkZhdzBEUWNNdXpacEVkcy1LR3dOalMyM2IzbUEzZFhQWXBQcGJzNmRVSnhIOVBrZzVieGF3UDVwMlNPajdQM25IdEpCR3lwTjJ3NzRfZjc3SjF5dUJ3Il19LCJuYmYiOjE2NjAyOTcyMTAsImlzcyI6ImRpZDprZXk6ejZNa2lVN1JzWlczcmllZUNvOUpzdVA0c0FxV3VhQzN5YXJpdWFQdlFqbWFuZWNQIn0.YcYbyqVlD8YsTjVw0kCEs0P_ie6SFMakf_ncPntEjsmS9C4cKyiS50ZhNkOv0R3Roy1NrzX7h93WBU55KeJlCw' + const presentationJWT = + 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjAyOTcyMTAsInZwIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZVByZXNlbnRhdGlvbiJdLCJ2ZXJpZmlhYmxlQ3JlZGVudGlhbCI6WyJleUpoYkdjaU9pSkZaRVJUUVNJc0luUjVjQ0k2SWtwWFZDSjkuZXlKbGVIQWlPakUyTmpBeU9UY3lNVEFzSW5aaklqcDdJa0JqYjI1MFpYaDBJanBiSW1oMGRIQnpPaTh2ZDNkM0xuY3pMbTl5Wnk4eU1ERTRMMk55WldSbGJuUnBZV3h6TDNZeElpd2lZM1Z6ZEc5dE9tVjRZVzF3YkdVdVkyOXVkR1Y0ZENKZExDSjBlWEJsSWpwYklsWmxjbWxtYVdGaWJHVkRjbVZrWlc1MGFXRnNJbDBzSW1OeVpXUmxiblJwWVd4VGRXSnFaV04wSWpwN0ltNXZkR2hwYm1jaU9pSmxiSE5sSUcxaGRIUmxjbk1pZlgwc0ltNWlaaUk2TVRZMk1ESTVOekl4TUN3aWFYTnpJam9pWkdsa09tdGxlVHA2TmsxcmFWVTNVbk5hVnpOeWFXVmxRMjg1U25OMVVEUnpRWEZYZFdGRE0zbGhjbWwxWVZCMlVXcHRZVzVsWTFBaWZRLkZhdzBEUWNNdXpacEVkcy1LR3dOalMyM2IzbUEzZFhQWXBQcGJzNmRVSnhIOVBrZzVieGF3UDVwMlNPajdQM25IdEpCR3lwTjJ3NzRfZjc3SjF5dUJ3Il19LCJuYmYiOjE2NjAyOTcyMTAsImlzcyI6ImRpZDprZXk6ejZNa2lVN1JzWlczcmllZUNvOUpzdVA0c0FxV3VhQzN5YXJpdWFQdlFqbWFuZWNQIn0.YcYbyqVlD8YsTjVw0kCEs0P_ie6SFMakf_ncPntEjsmS9C4cKyiS50ZhNkOv0R3Roy1NrzX7h93WBU55KeJlCw' const response = await agent.verifyPresentation({ presentation: presentationJWT, @@ -112,10 +114,10 @@ describe('credential-w3c full flow', () => { expect(response.error?.message).toContain('JWT has expired') }) + it('fails the verification with nbf in the future', async () => { + const presentationJWT = + 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXSwidmVyaWZpYWJsZUNyZWRlbnRpYWwiOlsiZXlKaGJHY2lPaUpGWkVSVFFTSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjJZeUk2ZXlKQVkyOXVkR1Y0ZENJNld5Sm9kSFJ3Y3pvdkwzZDNkeTUzTXk1dmNtY3ZNakF4T0M5amNtVmtaVzUwYVdGc2N5OTJNU0lzSW1OMWMzUnZiVHBsZUdGdGNHeGxMbU52Ym5SbGVIUWlYU3dpZEhsd1pTSTZXeUpXWlhKcFptbGhZbXhsUTNKbFpHVnVkR2xoYkNKZExDSmpjbVZrWlc1MGFXRnNVM1ZpYW1WamRDSTZleUp1YjNSb2FXNW5Jam9pWld4elpTQnRZWFIwWlhKekluMTlMQ0p1WW1ZaU9qRXhOall3TWprNE5UZzRMQ0pwYzNNaU9pSmthV1E2YTJWNU9ubzJUV3QyYlhCeFRXbDFOM2h1U25kVE9YQkVSR0ZSYW1oQ1dUWndlbU00V1RKQ2FWRnhSWFUwZW1GRldFMVdUQ0o5LnA4Y2FTS1pTcGdISm1TRzhMekpnSWlWMzFRU3NjOEJ2anZuQ1JrOEM3X1UxLXV5cS11MHlQcDdjRWlSOUtXTnprN2RDQlBiR2pBRGRiNC0tV3V5LUNRIl19LCJuYmYiOjI2NjAyOTg1ODgsImlzcyI6ImRpZDprZXk6ejZNa3ZtcHFNaXU3eG5Kd1M5cEREYVFqaEJZNnB6YzhZMkJpUXFFdTR6YUVYTVZMIiwibm9uY2UiOiJWRVJBTU8ifQ.F-uiI2iVMcdm1VFzkXgtZqq8QGw5XnyEI36vGblBluHnklnNYNmE5eluQ23dbcduGWSe3ZJJ65C7HrPTUoXvDA' - it('fails the verification with nbf in the future',async () => { - const presentationJWT = 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXSwidmVyaWZpYWJsZUNyZWRlbnRpYWwiOlsiZXlKaGJHY2lPaUpGWkVSVFFTSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjJZeUk2ZXlKQVkyOXVkR1Y0ZENJNld5Sm9kSFJ3Y3pvdkwzZDNkeTUzTXk1dmNtY3ZNakF4T0M5amNtVmtaVzUwYVdGc2N5OTJNU0lzSW1OMWMzUnZiVHBsZUdGdGNHeGxMbU52Ym5SbGVIUWlYU3dpZEhsd1pTSTZXeUpXWlhKcFptbGhZbXhsUTNKbFpHVnVkR2xoYkNKZExDSmpjbVZrWlc1MGFXRnNVM1ZpYW1WamRDSTZleUp1YjNSb2FXNW5Jam9pWld4elpTQnRZWFIwWlhKekluMTlMQ0p1WW1ZaU9qRXhOall3TWprNE5UZzRMQ0pwYzNNaU9pSmthV1E2YTJWNU9ubzJUV3QyYlhCeFRXbDFOM2h1U25kVE9YQkVSR0ZSYW1oQ1dUWndlbU00V1RKQ2FWRnhSWFUwZW1GRldFMVdUQ0o5LnA4Y2FTS1pTcGdISm1TRzhMekpnSWlWMzFRU3NjOEJ2anZuQ1JrOEM3X1UxLXV5cS11MHlQcDdjRWlSOUtXTnprN2RDQlBiR2pBRGRiNC0tV3V5LUNRIl19LCJuYmYiOjI2NjAyOTg1ODgsImlzcyI6ImRpZDprZXk6ejZNa3ZtcHFNaXU3eG5Kd1M5cEREYVFqaEJZNnB6YzhZMkJpUXFFdTR6YUVYTVZMIiwibm9uY2UiOiJWRVJBTU8ifQ.F-uiI2iVMcdm1VFzkXgtZqq8QGw5XnyEI36vGblBluHnklnNYNmE5eluQ23dbcduGWSe3ZJJ65C7HrPTUoXvDA' - const response = await agent.verifyPresentation({ presentation: presentationJWT, }) @@ -131,7 +133,7 @@ describe('credential-w3c full flow', () => { // it('passes the verification of an expired credential with policy exp false',async () => { // const presentationJWT = 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXSwidmVyaWZpYWJsZUNyZWRlbnRpYWwiOlsiZXlKaGJHY2lPaUpGWkVSVFFTSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjJZeUk2ZXlKQVkyOXVkR1Y0ZENJNld5Sm9kSFJ3Y3pvdkwzZDNkeTUzTXk1dmNtY3ZNakF4T0M5amNtVmtaVzUwYVdGc2N5OTJNU0lzSW1OMWMzUnZiVHBsZUdGdGNHeGxMbU52Ym5SbGVIUWlYU3dpZEhsd1pTSTZXeUpXWlhKcFptbGhZbXhsUTNKbFpHVnVkR2xoYkNKZExDSmpjbVZrWlc1MGFXRnNVM1ZpYW1WamRDSTZleUp1YjNSb2FXNW5Jam9pWld4elpTQnRZWFIwWlhKekluMTlMQ0p1WW1ZaU9qRXhOall3TWprNE5UZzRMQ0pwYzNNaU9pSmthV1E2YTJWNU9ubzJUV3QyYlhCeFRXbDFOM2h1U25kVE9YQkVSR0ZSYW1oQ1dUWndlbU00V1RKQ2FWRnhSWFUwZW1GRldFMVdUQ0o5LnA4Y2FTS1pTcGdISm1TRzhMekpnSWlWMzFRU3NjOEJ2anZuQ1JrOEM3X1UxLXV5cS11MHlQcDdjRWlSOUtXTnprN2RDQlBiR2pBRGRiNC0tV3V5LUNRIl19LCJuYmYiOjI2NjAyOTg1ODgsImlzcyI6ImRpZDprZXk6ejZNa3ZtcHFNaXU3eG5Kd1M5cEREYVFqaEJZNnB6YzhZMkJpUXFFdTR6YUVYTVZMIiwibm9uY2UiOiJWRVJBTU8ifQ.F-uiI2iVMcdm1VFzkXgtZqq8QGw5XnyEI36vGblBluHnklnNYNmE5eluQ23dbcduGWSe3ZJJ65C7HrPTUoXvDA' - + // const response = await agent.verifyPresentation({ // presentation: presentationJWT, // policies: { @@ -144,10 +146,10 @@ describe('credential-w3c full flow', () => { // it('passes the verification with nbf in the future with policy nbf false',async () => { // const presentationJWT = 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJ2cCI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdLCJ0eXBlIjpbIlZlcmlmaWFibGVQcmVzZW50YXRpb24iXSwidmVyaWZpYWJsZUNyZWRlbnRpYWwiOlsiZXlKaGJHY2lPaUpGWkVSVFFTSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjJZeUk2ZXlKQVkyOXVkR1Y0ZENJNld5Sm9kSFJ3Y3pvdkwzZDNkeTUzTXk1dmNtY3ZNakF4T0M5amNtVmtaVzUwYVdGc2N5OTJNU0lzSW1OMWMzUnZiVHBsZUdGdGNHeGxMbU52Ym5SbGVIUWlYU3dpZEhsd1pTSTZXeUpXWlhKcFptbGhZbXhsUTNKbFpHVnVkR2xoYkNKZExDSmpjbVZrWlc1MGFXRnNVM1ZpYW1WamRDSTZleUp1YjNSb2FXNW5Jam9pWld4elpTQnRZWFIwWlhKekluMTlMQ0p1WW1ZaU9qRXhOall3TWprNE5UZzRMQ0pwYzNNaU9pSmthV1E2YTJWNU9ubzJUV3QyYlhCeFRXbDFOM2h1U25kVE9YQkVSR0ZSYW1oQ1dUWndlbU00V1RKQ2FWRnhSWFUwZW1GRldFMVdUQ0o5LnA4Y2FTS1pTcGdISm1TRzhMekpnSWlWMzFRU3NjOEJ2anZuQ1JrOEM3X1UxLXV5cS11MHlQcDdjRWlSOUtXTnprN2RDQlBiR2pBRGRiNC0tV3V5LUNRIl19LCJuYmYiOjI2NjAyOTg1ODgsImlzcyI6ImRpZDprZXk6ejZNa3ZtcHFNaXU3eG5Kd1M5cEREYVFqaEJZNnB6YzhZMkJpUXFFdTR6YUVYTVZMIiwibm9uY2UiOiJWRVJBTU8ifQ.F-uiI2iVMcdm1VFzkXgtZqq8QGw5XnyEI36vGblBluHnklnNYNmE5eluQ23dbcduGWSe3ZJJ65C7HrPTUoXvDA' - + // const response = await agent.verifyPresentation({ // presentation: presentationJWT, - // policies: { + // policies: { // nbf: false // } // }) diff --git a/packages/credential-w3c/src/__tests__/message-handler.test.ts b/packages/credential-w3c/src/__tests__/message-handler.test.ts index 0948234dc..4fc4a795e 100644 --- a/packages/credential-w3c/src/__tests__/message-handler.test.ts +++ b/packages/credential-w3c/src/__tests__/message-handler.test.ts @@ -1,5 +1,5 @@ -import { DIDResolutionResult } from '@veramo/core' -import { Message } from '@veramo/message-handler' +import { DIDResolutionResult } from '../../../core/src' +import { Message } from '../../../message-handler/src' import { W3cMessageHandler, MessageTypes } from '../index' import { IContext } from '../message-handler' import { blake2bHex } from 'blakejs' diff --git a/packages/credential-w3c/src/action-handler.ts b/packages/credential-w3c/src/action-handler.ts index fcbd3ebed..42a9f24a4 100644 --- a/packages/credential-w3c/src/action-handler.ts +++ b/packages/credential-w3c/src/action-handler.ts @@ -1,18 +1,21 @@ import { - CredentialPayload, IAgentContext, IAgentPlugin, - IDataStore, - IDIDManager, + ICreateVerifiableCredentialArgs, + ICreateVerifiablePresentationArgs, + ICredentialPlugin, + ICredentialStatusVerifier, IIdentifier, IKey, IKeyManager, - IPluginMethodMap, - IResolver, + IssuerAgentContext, + IVerifyCredentialArgs, + IVerifyPresentationArgs, IVerifyResult, - PresentationPayload, + schema, VerifiableCredential, VerifiablePresentation, + VerifierAgentContext, W3CVerifiableCredential, W3CVerifiablePresentation, } from '@veramo/core' @@ -37,7 +40,6 @@ import { } from '@veramo/utils' import Debug from 'debug' import { Resolvable } from 'did-resolver' -import { schema } from './' const enum DocumentFormat { JWT, @@ -48,368 +50,13 @@ const enum DocumentFormat { const debug = Debug('veramo:w3c:action-handler') /** - * The type of encoding to be used for the Verifiable Credential or Presentation to be generated. - * - * Only `jwt` and `lds` is supported at the moment. - * - * @public - */ -export type ProofFormat = 'jwt' | 'lds' | 'EthereumEip712Signature2021' - -/** - * 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` - * - * `@context`, `type` and `issuanceDate` will be added automatically if omitted - */ - presentation: PresentationPayload - - /** - * If this parameter is true, the resulting VerifiablePresentation is sent to the - * {@link @veramo/core#IDataStore | storage plugin} to be saved. - *

- * @deprecated Please call - * {@link @veramo/core#IDataStore.dataStoreSaveVerifiablePresentation | dataStoreSaveVerifiablePresentation()} to - * save the credential after creating it. - */ - save?: boolean - - /** - * Optional (only JWT) string challenge parameter to add to the verifiable presentation. - */ - challenge?: string - - /** - * Optional string domain parameter to add to the verifiable presentation. - */ - domain?: string - - /** - * The desired format for the VerifiablePresentation to be created. - * Currently, only JWT is supported - */ - proofFormat: ProofFormat - - /** - * Remove payload members during JWT-JSON transformation. Defaults to `true`. - * See https://www.w3.org/TR/vc-data-model/#jwt-encoding - */ - removeOriginalFields?: boolean - - /** - * [Optional] The ID of the key that should sign this presentation. - * If this is not specified, the first matching key will be used. - */ - keyRef?: string - - /** - * When dealing with JSON-LD you also MUST provide the proper contexts. - * Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. - * The context definitions SHOULD rather be provided at startup instead of being fetched. - * - * @default false - */ - fetchRemoteContexts?: boolean - - /** - * Any other options that can be forwarded to the lower level libraries - */ - [x: string]: any -} - -/** - * 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` - * - * `@context`, `type` and `issuanceDate` will be added automatically if omitted - */ - credential: CredentialPayload - - /** - * If this parameter is true, the resulting VerifiablePresentation is sent to the - * {@link @veramo/core#IDataStore | storage plugin} to be saved. - * - * @deprecated Please call - * {@link @veramo/core#IDataStore.dataStoreSaveVerifiableCredential | dataStoreSaveVerifiableCredential()} to save - * the credential after creating it. - */ - save?: boolean - - /** - * The desired format for the VerifiablePresentation to be created. - */ - proofFormat: ProofFormat - - /** - * Remove payload members during JWT-JSON transformation. Defaults to `true`. - * See https://www.w3.org/TR/vc-data-model/#jwt-encoding - */ - removeOriginalFields?: boolean - - /** - * [Optional] The ID of the key that should sign this credential. - * If this is not specified, the first matching key will be used. - */ - keyRef?: string - - /** - * When dealing with JSON-LD you also MUST provide the proper contexts. - * Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. - * The context definitions SHOULD rather be provided at startup instead of being fetched. - * - * @default false - */ - fetchRemoteContexts?: boolean - - /** - * Any other options that can be forwarded to the lower level libraries - */ - [x: string]: any -} - -/** - * Encapsulates the parameters required to verify a - * {@link https://www.w3.org/TR/vc-data-model/#credentials | W3C Verifiable Credential} - * - * @public - */ -export interface IVerifyCredentialArgs { - /** - * The Verifiable Credential object according to the - * {@link https://www.w3.org/TR/vc-data-model/#credentials | canonical model} or the JWT representation. - * - * The signer of the Credential is verified based on the `issuer.id` property - * of the `credential` or the `iss` property of the JWT payload respectively - * - */ - credential: W3CVerifiableCredential - - /** - * When dealing with JSON-LD you also MUST provide the proper contexts. - * Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. - * The context definitions SHOULD rather be provided at startup instead of being fetched. - * - * @default false - */ - fetchRemoteContexts?: boolean - - /** - * Overrides specific aspects of credential verification, where possible. - */ - policies?: VerificationPolicies - - /** - * Other options can be specified for verification. - * They will be forwarded to the lower level modules. that perform the checks - */ - [x: string]: any -} - -/** - * Encapsulates the parameters required to verify a - * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation} - * - * @public - */ -export interface IVerifyPresentationArgs { - /** - * The Verifiable Presentation object according to the - * {@link https://www.w3.org/TR/vc-data-model/#presentations | canonical model} or the JWT representation. - * - * The signer of the Presentation is verified based on the `holder` property - * of the `presentation` or the `iss` property of the JWT payload respectively - * - */ - presentation: W3CVerifiablePresentation - - /** - * Optional (only for JWT) string challenge parameter to verify the verifiable presentation against - */ - challenge?: string - - /** - * Optional (only for JWT) string domain parameter to verify the verifiable presentation against - */ - domain?: string - - /** - * When dealing with JSON-LD you also MUST provide the proper contexts. - * Set this to `true` ONLY if you want the '@context' URLs to be fetched in case they are not preloaded. - * The context definitions SHOULD rather be provided at startup instead of being fetched. - * - * @default false - */ - fetchRemoteContexts?: boolean - - /** - * Overrides specific aspects of credential verification, where possible. - */ - policies?: VerificationPolicies - - /** - * Other options can be specified for verification. - * They will be forwarded to the lower level modules. that perform the checks - */ - [x: string]: any -} - -/** - * These optional settings can be used to override some default checks that are performed on Presentations during - * verification. - * - * @beta - */ -export interface VerificationPolicies { - /** - * policy to over the now (current time) during the verification check (UNIX time in seconds) - */ - now?: number - - /** - * policy to skip the issuanceDate (nbf) timestamp check when set to `false` - */ - issuanceDate?: boolean - - /** - * policy to skip the expirationDate (exp) timestamp check when set to `false` - */ - expirationDate?: boolean - - /** - * policy to skip the audience check when set to `false` - */ - audience?: boolean - - /** - * policy to skip the revocation check (credentialStatus) when set to `false` - */ - credentialStatus?: boolean - - /** - * Other options can be specified for verification. - * They will be forwarded to the lower level modules that perform the checks - */ - [x: string]: any -} - -/** - * Encapsulates the response object to verifyPresentation method after verifying a - * {@link https://www.w3.org/TR/vc-data-model/#presentations | W3C Verifiable Presentation} + * A Veramo plugin that implements the {@link @veramo/core#ICredentialPlugin | ICredentialPlugin} methods. * * @public */ - -/** - * 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 @veramo/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 @veramo/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 - - /** - * Verifies a Verifiable Credential JWT, LDS Format or EIP712. - * - * @param args - Arguments necessary to verify a VerifiableCredential - * @param context - This reserved param is automatically added and handled by the framework, *do not override* - * - * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error` - * for details - * - * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#credentials | Verifiable Credential data model} - */ - verifyCredential(args: IVerifyCredentialArgs, context: IContext): Promise - - /** - * Verifies a Verifiable Presentation JWT or LDS Format. - * - * @param args - Arguments necessary to verify a VerifiableCredential - * @param context - This reserved param is automatically added and handled by the framework, *do not override* - * - * @returns - a promise that resolves to an object containing a `verified` boolean property and an optional `error` - * for details - * - * @remarks Please see {@link https://www.w3.org/TR/vc-data-model/#presentations | Verifiable Credential data model} - */ - verifyPresentation(args: IVerifyPresentationArgs, 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< - IResolver & - Pick & - Pick & - Pick -> - -/** - * A Veramo plugin that implements the {@link ICredentialIssuer} methods. - * - * @public - */ -export class CredentialIssuer implements IAgentPlugin { - readonly methods: ICredentialIssuer - readonly schema = schema.ICredentialIssuer +export class CredentialPlugin implements IAgentPlugin { + readonly methods: ICredentialPlugin + readonly schema = schema.ICredentialPlugin constructor() { this.methods = { @@ -420,10 +67,10 @@ export class CredentialIssuer implements IAgentPlugin { } } - /** {@inheritdoc ICredentialIssuer.createVerifiablePresentation} */ + /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiablePresentation} */ async createVerifiablePresentation( args: ICreateVerifiablePresentationArgs, - context: IContext, + context: IssuerAgentContext, ): Promise { let { presentation, @@ -522,10 +169,10 @@ export class CredentialIssuer implements IAgentPlugin { return verifiablePresentation } - /** {@inheritdoc ICredentialIssuer.createVerifiableCredential} */ + /** {@inheritdoc @veramo/core#ICredentialIssuer.createVerifiableCredential} */ async createVerifiableCredential( args: ICreateVerifiableCredentialArgs, - context: IContext, + context: IssuerAgentContext, ): Promise { let { credential, proofFormat, keyRef, removeOriginalFields, save, now, ...otherOptions } = args const credentialContext = processEntryToArray(credential['@context'], MANDATORY_CREDENTIAL_CONTEXT) @@ -604,8 +251,8 @@ export class CredentialIssuer implements IAgentPlugin { } } - /** {@inheritdoc ICredentialIssuer.verifyCredential} */ - async verifyCredential(args: IVerifyCredentialArgs, context: IContext): Promise { + /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyCredential} */ + async verifyCredential(args: IVerifyCredentialArgs, context: VerifierAgentContext): Promise { let { credential, policies, ...otherOptions } = args let verifiedCredential: VerifiableCredential let verificationResult: IVerifyResult = { verified: false } @@ -683,7 +330,7 @@ export class CredentialIssuer implements IAgentPlugin { throw new Error('invalid_argument: Unknown credential type.') } - if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context))) { + if (policies?.credentialStatus !== false && (await isRevoked(verifiedCredential, context as any))) { verificationResult = { verified: false, error: { @@ -696,8 +343,11 @@ export class CredentialIssuer implements IAgentPlugin { return verificationResult } - /** {@inheritdoc ICredentialIssuer.verifyPresentation} */ - async verifyPresentation(args: IVerifyPresentationArgs, context: IContext): Promise { + /** {@inheritdoc @veramo/core#ICredentialVerifier.verifyPresentation} */ + async verifyPresentation( + args: IVerifyPresentationArgs, + context: VerifierAgentContext, + ): Promise { let { presentation, domain, challenge, fetchRemoteContexts, policies, ...otherOptions } = args const type: DocumentFormat = detectDocumentType(presentation) if (type === DocumentFormat.JWT) { @@ -736,7 +386,7 @@ export class CredentialIssuer implements IAgentPlugin { exp: policies?.exp ?? policies?.expirationDate, aud: policies?.aud ?? policies?.audience, }, - ...otherOptions + ...otherOptions, }) } catch (e: any) { let { message, errorCode } = e @@ -812,7 +462,10 @@ function detectDocumentType(document: W3CVerifiableCredential | W3CVerifiablePre return DocumentFormat.JSONLD } -async function isRevoked(credential: VerifiableCredential, context: IContext): Promise { +async function isRevoked( + credential: VerifiableCredential, + context: IAgentContext, +): Promise { if (!credential.credentialStatus) return false if (typeof context.agent.checkCredentialStatus === 'function') { diff --git a/packages/credential-w3c/src/index.ts b/packages/credential-w3c/src/index.ts index 48549bda0..729cca8e6 100644 --- a/packages/credential-w3c/src/index.ts +++ b/packages/credential-w3c/src/index.ts @@ -1,7 +1,7 @@ /** - * Provides a {@link @veramo/credential-w3c#CredentialIssuer | plugin} for the {@link @veramo/core#Agent} that + * Provides a {@link @veramo/credential-w3c#CredentialPlugin | plugin} for the {@link @veramo/core#Agent} that * implements - * {@link @veramo/credential-w3c#ICredentialIssuer} interface. + * {@link @veramo/core#ICredentialIssuer} interface. * * Provides a {@link @veramo/credential-w3c#W3cMessageHandler | plugin} for the * {@link @veramo/message-handler#MessageHandler} that verifies Credentials and Presentations in a message. @@ -9,17 +9,14 @@ * @packageDocumentation */ export { W3cMessageHandler, MessageTypes } from './message-handler' -export { - CredentialIssuer, - ICredentialIssuer, - ICreateVerifiableCredentialArgs, - ICreateVerifiablePresentationArgs, - ProofFormat, -} from './action-handler' +import { CredentialPlugin } from './action-handler' + /** - * The parameter and return type schemas for the methods of the {@link @veramo/credential-w3c#ICredentialIssuer} plugin. - * + * @deprecated please use {@link CredentialPlugin} instead * @public */ -const schema = require('../plugin.schema.json') -export { schema } +const CredentialIssuer = CredentialPlugin +export { CredentialIssuer, CredentialPlugin } + +// For backward compatibility, re-export the plugin types that were moved to core in v4 +export { ICredentialIssuer, ICredentialVerifier } from '@veramo/core' diff --git a/packages/credential-w3c/src/message-handler.ts b/packages/credential-w3c/src/message-handler.ts index 4d28176ab..b1554f2aa 100644 --- a/packages/credential-w3c/src/message-handler.ts +++ b/packages/credential-w3c/src/message-handler.ts @@ -1,4 +1,10 @@ -import { IAgentContext, IResolver, VerifiableCredential, VerifiablePresentation } from '@veramo/core' +import { + IAgentContext, + ICredentialVerifier, + IResolver, + VerifiableCredential, + VerifiablePresentation, +} from '@veramo/core' import { AbstractMessageHandler, Message } from '@veramo/message-handler' import { asArray, computeEntryHash, decodeCredentialToObject, extractIssuer } from '@veramo/utils' import { @@ -6,10 +12,7 @@ import { normalizePresentation, validateJwtCredentialPayload, validateJwtPresentationPayload, - VC_ERROR, } from 'did-jwt-vc' -import { JWT_ERROR } from 'did-jwt' -import { ICredentialIssuer } from './action-handler' import { v4 as uuidv4 } from 'uuid' import Debug from 'debug' @@ -33,7 +36,7 @@ export const MessageTypes = { * * This interface can be used for static type checks, to make sure your application is properly initialized. */ -export type IContext = IAgentContext +export type IContext = IAgentContext /** * An implementation of the {@link @veramo/message-handler#AbstractMessageHandler}. diff --git a/packages/data-store/src/index.ts b/packages/data-store/src/index.ts index 1f677e109..c8b65aece 100644 --- a/packages/data-store/src/index.ts +++ b/packages/data-store/src/index.ts @@ -57,3 +57,6 @@ export { PreMigrationKey, } export { migrations } from './migrations' + +// re-export the interfaces that were moved to core for backward compatibility +export { IDataStore, IDataStoreORM } from '@veramo/core' diff --git a/packages/key-manager/src/key-manager.ts b/packages/key-manager/src/key-manager.ts index 2a789510c..0d9837cd3 100644 --- a/packages/key-manager/src/key-manager.ts +++ b/packages/key-manager/src/key-manager.ts @@ -37,7 +37,7 @@ const debug = Debug('veramo:key-manager') * * The methods of this plugin are used automatically by other plugins, such as * {@link @veramo/did-manager#DIDManager | DIDManager}, - * {@link @veramo/credential-w3c#CredentialIssuer | CredentialIssuer}, or {@link @veramo/did-comm#DIDComm | DIDComm} to + * {@link @veramo/credential-w3c#CredentialPlugin | CredentialPlugin}, or {@link @veramo/did-comm#DIDComm | DIDComm} to * perform their required cryptographic operations using the managed keys. * * @public diff --git a/packages/kms-web3/src/web3-key-management-system.ts b/packages/kms-web3/src/web3-key-management-system.ts index d38ef2bf2..865ea2afa 100644 --- a/packages/kms-web3/src/web3-key-management-system.ts +++ b/packages/kms-web3/src/web3-key-management-system.ts @@ -11,8 +11,8 @@ import { toUtf8String } from '@ethersproject/strings' export class Web3KeyManagementSystem extends AbstractKeyManagementSystem { /** * - * @param providers - the key can be any unique name. Example { metamask: metamaskProvider, walletConnect: - * walletConnectProvider } + * @param providers - the key can be any unique name. + * Example `{ metamask: metamaskProvider, walletConnect: walletConnectProvider }` */ constructor(private providers: Record) { super() diff --git a/packages/selective-disclosure/src/action-handler.ts b/packages/selective-disclosure/src/action-handler.ts index 2295c3b96..100ad513b 100644 --- a/packages/selective-disclosure/src/action-handler.ts +++ b/packages/selective-disclosure/src/action-handler.ts @@ -8,7 +8,7 @@ import { TClaimsColumns, VerifiablePresentation, } from '@veramo/core' -import { ICredentialIssuer } from '@veramo/credential-w3c' +import { ICredentialIssuer } from '@veramo/core' import { ICreateProfileCredentialsArgs, ICreateSelectiveDisclosureRequestArgs, diff --git a/packages/selective-disclosure/src/types.ts b/packages/selective-disclosure/src/types.ts index 2d9af7e53..9bec54dec 100644 --- a/packages/selective-disclosure/src/types.ts +++ b/packages/selective-disclosure/src/types.ts @@ -7,7 +7,7 @@ import { UniqueVerifiableCredential, VerifiablePresentation, } from '@veramo/core' -import { ICredentialIssuer } from '@veramo/credential-w3c' +import { ICredentialIssuer } from '@veramo/core' /** * Used for requesting Credentials using Selective Disclosure. diff --git a/packages/test-react-app/src/veramo/setup.ts b/packages/test-react-app/src/veramo/setup.ts index 9295a80c7..3c321d8b6 100644 --- a/packages/test-react-app/src/veramo/setup.ts +++ b/packages/test-react-app/src/veramo/setup.ts @@ -1,13 +1,14 @@ import { createAgent, IAgentOptions, + ICredentialPlugin, IDataStore, IDataStoreORM, IDIDManager, IKeyManager, IMessageHandler, IResolver, - TAgent + TAgent, } from '@veramo/core' import { DIDResolverPlugin } from '@veramo/did-resolver' @@ -18,13 +19,13 @@ import { MessageHandler } from '@veramo/message-handler' import { KeyManager } from '@veramo/key-manager' import { DIDManager } from '@veramo/did-manager' import { JwtMessageHandler } from '@veramo/did-jwt' -import { CredentialIssuer, ICredentialIssuer, W3cMessageHandler } from '@veramo/credential-w3c' +import { CredentialPlugin, W3cMessageHandler } from '@veramo/credential-w3c' import { CredentialIssuerLD, ICredentialIssuerLD, LdDefaultContexts, VeramoEcdsaSecp256k1RecoverySignature2020, - VeramoEd25519Signature2018 + VeramoEd25519Signature2018, } from '@veramo/credential-ld' import { getDidKeyResolver, KeyDIDProvider } from '@veramo/did-provider-key' import { DIDComm, DIDCommMessageHandler, IDIDComm } from '@veramo/did-comm' @@ -33,30 +34,28 @@ import { KeyManagementSystem, SecretBox } from '@veramo/kms-local' import { Web3KeyManagementSystem } from '@veramo/kms-web3' import { EthrDIDProvider } from '@veramo/did-provider-ethr' import { WebDIDProvider } from '@veramo/did-provider-web' -import { DataStoreJson, DIDStoreJson, KeyStoreJson, PrivateKeyStoreJson } from "@veramo/data-store-json"; -import { FakeDidProvider, FakeDidResolver } from "@veramo/test-utils"; +import { DataStoreJson, DIDStoreJson, KeyStoreJson, PrivateKeyStoreJson } from '@veramo/data-store-json' +import { FakeDidProvider, FakeDidResolver } from '@veramo/test-utils' const INFURA_PROJECT_ID = '33aab9e0334c44b0a2e0c57c15302608' const DB_SECRET_KEY = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa83' const memoryJsonStore = { - notifyUpdate: () => Promise.resolve() + notifyUpdate: () => Promise.resolve(), } -type InstalledPlugins = - IResolver - & IKeyManager - & IDIDManager - & ICredentialIssuer - & ICredentialIssuerLD - & IDataStoreORM - & IDataStore - & IMessageHandler - & ISelectiveDisclosure - & IDIDComm +type InstalledPlugins = IResolver & + IKeyManager & + IDIDManager & + ICredentialPlugin & + ICredentialIssuerLD & + IDataStoreORM & + IDataStore & + IMessageHandler & + ISelectiveDisclosure & + IDIDComm export function getAgent(options?: IAgentOptions): TAgent { - const agent: TAgent = createAgent({ ...options, plugins: [ @@ -71,8 +70,10 @@ export function getAgent(options?: IAgentOptions): TAgent { new KeyManager({ store: new KeyStoreJson(memoryJsonStore), kms: { - local: new KeyManagementSystem(new PrivateKeyStoreJson(memoryJsonStore, new SecretBox(DB_SECRET_KEY))), - web3: new Web3KeyManagementSystem({}) + local: new KeyManagementSystem( + new PrivateKeyStoreJson(memoryJsonStore, new SecretBox(DB_SECRET_KEY)), + ), + web3: new Web3KeyManagementSystem({}), }, }), new DIDManager({ @@ -118,13 +119,10 @@ export function getAgent(options?: IAgentOptions): TAgent { ], }), new DIDComm(), - new CredentialIssuer(), + new CredentialPlugin(), new CredentialIssuerLD({ contextMaps: [LdDefaultContexts], - suites: [ - new VeramoEcdsaSecp256k1RecoverySignature2020(), - new VeramoEd25519Signature2018() - ], + suites: [new VeramoEcdsaSecp256k1RecoverySignature2020(), new VeramoEd25519Signature2018()], }), new SelectiveDisclosure(), ...(options?.plugins || []), diff --git a/scripts/prepare-integration-tests.ts b/scripts/prepare-integration-tests.ts index 44e8ad7f8..68fce7ea6 100644 --- a/scripts/prepare-integration-tests.ts +++ b/scripts/prepare-integration-tests.ts @@ -38,8 +38,17 @@ for (const inputFolder of inputFolders) { const apiJsonFilePath = './temp/.api.json' const agentPlugins: Record> = { - core: ['IResolver', 'IDIDManager', 'IMessageHandler', 'IDataStore', 'IDataStoreORM', 'IKeyManager'], - 'credential-w3c': ['ICredentialIssuer'], + core: [ + 'IResolver', + 'IDIDManager', + 'IMessageHandler', + 'IDataStore', + 'IDataStoreORM', + 'IKeyManager', + 'ICredentialIssuer', + 'ICredentialVerifier', + 'ICredentialPlugin', + ], 'selective-disclosure': ['ISelectiveDisclosure'], 'did-comm': ['IDIDComm'], } @@ -61,7 +70,7 @@ for (const packageName of Object.keys(agentPlugins)) { path: resolve('packages/' + packageName + '/src/index.ts'), encodeRefs: false, // TODO: https://github.com/transmute-industries/vc.js/issues/60 - skipTypeCheck: true + skipTypeCheck: true, }) const apiModel: ApiModel = new ApiModel() @@ -92,7 +101,8 @@ for (const packageName of Object.keys(agentPlugins)) { //@ts-ignore ?.getChildNodes()[0]?.text - method.example = (methodSignature.tsdocComment?.customBlocks[0]?.content?.getChildNodes()[1] as unknown) as DocFencedCode + method.example = + methodSignature.tsdocComment?.customBlocks[0]?.content?.getChildNodes()[1] as unknown as DocFencedCode method.description = method.description || ''