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

Working version of ticket proof requests #8

Merged
merged 3 commits into from
Sep 19, 2024
Merged
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
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
7 changes: 4 additions & 3 deletions apps/client-web/src/client/query_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import type { EntriesSchema, PODSchema, PodSpec } from "@parcnet-js/podspec";
import { EventEmitter } from "eventemitter3";
import type { PODCollection } from "./pod_collection.js";

interface Subscription {
query: PodSpec<EntriesSchema>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
interface Subscription<E extends EntriesSchema = any> {
query: PodSpec<E>;
serial: number;
}

Expand Down Expand Up @@ -63,7 +64,7 @@ export class QuerySubscriptions {
): Promise<string> {
const subscriptionId = (this.nextSubscriptionId++).toString();
this.subscriptions.set(subscriptionId, {
query: p.pod(query) as PodSpec<EntriesSchema>,
query: p.pod(query),
serial: 0
});

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/[email protected]
- @parcnet-js/[email protected]
- @parcnet-js/[email protected]

## 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-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: {
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
Loading
Loading