-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working version of ticket proof requests (#8)
- Loading branch information
Showing
41 changed files
with
1,407 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import type { PodspecProofRequest } from "@parcnet-js/podspec"; | ||
import { TicketSpec, ticketProofRequest } from "@parcnet-js/ticket-spec"; | ||
import type { POD } from "@pcd/pod"; | ||
import JSONBig from "json-bigint"; | ||
import type { ReactNode } from "react"; | ||
import { useState } from "react"; | ||
import { useEffect, useState } from "react"; | ||
import type { ProveResult } from "../../../../packages/client-rpc/src"; | ||
import { TryIt } from "../components/TryIt"; | ||
import { useParcnetClient } from "../hooks/useParcnetClient"; | ||
|
||
const EVENT_ID = "fca101d3-8c9d-56e4-9a25-6a3c1abf0fed"; | ||
const PRODUCT_ID = "59c3df09-2093-4b54-9033-7bf54b6f75db"; | ||
|
||
const request: PodspecProofRequest = { | ||
pods: { | ||
pod1: { | ||
|
@@ -53,6 +58,20 @@ export function GPC(): ReactNode { | |
const { z, connected } = useParcnetClient(); | ||
const [proveResult, setProveResult] = useState<ProveResult>(); | ||
const [verified, setVerified] = useState<boolean | undefined>(); | ||
const [identityV3, setIdentityV3] = useState<bigint | undefined>(); | ||
const [publicKey, setPublicKey] = useState<string | undefined>(); | ||
const [ticket, setTicket] = useState<POD | undefined>(); | ||
|
||
useEffect(() => { | ||
void (async () => { | ||
if (connected) { | ||
const identityV3 = await z.identity.getSemaphoreV3Commitment(); | ||
setIdentityV3(identityV3); | ||
const publicKey = await z.identity.getPublicKey(); | ||
setPublicKey(publicKey); | ||
} | ||
})(); | ||
}, [connected, z.identity]); | ||
|
||
return !connected ? null : ( | ||
<div> | ||
|
@@ -166,6 +185,125 @@ const verified = await z.gpc.verify(proof, config, revealedClaims, request); | |
</pre> | ||
)} | ||
</div> | ||
|
||
<div> | ||
<p> | ||
We're about to look at ticket ownership proofs. However, you might | ||
not have a ticket yet! Fortunately, tickets are just PODs, so you | ||
can generate a self-signed ticket like this: | ||
<code className="block text-xs font-base rounded-md p-2 whitespace-pre-wrap"> | ||
{` | ||
const ticketData = { | ||
ticketId: "302bdf00-60d9-4b0c-a07b-a6ef64d27a71", | ||
eventId: "${EVENT_ID}", | ||
productId: "${PRODUCT_ID}", | ||
ticketName: "Ticket 1", | ||
eventName: "Event 1", | ||
ticketSecret: "secret123", | ||
timestampConsumed: 1714857600, | ||
timestampSigned: 1714857600, | ||
attendeeSemaphoreId: ${identityV3}, | ||
owner: "${publicKey}", | ||
isConsumed: 0, | ||
isRevoked: 0, | ||
ticketCategory: 0, | ||
attendeeName: "John Doe", | ||
attendeeEmail: "[email protected]" | ||
}; | ||
const entries = TicketSpec.parseEntries(ticketData, { coerce: true }); | ||
const pod = await z.pod.sign(entries); | ||
await z.pod.insert(pod); | ||
`} | ||
</code> | ||
</p> | ||
<TryIt | ||
onClick={async () => { | ||
const ticketData = { | ||
ticketId: "302bdf00-60d9-4b0c-a07b-a6ef64d27a71", | ||
eventId: EVENT_ID, | ||
productId: PRODUCT_ID, | ||
ticketName: "Ticket 1", | ||
eventName: "Event 1", | ||
ticketSecret: "secret123", | ||
timestampConsumed: 1714857600, | ||
timestampSigned: 1714857600, | ||
attendeeSemaphoreId: identityV3!, | ||
owner: publicKey!, | ||
isConsumed: 0, | ||
isRevoked: 0, | ||
ticketCategory: 0, | ||
attendeeName: "John Doe", | ||
attendeeEmail: "[email protected]" | ||
}; | ||
|
||
const entries = TicketSpec.parseEntries(ticketData, { | ||
coerce: true | ||
}); | ||
|
||
const pod = await z.pod.sign(entries); | ||
await z.pod.insert(pod); | ||
setTicket(pod); | ||
}} | ||
label="Generate Ticket" | ||
/> | ||
{ticket && ( | ||
<div> | ||
Ticket signed successfully! The signature is{" "} | ||
<code className="block text-xs font-base rounded-md p-2 whitespace-pre"> | ||
{ticket?.signature} | ||
</code> | ||
</div> | ||
)} | ||
</div> | ||
|
||
<div> | ||
<p> | ||
Generating a ticket ownership proof is done like this: | ||
<code className="block text-xs font-base rounded-md p-2 whitespace-pre-wrap"> | ||
{` | ||
const request = ticketProofRequest({ | ||
attributes: [ | ||
[ | ||
// The public key to match | ||
"${publicKey}", | ||
// The event ID to match | ||
"${EVENT_ID}" | ||
] | ||
], | ||
fieldsToReveal: { | ||
eventId: true | ||
} | ||
}); | ||
const gpcProof = await z.gpc.prove(request); | ||
`} | ||
</code> | ||
</p> | ||
<TryIt | ||
onClick={async () => { | ||
try { | ||
const hmm = ticketProofRequest({ | ||
attributes: [[publicKey!, EVENT_ID]], | ||
fieldsToReveal: { | ||
eventId: true | ||
} | ||
}); | ||
console.log(hmm.schema); | ||
setProveResult(await z.gpc.prove(hmm.schema)); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}} | ||
label="Get GPC Proof" | ||
/> | ||
{proveResult && ( | ||
<pre className="whitespace-pre-wrap"> | ||
{JSONBig.stringify(proveResult, null, 2)} | ||
</pre> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.