Skip to content

Commit

Permalink
feat(credential-w3c): remove hardcoded proof formats (#1395)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The credential plugins specializing in JSON-LD / EIP712 are no longer top level veramo plugins but are now managed by the `@veramo/credential-w3c` plugin which will be able to use multiple proof formats and multiplex accordingly. The constructor for the `CredentialPlugin` has changed to accept different implementations of proof formats.
  • Loading branch information
nickreynolds authored Jul 11, 2024
1 parent 034afc4 commit 5b7d3fa
Show file tree
Hide file tree
Showing 54 changed files with 1,821 additions and 2,492 deletions.
69 changes: 33 additions & 36 deletions __tests__/localAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { AliasDiscoveryProvider, DIDManager } from '../packages/did-manager/src'
import { DIDResolverPlugin } from '../packages/did-resolver/src'
import { JwtMessageHandler } from '../packages/did-jwt/src'
import { CredentialPlugin, W3cMessageHandler } from '../packages/credential-w3c/src'
import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderJWT } from '../packages/credential-jwt/src'
import {
CredentialIssuerLD,
ICredentialIssuerLD,
CredentialProviderLD,
LdDefaultContexts,
VeramoEcdsaSecp256k1RecoverySignature2020,
VeramoEd25519Signature2018,
Expand Down Expand Up @@ -102,17 +102,15 @@ const secretKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa8

let agent: TAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure &
IDIDDiscovery
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ISelectiveDisclosure &
IDIDDiscovery
>
let dbConnection: Promise<DataSource>
let databaseFile: string
Expand All @@ -135,19 +133,28 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
const { provider, registry } = await createGanacheProvider()
const ethersProvider = createEthersProvider()

const eip712 = new CredentialProviderEIP712()
const jwt = new CredentialProviderJWT()
const ld = new CredentialProviderLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
],
})
agent = createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure &
IDIDDiscovery
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ISelectiveDisclosure &
IDIDDiscovery
>({
...options,
context: {
Expand Down Expand Up @@ -243,17 +250,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm({ transports: [new DIDCommHttpTransport()] }),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
],
}),
new CredentialPlugin({ issuers: [eip712, jwt, ld] }),
new SelectiveDisclosure(),
new DIDDiscovery({
providers: [
Expand Down
70 changes: 37 additions & 33 deletions __tests__/localJsonStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import { DIDManager } from '../packages/did-manager/src'
import { DIDResolverPlugin } from '../packages/did-resolver/src'
import { JwtMessageHandler } from '../packages/did-jwt/src'
import { CredentialPlugin, W3cMessageHandler } from '../packages/credential-w3c/src'
import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderJWT } from '../packages/credential-jwt/src'
import {
CredentialIssuerLD,
ICredentialIssuerLD,
CredentialProviderLD,
LdDefaultContexts,
VeramoEcdsaSecp256k1RecoverySignature2020,
VeramoEd25519Signature2018,
Expand Down Expand Up @@ -88,16 +88,14 @@ const secretKey = '29739248cad1bd1a0fc4d9b75cd4d2990de535baf5caadfdf8d8f86664aa8

let agent: TAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ISelectiveDisclosure
>

let databaseFile: string
Expand All @@ -108,20 +106,22 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
// and `DataStoreJson` if you want to use all the query capabilities of `DataStoreJson`
databaseFile = options?.context?.databaseFile || `./tmp/local-database-${Math.random().toPrecision(5)}.json`


// manually create the tmp directory
await fs.promises.mkdir('./tmp', { recursive: true })

const jsonFileStore = await JsonFileStore.fromFile(databaseFile)

agent = createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ISelectiveDisclosure
>({
...options,
context: {
Expand Down Expand Up @@ -199,16 +199,20 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm(),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoEd25519Signature2020(),
new VeramoJsonWebSignature2020(),
],
new CredentialPlugin({
issuers: [
new CredentialProviderEIP712(),
new CredentialProviderJWT(),
new CredentialProviderLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
],
})
]
}),
new SelectiveDisclosure(),
...(options?.plugins || []),
Expand Down
66 changes: 32 additions & 34 deletions __tests__/localMemoryStoreAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { DataSource } from 'typeorm'
import { DIDResolverPlugin } from '../packages/did-resolver/src'
import { JwtMessageHandler } from '../packages/did-jwt/src'
import { CredentialPlugin, W3cMessageHandler } from '../packages/credential-w3c/src'
import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderJWT } from '../packages/credential-jwt/src'
import {
CredentialIssuerLD,
ICredentialIssuerLD,
CredentialProviderLD,
LdDefaultContexts,
VeramoEcdsaSecp256k1RecoverySignature2020,
VeramoEd25519Signature2018,
Expand Down Expand Up @@ -80,16 +80,14 @@ const infuraProjectId = '3586660d179141e3801c3895de1c2eba'

let agent: TAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ISelectiveDisclosure
>
let dbConnection: DataSource

Expand All @@ -106,18 +104,28 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
entities: Entities,
})

const eip712 = new CredentialProviderEIP712()
const jwt = new CredentialProviderJWT()
const ld = new CredentialProviderLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
],
})

agent = createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialPlugin &
ISelectiveDisclosure
>({
...options,
context: {
Expand Down Expand Up @@ -194,17 +202,7 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
],
}),
new DIDComm(),
new CredentialPlugin(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
],
}),
new CredentialPlugin({ issuers: [eip712, jwt, ld] }),
new SelectiveDisclosure(),
...(options?.plugins || []),
],
Expand Down
58 changes: 34 additions & 24 deletions __tests__/restAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import {
ICredentialVerifier,
W3cMessageHandler,
} from '../packages/credential-w3c/src'
import { CredentialIssuerEIP712, ICredentialIssuerEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderEIP712 } from '../packages/credential-eip712/src'
import { CredentialProviderJWT } from '../packages/credential-jwt/src'
import {
CredentialIssuerLD,
ICredentialIssuerLD,
CredentialProviderLD,
LdDefaultContexts,
VeramoEcdsaSecp256k1RecoverySignature2020,
VeramoEd25519Signature2018,
Expand Down Expand Up @@ -112,21 +112,21 @@ let dbConnection: Promise<DataSource>
let serverAgent: IAgent
let restServer: Server



const getAgent = (options?: IAgentOptions) =>
createAgent<
IDIDManager &
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer & // import from old package to check compatibility
ICredentialVerifier &
ICredentialIssuerLD &
ICredentialIssuerEIP712 &
ISelectiveDisclosure &
IDIDDiscovery
IKeyManager &
IDataStore &
IDataStoreORM &
IResolver &
IMessageHandler &
IDIDComm &
ICredentialIssuer & // import from old package to check compatibility
ICredentialVerifier &
ISelectiveDisclosure &
IDIDDiscovery
>({
...options,
plugins: [
Expand All @@ -150,6 +150,18 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
entities: Entities,
}).initialize()

const eip712 = new CredentialProviderEIP712()
const jwt = new CredentialProviderJWT()
const ld = new CredentialProviderLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
],
})

serverAgent = new Agent({
...options,
plugins: [
Expand Down Expand Up @@ -227,15 +239,13 @@ const setup = async (options?: IAgentOptions): Promise<boolean> => {
}),
new DIDComm({ transports: [new DIDCommHttpTransport()] }),
// intentionally use the deprecated name to test compatibility
new CredentialIssuer(),
new CredentialIssuerEIP712(),
new CredentialIssuerLD({
contextMaps: [LdDefaultContexts, credential_contexts as any],
suites: [
new VeramoEcdsaSecp256k1RecoverySignature2020(),
new VeramoEd25519Signature2018(),
new VeramoJsonWebSignature2020(),
new VeramoEd25519Signature2020(),
new CredentialIssuer({ issuers: [eip712, jwt, ld] }),
new SelectiveDisclosure(),
new DIDDiscovery({
providers: [
new AliasDiscoveryProvider(),
new DataStoreDiscoveryProvider(),
new BrokenDiscoveryProvider(),
],
}),
new SelectiveDisclosure(),
Expand Down
2 changes: 1 addition & 1 deletion __tests__/shared/credentialPluginTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default (testContext: {
})

const options = await agent.listUsableProofFormats(iid)
expect(options).toEqual(['jwt', 'lds', 'EthereumEip712Signature2021'])
expect(options).toEqual(['EthereumEip712Signature2021', 'jwt', 'lds'])
})

it('should list signing options for did:key with X25519 key', async () => {
Expand Down
Loading

0 comments on commit 5b7d3fa

Please sign in to comment.