@sphereon/ssi-sdk.credential-vcdm-jsonld-provider 0.33.1-feature.jose.vcdm.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +287 -0
- package/dist/index.cjs +3147 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +222 -0
- package/dist/index.d.ts +222 -0
- package/dist/index.js +3117 -0
- package/dist/index.js.map +1 -0
- package/package.json +122 -0
- package/plugin.schema.json +12425 -0
- package/src/__tests__/context.loader.test.ts +41 -0
- package/src/__tests__/diwala.test.ts +129 -0
- package/src/__tests__/fixtures/diwala.ts +43 -0
- package/src/__tests__/issue-verify-flow-statuslist.test.ts +94 -0
- package/src/__tests__/issue-verify-flow-vcdm2.test.ts +268 -0
- package/src/__tests__/issue-verify-flow.test.ts +306 -0
- package/src/__tests__/localAgent.test.ts +36 -0
- package/src/__tests__/mocks.ts +473 -0
- package/src/__tests__/restAgent.test.ts +58 -0
- package/src/__tests__/shared/vcHandlerLocalAgentLogic.ts +160 -0
- package/src/agent/CredentialProviderJsonld.ts +281 -0
- package/src/agent/index.ts +1 -0
- package/src/contexts/X25519KeyAgreementKey2019.json +26 -0
- package/src/contexts/bbs-bls-signature-2020-v1.json +129 -0
- package/src/contexts/citizenship-v1.json +54 -0
- package/src/contexts/did_v0.11.json +64 -0
- package/src/contexts/ed25519-signature-2018-v1.json +91 -0
- package/src/contexts/ed25519-signature-2020-v1.json +77 -0
- package/src/contexts/eip712.json +93 -0
- package/src/contexts/json-web-signature-2020-v1.json +71 -0
- package/src/contexts/kyc-v1.json +8 -0
- package/src/contexts/lds-ecdsa-secp256k1-recovery2020-0.0.json +21 -0
- package/src/contexts/odrl.json +199 -0
- package/src/contexts/profile-v1.json +8 -0
- package/src/contexts/socialmedia-v1.json +7 -0
- package/src/contexts/transmute_v1.json +21 -0
- package/src/contexts/vc-revocation-list-2020-v1.json +46 -0
- package/src/contexts/vc-status-list-2021-v1.json +48 -0
- package/src/contexts/veramo.io_contexts_profile_v1.json +8 -0
- package/src/contexts/w3id.org_security_suites_ed25519-2018_v1.json +63 -0
- package/src/contexts/w3id.org_security_suites_secp256k1recovery-2020_v2.json +87 -0
- package/src/contexts/w3id.org_security_suites_x25519-2019_v1.json +26 -0
- package/src/contexts/w3id.org_security_v1.json +50 -0
- package/src/contexts/w3id.org_security_v2.json +63 -0
- package/src/contexts/w3id.org_security_v3-unstable.json +722 -0
- package/src/contexts/www.w3.org_2018_credentials_v1.json +237 -0
- package/src/contexts/www.w3.org_ns_credentials_v2.json +331 -0
- package/src/contexts/www.w3.org_ns_did_v1.json +58 -0
- package/src/enums.ts +28 -0
- package/src/index.ts +12 -0
- package/src/ld-context-loader.ts +32 -0
- package/src/ld-credential-module.ts +281 -0
- package/src/ld-default-contexts.ts +49 -0
- package/src/ld-document-loader.ts +156 -0
- package/src/ld-suite-loader.ts +83 -0
- package/src/ld-suites.ts +41 -0
- package/src/modules.d.ts +13 -0
- package/src/suites/EcdsaSecp256k1RecoverySignature2020.ts +100 -0
- package/src/suites/Ed25519Signature2018.ts +109 -0
- package/src/suites/Ed25519Signature2020.ts +93 -0
- package/src/suites/index.ts +3 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { ContextDoc } from '@veramo/credential-ld'
|
|
3
|
+
|
|
4
|
+
import { LdContextLoader } from '../ld-context-loader'
|
|
5
|
+
import { LdDefaultContexts } from '../ld-default-contexts'
|
|
6
|
+
|
|
7
|
+
describe('credential-ld context loader', () => {
|
|
8
|
+
const customContext: Record<string, ContextDoc> = {
|
|
9
|
+
'https://example.com/custom/context': {
|
|
10
|
+
'@context': {
|
|
11
|
+
'@version': 1.1,
|
|
12
|
+
id: '@id',
|
|
13
|
+
type: '@type',
|
|
14
|
+
nothing: 'https://example.com/nothing',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
it('should load custom context from record', async () => {
|
|
20
|
+
expect.assertions(2)
|
|
21
|
+
const loader = new LdContextLoader({ contextsPaths: [customContext] })
|
|
22
|
+
expect(loader.has('https://example.com/custom/context')).toBe(true)
|
|
23
|
+
await expect(loader.get('https://example.com/custom/context')).resolves.toEqual({
|
|
24
|
+
'@context': {
|
|
25
|
+
'@version': 1.1,
|
|
26
|
+
id: '@id',
|
|
27
|
+
type: '@type',
|
|
28
|
+
nothing: 'https://example.com/nothing',
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should load context from default map', async () => {
|
|
34
|
+
expect.assertions(2)
|
|
35
|
+
const loader = new LdContextLoader({ contextsPaths: [LdDefaultContexts] })
|
|
36
|
+
expect(loader.has('https://www.w3.org/2018/credentials/v1')).toBe(true)
|
|
37
|
+
|
|
38
|
+
const credsContext = await loader.get('https://www.w3.org/2018/credentials/v1')
|
|
39
|
+
expect(credsContext['@context']).toBeDefined()
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, it } from 'vitest'
|
|
2
|
+
import { createAgent, IDIDManager, IKeyManager, IResolver, TAgent, W3CVerifiableCredential } from '@veramo/core'
|
|
3
|
+
import { DIDManager, MemoryDIDStore } from '@veramo/did-manager'
|
|
4
|
+
import { getDidKeyResolver, SphereonKeyDidProvider } from '@sphereon/ssi-sdk-ext.did-provider-key'
|
|
5
|
+
import { DIDResolverPlugin } from '@veramo/did-resolver'
|
|
6
|
+
import { MemoryKeyStore, MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
7
|
+
import { Resolver } from 'did-resolver'
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import nock from 'nock'
|
|
10
|
+
import { CredentialProviderJsonld } from '../agent'
|
|
11
|
+
import { LdDefaultContexts } from '../ld-default-contexts'
|
|
12
|
+
import { SphereonEd25519Signature2018, SphereonEd25519Signature2020 } from '../suites'
|
|
13
|
+
import { diwalaVC } from './fixtures/diwala'
|
|
14
|
+
import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local'
|
|
15
|
+
import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
|
|
16
|
+
import { IVcdmCredentialPlugin, VcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm'
|
|
17
|
+
|
|
18
|
+
//jest.setTimeout(100000)
|
|
19
|
+
|
|
20
|
+
describe('Diwala issued VC', () => {
|
|
21
|
+
let agent: TAgent<IResolver & IKeyManager & IDIDManager & IVcdmCredentialPlugin>
|
|
22
|
+
|
|
23
|
+
const jsonld = new CredentialProviderJsonld({
|
|
24
|
+
contextMaps: [LdDefaultContexts],
|
|
25
|
+
suites: [new SphereonEd25519Signature2018(), new SphereonEd25519Signature2020()],
|
|
26
|
+
})
|
|
27
|
+
// //jest.setTimeout(1000000)
|
|
28
|
+
beforeAll(async () => {
|
|
29
|
+
agent = createAgent({
|
|
30
|
+
plugins: [
|
|
31
|
+
new SphereonKeyManager({
|
|
32
|
+
store: new MemoryKeyStore(),
|
|
33
|
+
kms: {
|
|
34
|
+
local: new SphereonKeyManagementSystem(new MemoryPrivateKeyStore()),
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
new DIDManager({
|
|
38
|
+
providers: {
|
|
39
|
+
'did:key': new SphereonKeyDidProvider({ defaultKms: 'local' }),
|
|
40
|
+
},
|
|
41
|
+
store: new MemoryDIDStore(),
|
|
42
|
+
defaultProvider: 'did:key',
|
|
43
|
+
}),
|
|
44
|
+
new DIDResolverPlugin({
|
|
45
|
+
resolver: new Resolver({
|
|
46
|
+
...getDidKeyResolver(),
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
new VcdmCredentialPlugin({ issuers: [jsonld] }),
|
|
50
|
+
],
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should be verified with Ed25519Signature2018', async () => {
|
|
55
|
+
const verifiableCredential: W3CVerifiableCredential = diwalaVC
|
|
56
|
+
expect(verifiableCredential).toBeDefined()
|
|
57
|
+
// console.log(verifiableCredential)
|
|
58
|
+
|
|
59
|
+
const verifiedCredential = await agent.verifyCredential({
|
|
60
|
+
credential: verifiableCredential,
|
|
61
|
+
fetchRemoteContexts: true,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
expect(verifiedCredential).toMatchObject({
|
|
65
|
+
log: [
|
|
66
|
+
{
|
|
67
|
+
id: 'valid_signature',
|
|
68
|
+
valid: true,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'issuer_did_resolves',
|
|
72
|
+
valid: true,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'expiration',
|
|
76
|
+
valid: true,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
results: [
|
|
80
|
+
{
|
|
81
|
+
log: [
|
|
82
|
+
{
|
|
83
|
+
id: 'valid_signature',
|
|
84
|
+
valid: true,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'issuer_did_resolves',
|
|
88
|
+
valid: true,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: 'expiration',
|
|
92
|
+
valid: true,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
proof: {
|
|
96
|
+
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://purl.imsglobal.org/spec/ob/v3p0/context.json'],
|
|
97
|
+
created: '2023-05-06T00:57:07Z',
|
|
98
|
+
jws: 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..d3MzWbyiG-gWH4LV15waD7UXXDC9-qKqJpx1g7tOeSrw7TdDeIrzzP9xr-e93ppWN0oYflp1xBxHZaUU2b2SCQ',
|
|
99
|
+
proofPurpose: 'assertionMethod',
|
|
100
|
+
type: 'Ed25519Signature2018',
|
|
101
|
+
verificationMethod: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
102
|
+
},
|
|
103
|
+
purposeResult: {
|
|
104
|
+
controller: {
|
|
105
|
+
assertionMethod: ['did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9'],
|
|
106
|
+
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
107
|
+
verificationMethod: [
|
|
108
|
+
{
|
|
109
|
+
controller: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
110
|
+
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
111
|
+
type: 'Ed25519VerificationKey2020',
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
valid: true,
|
|
116
|
+
},
|
|
117
|
+
verificationMethod: {
|
|
118
|
+
controller: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
119
|
+
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
120
|
+
// publicKeyBase58: 'DYGA3LbwgD66VokM9CQsB3XwrPNzoyX79P19mpPjTp4m',
|
|
121
|
+
type: 'Ed25519VerificationKey2020',
|
|
122
|
+
},
|
|
123
|
+
verified: true,
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
verified: true,
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const diwalaVC = {
|
|
2
|
+
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://purl.imsglobal.org/spec/ob/v3p0/context.json'],
|
|
3
|
+
id: 'urn:uuid:04331fea-f92b-4fb5-9e04-838c9b39d154',
|
|
4
|
+
type: ['VerifiableCredential', 'OpenBadgeCredential'],
|
|
5
|
+
name: 'JFF x vc-edu PlugFest 2 Interoperability',
|
|
6
|
+
issuer: {
|
|
7
|
+
type: ['Profile'],
|
|
8
|
+
id: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
9
|
+
name: 'Jobs for the Future (JFF)',
|
|
10
|
+
url: 'https://www.jff.org/',
|
|
11
|
+
image: {
|
|
12
|
+
id: 'https://w3c-ccg.github.io/vc-ed/plugfest-1-2022/images/JFF_LogoLockup.png',
|
|
13
|
+
type: 'Image',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
issuanceDate: '2023-05-06T00:57:07Z',
|
|
17
|
+
credentialSubject: {
|
|
18
|
+
type: ['AchievementSubject'],
|
|
19
|
+
id: 'did:key:z6MkrwRmStZZMf4mEkot8VnjtDX6VSfWyHeCj9nceCV3HyE9',
|
|
20
|
+
achievement: {
|
|
21
|
+
id: 'urn:uuid:94cc8fcf-b1be-481e-9105-682c37a307af',
|
|
22
|
+
type: ['Achievement'],
|
|
23
|
+
name: 'Diwala issued JFF x vc-edu PlugFest 2 Interoperability',
|
|
24
|
+
description:
|
|
25
|
+
'This credential solution supports the use of OBv3 and w3c Verifiable Credentials and is interoperable with at least two other solutions. This was demonstrated successfully during JFF x vc-edu PlugFest 2.',
|
|
26
|
+
criteria: {
|
|
27
|
+
narrative:
|
|
28
|
+
'Solutions providers earned this badge by demonstrating interoperability between multiple providers based on the OBv3 candidate final standard, with some additional required fields. Credential issuers earning this badge successfully issued a credential into at least two wallets. Wallet implementers earning this badge successfully displayed credentials issued by at least two different credential issuers.',
|
|
29
|
+
},
|
|
30
|
+
image: {
|
|
31
|
+
id: 'https://w3c-ccg.github.io/vc-ed/plugfest-2-2022/images/JFF-VC-EDU-PLUGFEST2-badge-image.png',
|
|
32
|
+
type: 'Image',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
proof: {
|
|
37
|
+
type: 'Ed25519Signature2018',
|
|
38
|
+
created: '2023-05-06T00:57:07Z',
|
|
39
|
+
verificationMethod: 'did:key:z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9#z6MkrzXCdarP1kaZcJb3pmNi295wfxerDrmTqPv5c6MkP2r9',
|
|
40
|
+
proofPurpose: 'assertionMethod',
|
|
41
|
+
jws: 'eyJhbGciOiJFZERTQSIsImI2NCI6ZmFsc2UsImNyaXQiOlsiYjY0Il19..d3MzWbyiG-gWH4LV15waD7UXXDC9-qKqJpx1g7tOeSrw7TdDeIrzzP9xr-e93ppWN0oYflp1xBxHZaUU2b2SCQ',
|
|
42
|
+
},
|
|
43
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, it, beforeAll } from 'vitest'
|
|
2
|
+
import { IdentifierResolution, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
3
|
+
import { createNewStatusList } from '@sphereon/ssi-sdk.vc-status-list'
|
|
4
|
+
import { StatusListType } from '@sphereon/ssi-types'
|
|
5
|
+
import { createAgent, IDIDManager, IIdentifier, IKeyManager, IResolver, TAgent } from '@veramo/core'
|
|
6
|
+
import { DIDManager, MemoryDIDStore } from '@veramo/did-manager'
|
|
7
|
+
import { getDidKeyResolver, SphereonKeyDidProvider } from '@sphereon/ssi-sdk-ext.did-provider-key'
|
|
8
|
+
import { DIDResolverPlugin } from '@veramo/did-resolver'
|
|
9
|
+
import { MemoryKeyStore, MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
10
|
+
import { Resolver } from 'did-resolver'
|
|
11
|
+
import { CredentialProviderJsonld } from '../agent'
|
|
12
|
+
import { LdDefaultContexts } from '../ld-default-contexts'
|
|
13
|
+
import { SphereonEd25519Signature2018, SphereonEd25519Signature2020 } from '../suites'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
import { bedrijfsInformatieV1, exampleV1 } from './mocks'
|
|
17
|
+
import { ContextDoc, IVcdmCredentialPlugin, VcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm'
|
|
18
|
+
import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
|
|
19
|
+
import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local'
|
|
20
|
+
|
|
21
|
+
//jest.setTimeout(100000)
|
|
22
|
+
|
|
23
|
+
const customContext = new Map<string, ContextDoc>([
|
|
24
|
+
[`https://www.w3.org/2018/credentials/examples/v1`, exampleV1],
|
|
25
|
+
['https://sphereon-opensource.github.io/vc-contexts/myc/bedrijfsinformatie-v1.jsonld', bedrijfsInformatieV1],
|
|
26
|
+
])
|
|
27
|
+
|
|
28
|
+
describe('credential-LD full flow', () => {
|
|
29
|
+
let didKeyIdentifier: IIdentifier
|
|
30
|
+
let agent: TAgent<IResolver & IKeyManager & IDIDManager & IVcdmCredentialPlugin & IIdentifierResolution>
|
|
31
|
+
|
|
32
|
+
const jsonld = new CredentialProviderJsonld({
|
|
33
|
+
contextMaps: [LdDefaultContexts, customContext],
|
|
34
|
+
suites: [new SphereonEd25519Signature2018(), new SphereonEd25519Signature2020()],
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
beforeAll(async () => {
|
|
38
|
+
agent = createAgent({
|
|
39
|
+
plugins: [
|
|
40
|
+
new SphereonKeyManager({
|
|
41
|
+
store: new MemoryKeyStore(),
|
|
42
|
+
kms: {
|
|
43
|
+
local: new SphereonKeyManagementSystem(new MemoryPrivateKeyStore()),
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
new DIDManager({
|
|
47
|
+
providers: {
|
|
48
|
+
'did:key': new SphereonKeyDidProvider({ defaultKms: 'local' }),
|
|
49
|
+
},
|
|
50
|
+
store: new MemoryDIDStore(),
|
|
51
|
+
defaultProvider: 'did:key',
|
|
52
|
+
}),
|
|
53
|
+
new DIDResolverPlugin({
|
|
54
|
+
resolver: new Resolver({
|
|
55
|
+
...getDidKeyResolver(),
|
|
56
|
+
}),
|
|
57
|
+
}),
|
|
58
|
+
new IdentifierResolution({}),
|
|
59
|
+
new VcdmCredentialPlugin({issuers: [jsonld]})
|
|
60
|
+
|
|
61
|
+
],
|
|
62
|
+
})
|
|
63
|
+
didKeyIdentifier = await agent.didManagerCreate({ options: { type: 'Ed25519' } })
|
|
64
|
+
console.log(JSON.stringify(didKeyIdentifier, null, 2))
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('create a new status list', async () => {
|
|
68
|
+
const statusList = await createNewStatusList(
|
|
69
|
+
{
|
|
70
|
+
type: StatusListType.StatusList2021,
|
|
71
|
+
proofFormat: 'lds',
|
|
72
|
+
id: 'http://localhost:9543/list1',
|
|
73
|
+
issuer: didKeyIdentifier.did,
|
|
74
|
+
length: 99999,
|
|
75
|
+
correlationId: '1234',
|
|
76
|
+
statusList2021: {
|
|
77
|
+
statusPurpose: 'revocation',
|
|
78
|
+
indexingDirection: 'rightToLeft',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{ agent },
|
|
82
|
+
)
|
|
83
|
+
expect(statusList).toBeDefined()
|
|
84
|
+
expect(statusList.id).toEqual('http://localhost:9543/list1')
|
|
85
|
+
expect(statusList.encodedList).toBeDefined()
|
|
86
|
+
expect(statusList.issuer).toEqual(didKeyIdentifier.did)
|
|
87
|
+
expect(statusList.length).toEqual(99999)
|
|
88
|
+
expect(statusList.statusList2021).toBeTruthy()
|
|
89
|
+
expect(statusList.statusList2021!.indexingDirection).toEqual('rightToLeft')
|
|
90
|
+
expect(statusList.statusList2021!.statusPurpose).toEqual('revocation')
|
|
91
|
+
expect(statusList.proofFormat).toEqual('lds')
|
|
92
|
+
expect(statusList.statusListCredential).toBeDefined()
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { beforeAll, describe, expect, it } from 'vitest'
|
|
2
|
+
import { getDidKeyResolver, SphereonKeyDidProvider } from '@sphereon/ssi-sdk-ext.did-provider-key'
|
|
3
|
+
import { IdentifierResolution, IIdentifierResolution } from '@sphereon/ssi-sdk-ext.identifier-resolution'
|
|
4
|
+
import { SphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
|
|
5
|
+
import { SphereonKeyManagementSystem } from '@sphereon/ssi-sdk-ext.kms-local'
|
|
6
|
+
import { createAgent, CredentialPayload, IDIDManager, IIdentifier, IKeyManager, IResolver, PresentationPayload, TAgent } from '@veramo/core'
|
|
7
|
+
import { DIDManager, MemoryDIDStore } from '@veramo/did-manager'
|
|
8
|
+
import { DIDResolverPlugin } from '@veramo/did-resolver'
|
|
9
|
+
import { MemoryKeyStore, MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
10
|
+
import { Resolver } from 'did-resolver'
|
|
11
|
+
import { CredentialProviderJsonld } from '../agent'
|
|
12
|
+
import { LdDefaultContexts } from '../ld-default-contexts'
|
|
13
|
+
import { SphereonEd25519Signature2020 } from '../suites'
|
|
14
|
+
|
|
15
|
+
import { bedrijfsInformatieV1, exampleV1 } from './mocks'
|
|
16
|
+
import { ContextDoc, IVcdmCredentialPlugin, VcdmCredentialPlugin } from '@sphereon/ssi-sdk.credential-vcdm'
|
|
17
|
+
import { ControllerProofPurpose } from '../enums'
|
|
18
|
+
|
|
19
|
+
const customContext = new Map<string, ContextDoc>([
|
|
20
|
+
[`https://www.w3.org/2018/credentials/examples/v1`, exampleV1],
|
|
21
|
+
['https://sphereon-opensource.github.io/vc-contexts/myc/bedrijfsinformatie-v1.jsonld', bedrijfsInformatieV1],
|
|
22
|
+
])
|
|
23
|
+
|
|
24
|
+
describe('credential-LD full flow with VCDM2', () => {
|
|
25
|
+
let didKeyIdentifier: IIdentifier
|
|
26
|
+
let agent: TAgent<IResolver & IKeyManager & IDIDManager & IIdentifierResolution & IVcdmCredentialPlugin>
|
|
27
|
+
const jsonld = new CredentialProviderJsonld({
|
|
28
|
+
contextMaps: [LdDefaultContexts],
|
|
29
|
+
suites: [new SphereonEd25519Signature2020()],
|
|
30
|
+
})
|
|
31
|
+
// //jest.setTimeout(1000000)
|
|
32
|
+
beforeAll(async () => {
|
|
33
|
+
agent = createAgent({
|
|
34
|
+
plugins: [
|
|
35
|
+
new SphereonKeyManager({
|
|
36
|
+
store: new MemoryKeyStore(),
|
|
37
|
+
kms: {
|
|
38
|
+
local: new SphereonKeyManagementSystem(new MemoryPrivateKeyStore()),
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
new IdentifierResolution({ crypto: global.crypto }),
|
|
42
|
+
new DIDManager({
|
|
43
|
+
providers: {
|
|
44
|
+
'did:key': new SphereonKeyDidProvider({ defaultKms: 'local' }),
|
|
45
|
+
},
|
|
46
|
+
store: new MemoryDIDStore(),
|
|
47
|
+
defaultProvider: 'did:key',
|
|
48
|
+
}),
|
|
49
|
+
new DIDResolverPlugin({
|
|
50
|
+
resolver: new Resolver({
|
|
51
|
+
...getDidKeyResolver(),
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
new VcdmCredentialPlugin({ issuers: [jsonld] }),
|
|
55
|
+
],
|
|
56
|
+
})
|
|
57
|
+
didKeyIdentifier = await agent.didManagerCreate({ provider: 'did:key', options: { type: 'Ed25519' } })
|
|
58
|
+
console.log('didKeyIdentifier', didKeyIdentifier.did)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should work with Ed25519Signature2020', async () => {
|
|
62
|
+
const credentialPayload: CredentialPayload = {
|
|
63
|
+
issuer: didKeyIdentifier.did,
|
|
64
|
+
type: ['VerifiableCredential', 'AlumniCredential'],
|
|
65
|
+
'@context': ['https://www.w3.org/ns/credentials/v2', 'https://www.w3.org/ns/credentials/examples/v2'],
|
|
66
|
+
issuanceDate: '2020-08-19T21:41:50Z',
|
|
67
|
+
credentialSubject: {
|
|
68
|
+
id: didKeyIdentifier.did,
|
|
69
|
+
mySubjectProperty: 'mySubjectValue',
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
const verifiableCredential = await agent.createVerifiableCredential({
|
|
73
|
+
credential: credentialPayload,
|
|
74
|
+
proofFormat: 'lds',
|
|
75
|
+
fetchRemoteContexts: true,
|
|
76
|
+
})
|
|
77
|
+
console.log(JSON.stringify(verifiableCredential, null, 2))
|
|
78
|
+
|
|
79
|
+
expect(verifiableCredential).toBeDefined()
|
|
80
|
+
|
|
81
|
+
const verifiedCredential = await agent.verifyCredential({
|
|
82
|
+
credential: verifiableCredential,
|
|
83
|
+
fetchRemoteContexts: true,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
console.log(JSON.stringify(verifiedCredential, null, 2))
|
|
87
|
+
|
|
88
|
+
expect(verifiedCredential).toMatchObject({
|
|
89
|
+
log: [
|
|
90
|
+
{
|
|
91
|
+
id: 'valid_signature',
|
|
92
|
+
valid: true,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'issuer_did_resolves',
|
|
96
|
+
valid: true,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 'expiration',
|
|
100
|
+
valid: true,
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
results: [
|
|
104
|
+
{
|
|
105
|
+
log: [
|
|
106
|
+
{
|
|
107
|
+
id: 'valid_signature',
|
|
108
|
+
valid: true,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
id: 'issuer_did_resolves',
|
|
112
|
+
valid: true,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 'expiration',
|
|
116
|
+
valid: true,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
proof: {
|
|
120
|
+
'@context': [
|
|
121
|
+
'https://www.w3.org/ns/credentials/v2',
|
|
122
|
+
'https://www.w3.org/ns/credentials/examples/v2',
|
|
123
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
124
|
+
],
|
|
125
|
+
proofPurpose: 'assertionMethod',
|
|
126
|
+
type: 'Ed25519Signature2020',
|
|
127
|
+
},
|
|
128
|
+
purposeResult: {
|
|
129
|
+
controller: {
|
|
130
|
+
'@context': [
|
|
131
|
+
'https://www.w3.org/ns/did/v1',
|
|
132
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
133
|
+
'https://w3id.org/security/suites/x25519-2020/v1',
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
valid: true,
|
|
137
|
+
},
|
|
138
|
+
verificationMethod: {
|
|
139
|
+
'@context': [
|
|
140
|
+
'https://www.w3.org/ns/did/v1',
|
|
141
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
142
|
+
'https://w3id.org/security/suites/x25519-2020/v1',
|
|
143
|
+
],
|
|
144
|
+
type: 'Ed25519VerificationKey2020',
|
|
145
|
+
},
|
|
146
|
+
verified: true,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
verified: true,
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const presentationPayload: PresentationPayload = {
|
|
153
|
+
holder: didKeyIdentifier.did,
|
|
154
|
+
|
|
155
|
+
verifiableCredential: [verifiableCredential],
|
|
156
|
+
}
|
|
157
|
+
const verifiablePresentation = await agent.createVerifiablePresentation({
|
|
158
|
+
keyRef: didKeyIdentifier.controllerKeyId,
|
|
159
|
+
proofFormat: 'lds',
|
|
160
|
+
presentation: presentationPayload,
|
|
161
|
+
// We are overriding the purpose since the DID in this test does not have an authentication proof purpose
|
|
162
|
+
purpose: new ControllerProofPurpose({ term: 'verificationMethod' }),
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
expect(verifiablePresentation).toBeDefined()
|
|
166
|
+
|
|
167
|
+
const verifiedPresentation = await agent.verifyPresentation({
|
|
168
|
+
presentation: verifiablePresentation,
|
|
169
|
+
fetchRemoteContexts: true,
|
|
170
|
+
// We are overriding the purpose since the DID in this test does not have an authentication proof purpose
|
|
171
|
+
presentationPurpose: new ControllerProofPurpose({ term: 'verificationMethod' }),
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
expect(verifiedPresentation).toMatchObject({
|
|
175
|
+
credentialResults: [
|
|
176
|
+
{
|
|
177
|
+
log: [
|
|
178
|
+
{
|
|
179
|
+
id: 'valid_signature',
|
|
180
|
+
valid: true,
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
id: 'issuer_did_resolves',
|
|
184
|
+
valid: true,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 'expiration',
|
|
188
|
+
valid: true,
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
results: [
|
|
192
|
+
{
|
|
193
|
+
log: [
|
|
194
|
+
{
|
|
195
|
+
id: 'valid_signature',
|
|
196
|
+
valid: true,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: 'issuer_did_resolves',
|
|
200
|
+
valid: true,
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
id: 'expiration',
|
|
204
|
+
valid: true,
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
proof: {
|
|
208
|
+
'@context': [
|
|
209
|
+
'https://www.w3.org/ns/credentials/v2',
|
|
210
|
+
'https://www.w3.org/ns/credentials/examples/v2',
|
|
211
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
212
|
+
],
|
|
213
|
+
proofPurpose: 'assertionMethod',
|
|
214
|
+
type: 'Ed25519Signature2020',
|
|
215
|
+
},
|
|
216
|
+
purposeResult: {
|
|
217
|
+
valid: true,
|
|
218
|
+
},
|
|
219
|
+
verificationMethod: {
|
|
220
|
+
'@context': [
|
|
221
|
+
'https://www.w3.org/ns/did/v1',
|
|
222
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
223
|
+
'https://w3id.org/security/suites/x25519-2020/v1',
|
|
224
|
+
],
|
|
225
|
+
|
|
226
|
+
type: 'Ed25519VerificationKey2020',
|
|
227
|
+
},
|
|
228
|
+
verified: true,
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
verified: true,
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
presentationResult: {
|
|
235
|
+
results: [
|
|
236
|
+
{
|
|
237
|
+
proof: {
|
|
238
|
+
'@context': ['https://www.w3.org/ns/credentials/v2', 'https://w3id.org/security/suites/ed25519-2020/v1'],
|
|
239
|
+
proofPurpose: 'verificationMethod',
|
|
240
|
+
type: 'Ed25519Signature2020',
|
|
241
|
+
},
|
|
242
|
+
purposeResult: {
|
|
243
|
+
controller: {
|
|
244
|
+
'@context': [
|
|
245
|
+
'https://www.w3.org/ns/did/v1',
|
|
246
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
247
|
+
'https://w3id.org/security/suites/x25519-2020/v1',
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
valid: true,
|
|
251
|
+
},
|
|
252
|
+
verificationMethod: {
|
|
253
|
+
'@context': [
|
|
254
|
+
'https://www.w3.org/ns/did/v1',
|
|
255
|
+
'https://w3id.org/security/suites/ed25519-2020/v1',
|
|
256
|
+
'https://w3id.org/security/suites/x25519-2020/v1',
|
|
257
|
+
],
|
|
258
|
+
type: 'Ed25519VerificationKey2020',
|
|
259
|
+
},
|
|
260
|
+
verified: true,
|
|
261
|
+
},
|
|
262
|
+
],
|
|
263
|
+
verified: true,
|
|
264
|
+
},
|
|
265
|
+
verified: true,
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
})
|