Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
OR13 committed Dec 4, 2023
1 parent 0568bcb commit 919b979
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/lib/Holder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import moment from 'moment';
import * as jose from "jose";
import { HolderCtx, RequestPresentation,Signer, SdHolderState } from "../types";
import { HolderCtx, RequestPresentation,Signer, SdHolderState, PresentedCompactSdJwt } from "../types";
import { COMBINED_serialization_FORMAT_SEPARATOR, KB_JWT_TYP_HEADER } from "./constants";
import _select_disclosures from './_select_disclosures'
import Parse from "./Parse";
Expand Down Expand Up @@ -69,6 +69,6 @@ export default class Holder {
})
presented_token += kbt
}
return presented_token;
return presented_token as PresentedCompactSdJwt;
};
}
4 changes: 2 additions & 2 deletions src/lib/Issuer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RequestIssuance, Signer, Digester, IssuerCtx, Salter } from "../types";
import { RequestIssuance, Signer, Digester, IssuerCtx, Salter, IssuedCompactSdJwt } from "../types";

import {
DIGEST_ALG_KEY,
Expand Down Expand Up @@ -67,6 +67,6 @@ export default class Issuer {
});
const issuedSdJwt = issuedJwt + COMBINED_serialization_FORMAT_SEPARATOR + Object.keys(config.disclosures)
.join(COMBINED_serialization_FORMAT_SEPARATOR)
return issuedSdJwt as any;
return issuedSdJwt as IssuedCompactSdJwt;
};
}
4 changes: 2 additions & 2 deletions src/lib/Verifier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { DIGEST_ALG_KEY } from "./constants";

import { VerifierCtx, RequestPresentationVerify, PublicKeyJwk } from '../types'
import { VerifierCtx, RequestPresentationVerify, VerifiedSdJwt } from '../types'

import JWS from './JWS';
import Parse from './Parse';
Expand Down Expand Up @@ -107,6 +107,6 @@ export default class Verifier {
const { disclosureMap, hashToEncodedDisclosureMap } = await Parse.expload(presentation, { digester: digester })
const state = { _hash_to_disclosure: hashToEncodedDisclosureMap, _hash_to_decoded_disclosure: disclosureMap }
const output = _unpack_disclosed_claims(verifiedIssuanceToken.claimset, state)
return JSON.parse(JSON.stringify({ protectedHeader: verifiedIssuanceToken.protectedHeader, claimset: output })) as any
return JSON.parse(JSON.stringify({ protectedHeader: verifiedIssuanceToken.protectedHeader, claimset: output })) as VerifiedSdJwt
}
}
12 changes: 7 additions & 5 deletions src/v2/verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ export default function verifier<T=VerifiedSdJwt>(options: RequestVerifier){
options.digester = digester()
}
if (options.publicKeyJwk){
options.alg = options.alg || options.publicKeyJwk.alg
const { publicKeyJwk } = options
options.alg = options.alg || publicKeyJwk.alg
if (!options.alg){
throw new Error('alg must be passed as an option or restricted via publicKeyJwk')
}
options.verifier = {
verify: async (token: string) => {
const parsed = Parse.compact(token)
const verifier = await JWS.verifier(options.publicKeyJwk as PublicKeyJwk)
return verifier.verify(parsed.jwt)
const { jwt } = Parse.compact(token)
const verifier = await JWS.verifier(publicKeyJwk as PublicKeyJwk)
return verifier.verify(jwt)
}
}
}
return {
verify: async ({ token, audience, nonce }: { token: string, audience ?: string, nonce?: string }): Promise<T> => {
const role = new Verifier(options as VerifierCtx)
return role.verify({
const verified = await role.verify({
presentation: token,
aud: audience,
nonce: nonce
})
return verified as T
}
}
}
Expand Down

0 comments on commit 919b979

Please sign in to comment.