From 6e6c15db6fd3ea79d4082f667fbc76c473d6100f Mon Sep 17 00:00:00 2001 From: Orie Steele Date: Sat, 10 Aug 2024 17:14:29 -0500 Subject: [PATCH] cleaning --- README.md | 4 ++-- src/index.ts | 20 ++++++++++++------- src/{v2 => lib}/digest.ts | 0 src/{v2 => lib}/digester.ts | 2 +- src/{v2 => lib}/holder.ts | 4 ++-- src/{v2 => lib}/issuer.ts | 4 ++-- src/{v2 => lib}/key.ts | 0 src/{v2 => lib}/random.ts | 0 src/{v2 => lib}/runtime.ts | 0 src/{v2 => lib}/salter.ts | 0 src/lib/sd_hash.ts | 2 +- src/{v2 => lib}/verifier.ts | 6 +++--- src/v2/index.ts | 13 ------------ .../token.resolver.test.ts | 4 ++-- .../full-disclosure.test.ts | 2 +- .../no-disclosure.test.ts | 2 +- test/headers.test.ts | 12 +++++------ .../precondition.test.ts | 2 +- test/v2.e2e.test.ts | 2 +- test/vc-jose-cose-test/vc-jose-cose.test.ts | 12 +++++------ 20 files changed, 42 insertions(+), 49 deletions(-) rename src/{v2 => lib}/digest.ts (100%) rename src/{v2 => lib}/digester.ts (84%) rename src/{v2 => lib}/holder.ts (93%) rename src/{v2 => lib}/issuer.ts (95%) rename src/{v2 => lib}/key.ts (100%) rename src/{v2 => lib}/random.ts (100%) rename src/{v2 => lib}/runtime.ts (100%) rename src/{v2 => lib}/salter.ts (100%) rename src/{v2 => lib}/verifier.ts (90%) delete mode 100644 src/v2/index.ts diff --git a/README.md b/README.md index 6267569..f2d9340 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ const verification = await sd.verifier({ const kid = decodedHeader.kid as string const absoluteDidUrl = kid && kid.startsWith(iss)? kid : `${iss}#${kid}` const { publicKeyJwk } = await dereference(absoluteDidUrl) - const verifier = await sd.JWS.verifier(publicKeyJwk) + const verifier = await SD.jws.verifier(publicKeyJwk) return verifier.verify(jwt) } if (decodedHeader.typ === 'kb+jwt'){ @@ -229,7 +229,7 @@ const verification = await sd.verifier({ const kid = decodedHeader.kid as string const absoluteDidUrl = kid && kid.startsWith(iss)? kid : `${iss}#${kid}` const { publicKeyJwk } = await dereference(absoluteDidUrl) - const verifier = await sd.JWS.verifier(publicKeyJwk) + const verifier = await SD.jws.verifier(publicKeyJwk) return verifier.verify(jwt) } throw new Error('Unsupported token typ') diff --git a/src/index.ts b/src/index.ts index 12df900..41f17fe 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,22 @@ +import YAML from './YAML-SD' -import JWK from './lib/JWK' -import JWS from './lib/JWS' -import Parse from './lib/Parse' +import jwk from './lib/JWK' +import jws from './lib/JWS' +import parse from './lib/Parse' -import YAML from './YAML-SD' +import key from './lib/key' +import salter from './lib/salter' +import digester from './lib/digester' -import v2 from './v2' +import issuer from './lib/issuer' +import holder from './lib/holder' +import verifier from './lib/verifier' -export * from './types' +const sd = { YAML, jwk, jws, parse, key, salter, digester, issuer, holder, verifier } -const sd = { ...v2, YAML, JWK, JWS, Parse } + +export * from './types' export default sd \ No newline at end of file diff --git a/src/v2/digest.ts b/src/lib/digest.ts similarity index 100% rename from src/v2/digest.ts rename to src/lib/digest.ts diff --git a/src/v2/digester.ts b/src/lib/digester.ts similarity index 84% rename from src/v2/digester.ts rename to src/lib/digester.ts index 79cff1f..dca271b 100644 --- a/src/v2/digester.ts +++ b/src/lib/digester.ts @@ -1,4 +1,4 @@ -import digest from "./digest"; +import digest from "../lib/digest"; const digester = (name = 'sha-256') => { if (name !== 'sha-256'){ diff --git a/src/v2/holder.ts b/src/lib/holder.ts similarity index 93% rename from src/v2/holder.ts rename to src/lib/holder.ts index a174ed2..3c51358 100644 --- a/src/v2/holder.ts +++ b/src/lib/holder.ts @@ -3,9 +3,9 @@ import YAML from "../YAML-SD" import digester from "./digester" import salter from "./salter" -import JWS from "../lib/JWS" +import JWS from "./JWS" -import { _present } from "../lib/_present" +import { _present } from "./_present" import { RequestHolder, PresentedCompactSdJwt } from "../types" diff --git a/src/v2/issuer.ts b/src/lib/issuer.ts similarity index 95% rename from src/v2/issuer.ts rename to src/lib/issuer.ts index 764bd66..4691efc 100644 --- a/src/v2/issuer.ts +++ b/src/lib/issuer.ts @@ -3,11 +3,11 @@ import YAML from "../YAML-SD" import digester from "./digester" import salter from "./salter" -import JWS from "../lib/JWS" +import JWS from "./JWS" import { RequestIssuer, Salter, Digester, Signer, IssuedCompactSdJwt } from "../types" -import { _issue } from "../lib/_issue" +import { _issue } from "./_issue" const issuer = (options: RequestIssuer) => { if (options.privateKeyJwk){ diff --git a/src/v2/key.ts b/src/lib/key.ts similarity index 100% rename from src/v2/key.ts rename to src/lib/key.ts diff --git a/src/v2/random.ts b/src/lib/random.ts similarity index 100% rename from src/v2/random.ts rename to src/lib/random.ts diff --git a/src/v2/runtime.ts b/src/lib/runtime.ts similarity index 100% rename from src/v2/runtime.ts rename to src/lib/runtime.ts diff --git a/src/v2/salter.ts b/src/lib/salter.ts similarity index 100% rename from src/v2/salter.ts rename to src/lib/salter.ts diff --git a/src/lib/sd_hash.ts b/src/lib/sd_hash.ts index f1fa49c..b1f85d2 100644 --- a/src/lib/sd_hash.ts +++ b/src/lib/sd_hash.ts @@ -1,5 +1,5 @@ -import digest from "../v2/digest" +import digest from "./digest" import { COMBINED_serialization_FORMAT_SEPARATOR, diff --git a/src/v2/verifier.ts b/src/lib/verifier.ts similarity index 90% rename from src/v2/verifier.ts rename to src/lib/verifier.ts index c74eba9..8f670bd 100644 --- a/src/v2/verifier.ts +++ b/src/lib/verifier.ts @@ -1,12 +1,12 @@ import digester from "./digester" -import JWS from "../lib/JWS" +import JWS from "./JWS" -import Parse from "../lib/Parse" +import Parse from "./Parse" import { PublicKeyJwk, RequestVerifier, VerifiedSdJwt } from '../types' -import { _verify } from "../lib/_verify" +import { _verify } from "./_verify" export default function verifier(options: RequestVerifier){ if (!options.digester){ diff --git a/src/v2/index.ts b/src/v2/index.ts deleted file mode 100644 index a5cb488..0000000 --- a/src/v2/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import key from './key' -import salter from './salter' -import digester from './digester' - -import issuer from './issuer' -import holder from './holder' -import verifier from './verifier' - -import JWS from '../lib/JWS' - -const v2 = { ...JWS, key, salter, digester, issuer, holder, verifier } - -export default v2 \ No newline at end of file diff --git a/test/controller-documents/token.resolver.test.ts b/test/controller-documents/token.resolver.test.ts index 1e76480..dcbc825 100644 --- a/test/controller-documents/token.resolver.test.ts +++ b/test/controller-documents/token.resolver.test.ts @@ -139,7 +139,7 @@ it('End to End Test', async () => { const kid = decodedHeader.kid as string const absoluteDidUrl = kid && kid.startsWith(iss)? kid : `${iss}#${kid}` const { publicKeyJwk } = await dereference(absoluteDidUrl) - const verifier = await sd.JWS.verifier(publicKeyJwk) + const verifier = await sd.jws.verifier(publicKeyJwk) return verifier.verify(jwt) } if (decodedHeader.typ === 'kb+jwt'){ @@ -148,7 +148,7 @@ it('End to End Test', async () => { const kid = decodedHeader.kid as string const absoluteDidUrl = kid && kid.startsWith(iss)? kid : `${iss}#${kid}` const { publicKeyJwk } = await dereference(absoluteDidUrl) - const verifier = await sd.JWS.verifier(publicKeyJwk) + const verifier = await sd.jws.verifier(publicKeyJwk) return verifier.verify(jwt) } throw new Error('Unsupported token typ') diff --git a/test/disclosure-edge-cases/full-disclosure.test.ts b/test/disclosure-edge-cases/full-disclosure.test.ts index 2467918..23e88d9 100644 --- a/test/disclosure-edge-cases/full-disclosure.test.ts +++ b/test/disclosure-edge-cases/full-disclosure.test.ts @@ -79,7 +79,7 @@ it('no disclosure and key binding', async () => { const typ = `application/vc+sd-jwt` const cty = `application/vc+ld+json` const { publicKeyJwk, privateKeyJwk } = await sd.key.generate(alg) - const signer = await sd.signer(privateKeyJwk) + const signer = await sd.jws.signer(privateKeyJwk) const salter = await sd.salter() const digester = await sd.digester() const vc = await sd.issuer({ alg, iss, kid, typ, cty, salter, digester, signer }) diff --git a/test/disclosure-edge-cases/no-disclosure.test.ts b/test/disclosure-edge-cases/no-disclosure.test.ts index a2d9143..9806557 100644 --- a/test/disclosure-edge-cases/no-disclosure.test.ts +++ b/test/disclosure-edge-cases/no-disclosure.test.ts @@ -79,7 +79,7 @@ it('no disclosure and key binding', async () => { const typ = `application/vc+sd-jwt` const cty = `application/vc+ld+json` const { publicKeyJwk, privateKeyJwk } = await sd.key.generate(alg) - const signer = await sd.signer(privateKeyJwk) + const signer = await sd.jws.signer(privateKeyJwk) const salter = await sd.salter() const digester = await sd.digester() const vc = await sd.issuer({ alg, iss, kid, typ, cty, salter, digester, signer }) diff --git a/test/headers.test.ts b/test/headers.test.ts index 576be0f..0353067 100644 --- a/test/headers.test.ts +++ b/test/headers.test.ts @@ -12,8 +12,8 @@ it('W3C Example', async () => { const iss = 'did:web:issuer.example' const nonce = '9876543210' const audience = 'did:web:verifier.example' - const issuerKeyPair = await SD.JWK.generate(alg) - const holderKeyPair = await SD.JWK.generate(alg) + const issuerKeyPair = await SD.jwk.generate(alg) + const holderKeyPair = await SD.jwk.generate(alg) const digester = testcase.digester('sha-256') const issuer = SD.issuer({ alg, @@ -22,7 +22,7 @@ it('W3C Example', async () => { cty: `application/vc+ld+json`, iss, digester, - signer: await SD.JWS.signer(issuerKeyPair.privateKeyJwk), + signer: await SD.jws.signer(issuerKeyPair.privateKeyJwk), salter }) const vc = await issuer.issue({ @@ -62,7 +62,7 @@ credentialSubject: const vp = await SD.holder({ alg, digester, - signer: await SD.JWS.signer(holderKeyPair.privateKeyJwk) + signer: await SD.jws.signer(holderKeyPair.privateKeyJwk) }).issue({ token: vc, nonce, @@ -79,8 +79,8 @@ credentialSubject: digester, verifier: { verify: async (token: string) => { - const parsed = SD.Parse.compact(token) - const verifier = await SD.JWS.verifier(issuerKeyPair.publicKeyJwk) + const parsed = SD.parse.compact(token) + const verifier = await SD.jws.verifier(issuerKeyPair.publicKeyJwk) return verifier.verify(parsed.jwt) } } diff --git a/test/reference-implementation/precondition.test.ts b/test/reference-implementation/precondition.test.ts index 81391e7..5908403 100644 --- a/test/reference-implementation/precondition.test.ts +++ b/test/reference-implementation/precondition.test.ts @@ -17,7 +17,7 @@ it('throws when _sd is present in user claims', async () => { const issuerKeyPair = await generateKeyPair(alg) const digester = testcase.digester('sha-256') const issuerPrivateKey = await exportJWK(issuerKeyPair.privateKey) - const issuerSigner = await SD.JWS.signer(issuerPrivateKey) + const issuerSigner = await SD.jws.signer(issuerPrivateKey) const issuer = SD.issuer({ alg, digester, diff --git a/test/v2.e2e.test.ts b/test/v2.e2e.test.ts index 1065c5d..5f8b86c 100644 --- a/test/v2.e2e.test.ts +++ b/test/v2.e2e.test.ts @@ -135,7 +135,7 @@ it('verbose setup', async () => { const typ = `application/vc+sd-jwt` const cty = `application/vc+ld+json` const { publicKeyJwk, privateKeyJwk } = await sd.key.generate(alg) - const signer = await sd.signer(privateKeyJwk) + const signer = await sd.jws.signer(privateKeyJwk) const salter = await sd.salter() const digester = await sd.digester() const vc = await sd.issuer({ alg, iss, kid, typ, cty, salter, digester, signer }) diff --git a/test/vc-jose-cose-test/vc-jose-cose.test.ts b/test/vc-jose-cose-test/vc-jose-cose.test.ts index 7cdfc08..7830cd4 100644 --- a/test/vc-jose-cose-test/vc-jose-cose.test.ts +++ b/test/vc-jose-cose-test/vc-jose-cose.test.ts @@ -10,13 +10,13 @@ it('W3C VC JOSE COSE Test', async () => { const alg = 'ES384' const nonce = '9876543210' const audience = 'did:web:verifier.example' - const issuerKeyPair = await SD.JWK.generate(alg) - const holderKeyPair = await SD.JWK.generate(alg) + const issuerKeyPair = await SD.jwk.generate(alg) + const holderKeyPair = await SD.jwk.generate(alg) const digester = testcase.digester('sha-256') const issuer = SD.issuer({ alg, digester, - signer: await SD.JWS.signer(issuerKeyPair.privateKeyJwk), + signer: await SD.jws.signer(issuerKeyPair.privateKeyJwk), salter }) @@ -31,7 +31,7 @@ it('W3C VC JOSE COSE Test', async () => { const vp = await SD.holder({ alg, digester, - signer: await SD.JWS.signer(holderKeyPair.privateKeyJwk) + signer: await SD.jws.signer(holderKeyPair.privateKeyJwk) }).issue({ token: vc, nonce, @@ -44,8 +44,8 @@ it('W3C VC JOSE COSE Test', async () => { digester, verifier: { verify: async (token: string) => { - const parsed = SD.Parse.compact(token) - const verifier = await SD.JWS.verifier(issuerKeyPair.publicKeyJwk) + const parsed = SD.parse.compact(token) + const verifier = await SD.jws.verifier(issuerKeyPair.publicKeyJwk) return verifier.verify(parsed.jwt) } }