diff --git a/packages/zk-connect-server/package.json b/packages/zk-connect-server/package.json index 78316c8..10a588a 100644 --- a/packages/zk-connect-server/package.json +++ b/packages/zk-connect-server/package.json @@ -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", diff --git a/packages/zk-connect-server/src/zk-connect.ts b/packages/zk-connect-server/src/zk-connect.ts index e9344a9..a3c914d 100644 --- a/packages/zk-connect-server/src/zk-connect.ts +++ b/packages/zk-connect-server/src/zk-connect.ts @@ -38,7 +38,29 @@ export class ZkConnectServer { public verify = async (zkConnectResponse: ZkConnectResponse, { dataRequest, namespace, - }: VerifyParamsZkConnect): Promise => { + }: VerifyParamsZkConnect = {}): Promise => { + 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( diff --git a/packages/zk-connect-server/tests/zk-connect-e2e.test.ts b/packages/zk-connect-server/tests/zk-connect-e2e.test.ts index 44b7e68..9ffaf51 100644 --- a/packages/zk-connect-server/tests/zk-connect-e2e.test.ts +++ b/packages/zk-connect-server/tests/zk-connect-e2e.test.ts @@ -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));