@sd-jwt/core 0.15.2-next.8 → 0.16.0

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/index.ts CHANGED
@@ -1,34 +1,34 @@
1
- import {
2
- base64urlDecode,
3
- base64urlEncode,
4
- SDJWTException,
5
- uint8ArrayToBase64Url,
6
- } from '@sd-jwt/utils';
7
- import { Jwt, type VerifierOptions } from './jwt';
8
- import { KBJwt } from './kbjwt';
9
- import { SDJwt, pack } from './sdjwt';
1
+ import { getSDAlgAndPayload } from '@sd-jwt/decode';
10
2
  import {
11
3
  type DisclosureFrame,
12
4
  type Hasher,
13
- type KBOptions,
5
+ IANA_HASH_ALGORITHMS,
6
+ type JwtPayload,
14
7
  KB_JWT_TYP,
8
+ type KBOptions,
15
9
  type PresentationFrame,
16
10
  type SDJWTCompact,
17
11
  type SDJWTConfig,
18
- type JwtPayload,
19
12
  type Signer,
20
- IANA_HASH_ALGORITHMS,
21
13
  } from '@sd-jwt/types';
22
- import { getSDAlgAndPayload } from '@sd-jwt/decode';
14
+ import {
15
+ base64urlDecode,
16
+ base64urlEncode,
17
+ SDJWTException,
18
+ uint8ArrayToBase64Url,
19
+ } from '@sd-jwt/utils';
23
20
  import { FlattenJSON } from './flattenJSON';
24
21
  import { GeneralJSON } from './generalJSON';
22
+ import { Jwt, type VerifierOptions } from './jwt';
23
+ import { KBJwt } from './kbjwt';
24
+ import { pack, SDJwt } from './sdjwt';
25
25
 
26
- export * from './sdjwt';
27
- export * from './kbjwt';
28
- export * from './jwt';
29
26
  export * from './decoy';
30
27
  export * from './flattenJSON';
31
28
  export * from './generalJSON';
29
+ export * from './jwt';
30
+ export * from './kbjwt';
31
+ export * from './sdjwt';
32
32
 
33
33
  export type SdJwtPayload = Record<string, unknown>;
34
34
 
@@ -154,7 +154,7 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
154
154
  * @returns
155
155
  */
156
156
  protected validateReservedFields<T extends ExtendedPayload>(
157
- disclosureFrame: DisclosureFrame<T>,
157
+ _disclosureFrame: DisclosureFrame<T>,
158
158
  ) {
159
159
  return;
160
160
  }
@@ -466,7 +466,7 @@ export class SDJwtGeneralJSONInstance<ExtendedPayload extends SdJwtPayload> {
466
466
  * @returns
467
467
  */
468
468
  protected validateReservedFields<T extends ExtendedPayload>(
469
- disclosureFrame: DisclosureFrame<T>,
469
+ _disclosureFrame: DisclosureFrame<T>,
470
470
  ) {
471
471
  return;
472
472
  }
package/src/jwt.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { base64urlEncode, SDJWTException } from '@sd-jwt/utils';
2
- import type { Base64urlString, Signer, Verifier } from '@sd-jwt/types';
3
1
  import { decodeJwt } from '@sd-jwt/decode';
2
+ import type { Base64urlString, Signer, Verifier } from '@sd-jwt/types';
3
+ import { base64urlEncode, SDJWTException } from '@sd-jwt/utils';
4
4
 
5
5
  export type JwtData<
6
6
  Header extends Record<string, unknown>,
package/src/kbjwt.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { SDJWTException } from '@sd-jwt/utils';
2
- import { Jwt } from './jwt';
3
1
  import {
4
2
  type JwtPayload,
5
3
  KB_JWT_TYP,
4
+ type KbVerifier,
6
5
  type kbHeader,
7
6
  type kbPayload,
8
- type KbVerifier,
9
7
  } from '@sd-jwt/types';
8
+ import { SDJWTException } from '@sd-jwt/utils';
9
+ import { Jwt } from './jwt';
10
10
 
11
11
  export class KBJwt<
12
12
  Header extends kbHeader = kbHeader,
package/src/sdjwt.ts CHANGED
@@ -1,23 +1,23 @@
1
- import { createDecoy } from './decoy';
2
- import { SDJWTException, Disclosure } from '@sd-jwt/utils';
3
- import { Jwt } from './jwt';
4
- import { KBJwt } from './kbjwt';
1
+ import { createHashMapping, getSDAlgAndPayload, unpack } from '@sd-jwt/decode';
2
+ import { transformPresentationFrame } from '@sd-jwt/present';
5
3
  import {
6
4
  type DisclosureFrame,
7
5
  type Hasher,
8
6
  type HasherAndAlg,
7
+ type kbHeader,
8
+ type kbPayload,
9
9
  type PresentationFrame,
10
- type SDJWTCompact,
10
+ type SaltGenerator,
11
11
  SD_DECOY,
12
12
  SD_DIGEST,
13
13
  SD_LIST_KEY,
14
14
  SD_SEPARATOR,
15
- type SaltGenerator,
16
- type kbHeader,
17
- type kbPayload,
15
+ type SDJWTCompact,
18
16
  } from '@sd-jwt/types';
19
- import { createHashMapping, getSDAlgAndPayload, unpack } from '@sd-jwt/decode';
20
- import { transformPresentationFrame } from '@sd-jwt/present';
17
+ import { Disclosure, SDJWTException } from '@sd-jwt/utils';
18
+ import { createDecoy } from './decoy';
19
+ import { Jwt } from './jwt';
20
+ import { KBJwt } from './kbjwt';
21
21
 
22
22
  export type SDJwtData<
23
23
  Header extends Record<string, unknown>,
@@ -254,7 +254,7 @@ export const pack = async <T extends Record<string, unknown>>(
254
254
 
255
255
  for (const key in disclosureFrame) {
256
256
  if (key !== SD_DIGEST) {
257
- const idx = Number.parseInt(key);
257
+ const idx = Number.parseInt(key, 10);
258
258
  const packed = await pack(
259
259
  claims[idx],
260
260
  disclosureFrame[idx],
@@ -287,7 +287,7 @@ export const pack = async <T extends Record<string, unknown>>(
287
287
  *
288
288
  * So If the index `i` is in the disclosure list(sd), then we create a disclosure for the claim
289
289
  */
290
- // @ts-ignore
290
+ // @ts-expect-error
291
291
  if (sd.includes(i)) {
292
292
  const salt = await saltGenerator(16);
293
293
  const disclosure = new Disclosure([salt, claim]);
@@ -312,7 +312,7 @@ export const pack = async <T extends Record<string, unknown>>(
312
312
  for (const key in disclosureFrame) {
313
313
  if (key !== SD_DIGEST) {
314
314
  const packed = await pack(
315
- // @ts-ignore
315
+ // @ts-expect-error
316
316
  claims[key],
317
317
  disclosureFrame[key],
318
318
  hash,
@@ -329,7 +329,6 @@ export const pack = async <T extends Record<string, unknown>>(
329
329
  const claim = recursivePackedClaims[key]
330
330
  ? recursivePackedClaims[key]
331
331
  : claims[key];
332
- // @ts-ignore
333
332
  if (sd.includes(key)) {
334
333
  const salt = await saltGenerator(16);
335
334
  const disclosure = new Disclosure([salt, key, claim]);
@@ -1,7 +1,7 @@
1
- import { createDecoy } from '../decoy';
2
- import { describe, expect, test } from 'vitest';
3
- import { base64urlEncode } from '@sd-jwt/utils';
4
1
  import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
2
+ import { base64urlEncode } from '@sd-jwt/utils';
3
+ import { describe, expect, test } from 'vitest';
4
+ import { createDecoy } from '../decoy';
5
5
 
6
6
  const hash = {
7
7
  hasher: digest,
@@ -1,7 +1,7 @@
1
+ import Crypto from 'node:crypto';
2
+ import type { Signer, Verifier } from '@sd-jwt/types';
1
3
  import { describe, expect, test } from 'vitest';
2
4
  import { GeneralJSON } from '..';
3
- import type { Signer, Verifier } from '@sd-jwt/types';
4
- import Crypto from 'node:crypto';
5
5
 
6
6
  const createSignerVerifier = () => {
7
7
  const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
@@ -1,9 +1,9 @@
1
- import { SDJwtInstance, type SdJwtPayload } from '../index';
2
- import type { Signer, Verifier, KbVerifier, JwtPayload } from '@sd-jwt/types';
3
1
  import Crypto, { type KeyLike } from 'node:crypto';
2
+ import { digest, ES256, generateSalt } from '@sd-jwt/crypto-nodejs';
3
+ import type { JwtPayload, KbVerifier, Signer, Verifier } from '@sd-jwt/types';
4
+ import { exportJWK, importJWK, type JWK } from 'jose';
4
5
  import { describe, expect, test } from 'vitest';
5
- import { digest, generateSalt, ES256 } from '@sd-jwt/crypto-nodejs';
6
- import { importJWK, exportJWK, type JWK } from 'jose';
6
+ import { SDJwtInstance, type SdJwtPayload } from '../index';
7
7
 
8
8
  // Extract the major version as a number
9
9
  const nodeVersionMajor = Number.parseInt(
@@ -373,7 +373,7 @@ describe('index', () => {
373
373
  },
374
374
  );
375
375
  try {
376
- const results = await sdjwt.verify(presentation, ['foo'], true);
376
+ await sdjwt.verify(presentation, { requiredClaimKeys: ['foo'] });
377
377
  } catch (e) {
378
378
  expect(e).toBeDefined();
379
379
  }
@@ -403,7 +403,7 @@ describe('index', () => {
403
403
  },
404
404
  );
405
405
  try {
406
- const presentation = await sdjwt.present<typeof claims>(
406
+ await sdjwt.present<typeof claims>(
407
407
  credential,
408
408
  { foo: true },
409
409
  {
@@ -459,7 +459,7 @@ describe('index', () => {
459
459
  },
460
460
  );
461
461
  try {
462
- const results = await sdjwt.verify(presentation, ['foo'], true);
462
+ await sdjwt.verify(presentation, { requiredClaimKeys: ['foo'] });
463
463
  } catch (e) {
464
464
  expect(e).toBeDefined();
465
465
  }
@@ -625,7 +625,7 @@ describe('index', () => {
625
625
  kbVerifier: await ES256.getVerifier(kbPubkey),
626
626
  });
627
627
 
628
- const decode = await sdjwt.verify(encodedJwt, undefined, true);
628
+ const decode = await sdjwt.verify(encodedJwt);
629
629
  expect(decode).toBeDefined();
630
630
  },
631
631
  );
@@ -1,8 +1,8 @@
1
- import { SDJWTException } from '@sd-jwt/utils';
2
- import { Jwt } from '../jwt';
3
1
  import Crypto from 'node:crypto';
4
2
  import type { Signer, Verifier } from '@sd-jwt/types';
3
+ import { SDJWTException } from '@sd-jwt/utils';
5
4
  import { describe, expect, test } from 'vitest';
5
+ import { Jwt } from '../jwt';
6
6
 
7
7
  describe('JWT', () => {
8
8
  test('create', async () => {
@@ -106,7 +106,7 @@ describe('JWT', () => {
106
106
  });
107
107
 
108
108
  test('encode', async () => {
109
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
109
+ const { privateKey } = Crypto.generateKeyPairSync('ed25519');
110
110
  const testSigner: Signer = async (data: string) => {
111
111
  const sig = Crypto.sign(null, Buffer.from(data), privateKey);
112
112
  return Buffer.from(sig).toString('base64url');
@@ -140,7 +140,7 @@ describe('JWT', () => {
140
140
  });
141
141
 
142
142
  test('getUnsignedToken failed', async () => {
143
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
143
+ const { privateKey } = Crypto.generateKeyPairSync('ed25519');
144
144
  const testSigner: Signer = async (data: string) => {
145
145
  const sig = Crypto.sign(null, Buffer.from(data), privateKey);
146
146
  return Buffer.from(sig).toString('base64url');
@@ -158,7 +158,7 @@ describe('JWT', () => {
158
158
  });
159
159
 
160
160
  test('wrong encoded field', async () => {
161
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
161
+ const { privateKey } = Crypto.generateKeyPairSync('ed25519');
162
162
  const testSigner: Signer = async (data: string) => {
163
163
  const sig = Crypto.sign(null, Buffer.from(data), privateKey);
164
164
  return Buffer.from(sig).toString('base64url');
@@ -178,7 +178,7 @@ describe('JWT', () => {
178
178
  });
179
179
 
180
180
  test('verify failed no signature', async () => {
181
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
181
+ const { publicKey } = Crypto.generateKeyPairSync('ed25519');
182
182
  const testVerifier: Verifier = async (data: string, sig: string) => {
183
183
  return Crypto.verify(
184
184
  null,
@@ -201,7 +201,7 @@ describe('JWT', () => {
201
201
  });
202
202
 
203
203
  test('verify with issuance date in the future', async () => {
204
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
204
+ const { publicKey } = Crypto.generateKeyPairSync('ed25519');
205
205
  const testVerifier: Verifier = async (data: string, sig: string) => {
206
206
  return Crypto.verify(
207
207
  null,
@@ -227,7 +227,7 @@ describe('JWT', () => {
227
227
  });
228
228
 
229
229
  test('verify with not before in the future', async () => {
230
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
230
+ const { publicKey } = Crypto.generateKeyPairSync('ed25519');
231
231
  const testVerifier: Verifier = async (data: string, sig: string) => {
232
232
  return Crypto.verify(
233
233
  null,
@@ -253,7 +253,7 @@ describe('JWT', () => {
253
253
  });
254
254
 
255
255
  test('verify with expired', async () => {
256
- const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
256
+ const { publicKey } = Crypto.generateKeyPairSync('ed25519');
257
257
  const testVerifier: Verifier = async (data: string, sig: string) => {
258
258
  return Crypto.verify(
259
259
  null,
@@ -1,15 +1,14 @@
1
- import type { SDJWTException } from '@sd-jwt/utils';
2
- import { KBJwt } from '../kbjwt';
1
+ import Crypto, { type KeyLike } from 'node:crypto';
3
2
  import {
4
3
  type JwtPayload,
5
4
  KB_JWT_TYP,
6
5
  type KbVerifier,
7
6
  type Signer,
8
- Verifier,
9
7
  } from '@sd-jwt/types';
10
- import Crypto, { type KeyLike } from 'node:crypto';
8
+ import type { SDJWTException } from '@sd-jwt/utils';
9
+ import { exportJWK, importJWK, type JWK } from 'jose';
11
10
  import { describe, expect, test } from 'vitest';
12
- import { type JWK, exportJWK, importJWK } from 'jose';
11
+ import { KBJwt } from '../kbjwt';
13
12
 
14
13
  describe('KB JWT', () => {
15
14
  test('create', async () => {
@@ -202,8 +201,8 @@ describe('KB JWT', () => {
202
201
  },
203
202
  };
204
203
  const testVerifier: KbVerifier = async (
205
- data: string,
206
- sig: string,
204
+ _data: string,
205
+ _sig: string,
207
206
  payload: JwtPayload,
208
207
  ) => {
209
208
  expect(payload).toStrictEqual(payload);
@@ -251,8 +250,8 @@ describe('KB JWT', () => {
251
250
  },
252
251
  };
253
252
  const testVerifier: KbVerifier = async (
254
- data: string,
255
- sig: string,
253
+ _data: string,
254
+ _sig: string,
256
255
  payload: JwtPayload,
257
256
  ) => {
258
257
  expect(payload).toStrictEqual(payload);
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, test } from 'vitest';
2
+
2
3
  describe('Should always pass', () => {
3
4
  test('adds 1 + 2 to equal 3', () => {
4
5
  expect(1 + 2).toBe(3);
@@ -1,11 +1,11 @@
1
- import { Disclosure } from '@sd-jwt/utils';
2
- import { Jwt } from '../jwt';
3
- import { SDJwt, listKeys, pack } from '../sdjwt';
4
1
  import Crypto from 'node:crypto';
5
- import { describe, test, expect } from 'vitest';
6
- import type { DisclosureFrame, Signer } from '@sd-jwt/types';
7
2
  import { generateSalt, digest as hasher } from '@sd-jwt/crypto-nodejs';
8
- import { unpack, createHashMapping } from '@sd-jwt/decode';
3
+ import { createHashMapping, unpack } from '@sd-jwt/decode';
4
+ import type { DisclosureFrame, Signer } from '@sd-jwt/types';
5
+ import { Disclosure } from '@sd-jwt/utils';
6
+ import { describe, expect, test } from 'vitest';
7
+ import { Jwt } from '../jwt';
8
+ import { listKeys, pack, SDJwt } from '../sdjwt';
9
9
 
10
10
  const hash = { alg: 'SHA256', hasher };
11
11
 
@@ -1,15 +1,15 @@
1
1
  import Crypto from 'node:crypto';
2
- import { SDJwtInstance, type SdJwtPayload } from '../src';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
3
5
  import type {
4
6
  DisclosureFrame,
5
7
  PresentationFrame,
6
8
  Signer,
7
9
  Verifier,
8
10
  } from '@sd-jwt/types';
9
- import fs from 'node:fs';
10
- import path from 'node:path';
11
11
  import { describe, expect, test } from 'vitest';
12
- import { digest, generateSalt } from '@sd-jwt/crypto-nodejs';
12
+ import { SDJwtInstance, type SdJwtPayload } from '../src';
13
13
 
14
14
  const createSignerVerifier = () => {
15
15
  const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');