Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
schlagtim committed Feb 13, 2024
1 parent 33cfe08 commit 857f91b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
32 changes: 18 additions & 14 deletions src/lib/sd-jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,31 @@ export function decodeSdJwt(encodedJwt: string) {

export default crypto;
export function provideHasher(alg: string) {
let browserAlg: string = '';
let browserAlg: string = "";
switch (alg.toLowerCase()) {
case 'sha-256':
browserAlg = "SHA-256"
case "sha-256":
browserAlg = "SHA-256";
break;
case 'sha-384':
browserAlg = "SHA-384"
case "sha-384":
browserAlg = "SHA-384";
break;
case 'sha-512':
browserAlg = "SHA-512"
case "sha-512":
browserAlg = "SHA-512";
break;
}
var enc = new TextEncoder();
const hasherAndAlgorithm: HasherAndAlgorithm = {
// TODO: how do you properly cast this?
hasher: (input: string) => crypto.subtle.digest(browserAlg, enc.encode(input)).then((val) => {
return new Uint8Array(val);
}).catch((err) => {
return new Uint8Array(0);
}),
hasher: (input: string) =>
crypto.subtle
.digest(browserAlg, enc.encode(input))
.then((val) => {
return new Uint8Array(val);
})
.catch((err) => {
return new Uint8Array(0);
}),
algorithm: alg,
}
};
return hasherAndAlgorithm;
}
}
10 changes: 5 additions & 5 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
let alg: any;
let jwtPayloadSelection = "credential";
$: sdJWt = encodedJwt ? decodeSdJwt(encodedJwt) : undefined;
$: jwtHeader = formatJsonObject(sdJWt?.header);
$: jwtPayload = formatJsonObject(sdJWt?.payload);
$: jwtSignature = sdJWt?.signature ? sdJWt?.signature.toLocaleString() : "";
$: alg = sdJWt ? sdJWt?.payload["_sd_alg"] : "";
$: disclosures = sdJWt ? sdJWt?.withHasher(provideHasher(alg)).disclosuresWithDigest() : undefined;
$: disclosures = sdJWt
? sdJWt?.withHasher(provideHasher(alg)).disclosuresWithDigest()
: undefined;
</script>

<svelte:head>
Expand All @@ -46,9 +47,8 @@
<Editor title="Signature" value={jwtSignature} emitChanges={false}></Editor>
</div>
<div class="column" style="flex: 1;">
{#await disclosures}
{:then disclosures}
<Disclosures bind:jwtPayloadSelection={jwtPayloadSelection} {disclosures}></Disclosures>
{#await disclosures then disclosures}
<Disclosures bind:jwtPayloadSelection {disclosures}></Disclosures>
{:catch error}
<p style="color: red">{error.message}</p>
{/await}
Expand Down

0 comments on commit 857f91b

Please sign in to comment.