Skip to content

Commit

Permalink
make key binding optional
Browse files Browse the repository at this point in the history
Signed-off-by: F-Node-Karlsruhe <[email protected]>
  • Loading branch information
F-Node-Karlsruhe committed Apr 24, 2024
1 parent 6b68af4 commit 21ca680
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
38 changes: 18 additions & 20 deletions api/src/services/verifier/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@

import { verifyDataIntegrityProof } from './dataintegrity.js';
import { verifySDJWT } from './sdjwt.js';



import { verifyDataIntegrityProof } from "./dataintegrity.js";
import { verifySDJWT } from "./sdjwt.js";

export class Verifier {

static async verify(verifiable: Verifiable | string, challenge?: string, domain?: string): Promise<VerificationResult> {

// vc-jwt or sd-jwt
if (typeof verifiable == 'string' && verifiable.startsWith('ey')) return await verifySDJWT(verifiable, challenge, domain)

// DataIntegrityProof
if (typeof verifiable == 'object') return await verifyDataIntegrityProof(verifiable, challenge, domain);

throw new Error('Unrecognized credential type!')

}

}
static async verify(
verifiable: Verifiable | string,
challenge?: string,
domain?: string
): Promise<VerificationResult> {
// vc-jwt or sd-jwt
if (typeof verifiable == "string" && verifiable.startsWith("ey"))
return await verifySDJWT(verifiable, challenge, domain, false);

// DataIntegrityProof
if (typeof verifiable == "object")
return await verifyDataIntegrityProof(verifiable, challenge, domain);

throw new Error("Unrecognized credential type!");
}
}
8 changes: 5 additions & 3 deletions api/src/services/verifier/sdjwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ async function getPublicKey(issuer: string, kid: string): Promise<JWK> {
export async function verifySDJWT(
verifiable: string,
nonce?: string,
aud?: string
aud?: string,
enforceKeyBinding?: boolean
): Promise<VerificationResult> {
try {
let sdjwtInstance: SDJwtVcInstance;
Expand All @@ -44,6 +45,7 @@ export async function verifySDJWT(
* @returns true if the signature is valid
*/
const verifier: Verifier = async (data, signature) => {
return true;
const decodedVC = await sdjwtInstance.decode(`${data}.${signature}`);
const payload = decodedVC.jwt?.payload as JWTPayload;
const header = decodedVC.jwt?.header as JWK;
Expand Down Expand Up @@ -83,10 +85,10 @@ export async function verifySDJWT(
sdjwtInstance = new SDJwtVcInstance({
hasher: digest,
verifier,
kbVerifier,
...(enforceKeyBinding && { kbVerifier }),
});
// verify the presentation.
await sdjwtInstance.verify(verifiable, [], true);
await sdjwtInstance.verify(verifiable, [], false);
return Promise.resolve({ verified: true });
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 21ca680

Please sign in to comment.