Skip to content

Commit

Permalink
Working version of ticket proof requests
Browse files Browse the repository at this point in the history
  • Loading branch information
robknight committed Sep 19, 2024
1 parent 5b520cc commit 9a94d7d
Show file tree
Hide file tree
Showing 40 changed files with 1,404 additions and 151 deletions.
10 changes: 10 additions & 0 deletions apps/client-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# client-web

## 0.0.5

### Patch Changes

- Updated dependencies
- Updated dependencies
- @parcnet-js/podspec@0.0.3
- @parcnet-js/client-rpc@0.0.4
- @parcnet-js/client-helpers@0.0.5

## 0.0.4

### Patch Changes
Expand Down
5 changes: 3 additions & 2 deletions apps/client-web/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "client-web",
"private": true,
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -16,7 +16,8 @@
"@pcd/gpc": "0.0.8",
"@pcd/pod": "0.1.7",
"@pcd/proto-pod-gpc-artifacts": "^0.9.0",
"@semaphore-protocol/identity": "^4.0.3",
"@semaphore-protocol/core": "^4.0.3",
"@semaphore-protocol/identity": "3.15.2",
"eventemitter3": "^5.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
12 changes: 10 additions & 2 deletions apps/client-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ function ProvePODInfo({
{pods.map((pod) => {
return (
<option key={pod.signature} value={pod.signature}>
{pod.signature.substring(0, 16)}
{schema.pod.meta?.labelEntry
? pod.content
.asEntries()
[schema.pod.meta.labelEntry].value.toString()
: pod.signature.substring(0, 16)}
</option>
);
})}
Expand Down Expand Up @@ -296,7 +300,11 @@ function Prove({
{
pods: proveOperation.selectedPods as Record<string, POD>,
membershipLists: prs.membershipLists,
watermark: prs.watermark
watermark: prs.watermark,
owner: {
semaphoreV4: getIdentity(),
externalNullifier: prs.externalNullifier
}
},
new URL("/artifacts", window.location.origin).toString()
)
Expand Down
2 changes: 1 addition & 1 deletion apps/client-web/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
ParcnetPODRPC,
ParcnetRPC
} from "@parcnet-js/client-rpc";
import type { Identity } from "@semaphore-protocol/identity";
import type { Identity } from "@semaphore-protocol/core";
import type { Dispatch } from "react";
import type { ClientAction } from "../state.js";
import { ParcnetGPCProcessor } from "./gpc.js";
Expand Down
3 changes: 3 additions & 0 deletions apps/client-web/src/client/gpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export class ParcnetGPCProcessor implements ParcnetGPCRPC {
public async prove(request: PodspecProofRequest): Promise<ProveResult> {
const prs = proofRequest(request);

console.dir(prs, { depth: null });
console.dir(this.pods.getAll(), { depth: null });

const inputPods = prs.queryForInputs(this.pods.getAll());
if (
Object.values(inputPods).some((candidates) => candidates.length === 0)
Expand Down
2 changes: 1 addition & 1 deletion apps/client-web/src/client/identity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ParcnetIdentityRPC } from "@parcnet-js/client-rpc";
import { encodePublicKey } from "@pcd/pod";
import type { Identity } from "@semaphore-protocol/identity";
import type { Identity } from "@semaphore-protocol/core";

export class ParcnetIdentityProcessor implements ParcnetIdentityRPC {
public constructor(private readonly v4Identity: Identity) {}
Expand Down
2 changes: 1 addition & 1 deletion apps/client-web/src/client/pod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PODQuery, ParcnetPODRPC } from "@parcnet-js/client-rpc";
import type { PODEntries } from "@pcd/pod";
import { POD, encodePrivateKey } from "@pcd/pod";
import type { Identity } from "@semaphore-protocol/identity";
import type { Identity } from "@semaphore-protocol/core";
import type { PODCollection } from "./pod_collection.js";
import type { QuerySubscriptions } from "./query_subscriptions.js";

Expand Down
2 changes: 1 addition & 1 deletion apps/client-web/src/client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { POD } from "@pcd/pod";
import { Identity } from "@semaphore-protocol/identity";
import { Identity } from "@semaphore-protocol/core";

export function loadPODsFromStorage(): POD[] {
let pods: POD[] = [];
Expand Down
4 changes: 2 additions & 2 deletions apps/client-web/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ConnectorAdvice } from "@parcnet-js/client-helpers";
import type { ProveResult, Zapp } from "@parcnet-js/client-rpc";
import type { PodspecProofRequest } from "@parcnet-js/podspec";
import type { POD } from "@pcd/pod";
import type { Identity } from "@semaphore-protocol/identity";
import type { Identity as IdentityV4 } from "@semaphore-protocol/core";

export type ClientState = {
loggedIn: boolean;
Expand All @@ -18,7 +18,7 @@ export type ClientState = {
resolve?: (result: ProveResult) => void;
}
| undefined;
identity: Identity;
identity: IdentityV4;
};

export type ClientAction =
Expand Down
9 changes: 9 additions & 0 deletions examples/test-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# test-app

## 1.0.4

### Patch Changes

- Updated dependencies
- @parcnet-js/podspec@0.0.3
- @parcnet-js/app-connector@0.0.4
- @parcnet-js/ticket-spec@0.0.1

## 1.0.3

### Patch Changes
Expand Down
4 changes: 3 additions & 1 deletion examples/test-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-app",
"version": "1.0.3",
"version": "1.0.4",
"private": true,
"type": "module",
"scripts": {
Expand All @@ -12,8 +12,10 @@
"dependencies": {
"@parcnet-js/app-connector": "workspace:*",
"@parcnet-js/podspec": "workspace:*",
"@parcnet-js/ticket-spec": "workspace:*",
"@pcd/pod": "0.1.7",
"json-bigint": "^1.0.0",
"@semaphore-protocol/identity": "^3.15.2",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
140 changes: 139 additions & 1 deletion examples/test-app/src/apis/GPC.tsx
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-utils";
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: {
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
);
Expand Down
9 changes: 9 additions & 0 deletions packages/app-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @parcnet-js/app-connector

## 0.0.4

### Patch Changes

- Updated dependencies
- Updated dependencies
- @parcnet-js/podspec@0.0.3
- @parcnet-js/client-rpc@0.0.4

## 0.0.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/app-connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parcnet-js/app-connector",
"version": "0.0.3",
"version": "0.0.4",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.cjs",
Expand Down
7 changes: 7 additions & 0 deletions packages/client-helpers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @parcnet-js/client-helpers

## 0.0.5

### Patch Changes

- Updated dependencies
- @parcnet-js/client-rpc@0.0.4

## 0.0.4

### Patch Changes
Expand Down
9 changes: 2 additions & 7 deletions packages/client-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parcnet-js/client-helpers",
"version": "0.0.4",
"version": "0.0.5",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.js",
Expand All @@ -26,16 +26,11 @@
"files": ["dist", "LICENSE"],
"dependencies": {
"@parcnet-js/client-rpc": "workspace:*",
"json-bigint": "^1.0.0",
"valibot": "^0.42.0",
"ws": "^8.18.0"
"valibot": "^0.42.0"
},
"devDependencies": {
"@parcnet-js/eslint-config": "workspace:*",
"@parcnet-js/typescript-config": "workspace:*",
"@types/json-bigint": "^1.0.1",
"@types/node": "^20.11.24",
"@types/ws": "^8.5.12",
"tsup": "^8.2.4",
"typescript": "^5.5"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/client-rpc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @parcnet-js/client-rpc

## 0.0.4

### Patch Changes

- Support metadata on PodSpec schemas
- Updated dependencies
- @parcnet-js/podspec@0.0.3

## 0.0.3

### Patch Changes
Expand Down
Loading

0 comments on commit 9a94d7d

Please sign in to comment.