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