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

Verifiable Credentials Data Model v2.0 integration into Proof of Passport #160

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion app/src/apps/sbt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -163,6 +174,7 @@ export const sbtApp: AppType = {
update({
proof: proof,
proofTime: end - start,
vc: vc
});
setStep(Steps.PROOF_GENERATED);
} catch (error: any) {
Expand Down Expand Up @@ -274,4 +286,4 @@ export const sbtApp: AppType = {
}
}

export default sbtApp;
export default sbtApp;
8 changes: 7 additions & 1 deletion app/src/stores/userStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -203,5 +204,10 @@ const useUserStore = create<UserState>((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
export default useUserStore
13 changes: 12 additions & 1 deletion app/src/utils/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -43,4 +44,14 @@ export async function isCommitmentRegistered(secret: string, passportData: Passp
} catch(err) {
return false;
}
}
}

// 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);
};
23 changes: 23 additions & 0 deletions common/src/utils/formatVc.ts
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion common/src/utils/generateInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { packBytes } from "../utils/utils";
import {
mockPassportDatas,
} from "./mockPassportData";
import { formatAsVC } from './formatVC';

export function generateCircuitInputsRegister(
secret: string,
Expand Down Expand Up @@ -175,4 +176,12 @@ export function findIndexInTree(tree: LeanIMT, commitment: bigint): number {
console.log(`Index of commitment in the registry: ${index}`);
}
return index;
}
}
export const generateInputs = (passportData: PassportData) => {
const credentialSubject = {
passportData,
attestationId: PASSPORT_ATTESTATION_ID
};
const vc = formatAsVC(credentialSubject);
console.log(vc);
};