Skip to content

Commit

Permalink
Include circuit identifier when making GPC proof (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
robknight authored Oct 22, 2024
1 parent 52b25c0 commit ef72370
Show file tree
Hide file tree
Showing 22 changed files with 234 additions and 47 deletions.
9 changes: 9 additions & 0 deletions apps/client-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# client-web

## 0.0.12

### Patch Changes

- Updated dependencies [c02d469]
- @parcnet-js/client-rpc@1.1.2
- @parcnet-js/podspec@1.1.1
- @parcnet-js/client-helpers@1.0.3

## 0.0.11

### Patch Changes
Expand Down
8 changes: 4 additions & 4 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.11",
"version": "0.0.12",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -13,11 +13,11 @@
"@parcnet-js/client-helpers": "workspace:*",
"@parcnet-js/client-rpc": "workspace:*",
"@parcnet-js/podspec": "workspace:*",
"@pcd/gpc": "0.2.0",
"@pcd/pod": "0.3.0",
"@pcd/gpc": "^0.2.0",
"@pcd/pod": "^0.3.0",
"@pcd/proto-pod-gpc-artifacts": "^0.9.0",
"@radix-ui/react-dialog": "^1.1.1",
"@semaphore-protocol/core": "^4.0.3",
"@semaphore-protocol/core": "^4.4.1",
"@semaphore-protocol/identity": "3.15.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
Expand Down
25 changes: 17 additions & 8 deletions apps/client-web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,26 @@ export function Prove({
const prs = proofRequest(
proveOperation.proofRequest
).getProofRequest();
const inputs = {
pods: proveOperation.selectedPods as Record<string, POD>,
membershipLists: prs.membershipLists,
watermark: prs.watermark,
owner: {
semaphoreV4: getIdentity(),
externalNullifier: prs.externalNullifier
}
};
console.log(inputs);
gpcProve(
prs.proofConfig,
{
pods: proveOperation.selectedPods as Record<string, POD>,
membershipLists: prs.membershipLists,
watermark: prs.watermark,
owner: {
semaphoreV4: getIdentity(),
externalNullifier: prs.externalNullifier
}
...prs.proofConfig,
...(proveOperation.circuitIdentifier
? {
circuitIdentifier: proveOperation.circuitIdentifier
}
: {})
},
inputs,
new URL("/artifacts", window.location.origin).toString()
)
.then((proof) => {
Expand Down
12 changes: 10 additions & 2 deletions apps/client-web/src/client/gpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
} from "@parcnet-js/client-rpc";
import type { PodspecProofRequest } from "@parcnet-js/podspec";
import { proofRequest } from "@parcnet-js/podspec";
import type { GPCBoundConfig, GPCProof, GPCRevealedClaims } from "@pcd/gpc";
import type {
GPCBoundConfig,
GPCIdentifier,
GPCProof,
GPCRevealedClaims
} from "@pcd/gpc";
import { gpcVerify } from "@pcd/gpc";
import type { Dispatch } from "react";
import type { ClientAction } from "../state";
Expand Down Expand Up @@ -68,10 +73,12 @@ export class ParcnetGPCProcessor implements ParcnetGPCRPC {

public async prove({
request,
collectionIds
collectionIds,
circuitIdentifier
}: {
request: PodspecProofRequest;
collectionIds?: string[];
circuitIdentifier?: GPCIdentifier;
}): Promise<ProveResult> {
const pods = this.getPODsIfPermitted(collectionIds, "gpc.prove");
const prs = proofRequest(request);
Expand All @@ -94,6 +101,7 @@ export class ParcnetGPCProcessor implements ParcnetGPCRPC {
proofRequest: request,
pods: inputPods,
selectedPods: {},
circuitIdentifier,
proving: false,
resolve: (result) => {
advice.hideClient();
Expand Down
4 changes: 4 additions & 0 deletions apps/client-web/src/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import type { PodspecProofRequest } from "@parcnet-js/podspec";
import * as p from "@parcnet-js/podspec";
import { $s } from "@parcnet-js/podspec/pod_value_utils";
import type { GPCIdentifier } from "@pcd/gpc";
import { POD, encodePrivateKey, encodePublicKey } from "@pcd/pod";
import type { Identity as IdentityV4 } from "@semaphore-protocol/core";
import isEqual from "lodash/isEqual";
Expand Down Expand Up @@ -81,6 +82,7 @@ export type ClientState = {
selectedPods: Record<string, POD | undefined>;
proofRequest: PodspecProofRequest;
proving: boolean;
circuitIdentifier?: GPCIdentifier;
resolve?: (result: ProveResult) => void;
}
| undefined;
Expand Down Expand Up @@ -112,6 +114,7 @@ export type ClientAction =
pods: Record<string, POD[]>;
selectedPods: Record<string, POD | undefined>;
proofRequest: PodspecProofRequest;
circuitIdentifier?: GPCIdentifier;
proving: boolean;
resolve?: (result: ProveResult) => void;
}
Expand Down Expand Up @@ -215,6 +218,7 @@ export function clientReducer(state: ClientState, action: ClientAction) {
selectedPods: action.selectedPods,
proofRequest: action.proofRequest,
proving: action.proving,
circuitIdentifier: action.circuitIdentifier,
resolve: action.resolve
}
};
Expand Down
10 changes: 10 additions & 0 deletions examples/test-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# test-app

## 1.0.15

### Patch Changes

- Updated dependencies [c02d469]
- @parcnet-js/app-connector@1.1.3
- @parcnet-js/client-rpc@1.1.2
- @parcnet-js/podspec@1.1.1
- @parcnet-js/ticket-spec@1.1.2

## 1.0.14

### Patch Changes
Expand Down
2 changes: 1 addition & 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.14",
"version": "1.0.15",
"private": true,
"type": "module",
"scripts": {
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

## 1.1.3

### Patch Changes

- c02d469: Support adding a circuit identifier to GPC proof requests
- Updated dependencies [c02d469]
- @parcnet-js/client-rpc@1.1.2
- @parcnet-js/podspec@1.1.1

## 1.1.2

### 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": "1.1.2",
"version": "1.1.3",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.cjs",
Expand Down
8 changes: 7 additions & 1 deletion packages/app-connector/src/api_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import type {
ProveResult
} from "@parcnet-js/client-rpc";
import type * as p from "@parcnet-js/podspec";
import type { GPCBoundConfig, GPCProof, GPCRevealedClaims } from "@pcd/gpc";
import type {
GPCBoundConfig,
GPCIdentifier,
GPCProof,
GPCRevealedClaims
} from "@pcd/gpc";
import type { PODEntries } from "@pcd/pod";
import { type Emitter, createNanoEvents } from "nanoevents";
import type { ModalEmitter } from "./adapters/iframe.js";
Expand Down Expand Up @@ -176,6 +181,7 @@ export class ParcnetGPCWrapper {

async prove(args: {
request: p.PodspecProofRequest;
circuitIdentifier: GPCIdentifier;
collectionIds?: string[];
}): Promise<ProveResult> {
return new Promise((resolve, reject) => {
Expand Down
13 changes: 10 additions & 3 deletions packages/app-connector/src/rpc_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import {
RPCMessageType
} from "@parcnet-js/client-rpc";
import type { PodspecProofRequest } from "@parcnet-js/podspec";
import type { GPCBoundConfig, GPCProof, GPCRevealedClaims } from "@pcd/gpc";
import type {
GPCBoundConfig,
GPCIdentifier,
GPCProof,
GPCRevealedClaims
} from "@pcd/gpc";
import type { PODEntries } from "@pcd/pod";
import { type Emitter, createNanoEvents } from "nanoevents";
import * as v from "valibot";
Expand Down Expand Up @@ -177,14 +182,16 @@ export class ParcnetRPCConnector implements ParcnetRPC, ParcnetEvents {
this.gpc = {
prove: async ({
request,
collectionIds
collectionIds,
circuitIdentifier
}: {
request: PodspecProofRequest;
collectionIds?: string[];
circuitIdentifier?: GPCIdentifier;
}): Promise<ProveResult> => {
return this.#typedInvoke(
"gpc.prove",
[{ collectionIds, request }],
[{ collectionIds, request, circuitIdentifier }],
ParcnetRPCSchema.gpc.prove
);
},
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

## 1.0.3

### Patch Changes

- Updated dependencies [c02d469]
- @parcnet-js/client-rpc@1.1.2

## 1.0.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion 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": "1.0.2",
"version": "1.0.3",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.js",
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

## 1.1.2

### Patch Changes

- c02d469: Support adding a circuit identifier to GPC proof requests
- Updated dependencies [c02d469]
- @parcnet-js/podspec@1.1.1

## 1.1.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/client-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@parcnet-js/client-rpc",
"type": "module",
"version": "1.1.1",
"version": "1.1.2",
"license": "GPL-3.0-or-later",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down
10 changes: 9 additions & 1 deletion packages/client-rpc/src/rpc_interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import type {
PODSchema,
PodspecProofRequest
} from "@parcnet-js/podspec";
import type { GPCBoundConfig, GPCProof, GPCRevealedClaims } from "@pcd/gpc";
import type {
GPCBoundConfig,
GPCIdentifier,
GPCProof,
GPCRevealedClaims
} from "@pcd/gpc";
import type { PODEntries } from "@pcd/pod";
import type { PODData } from "./pod_data.js";

Expand Down Expand Up @@ -41,13 +46,16 @@ export interface ParcnetGPCRPC {
collectionIds
}: {
request: PodspecProofRequest;
circuitIdentifier?: GPCIdentifier;
collectionIds?: string[];
}) => Promise<ProveResult>;
canProve: ({
request,
circuitIdentifier,
collectionIds
}: {
request: PodspecProofRequest;
circuitIdentifier: GPCIdentifier;
collectionIds?: string[];
}) => Promise<boolean>;
verify: (
Expand Down
10 changes: 10 additions & 0 deletions packages/client-rpc/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { GPCIdentifier } from "@pcd/gpc";
import * as v from "valibot";
import type { ParcnetRPC } from "./rpc_interfaces.js";
import {
Expand All @@ -9,8 +10,17 @@ import {

const CollectionIdSchema = v.string();

const CircuitIdentifierSchema = v.pipe(
v.string(),
v.check((s): s is GPCIdentifier => {
return s.includes("_") && s.split("_").length === 2;
}),
v.transform<string, GPCIdentifier>((s) => s as GPCIdentifier)
);

const ProveArgsSchema = v.object({
request: PodspecProofRequestSchema,
circuitIdentifier: v.optional(CircuitIdentifierSchema),
collectionIds: v.optional(v.array(CollectionIdSchema))
});

Expand Down
6 changes: 6 additions & 0 deletions packages/podspec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @parcnet-js/podspec

## 1.1.1

### Patch Changes

- c02d469: Support adding a circuit identifier to GPC proof requests

## 1.1.0

### Minor Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/podspec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parcnet-js/podspec",
"version": "1.1.0",
"version": "1.1.1",
"license": "GPL-3.0-or-later",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down Expand Up @@ -36,8 +36,8 @@
},
"files": ["dist", "./README.md", "./LICENSE"],
"dependencies": {
"@pcd/gpc": "0.2.0",
"@pcd/pod": "0.3.0"
"@pcd/gpc": "^0.2.0",
"@pcd/pod": "^0.3.0"
},
"devDependencies": {
"@parcnet-js/eslint-config": "workspace:*",
Expand Down
8 changes: 8 additions & 0 deletions packages/ticket-spec/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @parcnet-js/ticket-spec

## 1.1.2

### Patch Changes

- Updated dependencies [c02d469]
- @parcnet-js/client-rpc@1.1.2
- @parcnet-js/podspec@1.1.1

## 1.1.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ticket-spec/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@parcnet-js/ticket-spec",
"version": "1.1.1",
"version": "1.1.2",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.js",
Expand Down
Loading

0 comments on commit ef72370

Please sign in to comment.