@sd-jwt/core 0.18.0 → 0.18.1-next.1

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.d.mts CHANGED
@@ -118,6 +118,10 @@ type VerifierOptions = {
118
118
  * nonce used to verify the key binding jwt to prevent replay attacks.
119
119
  */
120
120
  keyBindingNonce?: string;
121
+ /**
122
+ * any other custom options
123
+ */
124
+ [key: string]: unknown;
121
125
  };
122
126
  declare class Jwt<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> {
123
127
  header?: Header;
@@ -143,7 +147,7 @@ declare class Jwt<Header extends Record<string, unknown> = Record<string, unknow
143
147
  * @param options - Options for verification, such as current date and skew seconds
144
148
  * @returns
145
149
  */
146
- verify(verifier: Verifier, options?: VerifierOptions): Promise<{
150
+ verify<T>(verifier: Verifier<T>, options?: T & VerifierOptions): Promise<{
147
151
  payload: Payload | undefined;
148
152
  header: Header | undefined;
149
153
  }>;
@@ -194,11 +198,11 @@ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFra
194
198
  declare const createDecoy: (hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<string>;
195
199
 
196
200
  type SdJwtPayload = Record<string, unknown>;
197
- declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
201
+ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload, T = unknown> {
198
202
  protected type?: string;
199
203
  static readonly DEFAULT_hashAlg = "sha-256";
200
- protected userConfig: SDJWTConfig;
201
- constructor(userConfig?: SDJWTConfig);
204
+ protected userConfig: SDJWTConfig<T>;
205
+ constructor(userConfig?: SDJWTConfig<T>);
202
206
  private createKBJwt;
203
207
  private SignJwt;
204
208
  private VerifyJwt;
@@ -214,7 +218,7 @@ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
214
218
  present<T extends Record<string, unknown>>(encodedSDJwt: string, presentationFrame?: PresentationFrame<T>, options?: {
215
219
  kb?: KBOptions;
216
220
  }): Promise<SDJWTCompact>;
217
- verify(encodedSDJwt: string, options?: VerifierOptions): Promise<{
221
+ verify(encodedSDJwt: string, options?: T & VerifierOptions): Promise<{
218
222
  payload: unknown;
219
223
  header: Record<string, unknown> | undefined;
220
224
  kb?: undefined;
@@ -234,7 +238,7 @@ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
234
238
  * @param options
235
239
  * @returns
236
240
  */
237
- validate(encodedSDJwt: string, options?: VerifierOptions): Promise<{
241
+ validate(encodedSDJwt: string, options?: T & VerifierOptions): Promise<{
238
242
  payload: unknown;
239
243
  header: Record<string, unknown> | undefined;
240
244
  }>;
package/dist/index.d.ts CHANGED
@@ -118,6 +118,10 @@ type VerifierOptions = {
118
118
  * nonce used to verify the key binding jwt to prevent replay attacks.
119
119
  */
120
120
  keyBindingNonce?: string;
121
+ /**
122
+ * any other custom options
123
+ */
124
+ [key: string]: unknown;
121
125
  };
122
126
  declare class Jwt<Header extends Record<string, unknown> = Record<string, unknown>, Payload extends Record<string, unknown> = Record<string, unknown>> {
123
127
  header?: Header;
@@ -143,7 +147,7 @@ declare class Jwt<Header extends Record<string, unknown> = Record<string, unknow
143
147
  * @param options - Options for verification, such as current date and skew seconds
144
148
  * @returns
145
149
  */
146
- verify(verifier: Verifier, options?: VerifierOptions): Promise<{
150
+ verify<T>(verifier: Verifier<T>, options?: T & VerifierOptions): Promise<{
147
151
  payload: Payload | undefined;
148
152
  header: Header | undefined;
149
153
  }>;
@@ -194,11 +198,11 @@ declare const pack: <T extends Record<string, unknown>>(claims: T, disclosureFra
194
198
  declare const createDecoy: (hash: HasherAndAlg, saltGenerator: SaltGenerator) => Promise<string>;
195
199
 
196
200
  type SdJwtPayload = Record<string, unknown>;
197
- declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
201
+ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload, T = unknown> {
198
202
  protected type?: string;
199
203
  static readonly DEFAULT_hashAlg = "sha-256";
200
- protected userConfig: SDJWTConfig;
201
- constructor(userConfig?: SDJWTConfig);
204
+ protected userConfig: SDJWTConfig<T>;
205
+ constructor(userConfig?: SDJWTConfig<T>);
202
206
  private createKBJwt;
203
207
  private SignJwt;
204
208
  private VerifyJwt;
@@ -214,7 +218,7 @@ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
214
218
  present<T extends Record<string, unknown>>(encodedSDJwt: string, presentationFrame?: PresentationFrame<T>, options?: {
215
219
  kb?: KBOptions;
216
220
  }): Promise<SDJWTCompact>;
217
- verify(encodedSDJwt: string, options?: VerifierOptions): Promise<{
221
+ verify(encodedSDJwt: string, options?: T & VerifierOptions): Promise<{
218
222
  payload: unknown;
219
223
  header: Record<string, unknown> | undefined;
220
224
  kb?: undefined;
@@ -234,7 +238,7 @@ declare class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
234
238
  * @param options
235
239
  * @returns
236
240
  */
237
- validate(encodedSDJwt: string, options?: VerifierOptions): Promise<{
241
+ validate(encodedSDJwt: string, options?: T & VerifierOptions): Promise<{
238
242
  payload: unknown;
239
243
  header: Record<string, unknown> | undefined;
240
244
  }>;
package/dist/index.js CHANGED
@@ -340,7 +340,7 @@ var Jwt = class _Jwt {
340
340
  throw new import_utils3.SDJWTException("Verify Error: no signature in JWT");
341
341
  }
342
342
  const data = this.getUnsignedToken();
343
- const verified = yield verifier(data, this.signature);
343
+ const verified = yield verifier(data, this.signature, options);
344
344
  if (!verified) {
345
345
  throw new import_utils3.SDJWTException("Verify Error: Invalid JWT Signature");
346
346
  }
package/dist/index.mjs CHANGED
@@ -318,7 +318,7 @@ var Jwt = class _Jwt {
318
318
  throw new SDJWTException3("Verify Error: no signature in JWT");
319
319
  }
320
320
  const data = this.getUnsignedToken();
321
- const verified = yield verifier(data, this.signature);
321
+ const verified = yield verifier(data, this.signature, options);
322
322
  if (!verified) {
323
323
  throw new SDJWTException3("Verify Error: Invalid JWT Signature");
324
324
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sd-jwt/core",
3
- "version": "0.18.0",
3
+ "version": "0.18.1-next.1+a11aff6",
4
4
  "description": "sd-jwt draft 7 implementation in typescript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -37,13 +37,13 @@
37
37
  },
38
38
  "license": "Apache-2.0",
39
39
  "devDependencies": {
40
- "@sd-jwt/crypto-nodejs": "0.18.0"
40
+ "@sd-jwt/crypto-nodejs": "0.18.1-next.1+a11aff6"
41
41
  },
42
42
  "dependencies": {
43
- "@sd-jwt/decode": "0.18.0",
44
- "@sd-jwt/present": "0.18.0",
45
- "@sd-jwt/types": "0.18.0",
46
- "@sd-jwt/utils": "0.18.0"
43
+ "@sd-jwt/decode": "0.18.1-next.1+a11aff6",
44
+ "@sd-jwt/present": "0.18.1-next.1+a11aff6",
45
+ "@sd-jwt/types": "0.18.1-next.1+a11aff6",
46
+ "@sd-jwt/utils": "0.18.1-next.1+a11aff6"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public"
@@ -61,5 +61,5 @@
61
61
  "esm"
62
62
  ]
63
63
  },
64
- "gitHead": "b22b6bebfa93f6d0f3f998d4503cac0e4534f92a"
64
+ "gitHead": "a11aff63d3c88139de5dd4fcfe03a25c56a64803"
65
65
  }
package/src/index.ts CHANGED
@@ -32,15 +32,15 @@ export * from './sdjwt';
32
32
 
33
33
  export type SdJwtPayload = Record<string, unknown>;
34
34
 
35
- export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
35
+ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload, T = unknown> {
36
36
  //header type
37
37
  protected type?: string;
38
38
 
39
39
  public static readonly DEFAULT_hashAlg = 'sha-256';
40
40
 
41
- protected userConfig: SDJWTConfig = {};
41
+ protected userConfig: SDJWTConfig<T> = {};
42
42
 
43
- constructor(userConfig?: SDJWTConfig) {
43
+ constructor(userConfig?: SDJWTConfig<T>) {
44
44
  if (userConfig) {
45
45
  if (
46
46
  userConfig.hashAlg &&
@@ -86,11 +86,11 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
86
86
  return jwt;
87
87
  }
88
88
 
89
- private async VerifyJwt(jwt: Jwt, options?: VerifierOptions) {
89
+ private async VerifyJwt(jwt: Jwt, options?: T & VerifierOptions) {
90
90
  if (!this.userConfig.verifier) {
91
91
  throw new SDJWTException('Verifier not found');
92
92
  }
93
- return jwt.verify(this.userConfig.verifier, options);
93
+ return jwt.verify<T>(this.userConfig.verifier, options);
94
94
  }
95
95
 
96
96
  public async issue<Payload extends ExtendedPayload>(
@@ -196,7 +196,7 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
196
196
  // This function is for verifying the SD JWT
197
197
  // If requiredClaimKeys is provided, it will check if the required claim keys are presentation in the SD JWT
198
198
  // If requireKeyBindings is true, it will check if the key binding JWT is presentation and verify it
199
- public async verify(encodedSDJwt: string, options?: VerifierOptions) {
199
+ public async verify(encodedSDJwt: string, options?: T & VerifierOptions) {
200
200
  if (!this.userConfig.hasher) {
201
201
  throw new SDJWTException('Hasher not found');
202
202
  }
@@ -280,7 +280,7 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
280
280
  * @param options
281
281
  * @returns
282
282
  */
283
- public async validate(encodedSDJwt: string, options?: VerifierOptions) {
283
+ public async validate(encodedSDJwt: string, options?: T & VerifierOptions) {
284
284
  if (!this.userConfig.hasher) {
285
285
  throw new SDJWTException('Hasher not found');
286
286
  }
package/src/jwt.ts CHANGED
@@ -36,6 +36,11 @@ export type VerifierOptions = {
36
36
  * nonce used to verify the key binding jwt to prevent replay attacks.
37
37
  */
38
38
  keyBindingNonce?: string;
39
+
40
+ /**
41
+ * any other custom options
42
+ */
43
+ [key: string]: unknown;
39
44
  };
40
45
 
41
46
  // This class is used to create and verify JWT
@@ -146,7 +151,7 @@ export class Jwt<
146
151
  * @param options - Options for verification, such as current date and skew seconds
147
152
  * @returns
148
153
  */
149
- public async verify(verifier: Verifier, options?: VerifierOptions) {
154
+ public async verify<T>(verifier: Verifier<T>, options?: T & VerifierOptions) {
150
155
  const skew = options?.skewSeconds ? options.skewSeconds : 0;
151
156
  const currentDate = options?.currentDate ?? Math.floor(Date.now() / 1000);
152
157
  if (
@@ -174,7 +179,7 @@ export class Jwt<
174
179
  }
175
180
  const data = this.getUnsignedToken();
176
181
 
177
- const verified = await verifier(data, this.signature);
182
+ const verified = await verifier(data, this.signature, options);
178
183
  if (!verified) {
179
184
  throw new SDJWTException('Verify Error: Invalid JWT Signature');
180
185
  }