Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Aug 10, 2024
1 parent ac13592 commit 6e6c15d
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 49 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand All @@ -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')
Expand Down
20 changes: 13 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
2 changes: 1 addition & 1 deletion src/v2/digester.ts → src/lib/digester.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import digest from "./digest";
import digest from "../lib/digest";

const digester = (name = 'sha-256') => {
if (name !== 'sha-256'){
Expand Down
4 changes: 2 additions & 2 deletions src/v2/holder.ts → src/lib/holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions src/v2/issuer.ts → src/lib/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib/sd_hash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import digest from "../v2/digest"
import digest from "./digest"

import {
COMBINED_serialization_FORMAT_SEPARATOR,
Expand Down
6 changes: 3 additions & 3 deletions src/v2/verifier.ts → src/lib/verifier.ts
Original file line number Diff line number Diff line change
@@ -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<T=VerifiedSdJwt>(options: RequestVerifier){
if (!options.digester){
Expand Down
13 changes: 0 additions & 13 deletions src/v2/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/controller-documents/token.resolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'){
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/disclosure-edge-cases/full-disclosure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion test/disclosure-edge-cases/no-disclosure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
12 changes: 6 additions & 6 deletions test/headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/reference-implementation/precondition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/v2.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
12 changes: 6 additions & 6 deletions test/vc-jose-cose-test/vc-jose-cose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand All @@ -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,
Expand All @@ -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)
}
}
Expand Down

0 comments on commit 6e6c15d

Please sign in to comment.