@veramo/credential-ld 6.0.1-next.5 → 6.0.1-next.6

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.
Files changed (55) hide show
  1. package/build/CredentialProviderLD.d.ts +42 -0
  2. package/build/CredentialProviderLD.d.ts.map +1 -0
  3. package/build/{action-handler.js → CredentialProviderLD.js} +38 -25
  4. package/build/CredentialProviderLD.js.map +1 -0
  5. package/build/index.d.ts +3 -4
  6. package/build/index.d.ts.map +1 -1
  7. package/build/index.js +3 -4
  8. package/build/index.js.map +1 -1
  9. package/build/ld-credential-module.d.ts +4 -4
  10. package/build/ld-credential-module.d.ts.map +1 -1
  11. package/build/ld-credential-module.js.map +1 -1
  12. package/build/ld-default-contexts.d.ts +1 -1
  13. package/build/ld-default-contexts.js +1 -1
  14. package/build/ld-suites.d.ts +1 -0
  15. package/build/ld-suites.d.ts.map +1 -1
  16. package/build/ld-suites.js.map +1 -1
  17. package/build/suites/EcdsaSecp256k1RecoverySignature2020.d.ts +1 -0
  18. package/build/suites/EcdsaSecp256k1RecoverySignature2020.d.ts.map +1 -1
  19. package/build/suites/EcdsaSecp256k1RecoverySignature2020.js +3 -0
  20. package/build/suites/EcdsaSecp256k1RecoverySignature2020.js.map +1 -1
  21. package/build/suites/Ed25519Signature2018.d.ts +1 -0
  22. package/build/suites/Ed25519Signature2018.d.ts.map +1 -1
  23. package/build/suites/Ed25519Signature2018.js +3 -0
  24. package/build/suites/Ed25519Signature2018.js.map +1 -1
  25. package/build/suites/Ed25519Signature2020.d.ts +1 -0
  26. package/build/suites/Ed25519Signature2020.d.ts.map +1 -1
  27. package/build/suites/Ed25519Signature2020.js +3 -0
  28. package/build/suites/Ed25519Signature2020.js.map +1 -1
  29. package/build/suites/JsonWebSignature2020.d.ts +1 -0
  30. package/build/suites/JsonWebSignature2020.d.ts.map +1 -1
  31. package/build/suites/JsonWebSignature2020.js +3 -0
  32. package/build/suites/JsonWebSignature2020.js.map +1 -1
  33. package/build/types.d.ts +0 -220
  34. package/build/types.d.ts.map +1 -1
  35. package/package.json +6 -10
  36. package/src/{action-handler.ts → CredentialProviderLD.ts} +61 -40
  37. package/src/__tests__/issue-verify-ed25519-2020.test.ts +122 -122
  38. package/src/__tests__/{issue-verify-flow.test.ts → issue-verify-flow-ld.test.ts} +7 -6
  39. package/src/index.ts +3 -4
  40. package/src/ld-credential-module.ts +4 -3
  41. package/src/ld-default-contexts.ts +1 -1
  42. package/src/ld-suites.ts +2 -0
  43. package/src/suites/EcdsaSecp256k1RecoverySignature2020.ts +6 -1
  44. package/src/suites/Ed25519Signature2018.ts +5 -0
  45. package/src/suites/Ed25519Signature2020.ts +5 -1
  46. package/src/suites/JsonWebSignature2020.ts +5 -1
  47. package/src/types.ts +0 -265
  48. package/build/action-handler.d.ts +0 -461
  49. package/build/action-handler.d.ts.map +0 -1
  50. package/build/action-handler.js.map +0 -1
  51. package/build/plugin.schema.d.ts +0 -430
  52. package/build/plugin.schema.d.ts.map +0 -1
  53. package/build/plugin.schema.js +0 -477
  54. package/build/plugin.schema.js.map +0 -1
  55. package/src/plugin.schema.ts +0 -476
@@ -1,143 +1,143 @@
1
1
  import {
2
- createAgent,
3
- CredentialPayload,
4
- ICredentialPlugin,
5
- IDIDManager,
6
- IIdentifier,
7
- IKeyManager,
8
- IResolver,
9
- TAgent,
10
- } from '../../../core/src'
11
- import { CredentialPlugin } from '../../../credential-w3c/src'
12
- import { DIDManager, MemoryDIDStore } from '../../../did-manager/src'
13
- import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-manager/src'
14
- import { KeyManagementSystem } from '../../../kms-local/src'
15
- import { DIDResolverPlugin } from '../../../did-resolver/src'
16
- import { ContextDoc } from '../types'
17
- import { CredentialIssuerLD } from '../action-handler'
18
- import { LdDefaultContexts } from '../ld-default-contexts'
19
- import { VeramoEd25519Signature2020 } from '../suites/Ed25519Signature2020'
20
- import { Resolver } from 'did-resolver'
21
- import { FakeDidProvider, FakeDidResolver } from '../../../test-utils/src/fake-did'
22
- import { jest } from '@jest/globals'
2
+ createAgent,
3
+ CredentialPayload,
4
+ ICredentialPlugin,
5
+ IDIDManager,
6
+ IIdentifier,
7
+ IKeyManager,
8
+ IResolver,
9
+ TAgent,
10
+ } from '../../../core/src'
11
+ import { CredentialPlugin } from '../../../credential-w3c/src'
12
+ import { DIDManager, MemoryDIDStore } from '../../../did-manager/src'
13
+ import { KeyManager, MemoryKeyStore, MemoryPrivateKeyStore } from '../../../key-manager/src'
14
+ import { KeyManagementSystem } from '../../../kms-local/src'
15
+ import { DIDResolverPlugin } from '../../../did-resolver/src'
16
+ import { ContextDoc } from '../types'
17
+ import { CredentialProviderLD } from '../CredentialProviderLD'
18
+ import { LdDefaultContexts } from '../ld-default-contexts'
19
+ import { VeramoEd25519Signature2020 } from '../suites/Ed25519Signature2020'
20
+ import { Resolver } from 'did-resolver'
21
+ import { FakeDidProvider, FakeDidResolver } from '../../../test-utils/src/fake-did'
22
+ import { jest } from '@jest/globals'
23
23
 
24
- jest.setTimeout(300000)
24
+ jest.setTimeout(300000)
25
25
 
26
- const customContext: Record<string, ContextDoc> = {
27
- 'custom:example.context': {
28
- '@context': {
29
- nothing: 'custom:example.context#blank',
30
- },
26
+ const customContext: Record<string, ContextDoc> = {
27
+ 'custom:example.context': {
28
+ '@context': {
29
+ nothing: 'custom:example.context#blank',
31
30
  },
32
- }
31
+ },
32
+ }
33
33
 
34
- describe('credential-LD full flow', () => {
35
- let didFakeIdentifier: IIdentifier
36
- let agent: TAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin>
34
+ describe('credential-LD full flow', () => {
35
+ let didFakeIdentifier: IIdentifier
36
+ let agent: TAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin>
37
37
 
38
- beforeAll(async () => {
39
- agent = createAgent({
40
- plugins: [
41
- new KeyManager({
42
- store: new MemoryKeyStore(),
43
- kms: {
44
- local: new KeyManagementSystem(new MemoryPrivateKeyStore()),
45
- },
46
- }),
47
- new DIDManager({
48
- providers: {
49
- 'did:fake': new FakeDidProvider(),
50
- },
51
- store: new MemoryDIDStore(),
52
- defaultProvider: 'did:fake',
53
- }),
54
- new DIDResolverPlugin({
55
- resolver: new Resolver({
56
- ...new FakeDidResolver(() => agent, true).getDidFakeResolver(),
57
- }),
58
- }),
59
- new CredentialPlugin(),
60
- new CredentialIssuerLD({
61
- contextMaps: [LdDefaultContexts, customContext],
62
- suites: [new VeramoEd25519Signature2020()],
63
- }),
64
- ],
65
- })
66
- didFakeIdentifier = await agent.didManagerImport({
67
- did: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo',
68
- keys: [
69
- {
70
- type: 'Ed25519',
71
- kid: 'didcomm-senderKey-1',
72
- publicKeyHex: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
73
- privateKeyHex:
74
- 'b57103882f7c66512dc96777cbafbeb2d48eca1e7a867f5a17a84e9a6740f7dc1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
75
- kms: 'local',
38
+ beforeAll(async () => {
39
+ const ld = new CredentialProviderLD({
40
+ contextMaps: [LdDefaultContexts, customContext],
41
+ suites: [new VeramoEd25519Signature2020()],
42
+ })
43
+ agent = createAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin>({
44
+ plugins: [
45
+ new KeyManager({
46
+ store: new MemoryKeyStore(),
47
+ kms: {
48
+ local: new KeyManagementSystem(new MemoryPrivateKeyStore()),
76
49
  },
77
- ],
78
- services: [
79
- {
80
- id: 'msg1',
81
- type: 'DIDCommMessaging',
82
- serviceEndpoint: 'http://localhost:3002/messaging',
50
+ }),
51
+ new DIDManager({
52
+ providers: {
53
+ 'did:fake': new FakeDidProvider(),
83
54
  },
84
- ],
85
- provider: 'did:fake',
86
- alias: 'sender',
87
- })
55
+ store: new MemoryDIDStore(),
56
+ defaultProvider: 'did:fake',
57
+ }),
58
+ new DIDResolverPlugin({
59
+ resolver: new Resolver({
60
+ ...new FakeDidResolver(() => agent, true).getDidFakeResolver(),
61
+ }),
62
+ }),
63
+ new CredentialPlugin({ issuers: [ld] }),
64
+ ],
88
65
  })
89
-
90
- it('works with Ed25519Signature2020 credential', async () => {
91
- const credential: CredentialPayload = {
92
- issuer: didFakeIdentifier.did,
93
- '@context': ['custom:example.context'],
94
- credentialSubject: {
95
- nothing: 'else matters',
66
+ didFakeIdentifier = await agent.didManagerImport({
67
+ did: 'did:fake:z6MkgbqNU4uF9NKSz5BqJQ4XKVHuQZYcUZP8pXGsJC8nTHwo',
68
+ keys: [
69
+ {
70
+ type: 'Ed25519',
71
+ kid: 'didcomm-senderKey-1',
72
+ publicKeyHex: '1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
73
+ privateKeyHex:
74
+ 'b57103882f7c66512dc96777cbafbeb2d48eca1e7a867f5a17a84e9a6740f7dc1fe9b397c196ab33549041b29cf93be29b9f2bdd27322f05844112fad97ff92a',
75
+ kms: 'local',
76
+ },
77
+ ],
78
+ services: [
79
+ {
80
+ id: 'msg1',
81
+ type: 'DIDCommMessaging',
82
+ serviceEndpoint: 'http://localhost:3002/messaging',
96
83
  },
97
- }
98
- const verifiableCredential = await agent.createVerifiableCredential({
99
- credential,
100
- proofFormat: 'lds',
101
- })
84
+ ],
85
+ provider: 'did:fake',
86
+ alias: 'sender',
87
+ })
88
+ })
102
89
 
103
- expect(verifiableCredential).toBeDefined()
90
+ it('works with Ed25519Signature2020 credential', async () => {
91
+ const credential: CredentialPayload = {
92
+ issuer: didFakeIdentifier.did,
93
+ '@context': ['custom:example.context'],
94
+ credentialSubject: {
95
+ nothing: 'else matters',
96
+ },
97
+ }
98
+ const verifiableCredential = await agent.createVerifiableCredential({
99
+ credential,
100
+ proofFormat: 'lds',
101
+ })
104
102
 
105
- const result = await agent.verifyCredential({
106
- credential: verifiableCredential,
107
- })
103
+ expect(verifiableCredential).toBeDefined()
108
104
 
109
- expect(result.verified).toBe(true)
105
+ const result = await agent.verifyCredential({
106
+ credential: verifiableCredential,
110
107
  })
111
108
 
112
- it('works with Ed25519Signature2020 credential and presentation', async () => {
113
- const credential: CredentialPayload = {
114
- issuer: didFakeIdentifier.did,
115
- '@context': ['custom:example.context'],
116
- credentialSubject: {
117
- nothing: 'else matters',
118
- },
119
- }
120
- const verifiableCredential1 = await agent.createVerifiableCredential({
121
- credential,
122
- proofFormat: 'lds',
123
- })
109
+ expect(result.verified).toBe(true)
110
+ })
124
111
 
125
- const verifiablePresentation = await agent.createVerifiablePresentation({
126
- presentation: {
127
- verifiableCredential: [verifiableCredential1],
128
- holder: didFakeIdentifier.did,
129
- },
130
- challenge: 'VERAMO',
131
- proofFormat: 'lds',
132
- })
112
+ it('works with Ed25519Signature2020 credential and presentation', async () => {
113
+ const credential: CredentialPayload = {
114
+ issuer: didFakeIdentifier.did,
115
+ '@context': ['custom:example.context'],
116
+ credentialSubject: {
117
+ nothing: 'else matters',
118
+ },
119
+ }
120
+ const verifiableCredential1 = await agent.createVerifiableCredential({
121
+ credential,
122
+ proofFormat: 'lds',
123
+ })
133
124
 
134
- expect(verifiablePresentation).toBeDefined()
125
+ const verifiablePresentation = await agent.createVerifiablePresentation({
126
+ presentation: {
127
+ verifiableCredential: [verifiableCredential1],
128
+ holder: didFakeIdentifier.did,
129
+ },
130
+ challenge: 'VERAMO',
131
+ proofFormat: 'lds',
132
+ })
135
133
 
136
- const result = await agent.verifyPresentation({
137
- presentation: verifiablePresentation,
138
- challenge: 'VERAMO',
139
- })
134
+ expect(verifiablePresentation).toBeDefined()
140
135
 
141
- expect(result.verified).toBe(true)
136
+ const result = await agent.verifyPresentation({
137
+ presentation: verifiablePresentation,
138
+ challenge: 'VERAMO',
142
139
  })
140
+
141
+ expect(result.verified).toBe(true)
143
142
  })
143
+ })
@@ -16,7 +16,7 @@ import { getDidKeyResolver, KeyDIDProvider } from '../../../did-provider-key/src
16
16
  import { DIDResolverPlugin } from '../../../did-resolver/src'
17
17
  import { EthrDIDProvider } from '../../../did-provider-ethr/src'
18
18
  import { ContextDoc } from '../types.js'
19
- import { CredentialIssuerLD } from '../action-handler.js'
19
+ import { CredentialProviderLD } from '../CredentialProviderLD.js'
20
20
  import { LdDefaultContexts } from '../ld-default-contexts.js'
21
21
  import { VeramoEd25519Signature2018 } from '../suites/Ed25519Signature2018.js'
22
22
  import { Resolver } from 'did-resolver'
@@ -43,6 +43,11 @@ describe('credential-LD full flow', () => {
43
43
  let didEthrIdentifier: IIdentifier
44
44
  let agent: TAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin>
45
45
 
46
+ const ld = new CredentialProviderLD({
47
+ contextMaps: [LdDefaultContexts, customContext],
48
+ suites: [new VeramoEd25519Signature2018(), new VeramoEcdsaSecp256k1RecoverySignature2020()],
49
+ })
50
+
46
51
  beforeAll(async () => {
47
52
  agent = createAgent<IResolver & IKeyManager & IDIDManager & ICredentialPlugin>({
48
53
  plugins: [
@@ -69,11 +74,7 @@ describe('credential-LD full flow', () => {
69
74
  ...ethrDidResolver({ infuraProjectId }),
70
75
  }),
71
76
  }),
72
- new CredentialPlugin(),
73
- new CredentialIssuerLD({
74
- contextMaps: [LdDefaultContexts, customContext],
75
- suites: [new VeramoEd25519Signature2018(), new VeramoEcdsaSecp256k1RecoverySignature2020()],
76
- }),
77
+ new CredentialPlugin({ issuers: [ld] }),
77
78
  ],
78
79
  })
79
80
  didKeyIdentifier = await agent.didManagerCreate()
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Provides a {@link @veramo/credential-ld#CredentialIssuerLD | plugin} for the {@link @veramo/core#Agent} that
2
+ * Provides a {@link @veramo/credential-ld#CredentialProviderLD | handler} for the {@link @veramo/credential-w3c#CredentialPlugin} that
3
3
  * implements
4
- * {@link @veramo/credential-ld#ICredentialIssuerLD} interface.
4
+ * {@link @veramo/core-types#AbstractCredentialProvider} interface.
5
5
  *
6
6
  * This plugin adds support for working with JSON-LD credentials.
7
7
  * When installed, this plugin will be automatically used by
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * @packageDocumentation
12
12
  */
13
- export { CredentialIssuerLD } from './action-handler.js'
13
+ export { CredentialProviderLD } from './CredentialProviderLD.js'
14
14
  export * from './types.js'
15
15
  export { LdDefaultContexts } from './ld-default-contexts.js'
16
16
  export { VeramoLdSignature } from './ld-suites.js'
@@ -18,4 +18,3 @@ export * from './suites/EcdsaSecp256k1RecoverySignature2020.js'
18
18
  export * from './suites/Ed25519Signature2018.js'
19
19
  export * from './suites/Ed25519Signature2020.js'
20
20
  export * from './suites/JsonWebSignature2020.js'
21
- export { schema } from './plugin.schema.js'
@@ -3,6 +3,7 @@ import {
3
3
  IAgentContext,
4
4
  IKey,
5
5
  IResolver,
6
+ IVerifyResult,
6
7
  PresentationPayload,
7
8
  UsingResolutionOptions,
8
9
  VerifiableCredential,
@@ -22,7 +23,7 @@ const debug = Debug('veramo:w3c:ld-credential-module')
22
23
 
23
24
  type ForwardedOptions = UsingResolutionOptions & {
24
25
  fetchRemoteContexts?: boolean // defaults to false
25
- now?: number // defaults to Date.now()
26
+ now?: Date // defaults to Date.now()
26
27
  }
27
28
 
28
29
  export class LdCredentialModule {
@@ -170,7 +171,7 @@ export class LdCredentialModule {
170
171
  credential: VerifiableCredential,
171
172
  options: ForwardedOptions,
172
173
  context: IAgentContext<IResolver>,
173
- ): Promise<boolean> {
174
+ ): Promise<IVerifyResult> {
174
175
  const fetchRemoteContexts = options.fetchRemoteContexts ?? false
175
176
  const result = await vc.verifyCredential({
176
177
  ...options,
@@ -195,7 +196,7 @@ export class LdCredentialModule {
195
196
  domain: string | undefined,
196
197
  options: ForwardedOptions,
197
198
  context: IAgentContext<IResolver>,
198
- ): Promise<boolean> {
199
+ ): Promise<IVerifyResult> {
199
200
  const fetchRemoteContexts = options.fetchRemoteContexts ?? false
200
201
  const result = await vc.verify({
201
202
  ...options,
@@ -20,7 +20,7 @@ import schema_org from './contexts/schema.org.json' assert { type: 'json' }
20
20
  * Provides a hardcoded map of common Linked Data `@context` definitions.
21
21
  *
22
22
  * You can use this to bootstrap the `@context` definitions used by
23
- * {@link @veramo/credential-ld#CredentialIssuerLD | CredentialIssuerLD} with these common context definitions.
23
+ * {@link @veramo/credential-ld#CredentialProviderLD | CredentialProviderLD} with these common context definitions.
24
24
  *
25
25
  * @beta This API may change without a BREAKING CHANGE notice.
26
26
  */
package/src/ld-suites.ts CHANGED
@@ -25,6 +25,8 @@ export abstract class VeramoLdSignature {
25
25
 
26
26
  abstract getSupportedVerificationType(): string | string[]
27
27
 
28
+ abstract getSupportedProofType(): string
29
+
28
30
  abstract getSupportedVeramoKeyType(): TKeyType
29
31
 
30
32
  abstract getSuiteForSigning(
@@ -17,6 +17,11 @@ export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature
17
17
  // 'JsonWebKey2020', 'Multikey']
18
18
  }
19
19
 
20
+ getSupportedProofType(): string {
21
+ return 'EcdsaSecp256k1RecoverySignature2020'
22
+ }
23
+
24
+
20
25
  getSupportedVeramoKeyType(): TKeyType {
21
26
  return 'Secp256k1'
22
27
  }
@@ -71,7 +76,7 @@ export class VeramoEcdsaSecp256k1RecoverySignature2020 extends VeramoLdSignature
71
76
  return new EcdsaSecp256k1RecoverySignature2020()
72
77
  }
73
78
 
74
- preSigningCredModification(credential: CredentialPayload): void {}
79
+ preSigningCredModification(credential: CredentialPayload): void { }
75
80
 
76
81
  async preDidResolutionModification(didUrl: string, didDoc: DIDDocument): Promise<DIDDocument> {
77
82
  const ctx = asArray(didDoc['@context'])
@@ -14,6 +14,11 @@ export class VeramoEd25519Signature2018 extends VeramoLdSignature {
14
14
  // TODO: add support for ['Ed25519VerificationKey2020', 'Multikey']
15
15
  }
16
16
 
17
+ getSupportedProofType(): string {
18
+ return 'Ed25519Signature2018'
19
+ }
20
+
21
+
17
22
  getSupportedVeramoKeyType(): TKeyType {
18
23
  return 'Ed25519'
19
24
  }
@@ -35,6 +35,10 @@ export class VeramoEd25519Signature2020 extends VeramoLdSignature {
35
35
  // TODO: add support for ['JsonWebKey2020', 'Multikey']
36
36
  }
37
37
 
38
+ getSupportedProofType(): string {
39
+ return 'Ed25519Signature2020'
40
+ }
41
+
38
42
  getSupportedVeramoKeyType(): TKeyType {
39
43
  return 'Ed25519'
40
44
  }
@@ -136,7 +140,7 @@ export class VeramoEd25519Signature2020 extends VeramoLdSignature {
136
140
 
137
141
  private transformVerificationMethod(vm: VerificationMethod): VerificationMethod {
138
142
  if (vm.type === 'Ed25519VerificationKey2020') {
139
- ;(vm as any)['@context'] = 'https://w3id.org/security/suites/ed25519-2020/v1'
143
+ ; (vm as any)['@context'] = 'https://w3id.org/security/suites/ed25519-2020/v1'
140
144
  // publicKeyMultibase is required by this suite
141
145
  if (!vm.publicKeyMultibase) {
142
146
  const { publicKeyHex } = extractPublicKeyHex(vm)
@@ -19,7 +19,11 @@ import {
19
19
  export class VeramoJsonWebSignature2020 extends VeramoLdSignature {
20
20
  getSupportedVerificationType(): string {
21
21
  return 'JsonWebKey2020'
22
- // TODO: add support for ['Ed25519VerificationKey2018', 'Ed25519VerificationKey2020', 'Multikey'] and others
22
+ // TODO: add support for ['Ed25519VerificationKey2018', 'Ed25519VerificationKey2020', 'Multikey'] and others
23
+ }
24
+
25
+ getSupportedProofType(): string {
26
+ return 'JsonWebSignature2020'
23
27
  }
24
28
 
25
29
  getSupportedVeramoKeyType(): TKeyType {