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

Make sure not to generate non-PODName list names #26

Merged
merged 4 commits into from
Oct 27, 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
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.16

### Patch Changes

- Updated dependencies
- @parcnet-js/podspec@1.1.3
- @parcnet-js/client-rpc@1.1.6
- @parcnet-js/client-helpers@1.0.7

## 0.0.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion 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.15",
"version": "0.0.16",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
11 changes: 11 additions & 0 deletions examples/test-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# test-app

## 1.0.20

### Patch Changes

- Updated dependencies
- @parcnet-js/podspec@1.1.3
- @parcnet-js/app-connector@1.1.8
- @parcnet-js/client-rpc@1.1.6
- @parcnet-js/ticket-spec@1.1.6
- @parcnet-js/app-connector-react@1.0.3

## 1.0.19

### 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.19",
"version": "1.0.20",
"private": true,
"type": "module",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions packages/app-connector-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @parcnet-js/app-connector-react

## 1.0.3

### Patch Changes

- @parcnet-js/app-connector@1.1.8

## 1.0.2

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

## 1.1.8

### Patch Changes

- Updated dependencies
- @parcnet-js/podspec@1.1.3
- @parcnet-js/client-rpc@1.1.6

## 1.1.7

### 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.7",
"version": "1.1.8",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.cjs",
Expand Down
14 changes: 10 additions & 4 deletions packages/app-connector/test/parcnet-connector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ describe("parcnet-client should work", function () {
const client = new ParcnetRPCConnector(chan.port2, mockDialog);
expect(client.isConnected()).to.be.false;

client.start(() => {
// This is called when the connection is established
expect(client.isConnected()).to.be.true;
});
client.start(
() => {
// This is called when the connection is established
expect(client.isConnected()).to.be.true;
},
() => {
// This is called if the connection fails. We should never get here.
assert(false);
}
);

postRPCMessage(chan.port1, {
type: RPCMessageType.PARCNET_CLIENT_READY
Expand Down
16 changes: 11 additions & 5 deletions packages/app-connector/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { RPCMessageType } from "@parcnet-js/client-rpc";
import { expect } from "vitest";
import { assert, expect } from "vitest";
import type { DialogController } from "../src/adapters/iframe.js";
import { postRPCMessage } from "../src/adapters/iframe.js";
import { ParcnetRPCConnector } from "../src/rpc_client.js";
Expand All @@ -19,10 +19,16 @@ export async function connectedClient(): Promise<{
}> {
const chan = new MessageChannel();
const client = new ParcnetRPCConnector(chan.port2, mockDialog);
client.start(() => {
// This is called when the connection is established
expect(client.isConnected()).to.be.true;
});
client.start(
() => {
// This is called when the connection is established
expect(client.isConnected()).to.be.true;
},
() => {
// This is called if the connection fails. We should never get here.
assert(false);
}
);

postRPCMessage(chan.port1, {
type: RPCMessageType.PARCNET_CLIENT_READY
Expand Down
6 changes: 6 additions & 0 deletions packages/client-helpers/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @parcnet-js/client-helpers

## 1.0.7

### Patch Changes

- @parcnet-js/client-rpc@1.1.6

## 1.0.6

### 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.6",
"version": "1.0.7",
"license": "GPL-3.0-or-later",
"type": "module",
"main": "dist/index.js",
Expand Down
7 changes: 7 additions & 0 deletions packages/client-rpc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @parcnet-js/client-rpc

## 1.1.6

### Patch Changes

- Updated dependencies
- @parcnet-js/podspec@1.1.3

## 1.1.5

### 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.5",
"version": "1.1.6",
"license": "GPL-3.0-or-later",
"main": "dist/index.js",
"module": "dist/index.js",
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.3

### Patch Changes

- Fix compatibility with POD serialization restrictions on membership list names

## 1.1.2

### Patch 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.2",
"version": "1.1.3",
"license": "GPL-3.0-or-later",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down Expand Up @@ -30,8 +30,8 @@
},
"scripts": {
"lint": "eslint . --max-warnings 0",
"build": "tsup 'src/**/*@(ts|tsx)' --format cjs,esm --clean --sourcemap",
"prepublish": "tsup 'src/**/*@(ts|tsx)' --format cjs,esm --clean --sourcemap --dts",
"build": "tsup 'src/**/*@(ts|tsx)' --format cjs,esm --clean --sourcemap --no-splitting",
"prepublish": "tsup 'src/**/*@(ts|tsx)' --format cjs,esm --clean --sourcemap --dts --no-splitting",
"test": "vitest run --typecheck"
},
"files": ["dist", "./README.md", "./LICENSE"],
Expand Down
27 changes: 24 additions & 3 deletions packages/podspec/src/gpc/proof_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
} from "@pcd/gpc";
import type { POD, PODName, PODValue } from "@pcd/pod";
import { PodSpec } from "../parse/pod.js";
import { $e } from "../pod_value_utils.js";
import type { EntriesSchema } from "../schemas/entries.js";
import type { PODSchema } from "../schemas/pod.js";

Expand Down Expand Up @@ -183,9 +184,9 @@ function makeProofRequest<P extends NamedPODs>(
}

for (const entriesTupleSchema of podSchema.tuples ?? []) {
const tupleName = `tuple_${podName}_entries_${entriesTupleSchema.entries.join(
"_"
)}`;
const tupleName = `tuple_${podName}_entries_${entriesTupleSchema.entries
.map((entryName) => entryName.replace("$", "_"))
.join("_")}`;
tuples[tupleName] = {
entries: entriesTupleSchema.entries.map(
(entryName) => `${podName}.${entryName}` satisfies PODEntryIdentifier
Expand Down Expand Up @@ -220,6 +221,26 @@ function makeProofRequest<P extends NamedPODs>(
}
}

if (podSchema.signerPublicKey) {
podConfig.signerPublicKey = {
isRevealed: podSchema.signerPublicKey.isRevealed ?? false
};
if (podSchema.signerPublicKey.isMemberOf) {
// Double underscore to avoid collision with entry names.
membershipLists[`allowlist_${podName}__signerPublicKey`] = $e(
podSchema.signerPublicKey.isMemberOf
);
podConfig.signerPublicKey.isMemberOf = `allowlist_${podName}__signerPublicKey`;
}
if (podSchema.signerPublicKey.isNotMemberOf) {
// Double underscore to avoid collision with entry names.
membershipLists[`blocklist_${podName}__signerPublicKey`] = $e(
podSchema.signerPublicKey.isNotMemberOf
);
podConfig.signerPublicKey.isNotMemberOf = `blocklist_${podName}__signerPublicKey`;
}
}

pods[podName] = podConfig;
}

Expand Down
1 change: 1 addition & 0 deletions packages/podspec/src/schemas/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type PODSchema<E extends EntriesSchema> = {
isNotMemberOf?: PODValue[][];
}[];
signerPublicKey?: {
isRevealed?: boolean;
isMemberOf?: string[];
isNotMemberOf?: string[];
};
Expand Down
6 changes: 6 additions & 0 deletions packages/podspec/test/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import path from "path";

export const GPC_NPM_ARTIFACTS_PATH = path.join(
__dirname,
"../node_modules/@pcd/proto-pod-gpc-artifacts"
);
10 changes: 2 additions & 8 deletions packages/podspec/test/podspec.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import path from "path";
import type { GPCBoundConfig } from "@pcd/gpc";
import { gpcProve, gpcVerify } from "@pcd/gpc";
import { POD } from "@pcd/pod";
import { POD_INT_MAX, POD_INT_MIN } from "@pcd/pod/podTypes";
import { POD, POD_INT_MAX, POD_INT_MIN } from "@pcd/pod";
import { v4 as uuidv4 } from "uuid";
import { assert, describe, expect, it } from "vitest";
import type {
Expand All @@ -14,13 +12,9 @@ import { IssueCode } from "../src/error.js";
import * as p from "../src/index.js";
import { $c, $i, $s } from "../src/pod_value_utils.js";
import type { EntriesTupleSchema } from "../src/schemas/entries.js";
import { GPC_NPM_ARTIFACTS_PATH } from "./constants.js";
import { generateKeyPair, generateRandomHex } from "./utils.js";

export const GPC_NPM_ARTIFACTS_PATH = path.join(
__dirname,
"../node_modules/@pcd/proto-pod-gpc-artifacts"
);

describe("podspec should work", function () {
it("should validate POD entries", () => {
// To begin with, we can create a specification for POD entries.
Expand Down
83 changes: 83 additions & 0 deletions packages/podspec/test/serialization.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import {
type GPCBoundConfig,
boundConfigToJSON,
gpcProve,
podMembershipListsToJSON,
proofConfigToJSON,
revealedClaimsToJSON
} from "@pcd/gpc";
import { POD } from "@pcd/pod";
import { describe, expect, it } from "vitest";
import * as p from "../src/index.js";
import { GPC_NPM_ARTIFACTS_PATH } from "./constants.js";
import { generateKeyPair } from "./utils.js";

describe("should be able to serialize outputs", function () {
it("should serialize proof request outputs", async function () {
const { publicKey, privateKey } = generateKeyPair();

const pod1 = p.pod({
entries: {
foo: { type: "string" },
bar: {
type: "int",
inRange: { min: 0n, max: 10n }
}
},
signerPublicKey: {
isMemberOf: [publicKey]
},
tuples: [
{
entries: ["$signerPublicKey", "foo", "bar"],
isMemberOf: [
[
{ type: "eddsa_pubkey", value: publicKey },
{ type: "string", value: "test" },
{ type: "int", value: 5n }
]
]
}
]
});
const prs = p.proofRequest({
pods: {
pod1: pod1.proofConfig({ revealed: { foo: true, bar: true } })
},
watermark: { type: "string", value: "1" },
externalNullifier: { type: "string", value: "1" }
});

const pr = prs.getProofRequest();
console.dir(pr, { depth: null });

expect(() => proofConfigToJSON(pr.proofConfig)).to.not.throw;
expect(() => podMembershipListsToJSON(pr.membershipLists)).to.not.throw;

const pod = POD.sign(
{
foo: { type: "string", value: "test" },
bar: { type: "int", value: 5n }
},
privateKey
);

const proof = await gpcProve(
pr.proofConfig,
{
membershipLists: pr.membershipLists,
pods: { pod1: pod }
},
GPC_NPM_ARTIFACTS_PATH
);

pr.proofConfig.circuitIdentifier = proof.boundConfig.circuitIdentifier;
const boundConfig: GPCBoundConfig = {
...pr.proofConfig,
circuitIdentifier: proof.boundConfig.circuitIdentifier
};

expect(() => boundConfigToJSON(boundConfig)).to.not.throw;
expect(() => revealedClaimsToJSON(proof.revealedClaims)).to.not.throw;
});
});
2 changes: 1 addition & 1 deletion packages/podspec/test/ticket-example.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { v4 as uuidv4 } from "uuid";
import { assert, describe, expect, it } from "vitest";
import * as p from "../src/index.js";
import { $s } from "../src/pod_value_utils.js";
import { GPC_NPM_ARTIFACTS_PATH } from "./podspec.spec.js";
import { GPC_NPM_ARTIFACTS_PATH } from "./constants.js";
import { generateKeyPair } from "./utils.js";

/**
Expand Down
Loading
Loading