@sphereon/ssi-sdk-ext.identifier-resolution 0.24.1-unstable.93 → 0.25.1-feature.SDK.41.oidf.support.11

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 (54) hide show
  1. package/dist/agent/IdentifierResolution.d.ts +5 -0
  2. package/dist/agent/IdentifierResolution.d.ts.map +1 -1
  3. package/dist/agent/IdentifierResolution.js +31 -1
  4. package/dist/agent/IdentifierResolution.js.map +1 -1
  5. package/dist/functions/LegacySupport.d.ts +12 -0
  6. package/dist/functions/LegacySupport.d.ts.map +1 -0
  7. package/dist/functions/LegacySupport.js +39 -0
  8. package/dist/functions/LegacySupport.js.map +1 -0
  9. package/dist/functions/externalIdentifierFunctions.d.ts +17 -1
  10. package/dist/functions/externalIdentifierFunctions.d.ts.map +1 -1
  11. package/dist/functions/externalIdentifierFunctions.js +89 -6
  12. package/dist/functions/externalIdentifierFunctions.js.map +1 -1
  13. package/dist/functions/externalOIDFIdentifier.d.ts +19 -0
  14. package/dist/functions/externalOIDFIdentifier.d.ts.map +1 -0
  15. package/dist/functions/externalOIDFIdentifier.js +84 -0
  16. package/dist/functions/externalOIDFIdentifier.js.map +1 -0
  17. package/dist/functions/index.d.ts +2 -11
  18. package/dist/functions/index.d.ts.map +1 -1
  19. package/dist/functions/index.js +2 -36
  20. package/dist/functions/index.js.map +1 -1
  21. package/dist/functions/managedIdentifierFunctions.d.ts +17 -3
  22. package/dist/functions/managedIdentifierFunctions.d.ts.map +1 -1
  23. package/dist/functions/managedIdentifierFunctions.js +134 -12
  24. package/dist/functions/managedIdentifierFunctions.js.map +1 -1
  25. package/dist/tsdoc-metadata.json +1 -1
  26. package/dist/types/IIdentifierResolution.d.ts +14 -3
  27. package/dist/types/IIdentifierResolution.d.ts.map +1 -1
  28. package/dist/types/IIdentifierResolution.js +18 -0
  29. package/dist/types/IIdentifierResolution.js.map +1 -1
  30. package/dist/types/common.d.ts +4 -1
  31. package/dist/types/common.d.ts.map +1 -1
  32. package/dist/types/common.js +21 -10
  33. package/dist/types/common.js.map +1 -1
  34. package/dist/types/externalIdentifierTypes.d.ts +38 -6
  35. package/dist/types/externalIdentifierTypes.d.ts.map +1 -1
  36. package/dist/types/externalIdentifierTypes.js +16 -7
  37. package/dist/types/externalIdentifierTypes.js.map +1 -1
  38. package/dist/types/managedIdentifierTypes.d.ts +43 -15
  39. package/dist/types/managedIdentifierTypes.d.ts.map +1 -1
  40. package/dist/types/managedIdentifierTypes.js +24 -11
  41. package/dist/types/managedIdentifierTypes.js.map +1 -1
  42. package/package.json +13 -12
  43. package/plugin.schema.json +2652 -281
  44. package/src/agent/IdentifierResolution.ts +71 -11
  45. package/src/functions/LegacySupport.ts +54 -0
  46. package/src/functions/externalIdentifierFunctions.ts +101 -6
  47. package/src/functions/externalOIDFIdentifier.ts +95 -0
  48. package/src/functions/index.ts +2 -51
  49. package/src/functions/managedIdentifierFunctions.ts +162 -14
  50. package/src/types/IIdentifierResolution.ts +47 -3
  51. package/src/types/IJwtService.d.ts +226 -0
  52. package/src/types/common.ts +14 -2
  53. package/src/types/externalIdentifierTypes.ts +76 -12
  54. package/src/types/managedIdentifierTypes.ts +78 -16
@@ -1,26 +1,34 @@
1
- import {getFirstKeyWithRelation} from '@sphereon/ssi-sdk-ext.did-utils'
2
- import {calculateJwkThumbprint, JWK, toJwk} from '@sphereon/ssi-sdk-ext.key-utils'
3
- import {pemOrDerToX509Certificate} from '@sphereon/ssi-sdk-ext.x509-utils'
4
- import {contextHasDidManager, contextHasKeyManager} from '@sphereon/ssi-sdk.agent-config'
5
- import {IAgentContext, IIdentifier, IKey, IKeyManager} from '@veramo/core'
6
- import {CryptoEngine, setEngine} from 'pkijs'
1
+ import { getFirstKeyWithRelation } from '@sphereon/ssi-sdk-ext.did-utils'
2
+ import { calculateJwkThumbprint, coseKeyToJwk, toJwk } from '@sphereon/ssi-sdk-ext.key-utils'
3
+ import { pemOrDerToX509Certificate } from '@sphereon/ssi-sdk-ext.x509-utils'
4
+ import { contextHasDidManager, contextHasKeyManager } from '@sphereon/ssi-sdk.agent-config'
5
+ import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
6
+ import { IAgentContext, IIdentifier, IKey, IKeyManager } from '@veramo/core'
7
+ import { CryptoEngine, setEngine } from 'pkijs'
7
8
  import {
8
9
  IIdentifierResolution,
10
+ isManagedIdentifierCoseKeyOpts,
9
11
  isManagedIdentifierDidOpts,
10
12
  isManagedIdentifierDidResult,
13
+ isManagedIdentifierOID4VCIssuerOpts,
11
14
  isManagedIdentifierJwkOpts,
15
+ isManagedIdentifierJwkResult,
12
16
  isManagedIdentifierKeyOpts,
17
+ isManagedIdentifierKeyResult,
13
18
  isManagedIdentifierKidOpts,
14
19
  isManagedIdentifierX5cOpts,
20
+ ManagedIdentifierCoseKeyOpts,
21
+ ManagedIdentifierCoseKeyResult,
15
22
  ManagedIdentifierDidOpts,
16
23
  ManagedIdentifierDidResult,
24
+ ManagedIdentifierOID4VCIssuerOpts,
25
+ ManagedIdentifierOID4VCIssuerResult,
17
26
  ManagedIdentifierJwkOpts,
18
27
  ManagedIdentifierJwkResult,
19
28
  ManagedIdentifierKeyOpts,
20
29
  ManagedIdentifierKeyResult,
21
30
  ManagedIdentifierKidOpts,
22
31
  ManagedIdentifierKidResult,
23
- ManagedIdentifierOpts,
24
32
  ManagedIdentifierOptsOrResult,
25
33
  ManagedIdentifierResult,
26
34
  ManagedIdentifierX5cOpts,
@@ -34,6 +42,8 @@ export async function getManagedKidIdentifier(
34
42
  const method = 'kid'
35
43
  if (!contextHasKeyManager(context)) {
36
44
  return Promise.reject(Error(`Cannot get Key/JWK identifier if KeyManager plugin is not enabled!`))
45
+ } else if (opts.identifier.startsWith('did:')) {
46
+ return Promise.reject(Error(`managed kid resolution called but a did url was passed in. Please call the did resolution method`))
37
47
  }
38
48
  const key = await context.agent.keyManagerGet({ kid: opts.kmsKeyRef ?? opts.identifier })
39
49
  const jwk = toJwk(key.publicKeyHex, key.type, { key })
@@ -43,27 +53,39 @@ export async function getManagedKidIdentifier(
43
53
  return {
44
54
  method,
45
55
  key,
56
+ identifier: opts.identifier,
46
57
  jwk,
47
58
  jwkThumbprint,
48
59
  kid,
60
+ clientId: opts.clientId,
61
+ clientIdScheme: opts.clientIdScheme,
49
62
  issuer,
50
63
  kmsKeyRef: key.kid,
51
64
  opts,
52
65
  } satisfies ManagedIdentifierKidResult
53
66
  }
54
67
 
68
+ export function isManagedIdentifierResult(
69
+ identifier: ManagedIdentifierOptsOrResult & {
70
+ crypto?: Crypto
71
+ }
72
+ ): identifier is ManagedIdentifierResult {
73
+ return 'key' in identifier && 'kmsKeyRef' in identifier && 'method' in identifier && 'opts' in identifier && 'jwkThumbprint' in identifier
74
+ }
75
+
55
76
  /**
56
77
  * Allows to get a managed identifier result in case identifier options are passed in, but returns the identifier directly in case results are passed in. This means resolution can have happened before, or happens in this method
57
78
  * @param identifier
58
79
  * @param context
59
80
  */
60
81
  export async function ensureManagedIdentifierResult(
61
- identifier: ManagedIdentifierOptsOrResult,
62
- context: IAgentContext<IIdentifierResolution>
82
+ identifier: ManagedIdentifierOptsOrResult & {
83
+ crypto?: Crypto
84
+ },
85
+ context: IAgentContext<IKeyManager>
63
86
  ): Promise<ManagedIdentifierResult> {
64
- return 'key' in identifier && 'kmsKeyRef' in identifier && 'method' in identifier && 'opts' in identifier
65
- ? identifier
66
- : await context.agent.identifierManagedGet(identifier)
87
+ const { lazyDisabled = false } = identifier
88
+ return !lazyDisabled && isManagedIdentifierResult(identifier) ? identifier : await getManagedIdentifier(identifier, context)
67
89
  }
68
90
 
69
91
  /**
@@ -84,15 +106,52 @@ export async function getManagedKeyIdentifier(opts: ManagedIdentifierKeyOpts, _c
84
106
  return {
85
107
  method,
86
108
  key,
109
+ identifier: key,
87
110
  jwk,
88
111
  jwkThumbprint,
89
112
  kid,
90
113
  issuer,
91
114
  kmsKeyRef: key.kid,
115
+ clientId: opts.clientId,
116
+ clientIdScheme: opts.clientIdScheme,
92
117
  opts,
93
118
  } satisfies ManagedIdentifierKeyResult
94
119
  }
95
120
 
121
+ /**
122
+ * 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
123
+ * @param opts
124
+ * @param context
125
+ */
126
+ export async function getManagedCoseKeyIdentifier(
127
+ opts: ManagedIdentifierCoseKeyOpts,
128
+ context: IAgentContext<any>
129
+ ): Promise<ManagedIdentifierCoseKeyResult> {
130
+ const method = 'cose_key'
131
+ const coseKey: ICoseKeyJson = opts.identifier
132
+ if (!contextHasKeyManager(context)) {
133
+ return Promise.reject(Error(`Cannot get Cose Key identifier if KeyManager plugin is not enabled!`))
134
+ }
135
+ const jwk = coseKeyToJwk(coseKey)
136
+ const jwkThumbprint = calculateJwkThumbprint({ jwk })
137
+ const key = await context.agent.keyManagerGet({ kid: opts.kmsKeyRef ?? jwkThumbprint })
138
+ const kid = opts.kid ?? coseKey.kid ?? jwkThumbprint
139
+ const issuer = opts.issuer
140
+ return {
141
+ method,
142
+ key,
143
+ identifier: opts.identifier,
144
+ jwk,
145
+ jwkThumbprint,
146
+ kid,
147
+ issuer,
148
+ kmsKeyRef: key.kid,
149
+ clientId: opts.clientId,
150
+ clientIdScheme: opts.clientIdScheme,
151
+ opts,
152
+ } satisfies ManagedIdentifierCoseKeyResult
153
+ }
154
+
96
155
  export async function getManagedDidIdentifier(opts: ManagedIdentifierDidOpts, context: IAgentContext<any>): Promise<ManagedIdentifierDidResult> {
97
156
  const method = 'did'
98
157
  if (!contextHasDidManager(context)) {
@@ -139,6 +198,8 @@ export async function getManagedDidIdentifier(opts: ManagedIdentifierDidOpts, co
139
198
  keys,
140
199
  issuer,
141
200
  identifier,
201
+ clientId: opts.clientId,
202
+ clientIdScheme: opts.clientIdScheme,
142
203
  opts,
143
204
  }
144
205
  }
@@ -160,10 +221,13 @@ export async function getManagedJwkIdentifier(
160
221
  method,
161
222
  key,
162
223
  kmsKeyRef: key.kid,
224
+ identifier: jwk,
163
225
  jwk,
164
226
  jwkThumbprint,
165
227
  kid,
166
228
  issuer,
229
+ clientId: opts.clientId,
230
+ clientIdScheme: opts.clientIdScheme,
167
231
  opts,
168
232
  } satisfies ManagedIdentifierJwkResult
169
233
  }
@@ -195,6 +259,7 @@ export async function getManagedX5cIdentifier(
195
259
  return {
196
260
  method,
197
261
  x5c,
262
+ identifier: x5c,
198
263
  certificate,
199
264
  jwk,
200
265
  jwkThumbprint,
@@ -202,17 +267,65 @@ export async function getManagedX5cIdentifier(
202
267
  kmsKeyRef: key.kid,
203
268
  kid,
204
269
  issuer,
270
+ clientId: opts.clientId,
271
+ clientIdScheme: opts.clientIdScheme,
205
272
  opts,
206
273
  } satisfies ManagedIdentifierX5cResult
207
274
  }
208
275
 
276
+ export async function getManagedOID4VCIssuerIdentifier(
277
+ opts: ManagedIdentifierOID4VCIssuerOpts,
278
+ context: IAgentContext<IKeyManager>
279
+ ): Promise<ManagedIdentifierOID4VCIssuerResult> {
280
+ const { identifier } = opts
281
+ const method = 'oid4vci-issuer'
282
+ // FIXME: We need to eventually determine the JWK based on the issuer. Using a dummy JWK for now
283
+ const jwk = {
284
+ "kty" : "RSA",
285
+ "kid" : "dummy-jwk-for-vci-issuer-signing",
286
+ "use" : "sig",
287
+ "n" : "pjdss8ZaDfEH6K6U7GeW2nxDqR4IP049fk1fK0lndimbMMVBdPv_hSpm8T8EtBDxrUdi1OHZfMhUixGaut-3nQ4GG9nM249oxhCtxqqNvEXrmQRGqczyLxuh-fKn9Fg--hS9UpazHpfVAFnB5aCfXoNhPuI8oByyFKMKaOVgHNqP5NBEqabiLftZD3W_lsFCPGuzr4Vp0YS7zS2hDYScC2oOMu4rGU1LcMZf39p3153Cq7bS2Xh6Y-vw5pwzFYZdjQxDn8x8BG3fJ6j8TGLXQsbKH1218_HcUJRvMwdpbUQG5nvA2GXVqLqdwp054Lzk9_B_f1lVrmOKuHjTNHq48w",
288
+ "e" : "AQAB",
289
+ "d" : "ksDmucdMJXkFGZxiomNHnroOZxe8AmDLDGO1vhs-POa5PZM7mtUPonxwjVmthmpbZzla-kg55OFfO7YcXhg-Hm2OWTKwm73_rLh3JavaHjvBqsVKuorX3V3RYkSro6HyYIzFJ1Ek7sLxbjDRcDOj4ievSX0oN9l-JZhaDYlPlci5uJsoqro_YrE0PRRWVhtGynd-_aWgQv1YzkfZuMD-hJtDi1Im2humOWxA4eZrFs9eG-whXcOvaSwO4sSGbS99ecQZHM2TcdXeAs1PvjVgQ_dKnZlGN3lTWoWfQP55Z7Tgt8Nf1q4ZAKd-NlMe-7iqCFfsnFwXjSiaOa2CRGZn-Q",
290
+ "p" : "4A5nU4ahEww7B65yuzmGeCUUi8ikWzv1C81pSyUKvKzu8CX41hp9J6oRaLGesKImYiuVQK47FhZ--wwfpRwHvSxtNU9qXb8ewo-BvadyO1eVrIk4tNV543QlSe7pQAoJGkxCia5rfznAE3InKF4JvIlchyqs0RQ8wx7lULqwnn0",
291
+ "q" : "ven83GM6SfrmO-TBHbjTk6JhP_3CMsIvmSdo4KrbQNvp4vHO3w1_0zJ3URkmkYGhz2tgPlfd7v1l2I6QkIh4Bumdj6FyFZEBpxjE4MpfdNVcNINvVj87cLyTRmIcaGxmfylY7QErP8GFA-k4UoH_eQmGKGK44TRzYj5hZYGWIC8",
292
+ "dp" : "lmmU_AG5SGxBhJqb8wxfNXDPJjf__i92BgJT2Vp4pskBbr5PGoyV0HbfUQVMnw977RONEurkR6O6gxZUeCclGt4kQlGZ-m0_XSWx13v9t9DIbheAtgVJ2mQyVDvK4m7aRYlEceFh0PsX8vYDS5o1txgPwb3oXkPTtrmbAGMUBpE",
293
+ "dq" : "mxRTU3QDyR2EnCv0Nl0TCF90oliJGAHR9HJmBe__EjuCBbwHfcT8OG3hWOv8vpzokQPRl5cQt3NckzX3fs6xlJN4Ai2Hh2zduKFVQ2p-AF2p6Yfahscjtq-GY9cB85NxLy2IXCC0PF--Sq9LOrTE9QV988SJy_yUrAjcZ5MmECk",
294
+ "qi" : "ldHXIrEmMZVaNwGzDF9WG8sHj2mOZmQpw9yrjLK9hAsmsNr5LTyqWAqJIYZSwPTYWhY4nu2O0EY9G9uYiqewXfCKw_UngrJt8Xwfq1Zruz0YY869zPN4GiE9-9rzdZB33RBw8kIOquY3MK74FMwCihYx_LiU2YTHkaoJ3ncvtvg"
295
+ } as JWK
296
+ const jwkThumbprint = calculateJwkThumbprint({ jwk })
297
+
298
+ const key = {
299
+ kid: 'dummy-key-for-vci-issuer-signing',
300
+ kms: 'local',
301
+ type: "RSA",
302
+ publicKeyHex: '9a3f75b2e4d8b91128fc6e9a8f6782e5a4f1cba3718e58b5d0a789d6e5f52b3a'
303
+ } as IKey
304
+
305
+ return {
306
+ method,
307
+ identifier,
308
+ jwk,
309
+ jwkThumbprint,
310
+ key, // FIXME: We need construct a key as soon as we have the external VCI Issuer resolution
311
+ kmsKeyRef: identifier, // FIXME: We need use kmsKeyRef as soon as we have the external VCI Issuer resolution
312
+ issuer: identifier.replace('/.well-known/openid-credential-issuer', ''),
313
+ clientId: opts.clientId,
314
+ clientIdScheme: opts.clientIdScheme,
315
+ opts,
316
+ } satisfies ManagedIdentifierOID4VCIssuerResult
317
+ }
318
+
209
319
  export async function getManagedIdentifier(
210
- opts: ManagedIdentifierOpts & {
320
+ opts: ManagedIdentifierOptsOrResult & {
211
321
  crypto?: Crypto
212
322
  },
213
323
  context: IAgentContext<IKeyManager>
214
324
  ): Promise<ManagedIdentifierResult> {
215
325
  let resolutionResult: ManagedIdentifierResult
326
+ if (isManagedIdentifierResult(opts)) {
327
+ opts
328
+ }
216
329
  if (isManagedIdentifierKidOpts(opts)) {
217
330
  resolutionResult = await getManagedKidIdentifier(opts, context)
218
331
  } else if (isManagedIdentifierDidOpts(opts)) {
@@ -223,13 +336,48 @@ export async function getManagedIdentifier(
223
336
  resolutionResult = await getManagedX5cIdentifier(opts, context)
224
337
  } else if (isManagedIdentifierKeyOpts(opts)) {
225
338
  resolutionResult = await getManagedKeyIdentifier(opts, context)
339
+ } else if (isManagedIdentifierCoseKeyOpts(opts)) {
340
+ resolutionResult = await getManagedCoseKeyIdentifier(opts, context)
341
+ } else if (isManagedIdentifierOID4VCIssuerOpts(opts)) {
342
+ resolutionResult = await getManagedOID4VCIssuerIdentifier(opts, context)
226
343
  } else {
227
344
  return Promise.reject(Error(`Could not determine identifier method. Please provide explicitly`))
228
345
  }
229
346
  const { key } = resolutionResult
230
- if (!key || (isManagedIdentifierDidOpts(opts) && isManagedIdentifierDidResult(resolutionResult) && !resolutionResult.identifier)) {
347
+ if ((!key && !isManagedIdentifierOID4VCIssuerOpts(opts)) || (isManagedIdentifierDidOpts(opts) && isManagedIdentifierDidResult(resolutionResult) && !resolutionResult.identifier)) {
231
348
  console.log(`Cannot find identifier`, opts.identifier)
232
349
  return Promise.reject(`Cannot find identifier ${opts.identifier}`)
233
350
  }
234
351
  return resolutionResult
235
352
  }
353
+
354
+ export async function managedIdentifierToKeyResult(
355
+ identifier: ManagedIdentifierOptsOrResult,
356
+ context: IAgentContext<IIdentifierResolution & IKeyManager>
357
+ ): Promise<ManagedIdentifierKeyResult> {
358
+ const resolved = await ensureManagedIdentifierResult(identifier, context)
359
+ if (isManagedIdentifierKeyResult(resolved)) {
360
+ return resolved
361
+ }
362
+
363
+ return {
364
+ ...resolved,
365
+ method: 'key',
366
+ identifier: resolved.key,
367
+ } satisfies ManagedIdentifierKeyResult
368
+ }
369
+
370
+ export async function managedIdentifierToJwk(
371
+ identifier: ManagedIdentifierOptsOrResult,
372
+ context: IAgentContext<IIdentifierResolution & IKeyManager>
373
+ ): Promise<ManagedIdentifierJwkResult> {
374
+ const resolved = await ensureManagedIdentifierResult(identifier, context)
375
+ if (isManagedIdentifierJwkResult(resolved)) {
376
+ return resolved
377
+ }
378
+ return {
379
+ ...resolved,
380
+ method: 'jwk',
381
+ identifier: resolved.jwk,
382
+ } satisfies ManagedIdentifierJwkResult
383
+ }
@@ -1,26 +1,53 @@
1
1
  import { IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap } from '@veramo/core'
2
2
  import {
3
+ ExternalIdentifierCoseKeyOpts,
4
+ ExternalIdentifierCoseKeyResult,
3
5
  ExternalIdentifierDidOpts,
4
- ExternalIdentifierDidResult,
6
+ ExternalIdentifierDidResult, ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult,
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,
19
+ ManagedIdentifierOID4VCIssuerOpts,
20
+ ManagedIdentifierOID4VCIssuerResult,
13
21
  ManagedIdentifierJwkOpts,
14
22
  ManagedIdentifierJwkResult,
15
23
  ManagedIdentifierKeyOpts,
16
24
  ManagedIdentifierKeyResult,
17
25
  ManagedIdentifierKidOpts,
18
26
  ManagedIdentifierKidResult,
19
- ManagedIdentifierOpts,
27
+ ManagedIdentifierOptsOrResult,
20
28
  ManagedIdentifierResult,
21
29
  ManagedIdentifierX5cOpts,
22
30
  ManagedIdentifierX5cResult,
23
31
  } from './managedIdentifierTypes'
32
+ import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
33
+
34
+ // Exposing the methods here for any REST implementation
35
+ export const identifierResolutionContextMethods: Array<string> = [
36
+ 'identifierManagedGet',
37
+ 'identifierManagedGetByDid',
38
+ 'identifierManagedGetByKid',
39
+ 'identifierManagedGetByJwk',
40
+ 'identifierManagedGetByX5c',
41
+ 'identifierManagedGetByKey',
42
+ 'identifierManagedGetByOID4VCIssuer',
43
+ 'identifierGetManagedByCoseKey',
44
+ 'identifierExternalResolve',
45
+ 'identifierExternalResolveByDid',
46
+ 'identifierExternalResolveByX5c',
47
+ 'identifierExternalResolveByJwk',
48
+ 'identifierExternalResolveByCoseKey',
49
+ 'identifierExternalResolveByOIDFEntityId',
50
+ ]
24
51
 
25
52
  /**
26
53
  * @public
@@ -30,11 +57,15 @@ export interface IIdentifierResolution extends IPluginMethodMap {
30
57
  * Main method for managed identifiers. We always go through this method (also the others) as we want to integrate a plugin for anomaly detection. Having a single method helps
31
58
  *
32
59
  * The end result of all these methods is a common baseline response that allows to use a key from the registered KMS systems. It also provides kid and iss(uer) values that can be used in a JWT/JWS for instance
60
+ * Allows to get a managed identifier result in case identifier options are passed in, but returns the identifier directly in case results are passed in. This means resolution can have happened before, or happens in this method
61
+ *
62
+ * We use the opts or result type almost everywhere, as it allows for just in time resolution whenever this method is called and afterwards we have the result, so resolution doesn't have to hit the DB, or external endpoints.
63
+ * Also use this method in the local agent, not using REST. If case the identifier needs to be resolved, you can always have the above methods using REST
33
64
  * @param args
34
65
  * @param context
35
66
  * @public
36
67
  */
37
- identifierManagedGet(args: ManagedIdentifierOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierResult>
68
+ identifierManagedGet(args: ManagedIdentifierOptsOrResult, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierResult>
38
69
 
39
70
  identifierManagedGetByDid(args: ManagedIdentifierDidOpts, context: IAgentContext<IKeyManager & IDIDManager>): Promise<ManagedIdentifierDidResult>
40
71
 
@@ -46,6 +77,13 @@ export interface IIdentifierResolution extends IPluginMethodMap {
46
77
 
47
78
  identifierManagedGetByKey(args: ManagedIdentifierKeyOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierKeyResult>
48
79
 
80
+ identifierManagedGetByCoseKey(
81
+ args: ManagedIdentifierCoseKeyOpts,
82
+ context: IAgentContext<IKeyManager & IIdentifierResolution>
83
+ ): Promise<ManagedIdentifierCoseKeyResult>
84
+
85
+ identifierManagedGetByOID4VCIssuer(args: ManagedIdentifierOID4VCIssuerOpts, context: IAgentContext<any>): Promise<ManagedIdentifierOID4VCIssuerResult>
86
+
49
87
  // 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
50
88
 
51
89
  /**
@@ -58,5 +96,11 @@ export interface IIdentifierResolution extends IPluginMethodMap {
58
96
 
59
97
  identifierExternalResolveByDid(args: ExternalIdentifierDidOpts, context: IAgentContext<any>): Promise<ExternalIdentifierDidResult>
60
98
 
99
+ identifierExternalResolveByJwk(args: ExternalIdentifierJwkOpts, context: IAgentContext<any>): Promise<ExternalIdentifierJwkResult>
100
+
101
+ identifierExternalResolveByCoseKey(args: ExternalIdentifierCoseKeyOpts, context: IAgentContext<any>): Promise<ExternalIdentifierCoseKeyResult>
102
+
61
103
  identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult>
104
+
105
+ identifierExternalResolveByOIDFEntityId(args: ExternalIdentifierOIDFEntityIdOpts, context: IAgentContext<IOIDFClient>): Promise<ExternalIdentifierOIDFEntityIdResult>
62
106
  }
@@ -0,0 +1,226 @@
1
+
2
+ // Copy of jwt-service typings since we cannot include that as devDependency due to cyclic dep
3
+
4
+ import { ExternalIdentifierDidOpts, ExternalIdentifierResult, ExternalIdentifierX5cOpts, IIdentifierResolution, ManagedIdentifierOptsOrResult, ManagedIdentifierResult } from '@sphereon/ssi-sdk-ext.identifier-resolution';
5
+ import { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils';
6
+ import { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types';
7
+ import { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core';
8
+ export type IRequiredContext = IAgentContext<IIdentifierResolution & IKeyManager>;
9
+ export declare const jwtServiceContextMethods: Array<string>;
10
+ export interface IJwtService extends IPluginMethodMap {
11
+ jwtPrepareJws(args: CreateJwsJsonArgs, context: IRequiredContext): Promise<PreparedJwsObject>;
12
+ jwtCreateJwsJsonGeneralSignature(args: CreateJwsJsonArgs, context: IRequiredContext): Promise<JwsJsonGeneral>;
13
+ jwtCreateJwsJsonFlattenedSignature(args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise<JwsJsonFlattened>;
14
+ jwtCreateJwsCompactSignature(args: CreateJwsCompactArgs, context: IRequiredContext): Promise<JwtCompactResult>;
15
+ jwtVerifyJwsSignature(args: VerifyJwsArgs, context: IRequiredContext): Promise<IJwsValidationResult>;
16
+ jwtEncryptJweCompactJwt(args: EncryptJweCompactJwtArgs, context: IRequiredContext): Promise<JwtCompactResult>;
17
+ jwtDecryptJweCompactJwt(args: DecryptJweCompactJwtArgs, context: IRequiredContext): Promise<JwtCompactResult>;
18
+ }
19
+ export type IJwsValidationResult = IValidationResult & {
20
+ jws: JwsJsonGeneralWithIdentifiers;
21
+ };
22
+ export interface PreparedJws {
23
+ protectedHeader: JwsHeader;
24
+ payload: Uint8Array;
25
+ unprotectedHeader?: JwsHeader;
26
+ existingSignatures?: Array<JwsJsonSignature>;
27
+ }
28
+ export interface JwsJsonSignature {
29
+ protected: string;
30
+ header?: JwsHeader;
31
+ signature: string;
32
+ }
33
+ /**
34
+ * The JWK representation of an ephemeral public key.
35
+ * See https://www.rfc-editor.org/rfc/rfc7518.html#section-6
36
+ */
37
+ export type EphemeralPublicKey = Omit<BaseJWK, 'alg'>;
38
+ export interface JweHeader extends Omit<BaseJwtHeader, 'alg'> {
39
+ alg: string;
40
+ enc: string;
41
+ jku?: string;
42
+ jwk?: BaseJWK;
43
+ epk?: EphemeralPublicKey;
44
+ x5u?: string;
45
+ x5c?: string[];
46
+ x5t?: string;
47
+ cty?: string;
48
+ crit?: string[];
49
+ [k: string]: any;
50
+ }
51
+ export interface JweRecipientUnprotectedHeader {
52
+ alg: string;
53
+ iv: string;
54
+ tag: string;
55
+ epk?: EphemeralPublicKey;
56
+ kid?: string;
57
+ apv?: string;
58
+ apu?: string;
59
+ }
60
+ export interface JweProtectedHeader extends Partial<JweHeader> {
61
+ zip?: 'DEF' | string;
62
+ }
63
+ export type Jws = JwsCompact | JwsJsonFlattened | JwsJsonGeneral;
64
+ export type JwsCompact = string;
65
+ export interface JwsJsonFlattened {
66
+ payload: string;
67
+ protected: string;
68
+ header?: JwsHeader;
69
+ signature: string;
70
+ }
71
+ export interface JwsJsonGeneral {
72
+ payload: string;
73
+ signatures: Array<JwsJsonSignature>;
74
+ }
75
+ export interface JwsJsonGeneralWithIdentifiers extends JwsJsonGeneral {
76
+ signatures: Array<JwsJsonSignatureWithIdentifier>;
77
+ }
78
+ export interface JwsJsonSignatureWithIdentifier extends JwsJsonSignature {
79
+ identifier: ExternalIdentifierResult;
80
+ publicKeyHex: string;
81
+ }
82
+ export type Jwe = JweCompact | JweJsonFlattened | JweJsonGeneral;
83
+ export type JweCompact = string;
84
+ export interface JweJsonFlattened {
85
+ protected: string;
86
+ unprotected: JweHeader;
87
+ header: JweHeader | JweRecipientUnprotectedHeader;
88
+ encrypted_key?: string;
89
+ aad?: string;
90
+ iv: string;
91
+ ciphertext: string;
92
+ tag?: string;
93
+ }
94
+ export interface JweRecipient {
95
+ header?: JweRecipientUnprotectedHeader;
96
+ encrypted_key?: string;
97
+ }
98
+ export interface JweJsonGeneral {
99
+ protected: string;
100
+ unprotected?: JweHeader;
101
+ recipients: Array<JweRecipient>;
102
+ aad?: string;
103
+ iv: string;
104
+ ciphertext: string;
105
+ tag?: string;
106
+ }
107
+ export interface PreparedJwsObject {
108
+ jws: PreparedJws;
109
+ b64: {
110
+ payload: string;
111
+ protectedHeader: string;
112
+ };
113
+ identifier: ManagedIdentifierResult;
114
+ }
115
+ export interface BaseJwtHeader {
116
+ typ?: string;
117
+ alg?: string;
118
+ kid?: string;
119
+ }
120
+ export interface BaseJwtPayload {
121
+ iss?: string;
122
+ sub?: string;
123
+ aud?: string[] | string;
124
+ exp?: number;
125
+ nbf?: number;
126
+ iat?: number;
127
+ jti?: string;
128
+ }
129
+ export interface JwsHeader extends BaseJwtHeader {
130
+ kid?: string;
131
+ jwk?: JWK;
132
+ x5c?: string[];
133
+ [key: string]: unknown;
134
+ }
135
+ export interface JwsPayload extends BaseJwtPayload {
136
+ [key: string]: unknown;
137
+ }
138
+ export interface JwsHeaderOpts {
139
+ alg: JoseSignatureAlgorithm | JoseSignatureAlgorithmString;
140
+ }
141
+ export type JwsIdentifierMode = 'x5c' | 'kid' | 'jwk' | 'did' | 'auto';
142
+ export type EncryptJweCompactJwtArgs = {
143
+ payload: JwsPayload;
144
+ protectedHeader?: JweProtectedHeader | undefined;
145
+ aad?: Uint8Array | undefined;
146
+ recipientKey: ExternalIdentifierResult & {
147
+ kid?: string;
148
+ };
149
+ alg?: JweAlg;
150
+ enc?: JweEnc;
151
+ apu?: string;
152
+ apv?: string;
153
+ expirationTime?: number | string | Date;
154
+ issuer?: string;
155
+ audience?: string | string[];
156
+ };
157
+ export type DecryptJweCompactJwtArgs = {
158
+ jwe: JweCompact;
159
+ idOpts: ManagedIdentifierOptsOrResult;
160
+ };
161
+ export type CreateJwsArgs = {
162
+ mode?: JwsIdentifierMode;
163
+ issuer: ManagedIdentifierOptsOrResult & {
164
+ noIssPayloadUpdate?: boolean;
165
+ noIdentifierInHeader?: boolean;
166
+ };
167
+ clientId?: string;
168
+ clientIdScheme?: ClientIdScheme | 'did' | string;
169
+ protectedHeader: JwsHeader;
170
+ payload: JwsPayload | Uint8Array | string;
171
+ };
172
+ export type CreateJweArgs = {
173
+ mode?: JwsIdentifierMode;
174
+ issuer: ManagedIdentifierOptsOrResult & {
175
+ noIssPayloadUpdate?: boolean;
176
+ noIdentifierInHeader?: boolean;
177
+ };
178
+ protectedHeader: JweProtectedHeader;
179
+ encryptedKey: string | EphemeralPublicKey;
180
+ iv: string;
181
+ ciphertext: string;
182
+ tag: string;
183
+ };
184
+ export type CreateJwsCompactArgs = CreateJwsArgs;
185
+ export type CreateJwsFlattenedArgs = Exclude<CreateJwsJsonArgs, 'existingSignatures'>;
186
+ export type VerifyJwsArgs = {
187
+ jws: Jws;
188
+ jwk?: JWK;
189
+ opts?: {
190
+ x5c?: Omit<ExternalIdentifierX5cOpts, 'identifier'>;
191
+ did?: Omit<ExternalIdentifierDidOpts, 'identifier'>;
192
+ };
193
+ };
194
+ /**
195
+ * @public
196
+ */
197
+ export type CreateJwsJsonArgs = CreateJwsArgs & {
198
+ unprotectedHeader?: JwsHeader;
199
+ existingSignatures?: Array<JwsJsonSignature>;
200
+ };
201
+ export type CreateJweJsonArgs = CreateJweArgs & {
202
+ unprotectedHeader?: JweHeader;
203
+ };
204
+ /**
205
+ * @public
206
+ */
207
+ export interface JwtCompactResult {
208
+ jwt: JwsCompact | JweCompact;
209
+ }
210
+ export declare function isJwsCompact(jws: Jws): jws is JwsCompact;
211
+ export declare function isJweCompact(jwe: Jwe): jwe is JweCompact;
212
+ export declare function isJwsJsonFlattened(jws: Jws): jws is JwsJsonFlattened;
213
+ export declare function isJwsJsonGeneral(jws: Jws): jws is JwsJsonGeneral;
214
+ export declare function isJweJsonFlattened(jwe: Jwe): jwe is JweJsonFlattened;
215
+ export declare function isJweJsonGeneral(jwe: Jwe): jwe is JweJsonGeneral;
216
+ export declare function isJwsHeader(header: BaseJwtHeader & Record<string, any>): header is JwsHeader;
217
+ export declare function isJweHeader(header: BaseJwtHeader & Record<string, any>): header is JweHeader;
218
+ export declare const COMPACT_JWS_REGEX: RegExp;
219
+ export declare const COMPACT_JWE_REGEX: RegExp;
220
+ export declare const JweAlgs: readonly ["RSA1_5", "RSA-OAEP", "RSA-OAEP-256", "A128KW", "A192KW", "A256KW", "dir", "ECDH-ES", "ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW", "A128GCMKW", "A192GCMKW", "A256GCMKW", "PBES2-HS256+A128KW", "PBES2-HS384+A192KW", "PBES2-HS512+A256KW"];
221
+ export type JweAlg = typeof JweAlgs[number];
222
+ export declare function jweAlg(alg?: string | JweAlg): JweAlg | undefined;
223
+ export declare const JweEncs: readonly ["A128CBC-HS256", "A192CBC-HS384", "A256CBC-HS512", "A128GCM", "A192GCM", "A256GCM"];
224
+ export type JweEnc = typeof JweEncs[number];
225
+ export declare function jweEnc(alg?: string | JweEnc): JweEnc | undefined;
226
+ //# sourceMappingURL=IJwtService.d.ts.map
@@ -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'
@@ -29,7 +29,11 @@ export function isJwksUrlIdentifier(identifier: ManagedIdentifierType | External
29
29
  }
30
30
 
31
31
  export function isKidIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
32
- return typeof identifier === 'string' && !identifier.startsWith('did:')
32
+ return typeof identifier === 'string' && !identifier.startsWith('did:') && !identifier.startsWith('http')
33
+ }
34
+
35
+ export function isOID4VCIssuerIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
36
+ return typeof identifier === 'string' && identifier.startsWith('http') && identifier.endsWith('/.well-known/openid-credential-issuer')
33
37
  }
34
38
 
35
39
  export function isKeyIdentifier(identifier: ManagedIdentifierType): identifier is IKey {
@@ -42,6 +46,14 @@ export function isKeyIdentifier(identifier: ManagedIdentifierType): identifier i
42
46
  )
43
47
  }
44
48
 
49
+ export function isCoseKeyIdentifier(identifier: ManagedIdentifierType): identifier is ICoseKeyJson {
50
+ return typeof identifier === 'object' && `kty` in identifier && ('baseIV' in identifier || 'x5chain' in identifier) && !('x5c' in identifier)
51
+ }
52
+
53
+ export function isOIDFEntityIdIdentifier(identifier: ManagedIdentifierType): identifier is ICoseKeyJson {
54
+ return typeof identifier === 'string' && identifier.startsWith('https://')
55
+ }
56
+
45
57
  export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] {
46
58
  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
59
  }