@sphereon/ssi-sdk.mdl-mdoc 0.33.1-feature.vcdm2.tsup.32 → 0.33.1-next.2

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.
@@ -3,31 +3,34 @@ import { calculateJwkThumbprint } from '@sphereon/ssi-sdk-ext.key-utils'
3
3
  import { CertificateInfo, getCertificateInfo, pemOrDerToX509Certificate, X509ValidationResult } from '@sphereon/ssi-sdk-ext.x509-utils'
4
4
  import { JWK } from '@sphereon/ssi-types'
5
5
  import { IAgentPlugin } from '@veramo/core'
6
- import { MdocOid4vpPresentArgs, MdocOid4VPPresentationAuth, MdocOid4vpRPVerifyArgs, MdocOid4vpRPVerifyResult, MdocOid4vpService, schema } from '..'
6
+ import { MdocOid4vpPresentArgs, MdocOid4VPPresentationAuth, MdocOid4vpRPVerifyArgs, MdocOid4vpRPVerifyResult, schema } from '..'
7
7
  import { CoseCryptoService, X509CallbackService } from '../functions'
8
8
  import {
9
- CborByteString,
10
- CoseCryptoServiceJS,
11
- CoseJoseKeyMappingService,
12
- CoseKeyCbor,
13
- DateTimeUtils,
14
- decodeFrom,
15
- DocumentCbor,
16
- DocumentDescriptorMatchResult,
17
- encodeTo,
18
- Encoding,
19
9
  GetX509CertificateInfoArgs,
20
10
  ImDLMdoc,
21
- IOid4VPPresentationDefinition,
22
11
  IRequiredContext,
23
- IVerifySignatureResult,
24
- KeyInfo,
25
12
  KeyType,
26
- Oid4VPPresentationSubmission,
27
- MdocValidations,
28
13
  MdocVerifyIssuerSignedArgs,
29
14
  VerifyCertificateChainArgs,
30
15
  } from '../types/ImDLMdoc'
16
+ import CborByteString = com.sphereon.cbor.CborByteString
17
+ import CoseKeyCbor = com.sphereon.crypto.cose.CoseKeyCbor
18
+ import CoseSign1Json = com.sphereon.crypto.cose.CoseSign1Json
19
+ import CoseCryptoServiceJS = com.sphereon.crypto.CoseCryptoServiceJS
20
+ import CoseJoseKeyMappingService = com.sphereon.crypto.CoseJoseKeyMappingService
21
+ import IVerifySignatureResult = com.sphereon.crypto.generic.IVerifySignatureResult
22
+ import KeyInfo = com.sphereon.crypto.KeyInfo
23
+ import DateTimeUtils = com.sphereon.kmp.DateTimeUtils
24
+ import decodeFrom = com.sphereon.kmp.decodeFrom
25
+ import encodeTo = com.sphereon.kmp.encodeTo
26
+ import Encoding = com.sphereon.kmp.Encoding
27
+ import DeviceResponseCbor = com.sphereon.mdoc.data.device.DeviceResponseCbor
28
+ import DocumentCbor = com.sphereon.mdoc.data.device.DocumentCbor
29
+ import MdocValidations = com.sphereon.mdoc.data.MdocValidations
30
+ import DocumentDescriptorMatchResult = com.sphereon.mdoc.oid4vp.DocumentDescriptorMatchResult
31
+ import IOid4VPPresentationDefinition = com.sphereon.mdoc.oid4vp.IOid4VPPresentationDefinition
32
+ import MdocOid4vpService = com.sphereon.mdoc.oid4vp.MdocOid4vpServiceJs
33
+ import Oid4VPPresentationSubmission = com.sphereon.mdoc.oid4vp.Oid4VPPresentationSubmission
31
34
 
32
35
  export const mdocSupportMethods: Array<string> = [
33
36
  'x509VerifyCertificateChain',
@@ -194,7 +197,7 @@ export class MDLMdoc implements IAgentPlugin {
194
197
  */
195
198
  private async mdocOid4vpRPVerify(args: MdocOid4vpRPVerifyArgs, _context: IRequiredContext): Promise<MdocOid4vpRPVerifyResult> {
196
199
  const { vp_token, presentation_submission, trustAnchors } = args
197
- const deviceResponse = com.sphereon.mdoc.data.device.DeviceResponseCbor.Static.cborDecode(decodeFrom(vp_token, Encoding.BASE64URL))
200
+ const deviceResponse = DeviceResponseCbor.Static.cborDecode(decodeFrom(vp_token, Encoding.BASE64URL))
198
201
  if (!deviceResponse.documents) {
199
202
  return Promise.reject(Error(`No documents found in vp_token`))
200
203
  }
@@ -252,7 +255,7 @@ export class MDLMdoc implements IAgentPlugin {
252
255
  const { input, keyInfo, requireX5Chain } = args
253
256
  const coseKeyInfo = keyInfo && CoseJoseKeyMappingService.toCoseKeyInfo(keyInfo)
254
257
  const verification = await new CoseCryptoServiceJS(new CoseCryptoService(context)).verify1(
255
- com.sphereon.crypto.cose.CoseSign1Json.Static.fromDTO(input).toCbor(),
258
+ CoseSign1Json.Static.fromDTO(input).toCbor(),
256
259
  coseKeyInfo,
257
260
  requireX5Chain,
258
261
  )
@@ -12,28 +12,30 @@ 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
- // @ts-ignore
16
- import { fromString } from 'uint8arrays/from-string'
15
+ import * as u8a from 'uint8arrays'
17
16
  import { IRequiredContext, VerifyCertificateChainArgs } from '../types/ImDLMdoc'
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
17
+ import CoseKeyCbor = com.sphereon.crypto.cose.CoseKeyCbor
18
+ import CoseSign1Cbor = com.sphereon.crypto.cose.CoseSign1Cbor
19
+ import ICoseKeyCbor = com.sphereon.crypto.cose.ICoseKeyCbor
20
+ import ToBeSignedCbor = com.sphereon.crypto.cose.ToBeSignedCbor
21
+ import CoseJoseKeyMappingService = com.sphereon.crypto.CoseJoseKeyMappingService
22
+ import DefaultCallbacks = com.sphereon.crypto.DefaultCallbacks
23
+ import IVerifySignatureResult = com.sphereon.crypto.generic.IVerifySignatureResult
24
+ import SignatureAlgorithm = com.sphereon.crypto.generic.SignatureAlgorithm
25
+ import ICoseCryptoCallbackJS = com.sphereon.crypto.ICoseCryptoCallbackJS
26
+ import IKey = com.sphereon.crypto.IKey
27
+ import IKeyInfo = com.sphereon.crypto.IKeyInfo
28
+ import IX509ServiceJS = com.sphereon.crypto.IX509ServiceJS
29
+ import IX509VerificationResult = com.sphereon.crypto.IX509VerificationResult
30
+ import Jwk = com.sphereon.crypto.jose.Jwk
31
+ import KeyInfo = com.sphereon.crypto.KeyInfo
32
+ import ResolvedKeyInfo = com.sphereon.crypto.ResolvedKeyInfo
33
+ import X509VerificationProfile = com.sphereon.crypto.X509VerificationProfile
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 LocalDateTimeKMP = com.sphereon.kmp.LocalDateTimeKMP
37
39
 
38
40
  export class CoseCryptoService implements ICoseCryptoCallbackJS {
39
41
  constructor(private context?: IRequiredContext) {}
@@ -53,8 +55,8 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
53
55
  if (key == null) {
54
56
  return Promise.reject(Error('No key present in keyInfo. This implementation cannot sign without a key!'))
55
57
  }
56
- const resolvedKeyInfo = com.sphereon.crypto.ResolvedKeyInfo.Static.fromKeyInfo(keyInfo, key)
57
- const jwkKeyInfo: com.sphereon.crypto.ResolvedKeyInfo<Jwk> = CoseJoseKeyMappingService.toResolvedJwkKeyInfo(resolvedKeyInfo)
58
+ const resolvedKeyInfo = ResolvedKeyInfo.Static.fromKeyInfo(keyInfo, key)
59
+ const jwkKeyInfo: ResolvedKeyInfo<Jwk> = CoseJoseKeyMappingService.toResolvedJwkKeyInfo(resolvedKeyInfo)
58
60
 
59
61
  const kid = jwkKeyInfo.kid ?? calculateJwkThumbprint({ jwk: jwkKeyInfo.key.toJsonDTO() }) ?? jwkKeyInfo.key.getKidAsString(true)
60
62
  if (!kid) {
@@ -72,10 +74,10 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
72
74
  }
73
75
 
74
76
  async verify1Async<CborType>(
75
- input: com.sphereon.crypto.cose.CoseSign1Cbor<CborType>,
76
- keyInfo: com.sphereon.crypto.IKeyInfo<ICoseKeyCbor>,
77
+ input: CoseSign1Cbor<CborType>,
78
+ keyInfo: IKeyInfo<ICoseKeyCbor>,
77
79
  requireX5Chain: Nullable<boolean>,
78
- ): Promise<com.sphereon.crypto.generic.IVerifySignatureResult<ICoseKeyCbor>> {
80
+ ): Promise<IVerifySignatureResult<ICoseKeyCbor>> {
79
81
  const getCertAndKey = async (
80
82
  x5c: Nullable<Array<string>>,
81
83
  ): Promise<{
@@ -126,7 +128,7 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
126
128
  if (kid === null) {
127
129
  kid = coseKeyInfo.key.getKidAsString(false)
128
130
  }
129
- issuerCoseKey = com.sphereon.crypto.cose.CoseKeyCbor.Static.fromDTO(coseKeyInfo.key)
131
+ issuerCoseKey = CoseKeyCbor.Static.fromDTO(coseKeyInfo.key)
130
132
  }
131
133
 
132
134
  const issuerCoseKeyInfo = new KeyInfo<CoseKeyCbor>(
@@ -143,8 +145,8 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
143
145
  const recalculatedToBeSigned = input.toBeSignedJson(issuerCoseKeyInfo, SignatureAlgorithm.Static.fromCose(coseAlg))
144
146
  const key = CoseJoseKeyMappingService.toJoseJwk(issuerCoseKeyInfo.key!).toJsonDTO<JWK>()
145
147
  const valid = await verifyRawSignature({
146
- data: fromString(recalculatedToBeSigned.base64UrlValue, 'base64url'),
147
- signature: fromString(sign1Json.signature, 'base64url'),
148
+ data: u8a.fromString(recalculatedToBeSigned.base64UrlValue, 'base64url'),
149
+ signature: u8a.fromString(sign1Json.signature, 'base64url'),
148
150
  key,
149
151
  })
150
152
 
@@ -154,7 +156,7 @@ export class CoseCryptoService implements ICoseCryptoCallbackJS {
154
156
  error: !valid,
155
157
  message: `Signature of '${issuerCert ? getSubjectDN(issuerCert).DN : kid}' was ${valid ? '' : 'in'}valid`,
156
158
  keyInfo: issuerCoseKeyInfo,
157
- } satisfies com.sphereon.crypto.generic.IVerifySignatureResult<ICoseKeyCbor>
159
+ } satisfies IVerifySignatureResult<ICoseKeyCbor>
158
160
  }
159
161
 
160
162
  resolvePublicKeyAsync<KT extends com.sphereon.crypto.IKey>(
@@ -210,7 +212,7 @@ export class X509CallbackService implements IX509ServiceJS {
210
212
  trustedCerts: Nullable<string[]>,
211
213
  verificationProfile?: X509VerificationProfile | undefined,
212
214
  verificationTime?: Nullable<LocalDateTimeKMP>,
213
- ): Promise<com.sphereon.crypto.IX509VerificationResult<KeyType>> {
215
+ ): Promise<IX509VerificationResult<KeyType>> {
214
216
  const verificationAt = verificationTime ?? DateTimeUtils.Static.DEFAULT.dateTimeLocal()
215
217
  let chain: Array<string | Uint8Array> = []
216
218
  if (chainDER && chainDER.length > 0) {
@@ -236,7 +238,7 @@ export class X509CallbackService implements IX509ServiceJS {
236
238
  message: result.message,
237
239
  error: result.error,
238
240
  verificationTime: verificationAt,
239
- } satisfies com.sphereon.crypto.IX509VerificationResult<KeyType>
241
+ } satisfies IX509VerificationResult<KeyType>
240
242
  }
241
243
 
242
244
  setTrustedCerts = (trustedCertsInPEM?: Array<string>) => {
@@ -253,12 +255,9 @@ export class X509CallbackService implements IX509ServiceJS {
253
255
  }
254
256
 
255
257
  const defaultCryptoEngine = () => {
256
- // @ts-ignore
257
258
  if (typeof self !== 'undefined') {
258
- // @ts-ignore
259
259
  if ('crypto' in self) {
260
260
  let engineName = 'webcrypto'
261
- // @ts-ignore
262
261
  if ('webkitSubtle' in self.crypto) {
263
262
  engineName = 'safari'
264
263
  }
@@ -3,31 +3,14 @@ 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
- 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
6
+ import CoseSign1Json = com.sphereon.crypto.cose.CoseSign1Json
7
+ import ICoseKeyCbor = com.sphereon.crypto.cose.ICoseKeyCbor
8
+ import ICoseKeyJson = com.sphereon.crypto.cose.ICoseKeyJson
9
+ import IKeyInfo = com.sphereon.crypto.IKeyInfo
10
+ import IVerifyResults = com.sphereon.crypto.generic.IVerifyResults
11
+ import IVerifySignatureResult = com.sphereon.crypto.generic.IVerifySignatureResult
12
+ import DocumentJson = com.sphereon.mdoc.data.device.DocumentJson
13
+ import DocumentCbor = com.sphereon.mdoc.data.device.DocumentCbor
31
14
 
32
15
  export interface ImDLMdoc extends IPluginMethodMap {
33
16
  // TODO: Extract cert methods to its own plugin