diff --git a/src/lib/Holder.ts b/src/lib/Holder.ts index 6450696..9152f14 100644 --- a/src/lib/Holder.ts +++ b/src/lib/Holder.ts @@ -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"; @@ -69,6 +69,6 @@ export default class Holder { }) presented_token += kbt } - return presented_token; + return presented_token as PresentedCompactSdJwt; }; } diff --git a/src/lib/Issuer.ts b/src/lib/Issuer.ts index cefa6a4..d2b164d 100644 --- a/src/lib/Issuer.ts +++ b/src/lib/Issuer.ts @@ -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, @@ -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; }; } diff --git a/src/lib/Verifier.ts b/src/lib/Verifier.ts index f92b6ba..40ff6bb 100644 --- a/src/lib/Verifier.ts +++ b/src/lib/Verifier.ts @@ -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'; @@ -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 } } \ No newline at end of file diff --git a/src/v2/verifier.ts b/src/v2/verifier.ts index df9ffbb..a518b70 100644 --- a/src/v2/verifier.ts +++ b/src/v2/verifier.ts @@ -13,26 +13,28 @@ export default function verifier(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 => { 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 } } }