Skip to content

Commit

Permalink
feat(credential-w3c): add ICredentialPlugin interface in core package (
Browse files Browse the repository at this point in the history
…#1001)

closes #941

The `ICredentialIssuer` interface was moved to the core package, but is reexported by the `credential-w3c` package for compatibility.
  • Loading branch information
mirceanis authored Sep 8, 2022
1 parent b987fc0 commit 7b6d195
Show file tree
Hide file tree
Showing 43 changed files with 1,403 additions and 1,085 deletions.
9 changes: 5 additions & 4 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import {
createAgent,
IAgentOptions,
ICredentialPlugin,
IDataStore,
IDataStoreORM,
IDIDManager,
Expand All @@ -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,
Expand Down Expand Up @@ -97,7 +98,7 @@ let agent: TAgent<
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure &
Expand Down Expand Up @@ -133,7 +134,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure &
Expand Down Expand Up @@ -219,7 +220,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm([new DIDCommHttpTransport()]),
new CredentialIssuer(),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
Expand Down
22 changes: 16 additions & 6 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
createAgent,
IAgentOptions,
ICredentialPlugin,
IDataStore,
IDataStoreORM,
IDIDManager,
Expand All @@ -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,
Expand All @@ -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'
Expand Down Expand Up @@ -76,7 +86,7 @@ let agent: TAgent<
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
Expand All @@ -100,7 +110,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
Expand Down Expand Up @@ -168,7 +178,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm(),
new CredentialIssuer(),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
Expand Down
9 changes: 5 additions & 4 deletions __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import {
createAgent,
IAgentOptions,
ICredentialPlugin,
IDataStore,
IDataStoreORM,
IDIDManager,
Expand All @@ -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,
Expand Down Expand Up @@ -79,7 +80,7 @@ let agent: TAgent<
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
Expand Down Expand Up @@ -107,7 +108,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
Expand Down Expand Up @@ -176,7 +177,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm(),
new CredentialIssuer(),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
Expand Down
11 changes: 9 additions & 2 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -109,7 +114,8 @@ const getAgent = (options?: IAgentOptions) =>
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer &
ICredentialIssuer & // import from old package to check compatibility
ICredentialVerifier &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure &
Expand Down Expand Up @@ -200,6 +206,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm([new DIDCommHttpTransport()]),
// intentionally use the deprecated name to test compatibility
new CredentialIssuer(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
Expand Down
4 changes: 2 additions & 2 deletions __tests__/shared/credentialStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { CredentialStatus } from 'credential-status'
import {
CredentialPayload,
IAgentOptions,
ICredentialPlugin,
IDataStore,
IDataStoreORM,
IDIDManager,
IIdentifier,
TAgent,
} from '../../packages/core/src'
import { CredentialStatusPlugin } from '../../packages/credential-status/src'
import { ICredentialIssuer } from '../../packages/credential-w3c/src'

type ConfiguredAgent = TAgent<IDIDManager & ICredentialIssuer & IDataStore & IDataStoreORM>
type ConfiguredAgent = TAgent<IDIDManager & ICredentialPlugin & IDataStore & IDataStoreORM>

// Constant used to simulate exception flows
const simulateStatusVerificationFailure = 'Any unexpected failure during status verification.'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/shared/dbInitOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import {
IAgentOptions,
ICredentialIssuer,
IDataStore,
IDataStoreORM,
IDIDManager,
Expand All @@ -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'

Expand Down
52 changes: 24 additions & 28 deletions __tests__/shared/didCommWithEthrDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,17 @@ 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',
},
})
expect(result.substr(0, 2)).toEqual('0x')

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 () => {
Expand All @@ -167,24 +167,23 @@ 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',
},
})
expect(result.substr(0, 2)).toEqual('0x')

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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 () => {
Expand Down Expand Up @@ -404,7 +402,6 @@ export default (testContext: {
)
})


it('should remove DIDComm service from receiver', async () => {
const result = await agent.didManagerRemoveService({
did: alice.did,
Expand All @@ -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,
Expand All @@ -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 () => {
Expand Down Expand Up @@ -482,7 +479,6 @@ export default (testContext: {
)
})


it('should remove DIDComm service from receiver', async () => {
const result = await agent.didManagerRemoveService({
did: alice.did,
Expand All @@ -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,
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions __tests__/shared/didDiscovery.ts
Original file line number Diff line number Diff line change
@@ -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<IDIDManager & IDIDDiscovery & IDataStoreORM & ICredentialIssuer>

Expand Down
Loading

0 comments on commit 7b6d195

Please sign in to comment.