@sphereon/ssi-sdk.sd-jwt 0.34.1-next.7 → 0.34.1-next.85

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/src/types.ts CHANGED
@@ -1,12 +1,22 @@
1
- import { SdJwtVcPayload as SdJwtPayload } from '@sd-jwt/sd-jwt-vc'
2
1
  import { Hasher, kbHeader, KBOptions, kbPayload, SaltGenerator, Signer } from '@sd-jwt/types'
3
2
  import { IIdentifierResolution, ManagedIdentifierResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
4
3
  import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service'
5
4
  import { X509CertificateChainValidationOpts } from '@sphereon/ssi-sdk-ext.x509-utils'
6
5
  import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
7
6
  import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc'
8
- import { HasherSync, JoseSignatureAlgorithm, JsonWebKey, SdJwtTypeMetadata } from '@sphereon/ssi-types'
7
+ import {
8
+ HasherSync,
9
+ JoseSignatureAlgorithm,
10
+ JsonWebKey,
11
+ SdJwtType,
12
+ SdJwtTypeMetadata,
13
+ SdJwtVcdm2Payload,
14
+ SdJwtVcType,
15
+ SdJwtVpType,
16
+ } from '@sphereon/ssi-types'
9
17
  import { DIDDocumentSection, IAgentContext, IDIDManager, IKeyManager, IPluginMethodMap, IResolver } from '@veramo/core'
18
+ import { SdJwtVcPayload as OrigSdJwtVcPayload } from '@sd-jwt/sd-jwt-vc'
19
+ import { SdJwtPayload } from '@sd-jwt/core'
10
20
 
11
21
  export const sdJwtPluginContextMethods: Array<string> = ['createSdJwtVc', 'createSdJwtPresentation', 'verifySdJwtVc', 'verifySdJwtPresentation']
12
22
 
@@ -85,12 +95,19 @@ export function contextHasSDJwtPlugin(context: IAgentContext<IPluginMethodMap>):
85
95
  * @beta
86
96
  */
87
97
 
88
- export interface SdJwtVcPayload extends SdJwtPayload {
98
+ export interface SdJwtVcPayload extends OrigSdJwtVcPayload {
89
99
  x5c?: string[]
90
100
  }
91
101
 
102
+ export type Vcdm2Enveloped = 'EnvelopedVerifiableCredential' | 'EnvelopedVerifiablePresentation'
103
+
104
+ export function isVcdm2SdJwt(type: SdJwtType | string): Boolean {
105
+ return type === 'vc+sd-jwt' || type === 'vp+sd-jwt'
106
+ }
107
+
92
108
  export interface ICreateSdJwtVcArgs {
93
- credentialPayload: SdJwtVcPayload
109
+ type?: SdJwtVcType
110
+ credentialPayload: SdJwtPayload
94
111
 
95
112
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
96
113
  disclosureFrame?: IDisclosureFrame
@@ -114,6 +131,8 @@ export interface IDisclosureFrame {
114
131
  * @beta
115
132
  */
116
133
  export interface ICreateSdJwtVcResult {
134
+ type: SdJwtVcType
135
+
117
136
  /**
118
137
  * the encoded sd-jwt credential
119
138
  */
@@ -146,6 +165,10 @@ export interface ICreateSdJwtPresentationArgs {
146
165
  * Information to include to add key binding.
147
166
  */
148
167
  kb?: KBOptions
168
+
169
+ type?: SdJwtVpType
170
+
171
+ vcdm2Enveloped?: Vcdm2Enveloped
149
172
  }
150
173
 
151
174
  /**
@@ -164,6 +187,8 @@ export interface ICreateSdJwtPresentationResult {
164
187
  * Encoded presentation.
165
188
  */
166
189
  presentation: string
190
+
191
+ type: SdJwtVpType
167
192
  }
168
193
 
169
194
  /**
@@ -180,7 +205,8 @@ export interface IVerifySdJwtVcArgs {
180
205
  * @beta
181
206
  */
182
207
  export type IVerifySdJwtVcResult = {
183
- payload: SdJwtPayload
208
+ type: SdJwtVcType
209
+ payload: SdJwtVcPayload | SdJwtVcdm2Payload
184
210
  header: Record<string, unknown>
185
211
  kb?: { header: kbHeader; payload: kbPayload }
186
212
  }
@@ -193,7 +219,15 @@ export interface IVerifySdJwtPresentationArgs {
193
219
 
194
220
  requiredClaimKeys?: string[]
195
221
 
196
- kb?: boolean
222
+ /**
223
+ * nonce used to verify the key binding jwt to prevent replay attacks.
224
+ */
225
+ keyBindingNonce?: string
226
+
227
+ /**
228
+ * Audience used to verify the key binding jwt
229
+ */
230
+ keyBindingAud?: string
197
231
  }
198
232
 
199
233
  /**
package/src/utils.ts CHANGED
@@ -1,7 +1,9 @@
1
- import { SdJwtTypeMetadata } from '@sphereon/ssi-types'
1
+ import type { SdJwtTypeMetadata, SdJwtVcdm2Payload } from '@sphereon/ssi-types'
2
2
  // @ts-ignore
3
3
  import { toString } from 'uint8arrays/to-string'
4
4
  import { Hasher, HasherSync } from '@sd-jwt/types'
5
+ import type { SdJwtPayload } from '@sd-jwt/core'
6
+ import type { SdJwtVcPayload } from '@sd-jwt/sd-jwt-vc'
5
7
 
6
8
  // Helper function to fetch API with error handling
7
9
  export async function fetchUrlWithErrorHandling(url: string): Promise<Response> {
@@ -64,3 +66,32 @@ export function assertValidTypeMetadata(metadata: SdJwtTypeMetadata, vct: string
64
66
  throw new Error('VCT mismatch in metadata and credential')
65
67
  }
66
68
  }
69
+
70
+ export function isVcdm2SdJwtPayload(payload: SdJwtPayload): payload is SdJwtVcdm2Payload {
71
+ return (
72
+ 'type' in payload &&
73
+ Array.isArray(payload.type) &&
74
+ payload.type.includes('VerifiableCredential') &&
75
+ '@context' in payload &&
76
+ ((typeof payload['@context'] === 'string' && payload['@context'].length > 0) ||
77
+ (Array.isArray(payload['@context']) && payload['@context'].length > 0 && payload['@context'].includes('https://www.w3.org/ns/credentials/v2')))
78
+ )
79
+ }
80
+
81
+ export function isSdjwtVcPayload(payload: SdJwtPayload): payload is SdJwtVcPayload {
82
+ return !isVcdm2SdJwtPayload(payload) && 'vct' in payload && typeof payload.vct === 'string'
83
+ }
84
+
85
+ export function getIssuerFromSdJwt(payload: SdJwtPayload): string {
86
+ let issuer: string | undefined
87
+ if (isVcdm2SdJwtPayload(payload)) {
88
+ issuer = typeof payload.issuer === 'string' ? payload.issuer : payload.issuer?.id
89
+ }
90
+ if (isSdjwtVcPayload(payload)) {
91
+ issuer = payload.iss as string
92
+ }
93
+ if (!issuer) {
94
+ throw new Error('No issuer (iss or VCDM 2 issuer) found in SD-JWT or no VCDM2 SD-JWT or SD-JWT VC')
95
+ }
96
+ return issuer
97
+ }