-
Notifications
You must be signed in to change notification settings - Fork 78
/
pcdPackages.ts
123 lines (108 loc) · 4.05 KB
/
pcdPackages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { EdDSAFrogPCDPackage } from "@pcd/eddsa-frog-pcd";
import { EdDSAPCDPackage } from "@pcd/eddsa-pcd";
import { EdDSATicketPCDPackage } from "@pcd/eddsa-ticket-pcd";
import { EmailPCDPackage } from "@pcd/email-pcd";
import { EthereumOwnershipPCDPackage } from "@pcd/ethereum-ownership-pcd";
import { GPCPCDPackage } from "@pcd/gpc-pcd";
import { HaLoNoncePCDPackage } from "@pcd/halo-nonce-pcd";
import { MessagePCDPackage } from "@pcd/message-pcd";
import { requestLogToServer } from "@pcd/passport-interface";
import { PCDCollection } from "@pcd/pcd-collection";
import { PCD, PCDPackage, SerializedPCD } from "@pcd/pcd-types";
import { PODPCDPackage } from "@pcd/pod-pcd";
import { PODTicketPCDPackage } from "@pcd/pod-ticket-pcd";
import { RSAImagePCDPackage } from "@pcd/rsa-image-pcd";
import { RSAPCDPackage } from "@pcd/rsa-pcd";
import { RSATicketPCDPackage } from "@pcd/rsa-ticket-pcd";
import { SemaphoreGroupPCDPackage } from "@pcd/semaphore-group-pcd";
import { SemaphoreIdentityPCDPackage } from "@pcd/semaphore-identity-pcd";
import { SemaphoreSignaturePCDPackage } from "@pcd/semaphore-signature-pcd";
import { UnknownPCDPackage, wrapUnknownPCD } from "@pcd/unknown-pcd";
import { getErrorMessage } from "@pcd/util";
import { ZKEdDSAEventTicketPCDPackage } from "@pcd/zk-eddsa-event-ticket-pcd";
import { ZKEdDSAFrogPCDPackage } from "@pcd/zk-eddsa-frog-pcd";
import { appConfig } from "./appConfig";
import { loadSelf } from "./localstorage";
import { makeEncodedVerifyLink } from "./qr";
import { getGPCArtifactsURL } from "./util";
let pcdPackages: Promise<PCDPackage[]> | undefined;
export async function getPackages(): Promise<PCDPackage[]> {
if (pcdPackages !== undefined) {
return pcdPackages;
}
pcdPackages = loadPackages();
return pcdPackages;
}
async function loadPackages(): Promise<PCDPackage[]> {
await SemaphoreGroupPCDPackage.init?.({
wasmFilePath: "/semaphore-artifacts/16.wasm",
zkeyFilePath: "/semaphore-artifacts/16.zkey"
});
await SemaphoreSignaturePCDPackage.init?.({
wasmFilePath: "/semaphore-artifacts/16.wasm",
zkeyFilePath: "/semaphore-artifacts/16.zkey"
});
await EthereumOwnershipPCDPackage.init?.({
wasmFilePath: "/semaphore-artifacts/16.wasm",
zkeyFilePath: "/semaphore-artifacts/16.zkey"
});
await RSATicketPCDPackage.init?.({
makeEncodedVerifyLink
});
await ZKEdDSAEventTicketPCDPackage.init?.({
wasmFilePath: "/artifacts/zk-eddsa-event-ticket-pcd/circuit.wasm",
zkeyFilePath: "/artifacts/zk-eddsa-event-ticket-pcd/circuit.zkey"
});
await ZKEdDSAFrogPCDPackage.init?.({
wasmFilePath: "/artifacts/zk-eddsa-frog-pcd/circuit.wasm",
zkeyFilePath: "/artifacts/zk-eddsa-frog-pcd/circuit.zkey"
});
await MessagePCDPackage.init?.({});
await PODPCDPackage.init?.({});
await GPCPCDPackage.init?.({
zkArtifactPath: getGPCArtifactsURL(
"/" /* zupassURL can use a site-relative URL */
)
});
await UnknownPCDPackage.init?.({ verifyBehavior: "error" });
return [
SemaphoreGroupPCDPackage,
SemaphoreIdentityPCDPackage,
SemaphoreSignaturePCDPackage,
EthereumOwnershipPCDPackage,
HaLoNoncePCDPackage,
RSAPCDPackage,
RSATicketPCDPackage,
EdDSAPCDPackage,
EdDSAFrogPCDPackage,
ZKEdDSAFrogPCDPackage,
EdDSATicketPCDPackage,
ZKEdDSAEventTicketPCDPackage,
RSAImagePCDPackage,
EmailPCDPackage,
MessagePCDPackage,
PODPCDPackage,
PODTicketPCDPackage,
GPCPCDPackage,
UnknownPCDPackage
];
}
export async function fallbackDeserializeFunction(
_collection: PCDCollection,
_pcdPackage: PCDPackage | undefined,
serializedPCD: SerializedPCD,
deserializeError: unknown
): Promise<PCD> {
console.error(
`Wrapping with UnknownPCD after failure to deserialize ${
serializedPCD.type
}. ${getErrorMessage(deserializeError)}`
);
requestLogToServer(appConfig.zupassServer, "pcd-deserialize-fallback", {
user: loadSelf()?.uuid,
pcdType: serializedPCD.type,
deserializeError,
errorMessage: getErrorMessage(deserializeError)
});
return wrapUnknownPCD(serializedPCD, deserializeError);
}