@sphereon/ssi-sdk.mdl-mdoc 0.32.1-next.54 → 0.33.1-feature.jose.vcdm.55
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 +2568 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +223 -0
- package/dist/index.d.ts +222 -6
- package/dist/index.js +2538 -25
- package/dist/index.js.map +1 -1
- package/package.json +35 -24
- package/src/agent/mDLMdoc.ts +49 -64
- package/src/functions/index.ts +36 -35
- package/src/types/ImDLMdoc.ts +25 -8
- package/dist/agent/mDLMdoc.d.ts +0 -68
- package/dist/agent/mDLMdoc.d.ts.map +0 -1
- package/dist/agent/mDLMdoc.js +0 -251
- package/dist/agent/mDLMdoc.js.map +0 -1
- package/dist/functions/index.d.ts +0 -47
- package/dist/functions/index.d.ts.map +0 -1
- package/dist/functions/index.js +0 -260
- package/dist/functions/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/ImDLMdoc.d.ts +0 -75
- package/dist/types/ImDLMdoc.d.ts.map +0 -1
- package/dist/types/ImDLMdoc.js +0 -3
- package/dist/types/ImDLMdoc.js.map +0 -1
package/src/agent/mDLMdoc.ts
CHANGED
|
@@ -1,54 +1,40 @@
|
|
|
1
1
|
import { com } from '@sphereon/kmp-mdoc-core'
|
|
2
2
|
import { calculateJwkThumbprint } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
3
|
-
import {
|
|
4
|
-
CertificateInfo,
|
|
5
|
-
getCertificateInfo,
|
|
6
|
-
pemOrDerToX509Certificate,
|
|
7
|
-
X509ValidationResult
|
|
8
|
-
} from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
3
|
+
import { CertificateInfo, getCertificateInfo, pemOrDerToX509Certificate, X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
9
4
|
import { JWK } from '@sphereon/ssi-types'
|
|
10
5
|
import { IAgentPlugin } from '@veramo/core'
|
|
11
|
-
import {
|
|
12
|
-
MdocOid4vpPresentArgs,
|
|
13
|
-
MdocOid4VPPresentationAuth,
|
|
14
|
-
MdocOid4vpRPVerifyArgs,
|
|
15
|
-
MdocOid4vpRPVerifyResult,
|
|
16
|
-
schema
|
|
17
|
-
} from '..'
|
|
6
|
+
import { MdocOid4vpPresentArgs, MdocOid4VPPresentationAuth, MdocOid4vpRPVerifyArgs, MdocOid4vpRPVerifyResult, MdocOid4vpService, schema } from '..'
|
|
18
7
|
import { CoseCryptoService, X509CallbackService } from '../functions'
|
|
19
8
|
import {
|
|
9
|
+
CborByteString,
|
|
10
|
+
CoseCryptoServiceJS,
|
|
11
|
+
CoseJoseKeyMappingService,
|
|
12
|
+
CoseKeyCbor,
|
|
13
|
+
DateTimeUtils,
|
|
14
|
+
decodeFrom,
|
|
15
|
+
DocumentCbor,
|
|
16
|
+
DocumentDescriptorMatchResult,
|
|
17
|
+
encodeTo,
|
|
18
|
+
Encoding,
|
|
20
19
|
GetX509CertificateInfoArgs,
|
|
21
20
|
ImDLMdoc,
|
|
21
|
+
IOid4VPPresentationDefinition,
|
|
22
22
|
IRequiredContext,
|
|
23
|
+
IVerifySignatureResult,
|
|
24
|
+
KeyInfo,
|
|
23
25
|
KeyType,
|
|
26
|
+
Oid4VPPresentationSubmission,
|
|
27
|
+
MdocValidations,
|
|
24
28
|
MdocVerifyIssuerSignedArgs,
|
|
25
|
-
VerifyCertificateChainArgs
|
|
29
|
+
VerifyCertificateChainArgs,
|
|
26
30
|
} from '../types/ImDLMdoc'
|
|
27
|
-
import CborByteString = com.sphereon.cbor.CborByteString
|
|
28
|
-
import CoseKeyCbor = com.sphereon.crypto.cose.CoseKeyCbor
|
|
29
|
-
import CoseSign1Json = com.sphereon.crypto.cose.CoseSign1Json
|
|
30
|
-
import CoseCryptoServiceJS = com.sphereon.crypto.CoseCryptoServiceJS
|
|
31
|
-
import CoseJoseKeyMappingService = com.sphereon.crypto.CoseJoseKeyMappingService
|
|
32
|
-
import IVerifySignatureResult = com.sphereon.crypto.generic.IVerifySignatureResult
|
|
33
|
-
import KeyInfo = com.sphereon.crypto.KeyInfo
|
|
34
|
-
import DateTimeUtils = com.sphereon.kmp.DateTimeUtils
|
|
35
|
-
import decodeFrom = com.sphereon.kmp.decodeFrom
|
|
36
|
-
import encodeTo = com.sphereon.kmp.encodeTo
|
|
37
|
-
import Encoding = com.sphereon.kmp.Encoding
|
|
38
|
-
import DeviceResponseCbor = com.sphereon.mdoc.data.device.DeviceResponseCbor
|
|
39
|
-
import DocumentCbor = com.sphereon.mdoc.data.device.DocumentCbor
|
|
40
|
-
import MdocValidations = com.sphereon.mdoc.data.MdocValidations
|
|
41
|
-
import DocumentDescriptorMatchResult = com.sphereon.mdoc.oid4vp.DocumentDescriptorMatchResult
|
|
42
|
-
import IOid4VPPresentationDefinition = com.sphereon.mdoc.oid4vp.IOid4VPPresentationDefinition
|
|
43
|
-
import MdocOid4vpService = com.sphereon.mdoc.oid4vp.MdocOid4vpServiceJs
|
|
44
|
-
import Oid4VPPresentationSubmission = com.sphereon.mdoc.oid4vp.Oid4VPPresentationSubmission
|
|
45
31
|
|
|
46
32
|
export const mdocSupportMethods: Array<string> = [
|
|
47
33
|
'x509VerifyCertificateChain',
|
|
48
34
|
'x509GetCertificateInfo',
|
|
49
35
|
'mdocVerifyIssuerSigned',
|
|
50
36
|
'mdocOid4vpHolderPresent',
|
|
51
|
-
'mdocOid4vpRPVerify'
|
|
37
|
+
'mdocOid4vpRPVerify',
|
|
52
38
|
]
|
|
53
39
|
|
|
54
40
|
/**
|
|
@@ -63,7 +49,7 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
63
49
|
x509GetCertificateInfo: this.x509GetCertificateInfo.bind(this),
|
|
64
50
|
mdocVerifyIssuerSigned: this.mdocVerifyIssuerSigned.bind(this),
|
|
65
51
|
mdocOid4vpHolderPresent: this.mdocOid4vpHolderPresent.bind(this),
|
|
66
|
-
mdocOid4vpRPVerify: this.mdocOid4vpRPVerify.bind(this)
|
|
52
|
+
mdocOid4vpRPVerify: this.mdocOid4vpRPVerify.bind(this),
|
|
67
53
|
}
|
|
68
54
|
private readonly trustAnchors: string[]
|
|
69
55
|
private opts: {
|
|
@@ -96,16 +82,7 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
96
82
|
* @return {Promise<MdocOid4VPPresentationAuth>} A promise that resolves to an object containing vp_token and presentation_submission.
|
|
97
83
|
*/
|
|
98
84
|
private async mdocOid4vpHolderPresent(args: MdocOid4vpPresentArgs, _context: IRequiredContext): Promise<MdocOid4VPPresentationAuth> {
|
|
99
|
-
const {
|
|
100
|
-
mdocs,
|
|
101
|
-
presentationDefinition,
|
|
102
|
-
trustAnchors,
|
|
103
|
-
verifications,
|
|
104
|
-
mdocHolderNonce,
|
|
105
|
-
authorizationRequestNonce,
|
|
106
|
-
responseUri,
|
|
107
|
-
clientId
|
|
108
|
-
} = args
|
|
85
|
+
const { mdocs, presentationDefinition, trustAnchors, verifications, mdocHolderNonce, authorizationRequestNonce, responseUri, clientId } = args
|
|
109
86
|
|
|
110
87
|
const oid4vpService = new MdocOid4vpService()
|
|
111
88
|
// const mdoc = DocumentCbor.Static.cborDecode(decodeFrom(mdocBase64Url, Encoding.BASE64URL))
|
|
@@ -116,7 +93,7 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
116
93
|
null,
|
|
117
94
|
trustAnchors ?? this.trustAnchors,
|
|
118
95
|
DateTimeUtils.Static.DEFAULT.dateTimeLocal((verifications?.verificationTime?.getTime() ?? Date.now()) / 1000),
|
|
119
|
-
verifications?.allowExpiredDocuments
|
|
96
|
+
verifications?.allowExpiredDocuments,
|
|
120
97
|
)
|
|
121
98
|
if (result.error) {
|
|
122
99
|
console.log(JSON.stringify(result, null, 2))
|
|
@@ -131,9 +108,9 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
131
108
|
name: 'mdoc',
|
|
132
109
|
error: true,
|
|
133
110
|
critical: true,
|
|
134
|
-
message: e.message as string
|
|
135
|
-
}
|
|
136
|
-
]
|
|
111
|
+
message: e.message as string,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
137
114
|
}
|
|
138
115
|
}
|
|
139
116
|
}
|
|
@@ -141,7 +118,7 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
141
118
|
const allMatches: DocumentDescriptorMatchResult[] = oid4vpService.matchDocumentsAndDescriptors(
|
|
142
119
|
mdocHolderNonce,
|
|
143
120
|
mdocs,
|
|
144
|
-
presentationDefinition as IOid4VPPresentationDefinition
|
|
121
|
+
presentationDefinition as IOid4VPPresentationDefinition,
|
|
145
122
|
)
|
|
146
123
|
const docsAndDescriptors: DocumentDescriptorMatchResult[] = []
|
|
147
124
|
let lastError: com.sphereon.crypto.generic.IVerifyResults<com.sphereon.crypto.cose.ICoseKeyCbor> | undefined = undefined
|
|
@@ -164,7 +141,16 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
164
141
|
const kms = key.kms
|
|
165
142
|
const kmsKeyRef = key.meta?.kmsKeyRef
|
|
166
143
|
const updateCborKey = cborKey.copy(false, cborKey.kty, cborKey.kid ?? new CborByteString(decodeFrom(kid, Encoding.UTF8)))
|
|
167
|
-
const deviceKeyInfo = KeyInfo.Static.fromDTO(keyInfo).copy(
|
|
144
|
+
const deviceKeyInfo = KeyInfo.Static.fromDTO(keyInfo).copy(
|
|
145
|
+
kid,
|
|
146
|
+
updateCborKey,
|
|
147
|
+
keyInfo.opts,
|
|
148
|
+
keyInfo.keyVisibility,
|
|
149
|
+
keyInfo.signatureAlgorithm,
|
|
150
|
+
keyInfo.x5c,
|
|
151
|
+
kmsKeyRef,
|
|
152
|
+
kms,
|
|
153
|
+
)
|
|
168
154
|
const updateMatch = match.copy(match.inputDescriptor, match.document, match.documentError, deviceKeyInfo)
|
|
169
155
|
match = updateMatch
|
|
170
156
|
}
|
|
@@ -172,7 +158,6 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
172
158
|
console.log(`We tied to ammend key info from the KMS, but failed. Potential trouble ahead ${e.message}`, e)
|
|
173
159
|
}
|
|
174
160
|
|
|
175
|
-
|
|
176
161
|
docsAndDescriptors.push(match)
|
|
177
162
|
} else if (result.error) {
|
|
178
163
|
lastError = result
|
|
@@ -190,11 +175,11 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
190
175
|
presentationDefinition as IOid4VPPresentationDefinition,
|
|
191
176
|
clientId,
|
|
192
177
|
responseUri,
|
|
193
|
-
authorizationRequestNonce
|
|
178
|
+
authorizationRequestNonce,
|
|
194
179
|
)
|
|
195
180
|
const vp_token = encodeTo(deviceResponse.cborEncode(), Encoding.BASE64URL)
|
|
196
181
|
const presentation_submission = Oid4VPPresentationSubmission.Static.fromPresentationDefinition(
|
|
197
|
-
presentationDefinition as IOid4VPPresentationDefinition
|
|
182
|
+
presentationDefinition as IOid4VPPresentationDefinition,
|
|
198
183
|
)
|
|
199
184
|
return { vp_token, presentation_submission }
|
|
200
185
|
}
|
|
@@ -209,7 +194,7 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
209
194
|
*/
|
|
210
195
|
private async mdocOid4vpRPVerify(args: MdocOid4vpRPVerifyArgs, _context: IRequiredContext): Promise<MdocOid4vpRPVerifyResult> {
|
|
211
196
|
const { vp_token, presentation_submission, trustAnchors } = args
|
|
212
|
-
const deviceResponse = DeviceResponseCbor.Static.cborDecode(decodeFrom(vp_token, Encoding.BASE64URL))
|
|
197
|
+
const deviceResponse = com.sphereon.mdoc.data.device.DeviceResponseCbor.Static.cborDecode(decodeFrom(vp_token, Encoding.BASE64URL))
|
|
213
198
|
if (!deviceResponse.documents) {
|
|
214
199
|
return Promise.reject(Error(`No documents found in vp_token`))
|
|
215
200
|
}
|
|
@@ -227,7 +212,7 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
227
212
|
name: 'mdoc',
|
|
228
213
|
error,
|
|
229
214
|
critical: error,
|
|
230
|
-
message: `No descriptor map id with document type ${document.docType.value} present
|
|
215
|
+
message: `No descriptor map id with document type ${document.docType.value} present`,
|
|
231
216
|
})
|
|
232
217
|
}
|
|
233
218
|
return { document: document.toJson(), validations }
|
|
@@ -242,13 +227,13 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
242
227
|
name: 'mdoc',
|
|
243
228
|
error,
|
|
244
229
|
critical: true,
|
|
245
|
-
message: e.message as string
|
|
246
|
-
}
|
|
247
|
-
]
|
|
248
|
-
}
|
|
230
|
+
message: e.message as string,
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
},
|
|
249
234
|
}
|
|
250
235
|
}
|
|
251
|
-
})
|
|
236
|
+
}),
|
|
252
237
|
)
|
|
253
238
|
if (error) {
|
|
254
239
|
console.log(JSON.stringify(documents, null, 2))
|
|
@@ -267,9 +252,9 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
267
252
|
const { input, keyInfo, requireX5Chain } = args
|
|
268
253
|
const coseKeyInfo = keyInfo && CoseJoseKeyMappingService.toCoseKeyInfo(keyInfo)
|
|
269
254
|
const verification = await new CoseCryptoServiceJS(new CoseCryptoService(context)).verify1(
|
|
270
|
-
CoseSign1Json.Static.fromDTO(input).toCbor(),
|
|
255
|
+
com.sphereon.crypto.cose.CoseSign1Json.Static.fromDTO(input).toCbor(),
|
|
271
256
|
coseKeyInfo,
|
|
272
|
-
requireX5Chain
|
|
257
|
+
requireX5Chain,
|
|
273
258
|
)
|
|
274
259
|
return { ...verification, keyInfo: keyInfo }
|
|
275
260
|
}
|
|
@@ -288,10 +273,10 @@ export class MDLMdoc implements IAgentPlugin {
|
|
|
288
273
|
const validationResult = await new X509CallbackService(Array.from(mergedAnchors)).verifyCertificateChain({
|
|
289
274
|
...args,
|
|
290
275
|
trustAnchors: Array.from(trustAnchors),
|
|
291
|
-
opts: { ...args?.opts, ...this.opts }
|
|
276
|
+
opts: { ...args?.opts, ...this.opts },
|
|
292
277
|
})
|
|
293
278
|
console.log(
|
|
294
|
-
`x509 validation for ${validationResult.error ? 'Error' : 'Success'}. message: ${validationResult.message}, details: ${validationResult.detailMessage}
|
|
279
|
+
`x509 validation for ${validationResult.error ? 'Error' : 'Success'}. message: ${validationResult.message}, details: ${validationResult.detailMessage}`,
|
|
295
280
|
)
|
|
296
281
|
return validationResult
|
|
297
282
|
}
|
package/src/functions/index.ts
CHANGED
|
@@ -12,30 +12,28 @@ import {
|
|
|
12
12
|
import { JWK } from '@sphereon/ssi-types'
|
|
13
13
|
import * as crypto from 'crypto'
|
|
14
14
|
import { Certificate, CryptoEngine, setEngine } from 'pkijs'
|
|
15
|
-
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
import { fromString } from 'uint8arrays/from-string'
|
|
16
17
|
import { IRequiredContext, VerifyCertificateChainArgs } from '../types/ImDLMdoc'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
import encodeTo = com.sphereon.kmp.encodeTo
|
|
37
|
-
import Encoding = com.sphereon.kmp.Encoding
|
|
38
|
-
import LocalDateTimeKMP = com.sphereon.kmp.LocalDateTimeKMP
|
|
18
|
+
|
|
19
|
+
type CoseKeyCbor = com.sphereon.crypto.cose.CoseKeyCbor
|
|
20
|
+
type ICoseKeyCbor = com.sphereon.crypto.cose.ICoseKeyCbor
|
|
21
|
+
type ToBeSignedCbor = com.sphereon.crypto.cose.ToBeSignedCbor
|
|
22
|
+
const CoseJoseKeyMappingService = com.sphereon.crypto.CoseJoseKeyMappingService
|
|
23
|
+
type SignatureAlgorithm = com.sphereon.crypto.generic.SignatureAlgorithm
|
|
24
|
+
type ICoseCryptoCallbackJS = com.sphereon.crypto.ICoseCryptoCallbackJS
|
|
25
|
+
type IKey = com.sphereon.crypto.IKey
|
|
26
|
+
type IX509ServiceJS = com.sphereon.crypto.IX509ServiceJS
|
|
27
|
+
type Jwk = com.sphereon.crypto.jose.Jwk
|
|
28
|
+
const KeyInfo = com.sphereon.crypto.KeyInfo
|
|
29
|
+
type X509VerificationProfile = com.sphereon.crypto.X509VerificationProfile
|
|
30
|
+
const DateTimeUtils = com.sphereon.kmp.DateTimeUtils
|
|
31
|
+
const decodeFrom = com.sphereon.kmp.decodeFrom
|
|
32
|
+
const encodeTo = com.sphereon.kmp.encodeTo
|
|
33
|
+
const Encoding = com.sphereon.kmp.Encoding
|
|
34
|
+
type LocalDateTimeKMP = com.sphereon.kmp.LocalDateTimeKMP
|
|
35
|
+
const SignatureAlgorithm = com.sphereon.crypto.generic.SignatureAlgorithm
|
|
36
|
+
const DefaultCallbacks = com.sphereon.crypto.DefaultCallbacks
|
|
39
37
|
|
|
40
38
|
export class CoseCryptoService implements ICoseCryptoCallbackJS {
|
|
41
39
|
constructor(private context?: IRequiredContext) {}
|
|
@@ -55,10 +53,10 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
|
|
|
55
53
|
if (key == null) {
|
|
56
54
|
return Promise.reject(Error('No key present in keyInfo. This implementation cannot sign without a key!'))
|
|
57
55
|
}
|
|
58
|
-
const resolvedKeyInfo = ResolvedKeyInfo.Static.fromKeyInfo(keyInfo, key)
|
|
59
|
-
const jwkKeyInfo: ResolvedKeyInfo<Jwk> = CoseJoseKeyMappingService.toResolvedJwkKeyInfo(resolvedKeyInfo)
|
|
56
|
+
const resolvedKeyInfo = com.sphereon.crypto.ResolvedKeyInfo.Static.fromKeyInfo(keyInfo, key)
|
|
57
|
+
const jwkKeyInfo: com.sphereon.crypto.ResolvedKeyInfo<Jwk> = CoseJoseKeyMappingService.toResolvedJwkKeyInfo(resolvedKeyInfo)
|
|
60
58
|
|
|
61
|
-
const kid = jwkKeyInfo.kid ?? calculateJwkThumbprint({jwk: jwkKeyInfo.key.toJsonDTO()}) ?? jwkKeyInfo.key.getKidAsString(true)
|
|
59
|
+
const kid = jwkKeyInfo.kid ?? calculateJwkThumbprint({ jwk: jwkKeyInfo.key.toJsonDTO() }) ?? jwkKeyInfo.key.getKidAsString(true)
|
|
62
60
|
if (!kid) {
|
|
63
61
|
return Promise.reject(Error('No kid present and not kmsKeyRef provided'))
|
|
64
62
|
}
|
|
@@ -74,10 +72,10 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
async verify1Async<CborType>(
|
|
77
|
-
input: CoseSign1Cbor<CborType>,
|
|
78
|
-
keyInfo: IKeyInfo<ICoseKeyCbor>,
|
|
75
|
+
input: com.sphereon.crypto.cose.CoseSign1Cbor<CborType>,
|
|
76
|
+
keyInfo: com.sphereon.crypto.IKeyInfo<ICoseKeyCbor>,
|
|
79
77
|
requireX5Chain: Nullable<boolean>,
|
|
80
|
-
): Promise<IVerifySignatureResult<ICoseKeyCbor>> {
|
|
78
|
+
): Promise<com.sphereon.crypto.generic.IVerifySignatureResult<ICoseKeyCbor>> {
|
|
81
79
|
const getCertAndKey = async (
|
|
82
80
|
x5c: Nullable<Array<string>>,
|
|
83
81
|
): Promise<{
|
|
@@ -128,7 +126,7 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
|
|
|
128
126
|
if (kid === null) {
|
|
129
127
|
kid = coseKeyInfo.key.getKidAsString(false)
|
|
130
128
|
}
|
|
131
|
-
issuerCoseKey = CoseKeyCbor.Static.fromDTO(coseKeyInfo.key)
|
|
129
|
+
issuerCoseKey = com.sphereon.crypto.cose.CoseKeyCbor.Static.fromDTO(coseKeyInfo.key)
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
const issuerCoseKeyInfo = new KeyInfo<CoseKeyCbor>(
|
|
@@ -145,8 +143,8 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
|
|
|
145
143
|
const recalculatedToBeSigned = input.toBeSignedJson(issuerCoseKeyInfo, SignatureAlgorithm.Static.fromCose(coseAlg))
|
|
146
144
|
const key = CoseJoseKeyMappingService.toJoseJwk(issuerCoseKeyInfo.key!).toJsonDTO<JWK>()
|
|
147
145
|
const valid = await verifyRawSignature({
|
|
148
|
-
data:
|
|
149
|
-
signature:
|
|
146
|
+
data: fromString(recalculatedToBeSigned.base64UrlValue, 'base64url'),
|
|
147
|
+
signature: fromString(sign1Json.signature, 'base64url'),
|
|
150
148
|
key,
|
|
151
149
|
})
|
|
152
150
|
|
|
@@ -156,7 +154,7 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
|
|
|
156
154
|
error: !valid,
|
|
157
155
|
message: `Signature of '${issuerCert ? getSubjectDN(issuerCert).DN : kid}' was ${valid ? '' : 'in'}valid`,
|
|
158
156
|
keyInfo: issuerCoseKeyInfo,
|
|
159
|
-
} satisfies IVerifySignatureResult<ICoseKeyCbor>
|
|
157
|
+
} satisfies com.sphereon.crypto.generic.IVerifySignatureResult<ICoseKeyCbor>
|
|
160
158
|
}
|
|
161
159
|
|
|
162
160
|
resolvePublicKeyAsync<KT extends com.sphereon.crypto.IKey>(
|
|
@@ -212,7 +210,7 @@ export class X509CallbackService implements IX509ServiceJS {
|
|
|
212
210
|
trustedCerts: Nullable<string[]>,
|
|
213
211
|
verificationProfile?: X509VerificationProfile | undefined,
|
|
214
212
|
verificationTime?: Nullable<LocalDateTimeKMP>,
|
|
215
|
-
): Promise<IX509VerificationResult<KeyType>> {
|
|
213
|
+
): Promise<com.sphereon.crypto.IX509VerificationResult<KeyType>> {
|
|
216
214
|
const verificationAt = verificationTime ?? DateTimeUtils.Static.DEFAULT.dateTimeLocal()
|
|
217
215
|
let chain: Array<string | Uint8Array> = []
|
|
218
216
|
if (chainDER && chainDER.length > 0) {
|
|
@@ -238,7 +236,7 @@ export class X509CallbackService implements IX509ServiceJS {
|
|
|
238
236
|
message: result.message,
|
|
239
237
|
error: result.error,
|
|
240
238
|
verificationTime: verificationAt,
|
|
241
|
-
} satisfies IX509VerificationResult<KeyType>
|
|
239
|
+
} satisfies com.sphereon.crypto.IX509VerificationResult<KeyType>
|
|
242
240
|
}
|
|
243
241
|
|
|
244
242
|
setTrustedCerts = (trustedCertsInPEM?: Array<string>) => {
|
|
@@ -255,9 +253,12 @@ export class X509CallbackService implements IX509ServiceJS {
|
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
const defaultCryptoEngine = () => {
|
|
256
|
+
// @ts-ignore
|
|
258
257
|
if (typeof self !== 'undefined') {
|
|
258
|
+
// @ts-ignore
|
|
259
259
|
if ('crypto' in self) {
|
|
260
260
|
let engineName = 'webcrypto'
|
|
261
|
+
// @ts-ignore
|
|
261
262
|
if ('webkitSubtle' in self.crypto) {
|
|
262
263
|
engineName = 'safari'
|
|
263
264
|
}
|
package/src/types/ImDLMdoc.ts
CHANGED
|
@@ -3,14 +3,31 @@ import { PresentationDefinitionV2, PresentationSubmission } from '@sphereon/pex-
|
|
|
3
3
|
import { ISphereonKeyManager } from '@sphereon/ssi-sdk-ext.key-manager'
|
|
4
4
|
import { CertificateInfo, SubjectAlternativeGeneralName, X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
5
5
|
import { IAgentContext, IDIDManager, IPluginMethodMap, IResolver } from '@veramo/core'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export type IKey = com.sphereon.crypto.IKey
|
|
7
|
+
export type CoseSign1Json = com.sphereon.crypto.cose.CoseSign1Json
|
|
8
|
+
export type CoseSign1Cbor<Any> = com.sphereon.crypto.cose.CoseSign1Cbor<Any>
|
|
9
|
+
export type ICoseKeyCbor = com.sphereon.crypto.cose.ICoseKeyCbor
|
|
10
|
+
export type ICoseKeyJson = com.sphereon.crypto.cose.ICoseKeyJson
|
|
11
|
+
export type IKeyInfo<KT extends IKey = IKey> = com.sphereon.crypto.IKeyInfo<KT>
|
|
12
|
+
export type IVerifyResults<KT extends IKey> = com.sphereon.crypto.generic.IVerifyResults<KT>
|
|
13
|
+
export type IVerifySignatureResult<KT extends IKey> = com.sphereon.crypto.generic.IVerifySignatureResult<KT>
|
|
14
|
+
export type DocumentJson = com.sphereon.mdoc.data.device.DocumentJson
|
|
15
|
+
export type DocumentCbor = com.sphereon.mdoc.data.device.DocumentCbor
|
|
16
|
+
export const CborByteString = com.sphereon.cbor.CborByteString
|
|
17
|
+
export const CoseKeyCbor = com.sphereon.crypto.cose.CoseKeyCbor
|
|
18
|
+
export const CoseCryptoServiceJS = com.sphereon.crypto.CoseCryptoServiceJS
|
|
19
|
+
export const CoseJoseKeyMappingService = com.sphereon.crypto.CoseJoseKeyMappingService
|
|
20
|
+
export const KeyInfo = com.sphereon.crypto.KeyInfo
|
|
21
|
+
export const DateTimeUtils = com.sphereon.kmp.DateTimeUtils
|
|
22
|
+
export const decodeFrom = com.sphereon.kmp.decodeFrom
|
|
23
|
+
export const encodeTo = com.sphereon.kmp.encodeTo
|
|
24
|
+
export const Encoding = com.sphereon.kmp.Encoding
|
|
25
|
+
export const MdocValidations = com.sphereon.mdoc.data.MdocValidations
|
|
26
|
+
export const MdocOid4vpService = com.sphereon.mdoc.oid4vp.MdocOid4vpServiceJs
|
|
27
|
+
export const Jwk = com.sphereon.crypto.jose.Jwk
|
|
28
|
+
export type DocumentDescriptorMatchResult = com.sphereon.mdoc.oid4vp.DocumentDescriptorMatchResult
|
|
29
|
+
export type IOid4VPPresentationDefinition = com.sphereon.mdoc.oid4vp.IOid4VPPresentationDefinition
|
|
30
|
+
export const Oid4VPPresentationSubmission = com.sphereon.mdoc.oid4vp.Oid4VPPresentationSubmission
|
|
14
31
|
|
|
15
32
|
export interface ImDLMdoc extends IPluginMethodMap {
|
|
16
33
|
// TODO: Extract cert methods to its own plugin
|
package/dist/agent/mDLMdoc.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { IAgentPlugin } from '@veramo/core';
|
|
2
|
-
import { ImDLMdoc } from '../types/ImDLMdoc';
|
|
3
|
-
export declare const mdocSupportMethods: Array<string>;
|
|
4
|
-
/**
|
|
5
|
-
* The MDLMdoc class implements the IAgentPlugin interface, providing methods for
|
|
6
|
-
* verification and information retrieval related to X.509 certificates and mDL (mobile
|
|
7
|
-
* driver's license) documents.
|
|
8
|
-
*/
|
|
9
|
-
export declare class MDLMdoc implements IAgentPlugin {
|
|
10
|
-
readonly schema: any;
|
|
11
|
-
readonly methods: ImDLMdoc;
|
|
12
|
-
private readonly trustAnchors;
|
|
13
|
-
private opts;
|
|
14
|
-
constructor(args?: {
|
|
15
|
-
trustAnchors?: string[];
|
|
16
|
-
opts?: {
|
|
17
|
-
trustRootWhenNoAnchors?: boolean;
|
|
18
|
-
allowSingleNoCAChainElement?: boolean;
|
|
19
|
-
blindlyTrustedAnchors?: string[];
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Processes and verifies the provided mdoc, generates device response and presentation submission tokens.
|
|
24
|
-
*
|
|
25
|
-
* @param {MdocOid4vpPresentArgs} args - An object containing arguments for mdoc oid4vp holder presentation.
|
|
26
|
-
* @param {IRequiredContext} _context - Required context for the operation.
|
|
27
|
-
* @return {Promise<MdocOid4VPPresentationAuth>} A promise that resolves to an object containing vp_token and presentation_submission.
|
|
28
|
-
*/
|
|
29
|
-
private mdocOid4vpHolderPresent;
|
|
30
|
-
/**
|
|
31
|
-
* Verifies on the Relying Party (RP) side for mdoc (mobile document) OIDC4VP (OpenID Connect for Verifiable Presentations).
|
|
32
|
-
*
|
|
33
|
-
* @param {MdocOid4vpRPVerifyArgs} args - The arguments required for verification, including the vp_token, presentation_submission, and trustAnchors.
|
|
34
|
-
* @param {IRequiredContext} _context - The required context for this method.
|
|
35
|
-
* @return {Promise<MdocOid4vpRPVerifyResult>} - A promise that resolves to an object containing error status,
|
|
36
|
-
* validated documents, and the original presentation submission.
|
|
37
|
-
*/
|
|
38
|
-
private mdocOid4vpRPVerify;
|
|
39
|
-
/**
|
|
40
|
-
* Verifies the issuer-signed Mobile Document (mDoc) using the provided arguments and context.
|
|
41
|
-
*
|
|
42
|
-
* @param {MdocVerifyIssuerSignedArgs} args - The arguments required for verification, including input and key information.
|
|
43
|
-
* @param {IRequiredContext} context - The context encompassing necessary dependencies and configurations.
|
|
44
|
-
* @return {Promise<IVerifySignatureResult<KeyType>>} A promise that resolves to the result of the signature verification, including key information if available.
|
|
45
|
-
*/
|
|
46
|
-
private mdocVerifyIssuerSigned;
|
|
47
|
-
/**
|
|
48
|
-
* Verifies an X.509 certificate chain against a set of trust anchors.
|
|
49
|
-
*
|
|
50
|
-
* @param {VerifyCertificateChainArgs} args - The arguments required for verifying the certificate chain.
|
|
51
|
-
* This includes the certificate chain to be verified and any additional trust anchors to be used.
|
|
52
|
-
* @param {IRequiredContext} _context - The context required for verification, including necessary dependencies and settings.
|
|
53
|
-
* @return {Promise<X509ValidationResult>} A promise that resolves to the result of the validation process, indicating the success or failure of the certificate chain verification.
|
|
54
|
-
*/
|
|
55
|
-
private x509VerifyCertificateChain;
|
|
56
|
-
/**
|
|
57
|
-
* Extracts information from a list of X509 certificates.
|
|
58
|
-
*
|
|
59
|
-
* @param {GetX509CertificateInfoArgs} args - Arguments required to retrieve certificate information,
|
|
60
|
-
* including the certificates and optional Subject Alternative Name (SAN) type filter.
|
|
61
|
-
* @param {IRequiredContext} context - The context required for the operation, which may include
|
|
62
|
-
* logging, configuration, and other operational details.
|
|
63
|
-
* @return {Promise<CertificateInfo[]>} A promise that resolves with an array of certificate
|
|
64
|
-
* information objects, each containing details extracted from individual certificates.
|
|
65
|
-
*/
|
|
66
|
-
private x509GetCertificateInfo;
|
|
67
|
-
}
|
|
68
|
-
//# sourceMappingURL=mDLMdoc.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mDLMdoc.d.ts","sourceRoot":"","sources":["../../src/agent/mDLMdoc.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAS3C,OAAO,EAEL,QAAQ,EAKT,MAAM,mBAAmB,CAAA;AAoB1B,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,MAAM,CAM5C,CAAA;AAED;;;;GAIG;AACH,qBAAa,OAAQ,YAAW,YAAY;IAC1C,QAAQ,CAAC,MAAM,MAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAMzB;IACD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,IAAI,CAIX;gBAEW,IAAI,CAAC,EAAE;QACjB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;QACvB,IAAI,CAAC,EAAE;YAEL,sBAAsB,CAAC,EAAE,OAAO,CAAA;YAEhC,2BAA2B,CAAC,EAAE,OAAO,CAAA;YAGrC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAA;SACjC,CAAA;KACF;IAKD;;;;;;OAMG;YACW,uBAAuB;IAwGrC;;;;;;;OAOG;YACW,kBAAkB;IAiDhC;;;;;;OAMG;YACW,sBAAsB;IAWpC;;;;;;;OAOG;YACW,0BAA0B;IAcxC;;;;;;;;;OASG;YACW,sBAAsB;CAIrC"}
|