@sphereon/ssi-sdk-ext.identifier-resolution 0.24.1-unstable.75 → 0.24.1-unstable.76

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 (48) hide show
  1. package/README.md +380 -1
  2. package/dist/agent/IdentifierResolution.d.ts +9 -1
  3. package/dist/agent/IdentifierResolution.d.ts.map +1 -1
  4. package/dist/agent/IdentifierResolution.js +22 -3
  5. package/dist/agent/IdentifierResolution.js.map +1 -1
  6. package/dist/functions/externalIdentifierFunctions.d.ts +10 -0
  7. package/dist/functions/externalIdentifierFunctions.d.ts.map +1 -0
  8. package/dist/functions/externalIdentifierFunctions.js +167 -0
  9. package/dist/functions/externalIdentifierFunctions.js.map +1 -0
  10. package/dist/functions/index.d.ts +2 -12
  11. package/dist/functions/index.d.ts.map +1 -1
  12. package/dist/functions/index.js +15 -237
  13. package/dist/functions/index.js.map +1 -1
  14. package/dist/functions/managedIdentifierFunctions.d.ts +6 -0
  15. package/dist/functions/managedIdentifierFunctions.d.ts.map +1 -0
  16. package/dist/functions/managedIdentifierFunctions.js +96 -0
  17. package/dist/functions/managedIdentifierFunctions.js.map +1 -0
  18. package/dist/types/IIdentifierResolution.d.ts +18 -159
  19. package/dist/types/IIdentifierResolution.d.ts.map +1 -1
  20. package/dist/types/IIdentifierResolution.js +0 -95
  21. package/dist/types/IIdentifierResolution.js.map +1 -1
  22. package/dist/types/common.d.ts +16 -0
  23. package/dist/types/common.d.ts.map +1 -0
  24. package/dist/types/common.js +32 -0
  25. package/dist/types/common.js.map +1 -0
  26. package/dist/types/externalIdentifierTypes.d.ts +80 -0
  27. package/dist/types/externalIdentifierTypes.d.ts.map +1 -0
  28. package/dist/types/externalIdentifierTypes.js +35 -0
  29. package/dist/types/externalIdentifierTypes.js.map +1 -0
  30. package/dist/types/index.d.ts +5 -0
  31. package/dist/types/index.d.ts.map +1 -0
  32. package/dist/types/index.js +21 -0
  33. package/dist/types/index.js.map +1 -0
  34. package/dist/types/managedIdentifierTypes.d.ts +73 -0
  35. package/dist/types/managedIdentifierTypes.d.ts.map +1 -0
  36. package/dist/types/managedIdentifierTypes.js +41 -0
  37. package/dist/types/managedIdentifierTypes.js.map +1 -0
  38. package/package.json +13 -11
  39. package/plugin.schema.json +849 -100
  40. package/src/agent/IdentifierResolution.ts +31 -8
  41. package/src/functions/externalIdentifierFunctions.ts +183 -0
  42. package/src/functions/index.ts +2 -267
  43. package/src/functions/managedIdentifierFunctions.ts +105 -0
  44. package/src/types/IIdentifierResolution.ts +35 -278
  45. package/src/types/common.ts +37 -0
  46. package/src/types/externalIdentifierTypes.ts +119 -0
  47. package/src/types/index.ts +4 -0
  48. package/src/types/managedIdentifierTypes.ts +121 -0
@@ -1,24 +1,35 @@
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'
4
- import { IParsedDID } from '@sphereon/ssi-types'
1
+ import { IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap } from '@veramo/core'
5
2
  import {
6
- DIDDocument,
7
- DIDDocumentSection,
8
- DIDResolutionResult,
9
- IAgentContext,
10
- IDIDManager,
11
- IIdentifier,
12
- IKey,
13
- IKeyManager,
14
- IPluginMethodMap,
15
- TKeyType,
16
- } from '@veramo/core'
3
+ ExternalIdentifierDidOpts,
4
+ ExternalIdentifierDidResult,
5
+ ExternalIdentifierOpts,
6
+ ExternalIdentifierResult,
7
+ ExternalIdentifierX5cOpts,
8
+ ExternalIdentifierX5cResult,
9
+ } from './externalIdentifierTypes'
10
+ import {
11
+ ManagedIdentifierDidOpts,
12
+ ManagedIdentifierDidResult,
13
+ ManagedIdentifierJwkOpts,
14
+ ManagedIdentifierJwkResult,
15
+ ManagedIdentifierKidOpts,
16
+ ManagedIdentifierKidResult,
17
+ ManagedIdentifierOpts,
18
+ ManagedIdentifierResult,
19
+ ManagedIdentifierX5cOpts,
20
+ ManagedIdentifierX5cResult,
21
+ } from './managedIdentifierTypes'
17
22
 
18
23
  /**
19
24
  * @public
20
25
  */
21
26
  export interface IIdentifierResolution extends IPluginMethodMap {
27
+ /**
28
+ * 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
29
+ * @param args
30
+ * @param context
31
+ * @public
32
+ */
22
33
  identifierManagedGet(args: ManagedIdentifierOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierResult>
23
34
 
24
35
  identifierManagedGetByDid(args: ManagedIdentifierDidOpts, context: IAgentContext<IKeyManager & IDIDManager>): Promise<ManagedIdentifierDidResult>
@@ -29,269 +40,15 @@ export interface IIdentifierResolution extends IPluginMethodMap {
29
40
 
30
41
  identifierManagedGetByX5c(args: ManagedIdentifierX5cOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierX5cResult>
31
42
 
32
- identifierExternalResolve(args: ExternalIdentifierOpts, context: IAgentContext<any>): Promise<any>
33
- }
34
-
35
- /**
36
- * Use whenever we need to pass in an identifier. We can pass in kids, DIDs, IIdentifier objects and x5chains
37
- *
38
- * The functions below can be used to check the type, and they also provide the proper runtime types
39
- */
40
- export type ManagedIdentifierType = IIdentifier /*did*/ | string /*did or kid*/ | string[] /*x5c*/ | JWK
41
-
42
- /**
43
- * Use whenever we need to resolve an external identifier. We can pass in kids, DIDs, and x5chains
44
- *
45
- * The functions below can be used to check the type, and they also provide the proper runtime types
46
- */
47
- export type ExternalIdentifierType = string | string[] | JWK
48
-
49
- export function isDidIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is IIdentifier | string {
50
- return isIIdentifier(identifier) || (typeof identifier === 'string' && identifier.startsWith('did:'))
51
- }
52
-
53
- export function isIIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is IIdentifier {
54
- return typeof identifier === 'object' && !Array.isArray(identifier) && 'did' in identifier && 'keys' in identifier
55
- }
56
-
57
- export function isJwkIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is JWK {
58
- return typeof identifier === 'object' && !Array.isArray(identifier) && 'kty' in identifier
59
- }
60
-
61
- export function isOidcDiscoveryIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
62
- return typeof identifier === 'string' && identifier.startsWith('http') && identifier.endsWith('/.well-known/openid-configuration')
63
- }
64
-
65
- export function isJwksUrlIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
66
- return typeof identifier === 'string' && identifier.startsWith('http') && identifier.endsWith('jwks.json')
67
- }
68
-
69
- export function isKidIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
70
- return typeof identifier === 'string' && !identifier.startsWith('did:')
71
- }
72
-
73
- export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] {
74
- 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
75
- }
76
-
77
- export type ExternalIdentifierOptsBase = {
78
- method?: ExternalIdentifierMethod // If provided always takes precedences otherwise it will be inferred from the identifier
79
- identifier: ExternalIdentifierType
80
- }
81
-
82
- export type ExternalIdentifierDidOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
83
- method?: 'did'
84
- identifier: string
85
- noVerificationMethodFallback?: boolean
86
- vmRelationship?: DIDDocumentSection
87
- localResolution?: boolean // Resolve identifiers hosted by the agent
88
- uniresolverResolution?: boolean // Resolve identifiers using universal resolver
89
- resolverResolution?: boolean // Use registered drivers
90
- }
91
-
92
- export function isExternalIdentifierDidOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierDidOpts {
93
- const { identifier } = opts
94
- return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
95
- }
96
-
97
- export type ExternalIdentifierOpts = (ExternalIdentifierJwkOpts | ExternalIdentifierX5cOpts | ExternalIdentifierDidOpts | ExternalIdentifierKidOpts) &
98
- ExternalIdentifierOptsBase
99
-
100
- export type ManagedIdentifierOpts = (ManagedIdentifierJwkOpts | ManagedIdentifierX5cOpts | ManagedIdentifierDidOpts | ManagedIdentifierKidOpts) &
101
- ManagedIdentifierOptsBase
102
-
103
- export type ManagedIdentifierOptsBase = {
104
- method?: ManagedIdentifierMethod // If provided always takes precedences otherwise it will be inferred from the identifier
105
- identifier: ManagedIdentifierType
106
- kmsKeyRef?: string
107
- }
108
-
109
- export type ManagedIdentifierDidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
110
- method?: 'did'
111
- identifier: IIdentifier | string
112
- keyType?: TKeyType
113
- offlineWhenNoDIDRegistered?: boolean
114
- noVerificationMethodFallback?: boolean
115
- controllerKey?: boolean
116
- vmRelationship?: DIDDocumentSection
117
- }
118
-
119
- export function isManagedIdentifierDidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierDidOpts {
120
- const { identifier } = opts
121
- return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
122
- }
123
-
124
- export type ExternalIdentifierKidOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
125
- method?: 'kid'
126
- identifier: string
127
- }
128
-
129
- export function isExternalIdentifierKidOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierKidOpts {
130
- const { identifier } = opts
131
- return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier)
132
- }
133
-
134
- export type ManagedIdentifierKidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
135
- method?: 'kid'
136
- identifier: string
137
- }
138
-
139
- export function isManagedIdentifierKidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierKidOpts {
140
- const { identifier } = opts
141
- return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier)
142
- }
143
-
144
- export type ExternalIdentifierJwkOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
145
- method?: 'jwk'
146
- identifier: JWK
147
- }
148
-
149
- export function isExternalIdentifierJwkOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwkOpts {
150
- const { identifier } = opts
151
- return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
152
- }
153
-
154
- export type ExternalIdentifierOidcDiscoveryOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
155
- method?: 'oidc-discovery'
156
- identifier: string
157
- }
43
+ /**
44
+ * Main method for external 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
45
+ * @param args
46
+ * @param context
47
+ * @public
48
+ */
49
+ identifierExternalResolve(args: ExternalIdentifierOpts, context: IAgentContext<any>): Promise<ExternalIdentifierResult>
158
50
 
159
- export function isExternalIdentifierOidcDiscoveryOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwkOpts {
160
- const { identifier } = opts
161
- return ('method' in opts && opts.method === 'oidc-discovery') || isOidcDiscoveryIdentifier(identifier)
162
- }
163
-
164
- export type ExternalIdentifierJwksUrlOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
165
- method?: 'jwks-url'
166
- identifier: string
167
- }
168
-
169
- export function isExternalIdentifierJwksUrlOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwksUrlOpts {
170
- const { identifier } = opts
171
- return ('method' in opts && opts.method === 'oidc-discovery') || isJwksUrlIdentifier(identifier)
172
- }
173
-
174
- export type ManagedIdentifierJwkOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
175
- method?: 'jwk'
176
- identifier: JWK
177
- }
178
-
179
- export function isManagedIdentifierJwkOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierJwkOpts {
180
- const { identifier } = opts
181
- return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
182
- }
183
-
184
- export type ExternalIdentifierX5cOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
185
- method?: 'x5c'
186
- identifier: string[]
187
- verify: boolean
188
- verificationTime?: Date
189
- trustAnchors?: string[]
190
- }
191
-
192
- export function isExternalIdentifierX5cOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierX5cOpts {
193
- const { identifier } = opts
194
- return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
195
- }
196
-
197
- export type ManagedIdentifierX5cOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
198
- method?: 'x5c'
199
- identifier: string[]
200
- }
201
-
202
- export function isManagedIdentifierX5cOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierX5cOpts {
203
- const { identifier } = opts
204
- return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
205
- }
206
-
207
- export type ExternalIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' | 'oidc-discovery' | 'jwks-url' | 'oid4vci-issuer'
208
-
209
- export type ExternalIdentifierResult = ExternalIdentifierDidResult | ExternalIdentifierX5cResult
210
-
211
- export type ManagedIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid'
212
-
213
- export type ManagedIdentifierResult =
214
- | ManagedIdentifierX5cResult
215
- | ManagedIdentifierDidResult
216
- | ManagedIdentifierJwkResult
217
- | ManagedIdentifierKidResult
218
-
219
- export interface IExternalIdentifierResultBase {
220
- method: ExternalIdentifierMethod
221
- jwks: Array<ExternalJwkInfo>
222
- }
223
-
224
- export interface JwkInfo {
225
- jwk: JWK
226
- jwkThumbprint: string
227
- }
228
-
229
- export interface ExternalJwkInfo extends JwkInfo {
230
- kid?: string
231
- }
232
-
233
- export interface ManagedJwkInfo extends JwkInfo {
234
- kmsKeyRef: string
235
- }
236
-
237
- export interface IManagedIdentifierResultBase extends ManagedJwkInfo {
238
- method: ManagedIdentifierMethod
239
- key: IKey
240
- }
241
-
242
- export function isManagedIdentifierDidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
243
- return object!! && typeof object === 'object' && 'method' in object && object.method === 'did'
244
- }
245
-
246
- export function isManagedIdentifierX5cResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
247
- return object!! && typeof object === 'object' && 'method' in object && object.method === 'x5c'
248
- }
249
-
250
- export function isManagedIdentifierJwkResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierJwkResult {
251
- return object!! && typeof object === 'object' && 'method' in object && object.method === 'jwk'
252
- }
253
-
254
- export function isManagedIdentifierKidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierKidResult {
255
- return object!! && typeof object === 'object' && 'method' in object && object.method === 'kid'
256
- }
257
-
258
- export interface ExternalIdentifierDidResult extends IExternalIdentifierResultBase {
259
- method: 'did'
260
- did: string
261
- didDocument?: DIDDocument
262
- didJwks?: DidDocumentJwks
263
- didResolutionResult: Omit<DIDResolutionResult, 'didDocument'> // we already provide that directly
264
- didParsed: IParsedDID
265
- }
266
-
267
- export interface ManagedIdentifierDidResult extends IManagedIdentifierResultBase {
268
- method: 'did'
269
- identifier: IIdentifier
270
- did: string
271
- // key: IKey // The key associated with the requested did method sections. Controller key in case of no DID method section requested
272
- keys: Array<IKey> // If there is more than one key for the VM relationship.
273
- verificationMethodSection?: DIDDocumentSection
274
- controllerKeyId: string
275
- }
276
-
277
- export interface ManagedIdentifierJwkResult extends IManagedIdentifierResultBase {
278
- method: 'jwk'
279
- }
280
-
281
- export interface ManagedIdentifierKidResult extends IManagedIdentifierResultBase {
282
- method: 'kid'
283
- }
284
-
285
- export interface ExternalIdentifierX5cResult extends IExternalIdentifierResultBase {
286
- method: 'x5c'
287
- x5c: string[]
288
- issuerJWK: JWK
289
- verificationResult?: X509ValidationResult
290
- certificates: any[] // for now since our schema generator trips on pkijs Certificate(Json) object //fixme
291
- }
51
+ identifierExternalResolveByDid(args: ExternalIdentifierDidOpts, context: IAgentContext<any>): Promise<ExternalIdentifierDidResult>
292
52
 
293
- export interface ManagedIdentifierX5cResult extends IManagedIdentifierResultBase {
294
- method: 'x5c'
295
- x5c: string[]
296
- certificate: any // Certificate(JSON_, but trips schema generator. Probably want to create our own DTO
53
+ identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult>
297
54
  }
@@ -0,0 +1,37 @@
1
+ import { JWK } from '@sphereon/ssi-sdk-ext.key-utils'
2
+ import { IIdentifier } from '@veramo/core'
3
+ import { ExternalIdentifierType } from './externalIdentifierTypes'
4
+ import { ManagedIdentifierType } from './managedIdentifierTypes'
5
+
6
+ export interface JwkInfo {
7
+ jwk: JWK
8
+ jwkThumbprint: string
9
+ }
10
+
11
+ export function isDidIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is IIdentifier | string {
12
+ return isIIdentifier(identifier) || (typeof identifier === 'string' && identifier.startsWith('did:'))
13
+ }
14
+
15
+ export function isIIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is IIdentifier {
16
+ return typeof identifier === 'object' && !Array.isArray(identifier) && 'did' in identifier && 'keys' in identifier
17
+ }
18
+
19
+ export function isJwkIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is JWK {
20
+ return typeof identifier === 'object' && !Array.isArray(identifier) && 'kty' in identifier
21
+ }
22
+
23
+ export function isOidcDiscoveryIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
24
+ return typeof identifier === 'string' && identifier.startsWith('http') && identifier.endsWith('/.well-known/openid-configuration')
25
+ }
26
+
27
+ export function isJwksUrlIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
28
+ return typeof identifier === 'string' && identifier.startsWith('http') && identifier.endsWith('jwks.json')
29
+ }
30
+
31
+ export function isKidIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string {
32
+ return typeof identifier === 'string' && !identifier.startsWith('did:')
33
+ }
34
+
35
+ export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] {
36
+ 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
37
+ }
@@ -0,0 +1,119 @@
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'
4
+ import { IParsedDID } from '@sphereon/ssi-types'
5
+ import { DIDDocument, DIDDocumentSection, DIDResolutionResult } from '@veramo/core'
6
+ import { isDidIdentifier, isJwkIdentifier, isJwksUrlIdentifier, isKidIdentifier, isOidcDiscoveryIdentifier, isX5cIdentifier, JwkInfo } from './common'
7
+
8
+ /**
9
+ * Use whenever we need to resolve an external identifier. We can pass in kids, DIDs, and x5chains
10
+ *
11
+ * The functions below can be used to check the type, and they also provide the proper runtime types
12
+ */
13
+ export type ExternalIdentifierType = string | string[] | JWK
14
+
15
+ export type ExternalIdentifierOptsBase = {
16
+ method?: ExternalIdentifierMethod // If provided always takes precedences otherwise it will be inferred from the identifier
17
+ identifier: ExternalIdentifierType
18
+ }
19
+
20
+ export type ExternalIdentifierDidOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
21
+ method?: 'did'
22
+ identifier: string
23
+ noVerificationMethodFallback?: boolean
24
+ vmRelationship?: DIDDocumentSection
25
+ localResolution?: boolean // Resolve identifiers hosted by the agent
26
+ uniresolverResolution?: boolean // Resolve identifiers using universal resolver
27
+ resolverResolution?: boolean // Use registered drivers
28
+ }
29
+
30
+ export function isExternalIdentifierDidOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierDidOpts {
31
+ const { identifier } = opts
32
+ return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
33
+ }
34
+
35
+ export type ExternalIdentifierOpts = (ExternalIdentifierJwkOpts | ExternalIdentifierX5cOpts | ExternalIdentifierDidOpts | ExternalIdentifierKidOpts) &
36
+ ExternalIdentifierOptsBase
37
+
38
+ export type ExternalIdentifierKidOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
39
+ method?: 'kid'
40
+ identifier: string
41
+ }
42
+
43
+ export function isExternalIdentifierKidOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierKidOpts {
44
+ const { identifier } = opts
45
+ return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier)
46
+ }
47
+
48
+ export type ExternalIdentifierJwkOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
49
+ method?: 'jwk'
50
+ identifier: JWK
51
+ }
52
+
53
+ export function isExternalIdentifierJwkOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwkOpts {
54
+ const { identifier } = opts
55
+ return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
56
+ }
57
+
58
+ export type ExternalIdentifierOidcDiscoveryOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
59
+ method?: 'oidc-discovery'
60
+ identifier: string
61
+ }
62
+
63
+ export function isExternalIdentifierOidcDiscoveryOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwkOpts {
64
+ const { identifier } = opts
65
+ return ('method' in opts && opts.method === 'oidc-discovery') || isOidcDiscoveryIdentifier(identifier)
66
+ }
67
+
68
+ export type ExternalIdentifierJwksUrlOpts = Omit<ExternalIdentifierOptsBase, 'method'> & {
69
+ method?: 'jwks-url'
70
+ identifier: string
71
+ }
72
+
73
+ export function isExternalIdentifierJwksUrlOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierJwksUrlOpts {
74
+ const { identifier } = opts
75
+ return ('method' in opts && opts.method === 'oidc-discovery') || isJwksUrlIdentifier(identifier)
76
+ }
77
+
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
+ }
85
+
86
+ export function isExternalIdentifierX5cOpts(opts: ExternalIdentifierOptsBase): opts is ExternalIdentifierX5cOpts {
87
+ const { identifier } = opts
88
+ return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
89
+ }
90
+
91
+ export type ExternalIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' | 'oidc-discovery' | 'jwks-url' | 'oid4vci-issuer'
92
+
93
+ export type ExternalIdentifierResult = ExternalIdentifierDidResult | ExternalIdentifierX5cResult
94
+
95
+ export interface IExternalIdentifierResultBase {
96
+ method: ExternalIdentifierMethod
97
+ jwks: Array<ExternalJwkInfo>
98
+ }
99
+
100
+ export interface ExternalIdentifierX5cResult extends IExternalIdentifierResultBase {
101
+ method: 'x5c'
102
+ x5c: string[]
103
+ issuerJWK: JWK
104
+ verificationResult?: X509ValidationResult
105
+ certificates: any[] // for now since our schema generator trips on pkijs Certificate(Json) object //fixme
106
+ }
107
+
108
+ export interface ExternalJwkInfo extends JwkInfo {
109
+ kid?: string
110
+ }
111
+
112
+ export interface ExternalIdentifierDidResult extends IExternalIdentifierResultBase {
113
+ method: 'did'
114
+ did: string
115
+ didDocument?: DIDDocument
116
+ didJwks?: DidDocumentJwks
117
+ didResolutionResult: Omit<DIDResolutionResult, 'didDocument'> // we already provide that directly
118
+ didParsed: IParsedDID
119
+ }
@@ -0,0 +1,4 @@
1
+ export * from './common'
2
+ export * from './externalIdentifierTypes'
3
+ export * from './managedIdentifierTypes'
4
+ export * from './IIdentifierResolution'
@@ -0,0 +1,121 @@
1
+ import { JWK } from '@sphereon/ssi-sdk-ext.key-utils'
2
+ import { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core'
3
+ import { isDidIdentifier, isJwkIdentifier, isKidIdentifier, isX5cIdentifier, JwkInfo } from './common'
4
+
5
+ /**
6
+ * Use whenever we need to pass in an identifier. We can pass in kids, DIDs, IIdentifier objects and x5chains
7
+ *
8
+ * The functions below can be used to check the type, and they also provide the proper runtime types
9
+ */
10
+ export type ManagedIdentifierType = IIdentifier /*did*/ | string /*did or kid*/ | string[] /*x5c*/ | JWK
11
+
12
+ export type ManagedIdentifierOpts = (ManagedIdentifierJwkOpts | ManagedIdentifierX5cOpts | ManagedIdentifierDidOpts | ManagedIdentifierKidOpts) &
13
+ ManagedIdentifierOptsBase
14
+
15
+ export type ManagedIdentifierOptsBase = {
16
+ method?: ManagedIdentifierMethod // If provided always takes precedences otherwise it will be inferred from the identifier
17
+ identifier: ManagedIdentifierType
18
+ kmsKeyRef?: string
19
+ }
20
+
21
+ export type ManagedIdentifierDidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
22
+ method?: 'did'
23
+ identifier: IIdentifier | string
24
+ keyType?: TKeyType
25
+ offlineWhenNoDIDRegistered?: boolean
26
+ noVerificationMethodFallback?: boolean
27
+ controllerKey?: boolean
28
+ vmRelationship?: DIDDocumentSection
29
+ }
30
+
31
+ export function isManagedIdentifierDidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierDidOpts {
32
+ const { identifier } = opts
33
+ return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
34
+ }
35
+
36
+ export type ManagedIdentifierKidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
37
+ method?: 'kid'
38
+ identifier: string
39
+ }
40
+
41
+ export function isManagedIdentifierKidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierKidOpts {
42
+ const { identifier } = opts
43
+ return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier)
44
+ }
45
+
46
+ export type ManagedIdentifierJwkOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
47
+ method?: 'jwk'
48
+ identifier: JWK
49
+ }
50
+
51
+ export function isManagedIdentifierJwkOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierJwkOpts {
52
+ const { identifier } = opts
53
+ return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
54
+ }
55
+
56
+ export type ManagedIdentifierX5cOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
57
+ method?: 'x5c'
58
+ identifier: string[]
59
+ }
60
+
61
+ export function isManagedIdentifierX5cOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierX5cOpts {
62
+ const { identifier } = opts
63
+ return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
64
+ }
65
+
66
+ export interface ManagedJwkInfo extends JwkInfo {
67
+ kmsKeyRef: string
68
+ }
69
+
70
+ export interface IManagedIdentifierResultBase extends ManagedJwkInfo {
71
+ method: ManagedIdentifierMethod
72
+ key: IKey
73
+ }
74
+
75
+ export function isManagedIdentifierDidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
76
+ return object!! && typeof object === 'object' && 'method' in object && object.method === 'did'
77
+ }
78
+
79
+ export function isManagedIdentifierX5cResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
80
+ return object!! && typeof object === 'object' && 'method' in object && object.method === 'x5c'
81
+ }
82
+
83
+ export function isManagedIdentifierJwkResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierJwkResult {
84
+ return object!! && typeof object === 'object' && 'method' in object && object.method === 'jwk'
85
+ }
86
+
87
+ export function isManagedIdentifierKidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierKidResult {
88
+ return object!! && typeof object === 'object' && 'method' in object && object.method === 'kid'
89
+ }
90
+
91
+ export interface ManagedIdentifierDidResult extends IManagedIdentifierResultBase {
92
+ method: 'did'
93
+ identifier: IIdentifier
94
+ did: string
95
+ // key: IKey // The key associated with the requested did method sections. Controller key in case of no DID method section requested
96
+ keys: Array<IKey> // If there is more than one key for the VM relationship.
97
+ verificationMethodSection?: DIDDocumentSection
98
+ controllerKeyId: string
99
+ }
100
+
101
+ export interface ManagedIdentifierJwkResult extends IManagedIdentifierResultBase {
102
+ method: 'jwk'
103
+ }
104
+
105
+ export interface ManagedIdentifierKidResult extends IManagedIdentifierResultBase {
106
+ method: 'kid'
107
+ }
108
+
109
+ export interface ManagedIdentifierX5cResult extends IManagedIdentifierResultBase {
110
+ method: 'x5c'
111
+ x5c: string[]
112
+ certificate: any // Certificate(JSON_, but trips schema generator. Probably want to create our own DTO
113
+ }
114
+
115
+ export type ManagedIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid'
116
+
117
+ export type ManagedIdentifierResult =
118
+ | ManagedIdentifierX5cResult
119
+ | ManagedIdentifierDidResult
120
+ | ManagedIdentifierJwkResult
121
+ | ManagedIdentifierKidResult