Skip to content

Commit

Permalink
feat: Add manifest for BankId credentials and update API endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dinkar-jain committed May 13, 2024
1 parent 81f2051 commit 978e116
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/content/1.credentials/BankId.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@
}
```

## Manifest

```json
{
"claims": {
"Name": "$.credentialSubject.givenName",
"Last Name": "$.credentialSubject.familyName",
"Date of Birth": "$.credentialSubject.birthDate",
"Account ID": "$.credentialSubject.accountId",
"IBAN": "$.credentialSubject.IBAN",
"BIC": "$.credentialSubject.BIC"
}
}
```

## Mapping example

```json
Expand Down
94 changes: 94 additions & 0 deletions src/content/1.credentials/KycCredential.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# KycDataCredential

```json
{
"@context": [
"https://www.w3.org/2018/credentials/v1"
],
"type": [
"VerifiableCredential",
"KycCredential"
],
"id": "urn:uuid:fd0e0f93-5011-4fa2-9020-fa7da57df947",
"credentialSubject": {
"id": "did:key:z6MkgjsyqQUvtW4wPWKkqffiygdCDathYK1vvpSkxC7qCmqr#z6MkgjsyqQUvtW4wPWKkqffiygdCDathYK1vvpSkxC7qCmqr",
"givenName": "HASSAN MOUSA MOHAMMAD ABUHELWEH",
"surname": "ABUHELWEH",
"verifiedEmail": "[email protected]",
"verifiedPhone": "+971557032203",
"documentNumber": "R301855",
"personalNumber": "R301855",
"birthDate": "1984-10-06",
"expiryDate": "2027-11-15",
"documentType": "P",
"issuingState": "JOR",
"nationality": "Jordan",
"sex": "M",
"faceMatch": 0.8,
"faceLiveness": "Genuine",
"authenticityLiveness": "Genuine",
"documents": [
{
"name": "Face",
"url": ""
},
{
"name": "document_front",
"url": ""
},
{
"name": "document_back",
"url": ""
}
]
},
"issuer": {
"id": "did:key:z6MkjoRhq1jSNJdLiruSXrFFxagqrztZaXHqHGUTKJbcNywp",
"name": "KYC Provider"
},
"issuanceDate": "2024-05-13T08:29:25.744750031Z",
"validFrom": "2024-05-13T08:29:25.744775222Z",
"expirationDate": "2025-05-13T08:29:25.744794971Z"
}
```

## Manifest

```json
{
"claims": {
"Name": "$.credentialSubject.givenName",
"Surname": "$.credentialSubject.surname",
"Email": "$.credentialSubject.verifiedEmail",
"Phone": "$.credentialSubject.verifiedPhone",
"Document Number": "$.credentialSubject.documentNumber",
"Personal Number": "$.credentialSubject.personalNumber",
"Birth Date": "$.credentialSubject.birthDate",
"Expiry Date": "$.credentialSubject.expiryDate",
"Document Type": "$.credentialSubject.documentType",
"Issuing State": "$.credentialSubject.issuingState",
"Nationality": "$.credentialSubject.nationality",
"Sex": "$.credentialSubject.sex",
"Face Match": "$.credentialSubject.faceMatch",
"Face Liveness": "$.credentialSubject.faceLiveness",
"Authenticity Liveness": "$.credentialSubject.authenticityLiveness"
}
}
```

## Mapping example

```json
{
"id": "<uuid>",
"credentialSubject": {
"id": "<subjectDid>"
},
"issuer": {
"id": "<issuerDid>"
},
"issuanceDate": "<timestamp>",
"validFrom": "<timestamp>",
"expirationDate": "<timestamp-in:365d>"
}
```
4 changes: 4 additions & 0 deletions src/content/2.api/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ GET /api/list
GET /api/vc/OpenBadgeCredential
```

```http
GET /api/manifest/OpenBadgeCredential
```

```http
GET /api/mapping/OpenBadgeCredential
```
58 changes: 58 additions & 0 deletions src/server/api/manifest/[name].get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { serverQueryContent } from "#content/server";

export default defineEventHandler(async (event) => {
const name = getRouterParam(event, "name");
if (name === undefined) {
setResponseStatus(event, 400);
return "error: No name set!";
}

const contentQuery = await serverQueryContent(event).find();

const matchedContent = contentQuery.find((content) => {
return content._path?.startsWith("/credentials/") && content.title === name;
});

if (matchedContent === undefined) {
const n = contentQuery
.filter((content) => {
return content.navigation === undefined;
})
.map((content) => {
return content.title;
});

setResponseStatus(event, 400);
return `error: No credential found named: \"${name}\". Available credentials: ${n.join(", ")}`;
}

const codeblocksAndTitles = matchedContent.body?.children.filter((elem) => {
return (elem.tag === "pre" && elem.props?.language === "json") || elem.tag === "h2";
});

if (!codeblocksAndTitles) {
setResponseStatus(event, 400);
return "error: no-credential";
}

let manifestInTitle = false;
for (const codeblockOrTitle of codeblocksAndTitles) {
if (
codeblockOrTitle.tag === "h2" &&
codeblockOrTitle?.children
?.find((c) => c.type === "text")
?.value?.toLowerCase()
?.includes("manifest") === true
) {
manifestInTitle = true;
continue;
}

if (manifestInTitle && codeblockOrTitle.tag === "pre" && codeblockOrTitle.props?.language === "json") {
return JSON.parse(codeblockOrTitle.props.code);
}
}

setResponseStatus(event, 400);
return "error: no-mapping";
});

0 comments on commit 978e116

Please sign in to comment.