Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Optional] Feat: adds credential expiration #4

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ This project is written in Typescript and uses the [Nuxt framework](https://nuxt
It uses [Bun](https://bun.sh/) as a typescript build and runtime tool.

## How To Run
first you need to create a `.env` file in the root directory of the project.
This file should contain the variables given in the `.env.example` file.

```bash
# To install dependencies
$ bun install
Expand Down
11 changes: 10 additions & 1 deletion components/Issuer/DiplomaCredentialForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
</div>
</div>

<div class="sm:col-span-1">
<label for="dateOfExpiry" class="block text-sm font-medium leading-6 text-gray-900">Date of expiry</label>
<div class="mt-2">
<input type="date" v-model="dateOfExpiry" name="date-of-expiry" id="dateOfExpiry" class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6">
</div>
</div>

<div class="sm:col-span-6 sm:col-start-1">
<label for="body" class="block text-sm font-medium leading-6 text-gray-900">Message</label>
<div class="mt-2">
Expand All @@ -71,7 +78,8 @@ const signee = ref('Ahmed E.');
const documentNumber = ref('A001');
const subject = ref('Mathematics');
const degree = ref('A+');
const dateOfIssue = ref('2013-09-01');
const dateOfIssue = ref('2024-01-01');
const dateOfExpiry = ref('2025-01-01');
const body = ref('Congrats!');

const CreateVCData = async () => {
Expand All @@ -81,6 +89,7 @@ const CreateVCData = async () => {
subject: subject.value,
degree: degree.value,
dateOfIssue: dateOfIssue.value,
dateOfExpiry: dateOfExpiry.value,
body: body.value
};
emit('DiplomaObjectCreated', createdDiploma)
Expand Down
63 changes: 44 additions & 19 deletions composables/IndyAPI.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import axios from "axios";
import {type DiplomaSchema } from "~/composables/VerifiableCredential";


export async function createConnection (isIssuer: boolean): Promise<{ invitationURL: string; connectionID: string}> {
const config = useRuntimeConfig()
let connectorName, connectionDomain, connectionAPIKey: string
if (isIssuer) {
connectorName = 'EPFL';
connectionDomain = process.env.ISSUER_URL;
connectionAPIKey = process.env.ISSUER_API_KEY;
connectionDomain = config.public.issuerURL;
connectionAPIKey = config.public.issuerAPIKey;
} else {
connectorName = 'Leo Inc.';
connectionDomain = process.env.VERIFIER_URL;
connectionDomain = process.env.VERIFIER_API_KEY;
connectionDomain = config.public.verifierURL;
connectionAPIKey = config.public.verifierAPIKey;
}
const {data} = await axios.post(
`${connectionDomain}/connections/create-invitation?auto_accept=true`,
Expand All @@ -27,13 +29,14 @@ export async function createConnection (isIssuer: boolean): Promise<{ invitation
}

export async function checkInvitationIsAccepted (connectionID: string, isIssuer: boolean): Promise<boolean> {
const config = useRuntimeConfig()
let connectionDomain, connectionAPIKey: string
if (isIssuer) {
connectionDomain = process.env.ISSUER_URL;
connectionAPIKey = process.env.ISSUER_API_KEY;
connectionDomain = config.public.issuerURL;
connectionAPIKey = config.public.issuerAPIKey;
} else {
connectionDomain = process.env.VERIFIER_URL;
connectionDomain = process.env.VERIFIER_API_KEY;
connectionDomain = config.public.verifierURL;
connectionAPIKey = config.public.verifierAPIKey;
}
console.log('Checking invitation is accepted...');
const {data} = await axios.get(
Expand All @@ -48,8 +51,9 @@ export async function checkInvitationIsAccepted (connectionID: string, isIssuer:
}

export const GenerateVC = async (connectionID: string, credentialData: DiplomaSchema) => {
const config = useRuntimeConfig()
console.log('Generating Verifiable Credential');
const {data} = await axios.post(`${process.env.ISSUER_URL}/issue-credential/send`, {
const {data} = await axios.post(`${config.public.issuerURL}/issue-credential/send`, {
"connection_id": connectionID,
"credential_proposal": {
"attributes": [
Expand Down Expand Up @@ -82,46 +86,66 @@ export const GenerateVC = async (connectionID: string, credentialData: DiplomaSc
"name": "date_of_issue",
"value": credentialData.dateOfIssue,
"mime-type": "text/plain"
},
{
"name": "date_of_expiry",
"value": String(Date.parse(credentialData.dateOfExpiry)),
"mime-type": "text/plain"
}
],
"@type": "issue-credential/1.0/credential-preview"
},
"auto_remove": "true",
"schema_id": "JEfsRZ6qBhToWbGcJDfe2N:2:EPFL_diploma_supplement:1.0.7"
"schema_id": "JEfsRZ6qBhToWbGcJDfe2N:2:EPFL_diploma_supplement:1.0.8"
},
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': process.env.ISSUER_API_KEY
'X-API-KEY': config.public.issuerAPIKey
}
})
console.log(data);
return
}

export async function sendProofRequest (connectionID: string): Promise<void> {
const config = useRuntimeConfig()
console.log('Sending proof request');
const {data} = await axios.post(
`${process.env.VERIFIER_URL}/present-proof/send-request`,
`${config.public.verifierURL}/present-proof/send-request`,
{
"connection_id": connectionID,
"auto_remove": false,
"auto_verify": true,
"proof_request": {
"name": "Diploma proof request",
"nonce": "1234567890",
"requested_predicates": {},
"requested_predicates": {
predicate_0: {
name: "date_of_expiry",
p_type: ">=",
p_value: Date.now(),
restrictions: [
{
"schema_name": "EPFL_diploma_supplement",
"schema_version": "1.0.8",
"issuer_did": "JEfsRZ6qBhToWbGcJDfe2N"
}
],
},
},
"requested_attributes": {
"info": {
"names": [
"subject",
"degree",
"document_number",
"date_of_issue",
"date_of_expiry",
],
"restrictions": [
{
"schema_name": "EPFL_diploma_supplement",
"schema_version": "1.0.7",
"schema_version": "1.0.8",
"issuer_did": "JEfsRZ6qBhToWbGcJDfe2N"
}
]
Expand All @@ -134,20 +158,21 @@ export async function sendProofRequest (connectionID: string): Promise<void> {
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': process.env.VERIFIER_API_KEY
'X-API-KEY': config.public.verifierAPIKey
}
})
return data
}

export async function checkProofRequestIsAccepted (proofRequestID: string): Promise<boolean> {
export async function checkProofRequestIsAccepted (proofRequestID: string): Promise<{ isAccepted: boolean; data: object}> {
const config = useRuntimeConfig()
console.log('Checking proof request is accepted...');
let {data} = await axios.get(
`${process.env.VERIFIER_URL}/present-proof/records/${proofRequestID}`,
`${config.public.verifierURL}/present-proof/records/${proofRequestID}`,
{
headers: {
'Content-Type': 'application/json',
'X-API-KEY': process.env.VERIFIER_API_KEY
'X-API-KEY': config.public.verifierAPIKey
}
})
let accepted = data.state === 'verified';
Expand Down
2 changes: 1 addition & 1 deletion composables/VerifiableCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ export interface DiplomaSchema {
documentNumber: string;
body: string;
dateOfIssue: string;

dateOfExpiry: string;
}
8 changes: 8 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
import {resolve} from "path";

export default defineNuxtConfig({
runtimeConfig: {
public: {
issuerURL: process.env.ISSUER_URL,
issuerAPIKey: process.env.ISSUER_API_KEY,
verifierURL: process.env.VERIFIER_URL,
verifierAPIKey: process.env.VERIFIER_API_KEY,
}
},
devtools: { enabled: true },
modules: [
'@nuxtjs/tailwindcss'
Expand Down
1 change: 1 addition & 0 deletions pages/issue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<p>Subject: {{ CredentialData.subject }}</p>
<p>Degree: {{ CredentialData.degree }}</p>
<p>Date of issue: {{ CredentialData.dateOfIssue }}</p>
<p>Date of expiry: {{ CredentialData.dateOfExpiry }}</p>
<p>Message: {{ CredentialData.body }}</p>
<br>
</div>
Expand Down