@sphereon/ssi-sdk-ext.identifier-resolution 0.24.1-next.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +433 -0
- package/dist/agent/IdentifierResolution.d.ts +33 -0
- package/dist/agent/IdentifierResolution.d.ts.map +1 -0
- package/dist/agent/IdentifierResolution.js +93 -0
- package/dist/agent/IdentifierResolution.js.map +1 -0
- package/dist/functions/LegacySupport.d.ts +12 -0
- package/dist/functions/LegacySupport.d.ts.map +1 -0
- package/dist/functions/LegacySupport.js +39 -0
- package/dist/functions/LegacySupport.js.map +1 -0
- package/dist/functions/externalIdentifierFunctions.d.ts +10 -0
- package/dist/functions/externalIdentifierFunctions.d.ts.map +1 -0
- package/dist/functions/externalIdentifierFunctions.js +167 -0
- package/dist/functions/externalIdentifierFunctions.js.map +1 -0
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +20 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/managedIdentifierFunctions.d.ts +28 -0
- package/dist/functions/managedIdentifierFunctions.d.ts.map +1 -0
- package/dist/functions/managedIdentifierFunctions.js +252 -0
- package/dist/functions/managedIdentifierFunctions.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/types/IIdentifierResolution.d.ts +37 -0
- package/dist/types/IIdentifierResolution.d.ts.map +1 -0
- package/dist/types/IIdentifierResolution.js +16 -0
- package/dist/types/IIdentifierResolution.js.map +1 -0
- package/dist/types/common.d.ts +17 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +40 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/externalIdentifierTypes.d.ts +80 -0
- package/dist/types/externalIdentifierTypes.d.ts.map +1 -0
- package/dist/types/externalIdentifierTypes.js +35 -0
- package/dist/types/externalIdentifierTypes.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/managedIdentifierTypes.d.ts +98 -0
- package/dist/types/managedIdentifierTypes.d.ts.map +1 -0
- package/dist/types/managedIdentifierTypes.js +50 -0
- package/dist/types/managedIdentifierTypes.js.map +1 -0
- package/package.json +68 -0
- package/plugin.schema.json +2393 -0
- package/src/agent/IdentifierResolution.ts +112 -0
- package/src/functions/LegacySupport.ts +50 -0
- package/src/functions/externalIdentifierFunctions.ts +183 -0
- package/src/functions/index.ts +3 -0
- package/src/functions/managedIdentifierFunctions.ts +278 -0
- package/src/index.ts +11 -0
- package/src/types/IIdentifierResolution.ts +79 -0
- package/src/types/common.ts +47 -0
- package/src/types/externalIdentifierTypes.ts +119 -0
- package/src/types/index.ts +4 -0
- package/src/types/managedIdentifierTypes.ts +157 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
2
|
+
import {
|
|
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
|
+
ManagedIdentifierKeyOpts,
|
|
16
|
+
ManagedIdentifierKeyResult,
|
|
17
|
+
ManagedIdentifierKidOpts,
|
|
18
|
+
ManagedIdentifierKidResult,
|
|
19
|
+
ManagedIdentifierOptsOrResult,
|
|
20
|
+
ManagedIdentifierResult,
|
|
21
|
+
ManagedIdentifierX5cOpts,
|
|
22
|
+
ManagedIdentifierX5cResult,
|
|
23
|
+
} from './managedIdentifierTypes'
|
|
24
|
+
|
|
25
|
+
// Exposing the methods here for any REST implementation
|
|
26
|
+
export const identifierResolutionContextMethods: Array<string> = [
|
|
27
|
+
'identifierManagedGet',
|
|
28
|
+
'identifierManagedGetByDid',
|
|
29
|
+
'identifierManagedGetByKid',
|
|
30
|
+
'identifierManagedGetByJwk',
|
|
31
|
+
'identifierManagedGetByX5c',
|
|
32
|
+
'identifierManagedGetByKey',
|
|
33
|
+
'identifierExternalResolve',
|
|
34
|
+
'identifierExternalResolveByDid',
|
|
35
|
+
'identifierExternalResolveByX5c',
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export interface IIdentifierResolution extends IPluginMethodMap {
|
|
42
|
+
/**
|
|
43
|
+
* 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
|
|
44
|
+
*
|
|
45
|
+
* 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
|
|
46
|
+
* 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
|
|
47
|
+
*
|
|
48
|
+
* 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.
|
|
49
|
+
* 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
|
|
50
|
+
* @param args
|
|
51
|
+
* @param context
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
identifierManagedGet(args: ManagedIdentifierOptsOrResult, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierResult>
|
|
55
|
+
|
|
56
|
+
identifierManagedGetByDid(args: ManagedIdentifierDidOpts, context: IAgentContext<IKeyManager & IDIDManager>): Promise<ManagedIdentifierDidResult>
|
|
57
|
+
|
|
58
|
+
identifierManagedGetByKid(args: ManagedIdentifierKidOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierKidResult>
|
|
59
|
+
|
|
60
|
+
identifierManagedGetByJwk(args: ManagedIdentifierJwkOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierJwkResult>
|
|
61
|
+
|
|
62
|
+
identifierManagedGetByX5c(args: ManagedIdentifierX5cOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierX5cResult>
|
|
63
|
+
|
|
64
|
+
identifierManagedGetByKey(args: ManagedIdentifierKeyOpts, context: IAgentContext<IKeyManager>): Promise<ManagedIdentifierKeyResult>
|
|
65
|
+
|
|
66
|
+
// 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
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 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
|
|
70
|
+
* @param args
|
|
71
|
+
* @param context
|
|
72
|
+
* @public
|
|
73
|
+
*/
|
|
74
|
+
identifierExternalResolve(args: ExternalIdentifierOpts, context: IAgentContext<any>): Promise<ExternalIdentifierResult>
|
|
75
|
+
|
|
76
|
+
identifierExternalResolveByDid(args: ExternalIdentifierDidOpts, context: IAgentContext<any>): Promise<ExternalIdentifierDidResult>
|
|
77
|
+
|
|
78
|
+
identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult>
|
|
79
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { JWK } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
2
|
+
import { IIdentifier, IKey } 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 isKeyIdentifier(identifier: ManagedIdentifierType): identifier is IKey {
|
|
36
|
+
return (
|
|
37
|
+
typeof identifier === 'string' &&
|
|
38
|
+
!Array.isArray(identifier) &&
|
|
39
|
+
typeof identifier === 'object' &&
|
|
40
|
+
`kid` in identifier &&
|
|
41
|
+
'publicKeyHex' in identifier
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] {
|
|
46
|
+
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
|
+
}
|
|
@@ -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,157 @@
|
|
|
1
|
+
import { JWK } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
2
|
+
import { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core'
|
|
3
|
+
import { isDidIdentifier, isJwkIdentifier, isKeyIdentifier, 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 | IKey
|
|
11
|
+
|
|
12
|
+
export type ManagedIdentifierOpts = (
|
|
13
|
+
| ManagedIdentifierJwkOpts
|
|
14
|
+
| ManagedIdentifierX5cOpts
|
|
15
|
+
| ManagedIdentifierDidOpts
|
|
16
|
+
| ManagedIdentifierKidOpts
|
|
17
|
+
| ManagedIdentifierKeyOpts
|
|
18
|
+
) &
|
|
19
|
+
ManagedIdentifierOptsBase
|
|
20
|
+
|
|
21
|
+
export type ManagedIdentifierOptsBase = {
|
|
22
|
+
method?: ManagedIdentifierMethod // If provided always takes precedences otherwise it will be inferred from the identifier
|
|
23
|
+
identifier: ManagedIdentifierType
|
|
24
|
+
kmsKeyRef?: string // The key reference for the KMS system. If provided this value will be used to determine the appropriate key. Otherwise it will be inferred
|
|
25
|
+
issuer?: string // can be used when a specific issuer needs to end up, for instance when signing JWTs. Will be returned or inferred if not provided
|
|
26
|
+
kid?: string // can be used when a specific kid value needs to be used. For instance when signing JWTs. Will be returned or inferred if not provided
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type ManagedIdentifierDidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
30
|
+
method?: 'did'
|
|
31
|
+
identifier: IIdentifier | string
|
|
32
|
+
keyType?: TKeyType
|
|
33
|
+
offlineWhenNoDIDRegistered?: boolean
|
|
34
|
+
noVerificationMethodFallback?: boolean
|
|
35
|
+
controllerKey?: boolean
|
|
36
|
+
vmRelationship?: DIDDocumentSection
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isManagedIdentifierDidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierDidOpts {
|
|
40
|
+
const { identifier } = opts
|
|
41
|
+
return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type ManagedIdentifierKidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
45
|
+
method?: 'kid'
|
|
46
|
+
identifier: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isManagedIdentifierKidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierKidOpts {
|
|
50
|
+
const { identifier } = opts
|
|
51
|
+
return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type ManagedIdentifierKeyOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
55
|
+
method?: 'key'
|
|
56
|
+
identifier: IKey
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isManagedIdentifierKeyOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierKidOpts {
|
|
60
|
+
const { identifier } = opts
|
|
61
|
+
return ('method' in opts && opts.method === 'key') || isKeyIdentifier(identifier)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type ManagedIdentifierJwkOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
65
|
+
method?: 'jwk'
|
|
66
|
+
identifier: JWK
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function isManagedIdentifierJwkOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierJwkOpts {
|
|
70
|
+
const { identifier } = opts
|
|
71
|
+
return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type ManagedIdentifierX5cOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
75
|
+
method?: 'x5c'
|
|
76
|
+
identifier: string[]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isManagedIdentifierX5cOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierX5cOpts {
|
|
80
|
+
const { identifier } = opts
|
|
81
|
+
return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface ManagedJwkInfo extends JwkInfo {
|
|
85
|
+
kmsKeyRef: string
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface IManagedIdentifierResultBase extends ManagedJwkInfo {
|
|
89
|
+
method: ManagedIdentifierMethod
|
|
90
|
+
opts: ManagedIdentifierOpts
|
|
91
|
+
key: IKey
|
|
92
|
+
kid?: string
|
|
93
|
+
issuer?: string
|
|
94
|
+
identifier: ManagedIdentifierType
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function isManagedIdentifierDidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
|
|
98
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'did'
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function isManagedIdentifierX5cResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierX5cResult {
|
|
102
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'x5c'
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function isManagedIdentifierJwkResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierJwkResult {
|
|
106
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'jwk'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isManagedIdentifierKidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierKidResult {
|
|
110
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'kid'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function isManagedIdentifierKeyResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierKeyResult {
|
|
114
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'key'
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ManagedIdentifierDidResult extends IManagedIdentifierResultBase {
|
|
118
|
+
method: 'did'
|
|
119
|
+
identifier: IIdentifier
|
|
120
|
+
did: string
|
|
121
|
+
// key: IKey // The key associated with the requested did method sections. Controller key in case of no DID method section requested
|
|
122
|
+
keys: Array<IKey> // If there is more than one key for the VM relationship.
|
|
123
|
+
verificationMethodSection?: DIDDocumentSection
|
|
124
|
+
controllerKeyId?: string
|
|
125
|
+
issuer: string
|
|
126
|
+
kid: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface ManagedIdentifierJwkResult extends IManagedIdentifierResultBase {
|
|
130
|
+
identifier: JWK
|
|
131
|
+
method: 'jwk'
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface ManagedIdentifierKidResult extends IManagedIdentifierResultBase {
|
|
135
|
+
method: 'kid'
|
|
136
|
+
identifier: string
|
|
137
|
+
kid: string
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface ManagedIdentifierKeyResult extends IManagedIdentifierResultBase {
|
|
141
|
+
method: 'key'
|
|
142
|
+
identifier: IKey
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface ManagedIdentifierX5cResult extends IManagedIdentifierResultBase {
|
|
146
|
+
method: 'x5c'
|
|
147
|
+
identifier: string[]
|
|
148
|
+
x5c: string[]
|
|
149
|
+
certificate: any // Certificate(JSON_, but trips schema generator. Probably want to create our own DTO
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export type ManagedIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid' | 'key'
|
|
153
|
+
|
|
154
|
+
export type ManagedIdentifierResult = IManagedIdentifierResultBase &
|
|
155
|
+
(ManagedIdentifierX5cResult | ManagedIdentifierDidResult | ManagedIdentifierJwkResult | ManagedIdentifierKidResult | ManagedIdentifierKeyResult)
|
|
156
|
+
|
|
157
|
+
export type ManagedIdentifierOptsOrResult = (ManagedIdentifierResult | ManagedIdentifierOpts) & { lazyDisabled?: boolean }
|