@sphereon/ssi-sdk-ext.identifier-resolution 0.24.1-unstable.93 → 0.25.0
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 +4 -0
- package/dist/agent/IdentifierResolution.d.ts.map +1 -1
- package/dist/agent/IdentifierResolution.js +25 -1
- package/dist/agent/IdentifierResolution.js.map +1 -1
- 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 +17 -1
- package/dist/functions/externalIdentifierFunctions.d.ts.map +1 -1
- package/dist/functions/externalIdentifierFunctions.js +85 -6
- package/dist/functions/externalIdentifierFunctions.js.map +1 -1
- package/dist/functions/index.d.ts +1 -11
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +1 -36
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/managedIdentifierFunctions.d.ts +17 -3
- package/dist/functions/managedIdentifierFunctions.d.ts.map +1 -1
- package/dist/functions/managedIdentifierFunctions.js +134 -12
- package/dist/functions/managedIdentifierFunctions.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/IIdentifierResolution.d.ts +12 -3
- package/dist/types/IIdentifierResolution.d.ts.map +1 -1
- package/dist/types/IIdentifierResolution.js +17 -0
- package/dist/types/IIdentifierResolution.js.map +1 -1
- package/dist/types/common.d.ts +3 -1
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +17 -10
- 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 +11 -7
- package/dist/types/externalIdentifierTypes.js.map +1 -1
- package/dist/types/managedIdentifierTypes.d.ts +43 -15
- package/dist/types/managedIdentifierTypes.d.ts.map +1 -1
- package/dist/types/managedIdentifierTypes.js +24 -11
- package/dist/types/managedIdentifierTypes.js.map +1 -1
- package/package.json +12 -12
- package/plugin.schema.json +2555 -313
- package/src/agent/IdentifierResolution.ts +63 -10
- package/src/functions/LegacySupport.ts +54 -0
- package/src/functions/externalIdentifierFunctions.ts +95 -5
- package/src/functions/index.ts +1 -51
- package/src/functions/managedIdentifierFunctions.ts +162 -14
- package/src/types/IIdentifierResolution.ts +42 -2
- package/src/types/common.ts +10 -2
- package/src/types/externalIdentifierTypes.ts +54 -13
- package/src/types/managedIdentifierTypes.ts +78 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IAgentContext, IAgentPlugin, IDIDManager, IKeyManager } from '@veramo/core'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { schema } from '..'
|
|
3
|
+
import { resolveExternalIdentifier, ensureManagedIdentifierResult } from '../functions'
|
|
4
4
|
import {
|
|
5
5
|
ExternalIdentifierDidOpts,
|
|
6
6
|
ExternalIdentifierDidResult,
|
|
@@ -8,17 +8,27 @@ import {
|
|
|
8
8
|
ExternalIdentifierResult,
|
|
9
9
|
ExternalIdentifierX5cOpts,
|
|
10
10
|
ExternalIdentifierX5cResult,
|
|
11
|
+
ExternalIdentifierCoseKeyOpts,
|
|
12
|
+
ExternalIdentifierCoseKeyResult,
|
|
13
|
+
ExternalIdentifierJwkOpts,
|
|
14
|
+
ExternalIdentifierJwkResult,
|
|
11
15
|
IIdentifierResolution,
|
|
16
|
+
ManagedIdentifierCoseKeyOpts,
|
|
17
|
+
ManagedIdentifierCoseKeyResult,
|
|
12
18
|
ManagedIdentifierDidOpts,
|
|
13
19
|
ManagedIdentifierDidResult,
|
|
14
20
|
ManagedIdentifierJwkOpts,
|
|
15
21
|
ManagedIdentifierJwkResult,
|
|
16
22
|
ManagedIdentifierKidOpts,
|
|
17
23
|
ManagedIdentifierKidResult,
|
|
18
|
-
ManagedIdentifierOpts,
|
|
19
24
|
ManagedIdentifierResult,
|
|
20
25
|
ManagedIdentifierX5cOpts,
|
|
21
26
|
ManagedIdentifierX5cResult,
|
|
27
|
+
ManagedIdentifierOID4VCIssuerResult,
|
|
28
|
+
ManagedIdentifierKeyOpts,
|
|
29
|
+
ManagedIdentifierKeyResult,
|
|
30
|
+
ManagedIdentifierOptsOrResult,
|
|
31
|
+
ManagedIdentifierOID4VCIssuerOpts
|
|
22
32
|
} from '../types'
|
|
23
33
|
|
|
24
34
|
/**
|
|
@@ -35,10 +45,14 @@ export class IdentifierResolution implements IAgentPlugin {
|
|
|
35
45
|
identifierManagedGetByJwk: this.identifierGetManagedByJwk.bind(this),
|
|
36
46
|
identifierManagedGetByX5c: this.identifierGetManagedByX5c.bind(this),
|
|
37
47
|
identifierManagedGetByKey: this.identifierGetManagedByKey.bind(this),
|
|
48
|
+
identifierManagedGetByCoseKey: this.identifierGetManagedByCoseKey.bind(this),
|
|
49
|
+
identifierManagedGetByOID4VCIssuer: this.identifierGetManagedByOID4VCIssuer.bind(this),
|
|
38
50
|
|
|
39
51
|
identifierExternalResolve: this.identifierResolveExternal.bind(this),
|
|
40
52
|
identifierExternalResolveByDid: this.identifierExternalResolveByDid.bind(this),
|
|
41
53
|
identifierExternalResolveByX5c: this.identifierExternalResolveByX5c.bind(this),
|
|
54
|
+
identifierExternalResolveByJwk: this.identifierExternalResolveByJwk.bind(this),
|
|
55
|
+
identifierExternalResolveByCoseKey: this.identifierExternalResolveByCoseKey.bind(this),
|
|
42
56
|
|
|
43
57
|
// todo: JWKSet, oidc-discovery, oid4vci-issuer etc. Anything we already can resolve and need keys of
|
|
44
58
|
}
|
|
@@ -57,30 +71,59 @@ export class IdentifierResolution implements IAgentPlugin {
|
|
|
57
71
|
* @param context
|
|
58
72
|
* @private
|
|
59
73
|
*/
|
|
60
|
-
private async identifierGetManaged(
|
|
61
|
-
|
|
74
|
+
private async identifierGetManaged(
|
|
75
|
+
args: ManagedIdentifierOptsOrResult,
|
|
76
|
+
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
77
|
+
): Promise<ManagedIdentifierResult> {
|
|
78
|
+
return await ensureManagedIdentifierResult({ ...args, crypto: this._crypto }, context)
|
|
62
79
|
}
|
|
63
80
|
|
|
64
81
|
private async identifierGetManagedByDid(
|
|
65
82
|
args: ManagedIdentifierDidOpts,
|
|
66
|
-
context: IAgentContext<IKeyManager & IDIDManager>
|
|
83
|
+
context: IAgentContext<IKeyManager & IDIDManager & IIdentifierResolution>
|
|
67
84
|
): Promise<ManagedIdentifierDidResult> {
|
|
68
85
|
return (await this.identifierGetManaged({ ...args, method: 'did' }, context)) as ManagedIdentifierDidResult
|
|
69
86
|
}
|
|
70
87
|
|
|
71
|
-
private async identifierGetManagedByKid(
|
|
88
|
+
private async identifierGetManagedByKid(
|
|
89
|
+
args: ManagedIdentifierKidOpts,
|
|
90
|
+
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
91
|
+
): Promise<ManagedIdentifierKidResult> {
|
|
72
92
|
return (await this.identifierGetManaged({ ...args, method: 'kid' }, context)) as ManagedIdentifierKidResult
|
|
73
93
|
}
|
|
74
94
|
|
|
75
|
-
private async identifierGetManagedByKey(
|
|
95
|
+
private async identifierGetManagedByKey(
|
|
96
|
+
args: ManagedIdentifierKeyOpts,
|
|
97
|
+
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
98
|
+
): Promise<ManagedIdentifierKeyResult> {
|
|
76
99
|
return (await this.identifierGetManaged({ ...args, method: 'key' }, context)) as ManagedIdentifierKeyResult
|
|
77
100
|
}
|
|
78
101
|
|
|
79
|
-
private async
|
|
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
|
+
|
|
109
|
+
private async identifierGetManagedByOID4VCIssuer(
|
|
110
|
+
args: ManagedIdentifierOID4VCIssuerOpts,
|
|
111
|
+
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
112
|
+
): Promise<ManagedIdentifierOID4VCIssuerResult> {
|
|
113
|
+
return (await this.identifierGetManaged({ ...args, method: 'oid4vci-issuer' }, context)) as ManagedIdentifierOID4VCIssuerResult
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private async identifierGetManagedByJwk(
|
|
117
|
+
args: ManagedIdentifierJwkOpts,
|
|
118
|
+
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
119
|
+
): Promise<ManagedIdentifierJwkResult> {
|
|
80
120
|
return (await this.identifierGetManaged({ ...args, method: 'jwk' }, context)) as ManagedIdentifierJwkResult
|
|
81
121
|
}
|
|
82
122
|
|
|
83
|
-
private async identifierGetManagedByX5c(
|
|
123
|
+
private async identifierGetManagedByX5c(
|
|
124
|
+
args: ManagedIdentifierX5cOpts,
|
|
125
|
+
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
126
|
+
): Promise<ManagedIdentifierX5cResult> {
|
|
84
127
|
return (await this.identifierGetManaged({ ...args, method: 'x5c' }, context)) as ManagedIdentifierX5cResult
|
|
85
128
|
}
|
|
86
129
|
|
|
@@ -95,4 +138,14 @@ export class IdentifierResolution implements IAgentPlugin {
|
|
|
95
138
|
private async identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult> {
|
|
96
139
|
return (await this.identifierResolveExternal({ ...args, method: 'x5c' }, context)) as ExternalIdentifierX5cResult
|
|
97
140
|
}
|
|
141
|
+
|
|
142
|
+
private async identifierExternalResolveByCoseKey(
|
|
143
|
+
args: ExternalIdentifierCoseKeyOpts,
|
|
144
|
+
context: IAgentContext<any>
|
|
145
|
+
): Promise<ExternalIdentifierCoseKeyResult> {
|
|
146
|
+
return (await this.identifierResolveExternal({ ...args, method: 'cose_key' }, context)) as ExternalIdentifierCoseKeyResult
|
|
147
|
+
}
|
|
148
|
+
private async identifierExternalResolveByJwk(args: ExternalIdentifierJwkOpts, context: IAgentContext<any>): Promise<ExternalIdentifierJwkResult> {
|
|
149
|
+
return (await this.identifierResolveExternal({ ...args, method: 'jwk' }, context)) as ExternalIdentifierJwkResult
|
|
150
|
+
}
|
|
98
151
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { IIdentifier } from '@veramo/core'
|
|
2
|
+
import { ManagedIdentifierDidOpts, ManagedIdentifierOptsOrResult } from '../types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts legacy id opts key refs to the new ManagedIdentifierOpts
|
|
6
|
+
* @param opts
|
|
7
|
+
*/
|
|
8
|
+
export function legacyKeyRefsToIdentifierOpts(opts: {
|
|
9
|
+
idOpts?: ManagedIdentifierOptsOrResult
|
|
10
|
+
iss?: string
|
|
11
|
+
keyRef?: string
|
|
12
|
+
didOpts?: any
|
|
13
|
+
}): ManagedIdentifierOptsOrResult {
|
|
14
|
+
if (!opts.idOpts) {
|
|
15
|
+
console.warn(
|
|
16
|
+
`Legacy idOpts being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
|
|
17
|
+
)
|
|
18
|
+
// legacy way
|
|
19
|
+
let kmsKeyRef =
|
|
20
|
+
opts.keyRef ??
|
|
21
|
+
opts.didOpts?.idOpts?.kmsKeyRef ??
|
|
22
|
+
opts.didOpts?.kid ??
|
|
23
|
+
opts.didOpts.idOpts?.kid ??
|
|
24
|
+
(typeof opts.didOpts?.idOpts.identifier === 'object' ? (opts.didOpts?.idOpts.identifier as IIdentifier).keys[0].kid : undefined)
|
|
25
|
+
if (!kmsKeyRef) {
|
|
26
|
+
throw Error('Key ref is needed for access token signer')
|
|
27
|
+
}
|
|
28
|
+
let identifier = (opts.didOpts?.identifier ?? opts.didOpts?.idOpts?.identifier) as IIdentifier | undefined
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
kmsKeyRef: opts.keyRef ?? kmsKeyRef,
|
|
32
|
+
identifier: identifier ?? kmsKeyRef,
|
|
33
|
+
issuer: opts.iss,
|
|
34
|
+
} satisfies ManagedIdentifierDidOpts
|
|
35
|
+
} else {
|
|
36
|
+
const idOpts = opts.idOpts
|
|
37
|
+
if (opts.keyRef && !idOpts.kmsKeyRef) {
|
|
38
|
+
// legacy way
|
|
39
|
+
console.warn(
|
|
40
|
+
`Legacy keyRef being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
|
|
41
|
+
)
|
|
42
|
+
idOpts.kmsKeyRef = opts.keyRef
|
|
43
|
+
}
|
|
44
|
+
if (opts.iss && !idOpts.issuer) {
|
|
45
|
+
// legacy way
|
|
46
|
+
console.warn(
|
|
47
|
+
`Legacy iss being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
|
|
48
|
+
)
|
|
49
|
+
idOpts.issuer = opts.iss
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return idOpts
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -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)) {
|
|
@@ -61,7 +71,7 @@ export async function resolveExternalX5cIdentifier(
|
|
|
61
71
|
const verify = opts.verify ?? true
|
|
62
72
|
const x5c = opts.identifier.map((derOrPem) => (derOrPem.includes('CERTIFICATE') ? PEMToDer(derOrPem) : derOrPem))
|
|
63
73
|
if (x5c.length === 0) {
|
|
64
|
-
return Promise.reject('Empty certification chain is
|
|
74
|
+
return Promise.reject('Empty certification chain is not allowed')
|
|
65
75
|
}
|
|
66
76
|
const certificates = x5c.map(pemOrDerToX509Certificate)
|
|
67
77
|
|
|
@@ -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
|
|
package/src/functions/index.ts
CHANGED
|
@@ -1,53 +1,3 @@
|
|
|
1
|
-
import { IIdentifier } from '@veramo/core'
|
|
2
|
-
import { ManagedIdentifierDidOpts, ManagedIdentifierOpts } from '../types'
|
|
3
|
-
|
|
4
1
|
export * from './managedIdentifierFunctions'
|
|
5
2
|
export * from './externalIdentifierFunctions'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Converts legacy id opts key refs to the new ManagedIdentifierOpts
|
|
9
|
-
* @param opts
|
|
10
|
-
*/
|
|
11
|
-
export function legacyKeyRefsToIdentifierOpts(opts: {
|
|
12
|
-
idOpts?: ManagedIdentifierOpts
|
|
13
|
-
iss?: string
|
|
14
|
-
keyRef?: string
|
|
15
|
-
didOpts?: any
|
|
16
|
-
}): ManagedIdentifierOpts {
|
|
17
|
-
if (!opts.idOpts) {
|
|
18
|
-
console.warn(
|
|
19
|
-
`Legacy idOpts being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
|
|
20
|
-
)
|
|
21
|
-
// legacy way
|
|
22
|
-
let kmsKeyRef =
|
|
23
|
-
opts.keyRef ??
|
|
24
|
-
opts.didOpts?.idOpts?.kmsKeyRef ??
|
|
25
|
-
(typeof opts.didOpts?.idOpts.identifier === 'object' ? (opts.didOpts?.idOpts.identifier as IIdentifier).keys[0].kid : undefined)
|
|
26
|
-
if (!kmsKeyRef) {
|
|
27
|
-
throw Error('Key ref is needed for access token signer')
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
kmsKeyRef: opts.keyRef ?? kmsKeyRef,
|
|
31
|
-
identifier: kmsKeyRef,
|
|
32
|
-
issuer: opts.iss,
|
|
33
|
-
} satisfies ManagedIdentifierDidOpts
|
|
34
|
-
} else {
|
|
35
|
-
const idOpts = opts.idOpts
|
|
36
|
-
if (opts.keyRef && !idOpts.kmsKeyRef) {
|
|
37
|
-
// legacy way
|
|
38
|
-
console.warn(
|
|
39
|
-
`Legacy keyRef being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
|
|
40
|
-
)
|
|
41
|
-
idOpts.kmsKeyRef = opts.keyRef
|
|
42
|
-
}
|
|
43
|
-
if (opts.iss && !idOpts.issuer) {
|
|
44
|
-
// legacy way
|
|
45
|
-
console.warn(
|
|
46
|
-
`Legacy iss being used. Support will be dropped in the future. Consider switching to the idOpts, to have support for DIDs, JWKS, x5c etc. See https://github.com/Sphereon-Opensource/SSI-SDK-crypto-extensions/tree/feature/multi_identifier_support/packages/identifier-resolution`
|
|
47
|
-
)
|
|
48
|
-
idOpts.issuer = opts.iss
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return idOpts
|
|
52
|
-
}
|
|
53
|
-
}
|
|
3
|
+
export * from './LegacySupport'
|