@sphereon/ssi-sdk-ext.identifier-resolution 0.28.1-feature.oyd.cmsm.improv.21 → 0.28.1-next.53
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/index.cjs +12080 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +439 -0
- package/dist/index.d.ts +434 -7
- package/dist/index.js +12047 -27
- package/dist/index.js.map +1 -1
- package/package.json +34 -21
- package/plugin.schema.json +7927 -1289
- package/src/agent/IdentifierResolution.ts +40 -39
- package/src/functions/LegacySupport.ts +2 -2
- package/src/functions/externalIdentifierFunctions.ts +27 -18
- package/src/functions/externalOIDFIdentifier.ts +9 -7
- package/src/functions/managedIdentifierFunctions.ts +25 -19
- package/src/index.ts +1 -1
- package/src/types/IIdentifierResolution.ts +4 -4
- package/src/types/IJwtService.d.ts +6 -5
- package/src/types/common.ts +4 -4
- package/src/types/externalIdentifierTypes.ts +7 -7
- package/src/types/managedIdentifierTypes.ts +4 -4
- package/dist/agent/IdentifierResolution.d.ts +0 -38
- package/dist/agent/IdentifierResolution.d.ts.map +0 -1
- package/dist/agent/IdentifierResolution.js +0 -123
- package/dist/agent/IdentifierResolution.js.map +0 -1
- package/dist/functions/LegacySupport.d.ts +0 -12
- package/dist/functions/LegacySupport.d.ts.map +0 -1
- package/dist/functions/LegacySupport.js +0 -39
- package/dist/functions/LegacySupport.js.map +0 -1
- package/dist/functions/externalIdentifierFunctions.d.ts +0 -26
- package/dist/functions/externalIdentifierFunctions.d.ts.map +0 -1
- package/dist/functions/externalIdentifierFunctions.js +0 -250
- package/dist/functions/externalIdentifierFunctions.js.map +0 -1
- package/dist/functions/externalOIDFIdentifier.d.ts +0 -19
- package/dist/functions/externalOIDFIdentifier.d.ts.map +0 -1
- package/dist/functions/externalOIDFIdentifier.js +0 -106
- package/dist/functions/externalOIDFIdentifier.js.map +0 -1
- package/dist/functions/index.d.ts +0 -5
- package/dist/functions/index.d.ts.map +0 -1
- package/dist/functions/index.js +0 -21
- package/dist/functions/index.js.map +0 -1
- package/dist/functions/managedIdentifierFunctions.d.ts +0 -38
- package/dist/functions/managedIdentifierFunctions.d.ts.map +0 -1
- package/dist/functions/managedIdentifierFunctions.js +0 -359
- package/dist/functions/managedIdentifierFunctions.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/IIdentifierResolution.d.ts +0 -42
- package/dist/types/IIdentifierResolution.d.ts.map +0 -1
- package/dist/types/IIdentifierResolution.js +0 -21
- package/dist/types/IIdentifierResolution.js.map +0 -1
- package/dist/types/common.d.ts +0 -20
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/common.js +0 -51
- package/dist/types/common.js.map +0 -1
- package/dist/types/externalIdentifierTypes.d.ts +0 -114
- package/dist/types/externalIdentifierTypes.d.ts.map +0 -1
- package/dist/types/externalIdentifierTypes.js +0 -44
- package/dist/types/externalIdentifierTypes.js.map +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -21
- package/dist/types/index.js.map +0 -1
- package/dist/types/managedIdentifierTypes.d.ts +0 -122
- package/dist/types/managedIdentifierTypes.d.ts.map +0 -1
- package/dist/types/managedIdentifierTypes.js +0 -63
- package/dist/types/managedIdentifierTypes.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { globalCrypto } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
2
|
-
import { IAgentContext, IAgentPlugin, IDIDManager, IKeyManager } from '@veramo/core'
|
|
3
|
-
import { ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult } from '../types'
|
|
4
|
-
import { schema } from '
|
|
2
|
+
import type { IAgentContext, IAgentPlugin, IDIDManager, IKeyManager } from '@veramo/core'
|
|
3
|
+
import type { ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult } from '../types'
|
|
4
|
+
import { schema } from '../index'
|
|
5
5
|
import { resolveExternalIdentifier, ensureManagedIdentifierResult } from '../functions'
|
|
6
|
-
import {
|
|
6
|
+
import type {
|
|
7
7
|
ExternalIdentifierDidOpts,
|
|
8
8
|
ExternalIdentifierDidResult,
|
|
9
9
|
ExternalIdentifierOpts,
|
|
@@ -32,26 +32,28 @@ import {
|
|
|
32
32
|
ManagedIdentifierOptsOrResult,
|
|
33
33
|
ManagedIdentifierOID4VCIssuerOpts,
|
|
34
34
|
} from '../types'
|
|
35
|
-
import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
|
|
35
|
+
import type { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
|
|
36
|
+
|
|
37
|
+
import { webcrypto } from 'node:crypto'
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
40
|
* @public
|
|
39
41
|
*/
|
|
40
42
|
export class IdentifierResolution implements IAgentPlugin {
|
|
41
|
-
|
|
43
|
+
readonly _crypto: webcrypto.Crypto
|
|
42
44
|
|
|
43
45
|
readonly schema = schema.IMnemonicInfoGenerator
|
|
44
46
|
readonly methods: IIdentifierResolution = {
|
|
45
|
-
identifierManagedGet: this.
|
|
46
|
-
identifierManagedGetByDid: this.
|
|
47
|
-
identifierManagedGetByKid: this.
|
|
48
|
-
identifierManagedGetByJwk: this.
|
|
49
|
-
identifierManagedGetByX5c: this.
|
|
50
|
-
identifierManagedGetByKey: this.
|
|
51
|
-
identifierManagedGetByCoseKey: this.
|
|
52
|
-
identifierManagedGetByOID4VCIssuer: this.
|
|
53
|
-
|
|
54
|
-
identifierExternalResolve: this.
|
|
47
|
+
identifierManagedGet: this.identifierManagedGet.bind(this),
|
|
48
|
+
identifierManagedGetByDid: this.identifierManagedGetByDid.bind(this),
|
|
49
|
+
identifierManagedGetByKid: this.identifierManagedGetByKid.bind(this),
|
|
50
|
+
identifierManagedGetByJwk: this.identifierManagedGetByJwk.bind(this),
|
|
51
|
+
identifierManagedGetByX5c: this.identifierManagedGetByX5c.bind(this),
|
|
52
|
+
identifierManagedGetByKey: this.identifierManagedGetByKey.bind(this),
|
|
53
|
+
identifierManagedGetByCoseKey: this.identifierManagedGetByCoseKey.bind(this),
|
|
54
|
+
identifierManagedGetByOID4VCIssuer: this.identifierManagedGetByOID4VCIssuer.bind(this),
|
|
55
|
+
|
|
56
|
+
identifierExternalResolve: this.identifierExternalResolve.bind(this),
|
|
55
57
|
identifierExternalResolveByDid: this.identifierExternalResolveByDid.bind(this),
|
|
56
58
|
identifierExternalResolveByX5c: this.identifierExternalResolveByX5c.bind(this),
|
|
57
59
|
identifierExternalResolveByJwk: this.identifierExternalResolveByJwk.bind(this),
|
|
@@ -64,7 +66,7 @@ export class IdentifierResolution implements IAgentPlugin {
|
|
|
64
66
|
/**
|
|
65
67
|
* TODO: Add a cache, as we are retrieving the same keys/info quite often
|
|
66
68
|
*/
|
|
67
|
-
constructor(opts?: { crypto?: Crypto }) {
|
|
69
|
+
constructor(opts?: { crypto?: webcrypto.Crypto }) {
|
|
68
70
|
this._crypto = globalCrypto(false, opts?.crypto)
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -73,65 +75,64 @@ export class IdentifierResolution implements IAgentPlugin {
|
|
|
73
75
|
* integrate a plugin for anomaly detection. Having a single method helps
|
|
74
76
|
* @param args
|
|
75
77
|
* @param context
|
|
76
|
-
* @private
|
|
77
78
|
*/
|
|
78
|
-
private async
|
|
79
|
+
private async identifierManagedGet(
|
|
79
80
|
args: ManagedIdentifierOptsOrResult,
|
|
80
81
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
81
82
|
): Promise<ManagedIdentifierResult> {
|
|
82
83
|
return await ensureManagedIdentifierResult({ ...args, crypto: this._crypto }, context)
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
private async
|
|
86
|
+
private async identifierManagedGetByDid(
|
|
86
87
|
args: ManagedIdentifierDidOpts,
|
|
87
88
|
context: IAgentContext<IKeyManager & IDIDManager & IIdentifierResolution>
|
|
88
89
|
): Promise<ManagedIdentifierDidResult> {
|
|
89
|
-
return (await this.
|
|
90
|
+
return (await this.identifierManagedGet({ ...args, method: 'did' }, context)) as ManagedIdentifierDidResult
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
private async
|
|
93
|
+
private async identifierManagedGetByKid(
|
|
93
94
|
args: ManagedIdentifierKidOpts,
|
|
94
95
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
95
96
|
): Promise<ManagedIdentifierKidResult> {
|
|
96
|
-
return (await this.
|
|
97
|
+
return (await this.identifierManagedGet({ ...args, method: 'kid' }, context)) as ManagedIdentifierKidResult
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
private async
|
|
100
|
+
private async identifierManagedGetByKey(
|
|
100
101
|
args: ManagedIdentifierKeyOpts,
|
|
101
102
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
102
103
|
): Promise<ManagedIdentifierKeyResult> {
|
|
103
|
-
return (await this.
|
|
104
|
+
return (await this.identifierManagedGet({ ...args, method: 'key' }, context)) as ManagedIdentifierKeyResult
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
private async
|
|
107
|
+
private async identifierManagedGetByCoseKey(
|
|
107
108
|
args: ManagedIdentifierCoseKeyOpts,
|
|
108
109
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
109
110
|
): Promise<ManagedIdentifierCoseKeyResult> {
|
|
110
|
-
return (await this.
|
|
111
|
+
return (await this.identifierManagedGet({ ...args, method: 'cose_key' }, context)) as ManagedIdentifierCoseKeyResult
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
private async
|
|
114
|
+
private async identifierManagedGetByOID4VCIssuer(
|
|
114
115
|
args: ManagedIdentifierOID4VCIssuerOpts,
|
|
115
116
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
116
117
|
): Promise<ManagedIdentifierOID4VCIssuerResult> {
|
|
117
|
-
return (await this.
|
|
118
|
+
return (await this.identifierManagedGet({ ...args, method: 'oid4vci-issuer' }, context)) as ManagedIdentifierOID4VCIssuerResult
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
private async
|
|
121
|
+
private async identifierManagedGetByJwk(
|
|
121
122
|
args: ManagedIdentifierJwkOpts,
|
|
122
123
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
123
124
|
): Promise<ManagedIdentifierJwkResult> {
|
|
124
|
-
return (await this.
|
|
125
|
+
return (await this.identifierManagedGet({ ...args, method: 'jwk' }, context)) as ManagedIdentifierJwkResult
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
private async
|
|
128
|
+
private async identifierManagedGetByX5c(
|
|
128
129
|
args: ManagedIdentifierX5cOpts,
|
|
129
130
|
context: IAgentContext<IKeyManager & IIdentifierResolution>
|
|
130
131
|
): Promise<ManagedIdentifierX5cResult> {
|
|
131
|
-
return (await this.
|
|
132
|
+
return (await this.identifierManagedGet({ ...args, method: 'x5c' }, context)) as ManagedIdentifierX5cResult
|
|
132
133
|
}
|
|
133
134
|
|
|
134
|
-
private async
|
|
135
|
+
private async identifierExternalResolve(
|
|
135
136
|
args: ExternalIdentifierOpts,
|
|
136
137
|
context: IAgentContext<IKeyManager | IOIDFClient>
|
|
137
138
|
): Promise<ExternalIdentifierResult> {
|
|
@@ -139,28 +140,28 @@ export class IdentifierResolution implements IAgentPlugin {
|
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
private async identifierExternalResolveByDid(args: ExternalIdentifierDidOpts, context: IAgentContext<any>): Promise<ExternalIdentifierDidResult> {
|
|
142
|
-
return (await this.
|
|
143
|
+
return (await this.identifierExternalResolve({ ...args, method: 'did' }, context)) as ExternalIdentifierDidResult
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
private async identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult> {
|
|
146
|
-
return (await this.
|
|
147
|
+
return (await this.identifierExternalResolve({ ...args, method: 'x5c' }, context)) as ExternalIdentifierX5cResult
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
private async identifierExternalResolveByCoseKey(
|
|
150
151
|
args: ExternalIdentifierCoseKeyOpts,
|
|
151
152
|
context: IAgentContext<any>
|
|
152
153
|
): Promise<ExternalIdentifierCoseKeyResult> {
|
|
153
|
-
return (await this.
|
|
154
|
+
return (await this.identifierExternalResolve({ ...args, method: 'cose_key' }, context)) as ExternalIdentifierCoseKeyResult
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
private async identifierExternalResolveByJwk(args: ExternalIdentifierJwkOpts, context: IAgentContext<any>): Promise<ExternalIdentifierJwkResult> {
|
|
157
|
-
return (await this.
|
|
158
|
+
return (await this.identifierExternalResolve({ ...args, method: 'jwk' }, context)) as ExternalIdentifierJwkResult
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
private async identifierExternalResolveByOIDFEntityId(
|
|
161
162
|
args: ExternalIdentifierOIDFEntityIdOpts,
|
|
162
163
|
context: IAgentContext<any>
|
|
163
164
|
): Promise<ExternalIdentifierOIDFEntityIdResult> {
|
|
164
|
-
return (await this.
|
|
165
|
+
return (await this.identifierExternalResolve({ ...args, method: 'entity_id' }, context)) as ExternalIdentifierOIDFEntityIdResult
|
|
165
166
|
}
|
|
166
167
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IIdentifier } from '@veramo/core'
|
|
2
|
-
import { ManagedIdentifierDidOpts, ManagedIdentifierOptsOrResult } from '../types'
|
|
1
|
+
import type { IIdentifier } from '@veramo/core'
|
|
2
|
+
import type { ManagedIdentifierDidOpts, ManagedIdentifierOptsOrResult } from '../types'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Converts legacy id opts key refs to the new ManagedIdentifierOpts
|
|
@@ -5,14 +5,14 @@ import {
|
|
|
5
5
|
pemOrDerToX509Certificate,
|
|
6
6
|
PEMToDer,
|
|
7
7
|
validateX509CertificateChain,
|
|
8
|
-
X509ValidationResult,
|
|
8
|
+
type X509ValidationResult,
|
|
9
9
|
} from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
10
10
|
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
|
|
11
|
-
import { IParsedDID, JWK, parseDid } from '@sphereon/ssi-types'
|
|
12
|
-
import { IAgentContext, IDIDManager, IResolver } from '@veramo/core'
|
|
11
|
+
import { type IParsedDID, type JWK, parseDid } from '@sphereon/ssi-types'
|
|
12
|
+
import type { IAgentContext, IDIDManager, IResolver } from '@veramo/core'
|
|
13
13
|
import { isDefined } from '@veramo/utils'
|
|
14
14
|
import { CryptoEngine, setEngine } from 'pkijs'
|
|
15
|
-
import {
|
|
15
|
+
import type {
|
|
16
16
|
ExternalIdentifierCoseKeyOpts,
|
|
17
17
|
ExternalIdentifierCoseKeyResult,
|
|
18
18
|
ExternalIdentifierDidOpts,
|
|
@@ -25,6 +25,8 @@ import {
|
|
|
25
25
|
ExternalIdentifierX5cOpts,
|
|
26
26
|
ExternalIdentifierX5cResult,
|
|
27
27
|
ExternalJwkInfo,
|
|
28
|
+
} from '../types'
|
|
29
|
+
import {
|
|
28
30
|
isExternalIdentifierCoseKeyOpts,
|
|
29
31
|
isExternalIdentifierDidOpts,
|
|
30
32
|
isExternalIdentifierJwkOpts,
|
|
@@ -36,9 +38,10 @@ import {
|
|
|
36
38
|
} from '../types'
|
|
37
39
|
import { resolveExternalOIDFEntityIdIdentifier } from '.'
|
|
38
40
|
|
|
41
|
+
import { webcrypto } from 'node:crypto'
|
|
39
42
|
export async function resolveExternalIdentifier(
|
|
40
43
|
opts: ExternalIdentifierOpts & {
|
|
41
|
-
crypto?: Crypto
|
|
44
|
+
crypto?: webcrypto.Crypto
|
|
42
45
|
},
|
|
43
46
|
context: IAgentContext<any>
|
|
44
47
|
): Promise<ExternalIdentifierResult> {
|
|
@@ -65,7 +68,7 @@ export async function resolveExternalIdentifier(
|
|
|
65
68
|
|
|
66
69
|
export async function resolveExternalX5cIdentifier(
|
|
67
70
|
opts: ExternalIdentifierX5cOpts & {
|
|
68
|
-
crypto?: Crypto
|
|
71
|
+
crypto?: webcrypto.Crypto
|
|
69
72
|
},
|
|
70
73
|
context: IAgentContext<IResolver & IDIDManager>
|
|
71
74
|
): Promise<ExternalIdentifierX5cResult> {
|
|
@@ -245,18 +248,24 @@ export async function resolveExternalDidIdentifier(
|
|
|
245
248
|
const didDocument = didResolutionResult.didDocument ?? undefined
|
|
246
249
|
const didJwks = didDocument ? didDocumentToJwks(didDocument) : undefined
|
|
247
250
|
const jwks = didJwks
|
|
248
|
-
? Array.from(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
.
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
251
|
+
? Array.from(
|
|
252
|
+
new Set(
|
|
253
|
+
Array.from(
|
|
254
|
+
Object.values(didJwks)
|
|
255
|
+
.filter((jwks) => isDefined(jwks) && jwks.length > 0)
|
|
256
|
+
.flatMap((jwks) => jwks)
|
|
257
|
+
)
|
|
258
|
+
.flatMap((jwk) => {
|
|
259
|
+
return {
|
|
260
|
+
jwk,
|
|
261
|
+
jwkThumbprint: calculateJwkThumbprint({ jwk }),
|
|
262
|
+
kid: jwk.kid,
|
|
263
|
+
publicKeyHex: jwkTtoPublicKeyHex(jwk),
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
.map((jwk) => JSON.stringify(jwk))
|
|
267
|
+
)
|
|
268
|
+
).map((jwks) => JSON.parse(jwks))
|
|
260
269
|
: []
|
|
261
270
|
|
|
262
271
|
if (didResolutionResult?.didDocument) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ErrorMessage, ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult, ExternalJwkInfo, TrustedAnchor } from '../types'
|
|
2
|
-
import { IAgentContext } from '@veramo/core'
|
|
3
|
-
import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
|
|
1
|
+
import type { ErrorMessage, ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult, ExternalJwkInfo, TrustedAnchor } from '../types'
|
|
2
|
+
import type { IAgentContext } from '@veramo/core'
|
|
3
|
+
import type { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
|
|
4
4
|
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
|
|
5
|
-
import {IJwsValidationResult, JwsPayload} from '../types/IJwtService'
|
|
5
|
+
import type { IJwsValidationResult, JwsPayload } from '../types/IJwtService'
|
|
6
|
+
// @ts-ignore
|
|
6
7
|
import * as u8a from 'uint8arrays'
|
|
8
|
+
const { fromString, toString } = u8a
|
|
7
9
|
/**
|
|
8
10
|
* Resolves an OIDF Entity ID against multiple trust anchors to establish trusted relationships
|
|
9
11
|
*
|
|
@@ -43,10 +45,10 @@ export async function resolveExternalOIDFEntityIdIdentifier(
|
|
|
43
45
|
trustAnchors: [trustAnchor],
|
|
44
46
|
})
|
|
45
47
|
|
|
46
|
-
if (resolveResult.
|
|
48
|
+
if (resolveResult.errorMessage || !resolveResult.trustChain) {
|
|
47
49
|
errorList[trustAnchor] = resolveResult.errorMessage ?? 'unspecified'
|
|
48
50
|
} else {
|
|
49
|
-
const trustChain
|
|
51
|
+
const trustChain = resolveResult.trustChain
|
|
50
52
|
if (trustChain.length === 0) {
|
|
51
53
|
errorList[trustAnchor] = 'Trust chain is empty'
|
|
52
54
|
continue
|
|
@@ -65,7 +67,7 @@ export async function resolveExternalOIDFEntityIdIdentifier(
|
|
|
65
67
|
continue
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
payload = JSON.parse(
|
|
70
|
+
payload = JSON.parse(toString(fromString(jwtVerifyResult.jws.payload, 'base64url')))
|
|
69
71
|
const signature = jwtVerifyResult.jws.signatures[0]
|
|
70
72
|
if (signature.identifier.jwks.length === 0) {
|
|
71
73
|
errorList[trustAnchor] = 'No JWK was present in the trust anchor signature'
|
|
@@ -2,21 +2,12 @@ import { getFirstKeyWithRelation } from '@sphereon/ssi-sdk-ext.did-utils'
|
|
|
2
2
|
import { calculateJwkThumbprint, coseKeyToJwk, globalCrypto, 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'
|
|
6
|
-
import { IAgentContext, IIdentifier, IKey, IKeyManager } from '@veramo/core'
|
|
5
|
+
import type { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
6
|
+
import type { IAgentContext, IIdentifier, IKey, IKeyManager } from '@veramo/core'
|
|
7
7
|
import { CryptoEngine, setEngine } from 'pkijs'
|
|
8
|
-
import {
|
|
8
|
+
import { webcrypto } from 'node:crypto'
|
|
9
|
+
import type {
|
|
9
10
|
IIdentifierResolution,
|
|
10
|
-
isManagedIdentifierCoseKeyOpts,
|
|
11
|
-
isManagedIdentifierDidOpts,
|
|
12
|
-
isManagedIdentifierDidResult,
|
|
13
|
-
isManagedIdentifierOID4VCIssuerOpts,
|
|
14
|
-
isManagedIdentifierJwkOpts,
|
|
15
|
-
isManagedIdentifierJwkResult,
|
|
16
|
-
isManagedIdentifierKeyOpts,
|
|
17
|
-
isManagedIdentifierKeyResult,
|
|
18
|
-
isManagedIdentifierKidOpts,
|
|
19
|
-
isManagedIdentifierX5cOpts,
|
|
20
11
|
ManagedIdentifierCoseKeyOpts,
|
|
21
12
|
ManagedIdentifierCoseKeyResult,
|
|
22
13
|
ManagedIdentifierDidOpts,
|
|
@@ -35,6 +26,19 @@ import {
|
|
|
35
26
|
ManagedIdentifierX5cResult,
|
|
36
27
|
} from '../types'
|
|
37
28
|
|
|
29
|
+
import {
|
|
30
|
+
isManagedIdentifierCoseKeyOpts,
|
|
31
|
+
isManagedIdentifierDidOpts,
|
|
32
|
+
isManagedIdentifierDidResult,
|
|
33
|
+
isManagedIdentifierOID4VCIssuerOpts,
|
|
34
|
+
isManagedIdentifierJwkOpts,
|
|
35
|
+
isManagedIdentifierJwkResult,
|
|
36
|
+
isManagedIdentifierKeyOpts,
|
|
37
|
+
isManagedIdentifierKeyResult,
|
|
38
|
+
isManagedIdentifierKidOpts,
|
|
39
|
+
isManagedIdentifierX5cOpts,
|
|
40
|
+
} from '../types'
|
|
41
|
+
|
|
38
42
|
export async function getManagedKidIdentifier(
|
|
39
43
|
opts: ManagedIdentifierKidOpts,
|
|
40
44
|
context: IAgentContext<IKeyManager>
|
|
@@ -47,13 +51,13 @@ export async function getManagedKidIdentifier(
|
|
|
47
51
|
return Promise.reject(Error(`Cannot get Key/JWK identifier if KeyManager plugin is not enabled!`))
|
|
48
52
|
} else if (opts.identifier.startsWith('did:')) {
|
|
49
53
|
const did = opts.identifier.split('#')[0]
|
|
50
|
-
const didIdentifier = await getManagedDidIdentifier({...opts, method: 'did', identifier: did}, context)
|
|
54
|
+
const didIdentifier = await getManagedDidIdentifier({ ...opts, method: 'did', identifier: did }, context)
|
|
51
55
|
key = didIdentifier.key
|
|
52
56
|
issuer = didIdentifier.issuer
|
|
53
57
|
kid = opts?.kid ?? (key.meta?.verificationMethod?.id as string) ?? didIdentifier.kid
|
|
54
58
|
}
|
|
55
59
|
if (!key) {
|
|
56
|
-
key = await context.agent.keyManagerGet({kid: opts.kmsKeyRef ?? opts.identifier})
|
|
60
|
+
key = await context.agent.keyManagerGet({ kid: opts.kmsKeyRef ?? opts.identifier })
|
|
57
61
|
}
|
|
58
62
|
const jwk = toJwk(key.publicKeyHex, key.type, { key })
|
|
59
63
|
const jwkThumbprint = (key.meta?.jwkThumbprint as string) ?? calculateJwkThumbprint({ jwk })
|
|
@@ -80,7 +84,7 @@ export async function getManagedKidIdentifier(
|
|
|
80
84
|
|
|
81
85
|
export function isManagedIdentifierResult(
|
|
82
86
|
identifier: ManagedIdentifierOptsOrResult & {
|
|
83
|
-
crypto?: Crypto
|
|
87
|
+
crypto?: webcrypto.Crypto
|
|
84
88
|
}
|
|
85
89
|
): identifier is ManagedIdentifierResult {
|
|
86
90
|
return 'key' in identifier && 'kmsKeyRef' in identifier && 'method' in identifier && 'opts' in identifier && 'jwkThumbprint' in identifier
|
|
@@ -93,7 +97,7 @@ export function isManagedIdentifierResult(
|
|
|
93
97
|
*/
|
|
94
98
|
export async function ensureManagedIdentifierResult(
|
|
95
99
|
identifier: ManagedIdentifierOptsOrResult & {
|
|
96
|
-
crypto?: Crypto
|
|
100
|
+
crypto?: webcrypto.Crypto
|
|
97
101
|
},
|
|
98
102
|
context: IAgentContext<IKeyManager>
|
|
99
103
|
): Promise<ManagedIdentifierResult> {
|
|
@@ -183,6 +187,8 @@ export async function getManagedDidIdentifier(opts: ManagedIdentifierDidOpts, co
|
|
|
183
187
|
const extendedKey = await getFirstKeyWithRelation(
|
|
184
188
|
{
|
|
185
189
|
...opts,
|
|
190
|
+
// Make sure we use offline mode if no pref was supplied. We are looking for managed DIDs after all. Could be it is not published yet
|
|
191
|
+
offlineWhenNoDIDRegistered: opts.offlineWhenNoDIDRegistered ?? true,
|
|
186
192
|
identifier,
|
|
187
193
|
vmRelationship: opts.vmRelationship ?? 'verificationMethod',
|
|
188
194
|
},
|
|
@@ -247,7 +253,7 @@ export async function getManagedJwkIdentifier(
|
|
|
247
253
|
|
|
248
254
|
export async function getManagedX5cIdentifier(
|
|
249
255
|
opts: ManagedIdentifierX5cOpts & {
|
|
250
|
-
crypto?: Crypto
|
|
256
|
+
crypto?: webcrypto.Crypto
|
|
251
257
|
},
|
|
252
258
|
context: IAgentContext<IKeyManager>
|
|
253
259
|
): Promise<ManagedIdentifierX5cResult> {
|
|
@@ -331,7 +337,7 @@ export async function getManagedOID4VCIssuerIdentifier(
|
|
|
331
337
|
|
|
332
338
|
export async function getManagedIdentifier(
|
|
333
339
|
opts: ManagedIdentifierOptsOrResult & {
|
|
334
|
-
crypto?: Crypto
|
|
340
|
+
crypto?: webcrypto.Crypto
|
|
335
341
|
},
|
|
336
342
|
context: IAgentContext<IKeyManager>
|
|
337
343
|
): Promise<ManagedIdentifierResult> {
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
2
|
-
import {
|
|
1
|
+
import type { IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
2
|
+
import type {
|
|
3
3
|
ExternalIdentifierCoseKeyOpts,
|
|
4
4
|
ExternalIdentifierCoseKeyResult,
|
|
5
5
|
ExternalIdentifierDidOpts,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
ExternalIdentifierX5cOpts,
|
|
14
14
|
ExternalIdentifierX5cResult,
|
|
15
15
|
} from './externalIdentifierTypes'
|
|
16
|
-
import {
|
|
16
|
+
import type {
|
|
17
17
|
ManagedIdentifierCoseKeyOpts,
|
|
18
18
|
ManagedIdentifierCoseKeyResult,
|
|
19
19
|
ManagedIdentifierDidOpts,
|
|
@@ -41,7 +41,7 @@ export const identifierResolutionContextMethods: Array<string> = [
|
|
|
41
41
|
'identifierManagedGetByX5c',
|
|
42
42
|
'identifierManagedGetByKey',
|
|
43
43
|
'identifierManagedGetByOID4VCIssuer',
|
|
44
|
-
'
|
|
44
|
+
'identifierManagedGetByCoseKey',
|
|
45
45
|
'identifierExternalResolve',
|
|
46
46
|
'identifierExternalResolveByDid',
|
|
47
47
|
'identifierExternalResolveByX5c',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Copy of jwt-service typings since we cannot include that as devDependency due to cyclic dep
|
|
2
|
-
|
|
2
|
+
/*
|
|
3
3
|
import {
|
|
4
4
|
ExternalIdentifierDidOpts,
|
|
5
5
|
ExternalIdentifierResult,
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
IIdentifierResolution,
|
|
8
8
|
ManagedIdentifierOptsOrResult,
|
|
9
9
|
ManagedIdentifierResult,
|
|
10
|
-
} from '
|
|
11
|
-
import { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
12
|
-
import { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types'
|
|
13
|
-
import { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
10
|
+
} from '../types'*/
|
|
11
|
+
import type { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
12
|
+
import type { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types'
|
|
13
|
+
import type { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core'
|
|
14
14
|
export type IRequiredContext = IAgentContext<IIdentifierResolution & IKeyManager>
|
|
15
15
|
export declare const jwtServiceContextMethods: Array<string>
|
|
16
16
|
export interface IJwtService extends IPluginMethodMap {
|
|
@@ -25,6 +25,7 @@ export interface IJwtService extends IPluginMethodMap {
|
|
|
25
25
|
export type IJwsValidationResult = IValidationResult & {
|
|
26
26
|
jws: JwsJsonGeneralWithIdentifiers
|
|
27
27
|
}
|
|
28
|
+
|
|
28
29
|
export interface PreparedJws {
|
|
29
30
|
protectedHeader: JwsHeader
|
|
30
31
|
payload: Uint8Array
|
package/src/types/common.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
2
|
-
import { IIdentifier, IKey } from '@veramo/core'
|
|
3
|
-
import { ExternalIdentifierType } from './externalIdentifierTypes'
|
|
4
|
-
import { ManagedIdentifierType } from './managedIdentifierTypes'
|
|
1
|
+
import type { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
2
|
+
import type { IIdentifier, IKey } from '@veramo/core'
|
|
3
|
+
import type { ExternalIdentifierType } from './externalIdentifierTypes'
|
|
4
|
+
import type { ManagedIdentifierType } from './managedIdentifierTypes'
|
|
5
5
|
|
|
6
6
|
export interface JwkInfo {
|
|
7
7
|
jwk: JWK
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DidDocumentJwks } from '@sphereon/ssi-sdk-ext.did-utils'
|
|
2
|
-
import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
3
|
-
import { X509CertificateChainValidationOpts, X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
4
|
-
import { IParsedDID } from '@sphereon/ssi-types'
|
|
5
|
-
import { DIDDocument, DIDDocumentSection, DIDResolutionResult } from '@veramo/core'
|
|
1
|
+
import type { DidDocumentJwks } from '@sphereon/ssi-sdk-ext.did-utils'
|
|
2
|
+
import type { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
3
|
+
import type { X509CertificateChainValidationOpts, X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
4
|
+
import type { IParsedDID } from '@sphereon/ssi-types'
|
|
5
|
+
import type { DIDDocument, DIDDocumentSection, DIDResolutionResult } from '@veramo/core'
|
|
6
6
|
import {
|
|
7
7
|
isCoseKeyIdentifier,
|
|
8
8
|
isDidIdentifier,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
isKidIdentifier,
|
|
13
13
|
isOidcDiscoveryIdentifier,
|
|
14
14
|
isX5cIdentifier,
|
|
15
|
-
JwkInfo,
|
|
15
|
+
type JwkInfo,
|
|
16
16
|
} from './common'
|
|
17
|
-
import {JwsPayload} from
|
|
17
|
+
import type { JwsPayload } from './IJwtService'
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Use whenever we need to resolve an external identifier. We can pass in kids, DIDs, and x5chains
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
2
|
-
import { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
3
|
-
import { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core'
|
|
1
|
+
import type { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
2
|
+
import type { ICoseKeyJson, JWK } from '@sphereon/ssi-types'
|
|
3
|
+
import type { DIDDocumentSection, IIdentifier, IKey, TKeyType } from '@veramo/core'
|
|
4
4
|
import {
|
|
5
5
|
isCoseKeyIdentifier,
|
|
6
6
|
isDidIdentifier,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isKeyIdentifier,
|
|
10
10
|
isKidIdentifier,
|
|
11
11
|
isX5cIdentifier,
|
|
12
|
-
JwkInfo,
|
|
12
|
+
type JwkInfo,
|
|
13
13
|
} from './common'
|
|
14
14
|
|
|
15
15
|
/**
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { IAgentPlugin } from '@veramo/core';
|
|
2
|
-
import { IIdentifierResolution } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
*/
|
|
6
|
-
export declare class IdentifierResolution implements IAgentPlugin {
|
|
7
|
-
private readonly _crypto;
|
|
8
|
-
readonly schema: any;
|
|
9
|
-
readonly methods: IIdentifierResolution;
|
|
10
|
-
/**
|
|
11
|
-
* TODO: Add a cache, as we are retrieving the same keys/info quite often
|
|
12
|
-
*/
|
|
13
|
-
constructor(opts?: {
|
|
14
|
-
crypto?: Crypto;
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* Main method for managed identifiers. We always go through this method (also the other methods below) as we want to
|
|
18
|
-
* integrate a plugin for anomaly detection. Having a single method helps
|
|
19
|
-
* @param args
|
|
20
|
-
* @param context
|
|
21
|
-
* @private
|
|
22
|
-
*/
|
|
23
|
-
private identifierGetManaged;
|
|
24
|
-
private identifierGetManagedByDid;
|
|
25
|
-
private identifierGetManagedByKid;
|
|
26
|
-
private identifierGetManagedByKey;
|
|
27
|
-
private identifierGetManagedByCoseKey;
|
|
28
|
-
private identifierGetManagedByOID4VCIssuer;
|
|
29
|
-
private identifierGetManagedByJwk;
|
|
30
|
-
private identifierGetManagedByX5c;
|
|
31
|
-
private identifierResolveExternal;
|
|
32
|
-
private identifierExternalResolveByDid;
|
|
33
|
-
private identifierExternalResolveByX5c;
|
|
34
|
-
private identifierExternalResolveByCoseKey;
|
|
35
|
-
private identifierExternalResolveByJwk;
|
|
36
|
-
private identifierExternalResolveByOIDFEntityId;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=IdentifierResolution.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IdentifierResolution.d.ts","sourceRoot":"","sources":["../../src/agent/IdentifierResolution.ts"],"names":[],"mappings":"AACA,OAAO,EAAiB,YAAY,EAA4B,MAAM,cAAc,CAAA;AAIpF,OAAO,EAWL,qBAAqB,EAiBtB,MAAM,UAAU,CAAA;AAGjB;;GAEG;AACH,qBAAa,oBAAqB,YAAW,YAAY;IACvD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAEhC,QAAQ,CAAC,MAAM,MAAgC;IAC/C,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAkBtC;IAED;;OAEG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;IAItC;;;;;;OAMG;YACW,oBAAoB;YAOpB,yBAAyB;YAOzB,yBAAyB;YAOzB,yBAAyB;YAOzB,6BAA6B;YAO7B,kCAAkC;YAOlC,yBAAyB;YAOzB,yBAAyB;YAOzB,yBAAyB;YAOzB,8BAA8B;YAI9B,8BAA8B;YAI9B,kCAAkC;YAOlC,8BAA8B;YAI9B,uCAAuC;CAMtD"}
|