From 7b67ff758c1ede1a5fd1b5ecfece606d06809ba0 Mon Sep 17 00:00:00 2001 From: Cristopher Aguilar <127804511+CristopherAguilar10@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:12:58 -0600 Subject: [PATCH 1/6] Update sbt.tsx - Add a test in sbt.tsx to verify correct functionality of formatAsVC." --- app/src/apps/sbt.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/apps/sbt.tsx b/app/src/apps/sbt.tsx index cd452c1f..acde82b1 100644 --- a/app/src/apps/sbt.tsx +++ b/app/src/apps/sbt.tsx @@ -150,6 +150,17 @@ export const sbtApp: AppType = { console.log('inputs:', inputs); + // Definition of the credentialSubject object with the data required for the verifiable credential + const credentialSubject= { + passportData, + attestionId: PASSPORT_ATTESTATION_ID, + disclosure, + address, + majority + }; + const vc = formatAsVC(credentialSubject); + console.log('Verifiable Credential:', vc); + const start = Date.now(); const proof = await generateProof( @@ -163,6 +174,7 @@ export const sbtApp: AppType = { update({ proof: proof, proofTime: end - start, + vc: vc }); setStep(Steps.PROOF_GENERATED); } catch (error: any) { @@ -274,4 +286,4 @@ export const sbtApp: AppType = { } } -export default sbtApp; \ No newline at end of file +export default sbtApp; From 9ebbe32b2f6219c1112fa079ddae2f2f66b5f12b Mon Sep 17 00:00:00 2001 From: Cristopher Aguilar <127804511+CristopherAguilar10@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:17:58 -0600 Subject: [PATCH 2/6] Create formatVc Add the formatAsVC function to common/src/utils/formatVC.ts to format verifiable credential data. --- common/src/utils/formatVc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 common/src/utils/formatVc diff --git a/common/src/utils/formatVc b/common/src/utils/formatVc new file mode 100644 index 00000000..e56d8d13 --- /dev/null +++ b/common/src/utils/formatVc @@ -0,0 +1,23 @@ +!Import the v4 function from the uuid package to generate unique identifiers +import {v4 as uuidv4} from 'uuid'; +!Exports the formatAsVC function that takes a credentialSubject object as a parameter +export function formatAsVC(credentialSubject: object){ +!Returns an object representing a Verifiable Credential (VC) conforming to the W3C standard + return { +!@context specifies the JSON-LD context used for the credential + "@context": [ + "https://www.w3.org/2018/credentials/v1" + ], + + "type":["VerifiableCredential"], + "id": `urn:uuid:${uuidv4()}`, + "issuer": "https://issuer.example.com", + "issuanceDate": new Date().toISOString(), + "creendtialSubject": credentialSubject + }; +} +!type defines the type of credential, in this case it is a "VerifiableCredential" +!id assigns a unique identifier to the credential using a v4 UUID +!issuer specifies the issuer of the credential, here is an example URL +!issuanceDate indicates the date and time of issuance of the credential in ISO 8601 format +!credentialSubject contains the specific information about the credential subject From 12695f9af168ac775d049dff7642dfa1c688a5e4 Mon Sep 17 00:00:00 2001 From: Cristopher Aguilar <127804511+CristopherAguilar10@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:19:03 -0600 Subject: [PATCH 3/6] Update and rename formatVc to formatVc.ts Add the formatAsVC function to common/src/utils/formatVC.ts to format verifiable credential data. --- common/src/utils/formatVc | 23 ----------------------- common/src/utils/formatVc.ts | 23 +++++++++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 common/src/utils/formatVc create mode 100644 common/src/utils/formatVc.ts diff --git a/common/src/utils/formatVc b/common/src/utils/formatVc deleted file mode 100644 index e56d8d13..00000000 --- a/common/src/utils/formatVc +++ /dev/null @@ -1,23 +0,0 @@ -!Import the v4 function from the uuid package to generate unique identifiers -import {v4 as uuidv4} from 'uuid'; -!Exports the formatAsVC function that takes a credentialSubject object as a parameter -export function formatAsVC(credentialSubject: object){ -!Returns an object representing a Verifiable Credential (VC) conforming to the W3C standard - return { -!@context specifies the JSON-LD context used for the credential - "@context": [ - "https://www.w3.org/2018/credentials/v1" - ], - - "type":["VerifiableCredential"], - "id": `urn:uuid:${uuidv4()}`, - "issuer": "https://issuer.example.com", - "issuanceDate": new Date().toISOString(), - "creendtialSubject": credentialSubject - }; -} -!type defines the type of credential, in this case it is a "VerifiableCredential" -!id assigns a unique identifier to the credential using a v4 UUID -!issuer specifies the issuer of the credential, here is an example URL -!issuanceDate indicates the date and time of issuance of the credential in ISO 8601 format -!credentialSubject contains the specific information about the credential subject diff --git a/common/src/utils/formatVc.ts b/common/src/utils/formatVc.ts new file mode 100644 index 00000000..a9d2c9a3 --- /dev/null +++ b/common/src/utils/formatVc.ts @@ -0,0 +1,23 @@ +//Import the v4 function from the uuid package to generate unique identifiers +import {v4 as uuidv4} from 'uuid'; +//Exports the formatAsVC function that takes a credentialSubject object as a parameter +export function formatAsVC(credentialSubject: object){ +//Returns an object representing a Verifiable Credential (VC) conforming to the W3C standard + return { +//@context specifies the JSON-LD context used for the credential + "@context": [ + "https://www.w3.org/2018/credentials/v1" + ], + + "type":["VerifiableCredential"], + "id": `urn:uuid:${uuidv4()}`, + "issuer": "https://issuer.example.com", + "issuanceDate": new Date().toISOString(), + "creendtialSubject": credentialSubject + }; +} +//type defines the type of credential, in this case it is a "VerifiableCredential" +//id assigns a unique identifier to the credential using a v4 UUID +//issuer specifies the issuer of the credential, here is an example URL +//issuanceDate indicates the date and time of issuance of the credential in ISO 8601 format +//credentialSubject contains the specific information about the credential subject From dbf83811a398c3f8f4c78a41fb6052151dc05859 Mon Sep 17 00:00:00 2001 From: Cristopher Aguilar <127804511+CristopherAguilar10@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:34:15 -0600 Subject: [PATCH 4/6] Update userStore.ts Add generateAttestation function to format credential as Verifiable Credential - Add `generateAttestation` function to `useUserStore` which formats passport data and attestation ID as a Verifiable Credential using `formatAsVC`. - Include import of `formatAsVC` from `../../../common/src/utils/formatVC`. - Update `UserState` store with the new function for better credential handling and formatting. --- app/src/stores/userStore.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/stores/userStore.ts b/app/src/stores/userStore.ts index d3dcd162..451adff5 100644 --- a/app/src/stores/userStore.ts +++ b/app/src/stores/userStore.ts @@ -19,6 +19,7 @@ import { sendRegisterTransaction } from '../utils/transactions'; import { loadPassportData, loadSecret, loadSecretOrCreateIt, storePassportData } from '../utils/keychain'; import { ethers } from 'ethers'; import { isCommitmentRegistered } from '../utils/registration'; +import { formatAsVC } from '../../../common/src/utils/formatVC'; interface UserState { passportNumber: string @@ -203,5 +204,10 @@ const useUserStore = create((set, get) => ({ dateOfExpiry: "", }), })) +// Function to generate an attestation formatted as a verifiable credential +const generateAttestation = (passportData) => { + const credentialSubject = { passportData, attestationId: PASSPORT_ATTESTATION_ID }; + return formatAsVC(credentialSubject); +}; -export default useUserStore \ No newline at end of file +export default useUserStore From 22cd68216b213ee4d1d370ff6eea3901636804a7 Mon Sep 17 00:00:00 2001 From: Cristopher Aguilar <127804511+CristopherAguilar10@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:42:28 -0600 Subject: [PATCH 5/6] Update registration.ts - Added `registerUser` function to create and log a Verifiable Credential. - Function uses `formatAsVC` to format `passportData` and `PASSPORT_ATTESTATION_ID` into a credentialSubject. --- app/src/utils/registration.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/utils/registration.ts b/app/src/utils/registration.ts index 1ab82331..5f14f000 100644 --- a/app/src/utils/registration.ts +++ b/app/src/utils/registration.ts @@ -6,6 +6,7 @@ import { PassportData } from "../../../common/src/utils/types"; import { getLeaf } from "../../../common/src/utils/pubkeyTree"; import { formatMrz, packBytes } from "../../../common/src/utils/utils"; import { findIndexInTree } from "../../../common/src/utils/generateInputs"; +import { formatAsVC } from '../../../common/src/utils/formatVC'; export async function isCommitmentRegistered(secret: string, passportData: PassportData) { const response = await axios.get(COMMITMENT_TREE_TRACKER_URL) @@ -43,4 +44,14 @@ export async function isCommitmentRegistered(secret: string, passportData: Passp } catch(err) { return false; } -} \ No newline at end of file +} + +// New function to register the user and generate a verifiable credential +export const registerUser = (passportData: PassportData) => { + const credentialSubject = { + passportData, + attestationId: PASSPORT_ATTESTATION_ID + }; + const vc = formatAsVC(credentialSubject); + console.log(vc); +}; From 8917e08e5bb7ef8a28e580416cf3cc91b3c62de7 Mon Sep 17 00:00:00 2001 From: Cristopher Aguilar <127804511+CristopherAguilar10@users.noreply.github.com> Date: Sun, 28 Jul 2024 22:47:08 -0600 Subject: [PATCH 6/6] Update generateInputs.ts - Added `generateInputs` function to create and log a Verifiable Credential. - Function uses `formatAsVC` to format `passportData` and `PASSPORT_ATTESTATION_ID` into a credentialSubject. --- common/src/utils/generateInputs.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/common/src/utils/generateInputs.ts b/common/src/utils/generateInputs.ts index 9c01a436..d35e15cd 100644 --- a/common/src/utils/generateInputs.ts +++ b/common/src/utils/generateInputs.ts @@ -16,6 +16,7 @@ import { packBytes } from "../utils/utils"; import { mockPassportDatas, } from "./mockPassportData"; +import { formatAsVC } from './formatVC'; export function generateCircuitInputsRegister( secret: string, @@ -175,4 +176,12 @@ export function findIndexInTree(tree: LeanIMT, commitment: bigint): number { console.log(`Index of commitment in the registry: ${index}`); } return index; -} \ No newline at end of file +} +export const generateInputs = (passportData: PassportData) => { + const credentialSubject = { + passportData, + attestationId: PASSPORT_ATTESTATION_ID + }; + const vc = formatAsVC(credentialSubject); + console.log(vc); +};