Skip to content

Commit

Permalink
fix: add checks on zkConnectResponse (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabin54 authored Mar 14, 2023
1 parent 1588632 commit 738aedc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/zk-connect-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sismo-core/zk-connect-server",
"version": "0.0.0-beta.9",
"version": "0.0.0-beta.10",
"description": "zkConnect server package",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
Expand Down
24 changes: 23 additions & 1 deletion packages/zk-connect-server/src/zk-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,29 @@ export class ZkConnectServer {
public verify = async (zkConnectResponse: ZkConnectResponse, {
dataRequest,
namespace,
}: VerifyParamsZkConnect): Promise<ZkConnectVerifiedResult> => {
}: VerifyParamsZkConnect = {}): Promise<ZkConnectVerifiedResult> => {
if (!zkConnectResponse) {
throw new Error(
`zkConnectResponse provided is undefined`
);
}

if (!zkConnectResponse.version) {
throw new Error(
`no version provided in your zkConnectResponse, please use the zkConnectResponse that was returned by the Sismo vault app`
);
}
if (!zkConnectResponse.appId) {
throw new Error(
`no appId provided in your zkConnectResponse, please use the zkConnectResponse that was returned by the Sismo vault app`
);
}
if (!zkConnectResponse.namespace) {
throw new Error(
`no namespace provided in your zkConnectResponse, please use the zkConnectResponse that was returned by the Sismo vault app`
);
}

namespace = namespace ?? "main";
if (zkConnectResponse.version !== ZK_CONNECT_VERSION) {
throw new Error(
Expand Down
17 changes: 17 additions & 0 deletions packages/zk-connect-server/tests/zk-connect-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ describe("ZkConnect", () => {

describe("zkConnect server", () => {
describe("verify with statements", () => {
it("should throw with an invalid zkConnectResponse", async () => {
const invalidZkConnectResponse = null;
await expect(
zkConnect.verify(invalidZkConnectResponse as any, { dataRequest, namespace })
).rejects.toThrow(
`zkConnectResponse provided is undefined`
);
});

it("should throw with an invalid zkConnectResponse", async () => {
const invalidZkConnectResponse = {};
await expect(
zkConnect.verify(invalidZkConnectResponse as any, { dataRequest, namespace })
).rejects.toThrow(
`no version provided in your zkConnectResponse, please use the zkConnectResponse that was returned by the Sismo vault app`
);
});

it("should throw with an invalid version", async () => {
const invalidZkConnectResponse = JSON.parse(JSON.stringify(zkConnectResponse));
Expand Down

0 comments on commit 738aedc

Please sign in to comment.