From 679e74c6ff0d3072c9bf35ed3125a44150f199be Mon Sep 17 00:00:00 2001 From: Frank Hinek Date: Mon, 11 Dec 2023 14:44:10 -0500 Subject: [PATCH] Remove unused jwt-decode dependency Signed-off-by: Frank Hinek --- package-lock.json | 22 ++++------------------ packages/credentials/package.json | 3 +-- packages/credentials/src/index.ts | 2 -- packages/credentials/tests/jwt.spec.ts | 20 ++++++++++---------- 4 files changed, 15 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4e515b663..c20add1e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1316,11 +1316,6 @@ "resolved": "https://registry.npmjs.org/@sphereon/pex-models/-/pex-models-2.1.2.tgz", "integrity": "sha512-Ec1qZl8tuPd+s6E+ZM7v+HkGkSOjGDMLNN1kqaxAfWpITBYtTLb+d5YvwjvBZ1P2upZ7zwNER97FfW5n/30y2w==" }, - "node_modules/@sphereon/pex/node_modules/jwt-decode": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", - "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" - }, "node_modules/@sphereon/ssi-types": { "version": "0.13.0", "resolved": "https://registry.npmjs.org/@sphereon/ssi-types/-/ssi-types-0.13.0.tgz", @@ -1329,11 +1324,6 @@ "jwt-decode": "^3.1.2" } }, - "node_modules/@sphereon/ssi-types/node_modules/jwt-decode": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", - "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" - }, "node_modules/@tbd54566975/dwn-sdk-js": { "version": "0.2.8", "resolved": "https://registry.npmjs.org/@tbd54566975/dwn-sdk-js/-/dwn-sdk-js-0.2.8.tgz", @@ -6892,12 +6882,9 @@ "dev": true }, "node_modules/jwt-decode": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", - "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", - "engines": { - "node": ">=18" - } + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" }, "node_modules/k-bucket": { "version": "5.1.0", @@ -12535,8 +12522,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", diff --git a/packages/credentials/package.json b/packages/credentials/package.json index fd07a8794..6a2e45baa 100644 --- a/packages/credentials/package.json +++ b/packages/credentials/package.json @@ -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", diff --git a/packages/credentials/src/index.ts b/packages/credentials/src/index.ts index 50bd35a9c..55ad631b3 100644 --- a/packages/credentials/src/index.ts +++ b/packages/credentials/src/index.ts @@ -1,5 +1,3 @@ -export type * from 'jwt-decode'; - export * from './jwt.js'; export * from './presentation-exchange.js'; export * from './verifiable-credential.js'; diff --git a/packages/credentials/tests/jwt.spec.ts b/packages/credentials/tests/jwt.spec.ts index f1e75291a..7edec27e7 100644 --- a/packages/credentials/tests/jwt.spec.ts +++ b/packages/credentials/tests/jwt.spec.ts @@ -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'; @@ -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(() => @@ -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(() => @@ -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(() => @@ -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(() => @@ -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(() => @@ -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) }; @@ -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) }; @@ -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) };