-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sdjwt and mdoc claims to redirect page
- Loading branch information
Showing
7 changed files
with
2,070 additions
and
2,294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type TagValue = { | ||
tag: number, | ||
value: Uint8Array, | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
// https://nuxt.com/docs/guide/concepts/typescript | ||
"extends": "./.nuxt/tsconfig.json" | ||
"extends": "./.nuxt/tsconfig.json", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {type DecodedSDJwt, decodeSdJwt, getClaims} from "@sd-jwt/decode"; | ||
import {digest} from "@sd-jwt/crypto-browser"; | ||
import type {TagValue} from "~/models/TagValue"; | ||
import * as cbor from 'cbor-web'; | ||
import {Buffer} from 'buffer'; | ||
|
||
export async function getSdJwtClaims(vpToken: string): Promise<{ key: string; value: string }[] | undefined> { | ||
try { | ||
const decodedSdJwt: DecodedSDJwt = await decodeSdJwt(vpToken, digest); | ||
return await getClaims( | ||
decodedSdJwt.jwt.payload, | ||
decodedSdJwt.disclosures, | ||
digest, | ||
) | ||
} catch { | ||
throw Error() | ||
} | ||
} | ||
|
||
export async function getMdocClaims(vpToken: string): Promise<{ | ||
[p: string]: { key: string; value: string } | ||
} | undefined> { | ||
try { | ||
|
||
const buf: Buffer = Buffer.from(vpToken, 'base64'); | ||
const valueOut: any = await cbor.decodeFirst(buf, { | ||
preferWeb: true | ||
|
||
}); | ||
// TODO: edit for multiple Presentations | ||
let namespaces = valueOut.nameSpaces; | ||
let firstNamespace = Object.entries(namespaces)[0][0]; | ||
const dataArray: TagValue[] = namespaces[firstNamespace]; | ||
|
||
const requestDataPromises = dataArray.map((item: TagValue) => cborDecode(item.value)); | ||
const requestData = await Promise.all(requestDataPromises); | ||
|
||
const claims: { key: string; value: string }[] = requestData.map((item: { elementIdentifier: string, elementValue: string }) => { | ||
return {key: item.elementIdentifier.replaceAll('_', ' '), value: item.elementValue}; | ||
}); | ||
|
||
return Object.fromEntries( | ||
Object.entries(claims)) as { [key: string]: { key: string; value: string } }; | ||
|
||
} catch { | ||
throw Error() | ||
} | ||
} | ||
|
||
async function cborDecode(buf: Uint8Array): Promise<any> { | ||
return cbor.decodeFirst(buf, { | ||
preferWeb: true | ||
}); | ||
} |