From 640e69b1b49de6318f849b6a83fc57e1aabb4ec3 Mon Sep 17 00:00:00 2001 From: Christian Bormann <8774236+c2bo@users.noreply.github.com> Date: Mon, 12 Feb 2024 20:49:43 +0100 Subject: [PATCH 1/3] integrate browser crypto and calculate hashes --- src/lib/sd-jwt.ts | 29 ++++++++++++++++++++++++++++- src/routes/+page.svelte | 19 +++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/lib/sd-jwt.ts b/src/lib/sd-jwt.ts index 3963bfb..a850f12 100644 --- a/src/lib/sd-jwt.ts +++ b/src/lib/sd-jwt.ts @@ -1,4 +1,4 @@ -import { SdJwt } from "@sd-jwt/core"; +import { SdJwt, type HasherAndAlgorithm, HasherAlgorithm } from "@sd-jwt/core"; export function splitJwt(text: string): string[] { const result = text.split("."); @@ -57,3 +57,30 @@ export function decodeSdJwt(encodedJwt: string) { return undefined; } } + +export default crypto; +export function provideHasher(alg: string) { + let browserAlg: string = ''; + switch (alg.toLowerCase()) { + case 'sha-256': + browserAlg = "SHA-256" + break; + case 'sha-384': + browserAlg = "SHA-384" + break; + 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); + }), + algorithm: alg, + } + return hasherAndAlgorithm; +} \ No newline at end of file diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index f252a63..d8030c9 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,21 +1,23 @@ @@ -35,7 +37,12 @@
- + {#await disclosures} + {:then disclosures} + + {:catch error} +

{error.message}

+ {/await}
From 33cfe089d30a2a754b21d33760b1c93b4b699b7d Mon Sep 17 00:00:00 2001 From: Christian Bormann <8774236+c2bo@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:15:23 +0100 Subject: [PATCH 2/3] WIP: Add highlight for disclosures --- src/routes/+page.svelte | 4 ++-- src/routes/.Disclosures.svelte.swp | Bin 0 -> 12288 bytes src/routes/Disclosures.svelte | 10 +++++++++- src/routes/Editor.svelte | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 src/routes/.Disclosures.svelte.swp diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 71b28b1..545d481 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -6,7 +6,7 @@ import { onMount } from "svelte"; let encodedJwt: string | undefined = - "eyJhbGciOiAiRVMyNTYiLCAidHlwIjogInZjK3NkLWp3dCJ9.eyJfc2QiOiBbIjBuOXl6RlNXdktfQlVIaWFNaG0xMmdockN0VmFockdKNl8ta1pQLXlTcTQiLCAiQ2gtREJjTDNrYjRWYkhJd3Rrbm5aZE5VSHRoRXE5TVpqb0ZkZzZpZGlobyIsICJEVzdnRlZaU3V5cjQyWVNZeDhwOHJWS0VrdEp6SjN1RkltZW5tSkJJbWRzIiwgIkkwMGZjRlVvRFhDdWNwNXl5MnVqcVBzc0RWR2FXTmlVbGlOel9hd0QwZ2MiLCAiWDlNYVBhRldtUVlwZkhFZHl0UmRhY2xuWW9FcnU4RXp0QkVVUXVXT2U0NCIsICJkOHFrZlBkb2UyUFlFOTNkNU1fZ0JMMWdabHBGUktDYzBkMWxhb2RfX3MwIiwgImxJM0wwaHNlQ1JXbVVQZzgyVkNVTl9hMTdzTUxfNjRRZ0E0SkZUWURGREUiLCAicHVNcEdMb0FHUmJjc0FnNTBVWjBoaFFMS0NMNnF6eFNLNDMwNGtCbjNfSSIsICJ6VTQ1MmxrR2JFS2g4WnVIXzhLeDNDVXZuMUY0eTFnWkxxbERUZ1hfOFBrIl0sICJpc3MiOiAiaHR0cHM6Ly9waWQtcHJvdmlkZXIubWVtYmVyc3RhdGUuZXhhbXBsZS5ldSIsICJpYXQiOiAxNTQxNDkzNzI0LCAiZXhwIjogMTg4MzAwMDAwMCwgInZjd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iY3JlZGVudGlhbFN1YmplY3QiLCJkaWQ6cGVlcjo0cmVjZWl2ZXItcGVlci1kaWQiXQ~WyJxYzlObkVjeVA4YmsxV2RKTE53c1BBIiwiZGF0ZU9mQmlydGgiLCIyMDAwMDEwMSJd~WyJvVXJsUnNfRzlncWlQN2o4TDhPekd3IiwibmFtZSIsIkpvaG4iXQ~WyJpeld6c3BQMzUxdm55dzN0eno0blNnIiwibGFzdE5hbWUiLCJEb2UiXQ~eyJ0eXAiOiJrYitqd3QiLCJhbGciOiJFZERTQSJ9.eyJpYXQiOjE3MDc2NjcxNTM2MzMsImF1ZCI6ImRpZDpwZWVyOjQ6c29tZS12ZXJpZmllciIsIm5vbmNlIjoiaVloOXBoU3ZWWTFVcUpsX05pNklJUSIsIl9zZF9oYXNoIjoiRTYwNWJfbnJPallsdUlSbktfQThKNTNhemwwcG8wcThBbHBJczZrQm5JWSJ9.6ZAydMHRVByM02Z79zQSWuZU3ZfNIkmVrMXM2ZVR-nN92h_J9D5-2cB7gPZ3aDP3Z-BY1Wj2kp_cIakv5ji3Cw"; let jwtHeader = ""; let jwtPayload = ""; let jwtSignature = ""; @@ -48,7 +48,7 @@
{#await disclosures} {:then disclosures} - + {:catch error}

{error.message}

{/await} diff --git a/src/routes/.Disclosures.svelte.swp b/src/routes/.Disclosures.svelte.swp new file mode 100644 index 0000000000000000000000000000000000000000..297d3c0130d80ef66b9ee27bba51436633f1ad0a GIT binary patch literal 12288 zcmeI2&1)n@7>6q&yF0ocq97{5mYo%{;7m_ui7b#6F7kZxBuR$rkPD>Z`aAwp_ze#dVAK!``@h*xV1-F(#Lb(2u8T|O#|yrmP`Ly>IT zt=6h7{qojOm6Z_OmWgL4qOX{=S3>D=A^QoF6**vBu_F_k0As)yxVM46>Xa{@TE9?R ztm?pd>nZxk!|V4RV|tANW55_N28;n?z!)$Fi~(cde`P?$bL4HT=)P=K8`XaNeI0LQ?WrwDluTnF!fXTfps=Sf0tfg9j` zum|1+Tc8RSz*+DpI0H_DV}O9)9wg*v@DunEd=I_?pMg)o4X_6kcmu>B0I!2h@DjKJ zUH}bH1B>8E@Hlu3oCJ3sAmk?a1$+xW2Oonyumb|%0}pJ1HE;<$4bFk%;C`ST|Dipb z%NQ^Qi~(c77%&Emfq%w;V@oyStVv3{q*Q9V-gbajFnfO46I>*9I^WS3TPEo3aJEzS z!-RP%6umk{NI&W=qsI?r%-vC)>JZ(aKkIZ6zgF5}hmJ8k%`Xz4C3xF2uG6ZHYfl=I zFzBj-O`LTOwG2aFb&)hqXUImT)z_&MJoF0*v+CO%3;LV2SENe9n900o#dcKL-2(NVcM97M`5p=m5L=Ea3Ld?^E@z3Sq>G8BwVtdVu@ZsYI&HrP^5qArbBws z61hnbqMjb~9>BW&v+Cp!=*yBu6?@zWr+wAGa zFSf3}n(kLG2s@*N!qfwo_t|+&UYIyb(xe-@^T5=l>D*X3O+7TMzupYPE_O>sVw){n z=~|q48azWZbWA39+6Sy`vk~fQ=Tb7IX~JD?yHxT-4=0*cxCj=kD`LQsuoqD48H#tM z*W3{ouHRyOavz@8dtWNe=%Ec-Fye;+lZsxN(N?FHm1eM{h1>jWIo+k^%4+NK%U4_LuRY&#YY+gg`<~9B3 z2%|K$8pVu`3n6rub`lX$>$%D6^R_1vrgtzKFs88^usrIV8^?IeBSs=9m{d-=+Y1_& Hl331N5#cW# literal 0 HcmV?d00001 diff --git a/src/routes/Disclosures.svelte b/src/routes/Disclosures.svelte index 95775be..a9f82e7 100644 --- a/src/routes/Disclosures.svelte +++ b/src/routes/Disclosures.svelte @@ -1,7 +1,9 @@
@@ -9,7 +11,13 @@
DISCLOSURES
{#each disclosures as disclosure} -
+
{ + jwtPayloadSelection = disclosure.digest ? disclosure.digest : ""; + console.log("Hovering ", jwtPayloadSelection); + }} + >

{disclosure.key}

diff --git a/src/routes/Editor.svelte b/src/routes/Editor.svelte index 1b2e753..9554db1 100644 --- a/src/routes/Editor.svelte +++ b/src/routes/Editor.svelte @@ -84,6 +84,7 @@ } $: if (selectText != null) { selectedText ? selectText(selectedText) : undefined; + console.log("setting hover target", selectedText); } onDestroy(() => { From 857f91b22b364144a3804afd654a9cf75e3dfabc Mon Sep 17 00:00:00 2001 From: schlagtim Date: Tue, 13 Feb 2024 22:49:18 +0100 Subject: [PATCH 3/3] Format code --- src/lib/sd-jwt.ts | 32 ++++++++++++++++++-------------- src/routes/+page.svelte | 10 +++++----- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/lib/sd-jwt.ts b/src/lib/sd-jwt.ts index a850f12..df0d236 100644 --- a/src/lib/sd-jwt.ts +++ b/src/lib/sd-jwt.ts @@ -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; -} \ No newline at end of file +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 545d481..de43939 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -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; @@ -46,9 +47,8 @@

- {#await disclosures} - {:then disclosures} - + {#await disclosures then disclosures} + {:catch error}

{error.message}

{/await}