-
Notifications
You must be signed in to change notification settings - Fork 77
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
Basic implementation of Email PODs in Z API #2194
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { PCDCollection } from "@pcd/pcd-collection"; | ||
import type { POD } from "@pcd/pod"; | ||
import { POD } from "@pcd/pod"; | ||
import { PODEmailPCD, isPODEmailPCD } from "@pcd/pod-email-pcd"; | ||
import { isPODPCD } from "@pcd/pod-pcd"; | ||
import { PODTicketPCD, isPODTicketPCD, ticketToPOD } from "@pcd/pod-ticket-pcd"; | ||
|
||
|
@@ -13,6 +14,14 @@ export function getCollectionNames(pcds: PCDCollection): string[] { | |
return pcds.getFoldersInFolder(COLLECTIONS_ROOT_FOLDER_NAME); | ||
} | ||
|
||
function emailPCDToPOD(pcd: PODEmailPCD): POD { | ||
return POD.load( | ||
pcd.claim.podEntries, | ||
pcd.proof.signature, | ||
pcd.claim.signerPublicKey | ||
); | ||
} | ||
|
||
export function getPODsForCollections( | ||
pcds: PCDCollection, | ||
collectionIds: string[] | ||
|
@@ -21,8 +30,16 @@ export function getPODsForCollections( | |
.flatMap((collectionId) => | ||
collectionId === "Devcon SEA" | ||
? pcds.getAllPCDsInFolder("Devcon SEA") | ||
: collectionId === "Email" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and then refactor this into a nice function if collection id is in VIRTUAL_COLLECTIONS |
||
? pcds.getAllPCDsInFolder("Email") | ||
: pcds.getAllPCDsInFolder(collectionIdToFolderName(collectionId)) | ||
) | ||
.filter((pcd) => isPODPCD(pcd) || isPODTicketPCD(pcd)) | ||
.map((pcd) => (isPODPCD(pcd) ? pcd.pod : ticketToPOD(pcd as PODTicketPCD))); | ||
.filter((pcd) => isPODPCD(pcd) || isPODTicketPCD(pcd) || isPODEmailPCD(pcd)) | ||
.map((pcd) => | ||
isPODPCD(pcd) | ||
? pcd.pod | ||
: isPODTicketPCD(pcd) | ||
? ticketToPOD(pcd as PODTicketPCD) | ||
: emailPCDToPOD(pcd as PODEmailPCD) | ||
); | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,6 +23,8 @@ export function PODSection(): ReactNode { | |||||
<div className="prose"> | ||||||
<h2 className="text-lg font-bold mt-4">Query PODs</h2> | ||||||
<QueryPODs z={z} /> | ||||||
<h2 className="text-lg font-bold mt-4">Query Email PODs</h2> | ||||||
<QueryEmailPODs z={z} /> | ||||||
<h2 className="text-lg font-bold mt-4">Sign POD</h2> | ||||||
<SignPOD z={z} setSignedPOD={setPOD} /> | ||||||
<h2 className="text-lg font-bold mt-4">Sign POD with Prefix</h2> | ||||||
|
@@ -120,6 +122,74 @@ const pods = await z.pod.collection("${selectedCollection}").query(q); | |||||
); | ||||||
} | ||||||
|
||||||
function QueryEmailPODs({ z }: { z: ParcnetAPI }): ReactNode { | ||||||
const [pods, setPODs] = useState<p.PODData[] | undefined>(undefined); | ||||||
return ( | ||||||
<div> | ||||||
<p> | ||||||
Querying Email PODs is done like this: | ||||||
<code className="block text-xs font-base rounded-md p-2 whitespace-pre"> | ||||||
{`const q = p.pod({ | ||||||
entries: { | ||||||
emailAddress: { | ||||||
type: "string" | ||||||
}, | ||||||
semaphoreV4PublicKey: { | ||||||
type: "eddsa_pubkey" | ||||||
}, | ||||||
pod_type: { | ||||||
type: "string", | ||||||
isMemberOf: [{ type: "string", value: "zupass.email" }] | ||||||
} | ||||||
} | ||||||
}); | ||||||
const pods = await z.pod.collection("Email").query(q); | ||||||
`} | ||||||
</code> | ||||||
</p> | ||||||
<TryIt | ||||||
onClick={async () => { | ||||||
try { | ||||||
const q = p.pod({ | ||||||
entries: { | ||||||
emailAddress: { | ||||||
type: "string" | ||||||
}, | ||||||
semaphoreV4PublicKey: { | ||||||
type: "eddsa_pubkey" | ||||||
}, | ||||||
pod_type: { | ||||||
type: "string", | ||||||
isMemberOf: [{ type: "string", value: "zupass.email" }] | ||||||
} | ||||||
} | ||||||
}); | ||||||
const pods = await z.pod.collection("Email").query(q); | ||||||
console.log(pods); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm |
||||||
setPODs(pods); | ||||||
} catch (e) { | ||||||
console.log(e); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
}} | ||||||
label="Query Email PODs" | ||||||
/> | ||||||
{pods !== undefined && ( | ||||||
<pre className="whitespace-pre-wrap"> | ||||||
{JSONBig.stringify( | ||||||
pods.map((p) => ({ | ||||||
entries: p.entries, | ||||||
signature: p.signature, | ||||||
signerPublicKey: p.signerPublicKey | ||||||
})), | ||||||
null, | ||||||
2 | ||||||
)} | ||||||
</pre> | ||||||
)} | ||||||
</div> | ||||||
); | ||||||
} | ||||||
|
||||||
type Action = | ||||||
| { | ||||||
type: "SET_KEY"; | ||||||
|
@@ -193,7 +263,7 @@ const editPODReducer = function ( | |||||
) { | ||||||
newState[action.key] = { | ||||||
type: action.podValueType as "string" | "eddsa_pubkey", | ||||||
value: newState[action.key].value.toString() | ||||||
value: newState[action.key].value?.toString() ?? "" | ||||||
}; | ||||||
} else { | ||||||
state[action.key].type = action.podValueType; | ||||||
|
@@ -203,7 +273,7 @@ const editPODReducer = function ( | |||||
case "SET_VALUE": { | ||||||
const newState = { ...state }; | ||||||
if (bigintish.includes(newState[action.key].type)) { | ||||||
const value = BigInt(action.value); | ||||||
const value = BigInt(action.value as string); | ||||||
if (value >= POD_INT_MIN && value <= POD_INT_MAX) { | ||||||
newState[action.key].value = value; | ||||||
} | ||||||
|
@@ -271,8 +341,8 @@ ${Object.entries(entries) | |||||
.map(([key, value]) => { | ||||||
return ` ${key}: { type: "${value.type}", value: ${ | ||||||
bigintish.includes(value.type) | ||||||
? `${value.value.toString()}n` | ||||||
: `"${value.value.toString()}"` | ||||||
? `${value.value?.toString() ?? ""}n` | ||||||
: `"${value.value?.toString() ?? ""}"` | ||||||
} }`; | ||||||
}) | ||||||
.join(",\n")} | ||||||
|
@@ -366,8 +436,8 @@ ${Object.entries(entries) | |||||
.map(([key, value]) => { | ||||||
return ` ${key}: { type: "${value.type}", value: ${ | ||||||
bigintish.includes(value.type) | ||||||
? `${value.value.toString()}n` | ||||||
: `"${value.value.toString()}"` | ||||||
? `${value.value?.toString() ?? ""}n` | ||||||
: `"${value.value?.toString() ?? ""}"` | ||||||
} }`; | ||||||
}) | ||||||
.join(",\n")} | ||||||
|
@@ -458,7 +528,7 @@ function EditPODEntry({ | |||||
<label className="block"> | ||||||
{showLabels && <span className="text-gray-700">Value</span>} | ||||||
<input | ||||||
value={value.toString()} | ||||||
value={value?.toString() ?? ""} | ||||||
type={typeof value === "string" ? "text" : "number"} | ||||||
className="mt-1 block w-full rounded-md bg-gray-100 border-transparent focus:border-gray-500 focus:bg-white focus:ring-0" | ||||||
placeholder="" | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit -- maybe make this an array const? something like
VIRTUAL_COLLECTIONS
(or another name) ?