diff --git a/apps/passport-client/components/screens/HomeScreen/utils.ts b/apps/passport-client/components/screens/HomeScreen/utils.ts index 42ca0e4dd8..a7dcff3763 100644 --- a/apps/passport-client/components/screens/HomeScreen/utils.ts +++ b/apps/passport-client/components/screens/HomeScreen/utils.ts @@ -1,3 +1,9 @@ +import { newEdDSAPrivateKey } from "@pcd/eddsa-pcd"; +import { EdDSATicketPCDPackage, TicketCategory } from "@pcd/eddsa-ticket-pcd"; +import { ArgumentTypeName } from "@pcd/pcd-types"; +import { randomUUID } from "@pcd/util"; +import { AppState } from "../../../src/state"; + export interface EventInfo { start: string; end: string; @@ -32,9 +38,79 @@ export const EVENTS: Record = { end: "2023-11-21", image: "https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Denver_Skyline_in_Winter.JPG/800px-Denver_Skyline_in_Winter.JPG" + }, + Devcon: { + start: "2024-11-12", + end: "2024-11-15", + image: + "https://devcon.org/_next/image/?url=/_next/static/media/backdrop.f0972b01.png&w=3840&q=75" + }, + "Devcon/ProgCrypto": { + start: "2024-11-12", + end: "2024-11-12", + image: + "https://online.york.ac.uk/wp-content/uploads/2023/10/Cryptography.jpg" } }; export function isEvent(folder: string): folder is keyof typeof EVENTS { return EVENTS[folder] !== undefined; } + +export async function initTestData(state: AppState): Promise { + if (!state.self) { + return; + } + + const testData = { + tickets: ["Devcon", "Devcon", "Devcon/ProgCrypto", "Devcon/ProgCrypto"] + } as const; + + const pcds = state.pcds; + if (state.pcds.folders["Devcon"]) { + return; + } + + const pkey = newEdDSAPrivateKey(); + + for (const [i, ticket] of testData.tickets.entries()) { + const eventName = ticket; + const ticketName = "GA"; + const ticketId = randomUUID(); + const eventId = randomUUID(); + const productId = randomUUID(); + + const pcd = await EdDSATicketPCDPackage.prove({ + id: { + argumentType: ArgumentTypeName.String, + value: ticketId + }, + privateKey: { + argumentType: ArgumentTypeName.String, + value: pkey + }, + ticket: { + argumentType: ArgumentTypeName.Object, + value: { + eventName: eventName, + ticketName: ticketName, + checkerEmail: undefined, + eventId, + productId, + ticketId, + timestampConsumed: 0, + timestampSigned: Date.now(), + attendeeSemaphoreId: state.identity.commitment.toString(), + isConsumed: false, + isRevoked: false, + ticketCategory: TicketCategory.Generic, + attendeeName: "", + attendeeEmail: state.self?.email ?? "test@test.com" + } + } + }); + + pcds.add(pcd, { upsert: true }); + pcds.setFolder(pcd.id, ticket); + } +} diff --git a/apps/passport-client/src/loadInitialState.ts b/apps/passport-client/src/loadInitialState.ts index aa940a25d0..fea1ecc9ff 100644 --- a/apps/passport-client/src/loadInitialState.ts +++ b/apps/passport-client/src/loadInitialState.ts @@ -1,5 +1,6 @@ import { createStorageBackedCredentialCache } from "@pcd/passport-interface"; import { Identity } from "@semaphore-protocol/identity"; +import { initTestData } from "../components/screens/HomeScreen/utils"; import { loadCheckedInOfflineDevconnectTickets, loadEncryptionKey, @@ -70,5 +71,7 @@ export async function loadInitialState(): Promise { state.modal = { modalType: "invalid-participant" }; } + await initTestData(state); + return state; }