@sphereon/ssi-sdk-ext.identifier-resolution 0.24.1-next.84
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 +31 -0
- package/dist/agent/IdentifierResolution.d.ts.map +1 -0
- package/dist/agent/IdentifierResolution.js +86 -0
- package/dist/agent/IdentifierResolution.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 +14 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +55 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/functions/managedIdentifierFunctions.d.ts +12 -0
- package/dist/functions/managedIdentifierFunctions.d.ts.map +1 -0
- package/dist/functions/managedIdentifierFunctions.js +168 -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 +29 -0
- package/dist/types/IIdentifierResolution.d.ts.map +1 -0
- package/dist/types/IIdentifierResolution.js +3 -0
- package/dist/types/IIdentifierResolution.js.map +1 -0
- package/dist/types/common.d.ts +16 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +32 -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 +81 -0
- package/dist/types/managedIdentifierTypes.d.ts.map +1 -0
- package/dist/types/managedIdentifierTypes.js +41 -0
- package/dist/types/managedIdentifierTypes.js.map +1 -0
- package/package.json +68 -0
- package/plugin.schema.json +1792 -0
- package/src/agent/IdentifierResolution.ts +92 -0
- package/src/functions/externalIdentifierFunctions.ts +183 -0
- package/src/functions/index.ts +53 -0
- package/src/functions/managedIdentifierFunctions.ts +178 -0
- package/src/index.ts +11 -0
- package/src/types/IIdentifierResolution.ts +54 -0
- package/src/types/common.ts +37 -0
- package/src/types/externalIdentifierTypes.ts +119 -0
- package/src/types/index.ts +4 -0
- package/src/types/managedIdentifierTypes.ts +126 -0
|
@@ -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,126 @@
|
|
|
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
|
+
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
|
|
20
|
+
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
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type ManagedIdentifierDidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
24
|
+
method?: 'did'
|
|
25
|
+
identifier: IIdentifier | string
|
|
26
|
+
keyType?: TKeyType
|
|
27
|
+
offlineWhenNoDIDRegistered?: boolean
|
|
28
|
+
noVerificationMethodFallback?: boolean
|
|
29
|
+
controllerKey?: boolean
|
|
30
|
+
vmRelationship?: DIDDocumentSection
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function isManagedIdentifierDidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierDidOpts {
|
|
34
|
+
const { identifier } = opts
|
|
35
|
+
return ('method' in opts && opts.method === 'did') || isDidIdentifier(identifier)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ManagedIdentifierKidOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
39
|
+
method?: 'kid'
|
|
40
|
+
identifier: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isManagedIdentifierKidOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierKidOpts {
|
|
44
|
+
const { identifier } = opts
|
|
45
|
+
return ('method' in opts && opts.method === 'kid') || isKidIdentifier(identifier)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type ManagedIdentifierJwkOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
49
|
+
method?: 'jwk'
|
|
50
|
+
identifier: JWK
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function isManagedIdentifierJwkOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierJwkOpts {
|
|
54
|
+
const { identifier } = opts
|
|
55
|
+
return ('method' in opts && opts.method === 'jwk') || isJwkIdentifier(identifier)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type ManagedIdentifierX5cOpts = Omit<ManagedIdentifierOptsBase, 'method'> & {
|
|
59
|
+
method?: 'x5c'
|
|
60
|
+
identifier: string[]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function isManagedIdentifierX5cOpts(opts: ManagedIdentifierOptsBase): opts is ManagedIdentifierX5cOpts {
|
|
64
|
+
const { identifier } = opts
|
|
65
|
+
return ('method' in opts && opts.method === 'x5c') || isX5cIdentifier(identifier)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface ManagedJwkInfo extends JwkInfo {
|
|
69
|
+
kmsKeyRef: string
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface IManagedIdentifierResultBase extends ManagedJwkInfo {
|
|
73
|
+
method: ManagedIdentifierMethod
|
|
74
|
+
key: IKey
|
|
75
|
+
kid?: string
|
|
76
|
+
issuer?: string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isManagedIdentifierDidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
|
|
80
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'did'
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function isManagedIdentifierX5cResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierDidResult {
|
|
84
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'x5c'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function isManagedIdentifierJwkResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierJwkResult {
|
|
88
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'jwk'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function isManagedIdentifierKidResult(object: IManagedIdentifierResultBase): object is ManagedIdentifierKidResult {
|
|
92
|
+
return object!! && typeof object === 'object' && 'method' in object && object.method === 'kid'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ManagedIdentifierDidResult extends IManagedIdentifierResultBase {
|
|
96
|
+
method: 'did'
|
|
97
|
+
identifier: IIdentifier
|
|
98
|
+
did: string
|
|
99
|
+
// key: IKey // The key associated with the requested did method sections. Controller key in case of no DID method section requested
|
|
100
|
+
keys: Array<IKey> // If there is more than one key for the VM relationship.
|
|
101
|
+
verificationMethodSection?: DIDDocumentSection
|
|
102
|
+
controllerKeyId?: string
|
|
103
|
+
issuer: string
|
|
104
|
+
kid: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface ManagedIdentifierJwkResult extends IManagedIdentifierResultBase {
|
|
108
|
+
method: 'jwk'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ManagedIdentifierKidResult extends IManagedIdentifierResultBase {
|
|
112
|
+
method: 'kid'
|
|
113
|
+
issuer: string
|
|
114
|
+
kid: string
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export interface ManagedIdentifierX5cResult extends IManagedIdentifierResultBase {
|
|
118
|
+
method: 'x5c'
|
|
119
|
+
x5c: string[]
|
|
120
|
+
certificate: any // Certificate(JSON_, but trips schema generator. Probably want to create our own DTO
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export type ManagedIdentifierMethod = 'did' | 'jwk' | 'x5c' | 'kid'
|
|
124
|
+
|
|
125
|
+
export type ManagedIdentifierResult = IManagedIdentifierResultBase &
|
|
126
|
+
(ManagedIdentifierX5cResult | ManagedIdentifierDidResult | ManagedIdentifierJwkResult | ManagedIdentifierKidResult)
|