Skip to content

Commit

Permalink
Remove unused jwt-decode dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Hinek <[email protected]>
  • Loading branch information
frankhinek committed Dec 11, 2023
1 parent 11f7f90 commit 679e74c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 32 deletions.
22 changes: 4 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions packages/credentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
"@sphereon/pex": "2.1.0",
"@web5/common": "0.2.2",
"@web5/crypto": "0.2.4",
"@web5/dids": "0.2.3",
"jwt-decode": "4.0.0"
"@web5/dids": "0.2.3"
},
"devDependencies": {
"@playwright/test": "1.40.1",
Expand Down
2 changes: 0 additions & 2 deletions packages/credentials/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export type * from 'jwt-decode';

export * from './jwt.js';
export * from './presentation-exchange.js';
export * from './verifiable-credential.js';
Expand Down
20 changes: 10 additions & 10 deletions packages/credentials/tests/jwt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { PrivateKeyJwk } from '@web5/crypto';
import type { JwtHeader, JwtPayload } from 'jwt-decode';
import type { JwtHeaderParams, JwtPayload, PrivateKeyJwk } from '@web5/crypto';

import { expect } from 'chai';
import { Convert } from '@web5/common';
Expand All @@ -23,7 +22,7 @@ describe('Jwt', () => {
});

it('throws error if JWT header is missing typ property', async () => {
const header: JwtHeader = { alg: 'ES256K', kid: 'whateva' };
const header: JwtHeaderParams = { alg: 'ES256K', kid: 'whateva' };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

expect(() =>
Expand All @@ -32,7 +31,7 @@ describe('Jwt', () => {
});

it('throws error if JWT header typ property is not set to JWT', async () => {
const header: JwtHeader = { typ: 'hehe', alg: 'ES256K', kid: 'whateva' };
const header: JwtHeaderParams = { typ: 'hehe', alg: 'ES256K', kid: 'whateva' };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

expect(() =>
Expand All @@ -41,7 +40,8 @@ describe('Jwt', () => {
});

it('throws error if JWT header alg property is missing', async () => {
const header: JwtHeader = { typ: 'JWT', kid: 'whateva' };
// @ts-expect-error because alg is intentionally missing to trigger error.
const header: JwtHeaderParams = { typ: 'JWT', kid: 'whateva' };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

expect(() =>
Expand All @@ -50,7 +50,7 @@ describe('Jwt', () => {
});

it('throws error if JWT header kid property is missing', async () => {
const header: JwtHeader = { typ: 'JWT', alg: 'ES256K' };
const header: JwtHeaderParams = { typ: 'JWT', alg: 'ES256K' };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

expect(() =>
Expand All @@ -59,7 +59,7 @@ describe('Jwt', () => {
});

it('throws error if JWT payload is not properly base64url encoded', async () => {
const header: JwtHeader = { typ: 'JWT', alg: 'ES256K', kid: 'whateva' };
const header: JwtHeaderParams = { typ: 'JWT', alg: 'ES256K', kid: 'whateva' };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

expect(() =>
Expand All @@ -71,7 +71,7 @@ describe('Jwt', () => {
describe('verify()', () => {
it('throws error if JWT header kid does not dereference a verification method', async () => {
const did = await DidKeyMethod.create({ keyAlgorithm: 'secp256k1' });
const header: JwtHeader = { typ: 'JWT', alg: 'ES256K', kid: did.did };
const header: JwtHeaderParams = { typ: 'JWT', alg: 'ES256K', kid: did.did };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

const payload: JwtPayload = { iat: Math.floor(Date.now() / 1000) };
Expand All @@ -87,7 +87,7 @@ describe('Jwt', () => {

it('throws error if alg is not supported', async () => {
const did = await DidKeyMethod.create({ keyAlgorithm: 'secp256k1' });
const header: JwtHeader = { typ: 'JWT', alg: 'RS256', kid: did.document.verificationMethod![0].id };
const header: JwtHeaderParams = { typ: 'JWT', alg: 'RS256', kid: did.document.verificationMethod![0].id };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

const payload: JwtPayload = { iat: Math.floor(Date.now() / 1000) };
Expand All @@ -103,7 +103,7 @@ describe('Jwt', () => {

it('returns signer DID if verification succeeds', async () => {
const did = await DidKeyMethod.create({ keyAlgorithm: 'secp256k1' });
const header: JwtHeader = { typ: 'JWT', alg: 'ES256K', kid: did.document.verificationMethod![0].id };
const header: JwtHeaderParams = { typ: 'JWT', alg: 'ES256K', kid: did.document.verificationMethod![0].id };
const base64UrlEncodedHeader = Convert.object(header).toBase64Url();

const payload: JwtPayload = { iat: Math.floor(Date.now() / 1000) };
Expand Down

0 comments on commit 679e74c

Please sign in to comment.