@sphereon/ssi-sdk-ext.identifier-resolution 0.24.1-next.103 → 0.24.1-next.105

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 (41) hide show
  1. package/dist/agent/IdentifierResolution.d.ts +3 -0
  2. package/dist/agent/IdentifierResolution.d.ts.map +1 -1
  3. package/dist/agent/IdentifierResolution.js +18 -0
  4. package/dist/agent/IdentifierResolution.js.map +1 -1
  5. package/dist/functions/LegacySupport.d.ts.map +1 -1
  6. package/dist/functions/LegacySupport.js +5 -4
  7. package/dist/functions/LegacySupport.js.map +1 -1
  8. package/dist/functions/externalIdentifierFunctions.d.ts +17 -1
  9. package/dist/functions/externalIdentifierFunctions.d.ts.map +1 -1
  10. package/dist/functions/externalIdentifierFunctions.js +82 -2
  11. package/dist/functions/externalIdentifierFunctions.js.map +1 -1
  12. package/dist/functions/managedIdentifierFunctions.d.ts +7 -1
  13. package/dist/functions/managedIdentifierFunctions.d.ts.map +1 -1
  14. package/dist/functions/managedIdentifierFunctions.js +39 -1
  15. package/dist/functions/managedIdentifierFunctions.js.map +1 -1
  16. package/dist/types/IIdentifierResolution.d.ts +5 -2
  17. package/dist/types/IIdentifierResolution.d.ts.map +1 -1
  18. package/dist/types/IIdentifierResolution.js +3 -0
  19. package/dist/types/IIdentifierResolution.js.map +1 -1
  20. package/dist/types/common.d.ts +2 -1
  21. package/dist/types/common.d.ts.map +1 -1
  22. package/dist/types/common.js +5 -1
  23. package/dist/types/common.js.map +1 -1
  24. package/dist/types/externalIdentifierTypes.d.ts +23 -6
  25. package/dist/types/externalIdentifierTypes.d.ts.map +1 -1
  26. package/dist/types/externalIdentifierTypes.js +6 -1
  27. package/dist/types/externalIdentifierTypes.js.map +1 -1
  28. package/dist/types/managedIdentifierTypes.d.ts +16 -6
  29. package/dist/types/managedIdentifierTypes.d.ts.map +1 -1
  30. package/dist/types/managedIdentifierTypes.js +10 -1
  31. package/dist/types/managedIdentifierTypes.js.map +1 -1
  32. package/package.json +12 -12
  33. package/plugin.schema.json +932 -110
  34. package/src/agent/IdentifierResolution.ts +33 -1
  35. package/src/functions/LegacySupport.ts +45 -41
  36. package/src/functions/externalIdentifierFunctions.ts +94 -4
  37. package/src/functions/managedIdentifierFunctions.ts +46 -2
  38. package/src/types/IIdentifierResolution.ts +18 -0
  39. package/src/types/common.ts +5 -1
  40. package/src/types/externalIdentifierTypes.ts +54 -13
  41. package/src/types/managedIdentifierTypes.ts +37 -8
@@ -1,5 +1,15 @@
1
1
  import { IAgentContext, IAgentPlugin, IDIDManager, IKeyManager } from '@veramo/core'
2
- import { ensureManagedIdentifierResult, ManagedIdentifierKeyOpts, ManagedIdentifierKeyResult, ManagedIdentifierOptsOrResult, schema } from '..'
2
+ import {
3
+ ensureManagedIdentifierResult,
4
+ ExternalIdentifierCoseKeyOpts,
5
+ ExternalIdentifierCoseKeyResult,
6
+ ExternalIdentifierJwkOpts,
7
+ ExternalIdentifierJwkResult,
8
+ ManagedIdentifierKeyOpts,
9
+ ManagedIdentifierKeyResult,
10
+ ManagedIdentifierOptsOrResult,
11
+ schema,
12
+ } from '..'
3
13
  import { resolveExternalIdentifier } from '../functions'
4
14
  import {
5
15
  ExternalIdentifierDidOpts,
@@ -9,6 +19,8 @@ import {
9
19
  ExternalIdentifierX5cOpts,
10
20
  ExternalIdentifierX5cResult,
11
21
  IIdentifierResolution,
22
+ ManagedIdentifierCoseKeyOpts,
23
+ ManagedIdentifierCoseKeyResult,
12
24
  ManagedIdentifierDidOpts,
13
25
  ManagedIdentifierDidResult,
14
26
  ManagedIdentifierJwkOpts,
@@ -34,10 +46,13 @@ export class IdentifierResolution implements IAgentPlugin {
34
46
  identifierManagedGetByJwk: this.identifierGetManagedByJwk.bind(this),
35
47
  identifierManagedGetByX5c: this.identifierGetManagedByX5c.bind(this),
36
48
  identifierManagedGetByKey: this.identifierGetManagedByKey.bind(this),
49
+ identifierManagedGetByCoseKey: this.identifierGetManagedByCoseKey.bind(this),
37
50
 
38
51
  identifierExternalResolve: this.identifierResolveExternal.bind(this),
39
52
  identifierExternalResolveByDid: this.identifierExternalResolveByDid.bind(this),
40
53
  identifierExternalResolveByX5c: this.identifierExternalResolveByX5c.bind(this),
54
+ identifierExternalResolveByJwk: this.identifierExternalResolveByJwk.bind(this),
55
+ identifierExternalResolveByCoseKey: this.identifierExternalResolveByCoseKey.bind(this),
41
56
 
42
57
  // todo: JWKSet, oidc-discovery, oid4vci-issuer etc. Anything we already can resolve and need keys of
43
58
  }
@@ -84,6 +99,13 @@ export class IdentifierResolution implements IAgentPlugin {
84
99
  return (await this.identifierGetManaged({ ...args, method: 'key' }, context)) as ManagedIdentifierKeyResult
85
100
  }
86
101
 
102
+ private async identifierGetManagedByCoseKey(
103
+ args: ManagedIdentifierCoseKeyOpts,
104
+ context: IAgentContext<IKeyManager & IIdentifierResolution>
105
+ ): Promise<ManagedIdentifierCoseKeyResult> {
106
+ return (await this.identifierGetManaged({ ...args, method: 'cose_key' }, context)) as ManagedIdentifierCoseKeyResult
107
+ }
108
+
87
109
  private async identifierGetManagedByJwk(
88
110
  args: ManagedIdentifierJwkOpts,
89
111
  context: IAgentContext<IKeyManager & IIdentifierResolution>
@@ -109,4 +131,14 @@ export class IdentifierResolution implements IAgentPlugin {
109
131
  private async identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult> {
110
132
  return (await this.identifierResolveExternal({ ...args, method: 'x5c' }, context)) as ExternalIdentifierX5cResult
111
133
  }
134
+
135
+ private async identifierExternalResolveByCoseKey(
136
+ args: ExternalIdentifierCoseKeyOpts,
137
+ context: IAgentContext<any>
138
+ ): Promise<ExternalIdentifierCoseKeyResult> {
139
+ return (await this.identifierResolveExternal({ ...args, method: 'cose_key' }, context)) as ExternalIdentifierCoseKeyResult
140
+ }
141
+ private async identifierExternalResolveByJwk(args: ExternalIdentifierJwkOpts, context: IAgentContext<any>): Promise<ExternalIdentifierJwkResult> {
142
+ return (await this.identifierResolveExternal({ ...args, method: 'jwk' }, context)) as ExternalIdentifierJwkResult
143
+ }
112
144
  }
@@ -1,50 +1,54 @@
1
- import { IIdentifier } from '@veramo/core'
2
- import { ManagedIdentifierDidOpts, ManagedIdentifierOptsOrResult } from '../types'
1
+ import {IIdentifier} from '@veramo/core'
2
+ import {ManagedIdentifierDidOpts, ManagedIdentifierOptsOrResult} from '../types'
3
3
 
4
4
  /**
5
5
  * Converts legacy id opts key refs to the new ManagedIdentifierOpts
6
6
  * @param opts
7
7
  */
8
8
  export function legacyKeyRefsToIdentifierOpts(opts: {
9
- idOpts?: ManagedIdentifierOptsOrResult
10
- iss?: string
11
- keyRef?: string
12
- didOpts?: any
9
+ idOpts?: ManagedIdentifierOptsOrResult
10
+ iss?: string
11
+ keyRef?: string
12
+ didOpts?: any
13
13
  }): ManagedIdentifierOptsOrResult {
14
- if (!opts.idOpts) {
15
- console.warn(
16
- `Legacy idOpts being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
17
- )
18
- // legacy way
19
- let kmsKeyRef =
20
- opts.keyRef ??
21
- opts.didOpts?.idOpts?.kmsKeyRef ??
22
- (typeof opts.didOpts?.idOpts.identifier === 'object' ? (opts.didOpts?.idOpts.identifier as IIdentifier).keys[0].kid : undefined)
23
- if (!kmsKeyRef) {
24
- throw Error('Key ref is needed for access token signer')
25
- }
26
- return {
27
- kmsKeyRef: opts.keyRef ?? kmsKeyRef,
28
- identifier: kmsKeyRef,
29
- issuer: opts.iss,
30
- } satisfies ManagedIdentifierDidOpts
31
- } else {
32
- const idOpts = opts.idOpts
33
- if (opts.keyRef && !idOpts.kmsKeyRef) {
34
- // legacy way
35
- console.warn(
36
- `Legacy keyRef being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
37
- )
38
- idOpts.kmsKeyRef = opts.keyRef
39
- }
40
- if (opts.iss && !idOpts.issuer) {
41
- // legacy way
42
- console.warn(
43
- `Legacy iss being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
44
- )
45
- idOpts.issuer = opts.iss
46
- }
14
+ if (!opts.idOpts) {
15
+ console.warn(
16
+ `Legacy idOpts being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
17
+ )
18
+ // legacy way
19
+ let kmsKeyRef =
20
+ opts.keyRef ??
21
+ opts.didOpts?.idOpts?.kmsKeyRef ??
22
+ opts.didOpts?.kid ??
23
+ opts.didOpts.idOpts?.kid ??
24
+ (typeof opts.didOpts?.idOpts.identifier === 'object' ? (opts.didOpts?.idOpts.identifier as IIdentifier).keys[0].kid : undefined)
25
+ if (!kmsKeyRef) {
26
+ throw Error('Key ref is needed for access token signer')
27
+ }
28
+ let identifier = (opts.didOpts?.identifier ?? opts.didOpts?.idOpts?.identifier) as IIdentifier | undefined
47
29
 
48
- return idOpts
49
- }
30
+ return {
31
+ kmsKeyRef: opts.keyRef ?? kmsKeyRef,
32
+ identifier: identifier ?? kmsKeyRef,
33
+ issuer: opts.iss,
34
+ } satisfies ManagedIdentifierDidOpts
35
+ } else {
36
+ const idOpts = opts.idOpts
37
+ if (opts.keyRef && !idOpts.kmsKeyRef) {
38
+ // legacy way
39
+ console.warn(
40
+ `Legacy keyRef being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
41
+ )
42
+ idOpts.kmsKeyRef = opts.keyRef
43
+ }
44
+ if (opts.iss && !idOpts.issuer) {
45
+ // legacy way
46
+ console.warn(
47
+ `Legacy iss being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
48
+ )
49
+ idOpts.issuer = opts.iss
50
+ }
51
+
52
+ return idOpts
53
+ }
50
54
  }
@@ -1,5 +1,5 @@
1
- import { didDocumentToJwks, getAgentResolver } from '@sphereon/ssi-sdk-ext.did-utils'
2
- import { calculateJwkThumbprint, JWK } from '@sphereon/ssi-sdk-ext.key-utils'
1
+ import { didDocumentToJwks, getAgentResolver, jwkTtoPublicKeyHex } from '@sphereon/ssi-sdk-ext.did-utils'
2
+ import { calculateJwkThumbprint, coseKeyToJwk } from '@sphereon/ssi-sdk-ext.key-utils'
3
3
  import {
4
4
  getSubjectDN,
5
5
  pemOrDerToX509Certificate,
@@ -8,20 +8,26 @@ import {
8
8
  X509ValidationResult,
9
9
  } from '@sphereon/ssi-sdk-ext.x509-utils'
10
10
  import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
11
- import { IParsedDID, parseDid } from '@sphereon/ssi-types'
11
+ import { IParsedDID, JWK, parseDid } from '@sphereon/ssi-types'
12
12
  import { IAgentContext, IDIDManager, IResolver } from '@veramo/core'
13
13
  import { isDefined } from '@veramo/utils'
14
14
  import { CryptoEngine, setEngine } from 'pkijs'
15
15
  import {
16
+ ExternalIdentifierCoseKeyOpts,
17
+ ExternalIdentifierCoseKeyResult,
16
18
  ExternalIdentifierDidOpts,
17
19
  ExternalIdentifierDidResult,
20
+ ExternalIdentifierJwkOpts,
21
+ ExternalIdentifierJwkResult,
18
22
  ExternalIdentifierMethod,
19
23
  ExternalIdentifierOpts,
20
24
  ExternalIdentifierResult,
21
25
  ExternalIdentifierX5cOpts,
22
26
  ExternalIdentifierX5cResult,
23
27
  ExternalJwkInfo,
28
+ isExternalIdentifierCoseKeyOpts,
24
29
  isExternalIdentifierDidOpts,
30
+ isExternalIdentifierJwkOpts,
25
31
  isExternalIdentifierJwksUrlOpts,
26
32
  isExternalIdentifierKidOpts,
27
33
  isExternalIdentifierOidcDiscoveryOpts,
@@ -39,6 +45,10 @@ export async function resolveExternalIdentifier(
39
45
  return resolveExternalDidIdentifier(opts, context)
40
46
  } else if (isExternalIdentifierX5cOpts(opts)) {
41
47
  return resolveExternalX5cIdentifier(opts, context)
48
+ } else if (isExternalIdentifierJwkOpts(opts)) {
49
+ return resolveExternalJwkIdentifier(opts, context)
50
+ } else if (isExternalIdentifierCoseKeyOpts(opts)) {
51
+ return resolveExternalCoseKeyIdentifier(opts, context)
42
52
  } else if (isExternalIdentifierKidOpts(opts)) {
43
53
  method = 'kid'
44
54
  } else if (isExternalIdentifierJwksUrlOpts(opts)) {
@@ -82,6 +92,7 @@ export async function resolveExternalX5cIdentifier(
82
92
  chain: opts.identifier,
83
93
  trustAnchors: opts.trustAnchors ?? [],
84
94
  verificationTime: opts.verificationTime,
95
+ opts,
85
96
  })
86
97
  }
87
98
  if (verificationResult.certificateChain) {
@@ -90,6 +101,7 @@ export async function resolveExternalX5cIdentifier(
90
101
  jwk: cert.publicKeyJWK,
91
102
  kid: cert.subject.dn.DN,
92
103
  jwkThumbprint: calculateJwkThumbprint({ jwk: cert.publicKeyJWK }),
104
+ publicKeyHex: jwkTtoPublicKeyHex(cert.publicKeyJWK),
93
105
  } satisfies ExternalJwkInfo
94
106
  })
95
107
  }
@@ -108,6 +120,7 @@ export async function resolveExternalX5cIdentifier(
108
120
  jwk,
109
121
  kid: getSubjectDN(cert).DN,
110
122
  jwkThumbprint: calculateJwkThumbprint({ jwk }),
123
+ publicKeyHex: jwkTtoPublicKeyHex(jwk),
111
124
  } satisfies ExternalJwkInfo
112
125
  })
113
126
  )
@@ -129,6 +142,78 @@ export async function resolveExternalX5cIdentifier(
129
142
  }
130
143
  }
131
144
 
145
+ /**
146
+ * Resolves a JWK. Normally this is just returning the JWK, but in case the JWK contains a x5c the chain is validated
147
+ * @param opts
148
+ * @param context
149
+ */
150
+ export async function resolveExternalJwkIdentifier(
151
+ opts: ExternalIdentifierJwkOpts & {
152
+ x5c?: ExternalIdentifierX5cOpts
153
+ },
154
+ context: IAgentContext<any>
155
+ ): Promise<ExternalIdentifierJwkResult> {
156
+ if (!isExternalIdentifierJwkOpts(opts)) {
157
+ return Promise.reject('External JWK Identifier args need to be provided')
158
+ }
159
+ const jwk = opts.identifier
160
+ let x5c: ExternalIdentifierX5cResult | undefined = undefined
161
+ if (jwk.x5c) {
162
+ x5c = await resolveExternalX5cIdentifier({ ...opts.x5c, identifier: jwk.x5c }, context)
163
+ }
164
+ const jwkThumbprint = calculateJwkThumbprint({ jwk })
165
+ return {
166
+ method: 'jwk',
167
+ jwk,
168
+ jwks: [
169
+ {
170
+ jwk,
171
+ jwkThumbprint,
172
+ kid: jwk.kid,
173
+ publicKeyHex: jwkTtoPublicKeyHex(jwk),
174
+ },
175
+ ],
176
+ x5c,
177
+ } satisfies ExternalIdentifierJwkResult
178
+ }
179
+
180
+ /**
181
+ * Resolves a JWK. Normally this is just returning the JWK, but in case the JWK contains a x5c the chain is validated
182
+ * @param opts
183
+ * @param context
184
+ */
185
+ export async function resolveExternalCoseKeyIdentifier(
186
+ opts: ExternalIdentifierCoseKeyOpts & {
187
+ x5c?: ExternalIdentifierX5cOpts
188
+ },
189
+ context: IAgentContext<any>
190
+ ): Promise<ExternalIdentifierCoseKeyResult> {
191
+ if (!isExternalIdentifierCoseKeyOpts(opts)) {
192
+ return Promise.reject('External Cose Key args need to be provided')
193
+ }
194
+ // TODO: We need to do cbor conversion here as well.
195
+ const coseKey = opts.identifier
196
+ let x5c: ExternalIdentifierX5cResult | undefined = undefined
197
+ if (coseKey.x5chain) {
198
+ x5c = await resolveExternalX5cIdentifier({ ...opts.x5c, identifier: coseKey.x5chain }, context)
199
+ }
200
+ const jwk = coseKeyToJwk(coseKey)
201
+ const jwkThumbprint = calculateJwkThumbprint({ jwk })
202
+ return {
203
+ method: 'cose_key',
204
+ coseKey,
205
+ jwks: [
206
+ {
207
+ jwk,
208
+ jwkThumbprint,
209
+ kid: coseKey.kid,
210
+ publicKeyHex: jwkTtoPublicKeyHex(jwk),
211
+ },
212
+ ],
213
+ x5c,
214
+ } satisfies ExternalIdentifierCoseKeyResult
215
+ }
216
+
132
217
  export async function resolveExternalDidIdentifier(
133
218
  opts: ExternalIdentifierDidOpts,
134
219
  context: IAgentContext<IResolver & IDIDManager>
@@ -163,7 +248,12 @@ export async function resolveExternalDidIdentifier(
163
248
  .flatMap((jwks) => jwks)
164
249
  )
165
250
  ).map((jwk) => {
166
- return { jwk, jwkThumbprint: calculateJwkThumbprint({ jwk }), kid: jwk.kid }
251
+ return {
252
+ jwk,
253
+ jwkThumbprint: calculateJwkThumbprint({ jwk }),
254
+ kid: jwk.kid,
255
+ publicKeyHex: jwkTtoPublicKeyHex(jwk),
256
+ }
167
257
  })
168
258
  : []
169
259
 
@@ -1,11 +1,13 @@
1
1
  import { getFirstKeyWithRelation } from '@sphereon/ssi-sdk-ext.did-utils'
2
- import { calculateJwkThumbprint, JWK, toJwk } from '@sphereon/ssi-sdk-ext.key-utils'
2
+ import { calculateJwkThumbprint, coseKeyToJwk, toJwk } from '@sphereon/ssi-sdk-ext.key-utils'
3
3
  import { pemOrDerToX509Certificate } from '@sphereon/ssi-sdk-ext.x509-utils'
4
4
  import { contextHasDidManager, contextHasKeyManager } from '@sphereon/ssi-sdk.agent-config'
5
+ import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
5
6
  import { IAgentContext, IIdentifier, IKey, IKeyManager } from '@veramo/core'
6
7
  import { CryptoEngine, setEngine } from 'pkijs'
7
8
  import {
8
9
  IIdentifierResolution,
10
+ isManagedIdentifierCoseKeyOpts,
9
11
  isManagedIdentifierDidOpts,
10
12
  isManagedIdentifierDidResult,
11
13
  isManagedIdentifierJwkOpts,
@@ -14,6 +16,8 @@ import {
14
16
  isManagedIdentifierKeyResult,
15
17
  isManagedIdentifierKidOpts,
16
18
  isManagedIdentifierX5cOpts,
19
+ ManagedIdentifierCoseKeyOpts,
20
+ ManagedIdentifierCoseKeyResult,
17
21
  ManagedIdentifierDidOpts,
18
22
  ManagedIdentifierDidResult,
19
23
  ManagedIdentifierJwkOpts,
@@ -35,6 +39,8 @@ export async function getManagedKidIdentifier(
35
39
  const method = 'kid'
36
40
  if (!contextHasKeyManager(context)) {
37
41
  return Promise.reject(Error(`Cannot get Key/JWK identifier if KeyManager plugin is not enabled!`))
42
+ } else if (opts.identifier.startsWith('did:')) {
43
+ return Promise.reject(Error(`managed kid resolution called but a did url was passed in. Please call the did resolution method`))
38
44
  }
39
45
  const key = await context.agent.keyManagerGet({ kid: opts.kmsKeyRef ?? opts.identifier })
40
46
  const jwk = toJwk(key.publicKeyHex, key.type, { key })
@@ -54,7 +60,11 @@ export async function getManagedKidIdentifier(
54
60
  } satisfies ManagedIdentifierKidResult
55
61
  }
56
62
 
57
- export function isManagedIdentifierResult(identifier: ManagedIdentifierOptsOrResult & { crypto?: Crypto }): identifier is ManagedIdentifierResult {
63
+ export function isManagedIdentifierResult(
64
+ identifier: ManagedIdentifierOptsOrResult & {
65
+ crypto?: Crypto
66
+ }
67
+ ): identifier is ManagedIdentifierResult {
58
68
  return 'key' in identifier && 'kmsKeyRef' in identifier && 'method' in identifier && 'opts' in identifier && 'jwkThumbprint' in identifier
59
69
  }
60
70
 
@@ -101,6 +111,38 @@ export async function getManagedKeyIdentifier(opts: ManagedIdentifierKeyOpts, _c
101
111
  } satisfies ManagedIdentifierKeyResult
102
112
  }
103
113
 
114
+ /**
115
+ * This function is just a convenience function to get a common result. The user already apparently had a key, so could have called the kid version as well
116
+ * @param opts
117
+ * @param context
118
+ */
119
+ export async function getManagedCoseKeyIdentifier(
120
+ opts: ManagedIdentifierCoseKeyOpts,
121
+ context: IAgentContext<any>
122
+ ): Promise<ManagedIdentifierCoseKeyResult> {
123
+ const method = 'cose_key'
124
+ const coseKey: ICoseKeyJson = opts.identifier
125
+ if (!contextHasKeyManager(context)) {
126
+ return Promise.reject(Error(`Cannot get Cose Key identifier if KeyManager plugin is not enabled!`))
127
+ }
128
+ const jwk = coseKeyToJwk(coseKey)
129
+ const jwkThumbprint = calculateJwkThumbprint({ jwk })
130
+ const key = await context.agent.keyManagerGet({ kid: opts.kmsKeyRef ?? jwkThumbprint })
131
+ const kid = opts.kid ?? coseKey.kid ?? jwkThumbprint
132
+ const issuer = opts.issuer
133
+ return {
134
+ method,
135
+ key,
136
+ identifier: opts.identifier,
137
+ jwk,
138
+ jwkThumbprint,
139
+ kid,
140
+ issuer,
141
+ kmsKeyRef: key.kid,
142
+ opts,
143
+ } satisfies ManagedIdentifierCoseKeyResult
144
+ }
145
+
104
146
  export async function getManagedDidIdentifier(opts: ManagedIdentifierDidOpts, context: IAgentContext<any>): Promise<ManagedIdentifierDidResult> {
105
147
  const method = 'did'
106
148
  if (!contextHasDidManager(context)) {
@@ -236,6 +278,8 @@ export async function getManagedIdentifier(
236
278
  resolutionResult = await getManagedX5cIdentifier(opts, context)
237
279
  } else if (isManagedIdentifierKeyOpts(opts)) {
238
280
  resolutionResult = await getManagedKeyIdentifier(opts, context)
281
+ } else if (isManagedIdentifierCoseKeyOpts(opts)) {
282
+ resolutionResult = await getManagedCoseKeyIdentifier(opts, context)
239
283
  } else {
240
284
  return Promise.reject(Error(`Could not determine identifier method. Please provide explicitly`))
241
285
  }
@@ -1,13 +1,19 @@
1
1
  import { IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap } from '@veramo/core'
2
2
  import {
3
+ ExternalIdentifierCoseKeyOpts,
4
+ ExternalIdentifierCoseKeyResult,
3
5
  ExternalIdentifierDidOpts,
4
6
  ExternalIdentifierDidResult,
7
+ ExternalIdentifierJwkOpts,
8
+ ExternalIdentifierJwkResult,
5
9
  ExternalIdentifierOpts,
6
10
  ExternalIdentifierResult,
7
11
  ExternalIdentifierX5cOpts,
8
12
  ExternalIdentifierX5cResult,
9
13
  } from './externalIdentifierTypes'
10
14
  import {
15
+ ManagedIdentifierCoseKeyOpts,
16
+ ManagedIdentifierCoseKeyResult,
11
17
  ManagedIdentifierDidOpts,
12
18
  ManagedIdentifierDidResult,
13
19
  ManagedIdentifierJwkOpts,
@@ -30,9 +36,12 @@ export const identifierResolutionContextMethods: Array<string> = [
30
36
  'identifierManagedGetByJwk',
31
37
  'identifierManagedGetByX5c',
32
38
  'identifierManagedGetByKey',
39
+ 'identifierGetManagedByCoseKey',
33
40
  'identifierExternalResolve',
34
41
  'identifierExternalResolveByDid',
35
42
  'identifierExternalResolveByX5c',
43
+ 'identifierExternalResolveByJwk',
44
+ 'identifierExternalResolveByCoseKey',
36
45
  ]
37
46
 
38
47
  /**
@@ -63,6 +72,11 @@ export interface IIdentifierResolution extends IPluginMethodMap {
63
72
 
64
73
  identifierManagedGetByKey(args: ManagedIdentifierKeyOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierKeyResult>
65
74
 
75
+ identifierManagedGetByCoseKey(
76
+ args: ManagedIdentifierCoseKeyOpts,
77
+ context: IAgentContext<IKeyManager & IIdentifierResolution>
78
+ ): Promise<ManagedIdentifierCoseKeyResult>
79
+
66
80
  // TODO: We can create a custom managed identifier method allowing developers to register a callback function to get their implementation hooked up. Needs more investigation as it would also impact the KMS
67
81
 
68
82
  /**
@@ -75,5 +89,9 @@ export interface IIdentifierResolution extends IPluginMethodMap {
75
89
 
76
90
  identifierExternalResolveByDid(args: ExternalIdentifierDidOpts, context: IAgentContext<any>): Promise<ExternalIdentifierDidResult>
77
91
 
92
+ identifierExternalResolveByJwk(args: ExternalIdentifierJwkOpts, context: IAgentContext<any>): Promise<ExternalIdentifierJwkResult>
93
+
94
+ identifierExternalResolveByCoseKey(args: ExternalIdentifierCoseKeyOpts, context: IAgentContext<any>): Promise<ExternalIdentifierCoseKeyResult>
95
+
78
96
  identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult>
79
97
  }
@@ -1,4 +1,4 @@
1
- import { JWK } from '@sphereon/ssi-sdk-ext.key-utils'
1
+ import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
2
2
  import { IIdentifier, IKey } from '@veramo/core'
3
3
  import { ExternalIdentifierType } from './externalIdentifierTypes'
4
4
  import { ManagedIdentifierType } from './managedIdentifierTypes'
@@ -42,6 +42,10 @@ export function isKeyIdentifier(identifier: ManagedIdentifierType): identifier i
42
42
  )
43
43
  }
44
44
 
45
+ export function isCoseKeyIdentifier(identifier: ManagedIdentifierType): identifier is ICoseKeyJson {
46
+ return typeof identifier === 'object' && `kty` in identifier && ('baseIV' in identifier || 'x5chain' in identifier) && !('x5c' in identifier)
47
+ }
48
+
45
49
  export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] {
46
50
  return Array.isArray(identifier) && identifier.length > 0 // todo: Do we want to do additional validation? We know it must be DER and thus hex for instance
47
51
  }
@@ -1,9 +1,18 @@
1
1
  import { DidDocumentJwks } from '@sphereon/ssi-sdk-ext.did-utils'
2
- import { JWK } from '@sphereon/ssi-sdk-ext.key-utils'
3
- import { X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
2
+ import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
3
+ import { X509CertificateChainValidationOpts, X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
4
4
  import { IParsedDID } from '@sphereon/ssi-types'
5
5
  import { DIDDocument, DIDDocumentSection, DIDResolutionResult } from '@veramo/core'
6
- import { isDidIdentifier, isJwkIdentifier, isJwksUrlIdentifier, isKidIdentifier, isOidcDiscoveryIdentifier, isX5cIdentifier, JwkInfo } from './common'
6
+ import {
7
+ isCoseKeyIdentifier,
8
+ isDidIdentifier,
9
+ isJwkIdentifier,
10
+ isJwksUrlIdentifier,
11
+ isKidIdentifier,
12
+ isOidcDiscoveryIdentifier,
13
+ isX5cIdentifier,
14
+ JwkInfo,
15
+ } from './common'
7
16
 
8
17
  /**
9
18
  * Use whenever we need to resolve an external identifier. We can pass in kids, DIDs, and x5chains
@@ -32,7 +41,13 @@ export function isExternalIdentifierDidOpts(opts: ExternalIdentifierOptsBase): o
32
41
  return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
33
42
  }
34
43
 
35
- export type ExternalIdentifierOpts = (ExternalIdentifierJwkOpts | ExternalIdentifierX5cOpts | ExternalIdentifierDidOpts | ExternalIdentifierKidOpts) &
44
+ export type ExternalIdentifierOpts = (
45
+ | ExternalIdentifierJwkOpts
46
+ | ExternalIdentifierX5cOpts
47
+ | ExternalIdentifierDidOpts
48
+ | ExternalIdentifierKidOpts
49
+ | ExternalIdentifierCoseKeyOpts
50
+ ) &
36
51
  ExternalIdentifierOptsBase
37
52
 
38
53
  export type ExternalIdentifierKidOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
@@ -48,6 +63,7 @@ export function isExternalIdentifierKidOpts(opts: ExternalIdentifierOptsBase): o
48
63
  export type ExternalIdentifierJwkOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
49
64
  method?: 'jwk'
50
65
  identifier: JWK
66
+ x5c?: ExternalIdentifierX5cOpts
51
67
  }
52
68
 
53
69
  export function isExternalIdentifierJwkOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwkOpts {
@@ -55,6 +71,16 @@ export function isExternalIdentifierJwkOpts(opts: ExternalIdentifierOptsBase): o
55
71
  return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
56
72
  }
57
73
 
74
+ export type ExternalIdentifierCoseKeyOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
75
+ method?: 'cose_key'
76
+ identifier: ICoseKeyJson
77
+ }
78
+
79
+ export function isExternalIdentifierCoseKeyOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierCoseKeyOpts {
80
+ const { identifier } = opts
81
+ return ('method' in opts && opts.method === 'cose_key') || isCoseKeyIdentifier(identifier)
82
+ }
83
+
58
84
  export type ExternalIdentifierOidcDiscoveryOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
59
85
  method?: 'oidc-discovery'
60
86
  identifier: string
@@ -75,28 +101,42 @@ export function isExternalIdentifierJwksUrlOpts(opts: ExternalIdentifierOptsBase
75
101
  return ('method' in opts && opts.method === 'oidc-discovery') || isJwksUrlIdentifier(identifier)
76
102
  }
77
103
 
78
- export type ExternalIdentifierX5cOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
79
- method?: 'x5c'
80
- identifier: string[]
81
- verify?: boolean // defaults to true
82
- verificationTime?: Date
83
- trustAnchors?: string[]
84
- }
104
+ export type ExternalIdentifierX5cOpts = Omit<ExternalIdentifierOptsBase, 'method'> &
105
+ X509CertificateChainValidationOpts & {
106
+ method?: 'x5c'
107
+ identifier: string[]
108
+ verify?: boolean // defaults to true
109
+ verificationTime?: Date
110
+ trustAnchors?: string[]
111
+ }
85
112
 
86
113
  export function isExternalIdentifierX5cOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierX5cOpts {
87
114
  const { identifier } = opts
88
115
  return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
89
116
  }
90
117
 
91
- export type ExternalIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' | 'oidc-discovery' | 'jwks-url' | 'oid4vci-issuer'
118
+ export type ExternalIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' | 'cose_key' | 'oidc-discovery' | 'jwks-url' | 'oid4vci-issuer'
92
119
 
93
- export type ExternalIdentifierResult = ExternalIdentifierDidResult | ExternalIdentifierX5cResult
120
+ export type ExternalIdentifierResult = IExternalIdentifierResultBase &
121
+ (ExternalIdentifierDidResult | ExternalIdentifierX5cResult | ExternalIdentifierJwkResult | ExternalIdentifierCoseKeyResult)
94
122
 
95
123
  export interface IExternalIdentifierResultBase {
96
124
  method: ExternalIdentifierMethod
97
125
  jwks: Array<ExternalJwkInfo>
98
126
  }
99
127
 
128
+ export interface ExternalIdentifierJwkResult extends IExternalIdentifierResultBase {
129
+ method: 'jwk'
130
+ jwk: JWK
131
+ x5c?: ExternalIdentifierX5cResult
132
+ }
133
+
134
+ export interface ExternalIdentifierCoseKeyResult extends IExternalIdentifierResultBase {
135
+ method: 'cose_key'
136
+ coseKey: ICoseKeyJson
137
+ x5c?: ExternalIdentifierX5cResult
138
+ }
139
+
100
140
  export interface ExternalIdentifierX5cResult extends IExternalIdentifierResultBase {
101
141
  method: 'x5c'
102
142
  x5c: string[]
@@ -107,6 +147,7 @@ export interface ExternalIdentifierX5cResult extends IExternalIdentifierResultBa
107
147
 
108
148
  export interface ExternalJwkInfo extends JwkInfo {
109
149
  kid?: string
150
+ publicKeyHex: string
110
151
  }
111
152
 
112
153
  export interface ExternalIdentifierDidResult extends IExternalIdentifierResultBase {